From robert.kern at gmail.com Sun Nov 1 00:09:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Oct 2009 23:09:05 -0500 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 10:35 PM, Robert Kern wrote: >> Peng Yu wrote: >> >>> I have defined 'long' in one of my previous message. I consider a file >>> long, when it does not fit in one or two screen. Basically, I want to >>> get a whole picture of the file after glancing of the file. >> I think you are going to have to get used to the fact that you have very >> strange personal preferences and that Python is designed for the vast >> majority of programmers who do not share them. > > So python would not be able to accommodate my preference one > class/function per file? I.e., I have to use something like 'from spam > import spam' or 'spam.spam()', or accept that the filename is not the > same as the class/function name. > > Inside test/__init__.py: > from a import A # class A from file a.py > from b import B # class B from file b.py If you are going to expose symbols in your __init__.py, they should not have the same name as any of the modules in the package. -- 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 tjreedy at udel.edu Sun Nov 1 00:28:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 Nov 2009 00:28:53 -0400 Subject: How to get the realpath of a symbolic link? In-Reply-To: <366c6f340910311248v60bd5e0nff79a90de942d84e@mail.gmail.com> References: <366c6f340910310003p632c087axeeb638aa0df08c56@mail.gmail.com> <366c6f340910311011h58ef9cecy882d561100aacac0@mail.gmail.com> <366c6f340910311248v60bd5e0nff79a90de942d84e@mail.gmail.com> Message-ID: Peng Yu wrote: > I find the following two files that define realpath. But I don't find > 'realpath' in os.py. I looked at 'os.py'. But I don't understand how > the function realpath is introduced in the name space in os.path. > Would you please let me know? > > gfind . ! -path '*backup*' -name "*.py" -type f -exec grep -n "def > realpath" {} \; -printf %p\\n\\n > 193:def realpath(path): > ./macpath.py > > 345:def realpath(filename): > ./posixpath.py That is where realpath is. From gagsl-py2 at yahoo.com.ar Sun Nov 1 00:38:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 01:38:16 -0300 Subject: import bug References: Message-ID: En Sat, 31 Oct 2009 12:12:21 -0300, kj escribi?: > I'm running into an ugly bug, which, IMHO, is really a bug in the > design of Python's module import scheme. The basic problem is that the "import scheme" was not designed in advance. It was a very simple thing at first. Then came packages. And then the __import__ builtin. And later some import hooks. And later support for zip files. And more import hooks and meta hooks. And namespace packages. And relative imports, absolute imports, and mixed imports. And now it's a mess. > Consider the following > directory structure: > [containing a re.py file in the same directory as the main script] > > If I now run the innocent-looking ham/spam.py, I get the following > error: > > % python26 ham/spam.py > Traceback (most recent call last): > [...] > File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in > __init__ > 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > My sin appears to be having the (empty) file ham/re.py. So Python > is confusing it with the re module of the standard library, and > using it when the inspect module tries to import re. Exactly; that's the root of your problem, and has been a problem ever since import existed. En Sat, 31 Oct 2009 13:27:20 -0300, kj escribi?: >> 2) this has been fixed in Py3 > > In my post I illustrated that the failure occurs both with Python > 2.6 *and* Python 3.0. Did you have a particular version of Python > 3 in mind? If the `re` module had been previously loaded (the true one, from the standard library) then this bug is not apparent. This may happen if re is imported from site.py, sitecustomize.py, any .pth file, the PYTHONSTARTUP script, perhaps other sources... The same error happens if ham\spam.py contains the single line: import smtpd, and instead of re.py there is an empty asyncore.py file; that fails on 3.1 too. En Sat, 31 Oct 2009 22:27:09 -0300, Steven D'Aprano escribi?: > On Sat, 31 Oct 2009 16:27:20 +0000, kj wrote: > >>> 1) it's a bad idea to name your own modules after modules in the stdlib >> >> Obviously, since it leads to the headaches this thread illustrates. But >> there is nothing intrisically wrong with it. The fact that it is >> problematic in Python is a design bug, plain and simple. There's no >> rational basis for it, > > Incorrect. Simplicity of implementation and API is a virtue, in and of > itself. The existing module machinery is quite simple to understand, use > and maintain. Uhm... module objects might be quite simple to understand, but module handling is everything but simple! (simplicity of implem...? quite simple to WHAT? ROTFLOL!!! :) ) > Dealing with name clashes doesn't come for free. If you > think it does, I encourage you to write a patch implementing the > behaviour you would prefer. I'd say it is really a bug, and has existed for a long time. One way to avoid name clashes would be to put the entire standard library under a package; a program that wants the standard re module would write "import std.re" instead of "import re", or something similar. Every time the std package is suggested, the main argument against it is backwards compatibility. > In addition, there are use-cases where the current behaviour is the > correct behaviour. Here's one way to backport (say) functools to older > versions of Python (untested): You still would be able to backport or patch modules, even if the standard ones live in the "std" package. En Sat, 31 Oct 2009 12:12:21 -0300, kj escribi?: > I've tried a lot of things to appease Python on this one, including > a liberal sprinkling of "from __future__ import absolute_import" > all over the place (except, of course, in inspect.py, which I don't > control), but to no avail. I think the only way is to make sure *your* modules always come *after* the standard ones in sys.path; try using this code right at the top of your main script: import sys, os.path if sys.argv[0]: script_path = os.path.dirname(os.path.abspath(sys.argv[0])) else: script_path = '' if script_path in sys.path: sys.path.remove(script_path) sys.path.append(script_path) (I'd want to put such code in sitecustomize.py, but sys.argv doesnt't exist yet at the time sitecustomize.py is executed) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:13:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:13:19 GMT Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> Message-ID: <02fd0755$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 14:12:40 -0400, Terry Reedy wrote: > alex23 wrote: >> Terry Reedy wrote: >>> alex23 wrote: >>>> You're completely wrong. Immutability has nothing to do with >>>> identity, > ... > > I'm honestly not getting your point here. > > Let me try again, a bit differently. > > I claim that the second statement, and therefor the first, can be seen > as wrong. I also claim that (Python) programmers need to understand why. > > In mathematics, we generally have immutable values whose 'identity' is > their value. There is, for example, only one, immutable, empty set. I think it's more than that -- I don't think pure mathematics makes any distinction at all between identity and equality. There are no instances at all, so you can't talk about individual values. It's not that the empty set is a singleton, because the empty set isn't a concrete object- with-existence at all. It's an abstraction, and as such, questions of "how many separate empty sets are there?" are meaningless. There are an infinite number of empty sets that differ according to their construction: The set of all American Presidents called Boris Nogoodnik. The set of all human languages with exactly one noun and one verb. The set of all fire-breathing mammals. The set of all real numbers equal to sqrt(-1). The set of all even prime numbers other than 2. The set of all integers between 0 and 1 exclusive. The set of all integers between 1 and 2 exclusive. The set of all positive integers between 2/5 and 4/5. The set of all multiples of five between 26 and 29. The set of all non-zero circles in Euclidean geometry where the radius equals the circumference. ... I certainly wouldn't say all fire-breathing mammals are integers between 0 and 1, so those sets are "different", and yet clearly they're also "the same" in some sense. I think this demonstrates that the question of how many different empty sets is meaningless -- it depends on what you mean by different and how many. > In informatics, and in particular in Python, in order to have > mutability, we have objects with value and an identity that is separate > from their value. I think you have this backwards. We have value and identity because of the hardware we use -- we store values in memory locations, which gives identity. Our universe imposes the distinction between value and identity. To simulate immutability and singletons is hard, and needs to be worked at. Nevertheless, it would be possible to go the other way. Given hypothetical hardware which only supported mutable singletons, we could simulate multiple instances. It would be horribly inefficient, but it could be done. Imagine a singleton-mutable-set implementation, something like this: class set: def __init__(id): return singleton def add(id, obj): singleton.elements.append((id, obj)) def __contains__(id, element) return (id, obj) in singleton.elements and so forth. You might notice that this is not terribly different from how one might define non-singleton sets. The difference being, Python sets have identity implied by storage in distinct memory locations, while this hypothetical singleton-set has to explicitly code for identity. > There can be, for example, multiple mutable empty > sets. Identity is important because we must care about which empty set > we add things to. 'Identity' is only needed because of 'mutability', so > it is mistaken to say they have nothing to do with each other. True, but it is not a mistake to say that identity and mutability are independent: there are immutable singletons, and mutable singletons, and immutable non-singletons, and mutable non-singletons. Clearly, knowing that an object is mutable doesn't tell you whether it is a singleton or not, and knowing it is a singleton doesn't tell you whether it is immutable or not. E.g. under normal circumstances modules are singletons, but they are mutable; frozensets are immutable, but they are not singletons. > Ideally, from both a conceptual and space efficiency view, an > implementation would allow only one copy for each value of immutable > classes. Ideally, from a complexity of implementation view, an implementation would allow an unlimited number of copies of each value of immutable classes. > This is what new programmers assume when they blithely use 'is' > instead of '==' (as would usually be correct in math). Nah, I think you're crediting them with far more sophistication than they actually have. I think most people in general, including many new programmers, simply don't have a good grasp of the conceptual difference between equality and identity. In plain language, "is" and its grammatical forms "be", "are", "am" etc. have many meanings: (1) Set membership testing: Socrates is a man. This is a hammer. (2) Existence: There is a computer language called Python. There is a monster under the bed. (3) Identity: Iron Man is Tony Stark. The butler is the murderer. (4) Mathematical equality: If x is 5, and y is 11, then y is 2x+1. (5) Equivalence: The winner of this race is the champion. The diameter of a circle is twice the radius. (6) Metaphoric equivalence: Kali is death. Life is like a box of chocolates. (7) Testing of state: My ankle is sore. Fred is left-handed. (8) Consequence If George won the lottery, he would say he is happy. (9) Cost A cup of coffee is $3. Only two of these usages work at all in any language I know of: equality and identity testing, although it would be interesting to consider a language that allowed type testing: 45 is an int -> returns True "abc" is a float -> returns False Some languages, like Hypertalk (by memory) and related languages, make "is" a synonym for equals. > However, for time efficiency reasons, there is no unique copy guarantee, > so one must use '==' instead of 'is', except in those few cases where > there is a unique copy guarantee, either by the language spec or by > one's own design, when one must use 'is' and not '=='. Here 'must' > means 'must to be generally assured of program correctness as intended'. > > We obviously agree on this guideline. Yes. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:34:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:34:40 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fd0c56$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: >>> In my question, module A and B exist just for the sake of >>> implementation. Even if I have module A and B, I don't want the user >>> feel the existence of module A and B. I want them feel exact like >>> class A and B are defined in module 'test' instead of feeling two >>> modules A and B are in package 'test'. >> >> >> Inside test/__init__.py: >> >> from A import A ?# class A from file A.py >> from B import B ?# class B from file B.py > > I can not use the above approach as I mentioned its problem in my > previous message. Either I have not seen it, or I have not understood it, but I don't understand why you can not use this approach. >> or better still: >> >> from a import A ?# class A from file a.py >> from b import B ?# class B from file b.py > > This artificially introduces the constraint that the file name can not > be the same as the class/function name. There is no constraint like this > if I can C++. It is not a constraint, it is a convention. You are free to ignore it if you like. Some people don't like writing "glob.glob" (for example). Some people would like to see Python ban modules with the same name as objects inside them, to avoid this error: >>> import datetime ... much later >>> from datetime import datetime >>> datetime.datetime() Traceback (most recent call last): File "", line 1, in AttributeError: type object 'datetime.datetime' has no attribute 'datetime' You seem to be inconsistent -- you say you want to name the file the same as the function in it, so you know which file to look for a function, but then you complain about writing: test.A.A so when we suggest naming A.py a.py, so you can write: test.a.A you complain about that too. Frankly, I think you are just complaining because Python isn't C++. >>> I know that module names should be in lower cases, in general. >>> However, it is OK to have the module name capitalized in this case >>> since the end users don't see them. >> >> Of course they do. > > This sentence is confusing. Can you spell out what you mean? If you supply a package test/ +-- __init__.py +-- A.py +-- B.py there is nothing stopping your users from doing this: import test.A as A import test.B as SomethingElse [...] > I have defined 'long' in one of my previous message. I consider a file > long, when it does not fit in one or two screen. Basically, I want to > get a whole picture of the file after glancing of the file. You must only write incredibly trivial programs then. There is more to understanding a program than understanding one single function. Any serious function will call other functions. To get the whole picture, you have to understand them too. Your requirement simply shifts the burden from "open one file, and read ten functions" to "open ten files, and read ten functions". -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:35:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:35:26 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> Message-ID: <02fd0c85$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote: > Many programmers I know stay away from 'lists' such as this, because > they are afraid to show their ignorance. Me, I'm fearless, and I have > learned a lot that I might not have otherwise. The only stupid question is the one you are afraid to ask. Good luck! -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:40:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:40:06 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> Message-ID: <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: >> Variables in a function are already private. ?How can the names in one >> function be affected by other functions in the same module? > > You misunderstood me. > > If there are multiple functions or classes in a file, when I change > variables in a function/class, I have to make sure that they are not in > other functions or classes. No you don't. def f(x): return x+1 def g(x): return x-1 If I choose to refactor f() and change "x" to "y", why do I care about the internal variable inside g()? Oh wait, I get it... you want to do a global search-and-replace over the entire file. *face-palm* If your functions are less than one-screen full, why do you need a global replacement? Global replacement risks changing words in docstrings, comments etc that it shouldn't. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:43:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:43:11 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> Message-ID: <02fd0e55$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: > So python would not be able to accommodate my preference one > class/function per file? Of course it does! You can do that RIGHT NOW -- just put one class per file. > I.e., I have to use something like 'from spam > import spam' or 'spam.spam()', How else do you expect to use the class if you don't import it? > or accept that the filename is not the > same as the class/function name. So let me see... You don't want to write "import spam; spam.spam()" You don't want to write "from spam import spam; spam()" You don't want to write "from Spam import spam; spam()" You don't want to write "from spam import Spam; Spam()" What exactly do you want? -- Steven From ben+python at benfinney.id.au Sun Nov 1 01:54:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 01 Nov 2009 16:54:12 +1100 Subject: Identifiers exposed by a package (was: How to import only one module in a package when the package __init__.py has already imports the modules?) References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> Message-ID: <87iqdux01n.fsf_-_@benfinney.id.au> Robert Kern writes: > If you are going to expose symbols in your __init__.py, they should > not have the same name as any of the modules in the package. Would I be correct in assuming you make an exception for the package importing one of the modules in the package, and thereby making that module's identifier exposed? package_foo/ __init__.py module_bar.py $ cat foo/__init__.py import module_bar Now the name ?package_foo.module_bar? will get the identifier already assigned within ?package_foo/__init__.py?, but that identifier is the module anyway. -- \ ?We demand rigidly defined areas of doubt and uncertainty!? | `\ ?Vroomfondel, _The Hitch-Hiker's Guide To The Galaxy_, Douglas | _o__) Adams | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:54:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:54:15 GMT Subject: import bug References: Message-ID: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: >> Incorrect. Simplicity of implementation and API is a virtue, in and of >> itself. The existing module machinery is quite simple to understand, >> use and maintain. > > Uhm... module objects might be quite simple to understand, but module > handling is everything but simple! (simplicity of implem...? quite > simple to WHAT? ROTFLOL!!! ) I stand corrected :) Nevertheless, the API is simple: the first time you "import name", Python searches a single namespace (the path) for a module called name. There are other variants of import, but the basics remain: search the path for the module called name, and do something with the first one you find. >> Dealing with name clashes doesn't come for free. If you think it does, >> I encourage you to write a patch implementing the behaviour you would >> prefer. > > I'd say it is really a bug, and has existed for a long time. Since import is advertised to return the first module with the given name it finds, I don't see it as a bug even if it doesn't do what the programmer intended it to do. If I do this: >>> len = 1 >>> def parrot(s): ... print len(s) ... >>> parrot("spam spam spam") Traceback (most recent call last): File "", line 1, in File "", line 2, in parrot TypeError: 'int' object is not callable it isn't a bug in Python that I have misunderstood scopes and inadvertently shadowed a builtin. Shadowing a standard library module is no different. > One way to > avoid name clashes would be to put the entire standard library under a > package; a program that wants the standard re module would write "import > std.re" instead of "import re", or something similar. Every time the std > package is suggested, the main argument against it is backwards > compatibility. You could do it in a backwards compatible way, by adding the std package directory into the path. -- Steven From ldo at geek-central.gen.new_zealand Sun Nov 1 01:08:00 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Nov 2009 19:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> In message , Carsten >> Haese wrote: >> >>> Lawrence D'Oliveiro wrote: >>> >>>> In message , >>>> Dennis Lee Bieber wrote: >>>> >>>>> This way regular string interpolation operations (or whatever Python >>>>> 3.x has replaced it with) are safe to construct the SQL, leaving only >>>>> user supplied (or program generated) data values to be passed via the >>>>> DB-API parameter system -- so that they are properly escaped and >>>>> rendered safe. >>>> >>>> Mixing the two is another recipe for confusion and mistakes. >>> >>> Mixing the two is necessary. >>> ... >>> As long as you understand what you're doing, there should be no >>> confusion. (And if you don't understand what you're doing, you shouldn't >>> be doing it!) >> >> But if you understand what you're doing, you don't need to mix the two. > > On what grounds are you asserting that it's not necessary to mix the > two? Please elaborate your point. On the grounds that Python has more general and powerful string parameter- substitution mechanisms than anything built into any database API. From robert.kern at gmail.com Sun Nov 1 01:41:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 01:41:52 -0500 Subject: Identifiers exposed by a package In-Reply-To: <87iqdux01n.fsf_-_@benfinney.id.au> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> <87iqdux01n.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > Robert Kern writes: > >> If you are going to expose symbols in your __init__.py, they should >> not have the same name as any of the modules in the package. > > Would I be correct in assuming you make an exception for the package > importing one of the modules in the package, and thereby making that > module's identifier exposed? > > package_foo/ > __init__.py > module_bar.py > > $ cat foo/__init__.py > import module_bar > > Now the name ?package_foo.module_bar? will get the identifier already > assigned within ?package_foo/__init__.py?, but that identifier is the > module anyway. Yes. -- 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 saketh.bhamidipati at gmail.com Sun Nov 1 02:06:50 2009 From: saketh.bhamidipati at gmail.com (Saketh) Date: Sun, 1 Nov 2009 00:06:50 -0700 (PDT) Subject: Pyfora, a place for python Message-ID: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Hi everyone, I am proud to announce the release of Pyfora (http://pyfora.org), an online community of Python enthusiasts to supplement comp.lang.python and #python. While the site is small right now, please feel free to register and post any questions or tips you may have. If you have any suggestions, let me know -- this is a community effort! Sincerely, Saketh (username:catechu) From gagsl-py2 at yahoo.com.ar Sun Nov 1 02:13:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 04:13:22 -0300 Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> Message-ID: En Fri, 30 Oct 2009 17:55:27 -0300, Jess Austin escribi?: > On Oct 29, 10:41 pm, "Gabriel Genellina" > wrote: >> We know the last test fails because the == logic fails to recognize >> mySet (on the right side) as a "more specialized" object than frozenset >> (on the left side), because set and frozenset don't have a common base >> type (although they share a lot of implementation) >> >> I think the only way would require modifying tp_richcompare of >> set/frozenset objects, so it is aware of subclasses on the right side. >> Currently, frozenset() == mySet() effectively ignores the fact that >> mySet is a subclass of set. > > I don't think even that would work. By the time set_richcompare() is > called (incidentally, it's used for both set and frozenset), it's too > late. That function is not responsible for calling the subclass's > method. It does call PyAnySet_Check(), but only to short-circuit > equality and inequality for non-set objects. I believe that something > higher-level in the interpreter decides to call the right-side type's > method because it's a subclass of the left-side type, but I'm not > familiar enough with the code to know where that happens. It may be > best not to sully such generalized code with a special case for > this. > > I may do some experiments with bytes, str, and unicode, since that > seems to be an analogous case. There is a basestring type, but at > this point I don't know that it really helps with anything. Looks like in 3.1 this can be done with bytes+str and viceversa, even if bytes and str don't have a common ancestor (other than object; basestring doesn't exist in 3.x): p3> Base = bytes p3> Other = str p3> p3> class Derived(Base): ... def __eq__(self, other): ... print('Derived.__eq__') ... return True ... p3> Derived()==Base() Derived.__eq__ True p3> Base()==Derived() Derived.__eq__ True p3> Derived()==Other() Derived.__eq__ True p3> Other()==Derived() Derived.__eq__ # !!! True p3> Base.mro() [, ] p3> Other.mro() [, ] The same example with set+frozenset (the one you're actually interested in) doesn't work, unfortunately. After further analysis, this works for bytes and str because both types refuse to guess and compare to each other; they return NotImplemented when the right-side operand is not of the same type. And this gives that other operand the chance of being called. set and frozenset, on the other hand, are promiscuous: their tp_richcompare slot happily accepts any set of any kind, derived or not, and compares their contents. I think it should be a bit more strict: if the right hand side is not of the same type, and its tp_richcompare slot is not the default one, it should return NotImplemented. This way the other type has a chance to be called. -- Gabriel Genellina From gu.yakahughes at gmail.com Sun Nov 1 02:37:44 2009 From: gu.yakahughes at gmail.com (KillSwitch) Date: Sun, 1 Nov 2009 00:37:44 -0700 (PDT) Subject: stdin in embedded python Message-ID: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> I have a C++ program, with a GUI, into which I have embedded python. I have made several python functions in C++, one of which I use to override the normal stdout and stderr so that they print to a text box of my GUI. One thing I cannot think of how to do is to redefine stdin so that it pauses the program, waits for a user to type input into the box, hit enter, and takes input from another text element and sends it to python like it was the console. I wonder if anyone could help me in trying to do such a thing. To simplify, the new stdin should wait for the C++ function to give it a value, like it waits for the console. From http Sun Nov 1 02:48:16 2009 From: http (Paul Rubin) Date: 01 Nov 2009 00:48:16 -0700 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <7xpr82y9bz.fsf@ruckus.brouhaha.com> Saketh writes: > I am proud to announce the release of Pyfora (http://pyfora.org), an > online community of Python enthusiasts to supplement comp.lang.python > and #python. And the reason to want to further fragment Python discussion is exactly what? From carsten.haese at gmail.com Sun Nov 1 03:09:25 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 01 Nov 2009 03:09:25 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: >> On what grounds are you asserting that it's not necessary to mix the >> two? Please elaborate your point. > > On the grounds that Python has more general and powerful string parameter- > substitution mechanisms than anything built into any database API. That statement is fundamentally flawed. You are assuming that the preferred way of getting a value into a query is by substituting a literal into the query string. That is, in general, not true, because that would be horribly inefficient. This is also why I despise the term "parameter substitution", since it implies incorrectly that passing parameters to a query is merely a string formatting exercise. The correct term is "parameter binding." Most databases actually provide an API for supplying parameters separately from the query string. This is more efficient, because it eliminates the need to render the parameter value into a literal form on the client side and to parse the literal form on the server side. Also, it allows the engine to perform the same query multiple times with different values without having to re-parse the query. Finally, you're assuming that every value that can be supplied to a query actually HAS a literal form. That is not true. For example, in Informix databases, there are no literals for BYTE-type values. (You'd probably call them blobs.) So, if vomiting literals into the query string were your only way of conveying values to the database, you'd never be able to populate a BYTE column on an Informix database. The only way to pass a BYTE value to an Informix database is by parameter binding. Since parameter binding is in general much more than string substitution, it is indeed necessary to mix the two. -- Carsten Haese http://informixdb.sourceforge.net From gklein at xs4all.nl Sun Nov 1 03:36:33 2009 From: gklein at xs4all.nl (Gertjan Klein) Date: Sun, 01 Nov 2009 09:36:33 +0100 Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> Message-ID: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Alf P. Steinbach wrote: >So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >file, or 'open' doesn't conform to the documentation. It does read beyond the end of file. This is perhaps the way the underlying C library works, but it looks like an "unexpected feature" (read: bug) to me. I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after creating an empty (0-byte) test file; after the write() the read() returns random garbage. I can't imagine why anyone would want that behaviour. The file grew to be 4099 bytes after f.close(). I wrote 'hello' to it, so the length of garbage added was 4094 bytes, which I find a strange number also. I would have expected the read to return nothing. Can anyone explain or even defend this behaviour? Gertjan. From ben+python at benfinney.id.au Sun Nov 1 03:44:10 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 01 Nov 2009 19:44:10 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <87my36my79.fsf@benfinney.id.au> Saketh writes: > If you have any suggestions, let me know -- this is a community > effort! Suggestion: Please don't make efforts to fragment the community. Rather, please direct seekers to the existing forums (the IRC channel, the Usenet groups and mailing lists) rather than setting up new walled gardens. -- \ ?None can love freedom heartily, but good men; the rest love | `\ not freedom, but license.? ?John Milton | _o__) | Ben Finney From alfps at start.no Sun Nov 1 04:44:45 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 10:44:45 +0100 Subject: problem with read() write() In-Reply-To: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: * Gertjan Klein: > Alf P. Steinbach wrote: > >> So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >> file, or 'open' doesn't conform to the documentation. > > It does read beyond the end of file. This is perhaps the way the > underlying C library works, but it looks like an "unexpected feature" > (read: bug) to me. > > I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after > creating an empty (0-byte) test file; after the write() the read() > returns random garbage. I can't imagine why anyone would want that > behaviour. The file grew to be 4099 bytes after f.close(). I wrote > 'hello' to it, so the length of garbage added was 4094 bytes, which I > find a strange number also. Could you post (copy and paste) the code, and description of results? > I would have expected the read to return nothing. Can anyone explain or > even defend this behaviour? I'm just a Python newbie, but in C and C++ such things are usually down to "undefined behavior", that is, the program doing something that is implicitly or explicitly defined as undefined behavior by the language standard. With UB the effect may then be something or nothing or anything or just what you expected; appearance of the infamous nasal demons is one possibility... Quoting n869, which is the January 18th 1999 draft of the C99 standard: ?7.19.5.3/6 When a file is opened with update mode (?+? as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos, or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file. Opening( or creating) a text file with update mode may instead open (or create) a binary stream in some implementations. "Shall not" means UB. This applies to C "FILE*" handling. AFAICS nothing except efficiency prevents the Python wrapper, if "FILE*" is what it uses, from automatically inserting an appropriate fflush or fseek. And for a language used by so many newbies (this is positive!) I agree that it should ideally get rid of that UB (assuming that's what the problem is), or, if it doesn't already, mention that in the Python documentation. Cheers, - Alf From rschroev_nospam_ml at fastmail.fm Sun Nov 1 05:38:39 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 01 Nov 2009 11:38:39 +0100 Subject: python os.path.exists failure In-Reply-To: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> References: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> Message-ID: koranthala schreef: > Hi all, > My code is as follows: > > path = r'C:/"Program Files"/testfolder/2.3/test.txt' > if os.path.lexists(path): > print 'Path Exists' > else: > print 'No file found in path - %s' %path > print Popen(path, stdout=PIPE, shell=True).stdout.read() > > The output comes as > No file found in path - C:/"Program Files"/testfolder/2.3/test.txt > but the test.txt file is opened. > > The issue, I guess, is that the double quotes inside is failing the > check. But without the double quotes, Popen fails. > One solution, I can think is to check without double quotes, and then > using some code, put the double quotes back inside, but it looks quite > kludgy. You can put the double quotes around the whole path instead of just around "Program Files" in the call to Popen(). The issue here is actually that os.path.exists() (and all other Python functions) use the path exactly like you pass it; but with your call to Popen(), the path is passed as an argument to the shell, and it needs to be quoted for the shell to interpret that correctly. So here's what I would do: first specify the path literally without quotes, and quote it only when needed: path = r'C:/Program Files/testfolder/2.3/test.txt' if os.path.lexists(path): print 'Path Exists' else: print 'No file found in path - %s' %path print Popen('"%s"' % path, stdout=PIPE, shell=True).stdout.read() Some other notes: - Since you use forward slashes, there's no need to use a raw string literal. - You can just as well use os.path.exists() instead of os.path.lexists(). The difference has to do with symbolic links, which Windows doesn't have. - I'm not sure what you expect the line with Popen to do. On my system, it opens the specified text file in notepad and returns an empty string. If that's what you want to do, it's easier with os.startfile(). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From gklein at xs4all.nl Sun Nov 1 06:07:03 2009 From: gklein at xs4all.nl (Gertjan Klein) Date: Sun, 01 Nov 2009 12:07:03 +0100 Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: Alf P. Steinbach wrote: >* Gertjan Klein: >> I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after >> creating an empty (0-byte) test file; after the write() the read() >> returns random garbage. I can't imagine why anyone would want that >> behaviour. The file grew to be 4099 bytes after f.close(). I wrote >> 'hello' to it, so the length of garbage added was 4094 bytes, which I >> find a strange number also. > >Could you post (copy and paste) the code, and description of results? The code is exactly the OP's code, with an f.close() after f.read(). The results are described above. >"Shall not" means UB. This applies to C "FILE*" handling. Yes. But Python is not C. I would have expected that Python shields me from such bizarre results. The fact that, apparently, the Python file object is a thin wrapper over a C library function is an explanation of the behaviour, but not a justification. >And for a language used by so many newbies (this is positive!) I agree that it >should ideally get rid of that UB (assuming that's what the problem is), or, if >it doesn't already, mention that in the Python documentation. I'm not sure I can defend this statement, but I think Python should not have undefined behaviour at all. Gertjan. From mnordhoff at mattnordhoff.com Sun Nov 1 06:17:25 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sun, 01 Nov 2009 11:17:25 +0000 Subject: problem with read() write() In-Reply-To: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: <4AED6E45.9080000@mattnordhoff.com> Gertjan Klein wrote: > Alf P. Steinbach wrote: > >> So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >> file, or 'open' doesn't conform to the documentation. > > It does read beyond the end of file. This is perhaps the way the > underlying C library works, but it looks like an "unexpected feature" > (read: bug) to me. > > I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after > creating an empty (0-byte) test file; after the write() the read() > returns random garbage. I can't imagine why anyone would want that > behaviour. The file grew to be 4099 bytes after f.close(). I wrote > 'hello' to it, so the length of garbage added was 4094 bytes, which I > find a strange number also. > > I would have expected the read to return nothing. Can anyone explain or > even defend this behaviour? > > Gertjan. I wonder, does it still happen if you open the file in binary mode? (Stick a "b" in the file mode.) It could be some Windows text mode craziness. -- From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 06:29:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 11:29:24 GMT Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: <02fd5f79$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 10:44:45 +0100, Alf P. Steinbach wrote: > Could you post (copy and paste) the code, and description of results? Using Python 2.6 under Linux (Fedora 7): >>> f = open('garbage', 'r') # prove the file doesn't exist Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'garbage' >>> f = open('garbage', 'wb+') >>> f.read(4) '' >>> f.write('hello world\n') >>> f.seek(0) >>> f.read(100) 'hello world\n' -- Steven From cousinstanley at gmail.com Sun Nov 1 08:23:25 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 1 Nov 2009 13:23:25 +0000 (UTC) Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: > .... > There are an infinite number of empty sets > that differ according to their construction: > .... > The set of all fire-breathing mammals. > .... Apparently, you have never been a witness to someone who recently ingested one of Cousin Chuy's Super-Burritos .......... :-) -- Stanley C. Kitching Human Being Phoenix, Arizona From davea at ieee.org Sun Nov 1 08:34:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 08:34:31 -0500 Subject: stdin in embedded python In-Reply-To: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: <4AED8E67.1060809@ieee.org> KillSwitch wrote: > I have a C++ program, with a GUI, into which I have embedded python. I > have made several python functions in C++, one of which I use to > override the normal stdout and stderr so that they print to a text box > of my GUI. One thing I cannot think of how to do is to redefine stdin > so that it pauses the program, waits for a user to type input into the > box, hit enter, and takes input from another text element and sends it > to python like it was the console. > > I wonder if anyone could help me in trying to do such a thing. To > simplify, the new stdin should wait for the C++ function to give it a > value, like it waits for the console. > > I suspect you don't really want to redirect stdin, but instead implement raw_input(). If you have control over the script, just change it from raw_input() to cpp_raw_input(). But if you need to be able to run arbitrary scripts, ... (untried) - Try changing __builtins__.raw_input to reference your new function. DaveA From pengyu.ut at gmail.com Sun Nov 1 09:07:37 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:07:37 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0c56$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <02fd0c56$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010607h14b6dd60he2783e5370b38034@mail.gmail.com> On Sat, Oct 31, 2009 at 11:34 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: > >>>> In my question, module A and B exist just for the sake of >>>> implementation. Even if I have module A and B, I don't want the user >>>> feel the existence of module A and B. I want them feel exact like >>>> class A and B are defined in module 'test' instead of feeling two >>>> modules A and B are in package 'test'. >>> >>> >>> Inside test/__init__.py: >>> >>> from A import A ?# class A from file A.py >>> from B import B ?# class B from file B.py >> >> I can not use the above approach as I mentioned its problem in my >> previous message. > > Either I have not seen it, or I have not understood it, but I don't > understand why you can not use this approach. The problem is when you test a package you want to 'import test.A' rather than 'import test'. Having such __init__.py does not allow you to import only 'test.A'. This cause artificial dependence. >>> or better still: >>> >>> from a import A ?# class A from file a.py >>> from b import B ?# class B from file b.py >> >> This artificially introduces the constraint that the file name can not >> be the same as the class/function name. There is no constraint like this >> if I can C++. > > It is not a constraint, it is a convention. You are free to ignore it if > you like. I'm ignoring this convention now. But I have to call a function like glob.glob, which I also feel inconvenient. > Some people don't like writing "glob.glob" (for example). Some people > would like to see Python ban modules with the same name as objects inside > them, to avoid this error: > >>>> import datetime > ... much later >>>> from datetime import datetime >>>> datetime.datetime() > Traceback (most recent call last): > ?File "", line 1, in > AttributeError: type object 'datetime.datetime' has no attribute > 'datetime' > > > You seem to be inconsistent -- you say you want to name the file the same > as the function in it, so you know which file to look for a function, but > then you complain about writing: > > test.A.A > > so when we suggest naming A.py a.py, so you can write: > > test.a.A > > you complain about that too. Frankly, I think you are just complaining > because Python isn't C++. I'm not complaining. I just wish there is a walkaround. In C++, I still have to write some script to make sure the directory hierarchy is consistent with the namespace, because C++ doesn't impose the constraint that the directory hierarchy is the same as the namespace. But it seems that is no such walkaround in python for my case, because python binds namespace to directory hierarchy. >>>> I know that module names should be in lower cases, in general. >>>> However, it is OK to have the module name capitalized in this case >>>> since the end users don't see them. >>> >>> Of course they do. >> >> This sentence is confusing. Can you spell out what you mean? > > If you supply a package > > test/ > +-- ?__init__.py > +-- ?A.py > +-- ?B.py > > > there is nothing stopping your users from doing this: > > import test.A as A > import test.B as SomethingElse First, this is a redudancy---'A' appears twice. Second, you can not do something like the following, because name A from the two name space is conflict. import test.A as A import test2.A as A > [...] >> I have defined 'long' in one of my previous message. I consider a file >> long, when it does not fit in one or two screen. Basically, I want to >> get a whole picture of the file after glancing of the file. > > You must only write incredibly trivial programs then. > > There is more to understanding a program than understanding one single > function. Any serious function will call other functions. To get the > whole picture, you have to understand them too. Your requirement simply > shifts the burden from "open one file, and read ten functions" to "open > ten files, and read ten functions". I insist on having screen long functions or classes, because they have less number of states compare with long ones. This allows me to test all the states of them to make sure they are bug free. It is reasonable to assume the log of the number of states of a function or a class is proportional to it length. Hence, when a function or a class is long, you will never be able to test all its states. I don't have to put all related functions in a single file. With vim and ctags, you should be able to jump to the definition of any function or class from the place where it is used. So putting single class/function in a file does not give me any extra 'burden' than if I put them in the same file. From mwilson at the-wire.com Sun Nov 1 09:11:26 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 01 Nov 2009 09:11:26 -0500 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > (6) Metaphoric equivalence: > Kali is death. > Life is like a box of chocolates. OK to here, but this one switches between metaphor and simile, and arguably, between identity and equality. Mel. From pengyu.ut at gmail.com Sun Nov 1 09:13:11 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:13:11 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0e55$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <02fd0e55$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: > >> So python would not be able to accommodate my preference one >> class/function per file? > > Of course it does! You can do that RIGHT NOW -- just put one class per > file. > >> I.e., I have to use something like 'from spam >> import spam' or 'spam.spam()', > > How else do you expect to use the class if you don't import it? > > >> or accept that the filename is not the >> same as the class/function name. > > So let me see... > > You don't want to write "import spam; spam.spam()" > You don't want to write "from spam import spam; spam()" > You don't want to write "from Spam import spam; spam()" > You don't want to write "from spam import Spam; Spam()" > > What exactly do you want? When I define class spam in file spam.py, I want to call it by import spam spam() If spam.py is in dir/, then I want to call it by import dir.spam dir.spam() From WanderingAengus at comcast.net Sun Nov 1 09:20:06 2009 From: WanderingAengus at comcast.net (Robinson) Date: Sun, 1 Nov 2009 07:20:06 -0700 Subject: Can I run a python program from within emacs? Message-ID: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> I have also just started with both Aquamacs and Python so I ask for your patience as well. When I evaluate the buffer (C-c C-C) I don't see any response or output from my python program. Should another buffer open automatically? Should a terminal window open? thanks for your patience. Rugbeia Floreat Ubique > On Mar 20, 3:09 pm, jmDesktop wrote: > > Hi, I'm trying to learn Python. I using Aquamac an emac > > implementation with mac os x. I have a program. If I go to the > > command prompt and type pythong myprog.py, it works. Can the > program > > be run from within the editor or is that not how development is > done? > > I ask because I was using Visual Studio with C# and, if you're > > familiar, you just hit run and it works. On Python do I use the > > editor for editing only and then run the program from the command > > line? Thank you. > > Aquamacs, just like any variant of GNU Emacs, will show a Python > menu. There's a "Start Interpreter" function, and one to evaluate the > buffer (C-c C-c). It's pretty straightforward (a euphemism for > obvious). > > If the Python menu doesn't show, then something is going wrong. M-x > python-mode RET would switch it on. > > > -- > http://aquamacs.org -- Aquamacs: Emacs on Mac OS X > http://aquamacs.org/donate -- Could we help you? Return the favor and > support the Aquamacs Project! From bieffe62 at gmail.com Sun Nov 1 09:27:23 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Sun, 1 Nov 2009 06:27:23 -0800 (PST) Subject: Looking for help getting tkinter to work. References: <9e15ab12-c826-4227-9a0c-82d3eccb96a0@r24g2000prf.googlegroups.com> Message-ID: <9d0c476a-86f7-4a8a-a01b-e260060c7bcc@a31g2000yqn.googlegroups.com> On Nov 1, 4:06?am, Shue Boks wrote: > I tried to compile Python and Tcl/Tk on Linux using the following > files: > > Python-3.1.1.tar.gz > tcl8.5.7-src.tar.gz > > Cannot get tkinter to work after compiling & installing Tcl/Tk. ?I get > the following error after compiling Python: > > "Python build finished, but the necessary bits to build these modules > were not found: > _tkinter > To find the necessary bits, look in setup.py in detect_modules() for > the module's name." > > Are the above files the correct versions to get tkinter to work? > > Thanks. The version should be ok. I just compiled python3.1 against tcl/tk 8.5, only I used the tcl/tk development packages coming with my distribution (Ubuntu). I used ./configure --with-tk, so if you did not, try that first. Did you run 'make install' during tcl/tk installation _before_ doing ./ configure in python source directory? If so, look where the library files ( e.g. libtk8.5.so ) and include files (e.g tk.h ) have been placed and check against the places where the function 'detect_tkinter' in 'setup.py' looks for them. Ciao ----- FB From pengyu.ut at gmail.com Sun Nov 1 09:44:19 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:44:19 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: > >>> Variables in a function are already private. ?How can the names in one >>> function be affected by other functions in the same module? >> >> You misunderstood me. >> >> If there are multiple functions or classes in a file, when I change >> variables in a function/class, I have to make sure that they are not in >> other functions or classes. > > No you don't. > > def f(x): > ? ?return x+1 > > def g(x): > ? ?return x-1 > > > If I choose to refactor f() and change "x" to "y", why do I care about > the internal variable inside g()? What I mean was, for example, I only want to change 'x' in f() to 'y', but not 'x' in g() to 'y', because the meaning of 'x' in f() and 'x' in g() may represent different things. If both f() and g() are in the same file, I have to make sure that I only replace 'x' in f() but not in g(). However, if I only have f() in a file, I can simply replace all x in the file without worrying replacing 'x' in g(). Is this clear? > Oh wait, I get it... you want to do a global search-and-replace over the > entire file. *face-palm* Yes. You get it. > If your functions are less than one-screen full, why do you need a global > replacement? Global replacement risks changing words in docstrings, > comments etc that it shouldn't. My variables in general are not as short as a single letter, like 'x', and is descriptive. In general, they will not appear in docstrings, unless the ones in docstrings mean the same thing, in which case it is OK to replace the variable and the one in docstrings. From arts.martijn at gmail.com Sun Nov 1 09:49:46 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Sun, 1 Nov 2009 15:49:46 +0100 Subject: Pyfora, a place for python In-Reply-To: <7xpr82y9bz.fsf@ruckus.brouhaha.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <7xpr82y9bz.fsf@ruckus.brouhaha.com> Message-ID: <23739e0a0911010649q697874d5lf752fe825a904f44@mail.gmail.com> I think it's a really good idea :) My accountname is "TotempaaltJ" On Sun, Nov 1, 2009 at 8:48 AM, Paul Rubin wrote: > Saketh writes: > > I am proud to announce the release of Pyfora (http://pyfora.org), an > > online community of Python enthusiasts to supplement comp.lang.python > > and #python. > > And the reason to want to further fragment Python discussion is > exactly what? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jasonsewall at gmail.com Sun Nov 1 11:15:25 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Sun, 1 Nov 2009 11:15:25 -0500 Subject: Can I run a python program from within emacs? In-Reply-To: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> References: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> Message-ID: <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> On Sun, Nov 1, 2009 at 9:20 AM, Robinson wrote: > I have also just started with both Aquamacs and Python so I ask for your > patience as well. > When I evaluate the buffer (C-c C-C) I don't see any response or output from > my python program. Should another buffer open automatically? Should a > terminal window open? I don't know much about Aquamacs or the version of Emacs the Aquamacs you are using is based on, but the C-c C-c command runs py-execute-buffer. Try M-x py-execute-buffer and see what happens. It should pop up a *Python Output* buffer, unless you're actually running the python interpreter in Emacs, in which case the code is run in that buffer. If you're still having trouble, probably an Emacs or Aquamacs list is a better place to look. Jason From omarimanway at gmail.com Sun Nov 1 11:33:02 2009 From: omarimanway at gmail.com (omer azazi) Date: Sun, 1 Nov 2009 08:33:02 -0800 (PST) Subject: What is Islam?-1 References: <5e32081e-ce29-4ece-9643-d579a610ec96@z24g2000yqb.googlegroups.com> <5e843d95-a028-4551-a871-2602b883ffc1@f21g2000vbm.googlegroups.com> <7fc212cf-3710-4ec5-86cd-e3fe1626dd83@o21g2000vbl.googlegroups.com> <87k4yi4qp3.fsf@benfinney.id.au> Message-ID: from python to exe py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built. see here http://www.py2exe.org/index.cgi/Tutorial http://www.py2exe.org/ http://www.scribd.com/doc/19792648/-python-to-exe also eclipse editor>>> http://www.eclipse.org/downloads/ thank u again From gu.yakahughes at gmail.com Sun Nov 1 11:34:44 2009 From: gu.yakahughes at gmail.com (KillSwitch) Date: Sun, 1 Nov 2009 08:34:44 -0800 (PST) Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: On Nov 1, 5:34?am, Dave Angel wrote: > KillSwitch wrote: > > I have a C++ program, with a GUI, into which I have embedded python. I > > have made several python functions in C++, one of which I use to > > override the normal stdout and stderr so that they print to a text box > > of my GUI. One thing I cannot think of how to do is to redefine stdin > > so that it pauses the program, waits for a user to type input into the > > box, hit enter, and takes input from another text element and sends it > > to python like it was the console. > > > I wonder if anyone could help me in trying to do such a thing. To > > simplify, the new stdin should wait for the C++ function to give it a > > value, like it waits for the console. > > I suspect you don't really want to redirect stdin, but instead implement > raw_input(). ?If you have control over the script, just change it from > raw_input() to cpp_raw_input(). ?But if ?you need to be able to run > arbitrary scripts, ... > > (untried) - Try changing __builtins__.raw_input ?to reference your new > function. > > DaveA But what would the function do? How would it pause python and wait for it to have text to send? From rustompmody at gmail.com Sun Nov 1 12:15:07 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 1 Nov 2009 09:15:07 -0800 (PST) Subject: Can I run a python program from within emacs? References: Message-ID: <892a4877-0391-4386-a14f-b66e1b216d49@m3g2000pri.googlegroups.com> On Nov 1, 7:20?pm, Robinson wrote: > I have also just started with both Aquamacs and Python so I ask for ? > your patience as well. > When I evaluate the buffer (C-c C-C) I don't see any response or ? > output from my python program. Should another buffer open ? > automatically? Should a terminal window open? > thanks for your patience. > Rugbeia Floreat Ubique > > > On Mar 20, 3:09 pm, jmDesktop wrote: > > > Hi, I'm trying to learn Python. ?I using Aquamac an emac > > > implementation with mac os x. ?I have a program. ?If I go to the > > > command prompt and type pythong myprog.py, it works. ?Can the ? > > program > > > be run from within the editor or is that not how development is ? > > done? There are two python modes -- python.el and python-mode.el Default with emacs is python.el, what comes from/with python is python- mode.el (needs a download and a couple of lines of setup see http://www.emacswiki.org/emacs/PythonMode). I recommend python-mode. The key-bindings are different --C-c ! to start interpreter followed by C-c C-c to exec a file. From WanderingAengus at comcast.net Sun Nov 1 12:16:45 2009 From: WanderingAengus at comcast.net (Robinson) Date: Sun, 1 Nov 2009 10:16:45 -0700 Subject: Can I run a python program from within emacs? In-Reply-To: <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> References: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> Message-ID: <87495589-2D5A-4353-AC16-5E69806D7886@comcast.net> Jason, Thanks, but I have already tried your suggestions (which seem like logical cause/effect actions) and nothing. There must be a python preference or something I haven't set correctly. There is no Aquamacs list, but I'll check further. Thanks again for the quick reply. On Nov 1, 2009, at 9:15 AM, Jason Sewall wrote: > On Sun, Nov 1, 2009 at 9:20 AM, Robinson > wrote: >> I have also just started with both Aquamacs and Python so I ask for >> your >> patience as well. >> When I evaluate the buffer (C-c C-C) I don't see any response or >> output from >> my python program. Should another buffer open automatically? Should a >> terminal window open? > > I don't know much about Aquamacs or the version of Emacs the Aquamacs > you are using is based on, but the C-c C-c command runs > py-execute-buffer. Try M-x py-execute-buffer and see what > happens. It should pop up a *Python Output* buffer, unless you're > actually running the python interpreter in Emacs, in which case the > code is run in that buffer. > > If you're still having trouble, probably an Emacs or Aquamacs list is > a better place to look. > > Jason From daniel at stutzbachenterprises.com Sun Nov 1 12:52:03 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Sun, 1 Nov 2009 12:52:03 -0500 Subject: ANN: blist 1.0.2 Message-ID: blist 1.0.2 is now available: http://pypi.python.org/pypi/blist/ What is blist? -------------- The blist is a type that looks, acts, and quacks like a Python list, but has better asymptotic performance when inserting or deleting elements (O(log n)). For small lists, blists and the built-in list have very similar performance. The blist also features copy-on-write behavior, so copying or taking large slices from a list is inexpensive. What's new? ----------- blist version 1.0.2 includes two important bug fixes: - Fixed a crash in the .index method, which was not properly sanitizing the optional arguments. - Fixed a possible crash when modifying the blist during iteration Other changes include: - Changed int to Py_ssize_t in several places for better 64-bit hygiene - Removed some over-zealous assertion checks that were causing crashes in oddball (but legal!) cases in debug builds - Ported tests to run under Python 2.6 and Python 3.1 (but no longer Python 2.5) - Got rid of warnings on non-ix86 platforms -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sun Nov 1 14:46:42 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 13:46:42 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano > wrote: >> Oh wait, I get it... you want to do a global search-and-replace over the >> entire file. *face-palm* > > Yes. You get it. In any capable programmer's editor, it should not be hard to do a local search-and-replace over just the one function. -- 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 Sun Nov 1 14:47:18 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 13:47:18 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <02fd0e55$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano > wrote: >> On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: >> >>> So python would not be able to accommodate my preference one >>> class/function per file? >> Of course it does! You can do that RIGHT NOW -- just put one class per >> file. >> >>> I.e., I have to use something like 'from spam >>> import spam' or 'spam.spam()', >> How else do you expect to use the class if you don't import it? >> >> >>> or accept that the filename is not the >>> same as the class/function name. >> So let me see... >> >> You don't want to write "import spam; spam.spam()" >> You don't want to write "from spam import spam; spam()" >> You don't want to write "from Spam import spam; spam()" >> You don't want to write "from spam import Spam; Spam()" >> >> What exactly do you want? > > When I define class spam in file spam.py, I want to call it by > > import spam > spam() > > If spam.py is in dir/, then I want to call it by > > import dir.spam > > dir.spam() That's just not how Python imports work. -- 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 lord_eldritch at yahoo.co.uk Sun Nov 1 14:53:25 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Sun, 01 Nov 2009 20:53:25 +0100 Subject: Tkinter callback arguments Message-ID: Hi Maybe this is maybe something it has been answered somewhere but I haven't been able to make it work. I wanna pass one variable to a callback function and I've read the proper way is: Button(......, command=lambda: function(x)) So with def function(a): print a I get the value of x. Ok. My problem now is that I generate the widgets in a loop and I use the variable to 'label' the widget: for x in range(0,3): Button(......, command=lambda: function(x)) so pressing each button should give me 0,1,2. But with the lambda, I always get the last index, because it gets actualized at each loop cycle. Is there any way to get that? Thanks in advance! -- Lord Eldritch From lord_eldritch at yahoo.co.uk Sun Nov 1 14:53:25 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Sun, 01 Nov 2009 20:53:25 +0100 Subject: Tkinter callback arguments Message-ID: Hi Maybe this is maybe something it has been answered somewhere but I haven't been able to make it work. I wanna pass one variable to a callback function and I've read the proper way is: Button(......, command=lambda: function(x)) So with def function(a): print a I get the value of x. Ok. My problem now is that I generate the widgets in a loop and I use the variable to 'label' the widget: for x in range(0,3): Button(......, command=lambda: function(x)) so pressing each button should give me 0,1,2. But with the lambda, I always get the last index, because it gets actualized at each loop cycle. Is there any way to get that? Thanks in advance! -- Lord Eldritch From python at mrabarnett.plus.com Sun Nov 1 15:13:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 01 Nov 2009 20:13:26 +0000 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: <4AEDEBE6.1080805@mrabarnett.plus.com> Lord Eldritch wrote: > Hi > > Maybe this is maybe something it has been answered somewhere but I haven't > been able to make it work. I wanna pass one variable to a callback function > and I've read the proper way is: > > Button(......, command=lambda: function(x)) > > So with > > def function(a): print a > > I get the value of x. Ok. My problem now is that I generate the widgets in a > loop and I use the variable to 'label' the widget: > > for x in range(0,3): Button(......, command=lambda: function(x)) > > so pressing each button should give me 0,1,2. > > But with the lambda, I always get the last index, because it gets actualized > at each loop cycle. Is there any way to get that? > A lambda expression is just an unnamed function. At the point the function is /called/ 'x' is bound to 3, so that's why 'function' is always called with 3. A function's default arguments are evaluated when the function is /defined/, so you can save the current value of 'x' creating the function (the lambda expression, in this case) with a default argument: for x in range(0,3): Button(......, command=lambda arg=x: function(arg)) The following will also work, although you might find the "x=x" a bit surprising/confusing if you're not used to how Python works: for x in range(0,3): Button(......, command=lambda x=x: function(x)) From mad.mick at gmx.de Sun Nov 1 15:32:15 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 01 Nov 2009 21:32:15 +0100 Subject: list comprehension problem In-Reply-To: <02fd0755$0$1326$c3e8da3@news.astraweb.com> References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There are an infinite number of empty sets that differ according to their > construction: > > The set of all American Presidents called Boris Nogoodnik. > The set of all human languages with exactly one noun and one verb. > The set of all fire-breathing mammals. > The set of all real numbers equal to sqrt(-1). > The set of all even prime numbers other than 2. > The set of all integers between 0 and 1 exclusive. > The set of all integers between 1 and 2 exclusive. > The set of all positive integers between 2/5 and 4/5. > The set of all multiples of five between 26 and 29. > The set of all non-zero circles in Euclidean geometry where the radius > equals the circumference. > ... Logically, they're all the same, by extensionality. There is of course a difference between the reference of an expression and it's meaning, but logical truth only depends on reference. In mathematical logic 'the thing, that ...' can be expressed with the iota operator (i...), defined like this: ((ia)phi e b) := (Ec)((c e b) & (Aa)((a = b) <-> phi)). with phi being a formula, E and A the existential and universal quantors, resp., e the membership relation, & the conjunction operator and <-> the bi-conditional operator. When we want find out if two sets s1 and s2 are the same we only need to look at their extensions, so given: (i s1)(Ay)(y e s1 <-> y is a fire-breathing animal) (i s2)(Ay)(y e s2 <-> y is a real number equal to sqrt(-1)) we only need to find out if: (Ax)(x is a fire-breathing animal <-> x is a real number equal to sqrt(-1)). And since there are neither such things, it follows that s1 = s2. BTW, '=' is usually defined as: a = b := (AabP)(Pa <-> Pb) AKA the Leibniz-Principle, but this definition is 2nd order logic. If we have sets at our disposal when we're axiomatisizing mathematics, we can also define it 1st-orderly: a = b := (Aabc)((a e c) <-> (b e c)) Regargs, Mick. From gagsl-py2 at yahoo.com.ar Sun Nov 1 15:34:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 17:34:19 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano escribi?: > On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: >>> Incorrect. Simplicity of implementation and API is a virtue, in and of >>> itself. The existing module machinery is quite simple to understand, >>> use and maintain. >> >> Uhm... module objects might be quite simple to understand, but module >> handling is everything but simple! (simplicity of implem...? quite >> simple to WHAT? ROTFLOL!!! ) > > I stand corrected :) > Nevertheless, the API is simple: the first time you "import name", Python > searches a single namespace (the path) for a module called name. There > are other variants of import, but the basics remain: > > search the path for the module called name, and do something with the > first one you find. Sure, beautiful, a plain and simple search over a list of directories. That's how it worked in Python 1.4, I think... Now you have lots of "hooks" and even "meta-hooks": sys.meta_path, sys.path_hooks, sys.path_importer_cache. And sys.path, of course, which may contain other things apart of directory names (zip files, eggs, and even instances of custom "loader" objects...). PEP 302 explains this but I'm not sure the description is still current. PEP369, if approved, would add even more hooks. Add packages to the picture, including relative imports and __path__[] processing, and it becomes increasingly harder to explain. Bret Cannon has rewritten the import system in pure Python (importlib) for 3.1; this should help to understand it, I hope. The whole system works, yes, but looks to me more like a collection of patches over patches than a coherent system. Perhaps this is due to the way it evolved. >>> Dealing with name clashes doesn't come for free. If you think it does, >>> I encourage you to write a patch implementing the behaviour you would >>> prefer. >> >> I'd say it is really a bug, and has existed for a long time. > > Since import is advertised to return the first module with the given name > it finds, I don't see it as a bug even if it doesn't do what the > programmer intended it to do. [...] Shadowing a standard library module > is no different. But that's what namespaces are for; if the standard library had its own namespace, such collisions would not occur. I can think of C++, Java, C#, all of them have some way of qualifying names. Python too - packages. But nobody came with a method to apply packages to the standard library in a backwards compatible way. Perhaps those name collisions are not considered serious. Perhaps every user module should live in packages and only the standard library has the privilege of using the global module namespace. Both C++ and XML got namespaces late in their life so in principle this should be possible. >> One way to >> avoid name clashes would be to put the entire standard library under a >> package; a program that wants the standard re module would write "import >> std.re" instead of "import re", or something similar. Every time the std >> package is suggested, the main argument against it is backwards >> compatibility. > > You could do it in a backwards compatible way, by adding the std package > directory into the path. Unfortunately you can't, at least not without some special treatment of the std package. One of the undocumented rules of the import system is that you must not have more than one way to refer to the same module (in this case, std.re and re). Suppose someone imports std.re; an entry in sys.modules with that name is created. Later someone imports re; as there is no entry in sys.modules with such name, the re module is imported again, resulting in two module instances, darkness, weeping and the gnashing of teeth :) (I'm sure you know the problem: it's the same as when someone imports the main script as a module, and gets a different module instance because the "original" is called __main__ instead). -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Sun Nov 1 15:39:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 01 Nov 2009 20:39:37 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach wrote: > * Rhodri James: >> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >> wrote: >>> with the best knowledge of the program's environment, is unable to >>> handle (such as delete) files or folders with paths greater than some >>> 260 characters, is unable to handle filenames that differ only in case >>> and are in the same directory, and is unable to e.g. delete a folder >>> called "con" -- although such files & folders can very easily be >>> created. >> You may or may not be aware that some of these things are limitations >> of >> the underlying disc format, > > Sorry no, it isn't. > > Even assuming you meant the more reasonable "file system", no, it isn't. Actually I should have mentioned the filing system as well as the disc format (which does matter). I may not be using correct Windows terminology, since I'm referring to both the bytes on hardware and the software stack that terminates in the OS API. Still, colour me surprised. I had assumed that NTFS had some (large) limit on filenames, and 256 sounded plausible. More to the point, I was under the impression that path manipulation logic in the filing system had limited sized buffers, which were the cause of this fault, and that Exploder's only sin was not programming around the bug. In fact, the more I think about it, the more sure I am that I've had to play silly buggers on the command line myself to get around this. > Depending on the file system a program may be unable to create such > things as I mentioned. And depending on the program design it may be > reasonable to refuse to create them. > > But a program should have no trouble deleting the files etc. once > they're there. Your faith is touching, but fundamentally misplaced. > That's why the Windows API handles them just fine, while Windows > Explorer does not. You may consider, since you're unfamiliar with the > API, that mostly it's no problem doing these things in the command > interpreter, which has no special support (rather, the reason it's easy > is because it doesn't properly check command arguments). And from that > you can deduce that the API support is there. Having stuffed this up many, many years ago, my recollection is that it needed a certain deviousness to get around. In the case of the long path names, my deduction from comparing the behaviours of the command line and Explorer was that the API limited the path name length, and Explorer didn't use relative paths to get around it. I find it hard to call that a bug, when it's only really exposing a limitation of the underlying FS. >>> For example, for general tool usage in Windows the student needs to >>> know about levels of environment variable specifications and file >>> associations, which in turn requires knowledge of processes and the >>> Windows registry database and various commands. >> Mercifully this is rubbish. For most purposes with most tools even >> Windows users don't need to know much if anything about environment >> variables and the registry. Needing to know anything about the >> registry is usually a sign that Windows has stuffed you up royally. > > I deduce that you mainly use IDEs and don't know about the things you're > commenting on here (more than you did above). Sorry, but there it is. You deduce incorrectly. I'd unbend enough to admit that setting environment variables is frequently very useful to inveterate command- line users like myself, and that Windows makes that a lot harder than necessary, but your original statement still reads like scaremongering. Why am I defending Windows again? -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Nov 1 15:45:46 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 01 Nov 2009 20:45:46 -0000 Subject: Feedback desired on reworked ch 1 progr. intro (now Python 3.x, Windows) In-Reply-To: References: Message-ID: Before we start, can I just say that I find Google Docs loathsome? On Sat, 31 Oct 2009 07:40:36 -0000, Alf P. Steinbach wrote: > I hope this new version of ch 1 is, well, better, addresses some of the > concerns raised? Section 1.1 needs serious work. You have a very assertive writing style and a lot of things that you definitively state are at best debatable. If I'd picked that up in a shop and browsed that opening, I'd put the book down and walk away; essentially you're calling your accuracy into question before you've even said anything about programming. -- Rhodri James *-* Wildebeest Herder to the Masses From gagsl-py2 at yahoo.com.ar Sun Nov 1 16:02:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 18:02:03 -0300 Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch escribi?: > On Nov 1, 5:34 am, Dave Angel wrote: >> KillSwitch wrote: >> > I have a C++ program, with a GUI, into which I have embedded python. I >> > have made several python functions in C++, one of which I use to >> > override the normal stdout and stderr so that they print to a text box >> > of my GUI. One thing I cannot think of how to do is to redefine stdin >> > so that it pauses the program, waits for a user to type input into the >> > box, hit enter, and takes input from another text element and sends it >> > to python like it was the console. >> >> I suspect you don't really want to redirect stdin, but instead implement >> raw_input(). [...]Try changing __builtins__.raw_input to reference >> your new >> function. > > But what would the function do? How would it pause python and wait for > it to have text to send? Whatever you want. You don't have to "pause python", Python itself won't resume until your function doesn't return. (You should release the GIL if your C++ function doesn't call back to Python code, to allow other threads to continue, but that's another story). This is a raw_input replacement written in Tkinter; it shows a dialog box instead of reading from stdin: py> from Tkinter import * py> from tkSimpleDialog import askstring py> def my_raw_input(prompt): ... return askstring("Python", prompt) ... py> root = Tk() py> import __builtin__ py> __builtin__.raw_input = my_raw_input py> py> raw_input("What's your name?") 'Gabriel' -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: ClipBoard-1.png Type: image/png Size: 5666 bytes Desc: not available URL: From jabba.laci at gmail.com Sun Nov 1 16:02:25 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 1 Nov 2009 16:02:25 -0500 Subject: __str__ difficulty with lists Message-ID: <310fbb00911011302g18661ccawa970109364202e66@mail.gmail.com> Hi, I have a list that contains custom objects. When printing the list, I'd like to have a readable result, i.e. I'd like to see the output of the __str__ functions. See an example below. When I call "print li", I would like to get "[3, 5]". How to do that? Thanks, Laszlo ========== class MyNumber: def __init__(self, n): self.n = n def __str__(self): return str(self.n) if __name__ == "__main__": li = [] a = MyNumber(3) li.append(a) li.append(MyNumber(5)) print li # [<__main__.MyNumber instance at 0xb77a456c>, <__main__.MyNumber instance at 0xb77a46ec>] print a # 3 From alfps at start.no Sun Nov 1 16:20:20 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 22:20:20 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: >>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>> wrote: >>>> with the best knowledge of the program's environment, is unable to >>>> handle (such as delete) files or folders with paths greater than >>>> some 260 characters, is unable to handle filenames that differ only >>>> in case and are in the same directory, and is unable to e.g. delete >>>> a folder called "con" -- although such files & folders can very >>>> easily be created. >>> You may or may not be aware that some of these things are >>> limitations of >>> the underlying disc format, >> >> Sorry no, it isn't. >> >> Even assuming you meant the more reasonable "file system", no, it isn't. > > Actually I should have mentioned the filing system as well as the disc > format (which does matter). I may not be using correct Windows > terminology, > since I'm referring to both the bytes on hardware and the software stack > that terminates in the OS API. > > Still, colour me surprised. I had assumed that NTFS had some (large) > limit on filenames, and 256 sounded plausible. For NTFS it's 32K or 64K wide characters, I don't recall which. But what's important is that that's also the API level limit. You can find most of the details in Microsoft's documentation of CreateFile (but it's off-topic here). Given that the API level makes it possible for long paths/names to exist, a program should be prepared to handle them, although it may reasonably refuse to create them. Windows Explorer fails to handle them. Not only to create them. A filesystem may impose a lower limit, but a program should ideally not be limited to or just work with a given filesystem (note: Windows supports multiple different filesystems, but accessed via the same general API). > More to the point, I > was under the impression that path manipulation logic in the filing > system had limited sized buffers, which were the cause of this fault, > and that Exploder's only sin was not programming around the bug. In > fact, the more I think about it, the more sure I am that I've had to > play silly buggers on the command line myself to get around this. > >> Depending on the file system a program may be unable to create such >> things as I mentioned. And depending on the program design it may be >> reasonable to refuse to create them. >> >> But a program should have no trouble deleting the files etc. once >> they're there. > > Your faith is touching, but fundamentally misplaced. By the facts, if I believed that most programs have no problem it would be a misplaced belief, yes (assuming that's what you mean above). But my argument and concrete example was the opposite. It expanded on my statement that "Unfortunately even most professional programs do not handle the requirements of their environs very well" So in what you quoted above I used "should" in the sense of the ideal to strive for, and illustrated the harsh reality that it currently isn't that way, by the concrete Windows Explorer example. This is worth keeping in mind: in a Usenet discussion, context often disappears. Looking up-thread is then one way to find out what it's all about. :-) >> That's why the Windows API handles them just fine, while Windows >> Explorer does not. You may consider, since you're unfamiliar with the >> API, that mostly it's no problem doing these things in the command >> interpreter, which has no special support (rather, the reason it's >> easy is because it doesn't properly check command arguments). And from >> that you can deduce that the API support is there. > > Having stuffed this up many, many years ago, my recollection is that > it needed a certain deviousness to get around. Yes. C:\> md rhodri & cd rhodri C:\rhodri> md \\?\c:\rhodri\con C:\rhodri> dir Volume in drive C is maindisk Volume Serial Number is C469-4FA2 Directory of C:\rhodri 01.11.2009 22:16 . 01.11.2009 22:16 .. 01.11.2009 22:16 con 0 File(s) 0 bytes 3 Dir(s) 18 405 834 752 bytes free C:\rhodri> cd con The system cannot find the path specified. C:\rhodri> cd \\?\c:\rhodri\con '\\?\c:\rhodri\con' CMD does not support UNC paths as current directories. C:\rhodri> rd \\?\c:\rhodri\con C:\rhodri> _ To keep it short the above example is of something that no program really is expected to handle. It's just an example of the mechanisms involved. Also, it's nice with concrete examples, to show that one is not just blowing wind. :-) > In the case of the long > path names, my deduction from comparing the behaviours of the command > line and Explorer was that the API limited the path name length, and > Explorer didn't use relative paths to get around it. I find it hard > to call that a bug, when it's only really exposing a limitation of the > underlying FS. No, it's not exposing a limitation of the underlying FS. It's exposing a limitation in the way that the program deals with paths. Apparently Windows Explorer uses fixed size buffers for paths, rather small buffers. >>>> For example, for general tool usage in Windows the student needs to >>>> know about levels of environment variable specifications and file >>>> associations, which in turn requires knowledge of processes and the >>>> Windows registry database and various commands. >>> Mercifully this is rubbish. For most purposes with most tools even >>> Windows users don't need to know much if anything about environment >>> variables and the registry. Needing to know anything about the >>> registry is usually a sign that Windows has stuffed you up royally. >> >> I deduce that you mainly use IDEs and don't know about the things >> you're commenting on here (more than you did above). Sorry, but there >> it is. > > You deduce incorrectly. I'd unbend enough to admit that setting > environment variables is frequently very useful to inveterate command- > line users like myself, and that Windows makes that a lot harder than > necessary, but your original statement still reads like scaremongering. > > Why am I defending Windows again? Because I used a Windows-based concrete example. Then by attempting to raise doubts about that which you found hard to believe, you got into an absurd rhetorical position. He he, it happens very often, but happily you saw it at once & adjusted: some folks just go on defending an indefensible position, they happily disregard facts and logic, and then it gets, "interesting". :-) Cheers, - Alf From alfps at start.no Sun Nov 1 16:24:52 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 22:24:52 +0100 Subject: Feedback desired on reworked ch 1 progr. intro (now Python 3.x, Windows) In-Reply-To: References: Message-ID: * Rhodri James: > Before we start, can I just say that I find Google Docs loathsome? > > On Sat, 31 Oct 2009 07:40:36 -0000, Alf P. Steinbach > wrote: > >> I hope this new version of ch 1 is, well, better, addresses some of >> the concerns raised? > > Section 1.1 needs serious work. Could you please expand on that? It is a hint. Byt it doesn't leave me with much to go on regarding what you mean. > You have a very assertive writing style > and a lot of things that you definitively state are at best debatable. > If I'd picked that up in a shop and browsed that opening, I'd put the > book down and walk away; essentially you're calling your accuracy into > question before you've even said anything about programming. Could you please expand on this also? Sort of, more concrete? Cheers & thanks, - Alf From deets at nospam.web.de Sun Nov 1 16:26:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 01 Nov 2009 22:26:33 +0100 Subject: __str__ difficulty with lists In-Reply-To: References: Message-ID: <7l6co9F3b3ap8U1@mid.uni-berlin.de> Jabba Laci schrieb: > Hi, > > I have a list that contains custom objects. When printing the list, > I'd like to have a readable result, i.e. I'd like to see the output of > the __str__ functions. See an example below. When I call "print li", I > would like to get "[3, 5]". How to do that? Use __repr__ instead - lists call that on their contained objects. Diez From ldo at geek-central.gen.new_zealand Sun Nov 1 16:34:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 02 Nov 2009 10:34:25 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> In message , >> Carsten Haese wrote: > >>> On what grounds are you asserting that it's not necessary to mix the >>> two? Please elaborate your point. >> >> On the grounds that Python has more general and powerful string >> parameter- substitution mechanisms than anything built into any database >> API. > > That statement is fundamentally flawed. You are assuming that the > preferred way of getting a value into a query is by substituting a > literal into the query string. That is, in general, not true, because > that would be horribly inefficient. Says someone who hasn't realized where the real inefficiencies are. Remember what Tony Hoare told us: "premature optimization is the root of all evil". These are databases we're talking about. Real-world databases are large, and reside on disk, which is several orders of magnitude slower than RAM. And RAM is where string parameter substitutions take place. So a few hundred extra RAM accesses isn't going to make any significant difference to the speed of database queries. > Finally, you're assuming that every value that can be supplied to a > query actually HAS a literal form. That is not true. For example, in > Informix databases, there are no literals for BYTE-type values. Probably why I don't use Informix. What use is a binary data type if you can't insert and retrieve binary data values? From python at mrabarnett.plus.com Sun Nov 1 17:01:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 01 Nov 2009 22:01:42 +0000 Subject: import bug In-Reply-To: References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: <4AEE0546.4040509@mrabarnett.plus.com> Gabriel Genellina wrote: [snip] >>> One way to avoid name clashes would be to put the entire standard >>> library under a package; a program that wants the standard re >>> module would write "import std.re" instead of "import re", or >>> something similar. Every time the std package is suggested, the >>> main argument against it is backwards compatibility. >> >> You could do it in a backwards compatible way, by adding the std >> package directory into the path. > > Unfortunately you can't, at least not without some special treatment > of the std package. One of the undocumented rules of the import > system is that you must not have more than one way to refer to the > same module (in this case, std.re and re). Suppose someone imports > std.re; an entry in sys.modules with that name is created. Later > someone imports re; as there is no entry in sys.modules with such > name, the re module is imported again, resulting in two module > instances, darkness, weeping and the gnashing of teeth :) (I'm sure > you know the problem: it's the same as when someone imports the main > script as a module, and gets a different module instance because the > "original" is called __main__ instead). > Couldn't the entry in sys.modules be where the module was found, so that if 're' was found in 'std' then the entry is 'std.re' even if the import said just 're'? From pengyu.ut at gmail.com Sun Nov 1 17:11:48 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 16:11:48 -0600 Subject: About one class/function per module Message-ID: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> I recently asked how to support one class/function per module under the title 'How to import only one module in a package when the package __init__.py has already imports the modules?' I summarize my key points below. In particular, I have to two questions: 1. What disadvantages there are to enforce one class/function per file? 2. How to better support one class/function per file in python? ------------------------------------------------------------------------------ I prefer organized my code one class/function per file (i.e per module in python). I know the majority of programmers don't use this approach. Therefore, I'm wondering what its disadvantage is. The advantages of one-function/class-per-file that I am aware of are the following items (maybe incomplete). 1. It is easy to see what functions and classes there are just by browsing the source directory, without the need of opening the file by an editor. 2. Testing code for a function/class can be organized along with the module for the function/class, which also makes it easier to keep track of the testing code for any function/class. 3. It is easy to move a function/class from one package to another by just moving files around. 4. It is easy change variable names, etc., for a function/class by replacement in a file without worrying accidentally change variable names in other functions. I have used the above approach on a C++ project. And I use vim + ctags to navigate from a reference of a class/funciton to its definition. So far it works fine. Some people mentioned an good IDE can do 1 and 4. But I'm not aware of an IDE that can allow me to change file name freely. I tried Visual Studio long time ago, I have to delete a file, change the file name and add the file back in order to change the file. Now let us consider how well python can support one function/class per file style. I encounter the following problems. Suppose that the parent directory of 'test' is in $PYTHONPATH and __init__.py is empty, test/ |-- __init__.py |-- A.py `-- B.py where A.py has only class A and B.py has only class B. The end user of the test package has to either import test.A a=test.A.A() or from test.A import A a=A() Both of the two cases are not satisfactory. In the first case, a end user has to type A twice in test.A.A(), which is a burden to the end user. In the second case, 'from test.A import A' screws up the namespace, which might cause potential conflicts with classes of the same name but from different packages. I was also suggested to put the following line in __init__.py. from A import A from B import B Then the end user can use the following code. import test test.A() But the disadvantage is that I can not import individule file test.A and test.B any more. Suppose that A is modified but not done yet, then I modify B. Since the modification of A is not finished yet, the test code of B won't run because the test code import test.A. I'm looking for if there is a solution, so that a end user can use the following code import test.A test.A() So far, I haven't find one. It seems impossible in python, but I want to double check if there is one solution. From deets at nospam.web.de Sun Nov 1 17:32:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 01 Nov 2009 23:32:00 +0100 Subject: About one class/function per module In-Reply-To: References: Message-ID: <7l6gj0F3bagckU1@mid.uni-berlin.de> Peng Yu schrieb: > I recently asked how to support one class/function per module under > the title 'How to import only one module in a package when the package > __init__.py has already imports the modules?' I summarize my key > points below. In particular, I have to two questions: > 1. What disadvantages there are to enforce one class/function per file? > 2. How to better support one class/function per file in python? Are you aware that it's much easier to just let go about your preconceptions about how things should work, and instead adapt for *Pythocode* to the way *Python* works? The energy you've invested in coming up with contrived reasons for why e.g. one file per function is a good idea is better spent actually programming Python - and ejoying it. Diez From carsten.haese at gmail.com Sun Nov 1 17:40:11 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 01 Nov 2009 17:40:11 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > Says someone who hasn't realized where the real inefficiencies are. Remember > what Tony Hoare told us: "premature optimization is the root of all evil". > These are databases we're talking about. Real-world databases are large, and > reside on disk, which is several orders of magnitude slower than RAM. And > RAM is where string parameter substitutions take place. So a few hundred > extra RAM accesses isn't going to make any significant difference to the > speed of database queries. You're just not getting it. The cost is not in performing the parameter substitutions themselves. The cost is in parsing what's essentially the same query one million times over when it could have been parsed only once. You might find an increase of seven orders of magnitude insignificant, but I don't. > Probably why I don't use Informix. What use is a binary data type if you > can't insert and retrieve binary data values? You CAN insert and retrieve binary data values. You just have to use the right tool for the job, and that is parameter binding. -- Carsten Haese http://informixdb.sourceforge.net From robert.kern at gmail.com Sun Nov 1 17:46:49 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 16:46:49 -0600 Subject: About one class/function per module In-Reply-To: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> References: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> Message-ID: Peng Yu wrote: > So far, I haven't find one. It seems impossible in python, but I want > to double check if there is one solution. We have already told you more than twice that the answer is "No." Please don't triple check. -- 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 REMOVE-THIS-cybersource.com.au Sun Nov 1 17:51:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:51:04 GMT Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fdff3a$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 17:34:19 -0300, Gabriel Genellina wrote: > En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano > escribi?: >> On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: > >>>> Incorrect. Simplicity of implementation and API is a virtue, in and >>>> of itself. The existing module machinery is quite simple to >>>> understand, use and maintain. >>> >>> Uhm... module objects might be quite simple to understand, but module >>> handling is everything but simple! (simplicity of implem...? quite >>> simple to WHAT? ROTFLOL!!! ) >> >> I stand corrected :) >> Nevertheless, the API is simple: the first time you "import name", >> Python searches a single namespace (the path) for a module called name. >> There are other variants of import, but the basics remain: >> >> search the path for the module called name, and do something with the >> first one you find. > > Sure, beautiful, a plain and simple search over a list of directories. > That's how it worked in Python 1.4, I think... Now you have lots of > "hooks" and even "meta-hooks": sys.meta_path, sys.path_hooks, > sys.path_importer_cache. And sys.path, of course, which may contain > other things apart of directory names (zip files, eggs, and even > instances of custom "loader" objects...). You'll notice I deliberately didn't refer to directories. I just said "the path". If the path contains things other than directories, they are searched too. > PEP 302 explains this but I'm > not sure the description is still current. PEP369, if approved, would > add even more hooks. > Add packages to the picture, including relative imports and __path__[] > processing, and it becomes increasingly harder to explain. Bret Cannon > has rewritten the import system in pure Python (importlib) for 3.1; this > should help to understand it, I hope. The whole system works, yes, but > looks to me more like a collection of patches over patches than a > coherent system. Perhaps this is due to the way it evolved. You've convinced me that the implementation of the import infrastructure isn't as clean as I imagined. I'm sure it's a gnarly hack on top of gnarly hacks, and that maintaining it requires heroic measures worthy of a medal *grin*. >>>> Dealing with name clashes doesn't come for free. If you think it >>>> does, I encourage you to write a patch implementing the behaviour you >>>> would prefer. >>> >>> I'd say it is really a bug, and has existed for a long time. >> >> Since import is advertised to return the first module with the given >> name it finds, I don't see it as a bug even if it doesn't do what the >> programmer intended it to do. [...] Shadowing a standard library module >> is no different. > > But that's what namespaces are for; if the standard library had its own > namespace, such collisions would not occur. Sure. But that's not a bug in the import system. If it's a bug, it's a bug in the layout of the standard library. >> You could do it in a backwards compatible way, by adding the std >> package directory into the path. > > Unfortunately you can't, at least not without some special treatment of > the std package. One of the undocumented rules of the import system is > that you must not have more than one way to refer to the same module (in > this case, std.re and re). *slaps head* How obvious in hindsight. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 17:52:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:52:10 GMT Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fdff7c$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: > When we want find out if two sets s1 and s2 are the same we only need to > look at their extensions, so given: > > (i s1)(Ay)(y e s1 <-> y is a fire-breathing animal) (i s2)(Ay)(y e s2 > <-> y is a real number equal to sqrt(-1)) > > we only need to find out if: > > (Ax)(x is a fire-breathing animal <-> x is a real number equal to > sqrt(-1)). > > And since there are neither such things, it follows that s1 = s2. That assumes that all({}) is defined as true. That is a common definition (Python uses it), it is what classical logic uses, and it often leads to the "obvious" behaviour you want, but there is no a priori reason to accept that all({}) is true, and indeed it leads to some difficulties: All invisible men are alive. All invisible men are dead. are both true. Consequently, not all logic systems accept vacuous truths. http://en.wikipedia.org/wiki/Vacuous_truth -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 17:53:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:53:49 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> Message-ID: <02fdffdf$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 13:46:42 -0600, Robert Kern wrote: > Peng Yu wrote: >> On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano >> wrote: > >>> Oh wait, I get it... you want to do a global search-and-replace over >>> the entire file. *face-palm* >> >> Yes. You get it. > > In any capable programmer's editor, it should not be hard to do a local > search-and-replace over just the one function. Given the OP's stated claim that all his functions are less than a screen in size, Notepad could do it, with just the tiniest amount of manual effort. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 18:02:47 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 23:02:47 GMT Subject: Function states [was Re: How to import only one module in a package when the package __init__.py has already imports the modules?] References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <02fd0c56$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fe01f9$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 08:07:37 -0600, Peng Yu wrote: > It is > reasonable to assume the log of the number of states of a function or a > class is proportional to it length. Hence, when a function or a > class is long, you will never be able to test all its states. def f(n): return n + 5 def g(n): x = n + 1 x += 1 x += 1 x += 1 return x + 1 Function g() has five times the length (in lines) as f(). Does it require five times the testing? Obviously not. In fact, there's no easy way to test the internal state of the function from outside, because x is local to g(). You can't test the value of x from outside, because x is not exposed to the outside. The complexity of testing functions is roughly proportional to the number of paths through the function, not the number of lines. Both f() and g() have a single path through the function and therefore require the same amount of testing. The simplest estimate of the number of paths in a function is the number of if...else statements. Each pair *doubles* the number of paths: def func(): if cond1: A else: B if cond2: C else: D if cond3: E else: F There are 2**3 paths that need testing: ACE ACF ADE ADF BCE BCF BDE BDF Or consider this example: def func(x, cond): for f in [A, B, C, D, E, F]: if cond(x): x = f(x) This function has two lines only, but clearly there could be as many as 128 paths that need testing. Ideally your test data should visit each one of these paths. -- Steven From alfps at start.no Sun Nov 1 18:19:51 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 00:19:51 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * MRAB: > Lord Eldritch wrote: >> Hi >> >> Maybe this is maybe something it has been answered somewhere but I >> haven't been able to make it work. I wanna pass one variable to a >> callback function and I've read the proper way is: >> >> Button(......, command=lambda: function(x)) >> >> So with >> >> def function(a): print a >> >> I get the value of x. Ok. My problem now is that I generate the >> widgets in a loop and I use the variable to 'label' the widget: >> >> for x in range(0,3): Button(......, command=lambda: function(x)) >> >> so pressing each button should give me 0,1,2. >> >> But with the lambda, I always get the last index, because it gets >> actualized at each loop cycle. Is there any way to get that? >> > A lambda expression is just an unnamed function. At the point the > function is /called/ 'x' is bound to 3, so that's why 'function' is > always called with 3. > > A function's default arguments are evaluated when the function is > /defined/, so you can save the current value of 'x' creating the > function (the lambda expression, in this case) with a default argument: > > for x in range(0,3): > Button(......, command=lambda arg=x: function(arg)) > > The following will also work, although you might find the "x=x" a bit > surprising/confusing if you're not used to how Python works: > > for x in range(0,3): > Button(......, command=lambda x=x: function(x)) An alternative reusable alternative is to create a button-with-id class. This is my very first Python class so I'm guessing that there are all sorts of issues, in particular naming conventions. And the idea of creating a reusable solution for such a small issue may be un-pythonic? But just as an example, in Python 3.x, import tkinter # I guess for Python 2.x do "import Tkinter as tkinter" but haven't tested. class IdButton( tkinter.Button ): def __init__( self, owner_widget, id = None, command = None, **args ): tkinter.Button.__init__( self, owner_widget, args, command = self.__on_tk_command ) self.__id = id self.__specified_command = command def __on_tk_command( self ): if self.__specified_command != None: self.__specified_command( self ) else: self.on_clicked() def on_clicked( self ): pass def id( self ): return self.__id def id_string( self ): return str( self.id() ); def on_button_click( aButton ): print( "Button " + aButton.id_string() + " clicked!" ) window = tkinter.Tk() n_buttons = 3 for x in range( 1, n_buttons + 1 ): IdButton( window, id = x, text = "Button " + str( x ), command = on_button_click ).pack() window.mainloop() Cheers, - Alf PS: Now I see that I've used camelCase once. Oh well... From cjwilliams43 at gmail.com Sun Nov 1 18:32:14 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sun, 01 Nov 2009 18:32:14 -0500 Subject: Why 'import module' will not import module.py but the directory module? In-Reply-To: References: <366c6f340910311651u597bec70qa4bf9526c40bb91a@mail.gmail.com> <366c6f340910311716n6827f6a1r9bf730c780aeba08@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2009-10-31 19:16 PM, Peng Yu wrote: >> On Sat, Oct 31, 2009 at 7:02 PM, Robert Kern >> wrote: >>> On 2009-10-31 18:51 PM, Peng Yu wrote: >>>> >>>> If I have both the directory 'module' and the file 'module.py' in a >>>> directory in $PYTHONPATH, python will import 'module' rather than >>>> 'module.py'. I'm wondering what is the design rationale of setting >>>> higher priorities to directories. Is there a way to reverse the >>>> priority? >>> >>> You mean that you have a package "module/"? With an __init__.py? Plain >>> directories that aren't packages shouldn't be imported by Python. >> >> Yes. I mean a pakcage 'module/' with an __init__.py. >> >>> No, you can't reverse the priority between packages and modules. I'm not >>> sure why that would help you. The package would then be inaccessible >>> if you >>> did. If it's inaccessible, then why have it at all? >> >> Why the package 'module' has to be inaccessible? I can 'import >> module.part1' to access the component of the package. > > No, it wouldn't. It's a moot point because Python picks the package > first, but if it did pick modules before packages, then > sys.modules['module'] would point to the module from module.py and not > module/__init__.py . "import module.part1" first executes "import > module", then looks in there to determine who to resolve "module.part1". > Since sys.modules['module'] is a regular module and not the package, it > wouldn't find module/part1.py . > Doesn't it make sense to avoid the use of names like module or package, even though they are permitted. Colin W. From stef.mientki at gmail.com Sun Nov 1 18:42:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 02 Nov 2009 00:42:26 +0100 Subject: Doesn't MS-Windows likes Python ? (or: why more than 20 sec delay when running a program from Python) Message-ID: <4AEE1CE2.4050205@gmail.com> hello, I've an AutoIt program that set some switches in the LAN settings. When I launch the AutoIt executable, the settings are changed immediately. When I launch the AutoIt executable from python (which is the intention), it hangs for about 20 seconds, before any action appears on the screen. Analyzing the script, shows that it hangs on the next 2 lines: Run ( "control.exe ncpa.cpl" ) WinWait( "Network Connections") Transfering the Run command to Python, it hangs on the next subprocess call subprocess.call ( [ r"control.exe", "ncpa.cpl" ]) Does anyone have a clue, why starting a process takes 20 seconds longer when ran from Python ? And even more important, is there a work around ? thanks, Stef Mientki From rhodri at wildebst.demon.co.uk Sun Nov 1 19:08:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 02 Nov 2009 00:08:37 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach wrote: > * Rhodri James: This is a weird attribution style, by the way. I don't think it helps. >> On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach >> wrote: >> >>> * Rhodri James: >>>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>>> wrote: >>>>> with the best knowledge of the program's environment, is unable to >>>>> handle (such as delete) files or folders with paths greater than >>>>> some 260 characters, is unable to handle filenames that differ only >>>>> in case and are in the same directory, and is unable to e.g. delete >>>>> a folder called "con" -- although such files & folders can very >>>>> easily be created. >>>> You may or may not be aware that some of these things are >>>> limitations of >>>> the underlying disc format, >>> >>> Sorry no, it isn't. >>> >>> Even assuming you meant the more reasonable "file system", no, it >>> isn't. >> Actually I should have mentioned the filing system as well as the disc >> format (which does matter). I may not be using correct Windows >> terminology, >> since I'm referring to both the bytes on hardware and the software stack >> that terminates in the OS API. >> Still, colour me surprised. I had assumed that NTFS had some (large) >> limit on filenames, and 256 sounded plausible. > > For NTFS it's 32K or 64K wide characters, I don't recall which. But > what's important is that that's also the API level limit. You can find > most of the details in Microsoft's documentation of CreateFile (but it's > off-topic here). Actually it's not, since it's a perfect example of the "not reading quite carefully enough" others have pointed out before. You make this statement as an absolute, iron-clad assertion. Checking the MS website, we find it actually says: "Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters." The exceptions are unicode versions of some of the functions, which do give you ~32K characters. However, the docs are pretty specific about what is and isn't the API limit. Since this applies to the command line just as much as to GUIs, I'll repeat my claim that blaming Explorer for something that causes just as much grief on a command line is a tad unfair. More importantly, I accuse you of making very definitive statments that turn out to be insufficiently researched. That's not an encouraging state of affairs in someone planning to write a beginners' textbook. Having originally learned C from one of Herbert Schildt's books, I reckon I've earned the right to be highly allergic to this! -- Rhodri James *-* Wildebeest Herder to the Masses From alfps at start.no Sun Nov 1 19:49:50 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 01:49:50 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: > > This is a weird attribution style, by the way. I don't think it helps. That's a pretty weird thing to comment on. And as far as I can see the comment doesn't make sense except as an attempt to find something negative to say. But anyway, the point about '*' was, once upon a time, that it made for a very clear style of quoting in old newsreaders. Nowadays the tools are generally of lesser quality (e.g. I'm using Thunderbird). And so it doesn't really have much of that advantage left, but I'm using it anyway; I can be pretty stubborn about issues of quality. >>> On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach >>> wrote: >>> >>>> * Rhodri James: >>>>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>>>> wrote: >>>>>> with the best knowledge of the program's environment, is unable to >>>>>> handle (such as delete) files or folders with paths greater than >>>>>> some 260 characters, is unable to handle filenames that differ >>>>>> only in case and are in the same directory, and is unable to e.g. >>>>>> delete a folder called "con" -- although such files & folders >>>>>> can very easily be created. >>>>> You may or may not be aware that some of these things are >>>>> limitations of >>>>> the underlying disc format, >>>> >>>> Sorry no, it isn't. >>>> >>>> Even assuming you meant the more reasonable "file system", no, it >>>> isn't. >>> Actually I should have mentioned the filing system as well as the disc >>> format (which does matter). I may not be using correct Windows >>> terminology, >>> since I'm referring to both the bytes on hardware and the software stack >>> that terminates in the OS API. >>> Still, colour me surprised. I had assumed that NTFS had some (large) >>> limit on filenames, and 256 sounded plausible. >> >> For NTFS it's 32K or 64K wide characters, I don't recall which. But >> what's important is that that's also the API level limit. You can find >> most of the details in Microsoft's documentation of CreateFile (but >> it's off-topic here). > > Actually it [the limit]'s not You're disputing a plain fact. For which you've been given a technical reference, as well as concrete example. I'm sorry, but it's idiotic to dispute plain facts. >, since it's a perfect example of the "not reading quite > carefully enough" others have pointed out before. You make this statement > as an absolute, iron-clad assertion. Checking the MS website, we find it > actually says: > > "Maximum Path Length Limitation > > In the Windows API (with some exceptions discussed in the following > paragraphs), the maximum length for a path is MAX_PATH, which is defined > as 260 characters." > > The exceptions are unicode versions of some of the functions, which do > give you ~32K characters. However, the docs are pretty specific about > what is and isn't the API limit. I'm sorry but you're misunderstanding the documentation. In your own words, you're "not reading quite carefully enough". By the way, your technique of vague ad hominem attack here is detestable. But anyway, if you read the documentation of CreateFile as I directed you to, or simply read on where you was, then you get a more technically correct picture. Or, by applying logic you can /deduce/ that since >260 character paths can and do exist, 260 characters is not "the limit". The MS documentation is unfortunately not all that clear. In many cases (the most infamous one is perhaps the claim that a program's entry point is WinMain) it's just plain incorrect, being written by technical writers. But it's simple enough to write a few programs to check it out. > Since this applies to the command > line just as much as to GUIs, No, it doesn't. And you've been given a concrete example of how. You can't just go on *inventing* facts. Facts are facts, your fantasies & wishes are your fantasies & wishes. > I'll repeat my claim that blaming Explorer > for something that causes just as much grief on a command line is a > tad unfair. I'm sorry, but there's a complete lack of logic in that, as well as misdirection. First, regarding the misdirection, it is untrue that I have "blamed" Windows Explorer for this. The blame, if any is to be affixed anywhere, belongs elsewhere than with a computer program. Second, regarding the logic, that a program exhibits low quality in some respect is not OK just because there's another program that also exhibits low quality. > More importantly, I accuse you of making very definitive statments > that turn out to be insufficiently researched. That would be OK and what I want. :-) But you haven't. You're making general vague statements about quality, but haven't addressed any concrete thing in the text. And what you have responded to here in this thread, it's all been incorrect. In this latest article you have even started disputing simple technical facts and started making fallacious deductions, shown above. > That's not an > encouraging state of affairs in someone planning to write a beginners' > textbook. Having originally learned C from one of Herbert Schildt's > books, I reckon I've earned the right to be highly allergic to this! I'm sorry to hear that you had to endure that. It's an old saying that the low price of Herbert's annotated C++ reference, compared to the official standard, reflected the value of his annotations... But that's no excuse to now start emulating Herbert, regarding blatant disregard for facts and logic, as you've done above. Cheers & hth., - Alf From wuwei23 at gmail.com Sun Nov 1 20:02:33 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 17:02:33 -0800 (PST) Subject: About one class/function per module References: Message-ID: On Nov 2, 8:11?am, Peng Yu wrote: > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. You mean, what disadvantages it has _other_ than the ones you've been experiencing? Aren't those enough to warrant actually working with Python's import mechanism rather than against it? From mad.mick at gmx.de Sun Nov 1 20:02:58 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Mon, 02 Nov 2009 02:02:58 +0100 Subject: list comprehension problem In-Reply-To: <02fdff7c$0$1326$c3e8da3@news.astraweb.com> References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> <02fdff7c$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: >> >> (Ax)(x is a fire-breathing animal <-> x is a real number equal to >> sqrt(-1)). >> >> And since there are neither such things, it follows that s1 = s2. > > That assumes that all({}) is defined as true. That is a common definition > (Python uses it), it is what classical logic uses, and it often leads to > the "obvious" behaviour you want, but there is no a priori reason to > accept that all({}) is true, and indeed it leads to some difficulties: > > All invisible men are alive. > All invisible men are dead. > > are both true. Consequently, not all logic systems accept vacuous truths. > > http://en.wikipedia.org/wiki/Vacuous_truth You're right, of course, but I'm an oldfashioned quinean guy :-) Also, in relevance logic and similar systems my beloved proof that there are no facts (Davidson's Slingshot) goes down the drain. So I think I'll stay with classical logic FTTB. Regards, Mick. From pengyu.ut at gmail.com Sun Nov 1 20:27:32 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 19:27:32 -0600 Subject: About one class/function per module In-Reply-To: References: Message-ID: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: > On Nov 2, 8:11?am, Peng Yu wrote: >> I prefer organized my code one class/function per file (i.e per module >> in python). I know the majority of programmers don't use this >> approach. Therefore, I'm wondering what its disadvantage is. > > You mean, what disadvantages it has _other_ than the ones you've been > experiencing? > > Aren't those enough to warrant actually working with Python's import > mechanism rather than against it? At least, I can use the following for now with one class/function per module. Unless this one class/function per module style have other disadvantages in term software engineering, I still can live with typing the class name (e.g. 'A') twice. import test.A a=test.A.A() So I am asking disadvantages besides python import mechanism is not friendly to it. From metal29a at gmail.com Sun Nov 1 21:00:45 2009 From: metal29a at gmail.com (metal) Date: Sun, 1 Nov 2009 18:00:45 -0800 (PST) Subject: About one class/function per module References: Message-ID: <2e97941b-848e-450e-bc03-590d82577023@v15g2000prn.googlegroups.com> On 11?2?, ??9?27?, Peng Yu wrote: > On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: > > On Nov 2, 8:11 am, Peng Yu wrote: > >> I prefer organized my code one class/function per file (i.e per module > >> in python). I know the majority of programmers don't use this > >> approach. Therefore, I'm wondering what its disadvantage is. > > > You mean, what disadvantages it has _other_ than the ones you've been > > experiencing? > > > Aren't those enough to warrant actually working with Python's import > > mechanism rather than against it? > > At least, I can use the following for now with one class/function per > module. Unless this one class/function per module style have other > disadvantages in term software engineering, I still can live with > typing the class name (e.g. 'A') twice. > > import test.A > a=test.A.A() > > So I am asking disadvantages besides python import mechanism is not > friendly to it. I recommand you double check django project, to learn how to organize python project From wuwei23 at gmail.com Sun Nov 1 21:06:57 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 18:06:57 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <4c1bef97-491a-4e87-ac97-e13c80cd252b@r24g2000prf.googlegroups.com> Saketh wrote: > If you have any suggestions, let me know -- this is a community > effort! I'd like to suggest Pyaspora as a more apropos name ;) From davea at ieee.org Sun Nov 1 21:13:10 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 21:13:10 -0500 Subject: stdin in embedded python In-Reply-To: References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: <4AEE4036.8000405@ieee.org> Gabriel Genellina wrote: > En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch > escribi?: >> On Nov 1, 5:34 am, Dave Angel wrote: >>> KillSwitch wrote: > >>> > I have a C++ program, with a GUI, into which I have embedded >>> python. I >>> > have made several python functions in C++, one of which I use to >>> > override the normal stdout and stderr so that they print to a text >>> box >>> > of my GUI. One thing I cannot think of how to do is to redefine stdin >>> > so that it pauses the program, waits for a user to type input into >>> the >>> > box, hit enter, and takes input from another text element and >>> sends it >>> > to python like it was the console. >>> >>> I suspect you don't really want to redirect stdin, but instead >>> implement >>> raw_input(). [...]Try changing __builtins__.raw_input to reference >>> your new >>> function. >> >> But what would the function do? How would it pause python and wait for >> it to have text to send? > > Whatever you want. You don't have to "pause python", Python itself > won't resume until your function doesn't return. (You should release > the GIL if your C++ function doesn't call back to Python code, to > allow other threads to continue, but that's another story). > This is a raw_input replacement written in Tkinter; it shows a dialog > box instead of reading from stdin: > > py> from Tkinter import * > py> from tkSimpleDialog import askstring > py> def my_raw_input(prompt): > ... return askstring("Python", prompt) > ... > py> root = Tk() > py> import __builtin__ > py> __builtin__.raw_input = my_raw_input > py> > py> raw_input("What's your name?") > 'Gabriel' > > > ------------------------------------------------------------------------ > I think I see the OP's problem. He has written a GUI program in C++, and is using (embedding) Python functions into it. So presumably those functions are being called from events in the C++ event loop. If one of those functions tries to call back into C++ code, the event loop will never get control, to process the events from the standard UI controls. So if the input is to be handled as an integral part of the C++ UI, there's a distinct problem. On the other hand, Gabriel's dialog box should work fine, as long as you don' t mind a modal dialog box as a solution. I don't know tkinter's askstring, but I suspect it'd work. However, the rest of the C++ GUI would be frozen, which could be a problem. DaveA From wuwei23 at gmail.com Sun Nov 1 21:33:57 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 18:33:57 -0800 (PST) Subject: About one class/function per module References: Message-ID: <8f259645-f704-4bde-bcde-58562cc7a196@b25g2000prb.googlegroups.com> Peng Yu wrote: > So I am asking disadvantages besides python import mechanism is not > friendly to it. Which part of "name collisions have to be resolved somehow" isn't explicit enough for you? You can't keep saying "this works in C++" while refusing to accept that this is an implementation decision with Python. At least be honest about what you're asking for, which is confirmation of your existing bias. From ThadSmith at acm.org Sun Nov 1 21:44:29 2009 From: ThadSmith at acm.org (Thad Smith) Date: Sun, 01 Nov 2009 20:44:29 -0600 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7ktsj6F3bciqlU1@mid.individual.net> Message-ID: <4aee4796$0$77552$892e0abb@auth.newsreader.octanews.com> Richard Heathfield wrote: > ... so I cheerfully installed it on the > user's desktop machine (Windows ME, would you believe), and then set > about configuring the reader, when... ouch! No PDF reader on the > machine. Not even an ancient Adobe version. Oh dear. Program suddenly > rendered completely useless for that person. There is a Catch 22 for installing Adobe Reader from the Adobe site ( http://get.adobe.com/reader/ ) for the first time, without making a blind promise: "By clicking the Download button you agree to the License Agreements and Privacy Policies for the software included." Guess what format the license agreement is in. ;-) -- Thad From davea at ieee.org Sun Nov 1 21:52:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 21:52:19 -0500 Subject: About one class/function per module In-Reply-To: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> References: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> Message-ID: <4AEE4963.6070008@ieee.org> Peng Yu wrote: > > > Some people mentioned an good IDE can do 1 and 4. But I'm not aware of > an IDE that can allow me to change file name freely. I tried Visual > Studio long time ago, I have to delete a file, change the file name > and add the file back in order to change the file. > > I use Komodo IDE version 5, where right-click->Rename works fine on files within a project. > Now let us consider how well python can support one function/class per > file style. I encounter the following problems. Suppose that the > parent directory of 'test' is in $PYTHONPATH and __init__.py is empty, > > test/ > |-- __init__.py > |-- A.py > `-- B.py > > where A.py has only class A and B.py has only class B. > > The end user of the test package has to either > > import test.A > a=test.A.A() > > or > > from test.A import A > a=A() > > I'm neither agreeing nor disagreeing with the self-imposed restriction of one class per module. But I'd like to jump in with an idea on dealing with the namespaces involved. How about a two-line import, where the second line is a simple assignment? import test.A test.A = test.A.A Now, you can use the class A just as you wanted -- obj = test.A() This has the disadvantage that the module itself is no longer addressable from here. But since the only symbol you apparently want from the module is the one class, it should be fine. And you could presumably have saved it in a module-specific global anyway. Note that I did not test whether other modules that also import test.A are affected. So some further study would be necessary. Also, I tried it only in CPython 2.6.2 DaveA From pjb at informatimago.com Sun Nov 1 21:59:19 2009 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 02 Nov 2009 03:59:19 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) References: <7ktsj6F3bciqlU1@mid.individual.net> <4aee4796$0$77552$892e0abb@auth.newsreader.octanews.com> Message-ID: <87fx8xhbso.fsf@galatea.local> Thad Smith writes: > Richard Heathfield wrote: > >> ... so I cheerfully installed it on the user's desktop machine >> (Windows ME, would you believe), and then set about configuring the >> reader, when... ouch! No PDF reader on the machine. Not even an >> ancient Adobe version. Oh dear. Program suddenly rendered completely >> useless for that person. > > There is a Catch 22 for installing Adobe Reader from the Adobe site ( > http://get.adobe.com/reader/ ) for the first time, without making a > blind promise: "By clicking the Download button you agree to the > License Agreements and Privacy Policies for the software included." > Guess what format the license agreement is in. ;-) Use xpdf to read it! Then use xpdf to read the other pdf documents, and forget about proprietary software? -- __Pascal Bourguignon__ From highcar at gmail.com Sun Nov 1 22:08:08 2009 From: highcar at gmail.com (elca) Date: Sun, 1 Nov 2009 19:08:08 -0800 (PST) Subject: disable image loading to speed up webpage load Message-ID: <26155440.post@talk.nabble.com> Hi, im using win32com 's webbrowser module. i have some question about it.. is it possible to disable image loading to speed up webpage load? any help ,much appreciate thanks in advance -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26155440.html Sent from the Python - python-list mailing list archive at Nabble.com. From rustompmody at gmail.com Sun Nov 1 22:12:07 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 1 Nov 2009 19:12:07 -0800 (PST) Subject: About one class/function per module References: Message-ID: <4b6a8a1a-30ff-43bd-a0ba-9bfe076e530e@m33g2000pri.googlegroups.com> On Nov 2, 3:11?am, Peng Yu wrote: > I recently asked how to support one class/function per module under > the title 'How to import only one module in a package when the package > __init__.py has already imports the modules?' I summarize my key > points below. In particular, I have to two questions: > 1. What disadvantages there are to enforce one class/function per file? > 2. How to better support one class/function per file in python? Others have told you to discard your biases. I would tell you to suspend them for a while (including our biases against your biases) and try to use emacs+ecb > > ------------------------------------------------------------------------------ > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. > > The advantages of one-function/class-per-file that I am aware of are > the following items (maybe incomplete). > ? 1. It is easy to see what functions and classes there are just by > browsing the source directory, without the need of opening the file by > an editor. Primary intention of ecb > ? 2. Testing code for a function/class can be organized along with the > module for the function/class, which also makes it easier to keep > track of the testing code for any function/class. > ? 3. It is easy to move a function/class from one package to another > by just moving files around. If an editing task is found hard it just means youve never used emacs! > ? 4. It is easy change variable names, etc., for a function/class by > replacement in a file without worrying accidentally change variable > names in other functions. > I have used the above approach on a C++ project. And I use vim + ctags > to navigate from a reference of a class/funciton to its definition. So > far it works fine. Should be possible to code this up in about 10 lines of emacs Simple workaround is to select the function/class and run search- replace on the selection From wuwei23 at gmail.com Sun Nov 1 22:23:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 19:23:21 -0800 (PST) Subject: Regular express question References: Message-ID: <602d2997-1148-4888-a474-326daaf03380@u36g2000prn.googlegroups.com> On Oct 31, 12:48?pm, elca wrote: > Hello, > i have some text document to parse. > sample text is such like follow > in this document, i would like to extract such like > SUBJECT = 'NETHERLANDS MUSIC EPA' > CONTENT = 'Michael Buble performs in Amsterdam Canadian singer Michael Buble > performs during a concert in Amsterdam, The Netherlands, 30 October 2009. > Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK ' > > if anyone help me,much appreciate > > " > NETHERLANDS MUSIC EPA | 36 before > Michael Buble performs in Amsterdam Canadian singer Michael Buble performs > during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble > released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK > " You really don't need regular expressions for this: >>> import os >>> eol = os.linesep >>> text = ''' ... NETHERLANDS MUSIC EPA | 36 before ... Michael Buble performs in Amsterdam Canadian singer Michael Buble performs ... during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble ... released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK ... ''' >>> text = text.strip() # remove eol markers >>> subject = text.split(' | ')[0] >>> content = ' '.join(text.split(eol)[1:]) >>> subject 'NETHERLANDS MUSIC EPA' >>> content "Michael Buble performs in Amsterdam Canadian singer Michael Buble performs during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK" From lord_eldritch at yahoo.co.uk Sun Nov 1 22:23:26 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Mon, 02 Nov 2009 04:23:26 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * MRAB: Thank you all! It is working now nicely! God! I love usenet..:D -- Lord Eldritch From steven at REMOVE.THIS.cybersource.com.au Sun Nov 1 23:01:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2009 04:01:12 GMT Subject: About one class/function per module References: <8f259645-f704-4bde-bcde-58562cc7a196@b25g2000prb.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 18:33:57 -0800, alex23 wrote: > Peng Yu wrote: >> So I am asking disadvantages besides python import mechanism is not >> friendly to it. > > Which part of "name collisions have to be resolved somehow" isn't > explicit enough for you? > > You can't keep saying "this works in C++" while refusing to accept that > this is an implementation decision with Python. Oh, it doesn't work to Peng Yu's satisfaction in C++ either. In an earlier email, he wrote: "I'm not complaining. I just wish there is a walkaround. In C++, I still have to write some script to make sure the directory hierarchy is consistent with the namespace, because C++ doesn't impose the constraint that the directory hierarchy is the same as the namespace. But it seems that is no such walkaround in python for my case, because python binds namespace to directory hierarchy." You got that? In Python, which forces the namespace and directory hierarchy to be the same, he wants them to be independent; in C++, which relaxes that restriction, he writes scripts to force them to be the same. [Aside: the word is "work-around" not "walk-around". Easy mistake to make.] -- Steven From cleberwillian at gmail.com Sun Nov 1 23:02:16 2009 From: cleberwillian at gmail.com (Cleber Santos) Date: Mon, 2 Nov 2009 02:02:16 -0200 Subject: spring effect in Python In-Reply-To: <553f6683-a463-43e6-aa0c-dcff81863786@g23g2000yqh.googlegroups.com> References: <553f6683-a463-43e6-aa0c-dcff81863786@g23g2000yqh.googlegroups.com> Message-ID: <6a8a14a20911012002x6c1faee8vdcc76bcc1b86f471@mail.gmail.com> You can try this: http://processingjs.org On Fri, Oct 30, 2009 at 5:26 AM, pochis40 wrote: > I'm trying to write in Python something similar to this: > (Java) > http://java.sun.com/applets/jdk/1.4/demo/applets/GraphLayout/example1.html > or these: > (Proce55ing) > http://www.cricketschirping.com/processing/ExportAtlas/ > or > > http://www.cricketschirping.com/weblog/2005/12/11/force-directed-graph-layout-with-proce55ing/ > or > > http://www.cricketschirping.com/weblog/2007/02/26/force-directed-graph-layout-with-processing-take-2/ > > I've problem to find something that give that physical effect (like a > spring). > > Any idea? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Cleber Santos website: binho.net skype: binhoweb msn: msn at binho.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sun Nov 1 23:50:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 01:50:41 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> <4AEE0546.4040509@mrabarnett.plus.com> Message-ID: En Sun, 01 Nov 2009 19:01:42 -0300, MRAB escribi?: > Gabriel Genellina wrote: >>>> One way to avoid name clashes would be to put the entire standard >>>> library under a package; a program that wants the standard re >>>> module would write "import std.re" instead of "import re", or >>>> something similar. >>> You could do it in a backwards compatible way, by adding the std >>> package directory into the path. >> Unfortunately you can't, at least not without some special treatment >> of the std package. One of the undocumented rules of the import >> system is that you must not have more than one way to refer to the >> same module (in this case, std.re and re). [...] > Couldn't the entry in sys.modules be where the module was found, so that > if 're' was found in 'std' then the entry is 'std.re' even if the import > said just 're'? What about a later 'import re'? 're' would not be found in sys.modules then. In any case, it requires a change in the current behavior, a PEP, and a lot of discussion... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 00:11:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 02:11:58 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> <02fdff3a$0$1326$c3e8da3@news.astraweb.com> Message-ID: En Sun, 01 Nov 2009 19:51:04 -0300, Steven D'Aprano escribi?: > On Sun, 01 Nov 2009 17:34:19 -0300, Gabriel Genellina wrote: >> En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano escribi?: >>> Shadowing a standard library module >>> is no different. >> >> But that's what namespaces are for; if the standard library had its own >> namespace, such collisions would not occur. > > Sure. But that's not a bug in the import system. If it's a bug, it's a > bug in the layout of the standard library. Half and half? The standard library cannot have a different structure because the import system cannot handle it in a backgwards compatible way? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 01:12:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 03:12:36 -0300 Subject: About one class/function per module References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> Message-ID: En Sun, 01 Nov 2009 22:27:32 -0300, Peng Yu escribi?: > On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: >> On Nov 2, 8:11 am, Peng Yu wrote: >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> You mean, what disadvantages it has _other_ than the ones you've been >> experiencing? >> >> Aren't those enough to warrant actually working with Python's import >> mechanism rather than against it? > > At least, I can use the following for now with one class/function per > module. Unless this one class/function per module style have other > disadvantages in term software engineering, I still can live with > typing the class name (e.g. 'A') twice. > > import test.A > a=test.A.A() > > So I am asking disadvantages besides python import mechanism is not > friendly to it. You don't type the class name twice. One 'A' is a module name, the other 'A' is the class name. In C++, a source file is just a compilation unit, only relevant for certain rules regarding visibility; it doesn't matter really in which source file the code is written in. In Python, a source file becomes a module. A module is an object: it is created (usually by importing it), it has attributes, there are module hierarchies (packages), contains other objects... A module is an important object in Python. You should not confuse the module with the class (or classes) that are defined inside it. In your example above, test.A is a module, test.A.A is a class; they're not the same thing. You may put one class per file, nobody forbids that - but remember that the class and the module are different objects. If you follow PEP8 conventions, module names are all in lowercase, and class names use TitleCase. This helps avoid confusion. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 01:20:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 03:20:37 -0300 Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> <4AEE4036.8000405@ieee.org> Message-ID: En Sun, 01 Nov 2009 23:13:10 -0300, Dave Angel escribi?: > Gabriel Genellina wrote: >> En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch >> escribi?: >>> On Nov 1, 5:34 am, Dave Angel wrote: >>>> KillSwitch wrote: >> >>>> > I have a C++ program, with a GUI, into which I have embedded >>>> python. I >>>> > have made several python functions in C++, one of which I use to >>>> > override the normal stdout and stderr so that they print to a text >>>> box >>>> > of my GUI. One thing I cannot think of how to do is to redefine >>>> stdin >>>> > so that it pauses the program, waits for a user to type input into >>>> the >>>> > box, hit enter, and takes input from another text element and sends >>>> it >>>> > to python like it was the console. >>>> >>>> I suspect you don't really want to redirect stdin, but instead >>>> implement >>>> raw_input(). >>> >>> But what would the function do? How would it pause python and wait for >>> it to have text to send? >> >> Whatever you want. You don't have to "pause python", Python itself >> won't resume until your function doesn't return. [example using >> Tkinter.askstring] >> > I think I see the OP's problem. He has written a GUI program in C++, > and is using (embedding) Python functions into it. So presumably those > functions are being called from events in the C++ event loop. > > If one of those functions tries to call back into C++ code, the event > loop will never get control, to process the events from the standard UI > controls. > > So if the input is to be handled as an integral part of the C++ UI, > there's a distinct problem. > > On the other hand, Gabriel's dialog box should work fine, as long as you > don' t mind a modal dialog box as a solution. I don't know tkinter's > askstring, but I suspect it'd work. However, the rest of the C++ GUI > would be frozen, which could be a problem. Perhaps looking a other examples may help. Both IDLE and PythonWin replace raw_input with a message box; IDLE is a Tkinter application, and PythonWin wraps MFC. Both have a main message loop and use a modal message box. -- Gabriel Genellina From jbperez at gmail.com Mon Nov 2 02:54:16 2009 From: jbperez at gmail.com (Jon P.) Date: Sun, 1 Nov 2009 23:54:16 -0800 (PST) Subject: substituting list comprehensions for map() Message-ID: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> I'd like to do: resultlist = operandlist1 + operandlist2 where for example operandlist1=[1,2,3,4,5] operandlist2=[5,4,3,2,1] and resultlist will become [6,6,6,6,6]. Using map(), I can do: map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) Is there any reasonable way to do this via a list comprehension ? From javier.collado at gmail.com Mon Nov 2 02:58:04 2009 From: javier.collado at gmail.com (Javier Collado) Date: Mon, 2 Nov 2009 08:58:04 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: Hello, I'll do the following: [op1+op2 for op1,op2 in zip(operandlist1, operandlist2)] Best regards, Javier 2009/11/2 Jon P. : > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. ?Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Mon Nov 2 02:59:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 00:59:44 -0700 Subject: substituting list comprehensions for map() In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <50697b2c0911012359x1648b833j3acd1340b2ea0992@mail.gmail.com> On Mon, Nov 2, 2009 at 12:54 AM, Jon P. wrote: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. ?Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? results = [x+y for x,y in zip(list1, list2)] Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Nov 2 03:13:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2009 08:13:50 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. Using map(), I can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) If the two lists are very large, it would be faster to use this: from operator import add map(add, operandlist1, operandlist2) > Is there any reasonable way to do this via a list comprehension ? [x+y for (x, y) in zip(operandlist1, operandlist2)] If the lists are huge, you can save some temporary memory by replacing zip with itertools.izip. -- Steven From paul.nospam at rudin.co.uk Mon Nov 2 03:17:59 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 02 Nov 2009 08:17:59 +0000 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87iqdtibm0.fsf@rudin.co.uk> "Jon P." writes: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? You can do it as a list comprehension e.g. like this: [ x + y for x, y in zip(operandlist1, operandlist2)] Note that there is some unnecessary list building going on here and it may be better to use itertools.izip. (In python 3 zip returns an iterator anyhow.) From ben+python at benfinney.id.au Mon Nov 2 03:19:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 19:19:41 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87bpjll4o2.fsf@benfinney.id.au> "Jon P." writes: > I'd like to do: > > resultlist = operandlist1 + operandlist2 That's an unfortunate way of expressing it; it's valid Python syntax that doesn't do what you're describing (in this case, it will bind ?resultlist? to a new list that is the *concatenation* of the two original lists). > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? Yes, just about any ?map()? operation has a corresponding list comprehension. (Does anyone know of a counter-example, a ?map()? operation that doesn't have a correspondingly simple list comprehension?) For the above case, this is how it's done:: >>> operandlist1 = [1, 2, 3, 4, 5] >>> operandlist2 = [5, 4, 3, 2, 1] >>> resultlist = [(a + b) for (a, b) in zip(operandlist1, operandlist2)] >>> resultlist [6, 6, 6, 6, 6] -- \ ?Creativity can be a social contribution, but only in so far as | `\ society is free to use the results.? ?Richard Stallman | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 03:49:34 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 09:49:34 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <87bpjll4o2.fsf@benfinney.id.au> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <4aee9d1e$0$19304$426a74cc@news.free.fr> Ben Finney a ?crit : (snip) > Yes, just about any ?map()? operation has a corresponding list > comprehension. Right AFAICT, but: > (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) ... depends on your definition of "simple". There are things I'd rather not write as a list comprehension... From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 03:55:57 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 09:55:57 +0100 Subject: About one class/function per module In-Reply-To: References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> Message-ID: <4aee9e9d$0$19304$426a74cc@news.free.fr> Gabriel Genellina a ?crit : >>> On Nov 2, 8:11 am, Peng Yu wrote: > >>>> I prefer organized my code one class/function per file (i.e per module >>>> in python). I know the majority of programmers don't use this >>>> approach. Therefore, I'm wondering what its disadvantage is. >>> (snip) > You may put one class per file, nobody forbids that But anyone having to work on your code will hate you. From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 04:03:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 10:03:58 +0100 Subject: About one class/function per module In-Reply-To: References: Message-ID: <4aeea07e$0$713$426a34cc@news.free.fr> Peng Yu a ?crit : (snip) > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. Hmmm... As far as I'm concerned, you already answered your own question: "the majority of programmers don't use this approach". Now, for a much more practical answer: 1/ having to handle thousands of files for even a simple project is a king-size PITA for the maintainer. 2/ having to load thousands of modules will add quite a lot of overhead when actually running the code. 3/ as a result, the poor guy that will end up maintaining your code will positively hate you. Beware : this poor guy might as well be you. From eric.brunel.pragmadev at gmail.com Mon Nov 2 04:07:45 2009 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Mon, 2 Nov 2009 01:07:45 -0800 (PST) Subject: Tkinter callback arguments References: Message-ID: On Nov 1, 8:53 pm, Lord Eldritch wrote: > Hi > > Maybe this is maybe something it has been answered somewhere but I haven't > been able to make it work. I wanna pass one variable to a callback function > and I've read the proper way is: > > Button(......, command=lambda: function(x)) > > So with > > def function(a): print a > > I get the value of x. Ok. My problem now is that I generate the widgets in a > loop and I use the variable to 'label' the widget: > > for x in range(0,3): Button(......, command=lambda: function(x)) > > so pressing each button should give me 0,1,2. > > But with the lambda, I always get the last index, because it gets actualized > at each loop cycle. Is there any way to get that? for x in range(0,3): Button(..., command=functools.partial(function, x)) With the functools standard module that appeared in version 2.5, I hardly ever use lambdas in Tkinter callbacks now. > Thanks in advance! HTH From neilcrighton at gmail.com Mon Nov 2 04:24:13 2009 From: neilcrighton at gmail.com (Neil Crighton) Date: Mon, 2 Nov 2009 09:24:13 +0000 (UTC) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes: > > > > operandlist1=[1,2,3,4,5] > > operandlist2=[5,4,3,2,1] > > > > and resultlist will become [6,6,6,6,6]. Using map(), I can do: > > > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > If the two lists are very large, it would be faster to use this: > If the two lists are *very* large and every element in each list has the same type, you should use NumPy arrays (http://numpy.scipy.org/). >>> import numpy >>> operandlist1 = numpy.array([1, 2, 3, 4, 5]) >>> operandlist2 = numpy.array([5, 4, 3, 2, 1]) >>> resultlist = operandlist1 + operandlist2 >>> resultlist array([6, 6, 6, 6, 6]) Neil From __peter__ at web.de Mon Nov 2 04:26:17 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 10:26:17 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: >> for x in range(0,3): >> Button(......, command=lambda x=x: function(x)) > > An alternative reusable alternative is to create a button-with-id class. > > This is my very first Python class so I'm guessing that there are all > sorts of issues, in particular naming conventions. Pseudo-private attributes, javaesque getter methods, unidiomatic None- checks, broken naming conventions (**args), spaces in funny places... > And the idea of creating a reusable solution for such a small issue may be > un-pythonic? Screw pythonic, the signal/noise ratio is awful in any language. > But just as an example, in Python 3.x, ...for achieving less in more lines? > > import tkinter > # I guess for Python 2.x do "import Tkinter as tkinter" but haven't > # tested. > > > class IdButton( tkinter.Button ): > def __init__( self, owner_widget, id = None, command = None, **args > ): > tkinter.Button.__init__( > self, owner_widget, args, command = self.__on_tk_command > ) > self.__id = id > self.__specified_command = command > > def __on_tk_command( self ): > if self.__specified_command != None: > self.__specified_command( self ) > else: > self.on_clicked() > > def on_clicked( self ): > pass > def id( self ): > return self.__id > def id_string( self ): > return str( self.id() ); > > > def on_button_click( aButton ): > print( "Button " + aButton.id_string() + " clicked!" ) > > window = tkinter.Tk() > > n_buttons = 3 > for x in range( 1, n_buttons + 1 ): > IdButton( > window, id = x, text = "Button " + str( x ), command = > on_button_click ).pack() > > window.mainloop() > I'm not grumpy, I just don't like your code ;) And I don't like the notion that you are about to spread this style with your book... Peter From Brian.Mingus at Colorado.EDU Mon Nov 2 04:37:20 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 2 Nov 2009 02:37:20 -0700 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: <9839a05c0911020137q75a934abq4dcb2f32a6905a54@mail.gmail.com> On Mon, Nov 2, 2009 at 2:26 AM, Peter Otten <__peter__ at web.de> wrote: > Alf P. Steinbach wrote: > > >> for x in range(0,3): > >> Button(......, command=lambda x=x: function(x)) > > > > An alternative reusable alternative is to create a button-with-id class. > > > > This is my very first Python class so I'm guessing that there are all > > sorts of issues, in particular naming conventions. > > Pseudo-private attributes, javaesque getter methods, unidiomatic None- > checks, broken naming conventions (**args), spaces in funny places... > > > And the idea of creating a reusable solution for such a small issue may > be > > un-pythonic? > > Screw pythonic, the signal/noise ratio is awful in any language. > > > But just as an example, in Python 3.x, > > ...for achieving less in more lines? > > > > > import tkinter > > # I guess for Python 2.x do "import Tkinter as tkinter" but haven't > > # tested. > > > > > > class IdButton( tkinter.Button ): > > def __init__( self, owner_widget, id = None, command = None, **args > > ): > > tkinter.Button.__init__( > > self, owner_widget, args, command = self.__on_tk_command > > ) > > self.__id = id > > self.__specified_command = command > > > > def __on_tk_command( self ): > > if self.__specified_command != None: > > self.__specified_command( self ) > > else: > > self.on_clicked() > > > > def on_clicked( self ): > > pass > > def id( self ): > > return self.__id > > def id_string( self ): > > return str( self.id() ); > > > > > > def on_button_click( aButton ): > > print( "Button " + aButton.id_string() + " clicked!" ) > > > > window = tkinter.Tk() > > > > n_buttons = 3 > > for x in range( 1, n_buttons + 1 ): > > IdButton( > > window, id = x, text = "Button " + str( x ), command = > > on_button_click ).pack() > > > > window.mainloop() > > > > I'm not grumpy, I just don't like your code ;) And I don't like the notion > that you are about to spread this style with your book... > > Peter I was going to agree with you ( particularly about this ) but then I saw your __email address__ and realized that you, too, have no style. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 2 04:38:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 10:38:27 +0100 Subject: disable image loading to speed up webpage load In-Reply-To: References: Message-ID: <7l7nklF3cgpk3U1@mid.uni-berlin.de> elca schrieb: > Hi, > im using win32com 's webbrowser module. > i have some question about it.. > is it possible to disable image loading to speed up webpage load? > any help ,much appreciate > thanks in advance Use urllib2. Diez From deets at nospam.web.de Mon Nov 2 04:39:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 10:39:49 +0100 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7l7nn7F3cgpk3U2@mid.uni-berlin.de> Steven D'Aprano schrieb: > On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 >> >> where for example >> >> operandlist1=[1,2,3,4,5] >> operandlist2=[5,4,3,2,1] >> >> and resultlist will become [6,6,6,6,6]. Using map(), I can do: >> >> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > > If the two lists are very large, it would be faster to use this: > > > from operator import add > map(add, operandlist1, operandlist2) > > >> Is there any reasonable way to do this via a list comprehension ? > > [x+y for (x, y) in zip(operandlist1, operandlist2)] > > If the lists are huge, you can save some temporary memory by replacing > zip with itertools.izip. And even more so if one needs the results one by one - then just use a generator-expression. Diez From ben+python at benfinney.id.au Mon Nov 2 05:01:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 21:01:48 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <4aee9d1e$0$19304$426a74cc@news.free.fr> Message-ID: <877hu9kzxv.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Ben Finney a ?crit : > > (Does anyone know of a counter-example, a ?map()? operation that > > doesn't have a correspondingly simple list comprehension?) > > ... depends on your definition of "simple". There are things I'd > rather not write as a list comprehension... That's why I qualified it as I did. I'd be interested to know a ?map()? usage where there isn't a correspondingly simple list comprehension; that is, one that couldn't be done without being significantly more complex than the corresponding ?map()? usage. -- \ ?If we have to give up either religion or education, we should | `\ give up education.? ?William Jennings Bryan, 1923-01 | _o__) | Ben Finney From ben+python at benfinney.id.au Mon Nov 2 05:03:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 21:03:54 +1100 Subject: About one class/function per module References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> <4aee9e9d$0$19304$426a74cc@news.free.fr> Message-ID: <873a4xkzud.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Gabriel Genellina a ?crit : > > You may put one class per file, nobody forbids that > > But anyone having to work on your code will hate you. And if you can find anyone to collaborate with who can stand your insistence on putting one *function* per file, you should probably marry them as being your soul mate. -- \ ?We tend to scoff at the beliefs of the ancients. But we can't | `\ scoff at them personally, to their faces, and this is what | _o__) annoys me.? ?Jack Handey | Ben Finney From SSchukat at dspace.de Mon Nov 2 05:26:42 2009 From: SSchukat at dspace.de (Stefan Schukat) Date: Mon, 2 Nov 2009 11:26:42 +0100 Subject: AW: Python2.6 + win32com crashes with unicode bug In-Reply-To: <4AEB1BAD.4080805@planet.nl> References: <4ae9e43f$0$1637$703f8584@textnews.kpn.nl> <4AEB1BAD.4080805@planet.nl> Message-ID: <9015A9FD792E914DADD11DDEB0753338431B592490@exchange2007.dspace.de> Hello Gerrit, there is no problem in the file, but in the description of the Visio API. The place where the error occurs is during the definition of the parameters of the corresponding Python methods. The information for the names comes from the typelibrary of visio. Probably there is a non english name inside the typelibrary (MS used native names in early Office products) which then could not decoded to a correct Python name. In my Version of Vsio OpenEx has two parameters called FileName and Flags. You have to look in your typelibrary, e.g. with OleView http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en and check the parameters. Regards Stefan -----Urspr?ngliche Nachricht----- Von: python-list-bounces+sschukat=dspace.de at python.org [mailto:python-list-bounces+sschukat=dspace.de at python.org] Im Auftrag von GerritM Gesendet: Freitag, 30. Oktober 2009 18:00 An: Terry Reedy Cc: python-list at python.org Betreff: Re: Python2.6 + win32com crashes with unicode bug Terry Reedy schreef: > GerritM wrote: >> I have automated image generation with Python, win32com and Visio5.0. >> This works well upto Python2.5 but fails with Python 2.6. >> Short term solution is to return to 2.5 :-(. >> >> I have reproduced the bug below with a minimum of Python lines. Below >> the problem the working example from 2.5 >> >> kind regards, Gerrit >> >> ---minimal session reproducing the bug--- >> <..snip..> >> d = v.Documents.OpenEx("D:/temp/test.vsd",8) <...snip...> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position >> 52: ordinal not in range(128) > > I suspect that 2.6 fixed the bug of allowing non-ascii chars when using > the ascii codec. I would check to see if there is an 0x83 in > D:/temp/test.vsd > <...snip...> the string "D:/temp/test.vsd" itself does not contain any charactervalue>128: >>> for c in "D:/temp/test.vsd": print ord(c), " ", 68 58 47 116 101 109 112 47 116 101 115 116 46 118 115 100 (on my current Python 2.5 configuration) The presumably binary file itself may contain any value, but I don't expect Python or win32com to do anything with the file content... There are explanations on internet that Windows uses internally 2 (incompatible) API's that cause poblems with Unicode based filenames. I do something like that to be the problem in Python 2.6 kind regards, Gerrit -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Mon Nov 2 05:37:43 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 11:37:43 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > Alf P. Steinbach wrote: > >>> for x in range(0,3): >>> Button(......, command=lambda x=x: function(x)) >> An alternative reusable alternative is to create a button-with-id class. >> >> This is my very first Python class so I'm guessing that there are all >> sorts of issues, in particular naming conventions. > > Pseudo-private attributes That means there is some way of making attributes private? Probably that comes across as an inane question but I ask it anyway. I haven't really started to look at Python classes. I'm guessing that by asking here I may learn things that are not obvious from the documentation. >, javaesque getter methods, What do you mean by that? What I associate with Java getter method is mainly the "get" prefix, for Java introspection. > unidiomatic None-checks What's the idiomatic Python way for an optional thing? In this case one alternative I see could be to get rid of the __on_tc_command method and more directly tell tkinter.Button to call the relevant function, doing the if-else choice once only in the IdButton constructor. Is that what you mean? I'm thinking more in terms of customization points when I write code. So I tend to avoid hardcoding things internally in methods, instead designing the choices out to where they're accessible to client code. >, broken naming conventions (**args), How to do this argument forwarding in modern style? Or is there an alternative to argument forwarding for this example? > spaces in funny places... Bah. ;-) >> And the idea of creating a reusable solution for such a small issue may be >> un-pythonic? > > Screw pythonic, the signal/noise ratio is awful in any language. > >> But just as an example, in Python 3.x, > > ...for achieving less in more lines? Now, that's a good Python-independent question! :-) Re your question's the number of lines: /if/ the code is heavily reused then the number of lines doesn't matter since they're only written /once/; the net effect can even be to reduce the total number of lines, or at least the number of apparent function points (or whatever size metric). That's part of what "reusable" means. For example, if the OP used the code then he or she didn't type them lines, but just copy/paste'd them, less work than typing in a lambda definition in every button creation, and more clear code at every creation. Re your question's what (the) reusability achieves. First, when you and others have used such a thing in a number of places then you gain confidence in correctness. For example, you don't wonder whether Python's str type is correct, and when you test your program you don't test the str type implementation. Since it's been used so much you know that it (mainly) is correct, and that any remaining bug in there can't be all that serious, because if it was then it would've surfaced in earlier use of the type. This advantage of confidence in correctness can be realized even without heavy reuse, because the encapsulation that's necessary for reuse, here having the code in a class, also makes it possible with more centralized testing. A centralized, encapsulated piece of code can be tested to death and deemed correct (enough) and frozen, while the application of a code pattern in umpteen places in umpteen programs, generally can't. Second, when you do find a bug, or need more functionality, or whatever, there's just /one place/ to fix/extend, whatever, instead of updating umpteen places in umpteen programs, and trying to be sure that you've covered all instances and done the right thing every place regardless of local variations (which is pretty hopeless in general, but my experience with that kind of badness has mostly been with C, not Python). More technically, it's reduced redundancy, in this case avoiding redundant application of a code pattern everywhere one needs a button with id (if that happens often). Reduced redundancy = good. And third, as I mentioned, at every button creation, or in general every place you'd use inline code rather than some reusable thing, you can get more clear code, which can (but will not automatically :-) ) reduce maintainance time. But, the big drawback. It's easy to become enamoured by reusability and invest a lot of work in encapsulation and general reusability, since it has those three big desirable traits. But when what one creates is not actually reused then most of that work can be /wasted/... :-) For example, if the code only is used in 1 place, then the advantage of centralized testing is pretty moot unless that code is changing for other reasons, for it doesn't matter much if you test it here or there. It can be simpler to test it here, inline, than over there. And another big drawback, but I believe it's less important in Python, that a reusable thing can be less efficient because it can't take advantage of locally available information and functionality each place where it's used, while inline code that achieves the same (applying a pattern) can take advantage. >> >> import tkinter >> # I guess for Python 2.x do "import Tkinter as tkinter" but haven't >> # tested. >> >> >> class IdButton( tkinter.Button ): >> def __init__( self, owner_widget, id = None, command = None, **args >> ): >> tkinter.Button.__init__( >> self, owner_widget, args, command = self.__on_tk_command >> ) >> self.__id = id >> self.__specified_command = command >> >> def __on_tk_command( self ): >> if self.__specified_command != None: >> self.__specified_command( self ) >> else: >> self.on_clicked() >> >> def on_clicked( self ): >> pass >> def id( self ): >> return self.__id >> def id_string( self ): >> return str( self.id() ); >> >> >> def on_button_click( aButton ): >> print( "Button " + aButton.id_string() + " clicked!" ) >> >> window = tkinter.Tk() >> >> n_buttons = 3 >> for x in range( 1, n_buttons + 1 ): >> IdButton( >> window, id = x, text = "Button " + str( x ), command = >> on_button_click ).pack() >> >> window.mainloop() >> > > I'm not grumpy, I just don't like your code ;) And I don't like the notion > that you are about to spread this style with your book... He he. :-) I've yet to acquire any Python style. Cheers, & thanks, - Alf From ilmirons at gmail.com Mon Nov 2 05:41:48 2009 From: ilmirons at gmail.com (Mirons) Date: Mon, 2 Nov 2009 02:41:48 -0800 (PST) Subject: About "Object in list" expression Message-ID: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> Hi everybody! I'm having a very annoying problem with Python: I need to check if a (mutable) object is part of a list but the usual expression return True also if the object isn't there. I've implemented both __hash__ and __eq__, but still no result. what does "in" implementation use for comparison (Python is 2.6)? From joncle at googlemail.com Mon Nov 2 05:46:10 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 2 Nov 2009 02:46:10 -0800 (PST) Subject: About "Object in list" expression References: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> Message-ID: <326c5001-936b-4148-b625-d16b02d9fbc3@v30g2000yqm.googlegroups.com> On Nov 2, 10:41?am, Mirons wrote: > Hi everybody! I'm having a very annoying problem with Python: I need > to check if a (mutable) object is part of a list but the usual > expression return True also if the object isn't there. I've > implemented both __hash__ and __eq__, but still no result. what does > "in" implementation use for comparison (Python is 2.6)? It would help showing an example... From jocjo at mail.dk Mon Nov 2 05:49:32 2009 From: jocjo at mail.dk (Hans Larsen) Date: Mon, 2 Nov 2009 11:49:32 +0100 Subject: exec-function in Python 3.+ Message-ID: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Help! I'm begginer in Python 3.+! If i wih to update a module after an import and chages, How could I do: By "from imp import reload" and then reload(mymodule) or how to use "exec(?)", it is mentoined in docs. In Python ver. <3 reload(module) writes something back to interpretter!, how about exec, which is a function?-:) I,m thanking on the help!! From ilmirons at gmail.com Mon Nov 2 05:59:15 2009 From: ilmirons at gmail.com (Mirons) Date: Mon, 2 Nov 2009 02:59:15 -0800 (PST) Subject: About "Object in list" expression References: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> <326c5001-936b-4148-b625-d16b02d9fbc3@v30g2000yqm.googlegroups.com> Message-ID: <39f99610-b187-41d8-9efb-cb759b935a20@b2g2000yqi.googlegroups.com> On 2 Nov, 11:46, Jon Clements wrote: > On Nov 2, 10:41?am, Mirons wrote: > > > Hi everybody! I'm having a very annoying problem with Python: I need > > to check if a (mutable) object is part of a list but the usual > > expression return True also if the object isn't there. I've > > implemented both __hash__ and __eq__, but still no result. what does > > "in" implementation use for comparison (Python is 2.6)? > > It would help showing an example... I just solved the problem! (Sorry for the bother). It was a matter of inplementation. It's __eq__ that is called for checking instances in list but I had implemented two version of __eq__ in different parts of code and the interpreter chose the wrong one. Excuse me again for the bother. From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 06:29:53 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 12:29:53 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <877hu9kzxv.fsf@benfinney.id.au> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <4aee9d1e$0$19304$426a74cc@news.free.fr> <877hu9kzxv.fsf@benfinney.id.au> Message-ID: <4aeec2b0$0$30849$426a74cc@news.free.fr> Ben Finney a ?crit : > Bruno Desthuilliers writes: > >> Ben Finney a ?crit : >>> (Does anyone know of a counter-example, a ?map()? operation that >>> doesn't have a correspondingly simple list comprehension?) >> ... depends on your definition of "simple". There are things I'd >> rather not write as a list comprehension... > > That's why I qualified it as I did. I'd be interested to know a ?map()? > usage where there isn't a correspondingly simple list comprehension; > that is, one that couldn't be done without being significantly more > complex than the corresponding ?map()? usage. I know I've seen the case, and more than once, but I'm afraid I don't have any example to publish here - I'd need to do quite a bit of archeology :-/ From joncle at googlemail.com Mon Nov 2 06:34:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 2 Nov 2009 03:34:08 -0800 (PST) Subject: exec-function in Python 3.+ References: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Message-ID: <81415eb9-76e3-4ccf-b44a-af4e609252a5@w19g2000yqk.googlegroups.com> On 2 Nov, 10:49, "Hans Larsen" wrote: > Help! > ? ? I'm begginer in Python 3.+! > ? ? If i wih to update a module after an import and chages, > ? ? How could I do: > ? ? By "from imp import reload" and then reload(mymodule) > ? ? or how to use "exec(?)", it is mentoined in docs. > ? ? In Python ver. <3 reload(module) writes something back to interpretter!, > how about exec, which is a function?-:) > ? ? I,m thanking on the help!! What makes you think you need to 'reload' a module. If you don't know exactly what you're doing (by saying you're a beginner I'm guessing not...), and aware of the consequences that can follow... I would say, *don't*. There's too much to bite you in the rear (and not a blatant bite from a lion, but rather a playful little kitten that then plays cute and exudes a "moi?" expression). Also, it may help others to post their thoughts if you tried to describe why you think you want to go down this line, and what you're trying to achieve. Jon. From __peter__ at web.de Mon Nov 2 07:18:18 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 13:18:18 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>>> for x in range(0,3): >>>> Button(......, command=lambda x=x: function(x)) >>> An alternative reusable alternative is to create a button-with-id class. >>> >>> This is my very first Python class so I'm guessing that there are all >>> sorts of issues, in particular naming conventions. >> >> Pseudo-private attributes > > That means there is some way of making attributes private? No, there isn't. And the name mangled __attribute is hardly ever needed. Use _attribute to convey the message "If you mess with this attribute you're on your own". > Probably that comes across as an inane question but I ask it anyway. I > haven't really started to look at Python classes. I'm guessing that by > asking here I may learn things that are not obvious from the > documentation. > > >>, javaesque getter methods, > > What do you mean by that? In Java you have a private attribute and a public getter method. In Python you can just make the attribute public, i. e. # bad class A: def __init__(self): self._id = 42 def id(self): return self._id # good class A: def __init__(self): self.id = 42 You can always switch to class A: # assuming 3.x @property def id(self): id = arbitrary_code() return id later. > What I associate with Java getter method is mainly the "get" prefix, for > Java introspection. > > >> unidiomatic None-checks > > What's the idiomatic Python way for an optional thing? if some_value is None: ... > In this case one alternative I see could be to get rid of the > __on_tc_command method and more directly tell tkinter.Button to call the > relevant function, doing the if-else choice once only in the IdButton > constructor. > > Is that what you mean? > > I'm thinking more in terms of customization points when I write code. > > So I tend to avoid hardcoding things internally in methods, instead > designing the choices out to where they're accessible to client code. > > >>, broken naming conventions (**args), > > How to do this argument forwarding in modern style? I meant that keyword args are traditionally named kw or kwargs, the name "args" is normally used for positional arguments: def f(*args, **kw): "whatever" > Or is there an alternative to argument forwarding for this example? > > >> spaces in funny places... > > Bah. ;-) > > >>> And the idea of creating a reusable solution for such a small issue may >>> be un-pythonic? >> >> Screw pythonic, the signal/noise ratio is awful in any language. >> >>> But just as an example, in Python 3.x, >> >> ...for achieving less in more lines? > > Now, that's a good Python-independent question! :-) > > Re your question's the number of lines: /if/ the code is heavily reused > then the number of lines doesn't matter since they're only written /once/; Every time someone has to read the code he will read, hesitate, read again, and then hopefully come to the conclusion that the code does nothing, consider not using it, or if it is not tied into a larger project removing it. > the net effect can even be to reduce the total number of lines, or at > least the number of apparent function points (or whatever size metric). > That's part of what "reusable" means. For example, if the OP used the code > then he or she didn't type them lines, but just copy/paste'd them, less > work than typing in a lambda definition in every button creation, and more > clear code at every creation. But most of your code does *nothing*. > Re your question's what (the) reusability achieves. > > First, when you and others have used such a thing in a number of places > then you gain confidence in correctness. For example, you don't wonder > whether Python's str type is correct, and when you test your program you > don't test the str type implementation. Since it's been used so much you > know that it (mainly) is correct, and that any remaining bug in there > can't be all that serious, because if it was then it would've surfaced in > earlier use of the type. The theory may be OK, but in practice it doesn't always work out. Example: Why do you introduce button.id_string() instead of str(button.id)? The programmer will hesitate, wonder whether to use button.id() or button.id_string(), how the two may interconnect... It feels more like a hoop to jump through than a helpful service providing tried an tested code. > This advantage of confidence in correctness can be realized even without > heavy reuse, because the encapsulation that's necessary for reuse, here > having the code in a class, also makes it possible with more centralized > testing. Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ ? > A centralized, encapsulated piece of code can be tested to death and > deemed correct (enough) and frozen, while the application of a code > pattern in umpteen places in umpteen programs, generally can't. I'd like to see a good test suite for your IdButton class, especially how it copes with the design decision that you can override the on_clicked() stub, or provide a command function, or both. > Second, when you do find a bug, or need more functionality, or whatever, > there's just /one place/ to fix/extend, whatever, instead of updating > umpteen places in umpteen programs, and trying to be sure that you've > covered all instances and done the right thing every place regardless of > local variations (which is pretty hopeless in general, but my experience > with that kind of badness has mostly been with C, not Python). More > technically, it's reduced redundancy, in this case avoiding redundant > application of a code pattern everywhere one needs a button with id (if > that happens often). Reduced redundancy = good. I agree with that maxim. Incidentally I have just found a nice example of redundancy for you: >>> def __on_tk_command( self ): >>> if self.__specified_command != None: >>> self.__specified_command( self ) >>> else: >>> self.on_clicked() Peter From henrik.sorensen at changenetworks.dk Mon Nov 2 07:29:24 2009 From: henrik.sorensen at changenetworks.dk (Henrik Aagaard =?ISO-8859-1?Q?S=F8rensen?=) Date: Mon, 02 Nov 2009 13:29:24 +0100 Subject: Help with SOAPpy and WSDL. Message-ID: <1257164964.22254.0.camel@apollo> I have a problem with SOAPpy and WSDL. It is explained here: http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 Many regards, Henrik From simon at brunningonline.net Mon Nov 2 07:58:03 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 2 Nov 2009 12:58:03 +0000 Subject: Help with SOAPpy and WSDL. In-Reply-To: <1257164964.22254.0.camel@apollo> References: <1257164964.22254.0.camel@apollo> Message-ID: <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> 2009/11/2 Henrik Aagaard S?rensen : > I have a problem with SOAPpy and WSDL. It is explained here: > http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 Why not explain it here? In any case, I imagine the advice is going to be to try Suds - . -- Cheers, Simon B. From deets at nospam.web.de Mon Nov 2 08:07:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 14:07:38 +0100 Subject: Tkinter callback arguments References: Message-ID: <7l83sqF3bac80U1@mid.uni-berlin.de> Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>>> for x in range(0,3): >>>> Button(......, command=lambda x=x: function(x)) >>> An alternative reusable alternative is to create a button-with-id class. >>> >>> This is my very first Python class so I'm guessing that there are all >>> sorts of issues, in particular naming conventions. >> >> Pseudo-private attributes > > That means there is some way of making attributes private? No, it means that in Python we are consenting adults, and either respect attributes with a leading underscore as private - or willfully chose to *not* do that because of good reasons. And the double-underscore is used against name-clashes, not for enhanced "privacy". >>, javaesque getter methods, > > What do you mean by that? > > What I associate with Java getter method is mainly the "get" prefix, for > Java introspection. You have an attribute id, whatfor do you need a method id? If at some point this id becomes a computed value - you introduce a property And that's what Peter meant with "javanesque" - the exact reason why in java everything is wrapped in getters/setters is that the language lacks a property-mechanism, so to present a consistent interface over several iterations of the code, one has to introduce them for every single attribute - regardless of their future destiny. > >> unidiomatic None-checks > > What's the idiomatic Python way for an optional thing? None is a singleton, so the idiomatic check is for object identity: foo = None foo is None Diez From pengyu.ut at gmail.com Mon Nov 2 08:11:28 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 07:11:28 -0600 Subject: About one class/function per module In-Reply-To: <4aeea07e$0$713$426a34cc@news.free.fr> References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers wrote: > Peng Yu a ?crit : > (snip) >> >> I prefer organized my code one class/function per file (i.e per module >> in python). I know the majority of programmers don't use this >> approach. Therefore, I'm wondering what its disadvantage is. > > Hmmm... As far as I'm concerned, you already answered your own question: > "the majority of programmers don't use this approach". > > Now, for a much more practical answer: > 1/ having to handle thousands of files for even a simple project is a > king-size PITA for the maintainer. > 2/ having to load thousands of modules will add quite a lot of overhead when > actually running the code. > 3/ as a result, the poor guy that will end up maintaining your code will > positively hate you. Beware : this poor guy might as well be you. I still don't understand why it is a nightmare to maintain the code. For my C++ project, so far so good. I can easily change filenames (that is class name or function name), I can easily find them, I can easily move things around, all with just the corresponding script command. I can navigate to the definition of class and function by vim + ctags, I can see example code that calls the class/function. Whenever I suspect there is a bug, I can easily go to the right level of class/function in the directory hierarchy to write a test case to trace down the bug without having to use gdb. Would you please let me why it is a nightmare? From pengyu.ut at gmail.com Mon Nov 2 08:24:59 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 07:24:59 -0600 Subject: About one class/function per module In-Reply-To: <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> Message-ID: <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> On Mon, Nov 2, 2009 at 7:11 AM, Peng Yu wrote: > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead when >> actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. > For my C++ project, so far so good. > > I can easily change filenames (that is class name or function name), I > can easily find them, I can easily move things around, all with just > the corresponding script command. I can navigate to the definition of > class and function by vim + ctags, I can see example code that calls > the class/function. Whenever I suspect there is a bug, I can easily go > to the right level of class/function in the directory hierarchy to > write a test case to trace down the bug without having to use gdb. > > Would you please let me why it is a nightmare? Another advantage one of class/function per file is that the syntax clearly tell the dependence relation between classes and functions. Suppose I have class A and class B in a file, I can not easily figure out which class depends on which class by a simple script. However, if they are in two separate files, for example B depends on A, then I will have 'import A' in file B. This dependency can be easily figured out by a script. The following scenario also demonstrate why the maintenance cost is lower with one class/function per file, because it decouples dependences. Let's suppose class A and B are in the same file. Now I'm changing class B. But while I'm changing class B, I just realize that I have to change A. But since the change in B is half way done (syntactical not correct), I will not be able to run the test case for A, because the test case import the file that has class B. In contrast, if A and B are in different files, even if B is half way done, I can still run test case for A. From deets at nospam.web.de Mon Nov 2 08:27:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 14:27:40 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <7l852dF3c5gi1U1@mid.uni-berlin.de> Peng Yu wrote: > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead >> when actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. > For my C++ project, so far so good. > > I can easily change filenames (that is class name or function name), I > can easily find them, I can easily move things around, all with just > the corresponding script command. I can navigate to the definition of > class and function by vim + ctags, I can see example code that calls > the class/function. Whenever I suspect there is a bug, I can easily go > to the right level of class/function in the directory hierarchy to > write a test case to trace down the bug without having to use gdb. > > Would you please let me why it is a nightmare? My current project has about 1300 source-files (luckily *not* laid out in your preferred way), which contain 1900 function-definitions (most probably even more so) and about 1700 classes. So your "approach" more than doubles the number of files to juggle around - in my head, in my editor, and so on. Not to speak about the inability to rename a function or class just in source-code. No, I'd also have to rename the file, causing all kinds of extra issues when using version-control-systems (which of course I do). It's simply a braindead idea. Get over it. Get rid of your "useful" scripts. Start learning a decent editor (emacs is mine) which allows you to deal with all of your perceived "problems" without making even small projects a nightmare of a bazillion files. Again: *program* in python, don't fantasize about something that's not there, and writing shoehorning-scripts. That's just an excuse to be ineffective. Diez From patrick.oloughlin at gmail.com Mon Nov 2 08:28:02 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Mon, 2 Nov 2009 13:28:02 +0000 Subject: Accessing a method from within its own code Message-ID: Hi, I was wondering if there was a shorthand way to get a reference to a method object from within that method's code. Take this code snippet as an example: import re class MyClass(object): def find_line(self, lines): if not hasattr(MyClass.do_work, "matcher"): MyClass.do_work.matcher = re.compile("\d - (.+)") for line in lines: m = MyClass.do_work.matcher.match(line) if m: return m.groups() Here, I have a method which uses a regular expression object to find matches. I want the regexp object to be tied to the function, but I don't want to have to recreate it every time the function is called (I am aware that regexp objects are cached, avoiding this problem, but I'm just using this as an example for what I want to know), so I've added it to the method object as an attribute and create it only if it doesn't exist. However, typing out .. everytime is pretty long and susceptible to refactoring issues, so I was wondering if there was a way in Python that I am missing which allows you to reference the method that the code is in (like __module__ gives a reference to the parent module). Paddy -- "Ray, when someone asks you if you're a god, you say YES!" -------------- next part -------------- An HTML attachment was scrubbed... URL: From heroshaojun at gmail.com Mon Nov 2 08:34:09 2009 From: heroshaojun at gmail.com (Junjun Shao) Date: Mon, 2 Nov 2009 21:34:09 +0800 Subject: have opensource crawler written by python? Message-ID: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> hi, Is there a crawler written by python? anybody can give me more information? thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Mon Nov 2 08:45:28 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Nov 2009 08:45:28 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87y6mpvy4n.fsf@agentultra.com> Steven D'Aprano writes: > On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 >> >> where for example >> >> operandlist1=[1,2,3,4,5] >> operandlist2=[5,4,3,2,1] >> >> and resultlist will become [6,6,6,6,6]. Using map(), I can do: >> >> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > > If the two lists are very large, it would be faster to use this: > > > from operator import add > map(add, operandlist1, operandlist2) This is the best solution so far. > > >> Is there any reasonable way to do this via a list comprehension ? > > [x+y for (x, y) in zip(operandlist1, operandlist2)] > > If the lists are huge, you can save some temporary memory by replacing > zip with itertools.izip. I understand the OP was asking for it, but list comprehensions aren't the best solution in this case... it would just be line noise. List comprehensions are good for one-off transformations where it would only create a one-time method for map to use. From alfps at start.no Mon Nov 2 08:54:11 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 14:54:11 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > Alf P. Steinbach wrote: > >> * Peter Otten: >>> Alf P. Steinbach wrote: >>> >>>>> for x in range(0,3): >>>>> Button(......, command=lambda x=x: function(x)) >>>> An alternative reusable alternative is to create a button-with-id class. >>>> >>>> This is my very first Python class so I'm guessing that there are all >>>> sorts of issues, in particular naming conventions. >>> Pseudo-private attributes >> That means there is some way of making attributes private? > > No, there isn't. And the name mangled __attribute is hardly ever needed. Use > _attribute to convey the message "If you mess with this attribute you're on > your own". Thanks! >> Probably that comes across as an inane question but I ask it anyway. I >> haven't really started to look at Python classes. I'm guessing that by >> asking here I may learn things that are not obvious from the >> documentation. >> >> >>> , javaesque getter methods, >> What do you mean by that? > > In Java you have a private attribute and a public getter method. In Python > you can just make the attribute public, i. e. > > # bad > class A: > def __init__(self): > self._id = 42 > def id(self): return self._id > > # good > class A: > def __init__(self): > self.id = 42 I think I get the gist that locally saving lines of code, and generally avoiding having to write empty argument list parentheses, and thereby also indicating in a way that one is accessing a logical data attribute, is considered good in Python, which goes to initial development time and the amount of code that one must scan to grok it both for definition and usage -- is that correct? But the trade-off is inviting modification of a supposedly fixed id, which goes to correctness and later fix-it time? > You can always switch to > > class A: # assuming 3.x > @property > def id(self): > id = arbitrary_code() > return id > > later. Thanks, now I learned about @property... :-) But when the thing has been used it's much more difficult to restrict the functionality (making read-only, breaking code that changes id) than to add functionality (making also writeable, breaking none of existing code). So isn't "later" a bit late to make it read-only, shouldn't that be the initial design, and then possibly adding a setter later if id's turn out to not be so constant after all? >> What I associate with Java getter method is mainly the "get" prefix, for >> Java introspection. >> >> >>> unidiomatic None-checks >> What's the idiomatic Python way for an optional thing? > > if some_value is None: ... Thanks! But why is this preferred? >> In this case one alternative I see could be to get rid of the >> __on_tc_command method and more directly tell tkinter.Button to call the >> relevant function, doing the if-else choice once only in the IdButton >> constructor. >> >> Is that what you mean? >> >> I'm thinking more in terms of customization points when I write code. >> >> So I tend to avoid hardcoding things internally in methods, instead >> designing the choices out to where they're accessible to client code. >> >> >>> , broken naming conventions (**args), >> How to do this argument forwarding in modern style? > > I meant that keyword args are traditionally named kw or kwargs, the name > "args" is normally used for positional arguments: > > def f(*args, **kw): > "whatever" Thanks! *Note to myself*: check if there are more such conventions. >> Or is there an alternative to argument forwarding for this example? >> >> >>> spaces in funny places... >> Bah. ;-) >> >> >>>> And the idea of creating a reusable solution for such a small issue may >>>> be un-pythonic? >>> Screw pythonic, the signal/noise ratio is awful in any language. >>> >>>> But just as an example, in Python 3.x, >>> ...for achieving less in more lines? >> Now, that's a good Python-independent question! :-) >> >> Re your question's the number of lines: /if/ the code is heavily reused >> then the number of lines doesn't matter since they're only written /once/; > > Every time someone has to read the code he will read, hesitate, read again, > and then hopefully come to the conclusion that the code does nothing, > consider not using it, or if it is not tied into a larger project removing > it. I don't understand what you mean. Not that it's a shiny example of code that does a lot, but it (1) simplifies and shortens creation of buttons with id, and (2) provides a nice start for adding other customizations of those buttons, and (3) supports searching for a button with given command id, e.g. for purpose of hiding or enable/disable. If I didn't just want to try out writing a Python class, which I've never done before so it appeared interesting, I'd probably just skipped points 2 and 3 and written the same functionality as a factory function, like import tkinter def id_button( owner_widget, id, command = None, **kwargs ): def tk_command( an_id = id, a_command = command ): if a_command is not None: a_command( id ) return tkinter.Button( owner_widget, kwargs, command = tk_command ) def on_button_click( id ): print( "Button " + str( id ) + " clicked!" ) window = tkinter.Tk() n_buttons = 3 for x in range( 1, n_buttons + 1 ): id_button( window, id = x, text = "Button " + str( x ), command = on_button_click ).pack() window.mainloop() but once you have the class, for whatever reason, it would be silly not to use it, especially since it provides points 2 and 3 which the function doesn't. By the way, I as yet know next to *nothing* about binding of variable references within a function such as tk_command above. Probably I've done Unnecessary Things(TM) above? >> the net effect can even be to reduce the total number of lines, or at >> least the number of apparent function points (or whatever size metric). >> That's part of what "reusable" means. For example, if the OP used the code >> then he or she didn't type them lines, but just copy/paste'd them, less >> work than typing in a lambda definition in every button creation, and more >> clear code at every creation. > > But most of your code does *nothing*. See above, points 2 and 3. Most of that class has to do with 2, customization ability. >> Re your question's what (the) reusability achieves. >> >> First, when you and others have used such a thing in a number of places >> then you gain confidence in correctness. For example, you don't wonder >> whether Python's str type is correct, and when you test your program you >> don't test the str type implementation. Since it's been used so much you >> know that it (mainly) is correct, and that any remaining bug in there >> can't be all that serious, because if it was then it would've surfaced in >> earlier use of the type. > > The theory may be OK, but in practice it doesn't always work out. Example: > Why do you introduce button.id_string() instead of str(button.id)? Because the string representation of an id then /can/ be customized independently of the id. For example, id's might be integers but for string representation you might want symbolic action names (e.g., you might have two or more buttons with same title but different actions, so that title would be ungood to identify button). And for another example, when debugging or testing you might want the string represention of an id to provide more information about the button and/or its context, and then id_string provides a single central customization point -- provided it's used, of course. > The > programmer will hesitate, wonder whether to use button.id() or > button.id_string(), how the two may interconnect... Hm, see immediately above. It's perhaps a different way of thinking? > It feels more like a hoop to jump through than a helpful service providing > tried an tested code. Yes. It's the old "every computer science problem can be solved by adding an extra layer of indirection". Sometimes it's nice when you can do that centrally. Retrofitting the indirection to existing client code can be hard. >> This advantage of confidence in correctness can be realized even without >> heavy reuse, because the encapsulation that's necessary for reuse, here >> having the code in a class, also makes it possible with more centralized >> testing. > > Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ ? No. :-) But you're right that testing isn't that much of an issue for that class. If that's what you meant. >> A centralized, encapsulated piece of code can be tested to death and >> deemed correct (enough) and frozen, while the application of a code >> pattern in umpteen places in umpteen programs, generally can't. > > I'd like to see a good test suite for your IdButton class, especially how it > copes with the design decision that you can override the on_clicked() stub, > or provide a command function, or both. The design is that for any given IdButton there's a single point of responsibility for the click action, namely either a button creation code supplies that action, or it relies on the action defined in the class. I.e. again customization ability, that the button creation code can /override/ the class provided action, per button, without getting into general overriding of class methods, just by defining a nice little lambda inline in the call. But as I learn more Python I may perhaps find that overriding class methods can also be done that conveniently -- I don't know, keep in mind I'm a Python newbie, and doing Very Much Else than studying Python. :-) >> Second, when you do find a bug, or need more functionality, or whatever, >> there's just /one place/ to fix/extend, whatever, instead of updating >> umpteen places in umpteen programs, and trying to be sure that you've >> covered all instances and done the right thing every place regardless of >> local variations (which is pretty hopeless in general, but my experience >> with that kind of badness has mostly been with C, not Python). More >> technically, it's reduced redundancy, in this case avoiding redundant >> application of a code pattern everywhere one needs a button with id (if >> that happens often). Reduced redundancy = good. > > I agree with that maxim. Incidentally I have just found a nice example of > redundancy for you: > >>>> def __on_tk_command( self ): >>>> if self.__specified_command != None: >>>> self.__specified_command( self ) >>>> else: >>>> self.on_clicked() > Uh, could you expand on how that's redundant and how to make it less so? Cheers, & thanks, - Alf From alfps at start.no Mon Nov 2 09:12:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 15:12:31 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l83sqF3bac80U1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Alf P. Steinbach wrote: > >> * Peter Otten: >>> Alf P. Steinbach wrote: >>> >>>>> for x in range(0,3): >>>>> Button(......, command=lambda x=x: function(x)) >>>> An alternative reusable alternative is to create a button-with-id class. >>>> >>>> This is my very first Python class so I'm guessing that there are all >>>> sorts of issues, in particular naming conventions. >>> Pseudo-private attributes >> That means there is some way of making attributes private? > > No, it means that in Python we are consenting adults, and either respect > attributes with a leading underscore as private - or willfully chose to > *not* do that because of good reasons. Hm. But thanks! That's very useful information -- now I'll not be going on a wild goose chase! > And the double-underscore is used against name-clashes, not for > enhanced "privacy". > >>> , javaesque getter methods, >> What do you mean by that? >> >> What I associate with Java getter method is mainly the "get" prefix, for >> Java introspection. > > You have an attribute id, whatfor do you need a method id? If at some point > this id becomes a computed value - you introduce a property > > And that's what Peter meant with "javanesque" - the exact reason why in java > everything is wrapped in getters/setters is that the language lacks a > property-mechanism, so to present a consistent interface over several > iterations of the code, one has to introduce them for every single > attribute - regardless of their future destiny. Thanks again for useful information. Also Peter mentioned this about changing simple attributes into properties at later time, so that seems to at least not be unheard of in Python? Your comment about "computed" makes it more clear what that's all about. Also Bertrand Meyer (Eiffel language creator) had idea like that, he called it "referential transparency". But I think when Python has this nice property mechanism, why do people change direct data attributes into properties and not the other way around or not at all, I mean using only properties for logical data attributes -- e.g. assuring correctness first via read-only property? >>> unidiomatic None-checks >> What's the idiomatic Python way for an optional thing? > > None is a singleton, so the idiomatic check is for object identity: > > foo = None > foo is None Again, thanks, that helps me understand the rationale. Although not completely. But there is a connection... Cheers, - Alf From deets at nospam.web.de Mon Nov 2 09:18:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 15:18:37 +0100 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: <7l881tF3dbb00U1@mid.uni-berlin.de> > Your comment about "computed" makes it more clear what that's all about. > Also Bertrand Meyer (Eiffel language creator) had idea like that, he > called it "referential transparency". But I think when Python has this > nice property mechanism, why do people change direct data attributes into > properties and not the other way around or not at all, I mean using only > properties for logical > data attributes -- e.g. assuring correctness first via read-only > property? I fail to see where read-only-ness of an attribute is a priori more correct than having modifyable attributes. Again, it's an assumption of a future use or constraint that is most of the times simply not correct or relevant - at the price for more typing, and computational overhead. Diez From henrik.sorensen at changenetworks.dk Mon Nov 2 09:25:37 2009 From: henrik.sorensen at changenetworks.dk (Henrik Aagaard =?ISO-8859-1?Q?S=F8rensen?=) Date: Mon, 02 Nov 2009 15:25:37 +0100 Subject: Help with SOAPpy and WSDL. In-Reply-To: <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> References: <1257164964.22254.0.camel@apollo> <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> Message-ID: <1257171937.22254.2.camel@apollo> I'll try to explain it here then: A small example on SOAPpy and WSDL. My code: from SOAPpy import WSDL wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl' server = WSDL.Proxy(wsdlFile) server.GetCurrencyByCountry('Zimbabwe') returns: Traceback (most recent call last): File "pythonwsdl.py", line 4, in server.GetCurrencyByCountry('Zimbabwe') File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 492, in __r_call self.__hd, self.__ma) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 406, in __call raise p SOAPpy.Types.faultType: System.Data.SqlClient.SqlException: Procedure or function 'GetCurrencyByCountry' expects parameter '@name', which was not supplied. at WebServicex.country.GetCurrencyByCountry(String CountryName) --- End of inner exception stack trace ---: > It is as if it doesn't get the name "Zimbabwe". On Mon, 2009-11-02 at 12:58 +0000, Simon Brunning wrote: > 2009/11/2 Henrik Aagaard S?rensen : > > I have a problem with SOAPpy and WSDL. It is explained here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 > > Why not explain it here? > > In any case, I imagine the advice is going to be to try Suds - > . > From fetchinson at googlemail.com Mon Nov 2 09:25:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 15:25:57 +0100 Subject: have opensource crawler written by python? In-Reply-To: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> References: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> Message-ID: > Is there a crawler written by python? anybody can give me more information? http://www.google.com/search?q=python+web+crawlers HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From collin.day.0 at gmail.com Mon Nov 2 09:27:25 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 2 Nov 2009 06:27:25 -0800 (PST) Subject: Command parsing... best module to use? Message-ID: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Hey everyone. I am writing a game in python, and it includes a text console somewhat like the one in WoW and Runescape. I want to be able to include "/" commands, like IRC, and was wondering what the best module would be to parse these. Thanks a lot, Collin D From fetchinson at googlemail.com Mon Nov 2 09:30:09 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 15:30:09 +0100 Subject: Pyfora, a place for python In-Reply-To: <87my36my79.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> Message-ID: >> If you have any suggestions, let me know -- this is a community >> effort! > > Suggestion: Please don't make efforts to fragment the community. When a community grows and consequently its needs also grow, how do you differentiate "natural growth" from "fragmenting the community"? Same question in another way: let's suppose Tim Peters sent the exact email the OP sent with the exact same website. Would you have responded to him the same way? > Rather, please direct seekers to the existing forums (the IRC channel, > the Usenet groups and mailing lists) rather than setting up new walled > gardens. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From simon at brunningonline.net Mon Nov 2 09:30:54 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 2 Nov 2009 14:30:54 +0000 Subject: Help with SOAPpy and WSDL. In-Reply-To: <1257171937.22254.2.camel@apollo> References: <1257164964.22254.0.camel@apollo> <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> <1257171937.22254.2.camel@apollo> Message-ID: <8c7f10c60911020630q41eaa1ccwfc14f8b0ea6fa5a6@mail.gmail.com> 2009/11/2 Henrik Aagaard S?rensen : > I'll try to explain it here then: > > A small example on SOAPpy and WSDL. My code: > from SOAPpy import WSDL > wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl' > server = WSDL.Proxy(wsdlFile) > server.GetCurrencyByCountry('Zimbabwe') > > returns: > System.Web.Services.Protocols.SoapException: Server was unable to > process request. ---> System.Data.SqlClient.SqlException: Procedure or > function 'GetCurrencyByCountry' expects parameter '@name', which was not > supplied. > ? at WebServicex.country.GetCurrencyByCountry(String CountryName) > ? --- End of inner exception stack trace ---: > > > > It is as if it doesn't get the name "Zimbabwe". Try server.GetCurrencyByCountry(name='Zimbabwe') -- Cheers, Simon B. From deets at nospam.web.de Mon Nov 2 09:44:52 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 15:44:52 +0100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> Message-ID: <7l89j4F3bl107U1@mid.uni-berlin.de> Daniel Fetchinson wrote: >>> If you have any suggestions, let me know -- this is a community >>> effort! >> >> Suggestion: Please don't make efforts to fragment the community. > > When a community grows and consequently its needs also grow, how do > you differentiate "natural growth" from "fragmenting the community"? > > Same question in another way: let's suppose Tim Peters sent the exact > email the OP sent with the exact same website. Would you have > responded to him the same way? Most probably not - but then because Tim certainly would have discussed this move with peers from the community, if there is a need for this kind of forum or not. Being from germany, I can say that we *have* this fragmentation, and frankly: I don't like it. I prefer my communication via NNTP/ML, and not with those visually rather noisy and IMHO suboptimal forums. E.g. it requires much more effort to get to know what new discussions arose, as well as following ongoing ones - because the interface lacks a comprehensive overview of that, and features like "jump to next unread article". Diez From davea at ieee.org Mon Nov 2 09:54:35 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 09:54:35 -0500 Subject: exec-function in Python 3.+ In-Reply-To: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> References: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Message-ID: <4AEEF2AB.3070803@ieee.org> Hans Larsen wrote: > Help! > I'm begginer in Python 3.+! > If i wih to update a module after an import and chages, > How could I do: > By "from imp import reload" and then reload(mymodule) > or how to use "exec(?)", it is mentoined in docs. > In Python ver. <3 reload(module) writes something back to interpretter!, > how about exec, which is a function?-:) > I,m thanking on the help!! > > > I've never used reload() in 2.x or 3.x. If I'm debugging interactively with the command line interpreter and I get to this point, I exit() and start the python interpreter again. And if there was too much typing to waste by doing that, I write the code into another script, and run that from an IDE. From most IDE's, you get a fresh chance every time you start a run. I haven't found any reason to change this behavior. So if you have a use-case, please elaborate. And know that there are lots of traps in reloading a module, as it can't really eliminate all traces of being already run once. It works for simple stuff, but you don't need it for simple stuff,... And I guess I'm repeating myself. DaveA From jeanmichel at sequans.com Mon Nov 2 10:02:43 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 Nov 2009 16:02:43 +0100 Subject: About one class/function per module In-Reply-To: <7l852dF3c5gi1U1@mid.uni-berlin.de> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> Message-ID: <4AEEF493.5010505@sequans.com> Diez B. Roggisch wrote: > Peng Yu wrote: > >> I can navigate to the definition of >> class and function by vim + ctags, >> > > Start learning a decent editor (emacs is mine) which allows you to deal > with all of your perceived "problems" > > Diez > This is a declaration of war against the vi community. We won't give up, prepare for vengeance ! By the way, why the hell would someone wants to limit itself to one function per file, file names would be probably related to the function name, that would make changing function name a nightmare, not mentiong the history issues when using version control systems. Definitely a bad idea. JM From lallous at lgwm.org Mon Nov 2 10:16:13 2009 From: lallous at lgwm.org (lallous) Date: Mon, 2 Nov 2009 16:16:13 +0100 Subject: C api and exception handling Message-ID: Hello, Is there is a way, using the Python C api, to install an exception handler that: - will be triggered when an exception occurs - analyze the reason of the exception - correct the situation and try again (something like exception handling on windows where the exception handler can retrieve the registers context->faulting instruction->fix situation if needed->restart execution from the same point) Since I will be asked: "what are you trying to achieve?", this is what I want: func_call("hello") <- no exceptions, good code: function is defined and called properly SomeUndefinedFunction("x", "y") <- undefined function call will trigger an exception. I want my python/C exception handler to inspect the reason of the exception, if it was a call to an undefined function call then redirect the execution to a certain method, say: ExecuteByName("SomeUndefinedFunction", "x", "y") I know if I create a small class with getattr hooked, what I want can be achieved. But can it be done otherwise (without using a class and instead relying on exception handlers and correcting the exception)? Regards, Elias From davea at ieee.org Mon Nov 2 10:21:46 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 10:21:46 -0500 Subject: Accessing a method from within its own code In-Reply-To: References: Message-ID: <4AEEF90A.8000608@ieee.org> Paddy O'Loughlin wrote: > Hi, > I was wondering if there was a shorthand way to get a reference to a method > object from within that method's code. > > Take this code snippet as an example: > import re > > class MyClass(object): > def find_line(self, lines): > if not hasattr(MyClass.do_work, "matcher"): > MyClass.do_work.matcher = re.compile("\d - (.+)") > for line in lines: > m = MyClass.do_work.matcher.match(line) > if m: > return m.groups() > > Here, I have a method which uses a regular expression object to find > matches. I want the regexp object to be tied to the function, but I don't > want to have to recreate it every time the function is called (I am aware > that regexp objects are cached, avoiding this problem, but I'm just using > this as an example for what I want to know), so I've added it to the method > object as an attribute and create it only if it doesn't exist. > > However, typing out .. everytime is > pretty long and susceptible to refactoring issues, so I was wondering if > there was a way in Python that I am missing which allows you to reference > the method that the code is in (like __module__ gives a reference to the > parent module). > > Paddy > > I suspect that the "inspection" module has your answer, but that it'll be bulkier, and much slower than just doing what you're doing already. Why not use the default arguments gimmick? Since this cached item is to have a module lifetime, it'd be desirable to create it when the method is being defined, which is exactly what default arguments do. Something like (untested): class ... def find_line(self, lines, _cacheitems = [] ) if not _cacheitems: _cacheitems.append( re.compile..... ) for ... m = _cacheitems[0]( line ) DaveA From kee at kagi.com Mon Nov 2 10:24:35 2009 From: kee at kagi.com (Kee Nethery) Date: Mon, 2 Nov 2009 07:24:35 -0800 Subject: Pyfora, a place for python In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> I just noticed the tag line "a place for Python". Looked it up online (http://pyfora.org/ ) and it will be interesting to see if it can fill the void that I experience (no centralized place to post and view user submitted sample code) in the existing Python community. As for user community fragmentation, I would guess that someone would be less likely to create such a site if the user community needs were being met by the official sites. There is a place for the existing old school interaction forums (the IRC channel, the Usenet groups and mailing lists), but there is also a place for archived user submitted comments. My personal preference would be a link in each sub-paragraph in the official documentation to a wiki page devoted to that specific aspect of the Python language. A place were users could augment the documentation by providing sample code and by expanding out the documentation for those of us who don't live and breath Python in our sleep. Real Python coders would not click on the user wiki links and all of us newbies could communicate with each other. But until a place like that exists, perhaps Pyfora will get us part way there. Kee From grflanagan at gmail.com Mon Nov 2 10:29:26 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 02 Nov 2009 15:29:26 +0000 Subject: Accessing a method from within its own code In-Reply-To: References: Message-ID: Paddy O'Loughlin wrote: > Hi, > I was wondering if there was a shorthand way to get a reference to a > method object from within that method's code. > > Take this code snippet as an example: > import re > > class MyClass(object): > def find_line(self, lines): > if not hasattr(MyClass.do_work, "matcher"): > MyClass.do_work.matcher = re.compile("\d - (.+)") > for line in lines: > m = MyClass.do_work.matcher.match(line) > if m: > return m.groups() > > Here, I have a method which uses a regular expression object to find > matches. I want the regexp object to be tied to the function, but I > don't want to have to recreate it every time the function is called Just an idea: ------------------------------ import re def matches(patt): def wrapper(fn): def inner(self, *args, **kw): return fn(self, *args, **kw) inner.match = re.compile(patt).match return inner return wrapper class MyClass(object): @matches('ab(.*)') def func(self): print 'hi' return 5 c = MyClass() ret = c.func() print ret print c.func.match('abc').groups() ------------------------------------ From deets at nospam.web.de Mon Nov 2 10:38:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 16:38:06 +0100 Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7l8cmuF3dlnh7U1@mid.uni-berlin.de> Kee Nethery wrote: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/ ) and it will be interesting to see if it can fill the > void that I experience (no centralized place to post and view user > submitted sample code) in the existing Python community. ASPN cookbook? And I don't think that a phpBB (or commercial rip-off) forum can be good at that - the search-function of these things sucks big time, and classification through tagging or hierarchical organization is also not possible. > My personal preference would be a link in each sub-paragraph in the > official documentation to a wiki page devoted to that specific aspect > of the Python language. A place were users could augment the > documentation by providing sample code and by expanding out the > documentation for those of us who don't live and breath Python in our > sleep. Real Python coders would not click on the user wiki links and > all of us newbies could communicate with each other. But until a place > like that exists, perhaps Pyfora will get us part way there. This idea has been discussed before, and unfortunately not bore any fruits so far - one of the few places PHP is actually better than Python. So I'd love to see it happen. However I totally fail to see how the pyfora are any step into that direction. Diez From kevinar18 at hotmail.com Mon Nov 2 10:41:18 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Mon, 2 Nov 2009 10:41:18 -0500 Subject: How do I install libxml2 and libxslt? Message-ID: I want to use the lxml library, but can't get it to work on Windows. The following will not work: * import libxml2 * import libxslt * from lxml import etree Here's the instructions: http://codespeak.net/lxml/installation.html * So, I run "easy_install lxml" -- that works! * Now, it says I need to install libxml2 and libxslt... how do I do that? ...so, I download the libxml2 and libxslt pre-built Windows binaries here: http://www.zlatkovic.com/pub/libxml/ Now what do I do with them? I opened the zip files and copied the bin directories to Python\Lib ... like this: Python\Lib\libxml2\libxml2.dll ... that doesn't work. I copy just dll to Python\DLLs ... that doesn't work. What now? _________________________________________________________________ Bing brings you maps, menus, and reviews organized in one place. http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Mon Nov 2 10:43:10 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 16:43:10 +0100 Subject: Pyfora, a place for python In-Reply-To: <7l89j4F3bl107U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: >>>> If you have any suggestions, let me know -- this is a community >>>> effort! >>> >>> Suggestion: Please don't make efforts to fragment the community. >> >> When a community grows and consequently its needs also grow, how do >> you differentiate "natural growth" from "fragmenting the community"? >> >> Same question in another way: let's suppose Tim Peters sent the exact >> email the OP sent with the exact same website. Would you have >> responded to him the same way? > > Most probably not - but then because Tim certainly would have discussed this > move with peers from the community, if there is a need for this kind of > forum or not. > > Being from germany, I can say that we *have* this fragmentation, and > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > with those visually rather noisy and IMHO suboptimal forums. If you prefer NNTP/ML, I'd suggest you pay attention to these channels only. BTW, I prefer ML also and I'm very happy with c.l.p. However that doesn't mean that I need to be hostile to other forms of communication and it doesn't mean that I need to discourage people from setting up other channels of communication for those folks who prefer them. If new channels open up for others it will not make c.l.p any worse. If enough people like c.l.p. it will continue to be a good channel, if too many too good people switch to an online forum, well, in that case c.l.p. will cease to be great, but it won't be because of artificial fragmentation by somebody but because the people started to prefer online forums (words like "free market" come to mind :)) I generally not register on any online forum and will most probably not register on pyfora either. But I know for a fact that many people prefer forums over ML and why shouldn't those people be happy with the communication platform they like and why shouldn't they be given a chance to join the python community if the only reason they stayed away was that they didn't like c.l.p. for one reason or another? > E.g. it > requires much more effort to get to know what new discussions arose, as > well as following ongoing ones - because the interface lacks a > comprehensive overview of that, and features like "jump to next unread > article". These are perfectly legitimate reasons for you to not use online forums and stick to c.l.p. I do the same thing. But again, if an enthusiastic python community member wants to open new channels for those folks who like them, why should anyone be hostile to him/her? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mwilson at the-wire.com Mon Nov 2 10:46:48 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 02 Nov 2009 10:46:48 -0500 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >>> * Peter Otten: >>>> unidiomatic None-checks >>> What's the idiomatic Python way for an optional thing? >> >> if some_value is None: ... > > Thanks! > > But why is this preferred? I guess because `some_value == None` restricts your choices if you want to give some_value's usual class an __eq__ method. It's a pretty arcane point.. but perhaps not.. the object named "some_value" might belong to a class that expects its instances only to be compared with each other, for the sake of economy and clear code. Mel. From alfps at start.no Mon Nov 2 10:51:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 16:51:36 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l881tF3dbb00U1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: >> Your comment about "computed" makes it more clear what that's all about. >> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >> called it "referential transparency". But I think when Python has this >> nice property mechanism, why do people change direct data attributes into >> properties and not the other way around or not at all, I mean using only >> properties for logical >> data attributes -- e.g. assuring correctness first via read-only >> property? > > I fail to see where read-only-ness of an attribute is a priori more correct > than having modifyable attributes. No, I didn't mean that it is more correct to have an attribute as read-only. I meant that letting a logical data attribute start out as a read only property can help to ensure correctness. For example, consider two rectangle classes R1 and R2, where R2 might be a successor to R1, at some point in system evolution replacing R1. R1 has logical data members left, top, width and height, and R2 has logical data members left, top, right and bottom. With R1 direct changes of left and top keeps the rectangle's size (since that size is specified by width and height), while with R2 it changes the rectangle's size. R1 is implemented with logical data members as directly exposed data attributes. Some code in the system deals only with R1 objects and for convenience or efficiency or whatever uses direct modification instead of set_position method. Due to new requirements it instead has to deal with R2 objects, with same methods. But due to the direct modification of object state it now changes the rectangle sizes, but at first it's not noticed since the attempted rectangle position changes are very small. People get upset. The bug is fixed. Time has been wasted. > Again, it's an assumption of a future > use or constraint that is most of the times simply not correct or > relevant - at the price for more typing, and computational overhead. Hm, not sure. Cheers, - Alf From patrick.oloughlin at gmail.com Mon Nov 2 10:59:02 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Mon, 2 Nov 2009 15:59:02 +0000 Subject: Accessing a method from within its own code In-Reply-To: <4AEEF90A.8000608@ieee.org> References: <4AEEF90A.8000608@ieee.org> Message-ID: > > I suspect that the "inspection" module has your answer, but that it'll be > bulkier, and much slower than just doing what you're doing already. > Hmm. Yeah, it does appear to be bulky. I don't think it's really any more use than what I'm doing already. Why not use the default arguments gimmick? Since this cached item is to > have a module lifetime, it'd be desirable to create it when the method is > being defined, which is exactly what default arguments do. > I've a few different ways of emulating static function variables from C/Java and the function/method attribute one is easily the one that appeals most to my sensibilities. I find the default arguments gimmick to be a gimmick. It's co-opting a piece of functionality for something it doesn't seem like it was originally intended for and as a consequence is less readable (to my eyes). The only problem with the function/method way is that it gets rather verbose when you are dealing with a user-defined method and have to give the class name and method name and it's also a bit of a pain for moving code around when refactoring. You ever wish there was more to python scoping than just locals(), globals() and __builtins__? Like a method's class's scope too? That's where I am at with this. -- "Ray, when someone asks you if you're a god, you say YES!" -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Nov 2 11:19:51 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 02 Nov 2009 11:19:51 -0500 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: Alf P. Steinbach wrote: > Your comment about "computed" makes it more clear what that's all about. > Also Bertrand Meyer (Eiffel language creator) had idea like that, he > called it "referential transparency". But I think when Python has this > nice property mechanism, why do people change direct data attributes into > properties and not the other way around or not at all, Python tends to prefer simple forms over complicated forms, so having a programmer write x = something.that and implementing a getter inside the call to something.__getattr__ is better than x = something.that() with a pair of needless parens, and then mangling the compiler/runtime to suddenly use the value of `that`, uncalled, if `something` happens to be an instance of the class we're discussing. Note too that something.that = x is pretty clean, but something.that() = x can't be done at all, and the syntactically correct something.that(x) just doesn't look like the simple assignment statement. Mel. From duncan.booth at invalid.invalid Mon Nov 2 11:22:08 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Nov 2009 16:22:08 GMT Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <7l8cmuF3dlnh7U1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" wrote: > Kee Nethery wrote: >> My personal preference would be a link in each sub-paragraph in the >> official documentation to a wiki page devoted to that specific aspect >> of the Python language. A place were users could augment the >> documentation by providing sample code and by expanding out the >> documentation for those of us who don't live and breath Python in our >> sleep. Real Python coders would not click on the user wiki links and >> all of us newbies could communicate with each other. But until a >> place like that exists, perhaps Pyfora will get us part way there. > > This idea has been discussed before, and unfortunately not bore any > fruits so far - one of the few places PHP is actually better than > Python. So I'd love to see it happen. One option would be to use Google sidewiki. That way we need no changes to the existing site and people can add comments on pages or individual paragraphs, phrases or words. It's up and running today. However, so far as I know there isn't any easy way to find all sidewiki comments for a site: the APIs only allow you to retrieve comments for an individual page. (There's a sidewiki issue for this http://code.google.com/p/gdata-issues/issues/detail?id=1493 ) If they address this issue then the site could include a ticker of recent comments. Also of course some people may have objections to using sidewiki e.g. on privacy grounds. -- Duncan Booth http://kupuguy.blogspot.com From bigboss1964 at gmail.com Mon Nov 2 11:22:37 2009 From: bigboss1964 at gmail.com (TerryP) Date: Mon, 2 Nov 2009 08:22:37 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: On Nov 2, 2:27?pm, Collin D wrote: > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. > > Thanks a lot, > Collin D I'm not aware of any module designed for parsing arbitrary text in that way, although it may be possible to subvert something to the task. If you are following the usual IRC client behavioural pattern, then just suck up the line - then see if the first non-whitespace character is a '/', then react accordingly. Simple. From rsheftel at gmail.com Mon Nov 2 11:42:41 2009 From: rsheftel at gmail.com (Ryan) Date: Mon, 2 Nov 2009 08:42:41 -0800 (PST) Subject: Migrating from R to Python Message-ID: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> I am a long time user of "R" for statistical analysis and find it an extremely useful environment for data exploration. That said I may be adding and/or moving to Python for more of my work and wanted to know if people had any recommendations. My work is primarily financial time series analysis. In R this means extensive use of "zoo" and "xts". I see from searching that there is a time-series package for Python called pytseries (http:// pytseries.sourceforge.net/) that looks closest to adding the time series capabilities to Python. My question is to people who have used zoo and xts in R, what has their experience been with Python? Would you recommend using native Python to do time series analysis, or rPy to link back to R for analysis? Thanks. From aaron.watters at gmail.com Mon Nov 2 11:57:08 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Mon, 2 Nov 2009 08:57:08 -0800 (PST) Subject: graceful degradation : is it degrading? Message-ID: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Graceful degradation is what I hope to display as I continue to age... But in the context of web programming it also refers to the supposedly desirable behaviour of web sites to "do something reasonable" as resources are denied them by client browsers such as cookies, applets, javascript, etcetera. So for example if the browser has javascript turned off pages should somehow "still work". These days javascript is so pervasive that graceful degradation is becoming increasingly difficult and absolutely no fun for web designers and programmers. Question: is graceful degradation for no-javascript feasible and desirable these days? For example after I announced my WHIFF treeview widgets http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2200.TreeView people noted that they sometimes didn't work properly with javascript off. I could fix this in some cases, but the fix would involve changing a "POST" to a "GET" and that would cause MSIE to suddenly fail when the GET parameters get too big (and probably other browsers too). So it really would only fix part of the problem. Consequently I'm tempted to say: "sorry, please enable javascript if you want to use this page..." What is the state of best-practices and such? -- Aaron Watters === she was dirty, flirty / musta been about thirty... Stones '60s she was shifty, nifty / musta been about fifty... Stones '90s (what rhymes with 80?) From davea at ieee.org Mon Nov 2 11:57:35 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 11:57:35 -0500 Subject: Accessing a method from within its own code In-Reply-To: References: <4AEEF90A.8000608@ieee.org> Message-ID: <4AEF0F7F.8080008@ieee.org> Paddy O'Loughlin wrote: >> I suspect that the "inspection" module has your answer, but that it'll be >> bulkier, and much slower than just doing what you're doing already. >> >> > Hmm. > Yeah, it does appear to be bulky. I don't think it's really any more use > than what I'm doing already. > > > Why not use the default arguments gimmick? Since this cached item is to > >> have a module lifetime, it'd be desirable to create it when the method is >> being defined, which is exactly what default arguments do. >> >> > > I've a few different ways of emulating static function variables from C/Java > and the function/method attribute one is easily the one that appeals most to > my sensibilities. > I find the default arguments gimmick to be a gimmick. It's co-opting a piece > of functionality for something it doesn't seem like it was originally > intended for and as a consequence is less readable (to my eyes). > The only problem with the function/method way is that it gets rather verbose > when you are dealing with a user-defined method and have to give the class > name and method name and it's also a bit of a pain for moving code around > when refactoring. > > You ever wish there was more to python scoping than just locals(), globals() > and __builtins__? Like a method's class's scope too? > That's where I am at with this. > > > Back to your original approach - if you don't bind a new value to a class variable, it's okay to just reference it with self, rather than needing cls. But if you forget, and bind a new value, then you'll end up with an instance attribute instead of reusing the class attribute. How about (untested): class ... cacheitems = [] def find_line(self, lines): if not self.cacheitems: self.cacheitems.append( re.compile..... ) for ... m = self.cacheitems[0]( line ) Just don't put self.cacheitems= xyzzy inside a method. Incidentally, if your cacheitems is an instance of a dummy class (with pass as a body), you could use named parameters instead of subscript. But then you're back to the three nodes you already thought was too verbose. All you've gained is the relative ease of refactoring. DaveA From pavlovevidence at gmail.com Mon Nov 2 12:01:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 09:01:44 -0800 (PST) Subject: C api and exception handling References: Message-ID: On Nov 2, 7:16?am, "lallous" wrote: > Hello, > > Is there is a way, using the Python C api, to install an exception handler > that: > - will be triggered when an exception occurs > - analyze the reason of the exception > - correct the situation and try again (something like exception handling on > windows where the exception handler can retrieve the registers > context->faulting instruction->fix situation if needed->restart execution > from the same point) Python has no concept of "retrying", at either the Python or C API level. You might be able to do something Evil in C to get this effect but I don't recommend it, it'll be fundamentally averse to how Python works and future versions are likely to break it. > Since I will be asked: "what are you trying to achieve?", this is what I > want: > > func_call("hello") <- no exceptions, good code: function is defined and > called properly > SomeUndefinedFunction("x", "y") <- undefined function call will trigger an > exception. I want my python/C exception handler to inspect the reason of the > exception, if it was a call to an undefined function call then redirect the > execution to a certain method, say: ExecuteByName("SomeUndefinedFunction", > "x", "y") > > I know if I create a small class with getattr hooked, what I want can be > achieved. I'd do it that way. There is ordinarily no way to hook into a plain function call like SomeUndefinedFunction() in Python; if you go around hacking up the interpreter to do that users will be highly confused and surprised. OTOH, hooking into attributes is pretty well-known. When a person sees attribute notation they know there's an opportunity to do weird stuff. When a strange function is called, they will be like, "oh, someone overrode __getattr__". > But can it be done otherwise (without using a class and instead relying on > exception handlers and correcting the exception)? Just forget about exception handling. If you REALLY insist on doing this, and I highly recommend against it, the best chance you have is to try to hook into the importing process and load a module that uses a custom dictionary object. Carl Banks From ishwor.gurung at gmail.com Mon Nov 2 12:02:26 2009 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Tue, 3 Nov 2009 04:02:26 +1100 Subject: Migrating from R to Python In-Reply-To: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> References: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> Message-ID: <34534aed0911020902paba078cp296f2a687bb39ee5@mail.gmail.com> Hi, 2009/11/3 Ryan : > I am a long time user of "R" for statistical analysis and find it an [...] > My question is to people who have used zoo and xts in R, what has > their experience been with Python? Would you recommend using native > Python to do time series analysis, or rPy to link back to R for > analysis? Although I haven't used 'zoo' nor 'xts' in R I use Rpy/Rpy2 because it seems to expose almost all(iirc) the necessary R space within Python space. So, if I need features in R - for e.g., importing modules - library('foo'), I can still have it in Python via the Rpy/Rpy2 bridge. On the other hand with pytseries Python library, I'd be limited to only run time-series analysis wouldn't I? In the end though, it all depends on your project requirements, resources and so forth.. -- Regards, Ishwor Gurung From __peter__ at web.de Mon Nov 2 12:09:47 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 18:09:47 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>> * Peter Otten: >>>> Alf P. Steinbach wrote: >>>> >>>>>> for x in range(0,3): >>>>>> Button(......, command=lambda x=x: function(x)) >>>>> An alternative reusable alternative is to create a button-with-id >>>>> class. >>>>> >>>>> This is my very first Python class so I'm guessing that there are all >>>>> sorts of issues, in particular naming conventions. >>>> Pseudo-private attributes >>> That means there is some way of making attributes private? >> >> No, there isn't. And the name mangled __attribute is hardly ever needed. >> Use _attribute to convey the message "If you mess with this attribute >> you're on your own". > > Thanks! > > >>> Probably that comes across as an inane question but I ask it anyway. I >>> haven't really started to look at Python classes. I'm guessing that by >>> asking here I may learn things that are not obvious from the >>> documentation. >>> >>> >>>> , javaesque getter methods, >>> What do you mean by that? >> >> In Java you have a private attribute and a public getter method. In >> Python you can just make the attribute public, i. e. >> >> # bad >> class A: >> def __init__(self): >> self._id = 42 >> def id(self): return self._id >> >> # good >> class A: >> def __init__(self): >> self.id = 42 > > I think I get the gist that locally saving lines of code, and generally > avoiding having to write empty argument list parentheses, and thereby also > indicating in a way that one is accessing a logical data attribute, is > considered good in Python, which goes to initial development time and the > amount of code that one > must scan to grok it both for definition and usage -- is that correct? Remember that .id does contain static data in your case. If it were a lengthy calculation the .id() method would be OK. > But the trade-off is inviting modification of a supposedly fixed id, which > goes to correctness and later fix-it time? > > >> You can always switch to >> >> class A: # assuming 3.x >> @property >> def id(self): >> id = arbitrary_code() >> return id >> >> later. > > Thanks, now I learned about @property... :-) > > But when the thing has been used it's much more difficult to restrict the > functionality (making read-only, breaking code that changes id) than to > add functionality (making also writeable, breaking none of existing code). > > So isn't "later" a bit late to make it read-only, shouldn't that be the > initial design, and then possibly adding a setter later if id's turn out > to not be so constant after all? You can break existing code with changes in a library in so many ways that I don't think this specific problem matters much. But if you don't feel comfortable with writing a warning into the documentation use a getter function or a property. >>> What I associate with Java getter method is mainly the "get" prefix, for >>> Java introspection. >>> >>> >>>> unidiomatic None-checks >>> What's the idiomatic Python way for an optional thing? >> >> if some_value is None: ... > > Thanks! > > But why is this preferred? > > >>> In this case one alternative I see could be to get rid of the >>> __on_tc_command method and more directly tell tkinter.Button to call the >>> relevant function, doing the if-else choice once only in the IdButton >>> constructor. >>> >>> Is that what you mean? >>> >>> I'm thinking more in terms of customization points when I write code. >>> >>> So I tend to avoid hardcoding things internally in methods, instead >>> designing the choices out to where they're accessible to client code. >>> >>> >>>> , broken naming conventions (**args), >>> How to do this argument forwarding in modern style? >> >> I meant that keyword args are traditionally named kw or kwargs, the name >> "args" is normally used for positional arguments: >> >> def f(*args, **kw): >> "whatever" > > Thanks! > > *Note to myself*: check if there are more such conventions. > > >>> Or is there an alternative to argument forwarding for this example? >>> >>> >>>> spaces in funny places... >>> Bah. ;-) >>> >>> >>>>> And the idea of creating a reusable solution for such a small issue >>>>> may be un-pythonic? >>>> Screw pythonic, the signal/noise ratio is awful in any language. >>>> >>>>> But just as an example, in Python 3.x, >>>> ...for achieving less in more lines? >>> Now, that's a good Python-independent question! :-) >>> >>> Re your question's the number of lines: /if/ the code is heavily reused >>> then the number of lines doesn't matter since they're only written >>> /once/; >> >> Every time someone has to read the code he will read, hesitate, read >> again, and then hopefully come to the conclusion that the code does >> nothing, consider not using it, or if it is not tied into a larger >> project removing it. > > I don't understand what you mean. Writing code is not fire and forget. It has to be debugged, tested, maintained, and will be read quite a few times in the process. Therefore it is important that you make it easy to read and understand. > Not that it's a shiny example of code that does a lot, but it (1) > simplifies and shortens creation of buttons with id, and (2) provides a > nice start for adding other customizations of those buttons, and (3) > supports searching for a button with given command id, e.g. for purpose of > hiding or enable/disable. > > If I didn't just want to try out writing a Python class, which I've never > done before so it appeared interesting, I'd probably just skipped points 2 > and 3 and written the same functionality as a factory function, like > > > > import tkinter > > def id_button( owner_widget, id, command = None, **kwargs ): > def tk_command( an_id = id, a_command = command ): > if a_command is not None: a_command( id ) > return tkinter.Button( owner_widget, kwargs, command = tk_command ) > > def on_button_click( id ): > print( "Button " + str( id ) + " clicked!" ) > > window = tkinter.Tk() > > n_buttons = 3 > for x in range( 1, n_buttons + 1 ): > id_button( > window, id = x, text = "Button " + str( x ), command = > on_button_click ).pack() > > window.mainloop() > I prefer that one, though without extra spaces in funny places. > but once you have the class, for whatever reason, it would be silly not to > use it, especially since it provides points 2 and 3 which the function > doesn't. > > By the way, I as yet know next to *nothing* about binding of variable > references within a function such as tk_command above. Probably I've done > Unnecessary Things(TM) above? Nothing too obvious; you could avoid the noop tk_command, and maybe provide the button instead of the id (all code untested): def make_button(owner, id, command=None, **kwargs): button = tkinter.Button(owner, kwargs) button.id = id if command is not None: button["command"] = functools.partial(command, button) button.pack() def button_click(button): print(button["text"], "clicked!") >>> the net effect can even be to reduce the total number of lines, or at >>> least the number of apparent function points (or whatever size metric). >>> That's part of what "reusable" means. For example, if the OP used the >>> code then he or she didn't type them lines, but just copy/paste'd them, >>> less work than typing in a lambda definition in every button creation, >>> and more clear code at every creation. >> >> But most of your code does *nothing*. > > See above, points 2 and 3. Most of that class has to do with 2, > customization ability. Couldn't class IdButton(tkinter.Button): def __init__(self, id, **kw): self.id = id tkinter.Button.__init__(self, **kw) be customised as easily? >>> Re your question's what (the) reusability achieves. >>> >>> First, when you and others have used such a thing in a number of places >>> then you gain confidence in correctness. For example, you don't wonder >>> whether Python's str type is correct, and when you test your program you >>> don't test the str type implementation. Since it's been used so much you >>> know that it (mainly) is correct, and that any remaining bug in there >>> can't be all that serious, because if it was then it would've surfaced >>> in earlier use of the type. >> >> The theory may be OK, but in practice it doesn't always work out. >> Example: Why do you introduce button.id_string() instead of >> str(button.id)? > > Because the string representation of an id then /can/ be customized > independently of the id. For example, id's might be integers but for > string representation you might want symbolic action names (e.g., you > might have two or more buttons with same title but different actions, so > that title would be ungood to identify button). And for another example, > when debugging or testing you might want the string represention of an id > to provide more information about the button and/or its context, and then > id_string provides a single > central customization point -- provided it's used, of course. And what about the IdEntry class? To me it would make more sense to customize the type of the .id value. >> The >> programmer will hesitate, wonder whether to use button.id() or >> button.id_string(), how the two may interconnect... > > Hm, see immediately above. > > It's perhaps a different way of thinking? > > >> It feels more like a hoop to jump through than a helpful service >> providing tried an tested code. > > Yes. > > It's the old "every computer science problem can be solved by adding an > extra layer of indirection". > > Sometimes it's nice when you can do that centrally. Retrofitting the > indirection to existing client code can be hard. Again, just-in-case indirections come at a cost. You are probably right about the way of thinking. >>> This advantage of confidence in correctness can be realized even without >>> heavy reuse, because the encapsulation that's necessary for reuse, here >>> having the code in a class, also makes it possible with more centralized >>> testing. >> >> Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ >> ? > > No. :-) But you're right that testing isn't that much of an issue for > that class. If that's what you meant. I read it twice but didn't understand it. You probably misplaced a word, but I can't figure out which one. >>> A centralized, encapsulated piece of code can be tested to death and >>> deemed correct (enough) and frozen, while the application of a code >>> pattern in umpteen places in umpteen programs, generally can't. >> >> I'd like to see a good test suite for your IdButton class, especially how >> it copes with the design decision that you can override the on_clicked() >> stub, or provide a command function, or both. > > The design is that for any given IdButton there's a single point of > responsibility for the click action, namely either a button creation code > supplies that action, or it relies on the action defined in the class. > > I.e. again customization ability, that the button creation code can > /override/ the class provided action, per button, without getting into > general overriding of class methods, just by defining a nice little lambda > inline in the call. > > But as I learn more Python I may perhaps find that overriding class > methods can > also be done that conveniently -- I don't know, keep in mind I'm a > Python newbie, and doing Very Much Else than studying Python. :-) > > >>> Second, when you do find a bug, or need more functionality, or whatever, >>> there's just /one place/ to fix/extend, whatever, instead of updating >>> umpteen places in umpteen programs, and trying to be sure that you've >>> covered all instances and done the right thing every place regardless of >>> local variations (which is pretty hopeless in general, but my experience >>> with that kind of badness has mostly been with C, not Python). More >>> technically, it's reduced redundancy, in this case avoiding redundant >>> application of a code pattern everywhere one needs a button with id (if >>> that happens often). Reduced redundancy = good. >> >> I agree with that maxim. Incidentally I have just found a nice example of >> redundancy for you: >> >>>>> def __on_tk_command( self ): >>>>> if self.__specified_command != None: >>>>> self.__specified_command( self ) >>>>> else: >>>>> self.on_clicked() >> > > Uh, could you expand on how that's redundant and how to make it less so? How about class IdButton(tkinter.Button): def __init__(self, owner, id, command=None, **kwargs): tkinter.Button.__init__( self, owner, kwargs, command=self.on_clicked) self.id = id self.specified_command = command def on_clicked(self): if self.specified_command is not None: self.specified_command(self) Peter From chris at simplistix.co.uk Mon Nov 2 12:12:12 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 02 Nov 2009 17:12:12 +0000 Subject: graceful degradation : is it degrading? In-Reply-To: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> References: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Message-ID: <4AEF12EC.1090401@simplistix.co.uk> Aaron Watters wrote: > These days javascript is so > pervasive that graceful degradation is becoming > increasingly difficult and absolutely no fun for > web designers and programmers. This sounds like something I'd ask about on #web on irc.freenode.net... Those guys are pretty knowledgeable, would be interesting to know what they have to say on all this... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From http Mon Nov 2 12:39:54 2009 From: http (Paul Rubin) Date: 02 Nov 2009 09:39:54 -0800 Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7xeiogomfp.fsf@ruckus.brouhaha.com> Kee Nethery writes: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/ ) and it will be interesting to see if it can fill > the void that I experience (no centralized place to post and view > user submitted sample code) in the existing Python community. Something wrong with pastebin.com or any of its lookalikes? From nat.williams at gmail.com Mon Nov 2 13:06:09 2009 From: nat.williams at gmail.com (Nat Williams) Date: Mon, 2 Nov 2009 12:06:09 -0600 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: On Mon, Nov 2, 2009 at 9:41 AM, Kevin Ar18 wrote: > I want to use the lxml library, but can't get it to work on Windows. > > The following will not work: > * import libxml2 > * import libxslt > * from lxml import etree > > Here's the instructions: > http://codespeak.net/lxml/installation.html > > * So, I run "easy_install lxml" -- that works! > * Now, it says I need to install libxml2 and libxslt... how do I do that? > ...so, I download the libxml2 and libxslt pre-built Windows binaries here: > http://www.zlatkovic.com/pub/libxml/ > Now what do I do with them? > I opened the zip files and copied the bin directories to Python\Lib ... > like this: Python\Lib\libxml2\libxml2.dll ... that doesn't work. I copy just > dll to Python\DLLs ... that doesn't work. > > What now? > According to the lxml installation instructions you linked, the windows lxml binary is statically linked and you do not need to install the libraries separately. If 'from lxml import etree' works, then you're done. libxml2 and libxslt are C libraries, not things that you can or would import. The joy of lxml is not having to deal with those libraries on your own. Nat -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Mon Nov 2 13:21:34 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 2 Nov 2009 10:21:34 -0800 Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: "Collin D" wrote in message news:94dbc92b-0682-4995-b358-0c615c95a27a at x6g2000prc.googlegroups.com... > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. Check out the pyparsing module. Here is a presentation given by the author for parsing an interactive game. http://us.pycon.org/zope/talks/2006/fri/track1/04/index.html -Mark From animator333 at gmail.com Mon Nov 2 14:40:25 2009 From: animator333 at gmail.com (King) Date: Mon, 2 Nov 2009 11:40:25 -0800 (PST) Subject: conditional __init__ Message-ID: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> class A(object): def __init__(self): pass def printme(self): print "I am A" class B(object): def __init__(self): pass def printme(self): print "I am B" class K(A, B): def __init__(self, value=0): if value == 0: A.__init__(self) print "__init__ A" elif value == 1: B.__init__(self) print "__init__ B" self.printme() o = K(value=1) Output >>__init__ B >>I am A In above code "B" is correctly getting initialized as per condition. How ever method "printme" is printing "I am A". Instead it has to print "I am B" because "B" is the one that has been initialized. What's wrong here? Is there a better/another way to do conditional initialization as needed above? Cheers Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Mon Nov 2 15:00:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 13:00:15 -0700 Subject: conditional __init__ In-Reply-To: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: <50697b2c0911021200j368ab384q27e36012dff4fbfe@mail.gmail.com> On Mon, Nov 2, 2009 at 12:40 PM, King wrote: > class A(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def printme(self): > ? ? ? ?print "I am A" > > class B(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def printme(self): > ? ? ? ?print "I am B" > > class K(A, B): > ? ?def __init__(self, value=0): > ? ? ? ?if value == 0: > ? ? ? ? ? ?A.__init__(self) > ? ? ? ? ? ?print "__init__ A" > ? ? ? ?elif value == 1: > ? ? ? ? ? ?B.__init__(self) > ? ? ? ? ? ?print "__init__ B" > ? ? ? ?self.printme() > > o = K(value=1) > > Output >>>__init__ B >>>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? > > Is there a better/another way to do conditional initialization as > needed above? Which initializers are called *has no effect* on what order base classes are consulted in when looking up methods. To change the lookup order, you need to change the order of the base classes in the class statement. Your problem could be fixed by: 1. Changing the code so the initializers do have an effect through what they initialize instance variables to; class A(object): def __init__(self): self.name = "A" def printme(self): print "I am", self.name class B(object): def __init__(self): self.name = "B" def printme(self): print "I am", self.name 2. Use a factory function to return an instance of the proper class: class K1(A, B): pass class K2(B, A): pass def newK(value): if value == 0: return K1() elif value == 1: return K2() Cheers, Chris -- http://blog.rebertia.com From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Nov 2 15:02:07 2009 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Mon, 2 Nov 2009 20:02:07 +0000 (UTC) Subject: conditional __init__ References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: King wrote: > class A(object): > def __init__(self): > pass > def printme(self): > print "I am A" > > class B(object): > def __init__(self): > pass > def printme(self): > print "I am B" > > class K(A, B): > def __init__(self, value=0): > if value == 0: > A.__init__(self) > print "__init__ A" > elif value == 1: > B.__init__(self) > print "__init__ B" > self.printme() > > o = K(value=1) > > Output >>>__init__ B >>>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? It prints "I am A" because K inherits from A before B. Your __init__ methods don't do anything, so it doesn't matter which one you call. You seem to be thinking that running __init__ magically determines the class of the object, but it doesn't; it's just code that runs when the object is first created. When you do self.printme(), it decides to use A.printme because you did "class K(A, B)". If you do class K(B, A)" it will use B.printme. I imagine it's possible to do fiendish things and try to choose the superclass inheritance order at runtime, but you should be wary of this. In your example, why don't you just have K override printme and dispatch to A or B depending on "value"? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From azhilprashanth87 at gmail.com Mon Nov 2 15:37:44 2009 From: azhilprashanth87 at gmail.com (pranesh) Date: Mon, 2 Nov 2009 12:37:44 -0800 (PST) Subject: Hi help me in installing pcapy extension module Message-ID: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> dear friends, I have python 2.6.4 i my Windows XP machine. I am trying to install pcapy - python extension module ( I am using http://oss.coresecurity.com/projects/pcapy.html for reference ) I decided to implement the libpcap library... Since I have only windows xp machine...... I installed WinPcap - this is a port of libpcap - windows uses this WinPcap As the pcapy extension is written in C++ it needs to be compiled for the host system before it can be accessed from Python. In order to compile and install the source, I executed python setup.py install from the directory where Pcapy's distribution has been unpacked. Now, I am getting the following error, C:\pcapy-0.10.4>python setup.py install running install running build running build_ext building 'pcapy' extension error: Unable to find vcvarsall.bat I request you to help me in solving this problem. regards Prashanth From ldo at geek-central.gen.new_zealand Mon Nov 2 15:41:10 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 09:41:10 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> Says someone who hasn't realized where the real inefficiencies are. >> Remember what Tony Hoare told us: "premature optimization is the root of >> all evil". These are databases we're talking about. Real-world databases >> are large, and reside on disk, which is several orders of magnitude >> slower than RAM. And RAM is where string parameter substitutions take >> place. So a few hundred extra RAM accesses isn't going to make any >> significant difference to the speed of database queries. > > You're just not getting it. The cost is not in performing the parameter > substitutions themselves. The cost is in parsing what's essentially the > same query one million times over when it could have been parsed only > once. You might find an increase of seven orders of magnitude > insignificant, but I don't. There is no such parsing overhead. I speak from experience. Look at the BulkInserter class here . I have successfully used that to insert tens of thousands of records in just a few seconds. Yet it makes no use of the parameter-substitution provided by MySQLdb; it is all just straight Python, including the SQLString routine (also on that page), which goes through every single character of each string value to decide what needs escaping. Python can do all that, and do it fast. You don't get to figure out what's efficient and what's not by mere hand- waving; you have to do actual real-world tests. From deets at nospam.web.de Mon Nov 2 15:44:35 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 21:44:35 +0100 Subject: Hi help me in installing pcapy extension module In-Reply-To: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> References: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> Message-ID: <7l8uljF3cjk5lU1@mid.uni-berlin.de> pranesh schrieb: > dear friends, > > I have python 2.6.4 i my Windows XP machine. > I am trying to install pcapy - python extension module > ( I am using http://oss.coresecurity.com/projects/pcapy.html for > reference ) > > I decided to implement the libpcap library... > Since I have only windows xp machine...... > I installed WinPcap - this is a port of libpcap - windows uses this > WinPcap > > As the pcapy extension is written in C++ it needs to be compiled for > the host system before it can be accessed from Python. > In order to compile and install the source, I executed > python setup.py install > from the directory where Pcapy's distribution has been unpacked. > > Now, I am getting the following error, > > C:\pcapy-0.10.4>python setup.py install > running install > running build > running build_ext > building 'pcapy' extension > error: Unable to find vcvarsall.bat This looks to my as if you are missing Visual C++, or at least it's not properly set up. > I request you to help me in solving this problem. I'm not a native-speaker - and I guess you aren't either. But "I request you to help me" is rather rude, as well as your subject. "I kindly ask you to help me" would be better I'd say. Diez From kevinar18 at hotmail.com Mon Nov 2 15:44:36 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Mon, 2 Nov 2009 15:44:36 -0500 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 > According to the lxml installation instructions you linked=2C > the windows lxml binary is statically linked and you do not > need to install the libraries separately. The install instructions say" "You need libxml2 and libxslt" and then links= to where to download the binaries=3B this means I need to install separate= ly=2C right? If not=2C those are aweful instructions. :) I can download the binaries=2C but I don't know where or how to install the= m? Is there any instructions anywhere? =20 > If 'from lxml import etree' works=2C then you're done. It doesn't work. =20 _________________________________________________________________ New Windows 7: Find the right PC for you. http://www.microsoft.com/windows/pc-scout/default.aspx?CBID=3Dwl&ocid=3DPID= 24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_pcscout:112009= From ldo at geek-central.gen.new_zealand Mon Nov 2 15:47:08 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 09:47:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Sun, 01 Nov 2009 19:08 +1300, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> On the grounds that Python has more general and powerful string >> parameter- substitution mechanisms than anything built into any database >> API. > > Really? In the case of MySQLdb, the DB-API /uses/ Pythons string > interpolation ... Only a limited subset thereof. For instance, I'm not aware of any database API that lets me do this: sql.cursor.execute \ ( "update numbers set flags = flags | %(setflags)u where projectid = %(projectid)s" "%(match_listid)s and number = %(number)s" % { "projectid" : SQLString(ProjectID), "match_listid" : ("", " and listid = %s" % SQLString(ListID))[ListID != None], "number" : SQLString(number), "setflags" : flags, } ) From aahz at pythoncraft.com Mon Nov 2 16:11:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 13:11:28 -0800 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: In article <7589e0a1-98b2-4df4-bc76-5d4c10194fde at f20g2000prn.googlegroups.com>, Falcolas wrote: > >I'd also recommend trying the following filter, since it is identical >to what you're trying to do, and will probably catch some additional >edge cases without any additional effort from you. > >[s.strip() for s in hosts if s.strip()] This breaks if s might be None -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Mon Nov 2 16:21:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 13:21:58 -0800 Subject: Recommended number of threads? (in CPython) References: Message-ID: In article , mk wrote: > >I wrote run-of-the-mill program for concurrent execution of ssh command >over a large number of hosts. (someone may ask why reinvent the wheel >when there's pssh and shmux around -- I'm not happy with working details >and lack of some options in either program) > >The program has a working queue of threads so that no more than >maxthreads number are created and working at particular time. > >But this begs the question: what is the recommended number of threads >working concurrently? If it's dependent on task, the task is: open ssh >connection, execute command (then the main thread loops over the queue >and if the thread is finished, it closes ssh connection and does .join() >on the thread) Given that you code is not just I/O-bound but wait-bound, I suggest following the suggestion to use asynch code -- then you could open a connection to every single machine simultaneously. Assuming your system setup can handle the load, that is. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From robert.kern at gmail.com Mon Nov 2 16:35:54 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Nov 2009 15:35:54 -0600 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: On 2009-11-02 14:47 PM, Lawrence D'Oliveiro wrote: > In message, Dennis Lee Bieber wrote: > >> On Sun, 01 Nov 2009 19:08 +1300, Lawrence D'Oliveiro >> declaimed the following in >> gmane.comp.python.general: >> >>> On the grounds that Python has more general and powerful string >>> parameter- substitution mechanisms than anything built into any database >>> API. >> >> Really? In the case of MySQLdb, the DB-API /uses/ Pythons string >> interpolation ... > > Only a limited subset thereof. For instance, I'm not aware of any database > API that lets me do this: > > sql.cursor.execute \ > ( > "update numbers set flags = flags | %(setflags)u where projectid = %(projectid)s" > "%(match_listid)s and number = %(number)s" > % > { > "projectid" : SQLString(ProjectID), > "match_listid" : > ("", " and listid = %s" % SQLString(ListID))[ListID != None], > "number" : SQLString(number), > "setflags" : flags, > } > ) When programmatically generating SQL, I like to use SQLAlchemy. This use case is handled with .where() on Update expression objects. Personally, I find manipulating the SQLAlchemy expression objects clearer, safer, and more portable than building the raw SQL through string interpolation. -- 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 ben+python at benfinney.id.au Mon Nov 2 17:14:05 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 09:14:05 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> Message-ID: <87ljiok21e.fsf@benfinney.id.au> J Kenneth King writes: > Steven D'Aprano writes: > > > from operator import add > > map(add, operandlist1, operandlist2) > > This is the best solution so far. Strange to say it's a solution, when it doesn't solve the stated problem: to replace use of ?map()? with a list comprehension. > I understand the OP was asking for it, but list comprehensions aren't > the best solution in this case... it would just be line noise. I disagree; a list comprehension is often clearer than use of ?map()? with a lambda form, and I find it to be so in this case. -- \ ?He may look like an idiot and talk like an idiot but don't let | `\ that fool you. He really is an idiot.? ?Groucho Marx | _o__) | Ben Finney From deets at nospam.web.de Mon Nov 2 17:16:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 23:16:54 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> Message-ID: <7l942mF3c94mlU1@mid.uni-berlin.de> Alf P. Steinbach schrieb: > * Diez B. Roggisch: >>> Your comment about "computed" makes it more clear what that's all about. >>> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >>> called it "referential transparency". But I think when Python has this >>> nice property mechanism, why do people change direct data attributes >>> into >>> properties and not the other way around or not at all, I mean using only >>> properties for logical >>> data attributes -- e.g. assuring correctness first via read-only >>> property? >> >> I fail to see where read-only-ness of an attribute is a priori more >> correct >> than having modifyable attributes. > > No, I didn't mean that it is more correct to have an attribute as > read-only. I meant that letting a logical data attribute start out as a > read only property can help to ensure correctness. Which is the same thing said with other words. > For example, consider > two rectangle classes R1 and R2, where R2 might be a successor to R1, at > some point in system evolution replacing R1. R1 has logical data members > left, top, width and height, and R2 has logical data members left, top, > right and bottom. With R1 direct changes of left and top keeps the > rectangle's size (since that size is specified by width and height), > while with R2 it changes the rectangle's size. R1 is implemented with > logical data members as directly exposed data attributes. Some code in > the system deals only with R1 objects and for convenience or efficiency > or whatever uses direct modification instead of set_position method. Due > to new requirements it instead has to deal with R2 objects, with same > methods. But due to the direct modification of object state it now > changes the rectangle sizes, but at first it's not noticed since the > attempted rectangle position changes are very small. People get upset. > The bug is fixed. Time has been wasted. If there is need for mutable rectangles, there is need for mutable rectangles. Using properties instead of attributes doesn't help - if you change semantics of something, code might break. In Python, attributes are part of the public interface as long as you don't explicitly define them otherwise. But preliminary assumptions about what could be in some yet unseen future is introducing more code with more chances of errors, reducing the flexibility at the same time. I still fail to see where that's good. Code for what you need code for. It works - in all languages, but especially in Python. Diez From tjreedy at udel.edu Mon Nov 2 17:17:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Nov 2009 17:17:40 -0500 Subject: graceful degradation : is it degrading? In-Reply-To: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> References: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Message-ID: Aaron Watters wrote: > people noted that they sometimes didn't work properly with > javascript off. I could fix this in some cases, but > the fix would involve changing a "POST" to a "GET" > and that would cause MSIE to suddenly fail when the > GET parameters get too big (and probably other > browsers too). So it really would only fix part of the > problem. Consequently I'm tempted to say: "sorry, > please enable javascript if you want to use this page..." If a page is sufficiently dynamic on the client side, that seems reasonable enough to me. From ben+python at benfinney.id.au Mon Nov 2 17:21:16 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 09:21:16 +1100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> Message-ID: <87hbtck1pf.fsf@benfinney.id.au> Jean-Michel Pichavant writes: > Diez B. Roggisch wrote: > > Start learning a decent editor (emacs is mine) which allows you to > > deal with all of your perceived "problems" > > This is a declaration of war against the vi community. We won't give > up, prepare for vengeance ! Bah. Saying that Emacs is a decent text editor doesn't preclude other decent text editors. You and your pugilistic editor wars... Of course, vi is *not* a decent text editor (which, to my reckoning, requires all of: free software, mature, widely used, powerful, extensible and ? because of all the preceding points ? extensive support for a huge range of editing tasks). The only text editors that make the bar are Emacs and Vim. Anyone who disagrees had better be prepared for vengeance. -- \ ?Be careless in your dress if you must, but keep a tidy soul.? | `\ ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From krister.svanlund at gmail.com Mon Nov 2 17:31:21 2009 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 2 Nov 2009 23:31:21 +0100 Subject: list comprehension problem In-Reply-To: References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: <2cf430a60911021431u5b6071e3mac552ab9b985cbde@mail.gmail.com> On Mon, Nov 2, 2009 at 10:11 PM, Aahz wrote: > In article <7589e0a1-98b2-4df4-bc76-5d4c10194fde at f20g2000prn.googlegroups.com>, > Falcolas ? wrote: >> >>I'd also recommend trying the following filter, since it is identical >>to what you're trying to do, and will probably catch some additional >>edge cases without any additional effort from you. >> >>[s.strip() for s in hosts if s.strip()] > > This breaks if s might be None If you don't want Nones in your list just make a check for it... [s.strip() for s in hosts if s is not None and s.strip()] From pavlovevidence at gmail.com Mon Nov 2 17:59:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 14:59:34 -0800 (PST) Subject: conditional __init__ References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: <9ed412a9-23e2-4c22-b108-7d7c002ef956@p8g2000yqb.googlegroups.com> On Nov 2, 11:40?am, King wrote: > class A(object): > ? ? def __init__(self): > ? ? ? ? pass > ? ? def printme(self): > ? ? ? ? print "I am A" > > class B(object): > ? ? def __init__(self): > ? ? ? ? pass > ? ? def printme(self): > ? ? ? ? print "I am B" > > class K(A, B): > ? ? def __init__(self, value=0): > ? ? ? ? if value == 0: > ? ? ? ? ? ? A.__init__(self) > ? ? ? ? ? ? print "__init__ A" > ? ? ? ? elif value == 1: > ? ? ? ? ? ? B.__init__(self) > ? ? ? ? ? ? print "__init__ B" > ? ? ? ? self.printme() > > o = K(value=1) > > Output > > >>__init__ B > >>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? What's wrong is that you have a fundamental misunderstanding of what's happening. You can't just shut off a subclass by refusing to initialize it--just doesn't work that way. All subclasses will continue to be active whether you call __init__ on them or not. Therefore when you call self.printme() it searches the base classes in order, and the first one it finds is A, so it always calls A's printme. It seems to me that you haven't learned enough about how inheritance works in Python to use multiple inheritance yet, so I would suggest just sticking to single inheritance for now, and study up. > Is there a better/another way to do conditional initialization as > needed above? The fact that you feel the need to do this suggests that you want a composition relationship, not an inheritance one. What you appear to be doing is defining a sort of "plugin", you have an object that can behave one way (A) or another (B), but which one isn't known till run time. In that case the A or B object should be made an attribute of the K object: class A(object): def printme(self): print "I am A" class B(object): def printme(self): print "I am B" class K(object): def __init__(self, value=0): if value == 0: self.plugin = A() print "__init__ A" elif value == 1: self.plugin = B() print "__init__ B" self.plugin.printme() Without seeing more of your code I strongly suspect that this change better reflects what you're trying to do. Carl Banks From skong1 at gmail.com Mon Nov 2 18:39:07 2009 From: skong1 at gmail.com (sityee kong) Date: Mon, 2 Nov 2009 15:39:07 -0800 Subject: read Zipfile Message-ID: Hi all, I'm writing a program to manipulate data in 3 different kind of format, there are GZIP, cvs/txt, or ZIP file. Here is part of my program to open these 3 kind formats of file, if (option==1): file=gzip.GzipFile(sys.argv[1],"r") elif (option==2): file=open(sys.argv[1],"r") elif (option==3): archive=zipfile.ZipFile(sys.argv[1],"r") I have no problem with opening GZIP or cvs/txt file. However for the ZIP file, let says the ZIP file contains only one member, >>> archive.namelist() ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] I would like to open the csv file with folowwing command, file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") But it turned out error, Traceback (most recent call last): File "", line 1, in ? AttributeError: ZipFile instance has no attribute 'open' Do you know the way to open an file from a ZIP archive, but not reading them all into memory. I would manipulate each line using "for line in file:" Hope my contents do make sense. Thanks, phoebe -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 2 19:02:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 17:02:34 -0700 Subject: read Zipfile In-Reply-To: References: Message-ID: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> On Mon, Nov 2, 2009 at 4:39 PM, sityee kong wrote: > However for the ZIP file, let says the ZIP file contains only one member, >>>> archive.namelist() > ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] > > I would like to open the csv file with folowwing command, > file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") > But it turned out error, > > Traceback (most recent call last): > ? File "", line 1, in ? > AttributeError: ZipFile instance has no attribute 'open' ZipFile.open(name[, mode[, pwd]]) [...] New in version 2.6. Would your Python version happen to be pre-2.6? Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Nov 2 19:04:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Nov 2009 00:04:31 -0000 Subject: About one class/function per module In-Reply-To: <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> Message-ID: On Mon, 02 Nov 2009 13:24:59 -0000, Peng Yu wrote: > Another advantage one of class/function per file is that the syntax > clearly tell the dependence relation between classes and functions. Um, no. Grepping for "import" now tells you that there is a dependency between the file contents, but it leaves you with no clue as to what that relationship is. You've thrown away the strong relationship information that comes from collecting your source into a single file. > Suppose I have class A and class B in a file, I can not easily figure > out which class depends on which class by a simple script. However, if > they are in two separate files, for example B depends on A, then I > will have 'import A' in file B. This dependency can be easily figured > out by a script. You could always try searching for the class name, which will tell you a whole lot more about how it's being used. > The following scenario also demonstrate why the maintenance cost is > lower with one class/function per file, because it decouples > dependences. Let's suppose class A and B are in the same file. Now I'm > changing class B. But while I'm changing class B, I just realize that > I have to change A. But since the change in B is half way done > (syntactical not correct), I will not be able to run the test case for > A, because the test case import the file that has class B. In > contrast, if A and B are in different files, even if B is half way > done, I can still run test case for A. Provided, of course, that the test case is still meaningful given the changes being made to B, and that you don't forget what you were doing with B while your attention is on A. Not my favorite way of working, though sometimes you just can't avoid it. Of course, given that A and B are in different files, your chances of realising that you needed to change A at all dropped dramatically. -- Rhodri James *-* Wildebeest Herder to the Masses From deets at nospam.web.de Mon Nov 2 19:12:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 01:12:59 +0100 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <7l9asbF3c7qa2U1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >>>>> If you have any suggestions, let me know -- this is a community >>>>> effort! >>>> Suggestion: Please don't make efforts to fragment the community. >>> When a community grows and consequently its needs also grow, how do >>> you differentiate "natural growth" from "fragmenting the community"? >>> >>> Same question in another way: let's suppose Tim Peters sent the exact >>> email the OP sent with the exact same website. Would you have >>> responded to him the same way? >> Most probably not - but then because Tim certainly would have discussed this >> move with peers from the community, if there is a need for this kind of >> forum or not. >> >> Being from germany, I can say that we *have* this fragmentation, and >> frankly: I don't like it. I prefer my communication via NNTP/ML, and not >> with those visually rather noisy and IMHO suboptimal forums. > > If you prefer NNTP/ML, I'd suggest you pay attention to these channels > only. BTW, I prefer ML also and I'm very happy with c.l.p. However > that doesn't mean that I need to be hostile to other forms of > communication and it doesn't mean that I need to discourage people > from setting up other channels of communication for those folks who > prefer them. Since when is the mere suggestion that fragmentation will occur and if that's a desirable consequence is hostile? The OP is not bound to it, and I also don't see the tone used by the two immediate answerers being hostile. Paul might have been terse - but hostility looks different IMHO. The OP *might* come to the conclusion that further fragmenting the community isn't within his personal goals either. OTOH, he might also simply think that once his forum gained traction, he can switch on the google ads, and cash in. Which a forum announced by Tim Peters, run under python.org wouldn't I'd say. > If new channels open up for others it will not make c.l.p any worse. It will, if they catch on. As some competent people will move away. Again, this is the case in the german python scene, and it plain sucks. We have a ML, a NG, and a forum. None of them is synchronized in any way. We wanted to do this for ML and NG - but the guy responsible for the ML can't be reached, or refuses to answer. If we had only one source, fragmentation wouldn't occur, and the competence would be bundled. That I personally prefer MLs and NGs doesn't mean that I wouldn't turn to the forum if it was *the* way to talk about Python. But as it stands, there are three kind of things, of which I'm already subsribed to two - and am annoyed of people posting questions in both of them. Now, I can't do anything about it in the sense that I can forbid it. But questioning the move to create a new form of exchange (especially something rather uninspired, in contrast to e.g. stackoverflow) I can. > If enough people like c.l.p. it will continue to be a good channel, if > too many too good people switch to an online forum, well, in that case > c.l.p. will cease to be great, but it won't be because of artificial > fragmentation by somebody but because the people started to prefer > online forums (words like "free market" come to mind :)) Yes. Or all of them suck equally. Free market again. I'm not against it, but asking the OP if he really thinks the value of his forum outweighs the risk of making existing fora worse is a valid question. Free speech, one other nice free thing out there. > I generally not register on any online forum and will most probably > not register on pyfora either. But I know for a fact that many people > prefer forums over ML and why shouldn't those people be happy with the > communication platform they like and why shouldn't they be given a > chance to join the python community if the only reason they stayed > away was that they didn't like c.l.p. for one reason or another? > >> E.g. it >> requires much more effort to get to know what new discussions arose, as >> well as following ongoing ones - because the interface lacks a >> comprehensive overview of that, and features like "jump to next unread >> article". > > These are perfectly legitimate reasons for you to not use online > forums and stick to c.l.p. I do the same thing. But again, if an > enthusiastic python community member wants to open new channels for > those folks who like them, why should anyone be hostile to him/her? Again, nobody has been. Diez From alfps at start.no Mon Nov 2 19:18:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 03 Nov 2009 01:18:53 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > * Alf P. Steinbach wrote: >> * Peter Otten: >>> Every time someone has to read the code he will read, hesitate, read >>> again, and then hopefully come to the conclusion that the code does >>> nothing, consider not using it, or if it is not tied into a larger >>> project removing it. >> I don't understand what you mean. > > Writing code is not fire and forget. It has to be debugged, tested, > maintained, and will be read quite a few times in the process. Therefore it > is important that you make it easy to read and understand. No, I meant that I didn't understand why you find it hard to read and understand. [snip] > Couldn't > > class IdButton(tkinter.Button): > def __init__(self, id, **kw): > self.id = id > tkinter.Button.__init__(self, **kw) > > be customised as easily? Not unless there's much more that I can learn about tkinter button 'command' callbacks. Which is of course possible. :-) Is it possible to pick up the relevant object from the handler? But AFAIK it's not (I got no arguments supplied in the calls when I tested, although I don't know whether there are any options or whatever to make it supply an event object argument, say). And so AFAICS with this code there's no way to get an id in the on-click (tkinter 'command') handler. [snip] >>> Example: Why do you introduce button.id_string() instead of >>> str(button.id)? >> Because the string representation of an id then /can/ be customized >> independently of the id. For example, id's might be integers but for >> string representation you might want symbolic action names (e.g., you >> might have two or more buttons with same title but different actions, so >> that title would be ungood to identify button). And for another example, >> when debugging or testing you might want the string represention of an id >> to provide more information about the button and/or its context, and then >> id_string provides a single >> central customization point -- provided it's used, of course. > > And what about the IdEntry class? The naming scheme doesn't hold up, but I'm pretty sure that's not what you mean? > To me it would make more sense to > customize the type of the .id value. That sounds rather complex, like introducing a command pattern or something just to support some debugging and testing. [snippety] >>>> This advantage of confidence in correctness can be realized even without >>>> heavy reuse, because the encapsulation that's necessary for reuse, here >>>> having the code in a class, also makes it possible with more centralized >>>> testing. >>> Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ >>> ? >> No. :-) But you're right that testing isn't that much of an issue for >> that class. If that's what you meant. > > I read it twice but didn't understand it. You probably misplaced a word, but > I can't figure out which one. In general, if you encapsulate functionality in a class or function definition or whatever, then you can move that code out to a module (or a package) and you can then test the module and gain some confidence in its correctness. In contrast, if you have nearly the same code duplicated in umpteen places, doing just about the same but with local variations, then testing and especially fixing it becomes more difficult and time consuming, and doesn't give you added confidence about any new instances of that code pattern (with own variations). But in this case the code to be duplicated is so small, just some glue for calling a handler with an id, that it's difficult to get wrong. Even though getting that wrong was exactly what this discussion thread started with. And so the possible savings in the amount of work for testing and fixing is probably (OK, weasel word) not that much of an issue in this case. [snippety] >>> >>>>>> def __on_tk_command( self ): >>>>>> if self.__specified_command != None: >>>>>> self.__specified_command( self ) >>>>>> else: >>>>>> self.on_clicked() >> Uh, could you expand on how that's redundant and how to make it less so? > > How about > > class IdButton(tkinter.Button): > def __init__(self, owner, id, command=None, **kwargs): > tkinter.Button.__init__( > self, owner, kwargs, command=self.on_clicked) > self.id = id > self.specified_command = command > > def on_clicked(self): > if self.specified_command is not None: > self.specified_command(self) The only purpose I can see for on_clicked is that it can be overridden (that was the purpose in my code too, a central customization point). But if anyone does that then he or she now has to duplicate the original on_clicked() code, or else ditch the per button customization via a supplied command handler function. I feel that forced code duplication, forced redundancy, something you just have to remember to add in the code, for the only purpose, is ungood. Cheers, - Alf From rhodri at wildebst.demon.co.uk Mon Nov 2 19:21:50 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Nov 2009 00:21:50 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Mon, 02 Nov 2009 00:49:50 -0000, Alf P. Steinbach wrote: > * Rhodri James: >> On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach >> wrote: >> >>> * Rhodri James: >> This is a weird attribution style, by the way. I don't think it helps. > > That's a pretty weird thing to comment on. > > And as far as I can see the comment doesn't make sense except as an > attempt to find something negative to say. > > But anyway, the point about '*' was, once upon a time, that it made for > a very clear style of quoting in old newsreaders. Nowadays the tools are > generally of lesser quality (e.g. I'm using Thunderbird). And so it > doesn't really have much of that advantage left, but I'm using it > anyway; I can be pretty stubborn about issues of quality. I'm struggling to recall as single instance of this in all of my Usenet days. And failing. And with that, I officially give up on you. -- Rhodri James *-* Wildebeest Herder to the Masses From alfps at start.no Mon Nov 2 19:38:40 2009 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 03 Nov 2009 01:38:40 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Mon, 02 Nov 2009 00:49:50 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: >>> On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach >>> wrote: >>> >>>> * Rhodri James: >>> This is a weird attribution style, by the way. I don't think it helps. >> >> That's a pretty weird thing to comment on. >> >> And as far as I can see the comment doesn't make sense except as an >> attempt to find something negative to say. >> >> But anyway, the point about '*' was, once upon a time, that it made >> for a very clear style of quoting in old newsreaders. Nowadays the >> tools are generally of lesser quality (e.g. I'm using Thunderbird). >> And so it doesn't really have much of that advantage left, but I'm >> using it anyway; I can be pretty stubborn about issues of quality. > > I'm struggling to recall as single instance of this in all of my Usenet > days. And failing. > > And with that, I officially give up on you. Again, a '*' in attributions is a pretty weird thing to focus on. But all you have posted so far in this thread has been technically incorrect (even when you've been led by hand to technical doc), logically fallacious, plus, and mostly, your vague unfocused negative feelings like above. So, it's understandable. :-) Cheers, - Alf From pavlovevidence at gmail.com Mon Nov 2 19:52:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 16:52:27 -0800 (PST) Subject: import bug References: Message-ID: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> On Oct 31, 7:12?am, kj wrote: > I'm running into an ugly bug, which, IMHO, is really a bug in the > design of Python's module import scheme. ?Consider the following > directory structure: > > ham > |-- __init__.py > |-- re.py > `-- spam.py > > ...with the following very simple files: > > % head ham/*.py > ==> ham/__init__.py <== > > ==> ham/re.py <== > > ==> ham/spam.py <== > import inspect > > I.e. only ham/spam.py is not empty, and it contains the single line > "import inspect". > > If I now run the innocent-looking ham/spam.py, I get the following > error: > > % python26 ham/spam.py > Traceback (most recent call last): > ? File "ham/spam.py", line 1, in > ? ? import inspect > ? File "/usr/local/python-2.6.1/lib/python2.6/inspect.py", line 35, in > ? ? import string > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 122, in > ? ? class Template: > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in __init__ > ? ? 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > > or, similarly, > > % python3 ham/spam.py > Traceback (most recent call last): > ? File "ham/spam.py", line 1, in > ? ? import inspect > ? File "/usr/local/python-3.0/lib/python3.0/inspect.py", line 36, in > ? ? import string > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 104, in > ? ? class Template(metaclass=_TemplateMetaclass): > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 98, in __init__ > ? ? 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > > My sin appears to be having the (empty) file ham/re.py. ?So Python > is confusing it with the re module of the standard library, and > using it when the inspect module tries to import re. Python is documented as behaving this way, so this is not a bug. It is arguably poor design. However, Guido van Rossum already ruled against using a single package for the standard library, and its not likely that special case code to detect accidental name-clashes with the standard library is going to be added, since there are legitimate reasons to override the standard library. So for better or worse, you'll just have to deal with it. Carl Banks From python.list at tim.thechases.com Mon Nov 2 20:02:52 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 19:02:52 -0600 Subject: read Zipfile In-Reply-To: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> Message-ID: <4AEF813C.8020707@tim.thechases.com> >> I would like to open the csv file with folowwing command, >> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >> But it turned out error, >> >> Traceback (most recent call last): >> File "", line 1, in ? >> AttributeError: ZipFile instance has no attribute 'open' > > ZipFile.open(name[, mode[, pwd]]) > [...] > New in version 2.6. > > Would your Python version happen to be pre-2.6? FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it into your project directory. I had a similar issue in 2.4 (wanted the iterator provided by 2.6's open() call) and Gabriel suggested trying to just copy in the 2.6 version into my project directory. Worked for me(tm). -tkc From jess.austin at gmail.com Mon Nov 2 20:05:42 2009 From: jess.austin at gmail.com (Jess Austin) Date: Mon, 2 Nov 2009 17:05:42 -0800 (PST) Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> Message-ID: <57317abf-35d6-42b6-b46b-3c2778f53888@m16g2000yqc.googlegroups.com> On Nov 1, 1:13?am, "Gabriel Genellina" wrote: > Looks like in 3.1 this can be done with bytes+str and viceversa, even if ? > bytes and str don't have a common ancestor (other than object; basestring ? > doesn't exist in 3.x): > > p3> Base = bytes > p3> Other = str > p3> > p3> class Derived(Base): > ... ? def __eq__(self, other): > ... ? ? print('Derived.__eq__') > ... ? ? return True > ... > p3> Derived()==Base() > Derived.__eq__ > True > p3> Base()==Derived() > Derived.__eq__ > True > p3> Derived()==Other() > Derived.__eq__ > True > p3> Other()==Derived() > Derived.__eq__ ? ? ? ? ? ?# !!! > True > p3> Base.mro() > [, ] > p3> Other.mro() > [, ] > > The same example with set+frozenset (the one you're actually interested ? > in) doesn't work, unfortunately. > After further analysis, this works for bytes and str because both types ? > refuse to guess and compare to each other; they return NotImplemented when ? > the right-side operand is not of the same type. And this gives that other ? > operand the chance of being called. > > set and frozenset, on the other hand, are promiscuous: their ? > tp_richcompare slot happily accepts any set of any kind, derived or not, ? > and compares their contents. I think it should be a bit more strict: if ? > the right hand side is not of the same type, and its tp_richcompare slot ? > is not the default one, it should return NotImplemented. This way the ? > other type has a chance to be called. Thanks for this, Gabriel! There seems to be a difference between the two cases, however: >>> str() == bytes() False >>> set() == frozenset() True I doubt that either of these invariants is amenable to modification, even for purposes of "consistency". I'm not sure how to resolve this, but you've definitely helped me here. Perhaps the test in set_richcompare can return NotImplemented in particular cases but not in others? I'll think about this; let me know if you come up with anything more. thanks, Jess From pengyu.ut at gmail.com Mon Nov 2 20:06:20 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 19:06:20 -0600 Subject: About one class/function per module In-Reply-To: <4AEEF493.5010505@sequans.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> On Mon, Nov 2, 2009 at 9:02 AM, Jean-Michel Pichavant wrote: > Diez B. Roggisch wrote: >> >> Peng Yu wrote: >> >>> >>> ?I can navigate to the definition of >>> class and function by vim + ctags, >>> >> >> Start learning a decent editor (emacs is mine) which allows you to deal >> with all of your perceived "problems" >> Diez >> > > This is a declaration of war against the vi community. We won't give up, > prepare for vengeance ! > By the way, why the hell would someone wants to limit itself to one function > per file, file names would be probably related to the function name, that > would make changing function name a nightmare, not mentiong the history > issues when using version control systems. Definitely a bad idea. I use vi rather than emacs. I stick to vi because I stated with vi and I don't what to use both editors but only at an amateur level. With some automated script, I don't think it is a nightmare to change function names. I can change function names and filenames and their reference with a simple command. I'd think that this is the limitation of current version control system. I don't aware of any version control system that allows easy change of filenames. But why such features can not be implemented in the version control system? From collin.day.0 at gmail.com Mon Nov 2 20:14:12 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 2 Nov 2009 17:14:12 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: <4e6ad15b-4f6d-463b-872a-44b400a4edaf@a37g2000prf.googlegroups.com> Thanks for the replies. Pyparsing looks just like what I need. From gagsl-py2 at yahoo.com.ar Mon Nov 2 20:19:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 22:19:01 -0300 Subject: read Zipfile References: Message-ID: En Mon, 02 Nov 2009 20:39:07 -0300, sityee kong escribi?: > However for the ZIP file, let says the ZIP file contains only one member, >>>> archive.namelist() > ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] > > I would like to open the csv file with folowwing command, > file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") > But it turned out error, > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: ZipFile instance has no attribute 'open' > > Do you know the way to open an file from a ZIP archive, but not reading > them > all into memory. I would manipulate each line using "for line in file:" open was added to the ZipFile class in Python 2.6; which version are you using? I think you can backport the 2.6 version onto 2.5 with little or no effort. http://docs.python.org/library/zipfile.html#zipfile.ZipFile.open > Hope my contents do make sense. Yes, it was clear to me. -- Gabriel Genellina From skong1 at gmail.com Mon Nov 2 20:28:46 2009 From: skong1 at gmail.com (sityee kong) Date: Mon, 2 Nov 2009 17:28:46 -0800 Subject: read Zipfile In-Reply-To: <4AEF813C.8020707@tim.thechases.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: Hi all, yes, im using python 2.4. I would like to know how does python 2.4 work for my case w/o the new added feature in 2.6? Do you guys know? thanks! On Mon, Nov 2, 2009 at 5:02 PM, Tim Chase wrote: > I would like to open the csv file with folowwing command, >>> >>> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >>> But it turned out error, >>> >>> Traceback (most recent call last): >>> File "", line 1, in ? >>> AttributeError: ZipFile instance has no attribute 'open' >>> >> >> ZipFile.open(name[, mode[, pwd]]) >> [...] >> New in version 2.6. >> >> Would your Python version happen to be pre-2.6? >> > > FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it > into your project directory. I had a similar issue in 2.4 (wanted the > iterator provided by 2.6's open() call) and Gabriel suggested trying to just > copy in the 2.6 version into my project directory. Worked for me(tm). > > -tkc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 2 20:37:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 17:37:31 -0800 Subject: read Zipfile In-Reply-To: References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> > On Mon, Nov 2, 2009 at 5:02 PM, Tim Chase > wrote: >>>> I would like to open the csv file with folowwing command, >>>> >>>> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >>>> But it turned out error, >>>> >>>> Traceback (most recent call last): >>>> ?File "", line 1, in ? >>>> AttributeError: ZipFile instance has no attribute 'open' >>> >>> ZipFile.open(name[, mode[, pwd]]) >>> [...] >>> ? ?New in version 2.6. >>> >>> Would your Python version happen to be pre-2.6? >> >> FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it >> into your project directory. ?I had a similar issue in 2.4 (wanted the >> iterator provided by 2.6's open() call) and Gabriel suggested trying to just >> copy in the 2.6 version into my project directory. ?Worked for me(tm). On Mon, Nov 2, 2009 at 5:28 PM, sityee kong wrote: > Hi all, yes, im using python 2.4. > > I would like to know how does python 2.4 work for my case w/o the new added > feature in 2.6? Do you guys know? Looks like you'd have to use the more primitive .read() method: http://docs.python.org/library/zipfile.html#zipfile.ZipFile.read Also, please avoid top-posting in the future. Cheers, Chris -- http://blog.rebertia.com From ldo at geek-central.gen.new_zealand Mon Nov 2 20:45:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 14:45:23 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 2009-11-02 14:47 PM, Lawrence D'Oliveiro wrote: > >> For instance, I'm not aware of any database API that lets me do this: >> >> sql.cursor.execute \ >> ( >> "update numbers set flags = flags | %(setflags)u where >> projectid = %(projectid)s" "%(match_listid)s and number = >> %(number)s" >> % >> { >> "projectid" : SQLString(ProjectID), >> "match_listid" : >> ("", " and listid = %s" % SQLString(ListID))[ListID >> != None], >> "number" : SQLString(number), >> "setflags" : flags, >> } >> ) > > When programmatically generating SQL, I like to use SQLAlchemy. This use > case is handled with .where() on Update expression objects. Personally, I > find manipulating the SQLAlchemy expression objects clearer, safer, and > more portable than building the raw SQL through string interpolation. Doesn't seem to support bulk insertions ? la this . Or even literal lists as per the SQLStringList routine on the same page. From gagsl-py2 at yahoo.com.ar Mon Nov 2 20:58:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 22:58:25 -0300 Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> <57317abf-35d6-42b6-b46b-3c2778f53888@m16g2000yqc.googlegroups.com> Message-ID: En Mon, 02 Nov 2009 22:05:42 -0300, Jess Austin escribi?: > On Nov 1, 1:13 am, "Gabriel Genellina" wrote: >> Looks like in 3.1 this can be done with bytes+str and viceversa, even >> if bytes and str don't have a common ancestor (other than object; >> basestring doesn't exist in 3.x): >> The same example with set+frozenset (the one you're actually interested >> in) doesn't work, unfortunately. > Thanks for this, Gabriel! There seems to be a difference between the > two cases, however: > >>>> str() == bytes() > False >>>> set() == frozenset() > True > > I doubt that either of these invariants is amenable to modification, > even for purposes of "consistency". I'm not sure how to resolve this, > but you've definitely helped me here. Perhaps the test in > set_richcompare can return NotImplemented in particular cases but not > in others? I'll think about this; let me know if you come up with > anything more. I think it should return NotImplemented only when the right-hand side operand has overriden tp_richcompare. That way, set()==frozenset() would still be True. Only when one inherits from set/frozenset AND overrides __eq__, set_richcompare should step aside and let the more specific __eq__ be called (by just returning NotImplemented). What is your goal when overriding __eq__ for your new set class? It may help building a case for this change; a concrete use case is much better than an abstract request. -- Gabriel Genellina From python.list at tim.thechases.com Mon Nov 2 21:21:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 20:21:39 -0600 Subject: read Zipfile In-Reply-To: References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: <4AEF93B3.70106@tim.thechases.com> > I would like to know how does python 2.4 work for my case w/o the new added > feature in 2.6? Do you guys know? You can just grab the zipfile.py file from within the 2.6 distribution[1] and dump it in your project folder. Python should find it before it finds the 2.4 version in the $PYTHONPATH. While you can also overwrite the older stock version in the $PYTHON_LIB_DIR directory, I recommend against it. -tkc (for future reference, please don't top-post) [1] http://svn.python.org/projects/python/trunk/Lib/zipfile.py From python.list at tim.thechases.com Mon Nov 2 21:29:44 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 20:29:44 -0600 Subject: read Zipfile In-Reply-To: <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> Message-ID: <4AEF9598.8040406@tim.thechases.com> > Looks like you'd have to use the more primitive .read() method: > http://docs.python.org/library/zipfile.html#zipfile.ZipFile.read Unfortunately, the ZipFile.read() reads the entire content. One of the main reasons to zip things is that they're big -- possibly too big to fit conveniently in memory. I don't know about the OP's use-case, so .read() might suffice if the resulting content is small enough. In my case[1], it was a zip containing multiple >700MB MS-Access .mdb files that I needed to stream to temporary disk storage and using .read() killed my dev machine. -tkc [1] http://markmail.org/message/7vn5shss2h64yoop From carsten.haese at gmail.com Mon Nov 2 21:46:03 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 02 Nov 2009 21:46:03 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > There is no such parsing overhead. I speak from experience. > > Look at the BulkInserter class here > . I have successfully > used that to insert tens of thousands of records in just a few seconds. Yet > it makes no use of the parameter-substitution provided by MySQLdb; it is all > just straight Python, including the SQLString routine (also on that page), > which goes through every single character of each string value to decide > what needs escaping. Python can do all that, and do it fast. With all due respect, but if your experience is exclusive to MySQL/MySQLdb, your experience means very little for database programming practices in general. Throughout most of its history, MySQL did not support prepared statements and parameter binding, and MySQLdb doesn't use any parameter binding API that might be available, so you're comparing your own implementation of string interpolation to MySQLdb's implementation of string interpolation. Your experience says nothing about databases that have an *actual* parameter binding API. > You don't get to figure out what's efficient and what's not by mere hand- > waving; I'm not handwaving. > you have to do actual real-world tests. I have. See for example the timing test in http://informixdb.blogspot.com/2007/07/filling-in-blanks.html . If you'd like to try it for yourself, here is a version of the test for SQLite: ================================================================= # querytest.py class Tester(object): def __init__(self): import sqlite3 conn = sqlite3.connect(":memory:") self.cur = conn.cursor() self.cur.execute("create temp table t1(a int, b int)") self.counter = 0 def with_params(self): self.counter += 1 self.cur.execute("insert into t1 values(?,?)", (self.counter,self.counter*2) ) def without_params(self): self.counter += 1 self.cur.execute("insert into t1 values(%s,%s)" % (self.counter,self.counter*2) ) ================================================================= And here are the corresponding results on my laptop: $ python -mtimeit -s "from querytest import Tester; t=Tester()" 't.with_params()' 10000 loops, best of 3: 20.9 usec per loop $ python -mtimeit -s "from querytest import Tester; t=Tester()" 't.without_params()' 10000 loops, best of 3: 36.2 usec per loop So, you can say whatever you want, but you will never convince me that string interpolation is better than parameter binding for getting variable values into a query. Even if you don't accept my proof that it is more efficient, you have not proved that parameter binding is less efficient. In addition to the efficiency factor, parameter binding is inherently secure, whereas string interpolation is too easy to use insecurely. Finally, parameter binding is the standard method, as defined by the SQL standard, of getting variable values into a query. You may call it "premature optimization", but I call it "choosing the right tool for the job." I assume that none of this will convince you, but that's fine. We'll just agree to disagree on this. -- Carsten Haese http://informixdb.sourceforge.net From pengyu.ut at gmail.com Mon Nov 2 22:22:25 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 21:22:25 -0600 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021922w5f28e5f4wbc041e9b5d19533@mail.gmail.com> On Mon, Nov 2, 2009 at 7:41 PM, Lee wrote: > On Nov 2, 7:06?pm, Peng Yu wrote: >> On Mon, Nov 2, 2009 at 9:02 AM, Jean-Michel Pichavant >> >> >> >> >> >> wrote: >> > Diez B. Roggisch wrote: >> >> >> Peng Yu wrote: >> >> >>> ?I can navigate to the definition of >> >>> class and function by vim + ctags, >> >> >> Start learning a decent editor (emacs is mine) which allows you to deal >> >> with all of your perceived "problems" >> >> Diez >> >> > This is a declaration of war against the vi community. We won't give up, >> > prepare for vengeance ! >> > By the way, why the hell would someone wants to limit itself to one function >> > per file, file names would be probably related to the function name, that >> > would make changing function name a nightmare, not mentiong the history >> > issues when using version control systems. Definitely a bad idea. >> >> I use vi rather than emacs. I stick to vi because I stated with vi and >> I don't what to use both editors but only at an amateur level. >> >> With some automated script, I don't think it is a nightmare to change >> function names. I can change function names and filenames and their >> reference with a simple command. >> >> I'd think that this is the limitation of current version control >> system. I don't aware of any version control system that allows easy >> change of filenames. But why such features can not be implemented in >> the version control system? > > Because then the version control system would have to implicitly > identify the original names for files that have changed names... > Think about it, if you change the name of one file, the system should > theoretically be able to accurately identify the original filename and > make the corresponding changes to its database. But if you were to > simultaneously change the names of many files, then there's no > possible way for the system to determine which names belongs where... > I think you can see where I'm going with this. I don't think that this is a problem that can not be overcome. A simple solution might be to associate a unique identifier to each file, so that even the filename has been changed, the new version and the old version can still be identified as actually the same file. From steve at REMOVE-THIS-cybersource.com.au Mon Nov 2 22:32:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 03:32:34 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> Message-ID: <02ff92ad$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 09:14:05 +1100, Ben Finney wrote: > J Kenneth King writes: > >> Steven D'Aprano writes: >> >> > from operator import add >> > map(add, operandlist1, operandlist2) >> >> This is the best solution so far. > > Strange to say it's a solution, when it doesn't solve the stated > problem: to replace use of ?map()? with a list comprehension. In context, I wasn't giving that as a replacement for map(), but as a replacement for map-with-a-lambda. >> I understand the OP was asking for it, but list comprehensions aren't >> the best solution in this case... it would just be line noise. > > I disagree; a list comprehension is often clearer than use of ?map()? > with a lambda form, and I find it to be so in this case. You obviously don't do enough functional programming :) Apart from an occasional brain-fart where I conflate map() with filter(), I find them perfectly readable and sensible. The only advantages to list comps are you can filter results with an if clause, and for simple expressions you don't need to create a function. They're non-trivial advantages, but for me readability isn't one of them. -- Steven From wuwei23 at gmail.com Mon Nov 2 22:39:53 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Nov 2009 19:39:53 -0800 (PST) Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: Peng Yu wrote: > I don't think that this is a problem that can not be overcome. A > simple solution might be to associate a unique identifier to each > file, so that even the filename has been changed, the new version and > the old version can still be identified as actually the same file. Or, again, you could work _with_ the tools you're using in the way they're meant to be used, rather than re-inventing the whole process of version control yourself. From pengyu.ut at gmail.com Mon Nov 2 22:50:56 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 21:50:56 -0600 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021950x473be99bv6077b8ea7aa53ad1@mail.gmail.com> On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: > Peng Yu wrote: >> I don't think that this is a problem that can not be overcome. A >> simple solution might be to associate a unique identifier to each >> file, so that even the filename has been changed, the new version and >> the old version can still be identified as actually the same file. > > Or, again, you could work _with_ the tools you're using in the way > they're meant to be used, rather than re-inventing the whole process > of version control yourself. I'm not trying to reinvent a new version control. But due to this drawback, I avoid use a version control system. Rather, I compressed my source code in a tar file whenever necessary. But if a version control system has this capability, I'd love to use it. And I don't think that no version control system support this is because of any technical difficult but rather because of practical issue (maybe it takes a lot efforts to add this feature to an existing version control system?). From steve at REMOVE-THIS-cybersource.com.au Mon Nov 2 23:04:47 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 04:04:47 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <02ff9a39$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote: > "Jon P." writes: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 > > That's an unfortunate way of expressing it; it's valid Python syntax > that doesn't do what you're describing (in this case, it will bind > ?resultlist? to a new list that is the *concatenation* of the two > original lists). True, but it is valid mathematical syntax if you interpret lists as vectors. I'm sure there are languages where [1,2]+[3,4] will return [4,6]. Possibly R or Mathematica? > Yes, just about any ?map()? operation has a corresponding list > comprehension. (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) Everyone forgets the multiple argument form of map. map(func, s1, s2, s3, ...) would need to be written as: [func(t) for f in itertools.izip_longest(s1, s2, s3, ...)] which I guess is relatively simple, but only because izip_longest() does the hard work. On the other hand, list comps using an if clause can't be written as pure maps. You can do this: [func(x) for x in seq if cond(x)] filter(cond, map(func, seq)) but the second version may use much more temporary memory if seq is huge and cond very rarely true. And I don't think you could write this as a single map: [func(a, b) for a in seq1 for b in seq2] -- Steven From anh.hai.trinh at gmail.com Mon Nov 2 23:06:51 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:06:51 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: > Yes, just about any ?map()? operation has a corresponding list > comprehension. (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) Try turning this into a list comprehension: vectorsum = lambda *args: map(sum, zip(*args)) vectorsum([1,2], [3,4], [5,6]) ->[9, 12] vectorsum([1,2], [3,4], [5,6], [7,8]) ->[16, 20] Peace, ----aht From gagsl-py2 at yahoo.com.ar Mon Nov 2 23:20:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 01:20:07 -0300 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021950x473be99bv6077b8ea7aa53ad1@mail.gmail.com> Message-ID: En Tue, 03 Nov 2009 00:50:56 -0300, Peng Yu escribi?: > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: >> Peng Yu wrote: >>> A simple solution might be to associate a unique identifier to each >>> file, so that even the filename has been changed, the new version and >>> the old version can still be identified as actually the same file. >> >> Or, again, you could work _with_ the tools you're using in the way >> they're meant to be used, rather than re-inventing the whole process >> of version control yourself. > > I'm not trying to reinvent a new version control. But due to this > drawback, I avoid use a version control system. Rather, I compressed > my source code in a tar file whenever necessary. But if a version > control system has this capability, I'd love to use it. And I don't > think that no version control system support this is because of any > technical difficult but rather because of practical issue (maybe it > takes a lot efforts to add this feature to an existing version control > system?). All version control systems that I know of support, at least, renaming files in the same directory. (Old CVS did not, but CVSNT does). svn, hg, darcs and bzr all have renaming support, although bzr seems to be the most robust, specially in non trivial cases. -- Gabriel Genellina From anh.hai.trinh at gmail.com Mon Nov 2 23:24:12 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:24:12 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <02ff9a39$0$1326$c3e8da3@news.astraweb.com> Message-ID: <5f0b9020-a5ad-4c22-82e1-36701a4611e6@z3g2000prd.googlegroups.com> > On the other hand, list comps using an if clause can't be written as pure > maps. You can do this: > > [func(x) for x in seq if cond(x)] > > filter(cond, map(func, seq)) > > but the second version may use much more temporary memory if seq is huge > and cond very rarely true. You could use ifilter, imap there to reduce memory. > And I don't think you could write this as a single map: > > [func(a, b) for a in seq1 for b in seq2] Oh you surely could: seq1, seq2 = [1,2,3], [4,5,6] [a+b for a in seq1 for b in seq2] ->[5, 6, 7, 6, 7, 8, 7, 8, 9] from itertools import product map(sum, product(seq1, seq2)) ->[5, 6, 7, 6, 7, 8, 7, 8, 9] Peace, ----aht From sean_mcilroy at yahoo.com Mon Nov 2 23:30:00 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Mon, 2 Nov 2009 20:30:00 -0800 (PST) Subject: chr / ord Message-ID: hello how do i say "chr" and "ord" in the new python? the functions below (which work in 2.6.6) show what i'm trying to do. thanks if you can help. def readbytes(filepath): return [ord(x) for x in open(filepath,'rb').read()] def writebytes(numbers,filepath): open(filepath,'wb').write(''.join([chr(x) for x in numbers])) From anh.hai.trinh at gmail.com Mon Nov 2 23:51:46 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:51:46 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <1ffbd665-dc70-46d5-a8f7-8e3391acf6ff@y28g2000prd.googlegroups.com> > Try turning this into a list comprehension: > > ? vectorsum = lambda *args: map(sum, zip(*args)) > > ? vectorsum([1,2], [3,4], [5,6]) > ->[9, 12] > ? vectorsum([1,2], [3,4], [5,6], [7,8]) > ->[16, 20] Nvm, it's actually easy: vectorsum = lambda *args: [sum(i) for i in zip(*args)] From aahz at pythoncraft.com Mon Nov 2 23:54:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 20:54:08 -0800 Subject: self.__dict__ tricks References: <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: In article <02fd0c85$0$1326$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote: >> >> Many programmers I know stay away from 'lists' such as this, because >> they are afraid to show their ignorance. Me, I'm fearless, and I have >> learned a lot that I might not have otherwise. > >The only stupid question is the one you are afraid to ask. "There are no stupid questions, only stupid people." -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ben+python at benfinney.id.au Mon Nov 2 23:55:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 15:55:20 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <02ff9a39$0$1326$c3e8da3@news.astraweb.com> Message-ID: <874opcjjgn.fsf@benfinney.id.au> Steven D'Aprano writes: > On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote: > > > "Jon P." writes: > > > >> I'd like to do: > >> > >> resultlist = operandlist1 + operandlist2 > > > > That's an unfortunate way of expressing it; it's valid Python syntax > > that doesn't do what you're describing (in this case, it will bind > > ?resultlist? to a new list that is the *concatenation* of the two > > original lists). > > True, but it is valid mathematical syntax if you interpret lists as > vectors. I'm sure there are languages where [1,2]+[3,4] will return > [4,6]. Possibly R or Mathematica? Python isn't one of them, which is why I cautioned strongly against presenting it that way in this forum. > Everyone forgets the multiple argument form of map. > > map(func, s1, s2, s3, ...) > > would need to be written as: > > [func(t) for f in itertools.izip_longest(s1, s2, s3, ...)] > > which I guess is relatively simple, but only because izip_longest() does > the hard work. Yes, I would call that equivalently simple. (I also find it more explicit and hence readable.) -- \ ?Laurie got offended that I used the word ?puke?. But to me, | `\ that's what her dinner tasted like.? ?Jack Handey | _o__) | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 00:01:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:01:00 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <87zl74i4mr.fsf@benfinney.id.au> Anh Hai Trinh writes: > > Yes, just about any ?map()? operation has a corresponding list > > comprehension. (Does anyone know of a counter-example, a ?map()? > > operation that doesn't have a correspondingly simple list > > comprehension?) > > Try turning this into a list comprehension: > > vectorsum = lambda *args: map(sum, zip(*args)) By ?this? I take you to mean ?the usage of ?map? in this code?, since that's the limit of my question. >>> vectorsum = lambda *args: [sum(items) for items in zip(*args)] >>> vectorsum([1,2], [3,4], [5,6]) [9, 12] >>> vectorsum([1,2], [3,4], [5,6], [7,8]) [16, 20] -- \ ?The apparent lesson of the Inquisition is that insistence on | `\ uniformity of belief is fatal to intellectual, moral, and | _o__) spiritual health.? ?_The Uses Of The Past_, Herbert J. Muller | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 00:10:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:10:20 +1100 Subject: chr / ord References: Message-ID: <87vdhsi477.fsf@benfinney.id.au> Sean McIlroy writes: > how do i say "chr" and "ord" in the new python? By ?the new python?, what do you mean? * Python 2.6.4, the newest released version. * Python 2.7, a currently in-development version. * Python 3.1, another new release (but not the latest). * Python 3.2, a currently in-development version. * Something else. > the functions below (which work in 2.6.6) I think we'll need you to have a closer look at version numbers; there is no Python 2.6.6. > show what i'm trying to do. Unfortunately, they leave us guessing as to what you what to do, and what you expect the result to be. I prefer not to guess. > thanks if you can help. > > def readbytes(filepath): > return [ord(x) for x in open(filepath,'rb').read()] > > def writebytes(numbers,filepath): > open(filepath,'wb').write(''.join([chr(x) for x in numbers])) Could you please show an example of a use of these functions ? preferably a complete, minimal example that anyone can run in the declared version of Python ? and what you would expect the output to be? -- \ ?Remorse: Regret that one waited so long to do it.? ?Henry L. | `\ Mencken | _o__) | Ben Finney From benjamin.kaplan at case.edu Tue Nov 3 00:10:23 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 3 Nov 2009 00:10:23 -0500 Subject: chr / ord In-Reply-To: References: Message-ID: On Mon, Nov 2, 2009 at 11:30 PM, Sean McIlroy wrote: > hello > > how do i say "chr" and "ord" in the new python? the functions below > (which work in 2.6.6) show what i'm trying to do. thanks if you can > help. > > def readbytes(filepath): > ? ?return [ord(x) for x in open(filepath,'rb').read()] > Ord should still work the way you expect. > def writebytes(numbers,filepath): > ? ?open(filepath,'wb').write(''.join([chr(x) for x in numbers])) I haven't played around with python 3 that much, but I believe that the bytes constructor can take an iterable of ints. So you should be able to do open(filepath,'wb').write(bytes(numbers)) > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Tue Nov 3 00:13:08 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:13:08 +1100 Subject: self.__dict__ tricks References: <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <87r5sgi42j.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > "There are no stupid questions, only stupid people." The earliest source I know for that aphorism is the fictional teacher Mister Garrisson, from South Park. Can anyone source it earlier? -- \ ?Read not to contradict and confute, nor to believe and take | `\ for granted ? but to weigh and consider.? ?Francis Bacon | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:17:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:17:38 GMT Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> Message-ID: <02ffab4d$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 07:24:59 -0600, Peng Yu wrote: > Suppose I have class A and class B in a file, I can not easily figure > out which class depends on which class by a simple script. How about looking at the classes? >>> class A: ... pass ... >>> class B(A): ... pass ... >>> >>> B.__bases__ (,) Classes know their own dependencies. Just ask them: import module for superclass in module.A.__bases__: print superclass, "is a dependency for class A" > However, if > they are in two separate files, for example B depends on A, then I will > have 'import A' in file B. This dependency can be easily figured out by > a script. If they are in the same file, you can just look at the class definition: class B(A): And now you know with 100% accuracy that B depends on A, instead of guessing that just because you import a module, that means you must have used a class from that module. > The following scenario also demonstrate why the maintenance cost is > lower with one class/function per file, because it decouples > dependences. Let's suppose class A and B are in the same file. Now I'm > changing class B. But while I'm changing class B, I just realize that I > have to change A. But since the change in B is half way done > (syntactical not correct), I will not be able to run the test case for > A, because the test case import the file that has class B. In contrast, > if A and B are in different files, even if B is half way done, I can > still run test case for A. Assuming A and B are independent, or that B depends on A but not the opposite, failing tests for B won't cause tests for A to fail. This doesn't change whether A and B are in the same file or not. The one exception to this is syntax errors. But if your project contains syntax errors, why are you trying to run test suites? -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:24:54 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:24:54 GMT Subject: chr / ord References: Message-ID: <02ffad01$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 20:30:00 -0800, Sean McIlroy wrote: > hello > > how do i say "chr" and "ord" in the new python? "chr" and "ord". > the functions below (which work in 2.6.6) Can I borrow your time machine, there's some lottery numbers I want to get. There is no Python 2.6.6. The latest version of 2.6 is 2.6.4. > show what i'm trying to do. thanks if you can help. > > def readbytes(filepath): > return [ord(x) for x in open(filepath,'rb').read()] > > def writebytes(numbers,filepath): > open(filepath,'wb').write(''.join([chr(x) for x in numbers])) Have you tried them in "the new Python" (whatever that is...)? What do they do that isn't what you expect? -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:31:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:31:51 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <02ffaea2$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 20:06:51 -0800, Anh Hai Trinh wrote: >> Yes, just about any ?map()? operation has a corresponding list >> comprehension. (Does anyone know of a counter-example, a ?map()? >> operation that doesn't have a correspondingly simple list >> comprehension?) > > Try turning this into a list comprehension: > > vectorsum = lambda *args: map(sum, zip(*args)) > > vectorsum([1,2], [3,4], [5,6]) > ->[9, 12] > vectorsum([1,2], [3,4], [5,6], [7,8]) > ->[16, 20] [sum(t) for t in zip(*args)] will do it. >>> args = [1,2], [3,4], [5,6] >>> [sum(t) for t in zip(*args)] [9, 12] >>> args = [1,2], [3,4], [5,6], [7,8] >>> [sum(t) for t in zip(*args)] [16, 20] -- Steven From half.italian at gmail.com Tue Nov 3 01:54:42 2009 From: half.italian at gmail.com (Sean DiZazzo) Date: Mon, 2 Nov 2009 22:54:42 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <87zl74i4mr.fsf@benfinney.id.au> Message-ID: <9d28a01c-c65b-40d5-ab14-d56118de3dd8@h14g2000pri.googlegroups.com> On Nov 2, 9:01?pm, Ben Finney wrote: > Anh Hai Trinh writes: > > > > Yes, just about any ?map()? operation has a corresponding list > > > comprehension. (Does anyone know of a counter-example, a ?map()? > > > operation that doesn't have a correspondingly simple list > > > comprehension?) > > > Try turning this into a list comprehension: > > > ? vectorsum = lambda *args: map(sum, zip(*args)) > > By ?this? I take you to mean ?the usage of ?map? in this code?, since > that's the limit of my question. > > ? ? >>> vectorsum = lambda *args: [sum(items) for items in zip(*args)] > ? ? >>> vectorsum([1,2], [3,4], [5,6]) > ? ? [9, 12] > ? ? >>> vectorsum([1,2], [3,4], [5,6], [7,8]) > ? ? [16, 20] > > -- > ?\ ? ? ? ?The apparent lesson of the Inquisition is that insistence on | > ? `\ ? ? ? ? uniformity of belief is fatal to intellectual, moral, and | > _o__) ? ?spiritual health.? ?_The Uses Of The Past_, Herbert J. Muller | > Ben Finney prickly From ldo at geek-central.gen.new_zealand Tue Nov 3 01:59:08 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 19:59:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > With all due respect, but if your experience is exclusive to > MySQL/MySQLdb, your experience means very little for database > programming practices in general. I wonder about the veracity of your claims, because: > And here are the corresponding results on my laptop: > $ python -mtimeit -s "from querytest import Tester; t=Tester()" > 't.with_params()' > 10000 loops, best of 3: 20.9 usec per loop > $ python -mtimeit -s "from querytest import Tester; t=Tester()" > 't.without_params()' > 10000 loops, best of 3: 36.2 usec per loop Didn't you say previously that there should be a "seven orders of magnitude" difference? What happened to that claim? From ldo at geek-central.gen.new_zealand Tue Nov 3 02:02:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 20:02:59 +1300 Subject: Sqlite3. Substitution of names in query. References: Message-ID: In message , Dennis Lee Bieber wrote: > On Tue, 03 Nov 2009 09:41:10 +1300, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> There is no such parsing overhead. I speak from experience. >> > > >> Look at the BulkInserter class here >> . I have >> successfully used that to insert tens of thousands of records in just a >> few seconds. Yet it makes no use of the parameter-substitution provided >> by MySQLdb; it is all > > You picked the wrong database to use for your argument. I would say "that is precisely my point", but I'll be kind and give you a chance: pick another database, if you think that will make your point better. From paul.nospam at rudin.co.uk Tue Nov 3 02:10:27 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 03 Nov 2009 07:10:27 +0000 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: <87k4y8rsm4.fsf@rudin.co.uk> Falcolas writes: > [s.strip() for s in hosts if s.strip()] There's something in me that rebels against seeing the same call twice. I'd probably write: filter(None, (s.strip() for s in hosts)) From ben+python at benfinney.id.au Tue Nov 3 02:59:37 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 18:59:37 +1100 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> <87k4y8rsm4.fsf@rudin.co.uk> Message-ID: <87my34hwd2.fsf@benfinney.id.au> Paul Rudin writes: > Falcolas writes: > > > [s.strip() for s in hosts if s.strip()] > > There's something in me that rebels against seeing the same call > twice. Agreed. I'd probably use: >>> lines = ["foo", " ", " bar ", "", "baz"] >>> [s for s in (s.strip() for s in lines) if s] ['foo', 'bar', 'baz'] -- \ ?[I]t is impossible for anyone to begin to learn that which he | `\ thinks he already knows.? ?Epictetus, _Discourses_ | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Tue Nov 3 04:14:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 22:14:25 +1300 Subject: Docs Typo Message-ID: -- ?ScrolledCavas? should be ?ScrolledCanvas?. Also, unlike documentation for other library modules, there is no indication of which features are new in Python 2.6. From ben+python at benfinney.id.au Tue Nov 3 04:38:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 20:38:19 +1100 Subject: Docs Typo References: Message-ID: <87eioghrsk.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > -- ?ScrolledCavas? should be > ?ScrolledCanvas?. Thanks for finding and describing a fault with the Python documentation. This is not the right place for reporting it, though: this is the Python user forum, not an appropriate place for reporting faults. If you would like the issue to be addressed, please report it to the Python bug tracking system . -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From henning.bredel at gmx.de Tue Nov 3 04:41:37 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 03 Nov 2009 09:41:37 GMT Subject: Cast into custom type Message-ID: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Hi, I created a plugin mechanism for my application orientating at the mechanism described by Martin Alchy in http://martyalchin.com/2008/jan/10/simple-plugin-framework/ Now I'd like to call methods like `initialize(parent)' when the user chooses to use a plugin. As described in the blog mentioned above, I only have access to the general type called `PluginMount' (holding all the actual plugin instances). I tried to define "abstract" methods in PluginMount type raising a `NotImplementedError' but it seems, there is no late binding (similar to Java), so the right method would be called. Only the message TypeError: unbound method initialize() must be called with GeoCache instance as first argument (got PluginMount instance instead) `GeoCache' would be the plugin type. What is strange, is the fact, that when asking what instances are hold by PluginMount [] is listed. So it seems, that no late binding is applied when calling the `initialize(self, parent)' method. I'm quite new using Python, so this might be a quite basic question caused by some misunderstandings in general. Feel free to point me to appropriate site to solve my problem. Thanks in advance. Henning From deets at nospam.web.de Tue Nov 3 05:00:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 11:00:23 +0100 Subject: Cast into custom type In-Reply-To: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <7lad9nF3dalgbU1@mid.uni-berlin.de> Henning Bredel schrieb: > Hi, > > I created a plugin mechanism for my application orientating > at the mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ > > Now I'd like to call methods like `initialize(parent)' when > the user chooses to use a plugin. As described in the blog > mentioned above, I only have access to the general type called > `PluginMount' (holding all the actual plugin instances). > > I tried to define "abstract" methods in PluginMount type > raising a `NotImplementedError' but it seems, there is no > late binding (similar to Java), so the right method would be > called. Only the message > > TypeError: unbound method initialize() must be called > with GeoCache instance as first argument (got PluginMount > instance instead) > > `GeoCache' would be the plugin type. What is strange, is the > fact, that when asking what instances are hold by PluginMount > > [] > > is listed. So it seems, that no late binding is applied when > calling the `initialize(self, parent)' method. > > I'm quite new using Python, so this might be a quite basic > question caused by some misunderstandings in general. Feel > free to point me to appropriate site to solve my problem. It seems that GeoCache is not a subclass of PluginMount. Diez From gagsl-py2 at yahoo.com.ar Tue Nov 3 05:08:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 07:08:03 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Tue, 03 Nov 2009 06:41:37 -0300, Henning Bredel escribi?: > I created a plugin mechanism for my application orientating > at the mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ > > Now I'd like to call methods like `initialize(parent)' when > the user chooses to use a plugin. As described in the blog > mentioned above, I only have access to the general type called > `PluginMount' (holding all the actual plugin instances). According to the article, PluginMount holds a list of all plugin *classes* defined, not instances. > I tried to define "abstract" methods in PluginMount type > raising a `NotImplementedError' but it seems, there is no > late binding (similar to Java), so the right method would be > called. Only the message > > TypeError: unbound method initialize() must be called > with GeoCache instance as first argument (got PluginMount > instance instead) Python uses "late binding", even more than Java. A reference like obj.foo(...) searches for "foo" along obj's attributes at runtime. Please post some code showing your issue, and don't forget to tell us what is your expected result, and what you actually get. -- Gabriel Genellina From gatti at dsdata.it Tue Nov 3 05:11:59 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 3 Nov 2009 02:11:59 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> On Nov 1, 8:06?am, Saketh wrote: > Hi everyone, > > I am proud to announce the release of Pyfora (http://pyfora.org), an > online community of Python enthusiasts to supplement comp.lang.python > and #python. While the site is small right now, please feel free to > register and post any questions or tips you may have. I'll feel free to not even bookmark it. I'm sorry, but it is just a bad idea. Your forum cannot (and should not) compete either with Python's official newsgroup, IRC channel and mailing list or with popular, well- made and well-frequented general programming sites like stackoverflow.com. It would be the Internet equivalent of looking for a poker tournament in a desert valley instead of driving half an hour less and going to Las Vegas: there are no incentives to choose your forum, except perhaps for isolationists who value being a big fish in a small pond over being part of a community. If you want to claim a small Python-related corner of the web, you should write a blog: if it is any good, and probably even if it isn't, it would be linked and read by someone and it would add to collective knowledge instead of fragmenting it. Regards, Lorenzo Gatti From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 05:18:29 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 10:18:29 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <02fff1ce$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 09:41:37 +0000, Henning Bredel wrote: > Hi, > > I created a plugin mechanism for my application orientating at the > mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ Regarding your subject line, Python doesn't have casts. A very small number of numeric types are automatically coerced as needed, for everything else you need an explicit conversion between objects of one type to different objects of another type. > Now I'd like to call methods like `initialize(parent)' when the user > chooses to use a plugin. As described in the blog mentioned above, I > only have access to the general type called `PluginMount' (holding all > the actual plugin instances). > > I tried to define "abstract" methods in PluginMount type raising a > `NotImplementedError' but it seems, there is no late binding (similar to > Java), so the right method would be called. You need to give some actual examples of what you are trying to do, and what you are expecting to happen. How is initialized() being called? > Only the message > > TypeError: unbound method initialize() must be called with GeoCache > instance as first argument (got PluginMount instance instead) Sounds like you are calling initialize on the class instead of on an instance. I'm *guessing* that you are doing something like this: plugin_manager = PluginMount() # ... # create plugins, which are registered in the plugin_manager # ... # Now initialize them: for cls in plugin_manager.plugins: cls.initialize(plugin_Manager) If my guess is correct, you can fix this two ways: (1) Change the for-loop to: for cls in plugin_manager.plugins: cls().initialize(plugin_Manager) although it isn't clear to me what you should do with the plugin instances after you've created them. (2) Change the initialize method to a classmethod: @classmethod def initialize(cls, parent): pass > `GeoCache' would be the plugin type. What is strange, is the fact, that > when asking what instances are hold by PluginMount > > [] > > is listed. So it seems, that no late binding is applied when calling the > `initialize(self, parent)' method. What do you mean by late binding, and what makes you think it applies (or should apply) to calling the initialize method? > I'm quite new using Python, so this might be a quite basic question > caused by some misunderstandings in general. Feel free to point me to > appropriate site to solve my problem. We have to understand your problem first. -- Steven From eric.brunel.pragmadev at gmail.com Tue Nov 3 05:19:54 2009 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Tue, 3 Nov 2009 02:19:54 -0800 (PST) Subject: PyGDChart2 module References: <17ace5a2-a541-4512-9699-a4719c6e65bb@p15g2000vbl.googlegroups.com> Message-ID: On Oct 28, 4:52 pm, eb303 wrote: > Hi all, > > I was looking for a simple chart drawing Python module and as a user > of the gd library and its Python interface, I was interested in the > Python interface to the gdchart library (http://www.fred.net/brv/ > chart/). Unfortunately, this module seems to have disappeared: its > former URL (http://www.nullcube.com/software/pygdchart2.html) gives a > 404 and a Google search did not return any other source. Does anyone > know where I can find a copy of this module's source code? > > Thanks. Replying to myself: finally found the source package at http://ftp.de.debian.org/debian/pool/main/p/pygdchart2/pygdchart2_0.beta1.orig.tar.gz Seems to work quite well. From mal at egenix.com Tue Nov 3 05:27:20 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 11:27:20 +0100 Subject: Pyfora, a place for python In-Reply-To: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> Message-ID: <4AF00588.5070504@egenix.com> Kee Nethery wrote: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/) and it will be interesting to see if it can fill > the void that I experience (no centralized place to post and view user > submitted sample code) in the existing Python community. There already is a well-known site for exchanging code snippets: The ActiveState Cookbook for Python http://code.activestate.com/recipes/langs/python/ > As for user community fragmentation, I would guess that someone would be > less likely to create such a site if the user community needs were being > met by the official sites. There is a place for the existing old school > interaction forums (the IRC channel, the Usenet groups and mailing > lists), but there is also a place for archived user submitted comments. > > My personal preference would be a link in each sub-paragraph in the > official documentation to a wiki page devoted to that specific aspect of > the Python language. A place were users could augment the documentation > by providing sample code and by expanding out the documentation for > those of us who don't live and breath Python in our sleep. Real Python > coders would not click on the user wiki links and all of us newbies > could communicate with each other. But until a place like that exists, > perhaps Pyfora will get us part way there. I'm sure something like that could be added to the official documentation. Please file a feature request for on the Python tracker. We could have a dedicated place on the python.org wiki to host such snippets and then use sub-pages for the various topics. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 05:37:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 10:37:13 GMT Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> Message-ID: <02fff632$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 02:11:59 -0800, Lorenzo Gatti wrote: > On Nov 1, 8:06?am, Saketh wrote: >> Hi everyone, >> >> I am proud to announce the release of Pyfora (http://pyfora.org), an >> online community of Python enthusiasts to supplement comp.lang.python >> and #python. While the site is small right now, please feel free to >> register and post any questions or tips you may have. > > I'll feel free to not even bookmark it. I'm sorry, but it is just a bad > idea. > > Your forum cannot (and should not) compete either with Python's official > newsgroup, IRC channel and mailing list or with popular, well- made and > well-frequented general programming sites like stackoverflow.com. Are you saying that now that comp.lang.python and stackoverflow exists, there no more room in the world for any more Python forums? I think that's terrible. Saketh, would you care to give a brief explanation for sets your forum apart from the existing Python forums, and why people should choose to spend time there instead of (or as well as) the existing forums? What advantages does it have? > It would be the Internet equivalent of looking for a poker tournament in > a desert valley instead of driving half an hour less and going to Las > Vegas: there are no incentives to choose your forum, except perhaps for > isolationists who value being a big fish in a small pond over being part > of a community. (Funny you mention Las Vegas -- it started off as a tiny little town in the middle of the desert too.) How about avoiding the noise and obtrusive advertising and bright lights of Las Vegas, the fakery, the "showmanship", the horrible fake pyramid and has-been celebrities, the crowds, the tackiness, the high prices, the bright lights that never turn off (Las Vegas is the brightest city on Earth)... if you're interested in poker without all the mayonnaise, maybe that poker tournament away from the tourists is exactly what you need. Personally, if I wanted to gamble, the last place I would go is any house which had gold-plated taps in the bathrooms. That tells me the house's percentage is *way* too high. -- Steven From simon at brunningonline.net Tue Nov 3 06:26:49 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 3 Nov 2009 11:26:49 +0000 Subject: self.__dict__ tricks In-Reply-To: <02fd0c85$0$1326$c3e8da3@news.astraweb.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> 2009/11/1 Steven D'Aprano : > > The only stupid question is the one you are afraid to ask. I was once asked, and I quote exactly, "are there any fish in the Atlantic sea?" That's pretty stupid. ;-) -- Cheers, Simon B. From furkankuru at gmail.com Tue Nov 3 06:45:31 2009 From: furkankuru at gmail.com (Furkan Kuru) Date: Tue, 3 Nov 2009 13:45:31 +0200 Subject: convert pyc (python 2.4) to py In-Reply-To: <50697b2c0910211158r5f9a1395sfef1976cfc27fc09@mail.gmail.com> References: <7k6p69F3888guU1@mid.uni-berlin.de> <366c6f340910211135r1170757dv746e46f58dbe1ec4@mail.gmail.com> <50697b2c0910211158r5f9a1395sfef1976cfc27fc09@mail.gmail.com> Message-ID: <3a4a8f930911030345l53e45244r301e6839acaa2e4d@mail.gmail.com> There is an online service at http://www.depython.com converting pyc files to py. You can give it a try. It does not have file size limit. On Wed, Oct 21, 2009 at 8:58 PM, Chris Rebert wrote: > On Wed, Oct 21, 2009 at 11:35 AM, Peng Yu wrote: >> On Tue, Oct 20, 2009 at 4:42 PM, Diez B. Roggisch wrote: >>> Peng Yu schrieb: >>>> >>>> I have a .pyc file generated by python 2.4. My current python is of >>>> version 2.6. I'm wondering how to generate the corresponding .py file >>>> from it. >>> >>> http://www.crazy-compilers.com/decompyle/ >> >> Is there any free one? > > There's an older version of the software at: > http://sourceforge.net/projects/decompyle/ > but it's not maintained like the service (just see the last-modified > date on it) and you'll have to figure out how to use it by yourself. > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Furkan Kuru From deets at nospam.web.de Tue Nov 3 06:52:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 12:52:20 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <7lajrkF3c97onU1@mid.uni-berlin.de> Peng Yu wrote: > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: >> Peng Yu wrote: >>> I don't think that this is a problem that can not be overcome. A >>> simple solution might be to associate a unique identifier to each >>> file, so that even the filename has been changed, the new version and >>> the old version can still be identified as actually the same file. >> >> Or, again, you could work _with_ the tools you're using in the way >> they're meant to be used, rather than re-inventing the whole process >> of version control yourself. > > I'm not trying to reinvent a new version control. But due to this > drawback, I avoid use a version control system. Rather, I compressed > my source code in a tar file whenever necessary. But if a version > control system has this capability, I'd love to use it. And I don't > think that no version control system support this is because of any > technical difficult but rather because of practical issue (maybe it > takes a lot efforts to add this feature to an existing version control > system?). There are those people who realize if *everything* they encounter needs adjustment to fit their needs, their needs need adjustment. Others fight an uphill battle & bicker about things not being as they want them. Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis. Diez From ben+python at benfinney.id.au Tue Nov 3 07:02:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 23:02:44 +1100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <7lajrkF3c97onU1@mid.uni-berlin.de> Message-ID: <87639rizob.fsf@benfinney.id.au> "Diez B. Roggisch" writes: > Don't get me wrong - innovation often comes from scratching ones > personal itch. But you seem to be suffering from a rather bad case of > neurodermatitis. +1 QOTW -- \ ?For my birthday I got a humidifier and a de-humidifier. I put | `\ them in the same room and let them fight it out.? ?Steven Wright | _o__) | Ben Finney From henning.bredel at gmx.de Tue Nov 3 07:07:01 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 03 Nov 2009 12:07:01 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> Message-ID: <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Diez, Gabriel, Steven, thanks for your answers. I'll mainly give response in this posting, so I hope not repeating myself. On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: > On Tue, 03 Nov 2009 09:41:37 +0000, Henning Bredel wrote: > >> Now I'd like to call methods like `initialize(parent)' when the user >> chooses to use a plugin. As described in the blog mentioned above, I >> only have access to the general type called `PluginMount' (holding all >> the actual plugin instances). >> >> I tried to define "abstract" methods in PluginMount type raising a >> `NotImplementedError' but it seems, there is no late binding (similar >> to Java), so the right method would be called. > > You need to give some actual examples of what you are trying to do, and > what you are expecting to happen. How is initialized() being called? Example: Assume a framework which offers common functionality for a plugin or a module a user can choose at the beginning. The framework does not know the concrete type of the plugin so it is possible to extend it by implementing a well known interface or abstract class. The framework reads the plugin directory, loads each module and creates buttons for each plugin with a callback method for initializing. To use common functionality of the framework, initialization method takes it as the parent parameter. I think this listing makes the most sense to you: # initialize all plugins self._plugin_modules = _load_plugins() # imp loading here LOGGER.debug(ActionProvider.plugins) # print what was loaded for plugin in ActionProvider.plugins: # create button for each app_button = gtk.Button(plugin.title) LOGGER.debug('Title of plugin: %s' % plugin.title) app_button.connect("clicked", plugin.initialize(plugin, self), None) self.set_canvas(app_button) app_button.show() >> TypeError: unbound method initialize() must be called with GeoCache >> instance as first argument (got PluginMount instance instead) > > Sounds like you are calling initialize on the class instead of on an > instance. I'm *guessing* that you are doing something like this: Oh, I didn't expext PluginMount to hold only classes :/. When calling `LOGGER.debug('Title of plugin: %s' % plugin.title)' the global (not class attribute) `title' attribute is printed out though. Probably some misinterpretation, too ..?! > (1) Change the for-loop to: > > for cls in plugin_manager.plugins: > cls().initialize(plugin_Manager) Good guess .. but calling it in that way another error says app_button.connect("clicked", plugin().initialize(self), None) TypeError: __init__() takes exactly 2 arguments (1 given) But also app_button.connect("clicked", plugin().initialize(plugin, self), None) TypeError: __init__() takes exactly 2 arguments (1 given) That is strange, because neither initialize() nor __init__ of the plugin is called .. only a logging statement shall print a msg. I hope it got a bit clearer what I am intended to do. Thanks for your help. Henning From python-url at phaseit.net Tue Nov 3 07:16:41 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 3 Nov 2009 12:16:41 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 3) Message-ID: QOTW: "I consider "import *" the first error to be fixed ..." - Robert Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker, on his personal style http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 Python 2.6.4 is out; it fixes some small but important bugs in previous 2.6.3 release: http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/ PEP391: A new way to configure Python logging, using dictionaries: http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/ Why do you use Python? http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/ Is there any value in forcing one class/function per module? (long thread): http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/ A review of complex solutions to an almost inexistent problem shows constructive criticism in action: http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/ A user module may shadow a standard module of the same name - is it avoidable? http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/ copy.deepcopy() is not as "deep" as its name implies: http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/ A long thread about Web development: why to use templates, and why frameworks actually do help developers: http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/ Using a module as a place to store application global settings: http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/ A simple list comprehension question leads to discuss mutability, identity, and Cousin Chuy's Super-Burritos: http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/ Combining map, zip and filter into an equivalent list comprehension: http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map timeit: make sure you actually measure what you want, and not other code: http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/ Why do compiled C extensions on Windows use '.pyd' in their name instead of '.dll'? http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/ Pyfora, a web forum about Python, was lauched recently. Will this fragment the community? http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/ A guy's future book on programming Python doesn't fit standard practice (a long thread!): http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 israelu at elbit.co.il Tue Nov 3 07:45:49 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 04:45:49 -0800 (PST) Subject: import from a string Message-ID: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Hi, Having a file called funcs.py, I would like to read it into a string, and then import from that string. That is instead of importing from the fie system, I wonder if it's possible to eval the text in the string and treat it as a module. For example with file('funcs.py') as f: txt = r.read() string_import(txt, 'funcs') # is string_import possible? to have now a module called funcs with the functions defined in funcs.py. Thanks From singletoned at gmail.com Tue Nov 3 07:53:44 2009 From: singletoned at gmail.com (Singletoned) Date: Tue, 3 Nov 2009 04:53:44 -0800 (PST) Subject: Aaaargh! "global name 'eggz' is not defined" References: <4aeaa96c$0$4145$426a74cc@news.free.fr> Message-ID: <05a9780d-bce4-42b6-834a-e81681923c04@k19g2000yqc.googlegroups.com> On Oct 30, 8:53?am, Bruno Desthuilliers wrote: > Robert Kern a ?crit :> On 2009-10-29 16:52 PM, Aahz wrote: > (snip) > >> Coincidentally, I tried PyFlakes yesterday and was unimpressed with the > >> way it doesn't work with "import *". > > > I consider "import *" the first error to be fixed, so it doesn't bother > > me much. :-) > > +1 QOTW Bruno, do you actually get to decide the QOTW? Because everytime you ` +1 QOTW` it gets to be the QOTW. Ed BTW I was the grateful recipient of your vote the other week. From rolf.oltmans at gmail.com Tue Nov 3 08:06:24 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Tue, 3 Nov 2009 05:06:24 -0800 (PST) Subject: Help resolve a syntax error on 'as' keyword (python 2.5) Message-ID: Hi, all. All I'm trying to do is to print the error message using the following code (copying/pasting from IDLE). def div(a,b): print a/b try: div(5,0) except Exception as msg: print msg but IDLE says (while highlighting the 'as' keyword) except Exception as msg: SyntaxError: invalid syntax I've searched the internet and I'm not sure what can cause this. Any help is highly appreciated. I'm using Python 2.5 on Windows XP. From fetchinson at googlemail.com Tue Nov 3 08:19:02 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 3 Nov 2009 14:19:02 +0100 Subject: Pyfora, a place for python In-Reply-To: <7l9asbF3c7qa2U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: On 11/3/09, Diez B. Roggisch wrote: > Daniel Fetchinson schrieb: >>>>>> If you have any suggestions, let me know -- this is a community >>>>>> effort! >>>>> Suggestion: Please don't make efforts to fragment the community. >>>> When a community grows and consequently its needs also grow, how do >>>> you differentiate "natural growth" from "fragmenting the community"? >>>> >>>> Same question in another way: let's suppose Tim Peters sent the exact >>>> email the OP sent with the exact same website. Would you have >>>> responded to him the same way? >>> Most probably not - but then because Tim certainly would have discussed >>> this >>> move with peers from the community, if there is a need for this kind of >>> forum or not. >>> >>> Being from germany, I can say that we *have* this fragmentation, and >>> frankly: I don't like it. I prefer my communication via NNTP/ML, and not >>> with those visually rather noisy and IMHO suboptimal forums. >> >> If you prefer NNTP/ML, I'd suggest you pay attention to these channels >> only. BTW, I prefer ML also and I'm very happy with c.l.p. However >> that doesn't mean that I need to be hostile to other forms of >> communication and it doesn't mean that I need to discourage people >> from setting up other channels of communication for those folks who >> prefer them. > > Since when is the mere suggestion that fragmentation will occur and if > that's a desirable consequence is hostile? The OP is not bound to it, > and I also don't see the tone used by the two immediate answerers being > hostile. Paul might have been terse - but hostility looks different IMHO. I was referring to this comment by Ben: "Suggestion: Please don't make efforts to fragment the community." This IMHO is hostile, because it presupposes that the mere goal of the OP is fragmenting the community, which is something negative, i.e. it contains negative prejudice. What I would have written in Ben's place: Have you considered the possibility that your website will further fragment the community? This wouldn't have been hostile, IMHO. > The OP *might* come to the conclusion that further fragmenting the > community isn't within his personal goals either. OTOH, he might also > simply think that once his forum gained traction, he can switch on the > google ads, and cash in. Which a forum announced by Tim Peters, run > under python.org wouldn't I'd say. > >> If new channels open up for others it will not make c.l.p any worse. > > It will, if they catch on. As some competent people will move away. Competent people will only move away if the website is great/fun/useful/etc. In which case we should welcome it, since something great/fun/useful/etc is a good thing. If it's not great/fun/useful/etc competent people will not move away, in which case c.l.p. will not be any worse as a result of launching the new website. > Again, this is the case in the german python scene, and it plain sucks. > We have a ML, a NG, and a forum. None of them is synchronized in any > way. We wanted to do this for ML and NG - but the guy responsible for > the ML can't be reached, or refuses to answer. Welcome to open source, the world of infinitely many forks, code variants, MLs, forums, NGs, websites, in other words, welcome to the bazaar! Cheers, Daniel > If we had only one source, fragmentation wouldn't occur, and the > competence would be bundled. That I personally prefer MLs and NGs > doesn't mean that I wouldn't turn to the forum if it was *the* way to > talk about Python. But as it stands, there are three kind of things, of > which I'm already subsribed to two - and am annoyed of people posting > questions in both of them. > > Now, I can't do anything about it in the sense that I can forbid it. But > questioning the move to create a new form of exchange (especially > something rather uninspired, in contrast to e.g. stackoverflow) I can. > >> If enough people like c.l.p. it will continue to be a good channel, if >> too many too good people switch to an online forum, well, in that case >> c.l.p. will cease to be great, but it won't be because of artificial >> fragmentation by somebody but because the people started to prefer >> online forums (words like "free market" come to mind :)) > > Yes. Or all of them suck equally. Free market again. I'm not against it, > but asking the OP if he really thinks the value of his forum outweighs > the risk of making existing fora worse is a valid question. Free speech, > one other nice free thing out there. > >> I generally not register on any online forum and will most probably >> not register on pyfora either. But I know for a fact that many people >> prefer forums over ML and why shouldn't those people be happy with the >> communication platform they like and why shouldn't they be given a >> chance to join the python community if the only reason they stayed >> away was that they didn't like c.l.p. for one reason or another? >> >>> E.g. it >>> requires much more effort to get to know what new discussions arose, as >>> well as following ongoing ones - because the interface lacks a >>> comprehensive overview of that, and features like "jump to next unread >>> article". >> >> These are perfectly legitimate reasons for you to not use online >> forums and stick to c.l.p. I do the same thing. But again, if an >> enthusiastic python community member wants to open new channels for >> those folks who like them, why should anyone be hostile to him/her? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From carsten.haese at gmail.com Tue Nov 3 08:19:10 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 03 Nov 2009 08:19:10 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Carsten > Haese wrote: > >> With all due respect, but if your experience is exclusive to >> MySQL/MySQLdb, your experience means very little for database >> programming practices in general. > > I wonder about the veracity of your claims, because: > >> And here are the corresponding results on my laptop: >> $ python -mtimeit -s "from querytest import Tester; t=Tester()" >> 't.with_params()' >> 10000 loops, best of 3: 20.9 usec per loop >> $ python -mtimeit -s "from querytest import Tester; t=Tester()" >> 't.without_params()' >> 10000 loops, best of 3: 36.2 usec per loop > > Didn't you say previously that there should be a "seven orders of magnitude" > difference? What happened to that claim? "That claim" was an exaggeration I resorted to after you distorted the concept of choosing the right tool for the job into premature optimization. It wasn't my initial claim. The "seven orders" (which is actually log-10 orders of however often the same query is executed with different values) is of course only the cost increase on parsing the query itself, which as you pointed out is drowned out by other fixed costs associated with performing database queries. However, you can't dispute the fact that using string interpolation *is* in general less efficient than parameter binding, and that was my initial claim. -- Carsten Haese http://informixdb.sourceforge.net From kmisoft at gmail.com Tue Nov 3 08:19:15 2009 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Tue, 3 Nov 2009 16:19:15 +0300 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) In-Reply-To: References: Message-ID: Hi, "except Exception as variable" is a new python-3 syntax. You should use "except Exception, variable" syntax in 2.x series. Vladimir Ignatov On Tue, Nov 3, 2009 at 4:06 PM, Oltmans wrote: > Hi, all. All I'm trying to do is to print the error message using the > following code (copying/pasting from IDLE). > > def div(a,b): > ? ? ? ?print a/b > > > try: > ? ?div(5,0) > except Exception as msg: > ? ?print msg > > but IDLE says (while highlighting the 'as' keyword) > except Exception as msg: > > SyntaxError: invalid syntax > > I've searched the internet and I'm not sure what can cause this. Any > help is highly appreciated. I'm using Python 2.5 on Windows XP. From contact at xavierho.com Tue Nov 3 08:24:08 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 3 Nov 2009 23:24:08 +1000 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) In-Reply-To: References: Message-ID: <2d56febf0911030524l13b23bcala9ecc1b48715f7af@mail.gmail.com> I don't have Python 25 on my computer, but since codepad.org is using Python 2.5.1, I did a quick test: # input try: raise Exception("Mrraa!") except Exception as msg: print msg # output t.py:3: Warning: 'as' will become a reserved keyword in Python 2.6 Line 3 except Exception as msg: ^ SyntaxError: invalid syntax ######### Well that's interesting. as isn't a keyword yet in Python 2.5. This works though, and I think it fits the specification in the documentation. # input try: raise Exception("Mrraa!") except Exception, msg: # Notice it's a comma print msg # output Mrraa! ############## Hope that helps, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From claird.visiprise at gmail.com Tue Nov 3 08:29:27 2009 From: claird.visiprise at gmail.com (Cameron Laird) Date: Tue, 3 Nov 2009 05:29:27 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Nov 3) Message-ID: QOTW: "I consider "import *" the first error to be fixed ..." - Robert Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker, on his personal style http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 Python 2.6.4 is out; it fixes some small but important bugs in previous 2.6.3 release: http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/ PEP391: A new way to configure Python logging, using dictionaries: http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/ Why do you use Python? http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/ Is there any value in forcing one class/function per module? (long thread): http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/ A review of complex solutions to an almost inexistent problem shows constructive criticism in action: http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/ A user module may shadow a standard module of the same name - is it avoidable? http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/ copy.deepcopy() is not as "deep" as its name implies: http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/ A long thread about Web development: why to use templates, and why frameworks actually do help developers: http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/ Using a module as a place to store application global settings: http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/ A simple list comprehension question leads to discuss mutability, identity, and Cousin Chuy's Super-Burritos: http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/ Combining map, zip and filter into an equivalent list comprehension: http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map timeit: make sure you actually measure what you want, and not other code: http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/ Why do compiled C extensions on Windows use '.pyd' in their name instead of '.dll'? http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/ Pyfora, a web forum about Python, was lauched recently. Will this fragment the community? http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/ A guy's future book on programming Python doesn't fit standard practice (a long thread!): http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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.p ython.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 deets at nospam.web.de Tue Nov 3 09:00:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 15:00:23 +0100 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: <7larbnF3bfnutU1@mid.uni-berlin.de> Vladimir Ignatov wrote: > Hi, > > "except Exception as variable" > > is a new python-3 syntax. > > You should use "except Exception, variable" syntax in 2.x series. Not entirely true. This feature has been backported to python2.6 as well. Diez From ben+python at benfinney.id.au Tue Nov 3 09:16:47 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 01:16:47 +1100 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: <87r5sfhewg.fsf@benfinney.id.au> Oltmans writes: > try: > div(5,0) > except Exception as msg: > print msg The name ?msg? here is misleading. The except syntax does *not* bind the target to a message object, it binds the target to an exception object. It would be clearer to write the above code as: try: div(5, 0) except Exception as exc: print(exc) since the target ?exc? names an exception object, not a message. (The ?print? function will *create* a string object from the exception object, use the string, then discard it.) > but IDLE says (while highlighting the 'as' keyword) > except Exception as msg: > > SyntaxError: invalid syntax > I've searched the internet and I'm not sure what can cause this. When you get a syntax error, you should check the syntax documentation for the version of Python you're using. > Any help is highly appreciated. I'm using Python 2.5 on Windows XP. The syntax above is for Python 3 only . In Python 2.5.4, the ?try ? except? syntax was different , and ?print? was not implemented as a function, but instead as a keyword . Use this form: try: div(5, 0) except Exception, exc: print exc -- \ ?When I get new information, I change my position. What, sir, | `\ do you do with new information?? ?John Maynard Keynes | _o__) | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 09:20:38 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 01:20:38 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: <87my33heq1.fsf@benfinney.id.au> Daniel Fetchinson writes: > I was referring to this comment by Ben: > > "Suggestion: Please don't make efforts to fragment the community." > > This IMHO is hostile, because it presupposes that the mere goal of the > OP is fragmenting the community It presupposes nothing of any goal. It describes a predictable result of the OP's efforts, and requests those efforts to cease. So I deny the characterisation of that request as hostile. -- \ ?Injustice is relatively easy to bear; what stings is justice.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From ahmedbarakat at gmail.com Tue Nov 3 09:21:12 2009 From: ahmedbarakat at gmail.com (Ahmed Barakat) Date: Tue, 3 Nov 2009 16:21:12 +0200 Subject: Handling large datastore search Message-ID: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> In case I have a huge datastore (10000 entries, each entry has like 6 properties), what is the best way to handle the search within such a huge datastore, and what if I want to make a generic search, for example you write a word and i use it to search within all properties I have for all entries? Is the conversion to XML a good solution, or it is not? sorry for being new to web development, and python. Thanks in advance. -- -------------------- Regards, Ahmed Barakat http://ahmedbarakat83.blogspot.com/ Even a small step counts -------------- next part -------------- An HTML attachment was scrubbed... URL: From motoom at xs4all.nl Tue Nov 3 09:53:51 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 03 Nov 2009 15:53:51 +0100 Subject: Handling large datastore search In-Reply-To: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> Message-ID: <4AF043FF.8050200@xs4all.nl> Ahmed Barakat wrote: > In case I have a huge datastore (10000 entries, each entry has like 6 > properties) Can you show some sample entries? That way we can get an idea how your datastore looks like. By the way, 10000 doesn't sound that much. At work I create python programs which do data processing and ofter have this much entries in a dictionary, often more. > Is the conversion to XML a good solution, or it is not? XML is meant to be an exchange format; it is not designed for storage or fast retrieval. Greetings, -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From gatti at dsdata.it Tue Nov 3 10:00:39 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 3 Nov 2009 07:00:39 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: <745e918b-ac0e-4486-93a4-e002bf27ddbf@c3g2000yqd.googlegroups.com> On Nov 3, 11:37?am, Steven D'Aprano wrote: > On Tue, 03 Nov 2009 02:11:59 -0800, Lorenzo Gatti wrote: [...] > Are you saying that now that comp.lang.python and stackoverflow exists, > there no more room in the world for any more Python forums? > > I think that's terrible. Although there is a high barrier to entry for general Python forums, it is not a problem because the door is always open for specialized forums that become the natural "home" of some group or thought leader or of some special interest, for example the forum of a new software product or of the fans of an important blog. Unfortunately, pyfora.org has neither a distinct crowd behind it nor an unique topic, and thus no niche to fill; it can only contribute fragmentation, which is unfortunate because Saketh seems enthusiastic. What in some fields (e.g. warez forums or art boards) would be healthy redundancy and competition between sites and forums becomes pure fragmentation if the only effect of multiple forums is to separate the same questions and opinions that would be posted elsewhere from potential readers and answerers. Reasonable people know this and post their requests for help and discussions either in the same appropriate places as everyone else or in random places they know and like; one needs serious personal issues to abandon popular forums for obscure ones. > Saketh, would you care to give a brief explanation for sets your forum > apart from the existing Python forums, and why people should choose to > spend time there instead of (or as well as) the existing forums? What > advantages does it have? That's the point, I couldn't put it better. > > It would be the Internet equivalent of looking for a poker tournament in > > a desert valley instead of driving half an hour less and going to Las > > Vegas: > > [...] > How about avoiding the noise and obtrusive advertising and bright lights > of Las Vegas, the fakery, the "showmanship", > [...] > if you're interested in poker without all the mayonnaise, maybe > that poker tournament away from the tourists is exactly what you need. I didn't explain my similitude clearly: I was comparing the fitness for purpose of going to Las Vegas with a plan to gamble with the absurdity of stopping, say, at an isolated gas station in the hope of finding a poker tournament there. If you are hinting that popular newsgroups and forums might be so full of fakery, showmanship, mayonnaise, etc. to deserve secession, it's another topic. Regards, Lorenzo Gatti From Scott.Daniels at Acm.Org Tue Nov 3 10:04:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Nov 2009 07:04:41 -0800 Subject: list comprehension problem In-Reply-To: References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> Message-ID: Terry Reedy wrote: > What immutability has to do with identity is that 'two' immutable > objects with the same value *may* actually be the same object, > *depending on the particular version of a particular implementation*. > >> >>>>> t1 = (1,2,3) # an immutable object >>>>> t2 = (1,2,3) # another immutable object > > Whether or not this is 'another' object or the same object is irrelevant > for all purposes except identity checking. It is completely up to the > interpreter. > >>>>> t1 is t2 >> False > > In this case, but it could have been True. > >>>>> t1 == t2 >> True A more telling example: >>> t1 = (1, 2) + (3,) # an immutable object >>> t2 = (1,) + (2, 3) # another immutable object >>> t1 is t2 >> False >>>>> t1 is t2 >> False Here you make obvious that (assuming an optimizer that is not far more aggressive than Python is used to), in order to make equal immutable values identical, you'd have to end each operation producing an immutable result with a search of all appropriately typed values for one that was equal. --Scott David Daniels Scott.Daniels at Acm.Org From gh at ghaering.de Tue Nov 3 10:05:21 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 03 Nov 2009 16:05:21 +0100 Subject: Pyfora, a place for python In-Reply-To: <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> Message-ID: Lorenzo Gatti wrote: > On Nov 1, 8:06 am, Saketh wrote: >> Hi everyone, >> >> I am proud to announce the release of Pyfora (http://pyfora.org), an >> online community of Python enthusiasts to supplement comp.lang.python >> and #python. While the site is small right now, please feel free to >> register and post any questions or tips you may have. > > I'll feel free to not even bookmark it. I'm sorry, but it is just a > bad idea. [...] I agree. > Your forum cannot (and should not) compete either with Python's > official newsgroup, IRC channel and mailing list or with popular, well- > made and well-frequented general programming sites like > stackoverflow.com. [...] The good thing is, unless something the announced new forum gets critical mass, it will just slowly (or not-so-slowly die). But even though I'm an old-timer who still prefers newsgroups/mailing lists, I think that there should be something better, browser based. In particular supporting moderation/voting and tagging/filtering. -- Gerhard From simon.hibbs at gmail.com Tue Nov 3 10:17:40 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 3 Nov 2009 07:17:40 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> <4e6ad15b-4f6d-463b-872a-44b400a4edaf@a37g2000prf.googlegroups.com> Message-ID: <1fecf2f6-58a5-43e4-8f03-deab170ffa8f@a32g2000yqm.googlegroups.com> On 3 Nov, 01:14, Collin D wrote: > Thanks for the replies. Pyparsing looks just like what I need. The cmd module in the standard library is fine for simple command interpreters. Depending on your needs you might find it does what you want. Doug Hellmann has covered it in his "Python module of the week" series of articles. http://www.doughellmann.com/PyMOTW/cmd/index.html Simon Hibbs From james at agentultra.com Tue Nov 3 10:22:28 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 03 Nov 2009 10:22:28 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> Message-ID: <87tyxbws3v.fsf@agentultra.com> Ben Finney writes: > J Kenneth King writes: > >> Steven D'Aprano writes: >> >> > from operator import add >> > map(add, operandlist1, operandlist2) >> >> This is the best solution so far. > > Strange to say it's a solution, when it doesn't solve the stated > problem: to replace use of ?map()? with a list comprehension. Granted I admit this later in my post. It's not a solution to the OPs request, but it is the best solution to such a case. > >> I understand the OP was asking for it, but list comprehensions aren't >> the best solution in this case... it would just be line noise. > > I disagree; a list comprehension is often clearer than use of ?map()? > with a lambda form, and I find it to be so in this case. The use of map expresses a value and implies the procedure by which it is obtained. The list comprehension expresses the procedure by which the value is obtained. Both have uses and in some cases a list comprehension is definitely preferrable to a map operation. However in this case the procedure by which we derive the value is not important or even interesting. It is much more succinct to think of the operation as a value and express it accordingly. There's no need to clutter the mind with extra name bindings and iteration keywords. They won't make our idea any more clear. dot_product = map(mul, vec1, vec2) vs dot_product = [a * b for a, b in zip(vec1, vec2)] It's very clear, at least to me, what a dot-product is in this case. Adding in the loop construct and name bindings doesn't enhance my understanding of what a dot-product is. I don't need to see the loop construct at all in this case. A dot product is simply the multiplication of each element in a vector sequence. It's more succinct to simply think of the value rather then expressing the procedure to construct that value. This isn't a hammer issue. Not every problem is a nail. From asksolem at gmail.com Tue Nov 3 10:29:10 2009 From: asksolem at gmail.com (Ask Solem) Date: Tue, 3 Nov 2009 07:29:10 -0800 (PST) Subject: import bug References: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> Message-ID: On Nov 3, 1:52?am, Carl Banks wrote: > On Oct 31, 7:12?am, kj wrote: > > > > > > > I'm running into an ugly bug, which, IMHO, is really a bug in the > > design of Python's module import scheme. ?Consider the following > > directory structure: > > > ham > > |-- __init__.py > > |-- re.py > > `-- spam.py > > > ...with the following very simple files: > > > % head ham/*.py > > ==> ham/__init__.py <== > > > ==> ham/re.py <== > > > ==> ham/spam.py <== > > import inspect > > > I.e. only ham/spam.py is not empty, and it contains the single line > > "import inspect". > > > If I now run the innocent-looking ham/spam.py, I get the following > > error: > > > % python26 ham/spam.py > > Traceback (most recent call last): > > ? File "ham/spam.py", line 1, in > > ? ? import inspect > > ? File "/usr/local/python-2.6.1/lib/python2.6/inspect.py", line 35, in > > ? ? import string > > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 122, in > > ? ? class Template: > > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in __init__ > > ? ? 'delim' : _re.escape(cls.delimiter), > > AttributeError: 'module' object has no attribute 'escape' > > > or, similarly, > > > % python3 ham/spam.py > > Traceback (most recent call last): > > ? File "ham/spam.py", line 1, in > > ? ? import inspect > > ? File "/usr/local/python-3.0/lib/python3.0/inspect.py", line 36, in > > ? ? import string > > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 104, in > > ? ? class Template(metaclass=_TemplateMetaclass): > > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 98, in __init__ > > ? ? 'delim' : _re.escape(cls.delimiter), > > AttributeError: 'module' object has no attribute 'escape' > > > My sin appears to be having the (empty) file ham/re.py. ?So Python > > is confusing it with the re module of the standard library, and > > using it when the inspect module tries to import re. > > Python is documented as behaving this way, so this is not a bug. > > It is arguably poor design. ?However, Guido van Rossum already ruled > against using a single package for the standard library, and its not > likely that special case code to detect accidental name-clashes with > the standard library is going to be added, since there are legitimate > reasons to override the standard library. > > So for better or worse, you'll just have to deal with it. > > Carl Banks Just have to add that you're not just affected by the standard library. If you have a module named myapp.django, and someone writes a cool library called django that you want to use, you can't use it unless you rename your local django module. file myapp/django.py: from django.utils.functional import curry ImportError: No module named utils.functional At least that's what I get, maybe there is some workaround, some way to say this is an absolute path? From jaime.buelta at gmail.com Tue Nov 3 10:43:11 2009 From: jaime.buelta at gmail.com (Jaime Buelta) Date: Tue, 3 Nov 2009 07:43:11 -0800 (PST) Subject: Why do you use python? References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> <78f78eb9-bee0-4472-b758-5042919454c6@k19g2000yqc.googlegroups.com> Message-ID: <868d533a-c7b5-43ae-a1fb-67cfb855b4ec@v25g2000yqk.googlegroups.com> On 1 nov, 08:54, Dennis Lee Bieber wrote: > On Sat, 31 Oct 2009 06:54:27 -0700 (PDT), Jaime Buelta > declaimed the following in > gmane.comp.python.general: > > > shouldn't be heard. Talks a guy that programmed a GUI on Motif using C > > (plain old C) in 2003 and takes almost forever (one year and a half), > > ? ? ? ? Lucky you... > > ? ? ? ? I emulated a Ramtek 9300 (think that was the model) graphics engine > using GKS (for display lists, and ability to turn "layers" on/off > without regenerating all the data) on top of plain DECWindows/Xt > library, with no layout utility. Around 1990 (I date it by the fact > that, on return from the 7 week two site deployment of the application, > I decided my old cameras had gotten too burdensome, and bought a Canon > EOS 10s, 35-105 & 100-300 lenses, and a photo vest that I could wear > onto the flights) > > ? ? ? ? Emulation was needed as the data generation program had to have > minimal changes -- we replaced the Ramtek library with a package that > formatted the Ramtek instructions as text strings, sent them via VAX/VMS > mailboxes to the emulation program... Oh, and the main data generation > program really was a set of some 50 programs that were invoked in > "random" order, each drawing certain data elements onto a single window > -- so there had to be a common graphics application to maintain the > window... > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? HTTP://wlfraed.home.netcom.com/ Hahahaha, I souposse that I must consider myself EXTREMELY lucky... ;-) Anyway, each tool has its time, and we should try to use more-or-less adequate and available tools of our time... From elpostssv at rediffmail.com Tue Nov 3 10:43:20 2009 From: elpostssv at rediffmail.com (Siva Subramanian) Date: 3 Nov 2009 15:43:20 -0000 Subject: =?utf-8?B?cHl0aG9uIGNvbXBhcmUgYW5kIHByb2Nlc3MgYSBjc3YgZmlsZQ==?= Message-ID: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Hello all,   I am new on this list and computer programming   I have two distinct statistical files (both csv) 1.       Report_2_5 ? this is a report dump containing over a 10 million records and is different every day 2.       Customer_id dump ? this is a daily dump of customers who have made payments. This is generally a million record I need to extract past history depending on customers who make regular payments For example, Report_2_5   Customer ID, Plan_NO, stat1, vol2, amount3 2134, Ins1, 10000, 20000, 10 2112, Ins3, 30000, 20000, 10 2121, Ins3, 30000, 20000, 10 2145, Ins2, 15000, 10000, 5 2245, Ins2, 15000, 10000, 5 0987, Ins1, 10000, 20000, 10 4546, Ins1, 10020, 21000, 10 6757, Ins1, 10200, 22000, 10 ? customer_id dump   0987 4546 6757 2134 I need to process the Report_2_5 and extract the following output Stat1: 40220 Vol2 : 83000 Amount3 : 40   I am new to programming and I have been extracting this data using MS ? Access and I badly need a better solution.   Will really appreciate any sample code in python.   Thanks in advance Siva -------------- next part -------------- An HTML attachment was scrubbed... URL: From mario.ruggier at gmail.com Tue Nov 3 10:50:22 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Tue, 3 Nov 2009 07:50:22 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <880dece00910271211l5e1ecf89i1d2b85c930998689@mail.gmail.com> <7kp7brF3an909U1@mid.uni-berlin.de> <880dece00910280118j14f40763k60cd376425b8d9c@mail.gmail.com> <7kqgg4F3aqqf9U1@mid.uni-berlin.de> <6f7e015d-deba-499b-bc5d-66c0a35610b0@y23g2000yqd.googlegroups.com> Message-ID: With respect to to original question regarding web frameworks + database and Python 3, all the following have been available for Python 3 since the day Python 3.0 was released: QP, a Web Framework http://pypi.python.org/pypi/qp/ Durus, a Python Object Database (the "default" in qp, for user sessions, etc) http://pypi.python.org/pypi/Durus/ Evoque, state-of-the-art templating engine http://pypi.python.org/pypi/evoque/ (this one is available for py3.0 since a little later, 21-jan-2009) All the above also runs on python 2.4 (thru to python 3) For the record, you may see the list of all pypi packages availabe for Python 3 at: http://pypi.python.org/pypi?:action=browse&show=all&c=533 m. From tartley at tartley.com Tue Nov 3 10:58:16 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 3 Nov 2009 07:58:16 -0800 (PST) Subject: comparing alternatives to py2exe Message-ID: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Hi, Recently I put together this incomplete comparison chart in an attempt to choose between the different alternatives to py2exe: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Columns represent methods of deploying to end-users such that they don't have to worry about installing Python, packages or other dependencies. 'Bundle' represents manually bundling an interpreter with your app. 'Bootstrap' represents a fanciful idea of mine to include an installer that downloads and installs an interpreter if necessary. This sounds fiddly, since it would have to install side-by- side with any existing interpreters of the wrong version, without breaking anything. Has anyone done this? The remaining columns represent the projects out there I could find which would do the bundling for me. Are there major things I'm missing or misunderstanding? Perhaps folks on the list would care to rate (+1/-1) rows that they find important or unimportant, or suggest additional rows that would be important to them. Maybe an updated and complete version of this table would help people agree on what's important, and help the various projects to improve faster. Best regards, Jonathan From fetchinson at googlemail.com Tue Nov 3 10:58:30 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 3 Nov 2009 16:58:30 +0100 Subject: Pyfora, a place for python In-Reply-To: <87my33heq1.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: >> I was referring to this comment by Ben: >> >> "Suggestion: Please don't make efforts to fragment the community." >> >> This IMHO is hostile, because it presupposes that the mere goal of the >> OP is fragmenting the community > > It presupposes nothing of any goal. It describes a predictable result of > the OP's efforts, and requests those efforts to cease. > > So I deny the characterisation of that request as hostile. Probably this thread is going by far too far :) but let's see this again, If A says to B "please don't do X" then A assumes that B does X. Otherwise the request of A doesn't make sense, since it doesn't make sense to ask somebody not to do something that he/she is not doing. Agreed? If no, please explain why you don't agree. If yes, then I guess we will also agree that if A says to B "please don't make efforts to do X" then request of A only makes sense if B makes an effort to do X. Agreed? If no, please explain why. If yes, great, let's continue! If A says to B "please don't make efforts to fragment the community" then this request from A only makes sense if B makes an effort to fragment the community. Agreed? If no, why not? If yes, we are almost there! In our example the request of A only makes sense if B is making an effort to fragment the community, in other words, assuming that A tries to make a meaningful request, A is assuming that B is making an effort to fragment the community. Agreed? If not, why not? If yes, with the substitution A = Ben and B = OP we get "in order for Ben's request to make sense, Ben has to assume that the OP is making an effort to fragment the community". This assumption on the part of Ben, I think, is hostile, since it assumes that the OP is making an effort to do something not nice. Whether the OP is indeed doing something not nice, is irrelevant. If the OP does do something not nice, the hostility is warranted. If the OP is not doing anything not nice, the hostility is unwarranted. But the fact that Ben was hostile is a fact :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From SD_V897 at NoSuchMail.Com Tue Nov 3 11:00:16 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Tue, 03 Nov 2009 16:00:16 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) Message-ID: I have a perplexing issue, I have four users set up on a W7 computer. The program runs fine for all users except the admin user who needs it for school assignments. It's not a firewall issue as I've added localhost for pythomw.exe as allow. I've done some data dumps using sysinternals process monitor and the working users create a 7.8mb dump file and the file for the broken user is only 1.04mb. I can send the zipped data dumps (XML) 384kb if someone could have a look. Python 2.6 Thanks SD From deets at nospam.web.de Tue Nov 3 11:17:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 17:17:55 +0100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: <7lb3dkF3cuvhqU1@mid.uni-berlin.de> >> Since when is the mere suggestion that fragmentation will occur and if >> that's a desirable consequence is hostile? The OP is not bound to it, >> and I also don't see the tone used by the two immediate answerers being >> hostile. Paul might have been terse - but hostility looks different IMHO. > > I was referring to this comment by Ben: > > "Suggestion: Please don't make efforts to fragment the community." > > This IMHO is hostile, because it presupposes that the mere goal of the > OP is fragmenting the community, which is something negative, i.e. it > contains negative prejudice. What I would have written in Ben's place: > > Have you considered the possibility that your website will further > fragment the community? > > This wouldn't have been hostile, IMHO. Well, this is *deep* into the realms of semantics and dialectics. To an extend that personal prejudice would change the perception of the sentence. If everything posted here (and elsewhere) had to be worded so carefully, we'd hardly discussing anything at all. > Competent people will only move away if the website is > great/fun/useful/etc. In which case we should welcome it, since > something great/fun/useful/etc is a good thing. If it's not > great/fun/useful/etc competent people will not move away, in which > case c.l.p. will not be any worse as a result of launching the new > website. There is not only the problem of people moving away - but also of them not even finding *this* place to discuss because they found pyfora first, and thus the "danger" of them getting not the good answers they are looking for. This sometimes already happens, if one of the google ad farms out there that tries to lure people onto their pages simply reproduces c.l.py content - and people believe it's a genuine forum - and wonder why they don't get answers there. > Welcome to open source, the world of infinitely many forks, code > variants, MLs, forums, NGs, websites, in other words, welcome to the > bazaar! Oh please. If every dissent on the direction of an open-source project (or commercial one) would lead to forking, we'd end up with a lot of projects which none of them being competitive and mature. So can we scrap this straw-man of an argument? Diez From mkhitrov at gmail.com Tue Nov 3 12:08:59 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 3 Nov 2009 12:08:59 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <26ddd1750911030908k71684060veded53ee36a2314@mail.gmail.com> On Tue, Nov 3, 2009 at 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > Columns represent methods of deploying to end-users such that they > don't have to worry about installing Python, packages or other > dependencies. 'Bundle' represents manually bundling an interpreter > with your app. 'Bootstrap' represents a fanciful idea of mine to > include an installer that downloads and installs an interpreter if > necessary. This sounds fiddly, since it would have to install side-by- > side with any existing interpreters of the wrong version, without > breaking anything. Has anyone done this? Maybe there is a way to use Portable Python for this, but I have no experience with it. > The remaining columns represent the projects out there I could find > which would do the bundling for me. > > Are there major things I'm missing or misunderstanding? > > Perhaps folks on the list would care to rate (+1/-1) rows that they > find important or unimportant, or suggest additional rows that would > be important to them. Maybe an updated and complete version of this > table would help people agree on what's important, and help the > various projects to improve faster. > > Best regards, > > ?Jonathan Good work. Recently I played with cx_freeze and compared it to py2exe, which I've been using for a while. Here are my findings: 1. I don't think cx_freeze supports single exe. I haven't even been able to get it to append the generated library.zip file to the executable using documented options. Other things like .pyd files always seem to be separate. At the same time, singe executables generated by py2exe do not always work. I have a program that works fine on Windows XP, Vista, and 7 if it is built under XP. However, if I build the exact same program under Windows 7, it no longer works on Vista or XP. I'm sure it has something to do with SxS or other dll issues. 2. For output directory structure, you are able to specify where to put the generated executable and all of its dependencies with both py2exe and cx_freeze. You cannot do things like put python26.dll in a separate directory from the executable. Not sure if that is what you are referring to. 3. py2exe does not support Python 3 (unfortunately). 4. Although cx_freeze does support optimization (-O), it's a bit broken in that the __debug__ variable is always set to True. In other words, the code is optimized and things like assert statements are not executed, but conditional statements that check __debug__ == True are. I know that py2exe does not have this problem, no experience with other tools. 5. py2exe is capable of generating smaller executables than cx_freeze because of the base executable size (18.5 KB vs 1.35 MB). This is offset by the fact that py2exe saves many more standard library components to library.zip by default. In a quick test I just ran, both generated a package of 4.03 MB, but I can remove at least a meg from py2exe's library.zip. Rather than "distribution size", I think it makes more sense to show "overhead" above the required components (exclude minimal library.zip, python dll, and pyd files). 6. cx_freeze is as easy to use as py2exe after looking at the bundled examples. - Max From robert.kern at gmail.com Tue Nov 3 12:35:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 Nov 2009 11:35:51 -0600 Subject: Python-URL! - weekly Python news and links (Nov 3) In-Reply-To: References: Message-ID: On 2009-11-03 07:29 AM, Cameron Laird wrote: > QOTW: "I consider "import *" the first error to be fixed ..." - > Robert > Kern, author of PyFlakes, a potential replacement for Pylint and > Pychecker, > on his personal style > http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 I am not the author of PyFlakes. That distinction belongs to Phil Frost and others at Divmod. -- 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 mccredie at gmail.com Tue Nov 3 12:49:43 2009 From: mccredie at gmail.com (Matt McCredie) Date: Tue, 3 Nov 2009 17:49:43 +0000 (UTC) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: iu2 elbit.co.il> writes: > > Hi, > > Having a file called funcs.py, I would like to read it into a string, > and then import from that string. > That is instead of importing from the fie system, I wonder if it's > possible to eval the text in the string and treat it as a module. > > For example > > with file('funcs.py') as f: txt = r.read() > string_import(txt, 'funcs') # is string_import possible? > > to have now a module called funcs with the functions defined in > funcs.py. You can do something like this: import types import sys mymodule = types.ModuleType("mymodule", "Optional Doc-String") with file('funcs.py') as f: txt = f.read() exec txt in globals(), mymodule.__dict__ sys.modules['mymodule'] = mymodule Note that you shouldn't exec untrusted code. You might also look at the __import__ funciton, which can import by python path. You might also look at the imp module. Matt From ethan at stoneleaf.us Tue Nov 3 12:59:32 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 09:59:32 -0800 Subject: self.__dict__ tricks In-Reply-To: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: <4AF06F84.2030302@stoneleaf.us> Simon Brunning wrote: > 2009/11/1 Steven D'Aprano : > >>The only stupid question is the one you are afraid to ask. > > > I was once asked, and I quote exactly, "are there any fish in the Atlantic sea?" > > That's pretty stupid. ;-) > Are there any fish in the Dead Sea? ~Ethan~ From girishvs at gmail.com Tue Nov 3 14:15:39 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:15:39 -0800 Subject: Freezing python files into executables Message-ID: Hello, I have been using freeze.py on 32 bit linux distributions without a problem. But recently I tried to do the same on RHEL5 x86_64 and ran into some issues. 1) When I ran the script, I got Error: needed directory /usr/lib/python2.4/config not found 2) Then I "yum install python-devel" which installed python-devel.i386 and python-devel.x86_64. Then when I tried freezing, it worked but make barfed up a bunch of errors during ld like /usr/bin/ld: warning: i386 architecture of input file `/usr/lib/python2.4/config/libpython2.4.a(rangeobject.o)' is incompatible with i386:x86-64 output and /usr/lib/python2.4/config/libpython2.4.a(posixmodule.o): In function `posix_getcwd': (.text+0x53a1): undefined reference to `PyEval_RestoreThread' 3) I tried uninstalling python-devel.i386 (retaining only the x86_64) and freeze fails with the same error message as in 1 Any help with this is greatly appreciated. Thanks From rami.chowdhury at gmail.com Tue Nov 3 14:21:19 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 11:21:19 -0800 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian wrote: > Hello, > I have been using freeze.py on 32 bit linux distributions without a > problem. But recently I tried to do the same on RHEL5 x86_64 and ran > into some issues. > > 1) When I ran the script, I got > Error: needed directory /usr/lib/python2.4/config not found > I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From girishvs at gmail.com Tue Nov 3 14:25:17 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:25:17 -0800 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: Hi Rami, Thanks for pointing this out. I did see that point - but apart from installing python-devel (which has created and populated /usr/lib64/python2.4/...) I am not sure what I should do - is there some setting in python where I can ask it to look at lib64 instead of lib? Thanks. On Tue, Nov 3, 2009 at 11:21 AM, Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian > wrote: > >> Hello, >> I have been using freeze.py on 32 bit linux distributions without a >> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >> into some issues. >> >> 1) When I ran the script, I got >> Error: needed directory /usr/lib/python2.4/config not found >> > > I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL, > Fedora, etc) it should be /usr/lib64/python2.4/config :-) > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > From mal at egenix.com Tue Nov 3 14:32:35 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 20:32:35 +0100 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: <4AF08553.70406@egenix.com> Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian > wrote: > >> Hello, >> I have been using freeze.py on 32 bit linux distributions without a >> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >> into some issues. >> >> 1) When I ran the script, I got >> Error: needed directory /usr/lib/python2.4/config not found >> > > I don't know anything about freeze.py but on 64-bit Red Hat distros > (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) This sounds a lot like a missing Python devel RPM. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 girishvs at gmail.com Tue Nov 3 14:35:11 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:35:11 -0800 Subject: Freezing python files into executables In-Reply-To: <4AF08553.70406@egenix.com> References: <4AF08553.70406@egenix.com> Message-ID: Hey Marc-Andre, Ummm - I have installed python-devel.x86_64 and checked that the /usr/lib64/python2.4/ is populated - anything else I can/shuld do to check/ensure the the devel rpm is installed? Thanks. On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: > Rami Chowdhury wrote: >> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >> wrote: >> >>> Hello, >>> I have been using freeze.py on 32 bit linux distributions without a >>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>> into some issues. >>> >>> 1) When I ran the script, I got >>> Error: needed directory /usr/lib/python2.4/config not found >>> >> >> I don't know anything about freeze.py but on 64-bit Red Hat distros >> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) > > This sounds a lot like a missing Python devel RPM. > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 03 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 sean_mcilroy at yahoo.com Tue Nov 3 14:40:21 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Tue, 3 Nov 2009 11:40:21 -0800 (PST) Subject: chr / ord References: Message-ID: <128a3624-573b-4f7e-83bb-9d41c2c7cb7b@c3g2000yqd.googlegroups.com> thanks. that did the trick. in case anyone else is in the same boat as myself, here are the relevant correspondences: string <-> [int] bytes <-> [int] --------------- -------------- lambda string: [ord(x) for x in string] list lambda ints: ''.join([chr(x) for x in ints]) bytes From mal at egenix.com Tue Nov 3 14:47:01 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 20:47:01 +0100 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> Message-ID: <4AF088B5.2070805@egenix.com> Girish Venkatasubramanian wrote: > Hey Marc-Andre, > Ummm - I have installed python-devel.x86_64 and checked that the > /usr/lib64/python2.4/ is populated - anything else I can/shuld do to > check/ensure the the devel rpm is installed? If you have the config/ sub-dir in there, things should be fine. However, it's possible that you need to tweek the freeze.py script a little, since RedHat chose to split the Python installation on x64 in two parts and they may have missed patching freeze.py as well: The platform independent parts are in /usr/lib, whereas the platform dependent parts are in /usr/lib64. Python normally doesn't support this. It only has a prefix and an exec_prefix, but those only allow to do things like prefix=/usr and exec_prefix=/usr64, not changing the lib/ part in /usr/lib/. > Thanks. > > On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >> Rami Chowdhury wrote: >>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>> wrote: >>> >>>> Hello, >>>> I have been using freeze.py on 32 bit linux distributions without a >>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>> into some issues. >>>> >>>> 1) When I ran the script, I got >>>> Error: needed directory /usr/lib/python2.4/config not found >>>> >>> >>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >> >> This sounds a lot like a missing Python devel RPM. >> >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source (#1, Nov 03 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/ >> -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 victorsubervi at gmail.com Tue Nov 3 14:50:10 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 3 Nov 2009 15:50:10 -0400 Subject: Calendar Problem Message-ID: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> Hi; I have the following: import calendar, datetime myCal = calendar.calendar(6) today = datetime.date.today() day = today.day mo = today.month yr = today.year month = myCal.monthdayscalendar(yr, mo) The last line throws errors no matter how I try and tweak it. The current incarnation complains about myCal being a string. What do? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Tue Nov 3 14:54:44 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 11:54:44 -0800 Subject: self.__dict__ tricks In-Reply-To: <4AF06F84.2030302@stoneleaf.us> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> <4AF06F84.2030302@stoneleaf.us> Message-ID: On Tue, 03 Nov 2009 09:59:32 -0800, Ethan Furman wrote: > Simon Brunning wrote: >> 2009/11/1 Steven D'Aprano : >> >>> The only stupid question is the one you are afraid to ask. >> I was once asked, and I quote exactly, "are there any fish in the >> Atlantic sea?" >> That's pretty stupid. ;-) >> > > Are there any fish in the Dead Sea? > Depends on how you define fish, surely ;-)? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From girishvs at gmail.com Tue Nov 3 14:57:17 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:57:17 -0800 Subject: Freezing python files into executables In-Reply-To: <4AF088B5.2070805@egenix.com> References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: I checked and ls /usr/lib64/python2.4/config/ returns config.c config.c.in install-sh libpython2.4.a Makefile makesetup python.o Setup Setup.config Setup.local so I am guessing the python-devel installation went off OK, from what you say. I looked at the freeze.py code and I see your point. But for tweaking, I would need to know what modules should get included from lib64 instead of lib and hardcode them .... Maybe tinkering around with the makefile which is produced by freeze is a better way to go? But since I need to freeze this python code by today, can you suggest any other tool to do this? Thanks. On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: > Girish Venkatasubramanian wrote: >> Hey Marc-Andre, >> Ummm - I have installed python-devel.x86_64 and checked that the >> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >> check/ensure the the devel rpm is installed? > > If you have the config/ sub-dir in there, things should be > fine. > > However, it's possible that you need to tweek the freeze.py > script a little, since RedHat chose to split the Python > installation on x64 in two parts and they may have missed > patching freeze.py as well: > > The platform independent parts are in /usr/lib, whereas the > platform dependent parts are in /usr/lib64. > > Python normally doesn't support this. It only has a > prefix and an exec_prefix, but those only allow to do > things like prefix=/usr and exec_prefix=/usr64, not > changing the lib/ part in /usr/lib/. > >> Thanks. >> >> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>> Rami Chowdhury wrote: >>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>> wrote: >>>> >>>>> Hello, >>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>> into some issues. >>>>> >>>>> 1) When I ran the script, I got >>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>> >>>> >>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>> >>> This sounds a lot like a missing Python devel RPM. >>> >>> -- >>> Marc-Andre Lemburg >>> eGenix.com >>> >>> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >>> > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 03 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 klich.michal at gmail.com Tue Nov 3 15:12:15 2009 From: klich.michal at gmail.com (=?utf-8?q?Micha=C5=82_Klich?=) Date: Tue, 3 Nov 2009 21:12:15 +0100 Subject: Calendar Problem In-Reply-To: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> Message-ID: <200911032112.15288.klich.michal@gmail.com> Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): > Hi; > I have the following: > > import calendar, datetime > > myCal = calendar.calendar(6) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > month = myCal.monthdayscalendar(yr, mo) > > The last line throws errors no matter how I try and tweak it. The current > incarnation complains about myCal being a string. What do? > TIA, > Victor > You should use myCal = calendar.Calendar(6) This creates calendar.Calendar object. -- Micha? Klich klich.michal at gmail.com michal at michalklich.com http://www.michalklich.com From rami.chowdhury at gmail.com Tue Nov 3 15:31:07 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 12:31:07 -0800 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian wrote: > I checked and ls /usr/lib64/python2.4/config/ returns > config.c config.c.in install-sh libpython2.4.a Makefile makesetup > python.o Setup Setup.config Setup.local > > so I am guessing the python-devel installation went off OK, from what > you say. > > I looked at the freeze.py code and I see your point. But for tweaking, > I would need to know what modules should get included from lib64 > instead of lib and hardcode them .... > Maybe tinkering around with the makefile which is produced by freeze > is a better way to go? > > But since I need to freeze this python code by today, can you suggest > any other tool to do this? > I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ; can you try just changing the directory freeze.py looks at to 'lib64', and see if the freeze works? > > On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: >> Girish Venkatasubramanian wrote: >>> Hey Marc-Andre, >>> Ummm - I have installed python-devel.x86_64 and checked that the >>> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >>> check/ensure the the devel rpm is installed? >> >> If you have the config/ sub-dir in there, things should be >> fine. >> >> However, it's possible that you need to tweek the freeze.py >> script a little, since RedHat chose to split the Python >> installation on x64 in two parts and they may have missed >> patching freeze.py as well: >> >> The platform independent parts are in /usr/lib, whereas the >> platform dependent parts are in /usr/lib64. >> >> Python normally doesn't support this. It only has a >> prefix and an exec_prefix, but those only allow to do >> things like prefix=/usr and exec_prefix=/usr64, not >> changing the lib/ part in /usr/lib/. >> >>> Thanks. >>> >>> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>>> Rami Chowdhury wrote: >>>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>>> wrote: >>>>> >>>>>> Hello, >>>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>>> into some issues. >>>>>> >>>>>> 1) When I ran the script, I got >>>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>>> >>>>> >>>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>>> >>>> This sounds a lot like a missing Python devel RPM. >>>> >>>> -- >>>> Marc-Andre Lemburg >>>> eGenix.com >>>> >>>> Professional Python Services directly from the Source ?(#1, Nov 03 >>>> 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/ >>>> >> >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >> -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From israelu at elbit.co.il Tue Nov 3 15:36:08 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 12:36:08 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: On Nov 3, 7:49?pm, Matt McCredie wrote: > iu2 elbit.co.il> writes: > > > > > Hi, > > > Having a file called funcs.py, I would like to read it into a string, > > and then import from that string. > > That is instead of importing from the fie system, I wonder if it's > > possible to eval the text in the string and treat it as a module. > > > For example > > > with file('funcs.py') as f: txt = r.read() > > string_import(txt, 'funcs') ?# is string_import possible? > > > to have now a module called funcs with the functions defined in > > funcs.py. > > You can do something like this: > > import types > import sys > > mymodule = types.ModuleType("mymodule", "Optional Doc-String") > > with file('funcs.py') as f: > ? ? txt = f.read() > exec txt in globals(), mymodule.__dict__ > sys.modules['mymodule'] = mymodule > > Note that you shouldn't exec untrusted code. > You might also look at the __import__ funciton, which can import by python path. > You might also look at the imp module. > > Matt Thanks, it seems simpler than I thought. I don't fully understand , though, the exec statement, how it causes the string execute in the context of mymodule. From ethan at stoneleaf.us Tue Nov 3 15:42:05 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 12:42:05 -0800 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: <4AF0959D.2020307@stoneleaf.us> Daniel Fetchinson wrote: >>>I was referring to this comment by Ben: >>> >>>"Suggestion: Please don't make efforts to fragment the community." >>> >>>This IMHO is hostile, because it presupposes that the mere goal of the >>>OP is fragmenting the community >> >>It presupposes nothing of any goal. It describes a predictable result of >>the OP's efforts, and requests those efforts to cease. >> >>So I deny the characterisation of that request as hostile. > [mass snippitude] > If yes, with the substitution A = Ben and B = OP we get "in order for > Ben's request to make sense, Ben has to assume that the OP is making > an effort to fragment the community". This assumption on the part of > Ben, I think, is hostile, since it assumes that the OP is making an > effort to do something not nice. Whether the OP is indeed doing > something not nice, is irrelevant. If the OP does do something not > nice, the hostility is warranted. If the OP is not doing anything not > nice, the hostility is unwarranted. But the fact that Ben was hostile > is a fact :) You were doing fine until you brought in the hostility. I must agree with Ben that his comment was not hostile. It was merely a statement. Not an exclamation, no name calling, just a plain request rooted in reality. And that's a fact. ;-) Shall we now discuss the nature of the space/time continuum and the exact reality of quarks? ~Ethan~ From israelu at elbit.co.il Tue Nov 3 15:50:42 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 12:50:42 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> On Nov 3, 5:58?pm, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > Columns represent methods of deploying to end-users such that they > don't have to worry about installing Python, packages or other > dependencies. 'Bundle' represents manually bundling an interpreter > with your app. 'Bootstrap' represents a fanciful idea of mine to > include an installer that downloads and installs an interpreter if > necessary. This sounds fiddly, since it would have to install side-by- > side with any existing interpreters of the wrong version, without > breaking anything. Has anyone done this? > > The remaining columns represent the projects out there I could find > which would do the bundling for me. > > Are there major things I'm missing or misunderstanding? > > Perhaps folks on the list would care to rate (+1/-1) rows that they > find important or unimportant, or suggest additional rows that would > be important to them. Maybe an updated and complete version of this > table would help people agree on what's important, and help the > various projects to improve faster. > > Best regards, > > ? Jonathan Another thing that I think is of interest is whether the application support modifying the version and description of the exe (that is, on Windows, when you right-click on an application and choose 'properties' you view the version number and description of the application, it is a resource inside the exe). I think py2exe supports it. From mkhitrov at gmail.com Tue Nov 3 16:06:34 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 3 Nov 2009 16:06:34 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> Message-ID: <26ddd1750911031306o41b089bcl38afeea03ff18c5d@mail.gmail.com> On Tue, Nov 3, 2009 at 3:50 PM, iu2 wrote: > On Nov 3, 5:58?pm, Jonathan Hartley wrote: >> Hi, >> >> Recently I put together this incomplete comparison chart in an attempt >> to choose between the different alternatives to py2exe: >> >> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... >> >> Columns represent methods of deploying to end-users such that they >> don't have to worry about installing Python, packages or other >> dependencies. 'Bundle' represents manually bundling an interpreter >> with your app. 'Bootstrap' represents a fanciful idea of mine to >> include an installer that downloads and installs an interpreter if >> necessary. This sounds fiddly, since it would have to install side-by- >> side with any existing interpreters of the wrong version, without >> breaking anything. Has anyone done this? >> >> The remaining columns represent the projects out there I could find >> which would do the bundling for me. >> >> Are there major things I'm missing or misunderstanding? >> >> Perhaps folks on the list would care to rate (+1/-1) rows that they >> find important or unimportant, or suggest additional rows that would >> be important to them. Maybe an updated and complete version of this >> table would help people agree on what's important, and help the >> various projects to improve faster. >> >> Best regards, >> >> ? Jonathan > > Another thing that I think is of interest is whether the application > support modifying the version and description of the exe (that is, on > Windows, when you right-click on an application and choose > 'properties' you view the version number and description of the > application, it is a resource inside the exe). I think py2exe supports > it. py2exe supports this, cx_freeze doesn't. - Max From ben+python at benfinney.id.au Tue Nov 3 16:13:24 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 08:13:24 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: <87iqdrgvm3.fsf@benfinney.id.au> Daniel Fetchinson writes: > Probably this thread is going by far too far :) Agreed. -- \ ???????? (The virtuous are not abandoned, they shall | `\ surely have neighbours.) ???? Confucius, 551 BCE ? 479 BCE | _o__) | Ben Finney From girishvs at gmail.com Tue Nov 3 16:23:04 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 13:23:04 -0800 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: Will try that. Meanwhile I went ahead and used cx_freeze and that seems to work OK. Thanks for your help Rami and Marc-Andre. On Tue, Nov 3, 2009 at 12:31 PM, Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian > wrote: > >> I checked and ls /usr/lib64/python2.4/config/ returns >> config.c config.c.in install-sh libpython2.4.a Makefile makesetup >> python.o Setup Setup.config Setup.local >> >> so I am guessing the python-devel installation went off OK, from what you >> say. >> >> I looked at the freeze.py code and I see your point. But for tweaking, >> I would need to know what modules should get included from lib64 >> instead of lib and hardcode them .... >> Maybe tinkering around with the makefile which is produced by freeze >> is a better way to go? >> >> But since I need to freeze this python code by today, can you suggest >> any other tool to do this? >> > > I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ; can > you try just changing the directory freeze.py looks at to 'lib64', and see > if the freeze works? > >> >> On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: >>> >>> Girish Venkatasubramanian wrote: >>>> >>>> Hey Marc-Andre, >>>> Ummm - I have installed python-devel.x86_64 and checked that the >>>> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >>>> check/ensure the the devel rpm is installed? >>> >>> If you have the config/ sub-dir in there, things should be >>> fine. >>> >>> However, it's possible that you need to tweek the freeze.py >>> script a little, since RedHat chose to split the Python >>> installation on x64 in two parts and they may have missed >>> patching freeze.py as well: >>> >>> The platform independent parts are in /usr/lib, whereas the >>> platform dependent parts are in /usr/lib64. >>> >>> Python normally doesn't support this. It only has a >>> prefix and an exec_prefix, but those only allow to do >>> things like prefix=/usr and exec_prefix=/usr64, not >>> changing the lib/ part in /usr/lib/. >>> >>>> Thanks. >>>> >>>> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>>>> >>>>> Rami Chowdhury wrote: >>>>>> >>>>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>>>> wrote: >>>>>> >>>>>>> Hello, >>>>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>>>> into some issues. >>>>>>> >>>>>>> 1) When I ran the script, I got >>>>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>>>> >>>>>> >>>>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>>>> >>>>> This sounds a lot like a missing Python devel RPM. >>>>> >>>>> -- >>>>> Marc-Andre Lemburg >>>>> eGenix.com >>>>> >>>>> Professional Python Services directly from the Source ?(#1, Nov 03 >>>>> 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/ >>>>> >>> >>> -- >>> Marc-Andre Lemburg >>> eGenix.com >>> >>> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >>> > > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > From huili.song at gmail.com Tue Nov 3 16:44:20 2009 From: huili.song at gmail.com (kylin) Date: Tue, 3 Nov 2009 13:44:20 -0800 (PST) Subject: how to remove the punctuation and no need words from paragraphs Message-ID: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> I want to remove all the punctuation and no need words form a string datasets for experiment. I am new to python, please give me some clue and direction to write this code. From patx at patx.me Tue Nov 3 16:52:25 2009 From: patx at patx.me (patx at patx.me) Date: Tue, 3 Nov 2009 16:52:25 -0500 Subject: fastPATX Panther for your speedy web browsing needs! Message-ID: <699f51260911031352s46ec54amcfd71cc10543d8c5@mail.gmail.com> fastPATX Panther is now out! It beats Firefox on startup and is very lightweight you have to try it! Download here: http://bitbucket.org/patx/fastpatx/fastpatx-panther.py -- patx, python gui and web, http://patx.me -------------- next part -------------- An HTML attachment was scrubbed... URL: From WanderingAengus at comcast.net Tue Nov 3 16:58:37 2009 From: WanderingAengus at comcast.net (Jean) Date: Tue, 3 Nov 2009 13:58:37 -0800 (PST) Subject: Can I run a python program from within emacs? References: <892a4877-0391-4386-a14f-b66e1b216d49@m3g2000pri.googlegroups.com> Message-ID: On Nov 1, 10:15?am, rustom wrote: > On Nov 1, 7:20?pm, Robinson wrote: > > > I have also just started with both Aquamacs and Python so I ask for ? > > your patience as well. > > When I evaluate the buffer (C-c C-C) I don't see any response or ? > > output from my python program. Should another buffer open ? > > automatically? Should a terminal window open? > > thanks for your patience. > > Rugbeia Floreat Ubique > > > > On Mar 20, 3:09 pm, jmDesktop wrote: > > > > Hi, I'm trying to learn Python. ?I usingAquamacan emac > > > > implementation with mac os x. ?I have a program. ?If I go to the > > > > command prompt and type pythong myprog.py, it works. ?Can the ? > > > program > > > > be run from within the editor or is that not how development is ? > > > done? > > There are two python modes -- python.el and python-mode.el > Default with emacs is python.el, what comes from/with python is python- > mode.el (needs a download and a couple of lines of setup seehttp://www.emacswiki.org/emacs/PythonMode). I recommend python-mode. > > The key-bindings are different --C-c ! to start interpreter followed > by C-c C-c to exec a file. Perfect! Many thanks... From huili.song at gmail.com Tue Nov 3 17:13:45 2009 From: huili.song at gmail.com (kylin) Date: Tue, 3 Nov 2009 14:13:45 -0800 (PST) Subject: how to remove the same words in the paragraph Message-ID: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> I need to remove the word if it appears in the paragraph twice. could some give me some clue or some useful function in the python. From kyosohma at gmail.com Tue Nov 3 17:28:29 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 3 Nov 2009 14:28:29 -0800 (PST) Subject: Freezing python files into executables References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: On Nov 3, 3:23?pm, Girish Venkatasubramanian wrote: > Will try that. > > Meanwhile I went ahead and used cx_freeze and that seems to work OK. > > Thanks for your help Rami and Marc-Andre. Something that you might want to try in the future is GUI2Exe, which allows you to play with a whole slew of freezing modules: http://code.google.com/p/gui2exe/ I've been using it to make executables on Windows through it's py2exe implementation. ------------------- Mike Driscoll Blog: http://blog.pythonlibrary.org From andreengels at gmail.com Tue Nov 3 17:33:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Tue, 3 Nov 2009 23:33:59 +0100 Subject: how to remove the same words in the paragraph In-Reply-To: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: <6faf39c90911031433g288501efq825d798cd19cd3f7@mail.gmail.com> On Tue, Nov 3, 2009 at 11:13 PM, kylin wrote: > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. Well, it depends a bit on what you call 'the same word' (In the paragraph "Fly fly, fly!" does the word fly occur 0, 1, 2 or 3 times?), but the split() function seems a logical choice to use whatever the answer to that question. -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Tue Nov 3 17:40:26 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2009 23:40:26 +0100 Subject: how to remove the same words in the paragraph References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: kylin wrote: > I want to remove all the punctuation and no need words form a string > datasets for experiment. > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. >>> para = u"""I need to remove the word if it appears in the paragraph twice. could ... some give me some clue or some useful function in the python. ... """ >>> print "\n".join(sorted(set(para.translate(dict.fromkeys(map(ord, ".:,-"))).split()))) I appears clue could function give if in it me need or paragraph python remove some the to twice useful word From NOSPAM_chuckwhite8 at charter.net Tue Nov 3 17:40:30 2009 From: NOSPAM_chuckwhite8 at charter.net (chuck) Date: Tue, 03 Nov 2009 17:40:30 -0500 Subject: unable to compile Python 2.6.4 on AIX using gcc Message-ID: Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX 5.3. Here are the settings: export OBJECT_MODE=64 export AR="ar -X64" export MAKE=/usr/bin/gmake export CC="gcc" export CFLAGS="-maix64 -O2 -g -mcpu=power5" export LDFLAGS="-L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" ../Python-2.6.4/configure --with-gcc --disable-ipv6 --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 make > make_264.log 2>&1 make fails very early with the following error =========== gcc -pthread -c -fno-strict-aliasing -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -IInclude -I../Python-2.6.4/Includ e -I/opt/freeware/include -I/usr/lpp/X11/include/X11 -DPy_BUILD_CORE -o Modules/python.o ../Python-2.6.4/Modules/python.c In file included from ../Python-2.6.4/Include/Python.h:58, from ../Python-2.6.4/Modules/python.c:3: ../Python-2.6.4/Include/pyport.h:685:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config ?)." make: The error code from the last command is 1. =========== I would appreciate any help. Thanks. From python.list at tim.thechases.com Tue Nov 3 17:57:14 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 03 Nov 2009 16:57:14 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: <4AF0B54A.7090602@tim.thechases.com> kylin wrote: > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. Sounds like homework. To fail your class, use this one: >>> p = "one two three four five six seven three four eight" >>> s = set() >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) one two three four five six seven eight which is absolutely horrible because it mutates the set within the list comprehension. The passable solution would use a for-loop to iterate over each word in the paragraph, emitting it if it hadn't already been seen. Maintain those words in set, so your words know how not to be seen. ("Mr. Nesbitt, would you please stand up?") This also assumes your paragraph consists only of words and whitespace. But since you posted your previous homework-sounding question on stripping out non-word/whitespace characters, you'll want to look into using a regexp like "[\w\s]" to clean up the cruft in the paragraph. Neither solution above preserves non white-space/word characters, for which I'd recommend using a re.sub() with a callback. Such a callback class might look something like >>> class Dedupe: ... def __init__(self): ... self.s = set() ... def __call__(self, m): ... w = m.group(0) ... if w in self.s: return '' ... self.s.add(w) ... return w ... >>> r.sub(Dedupe(), p) where I leave the definition of "r" to the student. Also beware of case-differences for which you might have to normalize. You'll also want to use more descriptive variable names than my one-letter tokens. -tkc From gagsl-py2 at yahoo.com.ar Tue Nov 3 18:26:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 20:26:18 -0300 Subject: import bug References: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 12:29:10 -0300, Ask Solem escribi?: > If you have a module named myapp.django, and someone writes a cool > library called > django that you want to use, you can't use it unless you rename your > local django module. > > > file myapp/django.py: > > from django.utils.functional import curry > > ImportError: No module named utils.functional > > At least that's what I get, maybe there is some workaround, some way > to say this is an absolute path? Yes, that's exactly the way to solve it. Either move on to Python 3, or use: from __future__ import absolute_import When absolute imports are in effect, and assuming your code is inside a package, then neither "import re" nor "from django.utils.functional import curry" are affected by your own module names, because those statements imply an absolute import ("absolute" means that the module is searched along sys.path). The only way to import a local file "re.py" is using "from .re import something"; the leading dot means it's a relative import ("relative" means that the module is searched in a single directory: the current package directory and its parents, depending on how many dots are specified) -- Gabriel Genellina From davea at ieee.org Tue Nov 3 18:27:50 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 03 Nov 2009 18:27:50 -0500 Subject: Handling large datastore search In-Reply-To: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> Message-ID: <4AF0BC76.4090908@ieee.org> Ahmed Barakat wrote: > In case I have a huge datastore (10000 entries, each entry has like 6 > properties), what is the best way > to handle the search within such a huge datastore, and what if I want to > make a generic search, for example > you write a word and i use it to search within all properties I have for all > entries? > > Is the conversion to XML a good solution, or it is not? > > sorry for being new to web development, and python. > > Thanks in advance. > > I don't see anything about your query which is specific to web development, and there's no need to be apologetic for being new anyway. One person's "huge" is another person's "pretty large." I'd say 10000 items is pretty small if you're working on the desktop, as you can readily hold all the data in "memory." I edit text files bigger than that. But I'll assume your data really is huge, or will grow to be huge, or is an environment which treats it as huge. When you're parsing large amounts of data, there are always tradeoffs between performance and other characteristics, usually size and complexity. If you have lots of data, you're probably best off by using a standard code system -- a real database. The developers of such things have decades of experience in making certain things fast, reliable, and self-consistent. But considering only speed here, I have to point out that you have to understand databases, and your particular model of database, pretty well to really benefit from all the performance tricks in there. Keeping it abstract, you specify what parts of the data you care about fast random access to. If you want fast search access to "all" of it, your database will generally be huge, and very slow to updates. And the best way to avoid that is to pick a database mechanism that best fits your search mechanism. I hate to think how many man-centuries Google has dedicated to getting fast random word access to its *enormous* database. I'm sure they did not build on a standard relational model. If you plan to do it yourself, I'd say the last thing you want to do is use XML. XML may be convenient way to store self-describing data, but it's not quick to parse large amounts of it. Instead, store the raw data in text form, with separate index files describing what is where. Anything that's indexed will be found rapidly, while anything that isn't will require search of the raw data. There are algorithms for searching raw data that are faster than scanning every byte, but a relevant index will almost always be faster. DaveA From davea at ieee.org Tue Nov 3 18:56:07 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 03 Nov 2009 18:56:07 -0500 Subject: Calendar Problem In-Reply-To: <200911032112.15288.klich.michal@gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> Message-ID: <4AF0C317.3010109@ieee.org> MichaB Klich wrote: > Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): > >> Hi; >> I have the following: >> >> import calendar, datetime >> >> myCal =alendar.calendar(6) >> today =atetime.date.today() >> day =oday.day >> mo =oday.month >> yr =oday.year >> month =yCal.monthdayscalendar(yr, mo) >> >> The last line throws errors no matter how I try and tweak it. The current >> incarnation complains about myCal being a string. What do? >> TIA, >> Victor >> >> > > You should use > > myCal =calendar.Calendar(6) > > This creates calendar.Calendar object. > > Right. But I wanted to tell the OP what to do with an error like this. You should post the actual error traceback, and tell us what version of Python you're using: Traceback (most recent call last): File "M:\Programming\Python\sources\dummy\stuff2.py", line 15, in month = myCal.monthdayscalendar(yr, mo) AttributeError: 'str' object has no attribute 'monthdayscalendar' Now, since it says that myCal is a 'str' object, the next thing you should do is look at the value. I get an actual printable calendar for a year. So clearly, it's not the Calendar object you were looking for. So you need to change from the calendar() function to the Calendar() constructor. DaveA From kee at kagi.com Tue Nov 3 19:01:46 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 16:01:46 -0800 Subject: elementtree XML() unicode In-Reply-To: References: Message-ID: Having an issue with elementtree XML() in python 2.6.4. This code works fine: from xml.etree import ElementTree as et getResponse = u''' bobbleheadcity''' theResponseXml = et.XML(getResponse) This code errors out when it tries to do the et.XML() from xml.etree import ElementTree as et getResponse = u''' \ue58d83\ue89189\ue79c8C \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03''' theResponseXml = et.XML(getResponse) In my real code, I'm pulling the getResponse data from a web page that returns as XML and when I display it in the browser you can see the Japanese characters in the data. I've removed all the stuff in my code and tried to distill it down to just what is failing. Hopefully I have not removed something essential. Why is this not working and what do I need to do to use Elementtree with unicode? Thanks, Kee Nethery From rhodri at wildebst.demon.co.uk Tue Nov 3 19:17:36 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Nov 2009 00:17:36 -0000 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: On Tue, 03 Nov 2009 15:58:30 -0000, Daniel Fetchinson wrote: > If yes, we are almost there! In our example the request of A only > makes sense if B is making an effort to fragment the community, in > other words, assuming that A tries to make a meaningful request, A is > assuming that B is making an effort to fragment the community. You are assuming here that B is intending his efforts to do X, and that A believes this to be the case. That's the assumption where your chain of logic fails; it is entirely possible that A's statement is abridging a chain of logic that B hasn't considered, and that A is making no assumption of any kind concerning B's intent. Say hello to the Law of Unintended Consequences. -- Rhodri James *-* Wildebeest Herder to the Masses From ryan at rfk.id.au Tue Nov 3 19:21:27 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Wed, 04 Nov 2009 11:21:27 +1100 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <1257294087.2819.1.camel@durian> > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > ...snip... > > Are there major things I'm missing or misunderstanding? A quick note - although I haven't tried it out, the latest version of bbfreeze claims to support OSX. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From rhodri at wildebst.demon.co.uk Tue Nov 3 19:29:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Nov 2009 00:29:18 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 wrote: > I have a perplexing issue, I have four users set up on a W7 computer. > The program runs fine for all users except the admin user who needs it > for school assignments. A little more information, please. How does it not work for the admin user? Is there a traceback? What do you get if you try to invoke it from a command line? -- Rhodri James *-* Wildebeest Herder to the Masses From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:31:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:31:27 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel escribi?: > On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: >> You need to give some actual examples of what you are trying to do, and >> what you are expecting to happen. How is initialized() being called? > > Example: Assume a framework which offers common functionality for a > plugin > or a module a user can choose at the beginning. The framework does not > know the concrete type of the plugin so it is possible to extend it by > implementing a well known interface or abstract class. > > The framework reads the plugin directory, loads each module and creates > buttons for each plugin with a callback method for initializing. To use > common functionality of the framework, initialization method takes it as > the parent parameter. Then forget about the code you read in that blog post, doesn't apply to your use case. > I think this listing makes the most sense to you: > > # initialize all plugins > self._plugin_modules = _load_plugins() # imp loading here > LOGGER.debug(ActionProvider.plugins) # print what was loaded > for plugin in ActionProvider.plugins: # create button for each > app_button = gtk.Button(plugin.title) > LOGGER.debug('Title of plugin: %s' % plugin.title) > app_button.connect("clicked", > plugin.initialize(plugin, self), > None) > self.set_canvas(app_button) > app_button.show() Try something like this: --- begin plugin.py --- class Plugin(object): "Every plugin class should have a docstring" def __init__(self, manager): pass --- end plugin.py --- --- begin pluginmgr.py -- import os.path from glob import glob from plugin import Plugin class PluginManager: def __init__(self, plugin_directory): self.plugin_directory = plugin_directory self.plugins = [] def load_all(self): for fn in glob(os.path.join(self.plugin_directory, '*.py')): namespace = {} execfile(fn, namespace) for name, obj in namespace.items(): if (isinstance(obj, type) and issubclass(obj, Plugin) and obj is not Plugin): # obj is a Plugin subclass cls = obj print cls.__name__, fn print cls.__doc__ print plugin = cls(self) # call the constructor self.plugins.append(plugin) if __name__ == '__main__': mgr = PluginManager(r'd:\\temp\\plugins') mgr.load_all() print mgr.plugins --- end pluginmgr.py --- --- begin one.py in the plugins directory --- from plugin import Plugin class MyPlugin(Plugin): """The most wonderful plugin in the world. This plugin does this, and that, and also that, too. It's very nice, I assure you.""" class Second(Plugin): """My second plugin. I don't know what is this for, but it works.""" --- end one.py --- Plugin is the base class; all plugins must inherit from it. PluginMgr scans the plugin directory, executes all modules it finds there (be careful...), and looks for Plugin subclasses. Then creates an instance of each Plugin subclass. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:44:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:44:54 -0300 Subject: elementtree XML() unicode References: Message-ID: En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery escribi?: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > from xml.etree import ElementTree as et > getResponse = u''' > bobblehead city>city''' > theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > from xml.etree import ElementTree as et > getResponse = u''' > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that > returns as XML and when I display it in the browser you can see the > Japanese characters in the data. I've removed all the stuff in my code > and tried to distill it down to just what is failing. Hopefully I have > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree with > unicode? et expects bytes as input, not unicode. You're decoding too early (decoding early is good, but not in this case, because et does the work for you). Either feed et.XML with the bytes before decoding, or reencode the received xml text in UTF-8 (since this is the declared encoding). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:57:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:57:00 -0300 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: En Tue, 03 Nov 2009 10:06:24 -0300, Oltmans escribi?: > Hi, all. All I'm trying to do is to print the error message using the > following code (copying/pasting from IDLE). > > try: > div(5,0) > except Exception as msg: > print msg > > SyntaxError: invalid syntax > > I'm using Python 2.5 on Windows XP. Other people already told you what the problem is. I suggest reading a book/tutorial written for the *same* Python version you're using (2.x; it doesn't matter 2.6, 2.5, 2.4...). Once you know the basics of the language, you may look at the differences in the "What's new?" document for Python 3.0 - but right now, they will just confuse you. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 20:10:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 22:10:51 -0300 Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribi?: > On Nov 3, 7:49 pm, Matt McCredie wrote: >> iu2 elbit.co.il> writes: >> >> > Having a file called funcs.py, I would like to read it into a string, >> > and then import from that string. >> > That is instead of importing from the fie system, I wonder if it's >> > possible to eval the text in the string and treat it as a module. >> mymodule = types.ModuleType("mymodule", "Optional Doc-String") >> with file('funcs.py') as f: >> txt = f.read() >> exec txt in globals(), mymodule.__dict__ >> sys.modules['mymodule'] = mymodule > > Thanks, it seems simpler than I thought. > I don't fully understand , though, the exec statement, how it causes > the string execute in the context of mymodule. Sometimes you don't even require a module, and this is simpler to understand. Suppose you have a string like this: txt = """ def foo(x): print 'x=', x def bar(x): return x + x """ you may execute it: py> namespace = {} py> exec txt in namespace The resulting namespace contains the foo and bar functions, and you may call them: py> namespace.keys() ['__builtins__', 'foo', 'bar'] py> namespace['foo']('hello') x= hello exec just executes the string using the given globals dictionary as its global namespace. Whatever is present in the dictionary is visible in the executed code as global variables (none in this example). The global names that the code creates become entries in the dictionary. (foo and bar; __builtins__ is an implementation detail of CPython). You may supply separate globals and locals dictionaries. -- Gabriel Genellina From kee at kagi.com Tue Nov 3 20:14:28 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 17:14:28 -0800 Subject: elementtree XML() unicode In-Reply-To: References: Message-ID: On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery > escribi?: > >> I've removed all the stuff in my code and tried to distill it down >> to just what is failing. Hopefully I have not removed something >> essential. Sounds like I did remove something essential. > > et expects bytes as input, not unicode. You're decoding too early > (decoding early is good, but not in this case, because et does the > work for you). Either feed et.XML with the bytes before decoding, or > reencode the received xml text in UTF-8 (since this is the declared > encoding). Here is the code that hits the URL: getResponse1 = urllib2.urlopen(theUrl) getResponse2 = getResponse1.read() getResponse3 = unicode(getResponse2,'UTF-8') theResponseXml = et.XML(getResponse3) So are you saying I want to do: getResponse1 = urllib2.urlopen(theUrl) getResponse4 = getResponse1.read() theResponseXml = et.XML(getResponse4) The reason I am confused is that getResponse2 is classified as an "str" in the Komodo IDE. I want to make sure I don't lose the non- ASCII characters coming from the URL. If I do the second set of code, does elementtree auto convert the str into unicode? How do I deal with the XML as unicode when I put it into elementtree as a string? Very confusing. Thanks for the help. Kee From sjmachin at lexicon.net Tue Nov 3 20:27:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 17:27:12 -0800 (PST) Subject: elementtree XML() unicode References: Message-ID: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> On Nov 4, 11:01?am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > ? ? ? from xml.etree import ElementTree as et > ? ? ? getResponse = u''' ? > bobblehead city>city''' > ? ? ? theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > ? ? ? from xml.etree import ElementTree as et > ? ? ? getResponse = u''' ? > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > ? ? ? theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that ? > returns as XML and when I display it in the browser you can see the ? > Japanese characters in the data. I've removed all the stuff in my code ? > and tried to distill it down to just what is failing. Hopefully I have ? > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree ? > with unicode? On Nov 4, 11:01 am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > from xml.etree import ElementTree as et > getResponse = u''' > bobblehead city>city''' > theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > from xml.etree import ElementTree as et > getResponse = u''' > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that > returns as XML and when I display it in the browser you can see the > Japanese characters in the data. I've removed all the stuff in my code > and tried to distill it down to just what is failing. Hopefully I have > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree > with unicode? What you need to do is NOT feed it unicode. You feed it a str object and it gets decoded according to the encoding declaration found in the first line. So take the str object that you get from the web (should be UTF8-encoded already unless the header is lying), and throw that at ET ... like this: | Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> from xml.etree import ElementTree as et | >>> ucode = u''' | ... | ... \ue58d83\ue89189\ue79c8C | ... \ue69f8f\ue5b882 | ... \ue9ab98\ue58d97\ue58fb03 | ... ''' | >>> xml= et.XML(ucode) | Traceback (most recent call last): | File "", line 1, in | File "C:\python26\lib\xml\etree\ElementTree.py", line 963, in XML | parser.feed(text) | File "C:\python26\lib\xml\etree\ElementTree.py", line 1245, in feed | self._parser.Parse(data, 0) | UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d' in position 69: ordinal not in range(128) | # as expected | >>> strg = ucode.encode('utf8') | # encoding as utf8 is for DEMO purposes. | # i.e. use the original web str object, don't convert it to unicode | # and back to utf8. | >>> xml2 = et.XML(strg) | >>> xml2.tag | 'customer' | >>> for c in xml2.getchildren(): | ... print c.tag, repr(c.text) | ... | shipping '\n' | >>> for c in xml2[0].getchildren(): | ... print c.tag, repr(c.text) | ... | state u'\ue58d83\ue89189\ue79c8C' | city u'\ue69f8f\ue5b882' | street u'\ue9ab98\ue58d97\ue58fb03' | >>> By the way: (1) it usually helps to be more explicit than "errors out", preferably the exact copied/pasted output as shown above; this is one of the rare cases where the error message is predictable (2) PLEASE don't start a new topic in a reply in somebody else's thread. From alfps at start.no Tue Nov 3 20:29:21 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 02:29:21 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l942mF3c94mlU1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Alf P. Steinbach schrieb: >> * Diez B. Roggisch: >>>> Your comment about "computed" makes it more clear what that's all >>>> about. >>>> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >>>> called it "referential transparency". But I think when Python has this >>>> nice property mechanism, why do people change direct data attributes >>>> into >>>> properties and not the other way around or not at all, I mean using >>>> only >>>> properties for logical >>>> data attributes -- e.g. assuring correctness first via read-only >>>> property? >>> >>> I fail to see where read-only-ness of an attribute is a priori more >>> correct >>> than having modifyable attributes. >> >> No, I didn't mean that it is more correct to have an attribute as >> read-only. I meant that letting a logical data attribute start out as >> a read only property can help to ensure correctness. > > Which is the same thing said with other words. No, it's two different things. Whether something is correct or not, it can help to ensure correctness. For a different example of that, a formally incorrect debug thing can help to ensure correctness. >> For example, consider two rectangle classes R1 and R2, where R2 might >> be a successor to R1, at some point in system evolution replacing R1. >> R1 has logical data members left, top, width and height, and R2 has >> logical data members left, top, right and bottom. With R1 direct >> changes of left and top keeps the rectangle's size (since that size is >> specified by width and height), while with R2 it changes the >> rectangle's size. R1 is implemented with logical data members as >> directly exposed data attributes. Some code in the system deals only >> with R1 objects and for convenience or efficiency or whatever uses >> direct modification instead of set_position method. Due to new >> requirements it instead has to deal with R2 objects, with same >> methods. But due to the direct modification of object state it now >> changes the rectangle sizes, but at first it's not noticed since the >> attempted rectangle position changes are very small. People get upset. >> The bug is fixed. Time has been wasted. > > If there is need for mutable rectangles, there is need for mutable > rectangles. Using properties instead of attributes doesn't help In the example above using properties would have avoided the problem. Hence your conclusion is wrong. :-) > - if you > change semantics of something, code might break. Yes, but that's totally out of the blue. If you, say, paint your nose bright green, then people might stare at it. That has nothing to do do with anything discussed here, and so anyone mentioning that as purportedly relevant to anything discussed here, would implicitly be saying "I don't understand anything abour it", and that's effectively what you're saying, sorry. However, I do understand what got you confused. Changing the internal representation of a class is not to change the class' semantics. It belongs to the class only. Anyone availing himself or herself of access to that internal representation is doing something that may or may not work in the future and would ideally be doing it at own's risk, but as the example above illustrated, they're most often doing it at *other*'s risk. And so the issue is how to get them to not do it, even when they think that nobody will check their code until next version of Lib XYZ comes in a year... And that's where using properties from the start enters the picture, making it less convenient for those tinkerers to use internal representation details. > In Python, attributes > are part of the public interface as long as you don't explicitly define > them otherwise. Not sure what that refers to. > But preliminary assumptions about what could be in some yet unseen > future is introducing more code with more chances of errors No not really. >, reducing > the flexibility at the same time. I still fail to see where that's good. Yes. Consider the *nix convention for files, that they're just byte streams. They're *restricted* to byte streams. That's darn inflexible, yes? And totally ungood. :-) (Note: irony) > Code for what you need code for. It works - in all languages, but > especially in Python. Whether that's good advice depends on what you're doing and in what kind of job setting you're doing it. For many cases it is, in essence, a very selfish way. It gets down to saving time *now* for increased future maintainance times for others, which of course is the only rational choice /if/ one is sure to get away with it. OK, I'm not antirely serious but it sounds like you're thinking in this way, to some degree. But check out any debate on Python vs. Perl, in particular about maintainability. Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Tue Nov 3 20:53:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 01:53:15 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > However in this case the procedure by which we derive the value is not > important or even interesting. It is much more succinct to think of the > operation as a value and express it accordingly. There's no need to > clutter the mind with extra name bindings and iteration keywords. They > won't make our idea any more clear. > > dot_product = map(mul, vec1, vec2) > > vs > > dot_product = [a * b for a, b in zip(vec1, vec2)] > > It's very clear, at least to me, what a dot-product is in this case. Except it's not. The dot product of two vectors returns a scalar, not another vector: http://en.wikipedia.org/wiki/Dot_product So what you want is: dot_product = sum(map(mul, vec1, vec2)) > Adding in the loop construct and name bindings doesn't enhance my > understanding of what a dot-product is. I don't need to see the loop > construct at all in this case. A dot product is simply the > multiplication of each element in a vector sequence. What you need is to define a function dot-product, and not hijack the name for a local value. Then the function's implementation is irrelevant to you: it could use a list comp, or could use map, it could use a for- loop, a while loop, recursion, or black magic: scalar = dot_product(vec1, vec2) -- Steven From ethan at stoneleaf.us Tue Nov 3 20:53:31 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 17:53:31 -0800 Subject: ANN: python-dBase 0.86 Released! Message-ID: <4AF0DE9B.1020806@stoneleaf.us> Greetings! I am happy to announce the latest release of python-dBase (dbf for short)! At this point it supports dBase III and Visual FoxPro 6 dbf files. It's a bit quicker now since it's using array.array to hold the records and not strings, and the API has been standardized. It also now has much better, though still basic, documentation. It was initially written to ease transition away from vfp files, but we use it here everyday for processing both vfp and dBase files. Drawbacks: * it is not concurrent * it does not support vfp auto-increment nor null fields * entire table is read into memory, so large tables process slowly * non-initialized logical fields show up as False (? ==> False) Advantages: * entire table is read into memory, so small to medium files process quickly * memo fields (reading *and* writing) are supported * :memory: tables can be used to hold result sets from bigger SQL tables to ease data access * custom date, datetime, and time wrappers to support empty date fields * direct translation from dbf field to python data type To-Do: * add an option to not keep all records in memory for large tables * add codepage support * add more dbf formats (dBase IV, V, 7 -- any links to these layouts would be /greatly/ appreciated!) This release is available at PyPI -- just search for dbf! As always, success stories and bug reports desired. Happy Hacking! ~Ethan~ From sjmachin at lexicon.net Tue Nov 3 20:56:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 17:56:38 -0800 (PST) Subject: elementtree XML() unicode References: Message-ID: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> On Nov 4, 12:14?pm, Kee Nethery wrote: > On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > > > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery ? > > escribi?: > > >> I've removed all the stuff in my code and tried to distill it down ? > >> to just what is failing. Hopefully I have not removed something ? > >> essential. > > Sounds like I did remove something essential. No, you added something that was not only inessential but caused trouble. > > et expects bytes as input, not unicode. You're decoding too early ? > > (decoding early is good, but not in this case, because et does the ? > > work for you). Either feed et.XML with the bytes before decoding, or ? > > reencode the received xml text in UTF-8 (since this is the declared ? > > encoding). > > Here is the code that hits the URL: > ? ? ? ? ?getResponse1 = urllib2.urlopen(theUrl) > ? ? ? ? ?getResponse2 = getResponse1.read() > ? ? ? ? ?getResponse3 = unicode(getResponse2,'UTF-8') > ? ? ? ? theResponseXml = et.XML(getResponse3) > > So are you saying I want to do: > ? ? ? ? ?getResponse1 = urllib2.urlopen(theUrl) > ? ? ? ? ?getResponse4 = getResponse1.read() > ? ? ? ? theResponseXml = et.XML(getResponse4) You got the essence. Note: that in no way implies any approval of your naming convention :-) > The reason I am confused is that getResponse2 is classified as an ? > "str" in the Komodo IDE. I want to make sure I don't lose the non- > ASCII characters coming from the URL. str is all about 8-bit bytes. Your data comes from the web in 8-bit bytes. No problem. Just don't palpate it unnecessarily. > If I do the second set of code, ? > does elementtree auto convert the str into unicode? Yes. See the example I gave in my earlier posting: | ... print c.tag, repr(c.text) | state u'\ue58d83\ue89189\ue79c8C' That first u means the type is unicode. > How do I deal with ? > the XML as unicode when I put it into elementtree as a string? That's unfortunately rather ambiguous: (1) put past/present? (2) string unicode/str? (3) what is referent of "it"? All text in what et returns is unicode [*] so you read it out as unicode (see above example) or written as unicode if you want to change it: your_element.text = u'a unicode object' [*] As an "optimisation", et stores strings as str objects if they contain only ASCII bytes (and are thus losslessly convertible to unicode). In preparation for running your code under Python 3.X, it's best to ignore this and use unicode constants u'foo' (if you need text constants at all) even if et would let you get away with 'foo'. HTH, John From kee at kagi.com Tue Nov 3 21:06:58 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 18:06:58 -0800 Subject: elementtree XML() unicode In-Reply-To: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: On Nov 3, 2009, at 5:27 PM, John Machin wrote: > On Nov 4, 11:01 am, Kee Nethery wrote: >> Having an issue with elementtree XML() in python 2.6.4. >> >> This code works fine: >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> bobblehead> city>city''' >> theResponseXml = et.XML(getResponse) >> >> This code errors out when it tries to do the et.XML() >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> \ue58d83\ue89189\ue79c8C >> \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03> shipping>''' >> theResponseXml = et.XML(getResponse) >> >> In my real code, I'm pulling the getResponse data from a web page >> that >> returns as XML and when I display it in the browser you can see the >> Japanese characters in the data. I've removed all the stuff in my >> code >> and tried to distill it down to just what is failing. Hopefully I >> have >> not removed something essential. >> >> Why is this not working and what do I need to do to use Elementtree >> with unicode? > > On Nov 4, 11:01 am, Kee Nethery wrote: >> Having an issue with elementtree XML() in python 2.6.4. >> >> This code works fine: >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> bobblehead> city>city''' >> theResponseXml = et.XML(getResponse) >> >> This code errors out when it tries to do the et.XML() >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> \ue58d83\ue89189\ue79c8C >> \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03> shipping>''' >> theResponseXml = et.XML(getResponse) >> >> In my real code, I'm pulling the getResponse data from a web page >> that >> returns as XML and when I display it in the browser you can see the >> Japanese characters in the data. I've removed all the stuff in my >> code >> and tried to distill it down to just what is failing. Hopefully I >> have >> not removed something essential. >> >> Why is this not working and what do I need to do to use Elementtree >> with unicode? > > What you need to do is NOT feed it unicode. You feed it a str object > and it gets decoded according to the encoding declaration found in the > first line. That it uses "the encoding declaration found in the first line" is the nugget of data that is not in the documentation that has stymied me for days. Thank you! The other thing that has been confusing is that I've been using "dump" to view what is in the elementtree instance and the non-ASCII characters have been displayed as "numbered entities" (柏市) and I know that is not the representation I want the data to be in. A co-worker suggested that instead of "dump" that I use "et.tostring(theResponseXml, encoding='utf-8')" and then print that to see the characters. That process causes the non-ASCII characters to display as the glyphs I know them to be. If there was a place in the official docs for me to append these nuggets of information to the sections for "xml.etree.ElementTree.XML(text)" and "xml.etree.ElementTree.dump(elem)" I would absolutely do so. Thank you! Kee Nethery > So take the str object that you get from the web (should > be UTF8-encoded already unless the header is lying), and throw that at > ET ... like this: > > | Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit > (Intel)] on win32 > | Type "help", "copyright", "credits" or "license" for more > information. > | >>> from xml.etree import ElementTree as et > | >>> ucode = u''' > | ... > | ... \ue58d83\ue89189\ue79c8C > | ... \ue69f8f\ue5b882 > | ... \ue9ab98\ue58d97\ue58fb03 > | ... ''' > | >>> xml= et.XML(ucode) > | Traceback (most recent call last): > | File "", line 1, in > | File "C:\python26\lib\xml\etree\ElementTree.py", line 963, in XML > | parser.feed(text) > | File "C:\python26\lib\xml\etree\ElementTree.py", line 1245, in > feed > | self._parser.Parse(data, 0) > | UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d' > in position 69: ordinal not in range(128) > | # as expected > | >>> strg = ucode.encode('utf8') > | # encoding as utf8 is for DEMO purposes. > | # i.e. use the original web str object, don't convert it to unicode > | # and back to utf8. > | >>> xml2 = et.XML(strg) > | >>> xml2.tag > | 'customer' > | >>> for c in xml2.getchildren(): > | ... print c.tag, repr(c.text) > | ... > | shipping '\n' > | >>> for c in xml2[0].getchildren(): > | ... print c.tag, repr(c.text) > | ... > | state u'\ue58d83\ue89189\ue79c8C' > | city u'\ue69f8f\ue5b882' > | street u'\ue9ab98\ue58d97\ue58fb03' > | >>> > > By the way: (1) it usually helps to be more explicit than "errors > out", preferably the exact copied/pasted output as shown above; this > is one of the rare cases where the error message is predictable (2) > PLEASE don't start a new topic in a reply in somebody else's thread. > > -- > http://mail.python.org/mailman/listinfo/python-list ------------------------------------------------- I check email roughly 2 to 3 times per business day. Kagi main office: +1 (510) 550-1336 From steven at REMOVE.THIS.cybersource.com.au Tue Nov 3 21:25:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 02:25:06 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: On Tue, 03 Nov 2009 11:26:49 +0000, Simon Brunning wrote: > 2009/11/1 Steven D'Aprano : >> >> The only stupid question is the one you are afraid to ask. > > I was once asked, and I quote exactly, "are there any fish in the > Atlantic sea?" > > That's pretty stupid. ;-) Once in the distant past, there were no fish in what would become the Atlantic Ocean (not sea); and some day in the future there won't be any fish either. At the rate we're going that day may not be that far away: fish are being over-fished all over the world, jellyfish are blooming, and there are areas of the Namibian continental where the dominant species have flipped from fish to jellyfish: http://www.scienceinafrica.co.za/2009/september/jellyfish.htm http://www.sciencedaily.com/releases/2006/07/060711091411.htm http://www.sciencedaily.com/releases/2009/06/090609092057.htm So, no, not a stupid question at all. -- Steven From ben+python at benfinney.id.au Tue Nov 3 21:59:03 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 13:59:03 +1100 Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <87hbtbf11k.fsf@benfinney.id.au> Simon Brunning writes: > 2009/11/1 Steven D'Aprano : > > > > The only stupid question is the one you are afraid to ask. > > I was once asked, and I quote exactly, "are there any fish in the > Atlantic sea?" > > That's pretty stupid. ;-) Not at all. The person asking the question might be ignorant of the facts about fishing, or the Atlantic, or marine ecosystems in that region, etc., in which case the question is smart and wise and to the point. Especially compared with the alternative: not asking the question perpetuates the ignorance. -- \ ?If I had known what it would be like to have it all... I might | `\ have been willing to settle for less.? ?Jane Wagner, via Lily | _o__) Tomlin | Ben Finney From sjmachin at lexicon.net Tue Nov 3 22:02:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 19:02:24 -0800 (PST) Subject: elementtree XML() unicode References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: <59090fb8-5a22-47c8-ac6d-90b22936f825@j9g2000prh.googlegroups.com> On Nov 4, 1:06?pm, Kee Nethery wrote: > On Nov 3, 2009, at 5:27 PM, John Machin wrote: > > > > > On Nov 4, 11:01 am, Kee Nethery wrote: > >> Why is this not working and what do I need to do to use Elementtree > >> with unicode? > > > What you need to do is NOT feed it unicode. You feed it a str object > > and it gets decoded according to the encoding declaration found in the > > first line. > > That it uses "the encoding declaration found in the first line" is the ? > nugget of data that is not in the documentation that has stymied me ? > for days. Thank you! And under the "don't repeat" principle, it shouldn't be in the Elementtree docs; it's nothing special about ET -- it's part of the definition of an XML document (which for universal loss-free transportability naturally must be encoded somehow, and the document must state what its own encoding is (if it's not the default (UTF-8))). > The other thing that has been confusing is that I've been using "dump" ? > to view what is in the elementtree instance and the non-ASCII ? > characters have been displayed as "numbered ? > entities" (柏市) and I know that is not the ? > representation I want the data to be in. A co-worker suggested that ? > instead of "dump" that I use "et.tostring(theResponseXml, ? > encoding='utf-8')" and then print that to see the characters. That ? > process causes the non-ASCII characters to display as the glyphs I ? > know them to be. > > If there was a place in the official docs for me to append these ? > nuggets of information to the sections for ? > "xml.etree.ElementTree.XML(text)" and ? > "xml.etree.ElementTree.dump(elem)" I would absolutely do so. I don't understand ... tostring() is in the same section as dump(), about two screen-heights away. You want to include the tostring() docs in the dump() docs? The usual idea is not to get bogged down in the first function that looks at first glance like it might do what you want ("look at the glyphs") but doesn't (it writes a (transportable) XML stream) but press on to the next plausible candidate. From gagsl-py2 at yahoo.com.ar Tue Nov 3 22:06:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 00:06:50 -0300 Subject: elementtree XML() unicode References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery escribi?: > If there was a place in the official docs for me to append these nuggets > of information to the sections for "xml.etree.ElementTree.XML(text)" and > "xml.etree.ElementTree.dump(elem)" I would absolutely do so. http://bugs.python.org/ applies to documentation too. -- Gabriel Genellina From fordhaivat at gmail.com Tue Nov 3 22:20:05 2009 From: fordhaivat at gmail.com (Someone Something) Date: Tue, 3 Nov 2009 22:20:05 -0500 Subject: continuous return? Message-ID: I'm trying to write something related to IRC. The thing is, I have one thread receiving and another sending. But, how can I keep the caller of the recv() function informed about what was last received so that it can all be printed out. But, I no idea how I can accomplish this. I was thinking about getting one variable that was constantly updated with the latest line that was recved and that the variable would be a member of the class so other functions/classes can access it -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Nov 3 22:31:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 00:31:34 -0300 Subject: continuous return? References: Message-ID: En Wed, 04 Nov 2009 00:20:05 -0300, Someone Something escribi?: > I'm trying to write something related to IRC. The thing is, I have one > thread receiving and another sending. But, how can I keep the caller of > the > recv() function informed about what was last received so that it can all > be > printed out. But, I no idea how I can accomplish this. I was thinking > about > getting one variable that was constantly updated with the latest line > that > was recved and that the variable would be a member of the class so other > functions/classes can access it I don't completely understand your scenario, but since you say you have several threads, a common way to communicate between them is to use a Queue object. Let the receiver thread put() lines into the queue, and the processing thread get() them and do some work. -- Gabriel Genellina From jon at jonhaddad.com Tue Nov 3 23:02:24 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Tue, 3 Nov 2009 20:02:24 -0800 Subject: unittest & setup Message-ID: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Maybe I'm doing something wrong here, definitely not the most experienced unit tester. I've got a class, in the constructor it loads a CSV file from disc. I'd like only 1 instance of the class to be instantiated. However, when running multiple unit tests, multiple instances of the class are created. What's the best way for me to avoid this? It takes about a few seconds to load the CSV file. -- Jonathan Haddad http://www.rustyrazorblade.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From kee at kagi.com Tue Nov 3 23:42:15 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 20:42:15 -0800 Subject: elementtree XML() unicode In-Reply-To: References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: <340744BF-30E0-490A-9FAC-52E8D26EA410@kagi.com> On Nov 3, 2009, at 7:06 PM, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery > escribi?: > >> If there was a place in the official docs for me to append these >> nuggets of information to the sections for >> "xml.etree.ElementTree.XML(text)" and >> "xml.etree.ElementTree.dump(elem)" I would absolutely do so. > > http://bugs.python.org/ applies to documentation too. I've submitted documentation bugs in the past and no action was taken on them, the bugs were closed. I'm guessing that information "that everyone knows" not being in the documentation is not a bug. It's my fault I'm a newbie and I accept that. Thanks to you two for helping me get past this block. Kee From gagsl-py2 at yahoo.com.ar Tue Nov 3 23:42:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 01:42:55 -0300 Subject: unittest & setup References: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Message-ID: En Wed, 04 Nov 2009 01:02:24 -0300, Jonathan Haddad escribi?: > I've got a class, in the constructor it loads a CSV file from disc. I'd > like only 1 instance of the class to be instantiated. However, when > running > multiple unit tests, multiple instances of the class are created. What's > the best way for me to avoid this? It takes about a few seconds to load > the > CSV file. Use a factory function: _instance = None def createFoo(parameters): if _instance is None: _instance = Foo(parameters) return _instance and replace all occurrences of Foo(parameters) with createFoo(parameters). For new-style classes, you may override the __new__ method instead. Perhaps I didn't understand your problem correctly because this is unrelated to unit testing... -- Gabriel Genellina From robert.kern at gmail.com Tue Nov 3 23:43:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 Nov 2009 22:43:45 -0600 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: Steven D'Aprano wrote: > On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: >> Adding in the loop construct and name bindings doesn't enhance my >> understanding of what a dot-product is. I don't need to see the loop >> construct at all in this case. A dot product is simply the >> multiplication of each element in a vector sequence. > > What you need is to define a function dot-product, and not hijack the > name for a local value. Then the function's implementation is irrelevant > to you: it could use a list comp, or could use map, it could use a for- > loop, a while loop, recursion, or black magic: > > scalar = dot_product(vec1, vec2) Or use the appropriate libraries: from numpy import dot scalar = dot(vec1, vec2) -- 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 gopalm at infotechsw.com Wed Nov 4 00:04:11 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Wed, 4 Nov 2009 10:34:11 +0530 Subject: how to create nested classes dynamically Message-ID: <99950C2A2F9D425F9B88823EEA113105@pwit.com> I have class structure as below. How can I create the following nested class and its properties dynamically. class AA(object): class BB(object): def setBB1(self, value): ##some code def getBB1(self): bb1 = #somecode return bb1 bb1 = property(getBB1, setBB1, None, None) bb2 = ... bb = BB() class CC(object): .... cc = CC() aa = AA() print aa.bb.bb1 aa.bb.bb2 = '10' print aa.bb.bb2 I want to achive dot structure get or set value.i.e. aa.bb.bb1 Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 00:35:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 05:35:30 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: > Steven D'Aprano wrote: >> On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > >>> Adding in the loop construct and name bindings doesn't enhance my >>> understanding of what a dot-product is. I don't need to see the loop >>> construct at all in this case. A dot product is simply the >>> multiplication of each element in a vector sequence. >> >> What you need is to define a function dot-product, and not hijack the >> name for a local value. Then the function's implementation is >> irrelevant to you: it could use a list comp, or could use map, it could >> use a for- loop, a while loop, recursion, or black magic: >> >> scalar = dot_product(vec1, vec2) > > Or use the appropriate libraries: > > from numpy import dot > > scalar = dot(vec1, vec2) Why would I want to use an already existing library that is fast, well- written and well-supported, when I can toss together a nasty kludge myself? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 00:35:52 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 05:35:52 GMT Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: >>> For example, consider two rectangle classes R1 and R2, where R2 might >>> be a successor to R1, at some point in system evolution replacing R1. >>> R1 has logical data members left, top, width and height, and R2 has >>> logical data members left, top, right and bottom. With R1 direct >>> changes of left and top keeps the rectangle's size (since that size is >>> specified by width and height), while with R2 it changes the >>> rectangle's size. R1 is implemented with logical data members as >>> directly exposed data attributes. Some code in the system deals only >>> with R1 objects and for convenience or efficiency or whatever uses >>> direct modification instead of set_position method. Due to new >>> requirements it instead has to deal with R2 objects, with same >>> methods. But due to the direct modification of object state it now >>> changes the rectangle sizes, but at first it's not noticed since the >>> attempted rectangle position changes are very small. People get upset. >>> The bug is fixed. Time has been wasted. >> >> If there is need for mutable rectangles, there is need for mutable >> rectangles. Using properties instead of attributes doesn't help > > In the example above using properties would have avoided the problem. How would it have avoided the problem? Either of these would have the exact same semantics: class R2(object): def __init__(self): self._secret = {'top': 0, 'bottom': 100} def _top_getter(self): return self._secret['top'] def _top_setter(self, value): self._secret['top'] = value top = property(_top_getter, _top_setter) vs class R2(object): def __init__(self): self.top = 0 self.bottom = 100 Given the semantics you specified, it is strictly irrelevant whether R2.top is an attribute or a property. That's an implementation detail. Now of course we're capable of imagining a rectangle class R3 where R3.top is a property which has the side-effect of also changing R3.bottom so as to avoid the resize. Great -- that's something you can't implement (easily, if at all) with bare attributes. But that class is not R2, it has different semantics to R2. We're not opposed to properties where the functional requirements are best suited by computed properties. But properties don't come for free, and if you're going to implement functional behaviour *identical* to bare attributes using properties, then what's the point? >> - if you >> change semantics of something, code might break. > > Yes, but that's totally out of the blue. If you, say, paint your nose > bright green, then people might stare at it. That has nothing to do do > with anything discussed here, and so anyone mentioning that as > purportedly relevant to anything discussed here, would implicitly be > saying "I don't understand anything abour it", and that's effectively > what you're saying, sorry. I'm afraid you have failed to understand Diez's point. The hypothetical project using class R1 had a specified functional behaviour: assigning to rectangle.top must move the rectangle, not resize it. You have replaced it with a class that has different behaviour. Who cares what the implementation is? It's the *change in behaviour* that caused the breakage, regardless of whether R2.top is implemented as a bare attribute or as a property. In that regard, it is *no different* from changing R2.set_position() to resize the rectangle. > However, I do understand what got you confused. I doubt that very much. > Changing the internal representation of a class is not to change the > class' semantics. That's true, but that's not what you've done in your example. You've clearly changes the class' semantics. You said so yourself: "With R1 direct changes of left and top keeps the rectangle's size (since that size is specified by width and height), while with R2 it changes the rectangle's size." Since in Python, non-underscore attributes are part of the public API, the two classes have different semantics. > It belongs to the class only. Anyone availing himself > or herself of access to that internal representation is doing something > that may or may not work in the future and would ideally be doing it at > own's risk, but as the example above illustrated, they're most often > doing it at *other*'s risk. Irrelevant. In Python, attributes are frequently part of the class API. If you have an attribute R1.top, then people will assign to it, and your class should deal with it. "Deal with it", by the way, may include saying "if you stuff something crazy in the attribute, then you are responsible for breaking it". Python classes tend to be written under the implicit promise/threat that if you do something stupid, you're responsible for the breakage. That allows the caller the responsibility to do something clever which you never thought of without having to defeat your defensive code, but with great power (duck-typing) comes great responsibility (don't set R1.top to None unless you want to see some amusing exceptions). > And so the issue is how to get them to not do it, even when they think > that nobody will check their code until next version of Lib XYZ comes in > a year... > > And that's where using properties from the start enters the picture, > making it less convenient for those tinkerers to use internal > representation details. This is Python. Introspection is easy, and messing up your internals is easy unless you write your class in C. Just because you hide something behind a property doesn't mean we can't find it and do strange and terrible things to it. We don't do it because when we do, it's our own foot we're shooting. >> In Python, attributes >> are part of the public interface as long as you don't explicitly define >> them otherwise. > > Not sure what that refers to. Dear me. Here you are talking about "internals", and you don't see the connection with the public interface? Hint: if something is in the public interface, it isn't an internal detail. >> But preliminary assumptions about what could be in some yet unseen >> future is introducing more code with more chances of errors > > No not really. Of course it is. Properties are *code*. Every line of code can contain bugs. Properties require testing. They don't fall from the sky and insert themselves into your class, you have to write them, test them, debug them, maintain them. >>, reducing >> the flexibility at the same time. I still fail to see where that's >> good. > > Yes. > > Consider the *nix convention for files, that they're just byte streams. > They're *restricted* to byte streams. That's darn inflexible, yes? No. Anything can be represented by a byte stream with a known encoding, provided you are willing to deal with errors. -- Steven From israelu at elbit.co.il Wed Nov 4 00:45:23 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 21:45:23 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> On Nov 4, 3:10?am, "Gabriel Genellina" wrote: > En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribi?: > > > > > > > On Nov 3, 7:49 pm, Matt McCredie wrote: > >> iu2 elbit.co.il> writes: > > >> > Having a file called funcs.py, I would like to read it into a string, > >> > and then import from that string. > >> > That is instead of importing from the fie system, I wonder if it's > >> > possible to eval the text in the string and treat it as a module. > >> mymodule = types.ModuleType("mymodule", "Optional Doc-String") > >> with file('funcs.py') as f: > >> ? ? txt = f.read() > >> exec txt in globals(), mymodule.__dict__ > >> sys.modules['mymodule'] = mymodule > > > Thanks, it seems simpler than I thought. > > I don't fully understand , though, the exec statement, how it causes > > the string execute in the context of mymodule. > > Sometimes you don't even require a module, and this is simpler to ? > understand. Suppose you have a string like this: > > txt = """ > def foo(x): > ? ?print 'x=', x > > def bar(x): > ? ?return x + x > """ > > you may execute it: > > py> namespace = {} > py> exec txt in namespace > > The resulting namespace contains the foo and bar functions, and you may ? > call them: > > py> namespace.keys() > ['__builtins__', 'foo', 'bar'] > py> namespace['foo']('hello') > x= hello > > exec just executes the string using the given globals dictionary as its ? > global namespace. Whatever is present in the dictionary is visible in the ? > executed code as global variables (none in this example). The global names ? > that the code creates become entries in the dictionary. (foo and bar; ? > __builtins__ is an implementation detail of CPython). You may supply ? > separate globals and locals dictionaries. > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - Thanks for the explanation. What happens if both global and local dictionaries are supplied: where are the newly created entities created? In the local dict? From gagsl-py2 at yahoo.com.ar Wed Nov 4 00:55:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 02:55:00 -0300 Subject: how to create nested classes dynamically References: <99950C2A2F9D425F9B88823EEA113105@pwit.com> Message-ID: En Wed, 04 Nov 2009 02:04:11 -0300, gopal mishra escribi?: > I have class structure as below. How can I create the following nested > class > and its properties dynamically. > > > class AA(object): > > class BB(object): > > def setBB1(self, value): > > ##some code > > def getBB1(self): > > bb1 = #somecode > > return bb1 > > bb1 = property(getBB1, setBB1, None, None) > > bb2 = ... > > bb = BB() > > class CC(object): > > .... > > cc = CC() > > aa = AA() First, I assume getBB1 and setBB1 really do some actual work. If they're just accessors for an instance attribute, don't use them; don't write Java in Python [1] In Python, you may have instance (or "normal") attributes, and class attributes. When you say obj.name, if name is not found as an instance attribute, it is looked up on its class (and all its base classes; this is how methods are searched, BTW) Class attributes are "shared" among all instances - that is, all instances retrieve the same object when you access a class attribute. Your code above, as it is written, creates two class attributes named bb and cc (they're class attributes because the statements bb=... and cc=... are inside the class definition). It works, but perhaps that's not what you want. If you want instance attributes instead, create them in AA.__init__ by using self.bb=something Nested classes provide no benefit here and are harder to use, so just move the class definitions to the module level. The code would become: class BB(object): def setBB1(self, value): ##some code def getBB1(self): "docstring for the property" bb1 = #somecode return bb1 bb1 = property(getBB1, setBB1) bb2 = ... class CC(object): .... class AA(object): def __init__(self, ...): self.bb = BB() self.cc = CC() Then, you can write: aa = AA() print aa.bb.bb1 aa.bb.bb2 = '10' print aa.bb.bb2 [1] http://dirtsimple.org/2004/12/python-is-not-java.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Nov 4 01:02:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 03:02:34 -0300 Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: > On Nov 4, 3:10 am, "Gabriel Genellina" wrote: >> txt = """ >> def foo(x): >> print 'x=', x >> >> def bar(x): >> return x + x >> """ >> >> py> namespace = {} >> py> exec txt in namespace >> py> namespace.keys() >> ['__builtins__', 'foo', 'bar'] >> py> namespace['foo']('hello') >> x= hello > What happens if both global and local dictionaries are supplied: where > are the newly created entities created? In the local dict? The amazing thing about Python is how easy is to experiment in the interpreter. Just see it by yourself! -- Gabriel Genellina From alfps at start.no Wed Nov 4 01:15:14 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 07:15:14 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Steven D'Aprano: > On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: > >>>> For example, consider two rectangle classes R1 and R2, where R2 might >>>> be a successor to R1, at some point in system evolution replacing R1. >>>> R1 has logical data members left, top, width and height, and R2 has >>>> logical data members left, top, right and bottom. With R1 direct >>>> changes of left and top keeps the rectangle's size (since that size is >>>> specified by width and height), while with R2 it changes the >>>> rectangle's size. R1 is implemented with logical data members as >>>> directly exposed data attributes. Some code in the system deals only >>>> with R1 objects and for convenience or efficiency or whatever uses >>>> direct modification instead of set_position method. Due to new >>>> requirements it instead has to deal with R2 objects, with same >>>> methods. But due to the direct modification of object state it now >>>> changes the rectangle sizes, but at first it's not noticed since the >>>> attempted rectangle position changes are very small. People get upset. >>>> The bug is fixed. Time has been wasted. >>> If there is need for mutable rectangles, there is need for mutable >>> rectangles. Using properties instead of attributes doesn't help >> In the example above using properties would have avoided the problem. > > How would it have avoided the problem? Either of these would have the > exact same semantics: > > class R2(object): > def __init__(self): > self._secret = {'top': 0, 'bottom': 100} > def _top_getter(self): > return self._secret['top'] > def _top_setter(self, value): > self._secret['top'] = value > top = property(_top_getter, _top_setter) > > vs > > class R2(object): > def __init__(self): > self.top = 0 > self.bottom = 100 OK, I had a laugh. :-) You maintain that all doors are dark red, and show up a photo of two of your dark red doors as proof. For R2, did you at *any* moment consider properties that emulated the internal representation of R1? I'm putting it that way on the off-chance that you're not just pretending to not understand. > Given the semantics you specified No semantics was specified in my example, quoted in full above. However, the natural semantics is that various logical properties, such as left, top, right, bottom, width and height, can be varied independently. > it is strictly irrelevant whether > R2.top is an attribute or a property. That's an implementation detail. Happily that's incorrect. You might try to consider what properties are *for*, why the language supports them if they do nothing at all except adding overhead. Cheers, & hth., - Alf From highcar at gmail.com Wed Nov 4 02:32:14 2009 From: highcar at gmail.com (elca) Date: Tue, 3 Nov 2009 23:32:14 -0800 (PST) Subject: disable image loading to speed up webpage load In-Reply-To: <7l7nklF3cgpk3U1@mid.uni-berlin.de> References: <26155440.post@talk.nabble.com> <7l7nklF3cgpk3U1@mid.uni-berlin.de> Message-ID: <26192072.post@talk.nabble.com> Diez B. Roggisch-2 wrote: > > elca schrieb: >> Hi, >> im using win32com 's webbrowser module. >> i have some question about it.. >> is it possible to disable image loading to speed up webpage load? >> any help ,much appreciate >> thanks in advance > > Use urllib2. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > you can show me some more specific sample or demo? -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26192072.html Sent from the Python - python-list mailing list archive at Nabble.com. From gagsl-py2 at yahoo.com.ar Wed Nov 4 02:37:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 04:37:14 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 03:15:14 -0300, Alf P. Steinbach escribi?: > * Steven D'Aprano: >> On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: >> >>>>> For example, consider two rectangle classes R1 and R2, where R2 might >>>>> be a successor to R1, at some point in system evolution replacing R1. >>>>> R1 has logical data members left, top, width and height, and R2 has >>>>> logical data members left, top, right and bottom. With R1 direct >>>>> changes of left and top keeps the rectangle's size (since that size >>>>> is >>>>> specified by width and height), while with R2 it changes the >>>>> rectangle's size. R1 is implemented with logical data members as >>>>> directly exposed data attributes. Some code in the system deals only >>>>> with R1 objects and for convenience or efficiency or whatever uses >>>>> direct modification instead of set_position method. Due to new >>>>> requirements it instead has to deal with R2 objects, with same >>>>> methods. But due to the direct modification of object state it now >>>>> changes the rectangle sizes, but at first it's not noticed since the >>>>> attempted rectangle position changes are very small. People get >>>>> upset. >>>>> The bug is fixed. Time has been wasted. >>>> If there is need for mutable rectangles, there is need for mutable >>>> rectangles. Using properties instead of attributes doesn't help >>> In the example above using properties would have avoided the problem. >> How would it have avoided the problem? Either of these would have the >> exact same semantics: >> class R2(object): >> def __init__(self): >> self._secret = {'top': 0, 'bottom': 100} >> def _top_getter(self): >> return self._secret['top'] >> def _top_setter(self, value): >> self._secret['top'] = value >> top = property(_top_getter, _top_setter) >> vs >> class R2(object): >> def __init__(self): >> self.top = 0 >> self.bottom = 100 > > OK, I had a laugh. :-) You maintain that all doors are dark red, and > show up a photo of two of your dark red doors as proof. > > For R2, did you at *any* moment consider properties that emulated the > internal representation of R1? > > I'm putting it that way on the off-chance that you're not just > pretending to not understand. I don't understand either. R1 and R2 have *different* semantics. They don't behave the same. Any breakage you experiment using R2 instead of R1 comes from the fact they behave differently, not because they're implemented differently, nor because they use properties or not. You could have implemented another variant, let's say RCrazy, that behaves exactly the same as R1 but internally stores a different set of attributes (the baricenter, the angle between both diagonals, and the diagonal length). As long as you implement the same public interfase (same set of externally visible attributes, same methods, same behavior) RCrazy is interchangeable with R1; RCrazy is a subtype of R1 in the sense of the Liskov substitution principle. Of course, perfect substitutability (did I spell it right?) isn't possible in Python; obj.__class__.__name__ returns 'RCrazy' instead of 'R1', it's mro() is different, dir() returns a different set of names, etc. But for any `reasonable` use of an R1 instance representing a rectangle, an RCrazy instance should serve equally well. >> Given the semantics you specified > > No semantics was specified in my example, quoted in full above. > > However, the natural semantics is that various logical properties, such > as left, top, right, bottom, width and height, can be varied > independently. You did specify the set of attributes and how they behave, perhaps not very formally, but that's a semantic specification to me. It was clear from your description that R2 behave different that R1; the problems that came after using R2 instead of R1 were caused by such different behavior, not because of using properties or not. In any case, I don't think the problem is specific to Python. >> it is strictly irrelevant whether R2.top is an attribute or a property. >> That's an implementation detail. > > Happily that's incorrect. You might try to consider what properties are > *for*, why the language supports them if they do nothing at all except > adding overhead. In normal usage (either obj.name or getattr(obj, 'name')) an attribute is undistinguishable from a property. Users of the class should not worry at all whether it is implemented as a simple attribute, a computed property, or an esoteric class attribute following the descriptor protocol. If all a property does is to store and retrieve its value as an instance attribute, yes, it just adds overhead. -- Gabriel Genellina From clp2 at rebertia.com Wed Nov 4 02:42:01 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 Nov 2009 23:42:01 -0800 Subject: how to remove the punctuation and no need words from paragraphs In-Reply-To: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> References: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> Message-ID: <50697b2c0911032342o6d85a958r25ec70c5b2572e1c@mail.gmail.com> On Tue, Nov 3, 2009 at 1:44 PM, kylin wrote: > I want to remove all the punctuation and no need words form a string > datasets for experiment. > > I am new to python, please give me some clue and direction to write > this code. The `replace` method of strings should get you pretty far (just replace unwanted stuff with the empty string): http://docs.python.org/library/stdtypes.html#str.replace Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Wed Nov 4 02:47:45 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Nov 2009 08:47:45 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> * Alf P. Steinbach wrote: >>> * Peter Otten: >>>> Every time someone has to read the code he will read, hesitate, read >>>> again, and then hopefully come to the conclusion that the code does >>>> nothing, consider not using it, or if it is not tied into a larger >>>> project removing it. >>> I don't understand what you mean. >> >> Writing code is not fire and forget. It has to be debugged, tested, >> maintained, and will be read quite a few times in the process. Therefore >> it is important that you make it easy to read and understand. > > No, I meant that I didn't understand why you find it hard to read and > understand. Too many indirections. > [snip] >> Couldn't >> >> class IdButton(tkinter.Button): >> def __init__(self, id, **kw): >> self.id = id >> tkinter.Button.__init__(self, **kw) >> >> be customised as easily? > > Not unless there's much more that I can learn about tkinter button > 'command' callbacks. Which is of course possible. :-) Is it possible to > pick up the relevant object from the handler? There may be a way using bind(), but the idea was to make simple specialised subclasses as needed that either invoke a method or take a function that can be wrapped (something like command = functools.partial(command, self)). >>>> Example: Why do you introduce button.id_string() instead of >>>> str(button.id)? >>> Because the string representation of an id then /can/ be customized >>> independently of the id. For example, id's might be integers but for >>> string representation you might want symbolic action names (e.g., you >>> might have two or more buttons with same title but different actions, so >>> that title would be ungood to identify button). And for another example, >>> when debugging or testing you might want the string represention of an >>> id to provide more information about the button and/or its context, and >>> then id_string provides a single >>> central customization point -- provided it's used, of course. >> >> And what about the IdEntry class? > > The naming scheme doesn't hold up, but I'm pretty sure that's not what you > mean? I meant that when you need other classes with an .id you will now have to implement .id_string(), too. A simple approach like entry = tkinter.Entry(...) entry.id = 42 won't work anymore. Peter From alfps at start.no Wed Nov 4 02:50:42 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 08:50:42 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > > I don't understand either. R1 and R2 have *different* semantics. Assume that they have the very exact same semantics -- like two TV sets that look the same and work the same except when you open 'em up and poke around in there, oh holy cow, in this one there's stuff that isn't in the other. After all the semantics (like the TV controls and their effects) were left unspecified, only the internal representations (like, the main circuit boards *inside* the TVs) were described, and the example only makes sense if R1 and R2 have the same semantics, that is, work the same via their public interfaces. If I'd known that people would start a discussion based on their wishes that the unspecied semantics should be some that made the example meaningless, well, then I'd simply specified the semantics -- consider that done. > They don't behave the same. Assume that they do -- except when you go poking into the innards. Cheers & hth., - Alf From neuphyte at gmail.com Wed Nov 4 02:55:16 2009 From: neuphyte at gmail.com (Siva Subramanian) Date: Wed, 4 Nov 2009 13:25:16 +0530 Subject: using csv dictreader in python Message-ID: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> Hello all, I am now trying to access the csv file using dictreader. import csv r25 = csv.DictReader(open('Report_ 25', 'rb'), delimiter=',') rownum = 1 for row in r25: # Save header row. if rownum == 0: header = row else: colnum = 0 for col in row: This only gets me the following output {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': '4001433', 'FieldName4': '759'} 1. How do i access the 4, 0.00, ... the values ? 2. How do i compare it with another csv file ? Thanks in advance Siva -------------- next part -------------- An HTML attachment was scrubbed... URL: From lorenzo.digregorio at gmail.com Wed Nov 4 03:04:08 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Wed, 4 Nov 2009 00:04:08 -0800 (PST) Subject: How to print zero-padded floating point numbers in python 2.6.1 Message-ID: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Hello, I thought that I could zero-pad a floating point number in 'print' by inserting a zero after '%', but this does not work. I get: print '%2.2F' % 3.5 3.50 print '%02.2F' % 3.5 3.50 How can I get print (in a simple way) to print 03.50? Best Regards, Lorenzo From _rdi_ at web.de Wed Nov 4 03:15:17 2009 From: _rdi_ at web.de (=?UTF-8?B?UsO8ZGlnZXIgUmFuZnQ=?=) Date: Wed, 04 Nov 2009 09:15:17 +0100 Subject: comparing alternatives to py2exe In-Reply-To: References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <7lcrglF3cc7quU1@mid.individual.net> Maxim Khitrov schrieb: > 1. I don't think cx_freeze supports single exe. I haven't even been > able to get it to append the generated library.zip file to the > executable using documented options. Other things like .pyd files > always seem to be separate. At the same time, singe executables > generated by py2exe do not always work. I have a program that works > fine on Windows XP, Vista, and 7 if it is built under XP. However, if > I build the exact same program under Windows 7, it no longer works on > Vista or XP. I'm sure it has something to do with SxS or other dll > issues. I had similar issues with under Vista generated programs not running under 2K (unfortunately I have to support it). This behavior came from the .dll dependency tracking of py2exe, which included a OS .dll into the dist output. These are the steps I toke to find the offending .dll * generated a "flat" directory (the .dll's not packed into library.zip) with options = { [...], 'bundle_files': 3 } * extracted the not loadable extension from library.zip * examined the dependencies of this module with Microsoft's "Dependency Walker" (you can find it somewhere in the MSDN) * added the superfluous .dll to the options = { [...], 'dll_excludes': ['offending.dll'] } parameter HTH Rudi From lutz.horn at fastmail.fm Wed Nov 4 03:25:53 2009 From: lutz.horn at fastmail.fm (Lutz Horn) Date: Wed, 04 Nov 2009 09:25:53 +0100 Subject: How to print zero-padded floating point numbers in python 2.6.1 In-Reply-To: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> References: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Message-ID: Lorenzo Di Gregorio schrieb: > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a simple way) to print 03.50? print '%05.2F' % 3.5 Lutz From _rdi_ at web.de Wed Nov 4 03:30:40 2009 From: _rdi_ at web.de (=?ISO-8859-1?Q?R=FCdiger_Ranft?=) Date: Wed, 04 Nov 2009 09:30:40 +0100 Subject: Win XP: How to hide command window for sub processes? In-Reply-To: References: <6ab3abec-c529-4832-b57b-9017f93c1730@g27g2000yqn.googlegroups.com> <7kt8sgF3blcosU1@mid.individual.net> Message-ID: <7lcsdjF3d92u0U1@mid.individual.net> klausfpga schrieb: > On Oct 29, 11:25 am, R?diger Ranft <_r... at web.de> wrote: > Thanks Ruediger, > > I'll try that immediately tomorrow, when working again on a windows > host. > > Good to know, that the Python API supports this. > though this feature was not that easy to be found in the doc. Well, getting the point from subproces.py was easy. Finding the documentation about STARTUPINFO in the MSDN was not. I better stop here before this post turns into a rant about Mircosofts use of javascript. bye Rudi From clp2 at rebertia.com Wed Nov 4 03:37:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 00:37:52 -0800 Subject: How to print zero-padded floating point numbers in python 2.6.1 In-Reply-To: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> References: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Message-ID: <50697b2c0911040037w29b4cb0bif518ef6efe458aa3@mail.gmail.com> On Wed, Nov 4, 2009 at 12:04 AM, Lorenzo Di Gregorio wrote: > Hello, > > I thought that I could zero-pad a floating point number in 'print' by > inserting a zero after '%', but this does not work. > > I get: > > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a simple way) to print 03.50? >>> print ("%.2f" % 3.5).zfill(5) 03.50 >>> print ("%5.2f" % 3.5).replace(' ','0') 03.50 Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 4 03:49:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 00:49:31 -0800 Subject: python compare and process a csv file In-Reply-To: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> References: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Message-ID: <50697b2c0911040049w16cf0611iaab7695be61b8048@mail.gmail.com> On Tue, Nov 3, 2009 at 7:43 AM, Siva Subramanian wrote: > Hello all, > > I am new on this list and computer programming > > I have two distinct statistical files (both csv) > > 1.?????? Report_2_5 ? this is a report dump containing over a 10 million records and is different every day > > 2.?????? Customer_id dump ? this is a daily dump of customers who have made payments. This is generally a million record > > I need to extract past history depending on customers who make regular payments > > For example, > > Report_2_5 > > Customer ID, Plan_NO, stat1, vol2, amount3 > 2134, Ins1, 10000, 20000, 10 > 2112, Ins3, 30000, 20000, 10 > 2121, Ins3, 30000, 20000, 10 > 2145, Ins2, 15000, 10000, 5 > 2245, Ins2, 15000, 10000, 5 > 0987, Ins1, 10000, 20000, 10 > > 4546, Ins1, 10020, 21000, 10 > > 6757, Ins1, 10200, 22000, 10 > ? > > customer_id dump > > > 0987 > > 4546 > > 6757 > > 2134 > > I need to process the Report_2_5 and extract the following output > > Stat1: 40220 > Vol2 : 83000 > Amount3 : 40 > > I am new to programming and I have been extracting this data using MS ? Access and I badly need a better solution. Have you considered using a proper SQL database? (See http://en.wikipedia.org/wiki/SQL ; MySQL is one example: http://en.wikipedia.org/wiki/MySQL) Mucking around with CSV files like this is basically doing the work of some simple SQL queries, only in an ad-hoc, inefficient manner. (MS Access is essentially a non-industrial-strength SQL for non-programmers.) Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Wed Nov 4 04:38:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 06:38:50 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 04:50:42 -0300, Alf P. Steinbach escribi?: > * Gabriel Genellina: >> I don't understand either. R1 and R2 have *different* semantics. > > Assume that they have the very exact same semantics -- like two TV > sets that look the same and work the same except when you open 'em up > and poke around in there, oh holy cow, in this one there's stuff that > isn't in the other. > >> They don't behave the same. > > Assume that they do -- except when you go poking into the innards. And the problem is...? That the internal details are different? Who cares? (I'm lost now.) -- Gabriel Genellina From highcar at gmail.com Wed Nov 4 04:39:36 2009 From: highcar at gmail.com (elca) Date: Wed, 4 Nov 2009 01:39:36 -0800 (PST) Subject: join , split question Message-ID: <26193334.post@talk.nabble.com> Hello, i have some text file list such like following format. i want to change text format to other format. i was upload it pastebin site http://elca.pastebin.com/d71261168 if anyone help ,much appreciate thanks in advance -- View this message in context: http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html Sent from the Python - python-list mailing list archive at Nabble.com. From alfps at start.no Wed Nov 4 04:45:51 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 10:45:51 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > En Wed, 04 Nov 2009 04:50:42 -0300, Alf P. Steinbach > escribi?: > >> * Gabriel Genellina: >>> I don't understand either. R1 and R2 have *different* semantics. >> >> Assume that they have the very exact same semantics -- like two TV >> sets that look the same and work the same except when you open 'em up >> and poke around in there, oh holy cow, in this one there's stuff that >> isn't in the other. > >> >>> They don't behave the same. >> >> Assume that they do -- except when you go poking into the innards. > > And the problem is...? > That the internal details are different? Who cares? > (I'm lost now.) It's a common Usenet phenomenon: the warping thread. Context is lost. It is available by going back up-thread but at the cost of some work. :-) Cheers & hth., - Alf From __peter__ at web.de Wed Nov 4 05:22:04 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Nov 2009 11:22:04 +0100 Subject: python compare and process a csv file References: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Message-ID: Chris Rebert wrote: > On Tue, Nov 3, 2009 at 7:43 AM, Siva Subramanian > wrote: >> Hello all, >> >> I am new on this list and computer programming >> >> I have two distinct statistical files (both csv) >> >> 1. Report_2_5 ? this is a report dump containing over a 10 million >> records and is different every day >> >> 2. Customer_id dump ? this is a daily dump of customers who have >> made payments. This is generally a million record >> >> I need to extract past history depending on customers who make regular >> payments >> >> For example, >> >> Report_2_5 >> >> Customer ID, Plan_NO, stat1, vol2, amount3 >> 2134, Ins1, 10000, 20000, 10 >> 2112, Ins3, 30000, 20000, 10 >> 2121, Ins3, 30000, 20000, 10 >> 2145, Ins2, 15000, 10000, 5 >> 2245, Ins2, 15000, 10000, 5 >> 0987, Ins1, 10000, 20000, 10 >> >> 4546, Ins1, 10020, 21000, 10 >> >> 6757, Ins1, 10200, 22000, 10 >> ? >> >> customer_id dump >> >> >> 0987 >> >> 4546 >> >> 6757 >> >> 2134 >> >> I need to process the Report_2_5 and extract the following output >> >> Stat1: 40220 >> Vol2 : 83000 >> Amount3 : 40 >> >> I am new to programming and I have been extracting this data using MS ? >> Access and I badly need a better solution. > > Have you considered using a proper SQL database? (See > http://en.wikipedia.org/wiki/SQL ; MySQL is one example: > http://en.wikipedia.org/wiki/MySQL) > Mucking around with CSV files like this is basically doing the work of > some simple SQL queries, only in an ad-hoc, inefficient manner. (MS > Access is essentially a non-industrial-strength SQL for > non-programmers.) Industrial strength or not, Access should be capable of solving the OP's problem. So it would be interesting what's so bad about it in this case. Anyway, here's a database-free python solution: import csv REPORT = "report.csv" CUSTOMERS = "customers.csv" with open(CUSTOMERS) as instream: next(instream) # skip header # put customer ids into a set for fast lookup customer_ids = set(line.strip() for line in instream) with open(REPORT) as instream: rows = csv.reader(instream) # find columns headers = [column.strip() for column in rows.next()] customer_column = headers.index("Customer ID") sum_over_columns = [headers.index(s) for s in "stat1 vol2 amount3".split()] # initialize totals sigma = [0] * len(headers) # calculate totals for row in rows: if row[customer_column] in customer_ids: for index in sum_over_columns: sigma[index] += int(row[index]) # print totals for index in sum_over_columns: print "%-10s %10d" % (headers[index] + ":", sigma[index]) The limiting factor for this approach is the customer_ids set which at some point may no longer fit into memory. Peter From mark.leander at topicbranch.net Wed Nov 4 05:28:41 2009 From: mark.leander at topicbranch.net (Mark Leander) Date: Wed, 4 Nov 2009 02:28:41 -0800 (PST) Subject: import bug References: Message-ID: On Oct 31, 5:12 pm, kj wrote: > I give up: what's the trick? (Of course, renaming ham/re.py is > hardly "the trick." It's rather Procrustes' Bed.) I realize that this is probably not the answer you were looking for, but: $ python -m ham.spam or ==> ./spammain.py <== import ham.spam $ python spammain.py I've found it easier to not fight the module/package system but work with it. But yes, I also think the problem you're seeing is a wart or bug even. Best regards Mark Leander From jspies at sun.ac.za Wed Nov 4 05:36:01 2009 From: jspies at sun.ac.za (Johann Spies) Date: Wed, 4 Nov 2009 12:36:01 +0200 Subject: using csv dictreader in python In-Reply-To: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> References: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> Message-ID: <20091104103601.GI16847@sun.ac.za> On Wed, Nov 04, 2009 at 01:25:16PM +0530, Siva Subramanian wrote: > This only gets me the following output > > {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': > '4001433', 'FieldName4': '759'} > > 1. How do i access the 4, 0.00, ... the values ? >>> a= {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': '4001433', 'FieldName4': '759'} >>> a {'FieldName4': '759', 'FieldName1': '4', 'FieldName3': '4001433', 'FieldName2': '0.00'} >>> a['FieldName3'] '4001433' > 2. How do i compare it with another csv file ? If you have the values in one file, get the values in the other one and then compare. I am not sure I understand what is the problem here. Regards Johann -- Johann Spies Telefoon: 021-808 4599 Informasietegnologie, Universiteit van Stellenbosch "Train up a child in the way he should go: and when he is old, he will not depart from it." Proverbs 22:6 From robin at reportlab.com Wed Nov 4 05:49:00 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 04 Nov 2009 10:49:00 +0000 Subject: restricted mode??? Message-ID: <4AF15C1C.5090200@chamonix.reportlab.co.uk> A reportlab user running via mod_python+django (Python 2.5.2 and mod_python 3.3.1) reports a strange intermittent error involving failure to read files which are known to be present. After some debugging efforts we got this clearer error message File "/usr/lib/python2.5/site-packages/reportlab/lib/utils.py", line 810, in dump f = open(self.fn,'wb') IOError: file() constructor not accessible in restricted mode this is not the original error, but part of our efforts to debug; however, the original error was during an attempt to read a file so presumably open was not available there. Googling the error indicates something to do with restricted environments/mod_python+threads. I thought that restricted mode died ages ago. Any ideas what could be causing this? -- Robin Becker From dickinsm at gmail.com Wed Nov 4 06:14:55 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 4 Nov 2009 03:14:55 -0800 (PST) Subject: unable to compile Python 2.6.4 on AIX using gcc References: Message-ID: On Nov 3, 10:40?pm, chuck wrote: > Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX > 5.3. ?Here are the settings: > > export OBJECT_MODE=64 > export AR="ar -X64" > export MAKE=/usr/bin/gmake > export CC="gcc" > export CFLAGS="-maix64 -O2 -g -mcpu=power5" > export LDFLAGS="-L/usr/lib64 -L/opt/freeware/lib64 > -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" > export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" > ../Python-2.6.4/configure --with-gcc --disable-ipv6 > --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 > make > make_264.log 2>&1 > > make fails very early with the following error > > =========== > > ? ? ? ? ?gcc -pthread -c -fno-strict-aliasing -DNDEBUG -O3 -Wall > -Wstrict-prototypes ?-I. -IInclude -I../Python-2.6.4/Includ > e -I/opt/freeware/include -I/usr/lpp/X11/include/X11 ?-DPy_BUILD_CORE -o > Modules/python.o ../Python-2.6.4/Modules/python.c > In file included from ../Python-2.6.4/Include/Python.h:58, > ? ? ? ? ? ? ? ? ? from ../Python-2.6.4/Modules/python.c:3: > ../Python-2.6.4/Include/pyport.h:685:2: error: #error "LONG_BIT > definition appears wrong for platform (bad gcc/glibc config > ?)." > make: The error code from the last command is 1. > =========== > > I would appreciate any help. Thanks. Take a look at: http://bugs.python.org/issue1628484 Mark From vesa.koppa at gmail.com Wed Nov 4 06:21:48 2009 From: vesa.koppa at gmail.com (=?ISO-8859-1?Q?Vesa_K=F6pp=E4?=) Date: Wed, 04 Nov 2009 13:21:48 +0200 Subject: comparing alternatives to py2exe In-Reply-To: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> Message-ID: <4af163cc$0$6279$4f793bc4@news.tdc.fi> iu2 wrote: > Another thing that I think is of interest is whether the application > support modifying the version and description of the exe (that is, on > Windows, when you right-click on an application and choose > 'properties' you view the version number and description of the > application, it is a resource inside the exe). I think py2exe supports > it. Pyinstaller supports this. Vesa From jebagnanadas at gmail.com Wed Nov 4 06:37:19 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Wed, 4 Nov 2009 17:07:19 +0530 Subject: problem in installing wxwidgets for python.. Message-ID: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> Hello friends, I've tried to install wxwidgets in my mandriva 2009 spring for GUI interaction with python. In the installation instruction it said that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got the message checking for BASE_DEPENDENCIES... configure: error: Package requirements (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were not met: Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables BASE_DEPENDENCIES_CFLAGS and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I installed all the packages using the following commands. tar xvzf filename.tar.gz cd folder ./configure make make install I've not specified anf options like --prefix and i installed in the folder itself. when i tried to install gtk+ after installing all this it showed the same error. What should i do to install wxwidgets? Plz. reply as soon as possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Nov 4 06:43:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Nov 2009 05:43:30 -0600 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <4AF168E2.8080203@tim.thechases.com> Steven D'Aprano wrote: > On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: >> Or use the appropriate libraries: >> >> from numpy import dot >> >> scalar = dot(vec1, vec2) > > > Why would I want to use an already existing library that is fast, well- > written and well-supported, when I can toss together a nasty kludge > myself? because you want to perform a dot-product on strings? >>> dot_product(['a', 'b', 'c'], [2,3,4]) 'aabbbcccc' [grins, ducks and scampers away after the sum-shouldn't-special-case-strings-with-an-error thread] -tkc From ben+python at benfinney.id.au Wed Nov 4 07:08:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 23:08:54 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <87aaz2ebl5.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: > > from numpy import dot > > > > scalar = dot(vec1, vec2) > > Why would I want to use an already existing library that is fast, > well- written and well-supported, when I can toss together a nasty > kludge myself? Because using that library will ensure you can't migrate to Python 3 any time soon? *rimshot* -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From ishwor.gurung at gmail.com Wed Nov 4 07:11:39 2009 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Wed, 4 Nov 2009 23:11:39 +1100 Subject: problem in installing wxwidgets for python.. In-Reply-To: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> References: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> Message-ID: <34534aed0911040411r73595b14gbe436fe09436f99d@mail.gmail.com> Hi, 2009/11/4 Jebagnana Das : > Hello friends, > ????????????????? I've tried to install wxwidgets in my mandriva 2009 spring > for GUI interaction with python. In the installation instruction it said > that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got > the message You probably want wxpython binding instead - http://www.wxpython.org/ Use binaries provided by Mandriva's package manager where possible unless you _really_ want to do a source installation. > checking for BASE_DEPENDENCIES... configure: error: Package requirements > (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were > not met: > > > Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 > > Consider adjusting the PKG_CONFIG_PATH environment variable if you > installed software in a non-standard prefix. $ export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig (considering that your local installs went to those directories. Try replacing those directories accordingly for glib, atk, pango and cairo). The files you're after is a ".pc" (pkg-config need them) file. A quick find will tell you where it is if it is installed. Run configure script again. > Alternatively, you may set the environment variables > BASE_DEPENDENCIES_CFLAGS > > and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. > See the pkg-config man page for more details. > > Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I > installed all the packages using the following commands. [...] > tar xvzf filename.tar.gz > cd folder > ./configure > > make > make install Yep. Check where it installed them one by one. In short, you need access to a ".pc" file that they provide. If not, write one yourself. > I've not specified anf options like --prefix and i installed in the folder > itself. man pkg-config for further info. > when i tried to install gtk+ after installing all this it showed the same > error. What should i do to install wxwidgets? Plz. reply as soon as > possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... See above. -- Regards, Ishwor Gurung From davea at ieee.org Wed Nov 4 07:13:14 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 04 Nov 2009 07:13:14 -0500 Subject: Handling large datastore search In-Reply-To: <61e270bc0911032257v69ae584ak82ee461c6ae362dc@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> <4AF0BC76.4090908@ieee.org> <61e270bc0911032257v69ae584ak82ee461c6ae362dc@mail.gmail.com> Message-ID: <4AF16FDA.7060107@ieee.org> (This reply was offline, but I forwarded parts so that others with Google App Engine experience might jump in) Ahmed Barakat wrote: > > .... but I was trying to make use of everything provided by App engine. > > > > On Wed, Nov 4, 2009 at 1:27 AM, Dave Angel wrote: > > >> Ahmed Barakat wrote: >> >> >>> In case I have a huge datastore (10000 entries, each entry has like 6 >>> properties), what is the best way >>> to handle the search within such a huge datastore, and what if I want to >>> make a generic search, for example >>> you write a word and i use it to search within all properties I have for >>> all >>> entries? >>> >>> Is the conversion to XML a good solution, or it is not? >>> >>> sorry for being new to web development, and python. >>> >>> Thanks in advance. >>> >>> >>> >>> >> I don't see anything about your query which is specific to web development, >> and there's no need to be apologetic for being new anyway. >> >> One person's "huge" is another person's "pretty large." I'd say 10000 >> items is pretty small if you're working on the desktop, as you can readily >> hold all the data in "memory." I edit text files bigger than that. But >> I'll assume your data really is huge, or will grow to be huge, or is an >> environment which treats it as huge. >> >> When you're parsing large amounts of data, there are always tradeoffs >> between performance and other characteristics, usually size and complexity. >> If you have lots of data, you're probably best off by using a standard code >> system -- a real database. The developers of such things have decades of >> experience in making certain things fast, reliable, and self-consistent. >> >> But considering only speed here, I have to point out that you have to >> understand databases, and your particular model of database, pretty well to >> really benefit from all the performance tricks in there. Keeping it >> abstract, you specify what parts of the data you care about fast random >> access to. If you want fast search access to "all" of it, your database >> will generally be huge, and very slow to updates. And the best way to avoid >> that is to pick a database mechanism that best fits your search mechanism. >> I hate to think how many man-centuries Google has dedicated to getting fast >> random word access to its *enormous* database. I'm sure they did not build >> on a standard relational model. >> >> If you plan to do it yourself, I'd say the last thing you want to do is use >> XML. XML may be convenient way to store self-describing data, but it's not >> quick to parse large amounts of it. Instead, store the raw data in text >> form, with separate index files describing what is where. Anything that's >> indexed will be found rapidly, while anything that isn't will require search >> of the raw data. >> >> There are algorithms for searching raw data that are faster than scanning >> every byte, but a relevant index will almost always be faster. >> >> DaveA >> >> >> Clearly, you left a few things out of your original query. Now that you mention App Engine, I'm guessing you meant Google's Datastore and that this whole query is about building a Google app. So many of my comments don't apply, because I was talking about a desktop environment, using (or not using) a traditional (relational) database. I've never used Google's AppEngine, and never done a database web-app. So I'm the wrong person to give more than general advice. Google's Datastore is apparently both more and less powerful than a relational database, and web apps have very different tradeoffs. So you need to respecify the problem, giviing the full requirements first, and maybe somebody with more relevant experience will then respond. Meanwhile, try the following links, and see if any of them help. http://code.google.com/appengine/docs/ http://code.google.com/appengine/docs/whatisgoogleappengine.html http://code.google.com/appengine/docs/datastore/ http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html http://snarfed.org/space/datastore_talk.html http://video.google.com/videosearch?q=app+engine+data+store&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&ei=uGjxSrX-HcPp8Qbb2uWACQ&sa=X&oi=video_result_group&ct=title&resnum=11&ved=0CDIQqwQwCg DaveA From fetchinson at googlemail.com Wed Nov 4 07:17:51 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 4 Nov 2009 13:17:51 +0100 Subject: Pyfora, a place for python In-Reply-To: <4AF0959D.2020307@stoneleaf.us> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> <4AF0959D.2020307@stoneleaf.us> Message-ID: >>>>I was referring to this comment by Ben: >>>> >>>>"Suggestion: Please don't make efforts to fragment the community." >>>> >>>>This IMHO is hostile, because it presupposes that the mere goal of the >>>>OP is fragmenting the community >>> >>>It presupposes nothing of any goal. It describes a predictable result of >>>the OP's efforts, and requests those efforts to cease. >>> >>>So I deny the characterisation of that request as hostile. >> > > [mass snippitude] > >> If yes, with the substitution A = Ben and B = OP we get "in order for >> Ben's request to make sense, Ben has to assume that the OP is making >> an effort to fragment the community". This assumption on the part of >> Ben, I think, is hostile, since it assumes that the OP is making an >> effort to do something not nice. Whether the OP is indeed doing >> something not nice, is irrelevant. If the OP does do something not >> nice, the hostility is warranted. If the OP is not doing anything not >> nice, the hostility is unwarranted. But the fact that Ben was hostile >> is a fact :) > > You were doing fine until you brought in the hostility. I must agree > with Ben that his comment was not hostile. It was merely a statement. > Not an exclamation, no name calling, just a plain request rooted in reality. Okay, before we get to quarks let's see what 'hostile' means :) >From Merriam-Webster http://www.learnersdictionary.net/dictionary/hostile : 1 a : of or relating to an enemy b : marked by malevolence c : openly opposed or resisting d (1) : not hospitable (2) : having an intimidating, antagonistic, or offensive nature Now, I think the OP was perceived by Ben as doing something which he thinks is not good. We most probably agree on this. In other words, Ben was opposing the OP's ideas. Yet in other words, Ben was resisting the OP's ideas. And yet in other words, Ben was not hospitable. So perhaps 1a and 1b doesn't quite fit the bill since Ben didn't go as far as call the OP an enemy and he wasn't evil or wished harm to the OP, but 1c and d(1) are certainly correctly describing his behavior and to a lesser extent d(2) as well. And the quarks...... :) Cheers, Daniel > And that's a fact. ;-) > > Shall we now discuss the nature of the space/time continuum and the > exact reality of quarks? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 4 07:19:36 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 4 Nov 2009 13:19:36 +0100 Subject: Pyfora, a place for python In-Reply-To: <02fff632$0$1326$c3e8da3@news.astraweb.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: >>> Hi everyone, >>> >>> I am proud to announce the release of Pyfora (http://pyfora.org), an >>> online community of Python enthusiasts to supplement comp.lang.python >>> and #python. While the site is small right now, please feel free to >>> register and post any questions or tips you may have. >> >> I'll feel free to not even bookmark it. I'm sorry, but it is just a bad >> idea. >> >> Your forum cannot (and should not) compete either with Python's official >> newsgroup, IRC channel and mailing list or with popular, well- made and >> well-frequented general programming sites like stackoverflow.com. > > Are you saying that now that comp.lang.python and stackoverflow exists, > there no more room in the world for any more Python forums? Exactly. > I think that's terrible. Exactly. > Saketh, would you care to give a brief explanation for sets your forum > apart from the existing Python forums, and why people should choose to > spend time there instead of (or as well as) the existing forums? What > advantages does it have? Yes, this is about the right kind of response I think everybody deserves who puts energy/enthusiasm/effort/time into putting together a python-related forum. Cheers, Daniel >> It would be the Internet equivalent of looking for a poker tournament in >> a desert valley instead of driving half an hour less and going to Las >> Vegas: there are no incentives to choose your forum, except perhaps for >> isolationists who value being a big fish in a small pond over being part >> of a community. > > (Funny you mention Las Vegas -- it started off as a tiny little town in > the middle of the desert too.) > > How about avoiding the noise and obtrusive advertising and bright lights > of Las Vegas, the fakery, the "showmanship", the horrible fake pyramid > and has-been celebrities, the crowds, the tackiness, the high prices, the > bright lights that never turn off (Las Vegas is the brightest city on > Earth)... if you're interested in poker without all the mayonnaise, maybe > that poker tournament away from the tourists is exactly what you need. > > Personally, if I wanted to gamble, the last place I would go is any house > which had gold-plated taps in the bathrooms. That tells me the house's > percentage is *way* too high. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From captntoad at galaxy42.net Wed Nov 4 07:59:57 2009 From: captntoad at galaxy42.net (Todd Lovette) Date: Wed, 04 Nov 2009 05:59:57 -0700 Subject: python 3.1.1 and --libdir option broken. Message-ID: <4AF17ACD.8000804@galaxy42.net> I've been trying to install Python 3.1.1 into /usr/lib64 via the configure script option --libdir, but it is ignored and Python 3.1.1 is installed in /usr/lib. Has anyone ran into this problem and solved it? Looking at the Makefile is seems as thought /lib in hard coded into the file. Any suggestions to fix this? Todd :-) From dotancohen at gmail.com Wed Nov 4 08:29:50 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 4 Nov 2009 15:29:50 +0200 Subject: Pyfora, a place for python In-Reply-To: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> Message-ID: <880dece00911040529o7c379535qc45f451396e0767d@mail.gmail.com> > My personal preference would be a link in each sub-paragraph in the official > documentation to a wiki page devoted to that specific aspect of the Python > language. A place were users could augment the documentation by providing > sample code and by expanding out the documentation for those of us who don't > live and breath Python in our sleep. Real Python coders would not click on > the user wiki links and all of us newbies could communicate with each other. > But until a place like that exists, perhaps Pyfora will get us part way > there. > The PHP documentation has this feature: user comments right on the same page (no link to a wiki, though). It's great, most of the best usage practices that I have learned in that language came from the user's comments, not from the official documentation itself. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From no.email at please.post Wed Nov 4 08:33:53 2009 From: no.email at please.post (kj) Date: Wed, 4 Nov 2009 13:33:53 +0000 (UTC) Subject: How to test urllib|urllib2-using code? Message-ID: I want to write some tests for code that uses both urllib and urllib2. I would like to be able to run these tests locally. Are there modules to facilitate the writing of such tests (e.g. for setting up a mock web server locally, etc.)? BTW, in the Perl world, one very easy way to learn how to write tests for stuff is to study the test suites that come with every module distribution, and which are usually readily recognizable as a bunch of files of the form t/*.t. (E.g. I'm sure I could find some good answers to my question above if I could look at the test suites for urllib and urllib2, but I can't find them anywhere. In fact, I don't even know what exactly I should be looking for.) Where can I find the equivalent for Python distributions? Thanks! kynn From stefan_ml at behnel.de Wed Nov 4 08:35:30 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 04 Nov 2009 14:35:30 +0100 Subject: elementtree XML() unicode In-Reply-To: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> References: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> Message-ID: <4af18322$0$7620$9b4e6d93@newsspool1.arcor-online.net> John Machin, 04.11.2009 02:56: > On Nov 4, 12:14 pm, Kee Nethery wrote: >> The reason I am confused is that getResponse2 is classified as an >> "str" in the Komodo IDE. I want to make sure I don't lose the non- >> ASCII characters coming from the URL. > > str is all about 8-bit bytes. True in Py2.x, false in Py3. What you mean is the "bytes" type, which, sadly, was named "str" in Python 2.x. The problem the OP ran into was due to the fact that Python 2.x handled "ASCII characters in a unicode string" <-> "ASCII encoded byte string" conversion behind the scenes, which lead to all sorts of trouble to loads of people, and was finally discarded in Python 3.0. Stefan From stefan_ml at behnel.de Wed Nov 4 08:41:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 04 Nov 2009 14:41:52 +0100 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: <4af184a0$0$7621$9b4e6d93@newsspool1.arcor-online.net> Kevin Ar18, 02.11.2009 21:44: >> According to the lxml installation instructions you linked=2C >> the windows lxml binary is statically linked and you do not >> need to install the libraries separately. > > The install instructions say" "You need libxml2 and libxslt" and then links= > to where to download the binaries=3B this means I need to install separate= > ly=2C right? If not=2C those are aweful instructions. :) Not being able to scroll down half a page (to the section titled "MS Windows") is not an excuse for blaming the docs. > I can download the binaries=2C but I don't know where or how to install the= > m? Is there any instructions anywhere? Yes, see the short section titled "Installation" at the top of the installation instructions page. Stefan From henning.bredel at gmx.de Wed Nov 4 08:52:51 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 04 Nov 2009 13:52:51 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4af18733$0$6591$9b4e6d93@newsspool3.arcor-online.net> Gabriel, thanks for your reply. See my comments below. On Tue, 03 Nov 2009 21:31:27 -0300, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel > escribi?: >> On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: > > Then forget about the code you read in that blog post, doesn't apply to > your use case. Well, but it shows how to mount plugins into the application without creating instances instantly. I only use one plugin/module at a time, so I'd like to avoid holding instances which aren't used. If the solution from the blogpost are meant completely different, I'd appreciate if you could point me on some concrete arguments why I shouldn't realize plugin mechanism in that way. BTW: I made it work now (was only a(nother) misinterpretation of how a callable should look like. > Try something like this: [...] > class PluginManager: > def __init__(self, plugin_directory): > self.plugin_directory = plugin_directory self.plugins = [] > > def load_all(self): > for fn in glob(os.path.join(self.plugin_directory, '*.py')): > namespace = {} > execfile(fn, namespace) > for name, obj in namespace.items(): > if (isinstance(obj, type) and > issubclass(obj, Plugin) and > obj is not Plugin): > # obj is a Plugin subclass > cls = obj > print cls.__name__, fn > print cls.__doc__ > print > plugin = cls(self) # call the constructor > self.plugins.append(plugin) [...] Yes, I get your point. But you instantiate all available plugins. I'd like to avoid that. Will a callable like `plugin().initialize' avoid that, or is an instance created immediately when passing this callable? > Plugin is the base class; all plugins must inherit from it. PluginMgr > scans the plugin directory, executes all modules it finds there (be > careful...), and looks for Plugin subclasses. Then creates an instance > of each Plugin subclass. Well, as far I understand it, I'd say that the ActionProvider class from the blogpost is the (nearly) the same as your Plugin base class. All new plugins has to implement the abstract ActionProvider class. The module loading/recognizing is done by my main application. So what would be the main difference here? Thanks for your advice Henning From mrkafk at gmail.com Wed Nov 4 09:00:38 2009 From: mrkafk at gmail.com (mk) Date: Wed, 04 Nov 2009 15:00:38 +0100 Subject: Request for comments - concurrent ssh client Message-ID: Hello everyone, Since I'm not happy with shmux or pssh, I wrote my own "concurrent ssh" program for parallel execution of SSH commands on multiple hosts. Before I release program to the wild, I would like to hear (constructive) comments on what may be wrong with the program and/or how to fix it. (note: the program requires paramiko ssh client module) #!/usr/local/bin/python -W ignore::DeprecationWarning import time import sys import os import operator import paramiko import threading import subprocess import optparse usage = "Usage: cssh [options] IP1 hostname2 IP3 hostname4 ...\n\n(IPs/hostnames on the commandline are actually optional, they can be specified in the file, see below.)" op = optparse.OptionParser(usage=usage) op.add_option('-c','--cmd',dest='cmd',help="""Command to run. Mutually exclusive with -s.""") op.add_option('-s','--script',dest='script',help="""Script file to run. Mutually exclusive with -c. Script can have its own arguments, specify them in doublequotes, like "script -arg arg".""") op.add_option('-i','--script-dir',dest='scriptdir',help="""The directory where script will be copied and executed. Defaults to /tmp.""") op.add_option('-l','--cleanup',dest='cleanup',action='store_true',help="""Delete the script on remote hosts after executing it.""") op.add_option('-f','--file',dest='file',help="""File with hosts to use, one host per line. Concatenated with list of hosts/IP addresses specified at the end of the commandline. Optionally, in a line of the file you can specify sequence: "Address/Hostname Username Password SSH_Port" separated by spaces (additional parameters can be specified on a subset of lines; where not specified, relevant parameters take default values).""") op.add_option('-d','--dir',dest='dir',help='Directory for storing standard output and standard error of command. If specified, directory will be created, with subdirs named IPs/hostnames and relevant files stored in those subdirs.') op.add_option('-u','--username',dest='username',help="""Username to specify for SSH. Defaults to 'root'.""") op.add_option('-p','--password',dest='password',help="""Password. Password is used first; if connection fails using password, cssh uses SSH key (default or specified).""") op.add_option('-o','--port',dest='port',help="""Default SSH port.""") op.add_option('-k','--key',dest='key',help="""SSH Key file. Defaults to '/root/.ssh/id_dsa'.""") op.add_option('-n','--nokey',dest='nokey',action="store_true", help="""Turns off using SSH key.""") op.add_option('-t','--timeout',dest='timeout',help="""SSH connection timeout. Defaults to 20 seconds.""") op.add_option('-m','--monochromatic',dest='mono',action='store_true',help="""Do not use colors while printing output.""") op.add_option('-r','--maxthreads',dest='maxthreads',help="""Maximum number of threads working concurrently. Default is 100. Exceeding 200 is generally not recommended due to potential exhaustion of address space (each thread can use 10 MB of address space and 32-bit systems have a maximum of 4GB of address space).""") op.add_option('-q','--quiet',dest='quiet',action='store_true',help="""Quiet. Do not print out summaries like IPs for which communication succeeded or failed, etc.""") # add resource file? (opts, args) = op.parse_args() failit = False if opts.cmd == None and opts.script == None: print "You have to specify one of the following: command to run, using -c command or --cmd command, or script to run, using -s scriptfile or --script scriptfile." print failit = True if opts.cmd != None and opts.script != None: print "Options command (-c) and script (-s) are mutually exclusive. Specify either one." print failit = True if opts.cmd == None and opts.script != None: try: scriptpath = opts.script.split()[0] scriptfo = open(scriptpath,'r') scriptfo.close() except IOError: print "Could not open script file %s." % opts.script print failit = True if opts.file == None and args == []: print "You have to specify at least one of the following:" print " - list of IPs/hostnames at the end of the command line (after all options)" print " - list of IPs/hostnames stored in file specified after -f or --file option (like: -f hostnames.txt)" print " You can also specify both sources. In that case IP/hostname lists will be concatenated." print failit = True if opts.password == None and opts.nokey: print "Since using key has been turned off using -n option, you have to specify password using -p password or --password password." print failit = True if opts.key is not None and opts.nokey: print "Options -n and -k keyfile are mutually exclusive. Specify either one." print failit = True if failit: sys.exit(0) if opts.scriptdir == None: opts.scriptdir = '/tmp' if opts.cleanup == None: opts.cleanup = False if opts.key == None: opts.key = '/root/.ssh/id_dsa' if opts.port == None: opts.port = 22 if opts.nokey: opts.key = None if opts.timeout == None: opts.timeout = 20 if opts.mono == None: opts.mono = False if opts.maxthreads == None: opts.maxthreads = 100 if opts.quiet == None: opts.quiet = False HEADER = '\033[95m' BLACK = '\033[30m' RED = '\033[31m' GREEN = '\033[32m' YELLOW = '\033[33m' BLUE = '\033[34m' OKBLUE = '\033[94m' MAGENTA = '\033[35m' CYAN = '\033[36m' WHITE = '\033[37m' ENDC = '\033[0m' if opts.mono: HEADER = BLACK = RED = GREEN = YELLOW = OKBLUE = BLUE = MAGENTA = CYAN = WHITE = ENDC = '' hosts = args[:] fhosts = [] fname = opts.file if fname is not None: try: fhosts = open(fname).readlines() except IOError, e: print "Error:", str(e) sys.exit(1) hosts.extend(fhosts) hosts = [ s.strip() for s in hosts if s != '' and s != None and s != '\n' ] hosts = [ s.split() for s in hosts ] if hosts == []: print "Error: list of hosts is empty. Quitting" sys.exit(1) class SSHThread(threading.Thread): def __init__(self, lock, cmd, ip, username, sshprivkey=None, passw=None, port=22, script=None, scriptdir=None): threading.Thread.__init__(self) self.lock = lock self.cmd = cmd self.ip = ip self.username = username self.sshprivkey = sshprivkey self.passw = passw self.port = port self.conobj = None self.confailed = True if script != None: scriptcomp = script.strip().split() self.scriptpath = scriptcomp[0] self.scriptname = self.scriptpath.split('/')[-1] self.scriptargs = script[len(scriptpath):] self.scriptdir = scriptdir.strip().rstrip('/') self.rspath = self.scriptdir + '/' + self.scriptname self.finished = False def ping(self, lock, ip): subp = subprocess.Popen(['/bin/ping', '-c', '1', ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) so, se = subp.communicate() return (so, se) def ssh_connect(self): self.conobj = paramiko.SSHClient() aap = paramiko.AutoAddPolicy() self.conobj.set_missing_host_key_policy(aap) loginsuccess = False if self.passw is not None: try: self.conobj.connect(self.ip, username=self.username, password=self.passw, port=self.port, timeout=opts.timeout, allow_agent=False, look_for_keys = False) loginsuccess = True except: pass if not loginsuccess and self.sshprivkey is not None: try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except: pass if not loginsuccess: self.conobj = None self.finished = True def execcmds(self): so = se = '' try: si, so, se = self.conobj.exec_command(self.cmd) sol = so.readlines() sel = se.readlines() so = ''.join([ s.replace('\r\n','\n') for s in sol ]) se = ''.join([ s.replace('\r\n','\n') for s in sel ]) except: pass return (so, se) def sendscript(self): fo = open(self.scriptpath,'rb') cnt = ''.join(fo.readlines()) transport = self.conobj.get_transport() channel = transport.open_session() destpath = self.scriptdir + '/' + self.scriptname try: channel.exec_command('scp -t -v %s\n' % destpath) except paramiko.SSHException, e: channel.close() return str(e) fl = 'C0755 %d 1\n' % os.path.getsize(self.scriptpath) channel.send(fl) while not channel.recv_ready(): time.sleep(0.1) try: channel.send(cnt) except socket.error, e: channel.close() return str(e) channel.close() return '' def setcmdtoscript(self): self.cmd = self.scriptdir + '/' + self.scriptname + self.scriptargs def execcmdonscript(self, cmd): si, so, se = self.conobj.exec_command(cmd) sol = so.readlines() sel = se.readlines() if sol != [] or sel != []: self.lock.acquire() print RED + "Host %s, Error while executing %s on script:" % (self.ip, cmd), "".join(sel), "".join(sol) + ENDC self.lock.release() def chmodscript(self): # just in case, as sometimes and on some operating systems the execution flags on the script are not always set self.execcmdonscript('chmod 0755 %s' % self.rspath) def delscript(self): self.execcmdonscript('rm -f %s' % self.rspath) def run(self): self.ssh_connect() so, se = ('', '') res = '' if self.conobj != None: if self.cmd == None: res = self.sendscript() self.setcmdtoscript() self.chmodscript() if res == '': so, se = self.execcmds() if opts.cleanup: time.sleep(0.5) self.delscript() self.lock.acquire() print OKBLUE + "%-20s" % self.ip + ENDC, ":", if self.conobj == None: print RED + "SSH connection failed" + ENDC self.confailed = True elif res != '': print RED + "Sending script failed: %s" % res + ENDC self.confailed = True else: self.confailed = False print OKBLUE + "SSH connection successful" + ENDC print so if se != '': print MAGENTA + "command standard error output:" + ENDC print se if opts.dir != None: if not os.path.isdir(opts.dir): os.mkdir(opts.dir) path = opts.dir + os.sep + self.ip if not os.path.isdir(path): os.mkdir(path) of = open(path + os.sep + 'stdout','w') of.write(so) of.close() of = open(path + os.sep + 'stderr','w') of.write(se) of.close() self.lock.release() self.finished = True def sshclose(self): if self.conobj != None: self.conobj.close() lock = threading.Lock() queue = [] thfinished = [] def getparams(h): ip = h[0] try: username = h[1] except IndexError: username = opts.username try: passw = h[2] except IndexError: passw = opts.password port = None try: port = int(h[3]) except IndexError: port = 22 except ValueError, e: print RED + "%-20s" % ip, ": error converting port:", str(e) + ENDC return (ip, username, passw, port) while len(hosts) > 0: if len(queue) <= opts.maxthreads: h = hosts.pop() (ip, username, passw, port) = getparams(h) if port != None: th = SSHThread(lock, opts.cmd, ip, username=username, sshprivkey=opts.key, passw=passw, port=port, script=opts.script, scriptdir=opts.scriptdir) queue.append((ip, th)) th.daemon = True th.start() else: thfinished.append((ip,None)) else: time.sleep(1) for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) queue.remove((ip,th)) while len(queue) > 0: for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) queue.remove((ip,th)) time.sleep(1) if not opts.quiet: print print OKBLUE + 'Communication SUCCEEDED for following IP addresses (SSH could open connection):' + ENDC for ip, th in thfinished: if th != None and not th.confailed: print ip print print OKBLUE + 'Communication FAILED for following IP addresses (SSH could not open connection / error in parameters):' + ENDC for ip, th in thfinished: if th == None or th.confailed: print ip From s.selvamsiva at gmail.com Wed Nov 4 09:04:27 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Wed, 4 Nov 2009 19:34:27 +0530 Subject: how to remove the same words in the paragraph In-Reply-To: <4AF0B54A.7090602@tim.thechases.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote: > kylin wrote: > >> I need to remove the word if it appears in the paragraph twice. could >> some give me some clue or some useful function in the python. >> > > Sounds like homework. To fail your class, use this one: > > >>> p = "one two three four five six seven three four eight" > >>> s = set() > >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) > one two three four five six seven eight > > which is absolutely horrible because it mutates the set within the list > comprehension. The passable solution would use a for-loop to iterate over > each word in the paragraph, emitting it if it hadn't already been seen. > Maintain those words in set, so your words know how not to be seen. ("Mr. > Nesbitt, would you please stand up?") > > Can we use inp_paragraph.count(iter_word) to make it simple ? This also assumes your paragraph consists only of words and whitespace. But > since you posted your previous homework-sounding question on stripping out > non-word/whitespace characters, you'll want to look into using a regexp like > "[\w\s]" to clean up the cruft in the paragraph. Neither solution above > preserves non white-space/word characters, for which I'd recommend using a > re.sub() with a callback. Such a callback class might look something like > > >>> class Dedupe: > ... def __init__(self): > ... self.s = set() > ... def __call__(self, m): > ... w = m.group(0) > ... if w in self.s: return '' > ... self.s.add(w) > ... return w > ... > >>> r.sub(Dedupe(), p) > > where I leave the definition of "r" to the student. Also beware of > case-differences for which you might have to normalize. > > You'll also want to use more descriptive variable names than my one-letter > tokens. > > -tkc > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From lutz.horn at fastmail.fm Wed Nov 4 09:06:45 2009 From: lutz.horn at fastmail.fm (Lutz Horn) Date: Wed, 04 Nov 2009 15:06:45 +0100 Subject: How to test urllib|urllib2-using code? In-Reply-To: References: Message-ID: Hi, kj wrote: > I want to write some tests for code that uses both urllib and > urllib2. Take a look at the discussion under the title "How can one mock/stub python module like urllib" at stackoverflow: http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python-module-like-urllib Lutz From goon12 at gmail.com Wed Nov 4 09:08:12 2009 From: goon12 at gmail.com (Joe Riopel) Date: Wed, 4 Nov 2009 09:08:12 -0500 Subject: unittest & setup In-Reply-To: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> References: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Message-ID: <6a2ccd190911040608o72f5a971lfd3ad73d6e74fa3f@mail.gmail.com> On Tue, Nov 3, 2009 at 11:02 PM, Jonathan Haddad wrote: > I've got a class, in the constructor it loads a CSV file from disc.? I'd > like only 1 instance of the class to be instantiated.? However, when running > multiple unit tests, multiple instances of the class are created.? What's > the best way for me to avoid this?? It takes about a few seconds to load the > CSV file. This post that might be worth reading, as it relates to testing with singletons. http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ As is this http://misko.hevery.com/code-reviewers-guide/ From ethan at stoneleaf.us Wed Nov 4 09:36:46 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Nov 2009 06:36:46 -0800 Subject: self.__dict__ tricks In-Reply-To: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: <4AF1917E.5090806@stoneleaf.us> Dennis Lee Bieber wrote: > Perfectly valid answer -- there are no fish as there is no > Atlantic sea Steven D'Aprano wrote: > Once in the distant past, there were no fish in what would become the > Atlantic Ocean (not sea) What's with the bias against the word 'sea'? sea ?noun 1. the salt waters that cover the greater part of the earth's surface. 2. a division of these waters, of considerable extent, more or less definitely marked off by land boundaries: the North Sea. 3. one of the seven seas; ocean. I'd say the Atlantic qualifies! ;-) ~Ethan~ From james at agentultra.com Wed Nov 4 09:39:32 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 04 Nov 2009 09:39:32 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <87pr7ywdzv.fsf@agentultra.com> Steven D'Aprano writes: > On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > >> However in this case the procedure by which we derive the value is not >> important or even interesting. It is much more succinct to think of the >> operation as a value and express it accordingly. There's no need to >> clutter the mind with extra name bindings and iteration keywords. They >> won't make our idea any more clear. >> >> dot_product = map(mul, vec1, vec2) >> >> vs >> >> dot_product = [a * b for a, b in zip(vec1, vec2)] >> >> It's very clear, at least to me, what a dot-product is in this case. > > Except it's not. > > The dot product of two vectors returns a scalar, not another vector: > http://en.wikipedia.org/wiki/Dot_product > > So what you want is: > > dot_product = sum(map(mul, vec1, vec2)) Derh. Thanks for the catch. My bad. >> Adding in the loop construct and name bindings doesn't enhance my >> understanding of what a dot-product is. I don't need to see the loop >> construct at all in this case. A dot product is simply the >> multiplication of each element in a vector sequence. > > What you need is to define a function dot-product, and not hijack the > name for a local value. Then the function's implementation is irrelevant > to you: it could use a list comp, or could use map, it could use a for- > loop, a while loop, recursion, or black magic: > > scalar = dot_product(vec1, vec2) Even better. But now I'm afraid the example is running away from the point. So to summarize: 1. Extra name bindings and loop keywords aren't always easier to read. 2. Expressing what we want rather than how we get it is much more clear. and (third dirty argument added) 3. List comprehensions leak their name bindings to the surrounding scope. :p Have a nice day. :) From ethan at stoneleaf.us Wed Nov 4 09:47:35 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Nov 2009 06:47:35 -0800 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> <4AF0959D.2020307@stoneleaf.us> Message-ID: <4AF19407.6050508@stoneleaf.us> Daniel Fetchinson wrote: >>>>>I was referring to this comment by Ben: >>>>> >>>>>"Suggestion: Please don't make efforts to fragment the community." >>>>> >>>>>This IMHO is hostile, because it presupposes that the mere goal of the >>>>>OP is fragmenting the community >>>> >>>>It presupposes nothing of any goal. It describes a predictable result of >>>>the OP's efforts, and requests those efforts to cease. >>>> >>>>So I deny the characterisation of that request as hostile. >>> >>[mass snippitude] >> >> >>>If yes, with the substitution A = Ben and B = OP we get "in order for >>>Ben's request to make sense, Ben has to assume that the OP is making >>>an effort to fragment the community". This assumption on the part of >>>Ben, I think, is hostile, since it assumes that the OP is making an >>>effort to do something not nice. Whether the OP is indeed doing >>>something not nice, is irrelevant. If the OP does do something not >>>nice, the hostility is warranted. If the OP is not doing anything not >>>nice, the hostility is unwarranted. But the fact that Ben was hostile >>>is a fact :) >> >>You were doing fine until you brought in the hostility. I must agree >>with Ben that his comment was not hostile. It was merely a statement. >>Not an exclamation, no name calling, just a plain request rooted in reality. > > > Okay, before we get to quarks let's see what 'hostile' means :) >>From Merriam-Webster http://www.learnersdictionary.net/dictionary/hostile : > > 1 a : of or relating to an enemy > b : marked by malevolence > c : openly opposed or resisting > d (1) : not hospitable > (2) : having an intimidating, antagonistic, or offensive nature > > > Now, I think the OP was perceived by Ben as doing something which he > thinks is not good. We most probably agree on this. In other words, > Ben was opposing the OP's ideas. Yet in other words, Ben was resisting > the OP's ideas. And yet in other words, Ben was not hospitable. So > perhaps 1a and 1b doesn't quite fit the bill since Ben didn't go as > far as call the OP an enemy and he wasn't evil or wished harm to the > OP, but 1c and d(1) are certainly correctly describing his behavior > and to a lesser extent d(2) as well. AH hahahahahahah. Okay, you got me. However, if we're going to start looking up the exact denotations of words to justify our remarks, surely we should also pay attention to the connotations? In normal, everyday speach the denotations of 'resisting' and 'opposed to' are very different from 'hostile' -- hence such phrases as 'resisting with hostility' and 'hostiley opposed to'. In other words, I'll grant you the win of that hair, but I still would not characterize it as hostile. ;-) ~Ethan~ From simon at mullis.co.uk Wed Nov 4 09:54:39 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 4 Nov 2009 15:54:39 +0100 Subject: Calling a method with a variable name Message-ID: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Hi All, I'm collating a bunch of my utility scripts into one, creating a single script to which I will symbolic link multiple times. This way I only have to write code for error checking, output-formatting etc a single time. So, I have ~/bin/foo -> ~/Code/python/mother_of_all_utility_scripts.py ~/bin/bar -> ~/Code/python/mother_of_all_utility_scripts.py ~/bin/baz -> ~/Code/python/mother_of_all_utility_scripts.py I would like "bar" to run the bar method (and so on). ------------- class Statistic() def __init__(self): pass def foo(self): return "foo!" def bar(self): return "bar!" # ... and so on... def main(): stats_obj = Statistic() name = re.sub("[^A-Za-z]", "", sys.argv[0]) method = getattr(stats_obj, name, None) if callable(method): stats_obj.name() # <------------HERE else: print "nope, not sure what you're after...." ----------- However, as I'm sure you've all noticed already, there is no method called "name". I would really prefer to get a nudge in the right direction before I start evaling variables and so on. Does my approach make sense? If not, please give me a hint... Thanks SM From deets at nospam.web.de Wed Nov 4 09:57:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 04 Nov 2009 15:57:24 +0100 Subject: Calling a method with a variable name References: Message-ID: <7ldj2kF38sg9oU1@mid.uni-berlin.de> Simon Mullis wrote: > Hi All, > > I'm collating a bunch of my utility scripts into one, creating a > single script to which I will symbolic link multiple times. This way > I only have to write code for error checking, output-formatting etc a > single time. > > So, I have > > ~/bin/foo -> ~/Code/python/mother_of_all_utility_scripts.py > ~/bin/bar -> ~/Code/python/mother_of_all_utility_scripts.py > ~/bin/baz -> ~/Code/python/mother_of_all_utility_scripts.py > > I would like "bar" to run the bar method (and so on). > > ------------- > class Statistic() > def __init__(self): > pass > > def foo(self): > return "foo!" > > def bar(self): > return "bar!" > > # ... and so on... > > def main(): > stats_obj = Statistic() > name = re.sub("[^A-Za-z]", "", sys.argv[0]) > method = getattr(stats_obj, name, None) > if callable(method): > stats_obj.name() # <------------HERE > else: > print "nope, not sure what you're after...." > ----------- > > However, as I'm sure you've all noticed already, there is no method > called "name". I would really prefer to get a nudge in the right > direction before I start evaling variables and so on. > > Does my approach make sense? If not, please give me a hint... You are almost there. Why don't you do if callable(method): method() ? Diez From lallous at lgwm.org Wed Nov 4 10:00:33 2009 From: lallous at lgwm.org (lallous) Date: Wed, 4 Nov 2009 16:00:33 +0100 Subject: C api and exception handling References: Message-ID: Thanks for your help Carl as usual. Will go with the getattr override method which is cleaner as you explained. Regards, Elias "Carl Banks" wrote in message news:f02c069c-e536-4c6b-b114-2215aa61129e at k17g2000yqh.googlegroups.com... > On Nov 2, 7:16 am, "lallous" wrote: >> Hello, >> >> Is there is a way, using the Python C api, to install an exception >> handler >> that: >> - will be triggered when an exception occurs >> - analyze the reason of the exception >> - correct the situation and try again (something like exception handling >> on >> windows where the exception handler can retrieve the registers >> context->faulting instruction->fix situation if needed->restart execution >> from the same point) > > Python has no concept of "retrying", at either the Python or C API > level. You might be able to do something Evil in C to get this effect > but I don't recommend it, it'll be fundamentally averse to how Python > works and future versions are likely to break it. > > >> Since I will be asked: "what are you trying to achieve?", this is what I >> want: >> >> func_call("hello") <- no exceptions, good code: function is defined and >> called properly >> SomeUndefinedFunction("x", "y") <- undefined function call will trigger >> an >> exception. I want my python/C exception handler to inspect the reason of >> the >> exception, if it was a call to an undefined function call then redirect >> the >> execution to a certain method, say: >> ExecuteByName("SomeUndefinedFunction", >> "x", "y") >> >> I know if I create a small class with getattr hooked, what I want can be >> achieved. > > > I'd do it that way. There is ordinarily no way to hook into a plain > function call like SomeUndefinedFunction() in Python; if you go around > hacking up the interpreter to do that users will be highly confused > and surprised. > > OTOH, hooking into attributes is pretty well-known. When a person > sees attribute notation they know there's an opportunity to do weird > stuff. When a strange function is called, they will be like, "oh, > someone overrode __getattr__". > > >> But can it be done otherwise (without using a class and instead relying >> on >> exception handlers and correcting the exception)? > > Just forget about exception handling. If you REALLY insist on doing > this, and I highly recommend against it, the best chance you have is > to try to hook into the importing process and load a module that uses > a custom dictionary object. > > > Carl Banks From carsten.haese at gmail.com Wed Nov 4 10:04:55 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 10:04:55 -0500 Subject: Calling a method with a variable name In-Reply-To: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> References: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Message-ID: Simon Mullis wrote: > def main(): > stats_obj = Statistic() > name = re.sub("[^A-Za-z]", "", sys.argv[0]) > method = getattr(stats_obj, name, None) > if callable(method): > stats_obj.name() # <------------HERE > else: > print "nope, not sure what you're after...." > ----------- > > However, as I'm sure you've all noticed already, there is no method > called "name". I would really prefer to get a nudge in the right > direction before I start evaling variables and so on. At the point you marked "HERE", you've already found the method, and you have determined that it is callable. You just need to call it. Like this: method(). HTH, -- Carsten Haese http://informixdb.sourceforge.net From python.list at tim.thechases.com Wed Nov 4 10:09:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Nov 2009 09:09:12 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: <4AF19918.9050406@tim.thechases.com> > Can we use inp_paragraph.count(iter_word) to make it simple ? It would work, but the performance will drop off sharply as the length of the paragraph grows, and you'd still have to keep track of which words you already printed so you can correctly print the first one. So you might as well not bother with counting. -tkc From simon at mullis.co.uk Wed Nov 4 10:20:50 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 4 Nov 2009 16:20:50 +0100 Subject: Calling a method with a variable name In-Reply-To: References: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Message-ID: <23d7e1bb0911040720s211f14b7l9c961bdaa17d6efa@mail.gmail.com> May I be the first to say "Doh!" Problem solved, many thanks to both Carsten and Diez! SM 2009/11/4 Carsten Haese : > Simon Mullis wrote: >> def main(): >> ? ? stats_obj = Statistic() >> ? ? name = re.sub("[^A-Za-z]", "", sys.argv[0]) >> ? ? method = getattr(stats_obj, name, None) >> ? ? if callable(method): >> ? ? ? ? stats_obj.name() ? ? ? ? ? ? ?# ?<------------HERE >> ? ? else: >> ? ? ? ? print "nope, not sure what you're after...." >> ----------- >> >> However, as I'm sure you've all noticed already, there is no method >> called "name". I would really prefer to get a nudge in the right >> direction before I start evaling variables and so on. > > At the point you marked "HERE", you've already found the method, and you > have determined that it is callable. You just need to call it. Like > this: method(). > > HTH, > > -- > Carsten Haese > http://informixdb.sourceforge.net > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Simon Mullis _________________ simon at mullis.co.uk From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 4 10:53:56 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Nov 2009 16:53:56 +0100 Subject: About one class/function per module In-Reply-To: <87639rizob.fsf@benfinney.id.au> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <7lajrkF3c97onU1@mid.uni-berlin.de> <87639rizob.fsf@benfinney.id.au> Message-ID: <4af1a394$0$428$426a74cc@news.free.fr> Ben Finney a ?crit : > "Diez B. Roggisch" writes: > >> Don't get me wrong - innovation often comes from scratching ones >> personal itch. But you seem to be suffering from a rather bad case of >> neurodermatitis. > > +1 QOTW > Make it +2 QOTW !-) From victorsubervi at gmail.com Wed Nov 4 10:57:47 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 4 Nov 2009 10:57:47 -0500 Subject: Calendar Problem In-Reply-To: <4AF0C317.3010109@ieee.org> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> <4AF0C317.3010109@ieee.org> Message-ID: <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> Well, you're right. That's what I initially had. My server, that I am in the process of leaving, rejected that syntax. Lovely. Thanks, V On Tue, Nov 3, 2009 at 6:56 PM, Dave Angel wrote: > > > MichaB Klich wrote: > >> Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): >> >> >>> Hi; >>> I have the following: >>> >>> import calendar, datetime >>> >>> myCal =alendar.calendar(6) >>> today =atetime.date.today() >>> day =oday.day >>> mo =oday.month >>> yr =oday.year >>> month =yCal.monthdayscalendar(yr, mo) >>> >>> >>> The last line throws errors no matter how I try and tweak it. The current >>> incarnation complains about myCal being a string. What do? >>> TIA, >>> Victor >>> >>> >>> >> >> You should use >> >> myCal =calendar.Calendar(6) >> >> This creates calendar.Calendar object. >> >> >> > Right. But I wanted to tell the OP what to do with an error like this. > > > You should post the actual error traceback, and tell us what version of > Python you're using: > > Traceback (most recent call last): > File "M:\Programming\Python\sources\dummy\stuff2.py", line 15, in > > month = myCal.monthdayscalendar(yr, mo) > AttributeError: 'str' object has no attribute 'monthdayscalendar' > > > Now, since it says that myCal is a 'str' object, the next thing you should > do is look at the value. I get an actual printable calendar for a year. So > clearly, it's not the Calendar object you were looking for. So you need to > change from the calendar() function to the Calendar() constructor. > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 4 11:07:00 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Nov 2009 17:07:00 +0100 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <4af1a6a4$0$420$426a74cc@news.free.fr> Peng Yu a ?crit : > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead when >> actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. Been here, done that. You obviously don't have enough experience with Python to understand why your "organization" suck. And given your apparent tendency to insist on imposing your own views / preconceptions on the language instead of learning how to use it properly (the canonical "I can write Java in any language" syndrom), it will probably take a long time before you get there - if you ever get there at all. My friendly (really) advice is to stop fighting the langage and start going with the flow. (snip lots of stuff that require neither "one line of code per file" nor fancy scripts) From Nadav.C at qualisystems.com Wed Nov 4 11:29:52 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 18:29:52 +0200 Subject: regexp help Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> Hello all, I'm trying to write regexp that find all files that are not with next extensions: exe|dll|ocx|py, but can't find any command that make it. Please, help me Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: From VBoycheva at jonesedmunds.com Wed Nov 4 11:34:52 2009 From: VBoycheva at jonesedmunds.com (Valentina Boycheva) Date: Wed, 4 Nov 2009 11:34:52 -0500 Subject: Pyfora, a place for python References: Message-ID: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> >>Daniel Fetchinson writes: > >Probably this thread is going by far too far :) >Ben Finney [ben+python at benfinney.id.au] writes: > Agreed. I was following this discussion first with curiosity and then with increasing disbelief. As a scientist and a programmer, I always considered myself belonging to a group of people who are broad-minded and task-oriented. Being an occasional Python programmer, I subscribed to this list in the hopes of learning from the pros. Most of the time I do. But I also see a disturbing trend of petty bickering, splitting hairs and one-upmanship. I understand there will be occasional language slips and misconstrued jokes but can we please stick to the topic and remain courteous at all times? I am seriously considering unsubscribing from this UL (and maybe joining Pyfora.) From carsten.haese at gmail.com Wed Nov 4 11:35:48 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 11:35:48 -0500 Subject: Calendar Problem In-Reply-To: <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> <4AF0C317.3010109@ieee.org> <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> Message-ID: Victor Subervi wrote: > That's what I initially had. My server, that I am in > the process of leaving, rejected that syntax. What version of Python does that server use? The calendar.Calendar class first appeared in Python 2.5. I suspect your server is using an older version. -- Carsten Haese http://informixdb.sourceforge.net From simon at brunningonline.net Wed Nov 4 11:43:48 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 16:43:48 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> Message-ID: <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> 2009/11/4 Nadav Chernin : > I?m trying to write regexp that find all files that are not with next > extensions: ?exe|dll|ocx|py, ?but can?t find any command that make it. http://code.activestate.com/recipes/499305/ should be a good start. Use the re module and your regex instead of fnmatch.filter(), and you should be good to go. -- Cheers, Simon B. From rustompmody at gmail.com Wed Nov 4 11:57:41 2009 From: rustompmody at gmail.com (rustom) Date: Wed, 4 Nov 2009 08:57:41 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> Message-ID: On Oct 30, 6:23?pm, Dotan Cohen wrote: > The point is that I want to use only _Python_ features, not > Django/Mako/whatever features. Pure python has a builtin templating system -- its called % See http://simonwillison.net/2003/Jul/28/simpleTemplates/ From Nadav.C at qualisystems.com Wed Nov 4 12:05:51 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 19:05:51 +0200 Subject: regexp help In-Reply-To: <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Thanks, but my question is how to write the regex. -----Original Message----- From: simon.brunning at gmail.com [mailto:simon.brunning at gmail.com] On Behalf Of Simon Brunning Sent: ? 04 ?????? 2009 18:44 To: Nadav Chernin; Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > I?m trying to write regexp that find all files that are not with next > extensions: ?exe|dll|ocx|py, ?but can?t find any command that make it. http://code.activestate.com/recipes/499305/ should be a good start. Use the re module and your regex instead of fnmatch.filter(), and you should be good to go. -- Cheers, Simon B. From simon at brunningonline.net Wed Nov 4 12:12:47 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 17:12:47 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Message-ID: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> 2009/11/4 Nadav Chernin : > Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. -- Cheers, Simon B. From carsten.haese at gmail.com Wed Nov 4 12:13:55 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 12:13:55 -0500 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Message-ID: Nadav Chernin wrote: > Thanks, but my question is how to write the regex. See http://www.amk.ca/python/howto/regex/ . -- Carsten Haese http://informixdb.sourceforge.net From Nadav.C at qualisystems.com Wed Nov 4 12:16:14 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 19:16:14 +0200 Subject: regexp help In-Reply-To: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> No, I need all files except exe|dll|ocx|py -----Original Message----- From: simon.brunning at gmail.com [mailto:simon.brunning at gmail.com] On Behalf Of Simon Brunning Sent: ? 04 ?????? 2009 19:13 To: Nadav Chernin Cc: Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. -- Cheers, Simon B. From simon at brunningonline.net Wed Nov 4 12:18:51 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 17:18:51 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> Message-ID: <8c7f10c60911040918h41222b02p6bee89ada1601157@mail.gmail.com> 2009/11/4 Nadav Chernin : > No, I need all files except exe|dll|ocx|py not re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) Now that wasn't so hard, was it? ;-) -- Cheers, Simon B. From NOSPAM_chuckwhite8 at charter.net Wed Nov 4 12:27:36 2009 From: NOSPAM_chuckwhite8 at charter.net (chuck) Date: Wed, 04 Nov 2009 12:27:36 -0500 Subject: unable to compile Python 2.6.4 on AIX using gcc In-Reply-To: References: Message-ID: <4AF1B988.2080206@charter.net> Thanks Mark. That was indeed very helpful. Here's the current status: ======================= 1. applied changes suggested by Bob Atkins in that thread. 2. setting env variables. export OBJECT_MODE=64 export CC="gcc" export CFLAGS="-maix64 -mcpu=power5" export LDFLAGS="-maix64 -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" 3. configuring and compiling using configure --with-gcc --enable-shared --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 ; make > make_264.log 2>&1 ======================= Both python (executable) and libpython2.6.a build just fine and are in the same directory as configure. However, none of the extensions build. I keep getting libpython2.6 not found error. Here's an example: building 'math' extension gcc -pthread -fno-strict-aliasing -maix64 -mcpu=power5 -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -I/usr/local/build/python/Python-2.6.4/./Include -I. - IInclude -I./Include -I/opt/freeware/include -I/usr/lpp/X11/include/X11 -I/usr/local/include -I/usr/local/build/python/Python-2.6.4/Include -I/usr/local /build/python/Python-2.6.4 -c /usr/local/build/python/Python-2.6.4/Modules/mathmodule.c -o build/temp.aix-5.3-2.6/usr/local/build/python/Python-2.6.4/Mo dules/mathmodule.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -maix64 -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freewa re/lib -fno-strict-aliasing -maix64 -mcpu=power5 -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/opt/freeware/include -I/usr/lpp/X11 /include/X11 build/temp.aix-5.3-2.6/usr/local/build/python/Python-2.6.4/Modules/mathmodule.o -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib - L/usr/X11R6/lib -L/opt/freeware/lib -L/usr/local/lib -lm -lpython2.6 -o build/lib.aix-5.3-2.6/math.so collect2: library libpython2.6 not found I hacked Makefile to LDFLAGS= <> -L./ I now get: ld: 0711-224 WARNING: Duplicate symbol: PyObject_Size ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. Fatal Python error: Interpreter not initialized (version mismatch?) make: The signal code from the last command is 6. There are no other versions of python on that machine. I would appreciate any help. Do I need to set the exec_prefix as well? Thanks. Mark Dickinson wrote: > On Nov 3, 10:40 pm, chuck wrote: >> Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX >> 5.3. Here are the settings: > Take a look at: > > http://bugs.python.org/issue1628484 > > Mark From python at mrabarnett.plus.com Wed Nov 4 12:45:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 04 Nov 2009 17:45:42 +0000 Subject: Request for comments - concurrent ssh client In-Reply-To: References: Message-ID: <4AF1BDC6.3070705@mrabarnett.plus.com> mk wrote: > Hello everyone, > > Since I'm not happy with shmux or pssh, I wrote my own "concurrent ssh" > program for parallel execution of SSH commands on multiple hosts. Before > I release program to the wild, I would like to hear (constructive) > comments on what may be wrong with the program and/or how to fix it. > (note: the program requires paramiko ssh client module) > [snip] > if opts.cmd == None and opts.script == None: > print "You have to specify one of the following: command to run, > using -c command or --cmd command, or script to run, using -s scriptfile > or --script scriptfile." > print > failit = True > The normal way to test for None is to use "is None" or "is not None". You do actually do that in some places! [snip] > hosts = [ s.strip() for s in hosts if s != '' and s != None and s != '\n' ] > hosts = [ s.split() for s in hosts ] > [snip] Both '' and None are treated as false by 'if' and 'while'; non-empty strings are treated as true. Also, "s.split()" splits on whitespace and disregards leading and trailing whitespace. The preceding lines can be simplified to: hosts = [ s.split() for s in hosts if s and s != '\n' ] > if hosts == []: [snip] Empty lists are also treated as false and non-empty lists as true. The Pythonic way to write the preceding line is: if not hosts: [snip] > scriptcomp = script.strip().split() As mentioned earlier, ".strip().split()" can be simplified to just ".split()": scriptcomp = script.split() [snip] > try: > self.conobj.connect(self.ip, username=self.username, > password=self.passw, port=self.port, timeout=opts.timeout, > allow_agent=False, look_for_keys = False) > loginsuccess = True > except: > pass [snip] Avoid bare "except" wherever possible. In this case you're ignoring _every_ exception that might occur. VERY BAD IDEA! > def execcmds(self): > so = se = '' > try: > si, so, se = self.conobj.exec_command(self.cmd) > sol = so.readlines() > sel = se.readlines() > so = ''.join([ s.replace('\r\n','\n') for s in sol ]) > se = ''.join([ s.replace('\r\n','\n') for s in sel ]) [snip] Recent versions of Python will accept generator expressions here, so instead of iterating through a list and creating a new list, which is then passed to '.join', you can let '.join' do the iterating. This can save time and memory: so = ''.join( s.replace('\r\n','\n') for s in sol ) se = ''.join( s.replace('\r\n','\n') for s in sel ) > if sol != [] or sel != []: As mentioned earlier, non-empty lists are treated as true: if sol or sel: > def chmodscript(self): > # just in case, as sometimes and on some operating systems the > execution flags on the script are not always set > self.execcmdonscript('chmod 0755 %s' % self.rspath) > [snip] You could also use: os.chmod(self.rspath, 0755) > def delscript(self): > self.execcmdonscript('rm -f %s' % self.rspath) > [snip] You could also use: os.remove(self.rspath) > for ip, th in queue: > if th.finished: > th.sshclose() > th.join() > thfinished.append((ip,th)) > queue.remove((ip,th)) > Never modify a list (or any container, in fact) while iterating through it. Some containers handle iteration by using an index, but if you remove an item from the container then the index might no longer be correct. Instead, build a new list of the items you want to keep: new_queue = [] for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) else: new_queue.append((ip,th)) queue = new_queue If there are other references to the queue itself then it might be better to replace the contents of the existing queue with those of the new one instead by changing: queue = new_queue to: queue[:] = new_queue From reckoner at gmail.com Wed Nov 4 12:59:00 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 09:59:00 -0800 (PST) Subject: set pdb break condition based upon number of hits? Message-ID: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> Is it possible to set pdb break condition based upon number of hits? I mean something like (Pdb) break line_number (number_of_hits_for_this_breakpoint >10) any help appreciated. From kevinar18 at hotmail.com Wed Nov 4 13:06:53 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Wed, 4 Nov 2009 13:06:53 -0500 Subject: How do I install dlls and exes for libtidy and others? Message-ID: 1. I already asked how to setup libxml2 and libxslt, but nobody answered how to... so if anyone knows I'm still having those problems. 2. I now can't get libtidy to work, which requires the same thing: I need to put some dlls and exes somewhere to make it work in Python. Thing is, I don't know where. There are no instructions on this part. Details: I get the following error: import tidy OSError: Couldn't find libtidy, please make sure it is installed. I downloaded these two files (the exe and the dll): http://www.paehl.com/open_source/?HTML_Tidy_for_Windows I copied the exe and dll to the Python directory and Python\Lib and Python\Dlls ... nothing worked I ran this installer (didn't solve the problem): http://int64.org/projects/tidy-binaries So, how can I setup libtidy to work with Python? What do I do with the exe and dll files? Do I need to make additional changes to the system? How do I get other programs like libxml2 and libxslt to work with python -- as in what do I do with the exe and dlls? _________________________________________________________________ Bing brings you maps, menus, and reviews organized in one place. http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1 From jeanmichel at sequans.com Wed Nov 4 13:15:01 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 04 Nov 2009 19:15:01 +0100 Subject: About one class/function per module In-Reply-To: <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> Message-ID: <4AF1C4A5.70604@sequans.com> Peng Yu wrote: > With some automated script, I don't think it is a nightmare to change > function names. I can change function names and filenames and their > reference with a simple command. > > I'd think that this is the limitation of current version control > system. I don't aware of any version control system that allows easy > change of filenames. But why such features can not be implemented in > the version control system? > So one function per files bring so many problems that you need an automated script to change one function name and complain about version control systems messing up with your file history. Still you insist on stating that this is the solution and that version control system have to adapt. It has already been told to you, and you should really consider the following advice: When everything is wrong except you, it may happen that *your* are somehow wrong. Among all the responses you got, I don't remember any one that would suggest you are in the right way. So what is your conclusion now ? JM From luke.leighton at googlemail.com Wed Nov 4 13:17:23 2009 From: luke.leighton at googlemail.com (Luke Kenneth Casson Leighton) Date: Wed, 4 Nov 2009 18:17:23 +0000 Subject: [ANN] Pyjamas 0.7pre1 Web Widget Set and python-to-javascript Compiler released Message-ID: Current Release: 0.7~pre1 --------------- This is a 0.7 prerelease of Pyjamas, to invite users to help test the latest version. The latest svn is regularly but informally tested against the regression tests and the examples, and used in production, but not extensively tested against all known browsers on each commit. Community assistance by running against a wider range of browsers ensures that *you* get a stable release. Pyjamas ------- Pyjamas is a port of Google Web Toolkit to Python, and thus enables the development of Rich Media AJAX applications in Python, with no need for special browser plugins. Pyjamas contains a stand-alone python-to-javascript compiler, and also a Widget Set API that looks very similar to Desktop Widget Set APIs (such as PyQT4 or PyGTK2). Pyjamas also contains a Desktop Widget Set version, running as pure python. Using web browser technology provides an alternative to PyQT4 and PyGTK2 that has the advantage of having full support for HTML, CSS, Plugin and other web-related features already built-in. For the windows port, this can save users around 30mb of downloads, as MSHTML is preinstalled as part of IE. For more information, see: http://pyjs.org http://pyjs.org/FAQ.html http://pyjs.org/features.html Known bugs: http://code.google.com/p/pyjamas/issues #290, #227, #228, #230, #304 Changelog Summary ----------------- Features and enhancements of the stand-alone 0.7 series javascript compiler include: * the addition of generators (support for yield, by rewriting the function so that it can be re-called and continue from the previous state); * the beginnings of decorators support, and support for properties; * some dramatic performance improvements due to a rewrite of for-loops; * improved support for import syntax (from . import module); * the addition of a built-in AST parser, use of which allows python 2.4 to compile programs with python 2.5 / 2.6 syntax into javascript; * addition of int and long types, and support for operator functions, so that e.g list multiplication by numbers and list addition now work, along with coercion between int, float and long types, and support for floating point exceptions. Overall, this release is a significant "pythonic" upgrade: for full details, see the CHANGELOG. In the User-Interface suite, which is separate from the Pyjamas stand-alone python-to-javascript compiler, the features and enhancements include: * An SVG / VML Canvas Library (a port of GWTCanvas). This has been ported to pure python, and consequently work under Pyjamas-Desktop as well. * A Graphical Chart Library (a port of GChart). This has been ported to pure python, and consequently work under Pyjamas-Desktop as well. For the same speed optimisations present in GChart, GChart for Pyjamas can also use the python port of GWTCanvas. * An internal restructure of Event handling, similar to GWT 1.7, providing Focus, Mouse and Click "Mixin" modules so that developers creating their own widgets have a minimal amount of work to do. This redesign could only take place once Pyjamas supported multiple inheritance (added in 0.6). Pyjamas-Desktop --------------- Pyjamas runs your application in a Web Browser (as javascript); Pyjamas-Desktop runs exactly the same python application on the Desktop (as python) http://pyjd.org Release 0.6 of Pyjamas incorporated Pyjamas-Desktop directly into the Pyjamas Distribution. To use Pyjamas-Desktop there are three choices, with more planned [MacOSX PyObjC; KDE's PyKHTML]. All ports of Pyjamas-Desktop will require a JSON library to be installed: as there are plenty already, it is counter-productive to write yet another one. Simplejson is recommended. 1) - XULRunner install hulahop and python-xpcom. hulahop is distributed with both Debian and Ubuntu; python-xpcom is part of XULRunner and is also distributed with both Debian and Ubuntu. Other users should investigate the installation instructions for python-xpcom and hulahop for the operating system of their choice on the appropriate web sites. GNU/Linux, FreeBSD and other POSIX systems are strongly advised to use XULRunner for Pyjamas-Desktop: it is the most stable of the PyJD ports. 2) - PyWebKitGtk you will need a patched version of pywebkitgtk: http://code.google.com/p/pywebkitgtk/issues/detail?id=13 you will need a patched version of webkit: http://github.com/lkcl/webkit/16401.master Detailed build instructions are available here: http://wiki.github.com/lkcl/webkit/helping-with-16401master 3) - MSHTML For Windows users, all that's required, other than installing python and Internet Explorer, is one further package: Win32 "comtypes". Win32 "comtypes" can be downloaded here: * http://sourceforge.net/projects/comtypes/ From sebas0 at gmail.com Wed Nov 4 13:37:39 2009 From: sebas0 at gmail.com (Sebastian) Date: Wed, 4 Nov 2009 16:37:39 -0200 Subject: a is b Message-ID: I have a question from the pyar list that may have been discussed on this list, but i didn't catch it. Have some common objects been somewhat hardcoded into python, like some integers as shown in the examples below? What other object have been hardcoded (strings ,etc) and what was the criteria used to select them? Any hints? cheers, - Seb >>> p = 500 >>> q = 500 >>> p == q True >>> p is q False >>> n = 50 >>> m = 50 >>> n == m True >>> n is m True >>> p = 500; q = 500 >>> p is q True >>> for i in range(-20,258): ... a = i ... b = i+0 ... if not (a is b): print i ... -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 257 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 4 13:42:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 10:42:27 -0800 Subject: a is b In-Reply-To: References: Message-ID: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> On Wed, Nov 4, 2009 at 10:37 AM, Sebastian wrote: > I have a question from the pyar? list that may have been discussed on this > list, but i didn't catch it. > Have some common objects been somewhat hardcoded into python, like some > integers as shown in the examples below? What other object have been > hardcoded (strings ,etc) and what was the criteria used to select them?? Any > hints? See recent thread on the subject: http://www.mail-archive.com/python-list at python.org/msg264434.html Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Nov 4 13:46:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 13:46:39 -0500 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: Alf P. Steinbach wrote: > However, the natural semantics is that various logical properties, such > as left, top, right, bottom, width and height, can be varied independently. But they *CANNOT* be varied independently. A rectangle with side parallel to the axes has exactly 4 degress of freedom, not 6. Terry Jan Reedy From tjreedy at udel.edu Wed Nov 4 13:51:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 13:51:02 -0500 Subject: import from a string In-Reply-To: References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: >> On Nov 4, 3:10 am, "Gabriel Genellina" wrote: > >>> txt = """ >>> def foo(x): >>> print 'x=', x >>> >>> def bar(x): >>> return x + x >>> """ >>> >>> py> namespace = {} >>> py> exec txt in namespace >>> py> namespace.keys() >>> ['__builtins__', 'foo', 'bar'] >>> py> namespace['foo']('hello') >>> x= hello > >> What happens if both global and local dictionaries are supplied: where >> are the newly created entities created? In the local dict? > > The amazing thing about Python is how easy is to experiment in the > interpreter. > Just see it by yourself! Hint: they are created in the same namespace they always are (ignoring nested functions and nonlocal namespaces). But I agree with Gabriel: just try it. n1,n2={},{}; exec.... Terry Jan Reedy From kevinar18 at hotmail.com Wed Nov 4 14:07:54 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Wed, 4 Nov 2009 14:07:54 -0500 Subject: How do I install dlls and exes for libtidy and others? Message-ID: Lme clarify my problems. My earlier emails were pretty vague... so this should help. Problem: I have been wanting to try out many libraries that use Python to C/C++ app bindings. This means I install the Python library using easy_install and then install the pre-compiled Windows binaries and/or dlls... but that is where the problem arises: * I do not know where to install the pre-compiled binaries. There are no instructions on this -- it's like everyone assumes I know what to do. * I tried copying the exe and/or dlls to Python, Python\Lib, Python\Dll * import libxml2, import libxslt, and import libtidy do not work. For example for libtidy, I get: import tidy OSError: Couldn't find libtidy, please make sure it is installed. * The problem is always when a library requires pre-compiled Windows binaries. I can't every get any such libraries to work. My questions. What is the proper way to setup these pre-compiled binaries so that they will work with Python libraries? What are all the steps? Is there some things I can do to help diagnose problems? Could the problems be something different? _________________________________________________________________ Windows 7: Unclutter your desktop. http://go.microsoft.com/?linkid=9690331&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen:112009 From tjreedy at udel.edu Wed Nov 4 14:10:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 14:10:19 -0500 Subject: Pyfora, a place for python In-Reply-To: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> References: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> Message-ID: Valentina Boycheva wrote: > I was following this discussion first with curiosity and then with > increasing disbelief. > So stop following it. Really. > As a scientist and a programmer, I always > considered myself belonging to a group of people who are broad-minded > and task-oriented. Ditto. I read python-list as the newgroup gmane.comp.python.general and only download the posts I select, which is well less than half, depending on my mood;-). -- which is to say, whether or not I am looking for time-wasting entertainment ;-) > Being an occasional Python programmer, I subscribed to this list in the > hopes of learning from the pros. Most of the time I do. But I also see a > disturbing trend of petty bickering, splitting hairs and one-upmanship. I have been reading for over 10 years and see no increasing trend. The worst times were definitely in the past. > I understand there will be occasional language slips and misconstrued > jokes but can we please stick to the topic and remain courteous at all > times? I completely agree, but have given up most admonishments ;-) > I am seriously considering unsubscribing from this UL That would be a shame. > (and maybe joining Pyfora.) That should be an independent decision. Most PHPBBS web forums I have seen are about the same or worse as far as civility. Terry Jan Reedy From starglider101 at gmail.com Wed Nov 4 14:17:21 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 4 Nov 2009 19:17:21 +0000 Subject: comparing alternatives to py2exe In-Reply-To: <4af163cc$0$6279$4f793bc4@news.tdc.fi> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> <4af163cc$0$6279$4f793bc4@news.tdc.fi> Message-ID: <6e5b31840911041117q7dbbe3fw718b9f7f6761c050@mail.gmail.com> Hi, in this discussion I read that we con create a bundle executable for our application, since I'm having troubles with create a exe due problems with kinterbasdb, can you show me tutorials for creating exe from bundle. thanks in advance. On Wed, Nov 4, 2009 at 11:21 AM, Vesa K?pp? wrote: > iu2 wrote: > >> Another thing that I think is of interest is whether the application >> support modifying the version and description of the exe (that is, on >> Windows, when you right-click on an application and choose >> 'properties' you view the version number and description of the >> application, it is a resource inside the exe). I think py2exe supports >> it. >> > > Pyinstaller supports this. > > Vesa > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reckoner at gmail.com Wed Nov 4 14:40:41 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 11:40:41 -0800 (PST) Subject: Using logging module for conditional nested logs Message-ID: Hi, I am getting started with your logging module and I went through the tutorial and know-how to create a top-level 'root' logger with the appropriate handlers. I have a number of functions,say, def foo1() def foo2() ... foo1() # foo2 calls foo1 and I know how to connect each of these functions to the 'root' logger by doing something like def foo1() logger = getLogger('root.foo1') but I want to arrange it so that foo1 adds to the logfile that foo2 is using ONLY when foo2 calls foo1. In other words, if I do def foo2() logger = getLogger('root.foo2') or def foo1() logger = getLogger('root.foo2.foo1') it responds to the 'root' logger when I want it to respond to *any* logger that is attached to foo2. Then, the question is how can I set up foo1 to log to whatever logger foo2 is using. The purpose of doing this is that I am interested in capturing when and by whom foo1 is called in whatever logger foo2 is using. So, if I attach a separate logger to a third function, say, foo3 (), then I can avoid reporting those instances when foo3 calls foo1. I hope that made some sense. From davea at ieee.org Wed Nov 4 16:03:57 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 04 Nov 2009 16:03:57 -0500 Subject: regexp help In-Reply-To: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> Message-ID: <4AF1EC3D.5070707@ieee.org> Simon Brunning wrote: > 2009/11/4 Nadav Chernin : > >> Thanks, but my question is how to write the regex. >> > > re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. > > How about: os.path.splitext(x)[1] in (".exe", ".dll", ".ocx", ".py"): DaveA From alfps at start.no Wed Nov 4 16:08:49 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 22:08:49 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Terry Reedy: > Alf P. Steinbach wrote: > >> However, the natural semantics is that various logical properties, >> such as left, top, right, bottom, width and height, can be varied >> independently. > > But they *CANNOT* be varied independently. A rectangle with side > parallel to the axes has exactly 4 degress of freedom, not 6. Yes . That's the basic idea of the example I presented up-thread, that's discussed here. With R1's state variables width and heigh can be varied independently by direct modification, with R2 it's right and bottom. The public interface must also make this choice, but it's an independent choice: the internal rectangle representation can have the opposite choice. And conversely, that means that if the internal representation isn't used directly, then it can be changed without affecting the public interface. Cheers, - Alf From vinay_sajip at yahoo.co.uk Wed Nov 4 16:30:42 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 4 Nov 2009 13:30:42 -0800 (PST) Subject: Using logging module for conditional nested logs References: Message-ID: On Nov 4, 7:40?pm, Reckoner wrote: > > I hope that made some sense. Not especially :-( Sorry I don't understand exactly what you mean, because I find your terminology confusing. For example, "logger that is attached to foo2" - loggers are not attached to functions. "It responds to the 'root' logger" - what responds? What's meant by "respond"? Loggers correspond to specific code components in an application. Normally these areas are modules and sometimes they're classes. You can certainly treat functions as areas but this will typically become unwieldy in any sizeable application. It doesn't (in general) make sense to have a specific logger for foo1 for use only when it's called by foo2. These seem like anti-patterns to me. Handlers are attached to loggers to make events logged via those loggers available to different audiences - via console, file, email etc. If you want to log that foo1 is being called by foo2, you can do this. For example, you could have a utility function which walks (a sufficient part of) the call stack to see the function call hierarchy, then log this as additional information (e.g. using the 'extra' parameter to the logging call). You can attach Filters to loggers and handlers which use this information to decide where and whether to actually record the event. As well as the Python logging documentation, you may also find the following link useful: http://plumberjack.blogspot.com/2009/09/python-logging-101.html Regards, Vinay Sajip From aahz at pythoncraft.com Wed Nov 4 16:57:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Nov 2009 13:57:06 -0800 Subject: python os.path.exists failure References: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> Message-ID: In article <9aaf6a31-a34e-454b-a8f0-e206ad9b7040 at t2g2000yqn.googlegroups.com>, koranthala wrote: > >path = r'C:/"Program Files"/testfolder/2.3/test.txt' >if os.path.lexists(path): > print 'Path Exists' >else: > print 'No file found in path - %s' %path >print Popen(path, stdout=PIPE, shell=True).stdout.read() Avoiding shell=True is a Good Idea -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From irmen at -nospam-xs4all.nl Wed Nov 4 17:04:49 2009 From: irmen at -nospam-xs4all.nl (Irmen de Jong) Date: Wed, 04 Nov 2009 23:04:49 +0100 Subject: disable image loading to speed up webpage load In-Reply-To: References: <26155440.post@talk.nabble.com> <7l7nklF3cgpk3U1@mid.uni-berlin.de> Message-ID: <4af1fa58$0$83241$e4fe514c@news.xs4all.nl> On 4-11-2009 8:32, elca wrote: > Diez B. Roggisch-2 wrote: >> >> Use urllib2. >> > > you can show me some more specific sample or demo? > It's not even more than 1 click away in the Python standard lib documentation... how hard can it be? http://docs.python.org/library/urllib2.html#examples -irmen From threaderslash at gmail.com Wed Nov 4 17:07:04 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 5 Nov 2009 09:07:04 +1100 Subject: problem in installing wxwidgets for python. Message-ID: This additional links should come in hand: http://www.gossamer-threads.com/lists/python/python/785413?page=last http://www.daniweb.com/forums/thread235862.html# http://forum.amule.org/index.php?topic=11728.0 http://www.linuxquestions.org/questions/linux-software-2/problem-in-installing-wxwidgets...-766666/ I hope it can help. Good luck and have fun! ThreaderSladh ---------- Forwarded message ---------- From: Ishwor Gurung To: python-list at python.org Date: Wed, 4 Nov 2009 23:11:39 +1100 Subject: Re: problem in installing wxwidgets for python.. Hi, 2009/11/4 Jebagnana Das : > Hello friends, > I've tried to install wxwidgets in my mandriva 2009 spring > for GUI interaction with python. In the installation instruction it said > that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got > the message You probably want wxpython binding instead - http://www.wxpython.org/ Use binaries provided by Mandriva's package manager where possible unless you _really_ want to do a source installation. > checking for BASE_DEPENDENCIES... configure: error: Package requirements > (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were > not met: > > > Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 > > Consider adjusting the PKG_CONFIG_PATH environment variable if you > installed software in a non-standard prefix. $ export PKG_CONFIG_PATH=/usr/lib/ pkgconfig:/usr/local/lib/pkgconfig (considering that your local installs went to those directories. Try replacing those directories accordingly for glib, atk, pango and cairo). The files you're after is a ".pc" (pkg-config need them) file. A quick find will tell you where it is if it is installed. Run configure script again. > Alternatively, you may set the environment variables > BASE_DEPENDENCIES_CFLAGS > > and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. > See the pkg-config man page for more details. > > Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I > installed all the packages using the following commands. [...] > tar xvzf filename.tar.gz > cd folder > ./configure > > make > make install Yep. Check where it installed them one by one. In short, you need access to a ".pc" file that they provide. If not, write one yourself. > I've not specified anf options like --prefix and i installed in the folder > itself. man pkg-config for further info. > when i tried to install gtk+ after installing all this it showed the same > error. What should i do to install wxwidgets? Plz. reply as soon as > possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... See above. -------------- next part -------------- An HTML attachment was scrubbed... URL: From doesnotexist at franzoni.invalid Wed Nov 4 17:28:47 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Wed, 04 Nov 2009 22:28:47 GMT Subject: Pyfora, a place for python In-Reply-To: <7l89j4F3bl107U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > Being from germany, I can say that we *have* this fragmentation, and > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > with those visually rather noisy and IMHO suboptimal forums. E.g. it That's right... forums, although more "accessible" to all the people who can't/doesn't want to use specific email or nntp clients, are quite slow to use. But I think Ubuntu forums support threads and are kind of "channeled" between ML and webinterface... something like Google Groups; I think THAT would be a good idea. What about trying to "channel" comp.lang.python and a forum? -- Alan Franzoni contact me at public@[mysurname].eu From martin at v.loewis.de Wed Nov 4 17:47:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 04 Nov 2009 23:47:55 +0100 Subject: restricted mode??? In-Reply-To: References: Message-ID: <4AF2049B.1050709@v.loewis.de> > I thought that restricted mode died ages ago. > > Any ideas what could be causing this? Restricted mode is still available, and activated whenever a frame's builtins directory is different from the interpreter's; see PyFrame_IsRestricted. Regards, Martin From reckoner at gmail.com Wed Nov 4 18:14:54 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 15:14:54 -0800 (PST) Subject: Using logging module for conditional nested logs References: Message-ID: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> On Nov 4, 1:30 pm, Vinay Sajip wrote: > On Nov 4, 7:40 pm, Reckoner wrote: > > > > > I hope that made some sense. > > Not especially :-( > > Sorry I don't understand exactly what you mean, because I find your > terminology confusing. For example, "logger that is attached to foo2" > - loggers are not attached to functions. "It responds to the 'root' > logger" - what responds? What's meant by "respond"? > > Loggers correspond to specific code components in an application. > Normally these areas are modules and sometimes they're classes. > > You can certainly treat functions as areas but this will typically > become unwieldy in any sizeable application. It doesn't (in general) > make sense to have a specific logger for foo1 for use only when it's > called by foo2. These seem like anti-patterns to me. > > Handlers are attached to loggers to make events logged via those > loggers available to different audiences - via console, file, email > etc. > > If you want to log that foo1 is being called by foo2, you can do this. > For example, you could have a utility function which walks (a > sufficient part of) the call stack to see the function call hierarchy, > then log this as additional information (e.g. using the 'extra' > parameter to the logging call). You can attach Filters to loggers and > handlers which use this information to decide where and whether to > actually record the event. > > As well as the Python logging documentation, you may also find the > following link useful: > > http://plumberjack.blogspot.com/2009/09/python-logging-101.html > > Regards, > > Vinay Sajip I appreciate your patience, as I am new to this. Your comments have put me on the right track. I will look at the link you specify. Thanks again. From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:44:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:44:50 GMT Subject: Python 3 [was Re: substituting list comprehensions for map()] References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> Message-ID: On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: >> > from numpy import dot >> > >> > scalar = dot(vec1, vec2) >> >> Why would I want to use an already existing library that is fast, well- >> written and well-supported, when I can toss together a nasty kludge >> myself? > > Because using that library will ensure you can't migrate to Python 3 any > time soon? Why would I want to migrate to Python 3 any time soon? 2.5 and 2.6 meet my needs (so far), and the new features in Python 3 aren't especially compelling to me. Particularly if migrating to 3 requires me to re-write all the libraries, where's the advantage? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:47:52 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:47:52 GMT Subject: How to test urllib|urllib2-using code? References: Message-ID: On Wed, 04 Nov 2009 15:06:45 +0100, Lutz Horn wrote: > Hi, > > kj wrote: >> I want to write some tests for code that uses both urllib and urllib2. > > Take a look at the discussion under the title "How can one mock/stub > python module like urllib" at stackoverflow: > > http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python- module-like-urllib Oh noes!!! Ur fragmenting teh python communities!!!!1!!! DO NOT WANT!!! *grin* (And for those who don't know what on earth I'm referring to, see the thread "Pyfora, a place for python".) -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:50:49 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:50:49 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: On Wed, 04 Nov 2009 06:36:46 -0800, Ethan Furman wrote: > Dennis Lee Bieber wrote: > > Perfectly valid answer -- there are no fish as there is no Atlantic > > sea > > > Steven D'Aprano wrote: > > Once in the distant past, there were no fish in what would become the > > Atlantic Ocean (not sea) > > What's with the bias against the word 'sea'? The Atlantic Ocean is named the Atlantic Ocean, not the Atlantic Lake or Atlantic Puddle or Atlantic Dewdrop or Atlantic Sea. Otherwise, sea is a perfectly good word, for describing what the Atlantic Ocean *is* rather than what it is *named*. -- Steven From toby.o.h.white at googlemail.com Wed Nov 4 19:08:20 2009 From: toby.o.h.white at googlemail.com (tow) Date: Wed, 4 Nov 2009 16:08:20 -0800 (PST) Subject: module imports and st_mtime Message-ID: I'm seeing a very strange effect which is confusing me - in brief, one python process appears to temporarily affect the os.stat results of another - perhaps someone can enlighten me. This is on Mac OS X Leopard, using the system python (2.5) The issue arises using Django. The default Django http server runs a watcher thread, which checks if any code is changing, and reloads itself. It does this by iterating over all loaded modules, and checking the mtime of each __file__. This was behaving oddly, and finding out why exposed this strangeness. (The relevant code is in django/utils/autoreload.py) Some of the code running under this django server imports simplejson, the C-implemented module of which has been put at /Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so This hasn't been touched since it was installed: ls -l ~/.python-eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/ simplejson/_speedups.so -rwxr-xr-x 1 tow staff 77596 12 Aug 17:56 /Users/tow/.python-eggs/ simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so If I check the mtime of that file from within django, it finds it correctly: print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so").st_mtime) 2009-08-12 17:56:02 The strange effect occurs when I open another python process, and import simplejson there as well. As soon as I've done that, the mtime that Django sees slips by an hour: print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so").st_mtime) 2009-08-12 16:56:02 In fact, to be precise, this happens as soon as the simplejson._speedups module *finishes* being imported. (Tested by stepping through every line with pdb) The second Python process still sees the correct mtime, though, both before and after it imports simplejson. Restarting the Django process resets its view of the world, and it sees the correct mtime again. The current time as seen by the Django process is correct both before and after the mtime slippage. This seems to be 100% reproducible here, except for the time offset. Usually it loses one hour, sometimes it gains 5 hours. (For what it's worth, I'm currently on GMT, but the file was created during daylight savings time). I haven't managed to replicate it when the first process is something other than Django. I've seen the effect on other Mac OS machines, but haven't tested it on Linux so far. I've only seen the effect with simplejson's C module, but I think this is the only C module which might be being imported twice in this way for me. Does anyone have any ideas what might be going on, or where further to look? I'm at a bit of a loss. Toby From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 19:39:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2009 00:39:25 GMT Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: > * Gabriel Genellina: >> >> I don't understand either. R1 and R2 have *different* semantics. > > Assume that they have the very exact same semantics Why would we assume that when you have explicitly told us that they don't? You stated categorically that they behave differently when you assign to the attribute/property "top". According to your own description, setting R1.top moves the rectangle, while setting R2.top resizes it. Perhaps the difference between "move" and "resize" is too subtle for you, but you can trust us on this, they are different semantics. > -- like two TV > sets that look the same and work the same except when you open 'em up > and poke around in there, oh holy cow, in this one there's stuff that > isn't in the other. Whether "top" is an attribute or a property is irrelevant, it is still part of the public API of the class. Such public attributes are NOT private internal details, they are part of the public interface. You've been told this repeatedly. Perhaps one more time may help: Public attributes are public. -- Steven From pavlovevidence at gmail.com Wed Nov 4 20:05:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 4 Nov 2009 17:05:45 -0800 (PST) Subject: module imports and st_mtime References: fb1b6b88-ccef-4f35-aaa9-b9d263969b61@k19g2000yqc.googlegroups.com Message-ID: On Nov 4, 4:08?pm, tow wrote: > Does anyone have any ideas what might be going on, or where further to > look? I'm at a bit of a loss. Does Mac OS have a concept of process-local filesystem modification? I.e. when loading the library does it create a process-local copy of the file with an updated timestamp? Only thing I can think of, and if so it's probably not something you want to turn off. Carl Banks From deets at nospam.web.de Wed Nov 4 20:41:31 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Nov 2009 02:41:31 +0100 Subject: set pdb break condition based upon number of hits? In-Reply-To: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> References: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> Message-ID: <7leoqbF3cbcagU1@mid.uni-berlin.de> Reckoner schrieb: > Is it possible to set pdb break condition based upon number of hits? I > mean something like > > (Pdb) break line_number (number_of_hits_for_this_breakpoint >10) > > any help appreciated. MY_GLOBAL_COUNTER = 0 MY_GLOBAL_COUNTER += 1 if MY_GLOBAL_COUNTER >= 10: import pdb; pdb.set_trace() Diez From alfps at start.no Wed Nov 4 20:48:00 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 02:48:00 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Steven D'Aprano: > On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: > >> * Gabriel Genellina: >>> I don't understand either. R1 and R2 have *different* semantics. >> Assume that they have the very exact same semantics > > > Why would we assume that when you have explicitly told us that they don't? > > You stated categorically that they behave differently when you assign to > the attribute/property "top". Uh, severe reading difficulties ... referring to self in plural ... Hm. :-) But anyway, in the example description I wrote "With R1 direct changes of left and top keeps the rectangle's size" and this is in the context of a discussion of modifying data attributes directly versus using properties. Anyway, if that formulation was confusing I have clarified it later, so you really, ideally, should have no problem grasping this. > According to your own description, setting > R1.top moves the rectangle, while setting R2.top resizes it. Perhaps the > difference between "move" and "resize" is too subtle for you, but you can > trust us on this, they are different semantics. No, I would absolutely not trust you Steven, whether that's plural or singular, to assign semantics to my examples. >> -- like two TV >> sets that look the same and work the same except when you open 'em up >> and poke around in there, oh holy cow, in this one there's stuff that >> isn't in the other. > > > Whether "top" is an attribute or a property is irrelevant, Sorry, that's incorrect. For example, if it is a read only property than you can't assign to the property. For another example, if it is a read/write property than it can update any parts of the rectangle represention. > it is still > part of the public API of the class. Sorry, that's incorrect; it depends on the class. > Such public attributes are NOT > private internal details, they are part of the public interface. Sorry, that's incorrect; it depends on the class, and as far as I know and have been informed here there are no private attributes in Python, just a notational convention. > You've > been told this repeatedly. Sorry, but repeating what you want me to have meant in my example, contrary to the direct text of the example, contrary to its context, choosing a meaningless interpreteration of what's left when you have ignored the text, plus contrary to further clarifications, well that's daft to say the least. > Perhaps one more time may help: > > Public attributes are public. It would be nice if Python had private ones, yes. Cheers & hth., - Alf From sebastianthegreatful at gmail.com Wed Nov 4 21:03:49 2009 From: sebastianthegreatful at gmail.com (Seb) Date: Wed, 4 Nov 2009 18:03:49 -0800 (PST) Subject: multicast Message-ID: I'm trying to implement a multicast module. I'm inspired by this blog http://chaos.weblogs.us/archives/164 I'd like to get some comments on the code so far but more importantly some suggestions on how I can implement reliable multicasting. best regards, Seb From sebastianthegreatful at gmail.com Wed Nov 4 21:05:24 2009 From: sebastianthegreatful at gmail.com (Seb) Date: Wed, 4 Nov 2009 18:05:24 -0800 (PST) Subject: multicast References: Message-ID: <63a0c482-367e-4bae-a4d8-b0e95d2d454d@z41g2000yqz.googlegroups.com> Forgot the code... doh! :) #! /usr/bin/env python import socket import time class MulticastSender(object): def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600): self.MCAST_ADDR = MCAST_ADDR self.MCAST_PORT = MCAST_PORT ANY = "0.0.0.0" SENDERPORT=1501 #create a UDP socket self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) #allow multiple sockets to use the same PORT number self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) #The sender is bound on (0.0.0.0:1501) self.sock.bind((ANY,SENDERPORT)) #Tell the kernel that we want to multicast and that the data is sent #to everyone (255 is the level of multicasting) self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255) def send(self, data): self.sock.sendto(data, (self.MCAST_ADDR, self.MCAST_PORT)); class MulticastReceiver(object): def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600): ANY = "0.0.0.0" #create a UDP socket self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) #allow multiple sockets to use the same PORT number self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) #Bind to the port that we know will receive multicast data self.sock.bind((ANY,MCAST_PORT)) #tell the kernel that we are a multicast socket self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255) #Tell the kernel that we want to add ourselves to a multicast group #The address for the multicast group is the third param status = self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_ADDR) + socket.inet_aton(ANY)); self.sock.setblocking(0) def setblocking(self, flag): self.sock.setblocking(flag) def recv(self, size = 1024): return self.sock.recvfrom(size) class Multicast(object): def __init__(self): self.__ms = MulticastSender() self.__mr = MulticastReceiver() def send(self, data): self.__ms.send(data) def recv(self, size = 1024): return self.__mr.recv() if __name__ == "__main__": mc = Multicast() while 1: try: data, addr = mc.recv() except socket.error, e: #print "sock.error: ", e pass else: print "FROM: ", addr print "DATA: ", data From nad at acm.org Wed Nov 4 21:18:43 2009 From: nad at acm.org (Ned Deily) Date: Wed, 04 Nov 2009 18:18:43 -0800 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: In article , Alan Franzoni wrote: > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > Being from germany, I can say that we *have* this fragmentation, and > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > That's right... forums, although more "accessible" to all the people who > can't/doesn't want to use specific email or nntp clients, are quite slow > to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? comp.lang.python *is* already "channel"ed in multiple venues: the Usenet group itself, the base python.org mailing list, gmane.org (NNTP newsgroup from the mailing list, various web interfaces, RSS feed), google groups, and others. -- Ned Deily, nad at acm.org From ben+python at benfinney.id.au Wed Nov 4 21:25:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2009 13:25:31 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <87k4y5d7xg.fsf@benfinney.id.au> Alan Franzoni writes: > That's right... forums, although more "accessible" to all the people > who can't/doesn't want to use specific email or nntp clients, are > quite slow to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? Please, be more specific. As I said earlier in this thread, a ?forum? could be a mailing list, a Usenet newsgroup, a walled-garden web application, an IRC channel, or a face-to-face meeting in a pub. So speaking of comp.lang.python as though it's *not* a forum is confusing. Please choose a term that makes it clear why what one is speaking about is distinct from the comp.lang.python forum. -- \ ?Just because nobody complains doesn't mean all parachutes are | `\ perfect.? ?Benny Hill | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Nov 4 21:27:09 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2009 13:27:09 +1100 Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> Message-ID: <87fx8td7uq.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > >> Why would I want to use an already existing library that is fast, > >> well- written and well-supported, when I can toss together a nasty > >> kludge myself? > > > > Because using that library will ensure you can't migrate to Python 3 > > any time soon? > > Why would I want to migrate to Python 3 any time soon? Sounds like you've answered the questions posed, then. Good for you! -- \ ?The whole area of [treating source code as intellectual | `\ property] is almost assuring a customer that you are not going | _o__) to do any innovation in the future.? ?Gary Barnett | Ben Finney From alfps at start.no Wed Nov 4 21:55:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 03:55:53 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Alf P. Steinbach: > * Steven D'Aprano: >> On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: >> >>> * Gabriel Genellina: >>>> I don't understand either. R1 and R2 have *different* semantics. >>> Assume that they have the very exact same semantics >> >> >> Why would we assume that when you have explicitly told us that they >> don't? >> >> You stated categorically that they behave differently when you assign >> to the attribute/property "top". > > Uh, severe reading difficulties ... referring to self in plural ... Hm. :-) > > But anyway, in the example description I wrote > > "With R1 direct changes of left and top keeps the rectangle's size" > > and this is in the context of a discussion of modifying data attributes > directly versus using properties. Perhaps this makes it more clear: in R1, which has a width/height based rectangle representation, assigning directly to the top data attribute /effectively/ moves the rectangle vertically without changing its height, since the height attribute is unchanged. But that does not reflect any intended semantics, it's not a requirement; it's an implementation artifact, a behavior that just results from direct modification and the choice of a particular rectangle representation. Real world Python example of that kind of artifact: as discussed in some other thread here, doing open( ..., 'r+' ) followed by write followed directly by read will on some implementations/systems produce garbage. Presumably because those implementations use C "FILE*" to implement the functionality, and implements it by a fairly direct mapping of calls down to the C level, where this sequence is in general Undefined Behavior. You might regard it as semantics, and it's quite real and presumably in a sense well-defined for the particular implementation on the particular system, but it's not part of any intended semantics, and any who relies on that behavior is doing it at other's risk. For the R1 class the indended semantics, the specification that the programmer was handed down or produced or had in mind, might include just rectangle construction, checking intersection with other rectangle, and obtaining any of three pairs of values: left upper corner, right lower corner and width+height. For example. :-) Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 22:00:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2009 03:00:08 GMT Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> >> Why would I want to use an already existing library that is fast, >> >> well- written and well-supported, when I can toss together a nasty >> >> kludge myself? >> > >> > Because using that library will ensure you can't migrate to Python 3 >> > any time soon? >> >> Why would I want to migrate to Python 3 any time soon? > > Sounds like you've answered the questions posed, then. Good for you! I was actually only being *half* tongue in cheek, which is why I left out the smiley. On the python-dev list at the moment is a lot of discussion on why uptake of Python 3.1 has been slower than hoped. But one of the things that people haven't really discussed -- or at least that I haven't seen -- is why one would prefer 3.1 over 2.5 or 2.6. I've played around with 3.0, and I've read the What's New for 3.1 (and am installing 3.1 now), and while the changes look nice, I'm not sure that they're nice enough to deal with the pain of 2to3 migration. So how about that, 3.1 fans? What are the most compelling reasons for you that convinced you to change? -- Steven From wuwei23 at gmail.com Wed Nov 4 22:18:21 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 4 Nov 2009 19:18:21 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: Daniel Fetchinson wrote: > Yes, this is about the right kind of response I think everybody > deserves who puts energy/enthusiasm/effort/time into putting together > a python-related forum. So what's the right kind of response deserved by those who put energy/ enthusiasm/effort/time into sustaining _this_ python-related forum? Accusations of hostility? Second-guessing their intentions? What right do you have to demand different behaviour from that which you yourself have demonstrated? From alfps at start.no Wed Nov 4 22:33:52 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 04:33:52 +0100 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: * Steven D'Aprano: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > >> Steven D'Aprano writes: >> >>> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >>> >>>> Steven D'Aprano writes: >>>>> Why would I want to use an already existing library that is fast, >>>>> well- written and well-supported, when I can toss together a nasty >>>>> kludge myself? >>>> Because using that library will ensure you can't migrate to Python 3 >>>> any time soon? >>> Why would I want to migrate to Python 3 any time soon? >> Sounds like you've answered the questions posed, then. Good for you! > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Since I'm just learning Python and am an utter Python novice this might not amount to much, but it's in the nature of language evolution that the new more or less incompatible version *does* become the dominant one, and for new things it's then a good idea to adopt the coming in future generally used version of the language, instead of being left in a quagmire trying to catch up with new versions of tools and libs suddenly not so compatible with the old code. This happened with e.g. C++ standardization in 1998. The whole standard library was revamped and put in a namespace, and old headers like [iostream.h] were removed. And as with the Python "/" operator core language functionality was changed: in C++98 'new' suddenly threw (Pythoneese raised) an exception instead of returning 0 on failure, and templates were suddenly "two phase" with quite different semantics, so that much old code didn't even compile, and when it did, didn't work correctly. But those who chose to stay behind paid and still for some pay the price, having to use ages old tools and libs. One amusing or sad (depending one's point of view) variant was where firms chose to get along with the language evolution, tools etc., but still restrict themselves to not only pre-standard C++ but some early 1980's version, not much more than "C with classes" or "better C". For example, at Google they generally don't use C++ exceptions, presumably because they have a large code base of non-exception-safe code. Still, assuming that's the rationale, it would surprise me if they don't use exceptions in their new code. This is perhaps an heretical view, that the new language version's advantages don't matter so much as the fact that the new language version is incompatible, viewing that incompatibility as a /reason/ to change. But I think it's realistic; getting the advantages (such as with Python 3.x improved efficiency for range etc., and thus also more clear notation) is just an added bonus. Cheers & hth., - Alf From israelu at elbit.co.il Thu Nov 5 00:53:17 2009 From: israelu at elbit.co.il (iu2) Date: Wed, 4 Nov 2009 21:53:17 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: <8851a23b-7935-4e82-9647-4ce0cc3365d6@a31g2000yqn.googlegroups.com> On Nov 4, 8:51?pm, Terry Reedy wrote: > Gabriel Genellina wrote: > > En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: > >> On Nov 4, 3:10 am, "Gabriel Genellina" wrote: > > >>> txt = """ > >>> def foo(x): > >>> ? ?print 'x=', x > > >>> def bar(x): > >>> ? ?return x + x > >>> """ > > >>> py> namespace = {} > >>> py> exec txt in namespace > >>> py> namespace.keys() > >>> ['__builtins__', 'foo', 'bar'] > >>> py> namespace['foo']('hello') > >>> x= hello > > >> What happens if both global and local dictionaries are supplied: where > >> are the newly created entities created? In the local dict? > > > The amazing thing about Python is how easy is to experiment in the > > interpreter. > > Just see it by yourself! > > Hint: they are created in the same namespace they always are (ignoring > nested functions and nonlocal namespaces). But I agree with Gabriel: > just try it. n1,n2={},{}; exec.... > > Terry Jan Reedy- Hide quoted text - > > - Show quoted text - n2 :-) From mensanator at aol.com Thu Nov 5 01:25:46 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 4 Nov 2009 22:25:46 -0800 (PST) Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: <56f7b929-025c-4ae4-bbba-9f46d8eea0db@z41g2000yqz.googlegroups.com> On Nov 4, 9:00?pm, Steven D'Aprano wrote: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > >> >> Why would I want to use an already existing library that is fast, > >> >> well- written and well-supported, when I can toss together a nasty > >> >> kludge myself? > > >> > Because using that library will ensure you can't migrate to Python 3 > >> > any time soon? > > >> Why would I want to migrate to Python 3 any time soon? > > > Sounds like you've answered the questions posed, then. Good for you! > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Itertools is worth the price of admission. As far as the "pain of migration" is concerned, less annoying than a mosquito bite. > > -- > Steven- Hide quoted text - > > - Show quoted text - From jitu.icfai at gmail.com Thu Nov 5 01:29:50 2009 From: jitu.icfai at gmail.com (jitendra gupta) Date: Thu, 5 Nov 2009 11:59:50 +0530 Subject: a is b In-Reply-To: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> References: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> Message-ID: Hi Sebas >>> w = "q" >>>a = "q" >>>id(w) 11160864 >>>id(a) 11160864 >>> z = "big string" >>> s = "big string" >>> id(z) 13675120 >>> id(s) 13674520 This is applicable for number also.. , python caches is using same id for small numbers and string. Jitendra Kumar On Thu, Nov 5, 2009 at 12:12 AM, Chris Rebert wrote: > On Wed, Nov 4, 2009 at 10:37 AM, Sebastian wrote: > > I have a question from the pyar list that may have been discussed on > this > > list, but i didn't catch it. > > Have some common objects been somewhat hardcoded into python, like some > > integers as shown in the examples below? What other object have been > > hardcoded (strings ,etc) and what was the criteria used to select them? > Any > > hints? > > See recent thread on the subject: > http://www.mail-archive.com/python-list at python.org/msg264434.html > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Thu Nov 5 02:33:26 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 5 Nov 2009 13:03:26 +0530 Subject: Python 3 Message-ID: Steven D'Aprano wrote: > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Why I am back on 2.5/2.6 Case 1 I need to use the library construct for parsing binary files http://construct.wikispaces.com/ I tried porting it to python 3 but was not successful. Dont pretend to have tried very hard but... 1. The library is quite well written but I dont know its internals 2. In fact I am just familiarisng myself with its usage 3. Intricacies of 2to3 changes their whys and wherefores are quite foreign to me -- specifically unicode matters have always frightened me. Case 2 I prefer to use python-mode in emacs for development python 3 has broken python-mode by removing execfile I suggested a (1-line) fix https://bugs.launchpad.net/python-mode/+bug/450552 Its still pending. Case 3 Python3 has a windows installer but no deb packages for ubuntu/debian I installed with the installer on windows and compiled the sources on linux (with some help of this list) However compilation takes time and converts my laptop into a toaster Given the above 2 cases I seem to have wasted the wearntear of my laptop. Summary: The attraction of python is not primarily in the language. Its not even in the batteries that are *included* but the non-included ones that are available. If that set is significantly sparser for 3 than for 2.x I dont see how many people can adopt it even if they wish to [Excludes the academics in ivory towers who discuss the subtle qualities of different languages. Been-there-done-that (was in a university for 20 years) and if I was in that context I would not use 2 or 3 but lisp, haskell or some other beautiful wonderment from arcanaland] From gagsl-py2 at yahoo.com.ar Thu Nov 5 02:34:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 04:34:16 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 18:08:49 -0300, Alf P. Steinbach escribi?: > * Terry Reedy: >> Alf P. Steinbach wrote: >> >>> However, the natural semantics is that various logical properties, >>> such as left, top, right, bottom, width and height, can be varied >>> independently. >> But they *CANNOT* be varied independently. A rectangle with side >> parallel to the axes has exactly 4 degress of freedom, not 6. > > Yes . That's the basic idea of the example I presented up-thread, > that's discussed here. With R1's state variables width and heigh can be > varied independently by direct modification, with R2 it's right and > bottom. > > The public interface must also make this choice, but it's an independent > choice: the internal rectangle representation can have the opposite > choice. > > And conversely, that means that if the internal representation isn't > used directly, then it can be changed without affecting the public > interface. And that's exactly what everyone is saying - so we all agree then! -- Gabriel Genellina From peter at www.pjb.com.au Thu Nov 5 02:45:02 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 05 Nov 2009 07:45:02 GMT Subject: MIDI.py version 3.4 Message-ID: Version 3.4 of the Python3 module MIDI.py is available through http://www.pjb.com.au/midi/MIDI.html and is believed to be pretty stable - in other words, I've actually tested it :-) (against Sean Burke's MIDI-Perl CPAN module) and it passes the tests. It's used by midisox: http://www.pjb.com.au/midi/midisox.html which can therefore also be considered increasingly stable. MIDI.py breaks out the .mid data into a simple list-of-lists structure, e.g. (in the closer-to-the-data "opus" format) [ 96, # Ticks [ # Track 0... ['note_on', 6, 1, 60, 100], ['note_off', 192, 1, 60, 100] ] ] which you can manipulate using all the resources of Python3, and then reconvert into MIDI. Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From georgeolivergo at gmail.com Thu Nov 5 03:10:54 2009 From: georgeolivergo at gmail.com (George Oliver) Date: Thu, 5 Nov 2009 00:10:54 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> I think it's long past the point where you could contain everyone who uses Python into a single community even if you tried. Besides, everyone knows about python-forum.org, right? ;) From gagsl-py2 at yahoo.com.ar Thu Nov 5 03:16:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 05:16:08 -0300 Subject: How to test urllib|urllib2-using code? References: Message-ID: En Wed, 04 Nov 2009 10:33:53 -0300, kj escribi?: > I'm sure I could find > some good answers to my question above if I could look at the test > suites for urllib and urllib2, but I can't find them anywhere. In > fact, I don't even know what exactly I should be looking for.) > Where can I find the equivalent for Python distributions? Most of the Python test suite is in the "test" subdirectory below the standard library; on Windows that's c:\PythonNN\Lib\test, on Linux /usr/lib/pythonN.N/test or /usr/local/... > dir /s/b test_url*.py D:\apps\Python26\Lib\test\test_urllib.py D:\apps\Python26\Lib\test\test_urllib2.py D:\apps\Python26\Lib\test\test_urllib2net.py D:\apps\Python26\Lib\test\test_urllib2_localnet.py D:\apps\Python26\Lib\test\test_urllibnet.py D:\apps\Python26\Lib\test\test_urlparse.py -- Gabriel Genellina From rpjday at crashcourse.ca Thu Nov 5 03:26:47 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 5 Nov 2009 03:26:47 -0500 (EST) Subject: starting with python 3.1 vs 3.2, and "test_telnetlib" Message-ID: a couple short questions. on my primary linux distro -- fedora -- python 2.x is going to be around for quite some time, but if some folks want to *start* programming in python, it seems reasonable to just co-install python 3.x and let them cut their teeth on that, invoking it with "python3". does that make sense as there seems to be little value in getting started on python 2.x. and in terms of installing python 3.x, just for fun, i used "svn" to check out the two relevant repositories: * release31-maint (for 3.1) * py3k (for 3.2) since i figured, if people are going to be using this strictly for hacking around, i can live life on the edge. however, on my f11 system, doing the configure/make/make test sequence, the 3.1 maintenance release failed two tests: multiprocessing and telnetlib, while the 3.2 branch failed only the telnetlib test. i've checked and, apparently, that telnetlib test failure has been around for a while. is there a tweak i can make to the configure and/or make to avoid that test? it would be nice to resolve it as it's the only test out of 315 that failed for me. rday p.s. the test output for telnetlib on the py3k (3.2) branch: test_telnetlib test test_telnetlib failed -- Traceback (most recent call last): File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 470, in test_debuglevel_reads self._test_debuglevel([a, EOF_sigil], b) File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 451, in _test_debuglevel txt = telnet.read_all() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 325, in read_all self.fill_rawq() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 516, in fill_rawq buf = self.sock.recv(50) socket.error: [Errno 104] Connection reset by peer i'm not running telnet on this host, and i have no intention of doing so -- it's all ssh, of course. is that what this test error is complaining about -- that it can't find a listening telnet server? -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From alfps at start.no Thu Nov 5 04:04:15 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 10:04:15 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > En Wed, 04 Nov 2009 18:08:49 -0300, Alf P. Steinbach > escribi?: >> * Terry Reedy: >>> Alf P. Steinbach wrote: >>> >>>> However, the natural semantics is that various logical properties, >>>> such as left, top, right, bottom, width and height, can be varied >>>> independently. >>> But they *CANNOT* be varied independently. A rectangle with side >>> parallel to the axes has exactly 4 degress of freedom, not 6. >> >> Yes . That's the basic idea of the example I presented up-thread, >> that's discussed here. With R1's state variables width and heigh can >> be varied independently by direct modification, with R2 it's right and >> bottom. >> >> The public interface must also make this choice, but it's an >> independent choice: the internal rectangle representation can have the >> opposite choice. >> >> And conversely, that means that if the internal representation isn't >> used directly, then it can be changed without affecting the public >> interface. > > And that's exactly what everyone is saying - so we all agree then! Well, it may be that we *violently* agree. :-) Cheers, - Alf From gagsl-py2 at yahoo.com.ar Thu Nov 5 04:15:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 06:15:25 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> <4af18733$0$6591$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Wed, 04 Nov 2009 10:52:51 -0300, Henning Bredel escribi?: > On Tue, 03 Nov 2009 21:31:27 -0300, Gabriel Genellina wrote: >> >> Then forget about the code you read in that blog post, doesn't apply to >> your use case. > > Well, but it shows how to mount plugins into the application without > creating instances instantly. I only use one plugin/module at a time, > so I'd like to avoid holding instances which aren't used. Ah, I see. Well, but you don't have to do anything special to collect plugin subclasses -- somebaseclass.__subclasses__() returns a list with all direct subclasses, without requiring a custom metaclass. This recipe [1] shows how to recursively collect all of them. (Perhaps some people prefer the metaclass approach, but not me) > Yes, I get your point. But you instantiate all available plugins. I'd > like > to avoid that. Will a callable like `plugin().initialize' avoid > that, or is an instance created immediately when passing this callable? plugin().initialize() creates a plugin instance, calls its initialize method, and then discards the instance. You probably want to create a plugin instance, store it somewhere as the "current plugin", call its initialize method, and use the "current plugin" to do some work. (Or, are the missing () after plugin().initialize intentional? Yes, this is a bound method, and it knows the plugin instance from which you got it. The instance is created at the time you ask for the bound method. You may call it later at any time. I'd probably use a bound method like that only if "initialize" is the only method you ever call on the plugin instance. In other cases, I'd store a plugin instance somewhere as described above. > Well, as far I understand it, I'd say that the ActionProvider class from > the blogpost is the (nearly) the same as your Plugin base class. All new > plugins has to implement the abstract ActionProvider class. The module > loading/recognizing is done by my main application. So what would be the > main difference here? Instead of relying on a custom metaclass, I excplicitely scan all module objects, testing for subclasses. That's all my code does, no rocket science involved :) [1] http://code.activestate.com/recipes/576949/ -- Gabriel Genellina From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 04:23:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 10:23:44 +0100 Subject: Web development with Python 3.1 In-Reply-To: References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> Message-ID: <4af2999c$0$11893$426a34cc@news.free.fr> rustom a ?crit : > On Oct 30, 6:23 pm, Dotan Cohen wrote: > >> The point is that I want to use only _Python_ features, not >> Django/Mako/whatever features. > > Pure python has a builtin templating system -- its called % Poor man's template... It only do variable substitutions - no branching nor iteration (and let's not talk about macros, inclusions, filters etc). From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 04:25:21 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 10:25:21 +0100 Subject: join , split question In-Reply-To: References: Message-ID: <4af299fc$0$11893$426a34cc@news.free.fr> elca a ?crit : > Hello, > i have some text file list such like following format. > i want to change text format to other format. > i was upload it pastebin site > http://elca.pastebin.com/d71261168 Dead link. > if anyone help With what ? From threaderslash at gmail.com Thu Nov 5 04:31:22 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 5 Nov 2009 20:31:22 +1100 Subject: Clean PyQt selection comboBox Message-ID: Hello Everybody, [image: 8)] I am using Qt and need to build a selection comboBox -- e.g.: http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG . The problem is - after one choice was made, and the code run, for the next time the user select a different choice, both, the present and all past choices run. See what I mean: [image: ;(] Code: selected color - blue we are on runBlue selected color - red we are on runBlue we are on runRed Here is the code: ......................................... QtCore.QObject.connect(self.selectComboBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.combo_activateInput) ......................................... def combo_activateInput(self): color=unicode(self.selectComboBox.currentText()) if(color == "blue"): print "selected color - blue" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) if(color == "red"): print "selected color - red" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runRed) if(color == "yellow"): print "selected color - yellow" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runYellow) del color ......................................... def combo_runBlue(self): print "we are on runBlue" def combo_runRed(self): print "we are on runRed" def combo_runYellow(self): print "we are on runYellow" I run "del color" to clean the content returned by selectComboBox.currentText, but it didn't clean the content indeed. So, any suggestion? All comments and suggestions are highly appreciated. [image: :D] [image: :D] [image: :D] -------------- next part -------------- An HTML attachment was scrubbed... URL: From tartley at tartley.com Thu Nov 5 04:47:06 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 5 Nov 2009 01:47:06 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> <4af163cc$0$6279$4f793bc4@news.tdc.fi> Message-ID: <1076c0fe-81f5-4d75-94ab-a82c15439505@k17g2000yqb.googlegroups.com> On Nov 4, 11:21?am, Vesa K?pp? wrote: > iu2 wrote: > > Another thing that I think is of interest is whether the application > > support modifying the version and description of the exe (that is, on > > Windows, when you right-click on an application and choose > > 'properties' you view the version number and description of the > > application, it is a resource inside the exe). I think py2exe supports > > it. > > Pyinstaller supports this. > > Vesa Thanks all for the inputs. I've updated my little chart and will continue to refine and fill in the blanks. From robin at reportlab.com Thu Nov 5 04:50:42 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Nov 2009 09:50:42 +0000 Subject: restricted mode??? In-Reply-To: <4AF2049B.1050709@v.loewis.de> References: <4AF2049B.1050709@v.loewis.de> Message-ID: <4AF29FF2.3050109@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >> I thought that restricted mode died ages ago. >> >> Any ideas what could be causing this? > > Restricted mode is still available, and activated whenever > a frame's builtins directory is different from the interpreter's; > see PyFrame_IsRestricted. > > Regards, > Martin thanks very much, I saw some references to mod_python & threading related to this, but nothing very obvious. -- Robin Becker From robin at reportlab.com Thu Nov 5 04:50:42 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Nov 2009 09:50:42 +0000 Subject: restricted mode??? In-Reply-To: <4AF2049B.1050709@v.loewis.de> References: <4AF2049B.1050709@v.loewis.de> Message-ID: <4AF29FF2.3050109@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >> I thought that restricted mode died ages ago. >> >> Any ideas what could be causing this? > > Restricted mode is still available, and activated whenever > a frame's builtins directory is different from the interpreter's; > see PyFrame_IsRestricted. > > Regards, > Martin thanks very much, I saw some references to mod_python & threading related to this, but nothing very obvious. -- Robin Becker From eight32 at gmail.com Thu Nov 5 04:54:50 2009 From: eight32 at gmail.com (Stuart Murray-Smith) Date: Thu, 5 Nov 2009 11:54:50 +0200 Subject: join , split question In-Reply-To: <4af299fc$0$11893$426a34cc@news.free.fr> References: <4af299fc$0$11893$426a34cc@news.free.fr> Message-ID: >> Hello, i have some text file list such like following format. >> i want to change text format to other format. >> ?i was upload it pastebin site >> http://elca.pastebin.com/d71261168 > Dead link. > With what ? http://elca.pastebin.com/d4d57929a :) From jeanmichel at sequans.com Thu Nov 5 05:10:33 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 05 Nov 2009 11:10:33 +0100 Subject: Using logging module for conditional nested logs In-Reply-To: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> References: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> Message-ID: <4AF2A499.3000701@sequans.com> Reckoner wrote: > On Nov 4, 1:30 pm, Vinay Sajip wrote: > >> On Nov 4, 7:40 pm, Reckoner wrote: >> >> >> >> >>> I hope that made some sense. >>> >> Not especially :-( >> >> Sorry I don't understand exactly what you mean, because I find your >> terminology confusing. For example, "logger that is attached to foo2" >> - loggers are not attached to functions. "It responds to the 'root' >> logger" - what responds? What's meant by "respond"? >> >> Loggers correspond to specific code components in an application. >> Normally these areas are modules and sometimes they're classes. >> >> You can certainly treat functions as areas but this will typically >> become unwieldy in any sizeable application. It doesn't (in general) >> make sense to have a specific logger for foo1 for use only when it's >> called by foo2. These seem like anti-patterns to me. >> >> Handlers are attached to loggers to make events logged via those >> loggers available to different audiences - via console, file, email >> etc. >> >> If you want to log that foo1 is being called by foo2, you can do this. >> For example, you could have a utility function which walks (a >> sufficient part of) the call stack to see the function call hierarchy, >> then log this as additional information (e.g. using the 'extra' >> parameter to the logging call). You can attach Filters to loggers and >> handlers which use this information to decide where and whether to >> actually record the event. >> >> As well as the Python logging documentation, you may also find the >> following link useful: >> >> http://plumberjack.blogspot.com/2009/09/python-logging-101.html >> >> Regards, >> >> Vinay Sajip >> > > I appreciate your patience, as I am new to this. > > Your comments have put me on the right track. I will look at the link > you specify. > > Thanks again. > _foo2Logger = None def foo2(): global _foo2Logger _foo2Logger = whateverLogger foo1() def foo1(): foo1Logger = logging.getLogger(_foo2Logger.name + '.foo1') # this is how you can "attach" dynamically a logger to another foo1Logger.info('') But for all the reasons expressed by Vinay, you don't want to do that. Jean-Michel From rustompmody at gmail.com Thu Nov 5 05:54:55 2009 From: rustompmody at gmail.com (rustom) Date: Thu, 5 Nov 2009 02:54:55 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> Message-ID: <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> On Nov 5, 2:23?pm, Bruno Desthuilliers wrote: > rustom a ?crit : > > > On Oct 30, 6:23 pm, Dotan Cohen wrote: > > >> The point is that I want to use only _Python_ features, not > >> Django/Mako/whatever features. > > > Pure python has a builtin templating system -- its called ?% > > Poor man's template... It only do variable substitutions - no branching > nor iteration (and let's not talk about macros, inclusions, filters etc). I realised that that link http://simonwillison.net/2003/Jul/28/simpleTemplates/ was written in 2003 Subsequently python has sprouted something explicitly templateish http://docs.python.org/library/string.html#template-strings From deets at nospam.web.de Thu Nov 5 06:08:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Nov 2009 12:08:04 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> Message-ID: <7lfq0kF3d079sU1@mid.uni-berlin.de> Jean-Michel Pichavant wrote: > Peng Yu wrote: >> With some automated script, I don't think it is a nightmare to change >> function names. I can change function names and filenames and their >> reference with a simple command. >> >> I'd think that this is the limitation of current version control >> system. I don't aware of any version control system that allows easy >> change of filenames. But why such features can not be implemented in >> the version control system? >> > > So one function per files bring so many problems that you need an > automated script to change one function name and complain about version > control systems messing up with your file history. > Still you insist on stating that this is the solution and that version > control system have to adapt. > It has already been told to you, and you should really consider the > following advice: > When everything is wrong except you, it may happen that *your* are > somehow wrong. > > Among all the responses you got, I don't remember any one that would > suggest you are in the right way. So what is your conclusion now ? Simple: not only are the languages he uses not proper, nor the revision control systems, and neither the editors/IDEs out there - the whole communities are of course also dysfunctional, not supporting his cause :) Diez From doesnotexist at franzoni.invalid Thu Nov 5 06:47:22 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Thu, 05 Nov 2009 11:47:22 GMT Subject: Pyfora, a place for python In-Reply-To: <87k4y5d7xg.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <87k4y5d7xg.fsf@benfinney.id.au> Message-ID: On 11/5/09 3:25 AM, Ben Finney wrote: Please, be more specific. As I said earlier in this thread, a ?forum? > could be a mailing list, a Usenet newsgroup, a walled-garden web > application, an IRC channel, or a face-to-face meeting in a pub. > > So speaking of comp.lang.python as though it's *not* a forum is > confusing. Please choose a term that makes it clear why what one is > speaking about is distinct from the comp.lang.python forum. Ok, when speaking about "forums" I meant a web-accessible public discussion group, something like those based on phpBB or Invision. But, as they correctly told me, this newgroup/mailing list is already web-accessible via Google Groups, so there would be no need for other web-based mirrors. -- Alan Franzoni contact me at public@[mysurname].eu From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 07:16:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 13:16:36 +0100 Subject: Web development with Python 3.1 In-Reply-To: <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> Message-ID: <4af2c21f$0$4917$426a74cc@news.free.fr> rustom a ?crit : > On Nov 5, 2:23 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> rustom a ?crit : >> >>> On Oct 30, 6:23 pm, Dotan Cohen wrote: >>>> The point is that I want to use only _Python_ features, not >>>> Django/Mako/whatever features. >>> Pure python has a builtin templating system -- its called % >> Poor man's template... It only do variable substitutions - no branching >> nor iteration (and let's not talk about macros, inclusions, filters etc). > > I realised that that link > http://simonwillison.net/2003/Jul/28/simpleTemplates/ > was written in 2003 > > Subsequently python has sprouted something explicitly templateish > http://docs.python.org/library/string.html#template-strings Still poor man's template. Just don't hope to do any realworld web templating with this. From rustompmody at gmail.com Thu Nov 5 07:38:40 2009 From: rustompmody at gmail.com (rustom) Date: Thu, 5 Nov 2009 04:38:40 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> <4af2c21f$0$4917$426a74cc@news.free.fr> Message-ID: On Nov 5, 5:16?pm, Bruno Desthuilliers wrote: > rustom a ?crit : > > > > > On Nov 5, 2:23 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > >> rustom a ?crit : > > >>> On Oct 30, 6:23 pm, Dotan Cohen wrote: > >>>> The point is that I want to use only _Python_ features, not > >>>> Django/Mako/whatever features. > >>> Pure python has a builtin templating system -- its called ?% > >> Poor man's template... It only do variable substitutions - no branching > >> nor iteration (and let's not talk about macros, inclusions, filters etc). > > > I realised that that link > >http://simonwillison.net/2003/Jul/28/simpleTemplates/ > > was written in 2003 > > > Subsequently python has sprouted something explicitly templateish > >http://docs.python.org/library/string.html#template-strings > > Still poor man's template. Just don't hope to do any realworld web > templating with this. This is said in the context of some of Dotan's quotes eg. > I am not a programmer by trade, only by hobby. > I want to learn Python not Django etc Python is generally imperative. Templates are by and large declarative. To get this 'Aha' across to him (remember he said hes a mechanical engineer) is (IMHO) more important than converting him to some moral high ground of reusability or some other nice software engineering jargon. From fetchinson at googlemail.com Thu Nov 5 08:10:17 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 5 Nov 2009 14:10:17 +0100 Subject: Pyfora, a place for python In-Reply-To: <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> Message-ID: > I think it's long past the point where you could contain everyone who > uses Python into a single community even if you tried. > > Besides, everyone knows about python-forum.org, right? ;) Well, no, I actually didn't :) There! Another fragmenter! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From paul at boddie.org.uk Thu Nov 5 08:48:05 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 5 Nov 2009 05:48:05 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <87k4y5d7xg.fsf@benfinney.id.au> Message-ID: On 5 Nov, 12:47, Alan Franzoni wrote: > > Ok, when speaking about "forums" I meant a web-accessible public > discussion group, something like those based on phpBB or Invision. > > But, as they correctly told me, this newgroup/mailing list is already > web-accessible via Google Groups, so there would be no need for other > web-based mirrors. I think that the community should try and make people more aware of the options. For example: http://www.python.org/community/lists/ http://wiki.python.org/moin/MailingListsAndNewsgroups (These resources need work, of course, and I encourage people to edit the Wiki-based resources and make them better.) Certainly, it's possible to read existing discussion venues - to avoid the overloaded term "forum" ;-) - using Web browsers, and I've seen Nabble promoted in some communities for this very purpose when people wanted to set up a "Web forum" because they didn't like mailing lists. I find Web forums inefficient, often full of "low-density" content (which then clogs up search results), and many of them give the impression that they won't be around for very long anyway. That said, there can still be understandable reasons why people want to have such forums, not limited to cultivating a small-scale community with an emphasis on getting to know others who are at the same level of expertise, typically with a social dimension that probably seems superfluous to those of us who use comp.lang.python and prefer that the discussion mostly remains focused on the topic of the group. Paul From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 09:08:06 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 15:08:06 +0100 Subject: join , split question In-Reply-To: References: <4af299fc$0$11893$426a34cc@news.free.fr> Message-ID: <4af2dc40$0$21867$426a34cc@news.free.fr> Stuart Murray-Smith a ?crit : >>> Hello, i have some text file list such like following format. >>> i want to change text format to other format. >>> i was upload it pastebin site >>> http://elca.pastebin.com/d71261168 > >> Dead link. > >> With what ? > > http://elca.pastebin.com/d4d57929a > Yeah, fine. And where's the code you or the OP (if not the same person) have problems with ? From paul at boddie.org.uk Thu Nov 5 09:26:12 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 5 Nov 2009 06:26:12 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <54b5ecab-bd7b-4106-9401-785e9813823d@c3g2000yqd.googlegroups.com> On 3 Nov, 16:58, Jonathan Hartley wrote: > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... Nice comparison! Perhaps this could join the material on the Wiki eventually: http://wiki.python.org/moin/DistributionUtilities If you don't want to spend time marking the table up, I'm sure I could help you out. Paul From jaybode at gmail.com Thu Nov 5 09:37:46 2009 From: jaybode at gmail.com (jay) Date: Thu, 5 Nov 2009 06:37:46 -0800 (PST) Subject: list to table Message-ID: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Hi All, Am new to using newgroup for help, but have exhausted my searching online for a solution I have a long list of data of associations between values with a value to that association as follows.. (var) to (var) = (var) hits A B 1 B A 1 A B 3 B A 3 A C 7 C A 2 And need to build a table as follows that accumulates the above: row is (from) column is (to) A B C A 0 4 7 B 4 0 0 C 2 0 0 Just can't seam to figure out how to manage this programatically. Any help or guidance much appreciated !!! Cheers, Jay From fabiofz at gmail.com Thu Nov 5 09:45:31 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 5 Nov 2009 12:45:31 -0200 Subject: Python 2.6 Global Variables In-Reply-To: References: Message-ID: On Wed, Oct 28, 2009 at 10:50 PM, mattofak wrote: > Hi All; > > I'm new to Python and moving from C, which is probably a big source of > my confusion. I'm struggling with something right now though and I > hope you all can help. > > I have a global configuration that I would like all my classes and > modules to be able to access. What is the correct way to do this? > > Thanks; > Matthew Walker > -- > http://mail.python.org/mailman/listinfo/python-list > I'd usually use the singleton pattern in this case (or you can just create a class and put things in the class -- and just as a note, I'd try to avoid declaring anything as global unless really needed). Cheers, Fabio From no.email at please.post Thu Nov 5 10:15:56 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:15:56 +0000 (UTC) Subject: How to test urllib|urllib2-using code? References: Message-ID: In Lutz Horn writes: >Hi, >kj wrote: >> I want to write some tests for code that uses both urllib and >> urllib2. >Take a look at the discussion under the title "How can one mock/stub >python module like urllib" at stackoverflow: >http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python-module-like-urllib Thanks, that helped. kynn From no.email at please.post Thu Nov 5 10:16:49 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:16:49 +0000 (UTC) Subject: How to test urllib|urllib2-using code? References: Message-ID: In "Gabriel Genellina" writes: >En Wed, 04 Nov 2009 10:33:53 -0300, kj escribi?: >> I'm sure I could find >> some good answers to my question above if I could look at the test >> suites for urllib and urllib2, but I can't find them anywhere. In >> fact, I don't even know what exactly I should be looking for.) >> Where can I find the equivalent for Python distributions? >Most of the Python test suite is in the "test" subdirectory below the >standard library; on Windows that's c:\PythonNN\Lib\test, on Linux >/usr/lib/pythonN.N/test or /usr/local/... >> dir /s/b test_url*.py >D:\apps\Python26\Lib\test\test_urllib.py >D:\apps\Python26\Lib\test\test_urllib2.py >D:\apps\Python26\Lib\test\test_urllib2net.py >D:\apps\Python26\Lib\test\test_urllib2_localnet.py >D:\apps\Python26\Lib\test\test_urllibnet.py >D:\apps\Python26\Lib\test\test_urlparse.py Muy agradecido, kynn From no.email at please.post Thu Nov 5 10:24:02 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:24:02 +0000 (UTC) Subject: Read handle concatenation Message-ID: I want to be able to take two or more open read handles and concatenate them into an object that behaves like a regular read handle (i.e. a file object open for reading), but behind the scenes it reads from the concatenated handles in sequence. I.e. I want the read-handle equivalent of the standard Unix utility cat. (The reason I can't use subprocess and cat for this is that I want to concatenate read handles that do not necessarily come from files.) The only way I know to do this from scratch is straightforward but tedious, so I thought I'd better ask to see if there's already some module that would facilitate this task. TIA! kynn From Scott.Daniels at Acm.Org Thu Nov 5 10:33:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 05 Nov 2009 07:33:40 -0800 Subject: list to table In-Reply-To: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: jay wrote: > ... > I have a long list of data of associations between values with a value > to that association as follows... > A B 1 > B A 1 > ... And need to build a table as follows that accumulates the above: > > row is (from) > column is (to) > > A B C > A 0 4 7 > B 4 0 0 > C 2 0 0 > > Just can't seam to figure out how to manage this programatically. How to solve this: Define (quite carefully) what you mean by "build a table" for yourself. Then, determine a single step that either gets you closer to the answer (going forward) or (working backward) determine something (typically some data structure) that you could use to produce the result you need. Keep pushing at both ends until you can get them to meet in the middle. --Scott David Daniels Scott.Daniels at Acm.Org From joncle at googlemail.com Thu Nov 5 10:33:41 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 07:33:41 -0800 (PST) Subject: Read handle concatenation References: Message-ID: On Nov 5, 3:24?pm, kj wrote: > I want to be able to take two or more open read handles and > concatenate them into an object that behaves like a regular read > handle (i.e. a file object open for reading), but behind the scenes > it reads from the concatenated handles in sequence. ?I.e. I want > the read-handle equivalent of the standard Unix utility cat. ?(The > reason I can't use subprocess and cat for this is that I want to > concatenate read handles that do not necessarily come from files.) > > The only way I know to do this from scratch is straightforward but > tedious, so I thought I'd better ask to see if there's already some > module that would facilitate this task. > > TIA! > > kynn Does the fileinput module do what you want? From python at mrabarnett.plus.com Thu Nov 5 10:37:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 05 Nov 2009 15:37:49 +0000 Subject: Clean PyQt selection comboBox In-Reply-To: References: Message-ID: <4AF2F14D.6090202@mrabarnett.plus.com> Threader Slash wrote: > Hello Everybody, 8) > > I am using Qt and need to build a selection comboBox -- e.g.: > http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG . > > The problem is - after one choice was made, and the code run, for the > next time the user select a different choice, both, the present and all > past choices run. See what I mean: ;( > > Code: > > selected color - blue > we are on runBlue > > selected color - red > we are on runBlue > we are on runRed > > > Here is the code: > > ......................................... > QtCore.QObject.connect(self.selectComboBox, > QtCore.SIGNAL("currentIndexChanged(QString)"), > self.combo_activateInput) > ......................................... > > def combo_activateInput(self): > color=unicode(self.selectComboBox.currentText()) > if(color == "blue"): > print "selected color - blue" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) > > if(color == "red"): > print "selected color - red" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runRed) > if(color == "yellow"): > > print "selected color - yellow" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runYellow) > del color > ......................................... > > def combo_runBlue(self): > print "we are on runBlue" > > def combo_runRed(self): > print "we are on runRed" > > def combo_runYellow(self): > print "we are on runYellow" > > I run "del color" to clean the content returned by > selectComboBox.currentText, but it didn't clean the content indeed. > "del color" doesn't "clean the content", it just says "forget this name", in this case "forget the local variable called 'color'". > So, any suggestion? All comments and suggestions are highly appreciated. > :D :D :D > The ".connect" method connects something each time it's called. If you call it multiple times then multiple things will be connected. Try using ".disconnect" to disconnect what you no longer want connected. From ethan at stoneleaf.us Thu Nov 5 11:04:44 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Nov 2009 08:04:44 -0800 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: <4AF2F79C.1070202@stoneleaf.us> Steven D'Aprano wrote: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > > >>Steven D'Aprano writes: >> >> >>>On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >>> >>> >>>>Steven D'Aprano writes: >>>> >>>>>Why would I want to use an already existing library that is fast, >>>>>well- written and well-supported, when I can toss together a nasty >>>>>kludge myself? >>>> >>>>Because using that library will ensure you can't migrate to Python 3 >>>>any time soon? >>> >>>Why would I want to migrate to Python 3 any time soon? >> >>Sounds like you've answered the questions posed, then. Good for you! > > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Python 3 is more pythonic. ;-) Cleaner, more consistent, etc. ~Ethan~ From mwilson at the-wire.com Thu Nov 5 11:05:49 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 05 Nov 2009 11:05:49 -0500 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> Message-ID: George Oliver wrote: > I think it's long past the point where you could contain everyone who > uses Python into a single community even if you tried. > > Besides, everyone knows about python-forum.org, right? ;) Or ohloh.net . Unless people use multiple pen names, there's a gang of Python developers there who don't hang out here. "stani" is the only name I recognize. Mel. From python.list at tim.thechases.com Thu Nov 5 11:06:05 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 05 Nov 2009 10:06:05 -0600 Subject: Read handle concatenation In-Reply-To: References: Message-ID: <4AF2F7ED.9030009@tim.thechases.com> > I want to be able to take two or more open read handles and > concatenate them into an object that behaves like a regular read > handle (i.e. a file object open for reading), but behind the scenes > it reads from the concatenated handles in sequence. I.e. I want > the read-handle equivalent of the standard Unix utility cat. (The > reason I can't use subprocess and cat for this is that I want to > concatenate read handles that do not necessarily come from files.) Sounds like itertools.chain would do what you want: for line in itertools.chain( file('a.txt'), file('b.txt'), ): do_something(line) or more generically if you have a list of file objects: lst = [file('a.txt'), file('b.txt'), ...] for line in itertools.chain(*lst): do_something(line) -tkc From alfps at start.no Thu Nov 5 11:09:48 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 17:09:48 +0100 Subject: list to table In-Reply-To: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: * jay: > > I have a long list of data of associations between values with a value > to that association as follows.. > > (var) to (var) = (var) hits > A B 1 > B A 1 > A B 3 > B A 3 > A C 7 > C A 2 > > And need to build a table as follows that accumulates the above: > > row is (from) > column is (to) > > A B C > A 0 4 7 > B 4 0 0 > C 2 0 0 > > Just can't seam to figure out how to manage this programatically. You're not very clear on what A, B and C are. Assuming that they're constants that denote unique values you can do something like table = dict() for k1, k2, n in list: position = (k1, k2) if position not in table: table[position] = n else: table[position] += n Disclaimer: I'm a Python newbie so there may be some much easier way... Cheers & hth., - Alf From rpjday at crashcourse.ca Thu Nov 5 11:12:18 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 5 Nov 2009 11:12:18 -0500 (EST) Subject: can i configure IDLE to use python 3.2 on fedora? Message-ID: on fedora 11 system, there is no python 3 package so i downloaded and manually installed (svn checkout) python pre-3.2 in /usr/local/bin. works fine, but if i install the python-tools package, "idle" that comes with it is hard-coded(?) to still refer to the officially-installed python-2.6. i see no way to configure idle to use the "python3" executable instead. is there a way? or am i just out of luck? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From peter.n.green at gmail.com Thu Nov 5 11:13:53 2009 From: peter.n.green at gmail.com (Peter Green) Date: Thu, 5 Nov 2009 08:13:53 -0800 (PST) Subject: Differentiating file attachments from inline attachments in Exchange Message-ID: <7154bd1c-9b5e-47ef-b7f4-990a9d1e511b@s15g2000yqs.googlegroups.com> I am trying to write some code that will scan an Exchange 2003 mailbox, detach file attachments from messages into the file system and replace them in the message with links. My initial attempt is based on Tim Golden's approach at http://timgolden.me.uk/python/win32_how_do_i/replace-outlook-attachments-with-links.html, using CDO. A typical message may contain AutoCAD drawings, PDFs, site photographs and Excel spreadsheet schedules as separate file attachments, together with inline graphics such as a corporate logo in the signature. The problem is that iterating over the message attachments using CDO detaches *everything*. I want to leave the inline images in the message body. I've looked at the CDO documentation and cannot see any property that distinguishes inline images from file attachments. I suspect I am barking up the wrong tree and need to be automating Outlook instead, but if so, any suggestions as to how I can achieve what I want? I imagine Content-Disposition Headers are going to be involved somehow... Thanks in advance, Peter From rafalgulinski at gmail.com Thu Nov 5 11:17:23 2009 From: rafalgulinski at gmail.com (Rafal Gulinski) Date: Thu, 5 Nov 2009 08:17:23 -0800 (PST) Subject: XML-RPC(using SimpleXMLRPCServer) slow on the first call References: <83d424980910121458r7518401fod78bef7104a2155e@mail.gmail.com> Message-ID: <85e125f3-614c-4e00-b436-67217509f6b1@v25g2000yqk.googlegroups.com> On 14 Pa?, 04:52, "Gabriel Genellina" wrote: > En Mon, 12 Oct 2009 18:58:45 -0300, Mahi Haile ? > escribi?: > > > Hello all,I have an xml-rpc server running on a machine in the same LAN ? > > as > > the client. Both the server and the client are in Python. > > > When I have a series of xmlrepc calls from the client to the server, the > > first call usually takes much longer than it should - orders of ? > > magnitude. > > The latency is usually sub-10ms on the other calls, but the first call ? > > takes > > up to 10 seconds or so. This are very simple functions, with almost no > > computation. > > > Do you have any ideas? > > I doubt this is a Python problem. I'd look into the network: DNS ? > resolution, IPv6 (Windows XP has some timeout issues with IPv6 enabled). > > -- > Gabriel Genellina Hi, I had quite similar issue and it was caused by some DNS settings. I solved it by changing host name to host ip (f.e. for 'localhost' it was '127.0.0.1'). I hope it will help you. Regards, Rafal From joncle at googlemail.com Thu Nov 5 11:57:23 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 08:57:23 -0800 (PST) Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> On Nov 5, 4:09?pm, "Alf P. Steinbach" wrote: > * jay: > > > > > > > I have a long list of data of associations between values with a value > > to that association as follows.. > > > (var) to (var) = (var) hits > > A B 1 > > B A 1 > > A B 3 > > B A 3 > > A C 7 > > C A 2 > > > And need to build a table as follows that accumulates the above: > > > row is (from) > > column is (to) > > > ? ?A B C > > A 0 4 7 > > B 4 0 0 > > C 2 0 0 > > > Just can't seam to figure out how to manage this programatically. > > You're not very clear on what A, B and C are. Assuming that they're constants > that denote unique values you can do something like > > > table = dict() > for k1, k2, n in list: > ? ? ?position = (k1, k2) > ? ? ?if position not in table: > ? ? ? ? ?table[position] = n > ? ? ?else: > ? ? ? ? ?table[position] += n > > > Disclaimer: I'm a Python newbie so there may be some much easier way... > > Cheers & hth., > > - Alf I read the OP as homework (I'm thinking Scott did as well), however, your code would be much nicer re-written using collections.defaultdict (int)... which I don't think is giving anything away... However, the challenge of making it 'tabular' or whatever the requirement of 'table' is, is still there. Jon. From tepperly at llnl.gov Thu Nov 5 12:20:28 2009 From: tepperly at llnl.gov (Tom Epperly) Date: Thu, 05 Nov 2009 09:20:28 -0800 Subject: Looking for portable what to determine directory where extensions are installed? Message-ID: <4AF3095C.6060906@llnl.gov> I work on a language interoperability tool, Babel https://computation.llnl.gov/casc/components/components.html; and I need a portable way to determine the directory where Python extension modules are installed by distutils (i.e., lib or lib64) to resolve this issue: https://www.cca-forum.org/bugs/babel/issue670 For example, I will invoke "python setup.py install --prefix=/home/foo/_inst --exec-prefix=/home/foo/_inst", and it usually installs the extensions in either /home/foo/_inst/lib/python2.5/site-packages or /home/foo/_inst/lib64/python2.5/site-packages. Initially, I did the following to determine where the extensions actually got installed: # assume exec_prefix=/home/foo/_inst # assume python_version=`python -c 'import sys; print sys.version' | sed '1s/^\(...\).*/\1/g;1q'` RUNTIME_PYTHON="$exec_prefix/lib/python$python_verbose/site-packages" This worked fine until I started running on 64-bit Python machines where the correct result was RUNTIME_PYTHON="$exec_prefix/lib64/python$python_verbose/site-packages" The first 64-bit machine I was using seemed to have this patch: http://bugs.python.org/file14726/Python-2.6.2-multilib.patch, so I amended my script to the following: pylib=`$PYTHON -c "import sys; print sys.__dict__.get('lib','lib')"` RUNTIME_PYTHON="$exec_prefix/$pylib/python$python_version/site-packages" However, this approach doesn't work with Fedora Core 12 prerelease or some other 64-bit Linux distributions. They don't define "sys.lib". I thought distutils.sysconfig.get_python_lib() might be helpful, but it returns "/usr/lib/python2.6/site-packages" even on the system where "/usr/lib64/python2.6/site-packages" is the right answer. Is there a canonical, Pythonic way to determine whether an installation of Python uses "lib" or "lib64"? Or is there a way to determine the full path of where distutils will install extensions relative to the specified exec prefix? Regards, Tom Epperly From joncle at googlemail.com Thu Nov 5 12:40:31 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 09:40:31 -0800 (PST) Subject: join , split question References: <4af299fc$0$11893$426a34cc@news.free.fr> <4af2dc40$0$21867$426a34cc@news.free.fr> Message-ID: <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> On Nov 5, 2:08?pm, Bruno Desthuilliers wrote: > Stuart Murray-Smith a ?crit : > > >>> Hello, i have some text file list such like following format. > >>> i want to change text format to other format. > >>> ?i was upload it pastebin site > >>>http://elca.pastebin.com/d71261168 > > >> Dead link. > > >> With what ? > > >http://elca.pastebin.com/d4d57929a > > Yeah, fine. And where's the code you or the OP (if not the same person) > have problems with ? I'd certainly be curious to see it, especially with the pagecheck() line 22 @ http://elca.pastebin.com/f5c69fe41 From jim.vickroy at noaa.gov Thu Nov 5 14:15:06 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Thu, 05 Nov 2009 12:15:06 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? Message-ID: Hello, I have just upgraded from Python 2.5 to 2.6 and am unable to locate any trace of the --install-script option, in release 2.6.4 (MS Windows XP), for distutils.core.setup. I also have been unable to locate any mention of it on-line. My v2.5 setup.py scripts are failing with the falling error: error: option --install-script not recognized I apologize for missing something obvious here, but I am stuck. Thanks in advance for your feedback. -- jv From lelandpeng at gmail.com Thu Nov 5 15:02:53 2009 From: lelandpeng at gmail.com (Leland) Date: Thu, 5 Nov 2009 12:02:53 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary Message-ID: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Hi, I always use readline(), strip(), split() and so on to parse a string. Is there some elegant way to parse the following string into a dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? NET_NAME '50MHZ_CLK_SRC' '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; NODE_NAME U122 2 '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': 'CLK2': CDS_PINID='CLK2'; NODE_NAME R1395 1 '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': 'A': CDS_PINID='A'; Thanks, Leland From flashk at gmail.com Thu Nov 5 16:00:17 2009 From: flashk at gmail.com (Farshid) Date: Thu, 5 Nov 2009 13:00:17 -0800 (PST) Subject: 2to3 ParseError with UTF-8 BOM Message-ID: I'm using Python 2.6.2 and when I run the 2to3 script on a file that contains a UTF-8 BOM I get the following error: RefactoringTool: Can't parse : ParseError: bad token: type=55, value='\xef', context=('', (1, 0)) If I remove the BOM then it works fine. Is this expected behavior or a bug in the 2to3 script? -farshid From emile at fenx.com Thu Nov 5 16:05:25 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 05 Nov 2009 13:05:25 -0800 Subject: parse a string (Cadence Allegro Netlist) to dictionary In-Reply-To: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On 11/5/2009 12:02 PM Leland said... > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; > > Thanks, > Leland This does it, but not very elegantly... mydict = dict( (kk[0].replace("'",""),",".join(kk[1:])) for kk in [ [ [ jj for jj in ii.split("\n") if jj.strip() ][0] for ii in txt.split("_NAME")[1:] ] ]) Emile From sjmachin at lexicon.net Thu Nov 5 16:18:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 5 Nov 2009 13:18:39 -0800 (PST) Subject: elementtree XML() unicode References: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> <4af18322$0$7620$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <1fddd745-14ba-4dac-8379-20841c15dd0a@y28g2000prd.googlegroups.com> On Nov 5, 12:35?am, Stefan Behnel wrote: > John Machin, 04.11.2009 02:56: > > > On Nov 4, 12:14 pm, Kee Nethery wrote: > >> The reason I am confused is that getResponse2 is classified as an ? > >> "str" in the Komodo IDE. I want to make sure I don't lose the non- > >> ASCII characters coming from the URL. > > > str is all about 8-bit bytes. > > True in Py2.x, false in Py3. And the context was 2.x. > What you mean is the "bytes" type, which, sadly, was named "str" in Python 2.x. What you mean is the "bytes" concept. > The problem the OP ran into was due to the fact that Python 2.x handled > "ASCII characters in a unicode string" <-> "ASCII encoded byte string" > conversion behind the scenes, which lead to all sorts of trouble to loads > of people, and was finally discarded in Python 3.0. What you describe is the symptom. The problems are (1) 2.X ET expects a str object but the OP supplied a unicode object, and (2) 2.X ET didn't check that, so it accidentally "worked" provided the contents were ASCII-only, and otherwise gave a novice-mystifying error message. From tjreedy at udel.edu Thu Nov 5 17:31:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Nov 2009 17:31:46 -0500 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. I am in a different position since I did not have current code that would need migrating. > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? I am writing a book on algorithms that uses a subset of 3.1 as the algorithm language. It it simply cleaner and easier to explain to people not already familiar with the quirks of 2.x. One small but important-to-me example. I do not need to put 'from __future__ import integerdivision' (or whatever the incantation is) as the top of files. Hence I do not need to waste energy (mime and readers) explaining furture imports and the specifics of the old versus new meaning of int/int. While I initially resisted the text==unicode change, I now see it as essential to the future of Python as a world algorithm language. I admit that I am more bothered about the leftover quirks (to me -- sludge) in 2.x than most. Unless you are the author/maintainer of an essential library, I have no opinion as to what you do with old code, or even what you use for new code. I do care about people trying to disparage or sabotage 3.x. Terry Jan Reedy From debatem1 at gmail.com Thu Nov 5 17:42:42 2009 From: debatem1 at gmail.com (geremy condra) Date: Thu, 5 Nov 2009 17:42:42 -0500 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: On Thu, Nov 5, 2009 at 5:31 PM, Terry Reedy wrote: > Steven D'Aprano wrote: > >> I've played around with 3.0, and I've read the What's New for 3.1 (and am >> installing 3.1 now), and while the changes look nice, I'm not sure that >> they're nice enough to deal with the pain of 2to3 migration. > > I am in a different position since I did not have current code that would > need migrating. > >> So how about that, 3.1 fans? What are the most compelling reasons for you >> that convinced you to change? > > I am writing a book on algorithms that uses a subset of 3.1 as the algorithm > language. It it simply cleaner and easier to explain to people not already > familiar with the quirks of 2.x. One small but important-to-me example. I do > not need to put 'from __future__ import integerdivision' (or whatever the > incantation is) as the top of files. Hence I do not need to waste energy > (mime and readers) explaining furture imports and the specifics of the old > versus new meaning of int/int. I agree. Most of my code is primarily mathematical, and while I personally see the move away from functional programming techniques as a minor misstep, the cleanliness of it all more than makes up for that. Geremy Condra From threaderslash at gmail.com Thu Nov 5 17:55:56 2009 From: threaderslash at gmail.com (Threader Slash) Date: Fri, 6 Nov 2009 09:55:56 +1100 Subject: Clean PyQt selection comboBox Message-ID: > ---------- Original message ---------- > From: MRAB > To: python-list at python.org > Date: Thu, 05 Nov 2009 15:37:49 +0000 > Subject: Re: Clean PyQt selection comboBox > Threader Slash wrote: > >> Hello Everybody, 8) >> >> I am using Qt and need to build a selection comboBox -- e.g.: >> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG. >> >> The problem is - after one choice was made, and the code run, for the next >> time the user select a different choice, both, the present and all past >> choices run. See what I mean: ;( >> >> Code: >> >> selected color - blue >> we are on runBlue >> >> selected color - red >> we are on runBlue >> we are on runRed >> >> >> Here is the code: >> >> ......................................... >> QtCore.QObject.connect(self.selectComboBox, >> QtCore.SIGNAL("currentIndexChanged(QString)"), >> self.combo_activateInput) ......................................... >> >> def combo_activateInput(self): >> color=unicode(self.selectComboBox.currentText()) >> if(color == "blue"): >> print "selected color - blue" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runBlue) >> >> if(color == "red"): >> print "selected color - red" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runRed) if(color >> == "yellow"): >> >> print "selected color - yellow" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runYellow) >> del color ......................................... >> >> def combo_runBlue(self): >> print "we are on runBlue" >> >> def combo_runRed(self): >> print "we are on runRed" >> >> def combo_runYellow(self): >> print "we are on runYellow" >> >> I run "del color" to clean the content returned by >> selectComboBox.currentText, but it didn't clean the content indeed. >> >> "del color" doesn't "clean the content", it just says "forget this > name", in this case "forget the local variable called 'color'". > > So, any suggestion? All comments and suggestions are highly appreciated. >> :D :D :D >> >> The ".connect" method connects something each time it's called. If you > call it multiple times then multiple things will be connected. > > Try using ".disconnect" to disconnect what you no longer want connected. > > ---------- ---------- > Thanks Man! You saved the day. It solved the problem... ................................................................ def combo_runBlue(self): print "we are on runBlue" QtCore.QObject.disconnect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) ................................................................ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nuffnough at gmail.com Thu Nov 5 18:10:51 2009 From: nuffnough at gmail.com (Nuff Nuff) Date: Thu, 5 Nov 2009 15:10:51 -0800 (PST) Subject: Need help dumping exif data in canon raw files Message-ID: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> So I've looked at all sorts of things, gone through as many different things as I can find, but I fear python just can't do it. I just need to be able to extract the exif info from a canon CR2 file. The info from canon suggest that it's just the same as a tiff, but anytime I try to get PIL to open one, it says that it tastes bad. And canon don't seem to be all that forthcoming on the details. Ideally I'd be able to update the file with new exif info too, but that would just be a bonus. Right now I just want to open a file (say /home/nuffi/IMG_0001.CR2 or d:\pic\IMG_0001.CR2) and print out all the exif info attached to the file. Is it impossible in Python? TIA! Nuffi From gagsl-py2 at yahoo.com.ar Thu Nov 5 18:11:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 20:11:32 -0300 Subject: Looking for portable what to determine directory where extensions are installed? References: <4AF3095C.6060906@llnl.gov> Message-ID: En Thu, 05 Nov 2009 14:20:28 -0300, Tom Epperly escribi?: > I work on a language interoperability tool, Babel > https://computation.llnl.gov/casc/components/components.html; and I need > a portable way to determine the directory where Python extension modules > are installed by distutils (i.e., lib or lib64) to resolve this issue: > https://www.cca-forum.org/bugs/babel/issue670 The distutils SIG is probably a better place to ask: http://www.python.org/community/sigs/current/distutils-sig/ -- Gabriel Genellina From shawjacob4 at gmail.com Thu Nov 5 18:19:00 2009 From: shawjacob4 at gmail.com (Jacob Shaw) Date: Thu, 5 Nov 2009 15:19:00 -0800 (PST) Subject: PiCloud Beta Release References: <47ab340d-befa-4ad8-99db-fd4494ace7fa@x25g2000prf.googlegroups.com> Message-ID: <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> On Nov 1, 5:13?pm, Ken Elkabany wrote: > Hello, > > PiCloud has just released a Python library, cloud, which allows you to > easily offload the execution of a function to a cluster of servers > running on Amazon Web Services. As a beta product, we are currently > free to all users who sign up with beta code "PYTHONLIST". To > register, go tohttp://www.picloud.com > > Full service description: > PiCloud is a cloud-computing platform that integrates into the Python > Programming Language. It enables you to leverage the compute power of > Amazon Web Services without having to manage, maintain, or configure > virtual servers. > > PiCloud integrates seamlessly into your existing code base through a > custom Python library, cloud. To offload the execution of a function > to the cloud, all you must do is pass your desired function into the > cloud library. PiCloud will then run the function on its > high-performance and automatically-scaling cluster. We quickly scale > our server capacity, both up and down, to meet your computational > needs, and only charge you for the resources you actually consume. > Getting on the cloud has never been this easy! > > PiCloud improves the full cycle of software development and > deployment. Functions that are run on PiCloud have their resource > usage monitored, performance analyzed, and errors traced; we further > aggregate all your functions to give you a bird's eye view of your > service. Through these introspective capabilities, PiCloud enables you > to develop faster, easier, and smarter. > > Common use cases for our platform: > * Crawling the web > * Manipulating images and videos > * Generating charts and graphs > * Statistical/Mathematical analysis of data sets > * Real-time data processing > > Cheers, > > Ken Elkabany > PiCloud, Inc. Wow, amazing service. I used PiCloud for some scraping work, and my script ran about 10x as fast. Some questions though: 1) I have another project which uses a custom python extension written in C++. Is there a way to use it on PiCloud? 2) I noticed you guys only support python 2.5 and 2.6. Will there be 3.1 support eventually? From http Thu Nov 5 18:27:02 2009 From: http (Paul Rubin) Date: 05 Nov 2009 15:27:02 -0800 Subject: Need help dumping exif data in canon raw files References: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> Message-ID: <7xd43w1rjt.fsf@ruckus.brouhaha.com> Nuff Nuff writes: > I just need to be able to extract the exif info from a canon CR2 > file. The info from canon suggest that it's just the same as a tiff, > but anytime I try to get PIL to open one, it says that it tastes > bad. And canon don't seem to be all that forthcoming on the details. CR2 is a hardware-specific raw format and PIL should not be expected to understand it. Try a websearch for dcraw.c to find a decoder for it. From sajmikins at gmail.com Thu Nov 5 18:48:35 2009 From: sajmikins at gmail.com (Simon Forman) Date: Thu, 5 Nov 2009 18:48:35 -0500 Subject: Why do you use python? In-Reply-To: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> Message-ID: <50f98a4c0911051548y5d020128xe4879586c4395100@mail.gmail.com> On Sat, Oct 31, 2009 at 2:11 AM, sk wrote: > What would be your answer if this question is asked to you in an > interview? > > a modified version might be: > "Where would you use python over C/C++/Java?" > > (because my resume says I know C/C++/Java)? Mark Miller has some adages posted on his homepage. [1] One of my favorites is this: "A Computer's Perspective on Moore's Law: Humans are getting more expensive at an exponential rate." Python saves you human-time. Python allows you to write software that runs, is readable, can be maintained and modified easily, etc... far better than any other language I've ever used. You can write working code, and read and understand already-written code /faster/ in Python than any other language I've ever used. Use Python. I would use C (to write Python extensions) only where profiling had shown a definite hotspot, and then only when there were no better algorithmic choices available. I would never use C++ or Java. (N.B. I've managed to be gainfully, and blissfully, employed programming in Python for about six years now. I've passed on otherwise interesting jobs because the folks involved were using something other than Python.) I'm actually working at a startup at the moment that originally hired me to "do python" and then decided to use PHP because more of the team (two out of three) knew it and didn't know python. I figured "what the heck, it's been awhile, and it will look good on my resume" so I have stuck with them. PHP isn't as horrible as I remembered, but it's still horrible. /Everything/ is horrible compared to Python. WTF is wrong with people? (Disclaimer: Smalltalk and LISP are not horrible... *grin*) Anyway, I wouldn't say all that in an interview, heh, but that's my $0.02. My strong advice to you or any programmer is, don't bother interviewing with a company that's not already committed to using Python as their main language (modulo extraordinary circumstances.) [1] http://www.caplet.com/adages.html From alfps at start.no Thu Nov 5 19:23:27 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 01:23:27 +0100 Subject: list to table In-Reply-To: <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: * Jon Clements: > > I read the OP as homework (I'm thinking Scott did as well), Sorry. Need to recalibrate that neural network. Back-propagation initiated... Done! :-) > however, > your code would be much nicer re-written using collections.defaultdict > (int)... which I don't think is giving anything away... Thanks! This sent me searching everywhere, because the documentation of '+=' and other "augmented assignment statements" says "The target is only evaluated once.", like in C++, which implies a kind of reference to mutable object. I couldn't immediately see how subscription could apparently return a reference to mutable int object in Python in a way so that it worked transparently (the idiom in C++). However, it worked to replace collections.defaultdict with a class overriding __getitem__ and __setitem__, so I guess that's how it works, that in this case '+=' is simply translated like 'x += n' -> 'temp = x; x = temp + n'. Is this a correct understanding, and if so, what exactly does the documentation mean for the general case? E.g. def foo(): print( "foo" ) d = dict(); d[43] = 666 return d def bar(): print( "bar" ) return 43; foo()[bar()] += 1 produces foo bar so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but evidently more like 'a = foo(); i = bar(); a.__setitem__(i, a.__getitem__(i) + 1)'? If so, is this behavior defined anywhere? I did find discussion (end of ?6.2 of the language reference) of the case where the target is an attibute reference, with this example: class A: x = 3 # class variable a = A() a.x += 1 # writes a.x as 4 leaving A.x as 3 :-) Cheers, & thanks, - Alf From metal29a at gmail.com Thu Nov 5 19:23:55 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:23:55 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On 11?6?, ??4?02?, Leland wrote: > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; > > Thanks, > Leland not very elegantly too. x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s) """ print {x[0]: x[1:]} >>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']} """ From metal29a at gmail.com Thu Nov 5 19:34:37 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:34:37 -0800 (PST) Subject: join , split question References: Message-ID: On 11?4?, ??5?39?, elca wrote: > Hello, > i have some text file list such like following format. > i want to change text format to other format. > ?i was upload it pastebin sitehttp://elca.pastebin.com/d71261168 > > if anyone help ,much appreciate thanks in advance > -- > View this message in context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html > Sent from the Python - python-list mailing list archive at Nabble.com. s = """uji708 uhodih utus29 agamu4 azi340 ekon62 """ from itertools import cycle for i, x in zip(cycle(range(3)), s.splitlines()): print x + ',', if i == 2: print """ uji708, uhodih, utus29, agamu4, azi340, ekon62, """ From rhodri at wildebst.demon.co.uk Thu Nov 5 19:42:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 06 Nov 2009 00:42:39 -0000 Subject: parse a string (Cadence Allegro Netlist) to dictionary In-Reply-To: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On Thu, 05 Nov 2009 20:02:53 -0000, Leland wrote: > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; Here's an inelegant way: **** CODE **** results = {} net_name_next = False net_name = None node_names = [] for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): if net_name is not None: results[net_name] = ", ".join(node_names) net_name = None node_names = [] net_name_next = True elif net_name_next: net_name = line.strip("'") net_name_next = False elif line.startswith('NODE_NAME'): node_names.append("{1}.{2}".format(*line.split())) # Last time through if net_name is not None: results[net_name] = ", ".join(node_names) **** END CODE **** If you're prepared to allow the dictionary values to be lists rather than strings, we can squash that down: **** CODE **** results = {None: []} net_name = None for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): net_name = sourcefile.next().strip(" \t\n'") results[net_name] = [] elif line.startswith('NODE_NAME'): results[net_name].append("{1}.{2}".format(*line.split())) del results[None] **** END CODE **** If you can guarantee that you won't meet a NODE_NAME before you see a NET_NAME then you can lose the messing about with results[None]. Having spent today picking up the pieces from an assumption that's rotted after several years, I'm not feeling that brave. A slightly less messy version of that would be: **** CODE **** results = {} entry = [] for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): entry = [] results[sourcefile.next().strip(" \t\n'")] = entry elif line.startswith('NODE_NAME'): entry.append("{1}.{2}".format(*line.split())) **** END CODE **** I'm a little dubious about doing mutable magic like this without copious comments, though. -- Rhodri James *-* Wildebeest Herder to the Masses From metal29a at gmail.com Thu Nov 5 19:46:04 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:46:04 -0800 (PST) Subject: join , split question References: Message-ID: On 11?6?, ??8?34?, metal wrote: > On 11?4?, ??5?39?, elca wrote: > > > Hello, > > i have some text file list such like following format. > > i want to change text format to other format. > > ?i was upload it pastebin sitehttp://elca.pastebin.com/d71261168 > > > if anyone help ,much appreciate thanks in advance > > -- > > View this message in context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > s = """uji708 > uhodih > utus29 > agamu4 > azi340 > ekon62 > """ > > from itertools import cycle > for i, x in zip(cycle(range(3)), s.splitlines()): > ? ? print x + ',', > ? ? if i == 2: > ? ? ? ? print > > """ > uji708, uhodih, utus29, > agamu4, azi340, ekon62, > """ yet another version, a little evil s = """uji708 uhodih utus29 agamu4 azi340 ekon62 """ from itertools import * print '\n'.join(','.join(x for i, x in g) for k, g in groupby(enumerate (s.splitlines()), lambda (i, x): i/3)) """ uji708,uhodih,utus29 agamu4,azi340,ekon62 """ From skip at pobox.com Thu Nov 5 20:50:57 2009 From: skip at pobox.com (Skip Montanaro) Date: Thu, 05 Nov 2009 19:50:57 -0600 Subject: 2to3 on Mac - unknown encoding: mbcs Message-ID: I tried naively running 2to3 over the SpamBayes source code on my Mac and got this traceback: Traceback (most recent call last): File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py", line 281, in find_cookie codec = lookup(encoding) LookupError: unknown encoding: mbcs SpamBayes does have several files which contain the "mbcs" coding cookie: ./windows/py2exe/gen_py/addin-designer.py ./windows/py2exe/gen_py/office-9.py ./windows/py2exe/gen_py/outlook-9.py After a little hunting I came across the docs for the codecs module, which for "mbcs" states: Windows only: Encode operand according to the ANSI codepage (CP_ACP) Is there something I can use to replace the mbcs coding cookies which will allow 2to3 to process these Windows-specific files? Thanks, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From aahz at pythoncraft.com Thu Nov 5 20:54:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Nov 2009 17:54:19 -0800 Subject: Freezing python files into executables References: Message-ID: In article , Mike Driscoll wrote: > >Something that you might want to try in the future is GUI2Exe, which >allows you to play with a whole slew of freezing modules: Does GUI2Exe work from just the command-line? I spent a fair amount of time getting rid of the Mac GUI .pkg creator and I sure don't want to introduce more GUI into our ant build process. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From highcar at gmail.com Thu Nov 5 21:08:08 2009 From: highcar at gmail.com (elca) Date: Thu, 5 Nov 2009 18:08:08 -0800 (PST) Subject: join , split question In-Reply-To: <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> References: <26193334.post@talk.nabble.com> <4af299fc$0$11893$426a34cc@news.free.fr> <4af2dc40$0$21867$426a34cc@news.free.fr> <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> Message-ID: <26225646.post@talk.nabble.com> Jon Clements-2 wrote: > > On Nov 5, 2:08?pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Stuart Murray-Smith a ?crit : >> >> >>> Hello, i have some text file list such like following format. >> >>> i want to change text format to other format. >> >>> ?i was upload it pastebin site >> >>>http://elca.pastebin.com/d71261168 >> >> >> Dead link. >> >> >> With what ? >> >> >http://elca.pastebin.com/d4d57929a >> >> Yeah, fine. And where's the code you or the OP (if not the same person) >> have problems with ? > > I'd certainly be curious to see it, especially with the pagecheck() > line 22 @ http://elca.pastebin.com/f5c69fe41 > > -- > http://mail.python.org/mailman/listinfo/python-list > > thanks all! i was resolved :) -- View this message in context: http://old.nabble.com/join-%2C-split-question-tp26193334p26225646.html Sent from the Python - python-list mailing list archive at Nabble.com. From brian at sweetapp.com Thu Nov 5 21:24:03 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 6 Nov 2009 13:24:03 +1100 Subject: futures - a new package for asynchronous execution Message-ID: Hey all, I recently implemented a package that I'd like to have include in the Python 3.x standard library (and maybe Python 2.x) and I'd love to have the feedback of this list. The basic idea is to implement an asynchronous execution method patterned heavily on java.util.concurrent (but less lame because Python has functions as first-class objects). Here is a fairly advanced example: import futures import functools import urllib.request URLS = [ 'http://www.foxnews.com/', 'http://www.cnn.com/', 'http://europe.wsj.com/', 'http://www.bbc.co.uk/', 'http://some-made-up-domain.com/'] def load_url(url, timeout): return urllib.request.urlopen(url, timeout=timeout).read() # Use a thread pool with 5 threads to download the URLs. Using a pool # of processes would involve changing the initialization to: # with futures.ProcessPoolExecutor(max_processes=5) as executor with futures.ThreadPoolExecutor(max_threads=5) as executor: future_list = executor.run_to_futures( [functools.partial(load_url, url, 30) for url in URLS]) # Check the results of each future. for url, future in zip(URLS, future_list): if future.exception() is not None: print('%r generated an exception: %s' % (url, future.exception())) else: print('%r page is %d bytes' % (url, len(future.result()))) In this example, executor.run_to_futures() returns only when every url has been retrieved but it is possible to return immediately, on the first completion or on the first failure depending on the desired work pattern. The complete docs are here: http://sweetapp.com/futures/ A draft PEP is here: http://code.google.com/p/pythonfutures/source/browse/trunk/PEP.txt And the code is here: http://pypi.python.org/pypi/futures3/ All feedback appreciated! Cheers, Brian From benjamin at python.org Thu Nov 5 22:18:54 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 6 Nov 2009 03:18:54 +0000 (UTC) Subject: 2to3 ParseError with UTF-8 BOM References: Message-ID: Farshid gmail.com> writes: > If I remove the BOM then it works fine. Is this expected behavior or a > bug in the 2to3 script? Try the 2to3 distributed in Python 3.1. From pengyu.ut at gmail.com Thu Nov 5 22:41:22 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 21:41:22 -0600 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? Message-ID: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> I looked though the os.path manual. I don't find a function that can test if a path is in a directory or its sub-directory (recursively). For example, /a/b/c/d is in /a its sub-directory (recursively). Could somebody let me know if such function is available somewhere? From clp2 at rebertia.com Thu Nov 5 22:53:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 19:53:14 -0800 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> Message-ID: <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: > I looked though the os.path manual. I don't find a function that can > test if a path is in a directory or its sub-directory (recursively). > > For example, /a/b/c/d is in /a its sub-directory (recursively). Could > somebody let me know if such function is available somewhere? Couldn't you just canonicalize the paths using os.path.abspath() and friends and then do subdirectory.startswith(parent_directory) [as strings]? Cheers, Chris -- http://blog.rebertia.com From pengyu.ut at gmail.com Thu Nov 5 23:19:08 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 22:19:08 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? Message-ID: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> Suppose I have a list of strings, A. I want to compute the list (call it B) of strings that are elements of A but doesn't match a regex. I could use a for loop to do so. In a functional language, there is way to do so without using the for loop. I'm wondering what is the best way to compute B in python. From clp2 at rebertia.com Thu Nov 5 23:25:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 20:25:24 -0800 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> Message-ID: <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. > > I'm wondering what is the best way to compute B in python. Since this sounds rather homework-y, I'll only give you a pointer: http://docs.python.org/tutorial/datastructures.html#list-comprehensions Cheers, Chris -- http://blog.rebertia.com From groups at tolomea.com Thu Nov 5 23:57:18 2009 From: groups at tolomea.com (Gordon) Date: Thu, 5 Nov 2009 20:57:18 -0800 (PST) Subject: ctypes exception in callback handlind Message-ID: This post concerns the situation where Python code calls C code via ctypes, the C code then calls a callback back into Python code which in turn raises an exception. Currently as I understand things when the callback finishes and control is returning to C land ctypes will catch and print the exception and then return normally back to C. The standard way of doing something meaningful with the exception is to catch it in the callback, set a global flag, somehow encourage the C code to unwind back to the original Python call and there check the flag and re-raise the exception. My current problems involves a non recoverable error being raised in the callback. The intermediate C code is not at all setup to deal with a failure like this and I can't find a way to "somehow encourage the C code to unwind". For extra giggles I can't just hit sys.exit as this stack got invoked as a callback out of a third party python library that needs to do some clean up. All of which leaves me wishing that ctypes would propgate the exception back to the python calling context for me. One approach I can think of that I would like to get some feedback on is the following: Create a new ctypes calling convention that does a setjmp on entry. When using that calling convention if an exception is raised by a call back, catch it and store it somewhere, longjmp back to the setjmp point and re-raise it. I appreciate that this will generally leave the intervening C code in an undefined state and as such would definitely have to be an optional feature. I realize that I could in theory do this myself by wrapping each of the C calls with a wrapper that does the setjmp work, but there are quite a few of them. So any comments or suggestions? G From gagsl-py2 at yahoo.com.ar Thu Nov 5 23:58:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 01:58:31 -0300 Subject: distutils.core.setup --install-script option in Python 2.6 ? References: Message-ID: En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy escribi?: > I have just upgraded from Python 2.5 to 2.6 and am unable to locate any > trace of the --install-script option, in release 2.6.4 (MS Windows XP), > for distutils.core.setup. I also have been unable to locate any mention > of it on-line. Do you mean this option? http://docs.python.org/distutils/builtdist.html#the-postinstallation-script Probably the distutils SIG is a better place to ask: http://www.python.org/community/sigs/current/distutils-sig/ -- Gabriel Genellina From pengyu.ut at gmail.com Fri Nov 6 00:23:12 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 23:23:12 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> Message-ID: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: > On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >> Suppose I have a list of strings, A. I want to compute the list (call >> it B) of strings that are elements of A but doesn't match a regex. I >> could use a for loop to do so. In a functional language, there is way >> to do so without using the for loop. >> >> I'm wondering what is the best way to compute B in python. > > Since this sounds rather homework-y, I'll only give you a pointer: > http://docs.python.org/tutorial/datastructures.html#list-comprehensions Now, I want to in-place delete elements in A that matches the regex. I know that I need to use del. But I'm not sure how to use the functional style programming for this problem. Would you please let me know? From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:26:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:26:52 -0300 Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach escribi?: > * Jon Clements: > This sent me searching everywhere, because the documentation of '+=' and > other "augmented assignment statements" says > > "The target is only evaluated once.", > > like in C++, which implies a kind of reference to mutable object. Not exactly. For an augmented assignment, the target (left side) may be an identifier, an atttribute reference, or a subscription/slicing. In the first case, the comment simply does not apply (there is a single one opportunity to evaluate the target). a += some(expression) means: evaluate "a", evaluate some(expression), perform the operation +=, bind the resulting object to the name "a". a.attr += some(expression) means: evaluate "a", ask it for its attribute "attr", evaluate some(expression), perform the operation +=, ask the (already known) object "a" to store the resulting object as its attribute "attr". a[index] += some(expression) performs a similar sequence of steps; "a" is evaluated only once, then it is asked to retrieve its element at [index], the computation is performed, and finally the (already known) object "a" is asked to store the result at [index]. "The target is only evaluated once." means that it is NOT reevaluated before the final result is stored. Same applies to "index" above, although this is not explicited. Perhaps it is more clear with a longer expression: a[b+c].c[d(e[f])].h += 1 computes the a[b+c].c[d(e[f])] part only once. > I couldn't immediately see how subscription could apparently return a > reference to mutable int object in Python in a way so that it worked > transparently (the idiom in C++). It does not. It perform first a "getitem" operation followed by a "setitem" to store the result. A normal dictionary would fail when asked for an inexistent item; a defaultdict creates and returns a default value in such case. py> import collections py> d = collections.defaultdict(int) py> d['a'] += 1 py> d['a'] += 1 py> d['a'] 2 py> d['b'] 0 note: int() returns 0; defaultdict(lambda: 0) could have been used. > However, it worked to replace collections.defaultdict with a class > overriding __getitem__ and __setitem__, so I guess that's how it works, > that in this case '+=' is simply translated like 'x += n' -> 'temp = x; > x = temp + n'. > > Is this a correct understanding, and if so, what exactly does the > documentation mean for the general case? If x is a simple name, the only difference between x += n and x = x+n is the method invoked to perform the operation (__iadd__ vs __add__ in arbitrary objects). Both x and n are evaluated only once - and this is not an optimization, nor a shortcut, simply there is no need to do otherwise (please make sure you understand this). From the docs for the operator module: "Many operations have an ?in-place? version. The following functions provide a more primitive access to in-place operators than the usual syntax does; for example, the statement x += y is equivalent to x = operator.iadd(x, y). Another way to put it is to say that z = operator.iadd(x, y) is equivalent to the compound statement z = x; z += y." http://docs.python.org/library/operator.html > foo()[bar()] += 1 > > so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but > evidently more like 'a = foo(); i = bar(); a.__setitem__(i, > a.__getitem__(i) + 1)'? Yes, something like that. > If so, is this behavior defined anywhere? Isn't the description at http://docs.python.org/reference/simple_stmts.html#assignment-statements enough? It goes to some detail describing, e.g., what a.x = 1 means. The next section explains what a.x += 1 means in terms of the former case. > I did find discussion (end of ?6.2 of the language reference) of the > case where the target is an attibute reference, with this example: > > class A: > x = 3 # class variable > a = A() > a.x += 1 # writes a.x as 4 leaving A.x as 3 Do you want to discuss this example? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:42:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:42:30 -0300 Subject: 2to3 on Mac - unknown encoding: mbcs References: Message-ID: En Thu, 05 Nov 2009 22:50:57 -0300, Skip Montanaro escribi?: > I tried naively running 2to3 over the SpamBayes source code on my Mac > and got this traceback: > > Traceback (most recent call last): > File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py", > line 281, in find_cookie > codec = lookup(encoding) > LookupError: unknown encoding: mbcs > > SpamBayes does have several files which contain the "mbcs" coding > cookie: > > ./windows/py2exe/gen_py/addin-designer.py > ./windows/py2exe/gen_py/office-9.py > ./windows/py2exe/gen_py/outlook-9.py > > After a little hunting I came across the docs for the codecs module, > which for "mbcs" states: > > Windows only: Encode operand according to the ANSI codepage (CP_ACP) > > Is there something I can use to replace the mbcs coding cookies which > will allow 2to3 to process these Windows-specific files? Using mbcs as the source encoding declaration is evil (and stupid too). mbcs means "whatever encoding is currently configured in Windows", it is not a specific encoding. You have to guess which encoding those files are in. windows-1252 (almost the same as latin-1) is the one used in "Western Europe", which covers an area much broader than its name. Good luck, -- Gabriel Genellina From rpjday at crashcourse.ca Fri Nov 6 01:48:48 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 01:48:48 -0500 (EST) Subject: listing an object's methods/attributes? Message-ID: getting back into python after a long hiatus and "diving" into python 3 (http://www.diveintopython3.org/), but i can't remember how to list an object's full set of methods or attributes. how does that go again? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:49:15 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:49:15 -0300 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> Message-ID: En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert escribi?: > On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >> I looked though the os.path manual. I don't find a function that can >> test if a path is in a directory or its sub-directory (recursively). >> >> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >> somebody let me know if such function is available somewhere? > > Couldn't you just canonicalize the paths using os.path.abspath() and > friends and then do subdirectory.startswith(parent_directory) [as > strings]? Beware of directories starting with the same letters. I'd canonicalize, split the strings on os.sep, and compare the resulting lists up to the shortest one. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:52:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:52:50 -0300 Subject: ctypes exception in callback handlind References: Message-ID: En Fri, 06 Nov 2009 01:57:18 -0300, Gordon escribi?: > This post concerns the situation where Python code calls C code via > ctypes, the C code then calls a callback back into Python code which > in turn raises an exception. I'd ask in a ctypes specific list: -- Gabriel Genellina From timr at probo.com Fri Nov 6 01:52:58 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Nov 2009 22:52:58 -0800 Subject: disable image loading to speed up webpage load References: Message-ID: <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> elca wrote: > >im using win32com 's webbrowser module. Win32com does not have a webbrowser module. Do you mean you are using Internet Explorer via win32com? >i have some question about it.. >is it possible to disable image loading to speed up webpage load? If you are using IE, then you need to tell IE to disable image loading. I don't know a way to do that through the IE COM interface. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Fri Nov 6 01:57:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 22:57:03 -0800 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: <50697b2c0911052257g292ab4feg5889aa56b1efbb23@mail.gmail.com> On Thu, Nov 5, 2009 at 9:23 PM, Peng Yu wrote: > On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: >> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >>> Suppose I have a list of strings, A. I want to compute the list (call >>> it B) of strings that are elements of A but doesn't match a regex. I >>> could use a for loop to do so. In a functional language, there is way >>> to do so without using the for loop. >>> >>> I'm wondering what is the best way to compute B in python. >> >> Since this sounds rather homework-y, I'll only give you a pointer: >> http://docs.python.org/tutorial/datastructures.html#list-comprehensions > > Now, I want to in-place delete elements in A that matches the regex. I > know that I need to use del. But I'm not sure how to use the > functional style programming for this problem. Would you please let me > know? Deletion is an imperative operation which has no direct equivalent in functional languages, so your question is nonsensical. To do it functionally, instead of deleting, you simply build a new list that omits the undesired elements. See also the built-in function filter(). Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:59:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:59:39 -0300 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: En Fri, 06 Nov 2009 02:23:12 -0300, Peng Yu escribi?: > On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: >> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >>> Suppose I have a list of strings, A. I want to compute the list (call >>> it B) of strings that are elements of A but doesn't match a regex. I >>> could use a for loop to do so. In a functional language, there is way >>> to do so without using the for loop. >>> >>> I'm wondering what is the best way to compute B in python. >> >> Since this sounds rather homework-y, I'll only give you a pointer: >> http://docs.python.org/tutorial/datastructures.html#list-comprehensions > > Now, I want to in-place delete elements in A that matches the regex. I > know that I need to use del. But I'm not sure how to use the > functional style programming for this problem. Would you please let me > know? Functional and del don't mix. What about: B = [item for item in A if regex.match(item) is None] B = filter(lambda item: regex.match(item) is None, A) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 02:10:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 04:10:02 -0300 Subject: listing an object's methods/attributes? References: Message-ID: En Fri, 06 Nov 2009 03:48:48 -0300, Robert P. J. Day escribi?: > getting back into python after a long hiatus and "diving" into > python 3 (http://www.diveintopython3.org/), but i can't remember how > to list an object's full set of methods or attributes. how does that > go again? Try dir(the_object), vars(the_object), help(the_object), see(the_object) - this last one a hidden gem from http://github.com/inky/see (see is "dir for humans") -- Gabriel Genellina From alfps at start.no Fri Nov 6 02:29:05 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 08:29:05 +0100 Subject: list to table In-Reply-To: References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: * Gabriel Genellina: > En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach > escribi?: > [snip] > From the docs for the operator module: "Many operations have an > ?in-place? version. The following functions provide a more primitive > access to in-place operators than the usual syntax does; for example, > the statement x += y is equivalent to x = operator.iadd(x, y). Another > way to put it is to say that z = operator.iadd(x, y) is equivalent to > the compound statement z = x; z += y." > http://docs.python.org/library/operator.html Thanks! >> foo()[bar()] += 1 >> >> so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but >> evidently more like 'a = foo(); i = bar(); a.__setitem__(i, >> a.__getitem__(i) + 1)'? > > Yes, something like that. > >> If so, is this behavior defined anywhere? > > Isn't the description at > http://docs.python.org/reference/simple_stmts.html#assignment-statements > enough? It goes to some detail describing, e.g., what a.x = 1 means. The > next section explains what a.x += 1 means in terms of the former case. No, it wasn't exactly enough for me, coming most recently from a C++ background. One reason was as mentioned that the C++ standard has essentially the /same wording/ about "only evaluated once" but with a more strict meaning; in C++, with the built-in += operator a()[foo()] += 1; not only avoids calling a() and foo() twice, it also avoids doing the internal indexing twice, while in python the internal indexing, locating that item, is performed first in __getitem__ and then in __setitem__ (unless that is optimized away at lower level by caching last access, but that in itself has overhead). Another reason was that ?6.2 does explicitly discuss attribute references as targets, but not subscription as target. It would have been more clear to me if all (four?) possible target forms were discussed. Happily you did now discuss that in the part that I snipped above, but would've been nice, and easier for for an other-language-thinking person :-), if it was in documentation. >> I did find discussion (end of ?6.2 of the language reference) of the >> case where the target is an attibute reference, with this example: >> >> class A: >> x = 3 # class variable >> a = A() >> a.x += 1 # writes a.x as 4 leaving A.x as 3 > > Do you want to discuss this example? Thanks but no, it's OK, I understand it. Cheers, - Alf From lie.1296 at gmail.com Fri Nov 6 02:30:18 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 06 Nov 2009 18:30:18 +1100 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: Message-ID: <4af3d0ae@dnews.tpgi.com.au> Peng Yu wrote: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. In functional language, there is no looping, so that argument is kind of pointless. The looping construct in many functional language is a syntax sugar for recursion. In python, instead of explicit loop, you can use either: map(pattern.match, list_of_strs) or [pattern.match(mystr) for mystr in list_of_strs] or if you want to be wicked evil, you can write a recursive function as such: def multimatcher(list_of_strs, index=0): return [] if index >= len(list_of_strs) else ( multimatcher( list_of_strs[index + 1] ).append( pattern.match(list_of_strs[index]) ) ) From clp2 at rebertia.com Fri Nov 6 03:19:56 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 00:19:56 -0800 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> Message-ID: <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> On Thu, Nov 5, 2009 at 10:49 PM, Gabriel Genellina wrote: > En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert > escribi?: >> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >>> I looked though the os.path manual. I don't find a function that can >>> test if a path is in a directory or its sub-directory (recursively). >>> >>> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >>> somebody let me know if such function is available somewhere? >> >> Couldn't you just canonicalize the paths using os.path.abspath() and >> friends and then do subdirectory.startswith(parent_directory) [as >> strings]? > > Beware of directories starting with the same letters. > I'd canonicalize, split the strings on os.sep, and compare the resulting > lists up to the shortest one. Ah, I thought there was some edge case I must've missed; my solution seemed too simple. Cheers, Chris From samuelrobertson at gmail.com Fri Nov 6 03:48:47 2009 From: samuelrobertson at gmail.com (sam) Date: Fri, 6 Nov 2009 00:48:47 -0800 (PST) Subject: decoding a byte array that is unicode escaped? Message-ID: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> I have a byte stream read over the internet: responseByteStream = urllib.request.urlopen( httpRequest ); responseByteArray = responseByteStream.read(); The characters are encoded with unicode escape sequences, for example a copyright symbol appears in the stream as the bytes: 5C 75 30 30 61 39 which translates to: \u00a9 which is unicode for the copyright symbol. I am simply trying to display this copyright symbol on a webpage, so how do I encode the byte array to utf-8 given that it is 'escape encoded' in the above way? I tried: responseByteArray.decode('utf-8') and responseByteArray.decode('unicode_escape') and str(responseByteArray). I am using Python 3.1. From __peter__ at web.de Fri Nov 6 03:59:24 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2009 09:59:24 +0100 Subject: decoding a byte array that is unicode escaped? References: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> Message-ID: sam wrote: > I have a byte stream read over the internet: > > responseByteStream = urllib.request.urlopen( httpRequest ); > responseByteArray = responseByteStream.read(); > > The characters are encoded with unicode escape sequences, for example > a copyright symbol appears in the stream as the bytes: > > 5C 75 30 30 61 39 > > which translates to: > \u00a9 > > which is unicode for the copyright symbol. > > I am simply trying to display this copyright symbol on a webpage, so > how do I encode the byte array to utf-8 given that it is 'escape > encoded' in the above way? I tried: > > responseByteArray.decode('utf-8') > and responseByteArray.decode('unicode_escape') > and str(responseByteArray). > > I am using Python 3.1. Convert the bytes to unicode first: >>> u = b"\\u00a9".decode("unicode-escape") >>> u '?' Then convert the string to bytes: >>> u.encode("utf-8") b'\xc2\xa9' From deets at nospam.web.de Fri Nov 6 04:05:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Nov 2009 10:05:30 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: Message-ID: <7li76qF3cq9l0U1@mid.uni-berlin.de> Peng Yu schrieb: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. Nonsense. For processing over each element, you have to loop over them, either with or without growing a call-stack at the same time. FP languages can optimize away the stack-frame-growth (tail recursion) - but this isn't reducing complexity in any way. So use a loop, either directly, or using a list-comprehension. Diez From gagsl-py2 at yahoo.com.ar Fri Nov 6 04:28:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 06:28:58 -0300 Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: En Fri, 06 Nov 2009 04:29:05 -0300, Alf P. Steinbach escribi?: > * Gabriel Genellina: >> En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach >> escribi?: >> >>> foo()[bar()] += 1 >>> > One reason was as mentioned that the C++ standard has essentially the > /same wording/ about "only evaluated once" but with a more strict > meaning; in C++, with the built-in += operator > > a()[foo()] += 1; > > not only avoids calling a() and foo() twice, it also avoids doing the > internal indexing twice, while in python the internal indexing, locating > that item, is performed first in __getitem__ and then in __setitem__ > (unless that is optimized away at lower level by caching last access, > but that in itself has overhead). Yes, that's a common misunderstanding in people coming from other languages with a different semantics for "assignment" and "variable". You're not alone :) Python does not have "lvalues" as in C++. In the statement x=1, the left hand side does not denote an object, but a name. x.attr=1 and x[index]=1 act more like a function call (they *are* function calls actually) than assignments. > Another reason was that ?6.2 does explicitly discuss attribute > references as targets, but not subscription as target. It would have > been more clear to me if all (four?) possible target forms were > discussed. Happily you did now discuss that in the part that I snipped > above, but would've been nice, and easier for for an > other-language-thinking person :-), if it was in documentation. Yes, probably that section should be improved (except the final example added, the text hasn't changed since it was first written, more than 9 years ago). Reading reference material may be terribly boring, I admit. Most people read only the specific sections required to solve a specific problem; and some concepts that are introduced earlier in the book are missed or skipped. If you haven't already done so, try at least to read these two sections from the Language Reference: 3.1. Objects, values and types, and 4.1. Naming and binding. They define the most important concepts in Python; the rest are just details. -- Gabriel Genellina From rpjday at crashcourse.ca Fri Nov 6 04:56:34 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 04:56:34 -0500 (EST) Subject: why does "help(import)" not work? Message-ID: i'm sure there's a painfully obvious answer to this, but is there a reason i can't do: >>> help(import) File "", line 1 help(import) ^ SyntaxError: invalid syntax >>> on the other hand, i can certainly go into "help()" and type "import" to get that help. it seems counter-intuitive to have the first variation fail but the second succeed. what is the rule for this in python3? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From simon at brunningonline.net Fri Nov 6 05:10:37 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:10:37 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <8c7f10c60911060210j47f8b46oa400158f64096d44@mail.gmail.com> 2009/11/6 Robert P. J. Day : > > ?i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > ?File "", line 1 > ? ?help(import) > ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax import is a keyword, not an object. -- Cheers, Simon B. From deets at nospam.web.de Fri Nov 6 05:11:44 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Nov 2009 11:11:44 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <7lib31F3ekkv5U1@mid.uni-berlin.de> Robert P. J. Day schrieb: > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. > > what is the rule for this in python3? import is a keyword, so the parser can't comprehend the expression you created. In the same way it can't do it for help(class) or help(def) or any other keyword. Diez From clp2 at rebertia.com Fri Nov 6 05:12:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 02:12:09 -0800 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > ?i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > ?File "", line 1 > ? ?help(import) > ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax >>>> > > ?on the other hand, i can certainly go into "help()" and type > "import" to get that help. ?it seems counter-intuitive to have the > first variation fail but the second succeed. > > ?what is the rule for this in python3? "Special cases aren't special enough to break the rules." -- Zen of Python (http://www.python.org/dev/peps/pep-0020/) It would take a hideous kludge to make help(import) work. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 6 05:12:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 06 Nov 2009 11:12:38 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <4af3f68b$0$31102$426a74cc@news.free.fr> Robert P. J. Day a ?crit : > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) Yes, there's a very painfully obvious reason : 'import' is a statement, 'help' is a function, and you can't (syntactically) pass a statement as an argument to function !-) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. Would you find it more "intuitive" to have different syntactic rules for the interactive shell ?-) FWIW, the way to get help on a statement (or on a non-already defined name) is to pass a string to help, ie: help("import") HTH From jim.vickroy at noaa.gov Fri Nov 6 05:12:40 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:12:40 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: References: Message-ID: <4AF3F698.50309@noaa.gov> Gabriel Genellina wrote: > En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy > escribi?: > >> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >> any trace of the --install-script option, in release 2.6.4 (MS Windows >> XP), for distutils.core.setup. I also have been unable to locate any >> mention of it on-line. > > Do you mean this option? > http://docs.python.org/distutils/builtdist.html#the-postinstallation-script ... actually, I really do mean the --install-script option > Probably the distutils SIG is a better place to ask: > http://www.python.org/community/sigs/current/distutils-sig/ > Thanks for the tip, I'll give that a try. From Jim.Vickroy at noaa.gov Fri Nov 6 05:12:40 2009 From: Jim.Vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:12:40 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: References: Message-ID: <4AF3F698.50309@noaa.gov> Gabriel Genellina wrote: > En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy > escribi?: > >> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >> any trace of the --install-script option, in release 2.6.4 (MS Windows >> XP), for distutils.core.setup. I also have been unable to locate any >> mention of it on-line. > > Do you mean this option? > http://docs.python.org/distutils/builtdist.html#the-postinstallation-script ... actually, I really do mean the --install-script option > Probably the distutils SIG is a better place to ask: > http://www.python.org/community/sigs/current/distutils-sig/ > Thanks for the tip, I'll give that a try. From brian at sweetapp.com Fri Nov 6 05:14:02 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 6 Nov 2009 21:14:02 +1100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: Hi Robert, help() is just a regular function that must be called with correct Python syntax and the import keyword is not allowed in an argument list. The correct syntax is: help('import') Cheers, Brian On 6 Nov 2009, at 20:56, Robert P. J. Day wrote: > > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax >>>> > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. > > what is the rule for this in python3? > > rday > -- > > > = > = > ====================================================================== > Robert P. J. Day Waterloo, Ontario, > CANADA > > Linux Consulting, Training and Kernel Pedantry. > > Web page: http://crashcourse.ca > Twitter: http://twitter.com/rpjday > = > = > ====================================================================== > -- > http://mail.python.org/mailman/listinfo/python-list From rpjday at crashcourse.ca Fri Nov 6 05:28:19 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:28:19 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Chris Rebert wrote: > On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > > ?i'm sure there's a painfully obvious answer to this, but is there a > > reason i can't do: > > > >>>> help(import) > > ?File "", line 1 > > ? ?help(import) > > ? ? ? ? ? ? ?^ > > SyntaxError: invalid syntax > >>>> > It would take a hideous kludge to make help(import) work. > > Cheers, > Chris um ... ok, i'll take your word for it, but is there at least a generalizable pattern for what is directly help()able and what isn't? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From Jim.Vickroy at noaa.gov Fri Nov 6 05:30:32 2009 From: Jim.Vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:30:32 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: <4AF3F698.50309@noaa.gov> References: <4AF3F698.50309@noaa.gov> Message-ID: <4AF3FAC8.4080601@noaa.gov> j vickroy wrote: > Gabriel Genellina wrote: >> En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy >> escribi?: >> >>> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >>> any trace of the --install-script option, in release 2.6.4 (MS >>> Windows XP), for distutils.core.setup. I also have been unable to >>> locate any mention of it on-line. >> >> Do you mean this option? >> http://docs.python.org/distutils/builtdist.html#the-postinstallation-script >> > ... actually, I really do mean the --install-script option Oh my, you are exactly right. That is it. That is what happens when I work at 3:00 AM. What I did not communicate clearly in my initial posting is that --install-script does not seem to be accepted in 2.6.4 and I could find no mention of that being the case on-line. Nor could I find this option in the 2.6.4 distutils source code of my Python installation. > >> Probably the distutils SIG is a better place to ask: >> http://www.python.org/community/sigs/current/distutils-sig/ >> > > Thanks for the tip, I'll give that a try. From jim.vickroy at noaa.gov Fri Nov 6 05:30:32 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:30:32 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: <4AF3F698.50309@noaa.gov> References: <4AF3F698.50309@noaa.gov> Message-ID: <4AF3FAC8.4080601@noaa.gov> j vickroy wrote: > Gabriel Genellina wrote: >> En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy >> escribi?: >> >>> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >>> any trace of the --install-script option, in release 2.6.4 (MS >>> Windows XP), for distutils.core.setup. I also have been unable to >>> locate any mention of it on-line. >> >> Do you mean this option? >> http://docs.python.org/distutils/builtdist.html#the-postinstallation-script >> > ... actually, I really do mean the --install-script option Oh my, you are exactly right. That is it. That is what happens when I work at 3:00 AM. What I did not communicate clearly in my initial posting is that --install-script does not seem to be accepted in 2.6.4 and I could find no mention of that being the case on-line. Nor could I find this option in the 2.6.4 distutils source code of my Python installation. > >> Probably the distutils SIG is a better place to ask: >> http://www.python.org/community/sigs/current/distutils-sig/ >> > > Thanks for the tip, I'll give that a try. From rpjday at crashcourse.ca Fri Nov 6 05:31:50 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:31:50 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: On Fri, 6 Nov 2009, Brian Quinlan wrote: > Hi Robert, > > help() is just a regular function that must be called with correct > Python syntax and the import keyword is not allowed in an argument > list. > > The correct syntax is: > help('import') ah, ok, now it makes sense. so python3 just lets me be sloppy about it, as in: >>> help(print) got it. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From clp2 at rebertia.com Fri Nov 6 05:36:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 02:36:14 -0800 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <50697b2c0911060236r7b0eff66q728c38a6a24b80e2@mail.gmail.com> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Chris Rebert wrote: > >> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: >> > ?i'm sure there's a painfully obvious answer to this, but is there a >> > reason i can't do: >> > >> >>>> help(import) >> > ?File "", line 1 >> > ? ?help(import) >> > ? ? ? ? ? ? ?^ >> > SyntaxError: invalid syntax >> >>>> > >> It would take a hideous kludge to make help(import) work. > > ?um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what isn't? Language keywords aren't help()-able: http://docs.python.org/reference/lexical_analysis.html#keywords Neither are punctuation/operators (see other sections on same webpage). help() is run-of-the-mill function, no different than any other, is not treated specially, and doesn't perform magic. You can't pass raw syntax elements to functions (whether the functions are built-in or user-defined). Cheers, Chris -- http://blog.rebertia.com From rpjday at crashcourse.ca Fri Nov 6 05:36:21 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:36:21 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Chris Rebert wrote: > > > On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > > > ?i'm sure there's a painfully obvious answer to this, but is there a > > > reason i can't do: > > > > > >>>> help(import) > > > ?File "", line 1 > > > ? ?help(import) > > > ? ? ? ? ? ? ?^ > > > SyntaxError: invalid syntax > > >>>> > > > It would take a hideous kludge to make help(import) work. > > > > Cheers, > > Chris > > um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what > isn't? never mind, i was just educated on the proper usage of help(). i *knew* i was going to embarrass myself when i asked that. :-P back to reading. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From simon at brunningonline.net Fri Nov 6 05:45:38 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:45:38 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <8c7f10c60911060245vb5a2fa7r8475c8ca393d4f1b@mail.gmail.com> 2009/11/6 Robert P. J. Day : > ?um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what isn't? If it's an object (or to be precise, a name bound to an object), it's helpable. If it's a keyword, it's not - and in fact can't be, since as you've found, it's a syntax error - so you fall back to passing a string. -- Cheers, Simon B. From simon at brunningonline.net Fri Nov 6 05:47:00 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:47:00 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <8c7f10c60911060247q54101abcs5c98b17ee502ab02@mail.gmail.com> 2009/11/6 Robert P. J. Day : > ?ah, ok, now it makes sense. ?so python3 just lets me be sloppy about > it, as in: print is a function in Python 3, so that's fine. In Python 2, that would also be a syntax error. -- Cheers, Simon B. From paul.nospam at rudin.co.uk Fri Nov 6 05:49:17 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 06 Nov 2009 10:49:17 +0000 Subject: why does "help(import)" not work? References: Message-ID: <87iqdoc4ia.fsf@rudin.co.uk> "Robert P. J. Day" writes: > On Fri, 6 Nov 2009, Brian Quinlan wrote: > >> Hi Robert, >> >> help() is just a regular function that must be called with correct >> Python syntax and the import keyword is not allowed in an argument >> list. >> >> The correct syntax is: >> help('import') > > ah, ok, now it makes sense. so python3 just lets me be sloppy about > it, as in: > > >>> help(print) > > got it. In python 3 print is a function. From sion at viridian.paintbox Fri Nov 6 05:51:46 2009 From: sion at viridian.paintbox (Sion Arrowsmith) Date: Fri, 06 Nov 2009 10:51:46 GMT Subject: why does "help(import)" not work? References: Message-ID: <6dTIm.43163$%%3.9141@newsfe23.ams2> Robert P. J. Day wrote: >On Fri, 6 Nov 2009, Brian Quinlan wrote: >> The correct syntax is: >> help('import') > > ah, ok, now it makes sense. so python3 just lets me be sloppy about >it, as in: > > >>> help(print) No, "print" is a function in python3, not a statement as it is in earlier versions. There's nothing sloppy about it, and nothing in help has changed from 2 to 3: if it's a language keyword, you need to pass help it's name; if it's a function or a class, you can pass help the object itself. -- \S under construction From ldo at geek-central.gen.new_zealand Fri Nov 6 07:09:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 07 Nov 2009 01:09:51 +1300 Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: In message <87eioghrsk.fsf at benfinney.id.au>, Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> -- ?ScrolledCavas? should be >> ?ScrolledCanvas?. > > Thanks for finding and describing a fault with the Python documentation. > This is not the right place for reporting it, though: this is the Python > user forum, not an appropriate place for reporting faults. > > If you would like the issue to be addressed, please report it to the > Python bug tracking system . What do you want, a bloody HTML patch? Just fix the damn typo, already! From no.email at please.post Fri Nov 6 07:12:40 2009 From: no.email at please.post (kj) Date: Fri, 6 Nov 2009 12:12:40 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? Message-ID: In Perl one can assign a value to any element of an array, even to ones corresponding to indices greater or equal than the length of the array: my @arr; $arr[999] = 42; perl grows the array as needed to accommodate this assignment. In fact one common optimization in Perl is to "pre-grow" the array to its final size, rather than having perl grow it piecemeal as required by assignments like the one above: my @arr; $#arr = 999_999; After assigning to $#arr (the last index of @arr) as shown above, @arr has length 1,000,000, and all its elements are initialized to undef. In Python the most literal translation of the first code snippet above triggers an IndexError exception: >>> arr = list() >>> arr[999] = 42 Traceback (most recent call last): File "", line 1, in IndexError: list assignment index out of range In fact, one would need to pre-grow the list sufficiently to be able to make an assignment like this one. I.e. one needs the equivalent of the second Perl snippet above. The best I can come up with is this: arr = [None] * 1000000 Is this the most efficient way to achieve this result? TIA! kynn From http Fri Nov 6 07:34:08 2009 From: http (Paul Rubin) Date: 06 Nov 2009 04:34:08 -0800 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <7x7hu3g7cv.fsf@ruckus.brouhaha.com> kj writes: > >>> arr[999] = 42 > ... > The best I can come up with is this: > arr = [None] * 1000000 > Is this the most efficient way to achieve this result? If you're talking about an array of ints, use the array module. You might also look at numpy. From mrkafk at gmail.com Fri Nov 6 08:20:42 2009 From: mrkafk at gmail.com (mk) Date: Fri, 06 Nov 2009 14:20:42 +0100 Subject: is None or == None ? Message-ID: Hello, Some claim that one should test for None using: if x is None: ..but the standard equality which is theoretically safer works as well: if x == None: So, which one is recommended? Can there be two None objects in interpreter's memory? Is testing for identity of some variable with None safe? Does language guarantee that? Or is it just property of implementation? Regards, mk From dickinsm at gmail.com Fri Nov 6 08:28:44 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 6 Nov 2009 05:28:44 -0800 (PST) Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: On Nov 6, 12:09?pm, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.... at benfinney.id.au>, Ben Finney wrote: > > > Lawrence D'Oliveiro writes: > > >> -- ?ScrolledCavas? should be > >> ?ScrolledCanvas?. > > > Thanks for finding and describing a fault with the Python documentation. > > This is not the right place for reporting it, though: this is the Python > > user forum, not an appropriate place for reporting faults. > > > If you would like the issue to be addressed, please report it to the > > Python bug tracking system . > > What do you want, a bloody HTML patch? Nope; just the first two lines of your original post in a bugs.python.org report would be plenty. If you make sure to mark 'Documentation' in the Components field, I think this will get corrected pretty quickly. > Just fix the damn typo, already! Who is this addressed to? The chances are that the people most likely to fix this aren't reading this thread. I'd fix it myself, but I'm at work at the moment with no commit access to the Python svn repo. And by the time I get home, I'll probably have forgotten about it. Filing a bugs.python.org issue makes sure that this *will* get noticed by someone. Mark From cokofreedom at gmail.com Fri Nov 6 08:32:58 2009 From: cokofreedom at gmail.com (hob) Date: Fri, 6 Nov 2009 05:32:58 -0800 (PST) Subject: Best way for permutating using multiple lists? Message-ID: if __name__ == '__main__': permutations = list() for i in list('def'): for j in list('abc'): for k in list('mno'): for l in list('mno'): for m in list('wxyz'): permutations.append() print '\t'.join("%s" % i for i in permutations) I'd rather find a way that can perform a permutation over any number of lists. I know there should be a way of doing this but my head isn't working today, any advice people? From stefan_ml at behnel.de Fri Nov 6 08:33:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 Nov 2009 14:33:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> mk, 06.11.2009 14:20: > Some claim that one should test for None using: > > if x is None: Which is the correct and safe way of doing it. > ..but the standard equality which is theoretically safer works as well: > > if x == None: Absolutely not safe, think of class Test(object): def __eq__(self, other): return other == None print Test() == None, Test() is None Stefan From dickinsm at gmail.com Fri Nov 6 08:33:47 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 6 Nov 2009 05:33:47 -0800 (PST) Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: On Nov 6, 12:09?pm, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.... at benfinney.id.au>, Ben Finney wrote: > > > Lawrence D'Oliveiro writes: > > >> -- ?ScrolledCavas? should be > >> ?ScrolledCanvas?. > > > Thanks for finding and describing a fault with the Python documentation. > > This is not the right place for reporting it, though: this is the Python > > user forum, not an appropriate place for reporting faults. > > > If you would like the issue to be addressed, please report it to the > > Python bug tracking system . > > What do you want, a bloody HTML patch? Just fix the damn typo, already! http://bugs.python.org/issue7271 Mark From alfps at start.no Fri Nov 6 08:35:14 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 14:35:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: * mk: > Hello, > > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? > > Can there be two None objects in interpreter's memory? Is testing for > identity of some variable with None safe? Does language guarantee that? > Or is it just property of implementation? As I understand it, 'is' will always work and will always be efficient (it just checks the variable's type), while '==' can depend on the implementation of equality checking for the other operand's class. Cheers & hth., - Alf From joncle at googlemail.com Fri Nov 6 08:39:44 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 05:39:44 -0800 (PST) Subject: Best way for permutating using multiple lists? References: Message-ID: On Nov 6, 1:32?pm, hob wrote: > if __name__ == '__main__': > ? ? permutations = list() > ? ? for i in list('def'): > ? ? ? ? for j in list('abc'): > ? ? ? ? ? ? for k in list('mno'): > ? ? ? ? ? ? ? ? for l in list('mno'): > ? ? ? ? ? ? ? ? ? ? for m in list('wxyz'): > ? ? ? ? ? ? ? ? ? ? ? ? permutations.append() > ? ? print '\t'.join("%s" % i for i in permutations) > > I'd rather find a way that can perform a permutation over any number > of lists. I know there should be a way of doing this but my head isn't > working today, any advice people? itertools.permutations (maybe with itertools.chain)? hth Jon. From motoom at xs4all.nl Fri Nov 6 08:43:07 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Fri, 06 Nov 2009 14:43:07 +0100 Subject: Best way for permutating using multiple lists? In-Reply-To: References: Message-ID: <4AF427EB.8010804@xs4all.nl> hob wrote: > any advice people? import itertools alt=itertools.product("def","abc","mno","mno","wxyz") -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From youngde811 at gmail.com Fri Nov 6 08:59:00 2009 From: youngde811 at gmail.com (david) Date: Fri, 6 Nov 2009 05:59:00 -0800 (PST) Subject: Why do you use python? References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> Message-ID: <63004d17-0f51-48bb-85a5-ab17b8cc27d9@z41g2000yqz.googlegroups.com> I liked your disclaimer (I'm done a lot of commercial Common Lisp), and I agree with your comments regarding python. I've turned down recruiters who have offered otherwise interesting positions, but Java was being used. This is just personal, and I'm not going to disparage anyone who enjoys Java, C++, whatever. But for me, dynamic languages (particularly python and Lisp) are so far ahead of anything else. -- david From sjmachin at lexicon.net Fri Nov 6 09:09:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 6 Nov 2009 06:09:03 -0800 (PST) Subject: is None or == None ? References: Message-ID: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> On Nov 7, 12:35?am, "Alf P. Steinbach" wrote: > * mk: > > > Hello, > > > Some claim that one should test for None using: > > > if x is None: > > > ..but the standard equality which is theoretically safer works as well: > > > if x == None: > > > So, which one is recommended? > > > As I understand it, 'is' will always work and will always be efficient (it just > checks the variable's type), It doesn't check the type. It doesn't need to. (x is y) is true if x and y are the same object. If that is so, then of course (type(x) is type(y)) is true, and if not so, their types are irrelevant. "is" testing is very efficient in the CPython implementation: addressof(x) == addressof(y) From joncle at googlemail.com Fri Nov 6 09:11:44 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 06:11:44 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On Nov 6, 12:12?pm, kj wrote: [snip] > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? That's a good as it gets I think. If sparsely populated I might be tempted to use a dict (or maybe defaultdict): d = {999: 42, 10673: 123} for idx in xrange(1000000): # Treat it as though it's a list of 1,000,000 items... print 'index %d has a value of %d' % (idx, d.get(idx, None)) Efficiency completely untested. Jon. From marco at sferacarta.com Fri Nov 6 09:13:14 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 06 Nov 2009 15:13:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: <_9WIm.27714$813.11966@tornado.fastwebnet.it> Alf P. Steinbach wrote: > As I understand it, 'is' will always work and will always be efficient > (it just checks the variable's type), while '==' can depend on the > implementation of equality checking for the other operand's class. "== None" makes sense, for instance, in the context of the SQLAlchemy sql construction layer, where the underlying machinery defines __eq__() / __ne__() and generates the appropriate 'IS NULL' SQL code when appropriate. From san82moon at gmail.com Fri Nov 6 09:15:06 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 06:15:06 -0800 (PST) Subject: newbie question - python lists Message-ID: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> hi, rfids= ['01','02'] i = 01 row = {} items = [] for rfid in rfids: brains = ['1','2'] if brains: for brain in brains: # this loop must run only once for each value of i row['itemnos'] = 'item_0'+str(i)+'s' print 'hi' items.append(row) print items break i=i+1 the above code produces output a: [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] but i want it to be, [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] can anyone point wer am erroring. Thanks in advance. From mrkafk at gmail.com Fri Nov 6 09:32:52 2009 From: mrkafk at gmail.com (mk) Date: Fri, 06 Nov 2009 15:32:52 +0100 Subject: is None or == None ? In-Reply-To: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> References: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > mk, 06.11.2009 14:20: >> Some claim that one should test for None using: >> >> if x is None: > > Which is the correct and safe way of doing it. ok >> ..but the standard equality which is theoretically safer works as well: >> >> if x == None: > > Absolutely not safe, think of > > class Test(object): > def __eq__(self, other): > return other == None > > print Test() == None, Test() is None Err, I don't want to sound daft, but what is wrong in this example? It should work as expected: >>> class Test(object): ... def __eq__(self, other): ... return other == None ... >>> Test() is None False >>> Test() == None True My interpretation of 1st call is that it is correct: instance Test() is not None (in terms of identity), but it happens to have value equal to None (2nd call). Or perhaps your example was supposed to show that I should test for identity with None, not for value with None? That, however, opens a can of worms, sort of: whether one should compare Test() for identity with None or for value with None depends on what programmer meant at the moment. Regards, mk From jim.hefferon at gmail.com Fri Nov 6 09:48:52 2009 From: jim.hefferon at gmail.com (Jim) Date: Fri, 6 Nov 2009 06:48:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Nov 6, 9:15 am, lee wrote: > can anyone point wer am erroring. I'm not sure what you are trying to do, but it is odd, isn't it, that you never refer to brain in the "for brain in brains:" loop? I think you are mixing i and brain somehow. Jim From fetchinson at googlemail.com Fri Nov 6 09:51:56 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 6 Nov 2009 15:51:56 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? It depends on what you want to do. There is no single answer to your question, until you tell us what your context is. The None object in python is a singleton. If you want to check whether a given object is this singleton None object (note that this is unambiguous, it either occupies the same address in memory as the singleton None or it doesn't) then you should use 'x is None'. If, however you want to test for equality, you should use 'x == None'. An object 'x' may implement equality checks in a funny way and it may be that 'x == None' is True although 'x is None' is False. But it may be that this is exactly what you want, because the author of the object 'x' intentionally has written the equality check code to make this so. In this case you need 'x == None'. So unless you tell us in what context you are asking this question, there is no single answer to it. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mah at spam.la Fri Nov 6 09:52:18 2009 From: mah at spam.la (Marco Bazzani) Date: Fri, 06 Nov 2009 15:52:18 +0100 Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: On Tue, 03 Nov 2009 16:58:16 +0100, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > blank page ? -- reply at: echo "nntp at marcobazzani dot name" |sed s/\ at\ /@/ |sed s/\ dot\ /./ From brian.curtin at gmail.com Fri Nov 6 09:56:28 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Fri, 6 Nov 2009 08:56:28 -0600 Subject: newbie question - python lists In-Reply-To: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, Nov 6, 2009 at 08:15, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. > Your call to items.append(row) passes row by reference. You added a row dictionary with key "itemnos" set to value "item_01s" the first time through the loop. The second time, you added a row dictionary with key "itemnos" set to value "item_02s". This modified the underlying `row` dictionary, so it also modified what you thought you put in the list in the first time through the loop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.weismueller at gmail.com Fri Nov 6 09:56:45 2009 From: jonas.weismueller at gmail.com (Jonas) Date: Fri, 6 Nov 2009 06:56:45 -0800 (PST) Subject: Securing a multiprocessing.BaseManager connection via SSL Message-ID: Hi, how can I secure the communication between two BaseManager objects? Regarding the socket/SSL documentation I just need to secure the socket by SSL. How can i get the socket object within the multiprocessing module? Best regards, Jonas From brian.curtin at gmail.com Fri Nov 6 10:04:28 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Fri, 6 Nov 2009 09:04:28 -0600 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: On Fri, Nov 6, 2009 at 06:12, kj wrote: > > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > my @arr; > $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > my @arr; > $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > Traceback (most recent call last): > File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn > Is there a reason you need to pre-allocate the list other than the fact that you do it that way in Perl? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Fri Nov 6 10:07:23 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 06 Nov 2009 10:07:23 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <4AF43BAB.5000201@codebykevin.com> On 11/3/09 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > I noticed information on py2app was mostly missing from your chart. --single exe file: yes, with qualification. On the Mac, standalone applications are actually directories called "application bundles" designed to look like a single file that can be double-clicked on. So, a lot of stuff--the Python libraries, icons, other resource files--are hidden inside the app bundle. --without unzipping at runtime--Yes. --control over output directory structure--no. --creates installer too: yes, with qualification. If you're building an app, you don't use an installer--the standard Mac method is drag-and-drop installation. You can also use py2app to package up Python libraries, and for these, it can create a standard Mac pkg installer. --Python 3--not yet, as far as I know. --can run as -O--not sure. --control over process/ouput--not sure what this means. --distribution size--Varies widely. A big Python application with lots of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with no other extensions would weigh in at about 20 megabytes--that's the smallest. --active development--some, but only in svn. Last stable release was a few years ago. --active mailing list--no standalone mailing list, but the PythonMac-sig mailing list has lots of discussion and bug reporting on py2app. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From andreengels at gmail.com Fri Nov 6 10:12:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 6 Nov 2009 16:12:59 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: <6faf39c90911060712s6e410168k726b95d84bcf1d8b@mail.gmail.com> On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: > > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ?my @arr; > ?$arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ?my @arr; > ?$#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > >>>> arr = list() >>>> arr[999] = 42 > Traceback (most recent call last): > ?File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? It depends - what do you want to do with it? My first hunch would be to use a dictionary instead of a list, then the whole problem disappears. If there is a reason you don't want to do that, what is it? -- Andr? Engels, andreengels at gmail.com From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 6 10:15:11 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 06 Nov 2009 16:15:11 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <4af43d73$0$11898$426a74cc@news.free.fr> Chris Rebert a ?crit : > On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day wrote: > >> um ... ok, i'll take your word for it, but is there at least a >> generalizable pattern for what is directly help()able and what isn't? > > Language keywords aren't help()-able: > http://docs.python.org/reference/lexical_analysis.html#keywords > Neither are punctuation/operators (see other sections on same webpage). Ever tried help("import") or help("if") or help("+") ? From alfps at start.no Fri Nov 6 10:16:54 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 16:16:54 +0100 Subject: is None or == None ? In-Reply-To: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * John Machin: > On Nov 7, 12:35 am, "Alf P. Steinbach" wrote: >> * mk: >> >>> Hello, >>> Some claim that one should test for None using: >>> if x is None: >>> ..but the standard equality which is theoretically safer works as well: >>> if x == None: >>> So, which one is recommended? >> >> As I understand it, 'is' will always work and will always be efficient (it just >> checks the variable's type), > > It doesn't check the type. > It doesn't need to. (x is y) is true if x > and y are the same object. If that is so, then of course (type(x) is > type(y)) is true, and if not so, their types are irrelevant. "is" > testing is very efficient in the CPython implementation: addressof(x) > == addressof(y) Maybe. I imagined it wouldn't waste additional space for e.g. (Python 2.x) int values, but just use the same space as used for pointer in the case of e.g. string, in which case it would have to check the type -- an integer can very easily have the same bitpattern as a pointer residing there. If you imagine that instead, for an integer variable x it stores the integer value in the variable in some other place than ordinarily used for pointer, and let the pointer point to that place in the same variable, then without checking type the 'is' operator should report false for 'x = 3; y = 3; x is y', but it doesn't with my Python installation, so if it doesn't check the type then even this half-measure (just somewhat wasteful of space) optimization isn't there. In short, you're saying that there is an extreme inefficiency with every integer dynamically allocated /plus/, upon production of an integer by e.g. + or *, inefficiently finding the previously allocated integer of that value and pointing there, sort of piling inefficiency on top of inefficiency, which is absurd but I have seen absurd things before so it's not completely unbelievable. I hope someone else can comment on these implications of your statement. Cheers, - Alf From joncle at googlemail.com Fri Nov 6 10:17:24 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 07:17:24 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <54adc2ba-d4f7-4d70-97cb-fcc474b005ab@t2g2000yqn.googlegroups.com> On Nov 6, 2:15?pm, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > ? ? brains = ['1','2'] > > ? ? if brains: > ? ? ? ? for brain in brains: > ? ? ? ? ? ? # this loop must run only once for each value of i > ? ? ? ? ? ? row['itemnos'] = 'item_0'+str(i)+'s' > ? ? ? ? ? ? print 'hi' > ? ? ? ? ? ? items.append(row) > ? ? ? ? ? ? print items > ? ? ? ? ? ? break > ? ? i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. You've made a good effort (and discovered at least one major common gotcha). There's lots in your code that needs highlighting. However, probably a good starting point would to be describe in plain english, what you're trying to achieve; Are you really sure you want a list of single item dict's? Jon. From rpjday at crashcourse.ca Fri Nov 6 10:31:17 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 10:31:17 -0500 (EST) Subject: newbie question - python lists In-Reply-To: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, 6 Nov 2009, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 for what it's worth, that statement above isn't even legal python3. > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From jjposner at optimum.net Fri Nov 6 10:44:38 2009 From: jjposner at optimum.net (John Posner) Date: Fri, 06 Nov 2009 10:44:38 -0500 Subject: list to table In-Reply-To: References: Message-ID: <4AF44466.4040200@optimum.net> Gabriel Genellina said: > >> Another reason was that ?6.2 does explicitly discuss attribute >> references as targets, but not subscription as target. It would have >> been more clear to me if all (four?) possible target forms were >> discussed. Happily you did now discuss that in the part that I >> snipped above, but would've been nice, and easier for for an >> other-language-thinking person :-), if it was in documentation. > > Yes, probably that section should be improved (except the final > example added, the text hasn't changed since it was first written, > more than 9 years ago). > FWIW ... following on a discussion in this forum in March of this year [1], I submitted issue #5621 at bugs.python.org, along with a proposed rewording of the documentation of this case: self.x = self.x + 1 I did *not* address the case in which the target is a subscription -- it wasn't the focus of the forum discussion. IMHO, the subscription case is much less subject to misunderstanding than the instance-attribute-vs-class-attribute case. My change was accepted (with some rearrangements made by Georg Brandl), but has not yet been included in any Py2 or Py3 release, AFAIK. -John [1] http://mail.python.org/pipermail/python-list/2009-March/175054.html From marco at sferacarta.com Fri Nov 6 10:51:18 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 06 Nov 2009 16:51:18 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > If you imagine that instead, for an integer variable x it stores the > integer value in the variable in some other place than ordinarily used > for pointer, and let the pointer point to that place in the same > variable, then without checking type the 'is' operator should report > false for 'x = 3; y = 3; x is y', but it doesn't with my Python Yes, CPython caches a handful of small, "commonly used" integers, and creates objects for them upon startup. Using "x is y" with integers makes no sense and has no guaranteed behaviour AFAIK > In short, you're saying that there is an extreme inefficiency with every > integer dynamically allocated /plus/, upon production of an integer by > e.g. + or *, inefficiently finding the previously allocated integer of > that value and pointing there, no, it doesn't "point there": >>>> a=1E6 >>>> a is 1E6 > False >>>> a=100 >>>> a is 100 > True From jjkk73 at gmail.com Fri Nov 6 11:04:37 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 6 Nov 2009 16:04:37 +0000 Subject: Defining re pattern for matching list of numbers Message-ID: Hi, I'm trying to write a re pattern to match a list of one or more numbers, each number is in the range of 1-15 value and the numbers are separated by spaces (but there are no spaces at the beginning and end of the string). For instance: "3" "1 14 8" but not: "22" " 5 11" I've come up with something like this re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") but I can't believe this has to be so complicated. Does anyone know some simpler re pattern to match this kind of string Many thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Fri Nov 6 11:16:58 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 6 Nov 2009 10:16:58 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <7li76qF3cq9l0U1@mid.uni-berlin.de> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> Message-ID: <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: > Peng Yu schrieb: >> >> Suppose I have a list of strings, A. I want to compute the list (call >> it B) of strings that are elements of A but doesn't match a regex. I >> could use a for loop to do so. In a functional language, there is way >> to do so without using the for loop. > > Nonsense. For processing over each element, you have to loop over them, > either with or without growing a call-stack at the same time. > > FP languages can optimize away the stack-frame-growth (tail recursion) - but > this isn't reducing complexity in any way. > > So use a loop, either directly, or using a list-comprehension. What is a list-comprehension? I tried the following code. The list 'l' will be ['a','b','c'] rather than ['b','c'], which is what I want. It seems 'remove' will disrupt the iterator, right? I am wondering how to make the code correct. l = ['a', 'a', 'b', 'c'] for x in l: if x == 'a': l.remove(x) print l From rpjday at crashcourse.ca Fri Nov 6 11:42:45 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 11:42:45 -0500 (EST) Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Peng Yu wrote: > On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: > > Peng Yu schrieb: > >> > >> Suppose I have a list of strings, A. I want to compute the list (call > >> it B) of strings that are elements of A but doesn't match a regex. I > >> could use a for loop to do so. In a functional language, there is way > >> to do so without using the for loop. > > > > Nonsense. For processing over each element, you have to loop over them, > > either with or without growing a call-stack at the same time. > > > > FP languages can optimize away the stack-frame-growth (tail recursion) - but > > this isn't reducing complexity in any way. > > > > So use a loop, either directly, or using a list-comprehension. > > What is a list-comprehension? > > I tried the following code. The list 'l' will be ['a','b','c'] rather > than ['b','c'], which is what I want. It seems 'remove' will disrupt > the iterator, right? I am wondering how to make the code correct. > > l = ['a', 'a', 'b', 'c'] > for x in l: > if x == 'a': > l.remove(x) > > print l list comprehension seems to be what you want: l = [i for i in l if i != 'a'] rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From san82moon at gmail.com Fri Nov 6 11:47:33 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:47:33 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From san82moon at gmail.com Fri Nov 6 11:49:52 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:49:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From info at egenix.com Fri Nov 6 11:51:18 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 06 Nov 2009 17:51:18 +0100 Subject: ANN: eGenix mxODBC - Python ODBC Database Interface 3.0.4 Message-ID: <4AF45406.3040407@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - Python ODBC Database Interface Version 3.0.4 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.0.4-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS mxODBC 3.0.4 is a patch-level release and includes the following updates: * Fixed Mac OS X Intel builds: The Mac OS X builds for 3.0.3 had a problem finding the installed iODBC administrator libraries on Intel Macs. This problem has now been resolved. Note: If you are having trouble finding the ODBC administrator on Mac OS X 10.6 (Snow Leopard), this is because the initial release of 10.6 did not include the administrator GUI. You can download the update with the ODBC administrator from the Apple support site: http://support.apple.com/downloads/ODBC_Administrator_Tool_for_Mac_OS_X Since mxODBC for Mac OS X is currently only available for 32-bit PPC and Intel platforms, be sure to use the Python.org 32-bit Mac OS X installer for installing Python and 32-bit ODBC drivers on Snow Leopard. * Enhanced support detecting platform mismatches: We have added better support for detecting mismatches between the downloaded prebuilt archive and the installation target configuration to the prebuilt archive installers. The setup.py script now prints an error message explaining the mismatch rather then trying to rebuild the extension. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC release, especially if you are using MS SQL Server or Informix as database server. Customers who have purchased mxODBC 3.0 licenses can download and install this patch-level release on top of their existing installations. The licenses will continue to work with version 3.0.4. Users of mxODBC 1.0 and 2.0 will have to purchase new licenses from our online shop in order to upgrade to mxODBC 3.0.4. You can request 30-day evaluation licenses by visiting our web-site at http://www.egenix.com/products/python/mxODBC/#Evaluation or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 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 alfps at start.no Fri Nov 6 11:54:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 17:54:53 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Marco Mariani: > Alf P. Steinbach wrote: > >> If you imagine that instead, for an integer variable x it stores the >> integer value in the variable in some other place than ordinarily used >> for pointer, and let the pointer point to that place in the same >> variable, then without checking type the 'is' operator should report >> false for 'x = 3; y = 3; x is y', but it doesn't with my Python > > Yes, CPython caches a handful of small, "commonly used" integers, and > creates objects for them upon startup. Using "x is y" with integers > makes no sense and has no guaranteed behaviour AFAIK > >> In short, you're saying that there is an extreme inefficiency with >> every integer dynamically allocated /plus/, upon production of an >> integer by e.g. + or *, inefficiently finding the previously allocated >> integer of that value and pointing there, > > no, it doesn't "point there": > >>>>> a=1E6 >>>>> a is 1E6 >> False >>>>> a=100 >>>>> a is 100 >> True I stand corrected on that issue, I didn't think of cache for small values. On my CPython 3.1.1 the cache seems to support integer values -5 to +256, inclusive, apparently using 16 bytes of storage per value (this last assuming id() just returns the address). But wow. That's pretty hare-brained: dynamic allocation for every stored value outside the cache range, needless extra indirection for every operation. Even Microsoft COM managed to get this right. On the positive side, except that it would probably break every C module (I don't know), in consultant speak that's definitely a potential for improvement. :-p Cheers, - Alf From san82moon at gmail.com Fri Nov 6 11:56:34 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:56:34 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <33ef111d-fa99-4788-8bda-631819929d03@g1g2000pra.googlegroups.com> On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From pengyu.ut at gmail.com Fri Nov 6 11:58:13 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 6 Nov 2009 10:58:13 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Peng Yu wrote: > >> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >> > Peng Yu schrieb: >> >> >> >> Suppose I have a list of strings, A. I want to compute the list (call >> >> it B) of strings that are elements of A but doesn't match a regex. I >> >> could use a for loop to do so. In a functional language, there is way >> >> to do so without using the for loop. >> > >> > Nonsense. For processing over each element, you have to loop over them, >> > either with or without growing a call-stack at the same time. >> > >> > FP languages can optimize away the stack-frame-growth (tail recursion) - but >> > this isn't reducing complexity in any way. >> > >> > So use a loop, either directly, or using a list-comprehension. >> >> What is a list-comprehension? >> >> I tried the following code. The list 'l' will be ['a','b','c'] rather >> than ['b','c'], which is what I want. It seems 'remove' will disrupt >> the iterator, right? I am wondering how to make the code correct. >> >> l = ['a', 'a', 'b', 'c'] >> for x in l: >> ? if x == 'a': >> ? ? l.remove(x) >> >> print l > > ?list comprehension seems to be what you want: > > ?l = [i for i in l if i != 'a'] My problem comes from the context of using os.walk(). Please see the description of the following webpage. Somehow I have to modify the list inplace. I have already tried 'dirs = [i for i in l if dirs != 'a']'. But it seems that it doesn't "prune the search". So I need the inplace modification of list. http://docs.python.org/library/os.html When topdown is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again. Modifying dirnames when topdown is False is ineffective, because in bottom-up mode the directories in dirnames are generated before dirpath itself is generated. From emily at nospam.com Fri Nov 6 12:00:30 2009 From: emily at nospam.com (Emily Rodgers) Date: Fri, 6 Nov 2009 17:00:30 -0000 Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: "lee" wrote in message news:8d1009a4-54c8-4bb3-9862-8b22e6b42a3b at y10g2000prg.googlegroups.com... > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. Hi, As some others have pointed out, it is not totally clear from your code what you are trying to do, but I will forgive you for that because you are clearly not used to python! I think what you are trying to do is: items = [] rfids= ['01','02'] for rfid in rfids: items.append({'itemnos': 'item_%ss' % rfid}) print items This can also be done using a list comprehension which is one of the (many) most useful features of python (imo): rfids= ['01','02'] print [{'itemnos': 'item_%ss' % rfid} for rfid in rfids] Or on one line (although it is always to be clearer rather trying to fit stuff into one line - it is not perl!) print [{'itemnos': 'item_%ss' % rfid} for rfid in ['01', '02']] Hope this helps. Emily From rami.chowdhury at gmail.com Fri Nov 6 12:04:18 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:04:18 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach wrote: > But wow. That's pretty hare-brained: dynamic allocation for every stored > value outside the cache range, needless extra indirection for every > operation. > Perhaps I'm not understanding this thread at all but how is dynamic allocation hare-brained, and what's the 'needless extra indirection'? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From __peter__ at web.de Fri Nov 6 12:05:11 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2009 18:05:11 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: Peng Yu wrote: > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs = [i for i in l if dirs != > 'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. Use dirs[:] = [d for d in dirs if d != "a"] or try: dirs.remove("a") except ValueError: pass From rpjday at crashcourse.ca Fri Nov 6 12:05:17 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 12:05:17 -0500 (EST) Subject: newbie question - python lists In-Reply-To: References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, 6 Nov 2009, lee wrote: > brains = ['1','2'] > for brain in brains: > row['item'] = brain > items.append(row) > print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . this seems to work: items = [] brains = ['1','2','3','4'] for brain in brains: items.append({'item':brain}) print(items) >>> import t1 [{'item': '1'}] [{'item': '1'}, {'item': '2'}] [{'item': '1'}, {'item': '2'}, {'item': '3'}] [{'item': '1'}, {'item': '2'}, {'item': '3'}, {'item': '4'}] rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From benjamin.kaplan at case.edu Fri Nov 6 12:07:17 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 6 Nov 2009 12:07:17 -0500 Subject: newbie question - python lists In-Reply-To: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> Message-ID: On Fri, Nov 6, 2009 at 11:49 AM, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: >> On Nov 6, 9:15 am, lee wrote: >> >> > can anyone point wer am erroring. >> >> I'm not sure what you are trying to do, but it is odd, isn't it, that >> you never refer to brain in the "for brain in brains:" loop? ?I think >> you are mixing i and brain somehow. >> >> Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > ? ?row['item'] = brain > ? ?items.append(row) > ? ?print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . > > Thanks > Lee. With Python, you're always dealing with objects, not with values. It isn't apparent with immutable objects like strings and ints, but here's what's actually happening. At the end, your list is [row, row]. It's the exact same dictionary. The value wasn't copied in. Try this row = {} row['item'] = 1 items = [row] row['item'] = 2 print row You get the same thing- you're changing the dict that's already in items. In order to get two different elements, you have to use 2 different dicts. if brains: for brain in brains: # this loop must run only once for each value of i row = { 'itemnos': 'item_0'+str(i)+'s'} print 'hi' items.append(row) print items break i=i+1 > -- > http://mail.python.org/mailman/listinfo/python-list > From rami.chowdhury at gmail.com Fri Nov 6 12:12:32 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:12:32 -0800 Subject: newbie question - python lists In-Reply-To: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 08:49:52 -0800, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: >> On Nov 6, 9:15 am, lee wrote: >> >> > can anyone point wer am erroring. >> >> I'm not sure what you are trying to do, but it is odd, isn't it, that >> you never refer to brain in the "for brain in brains:" loop? ?I think >> you are mixing i and brain somehow. >> >> Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > row['item'] = brain > items.append(row) > print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > Lee, When you do > row['item'] = brain you are actually modifying the existing dictionary object called 'row' -- and I get the impression this is not what you want to do. I'd suggest creating a new dictionary on each pass, which should give you the desired behavior. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From flashk at gmail.com Fri Nov 6 12:12:57 2009 From: flashk at gmail.com (Farshid) Date: Fri, 6 Nov 2009 09:12:57 -0800 (PST) Subject: 2to3 ParseError with UTF-8 BOM References: Message-ID: <50ad856e-8118-4374-82a4-58243ae3434b@13g2000prl.googlegroups.com> On Nov 5, 7:18?pm, Benjamin Peterson wrote: > Try the 2to3 distributed in Python 3.1. I get the same error with the 2to3 script in Python 3.1 -farshid From san82moon at gmail.com Fri Nov 6 12:19:00 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 09:19:00 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> On Nov 6, 9:47?pm, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: > > > On Nov 6, 9:15 am, lee wrote: > > > > can anyone point wer am erroring. > > > I'm not sure what you are trying to do, but it is odd, isn't it, that > > you never refer to brain in the "for brain in brains:" loop? ?I think > > you are mixing i and brain somehow. > > > Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > ? ? row['item'] = brain > ? ? items.append(row) > ? ? print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . > > Thanks > Lee. i got it solved , items = [] for brain in brains: dict = {'itemnos': 'item_0' + brain + 's'} items.append(dict) print(items) thanks all. Lee. From python at rcn.com Fri Nov 6 12:21:55 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 Nov 2009 09:21:55 -0800 (PST) Subject: is None or == None ? References: Message-ID: <0bd9e58f-12dd-4ead-9401-1a38b0aa4bea@y32g2000prd.googlegroups.com> On Nov 6, 5:20?am, mk wrote: > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? In the standard library, we use "x is None". The official recommendation in PEP 8 reads: ''' Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Also, beware of writing "if x" when you really mean "if x is not None" -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context! ''' Raymond From hniksic at xemacs.org Fri Nov 6 12:22:40 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 06 Nov 2009 18:22:40 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <87r5sbh8kf.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > But wow. That's pretty hare-brained: dynamic allocation for every > stored value outside the cache range, needless extra indirection for > every operation. > > Even Microsoft COM managed to get this right. > > On the positive side, except that it would probably break every C > module (I don't know), in consultant speak that's definitely a > potential for improvement. :-p Tagged integers have been tried, shown not really worth it, and ultimately rejected by the BDFL: http://mail.python.org/pipermail/python-dev/2004-July/thread.html#46139 From alfps at start.no Fri Nov 6 12:28:08 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 18:28:08 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Rami Chowdhury: > On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach > wrote: > >> But wow. That's pretty hare-brained: dynamic allocation for every >> stored value outside the cache range, needless extra indirection for >> every operation. >> > > Perhaps I'm not understanding this thread at all but how is dynamic > allocation hare-brained, and what's the 'needless extra indirection'? Dynamic allocation isn't hare-brained, but doing it for every stored integer value outside a very small range is, because dynamic allocation is (relatively speaking, in the context of integer operations) very costly even with a (relatively speaking, in the context of general dynamic allocation) very efficient small-objects allocator - here talking order(s) of magnitude. A typical scheme for representing dynamically typed objects goes like, in C++, enum TypeId { int_type_id, dyn_object_type_id }; struct Object { int type_id; union { void* p; int i; // Perhaps other special cased type's values in this union. }; }; This would then be the memory layout of what's regarded as a variable at the script language level. Then getting the integer value reduces to int intValueOf( Object const& o ) { if( o.type_id != int_type_id ) { throw TypeError(); } return o.i; } If on the other hand int (and perhaps floating point type, whatever) isn't special-cased, then it goes like int intValueOf( Object const& o ) { if( o.type_id != int_type_id ) { throw TypeError(); } return static_cast( o.p )->value; // Extra indirection } and depending on where the basic type id is stored it may be more extra indirection, and worse, creating that value then involves a dynamic allocation. Cheers & hth. - Alf From patrol at invisibleroads.com Fri Nov 6 12:33:16 2009 From: patrol at invisibleroads.com (Roy Hyunjin Han) Date: Fri, 06 Nov 2009 12:33:16 -0500 Subject: Cpython optimization In-Reply-To: References: Message-ID: <4AF45DDC.4080408@invisibleroads.com> On 10/21/2009 01:28 PM, Qrees wrote: > As my Master's dissertation I chose Cpython optimization. That's why > i'd like to ask what are your suggestions what can be optimized. Well, > I know that quite a lot. I've downloaded the source code (I plan to > work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at > the code I've found comment's like "this can be optimized by..." etc. > but maybe you guide me what should I concentrate on in my work? > > I've 6-7 month for this and If I create something decent I can > publish it. > Hi Qrees, Have you heard of the Unladen Swallow project? It is an optimization branch of CPython. Perhaps you can talk to some of the people working on the project. http://code.google.com/p/unladen-swallow/ RHH -- Get customized Python tutorials and live instruction for your business, research or programming problem Tuesday November 17 2009 6:30pm ? 10pm NYC Seminar and Conference Center (71 W 23rd St @ 6th Ave, New York, NY) 11/12 slots available for $30 each http://invisibleroads.com From python at mrabarnett.plus.com Fri Nov 6 12:33:54 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Nov 2009 17:33:54 +0000 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> Message-ID: <4AF45E02.50304@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: >> On Fri, 6 Nov 2009, Peng Yu wrote: >> >>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >>>> Peng Yu schrieb: >>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>> could use a for loop to do so. In a functional language, there is way >>>>> to do so without using the for loop. >>>> Nonsense. For processing over each element, you have to loop over them, >>>> either with or without growing a call-stack at the same time. >>>> >>>> FP languages can optimize away the stack-frame-growth (tail recursion) - but >>>> this isn't reducing complexity in any way. >>>> >>>> So use a loop, either directly, or using a list-comprehension. >>> What is a list-comprehension? >>> >>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>> the iterator, right? I am wondering how to make the code correct. >>> >>> l = ['a', 'a', 'b', 'c'] >>> for x in l: >>> if x == 'a': >>> l.remove(x) >>> >>> print l >> list comprehension seems to be what you want: >> >> l = [i for i in l if i != 'a'] > > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs = [i for i in l if dirs != > 'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. > [snip] You can replace the contents of a list like this: l[:] = [i for i in l if i != 'a'] From python at rcn.com Fri Nov 6 12:39:09 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 Nov 2009 09:39:09 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: [kj] > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? Yes. Raymond From damienlmoore at gmail.com Fri Nov 6 12:44:49 2009 From: damienlmoore at gmail.com (dmoore) Date: Fri, 6 Nov 2009 09:44:49 -0800 (PST) Subject: Need help dumping exif data in canon raw files References: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> <7xd43w1rjt.fsf@ruckus.brouhaha.com> Message-ID: <5fc08548-b164-4f63-9f01-10936e01d322@37g2000yqm.googlegroups.com> On Nov 5, 6:27?pm, Paul Rubin wrote: > Nuff Nuff writes: > > I just need to be able to extract the exif info from a canon CR2 > > file. ?The info from canon suggest that it's just the same as a tiff, > > but anytime I try to get PIL to open one, ?it says that it tastes > > bad. ?And canon don't seem to be all that forthcoming on the details. > >CR2 is a hardware-specific raw format and PIL should not be expected >to understand it. Try a websearch for dcraw.c to find a decoder for it. also check out pyexiv2 (a python binding of exiv2), available in many linux distros: http://tilloy.net/dev/pyexiv2/index.htm the current version of pyexiv2 doesn't yet support XMP metadata (the underlying exiv2 lib does) but should be able to read Exif and IPTC data ok. Looking at http://dev.exiv2.org/wiki/exiv2/Supported_image_formats you may be SOL for writing to CR2. You can also try calling exiftool from your python script: http://www.sno.phy.queensu.ca/~phil/exiftool/ From rami.chowdhury at gmail.com Fri Nov 6 12:47:37 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:47:37 -0800 Subject: newbie question - python lists In-Reply-To: <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 09:19:00 -0800, lee wrote: > On Nov 6, 9:47?pm, lee wrote: >> On Nov 6, 7:48?pm, Jim wrote: >> >> > On Nov 6, 9:15 am, lee wrote: >> >> > > can anyone point wer am erroring. >> >> > I'm not sure what you are trying to do, but it is odd, isn't it, that >> > you never refer to brain in the "for brain in brains:" loop? ?I think >> > you are mixing i and brain somehow. >> >> > Jim >> >> ok let me make it clear, >> >> brains = ['1','2'] >> for brain in brains: >> ? ? row['item'] = brain >> ? ? items.append(row) >> ? ? print items >> >> This produces >> [{'item': '1'}] >> [{'item': '2'}, {'item': '2'}] >> but i want >> [{'item': '1'}] >> [{'item': '1'}, {'item': '2'}] >> >> if i do items.append(brain), it gives, >> ['1', '2'] >> but i want dictionary inside list. >> @Jon - Yes i want single item dict's >> @Robert - i use python 2.4 . >> >> Thanks >> Lee. > > i got it solved , > > items = [] > for brain in brains: > dict = {'itemnos': 'item_0' + brain + 's'} > items.append(dict) > print(items) > Glad to see you solved it! A couple of minor considerations: - I would suggest you use a variable name other than 'dict', as that shadows the built-in 'dict' type - I would suggest using the idiom 'item_0%ss' % brain rather than 'item_0' + brain + 's', in case at some point you want to change the type of 'brain' -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From san82moon at gmail.com Fri Nov 6 13:01:52 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 10:01:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> Message-ID: <5b6ff9ff-ba71-47ed-88e3-bba13361582b@x25g2000prf.googlegroups.com> On Nov 6, 10:47?pm, "Rami Chowdhury" wrote: > On Fri, 06 Nov 2009 09:19:00 -0800, lee wrote: > > On Nov 6, 9:47?pm, lee wrote: > >> On Nov 6, 7:48?pm, Jim wrote: > > >> > On Nov 6, 9:15 am, lee wrote: > > >> > > can anyone point wer am erroring. > > >> > I'm not sure what you are trying to do, but it is odd, isn't it, that > >> > you never refer to brain in the "for brain in brains:" loop? ?I think > >> > you are mixing i and brain somehow. > > >> > Jim > > >> ok let me make it clear, > > >> brains = ['1','2'] > >> for brain in brains: > >> ? ? row['item'] = brain > >> ? ? items.append(row) > >> ? ? print items > > >> This produces > >> [{'item': '1'}] > >> [{'item': '2'}, {'item': '2'}] > >> but i want > >> [{'item': '1'}] > >> [{'item': '1'}, {'item': '2'}] > > >> if i do items.append(brain), it gives, > >> ['1', '2'] > >> but i want dictionary inside list. > >> @Jon - Yes i want single item dict's > >> @Robert - i use python 2.4 . > > >> Thanks > >> Lee. > > > i got it solved , > > > items = [] > > for brain in brains: > > ? ? ? ?dict = {'itemnos': 'item_0' + brain + 's'} > > ? ? ? ?items.append(dict) > > print(items) > > Glad to see you solved it! A couple of minor considerations: > ? ? ? ? - I would suggest you use a variable name other than 'dict', as that ? > shadows the built-in 'dict' type > ? ? ? ? - I would suggest using the idiom 'item_0%ss' % brain rather than ? > 'item_0' + brain + 's', in case at some point you want to change the type ? > of 'brain' > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- ? > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) i greatly value your suggestion. i have made changes as indicted by you. The code looks more clean now. Thank you, Lee. From clp2 at rebertia.com Fri Nov 6 13:04:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 10:04:21 -0800 Subject: why does "help(import)" not work? In-Reply-To: <4af43d73$0$11898$426a74cc@news.free.fr> References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> <4af43d73$0$11898$426a74cc@news.free.fr> Message-ID: <50697b2c0911061004l5b8cf6fdoa5c2a373535949b7@mail.gmail.com> On Fri, Nov 6, 2009 at 7:15 AM, Bruno Desthuilliers wrote: > Chris Rebert a ?crit : >> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day >> wrote: >>> ?um ... ok, i'll take your word for it, but is there at least a >>> generalizable pattern for what is directly help()able and what isn't? >> >> Language keywords aren't help()-able: >> http://docs.python.org/reference/lexical_analysis.html#keywords >> Neither are punctuation/operators (see other sections on same webpage). > > Ever tried help("import") or help("if") or help("+") ? help()-able in this context meaning you can drop the quotes and not get a syntax error. Cheers, Chris -- http://blog.rebertia.com From emily at nospam.com Fri Nov 6 13:11:47 2009 From: emily at nospam.com (Emily Rodgers) Date: Fri, 6 Nov 2009 18:11:47 -0000 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: "Andre Engels" wrote in message news:mailman.2696.1257520404.2807.python-list at python.org... >On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: [snip] >> arr = [None] * 1000000 >> >> Is this the most efficient way to achieve this result? > > It depends - what do you want to do with it? My first hunch would be > to use a dictionary instead of a list, then the whole problem > disappears. If there is a reason you don't want to do that, what is > it? > > -- > Andr? Engels, andreengels at gmail.com I second this. It might seem a sensible thing to do in perl, but I can't imagine what you would actually want to do it for! Seems like an odd thing to want to do! From VerweijA at tass-safe.com Fri Nov 6 13:15:41 2009 From: VerweijA at tass-safe.com (Verweij, Arjen) Date: Fri, 6 Nov 2009 19:15:41 +0100 Subject: safely returning objects from a Process to the parent through a Queue() Message-ID: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> Hi, I'm trying to parallelize a loop using Process and Queue. My code looks similar to the example in http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.managers It looks like this: def pp(q, t, s, a, h, p): doStuff() c.generate() q.put(c, True) #stuff a in a queue main: for a in aa: processes = [] q = Queue() for b in bb: try: if bla > 24: print "too old" continue except: print "etc" + t #file not found pass try: p = Process(target=pp, args=(q, t, s, a, h, p,)) #trailing comma, do not touch m'kay p.start() processes.append(p) #end for b in bb for p in processes: # p.join() # this deadlocks in combination with the Queue() at some point ss = q.get() bigcontainer.add(ss) bigcontainer.generate() world.add(bigcontainer) #end for a in aa world.generate() So I have some XML, that requires translation into HTML. I take a sublist, traverse it, spawn a process for every XML file in that list and generate HTML inside that process. Then I would very much like to have the results back in the original main() so it can be used. Is there a way to guarantee that the a in aa loop will not start the next loop? In other words, I'm worried that q will be depleted due to some unknown factor while a subprocess from b in bb still has to write to the Queue() and it will continue somehow leaking/destroying data. Before I found the example in the webpage that pointed out the deadlock I couldn't get the program to finish, but finishing without all the data would be equally bad. Thanks, Arjen Arjen Verweij QA/Test Engineer Schoemakerstraat 97 2628 VK? Delft The Netherlands Phone:??+31?88?827 7086 Fax:???????+31?88 827? 7003 Email:??arjen.verweij at tass-safe.com www.tass-safe.com This e-mail and its contents are subject to a DISCLAIMER with important RESERVATIONS. From clp2 at rebertia.com Fri Nov 6 13:16:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 10:16:31 -0800 Subject: Defining re pattern for matching list of numbers In-Reply-To: References: Message-ID: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> On Fri, Nov 6, 2009 at 8:04 AM, jorma kala wrote: > Hi, > I'm trying to write a re pattern to match a list of one or more numbers, > each number is in the range of 1-15 value and the numbers are separated by > spaces (but?there are no?spaces at the beginning and end of the string). For > instance: > > "3" > "1 14 8" > > but not: > > "22" > " 5 11" > > I've come up with something like this > > re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") > > but I can't believe this has to be so complicated. Your format seems so simple I have to ask why you're using regexes in the first place. try: nums = [int(num) for num in line.split(" ")] except ValueError: print "Invalid input" for num in nums: if num < 1 or num > 15: raise ValueError, "Number present which is outside of valid range" Cheers, Chris -- http://blog.rebertia.com From tartley at tartley.com Fri Nov 6 13:30:12 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:30:12 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <54b5ecab-bd7b-4106-9401-785e9813823d@c3g2000yqd.googlegroups.com> Message-ID: <8176e961-7e5b-4f5a-9fd1-53093160a07a@l2g2000yqd.googlegroups.com> On Nov 5, 2:26?pm, Paul Boddie wrote: > On 3 Nov, 16:58, Jonathan Hartley wrote: > > > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > Nice comparison! Perhaps this could join the material on the Wiki > eventually: > > http://wiki.python.org/moin/DistributionUtilities > > If you don't want to spend time marking the table up, I'm sure I could > help you out. > > Paul Nice idea Paul, and thanks for the offer. I'll ping you for guidance at least, as and when I reckon I've got the table into half decent shape. I notice the wiki page you linked to contains a bunch of options and information I wasn't even aware of, so I've probably got some work to do before that happens. Best, Jonathan From tartley at tartley.com Fri Nov 6 13:33:07 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:33:07 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <8bbdf9ae-bd36-4530-bde5-2f15a84561a5@g23g2000yqh.googlegroups.com> On Nov 6, 2:52?pm, "Marco Bazzani" wrote: > On Tue, 03 Nov 2009 16:58:16 +0100, Jonathan Hartley ? > wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > blank page ? > > -- > reply at: > echo "nntp at marcobazzani dot name" |sed s/\ at\ /@/ |sed s/\ dot\ /./ Hey Marco. Thanks for the heads-up. It's suppose to be a link to a shared google docs spreadsheet. At least some other people are able to see it without problems. If you're keen to see it, and it remains non- functional for you, and you're willing to help me try and debug this, then email me off list and maybe we could try some alternative ways of publishing it. Do you happen to know if other google docs spreadsheets work for you? Best, Jonathan From tartley at tartley.com Fri Nov 6 13:33:52 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:33:52 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <4AF43BAB.5000201@codebykevin.com> Message-ID: <899f4709-250c-4623-81ad-84af21008bce@n35g2000yqm.googlegroups.com> On Nov 6, 3:07?pm, Kevin Walzer wrote: > On 11/3/09 10:58 AM, Jonathan Hartley wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > I noticed information on py2app was mostly missing from your chart. > > --single exe file: yes, with qualification. On the Mac, standalone > applications are actually directories called "application bundles" > designed to look like a single file that can be double-clicked on. So, a > lot of stuff--the Python libraries, icons, other resource files--are > hidden inside the app bundle. > > --without unzipping at runtime--Yes. > --control over output directory structure--no. > > --creates installer too: yes, with qualification. If you're building an > app, you don't use an installer--the standard Mac method is > drag-and-drop installation. You can also use py2app to package up Python > libraries, and for these, it can create a standard Mac pkg installer. > > --Python 3--not yet, as far as I know. > --can run as -O--not sure. > --control over process/ouput--not sure what this means. > --distribution size--Varies widely. A big Python application with lots > of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with > no other extensions would weigh in at about 20 megabytes--that's the > smallest. > --active development--some, but only in svn. Last stable release was a > few years ago. > --active mailing list--no standalone mailing list, but the PythonMac-sig > mailing list has lots of discussion and bug reporting on py2app. > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Thanks heaps Kevin - I don't have a Mac, so I was just inferring information about py2app. Although my app does run on Macs and one of my Mac-loving friends has kindly agreed to help me produce Mac binaries, so this information is brilliant to know. Many thanks! Jonathan From tartley at tartley.com Fri Nov 6 13:41:51 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:41:51 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <4AF43BAB.5000201@codebykevin.com> Message-ID: On Nov 6, 3:07?pm, Kevin Walzer wrote: > On 11/3/09 10:58 AM, Jonathan Hartley wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > I noticed information on py2app was mostly missing from your chart. > > --single exe file: yes, with qualification. On the Mac, standalone > applications are actually directories called "application bundles" > designed to look like a single file that can be double-clicked on. So, a > lot of stuff--the Python libraries, icons, other resource files--are > hidden inside the app bundle. > > --without unzipping at runtime--Yes. > --control over output directory structure--no. > > --creates installer too: yes, with qualification. If you're building an > app, you don't use an installer--the standard Mac method is > drag-and-drop installation. You can also use py2app to package up Python > libraries, and for these, it can create a standard Mac pkg installer. > > --Python 3--not yet, as far as I know. > --can run as -O--not sure. > --control over process/ouput--not sure what this means. > --distribution size--Varies widely. A big Python application with lots > of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with > no other extensions would weigh in at about 20 megabytes--that's the > smallest. > --active development--some, but only in svn. Last stable release was a > few years ago. > --active mailing list--no standalone mailing list, but the PythonMac-sig > mailing list has lots of discussion and bug reporting on py2app. > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Kevin, Also: You are right that my 'control over process/output' is not at all clear. I shall think about what actual goal I'm trying to achieve with this, and re-describe it in those terms. Plus, as others have suggested, my guesstimate of 'distribution size' would probably be more usefully described as 'size overhead', ie. how big would the distribution be for a one-line python console 'hello world' script. I hope to try it out and see. Best regards, Jonathan From alfps at start.no Fri Nov 6 13:45:02 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 19:45:02 +0100 Subject: is None or == None ? In-Reply-To: <87r5sbh8kf.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> But wow. That's pretty hare-brained: dynamic allocation for every >> stored value outside the cache range, needless extra indirection for >> every operation. >> >> Even Microsoft COM managed to get this right. >> >> On the positive side, except that it would probably break every C >> module (I don't know), in consultant speak that's definitely a >> potential for improvement. :-p > > Tagged integers have been tried, shown not really worth it, and > ultimately rejected by the BDFL: > > http://mail.python.org/pipermail/python-dev/2004-July/thread.html#46139 Yah, as I suspected. I looked at the first few postings in that thread and it seems an inefficient baroque implementation was created and tested, not realizing more than 50% speedup in a test not particularly much exercising its savings, and against that counts as mentioned in the thread and as I mentioned in quoted material above, breaking lots of existing C code. Speedup would likely be more realistic with normal implementation (not fiddling with bit-fields and stuff) not to mention when removing other inefficiencies that likely dwarf and hide the low-level performance increase, but still I agree wholeheartedly with those who argue compatibility, not breaking code. As long as it Works, don't fix it... ;-) Cheers, (still amazed, though) - Alf From jjkk73 at gmail.com Fri Nov 6 14:12:11 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 6 Nov 2009 20:12:11 +0100 Subject: Defining re pattern for matching list of numbers In-Reply-To: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> References: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> Message-ID: Thanks for your reply. But I need to use a regex; my program deals with a large number of patterns, and I want to treat them in a uniform way (through regex). On 11/6/09, Chris Rebert wrote: > > On Fri, Nov 6, 2009 at 8:04 AM, jorma kala wrote: > > Hi, > > I'm trying to write a re pattern to match a list of one or more numbers, > > each number is in the range of 1-15 value and the numbers are separated > by > > spaces (but there are no spaces at the beginning and end of the string). > For > > instance: > > > > "3" > > "1 14 8" > > > > but not: > > > > "22" > > " 5 11" > > > > I've come up with something like this > > > > re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") > > > > but I can't believe this has to be so complicated. > > > Your format seems so simple I have to ask why you're using regexes in > the first place. > > try: > nums = [int(num) for num in line.split(" ")] > except ValueError: > print "Invalid input" > > for num in nums: > if num < 1 or num > 15: > raise ValueError, "Number present which is outside of valid range" > > Cheers, > Chris > > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Nov 6 14:20:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 6 Nov 2009 11:20:40 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Nov 6, 9:28?am, "Alf P. Steinbach" wrote: > * Rami Chowdhury: > > > On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach > > wrote: > > >> But wow. That's pretty hare-brained: dynamic allocation for every > >> stored value outside the cache range, needless extra indirection for > >> every operation. > > > Perhaps I'm not understanding this thread at all but how is dynamic > > allocation hare-brained, and what's the 'needless extra indirection'? > > Dynamic allocation isn't hare-brained, but doing it for every stored integer > value outside a very small range is, because dynamic allocation is (relatively > speaking, in the context of integer operations) very costly even with a > (relatively speaking, in the context of general dynamic allocation) very > efficient small-objects allocator - here talking order(s) of magnitude. Python made a design trade-off, it chose a simpler implementation and uniform object semantic behavior, at a cost of speed. C# made a different trade-off, choosing a more complex implementation, a language with two starkly different object semantic behaviors, so as to allow better performance. You don't have to like the decision Python made, but I don't think it's fair to call a deliberate design trade-off hare-brained. Carl Banks From rami.chowdhury at gmail.com Fri Nov 6 14:28:15 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 11:28:15 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >> wrote: >> >>> But wow. That's pretty hare-brained: dynamic allocation for every >>> stored value outside the cache range, needless extra indirection for >>> every operation. >>> >> Perhaps I'm not understanding this thread at all but how is dynamic >> allocation hare-brained, and what's the 'needless extra indirection'? > > Dynamic allocation isn't hare-brained, but doing it for every stored > integer value outside a very small range is, because dynamic allocation > is (relatively speaking, in the context of integer operations) very > costly even with a (relatively speaking, in the context of general > dynamic allocation) very efficient small-objects allocator - here > talking order(s) of magnitude. Well, sure, it may seem that way. But how large a cache would you want to preallocate? I can't see the average Python program needing to use the integers from -10000 to 10000, for instance. In my (admittedly limited) experience Python programs typically deal with rather more complex objects than plain integers. > int intValueOf( Object const& o ) > { > if( o.type_id != int_type_id ) { throw TypeError(); } > return static_cast( o.p )->value; // Extra > indirection > } If a large cache were created and maintained, would it not be equally indirect to check for the presence of a value in the cache, and return that value if it's present? > creating that value then involves a dynamic allocation. Creating which value, sorry -- the type object? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From alfps at start.no Fri Nov 6 14:41:41 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 20:41:41 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Carl Banks: > On Nov 6, 9:28 am, "Alf P. Steinbach" wrote: >> * Rami Chowdhury: >> >>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>> wrote: >>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>> stored value outside the cache range, needless extra indirection for >>>> every operation. >>> Perhaps I'm not understanding this thread at all but how is dynamic >>> allocation hare-brained, and what's the 'needless extra indirection'? >> Dynamic allocation isn't hare-brained, but doing it for every stored integer >> value outside a very small range is, because dynamic allocation is (relatively >> speaking, in the context of integer operations) very costly even with a >> (relatively speaking, in the context of general dynamic allocation) very >> efficient small-objects allocator - here talking order(s) of magnitude. > > > Python made a design trade-off, it chose a simpler implementation Note that the object implementation's complexity doesn't have to affect to any other code since it's trivial to provide abstract accessors (even macros), i.e., this isn't part of a trade-off except if the original developer(s) had limited resources -- and if so then it wasn't a trade-off at the language design level but a trade-off of getting things done then and there. > and uniform object semantic behavior, Also note that the script language level semantics of objects is /unaffected/ by the implementation, except for speed, i.e., this isn't part of a trade-off either. ;-) > at a cost of speed. In summary, the trade-off, if any, couldn't as I see it be what you describe, but there could have been a different kind of getting-it-done trade-off. It is usually better with Something Usable than waiting forever (or too long) for the Perfect... ;-) Or, it could be that things just evolved, constrained by frozen earlier decisions. That's the main reason for the many quirks in C++. Not unlikely that it's also that way for Python. > C# made a > different trade-off, choosing a more complex implementation, a > language with two starkly different object semantic behaviors, so as > to allow better performance. Don't know about the implementation of C#, but whatever it is, if it's bad in some respect then that has nothing to do with Python. > You don't have to like the decision Python made, but I don't think > it's fair to call a deliberate design trade-off hare-brained. OK. :-) Cheers, - Alf From dan.winsor at gmail.com Fri Nov 6 14:41:47 2009 From: dan.winsor at gmail.com (Dan Winsor) Date: Fri, 6 Nov 2009 11:41:47 -0800 (PST) Subject: username/password dialog prompt Message-ID: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> Hi, To preface, I'm a bit of a python novice, but I have been poking around for the solution for a bit and have found actually too many leads which has wedged me. I'm looking to impliment a dialog, preferably using Tkinter, that will prompt for a username and password. I'd like to have the password field blanked (via show="*"), and have the dialog return both fields to the command line script that I'm launching it from. Can someone recommend a good example or tutorial to work from? Thanks very much in advance. -- Dan Winsor Soy un poco loco en el coco. From alfps at start.no Fri Nov 6 14:50:33 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 20:50:33 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Rami Chowdhury: > On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach > wrote: > >> * Rami Chowdhury: >>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>> wrote: >>> >>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>> stored value outside the cache range, needless extra indirection for >>>> every operation. >>>> >>> Perhaps I'm not understanding this thread at all but how is dynamic >>> allocation hare-brained, and what's the 'needless extra indirection'? >> >> Dynamic allocation isn't hare-brained, but doing it for every stored >> integer value outside a very small range is, because dynamic >> allocation is (relatively speaking, in the context of integer >> operations) very costly even with a (relatively speaking, in the >> context of general dynamic allocation) very efficient small-objects >> allocator - here talking order(s) of magnitude. > > Well, sure, it may seem that way. But how large a cache would you want > to preallocate? I can't see the average Python program needing to use > the integers from -10000 to 10000, for instance. In my (admittedly > limited) experience Python programs typically deal with rather more > complex objects than plain integers. Uhm, you've misunderstood or failed to understand something basic, but what? The CPython implementation uses a cache to alleviate problems with performance. A tagged scheme (the usual elsewhere, e.g. Windows' Variant) doesn't need any cache and can't benefit from such a cache, since then an integer's value is directly available in any variable that logically holds an int. In short, a cache for integer values is maningless for the tagged scheme. >> int intValueOf( Object const& o ) >> { >> if( o.type_id != int_type_id ) { throw TypeError(); } >> return static_cast( o.p )->value; // Extra >> indirection >> } > > If a large cache were created and maintained, would it not be equally > indirect to check for the presence of a value in the cache, and return > that value if it's present? Again, that's meaningless. See above. >> creating that value then involves a dynamic allocation. > > Creating which value, sorry -- the type object? Well it's an out-of-context quote, but t'was about creating the value object that a variable contains a pointer to with the current CPython implementation. I'm sure that more information about tagged variant schemes are available on the net. E.g. Wikipedia. Cheers & hth., - Alf From python at mrabarnett.plus.com Fri Nov 6 14:53:59 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Nov 2009 19:53:59 +0000 Subject: safely returning objects from a Process to the parent through a Queue() In-Reply-To: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> References: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> Message-ID: <4AF47ED7.3090807@mrabarnett.plus.com> Verweij, Arjen wrote: > Hi, > > I'm trying to parallelize a loop using Process and Queue. My code looks similar to the example in http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.managers > > It looks like this: > > def pp(q, t, s, a, h, p): > doStuff() > c.generate() > q.put(c, True) #stuff a in a queue > > main: > > for a in aa: > processes = [] > q = Queue() > for b in bb: > try: > if bla > 24: > print "too old" > continue > except: > print "etc" + t #file not found > pass > try: > p = Process(target=pp, args=(q, t, s, a, h, p,)) #trailing comma, do not touch m'kay > p.start() > processes.append(p) > #end for b in bb > for p in processes: > # p.join() # this deadlocks in combination with the Queue() at some point > ss = q.get() > bigcontainer.add(ss) > bigcontainer.generate() > world.add(bigcontainer) > #end for a in aa > world.generate() > > So I have some XML, that requires translation into HTML. I take a sublist, traverse it, spawn a process for every XML file in that list and generate HTML inside that process. Then I would very much like to have the results back in the original main() so it can be used. Is there a way to guarantee that the a in aa loop will not start the next loop? In other words, I'm worried that q will be depleted due to some unknown factor while a subprocess from b in bb still has to write to the Queue() and it will continue somehow leaking/destroying data. > > Before I found the example in the webpage that pointed out the deadlock I couldn't get the program to finish, but finishing without all the data would be equally bad. > Here the answer I gave to an earlier question about multiprocessing: """It think it's down to the difference between multithreading and multiprocessing. When multithreading, the threads share the same address space, so items can be passed between the threads directly. However, when multiprocessing, the processes don't share the same address space, so items need to be passed from process to process via a pipe. Unfortunately, the pipe has a limited capacity, so if a process doesn't read from one end then the pipe will eventually fill up and the sender will block. Also, a process won't terminate until it has finished writing to the pipe, and it can't be joined until it has terminated. You can therefore get into a deadlock where: * Process A won't read from the queue until it has joined process B. * The join won't succeed until process B has terminated. * Process B won't terminate until it has finished writing to the queue. * Process B can't finish writing to the queue because it's full. * The queue is full because process A isn't reading from it. """ I suggest you get all the results from the queue and then join all the processes: for p in processes: ss = q.get() bigcontainer.add(ss) for p in processes: p.join() From philip at semanchuk.com Fri Nov 6 15:00:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 6 Nov 2009 15:00:17 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Hi Jonathan, I'm asking similar questions for the app suite that we're developing on my current project, so I thank you for doing my work for me. ;) I was interested in py2exe because we'd like to provide a one download, one click install experience for our Windows users. I think a lot of people are interested in py2exe for the same reason. Well, one thing that I came across in my travels was the fact that distutils can create MSIs. Like py2exe, MSIs provide a one download, one click install experience under Windows and therefore might be a replacement for py2exe. For me, the following command was sufficient to create an msi, although it only worked under Windows (not under Linux or OS X): python setup.py bdist_msi The resulting MSI worked just fine in my extensive testing (read: I tried it on one machine). It seems, then, that creating an MSI is even within the reach of someone like me who spends very little time in Windows-land, so it might be worth a column on your chart alongside rpm/deb. Thanks again for your work Philip From mwilson at the-wire.com Fri Nov 6 15:12:43 2009 From: mwilson at the-wire.com (Mel) Date: Fri, 06 Nov 2009 15:12:43 -0500 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > Note that the object implementation's complexity doesn't have to affect to > any other code since it's trivial to provide abstract accessors (even > macros), i.e., this isn't part of a trade-off except if the original > developer(s) had limited > resources -- and if so then it wasn't a trade-off at the language design > level but a trade-off of getting things done then and there. But remember what got us in here: your belief (which followed from your assumptions) that computing `is` required testing the object types. You might optimize out the "extra indirection" to get an object's value, but you'd need the "extra indirection" anyway to find out what type it was before you could use it. Mel. From rami.chowdhury at gmail.com Fri Nov 6 15:19:14 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 12:19:14 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 11:50:33 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach >> wrote: >> >>> * Rami Chowdhury: >>>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>>> wrote: >>>> >>>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>>> stored value outside the cache range, needless extra indirection for >>>>> every operation. >>>>> >>>> Perhaps I'm not understanding this thread at all but how is dynamic >>>> allocation hare-brained, and what's the 'needless extra indirection'? >>> >>> Dynamic allocation isn't hare-brained, but doing it for every stored >>> integer value outside a very small range is, because dynamic >>> allocation is (relatively speaking, in the context of integer >>> operations) very costly even with a (relatively speaking, in the >>> context of general dynamic allocation) very efficient small-objects >>> allocator - here talking order(s) of magnitude. >> Well, sure, it may seem that way. But how large a cache would you want >> to preallocate? I can't see the average Python program needing to use >> the integers from -10000 to 10000, for instance. In my (admittedly >> limited) experience Python programs typically deal with rather more >> complex objects than plain integers. > > Uhm, you've misunderstood or failed to understand something basic, but > what? Oh, I see, you were referring to a tagging scheme as an alternative. Sorry for the misunderstanding. > > Well it's an out-of-context quote, but t'was about creating the value > object that a variable contains a pointer to with the current CPython > implementation. > Again, perhaps I'm just misunderstanding what you're saying, but as I understand it, in CPython if you're looking for the value of a PyIntObject, that's stored right there in the structure, so no value object needs to be created... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From alfps at start.no Fri Nov 6 15:49:41 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 21:49:41 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Mel: > Alf P. Steinbach wrote: >> Note that the object implementation's complexity doesn't have to affect to >> any other code since it's trivial to provide abstract accessors (even >> macros), i.e., this isn't part of a trade-off except if the original >> developer(s) had limited >> resources -- and if so then it wasn't a trade-off at the language design >> level but a trade-off of getting things done then and there. > > But remember what got us in here: your belief (which followed from your > assumptions) that computing `is` required testing the object types. Yes, I couldn't believe what I've now been hearing. Uh, reading. :-) > You > might optimize out the "extra indirection" to get an object's value, but > you'd need the "extra indirection" anyway to find out what type it was > before you could use it. No, that type checking is limited (it just checks whether the type is special cased), doesn't involve indirection, and is there anyway except for 'is'. It can be moved around but it's there, or something more costly is there. 'is' is about the only operation you /can/ do without checking the type, but I don't see the point in optimizing 'is' at cost of all other operations on basic types. Cheers & hth., - Alf From pavlovevidence at gmail.com Fri Nov 6 15:53:10 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 6 Nov 2009 12:53:10 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <3f169204-50e5-483d-bcf6-0fe2c874614e@k19g2000yqc.googlegroups.com> On Nov 6, 11:41?am, "Alf P. Steinbach" wrote: > Note that the object implementation's complexity doesn't have to affect to any > other code since it's trivial to provide abstract accessors (even macros), i.e., > this isn't part of a trade-off except if the original developer(s) had limited > resources ?-- ?and if so then it wasn't a trade-off at the language design level > but a trade-off of getting things done then and there. I totally disagree with this; it would be like squaring the implementation complexity. It is far from "trivial" as you claim. Even if it were just a matter of accessor macros (and it isn't) they don't write themselves, especially when you focused on speed, so that's a non-trivial complexity increase already. But you besides writing code you now have reading code (which is now cluttered with all kinds of ugly accessor macros, as if the Python API wasn't ugly enough), debugging code, maintaining code, understanding semantics and nuances, handling all the extra corner cases. To say it's trivial is absurd. > > ?C# made a > > different trade-off, choosing a more complex implementation, a > > language with two starkly different object semantic behaviors, so as > > to allow better performance. > > Don't know about the implementation of C#, but whatever it is, if it's bad in > some respect then that has nothing to do with Python. C# is a prototypical example of a language that does what you were suggesting (also it draws upon frameworks like COM, which you mentioned) so it is a basis of comparison of the benefits versus drawbacks of the two approaches. Carl Banks From no.email at please.post Fri Nov 6 16:03:31 2009 From: no.email at please.post (kj) Date: Fri, 6 Nov 2009 21:03:31 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: In "Emily Rodgers" writes: >"Andre Engels" wrote in message >news:mailman.2696.1257520404.2807.python-list at python.org... >>On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: >[snip] >>> arr = [None] * 1000000 >>> >>> Is this the most efficient way to achieve this result? >> >> It depends - what do you want to do with it? My first hunch would be >> to use a dictionary instead of a list, then the whole problem >> disappears. If there is a reason you don't want to do that, what is >> it? >I second this. It might seem a sensible thing to do in perl, but I can't >imagine what you would actually want to do it for! Seems like an odd thing >to want to do! As I said, this is considered an optimization, at least in Perl, because it lets the interpreter allocate all the required memory in one fell swoop, instead of having to reallocate it repeatedly as the array grows. (Of course, like with all optimizations, whether it's worth the bother is another question.) Another situation where one may want to do this is if one needs to initialize a non-sparse array in a non-sequential order, e.g. if that's the way the data is initially received by the code. Of course, there are many ways to skin such a cat; pre-allocating the space and using direct list indexing is just one of them. I happen to think it is a particularly straighforward one, but I realize that others (you, Andre, etc.) may not agree. kynn From davea at ieee.org Fri Nov 6 16:08:49 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 16:08:49 -0500 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> Message-ID: <4AF49061.8000408@ieee.org> Chris Rebert wrote: > On Thu, Nov 5, 2009 at 10:49 PM, Gabriel Genellina > wrote: > >> En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert >> escribi?: >> >>> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >>> >>>> I looked though the os.path manual. I don't find a function that can >>>> test if a path is in a directory or its sub-directory (recursively). >>>> >>>> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >>>> somebody let me know if such function is available somewhere? >>>> >>> Couldn't you just canonicalize the paths using os.path.abspath() and >>> friends and then do subdirectory.startswith(parent_directory) [as >>> strings]? >>> >> Beware of directories starting with the same letters. >> I'd canonicalize, split the strings on os.sep, and compare the resulting >> lists up to the shortest one. >> > > Ah, I thought there was some edge case I must've missed; my solution > seemed too simple. > > Cheers, > Chris > > But you can probably add a trailing '/' (os.sep) to the shorter string before doing the startswith(). DaveA From irmen at -nospam-xs4all.nl Fri Nov 6 16:09:09 2009 From: irmen at -nospam-xs4all.nl (Irmen de Jong) Date: Fri, 06 Nov 2009 22:09:09 +0100 Subject: username/password dialog prompt In-Reply-To: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> Message-ID: <4af4904b$0$83240$e4fe514c@news.xs4all.nl> On 6-11-2009 20:41, Dan Winsor wrote: > Hi, > > To preface, I'm a bit of a python novice, but I have been poking > around for the solution for a bit and have found actually too many > leads which has wedged me. I'm looking to impliment a dialog, > preferably using Tkinter, that will prompt for a username and > password. I'd like to have the password field blanked (via show="*"), > and have the dialog return both fields to the command line script that > I'm launching it from. Can someone recommend a good example or > tutorial to work from? Thanks very much in advance. My Tkinter is very rusty but perhaps you could do it something like this: http://pastebin.com/m5e49da19 I forgot how to get rid of the empty root window that appears, sorry. -irmen From aahz at pythoncraft.com Fri Nov 6 16:15:32 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Nov 2009 13:15:32 -0800 Subject: Microsoft research on code quality Message-ID: http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From SD_V897 at NoSuchMail.Com Fri Nov 6 16:19:44 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Fri, 06 Nov 2009 21:19:44 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: Rhodri James wrote: > On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 wrote: > >> I have a perplexing issue, I have four users set up on a W7 computer. >> The program runs fine for all users except the admin user who needs it >> for school assignments. > > A little more information, please. How does it not work for the admin > user? Is there a traceback? What do you get if you try to invoke it > from a command line? > Hi Rhodri, here's a dump file, don't know if this helps or not.. Thanks SD Version=1 EventType=AppHangB1 EventTime=129003071519208984 ReportType=3 Consent=1 ReportIdentifier=6a6f168c-bb8f-11de-bef3-044b80808003 IntegratorReportIdentifier=6a6f168d-bb8f-11de-bef3-044b80808003 Response.type=4 Sig[0].Name=Application Name Sig[0].Value=pythonw.exe Sig[1].Name=Application Version Sig[1].Value=0.0.0.0 Sig[2].Name=Application Timestamp Sig[2].Value=49e4f60b Sig[3].Name=Hang Signature Sig[3].Value=ae24 Sig[4].Name=Hang Type Sig[4].Value=0 DynamicSig[1].Name=OS Version DynamicSig[1].Value=6.1.7600.2.0.0.256.1 DynamicSig[2].Name=Locale ID DynamicSig[2].Value=4105 DynamicSig[22].Name=Additional Hang Signature 1 DynamicSig[22].Value=ae248dc299fdb8350ad54ca616b9d7ab DynamicSig[23].Name=Additional Hang Signature 2 DynamicSig[23].Value=39ea DynamicSig[24].Name=Additional Hang Signature 3 DynamicSig[24].Value=39ea45ef52dc245a0c9d687814d64151 DynamicSig[25].Name=Additional Hang Signature 4 DynamicSig[25].Value=ae24 DynamicSig[26].Name=Additional Hang Signature 5 DynamicSig[26].Value=ae248dc299fdb8350ad54ca616b9d7ab DynamicSig[27].Name=Additional Hang Signature 6 DynamicSig[27].Value=39ea DynamicSig[28].Name=Additional Hang Signature 7 DynamicSig[28].Value=39ea45ef52dc245a0c9d687814d64151 UI[3]=pythonw.exe is not responding UI[4]=Windows can check online for a solution. If you close the program, you might lose information. UI[5]=Check for a solution and close the program UI[6]=Check for a solution and close the program UI[7]=Close the program LoadedModule[0]=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll LoadedModule[2]=C:\Windows\system32\kernel32.dll LoadedModule[3]=C:\Windows\system32\KERNELBASE.dll LoadedModule[4]=C:\Windows\system32\python26.dll LoadedModule[5]=C:\Windows\system32\USER32.dll LoadedModule[6]=C:\Windows\system32\GDI32.dll LoadedModule[7]=C:\Windows\system32\LPK.dll LoadedModule[8]=C:\Windows\system32\USP10.dll LoadedModule[9]=C:\Windows\system32\msvcrt.dll LoadedModule[10]=C:\Windows\system32\ADVAPI32.dll LoadedModule[11]=C:\Windows\SYSTEM32\sechost.dll LoadedModule[12]=C:\Windows\system32\RPCRT4.dll LoadedModule[13]=C:\Windows\system32\SHELL32.dll LoadedModule[14]=C:\Windows\system32\SHLWAPI.dll LoadedModule[15]=C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\MSVCR90.dll LoadedModule[16]=C:\Windows\system32\IMM32.DLL LoadedModule[17]=C:\Windows\system32\MSCTF.dll LoadedModule[18]=C:\Windows\system32\guard32.dll LoadedModule[19]=C:\Windows\system32\VERSION.dll LoadedModule[20]=C:\Windows\system32\fltlib.dll LoadedModule[21]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_socket.pyd LoadedModule[22]=C:\Windows\system32\WS2_32.dll LoadedModule[23]=C:\Windows\system32\NSI.dll LoadedModule[24]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_ssl.pyd LoadedModule[25]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_ctypes.pyd LoadedModule[26]=C:\Windows\system32\ole32.dll LoadedModule[27]=C:\Windows\system32\OLEAUT32.dll LoadedModule[28]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_tkinter.pyd LoadedModule[29]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\tcl85.dll LoadedModule[30]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\tk85.dll LoadedModule[31]=C:\Windows\system32\COMDLG32.dll LoadedModule[32]=C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16400_none_ebf9dccf6c73e561\COMCTL32.dll LoadedModule[33]=C:\Windows\system32\CRYPTSP.dll LoadedModule[34]=C:\Windows\system32\rsaenh.dll LoadedModule[35]=C:\Windows\system32\CRYPTBASE.dll LoadedModule[36]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\select.pyd LoadedModule[37]=C:\Windows\system32\WSOCK32.dll LoadedModule[38]=C:\Windows\system32\uxtheme.dll LoadedModule[39]=C:\Program Files\Utilities\RocketDock\RocketDock.dll LoadedModule[40]=C:\Windows\system32\PSAPI.DLL LoadedModule[41]=C:\Program Files\Utilities\Logitech Drivers\SetPoint\lgscroll.dll LoadedModule[42]=C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_d08a205e442db5b5\MSVCR80.dll LoadedModule[43]=C:\Windows\system32\ntmarta.dll LoadedModule[44]=C:\Windows\system32\WLDAP32.dll LoadedModule[45]=C:\Windows\system32\dwmapi.dll LoadedModule[46]=C:\Program Files\Utilities\Python Scripting v2.62\tcl\reg1.2\tclreg12.dll LoadedModule[47]=C:\Windows\system32\apphelp.dll LoadedModule[48]=C:\Windows\system32\mswsock.dll LoadedModule[49]=C:\Windows\System32\wshtcpip.dll LoadedModule[50]=C:\Windows\System32\ctagent.DLL LoadedModule[51]=C:\Program Files\Utilities\Directory Opus\dopushlp.dll LoadedModule[52]=C:\Windows\system32\MPR.dll LoadedModule[53]=C:\Windows\system32\CLBCatQ.DLL LoadedModule[54]=C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16400_none_4209f94e2b866170\comctl32.dll LoadedModule[55]=C:\Windows\system32\SETUPAPI.dll LoadedModule[56]=C:\Windows\system32\CFGMGR32.dll LoadedModule[57]=C:\Windows\system32\DEVOBJ.dll LoadedModule[58]=C:\Windows\system32\propsys.dll LoadedModule[59]=C:\Windows\system32\profapi.dll LoadedModule[60]=C:\Windows\system32\SearchFolder.dll LoadedModule[61]=C:\Windows\system32\XmlLite.dll LoadedModule[62]=C:\Windows\system32\LINKINFO.dll LoadedModule[63]=C:\Windows\system32\RpcRtRemote.dll LoadedModule[64]=C:\Windows\system32\explorerframe.dll LoadedModule[65]=C:\Windows\system32\DUser.dll LoadedModule[66]=C:\Windows\system32\DUI70.dll LoadedModule[67]=C:\Windows\system32\WindowsCodecs.dll LoadedModule[68]=C:\Windows\system32\EhStorShell.dll LoadedModule[69]=C:\Windows\System32\cscui.dll LoadedModule[70]=C:\Windows\System32\CSCDLL.dll LoadedModule[71]=C:\Windows\system32\CSCAPI.dll LoadedModule[72]=C:\Windows\system32\ntshrui.dll LoadedModule[73]=C:\Windows\system32\srvcli.dll LoadedModule[74]=C:\Windows\system32\slc.dll LoadedModule[75]=C:\Windows\system32\msls31.dll LoadedModule[76]=C:\Program Files\Common Files\microsoft shared\ink\tiptsf.dll LoadedModule[77]=C:\Windows\System32\StructuredQuery.dll LoadedModule[78]=C:\Windows\System32\Secur32.dll LoadedModule[79]=C:\Windows\System32\SSPICLI.DLL LoadedModule[80]=C:\Windows\system32\actxprxy.dll LoadedModule[81]=C:\Program Files\Internet Explorer\ieproxy.dll LoadedModule[82]=C:\Windows\system32\thumbcache.dll LoadedModule[83]=C:\Windows\system32\SHDOCVW.dll LoadedModule[84]=C:\Windows\system32\ieframe.DLL LoadedModule[85]=C:\Windows\system32\OLEACC.dll LoadedModule[86]=C:\Windows\system32\iertutil.dll LoadedModule[87]=C:\Windows\System32\drprov.dll LoadedModule[88]=C:\Windows\System32\WINSTA.dll LoadedModule[89]=C:\Windows\System32\ntlanman.dll LoadedModule[90]=C:\Windows\System32\davclnt.dll LoadedModule[91]=C:\Windows\System32\DAVHLPR.dll LoadedModule[92]=C:\Windows\system32\NetworkExplorer.dll LoadedModule[93]=C:\Windows\system32\wkscli.dll LoadedModule[94]=C:\Windows\system32\netutils.dll LoadedModule[95]=C:\Windows\system32\WINMM.dll LoadedModule[96]=C:\Windows\system32\PortableDeviceApi.dll LoadedModule[97]=C:\Windows\system32\WINTRUST.dll LoadedModule[98]=C:\Windows\system32\CRYPT32.dll LoadedModule[99]=C:\Windows\system32\MSASN1.dll LoadedModule[100]=C:\Windows\system32\EhStorAPI.dll LoadedModule[101]=C:\Windows\system32\mssprxy.dll LoadedModule[102]=C:\Windows\system32\IconCodecService.dll LoadedModule[103]=C:\Windows\system32\urlmon.dll FriendlyEventName=Stopped responding and was closed ConsentKey=AppHangXProcB1 AppName=pythonw.exe AppPath=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe ReportDescription=A problem caused this program to stop interacting with Windows. From davea at ieee.org Fri Nov 6 16:32:05 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 16:32:05 -0500 Subject: Best way for permutating using multiple lists? In-Reply-To: <4AF427EB.8010804@xs4all.nl> References: <4AF427EB.8010804@xs4all.nl> Message-ID: <4AF495D5.7090703@ieee.org> Michiel Overtoom wrote: >
hob wrote: > >> any advice people? > > import itertools > alt=itertools.product("def","abc","mno","mno","wxyz") > > Note to the OP. You called this permutation, but it's not. It's the crossproduct. Thus itertools.product DaveA From stef.mientki at gmail.com Fri Nov 6 16:33:37 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 06 Nov 2009 22:33:37 +0100 Subject: imputil.py, is this a bug ? Message-ID: <4AF49631.8090003@gmail.com> hello, I get an error compiling with pyjamas, in the standard module imputil, _import_top_module Traceback (most recent call last): File "D:\Data_Python_25\PyLab_Works\pylab_works_programs\PyJamas_Test\Vraag_Test1.py", line 22, in from Vragenlijsten import Get_Vragenlijst File "P:\Python\Lib\site-packages\pyjd\imputil.py", line 109, in _import_hook top_module = self._import_top_module(parts[0]) File "P:\Python\Lib\site-packages\pyjd\imputil.py", line 217, in _import_top_module module = item.import_top(name) AttributeError: 'unicode' object has no attribute 'import_top' It seems that elements of sys.path can be of the type unicode def _import_top_module(self, name): # scan sys.path looking for a location in the filesystem that contains # the module, or an Importer object that can import the module. for item in sys.path: if isinstance(item, _StringType): module = self.fs_imp.import_from_dir(item, name) else: module = item.import_top(name) if module: return module return None so by adding the next 2 lines, everything works ok. elif isinstance ( item, basestring ) : module = self.fs_imp.import_from_dir ( str(item), name) is this a bug ? (I'm using Python 2.5.2 on Windows ) thanks, Stef Mientki From cousinstanley at gmail.com Fri Nov 6 16:40:18 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 6 Nov 2009 21:40:18 +0000 (UTC) Subject: username/password dialog prompt References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> <4af4904b$0$83240$e4fe514c@news.xs4all.nl> Message-ID: > > My Tkinter is very rusty but perhaps you could do it > something like this : http://pastebin.com/m5e49da19 > > I forgot how to get rid of the empty root window > that appears, sorry. root.withdraw() # should do it -- Stanley C. Kitching Human Being Phoenix, Arizona From exarkun at twistedmatrix.com Fri Nov 6 16:47:18 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 06 Nov 2009 21:47:18 -0000 Subject: Microsoft research on code quality In-Reply-To: References: Message-ID: <20091106214718.3229.36519750.divmod.xquotient.208@localhost.localdomain> On 09:15 pm, aahz at pythoncraft.com wrote: >http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx Thanks for passing on the link. It's really encouraging to see people starting to do empirical research in this area. Jean-Paul From jabba.laci at gmail.com Fri Nov 6 16:50:16 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 Nov 2009 16:50:16 -0500 Subject: regexp question Message-ID: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Hi, How to find all occurences of a substring in a string? I want to convert the following Perl code to Python. Thanks, Laszlo ========== my $text = 'sdqssdsqs'; while ($text =~ m#href="?(.*?)"?>#g) { print $1, "\n"; } # output: # # ad1 # ad2 # ad3 From tjreedy at udel.edu Fri Nov 6 16:58:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Nov 2009 16:58:31 -0500 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: Peng Yu wrote: > Now, I want to in-place delete elements in A that matches the regex. You can to this with a for-loop *IF YOU ITERATE BACKWARDS*. It is O(n**2) in anycase. From bowman.joseph at gmail.com Fri Nov 6 17:06:18 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Fri, 6 Nov 2009 14:06:18 -0800 (PST) Subject: Question about creating dictionary like objects Message-ID: I'm working on a memcached based session library, and I've run into an interesting problem. Here's the full code for the session library - http://pastebin.com/m295fdfc2 What I'm doing is using __setitem__ to set an element as a list. When I call .append() on that list, it appears to be modifying the list in memory, but not running __setitem__ on the parent in order for the information to get saved in memcached. For example, here's a test I wrote in Tornado class TestHandler(BaseHandler): def get(self): session = sessions.Session(req_obj = self) if "test" in session: self.write("should be appending") session["test"].append(datetime.datetime.now()) else: session["test"] = ["first"] self.write(str(session)) This should have just "test" in the list on first load (which it does), the append the datetime object on every refresh, so the list should keep growing. What I'm seeing is that the datetime does get appended to the list in the session object that is printed, but the __setitem__() item is never called, so it never gets updated in memcached. Can someone tell me what I'm doing wrong? From joncle at googlemail.com Fri Nov 6 17:06:26 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 14:06:26 -0800 (PST) Subject: regexp question References: Message-ID: <8e537139-518f-46f3-b6d2-23c5ec0259e4@15g2000yqy.googlegroups.com> On Nov 6, 9:50?pm, Jabba Laci wrote: > Hi, > > How to find all occurences of a substring in a string? I want to > convert the following Perl code to Python. > > Thanks, > > Laszlo > > ========== > > my $text = 'sdqssdsqs'; > > while ($text =~ m#href="?(.*?)"?>#g) > { > ? ?print $1, "\n";} > > # output: > # > # ad1 > # ad2 > # ad3 There's numerous threads on why using regexp's to process html is not a great idea. Search GGs. You're better off using beautifulsoup (an HTML parsing library). The API is simple, and for real-world data is a much better choice. hth Jon. From rami.chowdhury at gmail.com Fri Nov 6 17:10:00 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 14:10:00 -0800 Subject: regexp question In-Reply-To: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> References: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Message-ID: On Fri, 06 Nov 2009 13:50:16 -0800, Jabba Laci wrote: > Hi, > > How to find all occurences of a substring in a string? I want to > convert the following Perl code to Python. > > Thanks, > > Laszlo > > ========== > > my $text = 'sdqssds href=ad3>qs'; > > while ($text =~ m#href="?(.*?)"?>#g) > { > print $1, "\n"; > } > # output: > # > # ad1 > # ad2 > # ad3 Your regular expression pattern should work unchanged, and you probably want to use http://docs.python.org/library/re.html#re.findall or similar to do the actual matching. If all you want to do is iterate over the matches, I would use re.finditer :-) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From jabba.laci at gmail.com Fri Nov 6 17:19:29 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 Nov 2009 17:19:29 -0500 Subject: regexp question In-Reply-To: References: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Message-ID: <310fbb00911061419ra4ba8beva4ed029f61197664@mail.gmail.com> > Your regular expression pattern should work unchanged, and you probably want > to use ?http://docs.python.org/library/re.html#re.findall or similar to do > the actual matching. If all you want to do is iterate over the matches, I > would use re.finditer :-) Thank you, I found the solution: for m in re.finditer(r'href="?(.*?)"?>', text): print m.group(1) Laszlo From clp2 at rebertia.com Fri Nov 6 17:55:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 14:55:53 -0800 Subject: Question about creating dictionary like objects In-Reply-To: References: Message-ID: <50697b2c0911061455r4ff60f48k96e1d87975be23e1@mail.gmail.com> On Fri, Nov 6, 2009 at 2:06 PM, bowman.joseph at gmail.com wrote: > I'm working on a memcached based session library, and I've run into an > interesting problem. > > Here's the full code for the session library - http://pastebin.com/m295fdfc2 > > What I'm doing is using __setitem__ to set an element as a list. When > I call .append() on that list, it appears to be modifying the list in > memory, but not running __setitem__ on the parent in order for the > information to get saved in memcached. list.append() just appends the item to the list object. That's all it does *and nothing else*. It doesn't call __setitem__ on the "parent" object containing the list; how would it even know about that object to begin with? (pointers aren't reversible) With normal containers, there's no need to store modified, mutable items back in the container: the item got modified in-place, the reference to it from the container is still valid, so storing it back would be pointless (sounds like memcached is quirky (but probably justifiably so) in not having this work). Perhaps you thought some copying occurs when getting items out of containers? That's not the case. Since it sounds like you need to force a __setitem__ call on `session` to have memcached update its storage, you'll have to do it explicitly. Change: session["test"].append(datetime.datetime.now()) To: #use some name better than "foo" obviously foo = session["test"] #fetch foo.append(datetime.datetime.now()) #mutate session["test"] = foo #store back explicitly so memcached knows there was a change Cheers, Chris -- http://blog.rebertia.com From subnibhatt at gmail.com Fri Nov 6 18:37:50 2009 From: subnibhatt at gmail.com (Subrahmanya Bhat) Date: Fri, 6 Nov 2009 18:37:50 -0500 Subject: Editing PDF files usig Python Message-ID: Hi All, Greetings, I am a newbie in Python, i have a requirement to develop a component in python that can "text" water mark the PDF file both digitallly and visibly. I have already devloped this kind of a component in .Net using iTextSharp library. So i know a thing or 2 about water marking :-) i also need to able to read back the water mark text that was put in to the PDF (both digital and visible). I looked around on google and found that pyPDF, win32Client etc which may be the one i will have to use. using neither of them i could put a text and hidden text in to the pdf files. Any light thrown in this direction will be of great help to me. Appcreciate your help with this. Thanks Subrah -------------- next part -------------- An HTML attachment was scrubbed... URL: From e1safdar at gmail.com Fri Nov 6 18:48:32 2009 From: e1safdar at gmail.com (safdar) Date: Fri, 6 Nov 2009 15:48:32 -0800 (PST) Subject: Earn Money Message-ID: <927fe7cc-8720-458c-804a-2396a09641c9@s21g2000prm.googlegroups.com> Hello Friend How R U I am fine Plz visit my Blogs http://howweearn.blogspot.com http://safdar-culturefashion.blogspot.com/ http://onlineearningmoneysites.blogspot.com/ http://workonadsense.blogspot.com/ http://safdarhussain2.wordpress.com/ http://chinapakistan.blogspot.com/ http://usamericaol.blogspot.com/ http://americavsmuslimworld.blogspot.com/ http://www.onlineork.cc.cc From davea at ieee.org Fri Nov 6 18:57:28 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 18:57:28 -0500 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> Message-ID: <4AF4B7E8.1030807@ieee.org> Peng Yu wrote: > On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: > >> On Fri, 6 Nov 2009, Peng Yu wrote: >> >> >>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >>> >>>> Peng Yu schrieb: >>>> >>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>> could use a for loop to do so. In a functional language, there is way >>>>> to do so without using the for loop. >>>>> >>>> Nonsense. For processing over each element, you have to loop over them, >>>> either with or without growing a call-stack at the same time. >>>> >>>> FP languages can optimize away the stack-frame-growth (tail recursion) - but >>>> this isn't reducing complexity in any way. >>>> >>>> So use a loop, either directly, or using a list-comprehension. >>>> >>> What is a list-comprehension? >>> >>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>> the iterator, right? I am wondering how to make the code correct. >>> >>> l ='a', 'a', 'b', 'c'] >>> for x in l: >>> if x ='a': >>> l.remove(x) >>> >>> print l >>> >> list comprehension seems to be what you want: >> >> l =i for i in l if i != 'a'] >> > > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs =i for i in l if dirs !'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. > > http://docs.python.org/library/os.html > > When topdown is True, the caller can modify the dirnames list in-place > (perhaps using del or slice assignment), and walk() will only recurse > into the subdirectories whose names remain in dirnames; this can be > used to prune the search, impose a specific order of visiting, or even > to inform walk() about directories the caller creates or renames > before it resumes walk() again. Modifying dirnames when topdown is > False is ineffective, because in bottom-up mode the directories in > dirnames are generated before dirpath itself is generated. > > The context is quite important in this case. The os.walk() iterator gives you a tuple of three values, and one of them is a list. You do indeed want to modify that list, but you usually don't want to do it "in-place." I'll show you the in-place version first, then show you the slice approach. If all you wanted to do was to remove one or two specific items from the list, then the remove method would be good. So in your example, you don' t need a loop. Just say: if 'a' in dirs: dirs.remove('a') But if you have an expression you want to match each dir against, the list comprehension is the best answer. And the trick to stuffing that new list into the original list object is to use slicing on the left side. The [:] notation is a default slice that means the whole list. dirs[:] = [ item for item in dirs if bool_expression_on_item ] HTH DaveA From gagsl-py2 at yahoo.com.ar Fri Nov 6 21:20:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 23:20:01 -0300 Subject: imputil.py, is this a bug ? References: <4AF49631.8090003@gmail.com> Message-ID: En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki escribi?: > I get an error compiling with pyjamas, in the standard module imputil, > _import_top_module Note that imputil is undocumented in 2.5, deprecated in 2.6 and definitively gone in 3.0 > AttributeError: 'unicode' object has no attribute 'import_top' > > def _import_top_module(self, name): > # scan sys.path looking for a location in the filesystem that > contains > # the module, or an Importer object that can import the module. > for item in sys.path: > if isinstance(item, _StringType): > module = self.fs_imp.import_from_dir(item, name) > else: > module = item.import_top(name) > if module: > return module > return None > > It seems that elements of sys.path can be of the type unicode > so by adding the next 2 lines, everything works ok. > elif isinstance ( item, basestring ) : > module = self.fs_imp.import_from_dir ( str(item), name) > > is this a bug ? > (I'm using Python 2.5.2 on Windows ) Yes, seems to be a bug. But given the current status of imputil, it's not likely to be fixed; certainly not in 2.5 which only gets security fixes now. I cannot test it at this moment, but I'd use the unicode item directly (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps item.encode(sys.getdefaultfilesystemencoding()). str(item) definitively won't work with directory names containing non-ascii characters. Why are you using imputil in the first place? -- Gabriel Genellina From gil_johnson at earthlink.net Fri Nov 6 21:46:33 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Fri, 6 Nov 2009 18:46:33 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On Nov 6, 6:12?am, kj wrote: > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ? my @arr; > ? $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ? my @arr; > ? $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > > Traceback (most recent call last): > ? File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn I don't have the code with me, but for huge arrays, I have used something like: >>> arr[0] = initializer >>> for i in range N: >>> arr.extend(arr) This doubles the array every time through the loop, and you can add the powers of 2 to get the desired result. Gil From rt8396 at gmail.com Fri Nov 6 22:06:29 2009 From: rt8396 at gmail.com (r) Date: Fri, 6 Nov 2009 19:06:29 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <1cda743f-5231-4b76-9322-db0e4d474472@p19g2000vbq.googlegroups.com> On Nov 6, 6:12?am, kj wrote: > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ? my @arr; > ? $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ? my @arr; > ? $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > > Traceback (most recent call last): > ? File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn You mean sum'in like dis? class PerlishList(list): '''Hand holding list object for even the most demanding Perl hacker''' def __init__(self, dim=0): list.__init__(self) if dim: self.__setitem__(dim, None) def __setitem__(self, idx, v): lenkeys = len(self) sup = super(PerlishList, self) if idx > lenkeys: for idx in range(lenkeys, idx): sup.append(None) sup.__setitem__(idx, v) def __getitem__(self, idx): return self[idx] l = PerlishList(3) l.append('a') l.append('b') print l l[10] = 10 print l ;-) From gagsl-py2 at yahoo.com.ar Fri Nov 6 22:31:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 07 Nov 2009 00:31:35 -0300 Subject: list to table References: <4AF44466.4040200@optimum.net> Message-ID: En Fri, 06 Nov 2009 12:44:38 -0300, John Posner escribi?: > Gabriel Genellina said: >> Yes, probably that section should be improved (except the final example >> added, the text hasn't changed since it was first written, more than 9 >> years ago). > FWIW ... following on a discussion in this forum in March of this year I > submitted issue #5621 at bugs.python.org [...] > My change was accepted (with some rearrangements made by Georg Brandl), > but has not yet been included in any Py2 or Py3 release, AFAIK. That's strange. Your modified text appears in the online version of the documentation for 2.6.4: http://www.python.org/doc/2.6.4/reference/simple_stmts.html#assignment-statements but not in the source package nor the .chm file included in the Windows binaries for the same release. Same with 3.1.1 Looks like an error in the build process. -- Gabriel Genellina From pict100 at gmail.com Fri Nov 6 23:12:02 2009 From: pict100 at gmail.com (DarkBlue) Date: Fri, 6 Nov 2009 20:12:02 -0800 (PST) Subject: PyQt processEvents not processing Message-ID: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> qt 4.5.3 pyqt 4.6.1 python 2.6 I have this QtTable widget which I want to refresh once about every 2 seconds with new data. so I do : def updateSchedule(self): for j in range(0,10): doUpdate() QtCore.processEvents() sleep(2) unfortunately QT appears to wait until the for loop finishes and only then paints the QtTable widget on the screen showing only the latest updated result. if I connect the doUpdate() to a Qtpushbutton widget and physically click the pushbutton , everything is fine and the updates get shown on every click. What is the right way to simulate this pushbutton click so that the table widget gets 'visibly' refreshed for every iteration of the loop ? Thanks Db From nagle at animats.com Sat Nov 7 00:27:55 2009 From: nagle at animats.com (John Nagle) Date: Fri, 06 Nov 2009 21:27:55 -0800 Subject: Aborting a read with pySerial Message-ID: <4af50316$0$1610$742ec2ed@news.sonic.net> I'm using pySerial to read from a serial port. One thread reads from the port, with no timeout. Another thread handles output and other tasks. This works fine until I want to shut down the program. I can't reliably break the program out of the read when it's waiting. On Windows, closing the serial port will abort the read, but that seems to have no effect on Linux. I know, I could put a timeout on the read and handle all those null returns. Is there a better way? John Nagle From jleihe at gmail.com Sat Nov 7 00:40:24 2009 From: jleihe at gmail.com (Joshua Leihe) Date: Fri, 6 Nov 2009 21:40:24 -0800 Subject: Py2exe error Message-ID: Hello, I was wondering if anyone know how to fix this. When I try to import py2exe version 0.6.9, using the command "import py2exe" I get the following error message. Warning (from warnings module): File "C:\Program Files\Python25\lib\site-packages\py2exe\build_exe.py", line 16 import sets DeprecationWarning: the sets module is deprecated Apparently something is wrong with the sets module, but I don't know how to fix it. Any ideas? Thanks a million, Joshua -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 7 01:12:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 22:12:32 -0800 Subject: Py2exe error In-Reply-To: References: Message-ID: <50697b2c0911062212l39c45eb5r1cccb7054d627220@mail.gmail.com> On Fri, Nov 6, 2009 at 9:40 PM, Joshua Leihe wrote: > Hello, I was wondering if anyone know how to fix this. > When I try to import py2exe version 0.6.9, using the command "import py2exe" > I get the following error message. > > Warning (from warnings module): > ? File "C:\Program Files\Python25\lib\site-packages\py2exe\build_exe.py", > line 16 > ??? import sets > DeprecationWarning: the sets module is deprecated > > Apparently something is wrong with the sets module, but I don't know how to > fix it. > Any ideas? It's a warning, not an error, so you don't truly need to fix it. You can safely ignore it. Apparently your version of py2exe was written for a Python version before sets became a built-in type and thus importing the `sets` module was required in order to use them. Since sets are now built-in, the `sets` module is being phased out, hence the warning; nothing is erroneous with the `sets` module, you're just being told the py2exe code is using it and that it's being deprecated. The py2exe code will /eventually/ need to be changed when it's ported to a version of Python that completely removes the `sets` module (e.g. 3.x), but it's nothing you personally need to worry about. Cheers, Chris -- http://blog.rebertia.com From callmeclaudius at gmail.com Sat Nov 7 01:25:47 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Fri, 6 Nov 2009 22:25:47 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On Nov 5, 7:23 pm, metal wrote: > On 11?6?, ??4?02?, Leland wrote: > > > > > Hi, > > > I always use readline(), strip(), split() and so on to parse a string. > > Is there some elegant way to parse the following string into a > > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > > NET_NAME > > '50MHZ_CLK_SRC' > > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > > NODE_NAME U122 2 > > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > > 'CLK2': CDS_PINID='CLK2'; > > NODE_NAME R1395 1 > > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > > 'A': CDS_PINID='A'; > > > Thanks, > > Leland > > not very elegantly too. > > x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s) > """ > print {x[0]: x[1:]}>>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']} > > """ @metal Apparently you and I differ considerably on our conceptions of elegance. From stefan_ml at behnel.de Sat Nov 7 02:20:20 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 07 Nov 2009 08:20:20 +0100 Subject: is None or == None ? In-Reply-To: References: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4af521a4$0$7614$9b4e6d93@newsspool1.arcor-online.net> mk, 06.11.2009 15:32: > Stefan Behnel wrote: >> class Test(object): >> def __eq__(self, other): >> return other == None >> >> print Test() == None, Test() is None > > Err, I don't want to sound daft, but what is wrong in this example? It > should work as expected: > > >>> class Test(object): > ... def __eq__(self, other): > ... return other == None > ... > >>> Test() is None > False > >>> Test() == None > True Yes, and it shows you that things can compare equal to None without being None. > Or perhaps your example was supposed to show that I should test for > identity with None, not for value with None? Instead of "value" you mean "equality" here, I suppose. While there are certain rare use cases where evaluating non-None objects as equal to None makes sense, in normal use, you almost always want to know if a value is exactly None, not just something that happens to return True when calculating its equality to None, be it because of a programmer's concious consideration or buggy implementation. Stefan From saketh.bhamidipati at gmail.com Sat Nov 7 02:58:15 2009 From: saketh.bhamidipati at gmail.com (Saketh) Date: Fri, 6 Nov 2009 23:58:15 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: On Nov 4, 5:28?pm, Alan Franzoni wrote: > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > > Being from germany, I can say that we *have* this fragmentation, and > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > That's right... forums, although more "accessible" to all the people who > can't/doesn't want to use specific email or nntp clients, are quite slow > to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? > > -- > Alan Franzoni > contact me at public@[mysurname].eu Hi everyone, My small effort to create a place for discussing Python seems to have sparked a larger discussion than I had anticipated. My intent in creating Pyfora is not to splinter the community or encroach upon comp.lang.python users, but to create an alternative location where users can discuss Python. If this offends or irritates anyone, please accept my humble apologies. I understand that forums can be degenerate and uncivil, but my hope is that with Pyfora, beginners will have a place to freely ask questions in a genial environment. A large part of my computer upbringing was on forums, and I wanted to share that experience with new Python users. Sincerely, Saketh From michele.simionato at gmail.com Sat Nov 7 02:59:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 6 Nov 2009 23:59:32 -0800 (PST) Subject: extracting info from media files Message-ID: I would like to extract some simple info from media files, such as size, resolution, duration, codec. What's the simplest way to do it? Once in a time there was pymedia but I see the latest release is of February 2006. The solution should work on Linux and provide support for a large set of video formats. From david at bibliolabs.com Sat Nov 7 04:29:35 2009 From: david at bibliolabs.com (David Williams) Date: Sat, 7 Nov 2009 03:29:35 -0600 (CST) Subject: Editing PDF files usig Python In-Reply-To: References: Message-ID: <58124.76.26.219.35.1257586175.squirrel@www.bibliobazaar.com> Maybe try ReportLab, its pretty much the most advanced Python PDF toolkit I know of: http://www.reportlab.org/ > Hi All, > > Greetings, > > I am a newbie in Python, i have a requirement to develop a component in > python that can "text" water mark the PDF file both digitallly and > visibly. > I have already devloped this kind of a component in .Net using iTextSharp > library. So i know a thing or 2 about water marking :-) > i also need to able to read back the water mark text that was put in to > the > PDF (both digital and visible). > > I looked around on google and found that pyPDF, win32Client etc which may > be > the one i will have to use. using neither of them i could put a text and > hidden text in to the pdf files. Any light thrown in this direction will > be > of great help to me. Appcreciate your help with this. > > Thanks > Subrah > -- > http://mail.python.org/mailman/listinfo/python-list > From raluk_th3blu3_star at yahoo.com Sat Nov 7 04:30:40 2009 From: raluk_th3blu3_star at yahoo.com (Raluca Spanu) Date: Sat, 7 Nov 2009 01:30:40 -0800 (PST) Subject: smtpd and custom MAIL_FROM/RCPT_TO validation Message-ID: <942240.55529.qm@web112306.mail.gq1.yahoo.com> Am o ?ntrebare, v? rug?m: De ce nu-mi trimit messages from Romania to America? :( -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sat Nov 7 04:55:31 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 07 Nov 2009 10:55:31 +0100 Subject: imputil.py, is this a bug ? In-Reply-To: References: <4AF49631.8090003@gmail.com> Message-ID: <4AF54413.9080502@gmail.com> Gabriel Genellina wrote: > En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki > escribi?: > >> I get an error compiling with pyjamas, in the standard module >> imputil, _import_top_module > > Note that imputil is undocumented in 2.5, deprecated in 2.6 and > definitively gone in 3.0 > >> AttributeError: 'unicode' object has no attribute 'import_top' >> >> def _import_top_module(self, name): >> # scan sys.path looking for a location in the filesystem that >> contains >> # the module, or an Importer object that can import the module. >> for item in sys.path: >> if isinstance(item, _StringType): >> module = self.fs_imp.import_from_dir(item, name) >> else: >> module = item.import_top(name) >> if module: >> return module >> return None >> >> It seems that elements of sys.path can be of the type unicode >> so by adding the next 2 lines, everything works ok. >> elif isinstance ( item, basestring ) : >> module = self.fs_imp.import_from_dir ( str(item), name) >> >> is this a bug ? >> (I'm using Python 2.5.2 on Windows ) > > Yes, seems to be a bug. But given the current status of imputil, it's > not likely to be fixed; certainly not in 2.5 which only gets security > fixes now. > > I cannot test it at this moment, but I'd use the unicode item directly > (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps > item.encode(sys.getdefaultfilesystemencoding()). str(item) > definitively won't work with directory names containing non-ascii > characters. > > Why are you using imputil in the first place? > thanks Gabriel, well PyJamas is using (a copy) of it and I bumped into problems using PyJamas. I'll send this message to the PyJamas developers, because this stuff is far beyond my knowledge. cheers, Stef From luke.leighton at googlemail.com Sat Nov 7 06:29:24 2009 From: luke.leighton at googlemail.com (lkcl) Date: Sat, 7 Nov 2009 03:29:24 -0800 (PST) Subject: imputil.py, is this a bug ? References: <4AF49631.8090003@gmail.com> Message-ID: On Nov 7, 2:20 am, "Gabriel Genellina" wrote: > Yes, seems to be a bug. But given the current status of imputil, it's not > likely to be fixed; certainly not in 2.5 which only gets security fixes > now. well, that bug's not the only one. the other one that i found, which i have been specifically ordered not to report (that or _any_ python bugs, of which there have been several discovered in the past eight months), will have to wait until the python developers rescind that order. if the python community is lucky, by the time that decision is made, i will not have forgotten what those bugs are. > (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps > item.encode(sys.getdefaultfilesystemencoding()). str(item) definitively > won't work with directory names containing non-ascii characters. > > Why are you using imputil in the first place? it's an absolutely necessary and integral part of pyjamas-desktop "platform overrides". it's absolutely essential to track, in exactly the same manner in which python "normally" performs importing, and to give the platform- specific "overrides" a chance to get in there, first. so, it is absolutely essential to have a correct working version of imputil.py - and due to the bugs present, and the unwillingness of the python team to fix those bugs, pyjamas-desktop is forced to maintain a copy of imputil.py the "platform" is set to e.g. hulahop, pywebkitgtk or mshtml, depending on the decision made by the user or the developer to use a particular browser engine. the platform name is stored in pyjd.platform in exactly the same way that the system name is stored in sys.platform. the way that the platform-specific overrides works is to perform AST translation of the module, and then to look for the exact same module but in platform/{modulename}{platformname}.py and perform AST translation of _that_ module as well. then, at the top level, any global functions in the platform-specific AST tree *replace* those in the "main" AST. likewise, a node-walk along all methods in all classes of the platform-specific AST tree. in this way, god-awful messy code like this: Widget.py class Widget: def do_something(self): if platform == 'mshtml': # do something terrible and ugly elif platform == 'pywebkitgtk': # do something only marginally better else: # do the default W3C standards-compliant thing def a_standard_function(self): # do something normal that all the browser engines get right can be replaced by three files, each of which encodes *only* the logic associated with the god-awful ugliness of each browser: Widget.py class Widget: def do_something(self): # do the default W3C standards-compliant thing def a_standard_function(self): # do something normal that all the browser engines get right platform/Widgetpywebkitgtk.py class Widget: def do_something(self): # do something only marginally better platform/Widgetmshtml.py class Widget: def do_something(self): # do something terrible and ugly a similar trick could in fact be deployed to drastically simplify the layout of e.g. distutils, _espeeecially_ the compiler and linker modules, by using sys.platform as the "override", or, given that that's not entirely the whole decision-making process, as i noted when doing the mingw32 port of python, it would be better to set something like distutils.platform and to use that. however, although the technique could be used in the distutils/ ccompiler.py case, the level of complexity of the code (the size of each "override"), and the small number of actual modules, means that there isn't actually that much benefit in deploying this AST- overriding technique. in the pyjamas API, however, with over 75 user-interface modules, and over 1200 functions, any one of which could be over-ridden by _eight_ separate platforms, each with their own quirks that can usually be handled with one or two lines of code, the AST-merging idea that james tauber came up with is an absolute god-send. l. From vinay_sajip at yahoo.co.uk Sat Nov 7 06:45:58 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 Nov 2009 03:45:58 -0800 (PST) Subject: Using logging module for conditional nested logs References: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> Message-ID: <09c60941-c594-4773-b0dd-8ec2270926b1@o10g2000yqa.googlegroups.com> On Nov 4, 11:14?pm, Reckoner wrote: > Thanks again. You're welcome. You asked (on a Logging 101 blog comment) for a tutorial on how to use Filters. I can point you this Stack Overflow question: http://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams The answer is perhaps the tutorial you asked for. Another example is given in this test script: http://opensolaris.org/sc/src/xen-gate/xvm-3.3+xen.hg/tools/python/logging/logging-0.4.9.2/test/log_test18.py Hope it helps. Regards, Vinay Sajip From baptiste.lepilleur at gmail.com Sat Nov 7 06:56:54 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sat, 7 Nov 2009 12:56:54 +0100 Subject: What is the correct way to port codecs.open to python 3.1? Message-ID: After applying 2to3.py to port a 2.6 script to 3.1, I get the following error when running my script: File "purekeyworddbtest.py", line 143, in __init__ f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') File "c:\Python31\lib\codecs.py", line 870, in open file = builtins.open(filename, mode, buffering) ValueError: can't have text and binary mode at once I skimmed through python 3.0 release notes, and I haven't seen anything indicating that codecs.open behaviour has changed in incompatible way (just that it is no longer useful). Have I missed something? Do I need to replace all codecs.open with the built-in open function? If so, why does codecs.open still exist? -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Sat Nov 7 06:58:50 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 07 Nov 2009 11:58:50 +0000 Subject: ErrorHandler 1.1.0 Released! Message-ID: <4AF560FA.7080506@simplistix.co.uk> I'm pleased to announce a new release of ErrorHandler. This is a handler for the python standard logging framework that can be used to tell whether messages have been logged at or above a certain level. The only change for this release is that there is now a full set of documentation available courtesy of Sphinx: http://packages.python.org/errorhandler/ For more information, please see: http://www.simplistix.co.uk/software/python/errorhandler cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From john_re at fastmail.us Sat Nov 7 07:11:14 2009 From: john_re at fastmail.us (john_re) Date: Sat, 07 Nov 2009 04:11:14 -0800 Subject: Nov 7 TODAY & Nov 22 - Join Global FreeSW Python GNU(Linux) HW Culture meeting via VOIP - BerkeleyTIP GlobalTIP - For Forwarding Message-ID: <1257595874.3681.1344041095@webmail.messagingengine.com> Guido Van Rossum SciPy talk this month! CONTENTS: Meeting days/times & Howto - Mark your calendar's dates; Videos; Hot topics; Opportunities; Announcement Flyers; New webpages ===== Come join in with the Global Free SW HW & Culture community at the BerkeleyTIP/GlobalTIP meeting, via VOIP. Two meetings this month: Sat Nov 7, 12Noon - 3PM Pacific Time (=UTC-8) Sun Nov 22, 12Noon - 3PM Pacific Time (=UTC-8) Mark your calendars, 1st Sat, 3rd Sun every month. {Note: 4th Sunday this November, to give 2 week spacing.} Join online #berkeleytip on irc.freenode.net & we'll help you get your voip HW & SW working: http://sites.google.com/site/berkeleytip/remote-attendance Or come to the FreeSpeech Cafe at UC Berkeley in person meeting. Join the global mailing list http://groups.google.com/group/BerkTIPGlobal I hope to see you there. :) ===== Talk Videos for November 2009: Django Development - Richard Kiss, Eddy Mulyono, Glen Jarvis, Simeon Franklin; BayPiggies Python for scientific research, discussion with Guido van Rossum; UCBSciPy Netbooks - Michael Gorven, Dave Mackie, and Jonathan Carter; CLUG Japan Linux Symposium Keynote, Linus Torvalds & Jim Zemlin; Linux Foundation http://sites.google.com/site/berkeleytip/talk-videos Download & watch them before the meetings, discuss at the meetings. Thanks to all the Speakers, Videographers, & Groups! :) [Record your local meeting! Put the video online, & email me for inclusion for next month. :) ] ===== Hot topics: Ubuntu 9.10 - Problems? Fixes? Upgrade? Install? Freeswitch VOIP server - setup for BTIP Flyers & outreach to UCBerkeley. Outreach to other UC campuses next semester. ===== Opportunities - Learn new, or increase your job skills, &/or volunteer & help the community: Set up any of: a BTIP Mailing List, web server/site, Freeswitch VOIP server, or Virtual Private Network & SSL ===== Announcement Flyers: Print & Post them in your community. 4/5 available - Freedom, Karmic Koala, Free Culture, SciPy, OLPC. See bottom of page: http://groups.google.com/group/BerkTIPGlobal ===== New BTIP Webpages @ http://sites.google.com/site/berkeleytip/ UC Campus local groups; Free Hardware; System Administration; Announcement Flyers; Opportunities For Forwarding - You are invited to forward this announcement wherever it would be appreciated. From python at mrabarnett.plus.com Sat Nov 7 08:11:47 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 07 Nov 2009 13:11:47 +0000 Subject: What is the correct way to port codecs.open to python 3.1? In-Reply-To: References: Message-ID: <4AF57213.5080203@mrabarnett.plus.com> Baptiste Lepilleur wrote: > After applying 2to3.py to port a 2.6 script to 3.1, I get the following > error when running my script: > File "purekeyworddbtest.py", line 143, in __init__ > f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') > File "c:\Python31\lib\codecs.py", line 870, in open > file = builtins.open(filename, mode, buffering) > ValueError: can't have text and binary mode at once > > I skimmed through python 3.0 release notes, and I haven't seen anything > indicating that codecs.open behaviour has changed in incompatible way > (just that it is no longer useful). Have I missed something? > > Do I need to replace all codecs.open with the built-in open function? If > so, why does codecs.open still exist? > The documentation says of codecs.open() that "Files are always opened in binary mode, even if no binary mode was specified", but you've given the mode as 'rt', so you're asking it to open the file both in text mode _and_ binary mode. This is the same as in Python 2.6. If it works in 2.6 but not in 3.1, perhaps it's just that in 2.6 it ignores the 't' whereas in 3.1 it complains. From ryan at rfk.id.au Sat Nov 7 08:20:23 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Sun, 08 Nov 2009 00:20:23 +1100 Subject: ANN: esky 0.2.1 Message-ID: <1257600023.9188.1.camel@durian> I'm pleased to announce the latest release of esky, a tool for keeping your frozen apps fresh: Downloads: http://pypi.python.org/pypi/esky/ Latest Version: 0.2.1 License: BSD Esky is an auto-update framework for frozen python apps, built on top of bbfreeze. It provides a simple API through which apps can find, fetch and install updates, and a bootstrapping mechanism that keeps the app safe in the face of failed or partial updates. A frozen app that wants to auto-update itself might run the following in a background thread: if hasattr(sys,"frozen"): app = esky.Esky(sys.executable,"http://myapp.com/downloads/") new_version = app.find_update() if new_version is not None: app.install_update(new_version) The new version of the application is linked into the app directory in the safest possible manner: using a carefully-ordered sequence of atomic renames on POSIX, using MoveFileTransacted on Windows Vista or later, and using the "rename-and-pray" method on older versions of Windows. Failed or partial updates are detected and cleaned up automatically. Enjoy! Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From victorsubervi at gmail.com Sat Nov 7 09:13:11 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 09:13:11 -0500 Subject: Serious Privileges Problem: Please Help Message-ID: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> I have a serious privileges problem that is making it impossible to serve python pages on a CentOS server. It appears that nobody on the CentOS discussion list has a solution to this problem. I'm desperate and hoping someone on this list can help. [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ Now, the file does exist: [root at 13gems global_solutions]# pwd /var/www/html/angrynates.com/global_solutions [root at 13gems global_solutions]# ls .... -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py .... and it serves just fine on another server, so there is no "premature end of script headers". Here's where it gets really weird. If I copy the code for index.py and template.py which the former calls, and create files test.py and test2.py and paste the code from the former files in those new files changing only the import statement from "template" to "test2", the tests will resolve!! Now, the ownership and mode are identical on all of them!! [root at 13gems global_solutions]# ls -al | grep test.py -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py [root at 13gems global_solutions]# ls -al | grep test2.py -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py [root at 13gems global_solutions]# ls -al | grep index.py -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py [root at 13gems global_solutions]# ls -al | grep template.py -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc where test.py is identical to index.py (other than the necessary import) and template is identical to test2.py fixfiles relabel /var/www/html # might just work It didn't touch /.autorelabel # and then reboot will relabel all copied files to the correct contexts for the location I rebooted apache with no luck or you could turn off SELinux and reboot I did that and the following two solutions with no luck: echo 0 >/selinux/enforce [root at 13gems ~]# cd /etc/ [root at 13gems etc]# mv selinux/ selinux.BAK [root at 13gems etc]# mkdir selinux [root at 13gems etc]# echo 0>/selinux/enforce ...and the problem continues: [root at 13gems etc]# tail /var/log/httpd/error_log [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of script headers: index.py [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not exist: /var/www/html/angrynates.com/robots.txt [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not exist: /var/www/html/angrynates.com/favicon.ico [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not exist: /var/www/html/angrynates.com/favicon.ico [root at 13gems etc]# Please help. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From baptiste.lepilleur at gmail.com Sat Nov 7 09:41:01 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sat, 7 Nov 2009 15:41:01 +0100 Subject: What is the correct way to port codecs.open to python 3.1? In-Reply-To: <4AF57213.5080203@mrabarnett.plus.com> References: <4AF57213.5080203@mrabarnett.plus.com> Message-ID: 2009/11/7 MRAB > Baptiste Lepilleur wrote: > [..] >> Do I need to replace all codecs.open with the built-in open function? If >> so, why does codecs.open still exist? >> >> The documentation says of codecs.open() that "Files are always opened in > binary mode, even if no binary mode was specified", but you've given the > mode as 'rt', so you're asking it to open the file both in text mode > _and_ binary mode. This is the same as in Python 2.6. > > If it works in 2.6 but not in 3.1, perhaps it's just that in 2.6 it > ignores the 't' whereas in 3.1 it complains. > So I did miss something, but it was in 2.6. Thanks for the clarification. Though, I think the documentation is somewhat confusing in 3.x as it says that it opens the file in binary mode, but the opened file iterator returns str not bytes... -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrholtsr at sbcglobal.net Sat Nov 7 09:44:43 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sat, 7 Nov 2009 09:44:43 -0500 Subject: Program to compute and print 1000th prime number Message-ID: <36B2917E90F0414EA90B73D7E896005F@ray> I am taking the MIT online course Introduction to Computer Science and Programming. I have a assignment to write a program to compute and print the 1000th. prime number. Can someone give me some leads on the correct code? Thanks, Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sat Nov 7 09:49:50 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 7 Nov 2009 09:49:50 -0500 Subject: Program to compute and print 1000th prime number In-Reply-To: <36B2917E90F0414EA90B73D7E896005F@ray> References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > I am taking the MIT online course Introduction to Computer Science > and Programming. I have a assignment to write a program to compute > and print the 1000th. prime number. Can someone give me some leads > on the correct code? Thanks, Ray Copying code != doing an assignment. Try Knuth. S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 09:54:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 14:54:18 GMT Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> Message-ID: <0305785b$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 10:16:58 -0600, Peng Yu wrote: > What is a list-comprehension? Time for you to Read The Fine Manual. http://docs.python.org/tutorial/index.html > I tried the following code. The list 'l' will be ['a','b','c'] rather > than ['b','c'], which is what I want. It seems 'remove' will disrupt the > iterator, right? I am wondering how to make the code correct. > > l = ['a', 'a', 'b', 'c'] > for x in l: > if x == 'a': > l.remove(x) Oh lordy, it's Shlemiel the Painter's algorithm. Please don't do that for lists with more than a handful of items. Better still, please don't do that. http://www.joelonsoftware.com/articles/fog0000000319.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:04:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:04:39 GMT Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: <03057ac9$0$1290$c3e8da3@news.astraweb.com> On Sat, 07 Nov 2009 01:09:51 +1300, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.fsf at benfinney.id.au>, Ben Finney wrote: > >> Lawrence D'Oliveiro writes: >> >>> -- ?ScrolledCavas? should >>> be ?ScrolledCanvas?. >> >> Thanks for finding and describing a fault with the Python >> documentation. This is not the right place for reporting it, though: >> this is the Python user forum, not an appropriate place for reporting >> faults. >> >> If you would like the issue to be addressed, please report it to the >> Python bug tracking system . > > What do you want, a bloody HTML patch? Just fix the damn typo, already! I tried abusing strangers on the Internet, but the typo is still there. So I tried waving my hands in the air, but the typo is still there. Then I tried chanting magical incantations, but the typo is still there. I tried kicking the dog across the room, but the typo is still there. Next I'm going to try wishing really, really hard, and if that fails I'll try abusing strangers on the Internet again, and if that still fails, well, I guess that there just is no possible way to fix typos in the Python documentation. Such a pity. If only there was, oh I don't know, a Python bug tracker or something, where one could report bugs and have them fixed. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:05:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:05:26 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <03057af7$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 16:51:18 +0100, Marco Mariani wrote: > Using "x is y" with integers > makes no sense and has no guaranteed behaviour AFAIK Of course it makes sense. `x is y` means *exactly the same thing* for ints as it does with any other object: it tests for object identity. That's all it does, and it does it perfectly. Python makes no promise whether x = 3; y = 3 will use the same object for both x and y or not. That's an implementation detail. That's not a problem with `is`, it is a problem with developers who make unjustified assumptions. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:07:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:07:15 GMT Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <03057b64$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 18:46:33 -0800, gil_johnson wrote: > I don't have the code with me, but for huge arrays, I have used > something like: > >>>> arr[0] = initializer >>>> for i in range N: >>>> arr.extend(arr) > > This doubles the array every time through the loop, and you can add the > powers of 2 to get the desired result. Gil Why is it better to grow the list piecemeal instead of just allocating a list the size you want in one go? arr = [x]*size_wanted -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:14:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:14:10 GMT Subject: Defining re pattern for matching list of numbers References: Message-ID: <03057d03$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 10:16:31 -0800, Chris Rebert wrote: > Your format seems so simple I have to ask why you're using regexes in > the first place. Raymond Hettinger has described some computing techniques as "code prions" -- programming advice or techniques which are sometimes useful but often actively harmful. http://www.mail-archive.com/python-list%40python.org/msg262651.html As useful as regexes are, I think they qualify as code prions too: people insist on using them in production code, even when a simple string method or function would do the job far more efficiently and readably. -- Steven From rpjday at crashcourse.ca Sat Nov 7 10:21:40 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 10:21:40 -0500 (EST) Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Sat, 7 Nov 2009, ssteinerX at gmail.com wrote: > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > I am taking the MIT online course Introduction to Computer Science and > Programming. I have a assignment to write a program to compute and print > the 1000th. prime number. Can someone give me some leads on the correct > code? Thanks, Ray > > > Copying code != doing an assignment. ?Try Knuth. i was going to say much the same, but it's also worth pointing out that, using standard techniques, there is no straightforward way to print the n'th prime number, given some initial value of n. the ubiquitous sieve of eratosthenes requires you to pre-specify your maximum value, after which -- once the sieve completes -- all you know is that you have all of the prime numbers up to n. whether you'll have 1000 of them isn't clear, which means that you might have to start all over with a larger maximum value. (being able to directly determine the n'th prime number would solve a *lot* of prime number problems. :-) and given that one can google and, in seconds, have the solution, i feel no guilt in referring to http://code.activestate.com/recipes/366178/. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From aneeshvkulkarni at gmail.com Sat Nov 7 10:43:15 2009 From: aneeshvkulkarni at gmail.com (Aneesh Kulkarni) Date: Sat, 7 Nov 2009 07:43:15 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <92e6ede8-7437-4f96-8751-f67749e490c0@m26g2000yqb.googlegroups.com> Imagine if no one ever created anything new out of fear of "fragmenting the community". Should we hurl the same accusation at Guido for fragmenting the programmer community and creating Python, when perfectly fine languages like Perl, Lisp & Smalltalk already existed? Creating new things is a part of the natural evolution of the web ecosystem. Some of them will succeed, like Python itself did, and ultimately improve the ecosystem. New places hardly fragment the community, because at the early stages, they usually don't draw many resources away from existing communities; by the time they do, they can be valuable contributors to the larger community in their own right. Aneesh On Nov 7, 2:58?am, Saketh wrote: > On Nov 4, 5:28?pm, Alan Franzoni > wrote: > > > > > > > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > > > Being from germany, I can say that we *have* this fragmentation, and > > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > > That's right... forums, although more "accessible" to all the people who > > can't/doesn't want to use specific email or nntp clients, are quite slow > > to use. > > > But I think Ubuntu forums support threads and are kind of "channeled" > > between ML and webinterface... something like Google Groups; I think > > THAT would be a good idea. What about trying to "channel" > > comp.lang.python and a forum? > > > -- > > Alan Franzoni > > contact me at public@[mysurname].eu > > Hi everyone, > > My small effort to create a place for discussing Python seems to have > sparked a larger discussion than I had anticipated. My intent in > creatingPyforais not to splinter the community or encroach upon > comp.lang.python users, but to create an alternative location where > users can discuss Python. If this offends or irritates anyone, please > accept my humble apologies. > > I understand that forums can be degenerate and uncivil, but my hope is > that withPyfora, beginners will have a place to freely ask questions > in a genial environment. A large part of my computer upbringing was on > forums, and I wanted to share that experience with new Python users. > > Sincerely, > Saketh From david at boddie.org.uk Sat Nov 7 11:04:13 2009 From: david at boddie.org.uk (David Boddie) Date: Sat, 07 Nov 2009 17:04:13 +0100 Subject: PyQt processEvents not processing References: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> Message-ID: On Saturday 07 November 2009 05:12, DarkBlue wrote: > qt 4.5.3 > pyqt 4.6.1 > python 2.6 > > I have this QtTable widget which I want to refresh once about every 2 > seconds with new data. > > so I do : > > def updateSchedule(self): > for j in range(0,10): > doUpdate() > QtCore.processEvents() > sleep(2) > > unfortunately QT appears to wait until the for loop finishes > and only then paints the QtTable widget on the screen showing > only the latest updated result. It's difficult to know exactly why this is without more context. Calling the application's processEvents() method should give the user interface the chance to update itself, but perhaps you need to explicitly call update() on the QTableView or QTableWidget instance to ensure that it is refreshed. An alternative way to do this is to use a timer to update the table every two seconds. David From pengyu.ut at gmail.com Sat Nov 7 11:12:25 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 10:12:25 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <0305785b$0$1290$c3e8da3@news.astraweb.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <0305785b$0$1290$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911070812r2d3da9f6r74dcdb29d26c1263@mail.gmail.com> On Sat, Nov 7, 2009 at 8:54 AM, Steven D'Aprano wrote: > On Fri, 06 Nov 2009 10:16:58 -0600, Peng Yu wrote: > >> What is a list-comprehension? > > Time for you to Read The Fine Manual. > > http://docs.python.org/tutorial/index.html > > >> I tried the following code. The list 'l' will be ['a','b','c'] rather >> than ['b','c'], which is what I want. It seems 'remove' will disrupt the >> iterator, right? I am wondering how to make the code correct. >> >> l = ['a', 'a', 'b', 'c'] >> for x in l: >> ? if x == 'a': >> ? ? l.remove(x) > > > Oh lordy, it's Shlemiel the Painter's algorithm. Please don't do that for > lists with more than a handful of items. Better still, please don't do > that. > > http://www.joelonsoftware.com/articles/fog0000000319.html I understand what is Shlemiel the Painter's algorithm. But if the iterator can be intelligently adjusted in my code upon 'remove()', is my code Shlemiel the Painter's algorithm? From pengyu.ut at gmail.com Sat Nov 7 11:13:52 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 10:13:52 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <4AF4B7E8.1030807@ieee.org> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> Message-ID: <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > > > Peng Yu wrote: >> >> On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day >> wrote: >> >>> >>> On Fri, 6 Nov 2009, Peng Yu wrote: >>> >>> >>>> >>>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch >>>> wrote: >>>> >>>>> >>>>> Peng Yu schrieb: >>>>> >>>>>> >>>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>>> could use a for loop to do so. In a functional language, there is way >>>>>> to do so without using the for loop. >>>>>> >>>>> >>>>> Nonsense. For processing over each element, you have to loop over them, >>>>> either with or without growing a call-stack at the same time. >>>>> >>>>> FP languages can optimize away the stack-frame-growth (tail recursion) >>>>> - but >>>>> this isn't reducing complexity in any way. >>>>> >>>>> So use a loop, either directly, or using a list-comprehension. >>>>> >>>> >>>> What is a list-comprehension? >>>> >>>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>>> the iterator, right? I am wondering how to make the code correct. >>>> >>>> l ='a', 'a', 'b', 'c'] >>>> for x in l: >>>> ?if x ='a': >>>> ? ?l.remove(x) >>>> >>>> print l >>>> >>> >>> ?list comprehension seems to be what you want: >>> >>> ?l =i for i in l if i != 'a'] >>> >> >> My problem comes from the context of using os.walk(). Please see the >> description of the following webpage. Somehow I have to modify the >> list inplace. I have already tried 'dirs =i for i in l if dirs !'a']'. But >> it seems that it doesn't "prune the search". So I need the >> inplace modification of list. >> >> http://docs.python.org/library/os.html >> >> When topdown is True, the caller can modify the dirnames list in-place >> (perhaps using del or slice assignment), and walk() will only recurse >> into the subdirectories whose names remain in dirnames; this can be >> used to prune the search, impose a specific order of visiting, or even >> to inform walk() about directories the caller creates or renames >> before it resumes walk() again. Modifying dirnames when topdown is >> False is ineffective, because in bottom-up mode the directories in >> dirnames are generated before dirpath itself is generated. >> >> > > The context is quite important in this case. ?The os.walk() iterator gives > you a tuple of three values, and one of them is a list. ?You do indeed want > to modify that list, but you usually don't want to do it "in-place." ? I'll > show you the in-place version first, then show you the slice approach. > > If all you wanted to do was to remove one or two specific items from the > list, then the remove method would be good. ?So in your example, you don' t > need a loop. ?Just say: > ? if 'a' in dirs: > ? ? ? ?dirs.remove('a') > > But if you have an expression you want to match each dir against, the list > comprehension is the best answer. ?And the trick to stuffing that new list > into the original list object is to use slicing on the left side. ?The [:] > notation is a default slice that means the whole list. > > ? dirs[:] = [ item for item in dirs if ? ? bool_expression_on_item ] I suggest to add this example to the document of os.walk() to make other users' life easier. From victorsubervi at gmail.com Sat Nov 7 11:59:29 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 11:59:29 -0500 Subject: Can't Find Module Message-ID: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> Hi; I'm getting this error: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line 204, in handler module = page_cache[req] File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 82, in __getitem__ return self._checkitem(name)[2] File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 124, in _checkitem value = self.build(key, name, opened, entry) File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line 77, in build return ModuleCache.build(self, key, req, opened, entry) File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 371, in build exec opened in module.__dict__ File "/var/www/html/angrynates.com/global_solutions/index.py", line 8, in ? from template import template ImportError: No module named template Here's the code: #!/usr/bin/python import string import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from template import template ourFile = string.split(__file__, "/") page = ourFile[len(ourFile) - 1][:-3] form = cgi.FieldStorage() w = form.getfirst('w', '1024') print page template(page, w) I can import this just fine from the python command prompt. So, what gives? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Sat Nov 7 12:23:06 2009 From: python at rcn.com (Raymond Hettinger) Date: Sat, 7 Nov 2009 09:23:06 -0800 (PST) Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > ? ? ? I am taking the MIT online course Introduction to Computer Science and > > ? ? ? Programming. I have a assignment to write a program to compute and print > > ? ? ? the 1000th. prime number. Can someone give me some leads on the correct > > ? ? ? code? Thanks, Ray Tongue in cheek solution: import urllib2 url = 'http://primes.utm.edu/lists/small/10000.txt' primes = [] for line in urllib2.urlopen(url).read().splitlines(): values = line.split() if len(values) == 10: primes.extend(values) print primes[1000-1] Raymond From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:29:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:29:58 +0100 Subject: how to display the return type of an os method? In-Reply-To: References: Message-ID: <4af5bc28$0$13899$426a74cc@news.free.fr> Robert P. J. Day a ?crit : > once again, a thoroughly newbie question but what's the quickest way > to display the return type of, say, os.stat()? i can obviously do > this in two steps: > >>>> x=os.stat('/etc/passwd') >>>> type(x) > > > i'd just like to see that os.stat() returns a posix.stat_result > object in one line. => type(os.stat('/etc/passwd')) But reading the doc might help too: => help(os.stat) From rpjday at crashcourse.ca Sat Nov 7 12:32:45 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 12:32:45 -0500 (EST) Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Sat, 7 Nov 2009, Raymond Hettinger wrote: > > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > > > ? ? ? I am taking the MIT online course Introduction to Computer > > > Science and ? ? ? Programming. I have a assignment to write a > > > program to compute and print ? ? ? the 1000th. prime number. Can > > > someone give me some leads on the correct ? ? ? code? Thanks, > > > Ray > > Tongue in cheek solution: > > import urllib2 > > url = 'http://primes.utm.edu/lists/small/10000.txt' > primes = [] > for line in urllib2.urlopen(url).read().splitlines(): > values = line.split() > if len(values) == 10: > primes.extend(values) > print primes[1000-1] reminds me of a variation of an old joke: using nothing but this barometer, determine the height of that building. answer: go to the building manager and say, "i'll give you this really neat barometer if you tell me how tall this building is." rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:36:08 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:36:08 +0100 Subject: exception due to NoneType In-Reply-To: References: Message-ID: <4af5bd9a$0$22506$426a74cc@news.free.fr> asit a ?crit : > In my program I want to catch exception which is caused by accessing > NoneType object. > > Can anyone suggest me how this can be done ?? Not without the minimal working code exposing your problem, or the full traceback you got. Merely "accessing NoneType object" doesn't by itself raise any exception... I suspect you get the None object where you expected something else and try to access an attribute of this 'something else', and ends up getting an AttributeError, but there are other possible scenarii that might fit your (very poor) description of the problem, so no way too help you without more informations. As a general rule, remember that the traceback is actually meant to *help* finding out what went wring. From contact at xavierho.com Sat Nov 7 12:37:48 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 8 Nov 2009 03:37:48 +1000 Subject: Program to compute and print 1000th prime number In-Reply-To: <36B2917E90F0414EA90B73D7E896005F@ray> References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <2d56febf0911070937u1114220fk140cbc4f1bfc30ed@mail.gmail.com> On Sun, Nov 8, 2009 at 12:44 AM, Ray Holt wrote: > I have a assignment to write a program to compute and print the 1000th. > prime number. Can someone give me some leads on the correct code? > Ray, if you really want an answer out of this list, you'll have to at least show us what efforts you've put into solving this problem. Perhaps if you post your code that doesn't quite work, we can make suggestions on how to improve/fix it. Other than that, it's generally considered bad karma to give any kind of code, and we need to know where you are. my 2c, Xavier -------------- next part -------------- An HTML attachment was scrubbed... URL: From half.italian at gmail.com Sat Nov 7 12:38:04 2009 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 7 Nov 2009 09:38:04 -0800 (PST) Subject: extracting info from media files References: Message-ID: <240b5019-c9d3-4a08-aee4-ec8e8924b42a@x5g2000prf.googlegroups.com> MediaInfo is your best bet. http://mediainfo.sourceforge.net/en ~Sean On Nov 6, 11:59?pm, Michele Simionato wrote: > I would like to extract some simple info from media files, such as > size, resolution, duration, codec. What's the simplest way to do it? > Once in a time there was pymedia but I see the latest release is of > February 2006. The solution should work on Linux and provide support > for a large set of video formats. From mensanator at aol.com Sat Nov 7 12:40:31 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 09:40:31 -0800 (PST) Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Nov 7, 11:23?am, Raymond Hettinger wrote: > > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > > ? ? ? I am taking the MIT online course Introduction to Computer Science and > > > ? ? ? Programming. I have a assignment to write a program to compute and print > > > ? ? ? the 1000th. prime number. Can someone give me some leads on the correct > > > ? ? ? code? Thanks, Ray > > Tongue in cheek solution: > > import urllib2 > > url = 'http://primes.utm.edu/lists/small/10000.txt' > primes = [] > for line in urllib2.urlopen(url).read().splitlines(): > ? ? values = line.split() > ? ? if len(values) == 10: > ? ? ? ? primes.extend(values) > print primes[1000-1] Nice, but you can do better. >>> import gmpy >>> n = 1 >>> for i in xrange(1000): n = gmpy.next_prime(n) >>> print n 7919 > > Raymond From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:43:35 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:43:35 +0100 Subject: Microsoft research on code quality In-Reply-To: References: Message-ID: <4af5bf58$0$20947$426a74cc@news.free.fr> Aahz a ?crit : > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx An interesting reading. Thanks for the link. From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:55:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:55:14 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: <4af5c216$0$715$426a74cc@news.free.fr> kj a ?crit : > > As I said, this is considered an optimization, at least in Perl, > because it lets the interpreter allocate all the required memory > in one fell swoop, instead of having to reallocate it repeatedly > as the array grows. IIRC, CPython has it's own way to optimize list growth. > (Of course, like with all optimizations, > whether it's worth the bother is another question.) My very humble opinion is that unless you spot a bottleneck (that is, you have real performance issues AND the profiler identified list growth as the culprit), the answer is a clear and obvious NO. > Another situation where one may want to do this is if one needs to > initialize a non-sparse array in a non-sequential order, Then use a dict. From lipun4u at gmail.com Sat Nov 7 13:06:43 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 10:06:43 -0800 (PST) Subject: exception due to NoneType Message-ID: In my program I want to catch exception which is caused by accessing NoneType object. Can anyone suggest me how this can be done ?? From solipsis at pitrou.net Sat Nov 7 13:10:24 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 7 Nov 2009 18:10:24 +0000 (UTC) Subject: What is the correct way to port codecs.open to python 3.1? References: Message-ID: Le Sat, 07 Nov 2009 12:56:54 +0100, Baptiste Lepilleur a ?crit?: > > After applying 2to3.py to port a 2.6 script to 3.1, I get the following > error when running my script: > File "purekeyworddbtest.py", line 143, in __init__ > f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') > File "c:\Python31\lib\codecs.py", line 870, in open > file = builtins.open(filename, mode, buffering) > ValueError: can't have text and binary mode at once I would suggest not using codecs.open() in 3.x, since the built-in open() will do the same thing, but faster. So just write: f = open(EXCLUDED_KEYWORDS_FILE, 'r', encoding='utf-8') and you'll get a fast file object giving you str (unicode) objects after an implicit utf-8 decoding of file data. Regards Antoine. From rpjday at crashcourse.ca Sat Nov 7 13:12:27 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:12:27 -0500 (EST) Subject: how to display the return type of an os method? Message-ID: once again, a thoroughly newbie question but what's the quickest way to display the return type of, say, os.stat()? i can obviously do this in two steps: >>> x=os.stat('/etc/passwd') >>> type(x) >>> i'd just like to see that os.stat() returns a posix.stat_result object in one line. how dumb a question is that? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From jjposner at optimum.net Sat Nov 7 13:18:18 2009 From: jjposner at optimum.net (John Posner) Date: Sat, 07 Nov 2009 13:18:18 -0500 Subject: Program to compute and print 1000th prime number In-Reply-To: References: Message-ID: <4AF5B9EA.2070307@optimum.net> Robert P. J. Day said: > the ubiquitous sieve of eratosthenes requires you to pre-specify > your maximum value, after which -- once the sieve completes -- all you > know is that you have all of the prime numbers up to n. whether > you'll have 1000 of them isn't clear, which means that you might have > to start all over with a larger maximum value. (being able to > directly determine the n'th prime number would solve a *lot* of prime > number problems. :-) > > In April of this year, members of this forum helped me to devise a prime-number iterator [1]. So here's a simple solution for the OP: #--------------- from itertools import ifilter, count # create iterator prime_iter = ifilter( lambda n, P=[]: all(n%p for p in P) and not P.append(n), count(2)) # throw away lots of primes for i in range(999): prime_iter.next() # here's the one we want print prime_iter.next() #7919 #--------------- I don't think this is a solution that a course instructor would expect, though! As mentioned in [1], optimizations of this algorithm (using itertools.takewhile() and/or caching previously-computed squares) are still at cl1p.net [2]. -John [1] http://mail.python.org/pipermail/python-list/2009-April/177415.html [2] http://www.cl1p.net/python_prime_generators From rpjday at crashcourse.ca Sat Nov 7 13:20:47 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:20:47 -0500 (EST) Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> Message-ID: On Sat, 7 Nov 2009, Peng Yu wrote: > On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > > But if you have an expression you want to match each dir against, > > the list comprehension is the best answer. ?And the trick to > > stuffing that new list into the original list object is to use > > slicing on the left side. ?The [:] notation is a default slice > > that means the whole list. > > > > ? dirs[:] = [ item for item in dirs if ? ? bool_expression_on_item ] > > I suggest to add this example to the document of os.walk() to make > other users' life easier. huh? why do you need the slice notation on the left? why can't you just assign to "dirs" as opposed to "dirs[:]"? using the former seems to work just fine. is this some kind of python optimization or idiom? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From andreengels at gmail.com Sat Nov 7 13:34:47 2009 From: andreengels at gmail.com (Andre Engels) Date: Sat, 7 Nov 2009 19:34:47 +0100 Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <6faf39c90911071034y3723541btfdfc684bc6ec771b@mail.gmail.com> On Sat, Nov 7, 2009 at 6:40 PM, Mensanator wrote: >> Tongue in cheek solution: >> >> import urllib2 >> >> url = 'http://primes.utm.edu/lists/small/10000.txt' >> primes = [] >> for line in urllib2.urlopen(url).read().splitlines(): >> ? ? values = line.split() >> ? ? if len(values) == 10: >> ? ? ? ? primes.extend(values) >> print primes[1000-1] > > Nice, but you can do better. > >>>> import gmpy >>>> n = 1 >>>> for i in xrange(1000): > ? ? ? ?n = gmpy.next_prime(n) >>>> print n > 7919 With the help of the solutions given so far, I can do even better than that: n = 7919 print n -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Sat Nov 7 13:47:41 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Nov 2009 19:47:41 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> Message-ID: Robert P. J. Day wrote: > On Sat, 7 Nov 2009, Peng Yu wrote: > >> On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > >> > But if you have an expression you want to match each dir against, >> > the list comprehension is the best answer. And the trick to >> > stuffing that new list into the original list object is to use >> > slicing on the left side. The [:] notation is a default slice >> > that means the whole list. >> > >> > dirs[:] = [ item for item in dirs if bool_expression_on_item ] >> >> I suggest to add this example to the document of os.walk() to make >> other users' life easier. > > huh? why do you need the slice notation on the left? why can't you > just assign to "dirs" as opposed to "dirs[:]"? using the former seems > to work just fine. is this some kind of python optimization or idiom? dirs = [...] rebinds the name "dirs" while dirs[:] = [...] updates the contents of the list currently bound to the "dirs" name. The latter is necessary in the context of os.walk() because it yields a list of subdirectories, gives the user a chance to update it and than uses this potentially updated list to decide which subdirectories to descend into. A simplified example: >>> def f(): ... items = ["a", "b", "c"] ... yield items ... print items ... >>> for items in f(): ... items = ["x", "y"] ... ['a', 'b', 'c'] >>> for items in f(): ... items[:] = ["x", "y"] ... ['x', 'y'] Peter From rpjday at crashcourse.ca Sat Nov 7 13:50:19 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:50:19 -0500 (EST) Subject: how to display the return type of an os method? In-Reply-To: <4af5bc28$0$13899$426a74cc@news.free.fr> References: <4af5bc28$0$13899$426a74cc@news.free.fr> Message-ID: On Sat, 7 Nov 2009, Bruno Desthuilliers wrote: > Robert P. J. Day a ?crit : > > once again, a thoroughly newbie question but what's the quickest way > > to display the return type of, say, os.stat()? i can obviously do > > this in two steps: > > > >>>> x=os.stat('/etc/passwd') > >>>> type(x) > > > > > > i'd just like to see that os.stat() returns a posix.stat_result > > object in one line. > > => type(os.stat('/etc/passwd')) > > But reading the doc might help too: > > => help(os.stat) never mind, i realize now it was a dumb question since the return type is based on the routine logic, of course. argh. carry on. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From lipun4u at gmail.com Sat Nov 7 14:08:18 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 11:08:18 -0800 (PST) Subject: exception due to NoneType References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: On Nov 7, 10:36?pm, Bruno Desthuilliers wrote: > asit a ?crit : > > > In my program I want to catch exception which is caused by accessing > > NoneType object. > > > Can anyone suggest me how this can be done ?? > > Not without the minimal working code exposing your problem, or the full > traceback you got. Merely "accessing NoneType object" doesn't by itself > raise any exception... I suspect you get the None object where you > expected something else and try to access an attribute of this > 'something else', and ends up getting an AttributeError, but there are > other possible scenarii that might fit your (very poor) description of > the problem, so no way too help you without more informations. As a > general rule, remember that the traceback is actually meant to *help* > finding out what went wring. I could have described the error, but the problem is that it's dependent of a third party library.. Let me write the code here... import twitter api = twitter.Api('asitdhal','swordfish') users = api.GetFriends() for s in users: print print "##########################################" try: print "user id : " + str(s.id) print "user name : " + s.name print "user location : " + s.location print "user description : " + s.description print "user profile image url : " + s.profile_image_url print "user url : " + s.url print "user status : " + str(s.status) except TypeError: pass look at the except TypeError. This is supposed to catch only exception thrown by NoneType. please help me. From lipun4u at gmail.com Sat Nov 7 14:24:20 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 11:24:20 -0800 (PST) Subject: database handling Message-ID: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> I need some tutorial about python-mysql connectivity(database handling). Somebody please help me !! From kyrie at uh.cu Sat Nov 7 14:25:19 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Sat, 07 Nov 2009 14:25:19 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <4af5c216$0$715$426a74cc@news.free.fr> References: <4af5c216$0$715$426a74cc@news.free.fr> Message-ID: <1257621919.4af5c99fcd1f6@mail.uh.cu> Quoting Bruno Desthuilliers : > > Another situation where one may want to do this is if one needs to > > initialize a non-sparse array in a non-sequential order, > > Then use a dict. Ok, he has a dict. Now what? He needs a non-sparse array. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From andreengels at gmail.com Sat Nov 7 14:33:29 2009 From: andreengels at gmail.com (Andre Engels) Date: Sat, 7 Nov 2009 20:33:29 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <1257621919.4af5c99fcd1f6@mail.uh.cu> References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> Message-ID: <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez wrote: > > Quoting Bruno Desthuilliers : > >> > Another situation where one may want to do this is if one needs to >> > initialize a non-sparse array in a non-sequential order, >> >> Then use a dict. > > Ok, he has a dict. > > Now what? He needs a non-sparse array. Let d be your dict. Call the zeroeth place in your array d[0], the first d[1], the 10000th d[100000]. -- Andr? Engels, andreengels at gmail.com From tjreedy at udel.edu Sat Nov 7 15:31:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 15:31:02 -0500 Subject: is None or == None ? In-Reply-To: <03057af7$0$1290$c3e8da3@news.astraweb.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <03057af7$0$1290$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 06 Nov 2009 16:51:18 +0100, Marco Mariani wrote: > >> Using "x is y" with integers >> makes no sense and has no guaranteed behaviour AFAIK > > Of course it makes sense. `x is y` means *exactly the same thing* for > ints as it does with any other object: it tests for object identity. > That's all it does, and it does it perfectly. > > Python makes no promise whether x = 3; y = 3 will use the same object for > both x and y or not. That's an implementation detail. That's not a > problem with `is`, it is a problem with developers who make unjustified > assumptions. Which is to say, it normally makes no sense to write 'm is n' for m, n ints. The *exception* is when one is exploring implementation details, either to discover them or to test that they are as intended. So, last I looked, the test suite for ints makes such tests. If the implementation changes, the test should change also. The problem comes when newbies use 'is' without realizing that they are doing black-box exploration of otherwise irrelevant internals. (White-box exploration would be reading the code, which makes it plain what is going on ;-). Terry Jan Reedy From tjreedy at udel.edu Sat Nov 7 15:39:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 15:39:50 -0500 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: Saketh wrote: > On Nov 4, 5:28 pm, Alan Franzoni > My small effort to create a place for discussing Python seems to have > sparked a larger discussion than I had anticipated. My intent in > creating Pyfora is not to splinter the community or encroach upon > comp.lang.python users, but to create an alternative location where > users can discuss Python. If this offends or irritates anyone, please > accept my humble apologies. > > I understand that forums can be degenerate and uncivil, but my hope is > that with Pyfora, beginners will have a place to freely ask questions > in a genial environment. A large part of my computer upbringing was on > forums, and I wanted to share that experience with new Python users. I have no problem with efforts to create something new and different. I am curious whether you were or have become aware of http://www.python-forum.org/pythonforum/index.php It seems to already do what you intended to do, so if you want to continue, you might think of how to differentiate PyFora. Terry Jan Reedy From kyrie at uh.cu Sat Nov 7 15:40:02 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Sat, 07 Nov 2009 15:40:02 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: <1257626402.4af5db225e233@mail.uh.cu> Quoting Andre Engels : > On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez > wrote: > > > > Ok, he has a dict. > > > > Now what? He needs a non-sparse array. > > Let d be your dict. > > Call the zeroeth place in your array d[0], the first d[1], the 10000th > d[100000]. Following that reasoning, we could get rid of lists and arrays altogether. Here's why that wouldn't work: for x,y in zip(d,other): ... do something ... Yes, we could also ignore zip and just use range/xrange to iterate for the indices... Lists and dictionaries have different semantics. One thing is to argue that you shouldn't be thinking on pre-growing a list for performance reasons before being sure that it is a bottleneck, and a very different one is to argue that because one operation (__setitem__) is the same with both structures, we should not use lists for what may need, depending on the problem, list semantics. ?Have you ever tried to read list/matrix that you know it is not sparse, but you don't know the size, and it may not be in order? A "grow-able" array would just be the right thing to use - currently I have to settle with either hacking together my own grow-able array, or preloading the data into a dict, growing a list with the [0]*size trick, and updating that list. Not hard, not worthy of a PEP, but certainly not so easy to dismiss. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From partofthething at gmail.com Sat Nov 7 15:51:32 2009 From: partofthething at gmail.com (Nick Touran) Date: Sat, 7 Nov 2009 12:51:32 -0800 Subject: database handling In-Reply-To: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> References: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> Message-ID: <6de163580911071251i2f97213bx58fde9f88e734323@mail.gmail.com> The mysqldb module works well for me. It's available on sourceforge. Find some examples in the documentation here: http://mysql-python.sourceforge.net/MySQLdb.html#some-mysql-examples -Nick On Sat, Nov 7, 2009 at 11:24 AM, asit wrote: > I need some tutorial about python-mysql connectivity(database > handling). > > Somebody please help me !! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 7 16:00:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 16:00:20 -0500 Subject: imputil.py, is this a bug ? In-Reply-To: <4AF54413.9080502@gmail.com> References: <4AF49631.8090003@gmail.com> <4AF54413.9080502@gmail.com> Message-ID: Stef Mientki wrote: > Gabriel Genellina wrote: >> En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki >> escribi?: >> >>> I get an error compiling with pyjamas, in the standard module >>> imputil, _import_top_module >> >> Note that imputil is undocumented in 2.5, deprecated in 2.6 and >> definitively gone in 3.0 It was deprecated because it is buggy and unmaintainable. In 3.1 it has been replaced with the new written-in-Python importlib. That has also been added to the upcoming 2.7. Anyone using imputil and having problems with it should try the 2.7 version of importlib and see if it runs well-enough on earlier versions. Terry Jan Reedy From rami.chowdhury at gmail.com Sat Nov 7 16:09:39 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 7 Nov 2009 13:09:39 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> Message-ID: <200911071309.40437.rami.chowdhury@gmail.com> On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > I have a serious privileges problem that is making it impossible to serve > python pages on a CentOS server. It appears that nobody on the CentOS > discussion list has a solution to this problem. I'm desperate and hoping > someone on this list can help. > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > > Now, the file does exist: > > [root at 13gems global_solutions]# pwd > /var/www/html/angrynates.com/global_solutions > [root at 13gems global_solutions]# ls > .... > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > .... > and it serves just fine on another server, so there is no "premature end of > script headers". > > > Here's where it gets really weird. If I copy the code for index.py and > template.py which the former calls, and create files test.py and test2.py > and paste the code from the former files in those new files changing only > the import statement from "template" to "test2", the tests will resolve!! > Now, the ownership and mode are identical on all of them!! > > > [root at 13gems global_solutions]# ls -al | grep test.py > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > [root at 13gems global_solutions]# ls -al | grep test2.py > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > [root at 13gems global_solutions]# ls -al | grep index.py > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > [root at 13gems global_solutions]# ls -al | grep template.py > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > where test.py is identical to index.py (other than the necessary import) > and template is identical to test2.py > > > fixfiles relabel /var/www/html > # might just work > It didn't > > touch /.autorelabel > # and then reboot will relabel all copied files to the correct contexts for > the location > I rebooted apache with no luck > > or you could turn off SELinux and reboot > I did that and the following two solutions with no luck: > echo 0 >/selinux/enforce > > [root at 13gems ~]# cd /etc/ > [root at 13gems etc]# mv selinux/ selinux.BAK > [root at 13gems etc]# mkdir selinux > [root at 13gems etc]# echo 0>/selinux/enforce > > ...and the problem continues: > [root at 13gems etc]# tail /var/log/httpd/error_log > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file or > directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' > failed > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of > script headers: index.py > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > exist: /var/www/html/angrynates.com/robots.txt > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [root at 13gems etc]# > > Please help. > Victor > Can we see the output of 'ls -lZ' and 'fixfiles check' on those directories, and see what the Apache (httpd.conf or .htaccess) configuration is for them? ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From tjreedy at udel.edu Sat Nov 7 16:13:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 16:13:46 -0500 Subject: imputil.py, is this a bug ? In-Reply-To: References: <4AF49631.8090003@gmail.com> Message-ID: lkcl wrote: > On Nov 7, 2:20 am, "Gabriel Genellina" wrote: >> Yes, seems to be a bug. But given the current status of imputil, it's not >> likely to be fixed; certainly not in 2.5 which only gets security fixes >> now. > > well, that bug's not the only one. the other one that i found, which > i have been specifically ordered not to report Imputil has been deprecated and has in 3.1 and will-be in 2.7 replaced by importlib, written in Python. So reporting more bugs in imputil is rather useless noise. So either use your patched version or try shifting to the 2.7 importlib and see if it runs well enough on earlier versions. >(that or _any_ python bugs, of which there have been several discovered in the past eight > months), will have to wait until the python developers rescind that > order. Without seeing documentary proof, I am dubious that you have been ordered to not properly report bugs in supported, not deprecated, modules. If really so, post reports here and interested parties can try to verify and possibly report them themselves. I, for instance, would be interested in 3.1 bugs that do not require outside resources to verify. Terry Jan Reedy From vicente.soler at gmail.com Sat Nov 7 16:39:07 2009 From: vicente.soler at gmail.com (vsoler) Date: Sat, 7 Nov 2009 13:39:07 -0800 (PST) Subject: My own accounting python euler problem Message-ID: In the accounting department I am working for we are from time to time confronted to the following problem: A customer sends us a check for a given amount, but without specifying what invoices it cancels. It is up to us to find out which ones the payment corresponds to. For example, say that the customer has the following outstanding invoices: $300, $200, $50; and say that the check is for $250. This time it is clear, the customer is paying bills $200 and $50. However, let's now say that the outstanding invoices are $300, $200, $100 and that the check is for $300. In this case there are already two possibilities. The customer is paying the $300 invoice or the $200 and $100. In other words, there is more than one solution to the problem. My first question is: 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a check Ch=600 how can I print all the different combinations of invoices that the check is possibly cancelling 1.a. first approach using "brute force", that is, exploring all different combinations: every single invoice, all of 2-element tuples, 3-element tuples, etc... 1.b can all the solutions be found without exploring all possible combinations? some problems can be solved by discarding some invoices, for example those whose amounts are greater than the amount of the check. Any ideas? My second question is: 2. this time there are also credit notes outstanding, that is, invoices with negative amounts. For example, I=[500, 400, -100, 450, 200, 600, -200, 700] and a check Ch=600 2.a is the "brute force" method used in 1.a still applicable now that "I" contains negative values? 2.b same as 1.b. However, this time I can imagen that the number of invoices that can be discarded is a lot more reduced. I am a fan of Python, which I find very elegant, powerful and easy to develop with. I would like to find answers to the problems described above, partially because I am still learning python, and I would like to make use of it. Can anybody help? From jackdied at gmail.com Sat Nov 7 16:45:15 2009 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 7 Nov 2009 16:45:15 -0500 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, Nov 7, 2009 at 4:39 PM, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. [big snip] http://en.wikipedia.org/wiki/Knapsack_problem Unless your customers are giant defense contractors you should be able to brute force a solution. If they are so big that it doesn't take micro seconds to brute force a solution then you probably have more problems than just matching checks to invoices... -Jack From rpjday at crashcourse.ca Sat Nov 7 16:47:36 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 16:47:36 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: 1. given a list of invoives I=[500, 400, 450, > 200, 600, 700] and a check Ch=600 how can I print all the different > combinations of invoices that the check is possibly cancelling that sounds like the classic knapsack problem: http://www.itl.nist.gov/div897/sqg/dads/HTML/knapsackProblem.html it's NP-complete. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From victorsubervi at gmail.com Sat Nov 7 16:51:06 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 16:51:06 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911071309.40437.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> httpd.conf: ServerAdmin me at creative.vi DocumentRoot /var/www/html/angrynates.com ServerName angrynates.com Options +ExecCGI -IncludesNoExec Options +ExecCGI AllowOverride Options AllowOverride FileInfo #AddHandler mod_python .py #PythonHandler mod_python.publisher #PythonDebug On #ls -lZ drwxr-xr-x root root 1024 drwxr-xr-x root root 1132 drwxr-xr-x root root 1255 -rwxr-xr-x root root About_Us_frame.py -rwxr-xr-x root root About_Us.py -rwxr-xr-x root root ajax.cgi.txt -rwxr-xr-x root root ajax.html -rwxr-xr-x root root Catalog_frame.py -rwxr-xr-x root root Catalog.py -rwxr-xr-x root root cats_edit2.py -rwxr-xr-x root root cats_edit.py -rwxr-xr-x root root client2.py -rwxr-xr-x root root client_delete2.py -rwxr-xr-x root root client_delete.py -rwxr-xr-x root root client_edit2.py -rwxr-xr-x root root client_edit3.py -rwxr-xr-x root root client_edit.py -rwxr-xr-x root root client.py -rwxr-xr-x root root Contact_Us_frame.py -rwxr-xr-x root root Contact_Us.py -rwxr-xr-x root root credit_app.doc -rwxr-xr-x root root Credit Application DP Dist .doc -rwxr-xr-x root root Customer_Templates_frame.py -rwxr-xr-x root root Customer_Templates.py -rwxr-xr-x root root display_spreadsheet2.py -rwxr-xr-x root root display_spreadsheet.py -rwxr-xr-x root root EDDIE-Tool-1.0.0.tar.gz -rwxr-xr-x root root email.py -rwxr-xr-x root root error.log.0 -rwxr-xr-x root root favicon.gif -rwxr-xr-x root root favicon.ico -rwxr-xr-x root root Forms_frame.py -rwxr-xr-x root root Forms.py -rwxr-xr-x root root fw9.pdf -rwxr-xr-x root root getResolution.py -rw-r--r-- root root hello.py drwxr-xr-x root root images drwxr-xr-x root root images1024 drwxr-xr-x root root images1132 drwxr-xr-x root root images1255 drwxr-xr-x root root images-old -rwxr-xr-x root root index_frame.py -rwxr-xr-x root root index.html -rwxr-xr-x root root index.py -rwxr-xr-x root root login.py -rwxr-xr-x root root login.pyc -rwxr-xr-x root root Office_Supplies_frame.py -rwxr-xr-x root root Office_Supplies.py -rwxr-xr-x root root Paper_Plastics_frame.py -rwxr-xr-x root root Paper_Plastics.py -rwxr-xr-x root root particulars.py -rwxr-xr-x root root particulars.pyc drwxr-xr-x root root pics -rwxr-xr-x root root ping.py -rwxr-xr-x root root products2.py -rwxr-xr-x root root products3.py -rwxr-xr-x root root products_cats.py -rwxr-xr-x root root products_delete2.py -rwxr-xr-x root root products_delete3.py -rwxr-xr-x root root products_delete.py -rwxr-xr-x root root products_edit2.py -rwxr-xr-x root root products_edit3.py -rwxr-xr-x root root products_edit.py -rwxr-xr-x root root products_items.py -rwxr-xr-x root root products_move2.py -rwxr-xr-x root root products_move3.py -rwxr-xr-x root root products_move.py -rwxr-xr-x root root salesperson2.py -rwxr-xr-x root root salesperson_delete2.py -rwxr-xr-x root root salesperson_delete.py -rwxr-xr-x root root salesperson_edit2.py -rwxr-xr-x root root salesperson_edit3.py -rwxr-xr-x root root salesperson_edit.py -rwxr-xr-x root root salesperson.py drwxr-xr-x root root simplemail -rwxr-xr-x root root spreadsheet2.py -rwxr-xr-x root root spreadsheet3.py -rwxr-xr-x root root spreadsheet4.py -rwxr-xr-x root root spreadsheet_delete2.py -rwxr-xr-x root root spreadsheet_delete.py -rwxr-xr-x root root spreadsheet_delete_rows2.py -rwxr-xr-x root root spreadsheet_delete_rows3.py -rwxr-xr-x root root spreadsheet_delete_rows.py -rwxr-xr-x root root spreadsheet_edit2.py -rwxr-xr-x root root spreadsheet_edit3.py -rwxr-xr-x root root spreadsheet_edit.py -rwxr-xr-x root root spreadsheet.py drwxr-xr-x root root spreadsheets -rwxr-xr-x root root start.py -rwxr-xr-x root root stuff.txt -rwxr-xr-x root root templateFrame.py -rwxr-xr-x root root templateFrame.pyc -rwxr-xr-x root root template.py -rwxrwxrwx root root template.pyc -rwxr-xr-x root root test2.py -rw-r--r-- root root test2.pyc -rwxr-xr-x root root test.html -rwxr-xr-x root root test.py -rwxr-xr-x root root tsd_sales_tax_dealer_or_purchaser_exemption_certificate_st5.pdf On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury wrote: > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > I have a serious privileges problem that is making it impossible to serve > > python pages on a CentOS server. It appears that nobody on the CentOS > > discussion list has a solution to this problem. I'm desperate and hoping > > someone on this list can help. > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > > > Now, the file does exist: > > > > [root at 13gems global_solutions]# pwd > > /var/www/html/angrynates.com/global_solutions > > [root at 13gems global_solutions]# ls > > .... > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > .... > > and it serves just fine on another server, so there is no "premature end > of > > script headers". > > > > > > Here's where it gets really weird. If I copy the code for index.py and > > template.py which the former calls, and create files test.py and test2.py > > and paste the code from the former files in those new files changing only > > the import statement from "template" to "test2", the tests will resolve!! > > Now, the ownership and mode are identical on all of them!! > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > [root at 13gems global_solutions]# ls -al | grep test2.py > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > [root at 13gems global_solutions]# ls -al | grep index.py > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > [root at 13gems global_solutions]# ls -al | grep template.py > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > where test.py is identical to index.py (other than the necessary import) > > and template is identical to test2.py > > > > > > fixfiles relabel /var/www/html > > # might just work > > It didn't > > > > touch /.autorelabel > > # and then reboot will relabel all copied files to the correct contexts > for > > the location > > I rebooted apache with no luck > > > > or you could turn off SELinux and reboot > > I did that and the following two solutions with no luck: > > echo 0 >/selinux/enforce > > > > [root at 13gems ~]# cd /etc/ > > [root at 13gems etc]# mv selinux/ selinux.BAK > > [root at 13gems etc]# mkdir selinux > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > ...and the problem continues: > > [root at 13gems etc]# tail /var/log/httpd/error_log > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file > or > > directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' > > failed > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of > > script headers: index.py > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > > exist: /var/www/html/angrynates.com/robots.txt > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > > exist: /var/www/html/angrynates.com/favicon.ico > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > > exist: /var/www/html/angrynates.com/favicon.ico > > [root at 13gems etc]# > > > > Please help. > > Victor > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > directories, > and see what the Apache (httpd.conf or .htaccess) configuration is for > them? > > ---- > Rami Chowdhury > "Passion is inversely proportional to the amount of real information > available." -- Benford's Law of Controversy > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 17:02:53 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 23:02:53 +0100 Subject: exception due to NoneType In-Reply-To: References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <4af5fc1f$0$400$426a74cc@news.free.fr> asit a ?crit : > On Nov 7, 10:36 pm, Bruno Desthuilliers > wrote: >> asit a ?crit : >> >>> In my program I want to catch exception which is caused by accessing >>> NoneType object. >>> Can anyone suggest me how this can be done ?? >> Not without the minimal working code exposing your problem, or the full >> traceback you got. Merely "accessing NoneType object" doesn't by itself >> raise any exception... I suspect you get the None object where you >> expected something else and try to access an attribute of this >> 'something else', and ends up getting an AttributeError, but there are >> other possible scenarii that might fit your (very poor) description of >> the problem, so no way too help you without more informations. As a >> general rule, remember that the traceback is actually meant to *help* >> finding out what went wring. > > I could have described the error, but the problem is that it's > dependent of a third party library.. This more often than not translates to "dependent of a wrong use of a 3rd part library". > Let me write the code here... > > import twitter > > api = twitter.Api('asitdhal','swordfish') I hope this is not your actual login. > users = api.GetFriends() > for s in users: > print > print "##########################################" > try: > print "user id : " + str(s.id) Please learn to use print and string formatting. Here are two ways to get rid of the need to use str(): 1/ print "user id : %s" % s.id 2/ print "user id : ", s.id > print "user name : " + s.name > print "user location : " + s.location > print "user description : " + s.description > print "user profile image url : " + s.profile_image_url > print "user url : " + s.url > print "user status : " + str(s.status) > except TypeError: > pass Silently passing exception is 99.999 out of 100 a very stupid thing to do. > > look at the except TypeError. Yes, I've seen it. It's stupid, and actually make debugging harder. Any statement in this try block could raise a TypeError if the looked up attribute of 's' is not a string. Python is NOT php, and will not happily adds apples and parrots - you can only concatenate strings with strings, not with ints or None or whatever... > This is supposed to catch only exception > thrown by NoneType. Please get your facts straight. 1/ The NoneType doesn't "throw" (the appropriate python term is "raise") any exception by itself 2/ this except clause will catch any TypeError. Try this: try: x = "aaa" + 42 except TypeError, e: print "This has nothing to do with NoneType" > please help me. Help yourself and read the FineManual. Then make appropriate use of string formatting (your best friend for simple formatted outputs) instead of useless string concatenations. From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 17:04:34 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 23:04:34 +0100 Subject: database handling In-Reply-To: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> References: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> Message-ID: <4af5fc83$0$400$426a74cc@news.free.fr> asit a ?crit : > I need some tutorial about python-mysql connectivity(database > handling). > > Somebody please help me !! You didn't search very far, did you ? http://wiki.python.org/moin/DatabaseProgramming/ From rpjday at crashcourse.ca Sat Nov 7 17:13:11 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 17:13:11 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > check Ch=600 > how can I print all the different combinations of invoices that the > check is possibly cancelling by the way, there's a bit more to it than just seeing if you can match the cheque amount exactly. some python solutions are here: http://rosettacode.org/wiki/Knapsack_Problem and a general solution allows you to place different "values" on which items you pack into your knapsack. say a customer has outstanding invoices for 200, 400 and 600, and you get a cheque for 600. what do you apply that against? the single invoice for 600, or the two for 200 and 400? that depends. if all invoices have the same "value", it won't matter. but if the invoice for 600 just went out, while the two others are just about to become, say, overdue so that a penalty is about to be applied, your customer would probably *really* appreciate it if you applied that cheque to the older invoices. in general, then, you can not only see what matches exactly but, for the sake of your customer, you can give higher value to paying off older invoices. that's how the general knapsack problem works. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From deets at nospam.web.de Sat Nov 7 17:16:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 07 Nov 2009 23:16:28 +0100 Subject: exception due to NoneType In-Reply-To: References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <7lm9tsF3ds91uU1@mid.uni-berlin.de> > api = twitter.Api('asitdhal','swordfish') You just gave the world the account-information to your twitter-account. You'd rather change these asap, or somebody hijacks your account... Diez From tjreedy at udel.edu Sat Nov 7 17:19:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 17:19:20 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <03057b64$0$1290$c3e8da3@news.astraweb.com> References: <03057b64$0$1290$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 06 Nov 2009 18:46:33 -0800, gil_johnson wrote: > >> I don't have the code with me, but for huge arrays, I have used >> something like: >> >>>>> arr[0] = initializer >>>>> for i in range N: >>>>> arr.extend(arr) >> This doubles the array every time through the loop, and you can add the >> powers of 2 to get the desired result. Gil > > Why is it better to grow the list piecemeal instead of just allocating a > list the size you want in one go? It isn't. > arr = [x]*size_wanted Is what I would do. From sturlamolden at yahoo.no Sat Nov 7 17:22:28 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:22:28 -0800 (PST) Subject: is None or == None ? References: Message-ID: On 6 Nov, 14:35, "Alf P. Steinbach" wrote: > As I understand it, 'is' will always work and will always be efficient (it just > checks the variable's type), while '==' can depend on the implementation of > equality checking for the other operand's class. '==' checks for logical equality. 'is' checks for object identity. None is a singleton of type NoneType. Since None evaluates to True only when compared against itself, it is safe to use both operators. From ivan.illarionov at gmail.com Sat Nov 7 17:24:15 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Sat, 7 Nov 2009 14:24:15 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <622d92f9-b930-443c-82cd-0773780b1320@t2g2000yqn.googlegroups.com> On Nov 6, 3:12?pm, kj wrote: > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? It is the most efficient SAFE way to achieve this result. In fact, there IS the more efficient way, but it's dangerous, unsafe, unpythonic and plain evil: >>> import ctypes >>> ctypes.pythonapi.PyList_New.restype = ctypes.py_object >>> ctypes.pythonapi.PyList_New(100) -- Ivan From sturlamolden at yahoo.no Sat Nov 7 17:27:05 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:27:05 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On 6 Nov, 18:28, "Alf P. Steinbach" wrote: > Dynamic allocation isn't hare-brained, but doing it for every stored integer > value outside a very small range is, because dynamic allocation is (relatively > speaking, in the context of integer operations) very costly even with a > (relatively speaking, in the context of general dynamic allocation) very > efficient small-objects allocator - here talking order(s) of magnitude. When it matters, we use NumPy and/or Cython. From henk at pa3btl.demon.nl Sat Nov 7 17:27:15 2009 From: henk at pa3btl.demon.nl (van Asselt) Date: Sat, 7 Nov 2009 23:27:15 +0100 Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: <4af5f44c$0$83239$e4fe514c@news.xs4all.nl> Hello Colin, I have been using 'cmdloop.py' from Crutcher Dunnavant in a few programs.... See http://py-cmdloop.googlecode.com/svn/trunk/cmdloop.py Regards, Henk --------------------- "Collin D" wrote in message news:94dbc92b-0682-4995-b358-0c615c95a27a at x6g2000prc.googlegroups.com... > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. > > Thanks a lot, > Collin D From wbrehaut at mcsnet.ca Sat Nov 7 17:43:13 2009 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Sat, 07 Nov 2009 15:43:13 -0700 Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <9vtbf510qrsl09conn773hal8jo7bttpa0@4ax.com> On Sat, 7 Nov 2009 19:34:47 +0100, Andre Engels wrote: >On Sat, Nov 7, 2009 at 6:40 PM, Mensanator wrote: > >>> Tongue in cheek solution: >>> >>> import urllib2 >>> >>> url = 'http://primes.utm.edu/lists/small/10000.txt' >>> primes = [] >>> for line in urllib2.urlopen(url).read().splitlines(): >>> ? ? values = line.split() >>> ? ? if len(values) == 10: >>> ? ? ? ? primes.extend(values) >>> print primes[1000-1] >> >> Nice, but you can do better. >> >>>>> import gmpy >>>>> n = 1 >>>>> for i in xrange(1000): >> ? ? ? ?n = gmpy.next_prime(n) >>>>> print n >> 7919 > >With the help of the solutions given so far, I can do even better than that: > >n = 7919 >print n >>> 7919 7919 ? From ubershmekel at gmail.com Sat Nov 7 17:45:31 2009 From: ubershmekel at gmail.com (Yuv) Date: Sat, 7 Nov 2009 14:45:31 -0800 (PST) Subject: feedback on function introspection in argparse Message-ID: This was posted to the argparse mailing list by Steven Bethard and now we'd like some feedback from comp.lang.python. We now have a branch[5] of argparse that supports an ``argparse.run`` function[6] which does some function introspection to build a command line parser from a function definition: ------------------------------ prog.py ------------------------------ import argparse def func(foo, bar, baz): """A function that foo's a bar with a baz. foo - The foo bar - The bar to be foo'd baz - The baz with which to foo. """ print foo, bar, baz if __name__ == '__main__': argparse.run(func) ------------------------------ cmdline ------------------------------ $ prog.py -h usage: prog.py [-h] foo bar baz A function that foo's a bar with a baz. positional arguments: foo The foo bar The bar to be foo'd baz The baz with which to foo. optional arguments: -h, --help show this help message and exit ---------------------------------------------------------------------- I'd love to hear some feedback on this. At the moment, the code can introspect argument names, types from defaults, types from annotations (in Python 3), help messages from docstrings, and knows how to convert multiple functions into subcommands. The code's compatible and tested on python 2.3 - 3.1. There are probably more things we could support [7], but I'd like to get some feedback on what we have so far. Some specific questions: * Do you think this is worth including in argparse? * Would you use the current ``argparse.run`` API in your own code? * If you wouldn't use it as-is, what additional features/modifications would you require? --Steve and Yuv PS: The authors of pyopt[1], opster[2], optfunc[3] and simpleopt[4] were CC'd, in the hopes that we can converge to a common API, but they didn't reply other than the pyopt guy (me) who wrote the patch. [0] SVN branch at: http://argparse.googlecode.com/svn/branches/function-arguments/ [1] http://code.google.com/p/pyopt/ [2] http://hg.piranha.org.ua/opster/ [3] http://github.com/simonw/optfunc/ [4] http://pypi.python.org/pypi/simpleopt/ [5] http://argparse.googlecode.com/svn/branches/function-arguments/ [6] The branch also adds ``ArgumentParser.add_function_arguments`` which ``argparse.run`` is built on top of. This method allows you to match function based arguments with other arguments as necessary, e.g.:: def items(n=10): return range(n) parser = argparse.ArgumentParser() parser.add_function_arguments(items) parser.add_argument('output_file') args = parser.parse_args() with open(args.output_file, 'w') as output_file: for item in args.items(): output_file.write("%d\n" % item) [7] I can imagine allowing the introspected values to be overridden with decorators, though it may be out of the scope of this patch. e.g.:: @annotate( dirname=positional(help='...'), listen=optional('-l', default='localhost', help='ip to listen on'), port=optional('-p', default=8000, help='port to listen on'), ...) def func(dirname, listen='localhost', port=8000, ...): From rami.chowdhury at gmail.com Sat Nov 7 17:49:28 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 7 Nov 2009 14:49:28 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> Message-ID: <200911071449.28713.rami.chowdhury@gmail.com> On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > httpd.conf: > > > ServerAdmin me at creative.vi > DocumentRoot /var/www/html/angrynates.com > ServerName angrynates.com > Options +ExecCGI -IncludesNoExec > You may want to change this to: If you want regular expression syntax, I would advise using the syntax or > #ls -lZ > drwxr-xr-x root root 1024 > drwxr-xr-x root root 1132 > drwxr-xr-x root root 1255 [snip] It looks like you don't have *any* SELinux context information; if SELinux is on, this will cause problems. Try using the 'restorecon' command to put the defaults in place, and consider using 'chcon' to change the security context to an appropriate one (I believe you want something like 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > I have a serious privileges problem that is making it impossible to > > > serve python pages on a CentOS server. It appears that nobody on the > > > CentOS discussion list has a solution to this problem. I'm desperate > > > and hoping someone on this list can help. > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > Now, the file does exist: > > > > > > [root at 13gems global_solutions]# pwd > > > /var/www/html/angrynates.com/global_solutions > > > [root at 13gems global_solutions]# ls > > > .... > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > .... > > > and it serves just fine on another server, so there is no "premature > > > end > > > > of > > > > > script headers". > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py and > > > template.py which the former calls, and create files test.py and > > > test2.py and paste the code from the former files in those new files > > > changing only the import statement from "template" to "test2", the > > > tests will resolve!! Now, the ownership and mode are identical on all > > > of them!! > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > where test.py is identical to index.py (other than the necessary > > > import) and template is identical to test2.py > > > > > > > > > fixfiles relabel /var/www/html > > > # might just work > > > It didn't > > > > > > touch /.autorelabel > > > # and then reboot will relabel all copied files to the correct contexts > > > > for > > > > > the location > > > I rebooted apache with no luck > > > > > > or you could turn off SELinux and reboot > > > I did that and the following two solutions with no luck: > > > echo 0 >/selinux/enforce > > > > > > [root at 13gems ~]# cd /etc/ > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > [root at 13gems etc]# mkdir selinux > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > ...and the problem continues: > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > file > > > > or > > > > > directory: exec of '/var/www/html/ > > > > angrynates.com/global_solutions/index.py' > > > > > failed > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end > > > of script headers: index.py > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > > > exist: /var/www/html/angrynates.com/robots.txt > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > > > exist: /var/www/html/angrynates.com/favicon.ico > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > > > exist: /var/www/html/angrynates.com/favicon.ico > > > [root at 13gems etc]# > > > > > > Please help. > > > Victor > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > directories, > > and see what the Apache (httpd.conf or .htaccess) configuration is for > > them? > > > > ---- > > Rami Chowdhury > > "Passion is inversely proportional to the amount of real information > > available." -- Benford's Law of Controversy > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > ---- Rami Chowdhury "Strangers are just friends who haven't had enough gin." -- Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From sturlamolden at yahoo.no Sat Nov 7 17:54:34 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:54:34 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On 6 Nov, 17:54, "Alf P. Steinbach" wrote: > But wow. That's pretty hare-brained: dynamic allocation for every stored value > outside the cache range, needless extra indirection for every operation. First, integers are not used the same way in Python as they are in C+ +. E.g. you typically don't iterate over them in a for loop, but rather iterate on the container itself. Second, if you need an array of integers or floats, that is usually not done with a list: you would use numpy.ndarray or array.array, and values are stored compactly. A Python list is a list, it is not an array. If you were to put integers in dynamic data structures in other languages (Java, C++), you would use dynamic allocation as well. Yes a list is implemented as an array of pointers, amortized to O(1) for appends, but that is an implementation detail. Python is not the only language that works like this. There are also MATLAB and Lisp. I know you have a strong background in C++, but when you are using Python you must unlearn that way of thinking. Finally: if none of these helps, we can always resort to Cython. In 99% of cases where integers are bottlenecks in Python, it is indicative of bad style. We very often see this from people coming form C++ and Java background, and subsequent claims that "Python is slow". Python is not an untyped Java. If you use it as such, it will hurt. Languages like Python, Perl, Common Lisp, and MATLAB require a different mindset from the programmer. From debatem1 at gmail.com Sat Nov 7 18:05:37 2009 From: debatem1 at gmail.com (geremy condra) Date: Sat, 7 Nov 2009 18:05:37 -0500 Subject: feedback on function introspection in argparse In-Reply-To: References: Message-ID: On Sat, Nov 7, 2009 at 5:45 PM, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some function introspection to build a command line parser from a > function definition: > > ------------------------------ prog.py ------------------------------ > import argparse > > def func(foo, bar, baz): > ? """A function that foo's a bar with a baz. > ? foo - The foo > ? bar - The bar to be foo'd > ? baz - The baz with which to foo. > ? """ > ? print foo, bar, baz > > if __name__ == '__main__': > ? argparse.run(func) > ------------------------------ cmdline ------------------------------ > $ prog.py -h > usage: prog.py [-h] foo bar baz > > A function that foo's a bar with a baz. > > positional arguments: > ?foo ? ? ? ? The foo > ?bar ? ? ? ? The bar to be foo'd > ?baz ? ? ? ? The baz with which to foo. > > optional arguments: > ?-h, --help ?show this help message and exit > ---------------------------------------------------------------------- Looks great! Very handy. > I'd love to hear some feedback on this. At the moment, the code can > introspect argument names, types from defaults, types from annotations > (in Python 3), help messages from docstrings, and knows how to convert > multiple functions into subcommands. The code's compatible and tested > on python 2.3 - 3.1. There are probably more things we could support > [7], but I'd like to get some feedback on what we have so > far. Some specific questions: > > * Do you think this is worth including in argparse? > * Would you use the current ``argparse.run`` API in your own code? yes. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 18:09:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 23:09:58 GMT Subject: is None or == None ? References: Message-ID: <0305ec85$0$1371$c3e8da3@news.astraweb.com> On Sat, 07 Nov 2009 14:22:28 -0800, sturlamolden wrote: > On 6 Nov, 14:35, "Alf P. Steinbach" wrote: > >> As I understand it, 'is' will always work and will always be efficient >> (it just checks the variable's type), while '==' can depend on the >> implementation of equality checking for the other operand's class. > > '==' checks for logical equality. 'is' checks for object identity. So far so good, although technically == merely calls __eq__, which can be over-ridden to do (nearly) anything you like: >>> class Funny(object): ... def __eq__(self, other): ... return self.payload + other ... >>> f = Funny() >>> f.payload = 5 >>> f == 10 15 > None is a singleton of type NoneType. Since None evaluates to True only > when compared against itself, That's wrong. None never evaluates to True, it always evaluates as None, in the same way that 42 evaluates as 42 and [1,2,3] evaluates as [1,2,3]. Python literals evaluate as themselves, always. Perhaps you mean that *comparisons* of None evaluate to True only if both operands are None. That's incorrect too: >>> None > None False You have to specify the comparison. It would be a pretty strange language if both None==None and None!=None returned True. > it is safe to use both operators. Only if you want unexpected results if somebody passes the wrong sort of object to your code. >>> class NoneProxy: ... def __eq__(self, other): ... if other is None: return True ... return False ... >>> o = NoneProxy() >>> o is None False >>> o == None True You should use == *only* if you want to test for objects which are equal to None, *whatever that object may be*, and is if you want to test for None itself. -- Steven From ben+python at benfinney.id.au Sat Nov 7 18:14:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 10:14:31 +1100 Subject: exception due to NoneType References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <871vka6i7c.fsf@benfinney.id.au> asit writes: > for s in users: > print > print "##########################################" > try: > print "user id : " + str(s.id) > print "user name : " + s.name > print "user location : " + s.location > print "user description : " + s.description > print "user profile image url : " + s.profile_image_url > print "user url : " + s.url > print "user status : " + str(s.status) > except TypeError: > pass Why are you catching TypeError, only to discard it? Ignoring an error doesn't make it go away. The above code should rather use string formatting to interpolate the values you want into a string for output:: import textwrap for user in users: print textwrap.dedent(""" ########################################## user id: %(id)s user name: %(name)s user location: %(location)s user description: %(description)s user profile image url: %(profile_image_url)s user url: %(url)s user status: %(status)s """) % vars(user) -- \ ?My classmates would copulate with anything that moved, but I | `\ never saw any reason to limit myself.? ?Emo Philips | _o__) | Ben Finney From mensanator at aol.com Sat Nov 7 18:22:26 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 15:22:26 -0800 (PST) Subject: Microsoft research on code quality References: Message-ID: <76d705f7-457d-41a1-90d0-714d860da735@r5g2000yqb.googlegroups.com> On Nov 6, 3:15?pm, a... at pythoncraft.com (Aahz) wrote: > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > [on old computer technologies and programmers] ?"Fancy tail fins on a > brand new '59 Cadillac didn't mean throwing out a whole generation of > mechanics who started with model As." ?--Andrew Dalke Microsoft has more to answer for for the fuckups they install deliberately than for the bugs that get in accidentally. From pavlovevidence at gmail.com Sat Nov 7 18:33:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 15:33:40 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: On Nov 7, 2:45?pm, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some function introspection to build a command line parser from a > function definition: > > ------------------------------ prog.py ------------------------------ > import argparse > > def func(foo, bar, baz): > ? ?"""A function that foo's a bar with a baz. > ? ?foo - The foo > ? ?bar - The bar to be foo'd > ? ?baz - The baz with which to foo. > ? ?""" > ? ?print foo, bar, baz > > if __name__ == '__main__': > ? ?argparse.run(func) > ------------------------------ cmdline ------------------------------ > $ prog.py -h > usage: prog.py [-h] foo bar baz > > A function that foo's a bar with a baz. > > positional arguments: > ?foo ? ? ? ? The foo > ?bar ? ? ? ? The bar to be foo'd > ?baz ? ? ? ? The baz with which to foo. > > optional arguments: > ?-h, --help ?show this help message and exit > ---------------------------------------------------------------------- > > I'd love to hear some feedback on this. At the moment, the code can > introspect argument names, types from defaults, types from annotations > (in Python 3), help messages from docstrings, and knows how to convert > multiple functions into subcommands. The code's compatible and tested > on python 2.3 - 3.1. There are probably more things we could support > [7], but I'd like to get some feedback on what we have so > far. Some specific questions: > > * Do you think this is worth including in argparse? > * Would you use the current ``argparse.run`` API in your own code? > * If you wouldn't use it as-is, what additional features/modifications > would you require? Looks quite useful. I am not sure I like the name "run", seems to short and innocent for a function this magical. Is the docstring expected to be formatted according to some convention? I don't recognize a docstring convention in the example, but then I don't bother with them much in my own code, that's why I ask. Carl Banks From ubershmekel at gmail.com Sat Nov 7 18:44:33 2009 From: ubershmekel at gmail.com (Yuv) Date: Sat, 7 Nov 2009 15:44:33 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: On Nov 8, 1:33?am, Carl Banks wrote: > Is the docstring expected to be formatted according to some > convention? Yes it does, we parse the docstring as explained in argparse.py: def _parse_docstring(function): """Parses a function's docstring for a description of the function and for help on the individual parameters. The parsing algorithm currently looks for lines that start with a parameter name immediately followed by any amount of whitespace, hyphens or colons. The rest of the line following the colon/hyphen/whitespace is the help. Keyword Arguments: function - the function whose docstring is parsed. Returns a (description, help_dict) tuple: description - all text before the first documented parameter help_dict - a dictionary mapping parameter names to their help strings """ We tried to comply to PEP 257 and we're open to suggestions on this. --yuv From no.email at please.post Sat Nov 7 19:23:18 2009 From: no.email at please.post (kj) Date: Sun, 8 Nov 2009 00:23:18 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: In Luis Alberto Zarrabeitia Gomez writes: >Quoting Andre Engels : >> On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez >> wrote: >> > >> > Ok, he has a dict. >> > >> > Now what? He needs a non-sparse array. >> >> Let d be your dict. >> >> Call the zeroeth place in your array d[0], the first d[1], the 10000th >> d[100000]. >Following that reasoning, we could get rid of lists and arrays altogether. >Here's why that wouldn't work: >for x,y in zip(d,other): > ... do something ... >Yes, we could also ignore zip and just use range/xrange to iterate for the >indices... >Lists and dictionaries have different semantics. One thing is to argue that you >shouldn't be thinking on pre-growing a list for performance reasons before being >sure that it is a bottleneck, and a very different one is to argue that because >one operation (__setitem__) is the same with both structures, we should not use >lists for what may need, depending on the problem, list semantics. >?Have you ever tried to read list/matrix that you know it is not sparse, but you >don't know the size, and it may not be in order? A "grow-able" array would just >be the right thing to use - currently I have to settle with either hacking >together my own grow-able array, or preloading the data into a dict, growing a >list with the [0]*size trick, and updating that list. Not hard, not worthy of a >PEP, but certainly not so easy to dismiss. Thanks. Well said. Saludos, kynn From fordhaivat at gmail.com Sat Nov 7 20:00:18 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 20:00:18 -0500 Subject: Spam Bot, broken pipe Message-ID: I have a irc spam bot (only testing on my channel :P ) whose main loop is the following: privc="PRIVMSG "+self.channel while True: self.sock.send(privc=" :SPAM SPAM SPAM!"); time.sleep(2); And it gives an error "Broken Pipe". How can I fix this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Sat Nov 7 20:03:37 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:03:37 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <28737d4e-c83b-403a-948a-abf0a97d03aa@g27g2000yqn.googlegroups.com> On 6 Nov, 13:12, kj wrote: > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? Yes, but why would you want to? Appending to a Python list has amortized O(1) complexity. I am not sure about Perl, but in MATLAB arrays are preallocated because resize has complexity O(n), instead of amortized O(1). You don't need to worry about that in Python. Python lists are resized with empty slots at the end, in proportion to the size of the list. On average, this has the same complexity as pre- allocation. From sturlamolden at yahoo.no Sat Nov 7 20:05:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:05:53 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> On 7 Nov, 03:46, gil_johnson wrote:> > I don't have the code with me, but for huge arrays, I have used > something like: > > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil You should really use append instead of extend. The above code is O (N**2), with append it becomes O(N) on average. From pavlovevidence at gmail.com Sat Nov 7 20:08:56 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 17:08:56 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: <2d2e7306-739c-46d5-8432-1bbeb538442e@g1g2000pra.googlegroups.com> On Nov 7, 3:44?pm, Yuv wrote: > On Nov 8, 1:33?am, Carl Banks wrote: > > > Is the docstring expected to be formatted according to some > > convention? [snippage] > We tried to comply to PEP 257 and we're open to suggestions on this. Ah, so we finally get to the answer: the convention is PEP 257. :) Carl Banks From sturlamolden at yahoo.no Sat Nov 7 20:13:07 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:13:07 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On 6 Nov, 22:03, kj wrote: > As I said, this is considered an optimization, at least in Perl, > because it lets the interpreter allocate all the required memory > in one fell swoop, instead of having to reallocate it repeatedly > as the array grows. Python does not need to reallocate repeatedly as a list grows. That is why it's called a 'list' and not an array. There will be empty slots at the end of a list you can append to, without reallocating. When the list is resized, it is reallocated with even more of these. Thus the need to reallocate becomes more and more rare as the list grows, and on average the complexity of appending is just O(1). From pengyu.ut at gmail.com Sat Nov 7 20:17:09 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 19:17:09 -0600 Subject: How convert string '1e7' to an integer? Message-ID: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> It seems that int() does not convert '1e7'. I'm wondering what function to use to convert '1e7' to an integer? >>> int('1e7') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1e7' From pavlovevidence at gmail.com Sat Nov 7 20:18:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 17:18:38 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> Message-ID: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> On Nov 7, 5:05?pm, sturlamolden wrote: > On 7 Nov, 03:46, gil_johnson wrote:> > > > I don't have the code with me, but for huge arrays, I have used > > something like: > > > >>> arr[0] = initializer > > >>> for i in range N: > > >>> ? ? ?arr.extend(arr) > > > This doubles the array every time through the loop, and you can add > > the powers of 2 to get the desired result. > > Gil > > You should really use append instead of extend. The above code is O > (N**2), with append it becomes O(N) on average. I think the top one is O(N log N), and I'm suspicious that it's even possible to grow a list in less than O(N log N) time without knowing the final size in advance. Citation? Futhermore why would it matter to use extend instead of append; I'd assume extend uses the same growth algorithm. (Although in this case since the extend doubles the size of the list it most likely reallocates after each call.) [None]*N is linear time and is better than growing the list using append or extend. Carl Banks From hniksic at xemacs.org Sat Nov 7 20:25:42 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 08 Nov 2009 02:25:42 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> Message-ID: <87my2xhko9.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > Speedup would likely be more realistic with normal implementation (not > fiddling with bit-fields and stuff) I'm not sure I understand this. How would you implement tagged integers without encoding type information in bits of the pointer value? From exarkun at twistedmatrix.com Sat Nov 7 20:32:30 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 08 Nov 2009 01:32:30 -0000 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> Message-ID: <20091108013230.3229.565954700.divmod.xquotient.346@localhost.localdomain> On 01:18 am, pavlovevidence at gmail.com wrote: >On Nov 7, 5:05?pm, sturlamolden wrote: >>On 7 Nov, 03:46, gil_johnson wrote:> >> >> > I don't have the code with me, but for huge arrays, I have used >> > something like: >> >> > >>> arr[0] = initializer >> > >>> for i in range N: >> > >>> ? ? ?arr.extend(arr) >> >> > This doubles the array every time through the loop, and you can add >> > the powers of 2 to get the desired result. >> > Gil >> >>You should really use append instead of extend. The above code is O >>(N**2), with append it becomes O(N) on average. > >I think the top one is O(N log N), and I'm suspicious that it's even >possible to grow a list in less than O(N log N) time without knowing >the final size in advance. Citation? Futhermore why would it matter >to use extend instead of append; I'd assume extend uses the same >growth algorithm. (Although in this case since the extend doubles the >size of the list it most likely reallocates after each call.) > >[None]*N is linear time and is better than growing the list using >append or extend. The wikipedia page for http://en.wikipedia.org/wiki/Amortized_analysis conveniently uses exactly this example to explain the concept of amortized costs. Jean-Paul From mensanator at aol.com Sat Nov 7 20:41:03 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 17:41:03 -0800 (PST) Subject: How convert string '1e7' to an integer? References: Message-ID: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> On Nov 7, 7:17?pm, Peng Yu wrote: > It seems that int() does not convert '1e7'. Because 'e' isn't a valid character in base 10. > I'm wondering what > function to use to convert '1e7' to an integer? > > >>> int('1e7') >>> int(1e7) 10000000 > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' From mad.mick at gmx.de Sat Nov 7 20:42:21 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 02:42:21 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: Message-ID: Peng Yu wrote: > It seems that int() does not convert '1e7'. It seems it does, though: >>> int('1e7', base=16) 487 Mick. From python at mrabarnett.plus.com Sat Nov 7 20:45:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 01:45:57 +0000 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: <4AF622D5.7090301@mrabarnett.plus.com> Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? > >>>> int('1e7') > Traceback (most recent call last): > File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' In Python the e-form indicates a float, as does the presence of a decimal point, but you can convert to float and then to int: >>> int(float('1e7')) 10000000 From ben+python at benfinney.id.au Sat Nov 7 20:49:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 12:49:48 +1100 Subject: How convert string '1e7' to an integer? References: Message-ID: <87d43t6b0j.fsf@benfinney.id.au> Mick Krippendorf writes: > Peng Yu wrote: > > It seems that int() does not convert '1e7'. > It seems it does, though: > > >>> int('1e7', base=16) > 487 Well played, sir. -- \ ?It is wrong to think that the task of physics is to find out | `\ how nature *is*. Physics concerns what we can *say* about | _o__) nature?? ?Niels Bohr | Ben Finney From gherron at islandtraining.com Sat Nov 7 20:50:53 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 07 Nov 2009 17:50:53 -0800 Subject: How convert string '1e7' to an integer? In-Reply-To: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: <4AF623FD.7060306@islandtraining.com> Mensanator wrote: > On Nov 7, 7:17 pm, Peng Yu wrote: > >> It seems that int() does not convert '1e7'. >> > > Because 'e' isn't a valid character in base 10. > But 1e7 is a valid float, so this works: >>> int(float('1e7')) 10000000 That has a problem though, if you surpass the ability of a float: >>> int(float('1e20')) 100000000000000000000L >>> int(float('1e30')) 1000000000000000019884624838656L Gary Herron > >> I'm wondering what >> function to use to convert '1e7' to an integer? >> >> >>>>> int('1e7') >>>>> > > >>>> int(1e7) >>>> > 10000000 > > > >> Traceback (most recent call last): >> File "", line 1, in >> ValueError: invalid literal for int() with base 10: '1e7' >> > > From benjamin.kaplan at case.edu Sat Nov 7 20:52:37 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 7 Nov 2009 20:52:37 -0500 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? > >>>> int('1e7') > Traceback (most recent call last): > ?File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' Whenever you use that notation, you always get a float >>> 1e7 10000000.0 So to convert '1e7' to a number, you need to use float('1e7') which you can then convert to an int >>> int(float('1e7')) 10000000 > -- > http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Sat Nov 7 20:55:08 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 08 Nov 2009 02:55:08 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? 1e7 is a way to express a float in science and math. Try float("1e7") Christian From sven at pantoffel-wg.de Sat Nov 7 21:04:04 2009 From: sven at pantoffel-wg.de (Sven Marnach) Date: Sun, 8 Nov 2009 03:04:04 +0100 Subject: Cancelling a python thread (revisited...) Message-ID: <20091108020404.GE4998@pantoffel-wg.de> Hi, the Python threading module does not seem to provide a means to cancel a running thread. There are many discussions on the web dealing with this issue and many solutions are offered, but none of them seems to be applicable to my situation, which is as follows: I have a C library which does some very computationally intensive stuff. Some functions in this library might run for a long time, and the code in the library is optimized for speed. The library is used in C programs and also from a PyGTK GUI program. In the GUI, you can choose the computation parameters and than start the computation. It is run in a separate thread, which calls a function in the C library via ctypes. Now it should be possible to cancel the computation from the GUI. In the C programs, I can just kill or cancel the thread (there is no cleanup to be done -- the thread does not use any system resources apart from CPU time). In Python, this is not possible. The solutions for this problem I found on the web usually recommend to have the thread regularly check some variable and exit if this variable indicates to do so. This would have to be included in the C library and would include quite a bit of code refactoring. The check cannot be included in the inner loop because it would lead to significant performance loss. Furthermore, I just do not want to mess up an elegant and efficient library design which works perfect when used from C just to make up for shortcomings in Python. So do I really have to refactor my C library just because Python Thread objects lack a cancel method? Is there really no other way? And why on earth doesn't that cancel method exist? There *are* good reasons to cancel a thread, just google for "terminate a Python thread" for tons of examples. I would be grateful for any suggestions. Greetings from Germany and have a nice day, Sven From python.list at tim.thechases.com Sat Nov 7 21:05:22 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 07 Nov 2009 20:05:22 -0600 Subject: How convert string '1e7' to an integer? In-Reply-To: References: Message-ID: <4AF62762.7070800@tim.thechases.com> Mick Krippendorf wrote: > Peng Yu wrote: >> It seems that int() does not convert '1e7'. > It seems it does, though: > >>>> int('1e7', base=16) > 487 Bah...so narrow-minded ;-) >>> print '\n'.join("Base %i: %i" % (base, int('1e7', base=base)) for base in range(15,37)) Base 15: 442 Base 16: 487 Base 17: 534 Base 18: 583 Base 19: 634 Base 20: 687 Base 21: 742 Base 22: 799 Base 23: 858 Base 24: 919 Base 25: 982 Base 26: 1047 Base 27: 1114 Base 28: 1183 Base 29: 1254 Base 30: 1327 Base 31: 1402 Base 32: 1479 Base 33: 1558 Base 34: 1639 Base 35: 1722 Base 36: 1807 I feel so dirty interpreting numbers in convenient ways...like an accountant. ("whaddaya mean I can't file my tax-return in base 17?! There's nothing in the supporting documentation that mentions such draconian restrictions!") -tkc From fordhaivat at gmail.com Sat Nov 7 21:06:12 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 21:06:12 -0500 Subject: Spam Bot, broken pipe In-Reply-To: References: <2cf430a60911071707r50701c20wa552ca5ae05eec15@mail.gmail.com> Message-ID: I'm just testing it on my channel! I promise! Besides, I'm doing it to learn about sockets! Please! On Sat, Nov 7, 2009 at 8:07 PM, Krister Svanlund wrote: > On Sun, Nov 8, 2009 at 2:00 AM, Someone Something > wrote: > > I have a irc spam bot (only testing on my channel :P ) whose main loop is > > the following: > > > > privc="PRIVMSG "+self.channel > > while True: > > self.sock.send(privc=" :SPAM SPAM SPAM!"); > > time.sleep(2); > > > > And it gives an error "Broken Pipe". > > How can I fix this? > > By doing it right... unfortunaly I don't approve of spam and can > therefor not tell you how to do that. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan at baselinedata.co.uk Sat Nov 7 21:08:22 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Sun, 08 Nov 2009 02:08:22 +0000 Subject: Web development with Python 3.1 In-Reply-To: References: <4AE4E4A7.5060708@baselinedata.co.uk> <880dece00910271211l5e1ecf89i1d2b85c930998689@mail.gmail.com> <7kp7brF3an909U1@mid.uni-berlin.de> <880dece00910280118j14f40763k60cd376425b8d9c@mail.gmail.com> <7kqgg4F3aqqf9U1@mid.uni-berlin.de> <6f7e015d-deba-499b-bc5d-66c0a35610b0@y23g2000yqd.googlegroups.com> Message-ID: <4AF62816.20807@baselinedata.co.uk> mario ruggier wrote: > With respect to to original question regarding web frameworks + > database and Python 3, all the following have been available for > Python 3 since the day Python 3.0 was released: > > QP, a Web Framework > http://pypi.python.org/pypi/qp/ > > Durus, a Python Object Database (the "default" in qp, for user > sessions, etc) > http://pypi.python.org/pypi/Durus/ > > Evoque, state-of-the-art templating engine > http://pypi.python.org/pypi/evoque/ > (this one is available for py3.0 since a little later, 21-jan-2009) > > All the above also runs on python 2.4 (thru to python 3) > > For the record, you may see the list of all pypi packages availabe for > Python 3 at: > http://pypi.python.org/pypi?:action=browse&show=all&c=533 > > m. Thanks for those links Mario - I'll check them out asap.. Regards, Alan From pict100 at gmail.com Sat Nov 7 21:16:50 2009 From: pict100 at gmail.com (DarkBlue) Date: Sat, 7 Nov 2009 18:16:50 -0800 (PST) Subject: PyQt processEvents not processing References: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> Message-ID: On Nov 8, 12:04?am, David Boddie wrote: > On Saturday 07 November 2009 05:12, DarkBlue wrote: > > > > > qt 4.5.3 > > pyqt 4.6.1 > > python 2.6 > > > I have this QtTable widget which I want to refresh once about every 2 > > seconds with new data. > > > so I do : > > > ?def updateSchedule(self): > > ? ? ? ? ?for j in range(0,10): > > ? ? ? ? ? ? ? ? ? ? ? doUpdate() > > ? ? ? ? ? ? ? ? ? ? ? QtCore.processEvents() > > ? ? ? ? ? ? ? ? ? ? ? sleep(2) > > > ?unfortunately QT appears to wait until the for loop finishes > > ?and only then paints the QtTable widget on the screen showing > > ?only the latest updated result. > > It's difficult to know exactly why this is without more context. Calling > the application's processEvents() method should give the user interface the > chance to update itself, but perhaps you need to explicitly call update() > on the QTableView or QTableWidget instance to ensure that it is refreshed. > > An alternative way to do this is to use a timer to update the table every > two seconds. > > David As per your suggestion I added a timer to the init part and now the update works as expected , even without calls to processEvents. self.myTimer = QtCore.QTimer(self) QtCore.QObject.connect(self.myTimer,QtCore.SIGNAL("timeout()"), self.doUpdate) self.timerTime = 0 self.myTimer.start(2000) Thanks Db From fordhaivat at gmail.com Sat Nov 7 21:37:34 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 21:37:34 -0500 Subject: Spam Bot, broken pipe In-Reply-To: References: <2cf430a60911071707r50701c20wa552ca5ae05eec15@mail.gmail.com> Message-ID: anyone? On Sat, Nov 7, 2009 at 9:06 PM, Someone Something wrote: > > > I'm just testing it on my channel! I promise! Besides, I'm doing it to > learn about sockets! Please! > > > On Sat, Nov 7, 2009 at 8:07 PM, Krister Svanlund < > krister.svanlund at gmail.com> wrote: > >> On Sun, Nov 8, 2009 at 2:00 AM, Someone Something >> wrote: >> > I have a irc spam bot (only testing on my channel :P ) whose main loop >> is >> > the following: >> > >> > privc="PRIVMSG "+self.channel >> > while True: >> > self.sock.send(privc=" :SPAM SPAM SPAM!"); >> > time.sleep(2); >> > >> > And it gives an error "Broken Pipe". >> > How can I fix this? >> >> By doing it right... unfortunaly I don't approve of spam and can >> therefor not tell you how to do that. >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sat Nov 7 21:57:26 2009 From: rt8396 at gmail.com (r) Date: Sat, 7 Nov 2009 18:57:26 -0800 (PST) Subject: An assessment of Tkinter and IDLE References: <55a0833d-3f1f-402a-8eb7-cb4b7861cce5@q5g2000yqh.googlegroups.com> <7b9665f6-8fa8-47d5-9636-da55da0fa78f@j19g2000yqk.googlegroups.com> Message-ID: <10463631-978d-4d1d-9d9a-e94af831ef15@p32g2000vbi.googlegroups.com> More on canvas widget... The Canvas widget should return objects and not simple tags/ids for canvas items *OR* at least allow for me to add attributes to the canvasitems "obj". I find that the id/tag system --while quite simple and strait forward-- can really leave you with both hands tied behind you back whilst suffering a wicked itch on the tip of your nose that is just not reachable! (god i hate that!) From pavlovevidence at gmail.com Sat Nov 7 22:27:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 19:27:52 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: Message-ID: On Nov 7, 6:04?pm, Sven Marnach wrote: > So do I really have to refactor my C library just because Python > Thread objects lack a cancel method? ?Is there really no other way? It doesn't sound like the thread is communicating with the process much. Therefore: 1. Run the C code in a separate process, or 2. Create the thread from a C extension, maybe even straight from ctypes, and kill it from C or ctypes. > And why on earth doesn't that cancel method exist? There *are* good > reasons to cancel a thread, just google for "terminate a Python > thread" for tons of examples. Arguing that there are good reasons to allow killing threads isn't going to get you very far. The language developers already know killing a thread is useful, yet the disallowed it anyway. The drawbacks were judged too severe (it makes enforcing invariants pretty much impossible). Carl Banks From kevinar18 at hotmail.com Sat Nov 7 22:39:31 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 22:39:31 -0500 Subject: How to parse HTTP time header? Message-ID: Basically, I'm wondering if it is part of the standard library somewhere before I code my own. Page 20 of RFC2616 (HTTP) describes the format(s) for the time header. It wouldn't be too difficult for me to code up a solution for the 3 standard formats, but what get's me is the little note about how some servers may still send badly format time headers. :( So, I'm curious if this has already been done in the standard Python library? How about in one of the Python web frameworks? Do any have a more robust solution already done? _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Nov 7 22:48:28 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 7 Nov 2009 22:48:28 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: <5BC7AEB5-C854-4D51-A1EF-2B3540771343@semanchuk.com> On Nov 7, 2009, at 10:39 PM, Kevin Ar18 wrote: > > Basically, I'm wondering if it is part of the standard library > somewhere before I code my own. > > Page 20 of RFC2616 (HTTP) describes the format(s) for the time > header. It wouldn't be too difficult for me to code up a solution > for the 3 standard formats, but what get's me is the little note > about how some servers may still send badly format time headers. :( > So, I'm curious if this has already been done in the standard Python > library? The parsedate() function in the rfc822 module does this and claims to be tolerant of slightly malformed dates, but that module is deprecated as of Python 2.5 in favor of the email module which hopefully has an equivalent function. HTH Philip From kevinar18 at hotmail.com Sat Nov 7 22:56:27 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 22:56:27 -0500 Subject: How to parse HTTP time header? Message-ID: >> Basically, I'm wondering if it is part of the standard library >> somewhere before I code my own. >> >> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >> header. It wouldn't be too difficult for me to code up a solution >> for the 3 standard formats, but what get's me is the little note >> about how some servers may still send badly format time headers. :( >> So, I'm curious if this has already been done in the standard Python >> library? > > The parsedate() function in the rfc822 module does this and claims to > be tolerant of slightly malformed dates, but that module is deprecated > as of Python 2.5 in favor of the email module which hopefully has an > equivalent function.Thanks, I'll give 'em a look. :) _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Nov 7 23:19:11 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 7 Nov 2009 23:19:11 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: <0F9A9052-4C33-4BF0-95BA-3CD41E90AAFB@semanchuk.com> On Nov 7, 2009, at 10:56 PM, Kevin Ar18 wrote: > >>> Basically, I'm wondering if it is part of the standard library >>> somewhere before I code my own. >>> >>> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >>> header. It wouldn't be too difficult for me to code up a solution >>> for the 3 standard formats, but what get's me is the little note >>> about how some servers may still send badly format time headers. :( >>> So, I'm curious if this has already been done in the standard Python >>> library? >> >> The parsedate() function in the rfc822 module does this and claims to >> be tolerant of slightly malformed dates, but that module is >> deprecated >> as of Python 2.5 in favor of the email module which hopefully has an >> equivalent function. > Thanks, I'll give 'em a look. :) Sorry, my mistake -- 2616 != 2822. I'm not sure if there's something in the standard library for parsing RFC 2616 dates. When I faced the problem of parsing HTTP dates, I wrote my own function although this was in an application that was deliberately unforgiving of invalid input and therefore my code makes no allowances for it. FWIW, it parsed over 1 million dates without encountering any that raised an error. Here it is, written in a time when I obviously didn't have total respect for PEP 8. ASCTIME_FORMAT = "%a %b %d %H:%M:%S %Y" RFC_850_FORMAT = "%A, %d-%b-%y %H:%M:%S GMT" RFC_1123_FORMAT = "%a, %d %b %Y %H:%M:%S GMT" def HttpDateToFloat(HttpDateString): # Per RFC 2616 section 3.3, HTTP dates can come in three flavors -- # Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 # Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 # Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format if not HttpDateString.endswith("GMT"): date = time.strptime(HttpDateString, ASCTIME_FORMAT) else: if "-" in HttpDateString: # RFC 850 format date = time.strptime(HttpDateString, RFC_850_FORMAT) else: # RFC 822/1123 date = time.strptime(HttpDateString, RFC_1123_FORMAT) return calendar.timegm(date) bye Philip From kevinar18 at hotmail.com Sat Nov 7 23:46:42 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 23:46:42 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: >>>> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >>>> header. It wouldn't be too difficult for me to code up a solution >>>> for the 3 standard formats, but what get's me is the little note >>>> about how some servers may still send badly format time headers. :( >>>> So, I'm curious if this has already been done in the standard Python >>>> library? >>> >>> The parsedate() function in the rfc822 module does this and claims to >>> be tolerant of slightly malformed dates, but that module is >>> deprecated >>> as of Python 2.5 in favor of the email module which hopefully has an >>> equivalent function. >> Thanks, I'll give 'em a look. :) > Sorry, my mistake -- 2616 != 2822. I'm not sure if there's something > in the standard library for parsing RFC 2616 dates. > > When I faced the problem of parsing HTTP dates, I wrote my own > function although this was in an application that was deliberately > unforgiving of invalid input and therefore my code makes no allowances > for it. FWIW, it parsed over 1 million dates without encountering any > that raised an error. > > Here it is, written in a time when I obviously didn't have total > respect for PEP 8. That's exactly what I had in mind when I said, I could write one quickly. :) I guess I can always do it that way if the email.util one doesn't work right. :)Thanks,Kevin _________________________________________________________________ Hotmail: Trusted email with Microsoft's powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/ http://clk.atdmt.com/GBL/go/177141664/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Sun Nov 8 00:14:33 2009 From: nagle at animats.com (John Nagle) Date: Sat, 07 Nov 2009 21:14:33 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: Message-ID: <4af65174$0$1638$742ec2ed@news.sonic.net> Carl Banks wrote: > Arguing that there are good reasons to allow killing threads isn't > going to get you very far. The language developers already know > killing a thread is useful, yet the disallowed it anyway. The > drawbacks were judged too severe (it makes enforcing invariants pretty > much impossible). While outright thread cancellation is generally unsafe, it would be useful if there was a way to force another thread to unblock from a wait condition, like a blocking read, with an exception. This is, among other things, why control-C won't terminate some threaded programs. Python 2.6 and 3 have some steps in this direction. There's "signal.set_wakeup_fd(fd)", and "siginterrupt()". But the real problem, that signals are associated only with the first thread, hasn't been addressed. Question: if "signal.set_wakeup_fd(fd)" is used, and the thread waiting on "fd" is not the main thread, will a signal cause the waiting thread to get a read completion? Or is this another "first thread only" thing"? John Nagle From alfps at start.no Sun Nov 8 01:27:27 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 08 Nov 2009 07:27:27 +0100 Subject: is None or == None ? In-Reply-To: <87my2xhko9.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> Speedup would likely be more realistic with normal implementation (not >> fiddling with bit-fields and stuff) > > I'm not sure I understand this. How would you implement tagged integers > without encoding type information in bits of the pointer value? A normal tag field, as illustrated in code earlier in the thread. Cheers & hth., - Alf From paul.nospam at rudin.co.uk Sun Nov 8 02:07:25 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 08 Nov 2009 07:07:25 +0000 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <87k4y1ebpu.fsf@rudin.co.uk> kj writes: > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > Depends on what you take as given. You can do it with ctypes more efficiently, but you can also shoot yourself in the foot. Another possibility is to use a numpy array. From martin.hellwig at dcuktec.org Sun Nov 8 02:27:43 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 08 Nov 2009 07:27:43 +0000 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: vsoler wrote: As mentioned in the other answers, your problem is best solved by a long overdue organisational decision instead of a technical one. Most popular solutions are: - All invoices are essential a single credit amount, money coming in is taken of from the big pile. - Invoices are split by date, creating multiple credit amounts, any money coming in is used the pay of the oldest one. The latter one allows more easily for different interest and penalty rates. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From victorsubervi at gmail.com Sun Nov 8 02:59:23 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 8 Nov 2009 02:59:23 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911071449.28713.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> <200911071449.28713.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> restorecon didn't change ls -lZ output Can you give me the exact command for chcon? It complains there are too few arguments, and I couldn't figure it out. Does this really matter? I moved the selinux folder and its contents as well as sent an "echo 0>..." command to kill it. Furthermore, [root at 13gems global_solutions]# ps wax|grep selinux 17645 pts/0 S+ 0:00 grep selinux Please advise. V On Sat, Nov 7, 2009 at 5:49 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > > httpd.conf: > > > > > > ServerAdmin me at creative.vi > > DocumentRoot /var/www/html/angrynates.com > > ServerName angrynates.com > > Options +ExecCGI -IncludesNoExec > > > > You may want to change this to: > > > If you want regular expression syntax, I would advise using the syntax > > or > > > > #ls -lZ > > drwxr-xr-x root root 1024 > > drwxr-xr-x root root 1132 > > drwxr-xr-x root root 1255 > [snip] > > It looks like you don't have *any* SELinux context information; if SELinux > is > on, this will cause problems. Try using the 'restorecon' command to put the > defaults in place, and consider using 'chcon' to change the security > context > to an appropriate one (I believe you want something like > 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > > > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury > wrote: > > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > > I have a serious privileges problem that is making it impossible to > > > > serve python pages on a CentOS server. It appears that nobody on the > > > > CentOS discussion list has a solution to this problem. I'm desperate > > > > and hoping someone on this list can help. > > > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > Now, the file does exist: > > > > > > > > [root at 13gems global_solutions]# pwd > > > > /var/www/html/angrynates.com/global_solutions > > > > [root at 13gems global_solutions]# ls > > > > .... > > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > > .... > > > > and it serves just fine on another server, so there is no "premature > > > > end > > > > > > of > > > > > > > script headers". > > > > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py > and > > > > template.py which the former calls, and create files test.py and > > > > test2.py and paste the code from the former files in those new files > > > > changing only the import statement from "template" to "test2", the > > > > tests will resolve!! Now, the ownership and mode are identical on all > > > > of them!! > > > > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > > > where test.py is identical to index.py (other than the necessary > > > > import) and template is identical to test2.py > > > > > > > > > > > > fixfiles relabel /var/www/html > > > > # might just work > > > > It didn't > > > > > > > > touch /.autorelabel > > > > # and then reboot will relabel all copied files to the correct > contexts > > > > > > for > > > > > > > the location > > > > I rebooted apache with no luck > > > > > > > > or you could turn off SELinux and reboot > > > > I did that and the following two solutions with no luck: > > > > echo 0 >/selinux/enforce > > > > > > > > [root at 13gems ~]# cd /etc/ > > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > > [root at 13gems etc]# mkdir selinux > > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > > > ...and the problem continues: > > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > > file > > > > > > or > > > > > > > directory: exec of '/var/www/html/ > > > > > > angrynates.com/global_solutions/index.py' > > > > > > > failed > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature > end > > > > of script headers: index.py > > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does > not > > > > exist: /var/www/html/angrynates.com/robots.txt > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does > not > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does > not > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > [root at 13gems etc]# > > > > > > > > Please help. > > > > Victor > > > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > > directories, > > > and see what the Apache (httpd.conf or .htaccess) configuration is for > > > them? > > > > > > ---- > > > Rami Chowdhury > > > "Passion is inversely proportional to the amount of real information > > > available." -- Benford's Law of Controversy > > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > > > ---- > Rami Chowdhury > "Strangers are just friends who haven't had enough gin." -- Howdle's Saying > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rschroev_nospam_ml at fastmail.fm Sun Nov 8 04:37:34 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 08 Nov 2009 10:37:34 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Gary Herron schreef: > Mensanator wrote: >> On Nov 7, 7:17 pm, Peng Yu wrote: >> >>> It seems that int() does not convert '1e7'. >>> >> Because 'e' isn't a valid character in base 10. >> > > But 1e7 is a valid float, so this works: > > >>> int(float('1e7')) > 10000000 > > That has a problem though, if you surpass the ability of a float: > > >>> int(float('1e20')) > 100000000000000000000L > >>> int(float('1e30')) > 1000000000000000019884624838656L If that is a concern, decimal can help: >>> import decimal >>> int(decimal.Decimal('1e30')) 1000000000000000000000000000000L -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From hniksic at xemacs.org Sun Nov 8 05:00:17 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 08 Nov 2009 11:00:17 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> Message-ID: <87iqdlgwum.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > * Hrvoje Niksic: >> "Alf P. Steinbach" writes: >> >>> Speedup would likely be more realistic with normal implementation (not >>> fiddling with bit-fields and stuff) >> >> I'm not sure I understand this. How would you implement tagged integers >> without encoding type information in bits of the pointer value? > > A normal tag field, as illustrated in code earlier in the thread. Ah, I see it now. That proposal effectively doubles the size of what is now a PyObject *, meaning that lists, dicts, etc., would also double their memory requirements, so it doesn't come without downsides. On the other hand, tagged pointers have been used in various Lisp implementations for decades, nothing really "baroque" (or inherently slow) about them. From alfps at start.no Sun Nov 8 05:34:55 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 08 Nov 2009 11:34:55 +0100 Subject: is None or == None ? In-Reply-To: <87iqdlgwum.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> * Hrvoje Niksic: >>> "Alf P. Steinbach" writes: >>> >>>> Speedup would likely be more realistic with normal implementation (not >>>> fiddling with bit-fields and stuff) >>> I'm not sure I understand this. How would you implement tagged integers >>> without encoding type information in bits of the pointer value? >> A normal tag field, as illustrated in code earlier in the thread. > > Ah, I see it now. That proposal effectively doubles the size of what is > now a PyObject *, meaning that lists, dicts, etc., would also double > their memory requirements, so it doesn't come without downsides. Whether it increases memory usage depends on the data mix in the program's execution. For a program primarily handling objects of atomic types (like int) it saves memory, since each value (generally) avoids a dynamically allocated object. Bit-field fiddling may save a little more memory, and is nearly guaranteed to save memory. But memory usage isn't an issue except to the degree it affects the OS's virtual memory manager. Slowness is an issue -- except that keeping compatibility is IMO a more important issue (don't fix, at cost, what works). > On the > other hand, tagged pointers have been used in various Lisp > implementations for decades, nothing really "baroque" (or inherently > slow) about them. Unpacking of bit fields generally adds overhead. The bit fields need to be unpacked for (e.g.) integer operations. Lisp once ran on severely memory constrained machines. Cheers & hth., - Alf From kbalavignesh at gmail.com Sun Nov 8 05:37:09 2009 From: kbalavignesh at gmail.com (balavignesh) Date: Sun, 8 Nov 2009 02:37:09 -0800 (PST) Subject: 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) Message-ID: Hello friends, I am using pyWPS + GRASS to generate the maps for the given request XML. As my requestxml contains scandinavian letters , i got the following error, " 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) " The Request xml also contains encoding specification like Then i traced the pywps code and added the following line, inputXml = inputXml.encode("utf-8") But it gives the following error, 'module' object has no attribute 'parsers'. Whats the wrong in my code? Do any one implemented the pywps with scandinavian letters successfully? Do i need to change anything on pywps part or request xml? Waiting for suggestions, Thanks & Regards, Bala From notvalid at wathever.com Sun Nov 8 05:43:42 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 11:43:42 +0100 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Hi, > My first question is: > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > check Ch=600 > how can I print all the different combinations of invoices that the > check is possibly cancelling > Incidentally, I'm currently learning python myself, and was working on more or less the same problem as an exercise; For listing all different subsets of a list (This is what I came up with. Can it be implemented shorter, btw?): def subsets(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets(L[1:]): S.append(s) S.append(s + [ L[0]]) return S Now, to use the above piece of code (after 'import subset'): >>> subset.subsets([4,7,8,2]) [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, 4], [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] >>> map(sum,subset.subsets([4,7,8,2])) [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] It's not a real solution yet, and as others have pointed out the problem is NP complete but it might help to get you going. cheers, Ozz From rami.chowdhury at gmail.com Sun Nov 8 05:49:54 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 8 Nov 2009 02:49:54 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071449.28713.rami.chowdhury@gmail.com> <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> Message-ID: <200911080249.55097.rami.chowdhury@gmail.com> On Saturday 07 November 2009 23:59:23 Victor Subervi wrote: > restorecon didn't change ls -lZ output Did the suggested changes to the Apache configuration help at all? > Can you give me the exact command for chcon? It complains there are too few > arguments, and I couldn't figure it out. For chcon, you probably want the 'unconfined_u' user setting, the 'object_r' role setting, and the 'httpd_sys_content_t' type setting. As 'chcon --help' tells us, you need to call it as follows: chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... Of course, here FILE can also be a directory, or the root of a directory tree, and the -R option will make chcon run recursively. > Does this really matter? I moved the selinux folder and its contents as > well as sent an "echo 0>..." command to kill it. I'm not certain -- have you tried confirming through programs such as system- config-securitylevel that it's off? > Furthermore, > [root at 13gems global_solutions]# ps wax|grep selinux > 17645 pts/0 S+ 0:00 grep selinux SELinux is a kernel subsystem -- it won't show up in the process list. > Please advise. > V > > On Sat, Nov 7, 2009 at 5:49 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > > > httpd.conf: > > > > > > > > > ServerAdmin me at creative.vi > > > DocumentRoot /var/www/html/angrynates.com > > > ServerName angrynates.com > > > Options +ExecCGI -IncludesNoExec > > > > > > > You may want to change this to: > > > > > > If you want regular expression syntax, I would advise using the syntax > > > > or > > > > > > > #ls -lZ > > > drwxr-xr-x root root 1024 > > > drwxr-xr-x root root 1132 > > > drwxr-xr-x root root 1255 > > > > [snip] > > > > It looks like you don't have *any* SELinux context information; if > > SELinux is > > on, this will cause problems. Try using the 'restorecon' command to put > > the defaults in place, and consider using 'chcon' to change the security > > context > > to an appropriate one (I believe you want something like > > 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > > > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury > > > > wrote: > > > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > > > I have a serious privileges problem that is making it impossible to > > > > > serve python pages on a CentOS server. It appears that nobody on > > > > > the CentOS discussion list has a solution to this problem. I'm > > > > > desperate and hoping someone on this list can help. > > > > > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > Now, the file does exist: > > > > > > > > > > [root at 13gems global_solutions]# pwd > > > > > /var/www/html/angrynates.com/global_solutions > > > > > [root at 13gems global_solutions]# ls > > > > > .... > > > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > > > .... > > > > > and it serves just fine on another server, so there is no > > > > > "premature end > > > > > > > > of > > > > > > > > > script headers". > > > > > > > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py > > > > and > > > > > > > template.py which the former calls, and create files test.py and > > > > > test2.py and paste the code from the former files in those new > > > > > files changing only the import statement from "template" to > > > > > "test2", the tests will resolve!! Now, the ownership and mode are > > > > > identical on all of them!! > > > > > > > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > > > > > where test.py is identical to index.py (other than the necessary > > > > > import) and template is identical to test2.py > > > > > > > > > > > > > > > fixfiles relabel /var/www/html > > > > > # might just work > > > > > It didn't > > > > > > > > > > touch /.autorelabel > > > > > # and then reboot will relabel all copied files to the correct > > > > contexts > > > > > > for > > > > > > > > > the location > > > > > I rebooted apache with no luck > > > > > > > > > > or you could turn off SELinux and reboot > > > > > I did that and the following two solutions with no luck: > > > > > echo 0 >/selinux/enforce > > > > > > > > > > [root at 13gems ~]# cd /etc/ > > > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > > > [root at 13gems etc]# mkdir selinux > > > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > > > > > ...and the problem continues: > > > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > > > file > > > > > > > > or > > > > > > > > > directory: exec of '/var/www/html/ > > > > > > > > angrynates.com/global_solutions/index.py' > > > > > > > > > failed > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature > > > > end > > > > > > > of script headers: index.py > > > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/robots.txt > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > > [root at 13gems etc]# > > > > > > > > > > Please help. > > > > > Victor > > > > > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > > > directories, > > > > and see what the Apache (httpd.conf or .htaccess) configuration is > > > > for them? > > > > > > > > ---- > > > > Rami Chowdhury > > > > "Passion is inversely proportional to the amount of real information > > > > available." -- Benford's Law of Controversy > > > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > > ---- > > Rami Chowdhury > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From ben+python at benfinney.id.au Sun Nov 8 05:51:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 21:51:54 +1100 Subject: 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) References: Message-ID: <87ocnd47cl.fsf@benfinney.id.au> balavignesh writes: > Whats the wrong in my code? Without seeing your code, all we could do is guess, poorly. Far better would be if you can construct a very small example, one that you post here so any reader here could run it, that demonstrates the behaviour you want explained. Don't forget to say what you expect the code to do differently. -- \ ?I can picture in my mind a world without war, a world without | `\ hate. And I can picture us attacking that world, because they'd | _o__) never expect it.? ?Jack Handey | Ben Finney From rpjday at crashcourse.ca Sun Nov 8 07:14:00 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sun, 8 Nov 2009 07:14:00 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, 8 Nov 2009, Ozz wrote: > > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning python myself, and was working > on more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] > else: > for s in subsets(L[1:]): > S.append(s) > S.append(s + [ L[0]]) > return S > > Now, to use the above piece of code (after 'import subset'): > > >>> subset.subsets([4,7,8,2]) > [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, 4], > [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] > >>> map(sum,subset.subsets([4,7,8,2])) > [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] > > It's not a real solution yet, and as others have pointed out the > problem is NP complete but it might help to get you going. does your solution allow for the possibility of different invoices of equal amounts? i would be reluctant to use the word "subset" in a context where you can have more than one element with the same value. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From notvalid at wathever.com Sun Nov 8 07:20:42 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 13:20:42 +0100 Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af6b799$0$83247$e4fe514c@news.xs4all.nl> Oops, > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] better to check for the empty set too, thus; if (len(L) == 0): return [[]] The order of the sets looks better too; >>> subset.subsets([1,2,3]) [[], [1], [2], [2, 1], [3], [3, 1], [3, 2], [3, 2, 1]] cheers, From notvalid at wathever.com Sun Nov 8 07:27:46 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 13:27:46 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Robert P. J. Day schreef: > does your solution allow for the possibility of different invoices > of equal amounts? i would be reluctant to use the word "subset" in a > context where you can have more than one element with the same value. I think it handles different invoices of equal amounts correctly. I agree with you though that the term subset may not be the best name in this context because of those duplicates. cheers, Ozz From sven at uni-hd.de Sun Nov 8 07:40:26 2009 From: sven at uni-hd.de (sven) Date: Sun, 8 Nov 2009 04:40:26 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: Message-ID: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> On Nov 8, 4:27?am, Carl Banks wrote: > It doesn't sound like the thread is communicating with the process > much. ?Therefore: There is quite a bit of communication -- the computation results are visulized while they are generated. > 1. Run the C code in a separate process, or > 2. Create the thread from a C extension, maybe even straight from > ctypes, and kill it from C or ctypes. The second option is a good idea. Thanks a lot, Carl! > > And why on earth doesn't that cancel method exist? There *are* good > > reasons to cancel a thread, just google for "terminate a Python > > thread" for tons of examples. > > Arguing that there are good reasons to allow killing threads isn't > going to get you very far. ?The language developers already know > killing a thread is useful, yet the disallowed it anyway. ?The > drawbacks were judged too severe (it makes enforcing invariants pretty > much impossible). I really don't get that. If the reason would be that it is too much work to implement, then I could accept it. But saying: We know it is useful, but we won't allow to do it, just does not seem reasonable. Thread cancellation might be generally unsafe, but there are cases when it is safe. It should be up to the user to decide it. There are many things that do harm if you don't use them correctly, and of course it would be a bad idea to remove all of them from Python. Well, I won't complain too much. At least some volunteers created that great language and gave it away for free :) Thanks again for your suggestion. Cheers, Sven From thom1948 at gmail.com Sun Nov 8 07:40:29 2009 From: thom1948 at gmail.com (Thomas) Date: Sun, 8 Nov 2009 04:40:29 -0800 (PST) Subject: How convert string '1e7' to an integer? References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Just a curiosity, why does Python do this? >>> l = [(base, int('1e7', base=base)) for base in range(15,37)] >>> l [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31, 1402), (32, 1479), (33, 1558), (34, 1639), (35, 1722), (36, 1807)] >>> l = ([base, int('1e7', base=base)] for base in range(15,37)) >>> l >>> From gil_johnson at earthlink.net Sun Nov 8 07:45:20 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Sun, 8 Nov 2009 04:45:20 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <2187be2d-56c0-4a5c-96d6-e0da13c30c76@j19g2000yqk.googlegroups.com> On Nov 6, 8:46?pm, gil_johnson wrote: > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil To all who asked about my previous post, I'm sorry I posted such a cryptic note before, I should have waited until I had the code available. I am still new to Python, and I couldn't find a way to create an array of size N, with each member initialized to a given value. If there is one, please let me know. I think Paul Rubin and Paul Rudin are right, if they really are 2 different people, an array is a better solution if you're dealing with integers. They both mention numpy, which I know nothing about, or the array module. kj, what *are* you going to do with this list/array? As others have pointed out, there are differences between lists, arrays, and dictionaries. The problem I was solving was this: I wanted an array of 32-bit integers to be used as a bit array, and I wanted it initialized with all bits set, that is, each member of the array had to be set to 4294967295. Of course, you could set your initializer to 0, or any other 32-bit number. Originally I found that the doubling method I wrote about before was a LOT faster than appending the elements one at a time, and tonight I tried the "list = initializer * N" method. Running the code below, the doubling method is still fastest, at least on my system. Of course, as long as you avoid the 'one at a time' method, we're talking about fractions of a second, even for arrays that I think are huge, like the 536,870,912 byte beastie below. [code] # Written in Python 3.x import array import time #* * * * * * * * * * * * * * * * * * * * * * # Doubling method, run time = 0.413938045502 t0 = time.time() newArray = array.array('I') # 32-bit unsigned integers newArray.append(4294967295) for i in range(27): # 2**27 integers, 2**29 bytes newArray.extend(newArray) print(time.time() - t0) print(newArray[134217727]) # confirm array is fully initialized #* * * * * * * * * * * * * * * * * * * * * * # One at a time, run time = 28.5479729176 t0 = time.time() newArray2 = array.array('I') for i in range(134217728): # the same size as above newArray2.append(4294967295) print(time.time() - t0) print(newArray2[134217727]) # confirm array #* * * * * * * * * * * * * * * * * * * * * * # List with "*", run time = 1.06160402298 t0 = time.time() newList = [4294967295] * 134217728 print(time.time() - t0) print(newList[134217727]) # confirm list [/code] If, instead of 134,217,728 integers, I want something different, like 100,000,000, the method I use is: [code] #* * * * * * * * * * * * * * * * * * * * * * # Not a power of 2, run time = 0.752086162567 t0 = time.time() newArray = array.array('I') tempArray = array.array('I') tempArray.append(4294967295) size = 100000000 while size: # chew through 'size' until it's gone if (size & 1): # if this bit of 'size' is 1 newArray.extend(tempArray) # add a copy of the temp array size >>= 1 # chew off one bit tempArray.extend(tempArray) # double the size of the temp array print(time.time() - t0) print(newArray[99999999]) #* * * * * * * * * * * * * * * * * * * * * * # # Not a power of 2, list with "*", run time = 1.19271993637 t0 = time.time() newList = [4294967295] * 100000000 print(time.time() - t0) print(newList[99999999]) [/code] I think it is interesting that the shorter list takes longer than the one that is a power of 2 in length. I think this may say that the "list = initializer * N" method uses something similar to the doubling method. Also, tempArray (above) gets reallocated frequently, and demonstrates that reallocation is not a big problem. Finally, I just looked into calling C functions, and found PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management section of the Python/C API Reference Manual. This gives you uninitialized memory, and should be really fast, but it's 6:45 AM here, and I don't have the energy to try it. Gil From gil_johnson at earthlink.net Sun Nov 8 08:08:35 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Sun, 8 Nov 2009 05:08:35 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> On Nov 6, 8:46?pm, gil_johnson wrote: > I don't have the code with me, but for huge arrays, I have used > something like: > > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil To all who asked about my previous post, I'm sorry I posted such a cryptic note before, I should have waited until I had the code available. I am still new to Python, and I couldn't find a way to create an array of size N, with each member initialized to a given value. If there is one, please let me know. I think Paul Rubin and Paul Rudin are right, if they really are 2 different people, an array is a better solution if you're dealing with integers. They both mention numpy, which I know nothing about, or the array module. kj, what *are* you going to do with this list/array? As others have pointed out, there are differences between lists, arrays, and dictionaries. The problem I was solving was this: I wanted an array of 32-bit integers to be used as a bit array, and I wanted it initialized with all bits set, that is, each member of the array had to be set to 4294967295. Of course, you could set your initializer to 0, or any other 32-bit number. Originally I found that the doubling method I wrote about before was a LOT faster than appending the elements one at a time, and tonight I tried the "list = initializer * N" method. Running the code below, the doubling method is still fastest, at least on my system. Of course, as long as you avoid the 'one at a time' method, we're talking about fractions of a second, even for arrays that I think are huge, like the 536,870,912 byte beastie below. [code] # Written in Python 3.x import array import time #* * * * * * * * * * * * * * * * * * * * * * # Doubling method, run time = 0.413938045502 t0 = time.time() newArray = array.array('I') # 32-bit unsigned integers newArray.append(4294967295) for i in range(27): # 2**27 integers, 2**29 bytes newArray.extend(newArray) print(time.time() - t0) print(newArray[134217727]) # confirm array is fully initialized #* * * * * * * * * * * * * * * * * * * * * * # One at a time, run time = 28.5479729176 t0 = time.time() newArray2 = array.array('I') for i in range(134217728): # the same size as above newArray2.append(4294967295) print(time.time() - t0) print(newArray2[134217727]) # confirm array #* * * * * * * * * * * * * * * * * * * * * * # List with "*", run time = 1.06160402298 t0 = time.time() newList = [4294967295] * 134217728 print(time.time() - t0) print(newList[134217727]) # confirm list [/code] If, instead of 134,217,728 integers, I want something different, like 100,000,000, the method I use is: [code] #* * * * * * * * * * * * * * * * * * * * * * # Not a power of 2, run time = 0.752086162567 t0 = time.time() newArray = array.array('I') tempArray = array.array('I') tempArray.append(4294967295) size = 100000000 while size: # chew through 'size' until it's gone if (size & 1): # if this bit of 'size' is 1 newArray.extend(tempArray) # add a copy of the temp array size >>= 1 # chew off one bit tempArray.extend(tempArray) # double the size of the temp array print(time.time() - t0) print(newArray[99999999]) #* * * * * * * * * * * * * * * * * * * * * * # # Not a power of 2, list with "*", run time = 1.19271993637 t0 = time.time() newList = [4294967295] * 100000000 print(time.time() - t0) print(newList[99999999]) [/code] I think it is interesting that the shorter list takes longer than the one that is a power of 2 in length. I think this may say that the "list = initializer * N" method uses something similar to the doubling method. Also, tempArray (above) gets reallocated frequently, and demonstrates that reallocation is not a big problem. Finally, I just looked into calling C functions, and found PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management section of the Python/C API Reference Manual. This gives you uninitialized memory, and should be really fast, but it's 6:45 AM here, and I don't have the energy to try it. Gil From mad.mick at gmx.de Sun Nov 8 08:39:05 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 14:39:05 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Thomas wrote: > Just a curiosity, why does Python do this? > >>>> [(base, int('1e7', base=base)) for base in range(15,37)] > [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), > (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), > (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31, 1402), (32, > 1479), (33, 1558), (34, 1639), (35, 1722), (36, 1807)] >>>> ([base, int('1e7', base=base)] for base in range(15,37)) > Because the former is a list comprehension, whereas the latter is a generator expression. Mick. From exarkun at twistedmatrix.com Sun Nov 8 08:50:07 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 08 Nov 2009 13:50:07 -0000 Subject: Cancelling a python thread (revisited...) In-Reply-To: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <20091108135007.3229.420540105.divmod.xquotient.363@localhost.localdomain> On 12:40 pm, sven at uni-hd.de wrote: >On Nov 8, 4:27?am, Carl Banks wrote: >>It doesn't sound like the thread is communicating with the process >>much. ?Therefore: > >There is quite a bit of communication -- the computation results are >visulized while they are generated. I'm curious how this visualization works, since earlier you said something to the affect that there were no shared resources. If you kill a thread and it had opened a window and was drawing on it, with most toolkits, you'll end up with a window stuck in your screen, won't you? >[snip] > >I really don't get that. If the reason would be that it is too much >work to >implement, then I could accept it. But saying: We know it is useful, >but we >won't allow to do it, just does not seem reasonable. Thread >cancellation >might be generally unsafe, but there are cases when it is safe. It >should be >up to the user to decide it. There are many things that do harm if >you don't >use them correctly, and of course it would be a bad idea to remove all >of >them from Python. The CPython philosophy sort of follows the guideline that you should be allowed to do bad stuff if you want, except when that bad stuff would crash the interpreter (clearly ctypes is an exception to this rule of thumb). I think this is the argument that has been applied in opposition to adding thread termination in the past, though I don't remember for sure. Jean-Paul From solipsis at pitrou.net Sun Nov 8 08:52:17 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 8 Nov 2009 13:52:17 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: Le Sun, 08 Nov 2009 04:40:26 -0800, sven a ?crit?: > > I really don't get that. If the reason would be that it is too much > work to > implement, then I could accept it. It would probably be a lot of work and even then it would still be unsafe. Read for example: http://msdn.microsoft.com/en-us/library/ms686717%28VS.85%29.aspx ? TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems: * If the target thread owns a critical section, the critical section will not be released. * If the target thread is allocating memory from the heap, the heap lock will not be released. * If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent. * If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL. ? From rdbriggs at mun.ca Sun Nov 8 09:56:18 2009 From: rdbriggs at mun.ca (Rob Briggs) Date: Sun, 08 Nov 2009 11:26:18 -0330 Subject: Query about doing fortran-esque repeat formatting Message-ID: <1257692178.27566.38.camel@vostok.physics.mun.ca> Hello, Is there a way to do a repeat formatting command like in Fortran? Rather that doing this: print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) Something like this: print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) regards, Rob From gb345 at invalid.com Sun Nov 8 10:20:42 2009 From: gb345 at invalid.com (gb345) Date: Sun, 8 Nov 2009 15:20:42 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: In Luis Alberto Zarrabeitia Gomez writes: >?Have you ever tried to read list/matrix that you know it is not sparse, but you jdon't know the size, and it may not be in order? A "grow-able" array would just >be the right thing to use - currently I have to settle with either hacking >together my own grow-able array, or... >...Not hard, not worthy of a >PEP, but certainly not so easy to dismiss. I'm pretty new to Python, and I thought I'd give this a try: class array(list): """A list that grows as needed upon assignment. Any required padding is done with the value of the fill option. Attempts to retrieve an index greater than the maximum assigned index still produces an IndexError. """ def __init__(self, seq='', fill=None): super(array, self).__init__(seq) self.fill = fill @property def max(self): return len(self) - 1 def __setitem__(self, index, item): m = self.max while m < index: self.append(self.fill) m += 1 super(array, self).__setitem__(index, item) if __name__ == '__main__': x = array(('zero',)) x[3] = 'it works!' print x --------------------------------------------------------------------------- ['zero', None, None, 'it works!'] Looks like it works, but it seems almost too easy. Did I miss anything? Comments welcome. (E.g. I'm not sure that '' is the best choice of default value for the seq parameter to __init__.) Thanks in advance, Gabe From vasudevram at gmail.com Sun Nov 8 10:34:23 2009 From: vasudevram at gmail.com (vasudevram) Date: Sun, 8 Nov 2009 07:34:23 -0800 (PST) Subject: PySiteCreator v0.1 released Message-ID: <41ff557a-d691-4c1b-a94f-493cc3f3c620@h40g2000prf.googlegroups.com> Hi group, I've released a tool for creating HTML pages or Web sites by writing them in Python - PySiteCreator v0.1. Description of PySiteCreator: PySiteCreator is a tool that allows the user to create Web (HTML) sites by writing them entirely in Python. A user creates one or more Python source files in each of which they import a PySiteCreator helper module, and then call helper functions defined in that module, in order to emit HTML elements and associated content. They can then run the PySiteCreator program to process all those Python files; processing each Python file will result in the creation of a corresponding HTML file with the desired HTML elements and content. Some more details and the download link are available here on my blog: http://jugad2.blogspot.com/2009/11/early-release-of-pysitecreator-v01.html I appreciate any feedback on PySiteCreator. Thanks, Vasudev Ram Biz: www.dancingbison.com Products: www.dancingbison.com/products.html Blog on software innovation: jugad2.blogspot.com From luca at keul.it Sun Nov 8 10:57:37 2009 From: luca at keul.it (Luca Fabbri) Date: Sun, 8 Nov 2009 16:57:37 +0100 Subject: Need help for my system python Message-ID: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> Hi all. I've recently updated my system to the last Kubuntu 9.10. On my system I use: python2.6 (default system python) python 2.4 (needed for the Zope application server) Also I have 2 easy_install script for installing my eggs. The default one for python2.6 works normally, but I've some problems with using eggs for python 2.4 The easy_install procedure works (eggs are installed and I see no errors) but after that if I run the interpreter, it seems that no new libraries are installed. I know that this is very general question, but I'm wondering if some one had the same problem. Where I can look at for solving this? -- -- luca From mensanator at aol.com Sun Nov 8 11:08:55 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 8 Nov 2009 08:08:55 -0800 (PST) Subject: Query about doing fortran-esque repeat formatting References: Message-ID: On Nov 8, 8:56?am, Rob Briggs wrote: > Hello, > > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], ?tmp[i][6], ?tmp[i][7], > tmp[i][8], ?tmp[i][9]) > > Something like this: > > print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], > tmp[i][6], ?tmp[i][7], tmp[i][8], ?tmp[i][9]) > >>> s = '%s ' + ' %-5.4f' * 7 >>> s '%s %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f' >>> print s % ('s',1,2,3,4,5,6,7) s 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 > regards, > > Rob From luca at keul.it Sun Nov 8 11:27:29 2009 From: luca at keul.it (Luca Fabbri) Date: Sun, 8 Nov 2009 17:27:29 +0100 Subject: Need help for my system python In-Reply-To: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> References: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> Message-ID: <27308d500911080827q70c6ab8dy8a0f85ab03fe2f6c@mail.gmail.com> SOLVED. For some reason a "zope" directory were inside my site-packages folder, so the zope.interface egg was not visible... On Sun, Nov 8, 2009 at 4:57 PM, Luca Fabbri wrote: > Hi all. > > I've recently updated my system to the last Kubuntu 9.10. > > On my system I use: > python2.6 (default system python) > python 2.4 (needed for the Zope application server) > > Also I have 2 easy_install script for installing my eggs. > > The default one for python2.6 works normally, but I've some problems > with using eggs for python 2.4 > > The easy_install procedure works (eggs are installed and I see no > errors) but after that if I run the interpreter, it seems that no new > libraries are installed. > > I know that this is very general question, but I'm wondering if some > one had the same problem. > Where I can look at for solving this? > > -- > -- luca > -- -- luca From danb_83 at yahoo.com Sun Nov 8 11:52:37 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Sun, 8 Nov 2009 08:52:37 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 4:43?am, Ozz wrote: > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning python myself, and was working on > more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > ? ? ? ? ?S = [] > ? ? ? ? ?if (len(L) == 1): > ? ? ? ? ? ? ? ? ?return [L, []] > ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): > ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) > ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) > ? ? ? ? ?return S You can avoid the S list my making it a generator: def subsets(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] From redplusbluemakespurple at gmail.com Sun Nov 8 11:57:18 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Sun, 8 Nov 2009 08:57:18 -0800 (PST) Subject: Help with OS X installation Message-ID: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> I have python 2.6 on OS X 10.5.8: $ python --version Python 2.6.2 $ which python /Library/Frameworks/Python.framework/Versions/2.6/bin/python When installing an egg, python 2.5 shows up: """ $ sudo easy_install ipython-0.10-py2.6.egg Password: Processing ipython-0.10-py2.6.egg removing '/Library/Python/2.5/site-packages/ipython-0.10- py2.6.egg' (and everything under it) creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages """ But 2.6 is not here: $ ls /Library/Python 2.3/ 2.5/ Launching ipython happens with Python 2.5.1 though. Is there something I did incorrectly when installing python 2.6? Stephen From ngabonzizap72 at gmail.com Sun Nov 8 12:01:09 2009 From: ngabonzizap72 at gmail.com (NGABONZIZA PROSPER) Date: Sun, 8 Nov 2009 19:01:09 +0200 Subject: ODES Message-ID: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> Hi all; Help! Could you Tell me where I may find documentation on Solving Differential equations with Scipy or Numpy. Thank you all From deets at nospam.web.de Sun Nov 8 12:12:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Nov 2009 18:12:12 +0100 Subject: Help with OS X installation In-Reply-To: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: <7locfcF3f1q68U1@mid.uni-berlin.de> stephen_b schrieb: > I have python 2.6 on OS X 10.5.8: > > $ python --version > Python 2.6.2 > > $ which python > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > When installing an egg, python 2.5 shows up: > > """ > $ sudo easy_install ipython-0.10-py2.6.egg > Password: > Processing ipython-0.10-py2.6.egg > removing '/Library/Python/2.5/site-packages/ipython-0.10- > py2.6.egg' (and everything under it) > creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg > Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages > """ > > But 2.6 is not here: > > $ ls /Library/Python > 2.3/ 2.5/ > > Launching ipython happens with Python 2.5.1 though. Is there something > I did incorrectly when installing python 2.6? You use the wrong easy_install - use easy_install-2.6. Diez From vicente.soler at gmail.com Sun Nov 8 12:16:27 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 8 Nov 2009 09:16:27 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 1:27?pm, Ozz wrote: > Robert P. J. Day schreef: > > > ? does your solution allow for the possibility of different invoices > > of equal amounts? ?i would be reluctant to use the word "subset" in a > > context where you can have more than one element with the same value. > > I think it handles different invoices of equal amounts correctly. > I agree with you though that the term subset may not be the best name in > this context because of those duplicates. > > cheers, > Ozz Ozz, Instead of subsets, do you mean permutations/combinations? Since 2 invoices can have the same amount perhaps the terms permutation is better. Vicente Soler From python at mrabarnett.plus.com Sun Nov 8 12:27:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 17:27:01 +0000 Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4AF6FF65.9060603@mrabarnett.plus.com> Ozz wrote: > > Hi, > >> My first question is: >> 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >> check Ch=600 >> how can I print all the different combinations of invoices that the >> check is possibly cancelling >> > > Incidentally, I'm currently learning python myself, and was working on > more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] > else: > for s in subsets(L[1:]): > S.append(s) > S.append(s + [ L[0]]) > return S > > Now, to use the above piece of code (after 'import subset'): > > >>> subset.subsets([4,7,8,2]) > [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, > 4], [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] > >>> map(sum,subset.subsets([4,7,8,2])) > [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] > > It's not a real solution yet, and as others have pointed out the problem > is NP complete but it might help to get you going. > Here's my own take on it: def list_possible_invoices(invoices, check): if check: # The check hasn't yet been fully consumed. for index, inv in enumerate(invoices): # If this invoice doesn't exceed the check then it consume some of the check. if inv <= check: # Try to consume the remainder of the check. for inv_list in list_possible_invoices(invoices[index + 1 : ], check - inv): yield [inv] + inv_list else: # The check has been fully consumed. yield [] invoices = [500, 400, 450, 200, 600, 700] check = 600 # List all the possible subsets of invoices. # Sorting the invoices first in descending order lets us reduce the number of possibilities to try. for inv_list in list_possible_invoices(sorted(invoices, reverse=True), check): print inv_list From rami.chowdhury at gmail.com Sun Nov 8 12:28:41 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 8 Nov 2009 09:28:41 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> Message-ID: <200911080928.41802.rami.chowdhury@gmail.com> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t > httpd_sys_content_t global_solutions > chcon: can't apply partial context to unlabeled file global_solutions > Please advise. Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t global_solutions/*', which should specify the whole context at once and avoid that error, as well as apply it recursively to all files and subdirectories. Also, to narrow down the error, can you let us have the output of: tail /var/log/messages tail /var/log/httpd/error_log HTH, Rami ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From debatem1 at gmail.com Sun Nov 8 12:31:26 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:31:26 -0500 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: > On Nov 8, 4:43?am, Ozz wrote: >> Hi, >> >> > My first question is: >> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >> > check Ch=600 >> > how can I print all the different combinations of invoices that the >> > check is possibly cancelling >> >> Incidentally, I'm currently learning python myself, and was working on >> more or less the same problem as an exercise; >> >> For listing all different subsets of a list (This is what I came up >> with. Can it be implemented shorter, btw?): >> >> def subsets(L): >> ? ? ? ? ?S = [] >> ? ? ? ? ?if (len(L) == 1): >> ? ? ? ? ? ? ? ? ?return [L, []] >> ? ? ? ? ?else: >> ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): >> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) >> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) >> ? ? ? ? ?return S > > You can avoid the S list my making it a generator: > > def subsets(L): > ? ?if L: > ? ? ? ?for s in subsets(L[1:]): > ? ? ? ? ? ?yield s > ? ? ? ? ? ?yield s + [L[0]] > ? ?else: > ? ? ? ?yield [] What you're describing is the powerset operation. Here's the example from the python docs: def powerset(iterable): "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) What I find interesting is that running it through timeit, it is much slower than the code suggested by Dan Bishop. setup = """ from itertools import chain, combinations x = list(range(100)) def subsets1(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets1(L[1:]): S.append(s) S.append(s + [ L[0]]) return S def subsets2(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] def subsets3(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) """ #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate timeit.timeit("subsets2(x)", setup) timeit.timeit("subsets3(x)", setup) I'm getting numbers roughly 3:1 in Dan's favor. Geremy Condra From debatem1 at gmail.com Sun Nov 8 12:36:39 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:36:39 -0500 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, Nov 8, 2009 at 12:31 PM, geremy condra wrote: > On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: >> On Nov 8, 4:43?am, Ozz wrote: >>> Hi, >>> >>> > My first question is: >>> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >>> > check Ch=600 >>> > how can I print all the different combinations of invoices that the >>> > check is possibly cancelling >>> >>> Incidentally, I'm currently learning python myself, and was working on >>> more or less the same problem as an exercise; >>> >>> For listing all different subsets of a list (This is what I came up >>> with. Can it be implemented shorter, btw?): >>> >>> def subsets(L): >>> ? ? ? ? ?S = [] >>> ? ? ? ? ?if (len(L) == 1): >>> ? ? ? ? ? ? ? ? ?return [L, []] >>> ? ? ? ? ?else: >>> ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): >>> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) >>> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) >>> ? ? ? ? ?return S >> >> You can avoid the S list my making it a generator: >> >> def subsets(L): >> ? ?if L: >> ? ? ? ?for s in subsets(L[1:]): >> ? ? ? ? ? ?yield s >> ? ? ? ? ? ?yield s + [L[0]] >> ? ?else: >> ? ? ? ?yield [] > > What you're describing is the powerset operation. Here's the example > from the python docs: > > def powerset(iterable): > ? ?"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" > ? ?s = list(iterable) > ? ?return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) > > What I find interesting is that running it through timeit, it is much > slower than the code suggested by Dan Bishop. > > setup = """ > from itertools import chain, combinations > > x = list(range(100)) > > def subsets1(L): > ? ? ? S = [] > ? ? ? if (len(L) == 1): > ? ? ? ? ? ? ? return [L, []] > ? ? ? else: > ? ? ? ? ? ? ? for s in subsets1(L[1:]): > ? ? ? ? ? ? ? ? ? ? ? S.append(s) > ? ? ? ? ? ? ? ? ? ? ? S.append(s + [ L[0]]) > ? ? ? return S > > def subsets2(L): > ? if L: > ? ? ? for s in subsets(L[1:]): > ? ? ? ? ? yield s > ? ? ? ? ? yield s + [L[0]] > ? else: > ? ? ? yield [] > > def subsets3(iterable): > ? ?s = list(iterable) > ? ?return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) > """ > > #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate > timeit.timeit("subsets2(x)", setup) > timeit.timeit("subsets3(x)", setup) > > > I'm getting numbers roughly 3:1 in Dan's favor. > > Geremy Condra > I made a mistake copying it on line 18 of the above; it should be subsets2, rather than just subsets. Geremy Condra From victorsubervi at gmail.com Sun Nov 8 12:40:58 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 8 Nov 2009 12:40:58 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911080928.41802.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> [root at 13gems angrynates.com]# chcon -R -h unconfined_u:object_r:httpd_sys_content_t global_solutions/* Then I surfed to http://209.216.9.56/global_solutions/index.py [root at 13gems angrynates.com]# tail /var/log/messages Nov 8 04:26:02 13gems syslogd 1.4.1: restart. [root at 13gems angrynates.com]# tail /var/log/httpd/error_log [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest authentication ... [Sun Nov 08 05:35:10 2009] [notice] Digest: done [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session mutexes based on 10 max processes and 0 max threads. [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not exist: /var/www/html/angrynates.com/favicon.ico [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not exist: /var/www/html/angrynates.com/favicon.ico [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://209.216.9.56/global_solutions/ TIA, V On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury wrote: > On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: > > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t > > httpd_sys_content_t global_solutions > > chcon: can't apply partial context to unlabeled file global_solutions > > Please advise. > > Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t > global_solutions/*', which should specify the whole context at once and > avoid > that error, as well as apply it recursively to all files and > subdirectories. > > Also, to narrow down the error, can you let us have the output of: > tail /var/log/messages > tail /var/log/httpd/error_log > > HTH, > Rami > > ---- > Rami Chowdhury > "As an online discussion grows longer, the probability of a comparison > involving Nazis or Hitler approaches one." -- Godwin's Law > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Sun Nov 8 12:53:45 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:53:45 -0500 Subject: ODES In-Reply-To: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> References: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> Message-ID: On Sun, Nov 8, 2009 at 12:01 PM, NGABONZIZA PROSPER wrote: > Hi all; > > > Help! > > Could you Tell me where I may find documentation ?on Solving > Differential equations ?with Scipy or Numpy. > > > > Thank you all > -- > http://mail.python.org/mailman/listinfo/python-list > http://lmgtfy.com/?q=solving+differential+equations+with+scipy ;) From benjamin.kaplan at case.edu Sun Nov 8 13:12:54 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Nov 2009 13:12:54 -0500 Subject: Help with OS X installation In-Reply-To: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: On Sun, Nov 8, 2009 at 11:57 AM, stephen_b wrote: > I have ?python 2.6 on OS X 10.5.8: > > $ python --version > Python 2.6.2 > > $ which python > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > When installing an egg, python 2.5 shows up: > > """ > $ sudo easy_install ipython-0.10-py2.6.egg > Password: > Processing ipython-0.10-py2.6.egg > removing '/Library/Python/2.5/site-packages/ipython-0.10- > py2.6.egg' (and everything under it) > creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg > Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages > """ > > But 2.6 is not here: > > $ ls /Library/Python > 2.3/ 2.5/ > > Launching ipython happens with Python 2.5.1 though. Is there something > I did incorrectly when installing python 2.6? > easy_install is not a part of Python- you have to download and install setuptools yourself. You never installed setuptools for python2.6 so the 2.5 version is still the default. http://pypi.python.org/pypi/setuptools > Stephen > -- > http://mail.python.org/mailman/listinfo/python-list > From wells at submute.net Sun Nov 8 13:15:06 2009 From: wells at submute.net (Wells) Date: Sun, 8 Nov 2009 10:15:06 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? Message-ID: I'm not quite understanding why a tuple is hashable but a list is not. Any pointers? Thanks! From digitalxero at gmail.com Sun Nov 8 13:31:09 2009 From: digitalxero at gmail.com (Dj Gilcrease) Date: Sun, 8 Nov 2009 11:31:09 -0700 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: On Sun, Nov 8, 2009 at 11:15 AM, Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! tuple is hashable because it is immutable whereas a list is mutable. From tycho at tycho.ws Sun Nov 8 13:33:12 2009 From: tycho at tycho.ws (Tycho Andersen) Date: Sun, 8 Nov 2009 12:33:12 -0600 (CST) Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: On Sun, 8 Nov 2009, Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! The keys of a dict have to be immutable. Lists are mutable, tuples are not. \t From nagle at animats.com Sun Nov 8 13:39:27 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 10:39:27 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <4af70e1b$0$1622$742ec2ed@news.sonic.net> Antoine Pitrou wrote: > Le Sun, 08 Nov 2009 04:40:26 -0800, sven a ?crit : >> I really don't get that. If the reason would be that it is too much >> work to >> implement, then I could accept it. > > It would probably be a lot of work and even then it would still be unsafe. > > Read for example: > http://msdn.microsoft.com/en-us/library/ms686717%28VS.85%29.aspx I'd argue against general thread cancellation. Inter-thread signals, though, have safety problems no worse than the first-thread only signals we have now. You're allowed to raise an exception in a signal handler, which is effectively thread cancellation. So right now, you can kill the first thread from another thread. John Nagle From python at mrabarnett.plus.com Sun Nov 8 13:52:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 18:52:06 +0000 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: <4AF71356.9080602@mrabarnett.plus.com> Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! A hash is created from the object. If the object is mutable then the hash can change. Lists are mutable but tuples aren't. From mrholtsr at sbcglobal.net Sun Nov 8 14:01:37 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sun, 8 Nov 2009 14:01:37 -0500 Subject: Indentation problems Message-ID: I am having problems with indentation some times. When I hit the enter key after if statements or while statemt there are times when the indentation is too much and other times too little. When I try to manually make sure the indentation is correct and try to print, I ge the error message of invalid syntax or incorrect indentation. Can someone help me. Also when I open the edit window instead of the shell the programs tend not to run. Help! Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid at wathever.com Sun Nov 8 14:33:54 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 20:33:54 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af71d21$0$83241$e4fe514c@news.xs4all.nl> Dan Bishop schreef: > > You can avoid the S list my making it a generator: > > def subsets(L): > if L: > for s in subsets(L[1:]): > yield s > yield s + [L[0]] > else: > yield [] Nice one. Thanks! Ozz From solipsis at pitrou.net Sun Nov 8 14:34:00 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 8 Nov 2009 19:34:00 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> Message-ID: John Nagle animats.com> writes: > > I'd argue against general thread cancellation. Inter-thread > signals, though, have safety problems no worse than the first-thread > only signals we have now. You're allowed to raise an exception > in a signal handler, which is effectively thread cancellation. Can you give an example of such "cancellation"? In any case, this would be a side-effect of the current implementation, not officially supported behaviour. Regards Antoine. From nagle at animats.com Sun Nov 8 14:36:33 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 11:36:33 -0800 Subject: pyserial vs. Linux power save hibernate/resume - program hangs Message-ID: <4af71b7e$0$1645$742ec2ed@news.sonic.net> I have an application running with pyserial talking to a USB to serial converter on a Linux EeePC 2G Surf. This works. Until the lid on the PC is closed and the device suspends. The application has /dev/ttyUSB0 open, and has a read pending with a 1 second timeout. When the device comes out of suspend, the USB devices are enumerated again. The serial device moves to /dev/ttyUSB1, and the application continues to poll /dev/ttyUSB0. No error results from polling the removed device. So the application is stuck and doesn't know it. An attempt to write to the disconnected serial port produces an IOError exception, but the read side doesn't seem to notice. Any ideas? John Nagle From shoebox56carson at gmail.com Sun Nov 8 14:38:31 2009 From: shoebox56carson at gmail.com (Shue Boks) Date: Sun, 8 Nov 2009 11:38:31 -0800 (PST) Subject: Looking for help getting tkinter to work. References: <9e15ab12-c826-4227-9a0c-82d3eccb96a0@r24g2000prf.googlegroups.com> <9d0c476a-86f7-4a8a-a01b-e260060c7bcc@a31g2000yqn.googlegroups.com> Message-ID: <6d6c1d60-4cea-44b0-b309-95f13f94bba7@12g2000pri.googlegroups.com> On Nov 1, 6:27 am, Francesco Bochicchio wrote: > On Nov 1, 4:06 am, Shue Boks wrote: > > > > > I tried to compile Python and Tcl/Tk on Linux using the following > > files: > > > Python-3.1.1.tar.gz > > tcl8.5.7-src.tar.gz > > > Cannot get tkinter to work after compiling & installing Tcl/Tk. I get > > the following error after compiling Python: > > > "Python build finished, but the necessary bits to build these modules > > were not found: > > _tkinter > > To find the necessary bits, look in setup.py in detect_modules() for > > the module's name." > > > Are the above files the correct versions to get tkinter to work? > > > Thanks. > > The version should be ok. I just compiled python3.1 against tcl/tk > 8.5, only I used > the tcl/tk development packages coming with my distribution (Ubuntu). > I used > ./configure --with-tk, so if you did not, try that first. > > Did you run 'make install' during tcl/tk installation _before_ doing ./ > configure in python source > directory? > > If so, look where the library files ( e.g. libtk8.5.so ) and include > files (e.g tk.h ) have been placed > and check against the places where the function 'detect_tkinter' in > 'setup.py' looks for them. > > Ciao > ----- > FB Sorry for the late response, I only get a chance to play with this on the weekends. I tried everything mentioned above, but nothing seems to work. I did a "find / " on the two files libtk8.5.so and tk.h, it doesn't appear anywhere. I am really thinking that tcl8.5.7-src.tar.gz doesn't have the necessary files I need. I am using Puppy Linux which I am slowly giving up on. I love Puppy, but their distribution doesn't come with the tcl/tk development package that Ubuntu has. From torriem at gmail.com Sun Nov 8 14:39:10 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 Nov 2009 12:39:10 -0700 Subject: Spam Bot, broken pipe In-Reply-To: References: Message-ID: <4AF71E5E.30300@gmail.com> Someone Something wrote: > I have a irc spam bot (only testing on my channel :P ) whose main loop is > the following: Poor choice of words on your part. Anything spam-related is evil and will not get a response. That said, "IRC bots" are certainly okay and common, and are useful tools. Some are even written in Python. From notvalid at wathever.com Sun Nov 8 14:42:09 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 20:42:09 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Message-ID: <4af71f11$0$83241$e4fe514c@news.xs4all.nl> vsoler schreef: > > Instead of subsets, do you mean permutations/combinations? Since 2 > invoices can have the same amount perhaps the terms permutation is > better. > As some other poster already suggested 'powerset' ( http://en.wikipedia.org/wiki/Power_set ) may be a better name, except for those duplicates, of course. On the other hand, I think viewing it as a powerset is the most 'natural' in this case. (imo permutations are about the order of objects, not about whether the objects are included in a set or not) cheers, Ozz From tjreedy at udel.edu Sun Nov 8 14:45:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 Nov 2009 14:45:31 -0500 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: Alf P. Steinbach wrote: > * Hrvoje Niksic: >> "Alf P. Steinbach" writes: >> >>> * Hrvoje Niksic: >>>> "Alf P. Steinbach" writes: >>>> >>>>> Speedup would likely be more realistic with normal implementation (not >>>>> fiddling with bit-fields and stuff) >>>> I'm not sure I understand this. How would you implement tagged >>>> integers >>>> without encoding type information in bits of the pointer value? >>> A normal tag field, as illustrated in code earlier in the thread. >> >> Ah, I see it now. That proposal effectively doubles the size of what is >> now a PyObject *, meaning that lists, dicts, etc., would also double >> their memory requirements, so it doesn't come without downsides. > > Whether it increases memory usage depends on the data mix in the > program's execution. > > For a program primarily handling objects of atomic types (like int) it > saves memory, since each value (generally) avoids a dynamically > allocated object. > > Bit-field fiddling may save a little more memory, and is nearly > guaranteed to save memory. > > But memory usage isn't an issue except to the degree it affects the OS's > virtual memory manager. > > Slowness is an issue -- except that keeping compatibility is IMO a > more important issue (don't fix, at cost, what works). I believe the use of tagged pointers has been considered and so far rejected by the CPython developers. And no one else that I know of has developed a fork for that. It would seem more feasible with 64 bit pointers where there seem to be spare bits. But CPython will have to support 32 bit machines for several years. Terry Jan Reedy From python.list at tim.thechases.com Sun Nov 8 14:48:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 08 Nov 2009 13:48:06 -0600 Subject: Indentation problems In-Reply-To: References: Message-ID: <4AF72076.8020806@tim.thechases.com> > I am having problems with indentation some times. When I hit the enter key > after if statements or while statemt there are times when the indentation is > too much and other times too little. Which editor are you using? On which operating system? Check for settings regarding spaces-per-tab, whether the editor expands tabs to spaces, and where your tab-stops are. If you were using Vim, I'd tell you to look at your settings for :set ai? ts? sts? sw? et? cpo? si? cin? inde? any of which can be tweaked to adjust the behavior of automatic indenting. Your unnamed editor may have some similar options you can control. -tkc From nad at acm.org Sun Nov 8 15:21:13 2009 From: nad at acm.org (Ned Deily) Date: Sun, 08 Nov 2009 12:21:13 -0800 Subject: pyserial vs. Linux power save hibernate/resume - program hangs References: <4af71b7e$0$1645$742ec2ed@news.sonic.net> Message-ID: In article <4af71b7e$0$1645$742ec2ed at news.sonic.net>, John Nagle wrote: > I have an application running with pyserial talking to a USB to serial > converter on a Linux EeePC 2G Surf. This works. Until the lid on the PC is > closed and the device suspends. > > The application has /dev/ttyUSB0 open, and has a read pending > with a 1 second timeout. When the device comes out of suspend, > the USB devices are enumerated again. The serial device moves > to /dev/ttyUSB1, and the application continues to poll /dev/ttyUSB0. > No error results from polling the removed device. So the > application is stuck and doesn't know it. > > An attempt to write to the disconnected serial port produces > an IOError exception, but the read side doesn't seem to notice. If your Linux is new enough, you should be able to create a permanent device name for the serial converter using a udev rule. Then your code won't need to be dependent on the /dev/ttyUSBx device name. -- Ned Deily, nad at acm.org From mad.mick at gmx.de Sun Nov 8 15:42:21 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 21:42:21 +0100 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. The short answer has already been given. Here is the long answer: For objects p and q, p==q implies hash(p)==hash(q). It is essential for dicts and sets that objects used as keys/elements uphold this law, and also that, for an object o, hash(o) doesn't change during the lifetime of o. What if you write a class that doesn't? Let's see: >>> class Thing(object): ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other.value ... def __hash__(self): ... return hash(self.value) ... def __repr__(self): ... return "Thing(%s)" % self.value ... >>> >>> thinglist = [Thing(i) for i in xrange(10)] >>> >>> thingdict = dict((y,x) for x,y in enumerate(thinglist)) >>> >>> print thingdict[thinglist[5]] 5 >>> >>> thinglist[5].value = 99 >>> >>> print thingdict[thinglist[5]] Traceback (most recent call last): File "", line 1, in KeyError: Thing(99) What happened? __eq__ and __hash__ both depend on a mutable attribute, and when that attribute was changed, their outcome changed as well. If a Thing is stored as key in a dict and later it's value attribute is changed, it cannot be found anymore. Too bad. BTW, this doesn't work either: >>> print thingdict[Thing(5)] Traceback (most recent call last): File "", line 1, in KeyError: Thing(5) wheras this works: >>> print thingdict[Thing(6)] 6 What has this got to do with lists and tuples? Well, two tuples x and y are considered equal, iff: >>> all(a==b for a,b in zip(x,y)) Also, by the law above, hash(x)==hash(y). Since tuples are immutable, x and y (and hash(x) and hash(y)) will be equal as long as they live. Lists have the same properties regarding equality, but are mutable. If we'd use a list as key in a dict and append an element to the list, __eq__ and __hash__ would return something different than before the append. The list couldn't be found anymore, just like the instance of the broken Thing class above. Lists are not hashable, because it would lead to untraceable bugs otherwise, and it would confuse beginners. This also teaches a lesson on how to implement __eq__ and __hash__, if you must. Just make sure your objects always do uphold the law above, and do not change in respect to __hash__ during their lifetime. OTOH it is possible to do otherwise, as long as you don't try to use these objects as elements of a set or keys in a dictionary. But then, why would you bother to implement your own __hash__ method? Regards, Mick. From webtourist at gmail.com Sun Nov 8 16:20:23 2009 From: webtourist at gmail.com (webtourist) Date: Sun, 8 Nov 2009 13:20:23 -0800 (PST) Subject: on "Namespaces" Message-ID: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> New bie Question: in "Zen of Python" - what exactly does the last one mean ? - Namespaces are one honking great idea -- let's do more of those! I mean why the emphasis ? Is it like saying "put modules into packages" in other programming paradigm s ? thanks From emile at fenx.com Sun Nov 8 16:59:53 2009 From: emile at fenx.com (Emile van Sebille) Date: Sun, 08 Nov 2009 13:59:53 -0800 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> Message-ID: On 11/7/2009 5:18 PM Carl Banks said... > I think the top one is O(N log N), and I'm suspicious that it's even > possible to grow a list in less than O(N log N) time without knowing > the final size in advance. Citation? Quoting Tim -- Python uses mildly exponential over-allocation, sufficient so that growing a list takes *amortized* O(1) time per append. Speed of indexed list access is much more important in most apps than speed of append, but Python has good O() behavior for both. O() behavior for deleting (or inserting) "in the middle" of a list is atrocious, though (O(len(list)). Life is a never-ending sequence of tradeoffs . -- For full context see http://groups.google.com/g/2e77fef2/t/82ee7a80757e84ab/d/6d1c154901794bb Emile From marko.loparic at gmail.com Sun Nov 8 17:41:27 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 8 Nov 2009 14:41:27 -0800 (PST) Subject: advice needed for lazy evaluation mechanism Message-ID: Hi, Could you please give me some advice on the piece of code I am writing? My system has several possible outputs, some of them are not always needed. I started to get confused with the code flow conditions needed to avoid doing unnecessary work. So I am trying to restructure it using lazy evaluation. In the new mechanism I am coding I have a repository with two types of objects: infos and routines. In the begining I have a list of routines. Each routine tells which infos it can compute. The execution is triggered when the value of an info is requested. In the example below I have 3 routines Routine "ReadData" computes info "gender" and info "birth_year" Routine "YearToAge" computes info "age" (using info "birth_year") Routine "ComputeMHF" computes info "max_heart_frequency" (using info "gender" and info "age") /--> gender ----------------------------\ ReadData --| | --> ComputeMHF -- > max_heart_frequency \--> birth_year --> YearToAge --> age --/ So for instance if all I need is info "age", only the routines "ReadData" and "YearToAge" are computed. The code below implements the example. There are 3 files: - test.py: the test case for the example - routines.py: the routines (classes) of the example - repository.py: the lazy evaluation mechanism (independent of the example) My questions are: - Is there a more standard (pythonic) way to do what I am trying to do? Are there libraries, design patterns, functional programming structures to use to achieve what I am looking for (i.e. am I trying to reinvent the wheel)? - Is the coding style good? - Can I avoid the eval command in Repository.add_routine? What I want there is to be able to have a generic code for the repository which does not depend on the files containing the routines I want it to hold. Note: The routines do not need to declare the info they depend on. They request the info in the computation phase. test.py === import unittest from repository import Repository ROUTINE_LIST = """ ReadData routines YearToAge routines ComputeMHF routines """ class Test(unittest.TestCase): def test_age(self): repo = Repository(ROUTINE_LIST) self.assertEqual(repo['age'], 30) def test_max_heart_frequency(self): repo = Repository(ROUTINE_LIST) self.assertEqual(repo['max_heart_frequency'], 181) === routines.py === from repository import AbstractRoutine class ReadData(AbstractRoutine): def __init__(self): super(ReadData, self).__init__(self.__class__.__name__, ['birth_year', 'gender']) def compute(self, repo): repo['birth_year'] = 1979 repo['gender'] = 'F' class YearToAge(AbstractRoutine): def __init__(self): super(YearToAge, self).__init__(self.__class__.__name__, ['age']) def compute(self, repo): repo['age'] = 2009 - repo['birth_year'] class ComputeMHF(AbstractRoutine): def __init__(self): super(ComputeMHF, self).__init__(self.__class__.__name__, ['max_heart_frequency']) def compute(self, repo): gender = repo['gender'] age = repo['age'] mhf = 211 - age if gender == 'F' else 205 - age repo['max_heart_frequency'] = mhf === repostory.py === from StringIO import StringIO class AbstractRoutine(object): def __init__(self, name, infos_provided): self.name = name self.infos_provided = infos_provided self.computed = False def compute(self): raise NotImplementedError class Info(object): def __init__(self, name, routine): self.name = name self.routine = routine self.computed = False self.value = None class Repository(object): def __init__(self, routine_definition_lines): self._infos = {} self.add_routines(routine_definition_lines) def add_routines(self, definition_lines): for line in StringIO(definition_lines): line = line.strip() if line == '': continue name, file_name = line.split() self.add_routine(name, file_name) def add_routine(self, class_name, file_name): routine = None # only to cheat pylint cmd = "from %s import %s\nroutine = %s()" % (file_name, class_name, class_name) exec(cmd) # XXX: ugly if not isinstance(routine, AbstractRoutine): raise ValueError('Class %s is not AbstractRoutine' % class_name) for info_name in routine.infos_provided: info = Info(info_name, routine) self._infos[info_name] = info def __setitem__(self, key, value): if key not in self._infos: raise ValueError('info %s not defined in repository' % key) info = self._infos[key] if info.computed: raise ValueError('info %s has already been computed' % key) info.value = value info.computed = True def __getitem__(self, key): if key not in self._infos: raise ValueError('info %s not defined in repository' % key) info = self._infos[key] if not info.computed: print('Calling routine %s to compute info %s' % (info.routine.name, info.name)) info.routine.compute(self) if not info.computed: raise ValueError('routine %s did not compute info %s' % (info.routine.name, key)) return info.value === Thanks a lot! Marko From lipun4u at gmail.com Sun Nov 8 17:46:24 2009 From: lipun4u at gmail.com (asit) Date: Sun, 8 Nov 2009 14:46:24 -0800 (PST) Subject: fetch all tweets.. Message-ID: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> This question is for any python-twitter developer I want to develop an application using python twitter . Just look at the code... import twitter api = twitter.Api(); sta = api.GetUserTimeline('ShashiTharoor') i = 0 for s in sta: i +=1 print str(i) + " " + s.text print print The above code only fetches 20 tweets. How can I fetch all tweets ?? From wells at submute.net Sun Nov 8 18:01:15 2009 From: wells at submute.net (Wells) Date: Sun, 8 Nov 2009 15:01:15 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? References: Message-ID: <659c7696-7cbe-426e-83b8-b8af5c6a3457@k19g2000yqc.googlegroups.com> On Nov 8, 2:42?pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. Here is the long answer: > > For objects p and q, p==q implies hash(p)==hash(q). It is essential for > dicts and sets that objects used as keys/elements uphold this law, and > also that, for an object o, hash(o) doesn't change during the lifetime > of o. What if you write a class that doesn't? Let's see: > > >>> class Thing(object): > > ... ? ? def __init__(self, value): > ... ? ? ? ? self.value = value > ... ? ? def __eq__(self, other): > ... ? ? ? ? return self.value == other.value > ... ? ? def __hash__(self): > ... ? ? ? ? return hash(self.value) > ... ? ? def __repr__(self): > ... ? ? ? ? return "Thing(%s)" % self.value > ... > > >>> thinglist = [Thing(i) for i in xrange(10)] > > >>> thingdict = dict((y,x) for x,y in enumerate(thinglist)) > > >>> print thingdict[thinglist[5]] > 5 > > >>> thinglist[5].value = 99 > > >>> print thingdict[thinglist[5]] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: Thing(99) > > What happened? __eq__ and __hash__ both depend on a mutable attribute, > and when that attribute was changed, their outcome changed as well. If a > Thing is stored as key in a dict and later it's value attribute is > changed, it cannot be found anymore. Too bad. > > BTW, this doesn't work either: > > >>> print thingdict[Thing(5)] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: Thing(5) > > wheras this works: > > >>> print thingdict[Thing(6)] > > 6 > > What has this got to do with lists and tuples? Well, two tuples x and y > are considered equal, iff: > > >>> all(a==b for a,b in zip(x,y)) > > Also, by the law above, hash(x)==hash(y). Since tuples are immutable, x > and y (and hash(x) and hash(y)) will be equal as long as they live. > > Lists have the same properties regarding equality, but are mutable. > If we'd use a list as key in a dict and append an element to the list, > __eq__ and __hash__ would return something different than before the > append. The list couldn't be found anymore, just like the instance of > the broken Thing class above. Lists are not hashable, because it would > lead to untraceable bugs otherwise, and it would confuse beginners. > > This also teaches a lesson on how to implement __eq__ and __hash__, if > you must. Just make sure your objects always do uphold the law above, > and do not change in respect to __hash__ during their lifetime. OTOH it > is possible to do otherwise, as long as you don't try to use these > objects as elements of a set or keys in a dictionary. But then, why > would you bother to implement your own __hash__ method? > > Regards, > Mick. Thanks Mick - this was very enlightening! From marko.loparic at gmail.com Sun Nov 8 18:04:54 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 8 Nov 2009 15:04:54 -0800 (PST) Subject: advice needed for lazy evaluation mechanism References: Message-ID: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Hi again, I put a copy of the message and the tarball of the code here (because of the problem of line breaks): http://python-advocacy.wikidot.com/comp-lang-python-question Thanks! Marko From mrholtsr at sbcglobal.net Sun Nov 8 18:13:15 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sun, 8 Nov 2009 18:13:15 -0500 Subject: Commenting and uncommenting from the shell Message-ID: <647DC539150C4636B450973AEDB318F9@ray> Can you comment and uncomment code from the shell. I know that the format meny only shows in the edit window. I tried crtl + 3, which is what it said in the configuration window to use, and nothing happens. Also can you write executable code from the edit window. I can't see to get code that I write there to execute. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 8 18:21:23 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 08 Nov 2009 17:21:23 -0600 Subject: fetch all tweets.. In-Reply-To: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> References: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> Message-ID: <4AF75273.6060708@tim.thechases.com> > This question is for any python-twitter developer while I don't use python-twitter, I do use Andrew Price's Twyt for my python+twitter scripting (I started to type "python+twitter scripting needs", but "needs" is SOOOOoooo not the right word for anything regarding twitter). > import twitter > > api = twitter.Api(); > sta = api.GetUserTimeline('ShashiTharoor') > i = 0 > for s in sta: > i +=1 > print str(i) + " " + s.text > print > > The above code only fetches 20 tweets. How can I fetch all tweets ?? I believe the API limits to 200 tweets. With twyt, I can just ask for .status_user_timeline(count=200) and get the last 200 tweets. I can also specify .status_user_timeline(count=200, since=tweet_id) to get those since a particular tweet. Your twitter API may have similar tools to specify the count, the starting ID, or the "page#" like twyt does. -tkc From sven at uni-hd.de Sun Nov 8 18:59:53 2009 From: sven at uni-hd.de (sven) Date: Sun, 8 Nov 2009 15:59:53 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <310944e8-ee2e-4bcc-b7f3-6d736c2000a4@z41g2000yqz.googlegroups.com> On Nov 8, 2:50?pm, exar... at twistedmatrix.com wrote: > I'm curious how this visualization works, since earlier you said > something to the affect that there were no shared resources. ?If you > kill a thread and it had opened a window and was drawing on it, with > most toolkits, you'll end up with a window stuck in your screen, won't > you? The Python code passes an array to the C library which in the end contains the computation results. This array only contains some kind of counts which are incremented during the computation. The PyGTK GUI simply visualizes the current state of this array in regular intervals. The C library does not do any GUI stuff. Cancelling the thread really would not do any harm -- the thread only allocates memory on the stack, and the stack will vanish with the thread. > The CPython philosophy sort of follows the guideline that you should be > allowed to do bad stuff if you want, except when that bad stuff would > crash the interpreter (clearly ctypes is an exception to this rule of > thumb). Well, I am really glad about that exception. And following the hint of Carl, I will use it to call pthread_cancel or pthread_kill directly from the library. (Most certainly I also have to use ctypes to create my threads to be able to do this.) Cheers, Sven From clp2 at rebertia.com Sun Nov 8 19:18:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Nov 2009 16:18:54 -0800 Subject: Commenting and uncommenting from the shell In-Reply-To: <647DC539150C4636B450973AEDB318F9@ray> References: <647DC539150C4636B450973AEDB318F9@ray> Message-ID: <50697b2c0911081618n47bca13bt1e227c7376422e06@mail.gmail.com> On Sun, Nov 8, 2009 at 3:13 PM, Ray Holt wrote: > Can you comment and uncomment code from the shell. I know that the format > meny only shows in the edit window. I tried crtl + 3, which is what it said > in the configuration window to use, and nothing happens. I'm assuming by "the shell" you mean IDLE's Python shell. You would do better to be less vague in the future. No, you can't use the un/comment features in the shell. Using them wouldn't make much sense anyway given the shell's interactive nature. > Also can you write > executable code from the edit window. I can't see to get code that I write > there to execute. Yes, of course. Press F5 or choose Run -> Run Module from the menu. Cheers, Chris -- http://blog.rebertia.com From fordhaivat at gmail.com Sun Nov 8 19:22:16 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sun, 8 Nov 2009 19:22:16 -0500 Subject: Tax Calculator--Tkinter Message-ID: I'm writing a simple tax calculator with Tkinter (just for fun). Here's my current code: from Tkinter import *; class TaxCalc: def __init__(self, root): rate=Frame(root) rate.pack() income=Frame(root) income.pack() result=Frame(root) result.pack() self.rate=Entry(rate); self.rate.pack(); self.enterr=Button(rate) self.enterr['text']="Enter tax rate"; self.enterr['command']=self.getRate; self.enterr.pack() self.income=Entry(income); self.income.pack(); self.enteri=Button(income); self.enteri['text']="Enter income"; self.enterr['command']=self.getIncome; self.enteri.pack(); self.result=Entry(result); self.result.pack(); self.entere=Button(result); self.entere['text']="Get result"; self.entere['command']=self.printResult; self.entere.pack(); def getRate(self): srate=self.rate.get(); print "srate: ", srate; def getIncome(self): sincome=self.income.get(); print "sincome: ", sincome; def printResult(self): if self.nrate is None | self.nincome is None: print "Clear everything and start again."; print "Don't fool around with me."; else: self.nresult=float(((100-self.nrate)/100)*self.nincome); self.result.insert(END, str(self.nresult)); root=Tk() MyCalc=TaxCalc(root) root.mainloop() The thing is, that even if I put "12" in the result text field, get returns an empty string. How can I fix this? From python at mrabarnett.plus.com Sun Nov 8 19:34:24 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Nov 2009 00:34:24 +0000 Subject: advice needed for lazy evaluation mechanism In-Reply-To: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> References: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Message-ID: <4AF76390.5010103@mrabarnett.plus.com> markolopa wrote: > Hi again, > > I put a copy of the message and the tarball of the code here (because > of the problem of line breaks): > > http://python-advocacy.wikidot.com/comp-lang-python-question > Here's a slightly different approach: repository.py ============= class Repository(object): def __init__(self): self._providers = {} self._values = {} def add_provider(self, func, keys): for k in keys: self._providers[k] = func def __getitem__(self, key): if key not in self._values: self._providers[key](self) return self._values[key] def __setitem__(self, key, value): self._values[key] = value def register(*modules): "Register the provider modules and return a repository." repo = Repository() for mod in modules: # Scan the module for providers. # A provider is a function which lists what it provides in its __doc__ string. for name, value in mod.__dict__.items(): if callable(value) and value.__doc__: repo.add_provider(value, value.__doc__.split()) return repo routines.py =========== # The providers are functions which list what they provide in their __doc__ strings. def ReadData(repo): 'birth_year gender' repo['birth_year'] = 1979 repo['gender'] = 'F' def YearToAge(repo): 'age' repo['age'] = 2009 - repo['birth_year'] def ComputeMHF(repo): 'max_heart_frequency' gender = repo['gender'] age = repo['age'] mhf = 211 - age if gender == 'F' else 205 - age repo['max_heart_frequency'] = mhf test.py ======= import unittest import repository import routines class Test(unittest.TestCase): def test_age(self): repo = repository.register(routines) self.assertEqual(repo['age'], 30) def test_max_heart_frequency(self): repo = repository.register(routines) self.assertEqual(repo['max_heart_frequency'], 181) unittest.main() From python at mrabarnett.plus.com Sun Nov 8 19:50:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Nov 2009 00:50:58 +0000 Subject: Tax Calculator--Tkinter In-Reply-To: References: Message-ID: <4AF76772.20408@mrabarnett.plus.com> Someone Something wrote: > I'm writing a simple tax calculator with Tkinter (just for fun). > Here's my current code: > [snip] > def printResult(self): > if self.nrate is None | self.nincome is None: There's no such attribute as nrate or nincome. Also, "|" is the bitwise operator. You probably intended "or" instead. > print "Clear everything and start again."; > print "Don't fool around with me."; > else: > self.nresult=float(((100-self.nrate)/100)*self.nincome); > self.result.insert(END, str(self.nresult)); > Try this instead: def printResult(self): try: rate = float(self.rate.get()) income = float(self.income.get()) result = ((100.0 - rate) / 100.0) * income self.result.insert(END, str(result)) except ValueError: print "Clear everything and start again." print "Don't fool around with me." From gregory.j.baker at gmail.com Sun Nov 8 19:56:40 2009 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Sun, 8 Nov 2009 16:56:40 -0800 (PST) Subject: Query about doing fortran-esque repeat formatting References: Message-ID: <789ba085-5199-450f-9c5b-b5bf4e8767d7@r24g2000prf.googlegroups.com> How about: print ('%s ' + '%-5.4f ' * 7) % ('text',1,2,3,4,5,6,7) From patf at well.com Sun Nov 8 21:36:50 2009 From: patf at well.com (menomnon) Date: Sun, 8 Nov 2009 18:36:50 -0800 (PST) Subject: Debugging python in emacs isn't working. Message-ID: <4a54b1ba-0fd8-4947-9ca0-67d5c98de2d9@k13g2000prh.googlegroups.com> Hi, Emacs 22.3, python 2.6.4 Put the following into my .emacs: (setq pdb-path 'c:\\python26\\lib\\pdb.py gud-pdb-command-name (symbol-name pdb-path)) (defadvice pdb (before gud-query-cmdline activate) "Provide a better default command line when called interactively." (interactive (list (gud-query-cmdline pdb-path (file-name-nondirectory buffer-file-name))))) So when I'm in a python buffer (I've tried both python.el and python- mode.el) and do M-x pdb I get, say: c:\python26\lib\pdb.py rpytest.py hit and get an empty buffer that says "Comint: no process". And the status line says: "Spawning child process: invalid argument". I've run into "spawning child process: invalid argument" before but not being an emacs uber-geek I never solved it directly. Hope someone has an idea of what I'm doing wrong. From alan at baselinedata.co.uk Sun Nov 8 21:38:16 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 02:38:16 +0000 Subject: String prefix question Message-ID: <4AF78098.1060509@baselinedata.co.uk> In the Python.org 3.1 documentation (section 20.4.6), there is a simple ?Hello World? WSGI application which includes the following method... def hello_world_app(environ, start_response): status = b'200 OK' # HTTP Status headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers start_response(status, headers) # The returned object is going to be printed return [b"Hello World"] Question - Can anyone tell me why the 'b' prefix is present before each string? The method seems to work equally well with and without the prefix. From what I can gather from the documentation the b prefix represents a bytes literal, but can anyone explain (in simple english) what this means? Many thanks, Alan From ben+python at benfinney.id.au Sun Nov 8 22:01:23 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2009 14:01:23 +1100 Subject: String prefix question References: Message-ID: <87vdhk2ygs.fsf@benfinney.id.au> Alan Harris-Reid writes: > From what I can gather from the documentation the b prefix represents > a bytes literal Yes. In Python 3 there are two types with similar-looking literal syntax: ?str? and ?bytes?. The types are mutually incompatible (though they can be explicitly converted). > but can anyone explain (in simple english) what this means? It means the difference between ?a sequence of bytes? and ?a sequence of characters?. The two are not the same, have not ever been the same despite a long history in computing of handwaving the differences, and Python 3 finally makes them unambiguously distinct. A general solution wasn't even feasible for a long time, but now we have Unicode, a mature standard for uniformly representing all the world's writing systems in software. So Python 3 made ?str? the Unicode ?string of characters? type, and the ?'foo'? literal syntax creates objects of this type. The Python 3.1 documentation has a Unicode HOWTO that you should read . -- \ ?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 benjamin.kaplan at case.edu Sun Nov 8 22:04:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Nov 2009 22:04:04 -0500 Subject: String prefix question In-Reply-To: <4AF78098.1060509@baselinedata.co.uk> References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: On Sun, Nov 8, 2009 at 9:38 PM, Alan Harris-Reid wrote: > In the Python.org 3.1 documentation (section 20.4.6), there is a simple > ?Hello World? WSGI application which includes the following method... > > def hello_world_app(environ, start_response): > status = b'200 OK' # HTTP Status > headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers > start_response(status, headers) > > # The returned object is going to be printed > return [b"Hello World"] > > Question - Can anyone tell me why the 'b' prefix is present before each > string? The method seems to work equally well with and without the prefix. > From what I can gather from the documentation the b prefix represents a > bytes literal, but can anyone explain (in simple english) what this means? > > Many thanks, > Alan The rather long version: read http://www.joelonsoftware.com/articles/Unicode.html A somewhat shorter summary, along with how Python deals with this: Once upon a time, someone decided to allocate 1 byte for each character. Since everything the Americans who made the computers needed fit into 7 bits, this was alright. And they called this the American Standard Code for Information Interchange (ASCII). When computers came along, device manufacturers realized that they had 128 characters that didn't mean anything, so they all made their own characters to show for the upper 128. And when they started selling computers internationally, they used the upper 128 to store the characters they needed for the local language. This had several problems. 1) Files made by on one computer in one country wouldn't display right in a computer made by a different manufacturer or for a different country 2) The 256 characters were enough for most Western languages, but Chinese and Japanese need a whole lot more. To solve this problem, Unicode was created. Rather than thinking of each character as a distinct set of bits, it just assigns a number to each one (a code point). The bottom 128 characters are the original ASCII set, and everything else you could think of was added on top of that - other alphabets, mathematical symbols, music notes, cuneiform, dominos, mah jong tiles, and more. Unicode is harder to implement than a simple byte array, but it means strings are universal- every program will interpret them exactly the same. Unicode strings in python are the default ('') in Python 3.x and created in 2.x by putting a u in front of the string declaration (u'') Unicode, however, is a concept, and concepts can't be mapped to bits that can be sent through the network or stored on the hard drive. So instead we deal with strings internally as Unicode and then give them an encoding when we send them back out. Some encodings, such as UTF-8, can have multiple bytes per character and, as such, can deal with the full range of Unicode characters. Other times, programs still expect the old 8-bit encodings like ISO-8859-1 or the Windows Ansi code pages. In Python, to declare that the string is a literal set of bytes and the program should not try and interpret it, you use b'' in Python 3.x, or just declare it normally in Python 2.x (''). ------------------------------------------------------ What happens in your program: When you print a Unicode string, Python has to decide what encoding to use. If you're printing to a terminal, Python looks for the terminal's encoding and uses that. In the event that it doesn't know what encoding to use, Python defaults to ASCII because that's compatible with almost everything. Since the string you're sending to the web page only contains ASCII characters, the automatic conversion works fine if you don't specify the b''. Since the resulting page uses UTF-8 (which you declare in the header), which is compatible with ASCII, the output looks fine. If you try sending a string that has non-ASCII characters, the program might throw a UnicodeEncodeError because it doesn't know what bytes to use for those characters. It may be able to guess, but since I haven't used WSGI directly before, I can't say for sure. From SD_V897 at NoSuchMail.Com Sun Nov 8 22:04:55 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Mon, 09 Nov 2009 03:04:55 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Fri, 06 Nov 2009 21:19:44 GMT, SD_V897 > declaimed the following in gmane.comp.python.general: > >> AppPath=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe > > That's an interesting path... Did the install path for Python (from > either python.org or activestate) change that much from 2.5.x, or is > that a custom install path (and is it the same path for the accounts it > works in). Especially as there is no "v2.62" to my knowledge... a 2.6.2, > OTOH... > > Now... I did change the upper level directory for mine (E:\; my C: > partition is rather packed, and I tend to install a lot of packages from > my user account), but the installer named top level was > "\Python25\pythonw.exe" > > I've added the folder directory to my PATH statement and also tried installing to the root but it doesn't make a difference. The 2.62 should be 2.64 my bad.. SD From redplusbluemakespurple at gmail.com Sun Nov 8 22:18:28 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Sun, 8 Nov 2009 19:18:28 -0800 (PST) Subject: Help with OS X installation References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: <81a156f8-47a3-4690-9df1-59ed62326c64@o10g2000yqa.googlegroups.com> Thanks all. That did it. From highcar at gmail.com Sun Nov 8 23:39:59 2009 From: highcar at gmail.com (elca) Date: Sun, 8 Nov 2009 20:39:59 -0800 (PST) Subject: disable image loading to speed up webpage load In-Reply-To: <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> References: <26155440.post@talk.nabble.com> <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> Message-ID: <26261219.post@talk.nabble.com> Tim Roberts wrote: > > elca wrote: >> >>im using win32com 's webbrowser module. > > Win32com does not have a webbrowser module. Do you mean you are using > Internet Explorer via win32com? > >>i have some question about it.. >>is it possible to disable image loading to speed up webpage load? > > If you are using IE, then you need to tell IE to disable image loading. I > don't know a way to do that through the IE COM interface. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, yes right, i mean IE com interface. thanks for your reply.. if anyone can help much appreciate ! -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26261219.html Sent from the Python - python-list mailing list archive at Nabble.com. From anthoniraja at gmail.com Sun Nov 8 23:49:13 2009 From: anthoniraja at gmail.com (Antony) Date: Sun, 8 Nov 2009 20:49:13 -0800 (PST) Subject: Choosing GUI Module for Python Message-ID: Hi all I just wanted to know which module is best for developing designing interface in python . i have come across some modules which are listed here . please tell your suggestions and comments to choose best one 1. PyGTK 2. PyQT 3. PySide 4. wxPython 5 . TKinter Also i need to know is there any IDE for developing these things . . . From nagle at animats.com Mon Nov 9 00:04:06 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 21:04:06 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> Message-ID: <4af7a083$0$1677$742ec2ed@news.sonic.net> Antoine Pitrou wrote: > John Nagle animats.com> writes: >> I'd argue against general thread cancellation. Inter-thread >> signals, though, have safety problems no worse than the first-thread >> only signals we have now. You're allowed to raise an exception >> in a signal handler, which is effectively thread cancellation. > > Can you give an example of such "cancellation"? > In any case, this would be a side-effect of the current implementation, not > officially supported behaviour. It's not only documented behavior, it's an example in the official documentation. See http://docs.python.org/library/signal.html#example where an exception is raised in a signal handler. John Nagle From rt8396 at gmail.com Mon Nov 9 01:49:19 2009 From: rt8396 at gmail.com (r) Date: Sun, 8 Nov 2009 22:49:19 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> On Nov 8, 10:49?pm, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . You may want to offer a little more info, like what exactly you are looking to do with such GUI. are your needs for a VW, Corvette, or Mercedes? etc, etc. All these kits have pros and cons, some better for this some for that, yadda yadda From s.selvamsiva at gmail.com Mon Nov 9 02:21:33 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Mon, 9 Nov 2009 12:51:33 +0530 Subject: how to remove the same words in the paragraph In-Reply-To: <4AF0B54A.7090602@tim.thechases.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote: > kylin wrote: > >> I need to remove the word if it appears in the paragraph twice. could >> some give me some clue or some useful function in the python. >> > > Sounds like homework. To fail your class, use this one: > > >>> p = "one two three four five six seven three four eight" > >>> s = set() > >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) > one two three four five six seven eight > > which is absolutely horrible because it mutates the set within the list > comprehension. The passable solution would use a for-loop to iterate over > each word in the paragraph, emitting it if it hadn't already been seen. > Maintain those words in set, so your words know how not to be seen. ("Mr. > Nesbitt, would you please stand up?") > > This also assumes your paragraph consists only of words and whitespace. > But since you posted your previous homework-sounding question on stripping > out non-word/whitespace characters, you'll want to look into using a regexp > like "[\w\s]" to clean up the cruft in the paragraph. Neither solution > above preserves non white-space/word characters, for which I'd recommend > using a re.sub() with a callback. Such a callback class might look > something like > > >>> class Dedupe: > ... def __init__(self): > ... self.s = set() > ... def __call__(self, m): > ... w = m.group(0) > ... if w in self.s: return '' > ... self.s.add(w) > ... return w > ... > >>> r.sub(Dedupe(), p) > > where I leave the definition of "r" to the student. Also beware of > case-differences for which you might have to normalize. > > You'll also want to use more descriptive variable names than my one-letter > tokens. > > -tkc > > > I think simple regex may come handy, p=re.compile(r'(.+) .*\1') #note the space s=p.search("python and i love python") s.groups() (' python',) But that matches for only one double word.Someone else could light up here to extract all the double words.Then they can be removed from the original paragraph. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam Sent from Bangalore, KA, India -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 9 02:39:34 2009 From: rt8396 at gmail.com (r) Date: Sun, 8 Nov 2009 23:39:34 -0800 (PST) Subject: Indentation problems References: Message-ID: <3de2d9d6-f4a8-4ecc-b86b-c3f4dd2373d3@n35g2000yqm.googlegroups.com> On Nov 8, 1:48?pm, Tim Chase wrote: > > I am having problems with indentation some times. When I hit the enter key > > after if statements or while statemt there are times when the indentation is > > too much and other times too little. Check for omitted brackets, braces and parenthesis. If you editor uses an auto indent function like even IDLE does then this will be the culprit! From anthoniraja at gmail.com Mon Nov 9 03:59:33 2009 From: anthoniraja at gmail.com (Antony) Date: Mon, 9 Nov 2009 00:59:33 -0800 (PST) Subject: Choosing GUI Module for Python References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> Message-ID: <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> On Nov 9, 11:49?am, r wrote: > On Nov 8, 10:49?pm, Antony wrote: > > > Hi all > > ? ?I just wanted to know which module is best for developing designing > > interface in python . > > i have come across some modules which are listed here . please tell > > your suggestions and comments to choose best one > > ?1. PyGTK > > ?2. PyQT > > ?3. PySide > > ?4. ?wxPython > > ?5 . TKinter > > > Also i need to know is there any IDE for developing these > > things . . . > > You may want to offer a little more info, like what exactly you are > looking to do with such GUI. are your needs for a ?VW, Corvette, or > Mercedes? etc, etc. All these kits have pros and cons, some better for > this some for that, yadda yadda I would like to know about that pros and cons only ... From highcar at gmail.com Mon Nov 9 06:48:19 2009 From: highcar at gmail.com (elca) Date: Mon, 9 Nov 2009 03:48:19 -0800 (PST) Subject: how to close not response win32 IE com interface Message-ID: <26265055.post@talk.nabble.com> hello, these day im making some script that use win32 IE com interface. one of problem is , my internet line is very slow, so sometimes my IE.navigate("http://www.example.com") not response timely. it looks hang and open status, not complete status. so my IE.navigate function is not correctly working. anyone can help me? in that case ,how to close or restart my script from start. thanks in advance Paul -- View this message in context: http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26265055.html Sent from the Python - python-list mailing list archive at Nabble.com. From deets at nospam.web.de Mon Nov 9 07:04:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 09 Nov 2009 13:04:30 +0100 Subject: installing library on MAC OS X 10.5.8 In-Reply-To: <9e367ea7-8a7d-4665-aa64-52a5cc705a18@h34g2000yqm.googlegroups.com> References: <9e367ea7-8a7d-4665-aa64-52a5cc705a18@h34g2000yqm.googlegroups.com> Message-ID: <7lqeqeF3e33mrU1@mid.uni-berlin.de> Xbiton schrieb: > Hi, > I'm new to mac and I'm having a lot of problems installing library on > mac ox x 10.5.8. > I want to install PyXML and although the install procedure - just done > like described on the web page of PyXML - That's a 5-years-old XML package. Don't use it. Your python2.5 already features element-tree, which is much nicer to use. Or is there a specific reason you need PyXML? Diez From zondo42 at googlemail.com Mon Nov 9 07:05:54 2009 From: zondo42 at googlemail.com (Glenn Hutchings) Date: Mon, 9 Nov 2009 12:05:54 +0000 (UTC) Subject: Query about doing fortran-esque repeat formatting References: <1257692178.27566.38.camel@vostok.physics.mun.ca> Message-ID: Rob Briggs mun.ca> writes: > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > tmp[i][8], tmp[i][9]) There certainly is. You can use python's string concatenation and repeat operators: print "%s" + " %-5.3f" * 7 % Glenn From dan.winsor at gmail.com Mon Nov 9 07:10:25 2009 From: dan.winsor at gmail.com (Dan Winsor) Date: Mon, 9 Nov 2009 04:10:25 -0800 (PST) Subject: username/password dialog prompt References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> <4af4904b$0$83240$e4fe514c@news.xs4all.nl> Message-ID: <6431ce76-6290-449d-a491-f884bf2ec2bc@e34g2000vbc.googlegroups.com> On Nov 6, 4:40?pm, Cousin Stanley wrote: > > My Tkinter is very rusty but perhaps you could do it > > something like this : ?http://pastebin.com/m5e49da19 > > > I forgot how to get rid of the empty root window > > that appears, sorry. > > ? root.withdraw() ? # should do it Thanks to you both - exactly what I was looking for. Much appreciated. -- Dan Winsor Soy un poco loco en el coco. From python.list at tim.thechases.com Mon Nov 9 07:13:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 09 Nov 2009 06:13:30 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: <4AF8076A.30005@tim.thechases.com> > I think simple regex may come handy, > > p=re.compile(r'(.+) .*\1') #note the space > s=p.search("python and i love python") > s.groups() > (' python',) > > But that matches for only one double word.Someone else could light up here > to extract all the double words.Then they can be removed from the original > paragraph. This has multiple problems: >>> p = re.compile(r'(.+) .*\1') >>> s = p.search("python one two one two python") >>> s.groups() ('python',) >>> s = p.search("python one two one two python one") >>> s.groups() # guess what happened to the 2nd "one"... ('python one',) and even once you have the list of theoretical duplicates (by changing the regexp to r'\b(\w+)\b.*?\1' perhaps), you still have to worry about emitting the first instance but not subsequent instances. -tkc From solipsis at pitrou.net Mon Nov 9 07:20:44 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 9 Nov 2009 12:20:44 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> <4af7a083$0$1677$742ec2ed@news.sonic.net> Message-ID: Le Sun, 08 Nov 2009 21:04:06 -0800, John Nagle a ?crit?: > Antoine Pitrou wrote: >> John Nagle animats.com> writes: >>> I'd argue against general thread cancellation. Inter-thread >>> signals, though, have safety problems no worse than the first-thread >>> only signals we have now. You're allowed to raise an exception in a >>> signal handler, which is effectively thread cancellation. >> >> Can you give an example of such "cancellation"? In any case, this would >> be a side-effect of the current implementation, not officially >> supported behaviour. > > It's not only documented behavior, it's an example in the official > documentation. See > > http://docs.python.org/library/signal.html#example Well, the only supported behaviour is to send signals to the main thread. Besides, it doesn't "cancel" the thread, it just raises an exception in it, which can be caught and silenced. Just try the following: import signal, time def handler(signum, frame): print 'Signal handler called with signal', signum raise IOError # Set the signal handler and a 5-second alarm signal.signal(signal.SIGALRM, handler) signal.alarm(2) try: time.sleep(10) except IOError: print "got IOError!" From jeanmichel at sequans.com Mon Nov 9 07:31:00 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 09 Nov 2009 13:31:00 +0100 Subject: Query about doing fortran-esque repeat formatting In-Reply-To: References: <1257692178.27566.38.camel@vostok.physics.mun.ca> Message-ID: <4AF80B84.2010200@sequans.com> Glenn Hutchings wrote: > Rob Briggs mun.ca> writes: > > >> Is there a way to do a repeat formatting command like in Fortran? Rather >> that doing this: >> >> print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % >> (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], >> tmp[i][8], tmp[i][9]) >> > > There certainly is. You can use python's string concatenation > and repeat operators: > > print "%s" + " %-5.3f" * 7 % > > Glenn > > data = tuple(parmName[i]) + tuple(tmp[i]) print "%s" + " %-5.3f" * len(tmp[i]) % data That should do the trick. JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From emin.shopper at gmail.com Mon Nov 9 07:45:32 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 9 Nov 2009 07:45:32 -0500 Subject: ANN: superpy 1.2.1 Message-ID: <32e43bb70911090445jf654264ha79d20a9edb3bc7e@mail.gmail.com> I am pleased to announce the release of superpy 1.2.1 available from http://code.google.com/p/superpy. As this is the first announcement of superpy, any comments and feedback would be much appreciated. ------------------ Superpy distributes python programs across a cluster of machines or across multiple processors on a single machine. This is a coarse-grained form of parallelism in the sense that remote tasks generally run in separate processes and do not share memory with the caller. Key features of superpy include: * Send tasks to remote servers or to same machine via XML RPC call * GUI to launch, monitor, and kill remote tasks * GUI can automatically launch tasks every day, hour, etc. * Works on the Microsoft Windows operating system o Can run as a windows service o Jobs submitted to windows can run as submitting user or as service user * Inputs/outputs are python objects via python pickle * Pure python implementation * Supports simple load-balancing to send tasks to best servers The ultimate vision for superpy is that you: 1. Install it as an always on service on a cloud of machines 2. Use the superpy scheduler to easily send python jobs into the cloud as needed 3. Use the SuperWatch GUI to track progress, kill tasks, etc. For smaller deployments, you can use superpy to take advantage of multiple processors on a single machine or multiple machines to maximize computing power. What makes superpy different than the many other excellent parallel processing packages already available for python? The superpy package is designed to allow sending jobs across a large number of machines (both Windows and LINUX). This requires the ability to monitor, debug, and otherwise get information about the status of jobs. While superpy is currently used in production for a number of different purposes, there are still many features we want to add. For a list of future plans and opportunities to help out or add to the discussion, please visit http://code.google.com/p/superpy/wiki/HelpImproveSuperpy. For a quick example of some of the the things superpy can do, check out http://code.google.com/p/superpy/wiki/Demos or in particular the demo application PyFog at http://code.google.com/p/superpy/wiki/PyFog. To install, you can use easy_install to try superpy via "easy_install superpy" or download a python egg from downloads. Of course, you will need python installed and if you are using windows, you should also install the python windows tools from http://sourceforge.net/projects/pywin32/files. See http://code.google.com/p/superpy/wiki/InstallFAQ if you have more questions about installation. From marko.loparic at gmail.com Mon Nov 9 08:14:19 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 9 Nov 2009 05:14:19 -0800 (PST) Subject: advice needed for lazy evaluation mechanism References: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Message-ID: <05e1446a-c579-43ef-89b3-324e1a2f32a5@37g2000yqm.googlegroups.com> On Nov 9, 1:34?am, MRAB wrote: > markolopa wrote: > > Hi again, > > > I put a copy of the message and the tarball of the code here (because > > of the problem of line breaks): > > >http://python-advocacy.wikidot.com/comp-lang-python-question > > Here's a slightly different approach: A clean and elegant solution, very impressive! Also a collection of nice Python features I had never used. Thanks a lot! Marko From pinkisntwell at gmail.com Mon Nov 9 08:53:00 2009 From: pinkisntwell at gmail.com (pinkisntwell) Date: Mon, 9 Nov 2009 05:53:00 -0800 (PST) Subject: OT: regular expression matching multiple occurrences of one group Message-ID: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> How can I make a regular expression that will match every occurrence of a group and return each occurrence as a group match? For example, for a string "-c-c-c-c-c", how can I make a regex which will return a group match for each occurrence of "-c"? From ssteinerx at gmail.com Mon Nov 9 09:21:33 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 09:21:33 -0500 Subject: Choosing GUI Module for Python In-Reply-To: <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> Message-ID: <2B0D56A2-8CEC-4FF1-AFF2-D7DA66F9A171@gmail.com> On Nov 9, 2009, at 3:59 AM, Antony wrote: >> >> You may want to offer a little more info, like what exactly you are >> looking to do with such GUI. are your needs for a VW, Corvette, or >> Mercedes? etc, etc. All these kits have pros and cons, some better >> for >> this some for that, yadda yadda > > I would like to know about that pros and cons only ... What might be a "pro" for one use case could easily be a "con" for another. For example, Kit-X may be infinitely configurable to run on everything from 800x600 to 1680x1050 pixel monitors with full viewport control, full zoom, pan, etc. and requires that all those cases be handled with correct configuration. That's great if you're writing an application that requires that. But, if you're writing a Pref Pane for OS X, which will never be any bigger than the pref-pane window and will only run on OS X, that particular kit might be a huge waste of time. The "pro" of infinite flexibility becomes a huge "con" for the OS X Pref Pane use-case. S From __peter__ at web.de Mon Nov 9 09:27:28 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Nov 2009 15:27:28 +0100 Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: J Wolfe wrote: > I would like to sort this dictionary by the values of the inner > dictionary ?ob? key. Python's built-in dictionary is unsorted by design. > mydict = > {?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?}, > ?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?} > } > > In this case, this would become: > > mysorteddic = > {?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?}, > ?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?} > } > > I have had no luck in trying to figure this out. I am restricted to > using python 2.4.3. > > Any help would be appreciated! You may be able to work around that limitation by putting the dict items into a list and sort that: >>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), reverse=True): ... print item ... ('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'}) ('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'}) ('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'}) Peter From victorsubervi at gmail.com Mon Nov 9 09:32:21 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 09:32:21 -0500 Subject: CGI vs mod_python Message-ID: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> Hi; I've been told by a server farm that they're having trouble getting my scripts to work because they're written with cgi calls as opposed to mod_python. Is there a basis for their complaint? These pages serve fine on another server. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Mon Nov 9 09:46:54 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 09:46:54 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> Message-ID: <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote: > Hi; > I've been told by a server farm that they're having trouble getting > my scripts to work because they're written with cgi calls as opposed > to mod_python. Is there a basis for their complaint? These pages > serve fine on another server. Does the server they're working fine on use CGI? Yes, they're different. S From rdbriggs at mun.ca Mon Nov 9 09:53:23 2009 From: rdbriggs at mun.ca (Rob Briggs) Date: Mon, 09 Nov 2009 11:23:23 -0330 Subject: Query about doing fortran-esque repeat formatting In-Reply-To: <4AF80B84.2010200@sequans.com> References: <1257692178.27566.38.camel@vostok.physics.mun.ca> <4AF80B84.2010200@sequans.com> Message-ID: <1257778403.19016.2.camel@vostok.physics.mun.ca> Thanks to the chaps who answered, I knew there would be an efficient answer to this. regards, Rob On Mon, 2009-11-09 at 13:31 +0100, Jean-Michel Pichavant wrote: > Glenn Hutchings wrote: > > Rob Briggs mun.ca> writes: > > > > > > > Is there a way to do a repeat formatting command like in Fortran? Rather > > > that doing this: > > > > > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > > > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > > > tmp[i][8], tmp[i][9]) > > > > > > > There certainly is. You can use python's string concatenation > > and repeat operators: > > > > print "%s" + " %-5.3f" * 7 % > > > > Glenn > > > > > > data = tuple(parmName[i]) + tuple(tmp[i]) > print "%s" + " %-5.3f" * len(tmp[i]) % data > > That should do the trick. > > JM From kw at codebykevin.com Mon Nov 9 10:02:48 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 09 Nov 2009 10:02:48 -0500 Subject: Choosing GUI Module for Python In-Reply-To: References: Message-ID: <692af$4af82f19$4275d90a$2778@FUSE.NET> On 11/8/09 11:49 PM, Antony wrote: > Hi all > I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > 1. PyGTK > 2. PyQT > 3. PySide > 4. wxPython > 5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . > http://lmgtfy.com/?q=gui+toolkit+for+python -- Kevin Walzer Code by Kevin http://www.codebykevin.com From victorsubervi at gmail.com Mon Nov 9 10:18:36 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 10:18:36 -0500 Subject: CGI vs mod_python In-Reply-To: <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> Message-ID: <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Yes, obviously. But if CGI is enabled, it should work anyway, should it not? V On Mon, Nov 9, 2009 at 9:46 AM, ssteinerX at gmail.com wrote: > > On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote: > > Hi; >> I've been told by a server farm that they're having trouble getting my >> scripts to work because they're written with cgi calls as opposed to >> mod_python. Is there a basis for their complaint? These pages serve fine on >> another server. >> > > Does the server they're working fine on use CGI? Yes, they're different. > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Mon Nov 9 10:29:54 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 10:29:54 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Message-ID: <6B4B78D7-110E-48AF-9307-1FCD04614717@gmail.com> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: > Yes, obviously. But if CGI is enabled, it should work anyway, should > it not? Depends on what "CGI is enabled" means. Usually, web servers are not set to just handle cgi scripts from anywhere, but only from specific file system locations. Otherwise, an an anonymous upload could be executed as CGI and wreak havoc. And "it should work anyway, should it not" is already answered by "they're having trouble getting my scripts to work." S From jamuah at gmail.com Mon Nov 9 10:45:57 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 17:45:57 +0200 Subject: [PYTHON] How to set the range for x-axis Message-ID: Hi Everyone, I have written a script in python to plot a graph. However, the range for the x-axis starts from 0.5 to 1.0. However, I would like to start from 0 to 1. Any pointer to this shall be appreciated. Thanks, Moses -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 9 10:46:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 09 Nov 2009 16:46:58 +0100 Subject: OT: regular expression matching multiple occurrences of one group In-Reply-To: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <7lqrriF3evehhU1@mid.uni-berlin.de> pinkisntwell schrieb: > How can I make a regular expression that will match every occurrence > of a group and return each occurrence as a group match? For example, > for a string "-c-c-c-c-c", how can I make a regex which will return a > group match for each occurrence of "-c"? Why is this flagged "OT"? And in python, you can't do that. Groups are based upon the lexical structure of the regexp, and thus have a fixed number of groups. Either use repetitive searches over the input, or postprocess the combined group by e.g. splitting it. Diez From clp2 at rebertia.com Mon Nov 9 10:49:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Nov 2009 07:49:33 -0800 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: Message-ID: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: > I have written a script in python to plot a graph. However, the > range for the x-axis starts from 0.5 to 1.0. However, I would like > to start from 0 to 1. Any pointer to this shall be appreciated. Some /very/ basic information such as what plotting library you're using would be necessary to answer your question. What version of Python you're using would also be useful. Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Mon Nov 9 10:52:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 10:52:39 -0500 Subject: CGI vs mod_python In-Reply-To: <65E266A7-DB3C-44D0-9085-8F0338FA29BC@gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <6B4B78D7-110E-48AF-9307-1FCD04614717@gmail.com> <4dc0cfea0911090741k5674c529xb6f9b4eb8fdc631a@mail.gmail.com> <65E266A7-DB3C-44D0-9085-8F0338FA29BC@gmail.com> Message-ID: <4dc0cfea0911090752t4d09587ap588d5e57329889ca@mail.gmail.com> Uuuuh. Thanks! V On Mon, Nov 9, 2009 at 10:45 AM, ssteinerX at gmail.com wrote: > On Nov 9, 2009, at 10:41 AM, Victor Subervi wrote: > > On Mon, Nov 9, 2009 at 10:29 AM, ssteinerX at gmail.com wrote: > >> >> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: >> >> Yes, obviously. But if CGI is enabled, it should work anyway, should it >>> not? >>> >> >> Depends on what "CGI is enabled" means. >> >> Usually, web servers are not set to just handle cgi scripts from anywhere, >> but only from specific file system locations. Otherwise, an an anonymous >> upload could be executed as CGI and wreak havoc. >> > > Of course, yes. > >> >> And "it should work anyway, should it not" is already answered by "they're >> having trouble getting my scripts to work." >> > > They're having _all_sorts_of_trouble_ getting my scripts to work, not just > this issue. These scripts worked fine on another server. I don't understand > what the problems are, and I'm trying to parameterize. > > > Gotcha. > > Do you have access to and have you given them the old httpd.conf? > > That could certainly give them some clues about what's different. > > Also, there is (on apache 2.x+ anyway) a whole directory tree full of > included files that get sucked in as the configuration is getting built so > that whole tree would give them everything they would need (if they know how > to work from it which they should if they're running a "server farm"). > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Mon Nov 9 10:59:53 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 07:59:53 -0800 (PST) Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <6236e9a0-7662-4935-a65d-6cbcd61c6f92@o10g2000yqa.googlegroups.com> On Nov 9, 1:53?pm, pinkisntwell wrote: > How can I make a regular expression that will match every occurrence > of a group and return each occurrence as a group match? For example, > for a string "-c-c-c-c-c", how can I make a regex which will return a > group match for each occurrence of "-c"? As well as what Diez has said, unless you absolutely want regexp's, and by the sounds of it I'm guessing you may be after something more flexible: what about the pyparsing module [1]. It handles your situation quite nicely. >>> import pyparsing >>> parser = pyparsing.ZeroOrMore('-c') >>> parser.parseString('-c-c-c-c-c-c') (['-c', '-c', '-c', '-c', '-c', '-c'], {}) hth, Jon. [1] http://pyparsing.wikispaces.com/ From alfps at start.no Mon Nov 9 11:10:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 17:10:31 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) Message-ID: Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. It's now Python 3.x, and reworked with lots of graphical examples and more explanatory text, plus limited in scope to Basic Concepts (which I previously just had as a first ch 2 section -- but there's rather a lot of concepts!). I think it's wise to invite comments even when it's not 100% completed. First, because as opposed to ch 1 there is quite a bit of code here, and since I'm a Python newbie I may be using non-idiomatic constructs, not to mention doing worse things. :-) Second, because comments in general can improve the text. Contents: 2.1 Super-basic concept: why programming is not DWIM. 1 2.2 Reported errors. 4 2.2.1 Case-sensitity. 4 2.2.2 Syntax / compilation errors. 4 2.2.3 Runtime errors / crashes. 5 2.3 A programming exploration tool: turtle graphics. 6 2.4 Naming things. 8 2.4.1 Naming actions: routines. 8 2.4.2 Naming data part I: variables. 11 2.4.3 Naming data part II: routine arguments. 13 2.5 Controlling the flow of execution. 14 2.5.1 Repeating actions automatically: loops. 14 2.5.2 Basic comparisions & boolean values. 16 2.5.3 Interlude I: a function graph program / about types. 17 2.5.4 Automated action choices. 21 2.5.5 Value-producing (function-like) routines. 23 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 2.5.7 Dynamically nested actions: recursive routines. 28 2.6 Objects. [Not started on this] 31 2.7 Collections. [Not started on this] 31 In Google Docs (both chapters available here): Formats: PDF Cheers, - Alf From jamuah at gmail.com Mon Nov 9 11:43:25 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 18:43:25 +0200 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: Hi Chris, I am using python 2.6 and am using scipy and pylab. See the code below. Cheers. from scipy import * from pylab import * x1 = [0.5,0.6,0.7,0.8,0.9,1.0] x2 = [0,1,2,3,4,5,6,7,8,9,10] plot(x1,y01,linewidth=5.0) show() Thanks. . On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert wrote: > On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: > > I have written a script in python to plot a graph. However, the > > range for the x-axis starts from 0.5 to 1.0. However, I would like > > to start from 0 to 1. Any pointer to this shall be appreciated. > > Some /very/ basic information such as what plotting library you're > using would be necessary to answer your question. What version of > Python you're using would also be useful. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jamuah at gmail.com Mon Nov 9 11:46:09 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 18:46:09 +0200 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: Hi Chris, The code is from scipy import * from pylab import * x = [0.5,0.6,0.7,0.8,0.9,1.0] y = [2,6,8,10,10,10] plot(x,y,linewidth=5.0) show() and not from scipy import * from pylab import * x1 = [0.5,0.6,0.7,0.8,0.9,1.0] x2 = [0,1,2,3,4,5,6,7,8,9,10] plot(x1,y01,linewidth=5.0) show() Moses On Mon, Nov 9, 2009 at 6:43 PM, Moses wrote: > > Hi Chris, > > I am using python 2.6 and am using scipy and pylab. See the code below. > Cheers. > > from scipy import * > from pylab import * > > x1 = [0.5,0.6,0.7,0.8,0.9,1.0] > x2 = [0,1,2,3,4,5,6,7,8,9,10] > > plot(x1,y01,linewidth=5.0) > show() > > Thanks. > . > > > > On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert wrote: > >> On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: >> > I have written a script in python to plot a graph. However, the >> > range for the x-axis starts from 0.5 to 1.0. However, I would like >> > to start from 0 to 1. Any pointer to this shall be appreciated. >> >> Some /very/ basic information such as what plotting library you're >> using would be necessary to answer your question. What version of >> Python you're using would also be useful. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Mon Nov 9 11:53:43 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 09 Nov 2009 16:53:43 +0000 Subject: String prefix question In-Reply-To: <4AF78098.1060509@baselinedata.co.uk> References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: Alan Harris-Reid wrote: > In the Python.org 3.1 documentation (section 20.4.6), there is a simple > ?Hello World? WSGI application which includes the following method... > > def hello_world_app(environ, start_response): > status = b'200 OK' # HTTP Status > headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers > start_response(status, headers) > > # The returned object is going to be printed > return [b"Hello World"] > > Question - Can anyone tell me why the 'b' prefix is present before each > string? The method seems to work equally well with and without the > prefix. From what I can gather from the documentation the b prefix > represents a bytes literal, but can anyone explain (in simple english) > what this means? > > Many thanks, > Alan Another link: http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror From joncle at googlemail.com Mon Nov 9 11:54:40 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 08:54:40 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: Message-ID: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> On Nov 9, 4:10?pm, "Alf P. Steinbach" wrote: > Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > It's now Python 3.x, and reworked with lots of graphical examples and more > explanatory text, plus limited in scope to Basic Concepts (which I previously > just had as a first ch 2 section ?-- ?but there's rather a lot of concepts!). > > I think it's wise to invite comments even when it's not 100% completed. First, > because as opposed to ch 1 there is quite a bit of code here, and since I'm a > Python newbie I may be using non-idiomatic constructs, not to mention doing > worse things. :-) Second, because comments in general can improve the text. > > Contents: > > 2.1 Super-basic concept: why programming is not DWIM. ? 1 > 2.2 Reported errors. ? ?4 > 2.2.1 ? Case-sensitity. 4 > 2.2.2 ? Syntax / compilation errors. ? ?4 > 2.2.3 ? Runtime errors / crashes. ? 5 > 2.3 A programming exploration tool: turtle graphics. ? ?6 > 2.4 Naming things. ?8 > 2.4.1 ? Naming actions: routines. ? 8 > 2.4.2 ? Naming data part I: variables. ?11 > 2.4.3 ? Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. ?14 > 2.5.1 ? Repeating actions automatically: loops. 14 > 2.5.2 ? Basic comparisions & boolean values. ? ?16 > 2.5.3 ? Interlude I: a function graph program / about types. ? ?17 > 2.5.4 ? Automated action choices. ? 21 > 2.5.5 ? Value-producing (function-like) routines. ? 23 > 2.5.6 ? Interlude II: a graph with zeroes marked / about program structure. 26 > 2.5.7 ? Dynamically nested actions: recursive routines. 28 > 2.6 Objects. ? ? [Not started on this] 31 > 2.7 Collections. ? ?[Not started on this] 31 > > In Google Docs (both chapters available here): > > ? ? ? > ? ? ?Formats: PDF > > Cheers, > > - Alf Well, you may not like it, but it is perfectly acceptable and indeed promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use of a well understood and oft-used idiom. I they're a lot of them, you generally have a settings module, that just lists all of the 'constants' (.h files effectively). "Technically line_length is a variable"...: No - it's a name that binds to an object that happens to be an integer. You've participated in discussions re: this. Similarly 'number_of_apples = number_of_apples + 1' is not an assignment ;) It's nit-picky and I realise you're trying to keep it simple, but as it's meant for new programmers to the Python language, then introduce them to Python's way of "variables", they'll thank you for it later... (or run screaming, or start another thread here...) I've never seen/heard != described as "different from"; what's wrong with "not equal to"? And why no mention of 'not' (should be mentioned with booleans surely?). That's as far as I've got; might get around to reading more later... Cool tree at the end :) Cheers, Jon From sln at netherlands.com Mon Nov 9 11:55:33 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Mon, 09 Nov 2009 08:55:33 -0800 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: On Mon, 9 Nov 2009 05:53:00 -0800 (PST), pinkisntwell wrote: >How can I make a regular expression that will match every occurrence >of a group and return each occurrence as a group match? For example, >for a string "-c-c-c-c-c", how can I make a regex which will return a >group match for each occurrence of "-c"? Is this a ludicrous question, or is it meant for the python group? use strict; use warnings; my @matches = "-c-c-c-c-c" =~ /(-c)/g; print "\n at matches\n"; @matches = (); "-c-a-c-c-c" =~ /(?:(-c)(?{push @matches, $^N})|.)+/x; print "@matches\n"; -sln From jurgenex at hotmail.com Mon Nov 9 12:18:54 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Mon, 09 Nov 2009 09:18:54 -0800 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <1jjgf5h1jutiqcdfld6atgv5i87djb4iqp@4ax.com> pinkisntwell wrote: >How can I make a regular expression that will match every occurrence >of a group and return each occurrence as a group match? For example, >for a string "-c-c-c-c-c", how can I make a regex which will return a >group match for each occurrence of "-c"? Where is the problem? The most straight-forward, simplest approach works just fine: use strict; use warnings; my $s = '-c-c-c-c-c'; my @matched = $s=~/-c/g; print "Found ". @matched . " occurences of '-c':\n"; print join "\n", @matched; Or did you forget to use the g modifier? jue From alfps at start.no Mon Nov 9 12:22:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 18:22:36 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: * Jon Clements: > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. >> >> It's now Python 3.x, and reworked with lots of graphical examples and more >> explanatory text, plus limited in scope to Basic Concepts (which I previously >> just had as a first ch 2 section -- but there's rather a lot of concepts!). >> >> I think it's wise to invite comments even when it's not 100% completed. First, >> because as opposed to ch 1 there is quite a bit of code here, and since I'm a >> Python newbie I may be using non-idiomatic constructs, not to mention doing >> worse things. :-) Second, because comments in general can improve the text. >> >> Contents: >> >> 2.1 Super-basic concept: why programming is not DWIM. 1 >> 2.2 Reported errors. 4 >> 2.2.1 Case-sensitity. 4 >> 2.2.2 Syntax / compilation errors. 4 >> 2.2.3 Runtime errors / crashes. 5 >> 2.3 A programming exploration tool: turtle graphics. 6 >> 2.4 Naming things. 8 >> 2.4.1 Naming actions: routines. 8 >> 2.4.2 Naming data part I: variables. 11 >> 2.4.3 Naming data part II: routine arguments. 13 >> 2.5 Controlling the flow of execution. 14 >> 2.5.1 Repeating actions automatically: loops. 14 >> 2.5.2 Basic comparisions & boolean values. 16 >> 2.5.3 Interlude I: a function graph program / about types. 17 >> 2.5.4 Automated action choices. 21 >> 2.5.5 Value-producing (function-like) routines. 23 >> 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 >> 2.5.7 Dynamically nested actions: recursive routines. 28 >> 2.6 Objects. [Not started on this] 31 >> 2.7 Collections. [Not started on this] 31 >> >> In Google Docs (both chapters available here): >> >> >> Formats: PDF >> >> Cheers, >> >> - Alf > > Well, you may not like it, but it is perfectly acceptable and indeed > promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use > of a well understood and oft-used idiom. I they're a lot of them, you > generally have a settings module, that just lists all of the > 'constants' (.h files effectively). Yeah, I thought of that angle so I emphasized 'programs'. As it happens about half or more of the variables in the examples are constants. All uppercase convention for that would be ugly to me. :-) > "Technically line_length is a variable"...: No - it's a name that > binds to an object that happens to be an integer. You've participated > in discussions re: this. Similarly 'number_of_apples = > number_of_apples + 1' is not an assignment ;) Ah, you're kidding. Probably. Anyways, that's the terminology employed by the language reference, and even if it wasn't I'd use it because this is primarily introduction to programming in general, where Python just happens to be the vehicle; thus, language independent terminology preferred (e.g., I use "routine" instead of C/Python "function"). > It's nit-picky and I > realise you're trying to keep it simple, but as it's meant for new > programmers to the Python language, then introduce them to Python's > way of "variables", they'll thank you for it later... (or run > screaming, or start another thread here...) Yeah, good point, thanks! But it will have to wait till I get down into details... ;-) > I've never seen/heard != described as "different from"; what's wrong > with "not equal to"? Thanks! > And why no mention of 'not' (should be mentioned > with booleans surely?). Again, I'll discuss that later. It's just too much to bring up. Most of my work with this has been to pare down to essentials and *remove* stuff I'd written. > That's as far as I've got; might get around to reading more later... > > Cool tree at the end :) Thanks! Cheers, - Alf From ssteinerx at gmail.com Mon Nov 9 12:32:18 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 12:32:18 -0500 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: <3C4B9B96-2852-4755-B5B1-A5E0F5439F49@gmail.com> On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >> First, because as opposed to ch 1 there is quite a bit of code >> here, and since I'm a >> Python newbie I may be using non-idiomatic constructs, Welp, there goes my last excuse. I'm off to write my book: Heart Surgery at Home *************** How to Save Thousands and Get Results Just Like in Hospital ******** Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan That's as far as I've gotten... Amazon best seller list, here I come! S From alan at baselinedata.co.uk Mon Nov 9 12:37:20 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 17:37:20 +0000 Subject: String prefix question In-Reply-To: References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: <4AF85350.6060401@baselinedata.co.uk> Gerard Flanagan wrote: >
Alan Harris-Reid wrote: >> In the Python.org 3.1 documentation (section 20.4.6), there is a >> simple ?Hello World? WSGI application which includes the following >> method... >> >> def hello_world_app(environ, start_response): >> status ='200 OK' # HTTP Status >> headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers >> start_response(status, headers) >> >> # The returned object is going to be printed >> return [b"Hello World"] >> >> Question - Can anyone tell me why the 'b' prefix is present before >> each string? The method seems to work equally well with and without >> the prefix. From what I can gather from the documentation the b >> prefix represents a bytes literal, but can anyone explain (in simple >> english) what this means? >> >> Many thanks, >> Alan > > Another link: > > http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror > > > > >
> Gerard - thanks for the link - explains it well. Many thanks, Alan From alfps at start.no Mon Nov 9 12:42:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 18:42:53 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: * ssteinerX at gmail.com: > > On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: > >> On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >>> First, because as opposed to ch 1 there is quite a bit of code here, >>> and since I'm a >>> Python newbie I may be using non-idiomatic constructs, > > Welp, there goes my last excuse. > > I'm off to write my book: > > Heart Surgery at Home > > *************** > How to Save Thousands and > Get Results Just Like in Hospital > ******** > > Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? > Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? > Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery > Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 > Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? > Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan > > That's as far as I've gotten... > > Amazon best seller list, here I come! > > S It helps if you have some experience with surgery on other parts of the body. Cheers & hth., - Alf From victorsubervi at gmail.com Mon Nov 9 12:44:24 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 12:44:24 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> Message-ID: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Did you give up on me? V On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi wrote: > [root at 13gems angrynates.com]# chcon -R -h > unconfined_u:object_r:httpd_sys_content_t global_solutions/* > > Then I surfed to > http://209.216.9.56/global_solutions/index.py > > [root at 13gems angrynates.com]# tail /var/log/messages > Nov 8 04:26:02 13gems syslogd 1.4.1: restart. > [root at 13gems angrynates.com]# tail /var/log/httpd/error_log > [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest > authentication ... > [Sun Nov 08 05:35:10 2009] [notice] Digest: done > [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session mutexes > based on 10 max processes and 0 max threads. > [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- > resuming normal operations > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' failed, referer: > http://209.216.9.56/global_solutions/ > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://209.216.9.56/global_solutions/ > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' failed, referer: > http://209.216.9.56/global_solutions/ > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://209.216.9.56/global_solutions/ > > TIA, > V > > On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury wrote: > >> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >> > httpd_sys_content_t global_solutions >> > chcon: can't apply partial context to unlabeled file global_solutions >> > Please advise. >> >> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >> global_solutions/*', which should specify the whole context at once and >> avoid >> that error, as well as apply it recursively to all files and >> subdirectories. >> >> Also, to narrow down the error, can you let us have the output of: >> tail /var/log/messages >> tail /var/log/httpd/error_log >> >> HTH, >> Rami >> >> ---- >> Rami Chowdhury >> "As an online discussion grows longer, the probability of a comparison >> involving Nazis or Hitler approaches one." -- Godwin's Law >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sajmikins at gmail.com Mon Nov 9 12:55:42 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 9 Nov 2009 12:55:42 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: <50f98a4c0911090955v3c8737afp205225d4477ccc6c@mail.gmail.com> On Mon, Nov 9, 2009 at 12:44 PM, Victor Subervi wrote: > Did you give up on me? > V > Please don't top-post. From rami.chowdhury at gmail.com Mon Nov 9 13:14:28 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 10:14:28 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi wrote: > Did you give up on me? > V > > On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi > wrote: > >> [root at 13gems angrynates.com]# chcon -R -h >> unconfined_u:object_r:httpd_sys_content_t global_solutions/* >> >> Then I surfed to >> http://209.216.9.56/global_solutions/index.py >> >> [root at 13gems angrynates.com]# tail /var/log/messages >> Nov 8 04:26:02 13gems syslogd 1.4.1: restart. >> [root at 13gems angrynates.com]# tail /var/log/httpd/error_log >> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest >> authentication ... >> [Sun Nov 08 05:35:10 2009] [notice] Digest: done >> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session >> mutexes >> based on 10 max processes and 0 max threads. >> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- >> resuming normal operations >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not >> exist: /var/www/html/angrynates.com/favicon.ico >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such >> file >> or directory: exec of '/var/www/html/ >> angrynates.com/global_solutions/index.py' failed, referer: >> http://209.216.9.56/global_solutions/ >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end >> of >> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not >> exist: /var/www/html/angrynates.com/favicon.ico >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such >> file >> or directory: exec of '/var/www/html/ >> angrynates.com/global_solutions/index.py' failed, referer: >> http://209.216.9.56/global_solutions/ >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end >> of >> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >> >> TIA, >> V >> >> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury >> wrote: >> >>> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >>> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >>> > httpd_sys_content_t global_solutions >>> > chcon: can't apply partial context to unlabeled file global_solutions >>> > Please advise. >>> >>> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >>> global_solutions/*', which should specify the whole context at once and >>> avoid >>> that error, as well as apply it recursively to all files and >>> subdirectories. >>> >>> Also, to narrow down the error, can you let us have the output of: >>> tail /var/log/messages >>> tail /var/log/httpd/error_log >>> OK, after all this I've forgotten what your .py file looked like -- can you post that please? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From gonatan at gmx.de Mon Nov 9 13:24:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Mon, 09 Nov 2009 19:24:10 +0100 Subject: Tax Calculator--Tkinter In-Reply-To: References: Message-ID: <4AF85E4A.4020603@gmx.de> Someone Something wrote: > > from Tkinter import *; Try to avoid this. Better import Tkinter. And don't forget to import Tkconstants too! > > rate=Frame(root) > > income=Frame(root) > > result=Frame(root) Why do you use three frames? You only need one. And you can make your class TaxCalc inherit from Tkinter.Frame ... > > The thing is, that even if I put "12" in the result text field, get > > returns an empty string. How can I fix this? I haven't found the reason for that, but this should work. I also added MRABs version of printResult(). import Tkinter, Tkconstants class TaxCalc(Tkinter.Frame): def __init__(self, root): Tkinter.Frame.__init__(self, root) Tkinter.Button(self, text='Enter tax rate', command=self.getRate).pack() self.rate=Tkinter.Entry(self) self.rate.pack() Tkinter.Button(self, text='Enter income', command=self.getIncome).pack() self.income=Tkinter.Entry(self) self.income.pack() Tkinter.Button(self, text='Get result', command=self.printResult).pack() self.result=Tkinter.Entry(self) self.result.pack() self.pack() def getRate(self): print "srate: ", self.rate.get() def getIncome(self): print "sincome: ", self.income.get() def printResult(self): try: rate = float(self.rate.get()) income = float(self.income.get()) result = ((100.0 - rate) / 100.0) * income self.result.insert(Tkconstants.END, str(result)) except ValueError: print "Clear everything and start again." print "Don't fool around with me." root=Tkinter.Tk() MyCalc=TaxCalc(root) root.mainloop() From victorsubervi at gmail.com Mon Nov 9 13:36:31 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 13:36:31 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Of course. Let me start with some updates to httpd.conf, which didn't help anyway: ServerAdmin me at creative.vi DocumentRoot /var/www/html/angrynates.com ServerName angrynates.com Options +ExecCGI -IncludesNoExec Options +ExecCGI AllowOverride All AllowOverride FileInfo #AddHandler mod_python .py #PythonHandler mod_python.publisher #PythonDebug On AddHandler cgi-script .cgi .py Options Includes Indexes SymLinksIfOwnerMatch ExecCGI SecFilterEngine Off SecRuleEngine Off AddHandler cgi-script .cgi .py Options Includes Indexes SymLinksIfOwnerMatch ExecCGI SecFilterEngine Off SecRuleEngine Off Here's index.py: #!/usr/bin/python import string import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from template import template ourFile = string.split(__file__, "/") page = ourFile[len(ourFile) - 1][:-3] form = cgi.FieldStorage() w = form.getfirst('w', '1024') template(page, w) Here's template.py: #!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) p = 'template' def template(page, w): wn = int(w)/1024 print "Content-Type: text/html" print print ''' Global Solutions Group ''' print "\n' % (a, w) This is looped through for every value of pic/id returned from the database, producing the following code on the Web page: The problem here is that only one of the images prints on the said page! However, if I surf to those URLs, the images appear! Is it possible that because I'm passing values to the variables and perhaps simultaneously calling the script, that it can only fulfill the first request? Is there a way around that? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From yosato16 at gmail.com Fri Nov 27 12:17:33 2009 From: yosato16 at gmail.com (Yo Sato) Date: Fri, 27 Nov 2009 17:17:33 +0000 Subject: debugger on system with Python 2 and 3 Message-ID: Hi, I am a relative newcomer to the Python language, and only write Python 3. Now I would very much like to a more-than-basic debugger. However it seems as if the fact that I have both Python 2 and 3 on the system complicates the matter... First I tried to use something called pydb, but it seems to invoke python 2, and I don't know quite how to (or whether I can) configure it for Python 3. Secondly I installed something called IDLE3, which complains that TK is not configured for Python 3. I don't want to remove or default to Python 2, as there seem to be a number of programs that rely on it. I wonder how best to avoid my problems. Would perhaps somebody in the same sort of situation share their wisdom?? Yo From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 12:21:54 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Nov 2009 17:21:54 GMT Subject: why do I get this behavior from a while loop? References: Message-ID: <00998f26$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? "What Every Computer Scientist Should Know About Floating Point" http://docs.sun.com/source/806-3568/ncg_goldberg.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 12:30:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Nov 2009 17:30:26 GMT Subject: Filling in a tuple from unknown size list References: Message-ID: <00999127$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: > Here's my question: Given a list of onknown length, I'd like to be able > to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining tuple > elements to be set to "None". If the list is longer, I'd like the excess > elements to be ignored. I'd call that a code-smell. If I saw that in code, I'd think long and hard about why it was there and if I could eliminate the names a...f and just work directly with the list. But if you really do need it, I think the simplest and best way is to use the technique Stefan suggested: a, b, c, d, e, f = (list + [None]*6)[:6] provided list is short. If you fear that list might be huge and copying it will be prohibitively expensive: a, b, c, d, e, f = (list[:6] + [None]*6)[:6] -- Steven From mwilson at the-wire.com Fri Nov 27 12:47:40 2009 From: mwilson at the-wire.com (Mel) Date: Fri, 27 Nov 2009 12:47:40 -0500 Subject: Filling in a tuple from unknown size list References: <00999127$0$26925$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: >> Here's my question: Given a list of onknown length, I'd like to be able >> to do the following: >> >> (a, b, c, d, e, f) = list >> >> If the list has fewer items than the tuple, I'd like the remaining tuple >> elements to be set to "None". If the list is longer, I'd like the excess >> elements to be ignored. > I'd call that a code-smell. If I saw that in code, I'd think long and > hard about why it was there and if I could eliminate the names a...f and > just work directly with the list. It's a common enough thing at the boundaries of your program, letting user input in through the gates, as it were. Deeper in, I agree; that stuff should have been dealt with at the gates. Mel. From coldtortuga at gmail.com Fri Nov 27 13:12:36 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Fri, 27 Nov 2009 10:12:36 -0800 (PST) Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: I was really inspired by this discussion thread! :-) After much tinkering, I think I have a simpler solution. Just make the inverse mapping accessible via an attribute, -AND- bind the inverse of -THAT- mapping back to the original. The result is a python dict with NO NEW METHODS except this inverse-mapping attribute. I have posted it on code.activestate.com as Recipe 576968: Flipdict -- python dict that also maintains a one-to-one inverse mapping -- F. Carr From aljosa.mohorovic at gmail.com Fri Nov 27 13:22:51 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 27 Nov 2009 10:22:51 -0800 (PST) Subject: setup.py and MANIFEST.in - duplicating inclusion of files? Message-ID: the only way i can get to distribute template files when using "python setup.py sdist" is to declare it both in setup.py and MANIFEST.in. setup.py: > package_data={'myapp':['templates/*.html', 'templates/admin/*.html'],} MANIFEST.in: > recursive-include myapp/templates *.html am i doing something wrong or is this correct? if it's correct, why? Aljosa Mohorovic From victorsubervi at gmail.com Fri Nov 27 13:26:18 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 27 Nov 2009 14:26:18 -0400 Subject: Can't Encode Pic In-Reply-To: References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911260819q4340bb1at9a02422f3226df87@mail.gmail.com> <4B0EB244.7050703@mrabarnett.plus.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> Message-ID: <4dc0cfea0911271026x240d869du80148727ec4de238@mail.gmail.com> On Fri, Nov 27, 2009 at 1:43 PM, Dennis Lee Bieber wrote: > On Fri, 27 Nov 2009 05:59:39 -0500, Victor Subervi > declaimed the following in > gmane.comp.python.general: > > > > > > > > The following complained that there weren't enough arguments: > > > > for pic in pics: > > sql = 'update %s set %s=%%s where ID=%s;' % (t, colNamesPics[i], > > '%s', str(id)) > > cursor.execute(sql, (MySQLdb.Binary(pics[int(i)]),), ) > > > I'm pretty sure that isn't what I had typed too... Count the % > > sql = "update %s set %s=%%s where ID = %%s" % (t, colNamesPics[i]) > Thank you, Dennis. This problem is resolved. Since our posts most likely crossed, and since yours has inadvertently appeared below mine with the latest problem, I'm reposting it here: Now, I have this line of code on another page that calls the images once the database is populated: print '\n' % (a, w) This is looped through for every value of pic/id returned from the database, producing the following code on the Web page: The problem here is that only one of the images prints on the said page! However, if I surf to those URLs, the images appear! Is it possible that because I'm passing values to the variables and perhaps simultaneously calling the script, that it can only fulfill the first request? Is there a way around that? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From doesnotexist at franzoni.invalid Fri Nov 27 14:03:10 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Fri, 27 Nov 2009 19:03:10 GMT Subject: debugger on system with Python 2 and 3 In-Reply-To: References: Message-ID: On 11/27/09 6:17 PM, Yo Sato wrote: > Hi, > > I am a relative newcomer to the Python language, and only write Python > 3. Now I would very much like to a more-than-basic debugger. However > it seems as if the fact that I have both Python 2 and 3 on the system > complicates the matter... You haven't told OS which OS you're using, and what are your exact problems, BTW I think two good debuggers for Python are winpdb/rpdb2 (work on any platform, despite the name) and the one you get in Eclipse+Pydev. You should be able to pick your platform, even though I've never tested them in Python 3. -- Alan Franzoni contact me at public@[mysurname].eu From carsten.haese at gmail.com Fri Nov 27 14:21:30 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 27 Nov 2009 14:21:30 -0500 Subject: Can't Encode Pic In-Reply-To: <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911260819q4340bb1at9a02422f3226df87@mail.gmail.com> <4B0EB244.7050703@mrabarnett.plus.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> <2f79f590911270602u17a1cfcex83aa2f4ffe0fdf29@mail.gmail.com> <4dc0cfea0911270708o64a12fe1pbdd12ad5b5edd56a@mail.gmail.com> <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Fri, Nov 27, 2009 at 12:13 PM, Carsten Haese > wrote: > > Victor Subervi wrote: > > The difficulty I am having is that for > > some reason it's not inserting. The form inserts the first image > but not > > the second. > > My guess is that you're not calling db.commit() after inserting the > second image. (If you had shown your code, I wouldn't have to guess.) > > > That was the logical guess and yes, it hit the target. I should have > known better. Thank you. > Now, I have this line of code on another page that calls the images once > the database is populated: > > print ' width="100">\n' % (a, w) > > This is looped through for every value of pic/id returned from the > database, producing the following code on the Web page: > > > > > The problem here is that only one of the images prints on the said page! > However, if I surf to those URLs, the images appear! Are you sure that you're surfing to *exactly* those URLs? When I go to http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get an error message. I am guessing that you have your pic and id parameter switched around. > Is it possible that > because I'm passing values to the variables and perhaps simultaneously > calling the script, that it can only fulfill the first request? That's possible if your script is doing something stupid, but I find my above guess much more likely. HTH, -- Carsten Haese http://informixdb.sourceforge.net From sccolbert at gmail.com Fri Nov 27 15:00:42 2009 From: sccolbert at gmail.com (S. Chris Colbert) Date: Fri, 27 Nov 2009 21:00:42 +0100 Subject: why do I get this behavior from a while loop? In-Reply-To: <00998f26$0$26925$c3e8da3@news.astraweb.com> References: <00998f26$0$26925$c3e8da3@news.astraweb.com> Message-ID: <200911272100.42168.sccolbert@gmail.com> What a newbie mistake for me to make. I appreciate the replies everyone! Cheers, Chris > On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > > I would think that second loop should terminate at 9.9, no? > > > > I am missing something fundamental? > > "What Every Computer Scientist Should Know About Floating Point" > http://docs.sun.com/source/806-3568/ncg_goldberg.html > From stefan_ml at behnel.de Fri Nov 27 15:11:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 Nov 2009 21:11:01 +0100 Subject: Filling in a tuple from unknown size list In-Reply-To: References: <00999127$0$26925$c3e8da3@news.astraweb.com> Message-ID: <4b103255$0$6566$9b4e6d93@newsspool4.arcor-online.net> Mel, 27.11.2009 18:47: > Steven D'Aprano wrote: >> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: >>> Here's my question: Given a list of onknown length, I'd like to be able >>> to do the following: >>> >>> (a, b, c, d, e, f) = list >>> >>> If the list has fewer items than the tuple, I'd like the remaining tuple >>> elements to be set to "None". If the list is longer, I'd like the excess >>> elements to be ignored. > >> I'd call that a code-smell. If I saw that in code, I'd think long and >> hard about why it was there and if I could eliminate the names a...f and >> just work directly with the list. > > It's a common enough thing at the boundaries of your program, letting user > input in through the gates, as it were. Deeper in, I agree; that stuff > should have been dealt with at the gates. But that may have a code smell on it, too. In most cases, when users provide excessive arguments that the program would ignore, that's best treated as an error. Stefan From victorsubervi at gmail.com Fri Nov 27 15:18:58 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 27 Nov 2009 16:18:58 -0400 Subject: Can't Encode Pic In-Reply-To: References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> <2f79f590911270602u17a1cfcex83aa2f4ffe0fdf29@mail.gmail.com> <4dc0cfea0911270708o64a12fe1pbdd12ad5b5edd56a@mail.gmail.com> <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> Message-ID: <4dc0cfea0911271218x160a585fxab91530b0fec945b@mail.gmail.com> > > > > > > > > > The problem here is that only one of the images prints on the said page! > > However, if I surf to those URLs, the images appear! > > Are you sure that you're surfing to *exactly* those URLs? When I go to > http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but > when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get > an error message. I am guessing that you have your pic and id parameter > switched around. > Yes. Sorry. Thanks. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Fri Nov 27 15:26:52 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 12:26:52 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: Testing, testing...is this thing on? Hang on guys, I'm having some trouble posting to the mailing list suddenly. From subhakolkata1234 at gmail.com Fri Nov 27 15:41:42 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 12:41:42 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys Message-ID: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> Dear Group, I have written a small and simple program like the following: def alphabet1(n): file_open=open("/python26/alphabetlist1.txt","r") file_read=file_open.read() file_word=file_read.split() print file_word Here, I am using a file ?alphabetlist1.txt? which I am reading and then splitting them into words. In this file ?alphabetlist1.txt? I have arranged few alphabets like the following: a A b B c C d D E e F f Where, a/b/c/d/e/f are in lower case and A/B/C/D/E/F are in upper case which I can say as SHIFT+a SHIFT+b SHIFT+c SHIFT+d SHIFT+e SHIFT+f Now, in the list or anywhere in the program if I want to write CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I may feel not only cut/copy/paste. How would I represent them? It may not be a Python specific question but as this room is full with many expert programmers if someone can help me out. I copied the above program from .py file to a word processor like MS- WORD so some indentation might have changed, I am sorry for the same. Regards, Subhabrata Banerjee. From anand.ibmgsi at gmail.com Fri Nov 27 16:23:42 2009 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Sat, 28 Nov 2009 02:53:42 +0530 Subject: Render a xml graph as an image Message-ID: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> hi all. Am looking to display a graph as an image.. the graph is in the format of a xml file(basically the output of a python-graph package).......... Is there a package that already does it?? ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with no accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Nov 27 16:23:55 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 28 Nov 2009 10:23:55 +1300 Subject: Intro To Python Using Turtle Graphics Message-ID: Done by Northland Polytechnic, available for download under CC-BY-NC-ND here . Thanks to Colin Jackson for the link. From rossgk at gmail.com Fri Nov 27 16:27:43 2009 From: rossgk at gmail.com (Ross) Date: Fri, 27 Nov 2009 13:27:43 -0800 (PST) Subject: My Python / wxPython app crashing - suggestions? Message-ID: <2bed9cbd-2bc7-4cfb-8b93-4a3dc4bbaaea@x16g2000vbk.googlegroups.com> I have a rather elaborate app on python 2.5.2 on mac osx 10.4.11. The GUI elements are built on wxPython 2.8.10.1. Development has gone pretty well, but I've got an intermittent rather silent crash that happens without spewing any error messages to my console at all. I'm developing in Eclipse with PyDev, and I build with py2app to make an executable app. Whether in Eclipse/PyDev or running standalone, the crash occurs randomly without any messages almost every run, though it takes me 10 -15min of usage before I get the fateful crash. The only data I can get is from the CrashReporter Log directory where a MyApp.crash.log tells me that Thread 4 crashed with: Thread: 4 Exception: EXC_BAD_ACCESS (0x0001) Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000004 and: Thread 4 crashed with X86 Thread State (32-bit): eax: 0x00000000 ebx: 0x9083d561 ecx: 0x00000074 edx: 0x92e341ac edi: 0x14442b60 esi: 0x00000000 ebp: 0xb0370b58 esp: 0xb0370b58 ss: 0x0000001f efl: 0x00010286 eip: 0x92e30522 cs: 0x00000017 ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037 Given the lack of other info, this doesn't tell me much. Any suggestions? One other (perhaps related issue?) very rarely, much less common than the crash is a spurious malloc error from deep in python somewhere. Not sure that my code is responsible. I don't recognize this format of complaint. Python(9544,0xa000d000) malloc: *** error for object 0x1a05c8f0: double free Python(9544,0xa000d000) malloc: *** set a breakpoint in szone_error to debug Can anyone suggest somewhere to start? If I start putting random breakpoints and prints in trying to catch the crash, I could be here for years as I can't yet nail down the conditions that precipitate it. Regards, Ross. From tjreedy at udel.edu Fri Nov 27 16:42:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 27 Nov 2009 16:42:42 -0500 Subject: extending optionparser to accept multiple comma delimited input for one arg In-Reply-To: <4734689a-1e89-4bbd-9a1b-f811f897a344@f16g2000yqm.googlegroups.com> References: <9230223a-2907-478a-ba30-15419b6db020@b2g2000yqi.googlegroups.com> <4734689a-1e89-4bbd-9a1b-f811f897a344@f16g2000yqm.googlegroups.com> Message-ID: cmptrwhz wrote: > On Nov 27, 2:33 am, Peter Otten <__pete... at web.de> wrote: >> If you had problems understanding the documentation perhaps you can suggest >> an improvement. >> >> Peter > First I would like to thank you very much for the quick and concise > answer this is very clear to me as to what I need to do now. Thank you > so much. > > The one thing that threw me off and confused me is that I went back in > the docs to see what actions are available to see if extend was an > allowable action. in section 14.3.2.4 Other actions, I did not see > that extend was a valid action so I looked thru section 14.3.3.3 > Defining options and this section did not show extend as a valid > action. I believe that if there was a complete disclosure of actions > available then I would have seen the error in my thinking. Everything > else made sense up to the point of where the subclass was described in > the docs as above but if the next couple lines you gave me was added > to this section (14.3.5.2 Adding new actions) it was have completed > the confirmation I needed that it was ok to type in extend as an > action. Maybe I am still not understanding this concept fully still > but I hope I am making sense with my point. > > So my suggestion would be to include this tidbit of extra as you have > described to me in the section 14.3.5.2 and all would have been as > clear as sunshine. :) thank you again for your time and listening to > my thoughts. > > parser = OptionParser(option_class=MyOption) > parser.add_option("-i", "--input", action="extend") > > options, args = parser.parse_args() > print options Please go to bugs.python.org, register if you have not, and add a type: feature request, component: documentation issue giving the exact sentence you suggest adding (keeping in mind the existing doc style) and the exact proposed location. Then explain, briefly, why. From david at bibliolabs.com Fri Nov 27 17:02:05 2009 From: david at bibliolabs.com (David Williams) Date: Fri, 27 Nov 2009 16:02:05 -0600 (CST) Subject: Render a xml graph as an image In-Reply-To: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> References: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> Message-ID: <51310.68.58.172.242.1259359325.squirrel@www.bibliobazaar.com> Maybe I am missing something, but according to this example, http://code.google.com/p/python-graph/wiki/Example, python-graph can export to at least PNG format. Another option, transform the XML into GraphML (http://graphml.graphdrawing.org/) using XSLT (assuming it is not already in that format), and then to SVG (http://www.w3.org/Graphics/SVG/). From there it should be easy to either directly display or get it into any bitmap format you want. On the GraphML website their is an XSL to transform GraphML to SVG. David > hi all. > Am looking to display a graph as an image.. the graph is in the > format of a xml file(basically the output of a python-graph > package).......... Is there a package that already does it?? > ============================================== > Anand J > http://sites.google.com/a/cbcs.ac.in/students/anand > ============================================== > The man who is really serious, > with the urge to find out what truth is, > has no style at all. He lives only in what is. > ~Bruce Lee > > Love is a trade with no accounting policies. > ~Aang Jie > -- > http://mail.python.org/mailman/listinfo/python-list > From bthate at gmail.com Fri Nov 27 18:38:58 2009 From: bthate at gmail.com (Bart Thate) Date: Fri, 27 Nov 2009 15:38:58 -0800 (PST) Subject: cmndbot 0.1 beta 1 released Message-ID: So once again i bite the bullet because i can no longer wait on going public with this. I'm pleased to announce CMNDBOT 0.1 BETA1 to the world as this is the first released of my port of GOZERBOT to the Google Application Engine, enabling it on wave, web and xmpp. I'll paste here the README to explain what it does: CMNDBOT is a port of gozerbot to google wave platform. GOZERBOT needed to be completely rewritten as programs running on google application engine (GAE) run within a CGI model which means that the bot get loaded on every request (unless its cached). Core functionality is available right now but most plugins need to be ported still. Besides wave the bot also supports web and jabber (XMPP) access. this is the code that is being run by the cmndbot.appspot.com bot and is free code (BSD license). you can clone it to run your own cmndbot or just to read how things are being done. no fear in reading cmndbot code ! as the name says cmndbot allows you to execute commands that you can program easily through the use of plugins. example: from gozerlib.commands import cmnds def handle_hello(bot, event): event.reply("hello %s" % event.userhost) cmnds.add('hello', handle_hello, 'USER') as of now a few gozerbot plugins are being ported to cmndbot, namely: * eight ball * ipcalc * todo * wikipedia * infoitem * gcalc * RSS other plugins will follow but the focus is now mainly on the bots core. CMNDBOT is accessible at http://cmndbot.appspot.com (WEB) or cmndbot at appspot.com (WAVE/XMPP). A gadget is also in the works at http://cmndbot.appspot.com/cmnd.xml but it only works with google chrome for now .. my javascript skills are very *kuch* young ;] actualy this code is still young as docs are mostely missing and the bot really needs to be tested, but thats what this release is for, rememer this is still version 0.1 ! code is at http://cmndbot.googlecode.com/hg I hope people are interested in developing this bot with me, if you do you can contact me at bthate at gmail.com or bthate at googlewave.com Bart From sjmachin at lexicon.net Fri Nov 27 19:02:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 27 Nov 2009 16:02:39 -0800 (PST) Subject: Filling in a tuple from unknown size list References: Message-ID: <5c5f1f89-e1f5-4814-bdfa-ea71c8b4d29a@z10g2000prh.googlegroups.com> On Nov 27, 11:18?pm, boblatest wrote: > Hello all, > > (sorry for posting from Google. I currently don't have access to my > normal nntp account.) > > Here's my question: Given a list of onknown length, I'd like to be > able to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining > tuple elements to be set to "None". If the list is longer, I'd like > the excess elements to be ignored. WRONG -- sweeping excess input under the carpet is a nasssssty perlish trick. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 19:35:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 00:35:16 GMT Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> Message-ID: <0099f4b9$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > Dear Group, > > I have written a small and simple program like the following: > > def alphabet1(n): > file_open=open("/python26/alphabetlist1.txt","r") > file_read=file_open.read() > file_word=file_read.split() > print file_word > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > splitting them into words. > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > following: > > a A > b B > c C > d D > E e > F f > > Where, a/b/c/d/e/f are in lower case and A/B/C/D/E/F are in upper case > which I can say as > SHIFT+a > SHIFT+b > SHIFT+c > SHIFT+d > SHIFT+e > SHIFT+f > > Now, in the list or anywhere in the program if I want to write > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > may feel not only cut/copy/paste. > > How would I represent them? This question is badly defined. What are your constraints? Is this meant to be a human-readable program? If so, you need to stick to ASCII text and probably want something like: a A CTRL-A ALT-A b B CTRL-B ALT-B ... but I'm not sure what the point of that would be. Normally, control-combinations generate control-characters. For example, CTRL-M would normally generate a carriage-return character. Depending on your needs, you can write this as any of the following: a description: CTRL-M an escape sequence: \r caret notation: ^M the standard abbreviation: CR the Unicode display glyph: ? or an actual carriage-return character. Note that in ASCII control characters only have a standard definition for the following: ctrl-@ ctrl-A through ctrl-Z ctrl-[ ctrl-\ ctrl-] ctrl-^ ctrl-_ ctrl-? See here for more: http://en.wikipedia.org/wiki/Control_characters As for Alt-combinations, I don't think there is any standard for what they are. I believe that they are operating system specific, and possibly even program specific. -- Steven From enkidu.com at com.cliffp.com Fri Nov 27 20:02:31 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:02:31 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: References: Message-ID: <4b1076a8$1@news2.actrix.gen.nz> Lawrence D'Oliveiro wrote: > > Done by Northland Polytechnic, available for download under CC-BY-NC-ND here > . > Urgh. Is that all that python is good for, drawing pretty pictures? Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From ben+python at benfinney.id.au Fri Nov 27 20:20:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 12:20:20 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> Message-ID: <873a3zwiln.fsf@benfinney.id.au> Enkidu writes: > Urgh. Is that all that python is good for, drawing pretty pictures? Yep, that's all . Rackspace, Google, NASA, Philips, Honeywell, AstraZeneca; they're *all* organisations focussed on drawing pretty pictures, and that's all they use Python for. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 20:32:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 01:32:06 GMT Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> Message-ID: <009a020b$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 14:02:31 +1300, Enkidu wrote: > Lawrence D'Oliveiro wrote: > > >> Done by Northland Polytechnic, available for download under CC-BY-NC-ND >> here >> . >> > Urgh. Is that all that python is good for, drawing pretty pictures? [sarcasm] Yes, yes it is. When they talk about "batteries included", they mean the batteries that run the turtle. [end sarcasm] Are you trolling or just a little sleep-deprived today? The movie is an introduction aimed at 13-16 year old school children. It's explicitly labelled as "an introduction using turtle graphics". What on earth makes you think that because the introduction uses turtle graphics, that's the ONLY thing that Python can do? -- Steven From aioe.org at technicalbloke.com Fri Nov 27 20:35:36 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 01:35:36 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. Message-ID: Hi, I'm writing a reliability monitoring app but I've run into a problem. I was hoping to keep it very simple and single threaded at first but that's looking unlikely now! The crux of it is this... gethostbyname ignores setdefaulttimeout. It seems gethostbyname asks the OS to resolve the address and the OS uses it's own timeout value ( 25 seconds ) rather than the one provided in setdefaulttimeout. 25 seconds of blocking is way too long for me, I want the response within 5 seconds or not at all but I can see no reasonable way to do this without messing with the OS which naturally I am loathe to do! The two ideas I've had so far are... Implement a cache. For this to work I'd need to avoid issuing gethostbyname until the cached address fails. Of course it will fail a little bit further down i the calling code when the app tries to use it and I'd then need it to refresh the cache and try again. That seems very kludgey to me :/ A pure python DNS lookup. This seems better but is an unknown quantity. How big a job is it to use non-blocking sockets to write a DNS lookup function with a customisable timeout? A few lines? A few hundred? I'd only need to resolve v4 addresses for the foreseeable. Any comments on these strategies, or any suggestions of methods you think might work better or be a lot easier to implement, warmly received. Roger. From enkidu.com at com.cliffp.com Fri Nov 27 20:52:11 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:52:11 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <873a3zwiln.fsf@benfinney.id.au> References: <4b1076a8$1@news2.actrix.gen.nz> <873a3zwiln.fsf@benfinney.id.au> Message-ID: <4b10824b$1@news2.actrix.gen.nz> Ben Finney wrote: > Enkidu writes: > >> Urgh. Is that all that python is good for, drawing pretty pictures? > > Yep, that's all . Rackspace, > Google, NASA, Philips, Honeywell, AstraZeneca; they're *all* > organisations focussed on drawing pretty pictures, and that's all they > use Python for. > Sorry, I did not mean to post to the CLP list. It would be a stupid troll to do so on purpose. My apologies. I *AM* a Perl fan but there is room for both languages. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From enkidu.com at com.cliffp.com Fri Nov 27 20:55:32 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:55:32 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <009a020b$0$26925$c3e8da3@news.astraweb.com> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> Message-ID: <4b108315$1@news2.actrix.gen.nz> Steven D'Aprano wrote: > On Sat, 28 Nov 2009 14:02:31 +1300, Enkidu wrote: > > Are you trolling or just a little sleep-deprived today? > Heh! Maybe a little sleep-deprived, but I didn't realise that the original post was cross-posted to comp.lang.python. If I'd purposely posted it to CLP it *would* have been a stupid troll. I did it by accident, and apologise for doing so. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From john at castleamber.com Fri Nov 27 21:04:51 2009 From: john at castleamber.com (John Bokma) Date: 28 Nov 2009 02:04:51 GMT Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > It seems gethostbyname asks the OS to resolve the address and the OS > uses it's own timeout value ( 25 seconds ) rather than the one provided > in setdefaulttimeout. 25 seconds of blocking is way too long for me, I > want the response within 5 seconds or not at all but I can see no > reasonable way to do this without messing with the OS which naturally I > am loathe to do! use signal.alarm(time) to send SIGALRM to your process: http://docs.python.org/library/signal.html#signal.alarm See example at bottom. John From gagsl-py2 at yahoo.com.ar Fri Nov 27 21:15:09 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Nov 2009 23:15:09 -0300 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: En Fri, 27 Nov 2009 22:35:36 -0300, r0g escribi?: > gethostbyname ignores setdefaulttimeout. > > How big a job is it to use non-blocking sockets to write a DNS lookup > function with a customisable timeout? A few lines? A few hundred? I'd > only need to resolve v4 addresses for the foreseeable. This guy reports good results using GNU adns to perform asynchronous queries: http://www.catonmat.net/blog/asynchronous-dns-resolution/ Also, look for pydns. Don't be afraid of its age; it always worked fine for me. -- Gabriel Genellina From ben+python at benfinney.id.au Fri Nov 27 21:15:46 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 13:15:46 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> Message-ID: <87ocmnv1gt.fsf@benfinney.id.au> Enkidu writes: > Heh! Maybe a little sleep-deprived, but I didn't realise that the > original post was cross-posted to comp.lang.python. If I'd purposely > posted it to CLP it *would* have been a stupid troll. I did it by > accident, and apologise for doing so. Oh, so trash-talking in *other* forums where you feel safe from being caught is okay? ;-) -- \ ?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 gagsl-py2 at yahoo.com.ar Fri Nov 27 21:36:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Nov 2009 23:36:13 -0300 Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: En Fri, 27 Nov 2009 15:12:36 -0300, Francis Carr escribi?: > I was really inspired by this discussion thread! :-) > > After much tinkering, I think I have a simpler solution. Just make > the inverse mapping accessible via an attribute, -AND- bind the > inverse of -THAT- mapping back to the original. The result is a > python dict with NO NEW METHODS except this inverse-mapping > attribute. I have posted it on code.activestate.com as href="http://code.activestate.com/recipes/576968/">Recipe 576968: > Flipdict -- python dict that also maintains a one-to-one inverse > mapping Nice idea! Just a couple of comments: Instead of: self._flip = dict.__new__(self.__class__) I'd write: self._flip = self.__class__() unless I'm missing something (but see the next point). Also, although Python's GC is able to handle them, I prefer to avoid circular references like those between x and x._flip. Making self._flip a weak reference (and dereferencing it in the property) should be enough. -- Gabriel Genellina From showell30 at yahoo.com Fri Nov 27 22:04:31 2009 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 27 Nov 2009 19:04:31 -0800 (PST) Subject: a 100-line indentation-based preprocessor for HTML Message-ID: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Python has this really neat idea called indentation-based syntax, and there are folks that have caught on to this idea in the HTML community. AFAIK the most popular indentation-based solution for generating HTML is a tool called HAML, which actually is written in Ruby. I have been poking around with the HAML concepts in Python, with the specific goal of integrating with Django. But before releasing that, I thought it would be useful to post code that distills the basic concept with no assumptions about your target renderer. I hope it also serves as a good example of what you can do in exactly 100 lines of Python code. Here is what it does... You can use indentation syntax for HTML tags like table. From this... table tr td Left td Center td Right ...you get this:
Homeoffice suppliescatalogcustomer templateformsabout uscontact us
\n' % (getpic) count2 += 1 except: print '' else: print '\n' % (field) x += 1 TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ralaxmyself at gmail.com Wed Nov 11 09:01:13 2009 From: ralaxmyself at gmail.com (Ralax) Date: Wed, 11 Nov 2009 06:01:13 -0800 (PST) Subject: Basic list/dictionary question References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Message-ID: <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> On Nov 11, 8:58?pm, Chris Rebert wrote: > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett wrote: > > Greetings, > > > I'm trying to categorize items in a list, by copying them into a > > dictionary... > > A simple example with strings doesn't seem to work how I'd expect: > > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] > >>>> d = {} > >>>> d = d.fromkeys(basket, []) > >>>> d > > {'orange': [], 'pear': [], 'apple': [], 'banana': []} > >>>> for fruit in basket: > > ...???? d[fruit].append(fruit) > > ... > > > No if I print d I'd EXPECT.... > >>>> d > > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > > 'apple'], 'banana': ['banana']} > > > But what I GET is.... > >>>> d > > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': > > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana']} > > > From what I can work out, there is only ONE list that is referenced from the > > dictionary 4 times. Which would be because the same empty list is assigned > > to every key in the dictionary by the "fromkeys" line. But that seems > > seriously counter-intuitive to me... > > Python doesn't do any extra copying in most places unless you > /explicitly/ do so yourself or ask it to; so yes, in this case, Python > just copies references to the same object and does not copy the object > itself. > > You'd probably be better off using a defaultdict in your particular usecase:http://docs.python.org/library/collections.html#collections.defaultdict > > Or and so you avoid running into it, default argument values aren't > copied either: > In [2]: def foo(z, a=[]): > ? ?...: ? ? ? ? a.append(z) > ? ?...: ? ? return a > ? ?...: > > In [3]: foo(1) > Out[3]: [1] > > In [4]: foo(2) > Out[4]: [1, 2] > > In [5]: foo(2) > Out[5]: [1, 2, 2] > > In [6]: foo(3) > Out[6]: [1, 2, 2, 3] > > In [7]: foo(4,[]) > Out[7]: [4] > > In [8]: foo(5) > Out[8]: [1, 2, 2, 3, 5] > > Cheers, > Chris > --http://blog.rebertia.com Usefull! From ralaxmyself at gmail.com Wed Nov 11 09:11:31 2009 From: ralaxmyself at gmail.com (Ralax) Date: Wed, 11 Nov 2009 06:11:31 -0800 (PST) Subject: Unexpected python exception References: Message-ID: <7d121326-ab5f-4151-8edb-f69bc6f9dee5@b36g2000prf.googlegroups.com> On Nov 11, 6:59?pm, Richard Purdie wrote: > I've been having problems with an unexpected exception from python which > I can summarise with the following testcase: > > def A(): > ? ? import __builtin__ > ? ? import os > > ? ? __builtin__.os = os > > def B(): > ? ? os.stat("/") > ? ? import os > > A() > B() > > which results in: > > Traceback (most recent call last): > ? File "./test.py", line 12, in > ? ? B() > ? File "./test.py", line 8, in B > ? ? os.stat("/") > UnboundLocalError: local variable 'os' referenced before assignment > > If I remove the "import os" from B(), it works as expected. > > >From what I've seen, its very unusual to have something operate > > "backwards" in scope in python. Can anyone explain why this happens? > > Cheers, > > Richard One word, Python treat objects in a function or method-scope as locals. So os is not defined in B(), is it right? From deets at nospam.web.de Wed Nov 11 09:23:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 15:23:06 +0100 Subject: installing lxml ? In-Reply-To: References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <7lvvmaF3ga6r2U1@mid.uni-berlin.de> Chris Rebert schrieb: > On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: >> I'm trying to install lxml, but I can't figure out the installation >> instructions. Here: >> >> http://codespeak.net/lxml/installation.html >> >> it says: >> >> 1) Get the easy_install tool. > >> My os is mac os x 10.4.11. > > I would recommend installing fink (http://www.finkproject.org/) and > then `sudo fink install setuptools-py26`. > As a bonus, you'll get a more up-to-date Python installed separate > from the system one (so you don't need to worry about hosing it). Which doesn't run any cocoa or other osx-specific code. Which some might call "hosed from the very beginning". Diez From starglider101 at gmail.com Wed Nov 11 09:28:11 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 11 Nov 2009 14:28:11 +0000 Subject: PyQt 2 Exe In-Reply-To: References: <6e5b31840911110607r5357d8amfec6205f81be6f23@mail.gmail.com> Message-ID: <6e5b31840911110628y1a4c9500o110502a07efdbdb7@mail.gmail.com> search the web, find the sites and follow the instructions. On Wed, Nov 11, 2009 at 2:11 PM, baboucarr sanneh wrote: > > How can i use it ? > > *$LIM $H at DY* > > > > > ------------------------------ > Date: Wed, 11 Nov 2009 14:07:47 +0000 > Subject: Re: PyQt 2 Exe > From: starglider101 at gmail.com > To: sanneh27 at hotmail.com > > > py2exe > pyinstaller > > On Wed, Nov 11, 2009 at 1:29 PM, baboucarr sanneh wrote: > > Hi guys, > > I wan to make a gui app using pyqt so i have done some thing already now i > want to save it as an exe file so that i can give it out to users who dont > have pyqt installed (windows users)..Please help me out on this one..thnx > > Regards > > *$LIM $H at DY* > > > > ------------------------------ > Keep your friends updated? even when you?re not signed in. > > -- > http://mail.python.org/mailman/listinfo/python-list > > > > ------------------------------ > Windows Live: Keep your friends up to date with what you do online. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpurdie at rpsys.net Wed Nov 11 09:29:21 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 14:29:21 +0000 Subject: Unexpected python exception In-Reply-To: <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> Message-ID: <1257949761.29038.399.camel@dax.rpnet.com> On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: > On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: > > > Is there a way to make the "global x" apply to all functions without > > adding it to each one? > > Thankfully, no. Hmm :(. > > What I'm trying to do is to avoid having "import X" statements > > everywhere by changing __builtin__. It seems my approach doesn't have > > quite the same effect as a true import though. > > And you can't just put all your imports together at the top of the > file because...? The application in question is bitbake, the parsing tool for the OpenEmbedded and Poky projects. We're talking about python code fragments spread across about 8,000 files which make up the "metadata" some of which is public and some of which is not. Rightly or wrongly bitbake does some interesting things with its execution contexts for these code fragments. Lets just say its not a traditional use case, we know the way bitbake does some things is evil but it does other things rather well and we can't break those. Cheers, Richard From deets at nospam.web.de Wed Nov 11 09:37:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 15:37:15 +0100 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <7m00grF3fr11qU1@mid.uni-berlin.de> 7stud schrieb: > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > Installing easy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > > 2) ...run the following as super-user (or administrator): > > easy_install lxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_install lxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_install lxml > > ----------- > > My os is mac os x 10.4.11. But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_install lxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. Nonsense. First of all, developers aren't "the average user". Second, the inability of others doesn't make a programmer worse. And third, there are limits to what extend one can anticipate the ineptness of others to read. The page you cite from starts with: For special installation instructions regarding MS Windows and MacOS-X, see below. And below you find this link: http://codespeak.net/lxml/build.html#building-lxml-on-macos-x Which contains the proper command STATIC_DEPS=true sudo easy_install lxml Diez From benjamin.kaplan at case.edu Wed Nov 11 09:40:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:40:43 -0500 Subject: PyQt 2 Exe In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 8:29 AM, baboucarr sanneh wrote: > Hi guys, > > I wan to make a gui app using pyqt so i have done some thing already now i > want to save it as an exe file so that i can give it out to users who dont > have pyqt installed? (windows users)..Please help me out on this one..thnx > > Regards > > $LIM $H at DY > http://lmgtfy.com/?q=python+exe the second link is to http://www.py2exe.org which is a program that bundles Python apps, the interpreter itself, and any libraries they need into a single executable. > > ________________________________ > Keep your friends updated? even when you?re not signed in. > -- > http://mail.python.org/mailman/listinfo/python-list > > From benjamin.kaplan at case.edu Wed Nov 11 09:46:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:46:35 -0500 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: On Wed, Nov 11, 2009 at 7:49 AM, 7stud wrote: > I'm trying to install lxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > Installing easy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > > 2) ...run the following as super-user (or administrator): > > easy_install lxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_install lxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_install lxml > > ----------- > > My os is mac os x 10.4.11. ? But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_install lxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. > > 1) It's not Python's fault that OS X doesn't add things to the path when its in a framework (like Python). 2) You almost got the command right. Environment variables are set before *any* command, including sudo. STATIC_DEPS=true sudo easy_install lxml > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From bbxx789_05ss at yahoo.com Wed Nov 11 09:54:23 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 06:54:23 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <3b94f11a-f4c8-4a84-aa71-93aed98b7bdc@f10g2000vbl.googlegroups.com> On Nov 11, 6:31?am, Jussi Piitulainen wrote: > 7stud writes: > > I'm trying to install lxml, but I can't figure out the installation > > instructions. ?Here: > ... > > My os is mac os x 10.4.11. ? But this: > > > STATIC_DEPS=true easy_install lxml > > > is not a valid command: > > > $ sudo STATIC_DEPS=true easy_install lxml > > Password: > > sudo: STATIC_DEPS=true: command not found > > Maybe > > ? ?STATIC_DEPS=true sudo easy_install lxml > > And be running Bash or some other Bourne type shell. > That worked. (The Terminal app on my mac uses bash by default.) Unfortunately, easy_install was not able to install lxml! Here is the output: --- $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: sudo: STATIC_DEPS=true: command not found $ STATIC_DEPS=true sudo /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: Searching for lxml Reading http://pypi.python.org/simple/lxml/ Reading http://codespeak.net/lxml Best match: lxml 2.2.3 Downloading http://codespeak.net/lxml/lxml-2.2.3.tgz Processing lxml-2.2.3.tgz Running lxml-2.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install- r2obQa/lxml-2.2.3/egg-dist-tmp-7v5A1n Building lxml version 2.2.3. Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/bin/ easy_install", line 8, in load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1712, in main File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1700, in with_ei_usage File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1716, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 211, in run File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 446, in easy_install File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 476, in install_item File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 655, in install_eggs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 930, in build_and_install File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 919, in run_setup File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 62, in run_setup File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 105, in run File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 64, in File "setup.py", line 119, in File "/tmp/easy_install-r2obQa/lxml-2.2.3/setupinfo.py", line 51, in ext_modules TypeError: build_libxml2xslt() got an unexpected keyword argument 'libiconv_version' From benjamin.kaplan at case.edu Wed Nov 11 09:56:08 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:56:08 -0500 Subject: installing lxml ? In-Reply-To: <7lvvmaF3ga6r2U1@mid.uni-berlin.de> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7lvvmaF3ga6r2U1@mid.uni-berlin.de> Message-ID: On Wed, Nov 11, 2009 at 9:23 AM, Diez B. Roggisch wrote: > Chris Rebert schrieb: >> >> On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: >>> >>> I'm trying to install lxml, but I can't figure out the installation >>> instructions. ?Here: >>> >>> http://codespeak.net/lxml/installation.html >>> >>> it says: >>> >>> 1) Get the easy_install tool. >> >> >>> >>> My os is mac os x 10.4.11. >> >> I would recommend installing fink (http://www.finkproject.org/) and >> then `sudo fink install setuptools-py26`. >> As a bonus, you'll get a more up-to-date Python installed separate >> from the system one (so you don't need to worry about hosing it). > > Which doesn't run any cocoa or other osx-specific code. Which some might > call "hosed from the very beginning". > http://pdb.finkproject.org/pdb/package.php/pyobjc-py26 I personally use Macports (it's got more stuff and more up to date from what I've found), but compiling all those packages can take a while especially for something with as many dependencies as Python. > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From bbxx789_05ss at yahoo.com Wed Nov 11 10:12:39 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 07:12:39 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> Message-ID: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> On Nov 11, 7:37?am, "Diez B. Roggisch" wrote: > And third, > there are limits to what extend one can anticipate the ineptness of > others to read. The page you cite from starts with: > > ? ?For special installation instructions regarding MS Windows and > MacOS-X, see below. > > And below you find this link: > > ? ?http://codespeak.net/lxml/build.html#building-lxml-on-macos-x > > Which contains the proper command > > ? ?STATIC_DEPS=true sudo easy_install lxml > Your characterization of that web page is so fraudulent that I can only say one thing in response: You are a damn liar. From mad.mick at gmx.de Wed Nov 11 10:14:59 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Wed, 11 Nov 2009 16:14:59 +0100 Subject: Basic list/dictionary question In-Reply-To: <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> Message-ID: Ralax wrote: > On Nov 11, 8:58 pm, Chris Rebert wrote: >> In [2]: def foo(z, a=[]): >> ...: a.append(z) >> ...: return a >> ...: >> >> In [3]: foo(1) >> Out[3]: [1] >> >> In [4]: foo(2) >> Out[4]: [1, 2] >> >> In [5]: foo(2) >> Out[5]: [1, 2, 2] >> >> In [6]: foo(3) >> Out[6]: [1, 2, 2, 3] >> >> In [7]: foo(4,[]) >> Out[7]: [4] >> >> In [8]: foo(5) >> Out[8]: [1, 2, 2, 3, 5] > > Usefull! I think Chris post was meant as a warning, but yes, it is useful sometimes. Here's a less error-prone version: >>> def bar(): ... def foo(z, a=[]): ... a.append(z) ... return a ... return foo ... >>> f = bar() >>> f(1) [1] >>> f(2) [1, 2] >>> g = bar() >>> g(3) [3] >>> g(4) [3, 4] Regards, Mick. From stefan_ml at behnel.de Wed Nov 11 10:17:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 11 Nov 2009 16:17:49 +0100 Subject: installing lxml ? In-Reply-To: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: <4afad59d$0$6736$9b4e6d93@newsspool2.arcor-online.net> 7stud, 11.11.2009 16:12: > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: >> And third, >> there are limits to what extend one can anticipate the ineptness of >> others to read. The page you cite from starts with: >> >> For special installation instructions regarding MS Windows and >> MacOS-X, see below. >> >> And below you find this link: >> >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x >> >> Which contains the proper command >> >> STATIC_DEPS=true sudo easy_install lxml > > Your characterization of that web page is so fraudulent that I can > only say one thing in response: You are a damn liar. PLONK. Stefan From highcar at gmail.com Wed Nov 11 10:20:10 2009 From: highcar at gmail.com (elca) Date: Wed, 11 Nov 2009 07:20:10 -0800 (PST) Subject: win32com IE interface PAMIE javascript click Message-ID: <26302679.post@talk.nabble.com> Hello, these day im making some script. i have encounter some problem with my script work. problem is i want to click emulate javascript on following site. http://news.naver.com/main/presscenter/category.nhn this site is news site. and everyday news content also changed, but javascript is not changed. for example i want to click javascript every inside 'li' element . how can i make it work with Pamie or win32com IE interface? thanks in advance
  • http://www.bloter.net/wp-content/bloter_html/2009/11/11/19083.html ???? ??? ?? ?? ???????? MS vs. VM??,
  • http://www.bloter.net/wp-content/bloter_html/2009/11/11/19105.html http://static.naver.com/newscast/2009/1111/1615301154902609.jpg "??????? PLM ?? ??"
  • -- View this message in context: http://old.nabble.com/win32com-IE-interface-PAMIE-javascript-click-tp26302679p26302679.html Sent from the Python - python-list mailing list archive at Nabble.com. From coldtortuga at gmail.com Wed Nov 11 11:13:54 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Wed, 11 Nov 2009 08:13:54 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: Hmmm. I am trying some algorithms, and timeit reports that a list.extend variant is fastest... WTH?! Really this seems like it must be a "bug" in implementing the "[None]*x" idiom. As expected, appending one-at-a-time is slowest (by an order of magnitude): % python -m timeit -s "N=1000000" \ "z=[2**32-1]" \ "while len(z) References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi wrote: > On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > >> Victor Subervi wrote: >> Wrong? >> 2) you don't show the error traceback >> > because there are none > > try: # It does this, because I've printed 'getpic1.py' etc. > getpic = "getpic" + str(w) + ".py" > try: > os.remove(getpic) > except: > pass There are no error tracebacks because you're deliberately suppressing them with the except: clause above. A bare except: clause *may* be acceptable in production code, where you may *want* to silently ignore all errors, but if you're trying to debug something then it's really not helpful. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Wed Nov 11 11:42:27 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 11:42:27 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury wrote: > On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >> >> Victor Subervi wrote: >>> >> > Wrong? >>> >>> 2) you don't show the error traceback >>> >>> because there are none >> >> try: # It does this, because I've printed 'getpic1.py' etc. >> getpic = "getpic" + str(w) + ".py" >> try: >> os.remove(getpic) >> except: >> pass >> > > There are no error tracebacks because you're deliberately suppressing them > with the except: clause above. A bare except: clause *may* be acceptable in > production code, where you may *want* to silently ignore all errors, but if > you're trying to debug something then it's really not helpful. > Well, that's the *only* place where I do so, and I dare say that in that case, it makes all the sense in the world. If there is no file getpic to remove, then don't worry about it! No, that's not where the error is. Please suggest something else. TIA, V > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jenn.duerr at gmail.com Wed Nov 11 11:43:29 2009 From: jenn.duerr at gmail.com (noydb) Date: Wed, 11 Nov 2009 08:43:29 -0800 (PST) Subject: Pause a script before termination Message-ID: Hi All, I want to pause my script before it terminates, just so a user can have a moment to read some print statements I include at the end. How can this be accomplished? Thanks! From jenn.duerr at gmail.com Wed Nov 11 11:47:05 2009 From: jenn.duerr at gmail.com (noydb) Date: Wed, 11 Nov 2009 08:47:05 -0800 (PST) Subject: Pause a script before termination References: Message-ID: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> On Nov 11, 11:43?am, noydb wrote: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. ?How > can this be accomplished? > > Thanks! Never mind, duh, found my answer now import time time.sleep(10) #10 second pause From lenz at joinville.udesc.br Wed Nov 11 11:49:02 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Wed, 11 Nov 2009 08:49:02 -0800 Subject: Unexpected python exception In-Reply-To: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <200911110849.02346.lenz@joinville.udesc.br> Em Qua 11 Nov 2009, ?s 03:21:55, Diez B. Roggisch escreveu: > Richard Purdie schrieb: > > I've been having problems with an unexpected exception from python which > > I can summarise with the following testcase: > > > > def A(): > > import __builtin__ > > import os > > > > __builtin__.os = os > > > > def B(): > > os.stat("/") > > import os > > > > A() > > B() > > > > which results in: > > > > Traceback (most recent call last): > > File "./test.py", line 12, in > > B() > > File "./test.py", line 8, in B > > os.stat("/") > > UnboundLocalError: local variable 'os' referenced before assignment > > > > If I remove the "import os" from B(), it works as expected. > > > >>From what I've seen, its very unusual to have something operate > > > > "backwards" in scope in python. Can anyone explain why this happens? > > As the import-statement in a function/method-scope doesn't leak the > imported names into the module scope, python treats them as locals. > Which makes your code equivalent to > > > x = 1000 > > def foo(): > print x > x = 10 > > Throws the same error. The remedy is to inform python that a specific > name belongs to global scope, using the "global"-statement. > > def foo(): > global x > print x > x = 10 > > > Beware though that then of course *assigning* to x is on global level. > This shouldn't be of any difference in your case though, because of the > import-only-once-mechanics of python. > > Diez > So...it should not work def A(): import __builtin__ import os __builtin__.os = os A() os.stat("/") but it does. Why ? B() cannot see the import, but the global level can ? Thanks. Eduardo. -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From rami.chowdhury at gmail.com Wed Nov 11 11:54:45 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 11 Nov 2009 08:54:45 -0800 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 08:42:27 -0800, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury > wrote: > >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >>> >>> Victor Subervi wrote: >>>> >>> >> Wrong? >>>> >>>> 2) you don't show the error traceback >>>> >>>> because there are none >>> >>> try: # It does this, because I've printed 'getpic1.py' etc. >>> getpic = "getpic" + str(w) + ".py" >>> try: >>> os.remove(getpic) >>> except: >>> pass >>> >> >> There are no error tracebacks because you're deliberately suppressing >> them >> with the except: clause above. A bare except: clause *may* be >> acceptable in >> production code, where you may *want* to silently ignore all errors, >> but if >> you're trying to debug something then it's really not helpful. >> > > Well, that's the *only* place where I do so, and I dare say that in that > case, it makes all the sense in the world. If there is no file getpic to > remove, then don't worry about it! Sure, and that's your decision to make... in an environment where you know everything else is working fine and the *only reason* that os.remove file is failing is that the file isn't present. If it's failing due to a permissions error, for instance, you won't be any wiser. I'd suggest removing that except clause, seeing what exception is actually raised, and posting that to the list. > No, that's not where the error is.Please > suggest something else. if os.path.exists(getpic): os.unlink(getpic) else: print "File %s could not be found!" % getpic -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From carsten.haese at gmail.com Wed Nov 11 11:58:31 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 11 Nov 2009 11:58:31 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: Victor Subervi wrote: > Here's > a bigger code snippet with the entire try clause: > > if 14 < x < 20: # This just shows that it's a pic, not some > other type of data > y += 1 > w += 1 > try: # It does this, because I've printed 'getpic1.py' etc. > getpic = "getpic" + str(w) + ".py" > try: > os.remove(getpic) > except: > pass > code = """#! /usr/bin/python > import cgitb; cgitb.enable() > import MySQLdb > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > def pic(): > user, passwd, db, host = login() > form = cgi.FieldStorage() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > sql = "select pic%s from products where ID=%s;" > cursor.execute(sql) > content = cursor.fetchone()[0] > cursor.close() > print content > print 'Content-type: image/jpeg' > print > pic()""" % (str(w), str(i)) > script = open(getpic, "w") # I've deleted everything below > this line to the except to test > script.write(code) > print '
  • \n' % > (getpic) > count2 += 1 > except: > print '' > else: > print '\n' % (field) > x += 1 If I'm understanding correctly what you're doing here, you're generating an HTML page with image tags, and at the same time you're generating the scripts whose purpose it is to serve the corresponding images' data. This is a terrible approach for the following reason: If two different users request this page for two different product IDs at roughly the same time, the getpic scripts for the first user will be overwritten by the getpic scripts for the second user before the first user's browser had a chance to issue its requests for the results for his getpic scripts. Rather than auto-generating on-the-fly variants of the getpic scripts that only differ in the picture number and product ID, you should have just one static getpic script that takes parameters from the URL that tell it which image number and product ID to use. This will fix your problem indirectly because then your script won't have to write out any files at all. -- Carsten Haese http://informixdb.sourceforge.net From philip at semanchuk.com Wed Nov 11 11:58:58 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 11 Nov 2009 11:58:58 -0500 Subject: Pause a script before termination In-Reply-To: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> References: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> Message-ID: <5EE56713-3E25-4DFF-A61F-0B53E0B5189C@semanchuk.com> On Nov 11, 2009, at 11:47 AM, noydb wrote: > On Nov 11, 11:43 am, noydb wrote: >> Hi All, >> >> I want to pause my script before it terminates, just so a user can >> have a moment to read some print statements I include at the end. >> How >> can this be accomplished? >> >> Thanks! > > Never mind, duh, found my answer now > > import time > time.sleep(10) #10 second pause Good for you for tracking that down. However, might I suggest that you replace that with a message like "Press to clear this message and end the program"? From gherron at islandtraining.com Wed Nov 11 11:59:12 2009 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 11 Nov 2009 08:59:12 -0800 Subject: Pause a script before termination In-Reply-To: References: Message-ID: <4AFAED60.9050902@islandtraining.com> noydb wrote: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. How > can this be accomplished? > > Thanks! > If your IO is to/from a command line window, try this: raw_input('Hit ENTER to exit: ') Gary Herron From sanneh27 at hotmail.com Wed Nov 11 12:00:41 2009 From: sanneh27 at hotmail.com (baboucarr sanneh) Date: Wed, 11 Nov 2009 17:00:41 +0000 Subject: Pause a script before termination In-Reply-To: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> References: Message-ID: $LIM $H at DY > From: jenn.duerr at gmail.com > Subject: Re: Pause a script before termination > Date: Wed, 11 Nov 2009 08:47:05 -0800 > To: python-list at python.org > > On Nov 11, 11:43 am, noydb wrote: > > Hi All, > > > > I want to pause my script before it terminates, just so a user can > > have a moment to read some print statements I include at the end. How > > can this be accomplished? > > > > Thanks! > > Never mind, duh, found my answer now > > import time > time.sleep(10) #10 second pause > -- > http://mail.python.org/mailman/listinfo/python-list okay thank you _________________________________________________________________ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at seehart.com Wed Nov 11 12:10:26 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 11 Nov 2009 09:10:26 -0800 Subject: Authentication session with urllib2 In-Reply-To: References: Message-ID: <4AFAF002.2040906@seehart.com> An HTML attachment was scrubbed... URL: From no.email at please.post Wed Nov 11 12:16:43 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 17:16:43 +0000 (UTC) Subject: How to specify Python version in script? Message-ID: I have a script that must be run with Python 2.6.x. If one tries to run it with, say, 2.5.x, *eventually* it runs into problems and crashes. (The failure is quicker if one attempts to run it with Python 3.x.) Is there some way to specify at the very beginning of the script the acceptable range of Python versions? TIA! kynn P.S. I know that I can hardcode the path to a specific intpreter in the #! line, but I'm trying to keep the code a bit more general than that. From lifeofsun at gmail.com Wed Nov 11 12:18:01 2009 From: lifeofsun at gmail.com (leo zhao) Date: Wed, 11 Nov 2009 09:18:01 -0800 (PST) Subject: ask a question about the module Message-ID: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> when I run a program, it list the hint: Could not import module "Gnuplot" - it is not installed on your system. You need to install the Gnuplot.py package. \easyviz\gnuplot_.py(41) : Traceback (most recent call last): File "E:\study\python\commodity modle 10.23.py", line 3, in import multipleloop as mp File "E:\study\python\multipleloop.py", line 81, in from scitools.misc import str2obj File "C:\Python26\lib\site-packages\scitools\__init__.py", line 67, in import sys, std File "C:\Python26\lib\site-packages\scitools\std.py", line 26, in from scitools.easyviz import * File "C:\Python26\lib\site-packages\scitools\easyviz\__init__.py", line 1819, in exec(cmd) File "", line 1, in File "C:\Python26\lib\site-packages\scitools\easyviz\gnuplot_.py", line 42, in import Gnuplot ImportError: No module named Gnuplot the above is the hint from python window, I know Gnuplot is a software and it can help us to make graphs, however, after I download Gnuplot and run it, the problem still exist. Is there any expert can help me solve this problem? Thank you very much! From victorsubervi at gmail.com Wed Nov 11 12:30:04 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 12:30:04 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> On Wed, Nov 11, 2009 at 11:58 AM, Carsten Haese wrote: > Victor Subervi wrote: > > Here's > > a bigger code snippet with the entire try clause: > > > > if 14 < x < 20: # This just shows that it's a pic, not some > > other type of data > > y += 1 > > w += 1 > > try: # It does this, because I've printed 'getpic1.py' etc. > > getpic = "getpic" + str(w) + ".py" > > try: > > os.remove(getpic) > > except: > > pass > > code = """#! /usr/bin/python > > import cgitb; cgitb.enable() > > import MySQLdb > > import cgi > > import sys,os > > sys.path.append(os.getcwd()) > > from login import login > > def pic(): > > user, passwd, db, host = login() > > form = cgi.FieldStorage() > > db = MySQLdb.connect(host, user, passwd, db) > > cursor= db.cursor() > > sql = "select pic%s from products where ID=%s;" > > cursor.execute(sql) > > content = cursor.fetchone()[0] > > cursor.close() > > print content > > print 'Content-type: image/jpeg' > > print > > pic()""" % (str(w), str(i)) > > script = open(getpic, "w") # I've deleted everything below > > this line to the except to test > > script.write(code) > > print '\n' % > > (getpic) > > count2 += 1 > > except: > > print '' > > else: > > print '\n' % (field) > > x += 1 > > If I'm understanding correctly what you're doing here, you're generating > an HTML page with image tags, and at the same time you're generating the > scripts whose purpose it is to serve the corresponding images' data. > This is a terrible approach for the following reason: If two different > users request this page for two different product IDs at roughly the > same time, the getpic scripts for the first user will be overwritten by > the getpic scripts for the second user before the first user's browser > had a chance to issue its requests for the results for his getpic scripts. > > Rather than auto-generating on-the-fly variants of the getpic scripts > that only differ in the picture number and product ID, you should have > just one static getpic script that takes parameters from the URL that > tell it which image number and product ID to use. > I will do that after I fix the problem > > This will fix your problem indirectly because then your script won't > have to write out any files at all. > No files are being written at all! No, this doesn't fix the problem! Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Wed Nov 11 12:33:25 2009 From: drobinow at gmail.com (David Robinow) Date: Wed, 11 Nov 2009 12:33:25 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: <4eb0089f0911110933l1eed6ecamf9904bd107634cf1@mail.gmail.com> On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: > > > > > I have a script that must be run with Python 2.6.x. ?If one tries > to run it with, say, 2.5.x, *eventually* it runs into problems and > crashes. ?(The failure is quicker if one attempts to run it with > Python 3.x.) > > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? > > TIA! > > kynn > > P.S. I know that I can hardcode the path to a specific intpreter > in the #! line, but I'm trying to keep the code a bit more general > than that. > -- > http://mail.python.org/mailman/listinfo/python-list > sys.version ? sys.version_info ? From carsten.haese at gmail.com Wed Nov 11 12:46:51 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 11 Nov 2009 12:46:51 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> Message-ID: Victor Subervi wrote: > I will do that after I fix the problem "Doing that" is the fix. > No, this doesn't fix the problem! How do you know? You obviously haven't tried it, since you say you have yet to do it. -- Carsten Haese http://informixdb.sourceforge.net From benjamin.kaplan at case.edu Wed Nov 11 13:18:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:18:39 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: > > > > > I have a script that must be run with Python 2.6.x. ?If one tries > to run it with, say, 2.5.x, *eventually* it runs into problems and > crashes. ?(The failure is quicker if one attempts to run it with > Python 3.x.) > > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? > min_version = (2,6) import sys if sys.version_info < min_version : print >> stderr, "must be run with at least Python 2.6" sys.exit(1) > TIA! > > kynn > > P.S. I know that I can hardcode the path to a specific intpreter > in the #! line, but I'm trying to keep the code a bit more general > than that. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Wed Nov 11 13:20:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:20:58 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury > wrote: >> >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi >> wrote: >> >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >>> >>>> Victor Subervi wrote: >> >>>> Wrong? >>>> 2) you don't show the error traceback >>>> >>> because there are none >>> >>> ? ? ? ? ? ?try: # It does this, because I've printed 'getpic1.py' etc. >>> ? ? ? ? ? ? ?getpic = "getpic" + str(w) + ".py" >>> ? ? ? ? ? ? ?try: >>> ? ? ? ? ? ? ? ?os.remove(getpic) >>> ? ? ? ? ? ? ?except: >>> ? ? ? ? ? ? ? ?pass >> >> There are no error tracebacks because you're deliberately suppressing them >> with the except: clause above. A bare except: clause *may* be acceptable in >> production code, where you may *want* to silently ignore all errors, but if >> you're trying to debug something then it's really not helpful. > > Well, that's the *only* place where I do so, and I dare say that in that > case, it makes all the sense in the world. If there is no file getpic to > remove, then don't worry about it! No, that's not where the error is. Please > suggest something else. > TIA, > V Even so, a bare except is a bad idea. Just catch the OSError. That way, you won't catch something like an NameError if you misspell getpic or something like that. >> >> >> -- >> Rami Chowdhury >> "Never attribute to malice that which can be attributed to stupidity" -- >> Hanlon's Razor >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From javier.collado at gmail.com Wed Nov 11 13:28:37 2009 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 11 Nov 2009 19:28:37 +0100 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: Hello, If you are working on linux, you can change the shebang line from: #!/usr/bin/python to: #!/usr/bin/python2.6 Best regards, Javier P.S. If you just want to avoid python 3 while running the latest python 2.x version, this should also work: #!/usr/bin/python2 2009/11/11 Benjamin Kaplan : > On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >> >> >> >> >> I have a script that must be run with Python 2.6.x. ?If one tries >> to run it with, say, 2.5.x, *eventually* it runs into problems and >> crashes. ?(The failure is quicker if one attempts to run it with >> Python 3.x.) >> >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >> > > min_version = (2,6) > import sys > if sys.version_info < min_version : > ? print >> stderr, "must be run with at least Python 2.6" > ? sys.exit(1) > > >> TIA! >> >> kynn >> >> P.S. I know that I can hardcode the path to a specific intpreter >> in the #! line, but I'm trying to keep the code a bit more general >> than that. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Wed Nov 11 13:39:17 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:39:17 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 1:28 PM, Javier Collado wrote: > Hello, > > If you are working on linux, you can change the shebang line from: > #!/usr/bin/python > > to: > #!/usr/bin/python2.6 > > Best regards, > ? ?Javier > > P.S. If you just want to avoid python 3 while running the latest > python 2.x version, this should also work: > #!/usr/bin/python2 > True, except that it doesn't meet the OP's requirements. The OP wanted to be able to specify a range of versions. The problem with changing the shebang line is that there's no way to say "python 2.5 or 2.6 or 2.7" Regardless, it's much better to do #!/usr/bin/evn python2.6 instead of hard-coding the path because not everyone has their interpreter in the same spot. I have the Macports python 2.6.4 installed in /opt/local/bin and I'd get kind of annoyed if a script, insisted on using the 2.6.1 that came with the system, especially if it depends on 3rd party libraries. > 2009/11/11 Benjamin Kaplan : >> On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >>> >>> >>> >>> >>> I have a script that must be run with Python 2.6.x. ?If one tries >>> to run it with, say, 2.5.x, *eventually* it runs into problems and >>> crashes. ?(The failure is quicker if one attempts to run it with >>> Python 3.x.) >>> >>> Is there some way to specify at the very beginning of the script >>> the acceptable range of Python versions? >>> >> >> min_version = (2,6) >> import sys >> if sys.version_info < min_version : >> ? print >> stderr, "must be run with at least Python 2.6" >> ? sys.exit(1) >> >> >>> TIA! >>> >>> kynn >>> >>> P.S. I know that I can hardcode the path to a specific intpreter >>> in the #! line, but I'm trying to keep the code a bit more general >>> than that. >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From boblatest at yahoo.com Wed Nov 11 14:01:33 2009 From: boblatest at yahoo.com (Robert Latest) Date: 11 Nov 2009 19:01:33 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> Message-ID: <7m0g0cF3d568fU1@mid.uni-berlin.de> r wrote: > Just thinking out loud here...what if variable assignments could > return a value... hmmm? Not to them selfs of course but to a caller, > like an if statement... > > if a=openfile: > # do something with a That's like in C. I sometimes miss it in Python. robert From victorsubervi at gmail.com Wed Nov 11 14:26:53 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:26:53 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> On Wed, Nov 11, 2009 at 1:20 PM, Benjamin Kaplan wrote: > On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi > wrote: > > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury < > rami.chowdhury at gmail.com> > > wrote: > >> > >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi > >> wrote: > >> > >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > >>> > >>>> Victor Subervi wrote: > >> > >>>> Wrong? > >>>> 2) you don't show the error traceback > >>>> > >>> because there are none > >>> > >>> try: # It does this, because I've printed 'getpic1.py' etc. > >>> getpic = "getpic" + str(w) + ".py" > >>> try: > >>> os.remove(getpic) > >>> except: > >>> pass > >> > Ok, I rewrote the script so that it calls one file called "getpic.py" with parameters: #! /usr/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login form = cgi.FieldStorage() w = form.getfirst('w', '') i = form.getfirst('i', '') def pic(): user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic%s from products where ID=%s;" % (w, i) cursor.execute(sql) content = cursor.fetchone()[0] cursor.close() print content print 'Content-type: image/jpeg' print pic() Now, the problem is that it doesn't print the picture. It prints only the url. Please try: http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 Now, if I go into mysql and the correct database and enter: select pic1 from products where ID=1; it starts printing out all sorts of crap (indicative of an image) and I have to close my ssh client. So it's there, all right. So, here I am back to trying to figure out how to get that stupid image to print. Please take a look at the code above and advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Nov 11 14:33:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 14:33:09 -0500 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: Steven D'Aprano wrote: >>> Why is the third example, with an if... test, so special that it needs >>> special syntax to make it a two-liner? >> ...because Beautiful is better than ugly. > > I can quote the Zen too: > > Special cases aren't special enough to break the rules. > > You haven't demonstrated that your construct is "beautiful", or the > existing way of writing it is "ugly". > > # apparently not ugly > x = func() > y = x + 1 > z = 2*x > > # also not ugly > var = range(N) > var.append(42) > find(23, var) > > # still not ugly > var = range(N) > for x in var: > do_something_with(x, var) > > # not ugly > var = MyClass() > with var.magic as x: > process(var) > > > # why is this ugly? > var = range(N) > if var: > process(var) This is the first time I have seen this explanation and justification of the status quo. Thanks for posting it so clearly. ... > What's so special about "truth-seeking"? as a second use > > for x in range(N) as var: > do_something_with(x, var) > > > That would save a line too, it would behave exactly as you specified, and > it uses virtually the identical syntax: "expr as name". I know that Guido does not want to generalize 'as' as a substitute for '=' except where really necessary. The three current uses in import, with, and except statements are necessary because the object being bound is produced in the statement itself and so the assignment cannot be separated into a prior proper assignment statement. Terry Jan Reedy From sridhar.ratna at gmail.com Wed Nov 11 14:38:23 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 11:38:23 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <8d874346-b5d7-4fd6-9ffe-391340145885@e4g2000prn.googlegroups.com> Much of these non-trivial build steps are abstracted in the ActiveState build repository. 1. Download ActivePython: http://www.activestate.com/activepython/ 2. Run "pypm install lxml" (on Mac, Linux or Windows) $ pypm install lxml Ready to perform these actions: The following packages will be installed: lxml-2.2.2 Get: [pypm.activestate.com] lxml 2.2.2-2 Installing lxml-2.2.2 $ python -c "import lxml; print lxml.__file__" /Users/sridharr/.local/lib/python2.6/site-packages/lxml/__init__.py $ -srid On Nov 11, 4:49?am, 7stud wrote: > I'm trying to installlxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installingeasy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/binInstallingeasy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > 2) ...run the following as super-user (or administrator): > > easy_installlxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_installlxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_installlxml > > ----------- > > My os is mac os x 10.4.11. ? But this: > > STATIC_DEPS=true easy_installlxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_installlxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installingeasy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. From sridhar.ratna at gmail.com Wed Nov 11 14:39:54 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 11:39:54 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <3b94f11a-f4c8-4a84-aa71-93aed98b7bdc@f10g2000vbl.googlegroups.com> Message-ID: <4ad5ade3-1212-4cd7-b279-b280adea9503@i12g2000prg.googlegroups.com> On Nov 11, 6:54?am, 7stud wrote: > > Unfortunately, easy_install was not able to installlxml! ?Here is the > output: > > --- > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > $ STATIC_DEPS=true sudo /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > Searching forlxml > Readinghttp://pypi.python.org/simple/lxml/ > Readinghttp://codespeak.net/lxml > Best match:lxml2.2.3 > Downloadinghttp://codespeak.net/lxml/lxml-2.2.3.tgz > Processinglxml-2.2.3.tgz > Runninglxml-2.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install- > r2obQa/lxml-2.2.3/egg-dist-tmp-7v5A1n > Buildinglxmlversion 2.2.3. > Traceback (most recent call last): > ? File "/Library/Frameworks/Python.framework/Versions/2.6/bin/ > easy_install", line 8, in > ? ? load_entry_point('setuptools==0.6c11', 'console_scripts', > 'easy_install')() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1712, in main > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1700, in with_ei_usage > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1716, in > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/core.py", line 152, in setup > ? ? dist.run_commands() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/dist.py", line 975, in run_commands > ? ? self.run_command(cmd) > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/dist.py", line 995, in run_command > ? ? cmd_obj.run() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 211, in run > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 446, in easy_install > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 476, in install_item > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 655, in install_eggs > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 930, in build_and_install > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 919, in run_setup > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 62, in run_setup > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 105, in run > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 64, in > ? File "setup.py", line 119, in > > ? File "/tmp/easy_install-r2obQa/lxml-2.2.3/setupinfo.py", line 51, in > ext_modules > TypeError: build_libxml2xslt() got an unexpected keyword argument > 'libiconv_version' https://bugs.launchpad.net/lxml/+bug/480225 -srid From victorsubervi at gmail.com Wed Nov 11 14:42:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:42:39 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: <4dc0cfea0911111142hbac8862nf649cc80dbf43d14@mail.gmail.com> Never mind. It appears my old original file from a couple of years ago prints out the image nicely. Thanks all! V On Wed, Nov 11, 2009 at 2:26 PM, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 1:20 PM, Benjamin Kaplan > wrote: > >> On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi >> wrote: >> > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury < >> rami.chowdhury at gmail.com> >> > wrote: >> >> >> >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi >> >> wrote: >> >> >> >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >> >>> >> >>>> Victor Subervi wrote: >> >> >> >>>> Wrong? >> >>>> 2) you don't show the error traceback >> >>>> >> >>> because there are none >> >>> >> >>> try: # It does this, because I've printed 'getpic1.py' etc. >> >>> getpic = "getpic" + str(w) + ".py" >> >>> try: >> >>> os.remove(getpic) >> >>> except: >> >>> pass >> >> >> > > Ok, I rewrote the script so that it calls one file called "getpic.py" with > parameters: > > #! /usr/bin/python > import cgitb; cgitb.enable() > import MySQLdb > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > form = cgi.FieldStorage() > w = form.getfirst('w', '') > i = form.getfirst('i', '') > def pic(): > user, passwd, db, host = login() > form = cgi.FieldStorage() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > sql = "select pic%s from products where ID=%s;" % (w, i) > cursor.execute(sql) > content = cursor.fetchone()[0] > cursor.close() > print content > print 'Content-type: image/jpeg' > print > pic() > > Now, the problem is that it doesn't print the picture. It prints only the > url. Please try: > http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 > Now, if I go into mysql and the correct database and enter: > select pic1 from products where ID=1; > it starts printing out all sorts of crap (indicative of an image) and I > have to close my ssh client. So it's there, all right. So, here I am back to > trying to figure out how to get that stupid image to print. Please take a > look at the code above and advise. > TIA, > V > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Wed Nov 11 14:46:40 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 11 Nov 2009 11:46:40 -0800 Subject: Can't Write File In-Reply-To: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: > Now, the problem is that it doesn't print the picture. It prints only the > url. Please try: > http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 > Now, if I go into mysql and the correct database and enter: > select pic1 from products where ID=1; > it starts printing out all sorts of crap (indicative of an image) and I > have > to close my ssh client. So it's there, all right. So, here I am back to > trying to figure out how to get that stupid image to print. Please take a > look at the code above and advise. I'm fairly sure this was gone through before -- what I'm getting is being properly sent as a JPEG, but it *doesn't contain valid JPEG data*, so the browser can't render it. What the URL you pointed me at seems to contain is the 'readable' representation of an array object. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Wed Nov 11 14:47:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:47:52 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: <4dc0cfea0911111147l406d786fg930e51c2f67c1371@mail.gmail.com> On Wed, Nov 11, 2009 at 2:46 PM, Rami Chowdhury wrote: > Now, the problem is that it doesn't print the picture. It prints only the >> url. Please try: >> http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 >> Now, if I go into mysql and the correct database and enter: >> select pic1 from products where ID=1; >> it starts printing out all sorts of crap (indicative of an image) and I >> have >> to close my ssh client. So it's there, all right. So, here I am back to >> trying to figure out how to get that stupid image to print. Please take a >> look at the code above and advise. >> > > I'm fairly sure this was gone through before -- what I'm getting is being > properly sent as a JPEG, but it *doesn't contain valid JPEG data*, so the > browser can't render it. What the URL you pointed me at seems to contain is > the 'readable' representation of an array object. > Yep. A million times before. The problem was the faulty hardware on the cheap server farm. I've moved ;) Thanks, V > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 71david at libero.it Wed Nov 11 14:50:35 2009 From: 71david at libero.it (David) Date: Wed, 11 Nov 2009 20:50:35 +0100 Subject: Pause a script before termination References: Message-ID: Il Wed, 11 Nov 2009 08:43:29 -0800 (PST), noydb ha scritto: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. How > can this be accomplished? http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user D. From tjreedy at udel.edu Wed Nov 11 15:15:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 15:15:02 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: Robert P. J. Day wrote: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > > thoughts? Program_cost = human_writing&maintance_cost + running_cost*number_of_runs Nothing new here. The builtin types and many modules are written in C to reduce running cost for frequency used components. The first killer ap for Python was scientific computing with early numerical python, where people often run one-time combinations of inputs and constantly reused linear algebra functions. Google has an unusually high number of runs for many programs, making running_cost minimization important. At one time, C was not 'scaleable enough' for constantly rerun aps. Hotspots were hand rewritten in assembler. Apparently now, with processors more complex and compilers much improved, that is not longer much the case. I can imagine a day when code compiled from Python is routinely time-competitive with hand-written C. Terry Jan Reedy From no.email at please.post Wed Nov 11 15:16:50 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 20:16:50 +0000 (UTC) Subject: How can a module know the module that imported it? Message-ID: The subject line says it all. Thanks! kynn From no.email at please.post Wed Nov 11 15:19:00 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 20:19:00 +0000 (UTC) Subject: How to specify Python version in script? References: Message-ID: In Benjamin Kaplan writes: >On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >> >> >> >> >> I have a script that must be run with Python 2.6.x. =A0If one tries >> to run it with, say, 2.5.x, *eventually* it runs into problems and >> crashes. =A0(The failure is quicker if one attempts to run it with >> Python 3.x.) >> >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >> >min_version =3D (2,6) >import sys >if sys.version_info < min_version : > print >> stderr, "must be run with at least Python 2.6" > sys.exit(1) Thanks! kynn From davea at ieee.org Wed Nov 11 15:32:51 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 11 Nov 2009 15:32:51 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> Message-ID: <4AFB1F73.5070508@ieee.org> Victor Subervi wrote: > > The problem was not CGI. It turned out to be line-endings being mangled by > Windoze and __invisible __ in my unix editor. Lovely. > Thanks anyway, > V > > That's twice you've blamed Windows for the line-ending problem. Windows didn't create those crlf endings, your text editor did. If your editor can't control that, you could try a different one. Komodo for example can do it either way, or it can preserve whatever is being used in the loaded file. Similarly metapad, in spite of its huge simplicity, lets you decide, and can convert an existing file in either direction. And I'm a great believer in visible control characters. I configure Komodo to show me spaces in the lines, so I can see whether it's a tab or a space. It can also be configured to show end-of-line characters, so I presume that'd work here. See whether your Unix editor can show you this sort of thing. Finally, many FTP programs can be told to automatically convert line-endings when transferring text files. There's probably some risk that it'll mangle a non-text file, but it's worth considering. DaveA From tjreedy at udel.edu Wed Nov 11 15:37:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 15:37:00 -0500 Subject: installing lxml ? In-Reply-To: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: 7stud wrote: > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: >> And third, >> there are limits to what extend one can anticipate the ineptness of Calling you inept was unnecessary, but.... >> others to read. The page you cite from starts with: You wrote " I'm trying to install lxml, but I can't figure out the installation instructions. Here: http://codespeak.net/lxml/installation.html " >> For special installation instructions regarding MS Windows and >> MacOS-X, see below. and that page indeed begins with the words above. >> And below you find this link: >> >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x >> >> Which contains the proper command >> >> STATIC_DEPS=true sudo easy_install lxml And this is also true. > Your characterization of that web page is so fraudulent that I can > only say one thing in response: You are a damn liar. So this makes no sense. If, when you have calmed down a bit, you have suggestions for improving the installation instructions, that might be more constructive. The lxml developers have obviously gone to some effort to give comprehensible instructions. Writing such is not easy. So if they have failed in your case, feedback might be considered. tjr From zac256 at gmail.com Wed Nov 11 15:40:38 2009 From: zac256 at gmail.com (Zac Burns) Date: Wed, 11 Nov 2009 12:40:38 -0800 Subject: Threaded import hang in cPickle.dumps In-Reply-To: References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <333edbe80911111240v27f17516y69f3d4e18d388fdf@mail.gmail.com> On Tue, Nov 10, 2009 at 2:27 PM, Benjamin Peterson wrote: > Zac Burns gmail.com> writes: >> What can I do about this? > > Not run it in a thread. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Isn't requesting that pickle not be used in a thread a bit of a tall order? Just thinking through the common use cases - database access, server request threads, file IO... pickle is commonly used in threads. Furthermore, the pickle documentation makes no mention of not being threadsafe. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From aahz at pythoncraft.com Wed Nov 11 16:06:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 13:06:07 -0800 Subject: Securing a multiprocessing.BaseManager connection via SSL References: Message-ID: In article , Jonas wrote: > >how can I secure the communication between two BaseManager objects? >Regarding the socket/SSL documentation I just need to secure the socket >by SSL. How can i get the socket object within the multiprocessing >module? You'll need to create subclasses of the objects in connection.py, but I'm not sure how to make multiprocessing use them. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Wed Nov 11 16:12:26 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 13:12:26 -0800 Subject: How can a module know the module that imported it? References: Message-ID: In article , kj wrote: > >The subject line says it all. You are probably trying to remove a screw with a hammer -- why don't you tell us what you really want to do and we'll come up with a Pythonic solution? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ethan at stoneleaf.us Wed Nov 11 16:44:06 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Nov 2009 13:44:06 -0800 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: <4AFB3026.2020408@stoneleaf.us> Aahz wrote: > In article , kj wrote: > >>The subject line says it all. > > > You are probably trying to remove a screw with a hammer -- why don't you > tell us what you really want to do and we'll come up with a Pythonic > solution? Well, I don't know what kj is trying to do, but my project is another (!) configuration program. (Don't worry, I won't release it... unless somebody is interested, of course !) So here's the idea so far: The configuration data is stored in a python module (call it settings.py). In order to be able to do things like add settings to it, save the file after changes are made, etc., settings.py will import the configuration module, called configure.py. A sample might look like this: import configure paths = configure.Item() paths.tables = 'c:\\app\\data' paths.temp = 'c:\\temp' And in the main program I would have: import settings main_table = dbf.Table('%s\\main' % paths.tables) # user can modify path locations, and does, so update # we'll say it changes to \work\temp settings.paths.temp = user_setting() settings.configure.save() And of course, at this point settings.py now looks like import configure paths = configure.Item() paths.tables = 'c:\\app\\data' paths.temp = 'c:\\work\\temp' Now, the tricky part is the line settings.configure.save() How will save know which module it's supposed to be re-writing? The solution that I have for now is def _get_module(): "get the calling module -- should be the config'ed module" target = os.path.splitext(inspect.stack()[2][1])[0] target = __import__(target) return target If there's a better way, I'd love to know about it! Oh, and I'm using 2.5.4, but I suspect kj is using 2.6. ~Ethan~ From solipsis at pitrou.net Wed Nov 11 16:48:36 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 11 Nov 2009 21:48:36 +0000 (UTC) Subject: Threaded import hang in cPickle.dumps References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: Le Tue, 10 Nov 2009 10:50:33 -0800, Zac Burns a ?crit?: > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running cPickle.dumps > in a thread, which leads me to believe that the first restriction here > is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? Please report a bug at http://bugs.python.org Better even if you can provide a small snippet of code which reproduces the problem reliably. Regards Antoine. From no.email at please.post Wed Nov 11 16:55:58 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 21:55:58 +0000 (UTC) Subject: How can a module know the module that imported it? References: Message-ID: In aahz at pythoncraft.com (Aahz) writes: >In article , kj wrote: >> >>The subject line says it all. >You are probably trying to remove a screw with a hammer Worse: I'm trying to write Perl using Python! >-- why don't you >tell us what you really want to do and we'll come up with a Pythonic >solution? Because the problem that gave rise to this question is insignificant. I would want to know the answer in any case. *Can* it be done in Python at all? OK, if you must know: With Perl one can set a module-global variable before the module is loaded. This provides a very handy backdoor during testing. E.g. # in t/some_test.t script ... BEGIN { $My::Module::TESTING = 1; } use My::Module; ... and in My/Module.pm: package My::Module; our $TESTING ||= 0; # set to 0 unless already initialized to !0 ... if ($TESTING) { # throw testing switches } This does not work in Python, because setting my.module.TESTING variable can happen only after my.module has been imported, but by this point, the module's top-level code has already been executed, so setting my.module.TESTING would have no effect. But one way to get a similar effect would be to have my.module set its TESTING (or whatever) variable equal to the value of this variable in the *importing* module. kynn From lists at cheimes.de Wed Nov 11 17:16:25 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 11 Nov 2009 23:16:25 +0100 Subject: Threaded import hang in cPickle.dumps In-Reply-To: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <4AFB37B9.8020309@cheimes.de> Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running > cPickle.dumps in a thread, which leads me to believe that the first > restriction here is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? You can do two things to stop the import lock from dead locking. * Never ever start a thread as a side effect of an import. This means you must not start a thread in the body of a module. As I explained in numerous other messages a well designed application imports all its modules first. After all modules have been imported the components are initialized and the threads are started. * Import all modules that are referred inside your pickled data before you unpickle. Christian From alain at dpt-info.u-strasbg.fr Wed Nov 11 17:31:35 2009 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 11 Nov 2009 23:31:35 +0100 Subject: python simply not scaleable enough for google? References: Message-ID: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. Have a look at http://code.google.com/p/unladen-swallow/downloads/detail?name=Unladen_Swallow_PyCon.pdf&can=2&q= Slide 6 is impressive. The bottom of slide/page 22 explains why python is so slow: in most cases "the program is less dynamic than the language". -- Alain. From deets at nospam.web.de Wed Nov 11 17:47:31 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 23:47:31 +0100 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: <7m0t83F3e6v3rU1@mid.uni-berlin.de> > Because the problem that gave rise to this question is insignificant. > I would want to know the answer in any case. *Can* it be done in > Python at all? No. > > OK, if you must know: > > With Perl one can set a module-global variable before the module > is loaded. This provides a very handy backdoor during testing. > E.g. > > # in t/some_test.t script > ... > BEGIN { $My::Module::TESTING = 1; } > use My::Module; > ... > > and in My/Module.pm: > > package My::Module; > our $TESTING ||= 0; # set to 0 unless already initialized to !0 > ... > if ($TESTING) { > # throw testing switches > } > > > This does not work in Python, because setting my.module.TESTING > variable can happen only after my.module has been imported, but by > this point, the module's top-level code has already been executed, > so setting my.module.TESTING would have no effect. But one way to > get a similar effect would be to have my.module set its TESTING > (or whatever) variable equal to the value of this variable in the > *importing* module. I don't understand enough (actually nothing) from perl, but I *am* a heavily test-driven developer in Python. And never felt that need. Sure, sometimes one wants to change behavior of a module under test, e.g. replacing something with a stub or some such. But where is the problem doing --- mytest.py --- import moduletobetested as m m.SOME_GLOBAL = "whatever" m.do_something() --- Diez From lists at cheimes.de Wed Nov 11 17:50:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 11 Nov 2009 23:50:20 +0100 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: kj wrote: > Because the problem that gave rise to this question is insignificant. > I would want to know the answer in any case. *Can* it be done in > Python at all? > > OK, if you must know: > > With Perl one can set a module-global variable before the module > is loaded. This provides a very handy backdoor during testing. > E.g. > > # in t/some_test.t script > .... > BEGIN { $My::Module::TESTING = 1; } > use My::Module; > .... > > and in My/Module.pm: > > package My::Module; > our $TESTING ||= 0; # set to 0 unless already initialized to !0 > .... > if ($TESTING) { > # throw testing switches > } > That's terrible style! Code should not react differently if you run it inside an unit test harness. If you need to change the environment for tests because you can test all aspects of your runtime environment, use a mock up system. Please read http://www.voidspace.org.uk/python/articles/mocking.shtml if you don't know the term. Christian From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 18:21:26 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 23:21:26 GMT Subject: How can a module know the module that imported it? References: Message-ID: On Wed, 11 Nov 2009 21:55:58 +0000, kj wrote: > With Perl one can set a module-global variable before the module is > loaded. This provides a very handy backdoor during testing. E.g. Any time somebody justifies a features as "a very handy backdoor", a billion voices cry out and then are suddenly silenced... [...] > This does not work in Python, because setting my.module.TESTING variable > can happen only after my.module has been imported, but by this point, > the module's top-level code has already been executed, so setting > my.module.TESTING would have no effect. (1) Then change your design so you're not relying on changing the behaviour of top-level code. Instead of: chant_incantation(arg) # effect module.magic, somehow... import module do_something_with( module.magic ) (where magic is created by the top-level code) do this instead: import module do_something_with( module.make_magic(arg) ) (2) If you still want a back-door, encapsulate it in another module: # Contents of module.py import _secret_backdoor if _secret_backdoor.manna > 17: magic = 42 else: magic = 23 Then in your calling code: # chant an incantation to change the behaviour of module import _secret_backdoor _secret_backdoor.manna = 1003 import module do_something_with(module.magic) (3) Abuse __builtins__ by polluting it with your own junk: # Contents of module.py try: my_secret_name12761 except NameError: magic = 23 else: magic = 42 Then in your calling code: # chant an incantation to change the behaviour of module import __builtins__ __builtins__.my_secret_name12761 = None import module do_something_with(module.magic) But if you do this one, hundreds of Python developers carrying flaming torches and pitchforks will track you down and do terrible things to your corpse... *wink* -- Steven From rhodri at wildebst.demon.co.uk Wed Nov 11 18:35:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 11 Nov 2009 23:35:08 -0000 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 14:00:44 -0000, Victor Subervi wrote: >> 6) you don't indicate which user is executing this script (only root can >> write to it) >> > Help me on this. All scripts are owned by root. Is it not root that is > executing the script? Not unless your server setup is very, very stupid. CGI scripts normally run as a user with *very* limited permissions to limit (amongst other things) the damage ineptly written scripts can do. -- Rhodri James *-* Wildebeest Herder to the Masses From sridhar.ratna at gmail.com Wed Nov 11 18:39:07 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 15:39:07 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <7610c270-23a6-46f7-855b-0071ce4147c4@e4g2000prn.googlegroups.com> On Nov 10, 8:25?pm, Phlip wrote: > On Nov 10, 3:11?pm, Wolodja Wentland > wrote: > > > The pip requirement file would contain the following line: > > > -e git+git://example.com/repo.git#egg=rep > > > I hope this answers your questions :-D > > Let me ask it like this. What happens when a user types..? > > ? ?sudo pip install repo Hey Phlip, If you run "pip install repo", it will try to find a package in http://pypi.python.org/ named "repo". Run the following commands: $ pip install pastescript $ paster create myapp $ cd myapp/ $ python setup.py sdist register upload That's all you need to do .. to have your "myapp" project uploaded to PyPI. From now onwards, anyone connected to the internet will be able to run "pip install myapp" to get your package. For more details, may I suggest you to read the official distutils tutorial: http://wiki.python.org/moin/Distutils/Tutorial -srid PS: Another advantage of using distutils (or setuptools/distribute) and uploading your package to PyPI is that you would automatically enable other package managers (such as PyPM - http://pypm.activestate.com/ ) to support your package. From rhodri at wildebst.demon.co.uk Wed Nov 11 18:55:15 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 11 Nov 2009 23:55:15 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: On Wed, 11 Nov 2009 04:51:38 -0000, SD_V897 wrote: > > Rhodri James wrote: >> On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 >> wrote: > >> No, I'm asking you -- or rather your admin user -- to invoke the >> program that is giving you grief from the command line, i.e. "python >> myscript.py", and tell me what happens. "It doesn't work" won't be >> considered at all helpful; without details we might as well just print >> out your script, throw darts at it, and tell you the problem is where >> the darts land. >> The rest of your answer however suggests that I've fundamentally >> misunderstood what you've said. Please tell me *exactly* what happens >> when it doesn't "run fine" for your admin user. >> > > I fixed it for some reason deleting my idlerc folder allows it to work > again.. > > http://bugs.python.org/issue7206 Then I'd hazard a guess that it was a permissions problem. If it recurs, please actually answer questions when we ask them, otherwise we really might as well not bother. -- Rhodri James *-* Wildebeest Herder to the Masses From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:12:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:12:08 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 03:52:45 -0800, Carl Banks wrote: >> This is where a helper function is good. You want a dispatcher: > > No I really don't. I want to be able to see the action performed > adjacent to the test, and not have to scroll up to down ten pages to > find whatever function it dispatched to. Then re-write the dispatcher to return a tuple (match_object, method_to_call) and then call them there at the spot. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:17:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:17:34 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 04:00:09 -0800, Carl Banks wrote: >> as has been posted before and again in a slightly different form in >> Steve's post. > > I'm well aware of it, but I didn't think the proposal deserved to be > called stupid when it was a reasonable solution to a real need, even > though a workable and less intrusive option exists. Fair enough, I was feeling grumpy at the time. Perhaps "stupid" was unfair. Perhaps. -- Steven From peteRE at MpeteOzilla.Vco.ukE Wed Nov 11 19:20:36 2009 From: peteRE at MpeteOzilla.Vco.ukE (Peter Chant) Date: Thu, 12 Nov 2009 00:20:36 +0000 Subject: python simply not scaleable enough for google? References: Message-ID: Terry Reedy wrote: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. In my very limited experience it was very informative programming in C for PIC microcontrollers and inspecting the assembly code produced. If I just threw together loops and complex if statements the assembly produced was very long and impossible to follow whereas if I though carefully about what I was doing, tried to parallel what I would have done in assembly I found the assembly produced looked a lot like I imagined it would if I were programming in assembler directly. Except that the whole process was 10x faster and actually worked. Pete -- http://www.petezilla.co.uk From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:22:53 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:22:53 GMT Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 08:13:54 -0800, Francis Carr wrote: > Hmmm. I am trying some algorithms, and timeit reports that a > list.extend variant is fastest... WTH?! Really this seems like it must > be a "bug" in implementing the "[None]*x" idiom. > The straightforward "pythonic" solution is better yet: > % python -m timeit -s "N=1000000" \ > "z=[2**32-1]*N" > 100 loops, best of 3: 8.81 msec per loop You're possibly including the time taken to calculate 2**32-1 in each test, which is unnecessary. The peek-hole optimizer *may* be optimizing that away to "z=[4294967295L]*N", or it may not. In any case, why not make the test even simpler and use z=[None]*N? You're testing list methods, not arithmetic and longs. But regardless of what's inside the list, what Python does internally is create an array of some size M, where M is some multiple of two and larger than N, then set the first N elements to the same item, leaving the rest unallocated. (That's what CPython does, other Pythons may behave differently.) Then each time you grow the list, it doubles in size. So over-allocating doesn't necessarily have the cost you think it does. > And the winner for speed is... over-allocate using list.extend, then > delete! > % python -m timeit -s "N=1000000" \ > "z=[2**32-1]" \ > "while len(z) "del z[N:]" > 100 loops, best of 3: 6.93 msec per loop I can't confirm that. I suspect you're running into a hardware specific cache effect or some side-effect of your specific setup. For what it's worth, my timings compared to your timings are: Append one-at-a-time: Me : You 520 : 223 list.extend doubling: 18.5 : 22.2 Multiplication: 9.36 : 8.81 over-allocate then delete 9.42 : 6.93 -- Steven From vmanis at telus.net Wed Nov 11 19:38:50 2009 From: vmanis at telus.net (Vincent Manis) Date: Wed, 11 Nov 2009 16:38:50 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <59997FA1-8E3F-4745-A42C-1B38C69E1047@telus.net> On 2009-11-11, at 14:31, Alain Ketterlin wrote: > Terry Reedy writes: > >> I can imagine a day when code compiled from Python is routinely >> time-competitive with hand-written C. > > Have a look at > http://code.google.com/p/unladen-swallow/downloads/detail?name=Unladen_Swallow_PyCon.pdf&can=2&q= > > Slide 6 is impressive. The bottom of slide/page 22 explains why python > is so slow: in most cases "the program is less dynamic than the > language". I'm having some trouble understanding this thread. My comments aren't directed at Terry's or Alain's comments, but at the thread overall. 1. The statement `Python is slow' doesn't make any sense to me. Python is a programming language; it is implementations that have speed or lack thereof. 2. A skilled programmer could build an implementation that compiled Python code into Common Lisp or Scheme code, and then used a high-performance Common Lisp compiler such as SBCL, or a high-performance Scheme compiler such as Chez Scheme, to produce quite fast code; Python's object model is such that this can be accomplished (and not using CLOS); a Smalltalk-80-style method cache can be used to get good method dispatch. This whole approach would be a bad idea, because the compile times would be dreadful, but I use this example as an existence proof that Python implementations can generate reasonably efficient executable programs. In the Lisp world, optional declarations and flow analysis are used to tell the compiler the types of various variables. Python 3's annotations could be used for this purpose as well. This doesn't impact the learner (or even the casual programmer) for who efficiency is not that important. Unladen Swallow's JIT approach is, IMHO, better than this; my point here is that we don't know what the speed limits of Python implementations might be, and therefore, again, we don't know the limits of performance scalability. 3. It is certainly true that CPython doesn't scale up to environments where there are a significant number of processors with shared memory. It is also true that similar languages for highly parallel architectures have been produced (Connection Machine Lisp comes to mind). Whether the current work being done on the GIL will resolve this I don't know. Still, even if CPython had to be thrown away completely (something I don't believe is necessary), a high-performance multiprocessor/shared memory implementation could be built, if resources were available. 4. As to the programming language Python, I've never seen any evidence one way or the other that Python is more or less scalable to large problems than Java. My former employers build huge programs in C++, and there's lots of evidence (most of which I'm NDA'd from repeating) that it's possible to build huge programs in C++, but that they will be horrible :) -- v From no.email at please.post Wed Nov 11 19:53:22 2009 From: no.email at please.post (kj) Date: Thu, 12 Nov 2009 00:53:22 +0000 (UTC) Subject: Python & Go Message-ID: I'm just learning about Google's latest: the GO (Go?) language. (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). There are some distinctly Pythonoid features to the syntax, such as "import this_or_that", the absence of parentheses at the top of flow control constructs, and quite a few statements without a trailing semicolon. Then again, there's a lot that looks distinctly un-Pythonlike, such as the curly brackets all over the place. And among the un-Pythonlike stuff there's a lot that looks like nothing else that I've ever seen... Just out of curiosity, how much did GvR contribute to this effort? Cheers, G. P.S. Keeping up with Google is becoming a full-time job. It's friggin non-stop. Who can handle it? Truly incredible. From bbxx789_05ss at yahoo.com Wed Nov 11 19:59:51 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 16:59:51 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: <1e499750-0e4f-496c-b7ff-d7bd8014f989@o10g2000yqa.googlegroups.com> On Nov 11, 1:37 pm, Terry Reedy wrote: > 7stud wrote: > > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: > >> And third, > >> there are limits to what extend one can anticipate the ineptness of > > Calling you inept was unnecessary, but.... > > >> others to read. The page you cite from starts with: > > You wrote > " > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: > > http://codespeak.net/lxml/installation.html > " > > >> For special installation instructions regarding MS Windows and > >> MacOS-X, see below. > > and that page indeed begins with the words above. > > >> And below you find this link: > > >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x > > >> Which contains the proper command > > >> STATIC_DEPS=true sudo easy_install lxml > > And this is also true. > Is it? First, that in fact was not the proper command. I posted the actual command I had to issue in my previous post: $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/ Versions/ 2.6/bin/easy_install lxml Shall I continue? Here is what the top of the web page that contains the installation instructions looks like (with my comments inserted in the text): ===== For special installation instructions regarding MS Windows and MacOS- X, see below. <<<****Ok, now I'm scrolling down looking for the *installation instructions*.>>> 1 Requirements 2 Installation 3 Installation in ActivePython 4 Building lxml from sources 5 MS Windows 6 MacOS-X Requirements You need Python 2.3 or later. Unless you are using a static binary distribution (e.g. a Windows binary egg from PyPI), you need to install libxml2 and libxslt, in particular: libxml 2.6.21 or later. It can be found here: http://xmlsoft.org/downloads.html If you want to use XPath, do not use libxml2 2.6.27. We recommend libxml2 2.7.2 or later. libxslt 1.1.15 or later. It can be found here: http://xmlsoft.org/XSLT/downloads.html Newer versions generally contain less bugs and are therefore recommended. XML Schema support is also still worked on in libxml2, so newer versions will give you better complience with the W3C spec. <<<***Ok, I better read the requirements. Uhg, those dependencies look ugly. Things are looking doubtful at this point. Back to looking for those special installation instructions for mac os x...>>> Installation Get the easy_install tool and run the following as super-user (or administrator): easy_install lxml On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to easy_install like this: easy_install lxml==2.2.2 On Linux (and most other well-behaved operating systems), easy_install will manage to build the source distribution as long as libxml2 and libxslt are properly installed, including development packages, i.e. header files, etc. Use your package management tool to look for packages like libxml2-dev or libxslt-devel if the build fails, and make sure they are installed. On MacOS-X, use the following to build the source distribution, and make sure you have a working Internet connection, as this will download libxml2 and libxslt in order to build them: STATIC_DEPS=true easy_install lxml <<<***Ah, hah. There are the special installation instructions for mac os x. I'm ready to go. Uh oh, what the heck is the easy_install tool? Oh, that's a link hiding behind the bolded text(hmm...this website has some usability issues). Time goes by, tetonic plates shift...Ok, I've got the easy_install tool installed. Let's install lxml now.>> > > Your characterization of that web page is so fraudulent that I can > > only say one thing in response: You are a damn liar. > > So this makes no sense. > If someone were viewing the web page containing the installation instructions with a screen that was 2 feet high, AND they happened to see the additional section buried at the bottom of the page, AND they chose to skip over instructions in the installation section for some reason, the first part of the section at the bottom of the page reads: === MacOS-X A macport of lxml is available. Try port install py25-lxml. If you want to use a more recent lxml release, you may have to build it yourself. Apple doesn't help here, as the system libraries of libxml2 and libxslt installed under MacOS-X are horribly outdated, and ***updating them is everything but easy***. In any case, you cannot run lxml 2.x with the system provided libraries, so you have to use newer libraries... === ...which would probably make their eyes roll back in their head, or dissuade them from reading any further, and therefore they would return to the relevant installation instructions. I, in fact, was not viewing the web page with a screen that was two feet high, therefore that section wasn't even visible when I was looking at the special installation instructions for mac osx. > If, when you have calmed down a bit, you have > suggestions for improving the installation instructions, that might be > more constructive. The lxml developers have obviously gone to some > effort to give comprehensible instructions. Writing such is not easy. So > if they have failed in your case, feedback might be considered. > That harks back to an earlier point that was made: Benjamin Kaplan wrote: > 1) It's not Python's fault that OS X doesn't add things to the path > when its in a framework (like Python). > 1) Maybe the installation instructions for mac osx should read: ==== Installation Instructions .... .... MAC OS X: We're not sure how mac osx works with easy_install. Apple's system installations of libxml and libxslt are pretty bad--and they are difficult to upgrade. As a result, the following instructions may or may not work for you... ==== 2) Stop proclaiming that lxml is cross platform and/or stop recommending easy_install. 3) Don't split up relevant installation instructions over two web pages and then bury the link connecting the two web pages at the bottom of one of the pages. In any case, thanks for all the help. I'll stick to BeautifulSoup. From aahz at pythoncraft.com Wed Nov 11 20:03:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 17:03:23 -0800 Subject: Aborting a read with pySerial References: <4af50316$0$1610$742ec2ed@news.sonic.net> Message-ID: In article <4af50316$0$1610$742ec2ed at news.sonic.net>, John Nagle wrote: > >I'm using pySerial to read from a serial port. One thread reads from >the port, with no timeout. Another thread handles output and other >tasks. This works fine until I want to shut down the program. I can't >reliably break the program out of the read when it's waiting. On >Windows, closing the serial port will abort the read, but that seems to >have no effect on Linux. > >I know, I could put a timeout on the read and handle all those null >returns. Is there a better way? No -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From bbxx789_05ss at yahoo.com Wed Nov 11 20:16:41 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 17:16:41 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> <1e499750-0e4f-496c-b7ff-d7bd8014f989@o10g2000yqa.googlegroups.com> Message-ID: On Nov 11, 5:59?pm, 7stud wrote: > > 1) Maybe the installation instructions for mac osx should read: > > ==== > Installation Instructions > .... > .... > MAC OS X: > We're not sure how mac osx works with easy_install. ?Apple's system > installations of libxml and libxslt are pretty bad--and they are > difficult to upgrade. ?As a result, the following instructions may or > may not work for you... > ==== > > 2) Stop proclaiming that lxml is cross platform and/or stop > recommending easy_install. > > 3) Don't split up relevant installation instructions over two web > pages and then bury the link connecting the two web pages at the > bottom of one of the pages. > ...and most importantly: 4) The path to easy_install may not get added to your PATH environment variable, so using the full path to easy_install might be necessary when issuing the easy_install command. If you get an error that says: easy_install: command not found then you will need to use the full path to easy_install. Some installs will put easy_install here: /Library/Frameworks/Python.framework/ Versions/2.6/bin/easy_install Others will put it here: .... If can't locate easy_install in any of those directories, you can locate easy_install using the find command: find / -name easy_install From henryzhang62 at yahoo.com Wed Nov 11 20:24:37 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 11 Nov 2009 17:24:37 -0800 (PST) Subject: python with echo Message-ID: <369236.94583.qm@web57902.mail.re3.yahoo.com> List, I have a question of python using echo. POWER = 14 return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') can assign 14 to tx_power But return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') return_value is 256 not 0. It cannot assign 14 to tx_power. What problem is it? os.system("echo $POWER") returns 0 but os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. Appreciate any help! Thanks. ---henry From jeremiahsavage at gmail.com Wed Nov 11 20:41:07 2009 From: jeremiahsavage at gmail.com (Jeremiah) Date: Wed, 11 Nov 2009 17:41:07 -0800 (PST) Subject: python parser overridden by pymol Message-ID: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Hello, I'm fairly new to python (version 2.5.4), and am writing a program which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from debian. It appears that when I add pymol to $PYTHONPATH, that parser.expr() is no longer available, and so I am unable to use numpy.load(). I have looked for where parser.expr() is defined in the python system so I could place that directory first in $PYTHONPATH, but I have not been able to find the file that defines expr(). My reason for using numpy.load() is that I have a numpy array which takes an hour to generate. Therefore, I'd like to use numpy.save() so I could generate the array one time, and then load it later as needed with numpy.load(). I've successfully tested the use of numpy.save() and numpy.load() with a small example when the pymol path is not defined in $PYTHONPATH : >>> import numpy >>> numpy.save('123',numpy.array([1,2,3])) >>> numpy.load('123.npy') array([1, 2, 3]) However, a problem arises once $PYTHONPATH includes the pymol directory. To use the pymol api, I add the following to ~/.bashrc: PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol export PYMOL_PATH PYTHONPATH=$PYMOL_PATH export PYTHONPATH Once this is done, numpy.load() no longer works correctly, as pymol contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ parser.py ), which apparently prevents python from using its native parser. >>> numpy.load('123.npy') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line 195, in load return format.read_array(fid) File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", line 353, in read_array shape, fortran_order, dtype = read_array_header_1_0(fp) File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", line 250, in read_array_header_1_0 d = safe_eval(header) File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line 840, in safe_eval ast = compiler.parse(source, "eval") File "/usr/lib/python2.5/compiler/transformer.py", line 54, in parse return Transformer().parseexpr(buf) File "/usr/lib/python2.5/compiler/transformer.py", line 133, in parseexpr return self.transform(parser.expr(text)) AttributeError: 'module' object has no attribute 'expr' If I understand the problem correctly, can anyone tell me where python.expr() is defined, or suggest a better method to fix this problem? Thanks, Jeremiah From mensanator at aol.com Wed Nov 11 21:00:07 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 18:00:07 -0800 (PST) Subject: Python & Go References: Message-ID: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> On Nov 11, 6:53?pm, kj wrote: > I'm just learning about Google's latest: the GO (Go?) language. > (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", There's more to Python than import statements. In fact, this Go language is nothing like Python. > the absence of parentheses at the top of > flow control constructs, Huh? > and quite a few statements without a > trailing semicolon. ? Those are exceptions, the rule appears to be "ends with semicolon". In this example, I see semicolons all over the place. 05 package main 07 import ( 08 "./file"; 09 "fmt"; 10 "os"; 11 ) 13 func main() { 14 hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'}; 15 file.Stdout.Write(hello); 16 file, err := file.Open("/does/not/exist", 0, 0); 17 if file == nil { 18 fmt.Printf("can't open file; err=%s\n", err.String()); 19 os.Exit(1); 20 } 21 } > Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. ? Duh. > And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... Go look at a C++ program sometime. > > Just out of curiosity, how much did GvR contribute to this effort? I hope none that he would admit to. > > Cheers, > > G. > > P.S. Keeping up with Google is becoming a full-time job. ?It's > friggin non-stop. ?Who can handle it? ?Truly incredible. From ethan at stoneleaf.us Wed Nov 11 21:15:22 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Nov 2009 18:15:22 -0800 Subject: using inspect Message-ID: <4AFB6FBA.3080908@stoneleaf.us> Greetings! How wise is it to base code on inspect? Specifically on things like live frames on the stack and whatnot. It occurs to me that this is leaning towards implementation details, and away from pure, pristine Python. As an example, I have this routine in a module I'm working on: def _get_module(): "get the calling module -- should be the config'ed module" target = os.path.splitext(inspect.stack()[2][1])[0] target = __import__(target) return target How brittle is this technique? ~Ethan~ From himanshu.garg at gmail.com Wed Nov 11 21:30:57 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 08:00:57 +0530 Subject: python with echo In-Reply-To: <369236.94583.qm@web57902.mail.re3.yahoo.com> References: <369236.94583.qm@web57902.mail.re3.yahoo.com> Message-ID: <6f82a7270911111830y732cfd39i97d1d993c182525@mail.gmail.com> 2009/11/12 hong zhang : > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. > > What problem is it? > > os.system("echo $POWER") returns 0 but > os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. > Sorry cannot try it myself to confirm. Could it be that $POWER is not set. Does it write to a regular file. Thank You, ++imanshu From python at mrabarnett.plus.com Wed Nov 11 21:49:54 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 02:49:54 +0000 Subject: python with echo In-Reply-To: <369236.94583.qm@web57902.mail.re3.yahoo.com> References: <369236.94583.qm@web57902.mail.re3.yahoo.com> Message-ID: <4AFB77D2.1000502@mrabarnett.plus.com> hong zhang wrote: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. > > What problem is it? > > os.system("echo $POWER") returns 0 but > os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. > Did you think that you could say: POWER = 14 return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') in a Python script and that would do the same as: return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') That won't work because 'POWER' exists only in Python and 'echo' is being run in the (Linux?) shell. You could try creating the command-line and then passing it to 'system': return_value = os.system('echo %s > /sys/class/net/wlan1/device/tx_power' % POWER) From pavlovevidence at gmail.com Wed Nov 11 22:04:36 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 19:04:36 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 11, 4:12?pm, Steven D'Aprano wrote: > On Wed, 11 Nov 2009 03:52:45 -0800, Carl Banks wrote: > >> This is where a helper function is good. You want a dispatcher: > > > No I really don't. ?I want to be able to see the action performed > > adjacent to the test, and not have to scroll up to down ten pages to > > find whatever function it dispatched to. > > Then re-write the dispatcher to return a tuple (match_object, > method_to_call) and then call them there at the spot. Well I don't just want to call a method, so I can't take that advice. Some actions will do more than just to call a method. And I don't want to scroll up or down ten screens to see what the actions associated with the regexp are. A dispatcher is out. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 22:07:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 03:07:12 GMT Subject: python with echo References: Message-ID: On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > > /sys/class/net/wlan1/device/tx_power') POWER = 14 doesn't create an environment variable visible to echo. It is a Python variable. >>> POWER = 14 >>> import os >>> return_value = os.system('echo $POWER') >>> return_value 0 > return_value is 256 not 0. It cannot assign 14 to tx_power. I don't understand that. Exit status codes on all systems I'm familiar with are limited to 0 through 255. What operating system are you using? Assuming your system allows two-byte exit statuses, you should check the documentation for echo and the shell to see why it is returning 256. Have you tried this in the shell, without involving Python? I will almost guarantee that Python is irrelevant to the problem. -- Steven From robert.kern at gmail.com Wed Nov 11 22:12:42 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Nov 2009 21:12:42 -0600 Subject: python parser overridden by pymol In-Reply-To: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: Jeremiah wrote: > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH Don't change your PYTHONPATH like that. You want to put /usr/lib/pymodules/python2.5 onto your PYTHONPATH and import PyMOL's stuff from the pymol package. I.e., instead of import api Do from pymol import api pymol is a package for precisely this reason. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 22:16:32 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 03:16:32 GMT Subject: python parser overridden by pymol References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 17:41:07 -0800, Jeremiah wrote: > Hello, > > I'm fairly new to python (version 2.5.4), and am writing a program which > uses both pymol (version 1.2r1) and numpy (version 1.3.0) from debian. > > It appears that when I add pymol to $PYTHONPATH, that parser.expr() is > no longer available, and so I am unable to use numpy.load(). I have > looked for where parser.expr() is defined in the python system so I > could place that directory first in $PYTHONPATH, but I have not been > able to find the file that defines expr(). >>> import parser >>> parser.__file__ '/usr/lib/python2.5/lib-dynload/parsermodule.so' >>> parser.expr [...] > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH Change that to PYMOL_PATH=/usr/lib/pymodules/python2.5 and it should work, assuming pymol uses a package, as it should. If it doesn't, if it's just a hodge-podge of loose modules in a directory, then they should be slapped with a wet fish for shadowing a standard library module. -- Steven From davea at ieee.org Wed Nov 11 22:48:34 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 11 Nov 2009 22:48:34 -0500 Subject: python parser overridden by pymol In-Reply-To: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: <4AFB8592.7040300@ieee.org> Jeremiah wrote: > Hello, > > I'm fairly new to python (version 2.5.4), and am writing a program > which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from > debian. > > It appears that when I add pymol to $PYTHONPATH, that parser.expr() is > no longer available, and so I am unable to use numpy.load(). I have > looked for where parser.expr() is defined in the python system so I > could place that directory first in $PYTHONPATH, but I have not been > able to find the file that defines expr(). > > My reason for using numpy.load() is that I have a numpy array which > takes an hour to generate. Therefore, I'd like to use numpy.save() so > I could generate the array one time, and then load it later as needed > with numpy.load(). > > I've successfully tested the use of numpy.save() and numpy.load() with > a small example when the pymol path is not defined in $PYTHONPATH : > > >>> import numpy > >>> numpy.save('123',numpy.array([1,2,3])) > >>> numpy.load('123.npy') > array([1, 2, 3]) > > > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH > > Once this is done, numpy.load() no longer works correctly, as pymol > contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ > parser.py ), which apparently prevents python from using its native > parser. > > >>> numpy.load('123.npy') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line > 195, in load > return format.read_array(fid) > File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", > line 353, in read_array > shape, fortran_order, dtype = read_array_header_1_0(fp) > File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", > line 250, in read_array_header_1_0 > d = safe_eval(header) > File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line > 840, in safe_eval > ast = compiler.parse(source, "eval") > File "/usr/lib/python2.5/compiler/transformer.py", line 54, in > parse > return Transformer().parseexpr(buf) > File "/usr/lib/python2.5/compiler/transformer.py", line 133, in > parseexpr > return self.transform(parser.expr(text)) > AttributeError: 'module' object has no attribute 'expr' > > If I understand the problem correctly, can anyone tell me where > python.expr() is defined, or suggest a better method to fix this > problem? > > Thanks, > Jeremiah > > Generic answers, I have no experience with pymol If pymol really needs that parser.py, you have a problem, as there can only be one module by that name in the application. But assuming it's needed for some obscure feature that you don't need, you could try the following sequence. 1) temporarily rename the pymol's parser.py file to something else, like pymolparser.py, and see what runs. 2) rather than changing the PYTHONPATH, fix up sys.path during your script initialization. In particular, do an import parser near the beginning of the script. This gets it loaded, even though you might not need to use it from this module. After that import, then add the following line (which could be generalized later) sys.path.append( "/usr/lib/pymodules/python2.5/pymol") If this works, then you can experiment a bit more, perhaps you don't need the extra import parser, just putting the pymol directory at the end of the sys.path rather than the beginning may be good enough. If the parser.py in the pymol is actually needed, you might need to rename its internal references to some other name, like pymolparser. HTH, DaveA From debatem1 at gmail.com Wed Nov 11 22:56:26 2009 From: debatem1 at gmail.com (geremy condra) Date: Wed, 11 Nov 2009 22:56:26 -0500 Subject: Python & Go In-Reply-To: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > On Nov 11, 6:53?pm, kj wrote: >> I'm just learning about Google's latest: the GO (Go?) language. >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). >> There are some distinctly Pythonoid features to the syntax, such >> as "import this_or_that", > > There's more to Python than import statements. > In fact, this Go language is nothing like Python. Actually, numerous analogies have been drawn between the two both by whoever wrote the docs and the tech media, including slashdot and techcrunch. >> the absence of parentheses at the top of >> flow control constructs, > > Huh? The OP is referring to the fact that for and if do not have mandatory parenthesis. >> and quite a few statements without a >> trailing semicolon. > > Those are exceptions, the rule appears to be "ends with semicolon". > In this example, I see semicolons all over the place. The rule is that if its between parens, it needs semicolons. >> Then again, there's a lot that looks distinctly >> un-Pythonlike, such as the curly brackets all over the place. > > Duh. > >> And >> among the un-Pythonlike stuff there's a lot that looks like nothing >> else that I've ever seen... > > Go look at a C++ program sometime. Go doesn't support inheritance, so C++ is pretty much out. C is a lot closer, but still not all that close. Geremy Condra From timr at probo.com Wed Nov 11 23:35:36 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Nov 2009 20:35:36 -0800 Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: Ognjen Bezanov wrote: > >I'm trying to see if there is any way I can make Python share data >between two hosts using DMA transfers over a firewire connection, so >avoiding the need for another layer on top such as IPv4 + Python sockets. > >Thanks to some old python bindings which I updated to python 2.6, I can >read any write to the RAM of any firewire connected host within python. >Because it uses DMA (the cpu is not involved in this at all), I can only >specify a physical address within the 4GB ram limit to read from and >write to. >... > From what I've been told so far, it's not possible to do this without >some OS-specific (Linux in this case) syscall. Is this correct? Correct. User-mode programs cannot find physical addresess, and they cannot lock pages into memory (which is required for DMA). You need the assistance of a driver for this. The driver will find the physical addresses. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pavlovevidence at gmail.com Wed Nov 11 23:42:53 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 20:42:53 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> On Nov 11, 7:56?pm, geremy condra wrote: > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > On Nov 11, 6:53?pm, kj wrote: > >> I'm just learning about Google's latest: the GO (Go?) language. > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> There are some distinctly Pythonoid features to the syntax, such > >> as "import this_or_that", > > > There's more to Python than import statements. > > In fact, this Go language is nothing like Python. > > Actually, numerous analogies have been drawn between the two > both by whoever wrote the docs and the tech media, including > slashdot and techcrunch. Superficially it looks quite hideous, at least this sample does, but underneath the covers might be another question. Javascript looks like Java but behaves more like Python. Such might also be the case for Go. I'll reserve judgment till I've looked at it, but it's advertised as natively supporting something I've always wanted in a static language: signatures (and, presumably, a culture to support them). [snip] > > Go look at a C++ program sometime. > > Go doesn't support inheritance, so C++ is pretty much out. C > is a lot closer, but still not all that close. Well, it's hard to argue with not being like C++, but the lack of inheritance is a doozie. Carl Banks From pengyu.ut at gmail.com Wed Nov 11 23:46:34 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 11 Nov 2009 22:46:34 -0600 Subject: Why Error is derived from EnvironmentError in shutil.py? Message-ID: <366c6f340911112046q2e9737d7tec36cfff42e79e5a@mail.gmail.com> I see Error is derived from EnvironmentError in shutil.py. class Error(EnvironmentError): pass I'm wondering why EnvironmentError can not be raised directly. Why Error is raised instead? From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 23:51:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 04:51:17 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Wed, 11 Nov 2009 16:38:50 -0800, Vincent Manis wrote: > I'm having some trouble understanding this thread. My comments aren't > directed at Terry's or Alain's comments, but at the thread overall. > > 1. The statement `Python is slow' doesn't make any sense to me. Python > is a programming language; it is implementations that have speed or lack > thereof. Of course you are right, but in common usage, "Python" refers to CPython, and in fact since all the common (and possibly uncommon) implementations of Python are as slow or slower than CPython, it's not an unreasonable short-hand. But of course "slow" is relative. And many applications are bound by I/O time, not CPU time. > 2. A skilled programmer could build an implementation that compiled > Python code into Common Lisp or Scheme code, and then used a > high-performance Common Lisp compiler such as SBCL, or a > high-performance Scheme compiler such as Chez Scheme, to produce quite > fast code; Unless you can demonstrate this, it's all theoretical. And probably not as straight-forward as you think: http://codespeak.net/pypy/dist/pypy/doc/faq.html#id29 > Python's object model is such that this can be accomplished > (and not using CLOS); a Smalltalk-80-style method cache can be used to > get good method dispatch. This whole approach would be a bad idea, > because the compile times would be dreadful, but I use this example as > an existence proof that Python implementations can generate reasonably > efficient executable programs. I think a better existence proof is implementations that *actually* exist, not theoretical ones. There's good work happening with Psycho and PyPy, and you can write C extensions using almost-Python code with Cython and Pyrex. There's very little reason why Python *applications* have to be slow, unless the application itself is inherently slow. > In the Lisp world, optional declarations and flow analysis are used to > tell the compiler the types of various variables. Python 3's annotations > could be used for this purpose as well. This doesn't impact the learner > (or even the casual programmer) for who efficiency is not that > important. > > Unladen Swallow's JIT approach is, IMHO, better than this; my point here > is that we don't know what the speed limits of Python implementations > might be, and therefore, again, we don't know the limits of performance > scalability. Absolutely. It's early days for Python. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 23:55:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 04:55:50 GMT Subject: Why Error is derived from EnvironmentError in shutil.py? References: Message-ID: On Wed, 11 Nov 2009 22:46:34 -0600, Peng Yu wrote: > I see Error is derived from EnvironmentError in shutil.py. > > class Error(EnvironmentError): > pass > > I'm wondering why EnvironmentError can not be raised directly. Why Error > is raised instead? Probably to do with the personal taste of the author. http://docs.python.org/library/shutil.html#shutil.Error -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Nov 12 00:05:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 05:05:57 GMT Subject: using inspect References: Message-ID: On Wed, 11 Nov 2009 18:15:22 -0800, Ethan Furman wrote: > Greetings! > > How wise is it to base code on inspect? Specifically on things like > live frames on the stack and whatnot. It occurs to me that this is > leaning towards implementation details, and away from pure, pristine > Python. > > As an example, I have this routine in a module I'm working on: > > def _get_module(): > "get the calling module -- should be the config'ed module" target = > os.path.splitext(inspect.stack()[2][1])[0] > target = __import__(target) > return target > > How brittle is this technique? Download and install PyPy, CLPython, IronPython and Jython and see how many it breaks on :) I think it's a brittle technique because it is creating a dependency where there shouldn't be one. What happens if somebody runs your module directly? It might not need to do anything sensible, but it shouldn't fail merely because there's no calling module. But I don't think it's inherently dangerous. It's a bit hacky, well, probably a lot hacky, but it doesn't seem to use anything specifically documented as implementation specific: http://docs.python.org/library/inspect.html#inspect.stack -- Steven From rt8396 at gmail.com Thu Nov 12 00:07:12 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 21:07:12 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: <31772cad-c255-4c2e-88af-f5cfc59c0386@g31g2000vbr.googlegroups.com> On Nov 11, 9:04 pm, Carl Banks wrote: (Carl's reply to Steven's comments...) > Well I don't just want to call a method, so I can't take that advice. > Some actions will do more than just to call a method. And I don't > want to scroll up or down ten screens to see what the actions > associated with the regexp are. A dispatcher is out. +1 The if... elif... construct that Carl provided coupled with the proposed new syntax is much cleaner. And i'm not just saying that because Steven called my idea stupid, well, *maybe* not? ;-) PS: Does anyone know the textual smiley for apathy? From mensanator at aol.com Thu Nov 12 00:27:31 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 21:27:31 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> On Nov 11, 9:56?pm, geremy condra wrote: > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > On Nov 11, 6:53?pm, kj wrote: > >> I'm just learning about Google's latest: the GO (Go?) language. > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> There are some distinctly Pythonoid features to the syntax, such > >> as "import this_or_that", > > > There's more to Python than import statements. > > In fact, this Go language is nothing like Python. > > Actually, numerous analogies have been drawn between the two > both by whoever wrote the docs and the tech media, including > slashdot and techcrunch. > > >> the absence of parentheses at the top of > >> flow control constructs, > > > Huh? > > The OP is referring to the fact that for and if do not have > mandatory parenthesis. > > >> and quite a few statements without a > >> trailing semicolon. > > > Those are exceptions, the rule appears to be "ends with semicolon". > > In this example, I see semicolons all over the place. > > The rule is that if its between parens, it needs semicolons. > > Why did you snip the example that proves you're wrong? > > >> Then again, there's a lot that looks distinctly > >> un-Pythonlike, such as the curly brackets all over the place. > > > Duh. > > >> And > >> among the un-Pythonlike stuff there's a lot that looks like nothing > >> else that I've ever seen... > > > Go look at a C++ program sometime. > > Go doesn't support inheritance, so C++ is pretty much out. C > is a lot closer, but still not all that close. > > Geremy Condra From wuwei23 at gmail.com Thu Nov 12 01:00:48 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 Nov 2009 22:00:48 -0800 (PST) Subject: Why Error is derived from EnvironmentError in shutil.py? References: Message-ID: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> On Nov 12, 2:46?pm, Peng Yu wrote: > I see Error is derived from EnvironmentError in shutil.py. > > class Error(EnvironmentError): > ? ? pass > > I'm wondering why EnvironmentError can not be raised directly. Why > Error is raised instead? This way you can explicitly trap on shutil.Error and not intercept any other EnvironmentError that might be raised. And as it's a descendent of EnvironmentError, it can still be caught by any handlers looking for such exceptions. From alfps at start.no Thu Nov 12 01:21:01 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 07:21:01 +0100 Subject: Does turtle graphics have the wrong associations? Message-ID: One reaction to has been that turtle graphics may be off-putting to some readers because it is associated with children's learning. What do you think? Cheers, - Alf From debatem1 at gmail.com Thu Nov 12 01:44:23 2009 From: debatem1 at gmail.com (geremy condra) Date: Thu, 12 Nov 2009 01:44:23 -0500 Subject: Python & Go In-Reply-To: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 12:27 AM, Mensanator wrote: > On Nov 11, 9:56?pm, geremy condra wrote: >> On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: >> > On Nov 11, 6:53?pm, kj wrote: >> >> I'm just learning about Google's latest: the GO (Go?) language. >> >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). >> >> There are some distinctly Pythonoid features to the syntax, such >> >> as "import this_or_that", >> >> > There's more to Python than import statements. >> > In fact, this Go language is nothing like Python. >> >> Actually, numerous analogies have been drawn between the two >> both by whoever wrote the docs and the tech media, including >> slashdot and techcrunch. >> >> >> the absence of parentheses at the top of >> >> flow control constructs, >> >> > Huh? >> >> The OP is referring to the fact that for and if do not have >> mandatory parenthesis. >> >> >> and quite a few statements without a >> >> trailing semicolon. >> >> > Those are exceptions, the rule appears to be "ends with semicolon". >> > In this example, I see semicolons all over the place. >> >> The rule is that if its between parens, it needs semicolons. >> >> > > Why did you snip the example that proves you're wrong? For the very simple reason that I'm not. From the roughly 20 minute tutorial: "Semicolons aren't needed here; in fact, semicolons are unnecessary after any top-level declaration, although they are needed as separators within a parenthesized list of declarations." In fact, you can clearly see this in action even in the example you posted- there is no semicolon after the import, nor is one required after any initialization or where line endings are unambiguous, such as immediately preceding the end of a block. Geremy Condra From vmanis at telus.net Thu Nov 12 01:53:37 2009 From: vmanis at telus.net (Vincent Manis) Date: Wed, 11 Nov 2009 22:53:37 -0800 Subject: Python & Go In-Reply-To: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: <5E7279DF-62BC-4DF3-A277-0FE330D16A73@telus.net> On 2009-11-11, at 21:27, Mensanator wrote: >> Go doesn't support inheritance, so C++ is pretty much out. C >> is a lot closer, but still not all that close. OK, if that's the case (I haven't read the Go documents), then Go is nothing like Python, no matter how many or few semicolons there are in Go programs, or whether one imports external code modules with `import', `require', or `iwant'. Programming languages are similar if their *semantics* are similar, not if their *syntaxes* are similar. A device that apparently has brake and accelerator pedals is similar to a car if the functions of these two pedals match those of a car, and is different from a car if the `brake' causes bread to be inserted into a toaster and the `accelerator' drops a 16ton weight on the driver. -- v From mensanator at aol.com Thu Nov 12 02:01:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 23:01:59 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: <1c248687-ec58-41db-ad4f-c2028ed428c3@c3g2000yqd.googlegroups.com> On Nov 12, 12:44?am, geremy condra wrote: > On Thu, Nov 12, 2009 at 12:27 AM, Mensanator wrote: > > On Nov 11, 9:56?pm, geremy condra wrote: > >> On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > >> > On Nov 11, 6:53?pm, kj wrote: > >> >> I'm just learning about Google's latest: the GO (Go?) language. > >> >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> >> There are some distinctly Pythonoid features to the syntax, such > >> >> as "import this_or_that", > > >> > There's more to Python than import statements. > >> > In fact, this Go language is nothing like Python. > > >> Actually, numerous analogies have been drawn between the two > >> both by whoever wrote the docs and the tech media, including > >> slashdot and techcrunch. > > >> >> the absence of parentheses at the top of > >> >> flow control constructs, > > >> > Huh? > > >> The OP is referring to the fact that for and if do not have > >> mandatory parenthesis. > > >> >> and quite a few statements without a > >> >> trailing semicolon. > > >> > Those are exceptions, the rule appears to be "ends with semicolon". > >> > In this example, I see semicolons all over the place. > > >> The rule is that if its between parens, it needs semicolons. > > >> > > > Why did you snip the example that proves you're wrong? > > For the very simple reason that I'm not. From the roughly > 20 minute tutorial: > > "Semicolons aren't needed here; in fact, semicolons are unnecessary > after any top-level declaration, although they are needed as > separators within a parenthesized list of declarations." > > In fact, you can clearly see this in action even in the example > you posted- there is no semicolon after the import, nor is one > required after any initialization or where line endings are > unambiguous, So, where line endings ARE ambiguous requires semicolons. The above statement may be true for top-level statements, but not within blocks, as the example clearly shows. The lines were NOT within parens, yet had trailing semicolons. You're still wrong. > such as immediately preceding the end of a > block. > > Geremy Condra From ak at nothere.com Thu Nov 12 02:24:23 2009 From: ak at nothere.com (AK) Date: Thu, 12 Nov 2009 02:24:23 -0500 Subject: Create video with text? Message-ID: <4afbb851$0$22531$607ed4bc@cv.net> Hi, what would be the best python package (or a framework that can be scripted in python) that can make a video with text moving around, jumping, zooming in/out and various other text effects? See the following link for an example: From anacrolix at gmail.com Thu Nov 12 02:51:54 2009 From: anacrolix at gmail.com (Matthew Joiner) Date: Wed, 11 Nov 2009 23:51:54 -0800 (PST) Subject: Matthew Joiner wants to stay in touch on LinkedIn Message-ID: <284081918.7836296.1258012314856.JavaMail.app@ech3-cdn13.prod> LinkedIn ------------ Matthew Joiner requested to add you as a connection on LinkedIn: ------------------------------------------ Jaime, I'd like to add you to my professional network on LinkedIn. - Matthew Joiner Accept invitation from Matthew Joiner http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I420651809_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvej0UcjkSc38QiiZ9jj19qBdVkOYVdPgUd3wSdjwLrCBxbOYWrSlI/EML_comm_afe/ View invitation from Matthew Joiner http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I420651809_3/0PnPAMe34Rdz0Od4ALqnpPbOYWrSlI/svi/ ------------------------------------------ Why might connecting with Matthew Joiner be a good idea? Matthew Joiner's connections could be useful to you: After accepting Matthew Joiner's invitation, check Matthew Joiner's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. ------ (c) 2009, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Thu Nov 12 02:53:57 2009 From: dieter at handshake.de (Dieter Maurer) Date: 12 Nov 2009 08:53:57 +0100 Subject: advice needed for lazy evaluation mechanism In-Reply-To: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> References: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes on 10 Nov 2009 19:11:07 GMT: > ... > > So I am trying to restructure it using lazy evaluation. > > Oh great, avoiding confusion with something even more confusing. Lazy evaluation may be confusing if it is misused. But, it may be very clear and powerful if used appropriately. Lazy evaluation essentially means: you describe beforehand how a computation should be performed but do this computation only when its result is immediately required. Of course, this makes it more difficult to predict when the computation actually happens -- something potentially very confusing when the computation has side effects. If the computation is side effect free, potentially great gains can be achieved without loss of clarity. Python supports lazy evaluation e.g. by its genenerators (and generator expressions). Its "itertools" module provides examples to efficiently use iterators (and by inclusion generators) without sacrificing clarity. -- Dieter From michele.simionato at gmail.com Thu Nov 12 03:07:36 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 00:07:36 -0800 (PST) Subject: Python & Go References: Message-ID: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> Well, Go looks like Python in the philosophy (it is a minimalist, keep it simple language) more than in the syntax. The one thing that I really like is the absence of classes and the presence of interfaces (I have been advocating something like that for years). I am dubious about the absence of exceptions, though. If I can attempt a prediction, I would say that if the language will be adopted internally in Google it will make a difference; otherwise, it will be rapidly forgotten. From yinon.me at gmail.com Thu Nov 12 03:13:52 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Thu, 12 Nov 2009 00:13:52 -0800 (PST) Subject: How to specify Python version in script? References: Message-ID: <77b812a9-d82c-4aaa-8037-ec30366fc14f@h34g2000yqm.googlegroups.com> > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? sys.hexversion, see http://mail.python.org/pipermail/python-list/2009-June/185939.html -- Yinon From michele.simionato at gmail.com Thu Nov 12 03:18:55 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 00:18:55 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> Message-ID: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> I forgot to post a link to a nice analysis of Go: http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php From steven at REMOVE.THIS.cybersource.com.au Thu Nov 12 03:27:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 08:27:08 GMT Subject: advice needed for lazy evaluation mechanism References: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 08:53:57 +0100, Dieter Maurer wrote: > Steven D'Aprano writes on 10 Nov > 2009 19:11:07 GMT: >> ... >> > So I am trying to restructure it using lazy evaluation. >> >> Oh great, avoiding confusion with something even more confusing. > > Lazy evaluation may be confusing if it is misused. But, it may be very > clear and powerful if used appropriately. I was referring to the specific example given, not the general concept of lazy evaluation. I went on to give another example of simple, straightforward lazy evaluation: using properties for computed attributes. -- Steven From naughtysriram at gmail.com Thu Nov 12 03:31:57 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 00:31:57 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' Message-ID: I guess why every programming language has some kind of a 'standard library' built in within it. In my view it must not be called as a 'library' at all. what it does is like a 'bunch of built-in programs ready-made to do stuff'. Lets see what a 'library' does: 1. offers books for customers 1.1 lets user select a book by genre, etc 1.2 lets user to use different books of same genre, etc 1.3 lets user to use books by same author, etc for different genre 2. keeps track of all the books + their genre 2.1 first knows what all books it has at present 2.2 when new book comes it is added to the particular shelf sorted by genre,author,edition, etc. 2.3 when books become old they are kept separately for future reference 2.4 very old books can be sent to a museum/discarded I guess no standard library does the minimum of this but wants to be called a library. As a python user I always wanted the standard library to have such features so the user/developer decides to use what set of libraries he want. consider the libraries for 2.5 ,2.6, 3K are all available to the user, the user selects what he wants with something like. use library 2.5 or use library 2.6 etc. The 2 main things that the library management interface has to do is intra library management and inter library management. intra library mgmt- consider books to be different libraries (standard, commercial, private, hobby, etc) inter library mgmt- consider books to be modules inside a library ( standard, commercial, private, hobby, etc) if somehow we could accomplish this kind of mother of a all plugin/ad- hoc system that is a real breakthrough. Advantages: 1. new modules can be added to the stream quickly 2. let the user select what he want to do 3. modules (that interdepend on each other) can be packed into small distribution and added to the stream quickly without waiting for new releases 4. solution to problems like py 2.x and 3.x 5. users can be up to date 6. documentation becomes easy + elaborate to users 7. bug managing is easy too 8. more feed back 9. testing also becomes easy 10. many more , i don't know.. you have to find. Python already has some thing like that __future__ stuff. but my question is how many people know that? and how many use that? most of them wait until old crust gets totally removed. that is bad for user and python. that is why problems like py2.x py3.x originate. If there is a newer book collection it must always be available at the library. i must not go to another library to get that book. These are just my views on the state of the standard libraries and to make them state-of-the-art..! ;) From pavlovevidence at gmail.com Thu Nov 12 03:54:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 00:54:55 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: <569e15fe-6791-4f9e-9757-0e232a57e698@o9g2000prg.googlegroups.com> On Nov 11, 8:42?pm, Carl Banks wrote: > On Nov 11, 7:56?pm, geremy condra wrote: > > > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > > On Nov 11, 6:53?pm, kj wrote: > > >> I'm just learning about Google's latest: the GO (Go?) language. > > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > > >> There are some distinctly Pythonoid features to the syntax, such > > >> as "import this_or_that", > > > > There's more to Python than import statements. > > > In fact, this Go language is nothing like Python. > > > Actually, numerous analogies have been drawn between the two > > both by whoever wrote the docs and the tech media, including > > slashdot and techcrunch. > > Superficially it looks quite hideous, at least this sample does, but > underneath the covers might be another question. ?Javascript looks > like Java but behaves more like Python. ?Such might also be the case > for Go. ?I'll reserve judgment till I've looked at it, but it's > advertised as natively supporting something I've always wanted in a > static language: signatures (and, presumably, a culture to support > them). Ok, I've read up on the language and I've seen enough. I, for one, won't be using it. I don't think it has any possibility of gaining traction without serious changes. If Google decides to throw money at it and/or push it internally (and I am skeptical Google's software engineers would let themselved be browbeaten into using it) it'll be Lisp 2: Electric Boogaloo. Carl Banks From sraji.me at gmail.com Thu Nov 12 04:07:22 2009 From: sraji.me at gmail.com (Raji Seetharaman) Date: Thu, 12 Nov 2009 14:37:22 +0530 Subject: Error in Windmill Message-ID: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> Hi Im learning Web scraping with Python from here http://www.packtpub.com/article/web-scraping-with-python-part-2 >From the above link, the complete code is here http://pastebin.com/m10046dc6 When i run the program in the terminal i receive following errors File "nasa.py", line 41, in test_scrape_iotd_gallery() File "nasa.py", line 24, in test_scrape_iotd_gallery client = WindmillTestClient(__name__) File "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", line 142, in __init__ method_proxy = windmill.tools.make_jsonrpc_client() File "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", line 35, in make_jsonrpc_client url = urlparse(windmill.settings['TEST_URL']) AttributeError: 'module' object has no attribute 'settings' Suggest me Thanks Raji. S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Nov 12 04:23:54 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 10:23:54 +0100 Subject: Python C API and references Message-ID: Hello, Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't need the reference to py_val I should decrement the reference after this call? So for example: PyObject *py_val = PyInt_FromLong(5) PyObject_SetAttrString(py_obj, "val", py_val); Py_DECREF(py_val) Right? If so, take sysmodule.c: if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) return NULL; Shouldn't they also call Py_DECREF(Py_None) ? Same logic applies to PyDict_SetItemString() and the reference should be decrement after setting the item (ofcourse if the value is not needed). -- Elias From lallous at lgwm.org Thu Nov 12 04:28:32 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 10:28:32 +0100 Subject: C api and checking for integers Message-ID: Hello, I am a little confused on how to check if a python variable is an integer or not. Sometimes PyInt_Check() fails and PyLong_Check() succeeds. How to properly check for integer values? OTOH, I tried PyNumber_Check() and: (1) The doc says: Returns 1 if the object o provides numeric protocols, and false otherwise. This function always succeeds. What do they mean: "always succeeds" ? (2) It seems PyNumber_check(py_val) returns true when passed an instance! Please advise. -- Elias From duncan.booth at invalid.invalid Thu Nov 12 04:55:52 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Nov 2009 09:55:52 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> Message-ID: Michele Simionato wrote: > I forgot to post a link to a nice analysis of Go: > http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php > Thanks for that link. I think it pretty well agrees with my first impressions of Go: there are some nice bits but there are also some bits they really should be so embarassed that they even considered. The lack of any kind of error handling, whether exceptions or anything else is, I think, a killer. When you access a value out of a map you have a choice of syntax: one way gives you a boolean flag you can test to see whether or not the item was in the map, the other either gives you the value or crashes the program (yes, the documentation actually says 'crash'). Both of these are wrong: the flag is wrong because it forces you to handle every lookup error immediately and at the same place in the code; the crash is wrong for obvious reasons. The lack of inheritance is a bit weird, so far as I can tell you can have what is effectively a base class providing some concrete implementation but there are no virtual methods so no way to override anything. What that article didn't mention, and what is possibly Go's real strong point is that it has built-in support for parallel processing. Again though the implementation looks weak: any attempt to read from a channel is either non-blocking or blocks forever. I guess you can probably implement timeouts by using a select to read from multiple channels, but as with accessing values from a map it doesn't sound like it will scale well to producing robust applications. It has too many special cases: a lot of the builtin types can exist only as builtin types: if they weren't part of the language you couldn't implement an equivalent. e.g. A map has a key and value. The key can be any type which implements equality, but you can't implement equality tests for your own types so you cannot define additional key types. -- Duncan Booth http://kupuguy.blogspot.com From ankita.dutta09 at gmail.com Thu Nov 12 04:59:40 2009 From: ankita.dutta09 at gmail.com (ankita dutta) Date: Thu, 12 Nov 2009 15:29:40 +0530 Subject: query regarding file handling. Message-ID: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> hi all, i have a file of 3x3 matrix of decimal numbers(tab separated). like this : 0.02 0.38 0.01 0.04 0.32 0.00 0.03 0.40 0.02 now i want to read 1 row and get the sum of a particular row. but when i am trying with the following code, i am getting errors : *code*: " ln1=open("A.txt","r+") # file "A.txt" contains my matrix lines1=ln1.readlines() n_1=[ ] for p1 in range (0,len(lines1)): f1=lines1[p1] n_1.append((f1) ) print n_1 print sum(n_1[0]) " *output*: ['0.0200\t0.3877\t0.0011\n', '0.0040\t0.3292\t0.0001\n', '0.0355\t0.4098\t0.0028\n', '0.0035\t0.3063\t0.0001\n', '0.0080\t0.3397\t0.0002\n'] Traceback (most recent call last): File "A_1.py", line 20, in print sum(nodes_1[0]) File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 993, in sum return _wrapit(a, 'sum', axis, dtype, out) File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 37, in _wrapit result = getattr(asarray(obj),method)(*args, **kwds) TypeError: cannot perform reduce with flexible type * what I think:* as the list is in form of '0.0200\t0.3877\t0.0011\n' , n_1[0] takes it as a whole string which includes "\t" , i think thats why they are giving error. now how can i read only required numbers from this line '0.0200\t0.3877\t0.0011\n' and find their sum ? can you kindly help me out how to properly code thing . thank you, regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Nov 12 05:15:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Nov 2009 02:15:24 -0800 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: <50697b2c0911120215t79472c7bkc37e8fb9c69b5977@mail.gmail.com> On Thu, Nov 12, 2009 at 1:59 AM, ankita dutta wrote: > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this : > > 0.02??? 0.38??? 0.01 > 0.04??? 0.32??? 0.00 > 0.03??? 0.40??? 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i am > trying with the following code, i am getting errors : Try using the `csv` module, which despite its name, works on the tab-delimited variant of the format as well: http://docs.python.org/library/csv.html Cheers, Chris -- http://blog.rebertia.com From gatti at dsdata.it Thu Nov 12 05:34:04 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Thu, 12 Nov 2009 02:34:04 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: <83d76e51-7844-47f0-912f-0bc764f91360@s31g2000yqs.googlegroups.com> On Nov 11, 9:48?am, Lorenzo Gatti wrote: > On a more constructive note, I started to follow the instructions athttp://www.pyside.org/docs/pyside/howto-build/index.html(which are > vague and terse enough to be cross-platform) with Microsoft VC9 > Express. > Hurdle 0: recompile Qt because the provided DLLs have hardcoded wrong > paths that confuse CMake. > How should Qt be configured? My first compilation attempt had to be > aborted (and couldn't be resumed) after about 2 hours: trial and error > at 1-2 builds per day could take weeks. Update: I successfully compiled Qt (with WebKit disabled since it gives link errors), as far as I can tell, and I'm now facing apiextractor. Hurdle 1a: convince CMake that I actually have Boost headers and compiled libraries. The Boost directory structure is confusing (compiled libraries in two places), and CMake's script (FindBoost.cmake) is inconsistent (should I set BOOST_INCLUDEDIR or BOOST_INCLUDE_DIR?), obsolete (last known version is 1.38 rather than the requisite 1.40) and rather fishy (e.g. hardcoded "c:\boost" paths). Would the Cmake-based branch of Boost work better? Any trick or recipe to try? Hurdle 1b: the instructions don't mention a dependency from libxml2. Lorenzo Gatti From deets at nospam.web.de Thu Nov 12 05:41:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 11:41:12 +0100 Subject: python with echo In-Reply-To: References: Message-ID: <7m2729F3fjr14U1@mid.uni-berlin.de> hong zhang schrieb: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. Because $POWER is an environment-variable, but POWER is a python-variable, which isn't magically becoming an environment variable. There are various ways to achieve what you want, but IMHO you should ditch the whole echo-business as it's just needless in python itself: with open("/sys/class/net/wlan1/device/tx_power", "w") as f: f.write("%i" % POWER) Diez From s.selvamsiva at gmail.com Thu Nov 12 05:55:44 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Thu, 12 Nov 2009 16:25:44 +0530 Subject: regex remove closest tag Message-ID: Hi all, 1) I need to remove the tags which is just before the keyword(i.e some_text2 ) excluding others. 2) input string may or may not contain tags. 3) Sample input: inputstr = """start some_text1 some_text2 keyword anything""" 4) I came up with the following regex, p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) s=p.search(inputstr) but second group matches both tags,while i need to match the recent one only. I would like to get your suggestions. Note: If i leave group('good1') as greedy, then it matches both the tag. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Nov 12 05:56:02 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 11:56:02 +0100 Subject: Python C API and references References: <3012832.N8HyCQ2AdE@nntp.coder.cl> Message-ID: Hello Daniel, Thanks for the reply. >> >> Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I >> don't >> need the reference to py_val I should decrement the reference after this >> call? > > It really depends on /how/ the object is created. If the > method used to create *py_val* increases the reference count > on the object and another function any other function is > used to increase the reference count, you should use Py_DECREF > or Py_XDECREF. > >> >> So for example: >> >> PyObject *py_val = PyInt_FromLong(5) >> PyObject_SetAttrString(py_obj, "val", py_val); >> Py_DECREF(py_val) >> >> Right? > > In this case is right. *PyInt_FromLong()* returns a new > reference: 'Return value: New reference.', which is increasing > the reference count and PyObject_SetAttrString does it twice, > then you have a reference count of two and you need to decrement > the initial reference counting of the object, or you will have > a memory leak. > [quote] int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) Set the value of the attribute named attr_name, for object o, to the value v. Returns -1 on failure. This is the equivalent of the Python statement o.attr_name = v. int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) Set the value of the attribute named attr_name, for object o, to the value v. Returns -1 on failure. This is the equivalent of the Python statement o.attr_name = v. [/quote] Looking at the documentation, should I have understood that the passed value reference will be incremented and that I should decrement it if I don't need it? Or I should have understood just because of the fact that whenever we have x = b (be it from the C api in a form of SetAttr()) then we should know that b's reference will be incremented. ? Because, before this discussion I did not know I should decrease the reference after SetAttr() >> >> If so, take sysmodule.c: >> >> if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) >> return NULL; >> >> Shouldn't they also call Py_DECREF(Py_None) ? > > No, I think that Py_None do not needs to decrease the > reference count... > None is an object like other objects. I think its reference must be taken into consideration too, for instance why there is the convenience macro: Py_RETURN_NONE ? -- Elias From deets at nospam.web.de Thu Nov 12 05:56:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 11:56:05 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: Message-ID: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > I guess why every programming language has some kind of a 'standard > library' built in within it. > In my view it must not be called as a 'library' at all. what it does > is like a 'bunch of built-in programs ready-made to do stuff'. > > Lets see what a 'library' does: > > 1. offers books for customers > 1.1 lets user select a book by genre, etc > 1.2 lets user to use different books of same genre, etc > 1.3 lets user to use books by same author, etc for different genre > > 2. keeps track of all the books + their genre > 2.1 first knows what all books it has at present > 2.2 when new book comes it is added to the particular shelf sorted by > genre,author,edition, etc. > 2.3 when books become old they are kept separately for future > reference > 2.4 very old books can be sent to a museum/discarded > > I guess no standard library does the minimum of this but wants to be > called a library. > > As a python user I always wanted the standard library to have such > features so the user/developer decides to use what set of libraries he > want. > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > the user selects what he wants with something like. > > use library 2.5 or use library 2.6 etc. > > The 2 main things that the library management interface has to do is > intra library management and inter library management. > > intra library mgmt- consider books to be different libraries > (standard, commercial, private, hobby, etc) > inter library mgmt- consider books to be modules inside a library > ( standard, commercial, private, hobby, etc) > > if somehow we could accomplish this kind of mother of a all plugin/ad- > hoc system that is a real breakthrough. > > Advantages: > > 1. new modules can be added to the stream quickly > 2. let the user select what he want to do > 3. modules (that interdepend on each other) can be packed into small > distribution and added to the stream quickly without waiting for new > releases > 4. solution to problems like py 2.x and 3.x > 5. users can be up to date > 6. documentation becomes easy + elaborate to users > 7. bug managing is easy too > 8. more feed back > 9. testing also becomes easy > 10. many more , i don't know.. you have to find. > > Python already has some thing like that __future__ stuff. but my > question is how many people know that? and how many use that? most of > them wait until old crust gets totally removed. that is bad for user > and python. that is why problems like py2.x py3.x originate. If there > is a newer book collection it must always be available at the library. > i must not go to another library to get that book. You are greatly oversimplifying things, and ignoring a *lot* of issues here. The reason for __future__ is that it can *break* things if new features were just introduced. Take the with-statement, reachable in python2.5 throug from __future__ import with_statement It introduces a new keyword, which until then could be happily used as variable name. So you can't arbirtarily mix code that is written with one or the other feature missing. Then there is the issue of evolving C-APIs (or ABI), wich makes modules incompatible between interpreters. And frankly, for most of your list I don't see how you think your "approach" reaches the stated advantages. Why is documentation becoming easier? Why bug managing? Why testing? I'm sorry, but this isn't thought out in any way, it's just wishful thinking IMHO. Diez From dickinsm at gmail.com Thu Nov 12 06:02:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 12 Nov 2009 03:02:12 -0800 (PST) Subject: Python C API and references References: Message-ID: <8c62bd48-9281-4422-b526-5d0b8cfd4b9d@l2g2000yqd.googlegroups.com> On Nov 12, 9:23?am, "lallous" wrote: > Hello, > > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't > need the reference to py_val I should decrement the reference after this > call? Not necessarily: it depends where py_val came from. I find the 'ownership' model described in the docs quite helpful: http://docs.python.org/c-api/intro.html#reference-count-details It's probably better to read the docs, but here's a short version: If you create a reference to some Python object in a function in your code, you then 'own' that reference, and you're responsible for getting rid of it by the time the function exits. There are various ways this can happen: you can return the reference, thereby transferring ownership to the calling function; you can explicitly discard the reference by calling Py_DECREF; or you can transfer ownership by calling a function that 'steals' the reference (most functions in the C-API don't steal references, but rather borrow them for the duration of the function call). > > So for example: > > PyObject *py_val = PyInt_FromLong(5) > PyObject_SetAttrString(py_obj, "val", py_val); > Py_DECREF(py_val) > > Right? Yes. Here you've created the reference in the first place, so you should Py_DECREF it before you exit. Right after the PyObject_SetAttrString call is a good place to do this. > > If so, take sysmodule.c: > > ? ? ? ? if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) > ? ? ? ? ? ? ? ? return NULL; > > Shouldn't they also call Py_DECREF(Py_None) ? No, I don't think so. I assume you're looking at the sys_displayhook function? This function doesn't create new references to Py_None (well, except when it's about to return Py_None to the caller), so at this point it doesn't own any reference to Py_None: it's not responsible for decrementing the reference count. > Same logic applies to PyDict_SetItemString() Yes. -- Mark From naughtysriram at gmail.com Thu Nov 12 06:18:03 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:18:03 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: On Nov 12, 3:56?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > I guess why every programming language has some kind of a 'standard > > library' built in within it. > > In my view it must not be called as a 'library' at all. what it does > > is like a 'bunch of built-in programs ready-made to do stuff'. > > > Lets see what a 'library' does: > > > 1. offers books for customers > > ?1.1 lets user select a book by genre, etc > > ?1.2 lets user to use different books of same genre, etc > > ?1.3 lets user to use books by same author, etc for different genre > > > 2. keeps track of all the books + their genre > > ?2.1 first knows what all books it has at present > > ?2.2 when new book comes it is added to the particular shelf sorted by > > genre,author,edition, etc. > > ?2.3 when books become old they are kept separately for future > > reference > > ?2.4 very old books can be sent to a museum/discarded > > > I guess no standard library does the minimum of this but wants to be > > called a library. > > > As a python user I always wanted the standard library to have such > > features so the user/developer decides to use what set of libraries he > > want. > > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > > the user selects what he wants with something like. > > > use library 2.5 or use library 2.6 etc. > > > The 2 main things that the library management interface has to do is > > intra library management and inter library management. > > > intra library mgmt- consider books to be different libraries > > (standard, commercial, private, hobby, etc) > > inter library mgmt- consider books to be modules inside a library > > ( standard, commercial, private, hobby, etc) > > > if somehow we could accomplish this kind of mother of a all plugin/ad- > > hoc system that is a real breakthrough. > > > Advantages: > > > 1. new modules can be added to the stream quickly > > 2. let the user select what he want to do > > 3. modules (that interdepend on each other) can be packed into small > > distribution and added to the stream quickly without waiting for new > > releases > > 4. solution to problems like py 2.x and 3.x > > 5. users can be up to date > > 6. documentation becomes easy + elaborate to users > > 7. bug managing is easy too > > 8. more feed back > > 9. testing also becomes easy > > 10. many more , i don't know.. you have to find. > > > Python already has some thing like that __future__ stuff. but my > > question is how many people know that? and how many use that? most of > > them wait until old crust gets totally removed. that is bad for user > > and python. that is why problems like py2.x py3.x originate. If there > > is a newer book collection it must always be available at the library. > > i must not go to another library to get that book. > > You are greatly oversimplifying things, and ignoring a *lot* of issues > here. The reason for __future__ is that it can *break* things if new > features were just introduced. Take the with-statement, reachable in > python2.5 throug > > ? ?from __future__ import with_statement > > It introduces a new keyword, which until then could be happily used as > variable name. > > So you can't arbirtarily mix code that is written with one or the other > feature missing. > > Then there is the issue of evolving C-APIs (or ABI), wich makes modules > incompatible between interpreters. > > And frankly, for most of your list I don't see how you think your > "approach" reaches the stated advantages. Why is documentation becoming > easier? Why bug managing? Why testing? > > I'm sorry, but this isn't thought out in any way, it's just wishful > thinking IMHO. > > Diez I don't know if you have used Dev-C++. It has a 'package management' mechanism for the standard libraries. please see the webpage where all the packaged libraries are stored. In python we have the PyPI which is equivalent to the http://devpacks.org but in PyPI the packages are mostly user made applications. What I want is similar to PyPI but for the python standard libraries, so that they (libraries) are as add-on as possible. check this out too.. I guess you understand what I am thinking... and do pardon my english too.. -- Regards, Sriram. From deets at nospam.web.de Thu Nov 12 06:27:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 12:27:12 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: <7m29p0F3fng2lU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: >> Sriram Srinivasan schrieb: >> >> >> >>> I guess why every programming language has some kind of a 'standard >>> library' built in within it. >>> In my view it must not be called as a 'library' at all. what it does >>> is like a 'bunch of built-in programs ready-made to do stuff'. >>> Lets see what a 'library' does: >>> 1. offers books for customers >>> 1.1 lets user select a book by genre, etc >>> 1.2 lets user to use different books of same genre, etc >>> 1.3 lets user to use books by same author, etc for different genre >>> 2. keeps track of all the books + their genre >>> 2.1 first knows what all books it has at present >>> 2.2 when new book comes it is added to the particular shelf sorted by >>> genre,author,edition, etc. >>> 2.3 when books become old they are kept separately for future >>> reference >>> 2.4 very old books can be sent to a museum/discarded >>> I guess no standard library does the minimum of this but wants to be >>> called a library. >>> As a python user I always wanted the standard library to have such >>> features so the user/developer decides to use what set of libraries he >>> want. >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, >>> the user selects what he wants with something like. >>> use library 2.5 or use library 2.6 etc. >>> The 2 main things that the library management interface has to do is >>> intra library management and inter library management. >>> intra library mgmt- consider books to be different libraries >>> (standard, commercial, private, hobby, etc) >>> inter library mgmt- consider books to be modules inside a library >>> ( standard, commercial, private, hobby, etc) >>> if somehow we could accomplish this kind of mother of a all plugin/ad- >>> hoc system that is a real breakthrough. >>> Advantages: >>> 1. new modules can be added to the stream quickly >>> 2. let the user select what he want to do >>> 3. modules (that interdepend on each other) can be packed into small >>> distribution and added to the stream quickly without waiting for new >>> releases >>> 4. solution to problems like py 2.x and 3.x >>> 5. users can be up to date >>> 6. documentation becomes easy + elaborate to users >>> 7. bug managing is easy too >>> 8. more feed back >>> 9. testing also becomes easy >>> 10. many more , i don't know.. you have to find. >>> Python already has some thing like that __future__ stuff. but my >>> question is how many people know that? and how many use that? most of >>> them wait until old crust gets totally removed. that is bad for user >>> and python. that is why problems like py2.x py3.x originate. If there >>> is a newer book collection it must always be available at the library. >>> i must not go to another library to get that book. >> You are greatly oversimplifying things, and ignoring a *lot* of issues >> here. The reason for __future__ is that it can *break* things if new >> features were just introduced. Take the with-statement, reachable in >> python2.5 throug >> >> from __future__ import with_statement >> >> It introduces a new keyword, which until then could be happily used as >> variable name. >> >> So you can't arbirtarily mix code that is written with one or the other >> feature missing. >> >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules >> incompatible between interpreters. >> >> And frankly, for most of your list I don't see how you think your >> "approach" reaches the stated advantages. Why is documentation becoming >> easier? Why bug managing? Why testing? >> >> I'm sorry, but this isn't thought out in any way, it's just wishful >> thinking IMHO. >> >> Diez > > I don't know if you have used Dev-C++. packages/index.html> It has a 'package management' mechanism for the > standard libraries. No, it hasn't. It has packages for *additional* libraries. C++ has only a very dim concept of standard-libraries. And those usually ship with the compiler, as standard-libraries shipped with python. > please see the webpage where all the packaged > libraries are stored. > > In python we have the PyPI which is equivalent to the http://devpacks.org > but in PyPI the packages are mostly user made applications. > What I want is similar to PyPI but for the python standard libraries, > so that they (libraries) are as add-on as possible. > check this out too.. Why do you want that? What is the actual issue you are addressing? Python's strength is that it comes with a certain set of libs bundled. Artificially to unbundle them, forcing users to install them separatly makes little sense, if any. Sure, updating a bug might be *slightly* easier, but then the standard-libraries are well-tested and decoupling their evolving from the releases of the core interpreter opens up a whole can of worms of problems. There is a tradeoff for both approaches, and one can argue if the current balance is the right one - but if so, then over concrete packages, not over the system in general. Diez From naughtysriram at gmail.com Thu Nov 12 06:28:41 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:28:41 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> On Nov 12, 3:56?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > I guess why every programming language has some kind of a 'standard > > library' built in within it. > > In my view it must not be called as a 'library' at all. what it does > > is like a 'bunch of built-in programs ready-made to do stuff'. > > > Lets see what a 'library' does: > > > 1. offers books for customers > > ?1.1 lets user select a book by genre, etc > > ?1.2 lets user to use different books of same genre, etc > > ?1.3 lets user to use books by same author, etc for different genre > > > 2. keeps track of all the books + their genre > > ?2.1 first knows what all books it has at present > > ?2.2 when new book comes it is added to the particular shelf sorted by > > genre,author,edition, etc. > > ?2.3 when books become old they are kept separately for future > > reference > > ?2.4 very old books can be sent to a museum/discarded > > > I guess no standard library does the minimum of this but wants to be > > called a library. > > > As a python user I always wanted the standard library to have such > > features so the user/developer decides to use what set of libraries he > > want. > > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > > the user selects what he wants with something like. > > > use library 2.5 or use library 2.6 etc. > > > The 2 main things that the library management interface has to do is > > intra library management and inter library management. > > > intra library mgmt- consider books to be different libraries > > (standard, commercial, private, hobby, etc) > > inter library mgmt- consider books to be modules inside a library > > ( standard, commercial, private, hobby, etc) > > > if somehow we could accomplish this kind of mother of a all plugin/ad- > > hoc system that is a real breakthrough. > > > Advantages: > > > 1. new modules can be added to the stream quickly > > 2. let the user select what he want to do > > 3. modules (that interdepend on each other) can be packed into small > > distribution and added to the stream quickly without waiting for new > > releases > > 4. solution to problems like py 2.x and 3.x > > 5. users can be up to date > > 6. documentation becomes easy + elaborate to users > > 7. bug managing is easy too > > 8. more feed back > > 9. testing also becomes easy > > 10. many more , i don't know.. you have to find. > > > Python already has some thing like that __future__ stuff. but my > > question is how many people know that? and how many use that? most of > > them wait until old crust gets totally removed. that is bad for user > > and python. that is why problems like py2.x py3.x originate. If there > > is a newer book collection it must always be available at the library. > > i must not go to another library to get that book. > > You are greatly oversimplifying things, and ignoring a *lot* of issues > here. The reason for __future__ is that it can *break* things if new > features were just introduced. Take the with-statement, reachable in > python2.5 throug > > ? ?from __future__ import with_statement > > It introduces a new keyword, which until then could be happily used as > variable name. > > So you can't arbirtarily mix code that is written with one or the other > feature missing. > > Then there is the issue of evolving C-APIs (or ABI), wich makes modules > incompatible between interpreters. > > And frankly, for most of your list I don't see how you think your > "approach" reaches the stated advantages. Why is documentation becoming > easier? Why bug managing? Why testing? > > I'm sorry, but this isn't thought out in any way, it's just wishful > thinking IMHO. > > Diez __future__ as you said helps in stop breaking things. what i suggest that if both the libraries (in yr case-with is defined in one and other with is not defined is a simple one) like py2.x and py3.x exists and i want to use 3.x features in the morning then in the evening i want to use 2.x or something like that just add on the library and i get the require functionality From tartley at tartley.com Thu Nov 12 06:29:59 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 Nov 2009 03:29:59 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: On Nov 10, 1:34?pm, Philip Semanchuk wrote: > On Nov 9, 2009, at 9:16 PM, Gabriel Genellina wrote: > > > > > En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk > > escribi?: > >> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: > > >>> Recently I put together this incomplete comparison chart in an ? > >>> attempt > >>> to choose between the different alternatives to py2exe: > > >>>http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > >> I was interested in py2exe because we'd like to provide a one ? > >> download, one click install experience for our Windows users. I ? > >> think a lot of people are interested in py2exe for the same reason. ? > >> Well, one thing that I came across in my travels was the fact that ? > >> distutils can create MSIs. Like py2exe, MSIs provide a one ? > >> download, one click install experience under Windows and therefore ? > >> might be a replacement for py2exe. > > > But py2exe and .msi are complementary, not a replacement. > > py2exe collects in onedirectory(or even in one file in some cases) ? > > all the pieces necesary to run your application. That is,Python? > > itself + your application code + all referenced libraries + other ? > > required pieces. > > The resulting files must beinstalledin the client machine; you ? > > either build a .msi file (a database for the Microsoft Installer) or ? > > use any other installer (like InnoSetup, the one I like). > > >> For me, the following command was sufficient to create an msi, ? > >> although it only worked under Windows (not under Linux or OS X): > >>pythonsetup.py bdist_msi > > >> The resulting MSI worked just fine in my extensive testing (read: I ? > >> tried it on one machine). > > > The resulting .msi file requiresPythonalreadyinstalledon the ? > > target machine, if I'm not mistaken. The whole point of py2exe is to ? > > avoid requiring a previousPythoninstall. > > You're right; the MSI I created doesn't include prerequisites. It ? > packaged up our app, that's it. To be fair to MSIs, they might be ? > capable of including prerequisites, the app, and the kitchen sink. But ? > I don't thinkPython'screation process through distutils makes that ? > possible. > > That's why I suggested MSIs belong alongside RPM/DEB in the chart (if ? > they're to be included at all). > > I wouldn't say that the whole point of py2exe is to bundlePython. ? > That's certainly a big benefit, but another benefit is that it can ? > bundle an app into a one-click download. That's why we were interested ? > in it. > > > > >> It seems, then, that creating an MSI is even within the reach of ? > >> someone like me who spends very little time in Windows-land, so it ? > >> might be worth a column on your chart alongside rpm/deb. > > > As said inhttp://wiki.python.org/moin/DistributionUtilitiesthe ? > > easiest way is to use py2exe + InnoSetup. > > Easiest for you. =) The list of packages and modules that might ? > require special treatment is almost a perfect superset of the modules ? > we're using in our application:http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules > > py2exe looks great, but it remains to be seen if it's the easiest way ? > to solve our problem. The MSI isn't nearly as nice for the end user, ? > but we created it using only thePythonstandard library and our ? > existing setup.py. Simplicity has value. > > Cheers > Philip Hey Philip and Gabriel, Interesting to hear your respective perspectives - you've given me much to ponder and to read about. Personally I'm keen to find a method that doesn't require the end-user to have to manually install (the correct version of) Python separately from my app, so I think that rules out the distutils-generated MSI for me. I can see it has value for others though. From deets at nospam.web.de Thu Nov 12 06:35:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 12:35:11 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> Message-ID: <7m2a7fF3g36nnU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: >> Sriram Srinivasan schrieb: >> >> >> >>> I guess why every programming language has some kind of a 'standard >>> library' built in within it. >>> In my view it must not be called as a 'library' at all. what it does >>> is like a 'bunch of built-in programs ready-made to do stuff'. >>> Lets see what a 'library' does: >>> 1. offers books for customers >>> 1.1 lets user select a book by genre, etc >>> 1.2 lets user to use different books of same genre, etc >>> 1.3 lets user to use books by same author, etc for different genre >>> 2. keeps track of all the books + their genre >>> 2.1 first knows what all books it has at present >>> 2.2 when new book comes it is added to the particular shelf sorted by >>> genre,author,edition, etc. >>> 2.3 when books become old they are kept separately for future >>> reference >>> 2.4 very old books can be sent to a museum/discarded >>> I guess no standard library does the minimum of this but wants to be >>> called a library. >>> As a python user I always wanted the standard library to have such >>> features so the user/developer decides to use what set of libraries he >>> want. >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, >>> the user selects what he wants with something like. >>> use library 2.5 or use library 2.6 etc. >>> The 2 main things that the library management interface has to do is >>> intra library management and inter library management. >>> intra library mgmt- consider books to be different libraries >>> (standard, commercial, private, hobby, etc) >>> inter library mgmt- consider books to be modules inside a library >>> ( standard, commercial, private, hobby, etc) >>> if somehow we could accomplish this kind of mother of a all plugin/ad- >>> hoc system that is a real breakthrough. >>> Advantages: >>> 1. new modules can be added to the stream quickly >>> 2. let the user select what he want to do >>> 3. modules (that interdepend on each other) can be packed into small >>> distribution and added to the stream quickly without waiting for new >>> releases >>> 4. solution to problems like py 2.x and 3.x >>> 5. users can be up to date >>> 6. documentation becomes easy + elaborate to users >>> 7. bug managing is easy too >>> 8. more feed back >>> 9. testing also becomes easy >>> 10. many more , i don't know.. you have to find. >>> Python already has some thing like that __future__ stuff. but my >>> question is how many people know that? and how many use that? most of >>> them wait until old crust gets totally removed. that is bad for user >>> and python. that is why problems like py2.x py3.x originate. If there >>> is a newer book collection it must always be available at the library. >>> i must not go to another library to get that book. >> You are greatly oversimplifying things, and ignoring a *lot* of issues >> here. The reason for __future__ is that it can *break* things if new >> features were just introduced. Take the with-statement, reachable in >> python2.5 throug >> >> from __future__ import with_statement >> >> It introduces a new keyword, which until then could be happily used as >> variable name. >> >> So you can't arbirtarily mix code that is written with one or the other >> feature missing. >> >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules >> incompatible between interpreters. >> >> And frankly, for most of your list I don't see how you think your >> "approach" reaches the stated advantages. Why is documentation becoming >> easier? Why bug managing? Why testing? >> >> I'm sorry, but this isn't thought out in any way, it's just wishful >> thinking IMHO. >> >> Diez > > __future__ as you said helps in stop breaking things. what i suggest > that if both the libraries (in yr case-with is defined in one and > other with is not defined is a simple one) like py2.x and py3.x exists > and i want to use 3.x features in the morning then in the evening i > want to use 2.x or something like that just add on the library and i > get the require functionality This doesn't make sense to me. What are you doing in the morning, and what in the evening, and to what extend is the code the same or are you talking about different pieces of code? Diez From naughtysriram at gmail.com Thu Nov 12 06:54:00 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:54:00 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> Message-ID: <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> On Nov 12, 4:35?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: > >> Sriram Srinivasan schrieb: > > >>> I guess why every programming language has some kind of a 'standard > >>> library' built in within it. > >>> In my view it must not be called as a 'library' at all. what it does > >>> is like a 'bunch of built-in programs ready-made to do stuff'. > >>> Lets see what a 'library' does: > >>> 1. offers books for customers > >>> ?1.1 lets user select a book by genre, etc > >>> ?1.2 lets user to use different books of same genre, etc > >>> ?1.3 lets user to use books by same author, etc for different genre > >>> 2. keeps track of all the books + their genre > >>> ?2.1 first knows what all books it has at present > >>> ?2.2 when new book comes it is added to the particular shelf sorted by > >>> genre,author,edition, etc. > >>> ?2.3 when books become old they are kept separately for future > >>> reference > >>> ?2.4 very old books can be sent to a museum/discarded > >>> I guess no standard library does the minimum of this but wants to be > >>> called a library. > >>> As a python user I always wanted the standard library to have such > >>> features so the user/developer decides to use what set of libraries he > >>> want. > >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, > >>> the user selects what he wants with something like. > >>> use library 2.5 or use library 2.6 etc. > >>> The 2 main things that the library management interface has to do is > >>> intra library management and inter library management. > >>> intra library mgmt- consider books to be different libraries > >>> (standard, commercial, private, hobby, etc) > >>> inter library mgmt- consider books to be modules inside a library > >>> ( standard, commercial, private, hobby, etc) > >>> if somehow we could accomplish this kind of mother of a all plugin/ad- > >>> hoc system that is a real breakthrough. > >>> Advantages: > >>> 1. new modules can be added to the stream quickly > >>> 2. let the user select what he want to do > >>> 3. modules (that interdepend on each other) can be packed into small > >>> distribution and added to the stream quickly without waiting for new > >>> releases > >>> 4. solution to problems like py 2.x and 3.x > >>> 5. users can be up to date > >>> 6. documentation becomes easy + elaborate to users > >>> 7. bug managing is easy too > >>> 8. more feed back > >>> 9. testing also becomes easy > >>> 10. many more , i don't know.. you have to find. > >>> Python already has some thing like that __future__ stuff. but my > >>> question is how many people know that? and how many use that? most of > >>> them wait until old crust gets totally removed. that is bad for user > >>> and python. that is why problems like py2.x py3.x originate. If there > >>> is a newer book collection it must always be available at the library. > >>> i must not go to another library to get that book. > >> You are greatly oversimplifying things, and ignoring a *lot* of issues > >> here. The reason for __future__ is that it can *break* things if new > >> features were just introduced. Take the with-statement, reachable in > >> python2.5 throug > > >> ? ?from __future__ import with_statement > > >> It introduces a new keyword, which until then could be happily used as > >> variable name. > > >> So you can't arbirtarily mix code that is written with one or the other > >> feature missing. > > >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules > >> incompatible between interpreters. > > >> And frankly, for most of your list I don't see how you think your > >> "approach" reaches the stated advantages. Why is documentation becoming > >> easier? Why bug managing? Why testing? > > >> I'm sorry, but this isn't thought out in any way, it's just wishful > >> thinking IMHO. > > >> Diez > > > __future__ as you said helps in stop breaking things. what i suggest > > that if both the libraries (in yr case-with is defined in one and > > other with is not defined is a simple one) like py2.x and py3.x exists > > and i want to use 3.x features in the morning then in the evening i > > want to use 2.x or something like that just add on the library and i > > get the require functionality > > This doesn't make sense to me. What are you doing in the morning, and > what in the evening, and to what extend is the code the same or are you > talking about different pieces of code? > > Diez ok let me make it more clear.. forget how you use python now.. i am talking about __futuristic__ python programming. there is no more python2.x or python3.x or python y.x releases. there is only updates of python and standard library say 1.1.5 and 1.1.6. let the difference be an old xml library updated with a new regex support. i am coding my program now. i want my application to be compatible with 1.1.5 library use library 1.1.5 import blah form blahblah ... ... i cannot use regex feature of xml in this application i then update my library in the evening now both the libraries are present in my system. now i try using the new feature use library 1.1.6 #thats all now i get all features import blah from blahblah ... ... From himanshu.garg at gmail.com Thu Nov 12 07:16:55 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 18:16:55 +0600 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: <6f82a7270911120416o76ebaf69p6c439fd36150e026@mail.gmail.com> 2009/11/12 ankita dutta : > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this : > > 0.02??? 0.38??? 0.01 > 0.04??? 0.32??? 0.00 > 0.03??? 0.40??? 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i am > trying with the following code, i am getting errors : > > code: > " > ln1=open("A.txt","r+")??? # file "A.txt" contains my matrix > lines1=ln1.readlines() > n_1=[ ] > > for p1 in range (0,len(lines1)): > ??? f1=lines1[p1] > ??? n_1.append((f1) ) > print n_1 > print? sum(n_1[0]) > > " > > output: > > ['0.0200\t0.3877\t0.0011\n', '0.0040\t0.3292\t0.0001\n', > '0.0355\t0.4098\t0.0028\n', '0.0035\t0.3063\t0.0001\n', > '0.0080\t0.3397\t0.0002\n'] > > Traceback (most recent call last): > ? File "A_1.py", line 20, in > ??? print sum(nodes_1[0]) > ? File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line > 993, in sum > ??? return _wrapit(a, 'sum', axis, dtype, out) > ? File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line > 37, in _wrapit > ??? result = getattr(asarray(obj),method)(*args, **kwds) > TypeError: cannot perform reduce with flexible type > > > what I think: > > as the list is in form of?? '0.0200\t0.3877\t0.0011\n'??? ,? n_1[0]? takes > it as a whole string?? which includes "\t" , i think thats why they are > giving error. > > now how can i read only required numbers from this line > '0.0200\t0.3877\t0.0011\n'? and find their sum ? > can you kindly help me out how to properly code thing . > Yes you have it right. Split the string at spaces and convert the numeric parts to floats before summing. Something along these lines :- 1 ln1=open("A.txt","r+") # file "A.txt" contains my matrix 2 lines1=ln1.readlines() 3 n_1=[ ] 4 5 for p1 in range (0,len(lines1)): 6 f1=lines1[p1] 7 n_1.append((f1) ) 8 print n_1 9 import re 10 nos = [] 11 for s in re.split('\s+', n_1[0]): 12 if s != '': 13 nos.append(float(s)) 14 print nos 15 print sum(nos) Better still use the csv module as suggested. Thank You, ++imanshu From arnaud.sig at gmail.com Thu Nov 12 07:25:41 2009 From: arnaud.sig at gmail.com (Arnaud Vandecasteele) Date: Thu, 12 Nov 2009 13:25:41 +0100 Subject: NetCDF to ascii file Message-ID: <166b86070911120425k69cc1e3co3dd1f4c7f2b1b4cb@mail.gmail.com> Hi all, I would like to know if it's possible to read data from a netcdf file and export it into an ASCII file. I'm trying to get the latitude, longitude and a determinate value of a netcdf file. But I don't know exactly how to do it. I succeed to open and read a netcdf file but i don't know how to export the data. Here is my simple script : import Scientific.IO.NetCDF as nc from Numeric import * import sys try : ncFile = nc.NetCDFFile("tos_O1_2001-2002.nc","r") except : print "can't open the file" sys.exit(1) try : print "################# Dimensions #################" print ncFile.dimensions.keys() print "################# Variables #################" print ncFile.variables.keys() #return ['time_bnds', 'lat_bnds', 'lon', 'lon_bnds', 'time', 'lat', 'tos' print "################# Var Dim #################" tos = ncFile.variables["tos"] print tos.dimensions #return : ('time', 'lat', 'lon') tosValue = tos.getValue() except : ncFile.close() Do you know how I can get for each tos feature the lat, lon and time values. Best regards Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From himanshu.garg at gmail.com Thu Nov 12 07:28:58 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 18:28:58 +0600 Subject: Error in Windmill In-Reply-To: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> References: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> Message-ID: <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> 2009/11/12 Raji Seetharaman : > > Hi > > Im learning Web scraping with Python from here > http://www.packtpub.com/article/web-scraping-with-python-part-2 > > From the above link, the complete code is here http://pastebin.com/m10046dc6 > > When i run the program in the terminal i receive following errors > > File "nasa.py", line 41, in > ??? test_scrape_iotd_gallery() > ? File "nasa.py", line 24, in test_scrape_iotd_gallery > ??? client = WindmillTestClient(__name__) > ? File > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", > line 142, in __init__ > ??? method_proxy = windmill.tools.make_jsonrpc_client() > ? File > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", > line 35, in make_jsonrpc_client > ??? url = urlparse(windmill.settings['TEST_URL']) > AttributeError: 'module' object has no attribute 'settings' > > Suggest me > > Thanks > Raji. S > > -- > http://mail.python.org/mailman/listinfo/python-list > > Google or See http://groups.google.com/group/windmill-dev/browse_thread/thread/c921f7a25c0200c9 From sromero at gmail.com Thu Nov 12 07:35:07 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 04:35:07 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) Message-ID: Hi. I'm trying to port (just for fun), my old Sinclair Spectrum emulator, ASpectrum, from C to Python + pygame. Although the Sinclair Spectrum has a simple Z80 8 bit 3.5Mhz microprocessor, and no aditional hardware (excluding the +2/+3 model's AYsound chip), I'm not sure if my loved scripted language, python, will be fast enought to emulate the Sinclair Spectrum at 100% speed. There are Java Spectrum emulators available, so it should be possible. Anyway, this message is directed to prepare the DESIGN so that the code can run as fast as possible. I mean, I want to know the best way to do some emulation tasks before starting to write a single line of code. My questions: GLOBAL VARIABLES VS OBJECTS: ================================== I need the emulation to be as fastest as possible. In my C program I have an struct called "Z80_Processor" that contains all the registers, memory structures, and so on. I pass that struct to the Z80Decode(), Z80Execute() or Z80Dissassemble() functions, i.e.. This allows me (in my C emulator) to emulate multiple z80 processors If I want. As Python is scripted and I imagine that emulation will be slower than the emulator written in C, I've thought of not creating a Z80_Processor *object* and declare global variables such as reg_A, reg_B, reg_PC, array main_memory[] and so on, and let the z80 functions to directly access that global variables. I'm doing this to avoid OOP's extra processing... but this makes the program less modular. Do you think using processor "objects" would make the execution slower, or I'm doing right using global variables and avoiding objects in this type of program? Should I start writing all the code with a Z80CPU object and if performance is low, just remove the "object" layer and declare it as globals, or I should go directly for globals? HIGH AND LOW PART OF REGISTERS: ================================= - In C, I have the following structs and code for emulating registers: typedef union { struct { unsigned char l, h; } B; unsigned short W; } eword; eword reg_A; This means that reg_A is a 16 bit "variable" that I can directly access with reg_A.w=value, and I can access also the LOW BYTE and HIGH BYTES with reg_A.B.h and reg_A.B.l. And more importante, changing W modifies l and h, and changing l or h modifies W. How can I implement this in Python, I mean, define a 16 byte variable so that high and low bytes can be accessed separately and changing W, H or L affects the entire variable? I would like to avoid doing BIT masks to get or change HIGH or LOW parts of a variable and let the compiled code to do it by itself. I know I can write an "object" with set and get methods that implement that (that could be done in C too), but for emulation, I need the FASTEST implementation possible (something like the C's Union trick). MEMORY (ARRAYS): =========================== To emulate Spectrum's memory in C, I have a 64KB array like: unsigned char memory_array[65535]. Then I can access memory_array[reg_PC] to fetch the next opcode (or data for an opcode) and just increment reg_PC. Is python's array module the best (and fastest) implementation to "emulate" the memory? MEMORY (PAGES): ============================= The Sinclair Spectrum 8 bit computer can address 64KB of memory and that memory is based on 16KB pages (so it can see 4 pages simultaneously, where page 0 is always ROM). Programs can change "pages" to point to aditional 16KB pages in 128KB memory models. I don't know how to emulate paging in python... My first approach would be to have eight 16KB arrays, and "memcpy()" memory to the main 64KB array when the user calls page swapping. I mean (C + pseudocode): main_memory[65536]; memory_blocks[8][16384]; // Initial settings current_pages[4] = [0, 1, 2, 3] // User swaps last memory page (3) to block 7, so I: page_to_swap_from = 3 page_to_map = 7 // Save the contents of current page (page being unmapped): memcpy( main_memory, // Source 16384*page_to_swap_from, // Starting at memory_blocks[current_pages[page_to_swap_from], // To 16384 ); // 16K // Now map page 7 to memory block 3: memcpy( memory_blocks[page_to_map], // Source 0, // Starting at main_memory[page_to_swap_from*16384], // To 16384 ); // 16K current_pages[page_to_swap_from] = page_to_map; Memcpy is very fast in C, but I don't know if doing the same in python with arrays would be fast enough, or if there is a better approach to simulate paging of 16KB blocks in a 64KB memory windows (4 mappable memory blocks). Maybe another approach based in pointers or something like that? From deets at nospam.web.de Thu Nov 12 08:07:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 14:07:48 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> Message-ID: <7m2fl4F3g3usmU1@mid.uni-berlin.de> > > ok let me make it more clear.. > forget how you use python now.. i am talking about __futuristic__ > python programming. > > > there is no more python2.x or python3.x or python y.x releases. there > is only updates of python and standard library say 1.1.5 and 1.1.6. > let the difference be an old xml library updated with a new regex > support. > > i am coding my program now. > i want my application to be compatible with 1.1.5 library > > use library 1.1.5 > import blah form blahblah > ... > ... > > i cannot use regex feature of xml in this application > i then update my library in the evening > now both the libraries are present in my system. > now i try using the new feature > > use library 1.1.6 #thats all now i get all features > import blah from blahblah This is not futuristic, this is state of the art with PyPI & setuptools. You still haven't addressed all the issues that arise though, regarding different python interpreter versions having different syntax and ABI. Diez From hpj at urpla.net Thu Nov 12 08:10:32 2009 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 12 Nov 2009 14:10:32 +0100 Subject: About one class/function per module In-Reply-To: <7lajrkF3c97onU1@mid.uni-berlin.de> References: <7lajrkF3c97onU1@mid.uni-berlin.de> Message-ID: <200911121410.32298.hpj@urpla.net> On Tuesday 03 November 2009, 12:52:20 Diez B. Roggisch wrote: > Peng Yu wrote: > > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: > >> Peng Yu wrote: > >>> I don't think that this is a problem that can not be overcome. A > >>> simple solution might be to associate a unique identifier to each > >>> file, so that even the filename has been changed, the new version and > >>> the old version can still be identified as actually the same file. > >> > >> Or, again, you could work _with_ the tools you're using in the way > >> they're meant to be used, rather than re-inventing the whole process > >> of version control yourself. > > > > I'm not trying to reinvent a new version control. But due to this > > drawback, I avoid use a version control system. Rather, I compressed > > my source code in a tar file whenever necessary. But if a version > > control system has this capability, I'd love to use it. And I don't > > think that no version control system support this is because of any > > technical difficult but rather because of practical issue (maybe it > > takes a lot efforts to add this feature to an existing version control > > system?). > > There are those people who realize if *everything* they encounter needs > adjustment to fit their needs, their needs need adjustment. > > Others fight an uphill battle & bicker about things not being as they > want them. > > Don't get me wrong - innovation often comes from scratching ones personal > itch. But you seem to be suffering from a rather bad case of > neurodermatitis. Diez, sorry for chiming in that lately, but while the whole thread is spilled over for no good reason, your QOTW remembered me on a quote of R.A.W., that sounds like a perfect fit: Whatever the Thinker thinks, the Prover will prove. And if the Thinker thinks passionately enough, the Prover will prove the thought so conclusively that you will never talk a person out of such a belief, even if it is something as remarkable as the notion that there is a gaseous vertebrate of astronomical heft ("GOD") who will spend all eternity torturing people who do not believe in his religion. From "Prometheus Rising" by Robert Anton Wilson Pete http://en.wikiquote.org/wiki/Robert_Anton_Wilson From sraji.me at gmail.com Thu Nov 12 08:20:35 2009 From: sraji.me at gmail.com (Raji Seetharaman) Date: Thu, 12 Nov 2009 18:50:35 +0530 Subject: Error in Windmill In-Reply-To: <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> References: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> Message-ID: <23e3fbb60911120520o2314bb15p2934c30eb7b54a6d@mail.gmail.com> On Thu, Nov 12, 2009 at 5:58 PM, Himanshu wrote: > 2009/11/12 Raji Seetharaman : > > > > Hi > > > > Im learning Web scraping with Python from here > > http://www.packtpub.com/article/web-scraping-with-python-part-2 > > > > From the above link, the complete code is here > http://pastebin.com/m10046dc6 > > > > When i run the program in the terminal i receive following errors > > > > File "nasa.py", line 41, in > > test_scrape_iotd_gallery() > > File "nasa.py", line 24, in test_scrape_iotd_gallery > > client = WindmillTestClient(__name__) > > File > > > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", > > line 142, in __init__ > > method_proxy = windmill.tools.make_jsonrpc_client() > > File > > > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", > > line 35, in make_jsonrpc_client > > url = urlparse(windmill.settings['TEST_URL']) > > AttributeError: 'module' object has no attribute 'settings' > > > > Suggest me > > > > Thanks > > Raji. S > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > Google or See > http://groups.google.com/group/windmill-dev/browse_thread/thread/c921f7a25c0200c9 > Thanks for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 08:21:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 13:21:32 GMT Subject: standard libraries don't behave like standard 'libraries' References: Message-ID: <00859027$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 00:31:57 -0800, Sriram Srinivasan wrote: > I guess why every programming language has some kind of a 'standard > library' built in within it. > In my view it must not be called as a 'library' at all. what it does is > like a 'bunch of built-in programs ready-made to do stuff'. > > Lets see what a 'library' does: > > 1. offers books for customers [...] You are describing a lending library, which is not the only sort of library. My personal library doesn't do any of those things. It is just a room with shelves filled with books. Words in English can have more than one meaning. Horses run, refrigerators run, and even though they don't have either legs or motors, programs run too. The argument that code libraries don't behave like lending libraries won't get you anywhere. > As a python user I always wanted the standard library to have such > features so the user/developer decides to use what set of libraries he > want. > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > the user selects what he wants with something like. > > use library 2.5 or use library 2.6 etc. Since library features are tied closely to the features available in the Python interpreter, the way to use library 2.5 is to use Python 2.5. You *might* be able to use library 2.5 with Python 2.6 or 2.4; you absolutely won't be able to use it with Python 1.5 or 3.1. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 08:33:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 13:33:21 GMT Subject: How can a module know the module that imported it? References: Message-ID: <008592ec$0$26916$c3e8da3@news.astraweb.com> On Wed, 11 Nov 2009 13:44:06 -0800, Ethan Furman wrote: > Well, I don't know what kj is trying to do, but my project is another > (!) configuration program. (Don't worry, I won't release it... unless > somebody is interested, of course !) > > So here's the idea so far: > The configuration data is stored in a python module (call it > settings.py). In order to be able to do things like add settings to it, > save the file after changes are made, etc., settings.py will import the > configuration module, called configure.py. > > A sample might look like this: > > > import configure > > paths = configure.Item() > paths.tables = 'c:\\app\\data' > paths.temp = 'c:\\temp' > > > And in the main program I would have: > > > import settings > > main_table = dbf.Table('%s\\main' % paths.tables) > > # user can modify path locations, and does, so update # we'll say it > changes to \work\temp > > settings.paths.temp = user_setting() > settings.configure.save() > > > And of course, at this point settings.py now looks like > > > import configure > > paths = configure.Item() > paths.tables = 'c:\\app\\data' > paths.temp = 'c:\\work\\temp' > Self-modifying code? UNCLEAN!!! UNCLEAN!!! > Now, the tricky part is the line > > settings.configure.save() > > How will save know which module it's supposed to be re-writing? In my opinion, the cleanest way is to tell it which module to re-write. Or better still, tell it which *file* to write to: settings.configure.save(settings.__file__) which is still self-modifying, but at least it doesn't need magic to modify itself. -- Steven From naughtysriram at gmail.com Thu Nov 12 08:43:20 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 05:43:20 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> Message-ID: <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> On Nov 12, 6:07?pm, "Diez B. Roggisch" wrote: > > ok let me make it more clear.. > > forget how you use python now.. i am talking about __futuristic__ > > python programming. > > > there is no more python2.x or python3.x or python y.x releases. there > > is only updates of python and standard library say 1.1.5 and 1.1.6. > > let the difference be an old xml library updated with a new regex > > support. > > > i am coding my program now. > > i want my application to be compatible with 1.1.5 library > > > use library 1.1.5 > > import blah form blahblah > > ... > > ... > > > i cannot use regex feature of xml in this application > > i then update my library in the evening > > now both the libraries are present in my system. > > now i try using the new feature > > > use library 1.1.6 #thats all now i get all features > > import blah from blahblah > > This is not futuristic, this is state of the art with PyPI & setuptools. > > You still haven't addressed all the issues that arise though, regarding > different python interpreter versions having different syntax and ABI. > > Diez haha... it would be awesome if they implement it in the 'future' .. i posted the same to python-dev at python.org, it seems the distutil is getting a big overhaul. (i hope they make a new uninstall option for setuptools n easy_install) they say there are many ways to do that using pkg tools... but python wants one and only one way- the python way. regarding issues: 1.security is always a issue 2. regarding problems like with statement you mentioned earlier.. i think there will be a basic feature set that is common for all versions of add-on libraries. 3.when you want the new feature you have to update your python interpreter use interpreter 1.5.2 may trigger the proper interpreter plugin(responsible for additional feature) to load and add functionality.. its simple to say but it is hard to make the compiler pluggable, may be they figure out. use library x.y.z while issuing this command the default interpreter has to automatically resolve dependencies of the core c/cpp static libraries and other shared libraries. so that must not be an issue. if they have implemented this much, dep solving is nothing. futuristic python may also contain an option for compiling a module into a static library. so we can code python libraries in python (mostly) itself. think of pypy. it is already state of the art. From pavlovevidence at gmail.com Thu Nov 12 08:58:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 05:58:45 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: Message-ID: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> On Nov 12, 4:35?am, Santiago Romero wrote: > ?Hi. > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > ASpectrum, from C to Python + pygame. The answer to your question is, "Use numpy". More details below. [snip] > ?Should I start writing all the code with a Z80CPU object and if > performance is low, just remove the "object" layer and declare it as > globals, Yes, but I'd suggest to index a numpy array rather than structures. See below. [snip] > ?How can I implement this in Python, I mean, define a 16 byte variable > so that high and low bytes can be accessed separately and changing W, > H or L affects the entire variable? I would like to avoid doing BIT > masks to get or change HIGH or LOW parts of a variable and let the > compiled code to do it by itself. You can do clever memory slicing like this with numpy. For instance: breg = numpy.zeros((16,),numpy.uint8) wreg = numpy.ndarray((8,),numpy.uint16,breg) This causes breg and wreg to share the same 16 bytes of memory. You can define constants to access specific registers: R1L = 1 R1H = 2 R1 = 1 breg[R1H] = 2 print wreg[R1] [snip] > ?Is python's array module the best (and fastest) implementation to > "emulate" the memory? I'd use numpy for this as well. (I doubt the Z80 had a 16-bit bus, but if it did you could use the same memory sharing trick I showed you with the registers to simulate word reads and writes.) Note that, when performing operations on single values, neither numpy nor array module are necessarily a lot faster than Python lists, might even be slower. But they use a LOT less memory, which is important for largish arrays. [snip] > ?The Sinclair Spectrum 8 bit computer can address 64KB of memory and > that memory is based on 16KB pages (so it can see 4 pages > simultaneously, where page 0 is always ROM). Programs can change > "pages" to point to aditional 16KB pages in 128KB memory models. > > ?I don't know how to emulate paging in python... numpy again. This would mean you'd have to fiddle with addresses a bit, but that shouldn't be too big a deal. Create the physical memory: mem = numpy.zeros((128*1024,),numpy.uint8) Then create the pages. (This is a regular Python list containing numpy slices. numpy slices share memory so there is no copying of underlying data.) page = [mem[0:16*1024], mem[16*1024:32*1024], mem[32*1024:48*1024], mem[48*1024:64*1024]] To access the byte at address 42432, you'd have use bit operations to get a page number and index (2 and 9664 in this case), then you can access the memory like this: page[2][9664] = 33 p = page[3][99] To swap a page, reassign the slice of main memory, page[2] = mem[96*1024:112*1024] Now, accessing address 42432 will access a byte from a different page. If you don't want to fiddle with indirect pages and would just rather copy memory around when a page swap occurs, you can do that, too. (Assigning to a slice copies the data rather than shares.) I don't know if it's as fast as memset but it should be pretty quick. . Hope these brief suggestions help. If you don't want third party libraries, then numpy will be of no use. But I guess if you're using pygame third party modules are ok. So get numpy, it'll make things a lot easier. It can be a bit daunting to learn, though. Carl Banks From naughtysriram at gmail.com Thu Nov 12 09:21:21 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 06:21:21 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <00859027$0$26916$c3e8da3@news.astraweb.com> Message-ID: <8f0c9f6a-35d1-43cf-8a90-250fadb217a8@m38g2000yqd.googlegroups.com> > You are describing a lending library, which is not the only sort of > library. My personal library doesn't do any of those things. It is just a > room with shelves filled with books. how i see is all libraries are libraries, for a personal library you are the only customer and you are the management too.! > Words in English can have more than one meaning. Horses run, > refrigerators run, and even though they don't have either legs or motors, > programs run too. The argument that code libraries don't behave like > lending libraries won't get you anywhere. first this is not an argument at all...i clearly stated these were my imaginations cum ideas. > Since library features are tied closely to the features available in the > Python interpreter, the way to use library 2.5 is to use Python 2.5. You > *might* be able to use library 2.5 with Python 2.6 or 2.4; you absolutely > won't be able to use it with Python 1.5 or 3.1. i am not talking about the past..past were experiences! that the developers had and what is happening today *might be* another experience for the future. From sromero at gmail.com Thu Nov 12 09:37:55 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 06:37:55 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > ASpectrum, from C to Python + pygame. > > The answer to your question is, "Use numpy". ?More details below. Let's see :-) > > ?How can I implement this in Python, I mean, define a 16 byte variable > > so that high and low bytes can be accessed separately and changing W, > > H or L affects the entire variable? I would like to avoid doing BIT > > masks to get or change HIGH or LOW parts of a variable and let the > > compiled code to do it by itself. > > You can do clever memory slicing like this with numpy. ?For instance: > > breg = numpy.zeros((16,),numpy.uint8) > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > This causes breg and wreg to share the same 16 bytes of memory. ?You > can define constants to access specific registers: > > R1L = 1 > R1H = 2 > R1 = 1 > > breg[R1H] = 2 > print wreg[R1] And how about speed? Assuming a 16 bit register named BC which contains 2 8 bit regiters (B and C)... Will the above be faster than shifts and bit operations (<<, and, >> ) with new B and C values to "recalculate" BC when reading or changing either B, C or BC? > > ?Is python's array module the best (and fastest) implementation to > > "emulate" the memory? > > I'd use numpy for this as well. ?(I doubt the Z80 had a 16-bit bus, > but if it did you could use the same memory sharing trick I showed you > with the registers to simulate word reads and writes.) Z80 has a 16 bit ADDRESS bus, 8 bit DATA bus. This means you can address from 0 to 65535 memory cells of 8 bytes. Z80 has 16 bit bus operations, but currently in C I write 16 bit values as two 8 bit consecutive values without using (unsigned short *) pointers. But it seems that numpy would allow me to do it better than C in this case... > Note that, when performing operations on single values, neither numpy > nor array module are necessarily a lot faster than Python lists, might > even be slower. ?But they use a LOT less memory, which is important > for largish arrays. Well, we're talking about a 128KB 1-byte array, that's the maximum memory size a Sinclair Spectrum can have, and always by using page swapping of 16KB blocks in a 64KB addressable space... If you really think that python lists can be faster that numpy or array modules, let me know. Maybe I'll make a "benchmark test", by making some millions of read / write operations and timing the results. I wan't to write the emulator as "pythonic" as possible... > > ?I don't know how to emulate paging in python... > > numpy again. ?This would mean you'd have to fiddle with addresses a > bit, but that shouldn't be too big a deal. ?Create the physical > memory: > > mem = numpy.zeros((128*1024,),numpy.uint8) A 128K array of zeroes... > Then create the pages. ?(This is a regular Python list containing > numpy slices. numpy slices share memory so there is no copying of > underlying data.) > > page = [mem[0:16*1024], > ? ? ? ? mem[16*1024:32*1024], > ? ? ? ? mem[32*1024:48*1024], > ? ? ? ? mem[48*1024:64*1024]] Those are just like pointers to the "mem" numpy array, pointing to concrete start indexes, aren't they? > To access the byte at address 42432, you'd have use bit operations to > get a page number and index (2 and 9664 in this case), then you can > access the memory like this: Do you mean: page = address / 16384 index = address MOD 16384 ? Or, better, with: page = address >> 14 index = address & 16383 ? > page[2][9664] = 33 > p = page[3][99] > > To swap a page, reassign the slice of main memory, > > page[2] = mem[96*1024:112*1024] > > Now, accessing address 42432 will access a byte from a different page. But the above calculations (page, index) wouldn't be slower than a simple play 64KB numpy array (and make no paging mechanism when reading or writing) and copy memory slices when page swappings are requested? > If you don't want to fiddle with indirect pages and would just rather > copy memory around when a page swap occurs, you can do that, too. > (Assigning to a slice copies the data rather than shares.) I don't > know if it's as fast as memset but it should be pretty quick. That's what I was talking about. With "page and index" I'm slowing down EACH memory read and write, and that includes opcode and data fetching... With "memory copying in page swaps", memory is always read and write quickly, and if "slice copies" are fast enough, the emulation will be >100% of speed (I hope) for a 3.5Mhz system ... > Hope these brief suggestions help. ?If you don't want third party > libraries, then numpy will be of no use. ?But I guess if you're using > pygame third party modules are ok. ?So get numpy, it'll make things a > lot easier. ?It can be a bit daunting to learn, though. Yes, you've been very helpful! How about numpy portability? Is array more portable? And finally, do you think I'm doing right by using global variables for registers, memory, and so, or should I put ALL into a single object and pass it to functions? Ummm ... I think I'm going to do some tests with some "for i in range (1,100000000000)" + time :-) Thanks a lot for your help :-) Any other suggestion is welcome. From no.email at please.post Thu Nov 12 09:38:19 2009 From: no.email at please.post (kj) Date: Thu, 12 Nov 2009 14:38:19 +0000 (UTC) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: In <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44 at p8g2000yqb.googlegroups.com> Carl Banks writes: >...but the lack of >inheritance is a doozie. That's what I like most about it. Inheritance introduces at least as many headaches as it solves. For one, it leads to spaghetti code. When reading such code, to follow any method call one must check in at least two places: the base class and the subclass. The deeper the inheritance chain, the more places one must check. For every method call. Yeecch. Good riddance. kj From casevh at gmail.com Thu Nov 12 09:38:40 2009 From: casevh at gmail.com (casevh) Date: Thu, 12 Nov 2009 06:38:40 -0800 (PST) Subject: C api and checking for integers References: Message-ID: <11dcc7b8-31a5-4245-8eda-a7cfa2f61d68@d9g2000prh.googlegroups.com> On Nov 12, 1:28?am, "lallous" wrote: > Hello, > > I am a little confused on how to check if a python variable is an integer or > not. > > Sometimes PyInt_Check() fails and PyLong_Check() succeeds. I assume you are using Python 2.x. There are two integer types: (1) PyInt which stores small values that can be stored in a single C long and (2) PyLong which stores values that may or may not fit in a single C long. The number 2 could arrive as either a PyInt or a PyLong. Try something like the following: if PyInt_CheckExact() myvar = PyInt_AS_LONG() else if PyLong_CheckExact() myvar = PyLong_As_Long() if ((myvar == -1) && (PyErr_Occurred()) # Too big to fit in a C long Python 3.x is a little easier since everything is a PyLong. > > How to properly check for integer values? > > OTOH, I tried PyNumber_Check() and: > > (1) The doc says: Returns 1 if the object o provides numeric protocols, and > false otherwise. This function always succeeds. > > What do they mean: "always succeeds" ? That it will always return true or false; it won't raise an error. > > (2) It seems PyNumber_check(py_val) returns true when passed an instance! > > Please advise. > > -- > Elias casevh From mcherm at gmail.com Thu Nov 12 10:07:23 2009 From: mcherm at gmail.com (mcherm) Date: Thu, 12 Nov 2009 07:07:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 11, 7:38?pm, Vincent Manis wrote: > 1. The statement `Python is slow' doesn't make any sense to me. > Python is a programming language; it is implementations that have > speed or lack thereof. [...] > 2. A skilled programmer could build an implementation that compiled > Python code into Common Lisp or Scheme code, and then used a > high-performance Common Lisp compiler... I think you have a fundamental misunderstanding of the reasons why Python is slow. Most of the slowness does NOT come from poor implementations: the CPython implementation is extremely well-optimized; the Jython and Iron Python implementations use best-in-the-world JIT runtimes. Most of the speed issues come from fundamental features of the LANGUAGE itself, mostly ways in which it is highly dynamic. In Python, a piece of code like this: len(x) needs to watch out for the following: * Perhaps x is a list OR * Perhaps x is a dict OR * Perhaps x is a user-defined type that declares a __len__ method OR * Perhaps a superclass of x declares __len__ OR * Perhaps we are running the built-in len() function OR * Perhaps there is a global variable 'len' which shadows the built-in OR * Perhaps there is a local variable 'len' which shadows the built-in OR * Perhaps someone has modified __builtins__ In Python it is possible for other code, outside your module to go in and modify or replace some methods from your module (a feature called "monkey-patching" which is SOMETIMES useful for certain kinds of testing). There are just so many things that can be dynamic (even if 99% of the time they are NOT dynamic) that there is very little that the compiler can assume. So whether you implement it in C, compile to CLR bytecode, or translate into Lisp, the computer is still going to have to to a whole bunch of lookups to make certain that there isn't some monkey business going on, rather than simply reading a single memory location that contains the length of the list. Brett Cannon's thesis is an example: he attempted desperate measures to perform some inferences that would allow performing these optimizations safely and, although a few of them could work in special cases, most of the hoped-for improvements were impossible because of the dynamic nature of the language. I have seen a number of attempts to address this, either by placing some restrictions on the dynamic nature of the code (but that would change the nature of the Python language) or by having some sort of a JIT optimize the common path where we don't monkey around. Unladen Swallow and PyPy are two such efforts that I find particularly promising. But it isn't NEARLY as simple as you make it out to be. -- Michael Chermside From victorsubervi at gmail.com Thu Nov 12 10:10:23 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:10:23 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911120710n4bdbffc3m4bd96307c2e848af@mail.gmail.com> On Wed, Nov 11, 2009 at 6:35 PM, Rhodri James wrote: > On Wed, 11 Nov 2009 14:00:44 -0000, Victor Subervi < > victorsubervi at gmail.com> wrote: > > 6) you don't indicate which user is executing this script (only root can >>> write to it) >>> >>> Help me on this. All scripts are owned by root. Is it not root that is >> executing the script? >> > > Not unless your server setup is very, very stupid. CGI scripts normally > run as a user with *very* limited permissions to limit (amongst other > things) the damage ineptly written scripts can do. > Thanks. I'll change it. V > > -- > Rhodri James *-* Wildebeest Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Thu Nov 12 10:10:24 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 12 Nov 2009 09:10:24 -0600 Subject: Why Error is derived from EnvironmentError in shutil.py? In-Reply-To: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> References: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> Message-ID: <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> On Thu, Nov 12, 2009 at 12:00 AM, alex23 wrote: > On Nov 12, 2:46?pm, Peng Yu wrote: >> I see Error is derived from EnvironmentError in shutil.py. >> >> class Error(EnvironmentError): >> ? ? pass >> >> I'm wondering why EnvironmentError can not be raised directly. Why >> Error is raised instead? > > This way you can explicitly trap on shutil.Error and not intercept any > other EnvironmentError that might be raised. > > And as it's a descendent of EnvironmentError, it can still be caught > by any handlers looking for such exceptions. It is true that an exception class is usually defined in a module and all the exceptions raised in this module should be of this derived class? Is it the general practice in python? From victorsubervi at gmail.com Thu Nov 12 10:12:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:12:43 -0500 Subject: CGI vs mod_python In-Reply-To: <4AFB1F73.5070508@ieee.org> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> <4AFB1F73.5070508@ieee.org> Message-ID: <4dc0cfea0911120712k28986b5amc11f8ebba4c99ff3@mail.gmail.com> On Wed, Nov 11, 2009 at 3:32 PM, Dave Angel wrote: > > > Victor Subervi wrote: > >> >> >> The problem was not CGI. It turned out to be line-endings being mangled by >> Windoze and __invisible __ in my unix editor. Lovely. >> Thanks anyway, >> V >> >> >> > That's twice you've blamed Windows for the line-ending problem. Windows > didn't create those crlf endings, your text editor did. If your editor > can't control that, you could try a different one. Komodo for example can > do it either way, or it can preserve whatever is being used in the loaded > file. Similarly metapad, in spite of its huge simplicity, lets you decide, > and can convert an existing file in either direction. > > And I'm a great believer in visible control characters. I configure Komodo > to show me spaces in the lines, so I can see whether it's a tab or a space. > It can also be configured to show end-of-line characters, so I presume > that'd work here. See whether your Unix editor can show you this sort of > thing. > > Finally, many FTP programs can be told to automatically convert > line-endings when transferring text files. There's probably some risk that > it'll mangle a non-text file, but it's worth considering. > Wonderful, wonderful. I'll take both of those pieces of advice. Thank you. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Nov 12 10:37:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Nov 2009 07:37:41 -0800 Subject: Why Error is derived from EnvironmentError in shutil.py? In-Reply-To: <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> References: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> Message-ID: <50697b2c0911120737p5b7999c6pe7a86d71352bab8c@mail.gmail.com> On Thu, Nov 12, 2009 at 7:10 AM, Peng Yu wrote: > On Thu, Nov 12, 2009 at 12:00 AM, alex23 wrote: >> On Nov 12, 2:46?pm, Peng Yu wrote: >>> I see Error is derived from EnvironmentError in shutil.py. >>> >>> class Error(EnvironmentError): >>> ? ? pass >>> >>> I'm wondering why EnvironmentError can not be raised directly. Why >>> Error is raised instead? >> >> This way you can explicitly trap on shutil.Error and not intercept any >> other EnvironmentError that might be raised. >> >> And as it's a descendent of EnvironmentError, it can still be caught >> by any handlers looking for such exceptions. > > It is true that an exception class is usually defined in a module and > all the exceptions raised in this module should be of this derived > class? Is it the general practice in python? It is common, but not universal. Several of the modules in the stdlib use the technique. Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Thu Nov 12 10:43:56 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:43:56 -0500 Subject: (OT) Recommend FTP Client Message-ID: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Hi; Someone on this list just recommended I find an ftp client that enables me to change line endings. He indicated that it would be easy, but googling I haven't been able to find one. I would prefer a free client, but whatever. Please send me a recommendation. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Nov 12 10:44:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 16:44:13 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> Message-ID: <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 6:07 pm, "Diez B. Roggisch" wrote: >>> ok let me make it more clear.. >>> forget how you use python now.. i am talking about __futuristic__ >>> python programming. >>> there is no more python2.x or python3.x or python y.x releases. there >>> is only updates of python and standard library say 1.1.5 and 1.1.6. >>> let the difference be an old xml library updated with a new regex >>> support. >>> i am coding my program now. >>> i want my application to be compatible with 1.1.5 library >>> use library 1.1.5 >>> import blah form blahblah >>> ... >>> ... >>> i cannot use regex feature of xml in this application >>> i then update my library in the evening >>> now both the libraries are present in my system. >>> now i try using the new feature >>> use library 1.1.6 #thats all now i get all features >>> import blah from blahblah >> This is not futuristic, this is state of the art with PyPI & setuptools. >> >> You still haven't addressed all the issues that arise though, regarding >> different python interpreter versions having different syntax and ABI. >> >> Diez > > haha... it would be awesome if they implement it in the 'future' .. i > posted the same to python-dev at python.org, it seems the distutil is > getting a big overhaul. (i hope they make a new uninstall option for > setuptools n easy_install) they say there are many ways to do that > using pkg tools... but python wants one and only one way- the python > way. > regarding issues: > > 1.security is always a issue > 2. regarding problems like with statement you mentioned earlier.. i > think there will be a basic feature set that is common for all > versions of add-on libraries. So all libraries written have to use the common subset, which - unless things are *removed*, which with python3 actually happened - is always the oldest interpreter. And if a feature goes away, they have to be rewritten with the then common subset. In other words: as a library writer, I can't use shiny, new & better features, I'm stuck with the old stuff, and whenever the intepreter evolves I have to rewrite even the old ones. Not appealing. Why develop the interpreter at all then? > 3.when you want the new feature you have to update your python > interpreter > > use interpreter 1.5.2 > > may trigger the proper interpreter plugin(responsible for additional > feature) to load and add functionality.. its simple to say but it is > hard to make the compiler pluggable, may be they figure out. > > > use library x.y.z > > while issuing this command the default interpreter has to > automatically resolve dependencies of the core c/cpp static libraries > and other shared libraries. so that must not be an issue. if they have > implemented this much, dep solving is nothing. In other words: the problem is solved by somehow solving the problem - but not by a concrete solution you propose? > > futuristic python may also contain an option for compiling a module > into a static library. so we can code python libraries in python > (mostly) itself. think of pypy. it is already state of the art. PyPy is cool, but by far not advanced enough to replace external, C-based libraries such as NUMPY and PyQt and whatnot. I don't say that the current situation is by any means ideal. There is a lot to be said about package creation, distribution, installation, removal, dependency handling, and even system-packaging-integration if one likes. You IMHO just add another layer of complexity on top of it, without proposing solutions to any of the layers in between, nor your new one - namely, the interpreter version agnosticism. Diez From callmeclaudius at gmail.com Thu Nov 12 11:35:23 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Thu, 12 Nov 2009 08:35:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 12, 10:07?am, mcherm wrote: > On Nov 11, 7:38?pm, Vincent Manis wrote: > > > 1. The statement `Python is slow' doesn't make any sense to me. > > Python is a programming language; it is implementations that have > > speed or lack thereof. > ? ?[...] > > 2. A skilled programmer could build an implementation that compiled > > Python code into Common Lisp or Scheme code, and then used a > > high-performance Common Lisp compiler... > > I think you have a fundamental misunderstanding of the reasons why > Python is > slow. Most of the slowness does NOT come from poor implementations: > the CPython > implementation is extremely well-optimized; the Jython and Iron Python > implementations use best-in-the-world JIT runtimes. Most of the speed > issues > come from fundamental features of the LANGUAGE itself, mostly ways in > which > it is highly dynamic. > > In Python, a piece of code like this: > ? ? len(x) > needs to watch out for the following: > ? ? * Perhaps x is a list OR > ? ? ? * Perhaps x is a dict OR > ? ? ? * Perhaps x is a user-defined type that declares a __len__ > method OR > ? ? ? * Perhaps a superclass of x declares __len__ OR > ? ? * Perhaps we are running the built-in len() function OR > ? ? ? * Perhaps there is a global variable 'len' which shadows the > built-in OR > ? ? ? * Perhaps there is a local variable 'len' which shadows the > built-in OR > ? ? ? * Perhaps someone has modified __builtins__ > > In Python it is possible for other code, outside your module to go in > and > modify or replace some methods from your module (a feature called > "monkey-patching" which is SOMETIMES useful for certain kinds of > testing). > There are just so many things that can be dynamic (even if 99% of the > time > they are NOT dynamic) that there is very little that the compiler can > assume. > > So whether you implement it in C, compile to CLR bytecode, or > translate into > Lisp, the computer is still going to have to to a whole bunch of > lookups to > make certain that there isn't some monkey business going on, rather > than > simply reading a single memory location that contains the length of > the list. > Brett Cannon's thesis is an example: he attempted desperate measures > to > perform some inferences that would allow performing these > optimizations > safely and, although a few of them could work in special cases, most > of the > hoped-for improvements were impossible because of the dynamic nature > of the > language. > > I have seen a number of attempts to address this, either by placing > some > restrictions on the dynamic nature of the code (but that would change > the > nature of the Python language) or by having some sort of a JIT > optimize the > common path where we don't monkey around. Unladen Swallow and PyPy are > two > such efforts that I find particularly promising. > > But it isn't NEARLY as simple as you make it out to be. > > -- Michael Chermside obviously the GIL is a major reason it's so slow. That's one of the _stated_ reasons why Google has decided to forgo CPython code. As far as how sweeping the directive is, I don't know, since the situation would sort of resolve itself if one committed to Jython application building or just wait until unladen swallow is finished. From davea at ieee.org Thu Nov 12 11:40:12 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 11:40:12 -0500 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <4AFC3A6C.4090505@ieee.org> Santiago Romero wrote: >>> I'm trying to port (just for fun), my old Sinclair Spectrum emulator, >>> A >> > Do you mean: > > page =ddress / 16384 > index =ddress MOD 16384 > > ? > > Or, better, with: > > page =ddress >> 14 > index =ddress & 16383 > > ? > > How about page, index = divmod(address, 16384) From sromero at gmail.com Thu Nov 12 11:43:29 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 08:43:29 -0800 (PST) Subject: #define (from C) in Python Message-ID: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Is there a Python version of C's language #define statements? Example: #define ReadMem( (x) ) memory[ (x) ] Instead of using a function, when you call to ReadMem(), the code is INCLUDED, (no function is called, the "compiler" just substitues the ReadMem( expression ) with memory[ (expression) ] . I want to avoid function calls to speed up a program by sacrifizing the resulting size ... Is that possible? From sromero at gmail.com Thu Nov 12 11:44:45 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 08:44:45 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: > How about > ? ? page, index = divmod(address, 16384) Surely, much better and faster :-) Thanks a lot. From deets at nospam.web.de Thu Nov 12 11:45:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 17:45:15 +0100 Subject: #define (from C) in Python In-Reply-To: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <7m2scsF3gfnc5U1@mid.uni-berlin.de> Santiago Romero schrieb: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) memory[ (x) ] > > Instead of using a function, when you call to ReadMem(), the code is > INCLUDED, (no function is called, the "compiler" just substitues the > ReadMem( expression ) with memory[ (expression) ] . > > I want to avoid function calls to speed up a program by sacrifizing > the resulting size ... > > Is that possible? Not without taking the extra step of a ... preprocessor. As C does. Diez From michele.simionato at gmail.com Thu Nov 12 11:53:26 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 08:53:26 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <592ed6b8-9c6b-4fad-ae75-693068033ae8@k17g2000yqh.googlegroups.com> On Nov 12, 5:43?pm, Santiago Romero wrote: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) ? ?memory[ (x) ] > > ?Instead of using a function, when you call to ReadMem(), the code is > INCLUDED, (no function is called, the "compiler" just substitues the > ReadMem( expression ) with memory[ (expression) ] . > > ?I want to avoid function calls to speed up a program by sacrifizing > the resulting size ... > > ?Is that possible? Python is a slow language and people usually do not even think of such micro-optimizations. From naughtysriram at gmail.com Thu Nov 12 12:05:06 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 09:05:06 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Message-ID: > So all libraries written have to use the common subset, which - unless > things are *removed*, which with python3 actually happened - is always > the oldest interpreter. And if a feature goes away, they have to be > rewritten with the then common subset. you see that's the problem with py3. instead of slowly removing the features one by one till the end they made a jump. the problem is not with the jump but with other libraries/packages that depend on py2. what i felt was if the new version was available as soon as it is into the stream, developers/users try to use them and get accustomed. now they follow this. they have frozen py3 for may be 2-3 years so ppl would move slowly to py2.6 ,2.7, 2.8... most. also the corporate companies are the most influential. also a point to note: if new updates keep on coming (for eg. daily antivirus update) developers tend to accept and move on *easily*. i am not an expert in programming/interpreter design/library writing/ packaging. i just wanted the standard library *too* to be pluggable, not just the applications based on it. i am not even experienced in python to make bold accusations so all i can say is 'how it would be if?' and i always stick to one thing 'why not?'. > In other words: as a library writer, I can't use shiny, new & better > features, I'm stuck with the old stuff, and whenever the interpreter > evolves I have to rewrite even the old ones. Not appealing. Why develop > the interpreter at all then? if you are app developer you needn't rewrite anything. that is the main point here! just specifying the interpreter and library version is enough every thing has to work like magic. as the previous library&interpreter wont be removed (unless and until it is your will) u can use them. thats how everybody would like it to be. as for a library writer is concerned: as you say it depends on certain things like other libraries,interpreter,etc. but i would like to say that change is inevitable. if some core developer has to change something he might change. and if you have to update your library you have to. this applies to the interpreter too. what python now does is make every update work with the minimal set (giving minimal backward compatibility) plus the new features too. which is exactly the right thing. what i wanted is the users have to be aware now and then when of the modification, deletion, addition stuff not in every release as in py3k. then the whole backward incompatibility issue would be *dissolved* or what i mean is *diffused* and ppl dont even know that they have switched over to a very new thing. > In other words: the problem is solved by somehow solving the problem - > but not by a concrete solution you propose? as i told before i neither know the problem nor the solution. i just wrote my ideas/imagination down > PyPy is cool, but by far not advanced enough to replace external, > C-based libraries such as NUMPY and PyQt and whatnot. > > I don't say that the current situation is by any means ideal. There is a > lot to be said about package creation, distribution, installation, > removal, dependency handling, and even system-packaging-integration if > one likes. > > You IMHO just add another layer of complexity on top of it, without > proposing solutions to any of the layers in between, nor your new one - > namely, the interpreter version agnosticism. yes you are right. python has a lot of bindings to a lot of stuff. but it is the strength and weakness. not exactly pythons weakness but with the thing on the other side. yes it may be looking complex because most of the 'standard library' system was not designed to be adhoc/add- on/pluggable from the start. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 12:12:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 17:12:53 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <0085c660$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 08:35:23 -0800, Joel Davis wrote: > obviously the GIL is a major reason it's so slow. No such "obviously" about it. There have been attempts to remove the GIL, and they lead to CPython becoming *slower*, not faster, for the still common case of single-core processors. And neither Jython nor IronPython have the GIL. Jython appears to scale slightly better than CPython, but for small data sets, is slower than CPython. IronPython varies greatly in performance, ranging from nearly twice as fast as CPython on some benchmarks to up to 6000 times slower! http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/ http://ironpython-urls.blogspot.com/2009/05/python-jython-and-ironpython.html Blaming CPython's supposed slowness on the GIL is superficially plausible but doesn't stand up to scrutiny. The speed of an implementation depends on many factors, and it also depends on *what you measure* -- it is sheer nonsense to talk about "the" speed of an implementation. Different tasks run at different speeds, and there is no universal benchmark. -- Steven From stefan_ml at behnel.de Thu Nov 12 12:16:02 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 12 Nov 2009 18:16:02 +0100 Subject: #define (from C) in Python In-Reply-To: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Santiago Romero, 12.11.2009 17:43: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) memory[ (x) ] Yes: ReadMem = memory.__getitem__ Stefan From fetchinson at googlemail.com Thu Nov 12 12:21:58 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 12 Nov 2009 18:21:58 +0100 Subject: ask a question about the module In-Reply-To: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> References: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> Message-ID: > Could not import module "Gnuplot" - it is not installed on your > system. You need to install the Gnuplot.py package. > \easyviz\gnuplot_.py(41) : > Traceback (most recent call last): > File "E:\study\python\commodity modle 10.23.py", line 3, in > import multipleloop as mp > File "E:\study\python\multipleloop.py", line 81, in > from scitools.misc import str2obj > File "C:\Python26\lib\site-packages\scitools\__init__.py", line 67, > in > import sys, std > File "C:\Python26\lib\site-packages\scitools\std.py", line 26, in > > from scitools.easyviz import * > File "C:\Python26\lib\site-packages\scitools\easyviz\__init__.py", > line 1819, in > exec(cmd) > File "", line 1, in > File "C:\Python26\lib\site-packages\scitools\easyviz\gnuplot_.py", > line 42, in > import Gnuplot > ImportError: No module named Gnuplot > > > the above is the hint from python window, I know Gnuplot is a software > and it can help us to make graphs, however, after I download Gnuplot > and run it, the problem still exist. Is there any expert can help me > solve this problem? > Thank you very much! Did you also install the python bindings for gnuplot? If not, you can get it from http://gnuplot-py.sourceforge.net/ HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From sromero at gmail.com Thu Nov 12 12:23:23 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:23:23 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On 12 nov, 18:16, Stefan Behnel wrote: > Santiago Romero, 12.11.2009 17:43: > > > Is there a Python version of C's language #define statements? > > > Example: > > > #define ReadMem( (x) ) ? ?memory[ (x) ] > > Yes: > > ? ? ? ? ReadMem = memory.__getitem__ > > Stefan Well, In the above concrete example, that would work, but I was talking for multiple code lines, like: #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ r_oph = Z80ReadMem(r_PC); r_PC++; \ reg = r_op #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ r_oph = Z80ReadMem(r_PC); r_PC++; \ r_tmpl = Z80ReadMem(r_op); \ r_tmph = Z80ReadMem((r_op)+1); \ dreg=r_tmp #define STORE_nn_rr(dreg) \ r_opl = Z80ReadMem(r_PC); r_PC++;\ r_oph = Z80ReadMem(r_PC); r_PC++; \ r_tmp = dreg; \ Z80WriteMem((r_op),r_tmpl, regs); \ Z80WriteMem((r_op+1),r_tmph, regs) But it seems that is not possible :-( From alfps at start.no Thu Nov 12 12:32:28 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 18:32:28 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: <0085c660$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 12 Nov 2009 08:35:23 -0800, Joel Davis wrote: > >> obviously the GIL is a major reason it's so slow. http://en.wikipedia.org/wiki/Global_Interpreter_Lock Uh oh... > No such "obviously" about it. > > There have been attempts to remove the GIL, and they lead to CPython > becoming *slower*, not faster, for the still common case of single-core > processors. > > And neither Jython nor IronPython have the GIL. Jython appears to scale > slightly better than CPython, but for small data sets, is slower than > CPython. IronPython varies greatly in performance, ranging from nearly > twice as fast as CPython on some benchmarks to up to 6000 times slower! > > http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/ > > http://ironpython-urls.blogspot.com/2009/05/python-jython-and-ironpython.html > > > Blaming CPython's supposed slowness Hm, this seems religious. Of course Python is slow: if you want speed, pay for it by complexity. It so happens that I think CPython could have been significantly faster, but (1) doing that would amount to creating a new implementation, say, C++Python , and (2) what for, really?, since CPU-intensive things should be offloaded to other language code anyway. > on the GIL is superficially plausible > but doesn't stand up to scrutiny. The speed of an implementation depends > on many factors, and it also depends on *what you measure* -- it is sheer > nonsense to talk about "the" speed of an implementation. Different tasks > run at different speeds, and there is no universal benchmark. This also seems religious. It's like in Norway it became illegal to market lemon soda, since umpteen years ago it's soda with lemon flavoring. This has to do with the *origin* of the citric acid, whether natural or chemist's concoction, no matter that it's the same chemical. So, some people think that it's wrong to talk about interpreted languages, hey, it should be a "language designed for interpretation", or better yet, "dynamic language", or bestest, "language with dynamic flavor". And slow language, oh no, should be "language whose current implementations are perceived as somewhat slow by some (well, all) people", but of course, that's just silly. Cheers, - Alf From james at agentultra.com Thu Nov 12 12:33:36 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 12 Nov 2009 12:33:36 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <87my2r7imn.fsf@agentultra.com> mcherm writes: > On Nov 11, 7:38?pm, Vincent Manis wrote: >> 1. The statement `Python is slow' doesn't make any sense to me. >> Python is a programming language; it is implementations that have >> speed or lack thereof. > [...] >> 2. A skilled programmer could build an implementation that compiled >> Python code into Common Lisp or Scheme code, and then used a >> high-performance Common Lisp compiler... > > I think you have a fundamental misunderstanding of the reasons why > Python is > slow. Most of the slowness does NOT come from poor implementations: > the CPython > implementation is extremely well-optimized; the Jython and Iron Python > implementations use best-in-the-world JIT runtimes. Most of the speed > issues > come from fundamental features of the LANGUAGE itself, mostly ways in > which > it is highly dynamic. > > In Python, a piece of code like this: > len(x) > needs to watch out for the following: > * Perhaps x is a list OR > * Perhaps x is a dict OR > * Perhaps x is a user-defined type that declares a __len__ > method OR > * Perhaps a superclass of x declares __len__ OR > * Perhaps we are running the built-in len() function OR > * Perhaps there is a global variable 'len' which shadows the > built-in OR > * Perhaps there is a local variable 'len' which shadows the > built-in OR > * Perhaps someone has modified __builtins__ > > In Python it is possible for other code, outside your module to go in > and > modify or replace some methods from your module (a feature called > "monkey-patching" which is SOMETIMES useful for certain kinds of > testing). > There are just so many things that can be dynamic (even if 99% of the > time > they are NOT dynamic) that there is very little that the compiler can > assume. > > So whether you implement it in C, compile to CLR bytecode, or > translate into > Lisp, the computer is still going to have to to a whole bunch of > lookups to > make certain that there isn't some monkey business going on, rather > than > simply reading a single memory location that contains the length of > the list. > Brett Cannon's thesis is an example: he attempted desperate measures > to > perform some inferences that would allow performing these > optimizations > safely and, although a few of them could work in special cases, most > of the > hoped-for improvements were impossible because of the dynamic nature > of the > language. > > I have seen a number of attempts to address this, either by placing > some > restrictions on the dynamic nature of the code (but that would change > the > nature of the Python language) or by having some sort of a JIT > optimize the > common path where we don't monkey around. Unladen Swallow and PyPy are > two > such efforts that I find particularly promising. > > But it isn't NEARLY as simple as you make it out to be. > > -- Michael Chermside You might be right for the wrong reasons in a way. Python isn't slow because it's a dynamic language. All the lookups you're citing are highly optimized hash lookups. It executes really fast. The OP is talking about scale. Some people say Python is slow at a certain scale. I say that's about true for any language. Large amounts of IO is a tough problem. Where Python might get hit *as a language* is that the Python programmer has to drop into C to implement optimized data-structures for dealing with the kind of IO that would slow down the Python interpreter. That's why we have numpy, scipy, etc. The special cases it takes to solve problems with custom types wasn't special enough to alter the language. Scale is a special case believe it or not. As an implementation though, the sky really is the limit and Python is only getting started. Give it another 40 years and it'll probably realize that it's just another Lisp. ;) From stefan_ml at behnel.de Thu Nov 12 12:34:09 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 12 Nov 2009 18:34:09 +0100 Subject: #define (from C) in Python In-Reply-To: References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> Santiago Romero, 12.11.2009 18:23: > #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) > > #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > reg = r_op > > #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) > > #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmpl = Z80ReadMem(r_op); \ > r_tmph = Z80ReadMem((r_op)+1); \ > dreg=r_tmp > > #define STORE_nn_rr(dreg) \ > r_opl = Z80ReadMem(r_PC); r_PC++;\ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmp = dreg; \ > Z80WriteMem((r_op),r_tmpl, regs); \ > Z80WriteMem((r_op+1),r_tmph, regs) > > But it seems that is not possible :-( As Michele said, this is a micro optimisation, likely premature. A function is usually good enough for this. If you need more speed (and you seem to be targeting direct memory access or something like that), take a look at Cython. Stefan From sromero at gmail.com Thu Nov 12 12:41:47 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:41:47 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <6ebe56b4-e43e-44bb-b5d3-12b7acd40fbc@u7g2000yqm.googlegroups.com> > You can do clever memory slicing like this with numpy. ?For instance: > > breg = numpy.zeros((16,),numpy.uint8) > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > This causes breg and wreg to share the same 16 bytes of memory. ?You > can define constants to access specific registers: What I'm doing wrong? [sromero at compiler:~]$ cat test.py #!/usr/bin/python import numpy # Register array breg = numpy.zeros((16,),numpy.uint8) wreg = numpy.ndarray((8,), numpy.uint16, breg ) reg_A = 1 reg_F = 2 reg_AF = 1 reg_B = 3 reg_C = 4 reg_BC = 3 breg[reg_B] = 5 breg[reg_C] = 10 print breg[reg_B] print breg[reg_C] print wreg[reg_BC] [sromero at compiler:~]$ python test.py 5 10 0 ? From warpcat at sbcglobal.net Thu Nov 12 12:49:53 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 09:49:53 -0800 (PST) Subject: How can a module know the module that imported it? References: <008592ec$0$26916$c3e8da3@news.astraweb.com> Message-ID: <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> so: # moduleA.py import moduleB # moduleB.py import sys stuff = sys._getframe(1).f_locals print stuff Prints: {'__builtins__': , '__file__': 'C:\\Documents and Settings\\\\My Documents\ \python\\moduleA.py', '__name__': '__main__', '__doc__': None} Looks like you could query stuff['__file__'] to pull what you're after. ? From sromero at gmail.com Thu Nov 12 12:51:50 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:51:50 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <6ebe56b4-e43e-44bb-b5d3-12b7acd40fbc@u7g2000yqm.googlegroups.com> Message-ID: <4b1370fa-373c-463a-8f50-3e8c3411dc62@g23g2000yqh.googlegroups.com> Oops, numpy arrays start with index=0 :-) From benjamin.kaplan at case.edu Thu Nov 12 13:05:45 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 13:05:45 -0500 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Message-ID: On Thu, Nov 12, 2009 at 12:05 PM, Sriram Srinivasan wrote: >> So all libraries written have to use the common subset, which - unless >> things are *removed*, which with python3 actually happened - is always >> the oldest interpreter. And if a feature goes away, they have to be >> rewritten with the then common subset. > > you see that's the problem with py3. instead of slowly removing the > features one by one till the end they made a jump. the problem is not > with the jump but with other libraries/packages that depend on py2. > what i felt was if the new version was available as soon as it is into > the stream, developers/users try to use them and get accustomed. now > they follow this. they have frozen py3 for may be 2-3 years so ppl > would move slowly to py2.6 ,2.7, 2.8... most. also the corporate > companies are the most influential. > The freeze was put in place so that the other implementations of Python, like Jython and IronPython, have a chance to catch up with the reference CPython implementation. It's not so people will slowly move up. FWIW, people knew for years what was going to change in Python 3. > also a point to note: if new updates keep on coming (for eg. daily > antivirus update) developers tend to accept and move on *easily*. > > i am not an expert in programming/interpreter design/library writing/ > packaging. i just wanted the standard library *too* to be pluggable, > not just the applications based on it. > i am not even experienced in python to make bold accusations so all i > can say is 'how it would be if?' and i always stick to one thing 'why > not?'. > >> In other words: as a library writer, I can't use shiny, new & better >> features, I'm stuck with the old stuff, and whenever the interpreter >> evolves I have to rewrite even the old ones. Not appealing. Why develop >> the interpreter at all then? > > if you are app developer you needn't rewrite anything. that is the > main point here! just specifying the interpreter and library version > is enough every thing has to work like magic. as the previous > library&interpreter wont be removed (unless and until it is your will) > u can use them. thats how everybody would like it to be. > So you're saying that we'd have multiple versions of the interpreter running at the same time, but they all have access to the same memory. That wouldn't just require a change to Python, that would require a change to the way all modern operating systems work. > as for a library writer is concerned: as you say it depends on certain > things like other libraries,interpreter,etc. but i would like to say > that change is inevitable. if some core developer has to change > something he might change. and if you have to update your library you > have to. this applies to the interpreter too. what python now does is > make every update work with the minimal set (giving minimal backward > compatibility) plus the new features too. which is exactly the right > thing. what i wanted is the users have to be aware now and then when > of the modification, deletion, addition stuff not in every release as > in py3k. then the whole backward incompatibility issue would be > *dissolved* or what i mean is *diffused* and ppl dont even know that > they have switched over to a very new thing. > > Actually, that's not entirely true. New versions to break things Consider these statements as = ['a','a','a'] with = [1,2,3] It's legal in Python 2.4 or earlier, a warning in Python 2.5, but illegal in Python 2.6 > >> In other words: the problem is solved by somehow solving the problem - >> but not by a concrete solution you propose? > > as i told before i neither know the problem nor the solution. i just > wrote my ideas/imagination down > >> PyPy is cool, but by far not advanced enough to replace external, >> C-based libraries such as NUMPY and PyQt and whatnot. >> >> I don't say that the current situation is by any means ideal. There is a >> lot to be said about package creation, distribution, installation, >> removal, dependency handling, and even system-packaging-integration if >> one likes. >> >> You IMHO just add another layer of complexity on top of it, without >> proposing solutions to any of the layers in between, nor your new one - >> namely, the interpreter version agnosticism. > > yes you are right. python has a lot of bindings to a lot of stuff. but > it is the strength and weakness. not exactly pythons weakness but with > the thing on the other side. yes it may be looking complex because > most of the 'standard library' system was not designed to be adhoc/add- > on/pluggable from the start. It is pluggable. The standard library consists of Python modules like any other. 2.6's multiprocessing module is just an incorporation of the pyprocessing module for instance. The point of the standard library is that you can count on it being there, and you can count on it having certain features, given your interpreter version. You can also be sure that anytime a new version of Python comes out, those modules will be compatible. > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Thu Nov 12 13:10:53 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 Nov 2009 10:10:53 -0800 Subject: How can a module know the module that imported it? In-Reply-To: <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> References: <008592ec$0$26916$c3e8da3@news.astraweb.com> <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> Message-ID: <4AFC4FAD.50307@stoneleaf.us> AK Eric wrote: > so: > > # moduleA.py > import moduleB > > # moduleB.py > import sys > stuff = sys._getframe(1).f_locals > print stuff > > Prints: > > {'__builtins__': , > '__file__': 'C:\\Documents and Settings\\\\My Documents\ > \python\\moduleA.py', > '__name__': '__main__', > '__doc__': None} > > Looks like you could query stuff['__file__'] to pull what you're > after. > ? The leading _ in _getframe indicates a private function to sys (aka implementation detail); in other words, something that could easily change between one Python version and the next. I'm using the inspect module (for the moment, at least), and my question boils down to: Will it work correctly on all versions of Python in the 2.x range? 3.x range? ~Ethan~ From warpcat at sbcglobal.net Thu Nov 12 13:35:55 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 10:35:55 -0800 (PST) Subject: How can a module know the module that imported it? References: <008592ec$0$26916$c3e8da3@news.astraweb.com> <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> Message-ID: On Nov 12, 10:10?am, Ethan Furman wrote: > AK Eric wrote: > > so: > > > # moduleA.py > > import moduleB > > > # moduleB.py > > import sys > > stuff = sys._getframe(1).f_locals > > print stuff > > > Prints: > > > {'__builtins__': , > > '__file__': 'C:\\Documents and Settings\\\\My Documents\ > > \python\\moduleA.py', > > '__name__': '__main__', > > '__doc__': None} > > > Looks like you could query stuff['__file__'] to pull what you're > > after. > > ? > > The leading _ in _getframe indicates a private function to sys (aka > implementation detail); in other words, something that could easily > change between one Python version and the next. > > I'm using the inspect module (for the moment, at least), and my question > boils down to: ?Will it work correctly on all versions of Python in the > 2.x range? ?3.x range? > Good point, I totally missed that. Someone had passed that solution to me at one point and I was so excited I kind of looked that over :P From mark.kecko at gmail.com Thu Nov 12 13:39:33 2009 From: mark.kecko at gmail.com (scoopseven) Date: Thu, 12 Nov 2009 10:39:33 -0800 (PST) Subject: QuerySets in Dictionaries Message-ID: I need to create a dictionary of querysets. I have code that looks like: query1 = Myobject.objects.filter(status=1) query2 = Myobject.objects.filter(status=2) query3 = Myobject.objects.filter(status=3) d={} d['a'] = query1 d['b'] = query2 d['c'] = query3 Is there a way to do this that I'm missing? Thanks. From python.list at tim.thechases.com Thu Nov 12 13:58:08 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Nov 2009 12:58:08 -0600 Subject: (OT) Recommend FTP Client In-Reply-To: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Message-ID: <4AFC5AC0.9000900@tim.thechases.com> > Someone on this list just recommended I find an ftp client that enables me > to change line endings. He indicated that it would be easy, but googling I > haven't been able to find one. I would prefer a free client, but whatever. > Please send me a recommendation. How about the command line client that comes with every modern OS? Just use the ASCII (default) and BIN commands to switch between line-ending translation. -tkc From rami.chowdhury at gmail.com Thu Nov 12 13:58:49 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 10:58:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach wrote: > > This also seems religious. It's like in Norway it became illegal to > market lemon soda, since umpteen years ago it's soda with lemon > flavoring. This has to do with the *origin* of the citric acid, whether > natural or chemist's concoction, no matter that it's the same chemical. > So, some people think that it's wrong to talk about interpreted > languages, hey, it should be a "language designed for interpretation", > or better yet, "dynamic language", or bestest, "language with dynamic > flavor". And slow language, oh no, should be "language whose current > implementations are perceived as somewhat slow by some (well, all) > people", but of course, that's just silly. Perhaps I'm missing the point of what you're saying but I don't see why you're conflating interpreted and dynamic here? Javascript is unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically JIT it. Does that make Javascript non-dynamic, because it's compiled? What about Common Lisp, which is a compiled language when it's run with CMUCL or SBCL? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From bigboss1964 at gmail.com Thu Nov 12 14:01:48 2009 From: bigboss1964 at gmail.com (TerryP) Date: Thu, 12 Nov 2009 11:01:48 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> If it's such a big hairy deal, just recompile a copy of the C Pre Processor to use something other then #, and hook it up to your python scripts in a pipe line from a shell wrapper. Personally, I'd rather have Lisps lambda or perls sub then Cs preprocessor, and even in those cases, Python suffices perfectly fine ;). From simon at brunningonline.net Thu Nov 12 14:06:33 2009 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 12 Nov 2009 19:06:33 +0000 Subject: QuerySets in Dictionaries In-Reply-To: References: Message-ID: <8c7f10c60911121106l58ff77fbpd88f44b42e15439b@mail.gmail.com> 2009/11/12 scoopseven : > I need to create a dictionary of querysets. ?I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? Untested: wanted = (('a', 1), ('b', 2), ('c', 2)) d = dict((key, Myobject.objects.filter(status=number)) for (key, number) in wanted) -- Cheers, Simon B. From deets at nospam.web.de Thu Nov 12 14:08:26 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 20:08:26 +0100 Subject: QuerySets in Dictionaries In-Reply-To: References: Message-ID: <7m34p9F3df2blU1@mid.uni-berlin.de> scoopseven schrieb: > I need to create a dictionary of querysets. I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? d = dict(a=Myobject.objects.filter(status=1), b=Myobject.objects.filter(status=2), c=Myobject.objects.filter(status=3)) Diez From mrholtsr at sbcglobal.net Thu Nov 12 14:11:45 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Thu, 12 Nov 2009 14:11:45 -0500 Subject: Computing the 1000th prime Message-ID: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> I have an assigment to find the 1000th. prime using python. What's wrong with the following code: PrimeCount = 0 PrimeCandidate = 1 while PrimeCount < 2000: IsPrime = True PrimeCandidate = PrimeCandidate + 2 for x in range(2, PrimeCandidate): if PrimeCandidate % x == 0: ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x print PrimeCandidate IsPrime = False break if IsPrime: PrimeCount = PrimeCount + 1 PrimeCandidate = PrimeCandidate + 2 print PrimeCandidate Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 12 14:17:16 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:17:16 +0000 Subject: regex remove closest tag In-Reply-To: References: Message-ID: <4AFC5F3C.6010302@mrabarnett.plus.com> S.Selvam wrote: > Hi all, > > > 1) I need to remove the tags which is just before the keyword(i.e > some_text2 ) excluding others. > > 2) input string may or may not contain tags. > > 3) Sample input: > > inputstr = """start some_text1 href="">some_text2 keyword anything""" > > 4) I came up with the following regex, > > > p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) > s=p.search(inputstr) > but second group matches both tags,while i need to match the > recent one only. > > I would like to get your suggestions. > > Note: > > If i leave group('good1') as greedy, then it matches both the tag. > ".*?" can match any number of any character, so it can match any intervening "" tags. Try "[^<]*?" instead. From alfps at start.no Thu Nov 12 14:24:18 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 20:24:18 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach > wrote: >> >> This also seems religious. It's like in Norway it became illegal to >> market lemon soda, since umpteen years ago it's soda with lemon >> flavoring. This has to do with the *origin* of the citric acid, >> whether natural or chemist's concoction, no matter that it's the same >> chemical. So, some people think that it's wrong to talk about >> interpreted languages, hey, it should be a "language designed for >> interpretation", or better yet, "dynamic language", or bestest, >> "language with dynamic flavor". And slow language, oh no, should be >> "language whose current implementations are perceived as somewhat slow >> by some (well, all) people", but of course, that's just silly. > > Perhaps I'm missing the point of what you're saying but I don't see why > you're conflating interpreted and dynamic here? Javascript is unarguably > a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically > JIT it. Does that make Javascript non-dynamic, because it's compiled? > What about Common Lisp, which is a compiled language when it's run with > CMUCL or SBCL? Yeah, you missed it. Blurring and coloring and downright hiding reality by insisting on misleading but apparently more precise terminology for some vague concept is a popular sport, and chiding others for using more practical and real-world oriented terms, can be effective in politics and some other arenas. But in a technical context it's silly. Or dumb. Whatever. E.g. you'll find it impossible to define interpretation rigorously in the sense that you're apparently thinking of. It's not that kind of term or concept. The nearest you can get is in a different direction, something like "a program whose actions are determined by data external to the program (+ x qualifications and weasel words)", which works in-practice, conceptually, but try that on as a rigorous definition and you'll see that when you get formal about it then it's completely meaningless: either anything qualifies or nothing qualifies. You'll also find it impossible to rigorously define "dynamic language" in a general way so that that definition excludes C++. So, to anyone who understands what one is talking about, "interpreted", or e.g. "slow language" (as was the case here), conveys the essence. And to anyone who doesn't understand it trying to be more precise is an exercise in futility and pure silliness -- except for the purpose of misleading. Cheers & hth., - Alf From davea at ieee.org Thu Nov 12 14:26:50 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 14:26:50 -0500 Subject: (OT) Recommend FTP Client In-Reply-To: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Message-ID: <4AFC617A.2070201@ieee.org> Victor Subervi wrote: > Hi; > Someone on this list just recommended I find an ftp client that enables me > to change line endings. He indicated that it would be easy, but googling I > haven't been able to find one. I would prefer a free client, but whatever. > Please send me a recommendation. > TIA, > Victor > > Try http://fireftp.mozdev.org/ fireftp is an (free) addon to Firefox. If you're already using Firefox, it's painless to download it, and easy to use. You can set up account(s) complete with passwords and default directories, and then transfer individual files or directory trees full just by selecting and pressing the Arrow icons (one for upload, one for download). You can sort by timestamp, so it's not hard to just transfer new stuff. One of the Tools->Options tabs is "Downloads/Uploads". First box looks like: When transferring files use: o - Automatic mode o - Binary mode o - ASCII mode According to the help, Automatic mode is very useful for CGI scripts, where you specify which extensions will get the line-endings converted. http://fireftp.mozdev.org/help.html But please understand: I personally use Binary mode in FireFTP because I'm a control freak. Python can handle Unix line-endings just fine, so any files that are bound for CGI I just edit in that mode in the first place. DaveA From python at mrabarnett.plus.com Thu Nov 12 14:30:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:30:01 +0000 Subject: python with echo In-Reply-To: References: Message-ID: <4AFC6239.40905@mrabarnett.plus.com> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > >> List, >> >> I have a question of python using echo. >> >> POWER = 14 >> return_value = os.system('echo 14 > >> /sys/class/net/wlan1/device/tx_power') >> >> can assign 14 to tx_power >> >> But >> return_value = os.system('echo $POWER > >> /sys/class/net/wlan1/device/tx_power') > > POWER = 14 doesn't create an environment variable visible to echo. It is > a Python variable. > > >>>> POWER = 14 >>>> import os >>>> return_value = os.system('echo $POWER') > >>>> return_value > 0 > > > >> return_value is 256 not 0. It cannot assign 14 to tx_power. > > > I don't understand that. Exit status codes on all systems I'm familiar > with are limited to 0 through 255. What operating system are you using? > > Assuming your system allows two-byte exit statuses, you should check the > documentation for echo and the shell to see why it is returning 256. > In some OSs the exit status consists of 2 fields, one being the child process's exit status and the other being supplied by the OS. The reason is simple. What if the child process terminated abnormally? You'd like an exit status to tell you that, but you wouldn't want it to be confused with the child process's own exit status, assuming that it had terminated normally. > Have you tried this in the shell, without involving Python? I will almost > guarantee that Python is irrelevant to the problem. > From tjreedy at udel.edu Thu Nov 12 14:31:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2009 14:31:41 -0500 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > graphics may be off-putting to some readers because it is associated > with children's learning. > > What do you think? I just started using the module for simple plots. I am not a child. You cannot please everyone. From warpcat at sbcglobal.net Thu Nov 12 14:36:39 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 11:36:39 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: On Nov 12, 11:31?am, Terry Reedy wrote: > Alf P. Steinbach wrote: > > One reaction to >http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > > graphics may be off-putting to some readers because it is associated > > with children's learning. > > > What do you think? > > I just started using the module for simple plots. > I am not a child. > You cannot please everyone. I used Turtle back on the Apple in the early 80's... so I personally have very positive feelings towards it ;) To each their own eh? From rami.chowdhury at gmail.com Thu Nov 12 14:42:05 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 11:42:05 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach >> wrote: >>> >>> This also seems religious. It's like in Norway it became illegal to >>> market lemon soda, since umpteen years ago it's soda with lemon >>> flavoring. This has to do with the *origin* of the citric acid, >>> whether natural or chemist's concoction, no matter that it's the same >>> chemical. So, some people think that it's wrong to talk about >>> interpreted languages, hey, it should be a "language designed for >>> interpretation", or better yet, "dynamic language", or bestest, >>> "language with dynamic flavor". And slow language, oh no, should be >>> "language whose current implementations are perceived as somewhat slow >>> by some (well, all) people", but of course, that's just silly. >> Perhaps I'm missing the point of what you're saying but I don't see >> why you're conflating interpreted and dynamic here? Javascript is >> unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all >> typically JIT it. Does that make Javascript non-dynamic, because it's >> compiled? What about Common Lisp, which is a compiled language when >> it's run with CMUCL or SBCL? > > Yeah, you missed it. > > Blurring and coloring and downright hiding reality by insisting on > misleading but apparently more precise terminology for some vague > concept is a popular sport, and chiding others for using more practical > and real-world oriented terms, can be effective in politics and some > other arenas. > > But in a technical context it's silly. Or dumb. Whatever. > > E.g. you'll find it impossible to define interpretation rigorously in > the sense that you're apparently thinking of. Well, sure. Can you explain, then, what sense you meant it in? > You'll also find it impossible to rigorously define "dynamic language" > in a general way so that that definition excludes C++. Or, for that matter, suitably clever assembler. I'm not arguing with you there. > So, to anyone who understands what one is talking about, "interpreted", > or e.g. "slow language" (as was the case here), conveys the essence. Not when the context isn't clear, it doesn't. > And to anyone who doesn't understand it trying to be more precise is an > exercise in futility and pure silliness -- except for the purpose of > misleading. Or for the purpose of greater understanding, surely - and isn't that the point? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From python at mrabarnett.plus.com Thu Nov 12 14:43:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:43:38 +0000 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: <4AFC656A.7010505@mrabarnett.plus.com> Ray Holt wrote: > I have an assigment to find the 1000th. prime using python. What's wrong > with the following code: > PrimeCount = 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > IsPrime = True > PrimeCandidate = PrimeCandidate + 2 > for x in range(2, PrimeCandidate): > if PrimeCandidate % x == 0: > ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x > print PrimeCandidate > IsPrime = False > break > if IsPrime: > PrimeCount = PrimeCount + 1 > PrimeCandidate = PrimeCandidate + 2 > print PrimeCandidate > Thanks > The indentation starting from the second 'if'. From victorsubervi at gmail.com Thu Nov 12 14:48:35 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 14:48:35 -0500 Subject: (OT) Recommend FTP Client In-Reply-To: <4AFC617A.2070201@ieee.org> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> <4AFC617A.2070201@ieee.org> Message-ID: <4dc0cfea0911121148m2f10cd3tc09f3db58958d0ce@mail.gmail.com> Thanks. V On Thu, Nov 12, 2009 at 2:26 PM, Dave Angel wrote: > > > Victor Subervi wrote: > >> Hi; >> Someone on this list just recommended I find an ftp client that enables me >> to change line endings. He indicated that it would be easy, but googling I >> haven't been able to find one. I would prefer a free client, but whatever. >> Please send me a recommendation. >> TIA, >> Victor >> >> >> > Try http://fireftp.mozdev.org/ > > fireftp is an (free) addon to Firefox. If you're already using Firefox, > it's painless to download it, and easy to use. You can set up account(s) > complete with passwords and default directories, and then transfer > individual files or directory trees full just by selecting and pressing the > Arrow icons (one for upload, one for download). You can sort by timestamp, > so it's not hard to just transfer new stuff. > > > One of the Tools->Options tabs is "Downloads/Uploads". First box looks > like: > > When transferring files use: > o - Automatic mode > o - Binary mode > o - ASCII mode > > > According to the help, Automatic mode is very useful for CGI scripts, where > you specify which extensions will get the line-endings converted. > http://fireftp.mozdev.org/help.html > > But please understand: I personally use Binary mode in FireFTP because I'm > a control freak. Python can handle Unix line-endings just fine, so any > files that are bound for CGI I just edit in that mode in the first place. > > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Thu Nov 12 14:52:18 2009 From: rantingrick at gmail.com (rantingrick) Date: Thu, 12 Nov 2009 11:52:18 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) Message-ID: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Hello, Currently i am using 2.6 on Windows and need to start writing code in 3.0. I cannot leave 2.x yet because 3rd party modules are still not converted. So i want to install 3.0 without disturbing my current Python2.x. What i'm afraid of is that some SYSVARIABLE will get changed to Python3.0 and when i double click a Python script it will try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts from the command line... > python3.x myscript.py So how do i do this? Is my fear unfounded? Thanks From alfps at start.no Thu Nov 12 15:02:11 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 21:02:11 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach > wrote: > >> * Rami Chowdhury: >>> On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach >>> wrote: >>>> >>>> This also seems religious. It's like in Norway it became illegal to >>>> market lemon soda, since umpteen years ago it's soda with lemon >>>> flavoring. This has to do with the *origin* of the citric acid, >>>> whether natural or chemist's concoction, no matter that it's the >>>> same chemical. So, some people think that it's wrong to talk about >>>> interpreted languages, hey, it should be a "language designed for >>>> interpretation", or better yet, "dynamic language", or bestest, >>>> "language with dynamic flavor". And slow language, oh no, should be >>>> "language whose current implementations are perceived as somewhat >>>> slow by some (well, all) people", but of course, that's just silly. >>> Perhaps I'm missing the point of what you're saying but I don't see >>> why you're conflating interpreted and dynamic here? Javascript is >>> unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 >>> all typically JIT it. Does that make Javascript non-dynamic, because >>> it's compiled? What about Common Lisp, which is a compiled language >>> when it's run with CMUCL or SBCL? >> >> Yeah, you missed it. >> >> Blurring and coloring and downright hiding reality by insisting on >> misleading but apparently more precise terminology for some vague >> concept is a popular sport, and chiding others for using more >> practical and real-world oriented terms, can be effective in politics >> and some other arenas. >> > >> But in a technical context it's silly. Or dumb. Whatever. >> >> E.g. you'll find it impossible to define interpretation rigorously in >> the sense that you're apparently thinking of. > > Well, sure. Can you explain, then, what sense you meant it in? I think that was in the part you *snipped* here. Just fill in the mentioned qualifications and weasel words. And considering that a routine might be an intepreter of data produced elsewhere in program, needs some fixing... >> You'll also find it impossible to rigorously define "dynamic language" >> in a general way so that that definition excludes C++. > > Or, for that matter, suitably clever assembler. I'm not arguing with you > there. > >> So, to anyone who understands what one is talking about, >> "interpreted", or e.g. "slow language" (as was the case here), conveys >> the essence. > > Not when the context isn't clear, it doesn't. > >> And to anyone who doesn't understand it trying to be more precise is >> an exercise in futility and pure silliness -- except for the purpose >> of misleading. > > Or for the purpose of greater understanding, surely - and isn't that the > point? I don't think that was the point. Specifically, I reacted to the statement that <>, made in response to someone upthread, in the context of Google finding CPython overall too slow. It is quite slow. ;-) Cheers, - Alf From russ.paielli at gmail.com Thu Nov 12 15:06:18 2009 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 12 Nov 2009 12:06:18 -0800 (PST) Subject: Psyco on 64-bit machines Message-ID: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> I have a Python program that runs too slow for some inputs. I would like to speed it up without rewriting any code. Psyco seemed like exactly what I need, until I saw that it only works on a 32-bit architecture. I work in an environment of Sun Ultras that are all 64- bit. However, the Psyco docs say this: "Psyco does not support the 64-bit x86 architecture, unless you have a Python compiled in 32-bit compatibility mode." Would it make sense to compile Python in the 32-bit compatibility mode so I can use Psyco? What would I lose in that mode, if anything? Thanks. From benjamin.kaplan at case.edu Thu Nov 12 15:07:29 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:07:29 -0500 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: On Thursday, November 12, 2009, Ray Holt wrote: > > > > > > I have an assigment > to find the 1000th. prime using python. What's wrong with the following > code: > PrimeCount = > 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > > IsPrime = True > ??? PrimeCandidate = PrimeCandidate + > 2 > ??? for x in range(2, > PrimeCandidate): > ??????? if PrimeCandidate > % x == > 0: > ##??????????? print > PrimeCandidate, 'equals', x, '*', > PrimeCandidate/x > > print PrimeCandidate > > > IsPrime = > False > > break > ??????? if > IsPrime: > > PrimeCount = PrimeCount + > 1 > > PrimeCandidate = PrimeCandidate + > 2 > ??????? print > PrimeCandidate > Thanks > You break on the first composite number, which means you immediately exit the loop. Just let it fall through Also, a couple of things to speed in up: 1) you look at all numbers from 2 to n to check if n is a prime number. You only need to check from 2 to int(math.sqrt(n)) 2) to really speed it up, keep a list of all the prime numbers. Then you only need to check if a number is divisible by those By combining the two, you'll only use a fraction of the comparisons. For 23, you'd only loop twice (2 and 3) instead of 20 times to determine that it's prime. The difference is even more dramatic on large numbers. From benjamin.kaplan at case.edu Thu Nov 12 15:11:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:11:39 -0500 Subject: Computing the 1000th prime In-Reply-To: References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: On Thursday, November 12, 2009, Benjamin Kaplan wrote: > On Thursday, November 12, 2009, Ray Holt wrote: >> >> >> >> >> >> I have an assigment >> to find the 1000th. prime using python. What's wrong with the following >> code: >> PrimeCount = >> 0 >> PrimeCandidate = 1 >> while PrimeCount < 2000: >> >> IsPrime = True >> ??? PrimeCandidate = PrimeCandidate + >> 2 >> ??? for x in range(2, >> PrimeCandidate): >> ??????? if PrimeCandidate >> % x == >> 0: >> ##??????????? print >> PrimeCandidate, 'equals', x, '*', >> PrimeCandidate/x >> >> print PrimeCandidate >> >> >> IsPrime = >> False >> >> break >> ??????? if >> IsPrime: > > You break on the first composite number, which means you immediately > exit the loop. Just let it fall through Also, a couple of things to > speed in up: > Nevermind MRAB is right. I missed the indentation error there. I guess that's what I get for trying to evaluate code on my iPod touch instead of getting my computer out and actually seeing what it's doing. >.< > 1) you look at all numbers from 2 to n to check if n is a prime > number. You only need to check from 2 to int(math.sqrt(n)) > > 2) to really speed it up, keep a list of all the prime numbers. Then > you only need to check if a number is divisible by those > > By combining the two, you'll only use a fraction of the comparisons. > For 23, you'd only loop twice (2 and 3) instead of 20 times to > determine that it's prime. The difference is even more dramatic on > large numbers. > From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:27:31 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:27:31 +0100 Subject: New syntax for blocks In-Reply-To: <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> Message-ID: <4afc7d43$0$7712$426a74cc@news.free.fr> r a ?crit : -snip) > Just thinking out loud here...what if variable assignments could > return a value... hmmm? Not to them selfs of course but to a caller, > like an if statement... > > if a=openfile: > # do something with a Congratulations, you just reinvented one of the most infamous source of bugs in C, C++, Java, PHP, javascript and quite a few other languages. Believe it or not, but not allowing this in Python was a very deliberate design choice. Now whether it was a good choice is another troll^Mtopic !-) From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:29:02 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:29:02 +0100 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <4afc7d9e$0$7712$426a74cc@news.free.fr> Steven D'Aprano a ?crit : (snip) > Hint to would-be language designers: if you start off by claiming that a > new feature will save an indent level, when in fact it *doesn't* save an > indent level, you can save yourself from embarrassment by pressing Close > on your post instead of Send. Mouaaaaaaaa !-) Thanks Steven, you made my day (me ---> go back mouaaaaaa) From rami.chowdhury at gmail.com Thu Nov 12 15:33:05 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 12:33:05 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach wrote: > I think that was in the part you *snipped* here. Just fill in the > mentioned qualifications and weasel words. OK, sure. I don't think they're weasel words, because I find them useful, but I think I see where you're coming from. > Specifically, I reacted to the statement that < talk about "the" speed of an implementation>>, made in response to > someone upthread, in the context of Google finding CPython overall too > slow. IIRC it was "the speed of a language" that was asserted to be nonsense, wasn't it? Which IMO is fair -- a physicist friend of mine works with a C++ interpreter which is relatively sluggish, but that doesn't mean C++ is slow... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:37:48 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:37:48 +0100 Subject: New syntax for blocks In-Reply-To: <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> Message-ID: <4afc7fad$0$7712$426a74cc@news.free.fr> r a ?crit : > On Nov 11, 2:37 am, Steven D'Aprano > wrote: >> On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: > >>> Yea it's called a NameError. Would it not also blow up in the current >>> state of syntax usage? >> No. >> >>> if var: >>> print 'var' >>> Traceback (most recent call last): >>> File "", line 1, in >>> if var: >>> NameError: name 'var' is not defined >> You missed a line: >> >> var = range(N) >> if var: > > Oh i get it now! If i assign a valid value to a variable the variable > is also valid...thats...thats... GENUIS! *sarcasm* It's not about "assigning a valid value to a variable", it's about the name being created (or not) in the current namespace, whatever it's bound to. From ckaynor at zindagigames.com Thu Nov 12 15:40:57 2009 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 12 Nov 2009 12:40:57 -0800 Subject: Psyco on 64-bit machines In-Reply-To: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 12:06 PM, Russ P. wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > The only things you should lose by using a 32-bit version of Python is access to the memory beyond the 4GB limit (approximate - the OS takes some of that), and any compiled extension modules you cannot find or recompile for 32-bit (.pyd on Windows - I think .so on Linux). Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Nov 12 15:44:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:44:00 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 12, 2009 at 2:24 PM, Alf P. Steinbach wrote: > > You'll also find it impossible to rigorously define "dynamic language" in a > general way so that that definition excludes C++. > > So, to anyone who understands what one is talking about, "interpreted", or > e.g. "slow language" (as was the case here), conveys the essence. > > And to anyone who doesn't understand it trying to be more precise is an > exercise in futility and pure silliness ?-- ?except for the purpose of > misleading. You just made Rami's point. You can't define a language as . You can however describe what features it has - static vs. dynamic typing, duck-typing, dynamic dispatch, and so on. Those are features of the language. Other things, like "interpreted" vs "compiled" are features of the implementation. C++ for instance is considered language that gets compiled to machine code. However, Visual Studio can compile C++ programs to run on the .NET framework which makes them JIT compiled. Some one could even write an interpreter for C++ if they wanted to. From benjamin.kaplan at case.edu Thu Nov 12 15:49:41 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:49:41 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 2:52 PM, rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? > At least on *nix (including OS X), installing Python 3 does exactly what you want by default. I don't know how it handles it on Windows. > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Nov 12 15:51:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2009 15:51:13 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? When you install 3.1 (not 3.0), it asks whether to make 'this' the default Python. Make sure the box is unchecked. From davea at ieee.org Thu Nov 12 15:51:44 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 15:51:44 -0500 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: <4AFC7560.50104@ieee.org> Ray Holt wrote: > I have an assigment to find the 1000th. prime using python. What's wrong > with the following code: > PrimeCount = 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > IsPrime = True > PrimeCandidate = PrimeCandidate + 2 > for x in range(2, PrimeCandidate): > if PrimeCandidate % x == 0: > ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x > print PrimeCandidate > IsPrime = False > break > if IsPrime: > PrimeCount = PrimeCount + 1 > PrimeCandidate = PrimeCandidate + 2 > print PrimeCandidate > Thanks > > There are a bunch of things wrong here. Did you write this code, or was it copied from somewhere else? Because it looks like there are several typos, that you could catch by inspection. First, at what point in the loop do you decide that you have a prime? Why not add a print there, printing the prime, instead of printing a value that's already been incremented beyond it. And put labels on your prints, or you'll never be able to decipher the output. Chnage the limit for PrimeCount to something small while you're debugging, because you can figure out small primes and composites by hand. Second, you have a loop which divides by x. But you change the PrimeCandidate within the loop, so it's not dividing the same value each time through. Check your indentation. Third, your limit value is too high. You aren't looking for 2000 primes, but 1000 of them. Further, your count is off by 1, as this loop doesn't identify 2 as a prime. I'd recommend making this whole thing a function, and have it actually build and return a list of primes. Then the caller can check both the size of the list and do a double check of the primality of each member. And naturally you'll be able to more readily check it yourself, either by eye or by comparing it to one of the standard list of primes you can find on the internet. The function should take a count, and loop until the len(primelist) matches the count. Then just return the primelist. DaveA From patrick.just4fun at gmail.com Thu Nov 12 16:04:51 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Thu, 12 Nov 2009 22:04:51 +0100 Subject: Python & Go In-Reply-To: <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: <4AFC7873.4020808@gmail.com> Carl Banks wrote: > Well, it's hard to argue with not being like C++, but the lack of > inheritance is a doozie. Well it has the concept of embedding, which seems to be similar to inheritance. - Patrick From davidb at panix.com Thu Nov 12 16:05:46 2009 From: davidb at panix.com (David M. Besonen) Date: Thu, 12 Nov 2009 13:05:46 -0800 Subject: (OT) Recommend FTP Client In-Reply-To: <4AFC617A.2070201@ieee.org> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> <4AFC617A.2070201@ieee.org> Message-ID: <4AFC78AA.3070807@panix.com> On 11/12/2009 11:26 AM, Dave Angel wrote: > Try http://fireftp.mozdev.org/ in the past i found this to be buggy. i'd recommend something different. what is your OS? -- david From rami.chowdhury at gmail.com Thu Nov 12 16:08:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 13:08:27 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 12:44:00 -0800, Benjamin Kaplan wrote: > Some one could even write an > interpreter for C++ if they wanted to. Someone has (http://root.cern.ch/drupal/content/cint)! -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From hansmu at xs4all.nl Thu Nov 12 16:20:47 2009 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 12 Nov 2009 22:20:47 +0100 Subject: python with echo In-Reply-To: References: Message-ID: <4afc7c9d$0$22941$e4fe514c@news.xs4all.nl> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > >> List, >> >> I have a question of python using echo. >> >> POWER = 14 >> return_value = os.system('echo 14 > >> /sys/class/net/wlan1/device/tx_power') >> >> can assign 14 to tx_power >> >> But >> return_value = os.system('echo $POWER > >> /sys/class/net/wlan1/device/tx_power') > > POWER = 14 doesn't create an environment variable visible to echo. It is > a Python variable. > >>>> POWER = 14 >>>> import os >>>> return_value = os.system('echo $POWER') > >>>> return_value > 0 You can set environment variables from within Python using os.putenv: >>> import os >>> os.putenv('POWER', '14') >>> return_value = os.system('echo $POWER') 14 >>> return_value 0 Keep in mind that putenv() only affects processes started by Python after you call putenv. It does not, for example, affect the shell process you used to invoke Python: $ POWER=14 $ python -c 'import os os.putenv("POWER", "42") os.system("echo $POWER")' 42 $ echo $POWER 14 $ >> return_value is 256 not 0. It cannot assign 14 to tx_power. > > I don't understand that. Exit status codes on all systems I'm familiar > with are limited to 0 through 255. What operating system are you using? Probably some form of Unix. The value returned by os.system() is the exit status shifted left one byte, for example: >>> os.system("exit 1") 256 Hope this helps, -- HansM From patrick.just4fun at gmail.com Thu Nov 12 16:22:42 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Thu, 12 Nov 2009 22:22:42 +0100 Subject: Python & Go In-Reply-To: References: Message-ID: <4AFC7CA2.3090606@gmail.com> kj wrote: > > I'm just learning about Google's latest: the GO (Go?) language. > (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", the absence of parentheses at the top of > flow control constructs, and quite a few statements without a > trailing semicolon. Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... I don't see many similarities with python, especially it's syntax looks completely different to me. Google Go introduces many new concepts. Interfaces work a little bit like duck typing. You may call that python-style. And it has go-routines, which are a bit similar to generators (although I haven't look at them in detail). There is no exception handling, but channels should be able to substitute them, although I haven't checked that. At a first look it seems, that using Google Go effectively, someone has to relinquish many programming habits and adapt lots of new ones. - Patrick From jaredatwork0 at gmail.com Thu Nov 12 16:25:41 2009 From: jaredatwork0 at gmail.com (Jared Klumpp) Date: Thu, 12 Nov 2009 13:25:41 -0800 (PST) Subject: JSR223 Access Python class instances through Java Message-ID: <1c8e4788-8ce5-4baa-818f-141f04f33997@l2g2000yqd.googlegroups.com> I am trying to access (from Java) a python class that extends a Java interface. The following program runs fine in the jython console (I can instantiate Tada, call t.getName() and everything prints correctly.) However, if I invoke test1() from Java using JSR223, the returned object is inaccessible (proxy type) and none of the "in init", "in getName" strings will print. Furthermore, none of the lines print unless I convert ITest to a concrete class, but then the getName methods return the concrete implementation's string. Has anyone successfully had this situation work, and how did you do it? Thanks in advance Code: =========== import ITest class Tada(ITest): def __init__(self): print "In Init" def getName(self): print "In getName" return "Joe Schmoe" def test1(): t = Tada() print t.getName() print "Hello, World" return t From invalid at invalid.invalid Thu Nov 12 16:37:30 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 12 Nov 2009 21:37:30 +0000 (UTC) Subject: Python & Go References: Message-ID: On 2009-11-12, Patrick Sabin wrote: > kj wrote: >> >> I'm just learning about Google's latest: the GO (Go?) language. >> (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). >> There are some distinctly Pythonoid features to the syntax, such >> as "import this_or_that", the absence of parentheses at the top of >> flow control constructs, and quite a few statements without a >> trailing semicolon. Then again, there's a lot that looks distinctly >> un-Pythonlike, such as the curly brackets all over the place. And >> among the un-Pythonlike stuff there's a lot that looks like nothing >> else that I've ever seen... > > I don't see many similarities with python, Same here. Go syntax is much more like C/Java than Python. Sematically, I don't see much that's similar either. Go is statically typed. Go has no inheritence. Go has no exceptions ( no practical error handling AFAICT). Despite all the people who keep saying it's similar to Python, I don't really see what they're talking about. It seems more like C with garbage collection and interfaces, or maybe cleaned-up Java. -- Grant Edwards grante Yow! I have a VISION! It's at a RANCID double-FISHWICH on visi.com an ENRICHED BUN!! From tschmidt at sacfoodcoop.com Thu Nov 12 17:04:40 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Thu, 12 Nov 2009 14:04:40 -0800 (PST) Subject: open source linux -> windows database connectivity? Message-ID: I am trying to read a Pervasive database on a Windows machine from a Python script on a Linux machine. I understand that this can be done with a proprietary ODBC-to-ODBC bridge called mxODBC or Easysoft OOB. Is there anyway to do this with existing free/ open source tools? Thanks in advance for any tips. From sridharr at activestate.com Thu Nov 12 17:12:44 2009 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 12 Nov 2009 14:12:44 -0800 Subject: ANN: ActivePython 2.6.4.8 is now available Message-ID: I'm happy to announce that ActivePython 2.6.4.8 is now available for download from: http://www.activestate.com/activepython/ This is a patch release that updates ActivePython to core Python 2.6.4. We recommend that you try 2.6 version first. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. Beginning the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC - Solaris/x86 - HP-UX/PA-RISC - AIX/PowerPC - AIX/PowerPC 64-bit Extra Bits ---------- ActivePython releases also include the following: - ActivePython26.chm: An MS compiled help collection of the full ActivePython documentation set. Linux users of applications such as xCHM might find this useful. This package is installed by default on Windows. Extra bits are available from: http://downloads.activestate.com/ActivePython/etc/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From rantingrick at gmail.com Thu Nov 12 17:15:10 2009 From: rantingrick at gmail.com (rantingrick) Date: Thu, 12 Nov 2009 14:15:10 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: <852fa408-a61d-4fa1-80fc-ef0424d96767@s31g2000yqs.googlegroups.com> On Nov 12, 2:51?pm, Terry Reedy wrote: > rantingrick wrote: > > Hello, > > > Currently i am using 2.6 on Windows and need to start writing code in > > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > > converted. So i want to install 3.0 without disturbing my current > > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > > changed to Python3.0 and when i double click a Python script it will > > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > > from the command line... > python3.x myscript.py > > > So how do i do this? Is my fear unfounded? > > When you install 3.1 (not 3.0), it asks whether to make 'this' the > default Python. Make sure the box is unchecked. Thanks for both of your replies, just to be safe though i'm going to back up everything ... Python 3000, here i come and i hope your ready for me!?!? Later Guy's! From lists at cheimes.de Thu Nov 12 17:31:00 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Nov 2009 23:31:00 +0100 Subject: python with echo In-Reply-To: <7m2729F3fjr14U1@mid.uni-berlin.de> References: <7m2729F3fjr14U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > with open("/sys/class/net/wlan1/device/tx_power", "w") as f: > f.write("%i" % POWER) IIRC the sys and proc virtual file system requires new line at the end of a modifier. At least echo appends \n unless it's told otherwise. Christian From rt8396 at gmail.com Thu Nov 12 17:55:12 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 14:55:12 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> Message-ID: <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> On Nov 12, 2:37?pm, Bruno Desthuilliers wrote: > > Oh i get it now! If i assign a valid value to a variable the variable > > is also valid...thats...thats... GENUIS! *sarcasm* > > It's not about "assigning a valid value to a variable", it's about the > name being created (or not) in the current namespace, whatever it's > bound to. And thats what my sarcasm was alluding to. Steven's argument is moot because it will blow up either way due to the fact that "value" is non- existent! Every argument that has been brought forth about how this will break is just False and basically a bunch of FUD! It just garbage so you can discredit the idea. It's actually quite funny when someone as small as me can bring down the iron curtain of c.l.py. '''Mr. Gorbachev, Tear down this wall!''' How about one of you "esteemed" Pythonista's show me a real example where it will break. Show me (and the world) this H.G Wells nightmarish scenario you speak of but show no solid proofs. Sorry chaps, I don't buy snake oil! Going, Going, Gonnnne, out the park! PS: And if it were so dangerous why would someone as knowledgeable as Carl have stepped in and supported it. I think because (like me) Carl put's the language before sewing circles. I think it's just personal like all the times before, that's OK, i have very thick skin! If it's wrong for a good reason i will graciously accept that, but no one has proven it's non-worth, not yet! From mal at egenix.com Thu Nov 12 17:56:22 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 12 Nov 2009 23:56:22 +0100 Subject: open source linux -> windows database connectivity? In-Reply-To: References: Message-ID: <4AFC9296.2040309@egenix.com> Tony Schmidt wrote: > I am trying to read a Pervasive database on a Windows machine from a > Python script on a Linux machine. > > I understand that this can be done with a proprietary ODBC-to-ODBC > bridge called mxODBC or Easysoft OOB. The product is called "mxODBC Connect" and allows connecting from Python (running on pretty much any major platform) to a Windows or Linux server running the database: http://www.egenix.com/products/python/mxODBCConnect/ Note: The client part of this product is free. You only need to get a license for the server part. Alternatively, you can also our mxODBC single-tier product with the Pervasive ODBC driver available for Linux: http://ww1.pervasive.com/developerzone/platforms/linux.asp Regards, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 12 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 dc.loco at gmail.com Thu Nov 12 19:47:36 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 16:47:36 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? Message-ID: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Hi, I recently asked our IT department how to gain access to an addressbook. After carefully explaining that I was on a Linux system using Python, I got the reply: "You should use our LDAP. With LDAP you can pull any data you want from Active Directory. On our network, the serverless binding address for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." with the actual "..." filled in. I don't know squat about LDAP, but installed the python-ldap deb, and started glancing at the documentation on-line. I didn't see anything obvious for working with the URI above. Can I work w/ it? If so, a short example, please? Thanx. From wuwei23 at gmail.com Thu Nov 12 20:01:47 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Nov 2009 17:01:47 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 13, 10:47?am, Kevin Cole wrote: > Hi, > > I recently asked our IT department how to gain access to an > addressbook. ?After carefully explaining that I was on a Linux system > using Python, I got the reply: > > "You should use our LDAP. With LDAP you can pull any data you want > from Active Directory. On our network, the serverless binding address > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > with the actual "..." filled in. > > I don't know squat about LDAP, but installed the python-ldap deb, and > started glancing at the documentation on-line. I didn't see anything > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > short example, please? > > Thanx. http://www.python-ldap.org/doc/html/ldapurl.html#example From dc.loco at gmail.com Thu Nov 12 20:27:03 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 17:27:03 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 12, 8:01?pm, alex23 wrote: > On Nov 13, 10:47?am, Kevin Cole wrote: > > > > > Hi, > > > I recently asked our IT department how to gain access to an > > addressbook. ?After carefully explaining that I was on a Linux system > > using Python, I got the reply: > > > "You should use our LDAP. With LDAP you can pull any data you want > > from Active Directory. On our network, the serverless binding address > > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > > with the actual "..." filled in. > > > I don't know squat about LDAP, but installed the python-ldap deb, and > > started glancing at the documentation on-line. I didn't see anything > > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > > short example, please? > > > Thanx. > > http://www.python-ldap.org/doc/html/ldapurl.html#example Ah, it wasn't clear to me that "localhost:1389" meant serverless. Armed with that, I'm off to experiment. Thanks. From jeremiahsavage at gmail.com Thu Nov 12 20:38:00 2009 From: jeremiahsavage at gmail.com (Jeremiah H. Savage) Date: Thu, 12 Nov 2009 17:38:00 -0800 Subject: python parser overridden by pymol In-Reply-To: <4AFB8592.7040300@ieee.org> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> Message-ID: <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> On Wed, Nov 11, 2009 at 7:48 PM, Dave Angel wrote: > > > Jeremiah wrote: >> >> Hello, >> >> I'm fairly new to python (version 2.5.4), and am writing a program >> which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from >> debian. >> >> It appears that when I add pymol to $PYTHONPATH, that parser.expr() is >> no longer available, and so I am unable to use numpy.load(). I have >> looked for where parser.expr() is defined in the python system so I >> could place that directory first in $PYTHONPATH, but I have not been >> able to find the file that defines expr(). >> >> My reason for using numpy.load() is that I have a numpy array which >> takes an hour to generate. Therefore, I'd like to use numpy.save() so >> I could generate the array one time, and then load it later as needed >> with numpy.load(). >> >> I've successfully tested the use of numpy.save() and numpy.load() with >> a small example when the pymol path is not defined in $PYTHONPATH ?: >> >> ? >>> import numpy >> ? >>> numpy.save('123',numpy.array([1,2,3])) >> ? >>> numpy.load('123.npy') >> ? array([1, 2, 3]) >> >> >> However, a problem arises once $PYTHONPATH includes the pymol >> directory. To use the pymol api, I add the following to ~/.bashrc: >> >> ? PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol >> ? export PYMOL_PATH >> ? PYTHONPATH=$PYMOL_PATH >> ? export PYTHONPATH >> >> Once this is done, numpy.load() no longer works correctly, as pymol >> contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ >> parser.py ), which apparently prevents python from using its native >> parser. >> >> ? >>> numpy.load('123.npy') >> ? Traceback (most recent call last): >> ? ? File "", line 1, in >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line >> 195, in load >> ? ? ? return format.read_array(fid) >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", >> line 353, in read_array >> ? ? ? shape, fortran_order, dtype = read_array_header_1_0(fp) >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", >> line 250, in read_array_header_1_0 >> ? ? ? d = safe_eval(header)Thank you. That really helped. To use pymol and numpy to >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line >> 840, in safe_eval >> ? ? ? ast = compiler.parse(source, "eval") >> ? ? File "/usr/lib/python2.5/compiler/transformer.py", line 54, in >> parse >> ? ? ? return Transformer().parseexpr(buf) >> ? ? File "/usr/lib/python2.5/compiler/transformer.py", line 133, in >> parseexpr >> ? ? ? return self.transform(parser.expr(text)) >> ? AttributeError: 'module' object has no attribute 'expr' >> >> If I understand the problem correctly, can anyone tell me where >> python.expr() is defined, or suggest a better method to fix this >> problem? >> >> Thanks, >> Jeremiah >> >> > > Generic answers, I have no experience with pymol > > If pymol really needs that parser.py, you have a problem, as there can only > be one module by that name in the application. ?But assuming it's needed for > some obscure feature that you don't need, you could try the following > sequence. > > 1) temporarily rename the pymol's ?parser.py ?file to something else, like > pymolparser.py, and see what runs. > 2) rather than changing the PYTHONPATH, fix ?up ?sys.path during your script > initialization. > ? In particular, do an ? ?import parser ? ?near the beginning of the script. > ?This gets it loaded, even though you might not need to use it from this > module. > ? After that import, then add the following line (which could be generalized > later) > ? sys.path.append( "/usr/lib/pymodules/python2.5/pymol") > > > If this works, then you can experiment a bit more, perhaps you don't need > the extra import parser, just putting the pymol directory at the end of the > sys.path rather than the beginning may be good enough. > > If the parser.py in the pymol is actually needed, you might need to rename > its internal references to some other name, like pymolparser. > > HTH, > DaveA > > Thank you. Your second suggestion really helped. To use pymol and numpy together, I now do the following: To ~/.bashrc add: PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol export PYMOL_PATH Then I can do the following in python: import numpy numpy.save('123',numpy.array([1,2,3])) numpy.load('123.npy') array([1, 2, 3]) import sys sys.path.append( "/usr/lib/pymodules/python2.5/pymol") import pymol pymol.finish_launching() pymol.importing.load("/path/to/file.pdb") Thanks, Jeremiah From dc.loco at gmail.com Thu Nov 12 20:39:55 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 17:39:55 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 12, 8:01?pm, alex23 wrote: > On Nov 13, 10:47?am, Kevin Cole wrote: > > > > > Hi, > > > I recently asked our IT department how to gain access to an > > addressbook. ?After carefully explaining that I was on a Linux system > > using Python, I got the reply: > > > "You should use our LDAP. With LDAP you can pull any data you want > > from Active Directory. On our network, the serverless binding address > > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > > with the actual "..." filled in. > > > I don't know squat about LDAP, but installed the python-ldap deb, and > > started glancing at the documentation on-line. I didn't see anything > > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > > short example, please? > > > Thanx. > > http://www.python-ldap.org/doc/html/ldapurl.html#example On second thought... That didn't help at all. The example just shows how to parse a URI. I'm trying to connect to a service (if I understand correctly) that is NOT on my Linux box, but somewhere out in our IT department's ether, and I do not have host/domain to work with. I interpreted "serverless binding" to mean that I was connecting by some means other than host.domain:port. Yes? From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:44:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:44:22 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> Message-ID: <00863e42$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > Congratulations, you just reinvented one of the most infamous source of > bugs in C, C++, Java, PHP, javascript and quite a few other languages. > Believe it or not, but not allowing this in Python was a very deliberate > design choice. Oh, but those hundreds of thousands of man-hours lost to bugs caused by assignment-as-an-expression is nothing compared to the dozens of man- minutes saved by having one fewer line of code! *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:49:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:49:08 GMT Subject: python with echo References: Message-ID: <00863f61$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 19:30:01 +0000, MRAB wrote: >> I don't understand that. Exit status codes on all systems I'm familiar >> with are limited to 0 through 255. What operating system are you using? >> >> Assuming your system allows two-byte exit statuses, you should check >> the documentation for echo and the shell to see why it is returning >> 256. >> > In some OSs the exit status consists of 2 fields, one being the child > process's exit status and the other being supplied by the OS. Which OSes? > The reason is simple. What if the child process terminated abnormally? > You'd like an exit status to tell you that, Which it does. Anything other than 0 is an error. I see that, for example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it to exit normally, it returns with an exit status of 130. [steve at soy ~]$ sleep 3 # no interrupt [steve at soy ~]$ echo $? 0 [steve at soy ~]$ sleep 3 # interrupt with ctrl-C [steve at soy ~]$ echo $? 130 I get the same result on a Linux box and a Solaris box, both running bash. > but you wouldn't want it to > be confused with the child process's own exit status, assuming that it > had terminated normally. I don't understand what you mean here. Why are you assuming it terminated normally if it terminated abnormally? -- Steven From tschmidt at sacfoodcoop.com Thu Nov 12 20:50:20 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Thu, 12 Nov 2009 17:50:20 -0800 (PST) Subject: open source linux -> windows database connectivity? References: Message-ID: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> >Note: The client part of this product is free. You only need to >get a license for the server part. Yeah, but don't I need the server part to make the connection? Would it be possible to use Jython and the Pervasive JDBC driver for this? On Nov 12, 2:56?pm, "M.-A. Lemburg" wrote: > Tony Schmidt wrote: > > I am trying to read a Pervasive database on a Windows machine from a > > Python script on a Linux machine. > > > I understand that this can be done with a proprietary ODBC-to-ODBC > > bridge called mxODBC or Easysoft OOB. > > The product is called "mxODBC Connect" and allows connecting from > Python (running on pretty much any major platform) to a Windows > or Linux server running the database: > > ? ?http://www.egenix.com/products/python/mxODBCConnect/ > > Note: The client part of this product is free. You only need to > get a license for the server part. > > Alternatively, you can also our mxODBC single-tier product with > the Pervasive ODBC driver available for Linux: > > ? ?http://ww1.pervasive.com/developerzone/platforms/linux.asp > > Regards, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 12 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 steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:55:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:55:57 GMT Subject: QuerySets in Dictionaries References: Message-ID: <008640fa$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: > I need to create a dictionary of querysets. I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? I don't understand your problem. Assuming Myobject is defined, and has the appropriate attribute objects.filter, the above should work exactly as you give it. What is your actual problem? Are you asking for help in defining a queryset? -- Steven From python at mrabarnett.plus.com Thu Nov 12 21:22:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Nov 2009 02:22:26 +0000 Subject: python with echo In-Reply-To: <00863f61$0$26916$c3e8da3@news.astraweb.com> References: <00863f61$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4AFCC2E2.5050007@mrabarnett.plus.com> Steven D'Aprano wrote: > On Thu, 12 Nov 2009 19:30:01 +0000, MRAB wrote: > >>> I don't understand that. Exit status codes on all systems I'm familiar >>> with are limited to 0 through 255. What operating system are you using? >>> >>> Assuming your system allows two-byte exit statuses, you should check >>> the documentation for echo and the shell to see why it is returning >>> 256. >>> >> In some OSs the exit status consists of 2 fields, one being the child >> process's exit status and the other being supplied by the OS. > > Which OSes? > >> The reason is simple. What if the child process terminated abnormally? >> You'd like an exit status to tell you that, > > Which it does. Anything other than 0 is an error. I see that, for > example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it > to exit normally, it returns with an exit status of 130. > > [steve at soy ~]$ sleep 3 # no interrupt > [steve at soy ~]$ echo $? > 0 > [steve at soy ~]$ sleep 3 # interrupt with ctrl-C > > [steve at soy ~]$ echo $? > 130 > > I get the same result on a Linux box and a Solaris box, both running bash. > > > >> but you wouldn't want it to >> be confused with the child process's own exit status, assuming that it >> had terminated normally. > > I don't understand what you mean here. Why are you assuming it terminated > normally if it terminated abnormally? > You want to be able to distinguish between a child process terminating with an exit status, and failing to run a child process for some reason. From greg at cosc.canterbury.ac.nz Thu Nov 12 21:29:03 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:29:03 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <7m3ujtF3gd1d7U1@mid.individual.net> Carl Banks wrote: > You > can define constants to access specific registers: > > R1L = 1 > R1H = 2 > R1 = 1 > > breg[R1H] = 2 > print wreg[R1] But keep in mind that named "constants" at the module level are really global variables, and therefore incur a dictionary lookup every time they're used. For maximum speed, nothing beats writing the numeric literals directly into the code, unfortunately. Generally, I think you're going to have quite a battle on your hands to get a pure Python implementation to run as fast as a real Z80, if it's even possible at all. And if you do succeed, the code will be pretty awful (due to things such as not being able to use named constants). I would be taking a different approach -- develop a prototype in Python, concentrating on clarity rather than speed, and later reimplement the core of the emulator as an extension module, using Pyrex or Cython or otherwise. -- Greg From robert.kern at gmail.com Thu Nov 12 21:32:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 Nov 2009 20:32:32 -0600 Subject: python parser overridden by pymol In-Reply-To: <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> Message-ID: Jeremiah H. Savage wrote: > To use pymol and numpy together, I now do the following: > > To ~/.bashrc add: > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > > Then I can do the following in python: > > import numpy > numpy.save('123',numpy.array([1,2,3])) > numpy.load('123.npy') > array([1, 2, 3]) > import sys > sys.path.append( "/usr/lib/pymodules/python2.5/pymol") > import pymol > pymol.finish_launching() > pymol.importing.load("/path/to/file.pdb") No, do not do this. Add /usr/lib/pymodules/python2.5/ to your $PYTHONPATH, *not* /usr/lib/pymodules/python2.5/pymol/. You will continue to run into problems if you do it this way. You are not supposed to put the directory *of* the package onto sys.path but rather the directory that *contains* the package directory. -- 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 greg at cosc.canterbury.ac.nz Thu Nov 12 21:33:53 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:33:53 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <7m3usvF3gec23U1@mid.individual.net> Santiago Romero wrote: >>How about >> page, index = divmod(address, 16384) > > Surely, much better and faster :-) Not necessarily, because it involves a function call, and constructing and deconstructing a result tuple. If you time them, you may well find that the explicit shift and mask operations turn out to be faster. That also goes for any of the other things being discussed here. Especially if you're used to C, one's intuitions about speed can go badly astray where Python is concerned. The only way to be sure is to measure! -- Greg From greg at cosc.canterbury.ac.nz Thu Nov 12 21:36:42 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:36:42 +1300 Subject: #define (from C) in Python In-Reply-To: <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> Message-ID: <7m3v25F3gec23U2@mid.individual.net> TerryP wrote: > If it's such a big hairy deal, just recompile a copy of the C Pre > Processor to use something other then #, and hook it up to your python > scripts in a pipe line from a shell wrapper. Or use a different preprocessor, such as m4, that doesn't clash with the # character. -- Greg From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 21:50:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 02:50:33 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <00864dc6$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 21:02:11 +0100, Alf P. Steinbach wrote: > Specifically, I reacted to the statement that < talk about "the" speed of an implementation>>, made in response to > someone upthread, in the context of Google finding CPython overall too > slow. > > It is quite slow. ;-) Quite slow to do what? Quite slow compared to what? I think you'll find using CPython to sort a list of ten million integers will be quite a bit faster than using bubblesort written in C, no matter how efficient the C compiler. And why are we limiting ourselves to integers representable by the native C int? What if the items in the list were of the order of 2**100000? Of if they were mixed integers, fractions, fixed-point decimals, and floating-point binaries? How fast is your C code going to be now? That's going to depend on the C library you use, isn't it? In other words, it is an *implementation* issue, not a *language* issue. Okay, let's keep it simple. Stick to numbers representable by native C ints. Around this point, people start complaining that it's not fair, I'm not comparing apples with apples. Why am I comparing a highly-optimized, incredibly fast sort method in CPython with a lousy O(N**2) algorithm in C? To make meaningful comparisons, you have to make sure the algorithms are the same, so the two language implementations do the same amount of work. (Funnily enough, it's "unfair" to play to Python's strengths, and "fair" to play to C's strengths.) Then people invariable try to compare (say) something in C involving low- level bit-twiddling or pointer arithmetic with something in CPython involving high-level object-oriented programming. Of course CPython is "slow" if you use it to do hundreds of times more work in every operation -- that's comparing apples with oranges again, but somehow people think that's okay when your intention is to prove "Python is slow". An apples-to-apples comparison would be to use a framework in C which offered the equivalent features as Python: readable syntax ("executable pseudo-code"), memory management, garbage disposal, high-level objects, message passing, exception handling, dynamic strong typing, and no core dumps ever. If you did that, you'd get something that runs much closer to the speed of CPython, because that's exactly what CPython is: a framework written in C that provides all those extra features. (That's not to say that Python-like high-level languages can't, in theory, be significantly faster than CPython, or that they can't have JIT compilers that emit highly efficient -- in space or time -- machine code. That's what Psyco does, now, and that's the aim of PyPy.) However, there is one sense that Python *the language* is slower than (say) C the language. Python requires that an implementation treat the built-in function (say) int as an object subject to modification by the caller, while C requires that it is a reserved word. So when a C compiler sees "int", it can optimize the call to a known low-level routine, while a Python compiler can't make this optimization. It *must* search the entire scope looking for the first object called 'int' it finds, then search the object's scope for a method called '__call__', then execute that. That's the rules for Python, and an implementation that does something else isn't Python. Even though the searching is highly optimized, if you call int() one million times, any Python implementation *must* perform that search one million times, which adds up. Merely identifying what function to call is O(N) at runtime for Python and O(1) at compile time for C. Note though that JIT compilers like Psyco can often take shortcuts and speed up code by a factor of 2, or up to 100 in the best cases, which brings the combination of CPython + Psyco within shouting distance of the speed of the machine code generated by good optimizing C compilers. Or you can pass the work onto an optimized library or function call that avoids the extra work. Like I said, there is no reason for Python *applications* to be slow. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 22:00:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 03:00:16 GMT Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <0086500d$0$26916$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 15:29:03 +1300, greg wrote: > Generally, I think you're going to have quite a battle on your hands to > get a pure Python implementation to run as fast as a real Z80, if it's > even possible at all. And if you do succeed, the code will be pretty > awful (due to things such as not being able to use named constants). I don't know about that... Python on a 2GHz processor (which is more or less entry-level for desktop PCs these days), emulating something which used to run at 2.5MHz? Even if the Python code does 1000 times more work, the modern processor is nearly 1000 times faster, so your Python code won't be much slower than the first generation Z80. The latest Z80 processors operate at 50MHz. That still gives you a factor of 40 to work with. Write your Python carefully, optimizing only the bits that *need* optimizing, and perhaps using a few C extensions or Psyco, and I think you have a good chance of being close enough to the speed of a real Z80. -- Steven From http Thu Nov 12 22:08:39 2009 From: http (Paul Rubin) Date: 12 Nov 2009 19:08:39 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> Message-ID: <7x8webruiw.fsf@ruckus.brouhaha.com> Duncan Booth writes: > > http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php > > > Thanks for that link. I think it pretty well agrees with my first > impressions of Go: It looks like a not-so-interesting C follow-on, but the article doesn't describe any of the parallelism stuff. > The lack of any kind of error handling, whether exceptions or > anything else is, I think, a killer. When you access a value out of > a map you have a choice of syntax: one way gives you a boolean flag > you can test to see whether or not the item was in the map, the > other either gives you the value or crashes the program (yes, the > documentation actually says 'crash'). Both of these are wrong: the > flag is wrong because it forces you to handle every lookup error > immediately and at the same place in the code; the crash is wrong > for obvious reasons. Nah, exceptions are an ugly effect that gets in the way of parallelism. Haskell handles lookups through its type system; dealing with lookup errors (say by chaining the Maybe type) is clean and elegant. Erlang handles it by crashing the process, and dealing with the crash through a supervision tree that cleans up after crashes and restarts the crashed processes. > What that article didn't mention, and what is possibly Go's real strong > point is that it has built-in support for parallel processing. Again though > the implementation looks weak... I'd like to know more about this; is there a link with a short write-up? I haven't gotten around to looking at the reference materials. > It has too many special cases: a lot of the builtin types can exist > only as builtin types: if they weren't part of the language you > couldn't implement an equivalent. I'd also like to have seen a more serious type system, like ML's or better. But they seemed to really be after a fast, lightweight compiler. Anyway, it doesn't like even slightly intended to be in the same space as Python. It's more like a de-bureaucratized replacement for Java. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 22:12:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 03:12:52 GMT Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> <7m3usvF3gec23U1@mid.individual.net> Message-ID: <00865301$0$26916$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 15:33:53 +1300, greg wrote: > Santiago Romero wrote: >>>How about >>> page, index = divmod(address, 16384) >> >> Surely, much better and faster :-) > > Not necessarily, because it involves a function call, and constructing > and deconstructing a result tuple. If you time them, you may well find > that the explicit shift and mask operations turn out to be faster. It's easy enough to test: >>> from timeit import Timer >>> t1 = Timer('a = n>>14; b = n & 16384', 'n=2137902') >>> t2 = Timer('a,b = divmod(n, 16384)', 'n=2137902') >>> min(t1.repeat(repeat=5)) 0.32850909233093262 >>> min(t2.repeat(repeat=5)) 0.54839301109313965 The shift and mask are a little faster on my machine, but that's certainly what I would call a micro-optimization. Unless the divmod call is the bottleneck in your code -- and it almost certainly won't be -- I don't think it's worth the obfuscation to use shift/mask. What should be done is write the code in the clearest way you can, then, only if it is it too slow, profile it to see where it actually needs optimizing. -- Steven From airia at acay.com.au Thu Nov 12 22:13:18 2009 From: airia at acay.com.au (Peter Nilsson) Date: Thu, 12 Nov 2009 19:13:18 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: "Alf P. Steinbach" wrote: > One reaction to has > been that turtle graphics may be off-putting to some > readers because it is associated with children's learning. [I'll be honest and say that I merely glanced at the two pdf files.] Who is your target audience? The opening Getting Started paragraph would probably put off many beginners right from the get go! You're talking about a 'first language' but throwing 'syntax', 'windows', 'graphics', 'networking', 'file and database access' and 'standard libraries' at them. The success of 'XXXX for Dummies' is certainly not their accuracy, but rather that they make far fewer assumptions that people already know the subject being tought! That assumption seems almost ingrained in every 'beginner' programming book I've ever seen! > What do you think? Whilst everyone knows children tend to think visually more than abstractly, the same is precisely true of adults. However, the ultimate problem with Turtle is that it ends up teaching a 'mathematical' perspective and it's far from intuitive how you map that perspective to tackling more real world issues. It's simply substituting one difficult abstraction with another. My recollection is that many children struggled with Turtle graphics because they had very little concept of trigonometry. [Why would they? Many wouldn't learn for another 2-10 years.] Adults tend to have even less concept since they almost never use trig (or much else from school ;-) in the real world. They can see the patterns and understand there's a logic to it, but they struggle replicating it. Get an angle wrong and you end up with a mess where it's not clear whether it's your algorithm or the maths that's at fault. The visual aspect might pique interest, but may put just as many people off. In any case, it won't relieve the difficulty of having to teach what is fundamentally an abstraction that doesn't have very good parallels with how people approach problems in the real world. Humans simply don't think like mathematicians^W computers. :-) I've met a lot of mathematics and comp sci teachers who honestly believe that you can't teach these subjects without a mathematical perspective. That stands in contrast to the number of people I see using spreadsheets with a very high proficiency who would never dream of saying they were good at mathematics or programming. -- Peter From aahz at pythoncraft.com Thu Nov 12 22:19:55 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Nov 2009 19:19:55 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >Esky is an auto-update framework for frozen python apps, built on top of >bbfreeze. It provides a simple API through which apps can find, fetch >and install updates, and a bootstrapping mechanism that keeps the app >safe in the face of failed or partial updates. Recently I was looking into distribution mechanisms, and I passed over bbfreeze because I saw no indication that Python 2.6 was supported. Kind of a bummer because esky looks pretty cool. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From hetchkay at gmail.com Thu Nov 12 22:27:31 2009 From: hetchkay at gmail.com (H Krishnan) Date: Fri, 13 Nov 2009 08:57:31 +0530 Subject: Python 2.6 and sys.exit() Message-ID: <1ab787d80911121927j1992416dl4d0007f8b4d3875b@mail.gmail.com> Hello, I have the following in exit.py: import sys sys.exit(0) I now try 'python -i exit.py': In 2.5, the script exits as I would expect. In 2.6, the following error is printed: Traceback (most recent call last): File "exit.py", line 2, in sys.exit(0) SystemExit: 0 >>> I couldn't find anything related to this in "What's new in 2.6". Is there any way I can get 2.6 to behave like 2.5? Thank you for your help, Regards, H. Krishnan -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Thu Nov 12 22:33:38 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 22:33:38 -0500 Subject: python parser overridden by pymol In-Reply-To: References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> Message-ID: <4AFCD392.6010106@ieee.org> Robert Kern wrote: >
    Jeremiah > H. Savage wrote: > >> To use pymol and numpy together, I now do the following: >> >> To ~/.bashrc add: >> PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol >> export PYMOL_PATH >> >> Then I can do the following in python: >> >> import numpy >> numpy.save('123',numpy.array([1,2,3])) >> numpy.load('123.npy') >> array([1, 2, 3]) >> import sys >> sys.path.append( "/usr/lib/pymodules/python2.5/pymol") >> import pymol >> pymol.finish_launching() >> pymol.importing.load("/path/to/file.pdb") > > No, do not do this. Add /usr/lib/pymodules/python2.5/ to your > $PYTHONPATH, *not* /usr/lib/pymodules/python2.5/pymol/. You will > continue to run into problems if you do it this way. You are not > supposed to put the directory *of* the package onto sys.path but > rather the directory that *contains* the package directory. > As I said before, I don't know pymol. But if that is the package name, then Robert is certainly right. You need to read the docs on pymol to see what they require. For example, it's surprising they require a separate PYMOL_PATH environment variable, since they can find their own directory path with the __file__ attribute of one of the modules. Anyway, one more generic comment. Rather than having that directory in both the bashrc file AND in your python source, I'd consider deriving the latter from the environment variable, once you determine that it's actually necessary. And of course you could strip the last node from the path in the environment variable before appending it to sys.path, if that's what's appropriate. DaveA From ryan at rfk.id.au Thu Nov 12 22:39:54 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 13 Nov 2009 14:39:54 +1100 Subject: ANN: esky 0.2.1 In-Reply-To: References: Message-ID: <1258083594.2715.18.camel@durian> > >Esky is an auto-update framework for frozen python apps, built on top of > >bbfreeze. It provides a simple API through which apps can find, fetch > >and install updates, and a bootstrapping mechanism that keeps the app > >safe in the face of failed or partial updates. > > Recently I was looking into distribution mechanisms, and I passed over > bbfreeze because I saw no indication that Python 2.6 was supported. Not sure if it's officially supported, but I do most of my development on Python 2.6 and bbfreeze hasn't given me any problems as yet. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From hetchkay at gmail.com Thu Nov 12 23:07:15 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 20:07:15 -0800 (PST) Subject: 2.6 and sys.exit() Message-ID: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Hello, I have the following in exit.py: import sys sys.exit(0) I now try 'python -i exit.py': In 2.5, the script exits as I would expect. In 2.6, the following error is printed: Traceback (most recent call last): File "exit.py", line 2, in sys.exit(0) SystemExit: 0 >>> I couldn't find anything related to this in "What's new in 2.6". Is there any way I can get 2.6 to behave like 2.5? Thank you for your help, Regards, H. Krishnan From rt8396 at gmail.com Thu Nov 12 23:10:29 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:10:29 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> On Nov 12, 7:44?pm, Steven D'Aprano wrote > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > assignment-as-an-expression is nothing compared to the dozens of man- > minutes saved by having one fewer line of code! OK, what *if* the variable would only be valid in *that* block and *that* block only! My first idea was to have the variable avaiable in the local scope (if that is correct terminology?) so if the conditional was in global space the value would be available in global space, alright? You follow me? Now forget all that and observe the following. ;-) if value=range(10): #this block *would* execute and "value" would be a valid name #but only IN this block!!! value.append(1) elif value=fetch(0): #this block would *never* execute value.append(1) value.append(1) -> this throws a NameError Is that different than how other languages handle "assignment-by- expression"? Will that avoid the cataclysmic downward spiral you speak of? I can't see any problems with it AND it can still be applied to myself and Carl's use cases. Anybody is welcome to comment...? From rt8396 at gmail.com Thu Nov 12 23:22:38 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:22:38 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Message-ID: <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> On Nov 12, 10:07?pm, hetchkay wrote: > Hello, > > I have the following in exit.py: > import sys > sys.exit(0) > > I now try 'python -i exit.py': > > In 2.5, the script exits as I would expect. > > In 2.6, the following error is printed: > > Traceback (most recent call last): > ? File "exit.py", line 2, in > ? ? sys.exit(0) > SystemExit: 0 > > > > I couldn't find anything related to this in "What's new in 2.6". Look here ;-) http://docs.python.org/library/exceptions.html#exceptions.SystemExit From rt8396 at gmail.com Thu Nov 12 23:26:43 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:26:43 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <71261a1b-1b56-4c37-bc0f-01049565c0ab@p28g2000vbi.googlegroups.com> PS: Python even answers questions: >>> import sys >>> help(sys.exit) Help on built-in function exit in module sys: exit(...) exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure). Just think of Python as a programmers version of the "Magic 8 balls". From hetchkay at gmail.com Thu Nov 12 23:32:38 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 20:32:38 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <8f5c9c64-cf21-4a1f-ba54-68d9f90ca8b1@f20g2000prn.googlegroups.com> Hello, Thanks for your help. I know what SystemExit is. In 2.5 as well SystemExit is raised when sys.exit() is called. For example: try: import sys sys.exit(0) except SystemExit: print "system exit raised" raise But I don't understand why the interpreter does not exit in 2.6 but does exit in 2.5. Well, I do not need to understand that but I need to know how to get the interpreter to exit in 2.6. Regards, Krishnan From highcar at gmail.com Thu Nov 12 23:32:57 2009 From: highcar at gmail.com (elca) Date: Thu, 12 Nov 2009 20:32:57 -0800 (PST) Subject: how to install python-spidermonkey on windows Message-ID: <26331307.post@talk.nabble.com> Hello all, im making some script with python mechanize, one of problem is it really hard to find which support javascript supported web client scraping or crawler. actually i was found some such as python-spidermonkey and pykhtml and so on. but most of all only support on linux . i want to make my python script with exe file. so definitely i have to install on windows platform. my question is ..are there any method to can install python-spidermonkey or pykhtml on windows platform? i really need to support windows platform. if anyone can hint or help really appreicate! thanks in advance Paul -- View this message in context: http://old.nabble.com/how-to-install-python-spidermonkey-on-windows-tp26331307p26331307.html Sent from the Python - python-list mailing list archive at Nabble.com. From gallium.arsenide at gmail.com Thu Nov 12 23:50:39 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 12 Nov 2009 20:50:39 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: On Nov 12, 11:22 pm, r wrote: > On Nov 12, 10:07 pm, hetchkay wrote: > > I have the following in exit.py: > > import sys > > sys.exit(0) > > > I now try 'python -i exit.py': > > > In 2.5, the script exits as I would expect. > > > In 2.6, the following error is printed: > > > Traceback (most recent call last): > > File "exit.py", line 2, in > > sys.exit(0) > > SystemExit: 0 > > > I couldn't find anything related to this in "What's new in 2.6". > > Look here ;-) > http://docs.python.org/library/exceptions.html#exceptions.SystemExit How does that answer the OP's question? Namely, how to make 2.6 behave like 2.5? (Even saying "You can't make 2.6 behave like 2.5" would have been a better answer.) Failing that, how about something that explains why 2.6 behaves differently than 2.5, and why one of them is better or more correct than the other? Personally, I think 2.6's is probably the more correct behavior. Specifically, if the point of the -i command line option is to force interactive mode after completion of the script (which in this case completed with sys.exit), then it should go to interactive mode regardless of whether the script terminates "normally" or not. I think 2.5's behavior of allowing interactive mode to be skipped is against the spirit of -i. Unless -i meant something different in 2.5. Is there some kind of environment variable to set up to control this? John From gallium.arsenide at gmail.com Fri Nov 13 00:02:56 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 12 Nov 2009 21:02:56 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> <8f5c9c64-cf21-4a1f-ba54-68d9f90ca8b1@f20g2000prn.googlegroups.com> Message-ID: <3eef8061-6422-4b1c-b60c-8770e233b1d5@h34g2000yqm.googlegroups.com> On Nov 12, 11:32?pm, hetchkay wrote: > But I don't understand why the interpreter does not exit in 2.6 but > does exit in 2.5. Well, I do not need to understand that but I need to > know how to get the interpreter to exit in 2.6. Well, taken at face value, I would say the answer is to not use the -i option. ;) But I assume you would like to be able to sometimes enter interactive mode after the script completes but sometimes not? That I don't know how to do, but I would think it is either very simple or impossible. Surely someone more knowledgeable will be able to say which it is. Also, if you present your reason for wanting such behavior, maybe people can suggest alternatives that will serve your needs, even if not exactly replicating what you had in 2.5. John From pavlovevidence at gmail.com Fri Nov 13 00:07:14 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 21:07:14 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <02f602e1-30f0-4b12-8048-75ecb44313b9@u7g2000yqm.googlegroups.com> On Nov 12, 6:37?am, Santiago Romero wrote: > > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > > ASpectrum, from C to Python + pygame. > > > The answer to your question is, "Use numpy". ?More details below. > > ?Let's see :-) > > > > ?How can I implement this in Python, I mean, define a 16 byte variable > > > so that high and low bytes can be accessed separately and changing W, > > > H or L affects the entire variable? I would like to avoid doing BIT > > > masks to get or change HIGH or LOW parts of a variable and let the > > > compiled code to do it by itself. > > > You can do clever memory slicing like this with numpy. ?For instance: > > > breg = numpy.zeros((16,),numpy.uint8) > > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > > This causes breg and wreg to share the same 16 bytes of memory. ?You > > can define constants to access specific registers: > > > R1L = 1 > > R1H = 2 > > R1 = 1 > > > breg[R1H] = 2 > > print wreg[R1] > > ?And how about speed? > > Assuming a 16 bit register named BC which contains 2 8 bit regiters (B > and C)... > > ?Will the above be faster than shifts and bit operations (<<, and,>> ) with new B and C values to "recalculate" BC when reading or > > changing either B, C or BC? I don't know. Strange thing about Python, the community generally isn't hellbent on speed so we don't usually memorize a bunch of facts like "X is faster than Y". I'm personally aware of only a few general rules of thumb on speed (like "local variables are much faster than globals" and "function calls have rather high overhead"). Obviously, given the problem you chose, you know you're going to have to worry about speed from the beginning. But since not many of us know speed details off-hand, you'll probably get a faster answer by just running the speed tests yourself. Having said that, I *suspect* the numpy approach I mentioned will be quite a bit faster than using bit operations and recalculating BC, but I really don't know. Carl Banks From pavlovevidence at gmail.com Fri Nov 13 00:10:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 21:10:04 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <0ceed898-487f-4b1f-ae45-0796b5bd3a9b@b2g2000yqi.googlegroups.com> On Nov 12, 6:29?pm, greg wrote: > I would be taking a different approach -- develop a prototype > in Python, concentrating on clarity rather than speed, and > later reimplement the core of the emulator as an extension > module, using Pyrex or Cython or otherwise. But keep in mind he said he was doing it just for fun. I don't know about you, but I find it much more fun to try to write fast Python than to write the fast stuff in C. Not as effective, but more fun. Carl Banks From nad at acm.org Fri Nov 13 00:10:32 2009 From: nad at acm.org (Ned Deily) Date: Thu, 12 Nov 2009 21:10:32 -0800 Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Message-ID: In article <008aa7ef-b945-4f70-b5e4-def66546eca2 at 2g2000prl.googlegroups.com>, hetchkay wrote: > I have the following in exit.py: > import sys > sys.exit(0) > > I now try 'python -i exit.py': > > In 2.5, the script exits as I would expect. > > In 2.6, the following error is printed: > > Traceback (most recent call last): > File "exit.py", line 2, in > sys.exit(0) > SystemExit: 0 > >>> > > I couldn't find anything related to this in "What's new in 2.6". > > Is there any way I can get 2.6 to behave like 2.5? Perhaps you don't want to be using the -i option? "-i When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command ..." http://docs.python.org/using/cmdline.html#generic-options If you don't want the interpreter to gain control on exit, don't use -i when you run the script. -- Ned Deily, nad at acm.org From s.selvamsiva at gmail.com Fri Nov 13 00:18:31 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Fri, 13 Nov 2009 10:48:31 +0530 Subject: regex remove closest tag In-Reply-To: <4AFC5F3C.6010302@mrabarnett.plus.com> References: <4AFC5F3C.6010302@mrabarnett.plus.com> Message-ID: On Fri, Nov 13, 2009 at 12:47 AM, MRAB wrote: > S.Selvam wrote: > >> Hi all, >> >> >> 1) I need to remove the tags which is just before the keyword(i.e >> some_text2 ) excluding others. >> >> 2) input string may or may not contain tags. >> >> 3) Sample input: inputstr = """start > href="some_url">some_text1 some_text2 keyword anything""" >> >> 4) I came up with the following regex, >> >> >> p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) >> s=p.search(inputstr) >> but second group matches both tags,while i need to match the recent >> one only. >> >> I would like to get your suggestions. >> >> Note: >> >> If i leave group('good1') as greedy, then it matches both the tag. >> >> ".*?" can match any number of any character, so it can match any > intervening "" tags. Try "[^<]*?" instead. > > Thanks a lot, p=re.compile(r'(?:\s*%s)'%(keyword),re.I|re.S) has done it ! -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From hetchkay at gmail.com Fri Nov 13 00:28:04 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 21:28:04 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: On Nov 13, 9:50?am, John Yeung wrote: > On Nov 12, 11:22 pm, r wrote: > > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > I have the following in exit.py: > > > import sys > > > sys.exit(0) > > > > I now try 'python -i exit.py': > > > > In 2.5, the script exits as I would expect. > > > > In 2.6, the following error is printed: > > > > Traceback (most recent call last): > > > ? File "exit.py", line 2, in > > > ? ? sys.exit(0) > > > SystemExit: 0 > > > > I couldn't find anything related to this in "What's new in 2.6". > > > Look here ;-) > >http://docs.python.org/library/exceptions.html#exceptions.SystemExit > > How does that answer the OP's question? ?Namely, how to make 2.6 > behave like 2.5? ?(Even saying "You can't make 2.6 behave like 2.5" > would have been a better answer.) > > Failing that, how about something that explains why 2.6 behaves > differently than 2.5, and why one of them is better or more correct > than the other? > > Personally, I think 2.6's is probably the more correct behavior. > Specifically, if the point of the -i command line option is to force > interactive mode after completion of the script (which in this case > completed with sys.exit), then it should go to interactive mode > regardless of whether the script terminates "normally" or not. ?I > think 2.5's behavior of allowing interactive mode to be skipped is > against the spirit of -i. ?Unless -i meant something different in 2.5. > > Is there some kind of environment variable to set up to control this? > > John I can understand the behavior from a '-i' point of view. My requirement is somewhat different. Consider a geometry tool that can be used to create objects, merge objects etc. I have python 'commands' for doing any of these operations and for saving the objects to a file. The user could write a file containing a set of commands (in python format) and load this file in the GUI. Optionally, one of the commands could be to exit in which case the GUI should shut down. I am using 'execfile' to execute the file, and this does not exit if the user has used sys.exit (or even if I expose a command called 'Exit' which calls sys.exit). May be I should not be using execfile but I am not sure what else I should use. The user-written file could contain loops and other constructs as well. -Krishnan From hetchkay at gmail.com Fri Nov 13 01:19:41 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 22:19:41 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <57f0c9b2-e63f-40b9-b638-96e710218261@w37g2000prg.googlegroups.com> On Nov 13, 10:28?am, hetchkay wrote: > On Nov 13, 9:50?am, John Yeung wrote: > > > > > On Nov 12, 11:22 pm, r wrote: > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > > I have the following in exit.py: > > > > import sys > > > > sys.exit(0) > > > > > I now try 'python -i exit.py': > > > > > In 2.5, the script exits as I would expect. > > > > > In 2.6, the following error is printed: > > > > > Traceback (most recent call last): > > > > ? File "exit.py", line 2, in > > > > ? ? sys.exit(0) > > > > SystemExit: 0 > > > > > I couldn't find anything related to this in "What's new in 2.6". > > > > Look here ;-) > > >http://docs.python.org/library/exceptions.html#exceptions.SystemExit > > > How does that answer the OP's question? ?Namely, how to make 2.6 > > behave like 2.5? ?(Even saying "You can't make 2.6 behave like 2.5" > > would have been a better answer.) > > > Failing that, how about something that explains why 2.6 behaves > > differently than 2.5, and why one of them is better or more correct > > than the other? > > > Personally, I think 2.6's is probably the more correct behavior. > > Specifically, if the point of the -i command line option is to force > > interactive mode after completion of the script (which in this case > > completed with sys.exit), then it should go to interactive mode > > regardless of whether the script terminates "normally" or not. ?I > > think 2.5's behavior of allowing interactive mode to be skipped is > > against the spirit of -i. ?Unless -i meant something different in 2.5. > > > Is there some kind of environment variable to set up to control this? > > > John > > I can understand the behavior from a '-i' point of view. My > requirement is somewhat different. Consider a geometry tool that can > be used to create objects, merge objects etc. I have python 'commands' > for doing any of these operations and for saving the objects to a > file. The user could write a file containing a set of commands (in > python format) and load this file in the GUI. Optionally, one of the > commands could be to exit in which case the GUI should shut down. I am > using 'execfile' to execute the file, and this does not exit if the > user has used sys.exit (or even if I expose a command called 'Exit' > which calls sys.exit). > > May be I should not be using execfile but I am not sure what else I > should use. The user-written file could contain loops and other > constructs as well. > > -Krishnan Hi, I had been starting my application with -i option. I have removed this now and made a few other changes and things work OK now. Thanks to everyone who helped in this. Regards, Krishnan From vmanis at telus.net Fri Nov 13 01:20:11 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 22:20:11 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <00864dc6$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <38E3CD73-E0D2-43A6-A757-6DB6A829D1A6@telus.net> When I was approximately 5, everybody knew that higher level languages were too slow for high-speed numeric computation (I actually didn't know that then, I was too busy watching Bill and Ben the Flowerpot Men), and therefore assembly languages were mandatory. Then IBM developed Fortran, and higher-level languages were not too slow for numeric computation. When I was in university, IBM released a perfectly horrible implementation of PL/I, which dynamically allocated and freed stack frames for each procedure entry and exit (`Do Not Use Procedures: They Are Inefficient': section heading from the IBM PL/I (G) Programmer's Guide, circa 1968). Everyone knew PL/I was an abomination of a language, which could not be implemented efficiently. Then MIT/Bell Labs/GE/Honeywell wrote Multics in a PL/I subset, and (eventually) it ran quite efficiently. When Bell Labs pulled out of the Multics effort, some of their researchers wrote the first version of Unix in assembly language, but a few years later rewrote the kernel in C. Their paper reporting this included a sentence that said in effect, `yes, the C version is bigger and slower than the assembler version, but it has more functionality, so C isn't so bad'. Everybody knew that high-level languages were too inefficient to write an operating system in (in spite of the fact that Los Alamos had already written an OS in a Fortran dialect). Nobody knew that at about that time, IBM had started writing new OS modules in a company-confidential PL/I subset. When I was in grad school, everybody knew that an absolute defence to a student project running slowly was `I wrote it in Lisp'; we only had a Lisp interpreter running on our system. We didn't have MacLisp, which had been demonstrated to compile carefully-written numerical programs into code that ran more efficiently than comparable programs compiled by DEC's PDP-10 Fortran compiler in optimizing mode. In an earlier post, I mentioned SBCL and Chez Scheme, highly optimizing compiler-based implementations of Common Lisp and Scheme, respectively. I don't have numbers for SBCL, but I know that (again with carefully-written Scheme code) Chez Scheme can produce code that runs in the same order of magnitude as optimized C code. These are both very old systems that, at least in the case of Chez Scheme, use techniques that have been reported in the academic literature. My point in the earlier post about translating Python into Common Lisp or Scheme was essentially saying `look, there's more than 30 years experience building high-performance implementations of Lisp languages, and Python isn't really that different from Lisp, so we ought to be able to do it too'. All of which leads me to summarize the current state of things. 1. Current Python implementations may or may not be performance-scalable in ways we need. 2. Reorganized interpreters may give us a substantial improvement in performance. More significant improvements would require a JIT compiler, and there are good projects such as Unladen Swallow that may well deliver a substantial improvement. 3. We might also get improvements from good use of Python 3 annotations, or other pragma style constructs that might be added to the language after the moratorium, which would give a compiler additional information about the programmer's intent. (For example, Scheme has a set of functions that essentially allow a programmer to say, `I am doing integer arithmetic with values that are limited in range to what can be stored in a machine word'.) These annotations wouldn't destroy the dynamic nature of Python, because they are purely optional. This type of language feature would allow a programmer to exploit the high-performance compilation technologies that are common in the Lisp world. Even though points (2) and (3) between them offer a great deal of hope for future Python implementations, there is much that can be done with our current implementations. Just ask the programmer who writes a loop that laboriously does what could be done much more quickly with a list comprehension or with map. -- v From danb_83 at yahoo.com Fri Nov 13 01:30:24 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Thu, 12 Nov 2009 22:30:24 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> On Nov 12, 1:52?pm, rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? Windows determines the double-click action based on the file extension. You just have to make sure that *.py files are associated with 2.x. http://support.microsoft.com/kb/307859 From vmanis at telus.net Fri Nov 13 01:36:09 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 22:36:09 -0800 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: <8FE6D77F-41DF-49ED-8C1F-C851D1CFC094@telus.net> On 2009-11-12, at 11:36, AK Eric wrote: > On Nov 12, 11:31 am, Terry Reedy wrote: >> Alf P. Steinbach wrote: >>> One reaction to >> http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle >>> graphics may be off-putting to some readers because it is associated >>> with children's learning. Take a look at Abelson and diSessa's _Turtle Geometry: The Computer as a Medium for Exploring Mathematics_ (MIT Press, 1986). This is most definitely not a kids' book. Chapter titles include `Topology of Turtle Paths', `Piecewise Flat Surfaces', and `Curved Space and General Relativity'. As well as being a very nice 2D graphics API, turtles let you explore very deep math. Of course, they also let you explore cybernetics and feedback; see some of the old MIT AI Lab reports on LOGO for that (you can find them at MIT's CSAIL lab website). For a lot of that, you actually need a robot turtle, like perhaps a LEGO Mindstorms robot. Seymour Papert (who did a lot of the MIT LOGO work) was, before his terrible motor accident, in research chair endowed by...LEGO. Hmmm... :) Of course, some people don't like Python itself because they are afraid of snakes. > I used Turtle back on the Apple in the early 80's... so I personally > have very positive feelings towards it ;) To each their own eh? I did my master's thesis on LOGO about 10 years before that, and I have VERY warm and fuzzy feelings about turtles :) -- v From apt.shansen at gmail.com Fri Nov 13 01:53:12 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 12 Nov 2009 22:53:12 -0800 Subject: New syntax for blocks In-Reply-To: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> Message-ID: <7a9c25c20911122253u6451e611ldfa2be88eb36aa32@mail.gmail.com> On Thu, Nov 12, 2009 at 8:10 PM, r wrote: > On Nov 12, 7:44 pm, Steven D'Aprano cybersource.com.au> wrote > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > > assignment-as-an-expression is nothing compared to the dozens of man- > > minutes saved by having one fewer line of code! > > OK, what *if* the variable would only be valid in *that* block and > *that* block only! My first idea was to have the variable avaiable in > the local scope (if that is correct terminology?) so if the > conditional was in global space the value would be available in global > space, alright? You follow me? Now forget all that and observe the > following. ;-) > > Assignment is a statement and not an expression in Python intentionally; its not just some random artifact. It was a decision. If you really want to overcome it, you need to show a SERIOUSLY huge amount of justification that goes far beyond 'hey, it saves me one line in certain situations'. You keep mentioning "elegant" and "clean" in the examples you've provided, but those terms (while often applied to Pythonisms) are very subjective. What you find elegant and clean, others may find prone to confusion or misunderstanding. There's a certain class of languages which treat assignments as expressions-- the C family most prominently. And some people love them and will forever seek it, as there is indeed a reduction of lines and/or code to express certain ideas if you use assignments as expressions. No one is really arguing against that. The argument against it is that it is extremely easy to screw up in ways which are extremely difficult to debug. > if value=range(10): > The problem with this is, its far too easy to type this but mean, "if value==range(10):" or some such. And then its far too hard to figure out why your program is wrong when it starts producing incorrect results. This has been a source of countless bugs over the years and years of C programming-- true, an excellent programmer will never make the mistake. But get some group of people together maintaining some codebase, and someone's gonna miss something, and others just will fail to see it as they scan over the code trying to figure out what's wrong. Granted, you can produce shorter and more concise code if you can make assignments expressions instead of statements. However, your code isn't anymore READABLE. And readability is more important then concise in Python, /on purpose/. It's true that you can usually produce a program in far fewer lines of Python code then you can in certain other languages not to be named; but that isn't the overriding goal. That's not a zen. There's no doctrine of, "Shorter is better". Readability counts is, though. The expression, "x=y" in a statement is far too easy to mess up with "x==y". You can try to do screwy things with the syntax like your original proposal of, "if x as y" to make it so a single missed = won't mess it up, but that doesn't really improve readability. It makes it less likely to accidentally screw things up, but also makes it very hard to scan code and determine where names are created and assigned to objects. Yeah, we use "as" in a few situations for assignment already. But those are all special constructs which stand on their own. Try/except, with, and import support it; but when scanning code those stand out on their own anyways, and none of them support arbitrarily complex expressions. The if statement does. The "as" can become lost within that expression, and when looking in the block of code you can easily miss where the binding occurs. The proposal that the variable exists only within the 'if' block is a non-starter; Python's namespaces don't work like that, they don't have arbitrary blocks of private variables. You just have your local, global, and builtin namespace (and static nested namespaces for closures)... changing that is a whooooooooole other can of worms, and this is not the proposal to do it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Fri Nov 13 01:58:27 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 12 Nov 2009 22:58:27 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> On Nov 11, 10:21?pm, "Alf P. Steinbach" wrote: > One reaction to has > been that turtle graphics may be off-putting to some readers because it is > associated with children's learning. > > What do you think? How about calling it Raptor Graphics that will please everyone ;-) Raymond From vmanis at telus.net Fri Nov 13 02:09:57 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 23:09:57 -0800 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: <812E8D48-258E-4164-935E-F2810D21E9F7@telus.net> On 2009-11-12, at 19:13, Peter Nilsson wrote: > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > This paragraph is based upon a complete misunderstanding of turtle geometry. You do NOT use trigonometry to teach it, because the goal isn't to replicate cartesian geometry. The whole point about turtle geometry is that the student viscerally imagines him/herself BEING the turtle, and moving around the room according to the succession of FORWARD and TURNRIGHT commands. This is easier to visualize when one has an actual robot that draws pictures on butcher paper, as the second iteration of the MIT/BBN turtle work did (and they worked in middle schools, Grades 4-8, so there was no issue of trigonometry). > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. Kindly explain to me the difference between `algorithm' and `maths' here. I believe you just said that if there's a bug in the design, the program won't work. Hmmm. This reminds me of a well-known anecdote about the original LOGO study done at Muzzey High in Lexington, MA, in 1968. A group of NSF funding people was doing a tour of the school, and they came across a Grade 5 student who was doing a family tree program. The NSF people were impressed by the complexity of the program. One of them said in a patronizing tone, `I guess this stuff really helps you learn math'. She got quite angry, and responded, `This stuff has NOTHING to do with math!' > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) Having taught grade 8 math, I can tell you that cartesian geometry is much LESS intuitive to people that are learning it than the relative polar coordinates of turtle geometry are. (`Oh, you want to get to the mall food court? Turn left, and walk past about 10 stores. The food court is right after the Gap.') > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. It is true that you can't teach computer science to children without having a strong understanding of the mathematical foundations. It is also true that when you teach it to children that you very carefully hide the mathematical formalism. I might point out that the people who had most to do with the invention of turtle geometry were Wally Feurzeig (who was my boss when I worked at BBN in the 1970s) and Seymour Papert. Papert had spent a lot of time working with Jean Piaget in Switzerland. If you read the original LOGO memos, you will see his clear explanations on how this material ought to be taught to people with no math background, including children who are too young to do symbolic thinking (that kicks in in the early teens). That's why the visceral `I am a turtle' approach works well with middle-school kids. -- v > > -- > Peter > -- > http://mail.python.org/mailman/listinfo/python-list From steve at REMOVE-THIS-cybersource.com.au Fri Nov 13 02:19:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 07:19:08 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <00868cb9$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > When I was approximately 5, everybody knew that higher level languages were too slow for high-speed numeric computation (I actually didn't know that then, I was too busy watching Bill and Ben the Flowerpot Men), and therefore assembly languages were mandatory. Then IBM developed Fortran, and higher-level languages were not too slow for numeric computation. Vincent, could you please fix your mail client, or news client, so that it follows the standard for mail and news (that is, it has a hard-break after 68 or 72 characters? Having to scroll horizontally to read your posts is a real pain. -- Steven From alfps at start.no Fri Nov 13 02:51:30 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 13 Nov 2009 08:51:30 +0100 Subject: Does turtle graphics have the wrong associations? In-Reply-To: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> References: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> Message-ID: * Raymond Hettinger: > On Nov 11, 10:21 pm, "Alf P. Steinbach" wrote: >> One reaction to has >> been that turtle graphics may be off-putting to some readers because it is >> associated with children's learning. >> >> What do you think? > > How about calling it Raptor Graphics that will please everyone ;-) He he. :-) import turtle as raptor raptor.shape( "triangle" ) def draw_poison_bush( level, angle, stem_length ): start_pos = raptor.pos() raptor.left( angle ) raptor.forward( stem_length ) if level > 0: draw_poison_bush( level-1, 30, 0.7*stem_length ) draw_poison_bush( level-1, 0, 0.85*stem_length ) draw_poison_bush( level-1, -37, 0.65*stem_length ) raptor.right( angle ) raptor.goto( start_pos ) raptor.title( "A DANGEROUS poison bush!" ) raptor.left( 90 ) raptor.back( 180 ) draw_poison_bush( 6, 0, 80 ) raptor.mainloop() Cheers, - Alf From vmanis at telus.net Fri Nov 13 02:53:10 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 23:53:10 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9F5C4977-87BC-446B-AFE7-7C7BAE83ABAC@telus.net> On 2009-11-12, at 23:19, Steven D'Aprano wrote: > On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > > Vincent, could you please fix your mail client, or news client, so > that it follows the standard for mail and news (that is, it has a > hard-break after 68 or 72 characters? My apologies. Will do. > Having to scroll horizontally to read your posts is a real pain. At least you're reading them. :) -- v -------------- next part -------------- An HTML attachment was scrubbed... URL: From catalinfest at gmail.com Fri Nov 13 03:06:20 2009 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Fri, 13 Nov 2009 00:06:20 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: Tkinter is deafult on python . Is more easy to use any editor text (geany). I don?t see a good IDE for GUI On Nov 9, 6:49?am, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . From alfps at start.no Fri Nov 13 03:11:29 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 13 Nov 2009 09:11:29 +0100 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: * Peter Nilsson: > "Alf P. Steinbach" wrote: >> One reaction to has >> been that turtle graphics may be off-putting to some >> readers because it is associated with children's learning. > > [I'll be honest and say that I merely glanced at the two > pdf files.] > > Who is your target audience? Someone intelligent who doesn't know anything or very much about programming and wants to learn general programming. > The opening Getting Started > paragraph would probably put off many beginners right from > the get go! You're talking about a 'first language' but > throwing 'syntax', 'windows', 'graphics', 'networking', > 'file and database access' and 'standard libraries' at them. > > The success of 'XXXX for Dummies' is certainly not their > accuracy, but rather that they make far fewer assumptions > that people already know the subject being tought! That > assumption seems almost ingrained in every 'beginner' > programming book I've ever seen! Yes, I totally agree with not assuming knowledge. However, (without implying that you think so) lack of knowledge is not lack of brains. I assume an intelligent reader, someone who doesn't balk at a few technical terms here and there. Pedagogically it's a challenge, because a correspondence between knowledge and brains is so often assumed, and the field of knowledge accordingly (but mostly by historical accident) divided up into "basic", "medium level" and "advanced". And so an explanation of something that's trivial to someone who already knows, something in the "basic" category, might seem (to someone who confuses knowledge with brains) to assume a dumb or childish reader. But in reality the intellectual challenge of something in the traditional "basic" category can be greater than for something conventionally regarded as "advanced". So I strive to not make any distinction between traditional levels of knowledge in the field, but rather to focus on what's relevant and on how hard something would be to grasp for someone without the base knowledge and experience. >> What do you think? > > Whilst everyone knows children tend to think visually more > than abstractly, the same is precisely true of adults. > However, the ultimate problem with Turtle is that it ends > up teaching a 'mathematical' perspective and it's far from > intuitive how you map that perspective to tackling more > real world issues. It's simply substituting one difficult > abstraction with another. > > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. > > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) > > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. Uhm, yes, I agree. I've tried to limit the math to what most anyone can handle. No geometry so far! Although it will have to be discussed for graphics. But although most ch 2 examples are graphical, graphics generation as such is not discussed. It's like the difference between driving a car and designing one. You don't need an engineering degree to drive a car. :-) Cheers, & thanks, - Alf From rjh at see.sig.invalid Fri Nov 13 03:27:00 2009 From: rjh at see.sig.invalid (Richard Heathfield) Date: Fri, 13 Nov 2009 08:27:00 +0000 Subject: Does turtle graphics have the wrong associations? References: Message-ID: In , Alf P. Steinbach wrote: > But in reality the intellectual challenge of something in the > traditional "basic" category can be greater than for something > conventionally regarded as "advanced". And consequently is much harder to teach. I have nothing but admiration for primary school children and their teachers, because children can *actually learn to read*. Once you can read, future learning objectives become much easier to achieve. Same with programming - once you've grokked the core ideas, the rest is more or less window dressing in comparison. The gap between nought and one is much greater than the gap between one and a thousand. > It's like > the difference between driving a car and designing one. You don't > need an engineering degree to drive a car. :-) Right. Nowadays, you need a degree in electronics instead. -- Richard Heathfield Email: -http://www. +rjh@ "Usenet is a strange place" - dmr 29 July 1999 Sig line vacant - apply within From catalinfest at gmail.com Fri Nov 13 03:39:19 2009 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Fri, 13 Nov 2009 00:39:19 -0800 (PST) Subject: Create video with text? References: <4afbb851$0$22531$607ed4bc@cv.net> Message-ID: On Nov 12, 9:24?am, AK wrote: > Hi, what would be the best python package (or a framework that can be > scripted in python) that can make a video with text moving around, > jumping, zooming in/out and various other text effects? See the > following link for an example: > > Yes, If you using both blender 3d and python . From eckhardt at satorlaser.com Fri Nov 13 03:43:14 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 13 Nov 2009 09:43:14 +0100 Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <2qivs6-v5e.ln1@satorlaser.homedns.org> Santiago Romero wrote: > Well, In the above concrete example, that would work, but I was > talking for multiple code lines, like: > > > #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) > > #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > reg = r_op > > #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) > > #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmpl = Z80ReadMem(r_op); \ > r_tmph = Z80ReadMem((r_op)+1); \ > dreg=r_tmp > > #define STORE_nn_rr(dreg) \ > r_opl = Z80ReadMem(r_PC); r_PC++;\ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmp = dreg; \ > Z80WriteMem((r_op),r_tmpl, regs); \ > Z80WriteMem((r_op+1),r_tmph, regs) Someone writing such code and calling it C should be taken behind the barn and shot. Which system runs Python but doesn't have a C compiler that knows inlining? > But it seems that is not possible :-( Thank getenv("DEITY") not! Uli From anders.u.persson at gmail.com Fri Nov 13 03:55:00 2009 From: anders.u.persson at gmail.com (uap12) Date: Fri, 13 Nov 2009 00:55:00 -0800 (PST) Subject: A beginner question about GUI use and development Message-ID: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Hi! I have written som Python programs but no one with a GUI yet, i have look around and found a lot of diffrent gui module. I will develop program that will use a small amout of GUI part eg. program to show status about server etc. I have looked att wxWidget, but i like a rekommendation here (Will develop Windows program but somtimes OSX to) When i givet the program away i like to pack it, so the enduser just run it, i don't like to tell the user to install Python, and/or som GUI package. is this possible. In the beginning it is okej to code the gui "by hand" to learn but after that i like som kind of GUI-designtool, and god to recommade ?? I know this is basic question, but i have't found any god answer so if some takes time to answer i would be happy. Best regards Anders From mal at egenix.com Fri Nov 13 04:03:54 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 13 Nov 2009 10:03:54 +0100 Subject: open source linux -> windows database connectivity? In-Reply-To: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> References: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> Message-ID: <4AFD20FA.2010408@egenix.com> Tony Schmidt wrote: >> Note: The client part of this product is free. You only need to >> get a license for the server part. > > Yeah, but don't I need the server part to make the connection? Sure, but you don't need to get a license per client, unlike for e.g. the combination mxODBC + EasySoft OOB. Regards, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 13 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 dpalmboom at evafoam.co.za Fri Nov 13 04:40:57 2009 From: dpalmboom at evafoam.co.za (Dylan Palmboom) Date: Fri, 13 Nov 2009 11:40:57 +0200 Subject: Choosing GUI Module for Python Message-ID: -----Original Message----- From: catalinfest at gmail.com [mailto:catalinfest at gmail.com] Sent: 13 November 2009 10:06 AM To: python-list at python.org Subject: Re: Choosing GUI Module for Python Tkinter is deafult on python . Is more easy to use any editor text (geany). I don?t see a good IDE for GUI On Nov 9, 6:49?am, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these things . . . PyQt is an excellent toolkit for us at work. It has nice documentation and very easy to learn. We use Eclipse IDE at work with the PyDev workspace loaded for the coding. Eclipse has nice features for integration with subversion all from one place, so it makes it more manageable when you have more than 1 person working on a project. There's only 2 of us here working together, but the subversion integration makes our lives so much easier. We use eclipse for gui design in code or we use Qt Creator which is very intuitive to use if you want to design a gui visually. Also, there's a python script we use called MakePyQt that you can find here: http://www.qtrac.eu/pyqtbook.tar.gz to convert the ui files from Qt Creator to python files. Then all you need to do is implement these generated python files in your program and add functionality etc. From michael at stroeder.com Fri Nov 13 05:04:57 2009 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 13 Nov 2009 11:04:57 +0100 Subject: Linux, Python 2.5.2, serverless binding LDAP? In-Reply-To: References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: <9jnvs6-s4f.ln1@nb2.stroeder.com> Kevin Cole wrote: > On Nov 12, 8:01 pm, alex23 wrote: >> On Nov 13, 10:47 am, Kevin Cole wrote: >>> I recently asked our IT department how to gain access to an >>> addressbook. After carefully explaining that I was on a Linux system >>> using Python, I got the reply: >>> "You should use our LDAP. With LDAP you can pull any data you want >>> from Active Directory. On our network, the serverless binding address >>> for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." >>> with the actual "..." filled in. >>> I don't know squat about LDAP, but installed the python-ldap deb, and >>> started glancing at the documentation on-line. I didn't see anything >>> obvious for working with the URI above. Can I work w/ it? If so, a >>> short example, please? >>> Thanx. >> http://www.python-ldap.org/doc/html/ldapurl.html#example > > Ah, it wasn't clear to me that "localhost:1389" meant serverless. > Armed with that, I'm off to experiment. localhost:1389 means localhost on port 1389. It has nothing to do with server-less bind. Server-less bind is based on a DNS lookup: Let's say you want to query the DNS server for returning the LDAP server(s) for naming context dc=uninett,dc=no then invoke on the command-line: $ host -t srv _ldap._tcp.uninett.no. _ldap._tcp.uninett.no has SRV record 0 0 389 ldap.uninett.no. That is also heavily used with MS AD. Off course you can do this SRV lookup with http://pydns.sf.net which is actually done in my LDAP client http://web2ldap.de: http://demo.web2ldap.de:1760/web2ldap?ldap:///dc=uninett,dc=no??one Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com From gonatan at gmx.de Fri Nov 13 05:24:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Fri, 13 Nov 2009 11:24:10 +0100 Subject: A beginner question about GUI use and development In-Reply-To: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <4AFD33CA.8030804@gmx.de> uap12 wrote: > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. So Tkinter would be your choice, cause its shipped with Python ... > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? http://wiki.python.org/moin/GuiProgramming From 4564 at 755189.45 Fri Nov 13 05:38:08 2009 From: 4564 at 755189.45 (Enrico) Date: Fri, 13 Nov 2009 11:38:08 +0100 Subject: A beginner question about GUI use and development References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> "uap12" ha scritto nel messaggio news:1a446fef-4250-4152-8c30-cfe2edb61089 at j4g2000yqe.googlegroups.com... > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) You have a lot of option. I use wx since I need an OS native interface and work on Windows, Linux and Mac. But your needs could be different.so maybe QT could be a good choice for you, or Tk. I suggest to give them a try and decide. You can find many examples and without writing to much code you can have an idea on the library. For example for the wx you have a complete suite of example that you can run and modify. > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. This is not related to the GUI. If you don't want your user to have Python and other packages installed you need to "build" the application. Look at py2exe and friends (freeze, py2app,...). You can prepare an application with everything needed to run it and install/copy it on the user machine. Regards, Enrico From tartley at tartley.com Fri Nov 13 05:40:28 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 13 Nov 2009 02:40:28 -0800 (PST) Subject: bootstrapping on machines without Python Message-ID: While examining py2exe et al of late, my thoughts keep returning to the idea of writing, in C or similar, a compiled stand-alone executable 'bootstrapper', which: 1) downloads and install a Python interpreter if none exists 2) runs the application's Python source code using this interpreter. An application source code could be distributed with this small exe to wrap its top level 'main.py', and the application could then be run on machines which do not (yet) have Python installed. The goal of this is to provide a way for end-users to download and double-click a Python application, without having to know what Python is or whether (an appropriate version of) it is installed. This method has some disadvantages compared to using py2exe et al, but it has the advantage that a small application would remain small: there is no need to bundle a whole interpreter with every application. From an advocacy point of view, it also must help that merely running such an application would seamlessly put a usable Python interpreter installed and on the PATH on Windows boxes. Even my very limited understanding of the issues is enough to see that the idea is far from trivial. I'm aware that great minds are working on related and overlapping problems, so I thought I'd ask whether many people have done this already, and if not, is there any value in taking the trivial first step described above? ie. Ignore all complications, and write a simple C program to download & install an interpreter, then use that to run my Python. In the long run, to be useful for real projects, the bootstrapper would need to manage some nasty details: * different versions of the interpreter for different applications * download required packages * manage conflicting versions of packages I'm hoping that these thorny problems will be solved, if they aren't already, by the great minds working on packaging, etc. I'm very aware that I don't know anything at all about this, compared to many on the list. Be gentle with me. :-) From python.list at tim.thechases.com Fri Nov 13 05:48:59 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 13 Nov 2009 04:48:59 -0600 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4AFD399B.4060705@tim.thechases.com> Steven D'Aprano wrote: > Vincent, could you please fix your mail client, or news > client, so that it follows the standard for mail and news > (that is, it has a hard-break after 68 or 72 characters? This seems an awfully curmudgeonly reply, given that word-wrapping is also client-controllable. Every MUA I've used has afforded word-wrap including the venerable command-line "mail", mutt, Thunderbird/Seamonkey, pine, Outlook & Outlook Express...the list goes on. If you're reading via web-based portal, if the web-reader doesn't support wrapped lines, (1) that sounds like a lousy reader and (2) if you absolutely must use such a borked web-interface, you can always hack it in a good browser with a greasemonkey-ish script or a user-level CSS "!" important attribute to ensure that the
    or

    in question wraps even if the site tries to specify otherwise. There might be some stand-alone news-readers that aren't smart enough to support word-wrapping/line-breaking, in which case, join the 80's and upgrade to one that does. Or even just pipe to your text editor of choice: vi, emacs, ed, cat, and even Notepad has a "wrap long lines" sort of setting or does the right thing by default (okay, so cat relies on your console to do the wrapping, but it does wrap). I can see complaining about HTML content since not all MUA's support it. I can see complaining about top-posting vs. inline responses because that effects readability. But when the issue is entirely controllable on your end, it sounds like a personal issue. -tkc From davea at ieee.org Fri Nov 13 06:05:48 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 13 Nov 2009 06:05:48 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> Message-ID: <4AFD3D8C.7020108@ieee.org> Dan Bishop wrote: > On Nov 12, 1:52 pm, rantingrick wrote: > >> Hello, >> >> Currently i am using 2.6 on Windows and need to start writing code in >> 3.0. I cannot leave 2.x yet because 3rd party modules are still not >> converted. So i want to install 3.0 without disturbing my current >> Python2.x. What i'm afraid of is that some SYSVARIABLE will get >> changed to Python3.0 and when i double click a Python script it will >> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts >> from the command line... > python3.x myscript.py >> >> So how do i do this? Is my fear unfounded? >> > > Windows determines the double-click action based on the file > extension. You just have to make sure that *.py files are associated > with 2.x. > http://support.microsoft.com/kb/307859 > > > And if someone simply wants to check or change these associations without all the Explorer nonsense, one can use assoc.exe and ftype.exe Using them without parameters lists all association information. Using them with parameters let you examine and/or change a single association. M:\Programming\Python\sources\dummy>assoc .py .py=Python.File M:\Programming\Python\sources\dummy>ftype python.file python.file="C:\PROGFI~1\ACTIVE~1\python.exe" "%1" %* Similarly for .pyw extension DaveA From kmisoft at gmail.com Fri Nov 13 06:06:43 2009 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Fri, 13 Nov 2009 14:06:43 +0300 Subject: A beginner question about GUI use and development In-Reply-To: <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> Message-ID: Hi, I have working with wxPython since about 2003 and still have a "mixed" feeling about it. Periodically I was catched in some traps especially in graphics-related parts of my code (just one example: try to find documentation about DC.Blit behaviour then UserScale != 1.0). For fresh-starters I would recommend to try a PyQT first (IMHO good commercial background/support is a big plus for any open-source project). Another option (my person choise so far) is to switch to web-based interface. My personal choice - web based interface using Django. Vladimir Ignatov >> Hi! >> I have written som Python programs but no one with a GUI yet, >> i have look around and found a lot of diffrent gui module. >> >> I will develop program that will use a small amout of GUI part >> eg. program to show status about server etc. >> >> I have looked att wxWidget, but i like a rekommendation here >> (Will develop Windows program but somtimes OSX to) From sromero at gmail.com Fri Nov 13 06:20:41 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 03:20:41 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> I'm going to quote all the answers in a single post, if you all don't mind: > [greg] > But keep in mind that named "constants" at the module level > are really global variables, and therefore incur a dictionary > lookup every time they're used. > > For maximum speed, nothing beats writing the numeric literals > directly into the code, unfortunately. So, finally, there are not constants available in python? (Like:) #define R1 1 > Generally, I think you're going to have quite a battle on > your hands to get a pure Python implementation to run as > fast as a real Z80, if it's even possible at all. Well... I'm trying to emulate the basic Z80, clocked at 3.5Mhz.. I hope python in a 2Ghz computer can emulate a 3.5Mhz machine ... Finally, if it's not possible... well, then I would just have some fun... :-) > [Steven D'Aprano] > The shift and mask are a little faster on my machine, but that's > certainly what I would call a micro-optimization. Unless the divmod call > is the bottleneck in your code -- and it almost certainly won't be -- It can be a real bottleneck. An emulator executes continously machine code instructions. Those machine code instructions are read from memory, and operands are read from memory too. The minimum opcode (00h -> NOP) requires 1 memory read, and the CPU task is read from mem & decode & execute. My problem is that I would need to "encapsulate" Memory reads and Memory Writes in functions. In C I use #define so that: - No function call is done (?code unrolling?) - I can "call" my function so I don't have to manually repeat my code - I can optimize my "#define" macro just once and all the "calls" are optimized too. This way (in C) I can write readable code and the compiler replaces my "readable macros" with the final code. > I don't think it's worth the obfuscation to use shift/mask. An idea. I think I'm going to write a layer previous to my python program, to allow to use macros in my emulator, and generate the final .py program with a script. VERY SIMPLE EXAMPLE: My program: File emulator.pym: ================================== #!/usr/bin/python import blah import sys MACRO BEGIN Z80WriteMem( address, value ) blablablah inc blah p = p + x MACRO END MACRO BEGIN Z80ReadMem( address ) ( memory[address>>4][blah] ) MACRO END (more code) pepe = @@@Z80ReadMem( reg_A ) (more code) @@@Z80WriteMem( 0x121212, value ) ================================== And then, use a script to replace macro calls @@@ by the final code. This way I could write my emulator with "macros" and my "preprocessor" would rewrite the final .py files for the "binary" releases. While I can keep the .pym files as the "real" source (because .py files would be generated from .pym macro-files). Can the above be easily done with another already-existing application? (example: can m4 do this job)? From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:04:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:04:32 -0300 Subject: 2to3 ParseError with UTF-8 BOM References: <50ad856e-8118-4374-82a4-58243ae3434b@13g2000prl.googlegroups.com> Message-ID: En Fri, 06 Nov 2009 14:12:57 -0300, Farshid escribi?: > On Nov 5, 7:18 pm, Benjamin Peterson wrote: > >> Try the 2to3 distributed in Python 3.1. > > I get the same error with the 2to3 script in Python 3.1 Reported as http://bugs.python.org/issue7313 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:04 -0300 Subject: Python C API and references References: Message-ID: En Thu, 12 Nov 2009 06:23:54 -0300, lallous escribi?: > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I > don't need the reference to py_val I should decrement the reference > after this call? If you own a reference to py_val, and you don't need it anymore, you must decrement it. It doesn't matter if you call PyObject_SetAttrString or whatever, except when the called function says it "steals" a reference. > So for example: > > PyObject *py_val = PyInt_FromLong(5) > PyObject_SetAttrString(py_obj, "val", py_val); > Py_DECREF(py_val) > > Right? Yes, because PyInt_FromLong returns a new reference, and you own it. > If so, take sysmodule.c: > > if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) > return NULL; > > Shouldn't they also call Py_DECREF(Py_None) ? No, because the reference count of Py_None was not incremented previously; the code doesn't own a reference to Py_None at that time. It's not the same as the example above. > Same logic applies to PyDict_SetItemString() and the reference should be > decrement after setting the item (ofcourse if the value is not needed). Yes, same as your first example. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:21 -0300 Subject: Unexpected python exception References: <7d121326-ab5f-4151-8edb-f69bc6f9dee5@b36g2000prf.googlegroups.com> Message-ID: En Wed, 11 Nov 2009 11:11:31 -0300, Ralax escribi?: > On Nov 11, 6:59 pm, Richard Purdie wrote: >> def B(): >> os.stat("/") >> import os >> >> Traceback (most recent call last): >> File "./test.py", line 12, in >> B() >> File "./test.py", line 8, in B >> os.stat("/") >> UnboundLocalError: local variable 'os' referenced before assignment >> >> If I remove the "import os" from B(), it works as expected. >> From what I've seen, its very unusual to have something operate >> "backwards" in scope in python. Can anyone explain why this happens? > > One word, Python treat objects in a function or method-scope as > locals. Not exactly; from the Language Reference [1]: "The following constructs bind names: formal parameters to functions, import statements, class and function definitions (these bind the class or function name in the defining block), and targets that are identifiers if occurring in an assignment, for loop header, or in the second position of an except clause header. The import statement of the form ?from ...import *? binds all names defined in the imported module, except those beginning with an underscore. This form may only be used at the module level. [...] If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." > So os is not defined in B(), is it right? "os" is a local name due to import, and starts uninitialized; using it before it is initialized raises UnboundLocalError [1] http://docs.python.org/reference/executionmodel.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:31 -0300 Subject: questions regarding stack size use for multi-threaded python programs References: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Message-ID: En Mon, 09 Nov 2009 16:05:31 -0300, Eyal Gordon escribi?: > background: > we are using python 2.4.3 on CentOS 5.3 with many threads - and our > shell's > default stack size limit is set to 10240KB (i.e. ~10MB). > > we noticed that python's Threading module appears to create threads with > this value as their stack size (we ran a sample program that creates 10 > threads and measured its virtual memory size, then reduced the stack size > limit of the shell to 5120KB - and saw that the program's virtual memory > size was reduced by ~50MBs). > > the problem: > our program uses numerous threads, and thus the virtual memory size gets > to > be very large. we would like to reduce the size of the stack to reduce > this > size. we were looking for information about recommendation for the stack > size to use, but found none. You can set the thread stack size (for threads that are going to be created, not existing threads) using threading.stack_size(SIZE) http://docs.python.org/library/threading.html#threading.stack_size > questions: > 1. is there some rule-of-thumb for the recommended stack size for python > programs of various sorts? No idea. I've been always happy with the default settings. > 2. is there a way for us, at runtime (from inside the code or outside the > process), to find how much of a thread's stack we are using (in KB or > some > other size units)? see top(1) > 3. when we define local objects - do the objects themselves get > allocated on > the stack - or are they allocated on the heap and only references to them > are kept on the stack? They're allocated on the heap, and most references to objects are on the heap too. The Python stack of execution frames is allocated on the heap too. Basically, the OS stack is used for local variables in C code only. > 4. would the size of the stacks (which are probably not really allocated > by > the linux virtual memory sub-system, unless used) have a noticeable > performance effect on a python program? same question regarding the use > of a > large number of threads? I think it doesn't matter, unless you create so many threads as to exhaust the available addressing space (in 32bits, 4GB address space and 10MB per thread means 400 threads maximum). -- Gabriel Genellina From sromero at gmail.com Fri Nov 13 07:21:00 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 04:21:00 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> Message-ID: <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> > > #define STORE_nn_rr(dreg) \ > > ? ? ? ? ? ? ? ? ? ? ? ? r_opl = Z80ReadMem(r_PC); r_PC++;\ > > ? ? ? ? ? ? ? ? ? ? ? ? r_oph = Z80ReadMem(r_PC); r_PC++; \ > > ? ? ? ? ? ? ? ? ? ? ? ? r_tmp = dreg; \ > > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op),r_tmpl, regs); \ > > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op+1),r_tmph, regs) > > Someone writing such code and calling it C should be taken > behind the barn and shot. That code is mine and maybe you should look the context before doing such kind of affirmations. In the Intel Pentium and P-II ages, I started to wrote the very first Spectrum emulator in C. With that "cpu power", emulators had to be written in ASM to be capable to emulate the destination machines at 100% full speed in multitasking systems. In the emulation world, every CPU cycle you can save is gold, and writing the above code as inline code saved lots of CALLS, PUSHs/POPs (parameters to stack), and RETs. That allowed ASpectrum to run 100% speed on old computers and even to be ported to the Sega Dreamcast's 200Mhz CPU. Think that Z80ReadMem() can be called up to 6 times in each emulated CPU-cycle. Saving 6 CALLs, 6 PUSHes, 6 POPs, and 6 RETs in each cycle of the 3.500.000 of Hz **did** make the difference that allow Aspectrum to run at 100% speed in ancient machines. Obviously, I prefer to write well structured code but I had to sacrifize SIZE by SPEED (size as inline code is included in the binary executable file). Each coding technique has their application environment and using inline macros, like loop unrolling or using "register" variables fall bellow all the techniques needed to write a fast emulator. Now I'm porting the emulator to a scripted language, so I need even more previous design ideas before starting to code, so that I can achieve (I hope I'll be able to do it with this group's help) 100% cpu speed in an standard desktop PC. > > ?But it seems that is not possible :-( > > Thank getenv("DEITY") not! Well, I don't agree with that, "constants" and "macros" wouldn't hurt python, when using them in the right situations. Thanks a lot anyway for all your help :-) From steve at REMOVE-THIS-cybersource.com.au Fri Nov 13 07:24:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 12:24:13 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <0086d43a$0$26932$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 04:48:59 -0600, Tim Chase wrote: > There might be some stand-alone news-readers that aren't smart enough to > support word-wrapping/line-breaking, in which case, join the 80's and > upgrade to one that does. Of course I can change my software. That fixes the problem for me. Or the poster can get a clue and follow the standard -- which may be as simple as clicking a checkbox, probably called "Wrap text", under Settings somewhere -- and fix the problem for EVERYBODY, regardless of what mail client or newsreader they're using. -- Steven From duncan.booth at invalid.invalid Fri Nov 13 07:35:07 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Nov 2009 12:35:07 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Nah, exceptions are an ugly effect that gets in the way of > parallelism. Haskell handles lookups through its type system; dealing > with lookup errors (say by chaining the Maybe type) is clean and > elegant. Erlang handles it by crashing the process, and dealing with > the crash through a supervision tree that cleans up after crashes and > restarts the crashed processes. I said exceptions or any other method of error handling. >> What that article didn't mention, and what is possibly Go's real >> strong point is that it has built-in support for parallel processing. >> Again though the implementation looks weak... > > I'd like to know more about this; is there a link with a short > write-up? I haven't gotten around to looking at the reference > materials. I just read the reference manual. As I understand it: Any function or method can be executed in parallel: instead of calling the function you use the go keyword: go doSomething(); go routines are executed using a thread pool, and an individual go routine might vary its execution thread depending on which threads are available. Most types are not thread safe, so you should never access any mutable value from more than one go routine. If you need to access something like a map from multiple parallel routines you need to use channels to protect it. You can declare and pass around channel variables. A channel can hold values or pointers of any type and has a specific number of free slots. e.g. var ch = make(chan int, 3); would create a channel that holds 3 int values. To write to a channel (blocking if it is full): ch <- value; To read from a channel (blocking if empty): value <- ch; To read from a channel blocking and discarding the result (e.g. to wait for a routine to finish): <- ch; To read without blocking: value, ok <- ch; ok set true if something was read. And to write without blocking: ok := ch <- value; or in fact any write in an expression context. You can also use a select statement (syntax similar to a switch statement) to read or write channels in parallel. It arbitrarily chooses one of the case statements that can proceed to execute, otherwise if there is a default statement it executes that. If there is no default statement the entire select blocks until one of the case statements can proceed. e.g. (example from the docs) var c1, c2 chan int; var i1, i2 int; select { case i1 = <-c1: print("received ", i1, " from c1\n"); case c2 <- i2: print("sent ", i2, " to c2\n"); default: print("no communication\n"); } There doesn't seem to be any way to specify a timeout on a read or write. I think you can create a timer channel with regular ticks and select from that to provide an effective timeout, but that sounds like a lot of boilerplate if you have to do very often. -- Duncan Booth http://kupuguy.blogspot.com From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:53:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:53:02 -0300 Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: En Thu, 12 Nov 2009 23:29:03 -0300, greg escribi?: > Carl Banks wrote: >> You >> can define constants to access specific registers: >> R1L = 1 >> R1H = 2 >> R1 = 1 >> breg[R1H] = 2 >> print wreg[R1] > > But keep in mind that named "constants" at the module level > are really global variables, and therefore incur a dictionary > lookup every time they're used. > > For maximum speed, nothing beats writing the numeric literals > directly into the code, unfortunately. This recipe may improve speed dramatically in those cases: http://code.activestate.com/recipes/277940/ -- Gabriel Genellina From animator333 at gmail.com Fri Nov 13 07:57:04 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 04:57:04 -0800 (PST) Subject: object indexing and item assignment Message-ID: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> class MyFloat(object): def __init__(self, value=0.): self.value = value def set(self, value): self.value = value def get(self): return self.value class MyColor(object): def __init__(self, value=(0,0,0)): self.value = (MyFloat(value[0]), MyFloat(value[1]), MyFloat(value[2])) def set(self, value): self.value[0].set(value[0]) self.value[1].set(value[1]) self.value[2].set(value[2]) def get(self): return (self.value[0].get(), self.value[1].get(), self.value[2].get()) col = MyColor() col[0].set(0.5) # 'MyColor' object does not support indexing col[0] = 0.5 # 'MyColor' object does not support item assignment The last two lines of the script produce errors. (written as comments). I know it won't work as I am expecting. One solution I can think of is to rewrite MyFloat and MyColor by sub classing default python types "float and "tuple". Is this the only solution? Prashant Python 2.6.2 Win XP 32 From bearophileHUGS at lycos.com Fri Nov 13 07:58:11 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Fri, 13 Nov 2009 04:58:11 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: <83c50eec-be41-4142-8f10-bb4744702c90@w19g2000yqk.googlegroups.com> Santiago Romero: >Obviously, I prefer to write well structured code but I had to sacrifize SIZE by SPEED< In C99 you have "inline" (and gcc/gcc-llvm usually inline small functions anyway) that helps avoid many macros. > ?Now I'm porting the emulator to a scripted language, so I need > even more previous design ideas before starting to code, so that > I can achieve (I hope I'll be able to do it with this group's help) > 100% cpu speed in an standard desktop PC. The tecniques needed to speed up Python code are very different from the ones you use in C. You may need a lot of time to learn Python performance tricks. Psyco helps a lot. > ?Well, I don't agree with that, "constants" and "macros" wouldn't > hurt python, when using them in the right situations. I miss true constants in Python, but it may be impossible to add them to this language, because of how it uses references. In Python you rely on convention, writing their names ALL_UPPERCASE. Bye, bearophile From benjamin.kaplan at case.edu Fri Nov 13 08:10:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 13 Nov 2009 08:10:00 -0500 Subject: object indexing and item assignment In-Reply-To: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> References: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> Message-ID: On Fri, Nov 13, 2009 at 7:57 AM, King wrote: > class MyFloat(object): > ? ?def __init__(self, value=0.): > ? ? ? ?self.value = value > > ? ?def set(self, value): > ? ? ? ?self.value = value > > ? ?def get(self): > ? ? ? ?return self.value > > class MyColor(object): > ? ?def __init__(self, value=(0,0,0)): > ? ? ? ?self.value = (MyFloat(value[0]), > ? ? ? ? ? ? ? ? ? ? ? ?MyFloat(value[1]), > ? ? ? ? ? ? ? ? ? ? ? ?MyFloat(value[2])) > > ? ?def set(self, value): > ? ? ? ?self.value[0].set(value[0]) > ? ? ? ?self.value[1].set(value[1]) > ? ? ? ?self.value[2].set(value[2]) > > ? ?def get(self): > ? ? ? ?return (self.value[0].get(), > ? ? ? ? ? ? ? ?self.value[1].get(), > ? ? ? ? ? ? ? ?self.value[2].get()) > > col = MyColor() > col[0].set(0.5) # 'MyColor' object does not support indexing > col[0] = 0.5 # 'MyColor' object does not support item assignment > > > The last two lines of the script produce errors. (written as > comments). I know it won't work as I am expecting. One solution I can > think of is to rewrite MyFloat and MyColor by sub classing default > python types "float and "tuple". Is this the only solution? > > Prashant > > Python 2.6.2 > Win XP 32 > -- In order to support indexing and item assignment, implement the __getitem__ and __setitem__ methods. def __getitem__(self, index) : return self.value[index] def __setitem__(self, index, value) : self.value[index].set(value) > http://mail.python.org/mailman/listinfo/python-list > From bearophileHUGS at lycos.com Fri Nov 13 08:15:35 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Fri, 13 Nov 2009 05:15:35 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: Message-ID: <3d203266-8cd1-4fca-8c29-51845944b255@m16g2000yqc.googlegroups.com> Try creation an extension module with ShedSkin. Bye, bearophile From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri Nov 13 08:44:13 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 13 Nov 2009 13:44:13 +0000 (UTC) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: Santiago Romero wrote: > >> > #define STORE_nn_rr(dreg) \ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_opl = Z80ReadMem(r_PC); r_PC++;\ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_oph = Z80ReadMem(r_PC); r_PC++; \ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_tmp = dreg; \ >> > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op),r_tmpl, regs); \ >> > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op+1),r_tmph, regs) >> >> Someone writing such code and calling it C should be taken >> behind the barn and shot. > > That code is mine and maybe you should look the context > before doing such kind of affirmations. > > In the Intel Pentium and P-II ages, I started to wrote the > very first Spectrum emulator in C. With that "cpu power", emulators > had to be written in ASM to be capable to emulate the destination > machines at 100% full speed in multitasking systems. > Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do not remember the CPU freqeuncy anymore, maybe 25MHz). First emulator in C that appeared on the emu-scene (I guess it was x128) needed 486 (~80MHz?) to run at realtime. Pentium and Pentium II was A LOT of power :-) ... > > Now I'm porting the emulator to a scripted language, so I need > even more previous design ideas before starting to code, so that > I can achieve (I hope I'll be able to do it with this group's help) > 100% cpu speed in an standard desktop PC. > >> > ?But it seems that is not possible :-( http://perl-spectrum.sourceforge.net/ It is quite fast IMHO. Just remember to use psyco... -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From mail at timgolden.me.uk Fri Nov 13 08:57:37 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Nov 2009 13:57:37 +0000 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <4AFD65D1.6040308@timgolden.me.uk> Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. Thinking aloud about what you're describing here... Assuming Windows, as your starting point is py2exe and I imagine that most Unix-like boxes already have Python on them. Step 1: The user downloads a tiny myapp.exe which is basically a zip of the myapp package / files plus an .exe header which will... Step 2a: ... download a minimised? (ie custom-built) Python interpreter and stdlib bundle which is just enough to run the app. Or... Step 2b: ... download and install the official python.org Windows installer for version x.y identified as the highest known to run this app if... Step 2bi) ... that version of the interpreter isn't already installed and registered on that machine (at least: for that user). My step 2a seems to be little better than a bundled py2exe, so I can only assume you mean Step 2b, especially given your comment below about ending up with an installation of Python where one wasn't before. This, though, seems fraught with accusations of backdoor installations etc. Have I misunderstood you? For the Record, I'm entirely in favour of moves to make Python use on Windows more seamless, attractive, consistent, etc. I was going to comment positively on your recent PyChooser widget and to plug a similar but unpublished one of my own. But I'm not sure if this particular proposal has enough wings to make it fly. TJG From philip at semanchuk.com Fri Nov 13 09:05:33 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 13 Nov 2009 09:05:33 -0500 Subject: A beginner question about GUI use and development In-Reply-To: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <05D89213-4094-4B0F-9281-9CD5FC06063E@semanchuk.com> On Nov 13, 2009, at 3:55 AM, uap12 wrote: > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) Hej Anders, wxWidgets and PyQT are very popular. As Marcus pointed out, Tkinter has the advantage that it ships with Python. These three should be your top candidates. > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. Yes, but the solutions aren't straightforward. Look at py2exe for Windows and py2app for the Mac. I don't know what to recommend for *nix (Linux, FreeBSD, etc.) > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? wxGlade is popular for wxWidgets. I don't know about PyQT or Tkinter. Lycka till, Philip From robince at gmail.com Fri Nov 13 09:14:58 2009 From: robince at gmail.com (Robin) Date: Fri, 13 Nov 2009 06:14:58 -0800 (PST) Subject: bus error in Py_Finalize with ctypes imported Message-ID: <924dc50d-e99f-48d4-bbf8-ba48deaca347@w19g2000yqk.googlegroups.com> Hi, I am trying to embed Python in a MATLAB mex function. This is loaded into the MATLAB interpreter - I would like the Python interpreter to be initialized once and stay there for future calls. I added a call to Py_Finalize as a mexAtExit handler which is called when the library is unloaded in MATLAB (with clear funcname) or when MATLAB shuts down. So far, things were working well, but I get a random but easily repeatable bus error in Py_Finalize if I have imported ctypes. Here is my code: #include #include static int PYRUNNING = 0; static void Cleanup(void) { mexPrintf("Finalising Python...\n"); Py_Finalize(); } void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) { mexPrintf("hello from mex\n"); if (!PYRUNNING) { Py_Initialize(); PYRUNNING = 1; mexAtExit(Cleanup); PyRun_SimpleString("import ctypes"); } PyRun_SimpleString("print 'hello from python'"); } If I load, run the function, and unload many times eventually I get the following stack trace (whcih i don't get if I'm not import ctypes). Does anyone have any idea what might be up? Could it be a bug in Py_Finalize or ctypes? Is there a problem with my approach (ie is it bad to leave the interpreter initialized between mex function calls - it seems to work provided ctypes is not imported - but I need ctypes to access other mex functions from python). ------------------------------------------------------------------------ Bus error detected at Fri Nov 13 14:06:12 2009 ------------------------------------------------------------------------ Configuration: MATLAB Version: 7.8.0.347 (R2009a) MATLAB License: 161051 Operating System: Darwin 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386 Window System: The X.Org Foundation (10402000), display /tmp/ launch-2p1ZWg/:0 Current Visual: 0x24 (class 4, depth 24) Processor ID: x86 Family 6 Model 15 Stepping 10, GenuineIntel Virtual Machine: Java 1.6.0_15-b03-219 with Apple Inc. Java HotSpot (TM) Client VM mixed mode Default Encoding: ISO-8859-1 Fault Count: 1 Register State: eax = 00000000 ebx = 3483d9be ecx = 33ff7620 edx = 00000000 esi = 32fb4dc0 edi = 0000001a ebp = b0b69938 esp = b0b69920 eip = 3485559f flg = 00010282 Stack Trace: [0] Python:type_dealloc~(0x32fb4dc0, 0x33f70818, 0x34854f0b, 0x34844410) + 26 bytes [1] Python:dict_dealloc~(0x33fef930, 0x348e4b40 "__builtin__", 0xb0b699bc, 0xb0b699b8) + 142 bytes [2] Python:dict_dealloc~(0x33f429c0, 0x348ee58c "exitfunc", 0xb0b699d8, 0x348b96b0) + 142 bytes [3] Python:_PyImport_Fini~(0x348ee58c "exitfunc", 0, 0, 0) + 82 bytes [4] Python:Py_Finalize~(673024, 1, 0, 0x00ab4700) + 207 bytes [5] libmex.dylib:SafeExitFunctionCall(void (*)())(0x30365df0, 0xb0b69ab8, 0xb0b69a80, 0x0073d01b) + 66 bytes [6] libmex.dylib:mexClearMexFileDefault(impl_info_tag*)(0x33e0dce0, 1, 0, 0x015fa3d8 "7Mfh_mex") + 80 bytes [7] libmex.dylib:safeMexClearMexFile(impl_info_tag*&)(0xb0b69bec "???3", 1, 0x015fc080, 0) + 76 bytes [8] libmex.dylib:Mlm_mex::unload_file()(0x32b01290, 0, 0, 0) + 250 bytes [9] libmwm_dispatcher.dylib:Mlm_file::unload_mf()(0x32b01290, 0, 0, 0) + 18 bytes [10] libmwm_dispatcher.dylib:Mlm_MATLAB_fn::clear()(0x32b01290, 0, 0xb0b69c9c, 236) + 82 bytes [11] libmwm_dispatcher.dylib:void clear (Mlmmf_string_matcher, int)(0x05319c00, 0x33e24b8c "pytest", 0x30476300, 0x03f3b531 "pytest") + 296 bytes [12] libmwm_dispatcher.dylib:mdClearFunctionsByName(0x33e24b8c "pytest", 42, 0xb0b6adf8, 10) + 650 bytes [13] libmwm_interpreter.dylib:InterpBridge::FullClearFcn(int, mxArray_tag**, int, mxArray_tag**)(0x036225e0, 0, 0xb0b6af6c, 1) + 1234 bytes [14] libmwm_interpreter.dylib:inFullClearFcn(int, mxArray_tag**, int, mxArray_tag**)(0, 0xb0b6af6c, 1, 0xb0b6afcc) + 50 bytes [15] libmwm_dispatcher.dylib:Mfh_builtin::dispatch_mf(int, mxArray_tag**, int, mxArray_tag**)(0x2dd025a0, 0, 0xb0b6af6c, 1) + 95 bytes [16] libmwm_dispatcher.dylib:Mfh_MATLAB_fn::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x2dd025a0, 0, 0xb0b6af6c, 1) + 192 bytes [17] libmwm_interpreter.dylib:inDispatchFromStack(int, char const*, int, int)(0, 0x304fa51c "clear", 0, 1) + 998 bytes [18] libmwm_interpreter.dylib:inDispatchCall(char const*, int, int, int, int*, int*)(1, 0xb0b6b298, 0x33e11a28, 0x9322e76b) + 152 bytes [19] libmwm_interpreter.dylib:inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag volatile*, int*)(1, 0, 1, 0) + 5167 bytes [20] libmwm_interpreter.dylib:protected_inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(1, 0, 1, 0) + 112 bytes [21] libmwm_interpreter.dylib:inInterPcodeSJ(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(0, 0x33e007d0, 0xb0b6b460, 0xb0b6b460) + 266 bytes [22] libmwm_interpreter.dylib:inExecuteMFunctionOrScript(Mfh_mp*, bool)(0x33e263c0, 1, 0xb0b6b99c, 0) + 932 bytes [23] libmwm_interpreter.dylib:inRunMfile(int, mxArray_tag**, int, mxArray_tag**, Mfh_mp*, inWorkSpace_tag*)(0, 0xb0b6b99c, 0, 0) + 696 bytes [24] libmwm_interpreter.dylib:Mfh_mp::dispatch_file(int, mxArray_tag**, int, mxArray_tag**)(0x33e263c0, 0, 0xb0b6b99c, 0) + 56 bytes [25] libmwm_dispatcher.dylib:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x33e263c0, 0, 0xb0b6b99c, 0) + 256 bytes [26] libmwm_interpreter.dylib:inEvalPcodeHeaderToWord (_memory_context*, int, mxArray_tag**, _pcodeheader*, Mfh_mp*, unsigned int)(0x000a2ac8 "?*\n", 0, 0xb0b6b99c, 0xb0b6b83c) + 252 bytes [27] libmwm_interpreter.dylib:inEvalStringWithIsVarFcn (_memory_context*, char const*, EvalType, int, mxArray_tag**, inDebugCheck, _pcodeheader*, int*, bool (*)(void*, char const*), void*, bool, bool)(0, 0xb0b6b99c, 0, 0) + 1835 bytes [28] libmwm_interpreter.dylib:inEvalCmdWithLocalReturn(char const*, int*, bool, bool, bool (*)(void*, char const*))(1, 0x004aeb20, 0, 0) + 148 bytes [29] libmwm_interpreter.dylib:inEvalCmdWithLocalReturn(0x2e3e5e00 "clear pytest\n", 0, 0, 1) + 66 bytes [30] libmwbridge.dylib:evalCommandWithLongjmpSafety(char const*) (0x2e3e5e00 "clear pytest\n", 2, 0x2de28978, 4073223) + 108 bytes [31] libmwbridge.dylib:mnParser(0xb0b6bb34, 0x0501fc00, 1, 0) + 666 bytes [32] libmwmcr.dylib:mcrInstance::mnParser_on_interpreter_thread() (0x0501fc00, 8, 0x05016000, 4) + 43 bytes [33] libmwmcr.dylib:boost::function0::operator()() const (0x2dd33904 "??A", 0, 0xb0b6bc68, 171953) + 41 bytes [34] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::NoResultInvocationRequest::run ()(0x2dd338f0, 0, 0xb0b6bbe8, 172001) + 21 bytes [35] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::invocation_request_handler (long)(0x2dd338f0, 0, 0xb0b6bc38, 3636709) + 24 bytes [36] libmwuix.dylib:uix_DispatchOrProcess(_XEvent*, _XtAppStruct*, int, bool)(0, 15, 0x000f4240 "put_target_string_with_length", 0x4afd6790) + 476 bytes [37] libmwuix.dylib:ws_ProcessPendingEventsHelper(int, int, bool)(1, 0xffffffff, 0, 852585) + 469 bytes [38] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::process_events (boost::shared_ptr const&) (0x036519b0, 0xb0b6be68, 0, 0x03651960 "/Applications/ MATLAB_R2009a.app/..") + 376 bytes [39] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::run (boost::shared_ptr const&, mcr::runtime::InterpreterThread::Impl::init_context*)(0x036519b0, 0xb0b6be68, 0xb0182cac, 4078061) + 410 bytes [40] libmwmcr.dylib:run_init_and_handle_events(void*)(0xb0182cac, 0, 0, 0) + 52 bytes [41] MATLAB:create_mcrInstance_and_run_mnParser(0xb0b6bf00 "@?A", 8816, 0, 0) + 553 bytes [42] MATLAB:start(2, 0xbffff4d0 "????????", 0xb0b6c000 "DRHT", 0xffffffff) + -2223 bytes [43] libmwmcr.dylib:runMcrMain(void*)(0xbffff440 "?%", 0x04000000, 1, 0) + 39 bytes [44] libSystem.B.dylib:_pthread_start~(0xb0b6c000 "DRHT", 13827, 0x004075f0, 0xbffff440 "?%") + 345 bytes [45] libSystem.B.dylib:thread_start~(0, 0, 0, 0x54485244) + 34 bytes From cr88192 at hotmail.com Fri Nov 13 09:22:09 2009 From: cr88192 at hotmail.com (BGB / cr88192) Date: Fri, 13 Nov 2009 07:22:09 -0700 Subject: Does turtle graphics have the wrong associations? References: Message-ID: "Peter Nilsson" wrote in message news:ed7d74f6-c84d-40f1-a06b-642f988fb464 at x25g2000prf.googlegroups.com... > "Alf P. Steinbach" wrote: >> One reaction to >> has >> been that turtle graphics may be off-putting to some >> readers because it is associated with children's learning. > > [I'll be honest and say that I merely glanced at the two > pdf files.] > > Who is your target audience? The opening Getting Started > paragraph would probably put off many beginners right from > the get go! You're talking about a 'first language' but > throwing 'syntax', 'windows', 'graphics', 'networking', > 'file and database access' and 'standard libraries' at them. > > The success of 'XXXX for Dummies' is certainly not their > accuracy, but rather that they make far fewer assumptions > that people already know the subject being tought! That > assumption seems almost ingrained in every 'beginner' > programming book I've ever seen! > yep, but I guess it depends some on the type of beginner... many beginner books take the style of lots of examples and verbosity, and trying to gradually ease the person into the topic, ... also common is more of a "crash course" style, where topics are introduced and defined, and where the contents tend to be far more categorical (in these books, often the later chapters and/or appendices are long, and often consist largely of definitions and reference material). there are merits to both styles I think... I have also seen where they try to fictionalize the topic, or turn it into some huge mass of allegories, but I don't really like this style so much... it is possible the 'turtle' may hold these sorts of associations... >> What do you think? > > Whilst everyone knows children tend to think visually more > than abstractly, the same is precisely true of adults. > However, the ultimate problem with Turtle is that it ends > up teaching a 'mathematical' perspective and it's far from > intuitive how you map that perspective to tackling more > real world issues. It's simply substituting one difficult > abstraction with another. > > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > yep, much the same as trying to teach trig in a pseudo-fantasy setting by addressing the relative dimensions of the various parts of Excalibur... one gets much more amusement out of just watching a sword fight where all they do is whack the swords into each other and pause momentarily, with whoever was doing the mixing unable to get the delay between the swords hitting and the 'clang' much less than about 300ms... > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. > yep... simple, unstructured, thinking is easier. if one screws up somewhere, it is a lot easier to find and correct the problem. this is probably part of why procedural and OO have traditionally been more popular than functional programming: one does not have to try to bend their mind so much to get things written or figure out just what the hell is going on... granted, some level of mind-bending in necessary for programming, but IMO it is more of a necessary evil... > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) > > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. > apparently, I don't even approach math in a mathematical manner... I had thought I had understood math, and I use it enough, but I am suspecting that the thing I am familiar with is a good deal different than that seen by mathematicians (partly as a result of some interactions with, and observation of, physics teachers...). or, it could be that my world is severely 'bent' because of my exposure to computers, and almost complete lack of need or desire to write proofs or to expand-out and perform huge amounts of symbolic manipulations by hand... so, I guess my difficulty curve is rather "unusual" as well... I live in a world where vectors and matrices are fairly simple, and quaternions would be, apart from my near inability to intuitively understand or visualize their behaviors... and, in this same world, set theory and predicate logic are evil beasts best avoided at all cost... and, it seems, traditional math screws me over even with seemingly trivial problems... and, it does not take long to figure out that, for example, even a trivial operation such as renormalizing a vector becomes a marathon of pain... A= |A|=sqrt(Ax^2+Bx^2+Cx^2) B=A/|A| = = =... I would far much rather think: N(A)=A/|A| and leave it as that, this way we factor out everything leaving mostly abstract operations... (once we know the operation, we no longer need to care what it is or how it works...). but, other people want to expand everything out and turn it into a big evil-looking mess, bleh... > -- > Peter From robince at gmail.com Fri Nov 13 09:27:23 2009 From: robince at gmail.com (Robin) Date: Fri, 13 Nov 2009 06:27:23 -0800 (PST) Subject: bus error in Py_Finalize with ctypes imported References: <924dc50d-e99f-48d4-bbf8-ba48deaca347@w19g2000yqk.googlegroups.com> Message-ID: <37162f95-b36d-4880-b723-c3d4a337e1a0@k4g2000yqb.googlegroups.com> On Nov 13, 2:14?pm, Robin wrote: > I am trying to embed Python in a MATLAB mex function. This is loaded > into the MATLAB interpreter - I would like the Python interpreter to > be initialized once and stay there for future calls. I added a call to > Py_Finalize as a mexAtExit handler which is called when the library is > unloaded in MATLAB (with clear funcname) or when MATLAB shuts down. So > far, things were working well, but I get a random but easily > repeatable bus error in Py_Finalize if I have imported ctypes. Looks like I've run into this bug: http://bugs.python.org/issue6869 I will try the attached patch - hopefully it will make into a forthcoming release. Cheers Robin From martin.hellwig at dcuktec.org Fri Nov 13 09:31:05 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 13 Nov 2009 14:31:05 +0000 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. I can see two distinctive scenarios: - Local temporarily installation - System wide installation (possible conflicts with older versions) Anyway this reminds me of the web installers where you only download the installer which download the rest from the net, like they used to be available from adobe and for java. It should be doable, for example you have an executable which has only one function; download a second stage installer from a fixed location. That second stage installer is a bit bigger and knows how to check for dependencies for that particular platform and install other dependencies. So you can chain a lot of installers after each other, for example the second stage installer can be a python installer then you could do all the remaining installing from the convenience of python. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From mmitchell at transparent.com Fri Nov 13 09:32:37 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 13 Nov 2009 09:32:37 -0500 Subject: tkFileDialog question Message-ID: Hi, This is my first attempt to write a script with any kind of gui. All I need the script to do is ask the user for a directory and then do stuff with the files in that directory. I used tkFileDialog.askdirectory(). It works great but it pops up an empty tk window. Is there any way to prevent the empty tk window from popping up? Here's the code: import tkFileDialog answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks! Matt From jg.campbell.ng at gmail.com Fri Nov 13 09:54:37 2009 From: jg.campbell.ng at gmail.com (Jonathan Campbell) Date: Fri, 13 Nov 2009 14:54:37 +0000 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > graphics may be off-putting to some readers because it is associated > with children's learning. > Incidentally ... something you may wish to consider for inclusion in you book ... games programming and Pygame. See, e.g., Andy Harris, Game Programming (L Line: The Express Line to Learning), John Wiley & Sons, 2007, ISBN-10: 0470068221 or Will McGugan, Beginning Game Development with Python and Pygame : From Novice to Professional, APRESS, 2007, ISBN-10: 1590598725. I have the impression that there are many young people who could learn programming via games programming. On the other hand, in languages like C++ or Java, the threshold to games programming is extremely high. Not so using Pygame. The additional nice thing about Pygame is that it is based on a Python binding of SDL (Simple DirectMedia Layer) an open-source games API. This could mean easy migration to C++ games programming (using SDL). Best regards, Jon C. -- Jonathan Campbell www.jgcampbell.com BT48, UK. From chris at simplistix.co.uk Fri Nov 13 10:39:19 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 13 Nov 2009 15:39:19 +0000 Subject: Vote on PyPI comments Message-ID: <4AFD7DA7.4010706@simplistix.co.uk> Hi All, Apologies for the cross post, but I'm not sure this has received the publicity it deserves... PyPI grew a commenting and rating system a while back, apparently in response to requests from users. However, since it's been rolled out, there's been a backlash from package maintainers who already have mailing lists, bug trackers, etc for their packages and don't want to have to try and keep track of yet another support forum. The arguments for and against are listed here: http://wiki.python.org/moin/PyPIComments To resolve the future of the commenting and rating system, a vote has been set up so everyone can have their say. To vote, please log in to: http://pypi.python.org/pypi ...and follow the instructions you'll be presented with. I would like to remain neutral on this, and for me that means giving package authors the ability to choose whether they want to receive comments, ratings or neither rather than either forcing package authors to accept comments and ratings or abandoning the idea of comments and ratings completely. The closest option to that is: "Allow package owners to disallow comments (ratings unmodified)" I hope the majority of you feel the same way... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From michele.simionato at gmail.com Fri Nov 13 10:53:05 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 13 Nov 2009 07:53:05 -0800 (PST) Subject: Vote on PyPI comments References: Message-ID: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> On Nov 13, 4:39?pm, Chris Withers wrote: > > PyPI grew a commenting and rating system a while back, apparently in > response to requests from users. However, since it's been rolled out, > there's been a backlash from package maintainers who already have > mailing lists, bug trackers, etc for their packages and don't want to > have to try and keep track of yet another support forum. > I am skeptical about the utility of both rating and comments. If somebody wants to know if a package is good, she should ask here. From aahz at pythoncraft.com Fri Nov 13 11:07:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 08:07:47 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >>>Esky is an auto-update framework for frozen python apps, built on top of >>>bbfreeze. It provides a simple API through which apps can find, fetch >>>and install updates, and a bootstrapping mechanism that keeps the app >>>safe in the face of failed or partial updates. >> >> Recently I was looking into distribution mechanisms, and I passed over >> bbfreeze because I saw no indication that Python 2.6 was supported. > >Not sure if it's officially supported, but I do most of my development >on Python 2.6 and bbfreeze hasn't given me any problems as yet. Also, bbfreeze doesn't seem to have active development. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From lallous at lgwm.org Fri Nov 13 11:30:19 2009 From: lallous at lgwm.org (lallous) Date: Fri, 13 Nov 2009 17:30:19 +0100 Subject: Adding methods to an object instance Message-ID: Hello class __object(object): def __getitem__(self, idx): return getattr(self, idx) class __dobject(object): pass x = __object() setattr(x, "0", "hello") print x["0"] y = __dobject(a=1,b=2) setattr(y, "0", "world") #print y["0"] How can I, given an object of instance "__dobject", add to that instance a __getitem__ method so that I can type: print y["0"] Thanks, Elias From athenka25 at gmail.com Fri Nov 13 11:34:57 2009 From: athenka25 at gmail.com (Alena Bacova) Date: Fri, 13 Nov 2009 11:34:57 -0500 Subject: wsgi with separate css file Message-ID: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> Hi all, I just wanted to know if anybody tried using wsgi as a web server that would be serving html file with separate css file. I managed to make my wsgi server display only on html file ( it has got the form tag, and I'm serving do_get and do_post call to) but I would like to have formatting stored in separate css file, rather then embedded in html code. Plus being able to serve image files with the html would be nice addition. I tried to google the thing, but there wasn't any explicit example of such thing. After I get the do_get request from browser and html is posted I do get "do_get /file.css" request, but I have no idea how to serve that. Any help, examples, suggestions more then welcome. Thanks. Alena -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Fri Nov 13 11:42:20 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 13 Nov 2009 08:42:20 -0800 Subject: wsgi with separate css file In-Reply-To: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> Message-ID: On Fri, 13 Nov 2009 08:34:57 -0800, Alena Bacova wrote: > Hi all, > > I just wanted to know if anybody tried using wsgi as a web server that > would > be serving html file with separate css file. I managed to make my wsgi > server display only on html file ( it has got the form tag, and I'm > serving > do_get and do_post call to) but I would like to have formatting stored in > separate css file, rather then embedded in html code. Plus being able to > serve image files with the html would be nice addition. > > I tried to google the thing, but there wasn't any explicit example of > such > thing. After I get the do_get request from browser and html is posted I > do > get "do_get /file.css" request, but I have no idea how to serve that. > > Any help, examples, suggestions more then welcome. > Hi Alena, Can you tell us a little more about your setup? For instance, are you using the simple_server from the wsgiref module? Where are the application and CSS files being stored and run? Cheers Rami -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From animator333 at gmail.com Fri Nov 13 11:46:55 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 08:46:55 -0800 (PST) Subject: object serialization as python scripts Message-ID: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> I have looked upon various object serialization de-serialization techniques. (shelve, pickle, anydbm, custom xml format etc.) What I personally feel that instead of all these methods for saving the objects it would be easier to save the data as python scripts itself. In this case, loading the data is merely to run the script in the context itself. Need some expert advice and pointers here. Is there any thing (module, script, doc, article) helpful out there for the concern? Prashant Python 2.6.2 Win XP 32 From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 13 11:47:02 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 17:47:02 +0100 Subject: Adding methods to an object instance In-Reply-To: References: Message-ID: <4afd8d6c$0$14707$426a34cc@news.free.fr> lallous a ?crit : > Hello > > class __object(object): the convention for reusing reserved words as identifiers is to *suffix* them with a single underscore, ie: class object_(object): # > def __getitem__(self, idx): > return getattr(self, idx) > > class __dobject(object): pass > > x = __object() > setattr(x, "0", "hello") > print x["0"] > > y = __dobject(a=1,b=2) > > setattr(y, "0", "world") > #print y["0"] > > How can I, given an object of instance "__dobject", add to that instance > a __getitem__ method so that I can type: > print y["0"] Adding per-instance methods won't work for __magic_methods__. But you could use the Decorator pattern here: class IndexableDecorator(object): def __init__(self, other): self._other = other def __getitem__(self, idx): return getattr(self._other, idx) def __setattr__(self, name, value): if name = "_other": object.__setattr__(self, name, value) else: setattr(self._other, name, value) x = IndexableDecorator(x) NB : not tested, so it probably contains at least one obvious error !-) From bryanvick at gmail.com Fri Nov 13 11:59:54 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Nov 2009 08:59:54 -0800 (PST) Subject: Dynamic property names on class Message-ID: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> I have several properties on a class that have very similar behavior. If one of the properties is set, all the other properties need to be set to None. So I wanted to create these properties in a loop like: class Test(object): for prop in ['foo', 'bar', 'spam']: # Attribute that data is actually stored in field = '_' + prop # Create getter/setter def _get(self): return getattr(self, field) def _set(self, val): setattr(self, field, val) for otherProp in prop: if otherProp != prop: setattr(self, '_' + otherProp, None) # Assign property to class setattr(Test, prop, property(_get, _set)) t = Test() t.foo = 1 assert t.bar == t.spam == None But the class Test is not defined yet, so I can't set a property on it. How can I do this? From rami.chowdhury at gmail.com Fri Nov 13 12:16:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 13 Nov 2009 09:16:27 -0800 Subject: wsgi with separate css file In-Reply-To: <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> Message-ID: On Fri, 13 Nov 2009 08:55:33 -0800, Alena Bacova wrote: > Hi, > I'm using: > > from wsgiref import simple_server > httpd = simple_server.make_server(HOST, PORT, Test) > try: > httpd.serve_forever() > except KeyboardInterrupt: > pass > > But I can use something else if needed. Application and htmk, css and > images are stored on the same machine, everything is stored in one > folder. > > Alena. > If you are just using this to learn to develop WSGI applications, I would recommend implementing a method to distinguish requests for static files, and handle them separately. A very naive implementation handling .css files might look like: from wsgiref import util import os def do_get(environ, start_response): REQUEST_URI = util.request_uri(environ) if (REQUEST_URI.endswith('.css')): return do_css(REQUEST_URI, start_response) # your regular code here def do_css(request_uri, start_response): full_path = os.path.abspath(os.path.join(MY_HTTP_DIRECTORY, request_uri)) if os.path.exists(full_path): file_obj = open(full_path, 'r') response_lines = file_obj.readlines() file_obj.close() start_response('200 OK', [('Content-Type', 'text/css')]) return response_lines else: start_response('404 Not Found', []) return [] However, this method is fragile and very inefficient. If you want to eventually deploy this application somewhere, I would suggest starting with a different method. Hope that helps, Rami -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From exarkun at twistedmatrix.com Fri Nov 13 12:23:39 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 13 Nov 2009 17:23:39 -0000 Subject: [ANN] pyOpenSSL 0.10 Message-ID: <20091113172339.3229.1288175132.divmod.xquotient.728@localhost.localdomain> I'm happy to announce the release of pyOpenSSL 0.10. pyOpenSSL 0.10 exposes several more OpenSSL APIs, including support for running TLS connections over in-memory BIOs, access to the OpenSSL random number generator, the ability to pass subject and issuer parameters when creating an X509Extension instance, more control over PKCS12 creation and an API for exporting PKCS12 objects, and APIs for controlling the client CA list servers send to clients. Several bugs have also been fixed, including a crash when certain X509Extension instances are deallocated, a mis-handling of the OpenSSL error queue in the X509Name implementation, Windows build issues, and a possible double free when using a debug build. The style of the docstrings for APIs implemented in C has also been changed throughout the project to be more useful to Python programmers. Extension type objects can also now be used to instantiate those types. Many thanks to numerous people who contributed patches to this release. You can find pyOpenSSL 0.10 on the Python Package Index: http://pypi.python.org/pypi/pyOpenSSL/0.10 You can now also find the pyOpenSSL documentation there: http://packages.python.org/pyOpenSSL/ As part of the ongoing transition away from SourceForge, I won't be uploading the release or the documentation to SourceForge. Please continue to use the pyOpenSSL Launchpad page for bug reports: https://launchpad.net/pyopenssl Enjoy! Jean-Paul Calderone From deets at nospam.web.de Fri Nov 13 12:33:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 18:33:48 +0100 Subject: object serialization as python scripts In-Reply-To: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> Message-ID: <7m5jjsF3egl9mU1@mid.uni-berlin.de> King schrieb: > I have looked upon various object serialization de-serialization > techniques. > (shelve, pickle, anydbm, custom xml format etc.) What I personally > feel that instead of all these > methods for saving the objects it would be easier to save the data as > python scripts itself. > In this case, loading the data is merely to run the script in the > context itself. > Need some expert advice and pointers here. Is there any thing (module, > script, doc, article) > helpful out there for the concern? Why is it easier than the above mentioned - they are *there* (except the custom xml), and just can be used. What don't they do you want to do? Other than that, and even security issues put aside, I don't see much difference between pickle and python code, except the latter being more verbose. Which suits humans, but other than that has no advantage. Diez From deets at nospam.web.de Fri Nov 13 12:34:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 18:34:58 +0100 Subject: Dynamic property names on class In-Reply-To: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> Message-ID: <7m5jm2F3egl9mU2@mid.uni-berlin.de> Bryan schrieb: > I have several properties on a class that have very similar behavior. > If one of the properties is set, all the other properties need to be > set to None. So I wanted to create these properties in a loop like: > > class Test(object): > for prop in ['foo', 'bar', 'spam']: > # Attribute that data is actually stored in > field = '_' + prop > # Create getter/setter > def _get(self): > return getattr(self, field) > def _set(self, val): > setattr(self, field, val) > for otherProp in prop: > if otherProp != prop: setattr(self, '_' + otherProp, None) > # Assign property to class > setattr(Test, prop, property(_get, _set)) > > t = Test() > t.foo = 1 > assert t.bar == t.spam == None > > But the class Test is not defined yet, so I can't set a property on > it. How can I do this? With a metaclass, or a post-class-creation function. Which is a metaclass without being fancy. Just put your above code into a function with the class in question as argument, and invoke it after Test is defined. Diez From tino at wildenhain.de Fri Nov 13 12:52:04 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 13 Nov 2009 18:52:04 +0100 Subject: Unexpected python exception In-Reply-To: <1257949761.29038.399.camel@dax.rpnet.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> <1257949761.29038.399.camel@dax.rpnet.com> Message-ID: <4AFD9CC4.4040408@wildenhain.de> Am 11.11.2009 15:29, schrieb Richard Purdie: > On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: >> On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: >> >>> Is there a way to make the "global x" apply to all functions without >>> adding it to each one? >> >> Thankfully, no. > > Hmm :(. > >>> What I'm trying to do is to avoid having "import X" statements >>> everywhere by changing __builtin__. It seems my approach doesn't have >>> quite the same effect as a true import though. >> >> And you can't just put all your imports together at the top of the >> file because...? > > The application in question is bitbake, the parsing tool for the > OpenEmbedded and Poky projects. > > We're talking about python code fragments spread across about 8,000 > files which make up the "metadata" some of which is public and some of > which is not. Rightly or wrongly bitbake does some interesting things > with its execution contexts for these code fragments. And you can't just use __import__() to programmatically include some of the fragments instead of having this local/global weirdness in funtions in those modules? > Lets just say its not a traditional use case, we know the way bitbake > does some things is evil but it does other things rather well and we > can't break those. I'd need to see the bigger picture because I don't know of bitbake but I have a feeling this can be done much nicer in the end. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From bryanvick at gmail.com Fri Nov 13 13:20:32 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Nov 2009 10:20:32 -0800 (PST) Subject: Dynamic property names on class References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> <7m5jm2F3egl9mU2@mid.uni-berlin.de> Message-ID: <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> On Nov 13, 9:34?am, "Diez B. Roggisch" wrote: > Bryan schrieb: > > > > > I have several properties on a class that have very similar behavior. > > If one of the properties is set, all the other properties need to be > > set to None. ?So I wanted to create these properties in a loop like: > > > class Test(object): > > ? ?for prop in ['foo', 'bar', 'spam']: > > ? ? ? ? ? ?# Attribute that data is actually stored in > > ? ? ? ? ? ?field = '_' + prop > > ? ? ? ? ? ?# Create getter/setter > > ? ? ? ? ? ?def _get(self): > > ? ? ? ? ? ? ? ? ? ?return getattr(self, field) > > ? ? ? ? ? ?def _set(self, val): > > ? ? ? ? ? ? ? ? ? ?setattr(self, field, val) > > ? ? ? ? ? ? ? ? ? ?for otherProp in prop: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?if otherProp != prop: setattr(self, '_' + otherProp, None) > > ? ? ? ? ? ?# Assign property to class > > ? ? ? ? ? ?setattr(Test, prop, property(_get, _set)) > > > t = Test() > > t.foo = 1 > > assert t.bar == t.spam == None > > > But the class Test is not defined yet, so I can't set a property on > > it. ?How can I do this? > > With a metaclass, or a post-class-creation function. Which is a > metaclass without being fancy. > > Just put your above code into a function with the class in question as > argument, and invoke it after Test is defined. > > Diez I think there are some closure issues with this as I am getting very strange results. I think all properties have the getter/setters of whatever the last item in the list was. t.foo = 'settingFoo' actually sets t.spam, as 'spam' was the last property generated. From jjposner at optimum.net Fri Nov 13 13:21:30 2009 From: jjposner at optimum.net (John Posner) Date: Fri, 13 Nov 2009 13:21:30 -0500 Subject: object indexing and item assignment In-Reply-To: References: Message-ID: <4AFDA3AA.5030403@optimum.net> King wrote: > class MyFloat(object): > def __init__(self, value=0.): > self.value = value > > def set(self, value): > self.value = value > > def get(self): > return self.value > > class MyColor(object): > def __init__(self, value=(0,0,0)): > self.value = (MyFloat(value[0]), > MyFloat(value[1]), > MyFloat(value[2])) > > def set(self, value): > self.value[0].set(value[0]) > self.value[1].set(value[1]) > self.value[2].set(value[2]) > > def get(self): > return (self.value[0].get(), > self.value[1].get(), > self.value[2].get()) > > col = MyColor() > col[0].set(0.5) # 'MyColor' object does not support indexing > col[0] = 0.5 # 'MyColor' object does not support item assignment > King, I think you might be trying too hard. (Since I don't know your "big picture", my suspicion might be wrong.) Python does not *require* you to implement "get" and "set" methods in user-defined classes. More detail ... * You might not need the MyFloat class at all. Try using a plain old Python "float" value. * You don't need the "set" and "get" methods in the MyColor class. So this might suffice: class MyColor(object): def __init__(self, value=(0.,0.,0.)): self.value = list(value) It's important for self.value to be a *list* object only if you want modify individual components of a MyColor instance. If you *do* want to modify individual components, then it *does* make sense to implement "set" and "get" methods: def set_comp(self, index, comp_value): self.value[index] = comp_value def get_comp(self, index): return self.value[index] For debugging, it makes senses to implement a __str__ or __repr__ method, so that "print" produces useful output: def __str__(self): return "MyColor: %3.1f %3.1f %3.1f" % tuple(self.value) Putting it all together ... #----------------- class MyColor(object): def __init__(self, value=(0.,0.,0.)): self.value = list(value) def __str__(self): return "MyColor: %3.1f %3.1f %3.1f" % tuple(self.value) def set_comp(self, index, comp_value): self.value[index] = comp_value def get_comp(self, index): return self.value[index] col = MyColor() print col # output: MyColor: 0.0 0.0 0.0 col.set_comp(0, 0.5) print col # MyColor: 0.5 0.0 0.0 col.set_comp(2, 0.7) print col # MyColor: 0.5 0.0 0.7 col = MyColor((0.2, 0.3, 0.4)) print col # MyColor: 0.2 0.3 0.4 #----------------- -John From animator333 at gmail.com Fri Nov 13 13:26:11 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 10:26:11 -0800 (PST) Subject: object serialization as python scripts References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> Message-ID: <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> > Why is it easier than the above mentioned - they are *there* (except the > custom xml), and just can be used. What don't they do you want to do? > > Other than that, and even security issues put aside, I don't see much > difference between pickle and python code, except the latter being more > verbose. Which suits humans, but other than that has no advantage. > > Diez My application is PyQt based and objects that I am trying to save are couple of QGraphicsItem instances. You can't save instances of QGraphicsItem using pickle or shelve. Custom xml format would be a real pain as you have to write code for writing/reading both. I am aware of security issue but over all there are only 5 statements I have to use to get the entire information back. I can do syntax checking and other stuff before I should execute the script. Another reason is that data should be in human readable form. Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Fri Nov 13 13:45:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 13 Nov 2009 10:45:24 -0800 Subject: object serialization as python scripts In-Reply-To: <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> Message-ID: <50697b2c0911131045k691b4d3fq626ee13306c9ea2c@mail.gmail.com> On Fri, Nov 13, 2009 at 10:26 AM, King wrote: >> Why is it easier than the above mentioned - they are *there* (except the >> custom xml), and just can be used. What don't they do you want to do? >> >> Other than that, and even security issues put aside, I don't see much >> difference between pickle and python code, except the latter being more >> verbose. Which suits humans, but other than that has no advantage. >> >> Diez > > My application is PyQt based and objects that I am trying to save are > couple of QGraphicsItem instances. You can't save instances of > QGraphicsItem > using pickle or shelve. > Custom xml format would be a real pain as you have to write code for > writing/reading both. > > I am aware of security issue but over all there are only 5 statements > I have to use to get the entire > information back. I can do syntax checking and other stuff before I > should execute the script. > > Another reason is that data should be in human readable form. Did you consider the `json` module? JSON is almost identical to Python literal syntax. http://docs.python.org/library/json.html Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Fri Nov 13 14:04:52 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 13 Nov 2009 20:04:52 +0100 Subject: Vote on PyPI comments In-Reply-To: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: >> PyPI grew a commenting and rating system a while back, apparently in >> response to requests from users. However, since it's been rolled out, >> there's been a backlash from package maintainers who already have >> mailing lists, bug trackers, etc for their packages and don't want to >> have to try and keep track of yet another support forum. >> > > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. Hmm, do you really think subscribing to python-list should be a prerequisite for people who want to have some clue which python software they want to use? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ronn.ross at gmail.com Fri Nov 13 14:05:26 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Fri, 13 Nov 2009 14:05:26 -0500 Subject: No subject Message-ID: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> I'm attempting to convert latitude and longitude coordinates from degrees minutes and second to decimal form. I would like to go from: N39 42 36.3 W77 42 51.5 to: -77.739855,39.706666 Does anyone know of a library or some existing out their to help with this conversion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronn.ross at gmail.com Fri Nov 13 14:08:15 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Fri, 13 Nov 2009 14:08:15 -0500 Subject: converting latitude and longitude Message-ID: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> I'm attempting to convert latitude and longitude coordinates from degrees minutes and second to decimal form. I would like to go from: N39 42 36.3 W77 42 51.5 to: -77.739855,39.706666 Does anyone know of a library or some existing out their to help with this conversion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Greg.Tilson at ngc.com Fri Nov 13 14:23:31 2009 From: Greg.Tilson at ngc.com (Tilson, Greg (IS)) Date: Fri, 13 Nov 2009 13:23:31 -0600 Subject: Python 2.6.3 TarFile Module Add odd behavior Message-ID: <49AA837A96E75E4C8CD87901F7F14080032B1228@XMBIL103.northgrum.com> In Windows Python 2.6.3 calling TarFile.add requires arcname= to be set to work with WinZIP or WinRAR Documentation reads: TarFile.add(name, arcname=None, recursive=True, exclude=None) Add the file name to the archive. name may be any type of file (directory, fifo, symbolic link, etc.). If given, arcname specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting recursive to False. If exclude is given it must be a function that takes one filename argument and returns a boolean value. Depending on this value the respective file is either excluded (True) or added (False). Changed in version 2.6: Added the exclude parameter. If arcname= is not set during extraction all filenames are "None" Suggest document change or filing a bug report I am accessing comp.lang.python through email because of Northrop Grumman News server issue -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Nov 13 14:25:28 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Nov 2009 19:25:28 +0000 Subject: converting latitude and longitude In-Reply-To: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> References: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> Message-ID: <4AFDB2A8.5080200@mrabarnett.plus.com> Ronn Ross wrote: > > > I'm attempting to convert latitude and longitude coordinates from > degrees minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this conversion? > The conversion is simple enough. Why do you need a library? BTW, are you sure the values are correct? I get '-77.714306,39.710083'. From mal at egenix.com Fri Nov 13 14:43:19 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 13 Nov 2009 20:43:19 +0100 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <4AFDB6D7.5050903@egenix.com> Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. > > An application source code could be distributed with this small exe to > wrap its top level 'main.py', and the application could then be run on > machines which do not (yet) have Python installed. > > The goal of this is to provide a way for end-users to download and > double-click a Python application, without having to know what Python > is or whether (an appropriate version of) it is installed. This method > has some disadvantages compared to using py2exe et al, but it has the > advantage that a small application would remain small: there is no > need to bundle a whole interpreter with every application. There are two major issues with such an approach: * users will not necessarily like it if a small application downloads a several MB from the web somewhere without asking * installing applications on Windows typically requires admin rights or at least user interaction I think a good solution to the problem is wrapping the application's main.py in a batch file which pops up a window to let the user know that s/he will need to install Python first and point him/her to the www.python.org web site, if necessary. Another aspect to consider is whether a py2exe wrapped Python application is really too big at all. We ship a rather complex application using py2exe (mxODBC Connect Server) and the resulting installed footprint is just around 14 MB - that's roughly the size of a typical YouTube video. By comparison, a full Python 2.5 installation is around 84 MB and includes lots of stuff normally not needed for a small Python application. > From an > advocacy point of view, it also must help that merely running such an > application would seamlessly put a usable Python interpreter installed > and on the PATH on Windows boxes. > > Even my very limited understanding of the issues is enough to see that > the idea is far from trivial. I'm aware that great minds are working > on related and overlapping problems, so I thought I'd ask whether many > people have done this already, and if not, is there any value in > taking the trivial first step described above? ie. Ignore all > complications, and write a simple C program to download & install an > interpreter, then use that to run my Python. > > In the long run, to be useful for real projects, the bootstrapper > would need to manage some nasty details: > * different versions of the interpreter for different applications > * download required packages > * manage conflicting versions of packages > I'm hoping that these thorny problems will be solved, if they aren't > already, by the great minds working on packaging, etc. > > I'm very aware that I don't know anything at all about this, compared > to many on the list. Be gentle with me. :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 13 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 deets at nospam.web.de Fri Nov 13 14:46:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 20:46:54 +0100 Subject: Dynamic property names on class In-Reply-To: <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> <7m5jm2F3egl9mU2@mid.uni-berlin.de> <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> Message-ID: <7m5rdeF3fvmqmU1@mid.uni-berlin.de> Bryan schrieb: > On Nov 13, 9:34 am, "Diez B. Roggisch" wrote: >> Bryan schrieb: >> >> >> >>> I have several properties on a class that have very similar behavior. >>> If one of the properties is set, all the other properties need to be >>> set to None. So I wanted to create these properties in a loop like: >>> class Test(object): >>> for prop in ['foo', 'bar', 'spam']: >>> # Attribute that data is actually stored in >>> field = '_' + prop >>> # Create getter/setter >>> def _get(self): >>> return getattr(self, field) >>> def _set(self, val): >>> setattr(self, field, val) >>> for otherProp in prop: >>> if otherProp != prop: setattr(self, '_' + otherProp, None) >>> # Assign property to class >>> setattr(Test, prop, property(_get, _set)) >>> t = Test() >>> t.foo = 1 >>> assert t.bar == t.spam == None >>> But the class Test is not defined yet, so I can't set a property on >>> it. How can I do this? >> With a metaclass, or a post-class-creation function. Which is a >> metaclass without being fancy. >> >> Just put your above code into a function with the class in question as >> argument, and invoke it after Test is defined. >> >> Diez > > I think there are some closure issues with this as I am getting very > strange results. I think all properties have the getter/setters of > whatever the last item in the list was. > t.foo = 'settingFoo' actually sets t.spam, as 'spam' was the last > property generated. That's a FAQ. Closures capture the *names*, not the values. There are various options to remedy this, e.g. by something like this: def gen_property(prop): def _get(...) # your code return property(_get, _set) setattr(Test, prop, gen_property(prop)) Diez From deets at nospam.web.de Fri Nov 13 14:50:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 20:50:53 +0100 Subject: Vote on PyPI comments In-Reply-To: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: <7m5rktF3fvmqmU2@mid.uni-berlin.de> Michele Simionato schrieb: > On Nov 13, 4:39 pm, Chris Withers wrote: >> PyPI grew a commenting and rating system a while back, apparently in >> response to requests from users. However, since it's been rolled out, >> there's been a backlash from package maintainers who already have >> mailing lists, bug trackers, etc for their packages and don't want to >> have to try and keep track of yet another support forum. >> > > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. The ratio user to posters certainly speaks against that - for any given package, there are so many users that never appear here - but they stil might share insights about the package. Diez From toby at rcsreg.com Fri Nov 13 15:28:43 2009 From: toby at rcsreg.com (Tobiah) Date: Fri, 13 Nov 2009 20:28:43 GMT Subject: run all scripts in sub-directory as subroutines? References: Message-ID: <%jjLm.16238$We2.1157@newsfe09.iad> > This works fine, but in the sub-modules the sys.path appropriately > returns the same as from the parent, I want them to know their own file > names. How?? I can pass it to them, but wondered if there is a more > self-sufficient way for a module to know from where it was invoked. I like the idea of passing the information to the module. Probably by setting a global variable into it. From aaron.watters at gmail.com Fri Nov 13 15:37:59 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 13 Nov 2009 12:37:59 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On Nov 11, 3:15?pm, Terry Reedy wrote: > Robert P. J. Day wrote: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. That time is now, in many cases. I still stand by my strategy published in Unix World ages ago: get it working in Python, profile it, optimize it, if you need to do it faster code the inner loops in C. Of course on google app engine, the last step is not possible, but I don't think it is needed for 90% of applications or more. My own favorite app on google app engine/appspot is http://listtree.appspot.com/ implemented using whiff http://whiff.sourceforge.net as described in this tutorial http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2300.GAEDeploy not as fast as I would like sporadically. But that's certainly not Python's problem because the same application running on my laptop is *much* faster. By the way: the GO language smells like Rob Pike, and I certainly hope it is more successful than Limbo was. Of course, if Google decides to really push it then it's gonna be successful regardless of all other considerations, just like Sun did to Java... -- Aaron Watters === Limbo: how low can you go? From russ.paielli at gmail.com Fri Nov 13 15:41:40 2009 From: russ.paielli at gmail.com (Russ P.) Date: Fri, 13 Nov 2009 12:41:40 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <95ce4d22-194e-4807-b464-c8fc53709696@12g2000pri.googlegroups.com> On Nov 12, 12:06?pm, "Russ P." wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. Has anyone tried this? From Brian.Mingus at Colorado.EDU Fri Nov 13 15:46:15 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Fri, 13 Nov 2009 13:46:15 -0700 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> On Fri, Nov 13, 2009 at 12:19 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > > > When I was approximately 5, everybody knew that higher level languages > were too slow for high-speed numeric computation (I actually didn't know > that then, I was too busy watching Bill and Ben the Flowerpot Men), and > therefore assembly languages were mandatory. Then IBM developed Fortran, and > higher-level languages were not too slow for numeric computation. > > Vincent, could you please fix your mail client, or news client, so > that it follows the standard for mail and news (that is, it has a > hard-break after 68 or 72 characters? > > Having to scroll horizontally to read your posts is a real pain. > > You're joking, right? Try purchasing a computer manufactured in this millennium. Monitors are much wider than 72 characters nowadays, old timer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmitchell at transparent.com Fri Nov 13 15:47:52 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 13 Nov 2009 15:47:52 -0500 Subject: tkFileDialog question In-Reply-To: References: Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Matt Mitchell Sent: Friday, November 13, 2009 9:33 AM To: python-list at python.org Subject: tkFileDialog question Hi, This is my first attempt to write a script with any kind of gui. All I need the script to do is ask the user for a directory and then do stuff with the files in that directory. I used tkFileDialog.askdirectory(). It works great but it pops up an empty tk window. Is there any way to prevent the empty tk window from popping up? Here's the code: import tkFileDialog answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks! Matt -- http://mail.python.org/mailman/listinfo/python-list Hi, After a few more hours of googling I answered my own question: import Tkinter, tkFileDialog root = Tk() root.withdraw() answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks!! From theller at python.net Fri Nov 13 15:48:45 2009 From: theller at python.net (Thomas Heller) Date: Fri, 13 Nov 2009 21:48:45 +0100 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <7m5v1cF3gihrvU1@mid.individual.net> M.-A. Lemburg schrieb: > Jonathan Hartley wrote: >> While examining py2exe et al of late, my thoughts keep returning to >> the idea of writing, in C or similar, a compiled stand-alone >> executable 'bootstrapper', which: >> 1) downloads and install a Python interpreter if none exists >> 2) runs the application's Python source code using this interpreter. >> >> An application source code could be distributed with this small exe to >> wrap its top level 'main.py', and the application could then be run on >> machines which do not (yet) have Python installed. >> >> The goal of this is to provide a way for end-users to download and >> double-click a Python application, without having to know what Python >> is or whether (an appropriate version of) it is installed. This method >> has some disadvantages compared to using py2exe et al, but it has the >> advantage that a small application would remain small: there is no >> need to bundle a whole interpreter with every application. > > There are two major issues with such an approach: > > * users will not necessarily like it if a small application > downloads a several MB from the web somewhere without asking > > * installing applications on Windows typically requires admin > rights or at least user interaction > > I think a good solution to the problem is wrapping the application's > main.py in a batch file which pops up a window to let the user know > that s/he will need to install Python first and point him/her to the > www.python.org web site, if necessary. Here is a batch file that simulates a similar approach, for demonstration purposes it doesn't download and install python, instead it simply copies 'c:\python25\python.exe' to the current directory under a different name (if it is not yet present), and executes the script with it. Batchfile experts should also be able to improve other things: @echo off && if exist py_exe.exe (py_exe.exe -x %0 %* && goto exit) else (goto download) # The python script import sys print "Hi, this is Python", sys.version sys.exit() # rest of the batch file """ :download echo Simulating download... copy c:\python25\python.exe py_exe.exe echo Done. REM start the script again after downloading %0 %* :exit rem """ Thomas From bdesth.quelquechose at free.quelquepart.fr Fri Nov 13 15:53:27 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 21:53:27 +0100 Subject: New syntax for blocks In-Reply-To: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> Message-ID: <4afdd4d8$0$22644$426a74cc@news.free.fr> r a ?crit : > On Nov 12, 7:44 pm, Steven D'Aprano cybersource.com.au> wrote >> Oh, but those hundreds of thousands of man-hours lost to bugs caused by >> assignment-as-an-expression is nothing compared to the dozens of man- >> minutes saved by having one fewer line of code! > > OK, what *if* the variable would only be valid in *that* block and > *that* block only! Python doesn't have the notion of a "block scope" (or "block namespace"). > My first idea was to have the variable avaiable in > the local scope (if that is correct terminology?) so if the > conditional was in global space the value would be available in global > space, alright? You follow me? Now forget all that and observe the > following. ;-) > > if value=range(10): > #this block *would* execute and "value" would be a valid name > #but only IN this block!!! > value.append(1) > elif value=fetch(0): > #this block would *never* execute > value.append(1) > > value.append(1) -> this throws a NameError Yuck. > > Is that different than how other languages handle "assignment-by- > expression"? Will that avoid the cataclysmic downward spiral you speak > of? It's different, but only worse. It doesn't solve the problem of mystyping "=" instead of "==" - which is the reason why Python's assignement is not an expression, and it's not even consistent with mainstream languages that support "assignement as an expression". > I can't see any problems with it I do see at least two big ones !-) Now I don't mean there's not a use case for some "assign and test" syntax - Carl provided a good one, and indeed there are some cases where a dispatcher is *not* the simplest and obvious solution. But by all means, not *this* syntax. From cgrebeld at gmail.com Fri Nov 13 15:58:39 2009 From: cgrebeld at gmail.com (chris grebeldinger) Date: Fri, 13 Nov 2009 12:58:39 -0800 (PST) Subject: 2.6.4 Mac x86_64 ? Message-ID: Hi All, I've been having some trouble getting a x86_64/i386 universal readline.so to build against libedit, on MacOS 10.5.6 as Apple does. Does anyone have any pointers about what changes I need to make to setup.py or readline.c to achive this? Has someone already done this and would like to share it? Are there any plans to provide 64 bit support in future Mac OS 2.6.x releases? Thanks From cmpython at gmail.com Fri Nov 13 16:08:20 2009 From: cmpython at gmail.com (CM) Date: Fri, 13 Nov 2009 13:08:20 -0800 (PST) Subject: A beginner question about GUI use and development References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: On Nov 13, 3:55?am, uap12 wrote: > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) In the context of Python, it is called wxPython. WxWidgets is the C++ version (and around which wxPython is a thin wrapper). > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. As others mentioned, yes. Many people use py2exe for Windows, and py2app for Mac OS X. These have nothing to do with the choice of GUI, though. However, if you choose wxPython as the widget toolkit, you can use a really nice application called GUI2Exe, which is a GUI interface for py2exe, py2app, and a few other such tools, and makes creating a packaged-up executable much easier. > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? Sure--that's one good way. I learned the other way around: by using a GUI designer to teach me what options there were for widgets and how they were coded. One nice IDE and GUI builder for wxPython is Boa Constructor. > I know this is basic question, but i have't found any god answer > so if some takes time to answer i would be happy. Googling these issues or searching this group should turn up dozens of answers and opinions; it has been asked many times. Che From aaron.watters at gmail.com Fri Nov 13 16:13:57 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 13 Nov 2009 13:13:57 -0800 (PST) Subject: wsgi with separate css file References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> Message-ID: RE: serving static CSS files using WSGI > ...However, this method is fragile and very inefficient. If you want to ? > eventually deploy this application somewhere, I would suggest starting ? > with a different method. The WHIFF WSGI tools are meant to make this kind of thing easy. In fact the quick start tells you how to do this http://aaron.oirt.rutgers.edu/myapp/docs/W0500.quickstart And if you want to deploy to the Google App Engine there's a tutorial for that too: http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2300.GAEDeploy For example the http://listtree.appspot.com/ service is implemented using WHIFF under the Google App Engine environment. -- Aaron Watters === TO INFINITY... AND BEYOND! From bdesth.quelquechose at free.quelquepart.fr Fri Nov 13 16:20:16 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 22:20:16 +0100 Subject: New syntax for blocks In-Reply-To: <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> Message-ID: <4afddb20$0$27405$426a74cc@news.free.fr> r a ?crit : > On Nov 12, 2:37 pm, Bruno Desthuilliers > wrote: > >>> Oh i get it now! If i assign a valid value to a variable the variable >>> is also valid...thats...thats... GENUIS! *sarcasm* >> It's not about "assigning a valid value to a variable", it's about the >> name being created (or not) in the current namespace, whatever it's >> bound to. > > And thats what my sarcasm was alluding to. Steven's argument is moot > because it will blow up either way due to the fact that "value" is non- > existent! Sorry, but Steve's code, ie: var = range(100) if var: ... will not break - after the first line, the name "var" exists, whether it's bound to true or false value. While with your proposal *as it is* (or at least as I and Steve understood it), the existence of name "var" depends on some unpredictable condition. > Every argument that has been brought forth about how this > will break is just False Actually, identity testing on True or False is considered a very bad practice. You really want equality testing > and basically a bunch of FUD! It just garbage > so you can discredit the idea. Please take a deep breath and calm down. There's no conspiracy, no secret plan, no hidden agenda, and pointing out the shortcomings of a proposals is definitly not "discredit"ing "the idea". > It's actually quite funny when someone as small as me can bring down > the iron curtain of c.l.py. > '''Mr. Gorbachev, Tear down this wall!''' > > How about one of you "esteemed" Pythonista's show me a real example > where it will break. Steve did. But I'm afraid you missed his point. > > PS: And if it were so dangerous why would someone as knowledgeable as > Carl have stepped in and supported it. Carl supported the idea of a syntax for "assignment and test", but that's not what Steve's comments were about - well, it may be that Steve also refuses to consider the whole idea, but he still has a good point wrt/ some shortcoming of your idea in it's current state. > I think because (like me) Carl > put's the language before sewing circles. I think it's just personal > like all the times before, Well, to be true, you did manage to make a clown of yourself more than once, so don't be surprised if some people here tend to treat you as one - even when you come up with something that _may_ have some value. > that's OK, i have very thick skin! If it's > wrong for a good reason i will graciously accept that, but no one has > proven it's non-worth, not yet! wrong != non-worth. I mean: having some possibly valid use case doesn't imply the proposed solution is the good one in it's current state. And pointing out the shortcomings of the proposed solution doesn't imply the problem is not real neither (now whether it's a critical enough problem to _require_ a solution is another problem I won't even debate here). Anyway, just going to personal considerations won't help. If you ever hope to be taken seriously, first behave as a reasonably sensible and mature person. My (hopefully friendly) 2 cents. From no.email at please.post Fri Nov 13 16:26:01 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 21:26:01 +0000 (UTC) Subject: The ol' [[]] * 500 bug... Message-ID: ...just bit me in the "fuzzy posterior". The best I can come up with is the hideous lol = [[] for _ in xrange(500)] Is there something better? What did one do before comprehensions were available? I suppose in that case one would have to go all the way with lol = [None] * 500 for i in xrange(len(lol)): lol[i] = [] Yikes. 10 miles uphill, both ways... kynn From tjreedy at udel.edu Fri Nov 13 16:48:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Nov 2009 16:48:44 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: Aaron Watters wrote: > On Nov 11, 3:15 pm, Terry Reedy wrote: >> Robert P. J. Day wrote: >> I can imagine a day when code compiled from Python is routinely >> time-competitive with hand-written C. > > That time is now, in many cases. By routinely, I meant ***ROUTINELY***, as in "C become the province of specialized tool coders, much like assembly is now, while most programmers use Python (or similar languages) because they cannot (easily) beat it with hand-coded C." We are not yet at *tha* place yet. > I still stand by my strategy published in Unix World > ages ago: get it working in Python, profile it, optimize > it, if you need to do it faster code the inner loops in > C. Agreed By the way: the GO language smells like Rob Pike, and I certainly hope it is more successful than Limbo was. Of course, if Google decides to really push it then it's gonna be successful regardless of all other considerations, just like Sun did to Java... > By the way: the GO language smells like Rob Pike, > and I certainly hope it is more successful than It still has the stupid, unnecessary, redundant C brackets, given that all their example code is nicely indented like Python. That alone is a deal killer for me. Terry Jan Reedy From eugene.druker at gmail.com Fri Nov 13 16:51:55 2009 From: eugene.druker at gmail.com (ezd) Date: Fri, 13 Nov 2009 13:51:55 -0800 (PST) Subject: converting latitude and longitude References: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> Message-ID: On Nov 13, 2:25?pm, MRAB wrote: > Ronn Ross wrote: > > > I'm attempting to convert latitude and longitude coordinates from ... > > Does anyone know of a library or some existing out their to help with > > this conversion? > Some time ago I saw file named LLUTM... for such conversions with more than 20 ellipsoids. Language of the file - C or Python, not sure. Try Google for LLUTM to find more. Regards, Eugene From joncle at googlemail.com Fri Nov 13 16:56:56 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 13 Nov 2009 13:56:56 -0800 (PST) Subject: The ol' [[]] * 500 bug... References: Message-ID: <6e20a31b-2218-49c5-a32c-5f0147db3172@k19g2000yqc.googlegroups.com> On 13 Nov, 21:26, kj wrote: > ...just bit me in the "fuzzy posterior". ?The best I can come up with > is the hideous > > ? lol = [[] for _ in xrange(500)] > > Is there something better? ? That's generally the accepted way of creating a LOL. > What did one do before comprehensions > were available? ?I suppose in that case one would have to go all > the way with > > ? lol = [None] * 500 > ? for i in xrange(len(lol)): > ? ? ? lol[i] = [] > > Yikes. ?10 miles uphill, both ways... > >>> lol = map(lambda L: [], xrange(5)) >>> [id(i) for i in lol] [167614956, 167605004, 167738060, 167737996, 167613036] Jon. From mark.kecko at gmail.com Fri Nov 13 17:10:10 2009 From: mark.kecko at gmail.com (scoopseven) Date: Fri, 13 Nov 2009 14:10:10 -0800 (PST) Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> Message-ID: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> On Nov 12, 8:55?pm, Steven D'Aprano wrote: > On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: > > I need to create a dictionary of querysets. ?I have code that looks > > like: > > > query1 = Myobject.objects.filter(status=1) > > query2 = Myobject.objects.filter(status=2) > > query3 = Myobject.objects.filter(status=3) > > > d={} > > d['a'] = query1 > > d['b'] = query2 > > d['c'] = query3 > > > Is there a way to do this that I'm missing? > > I don't understand your problem. Assuming Myobject is defined, and has > the appropriate attribute objects.filter, the above should work exactly > as you give it. > > What is your actual problem? Are you asking for help in defining a > queryset? > > -- > Steven I actually had a queryset that was dynamically generated, so I ended up having to use the eval function, like this... d = {} for thing in things: query_name = 'thing_' + str(thing.id) query_string = 'Thing.objects.filter(type=' + str(thing.id) + ').order_by(\'-date\')[:3]' executable_string = query_name + ' = Thing.objects.filter (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' exec(executable_string) d[query_name] = eval(query_string) And no, this is not based on user-generated input. Thanks for the input. From mmanns at gmx.net Fri Nov 13 17:25:39 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Fri, 13 Nov 2009 23:25:39 +0100 Subject: bootstrapping on machines without Python References: Message-ID: <20091113232539.0afbc5fe@Knock> On Fri, 13 Nov 2009 02:40:28 -0800 (PST) Jonathan Hartley wrote: > Even my very limited understanding of the issues is enough to see that > the idea is far from trivial. [...] > In the long run, to be useful for real projects, the bootstrapper > would need to manage some nasty details: > * different versions of the interpreter for different applications > * download required packages > * manage conflicting versions of packages An easy approach could be to use the portable apps version of Python. (I assume that you use Windows.) After installing portable Python on your computer, your application and any additional libraries are put into the site-packages / Scripts folders. Next, the install folder is zipped and provided for download. A batch script, which is downloaded and run by the user, downloads the zip file and extracts it. The script executes python.exe with your Python script as command line argument. In this scenario, the user would not need Administrator privileges. You could also get around compatibility problems by providing preferred versions of additional libraries in the site-packages folder of portable Python. However, the download size would probably exceed 100 MB. I also do not know if there are licensing issues using portable Python like this. Martin From sromero at gmail.com Fri Nov 13 17:35:28 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 14:35:28 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> > Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do > not remember the CPU freqeuncy anymore, maybe 25MHz). Yes, in ASM a simple 25 or 33Mhz 386 computer was able to emulate the Spectrum. At least, under MSDOS, like did Warajevo, Z80, x128 and "Spectrum" from Pedro Gimeno. > First emulator in C that appeared on the emu-scene (I guess it > was x128) needed 486 (~80MHz?) to run at realtime. Pentium and > Pentium II was A LOT of power :-) x128 was not pure C. The first emulator written in pure C was Aspectrum, although Philip Kendall "finished" FUSE (Free UNIX Spectrum Emulator) before my emulator was able to emulate 128K models. But currently only FUSE and ASpectrum can be compiled in lost of platforms (Wii, Dreamcast, PocketPC, NDS...) just by translating the O.S. dependent functions or if the destination platform supports the Allegro library... And at least a P1-P2 is needed for that :-) > http://perl-spectrum.sourceforge.net/ > > It is quite fast IMHO. It does not run 100% in my 1.8Ghz centrino computer :-(, but almost. At least, is a good start to see that is possible, at least no current DualCore computers :-) Thanks! From malaclypse2 at gmail.com Fri Nov 13 17:37:09 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 13 Nov 2009 17:37:09 -0500 Subject: QuerySets in Dictionaries In-Reply-To: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <16651e80911131437r56df712fh2cd5055ffaa5a087@mail.gmail.com> On Fri, Nov 13, 2009 at 5:10 PM, scoopseven wrote: > I actually had a queryset that was dynamically generated, so I ended > up having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) > > And no, this is not based on user-generated input. > I don't get it. If you're already storing the name to query mapping in a dictionary, why do you also need to use exec to do the same thing in the local namespace? If you're generating these names dynamically (which you obviously are, based on this snippet), it's going to be faster and more legible if you just look them up in the dictionary, instead of having to use exec and eval all over the place. Then all you'd need is something like: d = {} for thing in things: query_name = 'thing_%d' % thing.id d[query_name] = Thing.objects.filter(type=thing.id ).order_by('-date')[:3] then later you just look them up as d['thing_1'] (or d[thing_name] if you're dynamically generating the names again). -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Fri Nov 13 17:53:56 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 14 Nov 2009 11:53:56 +1300 Subject: ANN: PyGUI 2.1 Message-ID: PyGUI 2.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Highlights of this version: * Win32: Fixed bug preventing PyGUI apps from working under pythonw Fixed incorrect mouse coordinates in ScrollableView Added more standard cursors * MacOSX: Application menu now has working Hide, Hide Others and Show All commands. Plus a few other bug fixes and improvements. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. From no.email at please.post Fri Nov 13 18:05:57 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 23:05:57 +0000 (UTC) Subject: The ol' [[]] * 500 bug... References: <6e20a31b-2218-49c5-a32c-5f0147db3172@k19g2000yqc.googlegroups.com> Message-ID: In <6e20a31b-2218-49c5-a32c-5f0147db3172 at k19g2000yqc.googlegroups.com> Jon Clements writes: >>>> lol =3D map(lambda L: [], xrange(5)) >>>> [id(i) for i in lol] >[167614956, 167605004, 167738060, 167737996, 167613036] Oh yeah, map! I'd forgotten all about it. Thanks! kynn From aahz at pythoncraft.com Fri Nov 13 18:26:57 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 15:26:57 -0800 Subject: Compiler malware rebutted Message-ID: Ken Thompson's classic paper on bootstrapped malware finally gets a rebuttal: http://lwn.net/Articles/360040/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From zac256 at gmail.com Fri Nov 13 18:27:29 2009 From: zac256 at gmail.com (Zac Burns) Date: Fri, 13 Nov 2009 15:27:29 -0800 Subject: __import__ returns module without it's attributes? Message-ID: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From ryan at rfk.id.au Fri Nov 13 18:28:45 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 14 Nov 2009 10:28:45 +1100 Subject: ANN: esky 0.2.1 In-Reply-To: References: Message-ID: <1258154925.2755.6.camel@durian> > >> Recently I was looking into distribution mechanisms, and I passed over > >> bbfreeze because I saw no indication that Python 2.6 was supported. > > > >Not sure if it's officially supported, but I do most of my development > >on Python 2.6 and bbfreeze hasn't given me any problems as yet. > > Also, bbfreeze doesn't seem to have active development. It's slow but certainly active. Development was recently moved to github with almost no fanfare (in fact I only discovered the github site by accident): http://github.com/schmir/bbfreeze Out of curiosity, what freezer package did you settle on in the end? I'm curious it see if esky could easily switch between different freezers (although it currently depends on some rather deep details of the bbfreeze format). Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From no.email at please.post Fri Nov 13 18:29:07 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 23:29:07 +0000 (UTC) Subject: A "terminators' club" for clp Message-ID: This is "meta-question" about comp.lang.python. I apologize in advance if it has been already discussed. Also, I don't know enough about the underlying mechanics of comp.lang.python, so this may be *totally unfeasible*, but how about giving a few bona fide *and frequent* clp posters the ability to *easily* delete spam from the comp.lang.python server? Or it could be set up so that at least n > 1 "delete" votes and no "keep" votes are required to get something nixed. Etc. This seems simpler than all-out moderation. ("all-out moderation"? now, there's an oxymoron for ya!) One possible *initial* criterion for selecting these "terminators" would be the number of posts to clp between, say, January 2009 and July 2009. The members of this seed set could then select new members for the terminators' club. Just a thought. kynn From http Fri Nov 13 18:32:52 2009 From: http (Paul Rubin) Date: 13 Nov 2009 15:32:52 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7x8wea57bv.fsf@ruckus.brouhaha.com> Tim Chase writes: > Or even just pipe to > your text editor of choice: vi, emacs, ed, cat, and even Notepad > has a "wrap long lines" sort of setting or does the right thing > by default (okay, so cat relies on your console to do the > wrapping, but it does wrap). No, auto wrapping long lines looks like crap. It's better to keep the line length reasonable when you write the posts. This is Usenet so please stick with Usenet practices. If you want a web forum there are plenty of them out there. From http Fri Nov 13 18:43:28 2009 From: http (Paul Rubin) Date: 13 Nov 2009 15:43:28 -0800 Subject: A "terminators' club" for clp References: Message-ID: <7x3a4i56u7.fsf@ruckus.brouhaha.com> kj writes: > frequent* clp posters the ability to *easily* delete spam from the > comp.lang.python server? Um, this is usenet; there is no comp.lang.python server. Are you saying you want a moderated newsgroup? Hmm, maybe this group is busy enough that there is some merit to that idea. From rt8396 at gmail.com Fri Nov 13 19:13:42 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 16:13:42 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: <4d9e5296-6e8d-46fc-8783-ef8e8eb65403@l35g2000vba.googlegroups.com> On Nov 13, 5:29?pm, kj wrote: > This is "meta-question" about comp.lang.python. ?I apologize in > advance if it has been already discussed. ?Also, I don't know enough > about the underlying mechanics of comp.lang.python, so this may be > *totally unfeasible*, but how about giving a few bona fide *and > frequent* clp posters the ability to *easily* delete spam from the > comp.lang.python server? How long you been hanging around here? There are problems inherent in all moderated groups. When you give anyone the power to delete post they can use it for good and for evil. c.l.py like all groups has good and bad followers, spam, and trollers like anywhere else. What you consider spam and trolling i may consider freedom of speech although like anyone here i vehemently hate spammers and would like to put them out of business permanently! Trolls don't bother me so much because i just skip past their posts -- And there are many levels of trolling. However if you are selling something (that is *not* directly python related) then i think we could *safely* say that you are spamming this group. Nobody has come here to buy a knockoff Rolex's or Nike tennis shoes at ten bucks each. If you are posting porn links then we could *safely* say that porn is in no way applicable to this group and delete them on that merit. I'm OK with that, but would it stop there? If you look back through history you will find many instances of the powerful robbing the innocent peoples of freedoms in the name of good, or even the name of God, despicable hypocrite's!. Heck people where murdered by nation states just because of fear and ignorance ("Salem witch trials" ring a bell, the holocaust ring a bell?, and many many more sad cases). So if i had a choice between trollers, spammers, and power hungry murderers, i'll buy the rolex and listen to x-and-lee's all day long thank you very much! Power is corrupting, and absolute power is absolutely corrupting! From davidb at panix.com Fri Nov 13 19:54:21 2009 From: davidb at panix.com (David M. Besonen) Date: Fri, 13 Nov 2009 16:54:21 -0800 Subject: Compiler malware rebutted In-Reply-To: References: Message-ID: <4AFDFFBD.3010707@panix.com> On 11/13/2009 3:26 PM, Aahz wrote: > Ken Thompson's classic paper on bootstrapped malware > finally gets a rebuttal: > > http://lwn.net/Articles/360040/ thanks for pointing this out. -- david From andymac at bullseye.apana.org.au Fri Nov 13 19:57:39 2009 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Sat, 14 Nov 2009 11:57:39 +1100 Subject: questions regarding stack size use for multi-threaded python programs In-Reply-To: References: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Message-ID: <4AFE0083.30003@bullseye.andymac.org> Gabriel Genellina wrote: > En Mon, 09 Nov 2009 16:05:31 -0300, Eyal Gordon > escribi?: > >> background: >> we are using python 2.4.3 on CentOS 5.3 with many threads - and our >> shell's >> default stack size limit is set to 10240KB (i.e. ~10MB). >> >> we noticed that python's Threading module appears to create threads with >> this value as their stack size (we ran a sample program that creates 10 >> threads and measured its virtual memory size, then reduced the stack size >> limit of the shell to 5120KB - and saw that the program's virtual memory >> size was reduced by ~50MBs). >> >> the problem: >> our program uses numerous threads, and thus the virtual memory size >> gets to >> be very large. we would like to reduce the size of the stack to reduce >> this >> size. we were looking for information about recommendation for the stack >> size to use, but found none. > > You can set the thread stack size (for threads that are going to be > created, not existing threads) using threading.stack_size(SIZE) > http://docs.python.org/library/threading.html#threading.stack_size Sadly for the OP, that capability was introduced in Python 2.5. Prior to that, the only way to adjust thread stack size is via a compile time option (THREAD_STACK_SIZE). In the absence of that compile time option, the platform default is used - on pthread systems (incl Linux) refer to the manpage for pthread_attr_setstacksize() for more info, but I believe what the OP reports could reasonably be expected for his platform. The threading.stack_size() support would not be hard to backport to Python 2.4. >> questions: >> 1. is there some rule-of-thumb for the recommended stack size for python >> programs of various sorts? There is no rule of thumb because there are too many variables amongst the supported platforms. Extensive testing would be required to validate any selected size. I would suggest starting with 1MB and working down. On a 32bit platform I would suggest that 64kb might be adequate for child threads but most likely not for the primary thread (the thread that the Python interpreter starts in). If your app uses regexes, your stack space requirements are likely to be larger. FWIW the default thread stack size on Win32 is 1MB which anecdotally seems sufficient for a wide variety of applications on that platform. {...} >> 4. would the size of the stacks (which are probably not really >> allocated by >> the linux virtual memory sub-system, unless used) have a noticeable >> performance effect on a python program? same question regarding the >> use of a >> large number of threads? > > I think it doesn't matter, unless you create so many threads as to exhaust > the available addressing space (in 32bits, 4GB address space and 10MB per > thread means 400 threads maximum). The performance of course will degrade once the committed memory in the active working set exceeds the available real memory, as the OS will start swapping. How the OS treats unused stack space will affect that threshold. -- ------------------------------------------------------------------------- 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 rt8396 at gmail.com Fri Nov 13 20:00:53 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 17:00:53 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> <4afddb20$0$27405$426a74cc@news.free.fr> Message-ID: <2b3a0aab-8551-4c23-be71-9a5e1fc8a812@h2g2000vbd.googlegroups.com> On Nov 13, 3:20?pm, Bruno Desthuilliers wrote: (...snip...) > > I think because (like me) Carl > > put's the language before sewing circles. I think it's just personal > > like all the times before, > > Well, to be true, you did manage to make a clown of yourself more than > once, so don't be surprised if some people here tend to treat you as one > - even when you come up with something that _may_ have some value. Well, i must agree with that assessment. There have been some *interesting* post from me here. I am human and prone to make mistakes like anyone 0:-) > My (hopefully friendly) 2 cents. Thanks, the tone of this message was very good! But anyway this is all moot now. I received a message last night from a very intelligent person who i will not name since the message was only addressed to me (no it's not Guido! I don't want to start any crazy rumors people!) This "persons" response was *so* intelligent and informative i was awe struck whilst reading it and concluded i have no further basis to argue for this syntax change (not at this time anyway). I would like to post this person's message for all to see but i will not without their permission. I can now see how the pros *may* not outweigh the cons and so with that i concede to my opponents. Anyway, good discussion chaps! From aahz at pythoncraft.com Fri Nov 13 20:14:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 17:14:30 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >Out of curiosity, what freezer package did you settle on in the end? >I'm curious it see if esky could easily switch between different >freezers (although it currently depends on some rather deep details of >the bbfreeze format). We're currently using py2app and py2exe and are planning to use cx_freeze for Linux. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Fri Nov 13 20:25:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 17:25:38 -0800 Subject: Compiler malware rebutted References: Message-ID: In article , David M. Besonen wrote: >On 11/13/2009 3:26 PM, Aahz wrote: >> >> Ken Thompson's classic paper on bootstrapped malware >> finally gets a rebuttal: >> >> http://lwn.net/Articles/360040/ > >thanks for pointing this out. Actually, I found out about it on panix.chat ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From bbrown at speakeasy.net Fri Nov 13 20:42:51 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 20:42:51 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > On 2009-11-11, at 14:31, Alain Ketterlin wrote: > I'm having some trouble understanding this thread. My comments aren't > directed at Terry's or Alain's comments, but at the thread overall. > > 1. The statement `Python is slow' doesn't make any sense to me. Python is a > programming language; it is implementations that have speed or lack thereof. This is generally true, but Python *the language* is specified in a way that makes executing Python programs quickly very very difficult. I'm tempted to say it's impossible, but great strides have been made recently with JITs, so we'll see. > 2. A skilled programmer could build an implementation that compiled Python > code into Common Lisp or Scheme code, and then used a high-performance > Common Lisp compiler such as SBCL, or a high-performance Scheme compiler > such as Chez Scheme, to produce quite fast code ... A skilled programmer has done this for Common Lisp. The CLPython implementation converts Python souce code to Common Lisp code at read time, which is then is compiled. With SBCL you get native machine code for every Python expression. http://github.com/franzinc/cl-python/ http://common-lisp.net/project/clpython/ If you want to know why Python *the language* is slow, look at the Lisp code CLPython generates and at the code implementing the run time. Simple operations end up being very expensive. Does the object on the left side of a comparison implement compare? No, then does the right side implement it? No, then try something else .... I'm sure someone can come up with a faster Python implementation, but it will have to be very clever. > This whole approach would be a bad idea, because the compile times would be > dreadful, but I use this example as an existence proof that Python > implementations can generate reasonably efficient executable programs. The compile times are fine, not dreadful. Give it a try. > 3. It is certainly true that CPython doesn't scale up to environments where > there are a significant number of processors with shared memory. Even on one processor, CPython has problems. I last seriously used CPython to analyze OCRed books. The code read in the OCR results for one book at a time, which included the position of every word on every page. My books were long, 2000 pages, and dense and I was constantly fighting address space limitations and CPython slowness related to memory usage. I had to resort to packing and unpacking data into Python integers in order to fit all the OCR data into RAM. bob From bbrown at speakeasy.net Fri Nov 13 21:02:06 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 21:02:06 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis writes: > My point in the earlier post about translating Python into Common Lisp or > Scheme was essentially saying `look, there's more than 30 years experience > building high-performance implementations of Lisp languages, and Python > isn't really that different from Lisp, so we ought to be able to do it too'. Common Lisp and Scheme were designed by people who wanted to write complicated systems on machines with a tiny fraction of the horsepower of current workstations. They were carefully designed to be compiled efficiently, which is not the case with Python. There really is a difference here. Python the language has features that make fast implementations extremely difficult. bob From rhodri at wildebst.demon.co.uk Fri Nov 13 21:11:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 14 Nov 2009 02:11:33 -0000 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: On Thu, 12 Nov 2009 09:59:40 -0000, ankita dutta wrote: > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this > : > > 0.02 0.38 0.01 > 0.04 0.32 0.00 > 0.03 0.40 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i > am > trying with the following code, i am getting errors : > > *code*: > " > ln1=open("A.txt","r+") # file "A.txt" contains my matrix > lines1=ln1.readlines() You can iterate through the file line by line, so there's no need to read the whole thing in one go like this. > n_1=[ ] > > for p1 in range (0,len(lines1)): > f1=lines1[p1] If you ever write range(len(some_list)) in a 'for' statement, you're almost certainly making life harder for yourself than you need to. Since all you use 'pl' for is pulling out the 'current' line, you might as well just iterate through the list, i.e. replace those two lines with this: for fl in lines1: Better, as I mentioned earlier you can skip the whole business of slurping the file in using 'readlines' and read it one line at a time: for fl in ln1: > n_1.append((f1) ) > print n_1 > print sum(n_1[0]) > [snip] > * what I think:* > > as the list is in form of '0.0200\t0.3877\t0.0011\n' , n_1[0] > takes > it as a whole string which includes "\t" , i think thats why they are > giving error. You think right. > now how can i read only required numbers from this line > '0.0200\t0.3877\t0.0011\n' and find their sum ? > can you kindly help me out how to properly code thing . Read the line (as before), then split it on whitespace (the tabs in this case), and then sum the resulting list. Or as Chris said, get the 'csv' module to do the hard work for you. -- Rhodri James *-* Wildebeest Herder to the Masses From bbrown at speakeasy.net Fri Nov 13 21:13:04 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 21:13:04 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <87my2r7imn.fsf@agentultra.com> Message-ID: J Kenneth King writes: > mcherm writes: >> I think you have a fundamental misunderstanding of the reasons why Python >> is slow. Most of the slowness does NOT come from poor implementations: the >> CPython implementation is extremely well-optimized; the Jython and Iron >> Python implementations use best-in-the-world JIT runtimes. Most of the >> speed issues come from fundamental features of the LANGUAGE itself, mostly >> ways in which it is highly dynamic. >> >> -- Michael Chermside > You might be right for the wrong reasons in a way. Python isn't slow > because it's a dynamic language. All the lookups you're citing are highly > optimized hash lookups. It executes really fast. Sorry, but Michael is right for the right reason. Python the *language* is slow because it's "too dynamic". All those hash table lookups are unnecessary in some other dynamic languages and they slow down Python. A fast implementation is going to have to be very clever about memoizing method lookups and invalidating assumptions when methods are dynamically redefined. > As an implementation though, the sky really is the limit and Python is > only getting started. Yes, but Python is starting in the basement. bob From vmanis at telus.net Fri Nov 13 21:15:12 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:15:12 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> References: <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> Message-ID: <89D07812-FF73-4FE7-9AF0-772FFAFB2DC7@telus.net> On 2009-11-13, at 12:46, Brian J Mingus wrote: > You're joking, right? Try purchasing a computer manufactured in this millennium. Monitors are much wider than 72 characters nowadays, old timer. I have already agreed to make my postings VT100-friendly. Oh, wait, the VT-100, or at least some models of it, had a mode where you could have a line width of 132 characters. And what does this have to do with Python? About as much as an exploding penguin on your television. -- v From vmanis at telus.net Fri Nov 13 21:25:59 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:25:59 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7x8wea57bv.fsf@ruckus.brouhaha.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-13, at 15:32, Paul Rubin wrote: > This is Usenet so > please stick with Usenet practices. Er, this is NOT Usenet. 1. I haven't, to the best of my recollection, made a Usenet post in this millennium. 2. I haven't fired up a copy of rn or any other news reader in at least 2 decades. 3. I'm on the python-list mailing list, reading this with Apple's Mail application, which actually doesn't have convenient ways of enforcing `Usenet practices' regarding message format. 4. If we're going to adhere to tried-and-true message format rules, I want my IBM 2260 circa 1970, with its upper-case-only display and weird little end-of-line symbols. Stephen asked me to wrap my posts. I'm happy to do it. Can we please finish this thread off and dispose of it? -- v From rhodri at wildebst.demon.co.uk Fri Nov 13 21:30:13 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 14 Nov 2009 02:30:13 -0000 Subject: #define (from C) in Python In-Reply-To: <2qivs6-v5e.ln1@satorlaser.homedns.org> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> Message-ID: On Fri, 13 Nov 2009 08:43:14 -0000, Ulrich Eckhardt wrote: > Santiago Romero wrote: >> Well, In the above concrete example, that would work, but I was >> talking for multiple code lines, like: >> >> >> #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) >> >> #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> reg = r_op >> >> #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) >> >> #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> r_tmpl = Z80ReadMem(r_op); \ >> r_tmph = Z80ReadMem((r_op)+1); \ >> dreg=r_tmp >> >> #define STORE_nn_rr(dreg) \ >> r_opl = Z80ReadMem(r_PC); r_PC++;\ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> r_tmp = dreg; \ >> Z80WriteMem((r_op),r_tmpl, regs); \ >> Z80WriteMem((r_op+1),r_tmph, regs) > > Someone writing such code and calling it C should be taken behind the > barn > and shot. Having spent all day working on C code with *much* more complex #defines than that, I beg to disagree. Particularly in embedded applications, there are occasions when you absolutely must have bits of code inlined rather than as function calls. In those cases, declaring a function 'inline' is insufficient, as the compiler can choose to ignore you. In Python, however, the point is moot; you don't get to play those games without using a separate preprocessor. I've never particularly felt the urge to try, either. -- Rhodri James *-* Wildebeest Herder to the Masses From rt8396 at gmail.com Fri Nov 13 21:33:11 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 18:33:11 -0800 (PST) Subject: tkFileDialog question References: Message-ID: <51e9fd1a-cfe4-4370-9d95-783010328757@z7g2000vbl.googlegroups.com> On Nov 13, 2:47?pm, "Matt Mitchell" wrote: > ----------------------------------- > The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. > > > > -----Original Message----- > From: python-list-bounces+mmitchell=transparent.... at python.org > > [mailto:python-list-bounces+mmitchell=transparent.... at python.org] On > Behalf Of Matt Mitchell > Sent: Friday, November 13, 2009 9:33 AM > To: python-l... at python.org > Subject: tkFileDialog question > > Hi, > > This is my first attempt to write a script with any kind of gui. ? All I > need the script to do is ask the user for a directory and then do stuff > with the files in that directory. ?I used tkFileDialog.askdirectory(). > It works great but it pops up an empty tk window. ?Is there any way to > prevent the empty tk window from popping up? Here's the code: > > import tkFileDialog > > answer = tkFileDialog.askdirectory() > > if answer is not '': > ? ? ? ? #do stuff > > Thanks! > Matt > --http://mail.python.org/mailman/listinfo/python-list > > Hi, > > After a few more hours of googling I answered my own question: > > import Tkinter, tkFileDialog > > root = Tk() > root.withdraw() > > answer = tkFileDialog.askdirectory() > > if answer is not '': > ? ? ? ? #do stuff > > Thanks!! hello Matt, Here is one way import Tkinter as tk from tkFileDialog import askdirectory import os root = tk.Tk() root.withdraw() folder = askdirectory() if folder: root.destroy() #make sure to do this!!!! print os.listdir(folder) root.mainloop() good luck! From rt8396 at gmail.com Fri Nov 13 21:37:04 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 18:37:04 -0800 (PST) Subject: tkFileDialog question References: Message-ID: <2e71c92c-d63f-441e-b0c1-c2cfd56992ab@g31g2000vbr.googlegroups.com> Opps, i see you answered your own question ;-) To save you more hours of Googling take a look at these two sites! #great reference http://infohost.nmt.edu/tcc/help/pubs/tkinter/ #more in-depth http://effbot.org/tkinterbook/ you'll want to keep them both under your pillow. From vmanis at telus.net Fri Nov 13 21:39:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:39:01 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: > ... Python *the language* is specified in a way that > makes executing Python programs quickly very very difficult. That is untrue. I have mentioned before that optional declarations integrate well with dynamic languages. Apart from CL and Scheme, which I have mentioned several times, you might check out Strongtalk (typed Smalltalk), and Dylan, which was designed for high-performance compilation, though to my knowledge no Dylan compilers ever really achieved it. > I'm tempted to > say it's impossible, but great strides have been made recently with JITs, so > we'll see. > If you want to know why Python *the language* is slow, look at the Lisp code > CLPython generates and at the code implementing the run time. Simple > operations end up being very expensive. Does the object on the left side of a > comparison implement compare? No, then does the right side implement it? No, > then try something else .... I've never looked at CLPython. Did it use a method cache (see Peter Deutsch's paper on Smalltalk performance in the unfortunately out-of-print `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years old now. I have more to say, but I'll do that in responding to Bob's next post. -- v From drobinow at gmail.com Fri Nov 13 21:44:49 2009 From: drobinow at gmail.com (David Robinow) Date: Fri, 13 Nov 2009 18:44:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7x8wea57bv.fsf@ruckus.brouhaha.com> References: <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <4eb0089f0911131844t7032db07i3e9c15fd37427e9a@mail.gmail.com> On Fri, Nov 13, 2009 at 3:32 PM, Paul Rubin wrote: > ... ?This is Usenet so > please stick with Usenet practices. ?If you want a web forum there are > plenty of them out there. Actually this is python-list at python.org I don't use usenet and I have no intention to stick with Usenet practices. From rt8396 at gmail.com Fri Nov 13 22:05:32 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 19:05:32 -0800 (PST) Subject: tkFileDialog question References: <2e71c92c-d63f-441e-b0c1-c2cfd56992ab@g31g2000vbr.googlegroups.com> Message-ID: <1a9d0b84-2f89-44ec-a70e-b4ae56bf343b@x15g2000vbr.googlegroups.com> Opps: And here i go making a clown of myself again... import Tkinter as tk from tkFileDialog import askdirectory import os root = tk.Tk() root.withdraw() folder = askdirectory() #make sure to do this somewhere that will always execute! root.destroy() if folder: print os.listdir(folder) root.mainloop() r... just another would be language designer From vmanis at telus.net Fri Nov 13 22:15:09 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 19:15:09 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <017DAB27-652D-40ED-9E96-5D7AA26DAA7A@telus.net> On 2009-11-13, at 18:02, Robert Brown wrote: > Common Lisp and Scheme were designed by people who wanted to write complicated > systems on machines with a tiny fraction of the horsepower of current > workstations. They were carefully designed to be compiled efficiently, which > is not the case with Python. There really is a difference here. Python the > language has features that make fast implementations extremely difficult. Not true. Common Lisp was designed primarily by throwing together all of the features in every Lisp implementation the design committee was interested in. Although the committee members were familiar with high-performance compilation, the primary impetus was to achieve a standardized language that would be acceptable to the Lisp community. At the time that Common Lisp was started, there was still some sentiment that Lisp machines were the way to go for performance. As for Scheme, it was designed primarily to satisfy an aesthetic of minimalism. Even though Guy Steele's thesis project, Rabbit, was a Scheme compiler, the point here was that relatively simple compilation techniques could produce moderately reasonable object programs. Chez Scheme was indeed first run on machines that we would nowadays consider tiny, but so too was C++. Oh, wait, so was Python! I would agree that features such as exec and eval hurt the speed of Python programs, but the same things do the same thing in CL and in Scheme. There is a mystique about method dispatch, but again, the Smalltalk literature has dealt with this issue in the past. Using Python 3 annotations, one can imagine a Python compiler that does the appropriate thing (shown in the comments) with the following code. import my_module # static linking __private_functions__ = ['my_fn'] # my_fn doesn't appear in the module dictionary. def my_fn(x: python.int32): # Keeps x in a register def inner(z): # Lambda-lifts the function, no nonlocal vars return z // 2 # does not construct a closure y = x + 17 # Via flow analysis, concludes that y can be registerized; return inner(2 * y) # Uses inline integer arithmetic instructions. def blarf(a: python.int32): return my_fn(a // 2) # Because my_fn isn't exported, it can be inlined. A new pragma statement (which I am EXPLICITLY not proposing; I respect and support the moratorium) might be useful in telling the implementation that you don't mind integer overflow. Similarly, new library classes might be created to hold arrays of int32s or doubles. Obviously, no Python system does any of these things today. But there really is nothing stopping a Python system from doing any of these things, and the technology is well-understood in implementations of other languages. I am not claiming that this is _better_ than JIT. I like JIT and other runtime things such as method caches better than these because you don't have to know very much about the implementation in order to take advantage of them. But there may be some benefit in allowing programmers concerned with speed to relax some of Python's dynamism without ruining it for the people who need a truly dynamic language. If I want to think about scalability seriously, I'm more concerned about problems that Python shares with almost every modern language: if you have lots of processors accessing a large shared memory, there is a real GC efficiency problem as the number of processors goes up. On the other hand, if you have a lot of processors with some degree of private memory sharing a common bus (think the Cell processor), how do we build an efficient implementation of ANY language for that kind of environment? Somehow, the issues of Python seem very orthogonal to performance scalability. -- v From http Fri Nov 13 22:15:32 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:15:32 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <7x7httvlt7.fsf@ruckus.brouhaha.com> Vincent Manis writes: > 3. I'm on the python-list mailing list, reading this with Apple's > Mail application, which actually doesn't have convenient ways of > enforcing `Usenet practices' regarding message format. Oh, I see. Damn gateway. > Stephen asked me to wrap my posts. I'm happy to do it. Can we please > finish this thread off and dispose of it? Please wrap to 72 columns or less. It's easier to read that way. (I actually don't care if you do it or not. If you don't, I'll just stop responding to you, which might even suit your wishes.) From http Fri Nov 13 22:38:04 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:38:04 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> Message-ID: <7xpr7lixnn.fsf@ruckus.brouhaha.com> Duncan Booth writes: > > Haskell handles lookups through its type system; dealing with > > lookup errors (say by chaining the Maybe type) is clean and elegant. > I said exceptions or any other method of error handling. I think the use of an option type (like Maybe) is pretty standard and works fine. Go's use of multiple-value returns isn't so bad, but seems old-fashioned. > go routines are executed using a thread pool,... > Most types are not thread safe, so you should never access any mutable > value from more than one go routine. If you need to access something > like a map from multiple parallel routines you need to use channels to > protect it. OK, this sounds sort of like Erlang. > var ch = make(chan int, 3); > would create a channel that holds 3 int values. ... > You can also use a select statement (syntax similar to a switch > statement) to read or write channels in parallel. It arbitrarily chooses > one of the case statements that can proceed to execute,... Thanks, that is informative. The mechanism looks kind of primitive and it would be nice if there were a higher level wrapper of some sort. But again, it seems sort of Erlang-like (though I haven't used Erlang so I only have a vague sense of its similarity). > There doesn't seem to be any way to specify a timeout on a read or > write. I think you can create a timer channel with regular ticks and > select from that to provide an effective timeout, but that sounds like a > lot of boilerplate if you have to do very often. I wonder how Erlang handles this. It seems a little weird to me that they (Google) are concerned with the speed of the compiler, indicating that they plan to write enormous programs in the language. I've heard they use a 1000-node cluster to compile their large C++ apps. Go seems too primitive (so far) to really be suitable for such large-scale development, and (for a newly designed language) seems to be missing a lot of the latest ideas. From greg at cosc.canterbury.ac.nz Fri Nov 13 22:44:07 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 14 Nov 2009 16:44:07 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> Message-ID: <7m6nclF3gnlqfU1@mid.individual.net> Santiago Romero wrote: > Can the above be easily done with another already-existing > application? (example: can m4 do this job)? The problem you're going to have with something like m4 is indentation. When you inline a function call, somehow the inserted code has to be shifted to the same indentation level as the statement containing the call. I don't know of any off-the-shelf macro processor that can handle that sort of thing easily. You may want to consider writing a custom one in Python. You could use the ast facilities to parse the code, operate on the parse tree and then write it back out as code. You might be able to get some ideas from 2to3, which does similar kinds of source-to-source translations. -- Greg From http Fri Nov 13 22:53:00 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:53:00 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: <7xlji9iwyr.fsf@ruckus.brouhaha.com> "Robert P. J. Day" writes: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > thoughts? I'd bet it's not just about multicore scaling and general efficiency, but also the suitability of the language itself for large, complex projects. It's just not possible to be everything for everybody. Python is beginner-friendly, has a very fast learning curve for experienced programmers in other languages, and is highly productive for throwing small and medium sized scripts together, that are debugged through iterated testing. One might say it's optimized for those purposes. I use it all the time because a lot of my programming fits the pattern. The car analogy is the no-frills electric commuter car, just hop in and aim it where you want to go; if you crash it, brush yourself off and restart. But there are times (large production applications) when you really want the Airbus A380 with the 100's of automatic monitoring systems and checkout procedures to follow before you take off, even if the skill level needed to use it is much higher than the commuter car. From michele.simionato at gmail.com Fri Nov 13 23:09:27 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 13 Nov 2009 20:09:27 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> On Nov 14, 4:38?am, Paul Rubin wrote: > It seems a little weird to me that they (Google) are concerned with > the speed of the compiler, indicating that they plan to write enormous > programs in the language. ?I've heard they use a 1000-node cluster to > compile their large C++ apps. ?Go seems too primitive (so far) to > really be suitable for such large-scale development, and (for a newly > designed language) seems to be missing a lot of the latest ideas. It does not look so primitive to me, compared to commonly used languages. I am pretty sure that they are "missing a lot of the latest ideas" on purpose. If they want to succeed and make Go a popular language in the Google infrastructure (ideally replacing C++) their selling point must be a nearly zero learning curve. Python succeded with the low learning curve idea. I wish them the best. Certainly it is time to replace C with something more modern, be it Go or some other language. From aahz at pythoncraft.com Fri Nov 13 23:44:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 20:44:58 -0800 Subject: Choosing GUI Module for Python References: Message-ID: In article , Antony wrote: > > I just wanted to know which module is best for developing designing >interface in python . Haven't tried it, but a new release was just announced for this: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ethan at stoneleaf.us Sat Nov 14 00:33:53 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Nov 2009 21:33:53 -0800 Subject: the unicode saga continues... Message-ID: <4AFE4141.4020102@stoneleaf.us> So I've added unicode support to my dbf package, but I also have some rather large programs that aren't ready to make the switch over yet. So as a workaround I added a (rather lame) option to convert the unicode-ified data that was decoded from the dbf table back into an encoded format. Here's the fun part: in figuring out what the option should be for use with my system, I tried some tests... Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print u'\xed' ? >>> print u'\xed'.encode('cp437') ? >>> print u'\xed'.encode('cp850') ? >>> print u'\xed'.encode('cp1252') ? >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') My confusion lies in my apparant codepage (cp1252), and the discrepancy with character u'\xed' which is absolutely an i with an accent; yet when I encode with cp1252 and print it, I get an o with a line. Can anybody clue me in to what's going on here? ~Ethan~ From zvezdan at zope.com Sat Nov 14 00:53:36 2009 From: zvezdan at zope.com (Zvezdan Petkovic) Date: Sat, 14 Nov 2009 00:53:36 -0500 Subject: 2.6.4 Mac x86_64 ? In-Reply-To: References: Message-ID: <83EE66A8-C926-4D77-8FD4-6187B4D12899@zope.com> On Nov 13, 2009, at 3:58 PM, chris grebeldinger wrote: > Hi All, > I've been having some trouble getting a x86_64/i386 universal > readline.so to build against libedit, on MacOS 10.5.6 as Apple does. > Does anyone have any pointers about what changes I need to make to > setup.py or readline.c to achive this? > Has someone already done this and would like to share it? The fix for use of native editline (readline emulation) was done and is already implemented on the trunk (2.7). Please see: http://bugs.python.org/issue6877 You can find the patch in that tracker issue or here: http://svn.python.org/view?view=rev&revision=74970 It was marked for a backport to a future 2.6.5 release too. > Are there any plans to provide 64 bit support in future Mac OS 2.6.x > releases? AFAIK, it is already supported. Perhaps you should specify the exact problems you have. I believe that a more appropriate place for that would be pythonmac-sig mailing list, though. Best regards, Zvezdan From vmanis at telus.net Sat Nov 14 01:38:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 22:38:01 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7xlji9iwyr.fsf@ruckus.brouhaha.com> References: <7xlji9iwyr.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-13, at 19:53, Paul Rubin wrote: > "Robert P. J. Day" writes: >> http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 >> thoughts? > > I'd bet it's not just about multicore scaling and general efficiency, > but also the suitability of the language itself for large, complex > projects. It's just not possible to be everything for everybody. > Python is beginner-friendly, has a very fast learning curve for > experienced programmers in other languages, and is highly productive > for throwing small and medium sized scripts together, that are > debugged through iterated testing. One might say it's optimized for > those purposes. I use it all the time because a lot of my programming > fits the pattern. The car analogy is the no-frills electric commuter > car, just hop in and aim it where you want to go; if you crash it, > brush yourself off and restart. But there are times (large production > applications) when you really want the Airbus A380 with the 100's of > automatic monitoring systems and checkout procedures to follow before > you take off, even if the skill level needed to use it is much higher > than the commuter car. OK. The quoted link deals with Unladen Swallow, which is an attempt to deal with the very real performance limitations of current Python systems. The remarks above deal with productivity scalability, which is a totally different matter. So... People can and do write large programs in Python, not just `throwing...medium sized scripts together'. Unlike, say, Javascript, it has the necessary machinery to build very large programs that are highly maintainable. One can reasonably compare it with Java, C#, and Smalltalk; the facilities are comparable, and all of those (as well as Python) are used for building enterprise systems. I believe that the A380's control software is largely written in Ada, which is a perfectly fine programming language that I would prefer not to write code in. For approximately 10 years, US DOD pretty much required the use of Ada in military (and aerospace) software (though a a couple of years ago I discovered that there is still one remaining source of Jovial compilers that still sells to DOD). According to a presentation by Lt. Colonel J. A. Hamilton, `Programming Language Policy in the DOD: After The Ada Mandate', given in 1999, `We are unlikely to see a return of a programming language mandate' (www.drew-hamilton.com/stc99/stcAda_99.pdf). As I understand it, the removal of the Ada mandate came from the realization (20 years after many computer scientists *told* DOD this) that software engineering processes contribute more to reliability than do programming language structures (c.f. Fred Brooks, `No Silver Bullet'). So: to sum up, there are lots of large systems where Python might be totally appropriate, especially if complemented with processes that feature careful specification and strong automated testing. There are some large systems where Python would definitely NOT be the language of choice, or even usable at all, because different engineering processes were in place. From a productivity viewpoint, there is no data to say that Python is more, less, or equally scalable than in that it produces correctly-tested, highly-maintainable programs at a lower, higher, or equal cost. I would appreciate it if people who wanted to comment on Python's scalability or lack thereof would give another programming language that they would compare it with. -- v From alfps at start.no Sat Nov 14 01:51:03 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 07:51:03 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach > wrote: >> I think that was in the part you *snipped* here. Just fill in the >> mentioned qualifications and weasel words. > > OK, sure. I don't think they're weasel words, because I find them > useful, but I think I see where you're coming from. > >> Specifically, I reacted to the statement that <> to talk about "the" speed of an implementation>>, made in response to >> someone upthread, in the context of Google finding CPython overall too >> slow. > > IIRC it was "the speed of a language" that was asserted to be nonsense, > wasn't it? Yes, upthread. It's sort of hilarious. Alain Ketterlin: "slide/page 22 explains why python is so slow" Vincent Manis (response): "Python is a programming language; it is implementations that have speed or lack thereof" This was step 1 of trying to be more precise than the concept warranted. Then Steven D'Aprano chimed in, adding even more precision: Steven D'Aprano (further down response stack): "it is sheer nonsense to talk about "the" speed of an implementation" So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. Hip hurray, Google's observation annuled, by the injections of /precision/. :-) > Which IMO is fair -- a physicist friend of mine works with a > C++ interpreter which is relatively sluggish, but that doesn't mean C++ > is slow... Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. Cheers, - Alf From metolone+gmane at gmail.com Sat Nov 14 01:52:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 13 Nov 2009 22:52:16 -0800 Subject: the unicode saga continues... References: <4AFE4141.4020102@stoneleaf.us> Message-ID: "Ethan Furman" wrote in message news:4AFE4141.4020102 at stoneleaf.us... > So I've added unicode support to my dbf package, but I also have some > rather large programs that aren't ready to make the switch over yet. So > as a workaround I added a (rather lame) option to convert the > unicode-ified data that was decoded from the dbf table back into an > encoded format. > > Here's the fun part: in figuring out what the option should be for use > with my system, I tried some tests... > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print u'\xed' > ? > >>> print u'\xed'.encode('cp437') > ? > >>> print u'\xed'.encode('cp850') > ? > >>> print u'\xed'.encode('cp1252') > ? > >>> import locale > >>> locale.getdefaultlocale() > ('en_US', 'cp1252') > > My confusion lies in my apparant codepage (cp1252), and the discrepancy > with character u'\xed' which is absolutely an i with an accent; yet when I > encode with cp1252 and print it, I get an o with a line. > > Can anybody clue me in to what's going on here? Yes, your console window actually uses cp437, cp850 happens to map to the same character, and cp1252 does not. cp1252 is the default Windows encoding (what Notepad uses, for example): Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') >>> import sys >>> sys.stdout.encoding 'cp437' >>> print u'\xed'.encode('cp437') ? >>> print u'\xed'.encode('cp1252') ? -Mark From bbrown at speakeasy.net Sat Nov 14 02:20:44 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 02:20:44 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: >> ... Python *the language* is specified in a way that >> makes executing Python programs quickly very very difficult. > That is untrue. I have mentioned before that optional declarations integrate > well with dynamic languages. Apart from CL and Scheme, which I have > mentioned several times, you might check out Strongtalk (typed Smalltalk), > and Dylan, which was designed for high-performance compilation, though to my > knowledge no Dylan compilers ever really achieved it. You are not making an argument, just mentioning random facts. You claim I've made a false statement, then talk about optional type declarations, which Python doesn't have. Then you mention Smalltalk and Dylan. What's your point? To prove me wrong you have to demonstrate that it's not very difficult to produce a high performance Python system, given current Python semantics. >> I'm tempted to say it's impossible, but great strides have been made >> recently with JITs, so we'll see. > >> If you want to know why Python *the language* is slow, look at the Lisp >> code CLPython generates and at the code implementing the run time. Simple >> operations end up being very expensive. Does the object on the left side >> of a comparison implement compare? No, then does the right side implement >> it? No, then try something else .... > I've never looked at CLPython. Did it use a method cache (see Peter > Deutsch's paper on Smalltalk performance in the unfortunately out-of-print > `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years > old now. Please look at CLPython. The complexity of some Python operations will make you weep. CLPython uses Common Lisp's CLOS method dispatch in various places, so yes, those method lookups are definitely cached. Method lookup is just the tip if the iceburg. How about comparison? Here are some comments from CLPython's implementation of compare. There's a lot going on. It's complex and SLOW. ;; This function is used in comparisons like <, <=, ==. ;; ;; The CPython logic is a bit complicated; hopefully the following ;; is a correct translation. ;; If the class is equal and it defines __cmp__, use that. ;; The "rich comparison" operations __lt__, __eq__, __gt__ are ;; now called before __cmp__ is called. ;; ;; Normally, we take these methods of X. However, if class(Y) ;; is a subclass of class(X), the first look at Y's magic ;; methods. This allows the subclass to override its parent's ;; comparison operations. ;; ;; It is assumed that the subclass overrides all of ;; __{eq,lt,gt}__. For example, if sub.__eq__ is not defined, ;; first super.__eq__ is called, and after that __sub__.__lt__ ;; (or super.__lt__). ;; ;; object.c - try_rich_compare_bool(v,w,op) / try_rich_compare(v,w,op) ;; Try each `meth'; if the outcome it True, return `res-value'. ;; So the rich comparison operations didn't lead to a result. ;; ;; object.c - try_3way_compare(v,w) ;; ;; Now, first try X.__cmp__ (even if y.class is a subclass of ;; x.class) and Y.__cmp__ after that. ;; CPython now does some number coercion attempts that we don't ;; have to do because we have first-class numbers. (I think.) ;; object.c - default_3way_compare(v,w) ;; ;; Two instances of same class without any comparison operator, ;; are compared by pointer value. Our function `py-id' fakes ;; that. ;; None is smaller than everything (excluding itself, but that ;; is catched above already, when testing for same class; ;; NoneType is not subclassable). ;; Instances of different class are compared by class name, but ;; numbers are always smaller. ;; Probably, when we arrive here, there is a bug in the logic ;; above. Therefore print a warning. From doomster at knuut.de Sat Nov 14 02:32:07 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sat, 14 Nov 2009 08:32:07 +0100 Subject: the unicode saga continues... References: Message-ID: <7m74npF3fpqptU1@mid.uni-berlin.de> Ethan Furman wrote: > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print u'\xed' > ? > >>> print u'\xed'.encode('cp437') > ? > >>> print u'\xed'.encode('cp850') > ? > >>> print u'\xed'.encode('cp1252') > ? > >>> import locale > >>> locale.getdefaultlocale() > ('en_US', 'cp1252') > > My confusion lies in my apparant codepage (cp1252), and the discrepancy > with character u'\xed' which is absolutely an i with an accent; yet when > I encode with cp1252 and print it, I get an o with a line. ^^^^^^^^^^^^^^^^^^^^^^ For the record: I read a small Greek letter phi in your posting, not an o with a line. If I encode according to my default locale (UTF-8), I get the letter i with the accent. If I encode with codepage 1252, I get a marker for an invalid character on my terminal. This is using Debian though, not MS Windows. Try printing the repr() of that. The point is that internally, you have the codepoint u00ED (u'\xed'). Then, you encode this thing in various codepages, which yields a string of bytes representing this thing ('\xa1', '\xa1' and '\xed'), useful for storing on disk when the file uses said codepage or other forms of IO. Now, with a Unicode string, the output (print) knows what to do, it encodes it according to the defaultlocale and sends the resulting bytes to stdout. With a byte string, I think it directly forwards the content to stdout. Note: * If you want to verify your code, rather use 'print repr(..)'. * I could imagine that your locale is simply not set up correctly. Uli From paul.nospam at rudin.co.uk Sat Nov 14 02:32:48 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 07:32:48 +0000 Subject: python-daemonize and upstart Message-ID: <87my2pimsf.fsf@rudin.co.uk> I'm experimenting with the daemon module and upstart . There's something I don't understand, which may be more of an upstart issue than a python issue, but I thought I'd start by posting here. Here's a test script: #!/usr/bin/python2.6 import daemon import time def work(): count = 0 while True: with open('/tmp/test.txt', 'a') as f: f.write(str(count)) f.write('\n') count += 1 time.sleep(5) def main(): with daemon.DaemonContext(working_directory='/tmp'): work() if __name__ == "__main__": main() and here's a testdaemon.conf upstart configuration: description "test daemon" expect daemon chdir /tmp exec /tmp/testdaemon.py If I do "sudo start testdaemon" I see the "testdaemon.py" process starting, and the file '/tmp/test.txt' is being written to every 5 seconds, so everything has kicked off. The thing I don't understand is why start does not return. I guess it doesn't think that the process and properly started and daemonized itself? Quite possibly it's just that I don't understand this stuff well... From vmanis at telus.net Sat Nov 14 02:33:25 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 23:33:25 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <699FB81C-6711-487A-86C0-726C08B7EDD0@telus.net> On 2009-11-13, at 22:51, Alf P. Steinbach wrote: > It's sort of hilarious. It really is, see below. > So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. Because `language is slow' is meaningless. An earlier post of mine listed four examples where the common wisdom was `XXX is slow' and yet where that turned out not to be the case. Some others. 1. I once owned a Commodore 64. I got Waterloo Pascal for it. I timed the execution of some program (this was 25 years ago, I forget what the program did) at 1 second per statement. Therefore: `Pascal is slow'. 2. Bell Labs produced a fine programming language called Snobol 4. It was slow. But some folks at IIT in Chicago did their own implementation, Spitbol, which was fast and completely compatible. Presto: Snobol 4 was slow, but then it became fast. 3. If you write the following statements in Fortran IV (the last version of Fortran I learned) DO 10 I=1, 1000000 DO 10 J=1, 1000000 A(I, J) = 0.0 10 CONTINUE you would paralyze early virtual memory systems, because Fortran IV defined arrays to be stored in column major order, and the result was extreme thrashing. Many programmers did not realize this, and would naturally write code like that. Fortran cognoscenti would interchange the two DO statements and thus convert Fortran from being a slow language to being a fast one. 4. When Sun released the original Java system, programs ran very slowly, and everybody said `I will not use Java, it is a slow language'. Then Sun improved their JVM, and other organizations wrote their own JVMs which were fast. Therefore Java became a fast language. > Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. OK, let me work this one out. Because most iostreams implementations are very slow, C++ is a slow language. But since Kuhl did a high-performance implementation, he made C++ into a fast language. But since most people don't use his iostreams implementation, C++ is a slow language again, except for organizations that have banned iostreams (as my previous employers did) because it's too slow, therefore C++ is a fast language. Being imprecise is so much fun! I should write my programs this imprecisely. More seriously, when someone says `xxx is a slow language', the only thing they can possibly mean is `there is no implementation in existence, and no likelihood of an implementation being possible, that is efficient enough to solve my problem in the required time' or perhaps `I must write peculiar code in order to get programs to run in the specified time; writing code in the way the language seems to encourage produces programs that are too slow'. This is a very sweeping statement, and at the very least ought to be accompanied by some kind of proof. If Python is indeed a slow language, then Unladen Swallow and pypy, and many other projects, are wastes of time, and should not be continued. Again, this doesn't have anything to do with features of an implementation that are slow or fast. The only criterion that makes sense is `do programs run with the required performance if written in the way the language's inventors encourage'. Most implementations of every language have a nook or two where things get embarrassingly slow; the question is `are most programs unacceptably slow'. But, hey, if we are ok with being imprecise, let's go for it. Instead of saying `slow' and `fast', why not say `good' and `bad'? -- v From bbrown at speakeasy.net Sat Nov 14 02:39:48 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 02:39:48 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis writes: > On 2009-11-13, at 18:02, Robert Brown wrote: > >> Common Lisp and Scheme were designed by people who wanted to write >> complicated systems on machines with a tiny fraction of the horsepower of >> current workstations. They were carefully designed to be compiled >> efficiently, which is not the case with Python. There really is a >> difference here. Python the language has features that make fast >> implementations extremely difficult. > > Not true. Common Lisp was designed primarily by throwing together all of the > features in every Lisp implementation the design committee was interested > in. Although the committee members were familiar with high-performance > compilation, the primary impetus was to achieve a standardized language that > would be acceptable to the Lisp community. At the time that Common Lisp was > started, there was still some sentiment that Lisp machines were the way to > go for performance. Common Lisp blends together features of previous Lisps, which were designed to be executed efficiently. Operating systems were written in these variants. Execution speed was important. The Common Lisp standardization committee included people who were concerned about performance on C-optimized hardware. > As for Scheme, it was designed primarily to satisfy an aesthetic of > minimalism. Even though Guy Steele's thesis project, Rabbit, was a Scheme > compiler, the point here was that relatively simple compilation techniques > could produce moderately reasonable object programs. Chez Scheme was indeed > first run on machines that we would nowadays consider tiny, but so too was > C++. Oh, wait, so was Python! The Scheme standard has gone through many revisions. I think we're up to version 6 at this point. The people working on it are concerned about performance. For instance, see the discussions about whether the order of evaluating function arguments should be specified. Common Lisp evaluates arguments left to right, but Scheme leaves the order unspecified so the compiler can better optimize. You can't point to Rabbit (1978 ?) as representative of the Scheme programming community over the last few decades. > Using Python 3 annotations, one can imagine a Python compiler that does the > appropriate thing (shown in the comments) with the following code. I can imagine a lot too, but we're talking about Python as it's specified *today*. The Python language as it's specified today is hard to execute quickly. Not impossible, but very hard, which is why we don't see fast Python systems. bob From sturlamolden at yahoo.no Sat Nov 14 02:51:33 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 13 Nov 2009 23:51:33 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <80ea1c52-c845-4802-b77a-d742e789b9b6@m26g2000yqb.googlegroups.com> On 14 Nov, 08:39, Robert Brown wrote: > > Using Python 3 annotations, one can imagine a Python compiler that does the > > appropriate thing (shown in the comments) with the following code. > > I can imagine a lot too, but we're talking about Python as it's specified > *today*. ?The Python language as it's specified today is hard to execute > quickly. ?Not impossible, but very hard, which is why we don't see fast Python > systems. It would not be too difficult to have a compiler like Cython recognize those annotations instead of current "cdef"s. With Cython we can get "Python" to run at "the speed of C" just by adding in optional type declarations for critical variables (most need not be declared). With CMUCL and SBCL we can make Common Lisp perform at "the speed of C", for the same reason. Also a Cython program will usually out-perform most C code. It combines the strengths of C, Fortran 90 and Python. From vmanis at telus.net Sat Nov 14 02:55:22 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 23:55:22 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2009-11-13, at 23:20, Robert Brown wrote, quoting me: > On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: > >>> ... Python *the language* is specified in a way that >>> makes executing Python programs quickly very very difficult. > >> That is untrue. I have mentioned before that optional declarations integrate >> well with dynamic languages. Apart from CL and Scheme, which I have >> mentioned several times, you might check out Strongtalk (typed Smalltalk), >> and Dylan, which was designed for high-performance compilation, though to my >> knowledge no Dylan compilers ever really achieved it. > > You are not making an argument, just mentioning random facts. You claim I've > made a false statement, then talk about optional type declarations, which > Python doesn't have. Then you mention Smalltalk and Dylan. What's your > point? To prove me wrong you have to demonstrate that it's not very difficult > to produce a high performance Python system, given current Python semantics. The false statement you made is that `... Python *the language* is specified in a way that makes executing Python programs quickly very very difficult. I refuted it by citing several systems that implement languages with semantics similar to those of Python, and do so efficiently. >> I've never looked at CLPython. Did it use a method cache (see Peter >> Deutsch's paper on Smalltalk performance in the unfortunately out-of-print >> `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years >> old now. > > Please look at CLPython. The complexity of some Python operations will make > you weep. CLPython uses Common Lisp's CLOS method dispatch in various places, > so yes, those method lookups are definitely cached. Ah, that does explain it. CLOS is most definitely the wrong vehicle for implementing Python method dispatch. CLOS is focused around generic functions that themselves do method dispatch, and do so in a way that is different from Python's. If I were building a Python implementation in CL, I would definitely NOT use CLOS, but do my own dispatch using funcall (the CL equivalent of the now-vanished Python function apply). > Method lookup is just the tip if the iceburg. How about comparison? Here are > some comments from CLPython's implementation of compare. There's a lot going > on. It's complex and SLOW. Re comparison. Python 3 has cleaned comparison up a fair bit. In particular, you can no longer compare objects of different types using default comparisons. However, it could well be that there are nasty little crannies of inefficiency there, they could be the subject of PEPs after the moratorium is over. > > ;; The CPython logic is a bit complicated; hopefully the following > ;; is a correct translation. I can see why CLPython has such troubles. The author has endeavoured to copy CPython faithfully, using an implementation language (CLOS) that is hostile to Python method dispatch. OK, let me try this again. My assertion is that with some combination of JITting, reorganization of the Python runtime, and optional static declarations, Python can be made acceptably fast, which I define as program runtimes on the same order of magnitude as those of the same programs in C (Java and other languages have established a similar goal). I am not pushing optional declarations, as it's worth seeing what we can get out of JITting. If you wish to refute this assertion, citing behavior in CPython or another implementation is not enough. You have to show that the stated feature *cannot* be made to run in an acceptable time. For example, if method dispatch required an exponential-time algorithm, I would agree with you. But a hypothetical implementation that did method dispatch in exponential time for no reason would not be a proof, but would rather just be a poor implementation. -- v From sturlamolden at yahoo.no Sat Nov 14 03:05:59 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:05:59 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <87my2r7imn.fsf@agentultra.com> Message-ID: <840a4457-1973-4cdd-9cb5-92781fab8255@b2g2000yqi.googlegroups.com> On 12 Nov, 18:33, J Kenneth King wrote: > Where Python might get hit *as a language* is that the Python programmer > has to drop into C to implement optimized data-structures for dealing > with the kind of IO that would slow down the Python interpreter. ?That's > why we have numpy, scipy, etc. That's not a Python specific issue. We drop to SciPy/NumPy for certain compute-bound tasks that operates on vectors. If that does not help, we drop further down to Cython, C or Fortran. If that does not help, we can use assembly. In fact, if we use SciPy linked against GotoBLAS, a lot of compute-intensive work solving linear algebra is delegated to hand-optimized assembly. With Python we can stop at the level of abstraction that gives acceptable performance. When using C, we start out at a much lower level. The principle that premature optimization is the root of all evil applies here: Python code that is fast enough is fast enough. It does not matter that hand-tuned assembly will be 1000 times faster. We can direct our optimization effort to the parts of the code that needs it. From http Sat Nov 14 03:10:50 2009 From: http (Paul Rubin) Date: 14 Nov 2009 00:10:50 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <80ea1c52-c845-4802-b77a-d742e789b9b6@m26g2000yqb.googlegroups.com> Message-ID: <7xk4xta5md.fsf@ruckus.brouhaha.com> sturlamolden writes: > With Cython we can get "Python" to run at "the speed of C" just by > adding in optional type declarations for critical variables (most need > not be declared). I think there are other semantic differences too. For general thoughts on such differences (Cython is not mentioned though), see: http://dirtsimple.org/2005/10/children-of-lesser-python.html From vmanis at telus.net Sat Nov 14 03:20:13 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 00:20:13 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <3E25D697-E753-4D05-92DE-F80ED167F7EE@telus.net> On 2009-11-13, at 23:39, Robert Brown wrote, quoting me: > Common Lisp blends together features of previous Lisps, which were designed to > be executed efficiently. Operating systems were written in these variants. > Execution speed was important. The Common Lisp standardization committee > included people who were concerned about performance on C-optimized hardware. Guy L Steele, Jr., `Common Lisp The Language' 1/e (1984). p. 1 `COMMON LISP is intended to meet these goals: Commonality [...] Portability [...] Consistency [...] Expressiveness [...] Compatibility [...] Efficiency [...] Power [...] Stability [...]' The elided text amplifies each of the points. I repeat: the purpose of Common Lisp was to have a standard Lisp dialect; efficiency was less of an issue for those investigators. As for C-optimized hardware, well, the dialects it aims to be compatible with are ZetaLisp (Symbolics Lisp Machine), MacLisp (PDP-10), and Interlisp (PDP-10, originally). CLtL mentions S-1 Lisp as its exemplar of high numerical performance. Unfortunately, S-1 Lisp, written by Richard Gabriel and Rod Brooks was never finished. MacLisp was a highly efficient implementation, as I've mentioned. I worked at BBN at the time Interlisp flourished; it was many things, some of them quite wonderful, but efficiency was NOT its goal. > The Scheme standard has gone through many revisions. I think we're up to > version 6 at this point. The people working on it are concerned about > performance. Yes, they are. You should see 's rants about how specified certain features so they'd be efficient on his implementation. I had real people's names there, but I deleted them in the interests of not fanning flamewar flames. > For instance, see the discussions about whether the order of > evaluating function arguments should be specified. That was a long time ago, and had as much if not more to do with making arguments work the same as let forms as it had to do with efficiency. But I'll point out that the big feature of Scheme is continuations, and it took quite a few years after the first Scheme implementations came out to make continuations stop being horrendously *IN*efficient. > You can't point to Rabbit (1978 ?) as > representative of the Scheme programming community over the last few decades. I didn't. I used it to buttress YOUR argument that Schemers have always been concerned with performance. >> Using Python 3 annotations, one can imagine a Python compiler that does the >> appropriate thing (shown in the comments) with the following code. > I can imagine a lot too, but we're talking about Python as it's specified > *today*. The Python language as it's specified today is hard to execute > quickly. Not impossible, but very hard, which is why we don't see fast Python > systems. Python 3 annotations exist. Check the Python 3 Language Reference. I notice you've weakened your claim. Now we're down to `hard to execute quickly'. That I would agree with you on, in that building an efficient Python system would be a lot of work. However, my claim is that that work is engineering, not research: most of the bits and pieces of how to implement Python reasonably efficiently are known and in the public literature. And that has been my claim since the beginning. -- v From alfps at start.no Sat Nov 14 03:22:03 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 09:22:03 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-13, at 22:51, Alf P. Steinbach wrote: >> It's sort of hilarious. > It really is, see below. > >> So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. > Because `language is slow' is meaningless. > > An earlier post of mine listed four examples where the common wisdom was `XXX is slow' and yet where that > turned out not to be the case. > > Some others. > > 1. I once owned a Commodore 64. I got Waterloo Pascal for it. I timed the execution of some program > (this was 25 years ago, I forget what the program did) at 1 second per statement. Therefore: `Pascal > is slow'. > > 2. Bell Labs produced a fine programming language called Snobol 4. It was slow. But some folks at > IIT in Chicago did their own implementation, Spitbol, which was fast and completely compatible. > Presto: Snobol 4 was slow, but then it became fast. > > 3. If you write the following statements in Fortran IV (the last version of Fortran I learned) > > DO 10 I=1, 1000000 > DO 10 J=1, 1000000 > A(I, J) = 0.0 > 10 CONTINUE > > you would paralyze early virtual memory systems, because Fortran IV defined arrays to be stored > in column major order, and the result was extreme thrashing. Many programmers did not realize > this, and would naturally write code like that. Fortran cognoscenti would interchange the two > DO statements and thus convert Fortran from being a slow language to being a fast one. > > 4. When Sun released the original Java system, programs ran very slowly, and everybody said > `I will not use Java, it is a slow language'. Then Sun improved their JVM, and other organizations > wrote their own JVMs which were fast. Therefore Java became a fast language. > >> Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. > OK, let me work this one out. Because most iostreams implementations are very slow, C++ is a slow > language. But since Kuhl did a high-performance implementation, he made C++ into a fast language. > But since most people don't use his iostreams implementation, C++ is a slow language again, except > for organizations that have banned iostreams (as my previous employers did) because it's too slow, > therefore C++ is a fast language. > > Being imprecise is so much fun! I should write my programs this imprecisely. > > More seriously, when someone says `xxx is a slow language', the only thing they can possibly mean > is `there is no implementation in existence, and no likelihood of an implementation being possible, > that is efficient enough to solve my problem in the required time' or perhaps `I must write peculiar > code in order to get programs to run in the specified time; writing code in the way the language seems > to encourage produces programs that are too slow'. This is a very sweeping statement, and at the very > least ought to be accompanied by some kind of proof. If Python is indeed a slow language, then Unladen > Swallow and pypy, and many other projects, are wastes of time, and should not be continued. > > Again, this doesn't have anything to do with features of an implementation that are slow or fast. > The only criterion that makes sense is `do programs run with the required performance if written > in the way the language's inventors encourage'. Most implementations of every language have a nook > or two where things get embarrassingly slow; the question is `are most programs unacceptably slow'. > > But, hey, if we are ok with being imprecise, let's go for it. Instead of saying `slow' and `fast', > why not say `good' and `bad'? :-) You're piling up so extremely many fallacies in one go that I just quoted it all. Anyways, it's a good example of focusing on irrelevant and meaningless precision plus at the same time utilizing imprecision, higgedly-piggedly as it suits one's argument. Mixing hard precise logic with imprecise concepts and confound e.g. universal quantification with existential quantification, for best effect several times in the same sentence. Like the old Very Hard Logic + imprecision adage: "we must do something. this is something. ergo, we must do this". It's just idiocy. But fun. Cheers & hth., - Alf From ben+python at benfinney.id.au Sat Nov 14 03:28:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 14 Nov 2009 19:28:31 +1100 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> Message-ID: <87tywxse6o.fsf@benfinney.id.au> Paul Rudin writes: > I'm experimenting with the daemon module > and upstart > . First: Thank you for using ?python-daemon?; it's getting more widespread use all the time, which is really helping to find all the quirks of API and implementation. (And good for my ego at the same time.) > There's something I don't understand, which may be more of an upstart > issue than a python issue, but I thought I'd start by posting here. I'm unfamiliar with ?upstart?, I hope others with more experience can offer more insight. > Here's a test script: [?] The program looks fine to me. What happens if you run the program, without getting ?upstart? involved? > and here's a testdaemon.conf upstart configuration: > > description "test daemon" > expect daemon > chdir /tmp > exec /tmp/testdaemon.py > > If I do "sudo start testdaemon" I see the "testdaemon.py" process > starting, and the file '/tmp/test.txt' is being written to every 5 > seconds, so everything has kicked off. Good to know. > The thing I don't understand is why start does not return. I guess it > doesn't think that the process and properly started and daemonized > itself? Quite possibly it's just that I don't understand this stuff > well... As I say, I'm completely unfamiliar with the details of ?upstart?. Can you point me to whatever you used to understand it? -- \ ?I bought some batteries, but they weren't included; so I had | `\ to buy them again.? ?Steven Wright | _o__) | Ben Finney From deets at nospam.web.de Sat Nov 14 03:32:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 09:32:53 +0100 Subject: QuerySets in Dictionaries In-Reply-To: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <7m789lF3gaf1qU1@mid.uni-berlin.de> scoopseven schrieb: > On Nov 12, 8:55 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: >>> I need to create a dictionary of querysets. I have code that looks >>> like: >>> query1 = Myobject.objects.filter(status=1) >>> query2 = Myobject.objects.filter(status=2) >>> query3 = Myobject.objects.filter(status=3) >>> d={} >>> d['a'] = query1 >>> d['b'] = query2 >>> d['c'] = query3 >>> Is there a way to do this that I'm missing? >> I don't understand your problem. Assuming Myobject is defined, and has >> the appropriate attribute objects.filter, the above should work exactly >> as you give it. >> >> What is your actual problem? Are you asking for help in defining a >> queryset? >> >> -- >> Steven > > I actually had a queryset that was dynamically generated, so I ended > up having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) > > And no, this is not based on user-generated input. Why do you need this to use exec? And it seems that executable_string is superflous - or do you want the side-effect? But then, you have the results in d already. query = Thing.objects.filter(type="%i" % thing.id).order_by('-date')[:3] d[query_name] = query As a rule of thumb: if you think you need exec, you don't. Diez From sturlamolden at yahoo.no Sat Nov 14 03:36:23 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:36:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > Of course Python is slow: if you want speed, pay for it by complexity. Python is slow is really a misconception. Python is used for scientific computing at HPC centres around the world. NumPy's predecessor numarray was made by NASA for the Hubble space telescope. Python is slow for certain types of tasks, particularly iterative compute-bound work. But who says you have to use Python for this? It can easily be delegated to libraries written in C or Fortran. I can easily demonstrate Python being faster than C. For example, I could compare the speed of appending strings to a list and "".join (strlist) with multiple strcats in C. I can easily demonstrate C being faster than Python as well. To get speed from a high-level language like Python you have to leverage on high-level data types. But then you cannot compare algorithms in C and Python directly. Also consider that most program today are not CPU-bound: They are i/o bound or memory-bound. Using C does not give you faster disk access, faster ethernet connection, or faster RAM... It does not matter that computation is slow if the CPU is starved anyway. We have to consider what actually limits the speed of a program. Most of all I don't care that computation is slow if slow is fast enough. For example, I have a Python script that parses OpenGL headers and writes a declaration file for Cython. It takes a fraction of a second to complete. Should I migrate it to C to make it 20 times faster? Or do you really think I care if it takes 20 ms or just 1 ms to complete? The only harm the extra CPU cycles did was a minor contribution to global warming. From vmanis at telus.net Sat Nov 14 03:37:23 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 00:37:23 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <425A32A3-0714-4C34-A133-697D5B25B546@telus.net> On 2009-11-14, at 00:22, Alf P. Steinbach wrote, in response to my earlier post. > Anyways, it's a good example of focusing on irrelevant and meaningless precision plus at the same time utilizing imprecision, higgedly-piggedly as it suits one's argument. Mixing hard precise logic with imprecise concepts and confound e.g. universal quantification with existential quantification, for best effect several times in the same sentence. Like the old Very Hard Logic + imprecision adage: "we must do something. this is something. ergo, we must do this". OK, now we've reached a total breakdown in communication, Alf. You appear to take exception to distinguishing between a language and its implementation. My academic work, before I became a computer science/software engineering instructor, was in programming language specification and implementation, so I *DO* know what I'm talking about here. However, you and I apparently are speaking on different wavelengths. > It's just idiocy. Regretfully, I must agree. > But fun. Not so much, from my viewpoint. -- v From deets at nospam.web.de Sat Nov 14 03:40:42 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 09:40:42 +0100 Subject: The ol' [[]] * 500 bug... In-Reply-To: References: Message-ID: <7m78oaF3fgtcfU1@mid.uni-berlin.de> kj schrieb: > ...just bit me in the "fuzzy posterior". The best I can come up with > is the hideous > > lol = [[] for _ in xrange(500)] If you call that hideous, I suggest you perform the same exercise in Java or C++ - and then come back to python and relax.... Diez From sturlamolden at yahoo.no Sat Nov 14 03:43:19 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:43:19 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <027b5ed1-91ed-4b72-b2e0-0c86673ebc87@p8g2000yqb.googlegroups.com> On 14 Nov, 02:42, Robert Brown wrote: > If you want to know why Python *the language* is slow, look at the Lisp code > CLPython generates and at the code implementing the run time. ?Simple > operations end up being very expensive. You can also see this by looking at the C that Cython or Pyrex generates. You can also see the dramatic effect by a handful of strategically placed type declarations. From alfps at start.no Sat Nov 14 03:47:28 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 09:47:28 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: * sturlamolden: > On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > >> Of course Python is slow: if you want speed, pay for it by complexity. > > Python is slow is really a misconception. Sorry, no, I don't think so. But we can't know that without ESP powers. Which seem to be in short supply. > Python is used for > scientific computing at HPC centres around the world. NumPy's > predecessor numarray was made by NASA for the Hubble space telescope. > Python is slow for certain types of tasks, particularly iterative > compute-bound work. But who says you have to use Python for this? It > can easily be delegated to libraries written in C or Fortran. Yes, that's what I wrote immediately following what you quoted. > I can easily demonstrate Python being faster than C. For example, I > could compare the speed of appending strings to a list and "".join > (strlist) with multiple strcats in C. I can easily demonstrate C being > faster than Python as well. That is a straw man argument (which is one of the classic fallacies), that is, attacking a position that nobody's argued for. > To get speed from a high-level language like Python you have to > leverage on high-level data types. But then you cannot compare > algorithms in C and Python directly. > > Also consider that most program today are not CPU-bound: They are i/o > bound or memory-bound. Using C does not give you faster disk access, > faster ethernet connection, or faster RAM... It does not matter that > computation is slow if the CPU is starved anyway. We have to consider > what actually limits the speed of a program. > > Most of all I don't care that computation is slow if slow is fast > enough. For example, I have a Python script that parses OpenGL headers > and writes a declaration file for Cython. It takes a fraction of a > second to complete. Should I migrate it to C to make it 20 times > faster? Or do you really think I care if it takes 20 ms or just 1 ms > to complete? The only harm the extra CPU cycles did was a minor > contribution to global warming. Yeah, that's what I wrote immediately following what you quoted. So, except for the straw man arg and to what degree there is a misconception, which we can't know without ESP, it seems we /completely agree/ on this :-) ) Cheers & hth., - Alf From http Sat Nov 14 03:50:41 2009 From: http (Paul Rubin) Date: 14 Nov 2009 00:50:41 -0800 Subject: The ol' [[]] * 500 bug... References: Message-ID: <7xbpj5trq6.fsf@ruckus.brouhaha.com> kj writes: > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] lol = map(list, [()] * 500) From sturlamolden at yahoo.no Sat Nov 14 04:02:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 01:02:49 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > Hm, this seems religious. > > Of course Python is slow: if you want speed, pay for it by complexity. Not really. The speed problems of Python can to a large extent be attributed to a sub-optimal VM. Perl tends to be much faster than Python. Certain Common Lisp and Scheme implementations can often perform comparable to C++. There are JIT-compiled JavaScript which are very efficient. Java's Hotspot JIT comes from StrongTalk, a fast version of SmallTalk. It's not the static typing that makes Java run fast. It is a JIT originally developed for a dynamic language. Without Hotspot, Java can be just as bad as Python. Even more remarkable: Lua with LuaJIT performs about ~80% of GCC on Debian benchmarks. Question: Why is Lua so fast and Python so slow? Here we have two very similar dynamic scripting languages. One beats JIT-compiled Java and almost competes with C. The other is the slowest there is. Why? Lot of it has to do with the simple fact that Python' VM is stack-based whereas Lua's VM is register based. Stack-based VM's are bad for branch prediction and work against the modern CPUs. Python has reference counting which is bad for cache. Lua has a tracing GC. But these are all implementation details totally orthogonal to the languages. Python on a better VM (LuaJIT, Parrot, LLVM, several JavaScript) will easily outperform CPython by orders of magnitide. Sure, Google can brag about Go running at 80% of C speed, after introducing static typing. But LuaJIT does the same without any typing at all. From alfps at start.no Sat Nov 14 04:11:40 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 10:11:40 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-14, at 00:22, Alf P. Steinbach wrote, in response to my earlier post. > >> Anyways, it's a good example of focusing on irrelevant and meaningless >> precision plus at the same time utilizing imprecision, higgedly-piggedly >> as it suits one's argument. Mixing hard precise logic with imprecise >> concepts and confound e.g. universal quantification with existential >> quantification, for best effect several times in the same sentence. Like >> the old Very Hard Logic + imprecision adage: "we must do something. this >> is something. ergo, we must do this". > > OK, now we've reached a total breakdown in communication, Alf. You appear > to take exception to distinguishing between a language and its implementation. Not at all. But that doesn't mean that making that distinction is always meaningful. It's not like "there exists a context where making the distinction is not meaningful" means that "in all contexts making the distinction is meaningful". So considering that, my quoted comment about confounding universal quantification with existential quantification was spot on... :-) In some contexts, such as here, it is meaningless and just misleading to add the extra precision of the distinction between language and implementation. Academically it's there. But it doesn't influence anything (see below). Providing a counter example, a really fast Python implementation for the kind of processing mix that Google does, available for the relevant environments, would be relevant. Bringing in the hypothethical possibility of a future existence of such an implementation is, OTOH., only hot air. If someone were to apply the irrelevantly-precise kind of argument to that, then one could say that future hypotheticals don't have anything to do with what Python "is", today. Now, there's a fine word-splitting distinction... ;-) > My academic work, before I became a computer science/software engineering > instructor, was in programming language specification and implementation, > so I *DO* know what I'm talking about here. However, you and I apparently > are speaking on different wavelengths. Granted that you haven't related incorrect facts, and I don't think anyone here has, IMO the conclusions and implied conclusions still don't follow. Cheers & hth., - Alf From alfps at start.no Sat Nov 14 04:17:15 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 10:17:15 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * sturlamolden: > On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > >> Hm, this seems religious. >> >> Of course Python is slow: if you want speed, pay for it by complexity. > > Not really. The speed problems of Python can to a large extent be > attributed to a sub-optimal VM. > > Perl tends to be much faster than Python. > > Certain Common Lisp and Scheme implementations can often perform > comparable to C++. > > There are JIT-compiled JavaScript which are very efficient. > > Java's Hotspot JIT comes from StrongTalk, a fast version of SmallTalk. > It's not the static typing that makes Java run fast. It is a JIT > originally developed for a dynamic language. Without Hotspot, Java can > be just as bad as Python. > > Even more remarkable: Lua with LuaJIT performs about ~80% of GCC on > Debian benchmarks. Question: Why is Lua so fast and Python so slow? > Here we have two very similar dynamic scripting languages. One beats > JIT-compiled Java and almost competes with C. The other is the slowest > there is. Why? Lot of it has to do with the simple fact that Python' > VM is stack-based whereas Lua's VM is register based. Stack-based VM's > are bad for branch prediction and work against the modern CPUs. Python > has reference counting which is bad for cache. Lua has a tracing GC. > But these are all implementation details totally orthogonal to the > languages. Python on a better VM (LuaJIT, Parrot, LLVM, several > JavaScript) will easily outperform CPython by orders of magnitide. > > Sure, Google can brag about Go running at 80% of C speed, after > introducing static typing. But LuaJIT does the same without any typing > at all. Good points and good facts. And you dispensed with the word-splitting terminology discussion, writing just "The other [language] is the slowest". Currently. He he. :-) And it is, as you imply, totally in the in-practice domain. Cheers, - Alf From Brian.Mingus at Colorado.EDU Sat Nov 14 04:26:52 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 14 Nov 2009 02:26:52 -0700 Subject: The ol' [[]] * 500 bug... In-Reply-To: <7xbpj5trq6.fsf@ruckus.brouhaha.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> Message-ID: <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin wrote: > kj writes: > > lol = [None] * 500 > > for i in xrange(len(lol)): > > lol[i] = [] > > lol = map(list, [()] * 500) Could someone explain what the deal is with this thread? Thanks. [[]]*500 -------------- next part -------------- An HTML attachment was scrubbed... URL: From vmanis at telus.net Sat Nov 14 04:48:25 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 01:48:25 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >> OK, now we've reached a total breakdown in communication, Alf. You appear >> to take exception to distinguishing between a language and its implementation. > > Not at all. > > But that doesn't mean that making that distinction is always meaningful. It certainly is. A language is a (normally) infinite set of strings with a way of ascribing a meaning to each string. A language implementation is a computer program of some sort, which is a finite set of bits representing a program in some language, with the effect that the observed behavior of the implementation is that strings in the language are accepted, and the computer performs the operations defined by the semantics. These are always different things. > It's not like "there exists a context where making the distinction is not meaningful" means that "in all contexts making the distinction is meaningful". Because they are different things, in all cases the distinction is meaningful. > > So considering that, my quoted comment about confounding universal quantification with existential quantification was spot on... :-) It was not spot on. The examples I provided were just that, examples to help people see the difference. They were not presented as proof. The proof comes from the definitions above. > In some contexts, such as here, it is meaningless and just misleading to add the extra precision of the distinction between language and implementation. Academically it's there. But it doesn't influence anything (see below). Your assertion that this distinction is meaningless must be based upon YOUR definitions of words like `language' and `implementation'. Since I don't know your definitions, I cannot respond to this charge. > Providing a counter example, a really fast Python implementation for the kind of processing mix that Google does, available for the relevant environments, would be relevant. I have presented arguments that the technologies for preparing such an implementation are basically known, and in fact there are projects that aim to do exactly that. > > Bringing in the hypothethical possibility of a future existence of such an implementation is, OTOH., only hot air. Hmm...in every programming project I have ever worked on, the goal was to write code that didn't already exist. > If someone were to apply the irrelevantly-precise kind of argument to that, then one could say that future hypotheticals don't have anything to do with what Python "is", today. Now, there's a fine word-splitting distinction... ;-) Python is a set of strings, with a somewhat sloppily-defined semantics that ascribes meaning to the legal strings in the language. It was thus before any implementation existed, although I imagine that the original Python before GvR wrote any code had many differences from what Python is today. It is quite common for language designers to specify a language completely without regard to an implementation, or only a `reference' implementation that is not designed for performance or robustness. The `good' implementation comes after the language has been defined (though again languages and consequently implementations are almost always modified after the original release). If you like, a language is part of (but not all of) the set of requirements for the implementation. Alf, if you want to say that this is a difference that makes no difference, don't let me stop you. You are, however, completely out of step with the definitions of these terms as used in the field of programming languages. >> My academic work, before I became a computer science/software engineering >> instructor, was in programming language specification and implementation, so I *DO* know what I'm talking about here. However, you and I apparently >> are speaking on different wavelengths. > > Granted that you haven't related incorrect facts, and I don't think anyone here has, IMO the conclusions and implied conclusions still don't follow. The fact that you see the situation that way is a consequence of the fact that we're on different wavelengths. -- v From vlastimil.brom at gmail.com Sat Nov 14 04:50:58 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 14 Nov 2009 10:50:58 +0100 Subject: The ol' [[]] * 500 bug... In-Reply-To: <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> Message-ID: <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> 2009/11/14 Brian J Mingus : > > > On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin > wrote: >> >> kj writes: >> > ? lol = [None] * 500 >> > ? for i in xrange(len(lol)): >> > ? ? ? lol[i] = [] >> >> lol = map(list, [()] * 500) > > Could someone explain what the deal is with this thread? Thanks. > [[]]*500 > Try >>> lst=[[]]*500 >>> lst[7].append(2) >>> lst to see... vbr From Brian.Mingus at Colorado.EDU Sat Nov 14 05:08:46 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 14 Nov 2009 03:08:46 -0700 Subject: The ol' [[]] * 500 bug... In-Reply-To: <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> Message-ID: <9839a05c0911140208y4429adefx7882e45446753bd7@mail.gmail.com> On Sat, Nov 14, 2009 at 2:50 AM, Vlastimil Brom wrote: > 2009/11/14 Brian J Mingus : > > > > > > On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin @nospam.invalid> > > wrote: > >> > >> kj writes: > >> > lol = [None] * 500 > >> > for i in xrange(len(lol)): > >> > lol[i] = [] > >> > >> lol = map(list, [()] * 500) > > > > Could someone explain what the deal is with this thread? Thanks. > > [[]]*500 > > > > Try > >>> lst=[[]]*500 > >>> lst[7].append(2) > >>> lst > to see... > > vbr > -- > I see.. Here's what I came up with: list(eval('[],'*500)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Sat Nov 14 05:22:54 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 02:22:54 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: On 14 Nov, 09:47, "Alf P. Steinbach" wrote: > > Python is slow is really a misconception. > > Sorry, no, I don't think so. No, i really think a lot of the conveived slowness in Python comes from bad programming practices. Sure we can deomstrate that C or LuaJIT is faster by orders of magnitude for CPU-bound tasks like comparing DNA-sequences or or calculating the value of pi. But let me give an example to the opposite from graphics programming, one that we often run into when using OpenGL. This is not a toy benchmark problem but one that is frequently encountered in real programs. We all know that calling functions in Python has a big overhead. There are a dictionary lookup for the attribute name, and arguments are packed into a tuple (and somtimes a dictionary). Thus calling glVertex* repeatedly from Python will hurt. Doing it from C or Fortran might still be ok (albeit not always recommended). So should we conclude that Python is too slow and use C instead? No! What if we use glVertexArray or a display list instead? In case of a vertex array (e.g. using NumPy ndarray for storage), there is practically no difference in performance of C and Python. With a display list, there is a difference on creation, but not on invocation. So slowness from calling glVertex* multiple times is really slowness from bad Python programming. I use numpy ndarrays to store vertices, and pass them to OpenGL as a vertex arrays, instead of hammering on glVertex* in a tight loop. And speed wise, it does not really matter if I use C or Python. But what if we need some computation in the graphics program as well? We might use OpenCL, DirectCompute or OpenGL vertex shaders to control the GPU. Will C be better than Python for this? Most likely not. A program for the GPU is compiled by the graphics driver at run-time from a text string passed to it. It is much better to use Python than C to generate these. Will C on the CPU be better than OpenCL or a vertex shader on the GPU? Most likely not. So we might perhaps conclude that Python (with numpy) is better than C for high-performance graphics? Even though Python is slower than C, we can do just as well as C programmers by not falling into a few stupid pitfalls. Is Python really slower than C for practical programming like this? Superficially, perhaps yes. In practice, only if you use it badly. But that's not Python's fault. But if you make a CPU-bound benchmark like Debian, or time thousands of calls to glVertex*, yes it will look like C is much better. But it does not directly translate to the performance of a real program. The slower can be the faster, it all depends on the programmer. Two related issues: - For the few cases where a graphics program really need C, we can always resort to using ctypes, f2py or Cython. Gluing Python with C or Fortran is very easy using these tools. That is much better than keeping it all in C++. - I mostly find myself using Cython instead of Python for OpenGL. That is because I am unhappy with PyOpenGL. It was easier to expose the whole of OpenGL to Cython than create a full or partial wrapper for Python. With Cython there is no extra overhead from calling glVertex* in a tight loop, so we get the same performance as C in this case. But because I store vertices in NumPy arrays on the Python side, I mostly end up using glVertexArray anyway. From rschroev_nospam_ml at fastmail.fm Sat Nov 14 05:28:48 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 14 Nov 2009 11:28:48 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis schreef: > On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >>> OK, now we've reached a total breakdown in communication, Alf. You appear >>> to take exception to distinguishing between a language and its implementation. >> Not at all. >> >> But that doesn't mean that making that distinction is always meaningful. > It certainly is. A language is a (normally) infinite set of strings with a way of ascribing > a meaning to each string. That's true, for sure. But when people in the Python community use the word Python, the word is not used in the strict sense of Python the language. They use it to refer to both the language and one or more of implementations, mostly one of the existing and working implementations, and in most cases CPython (and sometimes it can also include the documentation, the website or the community). Example: go to http://python.org. Click Download. That page says "Download Python The current product versions are Python 2.6.4 and Python 3.1.1 ..." You can't download a language, but you can download an implementation. Clearly, even the project's website itself uses Python not only to refer to the language, but also to it's main implementation (and in a few places to other implementations). >From that point of view, your distinction between languages and implementations is correct but irrelevant. What is relevant is that all currently usable Python implementations are slow, and it's not incorrect to say that Python is slow. If and when a fast Python implementation gets to a usable state and gains traction (in the hopefully not too distant future), that changes. We'll have to say that Python can be fast if you use the right implementation. And once the most commonly used implementation is a fast one, we'll say that Python is fast, unless you happen to use a slow implementation for one reason or another. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From alfps at start.no Sat Nov 14 05:30:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 11:30:36 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >>> OK, now we've reached a total breakdown in communication, Alf. You appear >>> to take exception to distinguishing between a language and its implementation. >> Not at all. >> >> But that doesn't mean that making that distinction is always meaningful. > It certainly is. A language is a (normally) infinite set of strings with a way of ascribing > a meaning to each string. > > A language implementation is a computer program of some sort, which is a finite set of bits > representing a program in some language, with the effect that the observed behavior of the > implementation is that strings in the language are accepted, and the computer performs the > operations defined by the semantics. > > These are always different things. Well, there you have it, your basic misconception. Sometimes, when that's practically meaningful, people use the name of a language to refer to both, as whoever it was did up-thread. Or, they might mean just the latter. :-) Apply some intelligence and it's all clear. Stick boneheadedly to preconceived distinctions and absolute context independent meanings, and statements using other meanings appear to be meaningless or very unclear. [snippety] Cheers & hth., - Alf PS: You might, or might not, benefit from looking up Usenet discussions on the meaning of "character code", which is classic case of the confusion you have here. There's even a discussion of that in some RFC somewhere, I think it was MIME-related. Terms mean different things in different *contexts*. From rschroev_nospam_ml at fastmail.fm Sat Nov 14 05:35:42 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 14 Nov 2009 11:35:42 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <2KvLm.59963$TK7.5365@newsfe18.ams2> Vincent Manis schreef: > I notice you've weakened your claim. Now we're down to `hard to execute > quickly'. That I would agree with you on, in that building an efficient > Python system would be a lot of work. However, my claim is that that work > is engineering, not research: most of the bits and pieces of how to implement > Python reasonably efficiently are known and in the public literature. And > that has been my claim since the beginning. You talk about what can be and what might be. We talk about what is. The future is an interesting place, but it's not here. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From jjunho at gmail.com Sat Nov 14 05:37:31 2009 From: jjunho at gmail.com (Juliano) Date: Sat, 14 Nov 2009 02:37:31 -0800 (PST) Subject: Help with database planning Message-ID: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Hello, everybody. I'm a linguist with practical skills on computers/programming. We've been working with an ontology at my department, and now I need to create a GUI viewer for the flat file we have. I tried to write an Ontology class which manages the data read and parsed from the flat file, but it takes a relatively long time. Besides, we have plans to set up a website for online display of said ontology. So, I have been being pushed towards changing the basic plan and build a DB so that data access will be faster and easier for both the desktop GUI and the web app. Right now, I'm trying to work with sqlite, since it can be used as a separate file for the GUI and as a DB for Django (which may be the choice for the web interface). I have been redaing some books on DBs but I kind of get stuck when it comes to the normalization and the planning of the tables. The problem is that we have basically four fields that can be arranged in a tree- like structure. Eg: Concept |----- Slot | `------ Facet | `------ Filler `----- Slot `------ Facet `------ Filler `------ Filler ... So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. Besides, some *slots* and *fillers* are themselves *concepts*, creating a sort of recursive reference. line_no concepts slots facets fillers ------------------------------------------------------------------------------ 00000 ABANDON DEFINITION VALUE "to leave or desert something or someone" 00001 ABANDON IS-A VALUE EXIT 00002 ABANDON LEXE MAP-LEX "leave behind-V1" 00003 ABANDON LEXE MAP-LEX abandon-V1 (...) 97420 ZULU DEFINITION VALUE "a language or dialect spoken in south africa and others" 97421 ZULU INSTANCE-OF VALUE OTHER-NIGER-KORDOFANIAN-LANGUAGE 97422 ZULU LANGUAGE-OF INV LESOTHO 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA I tried to create index tables for concepts, slots, facets and fillers, which gave me the following table: line_no concepts slots facets fillers ------------------------------------------------------------------------------ 00000 cn_00000 sl_00048 fc_00007 fl_07349 00001 cn_00000 cn_02605 fc_00007 cn_01768 00002 cn_00000 sl_00121 fc_00002 fl_04329 00003 cn_00000 sl_00121 fc_00002 fl_15009 (...) 97420 cn_05429 sl_00048 fc_00007 fl_01340 97421 cn_05429 cn_02493 fc_00007 cn_03526 97422 cn_05429 cn_02750 fc_00001 cn_02816 97423 cn_05429 cn_02750 fc_00001 cn_04580 (cn_XXXXX from concept index, sl_XXXXX from slot index, fc_XXXXX from facet index, fl_XXXXX from filler index.) As you can see, only concepts and facets are populated by their own type of data. Whereas slots and fillers can be populated by their own types or by concepts. What would be a good way to create tables for this situation? In fact, this is the first time I've ever tried to create a DB, so I'm completely lost. I'm looking forward to a reply... Thank you very much, Juliano From no.email at please.post Sat Nov 14 05:59:41 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 10:59:41 +0000 (UTC) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: In <7x3a4i56u7.fsf at ruckus.brouhaha.com> Paul Rubin writes: >kj writes: >> frequent* clp posters the ability to *easily* delete spam from the >> comp.lang.python server? >Um, this is usenet; there is no comp.lang.python server. Are you >saying you want a moderated newsgroup? Hmm, maybe this group is busy >enough that there is some merit to that idea. Sorry, I had a mistaken view of how usenet was implemented. But yeah, I guess I'm thinking of a moderated newsgroup, but with a large number of moderators working in parallel, and a very lax acceptance policy. The goal is to filter out only the obvious spam, and let through all the other non-spam traffic as quickly as possible... What do I mean by "obvious spam"? Well, among the most recent messages (that have survived my killfile policies) I see the following subject lines: * Top 10 US mp3 songs.....Cheers * www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red monkey gino green global true religion ed-hardy kidrobot jeans hoodies china supplier wholesaler exporters,manufacture * "jobs in france" "jobs in france for english people" "jobs in france for foreigners" "jobs in france for australians" "jobs in france for foreigners " "jobs in france for new zealanders" "jobs" "paris jobs" http://jobs-in-fr ance.blogspot.com/ * "germany jobs" "germany job sites" "germany job search" "jobs in germany" "german jobs" "germany jobs it" "germany jobs for foreigners" "germany jobsite" "germany jobs in english" on http://jobs-germany.blogspot.com/ Those look pretty obvious to me. But, as I already showed, I'm out of my depth here, so I'd better shut up. kynn From no.email at please.post Sat Nov 14 06:14:04 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:14:04 +0000 (UTC) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: In <7xpr7lixnn.fsf at ruckus.brouhaha.com> Paul Rubin writes: >It seems a little weird to me that they (Google) are concerned with >the speed of the compiler, indicating that they plan to write enormous >programs in the language. Fast compilation also means that Go can conceivably become an attractive alternative to interpreted languages, because the compilation stage can be made as unobtrusive as, say, Python's byte-compilation stage (except that the Go compiler is generating native code). I believe that OCaml already offers a way to run code via such on-the-fly compilation, but I doubt that OCaml's compilers are as fast as Go's. kynn From no.email at please.post Sat Nov 14 06:26:00 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:26:00 +0000 (UTC) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: In <129a67e4-328c-42b9-9bf3-152f1b76fa5a at k19g2000yqc.googlegroups.com> Michele Simionato writes: >It does not look so primitive to me, compared to commonly used >languages. >I am pretty sure that they are "missing a lot of the latest ideas" on >purpose. If they want to succeed and make Go a popular language in the >Google >infrastructure (ideally replacing C++) their selling point must be a >nearly zero >learning curve. Python succeded with the low learning curve idea. I >wish them >the best. Certainly it is time to replace C with something more >modern, be it Go >or some other language. The two goals of replacing C with "something more modern" and at the same time have a "nearly zero learning curve" seem to me mutually negating. The closer to zero the learning curve is, the closer to C/C++, and therefore the less modern, that language will be. The "dark matter" in this discussion Google's projected OS, Chrome. Will Go be to Chrome what C was/is to Unix? The close collaboration between Rob Pike and Ken Thompson in this project gives reason to think so. And if so, how has the design of Chrome shaped the design of Go? One more thing: I found Rob Pike's mutterings on generics (towards the end of his rollout video) rather offputting, because he gave the impression that some important aspects of the language were not even considered before major decisions for it were set in stone. It looks like, if they ever get around to supporting generics, it will be a late-in-the-day hack. kynn From rt8396 at gmail.com Sat Nov 14 06:26:41 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 03:26:41 -0800 (PST) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> On Nov 14, 4:59?am, kj wrote: > But, as I already showed, I'm out of my depth here, > so I'd better shut up. Don't give up so easy! The idea is great, what Paul is saying is that most people who read this group use newsreaders and that has nothing to do with google groups. These guy's have kill filters for just this sort of thing but either way the emails are on their puters so they have to deal with them on an individual basis. It would be nice however to clean up the Google group version and rid it of the plagues of spam infestations. From no.email at please.post Sat Nov 14 06:28:02 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:28:02 +0000 (UTC) Subject: How to specify Python version in script? References: <77b812a9-d82c-4aaa-8037-ec30366fc14f@h34g2000yqm.googlegroups.com> Message-ID: In <77b812a9-d82c-4aaa-8037-ec30366fc14f at h34g2000yqm.googlegroups.com> Yinon Ehrlich writes: >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >sys.hexversion, >see http://mail.python.org/pipermail/python-list/2009-June/185939.html Cool. Thanks. kynn From himanshu.garg at gmail.com Sat Nov 14 06:43:11 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Sat, 14 Nov 2009 17:13:11 +0530 Subject: Help with database planning In-Reply-To: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <6f82a7270911140343u4ae027d8s91475442f7bf8381@mail.gmail.com> 2009/11/14 Juliano : > Hello, everybody. > > I'm a linguist with practical skills on computers/programming. > > We've been working with an ontology at my department, and now I need > to create a GUI viewer for the flat file we have. > I tried to write an Ontology class which manages the data read and > parsed from the flat file, but it takes a relatively long time. > Besides, we have plans to set up a website for online display of said > ontology. So, I have been being pushed towards changing the basic plan > and build a DB so that data access will be faster and easier for both > the desktop GUI and the web app. Right now, I'm trying to work with > sqlite, since it can be used as a separate file for the GUI and as a > DB for Django (which may be the choice for the web interface). > > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. The problem > is that we have basically four fields that can be arranged in a tree- > like structure. Eg: > > Concept > ?|----- Slot > ?| ? ? ? ?`------ Facet > ?| ? ? ? ? ? ? ? ? ?`------ Filler > ?`----- Slot > ? ? ? ? ? `------ Facet > ? ? ? ? ? ? ? ? ? ? `------ Filler > ? ? ? ? ? ? ? ? ? ? `------ Filler > ? ?... > > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. > > > line_no concepts ? ? ? ?slots ? facets ?fillers > ------------------------------------------------------------------------------ > 00000 ? ABANDON DEFINITION ? ? ?VALUE ? "to leave or desert something or > someone" > 00001 ? ABANDON IS-A ? ?VALUE ? EXIT > 00002 ? ABANDON LEXE ? ?MAP-LEX "leave behind-V1" > 00003 ? ABANDON LEXE ? ?MAP-LEX abandon-V1 > (...) > 97420 ? ZULU ? ?DEFINITION ? ? ?VALUE ? "a language or dialect spoken in south > africa and others" > 97421 ? ZULU ? ?INSTANCE-OF ? ? VALUE ? OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ? ZULU ? ?LANGUAGE-OF ? ? INV ? ? LESOTHO > 97423 ? ZULU ? ?LANGUAGE-OF ? ? INV ? ? SOUTH-AFRICA > > > I tried to create index tables for concepts, slots, facets and > fillers, which gave me the following table: > > > line_no concepts ? ? ? ?slots ? facets ?fillers > ------------------------------------------------------------------------------ > 00000 ? cn_00000 ? ? ? ?sl_00048 ? ? ? ?fc_00007 ? ? ? ?fl_07349 > 00001 ? cn_00000 ? ? ? ?cn_02605 ? ? ? ?fc_00007 ? ? ? ?cn_01768 > 00002 ? cn_00000 ? ? ? ?sl_00121 ? ? ? ?fc_00002 ? ? ? ?fl_04329 > 00003 ? cn_00000 ? ? ? ?sl_00121 ? ? ? ?fc_00002 ? ? ? ?fl_15009 > (...) > 97420 ? cn_05429 ? ? ? ?sl_00048 ? ? ? ?fc_00007 ? ? ? ?fl_01340 > 97421 ? cn_05429 ? ? ? ?cn_02493 ? ? ? ?fc_00007 ? ? ? ?cn_03526 > 97422 ? cn_05429 ? ? ? ?cn_02750 ? ? ? ?fc_00001 ? ? ? ?cn_02816 > 97423 ? cn_05429 ? ? ? ?cn_02750 ? ? ? ?fc_00001 ? ? ? ?cn_04580 > > > (cn_XXXXX from concept index, sl_XXXXX from slot index, > fc_XXXXX from facet index, fl_XXXXX from filler index.) > > As you can see, only concepts and facets are populated by their own > type of data. > Whereas slots and fillers can be populated by their own types or by > concepts. > > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. > > I'm looking forward to a reply... > > Thank you very much, > Juliano If you have an ontology that doesn't run into GB's of data you could also consider this. Load it into an in memory data structure of your choice from the text file. Here are the arguments in favour :- 1) The structure doesn't lend itself nicely to tables. So a relational database may not be the best choice when you start traversing the data. Imagine writing a query to get the data and show it as a tree. 2) Changes to the ontology are infrequent so you don't use most of the ACID facilities the database offers. 3) cyc uses its own proprietory data format which is probably not a _relational_ database 4) With your own data structure you know where to fix if the performance is bad. The current poor performance could be due to some other problem which may not go away on its own on switching to db. 5) Keeping the data in a flat file has the advantage of making it easy to update and version control. Otherwise you need another program for editing it. I am no database expert so let's see if someone has a better table design suggestion. Thank You, ++imanshu From ken at seehart.com Sat Nov 14 07:15:06 2009 From: ken at seehart.com (Ken Seehart) Date: Sat, 14 Nov 2009 04:15:06 -0800 Subject: Help with database planning In-Reply-To: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <4AFE9F4A.8020509@seehart.com> Good idea to use Django. I've just started using it and I really like it. However, I should give you a heads-up: You will probably want to use a Django migration tool (I'm using South) because the alternative is basically to rebuild your database each time your model changes. Unfortunately, South can sometimes get confused when using anything less sophisticated than PostgreSQL (I switched from MySQL to PostgreSQL for this reason). I don't know if South or the other various Django migration tools work with MySQL. Applying the DRY (don't repeat yourself), you might even consider running the same code as a local web server instead of implementing a separate desktop version. But it is just a suggestion; there are various reasons why you might not want to do that. On to the DB design question... One approach would be to make a Generic class that can represent a concept, slot, or filler, which would have a type field to identify which of these to use. class Concept(models.Model): ... class Slot(models.Model): ... class Filler(models.Model): ... class Facet(models.Model): ... class Generic(models.Model): TYPE_CHOICES = ( (u'c', u'concept'), (u's', u'slot'), (u'f', u'filler'), } # Only one of the following is used. The other two are blank. concept = models.ForeignKey(Concept) slot = models.ForeignKey(Slot) filler = models.ForeignKey(Filler) class ConceptDef(models.Model): concept = models.ForeignKey(Concept) slot = models.ForeignKey(Generic) facet = models.ForeignKey(Facet) filler = models.ForeignKey(Generic) Juliano wrote: > Hello, everybody. > > I'm a linguist with practical skills on computers/programming. > > We've been working with an ontology at my department, and now I need > to create a GUI viewer for the flat file we have. > I tried to write an Ontology class which manages the data read and > parsed from the flat file, but it takes a relatively long time. > Besides, we have plans to set up a website for online display of said > ontology. So, I have been being pushed towards changing the basic plan > and build a DB so that data access will be faster and easier for both > the desktop GUI and the web app. Right now, I'm trying to work with > sqlite, since it can be used as a separate file for the GUI and as a > DB for Django (which may be the choice for the web interface). > > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. The problem > is that we have basically four fields that can be arranged in a tree- > like structure. Eg: > > Concept > |----- Slot > | `------ Facet > | `------ Filler > `----- Slot > `------ Facet > `------ Filler > `------ Filler > ... > > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. > > > line_no concepts slots facets fillers > ------------------------------------------------------------------------------ > 00000 ABANDON DEFINITION VALUE "to leave or desert something or > someone" > 00001 ABANDON IS-A VALUE EXIT > 00002 ABANDON LEXE MAP-LEX "leave behind-V1" > 00003 ABANDON LEXE MAP-LEX abandon-V1 > (...) > 97420 ZULU DEFINITION VALUE "a language or dialect spoken in south > africa and others" > 97421 ZULU INSTANCE-OF VALUE OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ZULU LANGUAGE-OF INV LESOTHO > 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA > > > I tried to create index tables for concepts, slots, facets and > fillers, which gave me the following table: > > > line_no concepts slots facets fillers > ------------------------------------------------------------------------------ > 00000 cn_00000 sl_00048 fc_00007 fl_07349 > 00001 cn_00000 cn_02605 fc_00007 cn_01768 > 00002 cn_00000 sl_00121 fc_00002 fl_04329 > 00003 cn_00000 sl_00121 fc_00002 fl_15009 > (...) > 97420 cn_05429 sl_00048 fc_00007 fl_01340 > 97421 cn_05429 cn_02493 fc_00007 cn_03526 > 97422 cn_05429 cn_02750 fc_00001 cn_02816 > 97423 cn_05429 cn_02750 fc_00001 cn_04580 > > > (cn_XXXXX from concept index, sl_XXXXX from slot index, > fc_XXXXX from facet index, fl_XXXXX from filler index.) > > As you can see, only concepts and facets are populated by their own > type of data. > Whereas slots and fillers can be populated by their own types or by > concepts. > > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. > > I'm looking forward to a reply... > > Thank you very much, > Juliano > From ken at seehart.com Sat Nov 14 07:28:02 2009 From: ken at seehart.com (Ken Seehart) Date: Sat, 14 Nov 2009 04:28:02 -0800 Subject: Help with database planning In-Reply-To: <4AFE9F4A.8020509@seehart.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> <4AFE9F4A.8020509@seehart.com> Message-ID: <4AFEA252.3090400@seehart.com> Oops, forgot the blank arg. Anyway, this is of course untested code... # Only one of the following is used. The other two are blank. concept = models.ForeignKey(Concept, blank=True) slot = models.ForeignKey(Slot, blank=True) filler = models.ForeignKey(Filler, blank=True) Ken Seehart wrote: > Good idea to use Django. I've just started using it and I really like > it. However, I should give you a heads-up: You will probably want to > use a Django migration tool (I'm using South) because the alternative > is basically to rebuild your database each time your model changes. > Unfortunately, South can sometimes get confused when using anything > less sophisticated than PostgreSQL (I switched from MySQL to > PostgreSQL for this reason). I don't know if South or the other > various Django migration tools work with MySQL. > > Applying the DRY (don't repeat yourself), you might even consider > running the same code as a local web server instead of implementing a > separate desktop version. But it is just a suggestion; there are > various reasons why you might not want to do that. > > On to the DB design question... > > One approach would be to make a Generic class that can represent a > concept, slot, or filler, which would have a type field to identify > which of these to use. > > class Concept(models.Model): > ... > > class Slot(models.Model): > ... > > class Filler(models.Model): > ... > > class Facet(models.Model): > ... > > class Generic(models.Model): > TYPE_CHOICES = ( > (u'c', u'concept'), > (u's', u'slot'), > (u'f', u'filler'), > } > > # Only one of the following is used. The other two are blank. > concept = models.ForeignKey(Concept) > slot = models.ForeignKey(Slot) > filler = models.ForeignKey(Filler) > > class ConceptDef(models.Model): > concept = models.ForeignKey(Concept) > slot = models.ForeignKey(Generic) > facet = models.ForeignKey(Facet) > filler = models.ForeignKey(Generic) > > Juliano wrote: >> Hello, everybody. >> >> I'm a linguist with practical skills on computers/programming. >> >> We've been working with an ontology at my department, and now I need >> to create a GUI viewer for the flat file we have. >> I tried to write an Ontology class which manages the data read and >> parsed from the flat file, but it takes a relatively long time. >> Besides, we have plans to set up a website for online display of said >> ontology. So, I have been being pushed towards changing the basic plan >> and build a DB so that data access will be faster and easier for both >> the desktop GUI and the web app. Right now, I'm trying to work with >> sqlite, since it can be used as a separate file for the GUI and as a >> DB for Django (which may be the choice for the web interface). >> >> I have been redaing some books on DBs but I kind of get stuck when it >> comes to the normalization and the planning of the tables. The problem >> is that we have basically four fields that can be arranged in a tree- >> like structure. Eg: >> >> Concept >> |----- Slot >> | `------ Facet >> | `------ Filler >> `----- Slot >> `------ Facet >> `------ Filler >> `------ Filler >> ... >> >> So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has >> ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. >> Besides, some *slots* and *fillers* are themselves *concepts*, >> creating a sort of recursive reference. >> >> >> line_no concepts slots facets fillers >> ------------------------------------------------------------------------------ >> >> 00000 ABANDON DEFINITION VALUE "to leave or desert >> something or >> someone" >> 00001 ABANDON IS-A VALUE EXIT >> 00002 ABANDON LEXE MAP-LEX "leave behind-V1" >> 00003 ABANDON LEXE MAP-LEX abandon-V1 >> (...) >> 97420 ZULU DEFINITION VALUE "a language or dialect spoken >> in south >> africa and others" >> 97421 ZULU INSTANCE-OF VALUE >> OTHER-NIGER-KORDOFANIAN-LANGUAGE >> 97422 ZULU LANGUAGE-OF INV LESOTHO >> 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA >> >> >> I tried to create index tables for concepts, slots, facets and >> fillers, which gave me the following table: >> >> >> line_no concepts slots facets fillers >> ------------------------------------------------------------------------------ >> >> 00000 cn_00000 sl_00048 fc_00007 fl_07349 >> 00001 cn_00000 cn_02605 fc_00007 cn_01768 >> 00002 cn_00000 sl_00121 fc_00002 fl_04329 >> 00003 cn_00000 sl_00121 fc_00002 fl_15009 >> (...) >> 97420 cn_05429 sl_00048 fc_00007 fl_01340 >> 97421 cn_05429 cn_02493 fc_00007 cn_03526 >> 97422 cn_05429 cn_02750 fc_00001 cn_02816 >> 97423 cn_05429 cn_02750 fc_00001 cn_04580 >> >> >> (cn_XXXXX from concept index, sl_XXXXX from slot index, >> fc_XXXXX from facet index, fl_XXXXX from filler index.) >> >> As you can see, only concepts and facets are populated by their own >> type of data. >> Whereas slots and fillers can be populated by their own types or by >> concepts. >> >> What would be a good way to create tables for this situation? >> In fact, this is the first time I've ever tried to create a DB, so I'm >> completely lost. >> >> I'm looking forward to a reply... >> >> Thank you very much, >> Juliano >> > From sturlamolden at yahoo.no Sat Nov 14 07:29:55 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 04:29:55 -0800 (PST) Subject: Python & Go References: Message-ID: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> On 12 Nov, 01:53, kj wrote: > I'm just learning about Google's latest: the GO (Go?) language. > (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", the absence of parentheses at the top of > flow control constructs, and quite a few statements without a > trailing semicolon. ?Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. ?And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... It seems that the argument for using Go over Python is speed. They achieve that by static typing. According to Debian benchmarks, LuaJIT delivers the same performance as Google cleaims for Go (about 20% loss compared to C), and that is from a completely dynamic language. (Lua is Python's sibling.) It makes me wonder what Python would be like on LuaJIT. Perhaps we should make a Python frontend for the Lua VM and try? It would be fun :-) Anyway, the impressive performance of LuaJIT on Debian benchmarks just tells med that static typing a la Go is not needed for fast execution of CPU-bound code. And looking at Go, I cannot understand why Google prefer this over e.g. Lua. From sturlamolden at yahoo.no Sat Nov 14 07:39:20 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 04:39:20 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> On 9 Nov, 05:49, Antony wrote: > ? ?I just wanted to know which module is best for developing designing > interface in python . I personally feel the wxPython support in the 3.1 beta of wxFormBuilder makes the choise rather simple. It generates a Python file with classes for all WYSIWYG GUI forms/windows/dialogs. Then in our Python code, we just import and inherit the form, and implement the event handlers. It can't be done easier. GUI programming with Python is now comparable to programming with VB, Delphi or C#. I am using it for all my projects now. It just feels right. From martin at v.loewis.de Sat Nov 14 08:16:45 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 14 Nov 2009 14:16:45 +0100 Subject: the unicode saga continues... In-Reply-To: References: Message-ID: <4AFEADBD.90506@v.loewis.de> > Can anybody clue me in to what's going on here? It's as Mark says: the console encoding is cp437 on your system, cp1252. Windows has *two* default code pages at any point in time: the OEM code page, and the ANSI code page. Either one depends on the Windows release (Western, Japanese, etc.), and can be set by the administrator. The OEM code page is primarily used for the console (and then also as the encoding on the FAT filesystem); the ANSI code page is used in all other places (that don't use Unicode APIs). In addition, the console code page may deviate from the OEM code page, if you run chcp.exe. Regards, Martin From ben+python at benfinney.id.au Sat Nov 14 08:23:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 00:23:48 +1100 Subject: Help with database planning References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <87my2ps0ij.fsf@benfinney.id.au> Juliano writes: > We've been working with an ontology at my department [?] I have been > being pushed towards changing the basic plan and build a DB so that > data access will be faster and easier for both the desktop GUI and the > web app. Right now, I'm trying to work with sqlite, since it can be > used as a separate file for the GUI and as a DB for Django (which may > be the choice for the web interface). You're also working with a relational database system, which will make it relatively easy to migrate your database structure to a different relational database system if that proves necessary. > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. No shame in that; it's somewhat counter-intuitive, though it's an essential topic when working with databases. Try the Wikipedia article . > The problem is that we have basically four fields that can be arranged > in a tree- like structure. Tree-like structures don't fit into table-like relations very well; but it's not hopeless. > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. Recursive references, on the other hand, are deadly to storing data sanely in a relational database: while recursion is algorithmically elegant, it makes for hideously slow operations querying, and especially modifying, the database. The focus, then, should be on teasing out a non-recursive, declarative schema for the data. This is a well-known problem, with many possible solutions. Several popular approaches (each with different trade-offs) are ?Adjacency list? , ?Materialized path?, and ?Nested sets?. Use those terms in database-savvy circles and you'll get lots of explanations. > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. This topic is rather orthogonal to Python. You would do well to seek further guidance from a Usenet group such as . Good fortune, and persist; you're going into databases off the deep end with a problem domain like this :-) -- \ ?I distrust those people who know so well what God wants them | `\ to do to their fellows, because it always coincides with their | _o__) own desires.? ?Susan Brownell Anthony, 1896 | Ben Finney From lusvehla at gmail.com Sat Nov 14 08:24:26 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 05:24:26 -0800 (PST) Subject: COM Server wirh MS Excel Message-ID: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Hi, I would lake use win32com with Excel. I tried to use python COM example from 'The Quick Python Book' on page 250 but without success. The COM Module is successfully registetred but MS Excel reported this message http://home.tiscali.cz/fotogalerie7/Error80004005.gif I tried omitted following statement (how counselling on http://manning-sandbox.com/thread.jspa?messageID=7263): #_reg_class_spec_ = "ar_com_servers.DemoServer and new registration but not successful :-( Pleas help me From x7-g5W_rt at earthlink.net Sat Nov 14 08:28:30 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Sat, 14 Nov 2009 05:28:30 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: On Nov 13, 5:29?pm, kj wrote: [...] > Or it could be set up so that at least n > 1 "delete" votes and no > "keep" votes are required to get something nixed. ?Etc. > > This seems simpler than all-out moderation. > > ("all-out moderation"? now, there's an oxymoron for ya!) > How about using a "rank this post" feature? Anybody could rank a post as spam, and a sufficiently large number of negatives would quickly draw the attention of someone with the power to kill the message. I suppose even this is subject to abuse, allowing harassment of a legitimate poster., but my guess is that the votes against counterfeit Nike shoes, etc., would outnumber the most energetic "vote troll." Gil From chris at simplistix.co.uk Sat Nov 14 08:34:42 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 13:34:42 +0000 Subject: COM Server wirh MS Excel In-Reply-To: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: <4AFEB1F2.5080808@simplistix.co.uk> Cannonbiker wrote: > Hi, > I would lake use win32com with Excel. I tried to use python COM > example from 'The Quick Python Book' on page 250 but without success. I suggest you have a good read of http://www.python-excel.org. You may well find you don't need to use COM at all...# Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From lusvehla at gmail.com Sat Nov 14 08:44:34 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 05:44:34 -0800 (PST) Subject: COM Server wirh MS Excel References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: On 14 lis, 14:24, Cannonbiker wrote: The ServerCOM file is here http://home.tiscali.cz/fotogalerie7/ServerCOM.py From urbangabo at gmail.com Sat Nov 14 08:45:48 2009 From: urbangabo at gmail.com (Gabor Urban) Date: Sat, 14 Nov 2009 14:45:48 +0100 Subject: More Python versions on an XP machine Message-ID: Hi guys, this a very MS specific question. I do use a rather old Python version, because we have a couple of applications written for that. Porting them to a newer Python is not allowed by the bosses. Now we will start a new project with latest stable Python. Can I have them both on my computer, and how should I do that. Thanks, PS: This is my computer at the office.... :-) -- Linux: Choice of a GNU Generation From alfps at start.no Sat Nov 14 08:52:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 14:52:31 +0100 Subject: A "terminators' club" for clp In-Reply-To: References: Message-ID: * gil_johnson: > On Nov 13, 5:29 pm, kj wrote: > [...] >> Or it could be set up so that at least n > 1 "delete" votes and no >> "keep" votes are required to get something nixed. Etc. >> >> This seems simpler than all-out moderation. >> >> ("all-out moderation"? now, there's an oxymoron for ya!) >> > > How about using a "rank this post" feature? Anybody could rank a post > as spam, and a sufficiently large number of negatives would quickly > draw the attention of someone with the power to kill the message. I > suppose even this is subject to abuse, allowing harassment of a > legitimate poster., but my guess is that the votes against counterfeit > Nike shoes, etc., would outnumber the most energetic "vote troll." The problem with moderation isn't getting rid of spam and trolls etc., but turnaround time. In some cases trivial questions cause a flood of essentially identical trivial responses to pile up before the mods can get at them. And then there's the dilemma of whether to approve all that or make judgements based on /content/. The latter leads to a very slippery slope, you really don't want the mods to do that, plus that in some cases what might appear trivial leads to very fruitful discussion of not-so-trivial aspects. But it's not either/or: it's possible to have both an unmoderated group (fast turnaround, much spam, some heated discussion) and a corresponding moderated group (slow turnaround, no spam, far less heat, presence of more experts), e.g. as [comp.lang.c++] and [oomp.lang.c++.moderated]. :-) Cheers & hth., - Alf From deets at nospam.web.de Sat Nov 14 08:59:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 14:59:07 +0100 Subject: More Python versions on an XP machine In-Reply-To: References: Message-ID: <7m7rdbF3g7k6dU1@mid.uni-berlin.de> Gabor Urban schrieb: > Hi guys, > > this a very MS specific question. I do use a rather old Python > version, because we have a couple of applications written for that. > Porting them to a newer Python is not allowed by the bosses. Now we > will start a new project with latest stable Python. Can I have them > both on my computer, and how should I do that. As numerous posts here have indicated over the past years, and even this week - and to say it with a somewhate prematurely awarded Nobel Prize Winner: YES, YOU CAN! Diez From metawilm at gmail.com Sat Nov 14 09:13:47 2009 From: metawilm at gmail.com (Willem Broekema) Date: Sat, 14 Nov 2009 06:13:47 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 14, 8:55 am, Vincent Manis wrote: > On 2009-11-13, at 23:20, Robert Brown wrote, quoting me: > > Please look atCLPython. [...] > Ah, that does explain it. I bet you didn't even look at it. FWIW, I'm the author of CLPython. > CLOS is most definitely the wrong vehicle for implementing > Python method dispatch. CLOS is focused around generic functions that themselves > do method dispatch, and do so in a way that is different from Python's. If I were > building a Python implementation in CL, I would definitely NOT use CLOS, but > do my own dispatch using funcall (the CL equivalent of the now-vanished Python > function apply). CLOS is way more than method dispatch, it's an infrastructure for classes, metaclasses, slots, method combinations. And within method dispatch there are lots of opportunities to customize the behaviour. Ignoring all that functinality when implementing an object-oriented language, and using "dispatch using funcall" whatever that means, just sounds ridiculous. (And funcall != apply.) > > Method lookup is just the tip if the iceburg. How about comparison? Here are > > some comments fromCLPython'simplementation of compare. There's a lot going > > on. It's complex and SLOW. Right, although by special-casing the most common argument types you can save most of that lookup. > Re comparison. Python 3 has cleaned comparison up a fair bit. In particular, you > can no longer compare objects of different types using default comparisons. > However, it could well be that there are nasty little crannies of inefficiency > there, they could be the subject of PEPs after the moratorium is over. It might have gotten a bit better, but the central message still stands: Python has made design choices that make efficient compilation hard. > OK, let me try this again. My assertion is that with some combination of JITting, > reorganization of the Python runtime, and optional static declarations, Python > can be made acceptably fast, That does not contradict that, had other language design choices been made, it could be much easier to get better performance. Python may in general be about as dynamic as Common Lisp from a _user_ perspective, but from an implementator's point of view Python is harder to make it run efficiently. Here are some examples of design choices in Common Lisp that help it perform very well; while in Python there is more freedom at the cost of performance: - Lisp hashtables, arrays, numbers, and strings are not subclassable. The specialized operations on them, like function aref for array index referencing, don't invoke arbitrary user-level code, and also not lookup of magic methods. - Certain Lisp sequence objects, like lists and arrays, can easily be allocated on the stack; - Lisp allows type declarations, like for variables, array types, function arguments and return values. - Even if Python had type declarations, it is possible to define a subclass that redefines semantics. E.g. it's possible to subclass 'int' and redefine what '+' means, making a declaration that "x is of type int" not as valuable as in Lisp. - A recursive function defined at module level, can not assume that its name refers to itself. - Every function can be called using keyword arguments or positional arguments. E.g. with the definition "def f(x,y): ..", some possible calls are: f(1), f(1,2), f(x=1, y=2), f(1,y=2) so every function must be prepared to do keyword argument processing. (This can be considered a lack of separation between internal details and external interface.) - Every function call could potentially be a call to locals() (e.g. f=locals; f()), which means every function that contains a function call must store the value of all locals, even of "dead" variables. - Built-in functions can be shadowed. - The potential fields of a Python object are often not defined, as arbitrary attributes can be set. Accessors for fields generally generally have to retrieve the value from a dict. - When limiting the potential fields of a class instance using __slots__, subclasses may override __slots__ thus this is hardly limiting. - Python attribute lookup and comparison (as shown in a previous mail) are examples of hairy behaviour that often mean the lookup of several (!) __magic__ methods and could invoke arbitrary user code. (Lisp in particular offers "structures" whose definition is fixed, that inline all accessors, for maximum efficiency.) This is just to show how language design leads to efficieny characteristics. That there is a need for projects like NumPy and Cython, follows in my eyes from Python being too dynamic for its own good, with no way to tame it. In Common Lisp there would be less need to go to C for speed, because of user-supplied type declarations and compiler-based type inferencing. It has been said that CLPython is a very good counterargument for "just write a Python to Lisp compiler to make things fast", and even I as its developer agree. Lisp offers lots of readily available optimization opportunities, but Python simply doesn't. I remember reading some years ago about a Smalltalk compiler guru who said he would come up with a ridiculously fast Python implementation based on all the message sending optimizations he knew. It does not surprise me that we've never heard from him yet. - Willem From lusvehla at gmail.com Sat Nov 14 09:15:17 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 06:15:17 -0800 (PST) Subject: COM Server wirh MS Excel References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: <82f867e7-4808-46f0-861e-e3814cc20db7@n35g2000yqm.googlegroups.com> On 14 lis, 14:34, Chris Withers wrote: > Cannonbiker wrote: > > Hi, > > I would lake use win32com with Excel. I tried to use python COM > > example from 'The Quick Python Book' on page 250 but without success. > > I suggest you have a good read ofhttp://www.python-excel.org. > > You may well find you don't need to use COM at all...# > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk Thanks but this isn't solution for me. I need call Python functions from Excel and receive result back in Excel... From news at schwertberger.de Sat Nov 14 09:35:35 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 14 Nov 2009 15:35:35 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> Message-ID: <7m7thpF3g6c3gU1@mid.individual.net> sturlamolden schrieb: > I personally feel the wxPython support in the 3.1 beta of > wxFormBuilder makes the choise rather simple. It generates a Python > file with classes for all WYSIWYG GUI forms/windows/dialogs. Then in > our Python code, we just import and inherit the form, and implement > the event handlers. It can't be done easier. GUI programming with > Python is now comparable to programming with VB, Delphi or C#. I am > using it for all my projects now. It just feels right. Yes, wxFormBuilder looks very promising. But I don't think that 3.1 in it's current state it can be recommended for general use already. I just tried the latest version (from August) and it does not even generate correct Python code: self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 ) m_toolBar1.AddControl( m_button1 ) (i.e. "self." is missing) Regards, Dietmar From doomster at knuut.de Sat Nov 14 10:13:08 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sat, 14 Nov 2009 16:13:08 +0100 Subject: The ol' [[]] * 500 bug... References: <7m78oaF3fgtcfU1@mid.uni-berlin.de> Message-ID: <7m7vo6F3glkboU1@mid.uni-berlin.de> Diez B. Roggisch wrote: > kj schrieb: >> lol = [[] for _ in xrange(500)] > > If you call that hideous, I suggest you perform the same exercise in > Java or C++ - and then come back to python and relax.... I might be missing something that's not explicitly mentioned here, but I'd say that all non-associative containers in C++ have a resize() method, some even taking an initial size in their constructor. That said, [[]]*500 is IMHO more readable. Uli From davea at ieee.org Sat Nov 14 10:36:21 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 14 Nov 2009 10:36:21 -0500 Subject: run all scripts in sub-directory as subroutines? In-Reply-To: <%jjLm.16238$We2.1157@newsfe09.iad> References: <%jjLm.16238$We2.1157@newsfe09.iad> Message-ID: <4AFECE75.9000600@ieee.org> Tobiah wrote: >> This works fine, but in the sub-modules the sys.path appropriately >> returns the same as from the parent, I want them to know their own file >> names. How?? I can pass it to them, but wondered if there is a more >> self-sufficient way for a module to know from where it was invoked. >> > > I like the idea of passing the information to the module. > Probably by setting a global variable into it. > > > > As ryles pointed out in this thread, over a month ago, that's already there. The system loader creates a global variable __file__ with the full path to the module. So any module can see exactly where it was loaded from. From chris at simplistix.co.uk Sat Nov 14 10:44:55 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 15:44:55 +0000 Subject: feedback on function introspection in argparse In-Reply-To: References: Message-ID: <4AFED077.5040902@simplistix.co.uk> Yuv wrote: > On Nov 8, 1:33 am, Carl Banks wrote: >> Is the docstring expected to be formatted according to some >> convention? > > We tried to comply to PEP 257 and we're open to suggestions on this. I'd suggest at the very least supporting Sphinx docstrings that have the parameters in them... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From roy at panix.com Sat Nov 14 10:48:39 2009 From: roy at panix.com (Roy Smith) Date: Sat, 14 Nov 2009 07:48:39 -0800 (PST) Subject: Anything better than shutil? Message-ID: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> I'm converting some old bash scripts to python. There's lots of places where I'm doing things like "rm $source_dir/*.conf". The best way I can see to convert this into python is: configs = glob.glob(os.path.join(source_dir, '*.conf')) for conf_file in configs: shutil.copy(conf_file, conf_dir) which is pretty clunky. The old bash script ran under cygwin on windows, and the cygwin layer handled the slash-backslash business for me. Is there a better way to do what I'm doing? I don't want to use any of the popen() variants to call a real shell. The problem I'm trying to solve is that fork/exec is painfully slow under cygwin, so that would defeat the whole purpose. The idea interface I see would be one like: shutil.copy([source_dir, '*.conf'], conf_dir) the idea is that if the first argument is a list (or maybe any iterable other than a string?), it would automatically get run through os.path.join(). And, the result would always get passed through glob (), just like a normal shell would. Does anything like this exist? I'm currently using python 2.5.1. It's possible, but moderately painful, to move to a newer version. From chris at simplistix.co.uk Sat Nov 14 10:54:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 15:54:51 +0000 Subject: Anything better than shutil? In-Reply-To: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> References: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> Message-ID: <4AFED2CB.2050106@simplistix.co.uk> Roy Smith wrote: > The idea interface I see would be one like: > > shutil.copy([source_dir, '*.conf'], conf_dir) > > the idea is that if the first argument is a list (or maybe any > iterable other than a string?), it would automatically get run through > os.path.join(). And, the result would always get passed through glob > (), just like a normal shell would. Does anything like this exist? Why don't you wrap up your earlier code: > configs = glob.glob(os.path.join(source_dir, '*.conf')) > for conf_file in configs: > shutil.copy(conf_file, conf_dir) ...in a module with the exact interface you're after? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From luca at keul.it Sat Nov 14 11:02:29 2009 From: luca at keul.it (Luca Fabbri) Date: Sat, 14 Nov 2009 17:02:29 +0100 Subject: How to know if a file is a text file Message-ID: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Hi all. I'm looking for a way to be able to load a generic file from the system and understand if he is plain text. The mimetype module has some nice methods, but for example it's not working for file without extension. Any suggestion? -- -- luca From joost at h-labahn.de Sat Nov 14 11:04:32 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 08:04:32 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects Message-ID: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> Hello, this page http://docs.python.org/3.1/c-api/typeobj.html has a bad error: " PyTypeObject* PyObject.ob_type This is the type?s type, in other words its metatype. It is initialized by the argument to the PyObject_HEAD_INIT macro, and its value should normally be &PyType_Type. However, for dynamically loadable extension modules that must be usable on Windows (at least), the compiler complains that this is not a valid initializer. Therefore, the convention is to pass NULL to the PyObject_HEAD_INIT macro and to initialize this field explicitly at the start of the module?s initialization function, before doing anything else. This is typically done like this: Foo_Type.ob_type = &PyType_Type; " This cannot work, because Foo_Type is no PyObject but a PyVarObject (independent of the use of PyVarObject_HEAD_INIT or PyObject_HEAD_INIT). The code line would work so: ((PyObject *)&Foo_Type)->ob_type = &PyType_Type But in the Tutorial for Extensions and Embedding we are advised as follows: " This is so important that we?re going to pick the top of it apart still further: PyVarObject_HEAD_INIT(NULL, 0) This line is a bit of a wart; what we?d like to write is: PyVarObject_HEAD_INIT(&PyType_Type, 0) as the type of a type object is ?type?, but this isn?t strictly conforming C and some compilers complain. Fortunately, this member will be filled in for us by PyType_Ready(). " What now ? Another problem, which might be a documentation bug, is the last sentence here: " destructor PyTypeObject.tp_dealloc A pointer to the instance destructor function. This function must be defined unless the type guarantees that its instances will never be deallocated (as is the case for the singletons None and Ellipsis). The destructor function is called by the Py_DECREF() and Py_XDECREF() macros when the new reference count is zero. At this point, the instance is still in existence, but there are no references to it. The destructor function should free all references which the instance owns, free all memory buffers owned by the instance (using the freeing function corresponding to the allocation function used to allocate the buffer), and finally (as its last action) call the type?s tp_free function. If the type is not subtypable (doesn?t have the Py_TPFLAGS_BASETYPE flag bit set), it is permissible to call the object deallocator directly instead of via tp_free. " What ? Where do we "call" these methods ? Primarily we write them down to get members of the Foo_Type struct and our question is where. Shall this sentence mean, that we write the function, we'd normally use for tp_dealloc und which behaves like it, to the place of tp_free ? I've run into terrible trouble with extension classes, which have neither members nor init. They work (and i am quite happy about that) but finding out, that tp_dictoffset had to be set (for what i wanted) took more than a day of searching - including ?ecture of typeobject.c and object.c - and i cannot derive from them. class(my_extension_class): ... doesn't crash, but results in objects, which have the type my_extension_class, what means, that they do not call their __init__. In certain circumstances a correct tp_free seems to be a premise for inheritance, thus i'd very like to understand the quoted passage. Joost From davea at ieee.org Sat Nov 14 11:05:44 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 14 Nov 2009 11:05:44 -0500 Subject: __import__ returns module without it's attributes? In-Reply-To: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> References: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> Message-ID: <4AFED558.60703@ieee.org> Zac Burns wrote: > I've overloaded __import__ to modify modules after they are > imported... but running dir(module) on the result only returns > __builtins__, __doc__, __file__, > __name__, __package__, and __path__. > > Why is this? More importantly, where can I hook in that would allow me > to see the contents of the module? > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > > I'm probably not the one to give you the actual answer (at least not in the next couple of days), but I could help you ask a better question. Provide a simple example of your code, and what it does. Describe the python version and OS platform you're running it on. And detail the contents of any extra files or environment values that are needed to reproduce the problem. (You may find http://www.catb.org/~esr/faqs/smart-questions.html useful) BTW, I don't know of any method __import__(), only a builtin function, so I don't see how you can overload it. But your example should make it clear what you really meant. HTH DaveA From paul.nospam at rudin.co.uk Sat Nov 14 11:29:55 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 16:29:55 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> Message-ID: <87iqddhxx8.fsf@rudin.co.uk> Ben Finney writes: > Paul Rudin writes: > >> I'm experimenting with the daemon module >> and upstart >> . > > First: Thank you for using ?python-daemon?; it's getting more widespread > use all the time, which is really helping to find all the quirks of API > and implementation. (And good for my ego at the same time.) > > Thanks for writing it. > There's something I don't understand, which may be more of an upstart >> issue than a python issue, but I thought I'd start by posting here. > > I'm unfamiliar with ?upstart?, I hope others with more experience can > offer more insight. > On Karmic it seems to be the standard way for starting and stopping system processes. >> Here's a test script: > [?] > > The program looks fine to me. What happens if you run the program, > without getting ?upstart? involved? > As for as I can tell everything is ok invoking the script from the command line. >> and here's a testdaemon.conf upstart configuration: >> >> description "test daemon" >> expect daemon >> chdir /tmp >> exec /tmp/testdaemon.py >> >> If I do "sudo start testdaemon" I see the "testdaemon.py" process >> starting, and the file '/tmp/test.txt' is being written to every 5 >> seconds, so everything has kicked off. > > Good to know. > >> The thing I don't understand is why start does not return. I guess it >> doesn't think that the process and properly started and daemonized >> itself? Quite possibly it's just that I don't understand this stuff >> well... > > As I say, I'm completely unfamiliar with the details of ?upstart?. Can > you point me to whatever you used to understand it? The man pages on Karmic - "man start" etc. and the documentation on the upstart website: - check the getting started page and the wiki. Also some blog pages by its author: From joost at h-labahn.de Sat Nov 14 11:33:09 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 08:33:09 -0800 (PST) Subject: More Python versions on an XP machine References: Message-ID: <09651910-e61b-4ae1-8ac8-84bd83b8f06b@v30g2000yqm.googlegroups.com> Hi, there are several ways to do that besides starting python scripts with a double-click on a desktop icon (that can only work with the one and only python version of the registry). One is to start the new python version directly from a "DosBox". You could copy python.exe or pythonw.exe from the new version directly into the directory, where your python script is - both are only some kB large - and then execute "python your_script" in the cmd.exe. After some "cd"s to the directory of your script. Besides - it is no bad idea to have some copies of the cmd.exe at several places of your file system - the correct run of cmd.exe is not depending on its place in C:\Windows\system32. It also runs from external disks. This is, how i do that, not optimal probably, but easy to understand. Joost From tartley at tartley.com Sat Nov 14 11:51:36 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 14 Nov 2009 08:51:36 -0800 (PST) Subject: bootstrapping on machines without Python References: Message-ID: On Nov 13, 1:57?pm, Tim Golden wrote: > Jonathan Hartley wrote: > > While examining py2exe et al of late, my thoughts keep returning to > > the idea of writing, in C or similar, a compiled stand-alone > > executable 'bootstrapper', which: > > 1) downloads and install a Python interpreter if none exists > > 2) runs the application's Python source code using this interpreter. > > Thinking aloud about what you're describing here... Assuming Windows, > as your starting point is py2exe and I imagine that most Unix-like > boxes already have Python on them. > > Step 1: The user downloads a tiny myapp.exe which is basically a zip of the > myapp package / files plus an .exe header which will... > > Step 2a: ... download a minimised? (ie custom-built) Python interpreter > and stdlib bundle which is just enough to run the app. Or... > > Step 2b: ... download and install the official python.org Windows > installer for version x.y identified as the highest known to run > this app if... > > Step 2bi) ... that version of the interpreter isn't already installed > and registered on that machine (at least: for that user). > > My step 2a seems to be little better than a bundled py2exe, so I can > only assume you mean Step 2b, especially given your comment below > about ending up with an installation of Python where one wasn't > before. This, though, seems fraught with accusations of backdoor > installations etc. > > Have I misunderstood you? For the Record, I'm entirely in favour of moves > to make Python use on Windows more seamless, attractive, consistent, > etc. I was going to comment positively on your recent PyChooser widget > and to plug a similar but unpublished one of my own. But I'm not sure > if this particular proposal has enough wings to make it fly. > > TJG Hi Tim. Thanks for that. Yes, you have understood pretty much perfectly. I was envisaging something like 2b. I'm very much enamored of creating cross-platform apps, but I'm focused on deployment on Windows first, because this is where most users are, and also where the problem seems to need the most work. Your input is very much appreciated. It may be that you are right that I haven't thought this through clearly enough. Incidentally, I'd love to see your approach of dealing with the problem that pychoose addresses - Since creating it, I'm gripped with paranoia that it is failing to take account of lots of things which will trip me up later (or worse- trip other people up too, if anyone uses it) From michele.simionato at gmail.com Sat Nov 14 11:54:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 08:54:39 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <149ddcc2-ffee-4363-8123-fbb516574a06@m16g2000yqc.googlegroups.com> On Nov 14, 12:26?pm, kj wrote: > > The two goals of replacing C with "something more modern" and at > the same time have a "nearly zero learning curve" seem to me mutually > negating. ?The closer to zero the learning curve is, the closer to > C/C++, and therefore the less modern, that language will be. Not at all. A language with a small learning curve should be as far as possible for C++! Go is in many ways simpler than C (no header files, a simpler compilation process, no pointer arithmetic, no ternary operator, no while loop, in a sense no threads, etc) and it has an object orientation simpler than most languages; actually it looks even simpler than Python in many respects (no properties, no decorators, no metaclasses, a much simpler version of inheritance ...). It has static typing that makes things a bit more complicated, but also safer in same respect. It has also reflection and the ability to do a lot of things at runtime. If people starts writing libraries it has the potential to cover both C and Python niches at the same time! From paul.nospam at rudin.co.uk Sat Nov 14 11:56:47 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 16:56:47 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> <87iqddhxx8.fsf@rudin.co.uk> Message-ID: <87bpj5hwog.fsf@rudin.co.uk> Paul Rudin writes: > Ben Finney writes: > >> Paul Rudin writes: >>> description "test daemon" >>> expect daemon >>> chdir /tmp >>> exec /tmp/testdaemon.py Further experimentation reveals that by omitting the "expect daemon" stanza everything works fine. But I'm still a confused - the manpage says: expect daemon Specifies that the job's main process is a daemon, and will fork twice after being run. init(8) will follow this daemonisation, and will wait for this to occur before running the job's post- start script or considering the job to be running. Without this stanza init(8) is unable to supervise daemon pro? cesses and will believe them to have stopped as soon as they daemonise on startup. So I would have expected it to be necessary in this case. Maybe this is more an upstart issue than a python-daemon one - not sure. From sturlamolden at yahoo.no Sat Nov 14 11:58:02 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 08:58:02 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: On 14 Nov, 15:35, Dietmar Schwertberger wrote: > ? ?self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) > ? ?self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", > wx.DefaultPosition, wx.DefaultSize, 0 ) > ? ?m_toolBar1.AddControl( m_button1 ) > > (i.e. "self." is missing) I had problem like that with the first beta, but not the one from August. From tartley at tartley.com Sat Nov 14 12:06:56 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 14 Nov 2009 09:06:56 -0800 (PST) Subject: bootstrapping on machines without Python References: <20091113232539.0afbc5fe@Knock> Message-ID: <7d205b8d-01b5-4f95-ab2c-e21122fdb975@e23g2000yqd.googlegroups.com> On Nov 13, 10:25?pm, mma... at gmx.net wrote: > On Fri, 13 Nov 2009 02:40:28 -0800 (PST) > > Jonathan Hartley wrote: > > Even my very limited understanding of the issues is enough to see that > > the idea is far from trivial. Thanks heaps for the input from everyone. Martin Lemburg's 'chained' approach does sound like the smart way to do it, and Thomas does demonstrate pretty much the simplest possible example of what I'm thinking of. Martin Manns' portable Python sounds useful too, and is not disimilar to a suggestion made by Michael Foord off list. However, the problems that Tim, Martin, Marc and Martin point out do seem very real. I think users could be placated about 'backdoor installation' if we tell them what's going on, with an OK button. But I confess I wasn't aware that a full Python install is quite so large compared to the bundle produced by py2exe et al. Perhaps this idea is overly idealistic then - I was maybe transfixed by the 'needless consistency' of sharing a single interpreter between many applications. Thanks for helping me straighten out my thoughts on the subject. Best! Jonathan From philip at semanchuk.com Sat Nov 14 12:51:30 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 14 Nov 2009 12:51:30 -0500 Subject: How to know if a file is a text file In-Reply-To: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: On Nov 14, 2009, at 11:02 AM, Luca Fabbri wrote: > Hi all. > > I'm looking for a way to be able to load a generic file from the > system and understand if he is plain text. > The mimetype module has some nice methods, but for example it's not > working for file without extension. Hi Luca, You have to define what you mean by "text" file. It might seem obvious, but it's not. Do you mean just ASCII text? Or will you accept Unicode too? Unicode text can be more difficult to detect because you have to guess the file's encoding (unless it has a BOM; most don't). And do you need to verify that every single byte in the file is "text"? What if the file is 1GB, do you still want to examine every single byte? If you give us your own (specific!) definition of what "text" means, or perhaps a description of the problem you're trying to solve, then maybe we can help you better. Cheers Philip From news at schwertberger.de Sat Nov 14 13:02:14 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 14 Nov 2009 19:02:14 +0100 Subject: Choosing GUI Module for Python In-Reply-To: References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: <7m89l8F3g1lnpU1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 15:35, Dietmar Schwertberger wrote: > >> self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) >> self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", >> wx.DefaultPosition, wx.DefaultSize, 0 ) >> m_toolBar1.AddControl( m_button1 ) >> >> (i.e. "self." is missing) > > I had problem like that with the first beta, but not the one from > August. Which one? There are two: 08/23/2009 Version 3.01.63 (Beta) 08/19/2009 Version 3.01.62 (Beta) I tried 3.01.63. I can see in the Python window already that the code is not correct. Regards, Dietmar From rt8396 at gmail.com Sat Nov 14 13:08:59 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 10:08:59 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: <70529349-696e-4f67-8b65-068dc84b71f4@e20g2000vbb.googlegroups.com> On Nov 14, 7:28?am, gil_johnson wrote: > How about using a "rank this post" feature? Anybody could rank a post > as spam, and a sufficiently large number of negatives would quickly > draw the attention of someone with the power to kill the message. I > suppose even this is subject to abuse, allowing harassment of a > legitimate poster., but my guess is that the votes against counterfeit > Nike shoes, etc., would outnumber the most energetic "vote troll." > Gil Actually there is a "rank this post" (gotta be careful with that verbage!) AND a "report this post as spam". Of course it only exists in GG's and not Usenet. I *do* know that the star system is used quite frequently, but i doubt anyone bothers to use the "report as spam" link since it seems have no effect whatsoever. From http Sat Nov 14 13:10:43 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:10:43 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7xr5s1t1ss.fsf@ruckus.brouhaha.com> sturlamolden writes: > Python on a better VM (LuaJIT, Parrot, LLVM, several > JavaScript) will easily outperform CPython by orders of magnitide. Maybe Python semantics make it more difficult to optimize than those other languages. For example, in a = foo.bar(1) b = muggle() c = foo.bar(2) it is not ok to cache the value of foo.bar after the first assignment. Maybe the second one goes and modifies it through foo.__dict__ . See "Children of a Lesser Python" (linked in another post, or websearch) for discussion. From deets at nospam.web.de Sat Nov 14 13:15:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 19:15:41 +0100 Subject: Psyco on 64-bit machines In-Reply-To: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <7m8aedF3hrgipU1@mid.uni-berlin.de> Russ P. schrieb: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. Isn't the SUN Ultra using an ULTRA-Sparc core? If so, the point is moot. Diez From http Sat Nov 14 13:16:16 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:16:16 -0800 Subject: The ol' [[]] * 500 bug... References: <7m78oaF3fgtcfU1@mid.uni-berlin.de> <7m7vo6F3glkboU1@mid.uni-berlin.de> Message-ID: <7xmy2pt1jj.fsf@ruckus.brouhaha.com> Ulrich Eckhardt writes: > That said, [[]]*500 is IMHO more readable. But the issue in the thread is that it does the wrong thing. From nagle at animats.com Sat Nov 14 13:18:24 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Nov 2009 10:18:24 -0800 Subject: Python & Go In-Reply-To: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> Message-ID: <4afef1f5$0$1586$742ec2ed@news.sonic.net> sturlamolden wrote: > On 12 Nov, 01:53, kj wrote: >> I'm just learning about Google's latest: the GO (Go?) language. It's interesting. The semantics are closer to Java than any other mainstream language. While Java usually is run with a "virtual machine", Go is more like Java hard-compiled (which you can do with GCC.) It's far less dynamic than Python, which is good for performance. (That's not an inherent problem with Python. It's a problem with the CPython implementation. See Shed Skin.) The declaration syntax is borrowed from the Pascal/Modula/Ada family of languages, and it's an improvement over the C/C++ approach. I suspect that Go is LALR(1), which means it can be parsed with a simple context-independent parser. C and C++ are very difficult to parse, and modules can't be parsed independently. (Because of the C/C++ type syntax, you have to look up type names to find out how to parse declarations. So the include files have to be present to parse declarations. This is why there aren't many tools that manipulate C and C++ source code.) Having concurrency in the language is a win. Syntax for queues is a minor win. But the language doesn't directly address the issue of "who locks what". There are shared variables, and mutexes, but the language doesn't let you talk about which variables are shared. When the language doesn't know that, you either have to restrict optimization (as in Python) or have painful mechanisms like "mutable" as in C++. Leaving out exceptions was a mistake. Exceptions are well understood now, and they're far better than the usual "ignore errors" approach one sees in lamer C programs. The interface mechanism is simple enough. In a static language, you can convert "duck typing" to inheritance at link time, when you have the chance to see what can match what. So the implementation doesn't actually have to search for a match at run time. John Nagle From http Sat Nov 14 13:18:46 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:18:46 -0800 Subject: A "terminators' club" for clp References: Message-ID: <7xiqddt1fd.fsf@ruckus.brouhaha.com> "Alf P. Steinbach" writes: > The problem with moderation isn't getting rid of spam and trolls etc., > but turnaround time. There is automatic moderation software that auto-approves any post from an address that has had one or two posts manually approved. While that's susceptible to address forgery, the typical spammer doesn't do that. From http Sat Nov 14 13:23:57 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:23:57 -0800 Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> Message-ID: <7xd43lt16q.fsf@ruckus.brouhaha.com> sturlamolden writes: > And looking at Go, I cannot understand why Google prefer this over > e.g. Lua. I thought Lua had no type system and no concurrency. From http Sat Nov 14 13:34:44 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:34:44 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <7x8we9t0or.fsf@ruckus.brouhaha.com> kj writes: > One more thing: I found Rob Pike's mutterings on generics (towards > the end of his rollout video) rather offputting, because he gave > the impression that some important aspects of the language were > not even considered before major decisions for it were set in stone. > It looks like, if they ever get around to supporting generics, it > will be a late-in-the-day hack. Mark Chu-Carroll has a new post about Go: http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php Someone named Mightybyte also has a post about Go, and its comment thread is similarly pretty good: http://softwaresimply.blogspot.com/2009/11/standardizing-go.html One of the commenters wrote something that I felt was similar to my own impression of the language: From a PLT perspective Go isn't that interesting. The concurrency and "goroutines" look promising for possibly being able to do what Erlang does. The type system is pretty weak. From a practical perspective people are singing praise for how fast it compiles, but not much mention so far of how fast the resulting code is. Compare tinycc vs gcc for speed of compilation vs resulting code performace to see why I'm skeptical. From invalid at invalid.invalid Sat Nov 14 13:40:19 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 14 Nov 2009 18:40:19 +0000 (UTC) Subject: python simply not scaleable enough for google? References: <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-14, David Robinow wrote: > On Fri, Nov 13, 2009 at 3:32 PM, Paul Rubin > wrote: >> ... ?This is Usenet so >> please stick with Usenet practices. ?If you want a web forum there are >> plenty of them out there. > Actually this is python-list at python.org Actually this is comp.lang.python > I don't use usenet and I have no intention to stick with Usenet practices. From pedro.al at fenhi.uh.cu Sat Nov 14 14:26:11 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 14:26:11 -0500 Subject: Run a external program. Message-ID: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Hi all!! I'm writing a script where i call a external program which receive some arguments. One of this arguments is stored in a variable, that is passed as argument as well: import os ... f = open(file1, 'r') s = 'command $f -i file2 -w 1.4 -o file3.out' os.system(s) ... When i run the script i get the next message... '-i: No such file or directory' ... with a obvious error in the exit of the program. If i remove the option -i i get the same error with every option, even with those who don't get any file as argument. (file2 exist). BUT, when i run the external program in a python shell, it works... What's wrong? Please help me... Thanks -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From paul.nospam at rudin.co.uk Sat Nov 14 14:41:10 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 19:41:10 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> <87iqddhxx8.fsf@rudin.co.uk> <87bpj5hwog.fsf@rudin.co.uk> Message-ID: <877htsj3mx.fsf@rudin.co.uk> Paul Rudin writes: > > So I would have expected it to be necessary in this case. Maybe this is > more an upstart issue than a python-daemon one - not sure. Aha - so I discover that if detach_process is not explicitly passed to the DaemonContext initialiser it tries to guess whether it needs to do the double fork thing or not, passing it through explicitly makes every work as I expected. So it's probably an rtfm error on my part. Although I suppose that there may be an argument the the DaemonContext guessing should try and detect this situation.... not sure. From sturlamolden at yahoo.no Sat Nov 14 14:52:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 11:52:06 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> Message-ID: <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> On 14 Nov, 19:02, Dietmar Schwertberger wrote: > 08/23/2009 Version 3.01.63 (Beta) > 08/19/2009 Version 3.01.62 (Beta) > > I tried 3.01.63. > I can see in the Python window already that the code is not correct. 3.01.63 Did you remember to install the wxAdditions? Could you send me an .fbp file demonstrating the error? From python at mrabarnett.plus.com Sat Nov 14 14:53:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 14 Nov 2009 19:53:50 +0000 Subject: Run a external program. In-Reply-To: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Message-ID: <4AFF0ACE.6060803@mrabarnett.plus.com> Yasser Almeida Hern?ndez wrote: > Hi all!! > > I'm writing a script where i call a external program which receive some > arguments. > One of this arguments is stored in a variable, that is passed as > argument as well: > > import os > ... > f = open(file1, 'r') > s = 'command $f -i file2 -w 1.4 -o file3.out' > os.system(s) > ... > > When i run the script i get the next message... > '-i: No such file or directory' > ... with a obvious error in the exit of the program. If i remove the > option -i i get the same error with every option, even with those who > don't get any file as argument. (file2 exist). > BUT, when i run the external program in a python shell, it works... > > What's wrong? > The name 'f' in the Python script exists only in Python and is unrelated to the '$f' that the shell sees. From metolone+gmane at gmail.com Sat Nov 14 15:03:23 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 14 Nov 2009 12:03:23 -0800 Subject: Run a external program. References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Message-ID: "Yasser Almeida Hern?ndez" wrote in message news:20091114142611.sj45qput2c84s0w0 at correo.fenhi.uh.cu... > Hi all!! > > I'm writing a script where i call a external program which receive some > arguments. > One of this arguments is stored in a variable, that is passed as argument > as well: > > import os > ... > f = open(file1, 'r') > s = 'command $f -i file2 -w 1.4 -o file3.out' > os.system(s) > ... > > When i run the script i get the next message... > '-i: No such file or directory' > ... with a obvious error in the exit of the program. If i remove the > option -i i get the same error with every option, even with those who > don't get any file as argument. (file2 exist). > BUT, when i run the external program in a python shell, it works... > > What's wrong? Please post a small, complete example of your code and the error message. Cut-and-paste them exactly. Also provide the shell command you are running that works. -Mark From pedro.al at fenhi.uh.cu Sat Nov 14 15:07:26 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 15:07:26 -0500 Subject: Run a external program. In-Reply-To: <4AFF0ACE.6060803@mrabarnett.plus.com> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> Message-ID: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> So, how can i pass an argument as a variable in this context...? Quoting MRAB : > Yasser Almeida Hern?ndez wrote: >> Hi all!! >> >> I'm writing a script where i call a external program which receive >> some arguments. >> One of this arguments is stored in a variable, that is passed as >> argument as well: >> >> import os >> ... >> f = open(file1, 'r') >> s = 'command $f -i file2 -w 1.4 -o file3.out' >> os.system(s) >> ... >> >> When i run the script i get the next message... >> '-i: No such file or directory' >> ... with a obvious error in the exit of the program. If i remove >> the option -i i get the same error with every option, even with >> those who don't get any file as argument. (file2 exist). >> BUT, when i run the external program in a python shell, it works... >> >> What's wrong? >> > The name 'f' in the Python script exists only in Python and is unrelated > to the '$f' that the shell sees. > -- > http://mail.python.org/mailman/listinfo/python-list -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From sturlamolden at yahoo.no Sat Nov 14 15:15:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 12:15:53 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: On 14 Nov, 19:18, John Nagle wrote: > Syntax for queues is a minor win. No, that's syntax bloat. The go keyword could be a problem as well. I suspect it could infringe on Cilk++ patents. Perhaps Go cannot be used without a licence from Cilk Arts? From http Sat Nov 14 15:23:40 2009 From: http (Paul Rubin) Date: 14 Nov 2009 12:23:40 -0800 Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: <7xocn4rh2r.fsf@ruckus.brouhaha.com> sturlamolden writes: > The go keyword could be a problem as well. I suspect it could infringe > on Cilk++ patents. Perhaps Go cannot be used without a licence from > Cilk Arts? Also as somebody said, if after a while they decide to make a new version of the language, they'll have to call it Go2, which will necessarily be considered harmful. From clp2 at rebertia.com Sat Nov 14 15:50:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 12:50:14 -0800 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: <50697b2c0911141250p26f70f3co1367c816493d36b5@mail.gmail.com> > Quoting MRAB : >> Yasser Almeida Hern?ndez wrote: >>> >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive ?some >>> arguments. >>> One of this arguments is stored in a variable, that is passed as >>> ?argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove ?the >>> option -i i get the same error with every option, even with ?those who don't >>> get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. 2009/11/14 Yasser Almeida Hern?ndez : > So, how can i pass an argument as a variable in this context...? Use the string variable's value when specifying the arguments to the command. Here's how you'd do it using the newer `subprocess` module: import sys import subprocess args = ['command', file1, '-i', 'file2', '-w', '1.4', '-o', 'file3.out'] #assuming only file1 is variable return_code = subprocess.call(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr) Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sat Nov 14 15:56:30 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 14 Nov 2009 20:56:30 +0000 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: <4AFF197E.6080304@mrabarnett.plus.com> Yasser Almeida Hern?ndez wrote: > So, how can i pass an argument as a variable in this context...? > You can't pass arbitrary values on a command line. In this case, why not just pass the path of the file? s = 'command "%s" -i file2 -w 1.4 -o file3.out' % file1 > > Quoting MRAB : > >> Yasser Almeida Hern?ndez wrote: >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive >>> some arguments. >>> One of this arguments is stored in a variable, that is passed as >>> argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove the >>> option -i i get the same error with every option, even with those >>> who don't get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. > From rtw at freenet.co.uk Sat Nov 14 16:14:50 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sat, 14 Nov 2009 15:14:50 -0600 Subject: Help with database planning References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: Juliano wrote in news:0e64893a-af82-4004-bf3c-f397f2022846 at g22g2000prf.googlegroups.com in comp.lang.python: [snip] > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. What I'm grokking from the data you show is that a "Concept" is a table (or a python class), "slots" are attributes of the concept and facets are the type of "slot", finally the "fillers" are (mostly) the data. But also you seem to have "slots" that represent relationships between "Concepts" and other tables, in this case the "slots" should be tables. For example with the slot type "INSTANCE-OF", what is "OTHER-NIGER-KORDOFANIAN-LANGUAGE" is it another concept or a list of concepts or a concept "OTHER-NIGER-KORDOFANIAN" and a type "LANGUAGE", I suspect you have a table "Language" and also an table "Region" in there too. It may be time to start thinking in terms of what you are modeling and what the entities are (as apposed to trying to convert the data you have), once you have that, work out how to load that data from your current file and check that you can query your model correctly. Maybe something like (using a made up ORM): class Concept: name = TextField() definition = TextField() primary_key = PrimaryKey( name ) class IsASlot: concept = ForeignKey( Concept ) is_a = ForeignKey( Concept ) primary_key = PrimaryKey( concept, is_a ) class LexeSlot: concept = ForeignKey( Concept ) value = TextField() primary_key = PrimaryKey( concept, value ) class Region: region = TextField() primary_key = PrimaryKey( region ) class Language: language = ForeignKey( Concept ) # or is it TextField() ? primary_key = PrimaryKey( language ) class LanguageOfSlot: language = ForeignKey( Language ) region = ForeignKey( Region ) primary_key = PrimaryKey( language, region ) To reiterate, you should use your domain expertise to create the model. > > > line_no concepts slots facets fillers > ----------------------------------------------------------------------- > ------- 00000 ABANDON DEFINITION VALUE "to leave or > desert something or someone" > 00001 ABANDON IS-A VALUE EXIT > 00002 ABANDON LEXE MAP-LEX "leave behind-V1" > 00003 ABANDON LEXE MAP-LEX abandon-V1 The "-V1" in the above looks worryingly like you have structure embedded in the data field, if so you should extract is so its in its own field or table. > (...) > 97420 ZULU DEFINITION VALUE "a language or dialect > spoken in south africa and others" > 97421 ZULU INSTANCE-OF VALUE > OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ZULU LANGUAGE-OF INV LESOTHO > 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA Rob. From pedro.al at fenhi.uh.cu Sat Nov 14 16:23:22 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 16:23:22 -0500 Subject: Run a external program. In-Reply-To: <4AFF197E.6080304@mrabarnett.plus.com> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> <4AFF197E.6080304@mrabarnett.plus.com> Message-ID: <20091114162322.04wbz2hgtccssc8s@correo.fenhi.uh.cu> All ran ok!! Thanks a lot Quoting MRAB : > Yasser Almeida Hern?ndez wrote: >> So, how can i pass an argument as a variable in this context...? >> > You can't pass arbitrary values on a command line. In this case, why not > just pass the path of the file? > > s = 'command "%s" -i file2 -w 1.4 -o file3.out' % file1 > >> >> Quoting MRAB : >> >>> Yasser Almeida Hern?ndez wrote: >>>> Hi all!! >>>> >>>> I'm writing a script where i call a external program which >>>> receive some arguments. >>>> One of this arguments is stored in a variable, that is passed as >>>> argument as well: >>>> >>>> import os >>>> ... >>>> f = open(file1, 'r') >>>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>>> os.system(s) >>>> ... >>>> >>>> When i run the script i get the next message... >>>> '-i: No such file or directory' >>>> ... with a obvious error in the exit of the program. If i remove >>>> the option -i i get the same error with every option, even with >>>> those who don't get any file as argument. (file2 exist). >>>> BUT, when i run the external program in a python shell, it works... >>>> >>>> What's wrong? >>>> >>> The name 'f' in the Python script exists only in Python and is unrelated >>> to the '$f' that the shell sees. >> > > -- > http://mail.python.org/mailman/listinfo/python-list -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From nobody at nowhere.com Sat Nov 14 16:55:25 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 14 Nov 2009 21:55:25 +0000 Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> Message-ID: On Fri, 13 Nov 2009 06:05:48 -0500, Dave Angel wrote: >>> Currently i am using 2.6 on Windows and need to start writing code in >>> 3.0. I cannot leave 2.x yet because 3rd party modules are still not >>> converted. So i want to install 3.0 without disturbing my current >>> Python2.x. What i'm afraid of is that some SYSVARIABLE will get >>> changed to Python3.0 and when i double click a Python script it will >>> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts >>> from the command line... > python3.x myscript.py >>> >>> So how do i do this? Is my fear unfounded? >>> >> >> Windows determines the double-click action based on the file >> extension. You just have to make sure that *.py files are associated >> with 2.x. >> http://support.microsoft.com/kb/307859 >> >> >> > And if someone simply wants to check or change these associations > without all the Explorer nonsense, one can use > assoc.exe and ftype.exe That isn't reliable. The Windows registry has two distinct sets of mappings. HKEY_LOCAL_MACHINE\Software\Classes contains system-wide mappings, while HKEY_CURRENT_USER\Software\Classes contains per-user mappings. The per-user mappings are checked first, with the system-wide mappings acting as a fall-back. AFAICT, assoc and ftype modify the system-wide mappings, so if you have a per-user mapping, they have no effect. Note that HKEY_CLASSES_ROOT is a "virtual" key obtained by merging the above two keys (analogous to a view in an RDBMS). http://msdn.microsoft.com/en-us/library/ms724475(VS.85).aspx From tjreedy at udel.edu Sat Nov 14 17:02:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:02:19 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: sturlamolden wrote: > - For the few cases where a graphics program really need C, we can > always resort to using ctypes, f2py or Cython. Gluing Python with C or > Fortran is very easy using these tools. That is much better than > keeping it all in C++. In case anyone thinks resorting to C or Fortran is cheating, they should know that CPython, the implementation, was designed for this. That is why there is a documented C-API and why the CPython devs are slow to change it. Numerical Python dates back to at least 1.3 and probably earlier. The people who wrote it were some of the first production users of Python. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 17:10:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:10:50 -0500 Subject: Python & Go In-Reply-To: <7x8we9t0or.fsf@ruckus.brouhaha.com> References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Mark Chu-Carroll has a new post about Go: > > http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php In a couple of minutes, I wrote his toy prime filter example in Python, mostly from the text rather than the code, which I can barely stand to read. It ran the first time without error. def plurals(): i = 2 while True: yield i i += 1 def primefilter(src, prime): for i in src: if i % prime: yield i src = plurals() while True: i = next(src) print(i) src = primefilter(src, i) As I commented there "It stopped at 7877 when it hit the default recursion limit of 1000, which could easily be increased to get out-of-memory error instead. I think Google is making a blunder if it moves to another old-fashioned language whose code is bloated with junky boilerplate that doubles the size. It would be much better, for instance, to tweak Python, which it has had great success with, to better run on multiple cores." Terry Jan Reedy From falk at mauve.rahul.net Sat Nov 14 17:34:20 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Sat, 14 Nov 2009 22:34:20 +0000 (UTC) Subject: python simply not scaleable enough for google? References: Message-ID: In article , Terry Reedy wrote: > >I can imagine a day when code compiled from Python is routinely >time-competitive with hand-written C. I can't. Too much about the language is dynamic. The untyped variables alone are a killer. int a,b,c; ... a = b + c; In C, this compiles down to just a few machine instructions. In Python, the values in the variables need to be examined *at run time* to determine how to add them or if they can even be added at all. You'll never in a million years get that down to just two or three machine cycles. Yes, technically, the speed of a language depends on its implementation, but the nature of the language constrains what you can do in an implementation. Python the language is inherently slower than C the language, no matter how much effort you put into the implementation. This is generally true for all languages without strongly typed variables. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From yoav.goldberg at gmail.com Sat Nov 14 17:42:33 2009 From: yoav.goldberg at gmail.com (Yoav Goldberg) Date: Sun, 15 Nov 2009 00:42:33 +0200 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy wrote: > Paul Rubin wrote: > > Mark Chu-Carroll has a new post about Go: >> >> >> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> > > In a couple of minutes, I wrote his toy prime filter example in Python, > mostly from the text rather than the code, which I can barely stand to read. > It ran the first time without error. > > Yes, but the cool thing about the Go version is that it does each generator in a different thread, so in theory it could run twice as fast on a multi-core machine. Y -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 14 17:45:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:45:00 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Willem Broekema wrote: > It might have gotten a bit better, but the central message still > stands: Python has made design choices that make efficient compilation > hard. > >> OK, let me try this again. My assertion is that with some combination of JITting, >> reorganization of the Python runtime, and optional static declarations, Python >> can be made acceptably fast, > > That does not contradict that, had other language design choices been > made, it could be much easier to get better performance. Python may in > general be about as dynamic as Common Lisp from a _user_ perspective, > but from an implementator's point of view Python is harder to make it > run efficiently. I think you are right about the design choices. The reason for those design choices is that Guido intended from the beginning that Python implementations be part of open computational systems, and not islands to themselves like Smalltalk and some Lisps. While the public CPython C-API is *not* part of the Python language, Python was and has been designed with the knowledge that there *would be* such an interface, and that speed-critical code would be written in C or Fortran, or that Python programs would interface with and use such code already written. So: Python the language was designed for human readability, with the knowledge that CPython the implementation (originally and still today just called python.exe) would exist in a world where intensive computation could be pushed onto C or Fortan when necessary. So: to talk about the 'speed of Python', one should talk about the speed of human reading and writing. On this score, Python, I believe, beats most other algorithm languages, as intended. It certainly does for me. To talk about the speed of CPython, one must, to be fair, talk about the speed of CPython + extensions compiled to native code. In the scale of human readability, I believe Google go is a step backwards from Python. Terry Jan Reedy From russ.paielli at gmail.com Sat Nov 14 17:51:45 2009 From: russ.paielli at gmail.com (Russ P.) Date: Sat, 14 Nov 2009 14:51:45 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> <7m8aedF3hrgipU1@mid.uni-berlin.de> Message-ID: <96271b5f-9a52-4033-b56e-f772ce763c52@x6g2000prc.googlegroups.com> On Nov 14, 10:15?am, "Diez B. Roggisch" wrote: > Russ P. schrieb: > > > I have a Python program that runs too slow for some inputs. I would > > like to speed it up without rewriting any code. Psyco seemed like > > exactly what I need, until I saw that it only works on a 32-bit > > architecture. I work in an environment of Sun Ultras that are all 64- > > bit. However, the Psyco docs say this: > > > "Psyco does not support the 64-bit x86 architecture, unless you have a > > Python compiled in 32-bit compatibility mode." > > > Would it make sense to compile Python in the 32-bit compatibility mode > > so I can use Psyco? What would I lose in that mode, if anything? > > Thanks. > > Isn't the SUN Ultra using an ULTRA-Sparc core? If so, the point is moot. > > Diez No, it's Intel based. From tjreedy at udel.edu Sat Nov 14 17:52:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:52:01 -0500 Subject: A "terminators' club" for clp In-Reply-To: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: r wrote: > On Nov 14, 4:59 am, kj wrote: >> But, as I already showed, I'm out of my depth here, >> so I'd better shut up. > > Don't give up so easy! The idea is great, what Paul is saying is that > most people who read this group use newsreaders and that has nothing > to do with google groups. These guy's have kill filters for just this > sort of thing but either way the emails are on their puters so they > have to deal with them on an individual basis. It would be nice > however to clean up the Google group version and rid it of the plagues > of spam infestations. Anyone with a newsreader can, like me, read gmane.comp.python.general, which mirrors python-list, which now filters out much/most of the spam on c.l.p from G.g. To post from g.c.p.g, one must use a real email address and respond once to an email sent to that address. So, the only reason to use c.l.p is if one wants to post anonymously, like the spammers do ;-). Terry Jan Reedy From bbrown at speakeasy.net Sat Nov 14 17:56:39 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 17:56:39 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > The false statement you made is that `... Python *the language* is specified > in a way that makes executing Python programs quickly very very difficult. > I refuted it by citing several systems that implement languages with > semantics similar to those of Python, and do so efficiently. The semantic details matter. Please read Willem's reply to your post. It contains a long list of specific differences between Python (CPython) language semantics and Common Lisp language semantics that cause Python performance to suffer. > OK, let me try this again. My assertion is that with some combination of > JITting, reorganization of the Python runtime, and optional static > declarations, Python can be made acceptably fast, which I define as program > runtimes on the same order of magnitude as those of the same programs in C > (Java and other languages have established a similar goal). I am not pushing > optional declarations, as it's worth seeing what we can get out of > JITting. If you wish to refute this assertion, citing behavior in CPython or > another implementation is not enough. You have to show that the stated > feature *cannot* be made to run in an acceptable time. It's hard to refute your assertion. You're claiming that some future hypothetical Python implementation will have excellent performance via a JIT. On top of that you say that you're willing to change the definition of the Python language, say by adding type declarations, if an implementation with a JIT doesn't pan out. If you change the Python language to address the semantic problems Willem lists in his post and also add optional type declarations, then Python becomes closer to Common Lisp, which we know can be executed efficiently, within the same ballpark as C and Java. bob From http Sat Nov 14 18:03:55 2009 From: http (Paul Rubin) Date: 14 Nov 2009 15:03:55 -0800 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <7x639cyahw.fsf@ruckus.brouhaha.com> Terry Reedy writes: > To post from g.c.p.g, one must use a real email address and respond > once to an email sent to that address. > > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). No I don't think so. "Unwilling to disclose email address or enroll yet another computer account" is not the same as "anonymous". From aonlazio at gmail.com Sat Nov 14 18:25:07 2009 From: aonlazio at gmail.com (AON LAZIO) Date: Sat, 14 Nov 2009 18:25:07 -0500 Subject: Simple object reference Message-ID: Hi, I have some problem with object reference Say I have this code a = b = c = None slist = [a,b,c] for i in range(len(slist)): slist[i] = 5 print slist print a,b,c I got this [5, 5, 5] None None None Question is how can I got all a,b,c variable to have value 5 also? Thanks in advance -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 14 18:40:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 15:40:05 -0800 Subject: Simple object reference In-Reply-To: References: Message-ID: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: > Hi, I have some problem with object reference > Say I have this code > > a = b = c = None > slist = [a,b,c] Values are stored in the list, not references to names. Modifying the list does not change what values the names a, b, and c have. There is no Python-level notion of pointers. > for i in range(len(slist)): > slist[i] = 5 This modifies the contents of the list, it does not affect any other variables/names. > print slist > print a,b,c > > I got this > [5, 5, 5] > None None None > > ??? Question is how can I got all a,b,c variable to have value 5 also? Use tuple unpacking: #at start of code slist = [None]*3 #... #at end of code a, b, c = slist I would also recommend reading http://effbot.org/zone/call-by-object.htm for a good explanation of how Python's variables work. Cheers, Chris -- http://blog.rebertia.com From russ.paielli at gmail.com Sat Nov 14 18:48:49 2009 From: russ.paielli at gmail.com (Russ P.) Date: Sat, 14 Nov 2009 15:48:49 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: On Nov 12, 12:06?pm, "Russ P." wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. I just stumbled across "unladen swallow," a "faster implementation of Python." Is it ready for operational usage? How does it compare to Psyco? I poked around their website a bit, but I don't see answers to those questions. Thanks. From rt8396 at gmail.com Sat Nov 14 18:52:51 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 15:52:51 -0800 (PST) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> On Nov 14, 4:52?pm, Terry Reedy wrote: > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). I don't think that completely correct. Lots of people find GG's to be more suited to their news reading pleasures, i am one of them. I hate to have an email just overflowing with mails all the time. Here in GG's, i just come and go without worrying about deleting messages or kill filters or whatever. Maybe even Guido himself uses GG's? Heck for all we know Guido could have a "pybot" sending all these spams just so Python's TIOBE index will increase! ;-) From james.harris.1 at googlemail.com Sat Nov 14 19:12:39 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 14 Nov 2009 16:12:39 -0800 (PST) Subject: Easy way to play single musical notes in Python Message-ID: Is there a simple way to play musical notes in Python? Something like voice.play("c4") to play C in octave 4 would be ideal. I included a voice parameter as I'd like to play proper notes, not just beeps. This is for recognition of pitch. For example, the program plays a note and the user tries to identify the note played. There are many options at http://wiki.python.org/moin/PythonInMusic but which to choose? They generally seem too complex. I'm looking for something really basic. It would help if it was cross platform and didn't need Tkinter as the snack library does. I presume pure Python is not possible. Any suggestions? James From ben+python at benfinney.id.au Sat Nov 14 19:20:14 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 11:20:14 +1100 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <877htsskox.fsf@benfinney.id.au> Terry Reedy writes: > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). Or if one has an ISP who provides a Usenet feed, like mine does. A pox upon Andrew Cuomo for bashing ISPs in the USA with the stick of ?child pornography? (which he discovered on 88 out of many thousands of forums). Faced with the unreasonable role of policing Usenet, they shut it all off . -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From james.harris.1 at googlemail.com Sat Nov 14 19:21:51 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 14 Nov 2009 16:21:51 -0800 (PST) Subject: Easy way to play single musical notes in Python References: Message-ID: On 15 Nov, 00:12, James Harris wrote: > Is there a simple way to play musical notes in Python? Something like > > ? voice.play("c4") > > to play C in octave 4 would be ideal. I included a voice parameter as > I'd like to play proper notes, not just beeps. This is for recognition > of pitch. For example, the program plays a note and the user tries to > identify the note played. > > There are many options at > > ?http://wiki.python.org/moin/PythonInMusic > > but which to choose? They generally seem too complex. I'm looking for > something really basic. It would help if it was cross platform and > didn't need Tkinter as the snack library does. I presume pure Python > is not possible. > > Any suggestions? Oh, it would be OK if the system allowed numeric pitches such as voice.play(440) to play a note at 440 Hertz. Anything like the above should be good enough. James From ben+python at benfinney.id.au Sat Nov 14 19:36:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 11:36:25 +1100 Subject: Simple object reference References: Message-ID: <873a4gsjxy.fsf@benfinney.id.au> Chris Rebert writes: > On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: > > Hi, I have some problem with object reference > > Say I have this code > > > > a = b = c = None > > slist = [a,b,c] > > Values are stored in the list, not references to names. Modifying the > list does not change what values the names a, b, and c have. There is > no Python-level notion of pointers. There *is*, though, a notion of references, which is what the OP is asking about. The list does not store values, it stores references to values (just as a name references a value). You're right that the names are irrelevant for the items in the list; the name ?a? and the item ?slist[0]? are always independent references. > > for i in range(len(slist)): > > slist[i] = 5 Hence, this has no effect on what the names ?a?, ?b?, ?c? reference; those names continue to reference whatever they were already referencing. It is changing only what the list items ?slist[0]?, ?slist[1]?, ?slist[2]? reference. > I would also recommend reading > http://effbot.org/zone/call-by-object.htm for a good explanation of > how Python's variables work. Yes, the Effbot's explanations are good. It's also worth noting that the Python reference documentation has become much more readable recently, and the language reference has good explanations of the data model and what assignment statements do . -- \ ?As we enjoy great advantages from the inventions of others, we | `\ should be glad to serve others by any invention of ours; and | _o__) this we should do freely and generously.? ?Benjamin Franklin | Ben Finney From vincent at vincentdavis.net Sat Nov 14 20:01:48 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 14 Nov 2009 18:01:48 -0700 Subject: A different take on finding primes Message-ID: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Out of pure curiosity I would like to compare the efficiency of different methods of finding primes (need not be consecutive). Let me be clear, given 2min, how many primes can you find, they need not be in order or consecutive. I have not seen any examples of this. I am assume the solution is different depending on the time give, 2min or 2 hours. I assume a sieve solution would be best for larger times. When the numbers get really large checking to see if they are a prime gets costly. So what do you think? *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 14 20:14:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 20:14:23 -0500 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: Top-posting makes things more confusing. You cannot pass a Python file object to an external process. Pass the name instead. Yasser Almeida Hern?ndez wrote: > So, how can i pass an argument as a variable in this context...? > > > Quoting MRAB : > >> Yasser Almeida Hern?ndez wrote: >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive >>> some arguments. >>> One of this arguments is stored in a variable, that is passed as >>> argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove the >>> option -i i get the same error with every option, even with those >>> who don't get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > From martin at v.loewis.de Sat Nov 14 20:53:29 2009 From: martin at v.loewis.de (=?windows-1252?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 02:53:29 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> Message-ID: <4AFF5F19.3040809@v.loewis.de> > This cannot work, because Foo_Type is no PyObject but a PyVarObject > (independent > of the use of PyVarObject_HEAD_INIT or PyObject_HEAD_INIT). The code > line would > work so: > > ((PyObject *)&Foo_Type)->ob_type = &PyType_Type However, this is not what you should use. Instead, use Py_Type(&Foo_Type) = &PyType_Type > If the type is not subtypable (doesn?t have the > Py_TPFLAGS_BASETYPE flag bit set), it is permissible to call the > object deallocator directly instead of via tp_free. > " > > What ? Where do we "call" these methods ? You should typically call tp_free inside of tp_dealloc. For example, string_dealloc ends with Py_TYPE(op)->tp_free(op); In the specific case (Py_TYPE(op) is not subtypeable), you could alternatively also call PyObject_Del(op); If there are subclasses, they might have used a different allocator (rather than the object allocator), hence you must call the deallocator through tp_free. HTH, Martin From tjreedy at udel.edu Sat Nov 14 21:00:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:00:25 -0500 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: Yoav Goldberg wrote: > > On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy > wrote: > > Paul Rubin wrote: > > Mark Chu-Carroll has a new post about Go: > > http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php > > > In a couple of minutes, I wrote his toy prime filter example in > Python, mostly from the text rather than the code, which I can > barely stand to read. It ran the first time without error. > > > Yes, but the cool thing about the Go version is that it does each > generator in a different thread, so in theory it could run twice as fast > on a multi-core machine. Which is why I added, in my opinion, that "It would be much better, for instance, to tweak Python, which it has had great success with, to better run on multiple cores." For instance, add a new keyword 'go' such that go def f(): yield 1 runs the generator in a different thread, possibly on a different core. To go further, restrict Python's dynamism, require 3.x annotations, and call the result GoPython ;-). Actually, it is already possible to post-process code objects to, in effect, remove the effect of many dynamic assumptions http://code.activestate.com/recipes/277940/ Perhaps, with a different implementation, not even a keyword is needed, just a built-in decorator: @go def f(): yield 1 The go decorator would replace f with a wrapper that runs instances gf of f in threads or whatever, calls next(gf) immediately for parallel opereation, and caches the first yielded value until the calling function calls next(wrapper) to retrieve it. It seems to me that generators are already 'channels' that connect the calling code to the __next__ method, a semi-coroutine based on the body of the generator function. At present, the next method waits until an object is requested. Then it goes into action, yields an object, and rests again. For parallel operations, we need eager, anticipatory evaluation that produces things that *will* be needed rather than lazy evaluation of things that *are* needed and whose absence is holding up everything else. I see no reason why we cannot have that with Python. I not even sure we cannot have it with CPython, but I am not familiar enough with threads, processes, and CPython internals. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:09:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:09:02 -0500 Subject: A "terminators' club" for clp In-Reply-To: <7x639cyahw.fsf@ruckus.brouhaha.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <7x639cyahw.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >> To post from g.c.p.g, one must use a real email address and respond >> once to an email sent to that address. >> >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > No I don't think so. "Unwilling to disclose email address or enroll > yet another computer account" is not the same as "anonymous". There is no 'enrolling' except for hitting reply to an email *when you first post*, but never to just read. You point your news reader to gmane just like to any other newsserver. Once you do, you have access to a couple hundred other Python mailing lists and 1000s of others. I believe c.l.p is one of the few that also appear on gmane, and only because of its gateway to/from python-list. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:13:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:13:19 -0500 Subject: A "terminators' club" for clp In-Reply-To: <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> Message-ID: r wrote: > On Nov 14, 4:52 pm, Terry Reedy wrote: >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > I don't think that completely correct. Lots of people find GG's to be > more suited to their news reading pleasures, I was referring to c.l.p on a nntp newsserver read by a newsreader program. That was the context of the previous discussion. G.G. is different, read through a browser (and only that, as far as I know). i am one of them. I hate > to have an email just overflowing with mails all the time. Here in > GG's, i just come and go without worrying about deleting messages or > kill filters or whatever. That is why I read python-list and other mailing lists (that are not available as a g.g.) via gmane. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:25:08 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:25:08 -0500 Subject: A "terminators' club" for clp In-Reply-To: <877htsskox.fsf@benfinney.id.au> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <877htsskox.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Terry Reedy writes: > >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > Or if one has an ISP who provides a Usenet feed, like mine does. Gmane is a nntp news feed, just not a usenet feed. If you can read usenet, you can read gmane, probably in the time it took you to write this post -- and get access to 1000s of mirrer mailing lists. I switched to gmane's mirror of python-list *before* I had to because it was superior, overall, to my ISP at the time. Hoever, if you like the extra spam, don't spend the minute it takes. But my comment is directed at those complaining about it. Just tell your newsreader to make a new news 'account' for news.gmane.org or snews.gmane.org (port 563) to use ssl - either at the corresponding default ports. tjr From vmanis at telus.net Sat Nov 14 21:42:07 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 18:42:07 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> This whole thread has now proceeded to bore me senseless. I'm going to respond once with a restatement of what I originally said. Then I'm going to drop it, and never respond to the thread again. Much of what's below has been said by others as well; I'm taking no credit for it, just trying to put it together into a coherent framework. 1. The original question is `Is Python scalable enough for Google' (or, I assume any other huge application). That's what I was responding to. 2. `Scalable' can mean performance or productivity/reliability/maintenance quality. A number of posters conflated those. I'll deal with p/r/m by saying I'm not familiar with any study that has taken real enterprise-type programs and compared, e.g., Java, Python, and C++ on the p/r/m criteria. Let's leave that issue by saying that we all enjoy programming in Python, and Python has pretty much the same feature set (notably modules) as any other enterprise language. This just leaves us with performance. 3. Very clearly CPython can be improved. I don't take most benchmarks very seriously, but we know that CPython interprets bytecode, and thus suffers relative to systems that compile into native code, and likely to some other interpretative systems. (Lua has been mentioned, and I recall looking at a presentation by the Lua guys on why they chose a register rather than stack-based approach.) 4. Extensions such as numpy can produce tremendous improvements in productivity AND performance. One answer to `is Python scalable' is to rephrase it as `is Python+C scalable'. 5. There are a number of JIT projects being considered, and one or more of these might well hold promise. 6. Following Scott Meyers' outstanding advice (from his Effective C++ books), one should prefer compile time to runtime wherever possible, if one is concerned about performance. An implementation that takes hints from programmers, e.g., that a certain variable is not to be changed, or that a given argument is always an int32, can generate special-case code that is at least in the same ballpark as C, if not as fast. This in no way detracts from Python's dynamic nature: these hints would be completely optional, and would not change the semantics of correct programs. (They might cause programs running on incorrect data to crash, but if you want performance, you are kind of stuck). These hints would `turn off' features that are difficult to compile into efficient code, but would do so only in those parts of a program where, for example, it was known that a given variable contains an int32. Dynamic (hint-free) and somewhat less-dynamic (hinted) code would coexist. This has been done for other languages, and is not a radically new concept. Such hints already exist in the language; __slots__ is an example. The language, at least as far as Python 3 is concerned, has pretty much all the machinery needed to provide such hints. Mechanisms that are recognized specially by a high-performance implementation (imported from a special module, for example) could include: annotations, decorators, metaclasses, and assignment to special variables like __slots__. 7. No implementation of Python at present incorporates JITting and hints fully. Therefore, the answer to `is CPython performance-scalable' is likely `NO'. Another implementation that exploited all of the features described here might well have satisfactory performance for a range of computation-intensive problems. Therefore, the answer to `is the Python language performance-scalable' might be `we don't know, but there are a number of promising implementation techniques that have been proven to work well in other languages, and may well have tremendous payoff for Python'. -- v From tjreedy at udel.edu Sat Nov 14 21:53:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:53:39 -0500 Subject: Simple object reference In-Reply-To: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> References: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: >> Hi, I have some problem with object reference >> Say I have this code >> >> a = b = c = None >> slist = [a,b,c] > > Values are stored in the list, not references to names. That is not right either, or else newbies would not be surprised by >>> a = [0] >>> b = [a] >>> b[0][0] = 1 >>> a [1] Subscriptable collections associate subscripts with objects. Namespaces associated names with objects. In either case, if you change the object, you change it, regardless of how you access it, such as by means of other associations. If you replace an association by associating a name or subscript with a new object, the old object is untouched (unless that was its last association) and other access methods by means of other associations are not affected. Terry Jan Reedy From clp2 at rebertia.com Sat Nov 14 22:19:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 19:19:19 -0800 Subject: Simple object reference In-Reply-To: References: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> Message-ID: <50697b2c0911141919j2bbd7a40j9d6dd19ffd7ff84b@mail.gmail.com> On Sat, Nov 14, 2009 at 6:53 PM, Terry Reedy wrote: > Chris Rebert wrote: >> On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: >>> Hi, I have some problem with object reference >>> Say I have this code >>> >>> a = b = c = None >>> slist = [a,b,c] >> >> Values are stored in the list, not references to names. > > That is not right either, or else newbies would not be surprised by >>>> a = [0] >>>> b = [a] >>>> b[0][0] = 1 >>>> a > [1] > > Subscriptable collections associate subscripts with objects. > Namespaces associated names with objects. > In either case, if you change the object, you change it, regardless of how > you access it, such as by means of other associations. > If you replace an association by associating a name or subscript with a new > object, the old object is untouched (unless that was its last association) > and other access methods by means of other associations are not affected. Okay, I should have technically said "references to objects" rather than "values", but in any case, names themselves are certainly not referenced or the following would print "[1]". >>> a = [0] >>> b = [a] >>> a = [42] >>> b[0][0] = 1 >>> a [42] Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 22:55:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 03:55:21 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <030f69bf$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 18:25:59 -0800, Vincent Manis wrote: > On 2009-11-13, at 15:32, Paul Rubin wrote: >> This is Usenet so >> please stick with Usenet practices. > Er, this is NOT Usenet. Actually it is. I'm posting to comp.lang.python. > 1. I haven't, to the best of my recollection, made a Usenet post in this > millennium. Actually you have, you just didn't know it. > 2. I haven't fired up a copy of rn or any other news reader in at least > 2 decades. > > 3. I'm on the python-list mailing list, reading this with Apple's Mail > application, which actually doesn't have convenient ways of enforcing > `Usenet practices' regarding message format. Nevertheless, the standards for line length for email and Usenet are compatible. > 4. If we're going to adhere to tried-and-true message format rules, I > want my IBM 2260 circa 1970, with its upper-case-only display and weird > little end-of-line symbols. No you don't, you're just taking the piss. > Stephen asked me to wrap my posts. I'm happy to do it. Can we please > finish this thread off and dispose of it? My name is actually Steven, but thank you for wrapping your posts. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:17:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:17:24 GMT Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: <030f6eea$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 07:53:05 -0800, Michele Simionato wrote: > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. Because unlike people writing comments, people here are never incompetent, misinformed, dishonest, confused, trolling or just wrong. But sometimes sarcastic. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:19:55 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:19:55 GMT Subject: The ol' [[]] * 500 bug... References: Message-ID: <030f6f81$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 21:26:01 +0000, kj wrote: > ...just bit me in the "fuzzy posterior". It's not a bug. Just because it doesn't behave as you would like it to behave doesn't mean it isn't behaving as designed. > The best I can come up with is the hideous > > lol = [[] for _ in xrange(500)] That's not hideous. > Is there something better? What did one do before comprehensions were > available? I suppose in that case one would have to go all the way with > > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] > > Yikes. 10 miles uphill, both ways... What's wrong with that? lol = [] for _ in xrange(500): lol.append([]) is a simple alternative too, although the list comp is better. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:21:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:21:57 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: <030f6ffb$0$1313$c3e8da3@news.astraweb.com> On Sat, 14 Nov 2009 11:14:04 +0000, kj wrote: > In <7xpr7lixnn.fsf at ruckus.brouhaha.com> Paul Rubin > writes: > >>It seems a little weird to me that they (Google) are concerned with the >>speed of the compiler, indicating that they plan to write enormous >>programs in the language. > > Fast compilation also means that Go can conceivably become an attractive > alternative to interpreted languages, because the compilation stage can > be made as unobtrusive as, say, Python's byte-compilation stage (except > that the Go compiler is generating native code). Python (like many other languages) already has unobtrusive compilation. That's why you get .pyc files, and that's what the compile() built-in function does. It is compilation to byte-code rather than machine-code, but still. Psyco does JIT compilation to machine-code for CPython, at the cost of much extra memory. It's also limited to 32-bit Intel processors. The aim of the PyPy project is to (eventually) make JIT machine-code compilation available to any Python, on any machine. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:29:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:29:44 GMT Subject: Anything better than shutil? References: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> Message-ID: <030f71ce$0$1313$c3e8da3@news.astraweb.com> On Sat, 14 Nov 2009 07:48:39 -0800, Roy Smith wrote: > I'm converting some old bash scripts to python. There's lots of places > where I'm doing things like "rm $source_dir/*.conf". The best way I can > see to convert this into python is: > > configs = glob.glob(os.path.join(source_dir, '*.conf')) > for conf_file in configs: > shutil.copy(conf_file, conf_dir) > > which is pretty clunky. Particularly since you're converting a remove to a copy... I suppose if you're used to the sort of terse code filled with magic characters that you find in bash, then the Python code might seem a bit verbose. And I suppose you would be right :) But trying to do something complicated in bash rapidly becomes *far* more verbose, unreadable and clunky than Python. > The idea interface I see would be one like: > > shutil.copy([source_dir, '*.conf'], conf_dir) Then write a helper function, and call that. # Untested. def copy(glb, destination): if not isinstance(glb, str): glb = os.path.join(*glb) glb = glob.glob(glb) for source in glb: shutil.copy(source, destination) -- Steven From nagle at animats.com Sat Nov 14 23:41:49 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Nov 2009 20:41:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <4aff8413$0$1588$742ec2ed@news.sonic.net> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 16:38:50 -0800, Vincent Manis wrote: > >> I'm having some trouble understanding this thread. My comments aren't >> directed at Terry's or Alain's comments, but at the thread overall. >> >> 1. The statement `Python is slow' doesn't make any sense to me. Python >> is a programming language; it is implementations that have speed or lack >> thereof. > > Of course you are right, but in common usage, "Python" refers to CPython, > and in fact since all the common (and possibly uncommon) implementations > of Python are as slow or slower than CPython, it's not an unreasonable > short-hand. Take a good look at Shed Skin. One guy has been able to build a system that compiles Python to C++, without requiring the user to add "annotations" about types. The system uses type inference to figure it out itself. You give up some flexibility; a variable can have only one primitive type in its life, or it can be a class object. That's enough to simplify the type analysis to the point that most types can be nailed down before the program is run. (Note, though, that the entire program may have to be analyzed as a whole. Separate compilation may not work; you need to see the callers to figure out how to compile the callees.) It's 10 to 60x faster than CPython. It's the implementation, not the language. Just because PyPy was a dud doesn't mean it's impossible. There are Javascript JIT systems far faster than Python. Nor do you really need a JIT system. (Neither does Java; GCC has a hard-code Java compiler. Java is JIT-oriented for historical reasons. Remember browser applets?) If you're doing server-side work, the program's structure and form have usually been fully determined by the time the program begins execution. John Nagle From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:55:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:55:51 GMT Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <030f77ec$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 14:10:10 -0800, scoopseven wrote: > I actually had a queryset that was dynamically generated, so I ended up > having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) What an unmaintainable mess. If I've understood it, you can make it less crap by (1) getting rid of the unnecessary escaped quotes, (2) avoiding generating the same strings multiple times, and (3) avoiding string concatenation. d = {} for thing in things: expr = "Thing.objects.filter(type=%s).order_by('-date')[:3]" expr = rhs % thing.id name = "thing_%s" % thing.id exec("%s = %s" % (name, expr)) d[name] = eval(expr) What else can we do to fix it? Firstly, why are you creating local variables "thing_XXX" (where XXX is the thing ID) *and* dictionary keys of exactly the same name? I'm sure you don't need the local variables. (If you think you do, you almost certainly don't.) That gets rid of the exec. Next, let's get rid of the eval: d = {} for thing in things: x = thing.id name = "thing_%s" % x d[name] = Thing.objects.filter(type=x).order_by('-date')[:3] About half the size, ten times the speed, and 1000 times the readability. Unless I've missed something, you don't need either exec or eval. -- Steven From michele.simionato at gmail.com Sun Nov 15 00:03:50 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 21:03:50 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: <166b80fe-0c13-4e97-ae47-a0c093f5f897@f16g2000yqm.googlegroups.com> On Nov 14, 7:18?pm, John Nagle wrote: > ? ? ?Leaving out exceptions was a mistake. ?Exceptions are well understood now, > and they're far better than the usual "ignore errors" approach one sees in lamer > C programs. I am also surprised about the lack of exceptions. I could infer that Rob Pike and Ken Thompson are idiots that lack experience with languages with exceptions, or I could infer that they have reasons for doing so. I do not know about exceptions enough to have an opinion myself. However I will notice that in Python, when using threads, exceptions do not work so well: if I forget to trap an exception in a thread I see a traceback on stderr, but the other threads continue to run, basically ignoring the exception. Probably the language that get things right is Erlang, which is supervising all crashed process and it is designed to safely recover for unexpected events. From michele.simionato at gmail.com Sun Nov 15 00:15:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 21:15:11 -0800 (PST) Subject: Python & Go References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Nov 15, 3:00?am, Terry Reedy wrote: > It seems to me that generators are already 'channels' that connect the > calling code to the __next__ method, a semi-coroutine based on the body > of the generator function. At present, the next method waits until an > object is requested. Then it goes into action, yields an object, and > rests again. > > I see no reason why we cannot have that with Python. I not even sure we > cannot have it with CPython, but I am not familiar enough with threads, > processes, and CPython internals. Of course we can have Go capabilities with Python. We already have generators and the multiprocessing module. It is just a matter of performance: I assume the Go implementation is more efficient. It would be nice to have numbers to quantify this claim. One can still write prototypes in Python and convert them in Go and the process looks less cumbersome than converting them in C or C++. I could never force myself to write C or C++; but I do not have any particular resistence to coding in Go, should I need a performance-oriented language. From aahz at pythoncraft.com Sun Nov 15 00:32:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 21:32:51 -0800 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: In article , ssteinerX at gmail.com wrote: >On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: >> On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >>> First, because as opposed to ch 1 there is quite a bit of code >>> here, and since I'm a >>> Python newbie I may be using non-idiomatic constructs, > >Welp, there goes my last excuse. > >I'm off to write my book: > >Heart Surgery at Home > > *************** >How to Save Thousands and >Get Results Just Like in Hospital > ******** > >Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? >Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? >Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery >Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 >Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? >Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan > >That's as far as I've gotten... > >Amazon best seller list, here I come! +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From rt8396 at gmail.com Sun Nov 15 00:41:03 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 21:41:03 -0800 (PST) Subject: Easy way to play single musical notes in Python References: Message-ID: <163ac43b-4d63-4db2-99c7-9b022c2e1f23@m20g2000vbp.googlegroups.com> On Nov 14, 6:21?pm, James Harris wrote: > Is there a simple way to play musical notes in Python? Something like > ? voice.play("c4") Uhh, tksnack is pretty easy to use IMO, see this link... http://www.daniweb.com/code/snippet216655.html No python does not have access to cross platform soundcard capabilities built into the language. I think there is a wrapper for csound somewhere. But there are many 3rd party modules that do have capabilities to some extent. You could make calls to the underlying OS machinery and there is the winsound module (not exactly what you want though). Just look over this Google splooge... http://www.google.com/search?hl=en&rlz=1C1CHMI_enUS340US340&q=Python+sound&aq=f&oq=&aqi=g10 From davea at ieee.org Sun Nov 15 01:22:14 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 15 Nov 2009 01:22:14 -0500 Subject: A different take on finding primes In-Reply-To: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: <4AFF9E16.506@ieee.org> Vincent Davis wrote: > Out of pure curiosity I would like to compare the efficiency of different > methods of finding primes (need not be consecutive). Let me be clear, given > 2min, how many primes can you find, they need not be in order or > consecutive. I have not seen any examples of this. I am assume the solution > is different depending on the time give, 2min or 2 hours. I assume a sieve > solution would be best for larger times. When the numbers get really large > checking to see if they are a prime gets costly. > So what do you think? > > *Vincent Davis > 720-301-3003 * > vincent at vincentdavis.net > my blog | > LinkedIn > > The sieve can be very efficiently written, but you have to decide whether to optimize for memory size or for speed. At a minimum for size you need an object for each prime currently found, and you will be looking through that list for each new candidate. Incidentally this approach can be done without any division. If you have memory to burn, you make a bit array equal in size to the largest prime you expect to encounter. There are also good algorithms for deciding whether a number of a particular form is prime. For example, there's a test for numbers of the form 2**n + 1. And don't forget the Miller-Rabin test. DaveA From aahz at pythoncraft.com Sun Nov 15 01:22:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:22:30 -0800 Subject: Python as network protocol References: Message-ID: In article , Cooch wrote: > >I want to implement such specific feature: >I have a server written in Python. I have a client written in C++. I >want to use Python as network protocol between them. I mean: client >send to server such string: "a = MyObject()", so object of this type >will appear in server. Any ideas how to simplify this implementation? >I make XML-RPC/SOAP server using twisted which just execute sended >string. But I don't know how to: >1. Restrict usage of some modules on client side (os, sys etc..) >2. Divide variables of different clients. Generally, I know that I >should use "exec .. in .. " construct, but don't know how to >distinguish between clients in twisted. What you want is a DSL -- domain-specific language. That might be a subset of Python that you parse yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From michele.simionato at gmail.com Sun Nov 15 01:24:01 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 22:24:01 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> <166b80fe-0c13-4e97-ae47-a0c093f5f897@f16g2000yqm.googlegroups.com> Message-ID: <6b0a2e86-49ec-4756-bcec-f658a0890edd@j4g2000yqe.googlegroups.com> Let me add a quote from the FAQ: """ Why does Go not have exceptions? Exceptions are a similar story. A number of designs for exceptions have been proposed but each adds significant complexity to the language and run-time. By their very nature, exceptions span functions and perhaps even goroutines; they have wide-ranging implications. There is also concern about the effect they would have on the libraries. They are, by definition, exceptional yet experience with other languages that support them show they have profound effect on library and interface specification. It would be nice to find a design that allows them to be truly exceptional without encouraging common errors to turn into special control flow that requires every programmer to compensate. Like generics, exceptions remain an open issue. """ From aahz at pythoncraft.com Sun Nov 15 01:25:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:25:34 -0800 Subject: A "terminators' club" for clp References: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <877htsskox.fsf@benfinney.id.au> Message-ID: In article <877htsskox.fsf at benfinney.id.au>, Ben Finney wrote: >Terry Reedy writes: >> >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > >Or if one has an ISP who provides a Usenet feed, like mine does. Mine does, too. >A pox upon Andrew Cuomo for bashing ISPs in the USA with the stick of >???child pornography??? (which he discovered on 88 out of many thousands of >forums). Faced with the unreasonable role of policing Usenet, they shut >it all off . Actually, my ISP is in New York City. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From joost at h-labahn.de Sun Nov 15 01:25:38 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 22:25:38 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> Message-ID: <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> Thanks ! Okay, i've already used the call of tp_free as the last statement in tp_dealloc and do understand now, that a call of tp_dealloc should be the last statement in the code for tp_free in specific cases. And yes, "Py_Type(&Foo_Type) = &PyType_Type" will be more stable against changes of the object implementation. Still there remains the difference to what is told with the Noddy_Type in the tutorial. Skimmimg through PyType_Ready in typeobject.c i find, that 3760 if (Py_TYPE(type) == NULL && base != NULL) 3761 Py_TYPE(type) = Py_TYPE(base); are the only lines referring to what is ob_type now. Thus the quoted lines from the tutorial ending with "Fortunately, this member will be filled in for us by PyType_Ready()." are possibly wrong (respective outdated) too. The two lines above are, what happens to my extension classes, if i want to derive application classes from them. class(my_extension_class): ... will of course call more from Python than PyTypeReady, but PyType(type) = Py_TYPE(base) is not getting corrected by this "more" here and the class statement doesn't create a new type. I will examine now, why this happens (without a crash of the calling application !), but still welcome every hint. Seen from a strict perspective this is a bug in Python's C-API. I'll save a freeze of the code for my extension for anyone, who might interested to reproduce this. Joost From aahz at pythoncraft.com Sun Nov 15 01:26:46 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:26:46 -0800 Subject: A "terminators' club" for clp References: <7xiqddt1fd.fsf@ruckus.brouhaha.com> Message-ID: In article <7xiqddt1fd.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >There is automatic moderation software that auto-approves any post >from an address that has had one or two posts manually approved. >While that's susceptible to address forgery, the typical spammer >doesn't do that. There's even auto-mod with e-mail confirmation (similar to subscribing to a mailing list), see soc.singles.moderated. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From rami.chowdhury at gmail.com Sun Nov 15 01:46:12 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 14 Nov 2009 22:46:12 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> References: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> Message-ID: <200911142246.12411.rami.chowdhury@gmail.com> On Saturday 14 November 2009 18:42:07 Vincent Manis wrote: > > 3. Very clearly CPython can be improved. I don't take most benchmarks > very seriously, but we know that CPython interprets bytecode, and > thus suffers relative to systems that compile into native code, and > likely to some other interpretative systems. (Lua has been > mentioned, and I recall looking at a presentation by the Lua guys on > why they chose a register rather than stack-based approach.) > For those interested in exploring the possible performance benefits of Python on a register-based VM, there's Pynie (http://code.google.com/p/pynie/)... and there's even a JIT in the works for that (http://docs.parrot.org/parrot/1.0.0/html/docs/jit.pod.html)... ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From tjreedy at udel.edu Sun Nov 15 01:53:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 01:53:06 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <4aff8413$0$1588$742ec2ed@news.sonic.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Steven D'Aprano wrote: > > Take a good look at Shed Skin. One guy has been able to build a system > that compiles Python to C++, without requiring the user to add > "annotations" about types. In *only* compiles a subset of Python, as does Cython. Both cannot (currently) do generators, but that can be done and probably will eventually at least for Cython. Much as I love them, they can be rewritten by hand as iterator classes and even then are not needed for a lot of computational code. I think both are good pieces of work so far. > The system uses type inference to figure it out itself. > You give up some flexibility; a variable can have only one primitive type > in its life, or it can be a class object. That's enough to simplify the > type analysis to the point that most types can be nailed down before the > program is run. (Note, though, that the entire program may have to > be analyzed as a whole. Separate compilation may not work; you need > to see the callers to figure out how to compile the callees.) > > It's 10 to 60x faster than CPython. > > It's the implementation, not the language. Just because PyPy was a > dud doesn't mean it's impossible. There are Javascript JIT systems > far faster than Python. > > Nor do you really need a JIT system. (Neither does Java; GCC has > a hard-code Java compiler. Java is JIT-oriented for historical reasons. > Remember browser applets?) If you're doing server-side work, the > program's structure and form have usually been fully determined by > the time the program begins execution. > > John Nagle From lusvehla at gmail.com Sun Nov 15 02:20:35 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 23:20:35 -0800 (PST) Subject: Calling Python functions from Excel Message-ID: Hi, unfortunately is my question about server COM (win32com) http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# without answer. Please I need Calling Python functions from Excel and receive result back in Excel. Can me somebody advise simplest solution please? I am more VBA programmer than Python. Thanks From greg at cosc.canterbury.ac.nz Sun Nov 15 02:25:39 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 15 Nov 2009 20:25:39 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: <4aff8413$0$1588$742ec2ed@news.sonic.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> Message-ID: <7m9oo1F3f2dcmU1@mid.individual.net> John Nagle wrote: > Take a good look at Shed Skin. ... > You give up some flexibility; a variable can have only one primitive type > in its life, or it can be a class object. That's enough to simplify the > type analysis to the point that most types can be nailed down before the > program is run. These restrictions mean that it isn't really quite Python, though. -- Greg From carsten.haese at gmail.com Sun Nov 15 02:53:49 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 15 Nov 2009 02:53:49 -0500 Subject: Calling Python functions from Excel In-Reply-To: References: Message-ID: Cannonbiker wrote: > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. Maybe this will help: http://oreilly.com/catalog/pythonwin32/chapter/ch12.html (Scroll down to "Implementing a COM Server.") -- Carsten Haese http://informixdb.sourceforge.net From michele.simionato at gmail.com Sun Nov 15 03:12:44 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 15 Nov 2009 00:12:44 -0800 (PST) Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> Message-ID: <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> On Nov 15, 5:17?am, Steven D'Aprano wrote: > On Fri, 13 Nov 2009 07:53:05 -0800, Michele Simionato wrote: > > I am skeptical about the utility of both rating and comments. If > > somebody wants to know > > if a package is good, she should ask here. > > Because unlike people writing comments, people here are never > incompetent, misinformed, dishonest, confused, trolling or just wrong. > > But sometimes sarcastic. > > -- > Steven All right, but the newsgroup has interactivity and the presence of true Python experts too. A blind vote given by an anonymous person does not look more informative to me. From tjreedy at udel.edu Sun Nov 15 03:30:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 03:30:55 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <7m9oo1F3f2dcmU1@mid.individual.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> Message-ID: greg wrote: > John Nagle wrote: >> Take a good look at Shed Skin. ... >> You give up some flexibility; a variable can have only one primitive type >> in its life, or it can be a class object. That's enough to simplify the >> type analysis to the point that most types can be nailed down before the >> program is run. > > These restrictions mean that it isn't really quite > Python, though. Python code that only uses a subset of features very much *is* Python code. The author of ShedSkin makes no claim that is compiles all Python code. From fetchinson at googlemail.com Sun Nov 15 04:21:35 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 15 Nov 2009 10:21:35 +0100 Subject: Vote on PyPI comments In-Reply-To: <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> Message-ID: >> > I am skeptical about the utility of both rating and comments. If >> > somebody wants to know >> > if a package is good, she should ask here. >> >> Because unlike people writing comments, people here are never >> incompetent, misinformed, dishonest, confused, trolling or just wrong. >> >> But sometimes sarcastic. >> > > All right, but the newsgroup has interactivity and the presence of > true Python experts too. > A blind vote given by an anonymous person does not look more > informative to me. You are right about a single vote, but the way these things usually work is that out of 1000 votes the non-informative ones average out ("wow! awsome package!" vs "this sucks bad!") and the net vote result is generally indicative of the actual thing that was voted on especially when there is no direct financial incentive to cheat. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Nov 15 04:59:53 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 15 Nov 2009 09:59:53 +0000 (UTC) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> Message-ID: Santiago Romero wrote: >> Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do >> not remember the CPU freqeuncy anymore, maybe 25MHz). > > Yes, in ASM a simple 25 or 33Mhz 386 computer was able to emulate > the > Spectrum. At least, under MSDOS, like did Warajevo, Z80, x128 and > "Spectrum" > from Pedro Gimeno. And my very own, (sadly, rather little known at the time) 'Nuclear ZX' :-) It did not use a dispatch table - rather, each Z80 instruction was taken as a high byte of the pointer to a 64KB block of 8086 code, low byte being zero for unprefixed instructions or a given value for prefixed ones. This approach saved one lookup (several cycles) and one indirect jump (another several cycles) per instruction. Another optimization would be to unroll the return jump from each of the emulated instructions and replace it directly with inline read-the-next-instruction-and-jump-there code, but I never got around to that (would save one 8086 jump per one Z80 instruction :-)) >> http://perl-spectrum.sourceforge.net/ >> >> It is quite fast IMHO. > > It does not run 100% in my 1.8Ghz centrino computer :-(, but almost. > At least, is a good start to see that is possible, at least no current > DualCore computers :-) Python IS slower than perl, especially since you are dealing with objects. However, I'd suggest go the cPickle route - have a Z80Cpu module, and its C equivalent, cZ80, and use that one if available. This way, the emulator will be actually usable everywhere. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From tartley at tartley.com Sun Nov 15 05:56:29 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sun, 15 Nov 2009 02:56:29 -0800 (PST) Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> Message-ID: <153f9f72-342c-4a3f-9105-2a4596bd12d3@w19g2000yqk.googlegroups.com> On Nov 15, 9:21?am, Daniel Fetchinson wrote: > >> > I am skeptical about the utility of both rating and comments. If > >> > somebody wants to know > >> > if a package is good, she should ask here. > > >> Because unlike people writing comments, people here are never > >> incompetent, misinformed, dishonest, confused, trolling or just wrong. > > >> But sometimes sarcastic. > > > All right, but the newsgroup has interactivity and the presence of > > true Python experts too. > > A blind vote given by an anonymous person does not look more > > informative to me. > > You are right about a single vote, but the way these things usually > work is that out of 1000 votes the non-informative ones average out > ("wow! awsome package!" vs "this sucks bad!") and the net vote result > is generally indicative of the actual thing that was voted on > especially when there is no direct financial incentive to cheat. > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown I haven't used the PyPI rating / comments system at all. Can comments accrue which complain about bugs or missing features of old versions of the package? If so, they could be misleading for users coming to view a package before trying it. Or do comments and ratings only apply to a particular version of a package, and get removed from the package's 'front page' every time a new version is released? Thanks, Jonathan Hartley From sromero at gmail.com Sun Nov 15 06:17:08 2009 From: sromero at gmail.com (Santiago Romero) Date: Sun, 15 Nov 2009 03:17:08 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> Message-ID: > Python IS slower than perl, especially since you are dealing with > objects. However, I'd suggest go the cPickle route - have a Z80Cpu > module, and its C equivalent, cZ80, and use that one if available. This > way, the emulator will be actually usable everywhere. Thanks for the advice but ... my (currently working) emulator is already written in C, I don't see the point of calling it from a python module. I had 2 options: port the emulator from C+Allegro to C +SDL or port it to Python+Pygame+SDL... And the fun is trying to write it in pure python with pygame, without external C :-) I'll do a quick test, if I see that I can't achieve 100% speed in my other computer (DualCore2 1.82Ghz, the basic-standard-minimum computer nowadays), then I'll give up, but at least I want to try it X-D Today or tomorrow I'm finishing the pyinliner.py preprocessor X-D. I'll paste the results here :-) Thanks for your answer :-) From vicente.soler at gmail.com Sun Nov 15 06:59:29 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 15 Nov 2009 03:59:29 -0800 (PST) Subject: Changing the current directory Message-ID: <68faefbe-f1a8-4358-b65d-c9f0d562f7ff@r5g2000yqb.googlegroups.com> Ever since I installed my Python 2.6 interpreter, I've been saving my *.py files in the C:\Program Files\Python26 directory, which is the default directory for such files in my system. However, I have realised that the above is not the best practice. Therefore I created the C:\Program Files\Python26\test directory and I want it to be my default directory for saving *.py files, importing modules, etc. I'd like to do something like the DOS equivalent of "CD test" but I do not know kow to do it. I am currently doing something really awful: I open a *.py file in the est subdirectory, I run it with the F5 key and it works! but I am doing really something stupid. I can see that it works because if I do From nobody at nowhere.com Sun Nov 15 07:01:53 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 12:01:53 +0000 Subject: More Python versions on an XP machine References: Message-ID: On Sat, 14 Nov 2009 14:45:48 +0100, Gabor Urban wrote: > this a very MS specific question. I do use a rather old Python > version, because we have a couple of applications written for that. > Porting them to a newer Python is not allowed by the bosses. Now we > will start a new project with latest stable Python. Can I have them > both on my computer, and how should I do that. You can have multiple versions, but you can only associate one specific version with the ".py" suffix. This matters if you need to be able to execute .py files as if they were executables, e.g. double-clicking on the script in Explorer or typing the script's name in the command prompt. You can run scripts which use other versions of Python by specifying the interpreter explicitly, e.g.: "C:\Program Files\Python25\python.exe" "C:\Program Files\MyApp\myscript.py" From vicente.soler at gmail.com Sun Nov 15 07:04:06 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 15 Nov 2009 04:04:06 -0800 (PST) Subject: Changing the current directory (full post) Message-ID: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Oops!!! something went wrong with my keyboard. Here you have my full post: Ever since I installed my Python 2.6 interpreter (I use IDLE), I've been saving my *.py files in the C:\Program Files\Python26 directory, which is the default directory for such files in my system. However, I have realised that the above is not the best practice. Therefore I created the C:\Program Files\Python26\test directory and I want it to be my default directory for saving *.py files, importing modules, etc. I'd like to do something like the DOS equivalent of "CD test" but I do not know kow to do it. I am currently doing something really awful: I open a *.py file in the test subdirectory, I run it with the F5 key and it works! but I am doing really something stupid. I can see that it works because if I do import sys sys.path ... the first directory in the list is the test one. How should I proceed, if I want to proceed properly? Vicente Soler From nobody at nowhere.com Sun Nov 15 07:06:48 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 12:06:48 +0000 Subject: How to know if a file is a text file References: Message-ID: On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote: > I'm looking for a way to be able to load a generic file from the > system and understand if he is plain text. > The mimetype module has some nice methods, but for example it's not > working for file without extension. > > Any suggestion? You could use the "file" command. It's normally installed by default on Unix systems, but you can get a Windows version from: http://gnuwin32.sourceforge.net/packages/file.htm From clp2 at rebertia.com Sun Nov 15 07:34:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 Nov 2009 04:34:10 -0800 Subject: How to know if a file is a text file In-Reply-To: References: Message-ID: <50697b2c0911150434n33c1c7cdud346f3dd9a88ea97@mail.gmail.com> On Sun, Nov 15, 2009 at 4:06 AM, Nobody wrote: > On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote: > >> I'm looking for a way to be able to load a generic file from the >> system and understand if he is plain text. >> The mimetype module has some nice methods, but for example it's not >> working for file without extension. >> >> Any suggestion? > > You could use the "file" command. It's normally installed by default on > Unix systems, but you can get a Windows version from: FWIW, IIRC the heuristic `file` uses to check whether a file is text or not is whether it contains any null bytes; if it does, it classifies it as binary (i.e. not text). Cheers, Chris -- http://blog.rebertia.com From sungsuha at gmail.com Sun Nov 15 07:40:00 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 04:40:00 -0800 (PST) Subject: basic class question.. Message-ID: class rawDNA: import string trans = string.maketrans("GATC","CTAG") def __init__(self, template = "GATTACA"): self.template = template //shouldn't this make "template" accessible within the scope of "rawDNA"?? def noncoding(self): print template.translate(trans) // >>>test = rawDNA() >>>test.noncoding() Traceback (most recent call last): File "", line 1, in test.noncoding() File "", line 7, in noncoding print template.translate(trans) NameError: global name 'template' is not defined I'm curious .. what am I doing wrong?? P.S class rawDNA: import string trans = string.maketrans("GATC","CTAG") def __init__(self, template = "GATTACA"): self.template = template def noncoding(self): print self.template.translate(trans) this works as intended. Thanks in advance From lucafbb at gmail.com Sun Nov 15 07:49:54 2009 From: lucafbb at gmail.com (Luca) Date: Sun, 15 Nov 2009 13:49:54 +0100 Subject: How to know if a file is a text file In-Reply-To: References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: <27308d500911150449g2c3f375anc73ed7ad88f92a02@mail.gmail.com> On Sat, Nov 14, 2009 at 6:51 PM, Philip Semanchuk wrote: > Hi Luca, > You have to define what you mean by "text" file. It might seem obvious, but > it's not. > > Do you mean just ASCII text? Or will you accept Unicode too? Unicode text > can be more difficult to detect because you have to guess the file's > encoding (unless it has a BOM; most don't). > > And do you need to verify that every single byte in the file is "text"? What > if the file is 1GB, do you still want to examine every single byte? > > If you give us your own (specific!) definition of what "text" means, or > perhaps a description of the problem you're trying to solve, then maybe we > can help you better. > Thanks all. I was quite sure that this is not a very simple task. Right now search only inside ASCII encode is not enough for me (my native language is outside this encode :-) Checking every single byte can be a good solution... I can start using the mimetype module and, if the file has no extension, check byte one by one (commonly) as "file" command does. Better: I can check use the "file" command if available. Again: thanks all! -- -- luca From deets at nospam.web.de Sun Nov 15 07:52:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 13:52:55 +0100 Subject: basic class question.. In-Reply-To: References: Message-ID: <7mabt8F3gdudpU1@mid.uni-berlin.de> Pyrot schrieb: > class rawDNA: > import string Importing here is unusual. Unless you have good reasons to do so, I suggest you put the imports on top of the file. > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > self.template = template //shouldn't this make "template" > accessible within the scope of "rawDNA"?? No. > > > def noncoding(self): > print template.translate(trans) // This needs to be print self.template.translate(trans) Thes scopes insied a class are only the method-locals (to which the parameters count of course), and globals. Diez From highcar at gmail.com Sun Nov 15 08:08:31 2009 From: highcar at gmail.com (elca) Date: Sun, 15 Nov 2009 05:08:31 -0800 (PST) Subject: python win32com problem Message-ID: <26358976.post@talk.nabble.com> hello , these day im very stress of one of some strange thing. i want to enumurate inside list of url, and every enumurated url i want to visit i was uplod incompleted script source in here => http://elca.pastebin.com/m6f911584 if anyone can help me really appreciate thanks in advance Paul -- View this message in context: http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html Sent from the Python - python-list mailing list archive at Nabble.com. From python.list at tim.thechases.com Sun Nov 15 08:15:28 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Nov 2009 07:15:28 -0600 Subject: basic class question.. In-Reply-To: References: Message-ID: <4AFFFEF0.1000900@tim.thechases.com> Pyrot wrote: > class rawDNA: > import string > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > self.template = template //shouldn't this make "template" > accessible within the scope of "rawDNA"?? No. Python's scope resolution consists only of "local, global, or explicit". There is no "try to find this in the instance or class" scope-resolution guessing. Your code makes "template" accessible within the scope of "self", not in a global unqualified scope. So this: > def noncoding(self): > print template.translate(trans) // tries to reference "template" first in the local scope (within noncoding(), but it doesn't exist there), then in the global scope (it also doesn't exist there), and stops. It should be as you have it here: > class rawDNA: > import string > trans = string.maketrans("GATC","CTAG") > def __init__(self, template = "GATTACA"): > self.template = template > def noncoding(self): > print self.template.translate(trans) Here, you start with "self" which *is* in the local scope, which *does* contain "template" and so it successfully finds it and all is [qualifiedly] good. However, you'll also find that "trans" isn't found because it's neither in the local nor global scope: >>> class RawDNA: ... import string ... trans = string.maketrans("GATC", "CTAG") ... def __init__(self, template="GATTACA"): ... self.template = template ... def noncoding(self): ... print self.template.translate(trans) ... >>> r = RawDNA() >>> r.noncoding() Traceback (most recent call last): File "", line 1, in File "", line 7, in noncoding NameError: global name 'trans' is not defined so you need to fully qualify it as "RawDNA.trans" for Python to find it. (I also shifted to using the PEP-8 naming convention "RawDNA" instead of "rawDNA"). Which you indeed discovered: > this works as intended. Being explicit is part of "Python Zen" (from the python command-prompt, type "import this" to see the whole list) -tkc From deets at nospam.web.de Sun Nov 15 09:20:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 15:20:49 +0100 Subject: basic class question.. In-Reply-To: <7mabt8F3gdudpU1@mid.uni-berlin.de> References: <7mabt8F3gdudpU1@mid.uni-berlin.de> Message-ID: <7mah21F3fopovU1@mid.uni-berlin.de> Diez B. Roggisch schrieb: > Pyrot schrieb: >> class rawDNA: >> import string > > Importing here is unusual. Unless you have good reasons to do so, I > suggest you put the imports on top of the file. > >> trans = string.maketrans("GATC","CTAG") >> >> >> def __init__(self, template = "GATTACA"): >> self.template = template //shouldn't this make "template" >> accessible within the scope of "rawDNA"?? > > No. >> >> >> def noncoding(self): >> print template.translate(trans) // > > This needs to be > > print self.template.translate(trans) Ah, sorry, that should have been self.template.translate(self.trans) Diez From mrholtsr at gmail.com Sun Nov 15 09:30:50 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Sun, 15 Nov 2009 06:30:50 -0800 (PST) Subject: Code for finding the 1000th prime Message-ID: I am absolutely new to python and barely past beginner in programming. Also I am not a mathematician. Can some one give me pointers for finding the 1000th. prime for a course I am taking over the internet on Introduction to Computer Science and Programming. Thanks, Ray From rpjday at crashcourse.ca Sun Nov 15 09:44:43 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sun, 15 Nov 2009 09:44:43 -0500 (EST) Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: On Sun, 15 Nov 2009, mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray it's 7919. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From deets at nospam.web.de Sun Nov 15 10:02:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 16:02:09 +0100 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <7majfhF2j43tpU1@mid.uni-berlin.de> mrholtsr schrieb: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray Do you really think we are so retarded that we don't remember you posted the same question a week ago? Diez From loftusoft at yahoo.com Sun Nov 15 10:13:41 2009 From: loftusoft at yahoo.com (Mike) Date: Sun, 15 Nov 2009 07:13:41 -0800 (PST) Subject: Stagnant Frame Data? Message-ID: I'll apologize first for this somewhat lengthy example. It does however recreate the problem I've run into. This is stripped-down code from a much more meaningful system. I have two example classes, "AutoChecker" and "Snapshot" that evaluate variables in their caller's namespace using the frame stack. As written, the output is not what is expected: the variables evaluate to "stagnant" values. However, if the one indicated line is uncommented, then the result is as expected. So my questions are: Is this a bug in Python? Is this an invalid use of frame data? Why does the single line "sys._getframe(1).f_locals" fix the behavior? Thanks, Mike import sys class Snapshot(object): def __init__(self, caller_globals, caller_locals): self.signals = [] self.caller_globals = caller_globals self.caller_locals = caller_locals def get_values(self): samples = {} for signal in self.signals: samples[signal] = eval(signal, self.caller_globals, self.caller_locals) return samples def print_values(self): print 'snapshot data' for name, value in self.get_values().items(): print '\t', name, '=', value class AutoChecker(object): def __init__(self, statement): self.statement = statement self.caller_globals = sys._getframe(1).f_globals self.caller_locals = sys._getframe(1).f_locals self.snapshot = Snapshot(self.caller_globals, self.caller_locals) self.snapshot_history = [] def check(self): # uncomment following line to get expected behavior #sys._getframe(1).f_locals if eval(self.statement, self.caller_globals, self.caller_locals) == False: print self.statement, 'failed' self.snapshot.print_values() self.snapshot_history.append(self.snapshot.get_values()) def report(self): if len(self.snapshot_history): return print 'snapshot history' for samples in self.snapshot_history: for name, value in samples.items(): print '\t', name, '=', value def f(): x = 0.0 y = 0.0 ac1 = AutoChecker('x < 2.0') ac1.snapshot.signals.append('x') ac1.snapshot.signals.append('y') for i in range(5): x = i / 2.0 y = x / 2 print i, x ac1.check() ac1.snapshot.print_values() ac1.report() From joncle at googlemail.com Sun Nov 15 10:36:25 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 07:36:25 -0800 (PST) Subject: python win32com problem References: Message-ID: On Nov 15, 1:08?pm, elca wrote: > hello , these day im very stress of one of some strange thing. > > i want to enumurate inside list of url, and every enumurated url i want to > visit > > i was uplod incompleted script source in here => > > http://elca.pastebin.com/m6f911584 > > if anyone can help me really appreciate > > thanks in advance > > Paul > > -- > View this message in context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html > Sent from the Python - python-list mailing list archive at Nabble.com. How much effort have you put into this? It looks like you've just whacked together code (that isn't valid -- where'd the magical 'buttons' variable come from), given up and cried for help. Besides, I would suggest you're taking completely the wrong route. You'll find it one hell of a challenge to automate a browser as you want, that's if it supports exposing the DOM anyway. And without being rude, would definitely be beyond your abilities from your posts to c.l.p. Download and install BeautifulSoup from http://www.crummy.com/software/BeautifulSoup/ - you seem to have quite a few HTML based needs in your pastebin, so it'll come in useful for the future. Here's a snippet to get you started: from urllib2 import urlopen from BeautifulSoup import BeautifulSoup as BS url = urlopen('http://news.naver.com/main/presscenter/category.nhn') urldata = url.read() soup = BS(urldata) atags = soup('a', attrs={'href': lambda L: L and L.startswith('http:// news.khan.co.kr')}) for atag in atags: print atag['href'] I'll leave it to you where you want to go from there (ie, follow the links, or automate IE to open said pages etc...) I strongly suggest reading the urllib2 and BeautifulSoup docs, and documenting the above code snippet -- you should then understand it, should be less stressed, and have something to refer to for similar requirements in the future. hth, Jon. From __peter__ at web.de Sun Nov 15 11:00:17 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Nov 2009 17:00:17 +0100 Subject: Stagnant Frame Data? References: Message-ID: Mike wrote: > I'll apologize first for this somewhat lengthy example. It does > however recreate the problem I've run into. This is stripped-down code > from a much more meaningful system. > > I have two example classes, "AutoChecker" and "Snapshot" that evaluate > variables in their caller's namespace using the frame stack. As > written, the output is not what is expected: the variables evaluate to > "stagnant" values. > > However, if the one indicated line is uncommented, then the result is > as expected. > > So my questions are: Is this a bug in Python? Is this an invalid use > of frame data? Why does the single line "sys._getframe(1).f_locals" > fix the behavior? A simplified demonstration of your problem: >>> def f(update): ... a = locals() ... x = 42 ... if update: locals() ... print a ... >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} The local namespace is not a dictionary, and the locals()/f_locals dictionary contains a snapshot of the local namespace. Accessing the f_locals attribute is one way to trigger an update of that snapshot. What's puzzling is that the same dictionary is reused. Peter From news at schwertberger.de Sun Nov 15 11:05:54 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 15 Nov 2009 17:05:54 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> Message-ID: <7man75F3gh0lgU1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 19:02, Dietmar Schwertberger wrote: >> I tried 3.01.63. >> I can see in the Python window already that the code is not correct. > > 3.01.63 > > Did you remember to install the wxAdditions? No. I think that they should not be required (a minimal version seems to be included in wxFormBuilder) and I don't get any error message. Also using wxAdditions for wx Python doesn't seem to be straightforward. > Could you send me an .fbp file demonstrating the error? Sent by email. Did you receive it? Regards, Dietmar From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:08:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:08:23 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > I'm attempting to convert latitude and longitude coordinates from degrees > minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this > conversion? Should be: decimal = degrees + minutes/60.0 + seconds/3600.0 N,E are positive; S,W are negative. But the above numbers don't match. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:08:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:08:23 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > I'm attempting to convert latitude and longitude coordinates from degrees > minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this > conversion? Should be: decimal = degrees + minutes/60.0 + seconds/3600.0 N,E are positive; S,W are negative. But the above numbers don't match. -- Gabriel Genellina From exarkun at twistedmatrix.com Sun Nov 15 11:19:19 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 15 Nov 2009 16:19:19 -0000 Subject: Stagnant Frame Data? In-Reply-To: References: Message-ID: <20091115161919.27565.1296418538.divmod.xquotient.167@localhost.localdomain> On 04:00 pm, __peter__ at web.de wrote: >Mike wrote: >>I'll apologize first for this somewhat lengthy example. It does >>however recreate the problem I've run into. This is stripped-down code >>from a much more meaningful system. >> >>I have two example classes, "AutoChecker" and "Snapshot" that evaluate >>variables in their caller's namespace using the frame stack. As >>written, the output is not what is expected: the variables evaluate to >>"stagnant" values. >> >>However, if the one indicated line is uncommented, then the result is >>as expected. >> >>So my questions are: Is this a bug in Python? Is this an invalid use >>of frame data? Why does the single line "sys._getframe(1).f_locals" >>fix the behavior? > >A simplified demonstration of your problem: >>>>def f(update): >... a = locals() >... x = 42 >... if update: locals() >... print a >... >>>>f(False) >{'update': False} >>>>f(True) >{'a': {...}, 'x': 42, 'update': True} > >The local namespace is not a dictionary, and the locals()/f_locals >dictionary contains a snapshot of the local namespace. Accessing the >f_locals attribute is one way to trigger an update of that snapshot. > >What's puzzling is that the same dictionary is reused. http://bugs.python.org/issue6116 is vaguely related. Jean-Paul From ecir.hana at gmail.com Sun Nov 15 11:28:07 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Sun, 15 Nov 2009 08:28:07 -0800 (PST) Subject: Redirect stdout to a buffer Message-ID: Hello, I'm trying to write a simple Win32 app, which may run some Python scripts. Since it is a Windows GUI app, I would like to redirect all output (Python print, C printf, fprinf stderr, ...) to a text area inside the app. In other words, I'm trying to log all the output from the app (C, Python) to a window. So far, this works for C printf(): int fds[2]; _pipe(fds, 1024, O_TEXT); _dup2(fds[1], 1); ... and then I read from pipe's read-end and append the text to the text area. But when I try to run: Py_Initialize(); PyRun_SimpleString("print 'abc'"); Py_Finalize(); I get an error: IOError: [Errno 9] Bad file descriptor What am I doing wrong? How to redirect standard IO, both for C and for Python? PS: Maybe I'm doind something wrong, but SetStdHandle() does not work at all.... From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:32:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:32:01 -0300 Subject: __import__ returns module without it's attributes? References: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns escribi?: > I've overloaded __import__ to modify modules after they are > imported... but running dir(module) on the result only returns > __builtins__, __doc__, __file__, > __name__, __package__, and __path__. > > Why is this? More importantly, where can I hook in that would allow me > to see the contents of the module? Post some code. This works for me: py> import __builtin__ py> builtin_import = __builtin__.__import__ py> def __import__(*args): ... module = builtin_import(*args) ... module.__signature__ = "kilroywashere" ... return module ... py> __builtin__.__import__ = __import__ py> py> import htmllib py> dir(htmllib) ['AS_IS', 'HTMLParseError', 'HTMLParser', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__signature__', 'sgmllib', 'test'] py> htmllib.__signature__ 'kilroywashere' -- Gabriel Genellina From pengyu.ut at gmail.com Sun Nov 15 12:09:05 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 15 Nov 2009 09:09:05 -0800 (PST) Subject: IDE for python Message-ID: There had been some discussion on IDE. But I'm not sure what pros and cons of each choice. Current, I'm using vim and ctags. Could somebody give some advices on choosing the best IDE for me? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gst&q=IDE#e934bd5b9f2d0f8c From deets at nospam.web.de Sun Nov 15 12:15:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 18:15:16 +0100 Subject: IDE for python In-Reply-To: References: Message-ID: <7mar95F3g85n0U1@mid.uni-berlin.de> Peng Yu schrieb: > There had been some discussion on IDE. But I'm not sure what pros and > cons of each choice. Current, I'm using vim and ctags. > > Could somebody give some advices on choosing the best IDE for me? > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gst&q=IDE#e934bd5b9f2d0f8c I suggest you use your google foo that you just showed to search in this group for the numerous discussions about emacs, vi, eclipse+pydev, wing ide, komodo and notepad. Diez From phlip2005 at gmail.com Sun Nov 15 12:16:11 2009 From: phlip2005 at gmail.com (Phlip) Date: Sun, 15 Nov 2009 09:16:11 -0800 (PST) Subject: How can pip install a GitHub code drop? Message-ID: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> Not Hyp: Suppose I have a Python library, complete with a respectable setup.py. How can I point pip at the repo to install the library? if I use this... sudo pip -e git+git://github.com/Phlip/Kozmiq.git ...I get an editable drop in a ~/src/ folder. -- Phlip http://c2.com/cgi/wiki?ZeekLand From paul at boddie.org.uk Sun Nov 15 12:16:58 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 15 Nov 2009 09:16:58 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> Message-ID: <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> On 15 Nov, 09:30, Terry Reedy wrote: > greg wrote: > [Shed Skin] > > These restrictions mean that it isn't really quite > > Python, though. > > Python code that only uses a subset of features very much *is* Python > code. The author of ShedSkin makes no claim that is compiles all Python > code. Of course, Shed Skin doesn't support all the usual CPython features, but the code you would write for Shed Skin's benefit should be Python code that runs under CPython. It's fair to say that Shed Skin isn't a "complete" implementation of what CPython defines as being "the full Python", but you're still writing Python. One can argue that the restrictions imposed by Shed Skin inhibit the code from being "proper" Python, but every software project has restrictions in the form of styles, patterns and conventions. This is where the "Lesser Python" crowd usually step in and say that they won't look at anything which doesn't support "the full Python", but I think it's informative to evaluate which features of Python give the most value and which we could do without. The "Lesser Python" attitude is to say, "No! We want it all! It's all necessary for everything!" That doesn't really help the people implementing "proper" implementations or those trying to deliver better-performing implementations. In fact, the mentality that claims that "it's perfect, or it will be if we keep adding features" could drive Python into a diminishing niche over time. In contrast, considering variations of Python as some kind of "Greater Python" ecosystem could help Python (the language) adapt to the changing demands on programming languages to which Go (the Google language, not Go! which existed already) is supposedly a response. Paul P.S. And PyPy is hardly a dud: they're only just getting started delivering the performance benefits, and it looks rather promising. From highcar at gmail.com Sun Nov 15 12:29:34 2009 From: highcar at gmail.com (elca) Date: Sun, 15 Nov 2009 09:29:34 -0800 (PST) Subject: python win32com problem In-Reply-To: References: <26358976.post@talk.nabble.com> Message-ID: <26361229.post@talk.nabble.com> Jon Clements-2 wrote: > > On Nov 15, 1:08?pm, elca wrote: >> hello , these day im very stress of one of some strange thing. >> >> i want to enumurate inside list of url, and every enumurated url i want >> to >> visit >> >> i was uplod incompleted script source in here => >> >> http://elca.pastebin.com/m6f911584 >> >> if anyone can help me really appreciate >> >> thanks in advance >> >> Paul >> >> -- >> View this message in >> context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > How much effort have you put into this? It looks like you've just > whacked together code (that isn't valid -- where'd the magical > 'buttons' variable come from), given up and cried for help. > > Besides, I would suggest you're taking completely the wrong route. > You'll find it one hell of a challenge to automate a browser as you > want, that's if it supports exposing the DOM anyway. And without being > rude, would definitely be beyond your abilities from your posts to > c.l.p. > > Download and install BeautifulSoup from > http://www.crummy.com/software/BeautifulSoup/ > - you seem to have quite a few HTML based needs in your pastebin, so > it'll come in useful for the future. > > Here's a snippet to get you started: > > from urllib2 import urlopen > from BeautifulSoup import BeautifulSoup as BS > > url = urlopen('http://news.naver.com/main/presscenter/category.nhn') > urldata = url.read() > soup = BS(urldata) > atags = soup('a', attrs={'href': lambda L: L and L.startswith('http:// > news.khan.co.kr')}) > for atag in atags: > print atag['href'] > > I'll leave it to you where you want to go from there (ie, follow the > links, or automate IE to open said pages etc...) > > I strongly suggest reading the urllib2 and BeautifulSoup docs, and > documenting the above code snippet -- you should then understand it, > should be less stressed, and have something to refer to for similar > requirements in the future. > > hth, > Jon. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, thanks for your kind reply. your script is working very well im making scraper now. and im making with PAMIE but still slow module but i have no choice because of javascript support. before i was try to look for method with mechanize but almost failed. if mechanize can support javascript maybe my best choice will be mechanize. ok anyway..there is almost no choice so i have to go "automate IE to open said pages etc.." i want to visit every collect link with IE com interface.. for example i was collect 10 url ...i want to visit every 10 url. would you help me some more? if so much appreciate thanks -- View this message in context: http://old.nabble.com/python-win32com-problem-tp26358976p26361229.html Sent from the Python - python-list mailing list archive at Nabble.com. From pengyu.ut at gmail.com Sun Nov 15 12:39:17 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 15 Nov 2009 09:39:17 -0800 (PST) Subject: IDE for python References: <7mar95F3g85n0U1@mid.uni-berlin.de> Message-ID: On Nov 15, 11:15?am, "Diez B. Roggisch" wrote: > Peng Yu schrieb: > > > There had been some discussion on IDE. But I'm not sure what pros and > > cons of each choice. Current, I'm using vim and ctags. > > > Could somebody give some advices on choosing the best IDE for me? > > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > I suggest you use your google foo that you just showed to search in this > group for the numerous discussions about emacs, vi, eclipse+pydev, wing > ide, komodo and notepad. I see too many threads. But I don't any of them give me a complete comparison between different choices. If you are familiar with different choices, would you please give me some advices? http://groups.google.com/group/comp.lang.python/search?group=comp.lang.python&q=IDE&qt_g=Search+this+group From arve.knudsen at gmail.com Sun Nov 15 12:56:56 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 09:56:56 -0800 (PST) Subject: How to get directory of Python C library Message-ID: Hi I need to link against Python, is there a way to get the path to the directory containing Python's C library (e.g., /libs on Windows)? Thanks, Arve From joost at h-labahn.de Sun Nov 15 13:21:30 2009 From: joost at h-labahn.de (DreiJane) Date: Sun, 15 Nov 2009 10:21:30 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> Message-ID: <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> Thanks a second time - the picture has gotten clearer indeed. But for third-party readers the complexities of this matter require the correction, that "Py_Type(&Foo_Type) = &PyType_Type" must be: "Py_TYPE(&Foo_Type) = &PyType_Type " - or am i completely wrong ? Joost From showell30 at yahoo.com Sun Nov 15 13:25:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 10:25:43 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict Message-ID: I ran the following program, and found its output surprising in one place: class OnlyAl: def __getitem__(self, key): return 'al' class OnlyBob(dict): def __getitem__(self, key): return 'bob' import sys; print sys.version al = OnlyAl() bob = OnlyBob() print al['whatever'] al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' print al['whatever'] print bob['whatever'] bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems impossible' print bob['whatever'] 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] al NEW AND IMPROVED AL! bob bob In attempting to change the behavior for bob's dictionary lookup, I am clearly doing something wrong, or maybe even impossible. Obviously the examples are contrived, but I am interested on a purely academic level why setting __getitem__ on bob does not seem to change the behavior of bob['foo']. Note that OnlyBob subclasses dict; OnlyAl does not. On a more practical level, I will explain what I am trying to do. Basically, I am trying to create some code that allows me to spy on arbitrary objects in a test environment. I want to write a spy() method that takes an arbitrary object and overrides its implementation of __getitem__ and friends so that I can see how library code is invoking the object (with print statements or whatever). Furthermore, I want spy() to recursively spy on objects that get produced from my original object. The particular use case is that I am creating a context for Django templates, and I want to see which objects are getting rendered, all the way down the tree. It would be pretty easy to just create a subclass of the context method to spy at the top level, but I want to recursively spy on all its children, and that is why I need a monkeypatching approach. The original version had spy recursively returning proxy/masquerade objects that intercepted __getitem__ calls, but it becomes brittle when the proxy objects go off into places like template filters, where I am not prepared to intercept all calls to the object, and where in some cases it is impossible to gain control. Although I am interested in comments on the general problems (spying on objects, or spying on Django template rendering), I am most interested in the specific mechanism for changing the __getitem__ method for a subclass on a dictionary. Thanks in advance! From tjreedy at udel.edu Sun Nov 15 13:36:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 13:36:47 -0500 Subject: Stagnant Frame Data? In-Reply-To: References: Message-ID: Peter Otten wrote: > Mike wrote: > >> I'll apologize first for this somewhat lengthy example. It does >> however recreate the problem I've run into. This is stripped-down code >> from a much more meaningful system. >> >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate >> variables in their caller's namespace using the frame stack. As >> written, the output is not what is expected: the variables evaluate to >> "stagnant" values. >> >> However, if the one indicated line is uncommented, then the result is >> as expected. >> >> So my questions are: Is this a bug in Python? No. The existence and use of sys._getframe -- notice the leading underscore -- is a CPython implementation artifact. Use at your own risk. >> Is this an invalid use of frame data? Up to you to decide. >> Why does the single line "sys._getframe(1).f_locals" >> fix the behavior? It updates the dictionary. > A simplified demonstration of your problem: > >>>> def f(update): > ... a = locals() > ... x = 42 > ... if update: locals() > ... print a > ... >>>> f(False) > {'update': False} >>>> f(True) > {'a': {...}, 'x': 42, 'update': True} > > The local namespace is not a dictionary, and the locals()/f_locals > dictionary contains a snapshot of the local namespace. Accessing the > f_locals attribute is one way to trigger an update of that snapshot. > > What's puzzling is that the same dictionary is reused. Efficiency? Consistency? The doc for locals says "locals() Update and return a dictionary representing the current local symbol table." In class statements, where (currently) the local namespace *is* a dict, no update is needed and locals() simply returns the dict, the same one each time. Terry Jan Reedy From yoav.goldberg at gmail.com Sun Nov 15 13:40:53 2009 From: yoav.goldberg at gmail.com (Yoav Goldberg) Date: Sun, 15 Nov 2009 20:40:53 +0200 Subject: Python & Go In-Reply-To: References: <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Nov 15, 2009 at 4:00 AM, Terry Reedy wrote: > Yoav Goldberg wrote: > > >> On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy > tjreedy at udel.edu>> wrote: >> >> Paul Rubin wrote: >> >> Mark Chu-Carroll has a new post about Go: >> >> >> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> >> In a couple of minutes, I wrote his toy prime filter example in >> Python, mostly from the text rather than the code, which I can >> barely stand to read. It ran the first time without error. >> >> Yes, but the cool thing about the Go version is that it does each >> generator in a different thread, so in theory it could run twice as fast on >> a multi-core machine. >> > > Which is why I added, in my opinion, that "It would be much better, for > instance, to tweak Python, which it has had great success with, to better > run on multiple cores." > > For instance, add a new keyword 'go' such that > go def f(): yield 1 > runs the generator in a different thread, possibly on a different core. > > [...] > I see no reason why we cannot have that with Python. I not even sure we > cannot have it with CPython, but I am not familiar enough with threads, > processes, and CPython internals. > > > Yes, this could work, and would really cool. I believe you can go a long way with annotations, and maybe even provide a full working demo. So we can definitely have this in python, and it could be a really cool feature. Having it in CPython, though, is a different story altogether -- CPython way of handling threads is problematic, and not going to change soon, see here about the problem: http://blog.snaplogic.org/?p=94 and here about it no going away soon: http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock http://www.artima.com/weblogs/viewpost.jsp?thread=214235 So, yes, we could have this in python, but no I don't see it happening very soon.. And the compiled Go is really different in design than python -- easy to parse, easy to compile, static, works fast, etc. Different language. Is it a good thing to have a different language and not base yourself on an existing one? Not sure. But that's a different debate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Nov 15 13:50:43 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2009 10:50:43 -0800 Subject: Slicing history? Message-ID: Anyone remember or know why Python slices function like half-open intervals? I find it incredibly convenient myself, but an acquaintance familiar with other programming languages thinks it's bizarre and I'm wondering how it happened. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From nobody at nowhere.com Sun Nov 15 13:50:55 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 18:50:55 +0000 Subject: How to know if a file is a text file References: Message-ID: On Sun, 15 Nov 2009 04:34:10 -0800, Chris Rebert wrote: >>> I'm looking for a way to be able to load a generic file from the >>> system and understand if he is plain text. >>> The mimetype module has some nice methods, but for example it's not >>> working for file without extension. >>> >>> Any suggestion? >> >> You could use the "file" command. It's normally installed by default on >> Unix systems, but you can get a Windows version from: > > FWIW, IIRC the heuristic `file` uses to check whether a file is text > or not is whether it contains any null bytes; if it does, it > classifies it as binary (i.e. not text). "file" provides more granularity than that, recognising many specific formats, both text and binary. First, it uses "magic number" checks, checking for known signature bytes (e.g. "#!" or "JFIF") at the beginning of the file. If those checks fail it checks for common text encodings. If those also fail, it reports "data". Also, UTF-16-encoded text is recognised as text, even though it may contain a high proportion of NUL bytes. From nobody at nowhere.com Sun Nov 15 13:56:01 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 18:56:01 +0000 Subject: How to know if a file is a text file References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: On Sun, 15 Nov 2009 13:49:54 +0100, Luca wrote: > I was quite sure that this is not a very simple task. Right now search > only inside ASCII encode is not enough for me (my native language is > outside this encode :-) > Checking every single byte can be a good solution... > > I can start using the mimetype module and, if the file has no > extension, check byte one by one (commonly) as "file" command does. > Better: I can check use the "file" command if available. Another possible solution: Universal Encoding Detector Character encoding auto-detection in Python 2 and 3 http://chardet.feedparser.org/ From joncle at googlemail.com Sun Nov 15 14:01:49 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 11:01:49 -0800 (PST) Subject: Slicing history? References: Message-ID: On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > Anyone remember or know why Python slices function like half-open > intervals? ?I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > [on old computer technologies and programmers] ?"Fancy tail fins on a > brand new '59 Cadillac didn't mean throwing out a whole generation of > mechanics who started with model As." ?--Andrew Dalke Good ol' zero based indexing. It makes a lot more sense that range(len (my_list)) returns 'n' values which are valid indicies, otherwise they'd be a lot of IndexError's being raised. Besides, when you really want the full range (a corner case), it's a lot easier to do a +1, than to force people to write -1 for the vast majority of cases. Jon. From showell30 at yahoo.com Sun Nov 15 14:03:08 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:03:08 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <7dc79b2a-22e6-4d2f-8002-b3a6583030b1@13g2000prl.googlegroups.com> On Nov 14, 3:26?am, kj wrote: > One more thing: I found Rob Pike's mutterings on generics (towards > the end of his rollout video) rather offputting, because he gave > the impression that some important aspects of the language were > not even considered before major decisions for it were set in stone. > It looks like, if they ever get around to supporting generics, it > will be a late-in-the-day hack. > By "set in stone," do you mean "implemented"? Or have Rob Pike and friends literally put a redesign freeze on the language that was just released this month? From deets at nospam.web.de Sun Nov 15 14:03:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 20:03:48 +0100 Subject: IDE for python In-Reply-To: References: <7mar95F3g85n0U1@mid.uni-berlin.de> Message-ID: <7mb1kkF3h5cpfU1@mid.uni-berlin.de> Peng Yu schrieb: > On Nov 15, 11:15 am, "Diez B. Roggisch" wrote: >> Peng Yu schrieb: >> >>> There had been some discussion on IDE. But I'm not sure what pros and >>> cons of each choice. Current, I'm using vim and ctags. >>> Could somebody give some advices on choosing the best IDE for me? >>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> I suggest you use your google foo that you just showed to search in this >> group for the numerous discussions about emacs, vi, eclipse+pydev, wing >> ide, komodo and notepad. > > I see too many threads. But I don't any of them give me a complete > comparison between different choices. If you are familiar with > different choices, would you please give me some advices? > > http://groups.google.com/group/comp.lang.python/search?group=comp.lang.python&q=IDE&qt_g=Search+this+group Again: read the threads. They discuss the various aspects. They arose because of the same question asked as yours. If you don't find in them what you are looking for, chances are hight that you won't get it. This is very much a question of personal preferences, not of feature-matrices and strict metrics. So go, read, and them make an informed choice on what at least to try. Stick with what you prefer. And given your track record in this group here, I assume regardless of *what* beautiful scheme of explaining various IDEs and their respective merits, they all fall short of your "unique" way of doing things. Diez From deets at nospam.web.de Sun Nov 15 14:05:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 20:05:48 +0100 Subject: How to get directory of Python C library In-Reply-To: References: Message-ID: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > Hi > > I need to link against Python, is there a way to get the path to the > directory containing Python's C library (e.g., /libs on > Windows)? Most probably from the registry somehow. In general, try & locate a python-executable, and make it execute python -c "import sys; print sys.prefix" Capture that, and you're done. Depending on the OS, the libs then are placed in e.g. /lib. Diez From nobody at nowhere.com Sun Nov 15 14:19:01 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 19:19:01 +0000 Subject: Slicing history? References: Message-ID: On Sun, 15 Nov 2009 10:50:43 -0800, Aahz wrote: > Anyone remember or know why Python slices function like half-open > intervals? I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. How else would they function? Closed intervals? Using a closed interval (for just about anything) indicates that the designer has very limited programming experience. Anyone with a modicum of programming experience knows that half-open intervals are the norm, and that using closed intervals will confuse anyone else with a modicum of programming experience. That's aside from the objective merits, i.e. the fact that they can be used to partition an interval into subintervals without having to adjust the upper bound (which requires knowing how much to adjust the upper bound by, if that's even possible (for reals, it isn't)). From gherron at islandtraining.com Sun Nov 15 14:19:11 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 15 Nov 2009 11:19:11 -0800 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: Message-ID: <4B00542F.4030105@islandtraining.com> Steve Howell wrote: > I ran the following program, and found its output surprising in one > place: > > class OnlyAl: > def __getitem__(self, key): return 'al' > > class OnlyBob(dict): > def __getitem__(self, key): return 'bob' > > import sys; print sys.version > > al = OnlyAl() > bob = OnlyBob() > > print al['whatever'] > al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' > print al['whatever'] > > print bob['whatever'] > bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems > impossible' > print bob['whatever'] > > 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] > al > NEW AND IMPROVED AL! > bob > bob > It's the difference between old-style and new-style classes. Type dict and therefore OnlyBob are new style. OnlyAl defaults to old-style. If you derive OnlyAl from type object, you'll get consistent results. Gary Herron > In attempting to change the behavior for bob's dictionary lookup, I am > clearly doing something wrong, or maybe even impossible. > > Obviously the examples are contrived, but I am interested on a purely > academic level why setting __getitem__ on bob does not seem to change > the behavior of bob['foo']. Note that OnlyBob subclasses dict; > OnlyAl does not. > > On a more practical level, I will explain what I am trying to do. > Basically, I am trying to create some code that allows me to spy on > arbitrary objects in a test environment. I want to write a spy() > method that takes an arbitrary object and overrides its implementation > of __getitem__ and friends so that I can see how library code is > invoking the object (with print statements or whatever). Furthermore, > I want spy() to recursively spy on objects that get produced from my > original object. The particular use case is that I am creating a > context for Django templates, and I want to see which objects are > getting rendered, all the way down the tree. It would be pretty easy > to just create a subclass of the context method to spy at the top > level, but I want to recursively spy on all its children, and that is > why I need a monkeypatching approach. The original version had spy > recursively returning proxy/masquerade objects that intercepted > __getitem__ calls, but it becomes brittle when the proxy objects go > off into places like template filters, where I am not prepared to > intercept all calls to the object, and where in some cases it is > impossible to gain control. > > Although I am interested in comments on the general problems (spying > on objects, or spying on Django template rendering), I am most > interested in the specific mechanism for changing the __getitem__ > method for a subclass on a dictionary. Thanks in advance! > > From showell30 at yahoo.com Sun Nov 15 14:23:01 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:23:01 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: Message-ID: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> On Nov 15, 10:25?am, Steve Howell wrote: > [see original post...] > I am most > interested in the specific mechanism for changing the __getitem__ > method for a subclass on a dictionary. ?Thanks in advance! Sorry for replying to myself, but I just realized that the last statement in my original post was a little imprecise. I am more precisely looking for a way to change the behavior of foo ['bar'] (side effects and possibly return value) where "foo" is an instance of a class that subclasses "dict," and where "foo" is not created by me. The original post gives more context and example code that does not work as I expect/desire. From showell30 at yahoo.com Sun Nov 15 14:29:38 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:29:38 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: Message-ID: On Nov 15, 11:19?am, Gary Herron wrote: > Steve Howell wrote: > > I ran the following program, and found its output surprising in one > > place: > > > ? ? class OnlyAl: > > ? ? ? ? def __getitem__(self, key): return 'al' > > > ? ? class OnlyBob(dict): > > ? ? ? ? def __getitem__(self, key): return 'bob' > > > ? ? import sys; print sys.version > > > ? ? al = OnlyAl() > > ? ? bob = OnlyBob() > > > ? ? print al['whatever'] > > ? ? al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' > > ? ? print al['whatever'] > > > ? ? print bob['whatever'] > > ? ? bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems > > impossible' > > ? ? print bob['whatever'] > > > ? ? 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > > ? ? [GCC 4.3.3] > > ? ? al > > ? ? NEW AND IMPROVED AL! > > ? ? bobe > > ? ? bob > > It's the difference between old-style and new-style classes. ?Type dict > and therefore OnlyBob are new style. ?OnlyAl defaults to old-style. ?If > you derive OnlyAl from type object, you'll get consistent results. > Thanks, Gary. My problem is that I am actually looking for the behavior that the old-style OnlyAl provides, not OnlyBob--allowing me to override the behavior of al['foo'] and bob['foo']. I (hopefully) clarified my intent in a follow-up post that was sent before I saw your reply. Here it is re-posted for convenience of discussion: "I am more precisely looking for a way to change the behavior of foo ['bar'] (side effects and possibly return value) where "foo" is an instance of a class that subclasses "dict," and where "foo" is not created by me." From falk at mauve.rahul.net Sun Nov 15 14:33:10 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Sun, 15 Nov 2009 19:33:10 +0000 (UTC) Subject: python simply not scaleable enough for google? References: Message-ID: In article , Robert Brown wrote: > >It's hard to refute your assertion. You're claiming that some future >hypothetical Python implementation will have excellent performance via a JIT. >On top of that you say that you're willing to change the definition of the >Python language, say by adding type declarations, if an implementation with a >JIT doesn't pan out. If you change the Python language to address the >semantic problems Willem lists in his post and also add optional type >declarations, then Python becomes closer to Common Lisp, which we know can be >executed efficiently, within the same ballpark as C and Java. Ya know; without looking at Go, I'd bet that this was some of the thought process that was behind it. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From martin at v.loewis.de Sun Nov 15 14:35:23 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 20:35:23 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> Message-ID: <4B0057FB.3070504@v.loewis.de> > Still there remains the difference to what is told with the > Noddy_Type in the tutorial. Please report that to bugs.python.org. Regards, Martin From martin at v.loewis.de Sun Nov 15 14:36:10 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 20:36:10 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> Message-ID: <4B00582A.1030604@v.loewis.de> DreiJane wrote: > Thanks a second time - the picture has > gotten clearer indeed. But for third-party > readers the complexities of this matter > require the correction, that > > "Py_Type(&Foo_Type) = &PyType_Type" > > must be: > "Py_TYPE(&Foo_Type) = &PyType_Type " > > - or am i completely wrong ? Joost No, you are right - I forgot that the spelling had been changed to upper case. Regards, Martin From joncle at googlemail.com Sun Nov 15 15:01:00 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 12:01:00 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> Message-ID: <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> On Nov 15, 7:23?pm, Steve Howell wrote: > On Nov 15, 10:25?am, Steve Howell wrote: > > > [see original post...] > > I am most > > interested in the specific mechanism for changing the __getitem__ > > method for a subclass on a dictionary. ?Thanks in advance! > > Sorry for replying to myself, but I just realized that the last > statement in my original post was a little imprecise. > > I am more precisely looking for a way to change the behavior of foo > ['bar'] (side effects and possibly return value) where "foo" is an > instance of a class that subclasses "dict," and where "foo" is not > created by me. ?The original post gives more context and example code > that does not work as I expect/desire. [quote from http://docs.python.org/reference/datamodel.html] For instance, if a class defines a method named __getitem__(), and x is an instance of this class, then x[i] is roughly equivalent to x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) for new-style classes. [/quote] A quick hack could be: class Al(dict): def __getitem__(self, key): return self.spy(key) def spy(self, key): return 'Al' >>> a = Al() >>> a[3] 'Al' >>> a.spy = lambda key: 'test' >>> a[3] 'test' >>> b = Al() >>> b[3] 'Al' Seems to be what you're after anyway... hth, Jon. From http Sun Nov 15 15:01:57 2009 From: http (Paul Rubin) Date: 15 Nov 2009 12:01:57 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: <7xpr7jpney.fsf@ruckus.brouhaha.com> falk at mauve.rahul.net (Edward A. Falk) writes: > >If you change the Python language to address the semantic problems > >Willem lists in his post and also add optional type declarations, > >then Python becomes closer to Common Lisp, which we know can be > >executed efficiently, within the same ballpark as C and Java. > > Ya know; without looking at Go, I'd bet that this was some of the thought > process that was behind it. I don't have the slightest impression that Python had any significant influence on Go. Go has C-like syntax, static typing with mandatory declarations, and concurrency inspired by Occam. It seems to be a descendant of Oberon and Newsqueak (Pike's earlier language used in Plan 9). It also seems to be decades behind the times in some ways. Its creators are great programmers and system designers, but I wish they had gotten some PL theorists involved in designing Go. From showell30 at yahoo.com Sun Nov 15 15:09:21 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 12:09:21 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> Message-ID: <3b2918da-a5cd-47b6-9e3b-5ef6fc800b7c@t11g2000prh.googlegroups.com> On Nov 15, 12:01?pm, Jon Clements wrote: > On Nov 15, 7:23?pm, Steve Howell wrote: > > > I am more precisely looking for a way to change the behavior of foo > > ['bar'] (side effects and possibly return value) where "foo" is an > > instance of a class that subclasses "dict," and where "foo" is not > > created by me. ?The original post gives more context and example code > > that does not work as I expect/desire. > > [quote fromhttp://docs.python.org/reference/datamodel.html] > For instance, if a class defines a method named __getitem__(), and x > is an instance of this class, then x[i] is roughly equivalent to > x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) > for new-style classes. > [/quote] > > A quick hack could be: > > class Al(dict): > ? def __getitem__(self, key): > ? ? return self.spy(key) > ? def spy(self, key): > ? ? return 'Al' > > >>> a = Al() > >>> a[3] > 'Al' > >>> a.spy = lambda key: 'test' > >>> a[3] > 'test' > >>> b = Al() > >>> b[3] > > 'Al' > > Seems to be what you're after anyway... > This is very close to what I want, but the problem is that external code is defining Al, and I do not seem to be able to get this statement to have any effect: a.__getitem__ = lambda key: test How can I change the behavior of a['foo'] without redefining Al? From dickinsm at gmail.com Sun Nov 15 15:11:40 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 Nov 2009 12:11:40 -0800 (PST) Subject: Slicing history? References: Message-ID: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > Anyone remember or know why Python slices function like half-open > intervals? ?I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. Sounds like an excuse to post this Dijkstra link: http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF -- Mark From arve.knudsen at gmail.com Sun Nov 15 15:14:59 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 12:14:59 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> Message-ID: <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > Hi > > > I need to link against Python, is there a way to get the path to the > > directory containing Python's C library (e.g., /libs on > > Windows)? > > Most probably from the registry somehow. In general, try & locate a > python-executable, and make it execute > > ? python -c "import sys; print sys.prefix" > > Capture that, and you're done. Depending on the OS, the libs then are > placed in e.g. /lib. That doesn't solve anything, the hard part is figuring out the part after .. Arve From deets at nospam.web.de Sun Nov 15 15:24:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 21:24:01 +0100 Subject: How to get directory of Python C library In-Reply-To: <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> Message-ID: <7mb6b2F3h8d4pU1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >>> Hi >>> I need to link against Python, is there a way to get the path to the >>> directory containing Python's C library (e.g., /libs on >>> Windows)? >> Most probably from the registry somehow. In general, try & locate a >> python-executable, and make it execute >> >> python -c "import sys; print sys.prefix" >> >> Capture that, and you're done. Depending on the OS, the libs then are >> placed in e.g. /lib. > > That doesn't solve anything, the hard part is figuring out the part > after .. AFAIK is that only varying based on the OS. Under unix, it's /lib/python/ You can get the platform via sys.platform. Diez From showell30 at yahoo.com Sun Nov 15 15:40:44 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 12:40:44 -0800 (PST) Subject: Slicing history? References: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> Message-ID: <07a7b5ef-4993-47c8-92e9-3a8ed3a35625@o9g2000prg.googlegroups.com> On Nov 15, 12:11?pm, Mark Dickinson wrote: > On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > > > Anyone remember or know why Python slices function like half-open > > intervals? ?I find it incredibly convenient myself, but an acquaintance > > familiar with other programming languages thinks it's bizarre and I'm > > wondering how it happened. > > Sounds like an excuse to post this Dijkstra link: > > http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF > That is really good stuff! Like Aahz I have Python's slicing mechanism (and zero-based indexing) burnt into my brain, but I never had a good way to explain why it makes sense, other than just an intuitive notion that it works for me. It is interesting how the link actually seems to explain zero-based indexing as a consequence of the slicing approach, not a cause. I always understood zero-based indexing as a relic of memory management, which was fine, but I guess the reasons go deeper than that. From arve.knudsen at gmail.com Sun Nov 15 16:08:22 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 13:08:22 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> Message-ID: On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> Hi > >>> I need to link against Python, is there a way to get the path to the > >>> directory containing Python's C library (e.g., /libs on > >>> Windows)? > >> Most probably from the registry somehow. In general, try & locate a > >> python-executable, and make it execute > > >> ? python -c "import sys; print sys.prefix" > > >> Capture that, and you're done. Depending on the OS, the libs then are > >> placed in e.g. /lib. > > > That doesn't solve anything, the hard part is figuring out the part > > after .. > > AFAIK is that only varying based on the OS. Under unix, it's > > ? /lib/python/ > > You can get the platform via sys.platform. Well, my point is that I should like a way to query for this directory, just as I can query distutils.sysconfig for the include directory and Python library (i.e., the standard Python library) directory. It's not trivial to figure out Python's installation scheme so long as it's not written in stone .. Arve From deets at nospam.web.de Sun Nov 15 16:11:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 22:11:38 +0100 Subject: How to get directory of Python C library In-Reply-To: References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> Message-ID: <7mb94aF3f97c1U1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 21:24, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >> >> >> >> >>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >>>> arve.knud... at gmail.com schrieb: >>>>> Hi >>>>> I need to link against Python, is there a way to get the path to the >>>>> directory containing Python's C library (e.g., /libs on >>>>> Windows)? >>>> Most probably from the registry somehow. In general, try & locate a >>>> python-executable, and make it execute >>>> python -c "import sys; print sys.prefix" >>>> Capture that, and you're done. Depending on the OS, the libs then are >>>> placed in e.g. /lib. >>> That doesn't solve anything, the hard part is figuring out the part >>> after .. >> AFAIK is that only varying based on the OS. Under unix, it's >> >> /lib/python/ >> >> You can get the platform via sys.platform. > > Well, my point is that I should like a way to query for this > directory, just as I can query distutils.sysconfig for the include > directory and Python library (i.e., the standard Python library) > directory. It's not trivial to figure out Python's installation scheme > so long as it's not written in stone .. Well, than how about you word your question like that? But there is no simple function to call. So the answer to the question you asked is: no. I showed you a way that works for current python, and consists of stitching together a number of informations. Diez From aahz at pythoncraft.com Sun Nov 15 17:06:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2009 14:06:47 -0800 Subject: Slicing history? References: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> Message-ID: In article <667394cb-d505-4906-8c6b-ab2d361b3a4d at j24g2000yqa.googlegroups.com>, Mark Dickinson wrote: >On Nov 15, 6:50=A0pm, a... at pythoncraft.com (Aahz) wrote: >> >> Anyone remember or know why Python slices function like half-open >> intervals? =A0I find it incredibly convenient myself, but an acquaintance >> familiar with other programming languages thinks it's bizarre and I'm >> wondering how it happened. > >Sounds like an excuse to post this Dijkstra link: > >http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF Many thanks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 baptiste.lepilleur at gmail.com Sun Nov 15 17:12:53 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sun, 15 Nov 2009 23:12:53 +0100 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <7m6nclF3gnlqfU1@mid.individual.net> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> <7m6nclF3gnlqfU1@mid.individual.net> Message-ID: I think you can use python itself for "pre-processing". Here is an (shortened) example from PyPy RPython paper: # operators: the docstrings contain the # symbol associated with each operator class Op_Add(BinaryExpr): ?+? class Op_Sub(BinaryExpr): ?-? # INIT-TIME only: build the table of # opcodes and add the ?eval? methods def gen_eval(ch): code = """ def eval(self): return self.l.eval() %s self.r.eval() """ d = {} exec code.strip() % (ch) in d return d['eval'] OPCODES = {} def build_opcodes(): for name, value in globals().items(): if name.startswith(?Op_?): value.eval = gen_eval(value.__doc__) OPCODES[value.__doc__] = value build_opcodes() >From the paper: """ The eval method is generated via a call to the helper routine gen_eval, which creates a string of Python code that performs the desired computation and uses exec to compile this string into a Python method. Adding the class object to the OPCODES dictionary is done by simple assignment, using the class docstring as the key and the class object itself as the value. """ You might also want to have a look at PyGirl, the Nintendo Gameboy emulator of the PyPy project written in RPython (a subset of Python that allow static type inference). There is probably some ideas to borrow. The paper on PyGirl also details some of the "pre-processing" trick they used. They sometime call it meta-programming but its all the same, generating code with code :). See http://codespeak.net/pypy/dist/pypy/doc/extradoc.html for more info and look-up the rpython and pygirl docs. 2009/11/14 greg > Santiago Romero wrote: > > Can the above be easily done with another already-existing >> application? (example: can m4 do this job)? >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arve.knudsen at gmail.com Sun Nov 15 17:50:54 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 14:50:54 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> Message-ID: <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> On 15 Nov, 22:11, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >>>> arve.knud... at gmail.com schrieb: > >>>>> Hi > >>>>> I need to link against Python, is there a way to get the path to the > >>>>> directory containing Python's C library (e.g., /libs on > >>>>> Windows)? > >>>> Most probably from the registry somehow. In general, try & locate a > >>>> python-executable, and make it execute > >>>> ? python -c "import sys; print sys.prefix" > >>>> Capture that, and you're done. Depending on the OS, the libs then are > >>>> placed in e.g. /lib. > >>> That doesn't solve anything, the hard part is figuring out the part > >>> after .. > >> AFAIK is that only varying based on the OS. Under unix, it's > > >> ? /lib/python/ > > >> You can get the platform via sys.platform. > > > Well, my point is that I should like a way to query for this > > directory, just as I can query distutils.sysconfig for the include > > directory and Python library (i.e., the standard Python library) > > directory. It's not trivial to figure out Python's installation scheme > > so long as it's not written in stone .. > > Well, than how about you word your question like that? But there is no > simple function to call. So the answer to the question you asked is: no. > > I showed you a way that works for current python, and consists of > stitching together a number of informations. > > Diez My original question was pretty clear I think. And I don't have the required information to deduce what the library path may look like on any given platform, there really should be a standard function for this. Arve From showell30 at yahoo.com Sun Nov 15 17:52:54 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 14:52:54 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> Message-ID: <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> On Nov 15, 12:01?pm, Jon Clements wrote: > On Nov 15, 7:23?pm, Steve Howell wrote: > > > On Nov 15, 10:25?am, Steve Howell wrote: > > > > [see original post...] > > > I am most > > > interested in the specific mechanism for changing the __getitem__ > > > method for a subclass on a dictionary. ?Thanks in advance! > > > Sorry for replying to myself, but I just realized that the last > > statement in my original post was a little imprecise. > > > I am more precisely looking for a way to change the behavior of foo > > ['bar'] (side effects and possibly return value) where "foo" is an > > instance of a class that subclasses "dict," and where "foo" is not > > created by me. ?The original post gives more context and example code > > that does not work as I expect/desire. > > [quote fromhttp://docs.python.org/reference/datamodel.html] > For instance, if a class defines a method named __getitem__(), and x > is an instance of this class, then x[i] is roughly equivalent to > x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) > for new-style classes. > [/quote] > Ok, thanks to Jon and Gary pointing me in the right direction, I think I can provide an elaborate answer my own question now. Given an already instantiated instance foo of Foo where Foo subclasses dict, you cannot change the general behavior of calls of the form foo [bar]. (Obviously you can change the behavior for specific examples of bar after instantiation by setting foo['apple'] and foo['banana'] as needed, but that's not what I mean.) This may be surprising to naive programmers like myself, given that is possible to change the behavior of foo.bar() after instantiation by simply saying "foo.bar = some_method". Also, with old-style classes, you can change the behavior of foo[bar] by setting foo.__getitem__. Even in new-style classes, you can change the behavior of foo.__getitem__(bar) by saying foo.__getitem__ = some_method, but it is a pointless exercise, since foo.__getitem__ will have no bearing on the processing of "foo[bar]." Finally, you can define __getitem__ on the Foo class itself to change how foo[bar] gets resolved, presumably even after instantiation of foo itself (but this does not allow for instance-specific behavior). Here is the difference: foo.value looks for a definition of value on the instance before looking in the class hierarchy foo[bar] can find __getitem__ on foo before looking at Foo and its superclasses, if Foo is old-style foo[bar] will only look for __getitem__ in the class hierarchy if Foo derives from a new-style class Does anybody have any links that points to the rationale for ignoring instance definitions of __getitem__ when new-style classes are involved? I assume it has something to do with performance or protecting us from our own mistakes? So now I am still in search of a way to hook into calls to foo[bar] after foo has been instantiated. It is all test code, so I am not particularly concerned about safety or future compatibility. I can do something really gross like monkeypatch Foo class instead of foo instance and keep track of the ids to decide when to override behavior, but there must be a simpler way to do this. From deets at nospam.web.de Sun Nov 15 17:59:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 23:59:04 +0100 Subject: How to get directory of Python C library In-Reply-To: <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> Message-ID: <7mbfdpF3hr2s9U1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 22:11, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >> >> >> >> >>> On 15 Nov, 21:24, "Diez B. Roggisch" wrote: >>>> arve.knud... at gmail.com schrieb: >>>>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >>>>>> arve.knud... at gmail.com schrieb: >>>>>>> Hi >>>>>>> I need to link against Python, is there a way to get the path to the >>>>>>> directory containing Python's C library (e.g., /libs on >>>>>>> Windows)? >>>>>> Most probably from the registry somehow. In general, try & locate a >>>>>> python-executable, and make it execute >>>>>> python -c "import sys; print sys.prefix" >>>>>> Capture that, and you're done. Depending on the OS, the libs then are >>>>>> placed in e.g. /lib. >>>>> That doesn't solve anything, the hard part is figuring out the part >>>>> after .. >>>> AFAIK is that only varying based on the OS. Under unix, it's >>>> /lib/python/ >>>> You can get the platform via sys.platform. >>> Well, my point is that I should like a way to query for this >>> directory, just as I can query distutils.sysconfig for the include >>> directory and Python library (i.e., the standard Python library) >>> directory. It's not trivial to figure out Python's installation scheme >>> so long as it's not written in stone .. >> Well, than how about you word your question like that? But there is no >> simple function to call. So the answer to the question you asked is: no. >> >> I showed you a way that works for current python, and consists of >> stitching together a number of informations. >> >> Diez > > My original question was pretty clear I think. And I don't have the > required information to deduce what the library path may look like on > any given platform, there really should be a standard function for > this. I at least misunderstood it - which might be my fault. However, as there is no such function. I suggest you discuss this on the devel-list - however, anything before python2.7 is unlikely to grow such a function, so you are stuck with the ways I described. Diez From arve.knudsen at gmail.com Sun Nov 15 18:23:10 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 15:23:10 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> <7mbfdpF3hr2s9U1@mid.uni-berlin.de> Message-ID: <63acc587-3575-4db1-a142-5783dda694eb@d5g2000yqm.googlegroups.com> On 15 Nov, 23:59, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 22:11, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > >>>> arve.knud... at gmail.com schrieb: > >>>>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >>>>>> arve.knud... at gmail.com schrieb: > >>>>>>> Hi > >>>>>>> I need to link against Python, is there a way to get the path to the > >>>>>>> directory containing Python's C library (e.g., /libs on > >>>>>>> Windows)? > >>>>>> Most probably from the registry somehow. In general, try & locate a > >>>>>> python-executable, and make it execute > >>>>>> ? python -c "import sys; print sys.prefix" > >>>>>> Capture that, and you're done. Depending on the OS, the libs then are > >>>>>> placed in e.g. /lib. > >>>>> That doesn't solve anything, the hard part is figuring out the part > >>>>> after .. > >>>> AFAIK is that only varying based on the OS. Under unix, it's > >>>> ? /lib/python/ > >>>> You can get the platform via sys.platform. > >>> Well, my point is that I should like a way to query for this > >>> directory, just as I can query distutils.sysconfig for the include > >>> directory and Python library (i.e., the standard Python library) > >>> directory. It's not trivial to figure out Python's installation scheme > >>> so long as it's not written in stone .. > >> Well, than how about you word your question like that? But there is no > >> simple function to call. So the answer to the question you asked is: no. > > >> I showed you a way that works for current python, and consists of > >> stitching together a number of informations. > > >> Diez > > > My original question was pretty clear I think. And I don't have the > > required information to deduce what the library path may look like on > > any given platform, there really should be a standard function for > > this. > > I at least misunderstood it - which might be my fault. However, as there > is no such function. I suggest you discuss this on the devel-list - > however, anything before python2.7 is unlikely to grow such a function, > so you are stuck with the ways I described. > > Diez OK, thanks. Perhaps I'll try distutils-sig, given that it looks natural to extend distutils.sysconfig. Arve From rt8396 at gmail.com Sun Nov 15 18:30:23 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 15:30:23 -0800 (PST) Subject: ANN: PyGUI 2.1 References: Message-ID: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> OK this is my third attempt, someone please email me if these messages are getting through. I mailed this only to c.l.py and not the announce group this time, that may have been my previous problems??? Here we go... Hello Greg, I have looked over this kit in the past and it looks quite promising for meeting it stated goals (and mine). One the the best things about it (for me anyway) is the small size and the fact you have an OpenGL widget! I think all GUI kits should support OpenGL out of the box! This is the 21st century as we all know. Also these stated goals are what every GUI package should aspire to. (Hope you don't mind me quoting your site??) """ Develop a GUI API that is designed specifically for Python, taking advantage of Python's unique language features and working smoothly with Python's data types. Provide implementations of the API for the three major platforms (Unix, Macintosh and Windows) that are small and lightweight, interposing as little code as possible between the Python application and the platform's underlying GUI facilities, and not bloating the Python installations or applications which use them. """ I really like this! """ Document the API purely in Python terms, so that the programmer does not need to read the documentation for another GUI library, in terms of another language, and translate into Python. """ This is *so* important for any GUI. wxPython IMO lacks greatly in this department. I very much wish we had docs for wxPython as we do for Tkinter. But even Tkinter needs more details! You should never need to consult the TCL/TK doc's unless you are doing something really advanced. (or evil!) """ Get the library and its documentation included in the core Python distribution, so that truly cross-platform GUI applications may be written that will run on any Python installation, anywhere. """ This i also agree with! While we currently have Tkinter in Python we lack the real docs "in Python" for Tkinter. There are a few very good sites (effbot, NMT, and others) but users must bounce around from site to site to find all this. I want visit one place for a reference and one place only. Tuts can exist on the web. And by "reference" look at this site to see what i mean http://infohost.nmt.edu/tcc/help/pubs/tkinter/ I actually like Tkinter (because of "ease of use") however!, having an embedded TCL interpretor and wrapping TK calls with Python just seems wrong, and Tkinter is notoriously slow (probably due to this fact) as we all know. But after looking over your pyGUI it does "seem" that Tkinter has a richer widget set. (i could be wrong) What are the comparisons between Tkinter and PyGUI. I would love to use a kit that is lighter weight and has better cross platform abilities (and a glWidget to boot!), but i can't sacrifice the widget set. Can you give us a pros and cons of pyGUI versus Tkinter? This will help me decide and i think many others would benefit also. Here is the main widgets of Tkinter: -Entry -Label -Button -RadioButton -CheckButton -Frame -LabelFrame -Text -Listbox -Scrollbar -Scale -Toplevel -Canvas (2d) -Menu -MenuButton -OptionMenu -PanedWindow -Spinbox Easy to use dialogs from: -tkFileDialog -tkSimpleDialog -tkMessageBox Thanks From db3l.net at gmail.com Sun Nov 15 18:42:38 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 15 Nov 2009 18:42:38 -0500 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: Terry Reedy writes: > r wrote: >> On Nov 14, 4:59 am, kj wrote: >>> But, as I already showed, I'm out of my depth here, >>> so I'd better shut up. >> >> Don't give up so easy! The idea is great, what Paul is saying is that >> most people who read this group use newsreaders and that has nothing >> to do with google groups. These guy's have kill filters for just this >> sort of thing but either way the emails are on their puters so they >> have to deal with them on an individual basis. It would be nice >> however to clean up the Google group version and rid it of the plagues >> of spam infestations. > > Anyone with a newsreader can, like me, read gmane.comp.python.general, > which mirrors python-list, which now filters out much/most of the spam > on c.l.p from G.g. The same is true on some (not sure if it qualifies for many) Usenet servers. I use news.individual.net for example (for a modest yearly fee as of a few years ago) and in my experience it does a great job at filtering spam. I'm sure there are other services that do as well. I don't have to manage any special filters and don't seem to see any of the stuff in this group, for example, mentioned in this thread. I do use gmane for a lot of other lists (including python-dev) that aren't operated as a Usenet newsgroups and it's an excellent service. -- David From lists at cheimes.de Sun Nov 15 19:03:13 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 16 Nov 2009 01:03:13 +0100 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: Steve Howell wrote: > Does anybody have any links that points to the rationale for ignoring > instance definitions of __getitem__ when new-style classes are > involved? I assume it has something to do with performance or > protecting us from our own mistakes? Most magic methods are implemented as descriptors. Descriptors only looked up on the type to increase the performance of the interpreter and to simply the C API. The same is true for other descriptors like properties. The interpreter invokes egg.__getitem__(arg) as type(egg).__getitem__(egg, arg). > So now I am still in search of a way to hook into calls to foo[bar] > after foo has been instantiated. It is all test code, so I am not > particularly concerned about safety or future compatibility. I can do > something really gross like monkeypatch Foo class instead of foo > instance and keep track of the ids to decide when to override > behavior, but there must be a simpler way to do this. Try this untested code: class Spam(dict): def __getitem__(self, key): getitem = self.__dict__.get("__getitem__", dict.__getitem__) return getitem(self, key) Because dict is the most important and speed critical type in Python it has some special behaviors. If you are going to overwrite __getitem__ of a dict subclass then you have to overwrite all methods that call __getitem__, too. These are get, pop, update and setdefault. Christian From wentland at cl.uni-heidelberg.de Sun Nov 15 19:11:42 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 16 Nov 2009 01:11:42 +0100 Subject: How can pip install a GitHub code drop? In-Reply-To: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> References: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> Message-ID: <20091116001142.GC9776@kinakuta.local> On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote: > How can I point pip at the repo to install the library? > sudo pip -e git+git://github.com/Phlip/Kozmiq.git Make that: pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq and (preferably) don't install into system paths ;-) kind regards Wolodja -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From sungsuha at gmail.com Sun Nov 15 19:17:31 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 16:17:31 -0800 (PST) Subject: basic class question.. References: Message-ID: On 11?15?, ??10?15?, Tim Chase wrote: > Pyrot wrote: > > class rawDNA: > > import string > > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > > self.template = template //shouldn't this make "template" > > accessible within the scope of "rawDNA"?? > > No. Python's scope resolution consists only of "local, global, > or explicit". There is no "try to find this in the instance or > class" scope-resolution guessing. Your code makes "template" > accessible within the scope of "self", not in a global > unqualified scope. > > So this: > > > def noncoding(self): > > print template.translate(trans) // > > tries to reference "template" first in the local scope (within > noncoding(), but it doesn't exist there), then in the global > scope (it also doesn't exist there), and stops. > > It should be as you have it here: > > > class rawDNA: > > import string > > trans = string.maketrans("GATC","CTAG") > > def __init__(self, template = "GATTACA"): > > self.template = template > > def noncoding(self): > > print self.template.translate(trans) > > Here, you start with "self" which *is* in the local scope, which > *does* contain "template" and so it successfully finds it and all > is [qualifiedly] good. However, you'll also find that "trans" > isn't found because it's neither in the local nor global scope: > > >>> class RawDNA: > ... import string > ... trans = string.maketrans("GATC", "CTAG") > ... def __init__(self, template="GATTACA"): > ... self.template = template > ... def noncoding(self): > ... print self.template.translate(trans) > ... > >>> r = RawDNA() > >>> r.noncoding() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in noncoding > NameError: global name 'trans' is not defined > > so you need to fully qualify it as "RawDNA.trans" for Python to > find it. (I also shifted to using the PEP-8 naming convention > "RawDNA" instead of "rawDNA"). > > Which you indeed discovered: > > > this works as intended. > > Being explicit is part of "Python Zen" (from the python > command-prompt, type "import this" to see the whole list) > > -tkc thanks! one last question, is "self.template.translate(trans)" the right way to go(pythonic?)? I found it to be cumbersome(and a mouthful) and thought I might have been doing it wrong :-) From python at mrabarnett.plus.com Sun Nov 15 19:24:19 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 00:24:19 +0000 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <4B009BB3.90805@mrabarnett.plus.com> Christian Heimes wrote: > Steve Howell wrote: >> Does anybody have any links that points to the rationale for ignoring >> instance definitions of __getitem__ when new-style classes are >> involved? I assume it has something to do with performance or >> protecting us from our own mistakes? > > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. The same is true for other descriptors like > properties. The interpreter invokes egg.__getitem__(arg) as > type(egg).__getitem__(egg, arg). > >> So now I am still in search of a way to hook into calls to foo[bar] >> after foo has been instantiated. It is all test code, so I am not >> particularly concerned about safety or future compatibility. I can do >> something really gross like monkeypatch Foo class instead of foo >> instance and keep track of the ids to decide when to override >> behavior, but there must be a simpler way to do this. > > Try this untested code: > > class Spam(dict): > def __getitem__(self, key): > getitem = self.__dict__.get("__getitem__", dict.__getitem__) > return getitem(self, key) > > Because dict is the most important and speed critical type in Python it > has some special behaviors. If you are going to overwrite __getitem__ of > a dict subclass then you have to overwrite all methods that call > __getitem__, too. These are get, pop, update and setdefault. > I wonder whether it's possible to define 2 behaviours, an optimised one for instances of a class and another non-optimised one for instances of a subclasses. That would make it easier to subclass built-in classes without losing their speed. From sungsuha at gmail.com Sun Nov 15 19:26:59 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 16:26:59 -0800 (PST) Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> Message-ID: <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> On 11?15?, ??9?52?, "Diez B. Roggisch" wrote: > Pyrot schrieb: > > > class rawDNA: > > ? ?import string > > Importing here is unusual. Unless you have good reasons to do so, I > suggest you put the imports on top of the file. > > > ? ?trans = string.maketrans("GATC","CTAG") > > > ? ?def __init__(self, template = "GATTACA"): > > ? ? ? ? ? ?self.template = template ?//shouldn't this make "template" > > accessible within the scope of "rawDNA"?? > > No. > > > > > ? ?def noncoding(self): > > ? ? ? ? ? ?print template.translate(trans) ?// > > This needs to be > > ? ?print self.template.translate(trans) > > Thes scopes insied a class are only the method-locals (to which the > parameters count of course), and globals. > > Diez Thanks for the tip Diez. (Tthe core reason that I'm bothering with this at all is because I heard imports are costly(in time, space, processing power). If this turns out to be a non-issue, than my questions regarding Imports are all moot :->) I forgot to write about my second question which was: what happens when I use the import statement within a class/function declaration? I'm thinking either 1) It imports during the class/function declaration 2) It imports the first time a class/function call(x = rawDNA() ) occurs But if it's 2) then is the import valid outside of the function/class? what happens when the last function reference is removed?(del x) obviously this is a lot of questions... I respect your(or anyone who would like to help me) time, so all I ask is some kind of document or "Best practices" guide dealing all about "import".(because sadly, http://docs.python.org/reference/simple_stmts.html#the-import-statement does not ask my questions) From wentland at cl.uni-heidelberg.de Sun Nov 15 19:39:39 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 16 Nov 2009 01:39:39 +0100 Subject: How can pip install a GitHub code drop? In-Reply-To: <20091116001142.GC9776@kinakuta.local> References: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> <20091116001142.GC9776@kinakuta.local> Message-ID: <20091116003939.GD9776@kinakuta.local> On Mon, Nov 16, 2009 at 01:11 +0100, Wolodja Wentland wrote: > On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote: > > How can I point pip at the repo to install the library? > > sudo pip -e git+git://github.com/Phlip/Kozmiq.git > pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq err... pip install -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq ^^^^^^^ ^^^^^^^^^^^ Hope it works -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From showell30 at yahoo.com Sun Nov 15 19:58:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 16:58:43 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <35243ea1-60c6-4bb6-afba-7673a060768a@g1g2000pra.googlegroups.com> On Nov 15, 4:03?pm, Christian Heimes wrote: > Steve Howell wrote: > > Does anybody have any links that points to the rationale for ignoring > > instance definitions of __getitem__ when new-style classes are > > involved? ?I assume it has something to do with performance or > > protecting us from our own mistakes? > > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. The same is true for other descriptors like > properties. The interpreter invokes egg.__getitem__(arg) as > type(egg).__getitem__(egg, arg). > Is the justification along performance lines documented anywhere? > > So now I am still in search of a way to hook into calls to foo[bar] > > after foo has been instantiated. ?It is all test code, so I am not > > particularly concerned about safety or future compatibility. ?I can do > > something really gross like monkeypatch Foo class instead of foo > > instance and keep track of the ids to decide when to override > > behavior, but there must be a simpler way to do this. > > Try this untested code: > > class Spam(dict): > ? ? def __getitem__(self, key): > ? ? ? ? getitem = self.__dict__.get("__getitem__", dict.__getitem__) > ? ? ? ? return getitem(self, key) > [...] Not sure how this helps me, unless I am misunderstanding... It is the futility of writing lowercase_spam.__getitem__ that is setting me back. For my use case I do not want to override __getitem__ for all Spam objects, nor do I even have the option to modify the Spam class in some cases. From missive at hotmail.com Sun Nov 15 20:20:32 2009 From: missive at hotmail.com (Lee Harr) Date: Mon, 16 Nov 2009 05:50:32 +0430 Subject: [ANNC] acromania-0.5 Message-ID: Acromania is a word game of acronyms. This program is a computer moderator for networked games of acromania. It can connect to a channel on IRC, or start a standalone server which can be accessed much like a MUD. http://acromania.googlecode.com/ Acromania uses Twisted and SQLite. Optionally, it can use NLTK to generate computer opponents. Acromania is released under GPLv3. Changes in acromania-0.5: ??? - add versioning for database ??? - make building and loading bots more resilient ??? - sort score report ??? - add info command for in-game contact information ??? - allow listing top10 acros per player ??? - make leaderboard and top10 more resilient when empty ??? - improve color usage ??? - allow user to change password ??? - add admin user account ??? - allow admin user to change any user's password Notes: ??? I have only played the game using the standalone ??? server on a secure network. If you have experience ??? with programming IRC bots securely, please take ??? a look and contact me if you see any problems. ??? If you decide to connect it to IRC, please let me ??? know, because I'd like to play :o) _________________________________________________________________ Windows Live: Make it easier for your friends to see what you?re up to on Facebook. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009 From gagsl-py2 at yahoo.com.ar Sun Nov 15 20:35:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 22:35:14 -0300 Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Message-ID: En Sun, 15 Nov 2009 09:04:06 -0300, vsoler escribi?: > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > been saving my > *.py files in the C:\Program Files\Python26 directory, which is the > default directory for such files in my system. > > However, I have realised that the above is not the best practice. > Therefore I created the C:\Program Files\Python26\test directory and I > want it to be my default directory for saving *.py files, importing > modules, etc. This is *not* a good place either. Non-privileged users should not have write permission in the C:\Program Files directory. > I'd like to do something like the DOS equivalent of "CD test" but I > do not know kow to do it. > > I am currently doing something really awful: I open a *.py file in the > test subdirectory, I run it with the F5 key and it works! but I am > doing really something stupid. "it works!" What's the problem then? > How should I proceed, if I want to proceed properly? Sorry but I don't even see your problem. You can save your .py files anywhere you like... -- Gabriel Genellina From showell30 at yahoo.com Sun Nov 15 20:35:53 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 17:35:53 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <35243ea1-60c6-4bb6-afba-7673a060768a@g1g2000pra.googlegroups.com> Message-ID: <77cf9e89-0e99-405c-ad3b-fea6e916cef7@j9g2000prh.googlegroups.com> On Nov 15, 4:58?pm, Steve Howell wrote: > On Nov 15, 4:03?pm, Christian Heimes wrote: > > > Try this untested code: > > > class Spam(dict): > > ? ? def __getitem__(self, key): > > ? ? ? ? getitem = self.__dict__.get("__getitem__", dict.__getitem__) > > ? ? ? ? return getitem(self, key) > > [...] > > [I originally responded...] Not sure how this helps me, unless I am misunderstanding... > Ok, now I get where you were going with the idea. The following code runs as expected. Even in pure testing mode, I would want to make it a little more robust, but it illustrates the basic idea that you can monitor just particular objects by overriding the class method to look for an attribute on the instance before doing any special processing. class MyDict(dict): pass dict1 = MyDict() dict1['foo'] = 'bar' dict2 = MyDict() dict2['spam'] = 'eggs' dict3 = MyDict() dict3['BDFL'] = 'GvR' def spy(dict): def mygetitem(self, key): if hasattr(self, '__SPYING__'): value = self.__class__.__old_getitem__(self, key) print 'derefing %s to %s on %s' % (key, value, self) return value if not hasattr(dict.__class__, '__HOOKED__'): setattr(dict.__class__, '__old_getitem__', dict.__class__.__getitem__) setattr(dict.__class__, '__getitem__', mygetitem) setattr(dict.__class__, '__HOOKED__', True) dict.__SPYING__ = True dict1['foo'] # not spied yet spy(dict1) # this changes class and instance dict1['foo'] # spied dict2['spam'] # not spied spy(dict3) # this only changes instance dict3['BDFL'] # spied dict2['spam'] # spied Thanks, Christian! From gagsl-py2 at yahoo.com.ar Sun Nov 15 21:56:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 23:56:18 -0300 Subject: tkFileDialog question References: Message-ID: En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell escribi?: > answer = tkFileDialog.askdirectory() > > if answer is not '': > #do stuff Although it "reads well", this is *wrong*. You want != here, not the `is not` operator. if answer != '': ... If you want to compare the *values* of two objects, to see if they are equal or not, use == or !=. If you want to compare *identity*, to see if two results refer to the very same object or not, use `is` or `is not` (In your example, it *may* appear to work, because CPython optimizes very short strings like 'a' or '', but you should not rely on this optimization) -- Gabriel Genellina From rt8396 at gmail.com Sun Nov 15 22:27:38 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 19:27:38 -0800 (PST) Subject: tkFileDialog question References: Message-ID: On Nov 15, 8:56?pm, "Gabriel Genellina" wrote: > En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell ? > escribi?: > > > answer = tkFileDialog.askdirectory() > > > if answer is not '': > > ? ?#do stuff > > Although it "reads well", this is *wrong*. You want != here, not the `is ? > not` operator. > > if answer != '': ... > > If you want to compare the *values* of two objects, to see if they are ? > equal or not, use == or !=. > If you want to compare *identity*, to see if two results refer to the very ? > same object or not, use `is` or `is not` Actually "Gabe" your right and wrong.. the pythonic way to check for True/False is.. path = tkFileDialog.askwhatever() if path: #do something here NOT if path != '': #do something here Both work equally but the first is more Pythonic! UNLESS you are specifically testing for anything but the empty string that is. In that case your way *is* correct. But that is not the case with a file dialog return value. Yes the dialog returns either an empty string OR a valid path but True False is all that matters here when deciding whether to act on that path -- or not act on it. NOT whether or not it is an empty string. From sturlamolden at yahoo.no Sun Nov 15 22:29:08 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:29:08 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> <7man75F3gh0lgU1@mid.individual.net> Message-ID: <75d106a6-c2a1-4640-90d9-510864bd2fd1@b15g2000yqd.googlegroups.com> On 15 Nov, 17:05, Dietmar Schwertberger wrote: > > Could you send me an .fbp file demonstrating the error? > > Sent by email. Did you receive it? No... could you please resend to sturla at molden.no? From sturlamolden at yahoo.no Sun Nov 15 22:32:25 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:32:25 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> <7man75F3gh0lgU1@mid.individual.net> Message-ID: <13e60e57-3e67-402e-9182-5ae13b5ec46f@b15g2000yqd.googlegroups.com> On 15 Nov, 17:05, Dietmar Schwertberger wrote: > Sent by email. Did you receive it? > Yes I did, thank you :) (I thought I didn't, but it was just a problem with my e-mail filter.) From sturlamolden at yahoo.no Sun Nov 15 22:42:40 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:42:40 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> On 14 Nov, 15:35, Dietmar Schwertberger wrote: > ? ?self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) > ? ?self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", > wx.DefaultPosition, wx.DefaultSize, 0 ) > ? ?m_toolBar1.AddControl( m_button1 ) I can confirm this. There seems to be a bug in the generation of Python code for wxToolBar. From nagle at animats.com Sun Nov 15 23:09:44 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Nov 2009 20:09:44 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> Message-ID: <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Paul Boddie wrote: > On 15 Nov, 09:30, Terry Reedy wrote: >> greg wrote: >> > > [Shed Skin] > >>> These restrictions mean that it isn't really quite >>> Python, though. >> Python code that only uses a subset of features very much *is* Python >> code. The author of ShedSkin makes no claim that is compiles all Python >> code. > > Of course, Shed Skin doesn't support all the usual CPython features, > but the code you would write for Shed Skin's benefit should be Python > code that runs under CPython. It's fair to say that Shed Skin isn't a > "complete" implementation of what CPython defines as being "the full > Python", but you're still writing Python. One can argue that the > restrictions imposed by Shed Skin inhibit the code from being "proper" > Python, but every software project has restrictions in the form of > styles, patterns and conventions. > > This is where the "Lesser Python" crowd usually step in and say that > they won't look at anything which doesn't support "the full Python", > but I think it's informative to evaluate which features of Python give > the most value and which we could do without. The "Lesser Python" > attitude is to say, "No! We want it all! It's all necessary for > everything!" That doesn't really help the people implementing "proper" > implementations or those trying to deliver better-performing > implementations. > > In fact, the mentality that claims that "it's perfect, or it will be > if we keep adding features" could drive Python into a diminishing > niche over time. In contrast, considering variations of Python as some > kind of "Greater Python" ecosystem could help Python (the language) > adapt to the changing demands on programming languages to which Go > (the Google language, not Go! which existed already) is supposedly a > response. Yes. Niklaus Wirth, who designed Pascal, Modula, and Oberon, had that happen to his languages. He's old and bitter now; a friend of mine knows him. The problem is that "Greater Python" is to some extent "the set of features that are easy to implement if we look up everything at run time." You can insert a variable into a running function of another thread. This feature of very marginal utility is free in a naive lookup-based interpreter, and horribly expensive in anything that really compiles. Obsession with the CPython implementation as the language definition tends to overemphasize such features. The big headache from a compiler perspective is "hidden dynamism" - use of dynamic features that isn't obvious from examining the source code. (Hidden dynamism is a big headache to maintenance programmers, too.) For example, if you had the rule that you can't use "getattr" and "setattr" on an object from the outside unless the class itself implements or uses getattr and setattr, then you know at compile time if the machinery for dynamic attributes needs to be provided for that class. This allows the "slots" optimization, and direct compilation into struct-type code. Python is a very clean language held back from widespread use by slow implementations. If Python ran faster, Go would be unnecessary. And yes, performance matters when you buy servers in bulk. John Nagle From sturlamolden at yahoo.no Sun Nov 15 23:10:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 20:10:06 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <030f6ffb$0$1313$c3e8da3@news.astraweb.com> Message-ID: On 15 Nov, 05:21, Steven D'Aprano wrote: > Psyco does JIT compilation to machine-code for CPython, at the cost of > much extra memory. It's also limited to 32-bit Intel processors. The aim > of the PyPy project is to (eventually) make JIT machine-code compilation > available to any Python, on any machine. Who wants a JIT when it's orders of magnitude slower than interpreted Python? From sturlamolden at yahoo.no Sun Nov 15 23:51:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 20:51:29 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: On 16 Nov, 05:09, John Nagle wrote: > ? ? ? Python is a very clean language held back from widespread use by slow > implementations. ?If Python ran faster, Go would be unnecessary. That boggles me. NASA can find money to build a space telescope and put it in orbit. They don't find money to create a faster Python, which they use for analyzing the data. Google is a multi-billion dollar business. They are using Python extensively. Yes I know about Unladen Swallow, but why can't they put 1 mill dollar into making a fast Python? And then there is IBM and Cern's Blue Brain project. They can set up the fastest supercomputer known to man, but finance a faster Python? No... I saw this myself. At work I could get money to buy a ? 30,000 recording equipment. I could not get money for a MATLAB license. It seems software and software development is heavily underfinanced. The big bucks goes into fancy hardware. But fancy hardware is not so fancy without equally fancy software. From sturlamolden at yahoo.no Mon Nov 16 00:02:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:02:13 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <15e9625a-4cac-49f3-a16c-d6d0b854d97c@c3g2000yqd.googlegroups.com> On 16 Nov, 05:09, John Nagle wrote: > ? ? ? Python is a very clean language held back from widespread use by slow > implementations. Python is clean, minimalistic, and beautiful. Python don't have bloat like special syntax for XML or SQL databases (cf C#) or queues (Go). Most of all, it is easier to express ideas in Python than any computer language I know. Python's major drawback is slow implementations. I always find myself resorting to Cython (or C, C++, Fortran 95) here and there. But truth being told, I wrote an awful lot of C mex files when using MATLAB as well. MATLAB can easily be slower than Python by orders of magnitude, but it has not preventet it from widespread adoption. What's keeping it back is an expensive license. From sturlamolden at yahoo.no Mon Nov 16 00:09:21 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:09:21 -0800 (PST) Subject: IDE for python References: Message-ID: On 15 Nov, 18:09, Peng Yu wrote: > There had been some discussion on IDE. But I'm not sure what pros and > cons of each choice. Current, I'm using vim and ctags. > > Could somebody give some advices on choosing the best IDE for me? There is a plug-in to develop (amd debug) Python using MS Visual Studio. It works with IronPython and CPython. There is the PyDev plug-in for Eclipse. There is Komodo from ActiveState. There is KDevelop in KDE4. Which is better? I don't know. My impression is that Python development does noe need an IDE like e.g. C++ development do. There is no build process, which takes the major advantage of the IDE away. I am fine with a editor like IDLE or Kate. From sajmikins at gmail.com Mon Nov 16 00:10:47 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 16 Nov 2009 00:10:47 -0500 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy wrote: > Paul Rubin wrote: > >> Mark Chu-Carroll has a new post about Go: >> >> >> ?http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php > > In a couple of minutes, I wrote his toy prime filter example in Python, > mostly from the text rather than the code, which I can barely stand to read. > It ran the first time without error. > > def plurals(): > ?i = 2 > ?while True: > ? ?yield i > ? ?i += 1 > > def primefilter(src, prime): > ?for i in src: > ? ?if i % prime: > ? ? ?yield i > > src = plurals() > while True: > ?i = next(src) > ?print(i) > ?src = primefilter(src, i) > > As I commented there > "It stopped at 7877 when it hit the default recursion limit of 1000, which > could easily be increased to get out-of-memory error instead. > > I think Google is making a blunder if it moves to another old-fashioned > language whose code is bloated with junky boilerplate that doubles the size. > It would be much better, for instance, to tweak Python, which it has had > great success with, to better run on multiple cores." > > Terry Jan Reedy FWIW, def plurals(): i = 3 while True: yield i i += 2 From rt8396 at gmail.com Mon Nov 16 00:15:41 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 21:15:41 -0800 (PST) Subject: tkFileDialog question References: Message-ID: Matt, There is also a nice thing you need to know about Python if you already do not know. That is the fact that all empty collections bool to False. This makes Truth testing easier. >>> bool([]) False >>> bool('') False >>> bool({}) False >>> bool([1]) True >>> bool([[]]) True >>> bool(' ') True any empty collection, string, or 0 always bools to False. From sturlamolden at yahoo.no Mon Nov 16 00:25:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:25:53 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On 14 Nov, 23:10, Terry Reedy wrote: > It would be much better, for instance, to tweak Python, which it > has had great success with, to better run on multiple cores." Python run well on multiple cores, you just have to use processes instead of threads. From arts.martijn at gmail.com Mon Nov 16 01:37:58 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Mon, 16 Nov 2009 07:37:58 +0100 Subject: Pokemon gamestyle in Python Message-ID: <23739e0a0911152237r3a4da2bfle0c20e3fe773f8a9@mail.gmail.com> First; sorry, the title might be somewhat unclear about what I mean. Then; I know PyGame and I've worked with it, but I want to make a Pokemon/Legend of Zelda style game with a moving guy on a map. So what I'm asking is; is there anything better than PyGame for this gamestyle? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 16 02:10:40 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 23:10:40 -0800 (PST) Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> Message-ID: <6b2330ff-ae25-43c2-accc-9b12208240c6@a31g2000yqn.googlegroups.com> On Nov 15, 6:26?pm, Pyrot wrote: > what happens when I use the import statement within a class/function > declaration? > I'm thinking either > 1) It imports during the class/function declaration > 2) It imports the first time a class/function call(x = rawDNA() ) > occurs > > But if it's 2) then is the import valid outside of the function/class? > what happens when the last function reference is removed?(del x) Well just fire up you interpretor fella! >>> class A(): def __init__(self): import sys print sys.version >>> a = A() 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] >>> 'sys' in dir() False >>> print sys.version Traceback (most recent call last): File "", line 1, in print sys.version NameError: name 'sys' is not defined ;-) From gagsl-py2 at yahoo.com.ar Mon Nov 16 02:27:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 04:27:37 -0300 Subject: Python 2.6.3 TarFile Module Add odd behavior References: <49AA837A96E75E4C8CD87901F7F14080032B1228@XMBIL103.northgrum.com> Message-ID: En Fri, 13 Nov 2009 16:23:31 -0300, Tilson, Greg (IS) escribi?: > In Windows Python 2.6.3 calling TarFile.add requires arcname= to be set > to work with WinZIP or WinRAR [...]If arcname= is not set during > extraction all filenames are "None" > > Suggest document change or filing a bug report Post some code showing your problem. I wrote a quick test and worked fine for me. -- Gabriel Genellina From tjreedy at udel.edu Mon Nov 16 04:00:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 04:00:59 -0500 Subject: Python & Go In-Reply-To: <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> Message-ID: Simon Forman wrote: > On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy wrote: >> Paul Rubin wrote: >> >>> Mark Chu-Carroll has a new post about Go: >>> >>> >>> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> In a couple of minutes, I wrote his toy prime filter example in Python, >> mostly from the text rather than the code, which I can barely stand to read. >> It ran the first time without error. >> >> def plurals(): >> i = 2 >> while True: >> yield i >> i += 1 >> >> def primefilter(src, prime): >> for i in src: >> if i % prime: >> yield i >> >> src = plurals() >> while True: >> i = next(src) >> print(i) >> src = primefilter(src, i) >> >> As I commented there >> "It stopped at 7877 when it hit the default recursion limit of 1000, which >> could easily be increased to get out-of-memory error instead. >> >> I think Google is making a blunder if it moves to another old-fashioned >> language whose code is bloated with junky boilerplate that doubles the size. >> It would be much better, for instance, to tweak Python, which it has had >> great success with, to better run on multiple cores." >> >> Terry Jan Reedy > > FWIW, > > def plurals(): > i = 3 > while True: > yield i > i += 2 Of course, in fact, I thought of at the time def plurals(): i = 6 while True: yield i-1 yield i+1 i += 6 5,7, 11,13, 17,19, 23,(25-first miss), 29,31, (35-2nd miss),37, 41,43, 47,(49 erd)...Reduced the base cases by another 1/3. I *think* without measuring, that that compensates for the extra -1,+1. But I was implementing *Mark's* toy example, and first posted it on his blog, so I copied his naive version. Even better, to avoid extra -1, +1 def plurals(): yield 2 yield 3 i = 5 while True: yield i i += 2 yield i i += 4 Of course, testing with primes greater that square root(candidate) is wasteful, and recusion should be converted to iteration to avoid recursion limit. Terry Jan Reedy From tartley at tartley.com Mon Nov 16 04:05:54 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Mon, 16 Nov 2009 01:05:54 -0800 (PST) Subject: IDE for python References: Message-ID: On Nov 16, 5:09?am, sturlamolden wrote: > On 15 Nov, 18:09, Peng Yu wrote: > > > There had been some discussion on IDE. But I'm not sure what pros and > > cons of each choice. Current, I'm using vim and ctags. > > > Could somebody give some advices on choosing the best IDE for me? > > There is a plug-in to develop (amd debug) Python using MS Visual > Studio. It works with IronPython and CPython. > > There is the PyDev plug-in for Eclipse. > > There is Komodo from ActiveState. > > There is KDevelop in KDE4. > > Which is better? I don't know. > > My impression is that Python development does noe need an IDE like > e.g. C++ development do. There is no build process, which takes the > major advantage of the IDE away. I am fine with a editor like IDLE or > Kate. I'd like to offer the group the anecdote of the great Resolver IDE migration. Developers at Resolver, where I work, choose their own IDE. Being developers, that meant every single person chose a different one. We had them all. Which turned out, slightly unexpectedly, to be just fine. We pair on all production code. So this meant we all spent a lot of time sitting at each other's desks. We soon all became pretty familiar with each other's environments - there's nothing like 8 hours a day of hands-on usage, coupled with sitting right next to a bone-fide expert to get you up to speed pretty quick. I even learned a little Emacs, holy cow! Occasionally, after seeing the details of how well some other IDE worked, developers would switch from one to another. Then, after about a year, a curious thing happened. One by one, in entirely independent decisions, almost all developers decided to migrate to either Emacs or Vi.* Each person decided that the fancy features of their IDE wasn't as useful to them as having a flexible, powerful and lightweight editor which can easily be scripted to provide whatever ad-hoc features they need. I regard this as an example of the way pairing spreads knowledge. * I say 'most developers' - there were two notable exceptions: Michael Foord, who's prodigious contributions are legend, who likes Wing, and Will Reade, our tame brainiac, responsible for the exceedingly clever 'IronClad' open-source project, who likes the uncomplicated simplicity of TextPad. As far as I can make out, TextPad has only two features, syntax highlighting and the ability to define a 'make' command, and a regex that is used to extract filenames and line-numbers from the resulting output of that make command. These are, it turns out, sufficient to transform a program that would otherwise simply be 'Notepad' into an entirely credible development environment. From tjreedy at udel.edu Mon Nov 16 04:06:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 04:06:07 -0500 Subject: Python & Go In-Reply-To: References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: sturlamolden wrote: > On 14 Nov, 23:10, Terry Reedy wrote: > >> It would be much better, for instance, to tweak Python, which it >> has had great success with, to better run on multiple cores." > > Python run well on multiple cores, you just have to use processes > instead of threads. But not so trivially as to add one word to an existing function. Hence by tweak, I meant, as explained in another post, to add a keyword or just a decorator that will do what the go keyword does in go. From lallous at lgwm.org Mon Nov 16 05:03:27 2009 From: lallous at lgwm.org (lallous) Date: Mon, 16 Nov 2009 11:03:27 +0100 Subject: C api question and determining PyObject type Message-ID: Hello I have an a class defined as: class __object(object): pass Now, I call a C function that takes a PyObject* and checks its type: if (PyString_Check(obj)) ... if (PySequence_Check(obj)) .... Before doing the check, I print the passed object with PyObject_Str() and get: passed object: <__main__.__object object at 0x040E4050> However, the C code returns true on the: if (PySequence_Check(obj)) .... Why? That is not a sequence? Please advise. -- Elias From not_here at nowhere.com Mon Nov 16 05:06:02 2009 From: not_here at nowhere.com (me) Date: Mon, 16 Nov 2009 02:06:02 -0800 Subject: python gui builders Message-ID: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Good People I do not write stuff for humans, as it has been my job to remove humans from the loop. But I have to make a front end to a component database where everything was built in Python. I have looked at the Tk stuff that is built into Python -> not acceptable. So looking at wxGlade, Boa Constructor, Python Card. Also looked at the frames/forms created with QtDesigner, which can be used by Python via pyuic. BlackAdder IDE seems to have this built-in, but am loathe to buy into another GUI tool for a single job. I have not been able to find a decent Python gui builder. The last time I did gui garbage was with Borland C++ Builder which was ok because I was only using win boxen for that project. This time I am using both Linux and Win. What Python gui builder is well supported, does not require me to learn another framework/library, and can crank out stuff for multiple platforms ? thanks much, me From vs at it.uu.se Mon Nov 16 05:14:26 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 16 Nov 2009 11:14:26 +0100 Subject: Accessing a Web server --- how? Message-ID: <4B012602.7000606@it.uu.se> If one goes to the following URL: http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html it contains a link (click on "Current courses NBD AT99 3113A") to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& and if you now click on the tab labeled "history and compare" this will take you to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& Finally...This is where I would like to "connect to" the data on a daily basis or to gather data over different time intervals. I believe that if I can get some help on this, then I will be able to customize the code as needed for my own purposes. It should be clear that this is financial data on a fond managed by Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. Note, that I do have some experience with Python (2.6 mainly), and find it a very useful and powerful language. However, I have no experience with it in the area of Web services. Any suggestions/comments on how to set up this financial data service project would be greatly appreciated, and I would be glad to share this project with any interested parties. Note, I posted a similar message to the list pywebsvcs; but, received no responses. -- V. Stokes From sturlamolden at yahoo.no Mon Nov 16 05:27:28 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:27:28 -0800 (PST) Subject: IDE for python References: Message-ID: <79fcc08c-b904-4850-80c3-0be030447f52@a31g2000yqn.googlegroups.com> On 16 Nov, 10:05, Jonathan Hartley wrote: > As far as I can make out, TextPad has only two features, syntax > highlighting and the ability to define a 'make' command, and a regex > that is used to extract filenames and line-numbers from the resulting > output of that make command. These are, it turns out, sufficient to > transform a program that would otherwise simply be 'Notepad' into an > entirely credible development environment. When working with Java or C++ I like and IDE like KDevelop because it makes makefiles for me. And when debugging it is easier to insert break points graphically than use gdb from the terminal. But apart from that, I prefer a tiny editor like Kate (yes I know, call me a heretic for not using emacs). From pavlovevidence at gmail.com Mon Nov 16 05:35:07 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 02:35:07 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Nov 15, 2:52?pm, Steve Howell wrote: > Does anybody have any links that points to the rationale for ignoring > instance definitions of __getitem__ when new-style classes are > involved? ?I assume it has something to do with performance or > protecting us from our own mistakes? "Not important enough to justify complexity of implementation." I doubt they would have left if out of new-style classes if it had been straightforward to implement (if for no other reason than to retain backwards compatibility), but it wasn't. The way attribute lookups work meant it would have required all kinds of double lookups and edge cases. Some regarded it as dubious to begin with. And it's easily worked around by simply having __getitem__ call another method, as you've seen. Given all this it made better sense to just leave it out of new-style classes. Unfortunately not all such decisions and justifications are collected in a tidy place. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 05:39:10 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:39:10 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> On 16 Nov, 11:06, me wrote: > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? I use wxFormBuilder. The 3.1 beta can even create wxPython code, but it still has some minor issues (e.g. not always creating correct code due to missing "self."). wxFormBuilder 3.0 can create XRC files, which work excellently with wxPython. The drawback is that you must bind event handlers manually, instead of having it done automatically (as you can with Python code generation in 3.1 beta). If you are fine with GPL, or can afford the commercial license, there is QtDesigner which works with PyQt. This is a fantastic cross- platform GUI tool, if not hte best there is. If you are fine with Microsoft only, you can use Windows Forms with MS Visual Studio and IronPython. If you can use Jython, there are many tools for working with Java Swing or SWT. From news at schwertberger.de Mon Nov 16 05:39:51 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Mon, 16 Nov 2009 11:39:51 +0100 Subject: IDE for python In-Reply-To: References: Message-ID: <7mcofsF3hl5c5U1@mid.individual.net> sturlamolden schrieb: > On 15 Nov, 18:09, Peng Yu wrote: >> There had been some discussion on IDE. But I'm not sure what pros and >> cons of each choice. Current, I'm using vim and ctags. >> >> Could somebody give some advices on choosing the best IDE for me? > > There is a plug-in to develop (amd debug) Python using MS Visual > Studio. It works with IronPython and CPython. > > There is the PyDev plug-in for Eclipse. > > There is Komodo from ActiveState. > > There is KDevelop in KDE4. > > Which is better? I don't know. > > My impression is that Python development does noe need an IDE like > e.g. C++ development do. There is no build process, which takes the > major advantage of the IDE away. I am fine with a editor like IDLE or > Kate. For more than ten years I had the same opinion. I found that a very lightweight "IDE" like PythonWin is sufficient for me together with print statements and the built-in post-mortem debugger for debugging. But then, last year I had to find a tricky bug in my GUI code (wxPython) and thought that for this problem a debugger would be helpful. So I gave the Wing IDE with it's debugger a try and have been using it since then. Even though an IDE is not an absolute must, I found that my productivity increased a lot (25%?) and I would not want to miss: - code completion - powerful debugger (even if you only use the post-mortem debugger it will save you a lot of time compared to pdb.pm() as it takes only a mouse click to move to the exception point in the editor instead of looking at the line number and then find the same point in the editor...) - Mercurial integration - PyFlakes integration Regards, Dietmar From pavlovevidence at gmail.com Mon Nov 16 05:42:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 02:42:05 -0800 (PST) Subject: IDE for python References: Message-ID: On Nov 16, 1:05?am, Jonathan Hartley wrote: > Then, after about a year, a curious thing happened. One by one, in > entirely independent decisions, almost all developers decided to > migrate to either Emacs or Vi.* > > Each person decided that the fancy features of their IDE wasn't as > useful to them as having a flexible, powerful and lightweight editor > which can easily be scripted to provide whatever ad-hoc features they > need. > > I regard this as an example of the way pairing spreads knowledge. That's the best justification for pair programming I've seen yet. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 05:42:51 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:42:51 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> Message-ID: On 16 Nov, 11:39, sturlamolden wrote: > If you are fine with Microsoft only, you can use Windows Forms with MS > Visual Studio and IronPython. I also forgot to mention: If you can restrict yourself to Windows, you can always use Visual Basic or Borland Delphi with pywin32. Either expose your GUI as an ActiveX to pywin32 (you have e.g. an MFC binding) or expose your Python as an ActiveX to VB/Delphi. The same approach should work (with a little bit more work) for C# and VB.NET. From lallous at lgwm.org Mon Nov 16 05:44:34 2009 From: lallous at lgwm.org (lallous) Date: Mon, 16 Nov 2009 11:44:34 +0100 Subject: C api question and determining PyObject type References: Message-ID: Actually, the object class is defined as: class __object(object): def __getitem__(self, idx): return getattr(self, idx) Anyway, now I check like this: bool PyIsSequenceType(PyObject *obj) { if (!PySequence_Check(obj)) return false; Py_ssize_t sz = PySequence_Size(obj); if (sz == -1 || PyErr_Occurred() != NULL) { PyErr_Clear(); return false; } return true; } I don't like it, any other suggestions? -- Elias "lallous" wrote in message news:hdr80a$vsg$1 at aioe.org... > Hello > > I have an a class defined as: > > class __object(object): > pass > > Now, I call a C function that takes a PyObject* and checks its type: > > if (PyString_Check(obj)) ... > if (PySequence_Check(obj)) .... > > Before doing the check, I print the passed object with PyObject_Str() and > get: > > passed object: <__main__.__object object at 0x040E4050> > > However, the C code returns true on the: > if (PySequence_Check(obj)) .... > > > Why? That is not a sequence? > From sturlamolden at yahoo.no Mon Nov 16 06:05:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 03:05:13 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <99fff8de-5ecc-4bde-b486-f66b018532dc@g27g2000yqn.googlegroups.com> On 16 Nov, 10:06, Terry Reedy wrote: > > Python run well on multiple cores, you just have to use processes > > instead of threads. > > But not so trivially as to add one word to an existing function. > Hence by tweak, I meant, as explained in another post, to add a keyword > or just a decorator that will do what the go keyword does in go. A decorator function like @go could just call os.fork and run the function in the child. We already have a between-process Queue in multiprocessing to use as channels. Or we could have a context manager that forks in __enter__ and waitpids or exits in __exit__. The body of the with-statement would then be executed in the child process, the parent would just raise an exception to skip directly to __exit__. Not rocket science as all. Yes that would give us a new isolated process, but such isolation is present in Erlang as well. (Windows is more tricky though, as there is no efficent fork.) From eden at bicikl. Mon Nov 16 07:08:10 2009 From: eden at bicikl. (Eden Kirin) Date: Mon, 16 Nov 2009 13:08:10 +0100 Subject: SCGIServer and unusal termination Message-ID: Hi there, I'm playing with SCGIServer (http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), everything works just fine, but one thing bothers me. All prints after try-except block are executed twice after the Ctrl+C is pressed! test.py: #------------------------- from scgi.scgi_server import SCGIServer n = 0 print "Starting server." try: SCGIServer().serve() except (KeyboardInterrupt, SystemExit): print "Exception!" # print lines are executed twice (?!) n += 1 print "Terminating server, attempt %d." % n n += 1 print "Check n: %d." % n #------------------------- This is the output: eden at sunce:~/data/project/ScgiServer/src> python test.py Starting server. ^CException! Exception! Terminating server, attempt 1. Check n: 2. Terminating server, attempt 1. Check n: 2. eden at sunce:~/data/project/ScgiServer/src> If I put something else in try-except block, code after is executed normally: try: while 1: pass except (KeyboardInterrupt, SystemExit): print "Exception!" eden at sunce:~/data/project/ScgiServer/src> python test.py Starting server. ^CException! Terminating server, attempt 1. Check n: 2. eden at sunce:~/data/project/ScgiServer/src> Environment is 64bit Ubuntu with Python v2.6.4. Is there some reasonable explanation for this behaviour? Thanks in advance. -- www.vikendi.net -/- www.supergrupa.com From chen_zhitao at yahoo.com Mon Nov 16 07:50:09 2009 From: chen_zhitao at yahoo.com (Kuhl) Date: Mon, 16 Nov 2009 04:50:09 -0800 (PST) Subject: import subprocess in python Message-ID: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> I am a Linux user beginning to learn Python now. Below is the first Python script that I copied from the text book. It works, so it confirmed that there is python installed in my system: #!/usr/bin/env python for a in [1, 2]: for b in ['a', 'b']: print a, b But when I continue to learn Python, I come across with issue. The text book instructed me to use ipython, but ipython command is not found in my system, so I have to use python instead. However, "import subprocess" still failed, see below. # which python /usr/bin/python # which ipython ipython: Command not found. # python Python 2.2.3 (#1, Feb 2 2005, 12:22:48) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess Traceback (most recent call last): File "", line 1, in ? ImportError: No module named subprocess >>> So I guess that there should be a file named subprocess.py somewhere. But there are too many files on the huge disk, I don't know where I should start to search for it. Then I tried to key in a function file python_func_00.py by myself. def pyfunc(): print "Hello function" # python Python 2.2.3 (#1, Feb 2 2005, 12:22:48) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import python_func_00 >>> pyfunc() Traceback (most recent call last): File "", line 1, in ? NameError: name 'pyfunc' is not defined >>> >>> There's a binary file of 240 bytes created: python_func_00.pyc But as we can see above, the function pyfunc() does not work. I guess that I should add the following statement at first line of python_func_00.py, then redo the import: #!/usr/bin/env python But after adding this line and redoing the import, pyfunc() still failed like above. What's the mistake that I am making? How to solve it? Thanks. From sturlamolden at yahoo.no Mon Nov 16 07:58:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 04:58:00 -0800 (PST) Subject: import subprocess in python References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> Message-ID: <0834aa40-c2f8-4865-aa8d-cc9c4c272b0a@v25g2000yqk.googlegroups.com> On 16 Nov, 13:50, Kuhl wrote: > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > What's the mistake that I am making? How to solve it? Your Python version is too old. From clp2 at rebertia.com Mon Nov 16 08:04:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 05:04:02 -0800 Subject: import subprocess in python In-Reply-To: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> Message-ID: <50697b2c0911160504k3a634c23le9867f583b01bd0f@mail.gmail.com> On Mon, Nov 16, 2009 at 4:50 AM, Kuhl wrote: > found in my system, so I have to use python instead. However, "import > subprocess" still failed, see below. > > # which python > /usr/bin/python > # which ipython > ipython: Command not found. > # python > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import subprocess > Traceback (most recent call last): > ?File "", line 1, in ? > ImportError: No module named subprocess >>>> The `subprocess` modules was added in Python 2.4. You're using Python 2.2.3; you need to update. > should start to search for ?it. Then I tried to key in a function > file ?python_func_00.py ?by myself. > > def pyfunc(): > ? ? ? ?print "Hello function" > > > # python > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import python_func_00 >>>> pyfunc() > Traceback (most recent call last): > ?File "", line 1, in ? > NameError: name 'pyfunc' is not defined > What's the mistake that I am making? How to solve it? The `import foo` statement only adds the name of the module itself to your namespace, so you need to refer to pyfunc by way of the module name. To wit: import python_func_00 python_func_00.pyfunc() Alternatively, you can specify a set of names to import from the module namespace into your own using the `from foo import bar` syntax: from python_func_00 import pyfunc pyfunc() Regarding ipython, it's a third-party package that is not part of Python itself and must be installed separately. Exactly how you do so will obviously depend on which distro you're using. Cheers, Chris -- http://blog.rebertia.com From hvictor at bluewin.ch Mon Nov 16 08:04:48 2009 From: hvictor at bluewin.ch (hvictor) Date: Mon, 16 Nov 2009 05:04:48 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API Message-ID: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> I have C++ a void function pointer stored in a variable call. The pointed function takes an int and a char* as arguments. I have a python module containing this function: def yeah(x): x(int(0),"text argument") return "pointer called" As you can see I'm trying to use the argument x of the function like a method object. In the C++ side I'm doing following (note that I only paste relevant parts of code because this system is working fine, C++ is able to call function yeah and get its return value, but only with a string- oriented test): ... PyObject *pValue; // the argument for python pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn ptr, required from the api. PyObject *pFunc = PyObject_GetAttrString(pModule, "yeah"); ... PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the arguments, I insert pValue in it. pValue = PyObject_CallObject(pFunc, pArgs); ... It does not work. can anyone help me please? I just want python to call this function pointer. Thank you From ian at excess.org Mon Nov 16 08:24:26 2009 From: ian at excess.org (Ian Ward) Date: Mon, 16 Nov 2009 08:24:26 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B01528A.90303@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From ian at excess.org Mon Nov 16 08:24:52 2009 From: ian at excess.org (Ian Ward) Date: Mon, 16 Nov 2009 08:24:52 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B0152A4.7050307@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From pavlovevidence at gmail.com Mon Nov 16 08:25:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 05:25:05 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API References: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> Message-ID: <3dde088d-859b-41f7-9aad-11a6c2887b96@j14g2000yqm.googlegroups.com> On Nov 16, 5:04?am, hvictor wrote: > I have C++ a void function pointer stored in a variable call. The > pointed function takes an int and a char* as arguments. > > I have a python module containing this function: > > def yeah(x): > ? ? ? ? x(int(0),"text argument") > ? ? ? ? return "pointer called" > > As you can see I'm trying to use the argument x of the function like a > method object. > In the C++ side I'm doing following (note that I only paste relevant > parts of code because this system is working fine, C++ is able to call > function yeah and get its return value, but only with a string- > oriented test): > ... > PyObject *pValue; // the argument for python > > pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn > ptr, required from the api. > > PyObject *pFunc = PyObject_GetAttrString(pModule, "yeah"); > > ... > PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the > arguments, I insert pValue in it. > > pValue = PyObject_CallObject(pFunc, pArgs); > > ... > > It does not work. can anyone help me please? I just want python to > call this function pointer. Python can't call C function pointers. You have to write a function in C that accepts a CObject and some arguments, unpacks the arguments, retrieves the function pointer from the CObject, and calls it. Quick and dirty function that might do that (untested, not robust). static PyObject* call_user_void_ptr(PyObject* self, PyObject* args) { PyObject* cobj; int ival; char* sval; void (*func)(int,char*); if (!PyArg_ParseTuple("O!is",&PyCObject_Type,&cobj,&ival,&sval)) return 0; func = PyCObject_AsVoidPtr(cobj); func(ival,sval); Py_RETURN_NONE; } def yeah(x): call_user_void_ptr(x,int(i),"text_argument") print "pointer called" In a pinch, you could call the function pointer from ctypes. Since you're already writing a C extension I wouldn't recommend it as a final solution, though. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 08:26:57 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 05:26:57 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API References: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> <3dde088d-859b-41f7-9aad-11a6c2887b96@j14g2000yqm.googlegroups.com> Message-ID: <17ffa382-7fcb-4862-9b9d-f210252f50b0@r5g2000yqb.googlegroups.com> On 16 Nov, 14:25, Carl Banks wrote: > Python can't call C function pointers. ? Yes it can, use ctypes... From james at agentultra.com Mon Nov 16 08:27:18 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 16 Nov 2009 08:27:18 -0500 Subject: object serialization as python scripts References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> Message-ID: <87lji6mwg9.fsf@agentultra.com> King writes: >> Why is it easier than the above mentioned - they are *there* (except the >> custom xml), and just can be used. What don't they do you want to do? >> >> Other than that, and even security issues put aside, I don't see much >> difference between pickle and python code, except the latter being more >> verbose. Which suits humans, but other than that has no advantage. >> >> Diez > > My application is PyQt based and objects that I am trying to save are > couple of QGraphicsItem instances. You can't save instances of > QGraphicsItem > using pickle or shelve. > Custom xml format would be a real pain as you have to write code for > writing/reading both. > > I am aware of security issue but over all there are only 5 statements > I have to use to get the entire > information back. I can do syntax checking and other stuff before I > should execute the script. > > Another reason is that data should be in human readable form. > > Prashant > > Python 2.6.2 > Win XP 32 Pickling should work just fine. If you cannot pickle the class with the default pickler, you can hook into the pickler protocol to tell pickle how to pickle instances of the class. Failing that you can write your own pickler class for handling the special case. Python scripts aren't really a good data format. They're not structured in a way that would be easy to parse and extract information from in a non-python context without a lot of work. From robin at reportlab.com Mon Nov 16 08:28:36 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 13:28:36 +0000 Subject: Psyco on 64-bit machines In-Reply-To: References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <4B015384.9050104@chamonix.reportlab.co.uk> Russ P. wrote: ........ > I just stumbled across "unladen swallow," a "faster implementation of > Python." Is it ready for operational usage? How does it compare to > Psyco? I poked around their website a bit, but I don't see answers to > those questions. Thanks. I've tried a few things with it. It mostly works, but it isn't actually faster at normal programs. I've been told their target is for long running processes where JIT and similar can speed up the inner loops etc etc. Certainly makes sense for google apps in python so perhaps that's the intended end use. -- Robin Becker From robin at reportlab.com Mon Nov 16 08:28:36 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 13:28:36 +0000 Subject: Psyco on 64-bit machines In-Reply-To: References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <4B015384.9050104@chamonix.reportlab.co.uk> Russ P. wrote: ........ > I just stumbled across "unladen swallow," a "faster implementation of > Python." Is it ready for operational usage? How does it compare to > Psyco? I poked around their website a bit, but I don't see answers to > those questions. Thanks. I've tried a few things with it. It mostly works, but it isn't actually faster at normal programs. I've been told their target is for long running processes where JIT and similar can speed up the inner loops etc etc. Certainly makes sense for google apps in python so perhaps that's the intended end use. -- Robin Becker From darcymason at gmail.com Mon Nov 16 08:34:27 2009 From: darcymason at gmail.com (Darcy Mason) Date: Mon, 16 Nov 2009 05:34:27 -0800 (PST) Subject: Calling Python functions from Excel References: Message-ID: <93c20779-ceca-4a10-82ef-33878047b4dc@h34g2000yqm.googlegroups.com> On Nov 15, 2:20?am, Cannonbiker wrote: > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. A couple of years ago I used MSScriptControl for this. Couldn't find a great reference just now, but here is a discussion which should give enough information: http://www.velocityreviews.com/forums/t319222-re-python-in-excel.html Check from around message 3 on. From mrholtsr at gmail.com Mon Nov 16 09:00:18 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Mon, 16 Nov 2009 06:00:18 -0800 (PST) Subject: Code for finding the 1000th prime References: <7majfhF2j43tpU1@mid.uni-berlin.de> Message-ID: <0382cc5d-9800-49b0-a98f-55dc06a0e30f@p35g2000yqh.googlegroups.com> On Nov 15, 10:02?am, "Diez B. Roggisch" wrote: > mrholtsr schrieb: > > > I am absolutely new to python and barely past beginner in programming. > > Also I am not a mathematician. Can some one give me pointers for > > finding the 1000th. prime for a course I am taking over the internet > > on Introduction to Computer Science and Programming. Thanks, Ray > > Do you really think we are so retarded that we don't remember you posted > the same question a week ago? > > Diez Mea Culpa. I didn't realize at the time that this group was the same as the newsletter. Won't do it again. From jeremy+complangpython at jeremysanders.net Mon Nov 16 09:00:25 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Mon, 16 Nov 2009 14:00:25 +0000 Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: Russ P. wrote: > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. You won't be able to access large amounts of memory in 32 bit mode. Also, the x86-64 mode has more CPU registers than x86 mode, so Python will typically run faster in 64 bit mode (this is more pronounced in AMD processors, in my experience). It will depend on your application whether 32 bit mode plus Psyco is faster than 64 bit mode. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ From mrholtsr at gmail.com Mon Nov 16 09:01:44 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Mon, 16 Nov 2009 06:01:44 -0800 (PST) Subject: Newsgroup for beginners Message-ID: Is there a Python newsgroup for those who are strictly beginners at programming and python? From mr.spoon21 at gmail.com Mon Nov 16 09:02:28 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Mon, 16 Nov 2009 15:02:28 +0100 Subject: Logic operators with "in" statement Message-ID: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Hi, I'm trying to use logical operators (or, and) with the "in" statement, but I'm having some problems to understand their behavior. In [1]: l = ['3', 'no3', 'b3'] In [2]: '3' in l Out[2]: True In [3]: '3' and '4' in l Out[3]: False In [4]: '3' and 'no3' in l Out[4]: True This seems to work as I expected. ------------ In [5]: '3' and 'no3' or '3' and '4' in l Out[5]: 'no3' In [6]: ('3' and 'no3') or ('3' and '4') in l Out[6]: 'no3' I don't understand these outputs. --------------- In [7]: (('3' and 'no3') or ('3' and '4')) in l Out[7]: True In [10]: (('b3' and '4') or ('3' and 'no3')) in l Out[10]: False Here I expected to get True in the second case too, so clearly I don't really get how they work. Can you help me? What I really need is to create a sequence of "if" statements to check the presence of elements in a list, because some of them are mutually exclusive, so if for example there are both "3" and "no3" it should return an error. Thanks, Carlo From sturlamolden at yahoo.no Mon Nov 16 09:06:55 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 06:06:55 -0800 (PST) Subject: Code for finding the 1000th prime References: Message-ID: <92dc62d9-330c-4638-95ae-e19998b09add@m16g2000yqc.googlegroups.com> On 15 Nov, 15:30, mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray print "7919" From deets at nospam.web.de Mon Nov 16 09:07:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Nov 2009 15:07:05 +0100 Subject: Newsgroup for beginners References: Message-ID: <7md4k9F3fo2umU1@mid.uni-berlin.de> mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? Yes, the tutor-list. http://mail.python.org/mailman/listinfo/tutor Diez From mr.spoon21 at gmail.com Mon Nov 16 09:08:54 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Mon, 16 Nov 2009 15:08:54 +0100 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Sorry for replying to myself, but I think I understood why I was wrong. The correct statement should be something like this: In [13]: ('b3' and '5') in l or ('3' and 'b3') in l Out[13]: True From tgrav at me.com Mon Nov 16 09:11:20 2009 From: tgrav at me.com (Tommy Grav) Date: Mon, 16 Nov 2009 09:11:20 -0500 Subject: (unknown) In-Reply-To: References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: <3F923692-C191-4477-879B-1921C0268EB4@me.com> On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote: > En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > >> I'm attempting to convert latitude and longitude coordinates from degrees >> minutes and second to decimal form. I would like to go from: >> N39 42 36.3 W77 42 51.5 >> to: >> -77.739855,39.706666 >> >> Does anyone know of a library or some existing out their to help with this >> conversion? > > Should be: > > decimal = degrees + minutes/60.0 + seconds/3600.0 > N,E are positive; S,W are negative. > > But the above numbers don't match. It is more complicated than that. For negative numbers the value is degrees -minutes/60. - seconds/3600. And people always trip up on numbers that start with -00 :) Cheers Tommy From exarkun at twistedmatrix.com Mon Nov 16 09:12:27 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 16 Nov 2009 14:12:27 -0000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <20091116141227.27565.1164868262.divmod.xquotient.183@localhost.localdomain> On 02:02 pm, mr.spoon21 at gmail.com wrote: >Hi, >I'm trying to use logical operators (or, and) with the "in" statement, >but I'm having some problems to understand their behavior. "and" and "or" have no particular interaction with "in". > >In [1]: l = ['3', 'no3', 'b3'] > >In [2]: '3' in l >Out[2]: True > >In [3]: '3' and '4' in l >Out[3]: False > >In [4]: '3' and 'no3' in l >Out[4]: True > >This seems to work as I expected. What this actually does is '3' and ('no3' in l). So it might have produced the result you expected, but it didn't work how you expected. :) Jean-Paul From clp2 at rebertia.com Mon Nov 16 09:14:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:14:30 -0800 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: <50697b2c0911160614h71033b1eg714351ef695a6fb4@mail.gmail.com> On Mon, Nov 16, 2009 at 6:01 AM, mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? python-tutor: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://blog.rebertia.com From R.Brodie at rl.ac.uk Mon Nov 16 09:17:20 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 16 Nov 2009 14:17:20 -0000 Subject: Logic operators with "in" statement References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: "Mr.SpOOn" wrote in message news:mailman.492.1258380560.2873.python-list at python.org... > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True For anything more than the simplest cases, you might want use sets. That might be the correct data type from the start, depending on whether the ordering is important anywhere. From clp2 at rebertia.com Mon Nov 16 09:21:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:21:10 -0800 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <50697b2c0911160621s7d8d734bi88a83adddd2cbd4d@mail.gmail.com> On Mon, Nov 16, 2009 at 6:02 AM, Mr.SpOOn wrote: > Hi, > I'm trying to use logical operators (or, and) with the "in" statement, > but I'm having some problems to understand their behavior. > > In [1]: l = ['3', 'no3', 'b3'] > > In [2]: '3' in l > Out[2]: True > > In [3]: '3' and '4' in l > Out[3]: False > > In [4]: '3' and 'no3' in l > Out[4]: True > > This seems to work as I expected. No, it doesn't. You are misinterpreting. Membership tests via `in` do NOT distribute over `and` and `or`. '3' and '4' in l is equivalent to: ('3') and ('4' in l) Recall that non-empty sequences and containers are conventionally True in Python, so your expression is logically equivalent to: '4' in l With '3' not being checked for membership at all. To check multiple items for membership in a contains, you must write each `in` test separately and then conjoin then by the appropriate boolean operator: '3' in l and '4' in l Cheers, Chris -- http://blog.rebertia.com From contact at xavierho.com Mon Nov 16 09:23:01 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 00:23:01 +1000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> On Tue, Nov 17, 2009 at 12:02 AM, Mr.SpOOn wrote: > Hi, > I'm trying to use logical operators (or, and) with the "in" statement, > but I'm having some problems to understand their behavior. > Hey Carlo, I think your issue here is mistaking 'in' as a statement. It's just another logic operator, much like 'and' and 'or'... it's not a statement in itself. At least, I don't think that's how you'd call 'in'. You have to remember that Python's logical operators (and, or) works slightly different than most languages. It doesn't return True or False, if the things compared aren't boolean values. Instead, it returns the first thing that makes the decision. For example a statement such as >>>'3' and '4' '4' returns the string literal 4. 1. Python's AND operator returns the first element if the first one is False; else, it returns the second element. That's all it does. Python's OR operator returns the first element if the first one is True; else, it returns the second element. Think about it. It's a little strange, but they don't return a pure Boolean value. 2. Only the empty string is considered False. Any non-empty strings have True values. 3. The proper way of using the in operator is probably such: (There may be a better way I'm not aware of.) >>> '3' in l and '4' in l False >>> '3' in l and 'no3' in l True AND operator has a higher precedence, so you don't need any brackets here, I think. But anyway, you have to use it like that. So that's something you'll have to fix first. > What I really need is to create a sequence of "if" statements to check > the presence of elements in a list, because some of them are mutually > exclusive, so if for example there are both "3" and "no3" it should > return an error One idea I can think of is to have a presence count; assuming the input is non-repeating, you increase this count by 1, starting at 0. If you get anything above one, return this error you speak of, and that might be a good start. Good luck, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 16 09:30:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:30:30 -0800 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Message-ID: <50697b2c0911160630k3ed20c5sa5218ab4d53c27ff@mail.gmail.com> On Mon, Nov 16, 2009 at 6:08 AM, Mr.SpOOn wrote: > Sorry for replying to myself, but I think I understood why I was wrong. > > The correct statement should be something like this: > > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True No, you've just run into another misunderstanding. Given the expression `X and Y`: If bool(X) is False, it evaluates to X. Otherwise, it evaluates to Y. In other words, the subexpression which ends up determining the truth of the conjunction is what the conjunction evaluates to. `or` works similarly. This allows for tricky tricks like: foo = possiblyFalse or default # use default if given value is false Thus, due to the parentheses, your expression is equivalent to: '5' in l or 'b3' in l Which I trust is not what you intended. Again, you need to write separate `in`s for each item you need to check the membership of: ('b3' in l and '5' in l) or ('3' in l and 'b3' in l) Cheers, Chris -- Python language lawyer at your service http://blog.rebertia.com From contact at xavierho.com Mon Nov 16 09:30:33 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 00:30:33 +1000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Message-ID: <2d56febf0911160630m68f1148o6f1c9ff5bc42af73@mail.gmail.com> On Tue, Nov 17, 2009 at 12:08 AM, Mr.SpOOn wrote: > Sorry for replying to myself, but I think I understood why I was wrong. > > The correct statement should be something like this: > > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True > > Carlo, I'm not sure what that achieves. Care to enlighten me? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Nov 16 09:38:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 08:38:49 -0600 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <4B0163F9.5020600@tim.thechases.com> > Here I expected to get True in the second case too, so clearly I don't > really get how they work. You're seeing short-circuit evaluation: >>> "3" or "4" # true '3' >>> '4' or '3' # true '4' >>> '4' in l # false False >>> '3' or False # true '3' >>> '4' or '42' in l # true: same as "'4' or ('42' in l)" '4' >>> '4' or '42' '4' >>> ('4' or '42') in l # true: same as "'4' in l" '4' It just happens that sometimes you get unexpected results that happen to be right because of how Python handles strings/numbers as booleans and order-of-operations. > What I really need is to create a sequence of "if" statements to check > the presence of elements in a list, because some of them are mutually > exclusive, so if for example there are both "3" and "no3" it should > return an error. The "in" operator only checks containment of one item, not multiples, so you have to manage the checking yourself. This is fairly easy with the any()/all() functions added in 2.5: any(i in l for i in ("3", "4")) all(i in l for i in ("3", "4")) For more complex containment testing, using sets will be more efficient and offers a richer family of batch operators (contains, intersection, union, difference, issubset, issuperset) -tkc From python.list at tim.thechases.com Mon Nov 16 09:44:37 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 08:44:37 -0600 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: <4B016555.1070300@tim.thechases.com> mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? http://mail.python.org/mailman/listinfo/tutor -tkc From x31eq at cnntp.org Mon Nov 16 09:45:05 2009 From: x31eq at cnntp.org (Graham Breed) Date: Mon, 16 Nov 2009 22:45:05 +0800 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <4b016573$0$9750$6e1ede2f@read.cnntp.org> Terry Reedy wrote: > It seems to me that generators are already 'channels' that connect the > calling code to the __next__ method, a semi-coroutine based on the body > of the generator function. At present, the next method waits until an > object is requested. Then it goes into action, yields an object, and > rests again. For parallel operations, we need eager, anticipatory > evaluation that produces things that *will* be needed rather than lazy > evaluation of things that *are* needed and whose absence is holding up > everything else. Yes, generators look very much like channels. The obvious thing, from where I'm sitting, is to have a function called "channel" that takes an iterator, runs it in a different thread/process/goroutine, and returns an iterator that reads from the channel. A single threaded version would look very much like "iter" so let's use iter to get a working example: #!/usr/bin/python2 -u channel = iter # placeholder for missing feature def generate(): i = 2 while True: yield i i += 1 def filter(input, prime): for i in input: if i%prime != 0: yield i ch = channel(generate()) try: while True: prime = ch.next() print prime ch = channel(filter(ch, prime)) except IOError: pass That works fine in a single thread. It's close to the original go example, hence the evil shadowing of a builtin. I don't think the "channel" function would present any problems given an appropriate library to wrap. I got something like this working with Jython and the E language but, as I recall, had an accident and lost the code. If somebody wants to implement it using multiprocessing, go to it! Graham From clp2 at rebertia.com Mon Nov 16 09:46:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:46:48 -0800 Subject: Logic operators with "in" statement In-Reply-To: <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> Message-ID: <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote: >>>> '3' in l and 'no3' in l > True > > AND operator has a higher precedence, so you don't need any brackets here, I > think. But anyway, you have to use it like that. So that's something you'll > have to fix first. Er, you mean lower precedence. Higher precedence means it would bind tighter, thus the expression would mean: '3' in (l and 'no3') in l which is certainly incorrect. Cheers, Chris -- http://blog.rebertia.com From paul at boddie.org.uk Mon Nov 16 10:03:34 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 16 Nov 2009 07:03:34 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <7de63a99-dce9-47b0-9e05-b36f8283236d@b2g2000yqi.googlegroups.com> On 16 Nov, 05:51, sturlamolden wrote: > > NASA can find money to build a space telescope and put it in orbit. > They don't find money to create a faster Python, which they use for > analyzing the data. Is the analysis in Python really what slows it all down? > Google is a multi-billion dollar business. They are using Python > extensively. Yes I know about Unladen Swallow, but why can't they put > 1 mill dollar into making a fast Python? Isn't this where we need those Ohloh figures on how much Unladen Swallow is worth? ;-) I think Google is one of those organisations where that Steve Jobs mentality of shaving time off a once-per-day activity actually pays off. A few more cycles here and there is arguably nothing to us, but it's a few kW when running on thousands of Google nodes. > And then there is IBM and Cern's Blue Brain project. They can set up > the fastest supercomputer known to man, but finance a faster Python? > No... Businesses and organisations generally don't spend any more money than they need to. And if choosing another technology is cheaper for future work then they'll just do that instead. In a sense, Python's extensibility using C, C++ and Fortran have helped adoption of the language considerably, but it hasn't necessarily encouraged a focus on performance. Paul From carlo.dicelico at gmail.com Mon Nov 16 10:19:49 2009 From: carlo.dicelico at gmail.com (Carlo DiCelico) Date: Mon, 16 Nov 2009 07:19:49 -0800 (PST) Subject: Image to SVG conversion with Python Message-ID: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> I need to convert JPEG and PNG files to SVG. I'm currently using PIL to generate the JPEG/PNG files to begin with. However, I need to be able to scale the generated images up in size without a loss of image quality. Using SVG seems to be the best way to do this, other than generating the images in the maximum size/resolution in the first place, which would be too resource intensive. I've looked around online and have found some tools for creating SVGs but none for converting an image into SVG. Does anyone have any experience doing this? What would be the best way to go about this? Thanks, Carlo From python-url at phaseit.net Mon Nov 16 10:22:40 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Mon, 16 Nov 2009 15:22:40 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 16) Message-ID: QOTW: "The promise is 'batteries included.' Nobody promised you a nickel metal hydride battery that you can use as a replacement in your Prius." - Stephen J. Turnbull http://mail.python.org/pipermail/python-dev/2009-November/094014.html Google's new language, Go, has similarities to Python: http://groups.google.com/group/comp.lang.python/t/c1c4a8fe741c689a/ Is Python scalable enough for Google (or any other huge application)? http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/ Is it possible to get the physical memory address of a variable in python? http://groups.google.com/group/comp.lang.python/t/969462b9a3b452/ Serialize objects as Python code: http://groups.google.com/group/comp.lang.python/t/98536e7910e65256/ Overriding __getitem__ for a subclass of dict: http://groups.google.com/group/comp.lang.python/t/d9b822119fc0917c/ Ensure a script is run with a certain range of Python versions: http://groups.google.com/group/comp.lang.python/t/d21a492be99c90e8/ How to install applications when Python is not already present: http://groups.google.com/group/comp.lang.python/t/495794a40d18fbc/ Turtle graphics are just for kids - or not? Its advantages when teaching Python programming: http://groups.google.com/group/comp.lang.python/t/d55388b0fdd9ed2f/ Using dynamic property names: http://groups.google.com/group/comp.lang.python/t/f7b8829c97dcc3f9/ How can a module react differently when imported from one place or another? http://groups.google.com/group/comp.lang.python/t/da162dc08f1c3550/ Sharing distributed objects between Python and C++: http://groups.google.com/group/comp.lang.python/t/5a567a1a180511eb/ Beware: threads + import don't mix well! http://groups.google.com/group/comp.lang.python/t/a60c83590a016528/ locals() and frame.f_locals return old data: http://groups.google.com/group/comp.lang.python/t/fa17941218c6e89e/ Instantiate classes using names from the command line: http://groups.google.com/group/comp.lang.python/t/d597a1a42b88c0d1/ New syntax proposal: if some_expression as x: do_something_with(x) http://groups.google.com/group/comp.lang.python/t/55e7578903747dc4/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 gagsl-py2 at yahoo.com.ar Mon Nov 16 11:03:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:03:16 -0300 Subject: C api question and determining PyObject type References: Message-ID: En Mon, 16 Nov 2009 07:44:34 -0300, lallous escribi?: > Actually, the object class is defined as: > class __object(object): > def __getitem__(self, idx): > return getattr(self, idx) > > Anyway, now I check like this: > > bool PyIsSequenceType(PyObject *obj) > { > if (!PySequence_Check(obj)) > return false; > Py_ssize_t sz = PySequence_Size(obj); > if (sz == -1 || PyErr_Occurred() != NULL) > { > PyErr_Clear(); > return false; > } > return true; > } > > I don't like it, any other suggestions? Yes: find another name for the "thing" you're checking for. It's not the same as a "sequence" in the Python sense. Perhaps you want to consider your type a mapping? Sequences and mappings have a lot in common (mappings have length too.) In C you have separate slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is used for both meanings (and goes into both set of pointers.) tp_as_mapping takes precedence over tp_as_sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 16 11:03:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:03:16 -0300 Subject: C api question and determining PyObject type References: Message-ID: En Mon, 16 Nov 2009 07:44:34 -0300, lallous escribi?: > Actually, the object class is defined as: > class __object(object): > def __getitem__(self, idx): > return getattr(self, idx) > > Anyway, now I check like this: > > bool PyIsSequenceType(PyObject *obj) > { > if (!PySequence_Check(obj)) > return false; > Py_ssize_t sz = PySequence_Size(obj); > if (sz == -1 || PyErr_Occurred() != NULL) > { > PyErr_Clear(); > return false; > } > return true; > } > > I don't like it, any other suggestions? Yes: find another name for the "thing" you're checking for. It's not the same as a "sequence" in the Python sense. Perhaps you want to consider your type a mapping? Sequences and mappings have a lot in common (mappings have length too.) In C you have separate slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is used for both meanings (and goes into both set of pointers.) tp_as_mapping takes precedence over tp_as_sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 16 11:20:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:20:00 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> <3F923692-C191-4477-879B-1921C0268EB4@me.com> Message-ID: En Mon, 16 Nov 2009 11:11:20 -0300, Tommy Grav escribi?: > On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote: >> En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross >> escribi?: >> >>> I'm attempting to convert latitude and longitude coordinates from >>> degrees >>> minutes and second to decimal form. I would like to go from: >>> N39 42 36.3 W77 42 51.5 >>> to: >>> -77.739855,39.706666 >> >> decimal = degrees + minutes/60.0 + seconds/3600.0 >> N,E are positive; S,W are negative. >> But the above numbers don't match. > > It is more complicated than that. For negative numbers the value is > degrees -minutes/60. - seconds/3600. > And people always trip up on numbers that start with -00 :) I set the sign of the result *after* computing it, so it doesn't matter. py> 39 + 42/60.0 + 36.3/3600 39.710083333333337 py> 77 + 42/60.0 + 51.5/3600 77.714305555555555 Either the example above is incorrect, or there is another thing involved. -- Gabriel Genellina From tjreedy at udel.edu Mon Nov 16 11:22:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 11:22:49 -0500 Subject: A "terminators' club" for clp In-Reply-To: References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: kj wrote: > In <7x3a4i56u7.fsf at ruckus.brouhaha.com> Paul Rubin writes: > >> kj writes: >>> frequent* clp posters the ability to *easily* delete spam from the >>> comp.lang.python server? > >> Um, this is usenet; there is no comp.lang.python server. Are you >> saying you want a moderated newsgroup? Hmm, maybe this group is busy >> enough that there is some merit to that idea. > > Sorry, I had a mistaken view of how usenet was implemented. But > yeah, I guess I'm thinking of a moderated newsgroup, but with a > large number of moderators working in parallel, and a very lax > acceptance policy. The goal is to filter out only the obvious > spam, and let through all the other non-spam traffic as quickly as > possible... What do I mean by "obvious spam"? Well, among the > most recent messages (that have survived my killfile policies) I > see the following subject lines: > > * Top 10 US mp3 songs.....Cheers > * www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red monkey gino green global true religion ed-hardy kidrobot jeans hoodies china supplier wholesaler exporters,manufacture > * "jobs in france" "jobs in france for english people" "jobs in france for foreigners" "jobs in france for australians" "jobs in france for foreigners " "jobs in france for new zealanders" "jobs" "paris jobs" http://jobs-in-fr ance.blogspot.com/ > * "germany jobs" "germany job sites" "germany job search" "jobs in germany" "german jobs" "germany jobs it" "germany jobs for foreigners" "germany jobsite" "germany jobs in english" on http://jobs-germany.blogspot.com/ > > Those look pretty obvious to me. > > But, as I already showed, I'm out of my depth here, > so I'd better shut up. Some usenet newsgroups were/are moderated either by a robot, a person, or a team (as you suggested). But a particular newsgroup has to be set up that way from the beginning. Last I knew, it wan/is? difficult to convert an unmoderated group to moderation. Terry Jan Reedy From tjreedy at udel.edu Mon Nov 16 11:35:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 11:35:40 -0500 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? gmane.comp.python.tutor, which I believe mirrors the tutor-list From davea at ieee.org Mon Nov 16 11:48:12 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 11:48:12 -0500 Subject: Image to SVG conversion with Python In-Reply-To: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: <4B01824C.2080109@ieee.org> Carlo DiCelico wrote: > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > to generate the JPEG/PNG files to begin with. However, I need to be > able to scale the generated images up in size without a loss of image > quality. Using SVG seems to be the best way to do this, other than > generating the images in the maximum size/resolution in the first > place, which would be too resource intensive. > > I've looked around online and have found some tools for creating SVGs > but none for converting an image into SVG. > > Does anyone have any experience doing this? What would be the best way > to go about this? > > Thanks, > Carlo > > I have no direct experience with SVG, but have used and analyzed other formats. I expect it's unreasonable to convert jpg or png files to SVG. The latter is a vector format, and can't efficiently represent pixels, which is all you have in the jpg files. And even if you did it brute force, it still wouldn't scale any better than the original jpg. If the jpg file was generated from lines, and wasn't too crowded, it *might* be possible to analyze it to reconstruct the vectors, but it would be both very slow, and inaccurate. In Photoshop PSD files, you can have vector layers and RGB layers (plus other kinds). You convert a vector layer (such as text) to bits by rasterizing (or flattening). And once you do, it no longer scales cleanly. For instance, when I'm sending composite images to a printer, I get much better quality sending the raster portion separate from the text, either as layers in a PSD file, or in a PDF file, or even as two separate files that they will merge later. (In that case, I usually send a low-res flattened file, so they can see how it's supposed to look) I'd say you should change your python code to generate the svg files first (perhaps using http://code.activestate.com/recipes/325823/ ) Then you might want to use ( http://www.imagemagick.org/script/index.php ) to convert it to jpg or other format. DaveA From steve.ferg.bitbucket at gmail.com Mon Nov 16 11:54:28 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 16 Nov 2009 08:54:28 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? Message-ID: This is a question for the language mavens that I know hang out here. It is not Python related, except that recent comparisons of Python to Google's new Go language brought it to mind. NOTE that this is *not* a suggestion to change Python. I like Python just the way it is. I'm just curious about language design. For a long time I've wondered why languages still use blocks (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. I've often thought that a language with this kind of block-free syntax would be nice and intuitive: if then do stuff elif then do stuff else do stuff endif Note that you do not need block delimiters. Obviously, you could make a more Pythonesque syntax by using a colon rather then "then" for the condition terminator. You could make it more PL/I-like by using "do", etc. You can write shell scripts using if ... fi, but other than that I don't recall a language with this kind of syntax. Does anybody know a language with this kind of syntax for ifThenElseEndif? Is there any particular reason why this might be a *bad* language- design idea? From robin at reportlab.com Mon Nov 16 12:03:20 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:03:20 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B0185D8.8040305@chamonix.reportlab.co.uk> Steve Ferg wrote: ......... > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? ....... modern sh seems to use this with "fi" as endif eg ~: $ if true; then > echo true > elif false; then > echo false > else > echo hostile logic > fi true ~: $ -- Robin Becker From carlo.dicelico at gmail.com Mon Nov 16 12:06:42 2009 From: carlo.dicelico at gmail.com (Carlo DiCelico) Date: Mon, 16 Nov 2009 09:06:42 -0800 (PST) Subject: Image to SVG conversion with Python References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: <396dc22b-0dde-4434-9c38-d150d9bb027c@m20g2000vbp.googlegroups.com> On Nov 16, 11:48?am, Dave Angel wrote: > Carlo DiCelico wrote: > > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > > to generate the JPEG/PNG files to begin with. However, I need to be > > able to scale the generated images up in size without a loss of image > > quality. Using SVG seems to be the best way to do this, other than > > generating the images in the maximum size/resolution in the first > > place, which would be too resource intensive. > > > I've looked around online and have found some tools for creating SVGs > > but none for converting an image into SVG. > > > Does anyone have any experience doing this? What would be the best way > > to go about this? > > > Thanks, > > Carlo > > I have no direct experience with SVG, but have used and analyzed other > formats. > > I expect it's unreasonable to convert jpg or png files to SVG. ?The > latter is a vector format, and can't efficiently represent pixels, which > is all you have in the jpg files. ?And even if you did it brute force, > it still wouldn't scale any better than the original jpg. ?If the jpg > file was generated from lines, and wasn't too crowded, it *might* be > possible to analyze it to reconstruct the vectors, but it would be both > very slow, and inaccurate. > > In Photoshop PSD files, you can have vector layers and RGB layers (plus > other kinds). ?You convert a vector layer (such as text) to bits by > rasterizing (or flattening). ?And once you do, it no longer scales > cleanly. ?For instance, when I'm sending composite images to a printer, > I get much better quality sending the raster portion separate from the > text, either as layers in a PSD file, or in a PDF file, or even as two > separate files that they will merge later. ?(In that case, I usually > send a low-res flattened file, so they can see how it's supposed to look) > > I'd say you should change your python code to generate the svg files > first (perhaps usinghttp://code.activestate.com/recipes/325823/) > > Then you might want to use (http://www.imagemagick.org/script/index.php > ) to convert it to jpg or other format. > > DaveA Thanks, this makes perfect sense. From james.harris.1 at googlemail.com Mon Nov 16 12:09:12 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Mon, 16 Nov 2009 09:09:12 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <80bb6965-475f-4a7a-906e-09736d92e6a2@k17g2000yqh.googlegroups.com> On 16 Nov, 16:54, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? There are some. For example, Ada uses similar. See http://en.wikipedia.org/wiki/Ada_%28programming_language%29#Control_structures These other newsgroups may be of interest: comp.programming comp.lang.misc The latter is used by people designing programming languages where you can find knowledgeable comments aplenty. James From acherry at btinternet.com Mon Nov 16 12:16:46 2009 From: acherry at btinternet.com (Adrian Cherry) Date: 16 Nov 2009 17:16:46 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: Steve Ferg wrote in news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 at p36g2000vbn.googlegro ups.com: > This is a question for the language mavens that I know hang > out here. It is not Python related, except that recent > comparisons of Python to Google's new Go language brought it > to mind. > > NOTE that this is *not* a suggestion to change Python. I > like Python just the way it is. I'm just curious about > language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse > statements. > > I've often thought that a language with this kind of > block-free syntax would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using > a colon rather then "then" for the condition terminator. > You could make it more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than > that I don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* > language- design idea? I believe MATLAB has similar if syntax - please correct me if I'm wrong. From http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html "The if function can be used alone or with the else and elseif functions. When using elseif and/or else within an if statement, the general form of the statement is" if expression1 statements1 elseif expression2 statements2 else statements3 end Adrian From ecir.hana at gmail.com Mon Nov 16 12:17:52 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Mon, 16 Nov 2009 09:17:52 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: Message-ID: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> On Nov 15, 5:28?pm, Ecir Hana wrote: > Hello, > > I'm trying to write a simple Win32 app, which may run some Python > scripts. Since it is a Windows GUI app, I would like to redirect all > output (Python print, C printf, fprinf stderr, ...) to a text area > inside the app. In other words, I'm trying to log all the output from > the app (C, Python) to a window. So far, this works for C printf(): > > int fds[2]; > _pipe(fds, 1024, O_TEXT); > _dup2(fds[1], 1); > ... > and then I read from pipe's read-end and append the text to the text > area. > > But when I try to run: > Py_Initialize(); > PyRun_SimpleString("print 'abc'"); > Py_Finalize(); > > I get an error: > IOError: [Errno 9] Bad file descriptor > > What am I doing wrong? How to redirect standard IO, both for C and for > Python? > PS: Maybe I'm doind something wrong, but SetStdHandle() does not work > at all.... Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. From georgeolivergo at gmail.com Mon Nov 16 12:33:13 2009 From: georgeolivergo at gmail.com (George Oliver) Date: Mon, 16 Nov 2009 09:33:13 -0800 (PST) Subject: Newsgroup for beginners References: Message-ID: On Nov 16, 8:35?am, Terry Reedy wrote: > mrholtsr wrote: > > Is there a Python newsgroup for those who are strictly beginners at > > programming and python? > > gmane.comp.python.tutor, which I believe mirrors the tutor-list There also is a beginner's forum at python-forum.org: http://www.python-forum.org/pythonforum/viewforum.php?f=3 From python at mrabarnett.plus.com Mon Nov 16 12:39:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 17:39:20 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B018E48.8030505@mrabarnett.plus.com> Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. I like Python > just the way it is. I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? Ada and Turing have: if then do stuff elsif then do stuff else do stuff end if Comal has: if then do stuff elif then do stuff else do stuff end if Modula-2 has: if then do stuff elsif then do stuff else do stuff end From robin at reportlab.com Mon Nov 16 12:42:12 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:42:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <4B0185D8.8040305@chamonix.reportlab.co.uk> References: <4B0185D8.8040305@chamonix.reportlab.co.uk> Message-ID: <4B018EF4.7080603@chamonix.reportlab.co.uk> Robin Becker wrote: ....... > modern sh seems to use this with "fi" as endif eg > > ~: > $ if true; then > > echo true > > elif false; then > > echo false > > else > > echo hostile logic > > fi > true > ~: > $ > I meant to say that since sh uses this construct it cannot be too bad as a language construct since the world is built with sh and bash and similar. Of course that's a bad argument since there's more cobol than everything else put together (allegedly). -- Robin Becker From robin at reportlab.com Mon Nov 16 12:42:12 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:42:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <4B0185D8.8040305@chamonix.reportlab.co.uk> References: <4B0185D8.8040305@chamonix.reportlab.co.uk> Message-ID: <4B018EF4.7080603@chamonix.reportlab.co.uk> Robin Becker wrote: ....... > modern sh seems to use this with "fi" as endif eg > > ~: > $ if true; then > > echo true > > elif false; then > > echo false > > else > > echo hostile logic > > fi > true > ~: > $ > I meant to say that since sh uses this construct it cannot be too bad as a language construct since the world is built with sh and bash and similar. Of course that's a bad argument since there's more cobol than everything else put together (allegedly). -- Robin Becker From nobody at nowhere.com Mon Nov 16 12:53:01 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 17:53:01 +0000 Subject: import subprocess in python References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> <0834aa40-c2f8-4865-aa8d-cc9c4c272b0a@v25g2000yqk.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 04:58:00 -0800, sturlamolden wrote: > On 16 Nov, 13:50, Kuhl wrote: > >> Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > >> What's the mistake that I am making? How to solve it? > > Your Python version is too old. Your Python version is *way* too old. If you're lucky, people who use features of Python 2.5 or 2.6 will mention that you need Python 2.5 or 2.6, but having at least Python 2.4 is generally taken for granted. From nobody at nowhere.com Mon Nov 16 12:58:07 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 17:58:07 +0000 Subject: Image to SVG conversion with Python References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 07:19:49 -0800, Carlo DiCelico wrote: > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > to generate the JPEG/PNG files to begin with. However, I need to be > able to scale the generated images up in size without a loss of image > quality. Using SVG seems to be the best way to do this, other than > generating the images in the maximum size/resolution in the first > place, which would be too resource intensive. > > I've looked around online and have found some tools for creating SVGs > but none for converting an image into SVG. > > Does anyone have any experience doing this? What would be the best way > to go about this? JPEG/PNG are raster formats, SVG is a vector format. To convert raster graphics to vector graphics, you need a "tracing" program (aka "image tracing", "vector tracing", "vectorizing"), e.g. potrace (this program is often bundled with InkScape): http://potrace.sourceforge.net/ From nobody at nowhere.com Mon Nov 16 13:17:12 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 18:17:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote: > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > Does anybody know a language with this kind of syntax for > ifThenElseEndif? BBC BASIC V had if/then/else/endif (it didn't have elif). "make" has if/else/else/endif (it doesn't have a dedicated elif, but "else if ..." behaves like elif rather than starting a nested "if"). > Is there any particular reason why this might be a *bad* language- > design idea? Blocks can be useful for other reasons (e.g. limiting variable scope), so if you already have them, you don't need to provide dedicated blocks for control constructs. From toby at rcsreg.com Mon Nov 16 13:21:08 2009 From: toby at rcsreg.com (Tobiah) Date: Mon, 16 Nov 2009 18:21:08 GMT Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: >> Let me >> be clear, given 2min, how many primes can you find, they need not be in >> order or consecutive. Do they have to go from low to high? :( ) From gagsl-py2 at yahoo.com.ar Mon Nov 16 13:21:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 15:21:10 -0300 Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> Message-ID: En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana escribi?: >> I'm trying to write a simple Win32 app, which may run some Python >> scripts. Since it is a Windows GUI app, I would like to redirect all >> output (Python print, C printf, fprinf stderr, ...) to a text area >> inside the app. In other words, I'm trying to log all the output from >> the app (C, Python) to a window. So far, this works for C printf(): >> [...] >> PS: Maybe I'm doind something wrong, but SetStdHandle() does not work >> at all.... This worked for me: #include #include "Python.h" int main() { HANDLE hReadPipe, hWritePipe; DWORD nr, nw; char buffer[100]; CreatePipe( &hReadPipe, &hWritePipe, NULL, 1024); SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe); Py_Initialize(); PyRun_SimpleString("print 'from Python'"); Py_Finalize(); puts("from C\n"); CloseHandle(hWritePipe); ReadFile(hReadPipe, buffer, 19, &nr, NULL); CloseHandle(hReadPipe); WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); } > Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. I'm using Visual Studio 2008 Express Edition. -- Gabriel Genellina From mmitchell at transparent.com Mon Nov 16 13:30:02 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Mon, 16 Nov 2009 13:30:02 -0500 Subject: tkFileDialog question In-Reply-To: References: Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of r Sent: Monday, November 16, 2009 12:16 AM To: python-list at python.org Subject: Re: tkFileDialog question Matt, There is also a nice thing you need to know about Python if you already do not know. That is the fact that all empty collections bool to False. This makes Truth testing easier. >>> bool([]) False >>> bool('') False >>> bool({}) False >>> bool([1]) True >>> bool([[]]) True >>> bool(' ') True any empty collection, string, or 0 always bools to False. -- http://mail.python.org/mailman/listinfo/python-list Thank you both for all the help. Your suggestions have helped clean up a bunch of my code. Thanks! Matt From showell30 at yahoo.com Mon Nov 16 13:32:19 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 10:32:19 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Nov 16, 2:35?am, Carl Banks wrote: > On Nov 15, 2:52?pm, Steve Howell wrote: > > > Does anybody have any links that points to the rationale for ignoring > > instance definitions of __getitem__ when new-style classes are > > involved? ?I assume it has something to do with performance or > > protecting us from our own mistakes? > > "Not important enough to justify complexity of implementation." > > I doubt they would have left if out of new-style classes if it had > been straightforward to implement (if for no other reason than to > retain backwards compatibility), but it wasn't. ?The way attribute > lookups work meant it would have required all kinds of double lookups > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > easily worked around by simply having __getitem__ call another method, > as you've seen. ?Given all this it made better sense to just leave it > out of new-style classes. Actually, the __getitem__ workaround that I proposed earlier only works on subclasses of dict, not dict themselves. So given a pure dictionary object, it is impossible to hook into attribute lookups after instantiation in debugging/tracing code. I know it's not a super common thing to do, but it is a legitimate use case from my perspective. But I understand the tradeoffs. They seem kind of 20th century to me, but with Moore's Law declining and all, maybe it's a bad time to bring up the "flexibility trumps performance" argument. ;) The backward compatibility argument also seems a little dubious, because if anybody *had* put __getitem__ on a dictionary instance before, it would have already been broken code, and if they hadn't done it, there would be no semantic change, just a performance hit, albeit a pervasive one. > Unfortunately not all such decisions and justifications are collected > in a tidy place. > Yep, that's why I was asking here. I figured somebody might remember a thread on python-dev where this was discussed, or something like that. From python at mrabarnett.plus.com Mon Nov 16 13:37:22 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 18:37:22 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B019BE2.1050105@mrabarnett.plus.com> Nobody wrote: > On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote: > >> For a long time I've wondered why languages still use blocks >> (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. >> >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. > >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? > > BBC BASIC V had if/then/else/endif (it didn't have elif). > I forgot about that one. :-( I used to do this in order if I wanted to avoid a lot of indentation: CASE TRUE OF WHEN do something WHEN do something OTHERWISE do something ENDCASE > "make" has if/else/else/endif (it doesn't have a dedicated elif, but > "else if ..." behaves like elif rather than starting a nested "if"). > >> Is there any particular reason why this might be a *bad* language- >> design idea? > > Blocks can be useful for other reasons (e.g. limiting variable scope), so > if you already have them, you don't need to provide dedicated blocks > for control constructs. > From x7-g5W_rt at earthlink.net Mon Nov 16 13:57:36 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Mon, 16 Nov 2009 10:57:36 -0800 (PST) Subject: A "terminators' club" for clp References: <70529349-696e-4f67-8b65-068dc84b71f4@e20g2000vbb.googlegroups.com> Message-ID: On Nov 14, 12:08?pm, r wrote: > On Nov 14, 7:28?am, gil_johnson wrote: > Actually there is a "rank this post" (gotta be careful with that > verbage!) AND a "report this post as spam". Of course it only exists > in GG's and not Usenet. I *do* know that the star system is used quite > frequently, but i doubt anyone bothers to use the "report as spam" > link since it seems have no effect whatsoever. Heh. I should look around more before posting. It does prove your point, though. The 'spam' button is ubiquitous, but so seldom used it's forgotten. Actually, my enthusiasm for my idea faded with a little thought. It is an extra effort to open spam to get to the 'spam' button, and sends the message to the spammer that people are, indeed opening their junk. I'd use it if I opened a message with a deceptive subject. Gil From vs at it.uu.se Mon Nov 16 14:17:18 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 16 Nov 2009 20:17:18 +0100 Subject: Web servers Message-ID: <4B01A53E.1030903@it.uu.se> Any suggestions on using Python to connect to Web servers (e.g. to access financial time series data)? --V. Stokes From clp2 at rebertia.com Mon Nov 16 14:20:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:20:29 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50697b2c0911161120n5669d0caqf259d3fcca2a5e13@mail.gmail.com> On Mon, Nov 16, 2009 at 8:54 AM, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ?if then > ? ? ? ?do stuff > ? ?elif then > ? ? ? ?do stuff > ? ?else > ? ? ? ?do stuff > ? ?endif > > Note that you do not need block delimiters. > Does anybody know a language with this kind of syntax for > ifThenElseEndif? Ruby: if count > 10 puts "Try again" elsif tries == 3 puts "You lose" else puts "Enter a number" end Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Nov 16 14:22:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:22:26 -0800 Subject: Web servers In-Reply-To: <4B01A53E.1030903@it.uu.se> References: <4B01A53E.1030903@it.uu.se> Message-ID: <50697b2c0911161122m7be41b8eoeec1acc787d1a503@mail.gmail.com> On Mon, Nov 16, 2009 at 11:17 AM, Virgil Stokes wrote: > Any suggestions on using Python to connect to Web servers (e.g. to access > financial time series data)? In what format? Using what protocol? (*Insert other basic questions that need answering in order to answer your question here*) Cheers, Chris -- http://blog.rebertia.com From vicente.soler at gmail.com Mon Nov 16 14:36:49 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 16 Nov 2009 11:36:49 -0800 (PST) Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Message-ID: <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> On Nov 16, 2:35?am, "Gabriel Genellina" wrote: > En Sun, 15 Nov 2009 09:04:06 -0300, vsoler > escribi?: > > > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > > been saving my > > *.py files in the C:\Program Files\Python26 directory, which is the > > default directory for such files in my system. > > > However, I have realised that the above is not the best practice. > > Therefore I created the C:\Program Files\Python26\test directory and I > > want it to be my default directory for saving *.py files, importing > > modules, etc. > > This is *not* a good place either. Non-privileged users should not have > write permission in the C:\Program Files directory. > > > I'd like to do something like the DOS equivalent of ? "CD test" but I > > do not know kow to do it. > > > I am currently doing something really awful: I open a *.py file in the > > test subdirectory, I run it with the F5 key and it works! but I am > > doing really something stupid. > > "it works!" What's the problem then? > > > How should I proceed, if I want to proceed properly? > > Sorry but I don't even see your problem. You can save your .py files ? > anywhere you like... > > -- > Gabriel Genellina Gabriel, When I enter IDLE, I'd like to say at the prompt: "my current directory is... ...test" and then be able to run a module in that directory. This is what my problem is!!! Thank you if you can help From clp2 at rebertia.com Mon Nov 16 14:45:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:45:31 -0800 Subject: Changing the current directory (full post) In-Reply-To: <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> Message-ID: <50697b2c0911161145q1b0d7ae6w2c6bcea56663c38d@mail.gmail.com> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: > On Nov 16, 2:35?am, "Gabriel Genellina" > wrote: >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> escribi?: >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> > been saving my >> > *.py files in the C:\Program Files\Python26 directory, which is the >> > default directory for such files in my system. >> >> > However, I have realised that the above is not the best practice. >> > Therefore I created the C:\Program Files\Python26\test directory and I >> > want it to be my default directory for saving *.py files, importing >> > modules, etc. >> >> This is *not* a good place either. Non-privileged users should not have >> write permission in the C:\Program Files directory. >> >> > I'd like to do something like the DOS equivalent of ? "CD test" but I >> > do not know kow to do it. >> >> > I am currently doing something really awful: I open a *.py file in the >> > test subdirectory, I run it with the F5 key and it works! but I am >> > doing really something stupid. >> >> "it works!" What's the problem then? >> >> > How should I proceed, if I want to proceed properly? >> >> Sorry but I don't even see your problem. You can save your .py files >> anywhere you like... >> >> -- >> Gabriel Genellina > > Gabriel, > > When I enter IDLE, I'd like to say at the prompt: "my current > directory is... ?...test" and then be able to run a module in that > directory. This is what my problem is!!! 1. File -> Open 2. Navigate to file and choose it 3. Press F5 Cheers, Chris -- http://blog.rebertia.com From vicente.soler at gmail.com Mon Nov 16 14:56:49 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 16 Nov 2009 11:56:49 -0800 (PST) Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> Message-ID: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> On Nov 16, 8:45?pm, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: > > On Nov 16, 2:35?am, "Gabriel Genellina" > > wrote: > >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler > >> escribi?: > > >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > >> > been saving my > >> > *.py files in the C:\Program Files\Python26 directory, which is the > >> > default directory for such files in my system. > > >> > However, I have realised that the above is not the best practice. > >> > Therefore I created the C:\Program Files\Python26\test directory and I > >> > want it to be my default directory for saving *.py files, importing > >> > modules, etc. > > >> This is *not* a good place either. Non-privileged users should not have > >> write permission in the C:\Program Files directory. > > >> > I'd like to do something like the DOS equivalent of ? "CD test" but I > >> > do not know kow to do it. > > >> > I am currently doing something really awful: I open a *.py file in the > >> > test subdirectory, I run it with the F5 key and it works! but I am > >> > doing really something stupid. > > >> "it works!" What's the problem then? > > >> > How should I proceed, if I want to proceed properly? > > >> Sorry but I don't even see your problem. You can save your .py files > >> anywhere you like... > > >> -- > >> Gabriel Genellina > > > Gabriel, > > > When I enter IDLE, I'd like to say at the prompt: "my current > > directory is... ?...test" and then be able to run a module in that > > directory. This is what my problem is!!! > > 1. File -> Open > 2. Navigate to file and choose it > 3. Press F5 > > Cheers, > Chris > --http://blog.rebertia.com Say that you wanted to import a file in the test directory after just entering IDLE. How would you do it? From rami.chowdhury at gmail.com Mon Nov 16 15:10:56 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 16 Nov 2009 12:10:56 -0800 Subject: Changing the current directory (full post) In-Reply-To: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 11:56:49 -0800, vsoler wrote: > On Nov 16, 8:45?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler >> wrote: >> > On Nov 16, 2:35?am, "Gabriel Genellina" >> > wrote: >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> >> escribi?: >> >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> >> > been saving my >> >> > *.py files in the C:\Program Files\Python26 directory, which is the >> >> > default directory for such files in my system. >> >> >> > However, I have realised that the above is not the best practice. >> >> > Therefore I created the C:\Program Files\Python26\test directory >> and I >> >> > want it to be my default directory for saving *.py files, importing >> >> > modules, etc. >> >> >> This is *not* a good place either. Non-privileged users should not >> have >> >> write permission in the C:\Program Files directory. >> >> >> > I'd like to do something like the DOS equivalent of ? "CD test" >> but I >> >> > do not know kow to do it. >> >> >> > I am currently doing something really awful: I open a *.py file in >> the >> >> > test subdirectory, I run it with the F5 key and it works! but I am >> >> > doing really something stupid. >> >> >> "it works!" What's the problem then? >> >> >> > How should I proceed, if I want to proceed properly? >> >> >> Sorry but I don't even see your problem. You can save your .py files >> >> anywhere you like... >> >> >> -- >> >> Gabriel Genellina >> >> > Gabriel, >> >> > When I enter IDLE, I'd like to say at the prompt: "my current >> > directory is... ?...test" and then be able to run a module in that >> > directory. This is what my problem is!!! >> >> 1. File -> Open >> 2. Navigate to file and choose it >> 3. Press F5 >> >> Cheers, >> Chris >> --http://blog.rebertia.com > > Say that you wanted to import a file in the test directory after just > entering IDLE. How would you do it? http://docs.python.org/library/os.html#os.chdir and http://docs.python.org/library/sys.html#sys.path may be able to help you... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From clp2 at rebertia.com Mon Nov 16 15:11:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 12:11:19 -0800 Subject: Changing the current directory (full post) In-Reply-To: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> Message-ID: <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> On Mon, Nov 16, 2009 at 11:56 AM, vsoler wrote: > On Nov 16, 8:45?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: >> > On Nov 16, 2:35?am, "Gabriel Genellina" >> > wrote: >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> >> escribi?: >> >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> >> > been saving my >> >> > *.py files in the C:\Program Files\Python26 directory, which is the >> >> > default directory for such files in my system. >> >> >> > However, I have realised that the above is not the best practice. >> >> > Therefore I created the C:\Program Files\Python26\test directory and I >> >> > want it to be my default directory for saving *.py files, importing >> >> > modules, etc. >> >> >> This is *not* a good place either. Non-privileged users should not have >> >> write permission in the C:\Program Files directory. >> >> >> > I'd like to do something like the DOS equivalent of ? "CD test" but I >> >> > do not know kow to do it. >> >> >> > I am currently doing something really awful: I open a *.py file in the >> >> > test subdirectory, I run it with the F5 key and it works! but I am >> >> > doing really something stupid. >> >> >> "it works!" What's the problem then? >> >> >> > How should I proceed, if I want to proceed properly? >> >> >> Sorry but I don't even see your problem. You can save your .py files >> >> anywhere you like... >> >> > When I enter IDLE, I'd like to say at the prompt: "my current >> > directory is... ?...test" and then be able to run a module in that >> > directory. This is what my problem is!!! >> >> 1. File -> Open >> 2. Navigate to file and choose it >> 3. Press F5 > > Say that you wanted to import a file in the test directory after just > entering IDLE. How would you do it? import sys sys.path.insert(0, "C:/path/to/test/dir/here") import something_in_test_dir Cheers, Chris -- http://blog.rebertia.com From rt8396 at gmail.com Mon Nov 16 15:11:22 2009 From: rt8396 at gmail.com (r) Date: Mon, 16 Nov 2009 12:11:22 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 10:54?am, Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif WHY? Python's syntax is by far the most elegant of all, no need to show the end of a block. Python is the smartest kid on the block. And are you saying you would rather type "then" instead of ":" and "endif" instead of "\n"? No thanks! From pedro.al at fenhi.uh.cu Mon Nov 16 15:27:24 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Mon, 16 Nov 2009 15:27:24 -0500 Subject: TODO and FIXME tags Message-ID: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Hi all.. Sorry if this question sound elemental. How is the sintaxis for set the TODO and FIXME tags...? Thanks -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From davea at ieee.org Mon Nov 16 15:29:24 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 15:29:24 -0500 Subject: Web servers In-Reply-To: <4B01A53E.1030903@it.uu.se> References: <4B01A53E.1030903@it.uu.se> Message-ID: <4B01B624.7030102@ieee.org> Virgil Stokes wrote: >

    Any > suggestions on using Python to connect to Web servers (e.g. to access > financial time series data)? > > --V. Stokes > > > You can open a web page for reading with urllib2 module. You can parse html with beautiful soup, or if it's clean xhtml, with the xml module. But parsing raw html is error prone, and subject to change as the web designer reorganizes things. So many web servers also have a protocol intended for data (as opposed to intended for a browser). This is specific to each service, however. If you want to get started in your reading, you could google for "web services", which is one approach using SOAP & WSDL. Note also that most servers have restrictions on the data you access this way. They may or may not be enforceable, but if you access a lot of data from a server, you may be too big a drain on its resources, if it's configured for browser access only. DaveA From henryzhang62 at yahoo.com Mon Nov 16 15:33:15 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Mon, 16 Nov 2009 12:33:15 -0800 (PST) Subject: directory wildcard Message-ID: <637551.57013.qm@web57906.mail.re3.yahoo.com> List, I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) Any right way to do it? Thanks. --henry From falk at mauve.rahul.net Mon Nov 16 15:40:30 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 16 Nov 2009 20:40:30 +0000 (UTC) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: In article , Steve Ferg wrote: >I've often thought that a language with this kind of block-free syntax >would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > >Note that you do not need block delimiters. "then", "else", and "endif" *are* the block delimiters -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From robert.kern at gmail.com Mon Nov 16 15:51:43 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 Nov 2009 14:51:43 -0600 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: On 2009-11-16 14:40 PM, Edward A. Falk wrote: > In article, > Steve Ferg wrote: >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. > > "then", "else", and "endif" *are* the block delimiters I think he meant that you don't need *extra* block delimiters or generic block delimiters like {}. -- 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 deets at nospam.web.de Mon Nov 16 15:54:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Nov 2009 21:54:36 +0100 Subject: directory wildcard In-Reply-To: References: Message-ID: <7mdsgcF3hdui1U1@mid.uni-berlin.de> hong zhang schrieb: > List, > > I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: > > os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? Don't use os system. Use subprocess. Which incidentially is mentioned in the docs for os.system: http://docs.python.org/library/os.html#os.system Then you can pass the "use_shell=True" parameter - which should work in your case. Diez From jeff at jmcneil.net Mon Nov 16 16:01:59 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 16 Nov 2009 13:01:59 -0800 (PST) Subject: directory wildcard References: Message-ID: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> On Nov 16, 3:33?pm, hong zhang wrote: > List, > > I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: > > os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? > > Thanks. > > --henry I'd ditch the echo business altogether. 2.x. Not tested. import glob mcs = get_mcs_from_somewhere() for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/ force_mcs'): with open(i, 'w') as f: print >>f, mcs Thanks, Jeff mcjeff.blogspot.com From ecir.hana at gmail.com Mon Nov 16 16:04:21 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Mon, 16 Nov 2009 13:04:21 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> Message-ID: <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> On Nov 16, 7:21?pm, "Gabriel Genellina" wrote: > En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana ? > escribi?: > > >> I'm trying to write a simple Win32 app, which may run some Python > >> scripts. Since it is a Windows GUI app, I would like to redirect all > >> output (Python print, C printf, fprinf stderr, ...) to a text area > >> inside the app. In other words, I'm trying to log all the output from > >> the app (C, Python) to a window. So far, this works for C printf(): > >> [...] > >> PS: Maybe I'm doind something wrong, but SetStdHandle() does not work > >> at all.... > > This worked for me: > > #include > #include "Python.h" > > int main() > { > ? ?HANDLE hReadPipe, hWritePipe; > ? ?DWORD nr, nw; > ? ?char buffer[100]; > > ? ?CreatePipe( > ? ? ?&hReadPipe, > ? ? ?&hWritePipe, > ? ? ?NULL, > ? ? ?1024); > ? ?SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe); > > ? ?Py_Initialize(); > ? ?PyRun_SimpleString("print 'from Python'"); > ? ?Py_Finalize(); > > ? ?puts("from C\n"); > > ? ?CloseHandle(hWritePipe); > ? ?ReadFile(hReadPipe, buffer, 19, &nr, NULL); > ? ?CloseHandle(hReadPipe); > ? ?WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); > > } > > Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. > > I'm using Visual Studio 2008 Express Edition. > > -- > Gabriel Genellina Hi, thanks for the reply! However, please, could you tell me how many bytes it read here: ReadFile(hReadPipe, buffer, 19, &nr, NULL); because for me, it has read 0. When I run your code, it prints from both C and Python, but it prints straight to the console, not to the buffer. Could you also please try to add: WriteFile(GetStdHandle(STD_ERROR_HANDLE), "----\n", 5, &nw, NULL); before: WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); Does it print "----" before "from Python" and "from C" for you? Because for me it comes afterwards (as nr is 0)... From davea at ieee.org Mon Nov 16 16:10:51 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 16:10:51 -0500 Subject: Changing the current directory (full post) In-Reply-To: <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> Message-ID: <4B01BFDB.7090806@ieee.org> Chris Rebert wrote: > On Mon, Nov 16, 2009 at 11:56 AM, vsoler wrote: > >> On Nov 16, 8:45 pm, Chris Rebert wrote: >> >>> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: >>> >>>> On Nov 16, 2:35 am, "Gabriel Genellina" >>>> wrote: >>>> >>>>> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >>>>> escribi?: >>>>> >>>>>> Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >>>>>> been saving my >>>>>> *.py files in the C:\Program Files\Python26 directory, which is the >>>>>> default directory for such files in my system. >>>>>> >>>>>> However, I have realised that the above is not the best practice. >>>>>> Therefore I created the C:\Program Files\Python26\test directory and I >>>>>> want it to be my default directory for saving *.py files, importing >>>>>> modules, etc. >>>>>> >>>>> This is *not* a good place either. Non-privileged users should not have >>>>> write permission in the C:\Program Files directory. >>>>> >>>>>> I'd like to do something like the DOS equivalent of "CD test" but I >>>>>> do not know kow to do it. >>>>>> >>>>>> I am currently doing something really awful: I open a *.py file in the >>>>>> test subdirectory, I run it with the F5 key and it works! but I am >>>>>> doing really something stupid. >>>>>> >>>>> "it works!" What's the problem then? >>>>> >>>>>> How should I proceed, if I want to proceed properly? >>>>>> >>>>> Sorry but I don't even see your problem. You can save your .py files >>>>> anywhere you like... >>>>> >>>> When I enter IDLE, I'd like to say at the prompt: "my current >>>> directory is... ...test" and then be able to run a module in that >>>> directory. This is what my problem is!!! >>>> >>> 1. File -> Open >>> 2. Navigate to file and choose it >>> 3. Press F5 >>> >> Say that you wanted to import a file in the test directory after just >> entering IDLE. How would you do it? >> > > import sys > sys.path.insert(0, "C:/path/to/test/dir/here") > import something_in_test_dir > > Cheers, > Chris > -- > http://blog.rebertia.com > > Change directory to the test-directory Then run idle From ben+python at benfinney.id.au Mon Nov 16 16:17:17 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 08:17:17 +1100 Subject: IDE for python References: Message-ID: <87vdhanp9e.fsf@benfinney.id.au> Jonathan Hartley writes: > I'd like to offer the group the anecdote of the great Resolver IDE > migration. [?] It's great to see something refreshing and new ? data beyond a single person's subjective experience! ? come out of a topic that looked like it was just going to re-hash the same tired topic. Thank you. -- \ ?What I resent is that the range of your vision should be the | `\ limit of my action.? ?Henry James | _o__) | Ben Finney From python.list at tim.thechases.com Mon Nov 16 16:22:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 15:22:25 -0600 Subject: directory wildcard In-Reply-To: <637551.57013.qm@web57906.mail.re3.yahoo.com> References: <637551.57013.qm@web57906.mail.re3.yahoo.com> Message-ID: <4B01C291.7000807@tim.thechases.com> > I try to assign value to force_mcs sitting in a wildcard > subdirectory /sys/kernel/debug/ieee80211/phy*, but python does > not work for that such as: > > os.system("echo %i > > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? I'm not sure your code works if there's more than one phy* directory in that folder anyways since ">" piping usually only works for a single destination. Though I'd imagine this is only a problem for folks that have more than one 802.11 card in their machine (which I've done...a useless on-board and a PCMCIA on an older laptop). I'd use python's built-in glob module to do something like from glob import glob def set_force_mcs(mcs): for fname in glob('/sys/kernel/debug/' 'ieee80211/phy*/iwlagn/data/force_mcs'): f = open(fname, 'w') f.write('%i\n' % mcs) f.close() #the following should all work set_force_mcs(True) set_force_mcs(False) set_force_mcs(1) set_force_mcs(0) (I broke the for/glob line intentionally in a way that python transparently restores in case mailers munged them between here in there...normally, I'd just use a single string parameter for glob() instead of line-breaking it if it fit in 80 chars) If you're using a more recent version of python that has the "with" command (I think it was added in 2.6, and available from 2.5's future), it could be tidied to with open(fname, 'w') as f: f.write('%i\n' % mcs) -tkc From heintest at web.de Mon Nov 16 16:49:30 2009 From: heintest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Mon, 16 Nov 2009 22:49:30 +0100 Subject: mySQL access speed Message-ID: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Hello, I have some programs doing a lot sql IO in some mySQL databases. This works very fine and the DBAPI is quite simple to understand. Now I came to the point where I had to insert millions of lines into a table. My first aproach was to insert the data using executemany(). That's not bad and fairly simple to use. But it isn't very fast. For executemany I have some hundred thousend lines in a list of tuples. I joined() these lines to form an insert into table values (....) statement and blew it into the mysql cmdline client via os.popen(). This was 60(!) times faster and loaded my table in seconds! Is the mySQL module so slow ? Any ideas to have the mySQL module working faster ? The popen() way seems quite clumsy and not very pythonic for me, Greetings Hans From brownbar at gmail.com Mon Nov 16 17:14:33 2009 From: brownbar at gmail.com (Barry W Brown) Date: Mon, 16 Nov 2009 14:14:33 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 10:54?am, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? Fortran95. You can even label the IF...END IF structure -- handy for immense blocks. This is not a criticism of Python (or of Fortran). From henryzhang62 at yahoo.com Mon Nov 16 17:19:16 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Mon, 16 Nov 2009 14:19:16 -0800 (PST) Subject: directory wildcard In-Reply-To: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> Message-ID: <484826.59786.qm@web57901.mail.re3.yahoo.com> --- On Mon, 11/16/09, Jeff McNeil wrote: > From: Jeff McNeil > Subject: Re: directory wildcard > To: python-list at python.org > Date: Monday, November 16, 2009, 3:01 PM > On Nov 16, 3:33?pm, hong zhang > > wrote: > > List, > > > > I try to assign value to force_mcs sitting in a > wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but > python does not work for that such as: > > > > os.system("echo %i > > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % > mcs) > > > > Any right way to do it? > > > > Thanks. > > > > --henry > > I'd ditch the echo business altogether. 2.x. Not tested. > > import glob > > mcs = get_mcs_from_somewhere() > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/ > force_mcs'): > ? ? with open(i, 'w') as f: > ? ? ? ? print >>f, mcs This assigns decimal value, how can I assign Hex here to mcs? > From dikkie at nospam.org Mon Nov 16 17:28:35 2009 From: dikkie at nospam.org (Dikkie Dik) Date: Mon, 16 Nov 2009 23:28:35 +0100 Subject: mySQL access speed In-Reply-To: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> References: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b01d215$0$8788$bf4948fe@news.tele2.nl> > ... But it isn't very fast. > For executemany I have some hundred thousend lines in a list of tuples. > I joined() these lines to form an insert into table values (....) statement and > blew it into the mysql cmdline client via os.popen(). > This was 60(!) times faster and loaded my table in seconds! > > Is the mySQL module so slow ? No. The fact that each statement is atomic makes it slow. Try the multiple queries, but precede them with a "SET AUTOCOMMIT=0" statement or use a transaction. You will probably see a tremendous speed increase. When you combine all the queries into one statement, you are effectively doing the same. Best regards, Dikkie. From hyunchul.mailing at gmail.com Mon Nov 16 17:30:27 2009 From: hyunchul.mailing at gmail.com (Hyunchul Kim) Date: Tue, 17 Nov 2009 07:30:27 +0900 Subject: faster than list.extend() Message-ID: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Hi, all. I want to improve speed of following simple function. Any suggestion? ********** def triple(inputlist): results = [] for x in inputlist: results.extend([x,x,x]) return results ********** Thank you in advance, Hyunchul -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Mon Nov 16 17:37:11 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 16 Nov 2009 14:37:11 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <362dnUU5fJKKSZzWnZ2dnUVZ_jRi4p2d@giganews.com> r wrote: > On Nov 16, 10:54 am, Steve Ferg > wrote: > >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif > > WHY? Python's syntax is by far the most elegant of all, no need to > show the end of a block. Python is the smartest kid on the block. And > are you saying you would rather type "then" instead of ":" and "endif" > instead of "\n"? > > No thanks! You clipped out the part where he explicitly said it was not a suggestion to change Python. -- 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/Skype erikmaxfrancis Mona Lisa / Come to discover / I am your daughter -- Lamya From max at alcyone.com Mon Nov 16 17:38:33 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 16 Nov 2009 14:38:33 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <362dnUQ5fJL0SZzWnZ2dnUVZ_jRi4p2d@giganews.com> Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. It's the same syntax, with `fi` written instead of `endif` -- not sure why the difference in keyword is that big of a deal to you. As others have pointed out, either way, there are quite a few languages that use this type of syntax. -- 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/Skype erikmaxfrancis Mona Lisa / Come to discover / I am your daughter -- Lamya From clp2 at rebertia.com Mon Nov 16 17:41:25 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 14:41:25 -0800 Subject: faster than list.extend() In-Reply-To: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <50697b2c0911161441l1d9a7bc0k283db2617a3954ee@mail.gmail.com> On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim wrote: > Hi, all. > > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > ? results = [] > ? for x in inputlist: > ??? results.extend([x,x,x]) > ? return results > ********** You'd probably be better off calling .append() 3 times instead of .extend() as it would avoid the creation of all those intermediate 3-element lists. Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Mon Nov 16 17:54:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 19:54:45 -0300 Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> <4B01BFDB.7090806@ieee.org> Message-ID: En Mon, 16 Nov 2009 18:10:51 -0300, Dave Angel escribi?: > Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:56 AM, vsoler >> wrote: >>>>> When I enter IDLE, I'd like to say at the prompt: "my current >>>>> directory is... ...test" and then be able to run a module in that >>>>> directory. This is what my problem is!!! > Change directory to the test-directory > Then run idle Or, modify the Initial Directory in the menu shortcut that you use to start IDLE (right click, Properties). Or create another shortcut in your desktop using your desired initial directory. -- Gabriel Genellina From python.list at tim.thechases.com Mon Nov 16 17:55:55 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 16:55:55 -0600 Subject: faster than list.extend() In-Reply-To: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <4B01D87B.30102@tim.thechases.com> Hyunchul Kim wrote: > Hi, all. > > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > results = [] > for x in inputlist: > results.extend([x,x,x]) > return results > ********** Several ways occur to me: def t1(i): for x in i: yield x yield x yield x def t2(i): r = range(3) return (x for x in i for _ in r) I prefer to return generators in case the input is large, but in both cases, you can just wrap it in list() like list(t1(inputlist)) or in t2(), you can just change it to use return [x for x in i for _ in r] -tkc From rantingrick at gmail.com Mon Nov 16 18:18:23 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 16 Nov 2009 15:18:23 -0800 (PST) Subject: Command line arguments?? Message-ID: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> I am currently having "fun" with command line arguments in a windows environment. If i get a path that has spaces anywhere in it my script gets the wrong arguments from sys.argv. You guy's probably know what i am talking about. Heres and example. 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' inside my script i get the following result from sys.argv ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ \text.txt'] So i've got a few options 1. have people replace every space in all file paths system wide (sucks) 2. Create a custom parser, join the argv list, parse it...(maybe) 3. please tell me there is an option 3? (hopefully) From benjamin.kaplan at case.edu Mon Nov 16 18:23:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 16 Nov 2009 18:23:58 -0500 Subject: Command line arguments?? In-Reply-To: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, Nov 16, 2009 at 6:18 PM, rantingrick wrote: > I am currently having "fun" with command line arguments in a windows > environment. If i get a path that has spaces anywhere in it my script > gets the wrong arguments from sys.argv. You guy's probably know what i > am talking about. Heres and example. > > 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' > > inside my script i get the following result from sys.argv > > ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ > \text.txt'] > > So i've got a few options > ?1. have people replace every space in all file paths system wide > (sucks) > ?2. Create a custom parser, join the argv list, parse it...(maybe) > ?3. please tell me there is an option 3? (hopefully) > -- > http://mail.python.org/mailman/listinfo/python-list > The same thing you have to do with every command line program - wrap it in quotes. C:\\Python26\\python.exe C:\\echo.py "C:\\New Folder\\text.txt" From python at rcn.com Mon Nov 16 18:28:40 2009 From: python at rcn.com (Raymond Hettinger) Date: Mon, 16 Nov 2009 15:28:40 -0800 (PST) Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: On Nov 16, 2:41?pm, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim > > wrote: > > Hi, all. > > > I want to improve speed of following simple function. > > Any suggestion? > > > ********** > > def triple(inputlist): > > ? results = [] > > ? for x in inputlist: > > ??? results.extend([x,x,x]) > > ? return results Here's an itertools variant that is somewhat speedy when the inputlist is long: from itertools import * def triple3(inputlist, list=list, chain_from_iterable=chain.from_iterable, izip=izip): return list(chain_from_iterable(izip(inputlist, inputlist, inputlist))) Raymond From rhodri at wildebst.demon.co.uk Mon Nov 16 18:30:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 16 Nov 2009 23:30:09 -0000 Subject: Command line arguments?? In-Reply-To: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 23:18:23 -0000, rantingrick wrote: > I am currently having "fun" with command line arguments in a windows > environment. If i get a path that has spaces anywhere in it my script > gets the wrong arguments from sys.argv. You guy's probably know what i > am talking about. Heres and example. > > 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' > > inside my script i get the following result from sys.argv > > ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ > \text.txt'] > > So i've got a few options > 1. have people replace every space in all file paths system wide > (sucks) > 2. Create a custom parser, join the argv list, parse it...(maybe) > 3. please tell me there is an option 3? (hopefully) Quote the filenames or escape the spaces: C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" We've been living with this pain ever since windowed GUIs encouraged users to put spaces in their file names (Apple, I'm looking at you!). Fundamentally, if people want the pretty they have to live with the consequences. -- Rhodri James *-* Wildebeest Herder to the Masses From threaderslash at gmail.com Mon Nov 16 18:34:34 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 10:34:34 +1100 Subject: QtPython QtreeWidget - sortingEnabled Problem Message-ID: Hello Everybody, I trying to do a Qtreewidget to attend a customer design suggestion. I am coding it on QtPython. I did a first try using Qt Designer, then generated the code. But when I try to run it, an error comes out: self.centralwidget.setSortingEnabled(__sortingEnabled) AttributeError: setSortingEnabled I googled around, but didn't find any solution for this problem, except some suggestion just to simply delete the lines in the code that results in the compiling error. But it didn't really help, because if you do so, it triggers more error, just like that: self.treeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Item Name", None, QtGui.QApplication.UnicodeUTF8)) AttributeError: 'NoneType' object has no attribute 'setText' Here is my current code to generate a nice simple QtreeWidget/View: #//===========================================================//# def color_setupUi(self, MainWindow,phrase): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.eqpt_centralwdg(MainWindow) self.eqpt_retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) #//===========================================================//# def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") item = QtGui.QTreeWidgetItem(self.colorTreeWidget) item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.centralwidget.setSortingEnabled(__sortingEnabled) MainWindow.setCentralWidget(self.centralwidget) #//===========================================================//# def eqpt_retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "color", None, QtGui.QApplication.UnicodeUTF8) __sortingEnabled = self.colorTreeWidget.isSortingEnabled() self.colorTreeWidget.setSortingEnabled(False) self.colorTreeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Blue", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.setSortingEnabled(__sortingEnabled) #//===========================================================//# All other object I needed to implement on Qt using Designer and a little bit of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I just got stuck with this TreeWidget error. Any hints or suggestion are highly appreciated and welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Mon Nov 16 19:06:37 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 17 Nov 2009 13:06:37 +1300 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <7me7osF3hikpfU1@mid.individual.net> Christian Heimes wrote: > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. There's also a semantic problem. Since new-style classes are also instances (of class 'type') and you can create subclasses of 'type', if special methods were looked up on instances, it would be ambiguous whether an attribute '__getitem__' on a class was meant to specify the behaviour of the [] operation on its instances, or on the class itself. This problem didn't arise with old-style classes, because classes and instances were clearly separated (i.e. old-style classes were not old-style instances). -- Geg From glenn at zewt.org Mon Nov 16 19:23:51 2009 From: glenn at zewt.org (Glenn Maynard) Date: Mon, 16 Nov 2009 19:23:51 -0500 Subject: ZipFile - file adding API incomplete? Message-ID: I want to do something fairly simple: read files from one ZIP and add them to another, so I can remove and replace files. This led me to a couple things that seem to be missing from the API. The simple approach would be to open each file in the source ZIP, and hand it off to newzip.write(). There's a missing piece, though: there's no API that lets me pass in a file-like object and a ZipInfo, to preserve metadata. zip.write() only takes the filename and compression method, not a ZipInfo; writestr takes a ZipInfo but only accepts a string, not a file. Is there an API call I'm missing? (This seems like the fundamental API for adding files, that write and writestr should be calling.) The correct approach is to copy the data directly, so it's not recompressed. This would need two new API calls: rawopen(), acting like open() but returning a direct file slice and not decompressing data; and rawwrite(zinfo, file), to pass in pre-compressed data, where the compression method in zinfo matches the compression type used. I was surprised that I couldn't find the former. The latter is an advanced one, important for implementing any tool that modifies large ZIPs. Short-term, at least, I'll probably implement these externally. -- Glenn Maynard From contact at xavierho.com Mon Nov 16 19:32:43 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 10:32:43 +1000 Subject: Logic operators with "in" statement In-Reply-To: <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> Message-ID: <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> On Tue, Nov 17, 2009 at 12:46 AM, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote: > > AND operator has a higher precedence, so you don't need any brackets > here, I > > think. But anyway, you have to use it like that. So that's something > you'll > > have to fix first. > > Er, you mean lower precedence. Higher precedence means it would bind > tighter, thus the expression would mean: > '3' in (l and 'no3') in l > which is certainly incorrect. > > Thanks for the correction, Chris. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Nov 16 20:46:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Nov 2009 01:46:05 GMT Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 10:32:19 -0800, Steve Howell wrote: > Actually, the __getitem__ workaround that I proposed earlier only works > on subclasses of dict, not dict themselves. So given a pure dictionary > object, it is impossible to hook into attribute lookups after > instantiation in debugging/tracing code. If you have written your application to avoid unnecessary isinstance and type checks, i.e. to use duck-typing, then a technique you might find useful is delegation. class DebuggingDict(object): def __init__(self, dict_to_wrap, hook=None): self.__dict__['_d'] = dict_to_wrap self.__dict__['getitem_hook'] = hook def __getattr__(self, name): return getattr(self._d, name) def __setattr__(self, name, value): setattr(self._d, name, value) def __getitem__(self, key): if self.getitem_hook is not None: self.getitem_hook(self, key) return self._d[key] And in use: >>> def hook(self, key): ... print "Looking for key", key ... >>> d = DebuggingDict({1:'a', 2: 'b'}, hook) >>> d[1] Looking for key 1 'a' >>> d[2] Looking for key 2 'b' -- Steven From gagsl-py2 at yahoo.com.ar Mon Nov 16 21:15:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 23:15:06 -0300 Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: En Mon, 16 Nov 2009 19:30:27 -0300, Hyunchul Kim escribi?: > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > results = [] > for x in inputlist: > results.extend([x,x,x]) > return results > ********** These are my best attempts: def triple3(inputlist): results = [] append = results.append for x in inputlist: append(x); append(x); append(x) return results def triple4(inputlist, _three=xrange(3)): return [x for x in inputlist for _ in _three] For a 400-items list, triple3 is 40% faster and triple4 25% faster than yours. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Mon Nov 16 21:19:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Nov 2009 02:19:30 GMT Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> Message-ID: On Sun, 15 Nov 2009 16:26:59 -0800, Pyrot wrote: > On 11?15?, ??9?52?, "Diez B. Roggisch" wrote: >> Pyrot schrieb: >> >> > class rawDNA: >> > ? ?import string [...] > (Tthe core reason that I'm bothering with this at all is because I heard > imports are costly(in time, space, processing power). If this turns out > to be a non-issue, than my questions regarding Imports are all moot :->) Importing a module is only costly the first time (in any session) that you do so. Modules are cached, so the second time it is relatively fast. > I forgot to write about my second question which was: > > what happens when I use the import statement within a class/function > declaration? > I'm thinking either > 1) It imports during the class/function declaration > 2) It imports the first time a class/function call(x = rawDNA() ) occurs It imports when the class/function statement is *run*. def f(): import math The body of the function doesn't run until you call the function, so the import doesn't happen until you call f(). class K: import math def method(self): import string The class definition runs when you create the class, which imports math. But string is only imported when you call K().method(). > But if it's 2) then is the import valid outside of the function/class? No. The *name* "math" exists only inside the scope of the function, or class, and is not visible outside. >>> class K: ... import math ... >>> K.math >>> math Traceback (most recent call last): File "", line 1, in NameError: name 'math' is not defined > what happens when the last function reference is removed?(del x) You wrote: x = rawDNA() Deleting x won't do anything to the class rawDNA, or to the module string which is referenced by the rawDNA class. If you delete the rawDNA class, that won't do anything to the string module cached in sys. > I respect your(or anyone who would like to help me) time, so all I ask > is some kind of document or "Best practices" guide dealing all about > "import". 99.9% of the time you don't need to worry about it. Just import the modules you want at the top level of your program, and be happy that it all works fine. The other 0.1% of the time, you might have one or two good reasons for putting imports inside functions: (1) Encapsulation: you want to import a module to use in a function, without making it visible to other functions. (2) Just In Time importing. Imports at the top level slow down your program's start up. Normally, this is trivial and it is not worth the extra complexity to do something about it, but if you have a particularly expensive module which happens to be used only in one function which is rarely needed, then you can speed up your program for the majority of times by putting the import inside that one function. However, putting imports inside functions which are then called by threads can lead to deadlocks. So you also have to balance the risk of that happening. -- Steven From http Mon Nov 16 21:20:30 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:20:30 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> <99fff8de-5ecc-4bde-b486-f66b018532dc@g27g2000yqn.googlegroups.com> Message-ID: <7xr5rxyjrl.fsf@ruckus.brouhaha.com> sturlamolden writes: > A decorator function like @go could just call os.fork and run the > function in the child. We already have a between-process Queue in > multiprocessing to use as channels. Unlike with interthread queues, you have to serialize the values sent through those multiprocessing channels. I don't think you can send functions, generators, file descriptors, etc. From http Mon Nov 16 21:27:05 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:27:05 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <7xmy2lyjgm.fsf@ruckus.brouhaha.com> sturlamolden writes: > > ? ? ? Python is a very clean language held back from widespread use by slow > > implementations. ?If Python ran faster, Go would be unnecessary. > > Google is a multi-billion dollar business. They are using Python > extensively. Yes I know about Unladen Swallow, but why can't they put > 1 mill dollar into making a fast Python? I don't think Python and Go address the same set of programmer desires. For example, Go has a static type system. Some programmers find static type systems to be useless or undesirable. Others find them extremely helpful and want to use them them. If you're a programmer who wants a static type system, you'll probably prefer Go to Python, and vice versa. That has nothing to do with implementation speed or development expenditures. If Google spent a million dollars adding static types to Python, it wouldn't be Python any more. From http Mon Nov 16 21:31:44 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:31:44 -0800 Subject: Newsgroup for beginners References: Message-ID: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> mrholtsr writes: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? This group has its grouchy moments but for the most part it's reasonably friendly to beginners. The worst thing that usually happens is that if you ask a simple question, a bunch of experts will show off their knowledge to each other by giving you insanely complicated answers that you have no reason to want to understand. But they're not exactly being hostile when they do that. They're just really really into advanced Python programming. So go ahead and ask your questions. The first responses will probably be the most helpful, after which the response thread will go off into nerdy tangents that you can ignore. From jasonsewall at gmail.com Mon Nov 16 21:56:31 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Mon, 16 Nov 2009 21:56:31 -0500 Subject: faster than list.extend() In-Reply-To: References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <31e9dd080911161856g56751d52sf22514550644d5b9@mail.gmail.com> On Mon, Nov 16, 2009 at 6:28 PM, Raymond Hettinger wrote: > On Nov 16, 2:41?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim >> >> wrote: >> > Hi, all. >> >> > I want to improve speed of following simple function. >> > Any suggestion? >> >> > ********** >> > def triple(inputlist): >> > ? results = [] >> > ? for x in inputlist: >> > ??? results.extend([x,x,x]) >> > ? return results > > > Here's an itertools variant that is somewhat speedy when the inputlist > is long: > > ? ?from itertools import * > > ? ?def triple3(inputlist, list=list, > chain_from_iterable=chain.from_iterable, izip=izip): > ? ? ? ?return list(chain_from_iterable(izip(inputlist, inputlist, > inputlist))) Even (slightly) faster: def triple3_mk2(inputlist): return list(chain.from_iterable(izip(*repeat(inputlist, 3)))) I tried something like this when I saw Hyunchul's original email, but I didn't know about chain.from_iterable and it was pretty slow compared to the original. Adding (itertools.)repeat to Raymonds speeds it up 5-10% more. I'm pretty surprised this is faster than Tim's t2 (which is actually a little slower than the original); I always thought of comprehensions as the fastest way to do this find of stuff. Jason From threaderslash at gmail.com Mon Nov 16 22:07:10 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 14:07:10 +1100 Subject: Solved: QtPython QtreeWidget - sortingEnabled Problem Message-ID: > ---------- ---------- > From: Threader Slash > To: python-list at python.org > Date: Tue, 17 Nov 2009 10:34:34 +1100 > Subject: QtPython QtreeWidget - sortingEnabled Problem > Hello Everybody, > > I trying to do a Qtreewidget to attend a customer design suggestion. I am > coding it on QtPython. I did a first try using Qt Designer, then generated > the code. But when I try to run it, an error comes out: > > self.centralwidget.setSortingEnabled(__sortingEnabled) > AttributeError: setSortingEnabled > > I googled around, but didn't find any solution for this problem, except > some suggestion just to simply delete the lines in the code that results in > the compiling error. But it didn't really help, because if you do so, it > triggers more error, just like that: > > self.treeWidget.topLevelItem(0).child(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Item Name", None, > QtGui.QApplication.UnicodeUTF8)) > AttributeError: 'NoneType' object has no attribute 'setText' > > Here is my current code to generate a nice simple QtreeWidget/View: > > #//===========================================================//# > def color_setupUi(self, MainWindow,phrase): > MainWindow.setObjectName("MainWindow") > MainWindow.resize(800, 600) > self.eqpt_centralwdg(MainWindow) > self.eqpt_retranslateUi(MainWindow) > QtCore.QMetaObject.connectSlotsByName(MainWindow) > #//===========================================================//# > def eqpt_centralwdg(self,MainWindow): > self.centralwidget = QtGui.QWidget(MainWindow) > self.centralwidget.setObjectName("centralwidget") > > self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) > self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) > self.colorTreeWidget.setObjectName("colorTreeWidget") > > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > > self.centralwidget.setSortingEnabled(__sortingEnabled) > MainWindow.setCentralWidget(self.centralwidget) > #//===========================================================//# > def eqpt_retranslateUi(self, MainWindow): > > MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", > "MainWindow", None, QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.headerItem().setText(0, > QtGui.QApplication.translate("MainWindow", "color", None, > QtGui.QApplication.UnicodeUTF8) > __sortingEnabled = self.colorTreeWidget.isSortingEnabled() > self.colorTreeWidget.setSortingEnabled(False) > self.colorTreeWidget.topLevelItem(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow", None, > QtGui.QApplication.UnicodeUTF8) > self.colorTreeWidget.topLevelItem(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Blue", None, > QtGui.QApplication.UnicodeUTF8) > self.colorTreeWidget.setSortingEnabled(__sortingEnabled) > #//===========================================================//# > > All other object I needed to implement on Qt using Designer and a little > bit of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I > just got stuck with this TreeWidget error. > > Any hints or suggestion are highly appreciated and welcome. > > ---------- ---------- > Here is the solution: 1. delete/comment only the following line: #self.centralwidget.setSortingEnabled(__sortingEnabled) Then code: [code] def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") item = QtGui.QTreeWidgetItem(self.colorTreeWidget) item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.connect(self.colorTreeWidget, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.eqpt_activateInput) MainWindow.setCentralWidget(self.centralwidget) def eqpt_activateInput(self,item,col): print "Qtree ok! pressed" print item.text(col) [/code] Hope this may help others too. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From fred at bsdhost.net Mon Nov 16 22:16:21 2009 From: fred at bsdhost.net (Fred C) Date: Mon, 16 Nov 2009 19:16:21 -0800 Subject: ReverseProxy Message-ID: I have to write a quick and dirty ReverseProxy with Twisted, for one of our internal project. I never used Twisted before, and I was wondering of someone have an handy example of a ReverseProxy with Twisted to help that I can use as bootstrap. Many thanks. Fred -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Mon Nov 16 22:28:54 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 16 Nov 2009 19:28:54 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: Steve Ferg wrote: > Does anybody know a language with this kind of syntax for > ifThenElseEndif? VBScript. > Is there any particular reason why this might be a *bad* language- > design idea? VBScript. From yuzhichang at gmail.com Mon Nov 16 22:40:29 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Mon, 16 Nov 2009 19:40:29 -0800 (PST) Subject: Is pexpect unmaintained now? Message-ID: <252facf7-f9c6-4c6a-9d7f-ac69a830e6f0@h14g2000pri.googlegroups.com> Pexpect 2.4 is only available at Pypi. Both the homepage of pexpect(http://www.noah.org/wiki/Pexpect) and download page (http://sourceforge.net/projects/pexpect/files/) are outdated. The repository on Github (http://github.com/noahspurrier/pexpect/) has been removed. I ever contacted the author(noah at noah.org) but no response till now. I'm going to fork pexpect on Github and add some features... From invalid at invalid.invalid Mon Nov 16 22:56:42 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 17 Nov 2009 03:56:42 +0000 (UTC) Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-17, Paul Rubin wrote: > mrholtsr writes: >> Is there a Python newsgroup for those who are strictly beginners at >> programming and python? > > This group has its grouchy moments You've really got to try pretty hard to create one. But if you want to, here's how to do it: 1) Start by complaining that your program doesn't work because of a bug in Python. 2) Python programs are portable, so don't reveal what OS or Python version you're using. People will ask. Just ignore them. 2) State that your program "doesn't work", but don't explain either what you expect it to do or what it actually does. 3) Don't post the code that you're having problems with. 4) Once people start to get annoyed that you won't post any example code showing the problem you're having, then you post code. a) Post lots of code. The bigger the program the better; try for at least 500 lines -- but make sure that you leave out a few functions and "import" some libraries nobody has ever heard of. b) Post code that doesn't match the code who's behaviour you're describing (remember: be vague and be careful not to actually show real input or output at this point). c) For maximum effect try to make sure that what you post won't compile by inserting typos and changing the indentation in a few places. 5) Once you've stalled as long as possible you want to post code that will comipile and run. Now we move on to example inout and output. a) post output from a _different_ version of the program than what you're running. b) post input to and output from your program, but make sure that the output was generated with input differenent that what was posted. c) rather than cutting/pasting input and output, make sure you manually retype it into your posting -- inaccurately. In any other newsgroup, you'd have been burnt to a crisp and plonked long before getting this far, but in c.l.p there are still going to be a few people trying to help you. Now is the time to start making snide comments about how it would be so much easier in VB/Perl/C++ (pick whichever one you know the most about). Pick a feature from VB/Perl/C++ unrelated to the original problem and start demanding that it be added to Python so that you can use it to make your program work. For the final touch, forget about the original "bug" and start to wax philosophic about how this is just another typical example of the problems with Python, open-source, mass transit, the designated hitter, auto-tune, people who like cats, and the dewey decimal system. Use lots of poetic-sounding but nonsensical metaphors. It'll take several days and a fair bit of work, but you will be able to produce a some grouchy responses in c.l.p. > but for the most part it's reasonably friendly to beginners. > The worst thing that usually happens is that if you ask a > simple question, a bunch of experts will show off their > knowledge to each other by giving you insanely complicated > answers that you have no reason to want to understand. That usually happens when the question is vague and incomplete enough so that people have to guess what is being asked. Some people tend to guess more "interesting" questions than others. One will also get rather arcane answers when a poorly thought out question is answered literally. IOW, somebody asks "how to I do B?" when B _really_ isn't something anybody is going to want to in Python, but if you twist the language around enough you can actually _do_ B (even if it's quite pointless). The real question was "how do I accomplish A", but the poster having incorrectly assumed the answer is B, didn't ask "how do I accomplish A?" They're really not trying to torture beginners, they just think it's interesting trying to figure out a way to do B. Even if you do get some obscure answers, others will always figure out that what you really wanted to know was "how do I accomplish A" and tell you the best way to accomplish A and why B isn't what you want to do. -- Grant From ben+python at benfinney.id.au Mon Nov 16 23:08:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 15:08:18 +1100 Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <877htpokst.fsf@benfinney.id.au> Grant Edwards writes: > 2) State that your program "doesn't work", but don't explain > either what you expect it to do or what it actually does. A different flavour of this is also good for setting the seeds of grouchiness: 2a) Write a Subject field that doesn't say anything about what you're asking, so the thread doesn't garner any attention from busy people. For bonus points, put something like ?newbie question? there instead of anything actually relevant to the problem. No, this thread is not an example; the Subject field is an entirely relevant concise description of the information being sought. -- \ ?bash awk grep perl sed, df du, du-du du-du, vi troff su fsck | `\ rm * halt LART LART LART!? ?The Swedish BOFH, | _o__) alt.sysadmin.recovery | Ben Finney From rantingrick at gmail.com Mon Nov 16 23:18:55 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 16 Nov 2009 20:18:55 -0800 (PST) Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Nov 16, 5:30?pm, "Rhodri James" wrote: > We've been living with this pain ever since windowed GUIs encouraged users ? > to put spaces in their file names (Apple, I'm looking at you!). ? > Fundamentally, if people want the pretty they have to live with the ? > consequences. Thanks everyone , problem solved! From python.list at tim.thechases.com Mon Nov 16 23:40:53 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 22:40:53 -0600 Subject: Newsgroup for beginners In-Reply-To: References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <4B022955.7000204@tim.thechases.com> > 1) Start by complaining that your program doesn't work because > of a bug in Python. 1b) Omit the fact that this is a homework problem, and you want c.l.p to do your homework for you > 4) Once people start to get annoyed that you won't post any > example code showing the problem you're having, then you > post code. > > a) Post lots of code. The bigger the program the better; > try for at least 500 lines -- but make sure that you > leave out a few functions and "import" some libraries > nobody has ever heard of. > > b) Post code that doesn't match the code who's behaviour > you're describing (remember: be vague and be careful > not to actually show real input or output at this > point). > > c) For maximum effect try to make sure that what you post > won't compile by inserting typos and changing the > indentation in a few places. d) you post a link to your uploaded code on some code-sharing site that requires the latest versions of JavaScript, Flash, Silverlight, Java, and requires cookies to be enabled just to read your flippin' code. > c) rather than cutting/pasting input and output, make sure > you manually retype it into your posting -- > inaccurately. [sheepish grin] Guilty as charged on at least one occasion. > It'll take several days and a fair bit of work, but you will be > able to produce a some grouchy responses in c.l.p. oh, shut up! ;-) > One will also get rather arcane answers when a poorly thought > out question is answered literally. IOW, somebody asks "how to > I do B?" when B _really_ isn't something anybody is going to > want to in Python, but if you twist the language around enough > you can actually _do_ B (even if it's quite pointless). The > real question was "how do I accomplish A", but the poster > having incorrectly assumed the answer is B, didn't ask "how do > I accomplish A?" "But why can't I use regular expressions to do...?" :-) Even the best Pythoneers get grouchy ("This parrot wouldn't VOOM if you put 4 million volts through it!") -tkc From showell30 at yahoo.com Mon Nov 16 23:53:50 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 20:53:50 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> On Nov 16, 5:46?pm, Steven D'Aprano wrote: > On Mon, 16 Nov 2009 10:32:19 -0800, Steve Howell wrote: > > Actually, the __getitem__ workaround that I proposed earlier only works > > on subclasses of dict, not dict themselves. ?So given a pure dictionary > > object, it is impossible to hook into attribute lookups after > > instantiation in debugging/tracing code. > > If you have written your application to avoid unnecessary isinstance and > type checks, i.e. to use duck-typing, then a technique you might find > useful is delegation. > > class DebuggingDict(object): > ? ? def __init__(self, dict_to_wrap, hook=None): > ? ? ? ? self.__dict__['_d'] = dict_to_wrap > ? ? ? ? self.__dict__['getitem_hook'] = hook > ? ? def __getattr__(self, name): > ? ? ? ? return getattr(self._d, name) > ? ? def __setattr__(self, name, value): > ? ? ? ? setattr(self._d, name, value) > ? ? def __getitem__(self, key): > ? ? ? ? if self.getitem_hook is not None: > ? ? ? ? ? ? self.getitem_hook(self, key) > ? ? ? ? return self._d[key] > > And in use: > > >>> def hook(self, key): > > ... ? ? print "Looking for key", key > ...>>> d = DebuggingDict({1:'a', 2: 'b'}, hook) > >>> d[1] > > Looking for key 1 > 'a'>>> d[2] > > Looking for key 2 > 'b' > Yep, this basically resembles the approach that I originally took for the broader problem, which was that I wanted to see how a third party library (the Django templating system) was accessing dictionaries that referred to objects that my tracing code did not create. Although I did not instantiate the original objects, I did have the ability to substitute masquerade objects for the original objects before passing them along, and my code for the masquerading objects was similar in spirit to your DebuggingDict. It actually worked pretty well, except that eventually my masquerade objects went off to places where I was not fully able to maintain the illusion of being the original object. My original post on this thread sheds some light on what I'm doing, but basically I was trying to masquerade down the whole tree of calls from Django, which worked fine as long as Django was trying first to access my objects like dictionaries, which it always does first when rendering template variables, but all bets are off after that (custom filters, etc.). Eventually, I realized that it was easier to just monkeypatch Django while I was in test mode to get a more direct hook into the behavior I was trying to monitor, and then I didn't need to bother with overriding __getitem__ or creating complicated wrapper objects. I wrote about it here if anybody is morbidly interested: http://showellonprogramming.blogspot.com/ From showell30 at yahoo.com Tue Nov 17 00:17:48 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 21:17:48 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <7me7osF3hikpfU1@mid.individual.net> Message-ID: <4c84db77-31a7-48ce-b315-b9a1ab53463b@m33g2000pri.googlegroups.com> On Nov 16, 4:06?pm, greg wrote: > Christian Heimes wrote: > > Most magic methods are implemented as descriptors. Descriptors only > > looked up on the type to increase the performance of the interpreter and > > to simply the C API. > > There's also a semantic problem. Since new-style > classes are also instances (of class 'type') and you > can create subclasses of 'type', if special methods > were looked up on instances, it would be ambiguous > whether an attribute '__getitem__' on a class was > meant to specify the behaviour of the [] operation > on its instances, or on the class itself. > > This problem didn't arise with old-style classes, > because classes and instances were clearly separated > (i.e. old-style classes were not old-style instances). That explanation makes some sense to me. Given the ambiguity and the backward compatibility issues, I would argue that both of the commented lines in the program below should fail hard with a useful warning. Only one of them actually does. The other just silently no- ops. class A(dict): pass a = A() a['ignore'] = 'x' a.__getitem__ = lambda key: 'foo' # exercise in futility b = dict() b['ignore'] = 'x' b.__getitem__ = lambda key: 'foo' # hard failure Tested under 2.6. It seems like if __getitem__ is truly a special method, it should get special treatment whenever you try to use it, even if that special treatment is just an explicit error message that its use makes no sense in a particular context. If you allow __getitem__ to exist on a, then you create situations where __getitem__ is basically an instance method on an instance of a subtype of dict, which sounds awfully ambiguous to me, given that the whole intent of __getitem__ is to define the behavior of [] on classes. From gagsl-py2 at yahoo.com.ar Tue Nov 17 00:51:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Nov 2009 02:51:07 -0300 Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> Message-ID: En Mon, 16 Nov 2009 18:04:21 -0300, Ecir Hana escribi?: > On Nov 16, 7:21 pm, "Gabriel Genellina" > wrote: >> En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana >> escribi?: >> >> >> I'm trying to write a simple Win32 app, which may run some Python >> >> scripts. Since it is a Windows GUI app, I would like to redirect all >> >> output (Python print, C printf, fprinf stderr, ...) to a text area >> >> inside the app. In other words, I'm trying to log all the output from >> >> the app (C, Python) to a window. So far, this works for C printf(): >> >> [...] > > thanks for the reply! Sorry, my earlier code was not working as I expected; I wrongly assumed the output was being redirected but that was not the case. The version below ("set paranoid mode on") does redirect printf(), fwrite(stdout,...), write(1,...), WriteFile(consolehandle,...), all those calls in C, but fails in Python with IOError: [Errno 9] Bad file descriptor. I'm unable to figure out *where* it fails just by reading the Python source; one should set a breakpoint in python26.dll to see what actually happens. > However, please, could you tell me how many bytes it read here: > > ReadFile(hReadPipe, buffer, 19, &nr, NULL); The code below now reads from the pipe everything that has been written -- except from Python :( #include #include #include #include "Python.h" int error(char* lpszText) { LPVOID lpMsgBuf; DWORD lasterror = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lasterror, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); fprintf(stderr, "%s: error %d: %s", lpszText, lasterror, lpMsgBuf); LocalFree(lpMsgBuf); return 1; } int main() { HANDLE hReadPipe, hWritePipe; DWORD nr, nw; char buffer[100]; int fd, i; BOOL bResult; if (!CreatePipe( &hReadPipe, &hWritePipe, NULL, 0)) return error("cannot create pipe"); if (!SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe)) return error("SetStdHandle"); // this was missing in previous version fd = _open_osfhandle((intptr_t)hWritePipe, _O_TEXT); if (fd==-1) return error("_open_osfhandle"); if (_dup2(fd, 1)!=0) return error("dup2"); if (!WriteFile(hWritePipe, "WriteFile(pipe)\n", 16, &nr, NULL)) return error("WriteFile(pipe)"); if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "WriteFile(stdout)\n", 18, &nr, NULL)) return error("WriteFile(stdout)"); fputs("fputs from C\n", stdout); if (fwrite("fwrite from C\n", 1, 14, stdout)!=14) return error("fwrite!=14"); if (write(1, "write from C\n", 13)<0) return error("write"); fflush(stdout); fprintf(stderr, "before Python\n"); Py_Initialize(); PyRun_SimpleString("import sys;sys.stdout.write('from Python\\n')\n"); Py_Finalize(); fprintf(stderr, "before flush 2\n"); fflush(stdout); fprintf(stderr, "before close pipe w\n"); if (!CloseHandle(hWritePipe)) return error("CloseHandle(hWritePipe)"); fprintf(stderr, "before close STDOUT Handle\n"); if (!CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE))) return error("CloseHandle(STDOUT)"); fprintf(stderr, "before read pipe\n"); // read one char at a time... for (i = 0; i -- Gabriel Genellina From animator333 at gmail.com Tue Nov 17 01:04:14 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 22:04:14 -0800 (PST) Subject: Get attribute this way Message-ID: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Python's getattr, setattr and __getattribute__ commands works fine with python types. For example: print o.__getattribute__("name") print getattr(o, "name") This is the easiest way to get an attribute using a string. In my case the "Node" class load/creates all the attributes from a xml file. Example There are certain atrributes of compound type. Example: # Array of colors, Here we are referring first color and second element (green) self.gradient.colors[0][1] = 0.5 # Array of floats, referring first element self.gradient.positions[0] = 1.0 Color, color array and floats are all custom classes. Now question is how to get these compound attributes using string as we do with default singular attributes. Example: getattr(o, "gradient.colors[0][1] ") I need this to save the data of nodes->attributes into a custom xml format, when loading this data back, I create the node first and then setup values from the saved xml file. Prashant Python 2.6.2 Win XP 32 From pavlovevidence at gmail.com Tue Nov 17 01:11:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 22:11:50 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <58066d51-e47f-4d3f-934c-8255916e0684@j9g2000prh.googlegroups.com> On Nov 16, 10:32?am, Steve Howell wrote: > On Nov 16, 2:35?am, Carl Banks wrote: > > > > > On Nov 15, 2:52?pm, Steve Howell wrote: > > > > Does anybody have any links that points to the rationale for ignoring > > > instance definitions of __getitem__ when new-style classes are > > > involved? ?I assume it has something to do with performance or > > > protecting us from our own mistakes? > > > "Not important enough to justify complexity of implementation." > > > I doubt they would have left if out of new-style classes if it had > > been straightforward to implement (if for no other reason than to > > retain backwards compatibility), but it wasn't. ?The way attribute > > lookups work meant it would have required all kinds of double lookups > > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > > easily worked around by simply having __getitem__ call another method, > > as you've seen. ?Given all this it made better sense to just leave it > > out of new-style classes. > > Actually, the __getitem__ workaround that I proposed earlier only > works on subclasses of dict, not dict themselves. ?So given a pure > dictionary object, it is impossible to hook into attribute lookups > after instantiation in debugging/tracing code. ?I know it's not a > super common thing to do, but it is a legitimate use case from my > perspective. ?But I understand the tradeoffs. ?They seem kind of 20th > century to me, but with Moore's Law declining and all, maybe it's a > bad time to bring up the "flexibility trumps performance" > argument. ;) It's not performance, it's code complexity. Implementing this would have to added a lot of extra code to the Python codebase--more than you seem to realize--all in support of a dubious behavior. This would have meant more opporunities for bugs, and an increased maintainence burden. >?The backward compatibility argument also seems a little > dubious, because if anybody *had* put __getitem__ on a dictionary > instance before, it would have already been broken code, and if they > hadn't done it, there would be no semantic change, just a performance > hit, albeit a pervasive one. Wrong. It's only dubious from your narrow mindset that focuses on your own problem and ignores the greater problem. When new-style classes were introduced, they made a decision that magic methods would no longer work when defined on any instance. It affected a *lot* more than just your dictionary use-case. So please spare me any suggestions that the change didn't carry a significant backwards incompatibility. It did, and they made the change anyway. That should tell you how difficult it would have been to implement. Carl Banks From kev0960 at gmail.com Tue Nov 17 01:18:10 2009 From: kev0960 at gmail.com (Psi) Date: Mon, 16 Nov 2009 22:18:10 -0800 (PST) Subject: Please recommend the books that might be helpful to learn Python :) Message-ID: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> as the subject says, any books? From ben+python at benfinney.id.au Tue Nov 17 01:21:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 17:21:44 +1100 Subject: Please recommend the books that might be helpful to learn Python :) References: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> Message-ID: <87y6m5n01z.fsf@benfinney.id.au> Psi writes: > as the subject says, > > any books? Any web search would lead you to , no? -- \ ?There's no excuse to be bored. Sad, yes. Angry, yes. | `\ Depressed, yes. Crazy, yes. But there's no excuse for boredom, | _o__) ever.? ?Viggo Mortensen | Ben Finney From threaderslash at gmail.com Tue Nov 17 01:24:26 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 17:24:26 +1100 Subject: Qt Python : QTreeWidget Child Problem Message-ID: Hello Everybody, I have a QTreewidget that works fine if I have just one level on my treelist. If I decide to add child sublevels, it gives me an error. Here is the code, that works nice only without the "childs" lines on it (see after "child 1" and "child 2"). def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") # father root 1 item = QtGui.QTreeWidgetItem(self.colorTreeWidget) #child 1 - from father 1 item = QtGui.QTreeWidgetItem(item) #child 2 - from father 1 item = QtGui.QTreeWidgetItem(item) # father root 2 item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.connect(self.colorTreeWidget, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.eqpt_activateInput) MainWindow.setCentralWidget(self.centralwidget) def eqpt_retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "color", None, QtGui.QApplication.UnicodeUTF8) __sortingEnabled = self.colorTreeWidget.isSortingEnabled() self.colorTreeWidget.setSortingEnabled(False) # father root 1 self.colorTreeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow", None, QtGui.QApplication.UnicodeUTF8) #child 1 - from father 1 self.colorTreeWidget.topLevelItem(0).child(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Sun", None, QtGui.QApplication.UnicodeUTF8)) #child 2 - from father 1 self.colorTreeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Gold", None, QtGui.QApplication.UnicodeUTF8)) # father root 2 self.colorTreeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Blue", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.setSortingEnabled(__sortingEnabled) Here is the output, when it works def eqpt_activateInput(self,item,col): print "Qtree ok! pressed" print item.text(col) if I exclude the lines related to the "child 1" and "child 2" from the code, it runs. Otherwise, it gives me the error: AttributeError: 'NoneType' object has no attribute 'setText' I used the Qt Designer to generate the code, and added some lines to trigger events. Any hints or suggestions are highly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Nov 17 01:31:25 2009 From: nagle at animats.com (John Nagle) Date: Mon, 16 Nov 2009 22:31:25 -0800 Subject: mySQL access speed In-Reply-To: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> References: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b0240c5$0$1581$742ec2ed@news.sonic.net> Hans M?ller wrote: > Hello, > > I have some programs doing a lot sql IO in some mySQL databases. > This works very fine and the DBAPI is quite simple to understand. > > Now I came to the point where I had to insert millions of lines into a table. If you're loading into an empty table, use the LOAD command. That's far faster than doing vast numbers of INSERT operations. The LOAD command loads all the data, unindexed, then builds the indices. Expect a 10x speed improvement or better. John Nagle From clp2 at rebertia.com Tue Nov 17 01:35:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 22:35:43 -0800 Subject: Get attribute this way In-Reply-To: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <50697b2c0911162235i7e01623bn4be8535f93f3fc8b@mail.gmail.com> On Mon, Nov 16, 2009 at 10:04 PM, King wrote: > Python's getattr, setattr and __getattribute__ commands works fine > with python types. > For example: > print o.__getattribute__("name") > print getattr(o, "name") > This is the easiest way to get an attribute using a string. > > In my case the "Node" class load/creates all the attributes from a xml > file. > Example > > > > There are certain atrributes of compound type. > Example: > # Array of colors, Here we are referring first color and second element > (green) > self.gradient.colors[0][1] = 0.5 > # Array of floats, referring first element > self.gradient.positions[0] = 1.0 > > Color, color array and floats are all custom classes. > > Now question is how to get these compound attributes using string as > we do with default singular attributes. > Example: > getattr(o, "gradient.colors[0][1] ") > I need this to save the data of nodes->attributes into a custom xml > format, when loading this data back, I create the node first and then > setup values from the saved xml file. Can't you just iterate over the data structure? I'm not seeing why you'd need to use getattr() and friends in the first place. for color in self.gradient.colors: for element in color: #output XML fragment #repeat for self.gradient.positions, etc. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Nov 17 01:53:59 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 22:53:59 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: Writing/Reading data to xml is not a problem. The problem is when I have to write to attributes in xml, where a connections has been established. XML: While reading back I have to convert both source and destination strings into object so that I can call connections function using source and target attributes. Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Tue Nov 17 02:21:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 23:21:46 -0800 Subject: Get attribute this way In-Reply-To: References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <50697b2c0911162321k5bc80008gff8101340afdd9d3@mail.gmail.com> On Mon, Nov 16, 2009 at 10:53 PM, King wrote: > Writing/Reading data to xml is not a problem. The problem is when I > have to write to attributes in xml, where a connections has been > established. > XML: > destattribute="node2.gradient.colors[1][2]"/> You did not include an example like this in your original post. I'd say you're stuck using eval() unless you want to change your format or write a parser for the subset of Python involved. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Nov 17 02:37:02 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 23:37:02 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: "eval" can solve this problem right away but I am concerned about security issues. If not "eval" could you suggest something more efficient way. It won't be a big deal to change the format as application is still at development stage? Thanks Prashant Python 2.6.2 Win XP 32 From eden at bicikl. Tue Nov 17 02:44:24 2009 From: eden at bicikl. (Eden Kirin) Date: Tue, 17 Nov 2009 08:44:24 +0100 Subject: SCGIServer and unusal termination In-Reply-To: References: Message-ID: Anyone? -- www.vikendi.net -/- www.supergrupa.com From hyunchul.mailing at gmail.com Tue Nov 17 03:07:42 2009 From: hyunchul.mailing at gmail.com (Hyunchul Kim) Date: Tue, 17 Nov 2009 17:07:42 +0900 Subject: faster than list.extend() In-Reply-To: <4B01D87B.30102@tim.thechases.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> <4B01D87B.30102@tim.thechases.com> Message-ID: <573a3abd0911170007s62537a45y3233cf21018c5d2d@mail.gmail.com> Thank Tim, Raymond, and all. In my test, Tim's t1 was fastest and Raymond's triple3 is very near to Tim's t1. Anyway both of them took only 6~7% time of my original .extend() version. I think that following n_ple() is a good generalized function that was 1~3% slower than t1() and triple3() for "triple". ********* from itertools import * def n_ple(inputlist, n): chain_from_iterable = chain.from_iterable; izip = izip return chain_from_iterable(izip(*[inputlist]*n)) ********* def t2(i): r = range(3) return (x for x in i for _ in r) def t2_1(i): r = range(3) return [x for x in i for _ in r] I didn't know that list(t2(inputlist)) is much faster than t2_1(inputlist), it's gonna be a helpful tip for me. Thank you all. Hyunchul On Tue, Nov 17, 2009 at 7:55 AM, Tim Chase wrote: > Hyunchul Kim wrote: > >> Hi, all. >> >> I want to improve speed of following simple function. >> Any suggestion? >> >> ********** >> def triple(inputlist): >> results = [] >> for x in inputlist: >> results.extend([x,x,x]) >> return results >> ********** >> > > Several ways occur to me: > > def t1(i): > for x in i: > yield x > yield x > yield x > > def t2(i): > r = range(3) > return (x for x in i for _ in r) > > > I prefer to return generators in case the input is large, but in both > cases, you can just wrap it in list() like > > list(t1(inputlist)) > > or in t2(), you can just change it to use > > return [x for x in i for _ in r] > > -tkc > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From donn.ingle at gmail.com Tue Nov 17 03:10:01 2009 From: donn.ingle at gmail.com (Donn) Date: Tue, 17 Nov 2009 10:10:01 +0200 Subject: Python & Go In-Reply-To: <7xocn4rh2r.fsf@ruckus.brouhaha.com> References: <7xocn4rh2r.fsf@ruckus.brouhaha.com> Message-ID: <200911171010.01537.donn.ingle@gmail.com> On Saturday 14 November 2009 22:23:40 Paul Rubin wrote: > they'll have to call it Go2 Lol. Or we could fork it and call it Gosub ... and never return! \d From deets at nospam.web.de Tue Nov 17 03:20:44 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 09:20:44 +0100 Subject: Get attribute this way In-Reply-To: References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <7mf4muF3eokmqU1@mid.uni-berlin.de> King schrieb: > "eval" can solve this problem right away but I am concerned about > security issues. If not "eval" could you suggest something more > efficient way. It won't be a big deal to change the format as > application is still at development stage? If you don't want to use eval (which is a good thing not to want), you'd end up (as Chris already told you) writing your own parser for python subexpressions. Which is laborous. Or you create a XML-representation of these expressions, which saves you the parser, but not the evaluator, and bloats the XML. It could look like this: <... # close them all Is this *really* all worth doing, or can't you just overcome your preconceptions - and use pickle, as it has been suggested to you before? Potentially with __getstate__/__setstate__ overridden for specific objects. Diez From pavlovevidence at gmail.com Tue Nov 17 03:29:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 Nov 2009 00:29:38 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <6592fecb-0a94-4372-bdf0-d2b38979e896@13g2000prl.googlegroups.com> On Nov 16, 11:37?pm, King wrote: > "eval" can solve this problem right away but I am concerned about > security issues. If not "eval" could you suggest something more > efficient way. It won't be a big deal to change the format as > application is still at development stage? You are stuck parsing it yourself, then. Apart from eval, there's not a really handy way to do what you want. Here's something that might help you get started; it is not by any means a final solution. First of all, for simplicity's sake, change the subscript notation to attribute notation; that is, change "gradient.positions[0]" to "gradient.positions.0". Then you can find the object you're seeking like this (untested): obj = self while '.' in attr: next,attr = attr.split('.',1) try: index = int(next) except TypeError: obj = getattr(obj,next) else: obj = obj[index] Notice what's happening: we're splitting the string at the dot and using getattr to descend further into the structure. Also, if the part of the string before the dot is an integer, we index instead. Hopefully this example will help you understand what doing this entails and what you have to do to get it work. Carl Banks From deets at nospam.web.de Tue Nov 17 03:33:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 09:33:41 +0100 Subject: ZipFile - file adding API incomplete? In-Reply-To: References: Message-ID: <7mf5f6F3i297hU1@mid.uni-berlin.de> Glenn Maynard schrieb: > I want to do something fairly simple: read files from one ZIP and add > them to another, so I can remove and replace files. This led me to a > couple things that seem to be missing from the API. > > The simple approach would be to open each file in the source ZIP, and > hand it off to newzip.write(). There's a missing piece, though: > there's no API that lets me pass in a file-like object and a ZipInfo, > to preserve metadata. zip.write() only takes the filename and > compression method, not a ZipInfo; writestr takes a ZipInfo but only > accepts a string, not a file. Is there an API call I'm missing? > (This seems like the fundamental API for adding files, that write and > writestr should be calling.) > > The correct approach is to copy the data directly, so it's not > recompressed. This would need two new API calls: rawopen(), acting > like open() but returning a direct file slice and not decompressing > data; and rawwrite(zinfo, file), to pass in pre-compressed data, where > the compression method in zinfo matches the compression type used. > > I was surprised that I couldn't find the former. The latter is an > advanced one, important for implementing any tool that modifies large > ZIPs. Short-term, at least, I'll probably implement these externally. No idea why the write doesn't accept an open file - OTOH, as passing a string is just writestr(info, in_file.read()) I don't think that's *that* much of an inconvenience.. And regarding your second idea: can that really work? Intuitively, I would have thought that compression is adaptive, and based on prior additions to the file. I might be wrong with this though. Diez From clp2 at rebertia.com Tue Nov 17 04:08:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 01:08:55 -0800 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <50697b2c0911170108x14ac984w9ffe8c1850d4086b@mail.gmail.com> On Mon, Nov 16, 2009 at 2:14 AM, Virgil Stokes wrote: > If one goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > and if you now click on the tab labeled "history and compare" this will take > you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > Finally...This is where I would like to "connect to" the data on a daily > basis or to gather data over different time intervals. I believe that if I > can get some help on this, then I will be able to customize the code as > needed for my own purposes. HTML parsing: http://www.crummy.com/software/BeautifulSoup/ Downloading webpages: http://docs.python.org/library/urllib.html#urllib.urlopen BeautifulSoup is excellently documented: http://www.crummy.com/software/BeautifulSoup/documentation.html You'll probably be interested in the sections on searching and navigating the parse tree. Cheers, Chris -- IANAL and do not condone violating website TOSes http://blog.rebertia.com From clp2 at rebertia.com Tue Nov 17 04:10:11 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 01:10:11 -0800 Subject: TODO and FIXME tags In-Reply-To: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Message-ID: <50697b2c0911170110l7420e2caq9fdb043b3acb3db3@mail.gmail.com> 2009/11/16 Yasser Almeida Hern?ndez : > Hi all.. > Sorry if this question sound elemental. > How is the sintaxis for set the TODO and FIXME tags...? There is no special syntax for those. Some people use them in comments, but it's just a convention. Cheers, Chris -- http://blog.rebertia.com From Juergen.Hermann at 1und1.de Tue Nov 17 04:26:00 2009 From: Juergen.Hermann at 1und1.de (jhermann) Date: Tue, 17 Nov 2009 01:26:00 -0800 (PST) Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> <0083130b$0$26937$c3e8da3@news.astraweb.com> Message-ID: <2dbed67b-e622-4a20-8254-29ddd2687316@a32g2000yqm.googlegroups.com> On 10 Nov., 17:03, NickC wrote: > Many thanks for the replies. ?getattr() works great: You can get a little more versatile and even specify the location of the name (i.e. the module / package name) without pre-importing it, like this... def importName(modulename, name=None): """ Import identifier C{name} from module C{modulename}. If name is omitted, modulename must contain the name after the module path, delimited by a colon. @param modulename: Fully qualified module name, e.g. C{x.y.z}. @param name: Name to import from C{modulename}. @return: Requested object. @rtype: object """ if name is None: modulename, name = modulename.split(':', 1) module = __import__(modulename, globals(), {}, [name]) return getattr(module, name) print importName("socket:gethostname")() This is especially useful if you want to specify factory classes or the like in a non-python config file. The syntax is the same as that of setuptools entry points. From ben+python at benfinney.id.au Tue Nov 17 04:47:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 20:47:00 +1100 Subject: TODO and FIXME tags References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Message-ID: <87lji5mqjv.fsf@benfinney.id.au> Chris Rebert writes: > 2009/11/16 Yasser Almeida Hern?ndez : > > How is the sintaxis for set the TODO and FIXME tags...? > > There is no special syntax for those. Some people use them in > comments, but it's just a convention. This is true. However, the convention is fairly well established, and many text editor default configurations will highlight the strings ?TODO?, ?FIXME?, and others wherever they appear in comments. There's no widely-followed ?syntax? for this convention, though. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Tue Nov 17 04:49:50 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 17 Nov 2009 10:49:50 +0100 Subject: Get attribute this way In-Reply-To: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <4b0271b8$0$17015$426a74cc@news.free.fr> King a ?crit : > Python's getattr, setattr and __getattribute__ commands s/commands/functions/ > works fine > with python types. > For example: > print o.__getattribute__("name") A very few corner cases set aside - the main one being inside a custom __getattribute__ method -, you should not directly access __getattribute__ (nor most __magic_methods__ FWIW). > print getattr(o, "name") > This is the easiest way to get an attribute using a string. > > In my case the "Node" class load/creates all the attributes from a xml > file. > Example > > > > There are certain atrributes of compound type. There's no "compound type" in Python. There are only objects, objects and objects. > Example: > # Array of colors, Here we are referring first color and second element > (green) > self.gradient.colors[0][1] = 0.5 > # Array of floats, referring first element > self.gradient.positions[0] = 1.0 > > Color, color array and floats are all custom classes. > > Now question is how to get these compound attributes using string as > we do with default singular attributes. > Example: > getattr(o, "gradient.colors[0][1] ") You can't (at least OOTB). the expression: gradient.colors[0][1] is a shortcut for: colors = gradients.__getattribute__("color") colors_0 = colors.__getitem__(0) colors_0_1 = colors_0.__getitem__(1) You can of course do something like g = getattr(o, "gradient") c = getattr(g, "colors") # etc... but I guess this is not what you're after. > I need this to save the data of nodes->attributes into a custom xml > format, when loading this data back, I create the node first and then > setup values from the saved xml file. I really don't think you need anything like this to serialize / unserialize your objects (whatever the format FWIW). You should really google for +python +serialize +XML, I bet you'd find at least a couple helpful articles on that topic. From showell30 at yahoo.com Tue Nov 17 05:02:25 2009 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 17 Nov 2009 02:02:25 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <58066d51-e47f-4d3f-934c-8255916e0684@j9g2000prh.googlegroups.com> Message-ID: On Nov 16, 10:11?pm, Carl Banks wrote: > On Nov 16, 10:32?am, Steve Howell wrote: > > > > > On Nov 16, 2:35?am, Carl Banks wrote: > > > > On Nov 15, 2:52?pm, Steve Howell wrote: > > > > > Does anybody have any links that points to the rationale for ignoring > > > > instance definitions of __getitem__ when new-style classes are > > > > involved? ?I assume it has something to do with performance or > > > > protecting us from our own mistakes? > > > > "Not important enough to justify complexity of implementation." > > > > I doubt they would have left if out of new-style classes if it had > > > been straightforward to implement (if for no other reason than to > > > retain backwards compatibility), but it wasn't. ?The way attribute > > > lookups work meant it would have required all kinds of double lookups > > > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > > > easily worked around by simply having __getitem__ call another method, > > > as you've seen. ?Given all this it made better sense to just leave it > > > out of new-style classes. > > > Actually, the __getitem__ workaround that I proposed earlier only > > works on subclasses of dict, not dict themselves. ?So given a pure > > dictionary object, it is impossible to hook into attribute lookups > > after instantiation in debugging/tracing code. ?I know it's not a > > super common thing to do, but it is a legitimate use case from my > > perspective. ?But I understand the tradeoffs. ?They seem kind of 20th > > century to me, but with Moore's Law declining and all, maybe it's a > > bad time to bring up the "flexibility trumps performance" > > argument. ;) > > It's not performance, it's code complexity. > > Implementing this would have to added a lot of extra code to the > Python codebase--more than you seem to realize--all in support of a > dubious behavior. ?This would have meant more opporunities for bugs, > and an increased maintainence burden. > > >?The backward compatibility argument also seems a little > > dubious, because if anybody *had* put __getitem__ on a dictionary > > instance before, it would have already been broken code, and if they > > hadn't done it, there would be no semantic change, just a performance > > hit, albeit a pervasive one. > > Wrong. ?It's only dubious from your narrow mindset that focuses on > your own problem and ignores the greater problem. ?When new-style > classes were introduced, they made a decision that magic methods would > no longer work when defined on any instance. ?It affected a *lot* more > than just your dictionary use-case. > > So please spare me any suggestions that the change didn't carry a > significant backwards incompatibility. ?It did, and they made the > change anyway. ?That should tell you how difficult it would have been > to implement. > I am sorry having for a narrow mindset, and I apologize for not seeming to realize how much extra code would go into the Python codebase to allow me to hook into attribute lookups after instantiation in debugging/tracing code. From dickinsm at gmail.com Tue Nov 17 05:15:40 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 17 Nov 2009 02:15:40 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <383a179a-1e5d-4b47-a5db-87dae03cfb1e@d10g2000yqh.googlegroups.com> On Nov 16, 4:54?pm, Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. GAP uses almost exactly this syntax, but with 'fi' instead of 'endif': http://www.gap-system.org/Manuals/doc/htm/ref/CHAP004.htm#SECT016 Mark From __peter__ at web.de Tue Nov 17 05:24:18 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2009 11:24:18 +0100 Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > En Mon, 16 Nov 2009 19:30:27 -0300, Hyunchul Kim > escribi?: > >> I want to improve speed of following simple function. >> Any suggestion? >> >> ********** >> def triple(inputlist): >> results = [] >> for x in inputlist: >> results.extend([x,x,x]) >> return results >> ********** > > These are my best attempts: > > def triple3(inputlist): > results = [] > append = results.append > for x in inputlist: > append(x); append(x); append(x) > return results > > def triple4(inputlist, _three=xrange(3)): > return [x for x in inputlist for _ in _three] > > For a 400-items list, triple3 is 40% faster and triple4 25% faster than > yours. [I didn't see the original post] If inputlist is actually a list or tuple the following should beat them all: def triple_repeat(items): result = [None] * (3*len(items)) result[::3] = result[1::3] = result[2::3] = items return result For small n the generalization should still be quite competitive: def n_repeat(items, n): items = tuple(items) result = [None]*(len(items) * n) for offset in range(n): result[offset::n] = items return result Some measurements: $ cat extend.py from itertools import * def triple_repeat(items): result = [None] * (3*len(items)) result[::3] = result[1::3] = result[2::3] = items return result def n_repeat(items, n): items = tuple(items) result = [None]*(len(items) * n) for offset in range(n): result[offset::n] = items return result def t1(i): for x in i: yield x yield x yield x def triple3(inputlist, list=list, chain_from_iterable=chain.from_iterable, izip=izip): return list(chain_from_iterable(izip(inputlist, inputlist, inputlist))) data = range(1000) $ python -m timeit -s 'from extend import triple_repeat, data' 'triple_repeat(data)' 10000 loops, best of 3: 52.4 usec per loop $ python -m timeit -s 'from extend import n_repeat, data' 'n_repeat(data, 3)' 10000 loops, best of 3: 60.7 usec per loop $ python -m timeit -s 'from extend import t1, data' 'list(t1(data))' 1000 loops, best of 3: 337 usec per loop $ python -m timeit -s 'from extend import triple3, data' 'triple3(data)' 1000 loops, best of 3: 231 usec per loop Peter From martin.hellwig at dcuktec.org Tue Nov 17 06:27:03 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 17 Nov 2009 11:27:03 +0000 Subject: TODO and FIXME tags In-Reply-To: <87lji5mqjv.fsf@benfinney.id.au> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Chris Rebert writes: > >> 2009/11/16 Yasser Almeida Hern?ndez : >>> How is the sintaxis for set the TODO and FIXME tags...? >> There is no special syntax for those. Some people use them in >> comments, but it's just a convention. > > This is true. However, the convention is fairly well established, and > many text editor default configurations will highlight the strings > ?TODO?, ?FIXME?, and others wherever they appear in comments. > > There's no widely-followed ?syntax? for this convention, though. > Except for _not_ doing what is suggested in those comments, which appears to be the biggest convention :-) -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From chris at simplistix.co.uk Tue Nov 17 06:36:33 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 Nov 2009 11:36:33 +0000 Subject: Calling Python functions from Excel In-Reply-To: References: Message-ID: <4B028AC1.8020307@simplistix.co.uk> Cannonbiker wrote: > Hi, > unfortunately is my question about server COM (win32com) > http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# > without answer. > > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. Try http://code.google.com/p/pyinex/ cheers, Chris From mr.spoon21 at gmail.com Tue Nov 17 07:00:45 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Tue, 17 Nov 2009 13:00:45 +0100 Subject: Logic operators with "in" statement In-Reply-To: <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> Message-ID: <8f67b6f80911170400g122fd52cwe02a090511c06813@mail.gmail.com> Thanks everybody for all the answers and explanations. In the end maybe it is simpler if I use sets for these tests. Thanks again. From stefan_ml at behnel.de Tue Nov 17 08:00:35 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 17 Nov 2009 14:00:35 +0100 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Robert P. J. Day, 15.11.2009 15:44: > On Sun, 15 Nov 2009, mrholtsr wrote: > >> I am absolutely new to python and barely past beginner in programming. >> Also I am not a mathematician. Can some one give me pointers for >> finding the 1000th. prime for a course I am taking over the internet >> on Introduction to Computer Science and Programming. Thanks, Ray > > it's 7919. Now, all that's left to do is write a prime number generator (a random number generator will do, too, but writing a good one isn't easy), run it repeatedly in a loop, and check if the returned number is 7919. Once it compares equal, you can print the result and you're done. Stefan From aaron.watters at gmail.com Tue Nov 17 08:48:10 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 17 Nov 2009 05:48:10 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> Message-ID: <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> > I don't think Python and Go address the same set of programmer > desires. ?For example, Go has a static type system. ?Some programmers > find static type systems to be useless or undesirable. ?Others find > them extremely helpful and want to use them them. ?If you're a > programmer who wants a static type system, you'll probably prefer Go > to Python, and vice versa. ?That has nothing to do with implementation > speed or development expenditures. ?If Google spent a million dollars > adding static types to Python, it wouldn't be Python any more. ... and I still have an issue with the whole "Python is slow" meme. The reason NASA doesn't build a faster Python is because Python *when augmented with FORTRAN libraries that have been tested and optimized for decades and are worth billions of dollars and don't need to be rewritten* is very fast. The reason they don't replace the Python drivers with Java is because that would be very difficult and just stupid and I'd be willing to bet that when they were done the result would actually be *slower* especially when you consider things like process start-up time. And when someone implements a Mercurial replacement in GO (or C# or Java) which is faster and more useful than Mercurial, I'll be very impressed. Let me know when it happens (but I'm not holding my breath). By the way if it hasn't happened and if he isn't afraid of public speaking someone should invite Matt Mackall to give a Python conference keynote. Or how about Bram Cohen for that matter... -- Aaron Watters http://listtree.appspot.com/ === if you want a friend, get a dog. -Truman From not_here at nowhere.com Tue Nov 17 09:19:39 2009 From: not_here at nowhere.com (me) Date: Tue, 17 Nov 2009 06:19:39 -0800 Subject: python gui builders In-Reply-To: References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> Message-ID: Read the OP. No, read it again. sturlamolden wrote: > On 16 Nov, 11:39, sturlamolden wrote: > >> If you are fine with Microsoft only, you can use Windows Forms with MS >> Visual Studio and IronPython. > > I also forgot to mention: > > If you can restrict yourself to Windows, you can always use Visual > Basic or Borland Delphi with pywin32. Either expose your GUI as an > ActiveX to pywin32 (you have e.g. an MFC binding) or expose your > Python as an ActiveX to VB/Delphi. The same approach should work (with > a little bit more work) for C# and VB.NET. From slafs.e at gmail.com Tue Nov 17 09:19:54 2009 From: slafs.e at gmail.com (Slafs) Date: Tue, 17 Nov 2009 06:19:54 -0800 (PST) Subject: XML root node attributes Message-ID: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Hi I'm little confused about adding attributes to the root node when creating an XML document. Can I do this using minidom or something else. I can't find anything that would fit my needs. i would like to have something like this: .... Please help. Regards. From davea at ieee.org Tue Nov 17 09:28:01 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 09:28:01 -0500 Subject: ZipFile - file adding API incomplete? In-Reply-To: <7mf5f6F3i297hU1@mid.uni-berlin.de> References: <7mf5f6F3i297hU1@mid.uni-berlin.de> Message-ID: <4B02B2F1.4030407@ieee.org> Diez B. Roggisch wrote: >
    Glenn > Maynard schrieb: >> I want to do something fairly simple: read files from one ZIP and add >> them to another, so I can remove and replace files. This led me to a >> couple things that seem to be missing from the API. >> >> >> >> The correct approach is to copy the data directly, so it's not >> recompressed. This would need two new API calls: rawopen(), acting >> like open() but returning a direct file slice and not decompressing >> data; and rawwrite(zinfo, file), to pass in pre-compressed data, where >> the compression method in zinfo matches the compression type used. >> >> I was surprised that I couldn't find the former. The latter is an >> advanced one, important for implementing any tool that modifies large >> ZIPs. Short-term, at least, I'll probably implement these externally. > > > > And regarding your second idea: can that really work? Intuitively, I > would have thought that compression is adaptive, and based on prior > additions to the file. I might be wrong with this though. > > I'm pretty sure that the ZIP format uses independent compression for each contained file (member). You can add and remove members from an existing ZIP, and use several different compression methods within the same file. So the adaptive tables start over for each new member. What isn't so convenient is that the sizes are apparently at the end. So if you're trying to unzip "over the wire" you can't readily do it without somehow seeking to the end. That same feature is a good thing when it comes to spanning zip files across multiple disks. The zip file format is documented on the net, but I haven't read the spec in at least 15 years. DaveA From cournape at gmail.com Tue Nov 17 09:28:09 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 17 Nov 2009 23:28:09 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: > >> I don't think Python and Go address the same set of programmer >> desires. ?For example, Go has a static type system. ?Some programmers >> find static type systems to be useless or undesirable. ?Others find >> them extremely helpful and want to use them them. ?If you're a >> programmer who wants a static type system, you'll probably prefer Go >> to Python, and vice versa. ?That has nothing to do with implementation >> speed or development expenditures. ?If Google spent a million dollars >> adding static types to Python, it wouldn't be Python any more. > > ... and I still have an issue with the whole "Python is slow" > meme. ?The reason NASA doesn't build a faster Python is because > Python *when augmented with FORTRAN libraries that have been > tested and optimized for decades and are worth billions of dollars > and don't need to be rewritten* is very fast. It is a bit odd to dismiss "python is slow" by saying that you can extend it with fortran. One of the most significant point of python IMO is its readability, even for people not familiar with it, and that's important when doing scientific work. Relying on a lot of compiled libraries goes against it. I think that python with its scientific extensions is a fantastic tool, but I would certainly not mind if it were ten times faster. In particular, the significant cost of function calls makes it quickly unusable for code which cannot be easily "vectorized" - we have to resort to using C, etc... to circumvent this ATM. Another point which has not been mentioned much, maybe because it is obvious: it seems that it is possible to makes high level languages quite fast, but doing so while keeping memory usage low is very difficult. Incidentally, the same tradeoff appears when working with vectorized code in numpy/scipy. David From carsten.haese at gmail.com Tue Nov 17 09:33:34 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 17 Nov 2009 09:33:34 -0500 Subject: Code for finding the 1000th prime In-Reply-To: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert P. J. Day, 15.11.2009 15:44: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray >> it's 7919. > > Now, all that's left to do is write a prime number generator (a random > number generator will do, too, but writing a good one isn't easy), run it > repeatedly in a loop, and check if the returned number is 7919. Once it > compares equal, you can print the result and you're done. Just do a brute-force search: for i in range(10000): if i==7919: # Found it! print i ;-) -- Carsten Haese http://informixdb.sourceforge.net From stefan_ml at behnel.de Tue Nov 17 09:36:47 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 17 Nov 2009 15:36:47 +0100 Subject: XML root node attributes In-Reply-To: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Message-ID: <4b02b4ff$0$7615$9b4e6d93@newsspool1.arcor-online.net> Slafs, 17.11.2009 15:19: > I'm little confused about adding attributes to the root node when > creating an XML document. > Can I do this using minidom or something else. Yes, you /can/, but you /should/ use something else. > I can't find anything that would fit my needs. > > i would like to have something like this: > > > > .... > Use ElementTree: import xml.etree.ElementTree as ET root = ET.Element("root", dict(a='v', b='v2', c='v3')) root.SubElement('d') print ET.tostring(root) Stefan From mmitchell at transparent.com Tue Nov 17 09:40:36 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Tue, 17 Nov 2009 09:40:36 -0500 Subject: XML root node attributes In-Reply-To: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Slafs Sent: Tuesday, November 17, 2009 9:20 AM To: python-list at python.org Subject: XML root node attributes Hi I'm little confused about adding attributes to the root node when creating an XML document. Can I do this using minidom or something else. I can't find anything that would fit my needs. i would like to have something like this: .... Please help. Regards. -- http://mail.python.org/mailman/listinfo/python-list Hi, I'm sure someone will point out a better way to do it but yes, you can do it with minidom. from xml.dom.minidom import Document doc = Document() root = doc.createElement('root') root.setAttribute('a', 'v') root.setAttribute('b', 'v2') root.setAttribute('c', '3') doc.appendChild(root) d = doc.createElement('d') root.appendChild(d) print doc.toprettyxml() From chandrakant.silver at gmail.com Tue Nov 17 09:42:42 2009 From: chandrakant.silver at gmail.com (silvercl) Date: Tue, 17 Nov 2009 06:42:42 -0800 (PST) Subject: Please recommend the books that might be helpful to learn Python :) References: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> Message-ID: <78068b48-784d-45ea-b43b-43c6c05fdba4@a32g2000yqm.googlegroups.com> On Nov 17, 7:18?am, Psi wrote: > as the subject says, > > any books? This is one of the good books available on the internet... http://diveintopython.org/ I myself liked this book very much (to start with). Also, on the website, on the right-hand-side it mentions about other books. -- Silver, Chandrakant. From tsize69 at gmail.com Tue Nov 17 09:55:03 2009 From: tsize69 at gmail.com (Tsize) Date: Tue, 17 Nov 2009 06:55:03 -0800 (PST) Subject: ast manipulation Message-ID: Hello, I am hoping for a little help. I have been playing with the python ast module and have run into an issue that I need a little push on. I would like to be able to change a specific element in a specific node in an ast then compile the resulting ast. Consider the simplified example below with its output. In this example I would like a way to change a specific addition operation. With the NodeTransformer I see how to change every addition operator but not how to change a specific one. I would like this to work on both the 2.6 and 3.1 branches. Ideally I would like to read a file, count the instances of an operation of interest and then use an index to make the changes. I am probably missing something simple but I am lost right now. import ast class SwitchMinusPlus(ast.NodeTransformer): def visit_BinOp(self, node): node = self.generic_visit(node) if isinstance(node.op, ast.Add): node.op = ast.Sub() return node myfile = open('trivial.py').read() print myfile tree = compile(myfile, '', 'exec', ast.PyCF_ONLY_AST) print ast.dump(tree, annotate_fields=False, include_attributes=False) node = SwitchMinusPlus().visit(ast.parse(myfile)) print ast.dump(node, annotate_fields=False, include_attributes=False) Which gives the following output: Note that this code changes the addition operator to an subtraction operator at the AST level for every instance. a = 8 b = 6 c = b + a d = c + a Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store ())], Num(6)), Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a', Load()))), Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a', Load())))]) Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store ())], Num(6)), Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a', Load()))), Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a', Load())))]) Thanks in advance, Thomas From davea at ieee.org Tue Nov 17 10:02:13 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 10:02:13 -0500 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <4B02BAF5.8090005@ieee.org> Virgil Stokes wrote: >
    If one > goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > > and if you now click on the tab labeled "history and compare" this > will take you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > > Finally...This is where I would like to "connect to" the data on a > daily basis or to gather data over different time intervals. I believe > that if I can get some help on this, then I will be able to customize > the code as needed for my own purposes. > > It should be clear that this is financial data on a fond managed by > Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. > > Note, that I do have some experience with Python (2.6 mainly), and > find it a very useful and powerful language. However, I have no > experience with it in the area of Web services. Any > suggestions/comments on how to set up this financial data service > project would be greatly appreciated, and I would be glad to share > this project with any interested parties. > > Note, I posted a similar message to the list pywebsvcs; but, received > no responses. > > -- V. Stokes > > I still say you should contact the bank and see if they have any API or interface defined, so you don't have to do web-scraping. The following text is on the XHTML page for that last link:
    ''' TIA, V On Mon, Nov 9, 2009 at 1:14 PM, Rami Chowdhury wrote: > On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > Did you give up on me? >> V >> >> On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi > >wrote: >> >> [root at 13gems angrynates.com]# chcon -R -h >>> unconfined_u:object_r:httpd_sys_content_t global_solutions/* >>> >>> Then I surfed to >>> http://209.216.9.56/global_solutions/index.py >>> >>> [root at 13gems angrynates.com]# tail /var/log/messages >>> Nov 8 04:26:02 13gems syslogd 1.4.1: restart. >>> [root at 13gems angrynates.com]# tail /var/log/httpd/error_log >>> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest >>> authentication ... >>> [Sun Nov 08 05:35:10 2009] [notice] Digest: done >>> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session >>> mutexes >>> based on 10 max processes and 0 max threads. >>> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- >>> resuming normal operations >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not >>> exist: /var/www/html/angrynates.com/favicon.ico >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file >>> or directory: exec of '/var/www/html/ >>> angrynates.com/global_solutions/index.py' failed, referer: >>> http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end >>> of >>> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not >>> exist: /var/www/html/angrynates.com/favicon.ico >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file >>> or directory: exec of '/var/www/html/ >>> angrynates.com/global_solutions/index.py' failed, referer: >>> http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end >>> of >>> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >>> >>> TIA, >>> V >>> >>> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury < >>> rami.chowdhury at gmail.com>wrote: >>> >>> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >>>> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >>>> > httpd_sys_content_t global_solutions >>>> > chcon: can't apply partial context to unlabeled file global_solutions >>>> > Please advise. >>>> >>>> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >>>> global_solutions/*', which should specify the whole context at once and >>>> avoid >>>> that error, as well as apply it recursively to all files and >>>> subdirectories. >>>> >>>> Also, to narrow down the error, can you let us have the output of: >>>> tail /var/log/messages >>>> tail /var/log/httpd/error_log >>>> >>>> > OK, after all this I've forgotten what your .py file looked like -- can you > post that please? > > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 9 13:43:22 2009 From: rt8396 at gmail.com (r) Date: Mon, 9 Nov 2009 10:43:22 -0800 (PST) Subject: Choosing GUI Module for Python References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> Message-ID: <6ee3b0be-9cff-42d6-b14e-f0277af79374@u13g2000vbb.googlegroups.com> On Nov 9, 3:59?am, Antony wrote: > I would like to know about that pros and cons only ... I'll reiterate what i have said and others have said. WE NEED MORE INFO TO PROPERLY GUIDE YOU!!! Survey: What GUI is right for you? 1. What is your level of GUI programming? (0 1 2 3 4 5) 2. Will you be using this GUI for your own apps or distributing the apps? 3. What is the primary OS that this app will be used on (or any)? 4. What type of app (graphics(2D/3D), texteditor, hello world)? 5. Are themes/customizable look and feel important? *. You mentioned IDE's. That of course will narrow your choice pool substantially. Tkinter: +Is included in Python as a built-in module! +very easy to learn! +adequate docs! -lacks professional appearance -lacks many important widgets http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://effbot.org/tkinterbook/ wxPython: +larger richer widget set than tk! +better look and feel than tk! +opengl canvas built-in! -not as easy to learn as tk -docs are lacking at best (i really wish this were better!) -not built-in to Python (rightly so, too big!) i won't comment on the others. If you have absolutely no experience try out Tkinter just to a feel for GUI in a hand holding environment. If you are not happy with Tkinter's simplicity then move on to a full featured GUI kit if you need the more advanced stuff. I would say try them all! I would also suggest you learn to code GUI's without an IDE. I think the experience is more rewarding. You should know every bit of code you create personally! From joncle at googlemail.com Mon Nov 9 13:49:35 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 10:49:35 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: <5dface4a-ffa0-41b1-9f42-eeae9e80c91b@v25g2000yqk.googlegroups.com> On Nov 9, 5:22?pm, "Alf P. Steinbach" wrote: > * Jon Clements: > > > > > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: > >> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > >> It's now Python 3.x, and reworked with lots of graphical examples and more > >> explanatory text, plus limited in scope to Basic Concepts (which I previously > >> just had as a first ch 2 section ?-- ?but there's rather a lot of concepts!). > > >> I think it's wise to invite comments even when it's not 100% completed. First, > >> because as opposed to ch 1 there is quite a bit of code here, and since I'm a > >> Python newbie I may be using non-idiomatic constructs, not to mention doing > >> worse things. :-) Second, because comments in general can improve the text. > > >> Contents: > > >> 2.1 Super-basic concept: why programming is not DWIM. ? 1 > >> 2.2 Reported errors. ? ?4 > >> 2.2.1 ? Case-sensitity. 4 > >> 2.2.2 ? Syntax / compilation errors. ? ?4 > >> 2.2.3 ? Runtime errors / crashes. ? 5 > >> 2.3 A programming exploration tool: turtle graphics. ? ?6 > >> 2.4 Naming things. ?8 > >> 2.4.1 ? Naming actions: routines. ? 8 > >> 2.4.2 ? Naming data part I: variables. ?11 > >> 2.4.3 ? Naming data part II: routine arguments. 13 > >> 2.5 Controlling the flow of execution. ?14 > >> 2.5.1 ? Repeating actions automatically: loops. 14 > >> 2.5.2 ? Basic comparisions & boolean values. ? ?16 > >> 2.5.3 ? Interlude I: a function graph program / about types. ? ?17 > >> 2.5.4 ? Automated action choices. ? 21 > >> 2.5.5 ? Value-producing (function-like) routines. ? 23 > >> 2.5.6 ? Interlude II: a graph with zeroes marked / about program structure. 26 > >> 2.5.7 ? Dynamically nested actions: recursive routines. 28 > >> 2.6 Objects. ? ? [Not started on this] 31 > >> 2.7 Collections. ? ?[Not started on this] 31 > > >> In Google Docs (both chapters available here): > > >> ? ? ? > >> ? ? ?Formats: PDF > > >> Cheers, > > >> - Alf > > > Well, you may not like it, but it is perfectly acceptable and indeed > > promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use > > of a well understood and oft-used idiom. I they're a lot of them, you > > generally have a settings module, that just lists all of the > > 'constants' (.h files effectively). > > Yeah, I thought of that angle so I emphasized 'programs'. > > As it happens about half or more of the variables in the examples are constants. > > All uppercase convention for that would be ugly to me. :-) Okies, maybe introducing the fact that lots of 'programs' often have constants, which are quite often settings or whatever and they would use the uppercase notation (and if numerous, in a separate module). Also maybe you can introduce the fundamental idea of a 'namespace', maybe something like: class const: pi = 3.14 name = 'Alf' language = 'Python' or whatever, then reference const. ? I'm not 100% sure I'm keen on this idea, but it's an option you can consider at least. Introduces a couple of bits that may be discussed later, but I'd be a little scared that people would start thinking 'const.' was something magical. > > > "Technically line_length is a variable"...: No - it's a name that > > binds to an object that happens to be an integer. You've participated > > in discussions re: this. Similarly 'number_of_apples = > > number_of_apples + 1' is not an assignment ;) > > Ah, you're kidding. > > Probably. > > Anyways, that's the terminology employed by the language reference, and even if > it wasn't I'd use it because this is primarily introduction to programming in > general, where Python just happens to be the vehicle; thus, language independent > terminology preferred (e.g., I use "routine" instead of C/Python "function"). > > > It's nit-picky and I > > realise you're trying to keep it simple, but as it's meant for new > > programmers to the Python language, then introduce them to Python's > > way of "variables", they'll thank you for it later... (or run > > screaming, or start another thread here...) > > Yeah, good point, thanks! > > But it will have to wait till I get down into details... ;-) > Fair enough. It would be nice though to cover stuff like: a = [1,2,3] b = a - b is not a *copy* of a - b is not a *reference* to a - b just happens to be another name for the list object. And stuff about mutable/immutable: it would certainly help with a lot of gotcha's. > > I've never seen/heard != described as "different from"; what's wrong > > with "not equal to"? > > Thanks! > > > And why no mention of 'not' (should be mentioned > > with booleans surely?). > > Again, I'll discuss that later. It's just too much to bring up. Most of my work > with this has been to pare down to essentials and *remove* stuff I'd written. > Well, should you re-write != as "not equal to", it wouldn't hurt to mention a little later that not False is True and vice versa... > > That's as far as I've got; might get around to reading more later... > > > Cool tree at the end :) > > Thanks! > > Cheers, > > - Alf Cheers, Jon. From rami.chowdhury at gmail.com Mon Nov 9 13:53:04 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 10:53:04 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi wrote: > Of course. Let me start with some updates to httpd.conf, which didn't > help > anyway: > > > ServerAdmin me at creative.vi > DocumentRoot /var/www/html/angrynates.com > ServerName angrynates.com > Options +ExecCGI -IncludesNoExec > > Options +ExecCGI > AllowOverride All > AllowOverride FileInfo > #AddHandler mod_python .py > #PythonHandler mod_python.publisher > #PythonDebug On > AddHandler cgi-script .cgi .py > Options Includes Indexes SymLinksIfOwnerMatch ExecCGI > > SecFilterEngine Off > > > SecRuleEngine Off > > AddHandler cgi-script .cgi .py > Options Includes Indexes SymLinksIfOwnerMatch ExecCGI > > > SecFilterEngine Off > > > SecRuleEngine Off > > > > > > Here's index.py: > > #!/usr/bin/python > > import string > import cgitb; cgitb.enable() > import cgi > import sys,os > sys.path.append(os.getcwd()) > from template import template > > ourFile = string.split(__file__, "/") > page = ourFile[len(ourFile) - 1][:-3] > > form = cgi.FieldStorage() > w = form.getfirst('w', '1024') > > template(page, w) > > Can you try running index.py from the command-line, and let me know if that works? Also, as you've already been asked - please start your replies *below* the text you are replying to. Putting your replies above the last email, or "top-posting" makes reading long email threads with lots of text distracting and frustrating. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From eyal.gordon at gmail.com Mon Nov 9 14:05:31 2009 From: eyal.gordon at gmail.com (Eyal Gordon) Date: Mon, 9 Nov 2009 21:05:31 +0200 Subject: questions regarding stack size use for multi-threaded python programs Message-ID: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Hi, background: we are using python 2.4.3 on CentOS 5.3 with many threads - and our shell's default stack size limit is set to 10240KB (i.e. ~10MB). we noticed that python's Threading module appears to create threads with this value as their stack size (we ran a sample program that creates 10 threads and measured its virtual memory size, then reduced the stack size limit of the shell to 5120KB - and saw that the program's virtual memory size was reduced by ~50MBs). the problem: our program uses numerous threads, and thus the virtual memory size gets to be very large. we would like to reduce the size of the stack to reduce this size. we were looking for information about recommendation for the stack size to use, but found none. questions: 1. is there some rule-of-thumb for the recommended stack size for python programs of various sorts? 2. is there a way for us, at runtime (from inside the code or outside the process), to find how much of a thread's stack we are using (in KB or some other size units)? 3. when we define local objects - do the objects themselves get allocated on the stack - or are they allocated on the heap and only references to them are kept on the stack? 4. would the size of the stacks (which are probably not really allocated by the linux virtual memory sub-system, unless used) have a noticeable performance effect on a python program? same question regarding the use of a large number of threads? thanks, Eyal -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan at baselinedata.co.uk Mon Nov 9 14:18:56 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 19:18:56 +0000 Subject: String prefix question In-Reply-To: References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: <4AF86B20.3080208@baselinedata.co.uk> Benjamin Kaplan wrote: > On Sun, Nov 8, 2009 at 9:38 PM, Alan Harris-Reid > wrote: > >> In the Python.org 3.1 documentation (section 20.4.6), there is a simple >> "Hello World" WSGI application which includes the following method... >> >> def hello_world_app(environ, start_response): >> status ='200 OK' # HTTP Status >> headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers >> start_response(status, headers) >> >> # The returned object is going to be printed >> return [b"Hello World"] >> >> Question - Can anyone tell me why the 'b' prefix is present before each >> string? The method seems to work equally well with and without the prefix. >> From what I can gather from the documentation the b prefix represents a >> bytes literal, but can anyone explain (in simple english) what this means? >> >> Many thanks, >> Alan >> > > The rather long version: > read http://www.joelonsoftware.com/articles/Unicode.html > > A somewhat shorter summary, along with how Python deals with this: > > Once upon a time, someone decided to allocate 1 byte for each > character. Since everything the Americans who made the computers > needed fit into 7 bits, this was alright. And they called this the > American Standard Code for Information Interchange (ASCII). When > computers came along, device manufacturers realized that they had 128 > characters that didn't mean anything, so they all made their own > characters to show for the upper 128. And when they started selling > computers internationally, they used the upper 128 to store the > characters they needed for the local language. This had several > problems. > > 1) Files made by on one computer in one country wouldn't display right > in a computer made by a different manufacturer or for a different > country > > 2) The 256 characters were enough for most Western languages, but > Chinese and Japanese need a whole lot more. > > To solve this problem, Unicode was created. Rather than thinking of > each character as a distinct set of bits, it just assigns a number to > each one (a code point). The bottom 128 characters are the original > ASCII set, and everything else you could think of was added on top of > that - other alphabets, mathematical symbols, music notes, cuneiform, > dominos, mah jong tiles, and more. Unicode is harder to implement than > a simple byte array, but it means strings are universal- every program > will interpret them exactly the same. Unicode strings in python are > the default ('') in Python 3.x and created in 2.x by putting a u in > front of the string declaration (u'') > > Unicode, however, is a concept, and concepts can't be mapped to bits > that can be sent through the network or stored on the hard drive. So > instead we deal with strings internally as Unicode and then give them > an encoding when we send them back out. Some encodings, such as UTF-8, > can have multiple bytes per character and, as such, can deal with the > full range of Unicode characters. Other times, programs still expect > the old 8-bit encodings like ISO-8859-1 or the Windows Ansi code > pages. In Python, to declare that the string is a literal set of bytes > and the program should not try and interpret it, you use b'' in Python > 3.x, or just declare it normally in Python 2.x (''). > > ------------------------------------------------------ > What happens in your program: > > When you print a Unicode string, Python has to decide what encoding to > use. If you're printing to a terminal, Python looks for the terminal's > encoding and uses that. In the event that it doesn't know what > encoding to use, Python defaults to ASCII because that's compatible > with almost everything. Since the string you're sending to the web > page only contains ASCII characters, the automatic conversion works > fine if you don't specify the b''. Since the resulting page uses UTF-8 > (which you declare in the header), which is compatible with ASCII, the > output looks fine. If you try sending a string that has non-ASCII > characters, the program might throw a UnicodeEncodeError because it > doesn't know what bytes to use for those characters. It may be able to > guess, but since I haven't used WSGI directly before, I can't say for > sure. > Thanks Benjamin - great 'history' lesson - explains it well. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 9 14:24:33 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 14:24:33 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Message-ID: <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury wrote: > On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > Of course. Let me start with some updates to httpd.conf, which didn't help >> anyway: >> >> >> ServerAdmin me at creative.vi >> DocumentRoot /var/www/html/angrynates.com >> ServerName angrynates.com >> Options +ExecCGI -IncludesNoExec >> >> Options +ExecCGI >> AllowOverride All >> AllowOverride FileInfo >> #AddHandler mod_python .py >> #PythonHandler mod_python.publisher >> #PythonDebug On >> AddHandler cgi-script .cgi .py >> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >> >> SecFilterEngine Off >> >> >> SecRuleEngine Off >> >> AddHandler cgi-script .cgi .py >> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >> >> >> SecFilterEngine Off >> >> >> SecRuleEngine Off >> >> >> >> >> >> Here's index.py: >> >> #!/usr/bin/python >> >> import string >> import cgitb; cgitb.enable() >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from template import template >> >> ourFile = string.split(__file__, "/") >> page = ourFile[len(ourFile) - 1][:-3] >> >> form = cgi.FieldStorage() >> w = form.getfirst('w', '1024') >> >> template(page, w) >> >> >> > Can you try running index.py from the command-line, and let me know if that > works? > It runs fine. So I created a test file of the same, chmod and tried it on my browser. Rendered. So I deleted index.py and recreated it from the command line, chmod. Rendered! Apparently, somehow in the translation from uploading it via ftp to moving the files to a new dir, something got screwed up in the permissions that I can't see! Any idea what the heck that could possibly be?? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Mon Nov 9 14:27:25 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 11:27:25 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi wrote: > On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury > wrote: > >> On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> Of course. Let me start with some updates to httpd.conf, which didn't >> help >>> anyway: >>> >>> >>> ServerAdmin me at creative.vi >>> DocumentRoot /var/www/html/angrynates.com >>> ServerName angrynates.com >>> Options +ExecCGI -IncludesNoExec >>> >>> Options +ExecCGI >>> AllowOverride All >>> AllowOverride FileInfo >>> #AddHandler mod_python .py >>> #PythonHandler mod_python.publisher >>> #PythonDebug On >>> AddHandler cgi-script .cgi .py >>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>> >>> SecFilterEngine Off >>> >>> >>> SecRuleEngine Off >>> >>> AddHandler cgi-script .cgi .py >>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>> >>> >>> SecFilterEngine Off >>> >>> >>> SecRuleEngine Off >>> >>> >>> >>> >>> >>> Here's index.py: >>> >>> #!/usr/bin/python >>> >>> import string >>> import cgitb; cgitb.enable() >>> import cgi >>> import sys,os >>> sys.path.append(os.getcwd()) >>> from template import template >>> >>> ourFile = string.split(__file__, "/") >>> page = ourFile[len(ourFile) - 1][:-3] >>> >>> form = cgi.FieldStorage() >>> w = form.getfirst('w', '1024') >>> >>> template(page, w) >>> >>> >>> >> Can you try running index.py from the command-line, and let me know if >> that >> works? >> > > It runs fine. So I created a test file of the same, chmod and tried it > on my > browser. Rendered. So I deleted index.py and recreated it from the > command > line, chmod. Rendered! Apparently, somehow in the translation from > uploading > it via ftp to moving the files to a new dir, something got screwed up in > the > permissions that I can't see! Any idea what the heck that could possibly > be?? > TIA, > V What platform did you upload from? Something as seemingly insignificant as Windows line-endings can mess up file execution... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From joncle at googlemail.com Mon Nov 9 14:36:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 11:36:08 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> <5dface4a-ffa0-41b1-9f42-eeae9e80c91b@v25g2000yqk.googlegroups.com> Message-ID: <85ebdc3a-5ed3-4567-80a7-a319832de68c@n35g2000yqm.googlegroups.com> [posts snipped] The only other thing is that line_length is used as a constant in one of the programs. However, it's being mutated in the while loop example. It may still be in the reader's mind that line_length == 10. (Or maybe not) Cheers, Jon. From davecook at nowhere.net Mon Nov 9 14:55:35 2009 From: davecook at nowhere.net (Dave Cook) Date: 09 Nov 2009 19:55:35 GMT Subject: Choosing GUI Module for Python References: Message-ID: <0056b1e8$0$16924$c3e8da3@news.astraweb.com> On 2009-11-09, Antony wrote: > 1. PyGTK > 2. PyQT > 3. PySide > 4. wxPython > 5 . TKinter For cross-platform work, I'd choose either PyQt or wxPython. If you're not too worried about the dual license, I find PyQt the best combination of ease of use and features, particularly when used with Qt Designer. For commercial work, I'd use wxPython, which has a very liberal license. It's fairly featureful, but not very pleasant to use. Dave Cook From simon.hibbs at gmail.com Mon Nov 9 15:01:51 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Mon, 9 Nov 2009 12:01:51 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Having tried most of the options out there, personaly I've settled on two. I use Tkinter for ver simple GUIs such as single dialog boxes or results displays. The advantage of it being built-in to Python outweighs it's limitations. For anything more complex, I go for PyQT every time. QTDesigner is a full drag-and-drop GUI builder that rivals Visual Studio, and PyQT comes with a script to convert QTDesigner XML files into Python code, which you then subclass in your own script and attach your own code to the GUI widgets. There's a longer learning curve than Tkinter, but it's very much worth it for access to QTs mature and rich framework, with excellent professional-class documentation. Sorry, but wxWidgets which I have used doesn't come anywhere close. The main objection to using PyQT untill now was that for commercial development you needed to buy a license (it was free for GPL projects). That's rapidly becoming a non-issue as the core QT framework is now LGPL and Nokia have a project underway to produce PyQT compatible LGPL python bindings under the PySide project. Simon Hibbs From invalid at invalid.invalid Mon Nov 9 15:07:14 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 9 Nov 2009 20:07:14 +0000 (UTC) Subject: Choosing GUI Module for Python References: <0056b1e8$0$16924$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-09, Dave Cook wrote: > On 2009-11-09, Antony wrote: > >> 1. PyGTK >> 2. PyQT >> 3. PySide >> 4. wxPython >> 5 . TKinter > > For cross-platform work, I'd choose either PyQt or wxPython. > > If you're not too worried about the dual license, I find PyQt > the best combination of ease of use and features, particularly > when used with Qt Designer. > > For commercial work, I'd use wxPython, which has a very > liberal license. It's fairly featureful, but not very > pleasant to use. NB: One thing to I've noticed about wxPython is that if you follow the rules carefully, the cross-platform behavior consistency is pretty decent. However, if you're not careful, it's easy to do something the "wrong" way and have it still work fine on one platform, but not on another. During development, you need to test frequently on all the platforms you care about. If you wait until the end to test on that second/third platform, you may have accumulated enough minor problems that it becomes a real chore to try to figure them all out. -- Grant Edwards grante Yow! Why don't you ever at enter any CONTESTS, visi.com Marvin?? Don't you know your own ZIPCODE? From drobinow at gmail.com Mon Nov 9 15:27:10 2009 From: drobinow at gmail.com (David Robinow) Date: Mon, 9 Nov 2009 15:27:10 -0500 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: <4eb0089f0911091227l497c9342h74db66bf3b8a6140@mail.gmail.com> On Mon, Nov 9, 2009 at 11:46 AM, Moses wrote: > Hi Chris, > > The code is > > from scipy import * > from pylab import * > > x = [0.5,0.6,0.7,0.8,0.9,1.0] > y = [2,6,8,10,10,10] > > plot(x,y,linewidth=5.0) > show() > > and not > > from scipy import * > from pylab import * > > x1 = [0.5,0.6,0.7,0.8,0.9,1.0] > x2 = [0,1,2,3,4,5,6,7,8,9,10] > > plot(x1,y01,linewidth=5.0) > show() > Don't top-post use: axis([xmin,xmax,ymin,ymax]) See the documentation for details From robert.kern at gmail.com Mon Nov 9 15:45:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 Nov 2009 14:45:41 -0600 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: On 2009-11-09 10:43 AM, Moses wrote: > > Hi Chris, > > I am using python 2.6 and am using scipy and pylab. See the code below. You will want to ask matplotlib questions 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 victorsubervi at gmail.com Mon Nov 9 15:46:26 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 15:46:26 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> Message-ID: <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote: > > On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury wrote: > >> On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury >> >wrote: >>> >>> On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < >>>> victorsubervi at gmail.com> wrote: >>>> >>>> Of course. Let me start with some updates to httpd.conf, which didn't >>>> help >>>> >>>>> anyway: >>>>> >>>>> >>>>> ServerAdmin me at creative.vi >>>>> DocumentRoot /var/www/html/angrynates.com >>>>> ServerName angrynates.com >>>>> Options +ExecCGI -IncludesNoExec >>>>> >>>>> Options +ExecCGI >>>>> AllowOverride All >>>>> AllowOverride FileInfo >>>>> #AddHandler mod_python .py >>>>> #PythonHandler mod_python.publisher >>>>> #PythonDebug On >>>>> AddHandler cgi-script .cgi .py >>>>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>>>> >>>>> SecFilterEngine Off >>>>> >>>>> >>>>> SecRuleEngine Off >>>>> >>>>> AddHandler cgi-script .cgi .py >>>>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>>>> >>>>> >>>>> SecFilterEngine Off >>>>> >>>>> >>>>> SecRuleEngine Off >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Here's index.py: >>>>> >>>>> #!/usr/bin/python >>>>> >>>>> import string >>>>> import cgitb; cgitb.enable() >>>>> import cgi >>>>> import sys,os >>>>> sys.path.append(os.getcwd()) >>>>> from template import template >>>>> >>>>> ourFile = string.split(__file__, "/") >>>>> page = ourFile[len(ourFile) - 1][:-3] >>>>> >>>>> form = cgi.FieldStorage() >>>>> w = form.getfirst('w', '1024') >>>>> >>>>> template(page, w) >>>>> >>>>> >>>>> >>>>> Can you try running index.py from the command-line, and let me know if >>>> that >>>> works? >>>> >>>> >>> It runs fine. So I created a test file of the same, chmod and tried it on >>> my >>> browser. Rendered. So I deleted index.py and recreated it from the >>> command >>> line, chmod. Rendered! Apparently, somehow in the translation from >>> uploading >>> it via ftp to moving the files to a new dir, something got screwed up in >>> the >>> permissions that I can't see! Any idea what the heck that could possibly >>> be?? >>> TIA, >>> V >>> >> >> What platform did you upload from? Something as seemingly insignificant as >> Windows line-endings can mess up file execution... >> > > OS is Windoze XL. Have we caught the thief? How can I upload from this box > and not have this problem, or undo it at the server? You know, of course, I > don't see this line-ending from the command prompt when I vi it. > TIA, > V > > Hold everything. Apparently line-endings got mangled. What I don't understand is why I didn't see them when I opened the file to edit, and why they didn't copy and paste when I did that. But dos2unix cleaned up a couple of files so I presume it will clean up the rest. However, I tried one file, that reads exactly the same as index.py, and when I surfed to it got a 500 error. Here's what the log said: [Mon Nov 09 12:30:27 2009] [notice] mod_python: (Re)importing module 'mptest' [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: Traceback (most recent call last):, referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch\n log=debug), referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 461, in import_module\n f, p, d = imp.find_module(parts[i], path), referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: ImportError: No module named mptest, referer: http://www.angrynates.com/global_solutions/ Huh? Got no "mptest" anywhere. Not even using mod_python. Why doesn't it refer to a specific file in the folder? Any ideas on this one? TIA, V > >> >> >> -- >> Rami Chowdhury >> "Never attribute to malice that which can be attributed to stupidity" -- >> Hanlon's Razor >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdekauwe at gmail.com Mon Nov 9 17:02:56 2009 From: mdekauwe at gmail.com (Martin) Date: Mon, 9 Nov 2009 14:02:56 -0800 (PST) Subject: How to set the range for x-axis References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: <07c2fcef-87d1-4b9a-a552-8c63fee3e02c@p8g2000yqb.googlegroups.com> On Nov 9, 8:45?pm, Robert Kern wrote: > On 2009-11-09 10:43 AM, Moses wrote: > > > > > Hi Chris, > > > I am using python 2.6 and am using scipy and pylab. See the code below. > > You will want to ask matplotlib questions 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 import matplotlib.pyplot as plt plt.xlim(0., 1.) From mchl.dodd at gmail.com Mon Nov 9 17:08:18 2009 From: mchl.dodd at gmail.com (Michael) Date: Mon, 9 Nov 2009 14:08:18 -0800 (PST) Subject: IDLE python shell freezes after running show() of matplotlib References: <4c44996a-0a6a-4a4f-9607-e0323fbd1aa9@l35g2000vba.googlegroups.com> Message-ID: <07733d48-37a4-4216-92fb-40285efd4bef@a31g2000yqn.googlegroups.com> On Oct 28, 11:09?pm, Chris Colbert wrote: > This is a threading issue that is very common when using gui toolkits > with the interactive interpreter. > > You're better off just using ipython, which already has builtin > support for matplotlib when you start it via "ipython -pylab" > > On Wed, Oct 28, 2009 at 7:41 PM, OKB (not okblacke) > > > > wrote: > > Forrest Sheng Bao wrote: > > >> I am having a weird problem on IDLE. After I plot something using show > >> () of matplotlib, the python shell prompt in IDLE just freezes that I > >> cannot enter anything and there is no new ">>>" prompt show up. I > >> tried ctrl - C and it didn't work. I have to restart IDLE to use it > >> again. > > >> My system is Ubuntu Linux 9.04. I used apt-get to install IDLE. > > > ? ? ? ?I believe this is the intended behavior. ?Look in matplotlib > > documentation on the difference between interactive and non-interactive > > modes. > > > -- > > --OKB (not okblacke) > > Brendan Barnwell > > "Do not follow where the path may lead. ?Go, instead, where there is > > no path, and leave a trail." > > ? ? ? ?--author unknown > > -- > >http://mail.python.org/mailman/listinfo/python-list Same problem for me using IDLE 1.2.4, python 2.5.4, and matplotlib 0.99.1.1. Windows XP 32bit. Turning on interactive mode solved the problem with IDLE freezing, however the plot window still comes up empty and frozen. Using iPython now with no problems so far. Hopefully the problem with IDLE gets fixed. From rhodri at wildebst.demon.co.uk Mon Nov 9 18:01:00 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 09 Nov 2009 23:01:00 -0000 Subject: Can't Find Module In-Reply-To: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> References: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> Message-ID: On Sat, 07 Nov 2009 16:59:29 -0000, Victor Subervi wrote: > ImportError: No module named template [snip] > > I can import this just fine from the python command prompt. So, what > gives? Is template.py in your current directory when you run the script from the command line? -- Rhodri James *-* Wildebeest Herder to the Masses From powderdrop at gmail.com Mon Nov 9 18:29:03 2009 From: powderdrop at gmail.com (Penn) Date: Mon, 9 Nov 2009 15:29:03 -0800 (PST) Subject: NEWB problem with urllib2 Message-ID: I just installed PyDev into Eclipse using the 'update' method and did the standard installation. I allowed it to Auto Configure itself and ran a "Hello World" module to make sure I was in the ballpark. I got an starting module up and have run "Hello World" but now am stuck on getting urlopen to import from urllib2 for the following example. from urllib2 import * # doesn't give me an error ur = urlopen("http://www.daniweb.com/forums/thread161312.html") # gives me Undefined Variable: urlopen so I tried just import urllib2 # Eclipse gives "Unresolved Import" Is urllib2 not on my path? Isn't urllib2 in the standard installation and shouldn't that automatically be on my path? If not, how can I get it on the path? ThankS!! From Ken at Elkabany.com Mon Nov 9 19:20:12 2009 From: Ken at Elkabany.com (Ken Elkabany) Date: Mon, 9 Nov 2009 16:20:12 -0800 Subject: PiCloud Beta Release In-Reply-To: <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> References: <47ab340d-befa-4ad8-99db-fd4494ace7fa@x25g2000prf.googlegroups.com> <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> Message-ID: On Thu, Nov 5, 2009 at 3:19 PM, Jacob Shaw wrote: > On Nov 1, 5:13?pm, Ken Elkabany wrote: >> Hello, >> >> PiCloud has just released a Python library, cloud, which allows you to >> easily offload the execution of a function to a cluster of servers >> running on Amazon Web Services. As a beta product, we are currently >> free to all users who sign up with beta code "PYTHONLIST". To >> register, go tohttp://www.picloud.com >> >> Full service description: >> PiCloud is a cloud-computing platform that integrates into the Python >> Programming Language. It enables you to leverage the compute power of >> Amazon Web Services without having to manage, maintain, or configure >> virtual servers. >> >> PiCloud integrates seamlessly into your existing code base through a >> custom Python library, cloud. To offload the execution of a function >> to the cloud, all you must do is pass your desired function into the >> cloud library. PiCloud will then run the function on its >> high-performance and automatically-scaling cluster. We quickly scale >> our server capacity, both up and down, to meet your computational >> needs, and only charge you for the resources you actually consume. >> Getting on the cloud has never been this easy! >> >> PiCloud improves the full cycle of software development and >> deployment. Functions that are run on PiCloud have their resource >> usage monitored, performance analyzed, and errors traced; we further >> aggregate all your functions to give you a bird's eye view of your >> service. Through these introspective capabilities, PiCloud enables you >> to develop faster, easier, and smarter. >> >> Common use cases for our platform: >> * Crawling the web >> * Manipulating images and videos >> * Generating charts and graphs >> * Statistical/Mathematical analysis of data sets >> * Real-time data processing >> >> Cheers, >> >> Ken Elkabany >> PiCloud, Inc. > > Wow, amazing service. ?I used PiCloud for some scraping work, and my > script ran about 10x as fast. > > Some questions though: > 1) I have another project which uses a custom python extension written > in C++. ?Is there a way to use it on PiCloud? > 2) I noticed you guys only support python 2.5 and 2.6. ?Will there be > 3.1 support eventually? > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the compliments. 1) PiCloud will not automatically transfer libraries that require python C++ extensions. However, in your control panel, you can upload a tarball or synchronize an svn repository that contains your extension's code and we'll automatically compile/install it on our systems. 2) We are currently working on support for python 3.x (we've had requests from a fair number of users), and plan to release a compatible client library in a couple of weeks. Ken From swindle at ifa.hawaii.edu Mon Nov 9 19:24:19 2009 From: swindle at ifa.hawaii.edu (Ryan Swindle) Date: Mon, 9 Nov 2009 14:24:19 -1000 Subject: Socket programming with NetCom serial-to-ethernet module Message-ID: <69f048730911091624u732af9cfga612b51cedd17a24@mail.gmail.com> Hi, This is my first Python-list post; I hope it's going to the right place. Here's my problem: I've read many tutorials on socket programming, but I can't seem to piece them together for my particular case. I have 3 serial ports, each of which individually connects to a port on a NetCom box, which converts them to TCP/IP ports (see e.g. http://www.serialgear.com/4--Port-Serial-TCP-IP-NETCOM-411.html). But I'll just focus on communicating with 1 serial port right now (assume that I have a 1-port NetCom box). So, the flow pattern goes like this -- ascii string from my Python program via the ethernet card to the NetCom box, which feeds the serial port; this serial port is the input/output to a board that controls a motor. So, I can send an ascii string like "MI100\n", which tells that motor to move 100 steps. Currently, I can accomplish this using sockets. But if I instead want to request something from the motor, like it's current position, how do I return this information back to my Python program and still keep the socket alive and listening for say another position request? FYI, the NetCom box works on DHCP. So, I could use 'arp' or another method to actually find it's IP address, and I can connect to it using say port 2000. At this point, it looks as if I would setup a server socket for the NetCom box, and then create a client socket for the motor controller board to talk to the NetCom box (and e.g. give the current position of the motor, upon my request). But the hard part seems to be how to retrieve that information from the controller board, once it responds. For instance, if I were to just use pySerial, I open up a connection to the serial port, then serial.send(ascii) sends the request, and serial.readline() reads the response. I need to know how to implement this basic functionality with sockets, where the sockets remain alive and listening after each request/response, just as pySerial does. Any advice, sockets or not, is helpful and appreciated, and I can elaborate further on the problem, if requested. (Again, I hope this was not a misuse of the list in some way; I apologize, if so). Many thanks. -Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Nov 9 19:44:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 00:44:45 -0000 Subject: Indentation problems In-Reply-To: References: Message-ID: I'm going to make a whole bunch of wild guesses here, since you don't give us a lot to go on. Wild Guess #1: you're using IDLE. On Sun, 08 Nov 2009 19:01:37 -0000, Ray Holt wrote: > I am having problems with indentation some times. When I hit the enter > key > after if statements or while statemt there are times when the > indentation is > too much Wild Guess #2: you've forgotten to close a bracket of some sort. > and other times too little. Wild Guess #3: you've forgotten the colon on the end of the line > When I try to manually make sure the > indentation is correct and try to print, I ge the error message of > invalid > syntax or incorrect indentation. Ah. Wild Guess 1a: you're using IDLE in interactive mode. In that case, bear in mind Wild Guesses 2 and 3, but they aren't the whole story. In interactive mode, IDLE executes the code that you type Right Now This Instant And No Messing. When you type a compound statement like "if" or "while", that presents a bit of a problem since the statement isn't really finished until you've typed in all the statements that belong to that "if" or "while". Knowing this, IDLE puts off executing it, and helpfully adds the indentation that it knows you'll need. If you fiddle with that extra space and delete too much of it (easily done here), IDLE will tick you off for getting your indentation wrong. If you hit Return without typing anything else, IDLE will do exactly the same thing since it knows Python requires you to have at least one statement inside the "if". Once you've typed that one statement, you can carry on typing more to your hearts content; at this point, IDLE treats a blank line as meaning "I'm done." At this point it goes away and executes what you've typed Right Now This Instant And No Messing, and may end up complaining about something you got wrong three lines ago. > Can someone help me. Also when I open the > edit window instead of the shell the programs tend not to run. Help! Ray Well, no. Unlike the interactive window, typing into the edit window doesn't cause anything to be executed Right Now Etc Etc. It doesn't even cause anything to be executed Sometime Soon Honest Guv'nor. It just saves up what you've done so that it can be run later, assuming you remember to save it to a file. Unlike the interactive window, you can go back and change what you've written earlier to correct a mistake, and re-run the entire script rather than type it in again line by line. To actually run your program you have two alternatives. Either you can use the "Run Module" entry in the "Run" menu (F5 on my version: it may be called something slightly different in a slightly different menu with a slightly different shortcut key depending on your operating system and which version of IDLE you're running), or you can pull up a console (command line, terminal, xterm, whatever your OS calls it) and invoke Python on your file directly. If that last bit didn't make any sense to you, don't worry, just leave that particular adventure in computing for another day. -- Rhodri James *-* Wildebeest Herder to the Masses From Ognjen at mailshack.com Mon Nov 9 19:47:20 2009 From: Ognjen at mailshack.com (Ognjen Bezanov) Date: Tue, 10 Nov 2009 00:47:20 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? Message-ID: <4AF8B818.5090109@mailshack.com> Hello all, Say I have a python variable: a = "hello" Is it possible for me to get the physical address of that variable (i.e. where it is in RAM)? I know that id(a) will give me it's memory address, but the address given does not seem to correlate with the physical memory. Is this even possible? Thank you! Ognjen From rhodri at wildebst.demon.co.uk Mon Nov 9 20:02:49 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 01:02:49 -0000 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy wrote: > I believe the use of tagged pointers has been considered and so far > rejected by the CPython developers. And no one else that I know of has > developed a fork for that. It would seem more feasible with 64 bit > pointers where there seem to be spare bits. But CPython will have to > support 32 bit machines for several years. I've seen that mistake made twice (IBM 370 architecture (probably 360 too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see it a third time, thank you. -- Rhodri James *-* Wildebeest Herder to the Masses From benjamin.kaplan at case.edu Mon Nov 9 20:34:56 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 9 Nov 2009 20:34:56 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF8B818.5090109@mailshack.com> References: <4AF8B818.5090109@mailshack.com> Message-ID: On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address given > does not seem to correlate with the physical memory. Is this even possible? > > > Thank you! > > > Ognjen > When you use Python, program in Python and not C. What do you need the memory location of a variable for? Python, like Java and .NET is a higher level language. You're not supposed to worry about things like the physical location in memory. There's probably some ugly hack using ctypes, or just writing the code in C but I don't know enough about Python's C API to know what it is. FWIW, even the id(x) == address of x is only an implementation detail of CPython. Other Python implementations don't use that scheme. > -- > http://mail.python.org/mailman/listinfo/python-list > From sajmikins at gmail.com Mon Nov 9 20:39:59 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 9 Nov 2009 20:39:59 -0500 Subject: NEWB problem with urllib2 In-Reply-To: References: Message-ID: <50f98a4c0911091739n33a1a62eo39add8908566ba71@mail.gmail.com> On Mon, Nov 9, 2009 at 6:29 PM, Penn wrote: > I just installed PyDev into Eclipse using the 'update' method and did > the standard installation. ?I allowed it to Auto Configure itself and > ran a "Hello World" module to make sure I was in the ballpark. > > I got an starting module up and have run "Hello World" but now am > stuck on getting urlopen to import from urllib2 for the following > example. > > from urllib2 import * ? ?# doesn't give me an error > ur = urlopen("http://www.daniweb.com/forums/thread161312.html") # > gives me Undefined Variable: urlopen > > so I tried just > > import urllib2 ? ? ? ?# Eclipse gives "Unresolved Import" > > Is urllib2 not on my path? ?Isn't urllib2 in the standard installation > and shouldn't that automatically be on my path? ?If not, how can I get > it on the path? > > ThankS!! This sounds more like a PyDev and/or Eclipse problem than an urllib2 problem. :) One thing you can check: open the "raw" python interpreter outside of Eclipse and try importing urllib2 there. You might also try the interpreter interface within Eclipse (if it provides one.) HTH From python at mrabarnett.plus.com Mon Nov 9 20:44:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 01:44:57 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF8B818.5090109@mailshack.com> References: <4AF8B818.5090109@mailshack.com> Message-ID: <4AF8C599.9040202@mrabarnett.plus.com> Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address > given does not seem to correlate with the physical memory. Is this even > possible? > Python doesn't have variables as such. The variable's name is just a key in a dict and the variable's value is the corresponding value for that key (or, to be exact, a reference to the value). A particular value can be referred to by any number of 'variables'. From rhodri at wildebst.demon.co.uk Mon Nov 9 20:47:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 01:47:37 -0000 Subject: on "Namespaces" In-Reply-To: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: On Sun, 08 Nov 2009 21:20:23 -0000, webtourist wrote: > > New bie Question: > in "Zen of Python" - what exactly does the last one mean ? - > Namespaces are one honking great idea -- let's do more of those! > > I mean why the emphasis ? Is it like saying "put modules into > packages" in other programming paradigm s ? Like all things zen, 'meaning' as applied to this koan is a shifting concept best considered after deep meditiation on... oh, who am I kidding. If you keep names in separate namespaces, you are less likely to screw up by forgetting that you meant something else by that name 30 lines above. It's less about "put modules in packages" and more about "put code in modules." Corollary: what happens after "from somewhere import *" is all your own fault. -- Rhodri James *-* Wildebeest Herder to the Masses From powderdrop at gmail.com Mon Nov 9 20:48:01 2009 From: powderdrop at gmail.com (Penn) Date: Mon, 9 Nov 2009 17:48:01 -0800 (PST) Subject: NEWB problem with urllib2 References: Message-ID: Thanks Simon! You are right.. I also believe it is something with Eclipse. I've been working since... the module below runs.. but Eclipse is still showing an error when I reference urlopen with a little red X... saying it is an undefined variable in the IDE.. but not giving me an runtime errors. #URL LIBRARY from urllib2 import * def openfilereadaline(a): f = open(a) print f for line in f: print line.rstrip() f.close() def openWebSite(a): ur = urlopen(a) #open url contents = ur.readlines()#readlines from url file fo = open("test.txt", "w")#open test.txt for line in contents: print "writing %s to a file" %(line,) fo.write(line)#write lines from url file to text file fo.close()#close text file if __name__ == '__main__': openWebSite("http://www.daniweb.com/forums/thread161312.html") print "Hello World" From rhodri at wildebst.demon.co.uk Mon Nov 9 21:02:22 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 02:02:22 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 wrote: > Rhodri James wrote: >> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >> wrote: >> >>> I have a perplexing issue, I have four users set up on a W7 computer. >>> The program runs fine for all users except the admin user who needs it >>> for school assignments. >> A little more information, please. How does it not work for the admin >> user? Is there a traceback? What do you get if you try to invoke it >> from a command line? >> > > > Hi Rhodri, here's a dump file, don't know if this helps or not.. So Windows is reporting a crash, then. I'll repeat my last question in particular; what happens when your admin user runs the program you're trying to invoke from the command line? -- Rhodri James *-* Wildebeest Herder to the Masses From davea at ieee.org Mon Nov 9 21:12:21 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 09 Nov 2009 21:12:21 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> Message-ID: <4AF8CC05.8090902@ieee.org> Victor Subervi wrote: > On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote: > > >> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury wrote: >> >> >>> >> >> >> Hold everything. Apparently line-endings got mangled. What I don't >> > understand is why I didn't see them when I opened the file to edit, and why > they didn't copy and paste when I did that. But dos2unix cleaned up a couple > of files so I presume it will clean up the rest. However, I tried one file, > that reads exactly the same as index.py, and when I surfed to it got a 500 > error. Here's what the log said: > > > > What I've diagnosed as happening when a python script with Windows line-ending was posted on my server's cgi environment: The actual error seemed to be a failure to find the python interpreter, since some Unix shells take the shebang line to include the \r character that preceded the newline. Seems to me they could be more tolerant, since I don't think control characters are likely in the interpreter file name. DaveA From gagsl-py2 at yahoo.com.ar Mon Nov 9 21:16:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Nov 2009 23:16:40 -0300 Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk escribi?: > On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: >> >> Recently I put together this incomplete comparison chart in an attempt >> to choose between the different alternatives to py2exe: >> >> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > I was interested in py2exe because we'd like to provide a one download, > one click install experience for our Windows users. I think a lot of > people are interested in py2exe for the same reason. Well, one thing > that I came across in my travels was the fact that distutils can create > MSIs. Like py2exe, MSIs provide a one download, one click install > experience under Windows and therefore might be a replacement for py2exe. But py2exe and .msi are complementary, not a replacement. py2exe collects in one directory (or even in one file in some cases) all the pieces necesary to run your application. That is, Python itself + your application code + all referenced libraries + other required pieces. The resulting files must be installed in the client machine; you either build a .msi file (a database for the Microsoft Installer) or use any other installer (like InnoSetup, the one I like). > For me, the following command was sufficient to create an msi, although > it only worked under Windows (not under Linux or OS X): > python setup.py bdist_msi > > The resulting MSI worked just fine in my extensive testing (read: I > tried it on one machine). The resulting .msi file requires Python already installed on the target machine, if I'm not mistaken. The whole point of py2exe is to avoid requiring a previous Python install. > It seems, then, that creating an MSI is even within the reach of someone > like me who spends very little time in Windows-land, so it might be > worth a column on your chart alongside rpm/deb. As said in http://wiki.python.org/moin/DistributionUtilities the easiest way is to use py2exe + InnoSetup. -- Gabriel Genellina From patf at well.com Mon Nov 9 21:25:56 2009 From: patf at well.com (menomnon) Date: Mon, 9 Nov 2009 18:25:56 -0800 (PST) Subject: Debugging python in emacs isn't working. References: <4a54b1ba-0fd8-4947-9ca0-67d5c98de2d9@k13g2000prh.googlegroups.com> Message-ID: <082dffc7-6bd8-4733-bdd6-46a06a80a540@u36g2000prn.googlegroups.com> On Nov 8, 6:36?pm, menomnon wrote: > Hi, > > Emacs 22.3, python 2.6.4 > > Put the following into my .emacs: > > (setq pdb-path 'c:\\python26\\lib\\pdb.py > ? ? ? gud-pdb-command-name (symbol-name pdb-path)) > (defadvice pdb (before gud-query-cmdline activate) > ? "Provide a better default command line when called interactively." > ? (interactive > ? ?(list (gud-query-cmdline pdb-path > ? ? ? ? ? ? ? ? ? ? ? ? ? ? (file-name-nondirectory buffer-file-name))))) > > So when I'm in a python buffer (I've tried both python.el and python- > mode.el) and do M-x pdb I get, say: > > c:\python26\lib\pdb.py rpytest.py > > hit and get an empty buffer that says "Comint: no process". ?And > the status line says: "Spawning child process: invalid argument". > > I've run into "spawning child process: invalid argument" before but > not being an emacs uber-geek I never solved it directly. > > Hope someone has an idea of what I'm doing wrong. python -i. It's the -i part that's important. From davea at ieee.org Mon Nov 9 21:30:01 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 09 Nov 2009 21:30:01 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: References: <4AF8B818.5090109@mailshack.com> Message-ID: <4AF8D029.5040400@ieee.org> Benjamin Kaplan wrote: > On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov wrote: > >> Hello all, >> >> Say I have a python variable: >> >> a = "hello" >> >> Is it possible for me to get the physical address of that variable (i.e. >> where it is in RAM)? >> >> I know that id(a) will give me it's memory address, but the address given >> does not seem to correlate with the physical memory. Is this even possible? >> >> >> Thank you! >> >> >> Ognjen >> >> > > When you use Python, program in Python and not C. What do you need the > memory location of a variable for? Python, like Java and .NET is a > higher level language. You're not supposed to worry about things like > the physical location in memory. There's probably some ugly hack using > ctypes, or just writing the code in C but I don't know enough about > Python's C API to know what it is. > > FWIW, even the id(x) == address of x is only an implementation detail > of CPython. Other Python implementations don't use that scheme. > > > Following is for the CPython implementation. As Benjamin says, each implementation can do different things, as long as the documented semantics are preserved. The "variable" aaa is not at any particular location, and will quite likely move when you define a new "variable" bbb or ccc in the same scope. aaa is just a dictionary entry after all, in some scope. (Although it may be optimized, for locals, and for slots) aaa is bound to a particular object, and that object won't move. That object has an id() value, and I believe that id value is the address. And when you bind aaa to a different object, there'll be a different id() and address. But unless you're writing a C extension, the actual address is kind of irrelevant, isn't it? DaveA From pavlovevidence at gmail.com Mon Nov 9 21:30:13 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 9 Nov 2009 18:30:13 -0800 (PST) Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: On Nov 9, 4:47?pm, Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address > given does not seem to correlate with the physical memory. Is this even > possible? I'm going to guess that A. You don't really want physical address but logical address (i.e., the address where you might access the memory with a C pointer), and B. You want the address not of the object itself, but of the data within (that is, you'd want the "pointer" you receive to point to the ASCII string hello) Python's way to handle cases like this is called buffer protocol, but it only operates at the C-extension level. There is a set of functions in the C API that look like this PyObject_AsReadBuffer(obj,**buffer,*len) Calling this will return the address of the string "hello" in *buffer. See C API Reference Manual for more details. This function can also be called from ctypes, but I don't remember the exact procedure for modifying input arguments through a pointer. Note: If you really want a PHYSCIAL RAM address you'll have to make some OS-specific system call (I think) with the logical address, probably needing superuser privileges. Obviously this call isn't exposed in Python, because there's no use for it in Python. Unless you're programming DMA transfers or something like that, there's no use for it in C, either. Carl Banks From phlip2005 at gmail.com Mon Nov 9 22:48:26 2009 From: phlip2005 at gmail.com (Phlip) Date: Mon, 9 Nov 2009 19:48:26 -0800 (PST) Subject: how to create a pip package Message-ID: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Py hont: I have a single file that I need my crew to pip install. When I Google for "how to create a pip package" I don't hit anything. Of course that info is out there; I can't seem to pick up the trail of breadcrumbs to it. While I'm looking, could someone push the link in here? Purely for posterity? Thanks! -- Phlip http://c2.com/cgi/wiki?ZeekLand From steven at REMOVE.THIS.cybersource.com.au Mon Nov 9 23:52:42 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 04:52:42 GMT Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: On Mon, 09 Nov 2009 06:02:09 -0800, J Wolfe wrote: > Hi, > > I would like to sort this dictionary by the values of the inner > dictionary ?ob? key. You can't sort dictionaries in Python, because they are unordered hash tables. Giving up the ability to store items in order is one of the things which makes them so fast. You have five choices: (1) Create your own implementation of a sortable dictionary, perhaps using a red-black tree or similar. Unless you write it in C, expect it to be massively slower than the built-in dict type. If you write it in C, expect it to be merely slower than the built-in dict type. (2) Write small helper functions that sort the keys from the dict when you need them sorted. Since you (probably) only have a small number of items in each dict, it should be fast. (3) Use a subclass of dict that sorts the items as needed. (4) Give up on using dictionaries for this, and use some other mapping, like a list of (key, value) tuples. Expect it to be massively slower than the built-in dict type. (5) Give up on the need to have them sorted. My advice is to go with #2, 3 or 5. Here's a basic version of 3 to get you started: class SortedDict(dict): # Untested. def items(self): """Return items of self in sorted order.""" L = super(SortedDict, self).items() L.sort() return L You may even find a version with an appropriate licence you can freely use if you google for "Python Sorted Dict". -- Steven From gagsl-py2 at yahoo.com.ar Mon Nov 9 23:56:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 01:56:30 -0300 Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: En Sun, 08 Nov 2009 10:08:35 -0300, gil_johnson escribi?: > On Nov 6, 8:46 pm, gil_johnson wrote: > > The problem I was solving was this: I wanted an array of 32-bit > integers to be used as a bit array, and I wanted it initialized with > all bits set, that is, each member of the array had to be set to > 4294967295. Of course, you could set your initializer to 0, or any > other 32-bit number. > > Originally I found that the doubling method I wrote about before was a > LOT faster than appending the elements one at a time, and tonight I > tried the "list = initializer * N" method. Running the code below, the > doubling method is still fastest, at least on my system. > > Of course, as long as you avoid the 'one at a time' method, we're > talking about fractions of a second, even for arrays that I think are > huge, like the 536,870,912 byte beastie below. I don't get your same results; one_item*N is faster on my tests. Note that you're comparing disparate things: > # Doubling method, run time = 0.413938045502 > newArray = array.array('I') # 32-bit unsigned > integers Method 1 creates an array object; this takes roughly 2**29 bytes > # One at a time, run time = 28.5479729176 > newArray2 = array.array('I') > for i in range(134217728): # the same size as above > newArray2.append(4294967295) This creates also an array object, *and* 134 million integer objects in the meantime. > # List with "*", run time = 1.06160402298 > newList = [4294967295] * 134217728 And this creates a list object, not an array. Note that all your 3 methods create global objects and you never delete them - so the last method is at a disadvantage. A more fair test would use timeit, and run just one method at a time: # Written in Python 3.x # use xrange everywhere with Python 2.x import array INITIAL_VALUE = 4294967295 LOG2SIZE=25 SIZE = 2**LOG2SIZE def method1a(): newArray = array.array('I') newArray.append(INITIAL_VALUE) for i in range(LOG2SIZE): newArray.extend(newArray) assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method2a(): newArray = array.array('I') for i in range(SIZE): newArray.append(INITIAL_VALUE) assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method3a(): newArray = array.array('I', [INITIAL_VALUE]) * SIZE assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method1l(): newList = [INITIAL_VALUE] for i in range(LOG2SIZE): newList.extend(newList) assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE def method2l(): newList = [] for i in range(SIZE): newList.append(INITIAL_VALUE) assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE def method3l(): newList = [INITIAL_VALUE] * SIZE assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE D:\temp>python31 -m timeit -s "from arraygrow import method1a" "method1a()" 10 loops, best of 3: 411 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method2a" "method2a()" ...aborted, too long... D:\temp>python31 -m timeit -s "from arraygrow import method3a" "method3a()" 10 loops, best of 3: 377 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method1l" "method1l()" 10 loops, best of 3: 628 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method3l" "method3l()" 10 loops, best of 3: 459 msec per loop So arrays are faster than lists, and in both cases one_item*N outperforms your doubling algorithm. Adding one item at a time is -at least- several hundred times slower; I was not patient enough to wait. > Finally, I just looked into calling C functions, and found > PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management > section of the Python/C API Reference Manual. This gives you > uninitialized memory, and should be really fast, but it's 6:45 AM > here, and I don't have the energy to try it. No, those are for internal use only, you can't use the resulting pointer in Python code. An array object is a contiguous memory block, so you don't miss anything. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 00:02:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 05:02:25 GMT Subject: on "Namespaces" References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: On Sun, 08 Nov 2009 13:20:23 -0800, webtourist wrote: > New bie Question: > in "Zen of Python" - what exactly does the last one mean ? - Namespaces > are one honking great idea -- let's do more of those! > > I mean why the emphasis ? Is it like saying "put modules into packages" > in other programming paradigm s ? Modules are namespaces. So are packages. Classes and class instances are namespaces. Even function scopes are namespaces. When you write: n = None def spam(n): print "spam" * n def ham(n): print "ham" * n the n inside spam() and ham() and the global n are in different namespaces, and so independent. http://en.wikipedia.org/wiki/Namespace http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces -- Steven From gagsl-py2 at yahoo.com.ar Tue Nov 10 01:43:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 03:43:08 -0300 Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: En Tue, 10 Nov 2009 00:48:26 -0300, Phlip escribi?: > I have a single file that I need my crew to pip install. > > When I Google for "how to create a pip package" I don't hit anything. > Of course that info is out there; I can't seem to pick up the trail of > breadcrumbs to it. See http://pip.openplans.org/ You're looking for the "freeze" command. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 10 01:57:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 03:57:40 -0300 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> <6236e9a0-7662-4935-a65d-6cbcd61c6f92@o10g2000yqa.googlegroups.com> Message-ID: En Mon, 09 Nov 2009 12:59:53 -0300, Jon Clements escribi?: > On Nov 9, 1:53 pm, pinkisntwell wrote: >> How can I make a regular expression that will match every occurrence >> of a group and return each occurrence as a group match? For example, >> for a string "-c-c-c-c-c", how can I make a regex which will return a >> group match for each occurrence of "-c"? > > As well as what Diez has said, unless you absolutely want regexp's, > and by the sounds of it I'm guessing you may be after something more > flexible: what about the pyparsing module [1]. It handles your > situation quite nicely. > >>>> import pyparsing >>>> parser = pyparsing.ZeroOrMore('-c') >>>> parser.parseString('-c-c-c-c-c-c') > (['-c', '-c', '-c', '-c', '-c', '-c'], {}) Not that I like regexes very much, but findall does exactly that: py> re.findall('-c', '-c-c-c-c-c-c') ['-c', '-c', '-c', '-c', '-c', '-c'] Now, the OP said "return each occurrence as a group match": py> for g in re.finditer("-c", '-c-c-c-c-c-c'): print g, g.span(), g.group() ... <_sre.SRE_Match object at 0x00C096E8> (0, 2) -c <_sre.SRE_Match object at 0x00C09410> (2, 4) -c <_sre.SRE_Match object at 0x00C096E8> (4, 6) -c <_sre.SRE_Match object at 0x00C09410> (6, 8) -c <_sre.SRE_Match object at 0x00C096E8> (8, 10) -c <_sre.SRE_Match object at 0x00C09410> (10, 12) -c -- Gabriel Genellina From kochkin.dmitry at gmail.com Tue Nov 10 03:39:44 2009 From: kochkin.dmitry at gmail.com (Cooch) Date: Tue, 10 Nov 2009 00:39:44 -0800 (PST) Subject: Python as network protocol Message-ID: Hi, guys! I want to implement such specific feature: I have a server written in Python. I have a client written in C++. I want to use Python as network protocol between them. I mean: client send to server such string: "a = MyObject()", so object of this type will appear in server. Any ideas how to simplify this implementation? I make XML-RPC/SOAP server using twisted which just execute sended string. But I don't know how to: 1. Restrict usage of some modules on client side (os, sys etc..) 2. Divide variables of different clients. Generally, I know that I should use "exec .. in .. " construct, but don't know how to distinguish between clients in twisted. Dmitry. From deets at nospam.web.de Tue Nov 10 03:55:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Nov 2009 09:55:11 +0100 Subject: Python as network protocol In-Reply-To: References: Message-ID: <7lso3fF3fivalU1@mid.uni-berlin.de> Cooch schrieb: > Hi, guys! > > I want to implement such specific feature: > I have a server written in Python. I have a client written in C++. I > want to use Python as network protocol between them. I mean: client > send to server such string: "a = MyObject()", so object of this type > will appear in server. Any ideas how to simplify this implementation? > I make XML-RPC/SOAP server using twisted which just execute sended > string. But I don't know how to: > 1. Restrict usage of some modules on client side (os, sys etc..) > 2. Divide variables of different clients. Generally, I know that I > should use "exec .. in .. " construct, but don't know how to > distinguish between clients in twisted. This is a *really* bad idea. Because there is no real way to restrict execution in python, and thus you allow clients to inject arbitrary code into your server. Including the notorious "os.system('rm -rf /')". So - don't do that. Use e.g. CORBA if you need a richer, object-base protocol than XMLRPC. Diez From enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Nov 10 04:33:35 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 10 Nov 2009 10:33:35 +0100 Subject: how to close not response win32 IE com interface References: Message-ID: <4af93373$0$1001$ba4acef3@news.orange.fr> Hi! The only way I know is to use sendkeys. @+ Michel Claveau From wentland at cl.uni-heidelberg.de Tue Nov 10 04:54:39 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Tue, 10 Nov 2009 10:54:39 +0100 Subject: how to create a pip package In-Reply-To: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: <20091110095439.GF20601@kinakuta.local> On Mon, Nov 09, 2009 at 19:48 -0800, Phlip wrote: > I have a single file that I need my crew to pip install. Where do you plan to host this file? Will it be available on PiPy? > When I Google for "how to create a pip package" I don't hit anything. > Of course that info is out there; I can't seem to pick up the trail of > breadcrumbs to it. As has already been noted in this thread you do not create a file specifically for pip, but rather use the standard (or soon to be) way of distributing Python distributions outlined in: http://docs.python.org/library/distutils.html#module-distutils http://packages.python.org/distribute/ If you do not plan to host your "file" on pypi you can easily create a pip requirements file that references a VCS of your choice. Read how to do this in the pip documentation on "editable" packages: http://pypi.python.org/pypi/pip/ kind regards Wolodja -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From gatti at dsdata.it Tue Nov 10 05:40:52 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 10 Nov 2009 02:40:52 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On Nov 9, 9:01?pm, Simon Hibbs wrote: > The main objection to using PyQT untill now was that for commercial > development you needed to buy a license (it was free for GPL > projects). That's rapidly becoming a non-issue as the core QT > framework is now LGPL and Nokia have a project underway to produce > PyQT compatible LGPL python bindings under the PySide project. I also would like to use PySide, but unlike PyQt and Qt itself it doesn't seem likely to support Windows in the foreseeable future. A pity, to put it mildly. Regards, Lorenzo Gatti From highcar at gmail.com Tue Nov 10 06:00:41 2009 From: highcar at gmail.com (elca) Date: Tue, 10 Nov 2009 03:00:41 -0800 (PST) Subject: how to close not response win32 IE com interface In-Reply-To: <4af93373$0$1001$ba4acef3@news.orange.fr> References: <26265055.post@talk.nabble.com> <4af93373$0$1001$ba4acef3@news.orange.fr> Message-ID: <26281603.post@talk.nabble.com> Michel Claveau - MVP-2 wrote: > > Hi! > > The only way I know is to use sendkeys. > > @+ > > Michel Claveau > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, actually this is not hang status, i mean..it slow response, so in that case, i would like to close IE and want to restart from start. so closing is no problem ,problem is ,how to set timeout ,for example if i set 15sec, if not webpage open less than 15 sec i want to close it and restart from start. is this possible to use with IE com interface? really hard to find solution Paul, -- View this message in context: http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26281603.html Sent from the Python - python-list mailing list archive at Nabble.com. From Ognjen at mailshack.com Tue Nov 10 06:32:46 2009 From: Ognjen at mailshack.com (Ognjen Bezanov) Date: Tue, 10 Nov 2009 11:32:46 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? Message-ID: <4AF94F5E.8020806@mailshack.com> Hey, Thanks for all the responses guys. In hindsight I probably should have explained why on earth I'd need the physical address from an interpreted language. I'm trying to see if there is any way I can make Python share data between two hosts using DMA transfers over a firewire connection, so avoiding the need for another layer on top such as IPv4 + Python sockets. Thanks to some old python bindings which I updated to python 2.6, I can read any write to the RAM of any firewire connected host within python. Because it uses DMA (the cpu is not involved in this at all), I can only specify a physical address within the 4GB ram limit to read from and write to. Now what I've done so far is on the remote host I run python and set a variable as so: a = "foo" print a 'foo' Then on the local host I run a python script that scans the entire RAM looking for the string "foo", and replaces it with the string "oof". I have had success with this method. Once it's done and I do "print a" on the remote host, I get "oof" as the variable value, so in theory it can work. Problem is that it's slow. Scanning 3GB of RAM every time you want to do this is not a good method. I thought that if I could get python to return the physical address of where the value of a variable is, then I can just jump to that address and write the data. From what I've been told so far, it's not possible to do this without some OS-specific (Linux in this case) syscall. Is this correct? Thanks! Ognjen From mkhitrov at gmail.com Tue Nov 10 06:41:47 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 10 Nov 2009 06:41:47 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF94F5E.8020806@mailshack.com> References: <4AF94F5E.8020806@mailshack.com> Message-ID: <26ddd1750911100341g368f1e70mb70e491717d2cdd5@mail.gmail.com> On Tue, Nov 10, 2009 at 6:32 AM, Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an interpreted > language. > > I'm trying to see if there is any way I can make Python share data between > two hosts using DMA transfers over a firewire connection, so avoiding the > need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I can read > any write to the RAM of any firewire connected host within python. Because > it uses DMA (the cpu is not involved in this at all), I can only specify a > physical address within the 4GB ram limit to read from and write to. > > Now what I've done so far is on the remote host I run python and set a > variable as so: > > a = "foo" > print a > 'foo' > > Then on the local host I run a python script that scans the entire RAM > looking for the string "foo", and replaces it with the string "oof". I have > had success with this method. Once it's done and I do "print a" on the > remote host, I get "oof" as the variable value, so in theory it can work. > > Problem is that it's slow. Scanning 3GB of RAM every time you want to do > this is not a good method. I thought that if I could get python to return > the physical address of where the value of a variable is, then I can just > jump to that address and write the data. > > From what I've been told so far, it's not possible to do this without some > OS-specific (Linux in this case) syscall. Is this correct? > > Thanks! > > > Ognjen If all you need is a memory buffer, array.array provides a buffer_info() method that tells you the current (virtual) address. For DMA, I think there are dma_map_* functions in linux that you may be able to call through ctypes. - Max From luke.leighton at googlemail.com Tue Nov 10 07:48:03 2009 From: luke.leighton at googlemail.com (lkcl) Date: Tue, 10 Nov 2009 04:48:03 -0800 (PST) Subject: Newbie advice References: <69658d99-72de-4ad4-b4fe-315065f24dae@e34g2000vbc.googlegroups.com> Message-ID: On Oct 29, 7:00 am, alex23 wrote: > However, if you're already comfortable with HTML/CSS, I'd recommend > taking a look atPyjamas, which started as a port of the Google Web > Toolkit, taking Python code and compiling it into javascript. The > associated project,Pyjamas-Desktop, is a webkit-based desktop client/ > widget set; so ideally you only have to write one UI and it'll run > both on the web & the desktop. > > Pyjamas:http://pyjs.org/ > Pyjamas-Desktop:http://pyjd.sourceforge.net/ thank you for mentioning these, chris. the information on pyjd is slightly out-of-date. * pyjamas-desktop was merged into pyjamas as of the 0.6 release. * there are now three alternative back-ends for pyjamas-desktop, (just as there are three major web browser engines). MSHTML, xulrunner and webkit. Opera's engine cannot be included because Opera's developers have not responded to invitations to provide an engine / library to which python bindings can be added. when they have provided python bindings, a port of pyjd to use them can be done in approximately two weeks. * the webkit-based back-end is the least-recommended, due to intransigence of the webkit developer, mark rowe. mark rowe has shown consistent disrespect for free software contributions to make webkit with glib/ gobject bindings actually useful and useable, and has ensured that anyone who wishes to proceed with getting webkit its glib/gobject bindings will have an unacceptably hard time. efforts to work with the other webkit developers, which were proving successful, were deliberately destroyed by, and terminated by, mark rowe. * the MSHTML-based back-end is surprisingly the most successful of the three pyjd ports. it requires _very_ little in the way of libraries to be installed: only python-comtypes (at 250k) which is in complete contrast to the other ports, which require whopping 30mbyte installs of libraries and dependencies. * the xulrunner-based back-end is the best option for unix-based systems. the design of xulrunner's core infrastructure, XPCOM, however, is slightly ... "incomplete". it is based on DCOM, but does not provide the exact same capabilities as DCOM (no coclasses). the upshot is that current releases of xulrunner work perfectly well for _everything_ but 2D SVG Canvas "Image" loading. (i have a patch for xulrunner which fixes this one single error) so - it's a mixed and interesting bag of tricks. full and comprehensive non-javascript bindings to web technology seems to be a thoroughly misunderstood and underexploited area, with several variations on the same theme being available from several competitive sources. the nice thing about pyjamas is that just as pyjs makes all the differences "go away" when pyjamas apps are compiled to run in web browsers, pyjamas-desktop makes those differences "go away" when pyjamas apps are run as pure python on the desktop. l. From gerard.blais at gmail.com Tue Nov 10 07:57:04 2009 From: gerard.blais at gmail.com (Gerry) Date: Tue, 10 Nov 2009 04:57:04 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 2:42?pm, Ozz wrote: > vsoler schreef: > And, of course, you'd want to take a look a this: http://xkcd.com/287/ Gerry > > > Instead of subsets, do you mean permutations/combinations? ?Since 2 > > invoices can have the same amount perhaps the terms permutation is > > better. > > As some other poster already suggested 'powerset' (http://en.wikipedia.org/wiki/Power_set) may be a better name, except > for those duplicates, of course. On the other hand, I think viewing it > as a powerset is the most 'natural' in this case. (imo permutations are > about the order of objects, not about whether the objects are included > in a set or not) > > cheers, > Ozz From philip at semanchuk.com Tue Nov 10 08:34:31 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Nov 2009 08:34:31 -0500 Subject: comparing alternatives to py2exe In-Reply-To: References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: On Nov 9, 2009, at 9:16 PM, Gabriel Genellina wrote: > En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk > escribi?: >> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: >>> >>> Recently I put together this incomplete comparison chart in an >>> attempt >>> to choose between the different alternatives to py2exe: >>> >>> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html >> >> I was interested in py2exe because we'd like to provide a one >> download, one click install experience for our Windows users. I >> think a lot of people are interested in py2exe for the same reason. >> Well, one thing that I came across in my travels was the fact that >> distutils can create MSIs. Like py2exe, MSIs provide a one >> download, one click install experience under Windows and therefore >> might be a replacement for py2exe. > > But py2exe and .msi are complementary, not a replacement. > py2exe collects in one directory (or even in one file in some cases) > all the pieces necesary to run your application. That is, Python > itself + your application code + all referenced libraries + other > required pieces. > The resulting files must be installed in the client machine; you > either build a .msi file (a database for the Microsoft Installer) or > use any other installer (like InnoSetup, the one I like). > >> For me, the following command was sufficient to create an msi, >> although it only worked under Windows (not under Linux or OS X): >> python setup.py bdist_msi >> >> The resulting MSI worked just fine in my extensive testing (read: I >> tried it on one machine). > > The resulting .msi file requires Python already installed on the > target machine, if I'm not mistaken. The whole point of py2exe is to > avoid requiring a previous Python install. You're right; the MSI I created doesn't include prerequisites. It packaged up our app, that's it. To be fair to MSIs, they might be capable of including prerequisites, the app, and the kitchen sink. But I don't think Python's creation process through distutils makes that possible. That's why I suggested MSIs belong alongside RPM/DEB in the chart (if they're to be included at all). I wouldn't say that the whole point of py2exe is to bundle Python. That's certainly a big benefit, but another benefit is that it can bundle an app into a one-click download. That's why we were interested in it. > >> It seems, then, that creating an MSI is even within the reach of >> someone like me who spends very little time in Windows-land, so it >> might be worth a column on your chart alongside rpm/deb. > > As said in http://wiki.python.org/moin/DistributionUtilities the > easiest way is to use py2exe + InnoSetup. Easiest for you. =) The list of packages and modules that might require special treatment is almost a perfect superset of the modules we're using in our application: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules py2exe looks great, but it remains to be seen if it's the easiest way to solve our problem. The MSI isn't nearly as nice for the end user, but we created it using only the Python standard library and our existing setup.py. Simplicity has value. Cheers Philip From x7-g5W_rt at earthlink.net Tue Nov 10 08:49:03 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Tue, 10 Nov 2009 05:49:03 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: <7a9c4398-c5e7-40fe-9334-fdeffe12f9a4@l13g2000yqb.googlegroups.com> On Nov 9, 10:56?pm, "Gabriel Genellina" wrote: > > [much cutting] > > def method3a(): > ? ?newArray = array.array('I', [INITIAL_VALUE]) * SIZE > ? ?assert len(newArray)==SIZE > ? ?assert newArray[SIZE-1]==INITIAL_VALUE > > [more cutting] > > So arrays are faster than lists, and in both cases one_item*N outperforms ? > your doubling algorithm. > Adding one item at a time is -at least- several hundred times slower; I ? > was not patient enough to wait. > > > Finally, I just looked into calling C functions, and found > > PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management > > section of the Python/C API Reference Manual. This gives you > > uninitialized memory, and should be really fast, but it's 6:45 AM > > here, and I don't have the energy to try it. > > No, those are for internal use only, you can't use the resulting pointer ? > in Python code. An array object is a contiguous memory block, so you don't ? > miss anything. > Gabriel, Thanks for the reply - your method 3a was what I wanted, I missed "array.array('I', [INITIAL_VALUE]) * SIZ" on my earlier pass through the Python documentation. I included the 'one at a time' method because that was my first shot at the problem - I was so happy to find a method that would get the job done today that I didn't look farther than the doubling method. Yes, I know that I was comparing lists and arrays. Part of the confusion in this thread is that the problem hasn't been defined very well. The original post asked about arrays but the solution proposed generated a list. At this point, I have learned a lot about arrays, lists and dictionaries, and will be better able to chose the right solution to future problems. It's too bad about the C functions, they sure sounded good. And with that, I think I will withdraw from the field, and go write some code and learn about timeit. Gil From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 08:59:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 13:59:56 GMT Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <0309600d$0$1340$c3e8da3@news.astraweb.com> On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > What you're describing is the powerset operation. Here's the example > from the python docs: [...] > What I find interesting is that running it through timeit, it is much > slower than the code suggested by Dan Bishop. Your test doesn't show what you think it shows. You shouldn't just blindly apply timeit without testing to see that the functions return what you think they return. Your test is, I'm afraid, totally bogus and the conclusion you draw is completely wrong. [...] > #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate > timeit.timeit("subsets2(x)", setup) > timeit.timeit("subsets3(x)", setup) For the sake of speed, I've used a smaller x. Here are the results of calling the three functions: >>> x = range(3) >>> subsets1(x) [[2], [2, 0], [2, 1], [2, 1, 0], [], [0], [1], [1, 0]] >>> subsets2(x) >>> subsets3(x) The reason subsets1() "doesn't appear to terminate" is that you are trying to list all the subsets of x = range(100). That's a LOT of subsets: 2**100 to be precise, or approximately 1.2e30. subsets2() and subsets3() return a generator function and an iterator object respectively. There may be some overhead difference between those, but that's trivial compared to the cost of generating the subsets themselves. A better way of doing the timing is as follows: from itertools import chain, combinations from timeit import Timer # use a number small enough to calculate in a reasonable time x = list(range(10)) def subsets1(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets1(L[1:]): S.append(s) S.append(s + [ L[0]]) return S def subsets2(L): if L: for s in subsets2(L[1:]): yield s yield s + [L[0]] else: yield [] def subsets3(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) setup = "from __main__ import subsets1, subsets2, subsets3, x" # Check the three functions return the same results: x1 = sorted(subsets1(x)) x2 = sorted(subsets2(x)) x3 = sorted(list(t) for t in subsets1(x)) assert x1 == x2 == x3 # Set up some timers. t1 = Timer("subsets1(x)", setup) t2 = Timer("list(subsets2(x))", setup) t3 = Timer("list(subsets3(x))", setup) # And run them! for t in (t1, t2, t3): print min(t.repeat(number=1000, repeat=5)) The results I get are: 1.19647693634 0.901714801788 0.175387859344 Which as you can see, shows that the recipe in the docs is nearly ten times faster than Dan's version. That's not surprising -- the docs version uses highly optimized C code from itertools, while Dan's version uses slow-ish Python code and recursion. To show this is no fluke, I increased the size of x and ran the tests again: >>> x = list(range(15)) # 32000+ subsets >>> x1 = sorted(subsets1(x)) >>> x2 = sorted(subsets2(x)) >>> x3 = sorted(list(t) for t in subsets1(x)) >>> assert x1 == x2 == x3 >>> >>> t1 = Timer("subsets1(x)", setup) >>> t2 = Timer("list(subsets2(x))", setup) >>> t3 = Timer("list(subsets3(x))", setup) >>> for t in (t1, t2, t3): ... print min(t.repeat(number=1000, repeat=5)) ... 45.283468008 33.9274909496 7.40781188011 -- Steven From debatem1 at gmail.com Tue Nov 10 09:24:56 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 09:24:56 -0500 Subject: My own accounting python euler problem In-Reply-To: <0309600d$0$1340$c3e8da3@news.astraweb.com> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <0309600d$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 8:59 AM, Steven D'Aprano wrote: > On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > >> What you're describing is the powerset operation. Here's the example >> from the python docs: > [...] >> What I find interesting is that running it through timeit, it is much >> slower than the code suggested by Dan Bishop. > > Your test doesn't show what you think it shows. You shouldn't just > blindly apply timeit without testing to see that the functions return > what you think they return. Your test is, I'm afraid, totally bogus and > the conclusion you draw is completely wrong. Doh! I even noticed that the asymptotic times didn't match up and still blew right past the obvious answer. Thanks (again) for the correction, Steven. Geremy Condra From phlip2005 at gmail.com Tue Nov 10 09:30:53 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 06:30:53 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> On Nov 10, 1:54?am, Wolodja Wentland wrote: > http://docs.python.org/library/distutils.html#module-distutils > http://packages.python.org/distribute/ ktx... now some utterly retarded questions to prevent false starts. the distutils page starts with "from distutils.core import setup". but a sample project on github, presumably a pippable project, starts with: from setuptools import setup, find_packages (and it also has ez_setup()) I don't foresee my project growing larger than one* file any time soon. 'pip freeze' prob'ly won't write a setup.py. What is the absolute simplest setup.py to stick my project on the PYTHONPATH, and be done with it? [*but rest assured it has a developer test suite and a customer test script!] -- Phlip http://c2.com/cgi/wiki?ZeekLand From victorsubervi at gmail.com Tue Nov 10 09:37:57 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 09:37:57 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4AF8CC05.8090902@ieee.org> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> <4AF8CC05.8090902@ieee.org> Message-ID: <4dc0cfea0911100637m4712c7canebae37e6cead7698@mail.gmail.com> For others who discover this error, here's what happened as I've traced it: 1) I never before had built a python interpreter on my Windoze box. That was kind of silly, since I was uploading to my server every time I wanted to test. So I built on my Windoze box. Thereafter, Windoze assumed that all *.py files were native to its environment. That's where the little devil crept in. 2) When I went to edit my files on the server, I never saw any lines ending in "^M", the dead giveaway that Windoze has mangled the line endings. So the problem was __invisible__. Wow. What a pain in the &(%( Thanks for everyone's help! V On Mon, Nov 9, 2009 at 9:12 PM, Dave Angel wrote: > Victor Subervi wrote: > >> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi > >wrote: >> >> >> >>> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury >> >wrote: >>> >>> >>> >>>> >>>> >>> >>> >>> Hold everything. Apparently line-endings got mangled. What I don't >>> >>> >> understand is why I didn't see them when I opened the file to edit, and >> why >> they didn't copy and paste when I did that. But dos2unix cleaned up a >> couple >> of files so I presume it will clean up the rest. However, I tried one >> file, >> that reads exactly the same as index.py, and when I surfed to it got a 500 >> error. Here's what the log said: >> >> >> >> > What I've diagnosed as happening when a python script with Windows > line-ending was posted on my server's cgi environment: > > The actual error seemed to be a failure to find the python interpreter, > since some Unix shells take the shebang line to include the \r character > that preceded the newline. Seems to me they could be more tolerant, since > I don't think control characters are likely in the interpreter file name. > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reply-to at works.fine.invalid Tue Nov 10 09:59:25 2009 From: reply-to at works.fine.invalid (NickC) Date: 10 Nov 2009 14:59:25 GMT Subject: Create object from variable indirect reference? Message-ID: <00830413$0$26937$c3e8da3@news.astraweb.com> I can't seem to find a way to do something that seems straighforward, so I must have a mental block. I want to reference an object indirectly through a variable's value. Using a library that returns all sorts of information about "something", I want to provide the name of the "something" via a variable (command line argument). The something is a class in the library and I want to instantiate an object of the class so I can start querying it. I can't figure out how to pass the name of the class to the library. Or, put another way, I can't figure out how to indirectly reference the value of the command line argument to create the object. To make it clearer, it's roughly equivalent to this in bash: Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". command line: $ ./ephemeris.py Moon code: import ephem import optparse # various option parsing (left out for brevity), # so variable options.body contains string "Moon", # or even "Moon()" if that would make it easier. # Want to instantiate an object of class Moon. # Direct way: moon1 = ephem.Moon() # Indirect way from command line with a quasi bashism that obviously fails: moon2 = ephem.${!options.body}() Can someone point me in the right direction here? (The library is PyEphem, an extraordinarily useful library for anyone interested in astronomy.) Many thanks, -- NickC From Scott.Daniels at Acm.Org Tue Nov 10 10:08:03 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Nov 2009 07:08:03 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> Message-ID: Dave Angel wrote: > Victor Subervi wrote: >> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi >> wrote: >>> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury >>> wrote: >>> >>> >>> Hold everything. Apparently line-endings got mangled. What I don't ... >> > What I've diagnosed as happening when a python script with Windows > line-ending was posted on my server's cgi environment: > > The actual error seemed to be a failure to find the python interpreter, > since some Unix shells take the shebang line to include the \r character > that preceded the newline. Seems to me they could be more tolerant, > since I don't think control characters are likely in the interpreter > file name. You could work around this by creating a symlink (or even hard link to the python executable named "python\r" --Scott David Daniels Scott.Daniels at Acm.Org From joncle at googlemail.com Tue Nov 10 10:08:47 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 10 Nov 2009 07:08:47 -0800 (PST) Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> On Nov 10, 2:59?pm, NickC wrote: > I can't seem to find a way to do something that seems straighforward, so I > must have a mental block. ?I want to reference an object indirectly > through a variable's value. > > Using a library that returns all sorts of information about "something", I > want to provide the name of the "something" via a variable (command line > argument). ?The something is a class in the library and I want to > instantiate an object of the class so I can start querying it. ?I can't > figure out how to pass the name of the class to the library. > > Or, put another way, I can't figure out how to indirectly reference the > value of the command line argument to create the object. > > To make it clearer, it's roughly equivalent to this in bash: > ?Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". > > command line: > $ ./ephemeris.py Moon > > code: > import ephem > import optparse > > # various option parsing (left out for brevity), > # so variable options.body contains string "Moon", > # or even "Moon()" if that would make it easier. > > # Want to instantiate an object of class Moon. > # Direct way: > moon1 = ephem.Moon() > # Indirect way from command line with a quasi bashism that obviously fails: > moon2 = ephem.${!options.body}() > > Can someone point me in the right direction here? > > (The library is PyEphem, an extraordinarily useful library for anyone > interested in astronomy.) > > Many thanks, > > -- > NickC A direct way is to use: moon1 = getattr(ephem, 'Moon')() hth Jon. From rami.chowdhury at gmail.com Tue Nov 10 10:13:54 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 10 Nov 2009 07:13:54 -0800 Subject: Create object from variable indirect reference? In-Reply-To: <00830413$0$26937$c3e8da3@news.astraweb.com> References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Nov 2009 06:59:25 -0800, NickC wrote: > I can't seem to find a way to do something that seems straighforward, so > I > must have a mental block. I want to reference an object indirectly > through a variable's value. > > Using a library that returns all sorts of information about "something", > I > want to provide the name of the "something" via a variable (command line > argument). The something is a class in the library and I want to > instantiate an object of the class so I can start querying it. I can't > figure out how to pass the name of the class to the library. > > Or, put another way, I can't figure out how to indirectly reference the > value of the command line argument to create the object. > > To make it clearer, it's roughly equivalent to this in bash: > Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". > > command line: > $ ./ephemeris.py Moon > > code: > import ephem > import optparse > > # various option parsing (left out for brevity), > # so variable options.body contains string "Moon", > # or even "Moon()" if that would make it easier. > > # Want to instantiate an object of class Moon. > # Direct way: > moon1 = ephem.Moon() > # Indirect way from command line with a quasi bashism that obviously > fails: > moon2 = ephem.${!options.body}() > > Can someone point me in the right direction here? > > (The library is PyEphem, an extraordinarily useful library for anyone > interested in astronomy.) > > Many thanks, > Since Python 'variables' are really keys in a namespace dictionary, it's fairly straightforward to get at them given a string value -- what you probably want in this case is the built-in function getattr() (http://www.diveintopython.org/power_of_introspection/getattr.html)... So getattr(ephem, "Moon") should give you the class object ephem.Moon, which you can then instantiate... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From wentland at cl.uni-heidelberg.de Tue Nov 10 10:14:18 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Tue, 10 Nov 2009 16:14:18 +0100 Subject: how to create a pip package In-Reply-To: <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <20091110151418.GH20601@kinakuta.local> On Tue, Nov 10, 2009 at 06:30 -0800, Phlip wrote: > On Nov 10, 1:54?am, Wolodja Wentland > wrote: > > > http://docs.python.org/library/distutils.html#module-distutils > > http://packages.python.org/distribute/ > > ktx... now some utterly retarded questions to prevent false starts. > the distutils page starts with "from distutils.core import setup". [..] > from setuptools import setup, find_packages It will be enough to use the method outlined in the distutils documentation. Setuptools is a third-party library that used to be the de-facto standard for Python packaging. I don't want to go into detail why setuptools might not be the best choice for a project and leave that to [1] and [2]. The Distribute project was started in order to fix several bugs in setuptools which was essentially unmaintained for a year and provides a backward compatible fork in the 0.6 branch. kind regards Wolodja [1] http://www.b-list.org/weblog/2008/dec/14/packaging/ [2] http://blog.ianbicking.org/2008/12/14/a-few-corrections-to-on-packaging/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From fetchinson at googlemail.com Tue Nov 10 10:31:13 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 16:31:13 +0100 Subject: Python as network protocol In-Reply-To: <7lso3fF3fivalU1@mid.uni-berlin.de> References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: >> I want to implement such specific feature: >> I have a server written in Python. I have a client written in C++. I >> want to use Python as network protocol between them. I mean: client >> send to server such string: "a = MyObject()", so object of this type >> will appear in server. Any ideas how to simplify this implementation? >> I make XML-RPC/SOAP server using twisted which just execute sended >> string. But I don't know how to: >> 1. Restrict usage of some modules on client side (os, sys etc..) >> 2. Divide variables of different clients. Generally, I know that I >> should use "exec .. in .. " construct, but don't know how to >> distinguish between clients in twisted. Have you considered using pyro? http://pyro.sourceforge.net/ > This is a *really* bad idea. How do you know for sure? Maybe the OP wants to use this thing with 3 known researchers working on a cluster that is not even visible to the outside world. In such a setup the model the OP suggested is a perfectly reasonable one. I say this because I often work in such an environment and security is never an issue for us. And I find it always amusing that whenever I outline our code to a non-scientist programmer they always run away in shock and never talk to us again :) Nevertheless our code works perfectly for our purposes. > Because there is no real way to restrict > execution in python, and thus you allow clients to inject arbitrary code > into your server. Including the notorious "os.system('rm -rf /')". > > So - don't do that. Use e.g. CORBA if you need a richer, object-base > protocol than XMLRPC. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From SD_V897 at NoSuchMail.Com Tue Nov 10 10:39:46 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Tue, 10 Nov 2009 15:39:46 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: <6PfKm.51354$Db2.3028@edtnps83> Rhodri James wrote: > On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 wrote: > >> Rhodri James wrote: >>> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >>> wrote: >>> >>>> I have a perplexing issue, I have four users set up on a W7 >>>> computer. The program runs fine for all users except the admin user >>>> who needs it for school assignments. >>> A little more information, please. How does it not work for the admin >>> user? Is there a traceback? What do you get if you try to invoke it >>> from a command line? >>> >> >> >> Hi Rhodri, here's a dump file, don't know if this helps or not.. > > So Windows is reporting a crash, then. I'll repeat my last question in > particular; what happens when your admin user runs the program you're > trying to invoke from the command line? > Hi Rhodri, Python Command-Line works fine. Are toy recommending to invoke IDLE from there or from windows command line? Sorry I'm not to up on Python is there a command that would run IDLE from command? If I run idle.py -c -d I get idle is not defined. Thanks SD From invalid at invalid.invalid Tue Nov 10 10:46:10 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 15:46:10 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, Rhodri James wrote: > On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy wrote: > >> I believe the use of tagged pointers has been considered and so far >> rejected by the CPython developers. And no one else that I know of has >> developed a fork for that. It would seem more feasible with 64 bit >> pointers where there seem to be spare bits. But CPython will have to >> support 32 bit machines for several years. > > I've seen that mistake made twice (IBM 370 architecture (probably 360 too, > I'm too young to have used it) and ARM2/ARM3). I'd rather not see it a > third time, thank you. MacOS applications made the same mistake on the 68K. They reserved the high-end bits in a 32-bit pointer and used them to contain meta-information. After all, those bits were "extra" -- nobody could ever hope to actually address more than 4MB of memory, right? Heck, those address lines weren't even brought out of the CPU package. Guess what happened? It wasn't the decades-long global debacle that was the MS-DOS memory model, but it did cause problems when CPUs came out that implemented those address lines and RAM became cheap enough that people needed to use them. -- Grant Edwards grante Yow! Either CONFESS now or at we go to "PEOPLE'S COURT"!! visi.com From hniksic at xemacs.org Tue Nov 10 10:46:34 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 10 Nov 2009 16:46:34 +0100 Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: <87vdhil6w5.fsf@busola.homelinux.net> NickC writes: > moon2 = ephem.${!options.body}() moon2 = getattr(ephem, options.body)() From martin at marcher.name Tue Nov 10 10:46:45 2009 From: martin at marcher.name (Martin) Date: Tue, 10 Nov 2009 16:46:45 +0100 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> On Tue, Nov 10, 2009 at 16:31, Daniel Fetchinson wrote: >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a > perfectly reasonable one. I say this because I often work in such an > environment and security is never an issue for us. And I find it > always amusing that whenever I outline our code to a non-scientist > programmer they always run away in shock and never talk to us again :) > Nevertheless our code works perfectly for our purposes. It is a bad idea because that's exactly why we now have a spam problem. It _was_ a trusted environment once upon a time. Just check your spam messages to see why ignoring security can lead to really bad results. Do you know for sure that in say 3-5 years from now on your software isn't released into the wild and then has no security at all? regards, Martin -- 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 marco at sferacarta.com Tue Nov 10 10:56:06 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 10 Nov 2009 16:56:06 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: Grant Edwards wrote: > MacOS applications made the same mistake on the 68K. And and awful lot of the Amiga software, with the same 24/32 bit CPU. I did it too, every pointer came with 8 free bits so why not use them? > It wasn't the decades-long global debacle that was the MS-DOS > memory model, but it did cause problems when CPUs came out that > implemented those address lines and RAM became cheap enough > that people needed to use them. I suppose that's the reason many games didn't work on the 68020+ From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 10:56:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 15:56:56 GMT Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <03097b78$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using exec: >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a perfectly > reasonable one. I say this because I often work in such an environment > and security is never an issue for us. And I find it always amusing that > whenever I outline our code to a non-scientist programmer they always > run away in shock and never talk to us again You might be a great scientist, but perhaps you should pay attention to the experts on programming who tell you that this is opening a potential security hole in your system. No, it's not a "perfectly reasonable" tactic. It's a risky tactic that only works because the environment you use it in is so limited and the users so trusted. Can you guarantee that will never change? If not, then you should rethink your tactic of using exec. Besides, as a general rule, exec is around an order of magnitude slower than running code directly. If performance matters at all, you are better off to try to find an alternative to exec. > Nevertheless our code works perfectly for our purposes. Until the day that some manager decides that it would be great to make your code into a service available over the Internet, or until one of the other scientists decides that he really needs to access it from home, or somebody pastes the wrong text into the application and it blows up in your face... it's not just malice you need to be careful of, but also accidents. The history of computing is full of systems that were designed with no security because it wasn't needed, until it was needed, but it was too late by then. There's no need, or at least very little need, to put locks on the internal doors of your house, because we're not in the habit of taking internal doors and turning them into outside doors. But code designed to run inside your secure, safe network has a tendency to be re-purposed to run in insecure, unsafe networks, usually by people who have forgotten, or never knew, that they were opening up their system to code injection attacks. -- Steven From reply-to at works.fine.invalid Tue Nov 10 11:03:17 2009 From: reply-to at works.fine.invalid (NickC) Date: 10 Nov 2009 16:03:17 GMT Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> Message-ID: <0083130b$0$26937$c3e8da3@news.astraweb.com> Many thanks for the replies. getattr() works great: >>> name='Moon' >>> m2 = getattr(ephem,name)() >>> m2.compute(home) >>> print ephem.localtime(m2.rise_time) 2009-11-11 01:30:36.000002 shows the moon will rise at 1:30am localtime tonight at my home location. Excellent. -- NickC From floris.bruynooghe at gmail.com Tue Nov 10 11:06:33 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Tue, 10 Nov 2009 08:06:33 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <02718583-8643-4983-a312-373a5fe3a480@j4g2000yqe.googlegroups.com> On Nov 10, 2:30?pm, Phlip wrote: > On Nov 10, 1:54?am, Wolodja Wentland > wrote: > > >http://docs.python.org/library/distutils.html#module-distutils > >http://packages.python.org/distribute/ > > ktx... now some utterly retarded questions to prevent false starts. > > the distutils page starts with "from distutils.core import setup". > > but a sample project on github, presumably a pippable project, starts > with: > > ? ? from setuptools import setup, find_packages > > (and it also has ez_setup()) > > I don't foresee my project growing larger than one* file any time > soon. 'pip freeze' prob'ly won't write a setup.py. What is the > absolute simplest setup.py to stick my project on the PYTHONPATH, and > be done with it? Do what the distutils page says, setuptools tries to extend distutils with many fancy things but if you don't need those (and that's what it sounds like) then sticking to distutils is better as you only require the python stdlib. Regards Floris From python at mrabarnett.plus.com Tue Nov 10 11:08:13 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 16:08:13 +0000 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: <4AF98FED.5080500@mrabarnett.plus.com> Gerry wrote: > On Nov 8, 2:42 pm, Ozz wrote: >> vsoler schreef: >> > And, of course, you'd want to take a look a this: http://xkcd.com/287/ > I've found 2 solutions. (And I really should get back to what I was doing...) > Gerry >>> Instead of subsets, do you mean permutations/combinations? Since 2 >>> invoices can have the same amount perhaps the terms permutation is >>> better. >> As some other poster already suggested 'powerset' (http://en.wikipedia.org/wiki/Power_set) may be a better name, except >> for those duplicates, of course. On the other hand, I think viewing it >> as a powerset is the most 'natural' in this case. (imo permutations are >> about the order of objects, not about whether the objects are included >> in a set or not) >> >> cheers, >> Ozz > From mwilson at the-wire.com Tue Nov 10 11:14:24 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 10 Nov 2009 11:14:24 -0500 Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: Gerry wrote: > On Nov 8, 2:42 pm, Ozz wrote: >> vsoler schreef: >> > And, of course, you'd want to take a look a this: http://xkcd.com/287/ :) I remember that. mwilson at tecumseth:~/sandbox$ python xkcd_complete.py [1, 0, 0, 2, 0, 1] 1505 [7] 1505 Mel. From ckaynor at zindagigames.com Tue Nov 10 11:32:55 2009 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 10 Nov 2009 08:32:55 -0800 Subject: is None or == None ? In-Reply-To: References: <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Tue, Nov 10, 2009 at 7:56 AM, Marco Mariani wrote: > Grant Edwards wrote: > > MacOS applications made the same mistake on the 68K. >> > > And and awful lot of the Amiga software, with the same 24/32 bit CPU. > > I did it too, every pointer came with 8 free bits so why not use them? > > > > It wasn't the decades-long global debacle that was the MS-DOS >> memory model, but it did cause problems when CPUs came out that >> implemented those address lines and RAM became cheap enough >> that people needed to use them. >> > > I suppose that's the reason many games didn't work on the 68020+ > > > -- > http://mail.python.org/mailman/listinfo/python-list > As a note, the official specification (Ihttp:// www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf), the 64-bit pointers are required to be in canonical form for the exact reason of helping prevent these mistakes from being repeated. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Nov 10 11:46:38 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 16:46:38 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, Marco Mariani wrote: > Grant Edwards wrote: > >> MacOS applications made the same mistake on the 68K. > And and awful lot of the Amiga software, with the same 24/32 > bit CPU. > > I did it too, every pointer came with 8 free bits so why not > use them? TANSTAFB ;) I should probably add that MacOS itself used the same trick until system 7. >> It wasn't the decades-long global debacle that was the MS-DOS >> memory model, but it did cause problems when CPUs came out that >> implemented those address lines and RAM became cheap enough >> that people needed to use them. > > I suppose that's the reason many games didn't work on the 68020+ Probably. IIRC, it took a while for some vendors to come out with "32-bit clean" versions of products. http://en.wikipedia.org/wiki/Mac_OS_memory_management#32-bit_clean -- Grant Edwards grante Yow! I know how to do at SPECIAL EFFECTS!! visi.com From invalid at invalid.invalid Tue Nov 10 11:50:43 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 16:50:43 +0000 (UTC) Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-10, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using > exec: > >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing >> with 3 known researchers working on a cluster that is not even >> visible to the outside world. And those three researchers are perfect? They've never even made a typographical error? >> In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an >> environment and security is never an issue for us. And I find >> it always amusing that whenever I outline our code to a >> non-scientist programmer they always run away in shock and >> never talk to us again > > You might be a great scientist, but perhaps you should pay > attention to the experts on programming who tell you that this > is opening a potential security hole in your system. > > No, it's not a "perfectly reasonable" tactic. It's a risky > tactic that only works because the environment you use it in > is so limited and the users so trusted. Even then it only works until a trusted user makes a mistake and types the wrong thing. A stupid mistake can do just as much damage as an evil mastermind. -- Grant Edwards grante Yow! Is this an out-take at from the "BRADY BUNCH"? visi.com From phlip2005 at gmail.com Tue Nov 10 12:14:47 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 09:14:47 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: > > ? ? from setuptools import setup, find_packages > > It will be enough to use the method outlined in the distutils > documentation. Setuptools is a third-party library that used to be the > de-facto standard for Python packaging. I don't want to go into detail > why setuptools might not be the best choice for a project... Good - thanks, all! Those were the exact details I sought to avoid... From python-url at phaseit.net Tue Nov 10 12:19:53 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 10 Nov 2009 17:19:53 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 10) Message-ID: QOTW: "Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis." - Diez B. Roggisch, on ... well, personal style in problem-solving http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b Why aren't lists usable as dictionary keys? What do you mean, "hashable"? http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/ `x == None` or `x is None` -- which one is the right way? http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/ At Microsoft, they performed empirical research about common software engineering assumptions: "high test coverage is better", "write test code first", "use assertions", and others: http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/ The best way to populate a list of size N: http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/ A new variant of an old problem: I got a single check from my customer - which ones among all pending invoices did he intend to pay? http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/ How to test code that uses urllib without depending on external resources? http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/ Singletons are hard to test too: http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/ How to use Filters in the logging module: http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/ Delete items from a list that match a certain pattern: http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/ What is the correct way to port codecs.open to python 3.1? http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/ py2exe, cx_freeze, py2app: a comparison http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/ How to cancel a thread from another one: http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/ Why does "help(import)" not work? http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 deets at nospam.web.de Tue Nov 10 12:22:32 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Nov 2009 18:22:32 +0100 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <7ltlqpF3e7kvsU1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >>> I want to implement such specific feature: >>> I have a server written in Python. I have a client written in C++. I >>> want to use Python as network protocol between them. I mean: client >>> send to server such string: "a = MyObject()", so object of this type >>> will appear in server. Any ideas how to simplify this implementation? >>> I make XML-RPC/SOAP server using twisted which just execute sended >>> string. But I don't know how to: >>> 1. Restrict usage of some modules on client side (os, sys etc..) >>> 2. Divide variables of different clients. Generally, I know that I >>> should use "exec .. in .. " construct, but don't know how to >>> distinguish between clients in twisted. > > Have you considered using pyro? > > http://pyro.sourceforge.net/ Have you considered that C++ doesn't support Pyro? > >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a > perfectly reasonable one. I say this because I often work in such an > environment and security is never an issue for us. And I find it > always amusing that whenever I outline our code to a non-scientist > programmer they always run away in shock and never talk to us again :) > Nevertheless our code works perfectly for our purposes. If you read the OP message, he himself stated that he wants to lock down the interpreter. Which isn't possible. So (scientific) reasoning can tell us that his application might not run in a happy-go-lucky environment of scientific research. Additionally, there is always the option of mistakes being made involuntarily, so desigining a system that encourages these is a bad idea. And last but not least, instead of having a well-defined protocol relying on arbitrary in-process manipulation is a nightmare to maintain, and might well lead to nasty bugs, crashes or even subtler problems (think changing a global constant for all the others...) that are nearly impossible to debug. Plus the issues the others mentioned. Diez From debatem1 at gmail.com Tue Nov 10 12:28:49 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 12:28:49 -0500 Subject: Python as network protocol In-Reply-To: <03097b78$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 10:56 AM, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using > exec: > >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an environment >> and security is never an issue for us. And I find it always amusing that >> whenever I outline our code to a non-scientist programmer they always >> run away in shock and never talk to us again > > You might be a great scientist, but perhaps you should pay attention to > the experts on programming who tell you that this is opening a potential > security hole in your system. > > No, it's not a "perfectly reasonable" tactic. It's a risky tactic that > only works because the environment you use it in is so limited and the > users so trusted. Can you guarantee that will never change? If not, then > you should rethink your tactic of using exec. > > Besides, as a general rule, exec is around an order of magnitude slower > than running code directly. If performance matters at all, you are better > off to try to find an alternative to exec. > > >> Nevertheless our code works perfectly for our purposes. > > Until the day that some manager decides that it would be great to make > your code into a service available over the Internet, or until one of the > other scientists decides that he really needs to access it from home, or > somebody pastes the wrong text into the application and it blows up in > your face... it's not just malice you need to be careful of, but also > accidents. > > The history of computing is full of systems that were designed with no > security because it wasn't needed, until it was needed, but it was too > late by then. > > There's no need, or at least very little need, to put locks on the > internal doors of your house, because we're not in the habit of taking > internal doors and turning them into outside doors. But code designed to > run inside your secure, safe network has a tendency to be re-purposed to > run in insecure, unsafe networks, usually by people who have forgotten, > or never knew, that they were opening up their system to code injection > attacks. > > > > -- > Steven Steven, remember a few weeks ago when you tried to explain to me that the person who was storing windows administrative passwords using a 40 byte xor cipher with the hardcoded password might not be doing something stupid because I didn't know what their threat model was? Yeah- what you just said is what I was trying to explain then. Geremy Condra From syeberman at hotmail.com Tue Nov 10 12:44:55 2009 From: syeberman at hotmail.com (Syeberman) Date: Tue, 10 Nov 2009 09:44:55 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? References: Message-ID: <34954068-e546-4a42-9521-c0b0417f56c5@b2g2000yqi.googlegroups.com> On Nov 8, 3:42?pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. > The short answer isn't entirely correct, however. Tuples are only hashable so long as their elements are all hashable. The documentation, though, doesn't properly describe this: http://docs.python.org/glossary.html#term-hashable "All of Python?s immutable built-in objects are hashable" From victorsubervi at gmail.com Tue Nov 10 12:53:03 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 12:53:03 -0500 Subject: Calendar Stuff Message-ID: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Hi; I have the following code: import calendar, datetime def cal(): ... myCal = calendar.Calendar(calendar.SUNDAY) today = datetime.date.today() day = today.day mo = today.month yr = today.year # month = myCal.monthdayscalendar(int(time.strftime("%Y")) month = myCal.monthdayscalendar(yr, mo) print 'hi' html headers are included. No matter which one of the last two lines I comment out, I never get to the point of printing 'hi'. (If I comment them both out, it does print.) What do? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Nov 10 13:47:41 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 19:47:41 +0100 Subject: Python as network protocol In-Reply-To: <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> Message-ID: >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a >> perfectly reasonable one. I say this because I often work in such an >> environment and security is never an issue for us. And I find it >> always amusing that whenever I outline our code to a non-scientist >> programmer they always run away in shock and never talk to us again :) >> Nevertheless our code works perfectly for our purposes. > > It is a bad idea because that's exactly why we now have a spam > problem. It _was_ a trusted environment once upon a time. Just check > your spam messages to see why ignoring security can lead to really bad > results. > > Do you know for sure that in say 3-5 years from now on your software > isn't released into the wild and then has no security at all? In my case, yes, I know for sure that the software I was talking about will only be used by my colleagues (3-4 people) and will only be used on our system. Why? Because the code is completely unportable and undocumented and was made to serve one purpose alone: to just work on our clusters which are not visible from the internet. And it serves this purpose great. In case we need to share this code, release it, modify it, etc, etc, we will think about all the security issues. But not until then. The point I'm trying to make is that of course I'm aware of the risks in our approach, the environment we are working in allows for these risks. In another situation I wouldn't use this type of approach. As a programmer I decide what solution to use in which environment and I intend to not over kill. No risk environment = security holes are okay. Risky environment = secure code from day one. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From zac256 at gmail.com Tue Nov 10 13:50:33 2009 From: zac256 at gmail.com (Zac Burns) Date: Tue, 10 Nov 2009 10:50:33 -0800 Subject: Threaded import hang in cPickle.dumps Message-ID: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Using python 2.6 cPickle.dumps has an import which is causing my application to hang. (figured out by overriding builtin.__import__ with a print and seeing that this is the last line of code being run. I'm running cPickle.dumps in a thread, which leads me to believe that the first restriction here is the cause: http://docs.python.org/library/threading.html#importing-in-threaded-code What can I do about this? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From zac256 at gmail.com Tue Nov 10 13:55:25 2009 From: zac256 at gmail.com (Zac Burns) Date: Tue, 10 Nov 2009 10:55:25 -0800 Subject: Threaded import hang in cPickle.dumps In-Reply-To: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <333edbe80911101055u271c1f94nea4ef4160b8f57ef@mail.gmail.com> Oh, I'm pickling an NotImplementedError and it's importing exceptions. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Nov 10, 2009 at 10:50 AM, Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running > cPickle.dumps in a thread, which leads me to believe that the first > restriction here is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 13:55:25 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 18:55:25 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <0309a54d$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 15:46:10 +0000, Grant Edwards wrote: > On 2009-11-10, Rhodri James wrote: >> On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy >> wrote: >> >>> I believe the use of tagged pointers has been considered and so far >>> rejected by the CPython developers. And no one else that I know of has >>> developed a fork for that. It would seem more feasible with 64 bit >>> pointers where there seem to be spare bits. But CPython will have to >>> support 32 bit machines for several years. >> >> I've seen that mistake made twice (IBM 370 architecture (probably 360 >> too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see >> it a third time, thank you. > > MacOS applications made the same mistake on the 68K. They reserved the > high-end bits in a 32-bit pointer and used them to contain > meta-information. Obviously that was their mistake. They should have used the low-end bits for the metadata, instead of the more valuable high-end. High-end-is-always-better-right?-ly y'rs, -- Steven From fetchinson at googlemail.com Tue Nov 10 13:58:31 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 19:58:31 +0100 Subject: Python as network protocol In-Reply-To: <03097b78$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an environment >> and security is never an issue for us. And I find it always amusing that >> whenever I outline our code to a non-scientist programmer they always >> run away in shock and never talk to us again > > You might be a great scientist, but perhaps you should pay attention to > the experts on programming who tell you that this is opening a potential > security hole in your system. Well, I'm completely aware of the potential security threats. It's not something I'm overlooking, rather, I'm taking them into account according to their real importance in our specific environment. And by the way, I'm not a great scientist :) However if the environment is such that the potential risks can not be exploited (not even in theory), because exactly 3 people have access to a machine and all of them are trustworthy and the clusters on which the code runs is not accessible from the internet, well, then the 'security hole' which would be dangerous otherwise, is risk free in this case. > No, it's not a "perfectly reasonable" tactic. I believe it is. > It's a risky tactic that > only works because the environment you use it in is so limited and the > users so trusted. Exactly! > Can you guarantee that will never change? Yes. I will simply not release the code to anyone. > If not, then you should rethink your tactic of using exec. I agree. > Besides, as a general rule, exec is around an order of magnitude slower > than running code directly. If performance matters at all, you are better > off to try to find an alternative to exec. That is a good point, thanks. If we'll have performance issues, I'll remember this. >> Nevertheless our code works perfectly for our purposes. > > Until the day that some manager decides that it would be great to make > your code into a service available over the Internet, or until one of the > other scientists decides that he really needs to access it from home, or > somebody pastes the wrong text into the application and it blows up in > your face I agree. If any of those things would occur, our software would be pretty dangerous. > ... it's not just malice you need to be careful of, but also accidents. Agreed. If we mistype something (as suggested by others), well, it's our fault. We know what will happen, if we still do it, well, it's our fault, we'll fix it. Believe it or not, so far (after about 1.5 years of operation) there were no typos that created problems. > The history of computing is full of systems that were designed with no > security because it wasn't needed, until it was needed, but it was too > late by then. > > There's no need, or at least very little need, to put locks on the > internal doors of your house, because we're not in the habit of taking > internal doors and turning them into outside doors. But code designed to > run inside your secure, safe network has a tendency to be re-purposed to > run in insecure, unsafe networks, usually by people who have forgotten, > or never knew, that they were opening up their system to code injection > attacks. On general grounds, you are right, of course. My point is that hacking can still be a fun and easy-going activity when one writes code for himself (almost) without regards to security and nasty things like that creeping in from the outside. I'm the king in my castle, although I'm fully aware of the fact that my castle might be ugly from the outside :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at mrabarnett.plus.com Tue Nov 10 14:02:04 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 19:02:04 +0000 Subject: Calendar Stuff In-Reply-To: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Message-ID: <4AF9B8AC.7080101@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have the following code: > > import calendar, datetime > > def cal(): > ... > myCal = calendar.Calendar(calendar.SUNDAY) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > # month = myCal.monthdayscalendar(int(time.strftime("%Y")) > month = myCal.monthdayscalendar(yr, mo) > print 'hi' > > html headers are included. No matter which one of the last two lines I > comment out, I never get to the point of printing 'hi'. (If I comment > them both out, it does print.) What do? > Read the tracebacks? The commented line will raise an exception because: 1. There's a final ')' missing. 2. You haven't imported 'time'. 3. .monthdayscalendar() requires the year and month. I don't know why you're writing 'int(time.strftime("%Y"))' because you already have the year in 'yr'. The code above works for me if I comment out the line '...'. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 14:08:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 19:08:35 GMT Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: <0309a863$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote: > Steven, remember a few weeks ago when you tried to explain to me that > the person who was storing windows administrative passwords using a 40 > byte xor cipher with the hardcoded password might not be doing something > stupid because I didn't know what their threat model was? Yeah- what you > just said is what I was trying to explain then. No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from the Evil Dimension... *wink* Seriously, I'm not sure if I knew that the person was storing Windows admin passwords at the time. If I had, I probably would have agreed with you. But using a 40 byte xor cipher to obfuscate some strings in a game is perfectly valid -- not every locked box needs to be a safe with 18 inch tempered steel walls. I can only repeat what I said to Daniel: can you guarantee that the nice safe, low-risk environment will never change? If not, then choose a more realistic threat model, and build the walls of your locked box accordingly. -- Steven From lallous at lgwm.org Tue Nov 10 14:09:54 2009 From: lallous at lgwm.org (lallous) Date: Tue, 10 Nov 2009 20:09:54 +0100 Subject: Python C api: create a new object class Message-ID: Hello I have 3 questions, hope someone can help: 1) How can I create an instance class in Python, currently I do: class empty: pass Then anytime I want that class (which I treat like a dictionary): o = empty() o.myattr = 1 etc.... Is there is a one line syntax to instantiate an instance? Any other ways than this: o = new.classobj('object', (), {}) 2) How can I, similarly, create an object "o" in C api: PyObject *o = what_to_call(....) .... PyObject_SetAttrString(o, "attrname", py_val) ... One way I found was first calling PyClass_New() (to create an empty class) and then passing the return value to PyInstance_NewRaw to get a new instance of that empty class. Can I achieve the same otherwise? 3) Given a PyObject* is there is a way to tell if one can call PyObject_SetAttrString() on that object w/o getting an error? For example, before calling a PyObject* one can see if it is callable, but can I test if an object supports setattr? (from C api) Thank you, Elias From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 14:11:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 19:11:07 GMT Subject: advice needed for lazy evaluation mechanism References: Message-ID: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> On Sun, 08 Nov 2009 14:41:27 -0800, markolopa wrote: > Hi, > > Could you please give me some advice on the piece of code I am writing? > > My system has several possible outputs, some of them are not always > needed. I started to get confused with the code flow conditions needed > to avoid doing unnecessary work. How many dozens of man-hours (yours, and the people who have to maintain the software after you have moved on) of confusion are you going to spend to avoid how many microseconds of execution time? So what if your system takes 35ms instead of 18ms to calculate the result? As Tony Hoare famously said: "We should forget about the small efficiencies, say about 97% of the time: Premature optimization is the root of all evil." Of course, all of this assumes that the routines you are trying to avoid calling don't require hours of running time each time you call them... > So I am trying to restructure it using lazy evaluation. Oh great, avoiding confusion with something even more confusing. > - Is there a more standard (pythonic) way to do what I am trying to do? Yes. Avoid it. Do the simplest thing that works until you *know* -- because you have profiled it -- that it is too slow. Until then, all that complication you've built, all that over-engineered jungle of classes and abstract classes, is unnecessary. I find it beyond all credibility that your data is so complicated that you need a plug-in system just to manage the methods you need to calculate your data. Just create some properties, like this one: class Example(object): def __init__(self, birth_year): self.birth_year = birth_year @property def age(self): return 2009 - self.birth_year # FIXME -- it won't be 2009 forever And there you have a lazily-evaluated age property. Not complicated enough? The 3ms it takes to calculate the age is too long? Cache it! class Example(object): def __init__(self, birth_year): self.birth_year = birth_year self._age = None @property def age(self): a = self._age if a is None: a = 2009 - self.birth_year self._age = a return a Now all you need is to invalidate the cache if the birth_year changes. So you make birth_year a property too: class Example(object): def __init__(self, birth_year): self.birth_year = birth_year @property def birth_year(self): return self._birth_year @property.setter # Requires Python 2.6. Also untested. def birth_year(self, year): self._birth_year = year self._age = None @property def age(self): a = self._age if a is None: a = 2009 - self.birth_year self._age = a return a > Are there libraries, design patterns, functional programming structures > to use to achieve what I am looking for (i.e. am I trying to reinvent > the wheel)? The most important buzzwords you want are YAGNI and Premature Generalisation, and perhaps a touch of Architecture Astronaut: http://www.joelonsoftware.com/items/2008/05/01.html > - Is the coding style good? > - Can I avoid the eval command in Repository.add_routine? What I want > there is to be able to have a generic code for the repository which does > not depend on the files containing the routines I want it to hold. You mean the exec? cmd = "from %s import %s\nroutine = %s()" % (file_name, class_name, class_name) exec(cmd) # XXX: ugly Yes. Untested: module = __import__(filename) class_object = getattr(module, class_name) routine = class_object() Of course you can turn that into a one-liner: routine = getattr(__import__(filename), class_name)() -- Steven From rt8396 at gmail.com Tue Nov 10 14:23:35 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 11:23:35 -0800 (PST) Subject: New syntax for blocks Message-ID: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Forgive me if i don't properly explain the problem but i think the following syntax would be quite beneficial to replace some redundant "if's" in python code. if something_that_returns_value() as value: #do something with value # Which can replace the following syntactical construct... value = something_that_returns_value() if value: #do something with value i dunno, just seems to make good sense. You save one line of code but more importantly one indention level. However i have no idea how much trouble the implementation would be? Now i know you could write a function and do the following to forgo the indention... value = something_that_returns_value() if not value: return #do something with value ....but that's even uglier and i would like the construct to work in both sinlge 'ifs' and also conditional's Now some might say...Whats the big deal, you only save one line of code?...True, but if you can save one line of code 100 or 1000 times how many lines of code is that my inquisitive friend? ;-) From jim.valenza at gmail.com Tue Nov 10 14:33:16 2009 From: jim.valenza at gmail.com (Jim Valenza) Date: Tue, 10 Nov 2009 13:33:16 -0600 Subject: New to Python need on advice on this script Message-ID: <12ef9e020911101133rc28b7cbld19621ee0f667c89@mail.gmail.com> Hello all - I'm new to the world of Python as I am a GIS guy who would like to broaden his horizons. I have a question about a script that we've been working on: The purpose of the code is to *Syncronize SDE DropBox with Regulatory Project working files. I am looking for where the script dumps the domain list to a table and loops through the table? Is It necessary? Seems like you should be able to simply loop through the domain list. I was just trying to see if there was a more straitforward way. Thanks The script is as follows:* ** # Create the Geoprocessor import sys, string, os, arcgisscripting, shutil, time gp = arcgisscripting.create() # Jim V testing # Allow output to overwrite gp.OverwriteOutput = 1 gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data Management Tools.tbx") #---create a logging file named "YYYYMMDD HH_MM_QualityControlLog.txt" theTime = time.strftime('%Y%m%d %H_%M') #logfilename = "H:\\Development\\Python\\" + theTime + "_PODsQAQCLog.txt" logfilename = "L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\" + theTime + "_PODsQAQCLog.txt" log = open(logfilename,'w') log.write(time.ctime() + "\n") print time.ctime() THE_WORKSPACE = os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin") + "\\" #REAL MODE LINE #THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\" #TEST MODE LINE log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n") print "THE_WORKSPACE IS " + THE_WORKSPACE P_CODE = "P_CODE" #Create table of valid P_CODEs and convert to List gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb", \ "regulatory_p_code", r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table", \ "pcode", "pdesc", "") #searchRows = gp.searchCursor(r"H:\Development\temp\test.mdb\code_table") searchRows = gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table") searchRow = searchRows.next() domainList = [] while searchRow: domainList.append(searchRow.pcode) searchRow = searchRows.next() #print domainList try: #Get Workspaces from text file #for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE for line in open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QAQC_Scripts/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE #for line in open("H:/Development/testdata/workspaces.txt", 'r'): #TEST MODE LINE if not line: break line = line.strip() if not line.startswith("#"): # skip lines that start with # ws, P = line.split("RMP_2_5_",1) #parse line to get path and P_CODE log.write(" " + "\n") log.write(" " + "\n") log.write(P + "\n") print " " print P src = THE_WORKSPACE + line #defines each workspace path #If the Geodatabase exists, perform the operations if os.path.exists(src): #Archive Geodatabase before running script log.write("The Geodatabase exists " + src + "\n") print "The Geodatabase exists " + src archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" + "RMP_2_5_" + P log.write("archiveFolder is " + archiveFolder + "\n") print "archiveFolder is " + archiveFolder shutil.copy(src, archiveFolder) #Archive the Geodatabase #Set workspace and variables gp.workspace = src log.write(gp.workspace + "\n") print gp.workspace P_Value = (P.strip(".mdb")) #Valitate P_Code value against Domain list if P_Value in domainList: log.write("P_Code is valid: " + P_Value + "\n") print "P_Code is valid: " + P_Value # List all feature classes in feature datasets fdss = gp.ListDatasets("","") fds = fdss.Next() while fds: fcs = gp.ListFeatureClasses("*","",fds) fc = fcs.Next() while fc: gp.CalculateField_management(fc, P_CODE, "'" + P_Value + "'", "PYTHON") #Calc P_Code gp.RepairGeometry(fc, r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\outy.shp") fc = fcs.Next() print fc fds = fdss.Next() #Copy the Geodatabase to the SDE InBox sdeInbox = "S:/Production/DropBox/InBox" #REAL MODE LINE #sdeInbox = "H:/Development/testInbox" #TEST MODE LINE log.write("sdeInbox is " + sdeInbox + "\n") print "sdeInbox is " + sdeInbox shutil.copy(src, sdeInbox) #Copy Geodatabase to SDE Inbox else: log.write("P_Code is NOT valid: " + P_Value + "\n") print "P_Code is NOT valid: " + P_Value else: log.write("The Geodatabase does not exist " + src + "\n") print "The Geodatabase does not exist " + src except: # If an error occurred, print the messages returned by the tool log.write(gp.GetMessages() + "\n") print gp.GetMessages() log.write(time.ctime() + "\n") log.write("FINISHED" + "\n") os.startfile("L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\") log.close() print "FINISHED" print time.ctime() -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Tue Nov 10 14:56:17 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 10 Nov 2009 14:56:17 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF94F5E.8020806@mailshack.com> References: <4AF94F5E.8020806@mailshack.com> Message-ID: <4AF9C561.1080403@ieee.org> Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an > interpreted language. > > I'm trying to see if there is any way I can make Python share data > between two hosts using DMA transfers over a firewire connection, so > avoiding the need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I > can read any write to the RAM of any firewire connected host within > python. Because it uses DMA (the cpu is not involved in this at all), > I can only specify a physical address within the 4GB ram limit to read > from and write to. > > Now what I've done so far is on the remote host I run python and set a > variable as so: > > a = "foo" > print a > 'foo' > > Then on the local host I run a python script that scans the entire RAM > looking for the string "foo", and replaces it with the string "oof". I > have had success with this method. Once it's done and I do "print a" > on the remote host, I get "oof" as the variable value, so in theory it > can work. > > Problem is that it's slow. Scanning 3GB of RAM every time you want to > do this is not a good method. I thought that if I could get python to > return the physical address of where the value of a variable is, then > I can just jump to that address and write the data. > > From what I've been told so far, it's not possible to do this without > some OS-specific (Linux in this case) syscall. Is this correct? > > Thanks! > > > Ognjen > > I'm sure you realize that scanning for a 3 byte tag is not only slow, but very dangerous. It could easily have been three other bytes which just happened to match this string. And those bytes could have been part of a disk directory entry (result disk corruption) or some other application. Further, between the time you did the search and the time when you updated, the relevant bytes could have been swapped to disk, and something else put in the same physical address. Anyway, I've been assuming all along that you meant address in the sense that a C program uses it, which is a linear address. But as long as you're running on an OS that has virtual memory running, there's another translation going on invisibly to the application, which converts linear to physical. So even after you get a memory address, you need to convince the OS to lock such memory in place for awhile, and then tell you where (physical address) it locked it. Note also that if a range of addresses spans a 4k boundary (for Intel architecture), it's possible that the physical addresses are not even contiguous. But the system calls from Windows (and presumably also from Linux) can hide that from you, via double-buffering. DaveA From victorsubervi at gmail.com Tue Nov 10 14:58:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 14:58:43 -0500 Subject: Calendar Stuff In-Reply-To: <4AF9B8AC.7080101@mrabarnett.plus.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> <4AF9B8AC.7080101@mrabarnett.plus.com> Message-ID: <4dc0cfea0911101158q3f91879enfdb7717e2012f2f@mail.gmail.com> On Tue, Nov 10, 2009 at 2:02 PM, MRAB wrote: > Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> import calendar, datetime >> >> def cal(): >> ... >> myCal = calendar.Calendar(calendar.SUNDAY) >> today = datetime.date.today() >> day = today.day >> mo = today.month >> yr = today.year >> # month = myCal.monthdayscalendar(int(time.strftime("%Y")) >> month = myCal.monthdayscalendar(yr, mo) >> print 'hi' >> >> html headers are included. No matter which one of the last two lines I >> comment out, I never get to the point of printing 'hi'. (If I comment them >> both out, it does print.) What do? >> >> Read the tracebacks? > > The commented line will raise an exception because: > > 1. There's a final ')' missing. > > 2. You haven't imported 'time'. > > 3. .monthdayscalendar() requires the year and month. > > I don't know why you're writing 'int(time.strftime("%Y"))' because you > already have the year in 'yr'. > > The code above works for me if I comment out the line '...'. > -- > It works fine for me in the python interpreter but not in the page from which it's called! You say import time, but where do I call time in my script? Here's the code (abbreviated just to print something out to see it work), please advise if you can: #!/usr/bin/python import string import sys,os sys.path.append(os.getcwd()) import calendar, datetime, time import MySQLdb import string, re from login import login def calendarPrint(): print "Content-Type: text/html" print print """ NR Electric The slash must appear directly before the 'script' > """ > myCal = calendar.Calendar(calendar.SUNDAY) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > month = myCal.monthdayscalendar(yr, mo) > print month > > calendarPrint() > > I haven't tried to upload it to a server. But running it locally, then taking the output and feeding it to Firefox, I see a few things wrong. It's declared asw HTML, but you don't have a opening tag. And you're missing closing tags for /body and /html Tidy complains that the DOCTYPE url is malformed, but you couldn't prove it by me. And month is a list of lists, so I don't know why you're printing it. DaveA From phlip2005 at gmail.com Tue Nov 10 16:09:57 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 13:09:57 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> except... will pip pull from a simple GitHub repo? or do I need to package something up and put it in a pythonic repository somewhere? From aahz at pythoncraft.com Tue Nov 10 16:19:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 13:19:59 -0800 Subject: module imports and st_mtime References: Message-ID: In article , tow wrote: > >Does anyone have any ideas what might be going on, or where further to >look? I'm at a bit of a loss. Try asking on pythonmac-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From VBoycheva at jonesedmunds.com Tue Nov 10 16:21:18 2009 From: VBoycheva at jonesedmunds.com (Valentina Boycheva) Date: Tue, 10 Nov 2009 16:21:18 -0500 Subject: New to Python need on advice on this script References: <12ef9e020911101133rc28b7cbld19621ee0f667c89@mail.gmail.com> Message-ID: <82347ACEFB791E479B7E9C20F3567217026E29A3@mailje08.jea.net> Jim, In Python 2.5 under ArcMap 9.3 domains can be only listed. To get to the domain values, they need to be converted to tables. Also, the default value cannot be obtained from the existing GP API. Very annoying! The workaround is to use VBA ArcObjects or connect to the database directly, if possible, and extract the information from the GDB. This latter will work for PGDB, not sure about FGDB. Regards, Valentina Boycheva From: Jim Valenza [mailto:jim.valenza at gmail.com] Sent: Tuesday, November 10, 2009 2:33 PM To: python-list at python.org Subject: New to Python need on advice on this script Hello all - I'm new to the world of Python as I am a GIS guy who would like to broaden his horizons. I have a question about a script that we've been working on: The purpose of the code is to Syncronize SDE DropBox with Regulatory Project working files. I am looking for where the script dumps the domain list to a table and loops through the table? Is It necessary? Seems like you should be able to simply loop through the domain list. I was just trying to see if there was a more straitforward way. Thanks The script is as follows: # Create the Geoprocessor import sys, string, os, arcgisscripting, shutil, time gp = arcgisscripting.create() # Jim V testing # Allow output to overwrite gp.OverwriteOutput = 1 gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data Management Tools.tbx") #---create a logging file named "YYYYMMDD HH_MM_QualityControlLog.txt" theTime = time.strftime('%Y%m%d %H_%M') #logfilename = "H:\\Development\\Python\\" + theTime + "_PODsQAQCLog.txt" logfilename = "L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\ QAQC_Scripts\\" + theTime + "_PODsQAQCLog.txt" log = open(logfilename,'w') log.write(time.ctime() + "\n") print time.ctime() THE_WORKSPACE = os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin ") + "\\" #REAL MODE LINE #THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\" #TEST MODE LINE log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n") print "THE_WORKSPACE IS " + THE_WORKSPACE P_CODE = "P_CODE" #Create table of valid P_CODEs and convert to List gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder _River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb", \ "regulatory_p_code", r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_S cripts\test.mdb\code_table", \ "pcode", "pdesc", "") #searchRows = gp.searchCursor(r"H:\Development\temp\test.mdb\code_table") searchRows = gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin \Pipeline\QAQC_Scripts\test.mdb\code_table") searchRow = searchRows.next() domainList = [] while searchRow: domainList.append(searchRow.pcode) searchRow = searchRows.next() #print domainList try: #Get Workspaces from text file #for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE for line in open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QA QC_Scripts/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE #for line in open("H:/Development/testdata/workspaces.txt", 'r'): #TEST MODE LINE if not line: break line = line.strip() if not line.startswith("#"): # skip lines that start with # ws, P = line.split("RMP_2_5_",1) #parse line to get path and P_CODE log.write(" " + "\n") log.write(" " + "\n") log.write(P + "\n") print " " print P src = THE_WORKSPACE + line #defines each workspace path #If the Geodatabase exists, perform the operations if os.path.exists(src): #Archive Geodatabase before running script log.write("The Geodatabase exists " + src + "\n") print "The Geodatabase exists " + src archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" + "RMP_2_5_" + P log.write("archiveFolder is " + archiveFolder + "\n") print "archiveFolder is " + archiveFolder shutil.copy(src, archiveFolder) #Archive the Geodatabase #Set workspace and variables gp.workspace = src log.write(gp.workspace + "\n") print gp.workspace P_Value = (P.strip(".mdb")) #Valitate P_Code value against Domain list if P_Value in domainList: log.write("P_Code is valid: " + P_Value + "\n") print "P_Code is valid: " + P_Value # List all feature classes in feature datasets fdss = gp.ListDatasets("","") fds = fdss.Next() while fds: fcs = gp.ListFeatureClasses("*","",fds) fc = fcs.Next() while fc: gp.CalculateField_management(fc, P_CODE, "'" + P_Value + "'", "PYTHON") #Calc P_Code gp.RepairGeometry(fc, r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_S cripts\outy.shp") fc = fcs.Next() print fc fds = fdss.Next() #Copy the Geodatabase to the SDE InBox sdeInbox = "S:/Production/DropBox/InBox" #REAL MODE LINE #sdeInbox = "H:/Development/testInbox" #TEST MODE LINE log.write("sdeInbox is " + sdeInbox + "\n") print "sdeInbox is " + sdeInbox shutil.copy(src, sdeInbox) #Copy Geodatabase to SDE Inbox else: log.write("P_Code is NOT valid: " + P_Value + "\n") print "P_Code is NOT valid: " + P_Value else: log.write("The Geodatabase does not exist " + src + "\n") print "The Geodatabase does not exist " + src except: # If an error occurred, print the messages returned by the tool log.write(gp.GetMessages() + "\n") print gp.GetMessages() log.write(time.ctime() + "\n") log.write("FINISHED" + "\n") os.startfile("L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basi n\\Pipeline\\QAQC_Scripts\\") log.close() print "FINISHED" print time.ctime() -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Nov 10 16:27:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 22:27:19 +0100 Subject: Python as network protocol In-Reply-To: <7ltv3aF3ftjjpU1@mid.uni-berlin.de> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <7ltv3aF3ftjjpU1@mid.uni-berlin.de> Message-ID: >> My point is that hacking can still be a fun and easy-going activity >> when one writes code for himself (almost) without regards to security >> and nasty things like that creeping in from the outside. I'm the king >> in my castle, although I'm fully aware of the fact that my castle >> might be ugly from the outside :) > > Which is a relevant statement in the context of the OP seeking advice on > *secure ways* of executing code in a restricted environment in exactly > what way? Okay, I reread the original message and you are right, the OP did want restricted scope, so probably his environment is not completely risk free. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Tue Nov 10 16:33:51 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 10 Nov 2009 16:33:51 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> Message-ID: <4AF9DC3F.7020505@ieee.org> Victor Subervi wrote: > Hi; > I've determined the problem in a script is I can't open a file to write it: > script = open(getpic, "w") # where getpic is already defined > Here are the permissions: > -rwxr-xr-x 1 root root 4649 Nov 10 12:31 start.py > What am I doing wrong? > TIA, > Victor > > Wrong? 1) you don't specify the environment, python version, OS, etc. 2) you don't show the error traceback 3) you don't indicate the value of getpic at the time this statement executes 4) you don't indicate what the current working directory is, os.getcwd() 5) you don't indicate what directory the start.py is located in 6) you don't indicate which user is executing this script (only root can write to it) 7) you don't tell what the filename of the script is, specif. if it's called start.py 8) you don't say what happens if you do an open(getpic, "r"), or os.path.isfile(getpic) By the time you answer each of those questions, you may notice the answer to your own question. DaveA From ethan at stoneleaf.us Tue Nov 10 16:40:17 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Nov 2009 13:40:17 -0800 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: <4AF9DDC1.4010901@stoneleaf.us> Daniel Fetchinson wrote: > I'm the king in my castle, although I'm fully aware of the fact that my castle > might be ugly from the outside :) +1 QOTW From ethan at stoneleaf.us Tue Nov 10 16:43:02 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Nov 2009 13:43:02 -0800 Subject: Python as network protocol In-Reply-To: <0309a863$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <0309a863$0$1340$c3e8da3@news.astraweb.com> Message-ID: <4AF9DE66.5010301@stoneleaf.us> Steven D'Aprano wrote: > I can only repeat what I said to Daniel: can you guarantee that the nice > safe, low-risk environment will never change? If not, then choose a more > realistic threat model, and build the walls of your locked box > accordingly. Seems to me you can't really *guarentee* anything, especially something as elusive as the distant future. Program for what your needs are, and document accordingly. ~Ethan~ From claird.visiprise at gmail.com Tue Nov 10 16:56:50 2009 From: claird.visiprise at gmail.com (Cameron Laird) Date: Tue, 10 Nov 2009 13:56:50 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Nov 10) Message-ID: <05645648-fe4e-4554-8087-e2ccd5f879e2@s15g2000yqs.googlegroups.com> QOTW: "Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis." - Diez B. Roggisch, on ... well, personal style in problem-solving http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b [It's actually Gabriel Genellina who wrote these entries.] Why aren't lists usable as dictionary keys? What do you mean, "hashable"? http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/ `x == None` or `x is None` -- which one is the right way? http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/ At Microsoft, they performed empirical research about common software engineering assumptions: "high test coverage is better", "write test code first", "use assertions", and others: http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/ The best way to populate a list of size N: http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/ A new variant of an old problem: I got a single check from my customer - which ones among all pending invoices did he intend to pay? http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/ How to test code that uses urllib without depending on external resources? http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/ Singletons are hard to test too: http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/ How to use Filters in the logging module: http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/ Delete items from a list that match a certain pattern: http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/ What is the correct way to port codecs.open to python 3.1? http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/ py2exe, cx_freeze, py2app: a comparison http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/ How to cancel a thread from another one: http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/ Why does "help(import)" not work? http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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.com p.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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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.p ython.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 rt8396 at gmail.com Tue Nov 10 16:59:24 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 13:59:24 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> Message-ID: <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> On Nov 10, 2:08?pm, Robert Latest wrote: (..snip..) > Also it's not the "if" that is (if at all) redundant here but the assignment. Not exactly. The assignment happens only once just as the boolean check of "if " happens once. The redundancy is in validating the existence of a truthful value contained in a variable after assignment of a value to that same variable. It's like putting on your tennis shoes and then asking yourself 'am i wearing tennis shoes?'. Of course we all know *why* we must verify the existence of value afterward and the shoe analogy doesn't translate 1:1 to programming. It's more like... shoes = grab_a_pair_of_shoes_or_none_and_apply_to_feet() if shoes: shoes.this() shoes.that() Now did we find a pair of shoes or did we fail because the lights were out and all we accomplished was to toil around in the closet for half an hour bumping our head before finally giving up and returning empty handed? Just thinking out loud here...what if variable assignments could return a value... hmmm? Not to them selfs of course but to a caller, like an if statement... if a=openfile: # do something with a (if(a.__eq__(openfile))) Python would need to stuff the value of openfile into "a", then add the variable "a" to the proper namespace, then evaluate if "a" is True. This would read more naturally than even my first postulation. I bet it would confuse the crap out of noobies though! So basically with the new syntax what your saying is this: if the value of this expression bools to False, toss it away because i don't need it, else assign the value to a local variable and run the block. Basically your encaspulating an if..else block in one line of code. From aahz at pythoncraft.com Tue Nov 10 17:02:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 14:02:52 -0800 Subject: can i configure IDLE to use python 3.2 on fedora? References: Message-ID: In article , Robert P. J. Day wrote: > > on fedora 11 system, there is no python 3 package so i downloaded >and manually installed (svn checkout) python pre-3.2 in >/usr/local/bin. works fine, but if i install the python-tools >package, "idle" that comes with it is hard-coded(?) to still refer to >the officially-installed python-2.6. i see no way to configure idle >to use the "python3" executable instead. Just find your python3 IDLE, I think it's in Tools/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From simon.hibbs at gmail.com Tue Nov 10 17:08:14 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 10 Nov 2009 14:08:14 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On 10 Nov, 10:40, Lorenzo Gatti wrote: > I also would like to use PySide, but unlike PyQt and Qt itself it > doesn't seem likely to support Windows in the foreseeable future. A > pity, to put it mildly. It's not been ruled out. They don't officialy support the Mac either, but according to posts on the mailing list a independent developer has got it working in MacOS X at some level. Since QT runs on Windows, porting to the Windows version of QT shouldn't be hard. PySide is for the future, not the present, but it gives me a lot more confidence in using and recomending PyQT to know that there is so much work being put in to make sure it has a great future. Simon Hibbs From martin at v.loewis.de Tue Nov 10 17:08:33 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Nov 2009 23:08:33 +0100 Subject: DHT for Python 3.x? In-Reply-To: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: <4AF9E461.1030902@v.loewis.de> Salim Fadhley wrote: > There are plenty of good DHT projects for Python 2.x, however from > what I can tell none of them have made the jump to 3.x yet. > > I'm really keen to support Python 3.x for a project I'm working on. I > know that many developers (correctly) consider switching to Python 3 > foolish since it is less supported at the moment, but nevertheless I > am keen to carry on. > > So can somebody recommend me a working implementation of a DHT which > will work on Python 3.x and preferably Python 2.6 as well. I can't. But I recommend to port the library that you like most to 3.x, and provide any necessary changes to the author. Regards, Martin From martin at v.loewis.de Tue Nov 10 17:17:27 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Nov 2009 23:17:27 +0100 Subject: Python C api: create a new object class In-Reply-To: References: Message-ID: <4AF9E677.9050502@v.loewis.de> > How can I create an instance class in Python, currently I do: > > class empty: > pass > > Then anytime I want that class (which I treat like a dictionary): > > o = empty() > o.myattr = 1 > etc.... > > Is there is a one line syntax to instantiate an instance? > > Any other ways than this: > o = new.classobj('object', (), {}) Most certainly: o = empty(1) # or: o = empty(1, etc) This requires you to define class empty: def __init__(self, myattr, etc): self.myattr = myattr etc > 2) > > How can I, similarly, create an object "o" in C api: > > PyObject *o = what_to_call(....) o = PyObject_CallFunction(pointer_to_class_object, "") > 3) > > Given a PyObject* is there is a way to tell if one can call > PyObject_SetAttrString() on that object w/o getting an error? > > For example, before calling a PyObject* one can see if it is callable, > but can I test if an object supports setattr? > > (from C api) You could check whether the object supports setattr at all, but that would be pretty useless, since most objects do. What you want to test (would it support setting "myattr" to the specific value, at this point) is impossible to test: the object may give you an exception on every third call only (or only if the value is not an integer, etc). So just call SetAttr, and clear any exception you get that you don't want to get. Regards, Martin From benjamin at python.org Tue Nov 10 17:20:15 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Nov 2009 22:20:15 +0000 (UTC) Subject: Python C api: create a new object class References: Message-ID: lallous lgwm.org> writes: > Is there is a one line syntax to instantiate an instance? You can't instantiate an instance; it's already instantiated. > > Any other ways than this: > o = new.classobj('object', (), {}) class x: pass > How can I, similarly, create an object "o" in C api: Use PyObject_CallFunction(PyType_Type, [arguments]) > Given a PyObject* is there is a way to tell if one can call > PyObject_SetAttrString() on that object w/o getting an error? No. From benjamin at python.org Tue Nov 10 17:27:17 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Nov 2009 22:27:17 +0000 (UTC) Subject: Threaded import hang in cPickle.dumps References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: Zac Burns gmail.com> writes: > What can I do about this? Not run it in a thread. From ben+python at benfinney.id.au Tue Nov 10 17:45:59 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Nov 2009 09:45:59 +1100 Subject: on "Namespaces" References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: <87my2u0ziw.fsf@benfinney.id.au> Steven D'Aprano writes: > Modules are namespaces. So are packages. > > Classes and class instances are namespaces. > > Even function scopes are namespaces. Steven implies it with his wording, but to make it explicit: When you have a module, package, class, or instance-of-a-class object, those objects are themselves namespaces. That is, the name used to refer to the object can be a component in a namespace reference:: import foo_package import bar_module class Parrot(object): widget = object() parrot = Parrot() # Use a package as a namespace. foo_package.spam_module.frobnicate() # Use a module as a namespace. bar_module.spangulate() # Use a class as a namespace. print Parrot.widget # Use an arbitrary instance as a namespace. parrot.state = "Restin'" When you have a function object, the ?function scope? is not available in this way: you can't access the ?inside? of the function from the outside via the function object. (The function object, like any other object, has a namespace, but that's not the *function scope* namespace.) > When you write: > > > n = None > > def spam(n): > print "spam" * n > > def ham(n): > print "ham" * n > > the n inside spam() and ham() and the global n are in different > namespaces, and so independent. Right. And neither of them is available from outside those functions (since the reference only exists while the function is executing). -- \ ?Roll dice!? ?Why?? ?Shut up! I don't need your fucking | `\ *input*, I need you to roll dice!? ?Luke Crane, demonstrating | _o__) his refined approach to play testing, 2009 | Ben Finney From sjmachin at lexicon.net Tue Nov 10 17:46:49 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Nov 2009 14:46:49 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: <2f951ad3-df8c-44ec-ac27-e9a9395d722c@x6g2000prc.googlegroups.com> On Nov 8, 8:39?am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the $200 > and $100. In other words, there is more than one solution to the > problem. The problems that you mention are only a SUBSET of the total problem. Example: oustanding invoices are for 300, 200, and 100 and the cheque is for 450 -- in general the total of the cheque amounts does not equal the total of any possible selection of outstanding invoice amounts. I would be very surprised if a real accounting department did not already have a set of business rules for dealing with a problem that has existed since invoices and cheques were invented. I would be extremely surprised if a real accounting department could be persuaded to imagine a subset of their unpaid/underpaid/overpaid invoice problem as being an instance of the (extended) knapsack problem :-) From sjmachin at lexicon.net Tue Nov 10 17:59:13 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Nov 2009 14:59:13 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: On Nov 8, 8:39?am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > My second question is: > 2. this time there are also credit notes outstanding, that is, > invoices with negative amounts. For example, ?I=[500, 400, -100, 450, > 200, 600, -200, 700] and a check Ch=600 How can a credit note be "outstanding"? The accounting department issues a credit note without recording what invoice it relates to? From wentland at cl.uni-heidelberg.de Tue Nov 10 18:11:57 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Wed, 11 Nov 2009 00:11:57 +0100 Subject: how to create a pip package In-Reply-To: <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <20091110231157.GA672@kinakuta.local> On Tue, Nov 10, 2009 at 13:09 -0800, Phlip wrote: > will pip pull from a simple GitHub repo? or do I need to package > something up and put it in a pythonic repository somewhere? I don't quite understand, but would say: both ;-) You can't tell pip to pull from arbitrary git repositories, but only from those that contain the packaging code as outlined in the distutils documentation. These git repositories do *not* have to be hosted on pypi. You should however be able to do the following: $ git clone git://example.com/repo.git $ cd repo $ python setup.py install The pip requirement file would contain the following line: -e git+git://example.com/repo.git#egg=rep I hope this answers your questions :-D -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From nagle at animats.com Tue Nov 10 18:12:35 2009 From: nagle at animats.com (John Nagle) Date: Tue, 10 Nov 2009 15:12:35 -0800 Subject: CGI vs mod_python In-Reply-To: References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Message-ID: <4af9f122$0$1659$742ec2ed@news.sonic.net> ssteinerX at gmail.com wrote: > > On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: > >> Yes, obviously. But if CGI is enabled, it should work anyway, should >> it not? > > Depends on what "CGI is enabled" means. > > Usually, web servers are not set to just handle cgi scripts from > anywhere, but only from specific file system locations. Otherwise, an > an anonymous upload could be executed as CGI and wreak havoc. If it won't work as a CGI program, which is relatively straightforward, it probably won't work at all. First, write some trivial CGI program in Python and make sure the environment works - Python loads, the Python program loads, and you can get a response back. Bear in mind that most hosting services don't make much of an attempt to support Python. Expect important libraries to be missing or obsolete. John Nagle From rhodri at wildebst.demon.co.uk Tue Nov 10 18:18:20 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 23:18:20 -0000 Subject: is None or == None ? In-Reply-To: <0309a54d$0$1340$c3e8da3@news.astraweb.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> <0309a54d$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Nov 2009 18:55:25 -0000, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 15:46:10 +0000, Grant Edwards wrote: > >> On 2009-11-10, Rhodri James wrote: >>> On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy >>> wrote: >>> >>>> I believe the use of tagged pointers has been considered and so far >>>> rejected by the CPython developers. And no one else that I know of has >>>> developed a fork for that. It would seem more feasible with 64 bit >>>> pointers where there seem to be spare bits. But CPython will have to >>>> support 32 bit machines for several years. >>> >>> I've seen that mistake made twice (IBM 370 architecture (probably 360 >>> too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see >>> it a third time, thank you. >> >> MacOS applications made the same mistake on the 68K. They reserved the >> high-end bits in a 32-bit pointer and used them to contain >> meta-information. > > > Obviously that was their mistake. They should have used the low-end bits > for the metadata, instead of the more valuable high-end. Oh, ARM used the low bits too. After all, instructions were 4-byte aligned, so the PC had all those bits going spare... -- Rhodri James *-* Wildebeest Herder to the Masses From aahz at pythoncraft.com Tue Nov 10 18:23:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 15:23:40 -0800 Subject: futures - a new package for asynchronous execution References: Message-ID: In article , Brian Quinlan wrote: > >I recently implemented a package that I'd like to have include in the >Python 3.x standard library (and maybe Python 2.x) and I'd love to >have the feedback of this list. Any recently implemented library has an extremely high bar before it gets adopted into the standard library. You should concentrate on persuading people to use your library; for example, you should make regular feature and bugfix releases and announce them on c.l.py.announce. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From python at rcn.com Tue Nov 10 18:35:12 2009 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 Nov 2009 15:35:12 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: <498f3fbd-93bd-448d-8acd-9401b04daad6@m7g2000prd.googlegroups.com> [vsoler] > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. I worked on a similar problem involving frequent bank deposits (the bank recorded only the amount of the deposit with no other tracking information to let us know which store made the deposit) and reconciling those deposits to general ledger entries. As pointed-out by others, the purest statement of the problem is computationally unfeasible; however, the real-world application can provide useful heuristics to that limit the search space. 1) Dates can be used to provide some alignment. Customers tend to pay the oldest invoices first and they don't pay before the first invoice is sent. Also, there can be a typical time lag that helps identify where to start a search (i.e. the customer typically takes 45 days to pay an invoice). 2) Search smallest groupings first (eliminate exact matches) then groupings of two items and groupings of three items. 3) Sometime the values on the list possess properties that make them stand-out and easier to match-up. Given invoices of [10, 11, 12, 1000, 13, 14], the 1000 should be easy to match-up in any grouping of payments. Likewise, when looking for groupings, start with the most unique values. Given [2, 2, 2, 3, 3, 5, 5, 5, 6.1, 7], start by trying to match the 6.1 since there is only one occurrence. Raymond From rhodri at wildebst.demon.co.uk Tue Nov 10 18:35:47 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 23:35:47 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: <6PfKm.51354$Db2.3028@edtnps83> References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 wrote: > Rhodri James wrote: >> On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 >> wrote: >> >>> Rhodri James wrote: >>>> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >>>> wrote: >>>> >>>>> I have a perplexing issue, I have four users set up on a W7 >>>>> computer. The program runs fine for all users except the admin user >>>>> who needs it for school assignments. >>>> A little more information, please. How does it not work for the >>>> admin >>>> user? Is there a traceback? What do you get if you try to invoke it >>>> from a command line? >>>> >>> >>> >>> Hi Rhodri, here's a dump file, don't know if this helps or not.. >> So Windows is reporting a crash, then. I'll repeat my last question >> in particular; what happens when your admin user runs the program >> you're trying to invoke from the command line? >> > > Hi Rhodri, Python Command-Line works fine. I'm sure it does. That's not what I asked you. > Are toy recommending to invoke IDLE from there or from windows command > line? No, I'm asking you -- or rather your admin user -- to invoke the program that is giving you grief from the command line, i.e. "python myscript.py", and tell me what happens. "It doesn't work" won't be considered at all helpful; without details we might as well just print out your script, throw darts at it, and tell you the problem is where the darts land. The rest of your answer however suggests that I've fundamentally misunderstood what you've said. Please tell me *exactly* what happens when it doesn't "run fine" for your admin user. -- Rhodri James *-* Wildebeest Herder to the Masses From pavlovevidence at gmail.com Tue Nov 10 18:38:24 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 15:38:24 -0800 (PST) Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: On Nov 10, 3:32?am, Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an interpreted > language. > > I'm trying to see if there is any way I can make Python share data > between two hosts using DMA transfers over a firewire connection, so > avoiding the need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I can > read any write to the RAM of any firewire connected host within python. > Because it uses DMA (the cpu is not involved in this at all), I can only > specify a physical address within the 4GB ram limit to read from and > write to. [snip] > ?From what I've been told so far, it's not possible to do this without > some OS-specific (Linux in this case) syscall. Is this correct? What you'd normally need to do it to use system calls to allocate a DMA-able memory buffer, then copy contents of your Python object (which you get at using buffer protocol) to this buffer, then initiate the DMA transfer. At this point it probably would be easier to just write a C-extension to do that, but I see no reason it can't be done with ctypes. However, I'm not sure how that would interact with your pre-existing module. I'd expect a module that does DMA to take care of physical address mapping itself, you just pass it a logical address, or an object that supports buffer protocol, and it does the rest. It seems just getting a physical address and starting a DMA transfer from it is prone to danger if memory pages are discontiguous (and they often are), but maybe OSes these days can handle that automatically. Carl Banks From debatem1 at gmail.com Tue Nov 10 18:48:55 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 18:48:55 -0500 Subject: Python as network protocol In-Reply-To: <0309a863$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <0309a863$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 2:08 PM, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote: > >> Steven, remember a few weeks ago when you tried to explain to me that >> the person who was storing windows administrative passwords using a 40 >> byte xor cipher with the hardcoded password might not be doing something >> stupid because I didn't know what their threat model was? Yeah- what you >> just said is what I was trying to explain then. > > No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from > the Evil Dimension... > > *wink* I think I saw a mustache on him. Probably evil. > Seriously, I'm not sure if I knew that the person was storing Windows > admin passwords at the time. If I had, I probably would have agreed with > you. But using a 40 byte xor cipher to obfuscate some strings in a game > is perfectly valid -- not every locked box needs to be a safe with 18 > inch tempered steel walls. Granted, and I am going to be able to give a very nice talk on how not to do cryptography partially as a result of that particularly egregious bit of silliness, so I guess I can't complain too much. > I can only repeat what I said to Daniel: can you guarantee that the nice > safe, low-risk environment will never change? If not, then choose a more > realistic threat model, and build the walls of your locked box > accordingly. Or, plan on becoming part of one of my presentations in a few years. Either way works for me. Geremy Condra From vmanis at telus.net Tue Nov 10 19:05:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 16:05:01 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, at 07:46, Grant Edwards wrote: > MacOS applications made the same mistake on the 68K. They > reserved the high-end bits At the time the 32-bit Macs were about to come on the market, I saw an internal confidential document that estimated that at least over 80% of the applications that the investigators had looked at (including many from that company named after a fruit, whose head office is on Infinite Loop) were not 32-bit clean. This in spite of the original edition of Inside Mac (the one that looked like a telephone book) that specifically said always to write 32-bit clean apps, as 32-bit machines were expected in the near future. It's not quite as bad as the program I once looked at that was released in 1999 and was not Y2K compliant, but it's pretty close. --v From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 21:25:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 02:25:47 GMT Subject: My own accounting python euler problem References: <2f951ad3-df8c-44ec-ac27-e9a9395d722c@x6g2000prc.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 14:46:49 -0800, John Machin wrote: > The problems that you mention are only a SUBSET of the total problem. > Example: oustanding invoices are for 300, 200, and 100 and the cheque is > for 450 -- in general the total of the cheque amounts does not equal the > total of any possible selection of outstanding invoice amounts. > > I would be very surprised if a real accounting department did not > already have a set of business rules for dealing with a problem that has > existed since invoices and cheques were invented. As a sometimes accounts department, let me put my hand up for that. Yes. Generally the rule is, "call the damn customer and ask them what they're smoking", only more politely. Usually they'll have some convoluted breakdown of what amount they are paying off each invoice. Sometimes they will have taken off a settlement discount for prompt payment (often whether or not they actually paid promptly). Sometimes they overpay, or underpay, or apply credits to the wrong invoice, or pay invoices twice, or pay the wrong amount, or just make up a number from thin air. Sometimes they themselves will have no idea what the amount represents. And, I can guarantee, they will *ALWAYS* use a different rounding scheme to whatever accounting software you use, so there's always odd one or two cents that need to be manually adjusted somewhere. > I would be extremely surprised if a real accounting department could be > persuaded to imagine a subset of their unpaid/underpaid/overpaid invoice > problem as being an instance of the (extended) knapsack problem :-) That's because the average accounting department is mathematically illiterate :) Nevertheless, many accounting software packages, like Quickbooks, will take a wild stab at allocating payments for you, usually using some variation of "if you can't find an exact match for a single invoice, just blindly allocate it to the oldest invoices you can". Frankly, I'd much prefer a knapsack solution. -- Steven From anthoniraja at gmail.com Tue Nov 10 21:26:48 2009 From: anthoniraja at gmail.com (Antony) Date: Tue, 10 Nov 2009 18:26:48 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: <53e5095a-aec3-4268-9b23-d822949b47e3@12g2000pri.googlegroups.com> On Nov 11, 3:08?am, Simon Hibbs wrote: > On 10 Nov, 10:40, Lorenzo Gatti wrote: > > > I also would like to use PySide, but unlike PyQt and Qt itself it > > doesn't seem likely to support Windows in the foreseeable future. A > > pity, to put it mildly. > > It's not been ruled out. They don't officialy support the Mac either, > but according to posts on the mailing list a independent developer has > got it working in MacOS X at some level. Since QT runs on Windows, > porting to the Windows version of QT shouldn't be hard. > > PySide is for the future, not the present, but it gives me a lot more > confidence in using and recomending PyQT to know that there is so much > work being put in to make sure it has a great future. > > Simon Hibbs Thanks All I have got an idea,the way i need to choose GUI module in Python , As "r" said i am going to start from tkinter without any IDE . if i need any advanced feature then i will move on to some other module.... First i have to try the code ... From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 21:30:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 02:30:15 GMT Subject: My own accounting python euler problem References: Message-ID: On Tue, 10 Nov 2009 14:59:13 -0800, John Machin wrote: > On Nov 8, 8:39?am, vsoler wrote: >> In the accounting department I am working for we are from time to time >> confronted to the following problem: > [snip] > >> My second question is: >> 2. this time there are also credit notes outstanding, that is, invoices >> with negative amounts. For example, ?I=[500, 400, -100, 450, 200, 600, >> -200, 700] and a check Ch=600 > > How can a credit note be "outstanding"? The accounting department issues > a credit note without recording what invoice it relates to? Yes, that can happen. (1) Human error, or laziness, or dumb software that doesn't understand credits apply to specific invoices. (2) The credit note represents a settlement discount, rebate, "advertising allowance" or other kickback, or similar. (3) An invoice is paid in full, then later the client claims a refund against it. If granted, the credit can't be applied to the invoice that is already flagged as paid, so it remains as an "unallocated" credit note. (4) Or simply that the boss forbids you from allocating credit notes until payment is received. -- Steven From communication at linkedin.com Tue Nov 10 21:38:42 2009 From: communication at linkedin.com (LinkedIn Communication) Date: Tue, 10 Nov 2009 18:38:42 -0800 (PST) Subject: LinkedIn Messages, 11/10/2009 Message-ID: <1736753274.2985675.1257907122901.JavaMail.app@ech3-cdn09.prod> LinkedIn ------------ REMINDERS: Invitation Reminders: * View Invitation from Frank Pan http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I379833192_3/0PnP8VcjcPe3ATcQALqnpPbOYWrSlI/svi/ PENDING MESSAGES: There are a total of 4 messages awaiting your response. Visit your InBox now: http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/inb/ ------ Don't want to receive email notifications? Adjust your message settings: https://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/prv/ LinkedIn values your privacy. At no time has LinkedIn made your email address available to any other LinkedIn user without your permission. (c) 2009, LinkedIn Corporation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 22:07:36 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 03:07:36 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Tue, 10 Nov 2009 16:05:01 -0800, Vincent Manis wrote: > At the time the 32-bit Macs were about to come on the market, I saw an > internal confidential document that estimated that at least over 80% of > the applications that the investigators had looked at (including many > from that company named after a fruit, whose head office is on Infinite > Loop) were not 32-bit clean. This in spite of the original edition of > Inside Mac (the one that looked like a telephone book) that specifically > said always to write 32-bit clean apps, as 32-bit machines were expected > in the near future. That is incorrect. The original Inside Mac Volume 1 (published in 1985) didn't look anything like a phone book. The original Macintosh's CPU (the Motorola 68000) already used 32-bit addressing, but the high eight pins were ignored since the CPU physically lacked the pins corresponding to those bits. In fact, in Inside Mac Vol II, Apple explicitly gives the format of pointers: the low-order three bytes are the address, the high-order byte is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 the resource bit. The other five bits were unused. By all means criticize Apple for failing to foresee 32-bit apps, but criticizing them for hypocrisy (in this matter) is unfair. By the time they recognized the need for 32-bit clean applications, they were stuck with a lot of legacy code that were not clean. Including code burned into ROMs. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 22:12:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 03:12:55 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > r: > >> i think the following syntax would be quite beneficial to replace some >> redundant "if's" in python code. > > http://python.org/dev/peps/pep-3003/ I knew it wouldn't take long for people to start responding to any proposal with "don't bother, there's a moratorium". Of course in this case, the correct response would have been "don't bother, it's a stupid idea, moratorium or no moratorium". Hint to would-be language designers: if you start off by claiming that a new feature will save an indent level, when in fact it *doesn't* save an indent level, you can save yourself from embarrassment by pressing Close on your post instead of Send. -- Steven From invalid at invalid.invalid Tue Nov 10 22:39:54 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 11 Nov 2009 03:39:54 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-11, Steven D'Aprano wrote: > By all means criticize Apple for failing to foresee 32-bit > apps, but criticizing them for hypocrisy (in this matter) is > unfair. By the time they recognized the need for 32-bit clean > applications, they were stuck with a lot of legacy code that > were not clean. Including code burned into ROMs. They did manage to climb out of the hole they had dug and fix things up -- something Microsoft has yet to do after 25 years. Maybe it's finally going to be different this time around with Windows 7... -- Grant From phlip2005 at gmail.com Tue Nov 10 23:00:52 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:00:52 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <831422a4-bdaa-4be0-b448-7abf9bece3e6@2g2000prl.googlegroups.com> On Nov 10, 3:11?pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep I thought pip didn't do eggs. did I read a stale blog? > I hope this answers your questions :-D oooo we are so close! Pages like this... http://blog.ianbicking.org/2008/12/16/using-pip-requirements/ ...are answering the question "what if I have ten billion requirements?" I have one, Python. What's the simplest pip requirement file? I will post here if I figure it out first. From pavlovevidence at gmail.com Tue Nov 10 23:02:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 20:02:03 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 10, 11:23?am, r wrote: > if something_that_returns_value() as value: > ? ? #do something with value Been proposed before. No one has bothered to write a PEP for it, so I can't say for sure how the Python gods would react, but I suspect a "meh, don't think it's important enough". This, even though it's more useful than you are giving it credit for. It's a minor improvement. Carl Banks From pavlovevidence at gmail.com Tue Nov 10 23:13:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 20:13:21 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> On Nov 10, 7:12?pm, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > > r: > > >> i think the following syntax would be quite beneficial to replace some > >> redundant "if's" in python code. > > >http://python.org/dev/peps/pep-3003/ > > I knew it wouldn't take long for people to start responding to any > proposal with "don't bother, there's a moratorium". > > Of course in this case, the correct response would have been "don't > bother, it's a stupid idea, moratorium or no moratorium". r didn't actually give a good example. Here is case where it's actually useful. (Pretend the regexps are too complicated to be parsed with string method.) if re.match(r'go\s+(north|south|east|west)',cmd) as m: hero.move(m.group(1)) elif re.match(r'take\s+(\w+)',cmd) as m: hero.pick_up(m.group(1)) elif re.match(r'drop\s+(\w+)',cmd) as m: here.put_Down(m.group(1)) I wouldn't mind seeing this in Python for this exact use case, although I'd rather the syntax to be more like the following so that you can bind something other than the condition if need be. if m with m as re.match(regexp,command): Moot point for the next two years, and probably forever as I doubt it would ever happen. Carl Banks From rt8396 at gmail.com Tue Nov 10 23:23:03 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 20:23:03 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <0f547bb8-838e-4835-9216-ecd32fc711a1@n35g2000yqm.googlegroups.com> On Nov 10, 9:12?pm, Steven D'Aprano wrote: (..snip..) > Hint to would-be language designers: if you start off by claiming that a > new feature will save an indent level, when in fact it *doesn't* save an > indent level, you can save yourself from embarrassment by pressing Close > on your post instead of Send. Does anyone out there know the textual smiley for conveying an overwhelming feeling of embarrassment? Also may want to send the one for feeling of confusion too ;-) From phlip2005 at gmail.com Tue Nov 10 23:25:57 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:25:57 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: On Nov 10, 3:11?pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep > > I hope this answers your questions :-D Let me ask it like this. What happens when a user types..? sudo pip install repo Is github one of the default sites pip scans? If so, will it rip a requirements file in the root of repo.git? If so, what file name should that have? All the pages I'm reading start at the complex end of the requirements file concept. They don't seem to mention simple things like the name of the file, or how to lead pip to the file. From phlip2005 at gmail.com Tue Nov 10 23:35:47 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:35:47 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> <831422a4-bdaa-4be0-b448-7abf9bece3e6@2g2000prl.googlegroups.com> Message-ID: <90e132d9-1b16-45f8-89dc-d5a4eb7ebf21@f20g2000prn.googlegroups.com> > > -e git+git://example.com/repo.git#egg=rep Okay. -e is an argument to pip install. If anyone said that, I overlooked it. So, yes I can rip from github, just with a longer command line, for now. Tx! From SD_V897 at NoSuchMail.Com Tue Nov 10 23:51:38 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Wed, 11 Nov 2009 04:51:38 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: Rhodri James wrote: > On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 wrote: > No, I'm asking you -- or rather your admin user -- to invoke the program > that is giving you grief from the command line, i.e. "python > myscript.py", and tell me what happens. "It doesn't work" won't be > considered at all helpful; without details we might as well just print > out your script, throw darts at it, and tell you the problem is where > the darts land. > > The rest of your answer however suggests that I've fundamentally > misunderstood what you've said. Please tell me *exactly* what happens > when it doesn't "run fine" for your admin user. > I fixed it for some reason deleting my idlerc folder allows it to work again.. http://bugs.python.org/issue7206 Thanks everybody.. SD From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 00:37:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 05:37:13 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 20:13:21 -0800, Carl Banks wrote: > On Nov 10, 7:12?pm, Steven D'Aprano > wrote: >> On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: >> > r: >> >> >> i think the following syntax would be quite beneficial to replace >> >> some redundant "if's" in python code. >> >> >http://python.org/dev/peps/pep-3003/ >> >> I knew it wouldn't take long for people to start responding to any >> proposal with "don't bother, there's a moratorium". >> >> Of course in this case, the correct response would have been "don't >> bother, it's a stupid idea, moratorium or no moratorium". > > r didn't actually give a good example. Here is case where it's actually > useful. (Pretend the regexps are too complicated to be parsed with > string method.) > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > hero.move(m.group(1)) > elif re.match(r'take\s+(\w+)',cmd) as m: > hero.pick_up(m.group(1)) > elif re.match(r'drop\s+(\w+)',cmd) as m: > here.put_Down(m.group(1)) This is where a helper function is good. You want a dispatcher: COMMANDS = { r'go\s+(north|south|east|west)': hero.move, r'take\s+(\w+)': hero.pick_up, r'drop\s+(\w+)': here.put_Down, } def dispatch(cmd): for regex in COMMANDS: m = re.match(regex, cmd) if m: COMMANDS[regex](m.group(1)) break dispatch(cmd) If you need the regexes to be tested in a specific order, change the dict to an OrderedDict, or use a list of tuples and the obvious change to the for loop. -- Steven From tjreedy at udel.edu Wed Nov 11 00:44:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 00:44:55 -0500 Subject: New syntax for blocks In-Reply-To: <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: Carl Banks wrote: > > r didn't actually give a good example. Here is case where it's > actually useful. (Pretend the regexps are too complicated to be > parsed with string method.) > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > hero.move(m.group(1)) > elif re.match(r'take\s+(\w+)',cmd) as m: > hero.pick_up(m.group(1)) > elif re.match(r'drop\s+(\w+)',cmd) as m: > here.put_Down(m.group(1)) The effect of this proposal can already be accomplished with a 'pocket' class as has been posted before and again in a slightly different form in Steve's post. tjr From tjreedy at udel.edu Wed Nov 11 00:50:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 00:50:36 -0500 Subject: DHT for Python 3.x? In-Reply-To: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: Salim Fadhley wrote: > There are plenty of good DHT dihydrotestosterone? distributed hash table? DHT Maritime Inc.? DHT routing algorithm? D.H.T. the music group? digital home theater? (from first 20 Google hits) tjr From vmanis at telus.net Wed Nov 11 01:07:43 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 22:07:43 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> On 2009-11-10, at 19:07, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:05:01 -0800, Vincent Manis wrote: > That is incorrect. The original Inside Mac Volume 1 (published in 1985) > didn't look anything like a phone book. The original Macintosh's CPU (the > Motorola 68000) already used 32-bit addressing, but the high eight pins > were ignored since the CPU physically lacked the pins corresponding to > those bits. > > In fact, in Inside Mac Vol II, Apple explicitly gives the format of > pointers: the low-order three bytes are the address, the high-order byte > is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 > the resource bit. The other five bits were unused. You are correct. On thinking about it further, my source was some kind of internal developer seminar I attended round about 1985 or so, where an Apple person said `don't use the high order bits, we might someday produce machines that use all 32 address bits', and then winked at us. You are also correct (of course) about the original `Inside Mac', my copy was indeed 2 volumes in looseleaf binders; the phonebook came later. > By all means criticize Apple for failing to foresee 32-bit apps, but > criticizing them for hypocrisy (in this matter) is unfair. By the time > they recognized the need for 32-bit clean applications, they were stuck > with a lot of legacy code that were not clean. Including code burned into > ROMs. That's my point. I first heard about Moore's Law in 1974 from a talk given by Alan Kay. At about the same time, Gordon Bell had concluded, independently, that one needs extra address bit every 18 months (he was looking at core memory, so the cost factors were somewhat different). All of this should have suggested that relying on any `reserved' bits is always a bad idea. I am most definitely not faulting Apple for hypocrisy, just saying that programmers sometimes assume that just because something works on one machine, it will work forevermore. And that's unwise. -- v From sajmikins at gmail.com Wed Nov 11 01:12:41 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 11 Nov 2009 01:12:41 -0500 Subject: Calendar Stuff In-Reply-To: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Message-ID: <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi wrote: > Hi; > I have the following code: > > import calendar, datetime > > def cal(): > ? ... > ? myCal = calendar.Calendar(calendar.SUNDAY) > ? today = datetime.date.today() > ? day = today.day > ? mo = today.month > ? yr = today.year > #? month = myCal.monthdayscalendar(int(time.strftime("%Y")) > ? month = myCal.monthdayscalendar(yr, mo) > ? print 'hi' > > html headers are included. No matter which one of the last two lines I > comment out, I never get to the point of printing 'hi'. (If I comment them > both out, it does print.) What do? > TIA, > Victor Have you tried walking through the code line-by-line in the interactive interpreter? That should give you an idea of why those lines aren't working. Also, if your code never prints 'hi', what does it do instead? Hang? Or give you a traceback? From vmanis at telus.net Wed Nov 11 01:14:14 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 22:14:14 -0800 Subject: is None or == None ? In-Reply-To: <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> Message-ID: On 2009-11-10, at 22:07, Vincent Manis wrote: > On 2009-11-10, at 19:07, Steven D'Aprano wrote: >> In fact, in Inside Mac Vol II, Apple explicitly gives the format of >> pointers: the low-order three bytes are the address, the high-order byte >> is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 >> the resource bit. The other five bits were unused. I inadvertently must have deleted a paragraph in the response I just posted. Please add: The pointer format would have caused me to write macros or the like (that was still in the days when Apple liked Pascal) to hide the bit representation of pointers. -- v From martin at v.loewis.de Wed Nov 11 01:20:50 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 11 Nov 2009 07:20:50 +0100 Subject: DHT for Python 3.x? In-Reply-To: References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: <4AFA57C2.2000104@v.loewis.de> Terry Reedy wrote: > Salim Fadhley wrote: >> There are plenty of good DHT > distributed hash table? I think it's that one. Regards, Martin From rt8396 at gmail.com Wed Nov 11 02:00:09 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 23:00:09 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 10, 2:49?pm, steve wrote: (..snip..) > However, the same 'effect' can be obtained with the 'with' statement: (..snip..) Hardly!,Here is an interactive session with your test case #----------------------------------------------------------# >>> class something_that_returns_value: def __init__(self, x): # do something with x, self.value is what ought to be 'returned' self.value = x def __enter__(self): if self.value: return self.value else: return ValueError() def __exit__(self, type, value, traceback): return True >>> with something_that_returns_value(1) as value: print 'block' block >>> with something_that_returns_value(0) as value: print 'block' block >>> with something_that_returns_value(False) as value: print 'block' block >>> with something_that_returns_value([1,2,3]) as value: print 'block' block #----------------------------------------------------------# The block obviously executes every time no matter what value is returned from something_that_returns_value(*). The with statement is meant to only cleanup an exception in a "nice-clean-way" not to evaluate a variable assignment as evidenced by this simple testing of your code. If anything executes in the block following the "if" (when the assignment value is None) it undermines the whole reason for using the new syntax in the first place! I think what has escaped everyone (including myself until my second post) is the fact that what really needs to happen is for variable *assignments* to return a boolean to any "statements" that evaluate the assignment -- like in an "if" or "elif" construct. The current "with" statement cannot replace that action and was never meant for such things. if range(0) as var: #python will never execute even one line #in this block because bool(var) == None #also since bool(var) equals None, the #variable "var" will never be created! elif range(10) as var: #this block will execute and the variable "var" #will be added to appropriate namespace containing #a list of 10 ints var = 100 #var is still available in this namespace! Very clean, very elegant solution to a messy problem that pops up in python code quite often. It not only saves one distracting line of code per usage but makes the code more readable. If there is an existing solution, Steve's is not it. From ken at seehart.com Wed Nov 11 02:02:39 2009 From: ken at seehart.com (Ken Seehart) Date: Tue, 10 Nov 2009 23:02:39 -0800 Subject: Authentication session with urllib2 Message-ID: <4AFA618F.3030606@seehart.com> I'm having some difficulty implementing a client that needs to maintain an authenticated https: session. I'd like to avoid the approach of receiving a 401 and resubmit with authentication, for two reasons: 1. I control the server, and it was easy for me to make a url that receives a POST with username, password and authenticates the session. The server keeps a session correctly when I test with a browser. This part works fine. 2. I don't want to send every request twice. See http://bugs.python.org/issue7159 There's no reason why I should have to do this since I have the ability to keep the server simple. What I would really like to do is send one request with the username and password to establish the session, and then make multiple authenticated requests where the session information remembers the authentication. Is there a way to make this happen in python 2.5.2? Keep in mind that this only needs to work with a particular server which I control. It does not need to function as a general purpose browser. The server is powered by Django. - Ken From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 02:25:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 07:25:35 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 23:00:09 -0800, r wrote: > I think what has escaped everyone (including myself until my second > post) is the fact that what really needs to happen Why? > is for variable > *assignments* to return a boolean to any "statements" that evaluate the > assignment -- like in an "if" or "elif" construct. I don't even understand what that means. > The current "with" > statement cannot replace that action and was never meant for such > things. > > if range(0) as var: > #python will never execute even one line > #in this block because bool(var) == None No, that's impossible. bool() always returns True or False, not None. > #also since bool(var) equals None, the Incorrect. >>> True == None False >>> False == None False > #variable "var" will never be created! That will cause no end of trouble. if range(N) as var: do_something_with_var() if var: print "Oops, this blows up if N <= 0" Conditional assignments are a terrible idea. > elif range(10) as var: > #this block will execute and the variable "var" > #will be added to appropriate namespace containing > #a list of 10 ints > > var = 100 #var is still available in this namespace! > > > Very clean, very elegant solution to a messy problem that pops up in > python code quite often. You haven't actually explained what the messy problem is. var = range(N) if var: ... is not a messy problem. It's perfectly reasonable. If you need to do two things with a value, you assign it to a name first: var = range(N) p = var.index(5) var.append(42) x = func(10) y = x + 1 z = x*2 x = func(10) if x: y = x + 1 Why is the third example, with an if... test, so special that it needs special syntax to make it a two-liner? Would you suggest we can write this? # instead of var = range(N) p = range(N).index(5) as var # var might be range(N), or undefined. var.append(42) > It not only saves one distracting line of code > per usage but makes the code more readable. What distracting line of code? -- Steven From rt8396 at gmail.com Wed Nov 11 03:08:58 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 00:08:58 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 11, 1:25?am, Steven D'Aprano wrote: (snip) > Incorrect. > >>> True == None > False > >>> False == None > False Of course i meant True/False but my fingers were thinking None at the time. And besides if i don't make a mistake here or there what ever would you do with your time? ;-) Seven += 1 > > ? ?#variable "var" will never be created! > That will cause no end of trouble. > if range(N) as var: > ? ? do_something_with_var() > if var: > ? ? print "Oops, this blows up if N <= 0" > Conditional assignments are a terrible idea. Yea it's called a NameError. Would it not also blow up in the current state of syntax usage? if var: print 'var' Traceback (most recent call last): File "", line 1, in if var: NameError: name 'var' is not defined Steven -= 1 > Why is the third example, with an if... test, so special that it needs > special syntax to make it a two-liner? ...because Beautiful is better than ugly. > Would you suggest we can write this? > # instead of var = range(N) > p = range(N).index(5) as var ?# var might be range(N), or undefined. > var.append(42) No if you read my post my usage of this syntax only includes "if" and "elif" constructs and nothing "else" because usage outside of such a "truth-seeking" construct is pointless. print Steven -> 0 Hmm, just as i suspected. From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 03:37:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 08:37:35 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: >> > ? ?#variable "var" will never be created! >> That will cause no end of trouble. >> if range(N) as var: >> ? ? do_something_with_var() >> if var: >> ? ? print "Oops, this blows up if N <= 0" >> Conditional assignments are a terrible idea. > > Yea it's called a NameError. Would it not also blow up in the current > state of syntax usage? No. > if var: > print 'var' > > Traceback (most recent call last): > File "", line 1, in > if var: > NameError: name 'var' is not defined You missed a line: var = range(N) if var: ... The problem isn't the if statement, it is the conditional assignment. Sometimes "x as y" creates y, sometimes it doesn't, according to some mysterious rule something to do without whether the assignment is true or false, whatever that means. >> Why is the third example, with an if... test, so special that it needs >> special syntax to make it a two-liner? > > ...because Beautiful is better than ugly. I can quote the Zen too: Special cases aren't special enough to break the rules. You haven't demonstrated that your construct is "beautiful", or the existing way of writing it is "ugly". # apparently not ugly x = func() y = x + 1 z = 2*x # also not ugly var = range(N) var.append(42) find(23, var) # still not ugly var = range(N) for x in var: do_something_with(x, var) # not ugly var = MyClass() with var.magic as x: process(var) # why is this ugly? var = range(N) if var: process(var) >> Would you suggest we can write this? >> # instead of var = range(N) >> p = range(N).index(5) as var ?# var might be range(N), or undefined. >> var.append(42) > > No if you read my post my usage of this syntax only includes "if" and > "elif" constructs and nothing "else" because usage outside of such a > "truth-seeking" construct is pointless. What's so special about "truth-seeking"? for x in range(N) as var: do_something_with(x, var) That would save a line too, it would behave exactly as you specified, and it uses virtually the identical syntax: "expr as name". -- Steven From gatti at dsdata.it Wed Nov 11 03:48:26 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Wed, 11 Nov 2009 00:48:26 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On Nov 10, 11:08?pm, Simon Hibbs wrote: > Since QT runs on Windows, > porting to the Windows version of QT shouldn't be hard. The PySide developers, who are better judges of their own project than you and me, consider a Windows port so hard (and time consuming) that they didn't even try; a second iteration of the already working binding generator has a higher priority than supporting a large portion of the potential user base with a Windows port, so don't hold your breath. On a more constructive note, I started to follow the instructions at http://www.pyside.org/docs/pyside/howto-build/index.html (which are vague and terse enough to be cross-platform) with Microsoft VC9 Express. Hurdle 0: recompile Qt because the provided DLLs have hardcoded wrong paths that confuse CMake. How should Qt be configured? My first compilation attempt had to be aborted (and couldn't be resumed) after about 2 hours: trial and error at 1-2 builds per day could take weeks. Regards, Lorenzo Gatti From wentland at cl.uni-heidelberg.de Wed Nov 11 04:25:05 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Wed, 11 Nov 2009 10:25:05 +0100 Subject: how to create a pip package In-Reply-To: References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <20091111092505.GA29290@kinakuta.local> On Tue, Nov 10, 2009 at 20:25 -0800, Phlip wrote: > On Nov 10, 3:11?pm, Wolodja Wentland > wrote: > > > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep > Let me ask it like this. What happens when a user types..? > sudo pip install repo pip will check for 'repo' on pypi, find nothing and stop processing. > Is github one of the default sites pip scans? No. > If so, will it rip a requirements file in the root of repo.git? No. >If so, what file name should that have? You can choose any name you like. I think I have to explain a bit more. The requirement file is basically a list of *all installed distributions* in a Python environment and is usually created by 'pip freeze'. It is merely a way to tell pip later which distributions it should try to install. The basic way of working with requirement files if this: 1. Create virtual environment [1] 2. Install *your* package and all of its dependencies within the virtual environment 3. Run 'pip freeze' to get the list of installed distributions and write it to a file. This file is the requirement file. 4. Give the requirement file to someone else 5. Create a virtual environment 6. Run 'pip install -r requirement_file.txt' to install all distributions 'frozen' in the requirements file 7. PROFIT!!! A requirements file is not really meant to state the dependencies of a single distribution, but rather describe the complete state an environment is in *so it can be reconstructed later* exactly like is has been before. This is quite important if you want to deploy application and you want to make sure that only tested versions of you dependency get installed. I think of it rather in the terms of: pip freeze --> dpkg --get-selections pip install -r r.txt --> dpkg --set-selections aptitude install AFAIK you can also host the distribution on another site than pypi, but I am not sure how to tell pip to check there for distributions as well. You might want to ask this on the virtualenv list. -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From greg at cosc.canterbury.ac.nz Wed Nov 11 04:32:30 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 11 Nov 2009 22:32:30 +1300 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <7lvelqF3f3bq7U1@mid.individual.net> Vincent Manis wrote: > That's my point. I first heard about Moore's Law in 1974 from a talk given > by Alan Kay. At about the same time, Gordon Bell had concluded, independently, > that one needs extra address bit every 18 months Hmmm. At that rate, we'll use up the extra 32 bits in our 64 bit pointers in another 48 years. So 128-bit machines ought to be making an appearance around about 2057, and then we'll be all set until 2153 -- if we're still using anything as quaintly old-fashioned as binary memory addresses by then... -- Greg From rpjday at crashcourse.ca Wed Nov 11 04:57:28 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Wed, 11 Nov 2009 04:57:28 -0500 (EST) Subject: python simply not scaleable enough for google? Message-ID: http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 thoughts? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 05:06:32 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 11:06:32 +0100 Subject: YIELD_VALUE Byte Code Message-ID: <1257933992.2784.16.camel@laptop> Hi, I am not sure if this is the right newsgroup, so if not don't hesitate to tell me. I am developed a Python to C compiler, so that Byte Code files automatically can be translated into C Extension Modules. (And it works pretty well --> http://www.coremountains.com/products/bytecoat/) While developing, I found something strange concerning the YIELD_VALUE OpCode. Since Python Version 2.5 it behaves the following: 1. pop yield value from stack and return it to a former gen_send_ex() call from Objects/genobject.c 2. push the yield value on the stack in gen_send_ex() and return it 3. when the generator is executed again, the yield value is 'poped' from the stack again with the POP_TOP opcode Now I found that a little strange: 1. why is the value removed from the stack, than pushed on the stack to remove it finally again? the combination of YIELD_VALUE and TOP_POP seems hard coded in compile.c which means that a TOP_POP follows every YIELD_VALUE TOP_POP 2. If the semantic of the YIELD_VALUE OpCode has changed, why is this reached by using another function? Such thing should be done in the OpCode. (e.a.: instead of retval = POP() --> retval = TOP(); Py_INCREF(retval); ) I am a little confused about this. Best, Andreas From rt8396 at gmail.com Wed Nov 11 05:50:37 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 02:50:37 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> On Nov 11, 2:37?am, Steven D'Aprano wrote: > On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: > > Yea it's called a NameError. Would it not also blow up in the current > > state of syntax usage? > > No. > > > if var: > > ? ? print 'var' > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? ? if var: > > NameError: name 'var' is not defined > > You missed a line: > > var = range(N) > if var: Oh i get it now! If i assign a valid value to a variable the variable is also valid...thats...thats... GENUIS! *sarcasm* > The problem isn't the if statement, it is the conditional assignment. > Sometimes "x as y" creates y, sometimes it doesn't, according to some > mysterious rule something to do without whether the assignment is true or > false, whatever that means. i don't find True or False, Black or White, 1 or 0, Alpha or Omega to be mysterious...? If you still cannot grasp this simple concept then i fear i may not be able to help you understand Steven. (snip: excessive inane blubbering) > > No if you read my post my usage of this syntax only includes "if" and > > "elif" constructs and nothing "else" because usage outside of such a > > "truth-seeking" construct is pointless. > > What's so special about "truth-seeking"? > > for x in range(N) as var: > ? ? do_something_with(x, var) You could do that but why would you want to. A "for x in range(N)" is just so you can loop N times. And since changing the values in a list whilst looping over it is the sport of fools then what usefulness would a variable be for such a construct? You have failed to prove the usefulness of this syntax Steven. I suggest you go back and read over my posts again and then marinate on the contents for a while. THEN come back with an argument based in reality and we will try again...You know at one time i actually considered you a formidable foe, well these times they are a chang'in right Dylan? From rpurdie at rpsys.net Wed Nov 11 05:59:46 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 10:59:46 +0000 Subject: Unexpected python exception Message-ID: <1257937186.29038.305.camel@dax.rpnet.com> I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A(): import __builtin__ import os __builtin__.os = os def B(): os.stat("/") import os A() B() which results in: Traceback (most recent call last): File "./test.py", line 12, in B() File "./test.py", line 8, in B os.stat("/") UnboundLocalError: local variable 'os' referenced before assignment If I remove the "import os" from B(), it works as expected. >From what I've seen, its very unusual to have something operate "backwards" in scope in python. Can anyone explain why this happens? Cheers, Richard From deets at nospam.web.de Wed Nov 11 06:21:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 12:21:55 +0100 Subject: Unexpected python exception In-Reply-To: References: Message-ID: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Richard Purdie schrieb: > I've been having problems with an unexpected exception from python which > I can summarise with the following testcase: > > def A(): > import __builtin__ > import os > > __builtin__.os = os > > def B(): > os.stat("/") > import os > > A() > B() > > which results in: > > Traceback (most recent call last): > File "./test.py", line 12, in > B() > File "./test.py", line 8, in B > os.stat("/") > UnboundLocalError: local variable 'os' referenced before assignment > > If I remove the "import os" from B(), it works as expected. > >>From what I've seen, its very unusual to have something operate > "backwards" in scope in python. Can anyone explain why this happens? As the import-statement in a function/method-scope doesn't leak the imported names into the module scope, python treats them as locals. Which makes your code equivalent to x = 1000 def foo(): print x x = 10 Throws the same error. The remedy is to inform python that a specific name belongs to global scope, using the "global"-statement. def foo(): global x print x x = 10 Beware though that then of course *assigning* to x is on global level. This shouldn't be of any difference in your case though, because of the import-only-once-mechanics of python. Diez From hugo.leveille at visionglobale.com Wed Nov 11 06:25:04 2009 From: hugo.leveille at visionglobale.com (=?iso-8859-1?Q?Hugo_L=E9veill=E9?=) Date: Wed, 11 Nov 2009 06:25:04 -0500 Subject: Knob label justification Message-ID: By default, a boolean knob has the text label on the right. How can I make it on the left? thx -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 06:25:53 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 12:25:53 +0100 Subject: Unexpected python exception In-Reply-To: References: Message-ID: <1257938753.11260.6.camel@laptop> Hi, unfortunatley I cannot reproduce your error. Which Python Version do you use? The expected case in this scenario is that the exception is thrown, as you import os in A() where it is stored in the local namespace of the function. I tested it with Python 2.4, 2.5 and 2.6 and in both cases an exception is thrown. Best, Andreas From pavlovevidence at gmail.com Wed Nov 11 06:52:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 03:52:45 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 10, 9:37?pm, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 20:13:21 -0800, Carl Banks wrote: > > On Nov 10, 7:12?pm, Steven D'Aprano > > wrote: > >> On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > >> > r: > > >> >> i think the following syntax would be quite beneficial to replace > >> >> some redundant "if's" in python code. > > >> >http://python.org/dev/peps/pep-3003/ > > >> I knew it wouldn't take long for people to start responding to any > >> proposal with "don't bother, there's a moratorium". > > >> Of course in this case, the correct response would have been "don't > >> bother, it's a stupid idea, moratorium or no moratorium". > > > r didn't actually give a good example. ?Here is case where it's actually > > useful. ?(Pretend the regexps are too complicated to be parsed with > > string method.) > > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > > ? ? hero.move(m.group(1)) > > elif re.match(r'take\s+(\w+)',cmd) as m: > > ? ? hero.pick_up(m.group(1)) > > elif re.match(r'drop\s+(\w+)',cmd) as m: > > ? ? here.put_Down(m.group(1)) > > This is where a helper function is good. You want a dispatcher: No I really don't. I want to be able to see the action performed adjacent to the test, and not have to scroll up to down ten pages to find whatever function it dispatched to. Carl Banks From alfps at start.no Wed Nov 11 06:57:09 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 11 Nov 2009 12:57:09 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: References: Message-ID: * Alf P. Steinbach: > Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > It's now Python 3.x, and reworked with lots of graphical examples and > more explanatory text, plus limited in scope to Basic Concepts (which I > previously just had as a first ch 2 section -- but there's rather a > lot of concepts!). > > I think it's wise to invite comments even when it's not 100% completed. > First, because as opposed to ch 1 there is quite a bit of code here, and > since I'm a Python newbie I may be using non-idiomatic constructs, not > to mention doing worse things. :-) Second, because comments in general > can improve the text. > > > Contents: > > 2.1 Super-basic concept: why programming is not DWIM. 1 > 2.2 Reported errors. 4 > 2.2.1 Case-sensitity. 4 > 2.2.2 Syntax / compilation errors. 4 > 2.2.3 Runtime errors / crashes. 5 > 2.3 A programming exploration tool: turtle graphics. 6 > 2.4 Naming things. 8 > 2.4.1 Naming actions: routines. 8 > 2.4.2 Naming data part I: variables. 11 > 2.4.3 Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. 14 > 2.5.1 Repeating actions automatically: loops. 14 > 2.5.2 Basic comparisions & boolean values. 16 > 2.5.3 Interlude I: a function graph program / about types. 17 > 2.5.4 Automated action choices. 21 > 2.5.5 Value-producing (function-like) routines. 23 > 2.5.6 Interlude II: a graph with zeroes marked / about program > structure. 26 > 2.5.7 Dynamically nested actions: recursive routines. 28 > 2.6 Objects. [Not started on this] 31 > 2.7 Collections. [Not started on this] 31 > > > In Google Docs (both chapters available here): > > > Formats: PDF Added discussion and examples of C curve and dragon curve to section 2.5.7 on recursive routines. Enjoy. :-) I'm especially interested in comments from novices/newbies. E.g., is something unclear or hard to understand, or is it all as clear as military pea soup? Cheers, - Alf From pavlovevidence at gmail.com Wed Nov 11 07:00:09 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 04:00:09 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 10, 9:44?pm, Terry Reedy wrote: > Carl Banks wrote: > > > r didn't actually give a good example. ?Here is case where it's > > actually useful. ?(Pretend the regexps are too complicated to be > > parsed with string method.) > > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > > ? ? hero.move(m.group(1)) > > elif re.match(r'take\s+(\w+)',cmd) as m: > > ? ? hero.pick_up(m.group(1)) > > elif re.match(r'drop\s+(\w+)',cmd) as m: > > ? ? here.put_Down(m.group(1)) > > The effect of this proposal can already be accomplished with a 'pocket' > class Nice metaphorical name. > as has been posted before and again in a slightly different form > in Steve's post. I'm well aware of it, but I didn't think the proposal deserved to be called stupid when it was a reasonable solution to a real need, even though a workable and less intrusive option exists. Carl Banks From daniel.jowett at gmail.com Wed Nov 11 07:16:22 2009 From: daniel.jowett at gmail.com (Daniel Jowett) Date: Wed, 11 Nov 2009 12:16:22 +0000 Subject: Basic list/dictionary question Message-ID: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Greetings, I'm trying to categorize items in a list, by copying them into a dictionary... A simple example with strings doesn't seem to work how I'd expect: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> d = {} >>> d = d.fromkeys(basket, []) >>> d {'orange': [], 'pear': [], 'apple': [], 'banana': []} >>> for fruit in basket: ... d[fruit].append(fruit) ... No if I print d I'd EXPECT.... >>> d {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', 'apple'], 'banana': ['banana']} But what I GET is.... >>> d {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']} >>> >From what I can work out, there is only ONE list that is referenced from the dictionary 4 times. Which would be because the *same empty list* is assigned to every key in the dictionary by the "fromkeys" line. But that seems *seriously *counter-intuitive to me... Would anyone beg to differ and try to rewire my thinking? (I'm from a Java background if that helps) I've already solved the problem a different way, but I am concerned about this counter-intuitiveness as I see it. rgds, Daniel Jowett -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 11 07:20:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:20:24 -0800 Subject: Knob label justification In-Reply-To: References: Message-ID: <50697b2c0911110420l9aab83bpb736f28927307369@mail.gmail.com> On Wed, Nov 11, 2009 at 3:25 AM, Hugo L?veill? wrote: > By default, a boolean knob has the text label on the right. How can I make > it on the left? We're not mind readers. We'll need to know which GUI toolkit you're using. Cheers, Chris -- http://blog.rebertia.com From hugo.leveille at visionglobale.com Wed Nov 11 07:21:48 2009 From: hugo.leveille at visionglobale.com (Hugo Leveille) Date: Wed, 11 Nov 2009 07:21:48 -0500 Subject: Knob label justification In-Reply-To: <50697b2c0911110420l9aab83bpb736f28927307369@mail.gmail.com> Message-ID: Sorry, Im using the PythonPanel module of nuke. On 11/11/09 7:20 AM, "Chris Rebert" wrote: > On Wed, Nov 11, 2009 at 3:25 AM, Hugo L?veill? > wrote: >> By default, a boolean knob has the text label on the right. How can I make >> it on the left? > > We're not mind readers. We'll need to know which GUI toolkit you're using. > > Cheers, > Chris > -- > http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 11 07:23:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:23:18 -0800 Subject: Unexpected python exception In-Reply-To: <200911110849.02346.lenz@joinville.udesc.br> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <200911110849.02346.lenz@joinville.udesc.br> Message-ID: <50697b2c0911110423g71b11853wf0fd9b582b23d4cd@mail.gmail.com> On Wed, Nov 11, 2009 at 8:49 AM, Eduardo Lenz wrote: > Em Qua 11 Nov 2009, ?s 03:21:55, Diez B. Roggisch escreveu: >> Richard Purdie schrieb: >> > I've been having problems with an unexpected exception from python which >> > I can summarise with the following testcase: >> > >> > def A(): >> > ? ? import __builtin__ >> > ? ? import os >> > >> > ? ? __builtin__.os = os >> > >> > def B(): >> > ? ? os.stat("/") >> > ? ? import os >> > >> > A() >> > B() >> > >> > which results in: >> > >> > Traceback (most recent call last): >> > ? File "./test.py", line 12, in >> > ? ? B() >> > ? File "./test.py", line 8, in B >> > ? ? os.stat("/") >> > UnboundLocalError: local variable 'os' referenced before assignment >> > >> > If I remove the "import os" from B(), it works as expected. >> > >> >>From what I've seen, its very unusual to have something operate >> > >> > "backwards" in scope in python. Can anyone explain why this happens? >> >> As the import-statement in a function/method-scope doesn't leak the >> imported names into the module scope, python treats them as locals. >> Which makes your code equivalent to >> >> >> x = 1000 >> >> def foo(): >> ? ? ?print x >> ? ? ?x = 10 >> >> Throws the same error. The remedy is to inform python that a specific >> name belongs to global scope, using the "global"-statement. >> >> def foo(): >> ? ? ?global x >> ? ? ?print x >> ? ? ?x = 10 >> >> >> Beware though that then of course *assigning* to x is on global level. >> This shouldn't be of any difference in your case though, because of the >> import-only-once-mechanics of python. >> >> Diez >> > > So...it should not work > > def A(): > ? ? import __builtin__ > ? ? import os > ? ? __builtin__.os = os > > A() > os.stat("/") > > but it does. ?Why ? B() cannot see the import, but the global level can ? The optimization which results in the behavior in question is only done on functions scopes, not global scope. Cheers, Chris -- http://blog.rebertia.com From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 07:23:30 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 13:23:30 +0100 Subject: Unexpected python exception In-Reply-To: References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <1257942210.14502.3.camel@laptop> Python searches for Variables not only in local or global scoop but also in __builtins__. If you do something like __builtins__.os = os, than this variable should be accessible global. If you then write something like: def B(): os.stat("/") import os Python recognises on compile time, that os is a local variable in B and allocates memory for it. All reading or writing now goes to the local variable and not the one in __builtins__. And the local variable has never been assigned to a value and an Exception is thrown. Best From rpurdie at rpsys.net Wed Nov 11 07:37:04 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 12:37:04 +0000 Subject: Unexpected python exception In-Reply-To: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <1257943024.29038.379.camel@dax.rpnet.com> On Wed, 2009-11-11 at 12:21 +0100, Diez B. Roggisch wrote: > As the import-statement in a function/method-scope doesn't leak the > imported names into the module scope, python treats them as locals. > Which makes your code equivalent to > > > x = 1000 > > def foo(): > print x > x = 10 Aha, thanks. This makes it clear whats happening. > Throws the same error. The remedy is to inform python that a specific > name belongs to global scope, using the "global"-statement. > > def foo(): > global x > print x > x = 10 > > > Beware though that then of course *assigning* to x is on global level. > This shouldn't be of any difference in your case though, because of the > import-only-once-mechanics of python. Is there a way to make the "global x" apply to all functions without adding it to each one? I suspect this equates to intentionally "leaking the imported names into the module scope"? :) What I'm trying to do is to avoid having "import X" statements everywhere by changing __builtin__. It seems my approach doesn't have quite the same effect as a true import though. Cheers, Richard From bbxx789_05ss at yahoo.com Wed Nov 11 07:49:48 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 04:49:48 -0800 (PST) Subject: installing lxml ? Message-ID: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> I'm trying to install lxml, but I can't figure out the installation instructions. Here: http://codespeak.net/lxml/installation.html it says: 1) Get the easy_install tool. Ok, I went to the easy_install website, downloaded, and installed it. The last two lines of the output during installation said this: Installing easy_install script to /Library/Frameworks/Python.framework/ Versions/2.6/bin Installing easy_install-2.6 script to /Library/Frameworks/ Python.framework/Versions/2.6/bin 2) ...run the following as super-user (or administrator): easy_install lxml On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to easy_install like this: easy_install lxml==2.2.2 On Linux (and most other well-behaved operating systems), easy_install will manage to build the source distribution as long as libxml2 and libxslt are properly installed, including development packages, i.e. header files, etc. Use your package management tool to look for packages like libxml2-dev or libxslt-devel if the build fails, and make sure they are installed. On MacOS-X, use the following to build the source distribution, and make sure you have a working Internet connection, as this will download libxml2 and libxslt in order to build them: STATIC_DEPS=true easy_install lxml ----------- My os is mac os x 10.4.11. But this: STATIC_DEPS=true easy_install lxml is not a valid command: $ sudo STATIC_DEPS=true easy_install lxml Password: sudo: STATIC_DEPS=true: command not found In any case, if I do this: $ sudo easy_install lxml sudo: easy_install: command not found In other words, when I installed easy_install it did not add anything to my PATH which points to the installation directory mentioned during installation: Installing easy_install script to /Library/Frameworks/Python.framework/ Versions/2.6/bin Ok, so I need to use the full path to the easy_install program (which is not mentioned ANYWHERE in the installation instructions), i.e. /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install ...but this still isn't going to work: $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: sudo: STATIC_DEPS=true: command not found So what the heck is going on?? Attention developers: you may be one of the best programmers in the world, but if you can't convey how to use your software to the average user, then you are the equivalent of one of the worst programmers on the planet. From mark.leander at topicbranch.net Wed Nov 11 07:52:11 2009 From: mark.leander at topicbranch.net (Mark Leander) Date: Wed, 11 Nov 2009 04:52:11 -0800 (PST) Subject: Microsoft research on code quality References: Message-ID: > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx Thanks for the link! Hope he next takes on verifying that less code implies less bugs when other factors are constant, thus proving that Python is better than C and Java :-). Mark From joncle at googlemail.com Wed Nov 11 07:55:46 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 11 Nov 2009 04:55:46 -0800 (PST) Subject: Authentication session with urllib2 References: Message-ID: On 11 Nov, 07:02, Ken Seehart wrote: > I'm having some difficulty implementing a client that needs to maintain > an authenticated https: session. > > I'd like to avoid the approach of receiving a 401 and resubmit with > authentication, for two reasons: > > 1. I control the server, and it was easy for me to make a url that > receives a POST with username, password and authenticates the session. ? > The server keeps a session correctly when I test with a browser. ?This > part works fine. > > 2. I don't want to send every request twice. ?Seehttp://bugs.python.org/issue7159?There's no reason why I should have to > do this since I have the ability to keep the server simple. > > What I would really like to do is send one request with the username and > password to establish the session, and then make multiple authenticated > requests where the session information remembers the authentication. > > Is there a way to make this happen in python 2.5.2? > > Keep in mind that this only needs to work with a particular server which > I control. ?It does not need to function as a general purpose browser. ? > The server is powered by Django. > > - Ken How about http://docs.djangoproject.com/en/dev/topics/auth/ and using a urllib2 opener with cookie support ala some examples on http://personalpages.tds.net/~kent37/kk/00010.html ? hth, Jon. From clp2 at rebertia.com Wed Nov 11 07:58:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:58:55 -0800 Subject: Basic list/dictionary question In-Reply-To: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Message-ID: <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett wrote: > Greetings, > > I'm trying to categorize items in a list, by copying them into a > dictionary... > A simple example with strings doesn't seem to work how I'd expect: > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>>> d = {} >>>> d = d.fromkeys(basket, []) >>>> d > {'orange': [], 'pear': [], 'apple': [], 'banana': []} >>>> for fruit in basket: > ...???? d[fruit].append(fruit) > ... > > No if I print d I'd EXPECT.... >>>> d > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > 'apple'], 'banana': ['banana']} > > But what I GET is.... >>>> d > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > 'orange', 'apple', 'pear', 'orange', 'banana']} >>>> > > From what I can work out, there is only ONE list that is referenced from the > dictionary 4 times. Which would be because the same empty list is assigned > to every key in the dictionary by the "fromkeys" line. But that seems > seriously counter-intuitive to me... Python doesn't do any extra copying in most places unless you /explicitly/ do so yourself or ask it to; so yes, in this case, Python just copies references to the same object and does not copy the object itself. You'd probably be better off using a defaultdict in your particular usecase: http://docs.python.org/library/collections.html#collections.defaultdict Or and so you avoid running into it, default argument values aren't copied either: In [2]: def foo(z, a=[]): ...: a.append(z) ...: return a ...: In [3]: foo(1) Out[3]: [1] In [4]: foo(2) Out[4]: [1, 2] In [5]: foo(2) Out[5]: [1, 2, 2] In [6]: foo(3) Out[6]: [1, 2, 2, 3] In [7]: foo(4,[]) Out[7]: [4] In [8]: foo(5) Out[8]: [1, 2, 2, 3, 5] Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 11 08:04:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 05:04:57 -0800 Subject: Unexpected python exception In-Reply-To: <1257943024.29038.379.camel@dax.rpnet.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> Message-ID: <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: > Is there a way to make the "global x" apply to all functions without > adding it to each one? Thankfully, no. > What I'm trying to do is to avoid having "import X" statements > everywhere by changing __builtin__. It seems my approach doesn't have > quite the same effect as a true import though. And you can't just put all your imports together at the top of the file because...? If you're importing the same stuff across multiple modules, I'd say you have a code smell on your hands. Injecting stuff into the builtin namespace purely for convenience's sake is Just Evil (tm). At the least, you can put all the imports in one module and then use `from all_imports import *`, which is just slightly less evil. Cheers, Chris -- http://blog.rebertia.com From steve at lonetwin.net Wed Nov 11 08:10:03 2009 From: steve at lonetwin.net (steve) Date: Wed, 11 Nov 2009 18:40:03 +0530 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <4AFAB7AB.2040309@lonetwin.net> Hi, On 11/11/2009 12:30 PM, r wrote: > [...snip...] > I think what has escaped everyone (including myself until my second > post) is the fact that what really needs to happen is for variable > *assignments* to return a boolean to any "statements" that evaluate > the assignment -- like in an "if" or "elif" construct. The current > "with" statement cannot replace that action and was never meant for > such things. > True. It escaped me too that the assignment was happening and I was only relying on the side-effect to break out of the with statement. So, I'm sorry. > > Very clean, very elegant solution to a messy problem that pops up in > python code quite often. It not only saves one distracting line of > code per usage but makes the code more readable. If there is an > existing solution, Steve's is not it. However, if it is /only/ about saving that one 'distracting' line of the final code that you are concerned about (which I think is the case), how about: ----------------------------------------------------- def deco(f): def assign(x): if x: globals()['value'] = f(x) return True else: globals()['value'] = False return assign @deco def something_that_returns_value(x): # do something with x and return a value return x if something_that_returns_value(1) and value: print value if something_that_returns_value(0) and value: print value # or if you cannot decorate something_that_returns_value in it's definition # for instance, a method from another module, then ... if deco(something_that_returns_value)(0) and value: print value # Note that we've just siphoned off the assignment elsewhere. One problem # tho' is, irrespective of the conditional code being entered 'value' would # be initialized, which is what your ... # # if something_that_returns_value(x) as value: # # ... would also have done (if such a thing existed). # To avoid this side effect we could also do: if (something_that_returns_value(0) and value) or globals().pop('value'): print value # ...but that is beginning to look too much like the perl. Well, that's all i could think of to overcome one line of extra code. cheers, - steve -- random non tech spiel: http://lonetwin.blogspot.com/ tech randomness: http://lonehacks.blogspot.com/ what i'm stumbling into: http://lonetwin.stumbleupon.com/ From samwyse at gmail.com Wed Nov 11 08:11:21 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:11:21 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <992a972d-15fb-48bc-b019-f931a9aa59b3@a32g2000yqm.googlegroups.com> On Nov 10, 1:23?pm, r wrote: > Forgive me if i don't properly explain the problem but i think the > following syntax would be quite beneficial to replace some redundant > "if's" in python code. > > if something_that_returns_value() as value: > ? ? #do something with value > > # Which can replace the following syntactical construct... > > value = something_that_returns_value() > if value: > ? ? #do something with value I don't like the proposed syntax. I know, it's copied from the "with" statement, but it makes the assignment look like an afterthought. Plus, it's not good English when read aloud. If you want something useful, wait two years for the moratorium to expire and then figure out how to augment the "for" statement with an "if" clause, as is currently done in comprehensions. In other words, instead of this: "for" target_list "in" expression_list ":" suite let's have this: "for" target_list "in" expression_list [ "if" expression_nocond ] ":" suite You don't save much typing, but you really do save one indention level. OTOH, I can see the use of an else-clause following the 'for' as being even more confusing to anyone new to the language. And there's also the fact that an expression_list consists of conditional_expressions, which potentially use "if". You could probably get the parser to figure it out based on the presence of the "else" clause, but it wouldn't be easy. From rt8396 at gmail.com Wed Nov 11 08:11:28 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 05:11:28 -0800 (PST) Subject: Microsoft research on code quality References: <76d705f7-457d-41a1-90d0-714d860da735@r5g2000yqb.googlegroups.com> Message-ID: <55f3f2c8-5d77-4bf0-96e3-72a6e4445ee2@m26g2000yqb.googlegroups.com> On Nov 7, 5:22?pm, Mensanator wrote: > Microsoft has more to answer for for the fuckups they install > deliberately than for the bugs that get in accidentally. Here!, Here! Very well put Mensanator! From clp2 at rebertia.com Wed Nov 11 08:12:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 05:12:40 -0800 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <50697b2c0911110512q3453c30do3a4719dd1fa25151@mail.gmail.com> On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: > I'm trying to install lxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > My os is mac os x 10.4.11. I would recommend installing fink (http://www.finkproject.org/) and then `sudo fink install setuptools-py26`. As a bonus, you'll get a more up-to-date Python installed separate from the system one (so you don't need to worry about hosing it). Cheers, Chris -- http://blog.rebertia.com From daniel.jowett at gmail.com Wed Nov 11 08:15:59 2009 From: daniel.jowett at gmail.com (Daniel Jowett) Date: Wed, 11 Nov 2009 13:15:59 +0000 Subject: Basic list/dictionary question In-Reply-To: <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> Message-ID: <1119af330911110515r6d388f65u3271b2824fa8bc44@mail.gmail.com> Thanks Chris, yes it's becoming clearer now. And defaultdict looks nice - unfortunately I'm stuck to python 2.4 as I'm using Plone. Thanks again, Daniel 2009/11/11 Chris Rebert > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett > wrote: > > Greetings, > > > > I'm trying to categorize items in a list, by copying them into a > > dictionary... > > A simple example with strings doesn't seem to work how I'd expect: > > > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] > >>>> d = {} > >>>> d = d.fromkeys(basket, []) > >>>> d > > {'orange': [], 'pear': [], 'apple': [], 'banana': []} > >>>> for fruit in basket: > > ... d[fruit].append(fruit) > > ... > > > > No if I print d I'd EXPECT.... > >>>> d > > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > > 'apple'], 'banana': ['banana']} > > > > But what I GET is.... > >>>> d > > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], > 'pear': > > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': > ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana']} > >>>> > > > > From what I can work out, there is only ONE list that is referenced from > the > > dictionary 4 times. Which would be because the same empty list is > assigned > > to every key in the dictionary by the "fromkeys" line. But that seems > > seriously counter-intuitive to me... > > Python doesn't do any extra copying in most places unless you > /explicitly/ do so yourself or ask it to; so yes, in this case, Python > just copies references to the same object and does not copy the object > itself. > > You'd probably be better off using a defaultdict in your particular > usecase: > http://docs.python.org/library/collections.html#collections.defaultdict > > Or and so you avoid running into it, default argument values aren't > copied either: > In [2]: def foo(z, a=[]): > ...: a.append(z) > ...: return a > ...: > > In [3]: foo(1) > Out[3]: [1] > > In [4]: foo(2) > Out[4]: [1, 2] > > In [5]: foo(2) > Out[5]: [1, 2, 2] > > In [6]: foo(3) > Out[6]: [1, 2, 2, 3] > > In [7]: foo(4,[]) > Out[7]: [4] > > In [8]: foo(5) > Out[8]: [1, 2, 2, 3, 5] > > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Nov 11 08:23:48 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 08:23:48 -0500 Subject: Calendar Stuff In-Reply-To: <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> Message-ID: <4dc0cfea0911110523j68d6bd41webac713736505140@mail.gmail.com> On Wed, Nov 11, 2009 at 1:12 AM, Simon Forman wrote: > On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi > wrote: > > Hi; > > I have the following code: > > > > import calendar, datetime > > > > def cal(): > > ... > > myCal = calendar.Calendar(calendar.SUNDAY) > > today = datetime.date.today() > > day = today.day > > mo = today.month > > yr = today.year > > # month = myCal.monthdayscalendar(int(time.strftime("%Y")) > > month = myCal.monthdayscalendar(yr, mo) > > print 'hi' > > > > html headers are included. No matter which one of the last two lines I > > comment out, I never get to the point of printing 'hi'. (If I comment > them > > both out, it does print.) What do? > > TIA, > > Victor > > Have you tried walking through the code line-by-line in the > interactive interpreter? > Yes. It works just fine in the interactive interpreter, darn it. > > That should give you an idea of why those lines aren't working. Also, > if your code never prints 'hi', what does it do instead? Hang? Or > give you a traceback? > Hangs. I'd love a traceback! V > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Nov 11 08:25:01 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 08:25:01 -0500 Subject: CGI vs mod_python In-Reply-To: <4af9f122$0$1659$742ec2ed@news.sonic.net> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> Message-ID: <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> On Tue, Nov 10, 2009 at 6:12 PM, John Nagle wrote: > ssteinerX at gmail.com wrote: > >> >> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: >> >> Yes, obviously. But if CGI is enabled, it should work anyway, should it >>> not? >>> >> >> Depends on what "CGI is enabled" means. >> >> Usually, web servers are not set to just handle cgi scripts from anywhere, >> but only from specific file system locations. Otherwise, an an anonymous >> upload could be executed as CGI and wreak havoc. >> > > If it won't work as a CGI program, which is relatively straightforward, > it probably won't work at all. > > First, write some trivial CGI program in Python and make sure the > environment works - Python loads, the Python program loads, and you > can get a response back. > > Bear in mind that most hosting services don't make much of an attempt > to support Python. Expect important libraries to be missing or obsolete. > The problem was not CGI. It turned out to be line-endings being mangled by Windoze and __invisible __ in my unix editor. Lovely. Thanks anyway, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From samwyse at gmail.com Wed Nov 11 08:26:01 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:26:01 -0800 (PST) Subject: Python C api: create a new object class References: Message-ID: <5e150c6b-4eff-40ee-be93-ea195d674e79@f16g2000yqm.googlegroups.com> On Nov 10, 1:09?pm, "lallous" wrote: > Hello > > I have 3 questions, hope someone can help: > > 1) > How can I create an instance class in Python, currently I do: > > class empty: > ? pass > > Then anytime I want that class (which I treat like a dictionary): > > o = empty() > o.myattr = 1 > etc.... > > Is there is a one line syntax to instantiate an instance? I think that you want this: class c(object): def __init__(self, **kwds): self.__dict__ = kwds x = c(a=1, b=2) print x.a, x.b From sanneh27 at hotmail.com Wed Nov 11 08:29:36 2009 From: sanneh27 at hotmail.com (baboucarr sanneh) Date: Wed, 11 Nov 2009 13:29:36 +0000 Subject: PyQt 2 Exe Message-ID: Hi guys, I wan to make a gui app using pyqt so i have done some thing already now i want to save it as an exe file so that i can give it out to users who dont have pyqt installed (windows users)..Please help me out on this one..thnx Regards $LIM $H at DY _________________________________________________________________ Keep your friends updated?even when you?re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Wed Nov 11 08:31:32 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Nov 2009 15:31:32 +0200 Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: 7stud writes: > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: ... > My os is mac os x 10.4.11. But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found Maybe STATIC_DEPS=true sudo easy_install lxml And be running Bash or some other Bourne type shell. ... > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the > average user, then you are the equivalent of one of the worst > programmers on the planet. Harsh, but clearly there are problems with the installation procedure. Not nice, especially when running with admin rights. From samwyse at gmail.com Wed Nov 11 08:35:25 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:35:25 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: <7ce4f4d8-398e-4080-b874-02338f6c36ef@g23g2000yqh.googlegroups.com> On Nov 11, 3:57?am, "Robert P. J. Day" wrote: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4... > > ? thoughts? Google's already given us its thoughts: http://developers.slashdot.org/story/09/11/11/0210212/Go-Googles-New-Open-Source-Programming-Language From victorsubervi at gmail.com Wed Nov 11 09:00:44 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 09:00:44 -0500 Subject: Can't Write File In-Reply-To: <4AF9DC3F.7020505@ieee.org> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> Message-ID: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > Victor Subervi wrote: > >> Hi; >> I've determined the problem in a script is I can't open a file to write >> it: >> script = open(getpic, "w") # where getpic is already defined >> Here are the permissions: >> -rwxr-xr-x 1 root root 4649 Nov 10 12:31 start.py >> What am I doing wrong? >> TIA, >> Victor >> >> >> > Wrong? > > 1) you don't specify the environment, python version, OS, etc. > python 2.4.3 CentOS 5.4 final > 2) you don't show the error traceback > because there are none > 3) you don't indicate the value of getpic at the time this statement > executes > As mentioned earlier, it increments: getpic1.py getpic2.py getpic3.py getpic4.py getpic5.py > 4) you don't indicate what the current working directory is, os.getcwd() > /var/www/html/angrynates.com/stxresort/cart > 5) you don't indicate what directory the start.py is located in > ditto > 6) you don't indicate which user is executing this script (only root can > write to it) > Help me on this. All scripts are owned by root. Is it not root that is executing the script? > 7) you don't tell what the filename of the script is, specif. if it's > called start.py yes, start.py > 8) you don't say what happens if you do an open(getpic, "r"), or > os.path.isfile(getpic) > It doesn't like either of those. Goes to the except in the try. By the time you answer each of those questions, you may notice the answer to > your own question. > I wish that were so. I have written a little script that does nothing but test the line in question [open(getpic, 'w')] and that works. Here's a bigger code snippet with the entire try clause: if 14 < x < 20: # This just shows that it's a pic, not some other type of data y += 1 w += 1 try: # It does this, because I've printed 'getpic1.py' etc. getpic = "getpic" + str(w) + ".py" try: os.remove(getpic) except: pass code = """#! /usr/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login def pic(): user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic%s from products where ID=%s;" cursor.execute(sql) content = cursor.fetchone()[0] cursor.close() print content print 'Content-type: image/jpeg' print pic()""" % (str(w), str(i)) script = open(getpic, "w") # I've deleted everything below this line to the except to test script.write(code) print '
    \n' % str(x) os.chmod(getpic, 0755) print '

    nope%s\n' % str(x) > os.chmod(getpic, 0755) > print '

    nope%s\n' % str(x) > > os.chmod(getpic, 0755) > > print '

    nope%s
    Nordea Bank Finland Abp utf?rdad av Nordea Bank Finland Abp
    B?rskod K?p S?lj Senast F?rfallodag Tid
     NBF AT99 3113A  95,69  97,69  95,69  2011-06-03  12:33
    I didn't try it, but you could presumably use urllib2 to download that url (prob. to a file, so you can repeat the test often without loading the server). One caution, it did ask to store a cookie, and I know nothing about cookie handling in Python. Several cautions: I don't know how target= and magic= were derived, or whether they'll remain stable for more than a day or so. So you can download this file and figure how to parse it, but you'll probably need to also parse the earlier pages, and that could be easier or harder. This page format is very straightforward. If you know you're looking for NBF AT99, you could look for that particular line, then just parse all the td's till the next /tr. No XML logic needed. If you don't know the NBF string, you could look for B?rskod instead. But the big risk you run is the bank could easily change this format quite drastically, at any time. Those td elements don't have to be on separate lines, the browser doesn't care. And the class attribute could change if the CSS also changes correspondingly. Or they could come up with an entirely different way to display the data. All they care about is whether it's readable by the human looking at the browser page. Using xml..elementtree would be a good start; You could build the DOM, look for the table of class 'tableb3', and go in from there But you still run the risk of them changing things. The class name, for example, is just a link to the CSS page which describes how that class object should be displayed. If the name is changed at both ends, no change occurs, except to your script. At this point, you need to experiment. But build a sloppy skeleton first, so you don't invest too much time in any one aspect of the problem. Make sure you can cover the corner cases, then fill in the tough parts. I'd say roughly this order: 1. write code that download the page to a file, given an exact URL. For now, keep that code separate, as it'll probably end up being much more complex, walking through other pages. 2. parse that page, using a simple for loop that looks for some of the key strings mentioned above. 3. Repeat that for a few different URL's, presumably one per bond fund. 4. Make sure the URL's don't go stale over a few days. If they do, you'll have to back up to an earlier link (URL), and parse forward from there. Keep the various pieces in different modules, so that when an assumption breaks, you can recode that assumption pretty much independent of the others. HTH DaveA From Scott.Daniels at Acm.Org Tue Nov 17 10:11:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:11:01 -0800 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> Message-ID: Steve Howell wrote: ... > Eventually, I realized that it was easier to just monkeypatch Django > while I was in test mode to get a more direct hook into the behavior I > was trying to monitor, and then I didn't need to bother with > overriding __getitem__ or creating complicated wrapper objects.... Since nobody else has mentioned it, I'd point you at Mock objects: http://python-mock.sourceforge.net/ for another way to skin the cat that it sounds like has been biting you. They are surprisingly useful for exploratory and regression testing. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Tue Nov 17 10:20:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:20:21 -0800 Subject: python gui builders In-Reply-To: <8u9Mm.35397$Wd1.32454@newsfe15.iad> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: me wrote: > I have looked at the Tk stuff that is built into Python -> not > acceptable. Such insightful analysis, and it is _so_ helpful in stating your needs. > [a lot of guff about unacceptable things] > What Python gui builder is well supported, does not require me to learn > another framework/library, and can crank out stuff for multiple platforms ? Well, let's see. You want to do gui work without learning things. Good luck with that. If you discover how, I'd like to learn tensor analysis without using symbols or operations more complex than addition and subtraction. Maybe your groundwork can help me out with that. I must be in a really cranky mood today. --Scott David Daniels Scott.Daniels at Acm.Org From jsaxton at appsecinc.com Tue Nov 17 10:28:36 2009 From: jsaxton at appsecinc.com (Jonathan Saxton) Date: Tue, 17 Nov 2009 10:28:36 -0500 Subject: New syntax for blocks In-Reply-To: <00863e42$0$26916$c3e8da3@news.astraweb.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: >> Congratulations, you just reinvented one of the most infamous source of >> bugs in C, C++, Java, PHP, javascript and quite a few other languages. >> Believe it or not, but not allowing this in Python was a very deliberate >> design choice. > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > assignment-as-an-expression is nothing compared to the dozens of man- > minutes saved by having one fewer line of code! > > > *wink* And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. (Come to think of it, plagiarizing a bad idea is probably the worse evil.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list From sjmsoft at gmail.com Tue Nov 17 10:29:56 2009 From: sjmsoft at gmail.com (sjm) Date: Tue, 17 Nov 2009 07:29:56 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> On Nov 16, 12:54?pm, Steve Ferg wrote: > Does anybody know a language with this kind of syntax for > ifThenElseEndif? Modern-day COBOL: IF some-condition do-something ELSE do-something-else END-IF. The period is also meaningful as a statement terminator in COBOL, so it's not as clean as one might like. I, too, like the Python way. Cheers, Steve J. Martin From lee_merrill at yahoo.com Tue Nov 17 10:37:55 2009 From: lee_merrill at yahoo.com (Lee Merrill) Date: Tue, 17 Nov 2009 07:37:55 -0800 (PST) Subject: Time travel Message-ID: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> I'm seeing an anomaly in the python time function on March 9, 2008 (the "spring foward" time): >>> time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1)) 1205049599.0 >>> time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1)) 1205046000.0 Does anyone have an idea as to what might cause a 4000 seconds backwards jump on March 9th of last year? I would have expected 3600 seconds. Thanks, Lee P.S. A full program demonstrating the question: #!/usr/bin/env python import time, datetime d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() #!/usr/bin/env python import time, datetime d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple() t1 = time.mktime(d1) t2 = time.mktime(d2) print t1, t2 From himanshu.garg at gmail.com Tue Nov 17 10:41:09 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Tue, 17 Nov 2009 21:11:09 +0530 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <6f82a7270911170741m6b23e3f8if047bb639ccef76a@mail.gmail.com> 2009/11/15 mrholtsr : > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray > -- > http://mail.python.org/mailman/listinfo/python-list > Consider skipping such "mathematically oriented" exercises in an introductory course on python if targeted to a general audience. From lee_merrill at yahoo.com Tue Nov 17 10:43:04 2009 From: lee_merrill at yahoo.com (Lee Merrill) Date: Tue, 17 Nov 2009 07:43:04 -0800 (PST) Subject: Time travel References: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> Message-ID: <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> And I can't do arithmetic, it is actually about 3600--never mind! On Nov 17, 10:37?am, Lee Merrill wrote: > I'm seeing an anomaly in the python time function on March 9, 2008 > (the "spring foward" time): > > >>> time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1)) > 1205049599.0 > >>> time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1)) > > 1205046000.0 > > Does anyone have an idea as to what might cause a 4000 seconds > backwards jump on March 9th of last year? I would have expected 3600 > seconds. > > Thanks, > Lee > > P.S. A full program demonstrating the question: > > #!/usr/bin/env python > > import time, datetime > > d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() > #!/usr/bin/env python > > import time, datetime > > d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() > d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple() > t1 = time.mktime(d1) > t2 = time.mktime(d2) > > print t1, t2 From paul at boddie.org.uk Tue Nov 17 10:53:55 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 17 Nov 2009 07:53:55 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <6edf04af-abd3-4034-aa2c-fc8af296fac7@b15g2000yqd.googlegroups.com> On 17 Nov, 14:48, Aaron Watters wrote: > > ... and I still have an issue with the whole "Python is slow" > meme. ?The reason NASA doesn't build a faster Python is because > Python *when augmented with FORTRAN libraries that have been > tested and optimized for decades and are worth billions of dollars > and don't need to be rewritten* is very fast. That's why I wrote that Python's "extensibility using C, C++ and Fortran [has] helped adoption of the language considerably", and Python was particularly attractive to early adopters of the language precisely because of the "scripting" functionality it could give to existing applications, but although there are some reasonable solutions for writing bottlenecks of a system in lower-level programming languages, it can be awkward if those bottlenecks aren't self-contained components or if the performance issues permeate the entire system. [...] > And when someone implements a Mercurial replacement in GO (or C# > or Java) which is faster and more useful than Mercurial, I'll > be very impressed. ?Let me know when it happens (but I'm not > holding my breath). Mercurial is a great example of a Python-based tool with good performance. However, it's still interesting to consider why the implementers chose to rewrite precisely those parts that are implemented using C. I'm sure many people have had the experience of looking at a piece of code and being quite certain of what that code does, and yet wondering why it's so inefficient in vanilla Python. It's exactly this kind of issue that has never really been answered convincingly, other than claims that "Python must be that dynamic and no less" and "it's doing so much more than you think", leaving people to try and mitigate the design issues using clever implementation techniques as best they can. > By the way if it hasn't happened and if he isn't afraid > of public speaking someone should invite Matt Mackall > to give a Python conference keynote. ?Or how about > Bram Cohen for that matter... Bryan O'Sullivan gave a talk on Mercurial at EuroPython 2006, and although I missed that talk for various reasons beyond my control, I did catch his video lightning talk which emphasized performance. That's not to say that we couldn't do with more talks of this nature at Python conferences, however. Paul From Scott.Daniels at Acm.Org Tue Nov 17 10:54:30 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:54:30 -0800 Subject: ZipFile - file adding API incomplete? In-Reply-To: References: Message-ID: Glenn Maynard wrote: > I want to do something fairly simple: read files from one ZIP and add > them to another, so I can remove and replace files. This led me to a > couple things that seem to be missing from the API. > > .... zip.write() only takes the filename and > compression method, not a ZipInfo; writestr takes a ZipInfo but only > accepts a string, not a file. Is there an API call I'm missing? > (This seems like the fundamental API for adding files, that write and > writestr should be calling.) Simple answer: its not there in the API. Defining that API correctly is tricky, and fraught with issues about access to the ZipFile object (from both the same thread and from other threads) while it is mid-modification. Nonetheless, a carefully done API that addresses those issues would be valuable. If you do spend the time to get something reliable going, put it someplace public and I predict it will get use. The approach I fiddled with was: * Define a calls to read _portions_ of the raw (compressed, encrypted, whatever) data. * Define a call that locks the ZipFile object and returns a write handle for a single new file. At that point the new file doesn't exist, but reading of other portions of the zip file are allowed. * Only on successful close of the "write handle" is the new directory written. Unfortunately, I never worked very hard at the directory entries, and I realize that the big flaw in this design is that from the moment you start overwriting the existing master directory until you write a new master at the end, your do not have a valid zip file. Also note that you'll have to research standards about _exactly_ what the main header should look like if you use particular features. My stuff did bzip compression as well, and about the "find which bits means what" was where my process broke down. --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Tue Nov 17 10:59:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 16:59:40 +0100 Subject: SCGIServer and unusal termination References: Message-ID: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Eden Kirin wrote: > Hi there, > > I'm playing with SCGIServer > (http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), > everything works just fine, but one thing bothers me. All prints after > try-except block are executed twice after the Ctrl+C is pressed! > > test.py: > #------------------------- > from scgi.scgi_server import SCGIServer > > n = 0 > print "Starting server." > > try: > SCGIServer().serve() > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > # print lines are executed twice (?!) > n += 1 > print "Terminating server, attempt %d." % n > n += 1 > print "Check n: %d." % n > #------------------------- > > This is the output: > > eden at sunce:~/data/project/ScgiServer/src> python test.py > Starting server. > ^CException! > Exception! > Terminating server, attempt 1. > Check n: 2. > Terminating server, attempt 1. > Check n: 2. > eden at sunce:~/data/project/ScgiServer/src> > > > If I put something else in try-except block, code after is executed > normally: > > try: > while 1: > pass > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > eden at sunce:~/data/project/ScgiServer/src> python test.py > Starting server. > ^CException! > Terminating server, attempt 1. > Check n: 2. > eden at sunce:~/data/project/ScgiServer/src> > > Environment is 64bit Ubuntu with Python v2.6.4. > > Is there some reasonable explanation for this behaviour? Thanks in > advance. I can only guess that SCGIServer does something to stdout. Your code isn't executed twice, so the doubling seems to come from writing it twice. Try e.g. redirecting stdout and stderr to different files, and see if things appear once in both. Diez From showell30 at yahoo.com Tue Nov 17 11:12:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 17 Nov 2009 08:12:09 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> Message-ID: On Nov 17, 7:11?am, Scott David Daniels wrote: > Steve Howell wrote: > > ... > > > Eventually, I realized that it was easier to just monkeypatch Django > > while I was in test mode to get a more direct hook into the behavior I > > was trying to monitor, and then I didn't need to bother with > > overriding __getitem__ or creating complicated wrapper objects.... > > Since nobody else has mentioned it, I'd point you at Mock objects: > ? ? ?http://python-mock.sourceforge.net/ > for another way to skin the cat that it sounds like has been > biting you. ?They are surprisingly useful for exploratory > and regression testing. > Thanks, Scott. We do indeed use mocks in our development, and they are useful. In a way I am trying to emulate some of what mock objects do, but in more on an integration testing mode. For testing the rendering of whole templates, it sometimes becomes convenient for at least some of the objects that your code depends on to maintain their implementation under the hood, but you also want to see where they're going, which is why I want to be able to hook into the dictionary lookup mechanism. Even outside of pure unit testing, mock objects have been pretty versatile in terms of giving us the lay of the land, even when we start getting down into the Django template stack. It is mostly when you start interacting with the ORM that you want to start using real objects. On the one hand you want to isolate yourselves from the ORM behavior to validate the rest of your code, but sometimes it is difficult to emulate the exact semantics of the ORM, or maybe you are trying to get a handle on where the ORM is hitting the database, etc. The so-called "real world" situations are when you start wanting a messy hybrid of mock objects, merely-spied-on objects, real objects, etc. From metolone+gmane at gmail.com Tue Nov 17 11:23:39 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 17 Nov 2009 08:23:39 -0800 Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> Message-ID: "Chris Withers" wrote in message news:4B028AC1.8020307 at simplistix.co.uk... > Cannonbiker wrote: >> Hi, >> unfortunately is my question about server COM (win32com) >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# >> without answer. >> >> Please I need Calling Python functions from Excel and receive result >> back in Excel. Can me somebody advise simplest solution please? I am >> more VBA programmer than Python. > > Try http://code.google.com/p/pyinex/ The book Python: Programming on Win32 has a whole chapter on COM, and a section on COM servers. -Mark From __peter__ at web.de Tue Nov 17 11:27:36 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2009 17:27:36 +0100 Subject: Code for finding the 1000th prime References: Message-ID: mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray When you encounter a problem that you find hard try to split it into simpler subproblems. Example: To find the 1000th prime start with a program that finds all integers i = 1 while True: print i i = i + 1 If you run that it will print integers until you hit Ctrl-C. Python offers an elegant construct that helps you encapsulate the logic of a loop, called "generator". With that we can rewrite the all-integers program as def all_natural_numbers(): i = 1 while True: yield i i = i + 1 for i in all_natural_numbers(): print i Now let's tackle the next step: we want only prime numbers, but don't know how to check for them. How can we postpone that problem and still continue with our program? Easy: introduce a function where the check will ultimately go but have it do something that we do understand right now: def isprime(candidate): return candidate != 42 Why not check for candidate == 42? We would only ever get one "pseudo- prime", but we need at least 1000 of them. With the above bold assumption the program becomes def isprime(candidate): return candidate != 42 def all_natural_numbers(): i = 1 while True: yield i i = i + 1 for i in all_natural_numbers(): if isprime(i): print i While the actual output is a bit unorthodox we now have the structure to print all prime numbers. Again we can wrap the logic into a generator: def isprime(candidate): return candidate != 42 def all_natural_numbers(): i = 1 while True: yield i i = i + 1 def all_prime_numbers(): for i in all_natural_numbers(): if isprime(i): yield i for p in all_prime_numbers(): print p We are actually only interested in the 1000th prime. We can find that by counting over all prime numbers: i = 1 for p in all_prime_numbers(): if i == 1000: print p break i = i + 1 We can wrap this step in a function for future reuse: # all_natural_numbers(), all_prime_numbers(), # and isprime() as before def nth_item(items, n): i = 1 for item in items: if i == n: return item i = i + 1 # raise Exception("here be dragons") print nth_item(all_prime_numbers(), 1000) OK, we now have a nice clean python script that tells us that the 1000th prime number is 1001, a finding that will meet some opposition among mathematicians. Let's turn to wikipedia for help: """ a prime number (or a prime) is a natural number which has exactly two distinct natural number divisors: 1 and itself. ... The number 1 is by definition not a prime number. """ Translated into Python: def isprime(candidate): if candidate == 1: return False # 1 is not a prime for potential_divisor in range(2, candidate): if int(candidate/potential_divisor)*potential_divisor == candidate: # candidate could be divided by potential divisor # without rest, so it's not a prime return False # we didn't find a divisor for candidate # -- it must be a prime return True Now while this test for primality is not the most beautiful code I've ever written it should give you the correct result. As a first step to improve it have a look at the % ("modulo") operator in your textbook. Then try to reduce the number of potential divisors. Peter From eden at bicikl. Tue Nov 17 11:32:58 2009 From: eden at bicikl. (Eden Kirin) Date: Tue, 17 Nov 2009 17:32:58 +0100 Subject: SCGIServer and unusal termination In-Reply-To: <7mfvjcF3hnir0U1@mid.uni-berlin.de> References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: >> Is there some reasonable explanation for this behaviour? Thanks in >> advance. > > I can only guess that SCGIServer does something to stdout. Your code isn't > executed twice, so the doubling seems to come from writing it twice. Yes I know that code isn't executed twice since the value of n remains the same, only print lines are doubled. > Try e.g. redirecting stdout and stderr to different files, and see if things > appear once in both. Redirection of stdout: eden at sunce:~/data/project/ScgiServer/test> python test.py 1> output.txt ^Ceden at sunce:~/data/project/ScgiServer/test> cat output.txt Starting server. Exception! Terminating server, attempt 1. Check n: 2. Starting server. Exception! Terminating server, attempt 1. Check n: 2. Redirecting stderr creates an empty file. I still haven't found the solution. -- www.vikendi.net -/- www.supergrupa.com From reply-to at works.fine.invalid Tue Nov 17 11:33:30 2009 From: reply-to at works.fine.invalid (NickC) Date: 17 Nov 2009 16:33:30 GMT Subject: Vim breaks after Python upgrade Message-ID: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Perhaps OT, but I figure here is where people have seen this commonly. I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now complaining every startup about missing libraries, presumably as some plugins run some python code on initialisation. I'm guessing vim is complaining as it was compiled with python support, and that was 2.5.2, and the compiled-in python library locations no longer exist. I compiled a new vim, so things are ok-ish, but now my system is even further away from standard distro. I'm also a little surprised vim is so clunky as to use hard-coded locations. Do I really have to compile a new vim every python upgrade? 'strings vim' shows some ascii that could be the python library locations. Being quite ignorant of how the linux loader works, could I in future use sed on the vim binary to change every string of "2.5.2" to "2.6.2", or are the library locations used by the loader coded in binary rather than ascii (and so, harder to find)? Thanks, -- NickC From garrickp at gmail.com Tue Nov 17 11:34:49 2009 From: garrickp at gmail.com (Falcolas) Date: Tue, 17 Nov 2009 08:34:49 -0800 (PST) Subject: TODO and FIXME tags References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: <958474ea-f217-49cb-a9f4-0516e955eb14@u16g2000pru.googlegroups.com> On Nov 17, 4:27?am, "Martin P. Hellwig" wrote: > Ben Finney wrote: > > Chris Rebert writes: > > >> 2009/11/16 Yasser Almeida Hern?ndez : > >>> How is the sintaxis for set the TODO and FIXME tags...? > >> There is no special syntax for those. Some people use them in > >> comments, but it's just a convention. > > > This is true. However, the convention is fairly well established, and > > many text editor default configurations will highlight the strings > > ?TODO?, ?FIXME?, and others wherever they appear in comments. > > > There's no widely-followed ?syntax? for this convention, though. I have noticed that within Python XXX as an identifier is fairly popular as well - it's used throughout the standard libraries, and is recognized by many syntax highlighting schemes, as well as Pylint. Garrick From news at schwertberger.de Tue Nov 17 11:38:44 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Tue, 17 Nov 2009 17:38:44 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> Message-ID: <7mg1ssF3fbbi7U1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 15:35, Dietmar Schwertberger wrote: > >> self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) >> self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", >> wx.DefaultPosition, wx.DefaultSize, 0 ) >> m_toolBar1.AddControl( m_button1 ) > > I can confirm this. There seems to be a bug in the generation of > Python code for wxToolBar. If anybody faces this problem before a new revision of wxFormBuilder will be available: an XML file need to be updated to correctly include self. The modification: wxformbuilder\output\plugins\common\xml\menutoolbar.pythoncode: Regards, Dietmar From chris at simplistix.co.uk Tue Nov 17 11:40:03 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 Nov 2009 16:40:03 +0000 Subject: Calling Python functions from Excel In-Reply-To: References: <4B028AC1.8020307@simplistix.co.uk> Message-ID: <4B02D1E3.6080308@simplistix.co.uk> Mark Tolonen wrote: > >>> Please I need Calling Python functions from Excel and receive result >>> back in Excel. Can me somebody advise simplest solution please? I am >>> more VBA programmer than Python. >> >> Try http://code.google.com/p/pyinex/ > > The book Python: Programming on Win32 has a whole chapter on COM, and a > section on COM servers. ...and it's generally accepted that COM sucks rocks through straws, so explore alternatives when they're available ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rustompmody at gmail.com Tue Nov 17 11:41:42 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 17 Nov 2009 22:11:42 +0530 Subject: python simply not scaleable enough for google? Message-ID: "Language L is (in)efficient. No! Only implementations are (in)efficient" I am reminded of a personal anecdote. It happened about 20 years ago but is still fresh and this thread reminds me of it. I was attending some workshop on theoretical computer science. I gave a talk on Haskell. I showed off all the good-stuff -- pattern matching, lazy lists, infinite data structures, etc etc. Somebody asked me: Isnt all this very inefficient? Now at that time I was a strong adherent of the Dijkstra-religion and this viewpoint "efficiency has nothing to do with languages, only implementations" traces to him. So I quoted that. Slowing the venerable P S Thiagarajan got up and asked me: Lets say that I have a language with a type 'Proposition' And I have an operation on proposition called sat [ sat(p) returns true if p is satisfiable]... I wont complete the tale other than to say that Ive never had the wind in my sails taken out so completely! So Vincent? I wonder what you would have said in my place? From james at agentultra.com Tue Nov 17 11:42:44 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 17 Nov 2009 11:42:44 -0500 Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <87hbstqf0b.fsf@agentultra.com> David Cournapeau writes: > On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: >> >>> I don't think Python and Go address the same set of programmer >>> desires. ?For example, Go has a static type system. ?Some programmers >>> find static type systems to be useless or undesirable. ?Others find >>> them extremely helpful and want to use them them. ?If you're a >>> programmer who wants a static type system, you'll probably prefer Go >>> to Python, and vice versa. ?That has nothing to do with implementation >>> speed or development expenditures. ?If Google spent a million dollars >>> adding static types to Python, it wouldn't be Python any more. >> >> ... and I still have an issue with the whole "Python is slow" >> meme. ?The reason NASA doesn't build a faster Python is because >> Python *when augmented with FORTRAN libraries that have been >> tested and optimized for decades and are worth billions of dollars >> and don't need to be rewritten* is very fast. > > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. Relying on a lot of > compiled libraries goes against it. > > I think that python with its scientific extensions is a fantastic > tool, but I would certainly not mind if it were ten times faster. In > particular, the significant cost of function calls makes it quickly > unusable for code which cannot be easily "vectorized" - we have to > resort to using C, etc... to circumvent this ATM. > > Another point which has not been mentioned much, maybe because it is > obvious: it seems that it is possible to makes high level languages > quite fast, but doing so while keeping memory usage low is very > difficult. Incidentally, the same tradeoff appears when working with > vectorized code in numpy/scipy. I think this is the only interesting point in the whole conversation so far. It is possible for highly dynamic languages to be optimized, compiled, and run really fast. The recent versions of SBCL can compile Common Lisp into really fast and efficient binaries. And Lisp could be considered even more dynamic than Python (but that is debateable and I have very little evidence... so grain of salt on that statement). It's possible, it just hasn't been done yet. PyPy is getting there, but development is slow and they could probably use a hand. Instead of waiting on the sidelines for a company to back PyPy developemnt, the passionate Python programmers worth a salt that care about Python development should contribute at least a patch or two. The bigger problem though is probably attention span. A lot of developers today are more apt to simply try the next new language than to roll of their sleeves and think deeply enough to improve the tools they're already invested in. > > David From james.harris.1 at googlemail.com Tue Nov 17 11:55:33 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Tue, 17 Nov 2009 08:55:33 -0800 (PST) Subject: Easy way to play single musical notes in Python References: <163ac43b-4d63-4db2-99c7-9b022c2e1f23@m20g2000vbp.googlegroups.com> Message-ID: <88d19e11-631c-4c72-950c-d213625e5039@x31g2000yqx.googlegroups.com> On 15 Nov, 05:41, r wrote: > On Nov 14, 6:21?pm, James Harris > wrote: > > > Is there a simple way to play musical notes in Python? Something like > > ? voice.play("c4") > > Uhh, tksnack is pretty easy to use IMO, see this link... http://www.daniweb.com/code/snippet216655.html > > No python does not have access to cross platform soundcard > capabilities built into the language. I think there is a wrapper for > csound somewhere. But there are many 3rd party modules that do have > capabilities to some extent. You could make calls to the underlying OS > machinery and there is the winsound module (not exactly what you want > though). Just look over this Google splooge... > > http://www.google.com/search?hl=en&rlz=1C1CHMI_enUS340US340&q=Python+... As I say I was hoping to avoid tk. Thanks for the feedback though. If nothing else is suggested I'll have to try snack. James From J.Fine at open.ac.uk Tue Nov 17 11:59:44 2009 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Tue, 17 Nov 2009 16:59:44 +0000 Subject: FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you Message-ID: Hi A big thanks to Armin Ronacher and Raymond Hettinger for PEP 372: Adding an ordered dictionary to collections I'm using ConfigParser and I just assumed that the options in a section were returned in the order they were given. In fact, I relied on this fact. http://docs.python.org/library/configparser.html And then when I came to test the code it went wrong. After some anguish I looked at ConfigParser and saw I could pass it a dict_type. So I could fix the problem myself by writing an OrderDict. Which I duly prototyped (in about an hour). I then thought - maybe someone has been down this path before. A Google search quickly led me to PEP 372 and hence to http://docs.python.org/dev/py3k/library/configparser.html which says class configparser.RawConfigParser(defaults=None, dict_type=collections.OrderedDict) So all that I want has been done already, and will be waiting for me when I move to Python3. So a big thank you is in order. -- Jonathan From arts.martijn at gmail.com Tue Nov 17 12:09:53 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Tue, 17 Nov 2009 18:09:53 +0100 Subject: CTypes problem. Message-ID: <23739e0a0911170909m2c51782eoe56f31293939d5a0@mail.gmail.com> I wanted to use PyWiiUse, but, well, it sucks Then I thought; it can't be THAT hard, can it? So I began porting WiiUse to Python using ctypes, but apparently, I did something wrong. poll() gives back an event, *but* (there's always a but) the event doesn't register. Or... Well... See for yourself, I think it has something to do with Pointers, but I have no idea, really ;) So, here's the code: Code :-P -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Tue Nov 17 12:27:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 18:27:49 +0100 Subject: Code for finding the 1000th prime References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7mg4olF3idnj9U1@mid.uni-berlin.de> Stefan Behnel wrote: > Robert P. J. Day, 15.11.2009 15:44: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray >> >> it's 7919. > > Now, all that's left to do is write a prime number generator (a random > number generator will do, too, but writing a good one isn't easy), run it > repeatedly in a loop, and check if the returned number is 7919. Once it > compares equal, you can print the result and you're done. That reminds me of the only algorithm I really invented myself: debil sort. It goes like this: L = while not sorted(L): p = generate_random_permutation(len(L)) L = apply_permutation(L, p) print L Great algorithm. Actually works. And the saddest thing: somebody out there certainly has written something like that by accident... I've spotted sorting in O(n^3) (with non-deterministic exceptional termination conditions) already in the wild. Diez From deets at nospam.web.de Tue Nov 17 12:30:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 18:30:05 +0100 Subject: SCGIServer and unusal termination References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Message-ID: <7mg4stF3idnj9U2@mid.uni-berlin.de> Eden Kirin wrote: > Diez B. Roggisch wrote: > >>> Is there some reasonable explanation for this behaviour? Thanks in >>> advance. >> >> I can only guess that SCGIServer does something to stdout. Your code >> isn't executed twice, so the doubling seems to come from writing it >> twice. > > Yes I know that code isn't executed twice since the value of n remains > the same, only print lines are doubled. > >> Try e.g. redirecting stdout and stderr to different files, and see if >> things appear once in both. > > Redirection of stdout: > > eden at sunce:~/data/project/ScgiServer/test> python test.py 1> output.txt > ^Ceden at sunce:~/data/project/ScgiServer/test> cat output.txt > Starting server. > Exception! > Terminating server, attempt 1. > Check n: 2. > Starting server. > Exception! > Terminating server, attempt 1. > Check n: 2. > > Redirecting stderr creates an empty file. I still haven't found the > solution. > Then - save a reference to sys.stdout *before* invoking the server - compare to it after interruption. If it has changed, you at least know that somebody messed with it, and can beat him or whatever you see fit. Diez From python at mrabarnett.plus.com Tue Nov 17 12:31:18 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Nov 2009 17:31:18 +0000 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4B02DDE6.2050001@mrabarnett.plus.com> Jonathan Saxton wrote: > On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > >>> Congratulations, you just reinvented one of the most infamous >>> source of bugs in C, C++, Java, PHP, javascript and quite a few >>> other languages. Believe it or not, but not allowing this in >>> Python was a very deliberate design choice. >> Oh, but those hundreds of thousands of man-hours lost to bugs >> caused by assignment-as-an-expression is nothing compared to the >> dozens of man- minutes saved by having one fewer line of code! >> >> >> *wink* > > And if I ever find the genius who had the brilliant idea of using = > to mean assignment then I have a particularly nasty dungeon reserved > just for him. Also a foul-smelling leech-infested swamp for those > language designers and compiler writers who followed his example. > (Come to think of it, plagiarizing a bad idea is probably the worse > evil.) > C was derived from BCPL, which used ":=" and "=". Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes did. It's a pity that Guido chose to follow C. From pruebauno at latinmail.com Tue Nov 17 12:39:42 2009 From: pruebauno at latinmail.com (nn) Date: Tue, 17 Nov 2009 09:39:42 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <908f2c47-ee00-4094-993f-764fa7fce9f4@n35g2000yqm.googlegroups.com> On Nov 16, 11:54?am, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? I personally like the "END X" syntax (not that I would want it for Python mind you). It makes it easier to read programs backwards. Foxpro used that syntax form extensively: http://msdn.microsoft.com/en-us/library/b660264t%28VS.80%29.aspx DO CASE ... ENDCASE DO WHILE ... ENDDO FOR EACH ... ENDFOR FOR ... ENDFOR IF ... ENDIF PRINTJOB ... ENDPRINTJOB SCAN ... ENDSCAN TEXT ... ENDTEXT WITH ... ENDWITH From abegong at gmail.com Tue Nov 17 13:02:04 2009 From: abegong at gmail.com (Abe) Date: Tue, 17 Nov 2009 10:02:04 -0800 (PST) Subject: Is there a way to load multiple wxhtmlwindow at the same time? Message-ID: <35f37d98-0605-4912-bd6c-ec98f6541751@m26g2000yqb.googlegroups.com> All - I'm working on a program that loads a series of web pages so the user can view them quickly one after another. I'm using python and wxhtmlwindow, and the page loading is really slow. Is there a simple way to load up the next few pages in the queue while the user is looking at the current page? thanks! - Abe PS - If the answer involves threading, can you please point me to some resources on threading in wx? I know the basics of GUI programming in wx and threading in python, but I have no idea how to put them together. From rt8396 at gmail.com Tue Nov 17 13:15:41 2009 From: rt8396 at gmail.com (r) Date: Tue, 17 Nov 2009 10:15:41 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Nov 17, 9:28?am, Jonathan Saxton wrote: > And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. ?Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. ?(Come to think of it, plagiarizing a bad idea is probably the worse evil.) I think every new programmer wrestles with this dilemma in their first days but very soon after accepts it as reality. As for me it made perfect sense from day one to have '=' mean "assignment" and '==' to mean "equality". Programming is not mathematics (on the contrary) they are two sides of a mountain forever unknowing of each other but sharing the same space. I think the syntax was chosen because the alternatives are even worse AND since assignment is SO common in programming, would you *really* rather type two chars instead of one? From simon.hibbs at gmail.com Tue Nov 17 13:20:12 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 17 Nov 2009 10:20:12 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> On 16 Nov, 10:06, me wrote: > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? You're looking for a framework/library that doesn't require you to learn it. OK.... I've had this problem for a few years. I've tried PythonCard, WxWidgets with WxDesigner, BoaConstructor, etc. None of them come anywhere close to PyQT/QTDesigner. Dion't get Blackadder It hasn't been updated for several years and is a dead project. In any case it uses QTDesigner for GUI layout anyway. You're better off using Eric or Wing if you want a decent IDE. QT does have a learning curve of course, but you get a lot of power back in return for the investment. I'm just coming to grips with it's MVC framework and the book "Rapid GUI Programming with Python and Qt" is very helpful with that. I wouldn't completely dismiss Tkinter. It's too simple for complex GUIs but I still think it has it's place for basic utilities. Simon Hibbs From clp2 at rebertia.com Tue Nov 17 13:21:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 10:21:15 -0800 Subject: Code for finding the 1000th prime In-Reply-To: <7mg4olF3idnj9U1@mid.uni-berlin.de> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> <7mg4olF3idnj9U1@mid.uni-berlin.de> Message-ID: <50697b2c0911171021k35c757e1qb9453e507334f0e7@mail.gmail.com> On Tue, Nov 17, 2009 at 9:27 AM, Diez B. Roggisch wrote: > Stefan Behnel wrote: >> Robert P. J. Day, 15.11.2009 15:44: >> Now, all that's left to do is write a prime number generator (a random >> number generator will do, too, but writing a good one isn't easy), run it >> repeatedly in a loop, and check if the returned number is 7919. Once it >> compares equal, you can print the result and you're done. > > That reminds me of the only algorithm I really invented myself: debil sort. There's prior art for this algorithm: http://en.wikipedia.org/wiki/Bogosort > It goes like this: > > L = > > while not sorted(L): > ? p = generate_random_permutation(len(L)) > ? L = apply_permutation(L, p) > > print L > > > Great algorithm. Actually works. And the saddest thing: somebody out there > certainly has written something like that by accident... I've spotted > sorting in O(n^3) (with non-deterministic exceptional termination > conditions) already in the wild. Cheers, Chris -- http://blog.rebertia.com From cgrebeld at gmail.com Tue Nov 17 13:22:04 2009 From: cgrebeld at gmail.com (chris grebeldinger) Date: Tue, 17 Nov 2009 10:22:04 -0800 (PST) Subject: 2.6.4 Mac x86_64 ? References: Message-ID: <8c7cd73e-1e0b-43c7-a50f-ded80e656669@h14g2000pri.googlegroups.com> On Nov 14, 12:53?am, Zvezdan Petkovic wrote: > On Nov 13, 2009, at 3:58 PM, chris grebeldinger wrote: > > > Hi All, > > I've been having some trouble getting ax86_64/i386 universal > > readline.so to build against libedit, on MacOS 10.5.6 as Apple does. > > Does anyone have any pointers about what changes I need to make to > > setup.py or readline.c to achive this? > > Has someone already done this and would like to share it? > > The fix for use of native editline (readline emulation) was done and is already implemented on the trunk (2.7). > Please see:http://bugs.python.org/issue6877 > You can find the patch in that tracker issue or here:http://svn.python.org/view?view=rev&revision=74970 > > It was marked for a backport to a future 2.6.5 release too. > > > Are there any plans to provide 64 bit support in future Mac OS 2.6.x > > releases? > > AFAIK, it is already supported. > Perhaps you should specify the exact problems you have. > I believe that a more appropriate place for that would be pythonmac-sig mailing list, though. > > Best regards, > > ? ? ? ? Zvezdan Thank-you, doing a manual backport was easy once I knew where to find the diff =) - Chris From rt8396 at gmail.com Tue Nov 17 13:34:55 2009 From: rt8396 at gmail.com (r) Date: Tue, 17 Nov 2009 10:34:55 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> On Nov 17, 12:20?pm, Simon Hibbs wrote: > I wouldn't completely dismiss Tkinter. It's too simple for complex > GUIs but I still think it has it's place for basic utilities. Agreed! Tkinter (besides myself) seems to be the whipping boy of c.l.py. Tkinter has it's place in Python because of the same simplicity people laboriously lament about! Until something else comes along that can offer the same benefits of Tkinter and a little extra, we are going to keep seeing Tkinter release after release. Guido knows what he is doing people, don't sell the guy short! From cmpython at gmail.com Tue Nov 17 13:36:31 2009 From: cmpython at gmail.com (CM) Date: Tue, 17 Nov 2009 10:36:31 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: On Nov 16, 5:06?am, me wrote: > Good People > > I do not write stuff for humans, as it has been my job to remove > humans from the loop. But I have to make a front end to a > component database where everything was built in Python. > > I have looked at the Tk stuff that is built into Python -> not > acceptable. So looking at wxGlade, Boa Constructor, Python Card. > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. BlackAdder IDE seems to have > this built-in, but am loathe to buy into another GUI tool for a > single job. > > I have not been able to find a decent Python gui builder. The What was your issue with Boa Constructor? It produces wxPython code and I find it works quite well (less well on Linux, but if you use it in Windows, the app will run in Linux w/ minimal need for changes). Of course, whatever route you go, you have to learn the widget toolkit. Che From nick at stinemates.org Tue Nov 17 13:46:25 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 13:46:25 -0500 Subject: Vim breaks after Python upgrade In-Reply-To: <008c54b4$0$26908$c3e8da3@news.astraweb.com> References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: <20091117184625.GA20149@stinemates.org> At least with Gentoo, there's a command to recompile all of the plugins you have installed when upgrading python versions. Your issue is probably related to that. I don't think VIM uses hardcoded locations for scripts at the core. If you have any specific questions about the errors you're receiving, feel free to submit to the VIM mailing list or stop by the IRC channel: #vim on irc.freenode.org On Tue, Nov 17, 2009 at 04:33:30PM +0000, NickC wrote: > > Perhaps OT, but I figure here is where people have seen this commonly. > > I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now > complaining every startup about missing libraries, presumably as > some plugins run some python code on initialisation. I'm guessing vim is > complaining as it was compiled with python support, and that was 2.5.2, > and the compiled-in python library locations no longer exist. > > I compiled a new vim, so things are ok-ish, but now my system is even > further away from standard distro. I'm also a little surprised vim is so > clunky as to use hard-coded locations. Do I really have to compile a new > vim every python upgrade? > > 'strings vim' shows some ascii that could be the python library > locations. Being quite ignorant of how the linux loader works, could I in > future use sed on the vim binary to change every string of "2.5.2" to > "2.6.2", or are the library locations used by the loader coded in binary > rather than ascii (and so, harder to find)? > > Thanks, > > -- > NickC > -- > http://mail.python.org/mailman/listinfo/python-list From randall.walls at gmail.com Tue Nov 17 13:51:12 2009 From: randall.walls at gmail.com (Randall Walls) Date: Tue, 17 Nov 2009 13:51:12 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey Message-ID: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> Greetings, I'm writing a python script to automate creating ODBC connections on a Windows2008 Server (64bit) platform. I created an ODBC manually (using the GUI), for the purposes of fleshing out the 'check for existing' section of the script. Problem: though I can see the key in regedit (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the file specified'. Googling the error brought up the possibility that this key is being impacted by registry redirection ( http://mail.python.org/pipermail/python-win32/2009-February/008862.html), and thus the need to use _winreg.DisableReflectionKey to correct this. I'm new to using _winreg (but not new to python), and though it sounds simple, I can't figure out how to properly use _winreg.DisableReflectionKey to make the _winreg.OpenKey work properly, and there is nearly 0 documentation on how to use _winreg.DisableReflectionKey (though I would be happy to write something up if I could figure the damned thing out). any help is appreciated. Has anyone else run into this before? I realize that Server 2008 is new and that _winreg.DisableReflectionKey was just added, but I'm still hoping SOMEBODY has run into this before. Many thanks, -- Randall Walls Tyler Technologies, Inc -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at stinemates.org Tue Nov 17 13:51:55 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 13:51:55 -0500 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <20091117185154.GB20149@stinemates.org> This is what the History and Compare URL translates to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=(cc+(detail+(tsid+310746)+(view+hist)))& Some questions.. Do you have an idea on what the tsid is? It looks like it's a unique identifier for the chart and the only thing you'll need to change. Are you only interested in this chart or others? How would you like to extract the data? Is saving the chart enough or would you like to extract values from the chart? On Mon, Nov 16, 2009 at 11:14:26AM +0100, Virgil Stokes wrote: > If one goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > and if you now click on the tab labeled "history and compare" this will > take you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > Finally...This is where I would like to "connect to" the data on a daily > basis or to gather data over different time intervals. I believe that if > I can get some help on this, then I will be able to customize the code > as needed for my own purposes. > > It should be clear that this is financial data on a fond managed by > Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. > > Note, that I do have some experience with Python (2.6 mainly), and find > it a very useful and powerful language. However, I have no experience > with it in the area of Web services. Any suggestions/comments on how to > set up this financial data service project would be greatly appreciated, > and I would be glad to share this project with any interested parties. > > Note, I posted a similar message to the list pywebsvcs; but, received no responses. > > -- V. Stokes > > > -- > http://mail.python.org/mailman/listinfo/python-list From nobody at nowhere.com Tue Nov 17 14:09:22 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:09:22 +0000 Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Tue, 17 Nov 2009 17:31:18 +0000, MRAB wrote: >> And if I ever find the genius who had the brilliant idea of using = >> to mean assignment then I have a particularly nasty dungeon reserved >> just for him. Also a foul-smelling leech-infested swamp for those >> language designers and compiler writers who followed his example. >> (Come to think of it, plagiarizing a bad idea is probably the worse >> evil.) >> > C was derived from BCPL, which used ":=" and "=". ISTR that Ritchie said that he chose "=" because assignment is more common than testing for equality, so C's approach meant less typing. > Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes > did. > > It's a pity that Guido chose to follow C. OTOH, functional languages use "=" for binding (let x = ... in ...), which is more like C initialisation (which also uses "="). Python's "=" is somewhere between assignment and binding. It's arguable that Python should also have ":=" for in-place modification (as opposed to re-binding a name). E.g. for an array, "foo := bar" would be equivalent to "foo[:] = bar". From nobody at nowhere.com Tue Nov 17 14:18:23 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:18:23 +0000 Subject: directory wildcard References: Message-ID: On Mon, 16 Nov 2009 14:19:16 -0800, hong zhang wrote: >> ? ? ? ? print >>f, mcs > > This assigns decimal value, how can I assign Hex here to mcs? print >>f, "%x" % mcs From nick at stinemates.org Tue Nov 17 14:18:52 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 14:18:52 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> Message-ID: <20091117191852.GC20149@stinemates.org> >From _winreg.c: "Disables registry reflection for 32-bit processes running on a 64-bit OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit Operating System. If the key is not on the reflection list, the function succeeds but has noeffect. Disabling reflection for a key does not affect reflection of any subkeys." Are there any subkeys which you also need to disable? Parent keys? On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote: > Greetings, > > I'm writing a python script to automate creating ODBC connections on a > Windows2008 Server (64bit) platform. I created an ODBC manually (using the > GUI), for the purposes of fleshing out the 'check for existing' section of > the script. > > Problem: though I can see the key in regedit > (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an > _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the > file specified'. Googling the error brought up the possibility that this key > is being impacted by registry redirection ( > http://mail.python.org/pipermail/python-win32/2009-February/008862.html), > and thus the need to use _winreg.DisableReflectionKey to correct this. > > I'm new to using _winreg (but not new to python), and though it sounds > simple, I can't figure out how to properly use _winreg.DisableReflectionKey > to make the _winreg.OpenKey work properly, and there is nearly 0 > documentation on how to use _winreg.DisableReflectionKey (though I would be > happy to write something up if I could figure the damned thing out). > > any help is appreciated. Has anyone else run into this before? I realize > that Server 2008 is new and that _winreg.DisableReflectionKey was just > added, but I'm still hoping SOMEBODY has run into this before. > > Many thanks, > > -- > Randall Walls > Tyler Technologies, Inc > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Nov 17 14:19:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 14:19:59 -0500 Subject: YIELD_VALUE Byte Code In-Reply-To: <1257933992.2784.16.camel@laptop> References: <1257933992.2784.16.camel@laptop> Message-ID: Andreas L?scher wrote: > Hi, > I am not sure if this is the right newsgroup, so if not don't hesitate > to tell me. Since there is no CPython internals list, this is the right place to start, even though you might end up having to post a slightly off-topic query to python-devel just to get the attention of whoever has the answer. But there are a few deveoopers who read and post here also. > I am developed a Python to C compiler, so that Byte Code files > automatically can be translated into C Extension Modules. (And it works > pretty well --> http://www.coremountains.com/products/bytecoat/) > > While developing, I found something strange concerning the YIELD_VALUE > OpCode. > > Since Python Version 2.5 it behaves the following: > 1. pop yield value from stack and return it to > a former gen_send_ex() call from Objects/genobject.c > > 2. push the yield value on the stack in gen_send_ex() and return it > > 3. when the generator is executed again, the yield value is > 'poped' from the stack again with the POP_TOP opcode > > Now I found that a little strange: > 1. why is the value removed from the stack, than pushed on the > stack to remove it finally again? the combination of > YIELD_VALUE and TOP_POP seems hard coded in compile.c > which means that a TOP_POP follows every YIELD_VALUE > TOP_POP > > 2. If the semantic of the YIELD_VALUE OpCode has changed, why > is this reached by using another function? Such thing > should be done in the OpCode. > > (e.a.: instead of retval = POP() > --> retval = TOP(); Py_INCREF(retval); ) > > I am a little confused about this. I suspect that what you see reflects the 2.5 change of 'yield x' from a statement to an expression to enable gen.send(). It is possible that someone did the simplest thing that worked, rather than properly rewriting the code. Or maybe the trickery is needed. You can always try a simplyfing patch against the test suite and even submit it if it passes. Terry Jan Reedy From ian at excess.org Tue Nov 17 14:24:43 2009 From: ian at excess.org (Ian Ward) Date: Tue, 17 Nov 2009 14:24:43 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B02F87B.4090305@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From nobody at nowhere.com Tue Nov 17 14:26:46 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:26:46 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > Quote the filenames or escape the spaces: > > C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" > > We've been living with this pain ever since windowed GUIs encouraged users > to put spaces in their file names (Apple, I'm looking at you!). > Fundamentally, if people want the pretty they have to live with the > consequences. We've been living with much worse ever since Unix allowed users to put not only spaces but even newlines in their filenames. At least, those of us who prefer "works" over "sort of works most of the time" have. Then Python 3 decides to pretend that argv and environ and stdin contain text rather than bytes, thereby ensuring that Python 2 will outlive Python 3. From steven.oldner at gmail.com Tue Nov 17 14:27:06 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Tue, 17 Nov 2009 11:27:06 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <908f2c47-ee00-4094-993f-764fa7fce9f4@n35g2000yqm.googlegroups.com> Message-ID: Along the COBOl line is ABAP, the 4gl language from SAP. If today = 'Mon'. message 'oh boy'. elseif today = 'Wed'. message 'Hump day'. elseif today = 'Fri'. message 'TGIF'. else. message 'get to work'. endif. The period is the statement teminator. Indentation and separte lines are just to make it readable. From randall.walls at gmail.com Tue Nov 17 14:29:52 2009 From: randall.walls at gmail.com (Randall Walls) Date: Tue, 17 Nov 2009 14:29:52 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <20091117191852.GC20149@stinemates.org> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> Message-ID: <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> I don't believe so, but it seems like I'm in a catch 22, where I need to _winreg.OpenKey the key first before I can pass it to _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. I did find out that I can open the key using: hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ODBC\ODBC.INI\ DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells the system to look in the 64bit key area, and not under the Wow6432Node. That brings up problem #2, though... I can't seem to CREATE a key in the above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY (in fact it doesn't accept any options other than key, sub_key). _winreg.CreateKey does work, it just puts the key in SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to use one or the other, and not have to account for both. much obliged On Tue, Nov 17, 2009 at 2:18 PM, Nick Stinemates wrote: > From _winreg.c: > > "Disables registry reflection for 32-bit processes running on a 64-bit > OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit > Operating System. If the key is not on the reflection list, the function > succeeds but has noeffect. Disabling reflection for a key does not affect > reflection of any subkeys." > > Are there any subkeys which you also need to disable? Parent keys? > > > On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote: > > Greetings, > > > > I'm writing a python script to automate creating ODBC connections on a > > Windows2008 Server (64bit) platform. I created an ODBC manually (using > the > > GUI), for the purposes of fleshing out the 'check for existing' section > of > > the script. > > > > Problem: though I can see the key in regedit > > (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an > > _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find > the > > file specified'. Googling the error brought up the possibility that this > key > > is being impacted by registry redirection ( > > http://mail.python.org/pipermail/python-win32/2009-February/008862.html > ), > > and thus the need to use _winreg.DisableReflectionKey to correct this. > > > > I'm new to using _winreg (but not new to python), and though it sounds > > simple, I can't figure out how to properly use > _winreg.DisableReflectionKey > > to make the _winreg.OpenKey work properly, and there is nearly 0 > > documentation on how to use _winreg.DisableReflectionKey (though I would > be > > happy to write something up if I could figure the damned thing out). > > > > any help is appreciated. Has anyone else run into this before? I realize > > that Server 2008 is new and that _winreg.DisableReflectionKey was just > > added, but I'm still hoping SOMEBODY has run into this before. > > > > Many thanks, > > > > -- > > Randall Walls > > Tyler Technologies, Inc > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- Randall -------------- next part -------------- An HTML attachment was scrubbed... URL: From russ.paielli at gmail.com Tue Nov 17 14:36:23 2009 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 17 Nov 2009 11:36:23 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <235b457e-767d-461a-bf45-19d53d7affd8@13g2000prl.googlegroups.com> On Nov 17, 7:28?am, Jonathan Saxton wrote: > On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > >> Congratulations, you just reinvented one of the most infamous source of > >> bugs in C, C++, Java, PHP, javascript and quite a few other languages. > >> Believe it or not, but not allowing this in Python was a very deliberate > >> design choice. > > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > > assignment-as-an-expression is nothing compared to the dozens of man- > > minutes saved by having one fewer line of code! > > > *wink* > > And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. ?Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. ?(Come to think of it, plagiarizing a bad idea is probably the worse evil.) There is absolutely nothing wrong with using = for assignment. The problem in C was allowing an assignment within a conditional expression. Now *that* was a bonehead idea! (Hingsight is 20/20, of course.) Python does not allow that, so there is no problem. Nor do most other languages allow it. From gerard.blais at gmail.com Tue Nov 17 14:47:46 2009 From: gerard.blais at gmail.com (Gerry) Date: Tue, 17 Nov 2009 11:47:46 -0800 (PST) Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> On Nov 17, 2:26?pm, Nobody wrote: > On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > > Quote the filenames or escape the spaces: > > > C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" > > > We've been living with this pain ever since windowed GUIs encouraged users ? > > to put spaces in their file names (Apple, I'm looking at you!). ? > > Fundamentally, if people want the pretty they have to live with the ? > > consequences. > > We've been living with much worse ever since Unix allowed users to put > not only spaces but even newlines in their filenames. > > At least, those of us who prefer "works" over "sort of works most of the > time" have. > > Then Python 3 decides to pretend that argv and environ and stdin contain > text rather than bytes, thereby ensuring that Python 2 will outlive Python > 3. How about this: lastarg = " ".join(sys.argv[2:]) From falk at mauve.rahul.net Tue Nov 17 14:48:46 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Tue, 17 Nov 2009 19:48:46 +0000 (UTC) Subject: Code for finding the 1000th prime References: Message-ID: In article , mrholtsr wrote: >I am absolutely new to python and barely past beginner in programming. >Also I am not a mathematician. Can some one give me pointers for >finding the 1000th. prime for a course I am taking over the internet >on Introduction to Computer Science and Programming. Thanks, Ray OK, newbie soccer is over. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Everything you need is in there. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From apt.shansen at gmail.com Tue Nov 17 14:55:47 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 17 Nov 2009 11:55:47 -0800 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c20911171155k3771e054q1476ed78625e2536@mail.gmail.com> On Tue, Nov 17, 2009 at 10:15 AM, r wrote: > On Nov 17, 9:28 am, Jonathan Saxton wrote: > > > And if I ever find the genius who had the brilliant idea of using = to > mean assignment then I have a particularly nasty dungeon reserved just for > him. Also a foul-smelling leech-infested swamp for those language designers > and compiler writers who followed his example. (Come to think of it, > plagiarizing a bad idea is probably the worse evil.) > > I think every new programmer wrestles with this dilemma in their first > days but very soon after accepts it as reality. As for me it made > perfect sense from day one to have '=' mean "assignment" and '==' to > mean "equality". Programming is not mathematics (on the contrary) they > are two sides of a mountain forever unknowing of each other but > sharing the same space. I think the syntax was chosen because the > alternatives are even worse AND since assignment is SO common in > programming, would you *really* rather type two chars instead of one? > Well, equality testing is very very common too... I concede, a bit less common (probably) then assignment, but still. I too never had any issue with getting assignment verses equality-testing with the operations as concepts (except that it is a not terribly uncommon typo for me to type = and mean ==, and I'm quite happy its a syntax error as a result), but in an ideal world? If I were today making my own private little programming language to share with the world... I wish no one would use a single "=" by itself for anything. Neither assignment nor equality testing. For me, the problem comes down to readability; when one sees "x = y", what do they say in their head? "x equals y" -- the meaning of which for an individual can depend on the context and intonation, how they are reading the word "equal" in their head. They might be saying it as a verb, declaring "let x become y", or they my be saying it as an noun, testing "x is equal to y". I don't ever have that problem, but I know a lot of new programmers do and its something which can stick for quite awhile. The word "equal" is just sort of dodgy and fuzzy to the initiate and they start to confuse the two entirely separate concepts (equality testing, assignment) by having the same symbol in programming represent both. Personally! I wish that equality and assignment both got their hands off the bare "=" and let mathematics keep it, and programming take say, ":=" for assignment and "==" for equality testing (or whatever, not advocating a specific syntax) and have "=" by itself be an error all around. So yes, I'd actually much rather type two characters instead of one-- purely in the hypothetical sense that this conversation has gone down. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From kee at kagi.com Tue Nov 17 15:06:27 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 17 Nov 2009 12:06:27 -0800 Subject: Sample CGI for use with Unit Tests In-Reply-To: References: <1257933992.2784.16.camel@laptop> Message-ID: <85F4B6C5-04F2-478D-B44F-BC51629BAC41@kagi.com> I've been looking for examples of how to run unit tests on a CGI. Didn't find any so I came up with this pared down sample. Don't know where to post example code so I figured I'd just email it to this list. Perhaps it will be findable by others in the future. This CGI with unit test examples takes three separate files to make it work. Copy the example code into the files with the names provided and put them all into the same directory. In my current project, I have lots of unit tests for all the functions I have created, but the main CGI code itself had no unit tests and it really needed them. In this example, the CGI itself is a handful of lines that should never change and the bulk of the processing is in a function. This allows me to create unit tests on everything except the few unchanging lines that are the generic CGI in the cgiRunner.py file. Kee Nethery ---------- cgiRunner.py ------------ #!/usr/bin/env python # 2009-11-17 # this is a simple CGI that is structured to allow for unit tests. # this CGI responds to a GET or a POST # send it anything and it will parrot it back along with client # browser info. # This sample has three files: # cgiRunner.py this file # cgiFunctions.py does the bulk of the CGI processing # cgiUnitTest.py the unittest file for this CGI # In this example, the bulk of the CGI processing occurs in a # function. The function is in a separate file so that the # unit tests can be run against it. All this main does is # convert the URL parameters into a dictionary and # feed that dictionary to the CGI function formatClientData() # This is written for Python 2.6.x I'm using 2.6.4 and am trying to use # code that works with Python 3.x and up. import cgi ## so that I can be a web server CGI import cgiFunctions ## where formatClientData() is located def main(): # give me a list of all the user inputs posted to the cgi formPostData = cgi.FieldStorage() # and turn it into a key value pair dictionary # this uses a list comprehension which I modelled after others # examples. Normally I'd do a for loop but figured this # should be as fast as possible. formPostDict = dict((keyValue,formPostData[keyValue].value) \ for keyValue in formPostData) # this is the call to the actual CGI code. cgiResponseList = cgiFunctions.formatClientData(formPostDict) # I like to return a list from functions so that I can put # validity tests in the function. This one basically returns # True if the GET or POST had any parameters sent to the # CGI, False if none. Just an example. if cgiResponseList[1] == True: cgiResponseData = cgiResponseList[0] else: # if no parameters were sent to the CGI, the response # describes how to add parameters to the URL that # triggers this CGI. cgiResponseData = cgiResponseList[0] + '\n\n' + 'The POST \ or GET you submitted had no user supplied parameters so other than \ client data. The only data that can be returned is the data \ provided by your web client. Most CGIs accept parameters and \ return results based upon those parameters. To provide GET data \ try adding a parameter like "sample=some_text". A URL with \ "sample" as a parameter (and sample2 as a second parameter) might \ look like \n"http://machine.domain.com/cgi-bin/SimpleCgiUnittest.\ py?sample=some_text&sample2=more_text".' # Python 3.x style print statement that works in Python 2.6.x print('Content-type: text/html') print('') print(cgiResponseData) main() ---------- cgiFunctions.py ------------ #!/usr/bin/env python # 2009-11-17 import os ## gets the CGI client values like IP and URL def formatClientData(formPostDict): """ This function contains the guts of the CGI response. It is designed as a function so that I can use unittest to test it. """ # create the output variable and then add stuff to it cgiResponseData = '' # I like to return lists from functions so that more than # some kind of validity checking comes back from the # function. In this case it's a lame validity check but # it's an example. hasFormPostData = (len(formPostDict) > 0) # for something interesting to return, CGI client data cgiResponseData = cgiResponseData + 'from client browser:\n' for cgiKey in list(os.environ.keys()): # for each client data value, add a line to the output cgiResponseData = cgiResponseData + \ str(cgiKey) + ' = ' + os.environ[cgiKey] + '\n' cgiResponseData = cgiResponseData + '\n\nfrom the URL \ POST or GET:\n\n' # cycle through and output the POST or GET inputs for keyValuePair in formPostDict: cgiResponseData = cgiResponseData + \ keyValuePair + ' = ' + formPostDict[keyValuePair] + '\n' return [cgiResponseData, hasFormPostData] ---------- cgiUnitTest.py ------------ #!/usr/bin/env python import cgiFunctions import unittest class cgiTests(unittest.TestCase): ## For debugging of unit tests, to get one unit test ## to run first, UPPERCASE the first char of the unittext ## name (after "test_") so that it runs first then lower ## case it when it should be part of the group. def setUp(self): # this is for setting external stuff before unit tests # this gets called before EVERY test pass def test_formatClientData_With(self): inputDict = {'sample': 'test_text', 'drink': 'tea'} cgiResponse = '''from the URL POST or GET: sample = test_text drink = tea ''' expected0 = True expected1 = True outputList = cgiFunctions.formatClientData(inputDict) outputBoolean0 = (cgiResponse in outputList[0]) self.assertEqual(outputBoolean0,expected0) self.assertEqual(outputList[1],expected1) def test_formatClientData_Without(self): inputDict = {} expected1 = False outputList = cgiFunctions.formatClientData(inputDict) self.assertEqual(outputList[1],expected1) if __name__ == '__main__': testSuite=unittest.TestLoader().loadTestsFromTestCase(cgiTests) unittest.TextTestRunner(verbosity=2).run(testSuite) From tjreedy at udel.edu Tue Nov 17 15:29:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 15:29:47 -0500 Subject: Code for finding the 1000th prime In-Reply-To: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray Now for a serious answer ;-) The intent of the problem is that you write a function prime_n(n) that returns the nth prime, where 2 is the first. This is different from prime(n), which would return True/False depending on whether n is a prime or not. Then you are to execute prime_n(1000) and submit that. The person who set the problem expects that you will have learned and still remember the definition of prime numbers and a few basic facts about them. Or that you will look these up on a site such as Wikipedia. Since you are not taking a math course, you should expect that the basic facts will be enough. For this problem, the relevant fact is that there is no formula that will directly compute the nth prime from n. Instead, one must generate the first, the second, the third, ...., until reaching the nth. The easiest and direct way to do this is to use primes 1 to i to test whether counts greater than prime i are primes, until you find the (i+1)th prime. You may find references to the Sieve of Eratosthenes. It generates all the primes up to a certain number N by testing prime divisors in a different order. But to use it find the nth, one has to guess that some N will be larger than the nth, run the Sieve, and see whether you got the nth or have to try a larger value of N. For the 1000th, it turns out that N=10000 works. In general picking an N such that N * log(N) is 'comfortably' larger than n will work. But this guessing is not actually necessary in Python which has *expandable* arrays. A different approach, at least as difficult, is to write a program that looks up the answer by accessing a public database of primes. http://en.wikipedia.org/wiki/List_of_primes lists some of these in its External Links section. Terry Jan Reedy From mark.kecko at gmail.com Tue Nov 17 15:30:49 2009 From: mark.kecko at gmail.com (scoopseven) Date: Tue, 17 Nov 2009 12:30:49 -0800 (PST) Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> <030f77ec$0$1313$c3e8da3@news.astraweb.com> Message-ID: On Nov 14, 11:55?pm, Steven D'Aprano wrote: > On Fri, 13 Nov 2009 14:10:10 -0800, scoopseven wrote: > > I actually had a queryset that was dynamically generated, so I ended up > > having to use the eval function, like this... > > > d = {} > > for thing in things: > > ? ? ? ? query_name = 'thing_' + str(thing.id) > > ? ? ? ? query_string = 'Thing.objects.filter(type=' + str(thing.id) + ? > > ').order_by(\'-date\')[:3]' > > ? ? ? ? executable_string = query_name + ' = Thing.objects.filter > > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > > ? ? ? ? exec(executable_string) > > ? ? ? ? d[query_name] = eval(query_string) > > What an unmaintainable mess. > > If I've understood it, you can make it less crap by (1) getting rid of > the unnecessary escaped quotes, (2) avoiding generating the same strings > multiple times, and (3) avoiding string concatenation. > > d = {} > for thing in things: > ? ? expr = "Thing.objects.filter(type=%s).order_by('-date')[:3]" > ? ? expr = rhs % thing.id > ? ? name = "thing_%s" % thing.id > ? ? exec("%s = %s" % (name, expr)) > ? ? d[name] = eval(expr) > > What else can we do to fix it? Firstly, why are you creating local > variables "thing_XXX" (where XXX is the thing ID) *and* dictionary keys > of exactly the same name? I'm sure you don't need the local variables. > (If you think you do, you almost certainly don't.) That gets rid of the > exec. > > Next, let's get rid of the eval: > > d = {} > for thing in things: > ? ? x = thing.id > ? ? name = "thing_%s" % x > ? ? d[name] = Thing.objects.filter(type=x).order_by('-date')[:3] > > About half the size, ten times the speed, and 1000 times the readability. > > Unless I've missed something, you don't need either exec or eval. > > -- > Steven Steven, This worked like a charm! Thank you for your insight, it's greatly appreciated. Mark From http Tue Nov 17 15:48:05 2009 From: http (Paul Rubin) Date: 17 Nov 2009 12:48:05 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <7x1vjwswsa.fsf@ruckus.brouhaha.com> Aaron Watters writes: > ... and I still have an issue with the whole "Python is slow" > meme. The reason NASA doesn't build a faster Python is because > Python when augmented with FORTRAN libraries... Do you think that numerics is the only area of programming where users care about speed? > And when someone implements a Mercurial replacement in GO (or C# > or Java) which is faster and more useful than Mercurial, I'll > be very impressed. What about Git? Some people prefer it. From callmeclaudius at gmail.com Tue Nov 17 16:19:53 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Tue, 17 Nov 2009 13:19:53 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <4e29dc6f-0dec-4249-ade8-7ace85eb810c@c3g2000yqd.googlegroups.com> On Nov 16, 5:06?am, me wrote: > Good People > > I do not write stuff for humans, as it has been my job to remove > humans from the loop. But I have to make a front end to a > component database where everything was built in Python. > > I have looked at the Tk stuff that is built into Python -> not > acceptable. So looking at wxGlade, Boa Constructor, Python Card. > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. BlackAdder IDE seems to have > this built-in, but am loathe to buy into another GUI tool for a > single job. > > I have not been able to find a decent Python gui builder. The > last time I did gui garbage was with Borland C++ Builder which > was ok because I was only using win boxen for that project. This > time I am using both Linux and Win. > > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? > > thanks much, > me Glade is pretty easy to use, especially for a simple front end, if you already know python, then the amount of GTK you'd have to learn would be very minimal (5-15 minute crash course in it should suffice.) build your GUI in Glade, link the python code to the xml file, and the go back to coding non-gui stuff in no time. The Glade utility is free software so there's no expense (unless you get charged by the byte on your downloads.) From pengyu.ut at gmail.com Tue Nov 17 16:19:56 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 15:19:56 -0600 Subject: Anything equivalent to cassert in C++? Message-ID: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> There are some assertion code (testing if a condition is false, if it is false, raise an Error object) in my python, which is useful when I test my package. But such case would never occur when in the produce code. If I keep them in if statement, it will take some runtime. I'm wondering what is the practice that take care of the assertion code in python. From ben+python at benfinney.id.au Tue Nov 17 16:21:40 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 18 Nov 2009 08:21:40 +1100 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <87hbssn8yj.fsf@benfinney.id.au> Scott David Daniels writes: > Well, let's see. You want to do gui work without learning things. Good > luck with that. If you discover how, I'd like to learn tensor analysis > without using symbols or operations more complex than addition and > subtraction. Maybe your groundwork can help me out with that. > > I must be in a really cranky mood today. Yeah, it seems that way. Best to let such replies stew in your ?Drafts? folder, get the catharsis from having vented your frustration, then delete them unsent once you feel better. Works wonders for me :-) -- \ ?If society were bound to invent technologies which could only | `\ be used entirely within the law, then we would still be sitting | _o__) in caves sucking our feet.? ?Gene Kan, creator of Gnutella | Ben Finney From tundra at tundraware.com Tue Nov 17 16:25:32 2009 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 17 Nov 2009 15:25:32 -0600 Subject: python gui builders In-Reply-To: <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: Simon Hibbs wrote: > On 16 Nov, 10:06, me wrote: > >> What Python gui builder is well supported, does not require me >> to learn another framework/library, and can crank out stuff for >> multiple platforms ? > > You're looking for a framework/library that doesn't require you to > learn it. OK.... > > I've had this problem for a few years. I've tried PythonCard, > WxWidgets with WxDesigner, BoaConstructor, etc. None of them come > anywhere close to PyQT/QTDesigner. > > Dion't get Blackadder It hasn't been updated for several years and is > a dead project. In any case it uses QTDesigner for GUI layout anyway. > You're better off using Eric or Wing if you want a decent IDE. > > QT does have a learning curve of course, but you get a lot of power > back in return for the investment. I'm just coming to grips with it's > MVC framework and the book "Rapid GUI Programming with Python and Qt" > is very helpful with that. > > I wouldn't completely dismiss Tkinter. It's too simple for complex > GUIs but I still think it has it's place for basic utilities. > > Simon Hibbs +1 Tkinter for the simple stuff -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From sajmikins at gmail.com Tue Nov 17 17:01:38 2009 From: sajmikins at gmail.com (Simon Forman) Date: Tue, 17 Nov 2009 17:01:38 -0500 Subject: Anything equivalent to cassert in C++? In-Reply-To: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> References: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> Message-ID: <50f98a4c0911171401l5eac45f5sc29267d89f244b61@mail.gmail.com> On Tue, Nov 17, 2009 at 4:19 PM, Peng Yu wrote: > There are some assertion code (testing if a condition is false, if it > is false, raise an Error object) in my python, which is useful when I > test my package. ?But such case would never occur when in the produce > code. If I keep them in if statement, it will take some runtime. I'm > wondering what is the practice that take care of the assertion code in > python. Read the manual: http://docs.python.org/reference/simple_stmts.html#the-assert-statement "In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time." HTH, ~Simon From nobody at nowhere.com Tue Nov 17 17:19:49 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 22:19:49 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote: > How about this: > > lastarg = " ".join(sys.argv[2:]) What about it? IOW, why would you want to do that? From azeynel1 at gmail.com Tue Nov 17 17:38:55 2009 From: azeynel1 at gmail.com (Zeynel) Date: Tue, 17 Nov 2009 14:38:55 -0800 (PST) Subject: Beautifulsoup code that is not running Message-ID: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Hello, Please help with this code suggested in the beautifulsoup group http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa >>> from BeautifulSoup import BeautifulSoup >>> soup = BeautifulSoup (file("test.html").read()) >>> title = soup.find('title') >>> titleString = title.string >>> open('extract.text', 'w').write(titleString) This runs without an error, but nothing is written into the extract.text file. test.html has tags in it. Thank you. From cournape at gmail.com Tue Nov 17 17:43:44 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 18 Nov 2009 07:43:44 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: <7x1vjwswsa.fsf@ruckus.brouhaha.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7x1vjwswsa.fsf@ruckus.brouhaha.com> Message-ID: <5b8d13220911171443o466d72b6s28748a495b823b09@mail.gmail.com> On Wed, Nov 18, 2009 at 5:48 AM, Paul Rubin wrote: > > What about Git? ?Some people prefer it. Git is an interesting example, because it both really pushes performance into its core structure and reasonably complete implementations exist in other languages. In particular, jgit is implemented in java by one of the core git developer, here is what he has to say: http://marc.info/?l=git&m=124111702609723&w=2 I found the comment on "optimizing 5% here and 5 % there" interesting. It is often claimed that optimization should be done after having found the hotspot, but that does not always apply, and I think git is a good example of that. In those cases, using python as the main language does not work well, at least in my experience. Rewriting the slow parts in a compiled language only works if you can identify the slow parts, and even in numerical code, that's not always possible (this tends to happen when you need to deal with many objects interacting together, for example). David From tjreedy at udel.edu Tue Nov 17 17:50:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 17:50:04 -0500 Subject: ast manipulation In-Reply-To: References: Message-ID: Tsize wrote: > Hello, > > I am hoping for a little help. I have been playing with the python > ast module and have run into > an issue that I need a little push on. I would like to be able to > change a specific element in a > specific node in an ast then compile the resulting ast. If you can identify the specific nodes you want to change, no problem > Consider the simplified example below > with its output. In this example I would like a way to change a > specific addition operation. With the NodeTransformer I see how to > change every addition operator but not how to change a specific one. Which specific one or one? > I would like this to work on both the 2.6 and 3.1 branches. Ideally I > would like to read a file, count the instances of an operation of > interest and then use an index to make the changes. If 'specific one' means number i, great. In not, not. > > I am probably missing something simple but I am lost right now. You have not said what 'specific one' means. Nor what your general goal is, why you want to change asts. > > import ast > > class SwitchMinusPlus(ast.NodeTransformer): > > def visit_BinOp(self, node): > node = self.generic_visit(node) > if isinstance(node.op, ast.Add): if isinstance(node.op, ast.Add) and isspecificnode(node): > node.op = ast.Sub() > return node > > myfile = open('trivial.py').read() > print myfile > tree = compile(myfile, '', 'exec', ast.PyCF_ONLY_AST) > print ast.dump(tree, annotate_fields=False, include_attributes=False) > node = SwitchMinusPlus().visit(ast.parse(myfile)) > print ast.dump(node, annotate_fields=False, include_attributes=False) > > Which gives the following output: Note that this code changes the > addition operator to an > subtraction operator at the AST level for every instance. > > a = 8 > b = 6 > c = b + a > d = c + a > Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store > ())], Num(6)), > Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a', > Load()))), > Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a', > Load())))]) > > Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store > ())], Num(6)), > Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a', > Load()))), > Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a', > Load())))]) From tjreedy at udel.edu Tue Nov 17 17:56:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 17:56:44 -0500 Subject: Vim breaks after Python upgrade In-Reply-To: <008c54b4$0$26908$c3e8da3@news.astraweb.com> References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: NickC wrote: > Perhaps OT, but I figure here is where people have seen this commonly. > > I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now > complaining every startup about missing libraries, presumably as > some plugins run some python code on initialisation. I'm guessing vim is > complaining as it was compiled with python support, and that was 2.5.2, > and the compiled-in python library locations no longer exist. I believe you should have added 2.6.2 as an alternate installation and left 2.5.x alone. There have been several threads discussing this. > I compiled a new vim, so things are ok-ish, but now my system is even > further away from standard distro. I'm also a little surprised vim is so > clunky as to use hard-coded locations. Do I really have to compile a new > vim every python upgrade? Not if you add rather than substitute. > > 'strings vim' shows some ascii that could be the python library > locations. Being quite ignorant of how the linux loader works, could I in > future use sed on the vim binary to change every string of "2.5.2" to > "2.6.2", or are the library locations used by the loader coded in binary > rather than ascii (and so, harder to find)? > > Thanks, > From greg at cosc.canterbury.ac.nz Tue Nov 17 18:05:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:05:55 +1300 Subject: ANN: PyGUI 2.1 In-Reply-To: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> References: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> Message-ID: <4B032C53.9030406@cosc.canterbury.ac.nz> r wrote: > I really like this! > > But after looking over your pyGUI it does "seem" that Tkinter has a > richer widget set. PyGUI is a work in progress. I plan to add more widgets, but it will take a while to catch up with what's available in Tkinter and other GUI toolkits. I tend to add widgets as and when I need them for something I'm doing. If anyone has a widget they particularly want, let me know and I'll try to give it priority. From fabio at aptana.com Tue Nov 17 18:09:07 2009 From: fabio at aptana.com (Fabio Zadrozny) Date: Tue, 17 Nov 2009 21:09:07 -0200 Subject: Pydev 1.5.1 Released Message-ID: Hi All, Pydev 1.5.1 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Improvements in the AST rewriter * Improvements on the refactoring engine: o No longer using BRM o Merged with the latest PEPTIC o Inline local available o Extract method bug-fixes o Extract local on multi-line o Generating properties using coding style defined in preferences o Add after current method option added to extract method o A bunch of other corner-case situations were fixed * Bug-fixes: o Minor editor improvements o Adding default forced builtins on all platforms (e.g.: time, math, etc) which wouldn't be on sys.builtin_module_names on some python installations o Adding 'numpy' and 'Image' to the forced builtins always o Ctrl+1: Generate docstring minor fixes o Ctrl+1: Assign to local now follows coding style preferences properly o Exponential with uppercase E working on code-formatting o When a set/get method is found in code-completion for a java class an NPE is no longer thrown o Backspace properly treated in block mode o Setting IRONPYTHONPATH when dealing with Iron Python (projects could not be referenced) o No longer giving spurious 'statement has no effect' inside of lambda and decorators o Fixed new exec in python 3k o Fixed NPE when breakpoint is related to a resource in a removed project o Fixed import problem on regexp that could lead to a recursion. o No longer giving NPE when debugging with the register view open o List access be treated as __getitem__() in the list -- patch from Tassilo Barth o Fix for invalid auto-self added when typing What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and Iron Python 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 - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From greg at cosc.canterbury.ac.nz Tue Nov 17 18:24:37 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:24:37 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <7mgpm5F27pqogU1@mid.individual.net> David Cournapeau wrote: > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. Relying on a lot of > compiled libraries goes against it. If it were necessary to write a new compiled library every time you wanted to solve a new problem, that would be true. But it's not like that if you pick the right libraries. NumPy, for example, is *extremely* flexible. Someone put in the effort, once, to write it and make it fast -- and now an endless variety of programs can be written very easily in Python to make use of it. -- Greg From fetchinson at googlemail.com Tue Nov 17 18:24:51 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 18 Nov 2009 00:24:51 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <4B0152A4.7050307@excess.org> References: <4B0152A4.7050307@excess.org> Message-ID: On 11/16/09, Ian Ward wrote: > Announcing Urwid 0.9.9 > ---------------------- > > Urwid home page: > http://excess.org/urwid/ > > Updated screen shots: > http://excess.org/urwid/examples.html How did you make the html 'screenshots'? I guess you have some kind of urwid2html tool or some such or is it plain ncurses? Urwid is really cool! Cheers, Daniel > Tarball: > http://excess.org/urwid/urwid-0.9.9.tar.gz > > RSS: > http://excess.org/feeds/tag/urwid/ > > > About this release: > =================== > > This release includes many new features developed since the last major > release. Urwid now supports 256 and 88 color terminals. A new MainLoop > class has been introduced to tie together widgets, user input, screen > display and an event loop. Twisted and GLib-based event loops are now > supported directly. A new AttrMap class now allows mapping any > attribute to any other attribute. Most of the code base has been > cleaned up and now has better documentation and testing. Lots of other > improvements are listed below. > > > New in this release: > ==================== > > * New support for 256 and 88 color terminals with raw_display > and html_fragment display modules > > * New palette_test example program to demonstrate high color > modes > > * New AttrSpec class for specifying specific colors instead of > using attributes defined in the screen's palette > > * New MainLoop class ties together widgets, user input, screen > display and one of a number of new event loops, removing the > need for tedious, error-prone boilerplate code > > * New GLibEventLoop allows running Urwid applications with GLib > (makes D-Bus integration easier) > > * New TwistedEventLoop allows running Urwid with a Twisted reactor > > * Added new docstrings and doctests to many widget classes > > * New AttrMap widget supports mapping any attribute to any other > attribute, replaces AttrWrap widget > > * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, > Filler and LineBox widgets creates a common method for accessing > and updating their contained widgets > > * New left and right values may be specified in Padding widgets > > * New command_map for specifying which keys cause actions such as > clicking Button widgets and scrolling ListBox widgets > > * New tty_signal_keys() method of raw_display.Screen and > curses_display.Screen allows changing or disabling the keys used > to send signals to the application > > * Added helpful __repr__ for many widget classes > > * Updated all example programs to use MainLoop class > > * Updated tutorial with MainLoop usage and improved examples > > * Renamed WidgetWrap.w to _w, indicating its intended use as a way > to implement a widget with other widgets, not necessarily as > a container for other widgets > > * Replaced all tabs with 4 spaces, code is now more aerodynamic > (and PEP 8 compliant) > > * Added saving of stdin and stdout in raw_display module allowing > the originals to be redirected > > * Updated BigText widget's HalfBlock5x4Font > > * Fixed graph example CPU usage when animation is stopped > > * Fixed a memory leak related to objects listening for signals > > * Fixed a Popen3 deprecation warning > > > About Urwid > =========== > > Urwid is a console UI library for Python. It features fluid interface > resizing, UTF-8 support, multiple text layouts, simple attribute markup, > powerful scrolling list boxes and flexible interface design. > > Urwid is released under the GNU LGPL. > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kw at codebykevin.com Tue Nov 17 18:25:21 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 17 Nov 2009 18:25:21 -0500 Subject: python gui builders In-Reply-To: References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <5634a$4b0330e1$4275d90a$22348@FUSE.NET> On 11/17/09 4:25 PM, Tim Daneliuk wrote: > > +1 Tkinter for the simple stuff > You can actually use Tkinter to do quite sophisticated GUI's that rival anything found in Qt or wx... -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tjreedy at udel.edu Tue Nov 17 18:31:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 18:31:25 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: David Cournapeau wrote: > On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: >>> I don't think Python and Go address the same set of programmer >>> desires. For example, Go has a static type system. Some programmers >>> find static type systems to be useless or undesirable. Others find >>> them extremely helpful and want to use them them. If you're a >>> programmer who wants a static type system, you'll probably prefer Go >>> to Python, and vice versa. That has nothing to do with implementation >>> speed or development expenditures. If Google spent a million dollars >>> adding static types to Python, it wouldn't be Python any more. >> ... and I still have an issue with the whole "Python is slow" >> meme. The reason NASA doesn't build a faster Python is because >> Python *when augmented with FORTRAN libraries that have been >> tested and optimized for decades and are worth billions of dollars >> and don't need to be rewritten* is very fast. > > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. I find it a bit odd that people are so resistant to evaluating Python as it was designed to be. As Guido designed the language, he designed the implementation to be open and easily extended by assembler, Fortran, and C. No one carps about the fact the dictionary key lookup, say, is writen in (optimized) C rather than pretty Python. Why should Basic Linear Algebra Subroutines (BLAS) be any different? > One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. It is readable by humans because it was designed for that purpose. > Relying on a lot of compiled libraries goes against it. On the contrary, Python could be optimized for human readability because it was expected that heavy computation would be delegated to other code. There is no need for scientists to read the optimized code in BLAS, LINPACK, and FFTPACK, in assembler, Fortran, and/or C, which are incorporated in Numpy. It is unfortunate that there is not yet a 3.1 version of Numpy. That is what 3.1 most needs to run faster, as fast as intended. > I think that python with its scientific extensions is a fantastic > tool, but I would certainly not mind if it were ten times faster. Python today is at least 100x as fast as 1.4 (my first version) was in its time. Which is to say, Python today is as fast as C was then. The problem for the future is the switch to multiple cores for further speedups. Terry Jan Reedy From Brian.Mingus at Colorado.EDU Tue Nov 17 18:33:01 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Tue, 17 Nov 2009 16:33:01 -0700 Subject: Beautifulsoup code that is not running In-Reply-To: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Message-ID: <9839a05c0911171533p3ed4162dyae5171d4a7d0101b@mail.gmail.com> On Tue, Nov 17, 2009 at 3:38 PM, Zeynel wrote: > Hello, > > Please help with this code suggested in the beautifulsoup group > > http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa > > >>> from BeautifulSoup import BeautifulSoup > > >>> soup = BeautifulSoup (file("test.html").read()) > >>> title = soup.find('title') > >>> titleString = title.string > >>> open('extract.text', 'w').write(titleString) The problem has nothing to do with BeautifulSoup >>> from BeautifulSoup import BeautifulSoup >>> print BeautifulSoup('mytitle').title.string mytitle -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Tue Nov 17 18:33:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:33:55 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7x1vjwswsa.fsf@ruckus.brouhaha.com> Message-ID: <7mgq7jF3hp04tU1@mid.individual.net> David Cournapeau wrote: > It is often claimed that optimization should be done after having > found the hotspot, but that does not always apply It's more that if you *do* have a hotspot, you had better find it and direct your efforts there first. E.g. if there is a hotspot taking 99% of the time, then optimising elsewhere can't possibly improve the overall time by more than 1% at the very most. Once there are no hotspots left, then there may be further spread-out savings to be made. -- Greg From rhodri at wildebst.demon.co.uk Tue Nov 17 18:57:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 17 Nov 2009 23:57:55 -0000 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 19:26:46 -0000, Nobody wrote: > On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > >> Quote the filenames or escape the spaces: >> >> C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" >> >> We've been living with this pain ever since windowed GUIs encouraged >> users >> to put spaces in their file names (Apple, I'm looking at you!). >> Fundamentally, if people want the pretty they have to live with the >> consequences. > > We've been living with much worse ever since Unix allowed users to put > not only spaces but even newlines in their filenames. You'll notice I said "encouraged", not "allowed". -- Rhodri James *-* Wildebeest Herder to the Masses From henryzhang62 at yahoo.com Tue Nov 17 19:02:57 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 16:02:57 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> Message-ID: <89884.96844.qm@web57901.mail.re3.yahoo.com> List, My python script has a strange error. cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx work perfectly. But following get error like: print >>f, cont_tx IOError: [Errno 28] No space left on device def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx Too many layers? Thanks for help. ---henry From bigboss1964 at gmail.com Tue Nov 17 19:03:27 2009 From: bigboss1964 at gmail.com (TerryP) Date: Tue, 17 Nov 2009 16:03:27 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 4:54?pm, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? If you search Google, you will likely find some huge comparason of if or flow control statements in general, in zillions of languages. I personally like if expr [then | { | do | :] the code [done | } | ] As long as it starts with if and is immediately followed by expr, I could care less about the rest, unless someone forgets to document it ;-). Lisps cond is also sexy. From bigboss1964 at gmail.com Tue Nov 17 19:06:05 2009 From: bigboss1964 at gmail.com (TerryP) Date: Tue, 17 Nov 2009 16:06:05 -0800 (PST) Subject: Vim breaks after Python upgrade References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: In my experience (FreeBSD), compiling vim with Python, Perl, or Ruby support (etc), generally requires recompiling vim after upgrading the corresponding language. Note also that (if like me) you manage vim installations `by hand` on all systems, rather then use the systems package management system, upgrade tools can not magically do it. From wolfgang at rohdewald.de Tue Nov 17 19:17:49 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 18 Nov 2009 01:17:49 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: <200911180117.49361.wolfgang@rohdewald.de> On Wednesday 18 November 2009, Terry Reedy wrote: > Python today is at least 100x as fast as 1.4 (my first version) was > in its time. Which is to say, Python today is as fast as C was > then on the same hardware? That must have been a very buggy C compiler. Or was it a C interpreter? -- Wolfgang From wuwei23 at gmail.com Tue Nov 17 19:25:16 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 16:25:16 -0800 (PST) Subject: ANN: Urwid 0.9.9 - Console UI Library References: <4B0152A4.7050307@excess.org> Message-ID: <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> Daniel Fetchinson wrote: > How did you make the html 'screenshots'? I guess you have some kind of > urwid2html tool or some such or is it plain ncurses? It's all handled in the demo code. This is from tour.py: if urwid.web_display.is_web_request(): screen = urwid.web_display.Screen() else: screen = urwid.raw_display.Screen() > Urwid is really cool! No argument there :) From cournape at gmail.com Tue Nov 17 19:45:28 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 18 Nov 2009 09:45:28 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: References: <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: <5b8d13220911171645r5bd56cd5n1021e3aa8336b2bb@mail.gmail.com> On Wed, Nov 18, 2009 at 8:31 AM, Terry Reedy wrote: > David Cournapeau wrote: >> >> On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters >> wrote: >>>> >>>> I don't think Python and Go address the same set of programmer >>>> desires. ?For example, Go has a static type system. ?Some programmers >>>> find static type systems to be useless or undesirable. ?Others find >>>> them extremely helpful and want to use them them. ?If you're a >>>> programmer who wants a static type system, you'll probably prefer Go >>>> to Python, and vice versa. ?That has nothing to do with implementation >>>> speed or development expenditures. ?If Google spent a million dollars >>>> adding static types to Python, it wouldn't be Python any more. >>> >>> ... and I still have an issue with the whole "Python is slow" >>> meme. ?The reason NASA doesn't build a faster Python is because >>> Python *when augmented with FORTRAN libraries that have been >>> tested and optimized for decades and are worth billions of dollars >>> and don't need to be rewritten* is very fast. >> >> It is a bit odd to dismiss "python is slow" by saying that you can >> extend it with fortran. > > I find it a bit odd that people are so resistant to evaluating Python as it > was designed to be. As Guido designed the language, he designed the > implementation to be open and easily extended by assembler, Fortran, and C. I am well aware of that fact - that's one of the major reason why I decided to go the python route a few years ago instead of matlab, because matlab C api is so limited. > No one carps about the fact the dictionary key lookup, say, is writen in > (optimized) C rather than pretty Python. Why should Basic Linear Algebra > Subroutines (BLAS) be any different? BLAS/LAPACK explicitly contains stuff that can easily be factored out in a library. Linear algebra in general works well because the basic data structures are well understood. You can deal with those as black boxes most of the time (I for example have no idea how most of LAPACK algo work, except for the simple ones). But that's not always the case for numerical computations. Sometimes, you need to be able to go inside the black box, and that's where python is sometimes limited for me because of its cost. To be more concrete, one of my area is speech processing/speech recognition. Most of current engines are based on Hidden Markov Models, and there are a few well known libraries to deal with those, most of the time written in C/C++. You can wrap those in python (and people do), but you cannot really use those unless you deal with them at a high level. If you want to change some core algorithms (to deal with new topology, etc....), you cannot do it without going into C. It would be great to write my own HMM library in python, but I cannot do it because it would be way too slow. There is no easy black-box which I could wrap so that I keep enough flexibility without sacrificing too much speed. Said differently, I would be willing to be one order of magnitude slower than say C, but not 2 to 3 as currently in python when you cannot leverage existing libraries. When the code can be vectorized, numpy and scipy give me this. >> Relying on a lot of compiled libraries goes against it. > > On the contrary, Python could be optimized for human readability because it > was expected that heavy computation would be delegated to other code. There > is no need for scientists to read the optimized code in BLAS, LINPACK, and > FFTPACK, in assembler, Fortran, and/or C, which are incorporated in Numpy. I know all that (I am one of the main numpy develop nowadays), and indeed, writing blas/lapack in python does not make much sense. I am talking about libraries *I* would write. Scipy, for example, contains more fortran and C code than python, without counting the libraries we wrap, and a lot of it is because of speed/memory concern. David From lie.1296 at gmail.com Tue Nov 17 19:59:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 18 Nov 2009 11:59:08 +1100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: References: Message-ID: <4b034728$1@dnews.tpgi.com.au> hong zhang wrote: > List, > > My python script has a strange error. > > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx > > work perfectly. > > But following get error like: > print >>f, cont_tx > IOError: [Errno 28] No space left on device > > def do_cont_tx( is_start): > global cont_tx_started, stdscr > if is_start == START and not cont_tx_started: > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx > > Too many layers? > Thanks for help. Apparently the harddisk where you stored the file is full? From clp2 at rebertia.com Tue Nov 17 20:14:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 17:14:22 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <50697b2c0911171714y1f3e8eadre495b0dc948798db@mail.gmail.com> On Tue, Nov 17, 2009 at 8:41 AM, Rustom Mody wrote: > "Language L is (in)efficient. No! Only implementations are (in)efficient" > > I am reminded of a personal anecdote. ?It happened about 20 years ago > but is still fresh and this thread reminds me of it. > > I was attending some workshop on theoretical computer science. > I gave a talk on Haskell. > > I showed off all the good-stuff -- pattern matching, lazy lists, > infinite data structures, etc etc. > Somebody asked me: Isnt all this very inefficient? > Now at that time I was a strong adherent of the Dijkstra-religion and > this viewpoint "efficiency has nothing to do with languages, only > implementations" traces to him. So I quoted that. > > Slowing the venerable P S Thiagarajan got up and asked me: > Lets say that I have a language with a type 'Proposition' > And I have an operation on proposition called sat [ sat(p) returns > true if p is satisfiable]... > > I wont complete the tale other than to say that Ive never had the wind > in my sails taken out so completely! > > So Vincent? I wonder what you would have said in my place? I'm not Vincent, but: The sat() operation is by definition in inefficient, regardless of language? Cheers, Chris -- http://blog.rebertia.com From see at signature.invalid Tue Nov 17 20:33:24 2009 From: see at signature.invalid (Nigel Rowe) Date: Wed, 18 Nov 2009 12:33:24 +1100 Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: On Tue, 17 Nov 2009 05:21, Tobiah wrote in comp.lang.python <>: > >>> Let me >>> be clear, given 2min, how many primes can you find, they need not be in >>> order or consecutive. > > Do they have to go from low to high? :( ) 1) google list of prime numbers 2) see "Prime numbers list" in the results (number 3 in the results) 3) click link that leads to www.prime-numbers.org I found 455042511 prime numbers in approx 15 seconds. Is that what you wanted? -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) fisheggs (stop) name From henryzhang62 at yahoo.com Tue Nov 17 20:40:05 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 17:40:05 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b034728$1@dnews.tpgi.com.au> Message-ID: <530564.99251.qm@web57905.mail.re3.yahoo.com> --- On Tue, 11/17/09, Lie Ryan wrote: > From: Lie Ryan > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Tuesday, November 17, 2009, 6:59 PM > hong zhang wrote: > > List, > > > > My python script has a strange error. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > ??? with open(i, 'w') as f: > > ??? ??? print >>f, > cont_tx > > > > work perfectly. > > > > But following get error like: > > print >>f, cont_tx > > IOError: [Errno 28] No space left on device > > > > def do_cont_tx( is_start): > > ??? global cont_tx_started, stdscr > > ??? if is_start == START and not > cont_tx_started: > > ??? ??? cont_tx = 1 > > ??? ??? for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > ??? ??? > ??? with open(i, 'w') as f: > > ??? ??? > ??? ??? print >>f, > cont_tx > > > > Too many layers? > > Thanks for help. > > Apparently the harddisk where you stored the file is full? I have plenty space see: $ df -l Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 74027808 4910016 65357380 7% / but following is good. cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx > -- http://mail.python.org/mailman/listinfo/python-list > From python.list at tim.thechases.com Tue Nov 17 20:47:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Nov 2009 19:47:25 -0600 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b034728$1@dnews.tpgi.com.au> References: <4b034728$1@dnews.tpgi.com.au> Message-ID: <4B03522D.90909@tim.thechases.com> >> for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> with open(i, 'w') as f: >> print >>f, cont_tx >> >> work perfectly. >> >> But following get error like: >> print >>f, cont_tx >> IOError: [Errno 28] No space left on device > > Apparently the harddisk where you stored the file is full? Likely a misinterpretation of the error. I'm guessing either one needs to be root to write to this [likely virtual] file, or a member of an associated group. It would help to have the output of bash$ whoami bash$ id and bash$ ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx I'd be particularly interested in the group association and the permission bits. -tkc From henryzhang62 at yahoo.com Tue Nov 17 20:54:57 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 17:54:57 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4B03522D.90909@tim.thechases.com> Message-ID: <646737.85745.qm@web57908.mail.re3.yahoo.com> --- On Tue, 11/17/09, Tim Chase wrote: > From: Tim Chase > Subject: Re: IOError: [Errno 28] No space left on device > To: "Lie Ryan" > Cc: python-list at python.org > Date: Tuesday, November 17, 2009, 7:47 PM > >> for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> ??? with open(i, 'w') as f: > >> ??? ??? print > >>f, cont_tx > >> > >> work perfectly. > >> > >> But following get error like: > >> print >>f, cont_tx > >> IOError: [Errno 28] No space left on device > > > > Apparently the harddisk where you stored the file is > full? > > Likely a misinterpretation of the error.? I'm guessing > either one needs to be root to write to this [likely > virtual] file, or a member of an associated group.? It > would help to have the output of > > bash$ whoami > bash$ id > > and > > bash$ ls -lsF > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx It is root. see following. File "./henry-cont-tx", line 186, in do_cont_tx print >>f, cont_tx IOError: [Errno 28] No space left on device root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# whoami root root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id uid=0(root) gid=0(root) groups=0(root) root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx 0 -rw------- 1 root root 0 2009-11-17 17:51 /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx > > I'd be particularly interested in the group association and > the permission bits. > > -tkc > > > > > > > -- http://mail.python.org/mailman/listinfo/python-list > From skippy.hammond at gmail.com Tue Nov 17 20:59:32 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 18 Nov 2009 12:59:32 +1100 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> Message-ID: <4B035504.4050508@gmail.com> On 18/11/2009 6:29 AM, Randall Walls wrote: > I don't believe so, but it seems like I'm in a catch 22, where I need to > _winreg.OpenKey the key first before I can pass it to > _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. > > I did find out that I can open the key using: > hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ODBC\ODBC.INI\ > DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) > > The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells > the system to look in the 64bit key area, and not under the Wow6432Node. > That brings up problem #2, though... I can't seem to CREATE a key in the > above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY > (in fact it doesn't accept any options other than key, sub_key). > _winreg.CreateKey does work, it just puts the key in > SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to > use one or the other, and not have to account for both. It looks like _winreg needs to be enhanced to make the RegCreateKeyEx API function available. It can be called via the win32api module of pywin32, or could also be called via ctypes. HTH, Mark From bartc at freeuk.com Tue Nov 17 21:00:42 2009 From: bartc at freeuk.com (bartc) Date: Wed, 18 Nov 2009 02:00:42 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: "Steve Ferg" wrote in message news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 at p36g2000vbn.googlegroups.com... > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. I like Python > just the way it is. I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? I think Algol 68 was responsible for a lot of this syntax, but there must be huge numbers of languages using that those forms now, apart from C-family languages which evolved their own syntax (and even in C, the preprocessor uses #if, #elif, #endif). Some syntaxes insist on ugly begin...end blocks, but the bracketing introduced by Algol68 (maybe even earlier) showed that these are redundant: if s then s [elsif s]* [else s] fi where s is any sequence of statements. The statements after the 'then' are delimited by an elsif, else or fi (endif) keyword. The endif (or fi) is necessary to show where the final statement sequence ends, and fixes the dangling-else problem. (And Algol68 also allowed this short form: (a | b | c) which is just if a then b else c fi, although it gets a bit hairy with elsif in there too..) > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: ... You're not the first to think that.. I use these forms in my own language designs for that reason. And when people write pseudo-code, it always seems to look like this, then they go and implement it in some god-forsaken syntax like C++... ...For some reason I can't quite understand, this sort of clear syntax seems to be looked down on by 'real' programmers, who perhaps think code like this can't be taken seriously. -- Bartc From metolone+gmane at gmail.com Tue Nov 17 21:09:13 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 17 Nov 2009 18:09:13 -0800 Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: "Chris Withers" wrote in message news:4B02D1E3.6080308 at simplistix.co.uk... > Mark Tolonen wrote: >> >>>> Please I need Calling Python functions from Excel and receive result >>>> back in Excel. Can me somebody advise simplest solution please? I am >>>> more VBA programmer than Python. >>> >>> Try http://code.google.com/p/pyinex/ >> >> The book Python: Programming on Win32 has a whole chapter on COM, and a >> section on COM servers. > > ...and it's generally accepted that COM sucks rocks through straws, so > explore alternatives when they're available ;-) > > Chris True, but as usual Python makes it pretty darn easy (requires PyWin32): ------------- ex.py ------------------------------- class Example(object): _public_methods_ = ['Add','Mul'] _reg_progid_ = 'MyPython.Example' _reg_clsid_ = '{insert_GUID_here}' def Add(self,a,b): return a+b def Mul(self,a,b): return a*b if __name__ == '__main__': import win32com.server.register win32com.server.register.UseCommandLine(Example) --------------------------------------------------------- -------------- Excel Macro ---------------------- Sub Testit() Set ex = CreateObject("MyPython.Example") Range("A1") = ex.Add(1, 2) Range("A2") = ex.Mul(3, 4) End Sub -------------------------------------------------------- Just run the script to register the server. "ex.py --unregister" will remove it. -Mark From pengyu.ut at gmail.com Tue Nov 17 21:18:19 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:18:19 -0600 Subject: WindowsError is not available on linux? Message-ID: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> It's not clear to me whether WindowsError is available on linux or not, after I read the document. But I see WindowsError in shutil.py. Could you somebody let me know what cause the following error? >>> try: ... raise WindowsError('WindowsError') ... except WindowsError as e: ... print e ... Traceback (most recent call last): File "", line 3, in NameError: name 'WindowsError' is not defined From lie.1296 at gmail.com Tue Nov 17 21:23:41 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 18 Nov 2009 13:23:41 +1100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: References: Message-ID: <4b035afa$1@dnews.tpgi.com.au> hong zhang wrote: > > --- On Tue, 11/17/09, Tim Chase wrote: > >> From: Tim Chase >> Subject: Re: IOError: [Errno 28] No space left on device >> To: "Lie Ryan" >> Cc: python-list at python.org >> Date: Tuesday, November 17, 2009, 7:47 PM >>>> for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>>> with open(i, 'w') as f: >>>> print >>>> f, cont_tx >>>> >>>> work perfectly. >>>> >>>> But following get error like: >>>> print >>f, cont_tx >>>> IOError: [Errno 28] No space left on device >>> Apparently the harddisk where you stored the file is >> full? >> >> Likely a misinterpretation of the error. I'm guessing >> either one needs to be root to write to this [likely >> virtual] file, or a member of an associated group.. It >> would help to have the output of >> >> bash$ whoami >> bash$ id >> >> and >> >> bash$ ls -lsF >> /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx > > It is root. see following. > > File "../henry-cont-tx", line 186, in do_cont_tx > print >>f, cont_tx > IOError: [Errno 28] No space left on device > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# whoami > root > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id > uid=0(root) gid=0(root) groups=0(root) > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx > 0 -rw------- 1 root root 0 2009-11-17 17:51 /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx > Where is the output file? Could it possibly be located in a device that is impossible to write even for root (e.g. filesystem mounted as read-only or CD or floppy with the readonly switch active or NTFS partition without ntfs-3g driver)? Can you write to this file from outside python (try echo-ing to the file)? What's the permission of the folder? The output of your 'df' shows that you only have one partition (for root) and nothing else; it is quite uncommon for linux/unix to be setup with only one partition, you didn't trim anything right? What's the output of: $ mount From benjamin.kaplan at case.edu Tue Nov 17 21:25:20 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Nov 2009 21:25:20 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: > It's not clear to me whether WindowsError is available on linux or > not, after I read the document. But I see WindowsError in shutil.py. > Could you somebody let me know what cause the following error? > >>>> try: > ... ? raise WindowsError('WindowsError') > ... except WindowsError as e: > ... ? print e > ... > Traceback (most recent call last): > ?File "", line 3, in > NameError: name 'WindowsError' is not defined > -- does this answer your question? Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import shutil >>> print shutil.WindowsError None > http://mail.python.org/mailman/listinfo/python-list > From pengyu.ut at gmail.com Tue Nov 17 21:28:16 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:28:16 -0600 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' Message-ID: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> I don't see any different between the following code in terms of output. Are they exactly the same ('as' v.s. ',')? try: raise IOError('IOError') except IOError as e: print e try: raise IOError('IOError') except IOError, e: print e From steven at REMOVE.THIS.cybersource.com.au Tue Nov 17 21:32:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 02:32:06 GMT Subject: python simply not scaleable enough for google? References: Message-ID: On Tue, 17 Nov 2009 22:11:42 +0530, Rustom Mody wrote: > "Language L is (in)efficient. No! Only implementations are > (in)efficient" > > I am reminded of a personal anecdote. It happened about 20 years ago > but is still fresh and this thread reminds me of it. > > I was attending some workshop on theoretical computer science. I gave a > talk on Haskell. > > I showed off all the good-stuff -- pattern matching, lazy lists, > infinite data structures, etc etc. > Somebody asked me: Isnt all this very inefficient? Now at that time I > was a strong adherent of the Dijkstra-religion and this viewpoint > "efficiency has nothing to do with languages, only implementations" > traces to him. So I quoted that. > > Slowing the venerable P S Thiagarajan got up and asked me: Lets say that > I have a language with a type 'Proposition' And I have an operation on > proposition called sat [ sat(p) returns true if p is satisfiable]... I assume you're referring to this: http://en.wikipedia.org/wiki/Boolean_satisfiability_problem which is N-P complete and O(2**N) (although many such problems can be solved rapidly in polynomial time). > I wont complete the tale other than to say that Ive never had the wind > in my sails taken out so completely! > > So Vincent? I wonder what you would have said in my place? I won't answer for Vincent, but I would have made five points: (1) The existence of one inherently slow function in a language does not mean that the language itself is slow overall. It's not clear exactly what "overall" means in the context of a language, but one function out of potentially thousands obviously isn't it. (2) Obviously the quality of implementation for the sat function will make a major difference as far as speed goes, so the speed of the function is dependent on the implementation. (3) Since the language definition doesn't specify an implementation, no prediction of the time needed to execute the function can be made. At most we know how many algorithmic steps the function will take, given many assumptions, but we have no idea of the constant term. The language definition would be satisfied by having an omniscient, omnipotent deity perform the O(2**N) steps required by the algorithm infinitely fast, i.e. in constant (zero) time, which would make it pretty fast. The fact that we don't have access to such deities to do our calculations for us is an implementation issue, not a language issue. (4) In order to justify the claim that the language is slow, you have to define what you are comparing it against and how you are measuring the speed. Hence different benchmarks give different relative ordering between language implementations. You must have a valid benchmark, and not stack the deck against one language: compared to (say) integer addition in C, yes the sat function is slow, but that's an invalid comparison, as invalid as comparing the sat function against factorizing a one million digit number. ("Time to solve sat(P) -- sixty milliseconds. Time to factorize N -- sixty million years.") You have to compare similar functionality, not two arbitrary operations. Can you write a sat function in (say) C that does better than the one in your language? If you can't, then you have no justification for saying that C is faster than your language, for the amount of work your language does. If you can write a faster implementation of sat, then you can improve the implementation of your language by using that C function, thus demonstrating that speed depends on the implementation, not the language. (5) There's no need for such hypothetical examples. Let's use a more realistic example... disk IO is expensive and slow. I believe that disk IO is three orders of magnitude slower than memory access, and heaven help you if you're reading from tape instead of a hard drive! Would anyone like to argue that every language which supports disk IO (including C, Lisp, Fortran and, yes, Python) are therefore "slow"? Since the speed of the hard drive dominates the time taken, we might even be justified as saying that all languages are equally slow! Obviously this conclusion is nonsense. Since the conclusion is nonsense, we have to question the premise, and the weakest premise is the idea that talking about the speed of a *language* is even meaningful (except as a short-hand for "state of the art implementations of that language"). -- Steven From ethan at stoneleaf.us Tue Nov 17 21:33:21 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 Nov 2009 18:33:21 -0800 Subject: Calling Python functions from Excel In-Reply-To: <4B02D1E3.6080308@simplistix.co.uk> References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: <4B035CF1.4040400@stoneleaf.us> Chris Withers wrote: > Mark Tolonen wrote: >> The book Python: Programming on Win32 has a whole chapter on COM, and >> a section on COM servers. > > ...and it's generally accepted that COM sucks rocks through straws, so > explore alternatives when they're available ;-) +1 QOTW :D From contact at xavierho.com Tue Nov 17 21:33:43 2009 From: contact at xavierho.com (Xavier Ho) Date: Wed, 18 Nov 2009 12:33:43 +1000 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> Message-ID: <2d56febf0911171833w29dca025n613c6e2643b36019@mail.gmail.com> On Wed, Nov 18, 2009 at 12:28 PM, Peng Yu wrote: > I don't see any different between the following code in terms of > output. Are they exactly the same ('as' v.s. ',')? > Yes, they're exactly the same. However, the syntax with "as" is newer, introducted in Python 3.x, and eventually backported to 2.6. If you have used Python 2.5, only the comma syntax would work. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Tue Nov 17 21:38:36 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 02:38:36 GMT Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' References: Message-ID: On Tue, 17 Nov 2009 20:28:16 -0600, Peng Yu wrote: > I don't see any different between the following code in terms of output. > Are they exactly the same ('as' v.s. ',')? > > try: > raise IOError('IOError') > except IOError as e: > print e This is the preferred syntax. It is used in Python 2.6 and better. It is a syntax error in Python 2.5 and older. > try: > raise IOError('IOError') > except IOError, e: > print e This is the obsolete syntax, used in Python 2.5 and older. -- Steven From pengyu.ut at gmail.com Tue Nov 17 21:40:52 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:40:52 -0600 Subject: WindowsError is not available on linux? In-Reply-To: References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan wrote: > On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >> It's not clear to me whether WindowsError is available on linux or >> not, after I read the document. But I see WindowsError in shutil.py. >> Could you somebody let me know what cause the following error? >> >>>>> try: >> ... ? raise WindowsError('WindowsError') >> ... except WindowsError as e: >> ... ? print e >> ... >> Traceback (most recent call last): >> ?File "", line 3, in >> NameError: name 'WindowsError' is not defined >> -- > > does this answer your question? > > Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import shutil >>>> print shutil.WindowsError > None But the document doesn't say shutil need to be imported in order to use WindowsError. Shall the document or the code be corrected? http://docs.python.org/library/exceptions.html From davea at ieee.org Tue Nov 17 21:43:05 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 21:43:05 -0500 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> Message-ID: <4B035F39.7010409@ieee.org> Nobody wrote: > On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote: > > >> How about this: >> >> lastarg = " ".join(sys.argv[2:]) >> > > What about it? > > IOW, why would you want to do that? > > > Like many tricks, it'd work if several conditions applied: 1) there's exactly two arguments expected on the command line 2) you know that the second argument may have one or more spaces in it, but not consecutively, and no quotes immediately after any such space. 3) you don't mind fooling the user by making *most* cases work, so he's not trained for the general case. This one reminds me of CreateProcess() in Windows, which parses for the program by looking for each space, and seeing if there's an appropriate EXE file there. So if you have stuff installed in "C:\Program Files\My Dir\yyy" directory, you can be blindsided by someone creating a program in the root called c:\program.exe, or "c:\Program Files\My.exe" CreateProcess() keeps trying till one works, instead of immediately giving a diagnosable error. That was my (correct) diagnosis of an actual customer problem, referred to me by tech support. Customer described error message, and I studied what could cause it. Called back and asked whether there was a program.exe in the root directory. Told him to (temporarily) remove it. Problem vanished. Customer astounded how we could know about its existence. Of course it was really a bug in one of the products at my company, where quotes weren't used. Not usually needed, because of this "flexibility" on the part of CreateProcess() DaveA From python at mrabarnett.plus.com Tue Nov 17 21:44:47 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Nov 2009 02:44:47 +0000 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <4B035F9F.5090800@mrabarnett.plus.com> Peng Yu wrote: > It's not clear to me whether WindowsError is available on linux or > not, after I read the document. But I see WindowsError in shutil.py. > Could you somebody let me know what cause the following error? > >>>> try: > ... raise WindowsError('WindowsError') > ... except WindowsError as e: > ... print e > ... > Traceback (most recent call last): > File "", line 3, in > NameError: name 'WindowsError' is not defined WindowsError is for Windows-specific errors (hence the name!). You shouldn't rely on it being defined on non-Windows machines. From threaderslash at gmail.com Tue Nov 17 21:47:32 2009 From: threaderslash at gmail.com (Threader Slash) Date: Wed, 18 Nov 2009 13:47:32 +1100 Subject: Qt Python : QTreeWidget Child Problem In-Reply-To: References: Message-ID: > Hello Everybody, > > I have a QTreewidget that works fine if I have just one level on my > treelist. If I decide to add child sublevels, it gives me an error. Here is > the code, that works nice only without the "childs" lines on it (see after > > "child 1" and "child 2"). > > def eqpt_centralwdg(self,MainWindow): > self.centralwidget = QtGui.QWidget(MainWindow) > self.centralwidget.setObjectName("centralwidget") > > self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) > self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) > self.colorTreeWidget.setObjectName("colorTreeWidget") > > # father root 1 > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > #child 1 - from father 1 > item = QtGui.QTreeWidgetItem(item) > #child 2 - from father 1 > item = QtGui.QTreeWidgetItem(item) > > # father root 2 > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > > self.connect(self.colorTreeWidget, > QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), > self.eqpt_activateInput) > > MainWindow.setCentralWidget(self.centralwidget) > > def eqpt_retranslateUi(self, MainWindow): > MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", > "MainWindow", None, QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.headerItem().setText(0, > QtGui.QApplication.translate("MainWindow", "color", None, > QtGui.QApplication.UnicodeUTF8) > __sortingEnabled = self.colorTreeWidget.isSortingEnabled() > > self.colorTreeWidget.setSortingEnabled(False) > # father root 1 > self.colorTreeWidget.topLevelItem(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow", None, > > QtGui.QApplication.UnicodeUTF8) > #child 1 - from father 1 > self.colorTreeWidget.topLevelItem(0).child(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow Sun", None, > > QtGui.QApplication.UnicodeUTF8)) > #child 2 - from father 1 > self.colorTreeWidget.topLevelItem(0).child(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow Gold", None, > > QtGui.QApplication.UnicodeUTF8)) > > # father root 2 > self.colorTreeWidget.topLevelItem(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Blue", None, > QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.setSortingEnabled(__sortingEnabled) > > > Here is the output, when it works > > def eqpt_activateInput(self,item,col): > print "Qtree ok! pressed" > print item.text(col) > > if I exclude the lines related to the "child 1" and "child 2" from the code, > it runs. Otherwise, it gives me the error: > > AttributeError: 'NoneType' object has no attribute 'setText' > > > I used the Qt Designer to generate the code, and added some lines to trigger > events. > > Any hints or suggestions are highly appreciated. > > Solved! Here is the solution: parent1 = QtGui.QTreeWidgetItem(self.colorTreeWidget) child1_1 = QtGui.QTreeWidgetItem() child1_2 = QtGui.QTreeWidgetItem() parent1.addChild(child1_1) parent1.addChild(child1_2) Now it works properly. Hope this may help others too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Nov 17 21:52:44 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Nov 2009 02:52:44 +0000 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> Message-ID: <4B03617C.5070905@mrabarnett.plus.com> Peng Yu wrote: > I don't see any different between the following code in terms of > output. Are they exactly the same ('as' v.s. ',')? > > try: > raise IOError('IOError') > except IOError as e: > print e > > try: > raise IOError('IOError') > except IOError, e: > print e The second form is the old form. Later versions of Python introduced the first form because it is less confusing. If you wanted a single 'except' to catch 2 exceptions you would need to write: try: ... except (IOError, OSError): ... Sometimes people who are new to Python mistakenly write: try: ... except IOError, OSError: ... thinking that that form will catch 2 exceptions, and they'll then be puzzled when it doesn't work properly. From wuwei23 at gmail.com Tue Nov 17 22:18:21 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 19:18:21 -0800 (PST) Subject: WindowsError is not available on linux? References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Peng Yu wrote: > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? Neither, it's your understanding that needs correction. Benjamin wasn't trying to say that WindowsError is defined within shutil, he was showing that it _isn't_ defined within shutil on a non- Windows machine. As you're looking in shutil.py, you should have noticed this at the very top, just beneath the declaration of the Error exception: try: WindowsError except NameError: WindowsError = None This looks for the existence of the WindowsError exception - present only under Windows - and if it's not there it binds the name to None. You'll notice that the only place it's used in shutil.py is prefixed by the test WindowsError is not None... I think the mention of the exception being raised when a "Windows- specific error occurs" should make it pretty clear that this is a Windows-only exception. From benjamin.kaplan at case.edu Tue Nov 17 22:19:05 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Nov 2009 22:19:05 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> Message-ID: On Tue, Nov 17, 2009 at 9:40 PM, Peng Yu wrote: > On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan > wrote: >> On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. But I see WindowsError in shutil.py. >>> Could you somebody let me know what cause the following error? >>> >>>>>> try: >>> ... ? raise WindowsError('WindowsError') >>> ... except WindowsError as e: >>> ... ? print e >>> ... >>> Traceback (most recent call last): >>> ?File "", line 3, in >>> NameError: name 'WindowsError' is not defined >>> -- >> >> does this answer your question? >> >> Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import shutil >>>>> print shutil.WindowsError >> None > > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? > > http://docs.python.org/library/exceptions.html The exception WindowsError is not defined on my computer (a Mac). The *name* is defined in shutil, but it's mapped to None, not to an exception. > -- > http://mail.python.org/mailman/listinfo/python-list > From davecook at nowhere.net Tue Nov 17 22:21:17 2009 From: davecook at nowhere.net (Dave Cook) Date: 18 Nov 2009 03:21:17 GMT Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <007f3944$0$23487$c3e8da3@news.astraweb.com> On 2009-11-16, me wrote: > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. That's what I would recommend. What did you not like about it? Dave Cook From aurfalien at gmail.com Tue Nov 17 22:25:24 2009 From: aurfalien at gmail.com (aurfalien at gmail.com) Date: Tue, 17 Nov 2009 19:25:24 -0800 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' Message-ID: Hi all, I tried to make the subject as specific as possible rather then just "help me" or "its broke" or "my server is down", etc... So please excuse me if its too specific as I wasn't trying to be ridiculous. So I've been handed some one else's work to fix. While its fun and all, I haven't had much luck in debugging this particular issue. The error I get; File "myscript.py", Line 18, in ? projectpath = ourHome+"/etc/TEMPLATE" TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Python 2.4.3 I've read were when passing a string to exec may need to end with a '\n' I've tried a few diff variations on the below line 18 w/o luck. Any one mind helping out a bratha from anatha ... planet that is? line 18; projectpath = ourHome+"/etc/TEMPLATE" line 17; ourHome = os.environ.get('some_env') Thanks in advance, - aurf From Scott.Daniels at Acm.Org Tue Nov 17 22:25:26 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 19:25:26 -0800 Subject: TODO and FIXME tags In-Reply-To: References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Martin P. Hellwig wrote: > Ben Finney wrote: >> Chris Rebert writes: >> >>> 2009/11/16 Yasser Almeida Hern?ndez : >>>> How is the sintaxis for set the TODO and FIXME tags...? ... >> There's no widely-followed ?syntax? for this convention, though. > Except for _not_ doing what is suggested in those comments, which > appears to be the biggest convention :-) Perhaps: "The comments are a directive to delete the comment if you happen do this." --Scott David Daniels Scott.Daniels at Acm.Org From pengyu.ut at gmail.com Tue Nov 17 22:37:07 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 21:37:07 -0600 Subject: WindowsError is not available on linux? In-Reply-To: <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Message-ID: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: > Peng Yu wrote: >> But the document doesn't say shutil need to be imported in order to >> use WindowsError. Shall the document or the code be corrected? > > Neither, it's your understanding that needs correction. > > Benjamin wasn't trying to say that WindowsError is defined within > shutil, he was showing that it _isn't_ defined within shutil on a non- > Windows machine. > > As you're looking in shutil.py, you should have noticed this at the > very top, just beneath the declaration of the Error exception: > > ? ?try: > ? ? ? ?WindowsError > ? ?except NameError: > ? ? ? ?WindowsError = None > > This looks for the existence of the WindowsError exception - present > only under Windows - and if it's not there it binds the name to None. > You'll notice that the only place it's used in shutil.py is prefixed > by the test WindowsError is not None... > > I think the mention of the exception being raised when a "Windows- > specific error occurs" should make it pretty clear that this is a > Windows-only exception. I don't know about others. The wording "Windows-specific error occurs" was ambiguous to me. It could refers to some errors resulted from copying (on a linux machine) some files from linux file systems to windows files systems (via samba, maybe). I recommend to revise the document a little bit to avoid confusion. From davea at ieee.org Tue Nov 17 22:57:53 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 22:57:53 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> Message-ID: <4B0370C1.6020309@ieee.org> Peng Yu wrote: > On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan > wrote: > >> On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >> >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. But I see WindowsError in shutil.py. >>> Could you somebody let me know what cause the following error? >>> >>> >>>>>> try: >>>>>> >>> ... raise WindowsError('WindowsError') >>> ... except WindowsError as e: >>> ... print e >>> ... >>> Traceback (most recent call last): >>> File "", line 3, in >>> NameError: name 'WindowsError' is not defined >>> -- >>> >> does this answer your question? >> >> Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import shutil >>>>> print shutil.WindowsError >>>>> >> None >> > > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? > > http://docs.python.org/library/exceptions.html > > The WindowsError is available in a Windows build, and I don't directly know if it's available on Linux. I think shutil is a red-herring here, however. The docs show the implementation of copyTree(), and that function uses WindowsError. However, earlier in the shutil.py file, there is the following trick: try: WindowsError except NameError: WindowsError = None This has the effect of defining a dummy attribute "WindowsError" WITHIN THIS ONE MODULE, if it's not already in the global namespace. This lets the code in function copytree() deal with an OSError differently on Windows than in other systems. I do not expect that the name WindowsError of that module was intended to be accessed by user's code. And because some of you see a None value, that tells me that it is indeed not defined for some systems. I think that fact should be documented in the URL you mention, exceptions.html But in the meantime, if you're not on a Windows system, you won't see that exception, and if you need to be portable, you may pull the same trick that shutil did. DaveA From glenn at zewt.org Tue Nov 17 23:10:51 2009 From: glenn at zewt.org (Glenn Maynard) Date: Tue, 17 Nov 2009 23:10:51 -0500 Subject: ZipFile - file adding API incomplete? In-Reply-To: <4B02B2F1.4030407@ieee.org> References: <7mf5f6F3i297hU1@mid.uni-berlin.de> <4B02B2F1.4030407@ieee.org> Message-ID: On Tue, Nov 17, 2009 at 9:28 AM, Dave Angel wrote: > I'm pretty sure that the ZIP format uses independent compression for each > contained file (member). ?You can add and remove members from an existing > ZIP, and use several different compression methods within the same file. ?So > the adaptive tables start over for each new member. This is correct. It doesn't do solid compression, which is what you get with .tar.gz (and RARs, optionally). > What isn't so convenient is that the sizes are apparently at the end. ?So if > you're trying to unzip "over the wire" you can't readily do it without > somehow seeking to the end. ?That same feature is a good thing when it comes > to spanning zip files across multiple disks. Actually, there are two copies of the headers: one immediately before the file data (the local file header), and one at the end (the central directory); both contain copies of the compressed and uncompressed file size. Very few programs actually use the local file headers, but it's very nice to have the option. It also helps makes ZIPs very recoverable. If you've ever run a ZIP recovery tool, they're usually just reconstructing the central directory from the local file headers (and probably recomputing the CRCs). (This is no longer true if bit 3 of the bitflags is set, which puts the CRC and filesizes after the data. In that case, it's not possible to stream data--largely defeating the benefit of the local headers.) > Define a calls to read _portions_ of the raw (compressed, encrypted, whatever) data. I think the clean way is to return a file-like object for a specified file, eg.: # Read raw bytes 1024-1152 from each file in the ZIP: zip = ZipFile("file.zip", "r") for info in zip.infolist(): f = zip.rawopen(info) # or a filename f.seek(1024) f.read(128) > Define a call that locks the ZipFile object and returns a write handle for a single new file. I'd use a file-like object here, too, for probably obvious reasons--you can pass it to anything expecting a file object to write data to (eg. shutil.copyfile). > Only on successful close of the "write handle" is the new directory written. Rather, when the new file is closed, its directory entry is saved to ZipFile.filelist. The new directory on disk should be written when the zip's own close() method is called, just as when writing files with the other methods. Otherwise, writing lots of files in this way would write and overwrite the central directory repeatedly. Any thoughts about this rough API outline: ZipFile.rawopen(zinfo_or_arcname) Same definition as open(), but returns the raw data. No mode (no newline translation for raw files); no pwd (raw files aren't decrypted). ZipFile.writefile(zinfo[, raw]) Definition like ZipInfo.writestr. Relax writestr()'s "at least the filename, date, and time must be given" rule: if not specified, use the current date and time. Returns a file-like object (ZipWriteFile) which file data is written to. If raw is True, no actual compression is performed, and the file data should already be compressed with the specified compression type (no checking is performed). If raw is False (the default), the data will be compressed before being written. When finished writing data, the file must be closed. Only one ZipWriteFile may be open for each ZipFile at a time. Calls to ZipFile.writefile while a ZipWriteFile is already open will result in ValueError[1]. Another detail: is the CRC recomputed when writing in raw mode? No. If I delete a file from a ZIP (causing me to rewrite the ZIP) and another file in the ZIP is corrupt, it should just move the file as-is, invalid CRC and all; it should not rewrite the file with a new CRC (masking the corruption) or throw an error (I should not get errors about file X being corrupt if I'm deleting file Y). When writing in raw mode, if zinfo.CRC is already specified (not None), it should be used as-is. I don't like how this results in three different APIs for adding data (write, writestr, writefile), but trying to squeeze the APIs together feels unnatural--the parameters don't really line up too well. I'd expect the other two to become thin wrappers around ZipFile.writefile(). This never opens files directly like ZipFile.write, so it only takes a zinfo and not a filename (set the filename through the ZipInfo). Now you can stream data into a ZIP, specify all metadata for the file, and you can stream in compressed data from another ZIP (for deleting files and other cases) without recompressing. This also means you can do all of these things to encrypted files without the password, and to files compressed with unknown methods, which is currently impossible. > and I realize that the big flaw in this design is that from the moment you start overwriting the existing master directory until you write a new master at the end, your do not have a valid zip file. The same is true when appending to a ZIP with ZipFile.write(); until it finishes, the file on disk isn't a valid ZIP. That's unavoidable. Files in the ZIP can still be opened by the existing ZipFile object, since it keeps the central directory in memory. For what it's worth, I've written ZIP parsing code several times over the years (https://svn.stepmania.com/svn/trunk/stepmania/src/RageFileDriverZip.cpp), so I'm familiar with the more widely-used parts of the file format, but I havn't dealt with ZIP writing very much. I'm not sure if I'll have time to get to this soon, but I'll keep thinking about it. [1] seems odd, but mimicing http://docs.python.org/library/stdtypes.html#file.close -- Glenn Maynard From clp2 at rebertia.com Tue Nov 17 23:11:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 20:11:32 -0800 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' In-Reply-To: References: Message-ID: <50697b2c0911172011o4a8bc9b1kf8810386761c4576@mail.gmail.com> On Tue, Nov 17, 2009 at 7:25 PM, wrote: > The error I get; > > File "myscript.py", Line 18, in ? > projectpath = ourHome+"/etc/TEMPLATE" > TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' > > Python 2.4.3 > > I've read were when passing a string to exec may need to end with a '\n' > > I've tried a few diff variations on the below line 18 w/o luck. ?Any one > mind helping out a bratha from anatha ... planet that is? > > line 18; > > projectpath = ourHome+"/etc/TEMPLATE" > > line 17; > ourHome = os.environ.get('some_env') >From the `os` docs: os.environ A mapping object representing the string environment. >From the `dict` docs (`dict` being the built-in and prototypical mapping class): D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. >From this, I conclude that the environment variable `some_env` does not exist for you, thus .get() returns None, thus causing an error when you try and concatenate it with a string. Solution: Either fix things so the environment variable does exist or add code to handle the case of the environment variable not existing. Cheers, Chris -- http://blog.rebertia.com From wuwei23 at gmail.com Tue Nov 17 23:11:45 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 20:11:45 -0800 (PST) Subject: WindowsError is not available on linux? References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Message-ID: <8e5bd0b8-0bec-4360-ab02-e3f28efbff1c@m33g2000pri.googlegroups.com> Peng Yu wrote: > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. So file a bug: http://docs.python.org/bugs.html From clp2 at rebertia.com Tue Nov 17 23:18:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 20:18:33 -0800 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> Message-ID: <50697b2c0911172018tcb052acrc995b916c22251a7@mail.gmail.com> On Tue, Nov 17, 2009 at 7:37 PM, Peng Yu wrote: > On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: >> Peng Yu wrote: >>> But the document doesn't say shutil need to be imported in order to >>> use WindowsError. Shall the document or the code be corrected? >> >> Neither, it's your understanding that needs correction. >> >> Benjamin wasn't trying to say that WindowsError is defined within >> shutil, he was showing that it _isn't_ defined within shutil on a non- >> Windows machine. >> >> As you're looking in shutil.py, you should have noticed this at the >> very top, just beneath the declaration of the Error exception: >> >> ? ?try: >> ? ? ? ?WindowsError >> ? ?except NameError: >> ? ? ? ?WindowsError = None >> >> This looks for the existence of the WindowsError exception - present >> only under Windows - and if it's not there it binds the name to None. >> You'll notice that the only place it's used in shutil.py is prefixed >> by the test WindowsError is not None... >> >> I think the mention of the exception being raised when a "Windows- >> specific error occurs" should make it pretty clear that this is a >> Windows-only exception. > > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. But your example isn't even Windows-specific because Samba server exists; any error would network-related or specific to the SMB protocol rather than Windows-related. Cheers, Chris -- http://blog.rebertia.com From ashwiniyal at gmail.com Tue Nov 17 23:56:12 2009 From: ashwiniyal at gmail.com (ashwini yal) Date: Wed, 18 Nov 2009 10:26:12 +0530 Subject: Running a python script from interactive mode Message-ID: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Hi, I am trying to run a python script from interactive mode ,but i am not able to know how to run it? Is it possible? if yes please let me how to run the script? -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Wed Nov 18 00:02:01 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 00:02:01 -0500 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' In-Reply-To: References: Message-ID: <4B037FC9.9020409@ieee.org> aurfalien at gmail.com wrote: >
    Hi all, > > I tried to make the subject as specific as possible rather then just > "help me" or "its broke" or "my server is down", etc... > > So please excuse me if its too specific as I wasn't trying to be > ridiculous. > > So I've been handed some one else's work to fix. > > While its fun and all, I haven't had much luck in debugging this > particular issue. > > The error I get; > > File "myscript.py", Line 18, in ? > projectpath = ourHome+"/etc/TEMPLATE" > TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' > > Python 2.4.3 > > I've read were when passing a string to exec may need to end with a '\n' > > I've tried a few diff variations on the below line 18 w/o luck. Any > one mind helping out a bratha from anatha ... planet that is? > > line 18; > > projectpath = ourHome+"/etc/TEMPLATE" > > line 17; > ourHome = os.environ.get('some_env') > > > Thanks in advance, > - aurf > > Short answer: you (the program) don't have any such environment variable, and forgot to check for it, just implicitly assuming that it'll be present. When it isn't, the + doesn't make any sense. Longer answer: When you get an error on a line, try to figure out which of the variables on the line might be in doubt, and look at them in your debugger. Since the error is complaining about operands to + you'd look at both the ourHome variable and the literal. And then you'd look, and see that ourHome is equal to None. Which is what the error said. Now you look at the last place which bound that variable and it's os.environ.get(). How can get() return a None? Answer: when there's no such variable. As to how to fix it, you have to decide what behavior you want when the user doesn't have such a variable. Read the manual you wrote for the user, telling him to define it. If no such paragraph exists, then perhaps you intended a default value to be used, such as "/default/special" Add a paragraph to the manual, and a corresponding field to the get(). ourHome = os.environ.get("some_env", "/default/special") Now it'll always have a text value, either specified by the environment var, or /default/special. Alternatively, you could catch the exception, print an error to the user, telling him exactly how to fix his environment, and exit. Of course, this assumes you do the check pretty early in the program's run. DaveA From greg at cosc.canterbury.ac.nz Wed Nov 18 00:06:15 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:06:15 +1300 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: <7mhdmnF3hrf2fU1@mid.individual.net> Rhodri James wrote: > We've been living with this pain ever since windowed GUIs encouraged > users to put spaces in their file names (Apple, I'm looking at you!). It's not really Apple's fault. There was no problem with spaces in filenames in the classic MacOS environment, because there was no textual command language (at least not one that people used in day-to-day work). There's a slight problem sometimes in MacOSX when you use the shell, but at least unix passes args to a program as separate strings, so as long as you exec() something directly and avoid the shell, you're safe. Windows, on the other hand, passes all the args as a single string, whether a shell is involved or not (due to blindly adopting CP/M's argument passing mechanism into MSDOS). Microsoft screwed up by trying to partially implement Apple's ideas on top of a system that wasn't engineered to cope with them. -- Greg From davea at ieee.org Wed Nov 18 00:08:18 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 00:08:18 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> Message-ID: <4B038142.2090302@ieee.org> Peng Yu wrote: > On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: > >> Peng Yu wrote: >> >>> But the document doesn't say shutil need to be imported in order to >>> use WindowsError. Shall the document or the code be corrected? >>> >> Neither, it's your understanding that needs correction. >> >> Benjamin wasn't trying to say that WindowsError is defined within >> shutil, he was showing that it _isn't_ defined within shutil on a non- >> Windows machine. >> >> As you're looking in shutil.py, you should have noticed this at the >> very top, just beneath the declaration of the Error exception: >> >> try: >> WindowsError >> except NameError: >> WindowsError =one >> >> This looks for the existence of the WindowsError exception - present >> only under Windows - and if it's not there it binds the name to None. >> You'll notice that the only place it's used in shutil.py is prefixed >> by the test WindowsError is not None... >> >> I think the mention of the exception being raised when a "Windows- >> specific error occurs" should make it pretty clear that this is a >> Windows-only exception. >> > > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. > > Worse, even if the exception cannot be thrown on a non-Windows environment, leaving it undefined makes it very awkward to write portable code. An except clause that can never happen in a particular environment is pretty innocent. Or somebody can use a base class for his except clause, to catch this error and other related ones. But it blows up if you explicitly use this exception. I think that needs documentation, at a minimum. DaveA From clp2 at rebertia.com Wed Nov 18 00:10:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 21:10:23 -0800 Subject: Running a python script from interactive mode In-Reply-To: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> References: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Message-ID: <50697b2c0911172110s65ca16c1ra22f3808e0bf9fca@mail.gmail.com> On Tue, Nov 17, 2009 at 8:56 PM, ashwini yal wrote: > Hi, > > I am trying to run a python script from interactive mode ,but i am not able > to know how to run it? Is it possible? if yes please let me how to run the > script? execfile("/path/to/the/script.py") or if it's on your sys.path and doesn't use the `if __name__ == "__main__":` idiom then just importing it works: import script_name Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Wed Nov 18 00:17:25 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:17:25 +1300 Subject: YIELD_VALUE Byte Code In-Reply-To: <1257933992.2784.16.camel@laptop> References: <1257933992.2784.16.camel@laptop> Message-ID: <7mheblF3h98o5U1@mid.individual.net> Andreas L?scher wrote: > Since Python Version 2.5 it behaves the following: > 1. pop yield value from stack and return it to > a former gen_send_ex() call from Objects/genobject.c > > 2. push the yield value on the stack in gen_send_ex() and return Are you sure about that? I would expect the value pushed to be the one sent back into the generator using a send() call if any, or None if the generator is resumed using next() rather than send(). > 3. when the generator is executed again, the yield value is > 'poped' from the stack again with the POP_TOP opcode This will happen if the result of the yield expression is not used for anything in the Python code. -- Greg From himanshu.garg at gmail.com Wed Nov 18 00:21:04 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Wed, 18 Nov 2009 11:21:04 +0600 Subject: Running a python script from interactive mode In-Reply-To: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> References: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Message-ID: <6f82a7270911172121x1c1936eam47438de934b34541@mail.gmail.com> 2009/11/18 ashwini yal : > Hi, > > I am trying to run a python script from interactive mode ,but i am not able > to know how to run it? Is it possible? if yes please let me how to run the > script? > a) If you want to debug it then see http://docs.python.org/library/pdb.html b) If you want to accept simple input from user see http://docs.python.org/library/functions.html?highlight=raw_input#raw_input c) If you want to enter interactive mode after the script has finished execution use the -i option with python. See http://docs.python.org/tutorial/interpreter.html?highlight=interactive%20mode From greg at cosc.canterbury.ac.nz Wed Nov 18 00:22:44 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:22:44 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7mhelkF3go4saU1@mid.individual.net> MRAB wrote: > Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes > did. I think Fortran used .LT. and .GT. because some early character sets didn't have < and > symbols. Having done that, it probably seemed more consistent to use .EQ. for comparison than to break the pattern and use =. -- Greg From greg at cosc.canterbury.ac.nz Wed Nov 18 00:28:11 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:28:11 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7mhevoF3ht32sU1@mid.individual.net> r wrote: > I think the syntax was chosen because the > alternatives are even worse AND since assignment is SO common in > programming, would you *really* rather type two chars instead of one? Smalltalk solved the problem by using a left-arrow character for assignment. But they had an unfair advantage in being able to use a non-standard character set on their custom-built machines. We should be able to do a lot better now using Unicode. We could even heal the <> vs != rift by using a real not-equal symbol! -- Greg From greg at cosc.canterbury.ac.nz Wed Nov 18 00:34:16 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:34:16 +1300 Subject: Time travel In-Reply-To: <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> References: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> Message-ID: <7mhfb8F3i93hnU1@mid.individual.net> Lee Merrill wrote: > And I can't do arithmetic, it is actually about 3600--never mind! Don't feel too bad. Obviously Guido nipped back to March 8 2008 in his time machine and fixed the problem, making it *look* like you can't do arithmetic. Time travel often leads to embarrassments like that. -- Greg From sturlamolden at yahoo.no Wed Nov 18 01:10:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Nov 2009 22:10:00 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> Message-ID: On 17 Nov, 19:34, r wrote: > Agreed! Tkinter (besides myself) seems to be the whipping boy of > c.l.py. Tkinter has it's place in Python because of the same > simplicity people laboriously lament about! Until something else comes > along that can offer the same benefits of Tkinter and a little extra, > we are going to keep seeing Tkinter release after release. Guido knows > what he is doing people, don't sell the guy short! Tkinter is fine, particularly with Tix. But I want a GUI designer. I don't like the tedious work of hand- coding a GUI! From threaderslash at gmail.com Wed Nov 18 01:12:31 2009 From: threaderslash at gmail.com (Threader Slash) Date: Wed, 18 Nov 2009 17:12:31 +1100 Subject: Qt Python radiobutton: activate event Message-ID: Hi Everybody, I am developing a project for one customer, where the design has a radio button with exclusive options. Here is a piece of the code that runs and show two nice radio buttons: self.performGroupBox = QtGui.QGroupBox(self.centralwidget) self.performGroupBox.setGeometry(QtCore.QRect(50, 20, 181, 121)) self.performGroupBox.setObjectName("performGroupBox") self.consultRadioButton = QtGui.QRadioButton(self.performGroupBox) self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18)) self.consultRadioButton.setObjectName("consultRadioButton") self.insertRadioButton = QtGui.QRadioButton(self.performGroupBox) self.insertRadioButton.setGeometry(QtCore.QRect(40, 60, 84, 18)) self.insertRadioButton.setObjectName("insertRadioButton") it just looks like: perform: () Consult () Insert The point here is, how to know what choice was marked: "consultRadioButton" or "insertRadioButton"? Here is a sample on trying to get this information: if self.consultRadioButton.isChecked(): self.call_Consult() if self.insertRadioButton.isChecked(): self.call_Insert() But it didn't do anything when the radiobutton is chosen. Otherwise, using connect should be another option: QtCore.QObject.connect(self.consultRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Consult) QtCore.QObject.connect(self.insertRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Insert) But it didn't work either. What is missing here... Any suggestion? All comments are highly welcome and appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From yinon.me at gmail.com Wed Nov 18 01:22:59 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 17 Nov 2009 22:22:59 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> Message-ID: On Nov 18, 8:10?am, sturlamolden wrote: > On 17 Nov, 19:34, r wrote: > > > Agreed! Tkinter (besides myself) seems to be the whipping boy of > > c.l.py. Tkinter has it's place in Python because of the same > > simplicity people laboriously lament about! Until something else comes > > along that can offer the same benefits of Tkinter and a little extra, > > we are going to keep seeing Tkinter release after release. Guido knows > > what he is doing people, don't sell the guy short! > > Tkinter is fine, particularly with Tix. > > But I want a GUI designer. I don't like the tedious work of hand- > coding a GUI! http://stackoverflow.com/questions/1693939/need-a-gui-builder-for-tkinter-python From dotancohen at gmail.com Wed Nov 18 02:33:38 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 Nov 2009 09:33:38 +0200 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <880dece00911172333o793e97a1u3a4e08b67c3dacce@mail.gmail.com> 2009/11/16 Steve Ferg : > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ?if then > ? ? ? ?do stuff > ? ?elif then > ? ? ? ?do stuff > ? ?else > ? ? ? ?do stuff > ? ?endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > PHP has exactly this: if (condition) { // stuff } elseif (otherContition) { // otherStuff } elseif (yetAnotherCondition) { // yetOtherStuff } Furthermore, PHP has the switch statement: http://php.net/manual/en/control-structures.switch.php switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; } The break commands end the switch, and they can be removed to have multiple matches perform multiple functions. > Is there any particular reason why this might be a *bad* language- > design idea? It is about as far from OO as one could get. Whether or not that is "bad" depends on the use case. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From sturlamolden at yahoo.no Wed Nov 18 02:51:31 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Nov 2009 23:51:31 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> Message-ID: <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> On 18 Nov, 04:21, Dave Cook wrote: > On 2009-11-16, me wrote: > > > Also looked at the frames/forms created with QtDesigner, which > > can be used by Python via pyuic. > > That's what I would recommend. ?What did you not like about it? GPL From showell30 at yahoo.com Wed Nov 18 03:49:34 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 00:49:34 -0800 (PST) Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures Message-ID: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> During the last few days I have written code in support of a small DDL language that encapsulates a concise representation of the manipulations needed to make a deep subcopy of a Python-like data structure. It is inspired by syntax from mainstream modern languages, including, of course, Python. The DDL can be converted to an AST. That AST can be walked to either generate Python code that expresses the mapping or to generate Python objects that can execute the mapping. Either of the prior outputs can then subsequently be applied to real world inputs to create new Python data structures from old ones, using the mechanisms specified in the original DDL for attribute access, dictionary lookup, iteration, method invocation, etc. Here is an example of the DDL (and I hate the terminology "DDL," just cannot think of anything better): { 'show_table_of_contents', 'author' { .person 'name', .person 'location' as city, .favorite_books()[ .title, .cost() as expense ] as books} } There are more details here: http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html Apart from shamelessly plugging my blog, I am hoping to generate ideas, constructive criticism, etc. Feel free to comment here or on the blog. So far there are three entries on the blog, all pertaining to Python. The implementation of the idea is quite new, but it is a topic that I have been pondering for a long time--no matter how expressive your programming language of choice might be, there are certain programming tasks that just seem needlessly tedious. The mini-language above proposes to solve one problem but solve it well. I am particularly interested to find out whether somebody has tried something like this before. From deets at nospam.web.de Wed Nov 18 03:57:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 09:57:12 +0100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b035afa$1@dnews.tpgi.com.au> References: <4b035afa$1@dnews.tpgi.com.au> Message-ID: <7mhr78F3hrl1kU1@mid.uni-berlin.de> Lie Ryan schrieb: > hong zhang wrote: >> >> --- On Tue, 11/17/09, Tim Chase wrote: >> >>> From: Tim Chase >>> Subject: Re: IOError: [Errno 28] No space left on device >>> To: "Lie Ryan" >>> Cc: python-list at python.org >>> Date: Tuesday, November 17, 2009, 7:47 PM >>>>> for i in >>> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>>>> with open(i, 'w') as f: >>>>> print >>>>> f, cont_tx >>>>> >>>>> work perfectly. >>>>> >>>>> But following get error like: >>>>> print >>f, cont_tx >>>>> IOError: [Errno 28] No space left on device >>>> Apparently the harddisk where you stored the file is >>> full? >>> >>> Likely a misinterpretation of the error. I'm guessing >>> either one needs to be root to write to this [likely >>> virtual] file, or a member of an associated group.. It >>> would help to have the output of >>> >>> bash$ whoami >>> bash$ id >>> >>> and >>> >>> bash$ ls -lsF >>> /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx >> >> It is root. see following. >> File "../henry-cont-tx", line 186, in do_cont_tx >> print >>f, cont_tx >> IOError: [Errno 28] No space left on device >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# >> whoami >> root >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id >> uid=0(root) gid=0(root) groups=0(root) >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls >> -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx >> 0 -rw------- 1 root root 0 2009-11-17 17:51 >> /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx >> > > Where is the output file? Could it possibly be located in a device that > is impossible to write even for root (e.g. filesystem mounted as > read-only or CD or floppy with the readonly switch active or NTFS > partition without ntfs-3g driver)? > > Can you write to this file from outside python (try echo-ing to the > file)? What's the permission of the folder? > > The output of your 'df' shows that you only have one partition (for > root) and nothing else; it is quite uncommon for linux/unix to be setup > with only one partition, you didn't trim anything right? /sys is not a block-device, it's similar to /proc (or replaces it, I forgot). It displays system-information and device-trees and whatnot, and some of those files can be written to change settings. I think the error the OP sees is a mis-interpretion or unlucky re-map of an error-code the kernel gives when things go wrong, I can only guess but maybe he writes to fast to the files, or to often. Diez From slafs.e at gmail.com Wed Nov 18 04:13:11 2009 From: slafs.e at gmail.com (Slafs) Date: Wed, 18 Nov 2009 01:13:11 -0800 (PST) Subject: XML root node attributes References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> <4b02b4ff$0$7615$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Thanks But this doesn't work. I've ended using something like this: import xml.etree.ElementTree as ET root = ET.Element("root", dict(a='v', b='v2', c='v3')) n = ET.SubElement(root,'d') tree = ET.ElementTree(root) import sys tree.write(sys.stdout) On 17 Lis, 15:36, Stefan Behnel wrote: > Slafs, 17.11.2009 15:19: > > > I'm little confused about adding attributes to the root node when > > creating an XML document. > > Can I do this using minidom or something else. > > Yes, you /can/, but you /should/ use something else. > > > I can't find anything that would fit my needs. > > > i would like to have something like this: > > > > > > ? ? > > ? ?.... > > > > Use ElementTree: > > ? ? import xml.etree.ElementTree as ET > ? ? root = ET.Element("root", dict(a='v', b='v2', c='v3')) > ? ? root.SubElement('d') > > ? ? print ET.tostring(root) > > Stefan From showell30 at yahoo.com Wed Nov 18 04:15:32 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 01:15:32 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On the topic of "switch" statements and even-more-concise-then-we-have- already if/elif/else/end constructs, I have to say that Python does occasionally force you to write code like the code below. Maybe "force" is too strong a word, but Python lends itself to if/elif blocks like below, which get the job done just fine, but which are not syntactically pretty, due to the "(el){0,1}if kind ==" duplication. There are often cases where if/elif statements are just a smell that you do not know how to do dictionary lookups, but if you converted the below code to use dictionary lookups, you would complicate the code almost as much as you abstracted the code, if not more, unless I am just being very naive. Anonymous methods would help to a certain degree. I am not saying I want either anonymous methods or switch statements, but the lack of either in a language leads to very procedural looking code when you use number-of-lines-of-code as a (possibly dubious) metric. Maybe this excerpt can be golfed down to something simpler, I would love to see it! if kind == 'dict': return dictionary_schema(ast) elif kind == 'list': method = dictionary_schema(ast) return lambda lst: map(method, lst) elif kind == 'attr': return ((lambda obj: getattr(obj, ast.field)), ast.field) elif kind == 'key': return (lambda obj: obj.get(ast.field), ast.field) elif kind == 'as': method, old_name = schema(ast.parent) return (method, ast.synonym) elif kind == 'call': method, old_name = schema(ast.parent) def call(obj): return method(obj)() return (call, old_name) elif kind == 'recurse': expr = ast.expr kind = expr.kind method, field_name = schema(ast.parent) if kind in ['attr', 'key']: new_method, new_field_name = schema(expr) field_name = new_field_name elif kind in ['dict', 'list']: new_method = schema(expr) else: raise Exception('unknown kind!') def recurse(obj): obj = method(obj) return new_method(obj) return (recurse, field_name) else: raise Exception('unknown kind!') From gonatan at gmx.de Wed Nov 18 04:27:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Wed, 18 Nov 2009 10:27:10 +0100 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <4B03617C.5070905@mrabarnett.plus.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> <4B03617C.5070905@mrabarnett.plus.com> Message-ID: <4B03BDEE.6080906@gmx.de> See also http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110-exception-handling-changes From clp2 at rebertia.com Wed Nov 18 04:32:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 01:32:30 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50697b2c0911180132k399ba891uc5424ce4ecc19bde@mail.gmail.com> On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > On the topic of "switch" statements and even-more-concise-then-we-have- > already if/elif/else/end constructs, I have to say that Python does > occasionally force you to write code like the code below. ?Maybe > "force" is too strong a word, but Python lends itself to if/elif > blocks like below, which get the job done just fine, but which are not > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > There are often cases where if/elif statements are just a smell that > you do not know how to do dictionary lookups, but if you converted the > below code to use dictionary lookups, you would complicate the code > almost as much as you abstracted the code, if not more, unless I am > just being very naive. I'm gonna have to disagree and say using the dictionary dispatch technique would clean it up a good bit. Yes, it would entail creating several functions, but those functions could then be documented (vs. the currently opaque code blocks); and due to their separation and smaller length, they would be easier to understand and test than the given code. Additionally, the sheer length of the given code segment probably constitutes a code smell in and of itself for the function containing that code. Cheers, Chris -- http://blog.rebertia.com From jarausch at igpm.rwth-aachen.de Wed Nov 18 04:42:03 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 18 Nov 2009 10:42:03 +0100 Subject: pygtk - icons? Message-ID: <7mhtr5F3itsg6U1@mid.dfncis.de> Hi, please bear in mind that I'm an absolute newcomer to (py)gtk. I'm trying to install the nice synchronization tool http://live.gnome.org/Conduit which is written in Python and use pyGTK. This installed several icons e.g. /usr/share/icons/hicolor/16x16/apps/conduit.png When run, Conduit fails to find its icons. For testing purposes I've tried import gtk info=gtk.icon_theme_get_default().lookup_icon("conduit",16,0) which produces the error message GtkWarning: Could not find the icon 'conduit'. The 'hicolor' theme was not found either, perhaps you need to install it. You can get a copy from: http://icon-theme.freedesktop.org/releases On my Gentoo system lots of packages have placed icons under /usr/share/icons/hicolor So, what am I missing. Many thanks for a hint, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From showell30 at yahoo.com Wed Nov 18 04:53:50 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 01:53:50 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 18, 1:32?am, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > > On the topic of "switch" statements and even-more-concise-then-we-have- > > already if/elif/else/end constructs, I have to say that Python does > > occasionally force you to write code like the code below. ?Maybe > > "force" is too strong a word, but Python lends itself to if/elif > > blocks like below, which get the job done just fine, but which are not > > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > > There are often cases where if/elif statements are just a smell that > > you do not know how to do dictionary lookups, but if you converted the > > below code to use dictionary lookups, you would complicate the code > > almost as much as you abstracted the code, if not more, unless I am > > just being very naive. > > I'm gonna have to disagree and say using the dictionary dispatch > technique would clean it up a good bit. > Yes, it would entail creating several functions, but those functions > could then be documented (vs. the currently opaque code blocks); and > due to their separation and smaller length, they would be easier to > understand and test than the given code. > Additionally, the sheer length of the given code segment probably > constitutes a code smell in and of itself for the function containing > that code. > If you introduce seven tiny little methods, aren't you increasing the length of the module by seven lines and introducing more complexity with the dispatch mechanism? (Actually, it's 14 lines more if you put a line of whitespace between your methods, and then you are also blurring an important cue that each of the seven code blocks all perform within the same context.) I do agree with your point that separate methods lead to easier unit testing. I'm a little more skeptical about the documentation/understanding argument, since code is often best understood within the context of surrounding code. I am also a bit skeptical of any coding technique that leads to lexical duplication like {'attr': process_attr, 'key': process_key, 'call': process_call}(ast); that is just replacing one smell with another. Of course, you could do something like __modules__ [kind](ast) too, but that gets a bit overly abstract for a simple dispatch. Having said all that, I'm gonna take your suggestion...thanks for the response! From anh.hai.trinh at gmail.com Wed Nov 18 04:55:24 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Wed, 18 Nov 2009 01:55:24 -0800 (PST) Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: <50a6c08d-51c6-4a51-b246-dbdc19f34b71@f18g2000prf.googlegroups.com> > 1) google list of prime numbers > 2) see "Prime numbers list" in the results (number 3 in the results) > 3) click link that leads towww.prime-numbers.org > > I found 455042511 prime numbers in approx 15 seconds. Not bad at all. How about using http://www.sagemath.org/ (written in Python). sage: time primes_first_n(10^7); CPU times: user 4.36 s, sys: 2.43 s, total: 6.79 s Wall time: 6.88 s That used 3G of RAM, you could certainly go higher if you have more memory. ----aht From showell30 at yahoo.com Wed Nov 18 05:06:49 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 02:06:49 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> On Nov 18, 1:32?am, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > > On the topic of "switch" statements and even-more-concise-then-we-have- > > already if/elif/else/end constructs, I have to say that Python does > > occasionally force you to write code like the code below. ?Maybe > > "force" is too strong a word, but Python lends itself to if/elif > > blocks like below, which get the job done just fine, but which are not > > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > > There are often cases where if/elif statements are just a smell that > > you do not know how to do dictionary lookups, but if you converted the > > below code to use dictionary lookups, you would complicate the code > > almost as much as you abstracted the code, if not more, unless I am > > just being very naive. > > I'm gonna have to disagree and say using the dictionary dispatch > technique would clean it up a good bit. > Yes, it would entail creating several functions, but those functions > could then be documented (vs. the currently opaque code blocks); and > due to their separation and smaller length, they would be easier to > understand and test than the given code. > Additionally, the sheer length of the given code segment probably > constitutes a code smell in and of itself for the function containing > that code. > Here's the rewrite. The indirection from the definition of _dict to the first use of _dict is a little painful (36 lines away), but apart from that I am pleased with how the new code looks, so your points are well taken: kind = ast.kind def _dict(ast): return dictionary(ast, metavar) def _list(ast): ignore, code = dictionary(ast, 'item') code = '[%s for item in %s]' % (code, metavar) return label, code def _attr(ast): return ast.field, '%s.%s' % (metavar, ast.field) def _key(ast): return ast.field, '%s[%s]' % (metavar, repr(ast.field)) def _as(ast): ignore, parent = _code_generate(ast.parent, metavar) return ast.synonym, parent def _call(ast): parent_name, parent = _code_generate(ast.parent, metavar) parent += '()' return parent_name, parent def _recurse(ast): parent = ast.parent expr = ast.expr parent_name, parent = _code_generate(parent, metavar) kind = expr.kind if kind in ['attr', 'key', 'list']: parent_name, parent = _code_generate(expr, parent, parent_name) else: subparent_name, subparent = _code_generate(expr, parent_name) parent = '(lambda %s:\n' % parent_name + indent_block (subparent+')(%s)' % parent) return parent_name, parent dispatches = { 'dict': _dict, 'list': _list, 'attr': _attr, 'key': _key, 'as': _as, 'call': _call, 'recurse': _recurse, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') Thanks! P.S. The underscores before the method names might look a little funny for inner methods, but it's the nature of the code..._dict and _list would lead to confusion with builtins, if not actual conflict. From loftusoft at yahoo.com Wed Nov 18 05:10:09 2009 From: loftusoft at yahoo.com (Mike) Date: Wed, 18 Nov 2009 02:10:09 -0800 (PST) Subject: Stagnant Frame Data? References: Message-ID: <5e6f6aaf-903c-4219-a464-ea6c199d485b@b15g2000yqd.googlegroups.com> On Nov 15, 1:36?pm, Terry Reedy wrote: > Peter Otten wrote: > > Mike wrote: > > >> I'll apologize first for this somewhat lengthy example. It does > >> however recreate the problem I've run into. This is stripped-down code > >> from a much more meaningful system. > > >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate > >> variables in their caller's namespace using the frame stack. As > >> written, the output is not what is expected: the variables evaluate to > >> "stagnant" values. > > >> However, if the one indicated line is uncommented, then the result is > >> as expected. > > >> So my questions are: Is this a bug in Python? > > No. The existence and use of sys._getframe -- notice the leading > underscore -- is a CPython implementation artifact. Use at your own risk. > > ?>> Is this an invalid use of frame data? > > Up to you to decide. > > ?>> Why does the single line "sys._getframe(1).f_locals" > > >> fix the behavior? > > It updates the dictionary. > > > > > A simplified demonstration of your problem: > > >>>> def f(update): > > ... ? ? a = locals() > > ... ? ? x = 42 > > ... ? ? if update: locals() > > ... ? ? print a > > ... > >>>> f(False) > > {'update': False} > >>>> f(True) > > {'a': {...}, 'x': 42, 'update': True} > > > The local namespace is not a dictionary, and the locals()/f_locals > > dictionary contains a snapshot of the local namespace. Accessing the > > f_locals attribute is one way to trigger an update of that snapshot. > > > What's puzzling is that the same dictionary is reused. > > Efficiency? Consistency? The doc for locals says "locals() > Update and return a dictionary representing the current local symbol > table." In class statements, where (currently) the local namespace *is* > a dict, no update is needed and locals() simply returns the dict, the > same one each time. > > Terry Jan Reedy Thanks for the replies. If Peter's concise and much-appreciated example were to be modified as such: >>> def f(update): .....: a = inspect.stack()[0][0].f_locals .....: x = 42 .....: if update: .....: inspect.stack()[0][0].f_locals .....: print a .....: >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} Now there's no use of locals() to perform its documented "Update", but just a simple access of a dictionary. This behavior is curious. Further modification by accessing 'a' instead of '...f_locals' upon update produces: >>> f(False) {'update': False} >>> f(True) {'update': True} Checking the id() of 'a' and '...f_locals' shows the same "address". How is it that '...f_locals' gets updated in this example? Is it done in "stack()"? Where exactly is the frame data stored prior to updating the dictionary and can I get to it? Thanks, Mike From loftusoft at yahoo.com Wed Nov 18 05:10:29 2009 From: loftusoft at yahoo.com (Mike) Date: Wed, 18 Nov 2009 02:10:29 -0800 (PST) Subject: Stagnant Frame Data? References: Message-ID: <5fb36344-c61c-46a9-ba0c-907c0eec9bfc@l13g2000yqb.googlegroups.com> On Nov 15, 1:36?pm, Terry Reedy wrote: > Peter Otten wrote: > > Mike wrote: > > >> I'll apologize first for this somewhat lengthy example. It does > >> however recreate the problem I've run into. This is stripped-down code > >> from a much more meaningful system. > > >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate > >> variables in their caller's namespace using the frame stack. As > >> written, the output is not what is expected: the variables evaluate to > >> "stagnant" values. > > >> However, if the one indicated line is uncommented, then the result is > >> as expected. > > >> So my questions are: Is this a bug in Python? > > No. The existence and use of sys._getframe -- notice the leading > underscore -- is a CPython implementation artifact. Use at your own risk. > > ?>> Is this an invalid use of frame data? > > Up to you to decide. > > ?>> Why does the single line "sys._getframe(1).f_locals" > > >> fix the behavior? > > It updates the dictionary. > > > > > A simplified demonstration of your problem: > > >>>> def f(update): > > ... ? ? a = locals() > > ... ? ? x = 42 > > ... ? ? if update: locals() > > ... ? ? print a > > ... > >>>> f(False) > > {'update': False} > >>>> f(True) > > {'a': {...}, 'x': 42, 'update': True} > > > The local namespace is not a dictionary, and the locals()/f_locals > > dictionary contains a snapshot of the local namespace. Accessing the > > f_locals attribute is one way to trigger an update of that snapshot. > > > What's puzzling is that the same dictionary is reused. > > Efficiency? Consistency? The doc for locals says "locals() > Update and return a dictionary representing the current local symbol > table." In class statements, where (currently) the local namespace *is* > a dict, no update is needed and locals() simply returns the dict, the > same one each time. > > Terry Jan Reedy Thanks for the replies. If Peter's concise and much-appreciated example were to be modified as such: >>> def f(update): .....: a = inspect.stack()[0][0].f_locals .....: x = 42 .....: if update: .....: inspect.stack()[0][0].f_locals .....: print a .....: >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} Now there's no use of locals() to perform its documented "Update", but just a simple access of a dictionary. This behavior is curious. Further modification by accessing 'a' instead of '...f_locals' upon update produces: >>> f(False) {'update': False} >>> f(True) {'update': True} Checking the id() of 'a' and '...f_locals' shows the same "address". How is it that '...f_locals' gets updated in this example? Is it done in "stack()"? Where exactly is the frame data stored prior to updating the dictionary and can I get to it? Thanks, Mike From jeanmichel at sequans.com Wed Nov 18 05:16:20 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 18 Nov 2009 11:16:20 +0100 Subject: TODO and FIXME tags In-Reply-To: <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Message-ID: <4B03C974.9000106@sequans.com> Scott David Daniels wrote: > Martin P. Hellwig wrote: >> Ben Finney wrote: >>> Chris Rebert writes: >>> >>>> 2009/11/16 Yasser Almeida Hern?ndez : >>>>> How is the sintaxis for set the TODO and FIXME tags...? > ... >>> There's no widely-followed ?syntax? for this convention, though. >> Except for _not_ doing what is suggested in those comments, which >> appears to be the biggest convention :-) > > Perhaps: "The comments are a directive to delete the comment if > you happen do this." > > --Scott David Daniels > Scott.Daniels at Acm.Org I guess the world is split in two categories, those how come back to fix the TODO, and those how don't. I for myself belong to the second, that is why I never write TODO comments, I either do the stuff or consider this is not important enough to waste time on it. In other words I mostly agree with Martin, and envy people belonging to the first category. JM From alexis.flesch at free.fr Wed Nov 18 05:47:02 2009 From: alexis.flesch at free.fr (Snouffy) Date: Wed, 18 Nov 2009 02:47:02 -0800 (PST) Subject: PyQt4 4.4.4 : a bug with highlightBlock ? Message-ID: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Hello everybody, I've been trying to do some syntax highlighting using PyQt4. I ported the example given in the documentation of Qt4 to Python. It works fine on my computer at work (which has PyQt4 version 4.3.3) but doesn't on my home computer (which has version 4.4.4) : it gets stuck in an infinite loop. Here is the code : class MyHighlighter(QtGui.QSyntaxHighlighter): def __init__(self, edit): QtGui.QSyntaxHighlighter.__init__(self,edit) def highlightBlock(self, text): myClassFormat = QtGui.QTextCharFormat() myClassFormat.setFontWeight(QtGui.QFont.Bold) myClassFormat.setForeground(QtCore.Qt.darkMagenta) pattern = "\\b[A-Z_]+\\b" expression = QtCore.QRegExp(pattern) index = text.indexOf(expression); while (index >= 0): length = expression.matchedLength() self.setFormat(index, length, myClassFormat) index = text.indexOf(expression, index + length) What am I missing ? Is this a known bug of version 4.4.4 ? Thank you, Alexis. From jeanmichel at sequans.com Wed Nov 18 06:25:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 18 Nov 2009 12:25:14 +0100 Subject: getting properly one subprocess output Message-ID: <4B03D99A.1040509@sequans.com> Hi python fellows, I'm currently inspecting my Linux process list, trying to parse it in order to get one particular process (and kill it). I ran into an annoying issue: The stdout display is somehow truncated (maybe a terminal length issue, I don't know), breaking my parsing. import subprocess commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, stderr=subprocess.PIPE) processList, stderrdata = process.communicate() Here is a sample of what I get in processList.split('\n'): ' "25487 1122 4344 ? 7-17:48:32 2.5 firefox-bin /usr/lib/iceweasel/firefox-"', ' "25492 1122 4892 pts/6 00:08 57.2 ipython /usr/bin/python /usr/bin/ip"', As you can see, to complete process command line is truncated. Any clue on how to get the full version ? JM (python 2.5) From bartc at freeuk.com Wed Nov 18 06:31:45 2009 From: bartc at freeuk.com (bartc) Date: Wed, 18 Nov 2009 11:31:45 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF"syntax? In-Reply-To: References: Message-ID: Dotan Cohen wrote: > 2009/11/16 Steve Ferg steve.ferg.bitbucket at gmail.com: >> I've often thought that a language with this kind of block-free >> syntax would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? >> > > PHP has exactly this: > > if (condition) { > // stuff > } elseif (otherContition) { > // otherStuff > } elseif (yetAnotherCondition) { > // yetOtherStuff > } The OP explicitly said no block delimiters. Your example uses {..}, and doesn't have endif. -- Bartc From sturlamolden at yahoo.no Wed Nov 18 06:31:56 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Nov 2009 03:31:56 -0800 (PST) Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: On 18 Nov, 00:31, Terry Reedy wrote: > The > problem for the future is the switch to multiple cores for further speedups. The GIL is not a big problem for scientists. Scientists are not so dependent on threads as the Java/webdeveloper crowd: - We are used to running multiple processes with MPI. - Numerical libraries running C/Fortran/Assembler will often release the GIL. Python threads are ok for multicores then. - Numerical libraries can be written or compiles for multicores e.g. using OpenMP or special compilers. If FFTW is compiled for multiple cores it does not matter that Python has a GIL. LAPACK will use multiple cores if you use MKL or GotoBLAS, regardless of the GIL. Etc. - A scientist used to MATLAB will think "MEX function" (i.e. C or Fortran) if something is too slow. A web developer used to Java will think "multithreading". From sturlamolden at yahoo.no Wed Nov 18 06:42:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Nov 2009 03:42:13 -0800 (PST) Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7mgpm5F27pqogU1@mid.individual.net> Message-ID: On 18 Nov, 00:24, greg wrote: > NumPy, for example, is *extremely* flexible. Someone put > in the effort, once, to write it and make it fast -- and > now an endless variety of programs can be written very easily > in Python to make use of it. I'm quite sure David Cournapeau knows about NumPy... By the way, NumPy is not particularly fast because of the way it is written. It's performance is hampered by the creation of temporary arrays. But NumPy provides a flexible way of managing memory in scientific programs. From fetchinson at googlemail.com Wed Nov 18 06:55:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 18 Nov 2009 12:55:57 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> References: <4B0152A4.7050307@excess.org> <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> Message-ID: >> How did you make the html 'screenshots'? I guess you have some kind of >> urwid2html tool or some such or is it plain ncurses? > > It's all handled in the demo code. This is from tour.py: > > if urwid.web_display.is_web_request(): > screen = urwid.web_display.Screen() > else: > screen = urwid.raw_display.Screen() Thanks, I missed that. >> Urwid is really cool! > > No argument there :) None, indeed. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From looris at gmail.com Wed Nov 18 07:05:14 2009 From: looris at gmail.com (Lo'oris) Date: Wed, 18 Nov 2009 04:05:14 -0800 (PST) Subject: break LABEL vs. exceptions + PROPOSAL Message-ID: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> I've found this email, back from 10 years ago: http://mail.python.org/pipermail/python-list/1999-September/009983.html I guess it went unnoticed, because that proposal looks really intresting. ? break labels have been refused into python ? we can do it anyway using exceptions ? this is a proposal for something better, resembling "the exception way" and much more powerful and python-like than break labels From simon at brunningonline.net Wed Nov 18 07:31:11 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 18 Nov 2009 12:31:11 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> References: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> Message-ID: <8c7f10c60911180431t66053892y7fa6324dd3a59a46@mail.gmail.com> 2009/11/17 sjm : > On Nov 16, 12:54?pm, Steve Ferg > wrote: > >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? > > Modern-day COBOL: > > IF ? ? ?some-condition > ? ? ? ?do-something > ELSE > ? ? ? ?do-something-else > END-IF. RPG/400's SELEC statement: http://bit.ly/2LDegk Thing of beauty. Cheers, Simon B. From clp2 at rebertia.com Wed Nov 18 07:31:51 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 04:31:51 -0800 Subject: break LABEL vs. exceptions + PROPOSAL In-Reply-To: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> Message-ID: <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> On Wed, Nov 18, 2009 at 4:05 AM, Lo'oris wrote: > I've found this email, back from 10 years ago: > http://mail.python.org/pipermail/python-list/1999-September/009983.html > > I guess it went unnoticed, because that proposal looks really > intresting. > > ? break labels have been refused into python > ? we can do it anyway using exceptions > ? this is a proposal for something better, resembling "the exception > way" and much more powerful and python-like than break labels You're gonna have to wait 18-24 months: http://www.python.org/dev/peps/pep-3003/ Also, the python-ideas list might be a better forum for discussing this than the general-interest list: http://mail.python.org/mailman/listinfo/python-ideas Cheers, Chris -- http://blog.rebertia.com From mal at egenix.com Wed Nov 18 07:34:14 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 18 Nov 2009 13:34:14 +0100 Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures In-Reply-To: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> References: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> Message-ID: <4B03E9C6.4060303@egenix.com> Steve Howell wrote: > During the last few days I have written code in support of a small DDL > language that encapsulates a concise representation of the > manipulations needed to make a deep subcopy of a Python-like data > structure. It is inspired by syntax from mainstream modern languages, > including, of course, Python. The DDL can be converted to an AST. That > AST can be walked to either generate Python code that expresses the > mapping or to generate Python objects that can execute the mapping. > Either of the prior outputs can then subsequently be applied to real > world inputs to create new Python data structures from old ones, using > the mechanisms specified in the original DDL for attribute access, > dictionary lookup, iteration, method invocation, etc. > > Here is an example of the DDL (and I hate the terminology "DDL," just > cannot think of anything better): > > > { > 'show_table_of_contents', > 'author' { > .person 'name', > .person 'location' as city, > .favorite_books()[ > .title, > .cost() as expense > ] as books} > } > > > There are more details here: > > http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html Personally, I find the explicit approach more intuitive, since you immediately see what you are going to get: show_table_of_contents = context['show_table_of_contents'] author = context['author'] d = { 'show_table_of_contents': show_table_of_contents, 'author': { 'name': author.person['name'], 'city': author.person['location'], 'books': [{ 'title': item.title, 'expense': item.cost(), } for item in author.favorite_books()], }, } I particularly find this part non-intuitive: > .favorite_books()[ > .title, > .cost() as expense > ] as books} and would leave in the square brackets for __getitem__ lookups on these: > .person 'name', > .person 'location' as city, For additional inspiration, you might want to look at XSLT which provides similar transformations on XML data structures. There are also a number of other transformation languages: http://en.wikipedia.org/wiki/Model_Transformation_Language http://en.wikipedia.org/wiki/Data_transformation Regarding the term "DDL": that's normally used for "data definition language" and doesn't really have all that much to do with transforming data. You normally define data structures using DDL - without actually putting data into those structures. Why not "PyDTL".... Python data transformation language ?! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 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 thomas at thomas-lotze.de Wed Nov 18 07:55:52 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 13:55:52 +0100 Subject: Minimally intrusive XML editing using Python Message-ID: I wonder what Python XML library is best for writing a program that makes small modifications to an XML file in a minimally intrusive way. By that I mean that information the program doesn't recognize is kept, as are comments and whitespace, the order of attributes and even whitespace around attributes. In short, I want to be able to change an XML file while producing minimal textual diffs. Most libraries don't allow controlling the order of and the whitespace around attributes, so what's generally left to do is store snippets of original text along with the model objects and re-use that for writing the edited XML if the model wasn't modified by the program. Does a library exist that helps with this? Does any XML library at all allow structured access to the text representation of a tag with its attributes? Thank you very much. -- Thomas From ecir.hana at gmail.com Wed Nov 18 08:02:10 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Wed, 18 Nov 2009 05:02:10 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> Message-ID: <32d3502c-f335-42a7-be1c-bb8ddf72d568@d10g2000yqh.googlegroups.com> On Nov 17, 6:51?am, "Gabriel Genellina" wrote: > > The code below now reads from the pipe everything that has been written -- ? > except from Python :( Thanks a lot for the fine code! So far I don't know why it fails to print from Python - I'll post here any news I get... From stefan_ml at behnel.de Wed Nov 18 08:15:07 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 18 Nov 2009 14:15:07 +0100 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4b03f35b$0$7618$9b4e6d93@newsspool1.arcor-online.net> Thomas Lotze, 18.11.2009 13:55: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. Take a look at canonical XML (C14N). In short, that's the only way to get a predictable XML serialisation that can be used for textual diffs. It's supported by lxml. Stefan From clp2 at rebertia.com Wed Nov 18 08:23:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 05:23:54 -0800 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <50697b2c0911180523l6026e984m492806ca0993f3b5@mail.gmail.com> On Wed, Nov 18, 2009 at 4:55 AM, Thomas Lotze wrote: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. > > Most libraries don't allow controlling the order of and the whitespace > around attributes, so what's generally left to do is store snippets of > original text along with the model objects and re-use that for writing the > edited XML if the model wasn't modified by the program. Does a library > exist that helps with this? Does any XML library at all allow structured > access to the text representation of a tag with its attributes? Have you considered using an XML-specific diff tool such as: * One off this list: http://www.manageability.org/blog/stuff/open-source-xml-diff-in-java * xmldiff (it's in Python even): http://www.logilab.org/859 * diffxml: http://diffxml.sourceforge.net/ [Note: I haven't actually used any of these.] Cheers, Chris -- http://blog.rebertia.com From thomas at thomas-lotze.de Wed Nov 18 08:27:00 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 14:27:00 +0100 Subject: Minimally intrusive XML editing using Python References: <4b03f35b$0$7618$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Stefan Behnel wrote: > Take a look at canonical XML (C14N). In short, that's the only way to get a > predictable XML serialisation that can be used for textual diffs. It's > supported by lxml. Thank you for the pointer. IIUC, c14n is about changing an XML document so that its textual representation is reproducible. While this representation would certainly solve my problem if I were to deal with input that's already in c14n form, it doesn't help me handling arbitrarily formatted XML in a minimally intrusive way. IOW, I don't want the XML document to obey the rules of a process, but instead I want a process that respects the textual form my input happens to have. -- Thomas From thomas at thomas-lotze.de Wed Nov 18 08:30:54 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 14:30:54 +0100 Subject: Minimally intrusive XML editing using Python References: Message-ID: Chris Rebert wrote: > Have you considered using an XML-specific diff tool such as: I'm afraid I'll have to fall back to using such a thing if I don't find a solution to what I actually want to do. I do realize that XML isn't primarily about its textual representation, so I guess I shouldn't be surprised if what I'm looking for doesn't exist. Still, it would be nice if it did... -- Thomas From tsize69 at gmail.com Wed Nov 18 08:32:57 2009 From: tsize69 at gmail.com (Tsize) Date: Wed, 18 Nov 2009 05:32:57 -0800 (PST) Subject: ast manipulation References: Message-ID: Terry, Thank you for responding. I actually figured out how to do this shortly after posting the message. Sorry I wasn't quite clear enough in my post, I will try to be a little more explict in the future. Just to mention it I want to go to each node in the ast including child nodes and change the values. I am making a limited mutation analysis program. If it looks generally useful as I get further along I will release the code. I did an early prototype that worked on the text of the code itself but I thought that using the ast for this would be better and maybe a little faster. Regards, Thomas From keith.hughitt at gmail.com Wed Nov 18 09:09:11 2009 From: keith.hughitt at gmail.com (Keith Hughitt) Date: Wed, 18 Nov 2009 06:09:11 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Message-ID: Hi all, I ran into a problem recently when trying to add support for earlier versions of Python (2.4 and 2.5) to some database related code which uses MySQLdb, and was wondering if anyone has any suggestions. With later versions of Python (2.6), inserting Unicode is very simple, e.g.: # -*- coding: utf-8 -*- ... cursor.execute('''INSERT INTO `table` VALUES (0, '?ngstr?m'),...''') When the same code is run on earlier versions, however, the results is either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or an exception being thrown (Python 2.4): UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 60: ordinal not in range(128) So far I've tried a number of different things, including: 1. Using Unicode strings (e.g. u"\u212B") 2. Manually specifying the encoding using sys.setdefaultencoding ('utf-8') 3. Manually enabling Unicode support in MySQLdb (use_unicode=False, charset = "utf8") ...but no combination of any of the above resulted in proper database content. To be certain that the issue was related to Python/MySQLdb and not MySQL itself, I manually inserted the text and it worked just fine. Furthermore, when working in a Python console, both print "?" and print u"\u212B" display the correct output. Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 (Python 2.4), and 1.2.2-10 (Python 2.5). Thanks! Keith From deets at nospam.web.de Wed Nov 18 09:38:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 15:38:06 +0100 Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? References: Message-ID: <7mif6fF3hmd7eU1@mid.uni-berlin.de> Keith Hughitt wrote: > Hi all, > > I ran into a problem recently when trying to add support for earlier > versions of Python (2.4 and 2.5) to some database related code which > uses MySQLdb, and was wondering if anyone has any suggestions. > > With later versions of Python (2.6), inserting Unicode is very simple, > e.g.: > > # -*- coding: utf-8 -*- > ... > cursor.execute('''INSERT INTO `table` VALUES (0, > '?ngstr?m'),...''') You are aware that the coding-declaration only affects unicode-literals (the ones like u"i'm unicode")? So the above insert-statement is *not* unicode, it's a byte-string in whatever encoding your editor happens to save the file in. And that's point two: make sure your editor reads and writes the file in the same encoding you specified in the comment in the beginning. > > When the same code is run on earlier versions, however, the results is > either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or > an exception being thrown (Python 2.4): > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in > position 60: ordinal not in range(128) Makes sense if the execute tries to encode to unicode first - as you didn't give it a unicode-object. > > So far I've tried a number of different things, including: > > 1. Using Unicode strings (e.g. u"\u212B") > > 2. Manually specifying the encoding using sys.setdefaultencoding > ('utf-8') > > 3. Manually enabling Unicode support in MySQLdb > (use_unicode=False, charset = "utf8") You *disabled* unicode here!!!!! Unicode is NOT utf-8!!! http://www.joelonsoftware.com/articles/Unicode.html > > ...but no combination of any of the above resulted in proper database > content. > > To be certain that the issue was related to Python/MySQLdb and not > MySQL itself, I manually inserted the text and it worked just fine. > Furthermore, when working in a Python console, both print "?" and > print u"\u212B" display the correct output. > > Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 > (Python 2.4), and 1.2.2-10 (Python 2.5). Try the above, and better yet provide self-contained examples that show the behavior. Diez From tschmidt at sacfoodcoop.com Wed Nov 18 10:02:23 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Wed, 18 Nov 2009 07:02:23 -0800 (PST) Subject: open source linux -> windows database connectivity? References: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> Message-ID: <632b4319-ba2c-4895-9357-4086f668ea67@f10g2000vbl.googlegroups.com> Woo-hoo! Forget ODBC. Got this working with Jython and JDBC drivers! On Nov 13, 1:03?am, "M.-A. Lemburg" wrote: > TonySchmidtwrote: > >> Note: The client part of this product is free. You only need to > >> get a license for the server part. > > > Yeah, but don't I need the server part to make the connection? > > Sure, but you don't need to get a license per client, unlike for > e.g. the combination mxODBC + EasySoft OOB. > > Regards, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 13 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 victorsubervi at gmail.com Wed Nov 18 10:04:22 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 18 Nov 2009 11:04:22 -0400 Subject: base64MIME problem, Or Just New Email Client Message-ID: <4dc0cfea0911180704h4cdec41ava74249d859bc0c98@mail.gmail.com> Hi; I'm using SimpleMail, available from SF, that used to work fine for me but now I can't build it on my new server. I get this error: [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] import smtplib, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] File "/usr/lib64/python2.4/smtplib. py", line 49, in ?, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] from email.base64MIME import encode as encode_base64, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] ImportError: No module named base64MIME, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] Premature end of script headers: mail.py, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py So, let's try this: [root at 13gems simplemail]# find . |xargs grep 'base64MIME' [root at 13gems simplemail]# What gives? Well, if there ain't no solving this one, can someone recommend a good client for easily generating emails from forms to inject into qmail? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidj411 at gmail.com Wed Nov 18 10:12:33 2009 From: davidj411 at gmail.com (davidj411) Date: Wed, 18 Nov 2009 07:12:33 -0800 (PST) Subject: best performance for storage of server information for python CGI web app? Message-ID: <58e5cd75-75be-4785-8e79-4903643965ce@e31g2000vbm.googlegroups.com> I am wondering what will give me the best performance for storing information about the servers in our environment. currently i store all info about all servers in a single shelve file, but i have concerns. 1) as the size of the shelve file increases, will performance suffer ? 2) what about if 2 updates occur at the same time to the shelve file? when a shelve file is opened, is the whole file read into memory? if either scenario (1 or 2) is true, then should i think about creating a shelve file per server? i was also thinking about using SQL Lite with one DB to store all the info. with this option, i would not have to worry about concurrent updates, but as the file size increases, i could expect performance to suffer again? I am running Python 2.6 CGI scripts on Apache web server on windows platform. they interact with the current shelve file to pull info or request info from a python service which will go collect the info and put it into the shelve file. From invalid at invalid.invalid Wed Nov 18 10:22:38 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Nov 2009 15:22:38 +0000 (UTC) Subject: IOError: [Errno 28] No space left on device References: Message-ID: On 2009-11-18, hong zhang wrote: >> Apparently the harddisk where you stored the file is full? It's not a real file, and takes up no space. > I have plenty space see: > $ df -l > Filesystem 1K-blocks Used Available Use% Mounted on > /dev/sda1 74027808 4910016 65357380 7% / That doesn't matter. /sys doesn't contain real files. It's an API to access kernel internals. > but following is good. > > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx Well, if that works, then what's your problem? -- Grant Edwards grante Yow! I wonder if I ought at to tell them about my visi.com PREVIOUS LIFE as a COMPLETE STRANGER? From tbourden at doc.ic.ac.uk Wed Nov 18 10:34:59 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Wed, 18 Nov 2009 15:34:59 +0000 Subject: non-copy slices Message-ID: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Hi, I was looking for a facility similar to slices in python library that would avoid the implicit creation of a new list and copy of elements that is the default behaviour. Instead I'd rather have a lazy iteratable object on the original sequence. Well, in the end I wrote it myself but I was wondering if I missed sth in the library. If I didn't is there a particular reason there isn't sth like that? I find it hard to believe that all slice needs have strictly copy semantics. Cheers, Themis -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Nov 18 10:44:47 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 18 Nov 2009 07:44:47 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <4B04166F.7060507@stoneleaf.us> tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that > would avoid the implicit creation of a new list and copy of elements > that is the default behaviour. Instead I'd rather have a lazy iteratable > object on the original sequence. Well, in the end I wrote it myself but > I was wondering if I missed sth in the library. If I didn't is there a > particular reason there isn't sth like that? I find it hard to believe > that all slice needs have strictly copy semantics. > > Cheers, > Themis Two questions: 1) What is "sth"? and 2), What copy? Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] In [1]: class dummy(object): ...: pass ...: In [2]: a = dummy() In [3]: b = dummy() In [4]: c = dummy() In [5]: d = dummy() In [6]: e = dummy() In [7]: list1 = [a, b, c, d, e] In [8]: list1 Out[8]: [<__main__.dummy object at 0x0130C510>, <__main__.dummy object at 0x013F1A50>, <__main__.dummy object at 0x00A854F0>, <__main__.dummy object at 0x00A7EF50>, <__main__.dummy object at 0x00A7E650>] In [9]: list2 = list1[1:3] In [10]: list2 Out[10]: [<__main__.dummy object at 0x013F1A50>, <__main__.dummy object at 0x00A854F0>] In [11]: list2[0] is list1[1] Out[11]: *True* In [12]: list2[1] is list1[2] Out[12]: *True* No copying of items going on here. What do you get? ~Ethan~ From mail at timgolden.me.uk Wed Nov 18 10:44:51 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 18 Nov 2009 15:44:51 +0000 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <4B041673.8060503@timgolden.me.uk> tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that would > avoid the implicit creation of a new list and copy of elements that is the > default behaviour. Instead I'd rather have a lazy iteratable object on the > original sequence. Well, in the end I wrote it myself but I was wondering if > I missed sth in the library. If I didn't is there a particular reason there > isn't sth like that? I find it hard to believe that all slice needs have > strictly copy semantics. I suspect that itertools is your friend, specifically itertools.islice TJG From tbourden at doc.ic.ac.uk Wed Nov 18 10:52:47 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Wed, 18 Nov 2009 15:52:47 +0000 Subject: non-copy slices In-Reply-To: <4B041673.8060503@timgolden.me.uk> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B041673.8060503@timgolden.me.uk> Message-ID: <7fd737460911180752x5c685164ia33fa205271f2920@mail.gmail.com> Ahhh yes! that's exactly it. Thanks for pointing out! Themis On Wed, Nov 18, 2009 at 3:44 PM, Tim Golden wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > would > > avoid the implicit creation of a new list and copy of elements that is > the > > default behaviour. Instead I'd rather have a lazy iteratable object on > the > > original sequence. Well, in the end I wrote it myself but I was wondering > if > > I missed sth in the library. If I didn't is there a particular reason > there > > isn't sth like that? I find it hard to believe that all slice needs have > > strictly copy semantics. > > I suspect that itertools is your friend, specifically itertools.islice > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Wed Nov 18 11:14:29 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 08:14:29 -0800 (PST) Subject: getting properly one subprocess output References: Message-ID: <8116484c-3438-419c-a30e-0a1d9fe7481b@37g2000yqm.googlegroups.com> On Nov 18, 11:25?am, Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. > > import subprocess > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > processList, stderrdata = process.communicate() > > Here is a sample of what I get in processList.split('\n'): > > ?' "25487 1122 ? ? ?4344 ? ? ? ? ? 7-17:48:32 ?2.5 firefox-bin ? ? > /usr/lib/iceweasel/firefox-"', > ?' "25492 1122 ? ? ?4892 pts/6 ? ? ? ? ?00:08 57.2 ipython ? ? ? ? > /usr/bin/python /usr/bin/ip"', > > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? > > JM > > (python 2.5) What about "ps -eo pid,tty,cmd" ? Sample: 12680 ? geany /usr/share/gramps/ReportBase/ _CommandLineReport.py 12682 ? gnome-pty-helper 12683 pts/0 /bin/bash 13038 ? gnome-terminal 13039 ? gnome-pty-helper 13040 pts/1 bash 13755 pts/1 ps -eo pid,tty,cmd ...etc... hth, Jon. From joncle at googlemail.com Wed Nov 18 11:28:28 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 08:28:28 -0800 (PST) Subject: getting properly one subprocess output References: <8116484c-3438-419c-a30e-0a1d9fe7481b@37g2000yqm.googlegroups.com> Message-ID: On Nov 18, 4:14?pm, Jon Clements wrote: > On Nov 18, 11:25?am, Jean-Michel Pichavant > wrote: > > > > > Hi python fellows, > > > I'm currently inspecting my Linux process list, trying to parse it in > > order to get one particular process (and kill it). > > I ran into an annoying issue: > > The stdout display is somehow truncated (maybe a terminal length issue, > > I don't know), breaking my parsing. > > > import subprocess > > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > processList, stderrdata = process.communicate() > > > Here is a sample of what I get in processList.split('\n'): > > > ?' "25487 1122 ? ? ?4344 ? ? ? ? ? 7-17:48:32 ?2.5 firefox-bin ? ? > > /usr/lib/iceweasel/firefox-"', > > ?' "25492 1122 ? ? ?4892 pts/6 ? ? ? ? ?00:08 57.2 ipython ? ? ? ? > > /usr/bin/python /usr/bin/ip"', > > > As you can see, to complete process command line is truncated. > > Any clue on how to get the full version ? > > > JM > > > (python 2.5) > > What about "ps -eo pid,tty,cmd" ? > > Sample: > 12680 ? ? ? ? ?geany /usr/share/gramps/ReportBase/ > _CommandLineReport.py > 12682 ? ? ? ? ?gnome-pty-helper > 12683 pts/0 ? ?/bin/bash > 13038 ? ? ? ? ?gnome-terminal > 13039 ? ? ? ? ?gnome-pty-helper > 13040 pts/1 ? ?bash > 13755 pts/1 ? ?ps -eo pid,tty,cmd > > ...etc... > > hth, > > Jon. Another thought: if you're only wanting to find and kill a process, what about pkill? Saves you having to filter the list in Python and then issue a kill command. Jon. From doomster at knuut.de Wed Nov 18 11:42:11 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Wed, 18 Nov 2009 17:42:11 +0100 Subject: using struct module on a file Message-ID: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Hia! I need to read a file containing packed "binary" data. For that, I find the struct module pretty convenient. What I always need to do is reading a chunk of data from the file (either using calcsize() or a struct.Struct instance) and then parsing it with unpack(). For that, I repeatedly write utility functions that help me do just that, but I can't imagine that there is no better way for that. Questions: 0. Am I approaching this from the wrong direction? I'm not a programming noob, but rather new to Python still. 1. The struct module has pack_into() or unpack_from(), could I somehow combine that with a file? 2. Is there some easier way to read files? I know about array and xdrlib, but neither really fit my desires. 3. Failing all that, would you consider this a useful addition to the struct module, i.e. should I write a feature request? Thanks! Uli From "knutjbj(nospam)" at online.no Wed Nov 18 11:48:04 2009 From: "knutjbj(nospam)" at online.no (nospam) Date: Wed, 18 Nov 2009 17:48:04 +0100 Subject: question about tree in python Message-ID: How should I write a tree using diconary. I have used a dictonary to make a tree. tree={best:collections.defaultdict(lambda:default)} in a id3 tree. Is there a way to multple values and when then only return on type of values. I tried this apporach but it did not work. class Tree: def __init__(self): pass def ini(self,default_tree,d_attr): self.tree={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_A={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_I={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_p={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_n={d_attr:collections.defaultdict(lambda:default_tree)} return self.tree def __call__(self,best,val,subtree): self.tree[best][val]=subtree def input_tree(self,best,val,subtree,postive,negative,attribute_value,info_gain): tree=self.tree print best print val tree[best][val]=subtree print self.tree self.tree_A[best][val]= attribute_value self.tree_I[best][val]= info_gain self.tree_p[best][val]= postive self.tree_n=negative tree=self.tree return tree From ppearson at nowhere.invalid Wed Nov 18 11:50:44 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Nov 2009 16:50:44 GMT Subject: Beautifulsoup code that is not running References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Message-ID: <7mimv4F3g0n2uU1@mid.individual.net> On Tue, 17 Nov 2009 14:38:55 -0800 (PST), Zeynel wrote: [snip] >>>> from BeautifulSoup import BeautifulSoup > >>>> soup = BeautifulSoup (file("test.html").read()) >>>> title = soup.find('title') >>>> titleString = title.string >>>> open('extract.text', 'w').write(titleString) > > This runs without an error, but nothing is written into the > extract.text file. test.html has tags in it. Hmm. Works for me, but of course I don't have your test.html. Why don't you try examining "title" and "titleString"? Perhaps has resulted in titleString being the empty string. -- To email me, substitute nowhere->spamcop, invalid->net. From showell30 at yahoo.com Wed Nov 18 12:09:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 09:09:09 -0800 (PST) Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures References: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> Message-ID: <73c2ab31-8277-4f30-b27e-0fe6d7b40390@g1g2000pra.googlegroups.com> On Nov 18, 4:34?am, "M.-A. Lemburg" wrote: > Steve Howell wrote: > > [...] > > Here is an example of the DDL (and I hate the terminology "DDL," just > > cannot think of anything better): > > > ? ? ? ? ? ? { > > ? ? ? ? ? ? ? ? 'show_table_of_contents', > > ? ? ? ? ? ? ? ? 'author' { > > ? ? ? ? ? ? ? ? ? ? .person 'name', > > ? ? ? ? ? ? ? ? ? ? .person 'location' as city, > > ? ? ? ? ? ? ? ? ? ? .favorite_books()[ > > ? ? ? ? ? ? ? ? ? ? ? ? .title, > > ? ? ? ? ? ? ? ? ? ? ? ? .cost() as expense > > ? ? ? ? ? ? ? ? ? ? ? ? ] as books} > > ? ? ? ? ? ? } > > > There are more details here: > > >http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-... Thanks for your feedback, Marc-Andre! Comments inline... > > Personally, I find the explicit approach more intuitive, since > you immediately see what you are going to get: > > show_table_of_contents = context['show_table_of_contents'] > author = context['author'] > d = { > ? ? 'show_table_of_contents': show_table_of_contents, > ? ? 'author': { > ? ? ? ? 'name': author.person['name'], > ? ? ? ? 'city': author.person['location'], > ? ? ? ? 'books': [{ > ? ? ? ? ? ? 'title': item.title, > ? ? ? ? ? ? 'expense': item.cost(), > ? ? ? ? ? ? } > ? ? ? ? ? ? for item in author.favorite_books()], > ? ? ? ? }, > ? ? } > I understand what you mean about the explicit approach. When you go for brevity, you sacrifice some explicitness. One of the things I'm actually looking to do next is to be able to generate code like what you've written above. You could make the generated code even more procedural in terms of how it walks the structure--for example, replace the list comprehension with a for loop. This could be useful for inserting tracing code, for example. > I particularly find this part non-intuitive: > > > ? ? ? ? ? ? ? ? ? ? .favorite_books()[ > > ? ? ? ? ? ? ? ? ? ? ? ? .title, > > ? ? ? ? ? ? ? ? ? ? ? ? .cost() as expense > > ? ? ? ? ? ? ? ? ? ? ? ? ] as books} > Yep, I think what I really want is this: .favorite_books()[{ .title, .cost() as expense }] as books} I am not sure the curlies make the transformation completely intuitive, but they are more suggestive that you are generating a list of dictionaries. > and would leave in the square brackets for __getitem__ > lookups on these: > > > ? ? ? ? ? ? ? ? ? ? .person 'name', > > ? ? ? ? ? ? ? ? ? ? .person 'location' as city, > Yep, I agree. The square brackets were not a deliberate omission. They were just slightly more tricky to implement because of '[' having double syntactical meaning. > For additional inspiration, you might want to look at XSLT > which provides similar transformations on XML data structures. > > There are also a number of other transformation languages: > > http://en.wikipedia.org/wiki/Model_Transformation_Languagehttp://en.wikipedia.org/wiki/Data_transformation > Thanks for the links! > Regarding the term "DDL": that's normally used for "data definition > language" and doesn't really have all that much to do with > transforming data. You normally define data structures using > DDL - without actually putting data into those structures. > > Why not "PyDTL".... Python data transformation language ?! > Yep, I like that suggestion. The language does indeed describe a transformation. In some ways I was wanting to think of it more broadly, in terms that the transformation also acts as a schema for any input objects. For example, you could use '{.title, .publisher, {.name} }' as a schema to validate that an object behaves like a book. I suppose that's still a transformation in an abstract sense, where the output is just True, False, or maybe even the slice of the transformation that can/cannot be executed. From joncle at googlemail.com Wed Nov 18 12:12:14 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 09:12:14 -0800 (PST) Subject: using struct module on a file References: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Message-ID: On Nov 18, 4:42?pm, Ulrich Eckhardt wrote: > Hia! > > I need to read a file containing packed "binary" data. For that, I find the > struct module pretty convenient. What I always need to do is reading a chunk > of data from the file (either using calcsize() or a struct.Struct instance) > and then parsing it with unpack(). For that, I repeatedly write utility > functions that help me do just that, but I can't imagine that there is no > better way for that. > > Questions: > 0. Am I approaching this from the wrong direction? I'm not a programming > noob, but rather new to Python still. > 1. The struct module has pack_into() or unpack_from(), could I somehow > combine that with a file? > 2. Is there some easier way to read files? I know about array and xdrlib, > but neither really fit my desires. > 3. Failing all that, would you consider this a useful addition to the struct > module, i.e. should I write a feature request? > > Thanks! > > Uli First time I've seen zero based indexing for paragraph markers :) unpack_from() will work on anything that supports the buffer interface. To work with files you can use something like: my4chars = struct.Struct('4c') def struct_read(s, f): return s.unpack_from(f.read(s.size)) Which isn't hideously painful. Jon. From brian.curtin at gmail.com Wed Nov 18 12:50:52 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 18 Nov 2009 11:50:52 -0600 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <4B035504.4050508@gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> <4B035504.4050508@gmail.com> Message-ID: On Tue, Nov 17, 2009 at 19:59, Mark Hammond wrote: > On 18/11/2009 6:29 AM, Randall Walls wrote: > >> I don't believe so, but it seems like I'm in a catch 22, where I need to >> _winreg.OpenKey the key first before I can pass it to >> _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. >> >> I did find out that I can open the key using: >> hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, >> r"SOFTWARE\ODBC\ODBC.INI\ >> DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) >> >> The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells >> the system to look in the 64bit key area, and not under the Wow6432Node. >> That brings up problem #2, though... I can't seem to CREATE a key in the >> above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY >> (in fact it doesn't accept any options other than key, sub_key). >> _winreg.CreateKey does work, it just puts the key in >> SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to >> use one or the other, and not have to account for both. >> > > It looks like _winreg needs to be enhanced to make the RegCreateKeyEx API > function available. It can be called via the win32api module of pywin32, or > could also be called via ctypes. > > HTH, > > Mark > Created http://bugs.python.org/issue7347 and added a patch which I think will solve the problem moving forward. -------------- next part -------------- An HTML attachment was scrubbed... URL: From henryzhang62 at yahoo.com Wed Nov 18 12:56:46 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 09:56:46 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <299935.11323.qm@web57901.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 9:22 AM > On 2009-11-18, hong zhang > wrote: > > >> Apparently the harddisk where you stored the file > is full? > > It's not a real file, and takes up no space. > > > I have plenty space see: > > $ df -l > > Filesystem? ? ? ? > ???1K-blocks? ? ? Used > Available Use% Mounted on > > /dev/sda1? ? ? ? ? > ???74027808???4910016? > 65357380???7% / > > That doesn't matter.? /sys doesn't contain real > files.? It's an > API to access kernel internals. > > > but following is good. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >? ? ? with open(i, 'w') as f: > >? ? ? ? ? print >>f, > cont_tx > > Well, if that works, then what's your problem? But error comes from following, above is good. That is point here. def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx -- > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? > ???visi.com? ? ? ? ? > ? PREVIOUS LIFE as a COMPLETE > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? > ???STRANGER? > -- > http://mail.python.org/mailman/listinfo/python-list > From highcar at gmail.com Wed Nov 18 13:04:10 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 10:04:10 -0800 (PST) Subject: DOM related question and problem Message-ID: <26412730.post@talk.nabble.com> Hello, these day im making python script related with DOM. problem is these day many website structure is very complicate . what is best method to check DOM structure and path.. i mean...following is some example. what is best method to check can extract such like following info quickly? before i was spent much time to extract such info . and yes im also new to python and DOM. IE.Document.Frames(1).Document.forms('comment').value = 'hello' if i use DOM inspector, can i extract such info quickly ? if so would you show me some sample? here is some site . i want to extract some dom info. today i was spent all day long to extract what is dom info. but failed http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 at the end of this page,can find some comment input box. i want to know what kind of dom element should have to use, such like IE.Document.Frames(1).Document.forms('comment').value = 'hello' anyhelp much appreciate thanks -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26412730.html Sent from the Python - python-list mailing list archive at Nabble.com. From cjns1989 at gmail.com Wed Nov 18 13:07:53 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Wed, 18 Nov 2009 13:07:53 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <4B0152A4.7050307@excess.org> References: <4B0152A4.7050307@excess.org> Message-ID: <20091118180753.GC3385@turki.gavron.org> I noticed that when run on a 256-color capable xterm, upon exiting the demo programs the colors in the bash shell are modified - e.g the bash prompt, the output of colored ls commands. For instance, due to my fiddling with dircolors, a file with executable flags on is normally displayed in light green and it now appears in bright green, presumably #00ff00. CJ From clp2 at rebertia.com Wed Nov 18 13:10:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 10:10:44 -0800 Subject: DOM related question and problem In-Reply-To: <26412730.post@talk.nabble.com> References: <26412730.post@talk.nabble.com> Message-ID: <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> On Wed, Nov 18, 2009 at 10:04 AM, elca wrote: > Hello, > these day im making python script related with DOM. > > problem is these day many website structure is very complicate . > > what is best method to check DOM structure and path.. > > i mean...following is some example. > > what is best method to check ?can extract such like following info quickly? > > before i was spent much time to extract such info . > > and yes im also new to python and DOM. > > ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' > > if i use DOM inspector, can i extract such info quickly ? if so would you > show me some sample? > > here is some site . i want to extract some dom info. > > today i was spent all day long to extract what is dom info. but failed > > http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 > > at the end of this page,can find some comment input box. > > i want to know what kind of dom element should have to use, such like > > ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' > > anyhelp much appreciate thanks This sounds suspiciously like a spambot. Why do you want to submit comments in an automated fashion exactly? Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Wed Nov 18 13:11:51 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 19:11:51 +0100 Subject: IOError: [Errno 28] No space left on device References: Message-ID: <7mirn7F3g7f0qU1@mid.uni-berlin.de> hong zhang wrote: > > > --- On Wed, 11/18/09, Grant Edwards wrote: > >> From: Grant Edwards >> Subject: Re: IOError: [Errno 28] No space left on device >> To: python-list at python.org >> Date: Wednesday, November 18, 2009, 9:22 AM >> On 2009-11-18, hong zhang >> wrote: >> >> >> Apparently the harddisk where you stored the file >> is full? >> >> It's not a real file, and takes up no space. >> >> > I have plenty space see: >> > $ df -l >> > Filesystem >> 1K-blocks? ? ? Used >> Available Use% Mounted on >> > /dev/sda1 >> 74027808???4910016 >> 65357380???7% / >> >> That doesn't matter.? /sys doesn't contain real >> files.? It's an >> API to access kernel internals. >> >> > but following is good. >> > >> > cont_tx = 1 >> > for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> >with open(i, 'w') as f: >> >print >>f, >> cont_tx >> >> Well, if that works, then what's your problem? > > But error comes from following, above is good. That is point here. > > def do_cont_tx( is_start): > global cont_tx_started, stdscr > if is_start == START and not cont_tx_started: > cont_tx = 1 > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: print >>f, cont_tx -- "cont_x --" doesn't work. So the above can't be the actual code. Diez From tjreedy at udel.edu Wed Nov 18 13:13:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2009 13:13:11 -0500 Subject: break LABEL vs. exceptions + PROPOSAL In-Reply-To: <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Wed, Nov 18, 2009 at 4:05 AM, Lo'oris wrote: >> I've found this email, back from 10 years ago: >> http://mail.python.org/pipermail/python-list/1999-September/009983.html >> >> I guess it went unnoticed, because that proposal looks really >> intresting. I think it went unnoticed because it is not very good, once looked at. >> >> ? break labels have been refused into python >> ? we can do it anyway using exceptions So the proposal is not needed >> ? this is a proposal for something better, resembling "the exception >> way" and much more powerful and python-like than break labels It amounts to duplicating raise x...exception x as break x....continue x in the name of aesthetics and supposed efficiency. There would be no new functionality nor any abbreviation of code. The semantics of break/continue as specific loop subcommands would be changed to 'use anyplace'. The OP gives as a reason the possibility of a typo creating a raise x ... except y mis-match. But a break x ... continue y mismatch is equally likely. Anyway, I think the example given would be better written with immediate assignment followed by simple break, rather than the proposed delayed assignment. The exception example as given would have to be rewritten to work in 3.x. > You're gonna have to wait 18-24 months: > http://www.python.org/dev/peps/pep-3003/ > > Also, the python-ideas list might be a better forum for discussing > this than the general-interest list: > http://mail.python.org/mailman/listinfo/python-ideas This is a fine place to discuss it. Terry Jan Reedy From anthra.norell at bluewin.ch Wed Nov 18 13:17:35 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 18 Nov 2009 19:17:35 +0100 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4B043A3F.8010908@bluewin.ch> Thomas Lotze wrote: > Chris Rebert wrote: > > >> Have you considered using an XML-specific diff tool such as: >> > > I'm afraid I'll have to fall back to using such a thing if I don't find a > solution to what I actually want to do. > > I do realize that XML isn't primarily about its textual representation, so > I guess I shouldn't be surprised if what I'm looking for doesn't exist. > Still, it would be nice if it did... > > Thomas, I just might have what you are looking for. But I want to be sure I understand your problem. So, please show a small sample and explain how you want it modified. Frederic From nobody at nowhere.com Wed Nov 18 13:19:27 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 18:19:27 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 23:57:55 +0000, Rhodri James wrote: >>> Quote the filenames or escape the spaces: >>> >>> C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" >>> >>> We've been living with this pain ever since windowed GUIs encouraged >>> users >>> to put spaces in their file names (Apple, I'm looking at you!). >>> Fundamentally, if people want the pretty they have to live with the >>> consequences. >> >> We've been living with much worse ever since Unix allowed users to put >> not only spaces but even newlines in their filenames. > > You'll notice I said "encouraged", not "allowed". You'll notice I said "allowed", not "encouraged". Code which can't handle spaces in filenames is broken from the outset; it doesn't suddenly break the first time that someone passes a filename containing spaces. I have a suspicion that Win95 put spaces in two of the most important directory names specifically to force developers to deal with this. Nowadays, any Windows program which cannot handle spaces in pathnames is usually a port of a Unix program (and a shoddy one at that). OTOH, I'm surprised at how much Windows software still cannot handle filenames outside of the system codepage (i.e. it's using the byte-oriented API rather than the Unicode API). From lusvehla at gmail.com Wed Nov 18 13:38:19 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Wed, 18 Nov 2009 10:38:19 -0800 (PST) Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: <3381becb-3a90-40f6-a923-1c22ed4068d1@s31g2000yqs.googlegroups.com> On 18 lis, 03:09, "Mark Tolonen" wrote: > "Chris Withers" wrote in message > > news:4B02D1E3.6080308 at simplistix.co.uk... > > > Mark Tolonen wrote: > > >>>> Please I need Calling Python functions from Excel and receive result > >>>> back in Excel. Can me somebody advise simplest solution please? I am > >>>> more VBA programmer than Python. > > >>> Tryhttp://code.google.com/p/pyinex/ > > >> The book Python: Programming on Win32 has a whole chapter on COM, and a > >> section on COM servers. > > > ...and it's generally accepted that COM sucks rocks through straws, so > > explore alternatives when they're available ;-) > > > Chris > > True, but as usual Python makes it pretty darn easy (requires PyWin32): > > ------------- ex.py ------------------------------- > class Example(object): > ? ? _public_methods_ = ['Add','Mul'] > ? ? _reg_progid_ = 'MyPython.Example' > ? ? _reg_clsid_ = '{insert_GUID_here}' > > ? ? def Add(self,a,b): > ? ? ? ? return a+b > > ? ? def Mul(self,a,b): > ? ? ? ? return a*b > > if __name__ == '__main__': > ? ? import win32com.server.register > ? ? win32com.server.register.UseCommandLine(Example) > --------------------------------------------------------- > > -------------- Excel Macro ---------------------- > Sub Testit() > ? ? Set ex = CreateObject("MyPython.Example") > ? ? Range("A1") = ex.Add(1, 2) > ? ? Range("A2") = ex.Mul(3, 4) > End Sub > -------------------------------------------------------- > > Just run the script to register the server. ?"ex.py --unregister" will > remove it. > > -Mark Thanks very much. It works perfectly!!! :-) From nobody at nowhere.com Wed Nov 18 13:44:10 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 18:44:10 +0000 Subject: getting properly one subprocess output References: Message-ID: On Wed, 18 Nov 2009 12:25:14 +0100, Jean-Michel Pichavant wrote: > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? If you only need it to work on Linux, you can just enumerate /proc/[1-9]*/exe or /proc/[1-9]*/cmdline. Or you can add -ww to "ps" to avoid truncating the output. Note that the /proc/*/exe report the actual executable. The command line reported by "ps" (from /proc/*/cmdline) can be modified by the program, so it doesn't necessarily reflect the program being run. From tjreedy at udel.edu Wed Nov 18 13:49:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2009 13:49:27 -0500 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that > would avoid the implicit creation of a new list and copy of elements > that is the default behaviour. Instead I'd rather have a lazy iteratable > object on the original sequence. Well, in the end I wrote it myself but > I was wondering if I missed sth in the library If I didn't is there a > particular reason there isn't sth like that? I find it hard to believe > that all slice needs have strictly copy semantics. It is a strict *shallow* copy. There is no copying of contents. That aside, you are right, hence itertools.islice as already mentioned. In the design of 3.0, I believe the idea was raised of making slices iterables in 3.0, just as was done for map, filter, and range. However, it would have been highly disruptive, and not save much space. Map and range create an unbounded number of new objects, rather than just a sequence of references to existing objects (or bytes or words for bytes and str slices). There is also the problem of virtual slices preventing garbage collection of the source sequence when it is not otherwise needed. Terry Jan Reedy From henryzhang62 at yahoo.com Wed Nov 18 14:15:53 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 11:15:53 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <12689.15967.qm@web57904.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 9:22 AM > On 2009-11-18, hong zhang > wrote: > > >> Apparently the harddisk where you stored the file > is full? > > It's not a real file, and takes up no space. > > > I have plenty space see: > > $ df -l > > Filesystem? ? ? ? > ???1K-blocks? ? ? Used > Available Use% Mounted on > > /dev/sda1? ? ? ? ? > ???74027808???4910016? > 65357380???7% / > > That doesn't matter.? /sys doesn't contain real > files.? It's an > API to access kernel internals. > > > but following is good. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >? ? ? with open(i, 'w') as f: > >? ? ? ? ? print >>f, > cont_tx > > Well, if that works, then what's your problem? But error comes from following, above is good. That is point here. def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx From davea at ieee.org Wed Nov 18 14:16:42 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 14:16:42 -0500 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4B04481A.3000707@ieee.org> Thomas Lotze wrote: > Chris Rebert wrote: > > >> Have you considered using an XML-specific diff tool such as: >> > > I'm afraid I'll have to fall back to using such a thing if I don't find a > solution to what I actually want to do. > > I do realize that XML isn't primarily about its textual representation, so > I guess I shouldn't be surprised if what I'm looking for doesn't exist. > Still, it would be nice if it did... > > What's your real problem, or use case? Are you just concerned with diffing, or are others likely to read the xml, and want it formatted the way it already is? And how general do you need this tool to be? For example, if the only thing you're doing is modifying existing attributes or existing tags, the "minimal change" would be pretty unambiguous. But if you're adding tags, or adding content on what was an empty element, then the requirement gets fuzzy And finding an existing library for something "fuzzy" is unlikely. Sample input, change list, and desired output would be very useful. DaveA From henryzhang62 at yahoo.com Wed Nov 18 14:16:47 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 11:16:47 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <7mirn7F3g7f0qU1@mid.uni-berlin.de> Message-ID: <9734.42752.qm@web57906.mail.re3.yahoo.com> --- On Wed, 11/18/09, Diez B. Roggisch wrote: > From: Diez B. Roggisch > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 12:11 PM > hong zhang wrote: > > > > > > > --- On Wed, 11/18/09, Grant Edwards > wrote: > > > >> From: Grant Edwards > >> Subject: Re: IOError: [Errno 28] No space left on > device > >> To: python-list at python.org > >> Date: Wednesday, November 18, 2009, 9:22 AM > >> On 2009-11-18, hong zhang > >> wrote: > >> > >> >> Apparently the harddisk where you stored > the file > >> is full? > >> > >> It's not a real file, and takes up no space. > >> > >> > I have plenty space see: > >> > $ df -l > >> > Filesystem > >> 1K-blocks? ? ? Used > >> Available Use% Mounted on > >> > /dev/sda1 > >> 74027808???4910016 > >> 65357380???7% / > >> > >> That doesn't matter.? /sys doesn't contain real > >> files.? It's an > >> API to access kernel internals. > >> > >> > but following is good. > >> > > >> > cont_tx = 1 > >> > for i in > >> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> >with open(i, 'w') as f: > >> >print >>f, > >> cont_tx > >> > >> Well, if that works, then what's your problem? > > > > But error comes from following, above is good. That is > point here. > > > > def do_cont_tx( is_start): > > global cont_tx_started, stdscr > > if is_start == START and not cont_tx_started: > > cont_tx = 1 > > for i in > > > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > with open(i, 'w') as f: print >>f, cont_tx -- > > "cont_x --" doesn't work. So the above can't be the actual > code. Sorry, -- is typo. From nobody at nowhere.com Wed Nov 18 14:17:14 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 19:17:14 +0000 Subject: Minimally intrusive XML editing using Python References: Message-ID: On Wed, 18 Nov 2009 13:55:52 +0100, Thomas Lotze wrote: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. > > Most libraries don't allow controlling the order of and the whitespace > around attributes, so what's generally left to do is store snippets of > original text along with the model objects and re-use that for writing the > edited XML if the model wasn't modified by the program. Does a library > exist that helps with this? Does any XML library at all allow structured > access to the text representation of a tag with its attributes? Expat parsers have a CurrentByteIndex field, while SAX parsers have locators. You can use this to identify the portions of the input which need to be processed, and just copy everything else. One downside is that these only report either the beginning (Expat) or end (SAX) of the tag; you'll have to deduce the other side yourself. OTOH, "diff" is probably the wrong tool for the job. From davecook at nowhere.net Wed Nov 18 14:19:40 2009 From: davecook at nowhere.net (Dave Cook) Date: 18 Nov 2009 19:19:40 GMT Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> Message-ID: <00759512$0$8173$c3e8da3@news.astraweb.com> On 2009-11-18, sturlamolden wrote: > GPL If it's an issue for your project, I suggest wxPython. It's cross-platform, fairly complete, and extensible. But the API is clunky compared to Qt. Dave Cook From victorsubervi at gmail.com Wed Nov 18 14:27:11 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 18 Nov 2009 15:27:11 -0400 Subject: A Good Mailer Message-ID: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> Hi; I need a good mailer that will enable me to mail email from web forms. Suggestions? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Wed Nov 18 14:53:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Nov 2009 11:53:34 -0800 Subject: WindowsError is not available on linux? References: Message-ID: In article , Peng Yu wrote: > >It's not clear to me whether WindowsError is available on linux or >not, after I read the document. Here's what I told a co-worker to do yesterday: if os.name == 'nt': DiskError = (OSError, WindowsError) else: DiskError = WindowsError try: disk_operation() except DiskError: logit() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 invalid at invalid.invalid Wed Nov 18 15:00:29 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Nov 2009 20:00:29 +0000 (UTC) Subject: IOError: [Errno 28] No space left on device References: <7mirn7F3g7f0qU1@mid.uni-berlin.de> Message-ID: On 2009-11-18, Diez B. Roggisch wrote: > hong zhang wrote: >>> >>> > but following is good. >>> > >>> > cont_tx = 1 >>> > for i in >>> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>> >with open(i, 'w') as f: >>> >print >>f, >>> cont_tx >>> >>> Well, if that works, then what's your problem? >> >> But error comes from following, above is good. That is point here. >> >> def do_cont_tx( is_start): >> global cont_tx_started, stdscr >> if is_start == START and not cont_tx_started: >> cont_tx = 1 >> for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> with open(i, 'w') as f: print >>f, cont_tx -- > > "cont_x --" doesn't work. So the above can't be the actual code. You never want to post the actual code you're running. That would make it too easy for people to help. -- Grant Edwards grante Yow! My mind is making at ashtrays in Dayton ... visi.com From sajmikins at gmail.com Wed Nov 18 15:10:25 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 18 Nov 2009 15:10:25 -0500 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50f98a4c0911181210y48f5970eg9bdc14ede7225851@mail.gmail.com> On Wed, Nov 18, 2009 at 4:15 AM, Steve Howell wrote: > On the topic of "switch" statements and even-more-concise-then-we-have- > already if/elif/else/end constructs, I have to say that Python does > occasionally force you to write code like the code below. ?Maybe > "force" is too strong a word, but Python lends itself to if/elif > blocks like below, which get the job done just fine, but which are not > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > There are often cases where if/elif statements are just a smell that > you do not know how to do dictionary lookups, but if you converted the > below code to use dictionary lookups, you would complicate the code > almost as much as you abstracted the code, if not more, unless I am > just being very naive. ?Anonymous methods would help to a certain > degree. ?I am not saying I want either anonymous methods or switch > statements, but the lack of either in a language leads to very > procedural looking code when you use number-of-lines-of-code as a > (possibly dubious) metric. > > Maybe this excerpt can be golfed down to something simpler, I would > love to see it! > > ? ? ? ?if kind == 'dict': > ? ? ? ? ? ?return dictionary_schema(ast) > ? ? ? ?elif kind == 'list': > ? ? ? ? ? ?method = dictionary_schema(ast) > ? ? ? ? ? ?return lambda lst: map(method, lst) > ? ? ? ?elif kind == 'attr': > ? ? ? ? ? ?return ((lambda obj: getattr(obj, ast.field)), ast.field) > ? ? ? ?elif kind == 'key': > ? ? ? ? ? ?return (lambda obj: obj.get(ast.field), ast.field) > ? ? ? ?elif kind == 'as': > ? ? ? ? ? ?method, old_name = schema(ast.parent) > ? ? ? ? ? ?return (method, ast.synonym) > ? ? ? ?elif kind == 'call': > ? ? ? ? ? ?method, old_name = schema(ast.parent) > ? ? ? ? ? ?def call(obj): > ? ? ? ? ? ? ? ?return method(obj)() > ? ? ? ? ? ?return (call, old_name) > ? ? ? ?elif kind == 'recurse': > ? ? ? ? ? ?expr = ast.expr > ? ? ? ? ? ?kind = expr.kind > ? ? ? ? ? ?method, field_name = schema(ast.parent) > ? ? ? ? ? ?if kind in ['attr', 'key']: > ? ? ? ? ? ? ? ?new_method, new_field_name = schema(expr) > ? ? ? ? ? ? ? ?field_name = new_field_name > ? ? ? ? ? ?elif kind in ['dict', 'list']: > ? ? ? ? ? ? ? ?new_method = schema(expr) > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?raise Exception('unknown kind!') > ? ? ? ? ? ?def recurse(obj): > ? ? ? ? ? ? ? ?obj = method(obj) > ? ? ? ? ? ? ? ?return new_method(obj) > ? ? ? ? ? ?return (recurse, field_name) > ? ? ? ?else: > ? ? ? ? ? ?raise Exception('unknown kind!') This code is perhaps not a great example of your point. Every "(el){0,1}if" clause (other than the ones in the 'recurse' branch) end in return statements, so the "el's" are pointless. FWIW I might write it like so: class ASTthing: def processAST(self, ast, kind): try: method = getattr(self, 'do_' + kind) except AttributeError: raise Exception('unknown kind!') self.ast = ast return method() def do_dict(self): return dictionary_schema(self.ast) def do_list(self): method = dictionary_schema(self.ast) return lambda lst: map(method, lst) def do_attr(self): field_name = self.ast.field return lambda obj: getattr(obj, field_name), field_name def do_key(self): field_name = self.ast.field return lambda obj: obj.get(field_name), field_name def do_as(self): method, old_name = schema(self.ast.parent) return method, self.ast.synonym def do_call(self): method, old_name = schema(self.ast.parent) return lambda obj: method(obj)(), old_name def do_recurse(self): expr = self.ast.expr kind = expr.kind method, field_name = schema(self.ast.parent) if kind in 'attrkey': new_method, field_name = schema(expr) elif kind in 'dictlist': new_method = schema(expr) else: raise Exception('unknown kind!') def recurse(obj): obj = method(obj) return new_method(obj) return recurse, field_name IMO, that's more pythonic and less complicated. From dotancohen at gmail.com Wed Nov 18 15:20:15 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 Nov 2009 22:20:15 +0200 Subject: Language mavens: Is there a programming with "if then else ENDIF"syntax? In-Reply-To: References: Message-ID: <880dece00911181220s6ca1db17wd7326a1988eef5ae@mail.gmail.com> > The OP explicitly said no block delimiters. Your example uses {..}, and > doesn't have endif. > Just out of habit. I think that PHP, like C, lets you avoid the block deliminators so long as the block all fits on one line. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From t.bourdenas07 at imperial.ac.uk Wed Nov 18 15:22:11 2009 From: t.bourdenas07 at imperial.ac.uk (Themis Bourdenas) Date: Wed, 18 Nov 2009 20:22:11 +0000 Subject: non-copy slices In-Reply-To: References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> Sth else that I noticed as I started using islice. The name is somewhat misleading. Having the slice part in the name I would expect it to imitate the functionality of normal slices. Random access, sub-slicing etc. However, it is only iteratable. Any particular reasons for that? My guess is that it's inside the itertools so it's meant only for iteration and not random access. However, as I told before the name implies the same functionality while the only thing they share is iteration. It's nothing in the library that completely imitates the slice without the copies, right? Cheers, Themis On Wed, Nov 18, 2009 at 6:49 PM, Terry Reedy wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > > would avoid the implicit creation of a new list and copy of elements > > that is the default behaviour. Instead I'd rather have a lazy iteratable > > object on the original sequence. Well, in the end I wrote it myself but > > I was wondering if I missed sth in the library If I didn't is there a > > particular reason there isn't sth like that? I find it hard to believe > > that all slice needs have strictly copy semantics. > > It is a strict *shallow* copy. There is no copying of contents. > That aside, you are right, hence itertools.islice as already mentioned. > In the design of 3.0, I believe the idea was raised of making slices > iterables in 3.0, just as was done for map, filter, and range. However, > it would have been highly disruptive, and not save much space. Map and > range create an unbounded number of new objects, rather than just a > sequence of references to existing objects (or bytes or words for bytes > and str slices). There is also the problem of virtual slices preventing > garbage collection of the source sequence when it is not otherwise needed. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Nov 18 15:38:32 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Nov 2009 15:38:32 -0500 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2009 at 2:53 PM, Aahz wrote: > In article , > Peng Yu ? wrote: >> >>It's not clear to me whether WindowsError is available on linux or >>not, after I read the document. > > Here's what I told a co-worker to do yesterday: > > if os.name == 'nt': > ? ?DiskError = (OSError, WindowsError) > else: > ? ?DiskError = WindowsError > > try: > ? ?disk_operation() > except DiskError: > ? ?logit() > -- Shouldn't that be the other way? if os.name == 'nt': DiskError = OSError, WindowsError else : DiskError = OSError > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > "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 > -- > http://mail.python.org/mailman/listinfo/python-list > From nagle at animats.com Wed Nov 18 15:53:33 2009 From: nagle at animats.com (John Nagle) Date: Wed, 18 Nov 2009 12:53:33 -0800 Subject: Using "setup.py" for an application, not a library module. Message-ID: <4b045c57$0$1603$742ec2ed@news.sonic.net> Most of the documentation for "setup.py" assumes you're packaging a library module. (Ref: "http://docs.python.org/distutils/setupscript.html") How do you properly package an application? What happens on "setup.py install"? Where does the application get installed? Where does the main program go? If I package and build my app, it packages properly, and unpacks and builds into Messager1.0/build/lib which is appropriate for a library, but not an application. Here's the setup file. distutils.core.setup( name='Messager', description="Baudot Teletype RSS and SMS program", version='1.0', author="John Nagle", author_email="nagle at animats.com", packages=['messager'], requires=['pyserial', 'feedparser'] ) John Nagle From hsiehp at ohsu.edu Wed Nov 18 15:57:11 2009 From: hsiehp at ohsu.edu (Ping-Hsun Hsieh) Date: Wed, 18 Nov 2009 12:57:11 -0800 Subject: make two tables having same orders in both column and row names Message-ID: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Hi, I would like to compare values in two table with same column and row names, but with different orders in column and row names. For example, table_A in a file looks like the follows: AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20 Table_B in the other file looks like the follows: AA101 AA109 AA100 AA103 AA102 BB1 2 9 2.3 2 28 BB2 2 9 2.3 1 28 BB9 2 9 2.3 1 28 BB3 2 2 2 1 28 Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? Thanks, PingHsun From exarkun at twistedmatrix.com Wed Nov 18 15:58:51 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Wed, 18 Nov 2009 20:58:51 -0000 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: <20091118205851.27565.344498845.divmod.xquotient.318@localhost.localdomain> On 07:53 pm, aahz at pythoncraft.com wrote: >In article , >Peng Yu wrote: >> >>It's not clear to me whether WindowsError is available on linux or >>not, after I read the document. > >Here's what I told a co-worker to do yesterday: > >if os.name == 'nt': > DiskError = (OSError, WindowsError) >else: > DiskError = WindowsError > >try: > disk_operation() >except DiskError: > logit() This isn't necessary. WindowsError subclasses OSError. Jean-Paul From simon.hibbs at gmail.com Wed Nov 18 16:02:59 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Wed, 18 Nov 2009 13:02:59 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> Message-ID: <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> On 18 Nov, 07:51, sturlamolden wrote: > > GPL PyQT is GPL for now, but Qt itself is available under the LGPL as is PySide. Eventualy PySide, which tracks the PyQT API, will supplant it and the issue will be moot. For now it can be a problem, but PyQT developer licenses are very afordable at only a few hundred dollars. If a commercial project can't aford that, it's got problems. Only you can know enough to make an informed decision. Wx does look more usable than last time I used it for a project and is a fine option too, for me though QT is the gold standard against all others are measured, and generaly found wanting. Simon Hibbs From henryzhang62 at yahoo.com Wed Nov 18 16:08:34 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 13:08:34 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <762634.99131.qm@web57906.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 2:00 PM > On 2009-11-18, Diez B. Roggisch > > wrote: > > hong zhang wrote: > >>> > >>> > but following is good. > >>> > > >>> > cont_tx = 1 > >>> > for i in > >>> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >>> >with open(i, 'w') as f: > >>> >print >>f, > >>> cont_tx > >>> > >>> Well, if that works, then what's your > problem? > >> > >> But error comes from following, above is good. > That is point here. > >> > >> def do_cont_tx( is_start): > >> global cont_tx_started, stdscr > >> if is_start == START and not cont_tx_started: > >> cont_tx = 1 > >> for i in > >> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> with open(i, 'w') as f: print >>f, cont_tx > -- > > > > "cont_x --" doesn't work. So the above can't be the > actual code. > > You never want to post the actual code you're > running.? That > would make it too easy for people to help. > > -- It is typo. > http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Wed Nov 18 16:09:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Nov 2009 22:09:20 +0100 Subject: WindowsError is not available on linux? In-Reply-To: <4B038142.2090302@ieee.org> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> <4B038142.2090302@ieee.org> Message-ID: Dave Angel wrote: > Worse, even if the exception cannot be thrown on a non-Windows > environment, leaving it undefined makes it very awkward to write > portable code. An except clause that can never happen in a particular > environment is pretty innocent. Or somebody can use a base class for > his except clause, to catch this error and other related ones. But it > blows up if you explicitly use this exception. I think that needs > documentation, at a minimum. WindowsError is a subclass of OSError that contains additional Windows specific error information. Just catch OSError and you are on the safe side. Christian From simon.hibbs at gmail.com Wed Nov 18 16:15:25 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Wed, 18 Nov 2009 13:15:25 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> Message-ID: <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> On 17 Nov, 23:25, Kevin Walzer wrote: > On 11/17/09 4:25 PM, Tim Daneliuk wrote: > > > +1 Tkinter for the simple stuff > > You can actually use Tkinter to do quite sophisticated GUI's that rival > anything found in Qt or wx... Neither Tkinteror Wx have anything that come close to QGraphicsView, the Model-View-Delegate framework, the Phonon multimedia framework integration, QtSQL, QtXML, QtSVG, and the many other first grade components in Qt. You can substitute components from other frameworks, e.g. for database access, but then you lose the integration QtSQL has with the model-view-delegate features in other parts of the Qt world. Qt is much more than just a GUI framework, it's more of a rival to something like the MacOS development libraries, or the .NET framework in terms of the library facilities it offers. I think that's why Nokia bought into it. Qt provides them with a platform with the potential to rival the iPhone dev environment. Of course to take full advantage of it you need to invest in learning it all, which is non-trivial. It comes at a cost in time and potential lock-in. But the point is you can't just say Qt is just like Wx. Simon Hibbs From db3l.net at gmail.com Wed Nov 18 16:18:28 2009 From: db3l.net at gmail.com (David Bolen) Date: Wed, 18 Nov 2009 16:18:28 -0500 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: Simon Hibbs writes: > I've had this problem for a few years. I've tried PythonCard, > WxWidgets with WxDesigner, BoaConstructor, etc. None of them come > anywhere close to PyQT/QTDesigner. For me, the killer feature missing from of all of the wx-based designers is that they require sizer based designs at all stages, not even permitting a fixed layout up front as a first draft. Either that or any case I've found permitting a fixed layout, then didn't permit turning that easily into a sizer-based layout. >From an overall design perspective, that was the feature I found most intriguing in QTDesigner. I could randomly drop stuff around the window while doing an initial layout, which is especially helpful when you aren't quite sure yet how you want the layout to look. Then you can select groups of objects and apply the containers to provide for flexible layout. I absolutely prefer sizer-based layouts for a final implementation, but early in the design stages find it more helpful, and freeing, not to be as tied to the containers. With that said, for various reasons I still prefer wxPython to Qt, and at the moment, find wxFormBuilder the best fit for my own designs (even before the direct Python support, just using XRC). -- David From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 16:35:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 21:35:35 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Wed, 18 Nov 2009 09:33:38 +0200, Dotan Cohen wrote: >> Is there any particular reason why this might be a *bad* language- >> design idea? > > It is about as far from OO as one could get. Whether or not that is > "bad" depends on the use case. That's crazy talk. IF...ENDIF is *syntax*, not a programming model. How is this hypothetical Python-like syntax not object oriented? class Parrot: def speak(self): if self.name is None: name = "Polly" else: name = self.name endif return "%s wants a cracker!" % name Syntax controls *how* you instruct the compiler, the programming model controls *what* you instruct the compiler to do. -- Steven From davea at ieee.org Wed Nov 18 17:00:45 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 17:00:45 -0500 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: <4B046E8D.2070100@ieee.org> Benjamin Kaplan wrote: > On Wed, Nov 18, 2009 at 2:53 PM, Aahz wrote: > >> In article , >> Peng Yu wrote: >> >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. >>> >> Here's what I told a co-worker to do yesterday: >> >> if os.name ='nt': >> DiskError =OSError, WindowsError) >> else: >> DiskError =indowsError >> >> try: >> disk_operation() >> except DiskError: >> logit() >> -- >> > > Shouldn't that be the other way? > if os.name ='nt': > DiskError =SError, WindowsError > else : > DiskError =SError > > > Doesn't matter. It's not needed anyway, since WindowsError is derived from OSError. So just use OSError in the except clause. DaveA From lie.1296 at gmail.com Wed Nov 18 17:01:21 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 19 Nov 2009 09:01:21 +1100 Subject: question about tree in python In-Reply-To: References: Message-ID: <4b046f00$1@dnews.tpgi.com.au> nospam wrote: > How should I write a tree using diconary. I have used a dictonary to > make a tree. dictionary tree? root = { 'node_a': { 'node_a_a': 'blah', 'node_a_b': 'foo', 'node_a_c': 'bar', }, 'node_b': { 'node_b_a': 'soo', 'node_b_b': 'flee', 'node_b_c': { 'node_b_c_a': 'bee', 'node_b_c_b': 'fee', 'node_b_c_c': 'dee', }, }, } you can throw in some default dicts as well as necessary... Am I misunderstanding something? From threaderslash at gmail.com Wed Nov 18 17:07:01 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 19 Nov 2009 09:07:01 +1100 Subject: Solved: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Message-ID: ---------- Forwarded message ---------- From: Keith Hughitt To: python-list at python.org Date: Wed, 18 Nov 2009 06:09:11 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Hi all, I ran into a problem recently when trying to add support for earlier versions of Python (2.4 and 2.5) to some database related code which uses MySQLdb, and was wondering if anyone has any suggestions. With later versions of Python (2.6), inserting Unicode is very simple, e.g.: # -*- coding: utf-8 -*- ... cursor.execute('''INSERT INTO `table` VALUES (0, '?ngstr?m'),...''') When the same code is run on earlier versions, however, the results is either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or an exception being thrown (Python 2.4): UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 60: ordinal not in range(128) So far I've tried a number of different things, including: 1. Using Unicode strings (e.g. u"\u212B") 2. Manually specifying the encoding using sys.setdefaultencoding ('utf-8') 3. Manually enabling Unicode support in MySQLdb (use_unicode=False, charset = "utf8") ...but no combination of any of the above resulted in proper database content. To be certain that the issue was related to Python/MySQLdb and not MySQL itself, I manually inserted the text and it worked just fine. Furthermore, when working in a Python console, both print "?" and print u"\u212B" display the correct output. Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 (Python 2.4), and 1.2.2-10 (Python 2.5). Thanks! Keith ---- Hello Keithm, Here is your answer... I run on Python2.5, this syntax works fine for me -- a piece of my code: getMaxID_Query = """SELECT MAX(customerID) FROM customer;""" self.cursorMySQL.execute(getMaxID_Query) Try to use: """ instead of ''' . It will solve your problem. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Wed Nov 18 17:11:23 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 18 Nov 2009 23:11:23 +0100 Subject: python gui builders In-Reply-To: <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> Message-ID: <4B04710B.5050101@gmail.com> Simon Hibbs wrote: > On 18 Nov, 07:51, sturlamolden wrote: > > >> GPL >> > > PyQT is GPL for now, but Qt itself is available under the LGPL as is > PySide. Eventualy PySide, which tracks the PyQT API, will supplant it > and the issue will be moot. For now it can be a problem, but PyQT > developer licenses are very afordable at only a few hundred dollars. > If a commercial project can't aford that, it's got problems. > > Only you can know enough to make an informed decision. Wx does look > more usable than last time I used it for a project and is a fine > option too, for me though QT is the gold standard against all others > are measured, and generaly found wanting. > > Simon Hibbs > Wouldn't it be nice if each fan of some form of GUI-package, would post it's code (and resulting images) for generating one or two standard GUI-forms ? Then everyone can judge the differences, and see what's simple and not so simple !! And of course I'm willing to contribute the wxPython (wrapped in some convenience procedures) for it. cheers, Stef From philip at semanchuk.com Wed Nov 18 17:17:47 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 18 Nov 2009 17:17:47 -0500 Subject: Using "setup.py" for an application, not a library module. In-Reply-To: <4b045c57$0$1603$742ec2ed@news.sonic.net> References: <4b045c57$0$1603$742ec2ed@news.sonic.net> Message-ID: On Nov 18, 2009, at 3:53 PM, John Nagle wrote: > Most of the documentation for "setup.py" assumes you're packaging a > library module. (Ref: "http://docs.python.org/distutils/setupscript.html > ") > How do you properly package an application? What happens > on "setup.py install"? Where does the application get installed? > Where does > the main program go? > > If I package and build my app, it packages properly, and > unpacks and builds into > > Messager1.0/build/lib > > which is appropriate for a library, but not an application. > Here's the setup file. > > > distutils.core.setup( > name='Messager', > description="Baudot Teletype RSS and SMS program", > version='1.0', > author="John Nagle", > author_email="nagle at animats.com", > packages=['messager'], > requires=['pyserial', 'feedparser'] > ) Hi John, I'm not sure what part you find unpalatable other than "lib" being in the pathname. I recently wrote a setup.py for an app called Analysis. Under OS X, Linux and Windows it installs into the site-packages directory so I can run it like so: python C:\Python25\Lib\site-packages\analysis\main.py or: python /usr/local/lib/python2.6/dist-packages/analysis/main.py Now, packaging an application according to the expectations of the platform to provide a double-clickable icon will require something like py2exe or py2app. distutils doesn't provide a facility for that. DOes that give you an idea about what you were asking? bye Philip From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 17:22:51 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 22:22:51 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > P.S. The underscores before the method names might look a little funny > for inner methods, but it's the nature of the code..._dict and _list > would lead to confusion with builtins, if not actual conflict. Then name them something sensible that tells what they do! The convention (which you break at your peril) is that functions are verbs, and classes are nouns. Even "handle_dict" is better than _dict -- the latter looks like you're calling a private mapping type. -- Steven From nick at stinemates.org Wed Nov 18 17:30:41 2009 From: nick at stinemates.org (Nick Stinemates) Date: Wed, 18 Nov 2009 17:30:41 -0500 Subject: A Good Mailer In-Reply-To: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> References: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> Message-ID: <20091118223041.GA30691@stinemates.org> On Wed, Nov 18, 2009 at 03:27:11PM -0400, Victor Subervi wrote: > Hi; > I need a good mailer that will enable me to mail email from web forms. smtplib > Suggestions? silly example.. #!/usr/bin/env python import smtplib session = smtplib.SMTP("localhost") username = "abc" password = "def" session.login(username, password) # only if it requires auth subject = "Hello, " header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" message = "world!" email_from = "victor at is.awesome" email_to = ["email at myhost.com"] session.sendmail(email_from, email_to, header+messages) HTH, Nick Stinemates > TIA, > Victor > -- > http://mail.python.org/mailman/listinfo/python-list From sajmikins at gmail.com Wed Nov 18 17:42:21 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 18 Nov 2009 17:42:21 -0500 Subject: using struct module on a file In-Reply-To: <7mimf5F3ikmbuU1@mid.uni-berlin.de> References: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Message-ID: <50f98a4c0911181442w44868e0dva88296521478bbef@mail.gmail.com> On Wed, Nov 18, 2009 at 11:42 AM, Ulrich Eckhardt wrote: > Hia! > > I need to read a file containing packed "binary" data. For that, I find the > struct module pretty convenient. What I always need to do is reading a chunk > of data from the file (either using calcsize() or a struct.Struct instance) > and then parsing it with unpack(). For that, I repeatedly write utility > functions that help me do just that, but I can't imagine that there is no > better way for that. > > Questions: > 0. Am I approaching this from the wrong direction? I'm not a programming > noob, but rather new to Python still. > 1. The struct module has pack_into() or unpack_from(), could I somehow > combine that with a file? > 2. Is there some easier way to read files? I know about array and xdrlib, > but neither really fit my desires. > 3. Failing all that, would you consider this a useful addition to the struct > module, i.e. should I write a feature request? > > Thanks! > > Uli You might look at "Construct": http://construct.wikispaces.com/ ~Simon From doesnotexist at franzoni.invalid Wed Nov 18 17:55:19 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Wed, 18 Nov 2009 22:55:19 GMT Subject: Using "setup.py" for an application, not a library module. In-Reply-To: <4b045c57$0$1603$742ec2ed@news.sonic.net> References: <4b045c57$0$1603$742ec2ed@news.sonic.net> Message-ID: On 11/18/09 9:53 PM, John Nagle wrote: > Most of the documentation for "setup.py" assumes you're packaging a > library module. (Ref: "http://docs.python.org/distutils/setupscript.html") > How do you properly package an application? What happens > on "setup.py install"? Where does the application get installed? Where > does > the main program go? Usually, just package the lib and from your "main program" (e.g. the script that goes in /usr/bin, for instance), do just something like that: #!/usr/bin/python from mylib import main import sys sys.exit(main()) -- Alan Franzoni contact me at public@[mysurname].eu From kw at codebykevin.com Wed Nov 18 17:56:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 18 Nov 2009 17:56:58 -0500 Subject: python gui builders In-Reply-To: <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> Message-ID: <4B047BBA.5040405@codebykevin.com> On 11/18/09 4:15 PM, Simon Hibbs wrote: > On 17 Nov, 23:25, Kevin Walzer wrote: >> On 11/17/09 4:25 PM, Tim Daneliuk wrote: >> >>> +1 Tkinter for the simple stuff >> >> You can actually use Tkinter to do quite sophisticated GUI's that rival >> anything found in Qt or wx... > > Neither Tkinteror Wx have anything that come close to QGraphicsView, > the Model-View-Delegate framework, the Phonon multimedia framework > integration, QtSQL, QtXML, QtSVG, and the many other first grade > components in Qt. You can substitute components from other frameworks, > e.g. for database access, but then you lose the integration QtSQL has > with the model-view-delegate features in other parts of the Qt world. A few points of response: -I was focusing primarily on the UI bits, not the other parts of Qt. People tend to think that Tkinter only has labels, listboxes, buttons and menus: recent advances in Tk have greatly expanded and modernized the available widgets. There's also a rich econsystem of widget packages within Tk that can be wrapped in Tkinter. -Qt's support for things like SQL and XML make sense in a Pythonic context mainly if you're focusing on their integration with other parts of Qt. Python has many of these things just fine on its own, as you doubtless know. > > Qt is much more than just a GUI framework, it's more of a rival to > something like the MacOS development libraries, or the .NET framework > in terms of the library facilities it offers. I think that's why Nokia > bought into it. Qt provides them with a platform with the potential to > rival the iPhone dev environment. Of course, and I certainly wasn't claiming otherwise. > > Of course to take full advantage of it you need to invest in learning > it all, which is non-trivial. It comes at a cost in time and potential > lock-in. But the point is you can't just say Qt is just like Wx. > wxWidgets (the C++ library) has support for a lot of things other than UI bits, as well. wxPython itself is mainly a GUI library because the additional features of wxWidgets in C++ are redundant in Python. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 18:02:31 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 23:02:31 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Wed, 18 Nov 2009 01:53:50 -0800, Steve Howell wrote: > On Nov 18, 1:32?am, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell >> wrote: >> > On the topic of "switch" statements and >> > even-more-concise-then-we-have- already if/elif/else/end constructs, >> > I have to say that Python does occasionally force you to write code >> > like the code below. ?Maybe "force" is too strong a word, but Python >> > lends itself to if/elif blocks like below, which get the job done >> > just fine, but which are not syntactically pretty, due to the >> > "(el){0,1}if kind ==" duplication. There are often cases where >> > if/elif statements are just a smell that you do not know how to do >> > dictionary lookups, but if you converted the below code to use >> > dictionary lookups, you would complicate the code almost as much as >> > you abstracted the code, if not more, unless I am just being very >> > naive. >> >> I'm gonna have to disagree and say using the dictionary dispatch >> technique would clean it up a good bit. Yes, it would entail creating >> several functions, but those functions could then be documented (vs. >> the currently opaque code blocks); and due to their separation and >> smaller length, they would be easier to understand and test than the >> given code. Additionally, the sheer length of the given code segment >> probably constitutes a code smell in and of itself for the function >> containing that code. >> >> > If you introduce seven tiny little methods, aren't you increasing the > length of the module by seven lines and introducing more complexity with > the dispatch mechanism? (Actually, it's 14 lines more if you put a line > of whitespace between your methods, and then you are also blurring an > important cue that each of the seven code blocks all perform within the > same context.) Dear me, the 1960s called, they want their controversy over structured programming back *wink* Yes, you increase the length of the module by having function headers. You also increase the length of the module by using meaningful names instead of calling everything "a", "b", "c" etc. We're not playing code golf, there's no reward for making unreadable code. The dispatch mechanism is no more complicated than a series of if...elif statements. In fact, you can replace an arbitrary number of "if x == y" statements with a *single* lookup: if x == 1: return 27 elif x == 2: return 14 elif x == 5: return 7 else: return -1 becomes the single line: return {1: 27, 2: 14, 5: 7}.get(x, -1) (although for more complicated examples, you would put the dict into its own line, or even lines). Dispatching isn't a panacea. You can't (easily) replace a series of if...elif statements where the conditions being tested aren't equality tests, e.g.: if 0 <= x <= 1: return 27 elif 1 < x < 1.5 or x == 2: return 14 elif ... is hard to turn into a dispatcher. But it's still a very useful technique when it applies. > I do agree with your point that separate methods lead to easier unit > testing. > > I'm a little more skeptical about the documentation/understanding > argument, since code is often best understood within the context of > surrounding code. That depends on the code. In particular, it depends on how coupled the code is. Ideally, you should have loosely coupled code, not highly coupled. If the code is loosely coupled, then there's no problem with understanding it in isolation. If the code is highly coupled, then it is hard to refactor it into a separate function, but that's a side-effect of the original problem, namely the high degree of coupling. As a general rule, if you need to know the context of the surrounding code to understand a function, you have too much coupling. > I am also a bit skeptical of any coding technique > that leads to lexical duplication like {'attr': process_attr, 'key': > process_key, 'call': process_call}(ast); that is just replacing one > smell with another. But how is that different from this? if condition(x, 'attr'): return process_attr(x)(ast) elif condition(x, 'key'): return process_key(x)(ast) elif ... Lexical duplication is one of the weakest code smells around, because it is so prone to false negatives. You often can't avoid referring to the same lexical element multiple times: def sinc(x): if x != 0: return sin(x)/x return 1 That's four references to x in a four line function. Is this a problem? No, of course not. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 18:27:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 23:27:15 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: On Wed, 18 Nov 2009 18:28:11 +1300, greg wrote: > r wrote: >> I think the syntax was chosen because the alternatives are even worse >> AND since assignment is SO common in programming, would you *really* >> rather type two chars instead of one? > > Smalltalk solved the problem by using a left-arrow character for > assignment. But they had an unfair advantage in being able to use a > non-standard character set on their custom-built machines. > > We should be able to do a lot better now using Unicode. We could even > heal the <> vs != rift by using a real not-equal symbol! The problem isn't with the available characters, but with *typing* them. It is hard to enter arbitrary Unicode characters by the keyboard, which frankly boggles my mind. I don't know what the state of the art on Mac is these days, but in 1984s Macs had a standard keyboard layout that let you enter most available characters via the keyboard, using sensible mnemonics. E.g. on a US keyboard layout, you could get ? by holding down the Option key and typing =. For me, I had to: Click Start menu > Utilities > More Applications > KCharSelect. Click through thirty-four(!) tables scanning by eye for the symbol I wanted. Click the ? character. Click To Clipboard. Go back to my editor window and paste. -- Steven From wells at submute.net Wed Nov 18 18:28:04 2009 From: wells at submute.net (Wells) Date: Wed, 18 Nov 2009 15:28:04 -0800 (PST) Subject: Arcane question regarding white space, editors, and code collapsing Message-ID: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> I work in TextMate a lot, which I generally love, but it's code collapsing confounds me. Essentially you have to indent blank lines to the proper level for the current block. Then it will collapse that section as one section. If you have simply a new line, it will see it as a break, and not collapse, though the python interpreter doesn't care- it only cares about lines of actual code. Is it... pythonic, then, to have these lines of tabs/spaces to support code collapsing? Is it proper, improper, or irrelevant? Thanks. From ben+python at benfinney.id.au Wed Nov 18 18:56:35 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 10:56:35 +1100 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> Message-ID: <87fx8bl74c.fsf@benfinney.id.au> Wells writes: > Is it... pythonic, then, to have these lines of tabs/spaces to support > code collapsing? Is it proper, improper, or irrelevant? It's quite improper (though syntactically null, in Python) to have trailing whitespace on lines. That includes blank lines. One major reason is that trailing whitespace causes spurious invisible differences between otherwise-identical lines when doing an automatic comparison, which is done quite a lot in collaboration and version control. Fix your text editor (which may entail switching to a better text editor) to respect blank lines and the conventions of the language. -- \ ?Hey Homer! You're late for English!? ?Pff! English, who needs | `\ that? I'm never going to England!? ?Barney & Homer, _The | _o__) Simpsons_ | Ben Finney From showell30 at yahoo.com Wed Nov 18 18:58:24 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 15:58:24 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Nov 18, 2:22?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > > P.S. The underscores before the method names might look a little funny > > for inner methods, but it's the nature of the code..._dict and _list > > would lead to confusion with builtins, if not actual conflict. > > Then name them something sensible that tells what they do! > > The convention (which you break at your peril) is that functions are > verbs, and classes are nouns. Even "handle_dict" is better than _dict -- > the latter looks like you're calling a private mapping type. > Do you verbify functions with no side effects? Do you prefer calculate_cosine(angle) to cosine(angle)? From caldwellinva at verizon.net Wed Nov 18 19:14:13 2009 From: caldwellinva at verizon.net (Doug) Date: Wed, 18 Nov 2009 16:14:13 -0800 (PST) Subject: Writing a Carriage Return in Unicode Message-ID: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Hi! I am trying to write a UTF-8 file of UNICODE strings with a carriage return at the end of each line (code below). filOpen = codecs.open("c:\\temp\\unicode.txt",'w','utf-8') str1 = u'This is a test.' str2 = u'This is the second line.' str3 = u'This is the third line.' strCR = u"\u240D" filOpen.write(str1 + strCR) filOpen.write(str2 + strCR) filOpen.write(str3 + strCR) filOpen.close() The output looks like This is a test.???This is the second line.???This is the third line.??? when opened in Wordpad as a UNICODE file. Thanks for your help!! From showell30 at yahoo.com Wed Nov 18 19:44:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 16:44:09 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 18, 3:02?pm, Steven D'Aprano wrote: > > That depends on the code. In particular, it depends on how coupled the > code is. Ideally, you should have loosely coupled code, not highly > coupled. If the code is loosely coupled, then there's no problem with > understanding it in isolation. If the code is highly coupled, then it is > hard to refactor it into a separate function, but that's a side-effect of > the original problem, namely the high degree of coupling. > Different blocks of an if/elif/elif/elif/elif/end are never directly coupled to each other, since you know that only one of the blocks is gonna execute. The blocks inherently do not effect each other. What you really achieve by extracting the code from an inside an elif block into a method is decoupling the elif block from the code ABOVE the if. This in and of itself is a good thing, of course, because you get a nice clean namespace in the extracted method, and you make the coupling between the code ABOVE the if and the extracted method explicit by specifying which parameters get passed. And in the case of my original code, all seven methods that were extracted only depended on a single parameter, the variable I was calling "ast," so it was easy to dispatch them all using the same mechanism. (In my case I didn't achieve much in terms of cleaning the local namespace, since the only variable defined above the if/elif/elif/elif/end was "kind," but I did make my code less brittle to future changes.) I am not going to defend "if/elif/elif/elif/elif/end" too vigorously here. There are obvious advantages to extracting methods, even methods that only ever get called from one parent. I do not miss switch statements one bit in Python. I am little more ambivalent about anonymous methods. It pains me just a tiny bit whenever I have write code like this: dispatches = { 'dict': handle_dict, 'list': handle_list, 'attr': handle_attr, 'key': handle_key, 'as': handle_as, 'call': handle_call, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') I have used the idiom that Simon suggested in an earlier post, shown below, but it is still brittle to name changes in a way that anonymous methods are not, because you can't break an inline anonymous method with a name change (the benefits on anonymity!!): try: method = getattr(self, 'do_' + kind) except AttributeError: raise Exception('unknown kind!') self.ast = ast return method() From highcar at gmail.com Wed Nov 18 19:50:08 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 16:50:08 -0800 (PST) Subject: DOM related question and problem In-Reply-To: <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> References: <26412730.post@talk.nabble.com> <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> Message-ID: <26418556.post@talk.nabble.com> Chris Rebert-6 wrote: > > On Wed, Nov 18, 2009 at 10:04 AM, elca wrote: >> Hello, >> these day im making python script related with DOM. >> >> problem is these day many website structure is very complicate . >> >> what is best method to check DOM structure and path.. >> >> i mean...following is some example. >> >> what is best method to check ?can extract such like following info >> quickly? >> >> before i was spent much time to extract such info . >> >> and yes im also new to python and DOM. >> >> ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' >> >> if i use DOM inspector, can i extract such info quickly ? if so would you >> show me some sample? >> >> here is some site . i want to extract some dom info. >> >> today i was spent all day long to extract what is dom info. but failed >> >> http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 >> >> at the end of this page,can find some comment input box. >> >> i want to know what kind of dom element should have to use, such like >> >> ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' >> >> anyhelp much appreciate thanks > > This sounds suspiciously like a spambot. Why do you want to submit > comments in an automated fashion exactly? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello this is not spambot actually. it related with my blog scraper.. anyone can help me or advice much appreciate -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26418556.html Sent from the Python - python-list mailing list archive at Nabble.com. From phlip2005 at gmail.com Wed Nov 18 19:58:42 2009 From: phlip2005 at gmail.com (Phlip) Date: Wed, 18 Nov 2009 16:58:42 -0800 (PST) Subject: combinatorics via __future__ generators Message-ID: Python: I have a quaint combinatorics problem. Before I solve it, or find a solution among "generators", I thought y'all might like to show off any solutions. Given an array like this... [0, 4, 3] Produce an array like this: [ [0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 1, 2], [0, 2, 2], [0, 3, 2], ] The first array is the counts of options in 4 slots, and the second is all combinations of indexes of each option, such that every option associates once with every other option. The leading 0 simply represents a slot with no options; the algorithm must preserve those. This should be child's play for the generator package, right? -- Phlip http://zeekland.zeroplayer.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:06:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:06:07 GMT Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: On Thu, 19 Nov 2009 10:56:35 +1100, Ben Finney wrote: > Wells writes: > >> Is it... pythonic, then, to have these lines of tabs/spaces to support >> code collapsing? Is it proper, improper, or irrelevant? > > It's quite improper (though syntactically null, in Python) to have > trailing whitespace on lines. That includes blank lines. Blank lines are far from improper in Python, they're recommended by PEP 8. > One major reason is that trailing whitespace causes spurious invisible > differences between otherwise-identical lines when doing an automatic > comparison, which is done quite a lot in collaboration and version > control. Then you need better comparison software that doesn't give so many false matches due to insignificant differences. > Fix your text editor (which may entail switching to a better text > editor) to respect blank lines and the conventions of the language. Yes, if the editor's handling of code collapsing is broken, it needs to be fixed, or replaced. -- Steven From python at mrabarnett.plus.com Wed Nov 18 20:06:33 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 19 Nov 2009 01:06:33 +0000 Subject: Writing a Carriage Return in Unicode In-Reply-To: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <4B049A19.6050600@mrabarnett.plus.com> Doug wrote: > Hi! > > I am trying to write a UTF-8 file of UNICODE strings with a carriage > return at the end of each line (code below). > > filOpen = codecs.open("c:\\temp\\unicode.txt",'w','utf-8') > > str1 = u'This is a test.' > str2 = u'This is the second line.' > str3 = u'This is the third line.' > > strCR = u"\u240D" > > filOpen.write(str1 + strCR) > filOpen.write(str2 + strCR) > filOpen.write(str3 + strCR) > > filOpen.close() > > The output looks like > This is a test.???This is the second line.???This is the third > line.??? when opened in Wordpad as a UNICODE file. > > Thanks for your help!! u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a visible "CR" graphic) for carriage return. Windows programs normally expect lines to end with '\r\n'; just use u'\n' in programs and open the text files in text mode ('r' or 'w'). Some Windows programs won't recognise UTF-8 text as UTF-8 in files unless they start with a BOM; this will be handled automatically in Python if you specify the encoding as 'utf-8-sig'. From phlip2005 at gmail.com Wed Nov 18 20:07:28 2009 From: phlip2005 at gmail.com (Phlip) Date: Wed, 18 Nov 2009 17:07:28 -0800 (PST) Subject: combinatorics via __future__ generators References: Message-ID: <88c8996b-3e8c-41a5-95b8-87fcb89e70d1@n35g2000yqm.googlegroups.com> On Nov 18, 4:58?pm, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > > ? [0, 4, 3] > > Produce an array like this: > > ? [ > ? ? [0, 0, 0], > ? ? [0, 1, 0], > ? ? [0, 2, 0], > ? ? [0, 3, 0], [0, 0, 1], > [0, 1, 1], > ? ? [0, 2, 1], > ? ? [0, 3, 1], [0, 0, 2], > [0, 1, 2], > ? ? [0, 2, 2], > ? ? [0, 3, 2], > ] I forgot those combinations! > > The first array is the counts of options in 4 slots, and the second is > all combinations of indexes of each option, such that every option > associates once with every other option. The leading 0 simply > represents a slot with no options; the algorithm must preserve those. > > This should be child's play for the generator package, right? > > -- > ? Phlip > ?http://zeekland.zeroplayer.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:13:22 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:13:22 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 15:58:24 -0800, Steve Howell wrote: > On Nov 18, 2:22?pm, Steven D'Aprano > wrote: >> On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: >> > P.S. The underscores before the method names might look a little >> > funny for inner methods, but it's the nature of the code..._dict and >> > _list would lead to confusion with builtins, if not actual conflict. >> >> Then name them something sensible that tells what they do! >> >> The convention (which you break at your peril) is that functions are >> verbs, and classes are nouns. Even "handle_dict" is better than _dict >> -- the latter looks like you're calling a private mapping type. >> >> > Do you verbify functions with no side effects? Do you prefer > calculate_cosine(angle) to cosine(angle)? Neither, I prefer cos(angle). Mathematical functions are a special case. They have been around since long before computers, and there is a whole different tradition for them. (The tradition is that most functions are named after Euler, or the first person to discover them after Euler.) But you're right, the convention of using verbs for functions isn't as strong as the convention of using nouns for classes and types. Functions that return some property of a noun are often named after the property: len(x) rather than get_len(x) sqrt(x) rather than calculate_sqrt(x) and similar. Likewise, conversion functions are often named after the return result: int(x) returns an int str(x) returns a str [pedant] these are actually types, not functions, in Python [/pedant] But I'm not sure what naming convention you used. It seems fairly arbitrary to me, but whatever it is, it clashes with built-ins, which is a good sign that you need a different set of names. Since naming the functions with leading underscores also clashes with the convention that such functions are private, that's a further sign that you should use a different naming convention. At the point that you are apologizing for the convention you use, maybe you should rethink it. But of course it's your code, and you're free to use whatever convention you like. -- Steven From showell30 at yahoo.com Wed Nov 18 20:14:27 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 17:14:27 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> On Nov 18, 3:02?pm, Steven D'Aprano wrote: > Lexical duplication is one of the weakest code smells around, because it > is so prone to false negatives. You often can't avoid referring to the > same lexical element multiple times: > > def sinc(x): > ? ? if x != 0: > ? ? ? ? return sin(x)/x > ? ? return 1 > The existence of one code sample where lexical duplication is a false negative should not get you into the habit of disregarding it all together. In my rewritten code, here is the smell: dispatches = { 'dict': _dict, 'list': _list, 'attr': _attr, 'key': _key, 'as': _as, 'call': _call, 'recurse': _recurse, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') There is nothing wrong with the code taken out of context, but one of the first things that lexical duplication should alert you to is the fact that you are creating code that is brittle to extension. In my example, the reference to _dict is 36 lines of code away from its implementation, which forces indirection on the reader. So maybe the methods in between def _dict and _dict are too long. I can pretty quickly rule that out, as the methods average about four lines each. So maybe the dispatch method is calling out the need for a class, as Simon suggested in another post. I also wonder if an inline decorator is in order. One thing I promise not to do is revert the code to if/elif/elif. :) From azeynel1 at gmail.com Wed Nov 18 20:23:07 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 17:23:07 -0800 (PST) Subject: DeprecationWarning on md5 Message-ID: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Hello, I am a newbie both in Scrapy and Python. When I create a project with Scrapy I get these errors: C:\Python26\lib\site-packages\twisted\python\filepath.py:12: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha C:\Python26\lib\site-packages\twisted\spread\pb.py:30: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: DeprecationWarning: the MimeWriter module is deprecated; use the email package instead I found several references to this "bug" but I could not understand how to fix it. Can anyone help? Thanks From showell30 at yahoo.com Wed Nov 18 20:25:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 17:25:43 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: <17aa3a4b-57da-414b-846f-f78bbcdf2120@f20g2000prn.googlegroups.com> On Nov 18, 5:13?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 15:58:24 -0800, Steve Howell wrote: > > On Nov 18, 2:22?pm, Steven D'Aprano > > wrote: > >> On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > >> > P.S. The underscores before the method names might look a little > >> > funny for inner methods, but it's the nature of the code..._dict and > >> > _list would lead to confusion with builtins, if not actual conflict. > [...] > > But I'm not sure what naming convention you used. It seems fairly > arbitrary to me, but whatever it is, it clashes with built-ins, which is > a good sign that you need a different set of names. Since naming the > functions with leading underscores also clashes with the convention that > such functions are private, that's a further sign that you should use a > different naming convention. At the point that you are apologizing for > the convention you use, maybe you should rethink it. > > But of course it's your code, and you're free to use whatever convention > you like. > The code in question, with the _list and _dict, is used as a part of mini-compiler-like-thingy that generates code from an expression syntax. If you've ever worked with code to implement compilers, interpreters, VMs, etc., you probably know the naming challenges involved. The whole reason I mentioned the wierd names in a "P.S." was to say that I realized it was a little wierd, and it was kind of besides the point. But I have enjoyed your responses. They are slightly pedantic, of course, but in a good way! Makes me think about the code more... If you want more context on the code itself (apart from if/elif discussion and other digressions), I describe it in more detail here: http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html From ben+python at benfinney.id.au Wed Nov 18 20:27:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 12:27:41 +1100 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: <87skcbjoc2.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 19 Nov 2009 10:56:35 +1100, Ben Finney wrote: > > > It's quite improper (though syntactically null, in Python) to have > > trailing whitespace on lines. That includes blank lines. > > Blank lines are far from improper in Python, they're recommended by > PEP 8. I phrased that poorly. I meant ?That [admonishment against trailing whitespace] includes trailing whitespace on otherwise-empty lines?. > > One major reason is that trailing whitespace causes spurious > > invisible differences between otherwise-identical lines when doing > > an automatic comparison, which is done quite a lot in collaboration > > and version control. > > Then you need better comparison software that doesn't give so many > false matches due to insignificant differences. I have such tools, but I shouldn't require others to also have and use them. It would be irresponsible of me to spew output that causes breakage in the absence of such tools. My position on this is: be strict in what you emit (i.e. no trailing whitespace), and construct your output to function well with lowest-common-denominator standard tools (i.e. don't expect sophistication above the standard ?diff -u? etc.). -- \ ?It's up to the masses to distribute [music] however they want | `\ ? The laws don't matter at that point. People sharing music in | _o__) their bedrooms is the new radio.? ?Neil Young, 2008-05-06 | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:42:44 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:42:44 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 17:14:27 -0800, Steve Howell wrote: > In my rewritten code, here is the smell: > > dispatches = { > 'dict': _dict, > 'list': _list, > 'attr': _attr, > 'key': _key, > 'as': _as, > 'call': _call, > 'recurse': _recurse, > } > if kind in dispatches: > return dispatches[kind](ast) > else: > raise Exception('unknown kind!') > > > There is nothing wrong with the code taken out of context, but one of > the first things that lexical duplication should alert you to is the > fact that you are creating code that is brittle to extension. Really? It is very simple to extend it by adding another key:item to the dict. > In my > example, the reference to _dict is 36 lines of code away from its > implementation, which forces indirection on the reader. It gets worse -- the reference to the in operator is in a completely different module to the implementation of the in operator, which may be in a completely different language! (C in this case.) I'm being sarcastic, of course, but I do have a serious point. I'm not impressed by complaints that the definition of the function is oh-so-very- far-away from where you use it. Well duh, that's one of the reasons we have functions, so they can be used anywhere, not just where they're defined. If a function *only* makes sense immediately where you use it, then the level of coupling is too great and you should either reduce the coupling or bite the bullet and live with all the hassles of inline code. (Code duplication, difficulty in testing, etc.) Of course it would be convenient if, having noticed the reference to (say) function _recurse, you could see its definition without needing to do more than just glance up a line or two. But you should rarely need to care about the implementation -- that's another point of functions. You should be able to treat _recurse as a black box, just as you use the built-in function len as a black box without needing to see its implementation every time you use it. -- Steven From caldwellinva at gmail.com Wed Nov 18 20:46:15 2009 From: caldwellinva at gmail.com (Doug) Date: Wed, 18 Nov 2009 17:46:15 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <399ce95b-311d-4af4-acfe-d4bdd1b74bda@g27g2000yqn.googlegroups.com> Hi! Thanks for clearing this up!! From tbourden at doc.ic.ac.uk Wed Nov 18 20:47:09 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Thu, 19 Nov 2009 01:47:09 +0000 Subject: non-copy slices In-Reply-To: <4B04166F.7060507@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> Message-ID: <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> Hi, sth == something :) sorry for the abbreviation. I'm talking about the shallow copy, still it's a copy. Unnecessary in my case and the worst part in my scenario is the creation (allocation) and deletion of a very large number of lists of moderate size (a few hundred objects) generated due to slices, while I only need to have a restricted view on the original list. The islice class partially solves the problem as I mentioned in the previous emails. Cheers, Themis On Wed, Nov 18, 2009 at 3:44 PM, Ethan Furman wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > > would avoid the implicit creation of a new list and copy of elements > > that is the default behaviour. Instead I'd rather have a lazy iteratable > > object on the original sequence. Well, in the end I wrote it myself but > > I was wondering if I missed sth in the library. If I didn't is there a > > particular reason there isn't sth like that? I find it hard to believe > > that all slice needs have strictly copy semantics. > > > > Cheers, > > Themis > > Two questions: 1) What is "sth"? and 2), What copy? > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] > In [1]: class dummy(object): > ...: pass > ...: > > In [2]: a = dummy() > In [3]: b = dummy() > In [4]: c = dummy() > In [5]: d = dummy() > In [6]: e = dummy() > In [7]: list1 = [a, b, c, d, e] > In [8]: list1 > Out[8]: > [<__main__.dummy object at 0x0130C510>, > <__main__.dummy object at 0x013F1A50>, > <__main__.dummy object at 0x00A854F0>, > <__main__.dummy object at 0x00A7EF50>, > <__main__.dummy object at 0x00A7E650>] > > In [9]: list2 = list1[1:3] > In [10]: list2 > Out[10]: > [<__main__.dummy object at 0x013F1A50>, > <__main__.dummy object at 0x00A854F0>] > > In [11]: list2[0] is list1[1] > Out[11]: *True* > In [12]: list2[1] is list1[2] > Out[12]: *True* > > No copying of items going on here. What do you get? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Nov 18 21:06:16 2009 From: rt8396 at gmail.com (r) Date: Wed, 18 Nov 2009 18:06:16 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: On Nov 18, 5:27?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 18:28:11 +1300, greg wrote: > > r wrote: > >> I think the syntax was chosen because the alternatives are even worse > >> AND since assignment is SO common in programming, would you *really* > >> rather type two chars instead of one? > > > Smalltalk solved the problem by using a left-arrow character for > > assignment. But they had an unfair advantage in being able to use a > > non-standard character set on their custom-built machines. > > > We should be able to do a lot better now using Unicode. We could even > > heal the <> vs != rift by using a real not-equal symbol! > > The problem isn't with the available characters, but with *typing* them. > > It is hard to enter arbitrary Unicode characters by the keyboard, which > frankly boggles my mind. I don't know what the state of the art on Mac is > these days, but in 1984s Macs had a standard keyboard layout that let you > enter most available characters via the keyboard, using sensible > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > the Option key and typing =. > > For me, I had to: > > Click Start menu > Utilities > More Applications > KCharSelect. > Click through thirty-four(!) tables scanning by eye for the symbol I > wanted. > Click the ? character. > Click To Clipboard. > Go back to my editor window and paste. > > -- > Steven ? <-- Heres a free lesson... Stephen, hold down and press twice, then release . ;-) PS: But please lets not start using Unicode chars in programming, you guy's already know how much i *hate* Unicode. From clp2 at rebertia.com Wed Nov 18 21:12:45 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:12:45 -0800 Subject: DeprecationWarning on md5 In-Reply-To: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> References: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Message-ID: <50697b2c0911181812k32736d7cuc3075daa29ea1a6e@mail.gmail.com> On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > Hello, > > I am a newbie both in Scrapy and Python. When I create a project with > Scrapy I get these errors: > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > DeprecationWarning: the sha module is deprecated; use the hashlib > module instead import sha > C:\Python26\lib\site-packages\twisted\spread\pb.py:30: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > import md5 > C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: > DeprecationWarning: the MimeWriter module is deprecated; use the email > package instead > > I found several references to this "bug" but I could not understand > how to fix it. Can anyone help? This is a "bug" in the version of Twisted you're using. What Python is saying is that Twisted is using some modules from the Python stdlib that are deprecated and will be removed in some future version of Python, thus Twisted will /eventually/ need to be changed to use the newer replacement library. However, this is only a warning, not an error; the code will run just fine until you update to the eventual Python version that removed said deprecated libraries (by which time a new Twisted version will probably be available with the necessary fixes made). So, basically you can safely ignore the warnings, unless you want to custom-patch your Twisted installation, which I wouldn't particularly recommend. It's also entirely possible your Twisted is outdated and a new version fixed to avoid using the deprecated modules is already available. If you want to suppress the output of the warnings, see the docs for the `warnings` module: http://docs.python.org/library/warnings.html Cheers, Chris -- http://blog.rebertia.com From bluefisher80 at gmail.com Wed Nov 18 21:16:13 2009 From: bluefisher80 at gmail.com (Jim Qiu) Date: Wed, 18 Nov 2009 18:16:13 -0800 (PST) Subject: Invitation to connect on LinkedIn Message-ID: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> LinkedIn ------------ Jim Qiu requested to add you as a connection on LinkedIn: ------------------------------------------ Jaime, I'd like to add you to my professional network on LinkedIn. - Jim Accept invitation from Jim Qiu http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I431163609_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvej0ScPoNcjcQiiZNnSFSd55EjiYTcP4NejgPdPwLrCBxbOYWrSlI/EML_comm_afe/ View invitation from Jim Qiu http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I431163609_3/0PnPAMdzcScj4Pd4ALqnpPbOYWrSlI/svi/ ------------------------------------------ Why might connecting with Jim Qiu be a good idea? Jim Qiu's connections could be useful to you: After accepting Jim Qiu's invitation, check Jim Qiu's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. ------ (c) 2009, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Wed Nov 18 21:27:47 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 20:27:47 -0600 Subject: What is the naming convention for accessor of a 'private' variable? Message-ID: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> http://www.python.org/dev/peps/pep-0008/ The above webpage states the following naming convention. Such a variable can be an internal variable in a class. I'm wondering what is the naming convention for the method that access such variable. - _single_leading_underscore: weak "internal use" indicator. E.g. "from M import *" does not import objects whose name starts with an underscore. From showell30 at yahoo.com Wed Nov 18 21:28:06 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 18:28:06 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> Message-ID: <0b37cc8c-9ef8-4ae1-a64d-957e161f74b8@2g2000prl.googlegroups.com> On Nov 18, 5:42?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 17:14:27 -0800, Steve Howell wrote: > > In my rewritten code, here is the smell: > > > ? ? dispatches = { > > ? ? ? ? ? ? 'dict': _dict, > > ? ? ? ? ? ? 'list': _list, > > ? ? ? ? ? ? 'attr': _attr, > > ? ? ? ? ? ? 'key': _key, > > ? ? ? ? ? ? 'as': _as, > > ? ? ? ? ? ? 'call': _call, > > ? ? ? ? ? ? 'recurse': _recurse, > > ? ? ? ? ? ? } > > ? ? if kind in dispatches: > > ? ? ? ? return dispatches[kind](ast) > > ? ? else: > > ? ? ? ? raise Exception('unknown kind!') > > > There is nothing wrong with the code taken out of context, but one of > > the first things that lexical duplication should alert you to is the > > fact that you are creating code that is brittle to extension. > > Really? It is very simple to extend it by adding another key:item to the > dict. > Easy for me to extend, of course, since I wrote the code. It's the maintainers I am worried about. I can make their lives easier, of course, by changing the text of the exception to say something like this: "Silly maintenance programmer, you now have to update the dispatch table!" I have no problem with that. > > In my > > example, the reference to _dict is 36 lines of code away from its > > implementation, which forces indirection on the reader. > > It gets worse -- the reference to the in operator is in a completely > different module to the implementation of the in operator, which may be > in a completely different language! (C in this case.) > > I'm being sarcastic, of course, but I do have a serious point. I'm not > impressed by complaints that the definition of the function is oh-so-very- > far-away from where you use it. Well duh, that's one of the reasons we > have functions, so they can be used anywhere, not just where they're > defined. > The slippery slope here is that every block of code that you ever write should be extracted out into a method. Now I am all in favor of tiny methods, but the whole point of if/elif/elif/elif/elif/end code is that you are actually calling out to the maintenance programmer that this code is only applicable in certain conditions. That's why "if" statements are called "conditionals"! You are actually telling the maintenance programmer that is only sensible to use these statements under these conditions. It is actually extremely explicit. Now I'm being sarcastic too, but I also have a serious point. Nine times out of ten if/elif/elif/end calls out the smell of spaghetti code. But it can also occasionally be a false negative. It can be a case of avoiding premature abstraction and indirection. From henryzhang62 at yahoo.com Wed Nov 18 21:29:59 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 18:29:59 -0800 (PST) Subject: hex In-Reply-To: <50697b2c0911181812k32736d7cuc3075daa29ea1a6e@mail.gmail.com> Message-ID: <441732.63062.qm@web57901.mail.re3.yahoo.com> List, I want to input hex number instead of int number. in type="int" in following, parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", default=0, help="index of 11n mcs table. Default: 0.") How can I do it? Thanks. --henry From clp2 at rebertia.com Wed Nov 18 21:42:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:42:07 -0800 Subject: combinatorics via __future__ generators In-Reply-To: References: Message-ID: <50697b2c0911181842x3b791e7bwc37fbe097ad9ef2@mail.gmail.com> On Wed, Nov 18, 2009 at 4:58 PM, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > > ?[0, 4, 3] > > Produce an array like this: > > ?[ > ? ?[0, 0, 0], > ? ?[0, 1, 0], > ? ?[0, 2, 0], > ? ?[0, 3, 0], > ? ?[0, 1, 1], > ? ?[0, 2, 1], > ? ?[0, 3, 1], > ? ?[0, 1, 2], > ? ?[0, 2, 2], > ? ?[0, 3, 2], > ] > > The first array is the counts of options in 4 slots, and the second is > all combinations of indexes of each option, such that every option > associates once with every other option. The leading 0 simply > represents a slot with no options; the algorithm must preserve those. > > This should be child's play for the generator package, right? from itertools import imap, product def special_range(n): return (xrange(n) if n else [0]) def something(arr): return product(*imap(special_range, arr)) print list(something([0,4,3])) Cheers, Chris -- http://blog.rebertia.com From daniel at stutzbachenterprises.com Wed Nov 18 21:47:07 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 18 Nov 2009 20:47:07 -0600 Subject: non-copy slices In-Reply-To: <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> Message-ID: On Wed, Nov 18, 2009 at 2:22 PM, Themis Bourdenas < t.bourdenas07 at imperial.ac.uk> wrote: > It's nothing in the library that completely imitates the slice without the > copies, right? You might be interested in my blist extension type (link below). Syntactically, using a blist is just like using a list, but it has different performance characteristics. In particular for your needs, taking a slice is cheap. The blist implements copy-on-write behind the scenes, so taking a slice takes O(log n) time, where n is the size of the initial blist. http://pypi.python.org/pypi/blist/ Here is a simple example, which creates a blist with over 500 million elements and takes a slice of over 500 million elements. In under 22 microseconds. :-) from blist import blist small_list = blist([0]) BIG_list = small_list * 2**29 BIG_slice = BIG_list[4:-5] Cashew:~$ python2.5 -m timeit -s 'from blist import blist' 'small_list=blist([0])' ''BIG_list=small_list*2**29' 'BIG_slice=BIG_list[4:-5]' 10000 loops, best of 3: 21.5 usec per loop -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 18 21:47:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:47:34 -0800 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: > http://www.python.org/dev/peps/pep-0008/ > > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. > > ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M > ? ? ?import *" does not import objects whose name starts with an underscore. If there's a method to access the variable, then it's not all that private, is it? Accessor methods are not Pythonic. Just make the attribute public by not prefixing it with an underscore. See also "Python is Not Java": http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris -- http://blog.rebertia.com From benjamin.kaplan at case.edu Wed Nov 18 21:50:14 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Nov 2009 21:50:14 -0500 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: On Wed, Nov 18, 2009 at 9:27 PM, Peng Yu wrote: > http://www.python.org/dev/peps/pep-0008/ > > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. > > ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M > ? ? ?import *" does not import objects whose name starts with an underscore. > -- You never have any convention for a method that accesses the private variable. In a language that has scope declarations, a method that uses private variables is still declared public or private- there's no special keyword for it. > http://mail.python.org/mailman/listinfo/python-list > From pengyu.ut at gmail.com Wed Nov 18 21:51:37 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 20:51:37 -0600 Subject: convert a string to a regex? Message-ID: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> There are many special characters listed on http://docs.python.org/library/re.html I'm wondering if there is a convenient function that can readily convert a string with the special characters to its corresponding regex. For example, "some.thing" => "some\.thing" From rami.chowdhury at gmail.com Wed Nov 18 22:00:17 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 18 Nov 2009 19:00:17 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> Message-ID: <200911181900.17759.rami.chowdhury@gmail.com> On Wednesday 18 November 2009 17:47:09 tbourden at doc.ic.ac.uk wrote: > Hi, > > sth == something :) sorry for the abbreviation. I'm talking about the > shallow copy, still it's a copy. I'm not sure you're understanding the point others have been making. A list item is merely another reference to an existing object -- it doesn't copy the object in any way. > Unnecessary in my case and the worst > part in my scenario is the creation (allocation)> and deletion of a > very large number of lists of moderate size (a few hundred objects) > generated due to slices, while I only need to have a restricted view > on the original list. > The islice class partially solves the problem > as I mentioned in the previous emails. > > Cheers, > Themis > > On Wed, Nov 18, 2009 at 3:44 PM, Ethan Furman wrote: > > tbourden at doc.ic.ac.uk wrote: > > > Hi, > > > > > > I was looking for a facility similar to slices in python library > > > that would avoid the implicit creation of a new list and copy of > > > elements that is the default behaviour. Instead I'd rather have a > > > lazy iteratable object on the original sequence. Well, in the end > > > I wrote it myself but I was wondering if I missed sth in the > > > library. If I didn't is there a particular reason there isn't sth > > > like that? I find it hard to believe that all slice needs have > > > strictly copy semantics. > > > > > > Cheers, > > > Themis > > > > Two questions: 1) What is "sth"? and 2), What copy? > > > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > > (Intel)] > > In [1]: class dummy(object): > > ...: pass > > ...: > > > > In [2]: a = dummy() > > In [3]: b = dummy() > > In [4]: c = dummy() > > In [5]: d = dummy() > > In [6]: e = dummy() > > In [7]: list1 = [a, b, c, d, e] > > In [8]: list1 > > Out[8]: > > [<__main__.dummy object at 0x0130C510>, > > <__main__.dummy object at 0x013F1A50>, > > <__main__.dummy object at 0x00A854F0>, > > <__main__.dummy object at 0x00A7EF50>, > > <__main__.dummy object at 0x00A7E650>] > > > > In [9]: list2 = list1[1:3] > > In [10]: list2 > > Out[10]: > > [<__main__.dummy object at 0x013F1A50>, > > <__main__.dummy object at 0x00A854F0>] > > > > In [11]: list2[0] is list1[1] > > Out[11]: *True* > > In [12]: list2[1] is list1[2] > > Out[12]: *True* > > > > No copying of items going on here. What do you get? > > > > ~Ethan~ > > -- > > http://mail.python.org/mailman/listinfo/python-list > ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From ben+python at benfinney.id.au Wed Nov 18 22:01:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 14:01:45 +1100 Subject: What is the naming convention for accessor of a 'private' variable? References: Message-ID: <87iqd7jjza.fsf@benfinney.id.au> Peng Yu writes: > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. A property named with a regular public attribute name:: class Foo(object): def __init__(self, spam): self._spam = spam @property def spam(self): return self._spam -- \ ?The only tyrant I accept in this world is the still voice | `\ within.? ?Mahatma Gandhi | _o__) | Ben Finney From pengyu.ut at gmail.com Wed Nov 18 22:03:02 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:03:02 -0600 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <366c6f340911181903s7b956696q2949aa898a1b10df@mail.gmail.com> On Wed, Nov 18, 2009 at 8:50 PM, Benjamin Kaplan wrote: > On Wed, Nov 18, 2009 at 9:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >> ? ? ?import *" does not import objects whose name starts with an underscore. >> -- > > You never have any convention for a method that accesses the private > variable. In a language that has scope declarations, a method that > uses private variables is still declared public or private- there's no > special keyword for it. I knew this. That's why I put quote around 'private' in the email subject. From clp2 at rebertia.com Wed Nov 18 22:03:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:03:59 -0800 Subject: Invitation to connect on LinkedIn In-Reply-To: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> References: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> Message-ID: <50697b2c0911181903p1b5e981ek88fea19aa89537f5@mail.gmail.com> On Wed, Nov 18, 2009 at 6:16 PM, Jim Qiu wrote: > > LinkedIn > > Jim Qiu requested to add you as a connection on LinkedIn: > > Jaime, > > I'd like to add you to my professional network on LinkedIn. > > - Jim > > > Accept View invitation from Jim Qiu > > > WHY MIGHT CONNECTING WITH JIM QIU BE A GOOD IDEA? > > Jim Qiu's connections could be useful to you > After accepting Jim Qiu's invitation, check Jim Qiu's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. > > > > ? 2009, LinkedIn Corporation > > -- > http://mail.python.org/mailman/listinfo/python-list Could one of the list admins please reset the password and change the email on this guy's LinkedIn account? How the heck someone sets their account email to a mailinglist, I'll never figure out. Cheers, Chris -- http://blog.rebertia.com From pengyu.ut at gmail.com Wed Nov 18 22:04:46 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:04:46 -0600 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> Message-ID: <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >> ? ? ?import *" does not import objects whose name starts with an underscore. > > If there's a method to access the variable, then it's not all that > private, is it? > Accessor methods are not Pythonic. Just make the attribute public by > not prefixing it with an underscore. > > See also "Python is Not Java": > http://dirtsimple.org/2004/12/python-is-not-java.html I don't quite understand the following paragraph from the above webpage. Would you please give me an example to help me understand it? "Here's what you do. You write a function that contains a function. The inner function is a template for the functions that you're writing over and over again, but with variables in it for all the things that vary from one case of the function to the next. The outer function takes parameters that have the same names as those variables, and returns the inner function. Then, every place where you'd otherwise be writing yet another function, simply call the outer function, and assign the return value to the name you want the "duplicated" function to appear. Now, if you need to change how the pattern works, you only have to change it in one place: the template." From clp2 at rebertia.com Wed Nov 18 22:06:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:06:04 -0800 Subject: convert a string to a regex? In-Reply-To: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> Message-ID: <50697b2c0911181906p10127fafv493f4c3f82d3e01f@mail.gmail.com> On Wed, Nov 18, 2009 at 6:51 PM, Peng Yu wrote: > There are many special characters listed on > http://docs.python.org/library/re.html > > I'm wondering if there is a convenient function that can readily > convert a string with the special characters to its corresponding > regex. For example, > > "some.thing" => "some\.thing" If you'd taken 45 seconds to scan the documentation: http://docs.python.org/library/re.html#re.escape re.escape(string) Return string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it. Cheers, Chris -- http://blog.rebertia.com From python.list at tim.thechases.com Wed Nov 18 22:12:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 18 Nov 2009 21:12:29 -0600 Subject: convert a string to a regex? In-Reply-To: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> Message-ID: <4B04B79D.7090908@tim.thechases.com> > There are many special characters listed on > http://docs.python.org/library/re.html > > I'm wondering if there is a convenient function that can readily > convert a string with the special characters to its corresponding > regex. For example, > > "some.thing" => "some\.thing" Did you try bothering to *read* the page you linked to? There's a function for escaping strings right there... Literacy...a worthwhile skill to obtain. -tkc From pengyu.ut at gmail.com Wed Nov 18 22:27:58 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:27:58 -0600 Subject: convert a string to a regex? In-Reply-To: <4B04B79D.7090908@tim.thechases.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> <4B04B79D.7090908@tim.thechases.com> Message-ID: <366c6f340911181927q79542233x7b770a3ec5ee0511@mail.gmail.com> On Wed, Nov 18, 2009 at 9:12 PM, Tim Chase wrote: >> There are many special characters listed on >> http://docs.python.org/library/re.html >> >> I'm wondering if there is a convenient function that can readily >> convert a string with the special characters to its corresponding >> regex. For example, >> >> "some.thing" => "some\.thing" > > Did you try bothering to *read* the page you linked to? > > There's a function for escaping strings right there... > > Literacy...a worthwhile skill to obtain. Sorry, I didn't see it. If there are examples besides explanations for each command, it will help people see the usage of each command more easily. From clp2 at rebertia.com Wed Nov 18 22:32:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:32:03 -0800 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> Message-ID: <50697b2c0911181932r4c65cdd7ted8c638224f3b5a1@mail.gmail.com> On Wed, Nov 18, 2009 at 7:04 PM, Peng Yu wrote: > On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >>> http://www.python.org/dev/peps/pep-0008/ >>> >>> The above webpage states the following naming convention. Such a >>> variable can be an internal variable in a class. I'm wondering what is >>> the naming convention for the method that access such variable. >>> >>> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >>> ? ? ?import *" does not import objects whose name starts with an underscore. >> >> If there's a method to access the variable, then it's not all that >> private, is it? >> Accessor methods are not Pythonic. Just make the attribute public by >> not prefixing it with an underscore. >> >> See also "Python is Not Java": >> http://dirtsimple.org/2004/12/python-is-not-java.html > > I don't quite understand the following paragraph from the above > webpage. Would you please give me an example to help me understand it? > > "Here's what you do. You write a function that contains a function. > The inner function is a template for the functions that you're writing > over and over again, but with variables in it for all the things that > vary from one case of the function to the next. The outer function > takes parameters that have the same names as those variables, and > returns the inner function. Then, every place where you'd otherwise be > writing yet another function, simply call the outer function, and > assign the return value to the name you want the "duplicated" function > to appear. Now, if you need to change how the pattern works, you only > have to change it in one place: the template." #untested off-the-cuff example: from time import time def add_timing(func): # takes a function as an argument """Wraps functions so they output their execution time when called""" def wrapper(*args, **kwargs): #defines a new function start = time() # thanks to closures, we can access func here result = func(*args, **kwargs) # have the new function call the given function end = time() duration = end-start print "Call to", func.__name__, "took", duration, "seconds" return result return wrapper # return the new function so that it can replace the function it calls def long_calculation(x, y, z): # some code long_calculation = add_timing(long_calculation) print long_calculation(1, 7, 42) #Example output: #Call to long_calculation took 135.5 seconds #99 Now imaging applying add_timing to multiple functions and note the amount of code you'd save and how the unrelated concerns of timing and mathematical calculation (or whatever the functions you apply add_timing() to do) would then be cleanly separated. The same technique can be applied to logging and other repetitive code to factor it out. It's sort of like aspect-oriented programming, but not as kludgey. Cheers, Chris -- http://blog.rebertia.com From threaderslash at gmail.com Wed Nov 18 22:51:27 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 19 Nov 2009 14:51:27 +1100 Subject: Qt Python radiobutton: activate event Message-ID: Hi Guys, I am trying to get the choice made by the user on Python Qt with radiobutton. QtCore.QObject.connect(self.radioButton1, QtCore.SIGNAL("toggled()"),self.radio_activateInput) QtCore.QObject.connect(self.radioButton2, QtCore.SIGNAL("toggled()"),self.radio_activateInput) and that QtCore.QObject.connect(self.performGroupBox, QtCore.SIGNAL("toggled()"),self.radio_activateInput) But it didn't make anything when I click on the option. Yes, I have enabled it: self.radioButton1.setCheckable(True) self.radioButton1.setChecked(True) self.radioButton2.setCheckable(True) Any suggestion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From highcar at gmail.com Wed Nov 18 23:18:28 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 20:18:28 -0800 (PST) Subject: mechanize login problem with website Message-ID: <26420202.post@talk.nabble.com> Hello I'm making auto-login script by use mechanize python. Before I was used mechanize with no problem, but http://www.gmarket.co.kr in this site I couldn't make it . whenever i try to login always login page was returned even with correct gmarket id , pass, i can't login and I saw some suspicious message "" I think this related with my problem, but don't know exactly how to handle . i was upload my script in here http://paste.pocoo.org/show/151607/ if anyone can help me much appreciate thanks in advance -- View this message in context: http://old.nabble.com/mechanize-login-problem-with-website-tp26420202p26420202.html Sent from the Python - python-list mailing list archive at Nabble.com. From azeynel1 at gmail.com Wed Nov 18 23:59:24 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 20:59:24 -0800 (PST) Subject: Beautifulsoup code that is not running References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> <7mimv4F3g0n2uU1@mid.individual.net> Message-ID: Yes, it shows as empty string. But I learned about Scrapy and now I am studying the tutorial. I like it better than BeautifulSoup. For beginners it is better, I think. On Nov 18, 11:50?am, Peter Pearson wrote: > On Tue, 17 Nov 2009 14:38:55 -0800 (PST), Zeynel wrote: > > [snip] > > >>>> from BeautifulSoup import BeautifulSoup > > >>>> soup = BeautifulSoup (file("test.html").read()) > >>>> title = soup.find('title') > >>>> titleString = title.string > >>>> open('extract.text', 'w').write(titleString) > > > This runs without an error, but nothing is written into the > > extract.text file. test.html has tags in it. > > Hmm. ?Works for me, but of course I don't have your test.html. > Why don't you try examining "title" and "titleString"? ?Perhaps > has resulted in titleString being the empty string. > > -- > To email me, substitute nowhere->spamcop, invalid->net. From azeynel1 at gmail.com Thu Nov 19 00:04:44 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 21:04:44 -0800 (PST) Subject: DeprecationWarning on md5 References: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Message-ID: <398bca0b-900c-4e8c-b6a0-b4a3af7c2c54@k17g2000yqh.googlegroups.com> Thanks. I tried the suppress it but no success. I need to read the documentation more carefully. But since this is not error, I will ignore them for now. On Nov 18, 9:12?pm, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > > Hello, > > > I am a newbie both in Scrapy and Python. When I create a project with > > Scrapy I get these errors: > > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > > DeprecationWarning: the sha module is deprecated; use the hashlib > > module instead import sha > > C:\Python26\lib\site-packages\twisted\spread\pb.py:30: > > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > import md5 > > C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: > > DeprecationWarning: the MimeWriter module is deprecated; use the email > > package instead > > > I found several references to this "bug" but I could not understand > > how to fix it. Can anyone help? > > This is a "bug" in the version of Twisted you're using. What Python is > saying is that Twisted is using some modules from the Python stdlib > that are deprecated and will be removed in some future version of > Python, thus Twisted will /eventually/ need to be changed to use the > newer replacement library. > However, this is only a warning, not an error; the code will run just > fine until you update to the eventual Python version that removed said > deprecated libraries (by which time a new Twisted version will > probably be available with the necessary fixes made). > > So, basically you can safely ignore the warnings, unless you want to > custom-patch your Twisted installation, which I wouldn't particularly > recommend. > It's also entirely possible your Twisted is outdated and a new version > fixed to avoid using the deprecated modules is already available. > > If you want to suppress the output of the warnings, see the docs for > the `warnings` module:http://docs.python.org/library/warnings.html > > Cheers, > Chris > --http://blog.rebertia.com From 54wutong at gmail.com Thu Nov 19 00:21:02 2009 From: 54wutong at gmail.com (Stephen.Wu) Date: Wed, 18 Nov 2009 21:21:02 -0800 (PST) Subject: is there any FIX message handle modules in Python? Message-ID: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> FIX message is the "Financial information Exchange" protocol messages... any 3rd libs we have? From wuwei23 at gmail.com Thu Nov 19 00:25:27 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 18 Nov 2009 21:25:27 -0800 (PST) Subject: is there any FIX message handle modules in Python? References: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> Message-ID: <591b3af9-3db7-4d3d-bf69-bdbd48bc51e4@h14g2000pri.googlegroups.com> On Nov 19, 3:21?pm, "Stephen.Wu" <54wut... at gmail.com> wrote: > FIX message is the "Financial information Exchange" protocol > messages... > any 3rd libs we have? You mean like this one that was the first result when I googled 'python "financial information exchange"'? http://www.quickfixengine.org/ From tjreedy at udel.edu Thu Nov 19 01:11:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Nov 2009 01:11:46 -0500 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <762634.99131.qm@web57906.mail.re3.yahoo.com> References: <762634.99131.qm@web57906.mail.re3.yahoo.com> Message-ID: hong zhang wrote: > >>> "cont_x --" doesn't work. So the above can't be the >> actual code. >> >> You never want to post the actual code you're >> running. That would make it too easy for people to help. > It is typo. To avoid typos, copy and paste, as has been suggested many times. From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:14:34 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:14:34 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2ca$0$964$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:14:47 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:14:47 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2d7$0$930$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:15:06 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:15:06 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2ea$0$963$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From d.dalton at iinet.net.au Thu Nov 19 02:10:32 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 19 Nov 2009 18:10:32 +1100 Subject: python and web pages Message-ID: <20091119071032.GA8462@debian-hp.lan> Hi, Here is my situation: I'm using the command line, as in, I'm not starting gnome or kde (I'm on linux.) I have a string of text attached to a variable,. So I need to use one of the browsers on linux, that run under the command line, eg. lynx, elinks, links, links2 and do the following. 1. Open a certain web page and find the first text box on the page, and put this text into the form. 2. Press the submit button, and wait for the result page to load. 3. Click on the 15th link down the page. So, how do I do this, can anyone point me to some docs or modules that may help out here? Thank you, -- Cheers, Dan http://members.iinet.net.au/~ddalton/ From andrethehunter at gmail.com Thu Nov 19 03:02:59 2009 From: andrethehunter at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 19 Nov 2009 00:02:59 -0800 (PST) Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The specified module could not be found." Message-ID: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> Hello, I'm trying to get Python 3.1 and cx_Oracle 5.02 (cx_Oracle-5.0.2-10g.win32-py3.0.msi) to connect to an Oracle 11.1.0.7.0 database via OraClient10g 10.2.0.3.0 with Pydev 1.5.1.1258496115 in Eclipse 20090920-1017 on Windows XP SP 3 v2002. The import cx_Oracle line appears as an unresolved import and when I run the application I get the following error to console: Traceback (most recent call last): File "FILEPATHHERE", line 1, in import cx_Oracle ImportError: DLL load failed: The specified module could not be found. Apparently the error is caused by cx_Oracle not being able to find the Oracle client DLLs (oci.dll and others). The client home path and the client home path bin directory are in the PATH System Variable and oci.dll is there. I tried getting the Oracle Instant Client (instantclient-basic- win32-11.1.0.7.0.zip from http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html) and installing it as directed. I added the instant client path to the PATH System Variable but that didn't work either. I have scoured the internet and have not found a solution. Please help! From greg.ewing at canterbury.ac.nz Thu Nov 19 03:03:23 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 19 Nov 2009 21:03:23 +1300 Subject: ANN: PyGUI 2.1.1 Message-ID: PyGUI 2.1.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This is an emergency bugfix release to repair some major breakage in the gtk version. Also corrects some other problems. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From simon.hibbs at gmail.com Thu Nov 19 03:08:02 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Thu, 19 Nov 2009 00:08:02 -0800 (PST) Subject: is there any FIX message handle modules in Python? References: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> <591b3af9-3db7-4d3d-bf69-bdbd48bc51e4@h14g2000pri.googlegroups.com> Message-ID: <8edb47fa-fbbe-405e-8939-41ae64b3f0b6@k4g2000yqb.googlegroups.com> On 19 Nov, 05:25, alex23 wrote: > On Nov 19, 3:21?pm, "Stephen.Wu" <54wut... at gmail.com> wrote: > > > FIX message is the "Financial information Exchange" protocol > > messages... > > any 3rd libs we have? > > You mean like this one that was the first result when I googled > 'python "financial information exchange"'? > > http://www.quickfixengine.org/ There are no prebuilt Python modules available based on quickfix, at least that I'm aware of. It has Python bindings available, but you have to complie it with them yourself from the C++ source. Simon Hibbs From sturlamolden at yahoo.no Thu Nov 19 03:11:45 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Nov 2009 00:11:45 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <00759512$0$8173$c3e8da3@news.astraweb.com> Message-ID: On 18 Nov, 20:19, Dave Cook wrote: > If it's an issue for your project, I suggest wxPython. ?It's > cross-platform, fairly complete, and extensible. ?But the API is > clunky compared to Qt. Not if we use wxFormBuilder 3.1. From greg.ewing at canterbury.ac.nz Thu Nov 19 03:20:34 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Nov 2009 21:20:34 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: <7mkdf2F3i7k16U1@mid.individual.net> Steven D'Aprano wrote: > I don't know what the state of the art on Mac is > these days, but in 1984s Macs had a standard keyboard layout that let you > enter most available characters via the keyboard, using sensible > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > the Option key and typing =. They all still seem to work -- presumably generating the appropriate unicode characters now instead of MacRoman. I don't think there's any left-arrow character available on the keyboard though, unfortunately. -- Greg From jebagnanadas at gmail.com Thu Nov 19 03:42:33 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Thu, 19 Nov 2009 14:12:33 +0530 Subject: Communication between python and wxWidgets.. Help needed... Message-ID: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> Hi Friends, I want to thank you all for doing a great job.. I seek your suggestions and valuable guidance regarding two things. 1) I'm using python 3.1.1 and wxWidgets for GUI development in my project .. I want to have a half-duplex communication between widgets and python(say passing something from wxWidgets to python and processing there and sending it back to display the results in widgets). When i googled around i found that we have to have SWIG or Boost::Python and some other third party applications to make this to work.. I'm wondering why it's really tough to establish a communication between the two though wxWidgets which is an excellent tool is mainly projected as a GUI toolkit especially for c++ and python and python is described as a powerful scripting language.. Can u suggest an efficient way by which i could make these two programs to interact(back and forth) easily?? 2) My second question is even if i did that successfully if i want to convert my project into an executable file how would i do that? (Bcoz. i will be having two executables or binaries in linux one for python and other for widgets) Do i need to convert it to lib or dll file with respect to python and c++ or is there any other way for making a build-script? What are the tools and libraries needed(like cx-freeze,pyWin32) to accomplish this?? Please give me some useful links... All of your suggestions are highly welcomed.. Thanks & Regards, Jebagnanadas A, Python-Developer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Nov 19 03:43:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:43:50 +0100 Subject: python and web pages In-Reply-To: References: Message-ID: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> Daniel Dalton schrieb: > Hi, > > Here is my situation: > I'm using the command line, as in, I'm not starting gnome or kde (I'm on > linux.) > I have a string of text attached to a variable,. So I need to use one of > the browsers on linux, that run under the command line, eg. lynx, > elinks, links, links2 and do the following. > 1. Open a certain web page and find the first text box on the page, and > put this text into the form. > 2. Press the submit button, and wait for the result page to load. > 3. Click on the 15th link down the page. > > So, how do I do this, can anyone point me to some docs or modules that > may help out here? Use the module "mechanize". It will mimic a browser, and allows you to navigate to pages, fill in forms & submit them. And with lxml or BeatifulSoup, you can extract the link you need to press, and then make mechanize visit it. Diez From deets at nospam.web.de Thu Nov 19 03:45:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:45:36 +0100 Subject: convert a string to a regex? In-Reply-To: References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> <4B04B79D.7090908@tim.thechases.com> Message-ID: <7mkethF3ijnhnU2@mid.uni-berlin.de> Peng Yu schrieb: > On Wed, Nov 18, 2009 at 9:12 PM, Tim Chase > wrote: >>> There are many special characters listed on >>> http://docs.python.org/library/re.html >>> >>> I'm wondering if there is a convenient function that can readily >>> convert a string with the special characters to its corresponding >>> regex. For example, >>> >>> "some.thing" => "some\.thing" >> Did you try bothering to *read* the page you linked to? >> >> There's a function for escaping strings right there... >> >> Literacy...a worthwhile skill to obtain. > > Sorry, I didn't see it. If there are examples besides explanations for > each command, it will help people see the usage of each command more > easily. Or it will clutter the whole page. That's not to say the docs can't be improved. But *reading* them will always be required. Diez From deets at nospam.web.de Thu Nov 19 03:48:03 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:48:03 +0100 Subject: hex In-Reply-To: References: Message-ID: <7mkf24F3ijnhnU3@mid.uni-berlin.de> hong zhang schrieb: > List, > > I want to input hex number instead of int number. in type="int" in following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? You can't. You can get a string, and convert that with e.g. int("FF", 16) Or you can extend optparse to know a new type, should be possible. That would have the advantage that the parser already knows about it & can reject faulty input. Diez From jocjo at mail.dk Thu Nov 19 03:50:44 2009 From: jocjo at mail.dk (Hans Larsen) Date: Thu, 19 Nov 2009 09:50:44 +0100 Subject: real numbers with infinity precission Message-ID: <4b0506e3$0$36574$edfadb0f@dtext01.news.tele.dk> I have a READ.me file for real.py, but where could I get that module? I use Python 3.+ I hope that sombody can help me mailto: jocjo at mail.dk From nyamatongwe+thunder at gmail.com Thu Nov 19 03:57:05 2009 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Thu, 19 Nov 2009 08:57:05 GMT Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The specified module could not be found." In-Reply-To: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> References: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> Message-ID: Andr?: > Apparently the error is caused by cx_Oracle not being able to find the > Oracle client DLLs (oci.dll and others). The client home path and the > client home path bin directory are in the PATH System Variable and > oci.dll is there. Open the cx_Oracle extension with Dependency Walker (http://www.dependencywalker.com/) to get a better idea about what the problem is in more detail. Neil From yuzhichang at gmail.com Thu Nov 19 04:11:22 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Thu, 19 Nov 2009 01:11:22 -0800 (PST) Subject: Where to find pexpect References: Message-ID: <1f57bf3e-d5b1-40da-8973-7b588a600b30@2g2000prl.googlegroups.com> On 10?13?, ??9?42?, Jean-Michel Pichavant wrote: > Antoon Pardon wrote: > > I have been looking forpexpect. The links I find like > >http://pexpect.sourceforge.netall end up at > >http://www.noah.org/wiki/Pexpectwhich produces a 404 not > > found problem. > > > Does someone know the current location? > > maybe they removed the distribution so you may use "subprocess" :o) > > JM http://pexpect.sourceforge.net seems outdated. I've forked, ported to Python 3.1, and added more features to pexpect. See http://github.com/yuzhichang/pexpect. From yuzhichang at gmail.com Thu Nov 19 04:14:21 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Thu, 19 Nov 2009 01:14:21 -0800 (PST) Subject: Is pexpect unmaintained now? References: <252facf7-f9c6-4c6a-9d7f-ac69a830e6f0@h14g2000pri.googlegroups.com> Message-ID: On 11?17?, ??11?40?, yuzhichang wrote: > Pexpect2.4 is only available at Pypi. Both the homepage ofpexpect(http://www.noah.org/wiki/Pexpect) and download page > (http://sourceforge.net/projects/pexpect/files/) are outdated. The > repository on Github (http://github.com/noahspurrier/pexpect/) has > been removed. > > I ever contacted the author(n... at noah.org) but no response till now. > > I'm going to forkpexpecton Github and add some features... I've forked, ported it to Python 3.1, and added some features. See http://github.com/yuzhichang/pexpect. Regards, Zhichang Yu From eden at bicikl. Thu Nov 19 04:32:55 2009 From: eden at bicikl. (Eden Kirin) Date: Thu, 19 Nov 2009 10:32:55 +0100 Subject: SCGIServer and unusal termination In-Reply-To: <7mg4stF3idnj9U2@mid.uni-berlin.de> References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> <7mg4stF3idnj9U2@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > - save a reference to sys.stdout *before* invoking the server > - compare to it after interruption. If it has changed, you at least know > that somebody messed with it, and can beat him or whatever you see fit. Thanks for the help. Finally, I dropped python-scgi module and I wrote my own SCGI server. There was not only the problem with stdout, but one much serious which made it unusable to me. Every SCGI request was forked as a new process, without the ability to access the shared globals within the project. -- www.vikendi.net -/- www.supergrupa.com From marco at sferacarta.com Thu Nov 19 04:44:52 2009 From: marco at sferacarta.com (Marco Mariani) Date: Thu, 19 Nov 2009 10:44:52 +0100 Subject: TODO and FIXME tags In-Reply-To: References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Message-ID: Jean-Michel Pichavant wrote: > I guess the world is split in two categories, those how come back to fix > the TODO, and those how don't. I for myself belong to the second, that > is why I never write TODO comments, I either do the stuff or consider > this is not important enough to waste time on it. In other words I > mostly agree with Martin, and envy people belonging to the first category. I am in a third category, I added this line to my python.vim syntax file syn keyword pythonTodo WTF LOL SNAFU contained and envy those who didn't :) From sturlamolden at yahoo.no Thu Nov 19 04:54:07 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Nov 2009 01:54:07 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> <4B047BBA.5040405@codebykevin.com> Message-ID: <55a576b4-857d-498f-b69f-ed2b7038a415@m16g2000yqc.googlegroups.com> On 18 Nov, 23:56, Kevin Walzer wrote: > wxWidgets (the C++ library) has support for a lot of things other than > UI bits, as well. wxPython itself is mainly a GUI library because the > additional features of wxWidgets in C++ are redundant in Python. That is true. Nobody uses wxPython for socket programming in Python. Qt is also much more than a C++ GUI framework, but in Python it's mainly (only?) used for GUI. From seeWebInstead at rem.intarweb.org Thu Nov 19 05:00:58 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Thu, 19 Nov 2009 02:00:58 -0800 Subject: Does turtle graphics have the wrong associations? References: Message-ID: > > Who is your target audience? > From: "Alf P. Steinbach" > Someone intelligent who doesn't know anything or very much about > programming and wants to learn general programming. I think of what a computer *does* as data processing, and then programing is simply telling the computer what data processing to do. In calculator mode, you just tell the computer one step at a time and immediately see the result before giving the next command. In program mode, you tell the computer the whole sequences of steps before the computer does even the first, which requires planning the whole sequence in your mind ahead of time. Lisp's REP allows you to use calculator mode when doing a dry run, then just wrap PROG around it and viola you have a program of all the steps together, thus bridging the gap between calculator and program mode painlessly. The two "hard" things about programming are syntax and planning. REP gets rid of the need to plan in your mind before writing the code, but you're still stuck with the syntax. My proposed no-syntax IDE *also* gets rid of the need to bother with any programming-language syntax. I've been proposing it for years, but nobody has shown any interest, so I'm spending my time on other things, but sometime in the next several months I am very likely to go ahead and implement no-syntax IDE as part of http://TinyURL.Com/NewEco. > I assume an intelligent reader, someone who doesn't balk at a few > technical terms here and there. There's a **major** difference between the ability to figure out complex puzzles and the ability to memorize jargon. Case in point: I placed top-five in Putnam math context despite disability whereby it was very difficult for me to memorize vocabulary/jargon. Then I flunked out of graduate school because suddenly I was expected to (but unable to) memorize ten definitions/lemmas to solve each homework problem. Ideally, with either somebody like me with memorization disability, or a very young child who just naturally by age has trouble learning more than one concept or term simultaneously, you should introduce only one concept or term at a time, and exerecise the person's mind with that concept or term for a while before moving to the next. > It's like the difference between driving a car and designing one. > You don't need an engineering degree to drive a car. :-) Sure some humans can be trained like pigeons to do the motions of driving a car through a fixed course without having the slightest concept of what's really happening. But to be able to respond appropriately to new situations, it really helps to understand that the brake pedal does *not* stop the car, it merely pulls a lever that presses a plate against a wheel causing excess friction causing the wheel to gradualy slow down, which is connected to the tires causing *them* to resist motion of car against road, which on non-slippery surfaces and with *gentle* braking results in the car slowing down, but with **sudden** pressure on brake, or on slick surfaces, the wheels stop turning completely and simply slide against the roadway, causing loss of control of both yaw and momentum, so suddenly your whole car is spinning about a vertical axis as well as no longer going around the road-curve but instead veering in a straight line across opposing traffic lanes or over the edge of the "S curve" of the Bay Bridge and then 200 feet down to a rather violent meeting with Yerba Buena Island. I hate that "CHECK ENGINE" light, because there's usually no way the driver of the vehicle actually *can* check the engine in any meaningful way to determine why the light is on. I think it really means "check" in the sense of a cloak-room, where you "check" your raincoat and umbrella by handing them to a clerk, thus you really do "check" your automobile by handing it over to a mechanic. By the way, I don't want Python running on my Macintosh, because it might eat my mouse. From __peter__ at web.de Thu Nov 19 05:01:24 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Nov 2009 11:01:24 +0100 Subject: hex References: Message-ID: hong zhang wrote: > I want to input hex number instead of int number. in type="int" in > following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", > default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? Workaround for the lazy: '0xff' on the command line instead of 'ff'. From looris at gmail.com Thu Nov 19 05:38:34 2009 From: looris at gmail.com (Lo'oris) Date: Thu, 19 Nov 2009 02:38:34 -0800 (PST) Subject: break LABEL vs. exceptions + PROPOSAL References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> Message-ID: On Nov 18, 7:13?pm, Terry Reedy wrote: > It amounts to duplicating raise x...exception x as break x....continue x > in the name of aesthetics and supposed efficiency. There would be no new > functionality nor any abbreviation of code. The semantics of there would be abbreviation: you wouldn't have to declare somewhere a dummy exception class. > anyplace'. The OP gives as a reason the possibility of a typo creating a > raise x ... except y mis-match. But a break x ... continue y mismatch is > equally likely. no: if you mismatch a label in this case, it should be treated as a syntax error, not as an unhandled exception which you might not notice. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 05:39:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 10:39:39 GMT Subject: real numbers with infinity precission References: <4b0506e3$0$36574$edfadb0f@dtext01.news.tele.dk> Message-ID: <03150e68$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 09:50:44 +0100, Hans Larsen wrote: > I have a READ.me file for real.py, but where could I get that module? I > use Python 3.+ > > I hope that sombody can help me Have you googled for "real.py"? -- Steven From tbourden at doc.ic.ac.uk Thu Nov 19 05:39:42 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Thu, 19 Nov 2009 10:39:42 +0000 Subject: non-copy slices In-Reply-To: <200911181900.17759.rami.chowdhury@gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> Message-ID: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> No I'm well aware that there is no deep copy of the objects and the lists only keep references to the objects and in essence they have the same objects in there. But this doesn't mean they are the same list. Modifications to slices are not written back to the original list. x = range(5) y = x[1:3] y[0] = 13 x[1] == y[0] --> False Of course if I modify the object in the slice then the original list will see the change, but this is not what I was saying. Second and more importantly it's the performance penalty from allocating a large number of lists produced from the slices and the copy of the references. islice does not have this penalty, it should only instantiate a small object that iterates on the original list. Themis On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury wrote: > > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.hibbs at gmail.com Thu Nov 19 05:50:32 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Thu, 19 Nov 2009 02:50:32 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> Message-ID: <40330c10-d52f-45f1-be40-b2a711cfa03b@d10g2000yqh.googlegroups.com> On 18 Nov, 22:11, Stef Mientki wrote: > Simon Hibbs wrote: > > On 18 Nov, 07:51, sturlamolden wrote: > > >> GPL > > > PyQT is GPL for now, but Qt itself is available under the LGPL as is > > PySide. Eventualy PySide, which tracks the PyQT API, will supplant it > > and the issue will be moot. For now it can be a problem, but PyQT > > developer licenses are very afordable at only a few hundred dollars. > > If a commercial project can't aford that, it's got problems. > > > Only you can know enough to make an informed decision. Wx does look > > more usable than last time I used it for a project and is a fine > > option too, for me though QT is the gold standard against all others > > are measured, and generaly found wanting. > > > Simon Hibbs > > Wouldn't it be nice > if each fan of some form of GUI-package, > would post it's code (and resulting images) for generating one or two > standard GUI-forms ? > > Then everyone can judge the differences, > and see what's simple and not ?so simple !! I don't think a list like this is a great way to do that. There are plenty of examples and tutorials available for each option. Simon Hibbs From ben+python at benfinney.id.au Thu Nov 19 06:38:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 22:38:18 +1100 Subject: Input characters not available on the keyboard (was: New syntax for blocks) References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> Message-ID: <87zl6iiw2d.fsf_-_@benfinney.id.au> Gregory Ewing writes: > Steven D'Aprano wrote: > > I don't know what the state of the art on Mac is these days, but in > > 1984s Macs had a standard keyboard layout that let you enter most > > available characters via the keyboard, using sensible mnemonics. > > E.g. on a US keyboard layout, you could get ? by holding down the > > Option key and typing =. [?] > I don't think there's any left-arrow character available on the > keyboard though, unfortunately. I'm glad to live in an age when free-software ?Input Methods? for many different character entry purposes are available in good operating systems. I switch between them using SCIM . At a pinch, when I'm without my GUI, I can turn some of them on with Emacs. Common input methods ? joy. I usually default to the ?rfc1345? input method which has many non-keyboard characters available via two-character mnemonics from the eponymous RFC document ? which appears to be about the only purpose that document has any more. -- \ ?The most dangerous man to any government is the man who is | `\ able to think things out for himself, without regard to the | _o__) prevailing superstitions and taboos.? ?Henry L. Mencken | Ben Finney From pavlovevidence at gmail.com Thu Nov 19 07:32:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Nov 2009 04:32:44 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> Message-ID: <02026493-a48f-4fa7-8f74-c5b1e2897be1@l2g2000yqd.googlegroups.com> On Nov 19, 12:20?am, Gregory Ewing wrote: > Steven D'Aprano wrote: > > I don't know what the state of the art on Mac is > > these days, but in 1984s Macs had a standard keyboard layout that let you > > enter most available characters via the keyboard, using sensible > > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > > the Option key and typing =. > > They all still seem to work -- presumably generating the > appropriate unicode characters now instead of MacRoman. ?It?s about time.? Carl Banks From ben+python at benfinney.id.au Thu Nov 19 07:44:22 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 23:44:22 +1100 Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> <02026493-a48f-4fa7-8f74-c5b1e2897be1@l2g2000yqd.googlegroups.com> Message-ID: <87ocmyit09.fsf@benfinney.id.au> Carl Banks writes: > On Nov 19, 12:20?am, Gregory Ewing > wrote: > > They all still seem to work -- presumably generating the appropriate > > unicode characters now instead of MacRoman. > > ?It?s about time.? I ? Unicode. (lrf, gung *vf* qryvorengr, sbe gur uhzbhe-vzcnverq nzbat lbh) -- \ ?Courteous and efficient self-service.? ?caf?, southern France | `\ | _o__) | Ben Finney From jeanmichel at sequans.com Thu Nov 19 07:58:01 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 19 Nov 2009 13:58:01 +0100 Subject: getting properly one subprocess output In-Reply-To: References: Message-ID: <4B0540D9.4060304@sequans.com> Nobody wrote: > On Wed, 18 Nov 2009 12:25:14 +0100, Jean-Michel Pichavant wrote: > > >> I'm currently inspecting my Linux process list, trying to parse it in >> order to get one particular process (and kill it). >> I ran into an annoying issue: >> The stdout display is somehow truncated (maybe a terminal length issue, >> I don't know), breaking my parsing. >> > > >> As you can see, to complete process command line is truncated. >> Any clue on how to get the full version ? >> > > If you only need it to work on Linux, you can just enumerate > /proc/[1-9]*/exe or /proc/[1-9]*/cmdline. > > Or you can add -ww to "ps" to avoid truncating the output. > > Note that the /proc/*/exe report the actual executable. The command line > reported by "ps" (from /proc/*/cmdline) can be modified by the program, so > it doesn't necessarily reflect the program being run. > > > That is what I was searching for. It's in ps man page, I don't know why I missed it in the first place. Thanks. JM From daniel at stutzbachenterprises.com Thu Nov 19 08:16:45 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 19 Nov 2009 07:16:45 -0600 Subject: non-copy slices In-Reply-To: <200911181900.17759.rami.chowdhury@gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> Message-ID: On Wed, Nov 18, 2009 at 9:00 PM, Rami Chowdhury wrote: > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > It still has to copy the reference, though. That takes O(n) time if you're taking a big slice. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas at geiregat.org Thu Nov 19 08:33:46 2009 From: jonas at geiregat.org (Jonas Geiregat) Date: Thu, 19 Nov 2009 14:33:46 +0100 Subject: Communication between python and wxWidgets.. Help needed... In-Reply-To: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> References: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> Message-ID: <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> Op 19-nov-09, om 09:42 heeft Jebagnana Das het volgende geschreven: > Hi Friends, > > I want to thank you all for doing a great job.. I > seek your suggestions and valuable guidance regarding two things. > > 1) I'm using python 3.1.1 and wxWidgets for GUI development in my > project .. I want to have a half-duplex communication between > widgets and python(say passing something from wxWidgets to python > and processing there and sending it back to display the results in > widgets). When i googled around i found that we have to have SWIG or > Boost::Python and some other third party applications to make this > to work.. I'm wondering why it's really tough to establish a > communication between the two though wxWidgets which is an excellent > tool is mainly projected as a GUI toolkit especially for c++ and > python and python is described as a powerful scripting language.. > Can u suggest an efficient way by which i could make these two > programs to interact(back and forth) easily?? > For your first question check out: wx.lib.pubsub: http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From wegwerp at gmail.com Thu Nov 19 09:21:09 2009 From: wegwerp at gmail.com (Bas) Date: Thu, 19 Nov 2009 06:21:09 -0800 (PST) Subject: getting properly one subprocess output References: Message-ID: On Nov 18, 12:25?pm, Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. Below is the script I use to automatically kill firefox if it is not behaving, maybe you are looking for something similar. HTH, Bas #!/usr/bin/env python import commands, os lines = os.popen('ps ax|grep firefox').readlines() lines = [line for line in lines if 'grep' not in line] print lines[0] pid = int(lines[0][:5]) print 'Found pid: %d' %pid os.system('kill -9 %d' %pid) From ethan at stoneleaf.us Thu Nov 19 09:44:19 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 Nov 2009 06:44:19 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> Message-ID: <4B0559C3.5020707@stoneleaf.us> Please don't top post. :) tbourden at doc.ic.ac.uk wrote: > On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury > > wrote: > > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > > No I'm well aware that there is no deep copy of the objects and the > lists only keep references to the objects and in essence they have the > same objects in there. But this doesn't mean they are the same list. > Modifications to slices are not written back to the original list. > > x = range(5) > y = x[1:3] > y[0] = 13 > x[1] == y[0] --> False > > Of course if I modify the object in the slice then the original list > will see the change, but this is not what I was saying. Second and more > importantly it's the performance penalty from allocating a large number > of lists produced from the slices and the copy of the references. islice > does not have this penalty, it should only instantiate a small object > that iterates on the original list. > > Themis So "shallow copy" == "new label created for existing object". So is your desired behavior to write back to the original list if your sub-list is modified? In other words, you are creating a window onto an existing list? If not, what would happen when a sublist element was modified (or deleted, or appended, or ...)? ~Ethan~ From victorsubervi at gmail.com Thu Nov 19 09:51:33 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 10:51:33 -0400 Subject: A Good Mailer In-Reply-To: <20091118223041.GA30691@stinemates.org> References: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> <20091118223041.GA30691@stinemates.org> Message-ID: <4dc0cfea0911190651g186ba8b7ta9c390e6a483234c@mail.gmail.com> On Wed, Nov 18, 2009 at 6:30 PM, Nick Stinemates wrote: > On Wed, Nov 18, 2009 at 03:27:11PM -0400, Victor Subervi wrote: > > Hi; > > I need a good mailer that will enable me to mail email from web forms. > > smtplib > > > Suggestions? > > silly example.. > > #!/usr/bin/env python > import smtplib > > session = smtplib.SMTP("localhost") > username = "abc" > password = "def" > session.login(username, password) # only if it requires auth > > subject = "Hello, " > > header = "Subject: %s \r\nContent-type: text/html; > charset=utf-8\r\n\r\n" > > message = "world!" > > email_from = "victor at is.awesome" > email_to = ["email at myhost.com"] > > session.sendmail(email_from, email_to, header+messages) > > HTH, > Helps a lot! Thanks! V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Thu Nov 19 10:21:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 19 Nov 2009 07:21:27 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> Message-ID: On Thu, 19 Nov 2009 02:39:42 -0800, wrote: > Second and more > importantly it's the performance penalty from allocating a large number > of > lists produced from the slices and the copy of the references. Ah, I see what you were getting at -- thanks for clarifying. > > On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury > wrote: > >> >> I'm not sure you're understanding the point others have been making. A >> list item is merely another reference to an existing object -- it >> doesn't copy the object in any way. >> >> -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Thu Nov 19 10:28:37 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 11:28:37 -0400 Subject: Python Will Not Send Email!! Message-ID: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Hi; I created this testMail.py file as root: #!/usr/bin/env python import smtplib session = smtplib.SMTP("localhost") subject = "Hello, " header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" message = "world!" email_from = "victor at is.awesome" email_to = ["email at myhost.com"] session.sendmail(email_from, email_to, header+messages) [root at 13gems globalsolutionsgroup.vi]# chmod 755 testMail.py [root at 13gems globalsolutionsgroup.vi]# python testMail.py Traceback (most recent call last): File "testMail.py", line 2, in ? import smtplib File "/usr/lib64/python2.4/smtplib.py", line 49, in ? from email.base64MIME import encode as encode_base64 ImportError: No module named base64MIME What gives?? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Thu Nov 19 10:29:34 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 11:29:34 -0400 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: <4dc0cfea0911190729p46fe1db8pf387242f8c284cff@mail.gmail.com> On Thu, Nov 19, 2009 at 11:28 AM, Victor Subervi wrote: > Hi; > I created this testMail.py file as root: > > #!/usr/bin/env python > import smtplib > session = smtplib.SMTP("localhost") > subject = "Hello, " > header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" > message = "world!" > email_from = "victor at is.awesome" > email_to = ["email at myhost.com"] > session.sendmail(email_from, email_to, header+messages) > > [root at 13gems globalsolutionsgroup.vi]# chmod 755 testMail.py > [root at 13gems globalsolutionsgroup.vi]# python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > > What gives?? > TIA, > Victor > PS Python 2.4 on CentOS -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Thu Nov 19 10:45:16 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 19 Nov 2009 16:45:16 +0100 Subject: SCGIServer and unusal termination References: Message-ID: > everything works just fine, but one thing bothers me. All prints after > try-except block are executed twice after the Ctrl+C is pressed! > > test.py: > #------------------------- > from scgi.scgi_server import SCGIServer > > n = 0 > print "Starting server." > > try: > SCGIServer().serve() > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > # print lines are executed twice (?!) > n += 1 > print "Terminating server, attempt %d." % n > n += 1 > print "Check n: %d." % n > #------------------------- SCGIServer().serve() forks, so it seems that there are 2 python processes continuing to run after SCGIServer().serve() -- ?????? ((( http://damjan.softver.org.mk/ ))) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From keith.hughitt at gmail.com Thu Nov 19 10:48:16 2009 From: keith.hughitt at gmail.com (Keith Hughitt) Date: Thu, 19 Nov 2009 07:48:16 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? References: <7mif6fF3hmd7eU1@mid.uni-berlin.de> Message-ID: <9c3a6286-b502-40ef-a94a-a471f327f887@j4g2000yqe.googlegroups.com> Hello, Thanks for the suggestions and information Diez! On Nov 18, 9:38?am, "Diez B. Roggisch" wrote: > > You are aware that the coding-declaration only affects unicode-literals (the > ones like u"i'm unicode")? So the above insert-statement is *not* unicode, > it's a byte-string in whatever encoding your editor happens to save the > file in. Thanks. I didn't know that, but that is helpful. > > And that's point two: make sure your editor reads and writes the file in the > same encoding you specified in the comment in the beginning. That is taken care of: the files are opened/saved as UTF-8. > > Makes sense if the execute tries to encode to unicode first - as you didn't > give it a unicode-object. > In Python 2.6 where I originally developed the code, it wasn't necessary to explicitly specify the type of some text: it was basically handled for you. It does make sense though. > > > > So far I've tried a number of different things, including: > > > ? ? 1. Using Unicode strings (e.g. u"\u212B") > > > ? ? 2. Manually specifying the encoding using sys.setdefaultencoding > > ('utf-8') > > > ? ? 3. Manually enabling Unicode support in MySQLdb > > (use_unicode=False, charset = "utf8") > > You *disabled* unicode here!!!!! Unicode is NOT utf-8!!! Oops. It was enabled when I ran it, I just copied the above text from somewhere else and forgot to change it. I am aware that Unicode does not equal utf-8, but utf-8 is a Unicode encoding, right? > > http://www.joelonsoftware.com/articles/Unicode.html Thanks! > > Try the above, and better yet provide self-contained examples that show the > behavior. > > Diez Still no luck. I also tried using double-quotes instead of single- quotes around the relevant strings (as suggested over email by ThreaderSlash), however, that did not work for me. Here is a small example of what I'm trying to do. Notice that if you run it in Python 2.5-2.6, everything works fine. It is only in Python 2.4 that the below example doesn't work. ============= Begin Example ================== #!/usr/bin/env python #-*- coding:utf-8 -*- import sys def main(): import MySQLdb, getpass admin = raw_input("Database admin: ") pw = getpass.getpass("Password: ") db = MySQLdb.connect(user=admin, passwd=pw) cursor = db.cursor() cursor.execute("CREATE DATABASE IF NOT EXISTS unicode_test;") cursor.execute(''' CREATE TABLE `unicode_test`.`test` ( `id` SMALLINT unsigned NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), INDEX (`id`) ) DEFAULT CHARSET=utf8;''') cursor.execute(''' INSERT INTO `unicode_test`.`test` VALUES (NULL, '?ngstr?m'); ''') # Test 1 print "Just printing: %s" % '?ngstr?m' # Test 2 cursor.execute("SELECT name FROM unicode_test.test;") print "From database: %s" % cursor.fetchone()[0].decode('utf-8') # Test 3 (Manual) print 'To verify manually: mysql -u %s -p -e "SELECT name FROM unicode_test.test"' % admin if __name__ == '__main__': sys.exit(main()) ============= End Example ==================== Any suggestions? Thanks! Keith From paul.nospam at rudin.co.uk Thu Nov 19 10:55:09 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 19 Nov 2009 15:55:09 +0000 Subject: getting properly one subprocess output References: Message-ID: <87ocmyecgy.fsf@rudin.co.uk> Jean-Michel Pichavant writes: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length > issue, I don't know), breaking my parsing. > > import subprocess > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > processList, stderrdata = process.communicate() > > Here is a sample of what I get in processList.split('\n'): > > ' "25487 1122 4344 ? 7-17:48:32 2.5 firefox-bin > /usr/lib/iceweasel/firefox-"', > ' "25492 1122 4892 pts/6 00:08 57.2 ipython > /usr/bin/python /usr/bin/ip"', > > > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? > You need to pass -ww to ps, otherwise it tries to guess the width of your terminal and adjust output line lengths accordingly. From gh at ghaering.de Thu Nov 19 11:19:14 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 19 Nov 2009 17:19:14 +0100 Subject: python and web pages In-Reply-To: <20091119071032.GA8462@debian-hp.lan> References: <20091119071032.GA8462@debian-hp.lan> Message-ID: Daniel Dalton wrote: > Hi, > > Here is my situation: > I'm using the command line, as in, I'm not starting gnome or kde (I'm on > linux.) > I have a string of text attached to a variable,. So I need to use one of > the browsers on linux, that run under the command line, eg. lynx, > elinks, links, links2 and do the following. No, you don't need any text mode browser. It's much easier to do with modules from the Python standard library. > 1. Open a certain web page and find the first text box on the page, and > put this text into the form. I assume you know HTML and HTTP. You can use urllib or urllib2 to submit the form. > 2. Press the submit button, and wait for the result page to load. > 3. Click on the 15th link down the page. You will then get the returned HTML from a function and you will have to parse it for the link you're interested in. There are many approaches to get there. Manual parsing, regular expressions or one of the XML parsers in the standard library (etree is the easiest). > So, how do I do this, can anyone point me to some docs or modules that > may help out here? While all of this may seem overwhelming at first, I guess the solution can be written in 20 - 30 lines of code. -- Gerhard From nagle at animats.com Thu Nov 19 11:22:09 2009 From: nagle at animats.com (John Nagle) Date: Thu, 19 Nov 2009 08:22:09 -0800 Subject: Does Python 3.x support Unicode-named attributes? Message-ID: <4b056e3b$0$1588$742ec2ed@news.sonic.net> Does Python 3.x support Unicode-named attributes? There are several modules which operate on HTML and try to hammer HTML/XML into Python object attributes. I've had BeautifulSoup and "urllib" blow up at various times when running on non-English HTML/XML. Got this error today: urllib.py:1197: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal res = map(safe_map.__getitem__, s) John Nagle From aahz at pythoncraft.com Thu Nov 19 11:22:22 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:22:22 -0800 Subject: Invitation to connect on LinkedIn References: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> Message-ID: In article , Chris Rebert wrote: > >How the heck someone sets their account email to a mailinglist, I'll >never figure out. This probably is not Jaime's fault. LinkedIn has an expletive b0rken implementation where they randomly pick addresses that have been used in your account when your primary address bounces. Still a bit odd that LinkedIn got that address in the first place, but I'm betting on them being at fault. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:25:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:25:20 -0800 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: In article , Terry Reedy wrote: > >Some usenet newsgroups were/are moderated either by a robot, a person, >or a team (as you suggested). But a particular newsgroup has to be set >up that way from the beginning. Last I knew, it wan/is? difficult to >convert an unmoderated group to moderation. It has gotten exponentially more difficult over the last decade. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:27:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:27:07 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: In article , Steve Ferg wrote: > >Does anybody know a language with this kind of syntax for >ifThenElseEndif? Several templating systems, including Cheetah. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:33:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:33:09 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: In article , Robert P. J. Day wrote: > >http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > > thoughts? Haven't seen this elsewhere in the thread: http://dalkescientific.com/writings/diary/archive/2009/11/15/100000_tasklets.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:35:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:35:28 -0800 Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: In article , Grant Edwards wrote: > >You've really got to try pretty hard to create one. But if you >want to, here's how to do it: > > 1) Start by complaining that your program doesn't work because > of a bug in Python. > > [...] Post of the month! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 jaraco at jaraco.com Thu Nov 19 11:37:35 2009 From: jaraco at jaraco.com (Jason R. Coombs) Date: Thu, 19 Nov 2009 08:37:35 -0800 (PST) Subject: Relative versus absolute paths on Windows Message-ID: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> The current implementation of Python (2.6.4, 3.1.1) treats \bar as a relative path but reports it as an absolute path. >>> ntpath.isabs('\\bar') True >>> ntpath.abspath('\\bar') 'C:\\bar' >>> os.chdir('d:\\') >>> ntpath.abspath('\\bar') 'd:\\bar' >>> os.chdir('\\\\server\\share') >>> ntpath.abspath('\\bar') '\\\\server\\share\\bar' In other words, paths without a drive letter are reported as absolute, but treated as relative, except in a few special cases. >>> ntpath.join('d:\\foo', '\\bar') '\\bar' In this case, \bar is treated as absolute, and not relative to d:\foo. This inconsistency means that to effectively resolve one path relative to another, one has to resort to explicit drive letter manipulation. See http://stackoverflow.com/questions/1654659/find-a-path-in-windows-relative-to-another for a case in point. My understanding is that in Windows, a path is only absolute if it contains a drive letter or it begins with a double-backslash. Curiously, the .Net Framework seems to be subject to the same limitation # using IronPython 2.6RC2 >>> System.IO.Path.IsPathRooted('\\bar') True >>> System.IO.Path.Combine('d:\\foo', '\\bar') # expect d:\bar '\\bar' The documentation for Combine raises this issue in the Community Content (http://msdn.microsoft.com/en-us/library/fyy7a5kt.aspx). Furthermore, the Windows API utility is also consistent with this odd behavior (http://msdn.microsoft.com/en-us/library/bb773660%28VS. 85%29.aspx). The discussion here (http://groups.google.com/group/comp.os.ms- windows.programmer.win32/browse_thread/thread/b2ff7a9d1d7c9b5e) describes absolute paths consistent with my understanding: Absolute paths have these characteristics. Length is at least 2 characters, AND ( Second character is ":", OR First two characters is "\\" ) And according to WikiPedia (http://en.wikipedia.org/wiki/Path_ %28computing%29), "[an] absolute path is a path that points to the same location on one file system regardless of the working directory." By this definition, \bar is a relative path on Windows. Ultimately, I don't care what the definition is. It seems to me, however, that Python should have a function that can resolve one path name relative to another, but due to these limitations, it does not. I should point out that os.path.relpath is not the solution either as the first parameter is always treated as relative to the current directory (more info at http://bugs.python.org/issue7195). I've built workarounds in https://svn.jaraco.com/jaraco/python/jaraco.windows/jaraco/windows/filesystem.py as join() and resolve_path(). I'm happy to continue using these workarounds, but I wanted to bring this issue to the attention of the community for any comments or suggestions or answers to the following questions. What is the benefit of treating \path as absolute? Should Python have built-in support for resolving one path relative to another (such as is jaraco.windows.filesystem.resolve_path does)? Given the long established behavior of Python and other platforms for handling absolute paths in Windows, is there a way forward that handles these cases more elegantly, or is the best approach to just mumble something nasty under our breath and work around these issues on a case-by-case basis? From nobody at nowhere.com Thu Nov 19 11:40:10 2009 From: nobody at nowhere.com (Nobody) Date: Thu, 19 Nov 2009 16:40:10 +0000 Subject: getting properly one subprocess output References: Message-ID: On Thu, 19 Nov 2009 06:21:09 -0800, Bas wrote: > Below is the script I use to automatically kill firefox if it is not > behaving, maybe you are looking for something similar. > lines = os.popen('ps ax|grep firefox').readlines() This isn't robust. It will kill any process with "firefox" anywhere in its command line, which isn't limited to processes which are actually running the firefox web browser. > lines = [line for line in lines if 'grep' not in line] This line excludes one such process, but there may be others. A more robust approach would be to check for the string in the command name (i.e. argv[0]) rather than the complete command-line, by using e.g. "ps ... -o pid,comm": lines = os.popen('ps axheo pid,comm').readlines() lines = [line.strip().split(' ', 1) for line in lines] lines = [(int(pid), cmd) for pid, cmd in lines if 'firefox' in cmd] Better still would be to check that "firefox" is a complete word, not part of one, e.g. with the regular expression r"\bfirefox\b". This would match "firefox", "/usr/bin/firefox", "firefox-bin", etc, but not e.g. "kill_firefox", e.g.: lines = [(int(pid), cmd) for pid, cmd in lines if re.search(r'\bfirefox\b', cmd)] That's about as good as you can get without using non-portable mechanisms such as /proc/*/exe. From eden at bicikl. Thu Nov 19 12:03:21 2009 From: eden at bicikl. (Eden Kirin) Date: Thu, 19 Nov 2009 18:03:21 +0100 Subject: SCGIServer and unusal termination In-Reply-To: References: Message-ID: ?????? ??????????? wrote: > SCGIServer().serve() forks, so it seems that there are 2 python > processes continuing to run after SCGIServer().serve() I noticed that which makes it unusable to me. Also, it took me almost whole day to realize this. I'm adopting a huge application to work with SCGI which shares a certain amount of data between working threads and SCGI handler. I couldn't realize the cause of erratic and unconsistent data behaviour. After diving into python-scgi code, I gave it up and wrote my own SCGI server. -- www.vikendi.net -/- www.supergrupa.com From carsten.haese at gmail.com Thu Nov 19 12:32:28 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Thu, 19 Nov 2009 12:32:28 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > I created this testMail.py file as root: > > #!/usr/bin/env python > import smtplib > session = smtplib.SMTP("localhost") > subject = "Hello, " > header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" > message = "world!" > email_from = "victor at is.awesome" > email_to = ["email at myhost.com "] > session.sendmail(email_from, email_to, header+messages) > > [root at 13gems globalsolutionsgroup.vi ]# > chmod 755 testMail.py > [root at 13gems globalsolutionsgroup.vi ]# > python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > > What gives?? Do you have a file called "email.py" in your current directory or anywhere else on Python's path outside of the standard library? If so, it's hiding the real email module from your script and you'll need to get rid of "your" email.py by renaming or moving it. -- Carsten Haese http://informixdb.sourceforge.net From t.bourdenas07 at imperial.ac.uk Thu Nov 19 12:55:26 2009 From: t.bourdenas07 at imperial.ac.uk (Themis Bourdenas) Date: Thu, 19 Nov 2009 17:55:26 +0000 Subject: non-copy slices In-Reply-To: <4B0559C3.5020707@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> Message-ID: <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> On Thu, Nov 19, 2009 at 2:44 PM, Ethan Furman wrote: > Please don't top post. :) > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? In other words, you are creating a window onto an > existing list? If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > Yes a window / view on the existing list describes it best. So every modification you make in this view is actually modifying the original list accordingly. Blist that was suggested in a previous email in the thread seems lightweight but it does create a new list when a modification is made. In any case, I've already implemented the object myself and I can post it if you care to have a look, but I was just wondering if there was already something in the standard library. Themis -------------- next part -------------- An HTML attachment was scrubbed... URL: From hippostech at gmail.com Thu Nov 19 13:53:00 2009 From: hippostech at gmail.com (papa hippo) Date: Thu, 19 Nov 2009 10:53:00 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released Message-ID: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> The prime goal of 'phileas' is to enable html code to be seamlessly included in python code in a natural looking syntax, without resorting to templatng language. see: http://larry.myerscough.nl/phileas_project/ I intend to submit phileas to the python.announce forum within the next few days. Any feedback received now will be gratefully received and may lead to improved quality of that submission. Larry Myerscough Eindhoven NL hippos at chello.nl From showell30 at yahoo.com Thu Nov 19 14:18:32 2009 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 19 Nov 2009 11:18:32 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> On Nov 19, 10:53?am, papa hippo wrote: > The prime goal of 'phileas' is to enable html code to be seamlessly > included in python code in a natural looking syntax, without resorting > to templatng language. > > see: > > http://larry.myerscough.nl/phileas_project/ > > I intend to submit phileas to the python.announce ?forum within the > next few days. Any feedback received now will be gratefully received > and may lead to improved quality of that submission. > Hi Larry, looks like interesting stuff! There appears to be a problem with this page: http://larry.myerscough.nl/show_python_source.py?script_filename=./MyPage.py IOError: [Errno 2] No such file or directory: './MyPage.py' I do like the idea of having a more Python-oriented way to generate HTML. From martin at v.loewis.de Thu Nov 19 15:21:48 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 19 Nov 2009 21:21:48 +0100 Subject: Does Python 3.x support Unicode-named attributes? In-Reply-To: <4b056e3b$0$1588$742ec2ed@news.sonic.net> References: <4b056e3b$0$1588$742ec2ed@news.sonic.net> Message-ID: <4b05a8dd$0$20089$9b622d9e@news.freenet.de> > Does Python 3.x support Unicode-named attributes? Most certainly, yes. All identifiers (and thus all attribute names) are Unicode strings in Python 3.x. > There are several modules which operate on HTML and try to > hammer HTML/XML into Python object attributes. I've had > BeautifulSoup and "urllib" blow up at various times when > running on non-English HTML/XML. > > Got this error today: > > urllib.py:1197: UnicodeWarning: Unicode equal comparison failed to > convert both arguments to Unicode - interpreting > them as being unequal > res = map(safe_map.__getitem__, s) Perhaps the library you were using modified __dict__ directly, thus getting non-string attribute names into the dict? Or perhaps s is not a Unicode string? Regards, Martin From alfps at start.no Thu Nov 19 15:37:17 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 19 Nov 2009 21:37:17 +0100 Subject: Is an interactive command a block? Message-ID: The CPython 3.1.1 language reference ?4.1 says "Each command typed interactively is a block." It also says "If a name is bound in a block, it is a local variable of that block, unless declared as nonlocal" Even with a non-literal try-for-best-meaning reading I can't get this to mesh with the actual behavior of the interpreter, e.g. >>> for x in "poi": ... fandango = 666 ... >>> fandango 666 >>> _ My current understanding is (A) that the interpreter is correct in this respect (for one would harldly want the effects of statements to be fundamentally different in interpreted mode, except the presentation of expression results), and (B), but here I'm less sure, that the documentation is incorrect. So what I'm asking about is mainly (B), because if the documentation is correct after all, then there's something I haven't grokked. :-) Cheers, - Alf From highcar at gmail.com Thu Nov 19 15:50:09 2009 From: highcar at gmail.com (elca) Date: Thu, 19 Nov 2009 12:50:09 -0800 (PST) Subject: mechanize login problem with website In-Reply-To: <26420202.post@talk.nabble.com> References: <26420202.post@talk.nabble.com> Message-ID: <26421474.post@talk.nabble.com> elca wrote: > > Hello > > I'm making auto-login script by use mechanize python. > > Before I was used mechanize with no problem, but http://www.gmarket.co.kr > in this site I couldn't make it . > > whenever i try to login always login page was returned even with correct > gmarket id , pass, i can't login and I saw some suspicious message > > "" > > I think this related with my problem, but don't know exactly how to handle > . > > i was upload my script in here > > # -*- coding: cp949 -*- > from lxml.html import parse, fromstring > import sys,os > import mechanize, urllib > import cookielib > import re > from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag > > try: > > params = urllib.urlencode({'command':'login', > 'url':'http%3A%2F%2Fwww.gmarket.co.kr%2F', > 'member_type':'mem', > 'member_yn':'Y', > 'login_id':'tgi177', > 'image1.x':'31', > 'image1.y':'26', > 'passwd':'tk1047', > 'buyer_nm':'', > 'buyer_tel_no1':'', > 'buyer_tel_no2':'', > 'buyer_tel_no3':'' > > }) > rq = mechanize.Request("http://www.gmarket.co.kr/challenge/login.asp") > rs = mechanize.urlopen(rq) > data = rs.read() > > > logged_in = r'input_login_check_value' in data > if logged_in: > print ' login success !' > rq = mechanize.Request("http://www.gmarket.co.kr") > rs = mechanize.urlopen(rq) > data = rs.read() > print data > > else: > print 'login failed!' > pass > quit() > except: > pass > > > if anyone can help me much appreciate thanks in advance > > i was updated my script source -- View this message in context: http://old.nabble.com/mechanize-login-problem-with-website-tp26420202p26421474.html Sent from the Python - python-list mailing list archive at Nabble.com. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:08:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:08:15 GMT Subject: Is an interactive command a block? References: Message-ID: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: > The CPython 3.1.1 language reference ?4.1 says > > "Each command typed interactively is a block." > > It also says > > "If a name is bound in a block, it is a local variable of that block, > unless > declared as nonlocal" > > Even with a non-literal try-for-best-meaning reading I can't get this to > mesh with the actual behavior of the interpreter, e.g. > > >>> for x in "poi": > ... fandango = 666 > ... > >>> fandango > 666 > >>> _ > > My current understanding is (A) that the interpreter is correct in this > respect (for one would harldly want the effects of statements to be > fundamentally different in interpreted mode, except the presentation of > expression results), and (B), but here I'm less sure, that the > documentation is incorrect. Why do you say that? I don't see what it is in the command you typed that leads you to think the documentation is incorrect. The first command you type is: for x in "poi": fandango = 666 which binds two names, x and fandango. Since you are not typing them in a function or class definition, locals() is globals() and the two local names you create happen to also be globals. The next two commands you type: fandango _ don't bind anything, so aren't relevant. If it helps: >>> for x in "poi": ... fandango = 666 ... >>> locals() is globals() True >>> fandango 666 >>> locals()['fandango'] 666 >>> import __main__ >>> __main__.fandango 666 -- Steven From davea at ieee.org Thu Nov 19 16:14:18 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 19 Nov 2009 16:14:18 -0500 Subject: Communication between python and wxWidgets.. Help needed... In-Reply-To: <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> References: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> Message-ID: <4B05B52A.6010308@ieee.org> Jonas Geiregat wrote: > > Op 19-nov-09, om 09:42 heeft Jebagnana Das het volgende geschreven: > >> Hi Friends, >> >> I want to thank you all for doing a great job.. I >> seek your suggestions and valuable guidance regarding two things. >> >> 1) I'm using python 3.1.1 and wxWidgets for GUI development in my >> project .. I want to have a half-duplex communication between widgets >> and python(say passing something from wxWidgets to python and >> processing there and sending it back to display the results in >> widgets). When i googled around i found that we have to have SWIG or >> Boost::Python and some other third party applications to make this to >> work.. I'm wondering why it's really tough to establish a >> communication between the two though wxWidgets which is an excellent >> tool is mainly projected as a GUI toolkit especially for c++ and >> python and python is described as a powerful scripting language.. Can >> u suggest an efficient way by which i could make these two programs >> to interact(back and forth) easily?? >> > > > For your first question check out: wx.lib.pubsub: > http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html > > I looked at your query a couple of times, and I don't see wxPython listed there anywhere. You don't need SWIG or Boost or anything else -- that's what wxPython is. Instead of just getting wxWidgets, get wxPython, which includes wxWidgets as a black box underneath. binaries here: http://wxpython.org/download.php#binaries dos here: http://www.wxpython.org/docs/api/wx-module.html Of course, the catch is that this whole project supports Python 2.4 through 2.6. If you want to get it to work on 3.1, you have to either wait, or do it yourself. DaveA From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:22:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:22:15 GMT Subject: What is the naming convention for accessor of a 'private' variable? References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <0315a502$0$1327$c3e8da3@news.astraweb.com> On Wed, 18 Nov 2009 18:47:34 -0800, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. >> ? ?"from M >> ? ? ?import *" does not import objects whose name starts with an >> ? ? ?underscore. > > If there's a method to access the variable, then it's not all that > private, is it? True, but it might be read-only, or the accessor might do validation to ensure that the caller doesn't stuff a string in something expected to be a float, or some sort of computed attribute. That's why we have properties. > Accessor methods are not Pythonic. Accessor methods are *usually* not Pythonic, at least not the way they are commonly used in Java. In fact, Python has at least two built-in accessor functions: globals() locals() There may be others. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:28:42 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:28:42 GMT Subject: Does turtle graphics have the wrong associations? References: Message-ID: <0315a685$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 02:00:58 -0800, Robert Maas, http://tinyurl.com/uh3t wrote: > My proposed no-syntax > IDE *also* gets rid of the need to bother with any programming-language > syntax. I've been proposing it for years, but nobody has shown any > interest I'm interested. No-syntax IDE? How is this even possible? The only way I can think of is some sort of wizard interface. E.g. instead of having to remember the syntax for a slice, you click the "Slice" button and the computer prompts you to enter some combination of start, end, step, then generates the syntax [a:b:c] for you. -- Steven From emile at fenx.com Thu Nov 19 16:38:00 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 19 Nov 2009 13:38:00 -0800 Subject: make two tables having same orders in both column and row names In-Reply-To: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> References: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Message-ID: On 11/18/2009 12:57 PM Ping-Hsun Hsieh said... > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 AA109 AA101 AA103 AA102 > BB1 2 9 2.3 1 28 > BB3 12 9 2.3 1 28 > BB9 0.5 2 2.3 1 28 > BB2 2 9 21 1 20 > > Table_B in the other file looks like the follows: > AA101 AA109 AA100 AA103 AA102 > BB1 2 9 2.3 2 28 > BB2 2 9 2.3 1 28 > BB9 2 9 2.3 1 28 > BB3 2 2 2 1 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun > This is one way... (python 2.4.1) #For example, table_A in a file looks like the follows: table_A = [ line.split() for line in """AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20""".split('\n') ] #Table_B in the other file looks like the follows: table_B = [ line.split() for line in """AA101 AA109 AA100 AA103 AA102 BB1 2 9 2.3 2 28 BB2 2 9 2.3 1 28 BB9 2 9 2.3 1 28 BB3 2 2 2 1 28""".split('\n') ] for table in table_A,table_B: table[:] = [['']+table[0]]+sorted(table[1:]) table = zip(*sorted(zip(*table))) for ii in table: print ii Emile From alfps at start.no Thu Nov 19 16:42:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 19 Nov 2009 22:42:31 +0100 Subject: Is an interactive command a block? In-Reply-To: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: > >> The CPython 3.1.1 language reference ?4.1 says >> >> "Each command typed interactively is a block." >> >> It also says >> >> "If a name is bound in a block, it is a local variable of that block, >> unless >> declared as nonlocal" >> >> Even with a non-literal try-for-best-meaning reading I can't get this to >> mesh with the actual behavior of the interpreter, e.g. >> >> >>> for x in "poi": >> ... fandango = 666 >> ... >> >>> fandango >> 666 >> >>> _ >> >> My current understanding is (A) that the interpreter is correct in this >> respect (for one would harldly want the effects of statements to be >> fundamentally different in interpreted mode, except the presentation of >> expression results), and (B), but here I'm less sure, that the >> documentation is incorrect. > > > Why do you say that? I don't see what it is in the command you typed that > leads you to think the documentation is incorrect. > > The first command you type is: > > for x in "poi": > fandango = 666 > > > which binds two names, x and fandango. Since you are not typing them in a > function or class definition, locals() is globals() and the two local > names you create happen to also be globals. Thanks, that may be it. In most other languages I'm familiar with, if a name is local then it isn't global (and vice versa), and I had that as an underlying assumption since it doesn't appear to be mentioned in the documentation. However, I find a language reference statement that alludes to this: "(The variables of the module code block are local and global.)" Hm... > The next two commands you type: > > fandango > _ > > don't bind anything, so aren't relevant. Well it showed that 'fandango' had been defined as a global. :-) > If it helps: > > >>>> for x in "poi": > ... fandango = 666 > ... >>>> locals() is globals() > True >>>> fandango > 666 >>>> locals()['fandango'] > 666 >>>> import __main__ >>>> __main__.fandango > 666 Yeah, helps. I feel that there's still something lacking in my understanding though, like how/where the "really actually just pure local not also global" is defined for function definition, but it's now just a vague feeling of something missing, not a feeling of direct contradiction as I had when I believed local != global. Cheers, & thanks, - Alf From threaderslash at gmail.com Thu Nov 19 17:00:36 2009 From: threaderslash at gmail.com (Threader Slash) Date: Fri, 20 Nov 2009 09:00:36 +1100 Subject: Python-list Digest, Vol 74, Issue 245 In-Reply-To: References: Message-ID: On Thu, Nov 19, 2009 at 7:05 PM, wrote: > > ---------- ---------- > From: Threader Slash > To: python-list at python.org > Date: Thu, 19 Nov 2009 14:51:27 +1100 > Subject: Qt Python radiobutton: activate event > Hi Guys, > > I am trying to get the choice made by the user on Python Qt with > radiobutton. > > QtCore.QObject.connect(self.radioButton1, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > QtCore.QObject.connect(self.radioButton2, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > > and that > > QtCore.QObject.connect(self.performGroupBox, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > > But it didn't make anything when I click on the option. > > Yes, I have enabled it: > > self.radioButton1.setCheckable(True) > self.radioButton1.setChecked(True) > self.radioButton2.setCheckable(True) > > Any suggestion? > > > ---------- Forwarded message ---------- > Here is solution... now working: QtCore.QObject.connect(self.radioButton1,QtCore.SIGNAL("toggled(bool)"),self.radio_activateInput) when have the parameter bool included into toggled to signal, it worked. ThreadeSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Thu Nov 19 17:00:45 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 19 Nov 2009 14:00:45 -0800 (PST) Subject: make two tables having same orders in both column and row names References: Message-ID: On Nov 18, 8:57?pm, Ping-Hsun Hsieh wrote: > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 ? AA109 ? AA101 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 12 ? ? ?9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 0.5 ? ? 2 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 21 ? ? ?1 ? ? ? 20 > > Table_B in the other file looks like the follows: > AA101 ? AA109 ? AA100 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 2 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 2 ? ? ? 2 ? ? ? 2 ? ? ? 1 ? ? ? 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun Use a dictionary with a tuple of the row 'name' and column 'name' as the key. The following was put together in a hurry, so take with a pinch of salt (and brandy or something :))... t1data = """AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20""" def create_table(what): from itertools import imap, islice, izip, cycle, repeat table = filter(None, imap(str.split, what.split('\n'))) table_dict = {} for cols in islice(table, 1, None): for row_name, col_name, col in izip(cycle(table[0]), repeat (cols[0]), islice(cols, 1, None)): table_dict[(row_name, col_name)] = col return table_dict print create_table(t1data) hth Jon. From kevin.p.dwyer at gmail.com Thu Nov 19 17:01:15 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Thu, 19 Nov 2009 22:01:15 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: Hello Victor, There are some pages on the internet that suggest that this problem my be caused by a module named email.py (or email.pyc) in your pythonpath. If you try import smtplib in the interpreter do you get this error message? If so, start a new interpreter session and try import email - is the email module imported from the stdlib? If these steps don't help, it might be useful if you can tell us which Linux distribution you are using. Cheers, Kev From sajmikins at gmail.com Thu Nov 19 17:48:11 2009 From: sajmikins at gmail.com (Simon Forman) Date: Thu, 19 Nov 2009 17:48:11 -0500 Subject: make two tables having same orders in both column and row names In-Reply-To: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> References: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Message-ID: <50f98a4c0911191448i44a3b6d7w8c78f8068b72f903@mail.gmail.com> On Wed, Nov 18, 2009 at 3:57 PM, Ping-Hsun Hsieh wrote: > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 ? AA109 ? AA101 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 12 ? ? ?9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 0.5 ? ? 2 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 21 ? ? ?1 ? ? ? 20 > > Table_B in the other file looks like the follows: > AA101 ? AA109 ? AA100 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 2 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 2 ? ? ? 2 ? ? ? 2 ? ? ? 1 ? ? ? 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun Depending on the kind of comparisons you want to do and the sizes of your input files you could build a dict of dicts. For example: def generate_dict_values(F): column_names = f.readline().split() for line in F: row = line.split() yield row[0], dict(zip(column_names, row[1:])) # Fake a file. from StringIO import StringIO f = StringIO('''\ AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20 ''') d = dict(generate_dict_values(f)) # Now you can access the values without regards to the order in the file like so: d['BB9']['AA109'] # "Pretty print" the dict of dicts. from pprint import pprint pprint(d) # Prints: # # {'BB1': {'AA100': '2', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '9'}, # 'BB2': {'AA100': '2', # 'AA101': '21', # 'AA102': '20', # 'AA103': '1', # 'AA109': '9'}, # 'BB3': {'AA100': '12', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '9'}, # 'BB9': {'AA100': '0.5', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '2'}} From reply-to at works.fine.invalid Thu Nov 19 18:15:05 2009 From: reply-to at works.fine.invalid (NickC) Date: 19 Nov 2009 23:15:05 GMT Subject: Vim breaks after Python upgrade References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: <008f55d8$0$26926$c3e8da3@news.astraweb.com> On Tue, 17 Nov 2009 13:46:25 -0500, Nick Stinemates wrote: > At least with Gentoo, there's a command to recompile all of the plugins > you have installed when upgrading python versions. > > Your issue is probably related to that. I don't think VIM uses hardcoded > locations for scripts at the core. > > If you have any specific questions about the errors you're receiving, > feel free to submit to the VIM mailing list or stop by the IRC channel: > #vim on irc.freenode.org > Ok, thanks. I'm sorry for calling vim clunky; the choice of words probably reflected my disbelief at the time. FWIW, sed'ing 's:2\.5:2\.6:g' doesn't work. It does change some strings, but not (apparently) the numbers that matter. -- NickC From jabronson at gmail.com Thu Nov 19 18:24:46 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 15:24:46 -0800 (PST) Subject: python bijection Message-ID: I couldn't find a library providing a bijective map data structure (allowing for constant-time lookups by value) in the few minutes I looked, so I took a few more minutes to code one up: http://bitbucket.org/jab/toys/src/tip/bijection.py Is this at all worth releasing? Comments and suggestions welcome. Josh From rhodri at wildebst.demon.co.uk Thu Nov 19 18:45:56 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 19 Nov 2009 23:45:56 -0000 Subject: hex In-Reply-To: <441732.63062.qm@web57901.mail.re3.yahoo.com> References: <441732.63062.qm@web57901.mail.re3.yahoo.com> Message-ID: On Thu, 19 Nov 2009 02:29:59 -0000, hong zhang wrote: > List, > > I want to input hex number instead of int number. in type="int" in > following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", > default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? Assuming you're talking about "optparse", just prefix the number with "0x" on the command line: python myscript.py -F 0xDEAD If you don't want to have to type the leading "0x", you'll either have to make yourself a custom type for optparse, or treat it as a string and do the parsing and error handling afterwards. My recommendation is that you don't do this: not prefixing your constants if they aren't decimal is an accident waiting to happen. -- Rhodri James *-* Wildebeest Herder to the Masses From david at boddie.org.uk Thu Nov 19 18:55:51 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 20 Nov 2009 00:55:51 +0100 Subject: PyQt4 4.4.4 : a bug with highlightBlock ? References: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Message-ID: On Wednesday 18 November 2009 11:47, Snouffy wrote: > I've been trying to do some syntax highlighting using PyQt4. I ported > the example given in the documentation of Qt4 to Python. It works fine > on my computer at work (which has PyQt4 version 4.3.3) but doesn't on > my home computer (which has version 4.4.4) : it gets stuck in an > infinite loop. This is a known issue. There are examples distributed with PyQt that should have been updated to use a slightly different approach. > Here is the code : > > class MyHighlighter(QtGui.QSyntaxHighlighter): > def __init__(self, edit): > QtGui.QSyntaxHighlighter.__init__(self,edit) > > def highlightBlock(self, text): > myClassFormat = QtGui.QTextCharFormat() > myClassFormat.setFontWeight(QtGui.QFont.Bold) > myClassFormat.setForeground(QtCore.Qt.darkMagenta) > pattern = "\\b[A-Z_]+\\b" > > expression = QtCore.QRegExp(pattern) > index = text.indexOf(expression); > while (index >= 0): > length = expression.matchedLength() > self.setFormat(index, length, myClassFormat) > index = text.indexOf(expression, index + length) You need to change the indexOf() calls to indexIn() calls on the QRegExp object: index = expression.indexIn(text, index + length) > What am I missing ? Is this a known bug of version 4.4.4 ? I think there was a behavioural change at some point that affected regular expression searching in QStrings. David From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 19:05:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 00:05:45 GMT Subject: python bijection References: Message-ID: <0315cb54$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 15:24:46 -0800, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up: > http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? You just did :) > Comments and suggestions welcome. If I want a mapping a <-> b, I generally just create a dict {a:b, b:a}. What is the advantages or disadvantages of your code over the simplicity of the dict approach? (That is, sell us on the features of your approach.) -- Steven From ethan at stoneleaf.us Thu Nov 19 19:08:36 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 Nov 2009 16:08:36 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> Message-ID: <4B05DE04.9080101@stoneleaf.us> Themis Bourdenas wrote: > On Thu, Nov 19, 2009 at 2:44 PM, Ethan Furman > wrote: > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? In other words, you are creating a window onto an > existing list? If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? > > ~Ethan~ > > Yes a window / view on the existing list describes it best. So every > modification you make in this view is actually modifying the original > list accordingly. Blist that was suggested in a previous email in the > thread seems lightweight but it does create a new list when a > modification is made. In any case, I've already implemented the object > myself and I can post it if you care to have a look, but I was just > wondering if there was already something in the standard library. > > Themis Unfortunately, I am not very familiar with the stdlib yet (gotta buy that book!). I'm going to guess 'No' since nobody has chimed in with a 'Yes', though. I'd love to see what you have for that. Does in support a stepped window, or only contiguous sequences? The one I put together this afternoon only does contiguous sequences, as I had no use cases to decide how assignments of multiple items should be handled, and not a lot of time to implement something generic -- so, to answer John's question from a completely different thread, yes I do enjoy working on small projects even if IAGNI. :) Cheers! ~Ethan~ From david at boddie.org.uk Thu Nov 19 19:33:05 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 20 Nov 2009 01:33:05 +0100 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> <40330c10-d52f-45f1-be40-b2a711cfa03b@d10g2000yqh.googlegroups.com> Message-ID: On Thursday 19 November 2009 11:50, Simon Hibbs wrote: > I don't think a list like this is a great way to do that. There are > plenty of examples and tutorials available for each option. This site has a selection of tutorials that can be used to compare API and code styles: http://zetcode.com/ David From jabronson at gmail.com Thu Nov 19 19:39:37 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 16:39:37 -0800 (PST) Subject: python bijection References: <0315cb54$0$1327$c3e8da3@news.astraweb.com> Message-ID: <55b3949d-2424-41ef-90fd-6e8184cbbcd7@o10g2000yqa.googlegroups.com> On Nov 19, 7:05?pm, Steven D'Aprano wrote: > If I want a mapping a <-> b, I generally just create a dict {a:b, b:a}. > What is the advantages or disadvantages of your code over the simplicity > of the dict approach? Well for one, you don't have to manually update the mapping from b -> a if ever the mapping from a -> b changes. With your method you have to write something like "d[a] = c; d[c] = a; del d[b]" instead of just "d[a] = c", "del d[d.pop(a)]" instead of just "del d[a]", etc. More significantly, your approach doesn't actually model a bijection since there's no distinction between keys (the domain) and values (the range). In other words, you lose information about which way is the forward mapping and which is the inverse mapping. Worse, d.keys() and d.values() would each give you the combination of your keys and values, neither of which would be right, and d.items() would also return twice as many elements as you expect with no way to distinguish which side of the mapping a given pair comes from. From magicus23REMOVE-THIS at gmail.com Thu Nov 19 21:01:26 2009 From: magicus23REMOVE-THIS at gmail.com (furlan) Date: Fri, 20 Nov 2009 02:01:26 +0000 (UTC) Subject: Whom Must We Worship References: <90a98e7d-daff-466a-9060-6a4a789d892c@k4g2000yqb.googlegroups.com> Message-ID: On Sun, 15 Nov 2009 00:17:43 -0800, Mary wrote: > Whom Must We Worship > The Decision is yours! Thank you, I got that. I choose Python. Thanks for sharing. ciao, f -- aa #2301 "...The word that separates that which is dead from that which is living....In the beginning was the word and that word was...CHOICE" -- Tom Robbins (SLWW) From pavlovevidence at gmail.com Thu Nov 19 21:17:36 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Nov 2009 18:17:36 -0800 (PST) Subject: python bijection References: Message-ID: On Nov 19, 3:24?pm, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? Comments and suggestions welcome. Apart from the GPL, it seems perfectly fine to release, and looks like an interesting strategy. I've wanted one of those once in a while, never enough to bother looking for one or writing one myself. But you should absolutely not inherit from dict if you're overriding all it's methods. It's useless and wasteful to do that, perhaps dangerous. You end up using bytes for a small hash table that's never used. Plus Python 3 has a notion of Abstract Base Classes: it will allow customization of isinstance to advertise that your class implements MutableMapping, which is the right way to do it. Carl Banks From ben+python at benfinney.id.au Thu Nov 19 21:36:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 20 Nov 2009 13:36:19 +1100 Subject: python bijection References: Message-ID: <87aayhgbx8.fsf@benfinney.id.au> Carl Banks writes: > On Nov 19, 3:24?pm, Joshua Bronson wrote: > > I couldn't find a library providing a bijective map data structure > > (allowing for constant-time lookups by value) in the few minutes I > > looked, so I took a few more minutes to code one > > up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > > > Is this at all worth releasing? Comments and suggestions welcome. > > Apart from the GPL, it seems perfectly fine to release, and looks like > an interesting strategy. I've wanted one of those once in a while, > never enough to bother looking for one or writing one myself. I would think GPL is an excellent choice for such a library then, if the author's intention is to encourage more software to be free software so that it can incorporate a unique library like this. -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From pengyu.ut at gmail.com Thu Nov 19 22:18:04 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 19 Nov 2009 21:18:04 -0600 Subject: Is there something similar to list comprehension in dict? Message-ID: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> I'm wondering if there is something similar to list comprehension for dict (please see the example code below). d = dict(one=1, two=2) print d def fun(d):#Is there a way similar to list comprehension to change the argument d so that d is changed? d=dict(three=3) fun(d) print d def fun1(d): d['one']=-1 fun1(d) print d L = [1, 2] print L def fun2(L):#this doesn't have any effect on the argument L L=[] fun2(L) print L#[1, 2] def fun3(L):# argument L is changed L[:]=[1, 2, 3] fun3(L) print L#[1, 2, 3] From jabronson at gmail.com Fri Nov 20 00:33:18 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 21:33:18 -0800 (PST) Subject: python bijection References: Message-ID: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> On Nov 19, 9:17 pm, Carl Banks wrote: > Apart from the GPL what Ben said :) > it seems perfectly fine to release, and looks like > an interesting strategy. I've wanted one of those once in a while, > never enough to bother looking for one or writing one myself. glad to hear it! i'll release it to pypi if such feedback continues. > But you should absolutely not inherit from dict if you're overriding > all it's methods. It's useless and wasteful to do that, perhaps > dangerous. You end up using bytes for a small hash table that's never > used. > > Plus Python 3 has a notion of Abstract Base Classes: it will allow > customization of isinstance to advertise that your class implements > MutableMapping, which is the right way to do it. Actually that's what I was originally thinking of doing but didn't go through with it in my first pass out of concern that users might want isinstance(bijection(), dict) to be True. Now that you bring it up, I agree that it's the correct way to do it, and have reimplemented bijection as a MutableMapping (ABCs are actually in Python 2.6). Take a peek at the new and improved http://bitbucket.org/jab/toys/src/tip/bijection.py if you get a chance and let me know how it looks! Anyone have any other feedback? For instance, is offering the __call__ syntax for the inverse mapping wonderful or terrible, or maybe both? Thanks, Josh From Scott.Daniels at Acm.Org Fri Nov 20 00:55:46 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Nov 2009 21:55:46 -0800 Subject: FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you In-Reply-To: References: Message-ID: Jonathan Fine wrote:... > A big thanks to Armin Ronacher and Raymond Hettinger for > PEP 372: Adding an ordered dictionary to collections > ... I prototyped (in about an hour). > > I then thought - maybe someone has been down this path before.... > > So all that I want has been done already, and will be waiting for me > when I move to Python3. > > So a big thank you is in order. And thank you for, having done that, not simply smiling because your work was lighter. Instead you described a great work path and handed an attaboy to a pair of people that richly deserve attaboys. --Scott David Daniels Scott.Daniels at Acm.Org From nagle at animats.com Fri Nov 20 01:52:10 2009 From: nagle at animats.com (John Nagle) Date: Thu, 19 Nov 2009 22:52:10 -0800 Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? In-Reply-To: References: Message-ID: <4b063a25$0$1668$742ec2ed@news.sonic.net> Keith Hughitt wrote: > Hi all, > > I ran into a problem recently when trying to add support for earlier > versions of Python (2.4 and 2.5) to some database related code which > uses MySQLdb, and was wondering if anyone has any suggestions. > > With later versions of Python (2.6), inserting Unicode is very simple, > e.g.: > > # -*- coding: utf-8 -*- > ... > cursor.execute('''INSERT INTO `table` VALUES (0, > '?ngstr?m'),...''') > > When the same code is run on earlier versions, however, the results is > either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or > an exception being thrown (Python 2.4): > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in > position 60: ordinal not in range(128) > > So far I've tried a number of different things, including: > > 1. Using Unicode strings (e.g. u"\u212B") > > 2. Manually specifying the encoding using sys.setdefaultencoding > ('utf-8') > > 3. Manually enabling Unicode support in MySQLdb > (use_unicode=False, charset = "utf8") No, that's backwards. Try: db = MySQLdb.connect(host="localhost", use_unicode = True, charset = "utf8", user=username, passwd=password, db=database) "use_unicode" means that you want MySQLdb to accept and return Unicode strings. "charset="utf8" means you want MySQLdb to negotiate with the server to use UTF8 on the socket connecting it to the database. This works fine in Python 2.4 and 2.5. Returned strings will be in Unicode. At the database end, you have to make sure that 1) MySQL was built with Unicode support (it usually is), 2) the database fields of interest are in Unicode. I suggest ALTER DATABASE dbname DEFAULT CHARACTER SET utf8; before doing any CREATE TABLE operations. Then strings will be UTF8 in the database. Read this: http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html It all works quite well. John Nagle From Scott.Daniels at Acm.Org Fri Nov 20 02:22:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Nov 2009 23:22:22 -0800 Subject: Writing a Carriage Return in Unicode In-Reply-To: References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: MRAB wrote: > u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a visible > "CR" graphic) for carriage return. Windows programs normally expect > lines to end with '\r\n'; just use u'\n' in programs and open the text > files in text mode ('r' or 'w'). This is the one thing from standards that I believe Microsoft got right where others did not. The ASCII (American Standard for Information Interchange) standard end of line is _both_ carriage return (\r) _and_ line feed (\n) -- I believe in that order. The Unix operating system, in its enthusiasm to make _everything_ simpler (against Einstein's advice, "Everything should be made as simple as possible, but not simpler.") decided that end-of-line should be a simple line feed and not carriage return line feed. Before they made that decision, there was debate about the order of cr-lf or lf-cr, or inventing a new EOL character ('\037' == '\x1F' was the candidate). If you've actually typed on a physical typewriter, you know that moving the carriage back is a distinct operation from rolling the platen forward; both operations are accomplished when you push the carriage back using the bar, but you know they are distinct. Hell, MIT even had "line starve" character that moved the cursor up (or rolled the platen back). Lots of people talk about "dos-mode files" and "windows files" as if Microsoft got it wrong; it did not -- Unix made up a convenient fiction and people went along with it. (And, yes, if Unix had been there first, their convention was, in fact, better). So, sorry for venting, but I have bee wanting to say this in public for years. --Scott David Daniels Scott.Daniels at Acm.Org From timr at probo.com Fri Nov 20 02:27:00 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Nov 2009 23:27:00 -0800 Subject: ANN: Urwid 0.9.9 - Console UI Library References: <4b04e2d7$0$930$ba4acef3@news.orange.fr> Message-ID: "Michel Claveau - MVP" wrote: > >Hi! > >You forget to write "urwid" do not run under Windows. He also forgot to write "urwid" do not run under CP/M or OS/360. Why did you feel compelled to post this three times? If it supported Windows, it would say so. The fact that it doesn't say so means it isn't supported. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan_ml at behnel.de Fri Nov 20 02:55:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 08:55:40 +0100 Subject: DOM related question and problem In-Reply-To: References: Message-ID: <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> elca, 18.11.2009 19:04: > these day im making python script related with DOM. > > problem is these day many website structure is very complicate . > [...] > what is best method to check can extract such like following info quickly? This should help: http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciated-web-scraping-library/ Stefan From stefan_ml at behnel.de Fri Nov 20 03:02:30 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:02:30 +0100 Subject: Python/HTML integration: phileas v0.3 released In-Reply-To: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> papa hippo, 19.11.2009 19:53: > The prime goal of 'phileas' is to enable html code to be seamlessly > included in python code in a natural looking syntax, without resorting > to templatng language. I assume you know XIST, ElementTree's ElementMaker, and all those other ways of generating XML/HTML from Python code in a natural looking way? Stefan From michele.simionato at gmail.com Fri Nov 20 03:19:43 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 20 Nov 2009 00:19:43 -0800 (PST) Subject: Is there something similar to list comprehension in dict? References: Message-ID: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> On Nov 20, 4:18?am, Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict Yes, but only in Python 3: >>> {(i, x) for i, x in enumerate('abc')} {(0, 'a'), (1, 'b'), (2, 'c')} From stefan_ml at behnel.de Fri Nov 20 03:24:31 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:24:31 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: References: Message-ID: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> Peng Yu, 20.11.2009 04:18: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). A list comprehension is an expression that produces a list, e.g. [ i**2 for i in range(10) ] Your example below uses a slice assignment. > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > d=dict(three=3) > [...] > def fun3(L):# argument L is changed > L[:]=[1, 2, 3] You can use d.update(...) It accepts both another dict as well as a generator expression that produces item tuples, e.g. d.update( (i, i**2) for i in range(10) ) Does that help? Stefan From stefan_ml at behnel.de Fri Nov 20 03:26:21 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:26:21 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b0652ad$0$7617$9b4e6d93@newsspool1.arcor-online.net> Stefan Behnel, 20.11.2009 09:24: > You can use d.update(...) > > It accepts both another dict as well as a generator expression that > produces item tuples, e.g. > > d.update( (i, i**2) for i in range(10) ) This also works, BTW: >>> d = {} >>> d.update(value=5) >>> d {'value': 5} Stefan From ajtkmr at gmail.com Fri Nov 20 04:17:28 2009 From: ajtkmr at gmail.com (Ajit Kumar) Date: Fri, 20 Nov 2009 14:47:28 +0530 Subject: non-copy slices In-Reply-To: <4B0559C3.5020707@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> Message-ID: <413d5b60911200117t5737f64dy83658728f996b010@mail.gmail.com> On Thu, Nov 19, 2009 at 8:14 PM, Ethan Furman wrote: >> No I'm well aware that there is no deep copy of the objects and the lists >> only keep references to the objects and in essence they have the same >> objects in there. But this doesn't mean they are the same list. >> Modifications to slices are not written back to the original list. >> >> x = range(5) >> y = x[1:3] >> y[0] = 13 >> x[1] == y[0] ?--> False >> >> Of course if I modify the object in the slice then the original list will >> see the change, but this is not what I was saying. Second and more >> importantly it's the performance penalty from allocating a large number of >> lists produced from the slices and the copy of the references. islice does >> not have this penalty, it should only instantiate a small object that >> iterates on the original list. >> >> Themis > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? ?In other words, you are creating a window onto an > existing list? ?If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? On a related note, GO encourages use of slices. http://golang.org/doc/effective_go.html#slices From patrick.just4fun at gmail.com Fri Nov 20 04:21:40 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Fri, 20 Nov 2009 10:21:40 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <4B065FA4.4050700@gmail.com> Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). Do you mean something like this: >>> {i:i+1 for i in [1,2,3,4]} {1: 2, 2: 3, 3: 4, 4: 5} This works in python3, but not in python2 - Patrick From paul.nospam at rudin.co.uk Fri Nov 20 04:29:47 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 20 Nov 2009 09:29:47 +0000 Subject: Is there something similar to list comprehension in dict? References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <87zl6hilx0.fsf@rudin.co.uk> Patrick Sabin writes: > Peng Yu wrote: >> I'm wondering if there is something similar to list comprehension for >> dict (please see the example code below). > > Do you mean something like this: > >>>> {i:i+1 for i in [1,2,3,4]} > {1: 2, 2: 3, 3: 4, 4: 5} > > This works in python3, but not in python2 Of course in python 2 you can do: >>> dict((i, i+1) for i in [1,2,3,4]) {1: 2, 2: 3, 3: 4, 4: 5} From tjreedy at udel.edu Fri Nov 20 04:32:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 04:32:03 -0500 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). Python 3 has list, set, and dict comprehensions. Don't know about 2.6/7 From mrkafk at gmail.com Fri Nov 20 05:10:18 2009 From: mrkafk at gmail.com (mk) Date: Fri, 20 Nov 2009 11:10:18 +0100 Subject: checking 'type' programmatically Message-ID: Disclaimer: this is for exploring and debugging only. Really. I can check type or __class__ in the interactive interpreter: Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) >>> p >>> (so, se) = p.communicate() >>> so 'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmultbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nworkspace\n' >>> se '' >>> so.__class__ >>> type(so) >>> type(se) But when I do smth like this in code that is ran non-interactively (as normal program): req.write('stderr type %s
    ' % type(se)) req.write('stderr class %s
    ' % str(se.__class__)) then I get empty output. WTF? How do I get the type or __class__ into some object that I can display? Why do that: e.g. if documentation is incomplete, e.g. documentation on Popen.communicate() says "communicate() returns a tuple (stdoutdata, stderrdata)" but doesn't say what is the class of stdoutdata and stderrdata (a file object to read? a string?). Regards, mk From robin at reportlab.com Fri Nov 20 05:12:26 2009 From: robin at reportlab.com (Robin Becker) Date: Fri, 20 Nov 2009 10:12:26 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B066B8A.9000103@chamonix.reportlab.co.uk> Aahz wrote: > In article , > Robert P. J. Day wrote: >> http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 >> >> thoughts? > > Haven't seen this elsewhere in the thread: > > http://dalkescientific.com/writings/diary/archive/2009/11/15/100000_tasklets.html I looked at this and it looks very good in that stackless appears twice as fast as go(lang) (I used to be in the department of computing at Imperial so I suppose I have to side with McCabe). Anyhow, my reading of why Pike was so proud of his set up and tear down of the tasks example was that these were real threads. Presumably that means they could potentially run in parallel on the 100000 cpu machines of the future. I'm not so clear on whether the threadless tasklets will run on separate cpus. -- Robin Becker From list at qtrac.plus.com Fri Nov 20 05:20:17 2009 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 20 Nov 2009 02:20:17 -0800 (PST) Subject: Book: Programming Python 3 (Second Edition) now available Message-ID: <27f9ed25-db38-40ef-8512-5708a3a04901@r5g2000yqb.googlegroups.com> Hi, I'm delighted to announce that a new edition of my Python 3 book is now available in the U.S. "Programming in Python 3 (Second Edition): A Complete Introduction to the Python Language" ISBN 0321680561 http://www.qtrac.eu/py3book.html The book has been fully revised and updated and now covers both Python 3.0 and 3.1, and with the language moratorium (PEP 3003), this second edition should be useful for many years to come. And in addition to the thorough updating, the book has been extended with new chapters on debugging, testing, and profiling, and on parsing (including coverage of the PyParsing and PLY modules), as well as a new section on coroutines in the advanced chapter. The book is aimed at a wide audience, but assumes some programming experience (not necessarily Python, not necessarily object-oriented). It teaches solid procedural style programming, then builds on that to teach solid object-oriented programming, and then goes on to more advanced topics (e.g., including a nice way to create validated attributes by combining class decorators with descriptors). But even newcomers to Python 3 should be able to write useful (although small and basic) programs after reading chapter 1, and then go on to create larger and more sophisticated programs as they work through the chapters. All the examples are available for download from the book's web site. From seeWebInstead at rem.intarweb.org Fri Nov 20 05:35:47 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Fri, 20 Nov 2009 02:35:47 -0800 Subject: Does turtle graphics have the wrong associations? References: <0315a685$0$1327$c3e8da3@news.astraweb.com> Message-ID: > > My proposed no-syntax > > IDE *also* gets rid of the need to bother with any programming-language > > syntax. I've been proposing it for years, but nobody has shown any > > interest > From: Steven D'Aprano > I'm interested. No-syntax IDE? How is this even possible? I guess you missed what I previously posted. The basic idea is that you start with test data, and you use menus to select appropriate data-processing actions to perform on that data. For example, you manually key in a file name containing test data, or copy and paste that same file name. Then you select "open file by that name" or "load all lines from file by that name" etc. from a menu. If you just opened the file, you now have a stream of input, and you can select to read one line or one s-expression or one character etc. from that file. After loading the whole file or one unit of data, you now have some *real* data to work from. For example, with a line of input, you might break it into words. Caveat: When I said "no syntax", I mean no programming syntax, no syntax to indicate function calls or variable assignment etc. You still must deal with visual representation of strings and integers and other essential data objects, which in a way may be considered to be syntax. But if you want, you can avoid *all* syntax, even for data, by drawing a *picture* of the individual bits. For some low-level machine-language training, or boolean algebra lessons, this might actually be preferable to Arabic numerals and English letters to represent data values. Seeing a *picture* of something that looks like a paper tape seems more binary-friendly than seeing arabic digits "0" and "1" in rows across a page, when studying operations upon boolean values or bitmasks. Now if you don't like the burden of navigating the multi-level menus, a search engine can be available, whereby you key in keywords for the name of some data-processing operation you either saw before or a name you can construct in your mind based on naming conventions. The extreme case of search engine would be if English-language pseudo-code can be automatically converted into a very short menu of most likely data-processing operations. I actually am seriously considering doing NewEco software development by this means. Basically I contract people to brainstorm with me in a Delphi fashion to create the toplevel design of a new computer algorithm, then we do top-down break into pieces, and continue top-down break-down as far as it takes until the search engine recognizes some step as something it already knows how to do. > The only way I can think of is some sort of wizard interface. > E.g. instead of having to remember the syntax for a slice, you > click the "Slice" button and the computer prompts you to enter > some combination of start, end, step, then generates the syntax > [a:b:c] for you. Yeah, it'll be vaguely like that in some ways. For major data, we'll have the data first, all parameters to the next function to apply, and *then* we select what function to call on those parameters. But for minor parameters, we might allow you to choose the function before filling in the minor-parameter slots. For example, to select the nth character of string, we might have both the string and the integer N before we select the NTH function, but if N is a constant we might instead have just the string and select the NTH function and fill in the constant N. With the pseudo-code translation, some of the constant parameters might be apparent in the English. For example, we have a string, and we say "select the second word" (actually that's almost HyperTalk, the scripting language of HyperCard on Macintosh computers), at which point the constant parameter 2 would be supplied from the word "second" in the English. From joost at h-labahn.de Fri Nov 20 05:51:10 2009 From: joost at h-labahn.de (DreiJane) Date: Fri, 20 Nov 2009 02:51:10 -0800 (PST) Subject: Announcement: depikt - the minimalistic python gate to gtk Message-ID: <11b6b3ac-e406-4550-b812-12dedb4a4e64@p35g2000yqh.googlegroups.com> Hi all, these days i make depikt, a python C-extension for building apps with gtk. It was a challenge for me and big fun. From its short description on sourceforge.net: "Python-3 wrappers for GTK. A minimalistic approach - just suited for GUI-building of apps, in no way for widget-building. Currently 1250 lines for 15 widgets with about 100 methods ... " depikt is advanced enough now to begin the transition of an 8MB python app of me to it - simultaneously with the transition to Python-3 and English. During this process depikt will grow to support for perhaps 25 widgets and 200 methods. From gobject it has connect(), connect_after(), handler_block(), handler_unblock() and handler_is_connected(). Still its status is marked as PreAlpha and depikt not entered to the Python wiki, because gtk_container_set_focus_chain() is defunct now - a vital method for fine usable applications. It's difficult to find out why - as it is the code was working for some time. depikt is very minimalistic: No python attributes of its classes, let alone properties No __repr__, no standard __init__ No support for set_property, get_property No real class hierarchy, there is one abstract base class Pikt, from which all concrete widgets are inheriting directly No exposing of Glib to python (but all i need from pango, cairo and gdk) Thus the code is very petty, well understandable and easy to extend to support for other widgets. That was the primary design goal, together with exact control of encoding issues, support for Python-3 and registry- and autoconf-free installation. Exception handling is about average now - there no mimimalism is intended, quite the contrary (for the long run). depikt will get to some mature state in 2010 - with perhaps about 3.000 lines then. One C-file will always be sufficient. atk might be added by means of a second file, also support for gtk.TreeView might get an own file - but both directly inserted by #include (no .h planned). Enjoy, Joost From fetchinson at googlemail.com Fri Nov 20 05:52:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 20 Nov 2009 11:52:19 +0100 Subject: Python/HTML integration: phileas v0.3 released In-Reply-To: <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> Message-ID: >> The prime goal of 'phileas' is to enable html code to be seamlessly >> included in python code in a natural looking syntax, without resorting >> to templatng language. >> >> see: >> >> http://larry.myerscough.nl/phileas_project/ >> >> I intend to submit phileas to the python.announce forum within the >> next few days. Any feedback received now will be gratefully received >> and may lead to improved quality of that submission. >> > > Hi Larry, looks like interesting stuff! > > There appears to be a problem with this page: > > http://larry.myerscough.nl/show_python_source.py?script_filename=./MyPage.py > > IOError: [Errno 2] No such file or directory: './MyPage.py' > > I do like the idea of having a more Python-oriented way to generate > HTML. Have you guys considered markup.py from http://markup.sourceforge.net/ ? It's comparable to your project as far as I can see, a more detailed comparison would probably be useful. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From joost at h-labahn.de Fri Nov 20 06:08:01 2009 From: joost at h-labahn.de (DreiJane) Date: Fri, 20 Nov 2009 03:08:01 -0800 (PST) Subject: Is there something similar to list comprehension in dict? References: Message-ID: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, two:2} ? Since you do not write L=list((1, 2)) either. These composed objects as basic building blocks make Python code so dense and beautiful, thus using "{}" means embracing the language's concept. From andreengels at gmail.com Fri Nov 20 06:41:10 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 20 Nov 2009 12:41:10 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <6faf39c90911200341u35ad9514m2a1f7f2e6a8712b6@mail.gmail.com> On Fri, Nov 20, 2009 at 4:18 AM, Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). > > > d = dict(one=1, two=2) > print d > > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > ?d=dict(three=3) > > fun(d) > print d > > def fun1(d): > ?d['one']=-1 > > fun1(d) > print d > > > L = [1, 2] > print L > > def fun2(L):#this doesn't have any effect on the argument L > ?L=[] > > fun2(L) > print L#[1, 2] > > def fun3(L):# argument L is changed > ?L[:]=[1, 2, 3] > > fun3(L) > print L#[1, 2, 3] > -- > http://mail.python.org/mailman/listinfo/python-list > def fun(d): d.clear() d[three] = 3 -- Andr? Engels, andreengels at gmail.com From davea at ieee.org Fri Nov 20 06:45:27 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 06:45:27 -0500 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <4B068157.3060003@ieee.org> Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). > > > d = dict(one=1, two=2) > print d > > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > d=dict(three=3) > > fun(d) > print d > > def fun1(d): > d['one']=-1 > > fun1(d) > print d > > > L = [1, 2] > print L > > def fun2(L):#this doesn't have any effect on the argument L > L=[] > > fun2(L) > print L#[1, 2] > > def fun3(L):# argument L is changed > L[:]=[1, 2, 3] > > fun3(L) > print L#[1, 2, 3] > > You confused me by calling it a list comprehension. All you're using in fun3() is a slice. Using a slice, you can give a new set of values to an existing list. For a dictionary, it's just a bit trickier. You need two steps in the most general case. def fun4(d): d.clear() #clear out existing entries d.update(new_dict) #copy in new key:val pairs from a different dictionary This function will modify the caller's dictionary, completely replacing the contents. DaveA From mail at timgolden.me.uk Fri Nov 20 06:47:26 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 Nov 2009 11:47:26 +0000 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> References: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> Message-ID: <4B0681CE.1050404@timgolden.me.uk> Michele Simionato wrote: > On Nov 20, 4:18 am, Peng Yu wrote: >> I'm wondering if there is something similar to list comprehension for >> dict > > Yes, but only in Python 3: > >>>> {(i, x) for i, x in enumerate('abc')} > {(0, 'a'), (1, 'b'), (2, 'c')} Although the 2.x syntax is hardly onerous: dict ((i+5, x) for i, x in enumerate ('abc')) -- obviously without something like the i+5, the example equates to dict (enumerate ('abc')) :) TJG From simon at brunningonline.net Fri Nov 20 07:00:53 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 20 Nov 2009 12:00:53 +0000 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> References: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> Message-ID: <8c7f10c60911200400j2d58c9a5y1bd84083ea8ee415@mail.gmail.com> 2009/11/20 Michele Simionato : > Yes, but only in Python 3: > >>>> {(i, x) for i, x in enumerate('abc')} > {(0, 'a'), (1, 'b'), (2, 'c')} In Python 2.x, you can do: >>> dict((i, x) for i, x in enumerate('abc')) {0: 'a', 1: 'b', 2: 'c'} (Works in 2.5 - I can't remember when generator expressions were introduced.) -- Cheers, Simon B. From mrkafk at gmail.com Fri Nov 20 07:03:04 2009 From: mrkafk at gmail.com (mk) Date: Fri, 20 Nov 2009 13:03:04 +0100 Subject: Regexp and multiple groups (with repeats) Message-ID: Hello, >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') >>> r.search(r'c:/tmp/spam/eggs').groups() ('/eggs',) Obviously, I would like to capture all groups: ('/tmp', '/spam', '/eggs') But it seems that re captures only the last group. Is there any way to capture all groups with repeat following it, i.e. (...)+ or (...)* ? Even better would be: ('tmp', 'spam', 'eggs') Yes, I know about re.split: >>> re.split( r'(?:\w:)?[/\\]', r'c:/tmp/spam\\eggs/' ) ['', 'tmp', 'spam', '', 'eggs', ''] My interest is more general in this case: how to capture many groups with a repeat? Regards, mk From hippostech at gmail.com Fri Nov 20 07:31:51 2009 From: hippostech at gmail.com (papa hippo) Date: Fri, 20 Nov 2009 04:31:51 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> Message-ID: <59a9e5da-d615-4820-821a-cc1f02e9db77@z41g2000yqz.googlegroups.com> On 19 nov, 20:18, Steve Howell wrote: > On Nov 19, 10:53?am, papa hippo wrote: > > > The prime goal of 'phileas' is to enable html code to be seamlessly > > included in python code in a natural looking syntax, without resorting > > to templatng language. > > > see: > > >http://larry.myerscough.nl/phileas_project/ > > > I intend to submit phileas to the python.announce ?forum within the > > next few days. Any feedback received now will be gratefully received > > and may lead to improved quality of that submission. > > Hi Larry, looks like interesting stuff! > > There appears to be a problem with this page: > > http://larry.myerscough.nl/show_python_source.py?script_filename=./My... > > IOError: [Errno 2] No such file or directory: './MyPage.py' > Oh dear! my blunder; While syncing (with meld) from my test environment to the live environment, I missed a file. It seems to be fixed now. > I do like the idea of having a more Python-oriented way to generate > HTML. That's good to hear. Larry From victorsubervi at gmail.com Fri Nov 20 07:58:55 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 07:58:55 -0500 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer wrote: > On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: > > Hello Victor, > > There are some pages on the internet that suggest that this problem my be > caused by a module named email.py (or email.pyc) in your pythonpath. If > you try import smtplib in the interpreter do you get this error message? > If so, start a new interpreter session and try import email - is the > email module imported from the stdlib? > Both of these import just fine. > > If these steps don't help, it might be useful if you can tell us which > Linux distribution you are using. > Python 2.4.3 [root at 13gems ~]# uname -a Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25 MSK 2009 x86_64 x86_64 x86_64 GNU/Linux CentOS 5.4 final TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Fri Nov 20 08:06:24 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 20 Nov 2009 08:06:24 -0500 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: > * Steven D'Aprano: >> >> On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: >> >>> The CPython 3.1.1 language reference ?4.1 says >>> >>> ? "Each command typed interactively is a block." >>> >>> It also says >>> >>> ? "If a name is bound in a block, it is a local variable of that block, >>> ? unless >>> ? ?declared as nonlocal" >>> >>> Even with a non-literal try-for-best-meaning reading I can't get this to >>> mesh with the actual behavior of the interpreter, e.g. >>> >>> ? >>> for x in "poi": >>> ? ... ? ?fandango = 666 >>> ? ... >>> ? >>> fandango >>> ? 666 >>> ? >>> _ >>> >>> My current understanding is (A) that the interpreter is correct in this >>> respect (for one would harldly want the effects of statements to be >>> fundamentally different in interpreted mode, except the presentation of >>> expression results), and (B), but here I'm less sure, that the >>> documentation is incorrect. >> >> >> Why do you say that? I don't see what it is in the command you typed that >> leads you to think the documentation is incorrect. >> >> The first command you type is: >> >> for x in "poi": >> ? ?fandango = 666 >> >> >> which binds two names, x and fandango. Since you are not typing them in a >> function or class definition, locals() is globals() and the two local names >> you create happen to also be globals. > > Thanks, that may be it. > > In most other languages I'm familiar with, if a name is local then it isn't > global (and vice versa), and I had that as an underlying assumption since it > doesn't appear to be mentioned in the documentation. > > However, I find a language reference statement that alludes to this: "(The > variables of the module code block are local and global.)" > > Hm... > > >> The next two commands you type: >> >> fandango >> _ >> >> don't bind anything, so aren't relevant. > > Well it showed that 'fandango' had been defined as a global. :-) > > >> If it helps: >> >> >>>>> for x in "poi": >> >> ... ? ? fandango = 666 >> ... >>>>> >>>>> locals() is globals() >> >> True >>>>> >>>>> fandango >> >> 666 >>>>> >>>>> locals()['fandango'] >> >> 666 >>>>> >>>>> import __main__ >>>>> __main__.fandango >> >> 666 > > Yeah, helps. > > I feel that there's still something lacking in my understanding though, like > how/where the "really actually just pure local not also global" is defined > for function definition, but it's now just a vague feeling of something > missing, not a feeling of direct contradiction as I had when I believed > local != global. > It's because the only blocks in python that have their own scope are classes and functions. For loops don't have their own scope- they use the enclosing one, which in this case is globals. > > Cheers, & thanks, > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > From hippostech at gmail.com Fri Nov 20 08:18:06 2009 From: hippostech at gmail.com (papa hippo) Date: Fri, 20 Nov 2009 05:18:06 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On 20 nov, 09:02, Stefan Behnel wrote: > papa hippo, 19.11.2009 19:53: > > > The prime goal of 'phileas' is to enable html code to be seamlessly > > included in python code in a natural looking syntax, without resorting > > to templatng language. > > I assume you know XIST, ElementTree's ElementMaker, and all those other > ways of generating XML/HTML from Python code in a natural looking way? > > Stefan Hi Stefan, Thanks for your feedback. Yes, I am aware that phileas might - on the basis of the short description on this post - come across like a 're-invented wheel'. There is, however, one big difference between phileas and all other other similar packages (XIST, ELementTree, HTMLgen, HyperText, pyhtmloo etc.) that I inspected: Phileas uses distinct objects to generate each start and end tag, whereas all the others use a single function call (in some cases itself generated by a function call) to generate a complete well- formed element including start-tag and (where required) end-tag. In theory this is less neat and indeed it means one can write 'bad' HTML (e.g. missing end of paragraphs) with phileas just as easily as when writing pure html. In practice, however, I find it at a lot easier to use. While using pyhtmloo (my previous favourite HTML generator), I had found myself using awkward complicated artificial constructions in order to generate all but the simplest HTML - and spent much time playing 'hunt the missing bracket'. With phileas, these complexities seem to just fall away. Put another way, Phileas generates HTML4.0 - warts and all; it is not a parser or generator of XML. I'm considering building in checks/warnings for unclosed elements etc., probably in the next-but-one pre-release. Larry From deets at nospam.web.de Fri Nov 20 09:03:35 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 15:03:35 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> References: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> Message-ID: <7mnltnF3iv96rU1@mid.uni-berlin.de> DreiJane schrieb: > NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, > two:2} ? Since you do not write L=list((1, 2)) either. These composed because it's not working. >>> {one : 1} Traceback (most recent call last): File "", line 1, in NameError: name 'one' is not defined Yes, that looks nitpicky, but that is exactly the reason one often prefers the dict(...)-variant. Because it uses python keywords, it spares you to type quotes around all the keys. Which IMHO is more aesthetic. > objects as basic building blocks make Python code so dense and > beautiful, thus using "{}" means embracing the language's concept. The collection-literals are a great thing, no doubt. But these alternatives are not against any concept. Diez From sturlamolden at yahoo.no Fri Nov 20 09:37:23 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 06:37:23 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: On 19 Nov, 01:14, Doug wrote: > Thanks for your help!! A carriage return in unicode is u"\r" how this is written as bytes is dependent on the encoder. Don't try to outsmart the UTF-8 codec, it knows how to translate "\r" to UTF-8. Sturla Molden From exarkun at twistedmatrix.com Fri Nov 20 10:01:28 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 20 Nov 2009 15:01:28 -0000 Subject: checking 'type' programmatically In-Reply-To: References: Message-ID: <20091120150128.27565.1834940229.divmod.xquotient.339@localhost.localdomain> On 10:10 am, mrkafk at gmail.com wrote: > >Disclaimer: this is for exploring and debugging only. Really. > >I can check type or __class__ in the interactive interpreter: > >Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) >[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> >p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) > >>> p > > >>> (so, se) = p.communicate() > >>> so >'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmultbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nworkspace\n' > >>> se >'' > >>> so.__class__ > > >>> type(so) > > >>> type(se) > > >But when I do smth like this in code that is ran non-interactively (as >normal program): > >req.write('stderr type %s
    ' % type(se)) >req.write('stderr class %s
    ' % str(se.__class__)) > >then I get empty output. WTF? > >How do I get the type or __class__ into some object that I can display? Hooray for HTML. You asked a browser to render "stderr type
    ". This isn't valid HTML, so pretty much any behavior goes. In this case, the browser seems to be discarding the entire - not too suprising, as it has some features in common with an html tag. Try properly quoting your output (perhaps by generating your html with a real html generation library). Jean-Paul From kevin.p.dwyer at gmail.com Fri Nov 20 10:05:38 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 20 Nov 2009 15:05:38 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: On Fri, 20 Nov 2009 07:58:55 -0500, Victor Subervi wrote: > On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > wrote: > >> On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: >> >> Hello Victor, >> >> There are some pages on the internet that suggest that this problem my >> be caused by a module named email.py (or email.pyc) in your pythonpath. >> If you try import smtplib in the interpreter do you get this error >> message? If so, start a new interpreter session and try import email - >> is the email module imported from the stdlib? >> >> > Both of these import just fine. > > >> If these steps don't help, it might be useful if you can tell us which >> Linux distribution you are using. >> >> > Python 2.4.3 > [root at 13gems ~]# uname -a > Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6 > 11:28:25 MSK 2009 x86_64 x86_64 x86_64 GNU/Linux CentOS 5.4 final > TIA, > V >
    On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > < href="mailto:kevin.p.dwyer at gmail.com">kevin.p.dwyer at gmail.com> > wrote:
    On Thu, 19 Nov 2009 > 11:28:37 -0400, Victor Subervi wrote:

    > Hello Victor,
    >
    > There are some pages on the internet that suggest that this problem my > be
    caused by a module named email.py (or email.pyc) in your > pythonpath. ?If
    you try import smtplib in the interpreter do you get > this error message?
    If so, start a new interpreter session and try > import email - is the
    email module imported from the > stdlib?

    Both of these import just > fine.?

    > If these steps don't help, it might be useful if you can tell us > which
    Linux distribution you are > using.

    Python > 2.4.3
    [root at 13gems ~]# uname -a
    Linux href="http://13gems.com.13gems.com">13gems.com.13gems.com > 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25 MSK 2009 x86_64 x86_64 > x86_64 GNU/Linux
    CentOS 5.4 > final
    TIA,
    V
    Hello Victor, I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as yours but also running python 2.4.3). It ran without error. So I suspect that either you have a rogue email module/package on your machine or there's something wrong with the python install. You could try: import email email.__version__ My interpreter responds "3.0.1" If you get a different response that suggests a dodgy module somewhere - try email.__file__ and see where it's located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc). If the version number is "3.0.1" on your machine then I would check the contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module is missing. Cheers, Kev From billy.earney at gmail.com Fri Nov 20 10:06:09 2009 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 20 Nov 2009 09:06:09 -0600 Subject: checking 'type' programmatically In-Reply-To: References: Message-ID: <4b06b063.e402be0a.68e8.5fe5@mx.google.com> Try looking at the function 'isinstance', so for example if isinstance(obj, str): print "object is a string.." elif isinstance(obj, int): print "object is an integer.." -----Original Message----- From: python-list-bounces+billy.earney=gmail.com at python.org [mailto:python-list-bounces+billy.earney=gmail.com at python.org] On Behalf Of mk Sent: Friday, November 20, 2009 4:10 AM To: python-list at python.org Subject: checking 'type' programmatically Disclaimer: this is for exploring and debugging only. Really. I can check type or __class__ in the interactive interpreter: Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE ) >>> p >>> (so, se) = p.communicate() >>> so 'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmul tbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nwork space\n' >>> se '' >>> so.__class__ >>> type(so) >>> type(se) But when I do smth like this in code that is ran non-interactively (as normal program): req.write('stderr type %s
    ' % type(se)) req.write('stderr class %s
    ' % str(se.__class__)) then I get empty output. WTF? How do I get the type or __class__ into some object that I can display? Why do that: e.g. if documentation is incomplete, e.g. documentation on Popen.communicate() says "communicate() returns a tuple (stdoutdata, stderrdata)" but doesn't say what is the class of stdoutdata and stderrdata (a file object to read? a string?). Regards, mk -- http://mail.python.org/mailman/listinfo/python-list From carsten.haese at gmail.com Fri Nov 20 10:14:01 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 10:14:01 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > wrote: > > On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: > > Hello Victor, > > There are some pages on the internet that suggest that this problem > my be > caused by a module named email.py (or email.pyc) in your pythonpath. If > you try import smtplib in the interpreter do you get this error message? > If so, start a new interpreter session and try import email - is the > email module imported from the stdlib? > > > Both of these import just fine. Kevin neglected to mention that the new interpreter session must be started in the same directory as the one you're in when you run your testMail.py script. Since he didn't mention that, we can't be sure that that's what you did, so this experiment doesn't prove anything. Please show us a copy-and-paste of your command line window contents that result from executing <> and then executing <> immediately thereafter. -- Carsten Haese http://informixdb.sourceforge.net From alfps at start.no Fri Nov 20 10:23:48 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 20 Nov 2009 16:23:48 +0100 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: * Benjamin Kaplan: > On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: >> * Steven D'Aprano: >> >> I feel that there's still something lacking in my understanding though, like >> how/where the "really actually just pure local not also global" is defined >> for function definition, but it's now just a vague feeling of something >> missing, not a feeling of direct contradiction as I had when I believed >> local != global. >> > > It's because the only blocks in python that have their own scope are > classes and functions. For loops don't have their own scope- they use > the enclosing one, which in this case is globals. Thanks, but hey, contradiction: you mention globals as an "enclosing" scope, i.e. that a module can have a scope, while stating that only classes and functions have their own scope (so, would a module have it's not own scope?). I think, having now read up and down and sideways in the docs, that the proper term in Python is "namespace", and that "scope" in Python refers to where the names in a namespace are directly accessible, with a special case for classes, namely that the scope of a class' namespace doesn't penetrate down into function definitions, hence problem with comprehensions expressed directly in a class definition. I believe that's a so called language "wart" -- which C++ is full of, just now discovering some of Python's :-). It's almost like C++'s "most vexing parse", a natural and apparently meaningful source code construct that due to the detailed rules turns out to be meaningless. I wish language designers could be a little less hooked on low level consistency. Because it makes for high level inconsistency, very difficult to explain without zillions of details. But anyways, it's starting to make more sense, yes. Cheers, - Alf From victorsubervi at gmail.com Fri Nov 20 10:45:15 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:45:15 -0400 Subject: Too Many Values To Unpack Message-ID: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Hi; At one point Dennis Lee Bieber helped me with the following slightly modified code: #!/usr/bin/python import sys,os sys.path.append(os.getcwd()) import MySQLdb from login import login import re, string def printTree(aTree, level=0): tree = [] for name in sorted(aTree.keys()): tree.append("%s%s") % ("\t" * level, name) printTree(aTree[name], level + 1) def expand(fetched): aDict = {} for (name, ) in fetched: aDict[name] = {} return aDict def getChildren(levelDict, level = 0): MAXLEVEL = 7 if level > MAXLEVEL: return #possibly the data has a cycle/loop for (nm, dt) in levelDict: cursor.execute('''select c.name from categories as c inner join relationship as r on c.ID = r.Child inner join categories as p on r.Parent = p.ID where p.category = %s order by c.name''', (nm,)) levelDict[nm] = expand(cursor.fetchall()) # recursive call to do next level getChildren(levelDict[nm], level + 1) # no data return as we are mutating dictionaries in place def catTree(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('''create table if not exists categories (ID int(3) unsigned primary key, Category varchar(40), Parent varchar(40))''') cursor.execute('select Category, Parent from categories;') data = cursor.fetchall() cursor.execute('select Category from categories order by Parent, ID') print data Categories = [itm[0] for itm in cursor] #untuple single column if len(Categories) > 0: cursor.execute('select Parent from categories order by Parent, ID') Parents = [itm[0] for itm in cursor] MAXLEVEL = 15 cursor.execute('''create table if not exists categories (ID integer auto_increment primary key, Name varchar(40) not null, unique (Name) )''') cursor.execute('''create table if not exists Relationship (ID integer auto_increment primary key, Parent integer not null, foreign key (Parent) references categories (ID), Child integer not null, foreign key (Child) references categories (ID), check (Parent <> Child) );''') # get top level print 'ok' cursor.execute('select category from categories order by category') theTree = expand(cursor.fetchall()) getChildren(theTree) connection.commit() return printTree(theTree) else: return ['There are no categories yet.'] catTree() This throws the error: [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] Traceback (most recent call last): [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/createCats.py", line 8, in ? [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] from catTree import catTree [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 77, in ? [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] catTree() [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 71, in catTree [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] getChildren(theTree) [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in getChildren [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] for (nm, dt) in levelDict: [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] ValueError: too many values to unpack There is only one category in "categories". Please advise. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Nov 20 10:49:17 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:49:17 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: <4dc0cfea0911200749n35f51909ie78f42c175a55162@mail.gmail.com> On Fri, Nov 20, 2009 at 11:05 AM, Kev Dwyer wrote: > I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as > yours but also running python 2.4.3). It ran without error. So I > suspect that either you have a rogue email module/package on your machine > or there's something wrong with the python install. > > You could try: > > import email > email.__version__ > > My interpreter responds "3.0.1" If you get a different response that > suggests a dodgy module somewhere - try email.__file__ and see where it's > located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc). > > If the version number is "3.0.1" on your machine then I would check the > contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module > is missing. > >>> import email >>> email.__version__ '3.0.1' >>> [root at 13gems cart]# ls /usr/lib64/python2.4/email/ base64MIME.py Encoders.pyo Generator.pyc Iterators.py MIMEAudio.pyo MIMEMessage.pyc MIMEText.py Parser.pyo base64MIME.pyc Errors.py Generator.pyo Iterators.pyc MIMEBase.py MIMEMessage.pyo MIMEText.pyc quopriMIME.py base64MIME.pyo Errors.pyc Header.py Iterators.pyo MIMEBase.pyc MIMEMultipart.py MIMEText.pyo quopriMIME.pyc Charset.py Errors.pyo Header.pyc Message.py MIMEBase.pyo MIMEMultipart.pyc _parseaddr.py quopriMIME.pyo Charset.pyc FeedParser.py Header.pyo Message.pyc MIMEImage.py MIMEMultipart.pyo _parseaddr.pyc test Charset.pyo FeedParser.pyc __init__.py Message.pyo MIMEImage.pyc MIMENonMultipart.py _parseaddr.pyo Utils.py Encoders.py FeedParser.pyo __init__.pyc MIMEAudio.py MIMEImage.pyo MIMENonMultipart.pyc Parser.py Utils.pyc Encoders.pyc Generator.py __init__.pyo MIMEAudio.pyc MIMEMessage.py MIMENonMultipart.pyo Parser.pyc Utils.pyo Any other ideas? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Nov 20 10:52:30 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 20 Nov 2009 15:52:30 GMT Subject: Regexp and multiple groups (with repeats) References: Message-ID: <7mns9uF3i7o34U1@mid.individual.net> On 2009-11-20, mk wrote: > Hello, > > >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') > > >>> r.search(r'c:/tmp/spam/eggs').groups() > ('/eggs',) > > Obviously, I would like to capture all groups: > ('/tmp', '/spam', '/eggs') You'll have to do something else, for example: >>> s = re.compile(r'(?:[a-zA-Z]:)') >>> n = re.compile(r'[\\/]\w+') >>> m = s.match('c:/tmp/spam/eggs') >>> n.findall(m.string[m.end():]) ['/tmp', '/spam', '/eggs'] -- Neil Cerutti From victorsubervi at gmail.com Fri Nov 20 10:58:00 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:58:00 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese wrote: > Kevin neglected to mention that the new interpreter session must be > started in the same directory as the one you're in when you run your > testMail.py script. Since he didn't mention that, we can't be sure that > that's what you did, so this experiment doesn't prove anything. > > Please show us a copy-and-paste of your command line window contents > that result from executing <> and then executing > <> immediately thereafter. > [root at 13gems globalsolutionsgroup.vi]# python testMail.py Traceback (most recent call last): File "testMail.py", line 2, in ? import smtplib File "/usr/lib64/python2.4/smtplib.py", line 49, in ? from email.base64MIME import encode as encode_base64 ImportError: No module named base64MIME [root at 13gems globalsolutionsgroup.vi]# python -c "import email; print email" TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Nov 20 11:02:38 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 08:02:38 -0800 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: <4B06BD9E.80303@stoneleaf.us> Alf P. Steinbach wrote: > * Benjamin Kaplan: >> On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: >>> >>> I feel that there's still something lacking in my understanding >>> though, like >>> how/where the "really actually just pure local not also global" is >>> defined >>> for function definition, but it's now just a vague feeling of something >>> missing, not a feeling of direct contradiction as I had when I believed >>> local != global. >>> >> >> It's because the only blocks in python that have their own scope are >> classes and functions. For loops don't have their own scope- they use >> the enclosing one, which in this case is globals. > > > Thanks, but hey, contradiction: you mention globals as an "enclosing" > scope, i.e. that a module can have a scope, while stating that only > classes and functions have their own scope (so, would a module have it's > not own scope?). module scope == global scope That is, there is nothing higher than module scope. (So, yes, global is a slight misnomer... in Python it means 'global to a module'.) ~Ethan~ From metolone+gmane at gmail.com Fri Nov 20 11:03:51 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 20 Nov 2009 08:03:51 -0800 Subject: Regexp and multiple groups (with repeats) References: Message-ID: "mk" wrote in message news:he60ha$ivv$1 at ger.gmane.org... > Hello, > > >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') > > >>> r.search(r'c:/tmp/spam/eggs').groups() > ('/eggs',) > > Obviously, I would like to capture all groups: > ('/tmp', '/spam', '/eggs') > > But it seems that re captures only the last group. Is there any way to > capture all groups with repeat following it, i.e. (...)+ or (...)* ? > > Even better would be: > > ('tmp', 'spam', 'eggs') > > Yes, I know about re.split: > > >>> re.split( r'(?:\w:)?[/\\]', r'c:/tmp/spam\\eggs/' ) > ['', 'tmp', 'spam', '', 'eggs', ''] > > My interest is more general in this case: how to capture many groups with > a repeat? re.findall is what you're looking for. Here's all words not followed by a colon: >>> import re >>> re.findall(u'(\w+)(?!:)',r'c:\tmp\spam/eggs') ['tmp', 'spam', 'eggs'] -Mark From sturlamolden at yahoo.no Fri Nov 20 11:11:12 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 08:11:12 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <764c524e-9b1e-4e88-9ec4-806f8416d90d@b2g2000yqi.googlegroups.com> On 18 Nov, 22:18, David Bolen wrote: > With that said, for various reasons I still prefer wxPython to Qt, and > at the moment, find wxFormBuilder the best fit for my own designs > (even before the direct Python support, just using XRC). Personally I prefer wxFormBuilder over QtDesigner for sizer-based designs. For quickly creating mock-up designs (GUI or web) there is a Windows program called "DesignerVista". From eric.frederich at gmail.com Fri Nov 20 11:14:23 2009 From: eric.frederich at gmail.com (eric.frederich) Date: Fri, 20 Nov 2009 08:14:23 -0800 (PST) Subject: Split class across multiple files Message-ID: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> I have a class which holds a connection to a server and a bunch of services. In this class I have methods that need to work with that connection and services. Right now there are about 50 methods some of which can be quite long. >From an organizational standpoint, I'd like to have method implementations in their own files. Is this possible? It is recommended? Should I just stop worrying about it and have a 5,000 line class? From shashank.sunny.singh at gmail.com Fri Nov 20 11:14:44 2009 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Fri, 20 Nov 2009 21:44:44 +0530 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Message-ID: <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> On Fri, Nov 20, 2009 at 9:15 PM, Victor Subervi wrote: > Hi; > At one point Dennis Lee Bieber helped me with the following slightly > modified code: > > #!/usr/bin/python > > import sys,os > sys.path.append(os.getcwd()) > import MySQLdb > from login import login > import re, string > > def printTree(aTree, level=0): > tree = [] > for name in sorted(aTree.keys()): > tree.append("%s%s") % ("\t" * level, name) > printTree(aTree[name], level + 1) > > def expand(fetched): > aDict = {} > for (name, ) in fetched: > aDict[name] = {} > return aDict > def getChildren(levelDict, level = 0): > MAXLEVEL = 7 > if level > MAXLEVEL: > return #possibly the data has a cycle/loop > for (nm, dt) in levelDict: > Are you sure your key values are 2-tuples in levelDict? For-each on dicts enumerates the keys AFAIK -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Nov 20 11:15:49 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 12:15:49 -0400 Subject: Serve Pages Under Different Ownership Message-ID: <4dc0cfea0911200815x54f910abv41323cb2ecbc512b@mail.gmail.com> Hi; I'm building a new server after many years hiatus. I currently can only serve python pages chown'd to root. How do I change this? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Fri Nov 20 11:15:55 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 11:15:55 -0500 Subject: semantics of [:] Message-ID: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) ############# 1 ################## b = a[:] # b receives a copy of a, but they are independent # The following two are equivalent ############# 2 ################## c = [] c = a[:] # c receives a copy of a, but they are independent ############# 3 ################## d = [] d[:] = a # d receives a copy of a, but they are independent ### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ## do. Am I correct with this? Thanks. From deets at nospam.web.de Fri Nov 20 11:21:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:21:49 +0100 Subject: semantics of [:] In-Reply-To: References: Message-ID: <7mnu0tF3itudnU1@mid.uni-berlin.de> Esmail schrieb: > Could someone help confirm/clarify the semantics of the [:] operator > in Python? > > a = range(51,55) > > ############# 1 ################## > b = a[:] # b receives a copy of a, but they are independent > > > > # The following two are equivalent > ############# 2 ################## > c = [] > c = a[:] # c receives a copy of a, but they are independent No, the both above are equivalent. Both just bind a name (b or c) to a list. This list is in both cases a shallow copy of a. > > > ############# 3 ################## > d = [] > d[:] = a # d receives a copy of a, but they are independent This is a totally different beast. It modifies d in place, no rebinding a name. So whover had a refernce to d before, now has a changed object, whereas in the two cases above, the original lists aren't touched. Of course, in your concrete example, the looks of it are the same. The distinction is crucial in larger contexts. Diez From deets at nospam.web.de Fri Nov 20 11:31:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:31:27 +0100 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <7mnuivF3ih0p9U1@mid.uni-berlin.de> eric.frederich schrieb: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? It is recommended? Should I just stop worrying > about it and have a 5,000 line class? It is pretty easy to do, as python allows multiple inheritance. Just group together methods into a class, and create one that inherits from all. However, I'd say something that even splitted up is essentially one class with 5000 lines cries for a huge refactoring. Of course this depends on the use-case, but I for once don't have a single such beast. Looks like a god-object to me... http://en.wikipedia.org/wiki/God_object Diez From carsten.haese at gmail.com Fri Nov 20 11:32:32 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 11:32:32 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > At one point Dennis Lee Bieber helped me with the following slightly > modified code: > > [snippage...] > > def getChildren(levelDict, level = 0): > MAXLEVEL = 7 > if level > MAXLEVEL: > return #possibly the data has a cycle/loop > for (nm, dt) in levelDict: > cursor.execute('''select c.name from categories as c > inner join relationship as r > on c.ID = r.Child > inner join categories as p > on r.Parent = p.ID > where p.category = %s > order by c.name ''', (nm,)) > levelDict[nm] = expand(cursor.fetchall()) > # recursive call to do next level > getChildren(levelDict[nm], level + 1) > # no data return as we are mutating dictionaries in place > > [snippage...] > > [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] for (nm, > dt) in levelDict: > [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] ValueError: > too many values to unpack Iterating over a dictionary, such as what you're doing in the line <>, only produces the keys that are in the dictionary. This means that this line only works if the keys in levelDict are pairs of "nm"s and "dt"s, whatever "nm" and "dt" represent. (In case the foregoing is too subtle a clue: Choose better variable names.) However, the line <> indicates that the keys in levelDict are only "nm"s, which are presumably single objects, not pairs. Also, the "dt" that you're trying to unpack from levelDict's keys is not used anywhere in your function. So, this would indicate that changing the offending line to <> should fix this particular error. HTH, -- Carsten Haese http://informixdb.sourceforge.net From pavlovevidence at gmail.com Fri Nov 20 11:36:15 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 20 Nov 2009 08:36:15 -0800 (PST) Subject: Split class across multiple files References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <5a896672-2670-4268-adff-bbce2e3f5752@p23g2000vbl.googlegroups.com> On Nov 20, 8:14?am, "eric.frederich" wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? Yes, define all your different methods in separate classes in separate files. Then subclasses all of those separate classes into one big class. > It is recommended? Debateable. Personally, I have no problem using inheritance for purely mechanical reasons. Others might. (In my case, it was a separation into general and customized behavior. I wanted to define generic behavior in one package, and specialized behavior in another, but there was no internal logical difference between specialized and generic methods.) However.... > Should I just stop worrying > about it and have a 5,000 line class? Five thousand lines is pushing the comfort level of how big a class ought to be. I suggest instead of worrying about how to mechanically split off methods into different files, you should consider whether there's a way to refactor that one big class into smaller ones. Then the problem you have goes away. Carl Banks From carsten.haese at gmail.com Fri Nov 20 11:38:42 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 11:38:42 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese > wrote: > Please show us a copy-and-paste of your command line window contents > that result from executing <> and then executing > <> immediately thereafter. > > > [root at 13gems globalsolutionsgroup.vi ]# > python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > [root at 13gems globalsolutionsgroup.vi ]# > python -c "import email; print email" > Thank you. This proves conclusively that there IS in fact a file called email.pyc (and/or email.py) in your directory next to testMail.py. It is this email.pyc that is being imported instead of the email.py from the Python library. Getting rid of both email.py and email.pyc (by renaming them, deleting them, or moving them somewhere else) will fix your problem. -- Carsten Haese http://informixdb.sourceforge.net From animator333 at gmail.com Fri Nov 20 11:38:54 2009 From: animator333 at gmail.com (King) Date: Fri, 20 Nov 2009 08:38:54 -0800 (PST) Subject: No duplicate variable Message-ID: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> class A(object): def __init__(self, value=0.): self.value = value class B(A): def __init__(self, value=None): A.__init__(self) self.value = value obj = B() When "B" initializes, it overwrite "value" variable of "A". How do I make sure that no variable should not be defined with names of "A" in "B"? Prashant From deets at nospam.web.de Fri Nov 20 11:46:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:46:16 +0100 Subject: No duplicate variable In-Reply-To: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> References: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> Message-ID: <7mnveoF3hq8cmU1@mid.uni-berlin.de> King schrieb: > class A(object): > def __init__(self, value=0.): > self.value = value > > class B(A): > def __init__(self, value=None): > A.__init__(self) > self.value = value > > obj = B() > > When "B" initializes, it overwrite "value" variable of "A". How do I > make sure that no variable should not be defined with names of "A" in > "B"? To avoid these kinds of clashes, you can use the double-undescore syntax. It will create a mangled name that looks like _module_class_variablename By this, the two different variable get distinct names. *However*, this is neither a proper way of making variables private, nor are name-clashes something that should arise more than every now-and-then. Instead, try rather renaming value to something more meaningful. Diez From azeynel1 at gmail.com Fri Nov 20 11:46:30 2009 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 20 Nov 2009 08:46:30 -0800 (PST) Subject: Newbie question about scrapy tutorial Message-ID: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> Hello, I have a question about scrapy tutorial and I put 2 questions in the scrapy group http://groups.google.com/group/scrapy-users/t/d5afae7d88672e02 http://groups.google.com/group/scrapy-users/t/4d52fa8c589a412a but there were no answers. Can anyone here help me? The spider works fine but I couldn't figure out where the items file is so that I can print it to a file to transfer it to my database. The same question in stackoverflow http://stackoverflow.com/questions/1771151/newbie-q-about-scrapy-pipeline-py Thanks! From kevin.p.dwyer at gmail.com Fri Nov 20 11:56:19 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 20 Nov 2009 16:56:19 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: On Fri, 20 Nov 2009 11:58:00 -0400, Victor Subervi wrote: Hello Victor, Carsten's well-specified instruction has identified your problem. >[root at 13gems globalsolutionsgroup.vi]# python -c "import email; print >email" > There is a file named email.pyc, most likely in your current directory, that is masking the email package in the standard library. Remove/rename email.pyc and email.py, if it exists. Cheers, Kevin From victorsubervi at gmail.com Fri Nov 20 12:13:32 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 13:13:32 -0400 Subject: Too Many Values To Unpack In-Reply-To: <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> Message-ID: <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> On Fri, Nov 20, 2009 at 12:14 PM, Shashank Singh < shashank.sunny.singh at gmail.com> wrote: > Are you sure your key values are 2-tuples in levelDict? > No. Here's some tweaked code: cursor.execute('select category from categories order by category') theTree = expand(cursor.fetchall()) print theTree Now, categories only has one category called 'cat1'. Here's what it prints: {'cat1': {}} Now what I don't understand about the above code, provided by Dennis Lee Bieber, is the "expand" statement. Nor could I find any documentation googling either "expand python" or "expand fetchall python". Could someone please explain what this code does? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Nov 20 12:17:54 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 20 Nov 2009 11:17:54 -0600 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06CF42.3040905@tim.thechases.com> Diez B. Roggisch wrote: > Esmail schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no rebinding > a name. So whover had a refernce to d before, now has a changed object, > whereas in the two cases above, the original lists aren't touched. To demonstrate what Diez is saying: a = range(51,55) d = [] x = d d[:] = a print x #hey, I didn't change x...oh, yeah -tkc From davea at ieee.org Fri Nov 20 12:29:09 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 12:29:09 -0500 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06D1E5.20601@ieee.org> Diez B. Roggisch wrote: >
    Esmail > schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no > rebinding a name. So whover had a refernce to d before, now has a > changed object, whereas in the two cases above, the original lists > aren't touched. > > Of course, in your concrete example, the looks of it are the same. The > distinction is crucial in larger contexts. > > Diez > > While Diez is correct, I think it could be less confusing. So I'll try to put it clearer. If it's not, sorry. (2) binds an empty list to c, and immediately rebinds it to a new list, copied from a.. So the c=[] line is totally irrelevant, unless there's some other code in between. (3) again binds an empty list to d, but this is important, because the following line wouldn't be legal if there weren't already a list. The only time this has a different practical effect from the other two is if there's some other code between the two lines. If that other code binds something to the same object then it definitely matters. I'd say (1) is the preferable form, as no visible object is in an in-between state. The copy is built anonymously, then bound only when it has its full value. DaveA From victorsubervi at gmail.com Fri Nov 20 12:39:30 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 13:39:30 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: <4dc0cfea0911200939i3fc5e821l8bedbacb821ecbd7@mail.gmail.com> On Fri, Nov 20, 2009 at 12:38 PM, Carsten Haese wrote: > Thank you. This proves conclusively that there IS in fact a file called > email.pyc (and/or email.py) in your directory next to testMail.py. It is > this email.pyc that is being imported instead of the email.py from the > Python library. Getting rid of both email.py and email.pyc (by renaming > them, deleting them, or moving them somewhere else) will fix your problem. > Thank you! It did indeed fix that problem. Now I get this traceback: /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py 52 session.sendmail(clientEmail, ourEmail1, header+msg) 53 # session.sendmail(clientEmail, ourEmail2, header+msg) 54 55 mailSpreadsheet() 56 *mailSpreadsheet* = /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet *() 47 order += 'TOTAL: $' + str(total) 48 msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) 49 session = smtplib.SMTP("localhost") 50 session.login(user, passwd) # only if it requires auth 51 header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject session *undefined*, *global* *smtplib* = , smtplib.*SMTP* = /usr/lib64/python2.4/smtplib.py in *__init__*(self=, host='localhost', port=0, local_hostname=None) 242 self.esmtp_features = {} 243 if host: 244 (code, msg) = self.connect(host, port) 245 if code != 220: 246 raise SMTPConnectError(code, msg) code *undefined*, msg *undefined*, *self* = , self.* connect* = >, *host* = 'localhost', *port* = 0 /usr/lib64/python2.4/smtplib.py in *connect*(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* = , self.*getreply* = > /usr/lib64/python2.4/smtplib.py in *getreply*(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) *global* *SMTPServerDisconnected* = * SMTPServerDisconnected*: Connection unexpectedly closed args = ('Connection unexpectedly closed',) Why did this connection close? How do I fix it? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyrie at uh.cu Fri Nov 20 12:45:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 20 Nov 2009 12:45:11 -0500 Subject: semantics of [:] In-Reply-To: References: Message-ID: <200911201245.11995.kyrie@uh.cu> On Friday 20 November 2009 11:15:55 am Esmail wrote: > Could someone help confirm/clarify the semantics of the [:] operator > in Python? In short, a[:], when "a" is a list, returns a slice ("sublist") of "a" that happens to contain all the elemnts of "a". In general, a[low:upper:step] will give you the sublist containing all the items from low to upper, with the specified step size. When you omit the three arguments, you get the whole list. When used on the left side, it means "replace the contents of this slice with the contents of this iterable". (The get slice and set slice behaviors are defined by the class of ?a?, so while this explanation applies to list, it may not apply, and will likely not apply, to other data structures). Note that the sublist is always another list (even when you get the full slice). So, in your experiments: > ############# 1 ################## > b = a[:] # b receives a copy of a, but they are independent Indeed, a[:] would return a full slice, i.e, another list containing the same elements as ?a? > # The following two are equivalent > ############# 2 ################## > c = [] > c = a[:] # c receives a copy of a, but they are independent > ############# 3 ################## > d = [] > d[:] = a # d receives a copy of a, but they are independent Not exactly, but the difference is not big in this particular circumstance. In (2), you create an empty list, discard it immediately, create another list a[:] with the contents of ?a?, and assign it to ?c?. In (3) you create an empty list, and then fill it with the elements of ?a?. To see the difference, try: e = [] g = e e = a[:] print g and e = [] g = e e[:] = a print g > ### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ## > do. Depends on what you want to achieve. Some times, you need to keep the list and change the contents. That would be (3). For instance, when updating the "dirnames" output of the iterator returned by os.walk . Some times, you need to discard de old list, and get a new one. (1) would be the way to go. Note that (2) and (1) are the same, in both you discard the old value, if it exists, but in (2) you are creating a new list only to discard it right away - you shouldn't do that. > Am I correct with this? I hope I could help. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From sturlamolden at yahoo.no Fri Nov 20 12:51:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 09:51:49 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On 20 Nov, 11:12, Robin Becker wrote: > Presumably that means they could potentially run in parallel on the 100000 cpu > machines of the future. > > I'm not so clear on whether the threadless tasklets will run on separate cpus. You can make a user-space scheduler and run a 100000 tasklets on a threadpool. But there is a GIL in stackless as well. Nobody wants 100000 OS threads, not with Python, not with Go, not with C. Also note that Windows has native support for "taskelets", regardless of language. They are called "fibers" (as opposed to "threads") and are created using the CreateFiber system call. I would not be surprised if Unix'es has this as well. We do not need Stackless for light-weight threads. We can just take Python's threading modules' C code and replace CreateThread with CreateFiber. From alexis.flesch at gmail.com Fri Nov 20 12:58:47 2009 From: alexis.flesch at gmail.com (Snouffy) Date: Fri, 20 Nov 2009 09:58:47 -0800 (PST) Subject: PyQt4 4.4.4 : a bug with highlightBlock ? References: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Message-ID: <7a44700d-24a3-4161-a899-ffc57fbb1baf@o10g2000yqa.googlegroups.com> > You need to change the indexOf() calls to indexIn() calls on the QRegExp > object: > > ? index = expression.indexIn(text, index + length) Thank you so much ! After looking a bit more I found out that when using indexOf the command : length = expression.matchedLength() was the one causing a problem. Thus I also had to change the line : index = text.indexOf(expression) to : index = expression.indexIn(text) Now it works like a charm ! I'll test it at work where we have PyQt 4.3.3. Thanks again ! From ebonak at hotmail.com Fri Nov 20 13:04:39 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 13:04:39 -0500 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Esmail schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no rebinding > a name. So whover had a refernce to d before, now has a changed object, I follow all of this up to here, the next sentence is giving me pause > whereas in the two cases above, the original lists aren't touched. The original list 'a', isn't changed in any of these cases right? And modifying b, c or d would not change 'a' either - or am I not understanding this correctly? ## 1 ## creates a new list and copies all elements from a to b ## 2 ## take an already existing list (empty) and copies all elements from a to it (no data is lost by c since c was empty to start out with) ## 3 ## d is a list, and all of its contents (if it had any) would be filled with that of a .. but changes to a still are not reflected in d .. this is confusing... Semi-aside, if I wanted to make local copy of a list sent to me as a parameter, which of these is the most appropriate to use (I don't want changes to change the original list sent). Thanks again. From carsten.haese at gmail.com Fri Nov 20 13:07:49 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 13:07:49 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> Message-ID: Victor Subervi wrote: > Now what I don't understand about the above code, provided by Dennis Lee > Bieber, is the "expand" statement. It's not a statement. It's a function. The function is defined in your code. Or rather, it's defined in the code that you copied from Dennis Lee Bieber, apparently. Look at the function definition. It'll tell you what the function does. > Could > someone please explain what this code does? Maybe you should ask the person that wrote the code. -- Carsten Haese http://informixdb.sourceforge.net From eric.frederich at gmail.com Fri Nov 20 13:28:41 2009 From: eric.frederich at gmail.com (eric.frederich) Date: Fri, 20 Nov 2009 10:28:41 -0800 (PST) Subject: Split class across multiple files References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> <7mnuivF3ih0p9U1@mid.uni-berlin.de> Message-ID: Yeah... it does seem like a God Object. My reasoning for putting them all into one big class is that the class has references to all the required resources, connections, and services. The other option would be to have a simple object called Session which did nothing but login and hold those references. The problem then is that I'd have 50 methods all of which would need to take that session object as an argument. That is what I was trying to avoid, having a ton of methods all taking the same first parameter. In most cases there would only be one session. Perhaps I could do a singleton approach and have each of these methods implicitly use the single session object unless called with a session= keyword argument. How does this look?..... # Begin Session.py class Session(): def __init__(self, host=None, username=None, password=None): if host and username and password: self.login(host, username, password) def login(self, host, username, password): self.host = host self.username = username self.password = password self.connection = Something.login(host, username, password) self.someService = SomeService.getService(connection) self.anotherService = AnotherService.getService(connection) def logout(self): return self.connection.logout() defaultSession = Session() # Begin MyLibrary.py from session import defaultSession def doSomethig(x, y, z, session=defaultSession): return session.someService.doSomething(x, y, z) def anotherFunction(x, y, session=defaultSession): ret = 0 for item in session.anotherService.getStuff(x): if session.someService.foo(item, y): session.anotherService.bar(item, x) ret += 1 return ret On Nov 20, 11:31?am, "Diez B. Roggisch" wrote: > eric.frederich schrieb: > > > I have a class which holds a connection to a server and a bunch of > > services. > > In this class I have methods that need to work with that connection > > and services. > > > Right now there are about 50 methods some of which can be quite long. > > From an organizational standpoint, I'd like to have method > > implementations in their own files. > > > Is this possible? ?It is recommended? ?Should I just stop worrying > > about it and have a 5,000 line class? > > It is pretty easy to do, as python allows multiple inheritance. Just > group together methods into a class, and create one that inherits from all. > > However, I'd say something that even splitted up is essentially one > class with 5000 lines cries for a huge refactoring. Of course this > depends on the use-case, but I for once don't have a single such beast. > Looks like a god-object to me... > > http://en.wikipedia.org/wiki/God_object > > Diez From apt.shansen at gmail.com Fri Nov 20 13:40:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 20 Nov 2009 13:40:02 -0500 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <7a9c25c20911201040p3330f309s197b557f7da026f0@mail.gmail.com> > > The original list 'a', isn't changed in any of these cases right? And > modifying b, c or d would not change 'a' either - or am I not understanding > this correctly? > > ## 1 ## > > creates a new list and copies all elements from a to b > > Yes. > ## 2 ## > > take an already existing list (empty) and copies all elements from a to > it (no data is lost by c since c was empty to start out with) > > No. The 'already existing list' is simply completely discarded. You're creating it on one line, then destroying it. A brand new list is being created and returned and bound to the same name as the already existing list. > ## 3 ## > > d is a list, and all of its contents (if it had any) would be > filled with that of a .. but changes to a still are not reflected in d > .. this is confusing... > Not exactly, if I understand you correctly. D is a list, but its contents (if it had any) would be completely replaced. Any previous content would be gone, and it would now contain a copy of a. > Semi-aside, if I wanted to make local copy of a list sent to me as a > parameter, which of these is the most appropriate to use (I don't want > changes to change the original list sent). > my_copy = original[:] --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Nov 20 14:08:23 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 14:08:23 -0500 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06E927.5070407@ieee.org> Esmail wrote: >
    Diez B. > Roggisch wrote: >> Esmail schrieb: >>> Could someone help confirm/clarify the semantics of the [:] operator >>> in Python? >>> >>> a = range(51,55) >>> >>> ############# 1 ################## >>> b = a[:] # b receives a copy of a, but they are independent >> > >>> >>> > > > Semi-aside, if I wanted to make local copy of a list sent to me as a > parameter, which of these is the most appropriate to use (I don't want > changes to change the original list sent). > > Thanks again. > > (1) is most appropriate in that case. In fact, unless there is other code mixed in between, it's always the most appropriate. DaveA From ethan at stoneleaf.us Fri Nov 20 14:22:58 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 11:22:58 -0800 Subject: semantics of [:] In-Reply-To: <4B06E927.5070407@ieee.org> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> <4B06E927.5070407@ieee.org> Message-ID: <4B06EC92.1000701@stoneleaf.us> Dave Angel wrote: > Esmail wrote: >>> Esmail schrieb: >>> >>>> Could someone help confirm/clarify the semantics of the [:] operator >>>> in Python? >>>> >>>> a = range(51,55) >>>> >>>> ############# 1 ################## >>>> b = a[:] # b receives a copy of a, but they are independent >> >> Semi-aside, if I wanted to make local copy of a list sent to me as a >> parameter, which of these is the most appropriate to use (I don't want >> changes to change the original list sent). >> > (1) is most appropriate in that case. In fact, unless there is other > code mixed in between, it's always the most appropriate. Be aware: this is only a shallow copy -- if your copied list contains mutable objects that you mutate, those changes *will* show up in the original list. Shallow copies are useful when, for example, you won't be mutating objects in the copied list but are adding, removing, or reordering the copied list. Hope this helps. ~Ethan~ From tjreedy at udel.edu Fri Nov 20 14:39:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 14:39:51 -0500 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: <0315a685$0$1327$c3e8da3@news.astraweb.com> Message-ID: Robert Maas, http://tinyurl.com/uh3t wrote: >>> My proposed no-syntax >>> IDE *also* gets rid of the need to bother with any programming-language >>> syntax. I've been proposing it for years, but nobody has shown any >>> interest What you describe below is similar to various systems that have been proposed and even implemented, including visual programming systems. And there has been some success with non-programmers. But for most people, it is simply easier to say/write what one means rather than point and click. Point-and-click writing reminds me of point-and-click speaking. Great for those who need it but a hindrance to those who do not. This is not to say that traditional editors cannot be improved with better backup memory aids. Indeed, even IDLE recognizes function names and pops up a bar listing parameters. Feel free to develop a Visual Python environment. I might even give it a try. >> From: Steven D'Aprano >> I'm interested. No-syntax IDE? How is this even possible? > > I guess you missed what I previously posted. I did too and had the same question. > The basic idea is that > you start with test data, and you use menus to select appropriate > data-processing actions to perform on that data. For example, you > manually key in a file name containing test data, or copy and paste > that same file name. Then you select "open file by that name" or > "load all lines from file by that name" etc. from a menu. If you > just opened the file, you now have a stream of input, and you can > select to read one line or one s-expression or one character etc. > from that file. After loading the whole file or one unit of data, > you now have some *real* data to work from. For example, with a > line of input, you might break it into words. Processing a single data file is a common programming task, but not the only general category. A specialized Visual Data Analysis with Python might be a better and more focused project. When I was doing statistical data analysis on a daily basis for a living, I would have loved to have had a system that would read in the first line and let me define (and name) the fields by point and click. (I usually worked with fixed-width, column-delimited fields.) Instead, I had to write a format statement and some summary analysis code, run it, look at it for sanity, and decide if my format had been correct. Terry Jan Reedy From ethan at stoneleaf.us Fri Nov 20 14:42:20 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 11:42:20 -0800 Subject: Newsgroup for beginners In-Reply-To: References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <4B06F11C.2030806@stoneleaf.us> Aahz wrote: > In article , > Grant Edwards wrote: > >>You've really got to try pretty hard to create one. But if you >>want to, here's how to do it: >> >>1) Start by complaining that your program doesn't work because >> of a bug in Python. >> >> [...] > > > Post of the month! I'll second that! I really needed a good laugh. Many thanks! From vorticitywolfe at gmail.com Fri Nov 20 15:07:35 2009 From: vorticitywolfe at gmail.com (J Wolfe) Date: Fri, 20 Nov 2009 12:07:35 -0800 (PST) Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: <68b0e959-6054-422a-a1e0-aac2161f6558@37g2000yqm.googlegroups.com> On Nov 9, 2:27?pm, Peter Otten <__pete... at web.de> wrote: > J Wolfe wrote: > > I would like to sort this dictionary by the values of the inner > > dictionary ?ob? key. > > Python's built-in dictionary is unsorted by design. > > > > > mydict = > > {?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?}, > > ?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?} > > } > > > In this case, this would become: > > > mysorteddic = > > {?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?}, > > ?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?} > > } > > > I have had no luck in trying to figure this out. I am restricted to > > using python 2.4.3. > > > Any help would be appreciated! > > You may be able to work around that limitation by putting the dict items > into a list and sort that: > > >>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), > > reverse=True): > ... ? ? print item > ... > ('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'}) > ('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'}) > ('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'}) > > Peter Thanks Peter, That worked! :-) From tjreedy at udel.edu Fri Nov 20 15:09:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:09:41 -0500 Subject: python bijection In-Reply-To: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: Joshua Bronson wrote: > Anyone have any other feedback? For instance, is offering the __call__ > syntax for the inverse mapping wonderful or terrible, or maybe both? Terrible ;-) Use standard subscripting with slices, and only that, to both get and set. Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition Then m[:'abc'] == 4 m[4:] passes slice(4,None,None) to __getitem__ m[:'abc'] passes slice(None,'abc',None) It just happens that dict items and slices use the same notation, but they do, so take advantage of that. In fact, to emphasize the symmetry of the bijective map, consider disallowing m[key] as ambiguous and require m[key:], along with m[:key] to access and set. Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so this approach does not even prevent using slices as keys/values. In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an error. In __getitem__, it could either be a error or return True/False depending on whether the pair is in the map. But this depends on whether __contains__ only tests keys or is modified to test pairs. Terry Jan Reedy From duncan.booth at invalid.invalid Fri Nov 20 15:20:49 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Nov 2009 20:20:49 GMT Subject: semantics of [:] References: Message-ID: Dave Angel wrote: > > > Esmail wrote: >>
    Diez B. >> Roggisch wrote: >>> Esmail schrieb: >>>> Could someone help confirm/clarify the semantics of the [:] operator >>>> in Python? >>>> >>>> a = range(51,55) >>>> >>>> ############# 1 ################## >>>> b = a[:] # b receives a copy of a, but they are independent >>> > >>>> >>>> >> > (1) is most appropriate in that case. In fact, unless there is other > code mixed in between, it's always the most appropriate. An alternative view is that it is most appropriate to do: b = list(a) as that accepts any type of sequence for a and you don't have to remember obscure punctuation to know what it does. The exception of course is when (a) 'a' is sliceable and (b) you need to 'b' to be of the same type as 'a'. From tjreedy at udel.edu Fri Nov 20 15:26:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:26:33 -0500 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: eric.frederich wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. >>From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? A method is just function that is a class attribute. from somemethod import somemethod # has def somemethod class Huge: somemethod = somemethod # or class Huge: defs ... Huge.somemethod = somemethod > It is recommended? Should I just stop worrying > about it and have a 5,000 line class? I suspect some refactoring would be useful. From lfscripter at gmail.com Fri Nov 20 15:31:06 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Fri, 20 Nov 2009 21:31:06 +0100 Subject: Gray Hat Python: Python Programming for Hackers Soft copy Message-ID: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> Hi i`m looking for a place to get a soft copy of 'Gray Hat Python: Python Programming for Hackers' may be a pdf or chm format. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Nov 20 15:31:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:31:17 -0500 Subject: No duplicate variable In-Reply-To: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> References: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> Message-ID: King wrote: > class A(object): > def __init__(self, value=0.): > self.value = value > > class B(A): > def __init__(self, value=None): > A.__init__(self) > self.value = value > > obj = B() > > When "B" initializes, it overwrite "value" variable of "A". How do I > make sure that no variable should not be defined with names of "A" in > "B"? By knowing the public interface of A before you inherit from it, so you do not do that. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 20 15:37:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 20:37:12 GMT Subject: Is an interactive command a block? References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: <0316ebed$0$1379$c3e8da3@news.astraweb.com> On Fri, 20 Nov 2009 08:02:38 -0800, Ethan Furman wrote: >> Thanks, but hey, contradiction: you mention globals as an "enclosing" >> scope, i.e. that a module can have a scope, while stating that only >> classes and functions have their own scope (so, would a module have >> it's not own scope?). > > module scope == global scope > > That is, there is nothing higher than module scope. (So, yes, global is > a slight misnomer... in Python it means 'global to a module'.) Actually there is: built-ins. That's why you can access (e.g.) len without having to define it, or import it, first. And what's more, you can do this: >>> len([1,2,3]) 3 >>> def len(x): # Shadow the built-in ... return -3 ... >>> len([1,2,3]) -3 >>> del len >>> len([1,2,3]) # It's back! 3 -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 20 15:37:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 20:37:22 GMT Subject: Is there something similar to list comprehension in dict? References: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> Message-ID: <0316ebf7$0$1379$c3e8da3@news.astraweb.com> On Fri, 20 Nov 2009 03:08:01 -0800, DreiJane wrote: > NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, > two:2} ? Because it doesn't work unless you have defined names one and two. dict(one=1, two=2) uses keyword arguments, namely one and two. This is the same standard mechanism by which you call functions with keyword arguments: myfunc(widget=x, width=5, name='fred', flag=True) The dict literal syntax requires names one and two to already exist, otherwise you have to quote them to make them strings: d = {'one': 1, 'two': 2} > Since you do not write L=list((1, 2)) either. But you certainly can. It would be wasteful, since first it constructs a tuple (1, 2), then it creates a list from that tuple. > These composed > objects as basic building blocks make Python code so dense and > beautiful, thus using "{}" means embracing the language's concept. I don't understand this sentence. -- Steven From ethan at stoneleaf.us Fri Nov 20 15:52:50 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 12:52:50 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <4B0701A2.9040603@stoneleaf.us> Jason R. Coombs wrote: > The current implementation of Python (2.6.4, 3.1.1) treats \bar as a > relative path but reports it as an absolute path. > > >>>>ntpath.isabs('\\bar') > > True > >>>>ntpath.abspath('\\bar') > > 'C:\\bar' > >>>>os.chdir('d:\\') >>>>ntpath.abspath('\\bar') > > 'd:\\bar' > >>>>os.chdir('\\\\server\\share') >>>>ntpath.abspath('\\bar') > > '\\\\server\\share\\bar' > > In other words, paths without a drive letter are reported as absolute, > but treated as relative, except in a few special cases. > > >>>>ntpath.join('d:\\foo', '\\bar') > > '\\bar' > > In this case, \bar is treated as absolute, and not relative to d:\foo. It is often said on this list that 'Python is not Java'. It is also true that 'Windows is not Unix'. Unlike the *nix world where there is a *single* root, and everything else is relative to that, in the Windows world there are several roots -- every drive has one! So \bar is both an absolute path on whichever drive is active (or specified), as well as relative if you happen to have more than one drive, but it will not ever be relative on any specific drive. If you want 'bar' to be relative to the current directory, do not specify a leading '\'. [snip] > Ultimately, I don't care what the definition is. It seems to me, > however, that Python should have a function that can resolve one path > name relative to another, but due to these limitations, it does not. I > should point out that os.path.relpath is not the solution either as > the first parameter is always treated as relative to the current > directory (more info at http://bugs.python.org/issue7195). Please note that there *is not* a relative path that can take you from c:\foo to d:\bar (see the point about multiple roots above). > I've built workarounds in https://svn.jaraco.com/jaraco/python/jaraco.windows/jaraco/windows/filesystem.py > as join() and resolve_path(). I'm happy to continue using these > workarounds, but I wanted to bring this issue to the attention of the > community for any comments or suggestions or answers to the following > questions. > > What is the benefit of treating \path as absolute? That was not Python's decision, but Windows'. > Should Python have built-in support for resolving one path relative to > another (such as is jaraco.windows.filesystem.resolve_path does)? As I noted above, you are not returning a relative path when the paths cross drive letter boundaries, or one of the paths specified is a drive-absolute path (such as '\bar'). > Given the long established behavior of Python and other platforms for > handling absolute paths in Windows, is there a way forward that > handles these cases more elegantly, or is the best approach to just > mumble something nasty under our breath and work around these issues > on a case-by-case basis? I just go with the mumbling, myself. Hope this helps. ~Ethan~ P.S. And now that I look up the comments in the bug-tracker, I see this was all already pointed out to you. From ethan at stoneleaf.us Fri Nov 20 16:03:43 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 13:03:43 -0800 Subject: Is an interactive command a block? In-Reply-To: <0316ebed$0$1379$c3e8da3@news.astraweb.com> References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> <0316ebed$0$1379$c3e8da3@news.astraweb.com> Message-ID: <4B07042F.1010702@stoneleaf.us> Steven D'Aprano wrote: > On Fri, 20 Nov 2009 08:02:38 -0800, Ethan Furman wrote: >> >> module scope == global scope >> >> That is, there is nothing higher than module scope. (So, yes, global is >> a slight misnomer... in Python it means 'global to a module'.) > > Actually there is: built-ins. > > That's why you can access (e.g.) len without having to define it, or > import it, first. And what's more, you can do this: > >>>>len([1,2,3]) > > 3 > >>>>def len(x): # Shadow the built-in > ... return -3 > ... >>>>len([1,2,3]) > -3 > >>>>del len >>>>len([1,2,3]) # It's back! > > 3 Very good point, I had forgotten. Of course, injecting into built-ins is not recommended. ~Ethan~ From ebonak at hotmail.com Fri Nov 20 16:30:26 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 16:30:26 -0500 Subject: semantics of [:] In-Reply-To: References: Message-ID: Thank you all for your posts - this was very enlightening and I printed this thread off for future reference. From aahz at pythoncraft.com Fri Nov 20 16:45:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2009 13:45:04 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: In article , sturlamolden wrote: > >Also note that Windows has native support for "taskelets", regardless >of language. They are called "fibers" (as opposed to "threads") and are >created using the CreateFiber system call. I would not be surprised if >Unix'es has this as well. We do not need Stackless for light-weight >threads. We can just take Python's threading modules' C code and >replace CreateThread with CreateFiber. Are you advocating a high-fiber diet? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 mmitchell at transparent.com Fri Nov 20 16:45:43 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 20 Nov 2009 16:45:43 -0500 Subject: Gray Hat Python: Python Programming for Hackers Soft copy In-Reply-To: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> References: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> Message-ID: You mean like: http://nostarch.com/ghpython.htm From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Elf Scripter Sent: Friday, November 20, 2009 3:31 PM To: python-list at python.org Subject: Gray Hat Python: Python Programming for Hackers Soft copy Hi i`m looking for a place to get a soft copy of 'Gray Hat Python: Python Programming for Hackers' may be a pdf or chm format. Thank you ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jabronson at gmail.com Fri Nov 20 16:59:24 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 13:59:24 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <131ecb11-f1e0-480f-98b9-46b0359abe27@x16g2000vbk.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Joshua Bronson wrote: > > Anyone have any other feedback? For instance, is offering the __call__ > > syntax for the inverse mapping wonderful or terrible, or maybe both? > > Terrible ;-) > > Use standard subscripting with slices, and only that, to both get and set. > > Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition > Then m[:'abc'] == 4 > > m[4:] passes slice(4,None,None) to __getitem__ > m[:'abc'] passes slice(None,'abc',None) > > It just happens that dict items and slices use the same notation, but > they do, so take advantage of that. In fact, to emphasize the symmetry > of the bijective map, consider disallowing m[key] as ambiguous and > require m[key:], along with m[:key] to access and set. > > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. > > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. But this depends on whether > __contains__ only tests keys or is modified to test pairs. > > Terry Jan Reedy absolutely genius. implemented in the latest version: http://bitbucket.org/jab/toys/src/tip/bijection.py thank you for the terrific idea! From jabronson at gmail.com Fri Nov 20 16:59:24 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 13:59:24 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <131ecb11-f1e0-480f-98b9-46b0359abe27@x16g2000vbk.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Joshua Bronson wrote: > > Anyone have any other feedback? For instance, is offering the __call__ > > syntax for the inverse mapping wonderful or terrible, or maybe both? > > Terrible ;-) > > Use standard subscripting with slices, and only that, to both get and set. > > Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition > Then m[:'abc'] == 4 > > m[4:] passes slice(4,None,None) to __getitem__ > m[:'abc'] passes slice(None,'abc',None) > > It just happens that dict items and slices use the same notation, but > they do, so take advantage of that. In fact, to emphasize the symmetry > of the bijective map, consider disallowing m[key] as ambiguous and > require m[key:], along with m[:key] to access and set. > > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. > > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. But this depends on whether > __contains__ only tests keys or is modified to test pairs. > > Terry Jan Reedy absolutely genius. implemented in the latest version: http://bitbucket.org/jab/toys/src/tip/bijection.py thank you for the terrific idea! From deets at nospam.web.de Fri Nov 20 18:42:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 21 Nov 2009 00:42:00 +0100 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <7monqaF3icnf3U2@mid.uni-berlin.de> Esmail schrieb: > Diez B. Roggisch wrote: >> Esmail schrieb: >>> Could someone help confirm/clarify the semantics of the [:] operator >>> in Python? >>> >>> a = range(51,55) >>> >>> ############# 1 ################## >>> b = a[:] # b receives a copy of a, but they are independent >> > >>> >>> >>> # The following two are equivalent >>> ############# 2 ################## >>> c = [] >>> c = a[:] # c receives a copy of a, but they are independent >> >> No, the both above are equivalent. Both just bind a name (b or c) to a >> list. This list is in both cases a shallow copy of a. >> >>> >>> >>> ############# 3 ################## >>> d = [] >>> d[:] = a # d receives a copy of a, but they are independent >> >> >> This is a totally different beast. It modifies d in place, no >> rebinding a name. So whover had a refernce to d before, now has a >> changed object, > > I follow all of this up to here, the next sentence is giving me pause > >> whereas in the two cases above, the original lists aren't touched. > > The original list 'a', isn't changed in any of these cases right? And > modifying b, c or d would not change 'a' either - or am I not > understanding this correctly? None of your operations changes a. But I talked about the lists you bound b and c to before. Those aren't changed as well - they simply are not pointed to anymore. In your example, that means the will be garbage-collected, in other scenarios, such as this, the stay: a = [] foo = [] bar = foo assert bar is foo bar = a[:] assert bar is not foo Diez From ebonak at hotmail.com Fri Nov 20 18:58:10 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 18:58:10 -0500 Subject: semantics of [:] In-Reply-To: <7monqaF3icnf3U2@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> <7monqaF3icnf3U2@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Esmail schrieb: > > None of your operations changes a. But I talked about the lists you > bound b and c to before. Those aren't changed as well - they simply are > not pointed to anymore. In your example, that means the will be > garbage-collected, in other scenarios, such as this, the stay: > > a = [] > foo = [] > bar = foo > assert bar is foo > bar = a[:] > assert bar is not foo Got it :-) .. thanks for helping out Diez Esmail From greg.ewing at canterbury.ac.nz Fri Nov 20 19:26:57 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 13:26:57 +1300 Subject: ANN: PyGUI Mailing List Message-ID: There is now a mailing list for discussion of PyGUI: http://mail.python.org/mailman/listinfo/pygui What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From greg.ewing at canterbury.ac.nz Fri Nov 20 19:57:39 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 13:57:39 +1300 Subject: Relative versus absolute paths on Windows In-Reply-To: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <7mos8lF3is0n7U1@mid.individual.net> Jason R. Coombs wrote: > In other words, paths without a drive letter are reported as absolute, > but treated as relative, except in a few special cases. It's not clear what the result ought to be here, since Windows drive-relative paths don't really fit into the unix absolute/relative dichotomy. Arguments could be made either way, and what's right probably depends on the reason you're asking. For cross-platform code, it's probably safest to avoid drive-relative paths altogether -- convert them to fully absolute paths at the earliest opportunity. >>>>ntpath.join('d:\\foo', '\\bar') > > '\\bar' This does seem like a bug, though -- the correct result should really be 'd:\\bar', since that's what you would get if you used the name '\\bar' with 'd:' as your current drive. -- Greg From aahz at pythoncraft.com Fri Nov 20 20:12:36 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2009 17:12:36 -0800 Subject: Go versus Brand X Message-ID: Comparing Go to another computer language -- do you recognize it? http://www.cowlark.com/2009-11-15-go/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 greg.ewing at canterbury.ac.nz Fri Nov 20 20:16:52 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 14:16:52 +1300 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <0315a502$0$1327$c3e8da3@news.astraweb.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <0315a502$0$1327$c3e8da3@news.astraweb.com> Message-ID: <7motclF3if17eU1@mid.individual.net> Steven D'Aprano wrote: > On Wed, 18 Nov 2009 18:47:34 -0800, Chris Rebert wrote: > >>Accessor methods are not Pythonic. > > Accessor methods are *usually* not Pythonic, at least not the way they > are commonly used in Java. To elaborate, accessor methods that *only* read and write another, ordinary attribute are completely unnecessary in Python. In that case there is no harm in exposing the underlying attribute directly, because you can always replace it with a property later if you change your mind, without requiring any change in calling code. Also, even when you do need accessor methods, it's more elegant to hide them behind a property than to expect callers to use them directly. It makes the calling code more concise, and allows for changing your mind in the opposite direction. -- Greg From mensanator at aol.com Fri Nov 20 20:40:19 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 20 Nov 2009 17:40:19 -0800 (PST) Subject: Go versus Brand X References: Message-ID: <76168195-defb-4119-bf66-649da83ea306@s31g2000yqs.googlegroups.com> On Nov 20, 7:12?pm, a... at pythoncraft.com (Aahz) wrote: > Comparing Go to another computer language -- do you recognize it? No, it predates my entry into the computer biz. > > http://www.cowlark.com/2009-11-15-go/ > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "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 d.dalton at iinet.net.au Fri Nov 20 20:47:01 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sat, 21 Nov 2009 12:47:01 +1100 Subject: python and web pages In-Reply-To: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> References: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> Message-ID: <20091121014701.GA14070@gwsc.vic.edu.au> On Thu, Nov 19, 2009 at 09:43:50AM +0100, Diez B. Roggisch wrote: > >elinks, links, links2 and do the following. > >1. Open a certain web page and find the first text box on the page, and > >put this text into the form. > >2. Press the submit button, and wait for the result page to load. > >3. Click on the 15th link down the page. > > > >So, how do I do this, can anyone point me to some docs or modules that > >may help out here? > > Use the module "mechanize". It will mimic a browser, and allows you > to navigate to pages, fill in forms & submit them. Well, what seemed a very daunting task at first, proved to be quite easy, after a little bit of research. Thanks very much, I've written my script, and it works correctly, using the mechanize module. Thanks for everyone's help -- Cheers, Dan http://members.iinet.net.au/~ddalton/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From aaron.watters at gmail.com Fri Nov 20 21:05:45 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 20 Nov 2009 18:05:45 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9ece38d9-8052-4703-b4bb-a948f21adca5@m33g2000vbi.googlegroups.com> > Because `language is slow' is meaningless. Yes. Everyone knows java is faster than Python right? But look here: http://gaejava.appspot.com/ (you might want to run it a couple times to see what it does when it is 'warm'). I don't think this is a biased test -- I think the author expected to see Java faster. In my runs Python is usually a bit faster on a majority of these metrics consistently. Why? My guess is the reason is that Python is less bloated than Java so more of it can stay resident on a shared machine whereas big hunks of Java have to be swapped in for every access -- but it's just a guess. By the way: I see this all the time -- for web use Python always seems to be faster than Java in my experience. (With programs that I write: I tend to avoid some of the larger Python web tools available out there and code close to the protocol.) Comparing language platforms using small numeric benchmarks often completely misses the point. -- Aaron Watters http://whiffdoc.appspot.com http://listtree.appspot.com === an apple every 8 hours will keep 3 doctors away. - kliban From sturlamolden at yahoo.no Fri Nov 20 22:45:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 19:45:26 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On 20 Nov, 22:45, a... at pythoncraft.com (Aahz) wrote: > Are you advocating a high-fiber diet? Only if you are a ruminant. No really... Windows has user-space threads natively. But you must reserve some stack space for them (from virtual memory), which mainly makes them useful on 64 bit systems. From jabronson at gmail.com Sat Nov 21 02:34:15 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 23:34:15 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <63105bbf-7276-4296-ac91-7e2f6ff05007@h10g2000vbm.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Use standard subscripting with slices, and only that, to both get and set. i did this for __delitem__ too, so you can do e.g. del m[:'abc']. > In fact, to emphasize the symmetry of the bijective map, consider > disallowing m[key] as ambiguous and require m[key:] my initial feeling is that i'd prefer to be able to say m[key], the defense being that it's not ambiguous if it's documented, and users who don't like it don't have to use it, while users who do like it won't be alienated. but i am definitely still open to this. > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. except slices aren't hashable. but props for even thinking of that! > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. i went with raising an error for __getitem__(slice(a,b,None)). returning True/False for this usage based on whether a -> b is in the bijection is an interesting idea, but i feel like it complicates things for no good reason: if that's what you wanted to know you'd just ask whether m[a] == b. > But this depends on whether __contains__ only tests keys or is modified to test pairs. i have __contains__ only testing keys, and similarly [i for i in bijection] only gives you the keys, again on the theory that deviating too much from the dict api increases the learning (adoption) curve, so i think we should only do it if it buys us a tremendous usability win. thanks again for your insightful input, i'm pretty psyched about how this is coming along! any further feedback is always welcome. josh From jabronson at gmail.com Sat Nov 21 02:34:15 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 23:34:15 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <63105bbf-7276-4296-ac91-7e2f6ff05007@h10g2000vbm.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Use standard subscripting with slices, and only that, to both get and set. i did this for __delitem__ too, so you can do e.g. del m[:'abc']. > In fact, to emphasize the symmetry of the bijective map, consider > disallowing m[key] as ambiguous and require m[key:] my initial feeling is that i'd prefer to be able to say m[key], the defense being that it's not ambiguous if it's documented, and users who don't like it don't have to use it, while users who do like it won't be alienated. but i am definitely still open to this. > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. except slices aren't hashable. but props for even thinking of that! > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. i went with raising an error for __getitem__(slice(a,b,None)). returning True/False for this usage based on whether a -> b is in the bijection is an interesting idea, but i feel like it complicates things for no good reason: if that's what you wanted to know you'd just ask whether m[a] == b. > But this depends on whether __contains__ only tests keys or is modified to test pairs. i have __contains__ only testing keys, and similarly [i for i in bijection] only gives you the keys, again on the theory that deviating too much from the dict api increases the learning (adoption) curve, so i think we should only do it if it buys us a tremendous usability win. thanks again for your insightful input, i'm pretty psyched about how this is coming along! any further feedback is always welcome. josh From steve at REMOVE-THIS-cybersource.com.au Sat Nov 21 03:12:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2009 08:12:51 GMT Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <03178ef5$0$1379$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote: > MRAB wrote: >> u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a >> visible "CR" graphic) for carriage return. Windows programs normally >> expect lines to end with '\r\n'; just use u'\n' in programs and open >> the text files in text mode ('r' or 'w'). > > > This is the one thing from standards that I believe Microsoft got right > where others did not. Oh please, that's historical revisionism -- \r\n wasn't invented by Microsoft. Microsoft didn't "get it right", they simply copied what CP/M did, on account of the original MS-DOS being essentially a clone of CP/M. And of course the use of \r\n predates computers -- CR+LF (Carriage Return + LineFeed) were necessary to instruct the print head on teletype printers to move down one line and return to the left. It was a physical necessity for the oldest computer operating systems, because the only printers available were teletypes. > The ASCII (American Standard for Information > Interchange) standard end of line is _both_ carriage return (\r) _and_ > line feed (\n) I doubt that very much. Do you have a reference for this? It is true that the predecessor to ANSI (not ASCII), ASA, specified \r\n as the line terminator, but ISO specified that both \n and \r\n should be accepted. > I believe in that order. You "believe" in that order? But you're not sure? That's the trouble with \r\n, or \n\r -- it's an arbitrary choice, and therefore hard to remember which it is. I've even seen proprietary business-to-business software where the developers (apparently) couldn't remember which was the standard, so when exporting data to text, you had to choose which to use for line breaks. Of course, being Windows software, they didn't think that you might want to transfer the text file to a Unix system, or a Mac, and so didn't offer \n or \r alone as line terminators. > The Unix operating system, in its enthusiasm to make _everything_ > simpler (against Einstein's advice, "Everything should be made as simple > as possible, but not simpler.") decided that end-of-line should be a > simple line feed and not carriage return line feed. Why is it "too simple" to have line breaks be a single character? What is the downside of the Unix way? Why is \r\n "better"? We're not using teletypes any more. Or for that matter, classic Mac OS, which used a single \r as newline. Likewise for other OSes, such as Commodore, Amiga, Multics... > Before they made > that decision, there was debate about the order of cr-lf or lf-cr, or > inventing a new EOL character ('\037' == '\x1F' was the candidate). IBM operating systems that use EBCDIC used the NEL (NExt Line) character for line breaks, keeping CR and LF for other uses. The Unicode standard also specifies that any of the following be recognised as line separators or terminators: LF, CR, CR+LF, NEL, FF (FormFeed, \f), LS (LineSeparator, U+2028) and PS (ParagraphSeparator, U+2029). > If you've actually typed on a physical typewriter, you know that moving > the carriage back is a distinct operation from rolling the platen > forward; I haven't typed on a physical typewriter for nearly a quarter of a century. If you've typed on a physical typewriter, you'll know that to start a new page, you have to roll the platen forward until the page ejects, then move the typewriter guide forward to leave space, then feed a new piece of paper into the typewriter by hand, then roll the platen again until the page is under the guide, then push the guide back down again. That's FIVE distinct actions, and if you failed to do them, you would type but no letters would appear on the (non-existent) page. Perhaps we should specify that text files need a five-character sequence to specify a new page too? > both operations are accomplished when you push the carriage > back using the bar, but you know they are distinct. Hell, MIT even had > "line starve" character that moved the cursor up (or rolled the platen > back). > > > Lots of people talk about "dos-mode files" and "windows files" as if > Microsoft got it wrong; it did not -- Unix made up a convenient fiction > and people went along with it. (And, yes, if Unix had been there first, > their convention was, in fact, better). This makes zero sense. If Microsoft "got it right", then why is the Unix convention "convenient" and "better"? Since we're not using teletype machines, I would say Microsoft is now using an *inconvenient* fiction. -- Steven From "knutjbj(nospam)" at online.no Sat Nov 21 03:25:38 2009 From: "knutjbj(nospam)" at online.no (nospam) Date: Sat, 21 Nov 2009 09:25:38 +0100 Subject: extending dictonary Message-ID: Is there any way to extend the dictonary in such manner that I can insert muliplay value to each keys and return one of the value as the default value. I would like to have similar syste that I drawed out below. tree[nucelotide_postionc][nucleotide]=default(value subtree) This should be returned when doing lookup without any tree[nucelotide_postionc][nucleotide]=Postive value tree[nucelotide_postionc][nucleotide]=Negative value From sturlamolden at yahoo.no Sat Nov 21 04:48:44 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 21 Nov 2009 01:48:44 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> Message-ID: <595c7dca-7715-4081-8a5b-a47b1ed78bdf@d10g2000yqh.googlegroups.com> On 21 Nov, 09:12, Steven D'Aprano wrote: > Oh please, that's historical revisionism -- \r\n wasn't invented by > Microsoft. Microsoft didn't "get it right", they simply copied what CP/M > did, on account of the original MS-DOS being essentially a clone of CP/M. Actyually \r\n goes back to early mechanical typewriters with typebars, such as the Hermes. The operator would hit CR to return the paper carriage and LF to move down to the next line. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 21 04:50:28 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2009 09:50:28 GMT Subject: extending dictonary References: Message-ID: <0317a5d6$0$1379$c3e8da3@news.astraweb.com> On Sat, 21 Nov 2009 09:25:38 +0100, nospam wrote: > Is there any way to extend the dictonary in such manner that I can > insert muliplay value to each keys and return one of the value as the > default value. I would like to have similar syste that I drawed out > below. > > > tree[nucelotide_postionc][nucleotide]=default(value subtree) This should > be returned when doing lookup without any > tree[nucelotide_postionc][nucleotide]=Postive value > tree[nucelotide_postionc][nucleotide]=Negative value I'm sorry, I don't understand what you are asking. What are tree, nucelotide_postionc, nucleotide, subtree? What are positive value and negative value? If each key has multiple values, how do you want to specify which value to return? The simplest way to associate multiple values with a key is to use a list: >>> d = {} >>> d['a'] = [2, 3, 4] >>> d['b'] = [5, 6] >>> d['a'].append(0) >>> d {'a': [2, 3, 4, 0], 'b': [5, 6]} If you like, you can take the convention that the first item in the list is the default, and write this: >>> print d['b'][0] 5 -- Steven From sturlamolden at yahoo.no Sat Nov 21 04:59:09 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 21 Nov 2009 01:59:09 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: On 21 Nov, 08:10, Dennis Lee Bieber wrote: > ? ? ? ? Of course, if you are describing a /real/ /manual/ typewriter, you > would rapidly discover that the sequence is -- since pushing > the bar would often trigger the line feed before it would slide the > carriage to the right. > > ? ? ? ? But on a teletype, it would be , and maybe a few > for timing -- as the was the slower operation, and would complete > while the other characters were operated upon... Ah, yes you are right :-) The sequence is on a typewriter. Which is why the RETURN button often had the symbol | <----| From highcar at gmail.com Sat Nov 21 06:49:36 2009 From: highcar at gmail.com (elca) Date: Sat, 21 Nov 2009 03:49:36 -0800 (PST) Subject: DOM related question and problem In-Reply-To: <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> References: <26412730.post@talk.nabble.com> <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <26455800.post@talk.nabble.com> Stefan Behnel-3 wrote: > > elca, 18.11.2009 19:04: >> these day im making python script related with DOM. >> >> problem is these day many website structure is very complicate . >> [...] >> what is best method to check can extract such like following info >> quickly? > > This should help: > > http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciated-web-scraping-library/ > > Stefan > -- > http://mail.python.org/mailman/listinfo/python-list > > hello yes..i know this website already. but failed to use it lxml solution -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26455800.html Sent from the Python - python-list mailing list archive at Nabble.com. From lyarmulka at gmail.com Sat Nov 21 07:44:02 2009 From: lyarmulka at gmail.com (someone) Date: Sat, 21 Nov 2009 04:44:02 -0800 (PST) Subject: How do I print to text browser with Qthread? (in PyQt) Message-ID: <9aa71ac7-9ab9-4903-ae23-caf564814b3f@37g2000yqm.googlegroups.com> Hello, I wrote Qthread that gets in the constructor a textBrowser from PyQt application and I tryed to print in this widget text that is updated each 5 seconds (Like application that counts numbers of the text brouser) Is anyone can explain me how to do this? I would glad if you can attach a code example. thanks someone From victorsubervi at gmail.com Sat Nov 21 08:19:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 08:19:52 -0500 Subject: Problem w/ smtplib Message-ID: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Hi; I get the following error: /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py 52 session.sendmail(clientEmail, ourEmail1, header+msg) 53 # session.sendmail(clientEmail, ourEmail2, header+msg) 54 55 mailSpreadsheet() 56 *mailSpreadsheet* = /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet *() 47 order += 'TOTAL: $' + str(total) 48 msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) 49 session = smtplib.SMTP("localhost") 50 session.login(user, passwd) # only if it requires auth 51 header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject session *undefined*, *global* *smtplib* = , smtplib.*SMTP* = /usr/lib64/python2.4/smtplib.py in *__init__*(self=, host='localhost', port=0, local_hostname=None) 242 self.esmtp_features = {} 243 if host: 244 (code, msg) = self.connect(host, port) 245 if code != 220: 246 raise SMTPConnectError(code, msg) code *undefined*, msg *undefined*, *self* = , self.* connect* = >, *host* = 'localhost', *port* = 0 /usr/lib64/python2.4/smtplib.py in *connect*(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* = , self.*getreply* = > /usr/lib64/python2.4/smtplib.py in *getreply*(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) *global* *SMTPServerDisconnected* = * SMTPServerDisconnected*: Connection unexpectedly closed args = ('Connection unexpectedly closed',) Why did this connection close? How do I fix it? I tried commenting out the authentication line. I have imported smtplib. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From aaron.bobby1 at gmail.com Sat Nov 21 08:44:07 2009 From: aaron.bobby1 at gmail.com (Bobby) Date: Sat, 21 Nov 2009 05:44:07 -0800 (PST) Subject: python server developer Message-ID: <1ece1b55-63b7-43dc-a6ca-fbed83062346@u18g2000pro.googlegroups.com> Hello, We are looking for Python server developer location : Hyderabad Experience : 3 years . Send me your updated resume with availability for Telephonic interview From victorsubervi at gmail.com Sat Nov 21 08:47:14 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 08:47:14 -0500 Subject: crontab problem Message-ID: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> Hi; I have the following in crontab -eu root: @daily /usr/local/bin/mysql-backup-daily.sh @weekly /usr/local/bin/mysql-backup-weekly.sh @monthly /usr/local/bin/mysql-backup-monthly.sh [root at 13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-* /usr/local/bin/mysql-daily.sh /usr/local/bin/mysql-monthly.sh /usr/local/bin/mysql-weekly.sh These scripts worked on another server. The daily writes to: /usr/backup/database/mysql-backups/mysql-backup-dailys/ However, a day later, nothing is there. Please advise. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From jebagnanadas at gmail.com Sat Nov 21 08:47:56 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Sat, 21 Nov 2009 19:17:56 +0530 Subject: problem with pyqt.. help please... Message-ID: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> Hi friends, I've recently changed to ubuntu 9.04.. I've not had any problem with the installation of pyqt as it is available from the ubuntu repositories with umpteen number of packages.. Anyhow i've to download tarball file for python 3.1 and installed it.. I found that PyQt4 supports python 3.1(Am i right?).. I wanted to check the pyqt installation with a sample program.. import sys from PyQt4 import QtGui app=QtGui.QApplication(sys.argv) widget=QtGui.QWidget() widget.resize(250,150) widget.setWindowTitle('Simple') widget.show() sys.exit(app.exec_()) when i issued the command $python simple.py it worked perfectly since it's executed with 2.6 installation.. But when i tried to execute it with $python3 simple.py it showed the error like ImportError: No module named PyQt4 So i searched the sys.path for 2.6 and included /usr/lib/python2.6/dist-packages in python3 sys.path... Now when i tried to run this with python3 the error is like.. ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined symbol: PyString_FromString I got the same error when i tried to execute another program... So can u please tell me how to solve this problem?? Am i heading in the right direction???... Thanks & Regards... Jebagnanadas, Python Learner.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 21 08:59:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 Nov 2009 05:59:04 -0800 Subject: crontab problem In-Reply-To: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> References: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> Message-ID: <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> On Sat, Nov 21, 2009 at 5:47 AM, Victor Subervi wrote: > Hi; > I have the following in crontab -eu root: > @daily /usr/local/bin/mysql-backup-daily.sh > @weekly /usr/local/bin/mysql-backup-weekly.sh > @monthly /usr/local/bin/mysql-backup-monthly.sh > > [root at 13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-* > /usr/local/bin/mysql-daily.sh? /usr/local/bin/mysql-monthly.sh > /usr/local/bin/mysql-weekly.sh > > These scripts worked on another server. The daily writes to: > /usr/backup/database/mysql-backups/mysql-backup-dailys/ > However, a day later, nothing is there. Please advise. And this is germane to Python (and not instead say, *nix) how exactly? Cheers, Chris -- http://blog.rebertia.com From benjamin.kaplan at case.edu Sat Nov 21 09:05:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 21 Nov 2009 09:05:00 -0500 Subject: problem with pyqt.. help please... In-Reply-To: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> References: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> Message-ID: On Sat, Nov 21, 2009 at 8:47 AM, Jebagnana Das wrote: > Hi friends, > I've recently changed to ubuntu 9.04.. I've not had any > problem with the installation of pyqt as it is available from the ubuntu > repositories with umpteen number of packages.. Anyhow i've to download > tarball file for python 3.1 and installed it.. I found that PyQt4 supports > python 3.1(Am i right?).. > > I wanted to check the pyqt installation with a sample program.. > > import sys > from PyQt4 import QtGui > app=QtGui.QApplication(sys.argv) > widget=QtGui.QWidget() > widget.resize(250,150) > widget.setWindowTitle('Simple') > widget.show() > sys.exit(app.exec_()) > > when i issued the command > $python simple.py > it worked perfectly since it's executed with 2.6 installation.. > But when i tried to execute it with > $python3 simple.py > it showed the error like > ImportError: No module named PyQt4 > So i searched the sys.path for 2.6 and included > /usr/lib/python2.6/dist-packages > in python3 sys.path... > Now when i tried to run this with python3 the error is like.. > ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined > symbol: PyString_FromString > I got the same error when i tried to execute another program... So can u > please tell me how to solve this problem?? Am i heading in the right > direction???... > > Thanks & Regards... > > Jebagnanadas, > Python Learner.. > > As a general rule, never add packages that were installed for another version of Python . There are inconsistencies between versions, so the C libraries (like PyQT) always need to be recompiled. This is especially true between Python 2.x and Python 3.x, where there were some fundamental changes to the language. If you want to use PyQT on Python 3, download it and compile it yourself. > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 09:08:34 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 09:08:34 -0500 Subject: crontab problem In-Reply-To: <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> References: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> Message-ID: <4dc0cfea0911210608o32f933c7gb8b5165c92ce94e8@mail.gmail.com> On Sat, Nov 21, 2009 at 8:59 AM, Chris Rebert wrote: > > And this is germane to Python (and not instead say, *nix) how exactly? > Oops! Wrong list! -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 09:27:21 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 09:27:21 -0500 Subject: Too Many Values To Unpack In-Reply-To: References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> Message-ID: <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber wrote: > And my follow-up to that original thread stated that it /was/ > pseudo-code, not something tested. My goal was to illustrate the > general concepts of processing a recursive/nested data set stored in a > flat/relational table. > Of course and appreciated. > > "expand()" was responsible for taking each "key" from a select query > and creating an empty dictionary with that "key" as, well, key. Then the > recursive operation would perform a select query used to populate the > empty dictionary, ad infinitum. > Here is the output with just one test category: {'cat1': {}} Here is the code to which that output is fed: def getChildren(levelDict, level = 0): MAXLEVEL = 7 if level > MAXLEVEL: return #possibly the data has a cycle/loop for (nm, dt) in levelDict: cursor.execute('''select c.name from categories as c inner join relationship as r on c.ID = r.Child inner join categories as p on r.Parent = p.ID where p.category = %s order by c.name''', (nm,)) levelDict[nm] = expand(cursor.fetchall()) # recursive call to do next level getChildren(levelDict[nm], level + 1) # no data return as we are mutating dictionaries in place When this script is called from another script, the python interpreter throws the following error: Traceback (most recent call last): File "createCats.py", line 8, in ? from catTree import catTree File "/var/www/html/angrynates.com/cart/catTree.py", line 85, in ? catTree() File "/var/www/html/angrynates.com/cart/catTree.py", line 76, in catTree getChildren(theTree) File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in getChildren for (nm, dt) in levelDict: ValueError: too many values to unpack Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From joost at h-labahn.de Sat Nov 21 11:21:26 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 21 Nov 2009 08:21:26 -0800 (PST) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> Message-ID: <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Sorry, i have no idea what scrapy is - but i see, that you try to use idle with pipes or anything like that. That cannot work. idle doesn't even handle __file__ correctly. Use a full-fledged python IDE (PyDev under Eclipse leaves very few wishes open) or test in a python interpreter shell. Good luck, DreiJane From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat Nov 21 11:49:52 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 21 Nov 2009 16:49:52 +0000 (UTC) Subject: python server developer References: <1ece1b55-63b7-43dc-a6ca-fbed83062346@u18g2000pro.googlegroups.com> Message-ID: Bobby wrote: > Hello, > We are looking for Python server developer > location : Hyderabad > Experience : 3 years . > Send me your updated resume with availability for Telephonic interview Hyderabad, India or Hyderabad, Pakistan? (no, I am not going to apply in either case, even if I think I do qualify - I already have a nice, reasonably python related job). -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From kevin.p.dwyer at gmail.com Sat Nov 21 12:04:32 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 21 Nov 2009 17:04:32 +0000 (UTC) Subject: Problem w/ smtplib References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Message-ID: On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: Hello Victor, The information that you have sent comes from the client side of the transaction, so it isn't possible to tell why the server disconnected. Assuming that there is an SMTP server listening on port 25, you need to check the SMTP server logs. You might need to crank up the logging to get useful output. If the information that you pasted in comes from a Django traceback then you could check the Django page on e-mail at http://docs.djangoproject.com/en/dev/topics/email/#topics-email (dev version, you might need to view an older version). Cheers, Kev From victorsubervi at gmail.com Sat Nov 21 12:27:26 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 12:27:26 -0500 Subject: Problem w/ smtplib In-Reply-To: References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Message-ID: <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: > On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: > > Hello Victor, > > The information that you have sent comes from the client side of the > transaction, so it isn't possible to tell why the server disconnected. > Assuming that there is an SMTP server listening on port 25, you need to > check the SMTP server logs. There wasn't anything in /var/log/maillog. Is that where I should have checked? > You might need to crank up the logging to > get useful output. > How? Look at the output below: [root at 13gems stcroixresort]# netstat -tulp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 *:mysql *:* LISTEN 24488/mysqld tcp 0 0 *:pop3 *:* LISTEN 5278/tcpserver tcp 0 0 *:ftp *:* LISTEN 26564/vsftpd tcp 0 0 localhost.localdomai:domain *:* LISTEN 11845/named tcp 0 0 *:smtp *:* LISTEN 5274/tcpserver tcp 0 0 localhost.localdomain:rndc *:* LISTEN 11845/named tcp 0 0 *:http *:* LISTEN 5201/httpd tcp 0 0 localhost:domain *:* LISTEN 11845/named tcp 0 0 *:ssh *:* LISTEN 15509/sshd tcp 0 0 localhost:rndc *:* LISTEN 11845/named udp 0 0 localhost.locald:domain *:* 11845/named udp 0 0 localhost:domain *:* 11845/named [root at 13gems stcroixresort]# qmailctl stat /service/qmail-send: up (pid 5266) 594565 seconds /service/qmail-send/log: up (pid 5271) 594565 seconds /service/qmail-smtpd: up (pid 5274) 594565 seconds /service/qmail-smtpd/log: up (pid 5276) 594565 seconds /service/qmail-pop3d: up (pid 5278) 594565 seconds /service/qmail-pop3d/log: up (pid 5279) 594565 seconds messages in queue: 0 messages in queue but not yet preprocessed: 0 Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sat Nov 21 13:16:52 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 21 Nov 2009 18:16:52 +0000 Subject: Problem w/ smtplib In-Reply-To: <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> Message-ID: <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> 2009/11/21 Victor Subervi > On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: > >> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: >> >> Hello Victor, >> >> The information that you have sent comes from the client side of the >> transaction, so it isn't possible to tell why the server disconnected. >> Assuming that there is an SMTP server listening on port 25, you need to >> check the SMTP server logs. > > > There wasn't anything in /var/log/maillog. Is that where I should have > checked? > > >> You might need to crank up the logging to >> get useful output. >> > > How? > Look at the output below: > > [root at 13gems stcroixresort]# netstat -tulp > Active Internet connections (only servers) > Proto Recv-Q Send-Q Local Address Foreign Address > State PID/Program name > tcp 0 0 *:mysql *:* > LISTEN 24488/mysqld > tcp 0 0 *:pop3 *:* > LISTEN 5278/tcpserver > tcp 0 0 *:ftp *:* > LISTEN 26564/vsftpd > tcp 0 0 localhost.localdomai:domain *:* > LISTEN 11845/named > tcp 0 0 *:smtp *:* > LISTEN 5274/tcpserver > tcp 0 0 localhost.localdomain:rndc *:* > LISTEN 11845/named > tcp 0 0 *:http *:* > LISTEN 5201/httpd > tcp 0 0 localhost:domain *:* > LISTEN 11845/named > tcp 0 0 *:ssh *:* > LISTEN 15509/sshd > tcp 0 0 localhost:rndc *:* > LISTEN 11845/named > udp 0 0 localhost.locald:domain > *:* 11845/named > udp 0 0 localhost:domain > *:* 11845/named > [root at 13gems stcroixresort]# qmailctl stat > /service/qmail-send: up (pid 5266) 594565 seconds > /service/qmail-send/log: up (pid 5271) 594565 seconds > /service/qmail-smtpd: up (pid 5274) 594565 seconds > /service/qmail-smtpd/log: up (pid 5276) 594565 seconds > /service/qmail-pop3d: up (pid 5278) 594565 seconds > /service/qmail-pop3d/log: up (pid 5279) 594565 seconds > messages in queue: 0 > messages in queue but not yet preprocessed: 0 > > Please advise. > TIA, > V > Hello Victor, I'm afraid I don't know much about mail servers, you need to check the server docs or ask on a qmail mailing list. If you really think this is a python issue, then you could try: >>> import smtplib >>> server = smtplib.SMTP() >>> server.set_debuglevel(1) >>> server.connect() connect: ('localhost', 25) connect: (25, 'localhost') reply: '220 pluto.site ESMTP Postfix\r\n' reply: retcode (220); Msg: pluto.site ESMTP Postfix connect: pluto.site ESMTP Postfix (220, 'pluto.site ESMTP Postfix') >>> server.quit() send: 'quit\r\n' reply: '221 2.0.0 Bye\r\n' reply: retcode (221); Msg: 2.0.0 Bye (221, '2.0.0 Bye') and see if there are any error messages/tracebacks in the output; but if you still get a disconnect exception then it's unlikely that this is a python issue. Cheers, Kev -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 13:59:13 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 13:59:13 -0500 Subject: Problem w/ smtplib In-Reply-To: <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> Message-ID: <4dc0cfea0911211059h787b5815oecc90c1d1fe561f@mail.gmail.com> On Sat, Nov 21, 2009 at 1:16 PM, Kev Dwyer wrote: > > 2009/11/21 Victor Subervi > > On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: >> >>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: >>> >>> Hello Victor, >>> >>> The information that you have sent comes from the client side of the >>> transaction, so it isn't possible to tell why the server disconnected. >>> Assuming that there is an SMTP server listening on port 25, you need to >>> check the SMTP server logs. >> >> >> There wasn't anything in /var/log/maillog. Is that where I should have >> checked? >> >> >>> You might need to crank up the logging to >>> get useful output. >>> >> >> How? >> Look at the output below: >> >> [root at 13gems stcroixresort]# netstat -tulp >> Active Internet connections (only servers) >> Proto Recv-Q Send-Q Local Address Foreign >> Address State PID/Program name >> tcp 0 0 *:mysql >> *:* LISTEN 24488/mysqld >> tcp 0 0 *:pop3 >> *:* LISTEN 5278/tcpserver >> tcp 0 0 *:ftp >> *:* LISTEN 26564/vsftpd >> tcp 0 0 localhost.localdomai:domain >> *:* LISTEN 11845/named >> tcp 0 0 *:smtp >> *:* LISTEN 5274/tcpserver >> tcp 0 0 localhost.localdomain:rndc >> *:* LISTEN 11845/named >> tcp 0 0 *:http >> *:* LISTEN 5201/httpd >> tcp 0 0 localhost:domain >> *:* LISTEN 11845/named >> tcp 0 0 *:ssh >> *:* LISTEN 15509/sshd >> tcp 0 0 localhost:rndc >> *:* LISTEN 11845/named >> udp 0 0 localhost.locald:domain >> *:* 11845/named >> udp 0 0 localhost:domain >> *:* 11845/named >> [root at 13gems stcroixresort]# qmailctl stat >> /service/qmail-send: up (pid 5266) 594565 seconds >> /service/qmail-send/log: up (pid 5271) 594565 seconds >> /service/qmail-smtpd: up (pid 5274) 594565 seconds >> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds >> /service/qmail-pop3d: up (pid 5278) 594565 seconds >> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds >> messages in queue: 0 >> messages in queue but not yet preprocessed: 0 >> >> Please advise. >> TIA, >> V >> > > Hello Victor, > > I'm afraid I don't know much about mail servers, you need to check the > server docs or ask on a qmail mailing list. > > If you really think this is a python issue, then you could try: > >>> import smtplib > >>> server = smtplib.SMTP() > >>> server.set_debuglevel(1) > >>> server.connect() > connect: ('localhost', 25) > connect: (25, 'localhost') > reply: '220 pluto.site ESMTP Postfix\r\n' > reply: retcode (220); Msg: pluto.site ESMTP Postfix > connect: pluto.site ESMTP Postfix > (220, 'pluto.site ESMTP Postfix') > >>> server.quit() > send: 'quit\r\n' > reply: '221 2.0.0 Bye\r\n' > reply: retcode (221); Msg: 2.0.0 Bye > (221, '2.0.0 Bye') > > > and see if there are any error messages/tracebacks in the output; but if > you still get a disconnect exception then it's unlikely that this is a > python issue. > Thank you. Yes, there was an error. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From azeynel1 at gmail.com Sat Nov 21 14:00:58 2009 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 21 Nov 2009 11:00:58 -0800 (PST) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Message-ID: Now I use EditpadPro and IDLE which appears to be adequate for beginning level. But PyDev looks fun, I'll try it. By the way, I realized that the spider sends the scraped data to the pipelines.py. Now everything is working. On Nov 21, 11:21?am, DreiJane wrote: > Sorry, > > i have no idea what scrapy is - but i see, that you try to use > idle with pipes or anything like that. That cannot work. > idle doesn't even handle __file__ correctly. Use a full-fledged > python IDE (PyDev under Eclipse leaves very few wishes open) or > test in a python interpreter shell. > > Good luck, DreiJane From mrholtsr at sbcglobal.net Sat Nov 21 14:10:20 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sat, 21 Nov 2009 14:10:20 -0500 Subject: pythonpath Message-ID: Is there a way to make python point to a different directory for modules. I don't like to keep my modules in the program directory, but I can't figure out from the shell how to get the program to look in another directory. I am using XP Pro as an operating system and python2.6 -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Sat Nov 21 14:10:47 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sat, 21 Nov 2009 19:10:47 +0000 (UTC) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Message-ID: > i have no idea what scrapy is > .... http://scrapy.org/ Scrapy is a fast high-level screen scraping and web crawling framework, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from data mining to monitoring and automated testing. Also, previously unknown to me before google-izing .... -- Stanley C. Kitching Human Being Phoenix, Arizona From dadapapa at googlemail.com Sat Nov 21 14:19:02 2009 From: dadapapa at googlemail.com (Harold Fellermann) Date: Sat, 21 Nov 2009 11:19:02 -0800 (PST) Subject: Problem combining Scientific (leastSquaresFit) and scipy (odeint) Message-ID: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> Hi, I need to perform leastSquaresFit of a model that is given by a differential equation for which there seems to be no analytic solution. So, I am trying to solve the ODE numerically (using scipy.integrate.odeint) within the function I provide to leastSquaresFit as a model: def func(L, t, a, k) : return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.) def model((k, L0, a), t) : solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) ) return L0 - solution[1][0] params, chisq = leastSquaresFit(model, params, data) Unfortunately, this approach runs into an error (ValueError: shape mismatch: objects cannot be broadcast to a single shape) that seems to stem from the fact that leastSquaresFit is based on automatic derivation (DerivVar), and according to the manual "the function [that defines the model] may only use the mathematical functions known to the module FirstDerivatives". What is a good solution or workaround to this problem which appears to be quite a standard situation to me? Thanks for any help, harold. From johnroth1 at gmail.com Sat Nov 21 14:20:51 2009 From: johnroth1 at gmail.com (John Roth) Date: Sat, 21 Nov 2009 11:20:51 -0800 (PST) Subject: Go versus Brand X References: Message-ID: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> On Nov 21, 8:40?am, Duncan Booth wrote: > a... at pythoncraft.com (Aahz) wrote: > > Comparing Go to another computer language -- do you recognize it? > > >http://www.cowlark.com/2009-11-15-go/ > > Yes, spotted it at the first 'fi'. This isn't the first time anyone has criticized Go. The interesting, and somewhat sad, thing is that the entire mess can be explained very easily by looking at the beginning of the language design FAQ on the Go web site. See if you recognize the names of the principle people who designed it. Yep. Go is simply C with most (but not all) of the warts removed and some more modern features added. Brought to you by the same people who brought you C and Unix all those years ago. The use of the Plan 9 toolchain is not a coincidence. John Roth From nobody at nowhere.com Sat Nov 21 14:22:36 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 21 Nov 2009 19:22:36 +0000 Subject: python simply not scaleable enough for google? References: Message-ID: On Fri, 20 Nov 2009 09:51:49 -0800, sturlamolden wrote: > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. POSIX.1-2001 and POSIX.1-2004 have makecontext(), setcontext(), getcontext() and swapcontext(), but obsoleted by POSIX.1-2008. They are available on Linux; I don't know about other Unices. From nobody at nowhere.com Sat Nov 21 14:44:39 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 21 Nov 2009 19:44:39 +0000 Subject: Go versus Brand X References: Message-ID: On Fri, 20 Nov 2009 17:12:36 -0800, Aahz wrote: > Comparing Go to another computer language -- do you recognize it? "Here is a language so far ahead of its time that it was not only an improvement on its predecessors but also on nearly all its successors." - C. A. R. Hoare (although he was actually referring to ALGOL-60). From yota.news at gmail.com Sat Nov 21 14:44:57 2009 From: yota.news at gmail.com (yota.news at gmail.com) Date: Sat, 21 Nov 2009 11:44:57 -0800 (PST) Subject: memoize again Message-ID: I spent a lot of time looking for tips on how to properly write cache / memoize function. Testing, merging and fixing contributed but half finished pieces of code. Here is the summary of what I learned through a clean example, might it be useful for beginners. #!/usr/bin/env python3.1 (should work in python 2.5) def dcache(function) : """ simple, dict based cache """ return memoize(function, cache={}) def ccache(cache = {}): """ with dict-like custom cache. Can be any class with at least __contains__, __setitem__ and __getitem__ methods """ def xcache(function): return memoize(function, cache=cache) return xcache class memoize(object): def __init__(self, function, cache): self.function=function self.cache=cache def __get__(self, instance, cls=None): self.instance = instance return self def __call__(self, *args): if args not in self.cache: self.cache[args] = self.function(self.instance, *args) return self.cache[args] which can be used as this: - with the custom cache @ccache(cache=customCache()) def compute(self, alpha, beta): return alpha + beta - or with a default dict() cache @dcache def compute(self, alpha, beta): return alpha + beta Each time compute() is called, the memoize decorator looks first into the cache for a value whose key is the *args tuple. The full content of the cache can be acessed as compute.cache. ~? From rnichols at mightyheave.com Sat Nov 21 15:49:23 2009 From: rnichols at mightyheave.com (rnichols at mightyheave.com) Date: Sat, 21 Nov 2009 14:49:23 -0600 (CST) Subject: How do I create a vanilla object in C? Message-ID: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> I need to create a vanilla object in C, something I can do PyObject_SetAttr on. Obviously, I do something somewhat like this every time I create a minimal python class. I need to know how to do this in C though. From bnrj.rudra at gmail.com Sat Nov 21 16:24:24 2009 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 21 Nov 2009 13:24:24 -0800 (PST) Subject: plotting arrow in python Message-ID: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Dear friends, I am very new in python. Actually, I think I will not do much python then using it to plotting data. I have not done any "real" thing in python, so plz be easy. Now , the problem I have a data set: 0.0 0.0 0.1 0.0 0.1 0.1 0.1 0.0 0.5 like that! the first two column are coordinate and 3rd one is magnitude of moment (say: x y,m)!! so what i want to do is draw an arrow of magnitude(m) in the position (x,y). I know how python read array, and how to draw an array(via matplotlib)...but totally confused with this one. can you people plz help? From carsten.haese at gmail.com Sat Nov 21 16:41:04 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sat, 21 Nov 2009 16:41:04 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: Victor Subervi wrote: > File "/var/www/html/angrynates.com/cart/catTree.py > ", line 25, in getChildren > for (nm, dt) in levelDict: > ValueError: too many values to unpack > > Please advise. I already explained what's causing this error. Read my first response on this thread. (http://mail.python.org/pipermail/python-list/2009-November/1227008.html) -- Carsten Haese http://informixdb.sourceforge.net From mmanns at gmx.net Sat Nov 21 17:39:29 2009 From: mmanns at gmx.net (Martin Manns) Date: Sat, 21 Nov 2009 23:39:29 +0100 Subject: pyspread 0.0.12a released Message-ID: Pyspread is getting close to the first Beta. This new release should work with Windows as well as with Linux. About ----- Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Pyspread runs on Linux, Windows and *nix platforms with GTK+ support. I have reports that it works with MacOS X as well. Homepage -------- http://pyspread.sf.net New features in 0.0.12a ----------------------- * pys file support more secure * ODF file support removed * Left and right alignment to cell attributes added * Custom grid & cell drawing on refresh added * Save functionality for row and column size added * Problem with update of cells that contain strings, lists solved * Frozen cells toolbar update fixed * Windows missing cell background bug removed Martin From acangiano at gmail.com Sat Nov 21 17:53:53 2009 From: acangiano at gmail.com (Antonio Cangiano) Date: Sat, 21 Nov 2009 14:53:53 -0800 (PST) Subject: Are you happy with the current web deployment options? Message-ID: Phusion is a Dutch company that vastly improved the status quo of Ruby and Rails deployment through their open source module for Apache and nginx. Now they are publicly asking whether Pythonistas would be interested in a similar solution for Python (and Django of course). Not many Pythonistas read their Ruby-oriented blog, so I thought I'd share the link here: http://izumi.plan99.net/blog/index.php/2009/11/21/phusion-passenger-for-python/ Cheers, Antonio -- http://ThinkCode.TV - High-quality programming screencasts http://antoniocangiano.com - Zen and the Art of Programming Follow me on Twitter: http://twitter.com/acangiano Author of "Ruby on Rails for Microsoft Developers" (Wrox, 2009) From stef.mientki at gmail.com Sat Nov 21 18:19:55 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 22 Nov 2009 00:19:55 +0100 Subject: plotting arrow in python In-Reply-To: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <4B08759B.90109@gmail.com> rudra wrote: > Dear friends, > I am very new in python. Actually, I think I will not do much python > then using it to plotting data. I have not done any "real" thing in > python, so plz be easy. Now , the problem > I have a data set: > 0.0 0.0 0.1 > 0.0 0.1 0.1 > 0.1 0.0 0.5 > > like that! the first two column are coordinate and 3rd one is > magnitude of moment (say: x y,m)!! so what i want to do is draw an > arrow of magnitude(m) in the position (x,y). > I know how python read array, and how to draw an array(via > matplotlib)...but totally confused with this one. > can you people plz help? > maybe take a look at VPython cheers, Stef From cjwilliams43 at gmail.com Sat Nov 21 18:22:48 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sat, 21 Nov 2009 18:22:48 -0500 Subject: Problem combining Scientific (leastSquaresFit) and scipy (odeint) In-Reply-To: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> References: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> Message-ID: Harold Fellermann wrote: > Hi, > > I need to perform leastSquaresFit of a model that is given by a > differential equation for which there seems to be no analytic > solution. So, I am trying to solve the ODE numerically (using > scipy.integrate.odeint) within the function I provide to > leastSquaresFit as a model: > > def func(L, t, a, k) : > return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.) > > def model((k, L0, a), t) : > solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) ) > return L0 - solution[1][0] > > params, chisq = leastSquaresFit(model, params, data) > > Unfortunately, this approach runs into an error (ValueError: shape > mismatch: objects cannot be broadcast to a single shape) that seems to > stem from the fact that leastSquaresFit is based on automatic > derivation (DerivVar), and according to the manual "the function [that > defines the model] may only use the mathematical functions known to > the module FirstDerivatives". > > What is a good solution or workaround to this problem which appears to > be quite a standard situation to me? > > Thanks for any help, harold. You might consider using numpy. Colin W. From showell30 at yahoo.com Sat Nov 21 18:23:26 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 15:23:26 -0800 (PST) Subject: parallel class structures for AST-based objects Message-ID: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> I have been writing some code that parses a mini-language, and I am running into what I know is a pretty common design pattern problem, but I am wondering the most Pythonic way to solve it. Basically, I have a bunch of really simple classes that work together to define an expression--in my oversimplified example code below, those are Integer, Sum, and Product. Then I want to write different modules that work with those expression objects. In my example, I have a parallel set of classes that enable you to evaluate an expression, and another set of objects that enable you to pretty-print the expression. The below code works as intended so far (tested under 2.6), but before I go too much further with this design, I want to get a sanity check and some ideas on other ways to represent the interrelationships within the code. Basically, the issue here is that you have varying behavior in two dimensions--a node right now is only a Product/Integer/ Sum so far, but I might want to introduce new concepts like Difference, Quotient, etc. And right now the only things that you can do to expressions is eval() them and pprint() them, but you eventually might want to operate on the expressions in new ways, including fairly abstract operations that go beyond a simple walking of the tree. Here is the code: ####### # base classes just represents the expression itself, which # get created by a parser or unit tests # example usage is # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) class Integer: def __init__(self, val): self.val = val class BinaryOp: def __init__(self, a,b): self.a = a self.b = b class Sum(BinaryOp): pass class Product(BinaryOp): pass ######## class EvalNode: def __init__(self, node): self.node = node def evaluatechild(self, child): return EvalNode.factory(child).eval() @staticmethod def factory(child): mapper = { 'Sum': SumEvalNode, 'Product': ProductEvalNode, 'Integer': IntegerEvalNode } return abstract_factory(child, mapper) class SumEvalNode(EvalNode): def eval(self): a = self.evaluatechild(self.node.a) b = self.evaluatechild(self.node.b) return a + b class ProductEvalNode(EvalNode): def eval(self): a = self.evaluatechild(self.node.a) b = self.evaluatechild(self.node.b) return a * b class IntegerEvalNode(EvalNode): def eval(self): return self.node.val ####### class PrettyPrintNode: def __init__(self, node): self.node = node def pprint_child(self, child): return PrettyPrintNode.factory(child).pprint() @staticmethod def factory(child): mapper = { 'Sum': SumPrettyPrintNode, 'Product': ProductPrettyPrintNode, 'Integer': IntegerPrettyPrintNode } return abstract_factory(child, mapper) class SumPrettyPrintNode(PrettyPrintNode): def pprint(self): a = self.pprint_child(self.node.a) b = self.pprint_child(self.node.b) return '(the sum of %s and %s)' % (a, b) class ProductPrettyPrintNode(PrettyPrintNode): def pprint(self): a = self.pprint_child(self.node.a) b = self.pprint_child(self.node.b) return '(the product of %s and %s)' % (a, b) class IntegerPrettyPrintNode(PrettyPrintNode): def pprint(self): return self.node.val ############## # Not sure where this method really "wants to be" structurally, # or what it should be named, but it reduces some duplication def abstract_factory(node, node_class_mapper): return node_class_mapper[node.__class__.__name__](node) expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) evaluator = EvalNode.factory(expression) print evaluator.eval() pprinter = PrettyPrintNode.factory(expression) print pprinter.pprint() From tjreedy at udel.edu Sat Nov 21 18:24:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 Nov 2009 18:24:19 -0500 Subject: ANN: PyGUI Mailing List In-Reply-To: References: Message-ID: Gregory Ewing wrote: > There is now a mailing list for discussion of PyGUI: > > http://mail.python.org/mailman/listinfo/pygui Having it mirrored to news.gmane,org, if you have not yet, like other python.org lists, would make it easier to follow or join. Perhaps it will happen automatically, I do not know. From python at mrabarnett.plus.com Sat Nov 21 19:07:05 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 00:07:05 +0000 Subject: parallel class structures for AST-based objects In-Reply-To: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <4B0880A9.4080101@mrabarnett.plus.com> Steve Howell wrote: > I have been writing some code that parses a mini-language, and I am > running into what I know is a pretty common design pattern problem, > but I am wondering the most Pythonic way to solve it. > > Basically, I have a bunch of really simple classes that work together > to define an expression--in my oversimplified example code below, > those are Integer, Sum, and Product. > > Then I want to write different modules that work with those expression > objects. In my example, I have a parallel set of classes that enable > you to evaluate an expression, and another set of objects that enable > you to pretty-print the expression. > > The below code works as intended so far (tested under 2.6), but before > I go too much further with this design, I want to get a sanity check > and some ideas on other ways to represent the interrelationships > within the code. Basically, the issue here is that you have varying > behavior in two dimensions--a node right now is only a Product/Integer/ > Sum so far, but I might want to introduce new concepts like > Difference, Quotient, etc. And right now the only things that you can > do to expressions is eval() them and pprint() them, but you eventually > might want to operate on the expressions in new ways, including fairly > abstract operations that go beyond a simple walking of the tree. > > Here is the code: > > ####### > # base classes just represents the expression itself, which > # get created by a parser or unit tests > # example usage is > # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > class Integer: > def __init__(self, val): > self.val = val > > class BinaryOp: > def __init__(self, a,b): > self.a = a > self.b = b > > class Sum(BinaryOp): > pass > > class Product(BinaryOp): > pass > > ######## > > class EvalNode: > def __init__(self, node): > self.node = node > > def evaluatechild(self, child): > return EvalNode.factory(child).eval() > > @staticmethod > def factory(child): > mapper = { > 'Sum': SumEvalNode, > 'Product': ProductEvalNode, > 'Integer': IntegerEvalNode > } > return abstract_factory(child, mapper) > > class SumEvalNode(EvalNode): > def eval(self): > a = self.evaluatechild(self.node.a) > b = self.evaluatechild(self.node.b) > return a + b > > class ProductEvalNode(EvalNode): > def eval(self): > a = self.evaluatechild(self.node.a) > b = self.evaluatechild(self.node.b) > return a * b > > class IntegerEvalNode(EvalNode): > def eval(self): return self.node.val > > ####### > > class PrettyPrintNode: > def __init__(self, node): > self.node = node > > def pprint_child(self, child): > return PrettyPrintNode.factory(child).pprint() > > @staticmethod > def factory(child): > mapper = { > 'Sum': SumPrettyPrintNode, > 'Product': ProductPrettyPrintNode, > 'Integer': IntegerPrettyPrintNode > } > return abstract_factory(child, mapper) > > class SumPrettyPrintNode(PrettyPrintNode): > def pprint(self): > a = self.pprint_child(self.node.a) > b = self.pprint_child(self.node.b) > return '(the sum of %s and %s)' % (a, b) > > class ProductPrettyPrintNode(PrettyPrintNode): > def pprint(self): > a = self.pprint_child(self.node.a) > b = self.pprint_child(self.node.b) > return '(the product of %s and %s)' % (a, b) > > class IntegerPrettyPrintNode(PrettyPrintNode): > def pprint(self): return self.node.val > > ############## > # Not sure where this method really "wants to be" structurally, > # or what it should be named, but it reduces some duplication > > def abstract_factory(node, node_class_mapper): > return node_class_mapper[node.__class__.__name__](node) > > > expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > evaluator = EvalNode.factory(expression) > print evaluator.eval() > > pprinter = PrettyPrintNode.factory(expression) > print pprinter.pprint() I don't see the point of EvalNode and PrettyPrintNode. Why don't you just give Integer, Sum and Product 'eval' and 'pprint' methods? From showell30 at yahoo.com Sat Nov 21 19:11:36 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 16:11:36 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: On Nov 21, 11:20?am, John Roth wrote: > On Nov 21, 8:40?am, Duncan Booth wrote: > > > a... at pythoncraft.com (Aahz) wrote: > > > Comparing Go to another computer language -- do you recognize it? > > > >http://www.cowlark.com/2009-11-15-go/ > > > Yes, spotted it at the first 'fi'. > > This isn't the first time anyone has criticized Go. The interesting, > and somewhat sad, thing is that the entire mess can be explained > very easily by looking at the beginning of the language design > FAQ on the Go web site. See if you recognize the names of the > principle people who designed it. > > Yep. Go is simply C with most (but not all) of the warts > removed and some more modern features added. Brought to you > by the same people who brought you C and Unix all those years ago. > The use of the Plan 9 toolchain is not a coincidence. > The assertion that Go is simply C with warts removed and modern features added is not surprising. If you read the Go FAQ, you will see that there is no claim anywhere that they are trying to solve the problem that 40 years of language development since Algol has not produced super-sexy quantum leaps of improvement. Instead, they are trying to solve the problem that in the last ten years, there haven not seen ANY improvement in systems programming languages ("No major systems language has emerged in over a decade"). The critics of Go probably fall into four categories: 1) Some do not understand the goals of the Go project itself, so they are criticizing Go for not solving problems that were never in Go's bailiwick to begin with. 2) Some believe that Go does not deliver on its goal to modernize systems programming languages. 3) Some do not accept the premise that there has been no progress outside of Go in the last ten years with regards to systems programming languages, and they are wondering why Google invented Go instead of embracing other technologies. 4) Some people do not even believe that the problem is important--do we actually need a modern systems programming language, or do we just need modern programming languages to perform well under all circumstances, or at least be adaptable? My list probably isn't even nearly exhaustive. From showell30 at yahoo.com Sat Nov 21 19:18:47 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 16:18:47 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> On Nov 21, 4:07?pm, MRAB wrote: > > I don't see the point of EvalNode and PrettyPrintNode. Why don't you > just give Integer, Sum and Product 'eval' and 'pprint' methods? That's a good question, and it's the crux of my design dilemma. If ALL I ever wanted to to with Integer/Sum/Product was to eval() and pprint(), then I would just add those methods to Integer, Sum, and Product, and be done with it, as you suggest. But what happens when somebody wants to extend capability? Should every future software developer that wants to use Integer/Sum/Product extend those classes to get work done? What if they want to store additional state for nodes? From fetchinson at googlemail.com Sat Nov 21 19:21:47 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 22 Nov 2009 01:21:47 +0100 Subject: How do I create a vanilla object in C? In-Reply-To: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> References: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> Message-ID: > I need to create a vanilla object in C, something I can do > PyObject_SetAttr on. Obviously, I do something somewhat like this every > time I create a minimal python class. I need to know how to do this in C > though. Please see http://docs.python.org/extending/index.html http://docs.python.org/c-api/index.html http://docs.python.org/c-api/object.html HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chardster at gmail.com Sat Nov 21 19:33:28 2009 From: chardster at gmail.com (Richard Thomas) Date: Sat, 21 Nov 2009 16:33:28 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> On 22 Nov, 00:07, MRAB wrote: > Steve Howell wrote: > > I have been writing some code that parses a mini-language, and I am > > running into what I know is a pretty common design pattern problem, > > but I am wondering the most Pythonic way to solve it. > > > Basically, I have a bunch of really simple classes that work together > > to define an expression--in my oversimplified example code below, > > those are Integer, Sum, and Product. > > > Then I want to write different modules that work with those expression > > objects. ?In my example, I have a parallel set of classes that enable > > you to evaluate an expression, and another set of objects that enable > > you to pretty-print the expression. > > > The below code works as intended so far (tested under 2.6), but before > > I go too much further with this design, I want to get a sanity check > > and some ideas on other ways to represent the interrelationships > > within the code. ?Basically, the issue here is that you have varying > > behavior in two dimensions--a node right now is only a Product/Integer/ > > Sum so far, but I might want to introduce new concepts like > > Difference, Quotient, etc. ?And right now the only things that you can > > do to expressions is eval() them and pprint() them, but you eventually > > might want to operate on the expressions in new ways, including fairly > > abstract operations that go beyond a simple walking of the tree. > > > Here is the code: > > > ? ? ####### > > ? ? # base classes just represents the expression itself, which > > ? ? # get created by a parser or unit tests > > ? ? # example usage is > > ? ? # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > ? ? class Integer: > > ? ? ? ? def __init__(self, val): > > ? ? ? ? ? ? self.val = val > > > ? ? class BinaryOp: > > ? ? ? ? def __init__(self, a,b): > > ? ? ? ? ? ? self.a = a > > ? ? ? ? ? ? self.b = b > > > ? ? class Sum(BinaryOp): > > ? ? ? ? pass > > > ? ? class Product(BinaryOp): > > ? ? ? ? pass > > > ? ? ######## > > > ? ? class EvalNode: > > ? ? ? ? def __init__(self, node): > > ? ? ? ? ? ? self.node = node > > > ? ? ? ? def evaluatechild(self, child): > > ? ? ? ? ? ? return EvalNode.factory(child).eval() > > > ? ? ? ? @staticmethod > > ? ? ? ? def factory(child): > > ? ? ? ? ? ? mapper = { > > ? ? ? ? ? ? ? ? 'Sum': SumEvalNode, > > ? ? ? ? ? ? ? ? 'Product': ProductEvalNode, > > ? ? ? ? ? ? ? ? 'Integer': IntegerEvalNode > > ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? return abstract_factory(child, mapper) > > > ? ? class SumEvalNode(EvalNode): > > ? ? ? ? def eval(self): > > ? ? ? ? ? ? a = self.evaluatechild(self.node.a) > > ? ? ? ? ? ? b = self.evaluatechild(self.node.b) > > ? ? ? ? ? ? return a + b > > > ? ? class ProductEvalNode(EvalNode): > > ? ? ? ? def eval(self): > > ? ? ? ? ? ? a = self.evaluatechild(self.node.a) > > ? ? ? ? ? ? b = self.evaluatechild(self.node.b) > > ? ? ? ? ? ? return a * b > > > ? ? class IntegerEvalNode(EvalNode): > > ? ? ? ? def eval(self): return self.node.val > > > ? ? ####### > > > ? ? class PrettyPrintNode: > > ? ? ? ? def __init__(self, node): > > ? ? ? ? ? ? self.node = node > > > ? ? ? ? def pprint_child(self, child): > > ? ? ? ? ? ? return PrettyPrintNode.factory(child).pprint() > > > ? ? ? ? @staticmethod > > ? ? ? ? def factory(child): > > ? ? ? ? ? ? mapper = { > > ? ? ? ? ? ? ? ? 'Sum': SumPrettyPrintNode, > > ? ? ? ? ? ? ? ? 'Product': ProductPrettyPrintNode, > > ? ? ? ? ? ? ? ? 'Integer': IntegerPrettyPrintNode > > ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? return abstract_factory(child, mapper) > > > ? ? class SumPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): > > ? ? ? ? ? ? a = self.pprint_child(self.node.a) > > ? ? ? ? ? ? b = self.pprint_child(self.node.b) > > ? ? ? ? ? ? return '(the sum of %s and %s)' % (a, b) > > > ? ? class ProductPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): > > ? ? ? ? ? ? a = self.pprint_child(self.node.a) > > ? ? ? ? ? ? b = self.pprint_child(self.node.b) > > ? ? ? ? ? ? return '(the product of %s and %s)' % (a, b) > > > ? ? class IntegerPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): return self.node.val > > > ? ? ############## > > ? ? # Not sure where this method really "wants to be" structurally, > > ? ? # or what it should be named, but it reduces some duplication > > > ? ? def abstract_factory(node, node_class_mapper): > > ? ? ? ? return node_class_mapper[node.__class__.__name__](node) > > > ? ? expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > > ? ? evaluator = EvalNode.factory(expression) > > ? ? print evaluator.eval() > > > ? ? pprinter = PrettyPrintNode.factory(expression) > > ? ? print pprinter.pprint() > > I don't see the point of EvalNode and PrettyPrintNode. Why don't you > just give Integer, Sum and Product 'eval' and 'pprint' methods? This looks more structurally sound: class Node(object): def eval(self): raise NotImplementedError def pprint(self): raise NotImplementedError class BinaryOperatorNode(Node): operator = None def __init__(self, first, second): self.first = first self.second = second def eval(self): return self.operator(self.first.eval(), self.second.eval()) def pprint(self): "%s(%s, %s)" % (type(self).__name__, self.first.pprint(), self.second.pprint()) class Sum(BinaryOperatorNode): operator = lambda x, y: x + y class Product(BinaryOperatorNode): operator = lambda x, y: x * y I don't know what you're doing exactly but if all you need is to be able to parse and evaluate expressions then you can get very decent mileage out of overriding operators, to the extent that the whole thing you are trying to do could be a single class: class Expression(object): def __init__(self, func): self.func = func def __call__(self, **context): while isinstance(self, Expression): self = self.func(context) return self def __add__(self, other): return Expression(lambda context: self.func(context) + other) def __mul__(self, other): return Expression(lambda context: self.func(context) * other) def __radd__(self, other): return Expression(lambda context: other + self.func(context)) def __rmul__(self, other): return Expression(lambda context: other * self.func(context)) # ... and so forth ... def integer(value): return Expression(lambda context: value) def variable(name, default): return Expression(lambda context: context.get(name, default)) X = Expression("X", 0) expr = 2 * X + 1 assert expr(X=3) == 7 But maybe that's not what you need. No need to overengineer if it is though, keep it simple, simple is better than complex. From showell30 at yahoo.com Sat Nov 21 20:19:46 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 17:19:46 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> Message-ID: <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> On Nov 21, 4:33?pm, Richard Thomas wrote: > > This looks more structurally sound: > > class Node(object): > ? ?def eval(self): > ? ? ? raise NotImplementedError > ? ?def pprint(self): > ? ? ? raise NotImplementedError > My objection to the interface you describe is that Node defines the type of operations that can be done to it by third-party code, which is something that I cannot predict, and which (pscouples every subclass of Node to eval() and pprint(), even though those subclasses might not care about either operation. They might be reimplementing only one of those operations, or some completely different operation. > > class Sum(BinaryOperatorNode): > ? ?operator = lambda x, y: x + y > > class Product(BinaryOperatorNode): > ? ?operator = lambda x, y: x * y > I do like the notion of driving up Sum/Product abstractions like "operator" into BinaryOperatorNode, but that is sort of an artifact of my toy example, not my main design dilemma. > I don't know what you're doing exactly but if all you need is to be > able to parse and evaluate expressions then you can get very decent > mileage out of overriding operators, to the extent that the whole > thing you are trying to do could be a single class... > > class Expression(object): > def __init__(self, func): > self.func = func > def __call__(self, **context): > while isinstance(self, Expression): > self = self.func(context) > return self > def __add__(self, other): > return Expression(lambda context: self.func(context) + other) > def __mul__(self, other): > [snipped] It is my fault for muddying the conversation with a toy example that evaluates arithmetic expressions. My particular problem involves a mini-language that describes how you want to descend Python data structures. > But maybe that's not what you need. No need to overengineer if it is > though, keep it simple, simple is better than complex. Yep! I am trying to keep things simple, but my wish to extend is not speculative at this point; it is real. I have an expression syntax, which I call pyDTL, that I want these operations on: * generate two different versions of Python code that expresses the operation * eagerly evaluate the expression on some object * pretty-print the expression itself * use the expression as a prototype for stub objects to determine what operations they allow * etc.... All of those requirements create the need to somehow create new objects or functions that correspond to the same AST. I describe pyDTL here: http://showellonprogramming.blogspot.com/2009/11/mini-ddl-for-python.html Here is a simple example: echo '{.foo, .bar(){.spam, .eggs} }' | python dtl/parse.py dict( foo = obj.foo, bar = (lambda bar: dict( spam = bar.spam, eggs = bar.eggs, ))(obj.bar()), ) ### From lie.1296 at gmail.com Sat Nov 21 20:36:01 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 22 Nov 2009 12:36:01 +1100 Subject: plotting arrow in python In-Reply-To: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <4b0895d7$1@dnews.tpgi.com.au> rudra wrote: > Dear friends, > I am very new in python. Actually, I think I will not do much python > then using it to plotting data. I have not done any "real" thing in > python, so plz be easy. Now , the problem > I have a data set: > 0.0 0.0 0.1 > 0.0 0.1 0.1 > 0.1 0.0 0.5 > > like that! the first two column are coordinate and 3rd one is > magnitude of moment (say: x y,m)!! so what i want to do is draw an > arrow of magnitude(m) in the position (x,y). > I know how python read array, and how to draw an array(via > matplotlib)...but totally confused with this one. > can you people plz help? If you want to stay with regular python distribution, take a look on pygame (http://www.pygame.org/ ). If you want to avoid 3rd party modules, take a look at turtle and Tkinter in the standard library. From showell30 at yahoo.com Sat Nov 21 20:48:48 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 17:48:48 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> Message-ID: <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> On Nov 21, 12:12?am, Steven D'Aprano wrote: > On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote: > > > If you've actually typed on a physical typewriter, you know that moving > > the carriage back is a distinct operation from rolling the platen > > forward; > > I haven't typed on a physical typewriter for nearly a quarter of a > century. > > If you've typed on a physical typewriter, you'll know that to start a new > page, you have to roll the platen forward until the page ejects, then > move the typewriter guide forward to leave space, then feed a new piece > of paper into the typewriter by hand, then roll the platen again until > the page is under the guide, then push the guide back down again. That's > FIVE distinct actions, and if you failed to do them, you would type but > no letters would appear on the (non-existent) page. Perhaps we should > specify that text files need a five-character sequence to specify a new > page too? > > > both operations are accomplished when you push the carriage > > back using the bar, but you know they are distinct. ?Hell, MIT even had > > "line starve" character that moved the cursor up (or rolled the platen > > back). > > > > > Lots of people talk about "dos-mode files" and "windows files" as if > > Microsoft got it wrong; it did not -- Unix made up a convenient fiction > > and people went along with it. (And, yes, if Unix had been there first, > > their convention was, in fact, better). > > This makes zero sense. If Microsoft "got it right", then why is the Unix > convention "convenient" and "better"? Since we're not using teletype > machines, I would say Microsoft is now using an *inconvenient* fiction. > > -- > Steven It's been a long time since I have typed on a physical typewriter as well, but I still vaguely remember all the crazy things I had to do to get the tab key to produce a predictable indentation on the paper output. I agree with Steven that "\r\n" is completely insane. If you are going to couple character sets to their legacy physical implementations, you should also have a special extra character to dot your i's and cross your t's. Apparently neither Unix or Microsoft got that right. I mean, think about it, dotting the i is a distinct operation from creating the undotted "i." ;) From davea at ieee.org Sat Nov 21 20:58:14 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 21 Nov 2009 20:58:14 -0500 Subject: pythonpath In-Reply-To: References: Message-ID: <4B089AB6.20803@ieee.org> Ray Holt wrote: > Is there a way to make python point to a different directory for modules. I > don't like to keep my modules in the program directory, but I can't figure > out from the shell how to get the program to look in another directory. I am > using XP Pro as an operating system and python2.6 > > There are a few standard places that Python already looks for module imports. To see what they are on your system, you could simply look at sys.path. import sys for path in sys.path: print path In particular, you probably want to use the directory under appdata: C:\Documents and Settings\XXXX\Application Data\Python\Python26\site-packages where XXXX is your user-name. DaveA From rt8396 at gmail.com Sat Nov 21 21:01:53 2009 From: rt8396 at gmail.com (r) Date: Sat, 21 Nov 2009 18:01:53 -0800 (PST) Subject: plotting arrow in python References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> <4b0895d7$1@dnews.tpgi.com.au> Message-ID: On Nov 21, 7:36?pm, Lie Ryan wrote: (..snip..) > If you want to avoid 3rd party modules, take a look at turtle and > Tkinter in the standard library. Just to add to Ryans words... If you want to avoid 3rd party modules, take a look at turtle and the Tkinter *Canvas* widget in the standard library. Here is an example. #-- start code --# try: import Tkinter as tk except ImportError: import tkinter as tk #python 3+ app = tk.Tk() canvas = tk.Canvas(app) canvas.create_line(0,0, 50,50, arrow='last') canvas.pack() app.mainloop() #-- end code --# remove the try/except when you know which one to use. I just wanted to make sure it ran out-the-box for you, have fun! From python at rcn.com Sat Nov 21 21:22:30 2009 From: python at rcn.com (Raymond Hettinger) Date: Sat, 21 Nov 2009 18:22:30 -0800 (PST) Subject: python bijection References: Message-ID: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> On Nov 19, 3:24?pm, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? Comments and suggestions welcome. > > Josh Hello Joshua, I have a few design ideas and comments for you. * The idea of using __call__ for looking-up inverse values was inspired. That is useable, clean, and easy to remember; however, as discussed below, there are issues though with its actual use in real code. * Am not excited by the inverse iterators. With just a regular mapping you can write: for a, b in m.items() ... # consider either a or b be the key and the other to be the value That meets all of the needs that would have been served by iter_inverse_keys() or iter_inverse_values() or whatnot. The mirrored API doesn't really provide much in the way of value added. * After exercising the API on a couple of samples, I'm worried that almost any inverse-method based API makes it difficult to review code while keeping straight the intended meaning of the forward and inverse relationships. Am thinking that it is simpler, faster, and clearer to just use two dictionaries -- that approach lets the variable names communicate the important info. For example, the following code helps keep the coder and code reviewer from conflating the forward and inverse directions: myurl = ip2url[myip] myip = url2ip[myurl] Contrast that with: myurl = site_bijection[myip] myip = site_bijection(myurl) With the latter, it is darned difficult to detect accidental conflation of brackets with parentheses. * So, I'm thinking that code needing a bijection would be better-off with two ordinary dicts, perhaps augmented by a couple of convenience functions: biject_add(site_bijection, ip=myip, url=myurl) # Create a new pairing, raise ValueError if either key # maps to more than one value (in violation of the # bijection invariant: one-to-one and onto) biject_remove(ip=myip) # Clear an entry from both dicts or biject_remove(url=myurl) Alternatively, another possible approach is to used use the class generation approach (such as that used by named_tuple()) to generate a custom bijection class with either attribute based or keyworded accessors: Attribute based accessors: site = Bijection('ip', 'url') site.url[myip] = myurl for ip, url in site.items() ... print site.ip[myurl] myurl = site.url.pop(myip) Keyword accessors: site = Bijection('ip', 'url') site.set(ip=myip, url=myurl) myurl = site.get(ip=myip) myip = set.get(url=myurl) myurl = site.pop(ip=myip) site.del(ip=myip) site.del(url=myurl) Hope these ideas help. The ultimate success of the Bijection code will depend on its clarity, simplicity, and speed. Experiment with various approaches to find-out which looks the best in real code. It cannot be error-prone or it is doomed. Also, it should not introduce much overhead processing or else people will avoid it. The API should be trivially simple so that people remember how to use it months after seeing it for the first time. Good luck and happy hunting, Raymond From ivoras at gmail.com Sat Nov 21 21:43:31 2009 From: ivoras at gmail.com (Ivan Voras) Date: Sun, 22 Nov 2009 03:43:31 +0100 Subject: Imitating "tail -f" Message-ID: I'm trying to simply imitate what "tail -f" does, i.e. read a file, wait until it's appended to and process the new data, but apparently I'm missing something. The code is: 54 f = file(filename, "r", 1) 55 f.seek(-1000, os.SEEK_END) 56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL) 57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK) 58 59 pe = select.poll() 60 pe.register(f) 61 while True: 62 print repr(f.read()) 63 print pe.poll(1000) The problem is: poll() always returns that the fd is ready (without waiting), but read() always returns an empty string. Actually, it doesn't matter if I turn O_NDELAY on or off. select() does the same. Any advice? From mensanator at aol.com Sat Nov 21 21:51:39 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 21 Nov 2009 18:51:39 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: <8b2bec1b-59e1-4f54-a115-e56aaa9dd120@w19g2000yqk.googlegroups.com> On Nov 21, 6:11?pm, Steve Howell wrote: > On Nov 21, 11:20?am, John Roth wrote: > > > > > > > On Nov 21, 8:40?am, Duncan Booth wrote: > > > > a... at pythoncraft.com (Aahz) wrote: > > > > Comparing Go to another computer language -- do you recognize it? > > > > >http://www.cowlark.com/2009-11-15-go/ > > > > Yes, spotted it at the first 'fi'. > > > This isn't the first time anyone has criticized Go. The interesting, > > and somewhat sad, thing is that the entire mess can be explained > > very easily by looking at the beginning of the language design > > FAQ on the Go web site. See if you recognize the names of the > > principle people who designed it. > > > Yep. Go is simply C with most (but not all) of the warts > > removed and some more modern features added. Brought to you > > by the same people who brought you C and Unix all those years ago. > > The use of the Plan 9 toolchain is not a coincidence. > > The assertion that Go is simply C with warts removed and modern > features added is not surprising. > > If you read the Go FAQ, you will see that there is no claim anywhere > that they are trying to solve the problem that 40 years of language > development since Algol has not produced super-sexy quantum leaps of > improvement. ?Instead, they are trying to solve the problem that in > the last ten years, there haven not seen ANY improvement in systems > programming languages ("No major systems language has emerged in over > a decade"). ?The critics of Go probably fall into four categories: > > ? 1) Some do not understand the goals of the Go project itself, so > they are criticizing Go for not solving problems that were never in > Go's bailiwick to begin with. > ? 2) Some believe that Go does not deliver on its goal to modernize > systems programming languages. > ? 3) Some do not accept the premise that there has been no progress > outside of Go in the last ten years with regards to systems > programming languages, and they are wondering why Google invented Go > instead of embracing other technologies. > ? 4) Some people do not even believe that the problem is important--do > we actually need a modern systems programming language, or do we just > need modern programming languages to perform well under all > circumstances, or at least be adaptable? > > My list probably isn't even nearly exhaustive. Like those who think Python programmers would be interedted in Go because it has an import statement. From pavlovevidence at gmail.com Sat Nov 21 22:05:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 21 Nov 2009 19:05:30 -0800 (PST) Subject: How do I create a vanilla object in C? References: Message-ID: <6617094f-6c01-4997-998c-032da4797c88@x31g2000yqx.googlegroups.com> On Nov 21, 12:49?pm, rnich... at mightyheave.com wrote: > I need to create a vanilla object in C, something I can do > PyObject_SetAttr on. ?Obviously, I do something somewhat like this every > time I create a minimal python class. ?I need to know how to do this in C > though. First of all, if you don't need to share this object with any Python code, then I'd suggest you just use a dict (create with PyDict_New). If you do need to share it with Python, one thing to consider is whether it isn't easier to create the object in Python and pass it to the C code. If these suggestions aren't suitable, then you'll have to create a new vanilla type, then create an instance of that type. Unfortunately it's not too convenient from C. It's easy enough to define types and C (see the C-API documentation), but in order to use PyObject_SetAttr on it you'll have to make sure the type has a dictionary, so you'd have to set the tp_dictoffset member to the offset of your dict in the Python structure. Another thing you can do is to call type directly (as you can do in Python) with the name, bases, dict, as in the following example (error checking and reference counting omitted): name = PyString_FromString("vanilla"); bases = PyTuple_New(0); dict = PyDict_New(); vanilla_type = PyObject_CallObject( &PyType_Type,name,bases,dict,0); Then call the vanilla type (however you create it) to get a vanilla object: vanilla_object = PyObject_CallObject(vanilla_type,0); Definitely not the most straightforward thing to do from C. Carl Banks From exarkun at twistedmatrix.com Sat Nov 21 23:10:02 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 22 Nov 2009 04:10:02 -0000 Subject: Imitating "tail -f" In-Reply-To: References: Message-ID: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> On 02:43 am, ivoras at gmail.com wrote: >I'm trying to simply imitate what "tail -f" does, i.e. read a file, >wait >until it's appended to and process the new data, but apparently I'm >missing something. > >The code is: > >54 f = file(filename, "r", 1) >55 f.seek(-1000, os.SEEK_END) >56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL) >57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK) >58 >59 pe = select.poll() >60 pe.register(f) >61 while True: >62 print repr(f.read()) >63 print pe.poll(1000) > >The problem is: poll() always returns that the fd is ready (without >waiting), but read() always returns an empty string. Actually, it >doesn't matter if I turn O_NDELAY on or off. select() does the same. > >Any advice? select(), poll(), epoll, etc. all have the problem where they don't support files (in the thing-on-a-filesystem sense) at all. They just indicate the descriptor is readable or writeable all the time, regardless. "tail -f" is implemented by sleeping a little bit and then reading to see if there's anything new. Jean-Paul From jasonsewall at gmail.com Sat Nov 21 23:32:16 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Sat, 21 Nov 2009 23:32:16 -0500 Subject: Imitating "tail -f" In-Reply-To: <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> Message-ID: <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> FWIW, GNU tail on Linux uses inotify for tail -f: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c The wikipedia page for inotify lists several python bindings: http://en.wikipedia.org/wiki/Inotify Not much help for non-Linux users, but there it is. Too bad, because inotify is pretty cool. Jason On Nov 21, 2009 11:11 PM, wrote: On 02:43 am, ivoras at gmail.com wrote: > > I'm trying to simply imitate what "tail -f" does, i.e. read... select(), poll(), epoll, etc. all have the problem where they don't support files (in the thing-on-a-filesystem sense) at all. They just indicate the descriptor is readable or writeable all the time, regardless. "tail -f" is implemented by sleeping a little bit and then reading to see if there's anything new. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun Nov 22 00:19:49 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 18:19:49 +1300 Subject: Too Many Values To Unpack In-Reply-To: References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: <7ms008F3ibrvmU1@mid.individual.net> Dennis Lee Bieber wrote: > I apparently thought "for ... in dictionary" would return (key, > value) pairs, but it appears that it only returns the key itself -- and > a single key can't be unpacked. > > Misleading error... too many /targets/ to unpack... My guess is that the keys are strings, which means it's unpacking them into characters, in which case a key of length 3 or more will produce that message. -- Greg From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 00:37:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 05:37:17 GMT Subject: Too Many Values To Unpack References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: <0318bbfb$0$1336$c3e8da3@news.astraweb.com> On Sat, 21 Nov 2009 21:06:08 -0800, Dennis Lee Bieber wrote: > I apparently thought "for ... in dictionary" would return (key, > value) pairs, but it appears that it only returns the key itself -- and > a single key can't be unpacked. > > Misleading error... too many /targets/ to unpack... No, the error is fine. >>> for x, y in {1:'a'}: ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: unpack non-sequence >>> >>> for x, y in {'a':1}: ... pass ... Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack >>> >>> for x, y in {'parrot':1}: ... pass ... Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack Strings are iterable, and so unpack into individual characters. -- Steven From greg.ewing at canterbury.ac.nz Sun Nov 22 00:58:50 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 18:58:50 +1300 Subject: plotting arrow in python In-Reply-To: References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <7ms299F3jvhbiU1@mid.individual.net> > rudra wrote: > >> 0.0 0.0 0.1 >> 0.0 0.1 0.1 >> 0.1 0.0 0.5 >> >> like that! the first two column are coordinate and 3rd one is >> magnitude of moment (say: x y,m)!! so what i want to do is draw an >> arrow of magnitude(m) in the position (x,y). There seems to be some information missing there. How do you know what direction to draw the arrow in? -- Greg From sergiomb at sapo.pt Sun Nov 22 01:15:01 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Sun, 22 Nov 2009 06:15:01 +0000 Subject: python setup.py build 32-bits on x86_64 machine Message-ID: <4b08d6e9$0$28097$a729d347@news.telepac.pt> Hi, I am in x86_64 arch , but I need compile things on 32 bits. python setup.py build Can't change the fact that distutils creates x86_64 directories: gcc -pthread -shared build/temp.linux-x86_64-2.3/ Also if I try with a python compile in 32bits and installed in system . how I force distutils build to 32-bits ? Thanks in advance, From mnordhoff at mattnordhoff.com Sun Nov 22 01:32:27 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sun, 22 Nov 2009 06:32:27 +0000 Subject: Imitating "tail -f" In-Reply-To: <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: <4B08DAFB.4030203@mattnordhoff.com> Jason Sewall wrote: > FWIW, GNU tail on Linux uses inotify for tail -f: > > http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c > > The wikipedia page for inotify lists several python bindings: > > http://en.wikipedia.org/wiki/Inotify > > Not much help for non-Linux users, but there it is. Too bad, because > inotify is pretty cool. > > Jason Some other operating systems have similar facilities, e.g. FSEvents on OS X. -- Matt Nordhoff From greg.ewing at canterbury.ac.nz Sun Nov 22 01:48:34 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 19:48:34 +1300 Subject: parallel class structures for AST-based objects In-Reply-To: <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> Message-ID: <4B08DEC2.3080709@canterbury.ac.nz> Steve Howell wrote: > My objection to the interface you describe is that Node defines the > type of operations that can be done to it by third-party code, which > is something that I cannot predict I think you have the right idea with a mapping from node classes to implementations of operations, but your intermediate classes SumPrettyPrintNode etc. are not necessary. Just put functions implementing the operations directly into the mapping. Another thing is that the mappings should be somewhere global that can be extended, perhaps through a registration interface. Putting the mapping dicts inside the node classes doesn't gain you anything over simply using methods. All you've done is reimplement method dispatch. A third thing is that instead of just looking up the node class in the mapping, you may want to walk up the MRO and try each of the base classes until you find a match. That way, nodes will effectively inherit implementations from their base classes for any operations that they don't explicitly implement. This inheritance behaviour becomes important if you have two developers A and B, where A adds new classes and B adds new operations. If A and B don't talk to each other, you necessarily end up with gaps in the matrix: A's classes won't have implementations for B's operations. The best you can hope for is that the missing operations will somehow fall back gracefully on default implementations. Inheritance allows this to be achieved: if A derives all his classes from existing node classes, and B provides default implementations of all his operations for the root Node class, then some implementation will always be found for every class/operation combination. Now, there's actually a very easy way of implementing all this. Your registration interface could simply be def register_operation(klass, operation_name, function): setattr(klass, operation_name, function) In other words, monkey-patch the classes to add the new functions directly as methods. Since it's so simple, you could even do away with the registration function altogether and just have developers insert methods directly into the classes. Some people might consider this an ugly hack, but the end result is almost exactly the same, it's very simple, and it's very efficient, making use of Python's existing method dispatch machinery instead of reinventing it yourself. One reason you might want to keep the registration function, even if all it's doing is modifying the classes, is to make it easier to find where operations are being defined, by searching for calls to register_operation(). -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 02:26:02 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 20:26:02 +1300 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: <7ms7ctF3k2a79U1@mid.individual.net> > On Nov 21, 11:20 am, John Roth wrote: > >>Go is simply C with most (but not all) of the warts >>removed and some more modern features added. Syntax-wise, I find myself disappointed that they didn't do as good a job of removing the warts as they could have. For example, there are good reasons for putting types after variable names, but just swapping them around doesn't quite work. C's "int x" reads well because it mimics similar constructs in English which qualify a noun with another noun, e.g. "President Obama". If you say "Obama President", it doesn't sound right. You need some extra punctuation to make it meaningful: "Obama, President". Similarly, I think just a little bit more punctuation is needed to make name-first declarations readable. For my money, it's hard to beat the Wirth style: func foo(x: int; y: char): float However, Go's designers seem to favour using the absolute minimum number of characters they can get away with. Although if they *really* wanted that, they would have dropped most of the semicolons and used indentation-based block structure instead of curly braces. I would have forgiven them several other sins if they'd done that. :-) -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 02:33:00 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 20:33:00 +1300 Subject: Writing a Carriage Return in Unicode In-Reply-To: <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> Message-ID: <7ms7puF3jgcldU1@mid.individual.net> Steve Howell wrote: > If you are > going to couple character sets to their legacy physical > implementations, you should also have a special extra character to dot > your i's and cross your t's. No, no, no. For that device you need to output a series of motion vectors for the scribing point. Plus control characters for "dip nib" and "apply blotter", and possibly also "pluck goose" for when the print head becomes worn. -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 03:20:01 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 21:20:01 +1300 Subject: ANN: PyGUI Mailing List In-Reply-To: References: Message-ID: <4B08F431.5080707@canterbury.ac.nz> Terry Reedy wrote: > Having it mirrored to news.gmane,org, if you have not yet, like other > python.org lists, would make it easier to follow or join. Perhaps it > will happen automatically, I do not know. I don't think it's automatic. I've submitted a request to gmane to have it added and I'm waiting to see what happens. -- Greg From wentland at cl.uni-heidelberg.de Sun Nov 22 04:11:44 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sun, 22 Nov 2009 10:11:44 +0100 Subject: Imitating "tail -f" In-Reply-To: References: Message-ID: <20091122091144.GB9247@kinakuta.local> On Sun, Nov 22, 2009 at 03:43 +0100, Ivan Voras wrote: > I'm trying to simply imitate what "tail -f" does, i.e. read a file, wait > until it's appended to and process the new data, but apparently I'm > missing something. [..] > Any advice? Have a look at [1], which mimics "tail -f" perfectly. It comes from a talk by David Beazley on generators which you can find at [2] and [3]. Enjoy! [1] http://www.dabeaz.com/generators/follow.py [2] http://www.dabeaz.com/generators-uk/ [3] http://www.dabeaz.com/coroutines/ -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From n00m at narod.ru Sun Nov 22 04:21:42 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 01:21:42 -0800 (PST) Subject: Sorting: too different times. Why? Message-ID: Any comment: class Vector: def __init__(self, x, y): self.x = x self.y = y def __cmp__(self, v): if self.x < v.x and self.y > v.y: return -1 return 0 def v_cmp(v1, v2): if v1.x < v2.x and v1.y > v2.y: return -1 return 0 from random import randint from time import time a = [] for i in range(200000): a += [Vector(randint(0, 500000), randint(0, 500000))] b = a[:] c = a[:] print 'Sorting...' t = time() b.sort(cmp=v_cmp) print time() - t t = time() c.sort() print time() - t print b == c >>> ===================================== RESTART ====== >>> Sorting... 0.906000137329 6.57799983025 True From deets at nospam.web.de Sun Nov 22 04:50:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 10:50:27 +0100 Subject: parallel class structures for AST-based objects In-Reply-To: <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> Message-ID: <7msfr3F3j1ilfU1@mid.uni-berlin.de> Steve Howell schrieb: > On Nov 21, 4:07 pm, MRAB wrote: >> I don't see the point of EvalNode and PrettyPrintNode. Why don't you >> just give Integer, Sum and Product 'eval' and 'pprint' methods? > > That's a good question, and it's the crux of my design dilemma. If > ALL I ever wanted to to with Integer/Sum/Product was to eval() and > pprint(), then I would just add those methods to Integer, Sum, and > Product, and be done with it, as you suggest. But what happens when > somebody wants to extend capability? Should every future software > developer that wants to use Integer/Sum/Product extend those classes > to get work done? What if they want to store additional state for > nodes? > What's usually done is to create visitors/matchers. Those traverse the AST, and either only visit, or return transformed versions of it (think e.g. algebraic optimization) A visitor will roughly look like this: class ASTVisitor(object): def visit(self, node): name = node.__class__.__name__.lower() if hasattr(self, "visit_%s" % name): getattr(self, "visit_%s" % name)(node) for child in node: self.visit(child) You can of course chose another type of dispatch, using e.g. a generic method. Then you create Visitors for specific tasks - pretty-printing, evaluation, rewriting. Those don't have the overhead of your current design with all those factory-mapping stuff, and yet you aren't forced to put logic into AST you don't want there. Diez From sturlamolden at yahoo.no Sun Nov 22 04:57:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 22 Nov 2009 01:57:49 -0800 (PST) Subject: How do I create a vanilla object in C? References: <6617094f-6c01-4997-998c-032da4797c88@x31g2000yqx.googlegroups.com> Message-ID: <5f5f5385-16b6-44e2-84e0-34749824bc69@z41g2000yqz.googlegroups.com> On 22 Nov, 04:05, Carl Banks wrote: > name = PyString_FromString("vanilla"); > bases = PyTuple_New(0); > dict = PyDict_New(); > vanilla_type = PyObject_CallObject( > ? ? ? ? &PyType_Type,name,bases,dict,0); > > Then call the vanilla type (however you create it) to get a vanilla > object: > > vanilla_object = PyObject_CallObject(vanilla_type,0); > > Definitely not the most straightforward thing to do from C. It is much easier to do this from Cython. cdef class foo: # fields stored in C struct pass class foo: # fields stored in Python dict pass The let the Cython compiler generate the C code you need. http://docs.cython.org/src/tutorial/cdef_classes.html From showell30 at yahoo.com Sun Nov 22 05:38:36 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 02:38:36 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> <7ms7puF3jgcldU1@mid.individual.net> Message-ID: <5c28ec26-0e48-4b59-9003-ebb50613420a@y32g2000prd.googlegroups.com> On Nov 21, 11:33?pm, Gregory Ewing wrote: > Steve Howell wrote: > > If you are > > going to couple character sets to their legacy physical > > implementations, you should also have a special extra character to dot > > your i's and cross your t's. > > No, no, no. For that device you need to output a series > of motion vectors for the scribing point. Plus control > characters for "dip nib" and "apply blotter", and > possibly also "pluck goose" for when the print head > becomes worn. > Greg, at the first reading of your response, it sounded overly complicated for me to have to "dip nib" and "pluck goose" every time I just want to semantically indicate the ninth letter of the English alphabet, but that's easily solved with a wizard interface, I guess. Maybe every time I am trying to decide which letter to type in Word, there could be some kind of animated persona that helps me choose the character. There could be a visual icon of an "eye" that reminds me of the letter that I am trying to type, and I could configure the depth to which I dib the nib with some kind of slider interface. It actually sounds quite simple and elegant, the more that I think about it. From sumerc at gmail.com Sun Nov 22 05:44:48 2009 From: sumerc at gmail.com (k3xji) Date: Sun, 22 Nov 2009 02:44:48 -0800 (PST) Subject: yappi v0.3 Message-ID: <9ca5964d-21cb-4cce-9fbb-261c4766182b@b15g2000yqd.googlegroups.com> Hi, yappi(yet another python profiler) is a Python Profiler with multithreading support. This is the last beta version with some major changes and bugfixes: v0.3 Changes --------- [+] yappi did not compile out of box on VS2008. Fix the compile issues. (Thanks to Kevin Watters) [+] tidy up stat formatting code. that's previously messy. [+] BUGFIX:application total time is calculated wrong. [+] BUGFIX:change some int's to long long's to prevent simple integer overflows. [+] show profiler status. [+] show memory usage of the yappi itself. [+] show thread class name in the thread stats. [+] make thread/profiler stats column separated. [+] big endian support for core hash function. [+] BUGFIX: CURRENTCTX macro can return NULL on rare occassions, handle that. [+] BUGFIX: Shows wrong thread class name as we call it in the profile_thread. [+] OPTIMIZATION:some hashtable enhancements are done. For documentation and download see: http://code.google.com/p/yappi/ -- twitter.com/sumercip Sumer Cip From ben+python at benfinney.id.au Sun Nov 22 05:50:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 22 Nov 2009 21:50:41 +1100 Subject: Sorting: too different times. Why? References: Message-ID: <87y6lyal4u.fsf@benfinney.id.au> n00m writes: > Any comment: I get similar output. What were you expecting to happen? Did you have any questions? -- \ ?The right to search for truth implies also a duty; one must | `\ not conceal any part of what one has recognized to be true.? | _o__) ?Albert Einstein | Ben Finney From n00m at narod.ru Sun Nov 22 05:56:03 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 02:56:03 -0800 (PST) Subject: Sorting: too different times. Why? References: <87y6lyal4u.fsf@benfinney.id.au> Message-ID: <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> I was expecting the 1st method would be *slower* than the 2nd one :-) Or at least equal... Just random ("intuitive") expectations From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 06:04:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 11:04:19 GMT Subject: Sorting: too different times. Why? References: Message-ID: <031908a0$0$1336$c3e8da3@news.astraweb.com> In the subject line, you write "too different times". You actually want "two", the number, not "too" as in "too many", "too much". Lots of native English speakers get this wrong too :) On Sun, 22 Nov 2009 01:21:42 -0800, n00m wrote: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 Modern versions of Python (since 2.2 I think?) use __lt__ or __gt__ for sorting. If the class doesn't have a __lt__ method, Python falls back on __cmp__. > b.sort(cmp=v_cmp) This is relatively fast, because you pass a comparison function directly, so Python doesn't need to look for a __lt__ method then fall back to __cmp__. It just uses v_cmp, every time. > c.sort() This is slower, because every comparison looks up the __lt__ and fails, then tries the __cmp__. If you change the definition of Vector to include rich comparison methods as detailed here: http://docs.python.org/reference/datamodel.html#object.__lt__ sorting will probably be significantly faster still. -- Steven From deets at nospam.web.de Sun Nov 22 06:06:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 12:06:01 +0100 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B091B19.9040807@nospam.web.de> n00m schrieb: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 > > from random import randint > from time import time > > a = [] > for i in range(200000): Use xrange instead (unless you are under python3), because for loops you don't need the full list range creates - xrange is just a generator. > a += [Vector(randint(0, 500000), randint(0, 500000))] Better use .append here, looks nicer and should also be a bit faster. > b = a[:] > c = a[:] > > print 'Sorting...' > > t = time() > b.sort(cmp=v_cmp) > print time() - t > > t = time() > c.sort() > print time() - t > > print b == c > > > >>>> ===================================== RESTART ====== >>>> > Sorting... > 0.906000137329 > 6.57799983025 I think the main reason is that method-dispatch is more expensive than function-dispatch. The former must create a bound method before calling, the latter just works out of the box. Things get better if you do this: t = time() c.sort(cmp=Vector.__cmp__) print time() - t Although not the exact same performance - I get Sorting... 0.677843093872 1.4283311367 True Diez From duncan.booth at invalid.invalid Sun Nov 22 06:06:56 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Nov 2009 11:06:56 GMT Subject: Sorting: too different times. Why? References: Message-ID: n00m wrote: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 What's that comparison function supposed to be doing? >>> print Vector(1, 1) < Vector(2, 0) True >>> print Vector(2, 0) == Vector(1, 1) True If you use a broken comparison function then you must expect strange results, and your list of vectors isn't going to end up in any particular order (try adding "c.reverse()" before the call to "c.sort()" and the two 'sorted' lists won't match any more). In this case though the time difference may simply be down to creating in excess of 1 million bound methods. From clp2 at rebertia.com Sun Nov 22 06:07:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Nov 2009 03:07:08 -0800 Subject: Sorting: too different times. Why? In-Reply-To: <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> References: <87y6lyal4u.fsf@benfinney.id.au> <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> Message-ID: <50697b2c0911220307v15bb99c8if89e071e6d57aed3@mail.gmail.com> On Sun, Nov 22, 2009 at 2:56 AM, n00m wrote: > I was expecting the 1st method would be *slower* than the 2nd one :-) > Or at least equal... Just random ("intuitive") expectations The second method repeatedly looks up left_item.__class__.__cmp__ (i.e. Vector.__cmp__) when doing the necessary comparisons between the list items; while these lookups are optimized and are fast, they are not free and cannot be skipped because Python doesn't know the list contains only Vectors. The first method uses the single provided comparison function and thus does no such lookups; hence, it's faster. That's my guess anyway. Cheers, Chris -- http://blog.rebertia.com From dickinsm at gmail.com Sun Nov 22 06:44:58 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 22 Nov 2009 03:44:58 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: On Nov 22, 9:21?am, n00m wrote: > Any comment: > > class Vector: > ? ? def __init__(self, x, y): > ? ? ? ? self.x = x > ? ? ? ? self.y = y > ? ? def __cmp__(self, v): > ? ? ? ? if self.x < v.x and self.y > v.y: > ? ? ? ? ? ? return -1 > ? ? ? ? return 0 > > def v_cmp(v1, v2): > ? ? if v1.x < v2.x and v1.y > v2.y: > ? ? ? ? return -1 > ? ? return 0 > > from random import randint > from time import time > > a = [] > for i in range(200000): > ? ? a += [Vector(randint(0, 500000), randint(0, 500000))] > b = a[:] > c = a[:] > > print 'Sorting...' > > t = time() > b.sort(cmp=v_cmp) > print time() - t > > t = time() > c.sort() > print time() - t > > print b == c > > >>> ===================================== RESTART ====== > > Sorting... > 0.906000137329 > 6.57799983025 > True Do you get the same magnitude difference if you make Vector a new- style class? (I.e., use "class Vector(object)" instead of "class Vector ()".) Mark From seeWebInstead at rem.intarweb.org Sun Nov 22 07:03:28 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Sun, 22 Nov 2009 04:03:28 -0800 Subject: No-syntax Web-programming-IDE (was: Does turtle graphics have the wrong associations?) References: <0315a685$0$1327$c3e8...@news.astraweb.com> Message-ID: > >>> My proposed no-syntax > >>> IDE *also* gets rid of the need to bother with any programming-language > >>> syntax. I've been proposing it for years, but nobody has shown any > >>> interest > From: Terry Reedy > What you describe below is similar to various systems that have > been proposed and even implemented, including visual programming > systems. Are any of them integrated with tutorial material and available over the Web, as mine will be? If so, will you tell me the URLs so that I can play with them? > And there has been some success with non-programmers. The purpose of *my* system will be to start with mostly non-programmers and *teach* them algorithm design from examples of tasks they get paid (labor-credits, not $money$) to perform, without needing to simultaneously bother them with programming-language syntax. They learn how to take one step at a time towards a long journey (Chinese proverb) without needing to first learn a language for stating with ultra-precision *how* exactly to take each one step. Thus they learn algorithm design with maximal efficiency, because nearly their whole attention is on *that* without distraction of syntax too. > But for most people, it is simply easier to say/write what one > means rather than point and click. That works only after you already know to say/write what you mean for the computer *precisely*exactly*analRetentively* what you want the computer to do. If you don't already know *how* to say precisely what you mean for the computer to do, it's impossible. For example, show somebody this data: [12 15 19 26 43 62 92 71 78 85 93] Point to this item ...^^ Ask that person, who has *never* even seen a computer program much less written one him/herself, and also who has never studied formal mathematics such as set theory, and ask that person to say in precise terms how a computer should find that indicated item among the data. Look at the data. You see what's special about that one item among the data, right? So how to express to a computer how to find it? Answer: It's the item that's out-of-sequence relative to its neighbors. How many non-computer non-math beginners would even notice what's special about that item? (my guess: about half) How many would be able to express either the mathematical definition of the desired result, or an algorithm for finding it, clearly enough that even a human seeing the expression but *not* seeing the sample would be able to write a computer program per that spec to solve the problem? (my guess: less than 1%) Example of a valid informal mathematical expression: There's a sequence of numbers. Mostly they are in correct sequence. But exactly one of them is in the wrong place relative to the others around it. Find that one that's out of place. Example of a valid semi-formal mathematical expression: Given an index set [0..N], and a function F from that index set into the integers; Such that the predicate "lambda (i) F(i-1) < F(i) < F(i+1)" is true for all but one member of the interval [1..N-1]; Find the element of [1..N-1] for which the predicate is not true. Formal mathematical expression depends on the notation conventions, so I won't bother to even attempt to concoct such here for example. Computer algorithms are several in overall algorithm, depending on which primitives are available from declarative or imperative programming, from functional or prodedural etc. programming, and within each choice of *that*, the actual syntax can be any of several per programming language such as Lisp or APL or Forth etc. (Yeah, I deliberately avoided mentionning C or Fortran or Java etc.) If my guess is correct that less than 1% of absolute beginners can even state what is desired, so that a human can understand it unambiguously, much less how to obtain it, likewise, expecting that such an absolute beginner would simply "say/write what one means" is IMO unreasonable. Hence my idea is a sort of friendly "wizard" to take as much of a crude ambiguous statment as the student is capable of and willing to key in, use that to narrow and/or prioritize the number of possible data-processing steps that are reasonably possible given the data we have to work from, and then show the prioritized options to the student, clearly expressed moderately verbosely, and let the student either pick one of them or clarify what had been keyed in just before. At the start, before the student has said *anything* about what the next D/P step will be, *all* possible operations on existing data are available, organized in some meaningful way that would support a fully menu-driven method as you presume. But a hybrid of vague statement what to do (such as my first "answer" above which said nothing about there being any sequence or that the numbers were ascending except for that one out of place) and limited set of known options available a priori, would be available whenever the student *can* at least partially express what to do with the data. Now in the example given above, the desired processing step is too complicated to be directly available in most programming languages, and so I would treat that as a high-level problem to be broken into pieces rather than a low-level task to be directly expressed in primitives available at the start. So in a sense it wasn't a fair example, but it's what I thought of at the moment while composing this article. And it *does* serve as a good example of the *other* part of my proposed integrated NewEco contract-work team-programming system, namely the discussion forum and concensus-achiever process of how to break a complicated task down into pieces so that each piece can be solved separately by recursive application of the system and then the pieces can be applied in combination to solve the given toplevel problem. (Caveat: The problem example I stated above is probably not the actual highest-level problem, but more likely some intermediate problem that comprises the toplevel problem. But recursively it's the toplevel problem at the moment.) > Point-and-click writing reminds me of point-and-click speaking. > Great for those who need it but a hindrance to those who do not. The hybrid system would satisfy people at both ends of your spectrum, as well as people anywhere in the middle, such as a person who knew only fifty words and had only a vague idea of just a little of the grammar and needed to express something that used about half known words that can be keyed in and half unknown words that must be obtained from a thesaurus or menu. And actually if you compare programming with ordering food in a restaurant, unless you know in advance the entire menu of the restaurant or the entire set of functions/methods of the programming language, you really *do* need to consult the menu from time to time to see what's available, rather than make a fool of yourself by trying to ask for thousands of entrees not available in that restaurant (just **try** going into your local Jack in the Box and standing at the counter (or using the drive-thru intercom) and ordering a plate of escargot, then a plate of lasagna, then a pizza, then some marzipan candies, then a sundae, then a T-bone steak, then a souffle, then a mug of beer, then some fresh walnuts in the shell, then a can of corn beef hash, then some potstickers, then a bowl of chili, then a half pound of chicken almond chow mein, then a glass of Grey Reisling, then a plate of spaghetti, then a baked potato with sour cream, then ... see if you even get that far before the manager comes out to tell you to either read the menu or go away and stop bothering them) So yeah I have a grand idea of a system that represents data per intentional datatype rather than any specific implementational datatype used in any particular programming language, and uses generic intentional-datatype functions/methods not directly related to anything in any regular programming language (at least it'll be rare when by chance there's a function in an existing language that is *exactly* as general as what I offer), but uses a hierarchy of general-to-specific datatypes so that algorithms can be expressed very generally at first then at some point pinned down if necessary to a specific type of representation in order to be able to write algorithms dependent on that representation, or just left in abstract form if my system happens to have a built-in function to do exactly what is needed so that no further splitting of the task is necessary. For example, Java has the concept of a "Set", and functions to do various set-theoretic operations on it, with the *same* method specification regardless of whether the Set is implemented as a TreeSet or HashSet. By comparison, Common Lisp doesn't have such a generic set of methods defined, instead has separate functions defined for linked-list acting as a set or bitmap acting as a set or hashtable acting as a set. So depending on how large a system I have implemented, various of those operations might or might not be available at the get-go. Let me go back to that example I gave earlier. If users are presented with that problem, by example, and asked to think of ways to solve it, some might prefer the mathematical approach, similar to what I expressed earlier, similar to a declarational programming language, while others might prefer a procedural or functional expression of the algorithm. If both viewpoints had sufficient voters, the project might split into two different programming teams, one analyzing the problem mathematically, and the other analyzing the problem imperatively. These teams would then break the main goal into sub-tasks in somewhat different ways. And within each team, there might be further differences of opinion, such as whether to iterate sequentially (as might be done in C) or to use a mapping operation to emulate set-theoretic operations (as might be done in Lisp) or to use set-theoretical operations directly (as in SQL). At an even finer level of analysis, the iterative team might prefer linear search or parallel-processing (process-forking) recursive binary search, depending on their perception of the CPU and system-level task software available. And the linear-search team might prefer either explicit array indexing, i.e. for (ix=0; ix This is not to say that traditional editors cannot be improved > with better backup memory aids. Indeed, even IDLE recognizes > function names and pops up a bar listing parameters. But I assume the student using IDLE is *forced* into one particular syntax for the given programming language? > Feel free to develop a Visual Python environment. Like I said, there won't be *any* programming-language syntax. No Lisp, no PHP, no Java, no C (the C examples of array indexing vs. streams were just the best way I could think of expressing the *algorithm* style to reaaders of this thread, no intention that students would actually *see* that syntax anywhere in my system) and no Python, sorry, but I have to emphasize that point again. > I might even give it a try. Would you give it a try if it didn't show you any Python syntax at any point, but after an algorithm is *completed* it gave you the option of rendering the algorithm in any of several different programming languages, maybe even more than one way in each language if the abstract intentional datatypes were never resolved to specific implementational datatypes, hence could be emulated multiple ways per multiple implementational datatypes in each single language? For example, the sequence given in the example above could be represented in Java as a generic Vector using instance methods from the Vector class, or as a generic Array using primitive C-like code within static methods, or as an explicit user-defined class with user-defined methods, or as a user-defined sub-class of Vector that used a mix of Vector methods and sub-class methods, or in Java version 6 as a specialized type of Vector. Oops, somehow when I downloaded the above and below articles, for purpose of later responding to each, the newsgroup header from the article below was lost. Google Groups advanced search for phrase: I did too and had the same question turns up *nothing*, as if your article was never posted! Processing a single data file turns up only one false match. (I hate how Google Groups has been grossly broken for the past several months, as if they just don't care any more.) So I have no way find your article (below) to get the header, hence no way to post a followup to it, so I'll just append my reply here: > >> From: Steven D'Aprano > >> I'm interested. No-syntax IDE? How is this even possible? > > I guess you missed what I previously posted. > I did too and had the same question. ;Note the following is just *one* example of a test-rig set-up: > > The basic idea is that > > you start with test data, and you use menus to select appropriate > > data-processing actions to perform on that data. For example, you > > manually key in a file name containing test data, or copy and paste > > that same file name. Then you select "open file by that name" or > > "load all lines from file by that name" etc. from a menu. If you > > just opened the file, you now have a stream of input, and you can > > select to read one line or one s-expression or one character etc. > > from that file. After loading the whole file or one unit of data, > > you now have some *real* data to work from. For example, with a > > line of input, you might break it into words. > Processing a single data file is a common programming task, but > not the only general category. That was just an example, but in fact often when devising algorithms the sample test input data *is* given either in a disk file or in a Web page, so when writing *most* of the code, the input data might indeed come from such a test-data-file, even though the finished algorithm will in practice get its data *live* from some other source such as the URL-encoded form contents. For purpose of teaching absolute-beginning computer algorithm design, I think working from a disk-file of test-data is sufficiently general. That test-data file can in fact have either the URL-encoded form contents, or associative arrays for GET and POST and COOKIE already decoded as given. Then later after the student practices setting up CGI-hello-world demos on his/her own personal Web site, simply putting the two pieces together is enough to achieve an online server-side Web application. > A specialized Visual Data Analysis with Python might be a better > and more focused project. How would that be presented to the user via CGI or PHP? > When I was doing statistical data analysis on a daily basis for a > living, I would have loved to have had a system that would read > in the first line and let me define (and name) the fields by > point and click. (I usually worked with fixed-width, > column-delimited fields.) The first task is to *recognize* the boundaries between the various column-delimited fields. If there is always a blank column between adjacent data columns, and there's never an accidental blank column throughout all rows of any data column, it's pretty simple by algorithm to find where the columns are located, so as to show the user the columns already delimited and then all the user has to do is name each one (and if the first row is column headers, with no repeat names, then even the naming can be done automatically). 2008.Aug I wrote such a column-finder function-set in Lisp: ;Given a list of rows of the table, such as lines read from a file: ;Build an array of column counts. Each count is the number of lines that ; have non-white in that column. Short lines don't ever count past the ; end, hence as if all white after end. ;Note: Omit any header line(s) when passing data to this function, ; so that only the actual data columns will be tabulated. ;Return that array, of length exactly equal to the longest line in the list. (defun lines-count-nonwhite-cols (lines) ...) ;Given an array listing counts of non-white characters per column: ;Find start and end of each non-white multi-column. ;Return alternating list (startix1 endix1 startix2 endix2 ...) (defun arrcolnw-to-ixpairs (arr) ...) ;Given alternating list of start..end indices for multi-columns: ;Make a function object to parse strings per those multi-columns. (defun ixpairs-make-splitter-function-object (ixpairs) ...) Those three together effect a parse of each line into a vector, whereby positional indexing can pull out the nth field of each. Then to automatically match user-defined column-header strings against column headers given as top line of the file: ;Given the parsed form of the header line, hopefully with each field ; trimmed already, and a list of strings that are supposed to match ; some of these fields: ;Make sure each given string actually does match one of the fields. ;Note: The given string need only be a substring of the field name. ;Return a list of corresponding indexes into the record. (defun hdrrec+hdrstrs-find-field-indexes (hdrrec hdrstrs) ...) Now we have a way to map user-defined names to fields within records, thus retrieve a field by name instead of index. The rest of 2008-8-cols.lisp was a specific application of that to parsing and further processing of the report from FileList, which is a directory listing for Macintosh. Here's what one of those reports looks like (just the header line and a few file-lines): FILE NAME TYPE CREA BYTES CREATED MODIFIED VOLUME PATH About System 7.5 ttro ttxt 22032 96/05/31 12:00:00 96/05/31 12:00:00 HD: About System 7.5.5 Update ttro ttxt 17592 96/09/11 12:00:00 96/09/11 12:00:00 HD: About the Control Panels folder ttro ttxt 16410 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:About the MacOS: About the Extensions folder ttro ttxt 20558 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:About the MacOS: About the System Folder ttro ttxt 4618 96/01/17 12:00:00 96/01/17 12:00:00 HD:Apple Extras:About the MacOS: AppleCD Audio Player APPL aucd 141160 95/06/19 12:00:00 95/06/19 12:00:00 HD:Apple Extras:AppleCD Audio Player: AppleCD Audio Player Guide poco reno 114948 95/12/22 12:00:00 95/12/22 12:00:00 HD:Apple Extras:AppleCD Audio Player: About Automated Tasks ttro ttxt 5742 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:AppleScript:Automated Tasks: Add Alias to Apple Menu APPL dplt 8559 94/08/02 00:00:00 94/08/02 00:00:00 HD:Apple Extras:AppleScript:Automated Tasks: Find Original from Alias APPL dplt 8580 94/08/02 00:00:00 94/08/02 00:00:00 HD:Apple Extras:AppleScript:Automated Tasks: .. Note the blank column between "Apple" and "Extras" in the last field, which would cause that field to appear to be two different fields, if this were the *whole* datafile. There are various work-arounds for such a case if it occurs. > Instead, I had to write a format statement and some summary > analysis code, run it, look at it for sanity, and decide if my > format had been correct. Pain! Too bad you didn't have 2008-8-cols.lisp available to use, and didn't think to invent something similar yourself. From newptcai at gmail.com Sun Nov 22 07:03:30 2009 From: newptcai at gmail.com (=?UTF-8?B?5LiA6aaW6K+X?=) Date: Sun, 22 Nov 2009 04:03:30 -0800 (PST) Subject: Why Python allows comparison of a callable and a number? Message-ID: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> I used python to write an assignment last week, here is a code snippet #================================ def departTime(): ''' Calculate the time to depart a packet. ''' if(random.random < 0.8): t = random.expovariate(1.0 / 2.5) else: t = random.expovariate(1.0 / 10.5) return t #================================ Can you see the problem? I compare random.random with 0.8, which should be random.random(). Of course this because of my careless, but I don't get it. In my opinion, this kind of comparison should invoke a least a warning in any programming language. So why does python just ignore it? From clp2 at rebertia.com Sun Nov 22 07:09:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Nov 2009 04:09:08 -0800 Subject: Why Python allows comparison of a callable and a number? In-Reply-To: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> References: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> Message-ID: <50697b2c0911220409m420b6747i54396f7e67d9f9de@mail.gmail.com> On Sun, Nov 22, 2009 at 4:03 AM, ??? wrote: > I used python to write an assignment last week, here is a code snippet > > #================================ > > def departTime(): > ? ?''' > ? ?Calculate the time to depart a packet. > ? ?''' > ? ?if(random.random < 0.8): > ? ? ? ?t = random.expovariate(1.0 / 2.5) > ? ?else: > ? ? ? ?t = random.expovariate(1.0 / 10.5) > ? ?return t > > #================================ > > Can you see the problem? ?I compare random.random with 0.8, ?which > should be random.random(). > > Of course this because of my careless, but I don't get it. ?In my > opinion, this kind of comparison should invoke a least a warning in > any programming language. > > So why does python just ignore it? It's an historical anomaly that's been rectified in Python 3, where such non-equality comparisons between unrelated types *do* now raise an error. Cheers, Chris -- http://blog.rebertia.com From paul.nospam at rudin.co.uk Sun Nov 22 07:20:45 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 22 Nov 2009 12:20:45 +0000 Subject: Imitating "tail -f" References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: <87ws1i3g4i.fsf@rudin.co.uk> Matt Nordhoff writes: > Jason Sewall wrote: >> FWIW, GNU tail on Linux uses inotify for tail -f: >> >> http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c >> >> The wikipedia page for inotify lists several python bindings: >> >> http://en.wikipedia.org/wiki/Inotify >> >> Not much help for non-Linux users, but there it is. Too bad, because >> inotify is pretty cool. >> >> Jason > > Some other operating systems have similar facilities, e.g. FSEvents on OS X. Yeah, and there's a similar kind of thing in the windows api. A nice python project would be a cross-platform solution that presented a uniform api and just did the right thing behind the scenes on each OS. (Incidentally on linux you need to watch out for the value of /proc/sys/fs/inotify/max_user_watches - if you're using inotify in anger it's easy to exceed the default set by a lot of distributions.) From davea at ieee.org Sun Nov 22 07:28:55 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 07:28:55 -0500 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B092E87.9060904@ieee.org> n00m wrote: > Any comment: > > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 > > > The second part of the compound if is backwards. So if this is headed for production code, it better get fixed. DaveA From bnrj.rudra at gmail.com Sun Nov 22 07:30:38 2009 From: bnrj.rudra at gmail.com (rudra) Date: Sun, 22 Nov 2009 04:30:38 -0800 (PST) Subject: plotting arrow in python References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> <7ms299F3jvhbiU1@mid.individual.net> Message-ID: On Nov 22, 6:58?am, Gregory Ewing wrote: > > rudra wrote: > > >> 0.0 0.0 0.1 > >> 0.0 0.1 0.1 > >> 0.1 0.0 0.5 > > >> like that! the first two column are coordinate and 3rd one is > >> magnitude of moment (say: x y,m)!! so what i want to do is draw an > >> arrow of magnitude(m) in the position (x,y). > > There seems to be some information missing there. > How do you know what direction to draw the arrow in? > > -- > Greg Greg, you are right direction is also needed. But as a beginner, I am trying to make it simple and all arrows are collinear along x axis!! then i have to try non collinear as well. thank you From n00m at narod.ru Sun Nov 22 07:45:54 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 04:45:54 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: > Do you get the same magnitude difference > if you make Vector a new-style class? Yes (I mean "No"): new-style's much faster And now it's elephants instead of vectors. Def: an elephant is smarter than another one IIF its size is strictly less but its IQ is strictly greater I.e. you can't compare (2, 8) to (20, 50) or let count them as equally smart elephants. ================================================ class Elephant(object): def __init__(self, size, iq): self.size = size self.iq = iq def __cmp__(self, e): if self.size < e.size and self.iq > e.iq: return -1 if self.size > e.size and self.iq < e.iq: return 1 return 0 def e_cmp(e1, e2): if e1.size < e2.size and e1.iq > e2.iq: return -1 if e1.size > e2.size and e1.iq < e2.iq: return 1 return 0 from random import randint from time import time a = [] for i in xrange(200000): a.append(Elephant(randint(1, 50000), randint(1, 50000))) b = a[:] c = a[:] print 'Sorting...' t = time() b.sort(cmp=e_cmp) print time() - t t = time() c.sort() print time() - t print b == c >>> ===================================== RESTART ===== >>> Sorting... 1.56299996376 1.95300006866 True From n00m at narod.ru Sun Nov 22 07:49:46 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 04:49:46 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> > The second part of the compound if is backwards. ?So if this is headed > for production code, it better get fixed. > > DaveA Not sure I'm understanding your remark. From jelle at smetj.net Sun Nov 22 08:58:09 2009 From: jelle at smetj.net (Jelle Smet) Date: Sun, 22 Nov 2009 14:58:09 +0100 Subject: python regex "negative lookahead assertions" problems Message-ID: <58e207482b8723b1adf21a2345eb3396@smetj.net> Hi List, I'm trying to match lines in python using the re module. The end goal is to have a regex which enables me to skip lines which have ok and warning in it. But for some reason I can't get negative lookaheads working, the way it's explained in "http://docs.python.org/library/re.html". Consider this example: Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>> re.match('.*(?!warning)',line) <_sre.SRE_Match object at 0xb75b1598> I would expect that this would NOT match as it's a negative lookahead and warning is in the string. Thanks, -- Jelle Smet http://www.smetj.net From g.ricioppo at gmail.com Sun Nov 22 09:36:09 2009 From: g.ricioppo at gmail.com (Kill Joy) Date: Sun, 22 Nov 2009 06:36:09 -0800 (PST) Subject: MySQLdb Message-ID: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Hi all. I have a mod_python script with two query: cursor = db.cursor() sql = 'SELECT * FROM users where username=\'' + username +'\'' cursor.execute(sql) result = cursor.fetchall() num = int(cursor.rowcount) if num == 0 : sql2 = 'insert into users values (null, \'' + username + '\', \'' + password +'\', \'no\',\'fdfdf\')' cursor.execute(sql2) warning = "Registration ok" else : warning = "EXIST!" The first query is executed... but not the second. It doesn't insert. Why? I'm a newbie... sorry. Many thanks. K From python.list at tim.thechases.com Sun Nov 22 09:52:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 22 Nov 2009 08:52:39 -0600 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <58e207482b8723b1adf21a2345eb3396@smetj.net> References: <58e207482b8723b1adf21a2345eb3396@smetj.net> Message-ID: <4B095037.9010901@tim.thechases.com> >>>> import re >>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>> re.match('.*(?!warning)',line) > <_sre.SRE_Match object at 0xb75b1598> > > I would expect that this would NOT match as it's a negative lookahead and warning is in the string. This first finds everything (".*") and then asserts that "warning" doesn't follow it, which is correct in your example. You may have to assert that "warning" doesn't exist at every point along the way: re.match(r'(?:(?!warning).)*',line) which will match up-to-but-not-including the "warning" text. If you don't want it at all, you'd have to also anchor the far end re.match(r'^(?:(?!warning).)*$',line) but in the 2nd case I'd just as soon invert the test: if 'warning' not in line: do_stuff() -tkc From geraldwalkerx at gmail.com Sun Nov 22 10:00:03 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Sun, 22 Nov 2009 10:00:03 -0500 Subject: MySQLdb In-Reply-To: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> References: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Message-ID: Kill Joy wrote: > Hi all. > > I have a mod_python script with two query: > > cursor = db.cursor() > > sql = 'SELECT * FROM users where username=\'' + username +'\'' > cursor.execute(sql) > result = cursor.fetchall() > num = int(cursor.rowcount) > > if num == 0 : > sql2 = 'insert into users values (null, \'' + username + '\', \'' + > password +'\', \'no\',\'fdfdf\')' > cursor.execute(sql2) db.commit() > warning = "Registration ok" > > else : > warning = "EXIST!" > > The first query is executed... but not the second. It doesn't insert. > Why? > I'm a newbie... sorry. > > Many thanks. > I added db.commit() after cursor.execute(sql2). From g.ricioppo at gmail.com Sun Nov 22 10:03:18 2009 From: g.ricioppo at gmail.com (Kill Joy) Date: Sun, 22 Nov 2009 07:03:18 -0800 (PST) Subject: MySQLdb References: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Message-ID: On 22 Nov, 16:00, Gerald Walker wrote: > Kill Joy wrote: > > Hi all. > > > I have a mod_python script with two query: > > > ? ?cursor = db.cursor() > > > ? ?sql = 'SELECT * FROM users where username=\'' + username +'\'' > > ? ?cursor.execute(sql) > > ? ?result = cursor.fetchall() > > ? ?num = ?int(cursor.rowcount) > > > ? ?if num == 0 : > > ? ? ? ? ? ?sql2 = 'insert into users values (null, \'' + username + '\', \'' + > > password +'\', \'no\',\'fdfdf\')' > > ? ? ? ? ? ?cursor.execute(sql2) > > ? ? ? ? ? ? ? ? db.commit() > > > ? ? ? ? ? ?warning = "Registration ok" > > > ? ?else : > > ? ? ? ? ? ?warning = "EXIST!" > > > The first query is executed... but not the second. It doesn't insert. > > Why? > > I'm a newbie... sorry. > > > Many thanks. > > I added db.commit() after cursor.execute(sql2). ohhh... many thanks many thanks. Gius. From jarausch at skynet.be Sun Nov 22 10:05:47 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Sun, 22 Nov 2009 16:05:47 +0100 Subject: python regex "negative lookahead assertions" problems In-Reply-To: References: Message-ID: <4b09534c$0$2868$ba620e4c@news.skynet.be> On 11/22/09 14:58, Jelle Smet wrote: > Hi List, > > I'm trying to match lines in python using the re module. > The end goal is to have a regex which enables me to skip lines which have ok and warning in it. > But for some reason I can't get negative lookaheads working, the way it's explained in "http://docs.python.org/library/re.html". > > Consider this example: > > Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import re >>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>> re.match('.*(?!warning)',line) > <_sre.SRE_Match object at 0xb75b1598> > > I would expect that this would NOT match as it's a negative lookahead and warning is in the string. > '.*' eats all of line. Now, when at end of line, there is no 'warning' anymore, so it matches. What are you trying to achieve? If you just want to single out lines with 'ok' or warning in it, why not just if re.search('(ok|warning)') : call_skip Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From duncan.booth at invalid.invalid Sun Nov 22 10:08:28 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Nov 2009 15:08:28 GMT Subject: Sorting: too different times. Why? References: Message-ID: n00m wrote: > And now it's elephants instead of vectors. > Def: an elephant is smarter than another one IIF > its size is strictly less but its IQ is strictly > greater > > I.e. you can't compare (2, 8) to (20, 50) > or let count them as equally smart elephants. and that still isn't a relationship where you can get any meaningful order out of sorting them: >>> Elephant(1, 20) < Elephant(2, 10) True >>> Elephant(1, 20) == Elephant(2, 20) == Elephant(2, 10) True From sajmikins at gmail.com Sun Nov 22 10:55:08 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 22 Nov 2009 10:55:08 -0500 Subject: parallel class structures for AST-based objects In-Reply-To: <7msfr3F3j1ilfU1@mid.uni-berlin.de> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> <7msfr3F3j1ilfU1@mid.uni-berlin.de> Message-ID: <50f98a4c0911220755l53768729n62b982df03075474@mail.gmail.com> On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch wrote: > Steve Howell schrieb: >> >> On Nov 21, 4:07 pm, MRAB wrote: >>> >>> I don't see the point of EvalNode and PrettyPrintNode. Why don't you >>> just give Integer, Sum and Product 'eval' and 'pprint' methods? >> >> That's a good question, and it's the crux of my design dilemma. ?If >> ALL I ever wanted to to with Integer/Sum/Product was to eval() and >> pprint(), then I would just add those methods to Integer, Sum, and >> Product, and be done with it, as you suggest. ?But what happens when >> somebody wants to extend capability? ?Should every future software >> developer that wants to use Integer/Sum/Product extend those classes >> to get work done? ?What if they want to store additional state for >> nodes? >> > > What's usually done is to create visitors/matchers. Those traverse the AST, > and either only visit, or return transformed versions of it (think e.g. > algebraic optimization) > > A visitor will roughly look like this: > > > class ASTVisitor(object): > > > > ? def visit(self, node): > ? ? ? name = node.__class__.__name__.lower() > ? ? ? if hasattr(self, "visit_%s" % name): > ? ? ? ? ? getattr(self, "visit_%s" % name)(node) > ? ? ? for child in node: > ? ? ? ? ? self.visit(child) > > > > You can of course chose another type of dispatch, using e.g. a generic > method. > > Then you create Visitors for specific tasks - pretty-printing, evaluation, > rewriting. Those don't have the overhead of your current design with all > those factory-mapping stuff, and yet you aren't forced to put logic into AST > you don't want there. > FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting Kit) for this sort of thing. It has a GenericASTTraversal which "is a Visitor pattern according to Design Patterns." http://pages.cpsc.ucalgary.ca/~aycock/spark/ It's apparently distributed with the python source, but it's not in the standard library, more's the pity IMO. There's a bit of a learning curve but it's well worth it. ~Simon From python at mrabarnett.plus.com Sun Nov 22 11:17:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:17:12 +0000 Subject: Sorting: too different times. Why? In-Reply-To: <031908a0$0$1336$c3e8da3@news.astraweb.com> References: <031908a0$0$1336$c3e8da3@news.astraweb.com> Message-ID: <4B096408.2000601@mrabarnett.plus.com> Steven D'Aprano wrote: > In the subject line, you write "too different times". You actually want > "two", the number, not "too" as in "too many", "too much". Lots of native > English speakers get this wrong too :) > [snip] It could mean that the times are not just different, they're _too_ different, ie a lot more than they are expected to be. From python at mrabarnett.plus.com Sun Nov 22 11:23:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:23:26 +0000 Subject: Why Python allows comparison of a callable and a number? In-Reply-To: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> References: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> Message-ID: <4B09657E.2090405@mrabarnett.plus.com> ??? wrote: > I used python to write an assignment last week, here is a code snippet > > #================================ > > def departTime(): > ''' > Calculate the time to depart a packet. > ''' > if(random.random < 0.8): > t = random.expovariate(1.0 / 2.5) > else: > t = random.expovariate(1.0 / 10.5) > return t > > #================================ > > Can you see the problem? I compare random.random with 0.8, which > should be random.random(). > > Of course this because of my careless, but I don't get it. In my > opinion, this kind of comparison should invoke a least a warning in > any programming language. > > So why does python just ignore it? In Python 2 you can compare any 2 objects, for example an int with a string. The result is arbitrary but consistent. In Python 3 if the 2 objects aren't 'compatible' you'll get a TypeError at runtime. BTW, you don't need to put parentheses around the conditions in 'if' and 'while' statements. Python isn't C, etc. :-) From n00m at narod.ru Sun Nov 22 11:23:53 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 08:23:53 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: Here "meaningful order" is: if elephant "a[i]" is smarter than elephant "a[j]" then "i" must be strictly less than "j" Of course, to the same effect we could sort them simply by sizes, but then time of sorting would increase by ~ 2 times -- due to decreasing of number of equally smart things. But here it does not matter -- for my initial question. I like all above explanations. Especially that by Chris Rebert. From n00m at narod.ru Sun Nov 22 11:26:59 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 08:26:59 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: :-) Of course, by "too" I meant "too", as in "tooooo much" From python at mrabarnett.plus.com Sun Nov 22 11:32:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:32:49 +0000 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <4B095037.9010901@tim.thechases.com> References: <58e207482b8723b1adf21a2345eb3396@smetj.net> <4B095037.9010901@tim.thechases.com> Message-ID: <4B0967B1.80408@mrabarnett.plus.com> Tim Chase wrote: >>>>> import re >>>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh >>>>> qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf >>>>> lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>>> re.match('.*(?!warning)',line) >> <_sre.SRE_Match object at 0xb75b1598> >> >> I would expect that this would NOT match as it's a negative lookahead >> and warning is in the string. > > This first finds everything (".*") and then asserts that "warning" > doesn't follow it, which is correct in your example. You may have to > assert that "warning" doesn't exist at every point along the way: > > re.match(r'(?:(?!warning).)*',line) > > which will match up-to-but-not-including the "warning" text. If you > don't want it at all, you'd have to also anchor the far end > > re.match(r'^(?:(?!warning).)*$',line) > > but in the 2nd case I'd just as soon invert the test: > > if 'warning' not in line: > do_stuff() > The trick is to think what positive lookahead you'd need if you wanted check whether 'warning' is present: '(?=.*warning)' and then negate it: '(?!.*warning)' giving you: re.match(r'(?!.*warning)', line) From python at mrabarnett.plus.com Sun Nov 22 11:44:16 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:44:16 +0000 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B096A60.3030607@mrabarnett.plus.com> n00m wrote: > :-) Of course, by "too" I meant "too", as in "tooooo much" Although it's OK in English to say "too much x" or "too many x", it's somewhat unnatural to say "too different xs"; it would have to be "the xs are too different". Nobody said English was logical! :-) From n00m at narod.ru Sun Nov 22 12:15:57 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 09:15:57 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> > it's somewhat unnatural to say "too different xs" Aha. Thanks. PS For years I thought that song's title "No Woman No Cry" by Bob Marley means "No Woman -- No Cry". As if a man got rid of his woman and stopped crying, out of her bad behaviour etc. It turned out to mean "No, woman,.. no cry..." Or take "Drips" by Eminem. What on earth do the drips mean? Album: The Eminem Show Song: Drips [Eminem] Obie.. yo [Trice] {*coughing*} I'm sick [Eminem] Damn, you straight dog? [Chorus] That's why I ain't got no time for these games and stupid tricks or these bitches on my dick That's how dudes be gettin sick That's how dicks be gettin drips Fallin victims to this shit... ... ... From showell30 at yahoo.com Sun Nov 22 12:27:08 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 09:27:08 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> <7msfr3F3j1ilfU1@mid.uni-berlin.de> Message-ID: On Nov 22, 7:55?am, Simon Forman wrote: > On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch wrote: > > > > > Steve Howell schrieb: > > >> On Nov 21, 4:07 pm, MRAB wrote: > > >>> I don't see the point of EvalNode and PrettyPrintNode. Why don't you > >>> just give Integer, Sum and Product 'eval' and 'pprint' methods? > > >> That's a good question, and it's the crux of my design dilemma. ?If > >> ALL I ever wanted to to with Integer/Sum/Product was to eval() and > >> pprint(), then I would just add those methods to Integer, Sum, and > >> Product, and be done with it, as you suggest. ?But what happens when > >> somebody wants to extend capability? ?Should every future software > >> developer that wants to use Integer/Sum/Product extend those classes > >> to get work done? ?What if they want to store additional state for > >> nodes? > > > What's usually done is to create visitors/matchers. Those traverse the AST, > > and either only visit, or return transformed versions of it (think e.g. > > algebraic optimization) > > > A visitor will roughly look like this: > > > class ASTVisitor(object): > > > ? def visit(self, node): > > ? ? ? name = node.__class__.__name__.lower() > > ? ? ? if hasattr(self, "visit_%s" % name): > > ? ? ? ? ? getattr(self, "visit_%s" % name)(node) > > ? ? ? for child in node: > > ? ? ? ? ? self.visit(child) > > > You can of course chose another type of dispatch, using e.g. a generic > > method. > > > Then you create Visitors for specific tasks - pretty-printing, evaluation, > > rewriting. Those don't have the overhead of your current design with all > > those factory-mapping stuff, and yet you aren't forced to put logic into AST > > you don't want there. > > FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting > Kit) for this sort of thing. ?It has a GenericASTTraversal which "is a > Visitor pattern according to Design Patterns." > > http://pages.cpsc.ucalgary.ca/~aycock/spark/ > > It's apparently distributed with the python source, but it's not in > the standard library, more's the pity IMO. > > There's a bit of a learning curve but it's well worth it. > Thanks, Simon, I think something like GenericASTTraversal should work for me in most cases. A couple of folks have suggested an idea that is in his paper, which is to use a single class for something PrettyPrinter, and then use reflection to find methods on PrettyPrinter to pretty-print sums, products, integers, etc. From news123 at free.fr Sun Nov 22 12:32:03 2009 From: news123 at free.fr (News123) Date: Sun, 22 Nov 2009 18:32:03 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) Message-ID: <4b097593$0$30269$426a74cc@news.free.fr> Hi, I'm trying to scan a document from a python 2.6 script without user interaction. I found a code snippet, that allows me to scan under Vista, but that doesn't allow me to select the dpi / color mode / etc. The snippet uses win32com.client # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end My problems are: - This script works fine for me under Windows 7, however I'm unable to specify additional parameters, like dpi and color mode. - The script doesn't work under windows XP, though the scanner driver is installed. (Gimp finds the scanner (as WIA scanner)). Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL. The error message is: -------------------------------------------------------------------- Traceback (most recent call last): File "C:\work\python\minidemos\wia_get_simple.py", line 7, in wia = win32com.client.Dispatch("WIA.CommonDialog") File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid class string', None, None) --------------------------------------------------------------------- As I have no knowledge of Win32com and WIA I would appreciate some help or good documentation about wincom32 / WIA with python thanks for your help and bye N From victorsubervi at gmail.com Sun Nov 22 12:39:10 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 22 Nov 2009 12:39:10 -0500 Subject: Scripts Only Run In Root Message-ID: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Hi; I can only run my python scripts on my server if they are owned by root. How do I change that? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sun Nov 22 12:48:45 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 04:48:45 +1100 Subject: Sorting: too different times. Why? In-Reply-To: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> References: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> Message-ID: <4b0979d3$1@dnews.tpgi.com.au> n00m wrote: >> The second part of the compound if is backwards. So if this is headed >> for production code, it better get fixed. >> >> DaveA > > Not sure I'm understanding your remark. Maybe he meant, that this: if v1.x < v2.x and v1.y > v2.y should be: if v1.x < v2.x and v1.y < v2.y ? From lutfioduncuoglu at gmail.com Sun Nov 22 12:59:29 2009 From: lutfioduncuoglu at gmail.com (Lutfi Oduncuoglu) Date: Sun, 22 Nov 2009 19:59:29 +0200 Subject: TypeError: an integer is required Message-ID: Hello, I am a newbie on oython and I am taking the error at subject my code is below, I am trying to develop a qgis plugin and lines begin with # is the thing that I tried. Thus sys.stdout gives the type error. When I comment that line it turns an error like below. What may be the problem? thanks for help:) ...\ReadData.py", line 128, in run print "%d %s" %(k, attr.toString()) IOError: [Errno 9] Bad file descriptor # Import the PyQt and QGIS libraries from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from os import * from qgis.gui import * import sys import pdb # Initialize Qt resources from file resources.py import resources # Import the code for the dialog from ReadDataDialog import ReadDataDialog class ReadData: def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface def initGui(self): # Create action that will start plugin configuration self.action = QAction(QIcon(":/plugins/readdata/icon.png"), \ "Read shp for calculations", self.iface.mainWindow()) # connect the action to the run method QObject.connect(self.action, SIGNAL("triggered()"), self.run) # Add toolbar button and menu item self.iface.addToolBarIcon(self.action) self.iface.addPluginToMenu("&Read shp for calculations", self.action) def unload(self): # Remove the plugin menu item and icon self.iface.removePluginMenu("&Read shp for calculations",self.action) self.iface.removeToolBarIcon(self.action) # run method that performs all the real work def run(self): # fileName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select a file:"),"", "*.shp *.gml") # if fileName.isNull(): # QMessageBox.information(None, "Cancel", "File selection canceled") # else: # print fileName vlayer = QgsVectorLayer("C:\\Users\\lutfi\\Documents\\tezzzz\\deneme2\\ownership.shp", "hebe", "ogr") print vlayer.source() print vlayer.featureCount() QgsMapLayerRegistry.instance().addMapLayer(vlayer) QMessageBox.information(self.iface.mainWindow(), "info", "file: "+str(vlayer.source())+" is added.") if not vlayer.isValid(): print "Couldn't open the layer" pdb.set_trace() else: # QMessageBox.information(None, "Cancel", "File selection canceled") provider = vlayer.dataProvider() feat = QgsFeature() allAttrs = provider.attributeIndexes() provider.select(allAttrs) while provider.nextFeature(feat): geom = feat.geometry() import sys import os # win32api.SetFileAttributes('C://Users//lutfi//Documents//tezzzz//log.txt', win32con.FILE_ATTRIBUTE_NORMAL) # sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt', 777 ) print geom # QMessageBox.information(None, "Cancel", "File selection canceled") print "Feature ID %d: " % feat.id() if geom.type() == QGis.Point: x = geom.asPoint() print "Point: " + str(x) elif geom.type() == QGis.Line: x = geom.asPolyline() print "Line: %d points" % len(x) elif geom.type() == QGis.Polygon: x = geom.asPolygon() numPts = 0 for ring in x: numPts += len(ring) print "Polygon: %d rings with %d points" % (len(x), numPts) else: print "Unknown" attrs = feat.attributeMap() for (k,attr) in attrs.iteritems(): sys.stdout = os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) print "%d %s" %(k, attr.toString()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Sun Nov 22 13:28:43 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 13:28:43 -0500 Subject: Sorting: too different times. Why? In-Reply-To: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> References: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> Message-ID: <4B0982DB.8090004@ieee.org> n00m wrote: >> The second part of the compound if is backwards. So if this is headed >> for production code, it better get fixed. >> >> DaveA >> > > Not sure I'm understanding your remark. > > Well, others in the thread have observed the same thing, so maybe it doesn't matter. But the quoted code had only one if statement: >>def v_cmp(v1, v2): >> if v1.x < v2.x and v1.y > v2.y: >> return -1 >> return 0 And the first part of the compound if is a "<" comparison, while the second part is a ">" comparison This produces a different sort order than the default tuple comparison. So it needs fixing. DaveA From python at mrabarnett.plus.com Sun Nov 22 13:29:25 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 18:29:25 +0000 Subject: TypeError: an integer is required In-Reply-To: References: Message-ID: <4B098305.7060901@mrabarnett.plus.com> Lutfi Oduncuoglu wrote: > Hello, > > I am a newbie on oython and I am taking the error at subject my code is > below, I am trying to develop a qgis plugin and lines begin with # is > the thing that I tried. Thus sys.stdout gives the type error. When I > comment that line it turns an error like below. What may be the problem? > thanks for help:) > > ...\ReadData.py", line 128, in run > print "%d %s" %(k, attr.toString()) > IOError: [Errno 9] Bad file descriptor > > [snip] > > for (k,attr) in attrs.iteritems(): > sys.stdout = > os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) > print "%d %s" %(k, attr.toString()) > I think the problem is that you're binding a low-level file id to sys.stdout instead of a file object. Try: sys.stdout = open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) Actually, changing sys.stdout just to use print a single string is a bad idea. Try this instead: log_file = open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) print >> log_file, "%d %s" %(k, attr.toString()) log_file.close() From debatem1 at gmail.com Sun Nov 22 13:36:56 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 22 Nov 2009 13:36:56 -0500 Subject: Scripts Only Run In Root In-Reply-To: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Message-ID: On Sun, Nov 22, 2009 at 12:39 PM, Victor Subervi wrote: > Hi; > I can only run my python scripts on my server if they are owned by root. How > do I change that? > TIA, > Victor Almost certainly going to need more information. On that note, you are probably going to get better help with less explaining from the appropriate OS support channels. Geremy Condra From lie.1296 at gmail.com Sun Nov 22 13:41:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 05:41:08 +1100 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <4b098619$1@dnews.tpgi.com.au> eric.frederich wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? It is recommended? Should I just stop worrying > about it and have a 5,000 line class? If you're not joking about the 5000 lines estimation, then with 50 methods, each method would be ~100 lines? That stinks of huge refactoring. From aahz at pythoncraft.com Sun Nov 22 13:44:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Nov 2009 10:44:23 -0800 Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: In article <7ms7ctF3k2a79U1 at mid.individual.net>, Gregory Ewing wrote: > >However, Go's designers seem to favour using the absolute minimum >number of characters they can get away with. > >Although if they *really* wanted that, they would have dropped most of >the semicolons and used indentation-based block structure instead of >curly braces. I would have forgiven them several other sins if they'd >done that. :-) That's essentially my issue with Go based on the code samples I've seen: no over-arching design sensibility at the syntax level. It looks like an aggolomeration of semi-random C-like syntax. There's nothing that shouts out, "This is a Go program," unlike Python, C, and even Perl. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sun Nov 22 13:53:44 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 05:53:44 +1100 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> Message-ID: <4b09890d$1@dnews.tpgi.com.au> Peng Yu wrote: > On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >>> http://www.python.org/dev/peps/pep-0008/ >>> >>> The above webpage states the following naming convention. Such a >>> variable can be an internal variable in a class. I'm wondering what is >>> the naming convention for the method that access such variable. >>> >>> - _single_leading_underscore: weak "internal use" indicator. E..g. "from M >>> import *" does not import objects whose name starts with an underscore. >> If there's a method to access the variable, then it's not all that >> private, is it? >> Accessor methods are not Pythonic. Just make the attribute public by >> not prefixing it with an underscore. >> >> See also "Python is Not Java": >> http://dirtsimple.org/2004/12/python-is-not-java.html > > I don't quite understand the following paragraph from the above > webpage. Would you please give me an example to help me understand it? > > "Here's what you do. You write a function that contains a function. > The inner function is a template for the functions that you're writing > over and over again, but with variables in it for all the things that > vary from one case of the function to the next. The outer function > takes parameters that have the same names as those variables, and > returns the inner function. Then, every place where you'd otherwise be > writing yet another function, simply call the outer function, and > assign the return value to the name you want the "duplicated" function > to appear. Now, if you need to change how the pattern works, you only > have to change it in one place: the template." Basically it sums to (pun not intended): def adder(by): def _adder(num): return num + by return _adder add4 = adder(4) add10 = adder(10) add35 = adder(35) add1 = adder(1) in java, you'll need to manually duplicate the code, equivalent to doing: def add4(num): return num + 4 def add10(num): return num + 10 def add35(num): return num + 35 def add1(num): return num + 1 or passes two arguments (which completely misses the point). From mwilson at the-wire.com Sun Nov 22 13:57:38 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 22 Nov 2009 13:57:38 -0500 Subject: Sorting: too different times. Why? References: Message-ID: MRAB wrote: > n00m wrote: >> :-) Of course, by "too" I meant "too", as in "tooooo much" > > Although it's OK in English to say "too much x" or "too many x", it's > somewhat unnatural to say "too different xs"; it would have to be "the > xs are too different". Nobody said English was logical! :-) Now that James Joyce has written _Finnegans Wake_ there are no grammar errors and there are no spelling errors. There are only unexpected meanings. Mel. From victorsubervi at gmail.com Sun Nov 22 13:59:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 22 Nov 2009 13:59:39 -0500 Subject: Scripts Only Run In Root In-Reply-To: <23739e0a0911221030i3854f0fdhec90e1f88681aed@mail.gmail.com> References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> <23739e0a0911221030i3854f0fdhec90e1f88681aed@mail.gmail.com> Message-ID: <4dc0cfea0911221059t60cce481kf4a2d82da73e3c37@mail.gmail.com> On Sun, Nov 22, 2009 at 1:30 PM, Martijn Arts wrote: > If it's a UNIX server you can use Chown in the command line. Try "man > chown" first to see how it works. > This is strange. I'd tried chown'ing before and was always getting 403 errors. Just to make sure that's what the problem was, I did it again and now it works (?!). Ah, well. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sun Nov 22 15:33:34 2009 From: rt8396 at gmail.com (r) Date: Sun, 22 Nov 2009 12:33:34 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <35cb6163-0edc-4d4a-a562-4f8fc8a1ebbb@31g2000vbf.googlegroups.com> On Nov 22, 11:32 am, News123 wrote: > Hi, > > I'm trying to scan a document from a python 2.6 script without user > interaction. > > I found a code snippet, that allows me to scan under Vista, but that > doesn't allow me to select the dpi / color mode / etc. > > The snippet uses win32com.client Hello, I would also like to know the answer for which i am investigating now, although like yourself i don't know much about the windows API and the MSDN docs aren't helping much :(. All i can understand is that doing anything in windows is a real PITA! I am sure someone (or many) have climbed this mountain before but all of them seemed to have forgotten to leave us the map that shows the easy way up... bummer! The PyWin32extensions are great but lacking detailed information of how to use the thing. And i know some GUI kits like wxPython have Printer support but thats not really what i am talking about here. I want the functionality directly from Python with only win32extentions needed! We need to extend on the great work of PyWin32 *OR* create a new module that will be an abstraction of the Win32 module. The problem with Windows scripting is all the crap you need to do before you can even set parameters. Get a device context or find some cryptic dispatch code, then mull over some even more cryptic options and such. By now your eyeballs are about to pop out of there sockets and your head is ponding from a massive hemorrhage and yet you still have nothing to show for all this jumping through MS hoops!!! There needs to be a drive to make some docs and post them somewhere. This knowledge must be shared! The best place would be in the PyWin32 docs, but i don't expect the creator will do this, he has given us the vehicle now we must forge the path. I am willing to help create this if someone with even a small amount of win32 knowledge could lend their expertise (any takers? send me an email!). I would write all the Python code to implement these actions very easily. (of course i'm not promising ground breaking code here just something that works, but a hack is better than nothing! I think a good start would be two classes for dealing with Printers and Scanners in a very pythonic way (no device contexts!!!), from there the sky is the limit! ##PRINTING RAW STRING## import win32printer printer = win32printer.get_default() if not printer.online(): showerror('', 'Turn it on first you idiot!') sys.exit(1) printer.options.update({ 'orientation':'landscape', 'font':('Times New', 12), 'header':time.ctime(), }) printer.print_raw_string('hello printer, i have have arrived!') ##SCANNING## import win32scanner scanner = win32scanner.get_default() if not scanner.online(): showerror('', 'Turn it on first you idiot!') sys.exit(1) scanner.options['imagetype'] = '.jpg' scanner.scan(file="C:\\tmp\\image1") ##MORE??## All the device context and cryptic mumbo-gumbo are nicly hidden from the user. Of course there will also be option to show dialogs for user input because that will be needed. With this proposed module the bumbling confusion can be avoided. Joe-Scripter can study the source later to learn Win32 more in depth. Yes people i hate windows too, but for now we all have to deal with Windows like it or not! From nobody at nowhere.com Sun Nov 22 15:35:07 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 22 Nov 2009 20:35:07 +0000 Subject: Imitating "tail -f" References: Message-ID: On Sun, 22 Nov 2009 03:43:31 +0100, Ivan Voras wrote: > The problem is: poll() always returns that the fd is ready (without > waiting), but read() always returns an empty string. Actually, it > doesn't matter if I turn O_NDELAY on or off. select() does the same. Regular files are always "ready" for read/write. read() might return EOF, but it will never block (or fail with EAGAIN or EWOULDBLOCK). > Any advice? The Linux version of "tail" uses the Linux-specific inotify_add_watch() mechanism to block waiting for file-modification events. If you don't have access to inotify_add_watch(), you'll just have to keep trying to read from the file, sleep()ing whenever you hit EOF so that you don't tie up the system with a busy-wait. From nobody at nowhere.com Sun Nov 22 15:41:03 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 22 Nov 2009 20:41:03 +0000 Subject: TypeError: an integer is required References: Message-ID: On Sun, 22 Nov 2009 18:29:25 +0000, MRAB wrote: >> os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) > open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) Backslashes need to be doubled; forward slashes don't. From patrickstinson.lists at gmail.com Sun Nov 22 16:38:23 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Sun, 22 Nov 2009 14:38:23 -0700 Subject: xmlrpc idea for getting around the GIL Message-ID: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Has anyone every tried wrapping the CPython lib into a daemon with an RPC mechanism in order to move the GIL out of the process? I have multiple audio threads, each of which use the python interpreter but don't have to interact with each other and can might as well use a separate interpreter handled by a daemon with libpython linked in. I've never used a C xmlrpc lib before and would probably need to set up some shared memory to get it to work. Can anyone suggest a library out there that would at do that sort of thing, maybe with some cross-platform process management? I imagine this is how the multiprocessing module works. From davea at ieee.org Sun Nov 22 16:51:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 16:51:31 -0500 Subject: TypeError: an integer is required In-Reply-To: References: Message-ID: <4B09B263.70206@ieee.org> Lutfi Oduncuoglu wrote: > Hello, > > I am a newbie on oython and I am taking the error at subject my code is > below, I am trying to develop a qgis plugin and lines begin with # is the > thing that I tried. Thus sys.stdout gives the type error. When I comment > that line it turns an error like below. What may be the problem? thanks for > help:) > > ...\ReadData.py", line 128, in run > print "%d %s" %(k, attr.toString()) > IOError: [Errno 9] Bad file descriptor > > (Comment #2 is critical, but I didn't notice it right away. Remove that line "from os import *" and use "import os" instead. ) This error is caused by binding the wrong kind of open to stdout. os.open() returns a file descriptor (integer), while stdout is expected to be a "file" object. As for your previous error "an integer is required" it'd certainly be nice if you showed us the error message. You say it was on a line beginning with "#" but there are many of those, none of them near the present error. Taking a wild guess, I see another open for sys.stdout: sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt', 777 ) But that line causes a "file() argument 2 must be string, not int" error. You want "w" or "a" or something like that, rather than a mysterious 777 for that. Just randomly jumping around in your code, consider what happens if you have the following line: print "%d %s" %(k, attr) and k is a string. Then you'd get: "%d format: a number is required, not str" Well, enough guessing. You need to give a complete traceback, as you did for the "bad file descriptor" And you'd also need to specify Python version, as the messages might be different between your version and the 2.6 that I'm trying it with. Other comments: 1) Are you coming from a java background? In Python you do not need to put everything in a class definition. 2) the "from xxxx import *" form is discouraged, and you use it several times. I know some GUI packages specify it, and there you're best off by following their conventions. But for modules like os, you're asking for trouble. In this case, the built-in open() function that you need is being hidden by the os.open() call, which is not the one you wanted. So you'll get syntax errors and funny runtime errors, just because you're calling different functions that what you think you are. 3) You have import within other defs. This is unnecessary if the module has already been imported (such as sys), and is considered bad form in almost all cases. There are only two common cases where an import might not appear right at the top of the module: A) when you want to conditionally import a module, based on some runtime choice. Example would be to import a Unix version or a Windows version of some module. B) When a module will only be used in some unlikely case, such as in error handling. C) when a module is very slow to import, and you need to speed up startup time. 4) Simplified example code would do two things: A) easier for us to follow, especially those of us that don't happen to use the same libraries that you do. B) by simplifying it, you can frequently find the problem yourself, which is a great way to learn 5) If you have two different error messages, but only have one version of the code, make both tracebacks complete, and make sure we know what's changed between the two versions. HTH, DaveA From fetchinson at googlemail.com Sun Nov 22 16:52:49 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 22 Nov 2009 22:52:49 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Message-ID: > Has anyone every tried wrapping the CPython lib into a daemon with an > RPC mechanism in order to move the GIL out of the process? I have > multiple audio threads, each of which use the python interpreter but > don't have to interact with each other and can might as well use a > separate interpreter handled by a daemon with libpython linked in. > > I've never used a C xmlrpc lib before and would probably need to set > up some shared memory to get it to work. Can anyone suggest a library > out there that would at do that sort of thing, maybe with some > cross-platform process management? > > I imagine this is how the multiprocessing module works. Yes, it does seem you need multiprocessing. That would take advantage of multiple cores and the GIL wouldn't bother you at all. Take a look at http://docs.python.org/library/multiprocessing.html For what you describe (separate tasks running concurrently without communicating) the multiprocessing module would be ideal. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 17:05:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 22:05:08 GMT Subject: Sorting: too different times. Why? References: Message-ID: <0319a37d$0$1336$c3e8da3@news.astraweb.com> On Sun, 22 Nov 2009 15:08:28 +0000, Duncan Booth wrote: > n00m wrote: > >> And now it's elephants instead of vectors. Def: an elephant is smarter >> than another one IIF its size is strictly less but its IQ is strictly >> greater >> >> I.e. you can't compare (2, 8) to (20, 50) or let count them as equally >> smart elephants. > > and that still isn't a relationship where you can get any meaningful > order out of sorting them: Not everything has, or need have, a total order. There are relationships which are only partial (i.e. not all the items are comparable), or missing transitivity. A real-world example is pecking order in chickens, or social hierarchies in general. Using the > operator to mean "higher ranking", you often get non-transitive hierarchies like the following: A > B, C, D, E B > C, E C > D, E D > B, E That is, A > B > C > D > E except that D > B also. Economic preference is also non-transitive: people may prefer X to Y, and prefer Y to Z, but prefer Z to X. It is perfectly legitimate to sort a non-total ordered list, provided you understand the limitations, including that the order you get will depend on the order you started with. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 17:05:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 22:05:11 GMT Subject: Sorting: too different times. Why? References: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> Message-ID: <0319a381$0$1336$c3e8da3@news.astraweb.com> On Sun, 22 Nov 2009 09:15:57 -0800, n00m wrote: > Or take "Drips" by Eminem. What on earth do the drips mean? When you have a cold or flu, your nose drips. Some sexually transmitted diseases make your genitals drip. -- Steven From deets at nospam.web.de Sun Nov 22 17:15:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 23:15:01 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Message-ID: <7mtrf5F3h153dU1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >> Has anyone every tried wrapping the CPython lib into a daemon with an >> RPC mechanism in order to move the GIL out of the process? I have >> multiple audio threads, each of which use the python interpreter but >> don't have to interact with each other and can might as well use a >> separate interpreter handled by a daemon with libpython linked in. >> >> I've never used a C xmlrpc lib before and would probably need to set >> up some shared memory to get it to work. Can anyone suggest a library >> out there that would at do that sort of thing, maybe with some >> cross-platform process management? >> >> I imagine this is how the multiprocessing module works. > > Yes, it does seem you need multiprocessing. That would take advantage > of multiple cores and the GIL wouldn't bother you at all. Take a look > at > > http://docs.python.org/library/multiprocessing.html > > For what you describe (separate tasks running concurrently without > communicating) the multiprocessing module would be ideal. The problem is that the OP has a embedded application running threads. multiprocssing doesn't help there. Diez From perfreem at gmail.com Sun Nov 22 17:49:01 2009 From: perfreem at gmail.com (per) Date: Sun, 22 Nov 2009 14:49:01 -0800 (PST) Subject: creating pipelines in python Message-ID: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> hi all, i am looking for a python package to make it easier to create a "pipeline" of scripts (all in python). what i do right now is have a set of scripts that produce certain files as output, and i simply have a "master" script that checks at each stage whether the output of the previous script exists, using functions from the os module. this has several flaws and i am sure someone has thought of nice abstractions for making these kind of wrappers easier to write. does anyone have any recommendations for python packages that can do this? thanks. From marcglec at free.fr Sun Nov 22 17:50:43 2009 From: marcglec at free.fr (Marc Leconte) Date: Sun, 22 Nov 2009 23:50:43 +0100 Subject: problem manipulating a list belonging to a class Message-ID: <1258930243.11379.8.camel@gondor> Dear all, I have a problem with the following code (ubuntu 8.04, Python 2.5.2): class Toto(object): def __init__(self, number, mylist=[]): self.number=number self.mylist=mylist pass pass listA=Toto(number=1) listB=Toto(number=2) listA.mylist.append(5) print "1) ", listA.mylist print "2) ", listB.mylist >> 1) [5] >> 2) [5] I would have expected >> 1) [5] >> 2) [] Thanks in advance for advice, Marc. From threaderslash at gmail.com Sun Nov 22 17:52:45 2009 From: threaderslash at gmail.com (Threader Slash) Date: Mon, 23 Nov 2009 09:52:45 +1100 Subject: problem with pyqt.. help please... Message-ID: ---------- Forwarded message ---------- From: Jebagnana Das To: python-list at python.org Date: Sat, 21 Nov 2009 19:17:56 +0530 Subject: problem with pyqt.. help please... Hi friends, I've recently changed to ubuntu 9.04.. I've not had any problem with the installation of pyqt as it is available from the ubuntu repositories with umpteen number of packages.. Anyhow i've to download tarball file for python 3.1 and installed it.. I found that PyQt4 supports python 3.1(Am i right?).. I wanted to check the pyqt installation with a sample program.. import sys from PyQt4 import QtGui app=QtGui.QApplication(sys.argv) widget=QtGui.QWidget() widget.resize(250,150) widget.setWindowTitle('Simple') widget.show() sys.exit(app.exec_()) when i issued the command $python simple.py it worked perfectly since it's executed with 2.6 installation.. But when i tried to execute it with $python3 simple.py it showed the error like ImportError: No module named PyQt4 So i searched the sys.path for 2.6 and included /usr/lib/python2.6/dist-packages in python3 sys.path... Now when i tried to run this with python3 the error is like.. ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined symbol: PyString_FromString I got the same error when i tried to execute another program... So can u please tell me how to solve this problem?? Am i heading in the right direction???... Thanks & Regards... Jebagnanadas, Python Learner.. ........................................... it just looks like your problem is on setting your installation paths. Have a look here: http://www.linux.org/docs/ldp/howto/Nvidia-OpenGL-Configuration/instqt.html http://www.linuxforums.org/forum/debian-linux-help/108948-setting-path-qt.html Check and follow the steps. It should fix your problem. - ThreaderSlash. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Nov 22 18:10:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 00:10:19 +0100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: Message-ID: <7mtumsF3jg2qtU1@mid.uni-berlin.de> Marc Leconte schrieb: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass > > listA=Toto(number=1) > listB=Toto(number=2) > > listA.mylist.append(5) > print "1) ", listA.mylist > print "2) ", listB.mylist > >>> 1) [5] >>> 2) [5] > > I would have expected >>> 1) [5] >>> 2) [] http://effbot.org/zone/default-values.htm Diez From showell30 at yahoo.com Sun Nov 22 18:14:00 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 15:14:00 -0800 (PST) Subject: problem manipulating a list belonging to a class References: Message-ID: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> On Nov 22, 2:50?pm, Marc Leconte wrote: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > ? ? ? ? def __init__(self, number, mylist=[]) > ? ? ? ? ? ? ? ? self.number=number > ? ? ? ? ? ? ? ? self.mylist=mylist > ? ? ? ? ? ? ? ? pass > ? ? ? ? pass > Change your code to do this: def __init__(self, number, mylist=None): if mylist is None: self.mylist = [] else: self.mylist = mylist Explanations of why you need to write it that will follow... From showell30 at yahoo.com Sun Nov 22 18:16:42 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 15:16:42 -0800 (PST) Subject: problem manipulating a list belonging to a class References: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> Message-ID: On Nov 22, 3:14?pm, Steve Howell wrote: > Explanations of why you need to write it that will follow... I knew this had to be written up somewhere... http://www.ferg.org/projects/python_gotchas.html#contents_item_6 From knny.myer at gmail.com Sun Nov 22 21:06:50 2009 From: knny.myer at gmail.com (~km) Date: Sun, 22 Nov 2009 18:06:50 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) Message-ID: Hi together, I'm a python-proficient newbie and want to tackle a program with Python 2.x, which basically organizes all my digital books (*.pdf, *.chm, etc..) and to give them specific "labels", such as: "Author" -> string "Read" -> boolean "Last Opened:" -> string and so on.. Now my question is: Is it a better method to use a /database/, a /static File/, with some Markup (e.g.: YAML, XML), a Python dictionary or are there better ways I don't know of.., for organizing my books collection? I'm sure you can do it in any way above, but I'm apelling to /your/ personal experience and preference. Please give me at least one reason, why. --- I think we are in Rats' Alley where the dead men lost their bones. -- T.S. Eliot From lie.1296 at gmail.com Sun Nov 22 21:28:56 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 13:28:56 +1100 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <4b09f3c0$1@dnews.tpgi.com.au> per wrote: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? > > thanks. You're currently implementing a pseudo-pipeline: http://en.wikipedia.org/wiki/Pipeline_%28software%29#Pseudo-pipelines If you want to create a unix-style, byte-stream-oriented pipeline, have all scripts write output to stdout and read from stdin (i.e. read with raw_input and write with print). Since unix pipeline's is byte-oriented you will require parsing the input and formatting the output from/to an agreed format between each scripts. A more general approach could use more than two streams, you can use file-like objects to represent stream. For a more pythonic pipeline, you can rewrite your scripts into generators and use generator/list comprehension that reads objects from a FIFO queue and write objects to another FIFO queue (queue can be implemented using list, but take a look at Queue.Queue in standard modules). Basically an Object Pipeline: http://en.wikipedia.org/wiki/Pipeline_%28software%29#Object_pipelines For unix-style pipeline, you shell/batch scripts is the best tool, though you can also use subprocess module and redirect the process's stdin's and stdout's. For object pipeline, it can't be simpler than simply passing an input and output queue to each scripts. For in-script pipelines (c.f. inter-script pipeline), you can use generator/list comprehension and iterators. There are indeed several modules intended for providing slightly neater syntax than comprehension: http://code.google.com/p/python-pipeline/ though I personally prefer comprehension. From roy at panix.com Sun Nov 22 21:31:07 2009 From: roy at panix.com (Roy Smith) Date: Sun, 22 Nov 2009 18:31:07 -0800 (PST) Subject: Trying to understand += better Message-ID: If I've got an object foo, and I execute: foo.bar += baz exactly what happens if foo does not have a 'bar' attribute? It's pretty clear that foo.__getattr__('bar') gets called first, but it's a little murky after that. Assume for the moment that foo.__getattr__ ('bar') returns an object x. I think the complete sequence of calls is: foo.__getattr__('bar') ==> x x.__add__(baz) ==> y foo.__setattr__('bar', y) but I'm not 100% sure. It would be nice if it was, because that would let me do some very neat magic in a system I'm working on :-) How would things change if X defined __iadd__()? From lie.1296 at gmail.com Sun Nov 22 22:28:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:28:17 +1100 Subject: Trying to understand += better In-Reply-To: References: Message-ID: <4b0a01aa$1@dnews.tpgi.com.au> Roy Smith wrote: > If I've got an object foo, and I execute: > > foo.bar += baz > > exactly what happens if foo does not have a 'bar' attribute? It's > pretty clear that foo.__getattr__('bar') gets called first, but it's a > little murky after that. Assume for the moment that foo.__getattr__ > ('bar') returns an object x. I think the complete sequence of calls > is: > > foo.__getattr__('bar') ==> x > x.__add__(baz) ==> y > foo.__setattr__('bar', y) > > but I'm not 100% sure. It would be nice if it was, because that would > let me do some very neat magic in a system I'm working on :-) > > How would things change if X defined __iadd__()? The semantic of the in-place operator is something like: x += y becomes x = x.__iadd__(y) thus foo.bar += baz becomes foo.bar = foo.bar.__iadd__(baz) So the call sequence is, foo.__getattr__('bar') ==> x x.__iadd__(baz) ==> y foo.__setattr__('bar', y) the default definition of object.__iadd__ is something like this: def __iadd__(self, other): # this calls self.__add__ or other.__radd__ according to the # operator call rule, may call __coerce__ or any other magics # in operator calling return self + other From lie.1296 at gmail.com Sun Nov 22 22:49:51 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:49:51 +1100 Subject: Implementation of Book Organization tool (Python2.[x]) In-Reply-To: References: Message-ID: <4b0a06b8$1@dnews.tpgi.com.au> ~km wrote: > Hi together, > > I'm a python-proficient newbie and want to tackle a program with > Python 2.x, which basically organizes all my digital books (*.pdf, > *.chm, etc..) and to give them specific "labels", such as: > > "Author" -> string > "Read" -> boolean > "Last Opened:" -> string > and so on.. > > Now my question is: > > Is it a better method to use a /database/, a /static File/, with some > Markup (e.g.: YAML, XML), a Python dictionary or are there better ways In high-volume systems, it is almost always better to use a database. Database solves many issues with concurrent access and persistent memory. Though many would disagree, I consider XML as a form of database though it is only suitable for data exchange. XML is suitable for low- to medium-volume purpose and when compatibility with various systems is extremely important (nearly any OS and any programming language has XML parsers; porting a DBMS system may not be as easy as that). Python dictionary is stored in memory and closing the program == deleting the database. You can pickle dictionary; and this might be sufficient for quick and dirty, low-volume purpose. Pickled dictionary is the least portable solution; only python program can open a pickled dictionary and even different versions of python may have incompatibilities. > I > don't know of.., for organizing my books collection? I'm sure you can > do > it in any way above, but I'm apelling to /your/ personal experience > and > preference. Please give me at least one reason, why. For a personal book collection where the number of books is around ~300 books and you don't care about porting to another system, pickled dictionary may be just good enough. From lie.1296 at gmail.com Sun Nov 22 22:55:28 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:55:28 +1100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: Message-ID: <4b0a0808$1@dnews.tpgi.com.au> Marc Leconte wrote: > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass Why are you using pass to end your blocks? From showell30 at yahoo.com Sun Nov 22 23:01:46 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 20:01:46 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: On Nov 22, 7:28?pm, Lie Ryan wrote: > Roy Smith wrote: > > If I've got an object foo, and I execute: > > > foo.bar += baz > > > exactly what happens if foo does not have a 'bar' attribute? ?It's > > pretty clear that foo.__getattr__('bar') gets called first, but it's a > > little murky after that. ?Assume for the moment that foo.__getattr__ > > ('bar') returns an object x. ?I think the complete sequence of calls > > is: > > > foo.__getattr__('bar') ?==> x > > x.__add__(baz) ?==> y > > foo.__setattr__('bar', y) > > > but I'm not 100% sure. ?It would be nice if it was, because that would > > let me do some very neat magic in a system I'm working on :-) > > > How would things change if X defined __iadd__()? > > The semantic of the in-place operator is something like: > x += y > becomes > x = x.__iadd__(y) > > thus > foo.bar += baz > becomes > foo.bar = foo.bar.__iadd__(baz) > > So the call sequence is, > foo.__getattr__('bar') ==> x > x.__iadd__(baz) ==> y > foo.__setattr__('bar', y) > > the default definition of object.__iadd__ is something like this: > def __iadd__(self, other): > ? ? ?# this calls self.__add__ or other.__radd__ according to the > ? ? ?# operator call rule, may call __coerce__ or any other magics > ? ? ?# in operator calling > ? ? ?return self + other The __iadd__ method will often return self for mutable types. So, for example, these two statements are NOT identical where lst is a list: lst = lst + [3] lst += [3] The first statement is creating a whole new list; the second one isn't. http://docs.python.org/reference/datamodel.html From showell30 at yahoo.com Sun Nov 22 23:27:34 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 20:27:34 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) References: Message-ID: <0b5f6833-d741-4195-ab38-05d7039138b8@o9g2000prg.googlegroups.com> On Nov 22, 6:06?pm, "~km" wrote: > Hi together, > > I'm a python-proficient newbie and want to tackle a program with > Python 2.x, which basically organizes all my digital books (*.pdf, > *.chm, etc..) and to give them specific "labels", such as: > > "Author" -> string > "Read" -> boolean > "Last Opened:" -> string > and so on.. > > Now my question is: > > Is it a better method to use a /database/, a /static File/, with some > Markup (e.g.: YAML, XML), a Python dictionary or are there better ways > I > don't know of.., for organizing my books collection? I'm sure you can > do > it in any way above, but I'm apelling to /your/ personal experience > and > preference. Please give me at least one reason, why. If your data structure is just a list of dictionaries and you do not have any performance/security issues to consider yet, then you can use pure Python for your input, since it is pretty easy to hand-edit, and then occasionally you could use the PrettyPrinter module to format your data. YAML is another option, as it can offer a slightly cleaner syntax, but I do not think it buys you a whole lot more than that for your use case. Same for JSON--I like JSON but you do not need it right away. PrettyPrinter is batteries included. I would avoid XML and pickle. From roy at panix.com Sun Nov 22 23:38:28 2009 From: roy at panix.com (Roy Smith) Date: Sun, 22 Nov 2009 23:38:28 -0500 Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > The semantic of the in-place operator is something like: > x += y > becomes > x = x.__iadd__(y) > > thus > foo.bar += baz > becomes > foo.bar = foo.bar.__iadd__(baz) > > So the call sequence is, > foo.__getattr__('bar') ==> x > x.__iadd__(baz) ==> y > foo.__setattr__('bar', y) I don't get where the __setattr__() call comes from in this situation. I thought the whole idea of __iadd__(self, other) is that it's supposed to mutate self. So, why is there another assignment happening after the __iadd__() call? From alebezh at gmail.com Sun Nov 22 23:50:36 2009 From: alebezh at gmail.com (=?KOI8-R?B?4czFy9PBzsTSIOLF1sHb18nMyQ==?=) Date: Mon, 23 Nov 2009 07:50:36 +0300 Subject: Amoeba OS and Python Message-ID: <9ed87f7c0911222050t641b8684kbec49d068ff6f766@mail.gmail.com> As I know, Python has been started for Amoeba OS. Did anybody try Python with it? What about speed? Python is so slow for big projects and I try to find a way to accelerate it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From n00m at narod.ru Mon Nov 23 00:11:31 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 21:11:31 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: <34471c3a-722f-4811-beb8-58073e01484f@r31g2000vbi.googlegroups.com> > The first statement is creating a whole new list; Yes but *imo* not quite exactly so. We can't think of 2 lists as of absolutely independent things. ... x = [[0]] ... id(x) 19330632 ... id(x[0]) 19316608 ... z = x + [3] ... id(z) 19330312 ... id(z[0]) 19316608 ... ... z[0] is x[0] # ? True ... x[0][0] = 1 ... ... z[0][0] 1 From n00m at narod.ru Mon Nov 23 00:16:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 21:16:16 -0800 (PST) Subject: Sorting: too different times. Why? References: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> <0319a381$0$1336$c3e8da3@news.astraweb.com> Message-ID: <122415d7-fe2d-4b43-9464-f22193c4a41b@f10g2000vbl.googlegroups.com> > Some sexually transmitted diseases make your genitals drip. I suspected this :-) Eminem is a famous misogynist From showell30 at yahoo.com Mon Nov 23 00:42:26 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 21:42:26 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> <34471c3a-722f-4811-beb8-58073e01484f@r31g2000vbi.googlegroups.com> Message-ID: <658c3e61-de2e-48ab-8235-7e1ae5a8f22c@v15g2000prn.googlegroups.com> On Nov 22, 9:11?pm, n00m wrote: > > The first statement is creating a whole new list; > > Yes but *imo* not quite exactly so. > We can't think of 2 lists as of absolutely independent > things. > [...] You are correct that two lists can both have the same mutable object as items, and if you mutate that object, both lists will see that mutation. Changing the innards of an item doesn't change the list, if you think of the list as just a collection of ids, but your point is well taken. It is probably easiest to understand all this with a more elaborate example. >>> mutable = {'foo': 'bar'} >>> list1 = [mutable, 'bla'] >>> list2 = list1 + ['another element'] >>> list1 [{'foo': 'bar'}, 'bla'] >>> list2 [{'foo': 'bar'}, 'bla', 'another element'] So list2 and list1 are no longer the same list, but... >>> mutable['foo'] = 'new value for mutable' >>> list1 [{'foo': 'new value for mutable'}, 'bla'] >>> list2 [{'foo': 'new value for mutable'}, 'bla', 'another element'] They do still share a common element, as shown above. But you can reassign the first element of list2 without affecting list1: >>> list2[0] = 'only list 2' >>> list1 [{'foo': 'new value for mutable'}, 'bla'] >>> list2 ['only list 2', 'bla', 'another element'] Now look at fred_list and barney_list below. Since you use +=, fred_list and barney_list stay tied together even when you *think* you are only assigning a new value to barney_list[0]. >>> fred_list = [0] >>> barney_list = fred_list >>> barney_list += [1] >>> barney_list [0, 1] >>> fred_list [0, 1] >>> barney_list[0] = 'barney' >>> barney_list ['barney', 1] >>> fred_list ['barney', 1] From showell30 at yahoo.com Mon Nov 23 00:49:07 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 21:49:07 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: On Nov 22, 8:38?pm, Roy Smith wrote: > In article <4b0a01a... at dnews.tpgi.com.au>, Lie Ryan > wrote: > > > The semantic of the in-place operator is something like: > > x += y > > becomes > > x = x.__iadd__(y) > > > thus > > foo.bar += baz > > becomes > > foo.bar = foo.bar.__iadd__(baz) > > > So the call sequence is, > > foo.__getattr__('bar') ==> x > > x.__iadd__(baz) ==> y > > foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. ?I > thought the whole idea of __iadd__(self, other) is that it's supposed to > mutate self. ?So, why is there another assignment happening after the > __iadd__() call? Non-mutable types can also use += syntax. x = MagicalNumber(42) x += 5 # x gets reassigned to MagicalNumber(47) There is nothing that says that __iadd__ has to return self, but if you are designing a mutable type, you will generally do that. http://docs.python.org/reference/datamodel.html ''' These methods are called to implement the augmented arithmetic assignments (+=, -=, *=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=). These methods should attempt to do the operation in-place (modifying self) and return the result (which could be, but does not have to be, self). If a specific method is not defined, the augmented assignment falls back to the normal methods. For instance, to execute the statement x += y, where x is an instance of a class that has an __iadd__() method, x.__iadd__(y) is called. If x is an instance of a class that does not define a __iadd__() method, x.__add__(y) and y.__radd__(x) are considered, as with the evaluation of x + y. ''' From patrickstinson.lists at gmail.com Mon Nov 23 01:58:16 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Sun, 22 Nov 2009 23:58:16 -0700 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <7mtrf5F3h153dU1@mid.uni-berlin.de> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> Message-ID: <6214d7a20911222258q79a07546h2760798cbed3eeed@mail.gmail.com> that's right. I cannot make CPython calls from my original C-based threads. On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: > Daniel Fetchinson schrieb: >>> >>> Has anyone every tried wrapping the CPython lib into a daemon with an >>> RPC mechanism in order to move the GIL out of the process? I have >>> multiple audio threads, each of which use the python interpreter but >>> don't have to interact with each other and can might as well use a >>> separate interpreter handled by a daemon with libpython linked in. >>> >>> I've never used a C xmlrpc lib before and would probably need to set >>> up some shared memory to get it to work. Can anyone suggest a library >>> out there that would at do that sort of thing, maybe with some >>> cross-platform process management? >>> >>> I imagine this is how the multiprocessing module works. >> >> Yes, it does seem you need multiprocessing. That would take advantage >> of multiple cores and the GIL wouldn't bother you at all. Take a look >> at >> >> http://docs.python.org/library/multiprocessing.html >> >> For what you describe (separate tasks running concurrently without >> communicating) the multiprocessing module would be ideal. > > The problem is that the OP has a embedded application running threads. > multiprocssing doesn't help there. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Mon Nov 23 02:18:58 2009 From: rt8396 at gmail.com (r) Date: Sun, 22 Nov 2009 23:18:58 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: On Nov 22, 11:32?am, News123 wrote: > - This script works fine for me under Windows 7, however I'm > ? unable to ? specify additional parameters, like dpi and > ? color mode. I have found something interesting but have no idea HOW to implement it?? It seems the setting for the scanner are in the registry and must be changed that way or by specifically calling these constants on the device. WIA_IPS_YRES (ScannerPictureYres) Contains the current vertical resolution, in pixels per inch, for the device. An application sets this property to set the vertical resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_XRES (ScannerPictureXres) Contains the current horizontal resolution, in pixels per inch, for the device. An application sets this property to set the horizontal resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_OPTICAL_XRES (ScannerPictureOpticalXres) Note This property is supported only by Windows Vista and later. Horizontal Optical Resolution. Highest supported horizontal optical resolution in DPI. This property is a single value. This is not a list of all resolutions that can be generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items. Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_OPTICAL_YRES (ScannerPictureOpticalYres) Note This property is supported only by Windows Vista and later. Vertical Optical Resolution. Highest supported vertical optical resolution in DPI. This property is a single value. This is not a list of all resolutions that are generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items.Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_BRIGHTNESS (ScannerPictureBrightness) The image brightness values available within the scanner.Contains the current hardware brightness setting for the device. An application sets this property to the hardware's brightness value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_CONTRAST (ScannerPictureContrast) Contains the current hardware contrast setting for a device. An application sets this property to the hardware's contrast value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_ORIENTATION (ScannerPictureOrientation) Specifies the current orientation of the documents to be scanned. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_LIST ------------------------ Image Intent Constants ------------------------ Image intent constants specify what type of data the image is meant to represent. The WIA_IPS_CUR_INTENT scanner property uses these flags. To provide an intent, combine an intended image type flag with an intended size/quality flag by using the OR operator. WIA_INTENT_NONE should not be combined with any other flags. Note that an image cannot be both grayscale and color. WIA_INTENT_IMAGE_TYPE_COLOR (ImageTypeColor) WIA_INTENT_IMAGE_TYPE_GRAYSCALE (ImageTypeGrayscale) WIA_INTENT_IMAGE_TYPE_TEXT (ImageTypeText) WIA_INTENT_MINIMIZE_SIZE (MinimizeSize) WIA_INTENT_MAXIMIZE_QUALITY (MaximizeQuality) WIA_INTENT_BEST_PREVIEW (BestPreview) From lie.1296 at gmail.com Mon Nov 23 02:31:42 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 18:31:42 +1100 Subject: Trying to understand += better In-Reply-To: References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: <4b0a3ab8$1@dnews.tpgi.com.au> Roy Smith wrote: > In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan > wrote: > >> The semantic of the in-place operator is something like: >> x += y >> becomes >> x = x.__iadd__(y) >> >> thus >> foo.bar += baz >> becomes >> foo.bar = foo.bar.__iadd__(baz) >> >> So the call sequence is, >> foo.__getattr__('bar') ==> x >> x.__iadd__(baz) ==> y >> foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. I > thought the whole idea of __iadd__(self, other) is that it's supposed to > mutate self. So, why is there another assignment happening after the > __iadd__() call? The formal name of the __iop__ is "agumented assignment". The name doesn't talk about in-place; but it does talk about assignment. The semantic defines that augmented assignment operation is done in-place *when the left-hand side object supports it* (i.e. it does not require in-place mutation). """ The __iadd__ hook should behave similar to __add__, returning the result of the operation (which *could* be `self') which is to be assigned to the variable `x'. """ For a more complete description, see: http://www.python.org/dev/peps/pep-0203/ From pavlovevidence at gmail.com Mon Nov 23 03:01:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 23 Nov 2009 00:01:16 -0800 (PST) Subject: xmlrpc idea for getting around the GIL References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> Message-ID: <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> On Nov 22, 10:58?pm, Patrick Stinson wrote: > On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: icating) the multiprocessing module would be ideal. > > The problem is that the OP has a embedded application running threads. > > multiprocssing doesn't help there. > > that's right. I cannot make CPython calls from my original C-based threads. It's quite possible to do that. A thread started from C can make calls to Python if it first calls PyGILState_Ensure, although you'd have to make sure that the Python interpreter has been previously initialized. See PEP 311 for details. http://www.python.org/dev/peps/pep-0311/ I also suggest that if you want people to be more receptive to write your replies after the quoted text. That is the custom in this newsgroup/mailing list. Carl Banks From ashwiniyal at gmail.com Mon Nov 23 03:06:26 2009 From: ashwiniyal at gmail.com (ashwini yal) Date: Mon, 23 Nov 2009 13:36:26 +0530 Subject: multitasking Message-ID: <771960b20911230006g268d8495l22db994c76e8ecbb@mail.gmail.com> Hi, I want to know diffrent methods of multitasking supported by python(I want to run diffrent jobs simultaneously at same time) which is the good approach. I know about threads,but i also know that using threads leads to less operational speed. Can someone help me -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Mon Nov 23 03:30:53 2009 From: news123 at free.fr (News123) Date: Mon, 23 Nov 2009 09:30:53 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4B0A483D.9020205@free.fr> Hi r, r wrote: > On Nov 22, 11:32 am, News123 wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N From news123 at free.fr Mon Nov 23 03:31:08 2009 From: news123 at free.fr (News123) Date: Mon, 23 Nov 2009 09:31:08 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4b0a484c$0$8915$426a34cc@news.free.fr> Hi r, r wrote: > On Nov 22, 11:32 am, News123 wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N From robert.kern at gmail.com Mon Nov 23 03:36:33 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 02:36:33 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Aahz wrote: > In article <7ms7ctF3k2a79U1 at mid.individual.net>, > Gregory Ewing wrote: >> However, Go's designers seem to favour using the absolute minimum >> number of characters they can get away with. >> >> Although if they *really* wanted that, they would have dropped most of >> the semicolons and used indentation-based block structure instead of >> curly braces. I would have forgiven them several other sins if they'd >> done that. :-) > > That's essentially my issue with Go based on the code samples I've seen: > no over-arching design sensibility at the syntax level. It looks like an > aggolomeration of semi-random C-like syntax. There's nothing that > shouts out, "This is a Go program," unlike Python, C, and even Perl. I think there is an overall design sensibility, it's just not a human-facing one. They claim that they designed the syntax to be very easily parsed by very simple tools in order to make things like syntax highlighters very easy and robust. So indentation-based blocks are right out. -- 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 Nov 23 03:39:35 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 02:39:35 -0600 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: per wrote: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? You may want to try joblib or ruffus. I haven't had a chance to evaluate either one, though. http://pypi.python.org/pypi/joblib/ http://pypi.python.org/pypi/ruffus/ -- 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 rt8396 at gmail.com Mon Nov 23 03:59:20 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 00:59:20 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> Message-ID: more *maybe useful dump? >>> for i in dev.Items: for p in i.Properties: if not p.IsReadOnly: print p.Name, '->', p.Value Color Profile Name -> sRGB Color Space Profile Brightness -> 0 Contrast -> 0 Private Highlight Level -> 0 Private Midtone Level -> 0 Private Shadow Level -> 0 Private Gamma -> 2200 Private Saturation -> 1000 Private Hue X -> 0 Private Hue Y -> 0 Private Sharpen Level -> 3 Threshold -> 55 Horizontal Resolution -> 200 Vertical Resolution -> 200 Horizontal Start Position -> 0 Vertical Start Position -> 0 Horizontal Extent -> 1700 Vertical Extent -> 2338 Current Intent -> 0 Data Type -> 3 Media Type -> 128 Format -> {B96B3CAA-0728-11D3-9D7B-0000F81EF32E} Private Source Depth -> 0 Private Preview -> 0 Private Exposure Method -> 0 Private Smoothing -> 1 Private Color Enhanced -> 0 Private TMA Method -> 0 >>> dev.DeviceID u'{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000' >>> for p in dev.Properties: print p.Name, '->', p.Value Item Name -> Root Full Item Name -> 0000\Root Item Flags -> 76 Unique Device ID -> {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000 Manufacturer -> Hewlett-Packard Description -> HP Deskjet F300 Type -> 65538 Port -> \\.\Usbscan0 Name -> HP Deskjet F300 Server -> local Remote Device ID -> UI Class ID -> {0A8DC120-D685-4247-9CD1-8712F6BB2DED} Hardware Configuration -> 0 BaudRate -> STI Generic Capabilities -> 48 WIA Version -> 2.0 Driver Version -> 0.0.0.216 PnP ID String -> \\?\usb#vid_03f0&pid_5511&mi_00#6&2def7e7&0&0000# {6bdd1fc6-810f-11d0-bec7-08002be2092f} STI Driver Version -> 2 Horizontal Bed Size -> 8500 Vertical Bed Size -> 11690 Horizontal Bed Registration -> 0 Vertical Bed Registration -> 0 Access Rights -> 3 Horizontal Optical Resolution -> 2400 Vertical Optical Resolution -> 2400 Firmware Version -> 1.0.na Max Scan Time -> 500000 Now how to set the values... hmmm? From paul.nospam at rudin.co.uk Mon Nov 23 04:02:01 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 23 Nov 2009 09:02:01 +0000 Subject: creating pipelines in python References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <87y6lxd37a.fsf@rudin.co.uk> per writes: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? > Not entirely what you're looking for, but the subprocess module is easier to work with for this sort of thing than os. See e.g. From jarausch at igpm.rwth-aachen.de Mon Nov 23 04:20:30 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Mon, 23 Nov 2009 10:20:30 +0100 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <4b09534c$0$2868$ba620e4c@news.skynet.be> References: <4b09534c$0$2868$ba620e4c@news.skynet.be> Message-ID: <7mv2eqF3j15m8U1@mid.dfncis.de> On 11/22/09 16:05, Helmut Jarausch wrote: > On 11/22/09 14:58, Jelle Smet wrote: >> Hi List, >> >> I'm trying to match lines in python using the re module. >> The end goal is to have a regex which enables me to skip lines which >> have ok and warning in it. >> But for some reason I can't get negative lookaheads working, the way >> it's explained in "http://docs.python.org/library/re.html". >> >> Consider this example: >> >> Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import re >>>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh >>>>> qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf >>>>> lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>>> re.match('.*(?!warning)',line) >> <_sre.SRE_Match object at 0xb75b1598> >> >> I would expect that this would NOT match as it's a negative lookahead >> and warning is in the string. >> > > '.*' eats all of line. Now, when at end of line, there is no 'warning' > anymore, so it matches. > What are you trying to achieve? > > If you just want to single out lines with 'ok' or warning in it, why not > just > if re.search('(ok|warning)') : call_skip > Probably you don't want words like 'joke' to match 'ok'. So, a better regex is if re.search('\b(ok|warning)\b',line) : SKIP_ME Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From wentland at cl.uni-heidelberg.de Mon Nov 23 04:20:35 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 23 Nov 2009 10:20:35 +0100 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <20091123092035.GC9247@kinakuta.local> On Sun, Nov 22, 2009 at 14:49 -0800, per wrote: > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > does anyone have any recommendations for python packages that can do > this? There are various possibilities. I would suggest you have a look at [1] which details the creation of pipelines with generators that can be used within *one* program. If you want to chain different programs together you can use the subprocess package in the stdlib of Python 2.6. [1] http://www.dabeaz.com/generators/ -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From threaderslash at gmail.com Mon Nov 23 04:35:26 2009 From: threaderslash at gmail.com (Threader Slash) Date: Mon, 23 Nov 2009 20:35:26 +1100 Subject: QtPython: removeChild/addChild QGroupBox Message-ID: Hi Everybody, I am developing a system for a customer which is displayed in a set of GroupBox. Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table. Here is a piece of the code that runs nicely and shows the a groupBox. Now it starts to show some effects on removeWidget, but it is still didn't clear the box completely.. just the right border of the box is erased. self.vLayout_wdg = QtGui.QWidget(self.centralwidget) self.vLayout_wdg.setGeometry(QtCore.QRect(40, 160, 171, 121)) self.vLayout_wdg.setObjectName("vLayout_wdg") self.vLayoutBoxObj = QtGui.QVBoxLayout(self.vLayout_wdg) self.vLayoutBoxObj.setObjectName("vLayoutBoxObj") self.newGroupBox = QtGui.QGroupBox(self.vLayout_wdg) self.newGroupBox.setObjectName("newGroupBox") self.radioButton1 = QtGui.QRadioButton(self.newGroupBox) self.radioButton1.setGeometry(QtCore.QRect(30, 30, 101, 21)) self.radioButton1.setObjectName("helloRadioButton") self.radioButton2 = QtGui.QRadioButton(self.newGroupBox) self.radioButton2.setGeometry(QtCore.QRect(30, 60, 111, 18 ) self.radioButton2.setObjectName("niceRadioButton") self.vLayoutBoxObj.addWidget(self.newGroupBox) if removeContainer_Button_Pressed: self.vLayoutBoxObj.removeWidget(self.newGroupBox) self.newGroupBox.adjustSize() self.vLayoutBoxObj.deleteLater() self.vLayoutBoxObj.update() All hints and comments are highly welcome and appreciated. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 23 04:43:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 04:43:01 -0500 Subject: problem manipulating a list belonging to a class In-Reply-To: <1258930243.11379.8.camel@gondor> References: <1258930243.11379.8.camel@gondor> Message-ID: Marc Leconte wrote: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass > > listA=Toto(number=1) > listB=Toto(number=2) > > listA.mylist.append(5) > print "1) ", listA.mylist > print "2) ", listB.mylist > >>> 1) [5] >>> 2) [5] > > I would have expected >>> 1) [5] >>> 2) [] > > Thanks in advance for advice, Read the Python FAQ and or the reference manual section on def statements (function definition) which specifically has a paragraph with a bold-face statement explaining this. From srijit at yahoo.com Mon Nov 23 04:51:31 2009 From: srijit at yahoo.com (Srijit Kumar Bhadra) Date: Mon, 23 Nov 2009 01:51:31 -0800 (PST) Subject: lxml 2.2.4 for Python 2.6 Message-ID: <9a80baa0-986d-4c17-bcf2-a32d0bf276bf@z10g2000prh.googlegroups.com> Is there any reason why lxml-2.2.4-py2.6-win32.egg (md5) or lxml-2.2.4.win32-py2.6.exe is not available? Best regards, /Srijit From ajd at malcol.org Mon Nov 23 05:03:07 2009 From: ajd at malcol.org (Andy dixon) Date: Mon, 23 Nov 2009 10:03:07 -0000 Subject: python and Postgresq Message-ID: Hi, Does anyone have a link to, or can provide an example script for using python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can recommend an alternative, that would be fantastic. Thanks! Andy Dixon From deets at nospam.web.de Mon Nov 23 05:22:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 11:22:15 +0100 Subject: python and Postgresq References: Message-ID: <7mv62nF3hp171U1@mid.uni-berlin.de> Andy dixon wrote: > Hi, > > Does anyone have a link to, or can provide an example script for using > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can > recommend an alternative, that would be fantastic. I'd recommend psycopg2. This is an introduction: http://www.devx.com/opensource/Article/29071 But google yields tons more. And make sure you read the python db api 2.0 spec, this should give you the general idea on how to work with Python & RDBMS, which is nicely abstracted away from the actual database. http://www.python.org/dev/peps/pep-0249/ Diez From robin at reportlab.com Mon Nov 23 05:35:31 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 Nov 2009 10:35:31 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B0A6573.8070005@chamonix.reportlab.co.uk> sturlamolden wrote: > On 20 Nov, 11:12, Robin Becker wrote: > >> Presumably that means they could potentially run in parallel on the 100000 cpu >> machines of the future. >> >> I'm not so clear on whether the threadless tasklets will run on separate cpus. > > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. > ....... not really sure about all the parallelism that will actually be achievable, but apparently the goroutines are multiplexed onto native threads by the run time. Apparently each real thread is run until it blocks and then another goroutine is allowed to make use of the thread. Apparently the gccgo runtime has 1 goroutine per thread and is different to the fast compilers. -- Robin Becker From robin at reportlab.com Mon Nov 23 05:35:31 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 Nov 2009 10:35:31 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B0A6573.8070005@chamonix.reportlab.co.uk> sturlamolden wrote: > On 20 Nov, 11:12, Robin Becker wrote: > >> Presumably that means they could potentially run in parallel on the 100000 cpu >> machines of the future. >> >> I'm not so clear on whether the threadless tasklets will run on separate cpus. > > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. > ....... not really sure about all the parallelism that will actually be achievable, but apparently the goroutines are multiplexed onto native threads by the run time. Apparently each real thread is run until it blocks and then another goroutine is allowed to make use of the thread. Apparently the gccgo runtime has 1 goroutine per thread and is different to the fast compilers. -- Robin Becker From ajd at malcol.org Mon Nov 23 05:36:26 2009 From: ajd at malcol.org (Andy dixon) Date: Mon, 23 Nov 2009 10:36:26 -0000 Subject: python and Postgresq In-Reply-To: <7mv62nF3hp171U1@mid.uni-berlin.de> References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" wrote in message news:7mv62nF3hp171U1 at mid.uni-berlin.de... > Andy dixon wrote: > >> Hi, >> >> Does anyone have a link to, or can provide an example script for using >> python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone >> can >> recommend an alternative, that would be fantastic. > > I'd recommend psycopg2. > > This is an introduction: > > http://www.devx.com/opensource/Article/29071 > > But google yields tons more. And make sure you read the python db api 2.0 > spec, this should give you the general idea on how to work with Python & > RDBMS, which is nicely abstracted away from the actual database. > > http://www.python.org/dev/peps/pep-0249/ > > Diez Amazing. Works like a charm! Thanks.. I used the code (stripping out certain bits) if anyone else may find it useful: #!/usr/bin/env python import psycopg def main(): connection = psycopg.connect('host= dbname= user= password=') mark = connection.cursor() query='SELECT * FROM table' mark.execute(query) record = mark.fetchall() for i in record: print i return if __name__ == '__main__': main() From solipsis at pitrou.net Mon Nov 23 05:47:13 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 23 Nov 2009 10:47:13 +0000 (UTC) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit?: > > I think there is an overall design sensibility, it's just not a > human-facing one. They claim that they designed the syntax to be very > easily parsed by very simple tools in order to make things like syntax > highlighters very easy and robust. So indentation-based blocks are right > out. But computer languages should be designed to be readable by humans. It's not like you need to write a new parser once a year, but you have to read code everyday. Besides, if you want parsing to be easy, you don't need to make the syntax minimal, you just have to provide the parsing routines as part of the standard library and/or of an external API. From victorsubervi at gmail.com Mon Nov 23 05:47:20 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 05:47:20 -0500 Subject: Switching Databases Message-ID: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Hi; I have the following code: import MySQLdb ... user, passwd, db, host = login() db = MySQLdb.connect(host, user, passwd, 'cart') cursor= db.cursor() ... cursor.close() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() Now, python complains about me opening a new connection. But I thought I'd closed the first one! So, I replaced the last 3 lines with this: cursor.execute('use %s;' % db) but it didn't like that, either. Any way to switch databases? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From gh at ghaering.de Mon Nov 23 05:49:29 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 23 Nov 2009 11:49:29 +0100 Subject: Python & OpenOffice Spreadsheets Message-ID: Is there a *simple* way to read OpenOffice spreadsheets? Bonus: write them, too? I mean something like: doc.cells[0][0] = "foo" doc.save("xyz.ods") >From a quick look, pyodf offers little more than just using a XML parser directly. -- Gerhard From ben+python at benfinney.id.au Mon Nov 23 06:01:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 23 Nov 2009 22:01:54 +1100 Subject: python and Postgresq References: Message-ID: <873a45a4il.fsf@benfinney.id.au> "Andy dixon" writes: > Does anyone have a link to, or can provide an example script for using > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone > can recommend an alternative, that would be fantastic. "Diez B. Roggisch" writes: > I'd recommend psycopg2. I'd recommend installing ?psycopg2?, but using it at a slight distance by installing ?SQLAlchemy? to give a useful Pythonic access layer while having full access to SQL whenever needed. -- \ ?People come up to me and say, ?Emo, do people really come up | `\ to you??? ?Emo Philips | _o__) | Ben Finney From paul.nospam at rudin.co.uk Mon Nov 23 06:12:37 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 23 Nov 2009 11:12:37 +0000 Subject: Python & OpenOffice Spreadsheets References: Message-ID: <87pr79cx5m.fsf@rudin.co.uk> Gerhard H?ring writes: > Is there a *simple* way to read OpenOffice spreadsheets? > > Bonus: write them, too? > > I mean something like: > > doc.cells[0][0] = "foo" > doc.save("xyz.ods") > >>From a quick look, pyodf offers little more than just using a XML parser > directly. Depends on exactly what you mean by "simple" - but pyuno allows you to read and write openoffice spreadsheets. From hackingkk at gmail.com Mon Nov 23 06:20:04 2009 From: hackingkk at gmail.com (Krishnakant) Date: Mon, 23 Nov 2009 16:50:04 +0530 Subject: python and Postgresq In-Reply-To: <7mv62nF3hp171U1@mid.uni-berlin.de> References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: <1258975204.3770.7.camel@krishna-laptop> On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote: > Andy dixon wrote: > > > Hi, > > > > Does anyone have a link to, or can provide an example script for using > > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can > > recommend an alternative, that would be fantastic. > > I'd recommend psycopg2. > > This is an introduction: > > http://www.devx.com/opensource/Article/29071 > > But google yields tons more. And make sure you read the python db api 2.0 > spec, this should give you the general idea on how to work with Python & > RDBMS, which is nicely abstracted away from the actual database. Python-pgsql is a much better choice when it comes to big applications, specially if you are going to deal with xml-rpc. I have found that python-pgsql handles integers and other such postgresql datatypes better. Happy hacking. Krishnakant. From hackingkk at gmail.com Mon Nov 23 06:25:07 2009 From: hackingkk at gmail.com (Krishnakant) Date: Mon, 23 Nov 2009 16:55:07 +0530 Subject: Python & OpenOffice Spreadsheets In-Reply-To: <87pr79cx5m.fsf@rudin.co.uk> References: <87pr79cx5m.fsf@rudin.co.uk> Message-ID: <1258975507.3770.10.camel@krishna-laptop> On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: > Gerhard H?ring writes: > > > Is there a *simple* way to read OpenOffice spreadsheets? > > > > Bonus: write them, too? > > > > I mean something like: > > > > doc.cells[0][0] = "foo" > > doc.save("xyz.ods") > > > >>From a quick look, pyodf offers little more than just using a XML parser > > directly. > > > Depends on exactly what you mean by "simple" - but pyuno allows you to > read and write openoffice spreadsheets. Odfpy is a good module and is easy too. http://kk.hipatia.net/public/gnukhata/gnukhata-client/ has a deb package I built for ubuntu 9.04. I can even provide you the distutils tarball off the list (because I can't recall the url from I downloaded it, may be sourceforge ). Happy hacking. Krishnakant From deets at nospam.web.de Mon Nov 23 06:37:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 12:37:36 +0100 Subject: python and Postgresq References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: <7mvag0F3iacc0U1@mid.uni-berlin.de> Krishnakant wrote: > On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote: >> Andy dixon wrote: >> >> > Hi, >> > >> > Does anyone have a link to, or can provide an example script for using >> > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone >> > can recommend an alternative, that would be fantastic. >> >> I'd recommend psycopg2. >> >> This is an introduction: >> >> http://www.devx.com/opensource/Article/29071 >> >> But google yields tons more. And make sure you read the python db api 2.0 >> spec, this should give you the general idea on how to work with Python & >> RDBMS, which is nicely abstracted away from the actual database. > > Python-pgsql is a much better choice when it comes to big applications, > specially if you are going to deal with xml-rpc. I have found that > python-pgsql handles integers and other such postgresql datatypes > better. Where is the connection between XMLRPC and psql? And can you elaborate on what and how pgsql handles things better than psycopg2? Diez From m.shanmugarajan at gmail.com Mon Nov 23 07:16:49 2009 From: m.shanmugarajan at gmail.com (Shan) Date: Mon, 23 Nov 2009 04:16:49 -0800 (PST) Subject: python and netezza Message-ID: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> Is there any module in python to connect with netezza database?(like cx_Oracle which is used to connect Oracle from python) Thanks for any help. - Shan From chris at simplistix.co.uk Mon Nov 23 07:18:37 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 23 Nov 2009 12:18:37 +0000 Subject: Python & OpenOffice Spreadsheets In-Reply-To: References: Message-ID: <4B0A7D9D.10803@simplistix.co.uk> Gerhard H?ring wrote: > Is there a *simple* way to read OpenOffice spreadsheets? Ironically, if you don't mind working in .xls, which OpenOffice handles just fine, you have xlrd and xlwt to do exactly what you're after: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From mail at anjanesh.net Mon Nov 23 08:07:57 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 18:37:57 +0530 Subject: print function in python3.1 Message-ID: <1a7951080911230507v1273f4c3jd4efe794d9daa084@mail.gmail.com> Python 3.1.1 sql = "INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s');" for row in fp: print (sql, (row[0],row[1],row[2],row[3],row[4])) . INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', 'abc', '2006-04-09 02:19:24', '', '') . Why is it showing %s in the output ? 1. I dont want to sql % () because that doesnt escape the strings 2. I cant use conn.escape_string(r) because Im not connected to a database. Output script to file and import to database loated elsewhere. -- Anjanesh Lekshmnarayanan From deets at nospam.web.de Mon Nov 23 08:16:08 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 14:16:08 +0100 Subject: print function in python3.1 References: Message-ID: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: > Python 3.1.1 > > sql = "INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s');" > for row in fp: > print (sql, (row[0],row[1],row[2],row[3],row[4])) > . > INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', > 'abc', '2006-04-09 02:19:24', '', '') > . > Why is it showing %s in the output ? Because you gave it to it. How should it know that you want the %s to be replaced with the other parameters? That's what the %-operator is for. > > 1. I dont want to sql % () because that doesnt escape the strings > 2. I cant use conn.escape_string(r) because Im not connected to a > database. Output script to file and import to database loated > elsewhere. Depending on your DB-adapter, you are out of luck here. Either connect to a db even if you don't need it, or try & see if you can locate the implementation in the module somehow. E.g. MySQLdb has the function exposed as "escape_string", not only on a connection. Diez From bschollnick at gmail.com Mon Nov 23 08:26:18 2009 From: bschollnick at gmail.com (Benjamin Schollnick) Date: Mon, 23 Nov 2009 05:26:18 -0800 (PST) Subject: Perl conversion to python... Message-ID: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com> Folks, I'm having some issues here with pyserial & trying to translate a perl script to python... It's probably my inexperience with PySerial & perl that is troubling me... Can anyone assist? I'm concerned, since I can't seem to receive the data in any reliable manner.. I've tested multiple times, and only once received data... So I suspect that my Transmit & receive code is faulty... def xmit ( data, serialport ): for x in data: xmit_byte (x, serialport) # serialport.write ( binascii.unhexlify ( data ) ) # for x in data: # print str(x).encode ('hex') # serialport.write ( x.encode('hex')) def receive ( serialport ): received = serialport.read (20) print received, "!" ----- Perl Code ---- sub tx_command { my $port = shift; my $cmd = shift; # warn "tx_command($cmd)\n"; my @cmd_bytes = split(/\s/, $cmd); foreach my $byte (@cmd_bytes) { $byte = pack('C', hex($byte)); $port -> write($byte); select(undef, undef, undef, 0.01); } } # returns the rtt, or 0 if no response sub rx_response { my ($port, $address) = @_; $port->read_char_time(0); # don't wait for each character $port->read_const_time(5000); # timeout if we don't get what we're looking for my $buf = ''; my $t_start = time; ### accumulate one byte at a time until we see the substring we're looking for while (1) { my ($count_in, $string_in) = $port->read(1); if ($count_in == 0) { # warn "TIMEOUT\n"; return 0; } $buf .= $string_in; my $bufstring = packed_to_text($buf); #warn "bufstring: ".$bufstring; if ($bufstring =~/02 50 $address (.. .. ..) (..) (.. ..)/) { my $powerlinc_addr = $1; my $flags = $2; my $command = $3; # warn "got response!\n"; my $rtt = time() - $t_start; return $rtt; } } } From joost at h-labahn.de Mon Nov 23 08:37:10 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 05:37:10 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, code-inlining Pixbufs Message-ID: <4690c694-1c7e-4b83-a818-bf98fe8e6e34@t18g2000vbj.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving the utf-8-code sqlite works with alone. And in the long run one of the python-API of the monet database perhaps A preprocessor macro -DDEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this source code would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by pythons distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a little bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro -DDEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter(). Admittedly this isn't really tested now. Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now.. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable but python's array.array.fromstring() and array.array.tostring() are used to provide a well readable and well code-usable representation of these bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) back-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From mail at anjanesh.net Mon Nov 23 08:54:18 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 19:24:18 +0530 Subject: print function in python3.1 In-Reply-To: <7mvg8oF3jof5mU1@mid.uni-berlin.de> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Message-ID: <1a7951080911230554l39ab3eeax16c2ebf3fc8a3a6e@mail.gmail.com> > Depending on your DB-adapter, you are out of luck here. Either connect to a db even if you don't need it, or try & see if you can locate the implementation in the module somehow. ImportError: No module named MySQLdb MySQLdb only available in Python2. -- Anjanesh Lekshmnarayanan From liuxin9023 at gmail.com Mon Nov 23 09:10:03 2009 From: liuxin9023 at gmail.com (liuxin9023 at gmail.com) Date: Mon, 23 Nov 2009 06:10:03 -0800 (PST) Subject: Scripts Only Run In Root References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Message-ID: <15228b61-acef-49b0-8b05-3388782d9186@u25g2000prh.googlegroups.com> On Nov 23, 2:36?am, geremy condra wrote: > On Sun, Nov 22, 2009 at 12:39 PM, Victor Subervi > > wrote: > > Hi; > > I can only run my python scripts on my server if they are owned by root. How > > do I change that? > > TIA, > > Victor > > Almost certainly going to need more information. On that note, you are > probably going to get better help with less explaining from the appropriate > OS support channels. > > Geremy Condra I guess you are using *inux. Maybe you don't have enough permission, what you need to do is to change the permission. From deets at nospam.web.de Mon Nov 23 09:10:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 15:10:10 +0100 Subject: print function in python3.1 References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Message-ID: <7mvje2F3inifiU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: >> Depending on your DB-adapter, you are out of luck here. Either connect to >> a db even if you don't need it, or try & see if you can locate the >> implementation in the module somehow. > > ImportError: No module named MySQLdb > MySQLdb only available in Python2. > I don't have the slightest clue what you want to say with that. Diez From joost at h-labahn.de Mon Nov 23 09:12:10 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:12:10 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <1c6296e3-ab9c-4d27-acdd-1d07820a68db@p32g2000vbi.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving the utf-8-code sqlite works with alone. And in the long run one of the python-API of the monet database perhaps A preprocessor macro -DDEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this source code would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a little bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter(). Admittedly gtk-threads aren't really intensively now. Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of these bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) back-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From carsten.haese at gmail.com Mon Nov 23 09:17:44 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 09:17:44 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > I have the following code: > > import MySQLdb > ... > user, passwd, db, host = login() > db = MySQLdb.connect(host, user, passwd, 'cart') > cursor= db.cursor() > ... > cursor.close() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > > Now, python complains about me opening a new connection. Do not paraphrase error messages. Copy and paste the actual error message and traceback. > But I thought > I'd closed the first one! You thought you did, but did you? The code snippet above doesn't show any code that closes a database connection. > So, I replaced the last 3 lines with this: > > cursor.execute('use %s;' % db) > > but it didn't like that, either. Do not paraphrase error messages. Copy and paste the actual error message and traceback. -- Carsten Haese http://informixdb.sourceforge.net From joost at h-labahn.de Mon Nov 23 09:22:49 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:22:49 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <28a69bfb-f9d1-4ff6-8ae9-c080343c96d5@31g2000vbf.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk-threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From joost at h-labahn.de Mon Nov 23 09:27:38 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:27:38 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <64d2dd31-299d-4a88-a106-0d2273c26f4b@o9g2000vbj.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From mail at anjanesh.net Mon Nov 23 09:27:40 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 19:57:40 +0530 Subject: print function in python3.1 In-Reply-To: <7mvje2F3inifiU1@mid.uni-berlin.de> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> Message-ID: <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> As of now, there is no mysql adaptor for Python3. Hence cant use escape_string() > I don't have the slightest clue what you want to say with that. -- Anjanesh Lekshmnarayanan From joost at h-labahn.de Mon Nov 23 09:30:29 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:30:29 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From joost at h-labahn.de Mon Nov 23 09:33:27 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:33:27 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <3d72a0d4-a437-4ced-ac00-14ca48ad5f4f@o31g2000vbi.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From carsten.haese at gmail.com Mon Nov 23 09:40:30 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 09:40:30 -0500 Subject: print function in python3.1 In-Reply-To: <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > As of now, there is no mysql adaptor for Python3. Hence cant use escape_string() Maybe it would help if you explained what you are actually trying to accomplish. -- Carsten Haese http://informixdb.sourceforge.net From victorsubervi at gmail.com Mon Nov 23 09:45:36 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 09:45:36 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Message-ID: <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> On Mon, Nov 23, 2009 at 9:17 AM, Carsten Haese wrote: > You thought you did, but did you? The code snippet above doesn't show > any code that closes a database connection. > Would you be so kind as to tell me exactly what code *does* close a database, then? That would solve this handily. Other than than, when I am at a computer when I can provide you error messages, I will, but it all boils down to that code that closes the database, doesn't it? Since my code, according to you (and it seems logical) didn't, I sure would appreciate your providing the correct code that would. Thank you, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From carsten.haese at gmail.com Mon Nov 23 10:08:36 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 10:08:36 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Mon, Nov 23, 2009 at 9:17 AM, Carsten Haese > wrote: > > You thought you did, but did you? The code snippet above doesn't show > any code that closes a database connection. > > > Would you be so kind as to tell me exactly what code *does* close a > database, then? Assuming that db is the name of the database connection object, db.close() closes the connection. > That would solve this handily. Other than than, when I > am at a computer when I can provide you error messages, I will, but it > all boils down to that code that closes the database, doesn't it? Only if your diagnosis of the problem is accurate, and I have my doubts about that. A MySQL database server is perfectly capable of entertaining multiple simultaneous connections, so I find it unlikely that your inability to open a second connection is caused by not closing the first connection. As I said, the best way we can help you is if you copy the actual error message so that we may diagnose the actual problem and suggest a solution that fixes the problem. -- Carsten Haese http://informixdb.sourceforge.net From brendandetracey at yahoo.com Mon Nov 23 10:22:25 2009 From: brendandetracey at yahoo.com (Brendan) Date: Mon, 23 Nov 2009 07:22:25 -0800 (PST) Subject: KirbyBase : replacing string exceptions Message-ID: In KirbyBase there is a method that uses string exceptions for control, even though it has a defined exception. Is there any reason the string exceptions below could not be replaced? i.e. in code below replace: raise "No Match" with: raise KBError() and except 'No Match': with: except KBError: I have pasted the relevant method and the class definition of KBError below #---------------------------------------------------------------------- # _getMatches #---------------------------------------------------------------------- def _getMatches(self, fptr, fields, patterns, useRegExp): # Initialize a list to hold all records that match the search # criteria. match_list = [] # If one of the fields to search on is 'recno', which is the # table's primary key, then search just on that field and return # at most one record. if 'recno' in fields: return self._getMatchByRecno(fptr,patterns) # Otherwise, search table, using all search fields and patterns # specified in arguments lists. else: new_patterns = [] fieldNrs = [self.field_names.index(x) for x in fields] for fieldPos, pattern in zip(fieldNrs, patterns): if self.field_types[fieldPos] == str: # If useRegExp is True, compile the pattern to a # regular expression object and add it to the # new_patterns list. Otherwise, just add it to # the new_patterns list. This will be used below # when matching table records against the patterns. if useRegExp: new_patterns.append(re.compile(pattern)) # the pattern can be a tuple with re flags like re.I else: new_patterns.append(pattern) elif self.field_types[fieldPos] == bool: # If type is boolean, I am going to coerce it to be # either True or False by applying bool to it. This # is because it could be '' or []. Next, I am going # to convert it to the string representation: either # 'True' or 'False'. The reason I do this is because # that is how it is stored in each record of the table # and it is a lot faster to change this one value from # boolean to string than to change possibly thousands # of table values from string to boolean. And, if they # both are either 'True' or 'False' I can still # compare them using the equality test and get the same # result as if they were both booleans. new_patterns.append(str(bool(pattern))) else: # If type is int, float, date, or datetime, this next # bit of code will split the the comparison string # into the string representing the comparison # operator (i.e. ">=" and the actual value we are going # to compare the table records against from the input # pattern, (i.e. "5"). So, for example, ">5" would be # split into ">" and "5". r = re.search('[\s]*[\+-]?\d', pattern) if self.field_types[fieldPos] == int: patternValue = int(pattern[r.start():]) elif self.field_types[fieldPos] == float: patternValue = float(pattern[r.start():]) else: patternValue = pattern[r.start():] new_patterns.append( [self.cmpFuncs[pattern[:r.start()]], patternValue] ) fieldPos_new_patterns = zip(fieldNrs, new_patterns) maxfield = max(fieldNrs)+1 # Record current position in table. Then read first detail # record. fpos = fptr.tell() line = fptr.readline() # Loop through entire table. while line: # Strip off newline character and any trailing spaces. line = line[:-1].strip() try: # If blank line, skip this record. if line == "": raise 'No Match' # Split the line up into fields. record = line.split("|", maxfield) # Foreach correspond field and pattern, check to see # if the table record's field matches successfully. for fieldPos, pattern in fieldPos_new_patterns: # If the field type is string, it # must be an exact match or a regular expression, # so we will compare the table record's field to it # using either '==' or the regular expression # engine. Since it is a string field, we will need # to run it through the unencodeString function to # change any special characters back to their # original values. if self.field_types[fieldPos] == str: try: if useRegExp: if not pattern.search( self._unencodeString(record [fieldPos]) ): raise 'No Match' else: if record[fieldPos] != pattern: raise 'No Match' except Exception: raise KBError( 'Invalid match expression for %s' % self.field_names[fieldPos]) # If the field type is boolean, then I will simply # do an equality comparison. See comments above # about why I am actually doing a string compare # here rather than a boolean compare. elif self.field_types[fieldPos] == bool: if record[fieldPos] != pattern: raise 'No Match' # If it is not a string or a boolean, then it must # be a number or a date. else: # Convert the table's field value, which is a # string, back into it's native type so that # we can do the comparison. if record[fieldPos] == '': tableValue = None elif self.field_types[fieldPos] == int: tableValue = int(record[fieldPos]) elif self.field_types[fieldPos] == float: tableValue = float(record[fieldPos]) # I don't convert datetime values from strings # back into their native types because it is # faster to just leave them as strings and # convert the comparison value that the user # supplied into a string. Comparing the two # strings works out the same as comparing two # datetime values anyway. elif self.field_types[fieldPos] in ( datetime.date, datetime.datetime): tableValue = record[fieldPos] else: # If it falls through to here, then, # somehow, a bad field type got put into # the table and we show an error. raise KBError('Invalid field type for %s' % self.field_names[fieldPos]) # Now we do the actual comparison. I used to # just do an eval against the pattern string # here, but I found that eval's are VERY slow. # So, now I determine what type of comparison # they are trying to do and I do it directly. # This sped up queries by 40%. if not pattern[0](tableValue, pattern[1]): raise 'No Match' # If a 'No Match' exception was raised, then go to the # next record, otherwise, add it to the list of matches. except 'No Match': pass else: match_list.append([line, fpos]) # Save the file position BEFORE we read the next record, # because after a read it is pointing at the END of the # current record, which, of course, is also the BEGINNING # of the next record. That's why we have to save the # position BEFORE we read the next record. fpos = fptr.tell() line = fptr.readline() # After searching, return the list of matched records. return match_list #---------------------------------------------------------------------- #-------------------------------------------------------------------------- # KBError Class #-------------------------------------------------------------------------- class KBError(Exception): """Exception class for Database Management System. Public Methods: __init__ - Create an instance of exception. """ #---------------------------------------------------------------------- # init #---------------------------------------------------------------------- def __init__(self, value): self.value = value def __str__(self): return `self.value` # I overrode repr so I could pass error objects from the server to the # client across the network. def __repr__(self): format = """KBError("%s")""" return format % (self.value) From victorsubervi at gmail.com Mon Nov 23 10:26:57 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 10:26:57 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> Message-ID: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> On Mon, Nov 23, 2009 at 10:08 AM, Carsten Haese wrote: > As I said, the best way we can help you is if you copy the actual error > message so that we may diagnose the actual problem and suggest a > solution that fixes the problem. > That gave me the idea that I should simply open two separate connections. Here's the error that got thrown with the second connection: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/angrynates.com/cart/createProducts2.py 117 118 119 ''' 120 121 createProducts2() *createProducts2* = /var/www/html/angrynates.com/cart/createProducts2.py in *createProducts2*() 35 sst.append(bits[2]) 36 sstp.append(bits[1]) 37 db2 = MySQLdb.connect(host, user, passwd, db) 38 cursor2 = db.cursor() 39 created = [] db2 *undefined*, *global* *MySQLdb* = , MySQLdb.*connect * = , *host* = 'localhost', *user* = 'beno', *passwd* = 'Kj9rg2', *db* = <_mysql.connection open to 'localhost' at 28772c0> /usr/lib64/python2.4/site-packages/MySQLdb/__init__.py in *Connect*(*args=('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), **kwargs={}) 73 """Factory function for connections.Connection.""" 74 from connections import Connection 75 return Connection(*args, **kwargs) 76 77 connect = Connection = Connect *Connection* = , *args* = ('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), *kwargs* = {} /usr/lib64/python2.4/site-packages/MySQLdb/connections.py in *__init__*(self=<_mysql.connection closed at 28d95c0>, *args=('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), **kwargs={}) 162 kwargs2['client_flag'] = client_flag 163 164 super(Connection, self).__init__(*args, **kwargs2) 165 166 self.encoders = dict([ (k, v) for k, v in conv.items() *builtin* *super* = , *global* *Connection* = , *self* = <_mysql.connection closed at 28d95c0>, ).*__init__* = >, *args* = ('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), *kwargs2* = {'client_flag': 196608, 'conv': {0: , 1: , 2: , 3: , 4: , 5: , 7: , 8: , 9: , 10: , ...}}*TypeError*: connect() argument 4 must be string, not Connection args = ('connect() argument 4 must be string, not Connection',) TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Mon Nov 23 10:37:36 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 10:37:36 -0500 Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <85iqd145hb.fsf@agentultra.com> papa hippo writes: > On 20 nov, 09:02, Stefan Behnel wrote: >> papa hippo, 19.11.2009 19:53: >> >> > The prime goal of 'phileas' is to enable html code to be seamlessly >> > included in python code in a natural looking syntax, without resorting >> > to templatng language. >> >> I assume you know XIST, ElementTree's ElementMaker, and all those other >> ways of generating XML/HTML from Python code in a natural looking way? >> >> Stefan > > Hi Stefan, > > Thanks for your feedback. > > Yes, I am aware that phileas might - on the basis of the short > description on this post - come across like a 're-invented wheel'. > There is, however, one big difference between phileas and all other > other similar packages (XIST, ELementTree, HTMLgen, HyperText, > pyhtmloo etc.) that I inspected: > > Phileas uses distinct objects to generate each start and end tag, > whereas all the others use a single function call (in some cases > itself generated by a function call) to generate a complete well- > formed element including start-tag and (where required) end-tag. In > theory this is less neat and indeed it means one can write 'bad' HTML > (e.g. missing end of paragraphs) with phileas just as easily as when > writing pure html. In practice, however, I find it at a lot easier to > use. > > While using pyhtmloo (my previous favourite HTML generator), I had > found myself using awkward complicated artificial constructions in > order to generate all but the simplest HTML - and spent much time > playing 'hunt the missing bracket'. With phileas, these complexities > seem to just fall away. Any decent editor should be able to balance parenthesis for you. > > Put another way, Phileas generates HTML4.0 - warts and all; it is not > a parser or generator of XML. > > I'm considering building in checks/warnings for unclosed elements > etc., probably in the next-but-one pre-release. That your library will require a validation to be executed at run-time seems like it will be tedious to use. A decent text editor can even balance your HTML tags for you. Though you have a neat "DSL" like language for representing HTML elements. I'd suggest taking it one step further and creating a machine that can read in a Python data-structure and with as few hints as possible wrap it in the appropriate tags. > > Larry From mail at anjanesh.net Mon Nov 23 10:55:54 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 21:25:54 +0530 Subject: print function in python3.1 In-Reply-To: References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: <1a7951080911230755r12307fa5o2dbcf2ca8eb9fde6@mail.gmail.com> > Maybe it would help if you explained what you are actually trying to > accomplish. import csv f = csv.reader(open('data.txt'), delimiter='\t') # 2GB text file sql = "INSERT INTO `data` VALUES (NULL,%s,%s,%s,%s,%s);" for row in f: print (sql, (row[0],row[1],row[2],row[3],row[4])) $ python3 parse.py3 > data.sql But because of print() being a function in Py3, print (sql, (row[0],row[1],row[2],row[3],row[4])) prints INSERT INTO `data` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', 'abcde', '2006-03-01 05:17:14', '', '') instead of INSERT INTO `data` VALUES (NULL, '142', 'abcde', '2006-03-01 05:17:14', '', ''); Anjanesh From carsten.haese at gmail.com Mon Nov 23 10:59:59 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 10:59:59 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Mon, Nov 23, 2009 at 10:08 AM, Carsten Haese > wrote: > > As I said, the best way we can help you is if you copy the actual error > message so that we may diagnose the actual problem and suggest a > solution that fixes the problem. > > > That gave me the idea that I should simply open two separate > connections. Here's the error that got thrown with the second connection: > > [snip...] > > 37 db2 = MySQLdb.connect(host, user, passwd, db) > > [snip...] > > TypeError: connect() argument 4 must be string, not Connection Have you tried to *read* and *understand* this error message? My guess is no. The error message tells you all you need to know. You need to pass a string as argument 4, but you aren't. <> is a database connection object, not a string. Change <> to a string containing the name of the MySQL database to which you want to connect. -- Carsten Haese http://informixdb.sourceforge.net From victorsubervi at gmail.com Mon Nov 23 11:05:02 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 11:05:02 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: <4dc0cfea0911230805h691b3d67u3820a01c251aff68@mail.gmail.com> On Mon, Nov 23, 2009 at 10:59 AM, Carsten Haese wrote: > Have you tried to *read* and *understand* this error message? My guess > is no. The error message tells you all you need to know. You need to > pass a string as argument 4, but you aren't. <> is a database > connection object, not a string. Change <> to a string containing > the name of the MySQL database to which you want to connect. > Yes, Carsten, I did read the error message. And the obvious passed me by LOL! Sorry. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 23 11:07:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 17:07:33 +0100 Subject: print function in python3.1 References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: <7mvqa5F3kbrpqU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: >> Maybe it would help if you explained what you are actually trying to >> accomplish. > > import csv > f = csv.reader(open('data.txt'), delimiter='\t') # 2GB text file > sql = "INSERT INTO `data` VALUES (NULL,%s,%s,%s,%s,%s);" > for row in f: > print (sql, (row[0],row[1],row[2],row[3],row[4])) > > $ python3 parse.py3 > data.sql > > But because of print() being a function in Py3, > print (sql, (row[0],row[1],row[2],row[3],row[4])) > prints > INSERT INTO `data` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); > ('142', 'abcde', '2006-03-01 05:17:14', '', '') > instead of > INSERT INTO `data` VALUES (NULL, '142', 'abcde', '2006-03-01 05:17:14', > '', ''); No. It does so because you don't use print(sql % (row[0],row[1],row[2],row[3],row[4])) And that has nothing to do with print being a function or not. Diez From showell30 at yahoo.com Mon Nov 23 11:21:10 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 23 Nov 2009 08:21:10 -0800 (PST) Subject: KirbyBase : replacing string exceptions References: Message-ID: <22c066e4-2a4e-4e0b-8c60-2039a2536f81@g22g2000prf.googlegroups.com> On Nov 23, 7:22?am, Brendan wrote: > In KirbyBase there is a method that uses string exceptions for > control, even though it has a defined exception. Is there any reason > the string exceptions below could not be replaced? > i.e. in code below replace: > raise "No Match" > with: > raise KBError() > and > except 'No Match': > with: > except KBError: > It looks like in some cases KBError() should fall through and only 'No Match' was intended to be silently caught. I would consider either leaving it alone if it works, or doing more serious surgery on the code to simplify the control flow. The method is awfully long and nested. > I have pasted the relevant method and the class definition of KBError > below > > #---------------------------------------------------------------------- > ? ? # _getMatches > > #---------------------------------------------------------------------- > ? ? def _getMatches(self, fptr, fields, patterns, useRegExp): > ? ? ? ? # Initialize a list to hold all records that match the search > ? ? ? ? # criteria. > ? ? ? ? match_list = [] > > ? ? ? ? # If one of the fields to search on is 'recno', which is the > ? ? ? ? # table's primary key, then search just on that field and > return > ? ? ? ? # at most one record. > ? ? ? ? if 'recno' in fields: > ? ? ? ? ? ? return self._getMatchByRecno(fptr,patterns) > ? ? ? ? # Otherwise, search table, using all search fields and > patterns > ? ? ? ? # specified in arguments lists. > ? ? ? ? else: > ? ? ? ? ? ? new_patterns = [] > ? ? ? ? ? ? fieldNrs = [self.field_names.index(x) for x in fields] > ? ? ? ? ? ? for fieldPos, pattern in zip(fieldNrs, patterns): > ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > ? ? ? ? ? ? ? ? ? ? # If useRegExp is True, compile the pattern to a > ? ? ? ? ? ? ? ? ? ? # regular expression object and add it to the > ? ? ? ? ? ? ? ? ? ? # new_patterns list. ?Otherwise, ?just add it to > ? ? ? ? ? ? ? ? ? ? # the new_patterns list. ?This will be used below > ? ? ? ? ? ? ? ? ? ? # when matching table records against the > patterns. > ? ? ? ? ? ? ? ? ? ? if useRegExp: > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(re.compile(pattern)) > ? ? ? ? ? ? ? ? ? ? ? ? # the pattern can be a tuple with re flags > like re.I > ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(pattern) > ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > ? ? ? ? ? ? ? ? ? ? # If type is boolean, I am going to coerce it to > be > ? ? ? ? ? ? ? ? ? ? # either True or False by applying bool to it. > This > ? ? ? ? ? ? ? ? ? ? # is because it could be '' or []. ?Next, I am > going > ? ? ? ? ? ? ? ? ? ? # to convert it to the string representation: > either > ? ? ? ? ? ? ? ? ? ? # 'True' or 'False'. ?The reason I do this is > because > ? ? ? ? ? ? ? ? ? ? # that is how it is stored in each record of the > table > ? ? ? ? ? ? ? ? ? ? # and it is a lot faster to change this one value > from > ? ? ? ? ? ? ? ? ? ? # boolean to string than to change possibly > thousands > ? ? ? ? ? ? ? ? ? ? # of table values from string to boolean. ?And, if > they > ? ? ? ? ? ? ? ? ? ? # both are either 'True' or 'False' I can still > ? ? ? ? ? ? ? ? ? ? # compare them using the equality test and get the > same > ? ? ? ? ? ? ? ? ? ? # result as if they were both booleans. > ? ? ? ? ? ? ? ? ? ? new_patterns.append(str(bool(pattern))) > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? # If type is int, float, date, or datetime, this > next > ? ? ? ? ? ? ? ? ? ? # bit of code will split the the comparison string > ? ? ? ? ? ? ? ? ? ? # into the string representing the comparison > ? ? ? ? ? ? ? ? ? ? # operator (i.e. ">=" and the actual value we are > going > ? ? ? ? ? ? ? ? ? ? # to compare the table records against from the > input > ? ? ? ? ? ? ? ? ? ? # pattern, (i.e. "5"). ?So, for example, ">5" > would be > ? ? ? ? ? ? ? ? ? ? # split into ">" and "5". > ? ? ? ? ? ? ? ? ? ? r = re.search('[\s]*[\+-]?\d', pattern) > ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == int: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = int(pattern[r.start():]) > ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = float(pattern[r.start():]) > ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = pattern[r.start():] > ? ? ? ? ? ? ? ? ? ? new_patterns.append( > ? ? ? ? ? ? ? ? ? ? ?[self.cmpFuncs[pattern[:r.start()]], > patternValue] > ? ? ? ? ? ? ? ? ? ? ) > > ? ? ? ? ? ? fieldPos_new_patterns = zip(fieldNrs, new_patterns) > ? ? ? ? ? ? maxfield = max(fieldNrs)+1 > > ? ? ? ? ? ? # Record current position in table. Then read first detail > ? ? ? ? ? ? # record. > ? ? ? ? ? ? fpos = fptr.tell() > ? ? ? ? ? ? line = fptr.readline() > > ? ? ? ? ? ? # Loop through entire table. > ? ? ? ? ? ? while line: > ? ? ? ? ? ? ? ? # Strip off newline character and any trailing spaces. > ? ? ? ? ? ? ? ? line = line[:-1].strip() > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? # If blank line, skip this record. > ? ? ? ? ? ? ? ? ? ? if line == "": raise 'No Match' > ? ? ? ? ? ? ? ? ? ? # Split the line up into fields. > ? ? ? ? ? ? ? ? ? ? record = line.split("|", maxfield) > > ? ? ? ? ? ? ? ? ? ? # Foreach correspond field and pattern, check to > see > ? ? ? ? ? ? ? ? ? ? # if the table record's field matches > successfully. > ? ? ? ? ? ? ? ? ? ? for fieldPos, pattern in fieldPos_new_patterns: > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is string, it > ? ? ? ? ? ? ? ? ? ? ? ? # must be an exact match or a regular > expression, > ? ? ? ? ? ? ? ? ? ? ? ? # so we will compare the table record's field > to it > ? ? ? ? ? ? ? ? ? ? ? ? # using either '==' or the regular expression > ? ? ? ? ? ? ? ? ? ? ? ? # engine. ?Since it is a string field, we will > need > ? ? ? ? ? ? ? ? ? ? ? ? # to run it through the unencodeString > function to > ? ? ? ? ? ? ? ? ? ? ? ? # change any special characters back to their > ? ? ? ? ? ? ? ? ? ? ? ? # original values. > ? ? ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if useRegExp: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern.search( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self._unencodeString(record > [fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? except Exception: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'Invalid match expression for %s' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is boolean, then I will > simply > ? ? ? ? ? ? ? ? ? ? ? ? # do an equality comparison. ?See comments > above > ? ? ? ? ? ? ? ? ? ? ? ? # about why I am actually doing a string > compare > ? ? ? ? ? ? ? ? ? ? ? ? # here rather than a boolean compare. > ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? # If it is not a string or a boolean, then it > must > ? ? ? ? ? ? ? ? ? ? ? ? # be a number or a date. > ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Convert the table's field value, which > is a > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # string, back into it's native type so > that > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # we can do the comparison. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] == '': > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = None > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == int: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = int(record[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = float(record[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I don't convert datetime values from > strings > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # back into their native types because it > is > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # faster to just leave them as strings > and > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # convert the comparison value that the > user > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # supplied into a string. ?Comparing the > two > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # strings works out the same as comparing > two > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # datetime values anyway. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] in ( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?datetime.date, datetime.datetime): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = record[fieldPos] > ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # If it falls through to here, then, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # somehow, a bad field type got put > into > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # the table and we show an error. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError('Invalid field type for > %s' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Now we do the actual comparison. ?I used > to > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # just do an eval against the pattern > string > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # here, but I found that eval's are VERY > slow. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # So, now I determine what type of > comparison > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # they are trying to do and I do it > directly. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # This sped up queries by 40%. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern[0](tableValue, pattern[1]): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? # If a 'No Match' exception was raised, then go to the > ? ? ? ? ? ? ? ? # next record, otherwise, add it to the list of > matches. > ? ? ? ? ? ? ? ? except 'No Match': > ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? match_list.append([line, fpos]) > ? ? ? ? ? ? ? ? # Save the file position BEFORE we read the next > record, > ? ? ? ? ? ? ? ? # because after a read it is pointing at the END of > the > ? ? ? ? ? ? ? ? # current record, which, of course, is also the > BEGINNING > ? ? ? ? ? ? ? ? # of the next record. ?That's why we have to save the > ? ? ? ? ? ? ? ? # position BEFORE we read the next record. > ? ? ? ? ? ? ? ? fpos = fptr.tell() > ? ? ? ? ? ? ? ? line = fptr.readline() > > ? ? ? ? # After searching, return the list of matched records. > ? ? ? ? return match_list > > #---------------------------------------------------------------------- > > #-------------------------------------------------------------------------- > # KBError Class > #-------------------------------------------------------------------------- > class KBError(Exception): > ? ? """Exception class for Database Management System. > > ? ? Public Methods: > ? ? ? ? __init__ - Create an instance of exception. > ? ? """ > > #---------------------------------------------------------------------- > ? ? # init > > #---------------------------------------------------------------------- > ? ? def __init__(self, value): > ? ? ? ? self.value = value > > ? ? def __str__(self): > ? ? ? ? return `self.value` > > ? ? # I overrode repr so I could pass error objects from the server to > the > ? ? # client across the network. > ? ? def __repr__(self): > ? ? ? ? format = """KBError("%s")""" > ? ? ? ? return format % (self.value) From james at agentultra.com Mon Nov 23 11:29:33 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 11:29:33 -0500 Subject: Go versus Brand X References: Message-ID: <85d439432q.fsf@agentultra.com> aahz at pythoncraft.com (Aahz) writes: > Comparing Go to another computer language -- do you recognize it? > > http://www.cowlark.com/2009-11-15-go/ If you skip to the conclusion, you'll be better off. The author has an interesting point. Go (the language) is not really ground-breaking. I don't understand why they're so busy creating their own walled garden... Their own browser, their own programming languages, their own file systems, etc. Weird. From thomas at thomas-lotze.de Mon Nov 23 11:45:24 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Mon, 23 Nov 2009 17:45:24 +0100 Subject: Minimally intrusive XML editing using Python References: Message-ID: Please consider this a reply to any unanswered messages I received in response to my original post. Dave Angel wrote: > What's your real problem, or use case? Are you just concerned with > diffing, or are others likely to read the xml, and want it formatted the > way it already is? I'd like to put the XML under revision control along with other stuff. Other people should be able to make sense of the diffs and I'd rather not require them to configure their tools to use some XML differ. > And how general do you need this tool to be? For > example, if the only thing you're doing is modifying existing attributes > or existing tags, the "minimal change" would be pretty unambiguous. But > if you're adding tags, or adding content on what was an empty element, > then the requirement gets fuzzy And finding an existing library for > something "fuzzy" is unlikely. Sure. I guess it's something like an 80/20 problem: Changing attributes in a way that keeps the rest of the XML intact will go a long way and as we're talking about XML that is supposed to be looked at by humans, I would base any further requirements on the assumption that it's pretty-printed in some way so that removing an element, for example, can be defined by touching as few lines as possible, and adding one can be restricted to adding a line in the appropriate place. If more complex stuff isn't as well-defined, that would be entirely OK with me. > Sample input, change list, and desired output would be very useful. I'd like to be able to reliably produce a diff like this using a program that lets me change the value in some useful way, which might be dragging a point across a map with the mouse in this example: --- foo.gpx 2009-05-30 19:45:45.000000000 +0200 +++ bar.gpx 2009-11-23 17:41:36.000000000 +0100 @@ -11,7 +11,7 @@ 0.792244 2d - + 508.300000 15.150000 -- Thomas From lie.1296 at gmail.com Mon Nov 23 11:51:12 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 03:51:12 +1100 Subject: Go versus Brand X In-Reply-To: <85d439432q.fsf@agentultra.com> References: <85d439432q.fsf@agentultra.com> Message-ID: <4b0abddb$1@dnews.tpgi.com.au> J Kenneth King wrote: > aahz at pythoncraft.com (Aahz) writes: > >> Comparing Go to another computer language -- do you recognize it? >> >> http://www.cowlark.com/2009-11-15-go/ > > If you skip to the conclusion, you'll be better off. > > The author has an interesting point. > > Go (the language) is not really ground-breaking. > > I don't understand why they're so busy creating their own walled > garden... > > Their own browser, their own programming languages, their own file > systems, etc. because they can, no? Normal business logic doesn't apply to Google. From james at agentultra.com Mon Nov 23 11:59:38 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 11:59:38 -0500 Subject: Perl conversion to python... References: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com> Message-ID: <858wdx41ol.fsf@agentultra.com> Benjamin Schollnick writes: > Folks, > > I'm having some issues here with pyserial & trying to translate a perl > script to python... It's probably my inexperience with PySerial & > perl that is troubling me... > > Can anyone assist? > > I'm concerned, since I can't seem to receive the data in any reliable > manner.. I've tested multiple times, and only once received data... > So I suspect that my Transmit & receive code is faulty... > > def xmit ( data, serialport ): > for x in data: > xmit_byte (x, serialport) > # serialport.write ( binascii.unhexlify ( data ) ) > # for x in data: > # print str(x).encode ('hex') > # serialport.write ( x.encode('hex')) > > def receive ( serialport ): > received = serialport.read (20) > print received, "!" Gah.. indentation is broken in your post... :S > > ----- Perl Code ---- > sub tx_command { > my $port = shift; > my $cmd = shift; > > # warn "tx_command($cmd)\n"; > > my @cmd_bytes = split(/\s/, $cmd); > > foreach my $byte (@cmd_bytes) { > $byte = pack('C', hex($byte)); > > $port -> write($byte); > select(undef, undef, undef, 0.01); > } > } import struct def tx_command(port, cmd): cmd_bytes = cmd.split(' ') for byte in cmd_bytes: byte = struct.pack('C', hex(int(byte))) port.write(byte) # select() is a system call in Perl.. # insert Python equivalent here > > # returns the rtt, or 0 if no response > sub rx_response { > my ($port, $address) = @_; > > $port->read_char_time(0); # don't wait for each character > $port->read_const_time(5000); # timeout if we don't get what we're > looking for > > my $buf = ''; > > my $t_start = time; > > ### accumulate one byte at a time until we see the substring we're > looking for > > while (1) { > my ($count_in, $string_in) = $port->read(1); > > if ($count_in == 0) { > # warn "TIMEOUT\n"; > return 0; > } > > $buf .= $string_in; > > my $bufstring = packed_to_text($buf); > > #warn "bufstring: ".$bufstring; > > if ($bufstring =~/02 50 $address (.. .. ..) (..) (.. ..)/) { > > my $powerlinc_addr = $1; > my $flags = $2; > my $command = $3; > > # warn "got response!\n"; > > my $rtt = time() - $t_start; > > return $rtt; > } > > } > } This isn't all that more complicated. I dunno, maybe it's just me but I find most Perl pretty easy to read (barring obfuscation which just takes longer to read but is no more difficult). For the most part you can generally substitute the Python equivalent statements for each line of Perl and get good results. Optimize for better Pythonicity afterwards. From johnguenther at me.com Mon Nov 23 12:02:36 2009 From: johnguenther at me.com (John Guenther) Date: Mon, 23 Nov 2009 12:02:36 -0500 Subject: adding a directory to sys.path Message-ID: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> This is Mac related. I am running snow leopard. I am using Python 2.6.3. I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. I have a directory called PythonPrograms in my Documents folder. When I installed Python it had '/Users/johnguenther/Documents' as sys.path[0]. I tried setting PYTHONPATH and this worked for running Python from the bash shell but only until I exited the shell. PYTHONPATH had to be reset each time I restarted the shell. And it had no effect on sys.path when I ran Idle. I tried putting files with names ending with .pth in various directories all of which were already in sys.path. In this file I would put the path name of the directory, i.e., '/Users/johnguenter/Documents/PythonPrograms'. This had absolutely no effect. I searched the web for help and found nothing that worked. Finally I looked at a file that had been installed when I installed wxPython. I modified that file and now the directory I want is always part of sys.path when I start idle. Since I had so much trouble finding an answer to the question "How do I permanently change sys.path?", I thought I might post this message. I created a file called myconfig.pth In this file I included one line: import site; site.addsitedir('/Users/johnguenther/Documents/PythonPrograms') I placed the file in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages. From showell30 at yahoo.com Mon Nov 23 12:05:42 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 23 Nov 2009 09:05:42 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On Nov 23, 2:47?am, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit?: > > > > > I think there is an overall design sensibility, it's just not a > > human-facing one. They claim that they designed the syntax to be very > > easily parsed by very simple tools in order to make things like syntax > > highlighters very easy and robust. So indentation-based blocks are right > > out. > > But computer languages should be designed to be readable by humans. > It's not like you need to write a new parser once a year, but you have to > read code everyday. > Besides, if you want parsing to be easy, you don't need to make the > syntax minimal, you just have to provide the parsing routines as part of > the standard library and/or of an external API. You could argue that by keeping the computer-facing part of the language simple, you make it easier for tools to take care of the human-facing side. But when you leave it up to third-party tools (or diligent programmers) to format code, the language designers have a lot less control over the aesthetics of programs in the wild, and you start having style wars over braces, etc., and no two Go programs will look like they reflect the same sensibility. Human readability and computer readability obviously do not have to be completely orthogonal, as proven by Python. But to the extent that they are orthogonal, I think there's a natural inclination to make a systems programming language focus on the computer-facing issues, with the huge caveat that leaving human-side issues to higher levels on the stack (linters, code formatters, etc.) complicates the overall ecosystem. Since Go is designed for building large programs, any failure of the Go community to prescribe a common aesthetic will probably get magnified to a large degree. Finally, a lot of aesthetics transcend syntax, so you can argue that the most important thing to do to enable programmers to create beautiful programs is to make them be more productive, and a fast compiler is pretty crucial for that, since a lot of human programmers work better in a "flow" state. From brendandetracey at yahoo.com Mon Nov 23 12:05:48 2009 From: brendandetracey at yahoo.com (Brendan) Date: Mon, 23 Nov 2009 09:05:48 -0800 (PST) Subject: KirbyBase : replacing string exceptions References: <22c066e4-2a4e-4e0b-8c60-2039a2536f81@g22g2000prf.googlegroups.com> Message-ID: <6c4841d5-6878-4723-800d-0d3200591135@m20g2000vbp.googlegroups.com> On Nov 23, 12:21?pm, Steve Howell wrote: > On Nov 23, 7:22?am, Brendan wrote: > > > In KirbyBase there is a method that uses string exceptions for > > control, even though it has a defined exception. Is there any reason > > the string exceptions below could not be replaced? > > i.e. in code below replace: > > raise "No Match" > > with: > > raise KBError() > > and > > except 'No Match': > > with: > > except KBError: > > It looks like in some cases KBError() should fall through and only 'No > Match' was intended to be silently caught. > > I would consider either leaving it alone if it works, or doing more > serious surgery on the code to simplify the control flow. ?The method > is awfully long and nested. > > > > > I have pasted the relevant method and the class definition of KBError > > below > > > #---------------------------------------------------------------------- > > ? ? # _getMatches > > > #---------------------------------------------------------------------- > > ? ? def _getMatches(self, fptr, fields, patterns, useRegExp): > > ? ? ? ? # Initialize a list to hold all records that match the search > > ? ? ? ? # criteria. > > ? ? ? ? match_list = [] > > > ? ? ? ? # If one of the fields to search on is 'recno', which is the > > ? ? ? ? # table's primary key, then search just on that field and > > return > > ? ? ? ? # at most one record. > > ? ? ? ? if 'recno' in fields: > > ? ? ? ? ? ? return self._getMatchByRecno(fptr,patterns) > > ? ? ? ? # Otherwise, search table, using all search fields and > > patterns > > ? ? ? ? # specified in arguments lists. > > ? ? ? ? else: > > ? ? ? ? ? ? new_patterns = [] > > ? ? ? ? ? ? fieldNrs = [self.field_names.index(x) for x in fields] > > ? ? ? ? ? ? for fieldPos, pattern in zip(fieldNrs, patterns): > > ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > > ? ? ? ? ? ? ? ? ? ? # If useRegExp is True, compile the pattern to a > > ? ? ? ? ? ? ? ? ? ? # regular expression object and add it to the > > ? ? ? ? ? ? ? ? ? ? # new_patterns list. ?Otherwise, ?just add it to > > ? ? ? ? ? ? ? ? ? ? # the new_patterns list. ?This will be used below > > ? ? ? ? ? ? ? ? ? ? # when matching table records against the > > patterns. > > ? ? ? ? ? ? ? ? ? ? if useRegExp: > > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(re.compile(pattern)) > > ? ? ? ? ? ? ? ? ? ? ? ? # the pattern can be a tuple with re flags > > like re.I > > ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(pattern) > > ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > > ? ? ? ? ? ? ? ? ? ? # If type is boolean, I am going to coerce it to > > be > > ? ? ? ? ? ? ? ? ? ? # either True or False by applying bool to it. > > This > > ? ? ? ? ? ? ? ? ? ? # is because it could be '' or []. ?Next, I am > > going > > ? ? ? ? ? ? ? ? ? ? # to convert it to the string representation: > > either > > ? ? ? ? ? ? ? ? ? ? # 'True' or 'False'. ?The reason I do this is > > because > > ? ? ? ? ? ? ? ? ? ? # that is how it is stored in each record of the > > table > > ? ? ? ? ? ? ? ? ? ? # and it is a lot faster to change this one value > > from > > ? ? ? ? ? ? ? ? ? ? # boolean to string than to change possibly > > thousands > > ? ? ? ? ? ? ? ? ? ? # of table values from string to boolean. ?And, if > > they > > ? ? ? ? ? ? ? ? ? ? # both are either 'True' or 'False' I can still > > ? ? ? ? ? ? ? ? ? ? # compare them using the equality test and get the > > same > > ? ? ? ? ? ? ? ? ? ? # result as if they were both booleans. > > ? ? ? ? ? ? ? ? ? ? new_patterns.append(str(bool(pattern))) > > ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? # If type is int, float, date, or datetime, this > > next > > ? ? ? ? ? ? ? ? ? ? # bit of code will split the the comparison string > > ? ? ? ? ? ? ? ? ? ? # into the string representing the comparison > > ? ? ? ? ? ? ? ? ? ? # operator (i.e. ">=" and the actual value we are > > going > > ? ? ? ? ? ? ? ? ? ? # to compare the table records against from the > > input > > ? ? ? ? ? ? ? ? ? ? # pattern, (i.e. "5"). ?So, for example, ">5" > > would be > > ? ? ? ? ? ? ? ? ? ? # split into ">" and "5". > > ? ? ? ? ? ? ? ? ? ? r = re.search('[\s]*[\+-]?\d', pattern) > > ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == int: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = int(pattern[r.start():]) > > ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = float(pattern[r.start():]) > > ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = pattern[r.start():] > > ? ? ? ? ? ? ? ? ? ? new_patterns.append( > > ? ? ? ? ? ? ? ? ? ? ?[self.cmpFuncs[pattern[:r.start()]], > > patternValue] > > ? ? ? ? ? ? ? ? ? ? ) > > > ? ? ? ? ? ? fieldPos_new_patterns = zip(fieldNrs, new_patterns) > > ? ? ? ? ? ? maxfield = max(fieldNrs)+1 > > > ? ? ? ? ? ? # Record current position in table. Then read first detail > > ? ? ? ? ? ? # record. > > ? ? ? ? ? ? fpos = fptr.tell() > > ? ? ? ? ? ? line = fptr.readline() > > > ? ? ? ? ? ? # Loop through entire table. > > ? ? ? ? ? ? while line: > > ? ? ? ? ? ? ? ? # Strip off newline character and any trailing spaces. > > ? ? ? ? ? ? ? ? line = line[:-1].strip() > > ? ? ? ? ? ? ? ? try: > > ? ? ? ? ? ? ? ? ? ? # If blank line, skip this record. > > ? ? ? ? ? ? ? ? ? ? if line == "": raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? # Split the line up into fields. > > ? ? ? ? ? ? ? ? ? ? record = line.split("|", maxfield) > > > ? ? ? ? ? ? ? ? ? ? # Foreach correspond field and pattern, check to > > see > > ? ? ? ? ? ? ? ? ? ? # if the table record's field matches > > successfully. > > ? ? ? ? ? ? ? ? ? ? for fieldPos, pattern in fieldPos_new_patterns: > > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is string, it > > ? ? ? ? ? ? ? ? ? ? ? ? # must be an exact match or a regular > > expression, > > ? ? ? ? ? ? ? ? ? ? ? ? # so we will compare the table record's field > > to it > > ? ? ? ? ? ? ? ? ? ? ? ? # using either '==' or the regular expression > > ? ? ? ? ? ? ? ? ? ? ? ? # engine. ?Since it is a string field, we will > > need > > ? ? ? ? ? ? ? ? ? ? ? ? # to run it through the unencodeString > > function to > > ? ? ? ? ? ? ? ? ? ? ? ? # change any special characters back to their > > ? ? ? ? ? ? ? ? ? ? ? ? # original values. > > ? ? ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? try: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if useRegExp: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern.search( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self._unencodeString(record > > [fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?): > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? except Exception: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'Invalid match expression for %s' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is boolean, then I will > > simply > > ? ? ? ? ? ? ? ? ? ? ? ? # do an equality comparison. ?See comments > > above > > ? ? ? ? ? ? ? ? ? ? ? ? # about why I am actually doing a string > > compare > > ? ? ? ? ? ? ? ? ? ? ? ? # here rather than a boolean compare. > > ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? # If it is not a string or a boolean, then it > > must > > ? ? ? ? ? ? ? ? ? ? ? ? # be a number or a date. > > ? ? ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Convert the table's field value, which > > is a > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # string, back into it's native type so > > that > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # we can do the comparison. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] == '': > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = None > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == int: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = int(record[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = float(record[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I don't convert datetime values from > > strings > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # back into their native types because it > > is > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # faster to just leave them as strings > > and > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # convert the comparison value that the > > user > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # supplied into a string. ?Comparing the > > two > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # strings works out the same as comparing > > two > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # datetime values anyway. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] in ( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?- Hide quoted text - > > - Show quoted text -... > > read more ? Okay. Thanks. From vorticitywolfe at gmail.com Mon Nov 23 12:08:44 2009 From: vorticitywolfe at gmail.com (J Wolfe) Date: Mon, 23 Nov 2009 09:08:44 -0800 (PST) Subject: Print to Printer Tkinter Text Message-ID: <7a6b9bee-1e54-4069-a8e8-215186fac482@z3g2000prd.googlegroups.com> Hi, Is there a way to print the format of a Tkinter text box to a color printer with its tags, e.g. a blue text at font size 18 and bold will like it displays? Thanks, Jonathan From 457r0.jp at gmail.com Mon Nov 23 12:19:03 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 09:19:03 -0800 (PST) Subject: Beginning Question about Python functions, parameters... Message-ID: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Hi, I am trying to teach myself Python and have a good book to help me but I am stuck on something and I would like for someone to explain the following piece of code for me and what it's actually doing. Certain parts are very clear but once it enters the "def store(data, full_name): ...." function and the "def lookup()..." function things get a little confusing for me. Specifically, lines 103-108 *and* Lines 110-111. Lastly, I am not sure how to print the results I've put into this program either, the book I'm reading doesn't tell me. As you can tell, I am a beginner and I don't truly understand everything that is going on here...a lot, but not all.... Here is the code: 92 def init(data): 93 data['first'] = {} 94 data['middle'] = {} 95 data['last'] = {} 96 97 def store(data, full_name): 98 names = full_name.split() 100 if len(names) == 2: names.insert(1, '') 101 labels = 'first', 'middle', 'last' 103 for label, name in zip(labels, names): 104 people = lookup(data, label, name) 105 if people: 106 people.append(full_name) 107 else: 108 data[label][name] = [full_name] 109 110 def lookup(data, label, name): 111 return data[label].get(name) 112 113 114 MyNames = {} 115 init(MyNames) 116 store(MyNames, 'John Larry Smith') 117 lookup(MyNames, 'middle', 'Smith') From neo at picture-art.eu Mon Nov 23 12:37:33 2009 From: neo at picture-art.eu (Neo) Date: Mon, 23 Nov 2009 18:37:33 +0100 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <4B0AC85D.8050703@picture-art.eu> astral orange schrieb: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > 92 def init(data): > 93 data['first'] = {} > 94 data['middle'] = {} > 95 data['last'] = {} > 96 > 97 def store(data, full_name): > 98 names = full_name.split() > 100 if len(names) == 2: names.insert(1, '') > 101 labels = 'first', 'middle', 'last' > 103 for label, name in zip(labels, names): > 104 people = lookup(data, label, name) > 105 if people: > 106 people.append(full_name) > 107 else: > 108 data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 return data[label].get(name) > 112 > 113 > 114 MyNames = {} > 115 init(MyNames) > 116 store(MyNames, 'John Larry Smith') > 117 lookup(MyNames, 'middle', 'Smith') If it tells you so I'm not really sure its a good book - partially for teaching you into the unpythonic way to do things (above stuff, if its not a counter example, should really go into a class) Have you tried the tutorial first? Its online and very easy to follow from the very beginning but you can also skip parts if you are sure you already understand it: http://docs.python.org/tutorial/ HTH Tino From sergiomb at sapo.pt Mon Nov 23 12:39:17 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Mon, 23 Nov 2009 17:39:17 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine Message-ID: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> Hi, I am in x86_64 arch , but I need compile things on 32 bits with python setup.py build Can't change the fact that distutils creates x86_64 directories: build/temp.linux-x86_64-2.3/ Also if I try with a python compile in 32bits and installed in system . how I force distutils build to 32-bits on x86_64 arch? Thanks in advance, From wolftracks at invalid.com Mon Nov 23 12:49:17 2009 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 23 Nov 2009 09:49:17 -0800 Subject: A More Concise Description of Numpy than the Guide to Numpy? Message-ID: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? From robert.kern at gmail.com Mon Nov 23 12:54:19 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 11:54:19 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On 2009-11-23 04:47 AM, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit : >> >> I think there is an overall design sensibility, it's just not a >> human-facing one. They claim that they designed the syntax to be very >> easily parsed by very simple tools in order to make things like syntax >> highlighters very easy and robust. So indentation-based blocks are right >> out. > > But computer languages should be designed to be readable by humans. > It's not like you need to write a new parser once a year, but you have to > read code everyday. You will get no argument from me. My point was only that they had an overall design sensibility, not that it was a good one. > Besides, if you want parsing to be easy, you don't need to make the > syntax minimal, you just have to provide the parsing routines as part of > the standard library and/or of an external API. Not really. The idea was to make the language easily parsed and lexed and analyzed by *other* tools, not written in Go, that may have limited capabilities. Vim isn't written in Go and won't be able to use their API, for example. -- 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 Nov 23 13:03:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 12:03:32 -0600 Subject: A More Concise Description of Numpy than the Guide to Numpy? In-Reply-To: References: Message-ID: On 2009-11-23 11:49 AM, W. eWatson wrote: > I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more > concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists You may also find the NumPy User Guide more up your alley: http://docs.scipy.org/doc/numpy/user/ -- 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 deets at nospam.web.de Mon Nov 23 13:10:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 19:10:24 +0100 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> Message-ID: <7n01ggF3j2qn9U1@mid.uni-berlin.de> S?rgio Monteiro Basto wrote: > Hi, > I am in x86_64 arch , but I need > compile things on 32 bits with > python setup.py build > > Can't change the fact that distutils creates x86_64 > directories: > build/temp.linux-x86_64-2.3/ > > Also if I try with a python compile in 32bits and installed > in system . I doubt that. Distutils will always build based on the architecture of the interpreter you used when building an external module. Are you sure that the python you used to build the extension was the right one? What does -c "from distutils.util import get_platform; print get_platform()" return? Diez From victorsubervi at gmail.com Mon Nov 23 13:10:35 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 13:10:35 -0500 Subject: Don't Understand Error Message-ID: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Hi; I have the following code: #!/usr/bin/env python import smtplib import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from login import login import MySQLdb import re, string def mailSpreadsheet(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor= database.cursor() ourEmail1 = 'anemail at here.com' ourEmail2 = 'anotheremail at here.com' form = cgi.FieldStorage() client = form.getfirst('client', '') clientEmail = form.getfirst('clientEmail', '') po = form.getfirst('po', '') subject = 'Order From Client' sql = 'select clientEmail from clients where client="%s";' % (string.replace(client, '_', ' ')) cursor.execute(sql) clientEmail = cursor.fetchone()[0] cursor.execute('select * from %s;' % (client)) data = cursor.fetchall() i = 0 if po != '': order = 'PO#: %s\n' % (po) else: order = '' total = 0 for row in data: i += 1 quantity = form.getfirst('order_' + str(i), '') if quantity != '0': sql = 'select * from products p join %s c on p.ID=c.ID where c.ID=%s;' % (client, str(i)) cursor.execute(sql) stuff = cursor.fetchone() price = str(int(stuff[5]*100)) price = price[0:len(price)-2] + '.' + price[-2:] item, price, description, discount = stuff[2], price, stuff[3], stuff[8] order += 'Item #: ' + item + '\tQuantity: ' + quantity + '\tPrice: ' + price + '\tDiscount: ' + str(discount) + '\tDescription: ' + description[:20] + '...\n' total += float(price) * int(quantity) * (100 - discount)/100 order += 'TOTAL: $' + str(total) msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) session = smtplib.SMTP("localhost") session.login(user, passwd) # only if it requires auth header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject # session.sendmail(clientEmail, ourEmail1, header+msg) session.sendmail(clientEmail, ourEmail2, header+msg) mailSpreadsheet() The email does get sent, and it that happens out of the last line of code. If I surround the code with code to make it print a Web page, it prints without any error. However, as it is, it throws the following error: The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, me at creative.vi and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end of script headers: mailSpreadsheet.py, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py Why? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Nov 23 13:15:10 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 23 Nov 2009 19:15:10 +0100 Subject: adding a directory to sys.path In-Reply-To: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> References: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> Message-ID: <4B0AD12E.50504@cheimes.de> John Guenther schrieb: > This is Mac related. I am running snow leopard. I am using Python 2.6.3. > > I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. I have a directory called PythonPrograms in my Documents folder. When I installed Python it had '/Users/johnguenther/Documents' as sys.path[0]. I tried setting PYTHONPATH and this worked for running Python from the bash shell but only until I exited the shell. PYTHONPATH had to be reset each time I restarted the shell. And it had no effect on sys.path when I ran Idle. See my blog posting: http://lipyrary.blogspot.com/2009/08/how-to-add-new-module-search-path.html Christian From deets at nospam.web.de Mon Nov 23 13:17:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 19:17:12 +0100 Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <7n01t8F3jijv0U1@mid.uni-berlin.de> astral orange wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > 92 def init(data): > 93 data['first'] = {} > 94 data['middle'] = {} > 95 data['last'] = {} > 96 > 97 def store(data, full_name): > 98 names = full_name.split() > 100 if len(names) == 2: names.insert(1, '') > 101 labels = 'first', 'middle', 'last' > 103 for label, name in zip(labels, names): The zip-function takes n iterables, and produces a list with n-tuples out of it. Type this into the python-prompt: >>> zip([1, 2, 3], ["a", "b", "c"]) The other thing here is tuple-unpacking. If you know that something has a specific length, you can unpack it into distinct values like this: >>> a, b = (10, 20) >>> print a 10 >>> print b 20 Now for label, name in zip(labels, names): does - create a list of tuples, each tuple having two elements, the first being the label, the second a name - loops over this list - for each item in the list (remember, it's a 2-tuple!), unpack it into label and name > 104 people = lookup(data, label, name) > 105 if people: > 106 people.append(full_name) > 107 else: > 108 data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 return data[label].get(name) Data here is expected to be a dictionary of dictionaries. The first level of keys are the labels. The second is the name. It is expected that labels always exist, but names might be empty, so instead of writing return data[label][name] it uses get(name) on a dict which will return the value for the key, or None: >>> {"foo" : "bar"}.get("foo") bar >>> {"foo" : "bar"}.get("baz") >>> # no output means None That being said, I agree with Neo that this introduction seems to be rather bad. Diez From jimmy.casey.3 at gmail.com Mon Nov 23 13:26:42 2009 From: jimmy.casey.3 at gmail.com (j) Date: Mon, 23 Nov 2009 10:26:42 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> On Nov 23, 12:37?pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > ?92 def init(data): > > ?93 ? ? data['first'] = {} > > ?94 ? ? data['middle'] = {} > > ?95 ? ? data['last'] = {} > > ?96 > > ?97 def store(data, full_name): > > ?98 ? ? names = full_name.split() > > 100 ? ? if len(names) == 2: names.insert(1, '') > > 101 ? ? labels = 'first', 'middle', 'last' > > 103 ? ? for label, name in zip(labels, names): > > 104 ? ? ? ? people = lookup(data, label, name) > > 105 ? ? if people: > > 106 ? ? ? ? people.append(full_name) > > 107 ? ? else: > > 108 ? ? ? ? data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 ? ? return data[label].get(name) > > 112 > > 113 > > 114 MyNames = {} > > 115 init(MyNames) > > 116 store(MyNames, 'John Larry Smith') > > 117 lookup(MyNames, 'middle', 'Smith') > > If it tells you so I'm not really sure its a good book - partially for > teaching you into the unpythonic way to do things (above stuff, if its > not a counter example, should really go into a class) > > Have you tried the tutorial first? Its online and very easy to follow > from the very beginning but you can also skip parts if you are sure you > already understand it: > > http://docs.python.org/tutorial/ > > HTH > Tino The book is "Apress Beginning Python 2nd Edition". I think what you are saying is if I don't understand all of the code I should go into a class? Unfortunately I don't have the money or time to enroll into a class and even if I did they wouldn't be teaching Python it would be Java instead...and I've already taken Java before...so that's not really an option... Regardless, I understand up to the part "for label, name in zip (labels, names):" which zips the two sequences 'names' and 'labels' into a list of tuples... What I am not totally sure about is when the store function callsthe lookup function and does "return data[label].get(name)", that line "trips" me up some....then the lookup function returns that back to the store function, assigns the data to the variable 'people', THEN does this, which also isn't that clear to me what it's all doing: if people: people.append(full_name) else: data[label][name] = [full_name] My main problem is finding out what's it's actually *doing*? I know and understand the terminologies (what 'append' does, what a 'sequence' is, a 'list', a 'tuple', 'if'...'else'...etc...et....) Thanks for the reply back From suzieprogrammer at gmail.com Mon Nov 23 13:45:13 2009 From: suzieprogrammer at gmail.com (Susan Day) Date: Mon, 23 Nov 2009 13:45:13 -0500 Subject: Line Breaks Message-ID: Hi; I have the following line of code I'm sending to postfix: msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' '), msg) Unfortunately, it ignores the line breaks. I also tried %0A but that was ignored also. Please advise. TIA, Suzie -------------- next part -------------- An HTML attachment was scrubbed... URL: From knny.myer at gmail.com Mon Nov 23 13:45:35 2009 From: knny.myer at gmail.com (~km) Date: Mon, 23 Nov 2009 10:45:35 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) References: <4b0a06b8$1@dnews.tpgi.com.au> Message-ID: <319dbc2f-3f29-4c65-ac18-8b14dda34592@e7g2000vbi.googlegroups.com> > Though many would disagree, I consider XML as a form of database though > it is only suitable for data exchange. XML is suitable for low- to > medium-volume purpose and when compatibility with various systems is > extremely important (nearly any OS and any programming language has XML > parsers; porting a DBMS system may not be as easy as that). Thanks for the feedback. I consider XML as not very readable, so I prefer a Mark-up language like YAML. Cleaner syntax... but well, that's personal preference. > Python dictionary is stored in memory and closing the program == > deleting the database. [...] My error.. although pickling I would only "prefer" if organizing <100 books. From marcglec at free.fr Mon Nov 23 13:47:22 2009 From: marcglec at free.fr (Marc Leconte) Date: Mon, 23 Nov 2009 19:47:22 +0100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> Message-ID: <1259002042.6674.0.camel@gondor> Thx all, good to know :) Le dimanche 22 novembre 2009 ? 15:16 -0800, Steve Howell a ?crit : > On Nov 22, 3:14 pm, Steve Howell wrote: > > > Explanations of why you need to write it that will follow... > > I knew this had to be written up somewhere... > > http://www.ferg.org/projects/python_gotchas.html#contents_item_6 From sergiomb at sapo.pt Mon Nov 23 13:50:40 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Mon, 23 Nov 2009 18:50:40 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> Message-ID: <4b0ad983$0$13161$a729d347@news.telepac.pt> Diez B. Roggisch wrote: Hi, Thanks, > S?rgio Monteiro Basto wrote: > >> Hi, >> I am in x86_64 arch , but I need >> compile things on 32 bits with >> python setup.py build >> >> Can't change the fact that distutils creates x86_64 >> directories: >> build/temp.linux-x86_64-2.3/ >> >> Also if I try with a python compile in 32bits and installed >> in system . > > I doubt that. Distutils will always build based on the architecture of the > interpreter you used when building an external module. > > Are you sure that the python you used to build the extension was the right > one? What does > > -c "from distutils.util import get_platform; print > get_platform()" python32 -c "from distutils.util import get_platform; print get_platform()" linux-x86_64 ldd ~/bin/python32 linux-gate.so.1 => (0xffffe000) libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) libdl.so.2 => /lib/libdl.so.2 (0x0033f000) libutil.so.1 => /lib/libutil.so.1 (0x006b3000) libm.so.6 => /lib/libm.so.6 (0x00345000) libc.so.6 => /lib/libc.so.6 (0x001e0000) /lib/ld-linux.so.2 (0x001c2000) this a python 2.3, that's make any difference ? > > return? > > Diez From ethan at stoneleaf.us Mon Nov 23 13:52:00 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 10:52:00 -0800 Subject: attributes, properties, and accessors -- philosophy Message-ID: <4B0AD9D0.3000104@stoneleaf.us> The problem I have with properties is my typing. I'll end up assigning to an attribute, but get the spelling slightly wrong (capitalized, or missing an underscore -- non-obvious things when bug-hunting), so now I have an extra attribute which of course has zero effect on what I'm trying to do and I start getting wierd results like viewing deleted records when I *know* I set useDeleted = False... 30 minutes later I notice it was /supposed/ to be use_deleted. *sigh* So -- to keep myself out of trouble -- I have started coding such things as, for example: result = table.use_deleted() # returns True or False table.use_deleted(False) # skip deleted records instead of result = table.use_deleted table.use_deleted = False My question: is this [ severely | mildly | not at all ] un-pythonic? ~Ethan~ From jfabiani at yolo.com Mon Nov 23 14:01:00 2009 From: jfabiani at yolo.com (jfabiani at yolo.com) Date: Mon, 23 Nov 2009 11:01:00 -0800 Subject: Python & OpenOffice Spreadsheets References: <87pr79cx5m.fsf@rudin.co.uk> Message-ID: Krishnakant wrote: > On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: >> Gerhard H?ring writes: >> >> > Is there a *simple* way to read OpenOffice spreadsheets? >> > >> > Bonus: write them, too? >> > >> > I mean something like: >> > >> > doc.cells[0][0] = "foo" >> > doc.save("xyz.ods") >> > >> >>From a quick look, pyodf offers little more than just using a XML >> >>parser >> > directly. >> >> >> Depends on exactly what you mean by "simple" - but pyuno allows you to >> read and write openoffice spreadsheets. > > > Odfpy is a good module and is easy too. > http://kk.hipatia.net/public/gnukhata/gnukhata-client/ has a deb package > I built for ubuntu 9.04. > I can even provide you the distutils tarball off the list (because I > can't recall the url from I downloaded it, may be sourceforge ). > Happy hacking. > Krishnakant Would you including me in your response. I'd really like to find a py module to allow simple use of openoffice. Johnf From david_v_wright at yahoo.com Mon Nov 23 14:05:09 2009 From: david_v_wright at yahoo.com (david wright) Date: Mon, 23 Nov 2009 11:05:09 -0800 (PST) Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <753779.1414.qm@web31811.mail.mud.yahoo.com> ----- Original Message ---- From: j To: python-list at python.org Sent: Mon, November 23, 2009 10:26:42 AM Subject: Re: Beginning Question about Python functions, parameters... On Nov 23, 12:37 pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > 92 def init(data): > > 93 data['first'] = {} > > 94 data['middle'] = {} > > 95 data['last'] = {} > > 96 > > 97 def store(data, full_name): > > 98 names = full_name.split() > > 100 if len(names) == 2: names.insert(1, '') > > 101 labels = 'first', 'middle', 'last' > > 103 for label, name in zip(labels, names): > > 104 people = lookup(data, label, name) > > 105 if people: > > 106 people.append(full_name) > > 107 else: > > 108 data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 return data[label].get(name) > > 112 > > 113 > > 114 MyNames = {} > > 115 init(MyNames) > > 116 store(MyNames, 'John Larry Smith') > > 117 lookup(MyNames, 'middle', 'Smith') > > If it tells you so I'm not really sure its a good book - partially for > teaching you into the unpythonic way to do things (above stuff, if its > not a counter example, should really go into a class) > > Have you tried the tutorial first? Its online and very easy to follow > from the very beginning but you can also skip parts if you are sure you > already understand it: > > http://docs.python.org/tutorial/ > > HTH > Tino > > > My main problem is finding out what's it's actually *doing*? open it up in IDLE (or whatever development environment you use) and use the debugger to step through the code. the only way to learn stuff is to actually play with it. make a guess as to what will happen, run it, did that happen? what did happen? change something, what happens now? etc. From clp2 at rebertia.com Mon Nov 23 14:06:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Nov 2009 11:06:14 -0800 Subject: attributes, properties, and accessors -- philosophy In-Reply-To: <4B0AD9D0.3000104@stoneleaf.us> References: <4B0AD9D0.3000104@stoneleaf.us> Message-ID: <50697b2c0911231106o3ac9edc5i83fcf75e423eaf04@mail.gmail.com> On Mon, Nov 23, 2009 at 10:52 AM, Ethan Furman wrote: > The problem I have with properties is my typing. ?I'll end up assigning to > an attribute, but get the spelling slightly wrong (capitalized, or missing > an underscore -- non-obvious things when bug-hunting), so now I have an > extra attribute which of course has zero effect on what I'm trying to do and > I start getting wierd results like viewing deleted records when I *know* I > set useDeleted = False... 30 minutes later I notice it was /supposed/ to be > use_deleted. ?*sigh* > > So -- to keep myself out of trouble -- I have started coding such things as, > for example: > > result = table.use_deleted() ? ? ? # returns True or False > table.use_deleted(False) ? ? ? ? ? # skip deleted records > > instead of > > result = table.use_deleted > table.use_deleted = False > > My question: ?is this [ severely | mildly | not at all ] un-pythonic? Yes, it's unpythonic. Use something like pychecker, pylint, or pyflakes, which will catch the sorts of typo errors you talk about. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Mon Nov 23 14:12:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Nov 2009 19:12:12 +0000 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <4B0ADE8C.7010007@mrabarnett.plus.com> j wrote: > On Nov 23, 12:37 pm, Neo wrote: >> astral orange schrieb: >> >> >> >>> Hi, I am trying to teach myself Python and have a good book to help me >>> but I am stuck on something and I would like for someone to explain >>> the following piece of code for me and what it's actually doing. >>> Certain parts are very clear but once it enters the "def store(data, >>> full_name): ...." function and the "def lookup()..." function things >>> get a little confusing for me. Specifically, lines 103-108 *and* Lines >>> 110-111. >>> Lastly, I am not sure how to print the results I've put into this >>> program either, the book I'm reading doesn't tell me. As you can tell, >>> I am a beginner and I don't truly understand everything that is going >>> on here...a lot, but not all.... >>> Here is the code: >>> 92 def init(data): >>> 93 data['first'] = {} >>> 94 data['middle'] = {} >>> 95 data['last'] = {} >>> 96 >>> 97 def store(data, full_name): >>> 98 names = full_name.split() >>> 100 if len(names) == 2: names.insert(1, '') >>> 101 labels = 'first', 'middle', 'last' >>> 103 for label, name in zip(labels, names): >>> 104 people = lookup(data, label, name) >>> 105 if people: >>> 106 people.append(full_name) >>> 107 else: >>> 108 data[label][name] = [full_name] >>> 109 >>> 110 def lookup(data, label, name): >>> 111 return data[label].get(name) >>> 112 >>> 113 >>> 114 MyNames = {} >>> 115 init(MyNames) >>> 116 store(MyNames, 'John Larry Smith') >>> 117 lookup(MyNames, 'middle', 'Smith') >> If it tells you so I'm not really sure its a good book - partially for >> teaching you into the unpythonic way to do things (above stuff, if its >> not a counter example, should really go into a class) >> >> Have you tried the tutorial first? Its online and very easy to follow >> from the very beginning but you can also skip parts if you are sure you >> already understand it: >> >> http://docs.python.org/tutorial/ >> >> HTH >> Tino > > The book is "Apress Beginning Python 2nd Edition". I think what you > are saying is if I don't understand all of the code I should go into a > class? Unfortunately I don't have the money or time to enroll into a > class and even if I did they wouldn't be teaching Python it would be > Java instead...and I've already taken Java before...so that's not > really an option... > [snip] No, he's saying that the _functions_ shown in the code should go into a class, but the main criticism is that judging by the code shown above it doesn't look like a good book, and you should look at the on-line tutorial first if you haven't already done so. From neilc at norwich.edu Mon Nov 23 14:13:44 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Nov 2009 19:13:44 GMT Subject: Line-continuation "Anti-Idiom" and with statement Message-ID: <7n0578F3j7qa6U1@mid.individual.net> I installed Python 3.1 today, and I've been porting my small library of programs to the new system. I happened to read the interesting "Idioms and Anti-Idioms" HOWTO, and saw the '\' continuation character labeled an anti-idiom. I already generally avoided it, so I just nodded. Unfortunately, the new "nested" with statement (which I also read about today) forces me into this anti-idiom. When replacing an appearance of contextlib.nested with the 3K with statement, I ended up with an unexpected syntax error. with (open(roster_path, 'r') as roster_file, open(disb_path, 'w') as out_file, open(report_path, 'w') as report_file): The result was: File "C:\project\codxml.py", line 184 with (open(roster_path, 'r') as roster_file, ^ SyntaxError: invalid syntax Unless I'm missing something, I have to subject my code to a bit of contintuation: with open(roster_path, 'r') as roster_file,\ open(disb_path, 'w') as out_file,\ open(report_path, 'w') as report_file: I was thinking about submitting a enhancement request to the HOWTO, explaining that continuation my be required in this context. Am I missing anything obvious? -- Neil Cerutti From 457r0.jp at gmail.com Mon Nov 23 14:14:35 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 11:14:35 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: On Nov 23, 1:17?pm, "Diez B. Roggisch" wrote: > astral orange wrote: > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > ?92 def init(data): > > ?93 ? ? data['first'] = {} > > ?94 ? ? data['middle'] = {} > > ?95 ? ? data['last'] = {} > > ?96 > > ?97 def store(data, full_name): > > ?98 ? ? names = full_name.split() > > 100 ? ? if len(names) == 2: names.insert(1, '') > > 101 ? ? labels = 'first', 'middle', 'last' > > 103 ? ? for label, name in zip(labels, names): > > The zip-function takes n iterables, and produces a list with n-tuples out of > it. Type this into the python-prompt: > > >>> zip([1, 2, 3], ["a", "b", "c"]) > > The other thing here is tuple-unpacking. If you know that something has a > specific length, you can unpack it into distinct values like this: > > >>> a, b = (10, 20) > >>> print a > 10 > >>> print b > > 20 > > Now > > ?for label, name in zip(labels, names): > > does > > ?- create a list of tuples, each tuple having two elements, the first being > the label, the second a name > ?- loops over this list > ?- for each item in the list (remember, it's a 2-tuple!), unpack it into > label and name > > > 104 ? ? ? ? people = lookup(data, label, name) > > 105 ? ? if people: > > 106 ? ? ? ? people.append(full_name) > > 107 ? ? else: > > 108 ? ? ? ? data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 ? ? return data[label].get(name) > > Data here is expected to be a dictionary of dictionaries. The first level of > keys are the labels. The second is the name. It is expected that labels > always exist, but names might be empty, so instead of writing > > ? return data[label][name] > > it uses get(name) on a dict which will return the ?value for the key, or > None: > > > > >>> {"foo" : "bar"}.get("foo") > bar > >>> {"foo" : "bar"}.get("baz") > >>> # no output means None > > That being said, I agree with Neo that this introduction seems to be rather > bad. > > Diez Thanks all for the replies back! I do appreciate it. Yes, lines 104-111 is really where my problem lies in understanding what is going on here. I am beginner so this stuff seems a little unwieldy at the moment. :) I *did* invest $40 into this book so it' what I have to work with. By the way, the book is, "Apress Beginning Python 2nd Edition".... But back to the example, on line 104 I see there's a call to the lookup function, passing 3 parameters ('data', which I think is a nested dictionary, label (first, middle, last) and name). But I am getting lost on line 111 after the parameters are passed in to the lookup function. I'm not exactly sure what it's returning and when it does return, is this assigned the the variable 'people'? And if so, I'm not sure what 'append(full_name)' does here. The else statement which assigns '[full_name]' to 'data[label][name]' is somewhat confusing as I'm saying to myself where the heck did '[full_name]' come "into the picture". If I could understand what's going on with everything in this the rest of the chapter and the next should be fairly easy, but I really need to understand this before I move on. Thanks again for the replies back. I am looking over your comments right now. 457r0 From thomas.robitaille at gmail.com Mon Nov 23 14:14:38 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Mon, 23 Nov 2009 11:14:38 -0800 (PST) Subject: Read IDL save files into Python Message-ID: I would like to briefly advertise the 0.9.2 release of IDLSave, a package I recently developed to read IDL save files into Python. Installation instructions are available at http://idlsave.sourceforge.net/. Please do not hesitate to submit a bug report if you run into any problems! Cheers, Thomas From niklasro at gmail.com Mon Nov 23 14:20:27 2009 From: niklasro at gmail.com (NiklasRTZ) Date: Mon, 23 Nov 2009 11:20:27 -0800 (PST) Subject: IDE+hg Message-ID: Dear experts, Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim Mercurial support not found i.e. buttons to clone, commit and push to repositories to define dev env dvcs, editor and deployment all in 1. I tested Boa Constructor, dr Python, Eric and PIDA none of which has other than commandline access to Mercurial which is faster bound to button. The editor Eric claims "Mercurial support" and no obvious (button or plugin) availability, same with dr Python. Mercurial support these IDEs claim may mean that it's compatible and you must add the hg button customizing the editor. programatically. If you know a good light IDE with hg, please inform. Topic handled earlier, still undecided http://groups.google.com/group/google-appengine-python/browse_thread/... Thanks in advance Niklas Rosencrantz From apt.shansen at gmail.com Mon Nov 23 14:22:44 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:22:44 -0800 Subject: Line Breaks In-Reply-To: References: Message-ID: <7a9c25c20911231122v4049d726gba8d51267998d1da@mail.gmail.com> On Mon, Nov 23, 2009 at 10:45 AM, Susan Day wrote: > Hi; > I have the following line of code I'm sending to postfix: > > msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' '), > msg) > > Unfortunately, it ignores the line breaks. I also tried %0A but that was > ignored also. Please advise. > Does it ignore ALL line breaks-- or just doubled ones like \n\n? E.g., blank lines? I *think* its probably the latter, and doing msg.replace('\n\n', '\n \n') will make it work. That'd end up with a single space on those blank lines. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Mon Nov 23 14:26:38 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 23 Nov 2009 11:26:38 -0800 Subject: Line Breaks In-Reply-To: References: Message-ID: <4B0AE1EE.5070705@islandtraining.com> Susan Day wrote: > Hi; > I have the following line of code I'm sending to postfix: > > msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' > '), msg) > > Unfortunately, it ignores the line breaks. I also tried %0A but that > was ignored also. Please advise. > TIA, > Suzie That line does not ignore line breaks. Proof: >>> print 'A Message From %s:\n\n %s' % ('someone','some message') A Message From someone: some message So... *Exactly* what are you doing with msg, and *exactly* what is your evidence that line breaks are being ignored. With that information, perhaps we can identify and solve the real problem you're having. Gary Herron From apt.shansen at gmail.com Mon Nov 23 14:33:37 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:33:37 -0800 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <7a9c25c20911231133x1be0359t84d8109efcacb9b8@mail.gmail.com> On Mon, Nov 23, 2009 at 10:26 AM, j wrote: > What I am not totally sure about is when the store function callsthe > lookup function and does "return data[label].get(name)", that line > "trips" me up some....then the lookup function returns that back to > the store function, assigns the data to the variable 'people', THEN > does this, which also isn't that clear to me what it's all doing: > > It does it right when it hits it in the code; basically, the for loop runs over the list of items from the zip. In each one, it calls the lookup function. Execution then jumps over to lookup. Once the lookup function is done ('returns' or hits its it), execution jumps right back with a result, and that result is stored int he 'people' variable. Then the next item in the for loop is processed; again, when the function() is called, execution jumps over to that again, and so on. Only when all the things are done in the for loop, does execution move on to... > if people: > people.append(full_name) > else: > data[label][name] = [full_name] > > Basically, "lookup" will return one of two things. If someone with the given part of a name already has been stored, it'll return a list containing the people with that name. Otherwise, it will return None. The if/else above will operate on those two conditions: if 'lookup' returned a list of people, its going to add this person to that list. If it doesn't return a list of people, it's going to add this persons name to the data dictionary as a new list. So anyone in the future who has that name will find them on lookup. The thing is, I think lines 105-108 should be indented deeper one level to be 'inside' the for loop; and thus called with each execution, and not only after the for is all done with. As it is, it seems like a bug. Or I don't get at all what the point of the code is :) > My main problem is finding out what's it's actually *doing*? I know > and understand the terminologies (what 'append' does, what a > 'sequence' is, a 'list', a 'tuple', 'if'...'else'...etc...et....) > I concur with the other people who say this is bad code to learn from; the book could be a LOT clearer. I'd try another resource.. the online Python tutorial is a good place to start. A different book may be in order :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Nov 23 14:40:52 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:40:52 -0800 Subject: Beginning Question about Python functions, parameters... In-Reply-To: References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: <7a9c25c20911231140y8a9394cp95d04f52dcd53a1f@mail.gmail.com> On Mon, Nov 23, 2009 at 11:14 AM, astral orange <457r0.jp at gmail.com> wrote: > But back to the example, on line 104 I see there's a call to the > lookup function, passing 3 > parameters ('data', which I think is a nested dictionary, label > (first, middle, last) and name). > > But I am getting lost on line 111 after the parameters are passed in > to the lookup function. I'm > not exactly sure what it's returning The 'get' method of dictionaries returns either the value if it exists, or None. So lookup is returning either a the value from that nested dictionary (the value which will be a list of names), or None. > and when it does return, is this > assigned the the variable > 'people'? Yes. > And if so, I'm not sure what 'append(full_name)' does here. > The else statement which assigns > '[full_name]' to 'data[label][name]' is somewhat confusing as I'm > saying to myself where the heck did > '[full_name]' come "into the picture". > > Look up at line 97. The "purpose" of this code seems-- on a cursory glance-- to be to categorize peoples names into lists where their names are common. The data dictionary contains three dictionaries; one for first names, one for middle names, one for last names. Each dictionary would, over time, contain the name-part as a key and then a list of full names... So, I'd be: data['first']['Stephen'] = ['Stephen Hansen'] data['last']['Hansen'] = ['Stephen Hansen'] Then if Bob Hansen was run through the code, it'd end up as: data['last']['Hansen'] = ['Stephen Hansen', 'Bob Hansen'] At least I think that's what the code is doing. Based upon just a stare. :) (And if that's what its doing, I think it has a bug as I mentioned in a previous email; I think lines 105-108 need to be indented one level more) So, what all this code is doing is breaking apart someoen's full_name which was passed into the function originally, and seeing where to put it. That's what the for loop and lookup function calls are doing... seeing if we need a new list , or if there's an existing one to add the name to... When it decides where it goes, it puts the full_name in. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From suzieprogrammer at gmail.com Mon Nov 23 14:46:23 2009 From: suzieprogrammer at gmail.com (Susan Day) Date: Mon, 23 Nov 2009 14:46:23 -0500 Subject: Line Breaks In-Reply-To: <4B0AE1EE.5070705@islandtraining.com> References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron wrote: > >>> print 'A Message From %s:\n\n %s' % ('someone','some message') > A Message From someone: > > some message > > > So... *Exactly* what are you doing with msg, and *exactly* what is your > evidence that line breaks are being ignored. With that information, perhaps > we can identify and solve the real problem you're having. > First, it does in fact ignore all line breaks, not just double line breaks. Here's what I'm doing: session.sendmail(clientEmail, ourEmail2, header+msg) The email sent out has the message sans breaks. TIA, Suzie -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Nov 23 14:49:49 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 23 Nov 2009 19:49:49 +0000 Subject: Minimally intrusive XML editing using Python References: Message-ID: On Mon, 23 Nov 2009 17:45:24 +0100, Thomas Lotze wrote: >> What's your real problem, or use case? Are you just concerned with >> diffing, or are others likely to read the xml, and want it formatted the >> way it already is? > > I'd like to put the XML under revision control along with other stuff. > Other people should be able to make sense of the diffs and I'd rather not > require them to configure their tools to use some XML differ. In which case, the data format isn't "XML", but a subset of it (and probably an under-defined subset at that, unless you invest a lot of effort in defining it). That defeats one of the advantages of using a standardised "container" format such as XML, i.e. being able to take advantage of existing tools and libraries (which will be written to the offical standard, not to your private "standard"). One option is to require the files to be in a canonical form. Depending upon your revision control system, you may be able to configure it to either check that updated files are in this form, or even to convert them automatically. If your existing files aren't in such a form, there will be a one-time penalty (i.e. a huge diff) when converting the files. From tjreedy at udel.edu Mon Nov 23 14:56:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 14:56:05 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: Victor Subervi wrote: > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. [snip hmtl error report] Please post plain text - ascii or utf8. On my newsreader, what you posted, with a mismash of colors, bold, italic, and sizes, is not readable. From mal at egenix.com Mon Nov 23 14:59:43 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 23 Nov 2009 20:59:43 +0100 Subject: python and netezza In-Reply-To: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> References: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> Message-ID: <4B0AE9AF.3040606@egenix.com> Shan wrote: > Is there any module in python to connect with netezza database?(like > cx_Oracle which is used to connect Oracle from python) You can use our mxODBC database adapters together with the Netezza ODBC drivers. For single-tier setups (client application and database on the same server or the same platform, e.g. both Windows): http://www.egenix.com/products/python/mxODBC/ For multiple-tier setups (client application on a different server or different platform, e.g. Linux and Windows): http://www.egenix.com/products/python/mxODBCConnect/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 23 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 python at mrabarnett.plus.com Mon Nov 23 15:17:19 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Nov 2009 20:17:19 +0000 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <7n0578F3j7qa6U1@mid.individual.net> References: <7n0578F3j7qa6U1@mid.individual.net> Message-ID: <4B0AEDCF.4060300@mrabarnett.plus.com> Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generally avoided it, so I just nodded. > > Unfortunately, the new "nested" with statement (which I also read > about today) forces me into this anti-idiom. When replacing an > appearance of contextlib.nested with the 3K with statement, I > ended up with an unexpected syntax error. > > with (open(roster_path, 'r') as roster_file, > open(disb_path, 'w') as out_file, > open(report_path, 'w') as report_file): > > The result was: > > File "C:\project\codxml.py", line 184 > with (open(roster_path, 'r') as roster_file, > ^ > SyntaxError: invalid syntax > > Unless I'm missing something, I have to subject my code to a bit > of contintuation: > > with open(roster_path, 'r') as roster_file,\ > open(disb_path, 'w') as out_file,\ > open(report_path, 'w') as report_file: > > I was thinking about submitting a enhancement request to the > HOWTO, explaining that continuation my be required in this > context. Am I missing anything obvious? > The relevant syntax is: with_stmt ::= "with" with_item ("," with_item)* ":" suite with_item ::= expression ["as" target] Parentheses only work around an expression or when they are expected by the syntax, eg in function calls. In this case it sees the '(' and thinks that it's the start of a parenthesised expression. It parses the expression, then sees 'as', hence a SyntaxError. I suppose it could've complained about a missing ')' instead. I wonder whether an end-of-line could be ignored after a comma in a 'with' statement, and, for consistency, in any similar cases. From carsten.haese at gmail.com Mon Nov 23 15:18:05 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 15:18:05 -0500 Subject: Don't Understand Error In-Reply-To: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> References: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Message-ID: Victor Subervi wrote: > [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end > of script headers: mailSpreadsheet.py, referer: > http://globalsolutionsgroup.vi/display_spreadsheet.py > > Why? A CGI script is expected to produce output. Your script doesn't produce any output, and Apache is complaining about that. -- Carsten Haese http://informixdb.sourceforge.net From tjreedy at udel.edu Mon Nov 23 15:18:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:18:56 -0500 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Robert Kern wrote: > On 2009-11-23 04:47 AM, Antoine Pitrou wrote: >> Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit : >>> >>> I think there is an overall design sensibility, it's just not a >>> human-facing one. They claim that they designed the syntax to be very >>> easily parsed by very simple tools in order to make things like syntax >>> highlighters very easy and robust. So indentation-based blocks are right >>> out. >> >> But computer languages should be designed to be readable by humans. >> It's not like you need to write a new parser once a year, but you have to >> read code everyday. > > You will get no argument from me. My point was only that they had an > overall design sensibility, I think you characterized it fairly, even if it is not one many of us here want to work within. Of course, one way they could show the benefit of Go would be to rewrite CPython in Go and have it be faster, at least for appropriate programs on multicore machines. Or write a Python compiler. Either way, include a foreign function interface that could connect to existing C extensions. Google and the rest of the world certainly have lots of code to test such. From timprepscius at gmail.com Mon Nov 23 15:22:02 2009 From: timprepscius at gmail.com (timprepscius) Date: Mon, 23 Nov 2009 12:22:02 -0800 (PST) Subject: sandbox python via module loader Message-ID: <842a6cb7-b735-4362-829e-bcc09b813d06@m11g2000vbo.googlegroups.com> Greetings, in the past I wrote a sandboxing module loader for c++/ python. I am moving away from python.. I can't stand it actually. Call me blasphemous... I'm immune.. So this code is going to just find the trash.. Maybe it will be useful to someone else. Can't post it all, however, if you are trying to integrate python into a system in which you need to restrict access to "safe" modules (meaning, non-native code), and wish also to restrict a script's ability to access other scripts, may be useful to have a look at. Basically, it is modeled after java. Each instantiated script in your system will have a ModuleLoader. That module loader is in charge of enforcing restrictions. Sorry for not being able to post a full compilable segment. But this sure would have helped me to look at before I wrote it. -tim p.s. Man I hope this code is formatted okay after posting.. Will see I guess. Anyway. Cheers. -- .h /** * legal header - public domain * * ============================================================================ * * @author Timothy Prepscius */ #ifndef __SnowCrash_Script_Python_Internal_PScriptModuleLoader_h__ #define __SnowCrash_Script_Python_Internal_PScriptModuleLoader_h__ #include #include #include #include #include #include #define BOOST_PYTHON_STATIC_LIB #include namespace SnowCrash { namespace Script { namespace Python { namespace pInternal { class PModuleLoader { protected: static boost::python::object mainDictionary; static bool importLock; protected: typedef std::set ModuleSources; ModuleSources moduleSources; typedef std::map ModuleMap; typedef std::list ModuleList; ModuleMap moduleMap; // this is to ensure that modules are destroyed in reverse order of construction // because python doesn't seem to keep module references within modules ModuleList moduleList; PyObject *getCachedModule (const Utilities::URL &url); void setCachedModule (const Utilities::URL &url, PyObject *); PyObject *returningModule (PyObject *); PyObject *loadModule (Utilities::Transporter::BufferPtr buffer); Utilities::Transporter::BufferPtr loadCodeString (const Utilities::URL &url); PyObject *getModule(const Utilities::URL &name); PyObject *findModule(const std::wstring &name); typedef std::list ModuleURLList; ModuleURLList modulesLoading; public: PModuleLoader (); virtual ~PModuleLoader(); void addAvailableSource (const Utilities::URL &); PyObject *loadModule (const char *name); PyObject *loadModule (const Common::Script::Signature &); static PyObject *__import__ ( const char *name, PyObject *globals = NULL, PyObject *locals = NULL, PyObject *fromlist = NULL, PyObject *level = NULL ); static void setMainDictionary (boost::python::object); static void setImportLock (bool lock); } ; } // namespace pInternal } // namespace Python } // namespace Script } // namespace SnowCrash #endif -- .cpp /** * legal header - public domain * * ============================================================================ * * @author Timothy Prepscius */ #include "Utilities/BaseInclude/CppInclude.h" #include "PModuleLoader.h" #include #include "Global/Utilities.h" #include "Script/Instance.h" #include "../../Monitor.h" #include "../pScript/PScript.h" #include "../Exception.h" #include // for PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #include "marshal.h" //----------------------------------------------------------------------------- using namespace SnowCrash::Script::Python::pInternal; using namespace SnowCrash::Script::Python; using namespace SnowCrash::Script; using namespace boost::python; // ============================================================================= object PModuleLoader::mainDictionary; bool PModuleLoader::importLock = true; void PModuleLoader::setMainDictionary (object object) { PModuleLoader::mainDictionary = object; } PyObject *PModuleLoader::loadModule (Utilities::Transporter::BufferPtr buffer) { PyObject *m=NULL, *co=NULL, *v=NULL; try { // read the object // this failed once! must investigate co = PyMarshal_ReadObjectFromString (buffer->getData()+8, buffer- >getSize()-8); if (!co) throw Python::Exception (); m = PyModule_New("_private_"); if (!m) throw Python::Exception (); // get the dictionary and fill in the neccessary values.. arbitrary to us. // notice the incref on the dictionary, if it is not there garbage collections dies a // miserable death object dict = object(handle<>(incref(PyModule_GetDict(m)))); dict["__builtins__"] = mainDictionary["__builtins__"]; object fname = object(handle<>(((PyCodeObject *)co)->co_filename)); std::string s = extract(fname); dict["__file__"] = fname; // evaluate the code, I wonder what this returns. v = PyEval_EvalCode((PyCodeObject *)co, dict.ptr(), dict.ptr()); if (v) { decref (v); } else { throw Python::Exception(); } } catch (Python::Exception &e) { std::string pe = handleException (e); LogRelease (PModuleLoader::loadModule, "caught exception " << pe); } catch (...) { LogRelease (PModuleLoader::loadModule, "caught unknown exception."); } return m; } PyObject *PModuleLoader::returningModule (PyObject *module) { if (module) { moduleList.push_back (object(detail::borrowed_reference(module))); incref (module); return module; } Py_RETURN_NONE; } Utilities::Transporter::BufferPtr PModuleLoader::loadCodeString (const Utilities::URL &url) { std::wstring extension = L".pyc"; std::wstring urlString = url; if (urlString.find (extension) == -1) urlString += extension; Utilities::URL fileURL (urlString); Utilities::VFS::InFilePtr inFile = Utilities::VFS::SystemSingleton->getInFile ( Global::getVFSDataPath(fileURL) ); if (inFile) { int size = inFile->size(); char *buffer = new char[size]; inFile->read (buffer, size); return new Utilities::Transporter::AllocatorBuffer (buffer, size); } return NULL; } PModuleLoader::PModuleLoader () { } PModuleLoader::~PModuleLoader () { moduleMap.clear(); while (!moduleList.empty()) moduleList.pop_front(); } void PModuleLoader::addAvailableSource (const Utilities::URL &url) { moduleSources.insert (url); } PyObject *PModuleLoader::getCachedModule (const Utilities::URL &url) { std::wstring moduleName = url; // quick return if we have it ModuleMap::iterator i = moduleMap.find(moduleName); if (i != moduleMap.end()) return i->second; return NULL; } void PModuleLoader::setCachedModule (const Utilities::URL &url, PyObject *module) { std::wstring moduleName = url; moduleMap[moduleName] = module; } PyObject *PModuleLoader::getModule (const Utilities::URL &url) { // see if we have a cached module PyObject *module = getCachedModule (url); if (module) return module; // else try to load the codestring Utilities::Transporter::BufferPtr codeString = loadCodeString (url); if (codeString) { // try to load the module modulesLoading.push_front (url); module = loadModule (codeString); modulesLoading.pop_front (); } setCachedModule (url, module); return module; } PyObject *PModuleLoader::findModule (const std::wstring &name) { // first try to load the relative path from the module if (!modulesLoading.empty()) { const Utilities::URL &url = modulesLoading.front(); Utilities::URL urlWithName (url, name); PyObject *module = getModule (urlWithName); if (module) return module; } ModuleSources::iterator i; for (i=moduleSources.begin(); i!=moduleSources.end(); ++i) { const Utilities::URL &url = *i; Utilities::URL urlWithName = Utilities::URL::join(url, name); PyObject *module = getModule(urlWithName); if (module) return module; } return NULL; } PyObject *PModuleLoader::loadModule (const Common::Script::Signature &signature) { // path/file/class std::wstring invokation = signature.getInvokation(); // path/file std::wstring path = Utilities::File::getDirectory (invokation, false); // zipfile.zip/path/file Utilities::URL zipPath = Utilities::URL::join(signature.getURL (),path); return returningModule (getModule (zipPath)); } PyObject *PModuleLoader::loadModule (const char *name) { std::wstring path = Utilities::String::convert (name); std::replace (path.begin(), path.end(), L'.', L'/'); return returningModule(findModule (path)); } PyObject *PModuleLoader::__import__ ( const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, PyObject *level ) { LogDebug (Script::Python, "__import__ " << name); try { static char *allowedBuiltinModules[] = { "dD.*", "dD_*", NULL } ; bool allowed = !importLock; // check if it matches a given pattern int i; for (i=0; !allowed && allowedBuiltinModules[i]!=NULL; ++i) { char *check = allowedBuiltinModules[i]; int checkLength = strlen(check); // if there is a star at the end, match all thing that have the substring at the beginning if (check[checkLength-1] == '*') { if (strncmp (name, check, checkLength-1)==0) allowed = true; } else { if (strcmp (name, check)==0) allowed = true; } } // only import if it is one of ours, else, must be pure python code, // downloaded with the script if (allowed) { PyObject *module = PyImport_ImportModuleEx ((char *)name, globals, locals, fromlist); if (module) { incref (module); return module; } } } catch (Python::Exception &e) { handleException (e); } Script::Instance *script = Script::MonitorSingleton->getExecutingScript (); if (!script) Py_RETURN_NONE; Python::pScript::PScript *pscript = DynamicCastPtr(Python::pScript::PScript, script); return pscript->getModuleLoader()->loadModule (name); } void PModuleLoader::setImportLock (bool lock) { importLock = lock; } --- Also, for these things to be triggered, you need to override them in the main dictionary /** * legal header - public domain * * ============================================================================ * initials date comments * * @author Timothy Prepscius */ #include "Utilities/BaseInclude/CppInclude.h" #include "PPackage.h" #include "PAccessor.h" #include "PModuleLoader.h" #include "PRestricted.h" #include "PLog.h" #include "PSystem.h" #include "../Defines.h" using namespace SnowCrash::Script::Python::pInternal; using namespace boost::python; BOOST_PYTHON_MODULE(dD_internal) { class_("Log", init()) .def ("println", &PLog::println); class_("System", no_init) .def ("getClientTimeMS", &PSystem::getClientTimeMS) .staticmethod ("getClientTimeMS") .def ("getMetaverseTimeMS", &PSystem::getMetaverseTimeMS) .staticmethod ("getMetaverseTimeMS"); } BOOST_PYTHON_FUNCTION_OVERLOADS(import_overloads, PModuleLoader::__import__, 1, 5); BOOST_PYTHON_FUNCTION_OVERLOADS(compile_overloads, PRestricted::throwPermissionDeniedException, 3, 5); BOOST_PYTHON_FUNCTION_OVERLOADS(open_overloads, PRestricted::throwPermissionDeniedException, 1, 3); bool PPackage::registerNativeMethods () { if (! ( (PyImport_AppendInittab("dD_internal", initdD_internal) != -1) && PyImport_ImportModule ("dD_internal") )) return false; IMPLEMENT_PYTHON_CONVERTER (PAccessor); PModuleLoader::setImportLock (false); { object main = import("__main__"); object dict(main.attr("__dict__")); PModuleLoader::setMainDictionary (dict); object builtins (dict["__builtins__"]); scope within(builtins); def ("__import__", &PModuleLoader::__import__, import_overloads()); def ("compile", &PRestricted::throwPermissionDeniedException, compile_overloads()); def ("exit", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("execfile", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("file", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("open", &PRestricted::throwPermissionDeniedException, open_overloads()); } PModuleLoader::setImportLock (true); return true; } bool PPackage::deregisterNativeMethods () { return true; } From tjreedy at udel.edu Mon Nov 23 15:28:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:28:37 -0500 Subject: Python & OpenOffice Spreadsheets In-Reply-To: <1258975507.3770.10.camel@krishna-laptop> References: <87pr79cx5m.fsf@rudin.co.uk> <1258975507.3770.10.camel@krishna-laptop> Message-ID: Krishnakant wrote: > On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: >> Gerhard H?ring writes: >> >>> Is there a *simple* way to read OpenOffice spreadsheets? >>> >>> Bonus: write them, too? >>> >>> I mean something like: >>> >>> doc.cells[0][0] = "foo" >>> doc.save("xyz.ods") >>> >>> >From a quick look, pyodf offers little more than just using a XML parser >>> directly. >> >> Depends on exactly what you mean by "simple" - but pyuno allows you to >> read and write openoffice spreadsheets. > > > Odfpy is a good module and is easy too. Tarball at http://pypi.python.org/pypi/odfpy/ Hello world example at http://opendocumentfellowship.com/development/projects/odfpy From mail at anjanesh.net Mon Nov 23 15:30:19 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 24 Nov 2009 02:00:19 +0530 Subject: Waiting for receiving data Message-ID: <1a7951080911231230v2b76842fx7569c93f934125fd@mail.gmail.com> fp = urllib.urlopen(url) data = fp.read() Retrieving XML data via an XML service API. Very often network gets stuck in between. No errors / exceptions. CTRL+C File "get-xml.py", line 32, in fp = urllib.urlopen(url) File "/usr/lib/python2.6/urllib.py", line 87, in urlopen return opener.open(url) File "/usr/lib/python2.6/urllib.py", line 206, in open return getattr(self, name)(url) File "/usr/lib/python2.6/urllib.py", line 348, in open_http errcode, errmsg, headers = h.getreply() File "/usr/lib/python2.6/httplib.py", line 1048, in getreply response = self._conn.getresponse() File "/usr/lib/python2.6/httplib.py", line 974, in getresponse response.begin() File "/usr/lib/python2.6/httplib.py", line 391, in begin version, status, reason = self._read_status() File "/usr/lib/python2.6/httplib.py", line 349, in _read_status line = self.fp.readline() File "/usr/lib/python2.6/socket.py", line 397, in readline data = recv(1) KeyboardInterrupt Is there I can do to try something else if its taking too long to retrieve from the network ? Like kill previous attempt and retry ? Thanks Anjanesh Lekshmnarayanan From victorsubervi at gmail.com Mon Nov 23 15:33:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 15:33:43 -0500 Subject: Don't Understand Error In-Reply-To: References: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Message-ID: <4dc0cfea0911231233g48e32472t5762a603151bf316@mail.gmail.com> On Mon, Nov 23, 2009 at 3:18 PM, Carsten Haese wrote: > Victor Subervi wrote: > > [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end > > of script headers: mailSpreadsheet.py, referer: > > http://globalsolutionsgroup.vi/display_spreadsheet.py > > > > Why? > > A CGI script is expected to produce output. Your script doesn't produce > any output, and Apache is complaining about that. > Thank you. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 23 15:40:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:40:46 -0500 Subject: print function in python3.1 In-Reply-To: References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> <1a7951080911230755r12307fa5o2dbcf2ca8eb9fde6@mail.gmail.com> Message-ID: Dennis Lee Bieber wrote: > Does Python 3.x include SQLite? Of course ;-] >>> import sqlite3 >>> dir(sqlite3) ['Binary', 'Cache', 'Connection', 'Cursor', 'DataError', [snip] adapt', 'adapters', 'apilevel', 'complete_statement', 'connect', 'converters', 'datetime', 'dbapi2', 'enable_callback_tracebacks', 'enable_shared_cache', 'paramstyle', 'register_adapter', 'register_converter', 'sqlite_version', 'sqlite_version_info', 'threadsafety', 'time', 'version', 'version_info'] but is does not seem to have exposed escape_string function From solipsis at pitrou.net Mon Nov 23 15:47:37 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 23 Nov 2009 20:47:37 +0000 (UTC) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Le Mon, 23 Nov 2009 11:54:19 -0600, Robert Kern a ?crit?: > > Not really. The idea was to make the language easily parsed and lexed > and analyzed by *other* tools, not written in Go, that may have limited > capabilities. Well, if Go doesn't allow you to write libraries usable from other low- level languages I'm not sure it is a good systems programming language. One point of C is that you can bridge it with everything. > Vim isn't written in Go and won't be able to use their > API, for example. Syntax highlighting doesn't require a full-blown parser. You probably want to handle three types of events: - comments (and docstrings and the like for languages which have them) - keywords - delimiters of basic syntactical blocks (which most of the time is simply matching pairs of parens / square brackets / curly brackets) That is, you need a very small part of the information a complete parser would give you. In particular, you don't need to know about operator precedence. You don't need to know about what kind of block you are inside (function, method, class...). You don't need to know whether an identifier is a local variable, a global variable, a type, etc. You don't even need to know the different operators. You only need to recognize the basic lexemes and that's all. The reason the Go designers gave for the braindead syntax looks dramatically unserious and makes it look a bit like a joke. (actually, what really made me wonder whether Go was a joke was the "iota" keyword) From yota.news at gmail.com Mon Nov 23 15:49:44 2009 From: yota.news at gmail.com (yota.news at gmail.com) Date: Mon, 23 Nov 2009 12:49:44 -0800 (PST) Subject: dbapi2 select where IN (...) Message-ID: hello, I couldn't find how the dbapi2 planned to handle the sql IN statement. ex : SELECT * FROM table WHERE num IN (2,3,8,9); I'd be glad to take advantage of the ? mechanism, but what about tuples ! execute("""SELECT * FROM table WHERE num IN ?;""" , ((2,3,8,9),)) ...fail... what would be the most pythonic way to do this ? From joshua at joshuakugler.com Mon Nov 23 15:52:27 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Mon, 23 Nov 2009 11:52:27 -0900 Subject: IDE+hg References: Message-ID: NiklasRTZ wrote: > If you > know > a good light IDE with hg, please inform. Topic handled earlier, still > undecided > http://groups.google.com/group/google-appengine-python/browse_thread/... > Thanks in advance > Niklas Rosencrantz WingIDE support Hg, as well as svn, git, and many others. j From wolftracks at invalid.com Mon Nov 23 15:58:00 2009 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 23 Nov 2009 12:58:00 -0800 Subject: A More Concise Description of Numpy than the Guide to Numpy? In-Reply-To: References: Message-ID: Robert Kern wrote: > On 2009-11-23 11:49 AM, W. eWatson wrote: >> I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more >> concise and practical guide to its use in science and mathematics? > > You will want to ask numpy questions on the numpy mailing list: > > http://www.scipy.org/Mailing_Lists > > You may also find the NumPy User Guide more up your alley: > > http://docs.scipy.org/doc/numpy/user/ > Thanks. I think I'll join the list, and the last link looks like a good alley. From patrickstinson.lists at gmail.com Mon Nov 23 16:02:47 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Mon, 23 Nov 2009 14:02:47 -0700 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com> On Mon, Nov 23, 2009 at 1:01 AM, Carl Banks wrote: > On Nov 22, 10:58?pm, Patrick Stinson > wrote: >> On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: > icating) the multiprocessing module would be ideal. >> > The problem is that the OP has a embedded application running threads. >> > multiprocssing doesn't help there. >> >> that's right. I cannot make CPython calls from my original C-based threads. > > > It's quite possible to do that. ?A thread started from C can make > calls to Python if it first calls PyGILState_Ensure, although you'd > have to make sure that the Python interpreter has been previously > initialized. ?See PEP 311 for details. > > http://www.python.org/dev/peps/pep-0311/ > > I also suggest that if you want people to be more receptive to write > your replies after the quoted text. ?That is the custom in this > newsgroup/mailing list. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > thanks for the tip. What I meant was that I am *not allowed* to make calls to the CPython API from the threads I currently have because these threads are high priority and are never allowed to make blocking calls. Fortunately, each of these threads can have a completely separate interpreter, so my idea was to create a daemon process for each thread. This daemon would contain the libpython symbols and would make the CPython calls. This would keep my current threads from having to contend over the single GIL. My question was whether or not anyone has done anything like this in C/C++. This situation is slightly unique in that I am trying to maintain separate interpreters within a single app (which is currently kind of hacked out using a single interpreter, but it's ugly), but I could see how this sort of thing would be useful for other C/C++ apps that implement an embedded scripting engine. My reference to multiprocessing was based on the idea that the library hides the details fo the process management, shared memory, and rpc mechanisms. Again, I can't use multiprocessing because it runs *in* python I need this to be implemented *outside* of python to avoid acquiring the GIL. complex, I know. Naturally, the most intimidating part of perusing this kind of idea is the overhead of the processess management and the RPC. Further, libpython executes callable objects using C function pointers, and I can't think of a way that this would be able to re-gain access to the original app's respective functions if the interpreter was living in another processes. That's not to mention the impossibility of debugging. Damn you, Gil. From alfps at start.no Mon Nov 23 16:06:29 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 23 Nov 2009 22:06:29 +0100 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... Message-ID: This is the tragic story of this evening: 1. Aspirins to lessen the pain somewhat. 2. Over in [comp.programming] someone mentions paper on Quicksort. 3. I recall that X once sent me link to paper about how to foil Quicksort, written by was it Doug McIlroy, anyway some Bell Labs guy. Want to post that link in response to [comp.programming] article. 4. Checking in Thunderbird, no mails from X or about QS there. 5. But his mail address in address list so something funny going on! 6. Googling, yes, it seems Thunderbird has a habit of "forgetting" mails. But they're really there after all. It's just the index that's screwed up. 7. OK, opening Thunderbird mailbox file (it's just text) in nearest editor. 8. Machine hangs, Windows says it must increase virtual memory, blah blah. 9. Making little Python script to extract individual mails from file. 10. It says UnicodeDecodeError on mail nr. something something. 11. I switch mode to binary. Didn't know if that would work with std input. 12. It's now apparently ten times faster but *still* UnicodeDecodeError! 13. I ask here! Of course could have googled that paper, but at each step above it seemed just a half minute more to find the link in mails, and now I decided it must be found. And I'm hesitant to just delete index file, hoping that it'll rebuild. Thunderbird does funny things, so best would be if Python script worked. import os import fileinput def write( s ): print( s, end = "" ) msg_id = 0 f = open( "nul", "w" ) for line in fileinput.input( mode = "rb" ): if line.startswith( "From - " ): msg_id += 1; f.close() print( msg_id ) f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) else: f.write( line ) f.close() 955 956 957 958 Traceback (most recent call last): File "C:\test\tbfix\splitmails.py", line 11, in for line in fileinput.input( mode = "rb" ): File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, in __next__ line = self.readline() File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, in readline self._buffer = self._file.readlines(self._bufsize) File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 2188: character maps to Cheers, - Alf From deets at nospam.web.de Mon Nov 23 16:11:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 22:11:47 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <7n0c4jF3jsi7lU1@mid.uni-berlin.de> Patrick Stinson schrieb: > On Mon, Nov 23, 2009 at 1:01 AM, Carl Banks wrote: >> On Nov 22, 10:58 pm, Patrick Stinson >> wrote: >>> On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: >> icating) the multiprocessing module would be ideal. >>>> The problem is that the OP has a embedded application running threads. >>>> multiprocssing doesn't help there. >>> that's right. I cannot make CPython calls from my original C-based threads. >> >> It's quite possible to do that. A thread started from C can make >> calls to Python if it first calls PyGILState_Ensure, although you'd >> have to make sure that the Python interpreter has been previously >> initialized. See PEP 311 for details. >> >> http://www.python.org/dev/peps/pep-0311/ >> >> I also suggest that if you want people to be more receptive to write >> your replies after the quoted text. That is the custom in this >> newsgroup/mailing list. >> >> >> Carl Banks >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > thanks for the tip. > > What I meant was that I am *not allowed* to make calls to the CPython > API from the threads I currently have because these threads are high > priority and are never allowed to make blocking calls. Fortunately, > each of these threads can have a completely separate interpreter, so > my idea was to create a daemon process for each thread. This daemon > would contain the libpython symbols and would make the CPython calls. > This would keep my current threads from having to contend over the > single GIL. > > My question was whether or not anyone has done anything like this in > C/C++. This situation is slightly unique in that I am trying to > maintain separate interpreters within a single app (which is currently > kind of hacked out using a single interpreter, but it's ugly), but I > could see how this sort of thing would be useful for other C/C++ apps > that implement an embedded scripting engine. AFAIK, instantiating several interpreters is possible. There seem to be problems with extension modules, but maybe you don't need them, or can work around that problem. http://mail.python.org/pipermail/python-dev/2006-December/070370.html Diez From redplusbluemakespurple at gmail.com Mon Nov 23 16:15:07 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Mon, 23 Nov 2009 13:15:07 -0800 (PST) Subject: Converting a float to a formatted outside of print command Message-ID: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> I'd like to convert a list of floats to formatted strings. The following example raises a TypeError: y = 0.5 x = '.1f' % y From danb_83 at yahoo.com Mon Nov 23 16:17:42 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Mon, 23 Nov 2009 13:17:42 -0800 (PST) Subject: Converting a float to a formatted outside of print command References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: On Nov 23, 3:15?pm, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y You meant: x = '%.1f' % y From iurisilvio at gmail.com Mon Nov 23 16:24:18 2009 From: iurisilvio at gmail.com (Iuri) Date: Mon, 23 Nov 2009 19:24:18 -0200 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <789aac5a0911231324t4ee11387pc957232ec87ecf43@mail.gmail.com> You forgot a % simbol in your string: y = 0.5 x = '*%*.1f' % y []s iurisilvio On Mon, Nov 23, 2009 at 7:15 PM, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Nov 23 16:25:51 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 23 Nov 2009 16:25:51 -0500 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <5D06A473-6815-4653-9188-C1428762DCE1@semanchuk.com> On Nov 23, 2009, at 4:15 PM, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y You're missing a percent sign: x = '%.1f' % y or: print '%.1f' % 0.5 Hope this helps Philip From redplusbluemakespurple at gmail.com Mon Nov 23 16:27:45 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Mon, 23 Nov 2009 13:27:45 -0800 (PST) Subject: Converting a float to a formatted outside of print command References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <978da1a2-2e49-4e03-b7f4-f26f5fbc7f0b@p28g2000vbi.googlegroups.com> On Nov 23, 3:17?pm, Dan Bishop wrote: > You meant: > > x = '%.1f' % y Thanks, I'm a dufus today. From vlastimil.brom at gmail.com Mon Nov 23 16:28:53 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 23 Nov 2009 22:28:53 +0100 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <9fdb569a0911231328h4e896b69g2bc34c3eaec63f57@mail.gmail.com> 2009/11/23 stephen_b : > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y > -- > http://mail.python.org/mailman/listinfo/python-list Maybe '%.1f' % y ? hth vbr From robert.kern at gmail.com Mon Nov 23 16:30:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 15:30:16 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On 2009-11-23 14:47 PM, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 11:54:19 -0600, Robert Kern a ?crit : >> >> Not really. The idea was to make the language easily parsed and lexed >> and analyzed by *other* tools, not written in Go, that may have limited >> capabilities. > > Well, if Go doesn't allow you to write libraries usable from other low- > level languages I'm not sure it is a good systems programming language. > One point of C is that you can bridge it with everything. That doesn't help tools that are already built with their own capabilities. I don't link Python into my editor to get Python syntax highlighting. The easier it is to write *a* parser/analyzer for the language in any other programming language, the more tools you will get for a broader range of runtime environments, particularly constrained environments like editors that may not be extensible at all. >> Vim isn't written in Go and won't be able to use their >> API, for example. > > Syntax highlighting doesn't require a full-blown parser. Most of the time. FORTRAN does require a full-blown parser if you want to be accurate. And the more regular a language is, the more interesting things one can do with just the tools that are usually available for syntax highlighting. FORTRAN and Go represent two opposite sides of that spectrum. > You probably > want to handle three types of events: > - comments (and docstrings and the like for languages which have them) > - keywords > - delimiters of basic syntactical blocks (which most of the time is > simply matching pairs of parens / square brackets / curly brackets) > > That is, you need a very small part of the information a complete parser > would give you. > In particular, you don't need to know about operator precedence. You > don't need to know about what kind of block you are inside (function, > method, class...). You don't need to know whether an identifier is a > local variable, a global variable, a type, etc. You don't even need to > know the different operators. You only need to recognize the basic > lexemes and that's all. You can get away with just that and have something people recognize as syntax highlighting, yes. But if it is possible to highlight local variables, globals, and types differently, that *is* useful. And you will even see some syntax highlighters doing more advanced things like that even for Python (though mostly with heuristics). But note that the more regular the language is, the less you need to rely on a full parser, and the more interesting things you can do with just lexing and other simpler approaches. That's what they are going for. If I were designing a language, that wouldn't be the tradeoff I would make, but they have their own needs. -- 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 darcy at druid.net Mon Nov 23 16:31:03 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 23 Nov 2009 16:31:03 -0500 Subject: Line Breaks In-Reply-To: References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: <20091123163103.b8d83c24.darcy@druid.net> On Mon, 23 Nov 2009 14:46:23 -0500 Susan Day wrote: > First, it does in fact ignore all line breaks, not just double line breaks. > Here's what I'm doing: > session.sendmail(clientEmail, ourEmail2, header+msg) > The email sent out has the message sans breaks. You should really post an entire script that runs and shows the error so that we can run it (changing the email address of course) to see what it does. -- 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 tjreedy at udel.edu Mon Nov 23 16:35:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 16:35:43 -0500 Subject: Beginning Question about Python functions, parameters... In-Reply-To: References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: astral orange wrote: > Yes, lines 104-111 is really where my problem lies in understanding > what is going on here. > I am beginner so this stuff seems a little unwieldy at the moment. :) > I *did* invest $40 Water under the bridge. Focus on the future... > into this book so it' what I have to work with. By the way, the book > is, "Apress Beginning Python 2nd Edition".... The online tutorial is free. Read it along with the book. Two explanations of a particular point are often better than one, at least for me. Now, to where you seem to be stuck. Data is a dict of 3 dicts, one for each part of a full [Western] name. Each subdict maps pieces of fullnames to a list of fullnames that contain that piece in the appropriate position. This is something like a database of names with 3 fields and an index for each field pointing to records in the database, except that there is no database. This is why the structure strikes people as a bit strange. The records are still there, off in anonymous dataspace, but there is no way to access them except via the indexes. If init started with data['names'] = [] # empty list, not dict and the third line of store were data['names'].append(names) then there would be. You might try that as an exercise once you understand what is already there. Anyway, you should "print MyNames" (2.x) or "print(MyNames)" (3.x) after storing the first name so you can see the structure of MyNames. The tutorial, of course, tells you this. DO read it. Then add more data and print again to see what changes. For instance, store(MyNames, 'Susan Smith') print(MyNames) Then try several lookups. store() checks each of the pieces of a name to see whether or not it is already in the corresponding key dict. This is the "people =" line. The important point in lookup is that when dict d does not contain key k, d.get(k) returns None while the usual d[k]raises a KeyError. So lookup() always return something, even if just None. So 'people' is either None or an exiting list of names. In the latter case, the current full names is added to the list. In the former case, the name-piece is associated with a new list with one item. If this is still not clear, add print statements or print function statements at appropriate places inside the code for the store function. This is how many people clarify thier understanding of a function, including when debugging. Good luck. Terry Jan Reedy From marcmagransdeabril at gmail.com Mon Nov 23 16:42:09 2009 From: marcmagransdeabril at gmail.com (marc magrans de abril) Date: Mon, 23 Nov 2009 13:42:09 -0800 (PST) Subject: profiling differences using an extra function call Message-ID: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> Hi, I was a trying to profile a small script and after shrinking the code to the minimum I got a interesting profile difference. Given two test functions test1 and test2, that only differs from an extra level of indirection (i.e. find_substr), I wonder why I got a timming difference >50%? What is the recommended way to factorize the code? Should I write a big method containing everything? #!/usr/bin/python def find_substr(l): return l[15:20] def test1(t): for i in xrange(1000000): s = find_substr(t) def test2(t): for i in xrange(1000000): sub = t[15:20] import cProfile t = "This a long string containing several things apart from the end" cProfile.run("test1(t)") cProfile.run("test2(t)") ----Profiles test1 Profiles results: 1000003 function calls in 0.666 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno (function) 1 0.000 0.000 0.666 0.666 :1() 1000000 0.260 0.000 0.260 0.000 test.py:3(find_substr) 1 0.406 0.406 0.666 0.666 test.py:7(test1) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} ----Profile test2: 3 function calls in 0.248 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno (function) 1 0.000 0.000 0.248 0.248 :1() 1 0.248 0.248 0.248 0.248 test.py:12(test2) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} Thank you very much for the advice! marc From james.b.looney at ulalaunch.com Mon Nov 23 16:53:45 2009 From: james.b.looney at ulalaunch.com (James Looney) Date: Mon, 23 Nov 2009 13:53:45 -0800 (PST) Subject: Compiling Python 2.6.4 on IRIX 6.5 - "don't know how to make Parser/printgrammar.o (bu42)." Message-ID: I'm trying to compile Python 2.6.4 on my IRIX 6.5 machine. I have no idea how to fix this problem, and am hoping someone may know what to do. The closest thread I've found to this is http://bugs.python.org/issue4279, but that patch has already been added, yet I still get the error. The post makes reference to trying gmake, but I don't have that installed on this machine. I'm stuck with regular make. configure line: ../../configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/IRIX6 --enable-shared --with- threads --without-gcc --with-cxx-main=/usr/bin/CC make history: [14:50:54]> make /usr/bin/CC -c -OPT:Olimit=0 -DNDEBUG -O -I. -IInclude - I../../Include -DPy_BUILD_CORE -o Modules/python.o ../../Modules/ python.c don't know how to make Parser/printgrammar.o (bu42). From james.b.looney at ulalaunch.com Mon Nov 23 16:55:03 2009 From: james.b.looney at ulalaunch.com (James Looney) Date: Mon, 23 Nov 2009 13:55:03 -0800 (PST) Subject: Compiling Python 2.6.4 on IRIX 6.5 - "don't know how to make Parser/printgrammar.o (bu42)." Message-ID: <87f4f043-2f8b-4268-9cb4-edb10b08f150@x16g2000vbk.googlegroups.com> I'm trying to compile Python 2.6.4 on my IRIX 6.5 machine. I have no idea how to fix this problem, and am hoping someone may know what to do. The closest thread I've found to this is http://bugs.python.org/issue4279, but that patch has already been added, yet I still get the error. The post makes reference to trying gmake, but I don't have that installed on this machine. I'm stuck with regular make. configure line: ../../configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/IRIX6 --enable-shared --with- threads --without-gcc --with-cxx-main=/usr/bin/CC make history: [14:50:54]> make /usr/bin/CC -c -OPT:Olimit=0 -DNDEBUG -O -I. -IInclude - I../../Include -DPy_BUILD_CORE -o Modules/python.o ../../Modules/ python.c don't know how to make Parser/printgrammar.o (bu42). From andyjian430074 at gmail.com Mon Nov 23 16:57:23 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 13:57:23 -0800 (PST) Subject: sys.stdout is not flushed Message-ID: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> I am trying to use sys.stdout to print out "process-bar" like: -->1% Here is my program ?test.py?: from sys import stdout for v in range(10): stdout.write('-->%d' % v) stdout.flush() else: stdout.write('done!') #end for Then, I use 'python -u test.py' to run this script. But what I get is : -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! I am suppose to get 'done!'. Can anybody help me about this? Thanks. Jankins From jaraco at jaraco.com Mon Nov 23 16:59:33 2009 From: jaraco at jaraco.com (Jason R. Coombs) Date: Mon, 23 Nov 2009 13:59:33 -0800 (PST) Subject: Relative versus absolute paths on Windows References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> On Nov 20, 3:52?pm, Ethan Furman wrote: > It is often said on this list that 'Python is not Java'. ?It is also > true that 'Windows is not Unix'. > > Unlike the *nix world where there is a *single* root, and everything > else is relative to that, in the Windows world there are several roots > -- every drive has one! I acknowledge that the Windows paradigm is messy and less elegant than Unix. I'm not trying to place blame here. I pointed out that even the Windows interfaces don't seem to provide the functions needed to do what I want to do. However, my point is that there is a need for path resolution that respects a rooted path as relative to another path. > So \bar is both an absolute path on whichever drive is active (or > specified), as well as relative if you happen to have more than one > drive, but it will not ever be relative on any specific drive. ?If you > want 'bar' to be relative to the current directory, do not specify a > leading '\'. Precisely. And my point is that if the path "specified" has a drive (d: \foo) and one wants "\bar" relative to d:\foo, the result should be d: \bar, not \bar, which is relative to the current drive. I elaborate below. > > Ultimately, I don't care what the definition is. It seems to me, > > however, that Python should have a function that can resolve one path > > name relative to another, but due to these limitations, it does not. I > > should point out that os.path.relpath is not the solution either as > > the first parameter is always treated as relative to the current > > directory (more info athttp://bugs.python.org/issue7195). > > Please note that there *is not* a relative path that can take you from > c:\foo to d:\bar ?(see the point about multiple roots above). I'm not looking for a relative path from c:\foo to d:\bar. I know the "shortest relative path" from c:\foo to d:\bar is the absolute path d: \bar. What I am looking for is a way to resolve one path relative to another irrespective of the current directory. Here's the use case: A symlink or shortcut (they can both be treated for symbolic links for the sake of this discussion) is defined in a particular location, let's say d:\foo. This symlink points to "\bar". On Windows, the target of the symlink is treated as relative to the location of the symlink itself, not the current directory when accessed. In other words, \bar relative to d:\foo always resolves to d: \bar. To effectively track down the target of a symbolic link, it becomes necessary to perform this resolution. > > What is the benefit of treating \path as absolute? > > That was not Python's decision, but Windows'. Maybe so. My feeling is there's a good reason for it, based on the multiple implementations that follow the same approach. Nevertheless, that doesn't change the fact that despite the APIs, Windows does internally resolve symlinks relative to the symlink location. > > Should Python have built-in support for resolving one path relative to > > another (such as is jaraco.windows.filesystem.resolve_path does)? > > As I noted above, you are not returning a relative path when the paths > cross drive letter boundaries, or one of the paths specified is a > drive-absolute path (such as '\bar'). To be clear, I'm not trying to find a relative path between two paths. I'm trying to resolve one path relative to another. On Unix, os.path.join does this. On Windows, there is no such function (except jaraco.windows.filesystem.join). > Hope this helps. Thanks for taking the time to write a detailed response. I think I understand the problem. What is frustrating is that the current behavior seems buggy (others words, not mine) and a function that does what many would expect isn't available. > P.S. > And now that I look up the comments in the bug-tracker, I see this was > all already pointed out to you. Based on the name and specification, I expected something different from relpath, but after the discussion, I decided it wasn't the tool I was seeking. From deets at nospam.web.de Mon Nov 23 17:04:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 23:04:06 +0100 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine In-Reply-To: <4b0ad983$0$13161$a729d347@news.telepac.pt> References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> <4b0ad983$0$13161$a729d347@news.telepac.pt> Message-ID: <7n0f6qF3hgohqU1@mid.uni-berlin.de> S?rgio Monteiro Basto schrieb: > Diez B. Roggisch wrote: > > Hi, Thanks, >> S?rgio Monteiro Basto wrote: >> >>> Hi, >>> I am in x86_64 arch , but I need >>> compile things on 32 bits with >>> python setup.py build >>> >>> Can't change the fact that distutils creates x86_64 >>> directories: >>> build/temp.linux-x86_64-2.3/ >>> >>> Also if I try with a python compile in 32bits and installed >>> in system . >> I doubt that. Distutils will always build based on the architecture of the >> interpreter you used when building an external module. >> >> Are you sure that the python you used to build the extension was the right >> one? What does >> >> -c "from distutils.util import get_platform; print >> get_platform()" > python32 -c "from distutils.util import get_platform; print get_platform()" > linux-x86_64 > > ldd ~/bin/python32 > linux-gate.so.1 => (0xffffe000) > libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) > libdl.so.2 => /lib/libdl.so.2 (0x0033f000) > libutil.so.1 => /lib/libutil.so.1 (0x006b3000) > libm.so.6 => /lib/libm.so.6 (0x00345000) > libc.so.6 => /lib/libc.so.6 (0x001e0000) > /lib/ld-linux.so.2 (0x001c2000) > > this a python 2.3, that's make any difference ? Ok, next try: import distutils print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') What does that yield? Diez Diez From martin at v.loewis.de Mon Nov 23 17:07:28 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 23 Nov 2009 23:07:28 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <4b0b07a1$0$22159$9b622d9e@news.freenet.de> > What I meant was that I am *not allowed* to make calls to the CPython > API from the threads I currently have because these threads are high > priority and are never allowed to make blocking calls. Fortunately, > each of these threads can have a completely separate interpreter, so > my idea was to create a daemon process for each thread. This daemon > would contain the libpython symbols and would make the CPython calls. > This would keep my current threads from having to contend over the > single GIL. If this ("never allowed to make blocking calls") is a strict requirement, then this is no solution, either. Communicating to the remote process would involve IO, and all IO operations may block. Of course, you might use non-blocking IO, in which case I wonder how the thread continues if it finds that the IO is blocking. I also wonder how the thread will find out that the result of the computation is available, when it is not allowed to wait for the result. In any case, I don't think you'll need a multi-process solution; a single-process multi-threading approach will do fine. Just create *another* thread, that runs at a low priority and is allowed to block. Run the Python interpreter in that thread (create multiple of these if you need them). Then, use some queuing producer-consumer communication between the high-priority thread and the low priority thread. Have the high priority threads put requests into the queue, and the low priority thread take them from the queue, dispatching them to Python. Make sure you use non-blocking synchronization on the queue, or else priority inheritance if you can get permission to do so. > Damn you, Gil. It may sound to you like the GIL is responsible for that. However, consider a world where the GIL was removed in Python. There would *still* be synchronization for data structures be going on. As you are not allowed to have any blocking operation in the high-priority threads, you *still* couldn't directly call the Python interpreter (or any other thread-safe library) from your high-priority threads. Regards, Martin From deets at nospam.web.de Mon Nov 23 17:08:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 23:08:25 +0100 Subject: sys.stdout is not flushed In-Reply-To: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> Message-ID: <7n0fepF3hgohqU2@mid.uni-berlin.de> Jankins schrieb: > I am trying to use sys.stdout to print out "process-bar" like: > -->1% > > Here is my program ?test.py?: > > from sys import stdout > for v in range(10): > stdout.write('-->%d' % v) > stdout.flush() > else: > stdout.write('done!') > #end for > > Then, I use 'python -u test.py' to run this script. But what I get > is : > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > I am suppose to get 'done!'. > > Can anybody help me about this? You misunderstand what "flush" means. It is not about clearing the screen, or the line. Try printing stdout.write('\r-->%d') Diez From alfps at start.no Mon Nov 23 17:37:58 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 23 Nov 2009 23:37:58 +0100 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... In-Reply-To: References: Message-ID: * Alf P. Steinbach: > > > import os > import fileinput > > def write( s ): print( s, end = "" ) > > msg_id = 0 > f = open( "nul", "w" ) > for line in fileinput.input( mode = "rb" ): > if line.startswith( "From - " ): > msg_id += 1; > f.close() > print( msg_id ) > f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) > else: > f.write( line ) > f.close() > > > > > 955 > 956 > 957 > 958 > Traceback (most recent call last): > File "C:\test\tbfix\splitmails.py", line 11, in > for line in fileinput.input( mode = "rb" ): > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, > in __next__ > line = self.readline() > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, > in readline > self._buffer = self._file.readlines(self._bufsize) > File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line > 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position > 2188: character maps to The following worked: import sys import fileinput def write( s ): print( s, end = "" ) msg_id = 0 f = open( "nul", "w" ) input = sys.stdin.detach() # binary while True: line = input.readline() if len( line ) == 0: break elif line.decode( "ascii", "ignore" ).startswith( "From - " ): msg_id += 1; f.close() print( msg_id ) f = open( "msg_{0:0>6}.txt".format( msg_id ), "wb+" ) else: f.write( line ) f.close() Cheers, - Alf From andyjian430074 at gmail.com Mon Nov 23 17:59:39 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 14:59:39 -0800 (PST) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> Message-ID: <24aa394f-62da-4f3a-bb3b-d646d9df48e7@e31g2000vbm.googlegroups.com> On Nov 23, 4:08?pm, "Diez B. Roggisch" wrote: > Jankins schrieb: > > > > > > > I am trying to use sys.stdout to print out "process-bar" like: > > -->1% > > > Here is my program ?test.py?: > > > from sys import stdout > > for v in range(10): > > ? ? stdout.write('-->%d' % v) > > ? ? stdout.flush() > > else: > > ? ? stdout.write('done!') > > #end for > > > Then, I use 'python -u test.py' to run this script. But what I get > > is : > > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > > I am suppose to get 'done!'. > > > Can anybody help me about this? > > You misunderstand what "flush" means. It is not about clearing the > screen, or the line. > > Try printing > > ? ?stdout.write('\r-->%d') > > Diez It works. I did misunderstood the meaning the 'flush'. Thanks so much. From 457r0.jp at gmail.com Mon Nov 23 18:13:28 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 15:13:28 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> On Nov 23, 4:35?pm, Terry Reedy wrote: > astral orange wrote: > > Yes, lines 104-111 is really where my problem lies in understanding > > what is going on here. > > I am beginner so this stuff seems a little unwieldy at the moment. :) > > I *did* invest $40 > > Water under the bridge. Focus on the future... > > > into this book so it' what I have to work with. By the way, the book > > is, "Apress Beginning Python 2nd Edition".... > > The online tutorial is free. Read it along with the book. Two > explanations of a particular point are often better than one, at least > for me. > > Now, to where you seem to be stuck. Data is a dict of 3 dicts, one for > each part of a full [Western] name. Each subdict maps pieces of > fullnames to a list of fullnames that contain that piece in the > appropriate position. > > This is something like a database of names with 3 fields and an index > for each field pointing to records in the database, except that there is > no database. This is why the structure strikes people as a bit strange. > The records are still there, off in anonymous dataspace, but there is no > way to access them except via the indexes. If init started with > ? ? ?data['names'] = [] # empty list, not dict > and the third line of store were > ? ? ?data['names'].append(names) > then there would be. You might try that as an exercise once you > understand what is already there. > > Anyway, you should "print MyNames" (2.x) or "print(MyNames)" (3.x) after > storing the first name so you can see the structure of MyNames. The > tutorial, of course, tells you this. DO read it. > > Then add more data and print again to see what changes. For instance, > > store(MyNames, 'Susan Smith') > print(MyNames) > > Then try several lookups. > > store() checks each of the pieces of a name to see whether or not it is > already in the corresponding key dict. This is the "people =" line. The > important point in lookup is that when dict d does not contain key k, > d.get(k) returns None while the usual d[k]raises a KeyError. So lookup() > always return something, even if just None. So 'people' is either None > or an exiting list of names. In the latter case, the current full names > is added to the list. In the former case, the name-piece is associated > with a new list with one item. > > If this is still not clear, add print statements or print function > statements at appropriate places inside the code for the store function. > This is how many people clarify thier understanding of a function, > including when debugging. > > Good luck. > > Terry Jan Reedy Wow! First, thanks Terry for the detailed explanation. I'll spend the rest of the night trying to figure all of this out. :) Also, thanks to everyone else that responded as well. I do appreciate you all volunteering your time to help. I should of came here sooner. As far as the program. I did add print statements such as print (MyNames) and got back: {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} 'Smith': ['John Larry Smith'] was in the last key so I will spend some time figuring out just why that is the case. I'll spend more time working with the functions and hopefully figure this out soon. Thanks again! Thanks again for the responses. I'll take all your advice. From ethan at stoneleaf.us Mon Nov 23 18:37:10 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 15:37:10 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> Message-ID: <4B0B1CA6.3010508@stoneleaf.us> Jason R. Coombs wrote: > On Nov 20, 3:52 pm, Ethan Furman wrote: > >>It is often said on this list that 'Python is not Java'. It is also >>true that 'Windows is not Unix'. >> >>Unlike the *nix world where there is a *single* root, and everything >>else is relative to that, in the Windows world there are several roots >>-- every drive has one! > > > I acknowledge that the Windows paradigm is messy and less elegant than > Unix. I'm not trying to place blame here. I pointed out that even the > Windows interfaces don't seem to provide the functions needed to do > what I want to do. However, my point is that there is a need for path > resolution that respects a rooted path as relative to another path. I think for this discussion you would be better off using the word 'combine' rather than 'relative'. >>So \bar is both an absolute path on whichever drive is active (or >>specified), as well as relative if you happen to have more than one >>drive, but it will not ever be relative on any specific drive. If you >>want 'bar' to be relative to the current directory, do not specify a >>leading '\'. > > > Precisely. And my point is that if the path "specified" has a drive (d: > \foo) and one wants "\bar" relative to d:\foo, the result should be d: > \bar, not \bar, which is relative to the current drive. s/relative/combined with/ > I elaborate below. > > >>>Ultimately, I don't care what the definition is. It seems to me, >>>however, that Python should have a function that can resolve one path >>>name relative to another, but due to these limitations, it does not. I >>>should point out that os.path.relpath is not the solution either as >>>the first parameter is always treated as relative to the current >>>directory (more info athttp://bugs.python.org/issue7195). >> >>Please note that there *is not* a relative path that can take you from >>c:\foo to d:\bar (see the point about multiple roots above). > > > I'm not looking for a relative path from c:\foo to d:\bar. I know the > "shortest relative path" from c:\foo to d:\bar is the absolute path d: > \bar. What I am looking for is a way to resolve one path relative to > another irrespective of the current directory. > > Here's the use case: A symlink or shortcut (they can both be treated > for symbolic links for the sake of this discussion) is defined in a > particular location, let's say d:\foo. This symlink points to "\bar". > > On Windows, the target of the symlink is treated as relative to the > location of the symlink itself, not the current directory when > accessed. In other words, \bar relative to d:\foo always resolves to d: > \bar. To effectively track down the target of a symbolic link, it > becomes necessary to perform this resolution. > > >>>What is the benefit of treating \path as absolute? >> >>That was not Python's decision, but Windows'. > > > Maybe so. My feeling is there's a good reason for it, based on the > multiple implementations that follow the same approach. Nevertheless, > that doesn't change the fact that despite the APIs, Windows does > internally resolve symlinks relative to the symlink location. The multiple implementations exist because that's the way is has always been on the Microsoft side. You have to play by their rules if you are going to use their OS. >>>Should Python have built-in support for resolving one path relative to >>>another (such as is jaraco.windows.filesystem.resolve_path does)? >> >>As I noted above, you are not returning a relative path when the paths >>cross drive letter boundaries, or one of the paths specified is a >>drive-absolute path (such as '\bar'). > > > To be clear, I'm not trying to find a relative path between two paths. > I'm trying to resolve one path relative to another. On Unix, > os.path.join does this. On Windows, there is no such function (except > jaraco.windows.filesystem.join). > > >>Hope this helps. > > > Thanks for taking the time to write a detailed response. I think I > understand the problem. What is frustrating is that the current > behavior seems buggy (others words, not mine) and a function that does > what many would expect isn't available. > > >>P.S. >>And now that I look up the comments in the bug-tracker, I see this was >>all already pointed out to you. > > > Based on the name and specification, I expected something different > from relpath, but after the discussion, I decided it wasn't the tool I > was seeking. relpath is definitely not the tool you are looking for. I do agree with you that a function to combine two paths would be very handy... of course, since relpath does work if the current drive is the one specified (I think, haven't tested that statement), a wrapper function that saved the current path, then switched drives, did the relpath lookup, then switched back... hmmmm -- that would be a pain if the drive didn't exist on the system doing the work... oh well. Yup, if your function works, keep it! :D ~Ethan~ From rhodri at wildebst.demon.co.uk Mon Nov 23 18:37:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 23 Nov 2009 23:37:18 -0000 Subject: IDE+hg In-Reply-To: References: Message-ID: On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ wrote: > Dear experts, > Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim > Mercurial support not found i.e. buttons to clone, commit and push to > repositories to define dev env dvcs, editor and deployment all in 1. I don't really understand this urge to cram everything into a single program, since that inevitably leads to compromises that will compromise just how much of Mercurial's useful and interesting functionality you can get at. Still, if you really must, Emacs (and presumably vim) seems to be capable of working with most source control systems. -- Rhodri James *-* Wildebeest Herder to the Masses From greg.ewing at canterbury.ac.nz Mon Nov 23 18:40:17 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 24 Nov 2009 12:40:17 +1300 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: <7n0krhF3k0kc4U1@mid.individual.net> Robert Kern wrote: > The easier it is to write *a* parser/analyzer for the > language in any other programming language, the more tools you will get > for a broader range of runtime environments, particularly constrained > environments like editors that may not be extensible at all. Seems to me that having a bit more punctuation in the language would make it easier for things like editors that don't have sophisticated parsing abilities to do a better job of syntax highlighting. -- Greg From tjreedy at udel.edu Mon Nov 23 18:40:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 18:40:33 -0500 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <7n0578F3j7qa6U1@mid.individual.net> References: <7n0578F3j7qa6U1@mid.individual.net> Message-ID: Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generally avoided it, so I just nodded. > > Unfortunately, the new "nested" with statement (which I also read > about today) forces me into this anti-idiom. When replacing an > appearance of contextlib.nested with the 3K with statement, I > ended up with an unexpected syntax error. > > with (open(roster_path, 'r') as roster_file, > open(disb_path, 'w') as out_file, > open(report_path, 'w') as report_file): > > The result was: > > File "C:\project\codxml.py", line 184 > with (open(roster_path, 'r') as roster_file, > ^ > SyntaxError: invalid syntax Right. The first open paren is illegal. > Unless I'm missing something, I have to subject my code to a bit > of contintuation: > > with open(roster_path, 'r') as roster_file,\ > open(disb_path, 'w') as out_file,\ > open(report_path, 'w') as report_file: with open(roster_path, 'r') as roster_file, open( disb_path, 'w') as out_file, open(report_path, 'w') as report_file: would work ;-) > I was thinking about submitting a enhancement request to the > HOWTO, explaining that continuation my be required in this > context. Am I missing anything obvious? I would suggest replacing "It is usually much better to use the implicit continuation inside parenthesis:", which says both too much and too little, with something like "When the desired linebreak is within an expression, it is usually much better to use implicit continuation inside parentheses, brackets, or braces. If necessary, the whole expression can be surrounded by a new pair of parentheses." I would not mention 'with' specifically since there are many other non-expression contexts where one cannot randomly add parentheses. I believe that '\ \n' would always be harmless or a SyntexError outside of expressons. I believe 'subtly wrong' only applies within expressions. So I would not call \ continuation an anti-pattern outside expressions. So you might suggest that the whole entry specify expression context to begin with. To me, your example shows why blanket condemnation is wrong. You might separately request that with-item sequences be optionally surrounded by parens, but I have a suspicion that this was considered and rejected on either technical grounds and/or the grounds that \ continuation was purposefully left in the language in 3.x to be used when implicit continuation is not appropriate, as in this situation. The HOWTOs are not scripture. Terry Jan Reedy From paul.w.miller.please.dont.spam.me at wmich.edu Mon Nov 23 19:05:33 2009 From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller) Date: Tue, 24 Nov 2009 00:05:33 +0000 (UTC) Subject: Any elegant way to construct the complete $k$-partite graph in Python? Message-ID: I was wondering if there were any neat tools (like for instance, something from itertools) that would help me write the following function more elegantly. The return value should, of course, be the complete $k$- partite graph $K_{n_1, n_2, \dots, n_k}$: def completeGraph (*ns): ''' Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed the sequence \code {n_1, n_2, \dots, n_k}. ''' if len (ns) == 1: return completeGraph ( * ([1] * ns[0]) ) n = sum (ns) vertices = range (n) partition_indices = [sum (ns[:i]) for i in range (len (ns))] partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] \ for i in range (len (partition_indices) - 1)] partite_sets.append (vertices[partition_indices [-1]:] ) edges = [] for i in range (len (partite_sets)): for j in range (i + 1, len (partite_sets)): edges.extend ([ (u, v) for u in partite_sets [i] for v in \ partite_sets [j] ]) return graph.Graph (vertices = vertices, edges = edges) Many thanks! From anand.ibmgsi at gmail.com Mon Nov 23 19:25:46 2009 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 24 Nov 2009 05:55:46 +0530 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: <1a3a139e0911231625m6defb19nbccd097c8dc98808@mail.gmail.com> I am not sure what you mean by complete $k$- partite graph.... There is the python-graph package(http://code.google.com/p/python-graph/) you might wanna check out. It does return a complete graph.. may be u can tweak it?? ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with no accounting policies. ~Aang Jie On Tue, Nov 24, 2009 at 05:35, Paul Miller < paul.w.miller.please.dont.spam.me at wmich.edu> wrote: > I was wondering if there were any neat tools (like for instance, > something from itertools) that would help me write the following function > more elegantly. The return value should, of course, be the complete $k$- > partite graph $K_{n_1, n_2, \dots, n_k}$: > > def completeGraph (*ns): > ''' > Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > the sequence \code {n_1, n_2, \dots, n_k}. > ''' > if len (ns) == 1: > return completeGraph ( * ([1] * ns[0]) ) > n = sum (ns) > vertices = range (n) > partition_indices = [sum (ns[:i]) for i in range (len (ns))] > partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > \ > for i in range (len (partition_indices) - 1)] > partite_sets.append (vertices[partition_indices [-1]:] ) > > edges = [] > for i in range (len (partite_sets)): > for j in range (i + 1, len (partite_sets)): > edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > partite_sets [j] ]) > > return graph.Graph (vertices = vertices, edges = edges) > > Many thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 23 19:48:48 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 16:48:48 -0800 (PST) Subject: Python & OpenOffice Spreadsheets References: Message-ID: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> On Nov 23, 4:49?am, Gerhard H?ring wrote: > Is there a *simple* way to read OpenOffice spreadsheets? > > Bonus: write them, too? > > I mean something like: > > doc.cells[0][0] = "foo" > doc.save("xyz.ods") > > >From a quick look, pyodf offers little more than just using a XML parser I find the syntax far to complicated than it should be. Here is an example just to insert some text.. import uno """ Here is the sequence of things the lines do: 1. Get the uno component context from the PyUNO runtime 2. Create the UnoUrlResolver 3. Get the central desktop object 4. Declare the ServiceManager 5. Get the central desktop object 6. Access the current writer document 7. Access the document's text property 8. Create a cursor 9. Insert the text into the document """ localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve ( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager desktop = smgr.createInstanceWithContext ( "com.sun.star.frame.Desktop",ctx) model = desktop.getCurrentComponent() text = model.Text cursor = text.createTextCursor() text.insertString( cursor, "Hello World", 0 ) """ Do a nasty thing before exiting the python process. In case the last call is a one-way call (e.g. see idl-spec of insertString), it must be forced out of the remote-bridge caches before python exits the process. Otherwise, the one-way call may or may not reach the target object. I do this here by calling a cheap synchronous call (getPropertyValue).""" ctx.ServiceManager WHAT!?!?!??! I don't mean to discredit these guys but the API should be re-thought, and re-written! I don't care about component contexts, unoresolvers, or little green aliens. I just want to insert 'Hello World' into cell A3! Sheesh, There must be an easier way! From tjreedy at udel.edu Mon Nov 23 20:05:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:05:36 -0500 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> Message-ID: astral orange wrote: > As far as the program. I did add print statements such as print > (MyNames) and got back: > > {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} Hmmm, as I understood the code, either that should be ... 'last': {} ... before the first store(), as you seem to be thinking below, or after the first store(), {'middle': {'Larry': ['John Larry Smith'], 'last': {'Smith': ['John Larry Smith'], 'first': {'John' " ['John Larry Smith']} or the same with [['John','Larry','Smith']] for each entry (do not remember exactly what was stored. Maybe a typo. tjr From tjreedy at udel.edu Mon Nov 23 20:09:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:09:18 -0500 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <4B0AEDCF.4060300@mrabarnett.plus.com> References: <7n0578F3j7qa6U1@mid.individual.net> <4B0AEDCF.4060300@mrabarnett.plus.com> Message-ID: MRAB wrote: > Neil Cerutti wrote: > > I installed Python 3.1 today, and I've been porting my small > > library of programs to the new system. > > > > I happened to read the interesting "Idioms and Anti-Idioms" > > HOWTO, and saw the '\' continuation character labeled an > > anti-idiom. I already generally avoided it, so I just nodded. > > > > Unfortunately, the new "nested" with statement (which I also read > > about today) forces me into this anti-idiom. When replacing an > > appearance of contextlib.nested with the 3K with statement, I > > ended up with an unexpected syntax error. > > > > with (open(roster_path, 'r') as roster_file, > > open(disb_path, 'w') as out_file, > > open(report_path, 'w') as report_file): > > > > The result was: > > > > File "C:\project\codxml.py", line 184 > > with (open(roster_path, 'r') as roster_file, > > ^ > > SyntaxError: invalid syntax > > > > Unless I'm missing something, I have to subject my code to a bit > > of contintuation: > > > > with open(roster_path, 'r') as roster_file,\ > > open(disb_path, 'w') as out_file,\ > > open(report_path, 'w') as report_file: > > > > I was thinking about submitting a enhancement request to the > > HOWTO, explaining that continuation my be required in this > > context. Am I missing anything obvious? > > > The relevant syntax is: > > with_stmt ::= "with" with_item ("," with_item)* ":" suite > > with_item ::= expression ["as" target] > > Parentheses only work around an expression or when they are expected by > the syntax, eg in function calls. > > In this case it sees the '(' and thinks that it's the start of a > parenthesised expression. It parses the expression, then sees 'as', > hence a SyntaxError. I suppose it could've complained about a missing > ')' instead. > > I wonder whether an end-of-line could be ignored after a comma in a > 'with' statement, and, for consistency, in any similar cases. Then a line ending with ', ' would be different from one ending with ',', useless space and tabs at ends of lines were *always* ignored. Not sure whether that would create problems though. From lists at cheimes.de Mon Nov 23 20:23:19 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 24 Nov 2009 02:23:19 +0100 Subject: Relative versus absolute paths on Windows In-Reply-To: <7mos8lF3is0n7U1@mid.individual.net> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <7mos8lF3is0n7U1@mid.individual.net> Message-ID: Gregory Ewing wrote: >>>>> ntpath.join('d:\\foo', '\\bar') >> '\\bar' > > This does seem like a bug, though -- the correct result > should really be 'd:\\bar', since that's what you would > get if you used the name '\\bar' with 'd:' as your current > drive. No, it's not a bug. Since \bar is an absolute path, all path segments before the absolute path are ignored. This is documented at http://docs.python.org/library/os.path.html#os.path.join >>> ntpath.isabs("\\bar") True >>> ntpath.join("ignored", "\\bar") '\\bar' Posixpath follows the same rules, too. >>> posixpath.join("..", "egg", "/var") '/var' >>> posixpath.join("..", "egg", "var") '../egg/var' Christian From gabutler at acslink.net.au Mon Nov 23 20:27:50 2009 From: gabutler at acslink.net.au (gerry.butler) Date: Mon, 23 Nov 2009 17:27:50 -0800 (PST) Subject: Capturing output of os.system to a string Message-ID: How do I capture output to a string? For example, the output of os.system('whoami'). I guess I need to redirect stdout, but I'm a total beginner, and I haven't been able to find out from the tutorials how to do this. From apt.shansen at gmail.com Mon Nov 23 20:36:35 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 17:36:35 -0800 Subject: Capturing output of os.system to a string In-Reply-To: References: Message-ID: <7a9c25c20911231736y634b68cawc76bdc6b01b8e883@mail.gmail.com> On Mon, Nov 23, 2009 at 5:27 PM, gerry.butler wrote: > How do I capture output to a string? For example, the output of > os.system('whoami'). > > I guess I need to redirect stdout, but I'm a total beginner, and I > haven't been able to find out from the tutorials how to do this. > > You don't; os.system is only usable to send commands off that need no input and which you don't care for the output. Check out the subprocess module. You can do like: popen = subprocess.Popen("whoami", stdout=subprocess.PIPE) Then "out, err = popen.communicate()" The 'out' should contain the output from the command. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 23 20:40:00 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 12:40:00 +1100 Subject: Capturing output of os.system to a string In-Reply-To: References: Message-ID: <4b0b39ca$1@dnews.tpgi.com.au> gerry.butler wrote: > How do I capture output to a string? For example, the output of > os.system('whoami'). > > I guess I need to redirect stdout, but I'm a total beginner, and I > haven't been able to find out from the tutorials how to do this. > You can't with os.system; use subprocess module instead. From ethan at stoneleaf.us Mon Nov 23 20:44:46 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 17:44:46 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <7mos8lF3is0n7U1@mid.individual.net> Message-ID: <4B0B3A8E.2000201@stoneleaf.us> Christian Heimes wrote: > Gregory Ewing wrote: > >>>>>>ntpath.join('d:\\foo', '\\bar') >>> >>>'\\bar' >> >>This does seem like a bug, though -- the correct result >>should really be 'd:\\bar', since that's what you would >>get if you used the name '\\bar' with 'd:' as your current >>drive. > > > No, it's not a bug. Since \bar is an absolute path, all path segments > before the absolute path are ignored. This is documented at > http://docs.python.org/library/os.path.html#os.path.join Given that it's documented to work that way, I'll agree that this is not a bug -- however, that doesn't mean it's /right/. From the documentation: Join one or more path components *intelligently*. To me, that means taking into account the bizarre in the MS world of multiple roots on a system... I know I have looked at os.path.join a couple times also, and found the documented behavior to be completely unsatisfactory. In the MS world a drive letter specifier should trump a mere backslash, not be trumped by it. Are there real world situations where the reverse is desired? >>>>ntpath.isabs("\\bar") > > True > >>>>ntpath.join("ignored", "\\bar") > > '\\bar' > > Posixpath follows the same rules, too. > > >>>>posixpath.join("..", "egg", "/var") > > '/var' > >>>>posixpath.join("..", "egg", "var") > > '../egg/var' Posix has the luxury of running on sane systems with only one root. ~Ethan~ From tjreedy at udel.edu Mon Nov 23 20:48:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:48:40 -0500 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > import os > import fileinput > > def write( s ): print( s, end = "" ) I believe this is the same as write = sys.stdout.write though you never use it that I see. > > msg_id = 0 > f = open( "nul", "w" ) > for line in fileinput.input( mode = "rb" ): I presume you are expecting the line to be undecoded bytes, as with open(f,'rb'). To be sure, add write(type(line)). > if line.startswith( "From - " ): > msg_id += 1; > f.close() > print( msg_id ) > f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) I do not understand why you are writing since you just wanted to look. In any case, you open in text mode. > else: > f.write( line ) > f.close() > > > > > 955 > 956 > 957 > 958 > Traceback (most recent call last): > File "C:\test\tbfix\splitmails.py", line 11, in > for line in fileinput.input( mode = "rb" ): > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, > in __next__ > line = self.readline() > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, > in readline > self._buffer = self._file.readlines(self._bufsize) > File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line > 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position > 2188: character maps to After I tried os.path.normpath(), it is clear that the function doesn't return the trailing '/', if the path is a directory. But this fact is not documented. Should this be documented in future release of python. Also, I found the documentation of some functions in os.path are not clear. I have to try them in order to understand them for corner cases. I'm wondering if I can join the people who maintain the document to help improve it. From geraldwalkerx at gmail.com Mon Nov 23 20:53:23 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 20:53:23 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: Anjanesh Lekshminarayanan wrote: > fp = urllib.urlopen(url) > data = fp.read() > > Retrieving XML data via an XML service API. > Very often network gets stuck in between. No errors / exceptions. > > CTRL+C > > File "get-xml.py", line 32, in > fp = urllib.urlopen(url) > File "/usr/lib/python2.6/urllib.py", line 87, in urlopen > return opener.open(url) > File "/usr/lib/python2.6/urllib.py", line 206, in open > return getattr(self, name)(url) > File "/usr/lib/python2.6/urllib.py", line 348, in open_http > errcode, errmsg, headers = h.getreply() > File "/usr/lib/python2.6/httplib.py", line 1048, in getreply > response = self._conn.getresponse() > File "/usr/lib/python2.6/httplib.py", line 974, in getresponse > response.begin() > File "/usr/lib/python2.6/httplib.py", line 391, in begin > version, status, reason = self._read_status() > File "/usr/lib/python2.6/httplib.py", line 349, in _read_status > line = self.fp.readline() > File "/usr/lib/python2.6/socket.py", line 397, in readline > data = recv(1) > KeyboardInterrupt > > Is there I can do to try something else if its taking too long to > retrieve from the network ? Like kill previous attempt and retry ? > > Thanks > Anjanesh Lekshmnarayanan import socket from urllib2 import urlopen # A one-hundredths of a second (0.01) timeout before socket throws # an exception to demonstrate catching the timeout. # Obviously, this you will set this greater than 0.01 in real life. socket.setdefaulttimeout(0.01) # example xml feed xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" try: data = urlopen(xml_source) except urllib2.URLError, e: print 'URLError = ' + str(e.reason) From benjamin.kaplan at case.edu Mon Nov 23 20:59:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 23 Nov 2009 20:59:39 -0500 Subject: More precise document on os.path.normpath() In-Reply-To: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> References: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> Message-ID: On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu wrote: > After I tried os.path.normpath(), it is clear that the function > doesn't return the trailing '/', if the path is a directory. But this > fact is not documented. Should this be documented in future release of > python. > > Also, I found the documentation of some functions in os.path are not > clear. I have to try them in order to understand them for corner > cases. I'm wondering if I can join the people who maintain the > document to help improve it. > -- Just file a bug report listing what part you find unclear and what you suggest they put to clarify it. > http://mail.python.org/mailman/listinfo/python-list > From geraldwalkerx at gmail.com Mon Nov 23 21:01:55 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:01:55 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > import socket > from urllib2 import urlopen > > # A one-hundredths of a second (0.01) timeout before socket throws > # an exception to demonstrate catching the timeout. > # Obviously, this you will set this greater than 0.01 in real life. > socket.setdefaulttimeout(0.01) > > # example xml feed > xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" > > try: > data = urlopen(xml_source) > except urllib2.URLError, e: > print 'URLError = ' + str(e.reason) Also, if you are using multiple threads to retrieve the xml source(s) and any thread blocks due to network problems, the thread can go way by itself after the default timeout expires. From debatem1 at gmail.com Mon Nov 23 21:03:38 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:03:38 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller wrote: > I was wondering if there were any neat tools (like for instance, > something from itertools) that would help me write the following function > more elegantly. ?The return value should, of course, be the complete $k$- > partite graph $K_{n_1, n_2, \dots, n_k}$: > > def completeGraph (*ns): > ? ?''' > ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > ? ?the sequence \code {n_1, n_2, \dots, n_k}. > ? ?''' > ? ?if len (ns) == 1: > ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) > ? ?n = sum (ns) > ? ?vertices = range (n) > ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] > ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > \ > ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] > ? ?partite_sets.append (vertices[partition_indices [-1]:] ) > > ? ?edges = [] > ? ?for i in range (len (partite_sets)): > ? ? ? ?for j in range (i + 1, len (partite_sets)): > ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) > > ? ?return graph.Graph (vertices = vertices, edges = edges) > > Many thanks! Graphine does this with the following: from base import Graph def K(n): """Generates a completely connected undirected graph of size n. The verticies are numbered [0, n). The edges are named after the verticies they connect such that an edge connected verticies 1 and 2 is named (1,2). """ # create the graph k = Graph() # generate all the nodes for i in range(n): k.add_node(i) # generate all the edges for i in range(n): for j in range(i+1, n): k.add_edge(i, j, (i,j), is_directed=False) # return the graph return k Disclaimer: I'm the author of graphine. Geremy Condra From geraldwalkerx at gmail.com Mon Nov 23 21:06:05 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:06:05 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > Also, if you are using multiple threads to retrieve the xml source(s) > and any thread blocks due to network problems, the thread can go way by > itself after the default timeout expires. > > Typo, edited for clarity: That is: "..the thread can go *away* by itself after the default timeout expires." You don't need to explicitly kill it. From lie.1296 at gmail.com Mon Nov 23 21:08:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 13:08:24 +1100 Subject: profiling differences using an extra function call In-Reply-To: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> References: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> Message-ID: <4b0b4072$1@dnews.tpgi.com.au> marc magrans de abril wrote: > Hi, > > I was a trying to profile a small script and after shrinking the code > to the minimum I got a interesting profile difference. > Given two test functions test1 and test2, that only differs from an > extra level of indirection (i.e. find_substr), That's because there is a function call overhead. > I wonder why I got a > timming difference >50%? A very simple function body will (in terms of percentage) have larger function overhead. With a slightly more complex function body, the body will takes much more time than the function call overhead. > What is the recommended way to factorize the > code? Should I write a big method containing everything? Look in the absolute numbers: 0.666 CPU seconds vs. 0.248 CPU seconds over 1000000 loops means if you put everything into one big method you'll only save 418 nanoseconds per loop. Even over 1000000 loops; you only save 0.418 seconds. Is it worth optimizing? > ----Profiles test1 > Profiles results: > 1000003 function calls in 0.666 CPU seconds > > ----Profile test2: > 3 function calls in 0.248 CPU seconds I got a more striking difference: 5.291 CPU seconds vs 0.589 CPU seconds. But knowing how the profiler works, this is to be expected. Function call overhead become much (and I mean much) heavier with profiler ON. I get a more sane result with timing manually: import time start = time.time() test1(t) print time.time() - start start = time.time() test2(t) print time.time() - start It's 1.186 vs 0.608, which is blink of an eye vs. blink of an eye. From debatem1 at gmail.com Mon Nov 23 21:10:37 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:10:37 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: > On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller > wrote: >> I was wondering if there were any neat tools (like for instance, >> something from itertools) that would help me write the following function >> more elegantly. ?The return value should, of course, be the complete $k$- >> partite graph $K_{n_1, n_2, \dots, n_k}$: >> >> def completeGraph (*ns): >> ? ?''' >> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed >> ? ?the sequence \code {n_1, n_2, \dots, n_k}. >> ? ?''' >> ? ?if len (ns) == 1: >> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) >> ? ?n = sum (ns) >> ? ?vertices = range (n) >> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] >> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] >> \ >> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] >> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) >> >> ? ?edges = [] >> ? ?for i in range (len (partite_sets)): >> ? ? ? ?for j in range (i + 1, len (partite_sets)): >> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ >> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) >> >> ? ?return graph.Graph (vertices = vertices, edges = edges) >> >> Many thanks! > > Graphine does this with the following: > > from base import Graph > > def K(n): > ? ? ? ?"""Generates a completely connected undirected graph of size n. > > ? ? ? ?The verticies are numbered [0, n). > > ? ? ? ?The edges are named after the verticies they connect such that > ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). > ? ? ? ?""" > ? ? ? ?# create the graph > ? ? ? ?k = Graph() > ? ? ? ?# generate all the nodes > ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ?k.add_node(i) > ? ? ? ?# generate all the edges > ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ?for j in range(i+1, n): > ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) > ? ? ? ?# return the graph > ? ? ? ?return k > > > Disclaimer: I'm the author of graphine. > > Geremy Condra > Sorry, misread- to generate a k-partite graph, you'll need a bit more legwork. Give me a bit and I'll add it to graphine. Geremy Condra From gabutler at acslink.net.au Mon Nov 23 21:11:08 2009 From: gabutler at acslink.net.au (gerry.butler) Date: Mon, 23 Nov 2009 18:11:08 -0800 (PST) Subject: Capturing output of os.system to a string References: <4b0b39ca$1@dnews.tpgi.com.au> Message-ID: <1a88f8fa-e7a9-4754-8e8e-ba22b63ff43f@u1g2000pre.googlegroups.com> Thank you. I'll look at subprocess. I have since found that commands will do it too, eg, (status, txt) = commands.getstatusoutput('whoami') or txt = commands.getoutput('whoami') From andyjian430074 at gmail.com Mon Nov 23 21:14:56 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 18:14:56 -0800 (PST) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> Message-ID: <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> On Nov 23, 4:08?pm, "Diez B. Roggisch" wrote: > Jankins schrieb: > > > > > > > I am trying to use sys.stdout to print out "process-bar" like: > > -->1% > > > Here is my program ?test.py?: > > > from sys import stdout > > for v in range(10): > > ? ? stdout.write('-->%d' % v) > > ? ? stdout.flush() > > else: > > ? ? stdout.write('done!') > > #end for > > > Then, I use 'python -u test.py' to run this script. But what I get > > is : > > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > > I am suppose to get 'done!'. > > > Can anybody help me about this? > > You misunderstand what "flush" means. It is not about clearing the > screen, or the line. > > Try printing > > ? ?stdout.write('\r-->%d') > > Diez But there is still a problem. When you use control character '\r', you actually move to the head of the current buffer line and overwrite it. So if I use this way: for i in range(100, 0,-1) The tail of the buffer is not overwrote. How to solve this problem? Thanks. From geraldwalkerx at gmail.com Mon Nov 23 21:15:10 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:15:10 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > import socket > from urllib2 import urlopen > > # A one-hundredths of a second (0.01) timeout before socket throws > # an exception to demonstrate catching the timeout. > # Obviously, this you will set this greater than 0.01 in real life. > socket.setdefaulttimeout(0.01) > > # example xml feed > xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" > > try: > data = urlopen(xml_source) > except urllib2.URLError, e: > print 'URLError = ' + str(e.reason) Oops, the above doesn't run. This version works: import socket import urllib2 # A one-hundredths of a second (0.01) timeout before socket throws # an exception to demonstrate catching the timeout. # Obviously, this you will set this greater than 0.01 in real life. socket.setdefaulttimeout(0.01) # example xml feed xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" try: data = urllib2.urlopen(xml_source) except urllib2.URLError, e: print 'URLError = ' + str(e.reason) From limodou at gmail.com Mon Nov 23 21:16:42 2009 From: limodou at gmail.com (limodou) Date: Tue, 24 Nov 2009 10:16:42 +0800 Subject: ANN: UliPad 4.0 released! Message-ID: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> UliPad is a flexible editor, based on wxPython. It's has many features,just like:class browser, code auto-complete, html viewer, directory browser, wizard, etc. The main feature is the usage of mixin. This makes UliPad can be extended easily. So you can write your own mixin or plugin, or simple script, these can be easy and seamless integrated with UliPad.Features - *Cross platform* - based on wxPython, so it can run anywhere that wxPython works, such as: Windows, Linux. - Unicode support. - *Most features of wxStyledTextCtrl(Scintilla)* - Syntax highlighting, support Python, c/c++, html, plain text - Folding - Brace Matching - ... - *Extended selection* - Extended word selection -- You can press Ctrl+`MouseDoubleClick` to select a word including '.' - Matched selection -- Select text in quoted chars like: (), [], {}, '', "". For example: a string just like: def func(self, 'This is a test'): ^ The '^' char represents caret position in above line. If you press Ctrl+E, you will select the whole text in (), i.e. "self, 'This is a test'". Something more in Selection Menu. - *Other editing extension* - Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and more. You can duplicate above or below char, word, line which match the leading chars. - Quoting text -- Add some quoted chars before and after selected text, just as: "", '', (), [], {}, and customized string, etc. - Text convertion and view -- python -> html, reStructured Text -> html, textile -> html, and you can output or view the html text in message window, or html view window, or replace the selected text. - Utf-8 encoding auto detect - Changing document encoding - Auto backup - Last session support -- It'll save all the filenames as closed, and reopen the files as next started. - Smart judge the indent char -- It'll auto guess the indent char, and sets it. - Finding in files - Bookmark supports - *Python support* - built-in python interactive window based on PyShell, support Unicode - Auto completion - Function syntax calltips - Run, run with argument, stop python source - Auto change current path - Python class browser - Syntax and PEP8 style checking?also supply a pylint plugin. - *Code snippets* You can manage your code snippets with categories, and each category can have many items. Every item will represent a code snippet. You can insert an item just by double-clicking on it. It even supports importing and exporting. - *Simple project support* Can create a special file _project, so every file and folder under the folder which has the _project can be considered as a whole project. - *Extension mechanism* - Script -- You can write easy script to manipulate the all resource of UliPad, just like: text conversion, etc. - Plugin -- Customized function. More complex but more powerful. Can easily merge with UliPad, and can be managed via menu. - Shell command -- Add often used shell commands, and execute them. - *Ftp support* You can edit remote files through ftp. You can add, rename, delete, upload, download file/directory. - *Multilanguage support* Currently supports 4 languages: English, Spanish, Simplified Chinese and Traditional Chinese, which can be auto-detected. - *Ships many plugins* (must be configed as used them before) - Django support plugin - Batch rename files plugin - Collaborative Programming support plugin, names as *pairprog*. - Mp3 player plugin - Spell check plugin - wizard plugin - Text to speech(windows only) plugin - ... - *Shipped scripts* - You can find them in ($UliPadInstalled)/scripts. - *Wizard* You can make your own wizard template. The wizard can input user data, combine with template, and output the result. And wizard also support code framework created. This feature will help you improving coding efficiency. - *Direcotry Browser* Browse multiple directories, and you can really add, delete, rename directories and files. Double click will open the file in Editor window. - *`AutoComPlete`(acp)* Suport user autocomplete file, it can help to input code very helpful and functional. - *Column Editing Mode* You can select multilines, and then set a column mode region, so in any line of this region, if you enter a character, other lines will also add this character. If you want to deal with multilines as a similar mode, this functionality will be very handy. - *Smart Navigation* UliPad can remember the visit order of your opened files, and you can go back or go forward in these files. - *Live regular expression searching* You can type some regular expression on the fly, and see the result dynamiclly. - *Spell check plugin* Need to install PyEnchant module. - *Collaborative Programming* Multi-user can modify some files at the same time. You should enable * pairprog* plugin. - *Todo Supports* Auto finds todos and supports several kind of formats. - *Multi-View Supports* User can open a document in multi views, for example in left pane or bottom pane. - *Version Control Support* - svn support. Now you can use svn in UliPad to update, checkout, commit, etc. Links - Project: http://code.google.com/p/ulipad - source version: http://ulipad.googlecode.com/files/ulipad.4.0.zip - windows exe version: http://ulipad.googlecode.com/files/ulipad.4.0.py25.exe - maillist: http://groups.google.com/group/ulipad - ulipad snippets site: http://ulipad.appspot.com (hosted by GAE) Hope you enjoy it. -- I like python! UliPad <>: http://code.google.com/p/ulipad/ UliWeb <>: http://uliwebproject.appspot.com My Blog: http://hi.baidu.com/limodou -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary.wugang at gmail.com Mon Nov 23 21:18:25 2009 From: gary.wugang at gmail.com (Gang(Gary) Wu) Date: Tue, 24 Nov 2009 10:18:25 +0800 Subject: [CPyUG:110052] ANN: UliPad 4.0 released! In-Reply-To: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> References: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> Message-ID: ??????????emacs On Tue, Nov 24, 2009 at 10:16 AM, limodou wrote: > UliPad is a flexible editor, based on wxPython. It's has many > features,just like:class browser, code auto-complete, html viewer, directory > browser, wizard, etc. The main feature is the usage of mixin. This makes > UliPad can be extended easily. So you can write your own mixin or plugin, or > simple script, these can be easy and seamless integrated with UliPad. > Features > > - > > *Cross platform* > - based on wxPython, so it can run anywhere that wxPython works, such > as: Windows, Linux. > - Unicode support. > - > > *Most features of wxStyledTextCtrl(Scintilla)* > - Syntax highlighting, support Python, c/c++, html, plain text > - Folding > - Brace Matching > - ... > - > > *Extended selection* > - > > Extended word selection -- You can press Ctrl+`MouseDoubleClick` to > select a word including '.' > - > > Matched selection -- Select text in quoted chars like: (), [], {}, > '', "". > > For example: a string just like: > > def func(self, 'This is a test'): > ^ > > The '^' char represents caret position in above line. If you press > Ctrl+E, you will select the whole text in (), i.e. "self, 'This is a test'". > Something more in Selection Menu. > - > > *Other editing extension* > - Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and more. You can > duplicate above or below char, word, line which match the leading chars. > - Quoting text -- Add some quoted chars before and after selected > text, just as: "", '', (), [], {}, and customized string, etc. > - Text convertion and view -- python -> html, reStructured Text -> > html, textile -> html, and you can output or view the html text in message > window, or html view window, or replace the selected text. > - Utf-8 encoding auto detect > - Changing document encoding > - Auto backup > - Last session support -- It'll save all the filenames as closed, > and reopen the files as next started. > - Smart judge the indent char -- It'll auto guess the indent char, > and sets it. > - Finding in files > - Bookmark supports > - > > *Python support* > - built-in python interactive window based on PyShell, support Unicode > > - Auto completion > - Function syntax calltips > - Run, run with argument, stop python source > - Auto change current path > - Python class browser > - Syntax and PEP8 style checking?also supply a pylint plugin. > - > > *Code snippets* > > You can manage your code snippets with categories, and each category > can have many items. Every item will represent a code snippet. You can > insert an item just by double-clicking on it. It even supports importing and > exporting. > - > > *Simple project support* > > Can create a special file _project, so every file and folder under the > folder which has the _project can be considered as a whole project. > - > > *Extension mechanism* > - Script -- You can write easy script to manipulate the all resource > of UliPad, just like: text conversion, etc. > - Plugin -- Customized function. More complex but more powerful. Can > easily merge with UliPad, and can be managed via menu. > - Shell command -- Add often used shell commands, and execute them. > - > > *Ftp support* You can edit remote files through ftp. You can add, > rename, delete, upload, download file/directory. > - > > *Multilanguage support* > > Currently supports 4 languages: English, Spanish, Simplified Chinese > and Traditional Chinese, which can be auto-detected. > - > > *Ships many plugins* (must be configed as used them before) > - Django support plugin > - Batch rename files plugin > - Collaborative Programming support plugin, names as *pairprog*. > - Mp3 player plugin > - Spell check plugin > - wizard plugin > - Text to speech(windows only) plugin > - ... > - > > *Shipped scripts* > - You can find them in ($UliPadInstalled)/scripts. > - > > *Wizard* > > You can make your own wizard template. The wizard can input user data, > combine with template, and output the result. And wizard also support code > framework created. This feature will help you improving coding efficiency. > - > > *Direcotry Browser* > > Browse multiple directories, and you can really add, delete, rename > directories and files. Double click will open the file in Editor window. > - > > *`AutoComPlete`(acp)* > > Suport user autocomplete file, it can help to input code very helpful > and functional. > - > > *Column Editing Mode* > > You can select multilines, and then set a column mode region, so in any > line of this region, if you enter a character, other lines will also add > this character. If you want to deal with multilines as a similar mode, this > functionality will be very handy. > - > > *Smart Navigation* > > UliPad can remember the visit order of your opened files, and you can > go back or go forward in these files. > - > > *Live regular expression searching* > > You can type some regular expression on the fly, and see the result > dynamiclly. > - > > *Spell check plugin* > > Need to install PyEnchant module. > - > > *Collaborative Programming* > > Multi-user can modify some files at the same time. You should enable * > pairprog* plugin. > - > > *Todo Supports* > > Auto finds todos and supports several kind of formats. > - > > *Multi-View Supports* > > User can open a document in multi views, for example in left pane or > bottom pane. > - > > *Version Control Support* > - svn support. Now you can use svn in UliPad to update, checkout, > commit, etc. > > Links > > - Project: http://code.google.com/p/ulipad > - source version: http://ulipad.googlecode.com/files/ulipad.4.0.zip > - windows exe version: > http://ulipad.googlecode.com/files/ulipad.4.0.py25.exe > - maillist: http://groups.google.com/group/ulipad > - ulipad snippets site: http://ulipad.appspot.com (hosted by GAE) > > Hope you enjoy it. > > -- > I like python! > UliPad <>: http://code.google.com/p/ulipad/ > UliWeb <>: http://uliwebproject.appspot.com > My Blog: http://hi.baidu.com/limodou > > > --~--~---------~--~----~------------~-------~--~----~ > ??: `python-cn`:CPyUG ~ ????? | ??:python-cn at googlegroups.com > ??: http://tinyurl.com/45a9tb //??163/qq??:http://tinyurl.com/4dg6hc > ??: https://groups.google.com/group/python-cn > ??: ????! ????! http://wiki.woodpecker.org.cn/moin/AskForHelp > -~----------~----~----~----~------~----~------~--~--- > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Mon Nov 23 21:32:50 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 24 Nov 2009 02:32:50 +0000 (UTC) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> Message-ID: >> .... >> You misunderstand what "flush" means. It is not about >> clearing the screen, or the line. >> >> Try printing >> >> ? ?stdout.write('\r-->%d') >> >> Diez > > > But there is still a problem. When you use control character '\r', > you actually move to the head of the current buffer line and > overwrite it. > > So if I use this way: > for i in range(100, 0,-1) > > The tail of the buffer is not overwrote. > .... The following version works ok for me using python2.5 under debian linux .... import sys import time print for n in range( 11 ) : sys.stdout.write( '\r Working ----> %d ' % n ) sys.stdout.flush() time.sleep( 1 ) else : print "\n" print " That's all, folks !" print " Adios ........... " -- Stanley C. Kitching Human Being Phoenix, Arizona From sergiomb at sapo.pt Mon Nov 23 21:44:56 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Tue, 24 Nov 2009 02:44:56 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> <4b0ad983$0$13161$a729d347@news.telepac.pt> <7n0f6qF3hgohqU1@mid.uni-berlin.de> Message-ID: <4b0b48a9$0$11263$a729d347@news.telepac.pt> Diez B. Roggisch wrote: > S?rgio Monteiro Basto schrieb: >> Diez B. Roggisch wrote: >> >> Hi, Thanks, >>> S?rgio Monteiro Basto wrote: >>> >>>> Hi, >>>> I am in x86_64 arch , but I need >>>> compile things on 32 bits with >>>> python setup.py build >>>> >>>> Can't change the fact that distutils creates x86_64 >>>> directories: >>>> build/temp.linux-x86_64-2.3/ >>>> >>>> Also if I try with a python compile in 32bits and installed >>>> in system . >>> I doubt that. Distutils will always build based on the architecture of >>> the interpreter you used when building an external module. >>> >>> Are you sure that the python you used to build the extension was the >>> right one? What does >>> >>> -c "from distutils.util import get_platform; print >>> get_platform()" >> python32 -c "from distutils.util import get_platform; print >> get_platform()" linux-x86_64 >> >> ldd ~/bin/python32 >>linux-gate.so.1 => (0xffffe000) >>libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) >>libdl.so.2 => /lib/libdl.so.2 (0x0033f000) >>libutil.so.1 => /lib/libutil.so.1 (0x006b3000) >>libm.so.6 => /lib/libm.so.6 (0x00345000) >>libc.so.6 => /lib/libc.so.6 (0x001e0000) >>/lib/ld-linux.so.2 (0x001c2000) >> >> this a python 2.3, that's make any difference ? > > Ok, next try: > > import distutils > print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') > > What does that yield? >>> import distutils.sysconfig >>> print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') None Thanks, I found the problem, python doesn't have devel stuff like config/Makefile. A complete python3.5 with config/Makefile solved the problem . "distutils gets its compiler options from Python's Makefile", and I don't have config/Makefile correctly build ... Big thanks, From debatem1 at gmail.com Mon Nov 23 21:45:45 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:45:45 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 9:10 PM, geremy condra wrote: > On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: >> On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller >> wrote: >>> I was wondering if there were any neat tools (like for instance, >>> something from itertools) that would help me write the following function >>> more elegantly. ?The return value should, of course, be the complete $k$- >>> partite graph $K_{n_1, n_2, \dots, n_k}$: >>> >>> def completeGraph (*ns): >>> ? ?''' >>> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed >>> ? ?the sequence \code {n_1, n_2, \dots, n_k}. >>> ? ?''' >>> ? ?if len (ns) == 1: >>> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) >>> ? ?n = sum (ns) >>> ? ?vertices = range (n) >>> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] >>> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] >>> \ >>> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] >>> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) >>> >>> ? ?edges = [] >>> ? ?for i in range (len (partite_sets)): >>> ? ? ? ?for j in range (i + 1, len (partite_sets)): >>> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ >>> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) >>> >>> ? ?return graph.Graph (vertices = vertices, edges = edges) >>> >>> Many thanks! >> >> Graphine does this with the following: >> >> from base import Graph >> >> def K(n): >> ? ? ? ?"""Generates a completely connected undirected graph of size n. >> >> ? ? ? ?The verticies are numbered [0, n). >> >> ? ? ? ?The edges are named after the verticies they connect such that >> ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). >> ? ? ? ?""" >> ? ? ? ?# create the graph >> ? ? ? ?k = Graph() >> ? ? ? ?# generate all the nodes >> ? ? ? ?for i in range(n): >> ? ? ? ? ? ? ? ?k.add_node(i) >> ? ? ? ?# generate all the edges >> ? ? ? ?for i in range(n): >> ? ? ? ? ? ? ? ?for j in range(i+1, n): >> ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) >> ? ? ? ?# return the graph >> ? ? ? ?return k >> >> >> Disclaimer: I'm the author of graphine. >> >> Geremy Condra >> Alright, how does this look: def k_partite(*partition_sizes): g = Graph() for pos, num_nodes in enumerate(partition_sizes): for i in range(num_nodes): n = g.add_node(name=(pos,i), partition=pos) for node1 in g.nodes: for node2 in g.nodes: if node1.partition != node2.partition: g.add_edge(node1, node2, is_directed=False) return g Geremy Condra From pavlovevidence at gmail.com Mon Nov 23 21:49:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 23 Nov 2009 18:49:45 -0800 (PST) Subject: More precise document on os.path.normpath() References: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> Message-ID: <0767bed0-bc95-4494-ae3b-6b38f370f37e@p19g2000vbq.googlegroups.com> On Nov 23, 5:59?pm, Benjamin Kaplan wrote: > On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu wrote: > > After I tried os.path.normpath(), it is clear that the function > > doesn't return the trailing '/', if the path is a directory. But this > > fact is not documented. Should this be documented in future release of > > python. > > > Also, I found the documentation of some functions in os.path are not > > clear. I have to try them in order to understand them for corner > > cases. I'm wondering if I can join the people who maintain the > > document to help improve it. > > Just file a bug report listing what part you find unclear and what you > suggest they put to clarify it. The documentation does not and should not try to document every little detail of every function. For that matter, nor should comp.lang.python. Python is open source, anyone can look at the implementation to see how it behaves. The source code is the right place to seek answers about arcane minutae like when os.path.normpath appends a backslash. Not the Python docuementation, and definitely not this newsgroup. Carl Banks From sergiomb at sapo.pt Mon Nov 23 21:50:14 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Tue, 24 Nov 2009 02:50:14 +0000 Subject: lxml 2.2.4 for Python 2.6 References: <9a80baa0-986d-4c17-bcf2-a32d0bf276bf@z10g2000prh.googlegroups.com> Message-ID: <4b0b49e6$0$11263$a729d347@news.telepac.pt> Hi, Srijit Kumar Bhadra wrote: > Is there any reason why lxml-2.2.4-py2.6-win32.egg (md5) or > lxml-2.2.4.win32-py2.6.exe is not available? > > Best regards, > /Srijit maybe ask on lxml Mailing List , should be more appropriated S?rgio M. B. From davea at ieee.org Mon Nov 23 21:54:56 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 23 Nov 2009 21:54:56 -0500 Subject: sys.stdout is not flushed In-Reply-To: <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> Message-ID: <4B0B4B00.4050105@ieee.org> Jankins wrote: > On Nov 23, 4:08 pm, "Diez B. Roggisch" wrote: > >> Jankins schrieb: >> >> >> >> >> >> >>> I am trying to use sys.stdout to print out "process-bar" like: >>> -->1% >>> >>> Here is my program ?test.py?: >>> >>> from sys import stdout >>> for v in range(10): >>> stdout.write('-->%d' % v) >>> stdout.flush() >>> else: >>> stdout.write('done!') >>> #end for >>> >>> Then, I use 'python -u test.py' to run this script. But what I get >>> is : >>> -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! >>> >>> I am suppose to get 'done!'. >>> >>> Can anybody help me about this? >>> >> You misunderstand what "flush" means. It is not about clearing the >> screen, or the line. >> >> Try printing >> >> stdout.write('\r-->%d') >> >> Diez >> > > > But there is still a problem. When you use control character '\r', you > actually move to the head of the current buffer line and overwrite it. > So if I use this way: > for i in range(100, 0,-1) > > The tail of the buffer is not overwrote. > > How to solve this problem? > > Thanks. > > No idea what you mean by "buffer line." This is moving the cursor around on the console. Anyway, for such a loop, just make sure all the strings are the same length. Or just cheat and always write a few blanks at the end. sys.stdout.write("\r -- %5d" % i) should do it, for up to 5 digit values DaveA From pengyu.ut at gmail.com Mon Nov 23 22:15:48 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 23 Nov 2009 21:15:48 -0600 Subject: Where to put the error handing test? Message-ID: <366c6f340911231915k31cea424sbe9ad8e77def18b0@mail.gmail.com> Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of g(x) is safer, but the test is not necessary when g() is called by h(). If I put the test in f(), then g() becomes more efficient when other code call g() and guarantee x will pass the test even though the test code in not in g(). But there might be some caller of g() that pass an 'x' that might not pass the test, if there were the test in g(). def g(x): # I can put the code here to test whether x satisfies certain conditions. blah, blah def f(x): blah, blah #do something on x # I can also put the code here to test whether x satisfies certain conditions. g(x) def h() blah g(x)#x here are guaranteed to pass the test From rt8396 at gmail.com Mon Nov 23 22:37:09 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 19:37:09 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com> On Nov 23, 11:19?am, astral orange <457r0... at gmail.com> wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > ?92 def init(data): > ?93 ? ? data['first'] = {} > ?94 ? ? data['middle'] = {} > ?95 ? ? data['last'] = {} > ?96 > ?97 def store(data, full_name): > ?98 ? ? names = full_name.split() > 100 ? ? if len(names) == 2: names.insert(1, '') > 101 ? ? labels = 'first', 'middle', 'last' > 103 ? ? for label, name in zip(labels, names): > 104 ? ? ? ? people = lookup(data, label, name) > 105 ? ? if people: > 106 ? ? ? ? people.append(full_name) > 107 ? ? else: > 108 ? ? ? ? data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 ? ? return data[label].get(name) > 112 > 113 > 114 MyNames = {} > 115 init(MyNames) > 116 store(MyNames, 'John Larry Smith') > 117 lookup(MyNames, 'middle', 'Smith') This is a horrible example to show noobs. I think the OP could better understand this as a class EVEN though the OP may or may not know what a class *is* yet. >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last >>> name1 = Name('Guido', 'van', 'Rossum') >>> name1.first 'Guido' >>> name1.middle 'van' >>> name1.last 'Rossum' >>> print name1 <__main__.Name instance at 0x029BFD78> This time we add a __str__ method, the result will speak louder than words!! >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last def __str__(self): return '%s %s %s' %(self.first, self.middle, self.last) >>> name2 = Name('Terry', 'J', 'Reedy') >>> name2.first 'Terry' >>> name2.middle 'J' >>> name2.last 'Reedy' >>> print name2 Terry J Reedy See the difference in the print statements. Now lets have some real fun and access each sub name by index haha! >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last def __str__(self): return '%s %s %s' %(self.first, self.middle, self.last) def __len__(self): return 3 def __getitem__(self, item): if item == 0: return self.first elif item == 1: return self.middle elif item == 2: return self.last else: raise IndexError("Index must be in range 0, 2") >>> name = Name('Joe', 'blow', 'scripter') >>> name[0] 'Joe' >>> name[1] 'blow' >>> name[2] 'scripter' >>> len(name) 3 WOW, thats more info in a few lines than any tut i ever seen! I wish i could have seen that in my initial days, could have save some countless hours of confusion!!! Maybe i am in the wrong line of work? Should i keep going...? From lie.1296 at gmail.com Mon Nov 23 22:44:16 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 14:44:16 +1100 Subject: Where to put the error handing test? In-Reply-To: References: Message-ID: <4b0b56ea$1@dnews.tpgi.com.au> Peng Yu wrote: > Suppose that I have function f() that calls g(), I can put a test on > the argument 'x' in either g() or f(). I'm wondering what is the > common practice. > > My thought is that if I put the test in g(x), the code of g(x) is > safer, but the test is not necessary when g() is called by h(). > > If I put the test in f(), then g() becomes more efficient when other > code call g() and guarantee x will pass the test even though the test > code in not in g(). But there might be some caller of g() that pass an > 'x' that might not pass the test, if there were the test in g(). Typically, you test for x as early as possible, e.g. just after user input (or file or url load or whatever). After that test, you can (or should be able to) assume that all function calls will always be called with the correct argument. This is the ideal situation, it's not always easy to do. In any case though, don't optimize early. From chardster at gmail.com Mon Nov 23 22:57:05 2009 From: chardster at gmail.com (Richard Thomas) Date: Mon, 23 Nov 2009 19:57:05 -0800 (PST) Subject: Any elegant way to construct the complete $k$-partite graph in Python? References: Message-ID: <45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com> On Nov 24, 2:45?am, geremy condra wrote: > On Mon, Nov 23, 2009 at 9:10 PM, geremy condra wrote: > > On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: > >> On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller > >> wrote: > >>> I was wondering if there were any neat tools (like for instance, > >>> something from itertools) that would help me write the following function > >>> more elegantly. ?The return value should, of course, be the complete $k$- > >>> partite graph $K_{n_1, n_2, \dots, n_k}$: > > >>> def completeGraph (*ns): > >>> ? ?''' > >>> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > >>> ? ?the sequence \code {n_1, n_2, \dots, n_k}. > >>> ? ?''' > >>> ? ?if len (ns) == 1: > >>> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) > >>> ? ?n = sum (ns) > >>> ? ?vertices = range (n) > >>> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] > >>> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > >>> \ > >>> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] > >>> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) > > >>> ? ?edges = [] > >>> ? ?for i in range (len (partite_sets)): > >>> ? ? ? ?for j in range (i + 1, len (partite_sets)): > >>> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > >>> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) > > >>> ? ?return graph.Graph (vertices = vertices, edges = edges) > > >>> Many thanks! > > >> Graphine does this with the following: > > >> from base import Graph > > >> def K(n): > >> ? ? ? ?"""Generates a completely connected undirected graph of size n. > > >> ? ? ? ?The verticies are numbered [0, n). > > >> ? ? ? ?The edges are named after the verticies they connect such that > >> ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). > >> ? ? ? ?""" > >> ? ? ? ?# create the graph > >> ? ? ? ?k = Graph() > >> ? ? ? ?# generate all the nodes > >> ? ? ? ?for i in range(n): > >> ? ? ? ? ? ? ? ?k.add_node(i) > >> ? ? ? ?# generate all the edges > >> ? ? ? ?for i in range(n): > >> ? ? ? ? ? ? ? ?for j in range(i+1, n): > >> ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) > >> ? ? ? ?# return the graph > >> ? ? ? ?return k > > >> Disclaimer: I'm the author of graphine. > > >> Geremy Condra > > Alright, how does this look: > > def k_partite(*partition_sizes): > ? ? ? ? g = Graph() > ? ? ? ? for pos, num_nodes in enumerate(partition_sizes): > ? ? ? ? ? ? ? ? for i in range(num_nodes): > ? ? ? ? ? ? ? ? ? ? ? ? n = g.add_node(name=(pos,i), partition=pos) > ? ? ? ? for node1 in g.nodes: > ? ? ? ? ? ? ? ? for node2 in g.nodes: > ? ? ? ? ? ? ? ? ? ? ? ? if node1.partition != node2.partition: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g.add_edge(node1, node2, is_directed=False) > ? ? ? ? return g > > Geremy Condra Not sure exactly how you're representing graphs, this seems like the simplest way of listing the edges. def complete_partite(*sizes): total = sum(sizes) nodes, edges = range(total), [] for group in xrange(len(sizes)): low = sum(sizes[:group-1]) high = sum(sizes[:group]) edges.extend((i, j) for i in xrange(low, high) for j in xrange(high, total)) return nodes, edges Chard From lie.1296 at gmail.com Mon Nov 23 22:57:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 14:57:06 +1100 Subject: More precise document on os.path.normpath() In-Reply-To: References: Message-ID: <4b0b59ef@dnews.tpgi.com.au> Peng Yu wrote: > After I tried os.path.normpath(), it is clear that the function > doesn't return the trailing '/', if the path is a directory. But this > fact is not documented. Should this be documented in future release of > python. > > Also, I found the documentation of some functions in os.path are not > clear. I have to try them in order to understand them for corner > cases. I'm wondering if I can join the people who maintain the > document to help improve it. os.path is designed for OS-agnostic path manipulation. The textual representation of the output of os.path is irrelevant. If a trailing '/' doesn't affect the ability to open the directory or file or os.path.join or whatever, it is irrelevant to os.path. If the trailing / does affect those abilities, though, it is a bug in os.path. From lie.1296 at gmail.com Mon Nov 23 23:01:34 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 15:01:34 +1100 Subject: Line Breaks In-Reply-To: References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: <4b0b5aff@dnews.tpgi.com.au> D'Arcy J.M. Cain wrote: > On Mon, 23 Nov 2009 14:46:23 -0500 > Susan Day wrote: >> First, it does in fact ignore all line breaks, not just double line breaks. >> Here's what I'm doing: >> session.sendmail(clientEmail, ourEmail2, header+msg) >> The email sent out has the message sans breaks. > > You should really post an entire script that runs and shows the error > so that we can run it (changing the email address of course) to see > what it does. > My guess: you're writing HTML email? In HTML, superfluous whitespace is ignored. Use
    for line break   for space, or enclose the text in
    
    
    From lie.1296 at gmail.com  Mon Nov 23 23:02:23 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Tue, 24 Nov 2009 15:02:23 +1100
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: 
    References: 
    Message-ID: <4b0b5b2b@dnews.tpgi.com.au>
    
    Alf P. Steinbach wrote:
    > 
    > And I'm hesitant to just delete index file, hoping that it'll rebuild.
    
    it'll be rebuild the next time you start Thunderbird:
    (MozillaZine: http://kb.mozillazine.org/Disappearing_mail)
    *  It's possible that the ".msf" files (index files) are corrupted. To 
    rebuild the index of a folder, right-click it, select Properties, and 
    choose "Rebuild Index" from the General Information tab. You can also 
    close Thunderbird and manually delete them from your profile folder; 
    they will be rebuilt when Thunderbird starts.
    
    
    
    From pengyu.ut at gmail.com  Mon Nov 23 23:08:39 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Mon, 23 Nov 2009 22:08:39 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <4b0b56ea$1@dnews.tpgi.com.au>
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    Message-ID: <366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    
    On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    > Peng Yu wrote:
    >>
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> My thought is that if I put the test in g(x), the code of g(x) is
    >> safer, but the test is not necessary when g() is called by h().
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    >
    > Typically, you test for x as early as possible, e.g. just after user input
    > (or file or url load or whatever). After that test, you can (or should be
    > able to) assume that all function calls will always be called with the
    > correct argument. This is the ideal situation, it's not always easy to do.
    >
    > In any case though, don't optimize early.
    
    Let's suppose that g() is refactored out from f() and is call by not
    only f() but other functions, and g() is likely to be called by new
    functions.
    
    If I don't optimize early, I should put the test in g(), rather than f(), right?
    
    
    From andyjian430074 at gmail.com  Tue Nov 24 00:09:36 2009
    From: andyjian430074 at gmail.com (Jankins)
    Date: Mon, 23 Nov 2009 21:09:36 -0800 (PST)
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    	<45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com>
    	
    Message-ID: 
    
    On Nov 23, 8:32?pm, Cousin Stanley  wrote:
    > >> ....
    > >> You misunderstand what "flush" means. It is not about
    > >> clearing the screen, or the line.
    >
    > >> Try printing
    >
    > >> ? ?stdout.write('\r-->%d')
    >
    > >> Diez
    >
    > > But there is still a problem. When you use control character '\r',
    > > you actually move to the head of the current buffer line and
    > > overwrite it.
    >
    > > So if I use this way:
    > > for i in range(100, 0,-1)
    >
    > > The tail of the buffer is not overwrote.
    > > ....
    >
    > ? The following version works ok for me
    > ? using python2.5 under debian linux ....
    >
    > import sys
    > import time
    >
    > print
    >
    > for n in range( 11 ) :
    > ? ? sys.stdout.write( '\r ? ?Working ----> %d ' % n )
    > ? ? sys.stdout.flush()
    > ? ? time.sleep( 1 )
    >
    > else :
    > ? ? print "\n"
    > ? ? print " ? ?That's all, folks !"
    > ? ? print " ? ?Adios ........... "
    >
    > --
    > Stanley C. Kitching
    > Human Being
    > Phoenix, Arizona
    
    Thanks. It works. Put some space at the end of the output string.
    
    
    From andyjian430074 at gmail.com  Tue Nov 24 00:11:04 2009
    From: andyjian430074 at gmail.com (Jankins)
    Date: Mon, 23 Nov 2009 21:11:04 -0800 (PST)
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    	<45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com>
    	
    Message-ID: <22e5bc5f-0dc4-4334-9446-5a60c1ba9ed4@g1g2000vbr.googlegroups.com>
    
    On Nov 23, 8:54?pm, Dave Angel  wrote:
    > Jankins wrote:
    > > On Nov 23, 4:08 pm, "Diez B. Roggisch"  wrote:
    >
    > >> Jankins schrieb:
    >
    > >>> I am trying to use sys.stdout to print out "process-bar" like:
    > >>> -->1%
    >
    > >>> Here is my program ?test.py?:
    >
    > >>> from sys import stdout
    > >>> for v in range(10):
    > >>> ? ? stdout.write('-->%d' % v)
    > >>> ? ? stdout.flush()
    > >>> else:
    > >>> ? ? stdout.write('done!')
    > >>> #end for
    >
    > >>> Then, I use 'python -u test.py' to run this script. But what I get
    > >>> is :
    > >>> -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done!
    >
    > >>> I am suppose to get 'done!'.
    >
    > >>> Can anybody help me about this?
    >
    > >> You misunderstand what "flush" means. It is not about clearing the
    > >> screen, or the line.
    >
    > >> Try printing
    >
    > >> ? ?stdout.write('\r-->%d')
    >
    > >> Diez
    >
    > > But there is still a problem. When you use control character '\r', you
    > > actually move to the head of the current buffer line and overwrite it.
    > > So if I use this way:
    > > for i in range(100, 0,-1)
    >
    > > The tail of the buffer is not overwrote.
    >
    > > How to solve this problem?
    >
    > > Thanks.
    >
    > No idea what you mean by "buffer line." ?This is moving the cursor
    > around on the console.
    >
    > Anyway, for such a loop, just make sure all the strings are the same
    > length. ?Or just cheat and always write a few blanks at the end.
    >
    > ? ? ? ?sys.stdout.write("\r -- %5d" % i)
    >
    > should do it, for up to 5 digit values
    >
    > DaveA
    
    '%5d' is elegant. I prefer adding some space at the end of the output
    string.
    Thanks.
    
    
    From sean_mcilroy at yahoo.com  Tue Nov 24 00:15:52 2009
    From: sean_mcilroy at yahoo.com (Sean McIlroy)
    Date: Mon, 23 Nov 2009 21:15:52 -0800 (PST)
    Subject: midi file parser
    Message-ID: 
    
    
    """
    
    A Sequence is a list [FormatType, TimeDivision, Tracks] where
    
    *) FormatType is in [0,1,2]
    *) TimeDivision is either [TicksPerBeat] with TicksPerBeat in range
    (2**15) or
       [FramesPerSecond, TicksPerFrame] with FramesPerSecond in range
    (2**7)
       and TicksPerFrame in range(2**8)
    *) Tracks is a list of Events
    
    An Event is either a ChannelEvent or a MetaEvent.
    A ChannelEvent is  [DeltaTime, EventType, Channel, Parameters]
    and a MetaEvent is [DeltaTime, MetaType, Message] where
    
    *) DeltaTime  is a nonnegative integer
    *) EventType  is in range(7)
    *) Channel    is in range(2**4)
    *) Parameters is a list with elements in range(2**7)
    *) MetaType   is in range(2**7)
    *) Message    is a string
    
    The EventTypes and Parameters of ChannelEvents have the following
    verbal handles:
    
    EventType                        Parameters
    
    0 = NoteOff                      [NoteNumber, Velocity]
    1 = NoteOn                       [NoteNumber, Velocity]
    2 = NoteAftertouch               [NoteNumber, Amount]
    3 = Controller                   [ControllerType, Value]
    4 = ProgramChange                [ProgramNumber]
    5 = ChannelAftertouch            [Amount]
    6 = PitchBend                    [ValueLSB, ValueMSB]
    
    """
    
    def concat(xs):
        from itertools import chain
        return list(chain(*xs))
    
    def zeropadded(digits,minlength):
        return [0]*(minlength-len(digits)) + digits
    
    def noleadingzeros(digits):
        while digits[0]==0 and len(digits)>1: digits = digits[1:]
        return digits
    
    def number2digits(number,base):
        digits = [number]
        while digits[0]>=base: digits[0:1] = [digits[0]//base, digits
    [0]%base]
        return digits
    
    def digits2number(digits,base):
        reversedigits = reversed(noleadingzeros(digits))
        basepowers = [base**n for n in range(len(digits))]
        return sum([x*y for (x,y) in zip(reversedigits,basepowers)])
    
    def number2fixedlength(number,length):
        return zeropadded(number2digits(number,2**8),length)
    
    def fixedlength2number(digits):
        return digits2number(digits,2**8)
    
    def number2variablelength(number):
        digits = number2digits(number,2**7)
        padding = [2**7]*(len(digits)-1) + [0]
        return [x+y for (x,y) in zip(digits,padding)]
    
    def variablelength2number(variablelength):
        padding = [2**7]*(len(variablelength)-1) + [0]
        digits = [x-y for (x,y) in zip(variablelength,padding)]
        return digits2number(digits,2**7)
    
    def smallbyte(number):
        return number < (2**7)
    
    def getfixedlength(numbers,startindex,numbytes):
        endindex = startindex + numbytes
        return (endindex, numbers[startindex:endindex])
    
    def getvariablelength(numbers,startindex):
        index = startindex
        while not smallbyte(numbers[index]): index = index + 1
        endindex = index + 1
        return (endindex, numbers[startindex:endindex])
    
    def analyzetimedivision(numbers):
        [byte1, byte2]  = numbers
        indicator  = byte1 // (2**7)
        firstbyte  = byte1 % (2**7)
        secondbyte = byte2
        if indicator==0:
            ticksperbeat = (2**8) * firstbyte + secondbyte
            return [ticksperbeat]
        if indicator==1:
            framespersecond = firstbyte
            ticksperframe   = secondbyte
            return [framespersecond, ticksperframe]
    
    def synthesizetimedivision(numbers):
        if len(numbers)==1:
            [ticksperbeat] = numbers
            firstbyte  = ticksperbeat // (2**8)
            secondbyte = ticksperbeat  % (2**8)
            indicator = 0
        if len(numbers)==2:
            [framespersecond, ticksperframe] = numbers
            firstbyte  = framespersecond
            secondbyte = ticksperframe
            indicator = 1
        byte1 = indicator * (2**7) + firstbyte
        byte2 = secondbyte
        return [byte1, byte2]
    
    def analyzeheaderdata(numbers):
        formattype   =  fixedlength2number(numbers[0:2])
        numtracks    =  fixedlength2number(numbers[2:4])
        timedivision = analyzetimedivision(numbers[4:6])
        return (formattype, numtracks, timedivision)
    
    def synthesizeheaderdata(formattype,numtracks,timedivision):
        formattype   = number2fixedlength(formattype, 2)
        numtracks    = number2fixedlength(numtracks,  2)
        timedivision = synthesizetimedivision(timedivision)
        return formattype + numtracks + timedivision
    
    def analyzestatus(statusbyte):
        number = statusbyte - (2**7)
        eventtype = number // (2**4)
        channel   = number  % (2**4)
        return (eventtype, channel)
    
    def synthesizestatus(eventtype,channel):
        statusbyte = (2**7) + (2**4) * eventtype + channel
        return [statusbyte]
    
    def synthesizeevent(event):
        if len(event)==4:
            [deltatime, eventtype, channel, parameters] = event
            return number2variablelength(deltatime) + synthesizestatus
    (eventtype,channel) + parameters
        if len(event)==3:
            [deltatime, metatype, message] = event
            quantifiedmessage = number2variablelength(len(message)) + [ord
    (x) for x in message]
            return number2variablelength(deltatime) + synthesizestatus
    (7,15) + [metatype] + quantifiedmessage
    
    def makechunk(identifier,numbers):
        return identifier + number2fixedlength(len(numbers),4) + numbers
    
    def makeheader(formattype,numtracks,timedivision):
        headeridentifier = [77, 84, 104, 100]
        return makechunk(headeridentifier,synthesizeheaderdata
    (formattype,numtracks,timedivision))
    
    def maketrack(events):
        trackidentifier  = [77, 84, 114, 107]
        return makechunk(trackidentifier,concat([synthesizeevent(x) for x
    in events]))
    
    def getchunks(numbers):
        numbytes = len(numbers)
        index = 0
        chunks = []
        while index < numbytes:
            i = index + 4
            j = index + 8
            k = j + fixedlength2number(numbers[i:j])
            index = k
            chunks.append(numbers[j:k])
        return chunks
    
    def getevent(numbers,startindex,runningstatus):
        (i, deltatime)       = getvariablelength(numbers,startindex)
        deltatime            = variablelength2number(deltatime)
        (j, status)          = smallbyte(numbers[i]) and (i, []) or (i+1,
    [numbers[i]])
        nextrunningstatus    = status or runningstatus
        (eventtype, channel) = analyzestatus(nextrunningstatus[0])
        if not eventtype==7:
            numparameters                = eventtype in [4,5] and 1 or 2
            (nextstartindex, parameters) = getfixedlength
    (numbers,j,numparameters)
            event                        = [deltatime, eventtype, channel,
    parameters]
        if eventtype==7 and channel==15:
            (k, metatype)             = (j+1, numbers[j])
            (m, messagelength)        = getvariablelength(numbers,k)
            (nextstartindex, message) = getfixedlength
    (numbers,m,variablelength2number(messagelength))
            message                   = ''.join([chr(x) for x in message])
            event                     = [deltatime, metatype, message]
        if eventtype==7 and not channel==15:
            (k, messagelength)        = getvariablelength(numbers,j)
            (nextstartindex, message) = getfixedlength
    (numbers,k,variablelength2number(messagelength))
            event                     = None
        return (nextstartindex, nextrunningstatus, event)
    
    def getevents(numbers):
        numbytes = len(numbers)
        index = 0
        runningstatus = []
        events = []
        while index < numbytes:
            (nextindex, nextrunningstatus, event) = getevent
    (numbers,index,runningstatus)
            index = nextindex
            runningstatus = nextrunningstatus
            if not event==None: events.append(event)
        return events
    
    def parse(filedata):
        numbers = list(filedata)
        chunks = getchunks(numbers)
        (formattype, numtracks, timedivision) = analyzeheaderdata(chunks
    [0])
        tracks = [getevents(x) for x in chunks[1:]]
        return [formattype, timedivision, tracks]
    
    def unparse(sequence):
        [formattype, timedivision, tracks] = sequence
        numtracks = len(tracks)
        header = makeheader(formattype,numtracks,timedivision)
        numbers = header + concat([maketrack(x) for x in tracks])
        return bytes(numbers)
    
    ########################################
    ## from midiparser import parse, unparse
    
    def readmidi(filepath):
        return parse(open(filepath,'rb').read())
    
    def writemidi(sequence,filepath):
        open(filepath,'wb').write(unparse(sequence))
    
    def replace(replacee,replacer,string):
        return replacer.join(string.split(replacee))
    
    def notename(notenumber):
        names = ('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')
        return names[notenumber % 12] + '-' + str(notenumber // 12)
    
    def gettrackname(track):
        names = [event[2] for event in track if len(event)==3 and event[1]
    ==3]
        return names and numbers2string(names[0]) or None
    
    def noteevent(event):
        return len(event)==4 and event[1] in range(3)
    
    def switchevent(event):
        return len(event)==4 and event[1] in range(2)
    
    def firstnoteindices(track):
        for i in range(len(track)):
            if noteevent(track[i]): return [i]
        return []
    
    def lastnoteindices(track):
        for i in reversed(range(len(track))):
            if noteevent(track[i]): return [i]
        return []
    
    def explodefile(filepath,directorypath):
        [formattype, timedivision, tracks] = readmidi(filepath)
        index = formattype==1 and not firstnoteindices(tracks[0]) and 1 or
    0
        temposettings, tracks = tracks[:index], tracks[index:]
        for i in range(len(tracks)):
            trackname = gettrackname(tracks[i]) or ('track_' + str(i))
            rewrite = lambda basename: basename + '_' + replace('/', '_',
    trackname)
            singletrackfilepath = changefilepath
    (filepath,directorypath,rewrite)
            singletrackfile = (formattype, timedivision, temposettings +
    [tracks[i]])
            writemidi(singletrackfile,singletrackfilepath)
    
    def reflectpitch(event):
        if not noteevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        newparameters = [(2**7)-notenumber, velocity]
        return [deltatime, eventtype, channel, newparameters]
    
    def translatepitch(event,deltapitch):
        if not noteevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        newnotenumber = notenumber + deltapitch
        assert newnotenumber in range(2**7)
        newparameters = [newnotenumber, velocity]
        return [deltatime, eventtype, channel, newparameters]
    
    def switch(event):
        noteoff, noteon = range(2)
        if not switchevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        neweventtype = noteon
        newvelocity = (eventtype==noteoff or velocity==0) and (2**6) or 0
        newparameters = [notenumber, newvelocity]
        return [deltatime, neweventtype, channel, newparameters]
    
    def invert(track):
        return [reflectpitch(x) for x in track]
    
    def transpose(track,deltapitch):
        return [translatepitch(x,deltapitch) for x in track]
    
    def retrograde(track):
        prefixindex = firstnoteindices(track)[0]
        suffixindex = lastnoteindices(track)[0] + 1
        prefix, noteevents, suffix = track[:prefixindex], track
    [prefixindex: suffixindex], track[suffixindex:]
        newnoteevents = [switch(event) for event in reversed(noteevents)]
        nextdeltatime = noteevents[-1][0]
        for i in range(len(newnoteevents)):
            [deltatime, eventtype, channel, parameters] = newnoteevents[i]
            newnoteevents[i] = [nextdeltatime, eventtype, channel,
    parameters]
            nextdeltatime = deltatime
        return prefix + newnoteevents + suffix
    
    def sequences(length,elements):
        if length==0: return [[]]
        return [[x] + ys for x in elements for ys in sequences
    (length-1,elements)]
    
    def toggle(notenumber):
        on  = [0,   1, 0, [notenumber, (2**7)-1]]
        off = [300, 0, 0, [notenumber, 0]]
        return [on, off]
    
    def eartrainer(notenumbers):
        from functools import reduce
        endoftrack = [0, 47, []]
        track = reduce(lambda x,y: x+y, [toggle(x) for x in notenumbers])
    + [endoftrack]
        return [0, [120], [track]]
    
    def makeflashcards(length,lowest,highest):
        from os import mkdir
        from random import shuffle
        mkdir('questions')
        mkdir('answers')
        notesequences = sequences(length, range(lowest, highest + 1))
        shuffle(notesequences)
        for i in range(len(notesequences)):
            writemidi(eartrainer(notesequences[i]), 'questions/sequence_'
    + str(i) + '.mid')
            open('answers/sequence_' + str(i) + '.txt','w').write(' '.join
    ([notename(x) for x in notesequences[i]]))
    
    def noemptytracks(mididata):
        [formattype, timedivision, tracks] = mididata
        index = (formattype==1 and not firstnoteindices(tracks[0])) and 1
    or 0
        temposettings, tracks = tracks[:index], tracks[index:]
        newtracks = temposettings + [track for track in tracks if
    firstnoteindices(track)]
        return [formattype, timedivision, newtracks]
    
    def nocountin(mididata):
        [formattype, timedivision, tracks] = mididata
        TrackEventOldTime = [(i,j,tracks[i][j][0]) for i in range(len
    (tracks)) for j in firstnoteindices(tracks[i])]
        starttime = min([t for (i,j,t) in TrackEventOldTime])
        TrackEventNewTime = [(i,j,t-starttime) for (i,j,t) in
    TrackEventOldTime]
        newtracks = tracks[:]
        for (i,j,t) in TrackEventNewTime: newtracks[i][j][0] = t
        return [formattype, timedivision, newtracks]
    
    def processfiles(directorypath,function):
        from os import listdir, mkdir
        filenames = listdir(directorypath)
        subdirectorypath = directorypath + '/preprocessed'
        mkdir(subdirectorypath)
        for filename in filenames:
            oldfilepath = directorypath    + '/' + filename
            newfilepath = subdirectorypath + '/' + filename
            writemidi(function(readmidi(oldfilepath)),newfilepath)
    
    
    
    
    
    
    From gherron at islandtraining.com  Tue Nov 24 00:23:41 2009
    From: gherron at islandtraining.com (Gary Herron)
    Date: Mon, 23 Nov 2009 21:23:41 -0800
    Subject: Line Breaks
    In-Reply-To: 
    References: 	<4B0AE1EE.5070705@islandtraining.com>
    	
    Message-ID: <4B0B6DDD.3000301@islandtraining.com>
    
    Susan Day wrote:
    > On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron 
    > > wrote:
    >
    >     >>> print 'A Message From %s:\n\n %s' % ('someone','some message')
    >     A Message From someone:
    >
    >     some message
    >
    >
    >     So...  *Exactly* what are you doing with msg, and *exactly* what
    >     is your evidence that line breaks are being ignored.  With that
    >     information, perhaps we can identify and solve the real problem
    >     you're having.
    >
    >
    > First, it does in fact ignore all line breaks, not just double line 
    > breaks.
    > Here's what I'm doing:
    > session.sendmail(clientEmail, ourEmail2, header+msg)
    > The email sent out has the message sans breaks.
    > TIA,
    > Suzie
    
    
    You say "it does in fact ignore all line breaks", but which "IT" are you 
    talking about.  The line of code you originally showed us
            msg = 'A Message From %s:\n\n %s' % (string.replace(customer, 
    '_', ' '), msg)
    in fact does NOT ignore line breaks, and I demonstrated that to you.    
    Your problem is somewhere else. 
    
    Now you've shown us one more line of code.  But why only one?   Why make 
    it so hard for us to help you?   I for one will consider volunteering 
    more time on this problem only if I get a small, complete program, which 
    demonstrates the problem, and which I can cut and paste.
    
    Gary Herron
    
    
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:02:15 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:02:15 +0000
    Subject: Relative versus absolute paths on Windows
    References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com>
    	<7mos8lF3is0n7U1@mid.individual.net>
    	
    Message-ID: 
    
    On Tue, 24 Nov 2009 02:23:19 +0100, Christian Heimes wrote:
    
    > Gregory Ewing wrote:
    >>>>>> ntpath.join('d:\\foo', '\\bar')
    >>> '\\bar'
    >> 
    >> This does seem like a bug, though -- the correct result
    >> should really be 'd:\\bar', since that's what you would
    >> get if you used the name '\\bar' with 'd:' as your current
    >> drive.
    > 
    > No, it's not a bug. Since \bar is an absolute path, all path segments
    > before the absolute path are ignored.
    
    Except that a path without a drive letter *isn't* an absolute path in
    any meaningful sense. The fact that os.path.isabs() disagrees is a defect
    in os.path.isabs() (I won't call it a bug, as it's documented as behaving
    that way).
    
    The upshot is that the standard library is missing important functionality
    on Windows, i.e. testing whether a path is absolute, and resolving a
    relative path relative to an absolute path.
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:15:18 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:15:18 +0000
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    Message-ID: 
    
    On Mon, 23 Nov 2009 22:06:29 +0100, Alf P. Steinbach wrote:
    
    > 10. It says UnicodeDecodeError on mail nr. something something.
    
    That's what you get for using Python 3.x ;)
    
    If you must use 3.x, don't use the standard descriptors. If you must use
    the standard descriptors in 3.x, call detach() on them to get the
    underlying binary stream, i.e.
    
    	stdin = sys.stdin.detach()
    	stdout = sys.stdout.detach()
    
    and use those instead.
    
    Or set LC_ALL or LC_CTYPE to an ISO-8859-* locale (any stream of bytes can
    be decoded, and any string resulting from decoding can be encoded).
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:19:00 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:19:00 +0000
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    Message-ID: 
    
    On Mon, 23 Nov 2009 23:08:25 +0100, Diez B. Roggisch wrote:
    
    > Try printing
    > 
    >    stdout.write('\r-->%d')
    
    ^M-->0^M-->1^M-->2^M-->3... ;)
    
    But it's probably good enough for the OP's purposes.
    
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 01:23:53 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 06:23:53 +0000 (UTC)
    Subject: Any elegant way to construct the complete $k$-partite graph in 
    	Python?
    References: 
    	
    	
    	
    	<45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com>
    Message-ID: 
    
    On Mon, 23 Nov 2009 19:57:05 -0800, Richard Thomas wrote:
    
    > Not sure exactly how you're representing graphs, this seems like the
    > simplest way of listing the edges.
    > 
    > def complete_partite(*sizes):
    >     total = sum(sizes)
    >     nodes, edges = range(total), []
    >     for group in xrange(len(sizes)):
    >         low = sum(sizes[:group-1])
    >         high = sum(sizes[:group])
    >         edges.extend((i, j) for i in xrange(low, high)
    >                             for j in xrange(high, total))
    >     return nodes, edges
    
    Thanks!  I think this is what I was looking for (unless the collective 
    wisdom of c.l.py can come up with something *even more* elegant). :-)
    
    
    From wuwei23 at gmail.com  Tue Nov 24 01:27:24 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Mon, 23 Nov 2009 22:27:24 -0800 (PST)
    Subject: Where to put the error handing test?
    References: 
    Message-ID: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    
    On Nov 24, 1:15?pm, Peng Yu  wrote:
    > Suppose that I have function f() that calls g(), I can put a test on
    > the argument 'x' in either g() or f(). I'm wondering what is the
    > common practice.
    >
    > If I put the test in f(), then g() becomes more efficient when other
    > code call g() and guarantee x will pass the test even though the test
    > code in not in g(). But there might be some caller of g() that pass an
    > 'x' that might not pass the test, if there were the test in g().
    
    What you should try to do is make each function as self-contained as
    possible. f() shouldn't have to know what is a valid argument for g(),
    that's the responsibility of g(). What f() needs to know is how to
    deal with any problems that arise while using g().
    
    As a very rough example:
    
        def g(x):
            try:
                assert isinstance(x, int)
            except AssertionError:
                raise TypeError, "excepted int, got %s" % type(x)
            # ... function code goes here
    
        def f(x):
            try:
                g(x)
            except TypeError:
                # handle the problem here
            # ... function code goes here
    
    > My thought is that if I put the test in g(x), the code of g(x) is
    > safer, but the test is not necessary when g() is called by h().
    
    This sounds strange to me. Are you stating that h() can pass values to
    g() that would be illegal for f() to pass? That sounds like a very
    dangerous design...you want each function's behaviour to be as
    consistent and predictable as it possibly can.
    
    
    From wuwei23 at gmail.com  Tue Nov 24 01:28:39 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Mon, 23 Nov 2009 22:28:39 -0800 (PST)
    Subject: midi file parser
    References: 
    Message-ID: <21e09eb7-06a0-47c7-9049-4630cc3d7243@13g2000prl.googlegroups.com>
    
    On Nov 24, 3:15?pm, Sean McIlroy  wrote:
    > [code snipped]
    
    Great stuff. Have you considered bundling it up and putting it onto
    PyPI?
    
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 01:49:26 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 06:49:26 +0000 (UTC)
    Subject: adding a directory to sys.path
    References: 
    Message-ID: 
    
    On Mon, 23 Nov 2009 12:02:36 -0500, John Guenther wrote:
    
    > This is Mac related. I am running snow leopard. I am using Python 2.6.3.
    > 
    > I had a lot of difficulty figuring out how to add a directory to
    > sys.path that would be there every time I launched Idle.
    [...]
    
    For a comprehensive discussion of how to modify sys.path, see 
    
    http://docs.python.org/install/index.html#modifying-python-s-search-path
    
    If you really just need to modify sys.path for one particular user, what 
    I would do is add the line
    
    export PYTHONSTARTUP="/home/my_user/python/startup.py"
    
    to my .bashrc.  Then, in the file /home/my_user/python/startup.py, 
    include the following code:
    
    import sys
    
    sys.path.append ("/home/my_user/some_dir")
    
    This will add the directory /home/my_user/some_dir to sys.path every time 
    you start up Python.  
    
    The reason I like using PYTHONSTARTUP is that you can do other sorts of 
    customizations in that file, as well.  For example, I hate not having any 
    way to clear the screen when I'm typing at the Python prompt, so I added 
    this code to my $PYTHONSTARTUP file:
    
    import os
    
    def clear():
        os.system ('clear')
    
    Hope that all helps!
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Tue Nov 24 03:02:22 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 09:02:22 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 
    Message-ID: <4b0b92de$0$14677$426a74cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > The problem I have with properties is my typing.  I'll end up assigning 
    > to an attribute, but get the spelling slightly wrong (capitalized, or 
    > missing an underscore -- non-obvious things when bug-hunting), so now I 
    > have an extra attribute which of course has zero effect on what I'm 
    > trying to do and I start getting wierd results like viewing deleted 
    > records when I *know* I set useDeleted = False... 30 minutes later I 
    > notice it was /supposed/ to be use_deleted.  *sigh*
    > 
    > So -- to keep myself out of trouble -- I have started coding such things 
    > as, for example:
    > 
    > result = table.use_deleted()       # returns True or False
    > table.use_deleted(False)           # skip deleted records
    > 
    > instead of
    > 
    > result = table.use_deleted
    > table.use_deleted = False
    > 
    > My question:  is this [ severely | mildly | not at all ] un-pythonic?
    
    Definitly and totally unpythonic. The first solution to your problem is 
    to stick to standard naming conventions. If this is not enough, Chris 
    pointed you to really useful tools. Also, you can override __setattr__ 
    to catch such errors - at least during the coding/debug phase.
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Tue Nov 24 03:11:24 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 09:11:24 +0100
    Subject: Where to put the error handing test?
    In-Reply-To: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: <4b0b94fd$0$2717$426a74cc@news.free.fr>
    
    alex23 a ?crit :
    > On Nov 24, 1:15 pm, Peng Yu  wrote:
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    > 
    > What you should try to do is make each function as self-contained as
    > possible. f() shouldn't have to know what is a valid argument for g(),
    > that's the responsibility of g(). 
    
    There's no such clear-cut IMHO - it really depends on the context. If f 
    is a user-interface function - a function that deals with user inputs in 
    whatever form - and g is a domain-specific library function, then it's 
    f's responsability to validate user inputs before calling on g (_and_ of 
    course to deal with any exception raised withing g).
    
    As a general rule, "defensive code" should go at the interface level - 
    program's inputs of course, but also, sometimes, at "sub-systems" 
    boundaries.
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 04:31:28 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 09:31:28 +0000 (UTC)
    Subject: Where to put the error handing test?
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: 
    
    On Mon, 23 Nov 2009 22:27:24 -0800, alex23 wrote:
    
    > As a very rough example:
    > 
    >     def g(x):
    >         try:
    >             assert isinstance(x, int)
    >         except AssertionError:
    >             raise TypeError, "excepted int, got %s" % type(x)
    >         # ... function code goes here
    > 
    >     def f(x):
    >         try:
    >             g(x)
    >         except TypeError:
    >             # handle the problem here
    >         # ... function code goes here
    
    I know you say this is a "very rough" example, but, generally you don't 
    want to do this kind of "type checking" with isinstance.  Rather, it's 
    better to just simply manipulate x as if it were an integer and rely on 
    Python to check to see if x supports the operations you're trying to do 
    with it.  For instance, say we have
    
    def g(x):
        return x * x
    
    def f(x):
        return g(x) + 2
    
    If you try to pass any value to either of these functions that doesn't 
    support the required operations, Python itself will complain with a 
    TypeError.  Since the interpreter needs to do this check *anyway*, 
    there's no real sense in repeating it manually by checking isinstance.
    
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 05:53:30 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 02:53:30 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    Message-ID: <9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    
    On 22 Nov, 22:38, Patrick Stinson 
    wrote:
    
    > Has anyone every tried wrapping the CPython lib into a daemon with an
    > RPC mechanism in order to move the GIL out of the process?
    
    > I imagine this is how the multiprocessing module works.
    
    It does not.
    
    
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 05:58:35 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 02:58:35 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> 
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de> 
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	
    Message-ID: 
    
    On 23 Nov, 22:02, Patrick Stinson 
    wrote:
    
    > What I meant was that I am *not allowed* to make calls to the CPython
    > API from the threads I currently have because these threads are high
    > priority and are never allowed to make blocking calls. Fortunately,
    > each of these threads can have a completely separate interpreter,
    
    This seems confused. What would they do with the interpreter if they
    cannot call the CPython API?
    
    
    > My question was whether or not anyone has done anything like this in
    > C/C++.
    
    I have programmed parallel numerical software in Python, including on-
    line signal processing. I have yet to find the GIL gets in my way.
    
    Usually people complaining about the GIL does not know what they are
    talking about.
    
    
    
    
    
    From davea at ieee.org  Tue Nov 24 05:58:42 2009
    From: davea at ieee.org (Dave Angel)
    Date: Tue, 24 Nov 2009 05:58:42 -0500
    Subject: Where to put the error handing test?
    In-Reply-To: <366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    References: 	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    Message-ID: <4B0BBC62.7020702@ieee.org>
    
    Peng Yu wrote:
    > On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    >   
    >> Peng Yu wrote:
    >>     
    >>> Suppose that I have function f() that calls g(), I can put a test on
    >>> the argument 'x' in either g() or f(). I'm wondering what is the
    >>> common practice.
    >>>
    >>> My thought is that if I put the test in g(x), the code of g(x) is
    >>> safer, but the test is not necessary when g() is called by h().
    >>>
    >>> If I put the test in f(), then g() becomes more efficient when other
    >>> code call g() and guarantee x will pass the test even though the test
    >>> code in not in g(). But there might be some caller of g() that pass an
    >>> 'x' that might not pass the test, if there were the test in g().
    >>>       
    >> Typically, you test for x as early as possible, e.g. just after user input
    >> (or file or url load or whatever). After that test, you can (or should be
    >> able to) assume that all function calls will always be called with the
    >> correct argument. This is the ideal situation, it's not always easy to do.
    >>
    >> In any case though, don't optimize early.
    >>     
    >
    > Let's suppose that g() is refactored out from f() and is call by not
    > only f() but other functions, and g() is likely to be called by new
    > functions.
    >
    > If I don't optimize early, I should put the test in g(), rather than f(), right?
    >
    >   
    Your question is so open-ended as to be unanswerable.  All we should do 
    in this case is supply some guidelines so you can guess which one might 
    apply in your particular case.
    
    You could be referring to a test that triggers alternate handling.  Or 
    you could be referring to a test that notices bad input by a user, or 
    bad data from an untrusted source.  Or you could be referring to a test 
    that discovers bugs in your code.  And there are variations of these, 
    depending on whether your user is also writing code (eval, or even 
    import of user-supplied mixins), etc.
    
    The first thing that's needed in the function g() is a docstring, 
    defining what inputs it expects, and what it'll do with them.  Then if 
    it gets any input that doesn't meet those requirements, it might throw 
    an exception.  Or it might just get an arbitrary result.  That's all up 
    to the docstring.  Without any documentation, nothing is correct.
    
    Functions that are only called by trusted code need not have explicit 
    tests on their inputs, since you're writing it all.  Part of debugging 
    is catching those cases where f () can pass bad data to g().  If it's 
    caused because bad data is passed to f(), then you have a bug in that 
    caller.  Eventually, you get to the user.  If the bad data comes from 
    the user, it should be caught as soon as possible, and feedback supplied 
    right then.
    
    assert() ought to be the correct way to add tests in g() that test 
    whether there's such a bug in f().  Unfortunately, in CPython it 
    defaults to debug mode, so scripts that are run will execute those tests 
    by default.  Consequently, people leave them out, to avoid slowing down 
    code.
    
    
    
    It comes down to trust.  If you throw the code together without a test 
    suite, you'll be a long time finding all the bugs in non-trivial code.  
    So add lots of defensive tests throughout the code, and pretend that's 
    equivalent to a good test system.  If you're writing a library to be 
    used by others, then define your public interfaces with exceptions for 
    any invalid code, and write careful documentation describing what's 
    invalid.  And if you're writing an end-user application, test their 
    input as soon as you get it, so none of the rest of the application ever 
    gets "invalid" data.
    
    
    DaveA
    
    
    From fetchinson at googlemail.com  Tue Nov 24 06:15:39 2009
    From: fetchinson at googlemail.com (Daniel Fetchinson)
    Date: Tue, 24 Nov 2009 12:15:39 +0100
    Subject: xmlrpc idea for getting around the GIL
    In-Reply-To: <6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com>
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com>
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de>
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	<6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com>
    Message-ID: 
    
    >> icating) the multiprocessing module would be ideal.
    >>> > The problem is that the OP has a embedded application running threads.
    >>> > multiprocssing doesn't help there.
    >>>
    >>> that's right. I cannot make CPython calls from my original C-based
    >>> threads.
    >>
    >>
    >> It's quite possible to do that.  A thread started from C can make
    >> calls to Python if it first calls PyGILState_Ensure, although you'd
    >> have to make sure that the Python interpreter has been previously
    >> initialized.  See PEP 311 for details.
    >>
    >> http://www.python.org/dev/peps/pep-0311/
    >>
    >> I also suggest that if you want people to be more receptive to write
    >> your replies after the quoted text.  That is the custom in this
    >> newsgroup/mailing list.
    >>
    >
    > What I meant was that I am *not allowed* to make calls to the CPython
    > API from the threads I currently have because these threads are high
    > priority and are never allowed to make blocking calls. Fortunately,
    > each of these threads can have a completely separate interpreter, so
    > my idea was to create a daemon process for each thread. This daemon
    > would contain the libpython symbols and would make the CPython calls.
    > This would keep my current threads from having to contend over the
    > single GIL.
    >
    > My question was whether or not anyone has done anything like this in
    > C/C++. This situation is slightly unique in that I am trying to
    > maintain separate interpreters within a single app (which is currently
    > kind of hacked out using a single interpreter, but it's ugly), but I
    > could see how this sort of thing would be useful for other C/C++ apps
    > that implement an embedded scripting engine.
    >
    > My reference to multiprocessing was based on the idea that the library
    > hides the details fo the process management, shared memory, and rpc
    > mechanisms. Again, I can't use multiprocessing because it runs *in*
    > python I need this to be implemented *outside* of python to avoid
    > acquiring the GIL. complex, I know.
    >
    > Naturally, the most intimidating part of perusing this kind of idea is
    > the overhead of the processess management and the RPC. Further,
    > libpython executes callable objects using C function pointers, and I
    > can't think of a way that this would be able to re-gain access to the
    > original app's respective functions if the interpreter was living in
    > another processes.
    >
    > That's not to mention the impossibility of debugging.
    >
    > Damn you, Gil.
    
    
    By the way, you might be interested in this thread as well:
    
    http://groups.google.com/group/comp.lang.python/browse_thread/thread/2d537ad8df9dab67/cc4cb2b493c98170
    
    HTH,
    Daniel
    
    
    -- 
    Psss, psss, put it down! - http://www.cafepress.com/putitdown
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 06:29:29 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 03:29:29 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> 
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de> 
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	<6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com> 
    	
    Message-ID: <261ce8df-e152-4c1a-9da9-0994962da496@p36g2000vbn.googlegroups.com>
    
    On 24 Nov, 12:15, Daniel Fetchinson  wrote:
    
    > By the way, you might be interested in this thread as well:
    >
    > http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
    
    It is Windows specific, and it does not work with extension modules.
    
    Yes we can embed multiple interpreters just by making multiple copies
    of Python26.dll. It's an ugly hack and not one I'd recommend for
    production servers.
    
    
    
    
    From mrkafk at gmail.com  Tue Nov 24 07:03:44 2009
    From: mrkafk at gmail.com (mk)
    Date: Tue, 24 Nov 2009 13:03:44 +0100
    Subject: pointless musings on performance
    Message-ID: 
    
    #!/usr/local/bin/python
    
    import timeit
    
    
    def pythonic():
         nonevar = None
         zerovar = 0
         for x in range(1000000):
             if nonevar:
                 pass
             if zerovar:
                 pass
    
    def unpythonic():
         nonevar = None
         zerovar = 0
         for x in range(1000000):
             if nonevar is not None:
                 pass
             if zerovar > 0:
                 pass
    
    for f in [pythonic, unpythonic]:
         print f.func_name, timeit.timeit(f, number=10)
    
    
    
    # ./t.py
    pythonic 2.13092803955
    unpythonic 2.82064604759
    
    Decidedly counterintuitive: are there special optimizations for "if 
    nonevar:" type of statements in cpython implementation?
    
    
    regards,
    mk
    
    
    
    
    From python at mrabarnett.plus.com  Tue Nov 24 07:26:12 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Tue, 24 Nov 2009 12:26:12 +0000
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    Message-ID: <4B0BD0E4.8030707@mrabarnett.plus.com>
    
    mk wrote:
    > #!/usr/local/bin/python
    > 
    > import timeit
    > 
    > 
    > def pythonic():
    >     nonevar = None
    >     zerovar = 0
    >     for x in range(1000000):
    >         if nonevar:
    >             pass
    >         if zerovar:
    >             pass
    > 
    > def unpythonic():
    >     nonevar = None
    >     zerovar = 0
    >     for x in range(1000000):
    >         if nonevar is not None:
    >             pass
    >         if zerovar > 0:
    >             pass
    > 
    > for f in [pythonic, unpythonic]:
    >     print f.func_name, timeit.timeit(f, number=10)
    > 
    > 
    > 
    > # ./t.py
    > pythonic 2.13092803955
    > unpythonic 2.82064604759
    > 
    > Decidedly counterintuitive: are there special optimizations for "if 
    > nonevar:" type of statements in cpython implementation?
    > 
    In what way is it counterintuitive? In 'pythonic' the conditions are
    simpler, less work is being done, therefore it's faster.
    
    
    From rtw at freenet.co.uk  Tue Nov 24 07:31:37 2009
    From: rtw at freenet.co.uk (Rob Williscroft)
    Date: Tue, 24 Nov 2009 06:31:37 -0600
    Subject: pointless musings on performance
    References: 
    Message-ID: 
    
    mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in 
    comp.lang.python:
    
    > 
    > def pythonic():
     
    > def unpythonic():
     
     
    > Decidedly counterintuitive: are there special optimizations for "if 
    > nonevar:" type of statements in cpython implementation?
    > 
    
    from dis import dis
    
    dis( unpythonic )
    
    18          31 LOAD_FAST                0 (nonevar)
                 34 LOAD_CONST               0 (None)
                 37 COMPARE_OP               9 (is not)
                 40 JUMP_IF_FALSE            4 (to 47)
    
    dis( pythonic )
    
    11          31 LOAD_FAST                0 (nonevar)
                 34 JUMP_IF_FALSE            4 (to 41)
     
    Rob.
     
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 07:33:18 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 12:33:18 GMT
    Subject: Where to put the error handing test?
    References: 
    Message-ID: <031bc06f$0$1336$c3e8da3@news.astraweb.com>
    
    On Mon, 23 Nov 2009 21:15:48 -0600, Peng Yu wrote:
    
    > Suppose that I have function f() that calls g(), I can put a test on the
    > argument 'x' in either g() or f(). I'm wondering what is the common
    > practice.
    > 
    > My thought is that if I put the test in g(x), the code of g(x) is safer,
    > but the test is not necessary when g() is called by h().
    
    If the function g requires the test, then put it in g. If it does not 
    require the test, then don't put it in g.
    
    If the test is only required by f, then it belongs in f.
    
    
    
    -- 
    Steven
    
    
    From clp2 at rebertia.com  Tue Nov 24 07:43:50 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 04:43:50 -0800
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    	
    Message-ID: <50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft  wrote:
    > mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in
    > comp.lang.python:
    >
    >>
    >> def pythonic():
    >
    >> def unpythonic():
    >
    >
    >> Decidedly counterintuitive: are there special optimizations for "if
    >> nonevar:" type of statements in cpython implementation?
    >>
    >
    > from dis import dis
    >
    > dis( unpythonic )
    >
    > 18 ? ? ? ? ?31 LOAD_FAST ? ? ? ? ? ? ? ?0 (nonevar)
    > ? ? ? ? ? ? 34 LOAD_CONST ? ? ? ? ? ? ? 0 (None)
    > ? ? ? ? ? ? 37 COMPARE_OP ? ? ? ? ? ? ? 9 (is not)
    > ? ? ? ? ? ? 40 JUMP_IF_FALSE ? ? ? ? ? ?4 (to 47)
    >
    > dis( pythonic )
    >
    > 11 ? ? ? ? ?31 LOAD_FAST ? ? ? ? ? ? ? ?0 (nonevar)
    > ? ? ? ? ? ? 34 JUMP_IF_FALSE ? ? ? ? ? ?4 (to 41)
    
    In other words, CPython doesn't happen to optimize `if nonevar is not
    None` as much as it theoretically could (which would essentially
    require a JUMP_IF_NONE opcode). Since CPython isn't known for doing
    fancy optimizations, this isn't surprising.
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From Ron.Barak at lsi.com  Tue Nov 24 07:59:05 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 12:59:05 +0000
    Subject: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD05@enbmail01.lsi.com>
    
    Hi,
    
    I'm trying to add the logging module to my application, but I seem to be missing something.
    My application (a wxPython one) has a main script that calls various helper classes.
    I want the log messages from all modules to go to one central log file.
    
    When I implement logging, I think that due to preparation, I get the same message more than once.
    
    Here's an example:
    
    $ cat -n server.py
         1  import logging
         2  import logging.handlers
         3
         4  class Server():
         5      def __init__(self):
         6          self.client_logger = logging.getLogger("client")
         7          self.client_logger.setLevel(logging.DEBUG)
         8          h = logging.FileHandler("client.log")
         9          h.setLevel(logging.DEBUG)
        10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        11          h.setFormatter(formatter)
        12          self.client_logger.addHandler(h)
        13
        14      def util(self):
        15          self.client_logger.warning('This message comes from Server module')
    
    $ cat -n client.py
         1  import logging
         2  import logging.handlers
         3  from server import Server
         4
         5  class Client():
         6      def __init__(self):
         7          self.client_logger = logging.getLogger("client")
         8          self.client_logger.setLevel(logging.DEBUG)
         9          h = logging.FileHandler("client.log")
        10          h.setLevel(logging.DEBUG)
        11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        12          h.setFormatter(formatter)
        13          self.client_logger.addHandler(h)
        14
        15      def client_test(self):
        16          self.client_logger.warning("This message comes from Client module")
        17
        18  if __name__ == "__main__":
        19      ser = Server()
        20      cli = Client()
        21      ser.util()
        22      cli.client_test()
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    
    Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    
    Thanks,
    Ron.
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: image001.jpg
    Type: image/jpeg
    Size: 1512 bytes
    Desc: image001.jpg
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: image003.jpg
    Type: image/jpeg
    Size: 1650 bytes
    Desc: image003.jpg
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.log
    Type: application/octet-stream
    Size: 340 bytes
    Desc: client.log
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.py
    Type: application/octet-stream
    Size: 669 bytes
    Desc: client.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: server.py
    Type: application/octet-stream
    Size: 533 bytes
    Desc: server.py
    URL: 
    
    From helmert at informatik.uni-freiburg.de  Tue Nov 24 08:02:04 2009
    From: helmert at informatik.uni-freiburg.de (Malte Helmert)
    Date: Tue, 24 Nov 2009 14:02:04 +0100
    Subject: Any elegant way to construct the complete $k$-partite graph in
    	Python?
    In-Reply-To: 
    References: 				<45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com>
    	
    Message-ID: 
    
    Paul Miller wrote:
    > On Mon, 23 Nov 2009 19:57:05 -0800, Richard Thomas wrote:
    > 
    >> Not sure exactly how you're representing graphs, this seems like the
    >> simplest way of listing the edges.
    >>
    >> def complete_partite(*sizes):
    >>     total = sum(sizes)
    >>     nodes, edges = range(total), []
    >>     for group in xrange(len(sizes)):
    >>         low = sum(sizes[:group-1])
    >>         high = sum(sizes[:group])
    
    I think this has a conceptual off-by-one error. Add
    
               print group, low, high
    
    to see what I mean (especially the first iteration). It still works, but
    I think this would be clearer:
    
               low = sum(sizes[:group])
               high = sum(sizes[:group + 1])
    
    or to avoid doing essentially the same summation twice:
    
               low = sum(sizes[:group])
               high = low + sizes[group]
    
    >>         edges.extend((i, j) for i in xrange(low, high)
    >>                             for j in xrange(high, total))
    >>     return nodes, edges
    
    Here's a variant that uses a running total instead of recomputing the
    sum in every iteration, thus getting rid of xrange(len(...)).
    
    def complete_partite(*sizes):
        total = sum(sizes)
        nodes, edges = range(total), []
        curr_total = 0
        for size in sizes:
            edges.extend((i, j) for i in xrange(curr_total, curr_total+size)
                                for j in xrange(curr_total+size, total))
            curr_total += size
        return nodes, edges
    
    Finally, here is a variant that is a bit shorter because it produces the
    edges in a different way and hence gets rid of the need for knowing the
    total up front and uses total as running total instead. It has the
    drawback of not generating the edges in ascending order though, so I
    think the previous one is nicer:
    
    def complete_partite(*sizes):
        total, edges = 0, []
        for size in sizes:
            edges.extend((i, j) for i in xrange(total)
                                for j in xrange(total, total + size))
            total += size
        return range(total), edges
    
    Finally, here's a variation on the same theme:
    
    def complete_partite(*sizes):
        nodes, edges = [], []
        for size in sizes:
            partition = xrange(len(nodes), len(nodes) + size)
            edges.extend((i, j) for i in nodes for j in partition)
            nodes.extend(partition)
        return nodes, edges
    
    Malte
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 08:02:09 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 13:02:09 GMT
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    Message-ID: <031bc732$0$1336$c3e8da3@news.astraweb.com>
    
    On Mon, 23 Nov 2009 22:06:29 +0100, Alf P. Steinbach wrote:
    
    
    > 6. Googling, yes, it seems Thunderbird has a habit of "forgetting"
    > mails. But they're really there after all. It's just the index that's
    > screwed up.
    [...]
    > And I'm hesitant to just delete index file, hoping that it'll rebuild.
    
    Right-click on the mailbox and choose "Rebuild Index".
    
    If you're particularly paranoid, and you probably should be, make a 
    backup copy of the entire mail folder first.
    
    http://kb.mozillazine.org/Compacting_folders
    http://kb.mozillazine.org/Recover_messages_from_a_corrupt_folder
    http://kb.mozillazine.org/Disappearing_mail
    
    
    Good grief, it's about six weeks away from 2010 and Thunderbird still 
    uses mbox as it's default mail box format. Hello, the nineties called, 
    they want their mail formats back! Are the tbird developers on crack or 
    something? I can't believe that they're still using that crappy format.
    
    No, I tell a lie. I can believe it far too well.
    
    
    
    -- 
    Steven
    
    
    From __peter__ at web.de  Tue Nov 24 08:11:58 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 14:11:58 +0100
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<7n01t8F3jijv0U1@mid.uni-berlin.de>
    	
    	
    	<8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com>
    	
    Message-ID: 
    
    Terry Reedy wrote:
    
    > astral orange wrote:
    > 
    >> As far as the program. I did add print statements such as print
    >> (MyNames) and got back:
    >> 
    >> {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}}
    > 
    > Hmmm, as I understood the code, either that should be ... 'last': {} ...
    > before the first store(), as you seem to be thinking below, or after the
    > first store(),
    > 
    > {'middle': {'Larry': ['John Larry Smith'],
    >   'last':   {'Smith': ['John Larry Smith'],
    >   'first':  {'John' " ['John Larry Smith']}
    > 
    > or the same with [['John','Larry','Smith']] for each entry (do not
    > remember exactly what was stored. Maybe a typo.
    
    That's a bug in the store() function
    
    # as posted
    def store(data, full_name):
        names = full_name.split()
        if len(names) == 2: names.insert(1, '')
        labels = 'first', 'middle', 'last'
        for label, name in zip(labels, names):
            people = lookup(data, label, name)
        if people:
            people.append(full_name)
        else:
            data[label][name] = [full_name]
    
    # what was probably intended
    def store(data, full_name):
        names = full_name.split()
        if len(names) == 2: names.insert(1, '')
        labels = 'first', 'middle', 'last'
        for label, name in zip(labels, names):
            people = lookup(data, label, name)
            if people:
                people.append(full_name)
            else:
                data[label][name] = [full_name]
    
    
    Peter
    
    
    
    From Ron.Barak at lsi.com  Tue Nov 24 08:17:05 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 13:17:05 +0000
    Subject: Recall: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD07@enbmail01.lsi.com>
    
    Barak, Ron would like to recall the message, "How to log messages _only once_ from all modules ?".
    
    From Ron.Barak at lsi.com  Tue Nov 24 08:20:43 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 13:20:43 +0000
    Subject: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    
    Hi,
    
    I'm trying to add the logging module to my application, but I seem to be missing something.
    My application (a wxPython one) has a main script that calls various helper classes.
    I want the log messages from all modules to go to one central log file.
    
    When I implement logging, I think that due to preparation, I get the same message more than once.
    
    Here's an example:
    
    $ cat -n server.py
         1  import logging
         2  import logging.handlers
         3
         4  class Server():
         5      def __init__(self):
         6          self.client_logger = logging.getLogger("client")
         7          self.client_logger.setLevel(logging.DEBUG)
         8          h = logging.FileHandler("client.log")
         9          h.setLevel(logging.DEBUG)
        10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        11          h.setFormatter(formatter)
        12          self.client_logger.addHandler(h)
        13
        14      def util(self):
        15          self.client_logger.warning('This message comes from Server module')
    
    $ cat -n client.py
         1  import logging
         2  import logging.handlers
         3  from server import Server
         4
         5  class Client():
         6      def __init__(self):
         7          self.client_logger = logging.getLogger("client")
         8          self.client_logger.setLevel(logging.DEBUG)
         9          h = logging.FileHandler("client.log")
        10          h.setLevel(logging.DEBUG)
        11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        12          h.setFormatter(formatter)
        13          self.client_logger.addHandler(h)
        14
        15      def client_test(self):
        16          self.client_logger.warning("This message comes from Client module")
        17
        18  if __name__ == "__main__":
        19      ser = Server()
        20      cli = Client()
        21      ser.util()
        22      cli.client_test()
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    
    Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    
    Thanks,
    Ron.
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: server.py
    Type: application/octet-stream
    Size: 533 bytes
    Desc: server.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.py
    Type: application/octet-stream
    Size: 669 bytes
    Desc: client.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.log
    Type: application/octet-stream
    Size: 340 bytes
    Desc: client.log
    URL: 
    
    From solipsis at pitrou.net  Tue Nov 24 08:31:45 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 13:31:45 +0000 (UTC)
    Subject: Go versus Brand X
    References: 
    	<3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com>
    	
    	<7ms7ctF3k2a79U1@mid.individual.net> 
    	 
    	 
    	
    Message-ID: 
    
    Le Mon, 23 Nov 2009 15:30:16 -0600, Robert Kern a ?crit?:
    > particularly constrained environments like editors that may not be 
    > extensible at all.
    
    I'm not really an expert on this, but I think most good editors /are/ 
    extensible (through plugins, scripts or other things).
    
    > You can get away with just that and have something people recognize as
    > syntax highlighting, yes. But if it is possible to highlight local
    > variables, globals, and types differently, that *is* useful. And you
    > will even see some syntax highlighters doing more advanced things like
    > that even for Python (though mostly with heuristics).
    
    I suppose it's a matter of taste. I don't expect syntax highlighting to 
    do anything else than make the source code more readable and make some 
    important things stick out (comments, keywords etc.). It's probably the 
    same debate as text editor vs. full IDE. Users of text editors view 
    programming as a literary practice where they manipulate text, while 
    users of IDEs view programming as bringing technologies together through 
    specialized tools.
    
    Interestingly, we don't know how easy to parse Go is. We just have to 
    trust their word on that, but perhaps Python is easier to parse (while 
    being less ugly).
    
    
    
    From mrkafk at gmail.com  Tue Nov 24 08:41:19 2009
    From: mrkafk at gmail.com (mk)
    Date: Tue, 24 Nov 2009 14:41:19 +0100
    Subject: pointless musings on performance
    In-Reply-To: <4B0BD0E4.8030707@mrabarnett.plus.com>
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    Message-ID: 
    
    MRAB wrote:
    > In what way is it counterintuitive? In 'pythonic' the conditions are
    > simpler, less work is being done, therefore it's faster.
    
    But the pythonic condition is more general: nonevar or zerovar can be 
    '', 0, or None. So I thought it was more work for interpreter to compare 
    those, while I thought that "is not None" is translated to one, more 
    low-level and faster action. Apparently not.
    
    As Rob pointed out (thanks):
    
    11          31 LOAD_FAST                0 (nonevar)
                  34 JUMP_IF_FALSE            4 (to 41)
    
    I'm no good at py compiler or implementation internals and so I have no 
    idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    Regards,
    mk
    
    
    
    
    From bblais at bryant.edu  Tue Nov 24 08:42:04 2009
    From: bblais at bryant.edu (Brian Blais)
    Date: Tue, 24 Nov 2009 08:42:04 -0500
    Subject: xmlrpc idea for getting around the GIL
    In-Reply-To: 
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com>
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de>
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	
    	
    Message-ID: <78DF8A0D-9C1C-4ADD-8569-861DF31EC257@bryant.edu>
    
    On Nov 24, 2009, at 5:58 , sturlamolden wrote:
    
    > I have programmed parallel numerical software in Python, including on-
    > line signal processing. I have yet to find the GIL gets in my way.
    >
    > Usually people complaining about the GIL does not know what they are
    > talking about.
    >
    
    
    I'd love to know which tools/libraries/approach you have found most  
    profitable, and which were a waste of time.  Seems as if many people  
    feel the GIL gets in the way, but perhaps they've been trying methods  
    of parallelization that just aren't as effective.  What do you do?   
    Do you have any sample code?
    
    
    			bb
    
    
    -- 
    Brian Blais
    bblais at bryant.edu
    http://web.bryant.edu/~bblais
    
    
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From soltys at noabuse.com  Tue Nov 24 08:45:02 2009
    From: soltys at noabuse.com (Soltys)
    Date: Tue, 24 Nov 2009 14:45:02 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    Barak, Ron pisze:
    > Hi,
    > 
    > I'm trying to add the logging module to my application, but I seem to be missing something.
    > My application (a wxPython one) has a main script that calls various helper classes.
    > I want the log messages from all modules to go to one central log file.
    > 
    > When I implement logging, I think that due to preparation, I get the same message more than once.
    > 
    > Here's an example:
    > 
    > $ cat -n server.py
    >      1  import logging
    >      2  import logging.handlers
    >      3
    >      4  class Server():
    >      5      def __init__(self):
    >      6          self.client_logger = logging.getLogger("client")
    >      7          self.client_logger.setLevel(logging.DEBUG)
    >      8          h = logging.FileHandler("client.log")
    >      9          h.setLevel(logging.DEBUG)
    >     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >     11          h.setFormatter(formatter)
    >     12          self.client_logger.addHandler(h)
    >     13
    >     14      def util(self):
    >     15          self.client_logger.warning('This message comes from Server module')
    > 
    > $ cat -n client.py
    >      1  import logging
    >      2  import logging.handlers
    >      3  from server import Server
    >      4
    >      5  class Client():
    >      6      def __init__(self):
    >      7          self.client_logger = logging.getLogger("client")
    >      8          self.client_logger.setLevel(logging.DEBUG)
    >      9          h = logging.FileHandler("client.log")
    >     10          h.setLevel(logging.DEBUG)
    >     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >     12          h.setFormatter(formatter)
    >     13          self.client_logger.addHandler(h)
    >     14
    >     15      def client_test(self):
    >     16          self.client_logger.warning("This message comes from Client module")
    >     17
    >     18  if __name__ == "__main__":
    >     19      ser = Server()
    >     20      cli = Client()
    >     21      ser.util()
    >     22      cli.client_test()
    > $ rm client.log ; python client.py ; cat client.log
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    > 
    > Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    > 
    > Thanks,
    > Ron.
    > 
    > 
    
    Have a look at http://docs.python.org/library/logging.html#logger-objects
    First thing mentioned is Logger.propagate which is, what I believe, you're
    looking for ;)
    
    -- 
    Soltys
    
    "Free software is a matter of liberty not price"
    
    
    From rbarakx at gmail.com  Tue Nov 24 09:07:49 2009
    From: rbarakx at gmail.com (Ron Barak)
    Date: Tue, 24 Nov 2009 06:07:49 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    Message-ID: 
    
    On Nov 24, 3:45 pm, Soltys  wrote:
    > Barak, Ron pisze:
    >
    >
    >
    >
    >
    > > Hi,
    >
    > > I'm trying to add the logging module to my application, but I seem to be missing something.
    > > My application (a wxPython one) has a main script that calls various helper classes.
    > > I want the log messages from all modules to go to one central log file.
    >
    > > When I implement logging, I think that due to preparation, I get the same message more than once.
    >
    > > Here's an example:
    >
    > > $ cat -n server.py
    > >      1  import logging
    > >      2  import logging.handlers
    > >      3
    > >      4  class Server():
    > >      5      def __init__(self):
    > >      6          self.client_logger = logging.getLogger("client")
    > >      7          self.client_logger.setLevel(logging.DEBUG)
    > >      8          h = logging.FileHandler("client.log")
    > >      9          h.setLevel(logging.DEBUG)
    > >     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >     11          h.setFormatter(formatter)
    > >     12          self.client_logger.addHandler(h)
    > >     13
    > >     14      def util(self):
    > >     15          self.client_logger.warning('This message comes from Server module')
    >
    > > $ cat -n client.py
    > >      1  import logging
    > >      2  import logging.handlers
    > >      3  from server import Server
    > >      4
    > >      5  class Client():
    > >      6      def __init__(self):
    > >      7          self.client_logger = logging.getLogger("client")
    > >      8          self.client_logger.setLevel(logging.DEBUG)
    > >      9          h = logging.FileHandler("client.log")
    > >     10          h.setLevel(logging.DEBUG)
    > >     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >     12          h.setFormatter(formatter)
    > >     13          self.client_logger.addHandler(h)
    > >     14
    > >     15      def client_test(self):
    > >     16          self.client_logger.warning("This message comes from Client module")
    > >     17
    > >     18  if __name__ == "__main__":
    > >     19      ser = Server()
    > >     20      cli = Client()
    > >     21      ser.util()
    > >     22      cli.client_test()
    > > $ rm client.log ; python client.py ; cat client.log
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > > Googling and readinghttp://docs.python.org/library/logging.htmldidn't enlighten me.
    >
    > > Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    >
    > > Thanks,
    > > Ron.
    >
    > Have a look athttp://docs.python.org/library/logging.html#logger-objects
    > First thing mentioned is Logger.propagate which is, what I believe, you're
    > looking for ;)
    >
    > --
    > Soltys
    >
    > "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > - Show quoted text -
    
    Hi Soltys,
    I actually tried that, without any noticeable effects, viz.:
    
    $ cat server.py
    import logging
    import logging.handlers
    
    class Server():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
            self.client_logger.propagate = 0
    
        def util(self):
            self.client_logger.warning('This message comes from Server
    module')
    
    $ cat client.py
    import logging
    import logging.handlers
    from server import Server
    
    class Client():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
            self.client_logger.propagate = 0
    
        def client_test(self):
            self.client_logger.warning("This message comes from Client
    module")
    
    if __name__ == "__main__":
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Server module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Server module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Client module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Client module
    
    $
    
    
    
    From neilc at norwich.edu  Tue Nov 24 09:20:59 2009
    From: neilc at norwich.edu (Neil Cerutti)
    Date: 24 Nov 2009 14:20:59 GMT
    Subject: Line-continuation "Anti-Idiom" and with statement
    References: <7n0578F3j7qa6U1@mid.individual.net>
    	
    Message-ID: <7n28ebF3k2ba7U1@mid.individual.net>
    
    On 2009-11-23, Terry Reedy  wrote:
    > Neil Cerutti wrote:
    >> Unfortunately, the new "nested" with statement (which I also read
    >> about today) forces me into this anti-idiom. When replacing an
    >> appearance of contextlib.nested with the 3K with statement, I
    >> ended up with an unexpected syntax error.
    >> 
    >> with (open(roster_path, 'r') as roster_file,
    >>       open(disb_path, 'w') as out_file,
    >>       open(report_path, 'w') as report_file):
    >> 
    >> The result was:
    >> 
    >>   File "C:\project\codxml.py", line 184
    >>     with (open(roster_path, 'r') as roster_file,
    >>                                   ^
    >> SyntaxError: invalid syntax
    >
    > Right. The first open paren is illegal.
    >
    > I believe that '\ \n' would always be harmless or a SyntexError
    > outside of expressons. I believe 'subtly wrong' only applies
    > within expressions. 
    >
    > So I would not call \ continuation an anti-pattern outside
    > expressions. So you might suggest that the whole entry specify
    > expression context to begin with. To me, your example shows why
    > blanket condemnation is wrong.
    >
    > The HOWTOs are not scripture.
    
    I like your suggestion. Changing the title of the anti-idiom to
    "Using Backslash to Continue Expressions" seems like a good fix.
    I submitted it as issue 7391.
    
    I've done a search of the PEP's, Python-Dev, and Python-Ideas,
    but I couldn't find much official discussion. The change was made
    because contextlib.nested was not semantically equivalent to
    actual nested with statments.
    
    GvR noted in Python Ideas that he liked the idea of making the
    new syntax parallel to the import statement sytax variant:
    
    "import" module  ["as" name] ( ", " ["as" name] )*
    
    So that's where the 'multi-with' statement found its model.
    
    -- 
    Neil Cerutti
    
    
    From gh at ghaering.de  Tue Nov 24 09:35:08 2009
    From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=)
    Date: Tue, 24 Nov 2009 15:35:08 +0100
    Subject: IDE+hg
    In-Reply-To: 
    References: 
    	
    Message-ID: 
    
    Rhodri James wrote:
    > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    > 
    >> Dear experts,
    >> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    >> Mercurial support not found i.e. buttons to clone, commit and push to
    >> repositories to define dev env dvcs, editor and deployment all in 1.
    > 
    > I don't really understand this urge to cram everything into a single
    > program, since that inevitably leads to compromises that will compromise
    > just how much of Mercurial's useful and interesting functionality you
    > can get at.  Still, if you really must, Emacs (and presumably vim) seems
    > to be capable of working with most source control systems.
    
    I prefer the commandline tools, too.
    
    FWIW, Eclipse supports Mercurial through
    http://www.vectrace.com/mercurialeclipse/
    
    -- Gerhard
    
    
    
    
    From rtw at freenet.co.uk  Tue Nov 24 09:44:24 2009
    From: rtw at freenet.co.uk (Rob Williscroft)
    Date: Tue, 24 Nov 2009 08:44:24 -0600
    Subject: pointless musings on performance
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    	
    Message-ID: 
    
    mk wrote in news:mailman.923.1259070092.2873.python-list at python.org in 
    comp.lang.python:
    
    > MRAB wrote:
    >> In what way is it counterintuitive? In 'pythonic' the conditions are
    >> simpler, less work is being done, therefore it's faster.
    > 
    > But the pythonic condition is more general: nonevar or zerovar can be 
    > '', 0, or None. So I thought it was more work for interpreter to compare 
    > those, while I thought that "is not None" is translated to one, more 
    > low-level and faster action. Apparently not.
    > 
    > As Rob pointed out (thanks):
    > 
    > 11          31 LOAD_FAST                0 (nonevar)
    >               34 JUMP_IF_FALSE            4 (to 41)
    > 
    > I'm no good at py compiler or implementation internals and so I have no 
    > idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    IIUC it implements:
    
    http://docs.python.org/3.1/reference/expressions.html#boolean-operations
    
    "In the context of Boolean operations, and also when expressions are used 
    by control flow statements, the following values are interpreted as false: 
    False, None, numeric zero of all types, and empty strings and containers 
    (including strings, tuples, lists, dictionaries, sets and frozensets). All 
    other values are interpreted as true. User-defined objects can customize 
    their truth value by providing a __bool__() method."
    
    In particular its implementing "... Boolean operation ... used by 
    control flow ...", all in one handy op code.
    
    Rob.
    
    
    From soltys at noabuse.com  Tue Nov 24 10:08:09 2009
    From: soltys at noabuse.com (Soltys)
    Date: Tue, 24 Nov 2009 16:08:09 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: 
    References: 
    	
    	
    Message-ID: 
    
    Ron Barak pisze:
    > On Nov 24, 3:45 pm, Soltys  wrote:
    >> Barak, Ron pisze:
    >>
    >>
    >>
    >>
    >>
    >>> Hi,
    >>> I'm trying to add the logging module to my application, but I seem to be missing something.
    >>> My application (a wxPython one) has a main script that calls various helper classes.
    >>> I want the log messages from all modules to go to one central log file.
    >>> When I implement logging, I think that due to preparation, I get the same message more than once.
    >>> Here's an example:
    >>> $ cat -n server.py
    >>>      1  import logging
    >>>      2  import logging.handlers
    >>>      3
    >>>      4  class Server():
    >>>      5      def __init__(self):
    >>>      6          self.client_logger = logging.getLogger("client")
    >>>      7          self.client_logger.setLevel(logging.DEBUG)
    >>>      8          h = logging.FileHandler("client.log")
    >>>      9          h.setLevel(logging.DEBUG)
    >>>     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >>>     11          h.setFormatter(formatter)
    >>>     12          self.client_logger.addHandler(h)
    >>>     13
    >>>     14      def util(self):
    >>>     15          self.client_logger.warning('This message comes from Server module')
    >>> $ cat -n client.py
    >>>      1  import logging
    >>>      2  import logging.handlers
    >>>      3  from server import Server
    >>>      4
    >>>      5  class Client():
    >>>      6      def __init__(self):
    >>>      7          self.client_logger = logging.getLogger("client")
    >>>      8          self.client_logger.setLevel(logging.DEBUG)
    >>>      9          h = logging.FileHandler("client.log")
    >>>     10          h.setLevel(logging.DEBUG)
    >>>     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >>>     12          h.setFormatter(formatter)
    >>>     13          self.client_logger.addHandler(h)
    >>>     14
    >>>     15      def client_test(self):
    >>>     16          self.client_logger.warning("This message comes from Client module")
    >>>     17
    >>>     18  if __name__ == "__main__":
    >>>     19      ser = Server()
    >>>     20      cli = Client()
    >>>     21      ser.util()
    >>>     22      cli.client_test()
    >>> $ rm client.log ; python client.py ; cat client.log
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    >>> Googling and readinghttp://docs.python.org/library/logging.htmldidn't enlighten me.
    >>> Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    >>> Thanks,
    >>> Ron.
    >> Have a look athttp://docs.python.org/library/logging.html#logger-objects
    >> First thing mentioned is Logger.propagate which is, what I believe, you're
    >> looking for ;)
    >>
    >> --
    >> Soltys
    >>
    >> "Free software is a matter of liberty not price"- Hide quoted text -
    >>
    >> - Show quoted text -
    > 
    > Hi Soltys,
    > I actually tried that, without any noticeable effects, viz.:
    > 
    > $ cat server.py
    > import logging
    > import logging.handlers
    > 
    > class Server():
    >     def __init__(self):
    >         self.client_logger = logging.getLogger("client")
    >         self.client_logger.setLevel(logging.DEBUG)
    >         h = logging.FileHandler("client.log")
    >         h.setLevel(logging.DEBUG)
    >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > (levelname)-8s %(message)s")
    >         h.setFormatter(formatter)
    >         self.client_logger.addHandler(h)
    >         self.client_logger.propagate = 0
    > 
    >     def util(self):
    >         self.client_logger.warning('This message comes from Server
    > module')
    > 
    > $ cat client.py
    > import logging
    > import logging.handlers
    > from server import Server
    > 
    > class Client():
    >     def __init__(self):
    >         self.client_logger = logging.getLogger("client")
    >         self.client_logger.setLevel(logging.DEBUG)
    >         h = logging.FileHandler("client.log")
    >         h.setLevel(logging.DEBUG)
    >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > (levelname)-8s %(message)s")
    >         h.setFormatter(formatter)
    >         self.client_logger.addHandler(h)
    >         self.client_logger.propagate = 0
    > 
    >     def client_test(self):
    >         self.client_logger.warning("This message comes from Client
    > module")
    > 
    > if __name__ == "__main__":
    >     ser = Server()
    >     cli = Client()
    >     ser.util()
    >     cli.client_test()
    > 
    > $ rm client.log ; python client.py ; cat client.log
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Server module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Server module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Client module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Client module
    > 
    > $
    > 
    
    Rename logger in server.py to server:
    self.client_logger = logging.getLogger("server")
    
    Rerun, you should get sth. like this:
    $ cat client.log
    2009-11-24 16:06:54,990 server       WARNING  This message comes from Server module
    2009-11-24 16:06:54,990 client       WARNING  This message comes from Client module
    
    
    
    -- 
    Soltys
    
    "Free software is a matter of liberty not price"
    
    
    From solipsis at pitrou.net  Tue Nov 24 10:11:29 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 15:11:29 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    Message-ID: 
    
    
    Hello,
    
    Le Tue, 24 Nov 2009 14:41:19 +0100, mk a ?crit?:
    > 
    > As Rob pointed out (thanks):
    > 
    > 11          31 LOAD_FAST                0 (nonevar)
    >               34 JUMP_IF_FALSE            4 (to 41)
    > 
    > I'm no good at py compiler or implementation internals and so I have no
    > idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    It tries to evaluate the op of the stack (here nonevar) in a boolean 
    context (which theoretically involves calling __nonzero__ on the type) 
    and then jumps if the result is False (rather than True).
    
    You are totally right that it does /more/ than "is not None", but since 
    it is executed as a single opcode rather than a sequence of several 
    opcodes, the additional work it has to do is compensated (in this case) 
    by the smaller overhead in bytecode interpretation.
    
    As someone pointed out, the Python interpreter could grow CISC-like 
    opcodes so as to collapse "is not None" (or generically "is not 
    ") into a single JUMP_IF_IS_NOT_CONST opcode. Actually, it is 
    the kind of optimizations wpython does (http://code.google.com/p/
    wpython/).
    
    Regards
    
    Antoine.
    
    
    
    From rileyrgdev at gmail.com  Tue Nov 24 10:13:27 2009
    From: rileyrgdev at gmail.com (Richard Riley)
    Date: Tue, 24 Nov 2009 16:13:27 +0100
    Subject: IDE+hg
    References: 
    	
    	
    Message-ID: 
    
    Gerhard H?ring  writes:
    
    > Rhodri James wrote:
    >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >> 
    >>> Dear experts,
    >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    >>> Mercurial support not found i.e. buttons to clone, commit and push to
    >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >> 
    >> I don't really understand this urge to cram everything into a single
    >> program, since that inevitably leads to compromises that will
    >> compromise
    
    Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    merely programmed to hook into the external tools
    
    >> just how much of Mercurial's useful and interesting functionality you
    >> can get at.  Still, if you really must, Emacs (and presumably vim) seems
    >> to be capable of working with most source control systems.
    >
    > I prefer the commandline tools, too.
    >
    > FWIW, Eclipse supports Mercurial through
    > http://www.vectrace.com/mercurialeclipse/
    >
    > -- Gerhard
    
    Why would you prefer the command line tools in a shell when the same
    tools can be used in a way which makes navigating the output so much
    easier? It strikes me as a kind of intransigence. it's a common
    misconception that IDEs use their own tools all the time. They
    don't. They integrate the very same tools. e.g Why the hell would I drop
    to a command line to diff a file with a back version in GIT when I can
    do the same in the buffer in emacs with a single hot key? Why would I
    pipe the output of compile into a file then open that file when a single
    hot key can fire off the SAME compiler and then list the errors in an
    emacs buffer and another hot key can take me directly to the source
    lines in question? Living in the past has its mements, but really.
    
    e.g I have pylint working live in python buffers. Big time
    saver. Similar with C.
    
    
    From solipsis at pitrou.net  Tue Nov 24 10:13:29 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 15:13:29 +0000 (UTC)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 02:53:30 -0800, sturlamolden a ?crit?:
    > On 22 Nov, 22:38, Patrick Stinson 
    > wrote:
    > 
    >> Has anyone every tried wrapping the CPython lib into a daemon with an
    >> RPC mechanism in order to move the GIL out of the process?
    > 
    >> I imagine this is how the multiprocessing module works.
    > 
    > It does not.
    
    Actually, it is how multiprocessing works under Windows (for lack of the 
    fork() function), except that it uses pickle by default (but it does have 
    xmlrpc support).
    
    Regards
    
    Antoine.
    
    
    
    
    From rbarakx at gmail.com  Tue Nov 24 10:14:56 2009
    From: rbarakx at gmail.com (Ron Barak)
    Date: Tue, 24 Nov 2009 07:14:56 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    	
    	
    Message-ID: <9750596d-4d09-478a-a9df-942e44a4e83a@t18g2000vbj.googlegroups.com>
    
    On Nov 24, 5:08 pm, Soltys  wrote:
    > Ron Barak pisze:
    >
    >
    >
    >
    >
    > > On Nov 24, 3:45 pm, Soltys  wrote:
    > >> Barak, Ron pisze:
    >
    > >>> Hi,
    > >>> I'm trying to add the logging module to my application, but I seem to be missing something.
    > >>> My application (a wxPython one) has a main script that calls various helper classes.
    > >>> I want the log messages from all modules to go to one central log file.
    > >>> When I implement logging, I think that due to preparation, I get the same message more than once.
    > >>> Here's an example:
    > >>> $ cat -n server.py
    > >>>      1  import logging
    > >>>      2  import logging.handlers
    > >>>      3
    > >>>      4  class Server():
    > >>>      5      def __init__(self):
    > >>>      6          self.client_logger = logging.getLogger("client")
    > >>>      7          self.client_logger.setLevel(logging.DEBUG)
    > >>>      8          h = logging.FileHandler("client.log")
    > >>>      9          h.setLevel(logging.DEBUG)
    > >>>     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >>>     11          h.setFormatter(formatter)
    > >>>     12          self.client_logger.addHandler(h)
    > >>>     13
    > >>>     14      def util(self):
    > >>>     15          self.client_logger.warning('This message comes from Server module')
    > >>> $ cat -n client.py
    > >>>      1  import logging
    > >>>      2  import logging.handlers
    > >>>      3  from server import Server
    > >>>      4
    > >>>      5  class Client():
    > >>>      6      def __init__(self):
    > >>>      7          self.client_logger = logging.getLogger("client")
    > >>>      8          self.client_logger.setLevel(logging.DEBUG)
    > >>>      9          h = logging.FileHandler("client.log")
    > >>>     10          h.setLevel(logging.DEBUG)
    > >>>     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >>>     12          h.setFormatter(formatter)
    > >>>     13          self.client_logger.addHandler(h)
    > >>>     14
    > >>>     15      def client_test(self):
    > >>>     16          self.client_logger.warning("This message comes from Client module")
    > >>>     17
    > >>>     18  if __name__ == "__main__":
    > >>>     19      ser = Server()
    > >>>     20      cli = Client()
    > >>>     21      ser.util()
    > >>>     22      cli.client_test()
    > >>> $ rm client.log ; python client.py ; cat client.log
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > >>> Googling and readinghttp://docs.python.org/library/logging.htmldidn'tenlighten me.
    > >>> Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    > >>> Thanks,
    > >>> Ron.
    > >> Have a look athttp://docs.python.org/library/logging.html#logger-objects
    > >> First thing mentioned is Logger.propagate which is, what I believe, you're
    > >> looking for ;)
    >
    > >> --
    > >> Soltys
    >
    > >> "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > >> - Show quoted text -
    >
    > > Hi Soltys,
    > > I actually tried that, without any noticeable effects, viz.:
    >
    > > $ cat server.py
    > > import logging
    > > import logging.handlers
    >
    > > class Server():
    > >     def __init__(self):
    > >         self.client_logger = logging.getLogger("client")
    > >         self.client_logger.setLevel(logging.DEBUG)
    > >         h = logging.FileHandler("client.log")
    > >         h.setLevel(logging.DEBUG)
    > >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > > (levelname)-8s %(message)s")
    > >         h.setFormatter(formatter)
    > >         self.client_logger.addHandler(h)
    > >         self.client_logger.propagate = 0
    >
    > >     def util(self):
    > >         self.client_logger.warning('This message comes from Server
    > > module')
    >
    > > $ cat client.py
    > > import logging
    > > import logging.handlers
    > > from server import Server
    >
    > > class Client():
    > >     def __init__(self):
    > >         self.client_logger = logging.getLogger("client")
    > >         self.client_logger.setLevel(logging.DEBUG)
    > >         h = logging.FileHandler("client.log")
    > >         h.setLevel(logging.DEBUG)
    > >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > > (levelname)-8s %(message)s")
    > >         h.setFormatter(formatter)
    > >         self.client_logger.addHandler(h)
    > >         self.client_logger.propagate = 0
    >
    > >     def client_test(self):
    > >         self.client_logger.warning("This message comes from Client
    > > module")
    >
    > > if __name__ == "__main__":
    > >     ser = Server()
    > >     cli = Client()
    > >     ser.util()
    > >     cli.client_test()
    >
    > > $ rm client.log ; python client.py ; cat client.log
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Server module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Server module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Client module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Client module
    >
    > > $
    >
    > Rename logger in server.py to server:
    > self.client_logger = logging.getLogger("server")
    >
    > Rerun, you should get sth. like this:
    > $ cat client.log
    > 2009-11-24 16:06:54,990 server       WARNING  This message comes from Server module
    > 2009-11-24 16:06:54,990 client       WARNING  This message comes from Client module
    >
    > --
    > Soltys
    >
    > "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > - Show quoted text -
    
    Many thanks Soltys, that did the trick (actually, no need for setting
    propagate to 0), namely,
    
    $ cat client.py
    import logging
    import logging.handlers
    from server import Server
    
    class Client():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
    
        def client_test(self):
            self.client_logger.warning("This message comes from Client
    module")
    
    if __name__ == "__main__":
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    $ cat server.py
    import logging
    import logging.handlers
    
    class Server():
        def __init__(self):
            self.client_logger = logging.getLogger("server")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
    
        def util(self):
            self.client_logger.warning('This message comes from Server
    module')
    
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 17:13:15,989 server       WARNING  This message comes from
    Server module
    2009-11-24 17:13:15,989 client       WARNING  This message comes from
    Client module
    
    
    
    From 457r0.jp at gmail.com  Tue Nov 24 10:45:00 2009
    From: 457r0.jp at gmail.com (astral orange)
    Date: Tue, 24 Nov 2009 07:45:00 -0800 (PST)
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    Message-ID: 
    
    On Nov 23, 10:37?pm, r  wrote:
    > On Nov 23, 11:19?am, astral orange <457r0... at gmail.com> wrote:
    >
    >
    >
    > > Hi, I am trying to teach myself Python and have a good book to help me
    > > but I am stuck on something and I would like for someone to explain
    > > the following piece of code for me and what it's actually doing.
    > > Certain parts are very clear but once it enters the "def store(data,
    > > full_name): ...." function and the "def lookup()..." function things
    > > get a little confusing for me. Specifically, lines 103-108 *and* Lines
    > > 110-111.
    >
    > > Lastly, I am not sure how to print the results I've put into this
    > > program either, the book I'm reading doesn't tell me. As you can tell,
    > > I am a beginner and I don't truly understand everything that is going
    > > on here...a lot, but not all....
    >
    > > Here is the code:
    >
    > > ?92 def init(data):
    > > ?93 ? ? data['first'] = {}
    > > ?94 ? ? data['middle'] = {}
    > > ?95 ? ? data['last'] = {}
    > > ?96
    > > ?97 def store(data, full_name):
    > > ?98 ? ? names = full_name.split()
    > > 100 ? ? if len(names) == 2: names.insert(1, '')
    > > 101 ? ? labels = 'first', 'middle', 'last'
    > > 103 ? ? for label, name in zip(labels, names):
    > > 104 ? ? ? ? people = lookup(data, label, name)
    > > 105 ? ? if people:
    > > 106 ? ? ? ? people.append(full_name)
    > > 107 ? ? else:
    > > 108 ? ? ? ? data[label][name] = [full_name]
    > > 109
    > > 110 def lookup(data, label, name):
    > > 111 ? ? return data[label].get(name)
    > > 112
    > > 113
    > > 114 MyNames = {}
    > > 115 init(MyNames)
    > > 116 store(MyNames, 'John Larry Smith')
    > > 117 lookup(MyNames, 'middle', 'Smith')
    >
    > This is a horrible example to show noobs. I think the OP could better
    > understand this as a class EVEN though the OP may or may not know what
    > a class *is* yet.
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    >
    > >>> name1 = Name('Guido', 'van', 'Rossum')
    > >>> name1.first
    > 'Guido'
    > >>> name1.middle
    > 'van'
    > >>> name1.last
    > 'Rossum'
    > >>> print name1
    >
    > <__main__.Name instance at 0x029BFD78>
    >
    > This time we add a __str__ method, the result will speak louder than
    > words!!
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    > ? ? ? ? def __str__(self):
    > ? ? ? ? ? ? ? ? return '%s %s %s' %(self.first, self.middle, self.last)
    >
    > >>> name2 = Name('Terry', 'J', 'Reedy')
    > >>> name2.first
    > 'Terry'
    > >>> name2.middle
    > 'J'
    > >>> name2.last
    > 'Reedy'
    > >>> print name2
    >
    > Terry J Reedy
    >
    > See the difference in the print statements. Now lets have some real
    > fun and access each sub name by index haha!
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    > ? ? ? ? def __str__(self):
    > ? ? ? ? ? ? ? ? return '%s %s %s' %(self.first, self.middle, self.last)
    > ? ? ? ? def __len__(self):
    > ? ? ? ? ? ? ? ? return 3
    > ? ? ? ? def __getitem__(self, item):
    > ? ? ? ? ? ? ? ? if item == 0:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.first
    > ? ? ? ? ? ? ? ? elif item == 1:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.middle
    > ? ? ? ? ? ? ? ? elif item == 2:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.last
    > ? ? ? ? ? ? ? ? else:
    > ? ? ? ? ? ? ? ? ? ? ? ? raise IndexError("Index must be in range 0, 2")
    >
    > >>> name = Name('Joe', 'blow', 'scripter')
    > >>> name[0]
    > 'Joe'
    > >>> name[1]
    > 'blow'
    > >>> name[2]
    > 'scripter'
    > >>> len(name)
    >
    > 3
    >
    > WOW, thats more info in a few lines than any tut i ever seen! I wish i
    > could have seen that in my initial days, could have save some
    > countless hours of confusion!!! Maybe i am in the wrong line of work?
    >
    > Should i keep going...?
    
    Yeah, I don't think the example in the book is the best for someone
    starting out. I still
    am "not getting" certain parts of the program so I think I'll move on
    in hopes that it will
    *not* came back to haunt me and the book (along with the online
    tutorial) will help me grab
    more of the basics of Python programming.
    
    As for the "class Name():" example above? Even though I haven't seen
    exactly what purpose 'self' serves
    yet I can follow and understand what is going on very easily, that
    helps out tremendously.
    Very clearly written...Thank you!
    
    And thanks again to everyone...
    
    
    From marcu.nicolae at gmail.com  Tue Nov 24 10:47:40 2009
    From: marcu.nicolae at gmail.com (NMarcu)
    Date: Tue, 24 Nov 2009 07:47:40 -0800 (PST)
    Subject: Need help to understand a getattr syntax.
    Message-ID: <5b2a9e74-2958-4f54-bdea-0075c2ebcc32@o31g2000vbi.googlegroups.com>
    
    Hello all,
        I need some help to understand a getattr syntax. The syntax is:
    
    try:
        getattr(self, command)(cursor, row)
    except Exception, e:
        print "Action failed : '%s'" % command
        raise e
    
    I don't understand why is not like this: a = getattr(), and what are
    the scope of the second (): (cursor, row)
    
    Thanks.
    
    
    From pengyu.ut at gmail.com  Tue Nov 24 10:47:58 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 09:47:58 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: <366c6f340911240747k5e55fea5kb63f603c5baa5268@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 12:27 AM, alex23  wrote:
    > On Nov 24, 1:15?pm, Peng Yu  wrote:
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    >
    > What you should try to do is make each function as self-contained as
    > possible. f() shouldn't have to know what is a valid argument for g(),
    > that's the responsibility of g(). What f() needs to know is how to
    > deal with any problems that arise while using g().
    
    This may not always be possible, because g() might call a third party
    software, that I don't have the complete knowledge of. What would you
    do if this case?
    
    Another scenario:
    
    Suppose that f_1(),...,f_(), g() are in a package, where g() is an
    internal function that the end users are not suppose to call, and
    f_1(),...,f_() are the functions that the end users may call.
    
    Since all the f_1 ... f_ functions knows g(), they can be
    programmed to guarantee not to pass any arguments that can not be
    handled by g(). In this case, I think it is reasonable to move the
    test code from g()? Is it the general accepted practice?
    
    > As a very rough example:
    >
    > ? ?def g(x):
    > ? ? ? ?try:
    > ? ? ? ? ? ?assert isinstance(x, int)
    > ? ? ? ?except AssertionError:
    > ? ? ? ? ? ?raise TypeError, "excepted int, got %s" % type(x)
    > ? ? ? ?# ... function code goes here
    >
    > ? ?def f(x):
    > ? ? ? ?try:
    > ? ? ? ? ? ?g(x)
    > ? ? ? ?except TypeError:
    > ? ? ? ? ? ?# handle the problem here
    > ? ? ? ?# ... function code goes here
    >
    >> My thought is that if I put the test in g(x), the code of g(x) is
    >> safer, but the test is not necessary when g() is called by h().
    >
    > This sounds strange to me. Are you stating that h() can pass values to
    > g() that would be illegal for f() to pass? That sounds like a very
    > dangerous design...you want each function's behaviour to be as
    > consistent and predictable as it possibly can.
    
    You misunderstood me.
    
    h() doesn't pass any illegal arguments to g(). If I put the test code
    in g(), it would be a waste of run time when h() calls g(). In this
    case, and under the condition that g() is an internal function of a
    package as I mentioned above, I think I should move the test code from
    g() to f(). What do you think?
    
    
    From deets at nospam.web.de  Tue Nov 24 10:51:55 2009
    From: deets at nospam.web.de (Diez B. Roggisch)
    Date: Tue, 24 Nov 2009 16:51:55 +0100
    Subject: Need help to understand a getattr syntax.
    References: <5b2a9e74-2958-4f54-bdea-0075c2ebcc32@o31g2000vbi.googlegroups.com>
    Message-ID: <7n2dorF3jv2q5U1@mid.uni-berlin.de>
    
    NMarcu wrote:
    
    > Hello all,
    >     I need some help to understand a getattr syntax. The syntax is:
    > 
    > try:
    >     getattr(self, command)(cursor, row)
    > except Exception, e:
    >     print "Action failed : '%s'" % command
    >     raise e
    > 
    > I don't understand why is not like this: a = getattr(), and what are
    > the scope of the second (): (cursor, row)
    
    The attribute in question is a callable, a method most probably. So 
    
     getattr(self, command)
    
    returns a reference to the method, and the following
    
     (cursor, row)
    
    calls it with cursor and row as parameters.
    
    You could rewrite it as 
    
      method = getattr(self, command)
      print method
      method(cursor, row)
    
    Diez
    
    
    From neilc at norwich.edu  Tue Nov 24 11:00:59 2009
    From: neilc at norwich.edu (Neil Cerutti)
    Date: 24 Nov 2009 16:00:59 GMT
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    Message-ID: <7n2e9rF3k5ehtU1@mid.individual.net>
    
    On 2009-11-24, Antoine Pitrou  wrote:
    > It tries to evaluate the op of the stack (here nonevar) in a
    > boolean context (which theoretically involves calling
    > __nonzero__ on the type) 
    
    ...or __bool__ in Py3K.
    
    -- 
    Neil Cerutti
    
    
    From solipsis at pitrou.net  Tue Nov 24 11:05:01 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 16:05:01 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    Message-ID: 
    
    Le Tue, 24 Nov 2009 15:11:29 +0000, Antoine Pitrou a ?crit?:
    > Hello,
    > 
    > Le Tue, 24 Nov 2009 14:41:19 +0100, mk a ?crit?:
    >> 
    >> As Rob pointed out (thanks):
    >> 
    >> 11          31 LOAD_FAST                0 (nonevar)
    >>               34 JUMP_IF_FALSE            4 (to 41)
    >> 
    >> I'm no good at py compiler or implementation internals and so I have no
    >> idea what bytecode "JUMP_IF_FALSE" is actually doing.
    > 
    > It tries to evaluate the op of the stack (here nonevar)
    
    I meant "the top of the stack" obviously.
    
    
    
    
    From rustompmody at gmail.com  Tue Nov 24 11:09:41 2009
    From: rustompmody at gmail.com (rustom)
    Date: Tue, 24 Nov 2009 08:09:41 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    Message-ID: 
    
    On Nov 24, 8:13?pm, Richard Riley  wrote:
    > Gerhard H?ring  writes:
    > > Rhodri James wrote:
    > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >>> Dear experts,
    > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > >> I don't really understand this urge to cram everything into a single
    > >> program, since that inevitably leads to compromises that will
    > >> compromise
    >
    > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > merely programmed to hook into the external tools
    >
    > >> just how much of Mercurial's useful and interesting functionality you
    > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > >> to be capable of working with most source control systems.
    >
    > > I prefer the commandline tools, too.
    >
    > > FWIW, Eclipse supports Mercurial through
    > >http://www.vectrace.com/mercurialeclipse/
    >
    > > -- Gerhard
    >
    > Why would you prefer the command line tools in a shell when the same
    > tools can be used in a way which makes navigating the output so much
    > easier? It strikes me as a kind of intransigence. it's a common
    > misconception that IDEs use their own tools all the time. They
    > don't. They integrate the very same tools. e.g Why the hell would I drop
    > to a command line to diff a file with a back version in GIT when I can
    > do the same in the buffer in emacs with a single hot key? Why would I
    > pipe the output of compile into a file then open that file when a single
    > hot key can fire off the SAME compiler and then list the errors in an
    > emacs buffer and another hot key can take me directly to the source
    > lines in question? Living in the past has its mements, but really.
    >
    > e.g I have pylint working live in python buffers. Big time
    > saver. Similar with C.
    
    I sometimes think that the amount of time I spend tweaking emacs to
    save my time is more than the time I spend on anything else :-)
    
    But more seriously:
    I tried to use emacs with git recently -- it was a sorry experience.
    The git.el that comes with git is broken (on windows)
    vc was too old for git like systems
    dvc is a joke (its supposedly generic for all Distributed Version
    Systems -- but everything is couched in terms of tla.
    TLA! For heavens sake!
    magit would not run on windows and to use egg http://github.com/bogolisk/egg
    I must read magit docs.
    Finally I decided to stay with what Ive used for the last 25 years --
    the shell
    
    
    
    From pengyu.ut at gmail.com  Tue Nov 24 11:14:19 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 10:14:19 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <4B0BBC62.7020702@ieee.org>
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    	<4B0BBC62.7020702@ieee.org>
    Message-ID: <366c6f340911240814o4b02642bude4c306cf160bc01@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel  wrote:
    > Peng Yu wrote:
    >>
    >> On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    >>
    >>>
    >>> Peng Yu wrote:
    >>>
    >>>>
    >>>> Suppose that I have function f() that calls g(), I can put a test on
    >>>> the argument 'x' in either g() or f(). I'm wondering what is the
    >>>> common practice.
    >>>>
    >>>> My thought is that if I put the test in g(x), the code of g(x) is
    >>>> safer, but the test is not necessary when g() is called by h().
    >>>>
    >>>> If I put the test in f(), then g() becomes more efficient when other
    >>>> code call g() and guarantee x will pass the test even though the test
    >>>> code in not in g(). But there might be some caller of g() that pass an
    >>>> 'x' that might not pass the test, if there were the test in g().
    >>>>
    >>>
    >>> Typically, you test for x as early as possible, e.g. just after user
    >>> input
    >>> (or file or url load or whatever). After that test, you can (or should be
    >>> able to) assume that all function calls will always be called with the
    >>> correct argument. This is the ideal situation, it's not always easy to
    >>> do.
    >>>
    >>> In any case though, don't optimize early.
    >>>
    >>
    >> Let's suppose that g() is refactored out from f() and is call by not
    >> only f() but other functions, and g() is likely to be called by new
    >> functions.
    >>
    >> If I don't optimize early, I should put the test in g(), rather than f(),
    >> right?
    >>
    >>
    >
    > Your question is so open-ended as to be unanswerable. ?All we should do in
    > this case is supply some guidelines so you can guess which one might apply
    > in your particular case.
    >
    > You could be referring to a test that triggers alternate handling. ?Or you
    > could be referring to a test that notices bad input by a user, or bad data
    > from an untrusted source. ?Or you could be referring to a test that
    > discovers bugs in your code. ?And there are variations of these, depending
    > on whether your user is also writing code (eval, or even import of
    > user-supplied mixins), etc.
    >
    > The first thing that's needed in the function g() is a docstring, defining
    > what inputs it expects, and what it'll do with them. ?Then if it gets any
    > input that doesn't meet those requirements, it might throw an exception. ?Or
    > it might just get an arbitrary result. ?That's all up to the docstring.
    > ?Without any documentation, nothing is correct.
    >
    > Functions that are only called by trusted code need not have explicit tests
    > on their inputs, since you're writing it all. ?Part of debugging is catching
    > those cases where f () can pass bad data to g(). ?If it's caused because bad
    > data is passed to f(), then you have a bug in that caller. ?Eventually, you
    > get to the user. ?If the bad data comes from the user, it should be caught
    > as soon as possible, and feedback supplied right then.
    
    I'll still confused by the guideline that an error should be caught as
    early as possible.
    
    Suppose I have the following call chain
    
    f1() --> f2() --> f3() --> f4()
    
    The input in f1() might cause an error in f4(). However, this error
    can of cause be caught by f1(), whenever I want to do so. In the worst
    case, I could duplicate the code of f2 and f3, and the test code in f4
    to f1(), to catch the error in f1 rather than f4. But I don't think
    that this is what you mean.
    
    Then the problem is where to put the test code more effectively. I
    would consider 'whether it is obvious to test the condition in the
    give function' as the guideline. However, it might be equal obvious to
    test the same thing two functions, for example, f1 and f4.
    
    In this case, I thought originally that I should put the test code in
    f1 rather than f4, if f1, f2, f3 and f4 are all the functions that I
    have in the package that I am making. But it is possible that some
    time later I added the function f5(),...,f10() that calls f4(). Since
    f4 doesn't have the test code, f5(),...,f10() should have the same
    test code. This is clearly a redundancy to the code. If I move the
    test code to f4(), there is a redundancy of the code between f1 and
    f4.
    
    I'm wondering how you would solve the above problem?
    
    > assert() ought to be the correct way to add tests in g() that test whether
    > there's such a bug in f(). ?Unfortunately, in CPython it defaults to debug
    > mode, so scripts that are run will execute those tests by default.
    > ?Consequently, people leave them out, to avoid slowing down code.
    >
    >
    >
    > It comes down to trust. ?If you throw the code together without a test
    > suite, you'll be a long time finding all the bugs in non-trivial code. ?So
    > add lots of defensive tests throughout the code, and pretend that's
    > equivalent to a good test system. ?If you're writing a library to be used by
    > others, then define your public interfaces with exceptions for any invalid
    > code, and write careful documentation describing what's invalid. ?And if
    > you're writing an end-user application, test their input as soon as you get
    > it, so none of the rest of the application ever gets "invalid" data.
    
    Having the test code for any function and any class (even the ones
    that are internal in the package) is basically what I am doing.
    However, if I decided to put the test code in f1(), then I can not
    have my test code test the error case for f4(). If the rule is to test
    each function/class extensively, then I have to put the error handling
    code in f4(). But this is contradictory to catch the error as early as
    possible and removing code redundancy.
    
    Would you put a global solution to all the above problems that I mentioned?
    
    
    From wadienil at gmail.com  Tue Nov 24 11:14:35 2009
    From: wadienil at gmail.com (wadi wadi)
    Date: Tue, 24 Nov 2009 16:14:35 +0000
    Subject: fixing xml output format
    Message-ID: <3282bd0c0911240814s304840bdree681c18e9f6e0e0@mail.gmail.com>
    
     Hi all,
    
    I am creating some xml output using minidom and saving it to a file using
    doc.writexml()
    The output however is as follows:
    
    
    
    
            bill catman
    
    
    
    
    Is there a way to save xml output in a file such as xml is formatted the
    right way? I mean with the right indentation and the elements values with no
    new lines?
    
    
    
      bill catman
    
    
    Note: writexml() with parameters and toprettyxml() are not giving the
    desired output.
    
    Thanks.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From nulla.epistola at web.de  Tue Nov 24 11:42:57 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Tue, 24 Nov 2009 17:42:57 +0100
    Subject: csv and mixed lists of unicode and numbers
    Message-ID: 
    
    Hello,
    
    I want to put data from a database into a tab separated text file. This
    looks like a typical application for the csv module, but there is a
    snag: the rows I get from the database module (kinterbasdb in this case)
    contain unicode objects and numbers. And of course the unicode objects
    contain lots of non-ascii characters.
    
    If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    the UnicodeWriter from the module documentation, I get TypeErrors with
    the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    would cause other complications.)
    
    So do I have to process the rows myself and treat numbers and text
    fields differently? Or what's the best way?
    
    Here is a small example:
    
    ########################################################################
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import csv, codecs, cStringIO
    import tempfile
    
    cData = [u'?rger', u'?dland', 5, u'S??igkeit', u'?l?ve', 6.9, u'for?t']
    
    class UnicodeWriter:
         """
         A CSV writer which will write rows to CSV file "f",
         which is encoded in the given encoding.
         """
    
         def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
             # Redirect output to a queue
             self.queue = cStringIO.StringIO()
             self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
             self.stream = f
             self.encoder = codecs.getincrementalencoder(encoding)()
    
         def writerow(self, row):
             self.writer.writerow([s.encode("utf-8") for s in row])
             # Fetch UTF-8 output from the queue ...
             data = self.queue.getvalue()
             data = data.decode("utf-8")
             # ... and reencode it into the target encoding
             data = self.encoder.encode(data)
             # write to the target stream
             self.stream.write(data)
             # empty queue
             self.queue.truncate(0)
    
         def writerows(self, rows):
             for row in rows:
                 self.writerow(row)
    
    def writewithcsv(outfile, datalist):
         wrt = csv.writer(outfile, dialect=csv.excel)
         wrt.writerow(datalist)
    
    def writeunicode(outfile, datalist):
         wrt = UnicodeWriter(outfile)
         wrt.writerow(datalist)
    
    def main():
         with tempfile.NamedTemporaryFile() as csvfile:
             print "CSV file:", csvfile.name
             print "Try with csv.writer"
             try:
                 writewithcsv(csvfile, cData)
             except UnicodeEncodeError as e:
                 print e
             print "Try with UnicodeWriter"
             writeunicode(csvfile, cData)
         print "Ready."
    
    if __name__ == "__main__":
         main()
    
    
    ##############################################################################
    
    Hoping for advice,
    
    Sibylle
    
    
    From paul at boddie.org.uk  Tue Nov 24 11:58:40 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Tue, 24 Nov 2009 08:58:40 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	
    Message-ID: <4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    
    On 24 Nov, 16:11, Antoine Pitrou  wrote:
    >
    
    [JUMP_IF_FALSE]
    
    > It tries to evaluate the op of the stack (here nonevar) in a boolean
    > context (which theoretically involves calling __nonzero__ on the type)
    > and then jumps if the result is False (rather than True).
    
    [...]
    
    > As someone pointed out, the Python interpreter could grow CISC-like
    > opcodes so as to collapse "is not None" (or generically "is not
    > ") into a single JUMP_IF_IS_NOT_CONST opcode.
    
    Of course, JUMP_IF_FALSE is already quite CISC-like, whereas testing
    if something is not None could involve some fairly RISC-like
    instructions: just compare the address of an operand with the address
    of None. As you point out, a lot of this RISC vs. CISC analysis (and
    inferences drawn from Python bytecode analysis) is somewhat academic:
    the cost of the JUMP_IF_FALSE instruction is likely to be minimal in
    the context of all the activity going on to evaluate the bytecodes.
    
    I imagine that someone (or a number of people) must have profiled the
    Python interpreter and shown how much time goes on the individual
    bytecode implementations and how much goes on the interpreter's own
    housekeeping activities. It would be interesting to see such figures.
    
    Paul
    
    
    From bheemesh at gmail.com  Tue Nov 24 12:17:36 2009
    From: bheemesh at gmail.com (bheemesh v)
    Date: Tue, 24 Nov 2009 22:47:36 +0530
    Subject: howto send signal to a OS daemon on linux
    Message-ID: <670534840911240917u119aae1fmb05a48cc77cdab8b@mail.gmail.com>
    
    Hello,
    
    Greetings.
    
    I am a newbie to python programming.
    Can anybody please help me with options to send a user defined signal to a
    OS daemon (example a daemon snmpd).
    
    I tried finding options to get pid of a daemon (process) by passing it's
    name.
    Once a pid is available thenwe can use os.kill(signal_type, signalhandler);
    
    But how to get pid of a process by passing it's name and then how to send
    signal whichis userdefind.
    
    Kindly let me know.
    Thanks in advance.
    
    Best Regards,
    Bheemesh
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From sturlamolden at yahoo.no  Tue Nov 24 12:27:24 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 09:27:24 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References:  
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com> 
    	
    Message-ID: <1bafb82e-fe19-4a4f-a172-f1224cb1a314@h10g2000vbm.googlegroups.com>
    
    On 24 Nov, 16:13, Antoine Pitrou  wrote:
    
    > >> Has anyone every tried wrapping the CPython lib into a daemon with an
    > >> RPC mechanism in order to move the GIL out of the process?
    >
    > >> I imagine this is how the multiprocessing module works.
    >
    > > It does not.
    >
    > Actually, it is how multiprocessing works under Windows (for lack of the
    > fork() function), except that it uses pickle by default (but it does have
    > xmlrpc support).
    
    Windows does not have daemons, so this is obviously incorrect. (There
    are something called Windows Services, but multiprocessing does not
    use them.)
    
    Multiprocessing on Windows uses the subprocess module.
    
    
    
    
    
    
    
    
    
    
    
    
    
    From ethan at stoneleaf.us  Tue Nov 24 12:39:26 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Tue, 24 Nov 2009 09:39:26 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4b0b92de$0$14677$426a74cc@news.free.fr>
    References: 
    	<4b0b92de$0$14677$426a74cc@news.free.fr>
    Message-ID: <4B0C1A4E.7050204@stoneleaf.us>
    
    Bruno Desthuilliers wrote:
    > Ethan Furman a ?crit :
    > 
    >> The problem I have with properties is my typing.  I'll end up 
    >> assigning to an attribute, but get the spelling slightly wrong 
    >> (capitalized, or missing an underscore -- non-obvious things when 
    >> bug-hunting), so now I have an extra attribute which of course has 
    >> zero effect on what I'm trying to do and I start getting wierd results 
    >> like viewing deleted records when I *know* I set useDeleted = False... 
    >> 30 minutes later I notice it was /supposed/ to be use_deleted.  *sigh*
    >>
    >> So -- to keep myself out of trouble -- I have started coding such 
    >> things as, for example:
    >>
    >> result = table.use_deleted()       # returns True or False
    >> table.use_deleted(False)           # skip deleted records
    >>
    >> instead of
    >>
    >> result = table.use_deleted
    >> table.use_deleted = False
    >>
    >> My question:  is this [ severely | mildly | not at all ] un-pythonic?
    > 
    > 
    > Definitly and totally unpythonic. The first solution to your problem is 
    > to stick to standard naming conventions. If this is not enough, Chris 
    > pointed you to really useful tools. Also, you can override __setattr__ 
    > to catch such errors - at least during the coding/debug phase.
    
    Good tools to know about, and a consistent naming pattern also makes 
    life easier (which I have since done ;).
    
    Let's head towards murkier waters (at least murkier to me -- hopefully 
    they can be easily clarified):  some of the attributes are read-only, 
    such as record count; others are not directly exposed, but still 
    settable, such as table version; and still others require a small amount 
    of processing... at which point do I switch from simple attribute access 
    to method access?
    
    ~Ethan~
    
    
    From gd_usenet at spamfence.net  Tue Nov 24 12:47:37 2009
    From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich)
    Date: Tue, 24 Nov 2009 18:47:37 +0100
    Subject: IDE+hg
    References: 
    Message-ID: 
    
    NiklasRTZ  wrote:
    
    >Since no py IDE I found has easy hg access.
    
    Obviously, you didn't try Eclipse with PyDev () 
    and Mercurial Eclipse () 
    plugins.
    This combination is also available stuffed into one package as 
    'EasyEclipse for Python' ().
    
    Both, pure Eclipse with plugins installed by hand, and EasyEclipse, are 
    very convenient for python development.
    
    
    
    Best regards,
    
    G?nther
    
    
    From benjamin.kaplan at case.edu  Tue Nov 24 12:50:29 2009
    From: benjamin.kaplan at case.edu (Benjamin Kaplan)
    Date: Tue, 24 Nov 2009 12:50:29 -0500
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    Message-ID: 
    
    On Tue, Nov 24, 2009 at 11:42 AM, Sibylle Koczian  wrote:
    > Hello,
    >
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    >
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    >
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    >
    > Here is a small example:
    >
    > ########################################################################
    > #!/usr/bin/env python
    > # -*- coding: utf-8 -*-
    >
    > import csv, codecs, cStringIO
    > import tempfile
    >
    > cData = [u'?rger', u'?dland', 5, u'S??igkeit', u'?l?ve', 6.9, u'for?t']
    >
    > class UnicodeWriter:
    > ? ?"""
    > ? ?A CSV writer which will write rows to CSV file "f",
    > ? ?which is encoded in the given encoding.
    > ? ?"""
    >
    > ? ?def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
    > ? ? ? ?# Redirect output to a queue
    > ? ? ? ?self.queue = cStringIO.StringIO()
    > ? ? ? ?self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
    > ? ? ? ?self.stream = f
    > ? ? ? ?self.encoder = codecs.getincrementalencoder(encoding)()
    >
    > ? ?def writerow(self, row):
    > ? ? ? ?self.writer.writerow([s.encode("utf-8") for s in row])
    
    try doing [s.encode("utf-8") if isinstance(s,unicode) else s for s in row]
    That way, you'll only encode the unicode strings
    
    
    > ? ? ? ?# Fetch UTF-8 output from the queue ...
    > ? ? ? ?data = self.queue.getvalue()
    > ? ? ? ?data = data.decode("utf-8")
    > ? ? ? ?# ... and reencode it into the target encoding
    > ? ? ? ?data = self.encoder.encode(data)
    > ? ? ? ?# write to the target stream
    > ? ? ? ?self.stream.write(data)
    > ? ? ? ?# empty queue
    > ? ? ? ?self.queue.truncate(0)
    >
    > ? ?def writerows(self, rows):
    > ? ? ? ?for row in rows:
    > ? ? ? ? ? ?self.writerow(row)
    >
    > def writewithcsv(outfile, datalist):
    > ? ?wrt = csv.writer(outfile, dialect=csv.excel)
    > ? ?wrt.writerow(datalist)
    >
    > def writeunicode(outfile, datalist):
    > ? ?wrt = UnicodeWriter(outfile)
    > ? ?wrt.writerow(datalist)
    >
    > def main():
    > ? ?with tempfile.NamedTemporaryFile() as csvfile:
    > ? ? ? ?print "CSV file:", csvfile.name
    > ? ? ? ?print "Try with csv.writer"
    > ? ? ? ?try:
    > ? ? ? ? ? ?writewithcsv(csvfile, cData)
    > ? ? ? ?except UnicodeEncodeError as e:
    > ? ? ? ? ? ?print e
    > ? ? ? ?print "Try with UnicodeWriter"
    > ? ? ? ?writeunicode(csvfile, cData)
    > ? ?print "Ready."
    >
    > if __name__ == "__main__":
    > ? ?main()
    >
    >
    > ##############################################################################
    >
    > Hoping for advice,
    >
    > Sibylle
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    
    
    From gd_usenet at spamfence.net  Tue Nov 24 12:54:45 2009
    From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich)
    Date: Tue, 24 Nov 2009 18:54:45 +0100
    Subject: IDE+hg
    References: 
    	
    Message-ID: <68jtt6-oi.ln1@spamfence.net>
    
    In article ,
     "G?nther Dietrich"  wrote:
    
    >>Since no py IDE I found has easy hg access.
    >
    >Obviously, you didn't try Eclipse with PyDev () 
    >and Mercurial Eclipse () 
    >plugins.
    >This combination is also available stuffed into one package as 
    >'EasyEclipse for Python' ().
    
    Correction: EasyEclipse for Python does not contain the Mercurial 
    Eclipse plugin. That has to be installed by hand in both cases.
    
    
    
    Sorry,
    
    G?nther
    
    
    From claird.visiprise at gmail.com  Tue Nov 24 12:59:28 2009
    From: claird.visiprise at gmail.com (Cameron Laird)
    Date: Tue, 24 Nov 2009 09:59:28 -0800 (PST)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    Message-ID: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    
    QOTW:  "... it's generally accepted that COM sucks rocks through
    straws, so
    explore alternatives when they're available ;-)" - Chris Withers
        http://groups.google.com/group/comp.lang.python/msg/29577c851ceed167
    
    
        From nothing to a complete working program - Peter Otten on
    stepwise
        refinement:
            http://groups.google.com/group/comp.lang.python/t/f6f44b646af5b09e/8f59b2585da524a1?#8f59b2585da524a1
    
        Handling whitespace in command line arguments:
            http://groups.google.com/group/comp.lang.python/t/9a828279953b45a2/
    
        Recognizing hex arguments in the command line:
            http://groups.google.com/group/comp.lang.python/t/31d4c9386291c/
    
        A pipeline of Python programs:
            http://groups.google.com/group/comp.lang.python/t/cc06520602ae3f42/
    
        Calling Python functions from Excel
            http://groups.google.com/group/comp.lang.python/t/83aa60666c555d87/
    
        The scope of interactive commands:   =20
            http://groups.google.com/group/comp.lang.python/t/3f0d7607ed5a4a78/
    
        List comprehensions and slice assignments - which are the
    corresponding
        operations for dictionaries?
            http://groups.google.com/group/comp.lang.python/t/7aa443ac48f58851/
    
        The precise semantics of [:]=20
            http://groups.google.com/group/comp.lang.python/t/84b5ec30cdd26cde/
    
        The 'with' statement doesn't allow () for implicit line
    continuation:
            http://comments.gmane.org/gmane.comp.python.general/645508
    
        Grant Edwards on the best way to get help from this group :)
            http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    
        Finding the root cause of slowness when sorting certain objects:
            http://groups.google.com/group/comp.lang.python/t/44d80224360e085/
    
        The fastest alternative to list.extend()
            http://groups.google.com/group/comp.lang.python/t/614bfc36a09d9ab7/
    
        A library for bijective mappings:
            http://groups.google.com/group/comp.lang.python/t/785d100681f7d101/
    
        GUI builders reviewed:
            http://groups.google.com/group/comp.lang.python/t/3db5b18d77974b8/
    
        A long thread started two weeks ago: is Python not scalable enough
    for
        Google?
            http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/
    
    
    ========================================================================
    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
    enthusiasts":
            http://pythonpapers.org/
        The Python Magazine is a technical monthly devoted to Python:
            http://pythonmagazine.com
    
        Readers have recommended the "Planet" site:
            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/
    
        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.com
    p.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
    
        Enjoy the *Python Magazine*.
            http://pymag.phparch.com/
    
        *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.p
    ython.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 python-url at phaseit.net  Tue Nov 24 13:14:19 2009
    From: python-url at phaseit.net (Gabriel Genellina)
    Date: Tue, 24 Nov 2009 18:14:19 +0000 (UTC)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    Message-ID: 
    
    QOTW:  "... it's generally accepted that COM sucks rocks through straws, so
    explore alternatives when they're available ;-)" - Chris Withers
        http://groups.google.com/group/comp.lang.python/msg/29577c851ceed167
        
        
        From nothing to a complete working program - Peter Otten on stepwise
        refinement:
            http://groups.google.com/group/comp.lang.python/t/f6f44b646af5b09e/8f59b2585da524a1?#8f59b2585da524a1
        
        Handling whitespace in command line arguments:
            http://groups.google.com/group/comp.lang.python/t/9a828279953b45a2/
        
        Recognizing hex arguments in the command line:
            http://groups.google.com/group/comp.lang.python/t/31d4c9386291c/
        
        A pipeline of Python programs:
            http://groups.google.com/group/comp.lang.python/t/cc06520602ae3f42/
        
        Calling Python functions from Excel
            http://groups.google.com/group/comp.lang.python/t/83aa60666c555d87/
        
        The scope of interactive commands:   =20
            http://groups.google.com/group/comp.lang.python/t/3f0d7607ed5a4a78/
        
        List comprehensions and slice assignments - which are the corresponding
        operations for dictionaries?
            http://groups.google.com/group/comp.lang.python/t/7aa443ac48f58851/
        
        The precise semantics of [:]=20
            http://groups.google.com/group/comp.lang.python/t/84b5ec30cdd26cde/
        
        The 'with' statement doesn't allow () for implicit line continuation:
            http://comments.gmane.org/gmane.comp.python.general/645508
        
        Grant Edwards on the best way to get help from this group :)
            http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
        
        Finding the root cause of slowness when sorting certain objects:
            http://groups.google.com/group/comp.lang.python/t/44d80224360e085/
        
        The fastest alternative to list.extend()
            http://groups.google.com/group/comp.lang.python/t/614bfc36a09d9ab7/
        
        A library for bijective mappings:
            http://groups.google.com/group/comp.lang.python/t/785d100681f7d101/
        
        GUI builders reviewed:
            http://groups.google.com/group/comp.lang.python/t/3db5b18d77974b8/
        
        A long thread started two weeks ago: is Python not scalable enough for
        Google?
            http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/
        
        
    ========================================================================
    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 enthusiasts":
    	http://pythonpapers.org/
        The Python Magazine is a technical monthly devoted to Python:
    	http://pythonmagazine.com
    
        Readers have recommended the "Planet" site:
    	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/
    
        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
    
        Enjoy the *Python Magazine*.
    	http://pymag.phparch.com/
    
        *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 solipsis at pitrou.net  Tue Nov 24 13:17:17 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 18:17:17 +0000 (UTC)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    	
    	<1bafb82e-fe19-4a4f-a172-f1224cb1a314@h10g2000vbm.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 09:27:24 -0800, sturlamolden a ?crit?:
    > 
    > Windows does not have daemons, so this is obviously incorrect. (There
    > are something called Windows Services, but multiprocessing does not use
    > them.)
    
    This is nitpicking. Technically it might not be a daemon but it's used as 
    such.
    The important point is that it does use a (custom) form of RPC through 
    marshalling, which is what the original question was about.
    
    
    
    From cjns1989 at gmail.com  Tue Nov 24 13:19:10 2009
    From: cjns1989 at gmail.com (Chris Jones)
    Date: Tue, 24 Nov 2009 13:19:10 -0500
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: <031bc732$0$1336$c3e8da3@news.astraweb.com>
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <20091124181910.GB3122@turki.gavron.org>
    
    On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    
    > Good grief, it's about six weeks away from 2010 and Thunderbird still 
    > uses mbox as it's default mail box format. Hello, the nineties called, 
    > they want their mail formats back! Are the tbird developers on crack or 
    > something? I can't believe that they're still using that crappy format.
    > 
    > No, I tell a lie. I can believe it far too well.
    
    :-)
    
    I realize that's somewhat OT, but what mail box format do you recommend,
    and why?
    
    Thanks,
    
    CJ
    
    
    From jabronson at gmail.com  Tue Nov 24 13:21:58 2009
    From: jabronson at gmail.com (Joshua Bronson)
    Date: Tue, 24 Nov 2009 10:21:58 -0800 (PST)
    Subject: python bijection
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com>
    Message-ID: 
    
    Hey Raymond,
    
    Thanks for your thoughtful reply! I think your idea for a class-
    generation approach in the spirit of namedtuple is brilliant; looking
    forward to coding this up and seeing how it feels to use it.
    
    (By the way, it occurred to me that "bijection" is perhaps the wrong
    term to use for this data structure; really it's just an injective
    mapping, as it has no idea whether the function whose mappings it
    contains is also surjective. (Unless we take the domain, codomain, and
    range of the function being modeled to be exactly defined by the state
    of the mapping at any given time. But it feels more correct to me to
    interpret the mapping as a sampling of some underlying function, where
    the sampling can change but the function stays the same.) So I'm
    thinking of renaming the class injectivedict or idict instead of
    bijection. Is that crazy?)
    
    More responses inline:
    
    On Nov 21, 9:22?pm, Raymond Hettinger  wrote:
    > * The idea of using __call__ for looking-up inverse values was
    > inspired. ?That is useable, clean, and easy to remember; however, as
    > discussed below, there are issues though with its actual use in real
    > code.
    
    Totally agree the call syntax has issues. Did you happen to see
    Terry's suggestion to use slice syntax instead? Now *that* was
    inspired. It's also much better because it works for setitem and
    delitem too. I replaced the call syntax with the slice syntax on
    Friday night -- would be interested to hear whether you think it's an
    improvement.
    
    
    > * Am not excited by the inverse iterators. ?With just a regular
    > mapping you can write:
    >
    > ? ? ? ? for a, b in m.items() ... ? # consider either a or b be the
    > key and the other to be the value
    >
    > ? That meets all of the needs that would have been served by
    > iter_inverse_keys() or iter_inverse_values() or whatnot. ?The mirrored
    > API doesn't really provide much in the way of value added.
    
    Hm, the one value I see the latest version of ``inverted`` adding (may
    not have been in the version you saw) is that you can pass it either a
    mapping, an iterable, or any object implementing an __inverted__
    method. So in one case it's just syntax sugar for writing [(v, k) for
    (k, v) in d.items()], but in other cases it's providing some
    abstraction.
    
    
    
    > Hope these ideas help. ?The ultimate success of the Bijection code
    > will depend on its clarity, simplicity, and speed. ?Experiment with
    > various approaches to find-out which looks the best in real code. ?It
    > cannot be error-prone or it is doomed. ?Also, it should not introduce
    > much overhead processing or else people will avoid it. ?The API should
    > be trivially simple so that people remember how to use it months after
    > seeing it for the first time.
    
    Thank you for the sage advice.
    
    Best,
    Josh
    
    
    From clp2 at rebertia.com  Tue Nov 24 13:25:37 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 10:25:37 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4B0C1A4E.7050204@stoneleaf.us>
    References: 
    	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	<4B0C1A4E.7050204@stoneleaf.us>
    Message-ID: <50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 9:39 AM, Ethan Furman  wrote:
    > Bruno Desthuilliers wrote:
    >> Ethan Furman a ?crit :
    >>> The problem I have with properties is my typing. ?I'll end up assigning
    >>> to an attribute, but get the spelling slightly wrong (capitalized, or
    >>> missing an underscore -- non-obvious things when bug-hunting), so now I have
    >>> an extra attribute which of course has zero effect on what I'm trying to do
    >>> and I start getting wierd results like viewing deleted records when I *know*
    >>> I set useDeleted = False... 30 minutes later I notice it was /supposed/ to
    >>> be use_deleted. ?*sigh*
    >>>
    >>> So -- to keep myself out of trouble -- I have started coding such things
    >>> as, for example:
    >>>
    >>> result = table.use_deleted() ? ? ? # returns True or False
    >>> table.use_deleted(False) ? ? ? ? ? # skip deleted records
    >>>
    >>> instead of
    >>>
    >>> result = table.use_deleted
    >>> table.use_deleted = False
    >>>
    >>> My question: ?is this [ severely | mildly | not at all ] un-pythonic?
    >>
    >>
    >> Definitly and totally unpythonic. The first solution to your problem is to
    >> stick to standard naming conventions. If this is not enough, Chris pointed
    >> you to really useful tools. Also, you can override __setattr__ to catch such
    >> errors - at least during the coding/debug phase.
    >
    > Good tools to know about, and a consistent naming pattern also makes life
    > easier (which I have since done ;).
    >
    > Let's head towards murkier waters (at least murkier to me -- hopefully they
    > can be easily clarified): ?some of the attributes are read-only, such as
    > record count; others are not directly exposed, but still settable, such as
    > table version; and still others require a small amount of processing... at
    > which point do I switch from simple attribute access to method access?
    
    Thanks to the magic of properties, the end-user-programmer need not
    know which you're using:
    
    http://docs.python.org/library/functions.html#property
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From solipsis at pitrou.net  Tue Nov 24 13:25:37 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 18:25:37 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a ?crit?:
    > As you
    > point out, a lot of this RISC vs. CISC analysis (and inferences drawn
    > from Python bytecode analysis) is somewhat academic: the cost of the
    > JUMP_IF_FALSE instruction is likely to be minimal in the context of all
    > the activity going on to evaluate the bytecodes.
    
    Sorry, I have trouble parsing your sentence. Do you mean bytecode 
    interpretation overhead is minimal compared to the cost of actual useful 
    work, or the contrary?
    (IMO both are wrong by the way)
    
    > I imagine that someone (or a number of people) must have profiled the
    > Python interpreter and shown how much time goes on the individual
    > bytecode implementations and how much goes on the interpreter's own
    > housekeeping activities.
    
    Well the one problem is that it's not easy to draw a line. Another 
    problem is that it depends on the workload. If you are compressing large 
    data or running expensive regular expressions the answer won't be the 
    same as if you compute a Mandelbrot set in pure Python.
    
    One data point is that the "computed gotos" option in py3k generally 
    makes the interpreter faster by ~15%. Another data point I've heard is 
    that people who have tried a very crude form of Python-to-C compilation 
    (generating the exact C code corresponding to a function or method, using 
    Python's C API and preserving dynamicity without attempting to be clever) 
    have apparently reached speedups of up to 50% (in other words, "twice as 
    fast"). So you could say that the interpretation overhead is generally 
    between 15% and 50%.
    
    
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 13:45:27 2009
    From: x.sanz35 at gmail.com (Xavier)
    Date: Tue, 24 Nov 2009 10:45:27 -0800 (PST)
    Subject: multiprocessing.connection with ssl
    Message-ID: <8ff1698c-8205-4171-9e41-2e382bd52e89@g23g2000vbr.googlegroups.com>
    
    Hello
    
    I've hacked multiprocessing.connection (in a basic way) to allow ssl
    encryption using ssl.wrap_socket.
    
    Anybody knows how i can contribute this to main developers?
    
    Thanks in advance
    
    
    From __peter__ at web.de  Tue Nov 24 14:04:42 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 20:04:42 +0100
    Subject: csv and mixed lists of unicode and numbers
    References: 
    Message-ID: 
    
    Sibylle Koczian wrote:
    
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    > 
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    > 
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    
    I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    up with. Example:
    
    def recode_rows(rows, source_encoding, target_encoding):
        def recode(field):
            if isinstance(field, unicode):
                return field.encode(target_encoding)
            elif isinstance(field, str):
                return unicode(field, source_encoding).encode(target_encoding)
            return unicode(field).encode(target_encoding)
    
        return (map(recode, row) for row in rows)
    
    rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    writer = csv.writer(sys.stdout)
    writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    
    The only limitation I can see: target_encoding probably has to be a superset 
    of ASCII.
    
    Peter
    
    
    
    From tim.wintle at teamrubber.com  Tue Nov 24 14:16:18 2009
    From: tim.wintle at teamrubber.com (Tim Wintle)
    Date: Tue, 24 Nov 2009 19:16:18 +0000
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	
    Message-ID: <1259090178.661.34.camel@localhost>
    
    On Tue, 2009-11-24 at 18:25 +0000, Antoine Pitrou wrote:
    > Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a ?crit :
    > > As you
    > > point out, a lot of this RISC vs. CISC analysis (and inferences
    > drawn
    > > from Python bytecode analysis) is somewhat academic: the cost of the
    > > JUMP_IF_FALSE instruction is likely to be minimal in the context of
    > all the activity going on to evaluate the bytecodes.
    > 
    > Sorry, I have trouble parsing your sentence. Do you mean bytecode 
    > interpretation overhead is minimal compared to the cost of actual
    > useful work, or the contrary?
    > (IMO both are wrong by the way)
    
    Out of interest - has anyone else spotted that the call to
    PyObject_IsTrue in the XXX_JUMP_IF_YYYY blocks performs two unnecessary
    pointer comparisons?
    
    ==== ceval.c ====
    if (w == Py_True) {
        Py_DECREF(w);
        FAST_DISPATCH();
    }
    if (w == Py_False) {
        Py_DECREF(w);
        JUMPTO(oparg);
        FAST_DISPATCH();
    }
    err = PyObject_IsTrue(w);
    Py_DECREF(w);
    .
    .
    .
    ==================
    
    ==== object.c ====
    PyObject_IsTrue(PyObject *v)
    {
            Py_ssize_t res;
            if (v == Py_True)
                    return 1;
            if (v == Py_False)
                    return 0;
    .
    .
    .
    ==================
    
    Would it be worth in-lining the remaining part of PyObject_IsTrue in
    ceval?
    
    > Another data point I've heard is that people who have tried a very
    > crude form of Python-to-C compilation (generating the exact C code
    > corresponding to a function or method, using Python's C API and
    > preserving dynamicity without attempting to be clever) have apparently
    > reached speedups of up to 50% (in other words, "twice as fast").
    
    That's roughly what I get with Cython - which does exactly that.
    
    Tim
    
    
    
    From utabintarbo at gmail.com  Tue Nov 24 14:52:24 2009
    From: utabintarbo at gmail.com (utabintarbo)
    Date: Tue, 24 Nov 2009 11:52:24 -0800 (PST)
    Subject: Raw strings as input from File?
    Message-ID: 
    
    I have a log file with full Windows paths on a line. eg:
    K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    
    As I try to pull in the line and process it, python changes the "\10"
    to a "\x08". This is before I can do anything with it. Is there a way
    to specify that incoming lines (say, when using .readlines() ) should
    be treated as raw strings?
    
    TIA
    
    
    From lie.1296 at gmail.com  Tue Nov 24 15:04:06 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Wed, 25 Nov 2009 07:04:06 +1100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	
    Message-ID: <4b0c3c90$1@dnews.tpgi.com.au>
    
    Ethan Furman wrote:
    > 
    > Good tools to know about, and a consistent naming pattern also makes 
    > life easier (which I have since done ;).
    > 
    > Let's head towards murkier waters (at least murkier to me -- hopefully 
    > they can be easily clarified):  some of the attributes are read-only, 
    > such as record count; others are not directly exposed, but still 
    > settable, such as table version; and still others require a small amount 
    > of processing... at which point do I switch from simple attribute access 
    > to method access?
    > 
    > ~Ethan~
    
    method accessor is not pythonic, use property
    
    property can be read-only, write-only (!), and it can process data 
    before returning and setting the real attributes.
    
    
    From bdesth.quelquechose at free.quelquepart.fr  Tue Nov 24 15:21:01 2009
    From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 21:21:01 +0100
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    In-Reply-To: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    Message-ID: <4b0c4dbb$0$8926$426a74cc@news.free.fr>
    
    Cameron Laird a ?crit :
    
    > 
    >     Grant Edwards on the best way to get help from this group :)
    >         http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    > 
    
    This one really deserves a POTM award !-)
    
    
    From python at mrabarnett.plus.com  Tue Nov 24 15:27:39 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Tue, 24 Nov 2009 20:27:39 +0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: <4B0C41BB.40401@mrabarnett.plus.com>
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08". This is before I can do anything with it. Is there a way
    > to specify that incoming lines (say, when using .readlines() ) should
    > be treated as raw strings?
    > 
    .readlines() doesn't change the "\10" in a file to "\x08" in the string
    it returns.
    
    Could you provide some code which shows your problem?
    
    
    From carsten.haese at gmail.com  Tue Nov 24 15:28:30 2009
    From: carsten.haese at gmail.com (Carsten Haese)
    Date: Tue, 24 Nov 2009 15:28:30 -0500
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08".
    
    Python does no such thing. When Python reads bytes from a file, it
    doesn't interpret or change those bytes in any way. Either there is
    something else going on here that you're not telling us, or the file
    doesn't contain what you think it contains. Please show us the exact
    code you're using to process this file, and show us the exact contents
    of the file you're processing.
    
    --
    Carsten Haese
    http://informixdb.sourceforge.net
    
    
    
    From ethan at stoneleaf.us  Tue Nov 24 15:59:15 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Tue, 24 Nov 2009 12:59:15 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    References: 	
    	<4b0b92de$0$14677$426a74cc@news.free.fr>	
    	<4B0C1A4E.7050204@stoneleaf.us>
    	<50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    Message-ID: <4B0C4923.6080008@stoneleaf.us>
    
    Chris Rebert wrote:
    > On Tue, Nov 24, 2009 at 9:39 AM, Ethan Furman  wrote:
    > 
    >>Bruno Desthuilliers wrote:
    >>
    >>>Ethan Furman a ?crit :
    >>>
    >>>>The problem I have with properties is my typing.  I'll end up assigning
    >>>>to an attribute, but get the spelling slightly wrong (capitalized, or
    >>>>missing an underscore -- non-obvious things when bug-hunting), so now I have
    >>>>an extra attribute which of course has zero effect on what I'm trying to do
    >>>>and I start getting wierd results like viewing deleted records when I *know*
    >>>>I set useDeleted = False... 30 minutes later I notice it was /supposed/ to
    >>>>be use_deleted.  *sigh*
    >>>>
    >>>>So -- to keep myself out of trouble -- I have started coding such things
    >>>>as, for example:
    >>>>
    >>>>result = table.use_deleted()       # returns True or False
    >>>>table.use_deleted(False)           # skip deleted records
    >>>>
    >>>>instead of
    >>>>
    >>>>result = table.use_deleted
    >>>>table.use_deleted = False
    >>>>
    >>>>My question:  is this [ severely | mildly | not at all ] un-pythonic?
    >>>
    >>>
    >>>Definitly and totally unpythonic. The first solution to your problem is to
    >>>stick to standard naming conventions. If this is not enough, Chris pointed
    >>>you to really useful tools. Also, you can override __setattr__ to catch such
    >>>errors - at least during the coding/debug phase.
    >>
    >>Good tools to know about, and a consistent naming pattern also makes life
    >>easier (which I have since done ;).
    >>
    >>Let's head towards murkier waters (at least murkier to me -- hopefully they
    >>can be easily clarified):  some of the attributes are read-only, such as
    >>record count; others are not directly exposed, but still settable, such as
    >>table version; and still others require a small amount of processing... at
    >>which point do I switch from simple attribute access to method access?
    > 
    > 
    > Thanks to the magic of properties, the end-user-programmer need not
    > know which you're using:
    > 
    > http://docs.python.org/library/functions.html#property
    
    You know, when I first read that bit on properties a while back, the 
    explanation of the decorators and how a property was also a decorator 
    for the setter and deleter bits completely lost me.  Since then I've 
    played with decorators a bit, written a configaration module that uses 
    them, and just now, reading the description... it was so elegantly 
    simple it almost brought tears to my eyes *sniff*.  I love Python.
    
    Okay, I'll go back and switch all my attributes *back* to attributes -- 
    and properties will be much nicer than my original implementation (using 
    __getattr__ and __setattr__).
    
    Many thanks to all who answered!
    
    ~Ethan~
    
    
    From vinay_sajip at yahoo.co.uk  Tue Nov 24 15:59:52 2009
    From: vinay_sajip at yahoo.co.uk (Vinay Sajip)
    Date: Tue, 24 Nov 2009 12:59:52 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    	
    	
    	<9750596d-4d09-478a-a9df-942e44a4e83a@t18g2000vbj.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 3:14?pm, Ron Barak  wrote:
    > Many thanks Soltys, that did the trick (actually, no need for setting
    > propagate to 0), namely,
    >
    [snip]
    
    It might work for now, but instantiating a handler in an instance
    constructor can be an anti-pattern. If you ever create multiple client
    instances, for example, you would create multiple handlers and add
    those to the logger (which is essentially persistent for the lifetime
    of the process), which could result in multiple messages, corrupted
    output or exceptions (in the general case).
    
    It's generally better to declare module-level loggers via
    
    logger = logging.getLogger(__name__)
    
    or, if better granularity is wanted, loggers with names prefixed by
    __name__ + '.' - and handler set up should typically be done in one
    place in such a way as to not inadvertently create handlers multiple
    times. A common pattern is to just add handlers to the root logger
    (e.g. the basicConfig() API does this) - other loggers automatically
    get to use them, under normal circumstances.
    
    Regards,
    
    Vinay Sajip
    
    
    From nulla.epistola at web.de  Tue Nov 24 16:01:55 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Tue, 24 Nov 2009 22:01:55 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    	
    Message-ID: 
    
    Peter Otten schrieb:
    > I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    > up with. Example:
    > 
    > def recode_rows(rows, source_encoding, target_encoding):
    >     def recode(field):
    >         if isinstance(field, unicode):
    >             return field.encode(target_encoding)
    >         elif isinstance(field, str):
    >             return unicode(field, source_encoding).encode(target_encoding)
    >         return unicode(field).encode(target_encoding)
    > 
    >     return (map(recode, row) for row in rows)
    > 
    
    For this case isinstance really seems to be quite reasonable. And it was
    silly of me not to think of sys.stdout as file object for the example!
    
    > rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    > writer = csv.writer(sys.stdout)
    > writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    > 
    > The only limitation I can see: target_encoding probably has to be a superset 
    > of ASCII.
    > 
    
    Coping with umlauts and accents is quite enough for me.
    
    This problem really goes away with Python 3 (tried it on another
    machine), but something else changes too: in Python 2.6 the
    documentation for the csv module explicitly says "If csvfile is a file
    object, it must be opened with the ?b? flag on platforms where that
    makes a difference." The documentation for Python 3.1 doesn't have this
    sentence, and if I do that in Python 3.1 I get for all sorts of data,
    even for a list with only one integer literal:
    
    TypeError: must be bytes or buffer, not str
    
    I don't really understand that.
    
    Regards,
    Sibylle
    
    
    From keith.hughitt at gmail.com  Tue Nov 24 16:04:18 2009
    From: keith.hughitt at gmail.com (Keith Hughitt)
    Date: Tue, 24 Nov 2009 13:04:18 -0800 (PST)
    Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5?
    References: 
    	<4b063a25$0$1668$742ec2ed@news.sonic.net>
    Message-ID: 
    
    Hi John,
    
    Thanks for the suggestions: I have finally been able to get it
    working :)
    
    In anyone else runs into the same problem, here is some example code
    that works in Python 2.4+:
    
    ============= Begin Example ==================
    
    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    import sys
    def main():
        import MySQLdb, getpass
    
        admin = raw_input("Database admin: ")
        pw = getpass.getpass("Password: ")
        db = MySQLdb.connect(use_unicode=True, charset = "utf8",
    user=admin, passwd=pw)
    
        cursor = db.cursor()
        try:
            cursor.execute("DROP DATABASE IF EXISTS unicode_test;")
            cursor.execute("CREATE DATABASE unicode_test DEFAULT CHARACTER
    SET utf8;")
        except:
            print ""
    
        cursor.execute('''
        CREATE TABLE `unicode_test`.`test` (
          `id`          SMALLINT unsigned NOT NULL AUTO_INCREMENT,
          `name`        VARCHAR(255) NOT NULL,
           PRIMARY KEY (`id`), INDEX (`id`)
        ) DEFAULT CHARSET=utf8;''')
    
        cursor.execute("INSERT INTO `unicode_test`.`test` VALUES (NULL,
    '%s');" % u"?ngstr?m")
    
        # Test 1
        print "Just printing: %s" % '?ngstr?m'
    
        # Test 2
        cursor.execute("SELECT name FROM unicode_test.test;")
        print "From database: %s" % cursor.fetchone()[0]
    
        # Test 3 (Manual)
        print 'To verify manually: mysql -u %s -p -e "SELECT name FROM
    unicode_test.test"' % admin
    
    if __name__ == '__main__':
        sys.exit(main())
    
    ============= End Example ====================
    
    Thanks all for taking the time to help!
    
    Best,
    Keith
    
    
    From jasewarren at gmail.com  Tue Nov 24 16:08:27 2009
    From: jasewarren at gmail.com (Jase)
    Date: Tue, 24 Nov 2009 13:08:27 -0800 (PST)
    Subject: Creating a drop down filter in Admin site
    Message-ID: <46ba87ce-6843-4d89-b80c-4f3c1e20bc09@e22g2000vbm.googlegroups.com>
    
    Hoping someone could help me out. I am updating an admin site and
    added a couple "list_filter"s. They are rather long so I wanted to
    turn them into a drop down filter. Can this be done? Any suggestions?
    
    Thanks,
    
    Jase
    
    
    From lie.1296 at gmail.com  Tue Nov 24 16:17:09 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Wed, 25 Nov 2009 08:17:09 +1100
    Subject: Where to put the error handing test?
    In-Reply-To: 
    References: 	<4b0b56ea$1@dnews.tpgi.com.au>	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>	<4B0BBC62.7020702@ieee.org>
    	
    Message-ID: <4b0c4db0@dnews.tpgi.com.au>
    
    Peng Yu wrote:
    > On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel  wrote:
    
    I'll put an extra emphasis on this:
    >> Your question is so open-ended as to be unanswerable.  
    ========================================================
    
    > I'll still confused by the guideline that an error should be caught as
    > early as possible.
    
    but not too early. Errors must be RAISED as early as possible. Errors 
    must be CAUGHT as soon as there is enough information to handle the errors.
    
    > Suppose I have the following call chain
    > 
    > f1() --> f2() --> f3() --> f4()
    > 
    > The input in f1() might cause an error in f4(). However, this error
    > can of cause be caught by f1(), whenever I want to do so. In the worst
    > case, I could duplicate the code of f2 and f3, and the test code in f4
    > to f1(), to catch the error in f1 rather than f4. But I don't think
    > that this is what you mean.
    
    Why would f1() have faulty data? Does it come from external input? Then 
    the input must be invalidated at f1(). Then f2(), f3(), and f4() does 
    not require any argument checking since it is assumed that f1() calls 
    them with good input.
    
    Of course, there is cases where data validation may not be on f1. For 
    example, if f1() is a function that receives keyboard input for a 
    filename f1 validates whether the filename is valid. Then f2 might open 
    the file and validate that the file is of the expected type (if f2 
    expect a .csv file, but given an .xls file, f2 would scream out an 
    error). f3 received rows/lines of data from f2 and extracts 
    fields/columns from the rows; but some of the data might be faulty and 
    these must be filtered out before the data is transformed by the f4. f4 
    assumes f3 cleans the row and so f4 is does not do error-checking. The 
    transformed data then is rewritten back by f3. Now there is an f5 which 
    creates new data, the new data needs to be transformed by f4 as well and 
    since f5 creates a new data, there is no way for it to create invalid 
    data. Now assume f6 merges new data from another csv file; f6's data 
    will also be transformed by f4, f6 can use the same validation as in f3 
    but why not turn f2,f3 instead to open the other file? Now f7 will merge 
    data from multiple f3 streams and transforms by f4. Then comes f8 which 
    creates new data from user input, the user-inputted data will need some 
    checking; and now we have trouble since the data validation is inside 
    f3. But we can easily factor out the validation part into f9 and call f9 
    from f3 and f8.
    
    The example case still checks for problem as early as possible. It 
    checks for problem when it is possible to determine whether a particular 
    condition is problematic. The as early as possible guideline does not 
    mean f1, a filename input function, must check whether the csv fields 
    contains valid data. But f2, the file opening function, must be given a 
    valid filename; f3, the file parser, must be given a valid file object 
    with the proper type; f4, the transformer, must be given a valid row to 
    transform; etc. f2 should not need to check it is given a valid 
    filename, it's f1 job to validate it; f3 should not need to check 
    whether the file object is of the proper type; f4 should not need to 
    check it is given a valid row tuple; and so on...
    
    > Then the problem is where to put the test code more effectively. I
    > would consider 'whether it is obvious to test the condition in the
    > give function' as the guideline. However, it might be equal obvious to
    > test the same thing two functions, for example, f1 and f4.
    > 
    > In this case, I thought originally that I should put the test code in
    > f1 rather than f4, if f1, f2, f3 and f4 are all the functions that I
    > have in the package that I am making. But it is possible that some
    > time later I added the function f5(),...,f10() that calls f4(). Since
    > f4 doesn't have the test code, f5(),...,f10() should have the same
    > test code. This is clearly a redundancy to the code. If I move the
    > test code to f4(), there is a redundancy of the code between f1 and
    > f4.
    
    I can't think of a good example where such redundancy would happen and 
    there is no other, better way to walk around it. Could you provide a 
    CONCRETE example? One that might happen, instead one that could 
    theoretically happen.
    
    
    From bruno.desthuilliers at gmail.com  Tue Nov 24 16:17:13 2009
    From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com)
    Date: Tue, 24 Nov 2009 13:17:13 -0800 (PST)
    Subject: Newsgroup for beginners
    References: 
    	<7xiqd9yj8v.fsf@ruckus.brouhaha.com>  
    	
    	
    Message-ID: <4e0945a3-61e8-4772-9093-231e470a6641@x15g2000vbr.googlegroups.com>
    
    On 20 nov, 20:42, Ethan Furman  wrote:
    > Aahz wrote:
    > > In article ,
    > > Grant Edwards ? wrote:
    >
    > >>You've really got to try pretty hard to create one. ?But if you
    > >>want to, here's how to do it:
    >
    > >>1) Start by complaining that your program doesn't work because
    > >> ? of a bug in Python.
    >
    > >> [...]
    >
    > > Post of the month!
    >
    > I'll second that! ?I really needed a good laugh. ?Many thanks!
    
    So I'll thrice it - FWIW it indeed made it's way to the weekly python
    (thanks the python-url team), but deserves much more than that. I was
    so hilarious my son came out of it's room and even tried to read the
    post by himself - I just wasn't able to calm down and explain him what
    this was about.
    
    Grant, if we ever meet, remind me to pay you a couple beers. Cheers !
    
    
    From utabintarbo at gmail.com  Tue Nov 24 16:20:25 2009
    From: utabintarbo at gmail.com (utabintarbo)
    Date: Tue, 24 Nov 2009 13:20:25 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    Message-ID: 
    
    On Nov 24, 3:27?pm, MRAB  wrote:
    >
    > .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > it returns.
    >
    > Could you provide some code which shows your problem?
    
    Here is the code block I have so far:
    for l in open(CONTENTS, 'r').readlines():
        f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
        if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
            shutil.rmtree(os.path.join(DIR1,f))
    	if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    		shutil.rmtree(os.path.join(DIR2,f))
    
    I am trying to find dirs with the basename of the initial path less
    the extension in both DIR1 and DIR2
    
    A minimally obfuscated line from the log file:
    K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602
    
    What I get from the debugger/python shell:
    'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602'
    
    TIA
    
    
    
    From joncle at googlemail.com  Tue Nov 24 16:36:58 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:36:58 -0800 (PST)
    Subject: Creating a drop down filter in Admin site
    References: <46ba87ce-6843-4d89-b80c-4f3c1e20bc09@e22g2000vbm.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 9:08?pm, Jase  wrote:
    > Hoping someone could help me out. I am updating an admin site and
    > added a couple "list_filter"s. They are rather long so I wanted to
    > turn them into a drop down filter. Can this be done? Any suggestions?
    >
    > Thanks,
    >
    > Jase
    
    I'm guessing you mean Django - You may well get advice here, but the
    "Django Users" google group and the associated documentation of
    djangoproject and how to customise the admin interface is your best
    start.
    
    hth,
    Jon.
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 16:45:37 2009
    From: x.sanz35 at gmail.com (Xavier Sanz)
    Date: Tue, 24 Nov 2009 13:45:37 -0800 (PST)
    Subject: Securing a multiprocessing.BaseManager connection via SSL
    References: 
    Message-ID: <221434b3-839d-49db-8c08-4c1f1ececd5f@p33g2000vbn.googlegroups.com>
    
    Hi Jonas
    
    I've having same need so i found a solution but you need to hack a bit
    
    I am using python 2.6.3 but i suppose it could be applicable to your
    case.
    
    First of all u need to edit /usr/lib/python2.6/lib/python2.6/
    multiprocessing/connection.py
    
    This is mine:
    
    #
    # A higher level module for using sockets (or Windows named pipes)
    #
    # multiprocessing/connection.py
    #
    # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
    #
    
    __all__ = [ 'Client', 'Listener', 'Pipe' ]
    
    import os
    import sys
    import socket
    import errno
    import time
    import tempfile
    import itertools
    # Added by Xavi
    import ssl
    
    import _multiprocessing
    from multiprocessing import current_process, AuthenticationError
    from multiprocessing.util import get_temp_dir, Finalize, sub_debug,
    debug
    from multiprocessing.forking import duplicate, close
    
    
    #
    #
    #
    
    BUFSIZE = 8192
    
    _mmap_counter = itertools.count()
    
    default_family = 'AF_INET'
    families = ['AF_INET']
    
    if hasattr(socket, 'AF_UNIX'):
        default_family = 'AF_UNIX'
        families += ['AF_UNIX']
    
    if sys.platform == 'win32':
        default_family = 'AF_PIPE'
        families += ['AF_PIPE']
    
    #
    #
    #
    
    def arbitrary_address(family):
        '''
        Return an arbitrary free address for the given family
        '''
        if family == 'AF_INET':
            return ('localhost', 0)
        elif family == 'AF_UNIX':
            return tempfile.mktemp(prefix='listener-', dir=get_temp_dir())
        elif family == 'AF_PIPE':
            return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
                                   (os.getpid(), _mmap_counter.next()))
        else:
            raise ValueError('unrecognized family')
    
    
    def address_type(address):
        '''
        Return the types of the address
    
        This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
        '''
        if type(address) == tuple:
            return 'AF_INET'
        elif type(address) is str and address.startswith('\\\\'):
            return 'AF_PIPE'
        elif type(address) is str:
            return 'AF_UNIX'
        else:
            raise ValueError('address type of %r unrecognized' % address)
    
    #
    # Public functions
    #
    
    class Listener(object):
        '''
        Returns a listener object.
    
        This is a wrapper for a bound socket which is 'listening' for
        connections, or for a Windows named pipe.
        '''
        def __init__(self, address=None, family=None, backlog=1,
    authkey=None, sslsock=True):
            family = family or (address and address_type(address)) \
                     or default_family
            address = address or arbitrary_address(family)
    
            if family == 'AF_PIPE':
                self._listener = PipeListener(address, backlog)
            else:
                self._listener = SocketListener(address, family, backlog,
    sslsock)
            if authkey is not None and not isinstance(authkey, bytes):
                raise TypeError, 'authkey should be a byte string'
    
            self._authkey = authkey
    
        def accept(self):
            '''
            Accept a connection on the bound socket or named pipe of
    `self`.
    
            Returns a `Connection` object.
            '''
            c = self._listener.accept()
            if self._authkey:
                deliver_challenge(c, self._authkey)
                answer_challenge(c, self._authkey)
            return c
    
        def close(self):
            '''
            Close the bound socket or named pipe of `self`.
            '''
            return self._listener.close()
    
        address = property(lambda self: self._listener._address)
        last_accepted = property(lambda self:
    self._listener._last_accepted)
    
    
    def Client(address, family=None, authkey=None, sslsock=True):
        '''
        Returns a connection to the address of a `Listener`
        '''
        family = family or address_type(address)
        if family == 'AF_PIPE':
            c = PipeClient(address)
        else:
            c = SocketClient(address,sslsock)
    
        if authkey is not None and not isinstance(authkey, bytes):
            raise TypeError, 'authkey should be a byte string'
    
        if authkey is not None:
            answer_challenge(c, authkey)
            deliver_challenge(c, authkey)
    
        return c
    
    
    if sys.platform != 'win32':
    
        def Pipe(duplex=True):
            '''
            Returns pair of connection objects at either end of a pipe
            '''
            if duplex:
                s1, s2 = socket.socketpair()
                c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
                c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
                s1.close()
                s2.close()
            else:
                fd1, fd2 = os.pipe()
                c1 = _multiprocessing.Connection(fd1, writable=False)
                c2 = _multiprocessing.Connection(fd2, readable=False)
    
            return c1, c2
    
    else:
    
        from ._multiprocessing import win32
    
        def Pipe(duplex=True):
            '''
            Returns pair of connection objects at either end of a pipe
            '''
            address = arbitrary_address('AF_PIPE')
            if duplex:
                openmode = win32.PIPE_ACCESS_DUPLEX
                access = win32.GENERIC_READ | win32.GENERIC_WRITE
                obsize, ibsize = BUFSIZE, BUFSIZE
            else:
                openmode = win32.PIPE_ACCESS_INBOUND
                access = win32.GENERIC_WRITE
                obsize, ibsize = 0, BUFSIZE
    
            h1 = win32.CreateNamedPipe(
                address, openmode,
                win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
                win32.PIPE_WAIT,
                1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                )
            h2 = win32.CreateFile(
                address, access, 0, win32.NULL, win32.OPEN_EXISTING, 0,
    win32.NULL
                )
            win32.SetNamedPipeHandleState(
                h2, win32.PIPE_READMODE_MESSAGE, None, None
                )
    
            try:
                win32.ConnectNamedPipe(h1, win32.NULL)
            except WindowsError, e:
                if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                    raise
    
            c1 = _multiprocessing.PipeConnection(h1, writable=duplex)
            c2 = _multiprocessing.PipeConnection(h2, readable=duplex)
    
            return c1, c2
    
    #
    # Definitions for connections based on sockets
    #
    
    class SocketListener(object):
        '''
        Representation of a socket which is bound to an address and
    listening
        '''
    # Aadido sslsock por xavi
        def __init__(self, address, family, backlog=1, sslsock=True):
            self._socket = socket.socket(getattr(socket, family))
            if sslsock == True:
                print "SSL Enabled"
                self._socket = ssl.wrap_socket
    (self._socket,certfile="cert.pem",server_side=True,ssl_version=ssl.PROTOCOL_TLSv1)
            self._socket.setsockopt(socket.SOL_SOCKET,
    socket.SO_REUSEADDR, 1)
            self._socket.bind(address)
            self._socket.listen(backlog)
            self._address = self._socket.getsockname()
            self._family = family
            self._last_accepted = None
    
            if family == 'AF_UNIX':
                self._unlink = Finalize(
                    self, os.unlink, args=(address,), exitpriority=0
                    )
            else:
                self._unlink = None
    
    
        def accept(self):
            s, self._last_accepted = self._socket.accept()
            fd = duplicate(s.fileno())
            conn = _multiprocessing.Connection(fd)
            s.close()
            return conn
    
        def close(self):
            self._socket.close()
            if self._unlink is not None:
                self._unlink()
    
    
    def SocketClient(address, sslsock=True):
        '''
        Return a connection object connected to the socket given by
    `address`
        '''
        family = address_type(address)
        s = socket.socket( getattr(socket, family) )
        if sslsock == True:
            '''
            print "SSL Enabled"
            '''
            s = ssl.wrap_socket
    (s,ssl_version=ssl.PROTOCOL_TLSv1,cert_reqs=ssl.CERT_NONE,ca_certs=None)
        while 1:
            try:
                s.connect(address)
            except socket.error, e:
                if e.args[0] != errno.ECONNREFUSED: # connection refused
                    debug('failed to connect to address %s', address)
                    raise
                time.sleep(0.01)
            else:
                break
        else:
            raise
    
        fd = duplicate(s.fileno())
        conn = _multiprocessing.Connection(fd)
        s.close()
        return conn
    
    #
    # Definitions for connections based on named pipes
    #
    
    if sys.platform == 'win32':
    
        class PipeListener(object):
            '''
            Representation of a named pipe
            '''
            def __init__(self, address, backlog=None):
                self._address = address
                handle = win32.CreateNamedPipe(
                    address, win32.PIPE_ACCESS_DUPLEX,
                    win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    |
                    win32.PIPE_WAIT,
                    win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
                    win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                    )
                self._handle_queue = [handle]
                self._last_accepted = None
    
                sub_debug('listener created with address=%r',
    self._address)
    
                self.close = Finalize(
                    self, PipeListener._finalize_pipe_listener,
                    args=(self._handle_queue, self._address),
    exitpriority=0
                    )
    
            def accept(self):
                newhandle = win32.CreateNamedPipe(
                    self._address, win32.PIPE_ACCESS_DUPLEX,
                    win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    |
                    win32.PIPE_WAIT,
                    win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
                    win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                    )
                self._handle_queue.append(newhandle)
                handle = self._handle_queue.pop(0)
                try:
                    win32.ConnectNamedPipe(handle, win32.NULL)
                except WindowsError, e:
                    if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                        raise
                return _multiprocessing.PipeConnection(handle)
    
            @staticmethod
            def _finalize_pipe_listener(queue, address):
                sub_debug('closing listener with address=%r', address)
                for handle in queue:
                    close(handle)
    
        def PipeClient(address):
            '''
            Return a connection object connected to the pipe given by
    `address`
            '''
            while 1:
                try:
                    win32.WaitNamedPipe(address, 1000)
                    h = win32.CreateFile(
                        address, win32.GENERIC_READ | win32.GENERIC_WRITE,
                        0, win32.NULL, win32.OPEN_EXISTING, 0, win32.NULL
                        )
                except WindowsError, e:
                    if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
                                         win32.ERROR_PIPE_BUSY):
                        raise
                else:
                    break
            else:
                raise
    
            win32.SetNamedPipeHandleState(
                h, win32.PIPE_READMODE_MESSAGE, None, None
                )
            return _multiprocessing.PipeConnection(h)
    
    #
    # Authentication stuff
    #
    
    MESSAGE_LENGTH = 20
    
    CHALLENGE = b'#CHALLENGE#'
    WELCOME = b'#WELCOME#'
    FAILURE = b'#FAILURE#'
    
    def deliver_challenge(connection, authkey):
        import hmac
        assert isinstance(authkey, bytes)
        message = os.urandom(MESSAGE_LENGTH)
        connection.send_bytes(CHALLENGE + message)
        digest = hmac.new(authkey, message).digest()
        response = connection.recv_bytes(256)        # reject large
    message
        if response == digest:
            connection.send_bytes(WELCOME)
        else:
            connection.send_bytes(FAILURE)
            raise AuthenticationError('digest received was wrong')
    
    def answer_challenge(connection, authkey):
        import hmac
        assert isinstance(authkey, bytes)
        message = connection.recv_bytes(256)         # reject large
    message
        assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' %
    message
        message = message[len(CHALLENGE):]
        digest = hmac.new(authkey, message).digest()
        connection.send_bytes(digest)
        response = connection.recv_bytes(256)        # reject large
    message
        if response != WELCOME:
            raise AuthenticationError('digest sent was rejected')
    
    #
    # Support for using xmlrpclib for serialization
    #
    
    class ConnectionWrapper(object):
        def __init__(self, conn, dumps, loads):
            self._conn = conn
            self._dumps = dumps
            self._loads = loads
            for attr in ('fileno', 'close', 'poll', 'recv_bytes',
    'send_bytes'):
                obj = getattr(conn, attr)
                setattr(self, attr, obj)
        def send(self, obj):
            s = self._dumps(obj)
            self._conn.send_bytes(s)
        def recv(self):
            s = self._conn.recv_bytes()
            return self._loads(s)
    
    def _xml_dumps(obj):
        return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf8')
    
    def _xml_loads(s):
        (obj,), method = xmlrpclib.loads(s.decode('utf8'))
        return obj
    
    class XmlListener(Listener):
        def accept(self):
            global xmlrpclib
            import xmlrpclib
            obj = Listener.accept(self)
            return ConnectionWrapper(obj, _xml_dumps, _xml_loads)
    
    def XmlClient(*args, **kwds):
        global xmlrpclib
        import xmlrpclib
        return ConnectionWrapper(Client(*args, **kwds), _xml_dumps,
    _xml_loads)
    
    ================================
    
    If u take a look u can observe i've imported ssl module and added a
    sslsock parameter in SocketListener and SocketClient.
    
    There is a certificate file required called 'cert.pem', you can
    generate one by typing this:
    
    openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
    
    In same directory where your python server program runs.
    
    Encryption it's setup to AES-256 and mandatory, so it would raise and
    error if certificate file is missing.
    
    U don't need to change any code in your program.
    
    U can use tcpdump or wireshark to test that it works.
    
    
    
    
    
    
    
    
    On 6 nov, 15:56, Jonas  wrote:
    > Hi,
    > how can I secure the communication between two BaseManager objects?
    > Regarding the socket/SSL documentation I just need to secure the
    > socket by SSL. How can i get the socket object within themultiprocessing
    > module?
    >
    > Best regards,
    >
    > Jonas
    
    
    
    From joncle at googlemail.com  Tue Nov 24 16:50:57 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:50:57 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    Message-ID: <040a9c29-a8f2-4485-ab5f-4babd9484a0b@m20g2000vbp.googlegroups.com>
    
    On Nov 24, 9:20?pm, utabintarbo  wrote:
    > On Nov 24, 3:27?pm, MRAB  wrote:
    >
    >
    >
    > > .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > > it returns.
    >
    > > Could you provide some code which shows your problem?
    >
    > Here is the code block I have so far:
    > for l in open(CONTENTS, 'r').readlines():
    > ? ? f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    > ? ? if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    > ? ? ? ? shutil.rmtree(os.path.join(DIR1,f))
    > ? ? ? ? if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    > ? ? ? ? ? ? ? ? shutil.rmtree(os.path.join(DIR2,f))
    >
    > I am trying to find dirs with the basename of the initial path less
    > the extension in both DIR1 and DIR2
    >
    > A minimally obfuscated line from the log file:
    > K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602
    >
    > What I get from the debugger/python shell:
    > 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602'
    >
    > TIA
    
    jon at jon-desktop:~/pytest$ cat log.txt
    K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602
    
    >>> log = open('/home/jon/pytest/log.txt', 'r').readlines()
    >>> log
    ['K:\\sm\\SMI\\des\\RS\\Pat\\10DJ\\121.D5-30\\1215B-B-D5-BSHOE-MM.smz-
    >/arch_m1/\n', 'smi/des/RS/Pat/10DJ/121.D5-30\\1215B-B-D5-BSHOE-
    MM.smz ; t9480rc ;\n', '11/24/2009 08:16:42 ; 1259068602\n']
    
    See -- it's not doing anything :)
    
    Although, "Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" and "Pat
    \x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" seem to be fairly different -- are
    you sure you're posting the correct output!?
    
    Jon.
    
    
    From joncle at googlemail.com  Tue Nov 24 16:54:13 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:54:13 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	<040a9c29-a8f2-4485-ab5f-4babd9484a0b@m20g2000vbp.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 9:50?pm, Jon Clements  wrote:
    > On Nov 24, 9:20?pm, utabintarbo  wrote:
    [snip]
    > Although, "Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" and "Pat
    > \x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" seem to be fairly different -- are
    > you sure you're posting the correct output!?
    >
    
    Ugh... let's try that...
    
    Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz
    Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz
    
    Jon.
    
    
    From joncle at googlemail.com  Tue Nov 24 16:59:54 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:59:54 -0800 (PST)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    	<4b0c4dbb$0$8926$426a74cc@news.free.fr>
    Message-ID: <783624a8-4591-4360-aebe-6b8e6702c132@x15g2000vbr.googlegroups.com>
    
    On Nov 24, 8:21?pm, Bruno Desthuilliers
     wrote:
    > Cameron Laird a ?crit :
    >
    >
    >
    > > ? ? Grant Edwards on the best way to get help from this group :)
    > > ? ? ? ?http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21...
    >
    > This one really deserves a POTM award !-)
    
    Absolutely -- thumbs up to Grant.
    
    All we need to do is merge in the other bullet points, and put it as a
    "How-To-Not-Post-FAQ" :)
    
    Jon.
    
    
    From __peter__ at web.de  Tue Nov 24 17:02:27 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 23:02:27 +0100
    Subject: csv and mixed lists of unicode and numbers
    References: 
    	
    	
    Message-ID: 
    
    Sibylle Koczian wrote:
    
    > This problem really goes away with Python 3 (tried it on another
    > machine), but something else changes too: in Python 2.6 the
    > documentation for the csv module explicitly says "If csvfile is a file
    > object, it must be opened with the ?b? flag on platforms where that
    > makes a difference." The documentation for Python 3.1 doesn't have this
    > sentence, and if I do that in Python 3.1 I get for all sorts of data,
    > even for a list with only one integer literal:
    > 
    > TypeError: must be bytes or buffer, not str
    
    Read the documentation for open() at
    
    http://docs.python.org/3.1/library/functions.html#open
    
    There are significant changes with respect to 2.x; you won't even get a file 
    object anymore:
    
    >>> open("tmp.txt", "w")
    <_io.TextIOWrapper name='tmp.txt' encoding='UTF-8'>
    >>> _.write("yadda")
    5
    >>> open("tmp.dat", "wb")
    <_io.BufferedWriter name='tmp.dat'>
    >>> _.write("yadda")
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: write() argument 1 must be bytes or buffer, not str
    >>> open("tmp.dat", "wb").write(b"yadda")
    5
    
    If you specify the "b" flag in 3.x the write() method expects bytes, not 
    str. The translation of newlines is now controlled by the "newline" 
    argument.
    
    Peter
    
    
    
    From benjamin at python.org  Tue Nov 24 17:08:19 2009
    From: benjamin at python.org (Benjamin Peterson)
    Date: Tue, 24 Nov 2009 22:08:19 +0000 (UTC)
    Subject: pointless musings on performance
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    	
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	 <1259090178.661.34.camel@localhost>
    Message-ID: 
    
    Tim Wintle  teamrubber.com> writes:
    > Out of interest - has anyone else spotted that the call to
    > PyObject_IsTrue in the XXX_JUMP_IF_YYYY blocks performs two unnecessary
    > pointer comparisons?
    
    I doubt two pointer comparisons will make much of a difference.
    
    > Would it be worth in-lining the remaining part of PyObject_IsTrue in
    > ceval?
    
    Inlining by hand is prone to error and maintainability problems.
    
    
    
    
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 17:11:45 2009
    From: x.sanz35 at gmail.com (Xavier Sanz)
    Date: Tue, 24 Nov 2009 14:11:45 -0800 (PST)
    Subject: Securing a multiprocessing.BaseManager connection via SSL
    References: 
    	<221434b3-839d-49db-8c08-4c1f1ececd5f@p33g2000vbn.googlegroups.com>
    Message-ID: <6a9a14a7-6493-4655-b773-dca7fe2640d9@f10g2000vbl.googlegroups.com>
    
    I recommend u to test it before use it in production environment.
    
    On 24 nov, 22:45, Xavier Sanz  wrote:
    > Hi Jonas
    >
    > I've having same need so i found a solution but you need to hack a bit
    >
    > I am using python 2.6.3 but i suppose it could be applicable to your
    > case.
    >
    > First of all u need to edit /usr/lib/python2.6/lib/python2.6/multiprocessing/connection.py
    >
    > This is mine:
    >
    > #
    > # A higher level module for using sockets (or Windows named pipes)
    > #
    > #multiprocessing/connection.py
    > #
    > # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
    > #
    >
    > __all__ = [ 'Client', 'Listener', 'Pipe' ]
    >
    > import os
    > import sys
    > import socket
    > import errno
    > import time
    > import tempfile
    > import itertools
    > # Added by Xavi
    > import ssl
    >
    > import _multiprocessing
    > frommultiprocessingimport current_process, AuthenticationError
    > frommultiprocessing.util import get_temp_dir, Finalize, sub_debug,
    > debug
    > frommultiprocessing.forking import duplicate, close
    >
    > #
    > #
    > #
    >
    > BUFSIZE = 8192
    >
    > _mmap_counter = itertools.count()
    >
    > default_family = 'AF_INET'
    > families = ['AF_INET']
    >
    > if hasattr(socket, 'AF_UNIX'):
    > ? ? default_family = 'AF_UNIX'
    > ? ? families += ['AF_UNIX']
    >
    > if sys.platform == 'win32':
    > ? ? default_family = 'AF_PIPE'
    > ? ? families += ['AF_PIPE']
    >
    > #
    > #
    > #
    >
    > def arbitrary_address(family):
    > ? ? '''
    > ? ? Return an arbitrary free address for the given family
    > ? ? '''
    > ? ? if family == 'AF_INET':
    > ? ? ? ? return ('localhost', 0)
    > ? ? elif family == 'AF_UNIX':
    > ? ? ? ? return tempfile.mktemp(prefix='listener-', dir=get_temp_dir())
    > ? ? elif family == 'AF_PIPE':
    > ? ? ? ? return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
    > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(os.getpid(), _mmap_counter.next()))
    > ? ? else:
    > ? ? ? ? raise ValueError('unrecognized family')
    >
    > def address_type(address):
    > ? ? '''
    > ? ? Return the types of the address
    >
    > ? ? This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    > ? ? '''
    > ? ? if type(address) == tuple:
    > ? ? ? ? return 'AF_INET'
    > ? ? elif type(address) is str and address.startswith('\\\\'):
    > ? ? ? ? return 'AF_PIPE'
    > ? ? elif type(address) is str:
    > ? ? ? ? return 'AF_UNIX'
    > ? ? else:
    > ? ? ? ? raise ValueError('address type of %r unrecognized' % address)
    >
    > #
    > # Public functions
    > #
    >
    > class Listener(object):
    > ? ? '''
    > ? ? Returns a listener object.
    >
    > ? ? This is a wrapper for a bound socket which is 'listening' for
    > ? ? connections, or for a Windows named pipe.
    > ? ? '''
    > ? ? def __init__(self, address=None, family=None, backlog=1,
    > authkey=None, sslsock=True):
    > ? ? ? ? family = family or (address and address_type(address)) \
    > ? ? ? ? ? ? ? ? ?or default_family
    > ? ? ? ? address = address or arbitrary_address(family)
    >
    > ? ? ? ? if family == 'AF_PIPE':
    > ? ? ? ? ? ? self._listener = PipeListener(address, backlog)
    > ? ? ? ? else:
    > ? ? ? ? ? ? self._listener = SocketListener(address, family, backlog,
    > sslsock)
    > ? ? ? ? if authkey is not None and not isinstance(authkey, bytes):
    > ? ? ? ? ? ? raise TypeError, 'authkey should be a byte string'
    >
    > ? ? ? ? self._authkey = authkey
    >
    > ? ? def accept(self):
    > ? ? ? ? '''
    > ? ? ? ? Accept a connection on the bound socket or named pipe of
    > `self`.
    >
    > ? ? ? ? Returns a `Connection` object.
    > ? ? ? ? '''
    > ? ? ? ? c = self._listener.accept()
    > ? ? ? ? if self._authkey:
    > ? ? ? ? ? ? deliver_challenge(c, self._authkey)
    > ? ? ? ? ? ? answer_challenge(c, self._authkey)
    > ? ? ? ? return c
    >
    > ? ? def close(self):
    > ? ? ? ? '''
    > ? ? ? ? Close the bound socket or named pipe of `self`.
    > ? ? ? ? '''
    > ? ? ? ? return self._listener.close()
    >
    > ? ? address = property(lambda self: self._listener._address)
    > ? ? last_accepted = property(lambda self:
    > self._listener._last_accepted)
    >
    > def Client(address, family=None, authkey=None, sslsock=True):
    > ? ? '''
    > ? ? Returns a connection to the address of a `Listener`
    > ? ? '''
    > ? ? family = family or address_type(address)
    > ? ? if family == 'AF_PIPE':
    > ? ? ? ? c = PipeClient(address)
    > ? ? else:
    > ? ? ? ? c = SocketClient(address,sslsock)
    >
    > ? ? if authkey is not None and not isinstance(authkey, bytes):
    > ? ? ? ? raise TypeError, 'authkey should be a byte string'
    >
    > ? ? if authkey is not None:
    > ? ? ? ? answer_challenge(c, authkey)
    > ? ? ? ? deliver_challenge(c, authkey)
    >
    > ? ? return c
    >
    > if sys.platform != 'win32':
    >
    > ? ? def Pipe(duplex=True):
    > ? ? ? ? '''
    > ? ? ? ? Returns pair of connection objects at either end of a pipe
    > ? ? ? ? '''
    > ? ? ? ? if duplex:
    > ? ? ? ? ? ? s1, s2 = socket.socketpair()
    > ? ? ? ? ? ? c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
    > ? ? ? ? ? ? c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
    > ? ? ? ? ? ? s1.close()
    > ? ? ? ? ? ? s2.close()
    > ? ? ? ? else:
    > ? ? ? ? ? ? fd1, fd2 = os.pipe()
    > ? ? ? ? ? ? c1 = _multiprocessing.Connection(fd1, writable=False)
    > ? ? ? ? ? ? c2 = _multiprocessing.Connection(fd2, readable=False)
    >
    > ? ? ? ? return c1, c2
    >
    > else:
    >
    > ? ? from ._multiprocessing import win32
    >
    > ? ? def Pipe(duplex=True):
    > ? ? ? ? '''
    > ? ? ? ? Returns pair of connection objects at either end of a pipe
    > ? ? ? ? '''
    > ? ? ? ? address = arbitrary_address('AF_PIPE')
    > ? ? ? ? if duplex:
    > ? ? ? ? ? ? openmode = win32.PIPE_ACCESS_DUPLEX
    > ? ? ? ? ? ? access = win32.GENERIC_READ | win32.GENERIC_WRITE
    > ? ? ? ? ? ? obsize, ibsize = BUFSIZE, BUFSIZE
    > ? ? ? ? else:
    > ? ? ? ? ? ? openmode = win32.PIPE_ACCESS_INBOUND
    > ? ? ? ? ? ? access = win32.GENERIC_WRITE
    > ? ? ? ? ? ? obsize, ibsize = 0, BUFSIZE
    >
    > ? ? ? ? h1 = win32.CreateNamedPipe(
    > ? ? ? ? ? ? address, openmode,
    > ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
    > ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? 1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? )
    > ? ? ? ? h2 = win32.CreateFile(
    > ? ? ? ? ? ? address, access, 0, win32.NULL, win32.OPEN_EXISTING, 0,
    > win32.NULL
    > ? ? ? ? ? ? )
    > ? ? ? ? win32.SetNamedPipeHandleState(
    > ? ? ? ? ? ? h2, win32.PIPE_READMODE_MESSAGE, None, None
    > ? ? ? ? ? ? )
    >
    > ? ? ? ? try:
    > ? ? ? ? ? ? win32.ConnectNamedPipe(h1, win32.NULL)
    > ? ? ? ? except WindowsError, e:
    > ? ? ? ? ? ? if e.args[0] != win32.ERROR_PIPE_CONNECTED:
    > ? ? ? ? ? ? ? ? raise
    >
    > ? ? ? ? c1 = _multiprocessing.PipeConnection(h1, writable=duplex)
    > ? ? ? ? c2 = _multiprocessing.PipeConnection(h2, readable=duplex)
    >
    > ? ? ? ? return c1, c2
    >
    > #
    > # Definitions for connections based on sockets
    > #
    >
    > class SocketListener(object):
    > ? ? '''
    > ? ? Representation of a socket which is bound to an address and
    > listening
    > ? ? '''
    > # Aadido sslsock por xavi
    > ? ? def __init__(self, address, family, backlog=1, sslsock=True):
    > ? ? ? ? self._socket = socket.socket(getattr(socket, family))
    > ? ? ? ? if sslsock == True:
    > ? ? ? ? ? ? print "SSL Enabled"
    > ? ? ? ? ? ? self._socket = ssl.wrap_socket
    > (self._socket,certfile="cert.pem",server_side=True,ssl_version=ssl.PROTOCOL_TLSv1)
    > ? ? ? ? self._socket.setsockopt(socket.SOL_SOCKET,
    > socket.SO_REUSEADDR, 1)
    > ? ? ? ? self._socket.bind(address)
    > ? ? ? ? self._socket.listen(backlog)
    > ? ? ? ? self._address = self._socket.getsockname()
    > ? ? ? ? self._family = family
    > ? ? ? ? self._last_accepted = None
    >
    > ? ? ? ? if family == 'AF_UNIX':
    > ? ? ? ? ? ? self._unlink = Finalize(
    > ? ? ? ? ? ? ? ? self, os.unlink, args=(address,), exitpriority=0
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? else:
    > ? ? ? ? ? ? self._unlink = None
    >
    > ? ? def accept(self):
    > ? ? ? ? s, self._last_accepted = self._socket.accept()
    > ? ? ? ? fd = duplicate(s.fileno())
    > ? ? ? ? conn = _multiprocessing.Connection(fd)
    > ? ? ? ? s.close()
    > ? ? ? ? return conn
    >
    > ? ? def close(self):
    > ? ? ? ? self._socket.close()
    > ? ? ? ? if self._unlink is not None:
    > ? ? ? ? ? ? self._unlink()
    >
    > def SocketClient(address, sslsock=True):
    > ? ? '''
    > ? ? Return a connection object connected to the socket given by
    > `address`
    > ? ? '''
    > ? ? family = address_type(address)
    > ? ? s = socket.socket( getattr(socket, family) )
    > ? ? if sslsock == True:
    > ? ? ? ? '''
    > ? ? ? ? print "SSL Enabled"
    > ? ? ? ? '''
    > ? ? ? ? s = ssl.wrap_socket
    > (s,ssl_version=ssl.PROTOCOL_TLSv1,cert_reqs=ssl.CERT_NONE,ca_certs=None)
    > ? ? while 1:
    > ? ? ? ? try:
    > ? ? ? ? ? ? s.connect(address)
    > ? ? ? ? except socket.error, e:
    > ? ? ? ? ? ? if e.args[0] != errno.ECONNREFUSED: # connection refused
    > ? ? ? ? ? ? ? ? debug('failed to connect to address %s', address)
    > ? ? ? ? ? ? ? ? raise
    > ? ? ? ? ? ? time.sleep(0.01)
    > ? ? ? ? else:
    > ? ? ? ? ? ? break
    > ? ? else:
    > ? ? ? ? raise
    >
    > ? ? fd = duplicate(s.fileno())
    > ? ? conn = _multiprocessing.Connection(fd)
    > ? ? s.close()
    > ? ? return conn
    >
    > #
    > # Definitions for connections based on named pipes
    > #
    >
    > if sys.platform == 'win32':
    >
    > ? ? class PipeListener(object):
    > ? ? ? ? '''
    > ? ? ? ? Representation of a named pipe
    > ? ? ? ? '''
    > ? ? ? ? def __init__(self, address, backlog=None):
    > ? ? ? ? ? ? self._address = address
    > ? ? ? ? ? ? handle = win32.CreateNamedPipe(
    > ? ? ? ? ? ? ? ? address, win32.PIPE_ACCESS_DUPLEX,
    > ? ? ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    > |
    > ? ? ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? ? ? win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
    > ? ? ? ? ? ? ? ? win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? ? ? self._handle_queue = [handle]
    > ? ? ? ? ? ? self._last_accepted = None
    >
    > ? ? ? ? ? ? sub_debug('listener created with address=%r',
    > self._address)
    >
    > ? ? ? ? ? ? self.close = Finalize(
    > ? ? ? ? ? ? ? ? self, PipeListener._finalize_pipe_listener,
    > ? ? ? ? ? ? ? ? args=(self._handle_queue, self._address),
    > exitpriority=0
    > ? ? ? ? ? ? ? ? )
    >
    > ? ? ? ? def accept(self):
    > ? ? ? ? ? ? newhandle = win32.CreateNamedPipe(
    > ? ? ? ? ? ? ? ? self._address, win32.PIPE_ACCESS_DUPLEX,
    > ? ? ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    > |
    > ? ? ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? ? ? win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
    > ? ? ? ? ? ? ? ? win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? ? ? self._handle_queue.append(newhandle)
    > ? ? ? ? ? ? handle = self._handle_queue.pop(0)
    > ? ? ? ? ? ? try:
    > ? ? ? ? ? ? ? ? win32.ConnectNamedPipe(handle, win32.NULL)
    > ? ? ? ? ? ? except WindowsError, e:
    > ? ? ? ? ? ? ? ? if e.args[0] != win32.ERROR_PIPE_CONNECTED:
    > ? ? ? ? ? ? ? ? ? ? raise
    > ? ? ? ? ? ? return _multiprocessing.PipeConnection(handle)
    >
    > ? ? ? ? @staticmethod
    > ? ? ? ? def _finalize_pipe_listener(queue, address):
    > ? ? ? ? ? ? sub_debug('closing listener with address=%r', address)
    > ? ? ? ? ? ? for handle in queue:
    > ? ? ? ? ? ? ? ? close(handle)
    >
    > ? ? def PipeClient(address):
    > ? ? ? ? '''
    > ? ? ? ? Return a connection object connected to the pipe given by...
    >
    > leer m?s ?
    
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:14:15 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:14:15 -0500
    Subject: pointless musings on performance
    In-Reply-To: <50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    References: 	
    	<50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    Message-ID: 
    
    Chris Rebert wrote:
    > On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft  wrote:
    >> mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in
    >> comp.lang.python:
    >>
    >>> def pythonic():
    >>> def unpythonic():
    >>
    >>> Decidedly counterintuitive: are there special optimizations for "if
    >>> nonevar:" type of statements in cpython implementation?
    >>>
    >> from dis import dis
    >>
    >> dis( unpythonic )
    >>
    >> 18          31 LOAD_FAST                0 (nonevar)
    >>             34 LOAD_CONST               0 (None)
    >>             37 COMPARE_OP               9 (is not)
    >>             40 JUMP_IF_FALSE            4 (to 47)
    >>
    >> dis( pythonic )
    >>
    >> 11          31 LOAD_FAST                0 (nonevar)
    >>             34 JUMP_IF_FALSE            4 (to 41)
    > 
    > In other words, CPython doesn't happen to optimize `if nonevar is not
    > None` as much as it theoretically could (which would essentially
    > require a JUMP_IF_NONE opcode). Since CPython isn't known for doing
    > fancy optimizations, this isn't surprising.
    
    There is a limit of 256 bytecodes. I believe there are currently fewer. 
    It would seem that adding bytecodes that combine current pairs would 
    speed the interpreter, depending on how often the combined pair is used. 
    And people have looked for frequent pairs across a corpus of code, and 
    proposed additions.
    
    However, additional bytecodes enlarge the basic bytecode eval loop, 
    possibly (and sometimes actually) leading to to more processor cache 
    misses and slower execution. At least some proposed non-essential 
    additions have been rejected for the reason.
    
    Also, even though CPython-specific bytecodes are outside the language 
    definition, and could theoretically be revamped every minor (x.y) 
    release, there is a cost to change. Rewrite the ast to bytecode 
    compiler, rewrite dis, rewrite the dis doc, and burden anyone concerned 
    with multiple versions to remember. So in practice, change is minimized 
    and unassigned bytecodes are left open for the future.
    
    Optimizations that make better use of a fix set of bytecodes are a 
    different topic. Guido is conservative because historically, compilier 
    optimizations are too often not exactly equivalent to naive, obviously 
    correct code in some overlooked corner case, leading to subtle, 
    occasional bugs. Of course, byte code changes could mess-up current 
    optimizations that are performed.
    
    Terry Jan Reedy
    
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:29:35 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:29:35 -0500
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>	<7n01t8F3jijv0U1@mid.uni-berlin.de>			<8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com>	
    	
    Message-ID: 
    
    Peter Otten wrote:
    > Terry Reedy wrote:
    
    >> remember exactly what was stored. Maybe a typo.
    > 
    > That's a bug in the store() function
    > 
    > # as posted
    > def store(data, full_name):
    >     names = full_name.split()
    >     if len(names) == 2: names.insert(1, '')
    >     labels = 'first', 'middle', 'last'
    >     for label, name in zip(labels, names):
    >         people = lookup(data, label, name)
    >     if people:
    >         people.append(full_name)
    >     else:
    >         data[label][name] = [full_name]
    > 
    > # what was probably intended
    > def store(data, full_name):
    >     names = full_name.split()
    >     if len(names) == 2: names.insert(1, '')
    >     labels = 'first', 'middle', 'last'
    >     for label, name in zip(labels, names):
    >         people = lookup(data, label, name)
    >         if people:
    >             people.append(full_name)
    >         else:
    >             data[label][name] = [full_name]
    
    (Note indent error, which I overlooked)
    It is a nuisance when people post untested code, without identifying it 
    as such. Publishing untested but trivial-to-test code like this (one 
    print statement needed), especially in a book for learners, is really bad.
    
    (I am trying to do better in the book I am working on.)
    
    tjr
    
    
    
    From hansmu at xs4all.nl  Tue Nov 24 17:38:03 2009
    From: hansmu at xs4all.nl (Hans Mulder)
    Date: Tue, 24 Nov 2009 23:38:03 +0100
    Subject: Perl conversion to python...
    In-Reply-To: <858wdx41ol.fsf@agentultra.com>
    References: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com>
    	<858wdx41ol.fsf@agentultra.com>
    Message-ID: <4b0c60ba$0$22940$e4fe514c@news.xs4all.nl>
    
    J Kenneth King wrote:
    > Benjamin Schollnick  writes:
    
    >> 		select(undef, undef, undef, 0.01);
    
    >         # select() is a system call in Perl..
    >         # insert Python equivalent here
    
    That would be:
    
               time.sleep(0.01)
    
    Perl has a sleep() built-in, but it truncates its argument to an int.
    If you want to sleep less than a second in Perl, you have to use select
    as shown.
    
    Not so in Python.  Python's time.sleep() takes a float argument and
    calls some platform-dependent function that provides sleeping with
    sub-second accuracy.  On some platforms, it ends up calling the
    C level select() function.
    
    Keep in mind that in both languages, your program may end up sleeping
    longer than it should due to scheduling or other activity on the system.
    
    
    Hope this helps,
    
    -- HansM
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 17:43:32 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 22:43:32 GMT
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    	
    Message-ID: <031c4f72$0$1336$c3e8da3@news.astraweb.com>
    
    On Tue, 24 Nov 2009 13:19:10 -0500, Chris Jones wrote:
    
    > On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    > 
    >> Good grief, it's about six weeks away from 2010 and Thunderbird still
    >> uses mbox as it's default mail box format. Hello, the nineties called,
    >> they want their mail formats back! Are the tbird developers on crack or
    >> something? I can't believe that they're still using that crappy format.
    >> 
    >> No, I tell a lie. I can believe it far too well.
    > 
    > :-)
    > 
    > I realize that's somewhat OT, but what mail box format do you recommend,
    > and why?
    
    maildir++
    
    http://en.wikipedia.org/wiki/Maildir
    
    Corruption is less likely, if there is corruption you'll only lose a 
    single message rather than potentially everything in the mail folder[*], 
    at a pinch you can read the emails using a text editor or easily grep 
    through them, and compacting the mail folder is lightning fast, there's 
    no wasted space in the mail folder, and there's no need to mangle lines 
    starting with "From " in the body of the email.
    
    The only major downside is that because you're dealing with potentially 
    thousands of smallish files, it *may* have reduced performance on some 
    older file systems that don't deal well with lots of files. These days, 
    that's not a real issue.
    
    Oh yes, and people using Windows can't use maildir because (1) it doesn't 
    allow colons in names, and (2) it doesn't have atomic renames. Neither of 
    these are insurmountable problems: an implementation could substitute 
    another character for the colon, and while that would be a technical 
    violation of the standard, it would still work. And the lack of atomic 
    renames would simply mean that implementations have to be more careful 
    about not having two threads writing to the one mailbox at the same time.
    
    
    
    
    [*] I'm assuming normal "oops there's a bug in the mail client code" 
    corruption rather than "I got drunk and started deleting random files and 
    directories" corruption.
    
    
    
    -- 
    Steven
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 17:45:37 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 22:45:37 GMT
    Subject: Where to put the error handing test?
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    	<4B0BBC62.7020702@ieee.org>
    	
    Message-ID: <031c4fee$0$1336$c3e8da3@news.astraweb.com>
    
    On Tue, 24 Nov 2009 10:14:19 -0600, Peng Yu wrote:
    
    > I'll still confused by the guideline that an error should be caught as
    > early as possible.
    
    I think you are confused by what that means. It means the error should be 
    caught as early as possible in *time*, not in the function chain.
    
    In Python, errors are always generated as soon as they occur. But imagine 
    a system where you have a function that returns -1 on error and some 
    integer on success. Then it is possible for that -1 error code to be 
    passed along from one function to another to another to another before 
    finally causing a fatal error, by which time you have no idea where it 
    came from. That's what should be prohibited.
    
    
    
    > Suppose I have the following call chain
    > 
    > f1() --> f2() --> f3() --> f4()
    > 
    > The input in f1() might cause an error in f4(). 
    
    Assuming that none of the functions have side-effects, then f4 is the 
    right place to catch the error. To do otherwise means that f1 needs to 
    know all the possible things that can go wrong in f2, and f3, and f4.
    
    
    > However, this error can
    > of cause be caught by f1(), whenever I want to do so. In the worst case,
    > I could duplicate the code of f2 and f3, and the test code in f4 to
    > f1(), to catch the error in f1 rather than f4. But I don't think that
    > this is what you mean.
    > 
    > Then the problem is where to put the test code more effectively. I would
    > consider 'whether it is obvious to test the condition in the give
    > function' as the guideline. However, it might be equal obvious to test
    > the same thing two functions, for example, f1 and f4.
    
    You're not a mathematician, are you?
    
    For each function, define its domain: the values it must work with. 
    Suppose f1 should return a result for (e.g.) all integers, but f2 only 
    returns a result for *positive* integers.
    
    Then it is very simple: f2 will raise an error if given zero or negative 
    values, and so f1 must either:
    
    * avoid that error by handling zero or negative separately; or
    * catch the error and then handle zero or negative separately.
    
    Simplified example:
    
    def f2(x):
        if x > 0:
            return x+1
        raise ValueError
    
    
    def f1(x):  # version 1
        if x > 0:
            return f2(x)
        else:
            return "something else"
    
    # or
    
    def f1(x):  # version 2
        try:
            return f2(x)
        except ValueError:
            return "something else"
    
    
    Version two is the preferred way to do it, since that means f1 doesn't 
    need to know what the domain of f2 is. But if f2 has side-effects 
    (usually a bad idea) then version one is better.
    
    
    But what if f1 and f2 have the same domain?
    
    Then it is very simple: put the error checking wherever it makes sense. 
    If f2 is public, put the error checking there, and then f1 can avoid 
    duplicating the error checking.
    
    But what if f1 has the more restrictive domain? Then put the error 
    checking in f1.
    
    
    -- 
    Steven
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:55:11 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:55:11 -0500
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 	
    	
    Message-ID: 
    
    Sibylle Koczian wrote:
    > Peter Otten schrieb:
    >> I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    >> up with. Example:
    >>
    >> def recode_rows(rows, source_encoding, target_encoding):
    >>     def recode(field):
    >>         if isinstance(field, unicode):
    >>             return field.encode(target_encoding)
    >>         elif isinstance(field, str):
    >>             return unicode(field, source_encoding).encode(target_encoding)
    >>         return unicode(field).encode(target_encoding)
    >>
    >>     return (map(recode, row) for row in rows)
    >>
    > 
    > For this case isinstance really seems to be quite reasonable. And it was
    > silly of me not to think of sys.stdout as file object for the example!
    > 
    >> rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    >> writer = csv.writer(sys.stdout)
    >> writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    >>
    >> The only limitation I can see: target_encoding probably has to be a superset 
    >> of ASCII.
    >>
    > 
    > Coping with umlauts and accents is quite enough for me.
    > 
    > This problem really goes away with Python 3 (tried it on another
    > machine), but something else changes too: in Python 2.6 the
    > documentation for the csv module explicitly says "If csvfile is a file
    > object, it must be opened with the ?b? flag on platforms where that
    > makes a difference." The documentation for Python 3.1 doesn't have this
    > sentence, and if I do that in Python 3.1 I get for all sorts of data,
    > even for a list with only one integer literal:
    > 
    > TypeError: must be bytes or buffer, not str
    > 
    > I don't really understand that.
    
    In Python 3, a file opened in 'b' mode is for reading and writing bytes 
    with no encoding/decoding. I believe cvs works with files in text mode 
    as it returns and expects strings/text for reading and writing. Perhaps 
    the cvs doc should say must not be opened in 'b' mode. Not sure.
    
    tjr
    
    
    
    From max at alcyone.com  Tue Nov 24 17:59:26 2009
    From: max at alcyone.com (Erik Max Francis)
    Date: Tue, 24 Nov 2009 14:59:26 -0800
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    In-Reply-To: <4b0c4dbb$0$8926$426a74cc@news.free.fr>
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    	<4b0c4dbb$0$8926$426a74cc@news.free.fr>
    Message-ID: <_fqdncKvQrbT-JHWnZ2dnUVZ_v5i4p2d@giganews.com>
    
    Bruno Desthuilliers wrote:
    > Cameron Laird a ?crit :
    > 
    >>     Grant Edwards on the best way to get help from this group :)
    >>         http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    > 
    > This one really deserves a POTM award !-)
    
    It is a bit surprising to see on IRC how often people are asking for 
    help but trying desperately to either 1. not provide enough information 
    so that anyone could possibly help, or (even weirder) 2. argue with the 
    people trying to help with them or insist they didn't really need the 
    help anyway once they get the answer they're looking for.  The former is 
    surely just laziness, but there's something psychological going on with 
    the latter.
    
    -- 
    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/Skype erikmaxfrancis
       Nine worlds I remember.
        -- Icelandic Edda of Snorri Sturluson
    
    
    From tjreedy at udel.edu  Tue Nov 24 18:06:20 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 18:06:20 -0500
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08".
    
    This should only happen if you paste the test into your .py file as a 
    string literal.
    
    > This is before I can do anything with it. Is there a way
    > to specify that incoming lines (say, when using .readlines() ) should
    > be treated as raw strings?
    
    Or if you use execfile or compile and ask Python to interprete the input 
    as code.
    
    There are no raw strings, only raw string code literals marked with an 
    'r' prefix for raw processing of the quoted text.
    
    
    
    From sjmachin at lexicon.net  Tue Nov 24 18:08:05 2009
    From: sjmachin at lexicon.net (John Machin)
    Date: Tue, 24 Nov 2009 15:08:05 -0800 (PST)
    Subject: Newsgroup for beginners
    References: 
    	<7xiqd9yj8v.fsf@ruckus.brouhaha.com> 
    Message-ID: <59789396-9e9a-4bb5-aa7b-eb9797ddce02@g1g2000pra.googlegroups.com>
    
    On Nov 17, 2:56?pm, Grant Edwards  wrote:
    > On 2009-11-17, Paul Rubin  wrote:
    >
    > > mrholtsr  writes:
    > >> Is there a Python newsgroup for those who are strictly beginners at
    > >> programming and python?
    >
    > > This group has its grouchy moments
    >
    > You've really got to try pretty hard to create one. ?But if you
    > want to, here's how to do it:
    [snip]
    > ?2) Python programs are portable, so don't reveal what OS or
    > ? ? Python version you're using. ?People will ask. Just ignore
    > ? ? them.
    
    Don't supply a traceback, lest you inadvertently divulge such
    information (and more!) e.g.
    
      File "C:\python26\lib\encodings\cp1252.py", line 15, in decode
    
    A good safeguard against accidental disclosure of your Python version
    is to avoid using the default installation folder:
    
    File "C:\snake_teehee_ima_comedian\lib\etc_etc"
    
    This technique, used in a question like "How can I have multiple
    versions of Python installed" gives a good chance of getting a grumpy
    response.
    
    
    From samwyse at gmail.com  Tue Nov 24 18:09:00 2009
    From: samwyse at gmail.com (samwyse)
    Date: Tue, 24 Nov 2009 15:09:00 -0800 (PST)
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting 
    	and...
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com> 
    	
    	<031c4f72$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <07beafe7-b882-4bc1-82af-0e6f6596ba3b@f10g2000vbl.googlegroups.com>
    
    On Nov 24, 4:43?pm, Steven D'Aprano  wrote:
    
    > Oh yes, and people using Windows can't use maildir because (1) it doesn't
    > allow colons in names, and (2) it doesn't have atomic renames. Neither of
    > these are insurmountable problems: an implementation could substitute
    > another character for the colon, and while that would be a technical
    > violation of the standard, it would still work. And the lack of atomic
    > renames would simply mean that implementations have to be more careful
    > about not having two threads writing to the one mailbox at the same time.
    
    A common work around for the former is to URL encode the names, which
    let's you stick all sorts of odd characters.
    
    I'm afraid I can't help with the latter, though.
    
    
    From greg.ewing at canterbury.ac.nz  Tue Nov 24 18:49:10 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Wed, 25 Nov 2009 12:49:10 +1300
    Subject: python bijection
    In-Reply-To: 
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com>
    	
    Message-ID: <7n39ojF3jj6iuU1@mid.individual.net>
    
    Joshua Bronson wrote:
    > So I'm
    > thinking of renaming the class injectivedict or idict instead of
    > bijection. Is that crazy?)
    
    I think you'd be better off calling it something more
    down-to-earth such as bidict (bidirectional dictionary).
    That way people without an advanced degree in mathematics
    have a better shot at not being baffled by it.:-)
    
    -- 
    Greg
    
    
    From paul at boddie.org.uk  Tue Nov 24 19:09:10 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Tue, 24 Nov 2009 16:09:10 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	 
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com> 
    	
    Message-ID: <24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    
    On 24 Nov, 19:25, Antoine Pitrou  wrote:
    >
    > Sorry, I have trouble parsing your sentence. Do you mean bytecode
    > interpretation overhead is minimal compared to the cost of actual useful
    > work, or the contrary?
    > (IMO both are wrong by the way)
    
    I'm referring to what you're talking about at the end. The
    enhancements in Python 3 presumably came about after discussion of
    "threaded interpreters", confirming that the evaluation loop in Python
    2 was not exactly optimal.
    
    > > I imagine that someone (or a number of people) must have profiled the
    > > Python interpreter and shown how much time goes on the individual
    > > bytecode implementations and how much goes on the interpreter's own
    > > housekeeping activities.
    >
    > Well the one problem is that it's not easy to draw a line. Another
    > problem is that it depends on the workload. If you are compressing large
    > data or running expensive regular expressions the answer won't be the
    > same as if you compute a Mandelbrot set in pure Python.
    
    You need to draw the line between work done by system and external
    libraries and that done by Python, but a breakdown of the time spent
    executing each kind of bytecode instruction could be interesting.
    Certainly, without such actual cost estimations, a simple counting of
    bytecodes should hardly give an indication of how optimal some Python
    code might be.
    
    Paul
    
    
    From rhodri at wildebst.demon.co.uk  Tue Nov 24 20:11:29 2009
    From: rhodri at wildebst.demon.co.uk (Rhodri James)
    Date: Wed, 25 Nov 2009 01:11:29 -0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    	
    	
    Message-ID: 
    
    On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    wrote:
    
    > On Nov 24, 3:27 pm, MRAB  wrote:
    >>
    >> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >> it returns.
    >>
    >> Could you provide some code which shows your problem?
    >
    > Here is the code block I have so far:
    > for l in open(CONTENTS, 'r').readlines():
    >     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >         shutil.rmtree(os.path.join(DIR1,f))
    >         if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    >             shutil.rmtree(os.path.join(DIR2,f))
    
    Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    os.path.splitext() doesn't work.  Given that replacing the entire loop  
    contents with "print l" readily disproves your assertion, I suggest you  
    cut and paste actual code if you want an answer.  Otherwise we're just  
    going to keep saying "No, it doesn't", because no, it doesn't.
    
    > A minimally obfuscated line from the log file:
    > K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602
    >
    > What I get from the debugger/python shell:
    > 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602'
    
    When you do what, exactly?
    
    -- 
    Rhodri James *-* Wildebeest Herder to the Masses
    
    
    From rhodri at wildebst.demon.co.uk  Tue Nov 24 20:16:15 2009
    From: rhodri at wildebst.demon.co.uk (Rhodri James)
    Date: Wed, 25 Nov 2009 01:16:15 -0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    	
    	
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 01:11:29 -0000, Rhodri James  
     wrote:
    
    > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    > wrote:
    >
    >> On Nov 24, 3:27 pm, MRAB  wrote:
    >>>
    >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >>> it returns.
    >>>
    >>> Could you provide some code which shows your problem?
    >>
    >> Here is the code block I have so far:
    >> for l in open(CONTENTS, 'r').readlines():
    >>     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >>     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >>         shutil.rmtree(os.path.join(DIR1,f))
    >>         if f in os.listdir(DIR2) and  
    >> os.path.isdir(os.path.join(DIR2,f)):
    >>             shutil.rmtree(os.path.join(DIR2,f))
    >
    > Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    > os.path.splitext() doesn't work.
    
    I meant, "doesn't work on a tuple".  Sigh.  It's been one of those days.
    
    -- 
    Rhodri James *-* Wildebeest Herder to the Masses
    
    
    From rt8396 at gmail.com  Tue Nov 24 20:53:21 2009
    From: rt8396 at gmail.com (r)
    Date: Tue, 24 Nov 2009 17:53:21 -0800 (PST)
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com> 
    	
    Message-ID: <638c0f8f-9c63-4db4-b1ae-a92abfa20691@f16g2000yqm.googlegroups.com>
    
    On Nov 24, 9:45?am, astral orange <457r0... at gmail.com> wrote:
    >
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    > yet I can follow and understand what is going on very easily, that
    > helps out tremendously.
    > Very clearly written...Thank you!
    
    Yes and this is the stumbling block that almost every tutorial writer
    puts before the uninitiated! Simple, Simple examples are the key. The
    subject matter of the example should never outshine the subject that
    is being taught. Everybody understand what a first, middle, and last
    name is! What really ticks me off is when some show-off tut writer
    goes off using an internet protocol or mp3 tags example to explain
    classes or functions... WHAT!-O
    
    Pssst...tut writers remember this! While you may be an emacs "zen
    master" playing key chords that would make most piano virtuosos
    jealous, your tutorials are meant for inexperience users. Yes,
    exposing your "huge intelligence" to the world may give you warm
    fuzzies, but the "shock-and-awe-freak-show" will only be to the
    detriment of the very ideas you are attempting to transform into these
    minds.
    
    
    
    
    
    From jabronson at gmail.com  Tue Nov 24 22:28:38 2009
    From: jabronson at gmail.com (Joshua Bronson)
    Date: Tue, 24 Nov 2009 19:28:38 -0800 (PST)
    Subject: python bijection
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> 
    	 
    	<7n39ojF3jj6iuU1@mid.individual.net>
    Message-ID: <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com>
    
    On Nov 24, 6:49?pm, Gregory Ewing  wrote:
    > Joshua Bronson wrote:
    > > So I'm
    > > thinking of renaming the class injectivedict or idict instead of
    > > bijection. Is that crazy?)
    >
    > I think you'd be better off calling it something more
    > down-to-earth such as bidict (bidirectional dictionary).
    > That way people without an advanced degree in mathematics
    > have a better shot at not being baffled by it.:-)
    >
    > --
    > Greg
    
    heh, duly noted:) bidict it is!
    
    
    From invalid at invalid.invalid  Tue Nov 24 22:31:41 2009
    From: invalid at invalid.invalid (Grant Edwards)
    Date: Wed, 25 Nov 2009 03:31:41 +0000 (UTC)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	
    Message-ID: 
    
    On 2009-11-25, Rhodri James  wrote:
    > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    > wrote:
    >
    >> On Nov 24, 3:27 pm, MRAB  wrote:
    >>>
    >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >>> it returns.
    >>>
    >>> Could you provide some code which shows your problem?
    >>
    >> Here is the code block I have so far:
    >> for l in open(CONTENTS, 'r').readlines():
    >>     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >>     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >>         shutil.rmtree(os.path.join(DIR1,f))
    >>         if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    >>             shutil.rmtree(os.path.join(DIR2,f))
    >
    > Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    > os.path.splitext() doesn't work.  Given that replacing the entire loop  
    > contents with "print l" readily disproves your assertion, I suggest you  
    > cut and paste actual code if you want an answer.  Otherwise we're just  
    > going to keep saying "No, it doesn't", because no, it doesn't.
    
    It's, um, rewarding to see my recent set of instructions being
    followed.
    
    >> A minimally obfuscated line from the log file:
    >> K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    >> smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    >> 11/24/2009 08:16:42 ; 1259068602
    >>
    >> What I get from the debugger/python shell:
    >> 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    >> smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    >> 11/24/2009 08:16:42 ; 1259068602'
    >
    > When you do what, exactly?
    
    ;)
    
    -- 
    Grant
    
    
    From n00m at narod.ru  Tue Nov 24 23:57:04 2009
    From: n00m at narod.ru (n00m)
    Date: Tue, 24 Nov 2009 20:57:04 -0800 (PST)
    Subject: Can "self" crush itself?
    Message-ID: 
    
    Why does "h" instance stay alive?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                self.crush_me()
        def crush_me(self):
            print 'Will self be crushed?'
            self = None
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    
    print f
    print g
    print h
    
    
    =============== RESTART ====
    
    Will self be crushed?
    <__main__.Moo instance at 0x00CC9260>
    <__main__.Moo instance at 0x00CC9468>
    <__main__.Moo instance at 0x00CC94B8>
    
    
    From cjns1989 at gmail.com  Wed Nov 25 00:11:08 2009
    From: cjns1989 at gmail.com (Chris Jones)
    Date: Wed, 25 Nov 2009 00:11:08 -0500
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: <031c4f72$0$1336$c3e8da3@news.astraweb.com>
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    	
    	<031c4f72$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <20091125051108.GE3122@turki.gavron.org>
    
    On Tue, Nov 24, 2009 at 05:43:32PM EST, Steven D'Aprano wrote:
    > On Tue, 24 Nov 2009 13:19:10 -0500, Chris Jones wrote:
    > 
    > > On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    > > 
    > >> Good grief, it's about six weeks away from 2010 and Thunderbird still
    > >> uses mbox as it's default mail box format. Hello, the nineties called,
    > >> they want their mail formats back! Are the tbird developers on crack or
    > >> something? I can't believe that they're still using that crappy format.
    > >> 
    > >> No, I tell a lie. I can believe it far too well.
    > > 
    > > :-)
    > > 
    > > I realize that's somewhat OT, but what mail box format do you recommend,
    > > and why?
    > 
    > maildir++
    > 
    > http://en.wikipedia.org/wiki/Maildir
    
    Outside the two pluses, maildir also goes back to the 90s - 1995, Daniel
    Berstein's orginal specification.
    
    > Corruption is less likely, if there is corruption you'll only lose a 
    > single message rather than potentially everything in the mail folder[*], 
    > at a pinch you can read the emails using a text editor or easily grep 
    > through them, and compacting the mail folder is lightning fast, there's 
    > no wasted space in the mail folder, and there's no need to mangle lines 
    > starting with "From " in the body of the email.
    
    This last aspect very welcome.
    
    > The only major downside is that because you're dealing with potentially 
    > thousands of smallish files, it *may* have reduced performance on some 
    > older file systems that don't deal well with lots of files. These days, 
    > that's not a real issue.
    > 
    > Oh yes, and people using Windows can't use maildir because (1) it doesn't 
    > allow colons in names, and (2) it doesn't have atomic renames. Neither of 
    > these are insurmountable problems: an implementation could substitute 
    > another character for the colon, and while that would be a technical 
    > violation of the standard, it would still work. And the lack of atomic 
    > renames would simply mean that implementations have to be more careful 
    > about not having two threads writing to the one mailbox at the same time.
    > 
    > 
    > [*] I'm assuming normal "oops there's a bug in the mail client code" 
    > corruption rather than "I got drunk and started deleting random files and 
    > directories" corruption.
    
    I'm not concerned with the other aspects, but I'm reaching a point where
    mutt is becoming rather sluggish with the mbox format, especially those
    mail boxes that have more than about 3000 messages and it looks like
    maildir, especially with some form of header caching might help.
    
    Looks like running a local IMAP server would probably be more effective,
    though.
    
    Thank you for your comments.
    
    CJ
    
    
    From ben+python at benfinney.id.au  Wed Nov 25 00:12:26 2009
    From: ben+python at benfinney.id.au (Ben Finney)
    Date: Wed, 25 Nov 2009 16:12:26 +1100
    Subject: Can "self" crush itself?
    References: 
    Message-ID: <87tywj2nnp.fsf@benfinney.id.au>
    
    n00m  writes:
    
    >     def crush_me(self):
    >         print 'Will self be crushed?'
    >         self = None
    
    As with any function, the parameter is bound to a *local* name, in this
    case the name ?self?. Whatever you rebind ?self? to inside the function,
    the binding is lost once the function exits. None of this affects any
    other bindings the same object might retain from outside the function.
    
    It's exactly the same behaviour as this:
    
        >>> def frobnicate(foo):
        ...     print "Entered ?frobnicate?"
        ...     foo = None
        ...     print "Leaving ?frobnicate?"
        ... 
        >>> bar = "syzygy"
        >>> print bar
        syzygy
        >>> frobnicate(bar)
        Entered ?frobnicate?
        Leaving ?frobnicate?
        >>> print bar
        syzygy
    
    The only difference with an instance method is how Python determines
    what object to bind to the local name ?self?. That still doesn't change
    the fact that it's a local name inside that function.
    
    -- 
     \        ?Read not to contradict and confute, nor to believe and take |
      `\          for granted ? but to weigh and consider.? ?Francis Bacon |
    _o__)                                                                  |
    Ben Finney
    
    
    From swheatley at gmail.com  Wed Nov 25 00:38:52 2009
    From: swheatley at gmail.com (Shawn Wheatley)
    Date: Tue, 24 Nov 2009 21:38:52 -0800 (PST)
    Subject: python gui builders
    References: <8u9Mm.35397$Wd1.32454@newsfe15.iad>
    	<007f3944$0$23487$c3e8da3@news.astraweb.com> 
    	<05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> 
    	<863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> 
    	
    Message-ID: <987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    
    It's not quite all encompassing, but I found this link last year when
    looking for a similar comparison of Python GUIs:
    http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/
    
    Tkinter, Qt, GTK, IronPython... I think the only thing missing is
    Jython w/ Swing or SWT. Check it out.
    
    Shawn
    
    On Nov 18, 5:11?pm, Stef Mientki  wrote:
    > Wouldn't it be nice
    > if each fan of some form of GUI-package,
    > would post it's code (and resulting images) for generating one or two
    > standard GUI-forms ?
    
    
    From n00m at narod.ru  Wed Nov 25 00:45:56 2009
    From: n00m at narod.ru (n00m)
    Date: Tue, 24 Nov 2009 21:45:56 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    Message-ID: <57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    
    
    > Whatever you rebind ?self? to inside the function...
    
    
    Seems you are right! Thanks, Ben, for the lesson :-)
    
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                self.crush_me()
        def crush_me(self):
            print 'Will self be crushed?'
            self = None
            print self
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    print '================='
    print h
    
    
    
    Will self be crushed?
    None
    =================
    <__main__.Moo instance at 0x00CC9468>
    
    
    From pengyu.ut at gmail.com  Wed Nov 25 00:47:04 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 23:47:04 -0600
    Subject: get line number and filename in a source file
    Message-ID: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    
    __LINE__ __FILE__ in C++ can give the current line number and
    filename. Is there a similar thing in python that can give me the
    current line number and filename?
    
    Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    
    
    From clp2 at rebertia.com  Wed Nov 25 01:01:57 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 22:01:57 -0800
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: <50697b2c0911242201r5f260616wa5c3fc33df0d28db@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 9:47 PM, Peng Yu  wrote:
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    
    import inspect
    filename, linenum, funcname = inspect.getframeinfo(inspect.currentframe())[:3]
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From rami.chowdhury at gmail.com  Wed Nov 25 01:04:24 2009
    From: rami.chowdhury at gmail.com (Rami Chowdhury)
    Date: Tue, 24 Nov 2009 22:04:24 -0800
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: 
    
    On Nov 24, 2009, at 21:47 , Peng Yu wrote:
    
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    > Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    
    What do you want to use them for? 
    
    > -- 
    > http://mail.python.org/mailman/listinfo/python-list
    
    
    
    From nagle at animats.com  Wed Nov 25 01:42:28 2009
    From: nagle at animats.com (John Nagle)
    Date: Tue, 24 Nov 2009 22:42:28 -0800
    Subject: CentOS 5.3 vs. Python 2.5
    Message-ID: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    
        My dedicated hosting provider wants to switch me to a new server with
    CentOS 5.3, so I have to look at how much work is required.
    
        CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
    requires Python 2.4 for its own internal purposes, and actually
    installing Python 2.5 breaks the package manager.  There's
    no supported RPM for upgrading.
    
        It's apparently necessary to build Python 2.5 from source,
    build all the packages, and debug.  Nor does that "just work".
    There's documentation, but some of it is in Japanese.
    
    http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    
    Google Translate gives me
    
    "[...] On this entry uses the src.rpm. Kitara dropped, rpmbuild-rebuild 
    (rpm-rebuild, but often seen the entry, it says, there's this option only old 
    rpm) [...]"
    
    I'm trying to figure that out.
    
    				John Nagle
    
    
    From davea at ieee.org  Wed Nov 25 01:58:56 2009
    From: davea at ieee.org (Dave Angel)
    Date: Wed, 25 Nov 2009 01:58:56 -0500
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: <4B0CD5B0.20600@ieee.org>
    
    Peng Yu wrote:
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    >
    > Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    >
    >   
    mod.__name__  gives the module name, and   mod.__file__  gives the full 
    path to the given module.  Or if you need those for the current module, 
    just leave off the prefix.
    
    For line number information, you probably can get it from the inspect 
    module, but I don't have any direct experience.  I do have the following 
    untested line
    in my notes:
               inspect.getframeinfo(inspect.currentframe()).function)
    
    DaveA
    
    
    
    
    
    From timr at probo.com  Wed Nov 25 02:19:01 2009
    From: timr at probo.com (Tim Roberts)
    Date: Tue, 24 Nov 2009 23:19:01 -0800
    Subject: python and Postgresq
    References: 
    	<7mv62nF3hp171U1@mid.uni-berlin.de>
    	
    Message-ID: 
    
    Krishnakant  wrote:
    >
    >Python-pgsql is a much better choice when it comes to big applications,
    >specially if you are going to deal with xml-rpc.  I have found that
    >python-pgsql handles integers and other such postgresql datatypes
    >better.
    
    I wonder if you would mind expanding on the experiences that lead you to
    say this.  I've use both extensively (plus the old "pg"), and I've found
    psycopg to be unconditionally the better choice, especially for big
    applications where performance is critical.
    -- 
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.
    
    
    From wuwei23 at gmail.com  Wed Nov 25 02:28:47 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Tue, 24 Nov 2009 23:28:47 -0800 (PST)
    Subject: IDE+hg
    References: 
    Message-ID: <75ef83cb-b928-4bf4-b20a-11484a3fdc45@2g2000prl.googlegroups.com>
    
    NiklasRTZ  wrote:
    > no py IDE I found has easy hg access.
    
    ActiveState's Komodo IDE has support for CVS, Perforce, subversion,
    bazaar, git and mercurial.
    
    
    
    From news123 at free.fr  Wed Nov 25 03:08:26 2009
    From: news123 at free.fr (News123)
    Date: Wed, 25 Nov 2009 09:08:26 +0100
    Subject: scanning under windows WIA with custom settings (dpi / etc )
    In-Reply-To: <4b097593$0$30269$426a74cc@news.free.fr>
    References: <4b097593$0$30269$426a74cc@news.free.fr>
    Message-ID: <4b0ce5fa$0$25790$426a34cc@news.free.fr>
    
    
    
    News123 wrote:
    > Hi,
    > 
    > I'm trying to scan a document from a python 2.6 script without user
    > interaction.
    > 
    > I found  a code snippet, that allows me to scan under Vista, but that
    > doesn't allow me to select the dpi / color mode / etc.
    
    I'm still stuck.
    
    
    I'll try to look at any solution (visual C++, C#, Basic) first.
    Then it's perhaps easier to pythonize it via python .net.
    
    However I don't know whether python .net exists for 2.6 and whether it
    is stable enough.
    
    
    N
    
    > 
    > The snippet uses win32com.client
    > 
    > # ##################### script start
    > import win32com.client,os
    > 
    > WIA_IMG_FORMAT_PNG       = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
    > WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
    > 
    > os.chdir('c:/temp')
    > wia = win32com.client.Dispatch("WIA.CommonDialog")
    > dev = wia.ShowSelectDevice()
    > for command in dev.Commands:
    >     if command.CommandID==WIA_COMMAND_TAKE_PICTURE:
    >         foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE)
    > i=1
    > for item in dev.Items:
    >     if i==dev.Items.Count:
    >         image=item.Transfer(WIA_IMG_FORMAT_PNG)
    >         break
    >     i=i+1
    > 
    > image.SaveFile("test.png")
    > ######################### script end
    > 
    > 
    > My problems are:
    > 
    > - This script works fine for me under Windows 7, however I'm
    >   unable to   specify additional parameters, like dpi and
    >   color mode.
    > 
    > - The script doesn't work under windows XP, though the scanner driver is
    > installed. (Gimp finds the scanner (as WIA scanner)).
    > Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL.
    > The error message is:
    > --------------------------------------------------------------------
    > Traceback (most recent call last):
    >   File "C:\work\python\minidemos\wia_get_simple.py", line 7, in 
    >     wia = win32com.client.Dispatch("WIA.CommonDialog")
    >   File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line
    > 95, in Dispatch
    >     dispatch, userName =
    > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    >   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
    > 104, in _GetGoodDispatchAndUserName
    >     return (_GetGoodDispatch(IDispatch, clsctx), userName)
    >   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
    > 84, in _GetGoodDispatch
    >     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    > pythoncom.IID_IDispatch)
    > com_error: (-2147221005, 'Invalid class string', None, None)
    > ---------------------------------------------------------------------
    > 
    > 
    > As I have no knowledge of Win32com and WIA I would appreciate some help
    > or good documentation about wincom32 / WIA with python
    > 
    > 
    > 
    > thanks for your help and bye
    > 
    > 
    > N
    > 
    > 
    > 
    > 
    > 
    > 
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 03:13:04 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 25 Nov 2009 08:13:04 GMT
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    Message-ID: 
    
    On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    
    > My dedicated hosting provider wants to switch me to a new server with
    > CentOS 5.3, so I have to look at how much work is required.
    > 
    >     CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
    > requires Python 2.4 for its own internal purposes, and actually
    > installing Python 2.5 breaks the package manager.  There's no supported
    > RPM for upgrading.
    > 
    >     It's apparently necessary to build Python 2.5 from source,
    > build all the packages, and debug.
    
    
    You shouldn't need *quite* that much effort, particularly if you don't 
    care about tkinter. Just use the alternate installation so it doesn't 
    stomp all over the 2.4 installation:
    
    .configure
    make
    make altinstall
    
    You will need root or sudo for that last one.
    
    
    I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly 
    easily for me:
    
    $ wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    ...
    18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    $
    $ tar xzf Python-2.5.4.tgz
    $ cd Python-2.5.4
    $ ./configure
    ...
    $ make
    ...
    $ sudo make altinstall
    Password: 
    ...
    $ python -V
    Python 2.4.3
    $ python2.5 -V
    Python 2.5.4
    
    
    And it all seems to just work for me.
    
    
    
    
    > Nor does that "just work". There's
    > documentation, but some of it is in Japanese.
    > 
    > http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    
    I don't understand why you're using documentation for third-party RPMs as 
    evidence that building from source will be troublesome.
    
    
    
    -- 
    Steven
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 03:24:02 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 09:24:02 +0100
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    	
    Message-ID: <4b0ce96f$0$30625$426a74cc@news.free.fr>
    
    astral orange a ?crit :
    > On Nov 23, 10:37 pm, r  wrote:
    (snip)
    >> This is a horrible example to show noobs. I think the OP could better
    >> understand this as a class EVEN though the OP may or may not know what
    >> a class *is* yet.
    >>
    >>>>> class Name():
    >>         def __init__(self, first, middle, last):
    >>                 self.first = first
    >>                 self.middle = middle
    >>                 self.last = last
    >>
    (snip)
    
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    
    It's a reference to the current Name instance. But while technically 
    correct, I'm sure such this kind of explanation really helps :-/
    
    
    
    From lallous at lgwm.org  Wed Nov 25 03:51:06 2009
    From: lallous at lgwm.org (lallous)
    Date: Wed, 25 Nov 2009 09:51:06 +0100
    Subject: How to import a file by its full path using C api?
    Message-ID: 
    
    Hello
    
    PyObject* PyImport_ImportModule( const char *name) 
    
    How to specify a full file path instead and a module name?
    
    Like PyImport_SomeFunction(const char *path_to_script, const char *name)
    
    Thanks,
    Elias 
    
    
    From joncle at googlemail.com  Wed Nov 25 04:45:08 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Wed, 25 Nov 2009 01:45:08 -0800 (PST)
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    	
    Message-ID: 
    
    On Nov 25, 8:13?am, Steven D'Aprano
     wrote:
    > On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    > > My dedicated hosting provider wants to switch me to a new server with
    > > CentOS 5.3, so I have to look at how much work is required.
    >
    > > ? ? CentOS 5.3 apparently still ships with Python 2.4. ?Worse, it
    > > requires Python 2.4 for its own internal purposes, and actually
    > > installing Python 2.5 breaks the package manager. ?There's no supported
    > > RPM for upgrading.
    >
    > > ? ? It's apparently necessary to build Python 2.5 from source,
    > > build all the packages, and debug.
    >
    > You shouldn't need *quite* that much effort, particularly if you don't
    > care about tkinter. Just use the alternate installation so it doesn't
    > stomp all over the 2.4 installation:
    >
    > .configure
    > make
    > make altinstall
    >
    > You will need root or sudo for that last one.
    >
    > I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
    > easily for me:
    >
    > $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    > ...
    > 18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    > $
    > $ tar xzf Python-2.5.4.tgz
    > $ cd Python-2.5.4
    > $ ./configure
    > ...
    > $ make
    > ...
    > $ sudo make altinstall
    > Password:
    > ...
    > $ python -V
    > Python 2.4.3
    > $ python2.5 -V
    > Python 2.5.4
    >
    > And it all seems to just work for me.
    >
    > > Nor does that "just work". There's
    > > documentation, but some of it is in Japanese.
    >
    > >http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    >
    > I don't understand why you're using documentation for third-party RPMs as
    > evidence that building from source will be troublesome.
    >
    > --
    > Steven
    
    And might I add on a box where there is no root access, but sufficient
    tools (compilers etc...)
    
    1) Compile from source
    2) Set PYTHONPATH correctly for your shell
    3) Set your normal path to include your Python rather than the
    system's default Python
    4) When installing modules (via setup.py install or easy_install)
    include a "home_dir=" (I think that's right OTTOMH) to somewhere in
    your home directory, and make sure step 2) complies with this.
    5) Double check with "which python" to make sure it's the correct
    version.
    
    hth
    Jon.
    
    
    
    
    
    From n00m at narod.ru  Wed Nov 25 04:46:29 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 01:46:29 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    Message-ID: 
    
    Then how can we destroy the 3rd instance,
    right after its creation and from inside
    class Moo code?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                print id(self)
                ## 13406816
                ## in what dict is this ID?
                ## and can we delete it from there?
    
                ## ???
    
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    print h
    
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 04:55:05 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 10:55:05 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	
    Message-ID: <4b0cfefa$0$24750$426a34cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > 
    > Let's head towards murkier waters (at least murkier to me -- hopefully 
    > they can be easily clarified):  some of the attributes are read-only, 
    > such as record count; others are not directly exposed, but still 
    > settable, such as table version; and still others require a small amount 
    > of processing... at which point do I switch from simple attribute access 
    > to method access?
    
    Short answer : you don't !-)
    
    Long answer : well, in fact you do, but the client code doesn't have to 
    be aware that it's in fact calling an accessor.
    
    Before we go into more details, you have to know that Python has a 
    pretty good support for computed attributes, with both a simple generic 
    solution (the property type) and the full monty (custom types 
    implementing the descriptor protocol). So from the "interface" POV, you 
    should never have an explicit accessor method for what is semantically 
    an attribute (wheter the attribute is a plain or a computed one being 
    part of the implementation).
    
    Let's start with your second point: "not directly exposed but still 
    settable". I assume you mean "not part of the interface, only supposed 
    to be accessed (rw) from the methods" - if not, please pardon my 
    stupidity and provide better explanations !-). If yes: Python doesn't 
    have "language inforced" access restrictions (private / protected / 
    etc), but a *very strong* naming convention which is that names starting 
    with a leading underscore are implementation details, not part of the 
    official interface, and shouldn't be accessed directly. Kind of a 
    "warranty voided if unsealed".
    
    So if you have attributes you don't want to "expose" to the outside 
    world, just add a single leading underscore to their names.
    
    First and third points are solved by using computed attributes - usually 
    a property. The property type takes a few accessor functions as 
    arguments - typically, a getter and a setter, and eventually a 
    "deleter". Used as a class attribute, a property instance will hook up 
    into the attribute lookup / setup mechanism (__getattribute__ and 
    __setattr__), and will call resp. it's getter or setter function, 
    passing it the instance and (for the setter) value.
    
    This directly solves the third point. For the first one, the obvious 
    solution is to use a property with a setter that raises an exception - 
    canonically, an AttributeError with a message explaining that the 
    attribute is read-only.
    
    And for something more hands-on:
    
    class Person(object):
        def __init__(self, firstname, lastname, birthdate):
            self.firstname = firstname
            self.lastname = lastnale
            self.birthdate = birthdate
            self._foo = 42 # implementation only
    
        def _getfullname(self):
            return "%s %s" % (self.firstname, self.lastname)
        def _setfullname(self, value):
            raise AttributeError("%s.fullname is read-only" % type(self)
        fullname = property(fget=_getfullname, fset=_setfullname)
    
        def _getage(self):
            return some_computation_with(self.birthdate)
        def _setage(self, value):
            raise AttributeError("%s.age is read-only" % type(self)
        age = property(fget=_getage, fset=_setage)
    
    
    For more on computed attributes, you may want to read about the 
    "descriptor protocol" (google is your friend as usual). This and the 
    attribute resolution mechanism are fundamental parts of Python's inner 
    working. Learn how it works if you really want to leverage Python's power.
    
    HTH
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 04:56:19 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 10:56:19 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 		<4b0b92de$0$14677$426a74cc@news.free.fr>		<4B0C1A4E.7050204@stoneleaf.us>	<50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    	
    Message-ID: <4b0cff43$0$24750$426a34cc@news.free.fr>
    
    Ethan Furman a ?crit :
    (snip)
    
    > Okay, I'll go back and switch all my attributes *back* to attributes -- 
    > and properties will be much nicer than my original implementation (using 
    > __getattr__ and __setattr__).
    
    It will also be faster FWIW.
    
    
    From clp2 at rebertia.com  Wed Nov 25 04:58:49 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Wed, 25 Nov 2009 01:58:49 -0800
    Subject: Can "self" crush itself?
    In-Reply-To: 
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    Message-ID: <50697b2c0911250158p62c1edbcmccb095d3e1779d83@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 1:46 AM, n00m  wrote:
    > Then how can we destroy the 3rd instance,
    > right after its creation and from inside
    > class Moo code?
    
    Why would you want to do that in the first place? It's strange to say the least.
    If you want to prevent an instance being created in the first place,
    you can override __new__().
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From ben+python at benfinney.id.au  Wed Nov 25 05:04:32 2009
    From: ben+python at benfinney.id.au (Ben Finney)
    Date: Wed, 25 Nov 2009 21:04:32 +1100
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    Message-ID: <87einm3opb.fsf@benfinney.id.au>
    
    n00m  writes:
    
    > Then how can we destroy the 3rd instance, right after its creation and
    > from inside class Moo code?
    
    Normally, one binds whatever references one needs, and lets the garbage
    collector clean them up once they fall out of scope. If the references
    are living beyond their usefulness, that's probably a sign that your
    code isn't modular enough; short, focussed functions might help. But
    this is all diagnosis without seeing the symptoms.
    
    Perhaps it's beyond time that you explained what you're trying to
    achieve that you think ?destroy an instance? will help.
    
    -- 
     \      ?I bought a self learning record to learn Spanish. I turned it |
      `\        on and went to sleep; the record got stuck. The next day I |
    _o__)                   could only stutter in Spanish.? ?Steven Wright |
    Ben Finney
    
    
    From n00m at narod.ru  Wed Nov 25 06:42:07 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 03:42:07 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	 
    	<87einm3opb.fsf@benfinney.id.au>
    Message-ID: <10581b96-f44e-4ac5-b2cb-6d5a5f12aa89@m16g2000yqc.googlegroups.com>
    
    > Why would you want to do that in the first place?
    
    I don't know... :-)
    As Schoepenhauer put it:
    The man can do what he wants to do but he can't want to want
    what he wants to do
    
    
    
    From jeanmichel at sequans.com  Wed Nov 25 06:58:21 2009
    From: jeanmichel at sequans.com (Jean-Michel Pichavant)
    Date: Wed, 25 Nov 2009 12:58:21 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    References: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    Message-ID: <4B0D1BDD.70400@sequans.com>
    
    Barak, Ron wrote:
    > Hi,
    >  
    > I'm trying to add the logging module to my application, but I seem to 
    > be missing something.
    > My application (a wxPython one) has a main script that calls various 
    > helper classes.
    > I want the log messages from all modules to go to one central log file.
    >  
    > When I implement logging, I think that due to preparation, I get the 
    > same message more than once.
    >  
    > Here's an example:
    >  
    > [snip example]
    >  
    > Could you suggest what should I change in the above scripts so that 
    > the log messages would appear only once ?
    >  
    > Thanks,
    > Ron.
    >
    If you are starting with the logging facility, I would suggest to add 
    handlers only to the root logger (in your __main__ section).
    
    Basically, never configure or add handlers to any logger except for the 
    root logger in your __main__ section. There are very few reasons why you 
    would break this rule. And when you'll be familiar with the logging 
    module you'll when to break it.
    
    
    [server.py]
    
    import logging
    import logging.handlers
    
    logger = logging.getLogger(__name__) # you'd better to create the logger 
    at the module level, you may want to log within   the module function
    
    def aFunction(a, b, ,c):
        logger.debug('You called aFunction')
    
    class Server():
        def __init__(self):
            self.logger = logger
    
        def util(self):
            self.logger.warning('This message comes from Server module ')
    
    
    [client.py]
    
    import logging
    import logging.handlers
    from server import Server
    
    logger = logging.getLogger(__name__)
    
    class Client():
        def __init__(self):
            self.logger = logger
    
        def client_test(self):
            self.logger.warning("This message comes from Client module")
    
    if __name__ == "__main__":
        rootLogger = logging.getLogger()
        rootLogger.addHandler(logging.FileHandler("client.log"))
        rootLogger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s 
    %(name)-12s %(levelname)-8s %(message)s"))
        rootLogger.setLevel(logging.DEBUG)
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    Happy logging,
    
    Jean-Michel
    
    
    From solipsis at pitrou.net  Wed Nov 25 07:02:24 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Wed, 25 Nov 2009 12:02:24 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	 <1259090178.661.34.camel@localhost>
    	
    Message-ID: 
    
    Le Tue, 24 Nov 2009 22:08:19 +0000, Benjamin Peterson a ?crit?:
    > 
    >> Would it be worth in-lining the remaining part of PyObject_IsTrue in
    >> ceval?
    > 
    > Inlining by hand is prone to error and maintainability problems.
    
    Which is why we like to do it :-))
    
    
    
    
    From solipsis at pitrou.net  Wed Nov 25 07:11:31 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Wed, 25 Nov 2009 12:11:31 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	
    	<24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 16:09:10 -0800, Paul Boddie a ?crit?:
    > 
    > I'm referring to what you're talking about at the end. The enhancements
    > in Python 3 presumably came about after discussion of "threaded
    > interpreters", confirming that the evaluation loop in Python 2 was not
    > exactly optimal.
    
    An optimal evaluation loop is a evaluation loop which doesn't get 
    executed at all :-)
    (which is what unladen-swallow, cython and pypy are trying to do)
    
    > You need to draw the line between work done by system and external
    > libraries and that done by Python, but a breakdown of the time spent
    > executing each kind of bytecode instruction could be interesting.
    
    When you say "executing each kind of bytecode instruction", are you 
    talking about the overhead of bytecode dispatch and operand gathering, or 
    the total cost including doing the useful work?
    
    Regardless, it probably isn't easy to do such measurements. I once tried 
    using AMD's CodeAnalyst (I have an AMD CPU) but I didn't manage to get 
    any useful data out of it; the software felt very clumsy and it wasn't 
    obvious how to make it take into account the source code of the Python 
    interpreter.
    
    Regards
    
    Antoine.
    
    
    
    
    From Nadav.C at qualisystems.com  Wed Nov 25 07:47:16 2009
    From: Nadav.C at qualisystems.com (Nadav Chernin)
    Date: Wed, 25 Nov 2009 14:47:16 +0200
    Subject: Help with pprint
    Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    
    Hello, I want to print list of lists in matrix format. So I use pprint
    with parameter 'width' for this target. 
    
    For example :
    
     
    
    >>> data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    
    >>> pprint(data,width=20)
    
    [[1, 1, 1],
    
     [1, 1, 1],
    
     [1, 1, 1]]
    
     
    
    The problem that I don't know how to select width value, because if:
    
     
    
    >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one',
    'one']]  
    
    >>> pprint(data,width=20)
    
    [['one',
    
      'one',
    
      'one'],
    
     ['one',
    
      'one',
    
      'one'],
    
     ['one',
    
      'one',
    
      'one']]
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From newsuser at stacom-software.de  Wed Nov 25 07:49:44 2009
    From: newsuser at stacom-software.de (Alexander Eisenhuth)
    Date: Wed, 25 Nov 2009 13:49:44 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application busy"
    Message-ID: 
    
    Hello list,
    
    I'm having a problem with a python COM Excel client that rarely gets the 
    exception pywintypes.com_error with the error code -2147417846. (means Excel is 
    busy) Here the python code of the exception handling:
    
    [...]
    try:
         # write a excel cell
    [...]
    except pywintypes.com_error, ex:
         if ex[0] == -2147417846:
             time.sleep(1.0)
             # retry write?
    [...]
    
    My first approach was to retry the writing to the excel cell. But that ends in a 
    hanging Excel application (probably a deadlock).
    
    After a little research I found this post:
    
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5
    
    "[...] If you don't register a MessageFilter yourself (by calling 
    CoRegisterMessageFilter), you will get default behavior which will be to fail 
    the call if it gets rejected.  .Net converts the failure HRESULT to an 
    exception.  To deal with the possibility of the server being busy when you try 
    to call, you need to implement IMessageFilter::RetryRejectedCall in your client 
    code and also register the message filter.  In most cases, you will just need to 
    wait for a few seconds and then retry the call--generally that will be 
    sufficient time to enable Word to finish whatever it is doing so it can handle 
    your call.  However, if the instance of Word that you are controlling could 
    possibly visible, you might want to add additional logic to display the 
    OLEUIBUSY dialog after some amount of time has passed to notify the user that 
    you are waiting on Word to do something and give them the opportunity to help 
    the process.  For example, as Misha mentions, Word will reject all incoming 
    calls if a modal dialog box is up.  Therefore, in that situation, you would be 
    blocked indefinitely until the dialog is dismissed. [...]"
    
    As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't 
    included in pywin32 I don't see a possibility to do that, or?
    
    Did anybody else have to deal with that problem?
    
    Any hints are very welcome.
    
    Regards
    Alexander
    
    
    From enleverLesX_XXmcX at XmclavXeauX.com.invalid  Wed Nov 25 07:55:40 2009
    From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP)
    Date: Wed, 25 Nov 2009 13:55:40 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application
    	busy"
    References: 
    Message-ID: <4b0d2950$0$967$ba4acef3@news.orange.fr>
    
    Hi! 
    
    Your computer is too slow, for launch Excel.
    Configure the machine for more speed...
    
    @+
    -- 
    MCI
    
    
    From joncle at googlemail.com  Wed Nov 25 07:58:57 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Wed, 25 Nov 2009 04:58:57 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	
    	
    Message-ID: <80c312f8-2b0f-4ec0-9dcd-da0ed1efdbfc@37g2000yqm.googlegroups.com>
    
    On Nov 25, 3:31?am, Grant Edwards  wrote:
    > On 2009-11-25, Rhodri James  wrote:
    >
    >
    >
    > > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo  ?
    > > wrote:
    >
    > >> On Nov 24, 3:27 pm, MRAB  wrote:
    >
    > >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > >>> it returns.
    >
    > >>> Could you provide some code which shows your problem?
    >
    > >> Here is the code block I have so far:
    > >> for l in open(CONTENTS, 'r').readlines():
    > >> ? ? f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    > >> ? ? if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    > >> ? ? ? ? shutil.rmtree(os.path.join(DIR1,f))
    > >> ? ? ? ? if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    > >> ? ? ? ? ? ? shutil.rmtree(os.path.join(DIR2,f))
    >
    > > Ahem. ?This doesn't run. ?os.path.split() returns a tuple, and calling ?
    > > os.path.splitext() doesn't work. ?Given that replacing the entire loop ?
    > > contents with "print l" readily disproves your assertion, I suggest you ?
    > > cut and paste actual code if you want an answer. ?Otherwise we're just ?
    > > going to keep saying "No, it doesn't", because no, it doesn't.
    >
    > It's, um, rewarding to see my recent set of instructions being
    > followed.
    >
    > >> A minimally obfuscated line from the log file:
    > >> K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > >> smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > >> 11/24/2009 08:16:42 ; 1259068602
    >
    > >> What I get from the debugger/python shell:
    > >> 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > >> smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > >> 11/24/2009 08:16:42 ; 1259068602'
    >
    > > When you do what, exactly?
    >
    > ;)
    >
    > --
    > Grant
    
    Can't remember if this thread counts as "Edwards' Law 5[b|c]" :)
    
    I'm sure I pinned it up on my wall somewhere, right next to
    http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png
    
    Jon.
    
    
    From newsuser at stacom-software.de  Wed Nov 25 08:05:45 2009
    From: newsuser at stacom-software.de (Alexander Eisenhuth)
    Date: Wed, 25 Nov 2009 14:05:45 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application
    	busy"
    In-Reply-To: <4b0d2950$0$967$ba4acef3@news.orange.fr>
    References:  <4b0d2950$0$967$ba4acef3@news.orange.fr>
    Message-ID: 
    
    I don't think so, because it happens very rarely
    
    Michel Claveau - MVP schrieb:
    > Hi! 
    > 
    > Your computer is too slow, for launch Excel.
    > Configure the machine for more speed...
    > 
    > @+
    
    
    From hv at tbz-pariv.de  Wed Nov 25 09:06:44 2009
    From: hv at tbz-pariv.de (Thomas Guettler)
    Date: Wed, 25 Nov 2009 15:06:44 +0100
    Subject: 'classmethod' object has only read-only attributes
    Message-ID: <7n4rvkF3kjhtpU1@mid.individual.net>
    
    Hi,
    
    why have classmethods only readonly attributes? It works for other methods.
    
    exmpale code:
    {{{
    class Foo(object):
        @classmethod
        def bar(cls):
            pass
        bar.myattr='test'
    }}}
    
    user at host:~> python ~/tmp/t.py
    Traceback (most recent call last):
      File "/home/user/tmp/t.py", line 1, in 
        class Foo(object):
      File "/home/user/tmp/t.py", line 5, in Foo
        bar.myattr='test'
    TypeError: 'classmethod' object has only read-only attributes (assign to .myattr)
    
    
    -- 
    Thomas Guettler, http://www.thomas-guettler.de/
    E-Mail: guettli (*) thomas-guettler + de
    
    
    From lallous at lgwm.org  Wed Nov 25 09:27:44 2009
    From: lallous at lgwm.org (lallous)
    Date: Wed, 25 Nov 2009 15:27:44 +0100
    Subject: How to import a file by its full path using C api?
    References: 
    Message-ID: 
    
    Looks like one way to do that is to use something like:
    
        s.sprintf(
          "import imp\n"
          "imp.load_source('%s', r'%s')", modname, script_path);
        PyRun_SimpleString(s.c_str());
    
    Unless someone has a better suggestion.
    
    Regards,
    Elias
    "lallous"  wrote in message news:heir4g$ohv$1 at aioe.org...
    > Hello
    > 
    > PyObject* PyImport_ImportModule( const char *name) 
    > 
    > How to specify a full file path instead and a module name?
    > 
    > Like PyImport_SomeFunction(const char *path_to_script, const char *name)
    > 
    > Thanks,
    > Elias 
    
    
    From __peter__ at web.de  Wed Nov 25 09:30:21 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Wed, 25 Nov 2009 15:30:21 +0100
    Subject: 'classmethod' object has only read-only attributes
    References: <7n4rvkF3kjhtpU1@mid.individual.net>
    Message-ID: 
    
    Thomas Guettler wrote:
    
    > Hi,
    > 
    > why have classmethods only readonly attributes? It works for other
    > methods.
    > 
    > exmpale code:
    > {{{
    > class Foo(object):
    >     @classmethod
    >     def bar(cls):
    >         pass
    >     bar.myattr='test'
    > }}}
    > 
    > user at host:~> python ~/tmp/t.py
    > Traceback (most recent call last):
    >   File "/home/user/tmp/t.py", line 1, in 
    >     class Foo(object):
    >   File "/home/user/tmp/t.py", line 5, in Foo
    >     bar.myattr='test'
    > TypeError: 'classmethod' object has only read-only attributes (assign to
    > .myattr)
    
    No idea. But here's a workaround:
    
    >>> class A(object):
    ...     def method(cls): print cls
    ...     method.foo = 42
    ...     method = classmethod(method)
    ...
    >>> A.method()
    
    >>> A.method.foo
    42
    
    Or, going fancy:
    
    >>> def attrs(**kw):
    ...     def set(obj):
    ...             for k, v in kw.iteritems():
    ...                     setattr(obj, k, v)
    ...             return obj
    ...     return set
    ...
    >>> class A(object):
    ...     @classmethod
    ...     @attrs(foo=42)
    ...     def method(cls): print cls
    ...
    >>> A.method()
    
    >>> A().method.foo
    42
    
    Peter
    
    
    
    From lie.1296 at gmail.com  Wed Nov 25 10:08:48 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Thu, 26 Nov 2009 02:08:48 +1100
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    	
    Message-ID: <4b0d48dd$1@dnews.tpgi.com.au>
    
    astral orange wrote:
    > 
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    
    In many other programming language, self (or this, or Me) refers the the 
    current class instance. In some languages, you can refer to an instance 
    attribute without an explicit self, this, or Me; the name resolver will 
    search in the local namespace (method-level), instance namespace 
    (instance-level), class namespace (class-level), perhaps module level 
    namespace (file-level), and finally global (application level).
    
    Python interpreter is simple and stupid. It doesn't have many smarts; 
    instead of having such a sophisticated name resolver, the compiler 
    passes an argument to the function, making `self` a local variable that 
    refers to the current instance.
    
    Python programmers accesses instance and class namespace by explicitly 
    referring to `self`; the name resolver only have two places to lookup 
    names: local namespace (method level) and global namespace (module-level 
    [!] not application level in python).
    
    This choice of design simplifies the name resolver, simplifies 
    method/function object design (since it does not need any code to handle 
    an otherwise implicit self), and completely eliminates ambiguity (to the 
    programmer) when having a local variable with the same name as an 
    instance variable. Among many other advantages.
    
    The side-effect of this design choice is self must be explicitly 
    referenced to access class/instance attributes; unlike in some other 
    language where self/this/Me may be omitted when it doesn't clash with 
    other variable in local namespace.
    
    
    From victorsubervi at gmail.com  Wed Nov 25 10:19:09 2009
    From: victorsubervi at gmail.com (Victor Subervi)
    Date: Wed, 25 Nov 2009 10:19:09 -0500
    Subject: Workaround To Add Value To TextArea
    Message-ID: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    
    Hi;
    I've noticed that html doesn't support a "value" attribute for textarea. I
    have a form in which I enable users to edit data they've entered into my
    database, and one of the data is a textarea. How do I fill the textarea with
    the value, or what kind of workaround can I create?
    TIA,
    Victor
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From rami.chowdhury at gmail.com  Wed Nov 25 10:27:09 2009
    From: rami.chowdhury at gmail.com (Rami Chowdhury)
    Date: Wed, 25 Nov 2009 07:27:09 -0800
    Subject: Workaround To Add Value To TextArea
    In-Reply-To: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    Message-ID: <2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    
    --------
    Rami Chowdhury
    "Never assume malice when stupidity will suffice." -- Hanlon's Razor
    408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
    
    
    
    On Wed, Nov 25, 2009 at 07:19, Victor Subervi  wrote:
    > Hi;
    > I've noticed that html doesn't support a "value" attribute for textarea. I
    > have a form in which I enable users to edit data they've entered into my
    > database, and one of the data is a textarea. How do I fill the textarea with
    > the value, or what kind of workaround can I create?
    
    Hi Victor,
    
    You'll find the textarea and input tags differ significantly, even
    though they're both typically used in HTML forms. The W3C page has a
    fair overview of how various parts of HTML forms work in HTML 4.01,
    and it's roughly accurate for XHTML up to 1.1 as well:
    http://www.w3.org/TR/html401/interact/forms.html
    
    HTH,
    Rami
    
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    
    
    From victorsubervi at gmail.com  Wed Nov 25 10:41:09 2009
    From: victorsubervi at gmail.com (Victor Subervi)
    Date: Wed, 25 Nov 2009 10:41:09 -0500
    Subject: Workaround To Add Value To TextArea
    In-Reply-To: <2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    	<2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    Message-ID: <4dc0cfea0911250741y15ff4f5eldcad6cc817cf8c6d@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 10:27 AM, Rami Chowdhury
    wrote:
    
    > You'll find the textarea and input tags differ significantly, even
    > though they're both typically used in HTML forms. The W3C page has a
    > fair overview of how various parts of HTML forms work in HTML 4.01,
    > and it's roughly accurate for XHTML up to 1.1 as well:
    > http://www.w3.org/TR/html401/interact/forms.html
    >
    
    Oops. Silly mistake. Thought I had to put the value inside the tag like the
    other tags. Thanks,
    V
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From jitish.p at gmail.com  Wed Nov 25 10:46:19 2009
    From: jitish.p at gmail.com (Jitish)
    Date: Wed, 25 Nov 2009 07:46:19 -0800 (PST)
    Subject: Workaround To Add Value To TextArea
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com> 
    	
    Message-ID: 
    
    On Nov 25, 8:27?pm, Rami Chowdhury  wrote:
    > --------
    > Rami Chowdhury
    > "Never assume malice when stupidity will suffice." -- Hanlon's Razor
    > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
    >
    > On Wed, Nov 25, 2009 at 07:19, Victor Subervi  wrote:
    > > Hi;
    > > I've noticed that html doesn't support a "value" attribute for textarea. I
    > > have a form in which I enable users to edit data they've entered into my
    > > database, and one of the data is a textarea. How do I fill the textarea with
    > > the value, or what kind of workaround can I create?
    >
    > Hi Victor,
    >
    > You'll find the textarea and input tags differ significantly, even
    > though they're both typically used in HTML forms. The W3C page has a
    > fair overview of how various parts of HTML forms work in HTML 4.01,
    > and it's roughly accurate for XHTML up to 1.1 as well:http://www.w3.org/TR/html401/interact/forms.html
    >
    > HTH,
    > Rami
    >
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list
    >
    >
    
    HI,
      Ok the simplest solution for this is 
    
    Regards
    Jitish
    
    
    From ethan at stoneleaf.us  Wed Nov 25 10:47:39 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Wed, 25 Nov 2009 07:47:39 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4b0cfefa$0$24750$426a34cc@news.free.fr>
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>	
    	<4b0cfefa$0$24750$426a34cc@news.free.fr>
    Message-ID: <4B0D519B.2030102@stoneleaf.us>
    
    Bruno Desthuilliers wrote:
    > Ethan Furman a ?crit :
    > 
    >>
    >> Let's head towards murkier waters (at least murkier to me -- hopefully 
    >> they can be easily clarified):  some of the attributes are read-only, 
    >> such as record count; others are not directly exposed, but still 
    >> settable, such as table version; and still others require a small 
    >> amount of processing... at which point do I switch from simple 
    >> attribute access to method access?
    > 
    > 
    > Short answer : you don't !-)
    > 
    > Long answer : well, in fact you do, but the client code doesn't have to 
    > be aware that it's in fact calling an accessor.
    > 
    > Before we go into more details, you have to know that Python has a 
    > pretty good support for computed attributes, with both a simple generic 
    > solution (the property type) and the full monty (custom types 
    > implementing the descriptor protocol). So from the "interface" POV, you 
    > should never have an explicit accessor method for what is semantically 
    > an attribute (wheter the attribute is a plain or a computed one being 
    > part of the implementation).
    > 
    > Let's start with your second point: "not directly exposed but still 
    > settable". I assume you mean "not part of the interface, only supposed 
    > to be accessed (rw) from the methods" - if not, please pardon my 
    > stupidity and provide better explanations !-).
    
    Better explanation: attribute is publicly available, but buried a couple 
    layers deep in a private structure (yes, private structure name starts 
    with a leading underscore).
    
    > If yes: Python doesn't 
    > have "language inforced" access restrictions (private / protected / 
    > etc), but a *very strong* naming convention which is that names starting 
    > with a leading underscore are implementation details, not part of the 
    > official interface, and shouldn't be accessed directly. Kind of a 
    > "warranty voided if unsealed".
    > 
    > So if you have attributes you don't want to "expose" to the outside 
    > world, just add a single leading underscore to their names.
    > 
    > First and third points are solved by using computed attributes - usually 
    > a property. The property type takes a few accessor functions as 
    > arguments - typically, a getter and a setter, and eventually a 
    > "deleter". Used as a class attribute, a property instance will hook up 
    > into the attribute lookup / setup mechanism (__getattribute__ and 
    > __setattr__), and will call resp. it's getter or setter function, 
    > passing it the instance and (for the setter) value.
    > 
    > This directly solves the third point. For the first one, the obvious 
    > solution is to use a property with a setter that raises an exception - 
    > canonically, an AttributeError with a message explaining that the 
    > attribute is read-only.
    > 
    > And for something more hands-on:
    > 
    > class Person(object):
    >    def __init__(self, firstname, lastname, birthdate):
    >        self.firstname = firstname
    >        self.lastname = lastnale
    >        self.birthdate = birthdate
    >        self._foo = 42 # implementation only
    > 
    >    def _getfullname(self):
    >        return "%s %s" % (self.firstname, self.lastname)
    >    def _setfullname(self, value):
    >        raise AttributeError("%s.fullname is read-only" % type(self)
    >    fullname = property(fget=_getfullname, fset=_setfullname)
    > 
    >    def _getage(self):
    >        return some_computation_with(self.birthdate)
    >    def _setage(self, value):
    >        raise AttributeError("%s.age is read-only" % type(self)
    >    age = property(fget=_getage, fset=_setage)
    > 
    > 
    > For more on computed attributes, you may want to read about the 
    > "descriptor protocol" (google is your friend as usual). This and the 
    > attribute resolution mechanism are fundamental parts of Python's inner 
    > working. Learn how it works if you really want to leverage Python's power.
    > 
    > HTH
    
    Very helpful, thank you.  Hopefully my brain will be up to the 
    descriptor protocol this time... the last couple times were, um, less 
    than successful.  :)
    
    ~Ethan~
    
    
    From niklasro at gmail.com  Wed Nov 25 11:05:24 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:05:24 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    Message-ID: 
    
    On Nov 23, 11:37?pm, "Rhodri James" 
    wrote:
    > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    > > Dear experts,
    > > Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > > Mercurial support not found i.e. buttons to clone, commit and push to
    > > repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > I don't really understand this urge to cram everything into a single ?
    > program, since that inevitably leads to compromises that will compromise ?
    > just how much of Mercurial's useful and interesting functionality you can ?
    > get at. ?Still, if you really must, Emacs (and presumably vim) seems to be ?
    > capable of working with most source control systems.
    >
    > --
    > Rhodri James *-* Wildebeest Herder to the Masses
    
    Obvious explainations are commandline is slower and IDEs claim support
    (Eric) which may mean it's up2 programmer to add and enable the ui. Or
    any binding to enable 1 ui. Emacs sure can.
    Thank you
    
    
    From niklasro at gmail.com  Wed Nov 25 11:06:32 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:06:32 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	
    Message-ID: <31ca1f32-70da-4f1f-8040-4ee7d544e55b@j19g2000yqk.googlegroups.com>
    
    On Nov 24, 2:35?pm, Gerhard H?ring  wrote:
    > Rhodri James wrote:
    > > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >> Dear experts,
    > >> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >> Mercurial support not found i.e. buttons to clone, commit and push to
    > >> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > > I don't really understand this urge to cram everything into a single
    > > program, since that inevitably leads to compromises that will compromise
    > > just how much of Mercurial's useful and interesting functionality you
    > > can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > > to be capable of working with most source control systems.
    >
    > I prefer the commandline tools, too.
    >
    > FWIW, Eclipse supports Mercurial throughhttp://www.vectrace.com/mercurialeclipse/
    >
    > -- Gerhard
    
    Good just Eclipse is too much and tested 4,5... python IDE where non
    can hg. Just 2 or 3 buttons to drPython with script enables it.
    
    
    From niklasro at gmail.com  Wed Nov 25 11:07:41 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:07:41 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    Message-ID: <20a1b95a-a04c-4632-b068-01006a484770@g26g2000yqe.googlegroups.com>
    
    On Nov 24, 3:13?pm, Richard Riley  wrote:
    > Gerhard H?ring  writes:
    > > Rhodri James wrote:
    > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >>> Dear experts,
    > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > >> I don't really understand this urge to cram everything into a single
    > >> program, since that inevitably leads to compromises that will
    > >> compromise
    >
    > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > merely programmed to hook into the external tools
    >
    > >> just how much of Mercurial's useful and interesting functionality you
    > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > >> to be capable of working with most source control systems.
    >
    > > I prefer the commandline tools, too.
    >
    > > FWIW, Eclipse supports Mercurial through
    > >http://www.vectrace.com/mercurialeclipse/
    >
    > > -- Gerhard
    >
    > Why would you prefer the command line tools in a shell when the same
    > tools can be used in a way which makes navigating the output so much
    > easier? It strikes me as a kind of intransigence. it's a common
    > misconception that IDEs use their own tools all the time. They
    > don't. They integrate the very same tools. e.g Why the hell would I drop
    > to a command line to diff a file with a back version in GIT when I can
    > do the same in the buffer in emacs with a single hot key? Why would I
    > pipe the output of compile into a file then open that file when a single
    > hot key can fire off the SAME compiler and then list the errors in an
    > emacs buffer and another hot key can take me directly to the source
    > lines in question? Living in the past has its mements, but really.
    >
    > e.g I have pylint working live in python buffers. Big time
    > saver. Similar with C.
    
    true. While not many programmers lint the code.
    
    
    From perfreem at gmail.com  Wed Nov 25 11:42:01 2009
    From: perfreem at gmail.com (per)
    Date: Wed, 25 Nov 2009 08:42:01 -0800 (PST)
    Subject: creating pipelines in python
    References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com>
    	<87y6lxd37a.fsf@rudin.co.uk>
    Message-ID: <32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    
    Thanks to all for your replies.  i want to clarify what i mean by a
    pipeline.  a major feature i am looking for is the ability to chain
    functions or scripts together, where the output of one script -- which
    is usually a file -- is required for another script to run.  so one
    script has to wait for the other.  i would like to do this over a
    cluster, where some of the scripts are distributed as separate jobs on
    a cluster but the results are then collected together.  so the ideal
    library would have easily facilities for expressing this things:
    script X and Y run independently, but script Z depends on the output
    of X and Y (which is such and such file or file flag).
    
    is there a way to do this? i prefer not to use a framework that
    requires control of the clusters etc. like Disco, but something that's
    light weight and simple. right now ruffus seems most relevant but i am
    not sure -- are there other candidates?
    
    thank you.
    
    On Nov 23, 4:02?am, Paul Rudin  wrote:
    > per  writes:
    > > hi all,
    >
    > > i am looking for a python package to make it easier to create a
    > > "pipeline" of scripts (all in python). what i do right now is have a
    > > set of scripts that produce certain files as output, and i simply have
    > > a "master" script that checks at each stage whether the output of the
    > > previous script exists, using functions from the os module. this has
    > > several flaws and i am sure someone has thought of nice abstractions
    > > for making these kind of wrappers easier to write.
    >
    > > does anyone have any recommendations for python packages that can do
    > > this?
    >
    > Not entirely what you're looking for, but the subprocess module is
    > easier to work with for this sort of thing than os. See e.g. 
    
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 11:46:49 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 17:46:49 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>		<4b0cfefa$0$24750$426a34cc@news.free.fr>
    	
    Message-ID: <4b0d5f78$0$23304$426a74cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > 
    > Very helpful, thank you.  Hopefully my brain will be up to the 
    > descriptor protocol this time... the last couple times were, um, less 
    > than successful.  :)
    
    Well, it's quite simple in fact. Most of the "magic" happens in 
    object.__getattribute__ and object.__setattr__. You'll find a rough 
    description of what happens here:
    
    http://groups.google.com/group/comp.lang.python/browse_frm/thread/a136f7626b2a8b7d/70a672cf7448c68e
    
    
    
    
    
    
    From mal at egenix.com  Wed Nov 25 11:53:16 2009
    From: mal at egenix.com (M.-A. Lemburg)
    Date: Wed, 25 Nov 2009 17:53:16 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    Message-ID: <4B0D60FC.9030906@egenix.com>
    
    Sibylle Koczian wrote:
    > Hello,
    > 
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    > 
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    > 
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    
    It's best to convert all data to plain strings before passing it
    to the csv module.
    
    There are many situations where you may want to use a different
    string format than the standard str(obj) format, so this is best
    done with a set of format methods - one for each type and format
    you need, e.g. one for integers, floats, monetary values, Unicode
    text, plain text, etc.
    
    The required formatting also depends on the consumers of the
    generated csv or tsv file and their locale.
    
    -- 
    Marc-Andre Lemburg
    eGenix.com
    
    Professional Python Services directly from the Source  (#1, Nov 25 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 emile at fenx.com  Wed Nov 25 12:35:53 2009
    From: emile at fenx.com (Emile van Sebille)
    Date: Wed, 25 Nov 2009 09:35:53 -0800
    Subject: Help with pprint
    In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    References: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    Message-ID: 
    
    On 11/25/2009 4:47 AM Nadav Chernin said...
    > Hello, I want to print list of lists in matrix format. So I use pprint 
    > with parameter ?width? for this target.
    
    > The problem that I don?t know how to select width value, because if:
    > 
    >  
    > 
    >  >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
    > 'one']]  
    > 
    >  >>> pprint(data,width=20)
    
    Almost...
    
     >>> pprint.pprint(data,width=24)
    [['one', 'one', 'one'],
      ['one', 'one', 'one'],
      ['one', 'one', 'one']]
    
    Emile
    
    
    
    From doug.stevens73 at gmail.com  Wed Nov 25 12:38:54 2009
    From: doug.stevens73 at gmail.com (doug)
    Date: Wed, 25 Nov 2009 09:38:54 -0800 (PST)
    Subject: How to run python script in emacs
    References: 
    	
    Message-ID: <5273278a-abb3-4573-82df-ecdfc0de6837@e27g2000yqd.googlegroups.com>
    
    
    When I type C-c C-c my emacs window just hangs.  If I use Task Manager
    to kill cmdproxy I can get emacs back but of course interactivity with
    Python is not accomplished.  By the way, if I do C-c ! then I get a
    functional python shell.  Does anybody know a solution to this?
    
    On Oct 13, 7:12?am, rustom  wrote:
    > On Sep 26, 8:54?pm, devilkin  wrote:
    >
    > > I'm just starting learning python, and coding in emacs. I usually
    > > split emacs window into two, coding in one, and run script in the
    > > other, which is not very convenient. anyone can help me with it? is
    > > there any tricks like emacs short cut?
    >
    > > also please recommand some emacs plug-ins for python programming, i'm
    > > also beginner in emacs.currently i'm only using python.el.
    >
    > python.el comes with emacs
    > python-mode.el comes from python ?https://launchpad.net/python-mode/
    > Because of some emacs politics the first ships with emacs although
    > most uses prefer the second.
    > Note 1. The key bindings are different
    > Note 2. Does not work with python3. See my posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
    >
    > > Are any plugins supply code folding and autocomplete?
    >
    > See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
    > but its an installation headache (requires pymacs bleeding edge
    > version etc)
    > I suggest you just get used to python-mode first (C-c ! and C-c C-c)
    > and then explore these questions a bit later.
    >
    >
    >
    > > BTW, I'm not a english native speaker, any grammer mistakes, please
    > > correct them. :)
    >
    > grammer is spelt grammar :-)
    
    
    
    From jeff at jmcneil.net  Wed Nov 25 12:54:46 2009
    From: jeff at jmcneil.net (Jeff McNeil)
    Date: Wed, 25 Nov 2009 09:54:46 -0800 (PST)
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    	 
    	
    Message-ID: <7c952554-96f2-4de2-b4b8-935d8fe45ebd@n35g2000yqm.googlegroups.com>
    
    On Nov 25, 4:45?am, Jon Clements  wrote:
    > On Nov 25, 8:13?am, Steven D'Aprano
    >
    >
    >
    >
    >
    >  wrote:
    > > On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    > > > My dedicated hosting provider wants to switch me to a new server with
    > > > CentOS 5.3, so I have to look at how much work is required.
    >
    > > > ? ? CentOS 5.3 apparently still ships with Python 2.4. ?Worse, it
    > > > requires Python 2.4 for its own internal purposes, and actually
    > > > installing Python 2.5 breaks the package manager. ?There's no supported
    > > > RPM for upgrading.
    >
    > > > ? ? It's apparently necessary to build Python 2.5 from source,
    > > > build all the packages, and debug.
    >
    > > You shouldn't need *quite* that much effort, particularly if you don't
    > > care about tkinter. Just use the alternate installation so it doesn't
    > > stomp all over the 2.4 installation:
    >
    > > .configure
    > > make
    > > make altinstall
    >
    > > You will need root or sudo for that last one.
    >
    > > I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
    > > easily for me:
    >
    > > $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    > > ...
    > > 18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    > > $
    > > $ tar xzf Python-2.5.4.tgz
    > > $ cd Python-2.5.4
    > > $ ./configure
    > > ...
    > > $ make
    > > ...
    > > $ sudo make altinstall
    > > Password:
    > > ...
    > > $ python -V
    > > Python 2.4.3
    > > $ python2.5 -V
    > > Python 2.5.4
    >
    > > And it all seems to just work for me.
    >
    > > > Nor does that "just work". There's
    > > > documentation, but some of it is in Japanese.
    >
    > > >http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    >
    > > I don't understand why you're using documentation for third-party RPMs as
    > > evidence that building from source will be troublesome.
    >
    > > --
    > > Steven
    >
    > And might I add on a box where there is no root access, but sufficient
    > tools (compilers etc...)
    >
    > 1) Compile from source
    > 2) Set PYTHONPATH correctly for your shell
    > 3) Set your normal path to include your Python rather than the
    > system's default Python
    > 4) When installing modules (via setup.py install or easy_install)
    > include a "home_dir=" (I think that's right OTTOMH) to somewhere in
    > your home directory, and make sure step 2) complies with this.
    > 5) Double check with "which python" to make sure it's the correct
    > version.
    >
    > hth
    > Jon.
    
    I'm in a RHEL3 - RHEL5.4 environment and the situation is exactly the
    same.  The code I've written requires 2.5 or higher.  I keep a /usr/
    local/pythons directory and manually install the versions I need
    there.  I then use virtualenv so I don't have to worry about setting
    PYTHONPATH manually or anything. I just need to remember to use the
    right Python executable. I got to doing this when I discovered that
    there are issues with the Cluster Manager (Lucci) and some external
    Python packages (some of the Zope stuff, if I remember correctly).
    
    So, in addition to the above steps, you'll probably also want to
    include a '--prefix=.....' on the command line to the configure script
    in order to install in a non-standard location.
    
    
    
    From dboddie at trolltech.com  Wed Nov 25 13:57:17 2009
    From: dboddie at trolltech.com (David Boddie)
    Date: Wed, 25 Nov 2009 19:57:17 +0100
    Subject: QtPython: removeChild/addChild QGroupBox
    Message-ID: <200911251957.18330.dboddie@trolltech.com>
    
    On Mon Nov 23 10:35:26 CET 2009, Threader Slash wrote:
    
    > I am developing a system for a customer which is displayed in a set of
    > GroupBox.
    > Depending on mouse events, the container (groupBox) must be removed from
    > the centralwidget, or then added with new updated data for the table.
    > Here is a piece of the code that runs nicely and shows the a groupBox.
    >
    > Now it starts to show some effects on removeWidget, but it is still didn't
    > clear the box completely.. just the right border of the box is erased.
    
    [...]
    
    Dynamically changing layouts isn't the most intuitive thing to do in Qt.
    It might be easier to get something close to the effect you are looking for
    if you just hide the group box instead.
    
    David
    
    
    From manu3d at gmail.com  Wed Nov 25 14:02:39 2009
    From: manu3d at gmail.com (Emanuele D'Arrigo)
    Date: Wed, 25 Nov 2009 11:02:39 -0800 (PST)
    Subject: Python Statements/Keyword Localization
    Message-ID: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    
    Greetings everybody,
    
    some time ago I saw a paper that used an XSL transformation sheet to
    transform (if I remember correctly) a Chinese xml file (inclusive of
    Chinese-script XML tags) into an XHTML file.
    
    More recently you might have all heard how the ICANN has opened up the
    way for non-latin characters in domain names, so that we'll soon start
    seeing URLs using Russian, Asian and Arabic characters.
    
    In this context I was wondering if there has ever been much thought
    about a mechanism to allow the localization not only of the strings
    handled by python but also of its built-in keywords, such as "if",
    "for", "while", "class" and so on. For example, the following English-
    based piece of code:
    
    class MyClass(object):
        def myMethod(self, aVariable):
             if aVariable == True:
                print "It's True!"
             else:
                print "It's False!"
    
    would become (in Italian):
    
    classe LaMiaClasse(oggetto):
        def ilMioMetodo(io, unaVariabile)
             se unaVariabile == Vero:
                 stampa "E' Vero!"
             altrimenti:
                 stampa "E' Falso!"
    
    I can imagine how a translation script going through the source code
    could do a 1:1 keyword translation to English fairly quickly but this
    would mean that the runtime code still is in English and any error
    message would be in English. I can also imagine that it should be
    possible to "simply" recompile python to use different keywords, but
    then all libraries using the English keywords would become
    incompatible, wouldn't they?
    
    In this context it seems to be the case that the executable would have
    to be able to optionally accept -a list- of dictionaries to internally
    translate to English the keywords found in the input code and at most -
    one- dictionary to internally translate from English output messages
    such as a stack trace.
    
    What do you guys think?
    
    Manu
    
    
    From saketbharamberocks at gmail.com  Wed Nov 25 14:40:30 2009
    From: saketbharamberocks at gmail.com (Saket Bharambe)
    Date: Wed, 25 Nov 2009 11:40:30 -0800 (PST)
    Subject: A language for S40 mobiles
    Message-ID: <2bbdb975-e85c-477c-b906-6c9b31279cb9@s21g2000prm.googlegroups.com>
    
    Hey,
    I have recently created an application for S60 mobiles. But I want to
    create a similar application for S40 mobiles too. I did the
    application of S60 in pyS60 as java had problems with accessing inbox
    and contacts. I tried searching for pyS40 , but i couldnt find it.
    
    Ques : Is there python for S40 mobiles ? If yes , where can i find the
    installation files and documentation . If no , which the best language
    for writing application for S40 mobiles. (keeping in mind that I need
    to access the Inbox(sms) and contacts ) ?
    
    
    From tjreedy at udel.edu  Wed Nov 25 15:03:50 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 15:03:50 -0500
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: <4B0D1BDD.70400@sequans.com>
    References: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    	<4B0D1BDD.70400@sequans.com>
    Message-ID: 
    
    Jean-Michel Pichavant wrote:
    
    > 
    > Basically, never configure or add handlers to any logger except for the 
    > root logger in your __main__ section. There are very few reasons why you 
    > would break this rule. And when you'll be familiar with the logging 
    > module you'll when to break it.
    
    I have never used logging, but if and when I have a need for it, the 
    advice above and your clear example will be a good guide to getting 
    started. Thank you from me too.
    
    tjr
    
    > [server.py]
    > 
    > import logging
    > import logging.handlers
    > 
    > logger = logging.getLogger(__name__) # you'd better to create the logger 
    > at the module level, you may want to log within   the module function
    > 
    > def aFunction(a, b, ,c):
    >    logger.debug('You called aFunction')
    > 
    > class Server():
    >    def __init__(self):
    >        self.logger = logger
    > 
    >    def util(self):
    >        self.logger.warning('This message comes from Server module ')
    > 
    > 
    > [client.py]
    > 
    > import logging
    > import logging.handlers
    > from server import Server
    > 
    > logger = logging.getLogger(__name__)
    > 
    > class Client():
    >    def __init__(self):
    >        self.logger = logger
    > 
    >    def client_test(self):
    >        self.logger.warning("This message comes from Client module")
    > 
    > if __name__ == "__main__":
    >    rootLogger = logging.getLogger()
    >    rootLogger.addHandler(logging.FileHandler("client.log"))
    >    rootLogger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s 
    > %(name)-12s %(levelname)-8s %(message)s"))
    >    rootLogger.setLevel(logging.DEBUG)
    >    ser = Server()
    >    cli = Client()
    >    ser.util()
    >    cli.client_test()
    > 
    > Happy logging,
    > 
    > Jean-Michel
    
    
    
    From stef.mientki at gmail.com  Wed Nov 25 15:03:54 2009
    From: stef.mientki at gmail.com (Stef Mientki)
    Date: Wed, 25 Nov 2009 21:03:54 +0100
    Subject: python gui builders
    In-Reply-To: <987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    References: <8u9Mm.35397$Wd1.32454@newsfe15.iad>	<007f3944$0$23487$c3e8da3@news.astraweb.com>
    	<05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com>
    	<863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com>
    	
    	<987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    Message-ID: <4B0D8DAA.4020200@gmail.com>
    
    Shawn Wheatley wrote:
    > It's not quite all encompassing, but I found this link last year when
    > looking for a similar comparison of Python GUIs:
    > http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/
    >
    > Tkinter, Qt, GTK, IronPython... I think the only thing missing is
    > Jython w/ Swing or SWT. Check it out.
    >   
    Instead of "*hello* world" examples, I was thinking of  "*real* world" 
    applications,
    something like this,
      http://mientki.ruhosting.nl/data_www/pylab_works/random_gui.html
    which in a good GUI package should be doable in about 100 lines of code.
    
    cheers,
    Stef
    > Shawn
    >
    > On Nov 18, 5:11 pm, Stef Mientki  wrote:
    >   
    >> Wouldn't it be nice
    >> if each fan of some form of GUI-package,
    >> would post it's code (and resulting images) for generating one or two
    >> standard GUI-forms ?
    >>     
    
    
    
    From tjreedy at udel.edu  Wed Nov 25 15:22:08 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 15:22:08 -0500
    Subject: Help with pprint
    In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    References: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    Message-ID: 
    
    Nadav Chernin wrote:
    > Hello, I want to print list of lists in matrix format. So I use pprint 
    > with parameter ?width? for this target.
    > 
    > For example :
    >  >>> data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    >  >>> pprint(data,width=20)
    > [[1, 1, 1], 
    >  [1, 1, 1],
    >  [1, 1, 1]]
    
    > 
    > The problem that I don?t know how to select width value, because if:
    >   >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
    > 'one']]  
    >  >>> pprint(data,width=20)
    > [['one',
    >   'one',
      [snip]
    
    1. Cpp.pprint(data, width=100)alculate a width that is big enough but 
    not too big. In your example, the interval is [24,69]
    2. Write a loop, which gives you finer control.
    
     >>> for line in data: print(line)
    ['one', 'one', 'one']
    ['one', 'one', 'one']
    ['one', 'one', 'one']
    
    To me, this is more like a matrix and possibly better, depending on your 
    particular application. If the items have different default printed 
    widths and you want column lined up, you will need to custom format each 
      field in a column to a uniform width anyway. Print and pprint are for 
    quick, take-what-you-get output, not for customj-designed production output.
    
    Terry Jan Reedy
    
    
    
    From ericwoodworth at gmail.com  Wed Nov 25 15:22:55 2009
    From: ericwoodworth at gmail.com (EW)
    Date: Wed, 25 Nov 2009 12:22:55 -0800 (PST)
    Subject: reading windows event logs
    Message-ID: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    
    Hi All,
         I'm looking for some guidance on a better way to read eventlogs
    from windows servers.  I've written a handy little app that relies on
    WMI to pull the logs an in all my testing it worked great.  When I
    deployed it, however, WMI choked on servers with a lot of logs.  I've
    tried pulling the logs using much smaller VB scripts as well and they
    still failed, so I'm pretty sure I'm facing a WMI problem and not a
    python or system resources problem.  So I couldn't effectively get
    logs off of domain controllers for example or file servers that had
    auditing turned on.  Sadly those are exactly the types of servers
    whose logs are most interesting.
    
         So I'm looking for suggestions on a way to grab that data without
    using WMI for remote machines.  I know MS has C libraries for this but
    I haven't touched C for 10 years so I'm hoping there's a python
    equivalent out there somewhere.  Any advice would be appreciated.
    
    Thanks in advance for any help,
    Eric
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 15:26:34 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 20:26:34 +0000
    Subject: Python Statements/Keyword Localization
    In-Reply-To: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: <4B0D92FA.8010009@mrabarnett.plus.com>
    
    Emanuele D'Arrigo wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    > 
    > In this context I was wondering if there has ever been much thought
    > about a mechanism to allow the localization not only of the strings
    > handled by python but also of its built-in keywords, such as "if",
    > "for", "while", "class" and so on. For example, the following English-
    > based piece of code:
    > 
    > class MyClass(object):
    >     def myMethod(self, aVariable):
    >          if aVariable == True:
    >             print "It's True!"
    >          else:
    >             print "It's False!"
    > 
    > would become (in Italian):
    > 
    > classe LaMiaClasse(oggetto):
    >     def ilMioMetodo(io, unaVariabile)
    >          se unaVariabile == Vero:
    >              stampa "E' Vero!"
    >          altrimenti:
    >              stampa "E' Falso!"
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly but this
    > would mean that the runtime code still is in English and any error
    > message would be in English. I can also imagine that it should be
    > possible to "simply" recompile python to use different keywords, but
    > then all libraries using the English keywords would become
    > incompatible, wouldn't they?
    > 
    > In this context it seems to be the case that the executable would have
    > to be able to optionally accept -a list- of dictionaries to internally
    > translate to English the keywords found in the input code and at most -
    > one- dictionary to internally translate from English output messages
    > such as a stack trace.
    > 
    > What do you guys think?
    > 
    It might be necessary to work in tokens, where a token is a word or a
    string (or maybe also a comment). Your example would be encoded to:
    
         ?1? ?2?(?3?):
             ?4? ?5?(?6?, ?7?):
                 ?8? ?7? == ?9?:
                     ?10? ?11?
                 ?12?:
                     ?10? ?13?
    
    with either English:
    
         ?1? class
         ?2? MyClass
         ?3? object
         ?4? def
         ?5? myMethod
         ?6? self
         ?7? aVariable
         ?8? if
         ?9? True
         ?10? print
         ?11? "It's True!"
         ?12? else
         ?13? "It's False!"
    
    or Italian:
    
         ?1? classe
         ?2? LaMiaClasse
         ?3? oggetto
         ?4? def
         ?5? ilMioMetodo
         ?6? io
         ?7? unaVariabile
         ?8? se
         ?9? Vero
         ?10? stampa
         ?11? "? Vero!"
         ?12? altrimenti
         ?13? "? Falso!"
    
    Any messages produced by, or format strings used by, the runtime would
    also be tokens.
    
    Python currently does lexical analysis on the source code to identify
    names, strings, etc; a new tokenised file format would partially bypass
    that because the names and strings (and comments?) have already been
    identified.
    
    
    From garabik-news-2005-05 at kassiopeia.juls.savba.sk  Wed Nov 25 15:27:53 2009
    From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk)
    Date: Wed, 25 Nov 2009 20:27:53 +0000 (UTC)
    Subject: Python Statements/Keyword Localization
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: 
    
    Emanuele D'Arrigo  wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    
    Non-latin characters in domain names are already possible (and usable and
    actually used) for some years by now. Google for "punycode".
    
    ICANN was talking about TLD.
    
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly
    
    ...and get conflickts because I named my variable (in English python),
    say, stampa.
    
    Anyway, see http://www.chinesepython.org
    
    -- 
     -----------------------------------------------------------
    | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ |
    | __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
     -----------------------------------------------------------
    Antivirus alert: file .signature infected by signature virus.
    Hi! I'm a signature virus! Copy me into your signature file to help me spread!
    
    
    From nulla.epistola at web.de  Wed Nov 25 15:31:14 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Wed, 25 Nov 2009 21:31:14 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 		
    	
    Message-ID: 
    
    Terry Reedy schrieb:
    
    > In Python 3, a file opened in 'b' mode is for reading and writing bytes 
    > with no encoding/decoding. I believe cvs works with files in text mode 
    > as it returns and expects strings/text for reading and writing. Perhaps 
    > the cvs doc should say must not be opened in 'b' mode. Not sure.
    > 
    
    I think that might really be better, because for version 2.6 they 
    explicitly stated 'b' mode was necessary. The results I couldn't 
    understand, even after reading the documentation for open():
    
     >>> import csv
     >>> acsv = open(r"d:\home\sibylle\temp\tmp.csv", "wb")
     >>> row = [b"abc", b"def", b"ghi"]
     >>> wtr = csv.writer(acsv)
     >>> wtr.writerow(row)
    Traceback (most recent call last):
       File "", line 1, in 
         wtr.writerow(row)
    TypeError: must be bytes or buffer, not str
    
    Same error message with row = [5].
    
    But I think I understand it now: the cvs.writer takes mixed lists of 
    text and numbers - that's exactly why I like to use it - so it has to 
    convert them before writing. And it converts into text - even bytes for 
    a file opened in 'b' mode. Right?
    
    Thank you, everybody, for explaining.
    
    Sibylle
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 15:55:20 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 20:55:20 +0000
    Subject: reading windows event logs
    In-Reply-To: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    References: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    Message-ID: <4B0D99B8.1010605@mrabarnett.plus.com>
    
    EW wrote:
    > Hi All,
    >      I'm looking for some guidance on a better way to read eventlogs
    > from windows servers.  I've written a handy little app that relies on
    > WMI to pull the logs an in all my testing it worked great.  When I
    > deployed it, however, WMI choked on servers with a lot of logs.  I've
    > tried pulling the logs using much smaller VB scripts as well and they
    > still failed, so I'm pretty sure I'm facing a WMI problem and not a
    > python or system resources problem.  So I couldn't effectively get
    > logs off of domain controllers for example or file servers that had
    > auditing turned on.  Sadly those are exactly the types of servers
    > whose logs are most interesting.
    > 
    >      So I'm looking for suggestions on a way to grab that data without
    > using WMI for remote machines.  I know MS has C libraries for this but
    > I haven't touched C for 10 years so I'm hoping there's a python
    > equivalent out there somewhere.  Any advice would be appreciated.
    > 
    The events logs are in %SystemRoot%\system32\config and have the
    extension .evt. There's info here on the file format:
    
    http://www.whitehats.ca/main/members/Malik/malik_eventlogs/malik_eventlogs.html
    
    
    
    From tjreedy at udel.edu  Wed Nov 25 16:26:00 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 16:26:00 -0500
    Subject: Python Statements/Keyword Localization
    In-Reply-To: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: 
    
    Emanuele D'Arrigo wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    > 
    > In this context I was wondering if there has ever been much thought
    > about a mechanism to allow the localization not only of the strings
    > handled by python but also of its built-in keywords, such as "if",
    > "for", "while", "class" and so on.
    
    There have been various debates and discussions on the topic. There has 
    been slow movement away from ascii-only in user code. (But not in the 
    stdlib, nor will there be there.)
    1. Unicode data type.
    2. Unicode allowed in comment and string literals.
    This required input decoding and coding cookie. This lead, I believe 
    somewhat accidentally, to
    3. Extended ascii (high bit set, for other European chars in various 
    encodings) for identifiers.
    4 (In 3.0) unicode allowed for identifiers
    
      Here is a version of the anti-customized-keyword position. Python is 
    designed to be read by people. Currently, any programmer in the world 
    can potentially read any Python program. The developers, especially 
    Guido, like this. Fixed keywords are not an undue burden because any 
    educated person should learn to read Latin characters a-z,0-9. and 
    Python has an intentionally  short list that the developers are loath to 
    lengthen.
    
    Change 4 above inhibits universal readability. But once 3 happened and 
    str became unicode, in 3.0, it was hard to say no to this.
    
    A 'pro' argument: Python was designed for learning and is good for that 
    and *is* used in schools down to the elementary level. But kids cannot 
    be expected to know foreign alphabets and words whill still learning 
    their own.
    
     > For example, the following English-
    > based piece of code:
    > 
    > class MyClass(object):
    >     def myMethod(self, aVariable):
    >          if aVariable == True:
    >             print "It's True!"
    >          else:
    >             print "It's False!"
    > 
    > would become (in Italian):
    > 
    > classe LaMiaClasse(oggetto):
    >     def ilMioMetodo(io, unaVariabile)
    >          se unaVariabile == Vero:
    >              stampa "E' Vero!"
    >          altrimenti:
    >              stampa "E' Falso!"
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly but this
    > would mean that the runtime code still is in English and any error
    > message would be in English.
    
    This is currently seen as a reason to not have other keywords: it will 
    do no good anyway. A Python programmer must know minimal English and the 
    keywords are the least of the problem.
    
    I can imagine that there could be a mechanism for extracting and 
    replacing error messages with translations, like there is for Python 
    code, but I do not know if it will even happen with haphazard volunteer 
    work or will require grant sponsorship.
    
    > I can also imagine that it should be
    > possible to "simply" recompile python to use different keywords, but
    > then all libraries using the English keywords would become
    > incompatible, wouldn't they?
    > 
    > In this context it seems to be the case that the executable would have
    > to be able to optionally accept -a list- of dictionaries to internally
    > translate to English the keywords found in the input code and at most -
    > one- dictionary to internally translate from English output messages
    > such as a stack trace.
    > 
    > What do you guys think?
    
    I would like anyone in the world to be able to use Python, and I would 
    like Python programmers to potentially be able to potentially read any 
    Python code and not have the community severely balkanized. To me, this 
    would eventually mean both native keywords and tranliteration from other 
    alphabets and scripts to latin chars. Not an easy project.
    
    Terry Jan Reedy
    
    
    
    From aahz at pythoncraft.com  Wed Nov 25 16:38:19 2009
    From: aahz at pythoncraft.com (Aahz)
    Date: 25 Nov 2009 13:38:19 -0800
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    Message-ID: 
    
    In article ,
    Chris Rebert   wrote:
    >
    >If you want to prevent an instance being created in the first place,
    >you can override __new__().
    
    Or just raise an exception in __init__(), which I think is more common
    practice.
    -- 
    Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/
    
    The best way to get information on Usenet is not to ask a question, but
    to post the wrong information.  
    
    
    From francesco.pietra at accademialucchese.it  Wed Nov 25 16:40:28 2009
    From: francesco.pietra at accademialucchese.it (Francesco Pietra)
    Date: Wed, 25 Nov 2009 22:40:28 +0100
    Subject: reposition a column
    Message-ID: 
    
    Hi:
    
    In a pdb file made of lines "ATOM .." (see attachment as I was unable
    to obtain plain text with gmail) I would like to reposition the second
    "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    would be 20 18). I started with bold slices, then I was unable to
    complete the script. Much obliged for help.
    
    francesco pietra
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: repositionRES.py
    Type: text/x-python
    Size: 438 bytes
    Desc: not available
    URL: 
    
    From stefan_ml at behnel.de  Wed Nov 25 16:46:58 2009
    From: stefan_ml at behnel.de (Stefan Behnel)
    Date: Wed, 25 Nov 2009 22:46:58 +0100
    Subject: creating pipelines in python
    In-Reply-To: <32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com>
    	<87y6lxd37a.fsf@rudin.co.uk>
    	<32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    Message-ID: <4b0da5d5$0$6573$9b4e6d93@newsspool3.arcor-online.net>
    
    per, 25.11.2009 17:42:
    > Thanks to all for your replies.  i want to clarify what i mean by a
    > pipeline.  a major feature i am looking for is the ability to chain
    > functions or scripts together, where the output of one script -- which
    > is usually a file -- is required for another script to run.  so one
    > script has to wait for the other.  i would like to do this over a
    > cluster, where some of the scripts are distributed as separate jobs on
    > a cluster but the results are then collected together.  so the ideal
    > library would have easily facilities for expressing this things:
    > script X and Y run independently, but script Z depends on the output
    > of X and Y (which is such and such file or file flag).
    > 
    > is there a way to do this? i prefer not to use a framework that
    > requires control of the clusters etc. like Disco, but something that's
    > light weight and simple. right now ruffus seems most relevant but i am
    > not sure -- are there other candidates?
    
    As others have pointed out, a Unix pipe approach might be helpful if you
    want the processes to run in parallel. You can send the output of one
    process to stdout, a network socket, an HTTP channel or whatever, and have
    the next process read it and work on it while it's being generated by the
    first process.
    
    Looking into generators is still a good idea, even if you go for a pipe
    approach. See the link posted by Wolodja Wentland.
    
    Stefan
    
    
    From dksreddy at gmail.com  Wed Nov 25 16:52:09 2009
    From: dksreddy at gmail.com (Sandy)
    Date: Wed, 25 Nov 2009 13:52:09 -0800 (PST)
    Subject: confused with os.fork()
    Message-ID: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    
    Hi all,
    I am a little bit confused about os.fork().
    Say I have the following code.
    
    import os
    a = ['a','b','c','d','e']
    
    for i in xrange(len(a)):
        pid = os.fork()
        if not pid:
            print a[i]
            os._exit(0)
    
    >From most of the tuts and examples I saw online, I expect it to print
    a,b,c,d,e.
    Sometimes (very rare) it prints something like this:
    ab
    c
    d
    e
    I thought there is no way a parent process can enter the 'if'.
    Can anyone explain this behaviour? Is it the case where parent is
    forking a child even before the previous child is printing? In that
    case is there a way to prevent that? I can use os.wait(), but I don't
    want to wait till the child is finished, just don't want to mix the
    child processes, that's it.
    
    - dksr
    
    
    From deets at nospam.web.de  Wed Nov 25 17:15:50 2009
    From: deets at nospam.web.de (Diez B. Roggisch)
    Date: Wed, 25 Nov 2009 23:15:50 +0100
    Subject: confused with os.fork()
    In-Reply-To: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    References: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    Message-ID: <7n5okmF3ju980U1@mid.uni-berlin.de>
    
    Sandy schrieb:
    > Hi all,
    > I am a little bit confused about os.fork().
    > Say I have the following code.
    > 
    > import os
    > a = ['a','b','c','d','e']
    > 
    > for i in xrange(len(a)):
    >     pid = os.fork()
    >     if not pid:
    >         print a[i]
    >         os._exit(0)
    > 
    > From most of the tuts and examples I saw online, I expect it to print
    > a,b,c,d,e.
    > Sometimes (very rare) it prints something like this:
    > ab
    > c
    > d
    > e
    > I thought there is no way a parent process can enter the 'if'.
    > Can anyone explain this behaviour? Is it the case where parent is
    > forking a child even before the previous child is printing? In that
    > case is there a way to prevent that? I can use os.wait(), but I don't
    > want to wait till the child is finished, just don't want to mix the
    > child processes, that's it.
    
    Yes, that's the case - you have a race-condition here. Two childs at the 
    same time write, interleaving their data.
    
    To prevent this, you can use file-locking.
    
    http://docs.python.org/library/fcntl.html#fcntl.lockf
    
    Diez
    
    
    From icanbob at gmail.com  Wed Nov 25 17:18:29 2009
    From: icanbob at gmail.com (bobicanprogram)
    Date: Wed, 25 Nov 2009 14:18:29 -0800 (PST)
    Subject: Python & OpenOffice Spreadsheets
    References: 
    Message-ID: <6933d92b-3e22-4e3f-a69a-9e82db662c0a@s15g2000yqs.googlegroups.com>
    
    On Nov 23, 5:49 am, Gerhard H?ring  wrote:
    > Is there a *simple* way to read OpenOffice spreadsheets?
    >
    > Bonus: write them, too?
    >
    > I mean something like:
    >
    > doc.cells[0][0] = "foo"
    > doc.save("xyz.ods")
    >
    > >From a quick look, pyodf offers little more than just using a XML parser
    >
    > directly.
    >
    > -- Gerhard
    
    
    OO Calc has an HTML file feature for auto updating fields in a
    spreadsheet.
    
    I hacked together something for a talk a few years ago:
    
    http://www.icanprogram.com/hosug
    
    (See Open Office Calc demo section)
    While it isn't Python code it should be easy enough to convert to
    Python.
    
    bob
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 17:25:06 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 22:25:06 +0000
    Subject: reposition a column
    In-Reply-To: 
    References: 
    Message-ID: <4B0DAEC2.7050306@mrabarnett.plus.com>
    
    Francesco Pietra wrote:
    > Hi:
    > 
    > In a pdb file made of lines "ATOM .." (see attachment as I was unable
    > to obtain plain text with gmail) I would like to reposition the second
    > "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    > would be 20 18). I started with bold slices, then I was unable to
    > complete the script. Much obliged for help.
    > 
    I'm assuming that you want to put a space where the 'W' was.
    
    L = L[ : 17] + L[19] + L[18] + ' ' + L[20 : ]
    
    
    
    From vlastimil.brom at gmail.com  Wed Nov 25 17:32:17 2009
    From: vlastimil.brom at gmail.com (Vlastimil Brom)
    Date: Wed, 25 Nov 2009 23:32:17 +0100
    Subject: reposition a column
    In-Reply-To: 
    References: 
    Message-ID: <9fdb569a0911251432h10b04a4dra1ee8dc18c425954@mail.gmail.com>
    
    2009/11/25 Francesco Pietra :
    > Hi:
    >
    > In a pdb file made of lines "ATOM .." (see attachment as I was unable
    > to obtain plain text with gmail) I would like to reposition the second
    > "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    > would be 20 18). I started with bold slices, then I was unable to
    > complete the script. Much obliged for help.
    >
    > francesco pietra
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    Hi,
    using only string slices, you can probably do something like the
    following (if I underestand the specification correctly, i.e. to swap
    the two columns under the given condition).
    An alternative is to swap the indices directly using list.
    Also a regular expression replace with re.sub might be viable
    (probably the shortest one)...
    
    hth,
      vbr
    
    ######################################
    
    scale = """          1         2         3         4         5         6
    012345678901234567890123456789012345678901234567890123456789012345"""
    data_line = "ATOM      1  W     W     1       0.690  35.960  33.300  1.00  0.00"
    
    if data_line [19] == 'W':
        output_line = data_line [0:17]+data_line [19]+data_line
    [18]+data_line [17]+data_line [20:]
    # alternatively
        ch_19, ch_17 = data_line [19], data_line [17]
        data_lst = list(data_line)
        data_lst[17] = ch_19
        data_lst[19] = ch_17
        output_line_2 = "".join(data_lst)
        print output_line_2 == output_line
    
    else:
        output_line = data_line
    
    print scale
    print data_line
    print scale
    print output_line
    print "=" * 66
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 17:33:50 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 22:33:50 +0000
    Subject: confused with os.fork()
    In-Reply-To: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    References: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    Message-ID: <4B0DB0CE.4030007@mrabarnett.plus.com>
    
    Sandy wrote:
    > Hi all,
    > I am a little bit confused about os.fork().
    > Say I have the following code.
    > 
    > import os
    > a = ['a','b','c','d','e']
    > 
    > for i in xrange(len(a)):
    >     pid = os.fork()
    >     if not pid:
    >         print a[i]
    >         os._exit(0)
    > 
    >>From most of the tuts and examples I saw online, I expect it to print
    > a,b,c,d,e.
    > Sometimes (very rare) it prints something like this:
    > ab
    > c
    > d
    > e
    > I thought there is no way a parent process can enter the 'if'.
    > Can anyone explain this behaviour? Is it the case where parent is
    > forking a child even before the previous child is printing? In that
    > case is there a way to prevent that? I can use os.wait(), but I don't
    > want to wait till the child is finished, just don't want to mix the
    > child processes, that's it.
    > 
    The parent isn't entering the 'if' statement. os.fork() simply forks the
    process and then both the parent and the child processes continue.
    
    All of the child processes run independently and there's no guarantee as
    to the order in which they'll print, and there's nothing to stop the
    printouts from being mixed together (you would need to protect the
    'print' with a mutex to do that).
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 18:32:58 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 15:32:58 -0800 (PST)
    Subject: Cookie name and expiration
    Message-ID: 
    
    Hi,
    
    I'm testing the Cookie module's MarshalCookie in mod_python on my
    localhost environment. Everything looks ok and cookie set, get and
    update operations work well. But I'm not sure about the cookie name
    could be set by Cookie module. I mean the name of cookie file saved in
    the Temporary Internet Files directory of Internet Explorer. Consider
    that I run the script as http://localhost:8080/myScripts/myScript
    When I look at the Temporary Internet Files dir, not like other
    cookies came from normal websites, the cookie file was saved as
    "myScript/" and the cookie address is shown as http://localhost:8080/myScripts/
    I don't know this is normal behaviour of the browser or there is an
    option to set the name of cookie file.
    
    I mentioned the expiration in the subject but maybe it's not related
    to expiration. For example if I run directly http://localhost:8080/myScripts/myScript2
    after a day and look for the temporary internet directory again, I see
    a second cookie named "myScript2/" and the first cookie (myScript/)
    still exists there. But the first cookie seems no longer valid for
    this domain although I set the expire range for 30 days.
    
    Do I miss something about cookies concept and behaviour of browsers?
    Could anyone please clarify?
    
    Thanks and regards,
    Kutlu
    
    
    From skippy.hammond at gmail.com  Wed Nov 25 18:43:59 2009
    From: skippy.hammond at gmail.com (Mark Hammond)
    Date: Thu, 26 Nov 2009 10:43:59 +1100
    Subject: reading windows event logs
    In-Reply-To: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    References: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    Message-ID: <4B0DC13F.1060408@gmail.com>
    
    On 26/11/2009 7:22 AM, EW wrote:
    > Hi All,
    >       I'm looking for some guidance on a better way to read eventlogs
    > from windows servers.  I've written a handy little app that relies on
    > WMI to pull the logs an in all my testing it worked great.  When I
    > deployed it, however, WMI choked on servers with a lot of logs.  I've
    > tried pulling the logs using much smaller VB scripts as well and they
    > still failed, so I'm pretty sure I'm facing a WMI problem and not a
    > python or system resources problem.  So I couldn't effectively get
    > logs off of domain controllers for example or file servers that had
    > auditing turned on.  Sadly those are exactly the types of servers
    > whose logs are most interesting.
    >
    >       So I'm looking for suggestions on a way to grab that data without
    > using WMI for remote machines.  I know MS has C libraries for this but
    > I haven't touched C for 10 years so I'm hoping there's a python
    > equivalent out there somewhere.  Any advice would be appreciated.
    
    Look for the win32evtlog and win32evtlogutil modules which come with 
    pywin32 (http://sf.net/projects/pywin32)
    
    Cheers,
    
    Mark
    
    
    From naveen.garg at gmail.com  Wed Nov 25 19:12:09 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 16:12:09 -0800 (PST)
    Subject: embed python dynamically
    Message-ID: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    
    How do you embed the python dll file distributed with the automatic
    installable python distribution on windows?
    Is it possible to dynamically load the python dll from running c
    program and start up a python interpreter ?
    Do you have to compile python from source to be able to embed python?
    
    
    
    From nick.mellor.groups at pobox.com  Wed Nov 25 19:24:57 2009
    From: nick.mellor.groups at pobox.com (Nick Mellor)
    Date: Wed, 25 Nov 2009 16:24:57 -0800 (PST)
    Subject: High-performance Python websites
    Message-ID: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    
    Hi all,
    
    I'm contemplating setting up a Python-powered website for the tourist
    industry, which will involve a web service, a good deal of XML
    processing, and a Django-powered front-end. If the project works, it
    could get a lot of traffic. I'm sure it can be done, but I'm looking
    to find out more about how existing high-volume Python sites have
    managed their workload. Can anyone give me examples of high-volume
    Python-powered websites, if possible with some idea of their
    architecture?
    
    Many thanks,
    
    Nick
    
    
    From andrethehunter at gmail.com  Wed Nov 25 19:32:36 2009
    From: andrethehunter at gmail.com (=?ISO-8859-1?Q?Andr=E9?=)
    Date: Wed, 25 Nov 2009 16:32:36 -0800 (PST)
    Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The 
    	specified module could not be found."
    References: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com>
    	
    Message-ID: 
    
    On Nov 19, 6:57?pm, Neil Hodgson 
    wrote:
    > Andr?:
    >
    > > Apparently the error is caused by cx_Oracle not being able to find the
    > > Oracle client DLLs (oci.dll and others). The client home path and the
    > > client home path bin directory are in the PATH System Variable and
    > > oci.dll is there.
    >
    > ? ?Open the cx_Oracle extension with Dependency Walker
    > (http://www.dependencywalker.com/) to get a better idea about what the
    > problem is in more detail.
    >
    > ? ?Neil
    
    Thanks Neil. I used Dependency Walker and discovered cx_Oracle was
    looking for python30.dll. I seems to be a known issue with Python 3.1
    http://bugs.python.org/issue4091. I'm now used Python 2.6.4 and the
    corresponding cx_Oracle version with no problems.
    
    Thanks for the help
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 19:33:31 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 16:33:31 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    Message-ID: 
    
    Hi,
    
    Managing load of high volume of visitors is a common issue for all
    kind of web technologies. I mean this is not the python issue. This
    issue is mostly about server level designs. You need to supply load
    balancing for both web servers and databases to make your web site
    able to respond to several concurrent visitors. Of course a good
    programmed website is a key performance issue but for your mention I
    would also suggest considering how many hardwares, how many
    webservers, how many database cluster and which database server should
    be used or will be used in the future..
    
    Regards,
    Kutlu
    
    On Nov 26, 2:24?am, Nick Mellor  wrote:
    > Hi all,
    >
    > I'm contemplating setting up a Python-powered website for the tourist
    > industry, which will involve a web service, a good deal of XML
    > processing, and a Django-powered front-end. If the project works, it
    > could get a lot of traffic. I'm sure it can be done, but I'm looking
    > to find out more about how existing high-volume Python sites have
    > managed their workload. Can anyone give me examples of high-volume
    > Python-powered websites, if possible with some idea of their
    > architecture?
    >
    > Many thanks,
    >
    > Nick
    
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 19:45:27 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 16:45:27 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	
    Message-ID: 
    
    If you need an example one is in front of you and you are using it
    now. Google uses python at their thousands of servers. But as you see
    Google gains this performance from the power of hundreds of thousands
    servers. The main idea behind the Google search engine was indexing
    the whole web through hundreds of servers. So you can imagine where
    Google's power comes from..
    
    Regards
    
    
    On Nov 26, 2:33?am, ShoqulKutlu  wrote:
    > Hi,
    >
    > Managing load of high volume of visitors is a common issue for all
    > kind of web technologies. I mean this is not the python issue. This
    > issue is mostly about server level designs. You need to supply load
    > balancing for both web servers and databases to make your web site
    > able to respond to several concurrent visitors. Of course a good
    > programmed website is a key performance issue but for your mention I
    > would also suggest considering how many hardwares, how many
    > webservers, how many database cluster and which database server should
    > be used or will be used in the future..
    >
    > Regards,
    > Kutlu
    >
    > On Nov 26, 2:24?am, Nick Mellor  wrote:
    >
    >
    >
    > > Hi all,
    >
    > > I'm contemplating setting up a Python-powered website for the tourist
    > > industry, which will involve a web service, a good deal of XML
    > > processing, and a Django-powered front-end. If the project works, it
    > > could get a lot of traffic. I'm sure it can be done, but I'm looking
    > > to find out more about how existing high-volume Python sites have
    > > managed their workload. Can anyone give me examples of high-volume
    > > Python-powered websites, if possible with some idea of their
    > > architecture?
    >
    > > Many thanks,
    >
    > > Nick- Hide quoted text -
    >
    > - Show quoted text -
    
    
    
    From n00m at narod.ru  Wed Nov 25 19:56:07 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 16:56:07 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	
    Message-ID: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    
    > Or just raise an exception in __init__(),..
    
    Then we are forced to handle this exception outside of class code.
    It's Ok. Never mind.
    --------------------
    
    Next thing.
    I can't understand why we can get __name__, but not __dict__,
    on the module level?
    
    
    print __name__
    print __dict__
    
    
    >>> ===================================== RESTART ====
    >>>
    __main__
    
    Traceback (most recent call last):
      File "D:\Python25\zewrt.py", line 19, in 
        print __dict__
    NameError: name '__dict__' is not defined
    
    
    
    From naveen.garg at gmail.com  Wed Nov 25 19:58:50 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 16:58:50 -0800 (PST)
    Subject: embed installed python dynamically
    References: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    Message-ID: <12592aad-d6a4-4d18-b8ea-46521fae03ec@p8g2000yqb.googlegroups.com>
    
    ok, it was almost intuitive.
    just made a simple visual c express dll project
    included python26\include and python26\libs in the project settings
    the debug version has issues, but the release compiles without a
    problem.
    here is the source:
    http://github.com/tinku99/embedpython
    
    
    From tjreedy at udel.edu  Wed Nov 25 20:09:25 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 20:09:25 -0500
    Subject: Can "self" crush itself?
    In-Reply-To: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    References: 	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    		
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    Message-ID: 
    
    n00m wrote:
    >> Or just raise an exception in __init__(),..
    > 
    > Then we are forced to handle this exception outside of class code.
    > It's Ok. Never mind.
    > --------------------
    > 
    > Next thing.
    > I can't understand why we can get __name__, but not __dict__,
    > on the module level?
    > 
    > 
    > print __name__
    > print __dict__
    
    If the global namespace contained itself, as a dict, there would be an 
    infinite loop.
    
    
    
    From keith at nekotaku.com  Wed Nov 25 20:30:19 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 17:30:19 -0800 (PST)
    Subject: jython and java application
    Message-ID: 
    
    Hi there,
    
    Apologies if this is on the wrong group, this is a jython question.
    Please redirect me to the correct group if this is in error.
    
    I have a java application that takes no arguements. When I run it, it
    spits out output, and finishes.
    
    I am trying to run this java application from jython 2.5.1, JRE6.
    
    I have made simple "Hello World" java classes be callable from a
    simple jython script, yet I am stumbling on the java main construct in
    the application.
    
    print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    args error (expected 1, got 0) as the definition in the java
    application is:
    
    public static void main(String[] args)
    
    The jython code is as follows:
    import krbtest
    
    # was messing with this to pass a java formatted string but to no
    avail
    
    from java.lang import String
    
    print krbtest.SimpleHistoricTutorial().main()
    
    #####
    
    Any advice greatly appreciated! Especially with how to call "main()"
    with arguments from jython.
    
    Apologies in advance again if this is the wrong group.
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 20:54:23 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 17:54:23 -0800 (PST)
    Subject: jython and java application
    References: 
    Message-ID: <1dffc77c-8930-4949-9ce4-d05f5d991c7c@s15g2000yqs.googlegroups.com>
    
    I don't know if it's right place but normally main method requires an
    args even it is not needed to supply from commandline. Maybe this is a
    jython runtime error and requires at least an empty argument. You
    could try to pass and empty string array like ['']. I'm not using
    jython please use your own notation.
    
    Regards,
    Kutlu
    
    On Nov 26, 3:30?am, KB  wrote:
    > Hi there,
    >
    > Apologies if this is on the wrong group, this is a jython question.
    > Please redirect me to the correct group if this is in error.
    >
    > I have a java application that takes no arguements. When I run it, it
    > spits out output, and finishes.
    >
    > I am trying to run this java application from jython 2.5.1, JRE6.
    >
    > I have made simple "Hello World" java classes be callable from a
    > simple jython script, yet I am stumbling on the java main construct in
    > the application.
    >
    > print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    > args error (expected 1, got 0) as the definition in the java
    > application is:
    >
    > public static void main(String[] args)
    >
    > The jython code is as follows:
    > import krbtest
    >
    > # was messing with this to pass a java formatted string but to no
    > avail
    >
    > from java.lang import String
    >
    > print krbtest.SimpleHistoricTutorial().main()
    >
    > #####
    >
    > Any advice greatly appreciated! Especially with how to call "main()"
    > with arguments from jython.
    >
    > Apologies in advance again if this is the wrong group.
    
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 20:54:43 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Thu, 26 Nov 2009 01:54:43 +0000
    Subject: jython and java application
    In-Reply-To: 
    References: 
    Message-ID: <4B0DDFE3.1040204@mrabarnett.plus.com>
    
    KB wrote:
    > Hi there,
    > 
    > Apologies if this is on the wrong group, this is a jython question.
    > Please redirect me to the correct group if this is in error.
    > 
    > I have a java application that takes no arguements. When I run it, it
    > spits out output, and finishes.
    > 
    > I am trying to run this java application from jython 2.5.1, JRE6.
    > 
    > I have made simple "Hello World" java classes be callable from a
    > simple jython script, yet I am stumbling on the java main construct in
    > the application.
    > 
    > print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    > args error (expected 1, got 0) as the definition in the java
    > application is:
    > 
    > public static void main(String[] args)
    > 
    > The jython code is as follows:
    > import krbtest
    > 
    > # was messing with this to pass a java formatted string but to no
    > avail
    > 
    > from java.lang import String
    > 
    > print krbtest.SimpleHistoricTutorial().main()
    > 
    > #####
    > 
    > Any advice greatly appreciated! Especially with how to call "main()"
    > with arguments from jython.
    > 
    > Apologies in advance again if this is the wrong group.
    
    I don't know jython, but from the look of it I'd say that you need to
    give main() some kind of argument, such as a string or an empty list.
    (If you pass an empty jython list to a Java method that's expecting an
    array of String, will the Java method receive a zero-length array of
    String?).
    
    
    From naveen.garg at gmail.com  Wed Nov 25 20:57:10 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 17:57:10 -0800 (PST)
    Subject: embed installed python dynamically
    References: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    	<12592aad-d6a4-4d18-b8ea-46521fae03ec@p8g2000yqb.googlegroups.com>
    Message-ID: <78043e65-a3c8-4da7-a484-47eacc821b20@j14g2000yqm.googlegroups.com>
    
    ok, its even easier than that.
    With autohotkey:
    
    pythondll := DllCall("LoadLibrary", "str", "c:\windows
    \system32\python26.dll")
    init := DllCall("c:\windows\system32\python26.dll\Py_Initialize"
    , "Cdecl")
    msgbox python initalized
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "import sys", "Cdecl")
    msgbox will exit using python code
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "sys.exit(0)", "Cdecl")
    init := DllCall("c:\windows\system32\python26.dll\Py_Finalize"
    , "Cdecl")
    msgbox % never called
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 21:06:24 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 02:06:24 GMT
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 20:09:25 -0500, Terry Reedy wrote:
    
    > n00m wrote:
    >>> Or just raise an exception in __init__(),..
    >> 
    >> Then we are forced to handle this exception outside of class code. It's
    >> Ok. Never mind.
    >> --------------------
    >> 
    >> Next thing.
    >> I can't understand why we can get __name__, but not __dict__, on the
    >> module level?
    >> 
    >> 
    >> print __name__
    >> print __dict__
    > 
    > If the global namespace contained itself, as a dict, there would be an
    > infinite loop.
    
    
    Why would that be a problem?  Any time you do this:
    
    >>> g = globals()
    
    
    you create such a recursive reference:
    
    >>> globals()['g']['g']['g']['g'] is globals() is g
    True
    
    
    Yes, there's a tiny bit extra work needed when bootstrapping the 
    processes, and when exiting, but I don't see why it's a big deal. Whether 
    it's necessary or useful is another story.
    
    
    
    -- 
    Steven
    
    
    From FearsomeDragonfly at gmail.com  Wed Nov 25 21:35:06 2009
    From: FearsomeDragonfly at gmail.com (The Music Guy)
    Date: Wed, 25 Nov 2009 20:35:06 -0600
    Subject: Feature request: String-inferred names
    Message-ID: 
    
    Hello all,
    
    I just posted to my blog about a feature that I'd like to see added to
    Python. Before I go through the trouble of learning how to write a PEP or
    how to extend the Python interpreter, I want to know what people in the
    community have to say about it.
    
    http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    As far as I know, a feature like this does not appear in any existing PEPs.
    (If it does I would appreciate it if someone could tell me what PEP it is.)
    
    Please give and comments you may have, but I request that you be
    constructive if you must criticize...thank you!
    
    TMG
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From christian.grise at gmail.com  Wed Nov 25 21:39:03 2009
    From: christian.grise at gmail.com (Christian Grise)
    Date: Wed, 25 Nov 2009 21:39:03 -0500
    Subject: Help with error on self.show
    Message-ID: 
    
    Hi,
    
    I am getting an error when I try to run some code my friend gave me. Here is
    the error:
    
    Warning (from warnings module):
      File "C:\Documents and Settings\GriseC\Desktop\Widget Base\applet.py",
    line 145
        self.show()
    GtkWarning: ../../../../gtk+/gdk/win32/gdkwindow-win32.c:1089: SetWindowLong
    failed: Not enough storage is available to process this command.
    
    If anyone knows what this means, any info would be greatly appreciated.
    
    Thanks,
    Christian
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From n00m at narod.ru  Wed Nov 25 21:39:09 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 18:39:09 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	 
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com> 
    	
    	
    Message-ID: 
    
    
    aaah... globals()...
    Then why "self" not in globals()?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.__class__.cnt += 1
            if self.__class__.cnt < 3:
                self.x = x
            else:
                print id(self)
                for item in globals().items():
                    print item
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    
    
    >>> ===================================== RESTART ====
    >>>
    13407336
    ('g', <__main__.Moo instance at 0x00CC9260>)
    ('f', <__main__.Moo instance at 0x00CC9440>)
    ('__builtins__', )
    ('Moo', )
    ('__name__', '__main__')
    ('__doc__', None)
    >>>
    
    
    From musicguy at alphaios.net  Wed Nov 25 21:44:36 2009
    From: musicguy at alphaios.net (The Music Guy)
    Date: Wed, 25 Nov 2009 20:44:36 -0600
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 
    Message-ID: 
    
    I just posted to my blog about a feature that I'd like to see added to
    Python. Before I go through the trouble of learning how to write a PEP or
    how to extend the Python interpreter, I want to know what people in the
    community have to say about it.
    
    http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    As far as I know, a feature like this does not appear in any existing PEPs.
    (If it does I would appreciate it if someone could tell me what PEP it
    is.)Please give and comments you may have, but I request that you be
    constructive if you must criticize...thank you!
    
    TMG
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From keith at nekotaku.com  Wed Nov 25 21:49:15 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 18:49:15 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    Message-ID: 
    
    
    Hmmm, for some reason my follow up post didn't make it.
    
    Modified jython script to:
    
    # Eclipse package name for java application
    import krbtest
    
    import java.lang as lang
    from java.lang import String
    from jarray import array
    
    myargs=array([],String)
    
    krbtest.SimpleHistoricTutorial().main(myargs)
    ****
    
    Now I get:
    
    Traceback (most recent call last):
      File "test.py", line 15, in 
        krbtest.SimpleHistoricTutorial().main(myargs)
    	at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)
    
    	at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
    22)
    
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    
    	at java.lang.reflect.Method.invoke(Unknown Source)
    
    
    java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
    bloomberglp/blpapi/Session
    
    
    I would post the java app but its quite large, but the main defn:
    
    	public static void main(String[] args) throws Exception
    	{
    		SimpleHistoricTutorial example = new SimpleHistoricTutorial();
    		example.run();
    	}
    
    
    Is pretty vanilla. I have tried making the run() a public method and
    call it, all to no avail.
    
    Note, the Java app works fine standalone, I just need to call it from
    jython.
    
    Again, any help appreciated.
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:20:44 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:20:44 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    Message-ID: <300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com>
    
    Hi,
    
    I don't know how do you call the java library from within your jython
    application it gives java.lang.NoClassDefFoundError
    This looks like you referenced jar or whatever else from your jython
    application which also needs a class com/bloomberglp/blpapi/Session
    in another library file. It might run while running standalone because
    the dependent libraries exists where it looks for. For your jython
    application you need to make krbtest referenced to the dependent
    libraries. It seems you application took a copy of krbtest and other
    libraries not available to krbtest there. I hope it helps.
    
    Regards,
    Kutlu
    
    
    
    On Nov 26, 4:49?am, KB  wrote:
    > Hmmm, for some reason my follow up post didn't make it.
    >
    > Modified jython script to:
    >
    > # Eclipse package name for java application
    > import krbtest
    >
    > import java.lang as lang
    > from java.lang import String
    > from jarray import array
    >
    > myargs=array([],String)
    >
    > krbtest.SimpleHistoricTutorial().main(myargs)
    > ****
    >
    > Now I get:
    >
    > Traceback (most recent call last):
    > ? File "test.py", line 15, in 
    > ? ? krbtest.SimpleHistoricTutorial().main(myargs)
    > ? ? ? ? at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)
    >
    > ? ? ? ? at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
    > 22)
    >
    > ? ? ? ? at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >
    > ? ? ? ? at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    >
    > ? ? ? ? at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    >
    > ? ? ? ? at java.lang.reflect.Method.invoke(Unknown Source)
    >
    > java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
    > bloomberglp/blpapi/Session
    >
    > I would post the java app but its quite large, but the main defn:
    >
    > ? ? ? ? public static void main(String[] args) throws Exception
    > ? ? ? ? {
    > ? ? ? ? ? ? ? ? SimpleHistoricTutorial example = new SimpleHistoricTutorial();
    > ? ? ? ? ? ? ? ? example.run();
    > ? ? ? ? }
    >
    > Is pretty vanilla. I have tried making the run() a public method and
    > call it, all to no avail.
    >
    > Note, the Java app works fine standalone, I just need to call it from
    > jython.
    >
    > Again, any help appreciated.
    
    
    
    From keith at nekotaku.com  Wed Nov 25 22:33:02 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 19:33:02 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    	<300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com>
    Message-ID: <708eac8e-c0c0-4ff4-adcd-a8b7742fb9b5@b25g2000prb.googlegroups.com>
    
    Kutlu,
    
    I already have a first born, else I would name her after you.
    
    You are brilliant. That's what it was. Kudos.
    
    For future ref for fellow boneheads like me, in Eclipse, under Project
    properties, Jython Class Path, Add External JAR...
    
    Thanks a million!
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 22:33:05 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 03:33:05 GMT
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    	
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 18:39:09 -0800, n00m wrote:
    
    > aaah... globals()...
    > Then why "self" not in globals()?
    > 
    > class Moo:
    >     cnt = 0
    >     def __init__(self, x):
    >         self.__class__.cnt += 1
    
    
    Because it isn't a global, it's a local -- it is defined inside a class. 
    Inside functions and classes, names you create are local, not global, 
    unless you declare them global.
    
    
    
    
    -- 
    Steven
    
    
    From mwilson at the-wire.com  Wed Nov 25 22:36:06 2009
    From: mwilson at the-wire.com (Mel)
    Date: Wed, 25 Nov 2009 22:36:06 -0500
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    	
    	
    Message-ID: 
    
    n00m wrote:
    
    > 
    > aaah... globals()...
    > Then why "self" not in globals()?
    > 
    > class Moo:
    >     cnt = 0
    >     def __init__(self, x):
    >         self.__class__.cnt += 1
    >         if self.__class__.cnt < 3:
    >             self.x = x
    >         else:
    >             print id(self)
    >             for item in globals().items():
    >                 print item
    > 
    > f = Moo(1)
    > g = Moo(2)
    > h = Moo(3)
    
    Because self is not in globals().
    
    It's defined as a local symbol in Moo.__init__ , supplied to that function 
    as the first parameter.
    
    	Mel.
    
    
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:40:01 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:40:01 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    	<300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com> 
    	<708eac8e-c0c0-4ff4-adcd-a8b7742fb9b5@b25g2000prb.googlegroups.com>
    Message-ID: <1360eb33-2a3d-4a30-a40f-53704690c678@j14g2000yqm.googlegroups.com>
    
    Welcome a million :)
    
    On Nov 26, 5:33?am, KB  wrote:
    > Kutlu,
    >
    > I already have a first born, else I would name her after you.
    >
    > You are brilliant. That's what it was. Kudos.
    >
    > For future ref for fellow boneheads like me, in Eclipse, under Project
    > properties, Jython Class Path, Add External JAR...
    >
    > Thanks a million!
    
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 22:45:19 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 03:45:19 GMT
    Subject: How do I correctly download Wikipedia pages?
    Message-ID: 
    
    I'm trying to scrape a Wikipedia page from Python. Following instructions 
    here:
    
    http://en.wikipedia.org/wiki/Wikipedia:Database_download
    http://en.wikipedia.org/wiki/Special:Export
    
    I use the URL "http://en.wikipedia.org/wiki/Special:Export/Train" instead 
    of just "http://en.wikipedia.org/wiki/Train". But instead of getting the 
    page I expect, and can see in my browser, I get an error page:
    
    
    >>> import urllib
    >>> url = "http://en.wikipedia.org/wiki/Special:Export/Train"
    >>> print urllib.urlopen(url).read()
    ...
    Our servers are currently experiencing a technical problem. This is 
    probably temporary and should be fixed soon
    ...
    
    
    (Output is obviously truncated for your sanity and mine.)
    
    
    Is there a trick to downloading from Wikipedia with urllib?
    
    
    
    -- 
    Steven
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:58:57 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:58:57 -0800 (PST)
    Subject: How do I correctly download Wikipedia pages?
    References: 
    Message-ID: <6f8913f0-9b93-4ae5-979c-012057f5aff4@v30g2000yqm.googlegroups.com>
    
    Hi,
    
    Try not to be caught if you send multiple requests :)
    
    Have a look at here: http://wolfprojects.altervista.org/changeua.php
    
    Regards
    Kutlu
    
    On Nov 26, 5:45?am, Steven D'Aprano
     wrote:
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    > here:
    >
    > http://en.wikipedia.org/wiki/Wikipedia:Database_downloadhttp://en.wikipedia.org/wiki/Special:Export
    >
    > I use the URL "http://en.wikipedia.org/wiki/Special:Export/Train" instead
    > of just "http://en.wikipedia.org/wiki/Train". But instead of getting the
    > page I expect, and can see in my browser, I get an error page:
    >
    > >>> import urllib
    > >>> url = "http://en.wikipedia.org/wiki/Special:Export/Train"
    > >>> print urllib.urlopen(url).read()
    >
    > ...
    > Our servers are currently experiencing a technical problem. This is
    > probably temporary and should be fixed soon
    > ...
    >
    > (Output is obviously truncated for your sanity and mine.)
    >
    > Is there a trick to downloading from Wikipedia with urllib?
    >
    > --
    > Steven
    
    
    
    From apt.shansen at gmail.com  Wed Nov 25 23:04:00 2009
    From: apt.shansen at gmail.com (Stephen Hansen)
    Date: Wed, 25 Nov 2009 20:04:00 -0800
    Subject: How do I correctly download Wikipedia pages?
    In-Reply-To: 
    References: 
    Message-ID: <7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    
    2009/11/25 Steven D'Aprano 
    
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    > here:
    >
    >
    Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?
    
    Its not just via urllib, but I've scraped several MediaWiki-based sites with
    the software successfully.
    
    --S
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From taskinoor.hasan at csebuet.org  Wed Nov 25 23:37:39 2009
    From: taskinoor.hasan at csebuet.org (Taskinoor Hasan)
    Date: Thu, 26 Nov 2009 10:37:39 +0600
    Subject: How do I correctly download Wikipedia pages?
    In-Reply-To: <7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    References: 
    	<7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    Message-ID: <79153a2e0911252037h172a3723yd00e5d5f0edb8bf3@mail.gmail.com>
    
    I fetched a different problem. Whenever I tried to fetch any page from
    wikipedia, I received 403. Then I found that wikipedia don't accept the
    default user-agent (might be python-urllib2.x or something like this). After
    setting my own user-agent, it worked fine. You can try this if you receive
    403.
    
    On Thu, Nov 26, 2009 at 10:04 AM, Stephen Hansen wrote:
    
    >
    >
    > 2009/11/25 Steven D'Aprano 
    >
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    >> here:
    >>
    >>
    > Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?
    >
    > Its not just via urllib, but I've scraped several MediaWiki-based sites
    > with the software successfully.
    >
    > --S
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From clp2 at rebertia.com  Wed Nov 25 23:49:36 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Wed, 25 Nov 2009 20:49:36 -0800
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 
    Message-ID: <50697b2c0911252049n2ccbee1fhdcba9ef56fee1718@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
     wrote:
    > Hello all,
    >
    > I just posted to my blog about a feature that I'd like to see added to
    > Python. Before I go through the trouble of learning how to write a PEP or
    > how to extend the Python interpreter, I want to know what people in the
    > community have to say about it.
    >
    > http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    >
    > As far as I know, a feature like this does not appear in any existing PEPs.
    > (If it does I would appreciate it if someone could tell me what PEP it is.)
    >
    > Please give and comments you may have, but I request that you be
    > constructive if you must criticize...thank you!
    
    Ugly, Perlish, and as you even admit, entirely unnecessary.
    And you'd need to wait at least a year anyway:
    http://www.python.org/dev/peps/pep-3003/
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 23:59:06 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 04:59:06 GMT
    Subject: How do I correctly download Wikipedia pages?
    References: 
    	<6f8913f0-9b93-4ae5-979c-012057f5aff4@v30g2000yqm.googlegroups.com>
    Message-ID: 
    
    On Wed, 25 Nov 2009 19:58:57 -0800, ShoqulKutlu wrote:
    
    > Hi,
    > 
    > Try not to be caught if you send multiple requests :)
    > 
    > Have a look at here: http://wolfprojects.altervista.org/changeua.php
    
    Thanks, that seems to work perfectly.
    
    
    -- 
    Steven
    
    
    From nick.mellor.groups at pobox.com  Thu Nov 26 00:21:25 2009
    From: nick.mellor.groups at pobox.com (Nick Mellor)
    Date: Wed, 25 Nov 2009 21:21:25 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	
    Message-ID: <06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com>
    
    Thanks Kutlu,
    
    I wasn't aware that Google used Python for running their Google groups
    servers. Can you confirm that? The only place
    I've seen Google explicitly use Python on their web front end is in
    the Google Ads tests.
    
    I am impressed by the responsiveness of lawrence.com, ljworld.com and
    others on the Django home page (http://www.djangoproject.com/)
    
    They seem to do a great job of loading large, complex pages using
    Django (stacked on Python, stacked on bytecode, stacked on C.)
    Shows it can be done.
    
    Nick
    
    
    From themusicguy123 at gmail.com  Thu Nov 26 00:45:45 2009
    From: themusicguy123 at gmail.com (Brad)
    Date: Wed, 25 Nov 2009 21:45:45 -0800 (PST)
    Subject: Feature request: String-inferred names
    References:  
    	
    Message-ID: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    
    On Nov 25, 10:49?pm, Chris Rebert  wrote:
    > On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    >
    >  wrote:
    > > Hello all,
    >
    > > I just posted to my blog about a feature that I'd like to see added to
    > > Python. Before I go through the trouble of learning how to write a PEP or
    > > how to extend the Python interpreter, I want to know what people in the
    > > community have to say about it.
    >
    > >http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...
    >
    > > As far as I know, a feature like this does not appear in any existing PEPs.
    > > (If it does I would appreciate it if someone could tell me what PEP it is.)
    >
    > > Please give and comments you may have, but I request that you be
    > > constructive if you must criticize...thank you!
    >
    > Ugly, Perlish, and as you even admit, entirely unnecessary.
    > And you'd need to wait at least a year anyway:http://www.python.org/dev/peps/pep-3003/
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com
    
    Like I said, lots of things in Python are "unnecessary," but that
    doesn't make them "useless," and it certainly doesn't mean they
    shouldn't exist. My proposed feature is not useless; I think it would
    make a lot of code easier.
    
    As for it being ugly...well, that's really a matter of opinion and
    experience. How ugly it looks to you will be a product of how well you
    think it can be used, and how well you use it yourself. When I first
    looked at decorators, I thought they were not only ugly but confusing.
    Now that I understand them, however, I hardly consider them "ugly,"
    and see them as a shining example of Python's abilities. (By the way,
    decorators are another example of a feature that is "entirely
    unnecessary," but still very useful.)
    
    As for the wait, that's to be expected. I'm willing to wait.
    
    
    From musicguy at alphaios.net  Thu Nov 26 00:59:02 2009
    From: musicguy at alphaios.net (The Music Guy)
    Date: Wed, 25 Nov 2009 23:59:02 -0600
    Subject: Feature request: String-inferred names
    In-Reply-To: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    Message-ID: 
    
    P.S., my apologies for sending replies with different email addresses. This
    is an unintentional technical issue and I am currently trying to get it
    fixed.
    
    On Wed, Nov 25, 2009 at 11:45 PM, Brad  wrote:
    
    > On Nov 25, 10:49 pm, Chris Rebert  wrote:
    > > On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    > >
    > >  wrote:
    > > > Hello all,
    > >
    > > > I just posted to my blog about a feature that I'd like to see added to
    > > > Python. Before I go through the trouble of learning how to write a PEP
    > or
    > > > how to extend the Python interpreter, I want to know what people in the
    > > > community have to say about it.
    > >
    > > >http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor.
    > ..
    > >
    > > > As far as I know, a feature like this does not appear in any existing
    > PEPs.
    > > > (If it does I would appreciate it if someone could tell me what PEP it
    > is.)
    > >
    > > > Please give and comments you may have, but I request that you be
    > > > constructive if you must criticize...thank you!
    > >
    > > Ugly, Perlish, and as you even admit, entirely unnecessary.
    > > And you'd need to wait at least a year anyway:
    > http://www.python.org/dev/peps/pep-3003/
    > >
    > > Cheers,
    > > Chris
    > > --http://blog.rebertia.com
    >
    > Like I said, lots of things in Python are "unnecessary," but that
    > doesn't make them "useless," and it certainly doesn't mean they
    > shouldn't exist. My proposed feature is not useless; I think it would
    > make a lot of code easier.
    >
    > As for it being ugly...well, that's really a matter of opinion and
    > experience. How ugly it looks to you will be a product of how well you
    > think it can be used, and how well you use it yourself. When I first
    > looked at decorators, I thought they were not only ugly but confusing.
    > Now that I understand them, however, I hardly consider them "ugly,"
    > and see them as a shining example of Python's abilities. (By the way,
    > decorators are another example of a feature that is "entirely
    > unnecessary," but still very useful.)
    >
    > As for the wait, that's to be expected. I'm willing to wait.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From kursat.kutlu at gmail.com  Thu Nov 26 00:59:22 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 21:59:22 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	 
    	<06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com>
    Message-ID: <610e1147-532d-42b8-92bc-75c11c4e6e79@v25g2000yqk.googlegroups.com>
    
    Hi Nick,
    
    Sorry about my concern on Google. It caused a confusion about Google
    groups. I didn't mean explicitly where Google uses python, I mentioned
    just Google uses Python. A Google officer told that they run Python on
    thousands of their servers at an interview. Due to this claim I wanted
    to say it for you.
    Actualy of course it can be done and even it will not be worse than
    any other frameworks, and I bet can be better than Java and ASP.NET if
    configured and programmed well. I really encourage you to use
    mod_python for any project. Mod_python and mod_wsgi made it very
    powerful at web side. As I said in my previous message a web
    application's responsiveness is dependent to several issues. A good
    web framework, server speed, database design etc.. In this case you
    want to use django, which as I know build for mod_python and can be
    configured to run on a mod_wsgi web server. Consider that you will
    have one million members on your site. That traffic simply needs
    several clustered web servers and clustered databases. This means you
    supply a load balancing. So concurrent user sessions will be shared on
    different web servers. You can do your best with such a clustered
    system with such a powerful language. Really don't worry about that.
    
    Regards,
    Kutlu
    
    On Nov 26, 7:21?am, Nick Mellor  wrote:
    > Thanks Kutlu,
    >
    > I wasn't aware that Google used Python for running their Google groups
    > servers. Can you confirm that? The only place
    > I've seen Google explicitly use Python on their web front end is in
    > the Google Ads tests.
    >
    > I am impressed by the responsiveness of lawrence.com, ljworld.com and
    > others on the Django home page (http://www.djangoproject.com/)
    >
    > They seem to do a great job of loading large, complex pages using
    > Django (stacked on Python, stacked on bytecode, stacked on C.)
    > Shows it can be done.
    >
    > Nick
    
    
    
    From kursat.kutlu at gmail.com  Thu Nov 26 01:09:30 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 22:09:30 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	 
    	<06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com> 
    	<610e1147-532d-42b8-92bc-75c11c4e6e79@v25g2000yqk.googlegroups.com>
    Message-ID: 
    
    Hi again,
    
    I also want to say something about creating a better web application.
    If I were you I wouldn't use any web framework like django or other.
    If you want to create a commercial project and want to manage all
    modules of the application yourself I suggest you to create your own
    framework. I don't mean create a Django like framework. Determine your
    needs, modules, services and build your own modules. Use other
    independent open source modules for any specific issues. To make a
    successful project requires your own business logic. And you can do
    this with your own algorithm. Don't avoid collecting other modules for
    templating, xml parsing, DB connectivity issues. But build your own
    framework with these and your own modules..
    
    Regards,
    Kutlu
    
    
    From gagsl-py2 at yahoo.com.ar  Thu Nov 26 01:30:38 2009
    From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina)
    Date: Thu, 26 Nov 2009 03:30:38 -0300
    Subject: Feature request: String-inferred names
    References: 
    Message-ID: 
    
    En Wed, 25 Nov 2009 23:35:06 -0300, The Music Guy  
     escribi?:
    
    > I just posted to my blog about a feature that I'd like to see added to
    > Python. Before I go through the trouble of learning how to write a PEP or
    > how to extend the Python interpreter, I want to know what people in the
    > community have to say about it.
    >
    > http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    >
    > As far as I know, a feature like this does not appear in any existing  
    > PEPs.
    > (If it does I would appreciate it if someone could tell me what PEP it  
    > is.)
    
    Already suggested, and rejected; see PEP 363:  
    http://www.python.org/dev/peps/pep-0363/ and the python-dev discussion.
    
    -- 
    Gabriel Genellina
    
    
    
    From lie.1296 at gmail.com  Thu Nov 26 01:44:17 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Thu, 26 Nov 2009 17:44:17 +1100
    Subject: Feature request: String-inferred names
    In-Reply-To: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    Message-ID: <4b0e241f@dnews.tpgi.com.au>
    
    Brad wrote:
    > On Nov 25, 10:49 pm, Chris Rebert  wrote:
    >> On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    >>
    >>  wrote:
    >>> Hello all,
    >>> I just posted to my blog about a feature that I'd like to see added to
    >>> Python. Before I go through the trouble of learning how to write a PEP or
    >>> how to extend the Python interpreter, I want to know what people in the
    >>> community have to say about it.
    >>> http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...
    >>> As far as I know, a feature like this does not appear in any existing PEPs.
    >>> (If it does I would appreciate it if someone could tell me what PEP it is.)
    >>> Please give and comments you may have, but I request that you be
    >>> constructive if you must criticize...thank you!
    >> Ugly, Perlish, and as you even admit, entirely unnecessary.
    >> And you'd need to wait at least a year anyway:http://www.python.org/dev/peps/pep-3003/
    >>
    >> Cheers,
    >> Chris
    >> --http://blog.rebertia.com
    > 
    > Like I said, lots of things in Python are "unnecessary," but that
    > doesn't make them "useless," and it certainly doesn't mean they
    > shouldn't exist. My proposed feature is not useless; I think it would
    > make a lot of code easier.
    
    How is it easier than using dictionary with string as keys? setattr, 
    getattr, and delattr are already sugar for accessing instance.__dict__.
    
    You make a comparison with decorators; even if it's unnecessary it does 
    eliminate a DRY case (don't repeat yourself):
    def foo(self): pass
    foo = property(foo)
    
    there you repeat foo three times unnecessarily, instead of:
    @property
    def foo(self): pass
    
    people already bashed decorator syntax because it is ungoogleable; a 
    non-python programmer reading a python code can't google "python @" to 
    find out that it's a decorator. $ has very similar problem; and we don't 
    want to add more of this wart.
    
    You also make with iterators and generators. Iterator and generator is 
    an implication of the core design of python; because python chose not to 
    have a for-loop (python's "for-loop" is actually a for-each-loop). 
    Without the iterator protocol, it is not possible to make an iterable 
    class and people would have to use "for x in range(len(foo)):" every so 
    often. Iterator protocol also makes it possible to have infinite 
    iterable (e.g. for x in primegenerator(): produces prime numbers 
    indefinitely).
    
    A list comprehension is space saver; it saves a lot of lines for the 
    very common operation:
    
    a = []
    for x in orig:
         if test(x):
             a.append(transform(x))
    
    into one concise line:
    a = [transform(x) for x in orig if test(x)]
    
    Also a generator comprehension can be passed around without being evaluated.
    
    As you see, these "unnecessary features" does have significant benefits 
    to it. Decorators reduced DRY, iterators/generators eliminates the need 
    of range-len for-loop, list comprehension is huge space saver.
    
    The proposed syntax only saves a few character, does not eliminate any 
    DRY, is ungoogleable, and looks confusing to me. Is there any 
    significant benefit from it?
    
    
    From greg.ewing at canterbury.ac.nz  Thu Nov 26 02:04:39 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Thu, 26 Nov 2009 20:04:39 +1300
    Subject: Can "self" crush itself?
    In-Reply-To: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    Message-ID: <7n6nkoF3ki1sfU1@mid.individual.net>
    
    n00m wrote:
    
    > I can't understand why we can get __name__, but not __dict__,
    > on the module level?
    
    For much the same reason that you can see your own
    feet but (unless you look in a mirror) you can't
    see your own eyes.
    
    -- 
    Greg
    
    
    From greg.ewing at canterbury.ac.nz  Thu Nov 26 02:28:06 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Thu, 26 Nov 2009 20:28:06 +1300
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 	
    	
    Message-ID: <7n6p0qF3krjueU1@mid.individual.net>
    
    > On Wed, 25 Nov 2009 20:44:36 -0600, The Music Guy
    >  declaimed the following in
    > gmane.comp.python.general:
    > 
    >>I just posted to my blog about a feature that I'd like to see added to
    >>Python.
    >>
    >>http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    I don't think getattr and setattr are used anywhere near
    frequently enough to justify special syntax.
    
    To warrant having its own synax, a feature needs to be
    used *all the time*. If you find yourself using getattr
    and setattr that much, it's probably a symptom that
    you're abusing namespaces for things that would be
    better done using dictionaries.
    
    (A frequent question asked by newcomers from certain
    other kinds of languages is something like "How do I
    assign to a variable whose name is in another variable?"
    The answer is almost always "Don't do that, use a
    dictionary.")
    
    -- 
    Greg
    
    
    From n00m at narod.ru  Thu Nov 26 03:43:47 2009
    From: n00m at narod.ru (n00m)
    Date: Thu, 26 Nov 2009 00:43:47 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	 
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com> 
    	<7n6nkoF3ki1sfU1@mid.individual.net>
    Message-ID: <5a01852a-8f8c-45b9-83f9-b250bc5ed328@b2g2000yqi.googlegroups.com>
    
    Ok ok
    Of course, it's a local name; -- just my silly slip.
    And seems it belongs to no dict[]...
    Just an internal volatile elf
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Thu Nov 26 03:58:09 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Thu, 26 Nov 2009 09:58:09 +0100
    Subject: Feature request: String-inferred names
    In-Reply-To: <4b0e241f@dnews.tpgi.com.au>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    	<4b0e241f@dnews.tpgi.com.au>
    Message-ID: <4b0e431b$0$30358$426a34cc@news.free.fr>
    
    Lie Ryan a ?crit :
    
    (snip)
     > setattr,  getattr, and delattr are already sugar for accessing 
    instance.__dict__.
    
    They are actually much more than that - else descriptors and inheritance 
    wouldn't work.
    
    
    
    From calidion at gmail.com  Thu Nov 26 04:21:39 2009
    From: calidion at gmail.com (=?Big5?B?p/Wl1aFBpnKkQKTp?=)
    Date: Thu, 26 Nov 2009 01:21:39 -0800 (PST)
    Subject: a question about python
    Message-ID: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com>
    
    hi,
    i have a question on python programming.
    
    let file a.py has a class named a,
      class a():
        __G__ = "1111"
    
    in file b.py i need to insert an attribute __C__ to class a
    
    it would be as if class a defined in file a.py like this:
      class a():
        __G__ = "1111"
        __C__ = "22222"
    
    how this be done in python without inheritance?
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Thu Nov 26 04:45:51 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 09:45:51 GMT
    Subject: a question about python
    References: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com>
    Message-ID: <031e3c24$0$1335$c3e8da3@news.astraweb.com>
    
    On Thu, 26 Nov 2009 01:21:39 -0800, ?????? wrote:
    
    > hi,
    > i have a question on python programming.
    > 
    > let file a.py has a class named a,
    >   class a():
    >     __G__ = "1111"
    
    
    Methods with double leading and trailing underscores are reserved for 
    Python's special use. You should find a different naming convention.
    
    
    > in file b.py i need to insert an attribute __C__ to class a
    > 
    > it would be as if class a defined in file a.py like this:
    >   class a():
    >     __G__ = "1111"
    >     __C__ = "22222"
    > 
    > how this be done in python without inheritance?
    
    
    import a
    a.a.__C__ = "22222"
    
    
    
    -- 
    Steven
    
    
    From calidion at gmail.com  Thu Nov 26 04:57:45 2009
    From: calidion at gmail.com (=?UTF-8?B?5p2O55m977yM5a2X5LiA5pel?=)
    Date: Thu, 26 Nov 2009 01:57:45 -0800 (PST)
    Subject: a question about python
    References: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com> 
    	<031e3c24$0$1335$c3e8da3@news.astraweb.com>
    Message-ID: <0b54b155-9b59-4093-8334-73478c9a030e@g1g2000pra.googlegroups.com>
    
    thanks.
    
    On Nov 26, 5:45?pm, Steven D'Aprano  wrote:
    > On Thu, 26 Nov 2009 01:21:39 -0800, ?????? wrote:
    > > hi,
    > > i have a question on python programming.
    >
    > > let file a.py has a class named a,
    > > ? class a():
    > > ? ? __G__ = "1111"
    >
    > Methods with double leading and trailing underscores are reserved for
    > Python's special use. You should find a different naming convention.
    >
    > > in file b.py i need to insert an attribute __C__ to class a
    >
    > > it would be as if class a defined in file a.py like this:
    > > ? class a():
    > > ? ? __G__ = "1111"
    > > ? ? __C__ = "22222"
    >
    > > how this be done in python without inheritance?
    >
    > import a
    > a.a.__C__ = "22222"
    >
    > --
    > Steven
    
    
    
    From f.guerrieri at gmail.com  Thu Nov 26 05:06:44 2009
    From: f.guerrieri at gmail.com (Francesco Guerrieri)
    Date: Thu, 26 Nov 2009 11:06:44 +0100
    Subject: Can "self" crush itself?
    In-Reply-To: <7n6nkoF3ki1sfU1@mid.individual.net>
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	<7n6nkoF3ki1sfU1@mid.individual.net>
    Message-ID: <79b79e730911260206r4a5041fp4cada7a3e9200ac1@mail.gmail.com>
    
    On Thu, Nov 26, 2009 at 8:04 AM, Gregory Ewing
    wrote:
    
    > n00m wrote:
    >
    >  I can't understand why we can get __name__, but not __dict__,
    >> on the module level?
    >>
    >
    > For much the same reason that you can see your own
    > feet but (unless you look in a mirror) you can't
    > see your own eyes.
    >
    
    
    +1 QOTW
    
    Francesco
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From niklasro at gmail.com  Thu Nov 26 05:38:22 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:38:22 -0800 (PST)
    Subject: IDE+hg
    References: 
    	<75ef83cb-b928-4bf4-b20a-11484a3fdc45@2g2000prl.googlegroups.com>
    Message-ID: 
    
    On Nov 25, 7:28?am, alex23  wrote:
    > NiklasRTZ  wrote:
    > > no py IDE I found has easy hg access.
    >
    > ActiveState's Komodo IDE has support for CVS, Perforce, subversion,
    > bazaar, git and mercurial.
    
    unavailable via synaptic ubuntu karmic repos, presuming its
    commercially bound like wing. Boa constructor, PIDA, Eric, drPython
    are 4 where all should be configurable for obvious reasons + I like
    it.
    thanks for anyway prompt reply my friend
    
    
    From niklasro at gmail.com  Thu Nov 26 05:40:13 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:40:13 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    Message-ID: <1eebb434-f1b5-400f-8256-bb179b3a53f5@f16g2000yqm.googlegroups.com>
    
    On Nov 24, 5:47?pm, "G?nther Dietrich" 
    wrote:
    > NiklasRTZ  wrote:
    > >Since no py IDE I found has easy hg access.
    >
    > Obviously, you didn't try Eclipse with PyDev ()
    > and Mercurial Eclipse ()
    > plugins.
    > This combination is also available stuffed into one package as
    > 'EasyEclipse for Python' ().
    >
    > Both, pure Eclipse with plugins installed by hand, and EasyEclipse, are
    > very convenient for python development.
    >
    > Best regards,
    >
    > G?nther
    
    thank you G?nther for the most common recommendation I get (Eclipse)
    sure for C(++) eclipse works too and Netbeans just that pure python
    obviously closer to this min requirement + fed up with java generally
    here for decades moving all to python
    
    
    From niklasro at gmail.com  Thu Nov 26 05:41:10 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:41:10 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    	
    Message-ID: 
    
    On Nov 24, 4:09?pm, rustom  wrote:
    > On Nov 24, 8:13?pm, Richard Riley  wrote:
    >
    >
    >
    > > Gerhard H?ring  writes:
    > > > Rhodri James wrote:
    > > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > > >>> Dear experts,
    > > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > > >> I don't really understand this urge to cram everything into a single
    > > >> program, since that inevitably leads to compromises that will
    > > >> compromise
    >
    > > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > > merely programmed to hook into the external tools
    >
    > > >> just how much of Mercurial's useful and interesting functionality you
    > > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > > >> to be capable of working with most source control systems.
    >
    > > > I prefer the commandline tools, too.
    >
    > > > FWIW, Eclipse supports Mercurial through
    > > >http://www.vectrace.com/mercurialeclipse/
    >
    > > > -- Gerhard
    >
    > > Why would you prefer the command line tools in a shell when the same
    > > tools can be used in a way which makes navigating the output so much
    > > easier? It strikes me as a kind of intransigence. it's a common
    > > misconception that IDEs use their own tools all the time. They
    > > don't. They integrate the very same tools. e.g Why the hell would I drop
    > > to a command line to diff a file with a back version in GIT when I can
    > > do the same in the buffer in emacs with a single hot key? Why would I
    > > pipe the output of compile into a file then open that file when a single
    > > hot key can fire off the SAME compiler and then list the errors in an
    > > emacs buffer and another hot key can take me directly to the source
    > > lines in question? Living in the past has its mements, but really.
    >
    > > e.g I have pylint working live in python buffers. Big time
    > > saver. Similar with C.
    >
    > I sometimes think that the amount of time I spend tweaking emacs to
    > save my time is more than the time I spend on anything else :-)
    >
    > But more seriously:
    > I tried to use emacs with git recently -- it was a sorry experience.
    > The git.el that comes with git is broken (on windows)
    > vc was too old for git like systems
    > dvc is a joke (its supposedly generic for all Distributed Version
    > Systems -- but everything is couched in terms of tla.
    > TLA! For heavens sake!
    > magit would not run on windows and to use egghttp://github.com/bogolisk/egg
    > I must read magit docs.
    > Finally I decided to stay with what Ive used for the last 25 years --
    > the shell
    
    git is easier via commandline than hg. hg wants gears for simple thing
    ie. hg commit -m wants spec note, too long to type each commit.
    
    
    From paul at boddie.org.uk  Thu Nov 26 06:12:18 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Thu, 26 Nov 2009 03:12:18 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	 
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com> 
    	
    	<24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    	
    Message-ID: <98899688-7712-4f18-b498-d838e91b909c@x31g2000yqx.googlegroups.com>
    
    On 25 Nov, 13:11, Antoine Pitrou  wrote:
    >
    > When you say "executing each kind of bytecode instruction", are you
    > talking about the overhead of bytecode dispatch and operand gathering, or
    > the total cost including doing the useful work?
    
    Strip away any overhead (dispatch, operand gathering) and just measure
    the cumulative time spent doing the actual work for each kind of
    instruction, then calculate the average "cost" by dividing by the
    frequency of each instruction type. So, for a whole program you'd get
    a table of results like this:
    
    LOAD_CONST   
    Left Center Right
    Lists and divs work the same way, and note that attributes are not a problem. From this... div class="spinnable" ul li id="item1" One li id="item2" Two ...you get this:
    • One
    • Two
    You can still use raw HTML tags where appropriate (such as when converting legacy markup to the new style). From this... tr td Hello World!
    ...you get this:
    Hello World!
    And here is the code: import re def convert_text(in_body): ''' Convert HAML-like markup to HTML. Allow raw HTML to fall through. ''' indenter = Indenter() for prefix, line, kind in get_lines(in_body): if kind == 'branch' and '<' not in line: html_block_tag(prefix, line, indenter) else: indenter.add(prefix, line) return indenter.body() def html_block_tag(prefix, line, indenter): ''' Block tags have syntax like this and only apply to branches in indentation: table tr td class="foo" leaf #1 td leaf #2 ''' start_tag = '<%s>' % line end_tag = '' % line.split()[0] indenter.push(prefix, start_tag, end_tag) class Indenter: ''' Example usage: indenter = Indenter() indenter.push('', 'Start', 'End') indenter.push(' ', 'Foo', '/Foo') indenter.add (' ', 'bar') indenter.add (' ', 'yo') print indenter.body() ''' def __init__(self): self.stack = [] self.lines = [] def push(self, prefix, start, end): self.add(prefix, start) self.stack.append((prefix, end)) def add(self, prefix, line): if line: self.pop(prefix) self.insert(prefix, line) def insert(self, prefix, line): self.lines.append(prefix+line) def pop(self, prefix): while self.stack: start_prefix, end = self.stack[-1] if len(prefix) <= len(start_prefix): whitespace_lines = [] while self.lines and self.lines[-1] == '': whitespace_lines.append(self.lines.pop()) self.insert(start_prefix, end) self.lines += whitespace_lines self.stack.pop() else: return def body(self): self.pop('') return '\n'.join(self.lines) def get_lines(in_body): ''' Splits out lines from a file and identifies whether lines are branches, leafs, or blanks. The detection of branches could probably be done in a more elegant way than patching the last non-blank line, but it works. ''' lines = [] last_line = -1 for line in in_body.split('\n'): m = re.match('(\s*)(.*)', line) prefix, line = m.groups() if line: line = line.rstrip() if last_line >= 0: old_prefix, old_line, ignore = lines[last_line] if len(old_prefix) < len(prefix): lines[last_line] = (old_prefix, old_line, 'branch') last_line = len(lines) lines.append((prefix, line, 'leaf')) # leaf for now else: lines.append(('', '', 'blank')) return lines As I mention in the comment for get_lines(), I wonder if there are more elegant ways to deal with the indentation, both of the input and the output. From passionateforchrist at gmail.com Fri Nov 27 22:13:57 2009 From: passionateforchrist at gmail.com (P.F.C.) Date: Fri, 27 Nov 2009 22:13:57 -0500 Subject: Python C API, building a module Message-ID: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> Hello, I'm new to the mailing list but have been using python for a while. I am now attempting to embed the interpreter into a C application but am having an issue when building a module exposing my application's functions to python. I do not know if this is the right place to ask for help with it, if it isn't then please let me know where to go. the problem I'm having is with making a PyMethodDef array When I make the array like this it works: static PyMethodDef ge_methods[]={ {"test",ge_test,METH_NOARGS,"Test returns 123L"}, {NULL,NULL} }; but as soon as I try to build the array from constant variables like this: const int ge_test_args = METH_NOARGS; //The flag for this function const char* ge_test_doc = "Test\nwill print \"test\""; //The docstring static PyMethodDef ge_methods[]={ {"test",ge_test, ge_test_args, ge_test_doc}, //simply replacing the flag and the docstring with a constant variable {NULL,NULL} }; the compiler then gives the following errors: ./test1.c:74: error: initializer element is not constant ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) ./test1.c:74: error: initializer element is not constant ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) I'm using the gcc compiler This may well be because of my lack of understanding the C language but I was hoping someone could help me out, or at least point me in the right direction I also posted about this at http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 Thank you for any help -- Maranatha! --------------------------------- PFC aka Fezzik aka GAB -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Fri Nov 27 22:20:57 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 03:20:57 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: John Bokma wrote: > r0g wrote: > >> It seems gethostbyname asks the OS to resolve the address and the OS >> uses it's own timeout value ( 25 seconds ) rather than the one provided >> in setdefaulttimeout. 25 seconds of blocking is way too long for me, I >> want the response within 5 seconds or not at all but I can see no >> reasonable way to do this without messing with the OS which naturally I >> am loathe to do! > > use signal.alarm(time) to send SIGALRM to your process: > http://docs.python.org/library/signal.html#signal.alarm > See example at bottom. > > John Ahh so close. I set the alarm for 3 seconds and it raises the exception, but only after spending 25 seconds seemingly blocked in gethostbyname. Here's a snippet, just in case I'm doing it wrong!... def dns_timeout(a,b): raise Exception("DNS timeout") def send_one_ping(my_socket, dest_addr, ID): signal.signal(signal.SIGALRM, dns_timeout) signal.alarm(3) try: dest_addr = socket.gethostbyname(dest_addr) except Exception, exc: print "Exception caught:", exc signal.alarm(0) Oh well, even if it doesn't work in this case it's really useful to know about the signal module, I'd never stumbled across it til now, thanks! Roger. From python at mrabarnett.plus.com Fri Nov 27 22:25:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 03:25:15 +0000 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> Message-ID: <4B10981B.4070903@mrabarnett.plus.com> P.F.C. wrote: > Hello, I'm new to the mailing list but have been using python for a while. > > I am now attempting to embed the interpreter into a C application but am > having an issue when building a module exposing my application's > functions to python. > I do not know if this is the right place to ask for help with it, if it > isn't then please let me know where to go. > > the problem I'm having is with making a PyMethodDef array > When I make the array like this it works: > > static PyMethodDef ge_methods[]={ > {"test",ge_test,METH_NOARGS,"Test returns 123L"}, > {NULL,NULL} > }; > > but as soon as I try to build the array from constant variables like this: > > const int ge_test_args = METH_NOARGS; //The flag > for this function > const char* ge_test_doc = "Test\nwill print \"test\""; //The > docstring > static PyMethodDef ge_methods[]={ > {"test",ge_test, ge_test_args, ge_test_doc}, //simply > replacing the flag and the docstring with a constant variable > {NULL,NULL} > }; > > the compiler then gives the following errors: > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) > > I'm using the gcc compiler > > This may well be because of my lack of understanding the C language but > I was hoping someone could help me out, or at least point me in the > right direction > > I also posted about this at > http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 > > I think it's because C 'const' objects aren't true constants, but are more like read-only variables; you can initialise them in the declaration but not assign to them otherwise. Thus what you're actually trying to do is initialise from a variable, not a constant. From passionateforchrist at gmail.com Fri Nov 27 22:41:38 2009 From: passionateforchrist at gmail.com (P.F.C.) Date: Fri, 27 Nov 2009 22:41:38 -0500 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> <4B10981B.4070903@mrabarnett.plus.com> <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> Message-ID: <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> I see what your saying. Is there another way of declaring (at least) the docstring apart from the actual array?(it would get messy otherwise) I had also tried defining the variables as static but got the same result (I thought static meant in code memory instead of the heap...?) I am new to C so I may just be going about this all wrong... -- Maranatha! --------------------------------- PFC aka Fezzik aka GAB On Fri, Nov 27, 2009 at 10:25 PM, MRAB wrote: > P.F.C. wrote: > >> Hello, I'm new to the mailing list but have been using python for a while. >> >> I am now attempting to embed the interpreter into a C application but am >> having an issue when building a module exposing my application's functions >> to python. >> I do not know if this is the right place to ask for help with it, if it >> isn't then please let me know where to go. >> >> the problem I'm having is with making a PyMethodDef array >> When I make the array like this it works: >> >> static PyMethodDef ge_methods[]={ >> {"test",ge_test,METH_NOARGS,"Test returns 123L"}, >> {NULL,NULL} >> }; >> >> but as soon as I try to build the array from constant variables like this: >> >> const int ge_test_args = METH_NOARGS; //The flag for >> this function >> const char* ge_test_doc = "Test\nwill print \"test\""; //The >> docstring >> static PyMethodDef ge_methods[]={ >> {"test",ge_test, ge_test_args, ge_test_doc}, //simply >> replacing the flag and the docstring with a constant variable >> {NULL,NULL} >> }; >> >> the compiler then gives the following errors: >> ./test1.c:74: error: initializer element is not constant >> ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) >> ./test1.c:74: error: initializer element is not constant >> ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) >> >> I'm using the gcc compiler >> >> This may well be because of my lack of understanding the C language but I >> was hoping someone could help me out, or at least point me in the right >> direction >> >> I also posted about this at >> http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 < >> http://talk.christiandevs.com/viewtopic.php?f=13&t=2521> >> >> I think it's because C 'const' objects aren't true constants, but are > more like read-only variables; you can initialise them in the > declaration but not assign to them otherwise. Thus what you're actually > trying to do is initialise from a variable, not a constant. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 84715175 at qq.com Fri Nov 27 22:41:48 2009 From: 84715175 at qq.com (84715175 at qq.com) Date: Fri, 27 Nov 2009 19:41:48 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> Message-ID: <380b0aa5-e651-43a4-8511-c20218b565c3@z4g2000prh.googlegroups.com> On 11?27?, ??4?54?, luca72 wrote: > hello i have a problem > > i have this > > str = 'D3' > and i need to trasform in 0xd3 type int and not type string how i can > do this? > if i do > hex(int(str,16) ) i obtain a string and this is not what i need. > > thanks Luca

    sport jersey sports jersey uggboot nike

    From 84715175 at qq.com Fri Nov 27 22:42:29 2009 From: 84715175 at qq.com (84715175 at qq.com) Date: Fri, 27 Nov 2009 19:42:29 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <87bpioxprk.fsf@benfinney.id.au> Message-ID: <56731260-f284-4ecd-9907-82cc75735882@b25g2000prb.googlegroups.com> On 11?27?, ??6?59?, Marco Mariani wrote: > Ben Finney wrote: > >> i'm using pyscard > > > I don't know what that is; can you give a link to what you're referring > > to? > > Simple story: he has seen the examples with hex literals and didn't know > what they were.

    sport jersey sports jersey uggboot nike

    From cindyqjm at gmail.com Fri Nov 27 22:43:26 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:43:26 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> Message-ID: <5c9bdb00-5ec9-47aa-a7af-ec775b8a69cb@h14g2000pri.googlegroups.com> On 11?27?, ??4?54?, luca72 wrote: > hello i have a problem > > i have this > > str = 'D3' > and i need to trasform in 0xd3 type int and not type string how i can > do this? > if i do > hex(int(str,16) ) i obtain a string and this is not what i need. > > thanks Luca http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Fri Nov 27 22:44:59 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:44:59 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> Message-ID: <383e151a-1f58-45e0-98ab-0b5bf34a563a@g22g2000prf.googlegroups.com> On 11?27?, ??5?35?, "84715... at qq.com" <84715... at qq.com> wrote: > On 11?27?, ??5?28?, luca72 wrote: > > > > > i'm using pyscard > > > and for send a command he need a list like this: > > > cmd = [0xdd,0xff, etc] > > > the problem is that i get a text > > like dd > > and i need to trasform it in 0xdd for the list and if i use hex i have > > a sting that is not what i need > > > Luca > > > On 27 Nov, 10:22, Ben Finney wrote: > > > > luca72 writes: > > > > str = 'D3' > > > > Be careful when choosing names. Here you have clobbered the existing > > > string type binding to the name ?str?. > > > > > and i need to trasform in 0xd3 type int and not type string how i can > > > > do this? > > > > You already have the answer; you used it in your example below. I can > > > only assume you're wanting something additional; what is that? > > > > > if i do hex(int(str,16) ) i obtain a string and this is not what i > > > > need. > > > > You either want it as an int, or you want it as a string. Which is it? > > > > ? ? >>> foo = 'D3' > > > ? ? >>> int(foo, 16) > > > ? ? 211 > > > ? ? >>> 0xD3 > > > ? ? 211 > > > ? ? >>> int(foo, 16) == 0xD3 > > > ? ? True > > > > -- > > > ?\ ? ? ? ? ? ??Human reason is snatching everything to itself, leaving | > > > ? `\ ? ? ? ? ? ? ? ? ? ? nothing for faith.? ?Saint Bernard, 1090?1153 | > > > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > > > Ben Finney- ??????? - > > > - ??????? - > >

    target="sport jersey">sport ? jersey > href="http://www.sport-jersey.net" target="sport > jersey">sports jersey ? title="ugg women" href="http://www.uggwomen.net" target="ugg > women">uggboot ? nike

    - ??????? - > > - ??????? - http://www.enjoyebay.com/ From cindyqjm at gmail.com Fri Nov 27 22:45:53 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:45:53 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <87bpioxprk.fsf@benfinney.id.au> Message-ID: <1f880f64-921e-48cd-95af-7ae1d3df0122@a10g2000pre.googlegroups.com> On 11?27?, ??6?59?, Marco Mariani wrote: > Ben Finney wrote: > >> i'm using pyscard > > > I don't know what that is; can you give a link to what you're referring > > to? > > Simple story: he has seen the examples with hex literals and didn't know > what they were. http://www.mbthome.net/ mbt shoes http://www.nike-airyeezy.com discount nike air yeezy From cindyqjm at gmail.com Fri Nov 27 22:46:47 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:46:47 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <380b0aa5-e651-43a4-8511-c20218b565c3@z4g2000prh.googlegroups.com> Message-ID: On 11?28?, ??11?41?, "84715... at qq.com" <84715... at qq.com> wrote: > On 11?27?, ??4?54?, luca72 wrote: > > > hello i have a problem > > > i have this > > > str = 'D3' > > and i need to trasform in 0xd3 type int and not type string how i can > > do this? > > if i do > > hex(int(str,16) ) i obtain a string and this is not what i need. > > > thanks Luca > >

    target="sport jersey">sport jersey > href="http://www.sport-jersey.net" target="sport > jersey">sports jersey title="ugg women" href="http://www.uggwomen.net" target="ugg > women">uggboot nike

    http://www.mbthome.net/ mbt shoes From python at mrabarnett.plus.com Fri Nov 27 22:58:13 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 03:58:13 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. In-Reply-To: References: Message-ID: <4B109FD5.6040500@mrabarnett.plus.com> r0g wrote: > Hi, > > I'm writing a reliability monitoring app but I've run into a problem. I > was hoping to keep it very simple and single threaded at first but > that's looking unlikely now! The crux of it is this... > > gethostbyname ignores setdefaulttimeout. > > It seems gethostbyname asks the OS to resolve the address and the OS > uses it's own timeout value ( 25 seconds ) rather than the one provided > in setdefaulttimeout. 25 seconds of blocking is way too long for me, I > want the response within 5 seconds or not at all but I can see no > reasonable way to do this without messing with the OS which naturally I > am loathe to do! > > The two ideas I've had so far are... > > Implement a cache. For this to work I'd need to avoid issuing > gethostbyname until the cached address fails. Of course it will fail a > little bit further down i the calling code when the app tries to use it > and I'd then need it to refresh the cache and try again. That seems very > kludgey to me :/ > > A pure python DNS lookup. This seems better but is an unknown quantity. > How big a job is it to use non-blocking sockets to write a DNS lookup > function with a customisable timeout? A few lines? A few hundred? I'd > only need to resolve v4 addresses for the foreseeable. > > Any comments on these strategies, or any suggestions of methods you > think might work better or be a lot easier to implement, warmly received. > How about something like this: def get_host_by_name(hostname, timeout): def proc(): try: q.put(socket.gethostbyname(hostname)) except (socket.gaierror, socket.timeout): pass q = Queue.Queue() t = threading.Thread(target=proc) t.daemon = True t.start() try: return q.get(True, timeout) except Queue.Empty: raise socket.timeout From fearsomedragonfly at gmail.com Fri Nov 27 23:02:31 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 20:02:31 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: <2569860a-797c-413e-a957-8d5f714fc5e8@v30g2000yqm.googlegroups.com> On Nov 26, 9:10?pm, "Gabriel Genellina" wrote: > En Thu, 26 Nov 2009 20:43:04 -0300, The Music Guy ? > escribi?: > > > Nonetheless, the fact remains that the feature I'm proposing closely > > resembles one that has already been rejected... Well, it's been a few > > years since then. Maybe its about time for another PEP to be proposed? > > You'll have to wait a few more years; in case you missed the previous ? > reference to PEP 3003 up in the thread, the language syntax is frozen by ? > now [1] > > [1]http://www.python.org/dev/peps/pep-3003/ > > -- > Gabriel Genellina That PEP seems to pretty clearly state that it applies only to the 3.x branch and not to the 2.x branch. Is there maybe a slim chance of getting my idea added to 2.7, or even 2.8? :D From sisson.j at gmail.com Fri Nov 27 23:05:30 2009 From: sisson.j at gmail.com (J Sisson) Date: Fri, 27 Nov 2009 22:05:30 -0600 Subject: Best strategy for overcoming excessive gethostbyname timeout. In-Reply-To: References: Message-ID: <4297a9020911272005q6c67c7edka3cc2b1f4a9a5d5f@mail.gmail.com> On Fri, Nov 27, 2009 at 9:20 PM, r0g wrote: > Ahh so close. I set the alarm for 3 seconds and it raises the exception, > but only after spending 25 seconds seemingly blocked in gethostbyname. > > Here's a snippet, just in case I'm doing it wrong!... > > If you're doing many lookups prior to connecting to the machines or otherwise processing the information, you can create a very simple thread class to perform just the lookup, store the threads in a list, and poll the threads in the list so you can deal with the ones that finish first before moving on to the remaining ones. You'll still have a 25 second wait for the last ones to finish, but you can get the majority of the work done earlier than you would with a single-thread program. -- Computers are like air conditioners... They quit working when you open Windows. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Fri Nov 27 23:08:10 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 20:08:10 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> Message-ID: <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> Gred, thanks for your comments. On Nov 26, 7:49?pm, Gregory Ewing wrote: > > [...] Also, many of the uses of getattr in the std lib appear > to be of the 3-argument form, which your suggested syntax > doesn't cover. [...] Good point. After excluding those, only ~435 uses would work for my proposed syntax. Still seems fairly significant to me, though. Also, please keep in mind that I never suggested that the get*r functions should be removed from the language precisely because they DO work in ways that my proposed syntax does not, and that removing them would make a lot of existing code fail. For the purpose of the 3- argument form, I would still prefer using getattr or even a defaultdict depending on the task. (For the record, I disagree with the 2-argument form of Ben's proposed syntax; that's confusing and hard to read.) As for your code, I haven't seen it, so it would be hard for me to say exactly how the new syntax would come into play. What I can tell you, however, is that the parts of your code that would use it would probably be easier to read and change to anyone with a firm grasp of the proposed syntax. Quantity of code is definitely important, but I don't want to underwrite the importance of quality, either. Even if only 30 lines of code--rounding down--out of 40,000 would use it, those 40 lines would probably be easier to read and understand. (Off-handedly, you might also find that the availability of the new syntax makes new solutions to some task obvious which previously were not, so the number could rise.) The discussion of PEP 363 presented some good examples of what I'm talking about. Consider this code, which is a paraphrase of code that appeared in the discussion: setattr(obj, ("my_%s" % foo), getattr(obj, ("my_%s" % foo)) + 3) That could be written much more readably as: obj.$("my_%s" % foo) += 3 Or, if you don't like that exact syntax for it, why not any of these: obj.?("my_%s" % foo) += 3 obj.${"my_%s" % foo} += 3 obj.?{"my_%s" % foo} += 3 obj.<"my_%s" % foo> += 3 (and so on) Even if this sort of thing only needed to happen a few times in an entire project, the project as a whole could only benefit from it. My projects rely on a lot of metaclassing for the automatic generation of properties and methods, which saves tremendous amounts of coding. However, the code for the metaclasses is confusing because it relies heavily on the getattr and setattr functions for accessing not only the classes being created but also the instances of those classes. The code for the metaclasses themselves only constitute a small percentage of the overall code for the projects, but that doesn't mean the code doesn't need to be easy to read and understand. Dynamic attribute access via a syntactical construct would be very beneficial for me. Back to PEP 3003, I understand the odds of getting the feature in right now are slim. I get it. But that doesn't mean the idea of the feature is a bad one. There are other things that can be done in the mean time until the moratorium is lifted, like perfecting the syntax and implementation details, or whatever. --Brad Harms From himanshu.garg at gmail.com Fri Nov 27 23:15:44 2009 From: himanshu.garg at gmail.com (++imanshu) Date: Fri, 27 Nov 2009 20:15:44 -0800 (PST) Subject: How to Detect Use of Unassigned(Undefined) Variable(Function) References: <13b9e14f-b8f7-4cc4-90b3-c00087d595d1@b15g2000yqd.googlegroups.com> Message-ID: On Nov 27, 4:06?pm, Marco Mariani wrote: > Jon Clements wrote: > > pychecker returns "test.py:3: No global (o) found" for the above, and > > can be found athttp://pychecker.sourceforge.net/ > > > There's also pylint and another one whose name I can't remember... > > pyflakes. I use that one Thanks for the replies. Was looking for just these. Thank You, ++imanshu From python at mrabarnett.plus.com Fri Nov 27 23:17:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 04:17:17 +0000 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> <4B10981B.4070903@mrabarnett.plus.com> <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> Message-ID: <4B10A44D.2050709@mrabarnett.plus.com> P.F.C. wrote: > I see what your saying. > > Is there another way of declaring (at least) the docstring apart from > the actual array?(it would get messy otherwise) > > I had also tried defining the variables as static but got the same > result (I thought static meant in code memory instead of the heap...?) > > I am new to C so I may just be going about this all wrong... > The standard way of providing documentation strings is with PyDoc_STRVAR: const int ge_test_args = METH_NOARGS; //The flag for this function PyDoc_STRVAR(ge_test_doc, "Test\nwill print \"test\""); //The docstring static PyMethodDef ge_methods[]={ {"test", NULL, 0, ge_test_doc}, //simply replacing the flag and the docstring with a constant variable {NULL,NULL} }; > > -- Maranatha! > --------------------------------- > PFC aka Fezzik aka GAB > > > On Fri, Nov 27, 2009 at 10:25 PM, MRAB > wrote: > > P.F.C. wrote: > > Hello, I'm new to the mailing list but have been using python > for a while. > > I am now attempting to embed the interpreter into a C > application but am having an issue when building a module > exposing my application's functions to python. > I do not know if this is the right place to ask for help with > it, if it isn't then please let me know where to go. > > the problem I'm having is with making a PyMethodDef array > When I make the array like this it works: > > static PyMethodDef ge_methods[]={ > {"test",ge_test,METH_NOARGS,"Test returns 123L"}, > {NULL,NULL} > }; > > but as soon as I try to build the array from constant variables > like this: > > const int ge_test_args = METH_NOARGS; > //The flag for this function > const char* ge_test_doc = "Test\nwill print \"test\""; > //The docstring > static PyMethodDef ge_methods[]={ > {"test",ge_test, ge_test_args, ge_test_doc}, > //simply replacing the flag and the docstring with a constant > variable > {NULL,NULL} > }; > > the compiler then gives the following errors: > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for > ?ge_methods[0].ml_flags?) > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for > ?ge_methods[0].ml_doc?) > > I'm using the gcc compiler > > This may well be because of my lack of understanding the C > language but I was hoping someone could help me out, or at least > point me in the right direction > > I also posted about this at > http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 > > > > > I think it's because C 'const' objects aren't true constants, but are > more like read-only variables; you can initialise them in the > declaration but not assign to them otherwise. Thus what you're actually > trying to do is initialise from a variable, not a constant. > From aioe.org at technicalbloke.com Fri Nov 27 23:20:45 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 04:20:45 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: Gabriel Genellina wrote: > En Fri, 27 Nov 2009 22:35:36 -0300, r0g > escribi?: > >> gethostbyname ignores setdefaulttimeout. >> >> How big a job is it to use non-blocking sockets to write a DNS lookup >> function with a customisable timeout? A few lines? A few hundred? I'd >> only need to resolve v4 addresses for the foreseeable. > > This guy reports good results using GNU adns to perform asynchronous > queries: > http://www.catonmat.net/blog/asynchronous-dns-resolution/ > > Also, look for pydns. Don't be afraid of its age; it always worked fine > for me. > Thanks Gabriel, that worked a treat when combined with John's SIGALARM solution :) For posterity here's the code... import signal, socket try: import DNS except: DNS = False def DNSResolve( s ): if DNS: DNS.ParseResolvConf() # Windows? r = DNS.DnsRequest(name=s,qtype='A') a = r.req() return a.answers[0]['data'] else: return socket.gethostbyname( s ) def dns_timeout(a,b): raise Exception("Oh Noes! a DNS lookup timeout!") def canIHasIP( domain_name, timeout=3 ): signal.signal(signal.SIGALRM, dns_timeout) signal.alarm( timeout ) try: ip = DNSResolve( domain_name ) except Exception, exc: print exc return False signal.alarm(0) return ip usage: canIHasIP( domain_name, timeout_in_seconds) i.e. canIHasIP("google.com",5) Thanks guys! :D Roger. From enkidu.com at com.cliffp.com Fri Nov 27 23:25:54 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 17:25:54 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <87ocmnv1gt.fsf@benfinney.id.au> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> Message-ID: <4b10a652$1@news2.actrix.gen.nz> Ben Finney wrote: > Enkidu writes: > >> Heh! Maybe a little sleep-deprived, but I didn't realise that the >> original post was cross-posted to comp.lang.python. If I'd purposely >> posted it to CLP it *would* have been a stupid troll. I did it by >> accident, and apologise for doing so. > > Oh, so trash-talking in *other* forums where you feel safe from being > caught is okay? ;-) > I take your point, but the other group in question is a 'local' group. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From ldo at geek-central.gen.new_zealand Fri Nov 27 23:44:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 28 Nov 2009 17:44:53 +1300 Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: In message <486869af-d89f-4261-b4c2- f45af5d3bb93 at e7g2000vbi.googlegroups.com>, r wrote: > I find the syntax far to[o] complicated than it should be. That?s because it was originally written for Java programmers. From rt8396 at gmail.com Sat Nov 28 00:33:51 2009 From: rt8396 at gmail.com (r) Date: Fri, 27 Nov 2009 21:33:51 -0800 (PST) Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: <93d1cd57-5dce-4cc8-915d-5e9c33f3fdda@s31g2000yqs.googlegroups.com> On Nov 27, 10:44?pm, Lawrence D'Oliveiro wrote: > In message <486869af-d89f-4261-b4c2- > > f45af5d3b... at e7g2000vbi.googlegroups.com>, r wrote: > > I find the syntax far to[o] complicated than it should be. > > That?s because it was originally written for Java programmers. Well that explains the high level of asininity alright! ;-) From david at bibliolabs.com Sat Nov 28 00:56:37 2009 From: david at bibliolabs.com (David Williams) Date: Fri, 27 Nov 2009 23:56:37 -0600 (CST) Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: <59374.68.58.172.242.1259387797.squirrel@www.bibliobazaar.com> You might want to take a look at this: http://www.ghrml.org/ David > Python has this really neat idea called indentation-based syntax, and > there are folks that have caught on to this idea in the HTML > community. > > AFAIK the most popular indentation-based solution for generating HTML > is a tool called HAML, which actually is written in Ruby. > > I have been poking around with the HAML concepts in Python, with the > specific goal of integrating with Django. But before releasing that, > I thought it would be useful to post code that distills the basic > concept with no assumptions about your target renderer. I hope it > also serves as a good example of what you can do in exactly 100 lines > of Python code. > > Here is what it does... > > You can use indentation syntax for HTML tags like table. > > From this... > > table > tr > td > Left > td > Center > td > Right > > ...you get this: > > > > > > > >
    > Left > > Center > > Right >
    > > Lists and divs work the same way, and note that attributes are not > a problem. > > From this... > > div class="spinnable" > ul > li id="item1" > One > li id="item2" > Two > > ...you get this: > >
    >
      >
    • > One >
    • >
    • > Two >
    • >
    >
    > > You can still use raw HTML tags where appropriate (such as when > converting > legacy markup to the new style). > > From this... > > > tr > td > Hello World! >
    > > ...you get this: > > > > > >
    > Hello World! >
    > > And here is the code: > > import re > > def convert_text(in_body): > ''' > Convert HAML-like markup to HTML. Allow raw HTML to > fall through. > ''' > indenter = Indenter() > for prefix, line, kind in get_lines(in_body): > if kind == 'branch' and '<' not in line: > html_block_tag(prefix, line, indenter) > else: > indenter.add(prefix, line) > return indenter.body() > > > def html_block_tag(prefix, line, indenter): > ''' > Block tags have syntax like this and only > apply to branches in indentation: > > table > tr > td class="foo" > leaf #1 > td > leaf #2 > ''' > start_tag = '<%s>' % line > end_tag = '' % line.split()[0] > indenter.push(prefix, start_tag, end_tag) > > > class Indenter: > ''' > Example usage: > > indenter = Indenter() > indenter.push('', 'Start', 'End') > indenter.push(' ', 'Foo', '/Foo') > indenter.add (' ', 'bar') > indenter.add (' ', 'yo') > print indenter.body() > ''' > def __init__(self): > self.stack = [] > self.lines = [] > > def push(self, prefix, start, end): > self.add(prefix, start) > self.stack.append((prefix, end)) > > def add(self, prefix, line): > if line: > self.pop(prefix) > self.insert(prefix, line) > > def insert(self, prefix, line): > self.lines.append(prefix+line) > > def pop(self, prefix): > while self.stack: > start_prefix, end = self.stack[-1] > if len(prefix) <= len(start_prefix): > whitespace_lines = [] > while self.lines and self.lines[-1] == '': > whitespace_lines.append(self.lines.pop()) > self.insert(start_prefix, end) > self.lines += whitespace_lines > self.stack.pop() > else: > return > > def body(self): > self.pop('') > return '\n'.join(self.lines) > > def get_lines(in_body): > ''' > Splits out lines from a file and identifies whether lines > are branches, leafs, or blanks. The detection of branches > could probably be done in a more elegant way than patching > the last non-blank line, but it works. > ''' > lines = [] > last_line = -1 > for line in in_body.split('\n'): > m = re.match('(\s*)(.*)', line) > prefix, line = m.groups() > if line: > line = line.rstrip() > if last_line >= 0: > old_prefix, old_line, ignore = lines[last_line] > if len(old_prefix) < len(prefix): > lines[last_line] = (old_prefix, old_line, > 'branch') > last_line = len(lines) > lines.append((prefix, line, 'leaf')) # leaf for now > else: > lines.append(('', '', 'blank')) > return lines > > As I mention in the comment for get_lines(), I wonder if there are > more elegant ways to deal with the indentation, both of the input and > the output. > > -- > http://mail.python.org/mailman/listinfo/python-list > From showell30 at yahoo.com Sat Nov 28 01:32:56 2009 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 27 Nov 2009 22:32:56 -0800 (PST) Subject: a 100-line indentation-based preprocessor for HTML References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> On Nov 27, 9:56?pm, "David Williams" wrote: > You might want to take a look at this: > > http://www.ghrml.org/ > Yep, it's not clear how actively they are maintaining that. The fact that it seems to target Genshi only might be limiting their audience, which is unfortunate. From moijes12 at gmail.com Sat Nov 28 02:09:06 2009 From: moijes12 at gmail.com (moijes12) Date: Fri, 27 Nov 2009 23:09:06 -0800 (PST) Subject: need clarification on -0 Message-ID: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Hi I know the value -0 is quite meaningless and makes little sense.But I was just fiddling.I am unable to figure out the below result >>> -0 and True 0 ----------> (Why is this 0 and not say True or False) >>> -0 and false 0 >>> -0 or True True Could someone please provide me some resources on how these operations take place.I'd wanna find it out myself Thanks moijes From subhakolkata1234 at gmail.com Sat Nov 28 02:20:17 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 23:20:17 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> On Nov 28, 5:35?am, Steven D'Aprano wrote: > On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > > Dear Group, > > > I have written a small and simple program like the following: > > > def alphabet1(n): > > ? ? file_open=open("/python26/alphabetlist1.txt","r") > > ? ? file_read=file_open.read() > > ? ? file_word=file_read.split() > > ? ? print file_word > > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > > splitting them into words. > > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > > following: > > > a A > > b B > > c C > > d D > > E e > > F f > > > Where, a/b/c/d/e/f are in ?lower case and A/B/C/D/E/F are in upper case > > which I can say as > > SHIFT+a > > SHIFT+b > > SHIFT+c > > SHIFT+d > > SHIFT+e > > SHIFT+f > > > Now, in the list or anywhere in the program if I want to write > > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > > may feel not only cut/copy/paste. > > > How would I represent them? > > This question is badly defined. What are your constraints? Is this meant > to be a human-readable program? If so, you need to stick to ASCII text > and probably want something like: > > a A CTRL-A ALT-A > b B CTRL-B ALT-B > ... > > but I'm not sure what the point of that would be. > > Normally, control-combinations generate control-characters. For example, > CTRL-M would normally generate a carriage-return character. Depending on > your needs, you can write this as any of the following: > > a description: CTRL-M > an escape sequence: \r > caret notation: ^M > the standard abbreviation: CR > the Unicode display glyph: ? > or an actual carriage-return character. > > Note that in ASCII control characters only have a standard definition for > the following: > > ctrl-@ > ctrl-A through ctrl-Z > ctrl-[ > ctrl-\ > ctrl-] > ctrl-^ > ctrl-_ > ctrl-? > > See here for more:http://en.wikipedia.org/wiki/Control_characters > > As for Alt-combinations, I don't think there is any standard for what > they are. I believe that they are operating system specific, and possibly > even program specific. > > -- > Steven- Hide quoted text - > > - Show quoted text - Dear Sir, I was writing a transliteration program from Bengali to English and vice versa. The program using Unicode chart is giving me perfect outputs in Bengali and vice versa with Bengali input -> English. I wanted to add some more power to the key board entry scheme, as I have developed few fonts also and now trying to work out a windows based word processor in Bengali. Thank you for your kind answer. It helped me lot. ALT portion I'll work out on my own. Sorry for a wrongly given problem statement. Wishing you a happy day ahead, Regards, Subhabrata. From subhakolkata1234 at gmail.com Sat Nov 28 02:30:00 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 23:30:00 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> On Nov 28, 5:35?am, Steven D'Aprano wrote: > On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > > Dear Group, > > > I have written a small and simple program like the following: > > > def alphabet1(n): > > ? ? file_open=open("/python26/alphabetlist1.txt","r") > > ? ? file_read=file_open.read() > > ? ? file_word=file_read.split() > > ? ? print file_word > > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > > splitting them into words. > > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > > following: > > > a A > > b B > > c C > > d D > > E e > > F f > > > Where, a/b/c/d/e/f are in ?lower case and A/B/C/D/E/F are in upper case > > which I can say as > > SHIFT+a > > SHIFT+b > > SHIFT+c > > SHIFT+d > > SHIFT+e > > SHIFT+f > > > Now, in the list or anywhere in the program if I want to write > > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > > may feel not only cut/copy/paste. > > > How would I represent them? > > This question is badly defined. What are your constraints? Is this meant > to be a human-readable program? If so, you need to stick to ASCII text > and probably want something like: > > a A CTRL-A ALT-A > b B CTRL-B ALT-B > ... > > but I'm not sure what the point of that would be. > > Normally, control-combinations generate control-characters. For example, > CTRL-M would normally generate a carriage-return character. Depending on > your needs, you can write this as any of the following: > > a description: CTRL-M > an escape sequence: \r > caret notation: ^M > the standard abbreviation: CR > the Unicode display glyph: ? > or an actual carriage-return character. > > Note that in ASCII control characters only have a standard definition for > the following: > > ctrl-@ > ctrl-A through ctrl-Z > ctrl-[ > ctrl-\ > ctrl-] > ctrl-^ > ctrl-_ > ctrl-? > > See here for more:http://en.wikipedia.org/wiki/Control_characters > > As for Alt-combinations, I don't think there is any standard for what > they are. I believe that they are operating system specific, and possibly > even program specific. > > -- > Steven- Hide quoted text - > > - Show quoted text - It seems the following site: http://knopok.net/symbol-codes/alt-codes is quite resourceful on Alt. Regards, Subhabrata. From aioe.org at technicalbloke.com Sat Nov 28 02:46:42 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 07:46:42 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > Gabriel Genellina wrote: >> En Fri, 27 Nov 2009 22:35:36 -0300, r0g >> escribi?: >> >>> gethostbyname ignores setdefaulttimeout. >>> >>> How big a job is it to use non-blocking sockets to write a DNS lookup >>> function with a customisable timeout? A few lines? A few hundred? I'd As usual, everything is working beautifully until I try to make it work with windows! Turns out signals.SIGALRM is Unix only and I want to run on both platforms so I have done as the docs suggested and tried to convert the code to use threading.Timer to trigger an exception if the DNS lookup is taking too long. It's behaviour seems quite odd. The exception is raised on schedule after a couple of seconds and appears in the terminal (despite me not printing it to the terminal!). There's then a pause of nearly 30 seconds before the try/except catches it and proceeds as normal. I can see no reason for a delay between the error being raised and caught, unless whatever it's trying to interrupt is blocking, in which case it shouldn't have been interrupted by the signal either no? So anyway my questions are... Why the error message and can it be suppressed? Why the 30 second delay, what's it doing during that time? Code... timeout_timer = threading.Timer(DNS_TIMEOUT, dns_timeout) timeout_timer.start() try: dest_addr = DNSResolve( dest_addr ) except Exception: print "Caught an exception, returning False" try: timeout_timer.cancel() except: None return False Other code as before. On the face of it it looks like it might be dwelling in the .req() method of the pydns library but it can get confusing quickly with threading so I'm far from sure. On top of that I'm not sure if my threads are dying and being cleared up properly. Each Exception I raise shows the Thread number getting higher e.g. "Exception in thread Thread-8:". Do I need to be doing anything to clear these up or does Python just use a monotonic counter for thread names? Is there a less messy way to use signals on both Unix and Windows? The docs seem to suggest they've kludged the signals module into a workable form most platforms but on XP I get 'module' object has no attribute 'SIGALRM' :( Roger. From max at alcyone.com Sat Nov 28 02:55:18 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 27 Nov 2009 23:55:18 -0800 Subject: need clarification on -0 In-Reply-To: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <_tSdnUzUUfz7So3WnZ2dnUVZ_rZi4p2d@giganews.com> moijes12 wrote: > I know the value -0 is quite meaningless and makes little sense.But I > was just fiddling.I am unable to figure out the below result > >>>> -0 and True > 0 ----------> (Why is this 0 and not say True or False) >>>> -0 and false > 0 >>>> -0 or True > True > > Could someone please provide me some resources on how these operations > take place.I'd wanna find it out myself Your questions have nothing to do with -0, as it's no different from 0: >>> 0 == -0 True Your examples work the same way with simply 0, which is considered a false value: >>> bool(0) False >>> 0 and True 0 >>> 0 and False 0 >>> 0 or True True What you're seeing is simply the short-circuiting behavior of the `and` and `or` operators; they return the last (relevant) value they encountered before making their determination of the value of the overall expressions. See python.org/doc for more information. -- 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/Skype erikmaxfrancis You'll survive / A true Darwin star -- Des'ree From moijes12 at gmail.com Sat Nov 28 03:45:08 2009 From: moijes12 at gmail.com (moijes12) Date: Sat, 28 Nov 2009 00:45:08 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <_tSdnUzUUfz7So3WnZ2dnUVZ_rZi4p2d@giganews.com> Message-ID: <803a1fbe-f793-4625-89e2-08830577e35e@k13g2000prh.googlegroups.com> On Nov 28, 12:55?pm, Erik Max Francis wrote: > moijes12 wrote: > > I know the value -0 is quite meaningless and makes little sense.But I > > was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > > 0 ----------> (Why is this 0 and not say True or False) > >>>> -0 and false > > 0 > >>>> -0 or True > > True > > > Could someone please provide me some resources on how these operations > > take place.I'd wanna find it out myself > > Your questions have nothing to do with -0, as it's no different from 0: > > ?>>> 0 == -0 > True > > Your examples work the same way with simply 0, which is considered a > false value: > > ?>>> bool(0) > False > ?>>> 0 and True > 0 > ?>>> 0 and False > 0 > ?>>> 0 or True > True > > What you're seeing is simply the short-circuiting behavior of the `and` > and `or` operators; they return the last (relevant) value they > encountered before making their determination of the value of the > overall expressions. ?See python.org/doc for more information. > > -- > Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/ > ? San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis > ? ?You'll survive / A true Darwin star > ? ? -- Des'ree Thanks Erik From lie.1296 at gmail.com Sat Nov 28 04:07:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 20:07:27 +1100 Subject: Feature request: String-inferred names In-Reply-To: <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> Message-ID: <4b10e8b3@dnews.tpgi.com.au> On 11/28/2009 3:08 PM, The Music Guy wrote: > As for your code, I haven't seen it, so it would be hard for me to say > exactly how the new syntax would come into play. What I can tell you, > however, is that the parts of your code that would use it would > probably be easier to read and change to anyone with a firm grasp of > the proposed syntax. Isn't this much easier to read and grasp? obj.d["my_%s" % foo] += 3 doesn't need new syntax as well. > Even if this sort of thing only needed to happen a few times in an > entire project, the project as a whole could only benefit from it. My > projects rely on a lot of metaclassing for the automatic generation of > properties and methods, which saves tremendous amounts of coding. If you use it a lot, it is likely 1) you have abused class syntax for what should have been a dict or 2) what you need is to override __getattr__/__getattribute__ and __setattr__ From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 04:18:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 09:18:17 GMT Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <009a6f50$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 23:09:06 -0800, moijes12 wrote: > Hi > > I know the value -0 is quite meaningless and makes little sense. Actually, when it comes to floating point values, it is very useful to be able to distinguish between -0 and +0. > But I > was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > 0 ----------> (Why is this 0 and not say True or False) You need to know two things about Python: (1) All values can be interpreted in a boolean context: if None: print "this will never be printed" else: print "this is always printed" False values include: None, 0, 0.0, "", [], {} and of course False. True values include nearly everything else. (2) `and` and `or` are short-cut operators. They return the first argument which unambiguously defines the result: X and Y => X if X is a false value, and Y if X is a true value. X or Y => X if X is a true value, and Y if X is a false value. Why do `and` and `or` return objects other than True and False? This is especially useful when using `or` in situations like this: process(main_list or fallback_list) which will process the first list of the two which is not empty. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 04:19:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 09:19:53 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <2569860a-797c-413e-a957-8d5f714fc5e8@v30g2000yqm.googlegroups.com> Message-ID: <009a6fb0$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 20:02:31 -0800, The Music Guy wrote: > That PEP seems to pretty clearly state that it applies only to the 3.x > branch and not to the 2.x branch. Is there maybe a slim chance of > getting my idea added to 2.7, or even 2.8? :D The only new features being added to 2.7 are features which are also being added to 3.x. There is no chance at all of having new features added to 2.7 which isn't added to 3, unless that feature is specifically to make it easier to migrate from 2 to 3. -- Steven From lie.1296 at gmail.com Sat Nov 28 04:22:10 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 20:22:10 +1100 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> Message-ID: <4b10ec28@dnews.tpgi.com.au> On 11/28/2009 6:20 PM, joy99 wrote: > I was writing a transliteration program from Bengali to English and > vice versa. The program using Unicode chart is giving me perfect > outputs in Bengali and vice versa with Bengali input -> English. > I wanted to add some more power to the key board entry scheme, as I > have developed few fonts also and now trying to work out a windows > based word processor in Bengali. > Thank you for your kind answer. > It helped me lot. > ALT portion I'll work out on my own. > Sorry for a wrongly given problem statement. > Wishing you a happy day ahead, > Regards, > Subhabrata. If I haven't misunderstood you, you want to capture keyboard input involving the CTRL and ALT key, am I correct? Getting keyboard input with modifier keys depends on your GUI widgets. Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? From vinay_sajip at yahoo.co.uk Sat Nov 28 04:26:28 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 28 Nov 2009 01:26:28 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> Message-ID: <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> On Nov 27, 1:11?pm, Grimsqueaker wrote: > When I add a Filter to a Handler, everything works as expected (ie. > all messages sent from Loggers below the Filter's level are allowed > through), but when I add the Filter directly on to the Logger, only > that Logger is blocked, regardless of the contents of the Filter. The key thing to remember is that when a logger processes an event, handlers attached to it *and all its parents* are offered the event for handling. In the case where you have just one handler and it has the filter attached, filtering works as you expected. By attaching the filter to the root logger, you are not filtering its handler; this handler is invoked for events logged to all the other loggers, and so (apart from the event at the root logger) those events are not filtered. For some examples of filter usage, see this post: http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 Regards, Vinay Sajip From jabronson at gmail.com Sat Nov 28 04:30:44 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Sat, 28 Nov 2009 01:30:44 -0800 (PST) Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: On Nov 27, 9:36?pm, "Gabriel Genellina" wrote: > En Fri, 27 Nov 2009 15:12:36 -0300, Francis Carr ? > escribi?: > > > I was really inspired by this discussion thread! :-) > > > After much tinkering, I think I have a simpler solution. ?Just make > > the inverse mapping accessible via an attribute, -AND- bind the > > inverse of -THAT- mapping back to the original. ?The result is a > > python dict with NO NEW METHODS except this inverse-mapping > > attribute. ?I have posted it on code.activestate.com as > href="http://code.activestate.com/recipes/576968/">Recipe 576968: > > Flipdict -- python dict that also maintains a one-to-one inverse > > mapping > > Nice idea! Indeed! Thanks for sharing! I liked this so much I added something similar in http://bitbucket.org/jab/toys/src/tip/bidict.py (I made the inverse available via a .inv property, as well as via the unary ~ operator (by analogy to bitwise inverse)). I also got rid of getinv, popinv, et al. to keep the API leaner as you recommend. I've kept the slice syntax though as well as namedbidect, so for now I guess I'm allowing for many ways to skin this cat. > Just a couple of comments: > > Instead of: > ? ? ? ? self._flip = dict.__new__(self.__class__) > I'd write: > ? ? ? ? self._flip = self.__class__() > unless I'm missing something (but see the next point). How would this not cause infinite recursion? > Also, although Python's GC is able to handle them, I prefer to avoid ? > circular references like those between x and x._flip. ?Making self._flip a ? > weak reference (and dereferencing it in the property) should be enough. If both self._flip and self._flip._flip are weak references, no strong references to the inverse mapping survive leaving the constructor scope. Unless I'm missing something, only one of these can be a weak reference, and then you'd have to do something like this in the property to prevent "TypeError: FlipDict is not callable": @property def flip(self): try: # we're an inverse, self._flip is a weak reference return self._flip() except TypeError: # we're a forward mapping, self._flip is a strong reference return self._flip From paul.nospam at rudin.co.uk Sat Nov 28 05:14:39 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 28 Nov 2009 10:14:39 +0000 Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: <87k4xbrm5s.fsf@rudin.co.uk> r writes: > On Nov 23, 4:49?am, Gerhard H?ring wrote: >> Is there a *simple* way to read OpenOffice spreadsheets? >> >> Bonus: write them, too? >> >> I mean something like: >> >> doc.cells[0][0] = "foo" >> doc.save("xyz.ods") >> >> >From a quick look, pyodf offers little more than just using a XML parser > > > I find the syntax far to complicated than it should be. Here is an > example just to insert some text.. [employing weapons of mass snippage] It's true that it's a hassle, but the boiler plate stuff can be stuck in a function and then forgotton about really. From lucaberto at libero.it Sat Nov 28 05:29:11 2009 From: lucaberto at libero.it (luca72) Date: Sat, 28 Nov 2009 02:29:11 -0800 (PST) Subject: dvb3 Message-ID: hello i try to use the python-dvb3 bindings, but i have some problem: fe = dvb3.frontend.Frontend(0) type = tipo_1 = fe.get_dvbtype() now i need to set the parameters parametri = dvb3.frontend.QPSKParameters(frequency=frequency, inversion=2 , symbol_rate=27500, fec_inner=9) but when i use fe.set_frontend(parametri) i get the error The debugged program raised the exception IOError "(22, 'Invalid argument')" File: frontend.pyx, Line: 364 thedef is as follow : def set_frontend(self, parameters): global cfrontend cdef cfrontend.dvb_frontend_parameters p if pack_parameters(&p, parameters) == 0: raise ParameterError, "Incorrect parameter type" if ioctl(self.fd, cfrontend.FE_SET_FRONTEND, &p) == -1: raise_ioerror() can you hel me Luca From threaderslash at gmail.com Sat Nov 28 05:38:04 2009 From: threaderslash at gmail.com (Threader Slash) Date: Sat, 28 Nov 2009 21:38:04 +1100 Subject: Python MySQL: clean multiple foreign keys table Message-ID: Hi Everybody, I am working with Python MySQL, and need to clean a table in my database that has 13328 rows. I can not make a simple drop table, because this table is child and also father of other child foreign-keys linked on it. If I try drop table, the system forbidden me. The table is defined with ON UPDATE CASCADE, ON DELETE CASCADE and InnoDB; The primary_key index to that table is defined as productID INT(6) NOT NULL AUTO_INCREMENT ... PRIMARY KEY (productID,productNO) Therefore, I just have to clean; this will automatically restore the table primary key index to 1 for the next input. Right? This procedure worked fine for another table that was a father table, but not also a father and child table. But, for this table, which is child and father of other tables, I got stuck on it. Here is the code - productID is my primary index key to this table: def clean_tableProduct(self): getMaxID_MySQLQuery = """SELECT MAX(productID) FROM product;""" cleanTabeMySQLQuery="""DELETE FROM product WHERE productID <=%s;""" self.cursorMySQL.execute(getMaxID_MySQLQuery) for row in self.cursorMySQL: self.cursorMySQL.execute(cleanTabeMySQLQuery,(row[0],)) If I go to the MySQL console to check the processing results, it gets me: mysql> SELECT MIN(productID) FROM product; 4615748 mysql> SELECT MAX(productID) FROM product; 4629075 If I run the same command on console to clean the table, it works: mysql> DELETE FROM product WHERE productID <='4629075'; Query OK, 13328 rows affected (0.64 sec) and shows me what I would normally expect. However, if I go to Python function after having cleaned the table on console, and run the program again, and clean the table to restart the processing, it restarts the table index not with MIN:1, but instead 4629076. Any suggestion? All comments and suggestions are highly appreciated and welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From subhakolkata1234 at gmail.com Sat Nov 28 05:39:43 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 28 Nov 2009 02:39:43 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> <4b10ec28@dnews.tpgi.com.au> Message-ID: On Nov 28, 2:22?pm, Lie Ryan wrote: > On 11/28/2009 6:20 PM, joy99 wrote: > > > I was writing a transliteration program from Bengali to English and > > vice versa. The program using Unicode chart is giving me perfect > > outputs in Bengali and vice versa with Bengali input -> ?English. > > I wanted to add some more power to the key board entry scheme, as I > > have developed few fonts also and now trying to work out a windows > > based word processor in Bengali. > > Thank you for your kind answer. > > It helped me lot. > > ALT portion I'll work out on my own. > > Sorry for a wrongly given problem statement. > > Wishing you a happy day ahead, > > Regards, > > Subhabrata. > > If I haven't misunderstood you, you want to capture keyboard input > involving the CTRL and ALT key, am I correct? > > Getting keyboard input with modifier keys depends on your GUI widgets. > Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? You are very right. I am using IDLE on WinXP and for building GUI- TKinter. From tjreedy at udel.edu Sat Nov 28 05:41:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Nov 2009 05:41:46 -0500 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <4b10a652$1@news2.actrix.gen.nz> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> <4b10a652$1@news2.actrix.gen.nz> Message-ID: Enkidu wrote: > Ben Finney wrote: > >> Oh, so trash-talking in *other* forums where you feel safe from being >> caught is okay? ;-) >> > I take your point, but the other group in question is a 'local' group. I think he intended to mean that it was a local group where trash-talking and stupid comments are the norm. From ben+python at benfinney.id.au Sat Nov 28 06:11:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 22:11:12 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> <4b10a652$1@news2.actrix.gen.nz> Message-ID: <87tyweucof.fsf@benfinney.id.au> Terry Reedy writes: > Enkidu wrote: > > Ben Finney wrote: > >> Oh, so trash-talking in *other* forums where you feel safe from > >> being caught is okay? ;-) > >> > > I take your point, but the other group in question is a 'local' > > group. > > I think he intended to mean that it was a local group where > trash-talking and stupid comments are the norm. Well no, I'm not passing any comment on the group. Merely that trash-talk isn't made any more acceptable just because the target of the trash-talk isn't present to hear it. But more importantly, my comment was intended as a pleasant jibe (hence the smiley), not a severe admonishment. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we give peas a chance, won't the lima beans feel | _o__) left out?? ?_Pinky and The Brain_ | Ben Finney From fearsomedragonfly at gmail.com Sat Nov 28 06:38:38 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 03:38:38 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: On Nov 28, 3:07?am, Lie Ryan wrote: > On 11/28/2009 3:08 PM, The Music Guy wrote: > > > As for your code, I haven't seen it, so it would be hard for me to say > > exactly how the new syntax would come into play. What I can tell you, > > however, is that the parts of your code that would use it would > > probably be easier to read and change to anyone with a firm grasp of > > the proposed syntax. > > Isn't this much easier to read and grasp? > > obj.d["my_%s" % foo] += 3 > > doesn't need new syntax as well. Actually, that's similar to my backup solution, which is a variant of the "attrs" class that PEP 363 provides. It does make things easier to read, but a new syntax would still be better because: 1.) A new syntax would apply to _everything_ as it would be a hook to the very mechanism that gets the value of a member from an object and does not rely on an object defining the magic "d" property. I suppose you could argue that an enhancement could be made to the language that says that all objects must define the magic "d" (so the builins "object" and "type" would have to define it). That also has the added benefit of not conflicting with PEP 3003, which says it is fine to add new methods (and I would assume properties as well) to existing classes. 2.) Ben's patch for his proposed syntax generated an aproximate 1% performance hit for the interpreter overall versus a >40% increase where code that used the getattr/settattr functions was modified to use the proposed syntax. The magic "d" MIGHT have a performance increase over the getattr/setattr functions, but a syntax would still be significantly faster because there would be less function dereferencing/calling. For the purposes that I had intended for the syntax to be used, that would definitely matter. > If you use it a lot, it is likely 1) you have abused class syntax for > what should have been a dict or 2) what you need is to override > __getattr__/__getattribute__ and __setattr__ Oh boy...here we go. :| Please listen. In all the time I've spent in the coding community (that's at least 7 years) and especially since I started paying attention to the Python community (2 years), I have noticed a trend: When one coder does something that another cannot understand, frequently the other will assume the former is not only doing things wrong, but is doing them _blatantly_ wrong. I have caught myself making that very assumption many times in the past, and I've tried hard to build up an immunity against the impulse to make that assumption. At this point, I don't even believe in such a thing as a universal "wrong way" and a "right way" to code that applies to every circumstance. The way to solve a problem depends on the problem. When it comes to coding, there is not an absolute "right" way or "wrong" way--unless we're talking about, say, stealing closed source code without permission, or deliberately coding in a way that will cause problems for the end user (like causing memory clogs or buffer overflows and whatnot). All of this can be determined through common sense. And yet I continue to see the attitude of "my solution is the ONLY solution to your problem, and it doesn't matter if I don't even actually understand the problem." Not everyone does this, but it is a frequent enough occurence to be worth noting. If I had to pull a number out of my magic bag, I would say 4 out of 10 resposes have at least a hint of this attitude, and 2.5/10 where it is very obvious. But I digress. I've already gone over other possible solutions and the one I am using seems to fit the bill better than any other yet presented to me, including the ones you just suggested. In fact, I'm fairly certain that __getattr__ and friends even apply to the situation, or if they do, they're certainly inferior alternatives to the use of getattr/setattr. Not that I'm calling you inferior--I'm just saying that if you had a better understanding of the problem you would not see __getatrr__ et al. as parts of a possible solution because they don't really make logical sense given the circumstances. ...and I have one last thing to say. I feel very strongly that metaclassing is a fiercely underestimated and largely untapped source of good coding solutions. I hope that many coders will see this and help to make it more adoptable by the masses; at present it is seen as a big, scary beast that is hard to tame and even harder to drive. It is portrayed as something dangerous that should only be used in relatively rare situations. I disagree with this view. It is the view itself which makes it seem so dangerous (in other words, it is self- perpetuating). Well, that's about enough yakking for 5:30 in the morning...time to give my noggin a rest. -- Brad Harms From fearsomedragonfly at gmail.com Sat Nov 28 06:44:50 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 03:44:50 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <239496b3-36bc-4e9e-a364-d8c5fc64a968@e27g2000yqd.googlegroups.com> P.S., not trying to start a flame war. It's just that I can't stand to keep silent on the matter any longer. -- Brad Harms From lie.1296 at gmail.com Sat Nov 28 07:10:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 23:10:50 +1100 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <4b1113ad$1@dnews.tpgi.com.au> On 11/28/2009 10:38 PM, The Music Guy wrote: >> If you use it a lot, it is likely 1) you have abused class syntax for >> what should have been a dict or 2) what you need is to override >> __getattr__/__getattribute__ and __setattr__ > > Oh boy...here we go. :| > ok, then what's your use case, AFAICT in the discussion here and previous ones, nobody has yet described a realistic and compelling situation where setattr/getattr is the best solution. That's why the discussion tended to end with "not used frequently enough"; simply because nobody can turn up with a use case to justify a new syntax, especially since all the proposed syntax are ugly (the most acceptable one, for me, is obj.[foo], still ugly but not as ugly as the others). From ben+python at benfinney.id.au Sat Nov 28 07:12:09 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 23:12:09 +1100 Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <87ljhqu9uu.fsf@benfinney.id.au> The Music Guy writes: > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, > frequently the other will assume the former is not only doing things > wrong, but is doing them _blatantly_ wrong. I think you may be misinterpreting the message. > At this point, I don't even believe in such a thing as a universal > "wrong way" and a "right way" to code that applies to every > circumstance. The way to solve a problem depends on the problem. You'll find firm agreement on that in this group. > When it comes to coding, there is not an absolute "right" way or > "wrong" way--unless we're talking about, say, stealing closed source > code without permission, or deliberately coding in a way that will > cause problems for the end user (like causing memory clogs or buffer > overflows and whatnot). However, when it comes to a *specific*, mature programming language, there *are* right and wrong ways. Or, at least, there are ways encouraged or discouraged by the language, its interfaces, its style guides, and its community. Which is very important: it's the rare program that is only ever read by one person in one context. Far more often, the same program needs to be read multiple times, by multiple people, in multiple contexts, over multiple iterations of maintenance. And for that to be feasible, it's very important to write the program the right way *for that language*. Sticking to local conventions has a great deal of practical merit in the medium of human-to-human communication that we call ?programming?. Progress depends on doing things differently; but maintainability depends on keeping unexpected differences to a minimum. -- \ ?The truth is the most valuable thing we have. Let us economize | `\ it.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From cjwilliams43 at gmail.com Sat Nov 28 07:46:16 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sat, 28 Nov 2009 07:46:16 -0500 Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: On 27-Nov-09 22:04 PM, Steve Howell wrote: > Python has this really neat idea called indentation-based syntax, and > there are folks that have caught on to this idea in the HTML > community. > > AFAIK the most popular indentation-based solution for generating HTML > is a tool called HAML, which actually is written in Ruby. > > I have been poking around with the HAML concepts in Python, with the > specific goal of integrating with Django. But before releasing that, > I thought it would be useful to post code that distills the basic > concept with no assumptions about your target renderer. I hope it > also serves as a good example of what you can do in exactly 100 lines > of Python code. > > Here is what it does... > > You can use indentation syntax for HTML tags like table. > > From this... > > table > tr > td > Left > td > Center > td > Right > > ...you get this: > ... [snip] This is a neat idea but would a two character indentation not be enough? Colin W. From detlev at die-offenbachs.de Sat Nov 28 09:22:08 2009 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sat, 28 Nov 2009 15:22:08 +0100 Subject: debugger on system with Python 2 and 3 References: Message-ID: Hi, eric4 snapshot releases support Python3. Detlev Yo Sato wrote: > Hi, > > I am a relative newcomer to the Python language, and only write Python > 3. Now I would very much like to a more-than-basic debugger. However > it seems as if the fact that I have both Python 2 and 3 on the system > complicates the matter... > > First I tried to use something called pydb, but it seems to invoke > python 2, and I don't know quite how to (or whether I can) configure > it for Python 3. > > Secondly I installed something called IDLE3, which complains that TK > is not configured for Python 3. > > I don't want to remove or default to Python 2, as there seem to be a > number of programs that rely on it. > > I wonder how best to avoid my problems. Would perhaps somebody in the > same sort of situation share their wisdom?? > > Yo -- Detlev Offenbach detlev at die-offenbachs.de From vlastimil.brom at gmail.com Sat Nov 28 09:30:36 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 28 Nov 2009 15:30:36 +0100 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> <4b10ec28@dnews.tpgi.com.au> Message-ID: <9fdb569a0911280630v526fa3deve702acfc243c057a@mail.gmail.com> 2009/11/28 joy99 : > On Nov 28, 2:22?pm, Lie Ryan wrote: >> On 11/28/2009 6:20 PM, joy99 wrote: >> >> > I was writing a transliteration program from Bengali to English and >> > vice versa. The program using Unicode chart is giving me perfect >> > outputs in Bengali and vice versa with Bengali input -> ?English. >> > I wanted to add some more power to the key board entry scheme, as I >> > have developed few fonts also and now trying to work out a windows >> > based word processor in Bengali. >> > Thank you for your kind answer. >> > It helped me lot. >> > ALT portion I'll work out on my own. >> > Sorry for a wrongly given problem statement. >> > Wishing you a happy day ahead, >> > Regards, >> > Subhabrata. >> >> If I haven't misunderstood you, you want to capture keyboard input >> involving the CTRL and ALT key, am I correct? >> >> Getting keyboard input with modifier keys depends on your GUI widgets. >> Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? > > You are very right. I am using IDLE on WinXP and for building GUI- > TKinter. > -- > http://mail.python.org/mailman/listinfo/python-list > You may check e.g.: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm hth, vbr From pmaupin at gmail.com Sat Nov 28 10:31:51 2009 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 28 Nov 2009 07:31:51 -0800 (PST) Subject: python bijection References: <87aayhgbx8.fsf@benfinney.id.au> Message-ID: On Nov 19, 8:36?pm, Ben Finney wrote: > Carl Banks writes: > > On Nov 19, 3:24?pm, Joshua Bronson wrote: > > Apart from the GPL, it seems perfectly fine to release, and looks like > > an interesting strategy. I've wanted one of those once in a while, > > never enough to bother looking for one or writing one myself. > > I would think GPL is an excellent choice for such a library then, if the > author's intention is to encourage more software to be free software so > that it can incorporate a unique library like this. Well, yes and no. This bidict class sounds nice and full-featured, especially after the changes prompted by the fruitful discussion. I personally use inverse mappings on a regular basis, but for the most part, my data doesn't change all that dynamically (or performance doesn't really matter), so when I need to go backwards I often do something like: inverse_mapping = dict((y, x) for (x, y) in forward_mapping.iteritems ()) Having said that, if I ever actually *need* something more full- featured to add to non-GPLed software, I'd just write it (and release it under a permissive license). IMHO, GPLing something this simple is really the tail trying to wag the dog. Case in point: I was just using rst2pdf to combine some restructured text and SVG images, using svglib. svglib had some bugs and didn't work right on my PDFs. svglib is not developed publicly, and the author is somewhat slow to accept patches. Since svglib is reasonably small, if it had been released under a permissive license, or even the LGPL, I probably would have just copied it into the rst2pdf repository and fixed it. If it were any smaller, I would have rewritten it. I don't own the rst2pdf package, and didn't really want a license discussion about 1K of source lines dictating a license change on 15K lines. As it is, I figure the svglib author will probably get around to fixing the bug at some point anyway, and for now I can easily use PDFs for my graphics input format, so I cleaned up and added to some old PDF code I had lying around, and released it as the open source pdfrw package, and now rst2pdf can use that to import PDFs as vector images without rasterizing them -- a new capability. So in this case, the GPL spurred open-source development, in exactly the same way that proprietary licenses do... I'm quite happy to *use* GPLed software (and greatly appreciate the authors' efforts), and I'm even sometimes willing to debug or add features and submit patches to GPLed software, and I might even have a (business, not political) reason to release some software under the GPL myself someday. But if I ever did release something under the GPL for business reasons, it would be because I also had the right to also offer a proprietary version. This would require that I owned _all_ the code in the package, so the implication is: I'm not going to use your tiny little GPLed code in any major software I write for release, whether my software is GPLed or not. The LGPL is different. I view the LGPL as a statement of "if you ever add related functionality to this or fix a bug in this in a shipping product, I'd like to see the fix, please" and I could even see myself releasing something with this license under the right circumstances. Now if I were doing a web service, it would be a different story. I would be quite happy to add your GPLed software into the mix, so if that's a terrible thing, perhaps you should consider affero for your future offerings :-) Best regards, Pat From phlip2005 at gmail.com Sat Nov 28 11:19:02 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 08:19:02 -0800 (PST) Subject: filename of calling function? Message-ID: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Consider these two python modules: aa.py def a(): print '?' bb.py import aa def bb(): aa.a() bb() How do I make the print line emit the filename of bb.py? (It could be anything.) I am currently playing with sys.exc_info, but it seems to only emit the stack between the raise and the except. Could be pilot error, of course. Thanks for any help! -- Phlip http://c2.com/cgi/wiki?ZeekLand From arts.martijn at gmail.com Sat Nov 28 11:23:15 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Sat, 28 Nov 2009 17:23:15 +0100 Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> Message-ID: <23739e0a0911280823x3e80592checabd3ba1c0d13f0@mail.gmail.com> It?s quite clear to me: Not. I've taken a look at the "Timebar", and in the last two months there has been no change at all. On Sat, Nov 28, 2009 at 7:32 AM, Steve Howell wrote: > On Nov 27, 9:56 pm, "David Williams" wrote: > > You might want to take a look at this: > > > > http://www.ghrml.org/ > > > > Yep, it's not clear how actively they are maintaining that. The fact > that it seems to target Genshi only might be limiting their audience, > which is unfortunate. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phlip2005 at gmail.com Sat Nov 28 11:40:41 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 08:40:41 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: On Nov 28, 8:19?am, Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > ? ? print '?' > > bb.py > ? import aa > > def bb(): > ? aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) try: raise None except: import sys from traceback import extract_tb, extract_stack frame = sys.exc_info()[2].tb_frame.f_back calling_file = extract_stack(frame, 2)[1][0] From callmeclaudius at gmail.com Sat Nov 28 12:04:40 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Sat, 28 Nov 2009 09:04:40 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: <62448fc8-ad51-4600-99b6-713d21fa12dc@a32g2000yqm.googlegroups.com> On Nov 28, 11:40?am, Phlip wrote: > On Nov 28, 8:19?am, Phlip wrote: > > > > > Consider these two python modules: > > > aa.py > > > def a(): > > ? ? print '?' > > > bb.py > > ? import aa > > > def bb(): > > ? aa.a() > > > bb() > > > How do I make the print line emit the filename of bb.py? (It could be > > anything.) > > ? ? ? ? try: > ? ? ? ? ? ? raise None > ? ? ? ? except: > ? ? ? ? ? ? import sys > ? ? ? ? ? ? from traceback import extract_tb, extract_stack > ? ? ? ? ? ? frame = sys.exc_info()[2].tb_frame.f_back > ? ? ? ? ? ? calling_file = extract_stack(frame, 2)[1][0] code works perfectly except on my system both the indexes need to be 0 (eg: "extract_stack(frame, 2)[0][0]") From phlip2005 at gmail.com Sat Nov 28 12:37:13 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 09:37:13 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> <62448fc8-ad51-4600-99b6-713d21fa12dc@a32g2000yqm.googlegroups.com> Message-ID: <82e2dcd1-6b78-4863-ae04-4811205da3da@v15g2000prn.googlegroups.com> On Nov 28, 9:04?am, Joel Davis wrote: > > ? ? ? ? try: > > ? ? ? ? ? ? raise None > > ? ? ? ? except: > > ? ? ? ? ? ? import sys > > ? ? ? ? ? ? from traceback import extract_tb, extract_stack > > ? ? ? ? ? ? frame = sys.exc_info()[2].tb_frame.f_back > > ? ? ? ? ? ? calling_file = extract_stack(frame, 2)[1][0] > > code works perfectly except on my system both the indexes need to be 0 > (eg: "extract_stack(frame, 2)[0][0]") I thought the 0 was myself, 1 my caller, etc. But tx for trying it From aahz at pythoncraft.com Sat Nov 28 12:38:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:38:13 -0800 Subject: best performance for storage of server information for python CGI web app? References: <58e5cd75-75be-4785-8e79-4903643965ce@e31g2000vbm.googlegroups.com> Message-ID: In article <58e5cd75-75be-4785-8e79-4903643965ce at e31g2000vbm.googlegroups.com>, davidj411 wrote: > >i was also thinking about using SQL Lite with one DB to store all the >info. with this option, i would not have to worry about concurrent >updates, but as the file size increases, i could expect performance to >suffer again? Depends what you mean by "suffer". Performance always decreases as size gets larger unless you take specific steps (such as better algorithms or bigger hardware). Using indexes should give SQLite reasonable performance; you can always upgrade to a faster SQL implementation or switch to another kind of storage. But honestly, until you get to millions of records, you should be fine with SQLite. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:40:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:40:08 -0800 Subject: WindowsError is not available on linux? References: Message-ID: In article , wrote: >On 07:53 pm, aahz at pythoncraft.com wrote: >>In article , >>Peng Yu wrote: >>> >>>It's not clear to me whether WindowsError is available on linux or >>>not, after I read the document. >> >>Here's what I told a co-worker to do yesterday: >> >>if os.name =3D=3D 'nt': >> DiskError =3D (OSError, WindowsError) >>else: >> DiskError =3D WindowsError >> >>try: >> disk_operation() >>except DiskError: >> logit() > >This isn't necessary. WindowsError subclasses OSError. Thanks! Much appreciated! (I haven't done much Windows programming in the past -- and would have preferred to keep it that way. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:44:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:44:18 -0800 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: In article <87fx8bl74c.fsf at benfinney.id.au>, Ben Finney wrote: >Wells writes: >> >> Is it... pythonic, then, to have these lines of tabs/spaces to support >> code collapsing? Is it proper, improper, or irrelevant? > >It's quite improper (though syntactically null, in Python) to have >trailing whitespace on lines. That includes blank lines. Your parenthetical is not quite true, unfortunately. Trailing whitespace after a continuation backslash generates a SyntaxError. That's the main reason I loathe continuation lines. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:47:48 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:47:48 -0800 Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels > declaimed the following in >gmane.comp.python.general: >> >> If you've actually typed on a physical typewriter, you know that moving >> the carriage back is a distinct operation from rolling the platen >> forward; both operations are accomplished when you push the carriage >> back using the bar, but you know they are distinct. > > Of course, if you are describing a /real/ /manual/ typewriter, you >would rapidly discover that the sequence is -- since pushing >the bar would often trigger the line feed before it would slide the >carriage to the right. Often, but not always; it certainly was possible on most typewriters to return the carriage without a line feed -- and occasionally desirable for overstrike. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sat Nov 28 13:24:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 29 Nov 2009 05:24:24 +1100 Subject: Python Programming Challenges for beginners? In-Reply-To: References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> Message-ID: <4b116b3b@dnews.tpgi.com.au> On 11/28/2009 1:51 AM, n00m wrote: > On Nov 27, 1:22 pm, Jon Clements wrote: >> Of course, if you take '~' literally (len(s)<= -10001) I reckon >> you've got way too many :) >> >> Jon. > > Then better: len(s)< abs(~10000) > > PS It's a hard problem; so let's leave it alone I'm not going to write it, but I guess a fairly efficient solution can be written with using a Trie: http://en.wikipedia.org/wiki/Trie and iterating over its items, including partial prefixes. Worse case scenario for creating the tree would be O(n**2) where n = length of string, and iterating the structure would take O(N) where N = number of different substring. for "abbaz", the data structure would be: {'a': {'b': {'b': {'a': {'z': None}}}, 'z': None, }, 'b': {'b': {'a': {'z': None}}, 'a': {'z': None}}, }, 'z': None, } iterating the structure: a ab abb abba abbaz az b bb bba bbaz ba baz z --- 13 (not including '') Now, this makes me interested. How efficient it would be when len(s) == 10000... might as well write it and see. Take back what I said, give me a minute... From inq1ltd at inqvista.com Sat Nov 28 14:38:34 2009 From: inq1ltd at inqvista.com (jim-on-linux) Date: Sat, 28 Nov 2009 14:38:34 -0500 Subject: py2exe users In-Reply-To: <4b116b3b@dnews.tpgi.com.au> References: <4b116b3b@dnews.tpgi.com.au> Message-ID: <200911281438.35080.inq1ltd@inqvista.com> I have used py2exe many times with success. My current program is completing as expected but the exe file fails to open. The output file states that _imaging_gif is missing. I can run the program ok with IDLE but after converting with py2exe, the exe file just sits there. I'm using 2.6 on win XP. Any Ideas? jim-on-linux From n00m at narod.ru Sat Nov 28 14:45:52 2009 From: n00m at narod.ru (n00m) Date: Sat, 28 Nov 2009 11:45:52 -0800 (PST) Subject: Python Programming Challenges for beginners? References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> <4b116b3b@dnews.tpgi.com.au> Message-ID: <566a3d7d-4cc1-4909-aba0-b0c6011f719e@p8g2000yqb.googlegroups.com> On Nov 28, 8:24?pm, Lie Ryan wrote: > Now, this makes me interested. How efficient it would be when len(s) == > 10000... might as well write it and see. Take back what I said, give me > a minute... ... and you can check it here: http://www.spoj.pl/problems/DISUBSTR/ I see there only one (accepted) solution in Python: http://www.spoj.pl/ranks/DISUBSTR/lang=PYTH%202.5 From n00m at narod.ru Sat Nov 28 15:07:30 2009 From: n00m at narod.ru (n00m) Date: Sat, 28 Nov 2009 12:07:30 -0800 (PST) Subject: Python Programming Challenges for beginners? References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> <4b116b3b@dnews.tpgi.com.au> <566a3d7d-4cc1-4909-aba0-b0c6011f719e@p8g2000yqb.googlegroups.com> Message-ID: <3a695b27-cb82-4c93-b979-7185d2f3c2e9@9g2000yqa.googlegroups.com> PS My straightforward C++ solution got TLE... #include #include #include #include #include #include #include #include #include using namespace std; int main() { //freopen("88.txt", "rt", stdin); //freopen("99.txt", "wt", stdout); int tcs; string s; cin >> tcs; while (tcs-- > 0) { cin >> s; int n = s.size(); s = s + ' '; vector< vector > a(256); int ans = 0; for (int i = n - 1; i >= 0; --i) { int lev = 0; vector p = a[s[i]]; vector q; while (!p.empty()) { q.clear(); ++lev; for (int j = 0; j < p.size(); ++j) { if (s[p[j] + 1] == s[i + lev]) { q.push_back(p[j] + 1); } } p.swap(q); } a[s[i]].push_back(i); ans += n - i - lev; } cout << ans << endl; } return 0; } From grflanagan at gmail.com Sat Nov 28 15:14:53 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Sat, 28 Nov 2009 20:14:53 +0000 Subject: filename of calling function? In-Reply-To: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > print '?' > > bb.py > import aa > > def bb(): > aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) > Possibly not very reliable in every situation (doctests, other pythons, ...) but this is what I do: --------- aa.py -------------- import __main__ as CALLER def mynameis(): print CALLER.__file__ --------- bb.py -------------- import aa def whosthere(): aa.mynameis() whosthere() ------------------------------- OUTPUT: bb.py hth G.F. From timr at probo.com Sat Nov 28 15:26:33 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:26:33 -0800 Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <4b0f9e7c$1@dnews.tpgi.com.au> Message-ID: <8r13h5tbl1kck2eq0jds72mm15tpaelhon@4ax.com> Marco Mariani wrote: >luca72 wrote: > >> i have checked and pyscard accept also the decimal notation, > >I'm not sure you ever understood what the problem was, or where, but I'm >happy you feel like you've solved it. +1 QOTW. Great reply. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Nov 28 15:31:49 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:31:49 -0800 Subject: why do I get this behavior from a while loop? References: <00998f26$0$26925$c3e8da3@news.astraweb.com> Message-ID: "S. Chris Colbert" wrote: > >What a newbie mistake for me to make. Don't feel too badly about it. Even very experienced programmers get bitten by this issue. Until someone points it out, it's certainly not obvious. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Nov 28 15:39:05 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:39:05 -0800 Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> moijes12 wrote: > >I know the value -0 is quite meaningless and makes little sense.But I >was just fiddling.I am unable to figure out the below result > >>>> -0 and True >0 ----------> (Why is this 0 and not say True or False) >>>> -0 and false >0 >>>> -0 or True >True > >Could someone please provide me some resources on how these operations >take place.I'd wanna find it out myself Actually, there ARE computers where you might not see this result. Virtually all of the processors on which Python runs use two's complement arithmetic. In two's complement, there is no separate value called -0. 0 and -0 have the same bit representation. In one's complement, -0 and 0 have different representations. Having spent 10 years with Control Data (the 6000 and Cyber 70/170 mainframes were all one's complement), I am particularly sensitive to this. Processors are usually architected so that you don't normally see the -0, but it leads you to think about arithmetic a bit differently. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From news123 at free.fr Sat Nov 28 16:11:18 2009 From: news123 at free.fr (News123) Date: Sat, 28 Nov 2009 22:11:18 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> Message-ID: <4b1191f6$0$3891$426a74cc@news.free.fr> r wrote: > more *maybe useful dump? > >>>> for i in dev.Items: > for p in i.Properties: > if not p.IsReadOnly: > print p.Name, '->', p.Value > . . . > Horizontal Resolution -> 200 > Vertical Resolution -> 200 > Horizontal Start Position -> 0 . . . > > Now how to set the values... hmmm? > How to set the values? This is THE magic question. At least I found out how to set the values in C# : foreach (Property prop in item.Properties){ if (prop.IsReadOnly) continue; if (prop.Name == "Horizontal Resolution") { IProperty iprop = (IProperty)prop; Object val = 75; iprop.set_Value(ref val); } } Below my most recent complete script: (still not able to set params, though I can with C#) import win32com.client, os WIA_COM = "WIA.CommonDialog" WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE="{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" def takePictureOrNot(dev): # cameras have to call TakePicture for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: print "take PICK" foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) def setImgProps(item): # here scan properties should be set for prop in item.Properties: if prop.IsReadOnly: continue if(prop.Name == "Horizontal Resolution"): res = 250 print "trying to set",prop.Name,prop,"to ",res ### unfortunately the next line (if uncommented) fails #prop.set_Value(res) def transferImg(dev): # set properties and scan image i=1 image = None for item in dev.Items: if i==dev.Items.Count: setImgProps(item) image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 return image def scan_image_wia(): wia = win32com.client.Dispatch(WIA_COM) # CommonDialog object dev = wia.ShowSelectDevice() takePictureOrNot(dev) image = transferImg(dev) return image image = scan_image_wia() fname = 'wia-test.jpg' if os.path.exists(fname): os.remove(fname) image.SaveFile(fname) bye N From news123 at free.fr Sat Nov 28 16:18:35 2009 From: news123 at free.fr (News123) Date: Sat, 28 Nov 2009 22:18:35 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: <4b097593$0$30269$426a74cc@news.free.fr> References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4b1193ac$0$6093$426a34cc@news.free.fr> Meanwhile I found out, why my script worked only on windows 7/Vista and not on my XP host. The WIA 2.0 Scripting Model is by default not installed on Windows XP. Install instructions can be found at http://msdn.microsoft.com/en-us/library/ms630827%28VS.85%29.aspx My second problem (changing parameters) is still not solved in python. bye N News123 wrote: > Hi, > > I'm trying to scan a document from a python 2.6 script without user > interaction. > > I found a code snippet, that allows me to scan under Vista, but that > doesn't allow me to select the dpi / color mode / etc. > > The snippet uses win32com.client > > # ##################### script start > import win32com.client,os > > WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" > WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" > > os.chdir('c:/temp') > wia = win32com.client.Dispatch("WIA.CommonDialog") > dev = wia.ShowSelectDevice() > for command in dev.Commands: > if command.CommandID==WIA_COMMAND_TAKE_PICTURE: > foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) > i=1 > for item in dev.Items: > if i==dev.Items.Count: > image=item.Transfer(WIA_IMG_FORMAT_PNG) > break > i=i+1 > > image.SaveFile("test.png") > ######################### script end > > > My problems are: > > - This script works fine for me under Windows 7, however I'm > unable to specify additional parameters, like dpi and > color mode. > > - The script doesn't work under windows XP, though the scanner driver is > installed. (Gimp finds the scanner (as WIA scanner)). > Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL. > The error message is: > -------------------------------------------------------------------- > Traceback (most recent call last): > File "C:\work\python\minidemos\wia_get_simple.py", line 7, in > wia = win32com.client.Dispatch("WIA.CommonDialog") > File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line > 95, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line > 104, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line > 84, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > com_error: (-2147221005, 'Invalid class string', None, None) > --------------------------------------------------------------------- From changlani.nitin at gmail.com Sat Nov 28 17:19:02 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sat, 28 Nov 2009 17:19:02 -0500 Subject: Variables with cross-module usage Message-ID: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> Hello everyone, I am fairly new to Python and occasionally run into problems that are almost always resolved by referring to this mailing-list's archives. However, I have this one issue which has got me stuck and I hope you will be tolerant enough to help em out with it! What I want to achieve is something like the global variables in C/C++: you declare them in one file and "extern" them in all the files where you need to use them. I have 3 files: one.py, two.py and three.py as below: one.py ---------- a = 'place_a' b = 'place_b' x = 'place_x' myList = [a, b, 'place_c'] ====================================================================== two.py ---------- import one def myFunc(): print one.x print one.myList ====================================================================== three.py ------------ import one import two def argFunc(): one.x = 'place_no_x' one.a = 'place_no_a' one.b = 'place_no_b' if __name__ == '__main__': two.myFunc() print argFunc() two.myFunc() ====================================================================== Output: ----------- 'place_x' ['place_a', 'place_b', 'place_c'] 'place_no_x' ['place_a', 'place_b', 'place_c'] (*** instead of ['place_no_a', 'place_no_b', 'place_c'] ***) The last line in the output is what's baffling me. Can anyone please help me know if I am doing something wrong? Thanks in advance, Nitin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Nov 28 17:28:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 22:28:49 +0000 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: <4b1191f6$0$3891$426a74cc@news.free.fr> References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> <4b1191f6$0$3891$426a74cc@news.free.fr> Message-ID: <4B11A421.1020607@mrabarnett.plus.com> News123 wrote: > r wrote: >> more *maybe useful dump? >> >>>>> for i in dev.Items: >> for p in i.Properties: >> if not p.IsReadOnly: >> print p.Name, '->', p.Value >> > . . . >> Horizontal Resolution -> 200 >> Vertical Resolution -> 200 >> Horizontal Start Position -> 0 > . . . >> Now how to set the values... hmmm? >> Well, according to that they /aren't/ read-only because it says: if not p.IsReadOnly: ^^^ From python at mrabarnett.plus.com Sat Nov 28 17:36:24 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 22:36:24 +0000 Subject: Variables with cross-module usage In-Reply-To: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> Message-ID: <4B11A5E8.3080700@mrabarnett.plus.com> Nitin Changlani. wrote: > Hello everyone, > > I am fairly new to Python and occasionally run into problems that are > almost always resolved by referring to this mailing-list's archives. > However, I have this one issue which has got me stuck and I hope you > will be tolerant enough to help em out with it! > > What I want to achieve is something like the global variables in C/C++: > you declare them in one file and "extern" them in all the files where > you need to use them. I have 3 files: one.py, two.py and three.py as below: > > one.py > ---------- > a = 'place_a' > b = 'place_b' > x = 'place_x' > > myList = [a, b, 'place_c'] > > ====================================================================== > > two.py > ---------- > import one > > def myFunc(): > print one.x > print one.myList > > ====================================================================== > > three.py > ------------ > import one > import two > > def argFunc(): > one.x = 'place_no_x' > one.a = 'place_no_a' > one.b = 'place_no_b' > > if __name__ == '__main__': > two.myFunc() > print > argFunc() > two.myFunc() > > ====================================================================== > > Output: > ----------- > 'place_x' > ['place_a', 'place_b', 'place_c'] > > 'place_no_x' > ['place_a', 'place_b', 'place_c'] (*** instead of ['place_no_a', > 'place_no_b', 'place_c'] ***) > > The last line in the output is what's baffling me. Can anyone please > help me know if I am doing something wrong? > What's confusing you? myList gets its value (['place_a', 'place_b', 'place_c']) when one.py is first imported, and you never change it after that. From rami.chowdhury at gmail.com Sat Nov 28 17:46:37 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 28 Nov 2009 14:46:37 -0800 Subject: Variables with cross-module usage In-Reply-To: <4B11A5E8.3080700@mrabarnett.plus.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> Message-ID: <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> Hi Nitin, On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > Nitin Changlani. wrote: >> three.py >> ------------ >> import one >> import two >> >> def argFunc(): >> ? ?one.x = 'place_no_x' >> ? ?one.a = 'place_no_a' >> ? ?one.b = 'place_no_b' >> I think this is what is biting you. You might expect that after argFunc, one.x would be set to 'place_no_x' and so on. However, Python's scoping doesn't work like that -- the name one.x is only rebound in the function's scope, so outside of argFunc (e.g. in your main printing code) one.x is still bound to 'place_x'. HTH, Rami From mnordhoff at mattnordhoff.com Sat Nov 28 17:57:09 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sat, 28 Nov 2009 22:57:09 +0000 Subject: Variables with cross-module usage In-Reply-To: <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> Message-ID: <4B11AAC5.50108@mattnordhoff.com> Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> ------------ >>> import one >>> import two >>> >>> def argFunc(): >>> one.x = 'place_no_x' >>> one.a = 'place_no_a' >>> one.b = 'place_no_b' >>> > > I think this is what is biting you. You might expect that after > argFunc, one.x would be set to 'place_no_x' and so on. However, > Python's scoping doesn't work like that -- the name one.x is only > rebound in the function's scope, so outside of argFunc (e.g. in your > main printing code) one.x is still bound to 'place_x'. > > HTH, > Rami Not true. argFunc does not rebind the name "one", it mutates the module object referred to by the name "one". Since there is only one instance of a given module*, the change is indeed reflected everywhere the "one" module is accessed. The problem is that argFunc does not modify (or replace) one.myList, as MRAB said. * Unless you do something strange like reload() or editing sys.modules or having module available under different names...or something. -- Matt Nordhoff From rami.chowdhury at gmail.com Sat Nov 28 18:06:11 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 28 Nov 2009 15:06:11 -0800 Subject: Variables with cross-module usage In-Reply-To: <4B11AAC5.50108@mattnordhoff.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> <4B11AAC5.50108@mattnordhoff.com> Message-ID: <2f79f590911281506j16a66f58h2e974b39ae009787@mail.gmail.com> -------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Sat, Nov 28, 2009 at 14:57, Matt Nordhoff wrote: > Rami Chowdhury wrote: >> Hi Nitin, >> >> On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >>> Nitin Changlani. wrote: >>>> three.py >>>> ------------ >>>> import one >>>> import two >>>> >>>> def argFunc(): >>>> ? ?one.x = 'place_no_x' >>>> ? ?one.a = 'place_no_a' >>>> ? ?one.b = 'place_no_b' >>>> >> >> I think this is what is biting you. You might expect that after >> argFunc, one.x would be set to 'place_no_x' and so on. However, >> Python's scoping doesn't work like that -- the name one.x is only >> rebound in the function's scope, so outside of argFunc (e.g. in your >> main printing code) one.x is still bound to 'place_x'. >> >> HTH, >> Rami > > Not true. argFunc does not rebind the name "one", it mutates the module > object referred to by the name "one". Since there is only one instance > of a given module*, the change is indeed reflected everywhere the "one" > module is accessed. Ah, thanks for clarifying! From news123 at free.fr Sat Nov 28 18:10:45 2009 From: news123 at free.fr (News123) Date: Sun, 29 Nov 2009 00:10:45 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> <4b1191f6$0$3891$426a74cc@news.free.fr> Message-ID: <4b11adf5$0$30382$426a74cc@news.free.fr> MRAB wrote: > News123 wrote: >> r wrote: >>> more *maybe useful dump? >>> >>>>>> for i in dev.Items: >>> for p in i.Properties: >>> if not p.IsReadOnly: >>> print p.Name, '->', p.Value >>> >> . . . >>> Horizontal Resolution -> 200 >>> Vertical Resolution -> 200 >>> Horizontal Start Position -> 0 >> . . . >>> Now how to set the values... hmmm? >>> > Well, according to that they /aren't/ read-only because it says: > > if not p.IsReadOnly: > ^^^ > Exactly they are NOT read only, which means they are supposed to be writable. the python code is for p in i.Properties: if not.p.ISReadOnly: # if I'm here I'm supposed to change them, but how? the C# code, which succeds changing the property is: foreach (Property prop in item.Properties){ if (prop.IsReadOnly) continue; // skip rest of loop // if property cannot // be modified // now change property if (prop.Name == "Horizontal Resolution") { IProperty iprop = (IProperty)prop; Object val = 75; iprop.set_Value(ref val); } } The main question is the correct python method to change the property prop = 300 # doesn't work as it just replaces the property with an integer prop.set_Value(res) # doesn't work as the method set_Value doesn't seem to exist > Traceback (most recent call last): > File "C:\WIA\scan_wia.py", line 41, in > image = scan_image_wia() > File "C:\WIA\scan_wia.py", line 37, in scan_image_wia > image = transferImg(dev) > File "C:\WIA\scan_wia.py", line 27, in transferImg > setImgProps(item) > File "C:\WIA\scan_wia.py", line 20, in setImgProps > prop.set_Value(res) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 512, in > __getattr__ > raise AttributeError("%s.%s" % (self._username_, attr)) > AttributeError: .set_Value bye N From dickinsm at gmail.com Sat Nov 28 18:14:31 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 28 Nov 2009 15:14:31 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> Message-ID: <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> On Nov 28, 8:39?pm, Tim Roberts wrote: > moijes12 wrote: > > >I know the value -0 is quite meaningless and makes little sense.But I > >was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > >0 ----------> (Why is this 0 and not say True or False) > >>>> -0 and false > >0 > >>>> -0 or True > >True > > >Could someone please provide me some resources on how these operations > >take place.I'd wanna find it out myself > > Actually, there ARE computers where you might not see this result. > Virtually all of the processors on which Python runs use two's complement > arithmetic. ?In two's complement, there is no separate value called -0. ?0 > and -0 have the same bit representation. > > In one's complement, -0 and 0 have different representations. While that's true, I think the implementation of Python is such that the Python objects -0 and 0 should always be indistinguishable even on machines where the underlying architecture represents integers using ones' complement or sign-magnitude. At least that's certainly the intention: there are bits of CPython's source code that are deliberately written in convoluted ways in order to avoid the assumption of two's complement. But I have a nasty suspicion that, were Python ever unlucky enough to meet a ones' complement machine, we'd quickly find that there were many *other* bits of the source code that tacitly (and incorrectly) assumed a two's complement representation. Mark From john at castleamber.com Sat Nov 28 18:25:35 2009 From: john at castleamber.com (John Bokma) Date: 28 Nov 2009 23:25:35 GMT Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b11adf5$0$30382$426a74cc@news.free.fr> Message-ID: News123 wrote: > MRAB wrote: >> News123 wrote: >>> r wrote: >>>> more *maybe useful dump? >>>> >>>>>>> for i in dev.Items: >>>> for p in i.Properties: >>>> if not p.IsReadOnly: >>>> print p.Name, '->', p.Value [..] > The main question is the correct python method to change the property > > prop = 300 # doesn't work as it just replaces the property with an > integer wild guess, but how about p.Value = 300 ? John From mwilson at the-wire.com Sat Nov 28 18:26:25 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 28 Nov 2009 18:26:25 -0500 Subject: Variables with cross-module usage References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> Message-ID: Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> ------------ >>> import one >>> import two >>> >>> def argFunc(): >>> one.x = 'place_no_x' >>> one.a = 'place_no_a' >>> one.b = 'place_no_b' >>> > > I think this is what is biting you. You might expect that after > argFunc, one.x would be set to 'place_no_x' and so on. However, > Python's scoping doesn't work like that -- the name one.x is only > rebound in the function's scope, so outside of argFunc (e.g. in your > main printing code) one.x is still bound to 'place_x'. No, It's not like that. MRAB had it. The thing is, that when one.py is imported, it sets the name one.a to refer to a string 'place_a'. Then a list named one.myList is built with one.myList[0] referring to the same string as one.a . So far, so good. Then the function argFunc is called. It uses `one` as a name from its global namespace. Inside argFunc, the names one.x and one.a are rebound to different strings from the ones they started with. *But* one.myList[0] isn't touched, and still refers to 'place_x' like it always did. Mel. From dickinsm at gmail.com Sat Nov 28 18:38:09 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 28 Nov 2009 15:38:09 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> Message-ID: On Nov 28, 11:14?pm, Mark Dickinson wrote: > While that's true, I think the implementation of Python is > such that the Python objects -0 and 0 should always be > indistinguishable even on machines where the underlying > architecture represents integers using ones' complement or > sign-magnitude. Hmm. I really should think before posting. A quick glance at int_and, int_xor and int_or in Objects/intobject.c: http://svn.python.org/view/python/trunk/Objects/intobject.c?view=markup shows that Python clearly fails to be independent of the hardware's choice of integer representation. E.g., on a ones' complement machine, Python would give: >>> -1 & 1 0 but the same operation on longs would give a different result: >>> -1L & 1L 1L Mark From alfps at start.no Sat Nov 28 18:47:00 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 29 Nov 2009 00:47:00 +0100 Subject: Req. for comments section "Basic Data" in intro book Message-ID: I added a section on "basic data" to ch 2 of my writings, an introduction to programming (with Python as main language). The intended reader is someone who is intelligent and wants to learn programming but knows little or nothing about it. As before it would be nice with feedback on this. Format: PDF Current contents: 1 Getting started. 1 1.1 Python variants, implementations and distributions. 1 1.2 Download and install a Python implementation. 2 1.3 Test-drive the Python interpreter. 2 1.4 Create and run a Python console program. 4 1.5 Syntax highlighting and programmers' editors. 6 1.6 Create and run a Python GUI program. 7 1.7 About compilation. 9 1.8 About standalone Windows programs & other kinds. 10 1.9 Browse the local documentation. 11 EOT 12 2 Basic concepts. 1 2.1 Super-basic concept: why programming is not DWIM. 1 2.2 Reported errors. 4 2.2.1 Case-sensitity. 4 2.2.2 Syntax / compilation errors. 4 2.2.3 Runtime errors / crashes. 5 2.3 A programming exploration tool: turtle graphics. 6 2.4 Naming things. 8 2.4.1 Naming actions: routines. 8 2.4.2 Naming data part I: variables. 11 2.4.3 Naming data part II: routine arguments. 13 2.5 Controlling the flow of execution. 14 2.5.1 Repeating actions automatically: loops. 14 2.5.2 Basic comparisions & boolean values. 16 2.5.3 Interlude I: a function graph program / about types. 17 2.5.4 Automated action choices. 21 2.5.5 Value-producing (function-like) routines. 23 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 2.5.7 Dynamically nested actions: recursive routines. 28 2.6 Basic data. 36 2.6.1 Basic fundamental types / strings & concatenation. 36 2.6.2 Indexing and single characters (+ vaguely about sequences in general). 39 2.6.3 Interlude III: a ROT-13 encryption/decryption program, refactoring. 40 2.6.4 Attributes, methods, objects. 43 2.6.5 Doc strings. 44 2.6.6 Interlude IV: attribute names as strings, listing str attributes. 45 2.6.7 References. 46 EOT 49 The section on "References", 2.6.7, is about references in Python, it's not a list of references. :-) Cheers, - Alf From rhodri at wildebst.demon.co.uk Sat Nov 28 19:33:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 29 Nov 2009 00:33:31 -0000 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> Message-ID: On Sat, 28 Nov 2009 07:30:00 -0000, joy99 wrote: > On Nov 28, 5:35 am, Steven D'Aprano cybersource.com.au> wrote: >> As for Alt-combinations, I don't think there is any standard for what >> they are. I believe that they are operating system specific, and >> possibly >> even program specific. > > It seems the following site: > http://knopok.net/symbol-codes/alt-codes > is quite resourceful on Alt. *If* (and it's a big if) you're using Windows. Steven's point is very much worth bearing in mind. -- Rhodri James *-* Wildebeest Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 19:58:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 00:58:27 GMT Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> Message-ID: <009b4bab$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 15:14:31 -0800, Mark Dickinson wrote: >> Actually, there ARE computers where you might not see this result. >> Virtually all of the processors on which Python runs use two's >> complement arithmetic. ?In two's complement, there is no separate value >> called -0. ?0 and -0 have the same bit representation. >> >> In one's complement, -0 and 0 have different representations. > > While that's true, I think the implementation of Python is such that the > Python objects -0 and 0 should always be indistinguishable even on > machines where the underlying architecture represents integers using > ones' complement or sign-magnitude. I don't think that really has any bearing on the Original Poster's question -- presumably on such machines, Python should treat both -0 and +0 as false in a boolean context and generate the same result. When it comes to integers, I'm not aware of any mathematical or programming system which treats -0 and +0 as distinct entities, even if they have different internal representations. But the same doesn't apply for floats, where the IEEE standard requires that -0.0 and +0.0 be distinct and distinguishable (although it also requires that they compare as equal). -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 20:05:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 01:05:22 GMT Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: <009b4d4a$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 08:19:02 -0800, Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > print '?' > > bb.py > import aa > > def bb(): > aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) See the inspect module: http://stefaanlippens.net/python_inspect -- Steven From news123 at free.fr Sat Nov 28 20:14:53 2009 From: news123 at free.fr (News123) Date: Sun, 29 Nov 2009 02:14:53 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b11adf5$0$30382$426a74cc@news.free.fr> Message-ID: <4b11cb0d$0$5766$426a74cc@news.free.fr> Hi John, John Bokma wrote: > News123 wrote: > >> MRAB wrote: >>> News123 wrote: >>>> r wrote: >>>>> more *maybe useful dump? >>>>> >>>>>>>> for i in dev.Items: >>>>> for p in i.Properties: >>>>> if not p.IsReadOnly: >>>>> print p.Name, '->', p.Value > > [..] > >> The main question is the correct python method to change the property >> >> prop = 300 # doesn't work as it just replaces the property with an >> integer > > wild guess, but how about p.Value = 300 ? > > John Wild and good guess indeed. p.Value = 300 is working. Finally I can do WIA scans and set the parameters. How could I have found this out without guessing? Or phrased differently: What would be the correct way to find out what can be done with variables returned by win32com.client s. I tried dir(prop) prop.__doc__ type(prop) and got ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__doc__', '__eq__', '__getattr__', '__getitem__', '__init__', '__int__', '__len__', '__module__', '__ne__', '__nonzero__', '__repr__', '__setattr__', '__setitem__', '__str__', '_builtMethods_', '_enum_', '_find_dispatch_type_', '_get_good_object_', '_get_good_single_object_', '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] The dynamic class used as a last resort. The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy of using the makepy generated wrapper Python class instead of dynamic.CDispatch if/when possible. and T I'd like to avoid wild guessing when being confronted with another win32.com object. Thanks again N From fearsomedragonfly at gmail.com Sat Nov 28 20:22:27 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 17:22:27 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> Message-ID: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> On Nov 28, 6:10?am, Lie Ryan wrote: > On 11/28/2009 10:38 PM, The Music Guy wrote: > > >> If you use it a lot, it is likely 1) you have abused class syntax for > >> what should have been a dict or 2) what you need is to override > >> __getattr__/__getattribute__ and __setattr__ > > > Oh boy...here we go. :| > > > > ok, then what's your use case, AFAICT in the discussion here and > previous ones, nobody has yet described a realistic and compelling > situation where setattr/getattr is the best solution. That's why the > discussion tended to end with "not used frequently enough"; simply > because nobody can turn up with a use case to justify a new syntax, > especially since all the proposed syntax are ugly (the most acceptable > one, for me, is obj.[foo], still ugly but not as ugly as the others). Alright, I'm not sure if my last message about this came through, so I'm going to assume it didn't. When I first started seeing @ show up in Python code, I said "what the heck is that? It looks so weird and _ugly_. I would never try to mess with that." But I started seeing it more and more, so I asked #python what it was. They told me about decorators, so I looked it up in the docs, and I thought the idea was interesting. It took me a while to figure out exactly how they worked--and judging from messages I've seen in #python a number of people have the same trouble understanding them. My point is that any particular syntax would look ugly to you only because you haven't seen it in use enough, and haven't used it enough yourself. But of course you haven't--it's not currently a valid syntax. However, the ugliness would seem to go away after the syntax had been in use for a while. And again, the EXACT syntax of the feature can be adjusted until its "just right". As for my specific use case, it's somewhat difficult to explain. The general idea was to isolate a pattern that I spotted repeated in several unrelated parts of my project. The pattern manifested itself as a set of 4-5 methods and/or properties on a class whose objects were designed to work in conjunction with other objects that fit a particular behavior. These other objects had methods and properties that were designed to interact with the first type of object in a similar but--how should I say--"inverted" fashion. This pattern showed up in many different classes throughout the project, and not only that, but the code was very similar. I decided to try to eliminate some of the code redundancy by creating a base class for all the classes to derive from. That didn't worked out okay for some things, but not for others. I can't remember the exact details of the problem at this point, but I believe it had to do with the keying/indexing protocol (ie. __getitem__, __setitem__, etc.). I decided to keep the base class (and have since extended it), but decided that it wasn't enough--that's when I decided to try metaclassing. After some work I managed to recreate the object-to- object relationship pattern that kept showing up everywhere, but in a generic way that allowed for the names of methods and properties that composed the pattern to vary in name and in the names that they referenced from other objects. The code worked very well, and allowed for the pattern to be added to any class by using a single, short line of code (something along the lines of __class_attr = { key: value }). Not only that, but the metaclass code itself was comprised of less than a screenful of code after docstrings and comments had been removed. However, the code was (and still is) very difficult to follow simply because of the way getters and setters had to be used to generate the methods and properties. P.s. Lie Ryan, I appreciate your response, and I will get back to you, but I want to make sure I reply under the right circumstances or I'll end up putting my foot in my mouth. ^_^ From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 20:23:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 01:23:18 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <009b517e$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 03:38:38 -0800, The Music Guy wrote: > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, frequently > the other will assume the former is not only doing things wrong, but is > doing them _blatantly_ wrong. That's because most of the time that assumption is correct. 50% of all coders are worse than average -- and in fact since the distribution of coding skill is unlikely to be normally distributed, it may very well be true that *more* than 50% of all coders are worse than average. Which means that, when faced with a coder you know nothing about except that he is trying to do something you can't understand, merely by playing the odds you have at least a 50:50 chance that he's doing something silly. The coders who hang around forums casting judgement are more likely like to better than average -- they're not just code monkeys putting in their eight hours days cranking out boilerplate code. They usually know what they're doing. They are skillful and knowledgeable -- those who aren't don't last long: they either leave, or they learn and become knowledgeable. So when people on forums suggest something is a bad idea, statistics is on their side, to say nothing of reasoned judgement. Most new ideas are bad ideas. Pure statistics again -- if an idea is any good, somebody has probably already had it, and it has become a standard tool that everyone uses. Breaking code up into subroutines is such a good idea, and nearly every programming language has some way of breaking code up into subroutines. But bad ideas keep coming up over and over again, as they're thought of, then rejected, then somebody else comes along and thinks of it again. The same old bad ideas keep being raised again and again. > I have caught myself making that very > assumption many times in the past, and I've tried hard to build up an > immunity against the impulse to make that assumption. Doing so reduces your chances of making uncommon false negatives at the cost of increasing your chances of making common false positives. Personally, I think it's a bad strategy, but that depends on just how much effort you put into giving every new idea a fair shake. > At this point, I > don't even believe in such a thing as a universal "wrong way" and a > "right way" to code that applies to every circumstance. Well duh :) > The way to solve a problem depends on the problem. Well duh again :D But there are certain "standard", common, types of problems. Most problems are just variations on other problems. Very few problems are unique. > When it comes to coding, there is not > an absolute "right" way or "wrong" way--unless we're talking about, say, > stealing closed source code without permission, or deliberately coding > in a way that will cause problems for the end user (like causing memory > clogs or buffer overflows and whatnot). There is no need for "deliberately" in that sentence. If you cause problems like buffer overflows, you're doing it wrong. It's wrong whether you did so maliciously or through ignorance. Even if you document that it is subject to this failure mode ("don't do this"), it's still wrong. Sometimes we do the wrong thing because sometimes it's more important to get a 99% solution today than a 100% solution next month, but it's still objectively buggy. > All of this can be determined through common sense. And yet I continue > to see the attitude of "my solution is the ONLY solution to your > problem, and it doesn't matter if I don't even actually understand the > problem." Not everyone does this, but it is a frequent enough occurence > to be worth noting. If I had to pull a number out of my magic bag, I > would say 4 out of 10 resposes have at least a hint of this attitude, > and 2.5/10 where it is very obvious. You say that as if it's a bad thing. I think it's a good thing -- most solutions are tried and tested, and conservatively sticking to solutions that are known to work is a successful solution: * if you write code which took a lot of effort to understand, it will take a lot of effort to maintain; * if you write code which only the creator understands, then if something happens to the creator, nobody will understand the code; * debugging is harder than writing code in the first place, so if you write the cleverest code you possibly can, then you aren't clever enough to debug it. [...] > ...and I have one last thing to say. I feel very strongly that > metaclassing is a fiercely underestimated and largely untapped source of > good coding solutions. There's a reason for that -- metaclasses are *clever*. Good solutions should be dumb enough that even the 50% of below-average coders can use them. Metaclasses are hard, and because they're hard, they're underutilized, and consequently people are unfamiliar with them. Because they're unfamiliar, that makes them even harder to understand, and so people avoid metaclasses -- a vicious circle, as you pointed out. -- Steven From fearsomedragonfly at gmail.com Sat Nov 28 20:24:09 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 17:24:09 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> Message-ID: <2d3ae8de-5108-4528-b0d6-275e8849609a@g27g2000yqn.googlegroups.com> On Nov 28, 6:10?am, Lie Ryan wrote: > On 11/28/2009 10:38 PM, The Music Guy wrote: > > >> If you use it a lot, it is likely 1) you have abused class syntax for > >> what should have been a dict or 2) what you need is to override > >> __getattr__/__getattribute__ and __setattr__ > > > Oh boy...here we go. :| > > > > ok, then what's your use case, AFAICT in the discussion here and > previous ones, nobody has yet described a realistic and compelling > situation where setattr/getattr is the best solution. That's why the > discussion tended to end with "not used frequently enough"; simply > because nobody can turn up with a use case to justify a new syntax, > especially since all the proposed syntax are ugly (the most acceptable > one, for me, is obj.[foo], still ugly but not as ugly as the others). Alright, I'm not sure if my last message about this came through, so I'm going to assume it didn't. When I first started seeing @ show up in Python code, I said "what the heck is that? It looks so weird and _ugly_. I would never try to mess with that." But I started seeing it more and more, so I asked #python what it was. They told me about decorators, so I looked it up in the docs, and I thought the idea was interesting. It took me a while to figure out exactly how they worked--and judging from messages I've seen in #python a number of people have the same trouble understanding them. My point is that any particular syntax would look ugly to you only because you haven't seen it in use enough, and haven't used it enough yourself. But of course you haven't--it's not currently a valid syntax. However, the ugliness would seem to go away after the syntax had been in use for a while. And again, the EXACT syntax of the feature can be adjusted until its "just right". As for my specific use case, it's somewhat difficult to explain. The general idea was to isolate a pattern that I spotted repeated in several unrelated parts of my project. The pattern manifested itself as a set of 4-5 methods and/or properties on a class whose objects were designed to work in conjunction with other objects that fit a particular behavior. These other objects had methods and properties that were designed to interact with the first type of object in a similar but--how should I say--"inverted" fashion. This pattern showed up in many different classes throughout the project, and not only that, but the code was very similar. I decided to try to eliminate some of the code redundancy by creating a base class for all the classes to derive from. That didn't worked out okay for some things, but not for others. I can't remember the exact details of the problem at this point, but I believe it had to do with the keying/indexing protocol (ie. __getitem__, __setitem__, etc.). I decided to keep the base class (and have since extended it), but decided that it wasn't enough--that's when I decided to try metaclassing. After some work I managed to recreate the object-to- object relationship pattern that kept showing up everywhere, but in a generic way that allowed for the names of methods and properties that composed the pattern to vary in name and in the names that they referenced from other objects. The code worked very well, and allowed for the pattern to be added to any class by using a single, short line of code (something along the lines of __class_attr = { key: value }). Not only that, but the metaclass code itself was comprised of less than a screenful of code after docstrings and comments had been removed. However, the code was (and still is) very difficult to follow simply because of the way getters and setters had to be used to generate the methods and properties. P.s. Ben Finney, I appreciate your response, and I will get back to you, but I want to make sure I reply under the right circumstances or I'll end up putting my foot in my mouth. ^_^ From dreadpiratejeff at gmail.com Sat Nov 28 21:15:24 2009 From: dreadpiratejeff at gmail.com (J) Date: Sat, 28 Nov 2009 21:15:24 -0500 Subject: slightly OT: Python BootCamp Message-ID: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> Ok... so I've been re-teaching myself python, as it's been several years since I last really used it. And in the midst of this, my contracting company came up to me on Friday and asked if I'd be interested in filling a last minute vacancy in this: http://www.otg-nc.com/python-bootcamp It's a week long Python Bootcamp. I figured, free class, a week where I'll not have to actually go to work, AND I'll get paid, sure! So I was just wondering if any of you have attended this one, or one like it, and what your impressions were. I've attended a few before, and found them widely different. The RH300, for example, was blisteringly fast and really just touches on things, so if you don't already know Red Hat inside and out, you'll never survive. The VMWare VCP courses, on the other hand, were fairly languid by contrast and seemed to flow in a less frantic state. So I figured this would be the place to ask. And if it matters, I do have an educational background in programming (VB, C++, C, Java, etc) but my professional background has mostly been limited to Bash, OCCASIONAL C, and now a touch of Python, so I am not new to programming and OO programming, just not as proficient as I would like to be... Cheers Jeff -- Jonathan Swift - "May you live every day of your life." - http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html From joost at h-labahn.de Sat Nov 28 21:32:09 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 18:32:09 -0800 (PST) Subject: Python3 - encoding issues Message-ID: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Hello, at first i must beg the pardon of those from you, whose mailboxes got flooded by my last announcement of depikt. I myself get no emails from this list, and when i had done my corrections and posted each of the sligthly improved versions, i wasn't aware of the extra emails that produces. Sorry ! I read here recently, that some reagard Python3 worse at encoding issues than former versions. For me, a German, quite the contrary is true. The automatic conversion without an Exception from before 3 has caused pain over pain during the last years. Even some weeks before it happened, that pygtk suddenly returned utf-8, not unicode, and my software had delivered a lot of muddled automatically written emails, before i saw the mess. Python 3 would have raised Exceptions - however the translation of my software to 3 has just begun. Now there is a concept of two separated worlds, and i have decided to use bytes for my software. The string representation, that output needs anyway, and with depikt and a changed apsw (file reads anyway) or other database-APIs (internally they all understand utf-8) i can get utf-8 for all input too. This means, that i do not have the standard string methods, but substitutes are easily made. Not for a subclass of bytes, that wouldn't have the b"...." initialization. Thus only in form of functions. Here are some of my utools: u0 = "".encode('utf-8') def u(s): if type(s) in (int, float, type): s = str(s) if type(s) == str: return s.encode("utf-8") if type(s) == bytes: # we keep the two worlds cleanly separated raise TypeError(b"argument is bytes already") raise TypeError(b"Bad argument for utf-encoding") def u_startswith(s, test): try: if s.index(test) == 0: return True except: # a bit frisky perhaps return False def u_endswith(s, test): if s[-len(test):] == test: return True return False def u_split(s, splitter): ret = [] while s and splitter in s: if u_startswith(s, splitter): s = s[len(splitter):]; continue ret += s[:s.index[splitter]] return ret + [s] def u_join(joiner, l): while True: if len(l) in (0,1): return l else: l = [l[0]+joiner+l[1]]+l[2:] (not all with the standard signatures). Writing them is trivial. Note u0 - unfortunately b"" doesn't at all work as expected, i had to learn the hard way. Looking more close to these functions one sees, that they only use the sequence protocol. "index" is in the sequence protocol too now - there the library reference has still to be updated. Thus all of these and much more string methods could get to the sequence protocol too without much work - then nobody would have to write all this. This doesn't only affect string-like objects: split and join for lists could open interesting possibilities for list representations of trees for example. Does anybody want to make a PEP from this (i won't do so) ? Joost Behrends From changlani.nitin at gmail.com Sat Nov 28 21:46:25 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sat, 28 Nov 2009 21:46:25 -0500 Subject: Variables with cross-module usage Message-ID: <647908460911281846n417041cagd5f1db0790e6f55c@mail.gmail.com> Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. > > > > > Hi Nitin, > > > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > >> Nitin Changlani. wrote: > >>> three.py > >>> ------------ > >>> import one > >>> import two > >>> > >>> def argFunc(): > >>> one.x = 'place_no_x' > >>> one.a = 'place_no_a' > >>> one.b = 'place_no_b' > >>> > > > > I think this is what is biting you. You might expect that after > > argFunc, one.x would be set to 'place_no_x' and so on. However, > > Python's scoping doesn't work like that -- the name one.x is only > > rebound in the function's scope, so outside of argFunc (e.g. in your > > main printing code) one.x is still bound to 'place_x'. > > No, It's not like that. MRAB had it. The thing is, that when one.py is > imported, it sets the name one.a to refer to a string 'place_a'. Then a > list named one.myList is built with one.myList[0] referring to the same > string as one.a . So far, so good. > > Then the function argFunc is called. It uses `one` as a name from its > global namespace. Inside argFunc, the names one.x and one.a are rebound to > different strings from the ones they started with. *But* one.myList[0] > isn't touched, and still refers to 'place_x' like it always did. > > Mel. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin at python.org Sat Nov 28 21:51:48 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 Nov 2009 02:51:48 +0000 (UTC) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Message-ID: DreiJane h-labahn.de> writes: > Does anybody want to make a PEP from this (i won't do so) ? I will answer this query with a little interactive prompt session: $ python3 Python 3.1.1 (r311:74480, Nov 14 2009, 13:56:40) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data = b"Good, morning" >>> data.startswith(b"Good") True >>> data.split(b", ") [b'Good', b'morning'] >>> x = data.split(b", ") >>> b", ".join(x) b'Good, morning' Bytes already have the basic string functions! From aahz at pythoncraft.com Sat Nov 28 21:56:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 18:56:28 -0800 Subject: slightly OT: Python BootCamp References: Message-ID: In article , J wrote: > >Ok... so I've been re-teaching myself python, as it's been several >years since I last really used it. And in the midst of this, my >contracting company came up to me on Friday and asked if I'd be >interested in filling a last minute vacancy in this: > >http://www.otg-nc.com/python-bootcamp No opinion, but just wanted to note that this is completely ON-topic for comp.lang.python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 22:01:46 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 19:01:46 -0800 Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: In article <6ded5cc9-5491-43d3-849c-17fcfaaec85f at k17g2000yqh.googlegroups.com>, papa hippo wrote: > >The prime goal of 'phileas' is to enable html code to be seamlessly >included in python code in a natural looking syntax, without resorting >to templatng language. > >see: > >http://larry.myerscough.nl/phileas_project/ Why would I want to use this instead of Quixote? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From joost at h-labahn.de Sat Nov 28 22:09:20 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 19:09:20 -0800 (PST) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Message-ID: <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Ohhh - that's nice. But no words of that in the library reference here: http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range Still this fails: >>> a = (1,2,3,4) >>> print(a.startswith((1,2))) Traceback (most recent call last): File "", line 1, in AttributeError: 'tuple' object has no attribute 'startswith' Still methods of this kind would have a better place in the sequence protocol. From changlani.nitin at gmail.com Sat Nov 28 22:18:11 2009 From: changlani.nitin at gmail.com (Nitin Changlani) Date: Sat, 28 Nov 2009 22:18:11 -0500 Subject: Variables with cross-module usage Message-ID: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. From joost at h-labahn.de Sat Nov 28 22:18:31 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 19:18:31 -0800 (PST) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Message-ID: <97629ae3-d3e9-4024-aed8-4ebcad2bfcb0@z41g2000yqz.googlegroups.com> No, sorry, i must correct me. There is a paragraph below on the quoted site. ".index" is still under "Mutable sequence types" - but bytes are treated below. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 22:39:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 03:39:56 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: <009b7185$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 17:22:27 -0800, The Music Guy wrote: > As for my specific use case, it's somewhat difficult to explain. The > general idea was to isolate a pattern that I spotted repeated in several > unrelated parts of my project. The pattern manifested itself as a set of > 4-5 methods and/or properties on a class whose objects were designed to > work in conjunction with other objects that fit a particular behavior. > These other objects had methods and properties that were designed to > interact with the first type of object in a similar but--how should I > say--"inverted" fashion. > > This pattern showed up in many different classes throughout the project, > and not only that, but the code was very similar. I decided to try to > eliminate some of the code redundancy by creating a base class for all > the classes to derive from. That didn't worked out okay for some things, > but not for others. I can't remember the exact details of the problem at > this point, but I believe it had to do with the keying/indexing protocol > (ie. __getitem__, __setitem__, etc.). I decided to keep the base class > (and have since extended it), but decided that it wasn't enough--that's > when I decided to try metaclassing. After some work I managed to > recreate the object-to- object relationship pattern that kept showing up > everywhere, but in a generic way that allowed for the names of methods > and properties that composed the pattern to vary in name and in the > names that they referenced from other objects. Removing code redundancy is all very well, but beware of turning into an architecture astronaut: http://www.joelonsoftware.com/articles/fog0000000018.html There is such a thing as over-generalisation -- if you're having to struggle to get the abstract code working abstractly enough, you're probably over-generalising. > The code worked very > well, and allowed for the pattern to be added to any class by using a > single, short line of code (something along the lines of __class_attr = > { key: value }). Not only that, but the metaclass code itself was > comprised of less than a screenful of code after docstrings and comments > had been removed. However, the code was (and still is) very difficult to > follow simply because of the way getters and setters had to be used to > generate the methods and properties. That's good evidence that you've over-generalised. -- Steven From benjamin at python.org Sat Nov 28 22:43:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 Nov 2009 03:43:21 +0000 (UTC) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Message-ID: DreiJane h-labahn.de> writes: > > Ohhh - that's nice. But no words of that in the library reference > here: > > http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range That's because it's here: http://docs.python.org/3.1/library/stdtypes.html#bytes-and-byte-array-methods > > Still this fails: > > >>> a = (1,2,3,4) > >>> print(a.startswith((1,2))) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'tuple' object has no attribute 'startswith' > > Still methods of this kind would have a better place in the sequence > protocol. You are welcome to bring this idea to the python-ideas list, just know that it has a small chance of being accepted. From inhahe at gmail.com Sat Nov 28 23:06:15 2009 From: inhahe at gmail.com (inhahe) Date: Sat, 28 Nov 2009 23:06:15 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: Message-ID: i like this idea (i posted some thoughts on it in the blog, but it's not approved yet as of this writing) in short, i suggested extending the idea to make it more a) generalized, b) simple, c) intuitive, and d) flexible. so instead of just using $ for attributes, you could use it anywhere you define or reference a name. as in.. class $a: pass or $a = 1 also, you might want to do something like this b = ["zero", "one"] $b[0] = 0 but that's ambiguous, so you need some sort of grouping mechanism like for example ${b[0]} = 0 although "$(b[0]) = 0" might be just as reasonable. also maybe: b = 'bar' foo$b = 'baz' print foobar #prints baz ${b}foo = 'baz' print barfoo #prints baz $foo{b}baz = 1 print foobarbaz #prints 1 but i know that last idea is getting way into php-land and probably isn't (quote-unquote) necessary. i know a lot of people would probably hate this idea with a passion. i tend to be more liberal when it comes to adding concision and dynamicism in a language, although that could be just because it's too tempting; i.e., maybe it's only because somebody drew a line somewhere that we're coding in Python instead of K. -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Nov 28 23:29:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 20:29:00 -0800 Subject: Imitating "tail -f" References: <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: In article , Matt Nordhoff wrote: >Jason Sewall wrote: >> >> FWIW, GNU tail on Linux uses inotify for tail -f: > >Some other operating systems have similar facilities, e.g. FSEvents on OS X. Having spent some time with FSEvents, I would not call it particularly similar to inotify. FSEvents only works at the directory level. Someone suggested pnotify the last time this subject came up, but I haven't had time to try it out. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From ldo at geek-central.gen.new_zealand Sat Nov 28 23:54:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 29 Nov 2009 17:54:42 +1300 Subject: Is It A Directory Message-ID: When doing recursive directory traversal, sometimes you want to follow symlinks that point at other directories, and sometimes you don?t. Here?s a routine that you can use to check whether a path specifies a directory, with the option to treat a symlink to a directory as a directory, or not: import os import stat def isdir(path, followsymlink) : """returns true iff path specifies a directory. A symlink is followed iff followsymlink.""" return stat.S_ISDIR((os.lstat, os.stat)[followsymlink](path).st_mode) #end isdir From steve at REMOVE-THIS-cybersource.com.au Sun Nov 29 01:02:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 06:02:41 GMT Subject: Variables with cross-module usage References: Message-ID: <009b92f9$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or > used in an expression. It doesn't come intuitively to me as to why that > should not happen. Can you kindly suggest what is the correct way to go > about it? You are confusing *names* and *objects*. The presence or absence of a module qualifier is irrelevant, so for simplicity I will avoid it. I will use ` ` quotation marks to refer to names, to avoid confusing them with strings. The Python statement a = "some text" creates a name `a` which is bound to the object "some text". myList[0] = a stores the object bound to the name `a` to the first position of myList, not the name itself. So myList[0] ends up being "some text", but it has no idea whether it came from the name `a` or somewhere else. Then when you execute: a = "different text" the name `a` is bound to the object "different text". But this doesn't affect myList[0] at all, because you're not changing the object "some text" -- strings are immutable and can't be changed. -- Steven From nad at acm.org Sun Nov 29 01:33:43 2009 From: nad at acm.org (Ned Deily) Date: Sat, 28 Nov 2009 22:33:43 -0800 Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> <009b4bab$0$26925$c3e8da3@news.astraweb.com> Message-ID: In article <009b4bab$0$26925$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > When it comes to integers, I'm not aware of any mathematical or > programming system which treats -0 and +0 as distinct entities, even if > they have different internal representations. A documented feature of most FORTRAN run-time libraries on the Control Data 6600/70/170 family (a one's-complement architecture cited earlier by Tim Roberts) was to convert a blank numeric input field (i.e. consisting of all space characters) to minus zero. Many programmers took advantage of that, using a test for -0 as an easy, though not 100% foolproof, test for a missing numeric value. -- Ned Deily, nad at acm.org From pok3r4life at gmail.com Sun Nov 29 02:03:34 2009 From: pok3r4life at gmail.com (Poker Player) Date: Sun, 29 Nov 2009 01:03:34 -0600 Subject: Best strategy for converting to Python Message-ID: <002b01ca70c2$11bff6c0$353fe440$@com> I have a calculator program that is written in Visual C# and I would like to convert it to python using any method possible. I am thinking I have to rewrite the GUI and use the Visual C# as I go to make sure I am doing it right but I have no idea as to how this should work when converting a program like this. I almost think I could start from scratch and write the whole thing that way but I want to make sure I do not lose any of the important functionality/features. I can provide any details needed I just don't want to jump in without some sort of guidance. Thanks, Spencer -------------- next part -------------- An HTML attachment was scrubbed... URL: From d.dalton at iinet.net.au Sun Nov 29 02:55:04 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 29 Nov 2009 18:55:04 +1100 Subject: python and vc numbers Message-ID: <20091129075503.GA25864@gwsc.vic.edu.au> Hi, I have a very simple problem, but I can't work out the answer. How do I return the current tty number in python? eg. what function/module should I use to figure out what tty my program was invoked from? Thanks -- Cheers, Dan http://members.iinet.net.au/~ddalton/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From FearsomeDragonfly at gmail.com Sun Nov 29 03:43:37 2009 From: FearsomeDragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 02:43:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> Message-ID: > > On Sat, Nov 28, 2009 at 9:39 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > > Removing code redundancy is all very well, but beware of turning into an > >> architecture astronaut: > >> > http://www.joelonsoftware.com/articles/fog0000000018.html > >> > There is such a thing as over-generalisation -- if you're having to > >> struggle to get the abstract code working abstractly enough, you're > probably over-generalising. > That's an interesting article, but I don't really understand what the author's point is. It's okay to generalize, but don't make a big fuss about it? It's okay, but don't do it anyway? I honestly can't tell. He seems to be criticizing a lot of good products (like Java), not because they are generalizations exactly, but because there is too much hype surrounding them. > Anyway, I'm not generalizing for the sake of generalizing. I'm generalizing because it appears to be a logical solution to a _specific_ problem, namely the fact that nearly identical class definition code was being repeated in several classes with only a few minor details difference. If it were a regular processing problem, a function would be created to do the repeated work, but since the redundancy occurs before any processing has occurred in the traditional sense, the redundancies have to be collected in a _different_ way. > Now that I think about it, though, Python 2.6 and above support decorators on classes (an example of generalization, by the way). The metaclass code could be moved almost verbatim to a decorator function which could then be used on classes that needed it. It would still be a mess, though. > hm...actually, inhahe's code made me realize that the metaclass could be cleaned up even more than I originally thought by the proposed syntax because it could be used for naming functions as well as attributes. ;^_^ > > > > The code worked very > >> > well, and allowed for the pattern to be added to any class by using a > >> > single, short line of code (something along the lines of __class_attr = > >> > { key: value }). Not only that, but the metaclass code itself was > >> > comprised of less than a screenful of code after docstrings and comments > >> > had been removed. However, the code was (and still is) very difficult to > >> > follow simply because of the way getters and setters had to be used to > >> > generate the methods and properties. > >> > That's good evidence that you've over-generalised. > I don't follow. Could you please be more specific? (no pun intended) -------------- next part -------------- An HTML attachment was scrubbed... URL: From n00m at narod.ru Sun Nov 29 03:56:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 00:56:16 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: My Py solution: ===================================================== import psyco psyco.full() def foo(s): n = len(s) s = s + ' ' a = [[] for i in xrange(128)] ans = 0 for i in xrange(n - 1, -1, -1): lev = 0 for st in xrange(len(a[ord(s[i])]) - 1, -1, -1): j = a[ord(s[i])][st] if (n - j <= lev): break if (s[j + lev] != s[i + lev]): continue if (s[j + lev / 2] != s[i + lev / 2]): continue k = 0 while (s[j + k] == s[i + k]): k += 1 if (k > lev): lev = k a[ord(s[i])] += [i] ans += n - i - lev return ans from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] print >> z, foo(s) print >> z, time() - t z.close() ======================================================== From pavlovevidence at gmail.com Sun Nov 29 03:57:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 00:57:21 -0800 (PST) Subject: slightly OT: Python BootCamp References: Message-ID: On Nov 28, 6:15?pm, J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. ?And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. I'm surprised they're able to fill out 5 days with intensive training on Python. :) Carl Banks From dreadpiratejeff at gmail.com Sun Nov 29 04:23:20 2009 From: dreadpiratejeff at gmail.com (J) Date: Sun, 29 Nov 2009 04:23:20 -0500 Subject: slightly OT: Python BootCamp In-Reply-To: References: Message-ID: <36dec4ff0911290123y38bf3d8fr6a8d2ae4af800cfe@mail.gmail.com> On Sun, Nov 29, 2009 at 03:57, Carl Banks wrote: > On Nov 28, 6:15?pm, J wrote: >> http://www.otg-nc.com/python-bootcamp >> >> It's a week long Python Bootcamp. > > > I'm surprised they're able to fill out 5 days with intensive training > on Python. > > :) Well, if it's anything like other similar courses I've taken over the years, the 10 minute break ever 2 hours will be more like 20 minutes, the hour lunch more like 1.5 hours, and the 8:30 to 4:00 times will be more like 8:45 to 3:15 ;) but on a serious note, your comment was why I was asking... I was trying to figure out just how much python you could teach in an assumed 40 hours... but it's also supposed to be probably 80% (arbitrary semi-educated guess) hands on coding, and if that's the case, each 30 minute project could well be 45 minutes to an hour depending on how fast people type, how familiar they are with actually properly formatting code, etc... -- Pablo Picasso - "Computers are useless. They can only give you answers." - http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html From n00m at narod.ru Sun Nov 29 04:26:23 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 01:26:23 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <0fff49e3-29ec-49fd-818e-0425ddacf71c@v30g2000yqm.googlegroups.com> This worked out in 5.28s Imo it's not that *much* slower (of course, Psyco can't help here) =================================== import itertools def subs(s): return len(set(itertools.chain( s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1)))) - 1 from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] print >> z, subs(s) print >> z, time() - t z.close() ================================================== From inhahe at gmail.com Sun Nov 29 04:42:30 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 04:42:30 -0500 Subject: Filling in a tuple from unknown size list In-Reply-To: References: Message-ID: maybe that thing in python 3 that someone mentioned is the answer, but otherwise i always think Python should admit something like this: a, b, c, *d = list i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] not that that solves the None problem, though i don't have any feature suggestions that would address that. On Fri, Nov 27, 2009 at 7:18 AM, boblatest wrote: > Hello all, > > (sorry for posting from Google. I currently don't have access to my > normal nntp account.) > > Here's my question: Given a list of onknown length, I'd like to be > able to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining > tuple elements to be set to "None". If the list is longer, I'd like > the excess elements to be ignored. > > The code snippet below does what I want, I was just wondering if there > was an interesting "Pythonic" way of expressing the same thing. > > Thanks, > robert > > def iter_inf(li, n): > for i in range(n): > if i < len(li): > r = li[i] > else: > r = None > i += 1 > yield r > > > li = ['a', 'b', 'c'] > (a, b, c, d, e) = iter_inf(li, 5) > print a, b, c, d, e > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From inhahe at gmail.com Sun Nov 29 05:01:15 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 05:01:15 -0500 Subject: Filling in a tuple from unknown size list In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 4:42 AM, inhahe wrote: > maybe that thing in python 3 that someone mentioned is the answer, but > otherwise i always think Python should admit something like this: > > a, b, c, *d = list > > i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] > > not that that solves the None problem, though i don't have any feature > suggestions that would address that. > > Maybe instead of Python working this way: >>> a, b = xrange(10) Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack it should work this way: >>> a, b = xrange(10) >>> print a, b 0 1 and then they could include something in itertools that automatically fills extras with None, like Peter Otten's implementation but without having to pass it a value for the number of assignments, i.e.: a, b, c = itertools.ifill(list) with None being the default fill value, but if we wanted 1 to be, we could do a, b, c = itertools.ifill(list, 1) -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Sun Nov 29 05:15:25 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 02:15:25 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> Message-ID: <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Okay, I'm having a really hard time telling which messages are getting on to the list and which ones aren't. Some of the messages I send show up in the comp.lang.python mirror in Google Groups, and some aren't. Others show up on the Groups mirror, but don't show up in Gmail, or show up in a different order. It seems the only way I can guarantee anything showing up on Groups is to post on Groups, but that makes it difficult because I can't see the messages in the thread that only appear in my inbox. Is there a quick fix for this, because it's getting pretty aggravating trying to figure out who heard what. I don't like mailing lists. :P From qwertzuioplkjhgfdsayxcvbnm at gmail.com Sun Nov 29 05:56:28 2009 From: qwertzuioplkjhgfdsayxcvbnm at gmail.com (fejky) Date: Sun, 29 Nov 2009 02:56:28 -0800 (PST) Subject: Simple greatest common factor script Message-ID: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Simple script that calculates greatest common factor using euclid's theorem. a = int(input("Enter a: ")) b = int(input("Enter b: ")) m = 1 while True: if m != 0: if b > a: n = b/a m = b % a print b, " : ", a, " = ", n, " i ost ", m b = m if a > b: n = a/b # line 13 m = a % b print a, " : ", b, " = ", n, " i ost ", m a = m if a == b: print "NZM(", a, ",", b, ") = ", a m = 0 else: break but when i run this script: Enter a: 12345 Enter b: 54321 54321 : 12345 = 4 i ost 4941 12345 : 4941 = 2 i ost 2463 4941 : 2463 = 2 i ost 15 2463 : 15 = 164 i ost 3 15 : 3 = 5 i ost 0 Traceback (most recent call last): File "D:\Programing\Python_2.6\math\NZM.py", line 13, in n = a/b ZeroDivisionError: integer division or modulo by zero I don't see how this script is able to divide by zero. If a and b switch places everything works ok. Thanks From patrick.just4fun at gmail.com Sun Nov 29 06:18:51 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Sun, 29 Nov 2009 12:18:51 +0100 Subject: Simple greatest common factor script In-Reply-To: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> References: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Message-ID: <4B12589B.9060201@gmail.com> > I don't see how this script is able to divide by zero. If a and b > switch places everything works ok. Have a look at your if-statements. It is possible, that both your if's are executed in one loop iteration (you can check this using pdb). You may want to try elif instead. - Patrick From qwertzuioplkjhgfdsayxcvbnm at gmail.com Sun Nov 29 06:23:25 2009 From: qwertzuioplkjhgfdsayxcvbnm at gmail.com (fejky) Date: Sun, 29 Nov 2009 03:23:25 -0800 (PST) Subject: Simple greatest common factor script References: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Message-ID: <18ce3156-f8cb-4d35-ab59-c616332f4db0@m3g2000yqf.googlegroups.com> I have no idea how i missed that. Thanks! From inhahe at gmail.com Sun Nov 29 06:58:33 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 06:58:33 -0500 Subject: Feature request: String-inferred names In-Reply-To: <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 5:15 AM, The Music Guy wrote: > Okay, I'm having a really hard time telling which messages are getting > on to the list and which ones aren't. Some of the messages I send show > up in the comp.lang.python mirror in Google Groups, and some aren't. > Others show up on the Groups mirror, but don't show up in Gmail, or > show up in a different order. It seems the only way I can guarantee > anything showing up on Groups is to post on Groups, but that makes it > difficult because I can't see the messages in the thread that only > appear in my inbox. Is there a quick fix for this, because it's > getting pretty aggravating trying to figure out who heard what. I > don't like mailing lists. :P > -- > http://mail.python.org/mailman/listinfo/python-list > Did you say you were using gmail to post? I think mailing lists tend to have issues with gmail because it puts html in the message or something like that. Btw I recently set up this mailing list to send me a message back when I successfully posted something. oddly enough, i only remember getting one such message, so maybe none of my other messages got through. :P i think there's a way to disable html when sending a gmail message, but don't quote me on that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From inhahe at gmail.com Sun Nov 29 07:10:20 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 07:10:20 -0500 Subject: Arcane question regarding white space, editors, and code collapsing In-Reply-To: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> Message-ID: I had this same problem with an application called Notepad++, which is a shame because I like the way it works and it's nice and tight. Now I use Komodo Edit instead, which doesn't have that problem, and has all the features of Notepad++ but just isn't as fast. Also all the colors were awful, and I realized Notepad++'s were perfect so I spent some time using GetColor! to sample every token color Notepad++ uses and configure Komodo Edit to do the same. I guess this is all irrelevant information since you don't even use a PC, but I just wanted to say that apparently this strange problem is a popular phenomenon. And that Komodo Edit is cool. On Wed, Nov 18, 2009 at 6:28 PM, Wells wrote: > I work in TextMate a lot, which I generally love, but it's code > collapsing confounds me. Essentially you have to indent blank lines to > the proper level for the current block. Then it will collapse that > section as one section. If you have simply a new line, it will see it > as a break, and not collapse, though the python interpreter doesn't > care- it only cares about lines of actual code. > > Is it... pythonic, then, to have these lines of tabs/spaces to support > code collapsing? Is it proper, improper, or irrelevant? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From yosato16 at gmail.com Sun Nov 29 07:29:17 2009 From: yosato16 at gmail.com (Yo Sato) Date: Sun, 29 Nov 2009 12:29:17 +0000 Subject: debugger on system with Python 2 and 3 Message-ID: Thanx Alan, I am using Fedora Core 11. I wanted to use emacs, rather than the full-blown IDE or entirely gui-based debugger, and that's why I was drawn to pydb in the first instance. If there's no other choice I don't mind using winpdb, but it is installed (through Yum) under Python2 library and invokes Py2 at default... Don't quite know how to adapt it to Py3 or install the right version under the right directory, yet. It seems as if some environmental variable change is necessary. On the whole it doesn't seem that there's much support in the third-party debuggers in general as yet... In the meantime I might ask if it is possible to adapt pydb (or perhaps, IDLE) for Py3. Might be just a change in a env variable or two... Yo On Fri, 27 Nov 2009 19:03:10 +0000, Alan Franzoni wrote: > On 11/27/09 6:17 PM, Yo Sato wrote: >> Hi, >> >> I am a relative newcomer to the Python language, and only write Python >> 3. Now I would very much like to a more-than-basic debugger. However it >> seems as if the fact that I have both Python 2 and 3 on the system >> complicates the matter... > > You haven't told OS which OS you're using, and what are your exact > problems, BTW I think two good debuggers for Python are winpdb/rpdb2 > (work on any platform, despite the name) and the one you get in > Eclipse+Pydev. > > You should be able to pick your platform, even though I've never tested > them in Python 3. From bearophileHUGS at lycos.com Sun Nov 29 08:07:15 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:07:15 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <0fff49e3-29ec-49fd-818e-0425ddacf71c@v30g2000yqm.googlegroups.com> Message-ID: n00m: > This worked out in 5.28s > Imo it's not that *much* slower > (of course, Psyco can't help here) There's no need of a chain here, so you can rewrite this: import itertools def subs(s): return len(set(itertools.chain( s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1)))) - 1 as: def subs(s): return len(set(s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1))) - 1 Psyco helps a little (about 10% on my PC) if you use it like this: from time import time import psyco; psyco.full() def main(): t = time() fin = open("input.txt") fout = open("output.txt", "w") fin.next() for line in fin: r = set() s = line.rstrip() len_s = len(s) for i in xrange(len_s): for j in xrange(i, len_s + 1): r.add(s[i : j]) print >> fout, len(r) - 1 fout.close() print time() - t main() Bye, bearophile From bearophileHUGS at lycos.com Sun Nov 29 08:12:07 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:12:07 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <6005ac23-cad7-4951-ab13-ba9097fa95df@p35g2000yqh.googlegroups.com> n00m: > My Py solution: > ... Cute. You can replace: a[ord(s[i])] += [i] With: a[ord(s[i])].append(i) If you want to micro-optimize this with Psyco may be a little faster: (lev >> 1) Than: lev // 2 But to increase speed it's usually better to reduce memory allocations. So you can try to find a way to pull this out of the function: a = [[] for i in xrange(128)] And to avoid a true append: a[ord(s[i])] += [i] (There are many ways to avoid an append. One of them is to have an already allocated list/array and just bump forward an index variable that starts from 0. This is worth doing especially when you use Psyco). Bye, bearophile From thesul1970 at googlemail.com Sun Nov 29 08:14:43 2009 From: thesul1970 at googlemail.com (Paul O'Sullivan) Date: Sun, 29 Nov 2009 05:14:43 -0800 (PST) Subject: mysqldb cursor returning type along with result ? Message-ID: Just taken to Python (2.5)and started to look at some DB cursor stuff using MySQL. Anyway, after creating a query that in MySQL that has a result set of decimals I find that the cursor in python after a fetchall() returns a tuple that contains the following :: ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal ("98.08"),), (Decimal("97.73"),)) as such : sum(result) fails with "TypeError: unsupported operand type(s) for +: 'int' and 'tuple'" How do I either get the resultset back as 'float' or convert the returned tuple to 'floats'.? Thanks, Newb. From bearophileHUGS at lycos.com Sun Nov 29 08:15:14 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:15:14 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> n00m: > my home tests proved Python is a fellow fast beast of C++. > Quite unexpected (I expected Py would be by ~10 times slower). > PS > Both my codes are identical in their algorithms. > ============================= > 0.016 ? ? ? ? 0.0150001049042 ? <--- exec times Maybe in your C++ code there's something that can be improved, this is a 1:1 translation to D (V.1) language (using dlibs) and it's about 2.2 times faster than the Psyco version: http://codepad.org/MQLj0ydB Using a smarter usage of memory (that is avoiding all or most memory allocations inside all loops), the performance difference will surely grow. Bye, bearophile From inhahe at gmail.com Sun Nov 29 08:25:21 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 08:25:21 -0500 Subject: staticmethod not callable? (trying to make a Singleton metaclass..) Message-ID: I'm trying to come up with a system for singletons, where I don't have to modify anything for an individual class except to define __metaclass__ or, if possible, to inherit another class. I want it to raise an error if making a duplicate instance of a class is attempted, rather than to return the same object, because my philosophy is that if your class is a singleton and you're trying to make another instance of it then you're doing it wrong and you should probably know. Although the way I'm trying to do it could apply to either philosophy. I've seen several solutions for singletons in Python, but I don't like them, either because they require modification to each individual singleton class, or they require something after the class definition like Class = Class(), or I totally don't understand them. The novel way I've attempted to come up with is this: class Singleton(type): def __new__(meta, classname, bases, classDict): @staticmethod def nonewinst(*args, **kwargs): raise ValueError("Can't make duplicate instance of singleton " + classname) @staticmethod def newoldnew(obj): return obj oldnew = classDict.get("__new__", newoldnew) @staticmethod def newnew(obj, *args, **kwargs): o = oldnew(obj, *args, **kwargs) obj.__new__ = nonewinst return o classDict["__new__"] = newnew return type.__new__(meta, classname, bases, classDict) a little bit of experimentation revealed that apparently even functions defined within a method become class methods, so i tried making them all static methods. however, python is strange to me when it comes to methods and the self parameter. i mean i understand a function being free of the class so that the 'self' parameter doesn't mean anything in particular unless you explicitly pass it an instance. and i understand the method being bound to an object so that when it's called its self parameter is automatically sent the instance. but python seems to have this in-between mode where sometimes a function isn't particularly bound to an instance but if you try to pass the wrong kind of instance to 'self' it'll complain, which gets annoying, and i don't understand how its binding works. but anyway, the problem i'm currently having with the code might not even be related to that..because here's the error I'm getting: >>> from funcs import Singleton >>> class A: ... __metaclass__ = Singleton ... >>> b = A() Traceback (most recent call last): File "", line 1, in File "c:\python25\funcs.py", line 68, in newnew o = oldnew(obj, *args, **kwargs) TypeError: 'staticmethod' object is not callable i'm not that experienced with metaclasses, but it seems to me that something's obviously going fubar here because at that point oldnew should be the function newoldnew (since class A doesn't have a __new__ defined) which is clearly defined right there with a staticmethod decorator, and first of all, functions *should* be callable, and secondly, why is my object a 'staticmethod' object just because I used a decorator on it? it would seem it should be a function, so i tested it like this: >>> class A: ... @staticmethod ... def b(): pass ... >>> type(A.b) in that case, using @staticmethod returns a function. i have nfi why it's different in my Singleton class. oh, and thirdly, staticmethod is a decorator and decorators are callables so even given that for some mysterious reason it's a staticmethod object i don't know why it's not callable. so that's pretty confusing. can anyone clear this up for me? thanks.. ps. i'm aware of the evils of singletons and all that. short answer: I don't care. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 29 08:54:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 07:54:35 -0600 Subject: mysqldb cursor returning type along with result ? In-Reply-To: References: Message-ID: <4B127D1B.1000200@tim.thechases.com> > ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), > (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal > ("98.08"),), (Decimal("97.73"),)) > > as such : > sum(result) > fails with "TypeError: unsupported operand type(s) for +: 'int' and > 'tuple'" > > How do I either get the resultset back as 'float' or convert the > returned tuple to 'floats'.? Well, what you have is a tuple-of-tuples-of-decimals, and Sum can handle Decimal types just fine. You simply have to extract the first (only) item in each row: sum(row[0] for row in result) or sum(value for (value,) in result) whichever makes more sense to you. -tkc From n00m at narod.ru Sun Nov 29 09:10:46 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 06:10:46 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> Message-ID: <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> On Nov 29, 3:15?pm, Bearophile wrote: > Maybe in your C++ code there's something that can be improved, this is > a 1:1 translation to D (V.1) language (using dlibs) and it's about 2.2 > times faster than the Psyco version:http://codepad.org/MQLj0ydB > Using a smarter usage of memory (that is avoiding all or most memory > allocations inside all loops), the performance difference will surely > grow. Very interesting. Thanks. D code looks pretty neat. Btw D lang is among accepted langs there. Even if Py by 4x *slower* -- it's still a perfect Ok for it (C# will be much (much) slower than Python). Micro-optimizations. Of course, the best optimization would be to implement Suffix Tree: http://en.wikipedia.org/wiki/Trie Currently I hardly understand/know/read/etc its core idea. My algo is plainly stupid as soldier muddy boots. My C++ code: #include #include //#include //#include //#include #include #include #include #include using namespace std; int main() { clock_t start_time = clock(); freopen("88.txt", "rt", stdin); freopen("99.txt", "wt", stdout); int tcs; string s; cin >> tcs; while (tcs-- > 0) { cin >> s; int n = s.size(); s = s + ' '; vector< vector > a(128); int ans = 0; for (int i = n - 1; i >= 0; --i) { int lev = 0; for (int st = (int)a[s[i]].size() - 1; st >= 0; --st) { int j = a[s[i]][st]; if (n - j <= lev) break; if (s[j + lev] != s[i + lev]) continue; if (s[j + lev / 2] != s[i + lev / 2]) continue; int k = 0; while (s[j + k] == s[i + k]) ++k; if (k > lev) lev = k; } a[s[i]].push_back(i); ans += n - i - lev; } cout << ans << endl; } cout << (clock() - start_time) / CLOCKS_PER_SEC << endl; return 0; } From n00m at narod.ru Sun Nov 29 09:13:41 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 06:13:41 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: http://en.wikipedia.org/wiki/Suffix_tree Looks not very friendly appealing :-) From russandheather at gmail.com Sun Nov 29 09:25:24 2009 From: russandheather at gmail.com (Russell Warren) Date: Sun, 29 Nov 2009 06:25:24 -0800 (PST) Subject: * for generic unpacking and not just for arguments? Message-ID: Is there a reason that this is fine: >>> def f(a,b,c): ... return a+b+c ... >>> f(1, *(2,3)) 6 but the code below is not? >>> x = (3, 4) >>> (1, 2, *x) == (1, 2, 3, 4) Traceback (most recent call last): File "", line 1, in invalid syntax: , line 1, pos 8 Why does it only work when unpacking arguments for a function? Is it because the code below is preferred, and more readable? >>> x = (3, 4) >>> (1, 2) + x == (1, 2, 3, 4) True I've rooted around to see if there is an answer already and found some threads going way back to 1998 (!!), but can't find a concise answer as to why it is limited to args. I don't have a burning desire for this to work, but I just tried it unsuccessfully when building up a tuple and was mildly surprised that it didn't work, so I'm curious why. Maybe it's just that * is strictly for arguments, and trying it for generic tuple unpacking is abuse (which is down the corridor in 12A). From inhahe at gmail.com Sun Nov 29 09:36:21 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 09:36:21 -0500 Subject: Number of distinct substrings of a string [continuation] In-Reply-To: <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 9:10 AM, n00m wrote: > > Even if Py by 4x *slower* -- it's still a perfect Ok for it (C# will > be > much (much) slower than Python). > > How do you figure? As far as I know C# is many, many times faster than Python. (i was disappointed to find out that even IronPython is dozens of times slower than other .net langs) -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Sun Nov 29 09:58:57 2009 From: drobinow at gmail.com (David Robinow) Date: Sun, 29 Nov 2009 09:58:57 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Message-ID: <4eb0089f0911290658p107f0c5eg2e327b85592054cc@mail.gmail.com> On Sun, Nov 29, 2009 at 6:58 AM, inhahe wrote: > Did you say you were using gmail to post? ?I think mailing lists tend to > have issues with gmail because it puts html in the message or something like > that. ?Btw I recently set up this mailing list to send me a message back > when I successfully posted something. ?oddly enough, i only remember getting > one such message, so maybe none of my other messages got through. :P > i think there's a way to disable html when sending a gmail message, but > don't quote me on that. I wasn't aware it was possible to Enable html but apparently it is. Let me know if you see any html in this post. From mwilson at the-wire.com Sun Nov 29 10:40:29 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 29 Nov 2009 10:40:29 -0500 Subject: * for generic unpacking and not just for arguments? References: Message-ID: Russell Warren wrote: > Maybe it's just that * is strictly for arguments, and trying it for > generic tuple unpacking is abuse (which is down the corridor in 12A). I'd agree with that. It's a feature of function calls, not a feature of sequence types, so that you can handle a set of function arguments as a bunch, and apply them when you want. The other function call feature that sequence types don't do is a, b, c = **{'b':3, 'c':a, 'a':c} Mel. From aahz at pythoncraft.com Sun Nov 29 10:52:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 07:52:23 -0800 Subject: python setup.py build 32-bits on x86_64 machine References: <4b08d6e9$0$28097$a729d347@news.telepac.pt> Message-ID: In article <4b08d6e9$0$28097$a729d347 at news.telepac.pt>, =?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto wrote: > >I am in x86_64 arch , but I need >compile things on 32 bits. >python setup.py build Googling for "linux force 32-bit build" and similar phrases should find some useful results. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sun Nov 29 10:55:57 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 02:55:57 +1100 Subject: string payload expected: error In-Reply-To: References: <4b0ef5da$1@dnews.tpgi.com.au> Message-ID: <4b1299f3$1@dnews.tpgi.com.au> On 11/27/2009 8:43 PM, Ramdas wrote: > I tried with MIMEBASE but it still fails...... I changed it to > MIMEText, hoping that might trick __handletext to think its a string > Anyway that also doesn't work. > just pass the string directly to MIMEBase.set_payload: fp = open('...') msg1 = MIMEBase(maintype, subtype) msg1.set_payload(fp.read()) either that or use a more specialized subclass of MIMEBase (e.g. MIMEText). From lie.1296 at gmail.com Sun Nov 29 10:57:35 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 02:57:35 +1100 Subject: mysqldb cursor returning type along with result ? In-Reply-To: References: Message-ID: <4b129a54$1@dnews.tpgi.com.au> On 11/30/2009 12:14 AM, Paul O'Sullivan wrote: > Just taken to Python (2.5)and started to look at some DB cursor stuff > using MySQL. Anyway, after creating a query that in MySQL that has a > result set of decimals I find that the cursor in python after a > fetchall() returns a tuple that contains the following :: > > ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), > (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal > ("98.08"),), (Decimal("97.73"),)) > > as such : > sum(result) > fails with "TypeError: unsupported operand type(s) for +: 'int' and > 'tuple'" > > How do I either get the resultset back as 'float' or convert the > returned tuple to 'floats'.? I believe it returned decimal.Decimal() objects. You can do arithmetic with decimal.Decimals, so: sum(x[0] for x in result) From aahz at pythoncraft.com Sun Nov 29 10:57:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 07:57:52 -0800 Subject: xmlrpc idea for getting around the GIL References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> <4b0b07a1$0$22159$9b622d9e@news.freenet.de> Message-ID: In article <4b0b07a1$0$22159$9b622d9e at news.freenet.de>, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: > >In any case, I don't think you'll need a multi-process solution; a >single-process multi-threading approach will do fine. Just create >*another* thread, that runs at a low priority and is allowed to block. >Run the Python interpreter in that thread (create multiple of these if >you need them). Then, use some queuing producer-consumer communication >between the high-priority thread and the low priority thread. Have the >high priority threads put requests into the queue, and the low priority >thread take them from the queue, dispatching them to Python. Make sure >you use non-blocking synchronization on the queue, or else priority >inheritance if you can get permission to do so. This is close to what I would recommend, but I would suggest that the low-priority thread make calls out to an external Python process; that way, you can have a Python worker pool of processes. Based on what I've seen posted over the years, I generally recommend against instantiating multiple interpreter instances (although I've seen some success stories, I've seen more people butting their heads against the brick wall). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From showell30 at yahoo.com Sun Nov 29 10:58:05 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 29 Nov 2009 07:58:05 -0800 (PST) Subject: slightly OT: Python BootCamp References: Message-ID: <5c045972-d7f1-42f1-a7e5-9989eb8b7c6f@s21g2000prm.googlegroups.com> On Nov 28, 6:15?pm, J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. ?And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. ?I figured, free class, a week where > I'll not have to actually go to work, AND I'll get paid, suore! > I have never been, but it seems like a no-brainer to attend. Even if the class totally sucks, which I doubt, you will also have the opportunity to network with people with similar interests. If your ONLY objective in life was to learn Python, then I would recommend just hitting the books. From n00m at narod.ru Sun Nov 29 11:00:38 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 08:00:38 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Tested both my codes against a random string of length = 10000. =========================================== from random import choice s = '' for i in xrange(10000): s += choice(('a','b','c','d','e','f')) =========================================== C++: ~0.28s Python: ~0.48s PS I suspect that building of Suffix Tree would be a big exec.time-consuming overhead From aahz at pythoncraft.com Sun Nov 29 11:01:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 08:01:10 -0800 Subject: slightly OT: Python BootCamp References: Message-ID: In article , J wrote: >On Sun, Nov 29, 2009 at 03:57, Carl Banks wrote: >> On Nov 28, 6:15=A0pm, J wrote: >>> >>> http://www.otg-nc.com/python-bootcamp >>> >>> It's a week long Python Bootcamp. >> >> >> I'm surprised they're able to fill out 5 days with intensive training >> on Python. > >but on a serious note, your comment was why I was asking... I was >trying to figure out just how much python you could teach in an >assumed 40 hours... but it's also supposed to be probably 80% >(arbitrary semi-educated guess) hands on coding, and if that's the >case, each 30 minute project could well be 45 minutes to an hour >depending on how fast people type, how familiar they are with actually >properly formatting code, etc... There are a couple of ways you can get benefit out of this even if the class itself isn't that useful for you: * Spend time working on Python projects from your job without the pressure of being at work * Help the other people in the class learn Python, which will cement your knowledge -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sun Nov 29 11:06:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 08:06:40 -0800 Subject: Implementation of Book Organization tool (Python2.[x]) References: <4b0a06b8$1@dnews.tpgi.com.au> Message-ID: In article <4b0a06b8$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > >Python dictionary is stored in memory and closing the program == >deleting the database. You can pickle dictionary; and this might be >sufficient for quick and dirty, low-volume purpose. Pickled dictionary >is the least portable solution; only python program can open a >pickled dictionary and even different versions of python may have >incompatibilities. While that last sentence is technically true, I've never seen it be an issue for this kind of application when changing versions upward. IOW, pickles from previous versions of Python can almost always be read. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aioe.org at technicalbloke.com Sun Nov 29 11:08:24 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sun, 29 Nov 2009 16:08:24 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > r0g wrote: >> Gabriel Genellina wrote: >>> En Fri, 27 Nov 2009 22:35:36 -0300, r0g >>> escribi?: >>> >>>> gethostbyname ignores setdefaulttimeout. >>>> >>>> How big a job is it to use non-blocking sockets to write a DNS lookup >>>> function with a customisable timeout? A few lines? A few hundred? I'd > > > As usual, everything is working beautifully until I try to make it work > with windows! > > Turns out signals.SIGALRM is Unix only and I want to run on both > platforms so I have done as the docs suggested and tried to convert the > code to use threading.Timer to trigger an exception if the DNS lookup is > taking too long. Actually none of that was necessary in the end. Digging into the pydns source to debug the 30 second pause I happened across the timeout parameter! >>> result = ping.do_one( "google.com", 5 ) "" Phew, that simplifies thing a lot! :) Roger. From inhahe at gmail.com Sun Nov 29 11:09:04 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 11:09:04 -0500 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 10:40 AM, Mel wrote: > Russell Warren wrote: > >> Maybe it's just that * is strictly for arguments, and trying it for >> generic tuple unpacking is abuse (which is down the corridor in 12A). > > I'd agree with that. ?It's a feature of function calls, not a feature of > sequence types, so that you can handle a set of function arguments as a > bunch, and apply them when you want. > > The other function call feature that sequence types don't do is > > a, b, c = **{'b':3, 'c':a, 'a':c} > > > ? ? ? ?Mel. > > that's wicked i'd go for that i'd definitely go for the a, b, *c = lst syntax though From lists at cheimes.de Sun Nov 29 11:09:09 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 29 Nov 2009 17:09:09 +0100 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: Russell Warren wrote: > but the code below is not? > >>>> x = (3, 4) >>>> (1, 2, *x) == (1, 2, 3, 4) > Traceback (most recent call last): > File "", line 1, in > invalid syntax: , line 1, pos 8 > > Why does it only work when unpacking arguments for a function? Is it > because the code below is preferred, and more readable? > >>>> x = (3, 4) >>>> (1, 2) + x == (1, 2, 3, 4) > True > > I've rooted around to see if there is an answer already and found some > threads going way back to 1998 (!!), but can't find a concise answer > as to why it is limited to args. The feature is available in Python 3.x: >>> a, b, *c = 1, 2, 3, 4, 5 >>> a, b, c (1, 2, [3, 4, 5]) >>> a, *b, c = 1, 2, 3, 4, 5 >>> a, b, c (1, [2, 3, 4], 5) Christian From senhor.abrantes at gmail.com Sun Nov 29 12:03:05 2009 From: senhor.abrantes at gmail.com (joao abrantes) Date: Sun, 29 Nov 2009 17:03:05 +0000 Subject: Auto net surfing Message-ID: <880fa1d40911290903g2eadd36j67c78e2ca27e2914@mail.gmail.com> How can I make a python program that votes on certain polls ? Atm I am using ClientForm to fill forms but the polls that I found are always of the type = "hidden" and I don't know how to do it. I would also want to do a python program that would vote on a website. For example, if I go to this url http://games.top.org/ultima-online/ while I am on this site: http://www.uo.burstfire.net/ that site will win a vote... if i got to the same url but while i am on this site http://www.drw.ru/en/ the vote goes to this one. Well how can I make python give me the vote for a certain site? I don't know how this vote systems work sorry for the noob questions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From missive at hotmail.com Sun Nov 29 12:34:14 2009 From: missive at hotmail.com (Lee Harr) Date: Sun, 29 Nov 2009 22:04:14 +0430 Subject: [ANNC] pybotwar-0.7 Message-ID: pybotwar is a fun and educational game where players write computer programs to control simulated robots. http://pybotwar.googlecode.com/ pybotwar uses pybox2d for the physical simulation. It can be run in text-only mode -- useful for longer tournaments -- or use pyqt or pygame for a graphical interface and visualization of the action. pybotwar is released under GPLv3. Changes in pybotwar-0.7: ??? - pybox2d-2.0.2b1 compatibility (latest pybox2d release) ??? - decouple view modules so unused graphic modules are not required ??? - added new "pinged" sensor to detect when robot is seen by others ??? - randomize order robots are handled each tick ??? - PyQt4 interface improvements ??????? - new battle dialog to select combatants ??????? - internal text editor improvements ??????? - allow multiple open editor windows ??????? - do a few simple checks on robot programs when saving _________________________________________________________________ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010 From gagsl-py2 at yahoo.com.ar Sun Nov 29 12:58:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 29 Nov 2009 14:58:14 -0300 Subject: staticmethod not callable? (trying to make a Singleton metaclass..) References: Message-ID: En Sun, 29 Nov 2009 10:25:21 -0300, inhahe escribi?: > I'm trying to come up with a system for singletons, where I don't have to > modify anything for an individual class except to define __metaclass__ > or, > if possible, to inherit another class. > > I want it to raise an error if making a duplicate instance of a class is > attempted, rather than to return the same object, (I won't comment on the usefulness of such approach...) > class Singleton(type): > def __new__(meta, classname, bases, classDict): > @staticmethod > def nonewinst(*args, **kwargs): > raise ValueError("Can't make duplicate instance of singleton " + > classname) > @staticmethod > def newoldnew(obj): > return obj > oldnew = classDict.get("__new__", newoldnew) > @staticmethod > def newnew(obj, *args, **kwargs): > o = oldnew(obj, *args, **kwargs) > obj.__new__ = nonewinst > return o > classDict["__new__"] = newnew > return type.__new__(meta, classname, bases, classDict) __new__ is a classmethod, not a staticmethod. > a little bit of experimentation revealed that apparently even functions > defined within a method become class methods, ???????? > so i tried making them all > static methods. ???????? Why do you insist on static methods? > however, python is strange to me when it comes to methods > and the self parameter. i mean i understand a function being free of the > class so that the 'self' parameter doesn't mean anything in particular > unless you explicitly pass it an instance. and i understand the method > being bound to an object so that when it's called its self parameter is > automatically sent the instance. but python seems to have this > in-between > mode where sometimes a function isn't particularly bound to an instance > but > if you try to pass the wrong kind of instance to 'self' it'll complain, > which gets annoying, and i don't understand how its binding works. Do you mean this error? Traceback (most recent call last): File "", line 1, in TypeError: unbound method foo() must be called with X instan ce as first argument (got Y instance instead) This kind of check was removed in Python 3; ClassName.method_name yields a plain function, not an unbound method as in 2.x > but > anyway, the problem i'm currently having with the code might not even be > related to that..because here's the error I'm getting: > >>>> from funcs import Singleton >>>> class A: > ... __metaclass__ = Singleton > ... >>>> b = A() > Traceback (most recent call last): > File "", line 1, in > File "c:\python25\funcs.py", line 68, in newnew > o = oldnew(obj, *args, **kwargs) > TypeError: 'staticmethod' object is not callable That's true: instances of the staticmethod type are not callable. > i'm not that experienced with metaclasses, but it seems to me that > something's obviously going fubar here because at that point oldnew > should > be the function newoldnew (since class A doesn't have a __new__ defined) > which is clearly defined right there with a staticmethod decorator, and > first of all, functions *should* be callable, and secondly, why is my > object > a 'staticmethod' object just because I used a decorator on it? it would > seem it should be a function, so i tested it like this: > >>>> class A: > ... @staticmethod > ... def b(): pass > ... >>>> type(A.b) > > > in that case, using @staticmethod returns a function. i have nfi why > it's > different in my Singleton class. > > oh, and thirdly, staticmethod is a decorator and decorators are > callables so > even given that for some mysterious reason it's a staticmethod object i > don't know why it's not callable. so that's pretty confusing. can > anyone > clear this up for me? thanks.. staticmethod is a type: py> staticmethod Used as a decorator, it's like this: def b(): pass b = staticmethod(b) so b is an staticmethod instance. You can confirm this looking into the class: py> A.__dict__['b'] py> A.b A staticmethod instance is a descriptor; its __get__ method is invoked to resolve A.b (or getattr(A, "b")). If you retrieve it directly, you get the staticmethod object which is not callable: py> A.__dict__['b']() Traceback (most recent call last): File "", line 1, in TypeError: 'staticmethod' object is not callable Going back to your original goal, your code at the top is really a mess. I would not even use a metaclass. If you want to avoid creating more than one instance, just record the fact that you created it in the class constructor, __new__: class HardSingleton(object): "Only one instance of its subclasses may be created ever" _created = False def __new__(cls, *args, **kw): if cls._created: raise ValueError("Can't make duplicate instance of singleton %s" % cls.__name__) result = super(HardSingleton, cls).__new__(cls, *args, **kw) cls._created = True return result class A(HardSingleton): def __init__(self): print "A" s1 = A() s2 = A() -- Gabriel Genellina From russandheather at gmail.com Sun Nov 29 13:01:42 2009 From: russandheather at gmail.com (Russell Warren) Date: Sun, 29 Nov 2009 10:01:42 -0800 (PST) Subject: * for generic unpacking and not just for arguments? References: Message-ID: <039c00e7-324d-463e-84a8-fbf2bc42bb3a@x5g2000prf.googlegroups.com> On Nov 29, 11:09?am, Christian Heimes wrote: > The feature is available in Python 3.x: > > >>> a, b, *c = 1, 2, 3, 4, 5 > >>> a, b, c > (1, 2, [3, 4, 5]) > >>> a, *b, c = 1, 2, 3, 4, 5 > >>> a, b, c > > (1, [2, 3, 4], 5) Interesting... especially the recognition of how both ends work with the "a, *b, c" example. That is some funky syntax. And it goes to a list instead of a tuple now, I see. It is also the opposite of what I was considering, although I expect it goes both ways like it does for functions? The given python 3.0 example is on the LHS with * packing many-to-one while unpacking (like *args inside a function), whereas I was referring to RHS-style unpacking where * explodes/unpacks one-to-many (like passing *args _to_ a function). I've steered clear of 3.x so far, but it looks like I'll have to give it a whirl if only to avoid asking irrelevant questions! From pranny at gmail.com Sun Nov 29 13:06:49 2009 From: pranny at gmail.com (pranav) Date: Sun, 29 Nov 2009 10:06:49 -0800 (PST) Subject: Installing Python 2.5 with Python 2.6 Message-ID: <5265bdcf-cd33-4712-961f-6db9b494600b@d9g2000prh.googlegroups.com> Hi, I used to develop applications on Google AppEngine SDK (which supports Python 2.5) on my Fedora 10. I upgraded to Fedora 12 recently and it has Python 2.6. Unfortunately, some things are breaking up with the SDK. Here is the trace http://dpaste.com/hold/126668/ I had been suggested by the AppEngine guys to install Python 2.5. So i wanted to know -- is it safe to install Python 2.5 alongwith Python 2.6? How will i configure my OS to use Python 2.6 (which was there already) and the SDK to use Python 2.5, which i will install new? Any other issues/suggestions/comments anyone? From francesco.pietra at accademialucchese.it Sun Nov 29 13:12:18 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Sun, 29 Nov 2009 19:12:18 +0100 Subject: delete column content Message-ID: Hi: How to replace with blank the single-character in column 21 of a pdb file (in pdb numbering it is column 22). Attached is an incomplete exercise with slices. I am unable to get real plain text with gmail. Thanks for help francesco pietra -------------- next part -------------- A non-text attachment was scrubbed... Name: delete.label.py Type: text/x-python Size: 423 bytes Desc: not available URL: From nad at acm.org Sun Nov 29 13:12:56 2009 From: nad at acm.org (Ned Deily) Date: Sun, 29 Nov 2009 10:12:56 -0800 Subject: Filling in a tuple from unknown size list References: Message-ID: In article , inhahe wrote: > maybe that thing in python 3 that someone mentioned is the answer, but > otherwise i always think Python should admit something like this: > > a, b, c, *d = list > > i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] Extended iterable unpacking (http://www.python.org/dev/peps/pep-3132/) is implemented in python 3. $ python3 Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a, b, c, *d = [1,2,3,4,5] >>> d [4, 5] -- Ned Deily, nad at acm.org From deets at nospam.web.de Sun Nov 29 13:27:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 29 Nov 2009 19:27:50 +0100 Subject: delete column content In-Reply-To: References: Message-ID: <7nfsp6F3lpbpvU1@mid.uni-berlin.de> Francesco Pietra schrieb: > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help Wasn't the help you already got a few days ago sufficient? Diez From pranny at gmail.com Sun Nov 29 13:28:13 2009 From: pranny at gmail.com (pranav) Date: Sun, 29 Nov 2009 10:28:13 -0800 (PST) Subject: Installing Python 2.5 with Python 2.6 References: <5265bdcf-cd33-4712-961f-6db9b494600b@d9g2000prh.googlegroups.com> Message-ID: <511263c8-319c-48c5-b7f0-d6d03bd74400@2g2000prl.googlegroups.com> On Nov 29, 11:06?pm, pranav wrote: > Hi, > I used to develop applications on Google AppEngine SDK (which supports > Python 2.5) on my Fedora 10. > I upgraded to Fedora 12 recently and it has Python 2.6. > Unfortunately, some things are breaking up with the SDK. Here is the > tracehttp://dpaste.com/hold/126668/ > I had been suggested by the ?AppEngine guys to install Python 2.5. > So i wanted to know -- ?is it safe to install Python 2.5 alongwith > Python 2.6? How will i configure my OS to use Python 2.6 (which was > there already) and the SDK to use Python 2.5, which i will install > new? > Any other issues/suggestions/comments anyone? here, http://wtanaka.com/linux/f11#python25 . this page talks about installing Python 2.5 on fedora 11. Anyone knows a similar resource for Python 2.5 on Fedora 12? From vlastimil.brom at gmail.com Sun Nov 29 13:48:54 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 29 Nov 2009 19:48:54 +0100 Subject: delete column content In-Reply-To: References: Message-ID: <9fdb569a0911291048y38e83b08oc60abb06faca24f7@mail.gmail.com> 2009/11/29 Francesco Pietra : > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help > > francesco pietra > > -- > http://mail.python.org/mailman/listinfo/python-list > > Do you mean something like >>> line="abcdefghijklmnopqrstuvwxyz" >>> line[:21]+line[22:] 'abcdefghijklmnopqrstuwxyz' ? vbr From nir at winpdb.org Sun Nov 29 14:08:02 2009 From: nir at winpdb.org (Nir) Date: Sun, 29 Nov 2009 11:08:02 -0800 (PST) Subject: debugger on system with Python 2 and 3 References: Message-ID: rpdb2 should be compatible with Python 3.x. And once you start a debugging session with rpdb2 (running with Python 3.x) you can attach to it from a winpdb instance (running with Python 2.x) On Nov 29, 2:29?pm, Yo Sato wrote: > If there's no other choice I don't mind using winpdb, but it is > installed (through Yum) under Python2 library and invokes Py2 at > default... Don't quite know how to adapt it to Py3 or install the > right version under the right directory, yet. It seems as if some > environmental variable change is necessary. On the whole it doesn't > seem that there's much support in the third-party debuggers in general > as yet... > > In the meantime I might ask if it is possible to adapt pydb (or > perhaps, IDLE) for Py3. Might be just a change in a env variable or > two... > > Yo From lie.1296 at gmail.com Sun Nov 29 14:21:44 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 06:21:44 +1100 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: <4b12ca2e$1@dnews.tpgi.com.au> On 11/30/2009 1:25 AM, Russell Warren wrote: > > Maybe it's just that * is strictly for arguments, and trying it for > generic tuple unpacking is abuse (which is down the corridor in 12A). Because (1, 2, *x) == (1, 2, 3, 4) is not tuple unpacking [!] Tuple unpacking is related with assignment, e.g.: a, b, c = 1, 2, 3 In python 3, there is the extended tuple unpacking: >>> a, b, *c = [1, 2, 3, 4, 5] >>> # a = 1; b = 2; c = [3, 4, 5] >>> a, *b, c = [1, 2, 3, 4, 5] >>> # a = 1; b = [2, 3, 4]; c = 5 If I remember correctly, the idea of (1, 2, *x) to mean (1, 2) + x has been discussed before, and rejected as well. From bblais at bryant.edu Sun Nov 29 14:34:49 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 29 Nov 2009 14:34:49 -0500 Subject: teaching python using turtle module Message-ID: Hello, I was just playing with the turtle module, and thought it was an interesting way to augment the introduction to python (I teach college students, who haven't had any programming). It's a great way to introduce functions, for-loops, and general program structures. After a bit of playing, I realized that I couldn't think of many examples which use turtle with conditional structures (if- and while- statements), or functions that return values, as opposed to "procedures" like: def square(length): forward(length) right(90) forward(length) right(90) forward(length) right(90) forward(length) right(90) If-statements could possibly be used with some sort of random behavior (if rand()<0.5 ...). Are there any other situations, using turtle, that these structures would be natural? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 29 14:45:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 13:45:18 -0600 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: <4B12CF4E.2010203@tim.thechases.com> > The feature is available in Python 3.x: > >>>> a, b, *c = 1, 2, 3, 4, 5 >>>> a, b, c > (1, 2, [3, 4, 5]) >>>> a, *b, c = 1, 2, 3, 4, 5 >>>> a, b, c > (1, [2, 3, 4], 5) This is a nice feature of 3.x but I'm disappointed (especially in light of the move to make more things iterators/generators), that the first form unpacks and returns a list instead returning the unexhausted generator. There are times I've wanted to write something like def powers_of_n(n=2): p = 0 while True: yield n ** p p += 1 def linear(i=0, step=1): while True: yield i i += step CONST_A, CONST_B, CONST_C, *_ = linear() OPT_A, OPT_B, OPT_C, *_ = powers_of_n() because adding another CONST or OPT becomes trivial (just add it to the list of names). I currently have to do something like CONST_A, CONST_B, CONST_C = range(3) and then remember to bump up my range() parameter when I create a new value on the left. It's not bad to see here, but I often have times where N>60 constants and tweaking something in an alphabetically sorted list may require scrolling to see/remember the range() change. However, because 3.x tries to make a list out of it, this doesn't help me at all because my generator is infinite. Boo. Diez Roggisch gave me a beautiful (okay, the implementation code is a bit ugly, but the final product's simplicity achieves elegance) solution to my similar want for 2.x here: http://www.mail-archive.com/python-list at python.org/msg87022.html -tkc From victorsubervi at gmail.com Sun Nov 29 15:11:13 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 29 Nov 2009 15:11:13 -0500 Subject: Exec Statement Question Message-ID: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> Hi; I have the following line of code: exec('%s()' % table) where 'table' is a variable in a for loop that calls variables from another script. I've made it so that it only calls one variable. I know for a fact that it's calling that variable in the script because it found errors in that script. I've tried to have it return the following: print 'hi' return 'hi' It doesn't return anything. No errors are thrown because the code evaluates. I don't know how to capture the output. I would like to do something like: print exec(...) or var = exec(...) but of course those options don't work. Suggestions? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Sun Nov 29 15:39:59 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 12:39:59 -0800 Subject: The Strong Relationship between MatLab and MatPlotLib? What One Needs to Know? Message-ID: Although MatPlotLib has plenty of examples, they do not seem to cover the fundamentals like figure. It seems as though in someway this is dependent upon a user's knowledge of MatLab. Is this true, or oes MatPlotLib provide some description of how forming a figure works? From bearophileHUGS at lycos.com Sun Nov 29 16:08:40 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 13:08:40 -0800 (PST) Subject: * for generic unpacking and not just for arguments? References: Message-ID: <2a6bf3a0-54b7-4ebf-a1ef-f80f847aa325@z41g2000yqz.googlegroups.com> Christian Heimes: > The feature is available in Python 3.x: > > >>> a, b, *c = 1, 2, 3, 4, 5 Is it planned to be added to a close future Python 2.x version? I really hope the answer is positive. Bye, bearophile From marko.loparic at gmail.com Sun Nov 29 16:12:13 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 29 Nov 2009 13:12:13 -0800 (PST) Subject: Creating a local variable scope. Message-ID: Hi, On 18 Sep, 10:36, "markol... at gmail.com" wrote: > On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: > > I find several places in my code where I would like tohavea variable > > scope that is smaller than the enclosing function/class/module definition. > > This is one of the single major frustrations I have with Python and an > important source of bugs for me. Here is a typical situation Here is another bug that I just got. Twenty minutes lost to find it... class ValueColumn(AbstractColumn): def __init__(self, name, header, domain_names): if type(domain_names) != tuple: raise ValueError('a tuple of domain names must be given') for name in domain_names: if type(name) != str: raise ValueError('a tuple of domain names must be given') self.domain_names = domain_names super(ValueColumn, self).__init__(name, header) The upper class was initialized with the wrong name, because the for loop to check domain_names used "name" which is also the argument to be passed. If is an old thread but I am reopening to present real situation where this Python "feature" bothers me... Marko From bearophileHUGS at lycos.com Sun Nov 29 16:43:17 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 13:43:17 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Message-ID: n00m: > I suspect that building of Suffix Tree would > be a big exec.time-consuming overhead In C/D/C++ there are ways to allocate memory in smarter ways, using pools, arenas, stacks, freelists, etc. With that, using a compact encoding of tree nodes (there are many different tricks to reduce space used by a suffix tree), you can go fast enough. Probably a basic implementation too will suffice in many cases :-) Anyway, you may try a pure-Python2.x implementation: http://suffixtree.googlecode.com/files/suffixtree-0.1.py If you find time & will to try to use that (or similar code) to improve your Python solution to the problem 99, you can show us the code here... Bye, bearophile From changlani.nitin at gmail.com Sun Nov 29 17:06:57 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sun, 29 Nov 2009 17:06:57 -0500 Subject: Variables with cross-module usage In-Reply-To: <009b92f9$0$26925$c3e8da3@news.astraweb.com> References: <009b92f9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <647908460911291406n5e5dc664wac734924b567055a@mail.gmail.com> Thanks Dennis and Steve, This explains it all! I will discard using one.a and use one.myList[0] directly, instead. I really appreciate your patience and the elaboration of the concept. Warm Regards, Nitin Changlani. On Sun, Nov 29, 2009 at 1:02 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > > > Thanks for the reply MRAB, Rami, Matt and Mel, > > > > I was assuming that since one.myList0] = one.a, the change in one.a will > > ultimately trickle down to myList[0] whenever myList[0] is printed or > > used in an expression. It doesn't come intuitively to me as to why that > > should not happen. Can you kindly suggest what is the correct way to go > > about it? > > > You are confusing *names* and *objects*. The presence or absence of a > module qualifier is irrelevant, so for simplicity I will avoid it. I will > use ` ` quotation marks to refer to names, to avoid confusing them with > strings. > > > The Python statement > > a = "some text" > > creates a name `a` which is bound to the object "some text". > > myList[0] = a > > stores the object bound to the name `a` to the first position of myList, > not the name itself. So myList[0] ends up being "some text", but it has > no idea whether it came from the name `a` or somewhere else. > > Then when you execute: > > a = "different text" > > the name `a` is bound to the object "different text". But this doesn't > affect myList[0] at all, because you're not changing the object "some > text" -- strings are immutable and can't be changed. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or used > in an expression. It doesn't come intuitively to me as to why that should > not happen. Can you kindly suggest what is the correct way to go about it? > First you understand that no common programming language behaves this way... It's not just Python. It's just more subtle in Python. In classical languages "one.myList[0]" represents a location (in this case, think of a room of file cabinets). "one" is a cabinet in the room; myList is a drawer in the cabinet; [0] is a folder in the drawer. and "a" is another drawer. In this classical language "one.myList[0] = one.a" means "open up the drawer a in cabinet one, make a COPY of what it contains, and put that copy into the [0] folder inside drawer myList in cabinet one. In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. "one" is a name attached to an object (the module). "a" is a name "inside" the object "one" which is attached to some other object, whatever it is. Similarly, "myList" is a name attached to an object (an indexed list or a keyed dictionary). "[0]" is a "name" (the index or key) into the object the name "myList" is attached to. "one.myList[0] = one.a" means "find the object with the name 'one.a' attached to it, and attach then name 'one.myList[0]' to the same object" Later, if you do "one.a = something", you say "find the object with name 'something' and attach the name 'one.a' to it" -- it is, in effect, the name that is moved from object to object -- no copy is made. -- Wulfraed Dennis Lee Bieber KD6MOG wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sun Nov 29 17:11:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 09:11:50 +1100 Subject: Creating a local variable scope. In-Reply-To: References: Message-ID: <4b12f20c@dnews.tpgi.com.au> On 11/30/2009 8:12 AM, markolopa wrote: > Hi, > > On 18 Sep, 10:36, "markol... at gmail.com" wrote: >> On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: >>> I find several places in my code where I would like tohavea variable >>> scope that is smaller than the enclosing function/class/module definition. >> >> This is one of the single major frustrations I have with Python and an >> important source of bugs for me. Here is a typical situation > > Here is another bug that I just got. Twenty minutes lost to find it... > > class ValueColumn(AbstractColumn): > def __init__(self, name, header, domain_names): > if type(domain_names) != tuple: > raise ValueError('a tuple of domain names must be given') > for name in domain_names: > if type(name) != str: > raise ValueError('a tuple of domain names must be > given') > self.domain_names = domain_names > super(ValueColumn, self).__init__(name, header) > > The upper class was initialized with the wrong name, because the for > loop to check > domain_names used "name" which is also the argument to be passed. > > If is an old thread but I am reopening to present real situation where > this Python > "feature" bothers me... > here is another bug you might have if python have an "even-more-local" scope: while True: s = raw_input("enter something: ") if s not in ('q', 'quit', 'exit'): break print s if the while block has become its own namespace; print s would generate NameError. It is one or the other, you will have problem caused by "namespace too small" or "namespace too big". Neither is better than the other, so python's two-level name resolution (global and local level) is the simplest one, is the better one. From echerlin at gmail.com Sun Nov 29 17:51:14 2009 From: echerlin at gmail.com (Edward Cherlin) Date: Sun, 29 Nov 2009 14:51:14 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 11:34, Brian Blais wrote: > Hello, > I was just playing with the turtle module, and thought it was an interesting > way to augment the introduction to python (I teach college students, who > haven't had any programming). ?It's a great way to introduce functions, > for-loops, and general program structures. If you use the Python-programmable tile in Turtle Art in Sugar, or Smalltalk in the Turtle Graphics in Etoys, it's even better. I have been doing presentations on teaching Python in elementary schools, and working on how to teach basic Computer Science ideas. You can use an if-then-else to initialize a stream in Python for the first pass, and get a value at each pass thereafter. The logic can be either in the TA or the Python. > After a bit of playing, I realized that I couldn't think of many exaples > which use turtle with conditional structures (if- and while- statements), Repeat is used much more often. but of course we can provide examples of any behavior you like. I like to use the turtle to generate sequences, where I can use a conditional to stop when the turtle would go off the screen. Fibonacci numbers, for example, or exponentials. Similarly for spirals of various types. Simple cases like those are easy to do in TA, while more complex sequences could use Python. There are several fractal examples using loops provided with Sugar on a Stick, including variations on Siepinksi constructions, and the Koch Snowflake. When I can get the code for reading the color of a dot on the screen into the programmable tile, I can program a toy Turing machine, with an array of dots as the transition table, and a line of dots as the tape. > or > functions that return values, as opposed to "procedures" like: > def square(length): > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) Surely you mean repeat(4) forward(length) right(90) > If-statements could possibly be used with some sort of random behavior (if > rand()<0.5 ...). Drunkard's Walk. > Are there any other situations, using turtle, that these > structures would be natural? Recent versions of TA contain stack instructions: push, pop, read, clear. Your students might find it interesting to program Forth instructions in TA or Python. This has practical applications in implementing and porting virtual machines such as Parrot and the VMs in Smalltalk and I-APL. There is plenty more where this came from. You would also be welcome to adapt the Python source code for TA tiles to your environment. > thanks, > Brian Blais > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > > > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > > -- Edward Mokurai (??/???????????????/????????????? ?) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://www.earthtreasury.org/ From bblais at bryant.edu Sun Nov 29 18:14:42 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 29 Nov 2009 18:14:42 -0500 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: <34E79EB9-242E-4F6E-B646-626A6A618932@bryant.edu> On Nov 29, 2009, at 17:51 , Edward Cherlin wrote: > If you use the Python-programmable tile in Turtle Art in Sugar, or > Smalltalk in the Turtle Graphics in Etoys, it's even better. I'll have to check this out. > sequences, where I can use a conditional to stop when the turtle would > go off the screen. ah, good idea. >> or >> functions that return values, as opposed to "procedures" like: >> def square(length): >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) > > Surely you mean > > repeat(4) > forward(length) > right(90) > surely I don't mean. :) that's not python. I'd do: def square(length): for i in range(4): forward(length) right(90) but there isn't much difference with such a simple shape. obviously, as one continued, the for-loop method would be clearer. >> If-statements could possibly be used with some sort of random >> behavior (if >> rand()<0.5 ...). > > Drunkard's Walk. > yes, that was the kind of thing I was thinking about. thanks! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko.loparic at gmail.com Sun Nov 29 19:26:51 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 29 Nov 2009 16:26:51 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: Hi Lie! On Nov 29, 11:11?pm, Lie Ryan wrote: > here is another bug you might have if python have an "even-more-local" > scope: > > while True: > ? ? ?s = raw_input("enter something: ") > ? ? ?if s not in ('q', 'quit', 'exit'): break > print s > > if the while block has become its own namespace; print s would generate > NameError. This bug you show is completely different, because it is not dangerous: you get the error and you realise directly how to fix it. > It is one or the other, you will have problem caused by "namespace too > small" or "namespace too big". Neither is better than the other, so > python's two-level name resolution (global and local level) is the > simplest one, is the better one. I would be much happier with the smaller namespace. To fix the code that you show I would impose s = None while True: s = raw_input("enter something: ") if s not in ('q', 'quit', 'exit'): break print s The use in a block of variables created in an inner block is (for me at least) more an exception than a rule. Less than 3 hours have passed since my last post and got yet another bug that could be prevented if Python had the functionality that other languages have to destroy variables when a block ends. Here is the code: ========= arg_columns = [] for domain in self.domains: i = self.get_column_index(column_names, domain.name) col = column_elements[i] if len(col) != len(val_column): ValueError('column %s has not the same size as the value column %s' % (column_names[i], self.name)) arg_columns.append(col) [...] value_dict = {} for i, val_str in enumerate(val_column): arg_name_row = [c[i] for c in arg_columns] args = [domain[name] for name in arg_name_row] value_dict[tuple(args)] = float(val_str) repo[self.name] = value_dict ========= The bug is corrected replacing the line args = [domain[name] for name in arg_name_row] by args = [domain[name] for name, domain in zip(arg_name_row, self.domains)] so "domain" should not exist in my namespace since I have no information associated to "domain" only to "self.domains". Python should allow me to write safe code! Antoher 15 minutes lost because of that Python "feature"... Is it only me??? Thanks for your comment! Marko From ebonak at hotmail.com Sun Nov 29 19:39:48 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 19:39:48 -0500 Subject: semantics of ** (unexpected/inconsistent?) Message-ID: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -3**2 -9 >>> x = -3 >>> x**2 9 >>> I would have expected the same result in both cases. Initially I would have expected -3**2 to yield 9, but I can accept that ** binds tighter than the unary -, but shouldn't the results be consistent regardless if I use a literal or a variable? From showell30 at yahoo.com Sun Nov 29 19:46:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 29 Nov 2009 16:46:43 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: On Nov 29, 4:26?pm, markolopa wrote: > Less than 3 hours have passed since my last post and got yet another > bug that could be prevented if Python had the functionality that other > languages have to destroy variables when a block ends. Here is the > code: > > ========= > > arg_columns = [] > for domain in self.domains: > ? ? i = self.get_column_index(column_names, domain.name) > ? ? col = column_elements[i] > ? ? if len(col) != len(val_column): > ? ? ? ? ValueError('column %s has not the same size as the value > column %s' > ? ? ? ? ? ? ? ? ? ?% (column_names[i], self.name)) > ? ? ? ? arg_columns.append(col) > > [...] > > value_dict = {} > for i, val_str in enumerate(val_column): > ? ? arg_name_row = [c[i] for c in arg_columns] > ? ? args = [domain[name] for name in arg_name_row] > ? ? value_dict[tuple(args)] = float(val_str) > repo[self.name] = value_dict > > ========= > > The bug is corrected replacing the line > > ? ? args = [domain[name] for name in arg_name_row] > > by > > ? ? args = [domain[name] for name, domain in zip(arg_name_row, > self.domains)] > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! > > Antoher 15 minutes lost because of that Python "feature"... Is it only > me??? > I occasionally make the error you make, but I think the real problem you are having is lack of attention to detail. If name collisions are a common problem for you, consider writing shorter methods or develop the habit of using more descriptive variable names. In the code above, you could have easily cleaned up the namespace by extracting a method called get_arg_columns(). Having to spend 15 minutes tracking down a bug usually indicates that you are not being systematic in your thinking. If you are rushing too much, slow down. If you are tired, take a break. If you make the same mistake twice, commit to yourself not to make it a third time. Also, test your methods one at a time and get them rock solid before writing more code. From Brian.Mingus at Colorado.EDU Sun Nov 29 19:48:52 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sun, 29 Nov 2009 17:48:52 -0700 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> On Sun, Nov 29, 2009 at 5:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? > I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. >>> (-3)**2 9 >>> 3**2 9 >>> -3**2 -9 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Nov 29 19:50:11 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 Nov 2009 16:50:11 -0800 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>>> -3**2 > -9 > >>>> x = -3 > >>>> x**2 > 9 >>>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? _No_, because using the variable evaluates "-3" as a unit separately by itself, before the exponentiation ever occurs; it's the same as the difference between (-3)**2 and -3**2. Python is not a concatenative programming language[*]; you can't directly textually replace a variable with its value and expect to get the same result from an expression. For instance, in this case, you need to add the parentheses. Cheers, Chris -- http://blog.rebertia.com [*] http://en.wikipedia.org/wiki/Concatenative_language From ebonak at hotmail.com Sun Nov 29 19:58:06 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 19:58:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: Brian J Mingus wrote: > > > > I think you answered your own question. 3**2 comes first in the order of > operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same result if I use the literal -3 or a variable that contains -3 (x in my example). From tjreedy at udel.edu Sun Nov 29 20:00:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:00:07 -0500 Subject: Variables with cross-module usage In-Reply-To: References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Message-ID: Dennis Lee Bieber wrote: > In these languages, the names always refer to the same location. > Python confuses matters by having names that don't really refer to > location, but are attached to the objects. In everyday life and natural languages, names refer to people, other objects, roles, and only occasionally to places that can be occupied. I could claim that it is classical computer languages that confuse by restricting names to locations in a linear sequence. You are just used to the straightjacket ;-). From cjwilliams43 at gmail.com Sun Nov 29 20:03:27 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sun, 29 Nov 2009 20:03:27 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: On 29-Nov-09 19:50 PM, Chris Rebert wrote: > On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: >> Ok, this is somewhat unexpected: >> >> Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) >> [GCC 4.3.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >> >>>>> -3**2 >> -9 >> >>>>> x = -3 >> >>>>> x**2 >> 9 >>>>> >> >> I would have expected the same result in both cases. >> >> Initially I would have expected -3**2 to yield 9, but I can accept >> that ** binds tighter than the unary -, but shouldn't the results >> be consistent regardless if I use a literal or a variable? > > _No_, because using the variable evaluates "-3" as a unit separately > by itself, before the exponentiation ever occurs; it's the same as the > difference between (-3)**2 and -3**2. > Python is not a concatenative programming language[*]; you can't > directly textually replace a variable with its value and expect to get > the same result from an expression. For instance, in this case, you > need to add the parentheses. > > Cheers, > Chris > -- > http://blog.rebertia.com > > [*] http://en.wikipedia.org/wiki/Concatenative_language See the Operator Order of Precedence: http://docs.python.org/reference/expressions.html#summary Parentheses permit the user to vary the precedence. Colin W. From martin at v.loewis.de Sun Nov 29 20:03:46 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Nov 2009 02:03:46 +0100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <4b1319f2$0$13193$9b622d9e@news.freenet.de> >> I think you answered your own question. 3**2 comes first in the order >> of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contains -3 (x in my example). There is no literal -3 in Python, only a literal (+)3, see http://docs.python.org/reference/lexical_analysis.html#integer-and-long-integer-literals So -3**2 means -(3**2) == -9. Regards, Martin From ebonak at hotmail.com Sun Nov 29 20:04:01 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 20:04:01 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: Chris Rebert wrote: > > _No_, because using the variable evaluates "-3" as a unit separately > by itself, before the exponentiation ever occurs; it's the same as the > difference between (-3)**2 and -3**2. > Python is not a concatenative programming language[*]; you can't > directly textually replace a variable with its value and expect to get > the same result from an expression. For instance, in this case, you > need to add the parentheses. > > Cheers, > Chris > -- > http://blog.rebertia.com > > [*] http://en.wikipedia.org/wiki/Concatenative_language Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. (I use the Python interpreter frequently for small calculations - otherwise I'd never have realized this) Thanks, Esmail From FearsomeDragonfly at gmail.com Sun Nov 29 20:10:00 2009 From: FearsomeDragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 19:10:00 -0600 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: It's just like in algebra. You evaluate exponents before the - which, after all, is just another way to write -1, or times-negative-one. However, a variable with a negative value is not the same as a value that is being multiplied by a negative. -3 ** 2 = (-1)(3)^(2) in algebraic terms. Exponents first, then multiplication. However, x ** 2 = (x)^(2) = (-3)^(2) regardless of the value of x which, in this case, is -3. When you multiply a negative by itself, you get a positive. In short, the ** operator appears to have a higher precedence than the - operator, based on your results. On Sun, Nov 29, 2009 at 6:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Nov 29 20:10:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:10:12 -0500 Subject: Feature request: String-inferred names In-Reply-To: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: The Music Guy wrote: > When I first started seeing @ show up in Python code, I said "what the > heck is that? For future reference, PySymbols.html at http://code.google.com/p/xploro/downloads/list answers all such symbol questions. From ben+python at benfinney.id.au Sun Nov 29 20:10:47 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 12:10:47 +1100 Subject: semantics of ** (unexpected/inconsistent?) References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <87iqcsrf54.fsf@benfinney.id.au> Esmail writes: > Brian J Mingus wrote: > > > > > > > > I think you answered your own question. 3**2 comes first in the > > order of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 > or a variable that contains -3 (x in my example). You seem to be confusing the values, which (in this case) are numbers, with their incidental representation in Python code, which is literal expressions in text. Perhaps the following dissection will help: >>> -3**2 The expression ?-3**2? is evaluated, and a single value is the result. In that expression, there are two operators: the unary-minus operator and the exponential operator. There are two values as parameters in the expression: the natural number three, and the natural number two. >>> x = -3 The expression ?-3? is evaluated, and a single value is the result. That value has an internal representation of ?the integer that is three less than zero?. It is *not* the sequence of characters that you see in the Python code; it is a number. The name ?x? is then bound to that value. >>> x**2 The expression ?x**2? is evaluated, and a single value is the result. In that expression, there is *one* operator: the exponential operator. There is no unary-minus operator in the expression. There are two values as parameters in the expression: the value referenced by the name ?x? which is the integer negative-three, and the natural number two. I hope that explains the difference in behaviour. -- \ ?I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means ?put down?.? ?Bob Newhart | Ben Finney From alfps at start.no Sun Nov 29 20:11:12 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 02:11:12 +0100 Subject: Creating a local variable scope. In-Reply-To: References: Message-ID: * markolopa: > > On 18 Sep, 10:36, "markol... at gmail.com" wrote: >> On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: >>> I find several places in my code where I would like tohavea variable >>> scope that is smaller than the enclosing function/class/module definition. >> This is one of the single major frustrations I have with Python and an >> important source of bugs for me. Here is a typical situation > > Here is another bug that I just got. Twenty minutes lost to find it... > > class ValueColumn(AbstractColumn): > def __init__(self, name, header, domain_names): > if type(domain_names) != tuple: > raise ValueError('a tuple of domain names must be given') > for name in domain_names: > if type(name) != str: > raise ValueError('a tuple of domain names must be > given') > self.domain_names = domain_names > super(ValueColumn, self).__init__(name, header) > > The upper class was initialized with the wrong name, because the for > loop to check > domain_names used "name" which is also the argument to be passed. > > If is an old thread but I am reopening to present real situation where > this Python > "feature" bothers me... I think if one could somehow declare names as const (final, readonly, whatever) then that would cover the above plus much more. Cheers, - Alf From tjreedy at udel.edu Sun Nov 29 20:14:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:14:40 -0500 Subject: slightly OT: Python BootCamp In-Reply-To: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> References: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> Message-ID: J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. I figured, free class, a week where > I'll not have to actually go to work, AND I'll get paid, sure! > > So I was just wondering if any of you have attended this one, or one > like it, and what your impressions were. I've attended a few before, > and found them widely different. The RH300, for example, was > blisteringly fast and really just touches on things, so if you don't > already know Red Hat inside and out, you'll never survive. The VMWare > VCP courses, on the other hand, were fairly languid by contrast and > seemed to flow in a less frantic state. > > So I figured this would be the place to ask. > > And if it matters, I do have an educational background in programming > (VB, C++, C, Java, etc) but my professional background has mostly been > limited to Bash, OCCASIONAL C, and now a touch of Python, so I am not > new to programming and OO programming, just not as proficient as I > would like to be... The list of topics seems to cover basic + intermediate issues. If you do go, perhaps you could review it here. Same for people who have attended other Python training courses, of course. From greg.ewing at canterbury.ac.nz Sun Nov 29 20:21:54 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 30 Nov 2009 14:21:54 +1300 Subject: python and vc numbers In-Reply-To: References: Message-ID: <7ngl1gF3ml76pU1@mid.individual.net> Daniel Dalton wrote: > what function/module should > I use to figure out what tty my program was invoked from? Here's one way: % python Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen("tty").read() '/dev/ttyp1\n' -- Greg From kirby.urner at gmail.com Sun Nov 29 20:22:29 2009 From: kirby.urner at gmail.com (kirby urner) Date: Sun, 29 Nov 2009 17:22:29 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 2:51 PM, Edward Cherlin wrote: << snip >> > Drunkard's Walk. > If our think tank (isepp.org) could have gotten permission, we'd have used that Monopoly guy (looks kinda like Planters peanut guy) randomly walking on like some chess board with a lamp post (reminds of Narnia). We don't have that kind of dough though, so just do this conceptually (conceptual art). >> Are there any other situations, using turtle, that these >> structures would be natural? > > Recent versions of TA contain stack instructions: push, pop, read, > clear. Your students might find it interesting to program Forth > instructions in TA or Python. This has practical applications in > implementing and porting virtual machines such as Parrot and the VMs > in Smalltalk and I-APL. > > There is plenty more where this came from. You would also be welcome > to adapt the Python source code for TA tiles to your environment. > I recall Alan Kay communicating Seymour Papert's sense that having "an explicit receiver" was an OK development. What he meant by that, in Smalltalk terms, is that the original Logo had what I'd call a "context turtle" in that FORWARD or RIGHT were w/r to a given Turtle one didn't need to mention explicitly, like what else could one mean? With Python and other object oriented implementations, one first gives birth to a turtle, creates an instance, as in: >>> someturtle = Turtle() That's binding a name to a turtle object (giving some turtle object a name) and then controlling said turtle through the API using dot notation against the name, e.g. someturtle.forward(10) or someturtle.right(90). What you get from this is, of course, the possibility of multiple turtles, each with its own pen color, visibility, other properties of self-hood. This gets showcased in the default demo (in Windows, just double click on turtle.py in the Lib subdirectory): http://www.flickr.com/photos/17157315 at N00/4145780784/ (using Gregor's 3.1 code just minutes ago) IronPython also has access to the .NET turtle library: http://www.flickr.com/photos/mfoord/3104991233/ (not my computer) I suppose I'm only bringing this up to (a) name drop about being in a meeting with Alan Kay (with Guido and Mark Shuttleworth among others) and (b) to remind readers that Logo and turtle art, or the art of programming with turtles, are orthogonal axes. Logo as a language has also been extended considerably, as has the richness of the environment. Some of these are commercial, proprietary offerings. Some of these feature "spatial turtles" in a "turtle tank" i.e. each turtle is more like a biplane in a WWI dogfight (Snoopy vs. Red Baron), with all those extra degrees of freedom (roll, pitch, yaw). Python's turtle module is not, repeat not, an implementation of Logo in the Python language. It's an implementation of turtle graphics on a Tk canvas in the Python language. You'll also find a turtle module in wxPython such as in PythonCard by Kevin Altis. http://pythoncard.sourceforge.net/samples/turtle.html I think Gregor is right to see turtle.py as an easy way to implement an Objects First approach, consistent with a more generic approach to math concepts (vectors, polynomials, polyhedra) as objects (types), extending the OO rubric. We teach maths as extensible type systems that advance through the invention of new types, not just as systems evolving through a progression of proved theorems from fixed axioms. Kirby >> thanks, >> Brian Blais >> -- >> Brian Blais >> bblais at bryant.edu >> http://web.bryant.edu/~bblais >> >> >> >> _______________________________________________ >> Edu-sig mailing list >> Edu-sig at python.org >> http://mail.python.org/mailman/listinfo/edu-sig >> >> > > > > -- > Edward Mokurai (??/???????????????/????????????? ?) Cherlin > Silent Thunder is my name, and Children are my nation. > The Cosmos is my dwelling place, the Truth my destination. > http://www.earthtreasury.org/ > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- >>> from mars import math http://www.wikieducator.org/Martian_Math From alfps at start.no Sun Nov 29 20:23:32 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 02:23:32 +0100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: * Esmail: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? It is. >>> -3**2 -9 >>> x = 3 >>> -x**2 -9 >>> :-) I guess you expect your expression "x**2" to somehow be evaluated as "-3**2". But x doesn't contain text, it contains an integer value that presumably (I don't know) is represented in the binary number system, so it's evaluated as "(-3)**2". If x contained text and was evaluated as such, pure text replacement, then you should be able to write 2 x and have that evaluated as "2 -x"... Cheers & hth., - Alf From mwilson at the-wire.com Sun Nov 29 20:26:47 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 29 Nov 2009 20:26:47 -0500 Subject: semantics of ** (unexpected/inconsistent?) References: Message-ID: Esmail wrote: > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? When you say ** binds tighter than unary -, you're also saying that -3 isn't a literal: it's an expression. Try y=3 -y**2 Mel. From ebonak at hotmail.com Sun Nov 29 20:38:09 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 20:38:09 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. Cheers, Esmail From lie.1296 at gmail.com Sun Nov 29 20:49:40 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 12:49:40 +1100 Subject: Feature request: String-inferred names In-Reply-To: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: <4b132519$1@dnews.tpgi.com.au> On 11/29/2009 12:22 PM, The Music Guy wrote: > When I first started seeing @ show up in Python code, I said "what the > heck is that? It looks so weird and _ugly_.I would never try to mess > with that." But I started seeing it more and more, so I asked #python > what it was. They told me about decorators, so I looked it up in the > docs, and I thought the idea was interesting. It took me a while to > figure out exactly how they worked--and judging from messages I've > seen in #python a number of people have the same trouble understanding > them. And we don't want a second flood of users asking about foo.$bar. > My point is that any particular syntax would look ugly to you only > because you haven't seen it in use enough, and haven't used it enough > yourself. You're absolutely right, and I have *never needed* to use the plain getattr/setattr/delattr enough to even bother considering a syntax that already looks ugly at first sight. For @decorators, everyone used it *often enough* BEFORE it turned into a syntax that the ugly syntax is justified and become "acceptable". If you can find a syntax that doesn't look ugly at first sight +0, fine by me; otherwise -1, I don't want to be forced to read an ugly syntax for a feature that I don't use often enough. It's not just the syntax, the necessity+syntax don't add up well. > But of course you haven't--it's not currently a valid > syntax. However, the ugliness would seem to go away after the syntax > had been in use for a while. And again, the EXACT syntax of the > feature can be adjusted until its "just right". In so far, your definition of adjusting only means something around "[a-zA-Z0-9_]+\.[^a-zA-Z0-9_][<{(\[]?[a-zA-Z0-9_]+[>})\]]?" that class of syntax is ugly; some are more acceptable (e.g. obj.[arg]) the old thread have spawned better alternatives than that class of syntax. > As for my specific use case, it's somewhat difficult to explain. You know that: If the implementation is hard to explain it's a bad idea. -- Zen of Python -- right? > The > general idea was to isolate a pattern that I spotted repeated in > several unrelated parts of my project. The pattern manifested itself > as a set of 4-5 methods and/or properties on a class whose objects > were designed to work in conjunction with other objects that fit a > particular behavior. These other objects had methods and properties > that were designed to interact with the first type of object in a > similar but--how should I say--"inverted" fashion. Do you mean something like this? class A(object): @property def the_b(self): return self._b @the_b def the_b(self, new_b): self._b = new_b self._b._a = self class B(object): @property def the_a(self): return self._a @the_a def the_a(self, new_a): self._a = new_a self._a._b = self am I getting you right? If not, please elaborate and give an example of what you actually meant. From lie.1296 at gmail.com Sun Nov 29 21:19:33 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 13:19:33 +1100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <4b132c1b$1@dnews.tpgi.com.au> On 11/30/2009 12:38 PM, Esmail wrote: > Thanks all!! I get it now :-) > > It helped to have a number of different explanations, thanks > for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops, not the unary) * / ** for other operators I would have explicit parens. It's too much work to remember the rest of the precedence sheet. From ben+python at benfinney.id.au Sun Nov 29 21:29:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 13:29:54 +1100 Subject: semantics of ** (unexpected/inconsistent?) References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <87eingrbh9.fsf@benfinney.id.au> Lie Ryan writes: > I generally do not expect operator precedence to be reliable at all Have another read of the thread. The OP's confusion was not over operator precedence, but over how names resolve to values in expressions. -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From wolftracks at invalid.com Sun Nov 29 21:41:16 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 18:41:16 -0800 Subject: Object Not Callable, float? Message-ID: Here's an traceback error msg I get. 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\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", line 467, in ShowHistogram mean = sum(hist) TypeError: 'float' object is not callable for the code: ---------------------- sum = 0.0 avg = 0.0 nplt_bins = 32 for i in range(len(hist)): # msg = "%5d %6d\n" % (i,hist[i]) msg = "%5d %6d\n" % (i,hist[i]) sum = sum + hist[i] text.insert( END, msg ) for i in range(len(hist)): avg = avg + (i*hist[i]/sum) mean = sum(hist) <-------------- faulty line mean = mean/256.0 -------------------------end hist is a list of 256 integers. What does float have to do with this? From ben+python at benfinney.id.au Sun Nov 29 21:48:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 13:48:44 +1100 Subject: Object Not Callable, float? References: Message-ID: <87aay4ralv.fsf@benfinney.id.au> "W. eWatson" writes: > "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", > line 467, in ShowHistogram > mean = sum(hist) > TypeError: 'float' object is not callable It means you're calling an object of type ?float?. The line where it occurred shows that you're accessing that object through the name ?sum?, which means you've bound the name ?sum? to a float object. > for the code: > ---------------------- > sum = 0.0 Here you clobber the existing binding of ?sum?, binding it to the float value 0.0. > avg = 0.0 > nplt_bins = 32 > for i in range(len(hist)): > # msg = "%5d %6d\n" % (i,hist[i]) > msg = "%5d %6d\n" % (i,hist[i]) > sum = sum + hist[i] Here you keep re-binding the name ?sum? to new float objects of different value. > text.insert( END, msg ) > for i in range(len(hist)): > avg = avg + (i*hist[i]/sum) > > mean = sum(hist) <-------------- faulty line Here you try to call the object referenced by the name ?sum?, which is a float object. > hist is a list of 256 integers. What does float have to do with this? You explicitly bound the name ?sum? to an object of type ?float?. Solution: Choose names wisely, and if you want to use a built-in name like ?sum? for its built-in putpose, don't clobber that binding before using it. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From tuxsun1 at gmail.com Sun Nov 29 22:03:09 2009 From: tuxsun1 at gmail.com (tuxsun) Date: Sun, 29 Nov 2009 19:03:09 -0800 (PST) Subject: Noobie python shell question Message-ID: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> I've been working in the shell on and off all day, and need to see if a function I defined earlier is defined in the current shell I'm working in. Is there a shell command to get of list of functions I've defined? TIA! P.S. If it makes a difference, I'm using the shell from within IDLE, but once in a while I will use the python shell in a Bash console. From casevh at gmail.com Sun Nov 29 22:04:50 2009 From: casevh at gmail.com (casevh) Date: Sun, 29 Nov 2009 19:04:50 -0800 (PST) Subject: ANN: GMPY 1.11rc1 is available Message-ID: Everyone, I'm pleased to annouce that a new version of GMPY is available. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. GMPY 1.11rc1 is available for download from: http://code.google.com/p/gmpy/ In addition to support for Python 3.x, there are several new features in this release: - Even faster conversion to/from Python longs. - Performance improvements by reducing function overhead. - Performance improvements by improved caching. - Support for cdivmod, fdivmod, and tdivmod. - Unicode strings are accepted on Python 2.x and 3.x. - Fixed regression in GMPY 1.10 where True/False were no longer recognized. Comments on provided binaries The 32-bit Windows installers were compiled with MinGW32 using MPIR 1.3.0rc3 and will automatically recognize the CPU type and use code optimized for the CPU at runtime. The 64-bit Windows installers were compiled Microsoft's SDK compilers using MPRI 1.3.0rc3. Detailed instructions are included if you want to compile your own binary. Future plans On releasing the GIL: I have compared releasing the GIL versus the multiprocessing module and the multiprocessing module offers better and more predictable performance for embarrassingly parallel tasks than releasing the GIL. If there are requests, I can add a compile- time option to enable threading support but it is unlikely to become the default. On mutable integers: The performance advantages of mutable integers appears to be 20% to 30% for some operations. I plan to add a new mutable integer type in the next release of GMPY. If you want to experiment with mutable integers now, GMPY can be compiled with mutable version of the standard 'mpz' type. Please see the file "mutable_mpz.txt" for more information. Please report any issues! casevh From davea at ieee.org Sun Nov 29 22:23:15 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 22:23:15 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> Message-ID: <4B133AA3.4060405@ieee.org> Victor Subervi wrote: > Hi; > I have the following line of code: > > exec('%s()' % table) > > where 'table' is a variable in a for loop that calls variables from another > script. I've made it so that it only calls one variable. I know for a fact > that it's calling that variable in the script because it found errors in > that script. I've tried to have it return the following: > > print 'hi' > return 'hi' > > It doesn't return anything. No errors are thrown because the code evaluates. > I don't know how to capture the output. I would like to do something like: > > print exec(...) > > or > > var = exec(...) > > but of course those options don't work. Suggestions? > TIA, > Victor > > exec is a statement, and statements don't have "return values." It's not a function, so there are no parentheses in its syntax, either. exec is also a technique of last resort; there's nearly always a better/safer/faster way to accomplish what you might want, but of course you don't say what that is. As for "returning" values, exec by default uses the same global space as your app, so you can just modify a global variable in your "called" code and use it afterwards. abc = 42 value = 12 exec "abc = %d" % value print abc DaveA From davea at ieee.org Sun Nov 29 22:46:42 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 22:46:42 -0500 Subject: Creating a local variable scope. In-Reply-To: References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <4B134022.1070508@ieee.org> markolopa wrote: > > ======= > > arg_columns =] > for domain in self.domains: > i =elf.get_column_index(column_names, domain.name) > col =olumn_elements[i] > if len(col) !=en(val_column): > ValueError('column %s has not the same size as the value > column %s' > % (column_names[i], self.name)) > arg_columns.append(col) > > [...] > > value_dict =} > for i, val_str in enumerate(val_column): > arg_name_row =c[i] for c in arg_columns] > args =domain[name] for name in arg_name_row] > value_dict[tuple(args)] =loat(val_str) > repo[self.name] =alue_dict > > ======= > > The bug is corrected replacing the line > > args =domain[name] for name in arg_name_row] > > by > > args =domain[name] for name, domain in zip(arg_name_row, > self.domains)] > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! > > Antoher 15 minutes lost because of that Python "feature"... Is it only > me??? > > Yep, I think so. You're proposing a much more complex scoping rule, where if a variable already exists before entering a loop, then the loop uses that existing variable, but if not, it creates its own local one and destroys it when exiting the loop. That's the exact opposite of what function definitions do, which already makes it confusing. I think if you had your wish, you'd find that you had more exceptions where you had to pre-declare things, than the times when you avoided the bugs you describe. I don't like languages that make me write extra stuff 100 times, to save one instance of extra debugging. If Python already required declarations, then I might buy your arguments. But it wouldn't be Python. > Thanks for your comment! > Marko > > In your particular case, the compiler couldn't guess whether you used the first loop to decide which domain to use in the second loop, or whether you accidentally reused the same name without giving it a new value in the new loop. If you need to use the same name, you could always follow your loops with the del statement to invalidate the name. DaveA From pavlovevidence at gmail.com Sun Nov 29 22:52:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 19:52:44 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: <3de04434-55a6-4d49-a716-3e8200d5a1f4@13g2000prl.googlegroups.com> On Nov 26, 3:43?pm, The Music Guy wrote: > That aside, I still feel that a new syntax would be a better solution > than a new class. And, anyway, what I'm proposing isn't *quite* the > same as what Ben North proposed. Ben's idea was *strictly* to create > shorthand syntax to the getattr/setattr/delattr in the context of > specific objects. What I'm suggesting could be more accurately > described as a namespace-neutral transformation of the value of an > expression into a name. So if "bar" is the value of foo, then when the > interpreter sees ?$foo, it reads bar. This transformation isn't possible in Python. Python has seperate compile and run times, and the value of a variable (like foo) isn't known at compile time, but it would have to be known at compile time for the interpreter to "see" the value of that variable ("bar" in this example). Therefore, to get the effect you want, the evaluation of foo would have to be delayed until run time. The interpreter would "see" $foo, and explicitly change it to bar. But that leads to another problem. Local variables (in CPython at least) are converted to index lookups during the compile phase, for efficiency reasons. Python doesn't use the name of a the local variable at run time at all, and you can't dynamically create local variables. Thus, to use your syntax proposal with local variables you would have to accept two concessions: 1. You could not use $foo to dynamically create a new local variable; foo would have to evaluate to the name of a local variable that already exists. 2. You would take a significant performance hit. Furthermore, this would introduce a bad analogical inconsistency into the language. If you can write foo.$bar=1 to create a new attribute, you'd expect to be able to write $bar=1 to create a new local variable, but you can't. These issues are significant, and given that a proposal for just computed attributes that didn't have these issues was already rejected, I would say your proposal would have absolutely no chance, even if there hadn't been a moratorium on new syntax. Carl Banks From python.list at tim.thechases.com Sun Nov 29 22:53:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 21:53:30 -0600 Subject: Noobie python shell question In-Reply-To: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: <4B1341BA.7060607@tim.thechases.com> tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? yesish...you can use dir() from the prompt to see the bound names in a given scope: >>> dir() ['__builtins__', '__doc__', '__name__'] >>> def hello(who='world'): ... print "Hello, %s" % who ... >>> dir() ['__builtins__', '__doc__', '__name__', 'hello'] >>> x = 42 >>> dir() ['__builtins__', '__doc__', '__name__', 'hello', 'x'] however AFAIK, there's no readily accessible way to get the *definition* of that function back (other than scrolling back through your buffer or readline history) and it takes a bit more work to determine whether it's a callable function, or some other data-type. >>> callable(x) False >>> callable(hello) True (as an aside, is there a way to get a local/global variable from a string like one can fetch a variable from a class/object with getattr()? Something like getattr(magic_namespace_here, "hello") used in the above context? I know it can be done with eval(), but that's generally considered unsafe unless you vet your input thoroughly) -tkc From pavlovevidence at gmail.com Sun Nov 29 22:59:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 19:59:52 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> On Nov 28, 3:38?am, The Music Guy wrote: > On Nov 28, 3:07?am, Lie Ryan wrote: > > If you use it a lot, it is likely 1) you have abused class syntax for > > what should have been a dict or 2) what you need is to override > > __getattr__/__getattribute__ and __setattr__ > > Oh boy...here we go. :| > > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, > frequently the other will assume the former is not only doing things > wrong, but is doing them _blatantly_ wrong. I have caught myself > making that very assumption many times in the past, and I've tried > hard to build up an immunity against the impulse to make that > assumption. At this point, I don't even believe in such a thing as a > universal "wrong way" and a "right way" to code that applies to every > circumstance. The way to solve a problem depends on the problem. When > it comes to coding, there is not an absolute "right" way or "wrong" > way--unless we're talking about, say, stealing closed source code > without permission, or deliberately coding in a way that will cause > problems for the end user (like causing memory clogs or buffer > overflows and whatnot). > > All of this can be determined through common sense. Another thing that can be determined through common sense is that if you have object that you are calling getattr and setattr on so much that you think you need special syntax, you should have been using a dict. Carl Banks From FearsomeDragonfly at gmail.com Sun Nov 29 23:04:37 2009 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Sun, 29 Nov 2009 22:04:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: <4b132519$1@dnews.tpgi.com.au> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <4b132519$1@dnews.tpgi.com.au> Message-ID: On Sun, Nov 29, 2009 at 7:49 PM, Lie Ryan wrote: > On 11/29/2009 12:22 PM, The Music Guy wrote: > >> When I first started seeing @ show up in Python code, I said "what the >> heck is that? It looks so weird and _ugly_.I would never try to mess >> with that." But I started seeing it more and more, so I asked #python >> what it was. They told me about decorators, so I looked it up in the >> docs, and I thought the idea was interesting. It took me a while to >> figure out exactly how they worked--and judging from messages I've >> seen in #python a number of people have the same trouble understanding >> them. >> > > And we don't want a second flood of users asking about foo.$bar. > > > My point is that any particular syntax would look ugly to you only >> because you haven't seen it in use enough, and haven't used it enough >> yourself. >> > > You're absolutely right, and I have *never needed* to use the plain > getattr/setattr/delattr enough to even bother considering a syntax that > already looks ugly at first sight. For @decorators, everyone used it *often > enough* BEFORE it turned into a syntax that the ugly syntax is justified and > become "acceptable". If you can find a syntax that doesn't look ugly at > first sight +0, fine by me; otherwise -1, I don't want to be forced to read > an ugly syntax for a feature that I don't use often enough. It's not just > the syntax, the necessity+syntax don't add up well. > > > > But of course you haven't--it's not currently a valid > >> syntax. However, the ugliness would seem to go away after the syntax >> had been in use for a while. And again, the EXACT syntax of the >> feature can be adjusted until its "just right". >> > > In so far, your definition of adjusting only means something around > "[a-zA-Z0-9_]+\.[^a-zA-Z0-9_][<{(\[]?[a-zA-Z0-9_]+[>})\]]?" > that class of syntax is ugly; some are more acceptable (e.g. obj.[arg]) the > old thread have spawned better alternatives than that class of syntax. > > As for my specific use case, it's somewhat difficult to explain. >> > > You know that: > If the implementation is hard to explain it's a bad idea. > -- Zen of Python -- > > right? > > > > The > >> general idea was to isolate a pattern that I spotted repeated in >> several unrelated parts of my project. The pattern manifested itself >> as a set of 4-5 methods and/or properties on a class whose objects >> were designed to work in conjunction with other objects that fit a >> particular behavior. These other objects had methods and properties >> that were designed to interact with the first type of object in a >> similar but--how should I say--"inverted" fashion. >> > > Do you mean something like this? > > class A(object): > @property > def the_b(self): > return self._b > @the_b > def the_b(self, new_b): > self._b = new_b > self._b._a = self > > class B(object): > @property > def the_a(self): > return self._a > @the_a > def the_a(self, new_a): > self._a = new_a > self._a._b = self > > am I getting you right? If not, please elaborate and give an example of > what you actually meant. > > -- > http://mail.python.org/mailman/listinfo/python-list > I understand that in all likelyhood this feature won't be added to Python anytime soon, if at all. But I'd like to continue this discussion anyway; it's been enlightening for me. Even though I don't agree with the views of some of the people who've replied, I like the insight. And anyway, I think that if the syntax were already present, people would feel a lot more positively about it; it's the idea of adding it in so late in the game that people seem to have a problem with for the most part. It doesn't seem like anybody besides inhahe has actually realized that my proposition is actually different than PEP 363 in a subtle but crucial way. It's not _literally_ a shorthand for accessing the *attr functions; that's just the way I originally assumed it would be used most often. However, I have since realized that the syntax is more powerful than I originally thought: ANYWHERE that a name appeared--this includes function names, class names, function parameters, possibly even module names--could be replaced by an expression that would be evaluated to the name. That makes the use of any kind of brackets, except maybe , bad options, as it would conflict with [lists,] {dicts,} (tuples,) or generic parenthesized (expressions). There must be a unique indicator of some kind, something that isn't already in use by the interpreter. That way there is no possible way that it could get confused with another syntactical construct. So you could do something like this: def class_factory(this, that) get_that = "get_"+that set_that = "set_"+that _that = "_" + that class $this (object): def __init__(self, $that = None): self.$_that = $that def $get_that (self): return self.$_that def $set_that (self, $that): self.$_that = $that $that = property($get_that, $set_that) return $this Compare the code above with this approximation that uses the current syntax rules: def class_factory(this, that): get_that_name = "get_"+that set_that_name = "set_"+that _that = "_" + that class This(object): def __init__(self, that = None): setattr(self, _that, that) This.__name__ = this def get_that(self, that): return getattr(self, _that) get_that.__name__ = get_that_name setattr(This, get_that_name, get_that.__get__(None, This)) def set_that(self, that): setattr(self, _that, that) set_that.__name__ = set_that_name setattr(This, set_that_name, set_that.__get__(None, This)) setattr(This, that, property(get_that, set_that)) return This Given either of the two class factories above, the following can be done: Spam = new_foo_class("Spam", "eggs") Eggs = new_foo_class("Eggs", "spam") myspam = Spam() myeggs = Eggs() myeggs.spam = myspam myspam.set_eggs( myeggs ) print myspam.get_eggs() # prints "" print myeggs._spam # prints "" However, the following can only be done using the first example: myspam.set_eggs( eggs = myeggs ) For the second example, it would have to be this: myspam.set_eggs( that = myeggs ) The reason is that the parameter names for the first example are determined dynamically, which I don't think python allows you to do currently. The closest thing is **kwargs, but that's less readable than an actual parameter name. That was a relatively simple example; classes as simple as the ones generated by the It is more likely that the class generation could would appear in a metaclass's class constructor or decorator function, and there would be more than just the three attributes given. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Sun Nov 29 23:08:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 23:08:19 -0500 Subject: Noobie python shell question In-Reply-To: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: <4B134533.1060103@ieee.org> tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? > > TIA! > > P.S. If it makes a difference, I'm using the shell from within IDLE, > but once in a while I will use the python shell in a Bash console. > > > dir() is the answer to the question you ask. It'll display the entire global context. But usually there's a better way. If you think you previously defined a function def myfunc() .... just enter myfunc at the prompt (without parentheses). It should tell you it's a function, or undefined. DaveA From mrjean1 at gmail.com Sun Nov 29 23:12:05 2009 From: mrjean1 at gmail.com (MrJean1) Date: Sun, 29 Nov 2009 20:12:05 -0800 (PST) Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: <8e74b9ad-5b1f-48e1-bce0-22235ee68f2f@p36g2000vbn.googlegroups.com> Take a look at function timelimited in this recipe /Jean On Nov 29, 8:08?am, r0g wrote: > r0g wrote: > > r0g wrote: > >> Gabriel Genellina wrote: > >>> En Fri, 27 Nov 2009 22:35:36 -0300, r0g > >>> escribi?: > > >>>> gethostbyname ignores setdefaulttimeout. > > >>>> How big a job is it to use non-blocking sockets to write a DNS lookup > >>>> function with a customisable timeout? A few lines? A few hundred? I'd > > > > > As usual, everything is working beautifully until I try to make it work > > with windows! > > > Turns out signals.SIGALRM is Unix only and I want to run on both > > platforms so I have done as the docs suggested and tried to convert the > > code to use threading.Timer to trigger an exception if the DNS lookup is > > taking too long. > > Actually none of that was necessary in the end. Digging into the pydns > source to debug the 30 second pause I happened across the timeout parameter! > > >>> result = ping.do_one( "google.com", 5 ) > > "" > > Phew, that simplifies thing a lot! :) > > Roger. From clp2 at rebertia.com Sun Nov 29 23:14:13 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 Nov 2009 20:14:13 -0800 Subject: Noobie python shell question In-Reply-To: <4B1341BA.7060607@tim.thechases.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> <4B1341BA.7060607@tim.thechases.com> Message-ID: <50697b2c0911292014r146b5285le0f7852703f83ff6@mail.gmail.com> On Sun, Nov 29, 2009 at 7:53 PM, Tim Chase wrote: > (as an aside, is there a way to get a local/global variable from a string > like one can fetch a variable from a class/object with getattr()? ?Something > like getattr(magic_namespace_here, "hello") used in the above context? ?I > know it can be done with eval(), but that's generally considered unsafe > unless you vet your input thoroughly) locals()["hello"] and globals()["hello"], respectively Cheers, Chris -- http://blog.rebertia.com From wolftracks at invalid.com Sun Nov 29 23:14:15 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 20:14:15 -0800 Subject: Object Not Callable, float? In-Reply-To: <87aay4ralv.fsf@benfinney.id.au> References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > "W. eWatson" writes: > >> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", >> line 467, in ShowHistogram >> mean = sum(hist) >> TypeError: 'float' object is not callable > > It means you're calling an object of type ?float?. The line where it > occurred shows that you're accessing that object through the name ?sum?, > which means you've bound the name ?sum? to a float object. > >> for the code: >> ---------------------- >> sum = 0.0 > > Here you clobber the existing binding of ?sum?, binding it to the float > value 0.0. > >> avg = 0.0 >> nplt_bins = 32 >> for i in range(len(hist)): >> # msg = "%5d %6d\n" % (i,hist[i]) >> msg = "%5d %6d\n" % (i,hist[i]) >> sum = sum + hist[i] > > Here you keep re-binding the name ?sum? to new float objects of > different value. > >> text.insert( END, msg ) >> for i in range(len(hist)): >> avg = avg + (i*hist[i]/sum) >> >> mean = sum(hist) <-------------- faulty line > > Here you try to call the object referenced by the name ?sum?, which is a > float object. > >> hist is a list of 256 integers. What does float have to do with this? > > You explicitly bound the name ?sum? to an object of type ?float?. > > Solution: Choose names wisely, and if you want to use a built-in name > like ?sum? for its built-in putpose, don't clobber that binding before > using it. > Yikes. Thanks very much. Python seems to act unlike other language in which words like float are reserved. I'll use asum. From tjreedy at udel.edu Sun Nov 29 23:20:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 23:20:10 -0500 Subject: Creating a local variable scope. In-Reply-To: References: <4b12f20c@dnews.tpgi.com.au> Message-ID: markolopa wrote: > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! Leaving iteration names bound after loop exit is a feature. If you do not like it, explicitly unbind it. From pavlovevidence at gmail.com Sun Nov 29 23:23:22 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 20:23:22 -0800 (PST) Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <1cbe3891-d00c-4c2d-aa22-dc03041a5c3c@a10g2000pre.googlegroups.com> On Nov 29, 8:14?pm, "W. eWatson" wrote: > Ben Finney wrote: > > "W. eWatson" writes: > > >> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", > >> line 467, in ShowHistogram > >> ? ? mean = sum(hist) > >> TypeError: 'float' object is not callable > > > It means you're calling an object of type ?float?. The line where it > > occurred shows that you're accessing that object through the name ?sum?, > > which means you've bound the name ?sum? to a float object. > > >> for the code: > >> ---------------------- > >> ? ? ? ? sum = 0.0 > > > Here you clobber the existing binding of ?sum?, binding it to the float > > value 0.0. > > >> ? ? ? ? avg = 0.0 > >> ? ? ? ? nplt_bins = 32 > >> ? ? ? ? for i in range(len(hist)): > >> # ? ? ? ? ? ? msg = "%5d %6d\n" % (i,hist[i]) > >> ? ? ? ? ? ? msg = "%5d %6d\n" % (i,hist[i]) > >> ? ? ? ? ? ? sum = sum + hist[i] > > > Here you keep re-binding the name ?sum? to new float objects of > > different value. > > >> ? ? ? ? ? ? text.insert( END, msg ) > >> ? ? ? ? for i in range(len(hist)): > >> ? ? ? ? ? ? avg = avg + (i*hist[i]/sum) > > >> ? ? ? ? mean = sum(hist) ? <-------------- faulty line > > > Here you try to call the object referenced by the name ?sum?, which is a > > float object. > > >> hist is a list of 256 integers. What does float have to do with this? > > > You explicitly bound the name ?sum? to an object of type ?float?. > > > Solution: Choose names wisely, and if you want to use a built-in name > > like ?sum? for its built-in putpose, don't clobber that binding before > > using it. > > Yikes. Thanks very much. Python seems to act unlike other language in > which words like float are reserved. I'll use asum. That "float" isn't reserved isn't the problem here since the conflict occurred with the word sum, which is a function. Most languages I know don't reserve the names of functions. For instance you can't do this in C: int printf = 1; printf("%d\n", printf); Python doesn't reserve the names of types either, which is a little uncommon (but not unheard of), so that can be a gotcha. Carl Banks From john at castleamber.com Sun Nov 29 23:24:15 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 04:24:15 GMT Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: "W. eWatson" wrote: > Yikes. Thanks very much. Python seems to act unlike other language in > which words like float are reserved. I'll use asum. The problem is that there is a function sum and you creating a float sum: sum = 0.0 and mean = sum(hist) even if both could exist side by side it would be very confusing IMO. John From davea at ieee.org Sun Nov 29 23:30:09 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 23:30:09 -0500 Subject: Noobie python shell question In-Reply-To: <4B1341BA.7060607@tim.thechases.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> <4B1341BA.7060607@tim.thechases.com> Message-ID: <4B134A51.1030509@ieee.org> Tim Chase wrote: > > > (as an aside, is there a way to get a local/global variable from a > string like one can fetch a variable from a class/object with > getattr()? Something like getattr(magic_namespace_here, "hello") used > in the above context? I know it can be done with eval(), but that's > generally considered unsafe unless you vet your input thoroughly) > > I think you're looking for globals()["hello"], or of course magic_namespace=globals() DaveA From FearsomeDragonfly at gmail.com Mon Nov 30 00:01:37 2009 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Sun, 29 Nov 2009 23:01:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 9:59 PM, Carl Banks wrote: > Another thing that can be determined through common sense is that if > you have object that you are calling getattr and setattr on so much > that you think you need special syntax, you should have been using a > dict. > (Re-send; original was sent to the wrong address. I--I mean, Gmail--sent it to the wrong address by mistake. :P ) While you were writing this and your previous reply I was working on a response that kind of covers what you were talking about, but I'm going to say something anyway. Well, yes, the names would have to be determined at run time. That's what getattr and setattr do, except that that do it in the context of an object rather than the local scope. However, I was under the impression that python's mechanism for looking up local names was the same as the mechanism used to look up attributes because names and attributes seem to function pretty much the same way. This I assumed because of the functionality of the locals() and globals() functions, which seem to act like the __dict__ attribute on objects except that the work on the current scope. Also, there is the __builtins__ module, which actually _is_ an object, but its names can be accessed in the same way as locals and globals. I had considered the possibility of a peformance hit, however I didn't anticipate that it would be all that much. Not that it matters, but how much are we talking? 10% ? 50% ? In any case, I'm not really an expert on Python's internal constructions, but because of this discussion I'm considering taking some time to learn them. Python is unique compared to several other languages in that it makes a distinction between "items" and "attributes". Some languages, like JavaScript and Lua, do not make this distinction. They leave it to the programmer to access members of an object either as an item or as an attribute. I don't think there is necessarily anything wrong with this, nor do I think there is anything wrong with Python's separation. That said, just because you can use the proposed syntax to use an object in the same way as a dict does not mean that it works the other way around. I'm not talking about the allowance of any specific object to have any number of pairings between arbitrary keys and values. That's what dicts are for, and that's what indexing syntax implies. Rather, I'm talking about specific, concrete variables which objects are expected (though not technically required) to have bound to them according to how the object is intended to be used. (That's probably not the best definition of an attribute, but it's the best I can think of ATM.) I'm not trying to discard Python's distinction between items and attributes, but I don't want to be limited by it due to mere syntactical constraints, either. May the Penguin in the sky bless your every subroutine, Brad Harms -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 00:10:23 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 16:10:23 +1100 Subject: Variables with cross-module usage In-Reply-To: References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Message-ID: <4b135424$1@dnews.tpgi.com.au> On 11/30/2009 12:00 PM, Terry Reedy wrote: > Dennis Lee Bieber wrote: > >> In these languages, the names always refer to the same location. >> Python confuses matters by having names that don't really refer to >> location, but are attached to the objects. > > In everyday life and natural languages, names refer to people, other > objects, roles, and only occasionally to places that can be occupied. I > could claim that it is classical computer languages that confuse by > restricting names to locations in a linear sequence. You are just used > to the straightjacket ;-). In everyday life and natural languages, though an object may have many names/aliases; once objects are assigned a name, it is practically impossible to change the name to the object the name will be practically stuck to it forever. In everyday life and natural languages, a single name can be used to refer to multiple objects just by context without referring any namespace. Let's not start making analogism between nature and silicon. And of all, no one is confused. It is just a matter of assigning new shade of meaning to a word. From koranthala at gmail.com Mon Nov 30 00:10:53 2009 From: koranthala at gmail.com (koranthala) Date: Sun, 29 Nov 2009 21:10:53 -0800 (PST) Subject: Python py2exe - memory load error Message-ID: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> This is cross post from stackoverflow - I couldnt get the solution there. Hopefully, nobody would mind. I am creating a medium level application in Python. Everything works well now, and I am trying to make this a windows executable with py2exe. The executable is created fine, but when I try to run it, it fails with the following error. File "zipextimporter.pyc", line 82, in load_module File "pyAA\__init__.pyc", line 1, in ? File "zipextimporter.pyc", line 82, in load_module File "pyAA\AA.pyc", line 8, in ? File "zipextimporter.pyc", line 82, in load_module File "pyAA\pyAAc.pyc", line 5, in ? File "zipextimporter.pyc", line 98, in load_module ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd I am using pyAA in this application. I searched internet, but was unable to get any solution. I copied msvcp71.dll to windows/system32, but still issue is there. I had solved it earlier (around 7 months back), but my hard drive crashed and when I try to recreate it, I cannot seem to solve it now. :-( I would be much obliged if someone could help me out here. When I use py2exe without bundle files option, it is working perfectly. But when I use bundle file option, it is failing. I tried without zipfile option, wherein it creates a library.zip alongwith the executable. Again it failed. I did unzip of library.zip using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside the zip file. So, it looks like some issue with memoryloadlibrary function. >dir 11/30/2009 09:48 AM 25,172 AA.pyc 11/30/2009 09:48 AM 3,351 Defer.pyc 11/30/2009 09:48 AM 2,311 Path.pyc 11/30/2009 09:48 AM 11,216 pyAAc.pyc 11/30/2009 09:48 AM 5,920 Watcher.pyc 08/20/2005 02:00 PM 49,152 _pyAAc.pyd 11/30/2009 09:48 AM 162 __init__.pyc >From the trace it does look like it can extract AA.pyc etc. I am using windows7 - can it be some clue? From inhahe at gmail.com Mon Nov 30 00:15:25 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 00:15:25 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: On Sun, Nov 29, 2009 at 8:04 PM, Esmail wrote: > Chris Rebert wrote: > Wow .. never heard of Concatenative_languages languages before or the > distinction you make. Your distinction explains the behavior, but I > find it somewhat counter-intuitive. (I use the Python interpreter frequently > for small calculations - otherwise I'd never have realized this) Well I think of it like this -3**2, because of the order of operations as you know, groups as -(3**2) now if you set x to -3, (-3) is now automatically, inseparably grouped. so in a sense by setting x to that you're grouping it. x == (-3) x**2 == (-3)**2 if it still seems counterintuitive, what about the fact that it's exactly the same way in Algebra? basic algebra: -3(superscript)2 is -9 but if x is -3, then x(superscript)2 is 9 From wolftracks at invalid.com Mon Nov 30 00:20:09 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 21:20:09 -0800 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: John Bokma wrote: > "W. eWatson" wrote: > >> Yikes. Thanks very much. Python seems to act unlike other language in >> which words like float are reserved. I'll use asum. > > The problem is that there is a function sum and you creating a float sum: > > sum = 0.0 > > and > > mean = sum(hist) > > even if both could exist side by side it would be very confusing IMO. > > John I think I understand it, but how does one prevent it from happening, or know it's the cause? That msg I got? I think PL/I, FORTRAN, ALGOL, etc. have reserved words. From tjreedy at udel.edu Mon Nov 30 00:26:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 00:26:06 -0500 Subject: ANN: GMPY 1.11rc1 is available In-Reply-To: References: Message-ID: casevh wrote: > Everyone, > > I'm pleased to annouce that a new version of GMPY is available. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11rc1 is available for download from: Is this an update of the gmpy (1.02) registered at http://pypi.python.org/pypi/gmpy/1.02? Either way, please list it (with modified name if needed) and note that it is 3.x compatible so people searching for such packages can find it. From tjreedy at udel.edu Mon Nov 30 00:28:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 00:28:12 -0500 Subject: Exec Statement Question In-Reply-To: <4B133AA3.4060405@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> Message-ID: Dave Angel wrote: > exec is a statement, and statements don't have "return values." It's > not a function, In 3.x, it is a function, though the use of print as a statement indicates that the OP was using 2.x. From fearsomedragonfly at gmail.com Mon Nov 30 00:37:54 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 23:37:54 -0600 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 11:01 PM, Brad Harms wrote: > > May the Penguin in the sky bless your every subroutine, > Um...feel free to ignore that. >_> -- Brad Harms -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 00:44:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 16:44:50 +1100 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <4b135c37$1@dnews.tpgi.com.au> On 11/30/2009 4:20 PM, W. eWatson wrote: > John Bokma wrote: >> "W. eWatson" wrote: >> >>> Yikes. Thanks very much. Python seems to act unlike other language in >>> which words like float are reserved. I'll use asum. >> >> The problem is that there is a function sum and you creating a float sum: >> >> sum = 0.0 >> >> and >> >> mean = sum(hist) >> >> even if both could exist side by side it would be very confusing IMO. >> >> John > I think I understand it, but how does one prevent it from happening, or > know it's the cause? That msg I got? > > I think PL/I, FORTRAN, ALGOL, etc. have reserved words. Generally, use PyLint or similar tools; they'll warn you. From mwilson at the-wire.com Mon Nov 30 01:07:53 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 30 Nov 2009 01:07:53 -0500 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: W. eWatson wrote: > I think PL/I, FORTRAN, ALGOL, etc. have reserved words. Algol reserved syntactic tokens that resembled English words, but specified that they should be written in a different way from programmer-defined symbols, so no conflict was possible. Published algorithms might have the tokens underlined or boldfaced. In the Algol-60 I used, the tokens had to be enclosed in apostrophes. None of this applied to library subroutine names; it was open season on those. In FORTRAN and PL/I words were un-reserved to a degree that's really bizarre. A short post can't begin to do it justice -- let's just mention that IF and THEN could be variable names, and DO 100 I=1.10 . The syntaxes were carefully crafted so that context completely determined whether a symbol would be taken in a reserved sense or a programmer-defined sense, so any possibility for conflict was a syntax error. Mel. From prakash.stack at gmail.com Mon Nov 30 01:36:25 2009 From: prakash.stack at gmail.com (prakash jp) Date: Mon, 30 Nov 2009 12:06:25 +0530 Subject: Python py2exe - memory load error In-Reply-To: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> References: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> Message-ID: <805f59d50911292236i6b442778mbc073a988c86ea73@mail.gmail.com> Try to install "vcredist_x86.exe", then try to build using py2exe. I think that should solve the issue Regards Prakash On Mon, Nov 30, 2009 at 10:40 AM, koranthala wrote: > This is cross post from stackoverflow - I couldnt get the solution > there. Hopefully, nobody would mind. > > I am creating a medium level application in Python. Everything works > well now, and I am trying to make this a windows executable with > py2exe. The executable is created fine, but when I try to run it, it > fails with the following error. > > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\__init__.pyc", line 1, in ? > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\AA.pyc", line 8, in ? > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\pyAAc.pyc", line 5, in ? > File "zipextimporter.pyc", line 98, in load_module > ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd > > I am using pyAA in this application. I searched internet, but was > unable to get any solution. I copied msvcp71.dll to windows/system32, > but still issue is there. > > I had solved it earlier (around 7 months back), but my hard drive > crashed and when I try to recreate it, I cannot seem to solve it > now. :-( > > I would be much obliged if someone could help me out here. > > When I use py2exe without bundle files option, it is working > perfectly. But when I use bundle file option, it is failing. > > I tried without zipfile option, wherein it creates a library.zip > alongwith the executable. Again it failed. I did unzip of library.zip > using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside > the zip file. So, it looks like some issue with memoryloadlibrary > function. > > >dir > 11/30/2009 09:48 AM 25,172 AA.pyc > 11/30/2009 09:48 AM 3,351 Defer.pyc > 11/30/2009 09:48 AM 2,311 Path.pyc > 11/30/2009 09:48 AM 11,216 pyAAc.pyc > 11/30/2009 09:48 AM 5,920 Watcher.pyc > 08/20/2005 02:00 PM 49,152 _pyAAc.pyd > 11/30/2009 09:48 AM 162 __init__.pyc > > >From the trace it does look like it can extract AA.pyc etc. I am using > windows7 - can it be some clue? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grimsqueaker13 at gmail.com Mon Nov 30 01:42:50 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:42:50 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: On Nov 28, 11:26?am, Vinay Sajip wrote: > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > When I add a Filter to a Handler, everything works as expected (ie. > > all messages sent from Loggers below the Filter's level are allowed > > through), but when I add the Filter directly on to the Logger, only > > that Logger is blocked, regardless of the contents of the Filter. > > The key thing to remember is that when a logger processes an event, > handlers attached to it *and all its parents* are offered the event > for handling. In the case where you have just one handler and it has > the filter attached, filtering works as you expected. By attaching the > filter to the root logger, you are not filtering its handler; this > handler is invoked for events logged to all the other loggers, and so > (apart from the event at the root logger) those events are not > filtered. > > For some examples of filter usage, see this post: > > http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > Regards, > > Vinay Sajip OK, that makes sense, but does this mean that I am unable to block a logging path from one point? ie. in my example, I would have to add Filter(loggerB.name) to every Logger in the 'A' path to block the A path from showing at my root Handler? Is there no way I can just block the whole 'A' path from one point? I was under the impression that Filters worked hierarchically and that a message would be passed up the chain of Loggers until it was stopped by a Filter (or its loglevel was not allowed). Thanks for your help From grimsqueaker13 at gmail.com Mon Nov 30 01:52:09 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:52:09 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: <0eaf51df-ed54-4f63-9514-76077a378ee6@v30g2000yqm.googlegroups.com> On Nov 30, 8:42?am, Grimsqueaker wrote: > On Nov 28, 11:26?am, Vinay Sajip wrote: > > > > > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > > When I add a Filter to a Handler, everything works as expected (ie. > > > all messages sent from Loggers below the Filter's level are allowed > > > through), but when I add the Filter directly on to the Logger, only > > > that Logger is blocked, regardless of the contents of the Filter. > > > The key thing to remember is that when a logger processes an event, > > handlers attached to it *and all its parents* are offered the event > > for handling. In the case where you have just one handler and it has > > the filter attached, filtering works as you expected. By attaching the > > filter to the root logger, you are not filtering its handler; this > > handler is invoked for events logged to all the other loggers, and so > > (apart from the event at the root logger) those events are not > > filtered. > > > For some examples of filter usage, see this post: > > >http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > > Regards, > > > Vinay Sajip > > OK, that makes sense, but does this mean that I am unable to block a > logging path from one point? ie. in my example, I would have to add > Filter(loggerB.name) to every Logger in the 'A' path to block the A > path from showing at my root Handler? Is there no way I can just block > the whole 'A' path from one point? I was under the impression that > Filters worked hierarchically and that a message would be passed up > the chain of Loggers until it was stopped by a Filter (or its loglevel > was not allowed). > > Thanks for your help So would I be correct in saying that Filters apply only the the object they are attached to and have no effect on how messages are propagated through the logging hierarchy? If this is the case my next question would be: How can I affect whether or not a message is propagated further up the tree? Sorry to post again so quickly. From grimsqueaker13 at gmail.com Mon Nov 30 01:52:17 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:52:17 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: On Nov 30, 8:42?am, Grimsqueaker wrote: > On Nov 28, 11:26?am, Vinay Sajip wrote: > > > > > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > > When I add a Filter to a Handler, everything works as expected (ie. > > > all messages sent from Loggers below the Filter's level are allowed > > > through), but when I add the Filter directly on to the Logger, only > > > that Logger is blocked, regardless of the contents of the Filter. > > > The key thing to remember is that when a logger processes an event, > > handlers attached to it *and all its parents* are offered the event > > for handling. In the case where you have just one handler and it has > > the filter attached, filtering works as you expected. By attaching the > > filter to the root logger, you are not filtering its handler; this > > handler is invoked for events logged to all the other loggers, and so > > (apart from the event at the root logger) those events are not > > filtered. > > > For some examples of filter usage, see this post: > > >http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > > Regards, > > > Vinay Sajip > > OK, that makes sense, but does this mean that I am unable to block a > logging path from one point? ie. in my example, I would have to add > Filter(loggerB.name) to every Logger in the 'A' path to block the A > path from showing at my root Handler? Is there no way I can just block > the whole 'A' path from one point? I was under the impression that > Filters worked hierarchically and that a message would be passed up > the chain of Loggers until it was stopped by a Filter (or its loglevel > was not allowed). > > Thanks for your help So would I be correct in saying that Filters apply only the the object they are attached to and have no effect on how messages are propagated through the logging hierarchy? If this is the case my next question would be: How can I affect whether or not a message is propagated further up the tree? Sorry to post again so quickly. From ben+python at benfinney.id.au Mon Nov 30 01:54:52 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 17:54:52 +1100 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <87y6lopkn7.fsf@benfinney.id.au> "W. eWatson" writes: > I think I understand it, but how does one prevent it from happening, > or know it's the cause? That msg I got? Yes. The line of code was pretty clear: you were attempting to call an object, and the error message said the object's type doesn't support being called. More generally, you should insert an automatic step into your workflow where you run a static code checker like ?pyflakes? over all of your code to catch common errors and mistakes. -- \ ?To me, boxing is like a ballet, except there's no music, no | `\ choreography, and the dancers hit each other.? ?Jack Handey | _o__) | Ben Finney From n00m at narod.ru Mon Nov 30 02:36:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 23:36:16 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Message-ID: On Nov 29, 11:43?pm, Bearophile wrote: > Anyway, you may try a pure-Python2.x implementation:http://suffixtree.googlecode.com/files/suffixtree-0.1.py Ouch, Bearie... 214 lines of code are there. Ok.. I tested it. Firstly I replaced all "print " with "pass##print " (aiming to avoid intensive printing from inside of the code). Then I left in its final part only building of suffix trees. ================================================================== ... ... ... from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] test_str = s + '$' POSITIVE_INFINITY = len(test_str) - 1 suffix_tree = SuffixTree(test_str) print >> z, 'len(s) =', len(s) print >> z, 'time =', time() - t z.close() ============================================================ Output: ============================================================ len(s) = 1000 len(s) = 1000 len(s) = 10000 time = 0.641000032425 ============================================================ 0.64s > 0.48s (of my algo) I.e. the code can't help in my very special and narrow case. But of course it is worthy to be studied and memoized. E.g.: from huge string "s" we built its Suffix Tree. Now we are given arbitrary string "ss". Task: to find the largest its prefix occured in "s", traversing its Suffix Tree. From callmeclaudius at gmail.com Mon Nov 30 03:17:38 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Mon, 30 Nov 2009 00:17:38 -0800 (PST) Subject: Unpacking Tuples Message-ID: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> I hate to post such a simple Q and A here, but I seriously can't find it anywhere. Python (unsure of starting with which version) enables the remainder of the tuple to be placed in a "catch-all", for example: >> myTuple = (1,2,3,4) >> varOne, varTwo, *remaindingTuple = myTuple. where the values left unpacked get thrown into a tuple referenced to by "remaindingTuple" I included the asterix because it seems like I remember that being the operator that specifying the tuple's dumping ground. Which brings me to my two questions: 1) what's the syntax for this operation 2) what version does it start with? From d.dalton at iinet.net.au Mon Nov 30 03:20:59 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 19:20:59 +1100 Subject: python and vc numbers In-Reply-To: <7ngl1gF3ml76pU1@mid.individual.net> References: <7ngl1gF3ml76pU1@mid.individual.net> Message-ID: <20091130082059.GA10079@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 02:21:54PM +1300, Gregory Ewing wrote: > >I use to figure out what tty my program was invoked from? > > Here's one way: > > % python > Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.popen("tty").read() That did the trick, thanks, after I append [-2] It works great. Thanks Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From Nadav.C at qualisystems.com Mon Nov 30 03:25:35 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Mon, 30 Nov 2009 10:25:35 +0200 Subject: Running function from Win32 dll Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947BB4@exchange.qualisystems.local> Hi all, I want to run function from win32 dll. I used ctypes.windll.LoadLibrary to load the DLL. But I don't know how to select function and run it. Dll example attached (pylab.dll). It includes 2 functions: double Add(double a,double b) - adds 2 double numbers double Random(void) - generates random number Thank you, Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pylab.rar Type: application/octet-stream Size: 12749 bytes Desc: pylab.rar URL: From clp2 at rebertia.com Mon Nov 30 03:26:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 00:26:44 -0800 Subject: Unpacking Tuples In-Reply-To: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> References: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> Message-ID: <50697b2c0911300026v139776a3n4b4b8f5babf06dd1@mail.gmail.com> On Mon, Nov 30, 2009 at 12:17 AM, Joel Davis wrote: > I hate to post such a simple Q and A here, but I seriously can't find > it anywhere. Python (unsure of starting with which version) enables > the remainder of the tuple to be placed in a "catch-all", for example: > > >>> myTuple = (1,2,3,4) >>> varOne, varTwo, *remaindingTuple = myTuple. > > where the values left unpacked get thrown into a tuple referenced to > by "remaindingTuple" I included the asterix because it seems like I > remember that being the operator that specifying the tuple's dumping > ground. Which brings me to my two questions: > 1) what's the syntax for this operation Exactly as you showed above (well, minus the period obviously). 2) what version does it start with? Python 3.0 It might be backported into 2.7 when it gets released: http://bugs.python.org/issue2340 Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Mon Nov 30 03:32:38 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 30 Nov 2009 00:32:38 -0800 Subject: Unpacking Tuples In-Reply-To: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> References: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> Message-ID: <4B138326.6060500@islandtraining.com> Joel Davis wrote: > I hate to post such a simple Q and A here, but I seriously can't find > it anywhere. Python (unsure of starting with which version) enables > the remainder of the tuple to be placed in a "catch-all", for example: > > > >>> myTuple = (1,2,3,4) >>> varOne, varTwo, *remaindingTuple = myTuple. >>> > > where the values left unpacked get thrown into a tuple referenced to > by "remaindingTuple" I included the asterix because it seems like I > remember that being the operator that specifying the tuple's dumping > ground. Which brings me to my two questions: 1) what's the syntax for > this operation 2) what version does it start with? > 1) Syntax is just as you have it. (Not including the period you have at the end.) 2) Python 3.0 Gary Herron From Nadav.C at qualisystems.com Mon Nov 30 03:39:40 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Mon, 30 Nov 2009 10:39:40 +0200 Subject: Running function from win32 dll Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> Hi all, I want to run function from win32 dll. I used ctypes.windll.LoadLibrary to load the DLL. But I don't know how to select function and run it. Thank you, Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: From estartu at augusta.de Mon Nov 30 03:41:15 2009 From: estartu at augusta.de (Gerhard Schmidt) Date: Mon, 30 Nov 2009 09:41:15 +0100 Subject: Creating a datetime object from a C Extention Message-ID: HI, I'm writing a python C Extension and need to create datetime objects but when I call value = PyDateTime_FromDateAndTime(ti->tm_year+1900, ti->tm_mon, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec, u); I get an SegFault. ti = {tm_sec = 25, tm_min = 37, tm_hour = 8, tm_mday = 30, tm_mon = 10, tm_year = 109, tm_wday = 1, tm_yday = 333, tm_isdst = 0, tm_gmtoff = 0, tm_zone = 0x800fd20c8 "UTC"} u = 0 Is there an Dokumentation or example code HowTo create a datetime object from a C Extension. Regards Estartu -- ---------------------------------------------------------------------------- Gerhard Schmidt | http://www.augusta.de/~estartu/ | Fischbachweg 3 | | PGP Public Key 86856 Hiltenfingen | JabberID: estartu at augusta.de | auf Anfrage/ Tel: 08232 77 36 4 | IRCNET: Estartu | on request Fax: 08232 77 36 3 | | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 369 bytes Desc: OpenPGP digital signature URL: From greg.ewing at canterbury.ac.nz Mon Nov 30 03:46:42 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 30 Nov 2009 21:46:42 +1300 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: <7nhf3eF3lrgr4U1@mid.individual.net> Esmail wrote: > Wow .. never heard of Concatenative_languages languages before or the > distinction you make. Your distinction explains the behavior, but I > find it somewhat counter-intuitive. You shouldn't find it any more surprising than the fact that a = 2 + 3 print a * 5 gives a different result from print 2 + 3 * 5 -- Greg From marko.loparic at gmail.com Mon Nov 30 03:50:04 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 30 Nov 2009 00:50:04 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <1e5e38b7-3b75-4db6-b8f4-a5adb18fd91a@b15g2000yqd.googlegroups.com> Hi Steve! On Nov 30, 1:46?am, Steve Howell wrote: > I occasionally make the error you make, but I think the real problem > you are having is lack of attention to detail. ?If name collisions are > a common problem for you, consider writing shorter methods Yes, this could be a solution, though I believe that too many (sub) methods called by a single method turn the code less readable. > or develop > the habit of using more descriptive variable names. Also a good suggestion. Alternatively I have considered to do the opposite, to use weird (the opposite of descriptive) names for variables that should exist only inside the block, in order to differentiate them from the variables that should persist. > ?In the code > above, you could have easily cleaned up the namespace by extracting a > method called get_arg_columns(). ?Having to spend 15 minutes tracking > down a bug usually indicates that you are not being systematic in your > thinking. ?If you are rushing too much, slow down. ?If you are tired, > take a break. ?If you make the same mistake twice, commit to yourself > not to make it a third time. ?Also, test your methods one at a time > and get them rock solid before writing more code. Nice suggestions thanks, all of them apply to me!...:-) Compared to the normal coder I have a strong tendency to loose myself in details. That is why I have to be very systematic, write lots of defensive code (to catch the bugs as soon as possible), write unit tests (great habit I've developped recently!). Python is fantastic for those goals. The only laking feature I find is really the survival of variables, a problem that does not exist in C++ or in Perl (with use strict). Besides this kind of bug I have noticed only 2 other sources of bug I had more than once with python code. - expecting float from integer division (easily avoidable, either with 3.0 or from __future__...) - expecting diferent objects in a list have having the same several times (deepcopy issue, also easily avoidable once we know it) So my only other problem is with this "survival" feature. I consider to write my own version of Python, the one that would not allow the usage of varaibles outside the block it was created. Of course I won't rewrite CPython but I could add an error (or warning) to pylint. With some luck it already exists, I will investigate... Greets! Marko From cindyqjm at gmail.com Mon Nov 30 03:56:09 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:09 -0800 (PST) Subject: delete column content References: Message-ID: <2397e4fa-b863-46ce-b65a-672363ee0ee3@g22g2000prf.googlegroups.com> On 11?30?, ??2?12?, Francesco Pietra wrote: > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help > > francesco pietra > > ?delete.label.py > < 1K???? http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Mon Nov 30 03:56:19 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:19 -0800 (PST) Subject: delete column content References: <7nfsp6F3lpbpvU1@mid.uni-berlin.de> Message-ID: <3db6d209-9194-4bd4-b6d1-7d46580028fd@e4g2000prn.googlegroups.com> On 11?30?, ??2?27?, "Diez B. Roggisch" wrote: > Francesco Pietra schrieb: > > > Hi: > > How to replace with blank the single-character in column 21 of a pdb > > file (in pdb numbering it is column 22). Attached is an incomplete > > exercise with slices. I am unable to get real plain text with gmail. > > > Thanks for help > > Wasn't the help you already got a few days ago sufficient? > > Diez http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Mon Nov 30 03:56:24 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:24 -0800 (PST) Subject: delete column content References: Message-ID: <674ee6a8-41c7-4379-b364-dfec070d3adf@u36g2000prn.googlegroups.com> On 11?30?, ??2?48?, Vlastimil Brom wrote: > 2009/11/29 Francesco Pietra : > > > Hi: > > How to replace with blank the single-character in column 21 of a pdb > > file (in pdb numbering it is column 22). Attached is an incomplete > > exercise with slices. I am unable to get real plain text with gmail. > > > Thanks for help > > > francesco pietra > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Do you mean something like > > >>> line="abcdefghijklmnopqrstuvwxyz" > >>> line[:21]+line[22:] > > 'abcdefghijklmnopqrstuwxyz' > > ? > > vbr http://www.mbthome.net/ mbt shoes From martin at v.loewis.de Mon Nov 30 04:07:22 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Nov 2009 10:07:22 +0100 Subject: Creating a datetime object from a C Extention In-Reply-To: References: Message-ID: <4B138B4A.1070106@v.loewis.de> > I'm writing a python C Extension and need to create datetime objects but > when I call > value = PyDateTime_FromDateAndTime(ti->tm_year+1900, ti->tm_mon, > ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec, u); > I get an SegFault. > > ti = {tm_sec = 25, tm_min = 37, tm_hour = 8, tm_mday = 30, tm_mon = 10, > tm_year = 109, tm_wday = 1, tm_yday = 333, tm_isdst = 0, > tm_gmtoff = 0, tm_zone = 0x800fd20c8 "UTC"} > u = 0 > > Is there an Dokumentation or example code HowTo create a datetime object > from a C Extension. You need to put PyDateTime_IMPORT; into your module's init function. HTH, Martin From marko.loparic at gmail.com Mon Nov 30 04:13:35 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 30 Nov 2009 01:13:35 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> On Nov 30, 4:46?am, Dave Angel wrote: > markolopa wrote: > > Antoher 15 minutes lost because of that Python "feature"... Is it only > > me??? > > Yep, I think so. Not very consoling but thanks anyway!...:-)))) >?You're proposing a much more complex scoping rule, > where if a variable already exists before entering a loop, then the loop > uses that existing variable, but if not, it creates its own local one > and destroys it when exiting the loop. Alternatively you could forbid the creation of a variable in a inner block if it already exists. Either that or forbid the usage of the variable in an outter block later if it exists both in an inner and outer block. Aren't there languages that forbid the declarations of variables in a function with the same name as global variables? I know that this is an extreme defensive measure, but I have to say that I like it. Allowing to create a new variable when a variable with the same name is already exists in the namespace makes for harm that good, for me at least. Of course this issue is much broader than the one I proposed initially. > I think if you had your wish, you'd find that you had more exceptions > where you had to pre-declare things, than the times when you avoided the > bugs you describe. ? You are probably right, otherwise Guido would have done what I suggest... but I really don't see why. > I don't like languages that make me write extra > stuff 100 times, to save one instance of extra debugging. ?If Python > already required declarations, then I might buy your arguments. ?But it > wouldn't be Python. My guess is that if the change I propose was implemented, the number additional lines that would be needed to make the present python code work would be 1 in a thousand or less. Of course I may be wrong... Besides this additional line can make the code more readable, strassing the fact that the variable inside the block actually "belongs" to outside. > In your particular case, the compiler couldn't guess whether you used > the first loop to decide which domain to use in the second loop, That is what I wish the compiler should forbid...:-> > or > whether you accidentally reused the same name without giving it a new > value in the new loop. ? That is what I do regularly...8-> > If you need to use the same name, you could > always follow your loops with the del statement to invalidate the name. Several people have suggested explicit destruction of the variables I don't need. Python allows it but of course this does not solve my problem. It does not make sense to use such a clean language as Python and regularly delete all variables used inside the blocks when leaving it. And of course the bug comes because I have no idea that I am using the same name again. Cheers! Marko From nick at craig-wood.com Mon Nov 30 04:30:14 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 30 Nov 2009 03:30:14 -0600 Subject: ANN: GMPY 1.11rc1 is available References: Message-ID: casevh wrote: > I'm pleased to annouce that a new version of GMPY is available. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11rc1 is available for download from: [snip] > Future plans > > On releasing the GIL: I have compared releasing the GIL versus the > multiprocessing module and the multiprocessing module offers better > and more predictable performance for embarrassingly parallel tasks > than releasing the GIL. If there are requests, I can add a compile- > time option to enable threading support but it is unlikely to > become the default. You could have variant types of mpz etc which do release the GIL so you could mix and match accordingly. > On mutable integers: The performance advantages of mutable integers > appears to be 20% to 30% for some operations. I plan to add a new > mutable integer type in the next release of GMPY. If you want to > experiment with mutable integers now, GMPY can be compiled with > mutable version of the standard 'mpz' type. Please see the file > "mutable_mpz.txt" for more information. Mutable integers - whatever will they think of next ;-) Thanks for maintaining gmpy - it is an excellent bit of software! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From lie.1296 at gmail.com Mon Nov 30 04:30:16 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 20:30:16 +1100 Subject: Creating a local variable scope. In-Reply-To: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: <4b13910d$1@dnews.tpgi.com.au> On 11/30/2009 8:13 PM, markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: >> markolopa wrote: >>> Antoher 15 minutes lost because of that Python "feature"... Is it only >>> me??? >> >> Yep, I think so. > > Not very consoling but thanks anyway!...:-)))) > >> You're proposing a much more complex scoping rule, >> where if a variable already exists before entering a loop, then the loop >> uses that existing variable, but if not, it creates its own local one >> and destroys it when exiting the loop. > > Alternatively you could forbid the creation of a variable in a inner > block if it already exists. Either that or forbid the usage of the > variable in an outter block later if it exists both in an inner and > outer block. > Of course, the best solution would be to allow assignment only in a single line of source of code. Reassignment by different lines of code would be a syntax error. You're forced to have different names if you want assign something multiple times. That way, no bugs is possible. From d.dalton at iinet.net.au Mon Nov 30 05:02:00 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 21:02:00 +1100 Subject: python and vc numbers In-Reply-To: <20091130082059.GA10079@gwsc.vic.edu.au> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> Message-ID: <20091130100200.GB12885@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 07:20:59PM +1100, Daniel Dalton wrote: > That did the trick, thanks, after I append > [-2] Further testing under screen says otherwise -- it seems to give me the tty number, not the virtual console number. Is there any way to figure out what virtual console I'm am in so a certain command ran under screen process A isn't confused with a command ran under screen process B? Thanks Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From nobody at nowhere.com Mon Nov 30 05:19:07 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 30 Nov 2009 10:19:07 +0000 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: On Mon, 30 Nov 2009 01:07:53 -0500, Mel wrote: > In FORTRAN and PL/I words were un-reserved to a degree that's really > bizarre. A short post can't begin to do it justice -- let's just mention > that IF and THEN could be variable names, and DO 100 I=1.10 . The syntaxes > were carefully crafted so that context completely determined whether a > symbol would be taken in a reserved sense or a programmer-defined sense, so > any possibility for conflict was a syntax error. And then Lisp and Tcl just don't have reserved words. Many symbols are pre-defined, but you're free to re-define them (Lisp won't let you use 'quote' as a function name, but you can still use it as a variable name). From steve at REMOVE-THIS-cybersource.com.au Mon Nov 30 05:25:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Nov 2009 10:25:11 GMT Subject: Creating a local variable scope. References: Message-ID: <009d2203$0$26893$c3e8da3@news.astraweb.com> On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: > I think if one could somehow declare names as const (final, readonly, > whatever) then that would cover the above plus much more. Having real constants is one feature that I miss. Because Python doesn't have constants, I find I've lost the discipline to avoid "magic numbers" (and strings) in my code. -- Steven From clp2 at rebertia.com Mon Nov 30 05:26:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 02:26:14 -0800 Subject: python and vc numbers In-Reply-To: <20091130100200.GB12885@gwsc.vic.edu.au> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> Message-ID: <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> On Mon, Nov 30, 2009 at 2:02 AM, Daniel Dalton wrote: > > On Mon, Nov 30, 2009 at 07:20:59PM +1100, Daniel Dalton wrote: >> That did the trick, thanks, after I append >> [-2] > > Further testing under screen says otherwise -- it seems to give me the > tty number, not the virtual console number. Is there any way to figure > out what virtual console I'm am in so a certain command ran under screen > process A isn't confused with a command ran under screen process B? >From what I can find, virtual console == tty. Quoting http://en.wikipedia.org/wiki/Virtual_console_%28PC%29 "The virtual consoles are represented by device special files /dev/tty1, /dev/tty2 etc." Also, in my quickie newbie experimentation with `screen`, each screen "window" seems to get a unique tty#. Admittedly I am running OS X here, so if your notion of "virtual console" differs from Wikipedia's and is Linux-specific or something... Perhaps if you could explain your problem in greater detail? Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Nov 30 05:29:10 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 30 Nov 2009 05:29:10 -0500 Subject: Creating a local variable scope. In-Reply-To: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: <4B139E76.70105@ieee.org> markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: > >> markolopa wrote: >> >>> Antoher 15 minutes lost because of that Python "feature"... Is it only >>> me??? >>> >> Yep, I think so. >> > > Not very consoling but thanks anyway!...:-)))) > > >> You're proposing a much more complex scoping rule, >> where if a variable already exists before entering a loop, then the loop >> uses that existing variable, but if not, it creates its own local one >> and destroys it when exiting the loop. >> > > Alternatively you could forbid the creation of a variable in a inner > block if it already exists. Somehow you seem to think there's some syntax for "creating" a variable. In fact, what's happening is you're binding/rebinding a name to an object. And if you forbid doing this inside the loop, for names that exist outside the loop, then most of the useful work the loop does becomes impossible. Remember, in Python, there's no declaration of a variable (except the global statement, which does it sort-of). So you'd be disallowing the following: counter = 5 for item in itemlist: if item > 19: counter = counter + 5 The only way I can think you possibly want this is if you're just referring to "loop variables", such as "item" in the above example. The problem is that on many loops, for example a "while" loop, there's no such thing. > Either that or forbid the usage of the > variable in an outter block later if it exists both in an inner and > outer block. > > You need to define "exists" in order to make discussion unambiguous. Without extra declarations of some type, I can't believe there's any way to make any variation of this concept work in the general case. > Aren't there languages that forbid the declarations of variables in a > function with the same name as global variables? I know that this is > an extreme defensive measure, but I have to say that I like it. > Allowing to create a new variable when a variable with the same name > is already exists in the namespace makes for harm that good, for me at > least. Of course this issue is much broader than the one I proposed > initially. > > I can't think of any, among the 35 languages I've programmed in professionally over the years. All right, to be fair, about half of those were assembly languages at various levels. And I don't believe I worked in any assembly language that even had separate scoping for functions. DaveA From jeanmichel at sequans.com Mon Nov 30 06:02:53 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 30 Nov 2009 12:02:53 +0100 Subject: Creating a local variable scope. In-Reply-To: <009d2203$0$26893$c3e8da3@news.astraweb.com> References: <009d2203$0$26893$c3e8da3@news.astraweb.com> Message-ID: <4B13A65D.6010902@sequans.com> Steven D'Aprano wrote: > On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: > > >> I think if one could somehow declare names as const (final, readonly, >> whatever) then that would cover the above plus much more. >> > > Having real constants is one feature that I miss. Because Python doesn't > have constants, I find I've lost the discipline to avoid "magic > numbers" (and strings) in my code. > > > I don't get you, this can be easily avoid with a strong naming convention. I mean, despite they are not really constants, you can still use variables to name your numbers and string, to give the reader a usefull hint on the meaning of your code. Yet it is still a matter of discipline, it is sometimes very tempting to put the string directly (unlike numbers string can be meaningful sometimes) JM From d.dalton at iinet.net.au Mon Nov 30 06:05:18 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 22:05:18 +1100 Subject: python and vc numbers In-Reply-To: <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> Message-ID: <20091130110518.GA799@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 02:26:14AM -0800, Chris Rebert wrote: > Also, in my quickie newbie experimentation with `screen`, each screen > "window" seems to get a unique tty#. Admittedly I am running OS X Correct (Which creates the problem) > Perhaps if you could explain your problem in greater detail? Sure, well, first I am running screen in a console. Under screen I open many windows, but in my .screenrc file, after 15 minutes screen runs screen lock which is the equivalent of /usr/local/bin/lock /usr/local/bin/lock is my python script, basically it checks to see if file /tmp/.vlock.run exists and if it does, will not run vlock again, but if it doesn't then passes onto vlock. When vlock returns a clean exit, eg. the user unlocks the term, my program removes that statefile and exits nicely. (the purpose of this is so screen doesn't lock the system hundreds of times, asking for a password hundreds of times, or when using -na it doesn't create a bunch of useless blank "lock" windows in my screen session. This works well, but it is only useful for one tty, because if you lock tty1 then it blocks tty2 etc. I know I could have a bunch of different scripts using different files, but this just gets to complicated to manage, so the logical solution is to append vc number to the filename: /tmp/.vlock.run.1 /tmp/.vlock.run.2 etc So we can identify which consoles have been locked, and which haven't. The problem lies with the fact, I can't find a reliable way to determine the current console number with python or any bash tool. When I say console number, I mean the actual console number, not screen window or device it is sending to or whatever. I am totally blind, and therefore use a package called brltty, and this package has the ability to show me what number console I'm in, and even under screen always works reliably and consistently. So anyone know of a better solution, now I have described the issue in great detail? Thanks very much for all the help. Cheers, Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From paul at boddie.org.uk Mon Nov 30 06:15:18 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 30 Nov 2009 03:15:18 -0800 (PST) Subject: Imitating "tail -f" References: Message-ID: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> On 22 Nov, 05:10, exar... at twistedmatrix.com wrote: > > "tail -f" is implemented by sleeping a little bit and then reading to > see if there's anything new. This was the apparent assertion behind the "99 Bottles" concurrency example: http://wiki.python.org/moin/Concurrency/99Bottles However, as I pointed out (and as others have pointed out here), a realistic emulation of "tail -f" would actually involve handling events from operating system mechanisms. Here's the exchange I had at the time: http://wiki.python.org/moin/Concurrency/99Bottles?action=diff&rev2=12&rev1=11 It can be very tricky to think up good examples of multiprocessing (which is what the above page was presumably intended to investigate), as opposed to concurrency (which can quite easily encompass responding to events asynchronously in a single process). Paul P.S. What's Twisted's story on multiprocessing support? In my limited experience, the bulk of the work in providing usable multiprocessing solutions is in the communications handling, which is something Twisted should do very well. From victorsubervi at gmail.com Mon Nov 30 06:23:59 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 06:23:59 -0500 Subject: Exec Statement Question In-Reply-To: <4B133AA3.4060405@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> Message-ID: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: > exec is a statement, and statements don't have "return values." It's not > a function, so there are no parentheses in its syntax, either. exec is also > a technique of last resort; there's nearly always a better/safer/faster way > to accomplish what you might want, but of course you don't say what that is. > > As for "returning" values, exec by default uses the same global space as > your app, so you can just modify a global variable in your "called" code and > use it afterwards. > > abc = 42 > value = 12 > exec "abc = %d" % value > print abc > Taking out the parenthesis did it! Thanks. Now, you state this is an option of last resort. Although this does indeed achieve my desired aim, here is a complete example of what I am trying to achieve. The following is from 'createTables2.py': for table in tables: try: exec 'from options import %s' % table except: pass try: exec '%s()' % table except: pass The following is from 'options.py': def jewelry(which=''): code = [] names = [] meanings = [] code.append(['5', '5½', '6', '6½', '7', '7½', '8', '8½', '9', '9½', '10', '10½', '11', '11½', '12', '12½', '13', '13½']) meanings.append('The standard ring sizes.') names.append('ringSizes') code.append(['Petite (7")', 'Average (7½")', 'Large (8")', 'Extra-large (8½")']) meanings.append('The standard bracelet sizes.') names.append('braceletSizes') code.append(['16"', '18"', '20"', '22"', '24"']) meanings.append('The standard necklace sizes.') names.append('necklaceSizes') code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K white gold', 'platinum', 'tungsten', 'titanium']) meanings.append('The standard jewelry metals.') names.append('metals') code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', 'turquoise']) meanings.append('The standard jewelry stones.') names.append('stones') if which == '': i = 0 all = '' while i < len(meanings): table = '%s\n' % meanings[i] table += "\n \n \n " % names[i] j = 0 for elt in code: if (j + 8) % 8 == 0: table += ' \n' table += ' \n' % code[i] if (j + 8) % 8 == 0: table += ' \n' j += 1 if table[-6:] != '\n': table += ' \n' table += '
    %s
    %s
    \n' all += table + '

    ' i += 1 print all This all works fine; however, if there is a better way of doing it, please let me know. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Nov 30 06:34:59 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 12:34:59 +0100 Subject: Creating a local variable scope. In-Reply-To: References: <009d2203$0$26893$c3e8da3@news.astraweb.com> Message-ID: * Jean-Michel Pichavant: > Steven D'Aprano wrote: >> On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: >> >> >>> I think if one could somehow declare names as const (final, readonly, >>> whatever) then that would cover the above plus much more. >>> >> >> Having real constants is one feature that I miss. Because Python >> doesn't have constants, I find I've lost the discipline to avoid >> "magic numbers" (and strings) in my code. >> >> >> > I don't get you, this can be easily avoid with a strong naming > convention. I mean, despite they are not really constants, you can still > use variables to name your numbers and string, to give the reader a > usefull hint on the meaning of your code. Yet it is still a matter of > discipline, it is sometimes very tempting to put the string directly > (unlike numbers string can be meaningful sometimes) It may be surprising how many things turn out to be readonly. Consider the OP's code: class ValueColumn(AbstractColumn): def __init__(self, name, header, domain_names): if type(domain_names) != tuple: raise ValueError('a tuple of domain names must be given') for name in domain_names: if type(name) != str: raise ValueError('a tuple of domain names must be given') self.domain_names = domain_names super(ValueColumn, self).__init__(name, header) Here the arguments should ideally be read only names, which would have cought the bug of reusing 'name' in the for loop. But you really wouldn't code this as class ValueColumn(AbstractColumn): def __init__(SELF, NAME, HEADER, DOMAIN_NAMES): if type(DOMAIN_NAMES) != tuple: raise ValueError('a tuple of domain names must be given') for name in DOMAIN_NAMES: # Argh, at this point 'name' is readonly, but cannot express that. if type(name) != str: raise ValueError('a tuple of domain names must be given') SELF.domain_names = domain_names super(ValueColumn, SELF).__init__(NAME, HEADER) Or, at least I wouldn't do that. It's ugly. And you have to /change the names/ as the readonly-ness changes. Cheers, - Alf From inhahe at gmail.com Mon Nov 30 06:41:06 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 06:41:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <7nhf3eF3lrgr4U1@mid.individual.net> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> Message-ID: one point of confusion could be the use of ** instead of superscript. it might make things a little bit more counterintuitive-looking than with superscripts, since the issue with would only apply to exponents, as -5*4 and a = -5 a*4 return the same answer, and superscripts make it a little easier to associate the exponent value with the base more than with the - before it. On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing wrote: > Esmail wrote: > >> Wow .. never heard of Concatenative_languages languages before or the >> distinction you make. Your distinction explains the behavior, but I >> find it somewhat counter-intuitive. > > You shouldn't find it any more surprising than the fact that > > ?a = 2 + 3 > ?print a * 5 > > gives a different result from > > ?print 2 + 3 * 5 > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Mon Nov 30 07:26:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 07:26:09 -0500 Subject: Completely OT Message-ID: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Hi; I need a recommendation. I want to print out data like this: blue red and enable the user to select the various colors he wants to add to a list that would populate itself on the same page where the selections are, and then, once he's selected all the colors he wants, click to add them all at once to a table in a database, and move on to the next page. I believe this is achieved through JSON and AJAX; however, I haven't been able to google any demonstrations of this sort. Am I correct, or should I use some other sort of technology? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lou at cs.rutgers.edu Mon Nov 30 07:35:06 2009 From: lou at cs.rutgers.edu (Louis Steinberg) Date: Mon, 30 Nov 2009 07:35:06 -0500 Subject: problem with lambda / closures Message-ID: I have run into what seems to be a major bug, but given my short exposure to Python is probably just a feature: running Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin with file foo.py containing: ============================== clip here ============ def p(d): print d l=[ ] for k in [1,2,3]: l.append(lambda : p(k)) for f in l: f() ============================== clip here ============ I get output 3 3 3 instead of 1 2 3 which I would expect. Can anyone explain this or give me a workaround? Thank you From gnarlodious at gmail.com Mon Nov 30 07:36:17 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 05:36:17 -0700 Subject: Can't print Chinese to HTTP Message-ID: Hello. The "upgrade to Python 3.1 has been disaster so far. I can't figure out how to print Chinese to a browser. If my script is: #!/usr/bin/python print("Content-type:text/html\n\n") print('?') the Chinese string simply does not print. It works in interactive Terminal no problem, and also works in Python 2.6 (which my server is still running) in 4 different browsers. What am I doing wrong? BTW searched Google for 2 days no solution, if this doesn't get solved soon I will have to roll back to 2.6. Thanks for any clue. -- Gnarlie http://Gnarlodious.com From martin at v.loewis.de Mon Nov 30 07:53:13 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Mon, 30 Nov 2009 13:53:13 +0100 Subject: Can't print Chinese to HTTP In-Reply-To: References: Message-ID: <4b13c039$0$7478$9b622d9e@news.freenet.de> Gnarlodious wrote: > Hello. The "upgrade to Python 3.1 has been disaster so far. I can't > figure out how to print Chinese to a browser. If my script is: > > #!/usr/bin/python > print("Content-type:text/html\n\n") > print('?') > > the Chinese string simply does not print. It works in interactive > Terminal no problem, and also works in Python 2.6 (which my server is > still running) in 4 different browsers. What am I doing wrong? BTW > searched Google for 2 days no solution, if this doesn't get solved > soon I will have to roll back to 2.6. > > Thanks for any clue. In the CGI case, Python cannot figure out what encoding to use for output, so it raises an exception. This exception should show up in the error log of your web server, please check. One way of working around this problem is to encode the output explicitly: #!/usr/bin/python print("Content-type:text/plain;charset=utf-8\n\n") sys.stdout.buffer.write('?\n'.encode("utf-8")) FWIW, the Content-type in your example is wrong in two ways: what you produce is not HTML, and the charset parameter is missing. Regards, Martin From ebonak at hotmail.com Mon Nov 30 08:00:48 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 08:00:48 -0500 Subject: flattening and rebuilding a simple list of lists Message-ID: Hi, I have a list of lists. The number of sublists may vary. The sizes of the sublists may also vary. For instance, here I have a list with 3 sublists of differing sizes. [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] This list will never be any deeper than this one level. What I would like to do is flatten this list, rearrange the items in the new flattened list and then recreate the list of sublists with the new content. I would like the sublists to have the same size and order (relative to each other) as before. My code below seems to work, but it feels a bit "hack'ish", and I am concerned about efficiency - so I would appreciate suggestions. Again, the number of sublists may vary, and sizes of sublists are not always the same (there will always be at least one sublist). thanks! Esmail Here is my working code so far. ---------------- #!/usr/bin/env python from random import shuffle ################################################################## def flatten_list(parts): """ flatten parts, and return index vals where to split """ line = sum(parts, []) # join all parts into one idx_vals = [] idx = 0 for item in parts: # keep track of lengths/index values idx += len(item) idx_vals.append(idx) return line, idx_vals ################################################################## def rebuilt_lists(line, idx): """ rebuild list of list """ new_list = [line[0:idx[0]]] for i in xrange(len(idx)-1): new_list.append(line[idx[i]:idx[i+1]]) return new_list ################################################################## def main(): indi = [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] print 'indi :', indi # flatten list of list new_indi, idx_vals = flatten_list(indi) print 'new_indi:', new_indi print 'lengths :', idx_vals print # manipulate list print 'shuffling new_indi' shuffle(new_indi) print 'new_indi:', new_indi print # rebuild list of lists new_list = rebuilt_lists(new_indi, idx_vals) print 'new_list:', new_list if __name__ == '__main__': main() From olof.bjarnason at gmail.com Mon Nov 30 08:05:31 2009 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Mon, 30 Nov 2009 14:05:31 +0100 Subject: reading from a text file In-Reply-To: References: Message-ID: 2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. > e.g > in the text file i have these data > > 1.hello > 2.my name > 3.is > 4.World > > Your help is highly appreciated..thnx in advance Hi babourarr; import random with open("c:/test.txt") as f: lines = f.read().splitlines() random_line = lines[random.randrange(len(lines))] print(random_line) > > $LIM $H at DY > > > ________________________________ > Windows Live: Friends get your Flickr, Yelp, and Digg updates when they > e-mail you. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- twitter.com/olofb olofb.wordpress.com olofb.wordpress.com/tag/english From simon at brunningonline.net Mon Nov 30 08:06:56 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 30 Nov 2009 13:06:56 +0000 Subject: reading from a text file In-Reply-To: References: Message-ID: <8c7f10c60911300506h37ccf5fcl960f4821d5486a35@mail.gmail.com> 2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. This might be of use: http://code.activestate.com/recipes/426332/#c2 -- Cheers, Simon B. From neilc at norwich.edu Mon Nov 30 08:11:26 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Nov 2009 13:11:26 GMT Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: <7nhujuF3li0kqU1@mid.individual.net> On 2009-11-27, Diez B. Roggisch wrote: > The only thing that migh be automatized after a piece of code > is valid is normalization, like de-tabifying or making > everything based on 4 space characters indention. No idea if > there is something out there that does that. In vim, you can do something like: :set tabstop=4 :set expandtab :retab -- Neil Cerutti From ebonak at hotmail.com Mon Nov 30 08:34:08 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 08:34:08 -0500 Subject: reading from a text file In-Reply-To: References: Message-ID: baboucarr sanneh wrote: > > i would like to create a python program that would read from a text file > and returns one result at random. #!/usr/bin/env python # assuming the file fits into memory, and you are interested in # random lines from random import randrange f = open('data.txt') data = f.readlines() number = len(data) pick = randrange(0, number) print data[pick] should do the trick. Esmail From __peter__ at web.de Mon Nov 30 08:34:29 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Nov 2009 14:34:29 +0100 Subject: flattening and rebuilding a simple list of lists References: Message-ID: Esmail wrote: > Hi, > > I have a list of lists. The number of sublists may vary. The sizes of > the sublists may also vary. For instance, here I have a list with 3 > sublists of differing sizes. > > [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] > > This list will never be any deeper than this one level. > > What I would like to do is flatten this list, rearrange the items in > the new flattened list and then recreate the list of sublists with the > new content. I would like the sublists to have the same size and order > (relative to each other) as before. > > My code below seems to work, but it feels a bit "hack'ish", and I > am concerned about efficiency - so I would appreciate suggestions. I don't think it's hackish, but here's an alternative: >>> items = [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] >>> flat = sum(items, []) >>> flat.reverse() >>> from itertools import imap, islice >>> flat = iter(flat) >>> [list(islice(flat, size)) for size in imap(len, items)] [['i', 'h', 'g'], ['f', 'e'], ['d', 'c', 'b', 'a']] Peter From lacrima.maxim at gmail.com Mon Nov 30 08:46:11 2009 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 30 Nov 2009 05:46:11 -0800 (PST) Subject: TDD with nose or py.test Message-ID: <2519ffb0-fd49-4340-857b-62fca5c71421@33g2000vbe.googlegroups.com> Hello! I am learning TDD with Python and there is not much information about this topic. Python is shipped with unittest module. That is fine, but I also discovered other libraries: nose and py.test. They promise to make life yet easier for a developer. But I still can't figure out, which combination I should use them in. Nose seems simpler than py.test, but py.test offers more features. And both py.test and nose say that they do not replace unittest module, but extend it. So as I understand my choice should be nose + unittest, or py.test + unittest. And now I'd like to hear about best practices in TDD in Python. Maybe not best practices, but basic approach. So which tests should I write with unittest, which with nose or py.test? How should I combine them? I am learning Python and I need your advice. Thanks in advance. Sorry if my English isn't very proper From marco at sferacarta.com Mon Nov 30 09:01:51 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 30 Nov 2009 15:01:51 +0100 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short > exposure to Python is probably just a feature: Yes, it works as advertised :-/ > which I would expect. Can anyone explain this or give me a workaround? like this? > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda k=k: p(k)) > > for f in l: > f() From duncan.booth at invalid.invalid Mon Nov 30 09:04:16 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2009 14:04:16 GMT Subject: problem with lambda / closures References: Message-ID: Louis Steinberg wrote: >============================== clip here ============ > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda : p(k)) > > for f in l: > f() > >============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. Can anyone explain this or give me a > workaround? Thank you > There's nothing magic about lambda. The same holds true for any function definition. When you have a function that accesses a variable declared at an outer or global scope it always use the value of the variable at the time when it is accessed, not the value when it was defined. Your for loop is exactly equivalent to: def foo(): return p(k) l = [ foo, foo, foo ] k = 3 where it should be more obvious that you will always get the same result. Try this instead: from functools import partial l = [ partial(p, k) for k in [1, 2, 3]] -- Duncan Booth http://kupuguy.blogspot.com From neilc at norwich.edu Mon Nov 30 09:06:50 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Nov 2009 14:06:50 GMT Subject: flattening and rebuilding a simple list of lists References: Message-ID: <7ni1rqF3m40htU1@mid.individual.net> On 2009-11-30, Esmail wrote: > I have a list of lists. The number of sublists may vary. The > sizes of the sublists may also vary. For instance, here I have > a list with 3 sublists of differing sizes. > > [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] > > This list will never be any deeper than this one level. > > What I would like to do is flatten this list, rearrange the > items in the new flattened list and then recreate the list of > sublists with the new content. I would like the sublists to > have the same size and order (relative to each other) as > before. Depending on your usage pattern, directly mutating the original through a simple "view" might be a viable alternative: def set_flattened(lst, i, val): j = 0 while i >= len(lst[j]): i -= len(lst[j]) j += 1 lst[j][i] = val def get_flattened(lst, i): j = 0 while i >= len(lst[j]): i -= len(lst[j]) j += 1 return lst[j][i] A "view" should be easier to use and debug than your current flatten, mutate and unflatten approach. The above functions obviously make the maximum number of assumptions about your data structures, and currently don't work sensibly with negative indices. -- Neil Cerutti From vinay_sajip at yahoo.co.uk Mon Nov 30 09:10:41 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 30 Nov 2009 06:10:41 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> <0eaf51df-ed54-4f63-9514-76077a378ee6@v30g2000yqm.googlegroups.com> Message-ID: <6704aaa3-b3d1-4da7-a486-06833cbb0509@p33g2000vbn.googlegroups.com> On Nov 30, 6:52?am, Grimsqueaker wrote: > > So would I be correct in saying that Filters apply only the the object > they are attached to and have no effect on how messages are propagated > through thelogginghierarchy? If this is the case my next question > would be: How can I affect whether or not a message is propagated > further up the tree? > You are correct about how Filters work. To prevent propagation, use the propagate attribute, documented here: http://docs.python.org/library/logging.html#logger-objects Most times, you don't need to use this. For example, if you want events in the A hierarchy to go to one place and events in the B hierarchy to go to another place (e.g. two different log files), you just attach different handlers (e.g. two different FileHandlers) to loggers A and B. If you want a combined log as well, add an appropriate handler to the root logger. I find that things usually work OK if I just determine what handlers I need and attach them to the appropriate loggers, setting the levels on handlers and loggers appropriately. If I need filtering logic for a logger or handler which is more involved than just an integer threshold (which happens less often), I use Filters. Even less often, if I need to block events from a part of the logger hierarchy from bubbling upwards, then I use the propagate attribute. Regards, Vinay Sajip From jonas at geiregat.org Mon Nov 30 09:34:09 2009 From: jonas at geiregat.org (Jonas Geiregat) Date: Mon, 30 Nov 2009 15:34:09 +0100 Subject: Possibly something wrong with mailman ? Message-ID: I'm getting lot's of messages to: undisclosed-recipients:; Which horribly scrambles my email, since no filters are applied to them. From exarkun at twistedmatrix.com Mon Nov 30 09:36:38 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 30 Nov 2009 14:36:38 -0000 Subject: Imitating "tail -f" In-Reply-To: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> References: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> Message-ID: <20091130143638.2549.1083615942.divmod.xquotient.42@localhost.localdomain> On 11:15 am, paul at boddie.org.uk wrote: >On 22 Nov, 05:10, exar... at twistedmatrix.com wrote: >> >>"tail -f" is implemented by sleeping a little bit and then reading to >>see if there's anything new. > >This was the apparent assertion behind the "99 Bottles" concurrency >example: > >http://wiki.python.org/moin/Concurrency/99Bottles > >However, as I pointed out (and as others have pointed out here), a >realistic emulation of "tail -f" would actually involve handling >events from operating system mechanisms. Here's the exchange I had at >the time: > >http://wiki.python.org/moin/Concurrency/99Bottles?action=diff&rev2=12&rev1=11 > >It can be very tricky to think up good examples of multiprocessing >(which is what the above page was presumably intended to investigate), >as opposed to concurrency (which can quite easily encompass responding >to events asynchronously in a single process). > >Paul > >P.S. What's Twisted's story on multiprocessing support? In my limited >experience, the bulk of the work in providing usable multiprocessing >solutions is in the communications handling, which is something >Twisted should do very well. Twisted includes a primitive API for launching and controlling child processes, reactor.spawnProcess. It also has several higher-level APIs built on top of this aimed at making certain common tasks more convenient. There is also a third-party project called Ampoule which provides a process pool to which it is is relatively straightforward to send jobs and then collect their results. Jean-Paul From x7-g5W_rt at earthlink.net Mon Nov 30 09:37:19 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Mon, 30 Nov 2009 06:37:19 -0800 (PST) Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: On Nov 27, 9:58?am, "Diez B. Roggisch" wrote: [...] > > so i would like to have a tool to intelligently format the code for me > > and make the code more beautiful > > and automated. > > This is not possible. Consider the following situation: > [...] > Both are semantically radically different, and only you know which one > is the right one. > Diez I have to agree with Diez, there is no way to automate this. Some human intervention is needed. What I would like is an editor that will indicate what Python will consider a logical block (and sub-block, and sub-sub-block, etc.) It's complicated. I've tried to think of a way to do it, and have gotten lost after a few changes of indentation. Does anyone know of such a thing? I miss curly braces with an editor that will highlight matching parentheses, braces, etc. Gil From steve at REMOVE-THIS-cybersource.com.au Mon Nov 30 09:50:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Nov 2009 14:50:39 GMT Subject: * for generic unpacking and not just for arguments? References: Message-ID: <009d603c$0$26893$c3e8da3@news.astraweb.com> On Sun, 29 Nov 2009 13:45:18 -0600, Tim Chase wrote: >> The feature is available in Python 3.x: >> >>>>> a, b, *c = 1, 2, 3, 4, 5 >>>>> a, b, c >> (1, 2, [3, 4, 5]) >>>>> a, *b, c = 1, 2, 3, 4, 5 >>>>> a, b, c >> (1, [2, 3, 4], 5) > > This is a nice feature of 3.x but I'm disappointed (especially in light > of the move to make more things iterators/generators), that the first > form unpacks and returns a list instead returning the unexhausted > generator. So you want *x behave radically different in subtly different contexts? a, *x, b = iterator would give x a list and iterator run to exhaustion, whereas: a, b, *x = iterator would give x identical to iterator, which hasn't run to exhaustion, while both of these: a, *x, b = sequence a, b, *x = sequence would give x a list, but in the second case, unlike the case of iterators, x would not be identical to sequence. No thank you, I'd prefer a nice, consistent behaviour than a magical "Do what I mean" function. However, having some syntax giving the behaviour you want would be nice. Something like this perhaps? a, b, c = *iterable equivalent to: _t = iter(iterable) a = next(_t) b = next(_t) c = next(_t) # and so on for each of the left-hand names del _t That would be useful. -- Steven From lou at cs.rutgers.edu Mon Nov 30 10:09:07 2009 From: lou at cs.rutgers.edu (Louis Steinberg) Date: Mon, 30 Nov 2009 10:09:07 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: <50DAFD40-92BD-4A55-AE39-09E05220F27C@cs.rutgers.edu> I figured out the answer to my own query. In the original example (see below), there was only one binding for k, which was shared by all the closures, so they all saw the same value. Consider: def fie2(k): return lambda: fie3(k) def fie3(m): print m def fie1(j): return fie2(j) l=map(fie1,[1,2,3]) map(lambda f:f(), l) This prints 1 2 3 because each lambda has its own binding of k. On Nov 30, 2009, at 7:35 AM, Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short > exposure to Python is probably just a feature: > > running > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > with file foo.py containing: > > ============================== clip here ============ > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda : p(k)) > > for f in l: > f() > > ============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. Can anyone explain this or give me a > workaround? Thank you > > > > From gh at ghaering.de Mon Nov 30 10:13:16 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 30 Nov 2009 16:13:16 +0100 Subject: dbapi2 select where IN (...) In-Reply-To: References: Message-ID: yota.news at gmail.com wrote: > hello, > > I couldn't find how the dbapi2 planned to handle the sql IN statement. > > ex : > SELECT * FROM table WHERE num IN (2,3,8,9); > > I'd be glad to take advantage of the ? mechanism, but what about > tuples ! > > execute("""SELECT * FROM table WHERE num IN ?;""" , > ((2,3,8,9),)) ...fail... [...] You cannot use parameter binding when the number of parameters is unknown in advance. So you'll have to create this part of the SQL query differently. For example: ids = [2, 3, 8, 9] in_clause = " (" + ",".join([str(id) for id in ids]) + ")" query = "select * from table where num in" + in_clause -- Gerhard From jeanmichel at sequans.com Mon Nov 30 10:22:27 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 30 Nov 2009 16:22:27 +0100 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4B13E333.6090300@sequans.com> Victor Subervi wrote: > > if which == '': > i = 0 > all = '' > while i < len(meanings): > table = '%s\n' % meanings[i] > table += "\n \n \n " % names[i] > j = 0 > for elt in code: > if (j + 8) % 8 == 0: > table += ' \n' > table += ' \n' % code[i] > if (j + 8) % 8 == 0: > table += ' \n' > j += 1 > if table[-6:] != '\n': > table += ' \n' > table += '
    align='center'>%s
    %s
    \n' > all += table + '

    ' > i += 1 > print all > > This all works fine; however, if there is a better way of doing it, > please let me know. > Thanks, > V > I wonder which is worse, looking at your python code, or being blind :o) You should have a look at http://tottinge.blogsome.com/meaningfulnames/ Cheers, Jean-Michel From mail at timgolden.me.uk Mon Nov 30 10:41:38 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Nov 2009 15:41:38 +0000 Subject: reading from a text file In-Reply-To: References: Message-ID: <4B13E7B2.5030405@timgolden.me.uk> Olof Bjarnason wrote: > 2009/11/27 baboucarr sanneh : >> hi all >> >> i would like to create a python program that would read from a text file and >> returns one result at random. >> e.g >> in the text file i have these data >> >> 1.hello >> 2.my name >> 3.is >> 4.World >> >> Your help is highly appreciated..thnx in advance > > Hi babourarr; > > import random > with open("c:/test.txt") as f: > lines = f.read().splitlines() > random_line = lines[random.randrange(len(lines))] > print(random_line) Or, slightly more simply: import random with open ("c:/test.txt") as f: print random.choice (list (f)) You need the list () because random.choice only works on a finite iterable. TJG From duncan.booth at invalid.invalid Mon Nov 30 10:46:02 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2009 15:46:02 GMT Subject: dbapi2 select where IN (...) References: Message-ID: Gerhard H?ring wrote: >> execute("""SELECT * FROM table WHERE num IN ?;""" , >> ((2,3,8,9),)) ...fail... [...] > > You cannot use parameter binding when the number of parameters is > unknown in advance. So you'll have to create this part of the SQL query > differently. > > For example: > > ids = [2, 3, 8, 9] > in_clause = " (" + ",".join([str(id) for id in ids]) + ")" > query = "select * from table where num in" + in_clause > You can use parameter bindings when you don't know the number of parameters in advance. Just don't create the query string until you do know the number of parameters: ids = [2, 3, 8, 9] query = "select * from table where num in (%s)" % ','.join('?'*len(ids)) execute(query, ids) -- Duncan Booth http://kupuguy.blogspot.com From benjamin.kaplan at case.edu Mon Nov 30 10:54:47 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 Nov 2009 10:54:47 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: On Monday, November 30, 2009, Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short exposure to Python is probably just a feature: > > running > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > with file foo.py containing: > > ============================== clip here ============ > def p(d): > ? ?print d > > > l=[ ] > for k in [1,2,3]: > ? ?l.append(lambda : p(k)) > > for f in l: > ? ?f() > > ============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. ?Can anyone explain this or give me a workaround? ?Thank you > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I don't know if anyone considers python's incomplete implementation of closures a "feature" but it's documented so it's not really a bug either. I believe there is a trick with default arguments to get this to work, but I don't use lambdas enough to remember it. From koranthala at gmail.com Mon Nov 30 10:58:50 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 30 Nov 2009 07:58:50 -0800 (PST) Subject: pywintypes error Message-ID: <90c71adb-a774-4a3e-bb49-423014af4b1b@b36g2000prf.googlegroups.com> Hi, When I try to use Django with Apache and mod_python, I am facing an issue. Since this is a very usual configuration, I hope this issue is already solved. My web sites fail with the following error : "C:\\Python24\\Lib\\site-packages\\win32\\lib\\pywintypes.py", line 124, in?\n __import_pywin32_system_module__("pywintypes", globals()) [Mon Nov 30 15:13:50 2009] [error] [client 127.0.0.1] File"C:\ \Python24\\Lib\\site-packages\\win32\\lib\\pywintypes.py", line 114, in__import_pywin32_system_module__\n assert sys.modules[modname] isold_mod [Mon Nov 30 15:13:50 2009] [error] [client 127.0.0.1] AssertionError I checked the code in pywintypes and it is a sure assertion error: old_mod = sys.modules[modname] # Python can load the module mod = imp.load_dynamic(modname, found) # Check the sys.modules[] behaviour we describe above is true... if sys.version_info < (3,0): assert sys.modules[modname] is old_mod assert mod is old_mod else: assert sys.modules[modname] is not old_mod assert sys.modules[modname] is mod # as above - re-reset to the *old* module object then update globs. sys.modules[modname] = old_mod globs.update(mod.__dict__) I have python 2.4 so, it goes to the first check and fails. Has anyone else faced this issue? How to solve the same? From putumutukas at gmail.com Mon Nov 30 11:03:43 2009 From: putumutukas at gmail.com (a b) Date: Mon, 30 Nov 2009 08:03:43 -0800 (PST) Subject: PySerial and termios Message-ID: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> I have a pain in the a** problem with pyserial- it works 90% of time but on the 10% of time it thorows and termios.error exception with the value (5, 'Input/output error') and i cannot get rid of it :( The system works as follows: A device sends out rs485 data -> rs485 to rs232 converter converts it - > an rs232->usb cable attatched to a computer reads the data. Until now it hasn't bothered me too much since it hasn't been a lot of data (every time i get this exception i unload the pl2303 module from kernel, then reload it, open the com port and hope it won't happen soon). But now the amount of data is getting bigger and the exceptions in the log are quite bothering already so if anyone has a good idea what could affect it i'd be very glad... oh and the settings for the port opening are: self.ser = serial.Serial(self.port, self.baudrate, rtscts=0, xonxoff=0, timeout=0) With best regards, Tanel From deets at nospam.web.de Mon Nov 30 11:15:22 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 30 Nov 2009 17:15:22 +0100 Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: <7ni9cqF3lb4goU1@mid.uni-berlin.de> a b wrote: > I have a pain in the a** problem with pyserial- it works 90% of time > but on the 10% of time it thorows and termios.error exception with the > value (5, 'Input/output error') and i cannot get rid of it :( > The system works as follows: > A device sends out rs485 data -> rs485 to rs232 converter converts it - >> an rs232->usb cable attatched to a computer reads the data. Until > now it hasn't bothered me too much since it hasn't been a lot of data > (every time i get this exception i unload the pl2303 module from > kernel, then reload it, open the com port and hope it won't happen > soon). But now the amount of data is getting bigger and the exceptions > in the log are quite bothering already so if anyone has a good idea > what could affect it i'd be very glad... > oh and the settings for the port opening are: > self.ser = serial.Serial(self.port, self.baudrate, rtscts=0, > xonxoff=0, timeout=0) Did you try a different usb2serial-converter? I've got plenty of them used in the past few years, and frankly, they mostly suck. Big time. With them, all kinds of timing-issues and other problems arose, and some hardware refused to outright work with them. So, I suggest you try & get a hold on as many usb2serial-converters you can get from friends and colleagues, and try out which one works best. There is nothing on the software-side you can do (short from lowering the bps, as this might cover up for some issues due to relaxed timing. But I had to cut down to like 2400 bps or some crap like that, which isn't really usable) Diez From ronn.ross at gmail.com Mon Nov 30 11:20:29 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Mon, 30 Nov 2009 11:20:29 -0500 Subject: New to python Message-ID: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> I have recently come across something called a struct. I have googled this, but have note found a good explanation. Can someone give me a good definition or point me to a page that has one. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco at sferacarta.com Mon Nov 30 11:23:03 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 30 Nov 2009 17:23:03 +0100 Subject: Exec Statement Question In-Reply-To: References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: Jean-Michel Pichavant wrote: >> if which == '': >> i = 0 >> all = '' >> while i < len(meanings): >> table = '%s\n' % meanings[i] >> table += "\n \n \n': should use endswith(), and you won't run the risk of counting wrong if your literal changes. if (j + 8) % 8 == 0: could be simpler: if j % 8 == 0: The pattern: j=0 for elt in code: should be replaced by: for j, elt in enumerate(code): (and of course don't forget to then remove the j+=1 ) You're using the indexing variable i when it'd make much more sense to use zip. Or perhaps meanings and code should be a single list, with each item being a tuple. That's what zip builds, after the fact. But if you build it explicitly, you're less likely to accidentally have an extra or missing element in one of them, and have to deal with that bug. The zip approach might look something like: for meaning, code_element in zip(meanings, code): and then whenever you're using meanings[i] you use meaning, and whenever you're using code[i], you use code_element. (Obviously name changes would help, since code is a list, but the name isn't plural) More generally, when I see code with that much data embedded in it, it cries out for templates. They're known by many different names, but the idea is to write your data structures somewhere else, and manipulate them with the code, instead of embedding it all together. I suspect that each of these functions looks very similar, and they each have their own set of bugs and glitches. That's a good indicator that you need to separate the data. For my web work, I've written my own, very simple templating logic that's only as good as I needed. So I can't comment on the various ones that are already available. But the idea is you put data into one or more text files, which you systematically manipulate to produce your end result. A particular text file might be comma delimited, or defined in sections like an .ini file, or both, or some other mechanism, such as xml. But make it easy to parse, so you can concentrate on getting the data into its final form, consistently, and with common code for all your tables, parameterized by the stuff in the data files. DaveA From inhahe at gmail.com Mon Nov 30 12:14:04 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:14:04 -0500 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: to put it simplistically it's a way of combining multiple variables into one for example, for a person you could have person.haircolor person.echnicity person.age etc. but you can then also manipulate 'person' as a whole like you would any other variable, such as x[n] = person a struct, as far as i know, is like a class but with no methods. or a class is like a struct but with methods that act on the struct's data. i don't think structs technically exist in Python (though they exist in C/C++), but you could always use a plain class like a struct, like this, for a simple example: class Blah: pass b = blah() b.eyecolor = "brown" b.haircolor = "blond" b.ethnicity = "caucasion" On Mon, Nov 30, 2009 at 11:20 AM, Ronn Ross wrote: > I have recently come across something called a struct. I have googled this, > but have note found a good explanation. Can someone give me a good > definition or point me to a page that has one. > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > From rami.chowdhury at gmail.com Mon Nov 30 12:15:34 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 30 Nov 2009 09:15:34 -0800 Subject: Completely OT In-Reply-To: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> On Mon, Nov 30, 2009 at 04:26, Victor Subervi wrote: > Hi; > I need a recommendation. I want to print out data like this: > > > > > and enable the user to select the various colors he wants to add to a list > that would populate itself on the same page where the selections are, and > then, once he's selected all the colors he wants, click to add them all at > once to a table in a database, and move on to the next page. I believe this > is achieved through JSON and AJAX; however, I haven't been able to google > any demonstrations of this sort. Am I correct, or should I use some other > sort of technology? > TIA, > Victor There are a huge number of different ways to do this, including all on the server-side, all on the client side, and a mixture of both as you suggested. What kind of behavior are you actually looking for? From rami.chowdhury at gmail.com Mon Nov 30 12:21:15 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 30 Nov 2009 09:21:15 -0800 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <2f79f590911300921w36b32539n9f552fc7f352b0ae@mail.gmail.com> On Mon, Nov 30, 2009 at 08:20, Ronn Ross wrote: > I have recently come across something called a struct. I have googled this, > but have note found a good explanation. Can someone give me a good > definition or point me to a page that has one. > Where did you come across a "struct"? Depending on context it can be used to refer to a number of different things -- I assume you are looking for either the struct module in the Python standard library (http://docs.python.org/library/struct.html) or trying to implement something like a C "struct" in Python (http://stackoverflow.com/questions/35988/c-like-structures-in-python)? From inhahe at gmail.com Mon Nov 30 12:21:58 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:21:58 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: On Mon, Nov 30, 2009 at 10:54 AM, Benjamin Kaplan wrote: > > I don't know if anyone considers python's incomplete implementation of > closures a "feature" but it's documented so it's not really a bug > either. I believe there is a trick with default arguments to get this > to work, but I don't use lambdas enough to remember it. > -- > http://mail.python.org/mailman/listinfo/python-list > Well default arguments isn't the only way - and *sometimes* it's not workable. Another way to make closures in Python is to define the function a within function b which returns function a and in your loop call function b. i guess if you wanted to do that purely with lambas (outside of using default arguments like i=i) you'd have to do something like a = [] for x in xrange(10): a.append((lambda x: lambda: x)(x)) never tried that though.. From manuel.graune at koeln.de Mon Nov 30 12:22:17 2009 From: manuel.graune at koeln.de (Manuel Graune) Date: Mon, 30 Nov 2009 18:22:17 +0100 Subject: Questions about list-creation Message-ID: Hello, in (most) python documentation the syntax "list()" and "[]" is treated as being more or less the same thing. For example "help([])" and "help(list())" point to the same documentation. Since there are at least two cases where this similarity is not the case, (see below) can someone explain the reasoning behind this and point to further / relevant documentation? (To clarify: I am not complaining about this, just asking.) 1.) when using local variables in list comprehensions, say a=[i for i in xrange(10)] the local variable is not destroyed afterwards: print "a",a print "i",i using the similar code b=list(j for j in xrange(10)) the local variable is destroyed after use: print "b",b print "j",j and 2) a=list([]) vs. b=[[]] Regards, Manuel Graune -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From victorsubervi at gmail.com Mon Nov 30 12:26:40 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:26:40 -0400 Subject: Exec Statement Question In-Reply-To: References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4dc0cfea0911300926w1b42e344wc4657b33be50d998@mail.gmail.com> On Mon, Nov 30, 2009 at 12:25 PM, Carsten Haese wrote: > Victor Subervi wrote: > > Taking out the parenthesis did it! Thanks. Now, you state this is an > > option of last resort. Although this does indeed achieve my desired aim, > > here is a complete example of what I am trying to achieve. The following > > is from 'createTables2.py': > > > > for table in tables: > > try: > > exec 'from options import %s' % table > > except: > > pass > > try: > > exec '%s()' % table > > except: > > pass > > Here's a rough sketch of rewriting that snippet in a way that uses > attribute lookup instead of dynamic code execution: > > #---------------------------------------# > import options > for table in tables: > tablefunc = getattr(options, table) > tablefunc() > #---------------------------------------# > > The main ideas behind this approach are: > > 1) Rather than importing the functions from the options module piecemeal > into the local namespace, I just import the entire options module as its > own separate namespace. > > 2) I use getattr on that separate namespace to look up the desired > function object from the options module. I assign the local name > <> to the resulting function object. > > 3) I call that function using the local name <>. > > Thanks. This is good. Thanks Jean-Michelle for the suggestion on better naming. Thanks Marco for the lxml builder, but I'm happy with just plain old html. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 30 12:27:41 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:27:41 -0400 Subject: Completely OT In-Reply-To: <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> Message-ID: <4dc0cfea0911300927i697e8793t75b3dc6e69a7a6c9@mail.gmail.com> On Mon, Nov 30, 2009 at 1:15 PM, Rami Chowdhury wrote: > On Mon, Nov 30, 2009 at 04:26, Victor Subervi > wrote: > > Hi; > > I need a recommendation. I want to print out data like this: > > > > > > > > > > and enable the user to select the various colors he wants to add to a > list > > that would populate itself on the same page where the selections are, and > > then, once he's selected all the colors he wants, click to add them all > at > > once to a table in a database, and move on to the next page. I believe > this > > is achieved through JSON and AJAX; however, I haven't been able to google > > any demonstrations of this sort. Am I correct, or should I use some other > > sort of technology? > > TIA, > > Victor > > There are a huge number of different ways to do this, including all on > the server-side, all on the client side, and a mixture of both as you > suggested. What kind of behavior are you actually looking for? > Definitely client-side. I just want to enable the client to select all the fields he wants to include, then update to the server once. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From garrickp at gmail.com Mon Nov 30 12:30:30 2009 From: garrickp at gmail.com (Falcolas) Date: Mon, 30 Nov 2009 09:30:30 -0800 (PST) Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: On Nov 30, 7:37?am, gil_johnson wrote: > On Nov 27, 9:58?am, "Diez B. Roggisch" wrote: > [...] > > > > so i would like to have a tool to intelligently format the code for me > > > and make the code more beautiful > > > and automated. > > > This is not possible. Consider the following situation: > > [...] > > Both are semantically radically different, and only you know which one > > is the right one. > > Diez > > I have to agree with Diez, there is no way to automate this. Some > human intervention is needed. What I would like is an editor that will > indicate what Python will consider a logical block (and sub-block, and > sub-sub-block, etc.) > It's complicated. I've tried to think of a way to do it, and have > gotten lost after a few changes of indentation. > Does anyone know of such a thing? > I miss curly braces with an editor that will highlight matching > parentheses, braces, etc. > Gil At least with Windows, you get a number of scripts included in your Python install - under the python directory/tools/scripts. There are several scripts here which are intended to help with indentation issues - such as reindent and pindent. Those might help you out some. Nonetheless, it would be better to implement coding standards that everyone can stick to. From victorsubervi at gmail.com Mon Nov 30 12:30:31 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:30:31 -0400 Subject: Exec Statement Question In-Reply-To: <4B13FD11.1000808@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> <4B13FD11.1000808@ieee.org> Message-ID: <4dc0cfea0911300930l6ae653dfwcbf5a4a52fd2d432@mail.gmail.com> On Mon, Nov 30, 2009 at 1:12 PM, Dave Angel wrote: > Victor Subervi wrote: > >> On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: >> >> >> >>> exec is a statement, and statements don't have "return values." It's >>> not >>> a function, so there are no parentheses in its syntax, either. exec is >>> also >>> a technique of last resort; there's nearly always a better/safer/faster >>> way >>> to accomplish what you might want, but of course you don't say what that >>> is. >>> >>> As for "returning" values, exec by default uses the same global space as >>> your app, so you can just modify a global variable in your "called" code >>> and >>> use it afterwards. >>> >>> abc = 42 >>> value = 12 >>> exec "abc = %d" % value >>> print abc >>> >>> >>> >> >> Taking out the parenthesis did it! Thanks. Now, you state this is an >> option >> of last resort. Although this does indeed achieve my desired aim, here is >> a >> complete example of what I am trying to achieve. The following is from >> 'createTables2.py': >> >> for table in tables: >> try: >> exec 'from options import %s' % table >> except: >> pass >> try: >> exec '%s()' % table >> except: >> pass >> >> >> The following is from 'options.py': >> >> def jewelry(which=''): >> code = [] >> names = [] >> meanings = [] >> code.append(['5', '5½', '6', '6½', '7', '7½', '8', >> '8½', '9', '9½', '10', '10½', '11', '11½', >> '12', >> '12½', '13', '13½']) >> meanings.append('The standard ring sizes.') >> names.append('ringSizes') >> code.append(['Petite (7")', 'Average (7½")', 'Large >> (8")', 'Extra-large (8½")']) >> meanings.append('The standard bracelet sizes.') >> names.append('braceletSizes') >> code.append(['16"', '18"', '20"', '22"', '24"']) >> meanings.append('The standard necklace sizes.') >> names.append('necklaceSizes') >> code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K >> white gold', 'platinum', 'tungsten', 'titanium']) >> meanings.append('The standard jewelry metals.') >> names.append('metals') >> code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', >> 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose >> quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', >> 'turquoise']) >> meanings.append('The standard jewelry stones.') >> names.append('stones') >> if which == '': >> i = 0 >> all = '' >> while i < len(meanings): >> table = '%s\n' % meanings[i] >> table += "
    You should have a look at http://tottinge.blogsome.com/meaningfulnames/ I would also suggest to have a look at lxml.builder, or some kind of template system. From carsten.haese at gmail.com Mon Nov 30 11:25:29 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 30 Nov 2009 11:25:29 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: Victor Subervi wrote: > Taking out the parenthesis did it! Thanks. Now, you state this is an > option of last resort. Although this does indeed achieve my desired aim, > here is a complete example of what I am trying to achieve. The following > is from 'createTables2.py': > > for table in tables: > try: > exec 'from options import %s' % table > except: > pass > try: > exec '%s()' % table > except: > pass Here's a rough sketch of rewriting that snippet in a way that uses attribute lookup instead of dynamic code execution: #---------------------------------------# import options for table in tables: tablefunc = getattr(options, table) tablefunc() #---------------------------------------# The main ideas behind this approach are: 1) Rather than importing the functions from the options module piecemeal into the local namespace, I just import the entire options module as its own separate namespace. 2) I use getattr on that separate namespace to look up the desired function object from the options module. I assign the local name <> to the resulting function object. 3) I call that function using the local name <>. HTH, -- Carsten Haese http://informixdb.sourceforge.net From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 30 11:35:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 30 Nov 2009 17:35:24 +0100 Subject: Feature request: String-inferred names In-Reply-To: <4b10e8b3@dnews.tpgi.com.au> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <4b13f44c$0$7868$426a34cc@news.free.fr> Lie Ryan a ?crit : > On 11/28/2009 3:08 PM, The Music Guy wrote: (snip the part about the proposed feature - which I don't like but that's not the point) >> My >> projects rely on a lot of metaclassing for the automatic generation of >> properties and methods, which saves tremendous amounts of coding. > > If you use it a lot, it is likely 1) you have abused class syntax for > what should have been a dict or 2) what you need is to override > __getattr__/__getattribute__ and __setattr__ I have to totally disagree here. The way the OP uses metaprogramming is a really common and handy solution in lots of frameworks, and drastically reduces the need for boilerplate (and the potential for bugs). It's *WAY* cleaner (readability, introspection, doc etc) and far less error-prone than going the __getattr(ibute)__ / __setattr__, and also way more efficient (from execution time POV). Using __getattr__ and __setattr__ to emulate attributes (usually descriptors) that can be built at class creation time is IMHO what should be labeled as an "abuse" (at best). From gregor.lingl at aon.at Mon Nov 30 11:36:14 2009 From: gregor.lingl at aon.at (Gregor Lingl) Date: Mon, 30 Nov 2009 17:36:14 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: <4B13F47E.3080706@aon.at> Hello Brian, I think the most natural use of the if statement (using turtle graphics) occurs in recursive functions drawing trees, fractals and the like. This is well known from Logo, where recursion is the canonical way of doing repetitions. (But note, that Logo has tail recursion optimizaton!) If you are not yet ready to use recursion with your students, probably many of the problems coming to your mind that need the examination of conditions can be solved better by using a conditional loop (i. e. a while -loop in Python) than by using mere if statements. That is not the case however, if you have to perform actions in the body of a loop, that depend on the current situation. I did a quick search in my repository of examples and found a fairly short and simple script that demonstrates, what I mean: a drunken turtle collecting coins (or whatever) on its random walk. ##### Python script using turtle graphics from turtle import Screen, Turtle from random import randint s = Screen() s.setup(560,560) s.title("A drunken turtle collecting ...") s.tracer(False) writer = Turtle(visible=False) writer.penup() writer.goto(0, -275) coins = [] for i in range(-4,5): for j in range(-4, 5): if i == j == 0: continue c = Turtle(shape="circle") c.color("", "orange") c.shapesize(0.5) c.goto(40*i, 40*j) coins.append(c) s.tracer(True) DRUNKENNESS = 45 t = Turtle(shape="turtle") t.color("black","") points = 0 while abs(t.xcor()) < 200 and abs(t.ycor()) < 200: t.forward(5) t.right(randint(-DRUNKENNESS, DRUNKENNESS)) found = None for c in coins: if t.distance(c) < 10: found = c break if found: found.hideturtle() coins.remove(found) t.shapesize(1+points/5., outline=1+points) points += 1 writer.write("{0} points".format(points), align="center", font=('Arial', 24, 'bold')) ############## End of script You can see a screenshot of a run of this script here: http://www.dropbox.com/gallery/2016850/1/TurtleCollector?h=6b370a The script could be expanded in several ways, e. g. for doing statistical investigations or examinig how the result depends on different parameters like drunkenness etc. Or you distribute the coins randomly ... Does that alter the average "harvest"? Just a suggestion ... Regards, Gregor Brian Blais schrieb: > Hello, > > I was just playing with the turtle module, and thought it was an > interesting way to augment the introduction to python (I teach college > students, who haven't had any programming). It's a great way to > introduce functions, for-loops, and general program structures. > > After a bit of playing, I realized that I couldn't think of many > examples which use turtle with conditional structures (if- and while- > statements), or functions that return values, as opposed to > "procedures" like: > > def square(length): > forward(length) > right(90) > forward(length) > right(90) > forward(length) > right(90) > forward(length) > right(90) > > > If-statements could possibly be used with some sort of random behavior > (if rand()<0.5 ...). Are there any other situations, using turtle, > that these structures would be natural? > > > > thanks, > > Brian Blais > > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > From koranthala at gmail.com Mon Nov 30 11:56:13 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 30 Nov 2009 08:56:13 -0800 (PST) Subject: Python py2exe - memory load error References: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> Message-ID: <86b33eb1-6d53-43c1-bce3-9773f416d99a@g4g2000pri.googlegroups.com> On Nov 30, 10:10?am, koranthala wrote: > This is cross post from stackoverflow - I couldnt get the solution > there. Hopefully, nobody would mind. > > I am creating a medium level application in Python. Everything works > well now, and I am trying to make this a windows executable with > py2exe. The executable is created fine, but when I try to run it, it > fails with the following error. > > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\__init__.pyc", line 1, in ? > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\AA.pyc", line 8, in ? > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\pyAAc.pyc", line 5, in ? > ? File "zipextimporter.pyc", line 98, in load_module > ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd > > I am using pyAA in this application. I searched internet, but was > unable to get any solution. I copied msvcp71.dll to windows/system32, > but still issue is there. > > I had solved it earlier (around 7 months back), but my hard drive > crashed and when I try to recreate it, I cannot seem to solve it > now. :-( > > I would be much obliged if someone could help me out here. > > When I use py2exe without bundle files option, it is working > perfectly. But when I use bundle file option, it is failing. > > I tried without zipfile option, wherein it creates a library.zip > alongwith the executable. Again it failed. I did unzip of library.zip > using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside > the zip file. So, it looks like some issue with memoryloadlibrary > function. > > >dir > > 11/30/2009 ?09:48 AM ? ? ? ? ? ?25,172 AA.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 3,351 Defer.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 2,311 Path.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ?11,216 pyAAc.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 5,920 Watcher.pyc > 08/20/2005 ?02:00 PM ? ? ? ? ? ?49,152 _pyAAc.pyd > 11/30/2009 ?09:48 AM ? ? ? ? ? ? ? 162 __init__.pyc > > From the trace it does look like it can extract AA.pyc etc. I am using > windows7 - can it be some clue? Can anyone provide some clues on how to solve this issue? I would be much obliged if you could do the same. From python.list at tim.thechases.com Mon Nov 30 11:58:48 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Nov 2009 10:58:48 -0600 Subject: * for generic unpacking and not just for arguments? In-Reply-To: <009d603c$0$26893$c3e8da3@news.astraweb.com> References: <009d603c$0$26893$c3e8da3@news.astraweb.com> Message-ID: <4B13F9C8.3030203@tim.thechases.com> > So you want *x behave radically different in subtly different contexts? > > a, *x, b = iterator > > would give x a list and iterator run to exhaustion, whereas: Using the infix "*x" I'd be fine with x being an iterator too in the same way as the postfix "*x" I'd enjoy, but this would require consuming all-but-the-remaining-fixed and the converting the middle bits back into an iterator...which isn't that much different from the current implementation of "a, *x, b = itr" with x = iter(x) after the tuple assignment. Not a great gain, but at least consistent to remove that burr. It doesn't allow for infinite generators, but that's a somewhat nonsensical request anyways :) "b = INF"? "b=-INF"? "b=K"? and it gets weirder with a,*x,b,c,d = inf_seq_of_monotonically_increasing_primes() if you can get me b, c, and d in a finite amount of time, you get some sorta prize :) > However, having some syntax giving the behaviour you want would be nice. > Something like this perhaps? > > a, b, c = *iterable > > equivalent to: > > _t = iter(iterable) > a = next(_t) > b = next(_t) > c = next(_t) # and so on for each of the left-hand names > del _t > > That would be useful. But yes, that's even better for my use case, as it lacks the ugly "*_" sponge to soak up the remainder and removes my need to track the number of items on the LHS of the assignment. That seems it would involve a new Python construct/syntax rather than the existing py3k syntax. Or at least the removal of the "ValueError: too many values to unpack" error. That would be a lovely addition (when the new-feature-ban is lifted :) -tim From gherron at islandtraining.com Mon Nov 30 12:05:16 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 30 Nov 2009 09:05:16 -0800 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <4B13FB4C.9050506@islandtraining.com> Ronn Ross wrote: > I have recently come across something called a struct. I have googled > this, but have note found a good explanation. Can someone give me a > good definition or point me to a page that has one. > > Thanks Well... Since you don't give us *any* information, other then the single word "struct", let's start with this: Python has a module named struct: http://docs.python.org/library/struct.html#module-struct Is that what you wanted? Gary Herron From gnarlodious at gmail.com Mon Nov 30 12:05:16 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 09:05:16 -0800 (PST) Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: Thanks for the help, but it doesn't work. All I get is an error like: UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in position 0: ordinal not in range(128) It does work in Terminal interactively, after I import the sys module. But my script doesn't act the same. Here is my entire script: #!/usr/bin/python print("Content-type:text/plain;charset=utf-8\n\n") import sys sys.stdout.buffer.write('?\n'.encode("utf-8")) All I get is the despised "Internal Server Error" with Console reporting: malformed header from script. Bad header=\xe6\x99\x89 Strangely, if I run the script in Terminal it acts as expected. This is OSX 10.6 2,, Python 3.1.1. And it is frustrating because my entire website is hung up on this one line I have been working on for 5 days. -- Gnarlie http://Gnarlodious.com From davea at ieee.org Mon Nov 30 12:12:49 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 30 Nov 2009 12:12:49 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4B13FD11.1000808@ieee.org> Victor Subervi wrote: > On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: > > >> exec is a statement, and statements don't have "return values." It's not >> a function, so there are no parentheses in its syntax, either. exec is also >> a technique of last resort; there's nearly always a better/safer/faster way >> to accomplish what you might want, but of course you don't say what that is. >> >> As for "returning" values, exec by default uses the same global space as >> your app, so you can just modify a global variable in your "called" code and >> use it afterwards. >> >> abc = 42 >> value = 12 >> exec "abc = %d" % value >> print abc >> >> > > Taking out the parenthesis did it! Thanks. Now, you state this is an option > of last resort. Although this does indeed achieve my desired aim, here is a > complete example of what I am trying to achieve. The following is from > 'createTables2.py': > > for table in tables: > try: > exec 'from options import %s' % table > except: > pass > try: > exec '%s()' % table > except: > pass > > > The following is from 'options.py': > > def jewelry(which=''): > code = [] > names = [] > meanings = [] > code.append(['5', '5½', '6', '6½', '7', '7½', '8', > '8½', '9', '9½', '10', '10½', '11', '11½', '12', > '12½', '13', '13½']) > meanings.append('The standard ring sizes.') > names.append('ringSizes') > code.append(['Petite (7")', 'Average (7½")', 'Large > (8")', 'Extra-large (8½")']) > meanings.append('The standard bracelet sizes.') > names.append('braceletSizes') > code.append(['16"', '18"', '20"', '22"', '24"']) > meanings.append('The standard necklace sizes.') > names.append('necklaceSizes') > code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K > white gold', 'platinum', 'tungsten', 'titanium']) > meanings.append('The standard jewelry metals.') > names.append('metals') > code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', > 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose > quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', > 'turquoise']) > meanings.append('The standard jewelry stones.') > names.append('stones') > if which == '': > i = 0 > all = '' > while i < len(meanings): > table = '%s\n' % meanings[i] > table += "\n \n \n > " % names[i] > j = 0 > for elt in code: > if (j + 8) % 8 == 0: > table += ' \n' > table += ' \n' % code[i] > if (j + 8) % 8 == 0: > table += ' \n' > j += 1 > if table[-6:] != '\n': > table += ' \n' > table += '
    %s
    %s
    \n' > all += table + '

    ' > i += 1 > print all > > This all works fine; however, if there is a better way of doing it, please > > let me know. > Thanks, > V > > The parentheses can't do any harm for that particular expression, so that wasn't your problem. But I'm glad you fixed whatever else was your problem. I mentioned it because sometimes they can cause problems, and you shouldn't get in bad habits. (things like if, return, and exec are all statements that take an expression, but do not need parentheses.) I'll throw in a comment here about a bare except. Also a bad idea. You could easily mask some other problem involved in the import, and the program silently continues. If you know of a specific problem, or category of problems that you want to ignore, then pick an exception, or tuple of exceptions, to do that. The immediate question is how to get rid of exec. You're using it two places. First case, you're just using it to extract specific objects from that module's namespace. Assuming you've already imported options earlier in the code, you can replace from options import xyzzy by optfunc = options.xyzzy or option_func = getattr(options, "xyzzy", None) or even option_func = getattr(options, "xyzzy", dummyfunc) (where dummyfunc() is a function which takes no arguments and does nothing) Now, assuming you plan to call each such function immediately, you can just say option_func() in the same loop. def dummyfunc(): pass .... for table in tables: option_func = getattr(options, table, dummyfunc) option_func() If you didn't have the dummyfunc, you'd need an "if option_func" in there. Naturally, if this "tables" comes from the user, you need to give him some feedback, so perhaps dummyfunc isn't an empty function after all, but is supplied in options.py Other comments about your code: Someone else has mentioned names, so I won't dwell on that. if table[-6:] != '
    blueredbluered
    \n \n \n >> " % names[i] >> j = 0 >> for elt in code: >> if (j + 8) % 8 == 0: >> table += ' \n' >> table += ' \n' % code[i] >> if (j + 8) % 8 == 0: >> table += ' \n' >> j += 1 >> if table[-6:] != '\n': >> table += ' \n' >> table += '
    %s
    %s
    \n' >> all += table + '

    ' >> i += 1 >> print all >> >> This all works fine; however, if there is a better way of doing it, please >> >> > > let me know. >> Thanks, >> V >> >> >> > The parentheses can't do any harm for that particular expression, so that > wasn't your problem. But I'm glad you fixed whatever else was your problem. > I mentioned it because sometimes they can cause problems, and you shouldn't > get in bad habits. (things like if, return, and exec are all statements > that take an expression, but do not need parentheses.) > > I'll throw in a comment here about a bare except. Also a bad idea. You > could easily mask some other problem involved in the import, and the program > silently continues. If you know of a specific problem, or category of > problems that you want to ignore, then pick an exception, or tuple of > exceptions, to do that. > > > The immediate question is how to get rid of exec. You're using it two > places. First case, you're just using it to extract specific objects from > that module's namespace. > > Assuming you've already imported options earlier in the code, you can > replace > from options import xyzzy > by > optfunc = options.xyzzy > or > option_func = getattr(options, "xyzzy", None) > or even > option_func = getattr(options, "xyzzy", dummyfunc) > (where dummyfunc() is a function which takes no arguments and does nothing) > > Now, assuming you plan to call each such function immediately, you can just > say > option_func() > in the same loop. > > > def dummyfunc(): > pass > > .... > for table in tables: > option_func = getattr(options, table, dummyfunc) > option_func() > > If you didn't have the dummyfunc, you'd need an "if option_func" in there. > > > Naturally, if this "tables" comes from the user, you need to give him some > feedback, so perhaps dummyfunc isn't an empty function after all, but is > supplied in options.py > > Other comments about your code: Someone else has mentioned names, so I > won't dwell on that. > > if table[-6:] != '\n': > > should use endswith(), and you won't run the risk of counting wrong if > your literal changes. > > if (j + 8) % 8 == 0: > > could be simpler: > > if j % 8 == 0: > > The pattern: > j=0 > > for elt in code: > should be replaced by: > for j, elt in enumerate(code): > > (and of course don't forget to then remove the j+=1 ) > > You're using the indexing variable i when it'd make much more sense to use > zip. Or perhaps meanings and code should be a single list, with each item > being a tuple. That's what zip builds, after the fact. But if you build it > explicitly, you're less likely to accidentally have an extra or missing > element in one of them, and have to deal with that bug. > > The zip approach might look something like: > for meaning, code_element in zip(meanings, code): > > and then whenever you're using meanings[i] you use meaning, and whenever > you're using code[i], you use code_element. (Obviously name changes would > help, since code is a list, but the name isn't plural) > > > > More generally, when I see code with that much data embedded in it, it > cries out for templates. They're known by many different names, but the > idea is to write your data structures somewhere else, and manipulate them > with the code, instead of embedding it all together. I suspect that each of > these functions looks very similar, and they each have their own set of bugs > and glitches. That's a good indicator that you need to separate the data. > > For my web work, I've written my own, very simple templating logic that's > only as good as I needed. So I can't comment on the various ones that are > already available. But the idea is you put data into one or more text > files, which you systematically manipulate to produce your end result. A > particular text file might be comma delimited, or defined in sections like > an .ini file, or both, or some other mechanism, such as xml. But make it > easy to parse, so you can concentrate on getting the data into its final > form, consistently, and with common code for all your tables, parameterized > by the stuff in the data files. > > Yeah, maybe on the next iteration after I've finished the shopping cart and got it working. I'm the one who does everything right now, so it's not an issue for me. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From senhor.abrantes at gmail.com Mon Nov 30 12:35:31 2009 From: senhor.abrantes at gmail.com (joao abrantes) Date: Mon, 30 Nov 2009 17:35:31 +0000 Subject: os.starfile() linux Message-ID: <880fa1d40911300935v8df6708xc3c5957d3db25cd9@mail.gmail.com> i want a python program to start another python script and i want it to open a new shell and to put the output of the new python program there.. how can it be done? -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.org.uk Mon Nov 30 12:35:57 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 30 Nov 2009 09:35:57 -0800 (PST) Subject: New to python References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <5e77bdd7-deca-4d65-a6e0-7f40d0951d0e@v37g2000vbb.googlegroups.com> On 30 Nov, 18:14, inhahe wrote: > i don't think structs technically exist in Python (though they exist > in C/C++), but you could always use a plain class like a struct, like > this, for a simple example: > > class Blah: > ? pass > > b = blah() > b.eyecolor = "brown" [...] Yes, a "bare" class can be instantiated and the attributes of the created instance populated as desired. In fact, there are structures (or "structs") provided by various built-in extensions supplied with Python, such as the time structure (struct_time), although this appears as a class if you try to investigate it more closely from the Python prompt. See the Objects/structseq.c file in the Python source distribution for how such structures are actually implemented, however. Paul From alfps at start.no Mon Nov 30 12:38:56 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 18:38:56 +0100 Subject: Req. for comments section "Basic Data" in intro book In-Reply-To: References: Message-ID: * Alf P. Steinbach: > I added a section on "basic data" to ch 2 of my writings, an > introduction to programming (with Python as main language). > > The intended reader is someone who is intelligent and wants to learn > programming but knows little or nothing about it. > > As before it would be nice with feedback on this. > > > Format: PDF > > > > Current contents: > > 1 Getting started. 1 > 1.1 Python variants, implementations and distributions. 1 > 1.2 Download and install a Python implementation. 2 > 1.3 Test-drive the Python interpreter. 2 > 1.4 Create and run a Python console program. 4 > 1.5 Syntax highlighting and programmers' editors. 6 > 1.6 Create and run a Python GUI program. 7 > 1.7 About compilation. 9 > 1.8 About standalone Windows programs & other kinds. 10 > 1.9 Browse the local documentation. 11 > EOT 12 > > 2 Basic concepts. 1 > 2.1 Super-basic concept: why programming is not DWIM. 1 > 2.2 Reported errors. 4 > 2.2.1 Case-sensitity. 4 > 2.2.2 Syntax / compilation errors. 4 > 2.2.3 Runtime errors / crashes. 5 > 2.3 A programming exploration tool: turtle graphics. 6 > 2.4 Naming things. 8 > 2.4.1 Naming actions: routines. 8 > 2.4.2 Naming data part I: variables. 11 > 2.4.3 Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. 14 > 2.5.1 Repeating actions automatically: loops. 14 > 2.5.2 Basic comparisions & boolean values. 16 > 2.5.3 Interlude I: a function graph program / about types. 17 > 2.5.4 Automated action choices. 21 > 2.5.5 Value-producing (function-like) routines. 23 > 2.5.6 Interlude II: a graph with zeroes marked / about program > structure. 26 > 2.5.7 Dynamically nested actions: recursive routines. 28 > 2.6 Basic data. 36 > 2.6.1 Basic fundamental types / strings & concatenation. 36 > 2.6.2 Indexing and single characters (+ vaguely about sequences in > general). 39 > 2.6.3 Interlude III: a ROT-13 encryption/decryption program, > refactoring. 40 > 2.6.4 Attributes, methods, objects. 43 > 2.6.5 Doc strings. 44 > 2.6.6 Interlude IV: attribute names as strings, listing str attributes. 45 > 2.6.7 References. 46 > EOT 49 > > The section on "References", 2.6.7, is about references in Python, it's > not a list of references. :-) Based on feedback I received in private communications I've improved (I hope) the wording in various places, and expanded a bit on the last section. I've placed the latest version also in Google Docs, without yet removing the original -- the file names are the same but they have different dates. Comments welcome. Cheers, - Alf From jpiitula at ling.helsinki.fi Mon Nov 30 12:39:00 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Nov 2009 19:39:00 +0200 Subject: problem with lambda / closures References: Message-ID: Benjamin Kaplan writes: > On Monday, November 30, 2009, Louis Steinberg wrote: > > I have run into what seems to be a major bug, but given my short > > exposure to Python is probably just a feature: > > > > running > > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > > > with file foo.py containing: > > > > ============================== clip here ============ > > def p(d): > > ? ?print d > > > > > > l=[ ] > > for k in [1,2,3]: > > ? ?l.append(lambda : p(k)) > > > > for f in l: > > ? ?f() > > > > ============================== clip here ============ > > I get output > > 3 > > 3 > > 3 > > instead of > > 1 > > 2 > > 3 > > which I would expect. ?Can anyone explain this or give me a > > workaround? ?Thank you > > I don't know if anyone considers python's incomplete implementation > of closures a "feature" but it's documented so it's not really a bug > either. I believe there is a trick with default arguments to get > this to work, but I don't use lambdas enough to remember it. That trick has been shown in some branch of the present thread. Here's a non-trick solution, which I saved in file quux.py: def p(d): print d l=[] for k in [1,2,3]: l.append((lambda k : lambda : p(k))(k)) for f in l: f() Python 2.3.4 (#1, Jul 16 2009, 07:03:37) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import quux 1 2 3 >>> From inhahe at gmail.com Mon Nov 30 12:39:45 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:39:45 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: i'm pretty new to javascript programming, but i'm pretty sure you just need ajax, which AFAIK is a highly technical way of saying "using javascript in a way that makes web pages interactive" JSON afaik is a way of data to and from the server that allows for lists and more variable types and such, but also requires the user download a third-party js file that implements JSON. i don't think you'd technically need JSON, because you could simply send the server a string of all the colors selected delimited by a space or | or something. javascript also probably has inherent functions for generating xml, considering that the object you use to communicate with the server is an xmlhttprequst. but i think xml might be overkill in this case. the javascript would populate the list for the colors the user selects (the easiest way would probably be to give the list an id and use getElementByID()), and then when he's done it would create an xmlhttprequest object to send the data to the server. On Mon, Nov 30, 2009 at 7:26 AM, Victor Subervi wrote: > Hi; > I need a recommendation. I want to print out data like this: > > blue > red > > and enable the user to select the various colors he wants to add to a list > that would populate itself on the same page where the selections are, and > then, once he's selected all the colors he wants, click to add them all at > once to a table in a database, and move on to the next page. I believe this > is achieved through JSON and AJAX; however, I haven't been able to google > any demonstrations of this sort. Am I correct, or should I use some other > sort of technology? > TIA, > Victor > > -- > http://mail.python.org/mailman/listinfo/python-list > > From invalid at invalid.invalid Mon Nov 30 12:41:12 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 30 Nov 2009 17:41:12 +0000 (UTC) Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: On 2009-11-30, a b wrote: > I have a pain in the a** problem with pyserial- it works 90% > of time but on the 10% of time it thorows and termios.error > exception with the value (5, 'Input/output error') and i > cannot get rid of it :( Sounds like faulty converter or a bug in the device driver to me. > The system works as follows: > A device sends out rs485 data -> rs485 to rs232 converter converts it - >> an rs232->usb cable attatched to a computer reads the data. Until > now it hasn't bothered me too much since it hasn't been a lot > of data (every time i get this exception i unload the pl2303 > module from kernel, then reload it, open the com port Does that get rid of the error? If so, then it's definitely a problem with the converter or device-driver. > and hope it won't happen soon). But now the amount of data is > getting bigger and the exceptions in the log are quite > bothering already so if anyone has a good idea what could > affect it i'd be very glad... oh and the settings for the port > opening are: self.ser = serial.Serial(self.port, > self.baudrate, rtscts=0, xonxoff=0, timeout=0) Unless you want to try to troubleshoot the device driver and USB traffic, the only suggestion I have is to try different converters and/or different versions of the driver. -- Grant Edwards grante Yow! If Robert Di Niro at assassinates Walter Slezak, visi.com will Jodie Foster marry Bonzo?? From ebonak at hotmail.com Mon Nov 30 12:48:15 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 12:48:15 -0500 Subject: flattening and rebuilding a simple list of lists In-Reply-To: References: Message-ID: Ok, well I'm glad no one threw up their hands in horror to the code I posted. I'll have to study the alternate solutions offered (thanks!) Esmail From inhahe at gmail.com Mon Nov 30 12:48:56 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:48:56 -0500 Subject: reading from a text file In-Reply-To: <4B13E7B2.5030405@timgolden.me.uk> References: <4B13E7B2.5030405@timgolden.me.uk> Message-ID: i don't understand the point of using 'with' but i don't understand what 'with' does at all i've tried to understand it a few times anyway here: import random result = random.choice(open("c:\\test.txt").readlines()) On Mon, Nov 30, 2009 at 10:41 AM, Tim Golden wrote: > Olof Bjarnason wrote: >> >> 2009/11/27 baboucarr sanneh : >>> >>> hi all >>> >>> i would like to create a python program that would read from a text file >>> and >>> returns one result at random. >>> e.g >>> in the text file i have these data >>> >>> 1.hello >>> 2.my name >>> 3.is >>> 4.World >>> >>> Your help is highly appreciated..thnx in advance >> >> Hi babourarr; >> >> import random >> with open("c:/test.txt") as f: >> ?lines = f.read().splitlines() >> random_line = lines[random.randrange(len(lines))] >> print(random_line) > > Or, slightly more simply: > > import random > with open ("c:/test.txt") as f: > ?print random.choice (list (f)) > > > You need the list () because random.choice only works > on a finite iterable. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Mon Nov 30 12:49:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:49:09 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> On Mon, Nov 30, 2009 at 1:39 PM, inhahe wrote: > i'm pretty new to javascript programming, but i'm pretty sure you just > need ajax, which AFAIK is a highly technical way of saying "using > javascript in a way that makes web pages interactive" > JSON afaik is a way of data to and from the server that allows for > lists and more variable types and such, but also requires the user > download a third-party js file that implements JSON. i don't think > you'd technically need JSON, because you could simply send the server > a string of all the colors selected delimited by a space or | or > something. > javascript also probably has inherent functions for generating xml, > considering that the object you use to communicate with the server is > an xmlhttprequst. but i think xml might be overkill in this case. > > the javascript would populate the list for the colors the user selects > (the easiest way would probably be to give the list an id and use > getElementByID()), and then when he's done it would create an > xmlhttprequest object to send the data to the server. > If I'm not mistaken, that won't help me actually print to screen the user's choices as he selects them, which in my application, is important. Please advise. TIA, V > > On Mon, Nov 30, 2009 at 7:26 AM, Victor Subervi > wrote: > > Hi; > > I need a recommendation. I want to print out data like this: > > > > blue > > red > > > > and enable the user to select the various colors he wants to add to a > list > > that would populate itself on the same page where the selections are, and > > then, once he's selected all the colors he wants, click to add them all > at > > once to a table in a database, and move on to the next page. I believe > this > > is achieved through JSON and AJAX; however, I haven't been able to google > > any demonstrations of this sort. Am I correct, or should I use some other > > sort of technology? > > TIA, > > Victor > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Mon Nov 30 12:57:11 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 12:57:11 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... Message-ID: Hello all. I am using the PIL 1.1.6 and Python 2.6.x under XP without any problems. However, I can't display any images under Vista or Windows 7. I could understand Windows 7 as it's relatively new, but Vista has been around for a bit. Sample code: import Image im = Image.open('c://mypic.jpg') im.show() this will work fine under XP, but under Windows 7 and Vista the default image viewer will come up with some error message that the image can't be found. I tried with an external image view program and tried to supply it via the command parameter to show - but that too didn't work. Definition: im.show(self, title=None, command=None) Any suggestions/help/workarounds? If you can get this to work with Vista or Windows 7 I'd love to hear from you. Thanks! Esmail From jjposner at optimum.net Mon Nov 30 12:58:36 2009 From: jjposner at optimum.net (John Posner) Date: Mon, 30 Nov 2009 12:58:36 -0500 Subject: Noobie python shell question References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: On Sun, 29 Nov 2009 22:03:09 -0500, tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? > How about this: ################## > python Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a,b,c = 1,2,3 >>> def spam(): return None ... >>> def eggs(): return None ... >>> dir() ['__builtins__', '__doc__', '__name__', '__package__', 'a', 'b', 'c', 'eggs', 'spam'] >>> locals() {'a': 1, 'c': 3, 'b': 2, 'spam': , '__builtins__': , 'eggs': , '__package__': None, '__name__': '__main__', '__doc__': None} >>> [name for name in locals() if callable(locals()[name])] Traceback (most recent call last): File "", line 1, in RuntimeError: dictionary changed size during iteration >>> [name for name in locals() if callable(locals()[name])] ['spam', 'eggs'] ################## To avoid the harmless RuntimeError, define "name" before using it in the list comprehension (the final expression) -- e.g.: name = 1 -John From inhahe at gmail.com Mon Nov 30 12:58:39 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:58:39 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi wrote: > > > On Mon, Nov 30, 2009 at 1:39 PM, inhahe wrote: >> >> i'm pretty new to javascript programming, but i'm pretty sure you just >> need ajax, which AFAIK is a highly technical way of saying "using >> javascript in a way that makes web pages interactive" >> JSON afaik is a way of data to and from the server that allows for >> lists and more variable types and such, but also requires the user >> download a third-party js file that implements JSON. ?i don't think >> you'd technically need JSON, because you could simply send the server >> a string of all the colors selected delimited by a space or | or >> something. >> javascript also probably has inherent functions for generating xml, >> considering that the object you use to communicate with the server is >> an xmlhttprequst. but i think xml might be overkill in this case. >> >> the javascript would populate the list for the colors the user selects >> (the easiest way would probably be to give the list an id and use >> getElementByID()), and then when he's done it would create an >> xmlhttprequest object to send the data to the server. > > If I'm not mistaken, that won't help me actually print to screen the user's > choices as he selects them, which in my application, is important. Please > advise. > TIA, > V sure, that's where this part comes in: the javascript would populate the list for the colors the user selects (the easiest way would probably be to give the list an id and use getElementByID()) so basically you'd define, e.g., an onClick="blah('red'); return true" within the red element's tag, and then define a function blah(x) that says getElementById("my_list_id").innerHtml += "
    " + x; and of course give your list textarea an id="my_list_id" attribute in the tag. that could be slightly wrong, my javascript's rusty From inhahe at gmail.com Mon Nov 30 13:00:03 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:00:03 -0500 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > wrote: >> >> >> If I'm not mistaken, that won't help me actually print to screen the user's >> choices as he selects them, which in my application, is important. Please >> advise. >> TIA, >> V > > > sure, that's where this part comes in: > > the javascript would populate the list for the colors the user selects > (the easiest way would probably be to give the list an id and use > getElementByID()) > > so basically you'd define, e.g., an onClick="blah('red'); return true" > within the red element's tag, and then define a function blah(x) that > says > getElementById("my_list_id").innerHtml += "
    " + x; > and of course give your list textarea an id="my_list_id" attribute in the tag. > > that could be slightly wrong, my javascript's rusty > also don't forget to sanitize the data you receive before committing it to the database, or someone can hack the javascript and send an SQL injection attack From python at mrabarnett.plus.com Mon Nov 30 13:00:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Nov 2009 18:00:06 +0000 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <4b132c1b$1@dnews.tpgi.com.au> References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <4B140826.4070707@mrabarnett.plus.com> Lie Ryan wrote: > On 11/30/2009 12:38 PM, Esmail wrote: >> Thanks all!! I get it now :-) >> >> It helped to have a number of different explanations, thanks >> for taking the time to post. Much appreciated. > > I generally do not expect operator precedence to be reliable at all > except for: > > + - (binary ops, not the unary) > * / > ** > > for other operators I would have explicit parens. It's too much work to > remember the rest of the precedence sheet. Most programming languages don't differentiate in text between the number "negative 3" and the expression "negated 3". APL does. The former is written as "?3" (3 preceded by the overscore character) and the latter as "-3" (3 preceded by the minus sign). From ebonak at gmail.com Mon Nov 30 13:04:45 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 10:04:45 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: Message-ID: > > ? im = Image.open('c://mypic.jpg') sorry, slip of the finger, there's only one forward slash or you can use two backward slashes. The problem isn't with opening it (I know it opens fine since I can get its size attribute via im.size) - the show() is the problem. Esmail From lie.1296 at gmail.com Mon Nov 30 13:07:36 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:07:36 +1100 Subject: Feature request: String-inferred names In-Reply-To: <4b13f44c$0$7868$426a34cc@news.free.fr> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b13f44c$0$7868$426a34cc@news.free.fr> Message-ID: <4b140a4d@dnews.tpgi.com.au> On 12/1/2009 3:35 AM, Bruno Desthuilliers wrote: > Lie Ryan a ?crit : >> On 11/28/2009 3:08 PM, The Music Guy wrote: > > (snip the part about the proposed feature - which I don't like but > that's not the point) > >>> My >>> projects rely on a lot of metaclassing for the automatic generation of >>> properties and methods, which saves tremendous amounts of coding. >> >> If you use it a lot, it is likely 1) you have abused class syntax for >> what should have been a dict or 2) what you need is to override >> __getattr__/__getattribute__ and __setattr__ > > I have to totally disagree here. The way the OP uses metaprogramming is > a really common and handy solution in lots of frameworks, and > drastically reduces the need for boilerplate (and the potential for > bugs). It's *WAY* cleaner (readability, introspection, doc etc) and far > less error-prone than going the __getattr(ibute)__ / __setattr__, and > also way more efficient (from execution time POV). I won't argue with the usefulness of metaclass, I agree that metaclass is the cleanest way to implement certain things; but the main point is the OP's use of getattr/setattr while he got full control of the namespace dictionary. > Using __getattr__ and __setattr__ to emulate attributes (usually > descriptors) that can be built at class creation time is IMHO what > should be labeled as an "abuse" (at best). From manu3d at gmail.com Mon Nov 30 13:08:13 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Mon, 30 Nov 2009 10:08:13 -0800 (PST) Subject: Python Statements/Keyword Localization References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> Message-ID: <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> Thank you all for the insights. I particularly like the broad spread of opinions on the subject. Indeed when I wrote the original post my thoughts were with those young students of non-English speaking countries that start learning to program before they learn English. My case is almost one of those: I started at home when I was 13, toying around with Basic, and at the time not only I didn't know English, but for a few more years I would be learning only French. Later I did start learning English but I still found that while learning programming in Pascal at school its English keywords were somehow an interruption of my mental flow. At the time (20 years ago) localization wasn't a particularly big thing and this issue would have been a bit of a lost cause. But as the world is becoming more and more interconnected I think it is important that we all make an effort to respect cultural needs and sensitivities of both non-western adults and youngsters alike. Ultimately I certainly appreciate the ubiquity of English even though in the interest of fairness and efficiency I'd prefer the role of common language to be given to a constructed language, such as Ido. But it doesn't take a particularly religious person to see that "do to others as you would want them do to you" tends to be a valid principle, and in the same way the world would be at a loss if an Indian university came up with a wonderful programming language available only in Sanskrit, the world is at a loss not having a beautiful language such as Python natively available in other scripts. Again, thank you all! Manu From aahz at pythoncraft.com Mon Nov 30 13:10:25 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Nov 2009 10:10:25 -0800 Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: In article , Gnarlodious wrote: > >Thanks for the help, but it doesn't work. All I get is an error like: > >UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in >position 0: ordinal not in range(128) No time to give you more info, but you probably need to change the encoding of sys.stdout. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From inhahe at gmail.com Mon Nov 30 13:12:52 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:12:52 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: On Mon, Nov 30, 2009 at 12:22 PM, Manuel Graune wrote: > > Hello, > > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j > I could be wrong, but I think this was actually a bug that was fixed later. > and 2) > > a=list([]) > > vs. > > b=[[]] > those don't return the same thing list([]) will create a shallow copy of [], which will of course be [] i can't think of a place where you'd want to use list() instead of [], but sometimes you might want to use 'list', such as in a defaultdict, in which case it's being used as a factory > > Regards, > > Manuel Graune > > -- > A hundred men did the rational thing. The sum of those rational choices was > called panic. Neal Stephenson -- System of the world > http://www.graune.org/GnuPG_pubkey.asc > Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A ?5828 5476 7E92 2DB4 3C99 > -- > http://mail.python.org/mailman/listinfo/python-list > From lie.1296 at gmail.com Mon Nov 30 13:13:48 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:13:48 +1100 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <4b140bc1$1@dnews.tpgi.com.au> On 12/1/2009 4:22 AM, Manuel Graune wrote: > > Hello, > > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j It's not so much about list() vs. [] but generator comprehension vs. list comprehension. list() takes a generator comprehension, while [listcomp] is its own syntax. List comprehension leaked its "loop counter" to the surrounding namespace, while generator comprehension got its own tiny namespace. This "bug" (or feature, depending on your political alignment) is fixed in Python 3.x: Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = [i for i in range(10)] >>> i Traceback (most recent call last): File "", line 1, in NameError: name 'i' is not defined >>> a = list(i for i in range(10)) >>> i Traceback (most recent call last): File "", line 1, in NameError: name 'i' is not defined >>> ^Z From victorsubervi at gmail.com Mon Nov 30 13:21:00 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:21:00 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > > wrote: > >> > >> > >> If I'm not mistaken, that won't help me actually print to screen the > user's > >> choices as he selects them, which in my application, is important. > Please > >> advise. > >> TIA, > >> V > > > > > > sure, that's where this part comes in: > > > > the javascript would populate the list for the colors the user selects > > (the easiest way would probably be to give the list an id and use > > getElementByID()) > > > > so basically you'd define, e.g., an onClick="blah('red'); return true" > > within the red element's tag, and then define a function blah(x) that > > says > > getElementById("my_list_id").innerHtml += "
    " + x; > > and of course give your list textarea an id="my_list_id" attribute in the > tag. > > > > that could be slightly wrong, my javascript's rusty > > > > also don't forget to sanitize the data you receive before committing > it to the database, or someone can hack the javascript and send an SQL > injection attack > Good call! However, in my case I can put this all behind a firewall. It's only for the shop builder's use, and that's my client...whom I can track! But I presume this would entail doing searches for and eliminating all unnecessary characters, right? V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 30 13:24:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:24:09 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <4dc0cfea0911301024i49740011hcf9a5ede46363f4@mail.gmail.com> On Mon, Nov 30, 2009 at 1:35 PM, Dennis Lee Bieber wrote: > On Mon, 30 Nov 2009 07:26:09 -0500, Victor Subervi > declaimed the following in > gmane.comp.python.general: > > > Hi; > > I need a recommendation. I want to print out data like this: > > > > blue > > red > > > Why all the off-page links? > > How about just a table of checkboxes? > > > > > > > > > >
    > Blue >
    > Red >
    >
    > > >
    > > Ya know, in the interest of time, why not. There are a couple of selection lists that have a couple hundred elements each one, but heck, I need to move on and not spend days on this. Thanks ;) V -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Nov 30 13:28:18 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 30 Nov 2009 13:28:18 -0500 Subject: Questions about list-creation References: Message-ID: Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i Long ago, lists were built using explicit code: a = [] for i in xrange(10): a.append (i) which of course left i bound to the last value that was appended. People decided later that this was wordier than it had to be, and could bury the real point of a computation under a lot of boilerplate code that initialized lists, so we got list comprehensions, as you note, and they behave the same as the original code. > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: The list constructor is a lot more recent. It takes any iterable as an argument and makes (or tries to make) a list with the resulting values. The example you give takes a sequence comprehension as its argument. A sequence comprehension doesn't create data values -- it creates a block of code that can be executed later to create data values, and it can be executed later in any context. So we could also code (untested): def S(): return (j for j in xrange (10)) def T(s): return list (s) c = S() b = T(c) which still creates a list, but at an astonishing remove. The sequence comprehension `c` can't count on finding a `j` in the namespace it finally gets executed in, so it has to have it's own private namespace to use then. That's why you don't see `j` in your local namespace when `list` finallty runs the sequence comprehension. Mel. From inhahe at gmail.com Mon Nov 30 13:31:29 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:31:29 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: i should also mention that a=[i for i in xrange(10)] and b=list(j for j in xrange(10)) isn't really just a difference of using [] vs. list() the first case is a list comprehension, the second case is a generator comprehension which is then converted to a list (the bug only applies to list comprehensions, not generator comprehensions) i.e. notice that you can do this ''.join(x for x in ['a','b','c']) no list or [] involved - it's just a generator comprehension being passed to a function. On Mon, Nov 30, 2009 at 1:12 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:22 PM, Manuel Graune wrote: >> >> Hello, >> >> in (most) python documentation the syntax "list()" >> and "[]" is treated as being more or less the same >> thing. For example "help([])" and "help(list())" point >> to the same documentation. Since there are at least >> two cases where this similarity is not the case, (see below) >> can someone explain the reasoning behind this and point to >> further / relevant documentation? >> (To clarify: I am not complaining about this, just asking.) >> >> >> 1.) >> >> when using local variables in list comprehensions, say >> >> a=[i for i in xrange(10)] >> >> the local variable is not destroyed afterwards: >> >> print "a",a >> print "i",i >> >> using the similar code >> >> b=list(j for j in xrange(10)) >> >> the local variable is destroyed after use: >> >> print "b",b >> print "j",j >> > > I could be wrong, but I think this was actually a bug that was fixed later. > >> and 2) >> >> a=list([]) >> >> vs. >> >> b=[[]] >> > > those don't return the same thing > list([]) will create a shallow copy of [], which will of course be [] > > i can't think of a place where you'd want to use list() instead of [], > but sometimes you might want to use 'list', such as in a defaultdict, > in which case it's being used as a factory > >> >> Regards, >> >> Manuel Graune >> >> -- >> A hundred men did the rational thing. The sum of those rational choices was >> called panic. Neal Stephenson -- System of the world >> http://www.graune.org/GnuPG_pubkey.asc >> Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A ?5828 5476 7E92 2DB4 3C99 >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From lie.1296 at gmail.com Mon Nov 30 13:32:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:32:27 +1100 Subject: Can't print Chinese to HTTP In-Reply-To: References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: <4b141020$1@dnews.tpgi.com.au> On 12/1/2009 4:05 AM, Gnarlodious wrote: > Thanks for the help, but it doesn't work. All I get is an error like: > > UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in > position 0: ordinal not in range(128) The error says it all; you're trying to encode the chinese character using 'ascii' codec. > malformed header from script. Bad header=\xe6\x99\x89 Hmmm... strange. The \xe6\x99\x89 happens to coincide with UTF-8 representation of ?. Why is your content becoming a header? > #!/usr/bin/python do you know what python version, exactly, that gets called by this hashbang? You mentioned that you're using python 3, but I'm not sure that this hashbang will invoke python3 (unless Mac OSX has made a progress above other linux distros and made python 3 the default python). > Strangely, if I run the script in Terminal it acts as expected. I think I see it now. You're invoking python3 in the terminal; but your server invokes python 2. Python 2 uses byte-based string literal, while python 3 uses unicode-based string literal. When you try to ' ?\n'.encode("utf-8"), python 2 tried to decode the string using 'ascii' decoder, causing the exception. From mail at timgolden.me.uk Mon Nov 30 13:34:46 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Nov 2009 18:34:46 +0000 Subject: reading from a text file In-Reply-To: References: <4B13E7B2.5030405@timgolden.me.uk> Message-ID: <4B141046.80307@timgolden.me.uk> inhahe wrote: > i don't understand the point of using 'with' > but i don't understand what 'with' does at all > i've tried to understand it a few times > anyway here: > > import random > result = random.choice(open("c:\\test.txt").readlines()) Yep. That'll do the trick. The point of "with" is that, while in CPython, an open file will be closed as soon as it is out of scope -- in this case, after that line -- in other implementations of Python, this may not be so. Good practice suggests using with (or try/finally) which ensures that the file is closed, regardless of the implementation. For a quick example it's not always easy to know whether to include this kind of detail, but a with: block adds very little noise and will save you from being caught out somewhere, someday. http://www.python.org/doc/current/whatsnew/2.6.html#pep-343-the-with-statement TJG From inhahe at gmail.com Mon Nov 30 13:37:22 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:37:22 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi wrote: > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> > wrote: >> >> >> >> >> >> If I'm not mistaken, that won't help me actually print to screen the >> >> user's >> >> choices as he selects them, which in my application, is important. >> >> Please >> >> advise. >> >> TIA, >> >> V >> > >> > >> > sure, that's where this part comes in: >> > >> > the javascript would populate the list for the colors the user selects >> > (the easiest way would probably be to give the list an id and use >> > getElementByID()) >> > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" >> > within the red element's tag, and then define a function blah(x) that >> > says >> > getElementById("my_list_id").innerHtml += "
    " + x; >> > and of course give your list textarea an id="my_list_id" attribute in >> > the tag. >> > >> > that could be slightly wrong, my javascript's rusty >> > >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Good call! However, in my case I can put this all behind a firewall. It's > only for the shop builder's use, and that's my client...whom I can track! > But I presume this would entail doing searches for and eliminating all > unnecessary characters, right? > V > depends on if you're using python or php on the server side if you're using Python, just use parameterized sql, which completely avoids the issue of sql injection if you're using php, parameterized sql is kind of pain in the ass, but it includes a function for sanitizing strings so you don't have to make one yourself. if i remember correctly though, my friend and i had issues with that function, for example ' would be saved as \' in our database, or something like that i'm not sure which characters you need to eliminate to sanitize sql parameters.. i wouldn't be comfortable relying on my own function to do that without thoroughly researching the issue... and i'd probably just rather find a function that's already been written From victorsubervi at gmail.com Mon Nov 30 13:40:25 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:40:25 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: <4dc0cfea0911301040q761ab306h7ef70c601476bfe1@mail.gmail.com> On Mon, Nov 30, 2009 at 2:37 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi > wrote: > > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: > >> > >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > >> > wrote: > >> >> > >> >> > >> >> If I'm not mistaken, that won't help me actually print to screen the > >> >> user's > >> >> choices as he selects them, which in my application, is important. > >> >> Please > >> >> advise. > >> >> TIA, > >> >> V > >> > > >> > > >> > sure, that's where this part comes in: > >> > > >> > the javascript would populate the list for the colors the user selects > >> > (the easiest way would probably be to give the list an id and use > >> > getElementByID()) > >> > > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" > >> > within the red element's tag, and then define a function blah(x) that > >> > says > >> > getElementById("my_list_id").innerHtml += "
    " + x; > >> > and of course give your list textarea an id="my_list_id" attribute in > >> > the tag. > >> > > >> > that could be slightly wrong, my javascript's rusty > >> > > >> > >> also don't forget to sanitize the data you receive before committing > >> it to the database, or someone can hack the javascript and send an SQL > >> injection attack > > > > Good call! However, in my case I can put this all behind a firewall. It's > > only for the shop builder's use, and that's my client...whom I can track! > > But I presume this would entail doing searches for and eliminating all > > unnecessary characters, right? > > V > > > > depends on if you're using python or php on the server side > if you're using Python, just use parameterized sql, which completely > avoids the issue of sql injection > if you're using php, parameterized sql is kind of pain in the ass, but > it includes a function for sanitizing strings so you don't have to > make one yourself. > if i remember correctly though, my friend and i had issues with that > function, for example ' would be saved as \' in our database, or > something like that > i'm not sure which characters you need to eliminate to sanitize sql > parameters.. i wouldn't be comfortable relying on my own function to > do that without thoroughly researching the issue... and i'd probably > just rather find a function that's already been written > Yeah, parameterize it. PHP?! Wash your mouth out with soap! ;) V -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Mon Nov 30 13:40:59 2009 From: nad at acm.org (Ned Deily) Date: Mon, 30 Nov 2009 10:40:59 -0800 Subject: multiprocessing.connection with ssl References: <8ff1698c-8205-4171-9e41-2e382bd52e89@g23g2000vbr.googlegroups.com> Message-ID: In article <8ff1698c-8205-4171-9e41-2e382bd52e89 at g23g2000vbr.googlegroups.com>, Xavier wrote: > I've hacked multiprocessing.connection (in a basic way) to allow ssl > encryption using ssl.wrap_socket. > > Anybody knows how i can contribute this to main developers? If you haven't already, open a feature request issue on the Python bug tracker (http://bugs.python.org/) and attach the code as a patch file. -- Ned Deily, nad at acm.org From lie.1296 at gmail.com Mon Nov 30 13:42:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:42:04 +1100 Subject: python and vc numbers In-Reply-To: References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> Message-ID: <4b141261$1@dnews.tpgi.com.au> On 11/30/2009 10:05 PM, Daniel Dalton wrote: > On Mon, Nov 30, 2009 at 02:26:14AM -0800, Chris Rebert wrote: >> Also, in my quickie newbie experimentation with `screen`, each screen >> "window" seems to get a unique tty#. Admittedly I am running OS X Can you make do with the tempfile module? Or you'd need to identify from an external process which console is locked? From clp2 at rebertia.com Mon Nov 30 13:53:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 10:53:48 -0800 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> Message-ID: <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> > On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing > wrote: >> Esmail wrote: >> >>> Wow .. never heard of Concatenative_languages languages before or the >>> distinction you make. Your distinction explains the behavior, but I >>> find it somewhat counter-intuitive. >> >> You shouldn't find it any more surprising than the fact that >> >> ?a = 2 + 3 >> ?print a * 5 >> >> gives a different result from >> >> ?print 2 + 3 * 5 On Mon, Nov 30, 2009 at 3:41 AM, inhahe wrote: > one point of confusion could be the use of ** instead of superscript. > it might make things a little bit more counterintuitive-looking than > with superscripts, since the issue with Well, since source code is almost universally just plain ASCII and not in some file format with typesetting, superscripts aren't going to happen any time soon. (Also, avoid top-posting in the future.) Cheers, Chris -- http://blog.rebertia.com From inhahe at gmail.com Mon Nov 30 13:55:55 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:55:55 -0500 Subject: High-performance Python websites In-Reply-To: References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com> Message-ID: On Wed, Nov 25, 2009 at 7:33 PM, ShoqulKutlu wrote: > Hi, > > Managing load of high volume of visitors is a common issue for all > kind of web technologies. I mean this is not the python issue. This > issue is mostly about server level designs. You need to supply load > balancing for both web servers and databases to make your web site > able to respond to several concurrent visitors. Of course a good > programmed website is a key performance issue but for your mention I > would also suggest considering how many hardwares, how many > webservers, how many database cluster and which database server should > be used or will be used in the future.. > I don't know a lot about this issue, but take apache + php. every time a page is loaded a new instance of php is loaded to run the page, so i imagine load balancing can easiry be done on the page request level by distributing instances of php processes. whereas if you use python, you don't really want to load the python interpreter for every page request. as far as i can tell, the canonical way is to have one app for the whole website that's constantly running and communicates with the server via WSGI. or is that wrong? and wouldn't that make load balancing a little bit more tricky, or at least different? not sure.. From inhahe at gmail.com Mon Nov 30 13:58:06 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:58:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert wrote: >> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing >> wrote: >>> Esmail wrote: >>> >>>> Wow .. never heard of Concatenative_languages languages before or the >>>> distinction you make. Your distinction explains the behavior, but I >>>> find it somewhat counter-intuitive. >>> >>> You shouldn't find it any more surprising than the fact that >>> >>> ?a = 2 + 3 >>> ?print a * 5 >>> >>> gives a different result from >>> >>> ?print 2 + 3 * 5 > > On Mon, Nov 30, 2009 at 3:41 AM, inhahe wrote: >> one point of confusion could be the use of ** instead of superscript. >> it might make things a little bit more counterintuitive-looking than >> with superscripts, since the issue with > > Well, since source code is almost universally just plain ASCII and not > in some file format with typesetting, superscripts aren't going to > happen any time soon. > (Also, avoid top-posting in the future.) > i wasn't suggesting it as a feature for python, just pointing out why it might seem counterintuitive. From nad at acm.org Mon Nov 30 14:00:12 2009 From: nad at acm.org (Ned Deily) Date: Mon, 30 Nov 2009 11:00:12 -0800 Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: In article , Gnarlodious wrote: > It does work in Terminal interactively, after I import the sys module. > But my script doesn't act the same. Here is my entire script: > > #!/usr/bin/python > print("Content-type:text/plain;charset=utf-8\n\n") > import sys > sys.stdout.buffer.write('???n'.encode("utf-8")) > > All I get is the despised "Internal Server Error" with Console > reporting: > > malformed header from script. Bad header=?xe6?x99?x89 > > Strangely, if I run the script in Terminal it acts as expected. > > This is OSX 10.6 2,, Python 3.1.1. Are you sure you are actually using Python 3? /usr/bin/python is the path to the Apple-supplied python 2.6.1. If you installed Python 3.1.1 using the python.org OS X installer, the path should be /usr/local/bin/python3 -- Ned Deily, nad at acm.org From apt.shansen at gmail.com Mon Nov 30 14:01:46 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 30 Nov 2009 11:01:46 -0800 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: Message-ID: <7a9c25c20911301101t65d16d8er484209fa0b01b915@mail.gmail.com> On Mon, Nov 30, 2009 at 9:57 AM, Esmail wrote: > Hello all. > > I am using the PIL 1.1.6 and Python 2.6.x under XP without any > problems. However, I can't display any images under Vista > or Windows 7. I could understand Windows 7 as it's relatively > new, but Vista has been around for a bit. > > Sample code: > > import Image > > im = Image.open('c://mypic.jpg') > im.show() > Totally a guess, but did you try "c:\\mypic.jpg"? \ is the path separator on windows, not /. A / will work in many situations, but doubling it might cause problems perhaps (especially since you never have to double forward-slashes, unlike back slashes) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 14:02:21 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:02:21 +1100 Subject: how to format a python source file with tools? In-Reply-To: References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: <4b141722$1@dnews.tpgi.com.au> On 12/1/2009 4:30 AM, Falcolas wrote: > Nonetheless, it would be better to implement coding standards that > everyone can stick to. Agreed. You can't solve social issues with program. From lie.1296 at gmail.com Mon Nov 30 14:05:53 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:05:53 +1100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> Message-ID: <4b1417f6$1@dnews.tpgi.com.au> On 12/1/2009 5:58 AM, inhahe wrote: > i wasn't suggesting it as a feature for python, just pointing out why > it might seem counterintuitive. I'm interested, what do YOU (inhahe) think the result should be? Should both become -9 or both become 9. What was your expectation when you wrote that post? From lie.1296 at gmail.com Mon Nov 30 14:17:15 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:17:15 +1100 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: <4b141aa0@dnews.tpgi.com.au> On 12/1/2009 5:00 AM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> wrote: >>> >>> >>> If I'm not mistaken, that won't help me actually print to screen the user's >>> choices as he selects them, which in my application, is important. Please >>> advise. That's where Javascript kicks in. You only need to use the javascript to modify your document (visual effect); you won't need it to submit to the server (the real action). > > also don't forget to sanitize the data you receive before committing > it to the database, or someone can hack the javascript and send an SQL > injection attack Or a XSS attack (Cross-site scripting). Basically, you want to check whether the string received by the server matches your own predefined list of colors before storing to the database. From victorsubervi at gmail.com Mon Nov 30 14:21:29 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 15:21:29 -0400 Subject: os.remove() permission problem Message-ID: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Hi; I get the following error when I try os.remove(file) *OSError*: [Errno 13] Permission denied: 'particulars.py' args = (13, 'Permission denied') errno = 13 filename = 'particulars.py' strerror = 'Permission denied' Here are the permissions: -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py When I go into the python interpreter and execute that statement, it succeeds. What have I missed? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at twistedmatrix.com Mon Nov 30 14:32:31 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 30 Nov 2009 19:32:31 -0000 Subject: Can't print Chinese to HTTP In-Reply-To: References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: <20091130193231.2549.395377677.divmod.xquotient.45@localhost.localdomain> On 05:05 pm, gnarlodious at gmail.com wrote: >Thanks for the help, but it doesn't work. All I get is an error like: > >UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in >position 0: ordinal not in range(128) > >It does work in Terminal interactively, after I import the sys module. >But my script doesn't act the same. Here is my entire script: > >#!/usr/bin/python >print("Content-type:text/plain;charset=utf-8\n\n") >import sys >sys.stdout.buffer.write('f49\n'.encode("utf-8")) > >All I get is the despised "Internal Server Error" with Console >reporting: > >malformed header from script. Bad header=\xe6\x99\x89 As the error suggests, you're writing f49 to the headers section of the response. This is because you're not ending the headers section with a blank line. Lines in HTTP end with \r\n, not with just \n. Have you considered using something with fewer sharp corners than CGI? You might find it more productive. Jean-Paul From Brian.Mingus at Colorado.EDU Mon Nov 30 14:42:06 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 30 Nov 2009 12:42:06 -0700 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <9839a05c0911301142x5c4e3376j74416aa7bfdd73d2@mail.gmail.com> On Sun, Nov 29, 2009 at 5:58 PM, Esmail wrote: > Brian J Mingus wrote: > >> >> >> >> I think you answered your own question. 3**2 comes first in the order of >> operations, followed by the negation. >> > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contains -3 (x in my example) Yes, that is the problem. Setting x=-3 is the same as writing (-3)**2 vs. -(3**2). -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Nov 30 14:52:08 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 30 Nov 2009 11:52:08 -0800 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <7a9c25c20911301152t48a74badv2f91cf77eec2bfeb@mail.gmail.com> On Mon, Nov 30, 2009 at 9:22 AM, Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > They -do- pretty much the same thing, but you can't quite treat them as two forms which can be exchanged at a whim. [] is the syntax for creating a list literal in source code. Its also the syntax for list comprehensions. A list comprehension is an expression that constructs a list all at once. list() is a function (type/constructor/...) which accepts any iterable as an argument (or None), and uses it to construct a list, returning it. Those two things are very different, although in the end they both produce lists: one is syntax, the other is a function which has to be called. 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > List comprehensions "leaked", as more of an implementation detail I believe then anything else: in Python 3 it was removed, to better match generator expressions (IIRC). > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j > > But see, this is something completely different. (j for j in xrange(10)) is NOT a list comprehension. Its a generator comprehension. In the first example with lists, you're using literal syntax to construct (all at once) a list. In this, you're using literal syntax to construct a generator-- the generator is then passed to the list function, which iterates over it and constructs a list, returning when that generator is exhausted. And generator comprehensions don't leak their variables (I can't remember if that was an implementation detail or a deliberate design decision, but eventually list comprehensions were made to match the behavior). > and 2) > > a=list([]) > > vs. > > b=[[]] > Those are also doing two completely different things: on the first, you are using literal syntax to create an empty list. You are then passing this list (which is an iterable) to the list function, telling it to make a list out of that literal. It does so, which is in the end a (shallow) copy of the first list you made. The second, you are using literal syntax to create an empty list, and using literal syntax to place that empty list inside another list. You basically can't treat the two things as interchangable, because they're different: one is syntax, one is a function. Both are ways to make lists. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 15:08:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 07:08:26 +1100 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: Message-ID: <4b14269f$1@dnews.tpgi.com.au> On 12/1/2009 5:04 AM, Esmail wrote: >> >> im = Image.open('c://mypic.jpg') > > sorry, slip of the finger, there's only one forward slash > or you can use two backward slashes. > > The problem isn't with opening it (I know it opens fine > since I can get its size attribute via im.size) - the show() > is the problem. What's your default image viewer? im.show is intended to be for debugging purpose and may always guaranteed to work if your image viewer doesn't support receiving the file through . From kyrie at uh.cu Mon Nov 30 15:22:12 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 30 Nov 2009 15:22:12 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <200911301522.12827.kyrie@uh.cu> On Monday 30 November 2009 12:22:17 pm Manuel Graune wrote: > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: [...] > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: Actually, [] and list() are not the same. For instance, list(1,2) rises an error, while [1,2] is the list with two elements. The comprehension is just a syntactic contruct that allows you to simplify the creation of lists, while the list() "function" (it is a class, actually) receives an iterable object and returns a list. What you seem to be confused about is the construct: (j for j in xrange(10)) That is called a generator expression, and it is very similar to the list comprehension, except that it builds an iterator (instead of a list, i.e, the xrange(10) is not consumed until it is needed), and the loop variable doesn't "leak" outside. When you do b=list(j for j in xrange(10)), you are actually doing b=list((j for j in xrange(10))) (note the extra set of parenthesis - python lets you ommit those), i.e, you are calling the list() "function" with a single argument, an iterable that contains all the elements of xrange(10). You could be calling foobar(j for j in xrange(10)) instead. And I think I lost my way... I'm sleepy. If I confused you, sorry... and if I'm helped you, thank you for letting me :D. Cya. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From victorsubervi at gmail.com Mon Nov 30 15:35:32 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 16:35:32 -0400 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: <4dc0cfea0911301235k12106bcdj8c7ae5a5b7a43b9b@mail.gmail.com> On Mon, Nov 30, 2009 at 3:21 PM, Victor Subervi wrote: > Hi; > I get the following error when I try > os.remove(file) > > *OSError*: [Errno 13] Permission denied: 'particulars.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'particulars.py' > strerror = 'Permission denied' > > Here are the permissions: > > -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py > > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? > > This is on a CentOS system. I've tried manipulating the mode to 666 and 777 but that didn't help at all. I do read from the file, then close it, but I've tried deleting a file I don't read and come up with the same error. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at gmail.com Mon Nov 30 15:45:09 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 12:45:09 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> Message-ID: <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> On Nov 30, 3:08?pm, Lie Ryan wrote: > > What's your default image viewer? im.show is intended to be for > debugging purpose and may always guaranteed to work if your image viewer > doesn't support receiving the file through the image to the program>. It's whatever the default windows viewer is :-) .. so if I double- click on the image in the filemanager it fires it up and shows it. This works in XP and Windows 7 and Vista (ie double clicking on the image and having it display). I dug around in the docs and found a named parameter that I can set when I call show. Definition: im.show(self, title=None, command=None) I installed irfanview and specified it/its path in the parameter, but that didn't work either. It's really quite puzzling in the case of Vista since that's been around for quite a few years now. Esmail From arts.martijn at gmail.com Mon Nov 30 15:50:34 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Mon, 30 Nov 2009 21:50:34 +0100 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: <23739e0a0911301250h2dcd838en2cdffe2c116df9fd@mail.gmail.com> On Mon, Nov 30, 2009 at 8:21 PM, Victor Subervi wrote: > Hi; > I get the following error when I try > os.remove(file) > > *OSError*: [Errno 13] Permission denied: 'particulars.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'particulars.py' > strerror = 'Permission denied' > > Here are the permissions: > > -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py > Try chmodding the file to 755. > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? > TIA, > Victor > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 30 15:51:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 15:51:02 -0500 Subject: Variables with cross-module usage In-Reply-To: <4b135424$1@dnews.tpgi.com.au> References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> <4b135424$1@dnews.tpgi.com.au> Message-ID: Lie Ryan wrote: > On 11/30/2009 12:00 PM, Terry Reedy wrote: >> Dennis Lee Bieber wrote: >> >>> In these languages, the names always refer to the same location. >>> Python confuses matters by having names that don't really refer to >>> location, but are attached to the objects. >> >> In everyday life and natural languages, names refer to people, other >> objects, roles, and only occasionally to places that can be occupied. I >> could claim that it is classical computer languages that confuse by >> restricting names to locations in a linear sequence. You are just used >> to the straightjacket ;-). > > In everyday life and natural languages, though an object may have many > names/aliases; once objects are assigned a name, it is practically > impossible to change the name to the object the name will be practically > stuck to it forever. When children play tag, the role of It is rebound to another child every few seconds. When adults play conference, the role of Speaker or Presenter is rebound to another person a few times per hour. In Python, it easy, perhaps too easy, to rebind built-in names, but it is usually a mistake. (Just yesterday there was a newbie post with that mistake.) It is common for global names to be bound just once (especially to functions and classes). In both human life and programming performed by humans, the time scale of name rebinding varies tremendously. Not surprising really. > In everyday life and natural languages, a single > name can be used to refer to multiple objects just by context without > referring any namespace. Namespace are contexts. They were (re)invented in programming just to make it easier to have single name could refer to different objects -- in different contexts. Names bound within a function are interpreted as being within the default local context without explicitly referring to it. Indeed, one cannot explicitly refer to the local namespace of functions, only to a dict copy thereof. > Let's not start making analogism between nature and silicon. There are several things wrong with this. You meant 'analogies'. I will make them when I want to, which is when I think they are useful in providing new viewpoints and insight. They are one way to break out of straight-jacketed or boxed thinking. If you prefer your box, ignore me. Silicon is a part of the natural world, and I was not making any such analogy. Python is an information processing and algorithm language, not a silicon programming language per se. And indeed, without a concept of 'address', it is not very suited to that. I *was* making an analogy between how we communicate informally about the natural and social worlds and how we communicate more formally about the abstract information world. Is it really surprising that we use the same psychological mechanisms? Silicon machine languages do not have names. And names, as used by humans, *are* the subject of discussion here. Dennis clained that Python is confusing because it is not restricted to naming locations. I said I could claim instead that it is the restriction is confusing. I did not go into that counterclaim, but indeed, many people who program in C, for instance, use C names as if they were object names instead of location names (or location,increment tuple names). Sometimes they even forget that they are really just location names. One too-common result of that confusion has been buffer overruns and virus programs that exploit them. These are impossible in Python. To me, the virtue of Python is that it allows one to think and write in a relatively natural named-object model. Let the silicon-based interpreter then translate that to a named-sequential-location model, while avoiding the dangers thereof, even though it has the cost of slower execution. Terry Jan Reedy From kirby.urner at gmail.com Mon Nov 30 15:51:25 2009 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 30 Nov 2009 12:51:25 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: <4B13F47E.3080706@aon.at> References: <4B13F47E.3080706@aon.at> Message-ID: I'm glad turtle graphics intersected my thinking re extended precision decimals (Decimal type) on edu-sig just now. I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod: http://www.4dsolutions.net/ocn/python/tmod.py (runnable source) http://www.flickr.com/photos/17157315 at N00/4147429781/ (GUI view) Here's the graphical output: http://www.flickr.com/photos/17157315 at N00/4148139184/in/photostream/ (Python 3.1) If you actually wanna fold the T, you need to snip off the cap and reverse it, per this diagram: http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html 120 of them, 60 folded left, 60 folded right, all of volume 1/24, make the volume 5 rhombic triacontahedron. http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html If you blow up the volume by 3/2, to 7.5, the radius becomes phi / sqrt(2) -- what we're showing with Decimals. The reason this seems unfamiliar is the unit of volume is the tetrahedron formed by any four equi-radiused balls in inter-tangency. I'm spinning this as Martian Math these days, yakking on math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et al. Kirby From dahl.joachim at gmail.com Mon Nov 30 15:52:26 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 12:52:26 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 Message-ID: I am updating an extension module from Python2.6 to Python3. I used to pass character codes to the extension module, for example, I would write: >>> foo('X') with the corresponding C extension routine defined as follows: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char foo; char *kwlist[] = {"foo", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) return NULL; ... In Python3.0 this also works, but in Python3.1 I get the following error: TypeError: argument 1 must be a byte string of length 1, not str and I seem to be supposed to write >>> foo(b'X') instead. From the Python C API, I have not been able to explain this new behavior. What is the correct way to pass a single character argument to Python3.1 extension modules? From dahl.joachim at gmail.com Mon Nov 30 16:04:39 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 13:04:39 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: Message-ID: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Obviously the name of the C function and the char variable cannot both be foo, so the C code should be: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char foochar; char *kwlist[] = {"foochar", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foochar)) return NULL; ... The question remains the same: why can't I pass a single character argument to this function under Python3.1? Thanks. Joachim On Nov 30, 9:52?pm, Joachim Dahl wrote: > I am updating an extension module from Python2.6 to Python3. > > I used to pass character codes to the extension module, for example, I > would write: > > >>> foo('X') > > with the corresponding C extension routine defined as follows: > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char foo; > ? char *kwlist[] = {"foo", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > ? ? return NULL; > ? ... > > In Python3.0 this also works, but in Python3.1 I get the following > error: > TypeError: argument 1 must be a byte string of length 1, not str > > and I seem to be supposed to write>>> foo(b'X') > > instead. From the Python C API, I have not been able to explain this > new behavior. > What is the correct way to pass a single character argument to > Python3.1 > extension modules? From falk at mauve.rahul.net Mon Nov 30 16:13:29 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 30 Nov 2009 21:13:29 +0000 (UTC) Subject: Python Programming Challenges for beginners? References: <09ea817f-57a9-44a6-b815-299ae3ce75d3@x5g2000prf.googlegroups.com> Message-ID: In article <09ea817f-57a9-44a6-b815-299ae3ce75d3 at x5g2000prf.googlegroups.com>, alex23 wrote: >On Nov 27, 1:24?pm, astral orange <457r0... at gmail.com> wrote: >> I would like to test out what I know so far by solving programming >> challenges. > >Project Euler can be a lot of fun: http://projecteuler.net/ Oooh, that *does* look like fun. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From falk at mauve.rahul.net Mon Nov 30 16:16:50 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 30 Nov 2009 21:16:50 +0000 (UTC) Subject: parsing json data References: Message-ID: There's a json parsing library in 2.6. (Sadly, 2.6 is not out for Ubuntu yet.) -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From casevh at gmail.com Mon Nov 30 16:19:20 2009 From: casevh at gmail.com (casevh) Date: Mon, 30 Nov 2009 13:19:20 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: On Nov 30, 1:04?pm, Joachim Dahl wrote: > Obviously the name of the C function and the char variable cannot both > be foo, > so the C code should be: > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char foochar; > ? char *kwlist[] = {"foochar", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > &foochar)) > ? ? return NULL; > ? ... > > The question remains the same: why can't I pass a single character > argument to this function under Python3.1? > > Thanks. > Joachim > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > > I am updating an extension module from Python2.6 to Python3. > > > I used to pass character codes to the extension module, for example, I > > would write: > > > >>> foo('X') > > > with the corresponding C extension routine defined as follows: > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > { > > ? char foo; > > ? char *kwlist[] = {"foo", NULL}; > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > ? ? return NULL; > > ? ... > > > In Python3.0 this also works, but in Python3.1 I get the following > > error: > > TypeError: argument 1 must be a byte string of length 1, not str > > > and I seem to be supposed to write>>> foo(b'X') > > > instead. From the Python C API, I have not been able to explain this > > new behavior. > > What is the correct way to pass a single character argument to > > Python3.1 > > extension modules?- Hide quoted text - > > - Show quoted text - Python 3.1 uses "c" (lowercase c) to parse a single character from a byte-string and uses "C" (uppercase c) to parse a single character from a Unicode string. I don't think there is an easy way to accept a character from both. HTH, casevh From jon at jonhaddad.com Mon Nov 30 16:34:12 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Mon, 30 Nov 2009 15:34:12 -0600 Subject: top-like behavior Message-ID: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> Is there a specific library used for displaying up to date consoles in the same way top behaves? Thanks in advance, Jon From tjreedy at udel.edu Mon Nov 30 16:35:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 16:35:12 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: Brad Harms wrote: > Well, yes, the names would have to be determined at run time. That's > what getattr and setattr do, except that that do it in the context of an > object rather than the local scope. However, I was under the impression > that python's mechanism for looking up local names was the same as the > mechanism used to look up attributes because names and attributes seem > to function pretty much the same way. This I assumed because of the > functionality of the locals() and globals() functions, which seem to act > like the __dict__ attribute on objects except that the work on the > current scope. The definition of locals() allows it to just be a dict *copy* of the local namespace, rather than the local namespace itself. Within functions, (at least for CPython, and probably for other implementations), locals() is just a copy, and changes to locals() are *not* propagated back to the local namespace. Within functions, local name 'lookup' has nothing to do with dict lookup. (It is more like list indexing.) From alfps at start.no Mon Nov 30 16:36:04 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 22:36:04 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: * Edward Cherlin: > On Sun, Nov 29, 2009 at 11:34, Brian Blais wrote: > >> After a bit of playing, I realized that I couldn't think of many exaples >> which use turtle with conditional structures (if- and while- statements), > > Repeat is used much more often. but of course we can provide examples > of any behavior you like. I like to use the turtle to generate > sequences, where I can use a conditional to stop when the turtle would > go off the screen. Fibonacci numbers, for example, or exponentials. > Similarly for spirals of various types. Simple cases like those are > easy to do in TA, while more complex sequences could use Python. There > are several fractal examples using loops provided with Sugar on a > Stick, including variations on Siepinksi constructions, and the Koch > Snowflake. In ch 2 of I use a turtle-generated spiral as the first example of a while loop. I haven't got that far yet with that chapter, but I halfway plan on including a turtle graphics solve-a-maze example, which would/will be an example of conditionals with the turtle as a kind of actor making decisions. >> or >> functions that return values, as opposed to "procedures" like: >> def square(length): >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) Plotting a graph. Some examples of that in ch 2 of aforementioned URL. Cheers & hth., - Alf From db3l.net at gmail.com Mon Nov 30 16:37:05 2009 From: db3l.net at gmail.com (David Bolen) Date: Mon, 30 Nov 2009 16:37:05 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: Esmail writes: > I dug around in the docs and found a named parameter that I can set > when I > call show. > > Definition: im.show(self, title=None, command=None) > > I installed irfanview and specified it/its path in the parameter, > but that didn't work either. It's really quite puzzling in the > case of Vista since that's been around for quite a few years now. But I thought everyone was sticking their fingers in their ears and humming to try to forget Vista had been released, particularly now that Windows 7 is out :-) Perhaps there's an issue with the temporary file location. I don't have a Vista system to test on, but the show() operation writes the image to a temporary file as returned by tempfile.mktemp(), and then passes the name on to the external viewer. The viewing command is handed to os.system() with the filename embedded without any special quoting. So if, for example, the temporary location has spaces or "interesting" characters, it probably won't get parsed properly. One easy debugging step is probably to add a print just before the os.system() call that views the image (bottom of _showxv function in Image.py in my copy of 1.1.6). That way at least you'll know the exact command being used. If that's the issue, there are various ways around it. You could patch PIL itself (same function) to quote the filename when it is constructing the command. Alternatively, the tempfile module has a tempdir global you could set to some other temporary directory before using the show() function (or any other code using tempfile). -- David From yoavglazner at gmail.com Mon Nov 30 16:38:25 2009 From: yoavglazner at gmail.com (Glazner) Date: Mon, 30 Nov 2009 13:38:25 -0800 (PST) Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: On Nov 30, 7:41?pm, Grant Edwards wrote: > On 2009-11-30, a b wrote: > > > I have a pain in the a** problem with pyserial- it works 90% > > of time but on the 10% of time it thorows and termios.error > > exception with the value (5, 'Input/output error') and i > > cannot get rid of it :( > > Sounds like faulty converter or a bug in the device driver to > me. > > > The system works as follows: > > A device sends out rs485 data -> rs485 to rs232 converter converts it - > >> an rs232->usb cable attatched to a computer reads the data. Until > > now it hasn't bothered me too much since it hasn't been a lot > > of data (every time i get this exception i unload the pl2303 > > module from kernel, then reload it, open the com port > > Does that get rid of the error? ?If so, then it's definitely a > problem with the converter or device-driver. > > > and hope it won't happen soon). But now the amount of data is > > getting bigger and the exceptions in the log are quite > > bothering already so if anyone has a good idea what could > > affect it i'd be very glad... oh and the settings for the port > > opening are: self.ser = serial.Serial(self.port, > > self.baudrate, rtscts=0, xonxoff=0, timeout=0) > > Unless you want to try to troubleshoot the device driver and > USB traffic, the only suggestion I have is to try different > converters and/or different versions of the driver. > > -- > Grant Edwards ? ? ? ? ? ? ? ? ? grante ? ? ? ? ? ? Yow! If Robert Di Niro > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? assassinates Walter Slezak, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?visi.com ? ? ? ? ? ?will Jodie Foster marry > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Bonzo?? Try to use Portmon to see if your data is sent correctly.(if not, then its the cable/converter) http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx or another port monitor tool for other OS. From tjreedy at udel.edu Mon Nov 30 16:47:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 16:47:49 -0500 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: W. eWatson wrote: > I think I understand it, but how does one prevent it from happening, or > know it's the cause? That msg I got? Yes. The message 'x is not callable', where x is a name of something you expect to be callable (such as the builtin functions and classes), signals that x has been rebound to a non-callable object. On the other hand, if x is something you know not to be callable, there there is either a typo -- yxz(3) instead of yzx[3] -- or a bug such as expr(arg) where you expect expr to evaluate to a function but it does not. Say yzx[3]('abc') where you think yxz is a list of functions, or yzx(3)('abc') where you expect yzx to return a function. tjr From tjreedy at udel.edu Mon Nov 30 17:00:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:00:47 -0500 Subject: Running function from win32 dll In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> Message-ID: Nadav Chernin wrote: > I want to run function from win32 dll. > I used ctypes.windll.LoadLibrary to load the DLL. > But I don?t know how to select function and run it. Which part of the Lib manual chapter did you not understand? From lists at cheimes.de Mon Nov 30 17:06:32 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 30 Nov 2009 23:06:32 +0100 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: Victor Subervi wrote: > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? You are confusing the permissions of a Unix file system. In order to create or a remove a file from a directory you need the x and w permission to enter the directory (x) and to modify (w) the directory entry. Christian From john at castleamber.com Mon Nov 30 17:07:26 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 22:07:26 GMT Subject: top-like behavior References: Message-ID: Jonathan Haddad wrote: > Is there a specific library used for displaying up to date consoles in > the same way top behaves? No experience but I am quite sure that curses behaves like that. http://www.amk.ca/python/howto/curses/ via http://www.google.com/search?q=python%20curses John From ben+python at benfinney.id.au Mon Nov 30 17:07:30 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 09:07:30 +1100 Subject: Characters in arithmetic expressions (was: semantics of ** (unexpected/inconsistent?)) References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <87hbsbpsyl.fsf_-_@benfinney.id.au> MRAB writes: > Most programming languages don't differentiate in text between the > number "negative 3" and the expression "negated 3". APL does. The > former is written as "?3" (3 preceded by the overscore character) and > the latter as "-3" (3 preceded by the minus sign). Well, since we're talking about special characters: the ?-? that we find on our keyboard is a hyphen (U+002D). A minus sign is ??? (U+2212) and is unlikely to be found on the keyboard unless it's a keyboard designed specifically for APL :-) -- \ ?A ?No? uttered from deepest conviction is better and greater | `\ than a ?Yes? merely uttered to please, or what is worse, to | _o__) avoid trouble.? ?Mahatma Gandhi | Ben Finney From necronymouse at gmail.com Mon Nov 30 17:14:31 2009 From: necronymouse at gmail.com (Necronymouse) Date: Mon, 30 Nov 2009 14:14:31 -0800 (PST) Subject: Bored. Message-ID: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Hello, I am learning python for about 2 years and I am bored. Not with python but I have a little problem, when i want to write something I realise that somebody had alredy written it! So i don?t want to make a copy of something but i wanna get better in python skills. Don?t you know what I should do? ---sorry for my english, I ?m from czech rep... From ben+python at benfinney.id.au Mon Nov 30 17:15:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 09:15:12 +1100 Subject: Language and collaboration (was: Python Statements/Keyword Localization) References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> Message-ID: <87d42zpslr.fsf_-_@benfinney.id.au> "Emanuele D'Arrigo" writes: > Ultimately I certainly appreciate the ubiquity of English even though > in the interest of fairness and efficiency I'd prefer the role of > common language to be given to a constructed language, such as Ido. I prefer Lojban as being logically robust while fully expressive, and sharing the Ido goal of avoiding disadvantage to native speakers of any particular existing language. > But it doesn't take a particularly religious person to see that "do to > others as you would want them do to you" tends to be a valid principle Indeed, religion is entirely redundant to that principle: one of the earliest independent expressions of that principle is from a quite non-religious philosopher. ?????????? (What is undesirable to you, do not do to others.) ???? Confucius, 551 BCE ? 479 BCE I prefer this formulation, since it doesn't enjoin to *do* something to others on the unproven assumption that someone else wants the same as me :-) -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From inhahe at gmail.com Mon Nov 30 17:15:17 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 17:15:17 -0500 Subject: Completely OT In-Reply-To: <4b141aa0@dnews.tpgi.com.au> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4b141aa0@dnews.tpgi.com.au> Message-ID: On Mon, Nov 30, 2009 at 2:17 PM, Lie Ryan wrote: > On 12/1/2009 5:00 AM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe ?wrote: >>> >>> On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >>> ?wrote: >>>> >>>> >>>> If I'm not mistaken, that won't help me actually print to screen the >>>> user's >>>> choices as he selects them, which in my application, is important. >>>> Please >>>> advise. > > That's where Javascript kicks in. You only need to use the javascript to > modify your document (visual effect); you won't need it to submit to the > server (the real action). > Oh yes, good point - even though (if he were still going to go the JavaScript route) he'd modify the textarea using javascript, a regular submit button could be used because it'll submit the current contents of that textarea all the same. >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Or a XSS attack (Cross-site scripting). Basically, you want to check whether > the string received by the server matches your own predefined list of colors > before storing to the database. > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Nov 30 17:16:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:16:11 -0500 Subject: Intro To Python Using Turtle Graphics In-Reply-To: References: Message-ID: Lawrence D'Oliveiro wrote: > Done by Northland Polytechnic, available for download under CC-BY-NC-ND here > . I have two problems with the presentation, which make things harder for the students than they should be. First, the instructor has students edit code in an editor that cannot directly run the code. Save the file. Click to a command window. Enter 'python somefile.py'. Ugh. Python comes with IDLE. Let students use it. (Or some equivalent, but turtle works fine with IDLE.) Replace above with 'press F5'. If there is a SyntaxError, not uncommon for students, the edit window comes back with the cursor near the spot of the foul. Within the code, the instructor does 'import turtle' followed by 'turtle.up', turtle.move(x,y)', etc. for tens of lines. Ugh. Either 'from turtle import *' (which turtle was designed for) or, if one does not like that, 'import turtle as t', some one can write 't.up', etc. There is also a echo glitch in the audio when the video comes from the monitor, as opposed to the room camera. Aside from the above, it seems like a decent intro presenting statements, names, conditional execution, repeated execution, and function encapsulation. tjr From john at castleamber.com Mon Nov 30 17:16:45 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 22:16:45 GMT Subject: parsing json data References: Message-ID: falk at mauve.rahul.net (Edward A. Falk) wrote: > There's a json parsing library in 2.6. (Sadly, 2.6 is not out for > Ubuntu yet.) Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 on Ubuntu 9.04 John From dahl.joachim at gmail.com Mon Nov 30 17:18:19 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 14:18:19 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: I think that "C" encoding is what I need, however I run into an odd problem. If I use the following C code static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char a, b; char *kwlist[] = {"a", "b", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, &b)) return NULL; ... then the following works: >>> foo('a') >>> foo('a','b') >>> foo(a='a',b='b') but the following fails: >>> foo(b='b') RuntimeError: impossible: 'CC' Is this error-message expected? On Nov 30, 10:19?pm, casevh wrote: > On Nov 30, 1:04?pm, Joachim Dahl wrote: > > > > > > > Obviously the name of the C function and the char variable cannot both > > be foo, > > so the C code should be: > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > { > > ? char foochar; > > ? char *kwlist[] = {"foochar", NULL}; > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > > &foochar)) > > ? ? return NULL; > > ? ... > > > The question remains the same: why can't I pass a single character > > argument to this function under Python3.1? > > > Thanks. > > Joachim > > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > I am updating an extension module from Python2.6 to Python3. > > > > I used to pass character codes to the extension module, for example, I > > > would write: > > > > >>> foo('X') > > > > with the corresponding C extension routine defined as follows: > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > { > > > ? char foo; > > > ? char *kwlist[] = {"foo", NULL}; > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > > ? ? return NULL; > > > ? ... > > > > In Python3.0 this also works, but in Python3.1 I get the following > > > error: > > > TypeError: argument 1 must be a byte string of length 1, not str > > > > and I seem to be supposed to write>>> foo(b'X') > > > > instead. From the Python C API, I have not been able to explain this > > > new behavior. > > > What is the correct way to pass a single character argument to > > > Python3.1 > > > extension modules?- Hide quoted text - > > > - Show quoted text - > > Python 3.1 uses "c" (lowercase c) to parse a single character from a > byte-string and uses "C" (uppercase c) to parse a single character > from a Unicode string. I don't think there is an easy way to accept a > character from both. > > HTH, > > casevh From inhahe at gmail.com Mon Nov 30 17:19:59 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 17:19:59 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <4b1417f6$1@dnews.tpgi.com.au> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> <4b1417f6$1@dnews.tpgi.com.au> Message-ID: On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan wrote: > On 12/1/2009 5:58 AM, inhahe wrote: >> >> i wasn't suggesting it as a feature for python, just pointing out why >> it might seem counterintuitive. > > I'm interested, what do YOU (inhahe) think the result should be? Should both > become -9 or both become 9. What was your expectation when you wrote that > post? > -- > http://mail.python.org/mailman/listinfo/python-list > i think the way it works currently is the sane way..pays respect to the standard order of operations, doesn't have to do anything special with x = -3, just treats it as an integer, and corresponds with normal algebra. From jlconlin at gmail.com Mon Nov 30 17:26:32 2009 From: jlconlin at gmail.com (Jeremy) Date: Mon, 30 Nov 2009 14:26:32 -0800 (PST) Subject: How to prevent re.split() from removing part of string Message-ID: I am using re.split to... well, split a string into sections. I want to split when, following a new line, there are 4 or fewer spaces. The pattern I use is: sections = re.split('\n\s{,4}[^\s]', lineoftext) This splits appropriately but I lose the character matched by [^s]. I know I can put parentheses around [^s] and keep the matched character, but the character is placed in it's own element of the list instead of with the rest of the lineoftext. Does anyone know how I can accomplish this without losing the matched character? Thanks, Jeremy From tjreedy at udel.edu Mon Nov 30 17:35:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:35:20 -0500 Subject: Trying to understand += better In-Reply-To: References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: Roy Smith wrote: > In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan > wrote: > >> The semantic of the in-place operator is something like: >> x += y >> becomes >> x = x.__iadd__(y) Except that the expression x is evaluated just once instead of twice. >> thus >> foo.bar += baz >> becomes >> foo.bar = foo.bar.__iadd__(baz) >> >> So the call sequence is, >> foo.__getattr__('bar') ==> x >> x.__iadd__(baz) ==> y >> foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. Augmented *ASSIGNMENT* is a type of assignment. The dis module can be used to see what CPython does. >>> from dis import dis >>> def f(): foo.bar += baz >>> dis(f) 2 0 LOAD_GLOBAL 0 (foo) 3 DUP_TOP 4 LOAD_ATTR 1 (bar) 7 LOAD_GLOBAL 2 (baz) 10 INPLACE_ADD 11 ROT_TWO 12 STORE_ATTR 1 (bar) ... This amounts to what Roy said, with x and y being temporary entries on the stack. Terry Jan Reedy From ebonak at gmail.com Mon Nov 30 17:48:45 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 14:48:45 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: On Nov 30, 4:37?pm, David Bolen wrote: > Esmail writes: > > I dug around in the docs and found a named parameter that I can set > > when I > > call show. > > > Definition: ? ? im.show(self, title=None, command=None) > > > I installed irfanview and specified it/its path in the parameter, > > but that didn't work either. It's really quite puzzling in the > > case of Vista since that's been around for quite a few years now. > > But I thought everyone was sticking their fingers in their ears and > humming to try to forget Vista had been released, particularly now > that Windows 7 is out :-) > > Perhaps there's an issue with the temporary file location. ?I don't > have a Vista system to test on, but the show() operation writes the > image to a temporary file as returned by tempfile.mktemp(), and then > passes the name on to the external viewer. ?The viewing command is > handed to os.system() with the filename embedded without any special > quoting. ?So if, for example, the temporary location has spaces or > "interesting" characters, it probably won't get parsed properly. > > One easy debugging step is probably to add a print just before the > os.system() call that views the image (bottom of _showxv function in > Image.py in my copy of 1.1.6). ?That way at least you'll know the > exact command being used. > > If that's the issue, there are various ways around it. ?You could > patch PIL itself (same function) to quote the filename when it is > constructing the command. ?Alternatively, the tempfile module has a > tempdir global you could set to some other temporary directory before > using the show() function (or any other code using tempfile). > > -- David Thanks for the pointers David, this will give me some things to investigate. As for me, I'm a long time and regular Linux user with some XP tossed in. I use the PIL under XP at times, but this problem is happening to someone I know who is using both Vista and Windows and can't get the basic thing to work so I am trying to help. (I have access to a Win 7 VM for testing purposes at least). If I find a work-around or fix or concrete cause I'll post. In the meantime if anyone has any other ideas or fixes/suggestions, please don't be shy :-) Thanks, Esmail From tjreedy at udel.edu Mon Nov 30 17:53:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:53:38 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > I don't know if anyone considers python's incomplete implementation of > closures a "feature" but it's documented so it's not really a bug > either. I believe Python's implementation of closures is quite complete in 3.x. In what way do you consider it otherwise? One just has to use the right syntax. Closures in Python are created by nested function definitions. Lambda expressions create functions just like def statements and are not closures and do not create closure unless nested within another function definition. Thinking otherwise is the OP's mistake. > I believe there is a trick with default arguments to get this > to work, but I don't use lambdas enough to remember it. One can simulate closures by giving an un-nested function a default argument. This has nothing to do with whether the function is defined by a lambda expression or a def statement. Terry Jan Reedy From python.list at tim.thechases.com Mon Nov 30 17:57:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Nov 2009 16:57:30 -0600 Subject: top-like behavior In-Reply-To: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> References: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> Message-ID: <4B144DDA.9040705@tim.thechases.com> > Is there a specific library used for displaying up to date consoles in > the same way top behaves? From the last time a similar question was asked[1]: You might look at the sourcecode for "iotop"[2] 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://www.mail-archive.com/python-list at python.org/msg234993.html [2] http://guichaz.free.fr/iotop/ From python at mrabarnett.plus.com Mon Nov 30 17:58:05 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Nov 2009 22:58:05 +0000 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B144DFD.7060507@mrabarnett.plus.com> Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not > with python but I have a little problem, when i want to write > something I realise that somebody had alredy written it! So i don?t > want to make a copy of something but i wanna get better in python > skills. Don?t you know what I should do? > Choose a project that you find interesting. It doesn't matter if someone has already done something similar because you'll learn more by doing. When you have something reasonable, compare it to the one that already exists. Your approach might be better, but if it's not then you can still see why it isn't and how you could improve. This way, when you do something that no-one else has done before, you'll have a better understanding of the language and how best to design and implement your project. From xiao at xiao-yu.com Mon Nov 30 17:58:12 2009 From: xiao at xiao-yu.com (Xiao) Date: Mon, 30 Nov 2009 14:58:12 -0800 (PST) Subject: PIL build error on Snow Leopard Message-ID: <785f1942-6aec-4a5a-934a-8db50648b1ae@e22g2000vbm.googlegroups.com> Hello, I haven't fully understood the nuances in the difference between Apple's system Python and MacPython. But I have just installed Python 2.6.4 from python.org. Now I'm trying to install a fresh downloaded PIL 1.1.6 but couldn't. python setup.py install gives: lipo: can't open input file: /var/tmp//ccfwpQd6.out (No such file or directory) Everything worked fine on Apple's Python 2.6.1 From jon at jonhaddad.com Mon Nov 30 17:59:12 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Mon, 30 Nov 2009 16:59:12 -0600 Subject: top-like behavior In-Reply-To: <4B144DDA.9040705@tim.thechases.com> References: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> <4B144DDA.9040705@tim.thechases.com> Message-ID: <6e8dae020911301459k48a973a0vc9a4ca4e4da10f2c@mail.gmail.com> Awesome. Thank you! Jon On Mon, Nov 30, 2009 at 4:57 PM, Tim Chase wrote: >> Is there a specific library used for displaying up to date consoles in >> the same way top behaves? > > From the last time a similar question was asked[1]: > > You might look at the sourcecode for "iotop"[2] 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://www.mail-archive.com/python-list at python.org/msg234993.html > > [2] > http://guichaz.free.fr/iotop/ > -- Jonathan Haddad http://www.rustyrazorblade.com From jgardner at jonathangardner.net Mon Nov 30 18:01:29 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 30 Nov 2009 15:01:29 -0800 (PST) Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: On Nov 30, 2:14?pm, Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > Generally, lower-level stuff is already written, but the web apps and desktop apps that use those lower-level apps need to be written. I suggest you pick up web dev or app dev in Python. There are a variety of frameworks. Think of an app you'd like to see, find a framework, and have fun. From tjreedy at udel.edu Mon Nov 30 18:21:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:21:09 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. Untrue. List() and [] happen to both evaluate to the same thing, an empty list. But there is no reason to expect list() and [] to always evaluate to the same thing. The docs for list() calls and [] displays and comprehensions are quite different. In particular, they clearly say that [x] interprets x as an item and creates a list with one item, x, while list(x) interprets x as an iterable, and creates a list with multiple items, the items of x. So. in particular, list([]) != [[]]. > For example "help([])" and "help(list())" point > to the same documentation. This has nothing to do with list(text) and [text]. [] evaluates to an instance that has no doc string, so help backs up to its class. Compare >>> help(1) Help on int object: ... The alternative to to print nothing, which would not be very helpful. Try >>> help() ... help> topics and you will see that there is a topic LISTLITERALS, though not one for comprehensions or sets or even generators. The list of topics seems not to have been kept up to date. Terry Jan Reedy From debatem1 at gmail.com Mon Nov 30 18:40:41 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 30 Nov 2009 18:40:41 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi wrote: > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> > wrote: >> >> >> >> >> >> If I'm not mistaken, that won't help me actually print to screen the >> >> user's >> >> choices as he selects them, which in my application, is important. >> >> Please >> >> advise. >> >> TIA, >> >> V >> > >> > >> > sure, that's where this part comes in: >> > >> > the javascript would populate the list for the colors the user selects >> > (the easiest way would probably be to give the list an id and use >> > getElementByID()) >> > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" >> > within the red element's tag, and then define a function blah(x) that >> > says >> > getElementById("my_list_id").innerHtml += "
    " + x; >> > and of course give your list textarea an id="my_list_id" attribute in >> > the tag. >> > >> > that could be slightly wrong, my javascript's rusty >> > >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Good call! However, in my case I can put this all behind a firewall. It's > only for the shop builder's use, and that's my client...whom I can track! > But I presume this would entail doing searches for and eliminating all > unnecessary characters, right? > V Don't homebrew these things, they're easy to screw up and disastrous to get wrong. Also, if you're worried about how secure something you've written is, you can give yourself a little peace of mind by running over it with some of the standard script kiddie tools before deployment. It'll at least give you the comfort of knowing that they won't be able to autopwn you for a while. Geremy Condra From tjreedy at udel.edu Mon Nov 30 18:40:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:40:42 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: Esmail wrote: > On Nov 30, 4:37 pm, David Bolen wrote: >> If that's the issue, there are various ways around it. You could >> patch PIL itself (same function) to quote the filename when it is >> constructing the command. Alternatively, the tempfile module has a >> tempdir global you could set to some other temporary directory before >> using the show() function (or any other code using tempfile). >> >> -- David > > Thanks for the pointers David, this will give me some things to > investigate. > As for me, I'm a long time and regular Linux user with some XP tossed > in. > I use the PIL under XP at times, but this problem is happening to > someone > I know who is using both Vista and Windows and can't get the basic > thing > to work so I am trying to help. (I have access to a Win 7 VM for > testing > purposes at least). > > If I find a work-around or fix or concrete cause I'll post. In the > meantime > if anyone has any other ideas or fixes/suggestions, please don't be > shy :-) How about forget PIL's show and its automagic behavior. Use PIL's image save to write the image to a nice, known location, such as C:/temp/pic.jgp -- nothing but alphanumerics + ':/.' Next test how to run a known external viewer from a command window. Then use os.system or subprocess to run it with the same command line. Package the two lines as a myshow(params) function. From rich at noir.com Mon Nov 30 18:47:18 2009 From: rich at noir.com (K. Richard Pixley) Date: Mon, 30 Nov 2009 15:47:18 -0800 Subject: emacs, pdb, python3, ubuntu Message-ID: Does anyone have this combination working? And if so, which version of ubuntu and what did you have to do to get it to work? --rich From rtomek at ceti.com.pl Mon Nov 30 18:48:56 2009 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Tue, 1 Dec 2009 00:48:56 +0100 (CET) Subject: Bored. In-Reply-To: <4B144DFD.7060507@mrabarnett.plus.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> <4B144DFD.7060507@mrabarnett.plus.com> Message-ID: Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not > with python but I have a little problem, when i want to write > something I realise that somebody had alredy written it! So i don?t > want to make a copy of something but i wanna get better in python > skills. Don?t you know what I should do? In other words, you would like to be creative? If this is the case, you must let your head out of the box. People coding for too long have the tendency to have a box (say, a cube) on their heads. I think there is plenty of ideas waiting for someone to turn them into code. Look out the window. Read a book. Repeat. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From debatem1 at gmail.com Mon Nov 30 18:51:05 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 30 Nov 2009 18:51:05 -0500 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: On Mon, Nov 30, 2009 at 5:14 PM, Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > > > ---sorry for my english, I ?m from czech rep... I'd find a big project and contribute to it. There's a lot more to being a developer than writing code, and its hard to learn much about that side of things by working on your own projects all the time. Plus, it can be very satisfying to make a widely used piece of software better. Geremy Condra From tjreedy at udel.edu Mon Nov 30 18:52:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:52:21 -0500 Subject: Language and collaboration In-Reply-To: <87d42zpslr.fsf_-_@benfinney.id.au> References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> <87d42zpslr.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > "Emanuele D'Arrigo" writes: > >> Ultimately I certainly appreciate the ubiquity of English even though >> in the interest of fairness and efficiency I'd prefer the role of >> common language to be given to a constructed language, such as Ido. > > I prefer Lojban as being logically robust > while fully expressive, and sharing the Ido goal of avoiding > disadvantage to native speakers of any particular existing language. Even though I an mative-English speaking and therefore advantaged with English becoming ubiquitous, I would not mind learning *one* artificial 'natural' language. I even considered Esperanto at one point. But the advocates of such a lingua franca cannot seem to agree on which ;-). (Ido? never heard of it before -- will check W.P). tjr From stef.mientki at gmail.com Mon Nov 30 18:52:24 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 01 Dec 2009 00:52:24 +0100 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B145AB8.10000@gmail.com> Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > > > ---sorry for my english, I ?m from czech rep... > Well I thought that after 2 years you would know every detail of a language ;-) A few ideas ( or better said the things that I'm still missing, and I guess every one can name a few different ones ) - PyJamas needs a lot of extensions - Simultanuous recording of camera and sound (and preferable other signals) is completely missing - Rich editor or ( embedding of open office) - a system-wide mind mapper - graphical design package a la LabView There's also a Python site, were projects are submitted that needs something ( some even pay a little), but I can't remember where it is :-( cheers, Stef From john at castleamber.com Mon Nov 30 18:58:55 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 23:58:55 GMT Subject: emacs, pdb, python3, ubuntu References: Message-ID: "K. Richard Pixley" wrote: > Does anyone have this combination working? > > And if so, which version of ubuntu and what did you have to do to get it > to work? I run Ubuntu 8.10 and use Emacs to code Python (mostly 2.5.x but I've done some small Python 3). What has Emacs to do with it? John From john at castleamber.com Mon Nov 30 19:02:31 2009 From: john at castleamber.com (John Bokma) Date: 1 Dec 2009 00:02:31 GMT Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: Stef Mientki wrote: > There's also a Python site, were projects are submitted that needs > something ( some even pay a little), > but I can't remember where it is :-( OP: A Python program to find it :D John From ben+python at benfinney.id.au Mon Nov 30 19:20:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 11:20:00 +1100 Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <87y6lno89b.fsf@benfinney.id.au> geremy condra writes: > On Mon, Nov 30, 2009 at 5:14 PM, Necronymouse wrote: > > Hello, I am learning python for about 2 years and I am bored. Not > > with python but I have a little problem, when i want to write > > something I realise that somebody had alredy written it! That's great news: it means you can learn by example, and also learn the more important skills of collaborating with other developers. > I'd find a big project and contribute to it. There's a lot more to > being a developer than writing code, and its hard to learn much about > that side of things by working on your own projects all the time. > Plus, it can be very satisfying to make a widely used piece of > software better. This is good advice. I would also say that it can be very satisfying contributing on a *small* project: there is usually less communication overhead since there are fewer people that need to communicate (the principles explored in ?The Mythical Man-Month?). On a small project, too, you can often have a bigger impact which for many people is more satisfying. So, in general: when you realise someone has already written something you want to use, then start using it! You will quickly find that it doesn't quite do everything you want, so that's your opportunity to make improvements and start working with the existing developers. -- \ ?Always code as if the guy who ends up maintaining your code | `\ will be a violent psychopath who knows where you live.? ?John | _o__) F. Woods | Ben Finney From stef.mientki at gmail.com Mon Nov 30 19:24:43 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 01 Dec 2009 01:24:43 +0100 Subject: Bored. In-Reply-To: References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B14624B.6020809@gmail.com> John Bokma wrote: > Stef Mientki wrote: > > >> There's also a Python site, were projects are submitted that needs >> something ( some even pay a little), >> but I can't remember where it is :-( >> > > OP: A Python program to find it :D > > that was the mind mapper I mentioned :-) Stef > John > From python at mrabarnett.plus.com Mon Nov 30 19:24:43 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 01 Dec 2009 00:24:43 +0000 Subject: How to prevent re.split() from removing part of string In-Reply-To: References: Message-ID: <4B14624B.7090902@mrabarnett.plus.com> Jeremy wrote: > I am using re.split to... well, split a string into sections. I want > to split when, following a new line, there are 4 or fewer spaces. The > pattern I use is: > > sections = re.split('\n\s{,4}[^\s]', lineoftext) > > This splits appropriately but I lose the character matched by [^s]. I > know I can put parentheses around [^s] and keep the matched character, > but the character is placed in it's own element of the list instead of > with the rest of the lineoftext. > > Does anyone know how I can accomplish this without losing the matched > character? > First of all, \s matches any character that's _whitespace_, such as space, "\t", "\n", "\r", "\f". There's also \S, which matches any character that's not whitespace. But in answer to your question, use a look-ahead: sections = re.split('\n {,4}(?=\S)', lineoftext) From gregor.lingl at aon.at Mon Nov 30 19:31:52 2009 From: gregor.lingl at aon.at (Gregor Lingl) Date: Tue, 01 Dec 2009 01:31:52 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: <4B13F47E.3080706@aon.at> Message-ID: <4B1463F8.2000902@aon.at> kirby urner schrieb: > I'm glad turtle graphics intersected my thinking re extended precision > decimals (Decimal type) on edu-sig just now. > > I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod: > > http://www.4dsolutions.net/ocn/python/tmod.py (runnable source) > http://www.flickr.com/photos/17157315 at N00/4147429781/ (GUI view) > Nice tiny app! Albeit not an example for using the if statement ;-) Just to show you how turtle.py enables you to implement this using quite different approaches to doing geometry, I'd like to add two more implementations. Besides you may notice that these do not rely on rather complicated calculations of distances and angles, using the Pythagorean theorem and trigonometrics but only on a few more fundamental properties of the figure. ##### Version 2 - using coordinate geometry without coordinates ;-) # a different implementation for Kirby's "Plane Net for T-module" from turtle import * from math import sqrt PHI = (sqrt(5)-1)/2 def planeNet(h=500): setup(560,560) title("Plane Net for T-module") penup() back(h/2); left(90); back(h/2); right(90) pendown() forward(h); left(90) forward(h*PHI); A = pos(); forward(h-h*PHI); left(90) forward(h*PHI); B = pos(); forward(h-h*PHI); left(90) forward(h); C = pos() for P in A, B, C: goto(P) ##### Version 3 - stamping simple transforms of the shape of ##### an isosceles rectangular triangle: from turtle import Screen, Turtle from math import sqrt GOLDEN_RATIO = (sqrt(5)-1)/2 def planeNet(h=500.0, phi=GOLDEN_RATIO): s = Screen(); s.setup(560,560); s.title("Plane Net for T-module") s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h))) designer = Turtle(shape="recttriangle") designer.color("black","") designer.penup() designer.goto(-h/2, h/2) for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)): designer.shapesize(width, height) designer.stamp() designer.forward(h) designer.right(90) designer.hideturtle() Hoping, you will find this a bit interesting, best regards Gregor > Here's the graphical output: > > http://www.flickr.com/photos/17157315 at N00/4148139184/in/photostream/ > (Python 3.1) > > If you actually wanna fold the T, you need to snip off the cap and > reverse it, per this diagram: > > http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html > > 120 of them, 60 folded left, 60 folded right, all of volume 1/24, make > the volume 5 rhombic triacontahedron. > > http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html > > If you blow up the volume by 3/2, to 7.5, the radius becomes phi / > sqrt(2) -- what we're showing with Decimals. > > The reason this seems unfamiliar is the unit of volume is the > tetrahedron formed by any four equi-radiused balls in inter-tangency. > > I'm spinning this as Martian Math these days, yakking on > math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et > al. > > Kirby > > From kirby.urner at gmail.com Mon Nov 30 19:52:09 2009 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 30 Nov 2009 16:52:09 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: <4B1463F8.2000902@aon.at> References: <4B13F47E.3080706@aon.at> <4B1463F8.2000902@aon.at> Message-ID: On Mon, Nov 30, 2009 at 4:31 PM, Gregor Lingl wrote: << fascinating code >> > > Hoping, you will find this a bit interesting, > best regards > > Gregor > Really enlightening, both mathematically and from a coding point of view. I hadn't used turtle.py enough yet to know about the built-in "context turtle" if you want to just say "forward" and forgo specifying a target. That's a nice Logo-ish touch. Your take on the T is most excellent. With your permission, I'd be happy to add both versions with attribution to my online version of tmod.py for the benefit of future students, and/or I could simply link to this post in the edu-sig archives (why not both?). Kirby -- >>> from mars import math http://www.wikieducator.org/Digital_Math From jorgeecardona at gmail.com Mon Nov 30 20:15:48 2009 From: jorgeecardona at gmail.com (Jorge Cardona) Date: Mon, 30 Nov 2009 20:15:48 -0500 Subject: Bored. In-Reply-To: <4B145AB8.10000@gmail.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> <4B145AB8.10000@gmail.com> Message-ID: <51d803a90911301715k6d2eaf21v934b9da62783b25f@mail.gmail.com> 2009/11/30 Stef Mientki : > Necronymouse wrote: >> >> Hello, I am learning python for about 2 years and I am bored. Not with >> python but I have a little problem, when i want to write something I >> realise that somebody had alredy written it! So i don?t want to make a >> copy of something but i wanna get better in python skills. Don?t you >> know what I should do? >> >> >> ---sorry for my english, I ?m from czech rep... >> > > Well I thought that after 2 years you would know every detail of a language > ;-) > > A few ideas ( or better said the things that I'm still missing, and I guess > every one can name a ?few different ones ) > - PyJamas needs a lot of extensions > - Simultanuous recording of ?camera and sound (and preferable other signals) > is completely missing > - Rich editor or ( embedding of open office) > - a system-wide mind mapper > - graphical design package a la LabView I had have a project in mind for several months, a compiler for Modelica language in python, there is actually two main approach, openmodelica and jmodelica, both free ( i don't remember the exactly licences), openmodelica is written in C++ and jmodelica has a front-end for python, but its core is java based. I had started a gtkmodelica project, in code google, with c++ and spirit library( i didn't find at the moment a good library like spirit in python), but developing in c++ is quite slow (but is really nice), and recently I found pyparsing, I think is a good tool for the parser, and i create a repo in github (is empty right now), i wish i could have the enough time right now, but i got a lot of work right now. A project like this has a lot of great challenges: parsing, differential equation solving, a lot about language semantics, the graphical tool could be like labview, simulink, or maplesim ( I love flowcanvas library for gtk in c++, but it is quite old right now), code generation (to use hardware in the loop), real time plotting, etc... it could be a great project. I'm using right now some python classes that works as wrapper for openmodelica, and i use numpy for optimization purpose, and it works great, but a more natural mix with a native python tool would be just fantastic. http://github.com/jorgeecardona/pymodelica http://drobilla.net/software/flowcanvas/ http://code.google.com/p/gtkmodelica/ http://www.jmodelica.org/ http://www.ida.liu.se/~pelab/modelica/OpenModelica.html > > There's also a Python site, were projects are submitted that needs something > ( some even pay a little), > but I can't remember where it is :-( > > cheers, > Stef > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jorge Eduardo Cardona jorgeecardona at gmail.com jorgeecardona.blogspot.com ------------------------------------------------ Linux registered user #391186 Registered machine #291871 ------------------------------------------------ From fearsomedragonfly at gmail.com Mon Nov 30 21:55:46 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Mon, 30 Nov 2009 18:55:46 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <87skc0zstu.fsf@benfinney.id.au> Message-ID: > Brad Harms FearsomeDragonfly at gmail.com > Mon Nov 30 05:04:37 CET 2009 > > That was a relatively simple example; classes as simple as the ones > generated by the It is more likely that the class generation could would > appear in a metaclass's class constructor or decorator function, and there > would be more than just the three attributes given. Bwa ha ha! Well, I managed to screw up that paragraph pretty badly. (I code better than I write, honest.) Let me try again: That was a relatively simple example; classes as simple as the ones generated by the factory function example given are not needed very often. It is more likely that the class generation would appear in a metaclass's class constructor or decorator function, and there would be more than just the three attributes. That way it could be possible to ADD those properties and methods to a class in the process of being built rather than make a class with just those attributes. Lie Ryan, I think I see what you're saying about using __dict__ to add members to a class, but it's not quite the same. __dict__ is only for attributes, NOT properties, methods, etc. which all come from the class of an object rather than the object's __dict__. Adding things to __dict__ would only work halfway; it wouldn't be very extensible. That's (one of the reasons) why the members have to be accessed as attributes rather than dict items. From gnarlodious at gmail.com Mon Nov 30 22:24:54 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 19:24:54 -0800 (PST) Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: > you probably need to change the encoding of sys.stdout >>> sys.stdout.encoding 'UTF-8' >> #!/usr/bin/python > do you know what python version, exactly, that gets called by this hashbang? Verified in HTTP: >>> print(sys.version) 3.1.1 Is is possible modules are getting loaded from my old Python? I symlinked to the new Python, and no I do not want to roll it back because it is work (meaning I would have to type "sudo"). ls /usr/bin/python lrwxr-xr-x 1 root wheel 63 Nov 20 21:24 /usr/bin/python -> /Library/ Frameworks/Python.framework/Versions/3.1/bin/python3.1 Ugh, I have not been able to program in 11 days. Now I remember doing it that way because I could not figure out how to get Apache to find the new Python. ls /usr/local/bin/python3.1 lrwxr-xr-x 1 root wheel 71 Nov 20 08:19 /usr/local/bin/python3.1 - > ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 So they are both pointing to the same Python. And yes, I would prefer easier http scripting, but don't know one. -- Gnarlie From aioe.org at technicalbloke.com Mon Nov 30 23:20:37 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 01 Dec 2009 04:20:37 +0000 Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: >> markolopa wrote: >> or >> whether you accidentally reused the same name without giving it a new >> value in the new loop. > > That is what I do regularly...8-> > Well really dude, you need to stop doing that. It's not a language problem, it's a memory problem (human not RAM!). You need to be aware of what you're putting into your namespace. This is one of the reasons people try to avoid using global variables, if you forget you've used a variable name and use it again somewhere you get an undefined state and hours of debugging / data loss / subtle corruptions you won't spot until the backups have all been cycled etc. I'm surprised you have a recurring problem with this really. My memory is terrible and I reuse variable names all over the place without any trouble. Maybe try keeping the length of your functions down so that they fit on a single screen and create and use a strong naming convention i.e. Long, descriptive variable names all_in_lower_case Function names all in CamelCase Global names are in ALL CAPS Loop variable names all prefixed with 'each_' The details don't so much matter as long as you are consistent with it. I'm sure many here would hate my coding conventions if they had to use them but they seem to work OK for me and I can't recall ever having this problem. Roger. From casevh at gmail.com Mon Nov 30 23:51:06 2009 From: casevh at gmail.com (casevh) Date: Mon, 30 Nov 2009 20:51:06 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: <83f08b89-6b61-4005-9fbd-c9a01da36654@d9g2000prh.googlegroups.com> On Nov 30, 2:18?pm, Joachim Dahl wrote: > I think that "C" encoding is what I need, however I run into an odd > problem. > If I use the following C code > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char a, b; > ? char *kwlist[] = {"a", "b", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, > &b)) > ? ? return NULL; > ? ... > > then the following works: > > >>> foo('a') > >>> foo('a','b') > >>> foo(a='a',b='b') > > but the following fails:>>> foo(b='b') > > RuntimeError: impossible: 'CC' > > Is this error-message expected? Nope. It appears to be a bug in Python. The format code 'C' is missing in the switch statement in skipitem() in getargs.c. I added "case 'C': /* int */" after "case 'c': /* char */" and then example worked for me. I'll open a bug report. casevh > > On Nov 30, 10:19?pm, casevh wrote: > > > On Nov 30, 1:04?pm, Joachim Dahl wrote: > > > > Obviously the name of the C function and the char variable cannot both > > > be foo, > > > so the C code should be: > > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > { > > > ? char foochar; > > > ? char *kwlist[] = {"foochar", NULL}; > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > > > &foochar)) > > > ? ? return NULL; > > > ? ... > > > > The question remains the same: why can't I pass a single character > > > argument to this function under Python3.1? > > > > Thanks. > > > Joachim > > > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > > I am updating an extension module from Python2.6 to Python3. > > > > > I used to pass character codes to the extension module, for example, I > > > > would write: > > > > > >>> foo('X') > > > > > with the corresponding C extension routine defined as follows: > > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > > { > > > > ? char foo; > > > > ? char *kwlist[] = {"foo", NULL}; > > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > > > ? ? return NULL; > > > > ? ... > > > > > In Python3.0 this also works, but in Python3.1 I get the following > > > > error: > > > > TypeError: argument 1 must be a byte string of length 1, not str > > > > > and I seem to be supposed to write>>> foo(b'X') > > > > > instead. From the Python C API, I have not been able to explain this > > > > new behavior. > > > > What is the correct way to pass a single character argument to > > > > Python3.1 > > > > extension modules?- Hide quoted text - > > > > - Show quoted text - > > > Python 3.1 uses "c" (lowercase c) to parse a single character from a > > byte-string and uses "C" (uppercase c) to parse a single character > > from a Unicode string. I don't think there is an easy way to accept a > > character from both. > > > HTH, > > > casevh > > From robert.kern at gmail.com Sun Nov 1 00:09:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 31 Oct 2009 23:09:05 -0500 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 10:35 PM, Robert Kern wrote: >> Peng Yu wrote: >> >>> I have defined 'long' in one of my previous message. I consider a file >>> long, when it does not fit in one or two screen. Basically, I want to >>> get a whole picture of the file after glancing of the file. >> I think you are going to have to get used to the fact that you have very >> strange personal preferences and that Python is designed for the vast >> majority of programmers who do not share them. > > So python would not be able to accommodate my preference one > class/function per file? I.e., I have to use something like 'from spam > import spam' or 'spam.spam()', or accept that the filename is not the > same as the class/function name. > > Inside test/__init__.py: > from a import A # class A from file a.py > from b import B # class B from file b.py If you are going to expose symbols in your __init__.py, they should not have the same name as any of the modules in the package. -- 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 tjreedy at udel.edu Sun Nov 1 00:28:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 01 Nov 2009 00:28:53 -0400 Subject: How to get the realpath of a symbolic link? In-Reply-To: <366c6f340910311248v60bd5e0nff79a90de942d84e@mail.gmail.com> References: <366c6f340910310003p632c087axeeb638aa0df08c56@mail.gmail.com> <366c6f340910311011h58ef9cecy882d561100aacac0@mail.gmail.com> <366c6f340910311248v60bd5e0nff79a90de942d84e@mail.gmail.com> Message-ID: Peng Yu wrote: > I find the following two files that define realpath. But I don't find > 'realpath' in os.py. I looked at 'os.py'. But I don't understand how > the function realpath is introduced in the name space in os.path. > Would you please let me know? > > gfind . ! -path '*backup*' -name "*.py" -type f -exec grep -n "def > realpath" {} \; -printf %p\\n\\n > 193:def realpath(path): > ./macpath.py > > 345:def realpath(filename): > ./posixpath.py That is where realpath is. From gagsl-py2 at yahoo.com.ar Sun Nov 1 00:38:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 01:38:16 -0300 Subject: import bug References: Message-ID: En Sat, 31 Oct 2009 12:12:21 -0300, kj escribi?: > I'm running into an ugly bug, which, IMHO, is really a bug in the > design of Python's module import scheme. The basic problem is that the "import scheme" was not designed in advance. It was a very simple thing at first. Then came packages. And then the __import__ builtin. And later some import hooks. And later support for zip files. And more import hooks and meta hooks. And namespace packages. And relative imports, absolute imports, and mixed imports. And now it's a mess. > Consider the following > directory structure: > [containing a re.py file in the same directory as the main script] > > If I now run the innocent-looking ham/spam.py, I get the following > error: > > % python26 ham/spam.py > Traceback (most recent call last): > [...] > File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in > __init__ > 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > My sin appears to be having the (empty) file ham/re.py. So Python > is confusing it with the re module of the standard library, and > using it when the inspect module tries to import re. Exactly; that's the root of your problem, and has been a problem ever since import existed. En Sat, 31 Oct 2009 13:27:20 -0300, kj escribi?: >> 2) this has been fixed in Py3 > > In my post I illustrated that the failure occurs both with Python > 2.6 *and* Python 3.0. Did you have a particular version of Python > 3 in mind? If the `re` module had been previously loaded (the true one, from the standard library) then this bug is not apparent. This may happen if re is imported from site.py, sitecustomize.py, any .pth file, the PYTHONSTARTUP script, perhaps other sources... The same error happens if ham\spam.py contains the single line: import smtpd, and instead of re.py there is an empty asyncore.py file; that fails on 3.1 too. En Sat, 31 Oct 2009 22:27:09 -0300, Steven D'Aprano escribi?: > On Sat, 31 Oct 2009 16:27:20 +0000, kj wrote: > >>> 1) it's a bad idea to name your own modules after modules in the stdlib >> >> Obviously, since it leads to the headaches this thread illustrates. But >> there is nothing intrisically wrong with it. The fact that it is >> problematic in Python is a design bug, plain and simple. There's no >> rational basis for it, > > Incorrect. Simplicity of implementation and API is a virtue, in and of > itself. The existing module machinery is quite simple to understand, use > and maintain. Uhm... module objects might be quite simple to understand, but module handling is everything but simple! (simplicity of implem...? quite simple to WHAT? ROTFLOL!!! :) ) > Dealing with name clashes doesn't come for free. If you > think it does, I encourage you to write a patch implementing the > behaviour you would prefer. I'd say it is really a bug, and has existed for a long time. One way to avoid name clashes would be to put the entire standard library under a package; a program that wants the standard re module would write "import std.re" instead of "import re", or something similar. Every time the std package is suggested, the main argument against it is backwards compatibility. > In addition, there are use-cases where the current behaviour is the > correct behaviour. Here's one way to backport (say) functools to older > versions of Python (untested): You still would be able to backport or patch modules, even if the standard ones live in the "std" package. En Sat, 31 Oct 2009 12:12:21 -0300, kj escribi?: > I've tried a lot of things to appease Python on this one, including > a liberal sprinkling of "from __future__ import absolute_import" > all over the place (except, of course, in inspect.py, which I don't > control), but to no avail. I think the only way is to make sure *your* modules always come *after* the standard ones in sys.path; try using this code right at the top of your main script: import sys, os.path if sys.argv[0]: script_path = os.path.dirname(os.path.abspath(sys.argv[0])) else: script_path = '' if script_path in sys.path: sys.path.remove(script_path) sys.path.append(script_path) (I'd want to put such code in sitecustomize.py, but sys.argv doesnt't exist yet at the time sitecustomize.py is executed) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:13:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:13:19 GMT Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> Message-ID: <02fd0755$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 14:12:40 -0400, Terry Reedy wrote: > alex23 wrote: >> Terry Reedy wrote: >>> alex23 wrote: >>>> You're completely wrong. Immutability has nothing to do with >>>> identity, > ... > > I'm honestly not getting your point here. > > Let me try again, a bit differently. > > I claim that the second statement, and therefor the first, can be seen > as wrong. I also claim that (Python) programmers need to understand why. > > In mathematics, we generally have immutable values whose 'identity' is > their value. There is, for example, only one, immutable, empty set. I think it's more than that -- I don't think pure mathematics makes any distinction at all between identity and equality. There are no instances at all, so you can't talk about individual values. It's not that the empty set is a singleton, because the empty set isn't a concrete object- with-existence at all. It's an abstraction, and as such, questions of "how many separate empty sets are there?" are meaningless. There are an infinite number of empty sets that differ according to their construction: The set of all American Presidents called Boris Nogoodnik. The set of all human languages with exactly one noun and one verb. The set of all fire-breathing mammals. The set of all real numbers equal to sqrt(-1). The set of all even prime numbers other than 2. The set of all integers between 0 and 1 exclusive. The set of all integers between 1 and 2 exclusive. The set of all positive integers between 2/5 and 4/5. The set of all multiples of five between 26 and 29. The set of all non-zero circles in Euclidean geometry where the radius equals the circumference. ... I certainly wouldn't say all fire-breathing mammals are integers between 0 and 1, so those sets are "different", and yet clearly they're also "the same" in some sense. I think this demonstrates that the question of how many different empty sets is meaningless -- it depends on what you mean by different and how many. > In informatics, and in particular in Python, in order to have > mutability, we have objects with value and an identity that is separate > from their value. I think you have this backwards. We have value and identity because of the hardware we use -- we store values in memory locations, which gives identity. Our universe imposes the distinction between value and identity. To simulate immutability and singletons is hard, and needs to be worked at. Nevertheless, it would be possible to go the other way. Given hypothetical hardware which only supported mutable singletons, we could simulate multiple instances. It would be horribly inefficient, but it could be done. Imagine a singleton-mutable-set implementation, something like this: class set: def __init__(id): return singleton def add(id, obj): singleton.elements.append((id, obj)) def __contains__(id, element) return (id, obj) in singleton.elements and so forth. You might notice that this is not terribly different from how one might define non-singleton sets. The difference being, Python sets have identity implied by storage in distinct memory locations, while this hypothetical singleton-set has to explicitly code for identity. > There can be, for example, multiple mutable empty > sets. Identity is important because we must care about which empty set > we add things to. 'Identity' is only needed because of 'mutability', so > it is mistaken to say they have nothing to do with each other. True, but it is not a mistake to say that identity and mutability are independent: there are immutable singletons, and mutable singletons, and immutable non-singletons, and mutable non-singletons. Clearly, knowing that an object is mutable doesn't tell you whether it is a singleton or not, and knowing it is a singleton doesn't tell you whether it is immutable or not. E.g. under normal circumstances modules are singletons, but they are mutable; frozensets are immutable, but they are not singletons. > Ideally, from both a conceptual and space efficiency view, an > implementation would allow only one copy for each value of immutable > classes. Ideally, from a complexity of implementation view, an implementation would allow an unlimited number of copies of each value of immutable classes. > This is what new programmers assume when they blithely use 'is' > instead of '==' (as would usually be correct in math). Nah, I think you're crediting them with far more sophistication than they actually have. I think most people in general, including many new programmers, simply don't have a good grasp of the conceptual difference between equality and identity. In plain language, "is" and its grammatical forms "be", "are", "am" etc. have many meanings: (1) Set membership testing: Socrates is a man. This is a hammer. (2) Existence: There is a computer language called Python. There is a monster under the bed. (3) Identity: Iron Man is Tony Stark. The butler is the murderer. (4) Mathematical equality: If x is 5, and y is 11, then y is 2x+1. (5) Equivalence: The winner of this race is the champion. The diameter of a circle is twice the radius. (6) Metaphoric equivalence: Kali is death. Life is like a box of chocolates. (7) Testing of state: My ankle is sore. Fred is left-handed. (8) Consequence If George won the lottery, he would say he is happy. (9) Cost A cup of coffee is $3. Only two of these usages work at all in any language I know of: equality and identity testing, although it would be interesting to consider a language that allowed type testing: 45 is an int -> returns True "abc" is a float -> returns False Some languages, like Hypertalk (by memory) and related languages, make "is" a synonym for equals. > However, for time efficiency reasons, there is no unique copy guarantee, > so one must use '==' instead of 'is', except in those few cases where > there is a unique copy guarantee, either by the language spec or by > one's own design, when one must use 'is' and not '=='. Here 'must' > means 'must to be generally assured of program correctness as intended'. > > We obviously agree on this guideline. Yes. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:34:40 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:34:40 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fd0c56$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: >>> In my question, module A and B exist just for the sake of >>> implementation. Even if I have module A and B, I don't want the user >>> feel the existence of module A and B. I want them feel exact like >>> class A and B are defined in module 'test' instead of feeling two >>> modules A and B are in package 'test'. >> >> >> Inside test/__init__.py: >> >> from A import A ?# class A from file A.py >> from B import B ?# class B from file B.py > > I can not use the above approach as I mentioned its problem in my > previous message. Either I have not seen it, or I have not understood it, but I don't understand why you can not use this approach. >> or better still: >> >> from a import A ?# class A from file a.py >> from b import B ?# class B from file b.py > > This artificially introduces the constraint that the file name can not > be the same as the class/function name. There is no constraint like this > if I can C++. It is not a constraint, it is a convention. You are free to ignore it if you like. Some people don't like writing "glob.glob" (for example). Some people would like to see Python ban modules with the same name as objects inside them, to avoid this error: >>> import datetime ... much later >>> from datetime import datetime >>> datetime.datetime() Traceback (most recent call last): File "", line 1, in AttributeError: type object 'datetime.datetime' has no attribute 'datetime' You seem to be inconsistent -- you say you want to name the file the same as the function in it, so you know which file to look for a function, but then you complain about writing: test.A.A so when we suggest naming A.py a.py, so you can write: test.a.A you complain about that too. Frankly, I think you are just complaining because Python isn't C++. >>> I know that module names should be in lower cases, in general. >>> However, it is OK to have the module name capitalized in this case >>> since the end users don't see them. >> >> Of course they do. > > This sentence is confusing. Can you spell out what you mean? If you supply a package test/ +-- __init__.py +-- A.py +-- B.py there is nothing stopping your users from doing this: import test.A as A import test.B as SomethingElse [...] > I have defined 'long' in one of my previous message. I consider a file > long, when it does not fit in one or two screen. Basically, I want to > get a whole picture of the file after glancing of the file. You must only write incredibly trivial programs then. There is more to understanding a program than understanding one single function. Any serious function will call other functions. To get the whole picture, you have to understand them too. Your requirement simply shifts the burden from "open one file, and read ten functions" to "open ten files, and read ten functions". -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:35:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:35:26 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> Message-ID: <02fd0c85$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote: > Many programmers I know stay away from 'lists' such as this, because > they are afraid to show their ignorance. Me, I'm fearless, and I have > learned a lot that I might not have otherwise. The only stupid question is the one you are afraid to ask. Good luck! -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:40:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:40:06 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> Message-ID: <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: >> Variables in a function are already private. ?How can the names in one >> function be affected by other functions in the same module? > > You misunderstood me. > > If there are multiple functions or classes in a file, when I change > variables in a function/class, I have to make sure that they are not in > other functions or classes. No you don't. def f(x): return x+1 def g(x): return x-1 If I choose to refactor f() and change "x" to "y", why do I care about the internal variable inside g()? Oh wait, I get it... you want to do a global search-and-replace over the entire file. *face-palm* If your functions are less than one-screen full, why do you need a global replacement? Global replacement risks changing words in docstrings, comments etc that it shouldn't. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:43:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:43:11 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> Message-ID: <02fd0e55$0$1326$c3e8da3@news.astraweb.com> On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: > So python would not be able to accommodate my preference one > class/function per file? Of course it does! You can do that RIGHT NOW -- just put one class per file. > I.e., I have to use something like 'from spam > import spam' or 'spam.spam()', How else do you expect to use the class if you don't import it? > or accept that the filename is not the > same as the class/function name. So let me see... You don't want to write "import spam; spam.spam()" You don't want to write "from spam import spam; spam()" You don't want to write "from Spam import spam; spam()" You don't want to write "from spam import Spam; Spam()" What exactly do you want? -- Steven From ben+python at benfinney.id.au Sun Nov 1 01:54:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 01 Nov 2009 16:54:12 +1100 Subject: Identifiers exposed by a package (was: How to import only one module in a package when the package __init__.py has already imports the modules?) References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> Message-ID: <87iqdux01n.fsf_-_@benfinney.id.au> Robert Kern writes: > If you are going to expose symbols in your __init__.py, they should > not have the same name as any of the modules in the package. Would I be correct in assuming you make an exception for the package importing one of the modules in the package, and thereby making that module's identifier exposed? package_foo/ __init__.py module_bar.py $ cat foo/__init__.py import module_bar Now the name ?package_foo.module_bar? will get the identifier already assigned within ?package_foo/__init__.py?, but that identifier is the module anyway. -- \ ?We demand rigidly defined areas of doubt and uncertainty!? | `\ ?Vroomfondel, _The Hitch-Hiker's Guide To The Galaxy_, Douglas | _o__) Adams | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 01:54:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 05:54:15 GMT Subject: import bug References: Message-ID: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: >> Incorrect. Simplicity of implementation and API is a virtue, in and of >> itself. The existing module machinery is quite simple to understand, >> use and maintain. > > Uhm... module objects might be quite simple to understand, but module > handling is everything but simple! (simplicity of implem...? quite > simple to WHAT? ROTFLOL!!! ) I stand corrected :) Nevertheless, the API is simple: the first time you "import name", Python searches a single namespace (the path) for a module called name. There are other variants of import, but the basics remain: search the path for the module called name, and do something with the first one you find. >> Dealing with name clashes doesn't come for free. If you think it does, >> I encourage you to write a patch implementing the behaviour you would >> prefer. > > I'd say it is really a bug, and has existed for a long time. Since import is advertised to return the first module with the given name it finds, I don't see it as a bug even if it doesn't do what the programmer intended it to do. If I do this: >>> len = 1 >>> def parrot(s): ... print len(s) ... >>> parrot("spam spam spam") Traceback (most recent call last): File "", line 1, in File "", line 2, in parrot TypeError: 'int' object is not callable it isn't a bug in Python that I have misunderstood scopes and inadvertently shadowed a builtin. Shadowing a standard library module is no different. > One way to > avoid name clashes would be to put the entire standard library under a > package; a program that wants the standard re module would write "import > std.re" instead of "import re", or something similar. Every time the std > package is suggested, the main argument against it is backwards > compatibility. You could do it in a backwards compatible way, by adding the std package directory into the path. -- Steven From ldo at geek-central.gen.new_zealand Sun Nov 1 01:08:00 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Nov 2009 19:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> In message , Carsten >> Haese wrote: >> >>> Lawrence D'Oliveiro wrote: >>> >>>> In message , >>>> Dennis Lee Bieber wrote: >>>> >>>>> This way regular string interpolation operations (or whatever Python >>>>> 3.x has replaced it with) are safe to construct the SQL, leaving only >>>>> user supplied (or program generated) data values to be passed via the >>>>> DB-API parameter system -- so that they are properly escaped and >>>>> rendered safe. >>>> >>>> Mixing the two is another recipe for confusion and mistakes. >>> >>> Mixing the two is necessary. >>> ... >>> As long as you understand what you're doing, there should be no >>> confusion. (And if you don't understand what you're doing, you shouldn't >>> be doing it!) >> >> But if you understand what you're doing, you don't need to mix the two. > > On what grounds are you asserting that it's not necessary to mix the > two? Please elaborate your point. On the grounds that Python has more general and powerful string parameter- substitution mechanisms than anything built into any database API. From robert.kern at gmail.com Sun Nov 1 01:41:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 01:41:52 -0500 Subject: Identifiers exposed by a package In-Reply-To: <87iqdux01n.fsf_-_@benfinney.id.au> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <366c6f340910312054obc50442xc7fe671e3c7bd1c@mail.gmail.com> <87iqdux01n.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > Robert Kern writes: > >> If you are going to expose symbols in your __init__.py, they should >> not have the same name as any of the modules in the package. > > Would I be correct in assuming you make an exception for the package > importing one of the modules in the package, and thereby making that > module's identifier exposed? > > package_foo/ > __init__.py > module_bar.py > > $ cat foo/__init__.py > import module_bar > > Now the name ?package_foo.module_bar? will get the identifier already > assigned within ?package_foo/__init__.py?, but that identifier is the > module anyway. Yes. -- 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 saketh.bhamidipati at gmail.com Sun Nov 1 02:06:50 2009 From: saketh.bhamidipati at gmail.com (Saketh) Date: Sun, 1 Nov 2009 00:06:50 -0700 (PDT) Subject: Pyfora, a place for python Message-ID: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Hi everyone, I am proud to announce the release of Pyfora (http://pyfora.org), an online community of Python enthusiasts to supplement comp.lang.python and #python. While the site is small right now, please feel free to register and post any questions or tips you may have. If you have any suggestions, let me know -- this is a community effort! Sincerely, Saketh (username:catechu) From gagsl-py2 at yahoo.com.ar Sun Nov 1 02:13:22 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 04:13:22 -0300 Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> Message-ID: En Fri, 30 Oct 2009 17:55:27 -0300, Jess Austin escribi?: > On Oct 29, 10:41 pm, "Gabriel Genellina" > wrote: >> We know the last test fails because the == logic fails to recognize >> mySet (on the right side) as a "more specialized" object than frozenset >> (on the left side), because set and frozenset don't have a common base >> type (although they share a lot of implementation) >> >> I think the only way would require modifying tp_richcompare of >> set/frozenset objects, so it is aware of subclasses on the right side. >> Currently, frozenset() == mySet() effectively ignores the fact that >> mySet is a subclass of set. > > I don't think even that would work. By the time set_richcompare() is > called (incidentally, it's used for both set and frozenset), it's too > late. That function is not responsible for calling the subclass's > method. It does call PyAnySet_Check(), but only to short-circuit > equality and inequality for non-set objects. I believe that something > higher-level in the interpreter decides to call the right-side type's > method because it's a subclass of the left-side type, but I'm not > familiar enough with the code to know where that happens. It may be > best not to sully such generalized code with a special case for > this. > > I may do some experiments with bytes, str, and unicode, since that > seems to be an analogous case. There is a basestring type, but at > this point I don't know that it really helps with anything. Looks like in 3.1 this can be done with bytes+str and viceversa, even if bytes and str don't have a common ancestor (other than object; basestring doesn't exist in 3.x): p3> Base = bytes p3> Other = str p3> p3> class Derived(Base): ... def __eq__(self, other): ... print('Derived.__eq__') ... return True ... p3> Derived()==Base() Derived.__eq__ True p3> Base()==Derived() Derived.__eq__ True p3> Derived()==Other() Derived.__eq__ True p3> Other()==Derived() Derived.__eq__ # !!! True p3> Base.mro() [, ] p3> Other.mro() [, ] The same example with set+frozenset (the one you're actually interested in) doesn't work, unfortunately. After further analysis, this works for bytes and str because both types refuse to guess and compare to each other; they return NotImplemented when the right-side operand is not of the same type. And this gives that other operand the chance of being called. set and frozenset, on the other hand, are promiscuous: their tp_richcompare slot happily accepts any set of any kind, derived or not, and compares their contents. I think it should be a bit more strict: if the right hand side is not of the same type, and its tp_richcompare slot is not the default one, it should return NotImplemented. This way the other type has a chance to be called. -- Gabriel Genellina From gu.yakahughes at gmail.com Sun Nov 1 02:37:44 2009 From: gu.yakahughes at gmail.com (KillSwitch) Date: Sun, 1 Nov 2009 00:37:44 -0700 (PDT) Subject: stdin in embedded python Message-ID: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> I have a C++ program, with a GUI, into which I have embedded python. I have made several python functions in C++, one of which I use to override the normal stdout and stderr so that they print to a text box of my GUI. One thing I cannot think of how to do is to redefine stdin so that it pauses the program, waits for a user to type input into the box, hit enter, and takes input from another text element and sends it to python like it was the console. I wonder if anyone could help me in trying to do such a thing. To simplify, the new stdin should wait for the C++ function to give it a value, like it waits for the console. From http Sun Nov 1 02:48:16 2009 From: http (Paul Rubin) Date: 01 Nov 2009 00:48:16 -0700 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <7xpr82y9bz.fsf@ruckus.brouhaha.com> Saketh writes: > I am proud to announce the release of Pyfora (http://pyfora.org), an > online community of Python enthusiasts to supplement comp.lang.python > and #python. And the reason to want to further fragment Python discussion is exactly what? From carsten.haese at gmail.com Sun Nov 1 03:09:25 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 01 Nov 2009 03:09:25 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: >> On what grounds are you asserting that it's not necessary to mix the >> two? Please elaborate your point. > > On the grounds that Python has more general and powerful string parameter- > substitution mechanisms than anything built into any database API. That statement is fundamentally flawed. You are assuming that the preferred way of getting a value into a query is by substituting a literal into the query string. That is, in general, not true, because that would be horribly inefficient. This is also why I despise the term "parameter substitution", since it implies incorrectly that passing parameters to a query is merely a string formatting exercise. The correct term is "parameter binding." Most databases actually provide an API for supplying parameters separately from the query string. This is more efficient, because it eliminates the need to render the parameter value into a literal form on the client side and to parse the literal form on the server side. Also, it allows the engine to perform the same query multiple times with different values without having to re-parse the query. Finally, you're assuming that every value that can be supplied to a query actually HAS a literal form. That is not true. For example, in Informix databases, there are no literals for BYTE-type values. (You'd probably call them blobs.) So, if vomiting literals into the query string were your only way of conveying values to the database, you'd never be able to populate a BYTE column on an Informix database. The only way to pass a BYTE value to an Informix database is by parameter binding. Since parameter binding is in general much more than string substitution, it is indeed necessary to mix the two. -- Carsten Haese http://informixdb.sourceforge.net From gklein at xs4all.nl Sun Nov 1 03:36:33 2009 From: gklein at xs4all.nl (Gertjan Klein) Date: Sun, 01 Nov 2009 09:36:33 +0100 Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> Message-ID: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Alf P. Steinbach wrote: >So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >file, or 'open' doesn't conform to the documentation. It does read beyond the end of file. This is perhaps the way the underlying C library works, but it looks like an "unexpected feature" (read: bug) to me. I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after creating an empty (0-byte) test file; after the write() the read() returns random garbage. I can't imagine why anyone would want that behaviour. The file grew to be 4099 bytes after f.close(). I wrote 'hello' to it, so the length of garbage added was 4094 bytes, which I find a strange number also. I would have expected the read to return nothing. Can anyone explain or even defend this behaviour? Gertjan. From ben+python at benfinney.id.au Sun Nov 1 03:44:10 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 01 Nov 2009 19:44:10 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <87my36my79.fsf@benfinney.id.au> Saketh writes: > If you have any suggestions, let me know -- this is a community > effort! Suggestion: Please don't make efforts to fragment the community. Rather, please direct seekers to the existing forums (the IRC channel, the Usenet groups and mailing lists) rather than setting up new walled gardens. -- \ ?None can love freedom heartily, but good men; the rest love | `\ not freedom, but license.? ?John Milton | _o__) | Ben Finney From alfps at start.no Sun Nov 1 04:44:45 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 10:44:45 +0100 Subject: problem with read() write() In-Reply-To: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: * Gertjan Klein: > Alf P. Steinbach wrote: > >> So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >> file, or 'open' doesn't conform to the documentation. > > It does read beyond the end of file. This is perhaps the way the > underlying C library works, but it looks like an "unexpected feature" > (read: bug) to me. > > I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after > creating an empty (0-byte) test file; after the write() the read() > returns random garbage. I can't imagine why anyone would want that > behaviour. The file grew to be 4099 bytes after f.close(). I wrote > 'hello' to it, so the length of garbage added was 4094 bytes, which I > find a strange number also. Could you post (copy and paste) the code, and description of results? > I would have expected the read to return nothing. Can anyone explain or > even defend this behaviour? I'm just a Python newbie, but in C and C++ such things are usually down to "undefined behavior", that is, the program doing something that is implicitly or explicitly defined as undefined behavior by the language standard. With UB the effect may then be something or nothing or anything or just what you expected; appearance of the infamous nasal demons is one possibility... Quoting n869, which is the January 18th 1999 draft of the C99 standard: ?7.19.5.3/6 When a file is opened with update mode (?+? as the second or third character in the above list of mode argument values), both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, fsetpos, or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file. Opening( or creating) a text file with update mode may instead open (or create) a binary stream in some implementations. "Shall not" means UB. This applies to C "FILE*" handling. AFAICS nothing except efficiency prevents the Python wrapper, if "FILE*" is what it uses, from automatically inserting an appropriate fflush or fseek. And for a language used by so many newbies (this is positive!) I agree that it should ideally get rid of that UB (assuming that's what the problem is), or, if it doesn't already, mention that in the Python documentation. Cheers, - Alf From rschroev_nospam_ml at fastmail.fm Sun Nov 1 05:38:39 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 01 Nov 2009 11:38:39 +0100 Subject: python os.path.exists failure In-Reply-To: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> References: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> Message-ID: koranthala schreef: > Hi all, > My code is as follows: > > path = r'C:/"Program Files"/testfolder/2.3/test.txt' > if os.path.lexists(path): > print 'Path Exists' > else: > print 'No file found in path - %s' %path > print Popen(path, stdout=PIPE, shell=True).stdout.read() > > The output comes as > No file found in path - C:/"Program Files"/testfolder/2.3/test.txt > but the test.txt file is opened. > > The issue, I guess, is that the double quotes inside is failing the > check. But without the double quotes, Popen fails. > One solution, I can think is to check without double quotes, and then > using some code, put the double quotes back inside, but it looks quite > kludgy. You can put the double quotes around the whole path instead of just around "Program Files" in the call to Popen(). The issue here is actually that os.path.exists() (and all other Python functions) use the path exactly like you pass it; but with your call to Popen(), the path is passed as an argument to the shell, and it needs to be quoted for the shell to interpret that correctly. So here's what I would do: first specify the path literally without quotes, and quote it only when needed: path = r'C:/Program Files/testfolder/2.3/test.txt' if os.path.lexists(path): print 'Path Exists' else: print 'No file found in path - %s' %path print Popen('"%s"' % path, stdout=PIPE, shell=True).stdout.read() Some other notes: - Since you use forward slashes, there's no need to use a raw string literal. - You can just as well use os.path.exists() instead of os.path.lexists(). The difference has to do with symbolic links, which Windows doesn't have. - I'm not sure what you expect the line with Popen to do. On my system, it opens the specified text file in notepad and returns an empty string. If that's what you want to do, it's easier with os.startfile(). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From gklein at xs4all.nl Sun Nov 1 06:07:03 2009 From: gklein at xs4all.nl (Gertjan Klein) Date: Sun, 01 Nov 2009 12:07:03 +0100 Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: Alf P. Steinbach wrote: >* Gertjan Klein: >> I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after >> creating an empty (0-byte) test file; after the write() the read() >> returns random garbage. I can't imagine why anyone would want that >> behaviour. The file grew to be 4099 bytes after f.close(). I wrote >> 'hello' to it, so the length of garbage added was 4094 bytes, which I >> find a strange number also. > >Could you post (copy and paste) the code, and description of results? The code is exactly the OP's code, with an f.close() after f.read(). The results are described above. >"Shall not" means UB. This applies to C "FILE*" handling. Yes. But Python is not C. I would have expected that Python shields me from such bizarre results. The fact that, apparently, the Python file object is a thin wrapper over a C library function is an explanation of the behaviour, but not a justification. >And for a language used by so many newbies (this is positive!) I agree that it >should ideally get rid of that UB (assuming that's what the problem is), or, if >it doesn't already, mention that in the Python documentation. I'm not sure I can defend this statement, but I think Python should not have undefined behaviour at all. Gertjan. From mnordhoff at mattnordhoff.com Sun Nov 1 06:17:25 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sun, 01 Nov 2009 11:17:25 +0000 Subject: problem with read() write() In-Reply-To: <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: <4AED6E45.9080000@mattnordhoff.com> Gertjan Klein wrote: > Alf P. Steinbach wrote: > >> So with 'w+' the only way to get garbage is if 'read' reads beyond the end of >> file, or 'open' doesn't conform to the documentation. > > It does read beyond the end of file. This is perhaps the way the > underlying C library works, but it looks like an "unexpected feature" > (read: bug) to me. > > I reproduced (with Python 2.5.2 on WinXP) the code the OP wrote after > creating an empty (0-byte) test file; after the write() the read() > returns random garbage. I can't imagine why anyone would want that > behaviour. The file grew to be 4099 bytes after f.close(). I wrote > 'hello' to it, so the length of garbage added was 4094 bytes, which I > find a strange number also. > > I would have expected the read to return nothing. Can anyone explain or > even defend this behaviour? > > Gertjan. I wonder, does it still happen if you open the file in binary mode? (Stick a "b" in the file mode.) It could be some Windows text mode craziness. -- From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 06:29:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 11:29:24 GMT Subject: problem with read() write() References: <607b20de-5105-4009-8ac1-72f2de70f609@d5g2000yqm.googlegroups.com> <36577412-1187-4ed7-8bc2-45761f8a2a15@g23g2000yqh.googlegroups.com> <9ehqe5pk1so6ce7rgrmcj8vd3td7ue0pqq@4ax.com> Message-ID: <02fd5f79$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 10:44:45 +0100, Alf P. Steinbach wrote: > Could you post (copy and paste) the code, and description of results? Using Python 2.6 under Linux (Fedora 7): >>> f = open('garbage', 'r') # prove the file doesn't exist Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'garbage' >>> f = open('garbage', 'wb+') >>> f.read(4) '' >>> f.write('hello world\n') >>> f.seek(0) >>> f.read(100) 'hello world\n' -- Steven From cousinstanley at gmail.com Sun Nov 1 08:23:25 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 1 Nov 2009 13:23:25 +0000 (UTC) Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: > .... > There are an infinite number of empty sets > that differ according to their construction: > .... > The set of all fire-breathing mammals. > .... Apparently, you have never been a witness to someone who recently ingested one of Cousin Chuy's Super-Burritos .......... :-) -- Stanley C. Kitching Human Being Phoenix, Arizona From davea at ieee.org Sun Nov 1 08:34:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 08:34:31 -0500 Subject: stdin in embedded python In-Reply-To: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: <4AED8E67.1060809@ieee.org> KillSwitch wrote: > I have a C++ program, with a GUI, into which I have embedded python. I > have made several python functions in C++, one of which I use to > override the normal stdout and stderr so that they print to a text box > of my GUI. One thing I cannot think of how to do is to redefine stdin > so that it pauses the program, waits for a user to type input into the > box, hit enter, and takes input from another text element and sends it > to python like it was the console. > > I wonder if anyone could help me in trying to do such a thing. To > simplify, the new stdin should wait for the C++ function to give it a > value, like it waits for the console. > > I suspect you don't really want to redirect stdin, but instead implement raw_input(). If you have control over the script, just change it from raw_input() to cpp_raw_input(). But if you need to be able to run arbitrary scripts, ... (untried) - Try changing __builtins__.raw_input to reference your new function. DaveA From pengyu.ut at gmail.com Sun Nov 1 09:07:37 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:07:37 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0c56$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <02fd0c56$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010607h14b6dd60he2783e5370b38034@mail.gmail.com> On Sat, Oct 31, 2009 at 11:34 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:29:12 -0500, Peng Yu wrote: > >>>> In my question, module A and B exist just for the sake of >>>> implementation. Even if I have module A and B, I don't want the user >>>> feel the existence of module A and B. I want them feel exact like >>>> class A and B are defined in module 'test' instead of feeling two >>>> modules A and B are in package 'test'. >>> >>> >>> Inside test/__init__.py: >>> >>> from A import A ?# class A from file A.py >>> from B import B ?# class B from file B.py >> >> I can not use the above approach as I mentioned its problem in my >> previous message. > > Either I have not seen it, or I have not understood it, but I don't > understand why you can not use this approach. The problem is when you test a package you want to 'import test.A' rather than 'import test'. Having such __init__.py does not allow you to import only 'test.A'. This cause artificial dependence. >>> or better still: >>> >>> from a import A ?# class A from file a.py >>> from b import B ?# class B from file b.py >> >> This artificially introduces the constraint that the file name can not >> be the same as the class/function name. There is no constraint like this >> if I can C++. > > It is not a constraint, it is a convention. You are free to ignore it if > you like. I'm ignoring this convention now. But I have to call a function like glob.glob, which I also feel inconvenient. > Some people don't like writing "glob.glob" (for example). Some people > would like to see Python ban modules with the same name as objects inside > them, to avoid this error: > >>>> import datetime > ... much later >>>> from datetime import datetime >>>> datetime.datetime() > Traceback (most recent call last): > ?File "", line 1, in > AttributeError: type object 'datetime.datetime' has no attribute > 'datetime' > > > You seem to be inconsistent -- you say you want to name the file the same > as the function in it, so you know which file to look for a function, but > then you complain about writing: > > test.A.A > > so when we suggest naming A.py a.py, so you can write: > > test.a.A > > you complain about that too. Frankly, I think you are just complaining > because Python isn't C++. I'm not complaining. I just wish there is a walkaround. In C++, I still have to write some script to make sure the directory hierarchy is consistent with the namespace, because C++ doesn't impose the constraint that the directory hierarchy is the same as the namespace. But it seems that is no such walkaround in python for my case, because python binds namespace to directory hierarchy. >>>> I know that module names should be in lower cases, in general. >>>> However, it is OK to have the module name capitalized in this case >>>> since the end users don't see them. >>> >>> Of course they do. >> >> This sentence is confusing. Can you spell out what you mean? > > If you supply a package > > test/ > +-- ?__init__.py > +-- ?A.py > +-- ?B.py > > > there is nothing stopping your users from doing this: > > import test.A as A > import test.B as SomethingElse First, this is a redudancy---'A' appears twice. Second, you can not do something like the following, because name A from the two name space is conflict. import test.A as A import test2.A as A > [...] >> I have defined 'long' in one of my previous message. I consider a file >> long, when it does not fit in one or two screen. Basically, I want to >> get a whole picture of the file after glancing of the file. > > You must only write incredibly trivial programs then. > > There is more to understanding a program than understanding one single > function. Any serious function will call other functions. To get the > whole picture, you have to understand them too. Your requirement simply > shifts the burden from "open one file, and read ten functions" to "open > ten files, and read ten functions". I insist on having screen long functions or classes, because they have less number of states compare with long ones. This allows me to test all the states of them to make sure they are bug free. It is reasonable to assume the log of the number of states of a function or a class is proportional to it length. Hence, when a function or a class is long, you will never be able to test all its states. I don't have to put all related functions in a single file. With vim and ctags, you should be able to jump to the definition of any function or class from the place where it is used. So putting single class/function in a file does not give me any extra 'burden' than if I put them in the same file. From mwilson at the-wire.com Sun Nov 1 09:11:26 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 01 Nov 2009 09:11:26 -0500 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > (6) Metaphoric equivalence: > Kali is death. > Life is like a box of chocolates. OK to here, but this one switches between metaphor and simile, and arguably, between identity and equality. Mel. From pengyu.ut at gmail.com Sun Nov 1 09:13:11 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:13:11 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0e55$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <02fd0e55$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: > >> So python would not be able to accommodate my preference one >> class/function per file? > > Of course it does! You can do that RIGHT NOW -- just put one class per > file. > >> I.e., I have to use something like 'from spam >> import spam' or 'spam.spam()', > > How else do you expect to use the class if you don't import it? > > >> or accept that the filename is not the >> same as the class/function name. > > So let me see... > > You don't want to write "import spam; spam.spam()" > You don't want to write "from spam import spam; spam()" > You don't want to write "from Spam import spam; spam()" > You don't want to write "from spam import Spam; Spam()" > > What exactly do you want? When I define class spam in file spam.py, I want to call it by import spam spam() If spam.py is in dir/, then I want to call it by import dir.spam dir.spam() From WanderingAengus at comcast.net Sun Nov 1 09:20:06 2009 From: WanderingAengus at comcast.net (Robinson) Date: Sun, 1 Nov 2009 07:20:06 -0700 Subject: Can I run a python program from within emacs? Message-ID: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> I have also just started with both Aquamacs and Python so I ask for your patience as well. When I evaluate the buffer (C-c C-C) I don't see any response or output from my python program. Should another buffer open automatically? Should a terminal window open? thanks for your patience. Rugbeia Floreat Ubique > On Mar 20, 3:09 pm, jmDesktop wrote: > > Hi, I'm trying to learn Python. I using Aquamac an emac > > implementation with mac os x. I have a program. If I go to the > > command prompt and type pythong myprog.py, it works. Can the > program > > be run from within the editor or is that not how development is > done? > > I ask because I was using Visual Studio with C# and, if you're > > familiar, you just hit run and it works. On Python do I use the > > editor for editing only and then run the program from the command > > line? Thank you. > > Aquamacs, just like any variant of GNU Emacs, will show a Python > menu. There's a "Start Interpreter" function, and one to evaluate the > buffer (C-c C-c). It's pretty straightforward (a euphemism for > obvious). > > If the Python menu doesn't show, then something is going wrong. M-x > python-mode RET would switch it on. > > > -- > http://aquamacs.org -- Aquamacs: Emacs on Mac OS X > http://aquamacs.org/donate -- Could we help you? Return the favor and > support the Aquamacs Project! From bieffe62 at gmail.com Sun Nov 1 09:27:23 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Sun, 1 Nov 2009 06:27:23 -0800 (PST) Subject: Looking for help getting tkinter to work. References: <9e15ab12-c826-4227-9a0c-82d3eccb96a0@r24g2000prf.googlegroups.com> Message-ID: <9d0c476a-86f7-4a8a-a01b-e260060c7bcc@a31g2000yqn.googlegroups.com> On Nov 1, 4:06?am, Shue Boks wrote: > I tried to compile Python and Tcl/Tk on Linux using the following > files: > > Python-3.1.1.tar.gz > tcl8.5.7-src.tar.gz > > Cannot get tkinter to work after compiling & installing Tcl/Tk. ?I get > the following error after compiling Python: > > "Python build finished, but the necessary bits to build these modules > were not found: > _tkinter > To find the necessary bits, look in setup.py in detect_modules() for > the module's name." > > Are the above files the correct versions to get tkinter to work? > > Thanks. The version should be ok. I just compiled python3.1 against tcl/tk 8.5, only I used the tcl/tk development packages coming with my distribution (Ubuntu). I used ./configure --with-tk, so if you did not, try that first. Did you run 'make install' during tcl/tk installation _before_ doing ./ configure in python source directory? If so, look where the library files ( e.g. libtk8.5.so ) and include files (e.g tk.h ) have been placed and check against the places where the function 'detect_tkinter' in 'setup.py' looks for them. Ciao ----- FB From pengyu.ut at gmail.com Sun Nov 1 09:44:19 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 08:44:19 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano wrote: > On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote: > >>> Variables in a function are already private. ?How can the names in one >>> function be affected by other functions in the same module? >> >> You misunderstood me. >> >> If there are multiple functions or classes in a file, when I change >> variables in a function/class, I have to make sure that they are not in >> other functions or classes. > > No you don't. > > def f(x): > ? ?return x+1 > > def g(x): > ? ?return x-1 > > > If I choose to refactor f() and change "x" to "y", why do I care about > the internal variable inside g()? What I mean was, for example, I only want to change 'x' in f() to 'y', but not 'x' in g() to 'y', because the meaning of 'x' in f() and 'x' in g() may represent different things. If both f() and g() are in the same file, I have to make sure that I only replace 'x' in f() but not in g(). However, if I only have f() in a file, I can simply replace all x in the file without worrying replacing 'x' in g(). Is this clear? > Oh wait, I get it... you want to do a global search-and-replace over the > entire file. *face-palm* Yes. You get it. > If your functions are less than one-screen full, why do you need a global > replacement? Global replacement risks changing words in docstrings, > comments etc that it shouldn't. My variables in general are not as short as a single letter, like 'x', and is descriptive. In general, they will not appear in docstrings, unless the ones in docstrings mean the same thing, in which case it is OK to replace the variable and the one in docstrings. From arts.martijn at gmail.com Sun Nov 1 09:49:46 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Sun, 1 Nov 2009 15:49:46 +0100 Subject: Pyfora, a place for python In-Reply-To: <7xpr82y9bz.fsf@ruckus.brouhaha.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <7xpr82y9bz.fsf@ruckus.brouhaha.com> Message-ID: <23739e0a0911010649q697874d5lf752fe825a904f44@mail.gmail.com> I think it's a really good idea :) My accountname is "TotempaaltJ" On Sun, Nov 1, 2009 at 8:48 AM, Paul Rubin wrote: > Saketh writes: > > I am proud to announce the release of Pyfora (http://pyfora.org), an > > online community of Python enthusiasts to supplement comp.lang.python > > and #python. > > And the reason to want to further fragment Python discussion is > exactly what? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jasonsewall at gmail.com Sun Nov 1 11:15:25 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Sun, 1 Nov 2009 11:15:25 -0500 Subject: Can I run a python program from within emacs? In-Reply-To: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> References: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> Message-ID: <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> On Sun, Nov 1, 2009 at 9:20 AM, Robinson wrote: > I have also just started with both Aquamacs and Python so I ask for your > patience as well. > When I evaluate the buffer (C-c C-C) I don't see any response or output from > my python program. Should another buffer open automatically? Should a > terminal window open? I don't know much about Aquamacs or the version of Emacs the Aquamacs you are using is based on, but the C-c C-c command runs py-execute-buffer. Try M-x py-execute-buffer and see what happens. It should pop up a *Python Output* buffer, unless you're actually running the python interpreter in Emacs, in which case the code is run in that buffer. If you're still having trouble, probably an Emacs or Aquamacs list is a better place to look. Jason From omarimanway at gmail.com Sun Nov 1 11:33:02 2009 From: omarimanway at gmail.com (omer azazi) Date: Sun, 1 Nov 2009 08:33:02 -0800 (PST) Subject: What is Islam?-1 References: <5e32081e-ce29-4ece-9643-d579a610ec96@z24g2000yqb.googlegroups.com> <5e843d95-a028-4551-a871-2602b883ffc1@f21g2000vbm.googlegroups.com> <7fc212cf-3710-4ec5-86cd-e3fe1626dd83@o21g2000vbl.googlegroups.com> <87k4yi4qp3.fsf@benfinney.id.au> Message-ID: from python to exe py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built. see here http://www.py2exe.org/index.cgi/Tutorial http://www.py2exe.org/ http://www.scribd.com/doc/19792648/-python-to-exe also eclipse editor>>> http://www.eclipse.org/downloads/ thank u again From gu.yakahughes at gmail.com Sun Nov 1 11:34:44 2009 From: gu.yakahughes at gmail.com (KillSwitch) Date: Sun, 1 Nov 2009 08:34:44 -0800 (PST) Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: On Nov 1, 5:34?am, Dave Angel wrote: > KillSwitch wrote: > > I have a C++ program, with a GUI, into which I have embedded python. I > > have made several python functions in C++, one of which I use to > > override the normal stdout and stderr so that they print to a text box > > of my GUI. One thing I cannot think of how to do is to redefine stdin > > so that it pauses the program, waits for a user to type input into the > > box, hit enter, and takes input from another text element and sends it > > to python like it was the console. > > > I wonder if anyone could help me in trying to do such a thing. To > > simplify, the new stdin should wait for the C++ function to give it a > > value, like it waits for the console. > > I suspect you don't really want to redirect stdin, but instead implement > raw_input(). ?If you have control over the script, just change it from > raw_input() to cpp_raw_input(). ?But if ?you need to be able to run > arbitrary scripts, ... > > (untried) - Try changing __builtins__.raw_input ?to reference your new > function. > > DaveA But what would the function do? How would it pause python and wait for it to have text to send? From rustompmody at gmail.com Sun Nov 1 12:15:07 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 1 Nov 2009 09:15:07 -0800 (PST) Subject: Can I run a python program from within emacs? References: Message-ID: <892a4877-0391-4386-a14f-b66e1b216d49@m3g2000pri.googlegroups.com> On Nov 1, 7:20?pm, Robinson wrote: > I have also just started with both Aquamacs and Python so I ask for ? > your patience as well. > When I evaluate the buffer (C-c C-C) I don't see any response or ? > output from my python program. Should another buffer open ? > automatically? Should a terminal window open? > thanks for your patience. > Rugbeia Floreat Ubique > > > On Mar 20, 3:09 pm, jmDesktop wrote: > > > Hi, I'm trying to learn Python. ?I using Aquamac an emac > > > implementation with mac os x. ?I have a program. ?If I go to the > > > command prompt and type pythong myprog.py, it works. ?Can the ? > > program > > > be run from within the editor or is that not how development is ? > > done? There are two python modes -- python.el and python-mode.el Default with emacs is python.el, what comes from/with python is python- mode.el (needs a download and a couple of lines of setup see http://www.emacswiki.org/emacs/PythonMode). I recommend python-mode. The key-bindings are different --C-c ! to start interpreter followed by C-c C-c to exec a file. From WanderingAengus at comcast.net Sun Nov 1 12:16:45 2009 From: WanderingAengus at comcast.net (Robinson) Date: Sun, 1 Nov 2009 10:16:45 -0700 Subject: Can I run a python program from within emacs? In-Reply-To: <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> References: <26C1AFB9-0E74-425D-A6CE-AE8C89062008@comcast.net> <31e9dd080911010815tbe0cc34hbebe77b89d7e18e@mail.gmail.com> Message-ID: <87495589-2D5A-4353-AC16-5E69806D7886@comcast.net> Jason, Thanks, but I have already tried your suggestions (which seem like logical cause/effect actions) and nothing. There must be a python preference or something I haven't set correctly. There is no Aquamacs list, but I'll check further. Thanks again for the quick reply. On Nov 1, 2009, at 9:15 AM, Jason Sewall wrote: > On Sun, Nov 1, 2009 at 9:20 AM, Robinson > wrote: >> I have also just started with both Aquamacs and Python so I ask for >> your >> patience as well. >> When I evaluate the buffer (C-c C-C) I don't see any response or >> output from >> my python program. Should another buffer open automatically? Should a >> terminal window open? > > I don't know much about Aquamacs or the version of Emacs the Aquamacs > you are using is based on, but the C-c C-c command runs > py-execute-buffer. Try M-x py-execute-buffer and see what > happens. It should pop up a *Python Output* buffer, unless you're > actually running the python interpreter in Emacs, in which case the > code is run in that buffer. > > If you're still having trouble, probably an Emacs or Aquamacs list is > a better place to look. > > Jason From daniel at stutzbachenterprises.com Sun Nov 1 12:52:03 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Sun, 1 Nov 2009 12:52:03 -0500 Subject: ANN: blist 1.0.2 Message-ID: blist 1.0.2 is now available: http://pypi.python.org/pypi/blist/ What is blist? -------------- The blist is a type that looks, acts, and quacks like a Python list, but has better asymptotic performance when inserting or deleting elements (O(log n)). For small lists, blists and the built-in list have very similar performance. The blist also features copy-on-write behavior, so copying or taking large slices from a list is inexpensive. What's new? ----------- blist version 1.0.2 includes two important bug fixes: - Fixed a crash in the .index method, which was not properly sanitizing the optional arguments. - Fixed a possible crash when modifying the blist during iteration Other changes include: - Changed int to Py_ssize_t in several places for better 64-bit hygiene - Removed some over-zealous assertion checks that were causing crashes in oddball (but legal!) cases in debug builds - Ported tests to run under Python 2.6 and Python 3.1 (but no longer Python 2.5) - Got rid of warnings on non-ix86 platforms -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sun Nov 1 14:46:42 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 13:46:42 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano > wrote: >> Oh wait, I get it... you want to do a global search-and-replace over the >> entire file. *face-palm* > > Yes. You get it. In any capable programmer's editor, it should not be hard to do a local search-and-replace over just the one function. -- 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 Sun Nov 1 14:47:18 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 13:47:18 -0600 Subject: How to import only one module in a package when the package __init__.py has already imports the modules? In-Reply-To: <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <366c6f340910312029h74a714f3k7bb1d3d5b55298f1@mail.gmail.com> <02fd0e55$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010613y7d518b96o85dd088e6a59e85c@mail.gmail.com> Message-ID: Peng Yu wrote: > On Sat, Oct 31, 2009 at 11:43 PM, Steven D'Aprano > wrote: >> On Sat, 31 Oct 2009 22:54:47 -0500, Peng Yu wrote: >> >>> So python would not be able to accommodate my preference one >>> class/function per file? >> Of course it does! You can do that RIGHT NOW -- just put one class per >> file. >> >>> I.e., I have to use something like 'from spam >>> import spam' or 'spam.spam()', >> How else do you expect to use the class if you don't import it? >> >> >>> or accept that the filename is not the >>> same as the class/function name. >> So let me see... >> >> You don't want to write "import spam; spam.spam()" >> You don't want to write "from spam import spam; spam()" >> You don't want to write "from Spam import spam; spam()" >> You don't want to write "from spam import Spam; Spam()" >> >> What exactly do you want? > > When I define class spam in file spam.py, I want to call it by > > import spam > spam() > > If spam.py is in dir/, then I want to call it by > > import dir.spam > > dir.spam() That's just not how Python imports work. -- 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 lord_eldritch at yahoo.co.uk Sun Nov 1 14:53:25 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Sun, 01 Nov 2009 20:53:25 +0100 Subject: Tkinter callback arguments Message-ID: Hi Maybe this is maybe something it has been answered somewhere but I haven't been able to make it work. I wanna pass one variable to a callback function and I've read the proper way is: Button(......, command=lambda: function(x)) So with def function(a): print a I get the value of x. Ok. My problem now is that I generate the widgets in a loop and I use the variable to 'label' the widget: for x in range(0,3): Button(......, command=lambda: function(x)) so pressing each button should give me 0,1,2. But with the lambda, I always get the last index, because it gets actualized at each loop cycle. Is there any way to get that? Thanks in advance! -- Lord Eldritch From lord_eldritch at yahoo.co.uk Sun Nov 1 14:53:25 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Sun, 01 Nov 2009 20:53:25 +0100 Subject: Tkinter callback arguments Message-ID: Hi Maybe this is maybe something it has been answered somewhere but I haven't been able to make it work. I wanna pass one variable to a callback function and I've read the proper way is: Button(......, command=lambda: function(x)) So with def function(a): print a I get the value of x. Ok. My problem now is that I generate the widgets in a loop and I use the variable to 'label' the widget: for x in range(0,3): Button(......, command=lambda: function(x)) so pressing each button should give me 0,1,2. But with the lambda, I always get the last index, because it gets actualized at each loop cycle. Is there any way to get that? Thanks in advance! -- Lord Eldritch From python at mrabarnett.plus.com Sun Nov 1 15:13:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 01 Nov 2009 20:13:26 +0000 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: <4AEDEBE6.1080805@mrabarnett.plus.com> Lord Eldritch wrote: > Hi > > Maybe this is maybe something it has been answered somewhere but I haven't > been able to make it work. I wanna pass one variable to a callback function > and I've read the proper way is: > > Button(......, command=lambda: function(x)) > > So with > > def function(a): print a > > I get the value of x. Ok. My problem now is that I generate the widgets in a > loop and I use the variable to 'label' the widget: > > for x in range(0,3): Button(......, command=lambda: function(x)) > > so pressing each button should give me 0,1,2. > > But with the lambda, I always get the last index, because it gets actualized > at each loop cycle. Is there any way to get that? > A lambda expression is just an unnamed function. At the point the function is /called/ 'x' is bound to 3, so that's why 'function' is always called with 3. A function's default arguments are evaluated when the function is /defined/, so you can save the current value of 'x' creating the function (the lambda expression, in this case) with a default argument: for x in range(0,3): Button(......, command=lambda arg=x: function(arg)) The following will also work, although you might find the "x=x" a bit surprising/confusing if you're not used to how Python works: for x in range(0,3): Button(......, command=lambda x=x: function(x)) From mad.mick at gmx.de Sun Nov 1 15:32:15 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 01 Nov 2009 21:32:15 +0100 Subject: list comprehension problem In-Reply-To: <02fd0755$0$1326$c3e8da3@news.astraweb.com> References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There are an infinite number of empty sets that differ according to their > construction: > > The set of all American Presidents called Boris Nogoodnik. > The set of all human languages with exactly one noun and one verb. > The set of all fire-breathing mammals. > The set of all real numbers equal to sqrt(-1). > The set of all even prime numbers other than 2. > The set of all integers between 0 and 1 exclusive. > The set of all integers between 1 and 2 exclusive. > The set of all positive integers between 2/5 and 4/5. > The set of all multiples of five between 26 and 29. > The set of all non-zero circles in Euclidean geometry where the radius > equals the circumference. > ... Logically, they're all the same, by extensionality. There is of course a difference between the reference of an expression and it's meaning, but logical truth only depends on reference. In mathematical logic 'the thing, that ...' can be expressed with the iota operator (i...), defined like this: ((ia)phi e b) := (Ec)((c e b) & (Aa)((a = b) <-> phi)). with phi being a formula, E and A the existential and universal quantors, resp., e the membership relation, & the conjunction operator and <-> the bi-conditional operator. When we want find out if two sets s1 and s2 are the same we only need to look at their extensions, so given: (i s1)(Ay)(y e s1 <-> y is a fire-breathing animal) (i s2)(Ay)(y e s2 <-> y is a real number equal to sqrt(-1)) we only need to find out if: (Ax)(x is a fire-breathing animal <-> x is a real number equal to sqrt(-1)). And since there are neither such things, it follows that s1 = s2. BTW, '=' is usually defined as: a = b := (AabP)(Pa <-> Pb) AKA the Leibniz-Principle, but this definition is 2nd order logic. If we have sets at our disposal when we're axiomatisizing mathematics, we can also define it 1st-orderly: a = b := (Aabc)((a e c) <-> (b e c)) Regargs, Mick. From gagsl-py2 at yahoo.com.ar Sun Nov 1 15:34:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 17:34:19 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano escribi?: > On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: >>> Incorrect. Simplicity of implementation and API is a virtue, in and of >>> itself. The existing module machinery is quite simple to understand, >>> use and maintain. >> >> Uhm... module objects might be quite simple to understand, but module >> handling is everything but simple! (simplicity of implem...? quite >> simple to WHAT? ROTFLOL!!! ) > > I stand corrected :) > Nevertheless, the API is simple: the first time you "import name", Python > searches a single namespace (the path) for a module called name. There > are other variants of import, but the basics remain: > > search the path for the module called name, and do something with the > first one you find. Sure, beautiful, a plain and simple search over a list of directories. That's how it worked in Python 1.4, I think... Now you have lots of "hooks" and even "meta-hooks": sys.meta_path, sys.path_hooks, sys.path_importer_cache. And sys.path, of course, which may contain other things apart of directory names (zip files, eggs, and even instances of custom "loader" objects...). PEP 302 explains this but I'm not sure the description is still current. PEP369, if approved, would add even more hooks. Add packages to the picture, including relative imports and __path__[] processing, and it becomes increasingly harder to explain. Bret Cannon has rewritten the import system in pure Python (importlib) for 3.1; this should help to understand it, I hope. The whole system works, yes, but looks to me more like a collection of patches over patches than a coherent system. Perhaps this is due to the way it evolved. >>> Dealing with name clashes doesn't come for free. If you think it does, >>> I encourage you to write a patch implementing the behaviour you would >>> prefer. >> >> I'd say it is really a bug, and has existed for a long time. > > Since import is advertised to return the first module with the given name > it finds, I don't see it as a bug even if it doesn't do what the > programmer intended it to do. [...] Shadowing a standard library module > is no different. But that's what namespaces are for; if the standard library had its own namespace, such collisions would not occur. I can think of C++, Java, C#, all of them have some way of qualifying names. Python too - packages. But nobody came with a method to apply packages to the standard library in a backwards compatible way. Perhaps those name collisions are not considered serious. Perhaps every user module should live in packages and only the standard library has the privilege of using the global module namespace. Both C++ and XML got namespaces late in their life so in principle this should be possible. >> One way to >> avoid name clashes would be to put the entire standard library under a >> package; a program that wants the standard re module would write "import >> std.re" instead of "import re", or something similar. Every time the std >> package is suggested, the main argument against it is backwards >> compatibility. > > You could do it in a backwards compatible way, by adding the std package > directory into the path. Unfortunately you can't, at least not without some special treatment of the std package. One of the undocumented rules of the import system is that you must not have more than one way to refer to the same module (in this case, std.re and re). Suppose someone imports std.re; an entry in sys.modules with that name is created. Later someone imports re; as there is no entry in sys.modules with such name, the re module is imported again, resulting in two module instances, darkness, weeping and the gnashing of teeth :) (I'm sure you know the problem: it's the same as when someone imports the main script as a module, and gets a different module instance because the "original" is called __main__ instead). -- Gabriel Genellina From rhodri at wildebst.demon.co.uk Sun Nov 1 15:39:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 01 Nov 2009 20:39:37 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach wrote: > * Rhodri James: >> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >> wrote: >>> with the best knowledge of the program's environment, is unable to >>> handle (such as delete) files or folders with paths greater than some >>> 260 characters, is unable to handle filenames that differ only in case >>> and are in the same directory, and is unable to e.g. delete a folder >>> called "con" -- although such files & folders can very easily be >>> created. >> You may or may not be aware that some of these things are limitations >> of >> the underlying disc format, > > Sorry no, it isn't. > > Even assuming you meant the more reasonable "file system", no, it isn't. Actually I should have mentioned the filing system as well as the disc format (which does matter). I may not be using correct Windows terminology, since I'm referring to both the bytes on hardware and the software stack that terminates in the OS API. Still, colour me surprised. I had assumed that NTFS had some (large) limit on filenames, and 256 sounded plausible. More to the point, I was under the impression that path manipulation logic in the filing system had limited sized buffers, which were the cause of this fault, and that Exploder's only sin was not programming around the bug. In fact, the more I think about it, the more sure I am that I've had to play silly buggers on the command line myself to get around this. > Depending on the file system a program may be unable to create such > things as I mentioned. And depending on the program design it may be > reasonable to refuse to create them. > > But a program should have no trouble deleting the files etc. once > they're there. Your faith is touching, but fundamentally misplaced. > That's why the Windows API handles them just fine, while Windows > Explorer does not. You may consider, since you're unfamiliar with the > API, that mostly it's no problem doing these things in the command > interpreter, which has no special support (rather, the reason it's easy > is because it doesn't properly check command arguments). And from that > you can deduce that the API support is there. Having stuffed this up many, many years ago, my recollection is that it needed a certain deviousness to get around. In the case of the long path names, my deduction from comparing the behaviours of the command line and Explorer was that the API limited the path name length, and Explorer didn't use relative paths to get around it. I find it hard to call that a bug, when it's only really exposing a limitation of the underlying FS. >>> For example, for general tool usage in Windows the student needs to >>> know about levels of environment variable specifications and file >>> associations, which in turn requires knowledge of processes and the >>> Windows registry database and various commands. >> Mercifully this is rubbish. For most purposes with most tools even >> Windows users don't need to know much if anything about environment >> variables and the registry. Needing to know anything about the >> registry is usually a sign that Windows has stuffed you up royally. > > I deduce that you mainly use IDEs and don't know about the things you're > commenting on here (more than you did above). Sorry, but there it is. You deduce incorrectly. I'd unbend enough to admit that setting environment variables is frequently very useful to inveterate command- line users like myself, and that Windows makes that a lot harder than necessary, but your original statement still reads like scaremongering. Why am I defending Windows again? -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Nov 1 15:45:46 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 01 Nov 2009 20:45:46 -0000 Subject: Feedback desired on reworked ch 1 progr. intro (now Python 3.x, Windows) In-Reply-To: References: Message-ID: Before we start, can I just say that I find Google Docs loathsome? On Sat, 31 Oct 2009 07:40:36 -0000, Alf P. Steinbach wrote: > I hope this new version of ch 1 is, well, better, addresses some of the > concerns raised? Section 1.1 needs serious work. You have a very assertive writing style and a lot of things that you definitively state are at best debatable. If I'd picked that up in a shop and browsed that opening, I'd put the book down and walk away; essentially you're calling your accuracy into question before you've even said anything about programming. -- Rhodri James *-* Wildebeest Herder to the Masses From gagsl-py2 at yahoo.com.ar Sun Nov 1 16:02:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 01 Nov 2009 18:02:03 -0300 Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch escribi?: > On Nov 1, 5:34 am, Dave Angel wrote: >> KillSwitch wrote: >> > I have a C++ program, with a GUI, into which I have embedded python. I >> > have made several python functions in C++, one of which I use to >> > override the normal stdout and stderr so that they print to a text box >> > of my GUI. One thing I cannot think of how to do is to redefine stdin >> > so that it pauses the program, waits for a user to type input into the >> > box, hit enter, and takes input from another text element and sends it >> > to python like it was the console. >> >> I suspect you don't really want to redirect stdin, but instead implement >> raw_input(). [...]Try changing __builtins__.raw_input to reference >> your new >> function. > > But what would the function do? How would it pause python and wait for > it to have text to send? Whatever you want. You don't have to "pause python", Python itself won't resume until your function doesn't return. (You should release the GIL if your C++ function doesn't call back to Python code, to allow other threads to continue, but that's another story). This is a raw_input replacement written in Tkinter; it shows a dialog box instead of reading from stdin: py> from Tkinter import * py> from tkSimpleDialog import askstring py> def my_raw_input(prompt): ... return askstring("Python", prompt) ... py> root = Tk() py> import __builtin__ py> __builtin__.raw_input = my_raw_input py> py> raw_input("What's your name?") 'Gabriel' -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: ClipBoard-1.png Type: image/png Size: 5666 bytes Desc: not available URL: From jabba.laci at gmail.com Sun Nov 1 16:02:25 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 1 Nov 2009 16:02:25 -0500 Subject: __str__ difficulty with lists Message-ID: <310fbb00911011302g18661ccawa970109364202e66@mail.gmail.com> Hi, I have a list that contains custom objects. When printing the list, I'd like to have a readable result, i.e. I'd like to see the output of the __str__ functions. See an example below. When I call "print li", I would like to get "[3, 5]". How to do that? Thanks, Laszlo ========== class MyNumber: def __init__(self, n): self.n = n def __str__(self): return str(self.n) if __name__ == "__main__": li = [] a = MyNumber(3) li.append(a) li.append(MyNumber(5)) print li # [<__main__.MyNumber instance at 0xb77a456c>, <__main__.MyNumber instance at 0xb77a46ec>] print a # 3 From alfps at start.no Sun Nov 1 16:20:20 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 22:20:20 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: >>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>> wrote: >>>> with the best knowledge of the program's environment, is unable to >>>> handle (such as delete) files or folders with paths greater than >>>> some 260 characters, is unable to handle filenames that differ only >>>> in case and are in the same directory, and is unable to e.g. delete >>>> a folder called "con" -- although such files & folders can very >>>> easily be created. >>> You may or may not be aware that some of these things are >>> limitations of >>> the underlying disc format, >> >> Sorry no, it isn't. >> >> Even assuming you meant the more reasonable "file system", no, it isn't. > > Actually I should have mentioned the filing system as well as the disc > format (which does matter). I may not be using correct Windows > terminology, > since I'm referring to both the bytes on hardware and the software stack > that terminates in the OS API. > > Still, colour me surprised. I had assumed that NTFS had some (large) > limit on filenames, and 256 sounded plausible. For NTFS it's 32K or 64K wide characters, I don't recall which. But what's important is that that's also the API level limit. You can find most of the details in Microsoft's documentation of CreateFile (but it's off-topic here). Given that the API level makes it possible for long paths/names to exist, a program should be prepared to handle them, although it may reasonably refuse to create them. Windows Explorer fails to handle them. Not only to create them. A filesystem may impose a lower limit, but a program should ideally not be limited to or just work with a given filesystem (note: Windows supports multiple different filesystems, but accessed via the same general API). > More to the point, I > was under the impression that path manipulation logic in the filing > system had limited sized buffers, which were the cause of this fault, > and that Exploder's only sin was not programming around the bug. In > fact, the more I think about it, the more sure I am that I've had to > play silly buggers on the command line myself to get around this. > >> Depending on the file system a program may be unable to create such >> things as I mentioned. And depending on the program design it may be >> reasonable to refuse to create them. >> >> But a program should have no trouble deleting the files etc. once >> they're there. > > Your faith is touching, but fundamentally misplaced. By the facts, if I believed that most programs have no problem it would be a misplaced belief, yes (assuming that's what you mean above). But my argument and concrete example was the opposite. It expanded on my statement that "Unfortunately even most professional programs do not handle the requirements of their environs very well" So in what you quoted above I used "should" in the sense of the ideal to strive for, and illustrated the harsh reality that it currently isn't that way, by the concrete Windows Explorer example. This is worth keeping in mind: in a Usenet discussion, context often disappears. Looking up-thread is then one way to find out what it's all about. :-) >> That's why the Windows API handles them just fine, while Windows >> Explorer does not. You may consider, since you're unfamiliar with the >> API, that mostly it's no problem doing these things in the command >> interpreter, which has no special support (rather, the reason it's >> easy is because it doesn't properly check command arguments). And from >> that you can deduce that the API support is there. > > Having stuffed this up many, many years ago, my recollection is that > it needed a certain deviousness to get around. Yes. C:\> md rhodri & cd rhodri C:\rhodri> md \\?\c:\rhodri\con C:\rhodri> dir Volume in drive C is maindisk Volume Serial Number is C469-4FA2 Directory of C:\rhodri 01.11.2009 22:16 . 01.11.2009 22:16 .. 01.11.2009 22:16 con 0 File(s) 0 bytes 3 Dir(s) 18 405 834 752 bytes free C:\rhodri> cd con The system cannot find the path specified. C:\rhodri> cd \\?\c:\rhodri\con '\\?\c:\rhodri\con' CMD does not support UNC paths as current directories. C:\rhodri> rd \\?\c:\rhodri\con C:\rhodri> _ To keep it short the above example is of something that no program really is expected to handle. It's just an example of the mechanisms involved. Also, it's nice with concrete examples, to show that one is not just blowing wind. :-) > In the case of the long > path names, my deduction from comparing the behaviours of the command > line and Explorer was that the API limited the path name length, and > Explorer didn't use relative paths to get around it. I find it hard > to call that a bug, when it's only really exposing a limitation of the > underlying FS. No, it's not exposing a limitation of the underlying FS. It's exposing a limitation in the way that the program deals with paths. Apparently Windows Explorer uses fixed size buffers for paths, rather small buffers. >>>> For example, for general tool usage in Windows the student needs to >>>> know about levels of environment variable specifications and file >>>> associations, which in turn requires knowledge of processes and the >>>> Windows registry database and various commands. >>> Mercifully this is rubbish. For most purposes with most tools even >>> Windows users don't need to know much if anything about environment >>> variables and the registry. Needing to know anything about the >>> registry is usually a sign that Windows has stuffed you up royally. >> >> I deduce that you mainly use IDEs and don't know about the things >> you're commenting on here (more than you did above). Sorry, but there >> it is. > > You deduce incorrectly. I'd unbend enough to admit that setting > environment variables is frequently very useful to inveterate command- > line users like myself, and that Windows makes that a lot harder than > necessary, but your original statement still reads like scaremongering. > > Why am I defending Windows again? Because I used a Windows-based concrete example. Then by attempting to raise doubts about that which you found hard to believe, you got into an absurd rhetorical position. He he, it happens very often, but happily you saw it at once & adjusted: some folks just go on defending an indefensible position, they happily disregard facts and logic, and then it gets, "interesting". :-) Cheers, - Alf From alfps at start.no Sun Nov 1 16:24:52 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 01 Nov 2009 22:24:52 +0100 Subject: Feedback desired on reworked ch 1 progr. intro (now Python 3.x, Windows) In-Reply-To: References: Message-ID: * Rhodri James: > Before we start, can I just say that I find Google Docs loathsome? > > On Sat, 31 Oct 2009 07:40:36 -0000, Alf P. Steinbach > wrote: > >> I hope this new version of ch 1 is, well, better, addresses some of >> the concerns raised? > > Section 1.1 needs serious work. Could you please expand on that? It is a hint. Byt it doesn't leave me with much to go on regarding what you mean. > You have a very assertive writing style > and a lot of things that you definitively state are at best debatable. > If I'd picked that up in a shop and browsed that opening, I'd put the > book down and walk away; essentially you're calling your accuracy into > question before you've even said anything about programming. Could you please expand on this also? Sort of, more concrete? Cheers & thanks, - Alf From deets at nospam.web.de Sun Nov 1 16:26:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 01 Nov 2009 22:26:33 +0100 Subject: __str__ difficulty with lists In-Reply-To: References: Message-ID: <7l6co9F3b3ap8U1@mid.uni-berlin.de> Jabba Laci schrieb: > Hi, > > I have a list that contains custom objects. When printing the list, > I'd like to have a readable result, i.e. I'd like to see the output of > the __str__ functions. See an example below. When I call "print li", I > would like to get "[3, 5]". How to do that? Use __repr__ instead - lists call that on their contained objects. Diez From ldo at geek-central.gen.new_zealand Sun Nov 1 16:34:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 02 Nov 2009 10:34:25 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> In message , >> Carsten Haese wrote: > >>> On what grounds are you asserting that it's not necessary to mix the >>> two? Please elaborate your point. >> >> On the grounds that Python has more general and powerful string >> parameter- substitution mechanisms than anything built into any database >> API. > > That statement is fundamentally flawed. You are assuming that the > preferred way of getting a value into a query is by substituting a > literal into the query string. That is, in general, not true, because > that would be horribly inefficient. Says someone who hasn't realized where the real inefficiencies are. Remember what Tony Hoare told us: "premature optimization is the root of all evil". These are databases we're talking about. Real-world databases are large, and reside on disk, which is several orders of magnitude slower than RAM. And RAM is where string parameter substitutions take place. So a few hundred extra RAM accesses isn't going to make any significant difference to the speed of database queries. > Finally, you're assuming that every value that can be supplied to a > query actually HAS a literal form. That is not true. For example, in > Informix databases, there are no literals for BYTE-type values. Probably why I don't use Informix. What use is a binary data type if you can't insert and retrieve binary data values? From python at mrabarnett.plus.com Sun Nov 1 17:01:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 01 Nov 2009 22:01:42 +0000 Subject: import bug In-Reply-To: References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: <4AEE0546.4040509@mrabarnett.plus.com> Gabriel Genellina wrote: [snip] >>> One way to avoid name clashes would be to put the entire standard >>> library under a package; a program that wants the standard re >>> module would write "import std.re" instead of "import re", or >>> something similar. Every time the std package is suggested, the >>> main argument against it is backwards compatibility. >> >> You could do it in a backwards compatible way, by adding the std >> package directory into the path. > > Unfortunately you can't, at least not without some special treatment > of the std package. One of the undocumented rules of the import > system is that you must not have more than one way to refer to the > same module (in this case, std.re and re). Suppose someone imports > std.re; an entry in sys.modules with that name is created. Later > someone imports re; as there is no entry in sys.modules with such > name, the re module is imported again, resulting in two module > instances, darkness, weeping and the gnashing of teeth :) (I'm sure > you know the problem: it's the same as when someone imports the main > script as a module, and gets a different module instance because the > "original" is called __main__ instead). > Couldn't the entry in sys.modules be where the module was found, so that if 're' was found in 'std' then the entry is 'std.re' even if the import said just 're'? From pengyu.ut at gmail.com Sun Nov 1 17:11:48 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 16:11:48 -0600 Subject: About one class/function per module Message-ID: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> I recently asked how to support one class/function per module under the title 'How to import only one module in a package when the package __init__.py has already imports the modules?' I summarize my key points below. In particular, I have to two questions: 1. What disadvantages there are to enforce one class/function per file? 2. How to better support one class/function per file in python? ------------------------------------------------------------------------------ I prefer organized my code one class/function per file (i.e per module in python). I know the majority of programmers don't use this approach. Therefore, I'm wondering what its disadvantage is. The advantages of one-function/class-per-file that I am aware of are the following items (maybe incomplete). 1. It is easy to see what functions and classes there are just by browsing the source directory, without the need of opening the file by an editor. 2. Testing code for a function/class can be organized along with the module for the function/class, which also makes it easier to keep track of the testing code for any function/class. 3. It is easy to move a function/class from one package to another by just moving files around. 4. It is easy change variable names, etc., for a function/class by replacement in a file without worrying accidentally change variable names in other functions. I have used the above approach on a C++ project. And I use vim + ctags to navigate from a reference of a class/funciton to its definition. So far it works fine. Some people mentioned an good IDE can do 1 and 4. But I'm not aware of an IDE that can allow me to change file name freely. I tried Visual Studio long time ago, I have to delete a file, change the file name and add the file back in order to change the file. Now let us consider how well python can support one function/class per file style. I encounter the following problems. Suppose that the parent directory of 'test' is in $PYTHONPATH and __init__.py is empty, test/ |-- __init__.py |-- A.py `-- B.py where A.py has only class A and B.py has only class B. The end user of the test package has to either import test.A a=test.A.A() or from test.A import A a=A() Both of the two cases are not satisfactory. In the first case, a end user has to type A twice in test.A.A(), which is a burden to the end user. In the second case, 'from test.A import A' screws up the namespace, which might cause potential conflicts with classes of the same name but from different packages. I was also suggested to put the following line in __init__.py. from A import A from B import B Then the end user can use the following code. import test test.A() But the disadvantage is that I can not import individule file test.A and test.B any more. Suppose that A is modified but not done yet, then I modify B. Since the modification of A is not finished yet, the test code of B won't run because the test code import test.A. I'm looking for if there is a solution, so that a end user can use the following code import test.A test.A() So far, I haven't find one. It seems impossible in python, but I want to double check if there is one solution. From deets at nospam.web.de Sun Nov 1 17:32:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 01 Nov 2009 23:32:00 +0100 Subject: About one class/function per module In-Reply-To: References: Message-ID: <7l6gj0F3bagckU1@mid.uni-berlin.de> Peng Yu schrieb: > I recently asked how to support one class/function per module under > the title 'How to import only one module in a package when the package > __init__.py has already imports the modules?' I summarize my key > points below. In particular, I have to two questions: > 1. What disadvantages there are to enforce one class/function per file? > 2. How to better support one class/function per file in python? Are you aware that it's much easier to just let go about your preconceptions about how things should work, and instead adapt for *Pythocode* to the way *Python* works? The energy you've invested in coming up with contrived reasons for why e.g. one file per function is a good idea is better spent actually programming Python - and ejoying it. Diez From carsten.haese at gmail.com Sun Nov 1 17:40:11 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 01 Nov 2009 17:40:11 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > Says someone who hasn't realized where the real inefficiencies are. Remember > what Tony Hoare told us: "premature optimization is the root of all evil". > These are databases we're talking about. Real-world databases are large, and > reside on disk, which is several orders of magnitude slower than RAM. And > RAM is where string parameter substitutions take place. So a few hundred > extra RAM accesses isn't going to make any significant difference to the > speed of database queries. You're just not getting it. The cost is not in performing the parameter substitutions themselves. The cost is in parsing what's essentially the same query one million times over when it could have been parsed only once. You might find an increase of seven orders of magnitude insignificant, but I don't. > Probably why I don't use Informix. What use is a binary data type if you > can't insert and retrieve binary data values? You CAN insert and retrieve binary data values. You just have to use the right tool for the job, and that is parameter binding. -- Carsten Haese http://informixdb.sourceforge.net From robert.kern at gmail.com Sun Nov 1 17:46:49 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Nov 2009 16:46:49 -0600 Subject: About one class/function per module In-Reply-To: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> References: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> Message-ID: Peng Yu wrote: > So far, I haven't find one. It seems impossible in python, but I want > to double check if there is one solution. We have already told you more than twice that the answer is "No." Please don't triple check. -- 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 REMOVE-THIS-cybersource.com.au Sun Nov 1 17:51:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:51:04 GMT Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fdff3a$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 17:34:19 -0300, Gabriel Genellina wrote: > En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano > escribi?: >> On Sun, 01 Nov 2009 01:38:16 -0300, Gabriel Genellina wrote: > >>>> Incorrect. Simplicity of implementation and API is a virtue, in and >>>> of itself. The existing module machinery is quite simple to >>>> understand, use and maintain. >>> >>> Uhm... module objects might be quite simple to understand, but module >>> handling is everything but simple! (simplicity of implem...? quite >>> simple to WHAT? ROTFLOL!!! ) >> >> I stand corrected :) >> Nevertheless, the API is simple: the first time you "import name", >> Python searches a single namespace (the path) for a module called name. >> There are other variants of import, but the basics remain: >> >> search the path for the module called name, and do something with the >> first one you find. > > Sure, beautiful, a plain and simple search over a list of directories. > That's how it worked in Python 1.4, I think... Now you have lots of > "hooks" and even "meta-hooks": sys.meta_path, sys.path_hooks, > sys.path_importer_cache. And sys.path, of course, which may contain > other things apart of directory names (zip files, eggs, and even > instances of custom "loader" objects...). You'll notice I deliberately didn't refer to directories. I just said "the path". If the path contains things other than directories, they are searched too. > PEP 302 explains this but I'm > not sure the description is still current. PEP369, if approved, would > add even more hooks. > Add packages to the picture, including relative imports and __path__[] > processing, and it becomes increasingly harder to explain. Bret Cannon > has rewritten the import system in pure Python (importlib) for 3.1; this > should help to understand it, I hope. The whole system works, yes, but > looks to me more like a collection of patches over patches than a > coherent system. Perhaps this is due to the way it evolved. You've convinced me that the implementation of the import infrastructure isn't as clean as I imagined. I'm sure it's a gnarly hack on top of gnarly hacks, and that maintaining it requires heroic measures worthy of a medal *grin*. >>>> Dealing with name clashes doesn't come for free. If you think it >>>> does, I encourage you to write a patch implementing the behaviour you >>>> would prefer. >>> >>> I'd say it is really a bug, and has existed for a long time. >> >> Since import is advertised to return the first module with the given >> name it finds, I don't see it as a bug even if it doesn't do what the >> programmer intended it to do. [...] Shadowing a standard library module >> is no different. > > But that's what namespaces are for; if the standard library had its own > namespace, such collisions would not occur. Sure. But that's not a bug in the import system. If it's a bug, it's a bug in the layout of the standard library. >> You could do it in a backwards compatible way, by adding the std >> package directory into the path. > > Unfortunately you can't, at least not without some special treatment of > the std package. One of the undocumented rules of the import system is > that you must not have more than one way to refer to the same module (in > this case, std.re and re). *slaps head* How obvious in hindsight. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 17:52:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:52:10 GMT Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fdff7c$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: > When we want find out if two sets s1 and s2 are the same we only need to > look at their extensions, so given: > > (i s1)(Ay)(y e s1 <-> y is a fire-breathing animal) (i s2)(Ay)(y e s2 > <-> y is a real number equal to sqrt(-1)) > > we only need to find out if: > > (Ax)(x is a fire-breathing animal <-> x is a real number equal to > sqrt(-1)). > > And since there are neither such things, it follows that s1 = s2. That assumes that all({}) is defined as true. That is a common definition (Python uses it), it is what classical logic uses, and it often leads to the "obvious" behaviour you want, but there is no a priori reason to accept that all({}) is true, and indeed it leads to some difficulties: All invisible men are alive. All invisible men are dead. are both true. Consequently, not all logic systems accept vacuous truths. http://en.wikipedia.org/wiki/Vacuous_truth -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 17:53:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 22:53:49 GMT Subject: How to import only one module in a package when the package __init__.py has already imports the modules? References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <366c6f340910311453w50ffdf04n7272c76f9240eacf@mail.gmail.com> <20091031224516.GC6708@kinakuta.local> <366c6f340910311629h66d69c36s3463e2df3d84ba04@mail.gmail.com> <4AECEFE5.80106@ieee.org> <02fd0d9d$0$1326$c3e8da3@news.astraweb.com> <366c6f340911010644g68eafee4uea1fc5e513b22cc8@mail.gmail.com> Message-ID: <02fdffdf$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 13:46:42 -0600, Robert Kern wrote: > Peng Yu wrote: >> On Sat, Oct 31, 2009 at 11:40 PM, Steven D'Aprano >> wrote: > >>> Oh wait, I get it... you want to do a global search-and-replace over >>> the entire file. *face-palm* >> >> Yes. You get it. > > In any capable programmer's editor, it should not be hard to do a local > search-and-replace over just the one function. Given the OP's stated claim that all his functions are less than a screen in size, Notepad could do it, with just the tiniest amount of manual effort. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 1 18:02:47 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Nov 2009 23:02:47 GMT Subject: Function states [was Re: How to import only one module in a package when the package __init__.py has already imports the modules?] References: <366c6f340910311331x25815bdeybcd54834aaba81c2@mail.gmail.com> <02fce8d2$0$1326$c3e8da3@news.astraweb.com> <02fd0c56$0$1326$c3e8da3@news.astraweb.com> Message-ID: <02fe01f9$0$1326$c3e8da3@news.astraweb.com> On Sun, 01 Nov 2009 08:07:37 -0600, Peng Yu wrote: > It is > reasonable to assume the log of the number of states of a function or a > class is proportional to it length. Hence, when a function or a > class is long, you will never be able to test all its states. def f(n): return n + 5 def g(n): x = n + 1 x += 1 x += 1 x += 1 return x + 1 Function g() has five times the length (in lines) as f(). Does it require five times the testing? Obviously not. In fact, there's no easy way to test the internal state of the function from outside, because x is local to g(). You can't test the value of x from outside, because x is not exposed to the outside. The complexity of testing functions is roughly proportional to the number of paths through the function, not the number of lines. Both f() and g() have a single path through the function and therefore require the same amount of testing. The simplest estimate of the number of paths in a function is the number of if...else statements. Each pair *doubles* the number of paths: def func(): if cond1: A else: B if cond2: C else: D if cond3: E else: F There are 2**3 paths that need testing: ACE ACF ADE ADF BCE BCF BDE BDF Or consider this example: def func(x, cond): for f in [A, B, C, D, E, F]: if cond(x): x = f(x) This function has two lines only, but clearly there could be as many as 128 paths that need testing. Ideally your test data should visit each one of these paths. -- Steven From alfps at start.no Sun Nov 1 18:19:51 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 00:19:51 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * MRAB: > Lord Eldritch wrote: >> Hi >> >> Maybe this is maybe something it has been answered somewhere but I >> haven't been able to make it work. I wanna pass one variable to a >> callback function and I've read the proper way is: >> >> Button(......, command=lambda: function(x)) >> >> So with >> >> def function(a): print a >> >> I get the value of x. Ok. My problem now is that I generate the >> widgets in a loop and I use the variable to 'label' the widget: >> >> for x in range(0,3): Button(......, command=lambda: function(x)) >> >> so pressing each button should give me 0,1,2. >> >> But with the lambda, I always get the last index, because it gets >> actualized at each loop cycle. Is there any way to get that? >> > A lambda expression is just an unnamed function. At the point the > function is /called/ 'x' is bound to 3, so that's why 'function' is > always called with 3. > > A function's default arguments are evaluated when the function is > /defined/, so you can save the current value of 'x' creating the > function (the lambda expression, in this case) with a default argument: > > for x in range(0,3): > Button(......, command=lambda arg=x: function(arg)) > > The following will also work, although you might find the "x=x" a bit > surprising/confusing if you're not used to how Python works: > > for x in range(0,3): > Button(......, command=lambda x=x: function(x)) An alternative reusable alternative is to create a button-with-id class. This is my very first Python class so I'm guessing that there are all sorts of issues, in particular naming conventions. And the idea of creating a reusable solution for such a small issue may be un-pythonic? But just as an example, in Python 3.x, import tkinter # I guess for Python 2.x do "import Tkinter as tkinter" but haven't tested. class IdButton( tkinter.Button ): def __init__( self, owner_widget, id = None, command = None, **args ): tkinter.Button.__init__( self, owner_widget, args, command = self.__on_tk_command ) self.__id = id self.__specified_command = command def __on_tk_command( self ): if self.__specified_command != None: self.__specified_command( self ) else: self.on_clicked() def on_clicked( self ): pass def id( self ): return self.__id def id_string( self ): return str( self.id() ); def on_button_click( aButton ): print( "Button " + aButton.id_string() + " clicked!" ) window = tkinter.Tk() n_buttons = 3 for x in range( 1, n_buttons + 1 ): IdButton( window, id = x, text = "Button " + str( x ), command = on_button_click ).pack() window.mainloop() Cheers, - Alf PS: Now I see that I've used camelCase once. Oh well... From cjwilliams43 at gmail.com Sun Nov 1 18:32:14 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sun, 01 Nov 2009 18:32:14 -0500 Subject: Why 'import module' will not import module.py but the directory module? In-Reply-To: References: <366c6f340910311651u597bec70qa4bf9526c40bb91a@mail.gmail.com> <366c6f340910311716n6827f6a1r9bf730c780aeba08@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2009-10-31 19:16 PM, Peng Yu wrote: >> On Sat, Oct 31, 2009 at 7:02 PM, Robert Kern >> wrote: >>> On 2009-10-31 18:51 PM, Peng Yu wrote: >>>> >>>> If I have both the directory 'module' and the file 'module.py' in a >>>> directory in $PYTHONPATH, python will import 'module' rather than >>>> 'module.py'. I'm wondering what is the design rationale of setting >>>> higher priorities to directories. Is there a way to reverse the >>>> priority? >>> >>> You mean that you have a package "module/"? With an __init__.py? Plain >>> directories that aren't packages shouldn't be imported by Python. >> >> Yes. I mean a pakcage 'module/' with an __init__.py. >> >>> No, you can't reverse the priority between packages and modules. I'm not >>> sure why that would help you. The package would then be inaccessible >>> if you >>> did. If it's inaccessible, then why have it at all? >> >> Why the package 'module' has to be inaccessible? I can 'import >> module.part1' to access the component of the package. > > No, it wouldn't. It's a moot point because Python picks the package > first, but if it did pick modules before packages, then > sys.modules['module'] would point to the module from module.py and not > module/__init__.py . "import module.part1" first executes "import > module", then looks in there to determine who to resolve "module.part1". > Since sys.modules['module'] is a regular module and not the package, it > wouldn't find module/part1.py . > Doesn't it make sense to avoid the use of names like module or package, even though they are permitted. Colin W. From stef.mientki at gmail.com Sun Nov 1 18:42:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 02 Nov 2009 00:42:26 +0100 Subject: Doesn't MS-Windows likes Python ? (or: why more than 20 sec delay when running a program from Python) Message-ID: <4AEE1CE2.4050205@gmail.com> hello, I've an AutoIt program that set some switches in the LAN settings. When I launch the AutoIt executable, the settings are changed immediately. When I launch the AutoIt executable from python (which is the intention), it hangs for about 20 seconds, before any action appears on the screen. Analyzing the script, shows that it hangs on the next 2 lines: Run ( "control.exe ncpa.cpl" ) WinWait( "Network Connections") Transfering the Run command to Python, it hangs on the next subprocess call subprocess.call ( [ r"control.exe", "ncpa.cpl" ]) Does anyone have a clue, why starting a process takes 20 seconds longer when ran from Python ? And even more important, is there a work around ? thanks, Stef Mientki From rhodri at wildebst.demon.co.uk Sun Nov 1 19:08:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 02 Nov 2009 00:08:37 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach wrote: > * Rhodri James: This is a weird attribution style, by the way. I don't think it helps. >> On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach >> wrote: >> >>> * Rhodri James: >>>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>>> wrote: >>>>> with the best knowledge of the program's environment, is unable to >>>>> handle (such as delete) files or folders with paths greater than >>>>> some 260 characters, is unable to handle filenames that differ only >>>>> in case and are in the same directory, and is unable to e.g. delete >>>>> a folder called "con" -- although such files & folders can very >>>>> easily be created. >>>> You may or may not be aware that some of these things are >>>> limitations of >>>> the underlying disc format, >>> >>> Sorry no, it isn't. >>> >>> Even assuming you meant the more reasonable "file system", no, it >>> isn't. >> Actually I should have mentioned the filing system as well as the disc >> format (which does matter). I may not be using correct Windows >> terminology, >> since I'm referring to both the bytes on hardware and the software stack >> that terminates in the OS API. >> Still, colour me surprised. I had assumed that NTFS had some (large) >> limit on filenames, and 256 sounded plausible. > > For NTFS it's 32K or 64K wide characters, I don't recall which. But > what's important is that that's also the API level limit. You can find > most of the details in Microsoft's documentation of CreateFile (but it's > off-topic here). Actually it's not, since it's a perfect example of the "not reading quite carefully enough" others have pointed out before. You make this statement as an absolute, iron-clad assertion. Checking the MS website, we find it actually says: "Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters." The exceptions are unicode versions of some of the functions, which do give you ~32K characters. However, the docs are pretty specific about what is and isn't the API limit. Since this applies to the command line just as much as to GUIs, I'll repeat my claim that blaming Explorer for something that causes just as much grief on a command line is a tad unfair. More importantly, I accuse you of making very definitive statments that turn out to be insufficiently researched. That's not an encouraging state of affairs in someone planning to write a beginners' textbook. Having originally learned C from one of Herbert Schildt's books, I reckon I've earned the right to be highly allergic to this! -- Rhodri James *-* Wildebeest Herder to the Masses From alfps at start.no Sun Nov 1 19:49:50 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 01:49:50 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: > > This is a weird attribution style, by the way. I don't think it helps. That's a pretty weird thing to comment on. And as far as I can see the comment doesn't make sense except as an attempt to find something negative to say. But anyway, the point about '*' was, once upon a time, that it made for a very clear style of quoting in old newsreaders. Nowadays the tools are generally of lesser quality (e.g. I'm using Thunderbird). And so it doesn't really have much of that advantage left, but I'm using it anyway; I can be pretty stubborn about issues of quality. >>> On Fri, 30 Oct 2009 03:26:45 -0000, Alf P. Steinbach >>> wrote: >>> >>>> * Rhodri James: >>>>> On Thu, 29 Oct 2009 16:53:05 -0000, Alf P. Steinbach >>>>> wrote: >>>>>> with the best knowledge of the program's environment, is unable to >>>>>> handle (such as delete) files or folders with paths greater than >>>>>> some 260 characters, is unable to handle filenames that differ >>>>>> only in case and are in the same directory, and is unable to e.g. >>>>>> delete a folder called "con" -- although such files & folders >>>>>> can very easily be created. >>>>> You may or may not be aware that some of these things are >>>>> limitations of >>>>> the underlying disc format, >>>> >>>> Sorry no, it isn't. >>>> >>>> Even assuming you meant the more reasonable "file system", no, it >>>> isn't. >>> Actually I should have mentioned the filing system as well as the disc >>> format (which does matter). I may not be using correct Windows >>> terminology, >>> since I'm referring to both the bytes on hardware and the software stack >>> that terminates in the OS API. >>> Still, colour me surprised. I had assumed that NTFS had some (large) >>> limit on filenames, and 256 sounded plausible. >> >> For NTFS it's 32K or 64K wide characters, I don't recall which. But >> what's important is that that's also the API level limit. You can find >> most of the details in Microsoft's documentation of CreateFile (but >> it's off-topic here). > > Actually it [the limit]'s not You're disputing a plain fact. For which you've been given a technical reference, as well as concrete example. I'm sorry, but it's idiotic to dispute plain facts. >, since it's a perfect example of the "not reading quite > carefully enough" others have pointed out before. You make this statement > as an absolute, iron-clad assertion. Checking the MS website, we find it > actually says: > > "Maximum Path Length Limitation > > In the Windows API (with some exceptions discussed in the following > paragraphs), the maximum length for a path is MAX_PATH, which is defined > as 260 characters." > > The exceptions are unicode versions of some of the functions, which do > give you ~32K characters. However, the docs are pretty specific about > what is and isn't the API limit. I'm sorry but you're misunderstanding the documentation. In your own words, you're "not reading quite carefully enough". By the way, your technique of vague ad hominem attack here is detestable. But anyway, if you read the documentation of CreateFile as I directed you to, or simply read on where you was, then you get a more technically correct picture. Or, by applying logic you can /deduce/ that since >260 character paths can and do exist, 260 characters is not "the limit". The MS documentation is unfortunately not all that clear. In many cases (the most infamous one is perhaps the claim that a program's entry point is WinMain) it's just plain incorrect, being written by technical writers. But it's simple enough to write a few programs to check it out. > Since this applies to the command > line just as much as to GUIs, No, it doesn't. And you've been given a concrete example of how. You can't just go on *inventing* facts. Facts are facts, your fantasies & wishes are your fantasies & wishes. > I'll repeat my claim that blaming Explorer > for something that causes just as much grief on a command line is a > tad unfair. I'm sorry, but there's a complete lack of logic in that, as well as misdirection. First, regarding the misdirection, it is untrue that I have "blamed" Windows Explorer for this. The blame, if any is to be affixed anywhere, belongs elsewhere than with a computer program. Second, regarding the logic, that a program exhibits low quality in some respect is not OK just because there's another program that also exhibits low quality. > More importantly, I accuse you of making very definitive statments > that turn out to be insufficiently researched. That would be OK and what I want. :-) But you haven't. You're making general vague statements about quality, but haven't addressed any concrete thing in the text. And what you have responded to here in this thread, it's all been incorrect. In this latest article you have even started disputing simple technical facts and started making fallacious deductions, shown above. > That's not an > encouraging state of affairs in someone planning to write a beginners' > textbook. Having originally learned C from one of Herbert Schildt's > books, I reckon I've earned the right to be highly allergic to this! I'm sorry to hear that you had to endure that. It's an old saying that the low price of Herbert's annotated C++ reference, compared to the official standard, reflected the value of his annotations... But that's no excuse to now start emulating Herbert, regarding blatant disregard for facts and logic, as you've done above. Cheers & hth., - Alf From wuwei23 at gmail.com Sun Nov 1 20:02:33 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 17:02:33 -0800 (PST) Subject: About one class/function per module References: Message-ID: On Nov 2, 8:11?am, Peng Yu wrote: > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. You mean, what disadvantages it has _other_ than the ones you've been experiencing? Aren't those enough to warrant actually working with Python's import mechanism rather than against it? From mad.mick at gmx.de Sun Nov 1 20:02:58 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Mon, 02 Nov 2009 02:02:58 +0100 Subject: list comprehension problem In-Reply-To: <02fdff7c$0$1326$c3e8da3@news.astraweb.com> References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> <02fd0755$0$1326$c3e8da3@news.astraweb.com> <02fdff7c$0$1326$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: >> >> (Ax)(x is a fire-breathing animal <-> x is a real number equal to >> sqrt(-1)). >> >> And since there are neither such things, it follows that s1 = s2. > > That assumes that all({}) is defined as true. That is a common definition > (Python uses it), it is what classical logic uses, and it often leads to > the "obvious" behaviour you want, but there is no a priori reason to > accept that all({}) is true, and indeed it leads to some difficulties: > > All invisible men are alive. > All invisible men are dead. > > are both true. Consequently, not all logic systems accept vacuous truths. > > http://en.wikipedia.org/wiki/Vacuous_truth You're right, of course, but I'm an oldfashioned quinean guy :-) Also, in relevance logic and similar systems my beloved proof that there are no facts (Davidson's Slingshot) goes down the drain. So I think I'll stay with classical logic FTTB. Regards, Mick. From pengyu.ut at gmail.com Sun Nov 1 20:27:32 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 1 Nov 2009 19:27:32 -0600 Subject: About one class/function per module In-Reply-To: References: Message-ID: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: > On Nov 2, 8:11?am, Peng Yu wrote: >> I prefer organized my code one class/function per file (i.e per module >> in python). I know the majority of programmers don't use this >> approach. Therefore, I'm wondering what its disadvantage is. > > You mean, what disadvantages it has _other_ than the ones you've been > experiencing? > > Aren't those enough to warrant actually working with Python's import > mechanism rather than against it? At least, I can use the following for now with one class/function per module. Unless this one class/function per module style have other disadvantages in term software engineering, I still can live with typing the class name (e.g. 'A') twice. import test.A a=test.A.A() So I am asking disadvantages besides python import mechanism is not friendly to it. From metal29a at gmail.com Sun Nov 1 21:00:45 2009 From: metal29a at gmail.com (metal) Date: Sun, 1 Nov 2009 18:00:45 -0800 (PST) Subject: About one class/function per module References: Message-ID: <2e97941b-848e-450e-bc03-590d82577023@v15g2000prn.googlegroups.com> On 11?2?, ??9?27?, Peng Yu wrote: > On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: > > On Nov 2, 8:11 am, Peng Yu wrote: > >> I prefer organized my code one class/function per file (i.e per module > >> in python). I know the majority of programmers don't use this > >> approach. Therefore, I'm wondering what its disadvantage is. > > > You mean, what disadvantages it has _other_ than the ones you've been > > experiencing? > > > Aren't those enough to warrant actually working with Python's import > > mechanism rather than against it? > > At least, I can use the following for now with one class/function per > module. Unless this one class/function per module style have other > disadvantages in term software engineering, I still can live with > typing the class name (e.g. 'A') twice. > > import test.A > a=test.A.A() > > So I am asking disadvantages besides python import mechanism is not > friendly to it. I recommand you double check django project, to learn how to organize python project From wuwei23 at gmail.com Sun Nov 1 21:06:57 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 18:06:57 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <4c1bef97-491a-4e87-ac97-e13c80cd252b@r24g2000prf.googlegroups.com> Saketh wrote: > If you have any suggestions, let me know -- this is a community > effort! I'd like to suggest Pyaspora as a more apropos name ;) From davea at ieee.org Sun Nov 1 21:13:10 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 21:13:10 -0500 Subject: stdin in embedded python In-Reply-To: References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> Message-ID: <4AEE4036.8000405@ieee.org> Gabriel Genellina wrote: > En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch > escribi?: >> On Nov 1, 5:34 am, Dave Angel wrote: >>> KillSwitch wrote: > >>> > I have a C++ program, with a GUI, into which I have embedded >>> python. I >>> > have made several python functions in C++, one of which I use to >>> > override the normal stdout and stderr so that they print to a text >>> box >>> > of my GUI. One thing I cannot think of how to do is to redefine stdin >>> > so that it pauses the program, waits for a user to type input into >>> the >>> > box, hit enter, and takes input from another text element and >>> sends it >>> > to python like it was the console. >>> >>> I suspect you don't really want to redirect stdin, but instead >>> implement >>> raw_input(). [...]Try changing __builtins__.raw_input to reference >>> your new >>> function. >> >> But what would the function do? How would it pause python and wait for >> it to have text to send? > > Whatever you want. You don't have to "pause python", Python itself > won't resume until your function doesn't return. (You should release > the GIL if your C++ function doesn't call back to Python code, to > allow other threads to continue, but that's another story). > This is a raw_input replacement written in Tkinter; it shows a dialog > box instead of reading from stdin: > > py> from Tkinter import * > py> from tkSimpleDialog import askstring > py> def my_raw_input(prompt): > ... return askstring("Python", prompt) > ... > py> root = Tk() > py> import __builtin__ > py> __builtin__.raw_input = my_raw_input > py> > py> raw_input("What's your name?") > 'Gabriel' > > > ------------------------------------------------------------------------ > I think I see the OP's problem. He has written a GUI program in C++, and is using (embedding) Python functions into it. So presumably those functions are being called from events in the C++ event loop. If one of those functions tries to call back into C++ code, the event loop will never get control, to process the events from the standard UI controls. So if the input is to be handled as an integral part of the C++ UI, there's a distinct problem. On the other hand, Gabriel's dialog box should work fine, as long as you don' t mind a modal dialog box as a solution. I don't know tkinter's askstring, but I suspect it'd work. However, the rest of the C++ GUI would be frozen, which could be a problem. DaveA From wuwei23 at gmail.com Sun Nov 1 21:33:57 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 18:33:57 -0800 (PST) Subject: About one class/function per module References: Message-ID: <8f259645-f704-4bde-bcde-58562cc7a196@b25g2000prb.googlegroups.com> Peng Yu wrote: > So I am asking disadvantages besides python import mechanism is not > friendly to it. Which part of "name collisions have to be resolved somehow" isn't explicit enough for you? You can't keep saying "this works in C++" while refusing to accept that this is an implementation decision with Python. At least be honest about what you're asking for, which is confirmation of your existing bias. From ThadSmith at acm.org Sun Nov 1 21:44:29 2009 From: ThadSmith at acm.org (Thad Smith) Date: Sun, 01 Nov 2009 20:44:29 -0600 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7ktsj6F3bciqlU1@mid.individual.net> Message-ID: <4aee4796$0$77552$892e0abb@auth.newsreader.octanews.com> Richard Heathfield wrote: > ... so I cheerfully installed it on the > user's desktop machine (Windows ME, would you believe), and then set > about configuring the reader, when... ouch! No PDF reader on the > machine. Not even an ancient Adobe version. Oh dear. Program suddenly > rendered completely useless for that person. There is a Catch 22 for installing Adobe Reader from the Adobe site ( http://get.adobe.com/reader/ ) for the first time, without making a blind promise: "By clicking the Download button you agree to the License Agreements and Privacy Policies for the software included." Guess what format the license agreement is in. ;-) -- Thad From davea at ieee.org Sun Nov 1 21:52:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 01 Nov 2009 21:52:19 -0500 Subject: About one class/function per module In-Reply-To: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> References: <366c6f340911011411s22fc5ad5x5a80cbd31b4cc5d@mail.gmail.com> Message-ID: <4AEE4963.6070008@ieee.org> Peng Yu wrote: > > > Some people mentioned an good IDE can do 1 and 4. But I'm not aware of > an IDE that can allow me to change file name freely. I tried Visual > Studio long time ago, I have to delete a file, change the file name > and add the file back in order to change the file. > > I use Komodo IDE version 5, where right-click->Rename works fine on files within a project. > Now let us consider how well python can support one function/class per > file style. I encounter the following problems. Suppose that the > parent directory of 'test' is in $PYTHONPATH and __init__.py is empty, > > test/ > |-- __init__.py > |-- A.py > `-- B.py > > where A.py has only class A and B.py has only class B. > > The end user of the test package has to either > > import test.A > a=test.A.A() > > or > > from test.A import A > a=A() > > I'm neither agreeing nor disagreeing with the self-imposed restriction of one class per module. But I'd like to jump in with an idea on dealing with the namespaces involved. How about a two-line import, where the second line is a simple assignment? import test.A test.A = test.A.A Now, you can use the class A just as you wanted -- obj = test.A() This has the disadvantage that the module itself is no longer addressable from here. But since the only symbol you apparently want from the module is the one class, it should be fine. And you could presumably have saved it in a module-specific global anyway. Note that I did not test whether other modules that also import test.A are affected. So some further study would be necessary. Also, I tried it only in CPython 2.6.2 DaveA From pjb at informatimago.com Sun Nov 1 21:59:19 2009 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 02 Nov 2009 03:59:19 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) References: <7ktsj6F3bciqlU1@mid.individual.net> <4aee4796$0$77552$892e0abb@auth.newsreader.octanews.com> Message-ID: <87fx8xhbso.fsf@galatea.local> Thad Smith writes: > Richard Heathfield wrote: > >> ... so I cheerfully installed it on the user's desktop machine >> (Windows ME, would you believe), and then set about configuring the >> reader, when... ouch! No PDF reader on the machine. Not even an >> ancient Adobe version. Oh dear. Program suddenly rendered completely >> useless for that person. > > There is a Catch 22 for installing Adobe Reader from the Adobe site ( > http://get.adobe.com/reader/ ) for the first time, without making a > blind promise: "By clicking the Download button you agree to the > License Agreements and Privacy Policies for the software included." > Guess what format the license agreement is in. ;-) Use xpdf to read it! Then use xpdf to read the other pdf documents, and forget about proprietary software? -- __Pascal Bourguignon__ From highcar at gmail.com Sun Nov 1 22:08:08 2009 From: highcar at gmail.com (elca) Date: Sun, 1 Nov 2009 19:08:08 -0800 (PST) Subject: disable image loading to speed up webpage load Message-ID: <26155440.post@talk.nabble.com> Hi, im using win32com 's webbrowser module. i have some question about it.. is it possible to disable image loading to speed up webpage load? any help ,much appreciate thanks in advance -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26155440.html Sent from the Python - python-list mailing list archive at Nabble.com. From rustompmody at gmail.com Sun Nov 1 22:12:07 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 1 Nov 2009 19:12:07 -0800 (PST) Subject: About one class/function per module References: Message-ID: <4b6a8a1a-30ff-43bd-a0ba-9bfe076e530e@m33g2000pri.googlegroups.com> On Nov 2, 3:11?am, Peng Yu wrote: > I recently asked how to support one class/function per module under > the title 'How to import only one module in a package when the package > __init__.py has already imports the modules?' I summarize my key > points below. In particular, I have to two questions: > 1. What disadvantages there are to enforce one class/function per file? > 2. How to better support one class/function per file in python? Others have told you to discard your biases. I would tell you to suspend them for a while (including our biases against your biases) and try to use emacs+ecb > > ------------------------------------------------------------------------------ > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. > > The advantages of one-function/class-per-file that I am aware of are > the following items (maybe incomplete). > ? 1. It is easy to see what functions and classes there are just by > browsing the source directory, without the need of opening the file by > an editor. Primary intention of ecb > ? 2. Testing code for a function/class can be organized along with the > module for the function/class, which also makes it easier to keep > track of the testing code for any function/class. > ? 3. It is easy to move a function/class from one package to another > by just moving files around. If an editing task is found hard it just means youve never used emacs! > ? 4. It is easy change variable names, etc., for a function/class by > replacement in a file without worrying accidentally change variable > names in other functions. > I have used the above approach on a C++ project. And I use vim + ctags > to navigate from a reference of a class/funciton to its definition. So > far it works fine. Should be possible to code this up in about 10 lines of emacs Simple workaround is to select the function/class and run search- replace on the selection From wuwei23 at gmail.com Sun Nov 1 22:23:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 1 Nov 2009 19:23:21 -0800 (PST) Subject: Regular express question References: Message-ID: <602d2997-1148-4888-a474-326daaf03380@u36g2000prn.googlegroups.com> On Oct 31, 12:48?pm, elca wrote: > Hello, > i have some text document to parse. > sample text is such like follow > in this document, i would like to extract such like > SUBJECT = 'NETHERLANDS MUSIC EPA' > CONTENT = 'Michael Buble performs in Amsterdam Canadian singer Michael Buble > performs during a concert in Amsterdam, The Netherlands, 30 October 2009. > Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK ' > > if anyone help me,much appreciate > > " > NETHERLANDS MUSIC EPA | 36 before > Michael Buble performs in Amsterdam Canadian singer Michael Buble performs > during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble > released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK > " You really don't need regular expressions for this: >>> import os >>> eol = os.linesep >>> text = ''' ... NETHERLANDS MUSIC EPA | 36 before ... Michael Buble performs in Amsterdam Canadian singer Michael Buble performs ... during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble ... released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK ... ''' >>> text = text.strip() # remove eol markers >>> subject = text.split(' | ')[0] >>> content = ' '.join(text.split(eol)[1:]) >>> subject 'NETHERLANDS MUSIC EPA' >>> content "Michael Buble performs in Amsterdam Canadian singer Michael Buble performs during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK" From lord_eldritch at yahoo.co.uk Sun Nov 1 22:23:26 2009 From: lord_eldritch at yahoo.co.uk (Lord Eldritch) Date: Mon, 02 Nov 2009 04:23:26 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * MRAB: Thank you all! It is working now nicely! God! I love usenet..:D -- Lord Eldritch From steven at REMOVE.THIS.cybersource.com.au Sun Nov 1 23:01:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2009 04:01:12 GMT Subject: About one class/function per module References: <8f259645-f704-4bde-bcde-58562cc7a196@b25g2000prb.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 18:33:57 -0800, alex23 wrote: > Peng Yu wrote: >> So I am asking disadvantages besides python import mechanism is not >> friendly to it. > > Which part of "name collisions have to be resolved somehow" isn't > explicit enough for you? > > You can't keep saying "this works in C++" while refusing to accept that > this is an implementation decision with Python. Oh, it doesn't work to Peng Yu's satisfaction in C++ either. In an earlier email, he wrote: "I'm not complaining. I just wish there is a walkaround. In C++, I still have to write some script to make sure the directory hierarchy is consistent with the namespace, because C++ doesn't impose the constraint that the directory hierarchy is the same as the namespace. But it seems that is no such walkaround in python for my case, because python binds namespace to directory hierarchy." You got that? In Python, which forces the namespace and directory hierarchy to be the same, he wants them to be independent; in C++, which relaxes that restriction, he writes scripts to force them to be the same. [Aside: the word is "work-around" not "walk-around". Easy mistake to make.] -- Steven From cleberwillian at gmail.com Sun Nov 1 23:02:16 2009 From: cleberwillian at gmail.com (Cleber Santos) Date: Mon, 2 Nov 2009 02:02:16 -0200 Subject: spring effect in Python In-Reply-To: <553f6683-a463-43e6-aa0c-dcff81863786@g23g2000yqh.googlegroups.com> References: <553f6683-a463-43e6-aa0c-dcff81863786@g23g2000yqh.googlegroups.com> Message-ID: <6a8a14a20911012002x6c1faee8vdcc76bcc1b86f471@mail.gmail.com> You can try this: http://processingjs.org On Fri, Oct 30, 2009 at 5:26 AM, pochis40 wrote: > I'm trying to write in Python something similar to this: > (Java) > http://java.sun.com/applets/jdk/1.4/demo/applets/GraphLayout/example1.html > or these: > (Proce55ing) > http://www.cricketschirping.com/processing/ExportAtlas/ > or > > http://www.cricketschirping.com/weblog/2005/12/11/force-directed-graph-layout-with-proce55ing/ > or > > http://www.cricketschirping.com/weblog/2007/02/26/force-directed-graph-layout-with-processing-take-2/ > > I've problem to find something that give that physical effect (like a > spring). > > Any idea? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Cleber Santos website: binho.net skype: binhoweb msn: msn at binho.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sun Nov 1 23:50:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 01:50:41 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> <4AEE0546.4040509@mrabarnett.plus.com> Message-ID: En Sun, 01 Nov 2009 19:01:42 -0300, MRAB escribi?: > Gabriel Genellina wrote: >>>> One way to avoid name clashes would be to put the entire standard >>>> library under a package; a program that wants the standard re >>>> module would write "import std.re" instead of "import re", or >>>> something similar. >>> You could do it in a backwards compatible way, by adding the std >>> package directory into the path. >> Unfortunately you can't, at least not without some special treatment >> of the std package. One of the undocumented rules of the import >> system is that you must not have more than one way to refer to the >> same module (in this case, std.re and re). [...] > Couldn't the entry in sys.modules be where the module was found, so that > if 're' was found in 'std' then the entry is 'std.re' even if the import > said just 're'? What about a later 'import re'? 're' would not be found in sys.modules then. In any case, it requires a change in the current behavior, a PEP, and a lot of discussion... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 00:11:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 02:11:58 -0300 Subject: import bug References: <02fd10ee$0$1326$c3e8da3@news.astraweb.com> <02fdff3a$0$1326$c3e8da3@news.astraweb.com> Message-ID: En Sun, 01 Nov 2009 19:51:04 -0300, Steven D'Aprano escribi?: > On Sun, 01 Nov 2009 17:34:19 -0300, Gabriel Genellina wrote: >> En Sun, 01 Nov 2009 02:54:15 -0300, Steven D'Aprano escribi?: >>> Shadowing a standard library module >>> is no different. >> >> But that's what namespaces are for; if the standard library had its own >> namespace, such collisions would not occur. > > Sure. But that's not a bug in the import system. If it's a bug, it's a > bug in the layout of the standard library. Half and half? The standard library cannot have a different structure because the import system cannot handle it in a backgwards compatible way? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 01:12:36 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 03:12:36 -0300 Subject: About one class/function per module References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> Message-ID: En Sun, 01 Nov 2009 22:27:32 -0300, Peng Yu escribi?: > On Sun, Nov 1, 2009 at 7:02 PM, alex23 wrote: >> On Nov 2, 8:11 am, Peng Yu wrote: >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> You mean, what disadvantages it has _other_ than the ones you've been >> experiencing? >> >> Aren't those enough to warrant actually working with Python's import >> mechanism rather than against it? > > At least, I can use the following for now with one class/function per > module. Unless this one class/function per module style have other > disadvantages in term software engineering, I still can live with > typing the class name (e.g. 'A') twice. > > import test.A > a=test.A.A() > > So I am asking disadvantages besides python import mechanism is not > friendly to it. You don't type the class name twice. One 'A' is a module name, the other 'A' is the class name. In C++, a source file is just a compilation unit, only relevant for certain rules regarding visibility; it doesn't matter really in which source file the code is written in. In Python, a source file becomes a module. A module is an object: it is created (usually by importing it), it has attributes, there are module hierarchies (packages), contains other objects... A module is an important object in Python. You should not confuse the module with the class (or classes) that are defined inside it. In your example above, test.A is a module, test.A.A is a class; they're not the same thing. You may put one class per file, nobody forbids that - but remember that the class and the module are different objects. If you follow PEP8 conventions, module names are all in lowercase, and class names use TitleCase. This helps avoid confusion. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 2 01:20:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 03:20:37 -0300 Subject: stdin in embedded python References: <9ab67bd8-f6a5-4db4-9b68-4357b8bbcddf@15g2000yqy.googlegroups.com> <4AEE4036.8000405@ieee.org> Message-ID: En Sun, 01 Nov 2009 23:13:10 -0300, Dave Angel escribi?: > Gabriel Genellina wrote: >> En Sun, 01 Nov 2009 13:34:44 -0300, KillSwitch >> escribi?: >>> On Nov 1, 5:34 am, Dave Angel wrote: >>>> KillSwitch wrote: >> >>>> > I have a C++ program, with a GUI, into which I have embedded >>>> python. I >>>> > have made several python functions in C++, one of which I use to >>>> > override the normal stdout and stderr so that they print to a text >>>> box >>>> > of my GUI. One thing I cannot think of how to do is to redefine >>>> stdin >>>> > so that it pauses the program, waits for a user to type input into >>>> the >>>> > box, hit enter, and takes input from another text element and sends >>>> it >>>> > to python like it was the console. >>>> >>>> I suspect you don't really want to redirect stdin, but instead >>>> implement >>>> raw_input(). >>> >>> But what would the function do? How would it pause python and wait for >>> it to have text to send? >> >> Whatever you want. You don't have to "pause python", Python itself >> won't resume until your function doesn't return. [example using >> Tkinter.askstring] >> > I think I see the OP's problem. He has written a GUI program in C++, > and is using (embedding) Python functions into it. So presumably those > functions are being called from events in the C++ event loop. > > If one of those functions tries to call back into C++ code, the event > loop will never get control, to process the events from the standard UI > controls. > > So if the input is to be handled as an integral part of the C++ UI, > there's a distinct problem. > > On the other hand, Gabriel's dialog box should work fine, as long as you > don' t mind a modal dialog box as a solution. I don't know tkinter's > askstring, but I suspect it'd work. However, the rest of the C++ GUI > would be frozen, which could be a problem. Perhaps looking a other examples may help. Both IDLE and PythonWin replace raw_input with a message box; IDLE is a Tkinter application, and PythonWin wraps MFC. Both have a main message loop and use a modal message box. -- Gabriel Genellina From jbperez at gmail.com Mon Nov 2 02:54:16 2009 From: jbperez at gmail.com (Jon P.) Date: Sun, 1 Nov 2009 23:54:16 -0800 (PST) Subject: substituting list comprehensions for map() Message-ID: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> I'd like to do: resultlist = operandlist1 + operandlist2 where for example operandlist1=[1,2,3,4,5] operandlist2=[5,4,3,2,1] and resultlist will become [6,6,6,6,6]. Using map(), I can do: map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) Is there any reasonable way to do this via a list comprehension ? From javier.collado at gmail.com Mon Nov 2 02:58:04 2009 From: javier.collado at gmail.com (Javier Collado) Date: Mon, 2 Nov 2009 08:58:04 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: Hello, I'll do the following: [op1+op2 for op1,op2 in zip(operandlist1, operandlist2)] Best regards, Javier 2009/11/2 Jon P. : > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. ?Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Mon Nov 2 02:59:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 00:59:44 -0700 Subject: substituting list comprehensions for map() In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <50697b2c0911012359x1648b833j3acd1340b2ea0992@mail.gmail.com> On Mon, Nov 2, 2009 at 12:54 AM, Jon P. wrote: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. ?Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? results = [x+y for x,y in zip(list1, list2)] Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Nov 2 03:13:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Nov 2009 08:13:50 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. Using map(), I can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) If the two lists are very large, it would be faster to use this: from operator import add map(add, operandlist1, operandlist2) > Is there any reasonable way to do this via a list comprehension ? [x+y for (x, y) in zip(operandlist1, operandlist2)] If the lists are huge, you can save some temporary memory by replacing zip with itertools.izip. -- Steven From paul.nospam at rudin.co.uk Mon Nov 2 03:17:59 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 02 Nov 2009 08:17:59 +0000 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87iqdtibm0.fsf@rudin.co.uk> "Jon P." writes: > I'd like to do: > > resultlist = operandlist1 + operandlist2 > > where for example > > operandlist1=[1,2,3,4,5] > operandlist2=[5,4,3,2,1] > > and resultlist will become [6,6,6,6,6]. Using map(), I > can do: > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? You can do it as a list comprehension e.g. like this: [ x + y for x, y in zip(operandlist1, operandlist2)] Note that there is some unnecessary list building going on here and it may be better to use itertools.izip. (In python 3 zip returns an iterator anyhow.) From ben+python at benfinney.id.au Mon Nov 2 03:19:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 19:19:41 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87bpjll4o2.fsf@benfinney.id.au> "Jon P." writes: > I'd like to do: > > resultlist = operandlist1 + operandlist2 That's an unfortunate way of expressing it; it's valid Python syntax that doesn't do what you're describing (in this case, it will bind ?resultlist? to a new list that is the *concatenation* of the two original lists). > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > Is there any reasonable way to do this via a list comprehension ? Yes, just about any ?map()? operation has a corresponding list comprehension. (Does anyone know of a counter-example, a ?map()? operation that doesn't have a correspondingly simple list comprehension?) For the above case, this is how it's done:: >>> operandlist1 = [1, 2, 3, 4, 5] >>> operandlist2 = [5, 4, 3, 2, 1] >>> resultlist = [(a + b) for (a, b) in zip(operandlist1, operandlist2)] >>> resultlist [6, 6, 6, 6, 6] -- \ ?Creativity can be a social contribution, but only in so far as | `\ society is free to use the results.? ?Richard Stallman | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 03:49:34 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 09:49:34 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <87bpjll4o2.fsf@benfinney.id.au> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <4aee9d1e$0$19304$426a74cc@news.free.fr> Ben Finney a ?crit : (snip) > Yes, just about any ?map()? operation has a corresponding list > comprehension. Right AFAICT, but: > (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) ... depends on your definition of "simple". There are things I'd rather not write as a list comprehension... From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 03:55:57 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 09:55:57 +0100 Subject: About one class/function per module In-Reply-To: References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> Message-ID: <4aee9e9d$0$19304$426a74cc@news.free.fr> Gabriel Genellina a ?crit : >>> On Nov 2, 8:11 am, Peng Yu wrote: > >>>> I prefer organized my code one class/function per file (i.e per module >>>> in python). I know the majority of programmers don't use this >>>> approach. Therefore, I'm wondering what its disadvantage is. >>> (snip) > You may put one class per file, nobody forbids that But anyone having to work on your code will hate you. From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 04:03:58 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 10:03:58 +0100 Subject: About one class/function per module In-Reply-To: References: Message-ID: <4aeea07e$0$713$426a34cc@news.free.fr> Peng Yu a ?crit : (snip) > I prefer organized my code one class/function per file (i.e per module > in python). I know the majority of programmers don't use this > approach. Therefore, I'm wondering what its disadvantage is. Hmmm... As far as I'm concerned, you already answered your own question: "the majority of programmers don't use this approach". Now, for a much more practical answer: 1/ having to handle thousands of files for even a simple project is a king-size PITA for the maintainer. 2/ having to load thousands of modules will add quite a lot of overhead when actually running the code. 3/ as a result, the poor guy that will end up maintaining your code will positively hate you. Beware : this poor guy might as well be you. From eric.brunel.pragmadev at gmail.com Mon Nov 2 04:07:45 2009 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Mon, 2 Nov 2009 01:07:45 -0800 (PST) Subject: Tkinter callback arguments References: Message-ID: On Nov 1, 8:53 pm, Lord Eldritch wrote: > Hi > > Maybe this is maybe something it has been answered somewhere but I haven't > been able to make it work. I wanna pass one variable to a callback function > and I've read the proper way is: > > Button(......, command=lambda: function(x)) > > So with > > def function(a): print a > > I get the value of x. Ok. My problem now is that I generate the widgets in a > loop and I use the variable to 'label' the widget: > > for x in range(0,3): Button(......, command=lambda: function(x)) > > so pressing each button should give me 0,1,2. > > But with the lambda, I always get the last index, because it gets actualized > at each loop cycle. Is there any way to get that? for x in range(0,3): Button(..., command=functools.partial(function, x)) With the functools standard module that appeared in version 2.5, I hardly ever use lambdas in Tkinter callbacks now. > Thanks in advance! HTH From neilcrighton at gmail.com Mon Nov 2 04:24:13 2009 From: neilcrighton at gmail.com (Neil Crighton) Date: Mon, 2 Nov 2009 09:24:13 +0000 (UTC) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes: > > > > operandlist1=[1,2,3,4,5] > > operandlist2=[5,4,3,2,1] > > > > and resultlist will become [6,6,6,6,6]. Using map(), I can do: > > > > map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > If the two lists are very large, it would be faster to use this: > If the two lists are *very* large and every element in each list has the same type, you should use NumPy arrays (http://numpy.scipy.org/). >>> import numpy >>> operandlist1 = numpy.array([1, 2, 3, 4, 5]) >>> operandlist2 = numpy.array([5, 4, 3, 2, 1]) >>> resultlist = operandlist1 + operandlist2 >>> resultlist array([6, 6, 6, 6, 6]) Neil From __peter__ at web.de Mon Nov 2 04:26:17 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 10:26:17 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: >> for x in range(0,3): >> Button(......, command=lambda x=x: function(x)) > > An alternative reusable alternative is to create a button-with-id class. > > This is my very first Python class so I'm guessing that there are all > sorts of issues, in particular naming conventions. Pseudo-private attributes, javaesque getter methods, unidiomatic None- checks, broken naming conventions (**args), spaces in funny places... > And the idea of creating a reusable solution for such a small issue may be > un-pythonic? Screw pythonic, the signal/noise ratio is awful in any language. > But just as an example, in Python 3.x, ...for achieving less in more lines? > > import tkinter > # I guess for Python 2.x do "import Tkinter as tkinter" but haven't > # tested. > > > class IdButton( tkinter.Button ): > def __init__( self, owner_widget, id = None, command = None, **args > ): > tkinter.Button.__init__( > self, owner_widget, args, command = self.__on_tk_command > ) > self.__id = id > self.__specified_command = command > > def __on_tk_command( self ): > if self.__specified_command != None: > self.__specified_command( self ) > else: > self.on_clicked() > > def on_clicked( self ): > pass > def id( self ): > return self.__id > def id_string( self ): > return str( self.id() ); > > > def on_button_click( aButton ): > print( "Button " + aButton.id_string() + " clicked!" ) > > window = tkinter.Tk() > > n_buttons = 3 > for x in range( 1, n_buttons + 1 ): > IdButton( > window, id = x, text = "Button " + str( x ), command = > on_button_click ).pack() > > window.mainloop() > I'm not grumpy, I just don't like your code ;) And I don't like the notion that you are about to spread this style with your book... Peter From Brian.Mingus at Colorado.EDU Mon Nov 2 04:37:20 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 2 Nov 2009 02:37:20 -0700 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: <9839a05c0911020137q75a934abq4dcb2f32a6905a54@mail.gmail.com> On Mon, Nov 2, 2009 at 2:26 AM, Peter Otten <__peter__ at web.de> wrote: > Alf P. Steinbach wrote: > > >> for x in range(0,3): > >> Button(......, command=lambda x=x: function(x)) > > > > An alternative reusable alternative is to create a button-with-id class. > > > > This is my very first Python class so I'm guessing that there are all > > sorts of issues, in particular naming conventions. > > Pseudo-private attributes, javaesque getter methods, unidiomatic None- > checks, broken naming conventions (**args), spaces in funny places... > > > And the idea of creating a reusable solution for such a small issue may > be > > un-pythonic? > > Screw pythonic, the signal/noise ratio is awful in any language. > > > But just as an example, in Python 3.x, > > ...for achieving less in more lines? > > > > > import tkinter > > # I guess for Python 2.x do "import Tkinter as tkinter" but haven't > > # tested. > > > > > > class IdButton( tkinter.Button ): > > def __init__( self, owner_widget, id = None, command = None, **args > > ): > > tkinter.Button.__init__( > > self, owner_widget, args, command = self.__on_tk_command > > ) > > self.__id = id > > self.__specified_command = command > > > > def __on_tk_command( self ): > > if self.__specified_command != None: > > self.__specified_command( self ) > > else: > > self.on_clicked() > > > > def on_clicked( self ): > > pass > > def id( self ): > > return self.__id > > def id_string( self ): > > return str( self.id() ); > > > > > > def on_button_click( aButton ): > > print( "Button " + aButton.id_string() + " clicked!" ) > > > > window = tkinter.Tk() > > > > n_buttons = 3 > > for x in range( 1, n_buttons + 1 ): > > IdButton( > > window, id = x, text = "Button " + str( x ), command = > > on_button_click ).pack() > > > > window.mainloop() > > > > I'm not grumpy, I just don't like your code ;) And I don't like the notion > that you are about to spread this style with your book... > > Peter I was going to agree with you ( particularly about this ) but then I saw your __email address__ and realized that you, too, have no style. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 2 04:38:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 10:38:27 +0100 Subject: disable image loading to speed up webpage load In-Reply-To: References: Message-ID: <7l7nklF3cgpk3U1@mid.uni-berlin.de> elca schrieb: > Hi, > im using win32com 's webbrowser module. > i have some question about it.. > is it possible to disable image loading to speed up webpage load? > any help ,much appreciate > thanks in advance Use urllib2. Diez From deets at nospam.web.de Mon Nov 2 04:39:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 10:39:49 +0100 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7l7nn7F3cgpk3U2@mid.uni-berlin.de> Steven D'Aprano schrieb: > On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 >> >> where for example >> >> operandlist1=[1,2,3,4,5] >> operandlist2=[5,4,3,2,1] >> >> and resultlist will become [6,6,6,6,6]. Using map(), I can do: >> >> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > > If the two lists are very large, it would be faster to use this: > > > from operator import add > map(add, operandlist1, operandlist2) > > >> Is there any reasonable way to do this via a list comprehension ? > > [x+y for (x, y) in zip(operandlist1, operandlist2)] > > If the lists are huge, you can save some temporary memory by replacing > zip with itertools.izip. And even more so if one needs the results one by one - then just use a generator-expression. Diez From ben+python at benfinney.id.au Mon Nov 2 05:01:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 21:01:48 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <4aee9d1e$0$19304$426a74cc@news.free.fr> Message-ID: <877hu9kzxv.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Ben Finney a ?crit : > > (Does anyone know of a counter-example, a ?map()? operation that > > doesn't have a correspondingly simple list comprehension?) > > ... depends on your definition of "simple". There are things I'd > rather not write as a list comprehension... That's why I qualified it as I did. I'd be interested to know a ?map()? usage where there isn't a correspondingly simple list comprehension; that is, one that couldn't be done without being significantly more complex than the corresponding ?map()? usage. -- \ ?If we have to give up either religion or education, we should | `\ give up education.? ?William Jennings Bryan, 1923-01 | _o__) | Ben Finney From ben+python at benfinney.id.au Mon Nov 2 05:03:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Nov 2009 21:03:54 +1100 Subject: About one class/function per module References: <366c6f340911011727gde0af7fwed5c275c1268d363@mail.gmail.com> <4aee9e9d$0$19304$426a74cc@news.free.fr> Message-ID: <873a4xkzud.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Gabriel Genellina a ?crit : > > You may put one class per file, nobody forbids that > > But anyone having to work on your code will hate you. And if you can find anyone to collaborate with who can stand your insistence on putting one *function* per file, you should probably marry them as being your soul mate. -- \ ?We tend to scoff at the beliefs of the ancients. But we can't | `\ scoff at them personally, to their faces, and this is what | _o__) annoys me.? ?Jack Handey | Ben Finney From SSchukat at dspace.de Mon Nov 2 05:26:42 2009 From: SSchukat at dspace.de (Stefan Schukat) Date: Mon, 2 Nov 2009 11:26:42 +0100 Subject: AW: Python2.6 + win32com crashes with unicode bug In-Reply-To: <4AEB1BAD.4080805@planet.nl> References: <4ae9e43f$0$1637$703f8584@textnews.kpn.nl> <4AEB1BAD.4080805@planet.nl> Message-ID: <9015A9FD792E914DADD11DDEB0753338431B592490@exchange2007.dspace.de> Hello Gerrit, there is no problem in the file, but in the description of the Visio API. The place where the error occurs is during the definition of the parameters of the corresponding Python methods. The information for the names comes from the typelibrary of visio. Probably there is a non english name inside the typelibrary (MS used native names in early Office products) which then could not decoded to a correct Python name. In my Version of Vsio OpenEx has two parameters called FileName and Flags. You have to look in your typelibrary, e.g. with OleView http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en and check the parameters. Regards Stefan -----Urspr?ngliche Nachricht----- Von: python-list-bounces+sschukat=dspace.de at python.org [mailto:python-list-bounces+sschukat=dspace.de at python.org] Im Auftrag von GerritM Gesendet: Freitag, 30. Oktober 2009 18:00 An: Terry Reedy Cc: python-list at python.org Betreff: Re: Python2.6 + win32com crashes with unicode bug Terry Reedy schreef: > GerritM wrote: >> I have automated image generation with Python, win32com and Visio5.0. >> This works well upto Python2.5 but fails with Python 2.6. >> Short term solution is to return to 2.5 :-(. >> >> I have reproduced the bug below with a minimum of Python lines. Below >> the problem the working example from 2.5 >> >> kind regards, Gerrit >> >> ---minimal session reproducing the bug--- >> <..snip..> >> d = v.Documents.OpenEx("D:/temp/test.vsd",8) <...snip...> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position >> 52: ordinal not in range(128) > > I suspect that 2.6 fixed the bug of allowing non-ascii chars when using > the ascii codec. I would check to see if there is an 0x83 in > D:/temp/test.vsd > <...snip...> the string "D:/temp/test.vsd" itself does not contain any charactervalue>128: >>> for c in "D:/temp/test.vsd": print ord(c), " ", 68 58 47 116 101 109 112 47 116 101 115 116 46 118 115 100 (on my current Python 2.5 configuration) The presumably binary file itself may contain any value, but I don't expect Python or win32com to do anything with the file content... There are explanations on internet that Windows uses internally 2 (incompatible) API's that cause poblems with Unicode based filenames. I do something like that to be the problem in Python 2.6 kind regards, Gerrit -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Mon Nov 2 05:37:43 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 11:37:43 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > Alf P. Steinbach wrote: > >>> for x in range(0,3): >>> Button(......, command=lambda x=x: function(x)) >> An alternative reusable alternative is to create a button-with-id class. >> >> This is my very first Python class so I'm guessing that there are all >> sorts of issues, in particular naming conventions. > > Pseudo-private attributes That means there is some way of making attributes private? Probably that comes across as an inane question but I ask it anyway. I haven't really started to look at Python classes. I'm guessing that by asking here I may learn things that are not obvious from the documentation. >, javaesque getter methods, What do you mean by that? What I associate with Java getter method is mainly the "get" prefix, for Java introspection. > unidiomatic None-checks What's the idiomatic Python way for an optional thing? In this case one alternative I see could be to get rid of the __on_tc_command method and more directly tell tkinter.Button to call the relevant function, doing the if-else choice once only in the IdButton constructor. Is that what you mean? I'm thinking more in terms of customization points when I write code. So I tend to avoid hardcoding things internally in methods, instead designing the choices out to where they're accessible to client code. >, broken naming conventions (**args), How to do this argument forwarding in modern style? Or is there an alternative to argument forwarding for this example? > spaces in funny places... Bah. ;-) >> And the idea of creating a reusable solution for such a small issue may be >> un-pythonic? > > Screw pythonic, the signal/noise ratio is awful in any language. > >> But just as an example, in Python 3.x, > > ...for achieving less in more lines? Now, that's a good Python-independent question! :-) Re your question's the number of lines: /if/ the code is heavily reused then the number of lines doesn't matter since they're only written /once/; the net effect can even be to reduce the total number of lines, or at least the number of apparent function points (or whatever size metric). That's part of what "reusable" means. For example, if the OP used the code then he or she didn't type them lines, but just copy/paste'd them, less work than typing in a lambda definition in every button creation, and more clear code at every creation. Re your question's what (the) reusability achieves. First, when you and others have used such a thing in a number of places then you gain confidence in correctness. For example, you don't wonder whether Python's str type is correct, and when you test your program you don't test the str type implementation. Since it's been used so much you know that it (mainly) is correct, and that any remaining bug in there can't be all that serious, because if it was then it would've surfaced in earlier use of the type. This advantage of confidence in correctness can be realized even without heavy reuse, because the encapsulation that's necessary for reuse, here having the code in a class, also makes it possible with more centralized testing. A centralized, encapsulated piece of code can be tested to death and deemed correct (enough) and frozen, while the application of a code pattern in umpteen places in umpteen programs, generally can't. Second, when you do find a bug, or need more functionality, or whatever, there's just /one place/ to fix/extend, whatever, instead of updating umpteen places in umpteen programs, and trying to be sure that you've covered all instances and done the right thing every place regardless of local variations (which is pretty hopeless in general, but my experience with that kind of badness has mostly been with C, not Python). More technically, it's reduced redundancy, in this case avoiding redundant application of a code pattern everywhere one needs a button with id (if that happens often). Reduced redundancy = good. And third, as I mentioned, at every button creation, or in general every place you'd use inline code rather than some reusable thing, you can get more clear code, which can (but will not automatically :-) ) reduce maintainance time. But, the big drawback. It's easy to become enamoured by reusability and invest a lot of work in encapsulation and general reusability, since it has those three big desirable traits. But when what one creates is not actually reused then most of that work can be /wasted/... :-) For example, if the code only is used in 1 place, then the advantage of centralized testing is pretty moot unless that code is changing for other reasons, for it doesn't matter much if you test it here or there. It can be simpler to test it here, inline, than over there. And another big drawback, but I believe it's less important in Python, that a reusable thing can be less efficient because it can't take advantage of locally available information and functionality each place where it's used, while inline code that achieves the same (applying a pattern) can take advantage. >> >> import tkinter >> # I guess for Python 2.x do "import Tkinter as tkinter" but haven't >> # tested. >> >> >> class IdButton( tkinter.Button ): >> def __init__( self, owner_widget, id = None, command = None, **args >> ): >> tkinter.Button.__init__( >> self, owner_widget, args, command = self.__on_tk_command >> ) >> self.__id = id >> self.__specified_command = command >> >> def __on_tk_command( self ): >> if self.__specified_command != None: >> self.__specified_command( self ) >> else: >> self.on_clicked() >> >> def on_clicked( self ): >> pass >> def id( self ): >> return self.__id >> def id_string( self ): >> return str( self.id() ); >> >> >> def on_button_click( aButton ): >> print( "Button " + aButton.id_string() + " clicked!" ) >> >> window = tkinter.Tk() >> >> n_buttons = 3 >> for x in range( 1, n_buttons + 1 ): >> IdButton( >> window, id = x, text = "Button " + str( x ), command = >> on_button_click ).pack() >> >> window.mainloop() >> > > I'm not grumpy, I just don't like your code ;) And I don't like the notion > that you are about to spread this style with your book... He he. :-) I've yet to acquire any Python style. Cheers, & thanks, - Alf From ilmirons at gmail.com Mon Nov 2 05:41:48 2009 From: ilmirons at gmail.com (Mirons) Date: Mon, 2 Nov 2009 02:41:48 -0800 (PST) Subject: About "Object in list" expression Message-ID: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> Hi everybody! I'm having a very annoying problem with Python: I need to check if a (mutable) object is part of a list but the usual expression return True also if the object isn't there. I've implemented both __hash__ and __eq__, but still no result. what does "in" implementation use for comparison (Python is 2.6)? From joncle at googlemail.com Mon Nov 2 05:46:10 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 2 Nov 2009 02:46:10 -0800 (PST) Subject: About "Object in list" expression References: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> Message-ID: <326c5001-936b-4148-b625-d16b02d9fbc3@v30g2000yqm.googlegroups.com> On Nov 2, 10:41?am, Mirons wrote: > Hi everybody! I'm having a very annoying problem with Python: I need > to check if a (mutable) object is part of a list but the usual > expression return True also if the object isn't there. I've > implemented both __hash__ and __eq__, but still no result. what does > "in" implementation use for comparison (Python is 2.6)? It would help showing an example... From jocjo at mail.dk Mon Nov 2 05:49:32 2009 From: jocjo at mail.dk (Hans Larsen) Date: Mon, 2 Nov 2009 11:49:32 +0100 Subject: exec-function in Python 3.+ Message-ID: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Help! I'm begginer in Python 3.+! If i wih to update a module after an import and chages, How could I do: By "from imp import reload" and then reload(mymodule) or how to use "exec(?)", it is mentoined in docs. In Python ver. <3 reload(module) writes something back to interpretter!, how about exec, which is a function?-:) I,m thanking on the help!! From ilmirons at gmail.com Mon Nov 2 05:59:15 2009 From: ilmirons at gmail.com (Mirons) Date: Mon, 2 Nov 2009 02:59:15 -0800 (PST) Subject: About "Object in list" expression References: <1a2b6b5a-4b34-4659-980b-418305ab5372@v30g2000yqm.googlegroups.com> <326c5001-936b-4148-b625-d16b02d9fbc3@v30g2000yqm.googlegroups.com> Message-ID: <39f99610-b187-41d8-9efb-cb759b935a20@b2g2000yqi.googlegroups.com> On 2 Nov, 11:46, Jon Clements wrote: > On Nov 2, 10:41?am, Mirons wrote: > > > Hi everybody! I'm having a very annoying problem with Python: I need > > to check if a (mutable) object is part of a list but the usual > > expression return True also if the object isn't there. I've > > implemented both __hash__ and __eq__, but still no result. what does > > "in" implementation use for comparison (Python is 2.6)? > > It would help showing an example... I just solved the problem! (Sorry for the bother). It was a matter of inplementation. It's __eq__ that is called for checking instances in list but I had implemented two version of __eq__ in different parts of code and the interpreter chose the wrong one. Excuse me again for the bother. From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 2 06:29:53 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 02 Nov 2009 12:29:53 +0100 Subject: substituting list comprehensions for map() In-Reply-To: <877hu9kzxv.fsf@benfinney.id.au> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <4aee9d1e$0$19304$426a74cc@news.free.fr> <877hu9kzxv.fsf@benfinney.id.au> Message-ID: <4aeec2b0$0$30849$426a74cc@news.free.fr> Ben Finney a ?crit : > Bruno Desthuilliers writes: > >> Ben Finney a ?crit : >>> (Does anyone know of a counter-example, a ?map()? operation that >>> doesn't have a correspondingly simple list comprehension?) >> ... depends on your definition of "simple". There are things I'd >> rather not write as a list comprehension... > > That's why I qualified it as I did. I'd be interested to know a ?map()? > usage where there isn't a correspondingly simple list comprehension; > that is, one that couldn't be done without being significantly more > complex than the corresponding ?map()? usage. I know I've seen the case, and more than once, but I'm afraid I don't have any example to publish here - I'd need to do quite a bit of archeology :-/ From joncle at googlemail.com Mon Nov 2 06:34:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 2 Nov 2009 03:34:08 -0800 (PST) Subject: exec-function in Python 3.+ References: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Message-ID: <81415eb9-76e3-4ccf-b44a-af4e609252a5@w19g2000yqk.googlegroups.com> On 2 Nov, 10:49, "Hans Larsen" wrote: > Help! > ? ? I'm begginer in Python 3.+! > ? ? If i wih to update a module after an import and chages, > ? ? How could I do: > ? ? By "from imp import reload" and then reload(mymodule) > ? ? or how to use "exec(?)", it is mentoined in docs. > ? ? In Python ver. <3 reload(module) writes something back to interpretter!, > how about exec, which is a function?-:) > ? ? I,m thanking on the help!! What makes you think you need to 'reload' a module. If you don't know exactly what you're doing (by saying you're a beginner I'm guessing not...), and aware of the consequences that can follow... I would say, *don't*. There's too much to bite you in the rear (and not a blatant bite from a lion, but rather a playful little kitten that then plays cute and exudes a "moi?" expression). Also, it may help others to post their thoughts if you tried to describe why you think you want to go down this line, and what you're trying to achieve. Jon. From __peter__ at web.de Mon Nov 2 07:18:18 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 13:18:18 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>>> for x in range(0,3): >>>> Button(......, command=lambda x=x: function(x)) >>> An alternative reusable alternative is to create a button-with-id class. >>> >>> This is my very first Python class so I'm guessing that there are all >>> sorts of issues, in particular naming conventions. >> >> Pseudo-private attributes > > That means there is some way of making attributes private? No, there isn't. And the name mangled __attribute is hardly ever needed. Use _attribute to convey the message "If you mess with this attribute you're on your own". > Probably that comes across as an inane question but I ask it anyway. I > haven't really started to look at Python classes. I'm guessing that by > asking here I may learn things that are not obvious from the > documentation. > > >>, javaesque getter methods, > > What do you mean by that? In Java you have a private attribute and a public getter method. In Python you can just make the attribute public, i. e. # bad class A: def __init__(self): self._id = 42 def id(self): return self._id # good class A: def __init__(self): self.id = 42 You can always switch to class A: # assuming 3.x @property def id(self): id = arbitrary_code() return id later. > What I associate with Java getter method is mainly the "get" prefix, for > Java introspection. > > >> unidiomatic None-checks > > What's the idiomatic Python way for an optional thing? if some_value is None: ... > In this case one alternative I see could be to get rid of the > __on_tc_command method and more directly tell tkinter.Button to call the > relevant function, doing the if-else choice once only in the IdButton > constructor. > > Is that what you mean? > > I'm thinking more in terms of customization points when I write code. > > So I tend to avoid hardcoding things internally in methods, instead > designing the choices out to where they're accessible to client code. > > >>, broken naming conventions (**args), > > How to do this argument forwarding in modern style? I meant that keyword args are traditionally named kw or kwargs, the name "args" is normally used for positional arguments: def f(*args, **kw): "whatever" > Or is there an alternative to argument forwarding for this example? > > >> spaces in funny places... > > Bah. ;-) > > >>> And the idea of creating a reusable solution for such a small issue may >>> be un-pythonic? >> >> Screw pythonic, the signal/noise ratio is awful in any language. >> >>> But just as an example, in Python 3.x, >> >> ...for achieving less in more lines? > > Now, that's a good Python-independent question! :-) > > Re your question's the number of lines: /if/ the code is heavily reused > then the number of lines doesn't matter since they're only written /once/; Every time someone has to read the code he will read, hesitate, read again, and then hopefully come to the conclusion that the code does nothing, consider not using it, or if it is not tied into a larger project removing it. > the net effect can even be to reduce the total number of lines, or at > least the number of apparent function points (or whatever size metric). > That's part of what "reusable" means. For example, if the OP used the code > then he or she didn't type them lines, but just copy/paste'd them, less > work than typing in a lambda definition in every button creation, and more > clear code at every creation. But most of your code does *nothing*. > Re your question's what (the) reusability achieves. > > First, when you and others have used such a thing in a number of places > then you gain confidence in correctness. For example, you don't wonder > whether Python's str type is correct, and when you test your program you > don't test the str type implementation. Since it's been used so much you > know that it (mainly) is correct, and that any remaining bug in there > can't be all that serious, because if it was then it would've surfaced in > earlier use of the type. The theory may be OK, but in practice it doesn't always work out. Example: Why do you introduce button.id_string() instead of str(button.id)? The programmer will hesitate, wonder whether to use button.id() or button.id_string(), how the two may interconnect... It feels more like a hoop to jump through than a helpful service providing tried an tested code. > This advantage of confidence in correctness can be realized even without > heavy reuse, because the encapsulation that's necessary for reuse, here > having the code in a class, also makes it possible with more centralized > testing. Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ ? > A centralized, encapsulated piece of code can be tested to death and > deemed correct (enough) and frozen, while the application of a code > pattern in umpteen places in umpteen programs, generally can't. I'd like to see a good test suite for your IdButton class, especially how it copes with the design decision that you can override the on_clicked() stub, or provide a command function, or both. > Second, when you do find a bug, or need more functionality, or whatever, > there's just /one place/ to fix/extend, whatever, instead of updating > umpteen places in umpteen programs, and trying to be sure that you've > covered all instances and done the right thing every place regardless of > local variations (which is pretty hopeless in general, but my experience > with that kind of badness has mostly been with C, not Python). More > technically, it's reduced redundancy, in this case avoiding redundant > application of a code pattern everywhere one needs a button with id (if > that happens often). Reduced redundancy = good. I agree with that maxim. Incidentally I have just found a nice example of redundancy for you: >>> def __on_tk_command( self ): >>> if self.__specified_command != None: >>> self.__specified_command( self ) >>> else: >>> self.on_clicked() Peter From henrik.sorensen at changenetworks.dk Mon Nov 2 07:29:24 2009 From: henrik.sorensen at changenetworks.dk (Henrik Aagaard =?ISO-8859-1?Q?S=F8rensen?=) Date: Mon, 02 Nov 2009 13:29:24 +0100 Subject: Help with SOAPpy and WSDL. Message-ID: <1257164964.22254.0.camel@apollo> I have a problem with SOAPpy and WSDL. It is explained here: http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 Many regards, Henrik From simon at brunningonline.net Mon Nov 2 07:58:03 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 2 Nov 2009 12:58:03 +0000 Subject: Help with SOAPpy and WSDL. In-Reply-To: <1257164964.22254.0.camel@apollo> References: <1257164964.22254.0.camel@apollo> Message-ID: <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> 2009/11/2 Henrik Aagaard S?rensen : > I have a problem with SOAPpy and WSDL. It is explained here: > http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 Why not explain it here? In any case, I imagine the advice is going to be to try Suds - . -- Cheers, Simon B. From deets at nospam.web.de Mon Nov 2 08:07:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 14:07:38 +0100 Subject: Tkinter callback arguments References: Message-ID: <7l83sqF3bac80U1@mid.uni-berlin.de> Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>>> for x in range(0,3): >>>> Button(......, command=lambda x=x: function(x)) >>> An alternative reusable alternative is to create a button-with-id class. >>> >>> This is my very first Python class so I'm guessing that there are all >>> sorts of issues, in particular naming conventions. >> >> Pseudo-private attributes > > That means there is some way of making attributes private? No, it means that in Python we are consenting adults, and either respect attributes with a leading underscore as private - or willfully chose to *not* do that because of good reasons. And the double-underscore is used against name-clashes, not for enhanced "privacy". >>, javaesque getter methods, > > What do you mean by that? > > What I associate with Java getter method is mainly the "get" prefix, for > Java introspection. You have an attribute id, whatfor do you need a method id? If at some point this id becomes a computed value - you introduce a property And that's what Peter meant with "javanesque" - the exact reason why in java everything is wrapped in getters/setters is that the language lacks a property-mechanism, so to present a consistent interface over several iterations of the code, one has to introduce them for every single attribute - regardless of their future destiny. > >> unidiomatic None-checks > > What's the idiomatic Python way for an optional thing? None is a singleton, so the idiomatic check is for object identity: foo = None foo is None Diez From pengyu.ut at gmail.com Mon Nov 2 08:11:28 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 07:11:28 -0600 Subject: About one class/function per module In-Reply-To: <4aeea07e$0$713$426a34cc@news.free.fr> References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers wrote: > Peng Yu a ?crit : > (snip) >> >> I prefer organized my code one class/function per file (i.e per module >> in python). I know the majority of programmers don't use this >> approach. Therefore, I'm wondering what its disadvantage is. > > Hmmm... As far as I'm concerned, you already answered your own question: > "the majority of programmers don't use this approach". > > Now, for a much more practical answer: > 1/ having to handle thousands of files for even a simple project is a > king-size PITA for the maintainer. > 2/ having to load thousands of modules will add quite a lot of overhead when > actually running the code. > 3/ as a result, the poor guy that will end up maintaining your code will > positively hate you. Beware : this poor guy might as well be you. I still don't understand why it is a nightmare to maintain the code. For my C++ project, so far so good. I can easily change filenames (that is class name or function name), I can easily find them, I can easily move things around, all with just the corresponding script command. I can navigate to the definition of class and function by vim + ctags, I can see example code that calls the class/function. Whenever I suspect there is a bug, I can easily go to the right level of class/function in the directory hierarchy to write a test case to trace down the bug without having to use gdb. Would you please let me why it is a nightmare? From pengyu.ut at gmail.com Mon Nov 2 08:24:59 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 07:24:59 -0600 Subject: About one class/function per module In-Reply-To: <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> Message-ID: <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> On Mon, Nov 2, 2009 at 7:11 AM, Peng Yu wrote: > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead when >> actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. > For my C++ project, so far so good. > > I can easily change filenames (that is class name or function name), I > can easily find them, I can easily move things around, all with just > the corresponding script command. I can navigate to the definition of > class and function by vim + ctags, I can see example code that calls > the class/function. Whenever I suspect there is a bug, I can easily go > to the right level of class/function in the directory hierarchy to > write a test case to trace down the bug without having to use gdb. > > Would you please let me why it is a nightmare? Another advantage one of class/function per file is that the syntax clearly tell the dependence relation between classes and functions. Suppose I have class A and class B in a file, I can not easily figure out which class depends on which class by a simple script. However, if they are in two separate files, for example B depends on A, then I will have 'import A' in file B. This dependency can be easily figured out by a script. The following scenario also demonstrate why the maintenance cost is lower with one class/function per file, because it decouples dependences. Let's suppose class A and B are in the same file. Now I'm changing class B. But while I'm changing class B, I just realize that I have to change A. But since the change in B is half way done (syntactical not correct), I will not be able to run the test case for A, because the test case import the file that has class B. In contrast, if A and B are in different files, even if B is half way done, I can still run test case for A. From deets at nospam.web.de Mon Nov 2 08:27:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 14:27:40 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <7l852dF3c5gi1U1@mid.uni-berlin.de> Peng Yu wrote: > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead >> when actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. > For my C++ project, so far so good. > > I can easily change filenames (that is class name or function name), I > can easily find them, I can easily move things around, all with just > the corresponding script command. I can navigate to the definition of > class and function by vim + ctags, I can see example code that calls > the class/function. Whenever I suspect there is a bug, I can easily go > to the right level of class/function in the directory hierarchy to > write a test case to trace down the bug without having to use gdb. > > Would you please let me why it is a nightmare? My current project has about 1300 source-files (luckily *not* laid out in your preferred way), which contain 1900 function-definitions (most probably even more so) and about 1700 classes. So your "approach" more than doubles the number of files to juggle around - in my head, in my editor, and so on. Not to speak about the inability to rename a function or class just in source-code. No, I'd also have to rename the file, causing all kinds of extra issues when using version-control-systems (which of course I do). It's simply a braindead idea. Get over it. Get rid of your "useful" scripts. Start learning a decent editor (emacs is mine) which allows you to deal with all of your perceived "problems" without making even small projects a nightmare of a bazillion files. Again: *program* in python, don't fantasize about something that's not there, and writing shoehorning-scripts. That's just an excuse to be ineffective. Diez From patrick.oloughlin at gmail.com Mon Nov 2 08:28:02 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Mon, 2 Nov 2009 13:28:02 +0000 Subject: Accessing a method from within its own code Message-ID: Hi, I was wondering if there was a shorthand way to get a reference to a method object from within that method's code. Take this code snippet as an example: import re class MyClass(object): def find_line(self, lines): if not hasattr(MyClass.do_work, "matcher"): MyClass.do_work.matcher = re.compile("\d - (.+)") for line in lines: m = MyClass.do_work.matcher.match(line) if m: return m.groups() Here, I have a method which uses a regular expression object to find matches. I want the regexp object to be tied to the function, but I don't want to have to recreate it every time the function is called (I am aware that regexp objects are cached, avoiding this problem, but I'm just using this as an example for what I want to know), so I've added it to the method object as an attribute and create it only if it doesn't exist. However, typing out .. everytime is pretty long and susceptible to refactoring issues, so I was wondering if there was a way in Python that I am missing which allows you to reference the method that the code is in (like __module__ gives a reference to the parent module). Paddy -- "Ray, when someone asks you if you're a god, you say YES!" -------------- next part -------------- An HTML attachment was scrubbed... URL: From heroshaojun at gmail.com Mon Nov 2 08:34:09 2009 From: heroshaojun at gmail.com (Junjun Shao) Date: Mon, 2 Nov 2009 21:34:09 +0800 Subject: have opensource crawler written by python? Message-ID: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> hi, Is there a crawler written by python? anybody can give me more information? thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Mon Nov 2 08:45:28 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 02 Nov 2009 08:45:28 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <87y6mpvy4n.fsf@agentultra.com> Steven D'Aprano writes: > On Sun, 01 Nov 2009 23:54:16 -0800, Jon P. wrote: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 >> >> where for example >> >> operandlist1=[1,2,3,4,5] >> operandlist2=[5,4,3,2,1] >> >> and resultlist will become [6,6,6,6,6]. Using map(), I can do: >> >> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2) > > > If the two lists are very large, it would be faster to use this: > > > from operator import add > map(add, operandlist1, operandlist2) This is the best solution so far. > > >> Is there any reasonable way to do this via a list comprehension ? > > [x+y for (x, y) in zip(operandlist1, operandlist2)] > > If the lists are huge, you can save some temporary memory by replacing > zip with itertools.izip. I understand the OP was asking for it, but list comprehensions aren't the best solution in this case... it would just be line noise. List comprehensions are good for one-off transformations where it would only create a one-time method for map to use. From alfps at start.no Mon Nov 2 08:54:11 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 14:54:11 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > Alf P. Steinbach wrote: > >> * Peter Otten: >>> Alf P. Steinbach wrote: >>> >>>>> for x in range(0,3): >>>>> Button(......, command=lambda x=x: function(x)) >>>> An alternative reusable alternative is to create a button-with-id class. >>>> >>>> This is my very first Python class so I'm guessing that there are all >>>> sorts of issues, in particular naming conventions. >>> Pseudo-private attributes >> That means there is some way of making attributes private? > > No, there isn't. And the name mangled __attribute is hardly ever needed. Use > _attribute to convey the message "If you mess with this attribute you're on > your own". Thanks! >> Probably that comes across as an inane question but I ask it anyway. I >> haven't really started to look at Python classes. I'm guessing that by >> asking here I may learn things that are not obvious from the >> documentation. >> >> >>> , javaesque getter methods, >> What do you mean by that? > > In Java you have a private attribute and a public getter method. In Python > you can just make the attribute public, i. e. > > # bad > class A: > def __init__(self): > self._id = 42 > def id(self): return self._id > > # good > class A: > def __init__(self): > self.id = 42 I think I get the gist that locally saving lines of code, and generally avoiding having to write empty argument list parentheses, and thereby also indicating in a way that one is accessing a logical data attribute, is considered good in Python, which goes to initial development time and the amount of code that one must scan to grok it both for definition and usage -- is that correct? But the trade-off is inviting modification of a supposedly fixed id, which goes to correctness and later fix-it time? > You can always switch to > > class A: # assuming 3.x > @property > def id(self): > id = arbitrary_code() > return id > > later. Thanks, now I learned about @property... :-) But when the thing has been used it's much more difficult to restrict the functionality (making read-only, breaking code that changes id) than to add functionality (making also writeable, breaking none of existing code). So isn't "later" a bit late to make it read-only, shouldn't that be the initial design, and then possibly adding a setter later if id's turn out to not be so constant after all? >> What I associate with Java getter method is mainly the "get" prefix, for >> Java introspection. >> >> >>> unidiomatic None-checks >> What's the idiomatic Python way for an optional thing? > > if some_value is None: ... Thanks! But why is this preferred? >> In this case one alternative I see could be to get rid of the >> __on_tc_command method and more directly tell tkinter.Button to call the >> relevant function, doing the if-else choice once only in the IdButton >> constructor. >> >> Is that what you mean? >> >> I'm thinking more in terms of customization points when I write code. >> >> So I tend to avoid hardcoding things internally in methods, instead >> designing the choices out to where they're accessible to client code. >> >> >>> , broken naming conventions (**args), >> How to do this argument forwarding in modern style? > > I meant that keyword args are traditionally named kw or kwargs, the name > "args" is normally used for positional arguments: > > def f(*args, **kw): > "whatever" Thanks! *Note to myself*: check if there are more such conventions. >> Or is there an alternative to argument forwarding for this example? >> >> >>> spaces in funny places... >> Bah. ;-) >> >> >>>> And the idea of creating a reusable solution for such a small issue may >>>> be un-pythonic? >>> Screw pythonic, the signal/noise ratio is awful in any language. >>> >>>> But just as an example, in Python 3.x, >>> ...for achieving less in more lines? >> Now, that's a good Python-independent question! :-) >> >> Re your question's the number of lines: /if/ the code is heavily reused >> then the number of lines doesn't matter since they're only written /once/; > > Every time someone has to read the code he will read, hesitate, read again, > and then hopefully come to the conclusion that the code does nothing, > consider not using it, or if it is not tied into a larger project removing > it. I don't understand what you mean. Not that it's a shiny example of code that does a lot, but it (1) simplifies and shortens creation of buttons with id, and (2) provides a nice start for adding other customizations of those buttons, and (3) supports searching for a button with given command id, e.g. for purpose of hiding or enable/disable. If I didn't just want to try out writing a Python class, which I've never done before so it appeared interesting, I'd probably just skipped points 2 and 3 and written the same functionality as a factory function, like import tkinter def id_button( owner_widget, id, command = None, **kwargs ): def tk_command( an_id = id, a_command = command ): if a_command is not None: a_command( id ) return tkinter.Button( owner_widget, kwargs, command = tk_command ) def on_button_click( id ): print( "Button " + str( id ) + " clicked!" ) window = tkinter.Tk() n_buttons = 3 for x in range( 1, n_buttons + 1 ): id_button( window, id = x, text = "Button " + str( x ), command = on_button_click ).pack() window.mainloop() but once you have the class, for whatever reason, it would be silly not to use it, especially since it provides points 2 and 3 which the function doesn't. By the way, I as yet know next to *nothing* about binding of variable references within a function such as tk_command above. Probably I've done Unnecessary Things(TM) above? >> the net effect can even be to reduce the total number of lines, or at >> least the number of apparent function points (or whatever size metric). >> That's part of what "reusable" means. For example, if the OP used the code >> then he or she didn't type them lines, but just copy/paste'd them, less >> work than typing in a lambda definition in every button creation, and more >> clear code at every creation. > > But most of your code does *nothing*. See above, points 2 and 3. Most of that class has to do with 2, customization ability. >> Re your question's what (the) reusability achieves. >> >> First, when you and others have used such a thing in a number of places >> then you gain confidence in correctness. For example, you don't wonder >> whether Python's str type is correct, and when you test your program you >> don't test the str type implementation. Since it's been used so much you >> know that it (mainly) is correct, and that any remaining bug in there >> can't be all that serious, because if it was then it would've surfaced in >> earlier use of the type. > > The theory may be OK, but in practice it doesn't always work out. Example: > Why do you introduce button.id_string() instead of str(button.id)? Because the string representation of an id then /can/ be customized independently of the id. For example, id's might be integers but for string representation you might want symbolic action names (e.g., you might have two or more buttons with same title but different actions, so that title would be ungood to identify button). And for another example, when debugging or testing you might want the string represention of an id to provide more information about the button and/or its context, and then id_string provides a single central customization point -- provided it's used, of course. > The > programmer will hesitate, wonder whether to use button.id() or > button.id_string(), how the two may interconnect... Hm, see immediately above. It's perhaps a different way of thinking? > It feels more like a hoop to jump through than a helpful service providing > tried an tested code. Yes. It's the old "every computer science problem can be solved by adding an extra layer of indirection". Sometimes it's nice when you can do that centrally. Retrofitting the indirection to existing client code can be hard. >> This advantage of confidence in correctness can be realized even without >> heavy reuse, because the encapsulation that's necessary for reuse, here >> having the code in a class, also makes it possible with more centralized >> testing. > > Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ ? No. :-) But you're right that testing isn't that much of an issue for that class. If that's what you meant. >> A centralized, encapsulated piece of code can be tested to death and >> deemed correct (enough) and frozen, while the application of a code >> pattern in umpteen places in umpteen programs, generally can't. > > I'd like to see a good test suite for your IdButton class, especially how it > copes with the design decision that you can override the on_clicked() stub, > or provide a command function, or both. The design is that for any given IdButton there's a single point of responsibility for the click action, namely either a button creation code supplies that action, or it relies on the action defined in the class. I.e. again customization ability, that the button creation code can /override/ the class provided action, per button, without getting into general overriding of class methods, just by defining a nice little lambda inline in the call. But as I learn more Python I may perhaps find that overriding class methods can also be done that conveniently -- I don't know, keep in mind I'm a Python newbie, and doing Very Much Else than studying Python. :-) >> Second, when you do find a bug, or need more functionality, or whatever, >> there's just /one place/ to fix/extend, whatever, instead of updating >> umpteen places in umpteen programs, and trying to be sure that you've >> covered all instances and done the right thing every place regardless of >> local variations (which is pretty hopeless in general, but my experience >> with that kind of badness has mostly been with C, not Python). More >> technically, it's reduced redundancy, in this case avoiding redundant >> application of a code pattern everywhere one needs a button with id (if >> that happens often). Reduced redundancy = good. > > I agree with that maxim. Incidentally I have just found a nice example of > redundancy for you: > >>>> def __on_tk_command( self ): >>>> if self.__specified_command != None: >>>> self.__specified_command( self ) >>>> else: >>>> self.on_clicked() > Uh, could you expand on how that's redundant and how to make it less so? Cheers, & thanks, - Alf From alfps at start.no Mon Nov 2 09:12:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 15:12:31 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l83sqF3bac80U1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Alf P. Steinbach wrote: > >> * Peter Otten: >>> Alf P. Steinbach wrote: >>> >>>>> for x in range(0,3): >>>>> Button(......, command=lambda x=x: function(x)) >>>> An alternative reusable alternative is to create a button-with-id class. >>>> >>>> This is my very first Python class so I'm guessing that there are all >>>> sorts of issues, in particular naming conventions. >>> Pseudo-private attributes >> That means there is some way of making attributes private? > > No, it means that in Python we are consenting adults, and either respect > attributes with a leading underscore as private - or willfully chose to > *not* do that because of good reasons. Hm. But thanks! That's very useful information -- now I'll not be going on a wild goose chase! > And the double-underscore is used against name-clashes, not for > enhanced "privacy". > >>> , javaesque getter methods, >> What do you mean by that? >> >> What I associate with Java getter method is mainly the "get" prefix, for >> Java introspection. > > You have an attribute id, whatfor do you need a method id? If at some point > this id becomes a computed value - you introduce a property > > And that's what Peter meant with "javanesque" - the exact reason why in java > everything is wrapped in getters/setters is that the language lacks a > property-mechanism, so to present a consistent interface over several > iterations of the code, one has to introduce them for every single > attribute - regardless of their future destiny. Thanks again for useful information. Also Peter mentioned this about changing simple attributes into properties at later time, so that seems to at least not be unheard of in Python? Your comment about "computed" makes it more clear what that's all about. Also Bertrand Meyer (Eiffel language creator) had idea like that, he called it "referential transparency". But I think when Python has this nice property mechanism, why do people change direct data attributes into properties and not the other way around or not at all, I mean using only properties for logical data attributes -- e.g. assuring correctness first via read-only property? >>> unidiomatic None-checks >> What's the idiomatic Python way for an optional thing? > > None is a singleton, so the idiomatic check is for object identity: > > foo = None > foo is None Again, thanks, that helps me understand the rationale. Although not completely. But there is a connection... Cheers, - Alf From deets at nospam.web.de Mon Nov 2 09:18:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 15:18:37 +0100 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: <7l881tF3dbb00U1@mid.uni-berlin.de> > Your comment about "computed" makes it more clear what that's all about. > Also Bertrand Meyer (Eiffel language creator) had idea like that, he > called it "referential transparency". But I think when Python has this > nice property mechanism, why do people change direct data attributes into > properties and not the other way around or not at all, I mean using only > properties for logical > data attributes -- e.g. assuring correctness first via read-only > property? I fail to see where read-only-ness of an attribute is a priori more correct than having modifyable attributes. Again, it's an assumption of a future use or constraint that is most of the times simply not correct or relevant - at the price for more typing, and computational overhead. Diez From henrik.sorensen at changenetworks.dk Mon Nov 2 09:25:37 2009 From: henrik.sorensen at changenetworks.dk (Henrik Aagaard =?ISO-8859-1?Q?S=F8rensen?=) Date: Mon, 02 Nov 2009 15:25:37 +0100 Subject: Help with SOAPpy and WSDL. In-Reply-To: <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> References: <1257164964.22254.0.camel@apollo> <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> Message-ID: <1257171937.22254.2.camel@apollo> I'll try to explain it here then: A small example on SOAPpy and WSDL. My code: from SOAPpy import WSDL wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl' server = WSDL.Proxy(wsdlFile) server.GetCurrencyByCountry('Zimbabwe') returns: Traceback (most recent call last): File "pythonwsdl.py", line 4, in server.GetCurrencyByCountry('Zimbabwe') File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 492, in __r_call self.__hd, self.__ma) File "/var/lib/python-support/python2.6/SOAPpy/Client.py", line 406, in __call raise p SOAPpy.Types.faultType: System.Data.SqlClient.SqlException: Procedure or function 'GetCurrencyByCountry' expects parameter '@name', which was not supplied. at WebServicex.country.GetCurrencyByCountry(String CountryName) --- End of inner exception stack trace ---: > It is as if it doesn't get the name "Zimbabwe". On Mon, 2009-11-02 at 12:58 +0000, Simon Brunning wrote: > 2009/11/2 Henrik Aagaard S?rensen : > > I have a problem with SOAPpy and WSDL. It is explained here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=15532 > > Why not explain it here? > > In any case, I imagine the advice is going to be to try Suds - > . > From fetchinson at googlemail.com Mon Nov 2 09:25:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 15:25:57 +0100 Subject: have opensource crawler written by python? In-Reply-To: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> References: <26e931970911020534u7ef3efet344ea8aaf299f9a0@mail.gmail.com> Message-ID: > Is there a crawler written by python? anybody can give me more information? http://www.google.com/search?q=python+web+crawlers HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From collin.day.0 at gmail.com Mon Nov 2 09:27:25 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 2 Nov 2009 06:27:25 -0800 (PST) Subject: Command parsing... best module to use? Message-ID: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Hey everyone. I am writing a game in python, and it includes a text console somewhat like the one in WoW and Runescape. I want to be able to include "/" commands, like IRC, and was wondering what the best module would be to parse these. Thanks a lot, Collin D From fetchinson at googlemail.com Mon Nov 2 09:30:09 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 15:30:09 +0100 Subject: Pyfora, a place for python In-Reply-To: <87my36my79.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> Message-ID: >> If you have any suggestions, let me know -- this is a community >> effort! > > Suggestion: Please don't make efforts to fragment the community. When a community grows and consequently its needs also grow, how do you differentiate "natural growth" from "fragmenting the community"? Same question in another way: let's suppose Tim Peters sent the exact email the OP sent with the exact same website. Would you have responded to him the same way? > Rather, please direct seekers to the existing forums (the IRC channel, > the Usenet groups and mailing lists) rather than setting up new walled > gardens. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From simon at brunningonline.net Mon Nov 2 09:30:54 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 2 Nov 2009 14:30:54 +0000 Subject: Help with SOAPpy and WSDL. In-Reply-To: <1257171937.22254.2.camel@apollo> References: <1257164964.22254.0.camel@apollo> <8c7f10c60911020458u390be0e8v361fa1d88e49f14d@mail.gmail.com> <1257171937.22254.2.camel@apollo> Message-ID: <8c7f10c60911020630q41eaa1ccwfc14f8b0ea6fa5a6@mail.gmail.com> 2009/11/2 Henrik Aagaard S?rensen : > I'll try to explain it here then: > > A small example on SOAPpy and WSDL. My code: > from SOAPpy import WSDL > wsdlFile = 'http://www.webservicex.net/country.asmx?wsdl' > server = WSDL.Proxy(wsdlFile) > server.GetCurrencyByCountry('Zimbabwe') > > returns: > System.Web.Services.Protocols.SoapException: Server was unable to > process request. ---> System.Data.SqlClient.SqlException: Procedure or > function 'GetCurrencyByCountry' expects parameter '@name', which was not > supplied. > ? at WebServicex.country.GetCurrencyByCountry(String CountryName) > ? --- End of inner exception stack trace ---: > > > > It is as if it doesn't get the name "Zimbabwe". Try server.GetCurrencyByCountry(name='Zimbabwe') -- Cheers, Simon B. From deets at nospam.web.de Mon Nov 2 09:44:52 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 15:44:52 +0100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> Message-ID: <7l89j4F3bl107U1@mid.uni-berlin.de> Daniel Fetchinson wrote: >>> If you have any suggestions, let me know -- this is a community >>> effort! >> >> Suggestion: Please don't make efforts to fragment the community. > > When a community grows and consequently its needs also grow, how do > you differentiate "natural growth" from "fragmenting the community"? > > Same question in another way: let's suppose Tim Peters sent the exact > email the OP sent with the exact same website. Would you have > responded to him the same way? Most probably not - but then because Tim certainly would have discussed this move with peers from the community, if there is a need for this kind of forum or not. Being from germany, I can say that we *have* this fragmentation, and frankly: I don't like it. I prefer my communication via NNTP/ML, and not with those visually rather noisy and IMHO suboptimal forums. E.g. it requires much more effort to get to know what new discussions arose, as well as following ongoing ones - because the interface lacks a comprehensive overview of that, and features like "jump to next unread article". Diez From davea at ieee.org Mon Nov 2 09:54:35 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 09:54:35 -0500 Subject: exec-function in Python 3.+ In-Reply-To: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> References: <4aeeb939$0$56772$edfadb0f@dtext02.news.tele.dk> Message-ID: <4AEEF2AB.3070803@ieee.org> Hans Larsen wrote: > Help! > I'm begginer in Python 3.+! > If i wih to update a module after an import and chages, > How could I do: > By "from imp import reload" and then reload(mymodule) > or how to use "exec(?)", it is mentoined in docs. > In Python ver. <3 reload(module) writes something back to interpretter!, > how about exec, which is a function?-:) > I,m thanking on the help!! > > > I've never used reload() in 2.x or 3.x. If I'm debugging interactively with the command line interpreter and I get to this point, I exit() and start the python interpreter again. And if there was too much typing to waste by doing that, I write the code into another script, and run that from an IDE. From most IDE's, you get a fresh chance every time you start a run. I haven't found any reason to change this behavior. So if you have a use-case, please elaborate. And know that there are lots of traps in reloading a module, as it can't really eliminate all traces of being already run once. It works for simple stuff, but you don't need it for simple stuff,... And I guess I'm repeating myself. DaveA From jeanmichel at sequans.com Mon Nov 2 10:02:43 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 02 Nov 2009 16:02:43 +0100 Subject: About one class/function per module In-Reply-To: <7l852dF3c5gi1U1@mid.uni-berlin.de> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> Message-ID: <4AEEF493.5010505@sequans.com> Diez B. Roggisch wrote: > Peng Yu wrote: > >> I can navigate to the definition of >> class and function by vim + ctags, >> > > Start learning a decent editor (emacs is mine) which allows you to deal > with all of your perceived "problems" > > Diez > This is a declaration of war against the vi community. We won't give up, prepare for vengeance ! By the way, why the hell would someone wants to limit itself to one function per file, file names would be probably related to the function name, that would make changing function name a nightmare, not mentiong the history issues when using version control systems. Definitely a bad idea. JM From lallous at lgwm.org Mon Nov 2 10:16:13 2009 From: lallous at lgwm.org (lallous) Date: Mon, 2 Nov 2009 16:16:13 +0100 Subject: C api and exception handling Message-ID: Hello, Is there is a way, using the Python C api, to install an exception handler that: - will be triggered when an exception occurs - analyze the reason of the exception - correct the situation and try again (something like exception handling on windows where the exception handler can retrieve the registers context->faulting instruction->fix situation if needed->restart execution from the same point) Since I will be asked: "what are you trying to achieve?", this is what I want: func_call("hello") <- no exceptions, good code: function is defined and called properly SomeUndefinedFunction("x", "y") <- undefined function call will trigger an exception. I want my python/C exception handler to inspect the reason of the exception, if it was a call to an undefined function call then redirect the execution to a certain method, say: ExecuteByName("SomeUndefinedFunction", "x", "y") I know if I create a small class with getattr hooked, what I want can be achieved. But can it be done otherwise (without using a class and instead relying on exception handlers and correcting the exception)? Regards, Elias From davea at ieee.org Mon Nov 2 10:21:46 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 10:21:46 -0500 Subject: Accessing a method from within its own code In-Reply-To: References: Message-ID: <4AEEF90A.8000608@ieee.org> Paddy O'Loughlin wrote: > Hi, > I was wondering if there was a shorthand way to get a reference to a method > object from within that method's code. > > Take this code snippet as an example: > import re > > class MyClass(object): > def find_line(self, lines): > if not hasattr(MyClass.do_work, "matcher"): > MyClass.do_work.matcher = re.compile("\d - (.+)") > for line in lines: > m = MyClass.do_work.matcher.match(line) > if m: > return m.groups() > > Here, I have a method which uses a regular expression object to find > matches. I want the regexp object to be tied to the function, but I don't > want to have to recreate it every time the function is called (I am aware > that regexp objects are cached, avoiding this problem, but I'm just using > this as an example for what I want to know), so I've added it to the method > object as an attribute and create it only if it doesn't exist. > > However, typing out .. everytime is > pretty long and susceptible to refactoring issues, so I was wondering if > there was a way in Python that I am missing which allows you to reference > the method that the code is in (like __module__ gives a reference to the > parent module). > > Paddy > > I suspect that the "inspection" module has your answer, but that it'll be bulkier, and much slower than just doing what you're doing already. Why not use the default arguments gimmick? Since this cached item is to have a module lifetime, it'd be desirable to create it when the method is being defined, which is exactly what default arguments do. Something like (untested): class ... def find_line(self, lines, _cacheitems = [] ) if not _cacheitems: _cacheitems.append( re.compile..... ) for ... m = _cacheitems[0]( line ) DaveA From kee at kagi.com Mon Nov 2 10:24:35 2009 From: kee at kagi.com (Kee Nethery) Date: Mon, 2 Nov 2009 07:24:35 -0800 Subject: Pyfora, a place for python In-Reply-To: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> I just noticed the tag line "a place for Python". Looked it up online (http://pyfora.org/ ) and it will be interesting to see if it can fill the void that I experience (no centralized place to post and view user submitted sample code) in the existing Python community. As for user community fragmentation, I would guess that someone would be less likely to create such a site if the user community needs were being met by the official sites. There is a place for the existing old school interaction forums (the IRC channel, the Usenet groups and mailing lists), but there is also a place for archived user submitted comments. My personal preference would be a link in each sub-paragraph in the official documentation to a wiki page devoted to that specific aspect of the Python language. A place were users could augment the documentation by providing sample code and by expanding out the documentation for those of us who don't live and breath Python in our sleep. Real Python coders would not click on the user wiki links and all of us newbies could communicate with each other. But until a place like that exists, perhaps Pyfora will get us part way there. Kee From grflanagan at gmail.com Mon Nov 2 10:29:26 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 02 Nov 2009 15:29:26 +0000 Subject: Accessing a method from within its own code In-Reply-To: References: Message-ID: Paddy O'Loughlin wrote: > Hi, > I was wondering if there was a shorthand way to get a reference to a > method object from within that method's code. > > Take this code snippet as an example: > import re > > class MyClass(object): > def find_line(self, lines): > if not hasattr(MyClass.do_work, "matcher"): > MyClass.do_work.matcher = re.compile("\d - (.+)") > for line in lines: > m = MyClass.do_work.matcher.match(line) > if m: > return m.groups() > > Here, I have a method which uses a regular expression object to find > matches. I want the regexp object to be tied to the function, but I > don't want to have to recreate it every time the function is called Just an idea: ------------------------------ import re def matches(patt): def wrapper(fn): def inner(self, *args, **kw): return fn(self, *args, **kw) inner.match = re.compile(patt).match return inner return wrapper class MyClass(object): @matches('ab(.*)') def func(self): print 'hi' return 5 c = MyClass() ret = c.func() print ret print c.func.match('abc').groups() ------------------------------------ From deets at nospam.web.de Mon Nov 2 10:38:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 16:38:06 +0100 Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7l8cmuF3dlnh7U1@mid.uni-berlin.de> Kee Nethery wrote: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/ ) and it will be interesting to see if it can fill the > void that I experience (no centralized place to post and view user > submitted sample code) in the existing Python community. ASPN cookbook? And I don't think that a phpBB (or commercial rip-off) forum can be good at that - the search-function of these things sucks big time, and classification through tagging or hierarchical organization is also not possible. > My personal preference would be a link in each sub-paragraph in the > official documentation to a wiki page devoted to that specific aspect > of the Python language. A place were users could augment the > documentation by providing sample code and by expanding out the > documentation for those of us who don't live and breath Python in our > sleep. Real Python coders would not click on the user wiki links and > all of us newbies could communicate with each other. But until a place > like that exists, perhaps Pyfora will get us part way there. This idea has been discussed before, and unfortunately not bore any fruits so far - one of the few places PHP is actually better than Python. So I'd love to see it happen. However I totally fail to see how the pyfora are any step into that direction. Diez From kevinar18 at hotmail.com Mon Nov 2 10:41:18 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Mon, 2 Nov 2009 10:41:18 -0500 Subject: How do I install libxml2 and libxslt? Message-ID: I want to use the lxml library, but can't get it to work on Windows. The following will not work: * import libxml2 * import libxslt * from lxml import etree Here's the instructions: http://codespeak.net/lxml/installation.html * So, I run "easy_install lxml" -- that works! * Now, it says I need to install libxml2 and libxslt... how do I do that? ...so, I download the libxml2 and libxslt pre-built Windows binaries here: http://www.zlatkovic.com/pub/libxml/ Now what do I do with them? I opened the zip files and copied the bin directories to Python\Lib ... like this: Python\Lib\libxml2\libxml2.dll ... that doesn't work. I copy just dll to Python\DLLs ... that doesn't work. What now? _________________________________________________________________ Bing brings you maps, menus, and reviews organized in one place. http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Mon Nov 2 10:43:10 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 2 Nov 2009 16:43:10 +0100 Subject: Pyfora, a place for python In-Reply-To: <7l89j4F3bl107U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: >>>> If you have any suggestions, let me know -- this is a community >>>> effort! >>> >>> Suggestion: Please don't make efforts to fragment the community. >> >> When a community grows and consequently its needs also grow, how do >> you differentiate "natural growth" from "fragmenting the community"? >> >> Same question in another way: let's suppose Tim Peters sent the exact >> email the OP sent with the exact same website. Would you have >> responded to him the same way? > > Most probably not - but then because Tim certainly would have discussed this > move with peers from the community, if there is a need for this kind of > forum or not. > > Being from germany, I can say that we *have* this fragmentation, and > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > with those visually rather noisy and IMHO suboptimal forums. If you prefer NNTP/ML, I'd suggest you pay attention to these channels only. BTW, I prefer ML also and I'm very happy with c.l.p. However that doesn't mean that I need to be hostile to other forms of communication and it doesn't mean that I need to discourage people from setting up other channels of communication for those folks who prefer them. If new channels open up for others it will not make c.l.p any worse. If enough people like c.l.p. it will continue to be a good channel, if too many too good people switch to an online forum, well, in that case c.l.p. will cease to be great, but it won't be because of artificial fragmentation by somebody but because the people started to prefer online forums (words like "free market" come to mind :)) I generally not register on any online forum and will most probably not register on pyfora either. But I know for a fact that many people prefer forums over ML and why shouldn't those people be happy with the communication platform they like and why shouldn't they be given a chance to join the python community if the only reason they stayed away was that they didn't like c.l.p. for one reason or another? > E.g. it > requires much more effort to get to know what new discussions arose, as > well as following ongoing ones - because the interface lacks a > comprehensive overview of that, and features like "jump to next unread > article". These are perfectly legitimate reasons for you to not use online forums and stick to c.l.p. I do the same thing. But again, if an enthusiastic python community member wants to open new channels for those folks who like them, why should anyone be hostile to him/her? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mwilson at the-wire.com Mon Nov 2 10:46:48 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 02 Nov 2009 10:46:48 -0500 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >>> * Peter Otten: >>>> unidiomatic None-checks >>> What's the idiomatic Python way for an optional thing? >> >> if some_value is None: ... > > Thanks! > > But why is this preferred? I guess because `some_value == None` restricts your choices if you want to give some_value's usual class an __eq__ method. It's a pretty arcane point.. but perhaps not.. the object named "some_value" might belong to a class that expects its instances only to be compared with each other, for the sake of economy and clear code. Mel. From alfps at start.no Mon Nov 2 10:51:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 02 Nov 2009 16:51:36 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l881tF3dbb00U1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: >> Your comment about "computed" makes it more clear what that's all about. >> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >> called it "referential transparency". But I think when Python has this >> nice property mechanism, why do people change direct data attributes into >> properties and not the other way around or not at all, I mean using only >> properties for logical >> data attributes -- e.g. assuring correctness first via read-only >> property? > > I fail to see where read-only-ness of an attribute is a priori more correct > than having modifyable attributes. No, I didn't mean that it is more correct to have an attribute as read-only. I meant that letting a logical data attribute start out as a read only property can help to ensure correctness. For example, consider two rectangle classes R1 and R2, where R2 might be a successor to R1, at some point in system evolution replacing R1. R1 has logical data members left, top, width and height, and R2 has logical data members left, top, right and bottom. With R1 direct changes of left and top keeps the rectangle's size (since that size is specified by width and height), while with R2 it changes the rectangle's size. R1 is implemented with logical data members as directly exposed data attributes. Some code in the system deals only with R1 objects and for convenience or efficiency or whatever uses direct modification instead of set_position method. Due to new requirements it instead has to deal with R2 objects, with same methods. But due to the direct modification of object state it now changes the rectangle sizes, but at first it's not noticed since the attempted rectangle position changes are very small. People get upset. The bug is fixed. Time has been wasted. > Again, it's an assumption of a future > use or constraint that is most of the times simply not correct or > relevant - at the price for more typing, and computational overhead. Hm, not sure. Cheers, - Alf From patrick.oloughlin at gmail.com Mon Nov 2 10:59:02 2009 From: patrick.oloughlin at gmail.com (Paddy O'Loughlin) Date: Mon, 2 Nov 2009 15:59:02 +0000 Subject: Accessing a method from within its own code In-Reply-To: <4AEEF90A.8000608@ieee.org> References: <4AEEF90A.8000608@ieee.org> Message-ID: > > I suspect that the "inspection" module has your answer, but that it'll be > bulkier, and much slower than just doing what you're doing already. > Hmm. Yeah, it does appear to be bulky. I don't think it's really any more use than what I'm doing already. Why not use the default arguments gimmick? Since this cached item is to > have a module lifetime, it'd be desirable to create it when the method is > being defined, which is exactly what default arguments do. > I've a few different ways of emulating static function variables from C/Java and the function/method attribute one is easily the one that appeals most to my sensibilities. I find the default arguments gimmick to be a gimmick. It's co-opting a piece of functionality for something it doesn't seem like it was originally intended for and as a consequence is less readable (to my eyes). The only problem with the function/method way is that it gets rather verbose when you are dealing with a user-defined method and have to give the class name and method name and it's also a bit of a pain for moving code around when refactoring. You ever wish there was more to python scoping than just locals(), globals() and __builtins__? Like a method's class's scope too? That's where I am at with this. -- "Ray, when someone asks you if you're a god, you say YES!" -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Nov 2 11:19:51 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 02 Nov 2009 11:19:51 -0500 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> Message-ID: Alf P. Steinbach wrote: > Your comment about "computed" makes it more clear what that's all about. > Also Bertrand Meyer (Eiffel language creator) had idea like that, he > called it "referential transparency". But I think when Python has this > nice property mechanism, why do people change direct data attributes into > properties and not the other way around or not at all, Python tends to prefer simple forms over complicated forms, so having a programmer write x = something.that and implementing a getter inside the call to something.__getattr__ is better than x = something.that() with a pair of needless parens, and then mangling the compiler/runtime to suddenly use the value of `that`, uncalled, if `something` happens to be an instance of the class we're discussing. Note too that something.that = x is pretty clean, but something.that() = x can't be done at all, and the syntactically correct something.that(x) just doesn't look like the simple assignment statement. Mel. From duncan.booth at invalid.invalid Mon Nov 2 11:22:08 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Nov 2009 16:22:08 GMT Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <7l8cmuF3dlnh7U1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" wrote: > Kee Nethery wrote: >> My personal preference would be a link in each sub-paragraph in the >> official documentation to a wiki page devoted to that specific aspect >> of the Python language. A place were users could augment the >> documentation by providing sample code and by expanding out the >> documentation for those of us who don't live and breath Python in our >> sleep. Real Python coders would not click on the user wiki links and >> all of us newbies could communicate with each other. But until a >> place like that exists, perhaps Pyfora will get us part way there. > > This idea has been discussed before, and unfortunately not bore any > fruits so far - one of the few places PHP is actually better than > Python. So I'd love to see it happen. One option would be to use Google sidewiki. That way we need no changes to the existing site and people can add comments on pages or individual paragraphs, phrases or words. It's up and running today. However, so far as I know there isn't any easy way to find all sidewiki comments for a site: the APIs only allow you to retrieve comments for an individual page. (There's a sidewiki issue for this http://code.google.com/p/gdata-issues/issues/detail?id=1493 ) If they address this issue then the site could include a ticker of recent comments. Also of course some people may have objections to using sidewiki e.g. on privacy grounds. -- Duncan Booth http://kupuguy.blogspot.com From bigboss1964 at gmail.com Mon Nov 2 11:22:37 2009 From: bigboss1964 at gmail.com (TerryP) Date: Mon, 2 Nov 2009 08:22:37 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: On Nov 2, 2:27?pm, Collin D wrote: > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. > > Thanks a lot, > Collin D I'm not aware of any module designed for parsing arbitrary text in that way, although it may be possible to subvert something to the task. If you are following the usual IRC client behavioural pattern, then just suck up the line - then see if the first non-whitespace character is a '/', then react accordingly. Simple. From rsheftel at gmail.com Mon Nov 2 11:42:41 2009 From: rsheftel at gmail.com (Ryan) Date: Mon, 2 Nov 2009 08:42:41 -0800 (PST) Subject: Migrating from R to Python Message-ID: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> I am a long time user of "R" for statistical analysis and find it an extremely useful environment for data exploration. That said I may be adding and/or moving to Python for more of my work and wanted to know if people had any recommendations. My work is primarily financial time series analysis. In R this means extensive use of "zoo" and "xts". I see from searching that there is a time-series package for Python called pytseries (http:// pytseries.sourceforge.net/) that looks closest to adding the time series capabilities to Python. My question is to people who have used zoo and xts in R, what has their experience been with Python? Would you recommend using native Python to do time series analysis, or rPy to link back to R for analysis? Thanks. From aaron.watters at gmail.com Mon Nov 2 11:57:08 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Mon, 2 Nov 2009 08:57:08 -0800 (PST) Subject: graceful degradation : is it degrading? Message-ID: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Graceful degradation is what I hope to display as I continue to age... But in the context of web programming it also refers to the supposedly desirable behaviour of web sites to "do something reasonable" as resources are denied them by client browsers such as cookies, applets, javascript, etcetera. So for example if the browser has javascript turned off pages should somehow "still work". These days javascript is so pervasive that graceful degradation is becoming increasingly difficult and absolutely no fun for web designers and programmers. Question: is graceful degradation for no-javascript feasible and desirable these days? For example after I announced my WHIFF treeview widgets http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2200.TreeView people noted that they sometimes didn't work properly with javascript off. I could fix this in some cases, but the fix would involve changing a "POST" to a "GET" and that would cause MSIE to suddenly fail when the GET parameters get too big (and probably other browsers too). So it really would only fix part of the problem. Consequently I'm tempted to say: "sorry, please enable javascript if you want to use this page..." What is the state of best-practices and such? -- Aaron Watters === she was dirty, flirty / musta been about thirty... Stones '60s she was shifty, nifty / musta been about fifty... Stones '90s (what rhymes with 80?) From davea at ieee.org Mon Nov 2 11:57:35 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 02 Nov 2009 11:57:35 -0500 Subject: Accessing a method from within its own code In-Reply-To: References: <4AEEF90A.8000608@ieee.org> Message-ID: <4AEF0F7F.8080008@ieee.org> Paddy O'Loughlin wrote: >> I suspect that the "inspection" module has your answer, but that it'll be >> bulkier, and much slower than just doing what you're doing already. >> >> > Hmm. > Yeah, it does appear to be bulky. I don't think it's really any more use > than what I'm doing already. > > > Why not use the default arguments gimmick? Since this cached item is to > >> have a module lifetime, it'd be desirable to create it when the method is >> being defined, which is exactly what default arguments do. >> >> > > I've a few different ways of emulating static function variables from C/Java > and the function/method attribute one is easily the one that appeals most to > my sensibilities. > I find the default arguments gimmick to be a gimmick. It's co-opting a piece > of functionality for something it doesn't seem like it was originally > intended for and as a consequence is less readable (to my eyes). > The only problem with the function/method way is that it gets rather verbose > when you are dealing with a user-defined method and have to give the class > name and method name and it's also a bit of a pain for moving code around > when refactoring. > > You ever wish there was more to python scoping than just locals(), globals() > and __builtins__? Like a method's class's scope too? > That's where I am at with this. > > > Back to your original approach - if you don't bind a new value to a class variable, it's okay to just reference it with self, rather than needing cls. But if you forget, and bind a new value, then you'll end up with an instance attribute instead of reusing the class attribute. How about (untested): class ... cacheitems = [] def find_line(self, lines): if not self.cacheitems: self.cacheitems.append( re.compile..... ) for ... m = self.cacheitems[0]( line ) Just don't put self.cacheitems= xyzzy inside a method. Incidentally, if your cacheitems is an instance of a dummy class (with pass as a body), you could use named parameters instead of subscript. But then you're back to the three nodes you already thought was too verbose. All you've gained is the relative ease of refactoring. DaveA From pavlovevidence at gmail.com Mon Nov 2 12:01:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 09:01:44 -0800 (PST) Subject: C api and exception handling References: Message-ID: On Nov 2, 7:16?am, "lallous" wrote: > Hello, > > Is there is a way, using the Python C api, to install an exception handler > that: > - will be triggered when an exception occurs > - analyze the reason of the exception > - correct the situation and try again (something like exception handling on > windows where the exception handler can retrieve the registers > context->faulting instruction->fix situation if needed->restart execution > from the same point) Python has no concept of "retrying", at either the Python or C API level. You might be able to do something Evil in C to get this effect but I don't recommend it, it'll be fundamentally averse to how Python works and future versions are likely to break it. > Since I will be asked: "what are you trying to achieve?", this is what I > want: > > func_call("hello") <- no exceptions, good code: function is defined and > called properly > SomeUndefinedFunction("x", "y") <- undefined function call will trigger an > exception. I want my python/C exception handler to inspect the reason of the > exception, if it was a call to an undefined function call then redirect the > execution to a certain method, say: ExecuteByName("SomeUndefinedFunction", > "x", "y") > > I know if I create a small class with getattr hooked, what I want can be > achieved. I'd do it that way. There is ordinarily no way to hook into a plain function call like SomeUndefinedFunction() in Python; if you go around hacking up the interpreter to do that users will be highly confused and surprised. OTOH, hooking into attributes is pretty well-known. When a person sees attribute notation they know there's an opportunity to do weird stuff. When a strange function is called, they will be like, "oh, someone overrode __getattr__". > But can it be done otherwise (without using a class and instead relying on > exception handlers and correcting the exception)? Just forget about exception handling. If you REALLY insist on doing this, and I highly recommend against it, the best chance you have is to try to hook into the importing process and load a module that uses a custom dictionary object. Carl Banks From ishwor.gurung at gmail.com Mon Nov 2 12:02:26 2009 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Tue, 3 Nov 2009 04:02:26 +1100 Subject: Migrating from R to Python In-Reply-To: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> References: <97dfa851-d226-4788-9d75-2ebad6758676@j9g2000vbp.googlegroups.com> Message-ID: <34534aed0911020902paba078cp296f2a687bb39ee5@mail.gmail.com> Hi, 2009/11/3 Ryan : > I am a long time user of "R" for statistical analysis and find it an [...] > My question is to people who have used zoo and xts in R, what has > their experience been with Python? Would you recommend using native > Python to do time series analysis, or rPy to link back to R for > analysis? Although I haven't used 'zoo' nor 'xts' in R I use Rpy/Rpy2 because it seems to expose almost all(iirc) the necessary R space within Python space. So, if I need features in R - for e.g., importing modules - library('foo'), I can still have it in Python via the Rpy/Rpy2 bridge. On the other hand with pytseries Python library, I'd be limited to only run time-series analysis wouldn't I? In the end though, it all depends on your project requirements, resources and so forth.. -- Regards, Ishwor Gurung From __peter__ at web.de Mon Nov 2 12:09:47 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Nov 2009 18:09:47 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> Alf P. Steinbach wrote: >> >>> * Peter Otten: >>>> Alf P. Steinbach wrote: >>>> >>>>>> for x in range(0,3): >>>>>> Button(......, command=lambda x=x: function(x)) >>>>> An alternative reusable alternative is to create a button-with-id >>>>> class. >>>>> >>>>> This is my very first Python class so I'm guessing that there are all >>>>> sorts of issues, in particular naming conventions. >>>> Pseudo-private attributes >>> That means there is some way of making attributes private? >> >> No, there isn't. And the name mangled __attribute is hardly ever needed. >> Use _attribute to convey the message "If you mess with this attribute >> you're on your own". > > Thanks! > > >>> Probably that comes across as an inane question but I ask it anyway. I >>> haven't really started to look at Python classes. I'm guessing that by >>> asking here I may learn things that are not obvious from the >>> documentation. >>> >>> >>>> , javaesque getter methods, >>> What do you mean by that? >> >> In Java you have a private attribute and a public getter method. In >> Python you can just make the attribute public, i. e. >> >> # bad >> class A: >> def __init__(self): >> self._id = 42 >> def id(self): return self._id >> >> # good >> class A: >> def __init__(self): >> self.id = 42 > > I think I get the gist that locally saving lines of code, and generally > avoiding having to write empty argument list parentheses, and thereby also > indicating in a way that one is accessing a logical data attribute, is > considered good in Python, which goes to initial development time and the > amount of code that one > must scan to grok it both for definition and usage -- is that correct? Remember that .id does contain static data in your case. If it were a lengthy calculation the .id() method would be OK. > But the trade-off is inviting modification of a supposedly fixed id, which > goes to correctness and later fix-it time? > > >> You can always switch to >> >> class A: # assuming 3.x >> @property >> def id(self): >> id = arbitrary_code() >> return id >> >> later. > > Thanks, now I learned about @property... :-) > > But when the thing has been used it's much more difficult to restrict the > functionality (making read-only, breaking code that changes id) than to > add functionality (making also writeable, breaking none of existing code). > > So isn't "later" a bit late to make it read-only, shouldn't that be the > initial design, and then possibly adding a setter later if id's turn out > to not be so constant after all? You can break existing code with changes in a library in so many ways that I don't think this specific problem matters much. But if you don't feel comfortable with writing a warning into the documentation use a getter function or a property. >>> What I associate with Java getter method is mainly the "get" prefix, for >>> Java introspection. >>> >>> >>>> unidiomatic None-checks >>> What's the idiomatic Python way for an optional thing? >> >> if some_value is None: ... > > Thanks! > > But why is this preferred? > > >>> In this case one alternative I see could be to get rid of the >>> __on_tc_command method and more directly tell tkinter.Button to call the >>> relevant function, doing the if-else choice once only in the IdButton >>> constructor. >>> >>> Is that what you mean? >>> >>> I'm thinking more in terms of customization points when I write code. >>> >>> So I tend to avoid hardcoding things internally in methods, instead >>> designing the choices out to where they're accessible to client code. >>> >>> >>>> , broken naming conventions (**args), >>> How to do this argument forwarding in modern style? >> >> I meant that keyword args are traditionally named kw or kwargs, the name >> "args" is normally used for positional arguments: >> >> def f(*args, **kw): >> "whatever" > > Thanks! > > *Note to myself*: check if there are more such conventions. > > >>> Or is there an alternative to argument forwarding for this example? >>> >>> >>>> spaces in funny places... >>> Bah. ;-) >>> >>> >>>>> And the idea of creating a reusable solution for such a small issue >>>>> may be un-pythonic? >>>> Screw pythonic, the signal/noise ratio is awful in any language. >>>> >>>>> But just as an example, in Python 3.x, >>>> ...for achieving less in more lines? >>> Now, that's a good Python-independent question! :-) >>> >>> Re your question's the number of lines: /if/ the code is heavily reused >>> then the number of lines doesn't matter since they're only written >>> /once/; >> >> Every time someone has to read the code he will read, hesitate, read >> again, and then hopefully come to the conclusion that the code does >> nothing, consider not using it, or if it is not tied into a larger >> project removing it. > > I don't understand what you mean. Writing code is not fire and forget. It has to be debugged, tested, maintained, and will be read quite a few times in the process. Therefore it is important that you make it easy to read and understand. > Not that it's a shiny example of code that does a lot, but it (1) > simplifies and shortens creation of buttons with id, and (2) provides a > nice start for adding other customizations of those buttons, and (3) > supports searching for a button with given command id, e.g. for purpose of > hiding or enable/disable. > > If I didn't just want to try out writing a Python class, which I've never > done before so it appeared interesting, I'd probably just skipped points 2 > and 3 and written the same functionality as a factory function, like > > > > import tkinter > > def id_button( owner_widget, id, command = None, **kwargs ): > def tk_command( an_id = id, a_command = command ): > if a_command is not None: a_command( id ) > return tkinter.Button( owner_widget, kwargs, command = tk_command ) > > def on_button_click( id ): > print( "Button " + str( id ) + " clicked!" ) > > window = tkinter.Tk() > > n_buttons = 3 > for x in range( 1, n_buttons + 1 ): > id_button( > window, id = x, text = "Button " + str( x ), command = > on_button_click ).pack() > > window.mainloop() > I prefer that one, though without extra spaces in funny places. > but once you have the class, for whatever reason, it would be silly not to > use it, especially since it provides points 2 and 3 which the function > doesn't. > > By the way, I as yet know next to *nothing* about binding of variable > references within a function such as tk_command above. Probably I've done > Unnecessary Things(TM) above? Nothing too obvious; you could avoid the noop tk_command, and maybe provide the button instead of the id (all code untested): def make_button(owner, id, command=None, **kwargs): button = tkinter.Button(owner, kwargs) button.id = id if command is not None: button["command"] = functools.partial(command, button) button.pack() def button_click(button): print(button["text"], "clicked!") >>> the net effect can even be to reduce the total number of lines, or at >>> least the number of apparent function points (or whatever size metric). >>> That's part of what "reusable" means. For example, if the OP used the >>> code then he or she didn't type them lines, but just copy/paste'd them, >>> less work than typing in a lambda definition in every button creation, >>> and more clear code at every creation. >> >> But most of your code does *nothing*. > > See above, points 2 and 3. Most of that class has to do with 2, > customization ability. Couldn't class IdButton(tkinter.Button): def __init__(self, id, **kw): self.id = id tkinter.Button.__init__(self, **kw) be customised as easily? >>> Re your question's what (the) reusability achieves. >>> >>> First, when you and others have used such a thing in a number of places >>> then you gain confidence in correctness. For example, you don't wonder >>> whether Python's str type is correct, and when you test your program you >>> don't test the str type implementation. Since it's been used so much you >>> know that it (mainly) is correct, and that any remaining bug in there >>> can't be all that serious, because if it was then it would've surfaced >>> in earlier use of the type. >> >> The theory may be OK, but in practice it doesn't always work out. >> Example: Why do you introduce button.id_string() instead of >> str(button.id)? > > Because the string representation of an id then /can/ be customized > independently of the id. For example, id's might be integers but for > string representation you might want symbolic action names (e.g., you > might have two or more buttons with same title but different actions, so > that title would be ungood to identify button). And for another example, > when debugging or testing you might want the string represention of an id > to provide more information about the button and/or its context, and then > id_string provides a single > central customization point -- provided it's used, of course. And what about the IdEntry class? To me it would make more sense to customize the type of the .id value. >> The >> programmer will hesitate, wonder whether to use button.id() or >> button.id_string(), how the two may interconnect... > > Hm, see immediately above. > > It's perhaps a different way of thinking? > > >> It feels more like a hoop to jump through than a helpful service >> providing tried an tested code. > > Yes. > > It's the old "every computer science problem can be solved by adding an > extra layer of indirection". > > Sometimes it's nice when you can do that centrally. Retrofitting the > indirection to existing client code can be hard. Again, just-in-case indirections come at a cost. You are probably right about the way of thinking. >>> This advantage of confidence in correctness can be realized even without >>> heavy reuse, because the encapsulation that's necessary for reuse, here >>> having the code in a class, also makes it possible with more centralized >>> testing. >> >> Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ >> ? > > No. :-) But you're right that testing isn't that much of an issue for > that class. If that's what you meant. I read it twice but didn't understand it. You probably misplaced a word, but I can't figure out which one. >>> A centralized, encapsulated piece of code can be tested to death and >>> deemed correct (enough) and frozen, while the application of a code >>> pattern in umpteen places in umpteen programs, generally can't. >> >> I'd like to see a good test suite for your IdButton class, especially how >> it copes with the design decision that you can override the on_clicked() >> stub, or provide a command function, or both. > > The design is that for any given IdButton there's a single point of > responsibility for the click action, namely either a button creation code > supplies that action, or it relies on the action defined in the class. > > I.e. again customization ability, that the button creation code can > /override/ the class provided action, per button, without getting into > general overriding of class methods, just by defining a nice little lambda > inline in the call. > > But as I learn more Python I may perhaps find that overriding class > methods can > also be done that conveniently -- I don't know, keep in mind I'm a > Python newbie, and doing Very Much Else than studying Python. :-) > > >>> Second, when you do find a bug, or need more functionality, or whatever, >>> there's just /one place/ to fix/extend, whatever, instead of updating >>> umpteen places in umpteen programs, and trying to be sure that you've >>> covered all instances and done the right thing every place regardless of >>> local variations (which is pretty hopeless in general, but my experience >>> with that kind of badness has mostly been with C, not Python). More >>> technically, it's reduced redundancy, in this case avoiding redundant >>> application of a code pattern everywhere one needs a button with id (if >>> that happens often). Reduced redundancy = good. >> >> I agree with that maxim. Incidentally I have just found a nice example of >> redundancy for you: >> >>>>> def __on_tk_command( self ): >>>>> if self.__specified_command != None: >>>>> self.__specified_command( self ) >>>>> else: >>>>> self.on_clicked() >> > > Uh, could you expand on how that's redundant and how to make it less so? How about class IdButton(tkinter.Button): def __init__(self, owner, id, command=None, **kwargs): tkinter.Button.__init__( self, owner, kwargs, command=self.on_clicked) self.id = id self.specified_command = command def on_clicked(self): if self.specified_command is not None: self.specified_command(self) Peter From chris at simplistix.co.uk Mon Nov 2 12:12:12 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 02 Nov 2009 17:12:12 +0000 Subject: graceful degradation : is it degrading? In-Reply-To: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> References: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Message-ID: <4AEF12EC.1090401@simplistix.co.uk> Aaron Watters wrote: > These days javascript is so > pervasive that graceful degradation is becoming > increasingly difficult and absolutely no fun for > web designers and programmers. This sounds like something I'd ask about on #web on irc.freenode.net... Those guys are pretty knowledgeable, would be interesting to know what they have to say on all this... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From http Mon Nov 2 12:39:54 2009 From: http (Paul Rubin) Date: 02 Nov 2009 09:39:54 -0800 Subject: Pyfora, a place for python References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> Message-ID: <7xeiogomfp.fsf@ruckus.brouhaha.com> Kee Nethery writes: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/ ) and it will be interesting to see if it can fill > the void that I experience (no centralized place to post and view > user submitted sample code) in the existing Python community. Something wrong with pastebin.com or any of its lookalikes? From nat.williams at gmail.com Mon Nov 2 13:06:09 2009 From: nat.williams at gmail.com (Nat Williams) Date: Mon, 2 Nov 2009 12:06:09 -0600 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: On Mon, Nov 2, 2009 at 9:41 AM, Kevin Ar18 wrote: > I want to use the lxml library, but can't get it to work on Windows. > > The following will not work: > * import libxml2 > * import libxslt > * from lxml import etree > > Here's the instructions: > http://codespeak.net/lxml/installation.html > > * So, I run "easy_install lxml" -- that works! > * Now, it says I need to install libxml2 and libxslt... how do I do that? > ...so, I download the libxml2 and libxslt pre-built Windows binaries here: > http://www.zlatkovic.com/pub/libxml/ > Now what do I do with them? > I opened the zip files and copied the bin directories to Python\Lib ... > like this: Python\Lib\libxml2\libxml2.dll ... that doesn't work. I copy just > dll to Python\DLLs ... that doesn't work. > > What now? > According to the lxml installation instructions you linked, the windows lxml binary is statically linked and you do not need to install the libraries separately. If 'from lxml import etree' works, then you're done. libxml2 and libxslt are C libraries, not things that you can or would import. The joy of lxml is not having to deal with those libraries on your own. Nat -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Mon Nov 2 13:21:34 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 2 Nov 2009 10:21:34 -0800 Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: "Collin D" wrote in message news:94dbc92b-0682-4995-b358-0c615c95a27a at x6g2000prc.googlegroups.com... > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. Check out the pyparsing module. Here is a presentation given by the author for parsing an interactive game. http://us.pycon.org/zope/talks/2006/fri/track1/04/index.html -Mark From animator333 at gmail.com Mon Nov 2 14:40:25 2009 From: animator333 at gmail.com (King) Date: Mon, 2 Nov 2009 11:40:25 -0800 (PST) Subject: conditional __init__ Message-ID: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> class A(object): def __init__(self): pass def printme(self): print "I am A" class B(object): def __init__(self): pass def printme(self): print "I am B" class K(A, B): def __init__(self, value=0): if value == 0: A.__init__(self) print "__init__ A" elif value == 1: B.__init__(self) print "__init__ B" self.printme() o = K(value=1) Output >>__init__ B >>I am A In above code "B" is correctly getting initialized as per condition. How ever method "printme" is printing "I am A". Instead it has to print "I am B" because "B" is the one that has been initialized. What's wrong here? Is there a better/another way to do conditional initialization as needed above? Cheers Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Mon Nov 2 15:00:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 13:00:15 -0700 Subject: conditional __init__ In-Reply-To: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: <50697b2c0911021200j368ab384q27e36012dff4fbfe@mail.gmail.com> On Mon, Nov 2, 2009 at 12:40 PM, King wrote: > class A(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def printme(self): > ? ? ? ?print "I am A" > > class B(object): > ? ?def __init__(self): > ? ? ? ?pass > ? ?def printme(self): > ? ? ? ?print "I am B" > > class K(A, B): > ? ?def __init__(self, value=0): > ? ? ? ?if value == 0: > ? ? ? ? ? ?A.__init__(self) > ? ? ? ? ? ?print "__init__ A" > ? ? ? ?elif value == 1: > ? ? ? ? ? ?B.__init__(self) > ? ? ? ? ? ?print "__init__ B" > ? ? ? ?self.printme() > > o = K(value=1) > > Output >>>__init__ B >>>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? > > Is there a better/another way to do conditional initialization as > needed above? Which initializers are called *has no effect* on what order base classes are consulted in when looking up methods. To change the lookup order, you need to change the order of the base classes in the class statement. Your problem could be fixed by: 1. Changing the code so the initializers do have an effect through what they initialize instance variables to; class A(object): def __init__(self): self.name = "A" def printme(self): print "I am", self.name class B(object): def __init__(self): self.name = "B" def printme(self): print "I am", self.name 2. Use a factory function to return an instance of the proper class: class K1(A, B): pass class K2(B, A): pass def newK(value): if value == 0: return K1() elif value == 1: return K2() Cheers, Chris -- http://blog.rebertia.com From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Nov 2 15:02:07 2009 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Mon, 2 Nov 2009 20:02:07 +0000 (UTC) Subject: conditional __init__ References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: King wrote: > class A(object): > def __init__(self): > pass > def printme(self): > print "I am A" > > class B(object): > def __init__(self): > pass > def printme(self): > print "I am B" > > class K(A, B): > def __init__(self, value=0): > if value == 0: > A.__init__(self) > print "__init__ A" > elif value == 1: > B.__init__(self) > print "__init__ B" > self.printme() > > o = K(value=1) > > Output >>>__init__ B >>>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? It prints "I am A" because K inherits from A before B. Your __init__ methods don't do anything, so it doesn't matter which one you call. You seem to be thinking that running __init__ magically determines the class of the object, but it doesn't; it's just code that runs when the object is first created. When you do self.printme(), it decides to use A.printme because you did "class K(A, B)". If you do class K(B, A)" it will use B.printme. I imagine it's possible to do fiendish things and try to choose the superclass inheritance order at runtime, but you should be wary of this. In your example, why don't you just have K override printme and dispatch to A or B depending on "value"? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From azhilprashanth87 at gmail.com Mon Nov 2 15:37:44 2009 From: azhilprashanth87 at gmail.com (pranesh) Date: Mon, 2 Nov 2009 12:37:44 -0800 (PST) Subject: Hi help me in installing pcapy extension module Message-ID: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> dear friends, I have python 2.6.4 i my Windows XP machine. I am trying to install pcapy - python extension module ( I am using http://oss.coresecurity.com/projects/pcapy.html for reference ) I decided to implement the libpcap library... Since I have only windows xp machine...... I installed WinPcap - this is a port of libpcap - windows uses this WinPcap As the pcapy extension is written in C++ it needs to be compiled for the host system before it can be accessed from Python. In order to compile and install the source, I executed python setup.py install from the directory where Pcapy's distribution has been unpacked. Now, I am getting the following error, C:\pcapy-0.10.4>python setup.py install running install running build running build_ext building 'pcapy' extension error: Unable to find vcvarsall.bat I request you to help me in solving this problem. regards Prashanth From ldo at geek-central.gen.new_zealand Mon Nov 2 15:41:10 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 09:41:10 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > Lawrence D'Oliveiro wrote: > >> Says someone who hasn't realized where the real inefficiencies are. >> Remember what Tony Hoare told us: "premature optimization is the root of >> all evil". These are databases we're talking about. Real-world databases >> are large, and reside on disk, which is several orders of magnitude >> slower than RAM. And RAM is where string parameter substitutions take >> place. So a few hundred extra RAM accesses isn't going to make any >> significant difference to the speed of database queries. > > You're just not getting it. The cost is not in performing the parameter > substitutions themselves. The cost is in parsing what's essentially the > same query one million times over when it could have been parsed only > once. You might find an increase of seven orders of magnitude > insignificant, but I don't. There is no such parsing overhead. I speak from experience. Look at the BulkInserter class here . I have successfully used that to insert tens of thousands of records in just a few seconds. Yet it makes no use of the parameter-substitution provided by MySQLdb; it is all just straight Python, including the SQLString routine (also on that page), which goes through every single character of each string value to decide what needs escaping. Python can do all that, and do it fast. You don't get to figure out what's efficient and what's not by mere hand- waving; you have to do actual real-world tests. From deets at nospam.web.de Mon Nov 2 15:44:35 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 21:44:35 +0100 Subject: Hi help me in installing pcapy extension module In-Reply-To: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> References: <2b53a899-630c-45c2-891d-84ef9cfab073@h40g2000prf.googlegroups.com> Message-ID: <7l8uljF3cjk5lU1@mid.uni-berlin.de> pranesh schrieb: > dear friends, > > I have python 2.6.4 i my Windows XP machine. > I am trying to install pcapy - python extension module > ( I am using http://oss.coresecurity.com/projects/pcapy.html for > reference ) > > I decided to implement the libpcap library... > Since I have only windows xp machine...... > I installed WinPcap - this is a port of libpcap - windows uses this > WinPcap > > As the pcapy extension is written in C++ it needs to be compiled for > the host system before it can be accessed from Python. > In order to compile and install the source, I executed > python setup.py install > from the directory where Pcapy's distribution has been unpacked. > > Now, I am getting the following error, > > C:\pcapy-0.10.4>python setup.py install > running install > running build > running build_ext > building 'pcapy' extension > error: Unable to find vcvarsall.bat This looks to my as if you are missing Visual C++, or at least it's not properly set up. > I request you to help me in solving this problem. I'm not a native-speaker - and I guess you aren't either. But "I request you to help me" is rather rude, as well as your subject. "I kindly ask you to help me" would be better I'd say. Diez From kevinar18 at hotmail.com Mon Nov 2 15:44:36 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Mon, 2 Nov 2009 15:44:36 -0500 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 > According to the lxml installation instructions you linked=2C > the windows lxml binary is statically linked and you do not > need to install the libraries separately. The install instructions say" "You need libxml2 and libxslt" and then links= to where to download the binaries=3B this means I need to install separate= ly=2C right? If not=2C those are aweful instructions. :) I can download the binaries=2C but I don't know where or how to install the= m? Is there any instructions anywhere? =20 > If 'from lxml import etree' works=2C then you're done. It doesn't work. =20 _________________________________________________________________ New Windows 7: Find the right PC for you. http://www.microsoft.com/windows/pc-scout/default.aspx?CBID=3Dwl&ocid=3DPID= 24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_pcscout:112009= From ldo at geek-central.gen.new_zealand Mon Nov 2 15:47:08 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 09:47:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Dennis Lee Bieber wrote: > On Sun, 01 Nov 2009 19:08 +1300, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> On the grounds that Python has more general and powerful string >> parameter- substitution mechanisms than anything built into any database >> API. > > Really? In the case of MySQLdb, the DB-API /uses/ Pythons string > interpolation ... Only a limited subset thereof. For instance, I'm not aware of any database API that lets me do this: sql.cursor.execute \ ( "update numbers set flags = flags | %(setflags)u where projectid = %(projectid)s" "%(match_listid)s and number = %(number)s" % { "projectid" : SQLString(ProjectID), "match_listid" : ("", " and listid = %s" % SQLString(ListID))[ListID != None], "number" : SQLString(number), "setflags" : flags, } ) From aahz at pythoncraft.com Mon Nov 2 16:11:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 13:11:28 -0800 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: In article <7589e0a1-98b2-4df4-bc76-5d4c10194fde at f20g2000prn.googlegroups.com>, Falcolas wrote: > >I'd also recommend trying the following filter, since it is identical >to what you're trying to do, and will probably catch some additional >edge cases without any additional effort from you. > >[s.strip() for s in hosts if s.strip()] This breaks if s might be None -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Mon Nov 2 16:21:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 13:21:58 -0800 Subject: Recommended number of threads? (in CPython) References: Message-ID: In article , mk wrote: > >I wrote run-of-the-mill program for concurrent execution of ssh command >over a large number of hosts. (someone may ask why reinvent the wheel >when there's pssh and shmux around -- I'm not happy with working details >and lack of some options in either program) > >The program has a working queue of threads so that no more than >maxthreads number are created and working at particular time. > >But this begs the question: what is the recommended number of threads >working concurrently? If it's dependent on task, the task is: open ssh >connection, execute command (then the main thread loops over the queue >and if the thread is finished, it closes ssh connection and does .join() >on the thread) Given that you code is not just I/O-bound but wait-bound, I suggest following the suggestion to use asynch code -- then you could open a connection to every single machine simultaneously. Assuming your system setup can handle the load, that is. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From robert.kern at gmail.com Mon Nov 2 16:35:54 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Nov 2009 15:35:54 -0600 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: On 2009-11-02 14:47 PM, Lawrence D'Oliveiro wrote: > In message, Dennis Lee Bieber wrote: > >> On Sun, 01 Nov 2009 19:08 +1300, Lawrence D'Oliveiro >> declaimed the following in >> gmane.comp.python.general: >> >>> On the grounds that Python has more general and powerful string >>> parameter- substitution mechanisms than anything built into any database >>> API. >> >> Really? In the case of MySQLdb, the DB-API /uses/ Pythons string >> interpolation ... > > Only a limited subset thereof. For instance, I'm not aware of any database > API that lets me do this: > > sql.cursor.execute \ > ( > "update numbers set flags = flags | %(setflags)u where projectid = %(projectid)s" > "%(match_listid)s and number = %(number)s" > % > { > "projectid" : SQLString(ProjectID), > "match_listid" : > ("", " and listid = %s" % SQLString(ListID))[ListID != None], > "number" : SQLString(number), > "setflags" : flags, > } > ) When programmatically generating SQL, I like to use SQLAlchemy. This use case is handled with .where() on Update expression objects. Personally, I find manipulating the SQLAlchemy expression objects clearer, safer, and more portable than building the raw SQL through string interpolation. -- 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 ben+python at benfinney.id.au Mon Nov 2 17:14:05 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 09:14:05 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> Message-ID: <87ljiok21e.fsf@benfinney.id.au> J Kenneth King writes: > Steven D'Aprano writes: > > > from operator import add > > map(add, operandlist1, operandlist2) > > This is the best solution so far. Strange to say it's a solution, when it doesn't solve the stated problem: to replace use of ?map()? with a list comprehension. > I understand the OP was asking for it, but list comprehensions aren't > the best solution in this case... it would just be line noise. I disagree; a list comprehension is often clearer than use of ?map()? with a lambda form, and I find it to be so in this case. -- \ ?He may look like an idiot and talk like an idiot but don't let | `\ that fool you. He really is an idiot.? ?Groucho Marx | _o__) | Ben Finney From deets at nospam.web.de Mon Nov 2 17:16:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 02 Nov 2009 23:16:54 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> Message-ID: <7l942mF3c94mlU1@mid.uni-berlin.de> Alf P. Steinbach schrieb: > * Diez B. Roggisch: >>> Your comment about "computed" makes it more clear what that's all about. >>> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >>> called it "referential transparency". But I think when Python has this >>> nice property mechanism, why do people change direct data attributes >>> into >>> properties and not the other way around or not at all, I mean using only >>> properties for logical >>> data attributes -- e.g. assuring correctness first via read-only >>> property? >> >> I fail to see where read-only-ness of an attribute is a priori more >> correct >> than having modifyable attributes. > > No, I didn't mean that it is more correct to have an attribute as > read-only. I meant that letting a logical data attribute start out as a > read only property can help to ensure correctness. Which is the same thing said with other words. > For example, consider > two rectangle classes R1 and R2, where R2 might be a successor to R1, at > some point in system evolution replacing R1. R1 has logical data members > left, top, width and height, and R2 has logical data members left, top, > right and bottom. With R1 direct changes of left and top keeps the > rectangle's size (since that size is specified by width and height), > while with R2 it changes the rectangle's size. R1 is implemented with > logical data members as directly exposed data attributes. Some code in > the system deals only with R1 objects and for convenience or efficiency > or whatever uses direct modification instead of set_position method. Due > to new requirements it instead has to deal with R2 objects, with same > methods. But due to the direct modification of object state it now > changes the rectangle sizes, but at first it's not noticed since the > attempted rectangle position changes are very small. People get upset. > The bug is fixed. Time has been wasted. If there is need for mutable rectangles, there is need for mutable rectangles. Using properties instead of attributes doesn't help - if you change semantics of something, code might break. In Python, attributes are part of the public interface as long as you don't explicitly define them otherwise. But preliminary assumptions about what could be in some yet unseen future is introducing more code with more chances of errors, reducing the flexibility at the same time. I still fail to see where that's good. Code for what you need code for. It works - in all languages, but especially in Python. Diez From tjreedy at udel.edu Mon Nov 2 17:17:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Nov 2009 17:17:40 -0500 Subject: graceful degradation : is it degrading? In-Reply-To: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> References: <6b91b60a-1331-4773-8643-d2a19337eee3@d5g2000yqm.googlegroups.com> Message-ID: Aaron Watters wrote: > people noted that they sometimes didn't work properly with > javascript off. I could fix this in some cases, but > the fix would involve changing a "POST" to a "GET" > and that would cause MSIE to suddenly fail when the > GET parameters get too big (and probably other > browsers too). So it really would only fix part of the > problem. Consequently I'm tempted to say: "sorry, > please enable javascript if you want to use this page..." If a page is sufficiently dynamic on the client side, that seems reasonable enough to me. From ben+python at benfinney.id.au Mon Nov 2 17:21:16 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 09:21:16 +1100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> Message-ID: <87hbtck1pf.fsf@benfinney.id.au> Jean-Michel Pichavant writes: > Diez B. Roggisch wrote: > > Start learning a decent editor (emacs is mine) which allows you to > > deal with all of your perceived "problems" > > This is a declaration of war against the vi community. We won't give > up, prepare for vengeance ! Bah. Saying that Emacs is a decent text editor doesn't preclude other decent text editors. You and your pugilistic editor wars... Of course, vi is *not* a decent text editor (which, to my reckoning, requires all of: free software, mature, widely used, powerful, extensible and ? because of all the preceding points ? extensive support for a huge range of editing tasks). The only text editors that make the bar are Emacs and Vim. Anyone who disagrees had better be prepared for vengeance. -- \ ?Be careless in your dress if you must, but keep a tidy soul.? | `\ ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From krister.svanlund at gmail.com Mon Nov 2 17:31:21 2009 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 2 Nov 2009 23:31:21 +0100 Subject: list comprehension problem In-Reply-To: References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: <2cf430a60911021431u5b6071e3mac552ab9b985cbde@mail.gmail.com> On Mon, Nov 2, 2009 at 10:11 PM, Aahz wrote: > In article <7589e0a1-98b2-4df4-bc76-5d4c10194fde at f20g2000prn.googlegroups.com>, > Falcolas ? wrote: >> >>I'd also recommend trying the following filter, since it is identical >>to what you're trying to do, and will probably catch some additional >>edge cases without any additional effort from you. >> >>[s.strip() for s in hosts if s.strip()] > > This breaks if s might be None If you don't want Nones in your list just make a check for it... [s.strip() for s in hosts if s is not None and s.strip()] From pavlovevidence at gmail.com Mon Nov 2 17:59:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 14:59:34 -0800 (PST) Subject: conditional __init__ References: <600a6b7e-5bcb-4746-b5fd-0642840a53f5@m26g2000yqb.googlegroups.com> Message-ID: <9ed412a9-23e2-4c22-b108-7d7c002ef956@p8g2000yqb.googlegroups.com> On Nov 2, 11:40?am, King wrote: > class A(object): > ? ? def __init__(self): > ? ? ? ? pass > ? ? def printme(self): > ? ? ? ? print "I am A" > > class B(object): > ? ? def __init__(self): > ? ? ? ? pass > ? ? def printme(self): > ? ? ? ? print "I am B" > > class K(A, B): > ? ? def __init__(self, value=0): > ? ? ? ? if value == 0: > ? ? ? ? ? ? A.__init__(self) > ? ? ? ? ? ? print "__init__ A" > ? ? ? ? elif value == 1: > ? ? ? ? ? ? B.__init__(self) > ? ? ? ? ? ? print "__init__ B" > ? ? ? ? self.printme() > > o = K(value=1) > > Output > > >>__init__ B > >>I am A > > In above code "B" is correctly getting initialized as per condition. > How ever method "printme" is printing "I am A". > Instead it has to print "I am B" because "B" is the one that has been > initialized. What's wrong here? What's wrong is that you have a fundamental misunderstanding of what's happening. You can't just shut off a subclass by refusing to initialize it--just doesn't work that way. All subclasses will continue to be active whether you call __init__ on them or not. Therefore when you call self.printme() it searches the base classes in order, and the first one it finds is A, so it always calls A's printme. It seems to me that you haven't learned enough about how inheritance works in Python to use multiple inheritance yet, so I would suggest just sticking to single inheritance for now, and study up. > Is there a better/another way to do conditional initialization as > needed above? The fact that you feel the need to do this suggests that you want a composition relationship, not an inheritance one. What you appear to be doing is defining a sort of "plugin", you have an object that can behave one way (A) or another (B), but which one isn't known till run time. In that case the A or B object should be made an attribute of the K object: class A(object): def printme(self): print "I am A" class B(object): def printme(self): print "I am B" class K(object): def __init__(self, value=0): if value == 0: self.plugin = A() print "__init__ A" elif value == 1: self.plugin = B() print "__init__ B" self.plugin.printme() Without seeing more of your code I strongly suspect that this change better reflects what you're trying to do. Carl Banks From skong1 at gmail.com Mon Nov 2 18:39:07 2009 From: skong1 at gmail.com (sityee kong) Date: Mon, 2 Nov 2009 15:39:07 -0800 Subject: read Zipfile Message-ID: Hi all, I'm writing a program to manipulate data in 3 different kind of format, there are GZIP, cvs/txt, or ZIP file. Here is part of my program to open these 3 kind formats of file, if (option==1): file=gzip.GzipFile(sys.argv[1],"r") elif (option==2): file=open(sys.argv[1],"r") elif (option==3): archive=zipfile.ZipFile(sys.argv[1],"r") I have no problem with opening GZIP or cvs/txt file. However for the ZIP file, let says the ZIP file contains only one member, >>> archive.namelist() ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] I would like to open the csv file with folowwing command, file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") But it turned out error, Traceback (most recent call last): File "", line 1, in ? AttributeError: ZipFile instance has no attribute 'open' Do you know the way to open an file from a ZIP archive, but not reading them all into memory. I would manipulate each line using "for line in file:" Hope my contents do make sense. Thanks, phoebe -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 2 19:02:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 17:02:34 -0700 Subject: read Zipfile In-Reply-To: References: Message-ID: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> On Mon, Nov 2, 2009 at 4:39 PM, sityee kong wrote: > However for the ZIP file, let says the ZIP file contains only one member, >>>> archive.namelist() > ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] > > I would like to open the csv file with folowwing command, > file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") > But it turned out error, > > Traceback (most recent call last): > ? File "", line 1, in ? > AttributeError: ZipFile instance has no attribute 'open' ZipFile.open(name[, mode[, pwd]]) [...] New in version 2.6. Would your Python version happen to be pre-2.6? Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Nov 2 19:04:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Nov 2009 00:04:31 -0000 Subject: About one class/function per module In-Reply-To: <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> <366c6f340911020524m3ab3b919wdea40a583d6e6871@mail.gmail.com> Message-ID: On Mon, 02 Nov 2009 13:24:59 -0000, Peng Yu wrote: > Another advantage one of class/function per file is that the syntax > clearly tell the dependence relation between classes and functions. Um, no. Grepping for "import" now tells you that there is a dependency between the file contents, but it leaves you with no clue as to what that relationship is. You've thrown away the strong relationship information that comes from collecting your source into a single file. > Suppose I have class A and class B in a file, I can not easily figure > out which class depends on which class by a simple script. However, if > they are in two separate files, for example B depends on A, then I > will have 'import A' in file B. This dependency can be easily figured > out by a script. You could always try searching for the class name, which will tell you a whole lot more about how it's being used. > The following scenario also demonstrate why the maintenance cost is > lower with one class/function per file, because it decouples > dependences. Let's suppose class A and B are in the same file. Now I'm > changing class B. But while I'm changing class B, I just realize that > I have to change A. But since the change in B is half way done > (syntactical not correct), I will not be able to run the test case for > A, because the test case import the file that has class B. In > contrast, if A and B are in different files, even if B is half way > done, I can still run test case for A. Provided, of course, that the test case is still meaningful given the changes being made to B, and that you don't forget what you were doing with B while your attention is on A. Not my favorite way of working, though sometimes you just can't avoid it. Of course, given that A and B are in different files, your chances of realising that you needed to change A at all dropped dramatically. -- Rhodri James *-* Wildebeest Herder to the Masses From deets at nospam.web.de Mon Nov 2 19:12:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 01:12:59 +0100 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <7l9asbF3c7qa2U1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >>>>> If you have any suggestions, let me know -- this is a community >>>>> effort! >>>> Suggestion: Please don't make efforts to fragment the community. >>> When a community grows and consequently its needs also grow, how do >>> you differentiate "natural growth" from "fragmenting the community"? >>> >>> Same question in another way: let's suppose Tim Peters sent the exact >>> email the OP sent with the exact same website. Would you have >>> responded to him the same way? >> Most probably not - but then because Tim certainly would have discussed this >> move with peers from the community, if there is a need for this kind of >> forum or not. >> >> Being from germany, I can say that we *have* this fragmentation, and >> frankly: I don't like it. I prefer my communication via NNTP/ML, and not >> with those visually rather noisy and IMHO suboptimal forums. > > If you prefer NNTP/ML, I'd suggest you pay attention to these channels > only. BTW, I prefer ML also and I'm very happy with c.l.p. However > that doesn't mean that I need to be hostile to other forms of > communication and it doesn't mean that I need to discourage people > from setting up other channels of communication for those folks who > prefer them. Since when is the mere suggestion that fragmentation will occur and if that's a desirable consequence is hostile? The OP is not bound to it, and I also don't see the tone used by the two immediate answerers being hostile. Paul might have been terse - but hostility looks different IMHO. The OP *might* come to the conclusion that further fragmenting the community isn't within his personal goals either. OTOH, he might also simply think that once his forum gained traction, he can switch on the google ads, and cash in. Which a forum announced by Tim Peters, run under python.org wouldn't I'd say. > If new channels open up for others it will not make c.l.p any worse. It will, if they catch on. As some competent people will move away. Again, this is the case in the german python scene, and it plain sucks. We have a ML, a NG, and a forum. None of them is synchronized in any way. We wanted to do this for ML and NG - but the guy responsible for the ML can't be reached, or refuses to answer. If we had only one source, fragmentation wouldn't occur, and the competence would be bundled. That I personally prefer MLs and NGs doesn't mean that I wouldn't turn to the forum if it was *the* way to talk about Python. But as it stands, there are three kind of things, of which I'm already subsribed to two - and am annoyed of people posting questions in both of them. Now, I can't do anything about it in the sense that I can forbid it. But questioning the move to create a new form of exchange (especially something rather uninspired, in contrast to e.g. stackoverflow) I can. > If enough people like c.l.p. it will continue to be a good channel, if > too many too good people switch to an online forum, well, in that case > c.l.p. will cease to be great, but it won't be because of artificial > fragmentation by somebody but because the people started to prefer > online forums (words like "free market" come to mind :)) Yes. Or all of them suck equally. Free market again. I'm not against it, but asking the OP if he really thinks the value of his forum outweighs the risk of making existing fora worse is a valid question. Free speech, one other nice free thing out there. > I generally not register on any online forum and will most probably > not register on pyfora either. But I know for a fact that many people > prefer forums over ML and why shouldn't those people be happy with the > communication platform they like and why shouldn't they be given a > chance to join the python community if the only reason they stayed > away was that they didn't like c.l.p. for one reason or another? > >> E.g. it >> requires much more effort to get to know what new discussions arose, as >> well as following ongoing ones - because the interface lacks a >> comprehensive overview of that, and features like "jump to next unread >> article". > > These are perfectly legitimate reasons for you to not use online > forums and stick to c.l.p. I do the same thing. But again, if an > enthusiastic python community member wants to open new channels for > those folks who like them, why should anyone be hostile to him/her? Again, nobody has been. Diez From alfps at start.no Mon Nov 2 19:18:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 03 Nov 2009 01:18:53 +0100 Subject: Tkinter callback arguments In-Reply-To: References: Message-ID: * Peter Otten: > * Alf P. Steinbach wrote: >> * Peter Otten: >>> Every time someone has to read the code he will read, hesitate, read >>> again, and then hopefully come to the conclusion that the code does >>> nothing, consider not using it, or if it is not tied into a larger >>> project removing it. >> I don't understand what you mean. > > Writing code is not fire and forget. It has to be debugged, tested, > maintained, and will be read quite a few times in the process. Therefore it > is important that you make it easy to read and understand. No, I meant that I didn't understand why you find it hard to read and understand. [snip] > Couldn't > > class IdButton(tkinter.Button): > def __init__(self, id, **kw): > self.id = id > tkinter.Button.__init__(self, **kw) > > be customised as easily? Not unless there's much more that I can learn about tkinter button 'command' callbacks. Which is of course possible. :-) Is it possible to pick up the relevant object from the handler? But AFAIK it's not (I got no arguments supplied in the calls when I tested, although I don't know whether there are any options or whatever to make it supply an event object argument, say). And so AFAICS with this code there's no way to get an id in the on-click (tkinter 'command') handler. [snip] >>> Example: Why do you introduce button.id_string() instead of >>> str(button.id)? >> Because the string representation of an id then /can/ be customized >> independently of the id. For example, id's might be integers but for >> string representation you might want symbolic action names (e.g., you >> might have two or more buttons with same title but different actions, so >> that title would be ungood to identify button). And for another example, >> when debugging or testing you might want the string represention of an id >> to provide more information about the button and/or its context, and then >> id_string provides a single >> central customization point -- provided it's used, of course. > > And what about the IdEntry class? The naming scheme doesn't hold up, but I'm pretty sure that's not what you mean? > To me it would make more sense to > customize the type of the .id value. That sounds rather complex, like introducing a command pattern or something just to support some debugging and testing. [snippety] >>>> This advantage of confidence in correctness can be realized even without >>>> heavy reuse, because the encapsulation that's necessary for reuse, here >>>> having the code in a class, also makes it possible with more centralized >>>> testing. >>> Was this sentence/paragraph produced by http://pdos.csail.mit.edu/scigen/ >>> ? >> No. :-) But you're right that testing isn't that much of an issue for >> that class. If that's what you meant. > > I read it twice but didn't understand it. You probably misplaced a word, but > I can't figure out which one. In general, if you encapsulate functionality in a class or function definition or whatever, then you can move that code out to a module (or a package) and you can then test the module and gain some confidence in its correctness. In contrast, if you have nearly the same code duplicated in umpteen places, doing just about the same but with local variations, then testing and especially fixing it becomes more difficult and time consuming, and doesn't give you added confidence about any new instances of that code pattern (with own variations). But in this case the code to be duplicated is so small, just some glue for calling a handler with an id, that it's difficult to get wrong. Even though getting that wrong was exactly what this discussion thread started with. And so the possible savings in the amount of work for testing and fixing is probably (OK, weasel word) not that much of an issue in this case. [snippety] >>> >>>>>> def __on_tk_command( self ): >>>>>> if self.__specified_command != None: >>>>>> self.__specified_command( self ) >>>>>> else: >>>>>> self.on_clicked() >> Uh, could you expand on how that's redundant and how to make it less so? > > How about > > class IdButton(tkinter.Button): > def __init__(self, owner, id, command=None, **kwargs): > tkinter.Button.__init__( > self, owner, kwargs, command=self.on_clicked) > self.id = id > self.specified_command = command > > def on_clicked(self): > if self.specified_command is not None: > self.specified_command(self) The only purpose I can see for on_clicked is that it can be overridden (that was the purpose in my code too, a central customization point). But if anyone does that then he or she now has to duplicate the original on_clicked() code, or else ditch the per button customization via a supplied command handler function. I feel that forced code duplication, forced redundancy, something you just have to remember to add in the code, for the only purpose, is ungood. Cheers, - Alf From rhodri at wildebst.demon.co.uk Mon Nov 2 19:21:50 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Nov 2009 00:21:50 -0000 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: On Mon, 02 Nov 2009 00:49:50 -0000, Alf P. Steinbach wrote: > * Rhodri James: >> On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach >> wrote: >> >>> * Rhodri James: >> This is a weird attribution style, by the way. I don't think it helps. > > That's a pretty weird thing to comment on. > > And as far as I can see the comment doesn't make sense except as an > attempt to find something negative to say. > > But anyway, the point about '*' was, once upon a time, that it made for > a very clear style of quoting in old newsreaders. Nowadays the tools are > generally of lesser quality (e.g. I'm using Thunderbird). And so it > doesn't really have much of that advantage left, but I'm using it > anyway; I can be pretty stubborn about issues of quality. I'm struggling to recall as single instance of this in all of my Usenet days. And failing. And with that, I officially give up on you. -- Rhodri James *-* Wildebeest Herder to the Masses From alfps at start.no Mon Nov 2 19:38:40 2009 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 03 Nov 2009 01:38:40 +0100 Subject: Feedback wanted on programming introduction (Python in Windows) In-Reply-To: References: <7dcf7e6b-95e3-4747-afba-f790b99e98a0@y23g2000yqd.googlegroups.com> Message-ID: * Rhodri James: > On Mon, 02 Nov 2009 00:49:50 -0000, Alf P. Steinbach > wrote: > >> * Rhodri James: >>> On Sun, 01 Nov 2009 21:20:20 -0000, Alf P. Steinbach >>> wrote: >>> >>>> * Rhodri James: >>> This is a weird attribution style, by the way. I don't think it helps. >> >> That's a pretty weird thing to comment on. >> >> And as far as I can see the comment doesn't make sense except as an >> attempt to find something negative to say. >> >> But anyway, the point about '*' was, once upon a time, that it made >> for a very clear style of quoting in old newsreaders. Nowadays the >> tools are generally of lesser quality (e.g. I'm using Thunderbird). >> And so it doesn't really have much of that advantage left, but I'm >> using it anyway; I can be pretty stubborn about issues of quality. > > I'm struggling to recall as single instance of this in all of my Usenet > days. And failing. > > And with that, I officially give up on you. Again, a '*' in attributions is a pretty weird thing to focus on. But all you have posted so far in this thread has been technically incorrect (even when you've been led by hand to technical doc), logically fallacious, plus, and mostly, your vague unfocused negative feelings like above. So, it's understandable. :-) Cheers, - Alf From pavlovevidence at gmail.com Mon Nov 2 19:52:27 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 2 Nov 2009 16:52:27 -0800 (PST) Subject: import bug References: Message-ID: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> On Oct 31, 7:12?am, kj wrote: > I'm running into an ugly bug, which, IMHO, is really a bug in the > design of Python's module import scheme. ?Consider the following > directory structure: > > ham > |-- __init__.py > |-- re.py > `-- spam.py > > ...with the following very simple files: > > % head ham/*.py > ==> ham/__init__.py <== > > ==> ham/re.py <== > > ==> ham/spam.py <== > import inspect > > I.e. only ham/spam.py is not empty, and it contains the single line > "import inspect". > > If I now run the innocent-looking ham/spam.py, I get the following > error: > > % python26 ham/spam.py > Traceback (most recent call last): > ? File "ham/spam.py", line 1, in > ? ? import inspect > ? File "/usr/local/python-2.6.1/lib/python2.6/inspect.py", line 35, in > ? ? import string > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 122, in > ? ? class Template: > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in __init__ > ? ? 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > > or, similarly, > > % python3 ham/spam.py > Traceback (most recent call last): > ? File "ham/spam.py", line 1, in > ? ? import inspect > ? File "/usr/local/python-3.0/lib/python3.0/inspect.py", line 36, in > ? ? import string > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 104, in > ? ? class Template(metaclass=_TemplateMetaclass): > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 98, in __init__ > ? ? 'delim' : _re.escape(cls.delimiter), > AttributeError: 'module' object has no attribute 'escape' > > My sin appears to be having the (empty) file ham/re.py. ?So Python > is confusing it with the re module of the standard library, and > using it when the inspect module tries to import re. Python is documented as behaving this way, so this is not a bug. It is arguably poor design. However, Guido van Rossum already ruled against using a single package for the standard library, and its not likely that special case code to detect accidental name-clashes with the standard library is going to be added, since there are legitimate reasons to override the standard library. So for better or worse, you'll just have to deal with it. Carl Banks From python.list at tim.thechases.com Mon Nov 2 20:02:52 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 19:02:52 -0600 Subject: read Zipfile In-Reply-To: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> Message-ID: <4AEF813C.8020707@tim.thechases.com> >> I would like to open the csv file with folowwing command, >> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >> But it turned out error, >> >> Traceback (most recent call last): >> File "", line 1, in ? >> AttributeError: ZipFile instance has no attribute 'open' > > ZipFile.open(name[, mode[, pwd]]) > [...] > New in version 2.6. > > Would your Python version happen to be pre-2.6? FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it into your project directory. I had a similar issue in 2.4 (wanted the iterator provided by 2.6's open() call) and Gabriel suggested trying to just copy in the 2.6 version into my project directory. Worked for me(tm). -tkc From jess.austin at gmail.com Mon Nov 2 20:05:42 2009 From: jess.austin at gmail.com (Jess Austin) Date: Mon, 2 Nov 2009 17:05:42 -0800 (PST) Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> Message-ID: <57317abf-35d6-42b6-b46b-3c2778f53888@m16g2000yqc.googlegroups.com> On Nov 1, 1:13?am, "Gabriel Genellina" wrote: > Looks like in 3.1 this can be done with bytes+str and viceversa, even if ? > bytes and str don't have a common ancestor (other than object; basestring ? > doesn't exist in 3.x): > > p3> Base = bytes > p3> Other = str > p3> > p3> class Derived(Base): > ... ? def __eq__(self, other): > ... ? ? print('Derived.__eq__') > ... ? ? return True > ... > p3> Derived()==Base() > Derived.__eq__ > True > p3> Base()==Derived() > Derived.__eq__ > True > p3> Derived()==Other() > Derived.__eq__ > True > p3> Other()==Derived() > Derived.__eq__ ? ? ? ? ? ?# !!! > True > p3> Base.mro() > [, ] > p3> Other.mro() > [, ] > > The same example with set+frozenset (the one you're actually interested ? > in) doesn't work, unfortunately. > After further analysis, this works for bytes and str because both types ? > refuse to guess and compare to each other; they return NotImplemented when ? > the right-side operand is not of the same type. And this gives that other ? > operand the chance of being called. > > set and frozenset, on the other hand, are promiscuous: their ? > tp_richcompare slot happily accepts any set of any kind, derived or not, ? > and compares their contents. I think it should be a bit more strict: if ? > the right hand side is not of the same type, and its tp_richcompare slot ? > is not the default one, it should return NotImplemented. This way the ? > other type has a chance to be called. Thanks for this, Gabriel! There seems to be a difference between the two cases, however: >>> str() == bytes() False >>> set() == frozenset() True I doubt that either of these invariants is amenable to modification, even for purposes of "consistency". I'm not sure how to resolve this, but you've definitely helped me here. Perhaps the test in set_richcompare can return NotImplemented in particular cases but not in others? I'll think about this; let me know if you come up with anything more. thanks, Jess From pengyu.ut at gmail.com Mon Nov 2 20:06:20 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 19:06:20 -0600 Subject: About one class/function per module In-Reply-To: <4AEEF493.5010505@sequans.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> On Mon, Nov 2, 2009 at 9:02 AM, Jean-Michel Pichavant wrote: > Diez B. Roggisch wrote: >> >> Peng Yu wrote: >> >>> >>> ?I can navigate to the definition of >>> class and function by vim + ctags, >>> >> >> Start learning a decent editor (emacs is mine) which allows you to deal >> with all of your perceived "problems" >> Diez >> > > This is a declaration of war against the vi community. We won't give up, > prepare for vengeance ! > By the way, why the hell would someone wants to limit itself to one function > per file, file names would be probably related to the function name, that > would make changing function name a nightmare, not mentiong the history > issues when using version control systems. Definitely a bad idea. I use vi rather than emacs. I stick to vi because I stated with vi and I don't what to use both editors but only at an amateur level. With some automated script, I don't think it is a nightmare to change function names. I can change function names and filenames and their reference with a simple command. I'd think that this is the limitation of current version control system. I don't aware of any version control system that allows easy change of filenames. But why such features can not be implemented in the version control system? From collin.day.0 at gmail.com Mon Nov 2 20:14:12 2009 From: collin.day.0 at gmail.com (Collin D) Date: Mon, 2 Nov 2009 17:14:12 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: <4e6ad15b-4f6d-463b-872a-44b400a4edaf@a37g2000prf.googlegroups.com> Thanks for the replies. Pyparsing looks just like what I need. From gagsl-py2 at yahoo.com.ar Mon Nov 2 20:19:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 22:19:01 -0300 Subject: read Zipfile References: Message-ID: En Mon, 02 Nov 2009 20:39:07 -0300, sityee kong escribi?: > However for the ZIP file, let says the ZIP file contains only one member, >>>> archive.namelist() > ['CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv'] > > I would like to open the csv file with folowwing command, > file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") > But it turned out error, > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: ZipFile instance has no attribute 'open' > > Do you know the way to open an file from a ZIP archive, but not reading > them > all into memory. I would manipulate each line using "for line in file:" open was added to the ZipFile class in Python 2.6; which version are you using? I think you can backport the 2.6 version onto 2.5 with little or no effort. http://docs.python.org/library/zipfile.html#zipfile.ZipFile.open > Hope my contents do make sense. Yes, it was clear to me. -- Gabriel Genellina From skong1 at gmail.com Mon Nov 2 20:28:46 2009 From: skong1 at gmail.com (sityee kong) Date: Mon, 2 Nov 2009 17:28:46 -0800 Subject: read Zipfile In-Reply-To: <4AEF813C.8020707@tim.thechases.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: Hi all, yes, im using python 2.4. I would like to know how does python 2.4 work for my case w/o the new added feature in 2.6? Do you guys know? thanks! On Mon, Nov 2, 2009 at 5:02 PM, Tim Chase wrote: > I would like to open the csv file with folowwing command, >>> >>> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >>> But it turned out error, >>> >>> Traceback (most recent call last): >>> File "", line 1, in ? >>> AttributeError: ZipFile instance has no attribute 'open' >>> >> >> ZipFile.open(name[, mode[, pwd]]) >> [...] >> New in version 2.6. >> >> Would your Python version happen to be pre-2.6? >> > > FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it > into your project directory. I had a similar issue in 2.4 (wanted the > iterator provided by 2.6's open() call) and Gabriel suggested trying to just > copy in the 2.6 version into my project directory. Worked for me(tm). > > -tkc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 2 20:37:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 2 Nov 2009 17:37:31 -0800 Subject: read Zipfile In-Reply-To: References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> > On Mon, Nov 2, 2009 at 5:02 PM, Tim Chase > wrote: >>>> I would like to open the csv file with folowwing command, >>>> >>>> file=archive.open("CHAVI_MACS_SC_A__AUG_25_08_FinalReport_090812.csv","r") >>>> But it turned out error, >>>> >>>> Traceback (most recent call last): >>>> ?File "", line 1, in ? >>>> AttributeError: ZipFile instance has no attribute 'open' >>> >>> ZipFile.open(name[, mode[, pwd]]) >>> [...] >>> ? ?New in version 2.6. >>> >>> Would your Python version happen to be pre-2.6? >> >> FWIW, you can use the 2.6 zipfile.py as far back as 2.4 by just copying it >> into your project directory. ?I had a similar issue in 2.4 (wanted the >> iterator provided by 2.6's open() call) and Gabriel suggested trying to just >> copy in the 2.6 version into my project directory. ?Worked for me(tm). On Mon, Nov 2, 2009 at 5:28 PM, sityee kong wrote: > Hi all, yes, im using python 2.4. > > I would like to know how does python 2.4 work for my case w/o the new added > feature in 2.6? Do you guys know? Looks like you'd have to use the more primitive .read() method: http://docs.python.org/library/zipfile.html#zipfile.ZipFile.read Also, please avoid top-posting in the future. Cheers, Chris -- http://blog.rebertia.com From ldo at geek-central.gen.new_zealand Mon Nov 2 20:45:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 14:45:23 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Robert Kern wrote: > On 2009-11-02 14:47 PM, Lawrence D'Oliveiro wrote: > >> For instance, I'm not aware of any database API that lets me do this: >> >> sql.cursor.execute \ >> ( >> "update numbers set flags = flags | %(setflags)u where >> projectid = %(projectid)s" "%(match_listid)s and number = >> %(number)s" >> % >> { >> "projectid" : SQLString(ProjectID), >> "match_listid" : >> ("", " and listid = %s" % SQLString(ListID))[ListID >> != None], >> "number" : SQLString(number), >> "setflags" : flags, >> } >> ) > > When programmatically generating SQL, I like to use SQLAlchemy. This use > case is handled with .where() on Update expression objects. Personally, I > find manipulating the SQLAlchemy expression objects clearer, safer, and > more portable than building the raw SQL through string interpolation. Doesn't seem to support bulk insertions ? la this . Or even literal lists as per the SQLStringList routine on the same page. From gagsl-py2 at yahoo.com.ar Mon Nov 2 20:58:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 02 Nov 2009 22:58:25 -0300 Subject: __eq__() inconvenience when subclassing set References: <4a76cbc2-ac25-4d62-8cf7-acf8d8a25b54@g27g2000yqn.googlegroups.com> <57317abf-35d6-42b6-b46b-3c2778f53888@m16g2000yqc.googlegroups.com> Message-ID: En Mon, 02 Nov 2009 22:05:42 -0300, Jess Austin escribi?: > On Nov 1, 1:13 am, "Gabriel Genellina" wrote: >> Looks like in 3.1 this can be done with bytes+str and viceversa, even >> if bytes and str don't have a common ancestor (other than object; >> basestring doesn't exist in 3.x): >> The same example with set+frozenset (the one you're actually interested >> in) doesn't work, unfortunately. > Thanks for this, Gabriel! There seems to be a difference between the > two cases, however: > >>>> str() == bytes() > False >>>> set() == frozenset() > True > > I doubt that either of these invariants is amenable to modification, > even for purposes of "consistency". I'm not sure how to resolve this, > but you've definitely helped me here. Perhaps the test in > set_richcompare can return NotImplemented in particular cases but not > in others? I'll think about this; let me know if you come up with > anything more. I think it should return NotImplemented only when the right-hand side operand has overriden tp_richcompare. That way, set()==frozenset() would still be True. Only when one inherits from set/frozenset AND overrides __eq__, set_richcompare should step aside and let the more specific __eq__ be called (by just returning NotImplemented). What is your goal when overriding __eq__ for your new set class? It may help building a case for this change; a concrete use case is much better than an abstract request. -- Gabriel Genellina From python.list at tim.thechases.com Mon Nov 2 21:21:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 20:21:39 -0600 Subject: read Zipfile In-Reply-To: References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> Message-ID: <4AEF93B3.70106@tim.thechases.com> > I would like to know how does python 2.4 work for my case w/o the new added > feature in 2.6? Do you guys know? You can just grab the zipfile.py file from within the 2.6 distribution[1] and dump it in your project folder. Python should find it before it finds the 2.4 version in the $PYTHONPATH. While you can also overwrite the older stock version in the $PYTHON_LIB_DIR directory, I recommend against it. -tkc (for future reference, please don't top-post) [1] http://svn.python.org/projects/python/trunk/Lib/zipfile.py From python.list at tim.thechases.com Mon Nov 2 21:29:44 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 02 Nov 2009 20:29:44 -0600 Subject: read Zipfile In-Reply-To: <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> References: <50697b2c0911021602k21776e40gf75e5c402cc2ea3c@mail.gmail.com> <4AEF813C.8020707@tim.thechases.com> <50697b2c0911021737k2db356c6j85d5fbbcdde98a37@mail.gmail.com> Message-ID: <4AEF9598.8040406@tim.thechases.com> > Looks like you'd have to use the more primitive .read() method: > http://docs.python.org/library/zipfile.html#zipfile.ZipFile.read Unfortunately, the ZipFile.read() reads the entire content. One of the main reasons to zip things is that they're big -- possibly too big to fit conveniently in memory. I don't know about the OP's use-case, so .read() might suffice if the resulting content is small enough. In my case[1], it was a zip containing multiple >700MB MS-Access .mdb files that I needed to stream to temporary disk storage and using .read() killed my dev machine. -tkc [1] http://markmail.org/message/7vn5shss2h64yoop From carsten.haese at gmail.com Mon Nov 2 21:46:03 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 02 Nov 2009 21:46:03 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > There is no such parsing overhead. I speak from experience. > > Look at the BulkInserter class here > . I have successfully > used that to insert tens of thousands of records in just a few seconds. Yet > it makes no use of the parameter-substitution provided by MySQLdb; it is all > just straight Python, including the SQLString routine (also on that page), > which goes through every single character of each string value to decide > what needs escaping. Python can do all that, and do it fast. With all due respect, but if your experience is exclusive to MySQL/MySQLdb, your experience means very little for database programming practices in general. Throughout most of its history, MySQL did not support prepared statements and parameter binding, and MySQLdb doesn't use any parameter binding API that might be available, so you're comparing your own implementation of string interpolation to MySQLdb's implementation of string interpolation. Your experience says nothing about databases that have an *actual* parameter binding API. > You don't get to figure out what's efficient and what's not by mere hand- > waving; I'm not handwaving. > you have to do actual real-world tests. I have. See for example the timing test in http://informixdb.blogspot.com/2007/07/filling-in-blanks.html . If you'd like to try it for yourself, here is a version of the test for SQLite: ================================================================= # querytest.py class Tester(object): def __init__(self): import sqlite3 conn = sqlite3.connect(":memory:") self.cur = conn.cursor() self.cur.execute("create temp table t1(a int, b int)") self.counter = 0 def with_params(self): self.counter += 1 self.cur.execute("insert into t1 values(?,?)", (self.counter,self.counter*2) ) def without_params(self): self.counter += 1 self.cur.execute("insert into t1 values(%s,%s)" % (self.counter,self.counter*2) ) ================================================================= And here are the corresponding results on my laptop: $ python -mtimeit -s "from querytest import Tester; t=Tester()" 't.with_params()' 10000 loops, best of 3: 20.9 usec per loop $ python -mtimeit -s "from querytest import Tester; t=Tester()" 't.without_params()' 10000 loops, best of 3: 36.2 usec per loop So, you can say whatever you want, but you will never convince me that string interpolation is better than parameter binding for getting variable values into a query. Even if you don't accept my proof that it is more efficient, you have not proved that parameter binding is less efficient. In addition to the efficiency factor, parameter binding is inherently secure, whereas string interpolation is too easy to use insecurely. Finally, parameter binding is the standard method, as defined by the SQL standard, of getting variable values into a query. You may call it "premature optimization", but I call it "choosing the right tool for the job." I assume that none of this will convince you, but that's fine. We'll just agree to disagree on this. -- Carsten Haese http://informixdb.sourceforge.net From pengyu.ut at gmail.com Mon Nov 2 22:22:25 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 21:22:25 -0600 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021922w5f28e5f4wbc041e9b5d19533@mail.gmail.com> On Mon, Nov 2, 2009 at 7:41 PM, Lee wrote: > On Nov 2, 7:06?pm, Peng Yu wrote: >> On Mon, Nov 2, 2009 at 9:02 AM, Jean-Michel Pichavant >> >> >> >> >> >> wrote: >> > Diez B. Roggisch wrote: >> >> >> Peng Yu wrote: >> >> >>> ?I can navigate to the definition of >> >>> class and function by vim + ctags, >> >> >> Start learning a decent editor (emacs is mine) which allows you to deal >> >> with all of your perceived "problems" >> >> Diez >> >> > This is a declaration of war against the vi community. We won't give up, >> > prepare for vengeance ! >> > By the way, why the hell would someone wants to limit itself to one function >> > per file, file names would be probably related to the function name, that >> > would make changing function name a nightmare, not mentiong the history >> > issues when using version control systems. Definitely a bad idea. >> >> I use vi rather than emacs. I stick to vi because I stated with vi and >> I don't what to use both editors but only at an amateur level. >> >> With some automated script, I don't think it is a nightmare to change >> function names. I can change function names and filenames and their >> reference with a simple command. >> >> I'd think that this is the limitation of current version control >> system. I don't aware of any version control system that allows easy >> change of filenames. But why such features can not be implemented in >> the version control system? > > Because then the version control system would have to implicitly > identify the original names for files that have changed names... > Think about it, if you change the name of one file, the system should > theoretically be able to accurately identify the original filename and > make the corresponding changes to its database. But if you were to > simultaneously change the names of many files, then there's no > possible way for the system to determine which names belongs where... > I think you can see where I'm going with this. I don't think that this is a problem that can not be overcome. A simple solution might be to associate a unique identifier to each file, so that even the filename has been changed, the new version and the old version can still be identified as actually the same file. From steve at REMOVE-THIS-cybersource.com.au Mon Nov 2 22:32:34 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 03:32:34 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> Message-ID: <02ff92ad$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 09:14:05 +1100, Ben Finney wrote: > J Kenneth King writes: > >> Steven D'Aprano writes: >> >> > from operator import add >> > map(add, operandlist1, operandlist2) >> >> This is the best solution so far. > > Strange to say it's a solution, when it doesn't solve the stated > problem: to replace use of ?map()? with a list comprehension. In context, I wasn't giving that as a replacement for map(), but as a replacement for map-with-a-lambda. >> I understand the OP was asking for it, but list comprehensions aren't >> the best solution in this case... it would just be line noise. > > I disagree; a list comprehension is often clearer than use of ?map()? > with a lambda form, and I find it to be so in this case. You obviously don't do enough functional programming :) Apart from an occasional brain-fart where I conflate map() with filter(), I find them perfectly readable and sensible. The only advantages to list comps are you can filter results with an if clause, and for simple expressions you don't need to create a function. They're non-trivial advantages, but for me readability isn't one of them. -- Steven From wuwei23 at gmail.com Mon Nov 2 22:39:53 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Nov 2009 19:39:53 -0800 (PST) Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: Peng Yu wrote: > I don't think that this is a problem that can not be overcome. A > simple solution might be to associate a unique identifier to each > file, so that even the filename has been changed, the new version and > the old version can still be identified as actually the same file. Or, again, you could work _with_ the tools you're using in the way they're meant to be used, rather than re-inventing the whole process of version control yourself. From pengyu.ut at gmail.com Mon Nov 2 22:50:56 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 2 Nov 2009 21:50:56 -0600 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <366c6f340911021950x473be99bv6077b8ea7aa53ad1@mail.gmail.com> On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: > Peng Yu wrote: >> I don't think that this is a problem that can not be overcome. A >> simple solution might be to associate a unique identifier to each >> file, so that even the filename has been changed, the new version and >> the old version can still be identified as actually the same file. > > Or, again, you could work _with_ the tools you're using in the way > they're meant to be used, rather than re-inventing the whole process > of version control yourself. I'm not trying to reinvent a new version control. But due to this drawback, I avoid use a version control system. Rather, I compressed my source code in a tar file whenever necessary. But if a version control system has this capability, I'd love to use it. And I don't think that no version control system support this is because of any technical difficult but rather because of practical issue (maybe it takes a lot efforts to add this feature to an existing version control system?). From steve at REMOVE-THIS-cybersource.com.au Mon Nov 2 23:04:47 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 04:04:47 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <02ff9a39$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote: > "Jon P." writes: > >> I'd like to do: >> >> resultlist = operandlist1 + operandlist2 > > That's an unfortunate way of expressing it; it's valid Python syntax > that doesn't do what you're describing (in this case, it will bind > ?resultlist? to a new list that is the *concatenation* of the two > original lists). True, but it is valid mathematical syntax if you interpret lists as vectors. I'm sure there are languages where [1,2]+[3,4] will return [4,6]. Possibly R or Mathematica? > Yes, just about any ?map()? operation has a corresponding list > comprehension. (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) Everyone forgets the multiple argument form of map. map(func, s1, s2, s3, ...) would need to be written as: [func(t) for f in itertools.izip_longest(s1, s2, s3, ...)] which I guess is relatively simple, but only because izip_longest() does the hard work. On the other hand, list comps using an if clause can't be written as pure maps. You can do this: [func(x) for x in seq if cond(x)] filter(cond, map(func, seq)) but the second version may use much more temporary memory if seq is huge and cond very rarely true. And I don't think you could write this as a single map: [func(a, b) for a in seq1 for b in seq2] -- Steven From anh.hai.trinh at gmail.com Mon Nov 2 23:06:51 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:06:51 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: > Yes, just about any ?map()? operation has a corresponding list > comprehension. (Does anyone know of a counter-example, a ?map()? > operation that doesn't have a correspondingly simple list > comprehension?) Try turning this into a list comprehension: vectorsum = lambda *args: map(sum, zip(*args)) vectorsum([1,2], [3,4], [5,6]) ->[9, 12] vectorsum([1,2], [3,4], [5,6], [7,8]) ->[16, 20] Peace, ----aht From gagsl-py2 at yahoo.com.ar Mon Nov 2 23:20:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 01:20:07 -0300 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021950x473be99bv6077b8ea7aa53ad1@mail.gmail.com> Message-ID: En Tue, 03 Nov 2009 00:50:56 -0300, Peng Yu escribi?: > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: >> Peng Yu wrote: >>> A simple solution might be to associate a unique identifier to each >>> file, so that even the filename has been changed, the new version and >>> the old version can still be identified as actually the same file. >> >> Or, again, you could work _with_ the tools you're using in the way >> they're meant to be used, rather than re-inventing the whole process >> of version control yourself. > > I'm not trying to reinvent a new version control. But due to this > drawback, I avoid use a version control system. Rather, I compressed > my source code in a tar file whenever necessary. But if a version > control system has this capability, I'd love to use it. And I don't > think that no version control system support this is because of any > technical difficult but rather because of practical issue (maybe it > takes a lot efforts to add this feature to an existing version control > system?). All version control systems that I know of support, at least, renaming files in the same directory. (Old CVS did not, but CVSNT does). svn, hg, darcs and bzr all have renaming support, although bzr seems to be the most robust, specially in non trivial cases. -- Gabriel Genellina From anh.hai.trinh at gmail.com Mon Nov 2 23:24:12 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:24:12 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <02ff9a39$0$1326$c3e8da3@news.astraweb.com> Message-ID: <5f0b9020-a5ad-4c22-82e1-36701a4611e6@z3g2000prd.googlegroups.com> > On the other hand, list comps using an if clause can't be written as pure > maps. You can do this: > > [func(x) for x in seq if cond(x)] > > filter(cond, map(func, seq)) > > but the second version may use much more temporary memory if seq is huge > and cond very rarely true. You could use ifilter, imap there to reduce memory. > And I don't think you could write this as a single map: > > [func(a, b) for a in seq1 for b in seq2] Oh you surely could: seq1, seq2 = [1,2,3], [4,5,6] [a+b for a in seq1 for b in seq2] ->[5, 6, 7, 6, 7, 8, 7, 8, 9] from itertools import product map(sum, product(seq1, seq2)) ->[5, 6, 7, 6, 7, 8, 7, 8, 9] Peace, ----aht From sean_mcilroy at yahoo.com Mon Nov 2 23:30:00 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Mon, 2 Nov 2009 20:30:00 -0800 (PST) Subject: chr / ord Message-ID: hello how do i say "chr" and "ord" in the new python? the functions below (which work in 2.6.6) show what i'm trying to do. thanks if you can help. def readbytes(filepath): return [ord(x) for x in open(filepath,'rb').read()] def writebytes(numbers,filepath): open(filepath,'wb').write(''.join([chr(x) for x in numbers])) From anh.hai.trinh at gmail.com Mon Nov 2 23:51:46 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Mon, 2 Nov 2009 20:51:46 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <1ffbd665-dc70-46d5-a8f7-8e3391acf6ff@y28g2000prd.googlegroups.com> > Try turning this into a list comprehension: > > ? vectorsum = lambda *args: map(sum, zip(*args)) > > ? vectorsum([1,2], [3,4], [5,6]) > ->[9, 12] > ? vectorsum([1,2], [3,4], [5,6], [7,8]) > ->[16, 20] Nvm, it's actually easy: vectorsum = lambda *args: [sum(i) for i in zip(*args)] From aahz at pythoncraft.com Mon Nov 2 23:54:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Nov 2009 20:54:08 -0800 Subject: self.__dict__ tricks References: <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: In article <02fd0c85$0$1326$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote: >> >> Many programmers I know stay away from 'lists' such as this, because >> they are afraid to show their ignorance. Me, I'm fearless, and I have >> learned a lot that I might not have otherwise. > >The only stupid question is the one you are afraid to ask. "There are no stupid questions, only stupid people." -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ben+python at benfinney.id.au Mon Nov 2 23:55:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 15:55:20 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <02ff9a39$0$1326$c3e8da3@news.astraweb.com> Message-ID: <874opcjjgn.fsf@benfinney.id.au> Steven D'Aprano writes: > On Mon, 02 Nov 2009 19:19:41 +1100, Ben Finney wrote: > > > "Jon P." writes: > > > >> I'd like to do: > >> > >> resultlist = operandlist1 + operandlist2 > > > > That's an unfortunate way of expressing it; it's valid Python syntax > > that doesn't do what you're describing (in this case, it will bind > > ?resultlist? to a new list that is the *concatenation* of the two > > original lists). > > True, but it is valid mathematical syntax if you interpret lists as > vectors. I'm sure there are languages where [1,2]+[3,4] will return > [4,6]. Possibly R or Mathematica? Python isn't one of them, which is why I cautioned strongly against presenting it that way in this forum. > Everyone forgets the multiple argument form of map. > > map(func, s1, s2, s3, ...) > > would need to be written as: > > [func(t) for f in itertools.izip_longest(s1, s2, s3, ...)] > > which I guess is relatively simple, but only because izip_longest() does > the hard work. Yes, I would call that equivalently simple. (I also find it more explicit and hence readable.) -- \ ?Laurie got offended that I used the word ?puke?. But to me, | `\ that's what her dinner tasted like.? ?Jack Handey | _o__) | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 00:01:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:01:00 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <87zl74i4mr.fsf@benfinney.id.au> Anh Hai Trinh writes: > > Yes, just about any ?map()? operation has a corresponding list > > comprehension. (Does anyone know of a counter-example, a ?map()? > > operation that doesn't have a correspondingly simple list > > comprehension?) > > Try turning this into a list comprehension: > > vectorsum = lambda *args: map(sum, zip(*args)) By ?this? I take you to mean ?the usage of ?map? in this code?, since that's the limit of my question. >>> vectorsum = lambda *args: [sum(items) for items in zip(*args)] >>> vectorsum([1,2], [3,4], [5,6]) [9, 12] >>> vectorsum([1,2], [3,4], [5,6], [7,8]) [16, 20] -- \ ?The apparent lesson of the Inquisition is that insistence on | `\ uniformity of belief is fatal to intellectual, moral, and | _o__) spiritual health.? ?_The Uses Of The Past_, Herbert J. Muller | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 00:10:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:10:20 +1100 Subject: chr / ord References: Message-ID: <87vdhsi477.fsf@benfinney.id.au> Sean McIlroy writes: > how do i say "chr" and "ord" in the new python? By ?the new python?, what do you mean? * Python 2.6.4, the newest released version. * Python 2.7, a currently in-development version. * Python 3.1, another new release (but not the latest). * Python 3.2, a currently in-development version. * Something else. > the functions below (which work in 2.6.6) I think we'll need you to have a closer look at version numbers; there is no Python 2.6.6. > show what i'm trying to do. Unfortunately, they leave us guessing as to what you what to do, and what you expect the result to be. I prefer not to guess. > thanks if you can help. > > def readbytes(filepath): > return [ord(x) for x in open(filepath,'rb').read()] > > def writebytes(numbers,filepath): > open(filepath,'wb').write(''.join([chr(x) for x in numbers])) Could you please show an example of a use of these functions ? preferably a complete, minimal example that anyone can run in the declared version of Python ? and what you would expect the output to be? -- \ ?Remorse: Regret that one waited so long to do it.? ?Henry L. | `\ Mencken | _o__) | Ben Finney From benjamin.kaplan at case.edu Tue Nov 3 00:10:23 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 3 Nov 2009 00:10:23 -0500 Subject: chr / ord In-Reply-To: References: Message-ID: On Mon, Nov 2, 2009 at 11:30 PM, Sean McIlroy wrote: > hello > > how do i say "chr" and "ord" in the new python? the functions below > (which work in 2.6.6) show what i'm trying to do. thanks if you can > help. > > def readbytes(filepath): > ? ?return [ord(x) for x in open(filepath,'rb').read()] > Ord should still work the way you expect. > def writebytes(numbers,filepath): > ? ?open(filepath,'wb').write(''.join([chr(x) for x in numbers])) I haven't played around with python 3 that much, but I believe that the bytes constructor can take an iterable of ints. So you should be able to do open(filepath,'wb').write(bytes(numbers)) > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Tue Nov 3 00:13:08 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 16:13:08 +1100 Subject: self.__dict__ tricks References: <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <87r5sgi42j.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > "There are no stupid questions, only stupid people." The earliest source I know for that aphorism is the fictional teacher Mister Garrisson, from South Park. Can anyone source it earlier? -- \ ?Read not to contradict and confute, nor to believe and take | `\ for granted ? but to weigh and consider.? ?Francis Bacon | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:17:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:17:38 GMT Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <366c6f340911020511q749d151fn6f3cfb31edf67884@mail.gmail.com> Message-ID: <02ffab4d$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 07:24:59 -0600, Peng Yu wrote: > Suppose I have class A and class B in a file, I can not easily figure > out which class depends on which class by a simple script. How about looking at the classes? >>> class A: ... pass ... >>> class B(A): ... pass ... >>> >>> B.__bases__ (,) Classes know their own dependencies. Just ask them: import module for superclass in module.A.__bases__: print superclass, "is a dependency for class A" > However, if > they are in two separate files, for example B depends on A, then I will > have 'import A' in file B. This dependency can be easily figured out by > a script. If they are in the same file, you can just look at the class definition: class B(A): And now you know with 100% accuracy that B depends on A, instead of guessing that just because you import a module, that means you must have used a class from that module. > The following scenario also demonstrate why the maintenance cost is > lower with one class/function per file, because it decouples > dependences. Let's suppose class A and B are in the same file. Now I'm > changing class B. But while I'm changing class B, I just realize that I > have to change A. But since the change in B is half way done > (syntactical not correct), I will not be able to run the test case for > A, because the test case import the file that has class B. In contrast, > if A and B are in different files, even if B is half way done, I can > still run test case for A. Assuming A and B are independent, or that B depends on A but not the opposite, failing tests for B won't cause tests for A to fail. This doesn't change whether A and B are in the same file or not. The one exception to this is syntax errors. But if your project contains syntax errors, why are you trying to run test suites? -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:24:54 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:24:54 GMT Subject: chr / ord References: Message-ID: <02ffad01$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 20:30:00 -0800, Sean McIlroy wrote: > hello > > how do i say "chr" and "ord" in the new python? "chr" and "ord". > the functions below (which work in 2.6.6) Can I borrow your time machine, there's some lottery numbers I want to get. There is no Python 2.6.6. The latest version of 2.6 is 2.6.4. > show what i'm trying to do. thanks if you can help. > > def readbytes(filepath): > return [ord(x) for x in open(filepath,'rb').read()] > > def writebytes(numbers,filepath): > open(filepath,'wb').write(''.join([chr(x) for x in numbers])) Have you tried them in "the new Python" (whatever that is...)? What do they do that isn't what you expect? -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 00:31:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 05:31:51 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> Message-ID: <02ffaea2$0$1326$c3e8da3@news.astraweb.com> On Mon, 02 Nov 2009 20:06:51 -0800, Anh Hai Trinh wrote: >> Yes, just about any ?map()? operation has a corresponding list >> comprehension. (Does anyone know of a counter-example, a ?map()? >> operation that doesn't have a correspondingly simple list >> comprehension?) > > Try turning this into a list comprehension: > > vectorsum = lambda *args: map(sum, zip(*args)) > > vectorsum([1,2], [3,4], [5,6]) > ->[9, 12] > vectorsum([1,2], [3,4], [5,6], [7,8]) > ->[16, 20] [sum(t) for t in zip(*args)] will do it. >>> args = [1,2], [3,4], [5,6] >>> [sum(t) for t in zip(*args)] [9, 12] >>> args = [1,2], [3,4], [5,6], [7,8] >>> [sum(t) for t in zip(*args)] [16, 20] -- Steven From half.italian at gmail.com Tue Nov 3 01:54:42 2009 From: half.italian at gmail.com (Sean DiZazzo) Date: Mon, 2 Nov 2009 22:54:42 -0800 (PST) Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87bpjll4o2.fsf@benfinney.id.au> <87zl74i4mr.fsf@benfinney.id.au> Message-ID: <9d28a01c-c65b-40d5-ab14-d56118de3dd8@h14g2000pri.googlegroups.com> On Nov 2, 9:01?pm, Ben Finney wrote: > Anh Hai Trinh writes: > > > > Yes, just about any ?map()? operation has a corresponding list > > > comprehension. (Does anyone know of a counter-example, a ?map()? > > > operation that doesn't have a correspondingly simple list > > > comprehension?) > > > Try turning this into a list comprehension: > > > ? vectorsum = lambda *args: map(sum, zip(*args)) > > By ?this? I take you to mean ?the usage of ?map? in this code?, since > that's the limit of my question. > > ? ? >>> vectorsum = lambda *args: [sum(items) for items in zip(*args)] > ? ? >>> vectorsum([1,2], [3,4], [5,6]) > ? ? [9, 12] > ? ? >>> vectorsum([1,2], [3,4], [5,6], [7,8]) > ? ? [16, 20] > > -- > ?\ ? ? ? ?The apparent lesson of the Inquisition is that insistence on | > ? `\ ? ? ? ? uniformity of belief is fatal to intellectual, moral, and | > _o__) ? ?spiritual health.? ?_The Uses Of The Past_, Herbert J. Muller | > Ben Finney prickly From ldo at geek-central.gen.new_zealand Tue Nov 3 01:59:08 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 19:59:08 +1300 Subject: Sqlite3. Substitution of names in query. References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: In message , Carsten Haese wrote: > With all due respect, but if your experience is exclusive to > MySQL/MySQLdb, your experience means very little for database > programming practices in general. I wonder about the veracity of your claims, because: > And here are the corresponding results on my laptop: > $ python -mtimeit -s "from querytest import Tester; t=Tester()" > 't.with_params()' > 10000 loops, best of 3: 20.9 usec per loop > $ python -mtimeit -s "from querytest import Tester; t=Tester()" > 't.without_params()' > 10000 loops, best of 3: 36.2 usec per loop Didn't you say previously that there should be a "seven orders of magnitude" difference? What happened to that claim? From ldo at geek-central.gen.new_zealand Tue Nov 3 02:02:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 20:02:59 +1300 Subject: Sqlite3. Substitution of names in query. References: Message-ID: In message , Dennis Lee Bieber wrote: > On Tue, 03 Nov 2009 09:41:10 +1300, Lawrence D'Oliveiro > declaimed the following in > gmane.comp.python.general: > >> There is no such parsing overhead. I speak from experience. >> > > >> Look at the BulkInserter class here >> . I have >> successfully used that to insert tens of thousands of records in just a >> few seconds. Yet it makes no use of the parameter-substitution provided >> by MySQLdb; it is all > > You picked the wrong database to use for your argument. I would say "that is precisely my point", but I'll be kind and give you a chance: pick another database, if you think that will make your point better. From paul.nospam at rudin.co.uk Tue Nov 3 02:10:27 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 03 Nov 2009 07:10:27 +0000 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> Message-ID: <87k4y8rsm4.fsf@rudin.co.uk> Falcolas writes: > [s.strip() for s in hosts if s.strip()] There's something in me that rebels against seeing the same call twice. I'd probably write: filter(None, (s.strip() for s in hosts)) From ben+python at benfinney.id.au Tue Nov 3 02:59:37 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 18:59:37 +1100 Subject: list comprehension problem References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <7589e0a1-98b2-4df4-bc76-5d4c10194fde@f20g2000prn.googlegroups.com> <87k4y8rsm4.fsf@rudin.co.uk> Message-ID: <87my34hwd2.fsf@benfinney.id.au> Paul Rudin writes: > Falcolas writes: > > > [s.strip() for s in hosts if s.strip()] > > There's something in me that rebels against seeing the same call > twice. Agreed. I'd probably use: >>> lines = ["foo", " ", " bar ", "", "baz"] >>> [s for s in (s.strip() for s in lines) if s] ['foo', 'bar', 'baz'] -- \ ?[I]t is impossible for anyone to begin to learn that which he | `\ thinks he already knows.? ?Epictetus, _Discourses_ | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Tue Nov 3 04:14:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 03 Nov 2009 22:14:25 +1300 Subject: Docs Typo Message-ID: -- ?ScrolledCavas? should be ?ScrolledCanvas?. Also, unlike documentation for other library modules, there is no indication of which features are new in Python 2.6. From ben+python at benfinney.id.au Tue Nov 3 04:38:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 20:38:19 +1100 Subject: Docs Typo References: Message-ID: <87eioghrsk.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > -- ?ScrolledCavas? should be > ?ScrolledCanvas?. Thanks for finding and describing a fault with the Python documentation. This is not the right place for reporting it, though: this is the Python user forum, not an appropriate place for reporting faults. If you would like the issue to be addressed, please report it to the Python bug tracking system . -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From henning.bredel at gmx.de Tue Nov 3 04:41:37 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 03 Nov 2009 09:41:37 GMT Subject: Cast into custom type Message-ID: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Hi, I created a plugin mechanism for my application orientating at the mechanism described by Martin Alchy in http://martyalchin.com/2008/jan/10/simple-plugin-framework/ Now I'd like to call methods like `initialize(parent)' when the user chooses to use a plugin. As described in the blog mentioned above, I only have access to the general type called `PluginMount' (holding all the actual plugin instances). I tried to define "abstract" methods in PluginMount type raising a `NotImplementedError' but it seems, there is no late binding (similar to Java), so the right method would be called. Only the message TypeError: unbound method initialize() must be called with GeoCache instance as first argument (got PluginMount instance instead) `GeoCache' would be the plugin type. What is strange, is the fact, that when asking what instances are hold by PluginMount [] is listed. So it seems, that no late binding is applied when calling the `initialize(self, parent)' method. I'm quite new using Python, so this might be a quite basic question caused by some misunderstandings in general. Feel free to point me to appropriate site to solve my problem. Thanks in advance. Henning From deets at nospam.web.de Tue Nov 3 05:00:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 11:00:23 +0100 Subject: Cast into custom type In-Reply-To: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <7lad9nF3dalgbU1@mid.uni-berlin.de> Henning Bredel schrieb: > Hi, > > I created a plugin mechanism for my application orientating > at the mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ > > Now I'd like to call methods like `initialize(parent)' when > the user chooses to use a plugin. As described in the blog > mentioned above, I only have access to the general type called > `PluginMount' (holding all the actual plugin instances). > > I tried to define "abstract" methods in PluginMount type > raising a `NotImplementedError' but it seems, there is no > late binding (similar to Java), so the right method would be > called. Only the message > > TypeError: unbound method initialize() must be called > with GeoCache instance as first argument (got PluginMount > instance instead) > > `GeoCache' would be the plugin type. What is strange, is the > fact, that when asking what instances are hold by PluginMount > > [] > > is listed. So it seems, that no late binding is applied when > calling the `initialize(self, parent)' method. > > I'm quite new using Python, so this might be a quite basic > question caused by some misunderstandings in general. Feel > free to point me to appropriate site to solve my problem. It seems that GeoCache is not a subclass of PluginMount. Diez From gagsl-py2 at yahoo.com.ar Tue Nov 3 05:08:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 07:08:03 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Tue, 03 Nov 2009 06:41:37 -0300, Henning Bredel escribi?: > I created a plugin mechanism for my application orientating > at the mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ > > Now I'd like to call methods like `initialize(parent)' when > the user chooses to use a plugin. As described in the blog > mentioned above, I only have access to the general type called > `PluginMount' (holding all the actual plugin instances). According to the article, PluginMount holds a list of all plugin *classes* defined, not instances. > I tried to define "abstract" methods in PluginMount type > raising a `NotImplementedError' but it seems, there is no > late binding (similar to Java), so the right method would be > called. Only the message > > TypeError: unbound method initialize() must be called > with GeoCache instance as first argument (got PluginMount > instance instead) Python uses "late binding", even more than Java. A reference like obj.foo(...) searches for "foo" along obj's attributes at runtime. Please post some code showing your issue, and don't forget to tell us what is your expected result, and what you actually get. -- Gabriel Genellina From gatti at dsdata.it Tue Nov 3 05:11:59 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 3 Nov 2009 02:11:59 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> Message-ID: <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> On Nov 1, 8:06?am, Saketh wrote: > Hi everyone, > > I am proud to announce the release of Pyfora (http://pyfora.org), an > online community of Python enthusiasts to supplement comp.lang.python > and #python. While the site is small right now, please feel free to > register and post any questions or tips you may have. I'll feel free to not even bookmark it. I'm sorry, but it is just a bad idea. Your forum cannot (and should not) compete either with Python's official newsgroup, IRC channel and mailing list or with popular, well- made and well-frequented general programming sites like stackoverflow.com. It would be the Internet equivalent of looking for a poker tournament in a desert valley instead of driving half an hour less and going to Las Vegas: there are no incentives to choose your forum, except perhaps for isolationists who value being a big fish in a small pond over being part of a community. If you want to claim a small Python-related corner of the web, you should write a blog: if it is any good, and probably even if it isn't, it would be linked and read by someone and it would add to collective knowledge instead of fragmenting it. Regards, Lorenzo Gatti From steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 05:18:29 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 10:18:29 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <02fff1ce$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 09:41:37 +0000, Henning Bredel wrote: > Hi, > > I created a plugin mechanism for my application orientating at the > mechanism described by Martin Alchy in > > http://martyalchin.com/2008/jan/10/simple-plugin-framework/ Regarding your subject line, Python doesn't have casts. A very small number of numeric types are automatically coerced as needed, for everything else you need an explicit conversion between objects of one type to different objects of another type. > Now I'd like to call methods like `initialize(parent)' when the user > chooses to use a plugin. As described in the blog mentioned above, I > only have access to the general type called `PluginMount' (holding all > the actual plugin instances). > > I tried to define "abstract" methods in PluginMount type raising a > `NotImplementedError' but it seems, there is no late binding (similar to > Java), so the right method would be called. You need to give some actual examples of what you are trying to do, and what you are expecting to happen. How is initialized() being called? > Only the message > > TypeError: unbound method initialize() must be called with GeoCache > instance as first argument (got PluginMount instance instead) Sounds like you are calling initialize on the class instead of on an instance. I'm *guessing* that you are doing something like this: plugin_manager = PluginMount() # ... # create plugins, which are registered in the plugin_manager # ... # Now initialize them: for cls in plugin_manager.plugins: cls.initialize(plugin_Manager) If my guess is correct, you can fix this two ways: (1) Change the for-loop to: for cls in plugin_manager.plugins: cls().initialize(plugin_Manager) although it isn't clear to me what you should do with the plugin instances after you've created them. (2) Change the initialize method to a classmethod: @classmethod def initialize(cls, parent): pass > `GeoCache' would be the plugin type. What is strange, is the fact, that > when asking what instances are hold by PluginMount > > [] > > is listed. So it seems, that no late binding is applied when calling the > `initialize(self, parent)' method. What do you mean by late binding, and what makes you think it applies (or should apply) to calling the initialize method? > I'm quite new using Python, so this might be a quite basic question > caused by some misunderstandings in general. Feel free to point me to > appropriate site to solve my problem. We have to understand your problem first. -- Steven From eric.brunel.pragmadev at gmail.com Tue Nov 3 05:19:54 2009 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Tue, 3 Nov 2009 02:19:54 -0800 (PST) Subject: PyGDChart2 module References: <17ace5a2-a541-4512-9699-a4719c6e65bb@p15g2000vbl.googlegroups.com> Message-ID: On Oct 28, 4:52 pm, eb303 wrote: > Hi all, > > I was looking for a simple chart drawing Python module and as a user > of the gd library and its Python interface, I was interested in the > Python interface to the gdchart library (http://www.fred.net/brv/ > chart/). Unfortunately, this module seems to have disappeared: its > former URL (http://www.nullcube.com/software/pygdchart2.html) gives a > 404 and a Google search did not return any other source. Does anyone > know where I can find a copy of this module's source code? > > Thanks. Replying to myself: finally found the source package at http://ftp.de.debian.org/debian/pool/main/p/pygdchart2/pygdchart2_0.beta1.orig.tar.gz Seems to work quite well. From mal at egenix.com Tue Nov 3 05:27:20 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 11:27:20 +0100 Subject: Pyfora, a place for python In-Reply-To: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> Message-ID: <4AF00588.5070504@egenix.com> Kee Nethery wrote: > I just noticed the tag line "a place for Python". Looked it up online > (http://pyfora.org/) and it will be interesting to see if it can fill > the void that I experience (no centralized place to post and view user > submitted sample code) in the existing Python community. There already is a well-known site for exchanging code snippets: The ActiveState Cookbook for Python http://code.activestate.com/recipes/langs/python/ > As for user community fragmentation, I would guess that someone would be > less likely to create such a site if the user community needs were being > met by the official sites. There is a place for the existing old school > interaction forums (the IRC channel, the Usenet groups and mailing > lists), but there is also a place for archived user submitted comments. > > My personal preference would be a link in each sub-paragraph in the > official documentation to a wiki page devoted to that specific aspect of > the Python language. A place were users could augment the documentation > by providing sample code and by expanding out the documentation for > those of us who don't live and breath Python in our sleep. Real Python > coders would not click on the user wiki links and all of us newbies > could communicate with each other. But until a place like that exists, > perhaps Pyfora will get us part way there. I'm sure something like that could be added to the official documentation. Please file a feature request for on the Python tracker. We could have a dedicated place on the python.org wiki to host such snippets and then use sub-pages for the various topics. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 steve at REMOVE-THIS-cybersource.com.au Tue Nov 3 05:37:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Nov 2009 10:37:13 GMT Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> Message-ID: <02fff632$0$1326$c3e8da3@news.astraweb.com> On Tue, 03 Nov 2009 02:11:59 -0800, Lorenzo Gatti wrote: > On Nov 1, 8:06?am, Saketh wrote: >> Hi everyone, >> >> I am proud to announce the release of Pyfora (http://pyfora.org), an >> online community of Python enthusiasts to supplement comp.lang.python >> and #python. While the site is small right now, please feel free to >> register and post any questions or tips you may have. > > I'll feel free to not even bookmark it. I'm sorry, but it is just a bad > idea. > > Your forum cannot (and should not) compete either with Python's official > newsgroup, IRC channel and mailing list or with popular, well- made and > well-frequented general programming sites like stackoverflow.com. Are you saying that now that comp.lang.python and stackoverflow exists, there no more room in the world for any more Python forums? I think that's terrible. Saketh, would you care to give a brief explanation for sets your forum apart from the existing Python forums, and why people should choose to spend time there instead of (or as well as) the existing forums? What advantages does it have? > It would be the Internet equivalent of looking for a poker tournament in > a desert valley instead of driving half an hour less and going to Las > Vegas: there are no incentives to choose your forum, except perhaps for > isolationists who value being a big fish in a small pond over being part > of a community. (Funny you mention Las Vegas -- it started off as a tiny little town in the middle of the desert too.) How about avoiding the noise and obtrusive advertising and bright lights of Las Vegas, the fakery, the "showmanship", the horrible fake pyramid and has-been celebrities, the crowds, the tackiness, the high prices, the bright lights that never turn off (Las Vegas is the brightest city on Earth)... if you're interested in poker without all the mayonnaise, maybe that poker tournament away from the tourists is exactly what you need. Personally, if I wanted to gamble, the last place I would go is any house which had gold-plated taps in the bathrooms. That tells me the house's percentage is *way* too high. -- Steven From simon at brunningonline.net Tue Nov 3 06:26:49 2009 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 3 Nov 2009 11:26:49 +0000 Subject: self.__dict__ tricks In-Reply-To: <02fd0c85$0$1326$c3e8da3@news.astraweb.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> 2009/11/1 Steven D'Aprano : > > The only stupid question is the one you are afraid to ask. I was once asked, and I quote exactly, "are there any fish in the Atlantic sea?" That's pretty stupid. ;-) -- Cheers, Simon B. From furkankuru at gmail.com Tue Nov 3 06:45:31 2009 From: furkankuru at gmail.com (Furkan Kuru) Date: Tue, 3 Nov 2009 13:45:31 +0200 Subject: convert pyc (python 2.4) to py In-Reply-To: <50697b2c0910211158r5f9a1395sfef1976cfc27fc09@mail.gmail.com> References: <7k6p69F3888guU1@mid.uni-berlin.de> <366c6f340910211135r1170757dv746e46f58dbe1ec4@mail.gmail.com> <50697b2c0910211158r5f9a1395sfef1976cfc27fc09@mail.gmail.com> Message-ID: <3a4a8f930911030345l53e45244r301e6839acaa2e4d@mail.gmail.com> There is an online service at http://www.depython.com converting pyc files to py. You can give it a try. It does not have file size limit. On Wed, Oct 21, 2009 at 8:58 PM, Chris Rebert wrote: > On Wed, Oct 21, 2009 at 11:35 AM, Peng Yu wrote: >> On Tue, Oct 20, 2009 at 4:42 PM, Diez B. Roggisch wrote: >>> Peng Yu schrieb: >>>> >>>> I have a .pyc file generated by python 2.4. My current python is of >>>> version 2.6. I'm wondering how to generate the corresponding .py file >>>> from it. >>> >>> http://www.crazy-compilers.com/decompyle/ >> >> Is there any free one? > > There's an older version of the software at: > http://sourceforge.net/projects/decompyle/ > but it's not maintained like the service (just see the last-modified > date on it) and you'll have to figure out how to use it by yourself. > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Furkan Kuru From deets at nospam.web.de Tue Nov 3 06:52:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 12:52:20 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> Message-ID: <7lajrkF3c97onU1@mid.uni-berlin.de> Peng Yu wrote: > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: >> Peng Yu wrote: >>> I don't think that this is a problem that can not be overcome. A >>> simple solution might be to associate a unique identifier to each >>> file, so that even the filename has been changed, the new version and >>> the old version can still be identified as actually the same file. >> >> Or, again, you could work _with_ the tools you're using in the way >> they're meant to be used, rather than re-inventing the whole process >> of version control yourself. > > I'm not trying to reinvent a new version control. But due to this > drawback, I avoid use a version control system. Rather, I compressed > my source code in a tar file whenever necessary. But if a version > control system has this capability, I'd love to use it. And I don't > think that no version control system support this is because of any > technical difficult but rather because of practical issue (maybe it > takes a lot efforts to add this feature to an existing version control > system?). There are those people who realize if *everything* they encounter needs adjustment to fit their needs, their needs need adjustment. Others fight an uphill battle & bicker about things not being as they want them. Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis. Diez From ben+python at benfinney.id.au Tue Nov 3 07:02:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Nov 2009 23:02:44 +1100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <7lajrkF3c97onU1@mid.uni-berlin.de> Message-ID: <87639rizob.fsf@benfinney.id.au> "Diez B. Roggisch" writes: > Don't get me wrong - innovation often comes from scratching ones > personal itch. But you seem to be suffering from a rather bad case of > neurodermatitis. +1 QOTW -- \ ?For my birthday I got a humidifier and a de-humidifier. I put | `\ them in the same room and let them fight it out.? ?Steven Wright | _o__) | Ben Finney From henning.bredel at gmx.de Tue Nov 3 07:07:01 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 03 Nov 2009 12:07:01 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> Message-ID: <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Diez, Gabriel, Steven, thanks for your answers. I'll mainly give response in this posting, so I hope not repeating myself. On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: > On Tue, 03 Nov 2009 09:41:37 +0000, Henning Bredel wrote: > >> Now I'd like to call methods like `initialize(parent)' when the user >> chooses to use a plugin. As described in the blog mentioned above, I >> only have access to the general type called `PluginMount' (holding all >> the actual plugin instances). >> >> I tried to define "abstract" methods in PluginMount type raising a >> `NotImplementedError' but it seems, there is no late binding (similar >> to Java), so the right method would be called. > > You need to give some actual examples of what you are trying to do, and > what you are expecting to happen. How is initialized() being called? Example: Assume a framework which offers common functionality for a plugin or a module a user can choose at the beginning. The framework does not know the concrete type of the plugin so it is possible to extend it by implementing a well known interface or abstract class. The framework reads the plugin directory, loads each module and creates buttons for each plugin with a callback method for initializing. To use common functionality of the framework, initialization method takes it as the parent parameter. I think this listing makes the most sense to you: # initialize all plugins self._plugin_modules = _load_plugins() # imp loading here LOGGER.debug(ActionProvider.plugins) # print what was loaded for plugin in ActionProvider.plugins: # create button for each app_button = gtk.Button(plugin.title) LOGGER.debug('Title of plugin: %s' % plugin.title) app_button.connect("clicked", plugin.initialize(plugin, self), None) self.set_canvas(app_button) app_button.show() >> TypeError: unbound method initialize() must be called with GeoCache >> instance as first argument (got PluginMount instance instead) > > Sounds like you are calling initialize on the class instead of on an > instance. I'm *guessing* that you are doing something like this: Oh, I didn't expext PluginMount to hold only classes :/. When calling `LOGGER.debug('Title of plugin: %s' % plugin.title)' the global (not class attribute) `title' attribute is printed out though. Probably some misinterpretation, too ..?! > (1) Change the for-loop to: > > for cls in plugin_manager.plugins: > cls().initialize(plugin_Manager) Good guess .. but calling it in that way another error says app_button.connect("clicked", plugin().initialize(self), None) TypeError: __init__() takes exactly 2 arguments (1 given) But also app_button.connect("clicked", plugin().initialize(plugin, self), None) TypeError: __init__() takes exactly 2 arguments (1 given) That is strange, because neither initialize() nor __init__ of the plugin is called .. only a logging statement shall print a msg. I hope it got a bit clearer what I am intended to do. Thanks for your help. Henning From python-url at phaseit.net Tue Nov 3 07:16:41 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 3 Nov 2009 12:16:41 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 3) Message-ID: QOTW: "I consider "import *" the first error to be fixed ..." - Robert Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker, on his personal style http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 Python 2.6.4 is out; it fixes some small but important bugs in previous 2.6.3 release: http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/ PEP391: A new way to configure Python logging, using dictionaries: http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/ Why do you use Python? http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/ Is there any value in forcing one class/function per module? (long thread): http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/ A review of complex solutions to an almost inexistent problem shows constructive criticism in action: http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/ A user module may shadow a standard module of the same name - is it avoidable? http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/ copy.deepcopy() is not as "deep" as its name implies: http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/ A long thread about Web development: why to use templates, and why frameworks actually do help developers: http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/ Using a module as a place to store application global settings: http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/ A simple list comprehension question leads to discuss mutability, identity, and Cousin Chuy's Super-Burritos: http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/ Combining map, zip and filter into an equivalent list comprehension: http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map timeit: make sure you actually measure what you want, and not other code: http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/ Why do compiled C extensions on Windows use '.pyd' in their name instead of '.dll'? http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/ Pyfora, a web forum about Python, was lauched recently. Will this fragment the community? http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/ A guy's future book on programming Python doesn't fit standard practice (a long thread!): http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 israelu at elbit.co.il Tue Nov 3 07:45:49 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 04:45:49 -0800 (PST) Subject: import from a string Message-ID: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Hi, Having a file called funcs.py, I would like to read it into a string, and then import from that string. That is instead of importing from the fie system, I wonder if it's possible to eval the text in the string and treat it as a module. For example with file('funcs.py') as f: txt = r.read() string_import(txt, 'funcs') # is string_import possible? to have now a module called funcs with the functions defined in funcs.py. Thanks From singletoned at gmail.com Tue Nov 3 07:53:44 2009 From: singletoned at gmail.com (Singletoned) Date: Tue, 3 Nov 2009 04:53:44 -0800 (PST) Subject: Aaaargh! "global name 'eggz' is not defined" References: <4aeaa96c$0$4145$426a74cc@news.free.fr> Message-ID: <05a9780d-bce4-42b6-834a-e81681923c04@k19g2000yqc.googlegroups.com> On Oct 30, 8:53?am, Bruno Desthuilliers wrote: > Robert Kern a ?crit :> On 2009-10-29 16:52 PM, Aahz wrote: > (snip) > >> Coincidentally, I tried PyFlakes yesterday and was unimpressed with the > >> way it doesn't work with "import *". > > > I consider "import *" the first error to be fixed, so it doesn't bother > > me much. :-) > > +1 QOTW Bruno, do you actually get to decide the QOTW? Because everytime you ` +1 QOTW` it gets to be the QOTW. Ed BTW I was the grateful recipient of your vote the other week. From rolf.oltmans at gmail.com Tue Nov 3 08:06:24 2009 From: rolf.oltmans at gmail.com (Oltmans) Date: Tue, 3 Nov 2009 05:06:24 -0800 (PST) Subject: Help resolve a syntax error on 'as' keyword (python 2.5) Message-ID: Hi, all. All I'm trying to do is to print the error message using the following code (copying/pasting from IDLE). def div(a,b): print a/b try: div(5,0) except Exception as msg: print msg but IDLE says (while highlighting the 'as' keyword) except Exception as msg: SyntaxError: invalid syntax I've searched the internet and I'm not sure what can cause this. Any help is highly appreciated. I'm using Python 2.5 on Windows XP. From fetchinson at googlemail.com Tue Nov 3 08:19:02 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 3 Nov 2009 14:19:02 +0100 Subject: Pyfora, a place for python In-Reply-To: <7l9asbF3c7qa2U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: On 11/3/09, Diez B. Roggisch wrote: > Daniel Fetchinson schrieb: >>>>>> If you have any suggestions, let me know -- this is a community >>>>>> effort! >>>>> Suggestion: Please don't make efforts to fragment the community. >>>> When a community grows and consequently its needs also grow, how do >>>> you differentiate "natural growth" from "fragmenting the community"? >>>> >>>> Same question in another way: let's suppose Tim Peters sent the exact >>>> email the OP sent with the exact same website. Would you have >>>> responded to him the same way? >>> Most probably not - but then because Tim certainly would have discussed >>> this >>> move with peers from the community, if there is a need for this kind of >>> forum or not. >>> >>> Being from germany, I can say that we *have* this fragmentation, and >>> frankly: I don't like it. I prefer my communication via NNTP/ML, and not >>> with those visually rather noisy and IMHO suboptimal forums. >> >> If you prefer NNTP/ML, I'd suggest you pay attention to these channels >> only. BTW, I prefer ML also and I'm very happy with c.l.p. However >> that doesn't mean that I need to be hostile to other forms of >> communication and it doesn't mean that I need to discourage people >> from setting up other channels of communication for those folks who >> prefer them. > > Since when is the mere suggestion that fragmentation will occur and if > that's a desirable consequence is hostile? The OP is not bound to it, > and I also don't see the tone used by the two immediate answerers being > hostile. Paul might have been terse - but hostility looks different IMHO. I was referring to this comment by Ben: "Suggestion: Please don't make efforts to fragment the community." This IMHO is hostile, because it presupposes that the mere goal of the OP is fragmenting the community, which is something negative, i.e. it contains negative prejudice. What I would have written in Ben's place: Have you considered the possibility that your website will further fragment the community? This wouldn't have been hostile, IMHO. > The OP *might* come to the conclusion that further fragmenting the > community isn't within his personal goals either. OTOH, he might also > simply think that once his forum gained traction, he can switch on the > google ads, and cash in. Which a forum announced by Tim Peters, run > under python.org wouldn't I'd say. > >> If new channels open up for others it will not make c.l.p any worse. > > It will, if they catch on. As some competent people will move away. Competent people will only move away if the website is great/fun/useful/etc. In which case we should welcome it, since something great/fun/useful/etc is a good thing. If it's not great/fun/useful/etc competent people will not move away, in which case c.l.p. will not be any worse as a result of launching the new website. > Again, this is the case in the german python scene, and it plain sucks. > We have a ML, a NG, and a forum. None of them is synchronized in any > way. We wanted to do this for ML and NG - but the guy responsible for > the ML can't be reached, or refuses to answer. Welcome to open source, the world of infinitely many forks, code variants, MLs, forums, NGs, websites, in other words, welcome to the bazaar! Cheers, Daniel > If we had only one source, fragmentation wouldn't occur, and the > competence would be bundled. That I personally prefer MLs and NGs > doesn't mean that I wouldn't turn to the forum if it was *the* way to > talk about Python. But as it stands, there are three kind of things, of > which I'm already subsribed to two - and am annoyed of people posting > questions in both of them. > > Now, I can't do anything about it in the sense that I can forbid it. But > questioning the move to create a new form of exchange (especially > something rather uninspired, in contrast to e.g. stackoverflow) I can. > >> If enough people like c.l.p. it will continue to be a good channel, if >> too many too good people switch to an online forum, well, in that case >> c.l.p. will cease to be great, but it won't be because of artificial >> fragmentation by somebody but because the people started to prefer >> online forums (words like "free market" come to mind :)) > > Yes. Or all of them suck equally. Free market again. I'm not against it, > but asking the OP if he really thinks the value of his forum outweighs > the risk of making existing fora worse is a valid question. Free speech, > one other nice free thing out there. > >> I generally not register on any online forum and will most probably >> not register on pyfora either. But I know for a fact that many people >> prefer forums over ML and why shouldn't those people be happy with the >> communication platform they like and why shouldn't they be given a >> chance to join the python community if the only reason they stayed >> away was that they didn't like c.l.p. for one reason or another? >> >>> E.g. it >>> requires much more effort to get to know what new discussions arose, as >>> well as following ongoing ones - because the interface lacks a >>> comprehensive overview of that, and features like "jump to next unread >>> article". >> >> These are perfectly legitimate reasons for you to not use online >> forums and stick to c.l.p. I do the same thing. But again, if an >> enthusiastic python community member wants to open new channels for >> those folks who like them, why should anyone be hostile to him/her? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From carsten.haese at gmail.com Tue Nov 3 08:19:10 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 03 Nov 2009 08:19:10 -0500 Subject: Sqlite3. Substitution of names in query. In-Reply-To: References: <5b9f997f-4d1d-4fe9-b2f2-13a0ed733d2c@t2g2000yqn.googlegroups.com> <7l04e4F3b2u36U1@mid.uni-berlin.de> <81a64cf3-f2ce-4f1d-a5e6-053ce736b230@m16g2000yqc.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Carsten > Haese wrote: > >> With all due respect, but if your experience is exclusive to >> MySQL/MySQLdb, your experience means very little for database >> programming practices in general. > > I wonder about the veracity of your claims, because: > >> And here are the corresponding results on my laptop: >> $ python -mtimeit -s "from querytest import Tester; t=Tester()" >> 't.with_params()' >> 10000 loops, best of 3: 20.9 usec per loop >> $ python -mtimeit -s "from querytest import Tester; t=Tester()" >> 't.without_params()' >> 10000 loops, best of 3: 36.2 usec per loop > > Didn't you say previously that there should be a "seven orders of magnitude" > difference? What happened to that claim? "That claim" was an exaggeration I resorted to after you distorted the concept of choosing the right tool for the job into premature optimization. It wasn't my initial claim. The "seven orders" (which is actually log-10 orders of however often the same query is executed with different values) is of course only the cost increase on parsing the query itself, which as you pointed out is drowned out by other fixed costs associated with performing database queries. However, you can't dispute the fact that using string interpolation *is* in general less efficient than parameter binding, and that was my initial claim. -- Carsten Haese http://informixdb.sourceforge.net From kmisoft at gmail.com Tue Nov 3 08:19:15 2009 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Tue, 3 Nov 2009 16:19:15 +0300 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) In-Reply-To: References: Message-ID: Hi, "except Exception as variable" is a new python-3 syntax. You should use "except Exception, variable" syntax in 2.x series. Vladimir Ignatov On Tue, Nov 3, 2009 at 4:06 PM, Oltmans wrote: > Hi, all. All I'm trying to do is to print the error message using the > following code (copying/pasting from IDLE). > > def div(a,b): > ? ? ? ?print a/b > > > try: > ? ?div(5,0) > except Exception as msg: > ? ?print msg > > but IDLE says (while highlighting the 'as' keyword) > except Exception as msg: > > SyntaxError: invalid syntax > > I've searched the internet and I'm not sure what can cause this. Any > help is highly appreciated. I'm using Python 2.5 on Windows XP. From contact at xavierho.com Tue Nov 3 08:24:08 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 3 Nov 2009 23:24:08 +1000 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) In-Reply-To: References: Message-ID: <2d56febf0911030524l13b23bcala9ecc1b48715f7af@mail.gmail.com> I don't have Python 25 on my computer, but since codepad.org is using Python 2.5.1, I did a quick test: # input try: raise Exception("Mrraa!") except Exception as msg: print msg # output t.py:3: Warning: 'as' will become a reserved keyword in Python 2.6 Line 3 except Exception as msg: ^ SyntaxError: invalid syntax ######### Well that's interesting. as isn't a keyword yet in Python 2.5. This works though, and I think it fits the specification in the documentation. # input try: raise Exception("Mrraa!") except Exception, msg: # Notice it's a comma print msg # output Mrraa! ############## Hope that helps, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From claird.visiprise at gmail.com Tue Nov 3 08:29:27 2009 From: claird.visiprise at gmail.com (Cameron Laird) Date: Tue, 3 Nov 2009 05:29:27 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Nov 3) Message-ID: QOTW: "I consider "import *" the first error to be fixed ..." - Robert Kern, author of PyFlakes, a potential replacement for Pylint and Pychecker, on his personal style http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 Python 2.6.4 is out; it fixes some small but important bugs in previous 2.6.3 release: http://groups.google.com/group/comp.lang.python/t/44f4c166de5e6703/ PEP391: A new way to configure Python logging, using dictionaries: http://groups.google.com/group/comp.lang.python/t/3fc3138c22a50678/ Why do you use Python? http://groups.google.com/group/comp.lang.python/t/66ccb10d2da5b740/ Is there any value in forcing one class/function per module? (long thread): http://groups.google.com/group/comp.lang.python/t/1e0c1e2091539512/ A review of complex solutions to an almost inexistent problem shows constructive criticism in action: http://groups.google.com/group/comp.lang.python/t/d218212cabe9670b/ A user module may shadow a standard module of the same name - is it avoidable? http://groups.google.com/group/comp.lang.python/t/b31f74b6145c9d94/ copy.deepcopy() is not as "deep" as its name implies: http://groups.google.com/group/comp.lang.python/t/d827fd118189fe01/ A long thread about Web development: why to use templates, and why frameworks actually do help developers: http://groups.google.com/group/comp.lang.python/t/367025d4d9a2e15d/ Using a module as a place to store application global settings: http://groups.google.com/group/comp.lang.python/t/23e21edf1b232b32/ A simple list comprehension question leads to discuss mutability, identity, and Cousin Chuy's Super-Burritos: http://groups.google.com/group/comp.lang.python/t/17cfd91ece6ed54f/ Combining map, zip and filter into an equivalent list comprehension: http://groups.google.com/group/comp.lang.python/t/259976305282b0c0?q=map timeit: make sure you actually measure what you want, and not other code: http://groups.google.com/group/comp.lang.python/t/7ecae76e11f720ee/ Why do compiled C extensions on Windows use '.pyd' in their name instead of '.dll'? http://groups.google.com/group/comp.lang.python/t/c8d93871cc5f31dc/ Pyfora, a web forum about Python, was lauched recently. Will this fragment the community? http://groups.google.com/group/comp.lang.python/t/e6e0d99c995da697/ A guy's future book on programming Python doesn't fit standard practice (a long thread!): http://groups.google.com/group/comp.lang.python/t/6918784f36d147d2/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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.p ython.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 deets at nospam.web.de Tue Nov 3 09:00:23 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 15:00:23 +0100 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: <7larbnF3bfnutU1@mid.uni-berlin.de> Vladimir Ignatov wrote: > Hi, > > "except Exception as variable" > > is a new python-3 syntax. > > You should use "except Exception, variable" syntax in 2.x series. Not entirely true. This feature has been backported to python2.6 as well. Diez From ben+python at benfinney.id.au Tue Nov 3 09:16:47 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 01:16:47 +1100 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: <87r5sfhewg.fsf@benfinney.id.au> Oltmans writes: > try: > div(5,0) > except Exception as msg: > print msg The name ?msg? here is misleading. The except syntax does *not* bind the target to a message object, it binds the target to an exception object. It would be clearer to write the above code as: try: div(5, 0) except Exception as exc: print(exc) since the target ?exc? names an exception object, not a message. (The ?print? function will *create* a string object from the exception object, use the string, then discard it.) > but IDLE says (while highlighting the 'as' keyword) > except Exception as msg: > > SyntaxError: invalid syntax > I've searched the internet and I'm not sure what can cause this. When you get a syntax error, you should check the syntax documentation for the version of Python you're using. > Any help is highly appreciated. I'm using Python 2.5 on Windows XP. The syntax above is for Python 3 only . In Python 2.5.4, the ?try ? except? syntax was different , and ?print? was not implemented as a function, but instead as a keyword . Use this form: try: div(5, 0) except Exception, exc: print exc -- \ ?When I get new information, I change my position. What, sir, | `\ do you do with new information?? ?John Maynard Keynes | _o__) | Ben Finney From ben+python at benfinney.id.au Tue Nov 3 09:20:38 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 01:20:38 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: <87my33heq1.fsf@benfinney.id.au> Daniel Fetchinson writes: > I was referring to this comment by Ben: > > "Suggestion: Please don't make efforts to fragment the community." > > This IMHO is hostile, because it presupposes that the mere goal of the > OP is fragmenting the community It presupposes nothing of any goal. It describes a predictable result of the OP's efforts, and requests those efforts to cease. So I deny the characterisation of that request as hostile. -- \ ?Injustice is relatively easy to bear; what stings is justice.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From ahmedbarakat at gmail.com Tue Nov 3 09:21:12 2009 From: ahmedbarakat at gmail.com (Ahmed Barakat) Date: Tue, 3 Nov 2009 16:21:12 +0200 Subject: Handling large datastore search Message-ID: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> In case I have a huge datastore (10000 entries, each entry has like 6 properties), what is the best way to handle the search within such a huge datastore, and what if I want to make a generic search, for example you write a word and i use it to search within all properties I have for all entries? Is the conversion to XML a good solution, or it is not? sorry for being new to web development, and python. Thanks in advance. -- -------------------- Regards, Ahmed Barakat http://ahmedbarakat83.blogspot.com/ Even a small step counts -------------- next part -------------- An HTML attachment was scrubbed... URL: From motoom at xs4all.nl Tue Nov 3 09:53:51 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 03 Nov 2009 15:53:51 +0100 Subject: Handling large datastore search In-Reply-To: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> Message-ID: <4AF043FF.8050200@xs4all.nl> Ahmed Barakat wrote: > In case I have a huge datastore (10000 entries, each entry has like 6 > properties) Can you show some sample entries? That way we can get an idea how your datastore looks like. By the way, 10000 doesn't sound that much. At work I create python programs which do data processing and ofter have this much entries in a dictionary, often more. > Is the conversion to XML a good solution, or it is not? XML is meant to be an exchange format; it is not designed for storage or fast retrieval. Greetings, -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From gatti at dsdata.it Tue Nov 3 10:00:39 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 3 Nov 2009 07:00:39 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: <745e918b-ac0e-4486-93a4-e002bf27ddbf@c3g2000yqd.googlegroups.com> On Nov 3, 11:37?am, Steven D'Aprano wrote: > On Tue, 03 Nov 2009 02:11:59 -0800, Lorenzo Gatti wrote: [...] > Are you saying that now that comp.lang.python and stackoverflow exists, > there no more room in the world for any more Python forums? > > I think that's terrible. Although there is a high barrier to entry for general Python forums, it is not a problem because the door is always open for specialized forums that become the natural "home" of some group or thought leader or of some special interest, for example the forum of a new software product or of the fans of an important blog. Unfortunately, pyfora.org has neither a distinct crowd behind it nor an unique topic, and thus no niche to fill; it can only contribute fragmentation, which is unfortunate because Saketh seems enthusiastic. What in some fields (e.g. warez forums or art boards) would be healthy redundancy and competition between sites and forums becomes pure fragmentation if the only effect of multiple forums is to separate the same questions and opinions that would be posted elsewhere from potential readers and answerers. Reasonable people know this and post their requests for help and discussions either in the same appropriate places as everyone else or in random places they know and like; one needs serious personal issues to abandon popular forums for obscure ones. > Saketh, would you care to give a brief explanation for sets your forum > apart from the existing Python forums, and why people should choose to > spend time there instead of (or as well as) the existing forums? What > advantages does it have? That's the point, I couldn't put it better. > > It would be the Internet equivalent of looking for a poker tournament in > > a desert valley instead of driving half an hour less and going to Las > > Vegas: > > [...] > How about avoiding the noise and obtrusive advertising and bright lights > of Las Vegas, the fakery, the "showmanship", > [...] > if you're interested in poker without all the mayonnaise, maybe > that poker tournament away from the tourists is exactly what you need. I didn't explain my similitude clearly: I was comparing the fitness for purpose of going to Las Vegas with a plan to gamble with the absurdity of stopping, say, at an isolated gas station in the hope of finding a poker tournament there. If you are hinting that popular newsgroups and forums might be so full of fakery, showmanship, mayonnaise, etc. to deserve secession, it's another topic. Regards, Lorenzo Gatti From Scott.Daniels at Acm.Org Tue Nov 3 10:04:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 Nov 2009 07:04:41 -0800 Subject: list comprehension problem In-Reply-To: References: <7ktqpvF3ajgkiU3@mid.uni-berlin.de> <4AE9BE28.5080804@mrabarnett.plus.com> <40db9a24-414b-48c6-a52e-4589f3e3725b@m7g2000prd.googlegroups.com> Message-ID: Terry Reedy wrote: > What immutability has to do with identity is that 'two' immutable > objects with the same value *may* actually be the same object, > *depending on the particular version of a particular implementation*. > >> >>>>> t1 = (1,2,3) # an immutable object >>>>> t2 = (1,2,3) # another immutable object > > Whether or not this is 'another' object or the same object is irrelevant > for all purposes except identity checking. It is completely up to the > interpreter. > >>>>> t1 is t2 >> False > > In this case, but it could have been True. > >>>>> t1 == t2 >> True A more telling example: >>> t1 = (1, 2) + (3,) # an immutable object >>> t2 = (1,) + (2, 3) # another immutable object >>> t1 is t2 >> False >>>>> t1 is t2 >> False Here you make obvious that (assuming an optimizer that is not far more aggressive than Python is used to), in order to make equal immutable values identical, you'd have to end each operation producing an immutable result with a search of all appropriately typed values for one that was equal. --Scott David Daniels Scott.Daniels at Acm.Org From gh at ghaering.de Tue Nov 3 10:05:21 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 03 Nov 2009 16:05:21 +0100 Subject: Pyfora, a place for python In-Reply-To: <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> Message-ID: Lorenzo Gatti wrote: > On Nov 1, 8:06 am, Saketh wrote: >> Hi everyone, >> >> I am proud to announce the release of Pyfora (http://pyfora.org), an >> online community of Python enthusiasts to supplement comp.lang.python >> and #python. While the site is small right now, please feel free to >> register and post any questions or tips you may have. > > I'll feel free to not even bookmark it. I'm sorry, but it is just a > bad idea. [...] I agree. > Your forum cannot (and should not) compete either with Python's > official newsgroup, IRC channel and mailing list or with popular, well- > made and well-frequented general programming sites like > stackoverflow.com. [...] The good thing is, unless something the announced new forum gets critical mass, it will just slowly (or not-so-slowly die). But even though I'm an old-timer who still prefers newsgroups/mailing lists, I think that there should be something better, browser based. In particular supporting moderation/voting and tagging/filtering. -- Gerhard From simon.hibbs at gmail.com Tue Nov 3 10:17:40 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 3 Nov 2009 07:17:40 -0800 (PST) Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> <4e6ad15b-4f6d-463b-872a-44b400a4edaf@a37g2000prf.googlegroups.com> Message-ID: <1fecf2f6-58a5-43e4-8f03-deab170ffa8f@a32g2000yqm.googlegroups.com> On 3 Nov, 01:14, Collin D wrote: > Thanks for the replies. Pyparsing looks just like what I need. The cmd module in the standard library is fine for simple command interpreters. Depending on your needs you might find it does what you want. Doug Hellmann has covered it in his "Python module of the week" series of articles. http://www.doughellmann.com/PyMOTW/cmd/index.html Simon Hibbs From james at agentultra.com Tue Nov 3 10:22:28 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 03 Nov 2009 10:22:28 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> Message-ID: <87tyxbws3v.fsf@agentultra.com> Ben Finney writes: > J Kenneth King writes: > >> Steven D'Aprano writes: >> >> > from operator import add >> > map(add, operandlist1, operandlist2) >> >> This is the best solution so far. > > Strange to say it's a solution, when it doesn't solve the stated > problem: to replace use of ?map()? with a list comprehension. Granted I admit this later in my post. It's not a solution to the OPs request, but it is the best solution to such a case. > >> I understand the OP was asking for it, but list comprehensions aren't >> the best solution in this case... it would just be line noise. > > I disagree; a list comprehension is often clearer than use of ?map()? > with a lambda form, and I find it to be so in this case. The use of map expresses a value and implies the procedure by which it is obtained. The list comprehension expresses the procedure by which the value is obtained. Both have uses and in some cases a list comprehension is definitely preferrable to a map operation. However in this case the procedure by which we derive the value is not important or even interesting. It is much more succinct to think of the operation as a value and express it accordingly. There's no need to clutter the mind with extra name bindings and iteration keywords. They won't make our idea any more clear. dot_product = map(mul, vec1, vec2) vs dot_product = [a * b for a, b in zip(vec1, vec2)] It's very clear, at least to me, what a dot-product is in this case. Adding in the loop construct and name bindings doesn't enhance my understanding of what a dot-product is. I don't need to see the loop construct at all in this case. A dot product is simply the multiplication of each element in a vector sequence. It's more succinct to simply think of the value rather then expressing the procedure to construct that value. This isn't a hammer issue. Not every problem is a nail. From asksolem at gmail.com Tue Nov 3 10:29:10 2009 From: asksolem at gmail.com (Ask Solem) Date: Tue, 3 Nov 2009 07:29:10 -0800 (PST) Subject: import bug References: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> Message-ID: On Nov 3, 1:52?am, Carl Banks wrote: > On Oct 31, 7:12?am, kj wrote: > > > > > > > I'm running into an ugly bug, which, IMHO, is really a bug in the > > design of Python's module import scheme. ?Consider the following > > directory structure: > > > ham > > |-- __init__.py > > |-- re.py > > `-- spam.py > > > ...with the following very simple files: > > > % head ham/*.py > > ==> ham/__init__.py <== > > > ==> ham/re.py <== > > > ==> ham/spam.py <== > > import inspect > > > I.e. only ham/spam.py is not empty, and it contains the single line > > "import inspect". > > > If I now run the innocent-looking ham/spam.py, I get the following > > error: > > > % python26 ham/spam.py > > Traceback (most recent call last): > > ? File "ham/spam.py", line 1, in > > ? ? import inspect > > ? File "/usr/local/python-2.6.1/lib/python2.6/inspect.py", line 35, in > > ? ? import string > > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 122, in > > ? ? class Template: > > ? File "/usr/local/python-2.6.1/lib/python2.6/string.py", line 116, in __init__ > > ? ? 'delim' : _re.escape(cls.delimiter), > > AttributeError: 'module' object has no attribute 'escape' > > > or, similarly, > > > % python3 ham/spam.py > > Traceback (most recent call last): > > ? File "ham/spam.py", line 1, in > > ? ? import inspect > > ? File "/usr/local/python-3.0/lib/python3.0/inspect.py", line 36, in > > ? ? import string > > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 104, in > > ? ? class Template(metaclass=_TemplateMetaclass): > > ? File "/usr/local/python-3.0/lib/python3.0/string.py", line 98, in __init__ > > ? ? 'delim' : _re.escape(cls.delimiter), > > AttributeError: 'module' object has no attribute 'escape' > > > My sin appears to be having the (empty) file ham/re.py. ?So Python > > is confusing it with the re module of the standard library, and > > using it when the inspect module tries to import re. > > Python is documented as behaving this way, so this is not a bug. > > It is arguably poor design. ?However, Guido van Rossum already ruled > against using a single package for the standard library, and its not > likely that special case code to detect accidental name-clashes with > the standard library is going to be added, since there are legitimate > reasons to override the standard library. > > So for better or worse, you'll just have to deal with it. > > Carl Banks Just have to add that you're not just affected by the standard library. If you have a module named myapp.django, and someone writes a cool library called django that you want to use, you can't use it unless you rename your local django module. file myapp/django.py: from django.utils.functional import curry ImportError: No module named utils.functional At least that's what I get, maybe there is some workaround, some way to say this is an absolute path? From jaime.buelta at gmail.com Tue Nov 3 10:43:11 2009 From: jaime.buelta at gmail.com (Jaime Buelta) Date: Tue, 3 Nov 2009 07:43:11 -0800 (PST) Subject: Why do you use python? References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> <78f78eb9-bee0-4472-b758-5042919454c6@k19g2000yqc.googlegroups.com> Message-ID: <868d533a-c7b5-43ae-a1fb-67cfb855b4ec@v25g2000yqk.googlegroups.com> On 1 nov, 08:54, Dennis Lee Bieber wrote: > On Sat, 31 Oct 2009 06:54:27 -0700 (PDT), Jaime Buelta > declaimed the following in > gmane.comp.python.general: > > > shouldn't be heard. Talks a guy that programmed a GUI on Motif using C > > (plain old C) in 2003 and takes almost forever (one year and a half), > > ? ? ? ? Lucky you... > > ? ? ? ? I emulated a Ramtek 9300 (think that was the model) graphics engine > using GKS (for display lists, and ability to turn "layers" on/off > without regenerating all the data) on top of plain DECWindows/Xt > library, with no layout utility. Around 1990 (I date it by the fact > that, on return from the 7 week two site deployment of the application, > I decided my old cameras had gotten too burdensome, and bought a Canon > EOS 10s, 35-105 & 100-300 lenses, and a photo vest that I could wear > onto the flights) > > ? ? ? ? Emulation was needed as the data generation program had to have > minimal changes -- we replaced the Ramtek library with a package that > formatted the Ramtek instructions as text strings, sent them via VAX/VMS > mailboxes to the emulation program... Oh, and the main data generation > program really was a set of some 50 programs that were invoked in > "random" order, each drawing certain data elements onto a single window > -- so there had to be a common graphics application to maintain the > window... > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? HTTP://wlfraed.home.netcom.com/ Hahahaha, I souposse that I must consider myself EXTREMELY lucky... ;-) Anyway, each tool has its time, and we should try to use more-or-less adequate and available tools of our time... From elpostssv at rediffmail.com Tue Nov 3 10:43:20 2009 From: elpostssv at rediffmail.com (Siva Subramanian) Date: 3 Nov 2009 15:43:20 -0000 Subject: =?utf-8?B?cHl0aG9uIGNvbXBhcmUgYW5kIHByb2Nlc3MgYSBjc3YgZmlsZQ==?= Message-ID: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Hello all,   I am new on this list and computer programming   I have two distinct statistical files (both csv) 1.       Report_2_5 ? this is a report dump containing over a 10 million records and is different every day 2.       Customer_id dump ? this is a daily dump of customers who have made payments. This is generally a million record I need to extract past history depending on customers who make regular payments For example, Report_2_5   Customer ID, Plan_NO, stat1, vol2, amount3 2134, Ins1, 10000, 20000, 10 2112, Ins3, 30000, 20000, 10 2121, Ins3, 30000, 20000, 10 2145, Ins2, 15000, 10000, 5 2245, Ins2, 15000, 10000, 5 0987, Ins1, 10000, 20000, 10 4546, Ins1, 10020, 21000, 10 6757, Ins1, 10200, 22000, 10 ? customer_id dump   0987 4546 6757 2134 I need to process the Report_2_5 and extract the following output Stat1: 40220 Vol2 : 83000 Amount3 : 40   I am new to programming and I have been extracting this data using MS ? Access and I badly need a better solution.   Will really appreciate any sample code in python.   Thanks in advance Siva -------------- next part -------------- An HTML attachment was scrubbed... URL: From mario.ruggier at gmail.com Tue Nov 3 10:50:22 2009 From: mario.ruggier at gmail.com (mario ruggier) Date: Tue, 3 Nov 2009 07:50:22 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <880dece00910271211l5e1ecf89i1d2b85c930998689@mail.gmail.com> <7kp7brF3an909U1@mid.uni-berlin.de> <880dece00910280118j14f40763k60cd376425b8d9c@mail.gmail.com> <7kqgg4F3aqqf9U1@mid.uni-berlin.de> <6f7e015d-deba-499b-bc5d-66c0a35610b0@y23g2000yqd.googlegroups.com> Message-ID: With respect to to original question regarding web frameworks + database and Python 3, all the following have been available for Python 3 since the day Python 3.0 was released: QP, a Web Framework http://pypi.python.org/pypi/qp/ Durus, a Python Object Database (the "default" in qp, for user sessions, etc) http://pypi.python.org/pypi/Durus/ Evoque, state-of-the-art templating engine http://pypi.python.org/pypi/evoque/ (this one is available for py3.0 since a little later, 21-jan-2009) All the above also runs on python 2.4 (thru to python 3) For the record, you may see the list of all pypi packages availabe for Python 3 at: http://pypi.python.org/pypi?:action=browse&show=all&c=533 m. From tartley at tartley.com Tue Nov 3 10:58:16 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Tue, 3 Nov 2009 07:58:16 -0800 (PST) Subject: comparing alternatives to py2exe Message-ID: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Hi, Recently I put together this incomplete comparison chart in an attempt to choose between the different alternatives to py2exe: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Columns represent methods of deploying to end-users such that they don't have to worry about installing Python, packages or other dependencies. 'Bundle' represents manually bundling an interpreter with your app. 'Bootstrap' represents a fanciful idea of mine to include an installer that downloads and installs an interpreter if necessary. This sounds fiddly, since it would have to install side-by- side with any existing interpreters of the wrong version, without breaking anything. Has anyone done this? The remaining columns represent the projects out there I could find which would do the bundling for me. Are there major things I'm missing or misunderstanding? Perhaps folks on the list would care to rate (+1/-1) rows that they find important or unimportant, or suggest additional rows that would be important to them. Maybe an updated and complete version of this table would help people agree on what's important, and help the various projects to improve faster. Best regards, Jonathan From fetchinson at googlemail.com Tue Nov 3 10:58:30 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 3 Nov 2009 16:58:30 +0100 Subject: Pyfora, a place for python In-Reply-To: <87my33heq1.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: >> I was referring to this comment by Ben: >> >> "Suggestion: Please don't make efforts to fragment the community." >> >> This IMHO is hostile, because it presupposes that the mere goal of the >> OP is fragmenting the community > > It presupposes nothing of any goal. It describes a predictable result of > the OP's efforts, and requests those efforts to cease. > > So I deny the characterisation of that request as hostile. Probably this thread is going by far too far :) but let's see this again, If A says to B "please don't do X" then A assumes that B does X. Otherwise the request of A doesn't make sense, since it doesn't make sense to ask somebody not to do something that he/she is not doing. Agreed? If no, please explain why you don't agree. If yes, then I guess we will also agree that if A says to B "please don't make efforts to do X" then request of A only makes sense if B makes an effort to do X. Agreed? If no, please explain why. If yes, great, let's continue! If A says to B "please don't make efforts to fragment the community" then this request from A only makes sense if B makes an effort to fragment the community. Agreed? If no, why not? If yes, we are almost there! In our example the request of A only makes sense if B is making an effort to fragment the community, in other words, assuming that A tries to make a meaningful request, A is assuming that B is making an effort to fragment the community. Agreed? If not, why not? If yes, with the substitution A = Ben and B = OP we get "in order for Ben's request to make sense, Ben has to assume that the OP is making an effort to fragment the community". This assumption on the part of Ben, I think, is hostile, since it assumes that the OP is making an effort to do something not nice. Whether the OP is indeed doing something not nice, is irrelevant. If the OP does do something not nice, the hostility is warranted. If the OP is not doing anything not nice, the hostility is unwarranted. But the fact that Ben was hostile is a fact :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From SD_V897 at NoSuchMail.Com Tue Nov 3 11:00:16 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Tue, 03 Nov 2009 16:00:16 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) Message-ID: I have a perplexing issue, I have four users set up on a W7 computer. The program runs fine for all users except the admin user who needs it for school assignments. It's not a firewall issue as I've added localhost for pythomw.exe as allow. I've done some data dumps using sysinternals process monitor and the working users create a 7.8mb dump file and the file for the broken user is only 1.04mb. I can send the zipped data dumps (XML) 384kb if someone could have a look. Python 2.6 Thanks SD From deets at nospam.web.de Tue Nov 3 11:17:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 03 Nov 2009 17:17:55 +0100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> Message-ID: <7lb3dkF3cuvhqU1@mid.uni-berlin.de> >> Since when is the mere suggestion that fragmentation will occur and if >> that's a desirable consequence is hostile? The OP is not bound to it, >> and I also don't see the tone used by the two immediate answerers being >> hostile. Paul might have been terse - but hostility looks different IMHO. > > I was referring to this comment by Ben: > > "Suggestion: Please don't make efforts to fragment the community." > > This IMHO is hostile, because it presupposes that the mere goal of the > OP is fragmenting the community, which is something negative, i.e. it > contains negative prejudice. What I would have written in Ben's place: > > Have you considered the possibility that your website will further > fragment the community? > > This wouldn't have been hostile, IMHO. Well, this is *deep* into the realms of semantics and dialectics. To an extend that personal prejudice would change the perception of the sentence. If everything posted here (and elsewhere) had to be worded so carefully, we'd hardly discussing anything at all. > Competent people will only move away if the website is > great/fun/useful/etc. In which case we should welcome it, since > something great/fun/useful/etc is a good thing. If it's not > great/fun/useful/etc competent people will not move away, in which > case c.l.p. will not be any worse as a result of launching the new > website. There is not only the problem of people moving away - but also of them not even finding *this* place to discuss because they found pyfora first, and thus the "danger" of them getting not the good answers they are looking for. This sometimes already happens, if one of the google ad farms out there that tries to lure people onto their pages simply reproduces c.l.py content - and people believe it's a genuine forum - and wonder why they don't get answers there. > Welcome to open source, the world of infinitely many forks, code > variants, MLs, forums, NGs, websites, in other words, welcome to the > bazaar! Oh please. If every dissent on the direction of an open-source project (or commercial one) would lead to forking, we'd end up with a lot of projects which none of them being competitive and mature. So can we scrap this straw-man of an argument? Diez From mkhitrov at gmail.com Tue Nov 3 12:08:59 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 3 Nov 2009 12:08:59 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <26ddd1750911030908k71684060veded53ee36a2314@mail.gmail.com> On Tue, Nov 3, 2009 at 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > Columns represent methods of deploying to end-users such that they > don't have to worry about installing Python, packages or other > dependencies. 'Bundle' represents manually bundling an interpreter > with your app. 'Bootstrap' represents a fanciful idea of mine to > include an installer that downloads and installs an interpreter if > necessary. This sounds fiddly, since it would have to install side-by- > side with any existing interpreters of the wrong version, without > breaking anything. Has anyone done this? Maybe there is a way to use Portable Python for this, but I have no experience with it. > The remaining columns represent the projects out there I could find > which would do the bundling for me. > > Are there major things I'm missing or misunderstanding? > > Perhaps folks on the list would care to rate (+1/-1) rows that they > find important or unimportant, or suggest additional rows that would > be important to them. Maybe an updated and complete version of this > table would help people agree on what's important, and help the > various projects to improve faster. > > Best regards, > > ?Jonathan Good work. Recently I played with cx_freeze and compared it to py2exe, which I've been using for a while. Here are my findings: 1. I don't think cx_freeze supports single exe. I haven't even been able to get it to append the generated library.zip file to the executable using documented options. Other things like .pyd files always seem to be separate. At the same time, singe executables generated by py2exe do not always work. I have a program that works fine on Windows XP, Vista, and 7 if it is built under XP. However, if I build the exact same program under Windows 7, it no longer works on Vista or XP. I'm sure it has something to do with SxS or other dll issues. 2. For output directory structure, you are able to specify where to put the generated executable and all of its dependencies with both py2exe and cx_freeze. You cannot do things like put python26.dll in a separate directory from the executable. Not sure if that is what you are referring to. 3. py2exe does not support Python 3 (unfortunately). 4. Although cx_freeze does support optimization (-O), it's a bit broken in that the __debug__ variable is always set to True. In other words, the code is optimized and things like assert statements are not executed, but conditional statements that check __debug__ == True are. I know that py2exe does not have this problem, no experience with other tools. 5. py2exe is capable of generating smaller executables than cx_freeze because of the base executable size (18.5 KB vs 1.35 MB). This is offset by the fact that py2exe saves many more standard library components to library.zip by default. In a quick test I just ran, both generated a package of 4.03 MB, but I can remove at least a meg from py2exe's library.zip. Rather than "distribution size", I think it makes more sense to show "overhead" above the required components (exclude minimal library.zip, python dll, and pyd files). 6. cx_freeze is as easy to use as py2exe after looking at the bundled examples. - Max From robert.kern at gmail.com Tue Nov 3 12:35:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 Nov 2009 11:35:51 -0600 Subject: Python-URL! - weekly Python news and links (Nov 3) In-Reply-To: References: Message-ID: On 2009-11-03 07:29 AM, Cameron Laird wrote: > QOTW: "I consider "import *" the first error to be fixed ..." - > Robert > Kern, author of PyFlakes, a potential replacement for Pylint and > Pychecker, > on his personal style > http://groups.google.com/group/comp.lang.python/msg/5bf77b21b3b0caf2 I am not the author of PyFlakes. That distinction belongs to Phil Frost and others at Divmod. -- 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 mccredie at gmail.com Tue Nov 3 12:49:43 2009 From: mccredie at gmail.com (Matt McCredie) Date: Tue, 3 Nov 2009 17:49:43 +0000 (UTC) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: iu2 elbit.co.il> writes: > > Hi, > > Having a file called funcs.py, I would like to read it into a string, > and then import from that string. > That is instead of importing from the fie system, I wonder if it's > possible to eval the text in the string and treat it as a module. > > For example > > with file('funcs.py') as f: txt = r.read() > string_import(txt, 'funcs') # is string_import possible? > > to have now a module called funcs with the functions defined in > funcs.py. You can do something like this: import types import sys mymodule = types.ModuleType("mymodule", "Optional Doc-String") with file('funcs.py') as f: txt = f.read() exec txt in globals(), mymodule.__dict__ sys.modules['mymodule'] = mymodule Note that you shouldn't exec untrusted code. You might also look at the __import__ funciton, which can import by python path. You might also look at the imp module. Matt From ethan at stoneleaf.us Tue Nov 3 12:59:32 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 09:59:32 -0800 Subject: self.__dict__ tricks In-Reply-To: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: <4AF06F84.2030302@stoneleaf.us> Simon Brunning wrote: > 2009/11/1 Steven D'Aprano : > >>The only stupid question is the one you are afraid to ask. > > > I was once asked, and I quote exactly, "are there any fish in the Atlantic sea?" > > That's pretty stupid. ;-) > Are there any fish in the Dead Sea? ~Ethan~ From girishvs at gmail.com Tue Nov 3 14:15:39 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:15:39 -0800 Subject: Freezing python files into executables Message-ID: Hello, I have been using freeze.py on 32 bit linux distributions without a problem. But recently I tried to do the same on RHEL5 x86_64 and ran into some issues. 1) When I ran the script, I got Error: needed directory /usr/lib/python2.4/config not found 2) Then I "yum install python-devel" which installed python-devel.i386 and python-devel.x86_64. Then when I tried freezing, it worked but make barfed up a bunch of errors during ld like /usr/bin/ld: warning: i386 architecture of input file `/usr/lib/python2.4/config/libpython2.4.a(rangeobject.o)' is incompatible with i386:x86-64 output and /usr/lib/python2.4/config/libpython2.4.a(posixmodule.o): In function `posix_getcwd': (.text+0x53a1): undefined reference to `PyEval_RestoreThread' 3) I tried uninstalling python-devel.i386 (retaining only the x86_64) and freeze fails with the same error message as in 1 Any help with this is greatly appreciated. Thanks From rami.chowdhury at gmail.com Tue Nov 3 14:21:19 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 11:21:19 -0800 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian wrote: > Hello, > I have been using freeze.py on 32 bit linux distributions without a > problem. But recently I tried to do the same on RHEL5 x86_64 and ran > into some issues. > > 1) When I ran the script, I got > Error: needed directory /usr/lib/python2.4/config not found > I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From girishvs at gmail.com Tue Nov 3 14:25:17 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:25:17 -0800 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: Hi Rami, Thanks for pointing this out. I did see that point - but apart from installing python-devel (which has created and populated /usr/lib64/python2.4/...) I am not sure what I should do - is there some setting in python where I can ask it to look at lib64 instead of lib? Thanks. On Tue, Nov 3, 2009 at 11:21 AM, Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian > wrote: > >> Hello, >> I have been using freeze.py on 32 bit linux distributions without a >> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >> into some issues. >> >> 1) When I ran the script, I got >> Error: needed directory /usr/lib/python2.4/config not found >> > > I don't know anything about freeze.py but on 64-bit Red Hat distros (RHEL, > Fedora, etc) it should be /usr/lib64/python2.4/config :-) > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > From mal at egenix.com Tue Nov 3 14:32:35 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 20:32:35 +0100 Subject: Freezing python files into executables In-Reply-To: References: Message-ID: <4AF08553.70406@egenix.com> Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian > wrote: > >> Hello, >> I have been using freeze.py on 32 bit linux distributions without a >> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >> into some issues. >> >> 1) When I ran the script, I got >> Error: needed directory /usr/lib/python2.4/config not found >> > > I don't know anything about freeze.py but on 64-bit Red Hat distros > (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) This sounds a lot like a missing Python devel RPM. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 girishvs at gmail.com Tue Nov 3 14:35:11 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:35:11 -0800 Subject: Freezing python files into executables In-Reply-To: <4AF08553.70406@egenix.com> References: <4AF08553.70406@egenix.com> Message-ID: Hey Marc-Andre, Ummm - I have installed python-devel.x86_64 and checked that the /usr/lib64/python2.4/ is populated - anything else I can/shuld do to check/ensure the the devel rpm is installed? Thanks. On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: > Rami Chowdhury wrote: >> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >> wrote: >> >>> Hello, >>> I have been using freeze.py on 32 bit linux distributions without a >>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>> into some issues. >>> >>> 1) When I ran the script, I got >>> Error: needed directory /usr/lib/python2.4/config not found >>> >> >> I don't know anything about freeze.py but on 64-bit Red Hat distros >> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) > > This sounds a lot like a missing Python devel RPM. > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 03 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 sean_mcilroy at yahoo.com Tue Nov 3 14:40:21 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Tue, 3 Nov 2009 11:40:21 -0800 (PST) Subject: chr / ord References: Message-ID: <128a3624-573b-4f7e-83bb-9d41c2c7cb7b@c3g2000yqd.googlegroups.com> thanks. that did the trick. in case anyone else is in the same boat as myself, here are the relevant correspondences: string <-> [int] bytes <-> [int] --------------- -------------- lambda string: [ord(x) for x in string] list lambda ints: ''.join([chr(x) for x in ints]) bytes From mal at egenix.com Tue Nov 3 14:47:01 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Tue, 03 Nov 2009 20:47:01 +0100 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> Message-ID: <4AF088B5.2070805@egenix.com> Girish Venkatasubramanian wrote: > Hey Marc-Andre, > Ummm - I have installed python-devel.x86_64 and checked that the > /usr/lib64/python2.4/ is populated - anything else I can/shuld do to > check/ensure the the devel rpm is installed? If you have the config/ sub-dir in there, things should be fine. However, it's possible that you need to tweek the freeze.py script a little, since RedHat chose to split the Python installation on x64 in two parts and they may have missed patching freeze.py as well: The platform independent parts are in /usr/lib, whereas the platform dependent parts are in /usr/lib64. Python normally doesn't support this. It only has a prefix and an exec_prefix, but those only allow to do things like prefix=/usr and exec_prefix=/usr64, not changing the lib/ part in /usr/lib/. > Thanks. > > On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >> Rami Chowdhury wrote: >>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>> wrote: >>> >>>> Hello, >>>> I have been using freeze.py on 32 bit linux distributions without a >>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>> into some issues. >>>> >>>> 1) When I ran the script, I got >>>> Error: needed directory /usr/lib/python2.4/config not found >>>> >>> >>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >> >> This sounds a lot like a missing Python devel RPM. >> >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source (#1, Nov 03 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/ >> -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 03 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 victorsubervi at gmail.com Tue Nov 3 14:50:10 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 3 Nov 2009 15:50:10 -0400 Subject: Calendar Problem Message-ID: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> Hi; I have the following: import calendar, datetime myCal = calendar.calendar(6) today = datetime.date.today() day = today.day mo = today.month yr = today.year month = myCal.monthdayscalendar(yr, mo) The last line throws errors no matter how I try and tweak it. The current incarnation complains about myCal being a string. What do? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Tue Nov 3 14:54:44 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 11:54:44 -0800 Subject: self.__dict__ tricks In-Reply-To: <4AF06F84.2030302@stoneleaf.us> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> <4AF06F84.2030302@stoneleaf.us> Message-ID: On Tue, 03 Nov 2009 09:59:32 -0800, Ethan Furman wrote: > Simon Brunning wrote: >> 2009/11/1 Steven D'Aprano : >> >>> The only stupid question is the one you are afraid to ask. >> I was once asked, and I quote exactly, "are there any fish in the >> Atlantic sea?" >> That's pretty stupid. ;-) >> > > Are there any fish in the Dead Sea? > Depends on how you define fish, surely ;-)? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From girishvs at gmail.com Tue Nov 3 14:57:17 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 11:57:17 -0800 Subject: Freezing python files into executables In-Reply-To: <4AF088B5.2070805@egenix.com> References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: I checked and ls /usr/lib64/python2.4/config/ returns config.c config.c.in install-sh libpython2.4.a Makefile makesetup python.o Setup Setup.config Setup.local so I am guessing the python-devel installation went off OK, from what you say. I looked at the freeze.py code and I see your point. But for tweaking, I would need to know what modules should get included from lib64 instead of lib and hardcode them .... Maybe tinkering around with the makefile which is produced by freeze is a better way to go? But since I need to freeze this python code by today, can you suggest any other tool to do this? Thanks. On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: > Girish Venkatasubramanian wrote: >> Hey Marc-Andre, >> Ummm - I have installed python-devel.x86_64 and checked that the >> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >> check/ensure the the devel rpm is installed? > > If you have the config/ sub-dir in there, things should be > fine. > > However, it's possible that you need to tweek the freeze.py > script a little, since RedHat chose to split the Python > installation on x64 in two parts and they may have missed > patching freeze.py as well: > > The platform independent parts are in /usr/lib, whereas the > platform dependent parts are in /usr/lib64. > > Python normally doesn't support this. It only has a > prefix and an exec_prefix, but those only allow to do > things like prefix=/usr and exec_prefix=/usr64, not > changing the lib/ part in /usr/lib/. > >> Thanks. >> >> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>> Rami Chowdhury wrote: >>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>> wrote: >>>> >>>>> Hello, >>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>> into some issues. >>>>> >>>>> 1) When I ran the script, I got >>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>> >>>> >>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>> >>> This sounds a lot like a missing Python devel RPM. >>> >>> -- >>> Marc-Andre Lemburg >>> eGenix.com >>> >>> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >>> > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 03 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 klich.michal at gmail.com Tue Nov 3 15:12:15 2009 From: klich.michal at gmail.com (=?utf-8?q?Micha=C5=82_Klich?=) Date: Tue, 3 Nov 2009 21:12:15 +0100 Subject: Calendar Problem In-Reply-To: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> Message-ID: <200911032112.15288.klich.michal@gmail.com> Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): > Hi; > I have the following: > > import calendar, datetime > > myCal = calendar.calendar(6) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > month = myCal.monthdayscalendar(yr, mo) > > The last line throws errors no matter how I try and tweak it. The current > incarnation complains about myCal being a string. What do? > TIA, > Victor > You should use myCal = calendar.Calendar(6) This creates calendar.Calendar object. -- Micha? Klich klich.michal at gmail.com michal at michalklich.com http://www.michalklich.com From rami.chowdhury at gmail.com Tue Nov 3 15:31:07 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 03 Nov 2009 12:31:07 -0800 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian wrote: > I checked and ls /usr/lib64/python2.4/config/ returns > config.c config.c.in install-sh libpython2.4.a Makefile makesetup > python.o Setup Setup.config Setup.local > > so I am guessing the python-devel installation went off OK, from what > you say. > > I looked at the freeze.py code and I see your point. But for tweaking, > I would need to know what modules should get included from lib64 > instead of lib and hardcode them .... > Maybe tinkering around with the makefile which is produced by freeze > is a better way to go? > > But since I need to freeze this python code by today, can you suggest > any other tool to do this? > I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ; can you try just changing the directory freeze.py looks at to 'lib64', and see if the freeze works? > > On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: >> Girish Venkatasubramanian wrote: >>> Hey Marc-Andre, >>> Ummm - I have installed python-devel.x86_64 and checked that the >>> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >>> check/ensure the the devel rpm is installed? >> >> If you have the config/ sub-dir in there, things should be >> fine. >> >> However, it's possible that you need to tweek the freeze.py >> script a little, since RedHat chose to split the Python >> installation on x64 in two parts and they may have missed >> patching freeze.py as well: >> >> The platform independent parts are in /usr/lib, whereas the >> platform dependent parts are in /usr/lib64. >> >> Python normally doesn't support this. It only has a >> prefix and an exec_prefix, but those only allow to do >> things like prefix=/usr and exec_prefix=/usr64, not >> changing the lib/ part in /usr/lib/. >> >>> Thanks. >>> >>> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>>> Rami Chowdhury wrote: >>>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>>> wrote: >>>>> >>>>>> Hello, >>>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>>> into some issues. >>>>>> >>>>>> 1) When I ran the script, I got >>>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>>> >>>>> >>>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>>> >>>> This sounds a lot like a missing Python devel RPM. >>>> >>>> -- >>>> Marc-Andre Lemburg >>>> eGenix.com >>>> >>>> Professional Python Services directly from the Source ?(#1, Nov 03 >>>> 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/ >>>> >> >> -- >> Marc-Andre Lemburg >> eGenix.com >> >> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >> -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From israelu at elbit.co.il Tue Nov 3 15:36:08 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 12:36:08 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: On Nov 3, 7:49?pm, Matt McCredie wrote: > iu2 elbit.co.il> writes: > > > > > Hi, > > > Having a file called funcs.py, I would like to read it into a string, > > and then import from that string. > > That is instead of importing from the fie system, I wonder if it's > > possible to eval the text in the string and treat it as a module. > > > For example > > > with file('funcs.py') as f: txt = r.read() > > string_import(txt, 'funcs') ?# is string_import possible? > > > to have now a module called funcs with the functions defined in > > funcs.py. > > You can do something like this: > > import types > import sys > > mymodule = types.ModuleType("mymodule", "Optional Doc-String") > > with file('funcs.py') as f: > ? ? txt = f.read() > exec txt in globals(), mymodule.__dict__ > sys.modules['mymodule'] = mymodule > > Note that you shouldn't exec untrusted code. > You might also look at the __import__ funciton, which can import by python path. > You might also look at the imp module. > > Matt Thanks, it seems simpler than I thought. I don't fully understand , though, the exec statement, how it causes the string execute in the context of mymodule. From ethan at stoneleaf.us Tue Nov 3 15:42:05 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 12:42:05 -0800 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: <4AF0959D.2020307@stoneleaf.us> Daniel Fetchinson wrote: >>>I was referring to this comment by Ben: >>> >>>"Suggestion: Please don't make efforts to fragment the community." >>> >>>This IMHO is hostile, because it presupposes that the mere goal of the >>>OP is fragmenting the community >> >>It presupposes nothing of any goal. It describes a predictable result of >>the OP's efforts, and requests those efforts to cease. >> >>So I deny the characterisation of that request as hostile. > [mass snippitude] > If yes, with the substitution A = Ben and B = OP we get "in order for > Ben's request to make sense, Ben has to assume that the OP is making > an effort to fragment the community". This assumption on the part of > Ben, I think, is hostile, since it assumes that the OP is making an > effort to do something not nice. Whether the OP is indeed doing > something not nice, is irrelevant. If the OP does do something not > nice, the hostility is warranted. If the OP is not doing anything not > nice, the hostility is unwarranted. But the fact that Ben was hostile > is a fact :) You were doing fine until you brought in the hostility. I must agree with Ben that his comment was not hostile. It was merely a statement. Not an exclamation, no name calling, just a plain request rooted in reality. And that's a fact. ;-) Shall we now discuss the nature of the space/time continuum and the exact reality of quarks? ~Ethan~ From israelu at elbit.co.il Tue Nov 3 15:50:42 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 12:50:42 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> On Nov 3, 5:58?pm, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > Columns represent methods of deploying to end-users such that they > don't have to worry about installing Python, packages or other > dependencies. 'Bundle' represents manually bundling an interpreter > with your app. 'Bootstrap' represents a fanciful idea of mine to > include an installer that downloads and installs an interpreter if > necessary. This sounds fiddly, since it would have to install side-by- > side with any existing interpreters of the wrong version, without > breaking anything. Has anyone done this? > > The remaining columns represent the projects out there I could find > which would do the bundling for me. > > Are there major things I'm missing or misunderstanding? > > Perhaps folks on the list would care to rate (+1/-1) rows that they > find important or unimportant, or suggest additional rows that would > be important to them. Maybe an updated and complete version of this > table would help people agree on what's important, and help the > various projects to improve faster. > > Best regards, > > ? Jonathan Another thing that I think is of interest is whether the application support modifying the version and description of the exe (that is, on Windows, when you right-click on an application and choose 'properties' you view the version number and description of the application, it is a resource inside the exe). I think py2exe supports it. From mkhitrov at gmail.com Tue Nov 3 16:06:34 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 3 Nov 2009 16:06:34 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> Message-ID: <26ddd1750911031306o41b089bcl38afeea03ff18c5d@mail.gmail.com> On Tue, Nov 3, 2009 at 3:50 PM, iu2 wrote: > On Nov 3, 5:58?pm, Jonathan Hartley wrote: >> Hi, >> >> Recently I put together this incomplete comparison chart in an attempt >> to choose between the different alternatives to py2exe: >> >> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... >> >> Columns represent methods of deploying to end-users such that they >> don't have to worry about installing Python, packages or other >> dependencies. 'Bundle' represents manually bundling an interpreter >> with your app. 'Bootstrap' represents a fanciful idea of mine to >> include an installer that downloads and installs an interpreter if >> necessary. This sounds fiddly, since it would have to install side-by- >> side with any existing interpreters of the wrong version, without >> breaking anything. Has anyone done this? >> >> The remaining columns represent the projects out there I could find >> which would do the bundling for me. >> >> Are there major things I'm missing or misunderstanding? >> >> Perhaps folks on the list would care to rate (+1/-1) rows that they >> find important or unimportant, or suggest additional rows that would >> be important to them. Maybe an updated and complete version of this >> table would help people agree on what's important, and help the >> various projects to improve faster. >> >> Best regards, >> >> ? Jonathan > > Another thing that I think is of interest is whether the application > support modifying the version and description of the exe (that is, on > Windows, when you right-click on an application and choose > 'properties' you view the version number and description of the > application, it is a resource inside the exe). I think py2exe supports > it. py2exe supports this, cx_freeze doesn't. - Max From ben+python at benfinney.id.au Tue Nov 3 16:13:24 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 08:13:24 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: <87iqdrgvm3.fsf@benfinney.id.au> Daniel Fetchinson writes: > Probably this thread is going by far too far :) Agreed. -- \ ???????? (The virtuous are not abandoned, they shall | `\ surely have neighbours.) ???? Confucius, 551 BCE ? 479 BCE | _o__) | Ben Finney From girishvs at gmail.com Tue Nov 3 16:23:04 2009 From: girishvs at gmail.com (Girish Venkatasubramanian) Date: Tue, 3 Nov 2009 13:23:04 -0800 Subject: Freezing python files into executables In-Reply-To: References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: Will try that. Meanwhile I went ahead and used cx_freeze and that seems to work OK. Thanks for your help Rami and Marc-Andre. On Tue, Nov 3, 2009 at 12:31 PM, Rami Chowdhury wrote: > On Tue, 03 Nov 2009 11:57:17 -0800, Girish Venkatasubramanian > wrote: > >> I checked and ls /usr/lib64/python2.4/config/ returns >> config.c config.c.in install-sh libpython2.4.a Makefile makesetup >> python.o Setup Setup.config Setup.local >> >> so I am guessing the python-devel installation went off OK, from what you >> say. >> >> I looked at the freeze.py code and I see your point. But for tweaking, >> I would need to know what modules should get included from lib64 >> instead of lib and hardcode them .... >> Maybe tinkering around with the makefile which is produced by freeze >> is a better way to go? >> >> But since I need to freeze this python code by today, can you suggest >> any other tool to do this? >> > > I believe /usr/lib64 on a 64-bit RHEL will contain everything you need ; can > you try just changing the directory freeze.py looks at to 'lib64', and see > if the freeze works? > >> >> On Tue, Nov 3, 2009 at 11:47 AM, M.-A. Lemburg wrote: >>> >>> Girish Venkatasubramanian wrote: >>>> >>>> Hey Marc-Andre, >>>> Ummm - I have installed python-devel.x86_64 and checked that the >>>> /usr/lib64/python2.4/ is populated - anything else I can/shuld do to >>>> check/ensure the the devel rpm is installed? >>> >>> If you have the config/ sub-dir in there, things should be >>> fine. >>> >>> However, it's possible that you need to tweek the freeze.py >>> script a little, since RedHat chose to split the Python >>> installation on x64 in two parts and they may have missed >>> patching freeze.py as well: >>> >>> The platform independent parts are in /usr/lib, whereas the >>> platform dependent parts are in /usr/lib64. >>> >>> Python normally doesn't support this. It only has a >>> prefix and an exec_prefix, but those only allow to do >>> things like prefix=/usr and exec_prefix=/usr64, not >>> changing the lib/ part in /usr/lib/. >>> >>>> Thanks. >>>> >>>> On Tue, Nov 3, 2009 at 11:32 AM, M.-A. Lemburg wrote: >>>>> >>>>> Rami Chowdhury wrote: >>>>>> >>>>>> On Tue, 03 Nov 2009 11:15:39 -0800, Girish Venkatasubramanian >>>>>> wrote: >>>>>> >>>>>>> Hello, >>>>>>> I have been using freeze.py on 32 bit linux distributions without a >>>>>>> problem. But recently I tried to do the same on RHEL5 x86_64 and ran >>>>>>> into some issues. >>>>>>> >>>>>>> 1) When I ran the script, I got >>>>>>> Error: needed directory /usr/lib/python2.4/config not found >>>>>>> >>>>>> >>>>>> I don't know anything about freeze.py but on 64-bit Red Hat distros >>>>>> (RHEL, Fedora, etc) it should be /usr/lib64/python2.4/config :-) >>>>> >>>>> This sounds a lot like a missing Python devel RPM. >>>>> >>>>> -- >>>>> Marc-Andre Lemburg >>>>> eGenix.com >>>>> >>>>> Professional Python Services directly from the Source ?(#1, Nov 03 >>>>> 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/ >>>>> >>> >>> -- >>> Marc-Andre Lemburg >>> eGenix.com >>> >>> Professional Python Services directly from the Source ?(#1, Nov 03 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/ >>> > > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > From huili.song at gmail.com Tue Nov 3 16:44:20 2009 From: huili.song at gmail.com (kylin) Date: Tue, 3 Nov 2009 13:44:20 -0800 (PST) Subject: how to remove the punctuation and no need words from paragraphs Message-ID: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> I want to remove all the punctuation and no need words form a string datasets for experiment. I am new to python, please give me some clue and direction to write this code. From patx at patx.me Tue Nov 3 16:52:25 2009 From: patx at patx.me (patx at patx.me) Date: Tue, 3 Nov 2009 16:52:25 -0500 Subject: fastPATX Panther for your speedy web browsing needs! Message-ID: <699f51260911031352s46ec54amcfd71cc10543d8c5@mail.gmail.com> fastPATX Panther is now out! It beats Firefox on startup and is very lightweight you have to try it! Download here: http://bitbucket.org/patx/fastpatx/fastpatx-panther.py -- patx, python gui and web, http://patx.me -------------- next part -------------- An HTML attachment was scrubbed... URL: From WanderingAengus at comcast.net Tue Nov 3 16:58:37 2009 From: WanderingAengus at comcast.net (Jean) Date: Tue, 3 Nov 2009 13:58:37 -0800 (PST) Subject: Can I run a python program from within emacs? References: <892a4877-0391-4386-a14f-b66e1b216d49@m3g2000pri.googlegroups.com> Message-ID: On Nov 1, 10:15?am, rustom wrote: > On Nov 1, 7:20?pm, Robinson wrote: > > > I have also just started with both Aquamacs and Python so I ask for ? > > your patience as well. > > When I evaluate the buffer (C-c C-C) I don't see any response or ? > > output from my python program. Should another buffer open ? > > automatically? Should a terminal window open? > > thanks for your patience. > > Rugbeia Floreat Ubique > > > > On Mar 20, 3:09 pm, jmDesktop wrote: > > > > Hi, I'm trying to learn Python. ?I usingAquamacan emac > > > > implementation with mac os x. ?I have a program. ?If I go to the > > > > command prompt and type pythong myprog.py, it works. ?Can the ? > > > program > > > > be run from within the editor or is that not how development is ? > > > done? > > There are two python modes -- python.el and python-mode.el > Default with emacs is python.el, what comes from/with python is python- > mode.el (needs a download and a couple of lines of setup seehttp://www.emacswiki.org/emacs/PythonMode). I recommend python-mode. > > The key-bindings are different --C-c ! to start interpreter followed > by C-c C-c to exec a file. Perfect! Many thanks... From huili.song at gmail.com Tue Nov 3 17:13:45 2009 From: huili.song at gmail.com (kylin) Date: Tue, 3 Nov 2009 14:13:45 -0800 (PST) Subject: how to remove the same words in the paragraph Message-ID: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> I need to remove the word if it appears in the paragraph twice. could some give me some clue or some useful function in the python. From kyosohma at gmail.com Tue Nov 3 17:28:29 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 3 Nov 2009 14:28:29 -0800 (PST) Subject: Freezing python files into executables References: <4AF08553.70406@egenix.com> <4AF088B5.2070805@egenix.com> Message-ID: On Nov 3, 3:23?pm, Girish Venkatasubramanian wrote: > Will try that. > > Meanwhile I went ahead and used cx_freeze and that seems to work OK. > > Thanks for your help Rami and Marc-Andre. Something that you might want to try in the future is GUI2Exe, which allows you to play with a whole slew of freezing modules: http://code.google.com/p/gui2exe/ I've been using it to make executables on Windows through it's py2exe implementation. ------------------- Mike Driscoll Blog: http://blog.pythonlibrary.org From andreengels at gmail.com Tue Nov 3 17:33:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Tue, 3 Nov 2009 23:33:59 +0100 Subject: how to remove the same words in the paragraph In-Reply-To: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: <6faf39c90911031433g288501efq825d798cd19cd3f7@mail.gmail.com> On Tue, Nov 3, 2009 at 11:13 PM, kylin wrote: > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. Well, it depends a bit on what you call 'the same word' (In the paragraph "Fly fly, fly!" does the word fly occur 0, 1, 2 or 3 times?), but the split() function seems a logical choice to use whatever the answer to that question. -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Tue Nov 3 17:40:26 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Nov 2009 23:40:26 +0100 Subject: how to remove the same words in the paragraph References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: kylin wrote: > I want to remove all the punctuation and no need words form a string > datasets for experiment. > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. >>> para = u"""I need to remove the word if it appears in the paragraph twice. could ... some give me some clue or some useful function in the python. ... """ >>> print "\n".join(sorted(set(para.translate(dict.fromkeys(map(ord, ".:,-"))).split()))) I appears clue could function give if in it me need or paragraph python remove some the to twice useful word From NOSPAM_chuckwhite8 at charter.net Tue Nov 3 17:40:30 2009 From: NOSPAM_chuckwhite8 at charter.net (chuck) Date: Tue, 03 Nov 2009 17:40:30 -0500 Subject: unable to compile Python 2.6.4 on AIX using gcc Message-ID: Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX 5.3. Here are the settings: export OBJECT_MODE=64 export AR="ar -X64" export MAKE=/usr/bin/gmake export CC="gcc" export CFLAGS="-maix64 -O2 -g -mcpu=power5" export LDFLAGS="-L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" ../Python-2.6.4/configure --with-gcc --disable-ipv6 --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 make > make_264.log 2>&1 make fails very early with the following error =========== gcc -pthread -c -fno-strict-aliasing -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -IInclude -I../Python-2.6.4/Includ e -I/opt/freeware/include -I/usr/lpp/X11/include/X11 -DPy_BUILD_CORE -o Modules/python.o ../Python-2.6.4/Modules/python.c In file included from ../Python-2.6.4/Include/Python.h:58, from ../Python-2.6.4/Modules/python.c:3: ../Python-2.6.4/Include/pyport.h:685:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config ?)." make: The error code from the last command is 1. =========== I would appreciate any help. Thanks. From python.list at tim.thechases.com Tue Nov 3 17:57:14 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 03 Nov 2009 16:57:14 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> Message-ID: <4AF0B54A.7090602@tim.thechases.com> kylin wrote: > I need to remove the word if it appears in the paragraph twice. could > some give me some clue or some useful function in the python. Sounds like homework. To fail your class, use this one: >>> p = "one two three four five six seven three four eight" >>> s = set() >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) one two three four five six seven eight which is absolutely horrible because it mutates the set within the list comprehension. The passable solution would use a for-loop to iterate over each word in the paragraph, emitting it if it hadn't already been seen. Maintain those words in set, so your words know how not to be seen. ("Mr. Nesbitt, would you please stand up?") This also assumes your paragraph consists only of words and whitespace. But since you posted your previous homework-sounding question on stripping out non-word/whitespace characters, you'll want to look into using a regexp like "[\w\s]" to clean up the cruft in the paragraph. Neither solution above preserves non white-space/word characters, for which I'd recommend using a re.sub() with a callback. Such a callback class might look something like >>> class Dedupe: ... def __init__(self): ... self.s = set() ... def __call__(self, m): ... w = m.group(0) ... if w in self.s: return '' ... self.s.add(w) ... return w ... >>> r.sub(Dedupe(), p) where I leave the definition of "r" to the student. Also beware of case-differences for which you might have to normalize. You'll also want to use more descriptive variable names than my one-letter tokens. -tkc From gagsl-py2 at yahoo.com.ar Tue Nov 3 18:26:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 20:26:18 -0300 Subject: import bug References: <7dfff81a-b594-4065-8d4f-44c5009fe23b@k4g2000yqb.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 12:29:10 -0300, Ask Solem escribi?: > If you have a module named myapp.django, and someone writes a cool > library called > django that you want to use, you can't use it unless you rename your > local django module. > > > file myapp/django.py: > > from django.utils.functional import curry > > ImportError: No module named utils.functional > > At least that's what I get, maybe there is some workaround, some way > to say this is an absolute path? Yes, that's exactly the way to solve it. Either move on to Python 3, or use: from __future__ import absolute_import When absolute imports are in effect, and assuming your code is inside a package, then neither "import re" nor "from django.utils.functional import curry" are affected by your own module names, because those statements imply an absolute import ("absolute" means that the module is searched along sys.path). The only way to import a local file "re.py" is using "from .re import something"; the leading dot means it's a relative import ("relative" means that the module is searched in a single directory: the current package directory and its parents, depending on how many dots are specified) -- Gabriel Genellina From davea at ieee.org Tue Nov 3 18:27:50 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 03 Nov 2009 18:27:50 -0500 Subject: Handling large datastore search In-Reply-To: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> Message-ID: <4AF0BC76.4090908@ieee.org> Ahmed Barakat wrote: > In case I have a huge datastore (10000 entries, each entry has like 6 > properties), what is the best way > to handle the search within such a huge datastore, and what if I want to > make a generic search, for example > you write a word and i use it to search within all properties I have for all > entries? > > Is the conversion to XML a good solution, or it is not? > > sorry for being new to web development, and python. > > Thanks in advance. > > I don't see anything about your query which is specific to web development, and there's no need to be apologetic for being new anyway. One person's "huge" is another person's "pretty large." I'd say 10000 items is pretty small if you're working on the desktop, as you can readily hold all the data in "memory." I edit text files bigger than that. But I'll assume your data really is huge, or will grow to be huge, or is an environment which treats it as huge. When you're parsing large amounts of data, there are always tradeoffs between performance and other characteristics, usually size and complexity. If you have lots of data, you're probably best off by using a standard code system -- a real database. The developers of such things have decades of experience in making certain things fast, reliable, and self-consistent. But considering only speed here, I have to point out that you have to understand databases, and your particular model of database, pretty well to really benefit from all the performance tricks in there. Keeping it abstract, you specify what parts of the data you care about fast random access to. If you want fast search access to "all" of it, your database will generally be huge, and very slow to updates. And the best way to avoid that is to pick a database mechanism that best fits your search mechanism. I hate to think how many man-centuries Google has dedicated to getting fast random word access to its *enormous* database. I'm sure they did not build on a standard relational model. If you plan to do it yourself, I'd say the last thing you want to do is use XML. XML may be convenient way to store self-describing data, but it's not quick to parse large amounts of it. Instead, store the raw data in text form, with separate index files describing what is where. Anything that's indexed will be found rapidly, while anything that isn't will require search of the raw data. There are algorithms for searching raw data that are faster than scanning every byte, but a relevant index will almost always be faster. DaveA From davea at ieee.org Tue Nov 3 18:56:07 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 03 Nov 2009 18:56:07 -0500 Subject: Calendar Problem In-Reply-To: <200911032112.15288.klich.michal@gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> Message-ID: <4AF0C317.3010109@ieee.org> MichaB Klich wrote: > Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): > >> Hi; >> I have the following: >> >> import calendar, datetime >> >> myCal =alendar.calendar(6) >> today =atetime.date.today() >> day =oday.day >> mo =oday.month >> yr =oday.year >> month =yCal.monthdayscalendar(yr, mo) >> >> The last line throws errors no matter how I try and tweak it. The current >> incarnation complains about myCal being a string. What do? >> TIA, >> Victor >> >> > > You should use > > myCal =calendar.Calendar(6) > > This creates calendar.Calendar object. > > Right. But I wanted to tell the OP what to do with an error like this. You should post the actual error traceback, and tell us what version of Python you're using: Traceback (most recent call last): File "M:\Programming\Python\sources\dummy\stuff2.py", line 15, in month = myCal.monthdayscalendar(yr, mo) AttributeError: 'str' object has no attribute 'monthdayscalendar' Now, since it says that myCal is a 'str' object, the next thing you should do is look at the value. I get an actual printable calendar for a year. So clearly, it's not the Calendar object you were looking for. So you need to change from the calendar() function to the Calendar() constructor. DaveA From kee at kagi.com Tue Nov 3 19:01:46 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 16:01:46 -0800 Subject: elementtree XML() unicode In-Reply-To: References: Message-ID: Having an issue with elementtree XML() in python 2.6.4. This code works fine: from xml.etree import ElementTree as et getResponse = u''' bobbleheadcity''' theResponseXml = et.XML(getResponse) This code errors out when it tries to do the et.XML() from xml.etree import ElementTree as et getResponse = u''' \ue58d83\ue89189\ue79c8C \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03''' theResponseXml = et.XML(getResponse) In my real code, I'm pulling the getResponse data from a web page that returns as XML and when I display it in the browser you can see the Japanese characters in the data. I've removed all the stuff in my code and tried to distill it down to just what is failing. Hopefully I have not removed something essential. Why is this not working and what do I need to do to use Elementtree with unicode? Thanks, Kee Nethery From rhodri at wildebst.demon.co.uk Tue Nov 3 19:17:36 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Nov 2009 00:17:36 -0000 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> Message-ID: On Tue, 03 Nov 2009 15:58:30 -0000, Daniel Fetchinson wrote: > If yes, we are almost there! In our example the request of A only > makes sense if B is making an effort to fragment the community, in > other words, assuming that A tries to make a meaningful request, A is > assuming that B is making an effort to fragment the community. You are assuming here that B is intending his efforts to do X, and that A believes this to be the case. That's the assumption where your chain of logic fails; it is entirely possible that A's statement is abridging a chain of logic that B hasn't considered, and that A is making no assumption of any kind concerning B's intent. Say hello to the Law of Unintended Consequences. -- Rhodri James *-* Wildebeest Herder to the Masses From ryan at rfk.id.au Tue Nov 3 19:21:27 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Wed, 04 Nov 2009 11:21:27 +1100 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <1257294087.2819.1.camel@durian> > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > ...snip... > > Are there major things I'm missing or misunderstanding? A quick note - although I haven't tried it out, the latest version of bbfreeze claims to support OSX. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From rhodri at wildebst.demon.co.uk Tue Nov 3 19:29:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 04 Nov 2009 00:29:18 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 wrote: > I have a perplexing issue, I have four users set up on a W7 computer. > The program runs fine for all users except the admin user who needs it > for school assignments. A little more information, please. How does it not work for the admin user? Is there a traceback? What do you get if you try to invoke it from a command line? -- Rhodri James *-* Wildebeest Herder to the Masses From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:31:27 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:31:27 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel escribi?: > On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: >> You need to give some actual examples of what you are trying to do, and >> what you are expecting to happen. How is initialized() being called? > > Example: Assume a framework which offers common functionality for a > plugin > or a module a user can choose at the beginning. The framework does not > know the concrete type of the plugin so it is possible to extend it by > implementing a well known interface or abstract class. > > The framework reads the plugin directory, loads each module and creates > buttons for each plugin with a callback method for initializing. To use > common functionality of the framework, initialization method takes it as > the parent parameter. Then forget about the code you read in that blog post, doesn't apply to your use case. > I think this listing makes the most sense to you: > > # initialize all plugins > self._plugin_modules = _load_plugins() # imp loading here > LOGGER.debug(ActionProvider.plugins) # print what was loaded > for plugin in ActionProvider.plugins: # create button for each > app_button = gtk.Button(plugin.title) > LOGGER.debug('Title of plugin: %s' % plugin.title) > app_button.connect("clicked", > plugin.initialize(plugin, self), > None) > self.set_canvas(app_button) > app_button.show() Try something like this: --- begin plugin.py --- class Plugin(object): "Every plugin class should have a docstring" def __init__(self, manager): pass --- end plugin.py --- --- begin pluginmgr.py -- import os.path from glob import glob from plugin import Plugin class PluginManager: def __init__(self, plugin_directory): self.plugin_directory = plugin_directory self.plugins = [] def load_all(self): for fn in glob(os.path.join(self.plugin_directory, '*.py')): namespace = {} execfile(fn, namespace) for name, obj in namespace.items(): if (isinstance(obj, type) and issubclass(obj, Plugin) and obj is not Plugin): # obj is a Plugin subclass cls = obj print cls.__name__, fn print cls.__doc__ print plugin = cls(self) # call the constructor self.plugins.append(plugin) if __name__ == '__main__': mgr = PluginManager(r'd:\\temp\\plugins') mgr.load_all() print mgr.plugins --- end pluginmgr.py --- --- begin one.py in the plugins directory --- from plugin import Plugin class MyPlugin(Plugin): """The most wonderful plugin in the world. This plugin does this, and that, and also that, too. It's very nice, I assure you.""" class Second(Plugin): """My second plugin. I don't know what is this for, but it works.""" --- end one.py --- Plugin is the base class; all plugins must inherit from it. PluginMgr scans the plugin directory, executes all modules it finds there (be careful...), and looks for Plugin subclasses. Then creates an instance of each Plugin subclass. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:44:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:44:54 -0300 Subject: elementtree XML() unicode References: Message-ID: En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery escribi?: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > from xml.etree import ElementTree as et > getResponse = u''' > bobblehead city>city''' > theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > from xml.etree import ElementTree as et > getResponse = u''' > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that > returns as XML and when I display it in the browser you can see the > Japanese characters in the data. I've removed all the stuff in my code > and tried to distill it down to just what is failing. Hopefully I have > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree with > unicode? et expects bytes as input, not unicode. You're decoding too early (decoding early is good, but not in this case, because et does the work for you). Either feed et.XML with the bytes before decoding, or reencode the received xml text in UTF-8 (since this is the declared encoding). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 19:57:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 21:57:00 -0300 Subject: Help resolve a syntax error on 'as' keyword (python 2.5) References: Message-ID: En Tue, 03 Nov 2009 10:06:24 -0300, Oltmans escribi?: > Hi, all. All I'm trying to do is to print the error message using the > following code (copying/pasting from IDLE). > > try: > div(5,0) > except Exception as msg: > print msg > > SyntaxError: invalid syntax > > I'm using Python 2.5 on Windows XP. Other people already told you what the problem is. I suggest reading a book/tutorial written for the *same* Python version you're using (2.x; it doesn't matter 2.6, 2.5, 2.4...). Once you know the basics of the language, you may look at the differences in the "What's new?" document for Python 3.0 - but right now, they will just confuse you. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 3 20:10:51 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Nov 2009 22:10:51 -0300 Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribi?: > On Nov 3, 7:49 pm, Matt McCredie wrote: >> iu2 elbit.co.il> writes: >> >> > Having a file called funcs.py, I would like to read it into a string, >> > and then import from that string. >> > That is instead of importing from the fie system, I wonder if it's >> > possible to eval the text in the string and treat it as a module. >> mymodule = types.ModuleType("mymodule", "Optional Doc-String") >> with file('funcs.py') as f: >> txt = f.read() >> exec txt in globals(), mymodule.__dict__ >> sys.modules['mymodule'] = mymodule > > Thanks, it seems simpler than I thought. > I don't fully understand , though, the exec statement, how it causes > the string execute in the context of mymodule. Sometimes you don't even require a module, and this is simpler to understand. Suppose you have a string like this: txt = """ def foo(x): print 'x=', x def bar(x): return x + x """ you may execute it: py> namespace = {} py> exec txt in namespace The resulting namespace contains the foo and bar functions, and you may call them: py> namespace.keys() ['__builtins__', 'foo', 'bar'] py> namespace['foo']('hello') x= hello exec just executes the string using the given globals dictionary as its global namespace. Whatever is present in the dictionary is visible in the executed code as global variables (none in this example). The global names that the code creates become entries in the dictionary. (foo and bar; __builtins__ is an implementation detail of CPython). You may supply separate globals and locals dictionaries. -- Gabriel Genellina From kee at kagi.com Tue Nov 3 20:14:28 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 17:14:28 -0800 Subject: elementtree XML() unicode In-Reply-To: References: Message-ID: On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery > escribi?: > >> I've removed all the stuff in my code and tried to distill it down >> to just what is failing. Hopefully I have not removed something >> essential. Sounds like I did remove something essential. > > et expects bytes as input, not unicode. You're decoding too early > (decoding early is good, but not in this case, because et does the > work for you). Either feed et.XML with the bytes before decoding, or > reencode the received xml text in UTF-8 (since this is the declared > encoding). Here is the code that hits the URL: getResponse1 = urllib2.urlopen(theUrl) getResponse2 = getResponse1.read() getResponse3 = unicode(getResponse2,'UTF-8') theResponseXml = et.XML(getResponse3) So are you saying I want to do: getResponse1 = urllib2.urlopen(theUrl) getResponse4 = getResponse1.read() theResponseXml = et.XML(getResponse4) The reason I am confused is that getResponse2 is classified as an "str" in the Komodo IDE. I want to make sure I don't lose the non- ASCII characters coming from the URL. If I do the second set of code, does elementtree auto convert the str into unicode? How do I deal with the XML as unicode when I put it into elementtree as a string? Very confusing. Thanks for the help. Kee From sjmachin at lexicon.net Tue Nov 3 20:27:12 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 17:27:12 -0800 (PST) Subject: elementtree XML() unicode References: Message-ID: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> On Nov 4, 11:01?am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > ? ? ? from xml.etree import ElementTree as et > ? ? ? getResponse = u''' ? > bobblehead city>city''' > ? ? ? theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > ? ? ? from xml.etree import ElementTree as et > ? ? ? getResponse = u''' ? > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > ? ? ? theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that ? > returns as XML and when I display it in the browser you can see the ? > Japanese characters in the data. I've removed all the stuff in my code ? > and tried to distill it down to just what is failing. Hopefully I have ? > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree ? > with unicode? On Nov 4, 11:01 am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > > from xml.etree import ElementTree as et > getResponse = u''' > bobblehead city>city''' > theResponseXml = et.XML(getResponse) > > This code errors out when it tries to do the et.XML() > > from xml.etree import ElementTree as et > getResponse = u''' > \ue58d83\ue89189\ue79c8C > \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03 shipping>''' > theResponseXml = et.XML(getResponse) > > In my real code, I'm pulling the getResponse data from a web page that > returns as XML and when I display it in the browser you can see the > Japanese characters in the data. I've removed all the stuff in my code > and tried to distill it down to just what is failing. Hopefully I have > not removed something essential. > > Why is this not working and what do I need to do to use Elementtree > with unicode? What you need to do is NOT feed it unicode. You feed it a str object and it gets decoded according to the encoding declaration found in the first line. So take the str object that you get from the web (should be UTF8-encoded already unless the header is lying), and throw that at ET ... like this: | Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. | >>> from xml.etree import ElementTree as et | >>> ucode = u''' | ... | ... \ue58d83\ue89189\ue79c8C | ... \ue69f8f\ue5b882 | ... \ue9ab98\ue58d97\ue58fb03 | ... ''' | >>> xml= et.XML(ucode) | Traceback (most recent call last): | File "", line 1, in | File "C:\python26\lib\xml\etree\ElementTree.py", line 963, in XML | parser.feed(text) | File "C:\python26\lib\xml\etree\ElementTree.py", line 1245, in feed | self._parser.Parse(data, 0) | UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d' in position 69: ordinal not in range(128) | # as expected | >>> strg = ucode.encode('utf8') | # encoding as utf8 is for DEMO purposes. | # i.e. use the original web str object, don't convert it to unicode | # and back to utf8. | >>> xml2 = et.XML(strg) | >>> xml2.tag | 'customer' | >>> for c in xml2.getchildren(): | ... print c.tag, repr(c.text) | ... | shipping '\n' | >>> for c in xml2[0].getchildren(): | ... print c.tag, repr(c.text) | ... | state u'\ue58d83\ue89189\ue79c8C' | city u'\ue69f8f\ue5b882' | street u'\ue9ab98\ue58d97\ue58fb03' | >>> By the way: (1) it usually helps to be more explicit than "errors out", preferably the exact copied/pasted output as shown above; this is one of the rare cases where the error message is predictable (2) PLEASE don't start a new topic in a reply in somebody else's thread. From alfps at start.no Tue Nov 3 20:29:21 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 02:29:21 +0100 Subject: Tkinter callback arguments In-Reply-To: <7l942mF3c94mlU1@mid.uni-berlin.de> References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Alf P. Steinbach schrieb: >> * Diez B. Roggisch: >>>> Your comment about "computed" makes it more clear what that's all >>>> about. >>>> Also Bertrand Meyer (Eiffel language creator) had idea like that, he >>>> called it "referential transparency". But I think when Python has this >>>> nice property mechanism, why do people change direct data attributes >>>> into >>>> properties and not the other way around or not at all, I mean using >>>> only >>>> properties for logical >>>> data attributes -- e.g. assuring correctness first via read-only >>>> property? >>> >>> I fail to see where read-only-ness of an attribute is a priori more >>> correct >>> than having modifyable attributes. >> >> No, I didn't mean that it is more correct to have an attribute as >> read-only. I meant that letting a logical data attribute start out as >> a read only property can help to ensure correctness. > > Which is the same thing said with other words. No, it's two different things. Whether something is correct or not, it can help to ensure correctness. For a different example of that, a formally incorrect debug thing can help to ensure correctness. >> For example, consider two rectangle classes R1 and R2, where R2 might >> be a successor to R1, at some point in system evolution replacing R1. >> R1 has logical data members left, top, width and height, and R2 has >> logical data members left, top, right and bottom. With R1 direct >> changes of left and top keeps the rectangle's size (since that size is >> specified by width and height), while with R2 it changes the >> rectangle's size. R1 is implemented with logical data members as >> directly exposed data attributes. Some code in the system deals only >> with R1 objects and for convenience or efficiency or whatever uses >> direct modification instead of set_position method. Due to new >> requirements it instead has to deal with R2 objects, with same >> methods. But due to the direct modification of object state it now >> changes the rectangle sizes, but at first it's not noticed since the >> attempted rectangle position changes are very small. People get upset. >> The bug is fixed. Time has been wasted. > > If there is need for mutable rectangles, there is need for mutable > rectangles. Using properties instead of attributes doesn't help In the example above using properties would have avoided the problem. Hence your conclusion is wrong. :-) > - if you > change semantics of something, code might break. Yes, but that's totally out of the blue. If you, say, paint your nose bright green, then people might stare at it. That has nothing to do do with anything discussed here, and so anyone mentioning that as purportedly relevant to anything discussed here, would implicitly be saying "I don't understand anything abour it", and that's effectively what you're saying, sorry. However, I do understand what got you confused. Changing the internal representation of a class is not to change the class' semantics. It belongs to the class only. Anyone availing himself or herself of access to that internal representation is doing something that may or may not work in the future and would ideally be doing it at own's risk, but as the example above illustrated, they're most often doing it at *other*'s risk. And so the issue is how to get them to not do it, even when they think that nobody will check their code until next version of Lib XYZ comes in a year... And that's where using properties from the start enters the picture, making it less convenient for those tinkerers to use internal representation details. > In Python, attributes > are part of the public interface as long as you don't explicitly define > them otherwise. Not sure what that refers to. > But preliminary assumptions about what could be in some yet unseen > future is introducing more code with more chances of errors No not really. >, reducing > the flexibility at the same time. I still fail to see where that's good. Yes. Consider the *nix convention for files, that they're just byte streams. They're *restricted* to byte streams. That's darn inflexible, yes? And totally ungood. :-) (Note: irony) > Code for what you need code for. It works - in all languages, but > especially in Python. Whether that's good advice depends on what you're doing and in what kind of job setting you're doing it. For many cases it is, in essence, a very selfish way. It gets down to saving time *now* for increased future maintainance times for others, which of course is the only rational choice /if/ one is sure to get away with it. OK, I'm not antirely serious but it sounds like you're thinking in this way, to some degree. But check out any debate on Python vs. Perl, in particular about maintainability. Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Tue Nov 3 20:53:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 01:53:15 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > However in this case the procedure by which we derive the value is not > important or even interesting. It is much more succinct to think of the > operation as a value and express it accordingly. There's no need to > clutter the mind with extra name bindings and iteration keywords. They > won't make our idea any more clear. > > dot_product = map(mul, vec1, vec2) > > vs > > dot_product = [a * b for a, b in zip(vec1, vec2)] > > It's very clear, at least to me, what a dot-product is in this case. Except it's not. The dot product of two vectors returns a scalar, not another vector: http://en.wikipedia.org/wiki/Dot_product So what you want is: dot_product = sum(map(mul, vec1, vec2)) > Adding in the loop construct and name bindings doesn't enhance my > understanding of what a dot-product is. I don't need to see the loop > construct at all in this case. A dot product is simply the > multiplication of each element in a vector sequence. What you need is to define a function dot-product, and not hijack the name for a local value. Then the function's implementation is irrelevant to you: it could use a list comp, or could use map, it could use a for- loop, a while loop, recursion, or black magic: scalar = dot_product(vec1, vec2) -- Steven From ethan at stoneleaf.us Tue Nov 3 20:53:31 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Nov 2009 17:53:31 -0800 Subject: ANN: python-dBase 0.86 Released! Message-ID: <4AF0DE9B.1020806@stoneleaf.us> Greetings! I am happy to announce the latest release of python-dBase (dbf for short)! At this point it supports dBase III and Visual FoxPro 6 dbf files. It's a bit quicker now since it's using array.array to hold the records and not strings, and the API has been standardized. It also now has much better, though still basic, documentation. It was initially written to ease transition away from vfp files, but we use it here everyday for processing both vfp and dBase files. Drawbacks: * it is not concurrent * it does not support vfp auto-increment nor null fields * entire table is read into memory, so large tables process slowly * non-initialized logical fields show up as False (? ==> False) Advantages: * entire table is read into memory, so small to medium files process quickly * memo fields (reading *and* writing) are supported * :memory: tables can be used to hold result sets from bigger SQL tables to ease data access * custom date, datetime, and time wrappers to support empty date fields * direct translation from dbf field to python data type To-Do: * add an option to not keep all records in memory for large tables * add codepage support * add more dbf formats (dBase IV, V, 7 -- any links to these layouts would be /greatly/ appreciated!) This release is available at PyPI -- just search for dbf! As always, success stories and bug reports desired. Happy Hacking! ~Ethan~ From sjmachin at lexicon.net Tue Nov 3 20:56:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 17:56:38 -0800 (PST) Subject: elementtree XML() unicode References: Message-ID: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> On Nov 4, 12:14?pm, Kee Nethery wrote: > On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > > > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery ? > > escribi?: > > >> I've removed all the stuff in my code and tried to distill it down ? > >> to just what is failing. Hopefully I have not removed something ? > >> essential. > > Sounds like I did remove something essential. No, you added something that was not only inessential but caused trouble. > > et expects bytes as input, not unicode. You're decoding too early ? > > (decoding early is good, but not in this case, because et does the ? > > work for you). Either feed et.XML with the bytes before decoding, or ? > > reencode the received xml text in UTF-8 (since this is the declared ? > > encoding). > > Here is the code that hits the URL: > ? ? ? ? ?getResponse1 = urllib2.urlopen(theUrl) > ? ? ? ? ?getResponse2 = getResponse1.read() > ? ? ? ? ?getResponse3 = unicode(getResponse2,'UTF-8') > ? ? ? ? theResponseXml = et.XML(getResponse3) > > So are you saying I want to do: > ? ? ? ? ?getResponse1 = urllib2.urlopen(theUrl) > ? ? ? ? ?getResponse4 = getResponse1.read() > ? ? ? ? theResponseXml = et.XML(getResponse4) You got the essence. Note: that in no way implies any approval of your naming convention :-) > The reason I am confused is that getResponse2 is classified as an ? > "str" in the Komodo IDE. I want to make sure I don't lose the non- > ASCII characters coming from the URL. str is all about 8-bit bytes. Your data comes from the web in 8-bit bytes. No problem. Just don't palpate it unnecessarily. > If I do the second set of code, ? > does elementtree auto convert the str into unicode? Yes. See the example I gave in my earlier posting: | ... print c.tag, repr(c.text) | state u'\ue58d83\ue89189\ue79c8C' That first u means the type is unicode. > How do I deal with ? > the XML as unicode when I put it into elementtree as a string? That's unfortunately rather ambiguous: (1) put past/present? (2) string unicode/str? (3) what is referent of "it"? All text in what et returns is unicode [*] so you read it out as unicode (see above example) or written as unicode if you want to change it: your_element.text = u'a unicode object' [*] As an "optimisation", et stores strings as str objects if they contain only ASCII bytes (and are thus losslessly convertible to unicode). In preparation for running your code under Python 3.X, it's best to ignore this and use unicode constants u'foo' (if you need text constants at all) even if et would let you get away with 'foo'. HTH, John From kee at kagi.com Tue Nov 3 21:06:58 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 18:06:58 -0800 Subject: elementtree XML() unicode In-Reply-To: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: On Nov 3, 2009, at 5:27 PM, John Machin wrote: > On Nov 4, 11:01 am, Kee Nethery wrote: >> Having an issue with elementtree XML() in python 2.6.4. >> >> This code works fine: >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> bobblehead> city>city''' >> theResponseXml = et.XML(getResponse) >> >> This code errors out when it tries to do the et.XML() >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> \ue58d83\ue89189\ue79c8C >> \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03> shipping>''' >> theResponseXml = et.XML(getResponse) >> >> In my real code, I'm pulling the getResponse data from a web page >> that >> returns as XML and when I display it in the browser you can see the >> Japanese characters in the data. I've removed all the stuff in my >> code >> and tried to distill it down to just what is failing. Hopefully I >> have >> not removed something essential. >> >> Why is this not working and what do I need to do to use Elementtree >> with unicode? > > On Nov 4, 11:01 am, Kee Nethery wrote: >> Having an issue with elementtree XML() in python 2.6.4. >> >> This code works fine: >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> bobblehead> city>city''' >> theResponseXml = et.XML(getResponse) >> >> This code errors out when it tries to do the et.XML() >> >> from xml.etree import ElementTree as et >> getResponse = u''' >> \ue58d83\ue89189\ue79c8C >> \ue69f8f\ue5b882\ue9ab98\ue58d97\ue58fb03> shipping>''' >> theResponseXml = et.XML(getResponse) >> >> In my real code, I'm pulling the getResponse data from a web page >> that >> returns as XML and when I display it in the browser you can see the >> Japanese characters in the data. I've removed all the stuff in my >> code >> and tried to distill it down to just what is failing. Hopefully I >> have >> not removed something essential. >> >> Why is this not working and what do I need to do to use Elementtree >> with unicode? > > What you need to do is NOT feed it unicode. You feed it a str object > and it gets decoded according to the encoding declaration found in the > first line. That it uses "the encoding declaration found in the first line" is the nugget of data that is not in the documentation that has stymied me for days. Thank you! The other thing that has been confusing is that I've been using "dump" to view what is in the elementtree instance and the non-ASCII characters have been displayed as "numbered entities" (柏市) and I know that is not the representation I want the data to be in. A co-worker suggested that instead of "dump" that I use "et.tostring(theResponseXml, encoding='utf-8')" and then print that to see the characters. That process causes the non-ASCII characters to display as the glyphs I know them to be. If there was a place in the official docs for me to append these nuggets of information to the sections for "xml.etree.ElementTree.XML(text)" and "xml.etree.ElementTree.dump(elem)" I would absolutely do so. Thank you! Kee Nethery > So take the str object that you get from the web (should > be UTF8-encoded already unless the header is lying), and throw that at > ET ... like this: > > | Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit > (Intel)] on win32 > | Type "help", "copyright", "credits" or "license" for more > information. > | >>> from xml.etree import ElementTree as et > | >>> ucode = u''' > | ... > | ... \ue58d83\ue89189\ue79c8C > | ... \ue69f8f\ue5b882 > | ... \ue9ab98\ue58d97\ue58fb03 > | ... ''' > | >>> xml= et.XML(ucode) > | Traceback (most recent call last): > | File "", line 1, in > | File "C:\python26\lib\xml\etree\ElementTree.py", line 963, in XML > | parser.feed(text) > | File "C:\python26\lib\xml\etree\ElementTree.py", line 1245, in > feed > | self._parser.Parse(data, 0) > | UnicodeEncodeError: 'ascii' codec can't encode character u'\ue58d' > in position 69: ordinal not in range(128) > | # as expected > | >>> strg = ucode.encode('utf8') > | # encoding as utf8 is for DEMO purposes. > | # i.e. use the original web str object, don't convert it to unicode > | # and back to utf8. > | >>> xml2 = et.XML(strg) > | >>> xml2.tag > | 'customer' > | >>> for c in xml2.getchildren(): > | ... print c.tag, repr(c.text) > | ... > | shipping '\n' > | >>> for c in xml2[0].getchildren(): > | ... print c.tag, repr(c.text) > | ... > | state u'\ue58d83\ue89189\ue79c8C' > | city u'\ue69f8f\ue5b882' > | street u'\ue9ab98\ue58d97\ue58fb03' > | >>> > > By the way: (1) it usually helps to be more explicit than "errors > out", preferably the exact copied/pasted output as shown above; this > is one of the rare cases where the error message is predictable (2) > PLEASE don't start a new topic in a reply in somebody else's thread. > > -- > http://mail.python.org/mailman/listinfo/python-list ------------------------------------------------- I check email roughly 2 to 3 times per business day. Kagi main office: +1 (510) 550-1336 From steven at REMOVE.THIS.cybersource.com.au Tue Nov 3 21:25:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 02:25:06 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: On Tue, 03 Nov 2009 11:26:49 +0000, Simon Brunning wrote: > 2009/11/1 Steven D'Aprano : >> >> The only stupid question is the one you are afraid to ask. > > I was once asked, and I quote exactly, "are there any fish in the > Atlantic sea?" > > That's pretty stupid. ;-) Once in the distant past, there were no fish in what would become the Atlantic Ocean (not sea); and some day in the future there won't be any fish either. At the rate we're going that day may not be that far away: fish are being over-fished all over the world, jellyfish are blooming, and there are areas of the Namibian continental where the dominant species have flipped from fish to jellyfish: http://www.scienceinafrica.co.za/2009/september/jellyfish.htm http://www.sciencedaily.com/releases/2006/07/060711091411.htm http://www.sciencedaily.com/releases/2009/06/090609092057.htm So, no, not a stupid question at all. -- Steven From ben+python at benfinney.id.au Tue Nov 3 21:59:03 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 13:59:03 +1100 Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> Message-ID: <87hbtbf11k.fsf@benfinney.id.au> Simon Brunning writes: > 2009/11/1 Steven D'Aprano : > > > > The only stupid question is the one you are afraid to ask. > > I was once asked, and I quote exactly, "are there any fish in the > Atlantic sea?" > > That's pretty stupid. ;-) Not at all. The person asking the question might be ignorant of the facts about fishing, or the Atlantic, or marine ecosystems in that region, etc., in which case the question is smart and wise and to the point. Especially compared with the alternative: not asking the question perpetuates the ignorance. -- \ ?If I had known what it would be like to have it all... I might | `\ have been willing to settle for less.? ?Jane Wagner, via Lily | _o__) Tomlin | Ben Finney From sjmachin at lexicon.net Tue Nov 3 22:02:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 3 Nov 2009 19:02:24 -0800 (PST) Subject: elementtree XML() unicode References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: <59090fb8-5a22-47c8-ac6d-90b22936f825@j9g2000prh.googlegroups.com> On Nov 4, 1:06?pm, Kee Nethery wrote: > On Nov 3, 2009, at 5:27 PM, John Machin wrote: > > > > > On Nov 4, 11:01 am, Kee Nethery wrote: > >> Why is this not working and what do I need to do to use Elementtree > >> with unicode? > > > What you need to do is NOT feed it unicode. You feed it a str object > > and it gets decoded according to the encoding declaration found in the > > first line. > > That it uses "the encoding declaration found in the first line" is the ? > nugget of data that is not in the documentation that has stymied me ? > for days. Thank you! And under the "don't repeat" principle, it shouldn't be in the Elementtree docs; it's nothing special about ET -- it's part of the definition of an XML document (which for universal loss-free transportability naturally must be encoded somehow, and the document must state what its own encoding is (if it's not the default (UTF-8))). > The other thing that has been confusing is that I've been using "dump" ? > to view what is in the elementtree instance and the non-ASCII ? > characters have been displayed as "numbered ? > entities" (柏市) and I know that is not the ? > representation I want the data to be in. A co-worker suggested that ? > instead of "dump" that I use "et.tostring(theResponseXml, ? > encoding='utf-8')" and then print that to see the characters. That ? > process causes the non-ASCII characters to display as the glyphs I ? > know them to be. > > If there was a place in the official docs for me to append these ? > nuggets of information to the sections for ? > "xml.etree.ElementTree.XML(text)" and ? > "xml.etree.ElementTree.dump(elem)" I would absolutely do so. I don't understand ... tostring() is in the same section as dump(), about two screen-heights away. You want to include the tostring() docs in the dump() docs? The usual idea is not to get bogged down in the first function that looks at first glance like it might do what you want ("look at the glyphs") but doesn't (it writes a (transportable) XML stream) but press on to the next plausible candidate. From gagsl-py2 at yahoo.com.ar Tue Nov 3 22:06:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 00:06:50 -0300 Subject: elementtree XML() unicode References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery escribi?: > If there was a place in the official docs for me to append these nuggets > of information to the sections for "xml.etree.ElementTree.XML(text)" and > "xml.etree.ElementTree.dump(elem)" I would absolutely do so. http://bugs.python.org/ applies to documentation too. -- Gabriel Genellina From fordhaivat at gmail.com Tue Nov 3 22:20:05 2009 From: fordhaivat at gmail.com (Someone Something) Date: Tue, 3 Nov 2009 22:20:05 -0500 Subject: continuous return? Message-ID: I'm trying to write something related to IRC. The thing is, I have one thread receiving and another sending. But, how can I keep the caller of the recv() function informed about what was last received so that it can all be printed out. But, I no idea how I can accomplish this. I was thinking about getting one variable that was constantly updated with the latest line that was recved and that the variable would be a member of the class so other functions/classes can access it -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Nov 3 22:31:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 00:31:34 -0300 Subject: continuous return? References: Message-ID: En Wed, 04 Nov 2009 00:20:05 -0300, Someone Something escribi?: > I'm trying to write something related to IRC. The thing is, I have one > thread receiving and another sending. But, how can I keep the caller of > the > recv() function informed about what was last received so that it can all > be > printed out. But, I no idea how I can accomplish this. I was thinking > about > getting one variable that was constantly updated with the latest line > that > was recved and that the variable would be a member of the class so other > functions/classes can access it I don't completely understand your scenario, but since you say you have several threads, a common way to communicate between them is to use a Queue object. Let the receiver thread put() lines into the queue, and the processing thread get() them and do some work. -- Gabriel Genellina From jon at jonhaddad.com Tue Nov 3 23:02:24 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Tue, 3 Nov 2009 20:02:24 -0800 Subject: unittest & setup Message-ID: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Maybe I'm doing something wrong here, definitely not the most experienced unit tester. I've got a class, in the constructor it loads a CSV file from disc. I'd like only 1 instance of the class to be instantiated. However, when running multiple unit tests, multiple instances of the class are created. What's the best way for me to avoid this? It takes about a few seconds to load the CSV file. -- Jonathan Haddad http://www.rustyrazorblade.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From kee at kagi.com Tue Nov 3 23:42:15 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 3 Nov 2009 20:42:15 -0800 Subject: elementtree XML() unicode In-Reply-To: References: <5c386831-eb92-4027-9786-d94a95e859f0@b25g2000prb.googlegroups.com> Message-ID: <340744BF-30E0-490A-9FAC-52E8D26EA410@kagi.com> On Nov 3, 2009, at 7:06 PM, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery > escribi?: > >> If there was a place in the official docs for me to append these >> nuggets of information to the sections for >> "xml.etree.ElementTree.XML(text)" and >> "xml.etree.ElementTree.dump(elem)" I would absolutely do so. > > http://bugs.python.org/ applies to documentation too. I've submitted documentation bugs in the past and no action was taken on them, the bugs were closed. I'm guessing that information "that everyone knows" not being in the documentation is not a bug. It's my fault I'm a newbie and I accept that. Thanks to you two for helping me get past this block. Kee From gagsl-py2 at yahoo.com.ar Tue Nov 3 23:42:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 01:42:55 -0300 Subject: unittest & setup References: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Message-ID: En Wed, 04 Nov 2009 01:02:24 -0300, Jonathan Haddad escribi?: > I've got a class, in the constructor it loads a CSV file from disc. I'd > like only 1 instance of the class to be instantiated. However, when > running > multiple unit tests, multiple instances of the class are created. What's > the best way for me to avoid this? It takes about a few seconds to load > the > CSV file. Use a factory function: _instance = None def createFoo(parameters): if _instance is None: _instance = Foo(parameters) return _instance and replace all occurrences of Foo(parameters) with createFoo(parameters). For new-style classes, you may override the __new__ method instead. Perhaps I didn't understand your problem correctly because this is unrelated to unit testing... -- Gabriel Genellina From robert.kern at gmail.com Tue Nov 3 23:43:45 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 03 Nov 2009 22:43:45 -0600 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: Steven D'Aprano wrote: > On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: >> Adding in the loop construct and name bindings doesn't enhance my >> understanding of what a dot-product is. I don't need to see the loop >> construct at all in this case. A dot product is simply the >> multiplication of each element in a vector sequence. > > What you need is to define a function dot-product, and not hijack the > name for a local value. Then the function's implementation is irrelevant > to you: it could use a list comp, or could use map, it could use a for- > loop, a while loop, recursion, or black magic: > > scalar = dot_product(vec1, vec2) Or use the appropriate libraries: from numpy import dot scalar = dot(vec1, vec2) -- 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 gopalm at infotechsw.com Wed Nov 4 00:04:11 2009 From: gopalm at infotechsw.com (gopal mishra) Date: Wed, 4 Nov 2009 10:34:11 +0530 Subject: how to create nested classes dynamically Message-ID: <99950C2A2F9D425F9B88823EEA113105@pwit.com> I have class structure as below. How can I create the following nested class and its properties dynamically. class AA(object): class BB(object): def setBB1(self, value): ##some code def getBB1(self): bb1 = #somecode return bb1 bb1 = property(getBB1, setBB1, None, None) bb2 = ... bb = BB() class CC(object): .... cc = CC() aa = AA() print aa.bb.bb1 aa.bb.bb2 = '10' print aa.bb.bb2 I want to achive dot structure get or set value.i.e. aa.bb.bb1 Thanks, Gopal -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 00:35:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 05:35:30 GMT Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: > Steven D'Aprano wrote: >> On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > >>> Adding in the loop construct and name bindings doesn't enhance my >>> understanding of what a dot-product is. I don't need to see the loop >>> construct at all in this case. A dot product is simply the >>> multiplication of each element in a vector sequence. >> >> What you need is to define a function dot-product, and not hijack the >> name for a local value. Then the function's implementation is >> irrelevant to you: it could use a list comp, or could use map, it could >> use a for- loop, a while loop, recursion, or black magic: >> >> scalar = dot_product(vec1, vec2) > > Or use the appropriate libraries: > > from numpy import dot > > scalar = dot(vec1, vec2) Why would I want to use an already existing library that is fast, well- written and well-supported, when I can toss together a nasty kludge myself? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 00:35:52 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 05:35:52 GMT Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: >>> For example, consider two rectangle classes R1 and R2, where R2 might >>> be a successor to R1, at some point in system evolution replacing R1. >>> R1 has logical data members left, top, width and height, and R2 has >>> logical data members left, top, right and bottom. With R1 direct >>> changes of left and top keeps the rectangle's size (since that size is >>> specified by width and height), while with R2 it changes the >>> rectangle's size. R1 is implemented with logical data members as >>> directly exposed data attributes. Some code in the system deals only >>> with R1 objects and for convenience or efficiency or whatever uses >>> direct modification instead of set_position method. Due to new >>> requirements it instead has to deal with R2 objects, with same >>> methods. But due to the direct modification of object state it now >>> changes the rectangle sizes, but at first it's not noticed since the >>> attempted rectangle position changes are very small. People get upset. >>> The bug is fixed. Time has been wasted. >> >> If there is need for mutable rectangles, there is need for mutable >> rectangles. Using properties instead of attributes doesn't help > > In the example above using properties would have avoided the problem. How would it have avoided the problem? Either of these would have the exact same semantics: class R2(object): def __init__(self): self._secret = {'top': 0, 'bottom': 100} def _top_getter(self): return self._secret['top'] def _top_setter(self, value): self._secret['top'] = value top = property(_top_getter, _top_setter) vs class R2(object): def __init__(self): self.top = 0 self.bottom = 100 Given the semantics you specified, it is strictly irrelevant whether R2.top is an attribute or a property. That's an implementation detail. Now of course we're capable of imagining a rectangle class R3 where R3.top is a property which has the side-effect of also changing R3.bottom so as to avoid the resize. Great -- that's something you can't implement (easily, if at all) with bare attributes. But that class is not R2, it has different semantics to R2. We're not opposed to properties where the functional requirements are best suited by computed properties. But properties don't come for free, and if you're going to implement functional behaviour *identical* to bare attributes using properties, then what's the point? >> - if you >> change semantics of something, code might break. > > Yes, but that's totally out of the blue. If you, say, paint your nose > bright green, then people might stare at it. That has nothing to do do > with anything discussed here, and so anyone mentioning that as > purportedly relevant to anything discussed here, would implicitly be > saying "I don't understand anything abour it", and that's effectively > what you're saying, sorry. I'm afraid you have failed to understand Diez's point. The hypothetical project using class R1 had a specified functional behaviour: assigning to rectangle.top must move the rectangle, not resize it. You have replaced it with a class that has different behaviour. Who cares what the implementation is? It's the *change in behaviour* that caused the breakage, regardless of whether R2.top is implemented as a bare attribute or as a property. In that regard, it is *no different* from changing R2.set_position() to resize the rectangle. > However, I do understand what got you confused. I doubt that very much. > Changing the internal representation of a class is not to change the > class' semantics. That's true, but that's not what you've done in your example. You've clearly changes the class' semantics. You said so yourself: "With R1 direct changes of left and top keeps the rectangle's size (since that size is specified by width and height), while with R2 it changes the rectangle's size." Since in Python, non-underscore attributes are part of the public API, the two classes have different semantics. > It belongs to the class only. Anyone availing himself > or herself of access to that internal representation is doing something > that may or may not work in the future and would ideally be doing it at > own's risk, but as the example above illustrated, they're most often > doing it at *other*'s risk. Irrelevant. In Python, attributes are frequently part of the class API. If you have an attribute R1.top, then people will assign to it, and your class should deal with it. "Deal with it", by the way, may include saying "if you stuff something crazy in the attribute, then you are responsible for breaking it". Python classes tend to be written under the implicit promise/threat that if you do something stupid, you're responsible for the breakage. That allows the caller the responsibility to do something clever which you never thought of without having to defeat your defensive code, but with great power (duck-typing) comes great responsibility (don't set R1.top to None unless you want to see some amusing exceptions). > And so the issue is how to get them to not do it, even when they think > that nobody will check their code until next version of Lib XYZ comes in > a year... > > And that's where using properties from the start enters the picture, > making it less convenient for those tinkerers to use internal > representation details. This is Python. Introspection is easy, and messing up your internals is easy unless you write your class in C. Just because you hide something behind a property doesn't mean we can't find it and do strange and terrible things to it. We don't do it because when we do, it's our own foot we're shooting. >> In Python, attributes >> are part of the public interface as long as you don't explicitly define >> them otherwise. > > Not sure what that refers to. Dear me. Here you are talking about "internals", and you don't see the connection with the public interface? Hint: if something is in the public interface, it isn't an internal detail. >> But preliminary assumptions about what could be in some yet unseen >> future is introducing more code with more chances of errors > > No not really. Of course it is. Properties are *code*. Every line of code can contain bugs. Properties require testing. They don't fall from the sky and insert themselves into your class, you have to write them, test them, debug them, maintain them. >>, reducing >> the flexibility at the same time. I still fail to see where that's >> good. > > Yes. > > Consider the *nix convention for files, that they're just byte streams. > They're *restricted* to byte streams. That's darn inflexible, yes? No. Anything can be represented by a byte stream with a known encoding, provided you are willing to deal with errors. -- Steven From israelu at elbit.co.il Wed Nov 4 00:45:23 2009 From: israelu at elbit.co.il (iu2) Date: Tue, 3 Nov 2009 21:45:23 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> Message-ID: <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> On Nov 4, 3:10?am, "Gabriel Genellina" wrote: > En Tue, 03 Nov 2009 17:36:08 -0300, iu2 escribi?: > > > > > > > On Nov 3, 7:49 pm, Matt McCredie wrote: > >> iu2 elbit.co.il> writes: > > >> > Having a file called funcs.py, I would like to read it into a string, > >> > and then import from that string. > >> > That is instead of importing from the fie system, I wonder if it's > >> > possible to eval the text in the string and treat it as a module. > >> mymodule = types.ModuleType("mymodule", "Optional Doc-String") > >> with file('funcs.py') as f: > >> ? ? txt = f.read() > >> exec txt in globals(), mymodule.__dict__ > >> sys.modules['mymodule'] = mymodule > > > Thanks, it seems simpler than I thought. > > I don't fully understand , though, the exec statement, how it causes > > the string execute in the context of mymodule. > > Sometimes you don't even require a module, and this is simpler to ? > understand. Suppose you have a string like this: > > txt = """ > def foo(x): > ? ?print 'x=', x > > def bar(x): > ? ?return x + x > """ > > you may execute it: > > py> namespace = {} > py> exec txt in namespace > > The resulting namespace contains the foo and bar functions, and you may ? > call them: > > py> namespace.keys() > ['__builtins__', 'foo', 'bar'] > py> namespace['foo']('hello') > x= hello > > exec just executes the string using the given globals dictionary as its ? > global namespace. Whatever is present in the dictionary is visible in the ? > executed code as global variables (none in this example). The global names ? > that the code creates become entries in the dictionary. (foo and bar; ? > __builtins__ is an implementation detail of CPython). You may supply ? > separate globals and locals dictionaries. > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - Thanks for the explanation. What happens if both global and local dictionaries are supplied: where are the newly created entities created? In the local dict? From gagsl-py2 at yahoo.com.ar Wed Nov 4 00:55:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 02:55:00 -0300 Subject: how to create nested classes dynamically References: <99950C2A2F9D425F9B88823EEA113105@pwit.com> Message-ID: En Wed, 04 Nov 2009 02:04:11 -0300, gopal mishra escribi?: > I have class structure as below. How can I create the following nested > class > and its properties dynamically. > > > class AA(object): > > class BB(object): > > def setBB1(self, value): > > ##some code > > def getBB1(self): > > bb1 = #somecode > > return bb1 > > bb1 = property(getBB1, setBB1, None, None) > > bb2 = ... > > bb = BB() > > class CC(object): > > .... > > cc = CC() > > aa = AA() First, I assume getBB1 and setBB1 really do some actual work. If they're just accessors for an instance attribute, don't use them; don't write Java in Python [1] In Python, you may have instance (or "normal") attributes, and class attributes. When you say obj.name, if name is not found as an instance attribute, it is looked up on its class (and all its base classes; this is how methods are searched, BTW) Class attributes are "shared" among all instances - that is, all instances retrieve the same object when you access a class attribute. Your code above, as it is written, creates two class attributes named bb and cc (they're class attributes because the statements bb=... and cc=... are inside the class definition). It works, but perhaps that's not what you want. If you want instance attributes instead, create them in AA.__init__ by using self.bb=something Nested classes provide no benefit here and are harder to use, so just move the class definitions to the module level. The code would become: class BB(object): def setBB1(self, value): ##some code def getBB1(self): "docstring for the property" bb1 = #somecode return bb1 bb1 = property(getBB1, setBB1) bb2 = ... class CC(object): .... class AA(object): def __init__(self, ...): self.bb = BB() self.cc = CC() Then, you can write: aa = AA() print aa.bb.bb1 aa.bb.bb2 = '10' print aa.bb.bb2 [1] http://dirtsimple.org/2004/12/python-is-not-java.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Nov 4 01:02:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 03:02:34 -0300 Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: > On Nov 4, 3:10 am, "Gabriel Genellina" wrote: >> txt = """ >> def foo(x): >> print 'x=', x >> >> def bar(x): >> return x + x >> """ >> >> py> namespace = {} >> py> exec txt in namespace >> py> namespace.keys() >> ['__builtins__', 'foo', 'bar'] >> py> namespace['foo']('hello') >> x= hello > What happens if both global and local dictionaries are supplied: where > are the newly created entities created? In the local dict? The amazing thing about Python is how easy is to experiment in the interpreter. Just see it by yourself! -- Gabriel Genellina From alfps at start.no Wed Nov 4 01:15:14 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 07:15:14 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Steven D'Aprano: > On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: > >>>> For example, consider two rectangle classes R1 and R2, where R2 might >>>> be a successor to R1, at some point in system evolution replacing R1. >>>> R1 has logical data members left, top, width and height, and R2 has >>>> logical data members left, top, right and bottom. With R1 direct >>>> changes of left and top keeps the rectangle's size (since that size is >>>> specified by width and height), while with R2 it changes the >>>> rectangle's size. R1 is implemented with logical data members as >>>> directly exposed data attributes. Some code in the system deals only >>>> with R1 objects and for convenience or efficiency or whatever uses >>>> direct modification instead of set_position method. Due to new >>>> requirements it instead has to deal with R2 objects, with same >>>> methods. But due to the direct modification of object state it now >>>> changes the rectangle sizes, but at first it's not noticed since the >>>> attempted rectangle position changes are very small. People get upset. >>>> The bug is fixed. Time has been wasted. >>> If there is need for mutable rectangles, there is need for mutable >>> rectangles. Using properties instead of attributes doesn't help >> In the example above using properties would have avoided the problem. > > How would it have avoided the problem? Either of these would have the > exact same semantics: > > class R2(object): > def __init__(self): > self._secret = {'top': 0, 'bottom': 100} > def _top_getter(self): > return self._secret['top'] > def _top_setter(self, value): > self._secret['top'] = value > top = property(_top_getter, _top_setter) > > vs > > class R2(object): > def __init__(self): > self.top = 0 > self.bottom = 100 OK, I had a laugh. :-) You maintain that all doors are dark red, and show up a photo of two of your dark red doors as proof. For R2, did you at *any* moment consider properties that emulated the internal representation of R1? I'm putting it that way on the off-chance that you're not just pretending to not understand. > Given the semantics you specified No semantics was specified in my example, quoted in full above. However, the natural semantics is that various logical properties, such as left, top, right, bottom, width and height, can be varied independently. > it is strictly irrelevant whether > R2.top is an attribute or a property. That's an implementation detail. Happily that's incorrect. You might try to consider what properties are *for*, why the language supports them if they do nothing at all except adding overhead. Cheers, & hth., - Alf From highcar at gmail.com Wed Nov 4 02:32:14 2009 From: highcar at gmail.com (elca) Date: Tue, 3 Nov 2009 23:32:14 -0800 (PST) Subject: disable image loading to speed up webpage load In-Reply-To: <7l7nklF3cgpk3U1@mid.uni-berlin.de> References: <26155440.post@talk.nabble.com> <7l7nklF3cgpk3U1@mid.uni-berlin.de> Message-ID: <26192072.post@talk.nabble.com> Diez B. Roggisch-2 wrote: > > elca schrieb: >> Hi, >> im using win32com 's webbrowser module. >> i have some question about it.. >> is it possible to disable image loading to speed up webpage load? >> any help ,much appreciate >> thanks in advance > > Use urllib2. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > you can show me some more specific sample or demo? -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26192072.html Sent from the Python - python-list mailing list archive at Nabble.com. From gagsl-py2 at yahoo.com.ar Wed Nov 4 02:37:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 04:37:14 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 03:15:14 -0300, Alf P. Steinbach escribi?: > * Steven D'Aprano: >> On Wed, 04 Nov 2009 02:29:21 +0100, Alf P. Steinbach wrote: >> >>>>> For example, consider two rectangle classes R1 and R2, where R2 might >>>>> be a successor to R1, at some point in system evolution replacing R1. >>>>> R1 has logical data members left, top, width and height, and R2 has >>>>> logical data members left, top, right and bottom. With R1 direct >>>>> changes of left and top keeps the rectangle's size (since that size >>>>> is >>>>> specified by width and height), while with R2 it changes the >>>>> rectangle's size. R1 is implemented with logical data members as >>>>> directly exposed data attributes. Some code in the system deals only >>>>> with R1 objects and for convenience or efficiency or whatever uses >>>>> direct modification instead of set_position method. Due to new >>>>> requirements it instead has to deal with R2 objects, with same >>>>> methods. But due to the direct modification of object state it now >>>>> changes the rectangle sizes, but at first it's not noticed since the >>>>> attempted rectangle position changes are very small. People get >>>>> upset. >>>>> The bug is fixed. Time has been wasted. >>>> If there is need for mutable rectangles, there is need for mutable >>>> rectangles. Using properties instead of attributes doesn't help >>> In the example above using properties would have avoided the problem. >> How would it have avoided the problem? Either of these would have the >> exact same semantics: >> class R2(object): >> def __init__(self): >> self._secret = {'top': 0, 'bottom': 100} >> def _top_getter(self): >> return self._secret['top'] >> def _top_setter(self, value): >> self._secret['top'] = value >> top = property(_top_getter, _top_setter) >> vs >> class R2(object): >> def __init__(self): >> self.top = 0 >> self.bottom = 100 > > OK, I had a laugh. :-) You maintain that all doors are dark red, and > show up a photo of two of your dark red doors as proof. > > For R2, did you at *any* moment consider properties that emulated the > internal representation of R1? > > I'm putting it that way on the off-chance that you're not just > pretending to not understand. I don't understand either. R1 and R2 have *different* semantics. They don't behave the same. Any breakage you experiment using R2 instead of R1 comes from the fact they behave differently, not because they're implemented differently, nor because they use properties or not. You could have implemented another variant, let's say RCrazy, that behaves exactly the same as R1 but internally stores a different set of attributes (the baricenter, the angle between both diagonals, and the diagonal length). As long as you implement the same public interfase (same set of externally visible attributes, same methods, same behavior) RCrazy is interchangeable with R1; RCrazy is a subtype of R1 in the sense of the Liskov substitution principle. Of course, perfect substitutability (did I spell it right?) isn't possible in Python; obj.__class__.__name__ returns 'RCrazy' instead of 'R1', it's mro() is different, dir() returns a different set of names, etc. But for any `reasonable` use of an R1 instance representing a rectangle, an RCrazy instance should serve equally well. >> Given the semantics you specified > > No semantics was specified in my example, quoted in full above. > > However, the natural semantics is that various logical properties, such > as left, top, right, bottom, width and height, can be varied > independently. You did specify the set of attributes and how they behave, perhaps not very formally, but that's a semantic specification to me. It was clear from your description that R2 behave different that R1; the problems that came after using R2 instead of R1 were caused by such different behavior, not because of using properties or not. In any case, I don't think the problem is specific to Python. >> it is strictly irrelevant whether R2.top is an attribute or a property. >> That's an implementation detail. > > Happily that's incorrect. You might try to consider what properties are > *for*, why the language supports them if they do nothing at all except > adding overhead. In normal usage (either obj.name or getattr(obj, 'name')) an attribute is undistinguishable from a property. Users of the class should not worry at all whether it is implemented as a simple attribute, a computed property, or an esoteric class attribute following the descriptor protocol. If all a property does is to store and retrieve its value as an instance attribute, yes, it just adds overhead. -- Gabriel Genellina From clp2 at rebertia.com Wed Nov 4 02:42:01 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 3 Nov 2009 23:42:01 -0800 Subject: how to remove the punctuation and no need words from paragraphs In-Reply-To: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> References: <5994811b-b72a-4426-9b39-7d9f8bf54ea1@a39g2000pre.googlegroups.com> Message-ID: <50697b2c0911032342o6d85a958r25ec70c5b2572e1c@mail.gmail.com> On Tue, Nov 3, 2009 at 1:44 PM, kylin wrote: > I want to remove all the punctuation and no need words form a string > datasets for experiment. > > I am new to python, please give me some clue and direction to write > this code. The `replace` method of strings should get you pretty far (just replace unwanted stuff with the empty string): http://docs.python.org/library/stdtypes.html#str.replace Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Wed Nov 4 02:47:45 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Nov 2009 08:47:45 +0100 Subject: Tkinter callback arguments References: Message-ID: Alf P. Steinbach wrote: > * Peter Otten: >> * Alf P. Steinbach wrote: >>> * Peter Otten: >>>> Every time someone has to read the code he will read, hesitate, read >>>> again, and then hopefully come to the conclusion that the code does >>>> nothing, consider not using it, or if it is not tied into a larger >>>> project removing it. >>> I don't understand what you mean. >> >> Writing code is not fire and forget. It has to be debugged, tested, >> maintained, and will be read quite a few times in the process. Therefore >> it is important that you make it easy to read and understand. > > No, I meant that I didn't understand why you find it hard to read and > understand. Too many indirections. > [snip] >> Couldn't >> >> class IdButton(tkinter.Button): >> def __init__(self, id, **kw): >> self.id = id >> tkinter.Button.__init__(self, **kw) >> >> be customised as easily? > > Not unless there's much more that I can learn about tkinter button > 'command' callbacks. Which is of course possible. :-) Is it possible to > pick up the relevant object from the handler? There may be a way using bind(), but the idea was to make simple specialised subclasses as needed that either invoke a method or take a function that can be wrapped (something like command = functools.partial(command, self)). >>>> Example: Why do you introduce button.id_string() instead of >>>> str(button.id)? >>> Because the string representation of an id then /can/ be customized >>> independently of the id. For example, id's might be integers but for >>> string representation you might want symbolic action names (e.g., you >>> might have two or more buttons with same title but different actions, so >>> that title would be ungood to identify button). And for another example, >>> when debugging or testing you might want the string represention of an >>> id to provide more information about the button and/or its context, and >>> then id_string provides a single >>> central customization point -- provided it's used, of course. >> >> And what about the IdEntry class? > > The naming scheme doesn't hold up, but I'm pretty sure that's not what you > mean? I meant that when you need other classes with an .id you will now have to implement .id_string(), too. A simple approach like entry = tkinter.Entry(...) entry.id = 42 won't work anymore. Peter From alfps at start.no Wed Nov 4 02:50:42 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 08:50:42 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > > I don't understand either. R1 and R2 have *different* semantics. Assume that they have the very exact same semantics -- like two TV sets that look the same and work the same except when you open 'em up and poke around in there, oh holy cow, in this one there's stuff that isn't in the other. After all the semantics (like the TV controls and their effects) were left unspecified, only the internal representations (like, the main circuit boards *inside* the TVs) were described, and the example only makes sense if R1 and R2 have the same semantics, that is, work the same via their public interfaces. If I'd known that people would start a discussion based on their wishes that the unspecied semantics should be some that made the example meaningless, well, then I'd simply specified the semantics -- consider that done. > They don't behave the same. Assume that they do -- except when you go poking into the innards. Cheers & hth., - Alf From neuphyte at gmail.com Wed Nov 4 02:55:16 2009 From: neuphyte at gmail.com (Siva Subramanian) Date: Wed, 4 Nov 2009 13:25:16 +0530 Subject: using csv dictreader in python Message-ID: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> Hello all, I am now trying to access the csv file using dictreader. import csv r25 = csv.DictReader(open('Report_ 25', 'rb'), delimiter=',') rownum = 1 for row in r25: # Save header row. if rownum == 0: header = row else: colnum = 0 for col in row: This only gets me the following output {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': '4001433', 'FieldName4': '759'} 1. How do i access the 4, 0.00, ... the values ? 2. How do i compare it with another csv file ? Thanks in advance Siva -------------- next part -------------- An HTML attachment was scrubbed... URL: From lorenzo.digregorio at gmail.com Wed Nov 4 03:04:08 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Wed, 4 Nov 2009 00:04:08 -0800 (PST) Subject: How to print zero-padded floating point numbers in python 2.6.1 Message-ID: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Hello, I thought that I could zero-pad a floating point number in 'print' by inserting a zero after '%', but this does not work. I get: print '%2.2F' % 3.5 3.50 print '%02.2F' % 3.5 3.50 How can I get print (in a simple way) to print 03.50? Best Regards, Lorenzo From _rdi_ at web.de Wed Nov 4 03:15:17 2009 From: _rdi_ at web.de (=?UTF-8?B?UsO8ZGlnZXIgUmFuZnQ=?=) Date: Wed, 04 Nov 2009 09:15:17 +0100 Subject: comparing alternatives to py2exe In-Reply-To: References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <7lcrglF3cc7quU1@mid.individual.net> Maxim Khitrov schrieb: > 1. I don't think cx_freeze supports single exe. I haven't even been > able to get it to append the generated library.zip file to the > executable using documented options. Other things like .pyd files > always seem to be separate. At the same time, singe executables > generated by py2exe do not always work. I have a program that works > fine on Windows XP, Vista, and 7 if it is built under XP. However, if > I build the exact same program under Windows 7, it no longer works on > Vista or XP. I'm sure it has something to do with SxS or other dll > issues. I had similar issues with under Vista generated programs not running under 2K (unfortunately I have to support it). This behavior came from the .dll dependency tracking of py2exe, which included a OS .dll into the dist output. These are the steps I toke to find the offending .dll * generated a "flat" directory (the .dll's not packed into library.zip) with options = { [...], 'bundle_files': 3 } * extracted the not loadable extension from library.zip * examined the dependencies of this module with Microsoft's "Dependency Walker" (you can find it somewhere in the MSDN) * added the superfluous .dll to the options = { [...], 'dll_excludes': ['offending.dll'] } parameter HTH Rudi From lutz.horn at fastmail.fm Wed Nov 4 03:25:53 2009 From: lutz.horn at fastmail.fm (Lutz Horn) Date: Wed, 04 Nov 2009 09:25:53 +0100 Subject: How to print zero-padded floating point numbers in python 2.6.1 In-Reply-To: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> References: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Message-ID: Lorenzo Di Gregorio schrieb: > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a simple way) to print 03.50? print '%05.2F' % 3.5 Lutz From _rdi_ at web.de Wed Nov 4 03:30:40 2009 From: _rdi_ at web.de (=?ISO-8859-1?Q?R=FCdiger_Ranft?=) Date: Wed, 04 Nov 2009 09:30:40 +0100 Subject: Win XP: How to hide command window for sub processes? In-Reply-To: References: <6ab3abec-c529-4832-b57b-9017f93c1730@g27g2000yqn.googlegroups.com> <7kt8sgF3blcosU1@mid.individual.net> Message-ID: <7lcsdjF3d92u0U1@mid.individual.net> klausfpga schrieb: > On Oct 29, 11:25 am, R?diger Ranft <_r... at web.de> wrote: > Thanks Ruediger, > > I'll try that immediately tomorrow, when working again on a windows > host. > > Good to know, that the Python API supports this. > though this feature was not that easy to be found in the doc. Well, getting the point from subproces.py was easy. Finding the documentation about STARTUPINFO in the MSDN was not. I better stop here before this post turns into a rant about Mircosofts use of javascript. bye Rudi From clp2 at rebertia.com Wed Nov 4 03:37:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 00:37:52 -0800 Subject: How to print zero-padded floating point numbers in python 2.6.1 In-Reply-To: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> References: <68c923fc-4dba-48dc-80c1-002ff764f7d3@v25g2000yqk.googlegroups.com> Message-ID: <50697b2c0911040037w29b4cb0bif518ef6efe458aa3@mail.gmail.com> On Wed, Nov 4, 2009 at 12:04 AM, Lorenzo Di Gregorio wrote: > Hello, > > I thought that I could zero-pad a floating point number in 'print' by > inserting a zero after '%', but this does not work. > > I get: > > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > > How can I get print (in a simple way) to print 03.50? >>> print ("%.2f" % 3.5).zfill(5) 03.50 >>> print ("%5.2f" % 3.5).replace(' ','0') 03.50 Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 4 03:49:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 00:49:31 -0800 Subject: python compare and process a csv file In-Reply-To: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> References: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Message-ID: <50697b2c0911040049w16cf0611iaab7695be61b8048@mail.gmail.com> On Tue, Nov 3, 2009 at 7:43 AM, Siva Subramanian wrote: > Hello all, > > I am new on this list and computer programming > > I have two distinct statistical files (both csv) > > 1.?????? Report_2_5 ? this is a report dump containing over a 10 million records and is different every day > > 2.?????? Customer_id dump ? this is a daily dump of customers who have made payments. This is generally a million record > > I need to extract past history depending on customers who make regular payments > > For example, > > Report_2_5 > > Customer ID, Plan_NO, stat1, vol2, amount3 > 2134, Ins1, 10000, 20000, 10 > 2112, Ins3, 30000, 20000, 10 > 2121, Ins3, 30000, 20000, 10 > 2145, Ins2, 15000, 10000, 5 > 2245, Ins2, 15000, 10000, 5 > 0987, Ins1, 10000, 20000, 10 > > 4546, Ins1, 10020, 21000, 10 > > 6757, Ins1, 10200, 22000, 10 > ? > > customer_id dump > > > 0987 > > 4546 > > 6757 > > 2134 > > I need to process the Report_2_5 and extract the following output > > Stat1: 40220 > Vol2 : 83000 > Amount3 : 40 > > I am new to programming and I have been extracting this data using MS ? Access and I badly need a better solution. Have you considered using a proper SQL database? (See http://en.wikipedia.org/wiki/SQL ; MySQL is one example: http://en.wikipedia.org/wiki/MySQL) Mucking around with CSV files like this is basically doing the work of some simple SQL queries, only in an ad-hoc, inefficient manner. (MS Access is essentially a non-industrial-strength SQL for non-programmers.) Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Wed Nov 4 04:38:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 04 Nov 2009 06:38:50 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 04:50:42 -0300, Alf P. Steinbach escribi?: > * Gabriel Genellina: >> I don't understand either. R1 and R2 have *different* semantics. > > Assume that they have the very exact same semantics -- like two TV > sets that look the same and work the same except when you open 'em up > and poke around in there, oh holy cow, in this one there's stuff that > isn't in the other. > >> They don't behave the same. > > Assume that they do -- except when you go poking into the innards. And the problem is...? That the internal details are different? Who cares? (I'm lost now.) -- Gabriel Genellina From highcar at gmail.com Wed Nov 4 04:39:36 2009 From: highcar at gmail.com (elca) Date: Wed, 4 Nov 2009 01:39:36 -0800 (PST) Subject: join , split question Message-ID: <26193334.post@talk.nabble.com> Hello, i have some text file list such like following format. i want to change text format to other format. i was upload it pastebin site http://elca.pastebin.com/d71261168 if anyone help ,much appreciate thanks in advance -- View this message in context: http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html Sent from the Python - python-list mailing list archive at Nabble.com. From alfps at start.no Wed Nov 4 04:45:51 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 10:45:51 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > En Wed, 04 Nov 2009 04:50:42 -0300, Alf P. Steinbach > escribi?: > >> * Gabriel Genellina: >>> I don't understand either. R1 and R2 have *different* semantics. >> >> Assume that they have the very exact same semantics -- like two TV >> sets that look the same and work the same except when you open 'em up >> and poke around in there, oh holy cow, in this one there's stuff that >> isn't in the other. > >> >>> They don't behave the same. >> >> Assume that they do -- except when you go poking into the innards. > > And the problem is...? > That the internal details are different? Who cares? > (I'm lost now.) It's a common Usenet phenomenon: the warping thread. Context is lost. It is available by going back up-thread but at the cost of some work. :-) Cheers & hth., - Alf From __peter__ at web.de Wed Nov 4 05:22:04 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Nov 2009 11:22:04 +0100 Subject: python compare and process a csv file References: <20091103154320.34619.qmail@f6mail-144-200.rediffmail.com> Message-ID: Chris Rebert wrote: > On Tue, Nov 3, 2009 at 7:43 AM, Siva Subramanian > wrote: >> Hello all, >> >> I am new on this list and computer programming >> >> I have two distinct statistical files (both csv) >> >> 1. Report_2_5 ? this is a report dump containing over a 10 million >> records and is different every day >> >> 2. Customer_id dump ? this is a daily dump of customers who have >> made payments. This is generally a million record >> >> I need to extract past history depending on customers who make regular >> payments >> >> For example, >> >> Report_2_5 >> >> Customer ID, Plan_NO, stat1, vol2, amount3 >> 2134, Ins1, 10000, 20000, 10 >> 2112, Ins3, 30000, 20000, 10 >> 2121, Ins3, 30000, 20000, 10 >> 2145, Ins2, 15000, 10000, 5 >> 2245, Ins2, 15000, 10000, 5 >> 0987, Ins1, 10000, 20000, 10 >> >> 4546, Ins1, 10020, 21000, 10 >> >> 6757, Ins1, 10200, 22000, 10 >> ? >> >> customer_id dump >> >> >> 0987 >> >> 4546 >> >> 6757 >> >> 2134 >> >> I need to process the Report_2_5 and extract the following output >> >> Stat1: 40220 >> Vol2 : 83000 >> Amount3 : 40 >> >> I am new to programming and I have been extracting this data using MS ? >> Access and I badly need a better solution. > > Have you considered using a proper SQL database? (See > http://en.wikipedia.org/wiki/SQL ; MySQL is one example: > http://en.wikipedia.org/wiki/MySQL) > Mucking around with CSV files like this is basically doing the work of > some simple SQL queries, only in an ad-hoc, inefficient manner. (MS > Access is essentially a non-industrial-strength SQL for > non-programmers.) Industrial strength or not, Access should be capable of solving the OP's problem. So it would be interesting what's so bad about it in this case. Anyway, here's a database-free python solution: import csv REPORT = "report.csv" CUSTOMERS = "customers.csv" with open(CUSTOMERS) as instream: next(instream) # skip header # put customer ids into a set for fast lookup customer_ids = set(line.strip() for line in instream) with open(REPORT) as instream: rows = csv.reader(instream) # find columns headers = [column.strip() for column in rows.next()] customer_column = headers.index("Customer ID") sum_over_columns = [headers.index(s) for s in "stat1 vol2 amount3".split()] # initialize totals sigma = [0] * len(headers) # calculate totals for row in rows: if row[customer_column] in customer_ids: for index in sum_over_columns: sigma[index] += int(row[index]) # print totals for index in sum_over_columns: print "%-10s %10d" % (headers[index] + ":", sigma[index]) The limiting factor for this approach is the customer_ids set which at some point may no longer fit into memory. Peter From mark.leander at topicbranch.net Wed Nov 4 05:28:41 2009 From: mark.leander at topicbranch.net (Mark Leander) Date: Wed, 4 Nov 2009 02:28:41 -0800 (PST) Subject: import bug References: Message-ID: On Oct 31, 5:12 pm, kj wrote: > I give up: what's the trick? (Of course, renaming ham/re.py is > hardly "the trick." It's rather Procrustes' Bed.) I realize that this is probably not the answer you were looking for, but: $ python -m ham.spam or ==> ./spammain.py <== import ham.spam $ python spammain.py I've found it easier to not fight the module/package system but work with it. But yes, I also think the problem you're seeing is a wart or bug even. Best regards Mark Leander From jspies at sun.ac.za Wed Nov 4 05:36:01 2009 From: jspies at sun.ac.za (Johann Spies) Date: Wed, 4 Nov 2009 12:36:01 +0200 Subject: using csv dictreader in python In-Reply-To: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> References: <2354c1c50911032355g43e13402i946429a97d7c5d4f@mail.gmail.com> Message-ID: <20091104103601.GI16847@sun.ac.za> On Wed, Nov 04, 2009 at 01:25:16PM +0530, Siva Subramanian wrote: > This only gets me the following output > > {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': > '4001433', 'FieldName4': '759'} > > 1. How do i access the 4, 0.00, ... the values ? >>> a= {'FieldName1': '4', 'FieldName2': '0.00', 'FieldName3': '4001433', 'FieldName4': '759'} >>> a {'FieldName4': '759', 'FieldName1': '4', 'FieldName3': '4001433', 'FieldName2': '0.00'} >>> a['FieldName3'] '4001433' > 2. How do i compare it with another csv file ? If you have the values in one file, get the values in the other one and then compare. I am not sure I understand what is the problem here. Regards Johann -- Johann Spies Telefoon: 021-808 4599 Informasietegnologie, Universiteit van Stellenbosch "Train up a child in the way he should go: and when he is old, he will not depart from it." Proverbs 22:6 From robin at reportlab.com Wed Nov 4 05:49:00 2009 From: robin at reportlab.com (Robin Becker) Date: Wed, 04 Nov 2009 10:49:00 +0000 Subject: restricted mode??? Message-ID: <4AF15C1C.5090200@chamonix.reportlab.co.uk> A reportlab user running via mod_python+django (Python 2.5.2 and mod_python 3.3.1) reports a strange intermittent error involving failure to read files which are known to be present. After some debugging efforts we got this clearer error message File "/usr/lib/python2.5/site-packages/reportlab/lib/utils.py", line 810, in dump f = open(self.fn,'wb') IOError: file() constructor not accessible in restricted mode this is not the original error, but part of our efforts to debug; however, the original error was during an attempt to read a file so presumably open was not available there. Googling the error indicates something to do with restricted environments/mod_python+threads. I thought that restricted mode died ages ago. Any ideas what could be causing this? -- Robin Becker From dickinsm at gmail.com Wed Nov 4 06:14:55 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 4 Nov 2009 03:14:55 -0800 (PST) Subject: unable to compile Python 2.6.4 on AIX using gcc References: Message-ID: On Nov 3, 10:40?pm, chuck wrote: > Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX > 5.3. ?Here are the settings: > > export OBJECT_MODE=64 > export AR="ar -X64" > export MAKE=/usr/bin/gmake > export CC="gcc" > export CFLAGS="-maix64 -O2 -g -mcpu=power5" > export LDFLAGS="-L/usr/lib64 -L/opt/freeware/lib64 > -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" > export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" > ../Python-2.6.4/configure --with-gcc --disable-ipv6 > --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 > make > make_264.log 2>&1 > > make fails very early with the following error > > =========== > > ? ? ? ? ?gcc -pthread -c -fno-strict-aliasing -DNDEBUG -O3 -Wall > -Wstrict-prototypes ?-I. -IInclude -I../Python-2.6.4/Includ > e -I/opt/freeware/include -I/usr/lpp/X11/include/X11 ?-DPy_BUILD_CORE -o > Modules/python.o ../Python-2.6.4/Modules/python.c > In file included from ../Python-2.6.4/Include/Python.h:58, > ? ? ? ? ? ? ? ? ? from ../Python-2.6.4/Modules/python.c:3: > ../Python-2.6.4/Include/pyport.h:685:2: error: #error "LONG_BIT > definition appears wrong for platform (bad gcc/glibc config > ?)." > make: The error code from the last command is 1. > =========== > > I would appreciate any help. Thanks. Take a look at: http://bugs.python.org/issue1628484 Mark From vesa.koppa at gmail.com Wed Nov 4 06:21:48 2009 From: vesa.koppa at gmail.com (=?ISO-8859-1?Q?Vesa_K=F6pp=E4?=) Date: Wed, 04 Nov 2009 13:21:48 +0200 Subject: comparing alternatives to py2exe In-Reply-To: <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> Message-ID: <4af163cc$0$6279$4f793bc4@news.tdc.fi> iu2 wrote: > Another thing that I think is of interest is whether the application > support modifying the version and description of the exe (that is, on > Windows, when you right-click on an application and choose > 'properties' you view the version number and description of the > application, it is a resource inside the exe). I think py2exe supports > it. Pyinstaller supports this. Vesa From jebagnanadas at gmail.com Wed Nov 4 06:37:19 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Wed, 4 Nov 2009 17:07:19 +0530 Subject: problem in installing wxwidgets for python.. Message-ID: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> Hello friends, I've tried to install wxwidgets in my mandriva 2009 spring for GUI interaction with python. In the installation instruction it said that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got the message checking for BASE_DEPENDENCIES... configure: error: Package requirements (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were not met: Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables BASE_DEPENDENCIES_CFLAGS and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I installed all the packages using the following commands. tar xvzf filename.tar.gz cd folder ./configure make make install I've not specified anf options like --prefix and i installed in the folder itself. when i tried to install gtk+ after installing all this it showed the same error. What should i do to install wxwidgets? Plz. reply as soon as possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Nov 4 06:43:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Nov 2009 05:43:30 -0600 Subject: substituting list comprehensions for map() In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <4AF168E2.8080203@tim.thechases.com> Steven D'Aprano wrote: > On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: >> Or use the appropriate libraries: >> >> from numpy import dot >> >> scalar = dot(vec1, vec2) > > > Why would I want to use an already existing library that is fast, well- > written and well-supported, when I can toss together a nasty kludge > myself? because you want to perform a dot-product on strings? >>> dot_product(['a', 'b', 'c'], [2,3,4]) 'aabbbcccc' [grins, ducks and scampers away after the sum-shouldn't-special-case-strings-with-an-error thread] -tkc From ben+python at benfinney.id.au Wed Nov 4 07:08:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Nov 2009 23:08:54 +1100 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <87aaz2ebl5.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: > > from numpy import dot > > > > scalar = dot(vec1, vec2) > > Why would I want to use an already existing library that is fast, > well- written and well-supported, when I can toss together a nasty > kludge myself? Because using that library will ensure you can't migrate to Python 3 any time soon? *rimshot* -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From ishwor.gurung at gmail.com Wed Nov 4 07:11:39 2009 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Wed, 4 Nov 2009 23:11:39 +1100 Subject: problem in installing wxwidgets for python.. In-Reply-To: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> References: <5ff1e7d40911040337l4ee8c0a0n39bb11f7939ff197@mail.gmail.com> Message-ID: <34534aed0911040411r73595b14gbe436fe09436f99d@mail.gmail.com> Hi, 2009/11/4 Jebagnana Das : > Hello friends, > ????????????????? I've tried to install wxwidgets in my mandriva 2009 spring > for GUI interaction with python. In the installation instruction it said > that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got > the message You probably want wxpython binding instead - http://www.wxpython.org/ Use binaries provided by Mandriva's package manager where possible unless you _really_ want to do a source installation. > checking for BASE_DEPENDENCIES... configure: error: Package requirements > (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were > not met: > > > Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 > > Consider adjusting the PKG_CONFIG_PATH environment variable if you > installed software in a non-standard prefix. $ export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig (considering that your local installs went to those directories. Try replacing those directories accordingly for glib, atk, pango and cairo). The files you're after is a ".pc" (pkg-config need them) file. A quick find will tell you where it is if it is installed. Run configure script again. > Alternatively, you may set the environment variables > BASE_DEPENDENCIES_CFLAGS > > and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. > See the pkg-config man page for more details. > > Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I > installed all the packages using the following commands. [...] > tar xvzf filename.tar.gz > cd folder > ./configure > > make > make install Yep. Check where it installed them one by one. In short, you need access to a ".pc" file that they provide. If not, write one yourself. > I've not specified anf options like --prefix and i installed in the folder > itself. man pkg-config for further info. > when i tried to install gtk+ after installing all this it showed the same > error. What should i do to install wxwidgets? Plz. reply as soon as > possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... See above. -- Regards, Ishwor Gurung From davea at ieee.org Wed Nov 4 07:13:14 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 04 Nov 2009 07:13:14 -0500 Subject: Handling large datastore search In-Reply-To: <61e270bc0911032257v69ae584ak82ee461c6ae362dc@mail.gmail.com> References: <61e270bc0911030621w14069f1fk58f2ab7fe1d78c57@mail.gmail.com> <4AF0BC76.4090908@ieee.org> <61e270bc0911032257v69ae584ak82ee461c6ae362dc@mail.gmail.com> Message-ID: <4AF16FDA.7060107@ieee.org> (This reply was offline, but I forwarded parts so that others with Google App Engine experience might jump in) Ahmed Barakat wrote: > > .... but I was trying to make use of everything provided by App engine. > > > > On Wed, Nov 4, 2009 at 1:27 AM, Dave Angel wrote: > > >> Ahmed Barakat wrote: >> >> >>> In case I have a huge datastore (10000 entries, each entry has like 6 >>> properties), what is the best way >>> to handle the search within such a huge datastore, and what if I want to >>> make a generic search, for example >>> you write a word and i use it to search within all properties I have for >>> all >>> entries? >>> >>> Is the conversion to XML a good solution, or it is not? >>> >>> sorry for being new to web development, and python. >>> >>> Thanks in advance. >>> >>> >>> >>> >> I don't see anything about your query which is specific to web development, >> and there's no need to be apologetic for being new anyway. >> >> One person's "huge" is another person's "pretty large." I'd say 10000 >> items is pretty small if you're working on the desktop, as you can readily >> hold all the data in "memory." I edit text files bigger than that. But >> I'll assume your data really is huge, or will grow to be huge, or is an >> environment which treats it as huge. >> >> When you're parsing large amounts of data, there are always tradeoffs >> between performance and other characteristics, usually size and complexity. >> If you have lots of data, you're probably best off by using a standard code >> system -- a real database. The developers of such things have decades of >> experience in making certain things fast, reliable, and self-consistent. >> >> But considering only speed here, I have to point out that you have to >> understand databases, and your particular model of database, pretty well to >> really benefit from all the performance tricks in there. Keeping it >> abstract, you specify what parts of the data you care about fast random >> access to. If you want fast search access to "all" of it, your database >> will generally be huge, and very slow to updates. And the best way to avoid >> that is to pick a database mechanism that best fits your search mechanism. >> I hate to think how many man-centuries Google has dedicated to getting fast >> random word access to its *enormous* database. I'm sure they did not build >> on a standard relational model. >> >> If you plan to do it yourself, I'd say the last thing you want to do is use >> XML. XML may be convenient way to store self-describing data, but it's not >> quick to parse large amounts of it. Instead, store the raw data in text >> form, with separate index files describing what is where. Anything that's >> indexed will be found rapidly, while anything that isn't will require search >> of the raw data. >> >> There are algorithms for searching raw data that are faster than scanning >> every byte, but a relevant index will almost always be faster. >> >> DaveA >> >> >> Clearly, you left a few things out of your original query. Now that you mention App Engine, I'm guessing you meant Google's Datastore and that this whole query is about building a Google app. So many of my comments don't apply, because I was talking about a desktop environment, using (or not using) a traditional (relational) database. I've never used Google's AppEngine, and never done a database web-app. So I'm the wrong person to give more than general advice. Google's Datastore is apparently both more and less powerful than a relational database, and web apps have very different tradeoffs. So you need to respecify the problem, giviing the full requirements first, and maybe somebody with more relevant experience will then respond. Meanwhile, try the following links, and see if any of them help. http://code.google.com/appengine/docs/ http://code.google.com/appengine/docs/whatisgoogleappengine.html http://code.google.com/appengine/docs/datastore/ http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html http://snarfed.org/space/datastore_talk.html http://video.google.com/videosearch?q=app+engine+data+store&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&ei=uGjxSrX-HcPp8Qbb2uWACQ&sa=X&oi=video_result_group&ct=title&resnum=11&ved=0CDIQqwQwCg DaveA From fetchinson at googlemail.com Wed Nov 4 07:17:51 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 4 Nov 2009 13:17:51 +0100 Subject: Pyfora, a place for python In-Reply-To: <4AF0959D.2020307@stoneleaf.us> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> <4AF0959D.2020307@stoneleaf.us> Message-ID: >>>>I was referring to this comment by Ben: >>>> >>>>"Suggestion: Please don't make efforts to fragment the community." >>>> >>>>This IMHO is hostile, because it presupposes that the mere goal of the >>>>OP is fragmenting the community >>> >>>It presupposes nothing of any goal. It describes a predictable result of >>>the OP's efforts, and requests those efforts to cease. >>> >>>So I deny the characterisation of that request as hostile. >> > > [mass snippitude] > >> If yes, with the substitution A = Ben and B = OP we get "in order for >> Ben's request to make sense, Ben has to assume that the OP is making >> an effort to fragment the community". This assumption on the part of >> Ben, I think, is hostile, since it assumes that the OP is making an >> effort to do something not nice. Whether the OP is indeed doing >> something not nice, is irrelevant. If the OP does do something not >> nice, the hostility is warranted. If the OP is not doing anything not >> nice, the hostility is unwarranted. But the fact that Ben was hostile >> is a fact :) > > You were doing fine until you brought in the hostility. I must agree > with Ben that his comment was not hostile. It was merely a statement. > Not an exclamation, no name calling, just a plain request rooted in reality. Okay, before we get to quarks let's see what 'hostile' means :) >From Merriam-Webster http://www.learnersdictionary.net/dictionary/hostile : 1 a : of or relating to an enemy b : marked by malevolence c : openly opposed or resisting d (1) : not hospitable (2) : having an intimidating, antagonistic, or offensive nature Now, I think the OP was perceived by Ben as doing something which he thinks is not good. We most probably agree on this. In other words, Ben was opposing the OP's ideas. Yet in other words, Ben was resisting the OP's ideas. And yet in other words, Ben was not hospitable. So perhaps 1a and 1b doesn't quite fit the bill since Ben didn't go as far as call the OP an enemy and he wasn't evil or wished harm to the OP, but 1c and d(1) are certainly correctly describing his behavior and to a lesser extent d(2) as well. And the quarks...... :) Cheers, Daniel > And that's a fact. ;-) > > Shall we now discuss the nature of the space/time continuum and the > exact reality of quarks? -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Nov 4 07:19:36 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 4 Nov 2009 13:19:36 +0100 Subject: Pyfora, a place for python In-Reply-To: <02fff632$0$1326$c3e8da3@news.astraweb.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: >>> Hi everyone, >>> >>> I am proud to announce the release of Pyfora (http://pyfora.org), an >>> online community of Python enthusiasts to supplement comp.lang.python >>> and #python. While the site is small right now, please feel free to >>> register and post any questions or tips you may have. >> >> I'll feel free to not even bookmark it. I'm sorry, but it is just a bad >> idea. >> >> Your forum cannot (and should not) compete either with Python's official >> newsgroup, IRC channel and mailing list or with popular, well- made and >> well-frequented general programming sites like stackoverflow.com. > > Are you saying that now that comp.lang.python and stackoverflow exists, > there no more room in the world for any more Python forums? Exactly. > I think that's terrible. Exactly. > Saketh, would you care to give a brief explanation for sets your forum > apart from the existing Python forums, and why people should choose to > spend time there instead of (or as well as) the existing forums? What > advantages does it have? Yes, this is about the right kind of response I think everybody deserves who puts energy/enthusiasm/effort/time into putting together a python-related forum. Cheers, Daniel >> It would be the Internet equivalent of looking for a poker tournament in >> a desert valley instead of driving half an hour less and going to Las >> Vegas: there are no incentives to choose your forum, except perhaps for >> isolationists who value being a big fish in a small pond over being part >> of a community. > > (Funny you mention Las Vegas -- it started off as a tiny little town in > the middle of the desert too.) > > How about avoiding the noise and obtrusive advertising and bright lights > of Las Vegas, the fakery, the "showmanship", the horrible fake pyramid > and has-been celebrities, the crowds, the tackiness, the high prices, the > bright lights that never turn off (Las Vegas is the brightest city on > Earth)... if you're interested in poker without all the mayonnaise, maybe > that poker tournament away from the tourists is exactly what you need. > > Personally, if I wanted to gamble, the last place I would go is any house > which had gold-plated taps in the bathrooms. That tells me the house's > percentage is *way* too high. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From captntoad at galaxy42.net Wed Nov 4 07:59:57 2009 From: captntoad at galaxy42.net (Todd Lovette) Date: Wed, 04 Nov 2009 05:59:57 -0700 Subject: python 3.1.1 and --libdir option broken. Message-ID: <4AF17ACD.8000804@galaxy42.net> I've been trying to install Python 3.1.1 into /usr/lib64 via the configure script option --libdir, but it is ignored and Python 3.1.1 is installed in /usr/lib. Has anyone ran into this problem and solved it? Looking at the Makefile is seems as thought /lib in hard coded into the file. Any suggestions to fix this? Todd :-) From dotancohen at gmail.com Wed Nov 4 08:29:50 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 4 Nov 2009 15:29:50 +0200 Subject: Pyfora, a place for python In-Reply-To: <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <262EC99C-8C1E-4872-B992-9DCA2994A26F@kagi.com> Message-ID: <880dece00911040529o7c379535qc45f451396e0767d@mail.gmail.com> > My personal preference would be a link in each sub-paragraph in the official > documentation to a wiki page devoted to that specific aspect of the Python > language. A place were users could augment the documentation by providing > sample code and by expanding out the documentation for those of us who don't > live and breath Python in our sleep. Real Python coders would not click on > the user wiki links and all of us newbies could communicate with each other. > But until a place like that exists, perhaps Pyfora will get us part way > there. > The PHP documentation has this feature: user comments right on the same page (no link to a wiki, though). It's great, most of the best usage practices that I have learned in that language came from the user's comments, not from the official documentation itself. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From no.email at please.post Wed Nov 4 08:33:53 2009 From: no.email at please.post (kj) Date: Wed, 4 Nov 2009 13:33:53 +0000 (UTC) Subject: How to test urllib|urllib2-using code? Message-ID: I want to write some tests for code that uses both urllib and urllib2. I would like to be able to run these tests locally. Are there modules to facilitate the writing of such tests (e.g. for setting up a mock web server locally, etc.)? BTW, in the Perl world, one very easy way to learn how to write tests for stuff is to study the test suites that come with every module distribution, and which are usually readily recognizable as a bunch of files of the form t/*.t. (E.g. I'm sure I could find some good answers to my question above if I could look at the test suites for urllib and urllib2, but I can't find them anywhere. In fact, I don't even know what exactly I should be looking for.) Where can I find the equivalent for Python distributions? Thanks! kynn From stefan_ml at behnel.de Wed Nov 4 08:35:30 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 04 Nov 2009 14:35:30 +0100 Subject: elementtree XML() unicode In-Reply-To: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> References: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> Message-ID: <4af18322$0$7620$9b4e6d93@newsspool1.arcor-online.net> John Machin, 04.11.2009 02:56: > On Nov 4, 12:14 pm, Kee Nethery wrote: >> The reason I am confused is that getResponse2 is classified as an >> "str" in the Komodo IDE. I want to make sure I don't lose the non- >> ASCII characters coming from the URL. > > str is all about 8-bit bytes. True in Py2.x, false in Py3. What you mean is the "bytes" type, which, sadly, was named "str" in Python 2.x. The problem the OP ran into was due to the fact that Python 2.x handled "ASCII characters in a unicode string" <-> "ASCII encoded byte string" conversion behind the scenes, which lead to all sorts of trouble to loads of people, and was finally discarded in Python 3.0. Stefan From stefan_ml at behnel.de Wed Nov 4 08:41:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 04 Nov 2009 14:41:52 +0100 Subject: How do I install libxml2 and libxslt? In-Reply-To: References: Message-ID: <4af184a0$0$7621$9b4e6d93@newsspool1.arcor-online.net> Kevin Ar18, 02.11.2009 21:44: >> According to the lxml installation instructions you linked=2C >> the windows lxml binary is statically linked and you do not >> need to install the libraries separately. > > The install instructions say" "You need libxml2 and libxslt" and then links= > to where to download the binaries=3B this means I need to install separate= > ly=2C right? If not=2C those are aweful instructions. :) Not being able to scroll down half a page (to the section titled "MS Windows") is not an excuse for blaming the docs. > I can download the binaries=2C but I don't know where or how to install the= > m? Is there any instructions anywhere? Yes, see the short section titled "Installation" at the top of the installation instructions page. Stefan From henning.bredel at gmx.de Wed Nov 4 08:52:51 2009 From: henning.bredel at gmx.de (Henning Bredel) Date: 04 Nov 2009 13:52:51 GMT Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4af18733$0$6591$9b4e6d93@newsspool3.arcor-online.net> Gabriel, thanks for your reply. See my comments below. On Tue, 03 Nov 2009 21:31:27 -0300, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel > escribi?: >> On Tue, 03 Nov 2009 10:18:29 +0000, Steven D'Aprano wrote: > > Then forget about the code you read in that blog post, doesn't apply to > your use case. Well, but it shows how to mount plugins into the application without creating instances instantly. I only use one plugin/module at a time, so I'd like to avoid holding instances which aren't used. If the solution from the blogpost are meant completely different, I'd appreciate if you could point me on some concrete arguments why I shouldn't realize plugin mechanism in that way. BTW: I made it work now (was only a(nother) misinterpretation of how a callable should look like. > Try something like this: [...] > class PluginManager: > def __init__(self, plugin_directory): > self.plugin_directory = plugin_directory self.plugins = [] > > def load_all(self): > for fn in glob(os.path.join(self.plugin_directory, '*.py')): > namespace = {} > execfile(fn, namespace) > for name, obj in namespace.items(): > if (isinstance(obj, type) and > issubclass(obj, Plugin) and > obj is not Plugin): > # obj is a Plugin subclass > cls = obj > print cls.__name__, fn > print cls.__doc__ > print > plugin = cls(self) # call the constructor > self.plugins.append(plugin) [...] Yes, I get your point. But you instantiate all available plugins. I'd like to avoid that. Will a callable like `plugin().initialize' avoid that, or is an instance created immediately when passing this callable? > Plugin is the base class; all plugins must inherit from it. PluginMgr > scans the plugin directory, executes all modules it finds there (be > careful...), and looks for Plugin subclasses. Then creates an instance > of each Plugin subclass. Well, as far I understand it, I'd say that the ActionProvider class from the blogpost is the (nearly) the same as your Plugin base class. All new plugins has to implement the abstract ActionProvider class. The module loading/recognizing is done by my main application. So what would be the main difference here? Thanks for your advice Henning From mrkafk at gmail.com Wed Nov 4 09:00:38 2009 From: mrkafk at gmail.com (mk) Date: Wed, 04 Nov 2009 15:00:38 +0100 Subject: Request for comments - concurrent ssh client Message-ID: Hello everyone, Since I'm not happy with shmux or pssh, I wrote my own "concurrent ssh" program for parallel execution of SSH commands on multiple hosts. Before I release program to the wild, I would like to hear (constructive) comments on what may be wrong with the program and/or how to fix it. (note: the program requires paramiko ssh client module) #!/usr/local/bin/python -W ignore::DeprecationWarning import time import sys import os import operator import paramiko import threading import subprocess import optparse usage = "Usage: cssh [options] IP1 hostname2 IP3 hostname4 ...\n\n(IPs/hostnames on the commandline are actually optional, they can be specified in the file, see below.)" op = optparse.OptionParser(usage=usage) op.add_option('-c','--cmd',dest='cmd',help="""Command to run. Mutually exclusive with -s.""") op.add_option('-s','--script',dest='script',help="""Script file to run. Mutually exclusive with -c. Script can have its own arguments, specify them in doublequotes, like "script -arg arg".""") op.add_option('-i','--script-dir',dest='scriptdir',help="""The directory where script will be copied and executed. Defaults to /tmp.""") op.add_option('-l','--cleanup',dest='cleanup',action='store_true',help="""Delete the script on remote hosts after executing it.""") op.add_option('-f','--file',dest='file',help="""File with hosts to use, one host per line. Concatenated with list of hosts/IP addresses specified at the end of the commandline. Optionally, in a line of the file you can specify sequence: "Address/Hostname Username Password SSH_Port" separated by spaces (additional parameters can be specified on a subset of lines; where not specified, relevant parameters take default values).""") op.add_option('-d','--dir',dest='dir',help='Directory for storing standard output and standard error of command. If specified, directory will be created, with subdirs named IPs/hostnames and relevant files stored in those subdirs.') op.add_option('-u','--username',dest='username',help="""Username to specify for SSH. Defaults to 'root'.""") op.add_option('-p','--password',dest='password',help="""Password. Password is used first; if connection fails using password, cssh uses SSH key (default or specified).""") op.add_option('-o','--port',dest='port',help="""Default SSH port.""") op.add_option('-k','--key',dest='key',help="""SSH Key file. Defaults to '/root/.ssh/id_dsa'.""") op.add_option('-n','--nokey',dest='nokey',action="store_true", help="""Turns off using SSH key.""") op.add_option('-t','--timeout',dest='timeout',help="""SSH connection timeout. Defaults to 20 seconds.""") op.add_option('-m','--monochromatic',dest='mono',action='store_true',help="""Do not use colors while printing output.""") op.add_option('-r','--maxthreads',dest='maxthreads',help="""Maximum number of threads working concurrently. Default is 100. Exceeding 200 is generally not recommended due to potential exhaustion of address space (each thread can use 10 MB of address space and 32-bit systems have a maximum of 4GB of address space).""") op.add_option('-q','--quiet',dest='quiet',action='store_true',help="""Quiet. Do not print out summaries like IPs for which communication succeeded or failed, etc.""") # add resource file? (opts, args) = op.parse_args() failit = False if opts.cmd == None and opts.script == None: print "You have to specify one of the following: command to run, using -c command or --cmd command, or script to run, using -s scriptfile or --script scriptfile." print failit = True if opts.cmd != None and opts.script != None: print "Options command (-c) and script (-s) are mutually exclusive. Specify either one." print failit = True if opts.cmd == None and opts.script != None: try: scriptpath = opts.script.split()[0] scriptfo = open(scriptpath,'r') scriptfo.close() except IOError: print "Could not open script file %s." % opts.script print failit = True if opts.file == None and args == []: print "You have to specify at least one of the following:" print " - list of IPs/hostnames at the end of the command line (after all options)" print " - list of IPs/hostnames stored in file specified after -f or --file option (like: -f hostnames.txt)" print " You can also specify both sources. In that case IP/hostname lists will be concatenated." print failit = True if opts.password == None and opts.nokey: print "Since using key has been turned off using -n option, you have to specify password using -p password or --password password." print failit = True if opts.key is not None and opts.nokey: print "Options -n and -k keyfile are mutually exclusive. Specify either one." print failit = True if failit: sys.exit(0) if opts.scriptdir == None: opts.scriptdir = '/tmp' if opts.cleanup == None: opts.cleanup = False if opts.key == None: opts.key = '/root/.ssh/id_dsa' if opts.port == None: opts.port = 22 if opts.nokey: opts.key = None if opts.timeout == None: opts.timeout = 20 if opts.mono == None: opts.mono = False if opts.maxthreads == None: opts.maxthreads = 100 if opts.quiet == None: opts.quiet = False HEADER = '\033[95m' BLACK = '\033[30m' RED = '\033[31m' GREEN = '\033[32m' YELLOW = '\033[33m' BLUE = '\033[34m' OKBLUE = '\033[94m' MAGENTA = '\033[35m' CYAN = '\033[36m' WHITE = '\033[37m' ENDC = '\033[0m' if opts.mono: HEADER = BLACK = RED = GREEN = YELLOW = OKBLUE = BLUE = MAGENTA = CYAN = WHITE = ENDC = '' hosts = args[:] fhosts = [] fname = opts.file if fname is not None: try: fhosts = open(fname).readlines() except IOError, e: print "Error:", str(e) sys.exit(1) hosts.extend(fhosts) hosts = [ s.strip() for s in hosts if s != '' and s != None and s != '\n' ] hosts = [ s.split() for s in hosts ] if hosts == []: print "Error: list of hosts is empty. Quitting" sys.exit(1) class SSHThread(threading.Thread): def __init__(self, lock, cmd, ip, username, sshprivkey=None, passw=None, port=22, script=None, scriptdir=None): threading.Thread.__init__(self) self.lock = lock self.cmd = cmd self.ip = ip self.username = username self.sshprivkey = sshprivkey self.passw = passw self.port = port self.conobj = None self.confailed = True if script != None: scriptcomp = script.strip().split() self.scriptpath = scriptcomp[0] self.scriptname = self.scriptpath.split('/')[-1] self.scriptargs = script[len(scriptpath):] self.scriptdir = scriptdir.strip().rstrip('/') self.rspath = self.scriptdir + '/' + self.scriptname self.finished = False def ping(self, lock, ip): subp = subprocess.Popen(['/bin/ping', '-c', '1', ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) so, se = subp.communicate() return (so, se) def ssh_connect(self): self.conobj = paramiko.SSHClient() aap = paramiko.AutoAddPolicy() self.conobj.set_missing_host_key_policy(aap) loginsuccess = False if self.passw is not None: try: self.conobj.connect(self.ip, username=self.username, password=self.passw, port=self.port, timeout=opts.timeout, allow_agent=False, look_for_keys = False) loginsuccess = True except: pass if not loginsuccess and self.sshprivkey is not None: try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except: pass if not loginsuccess: self.conobj = None self.finished = True def execcmds(self): so = se = '' try: si, so, se = self.conobj.exec_command(self.cmd) sol = so.readlines() sel = se.readlines() so = ''.join([ s.replace('\r\n','\n') for s in sol ]) se = ''.join([ s.replace('\r\n','\n') for s in sel ]) except: pass return (so, se) def sendscript(self): fo = open(self.scriptpath,'rb') cnt = ''.join(fo.readlines()) transport = self.conobj.get_transport() channel = transport.open_session() destpath = self.scriptdir + '/' + self.scriptname try: channel.exec_command('scp -t -v %s\n' % destpath) except paramiko.SSHException, e: channel.close() return str(e) fl = 'C0755 %d 1\n' % os.path.getsize(self.scriptpath) channel.send(fl) while not channel.recv_ready(): time.sleep(0.1) try: channel.send(cnt) except socket.error, e: channel.close() return str(e) channel.close() return '' def setcmdtoscript(self): self.cmd = self.scriptdir + '/' + self.scriptname + self.scriptargs def execcmdonscript(self, cmd): si, so, se = self.conobj.exec_command(cmd) sol = so.readlines() sel = se.readlines() if sol != [] or sel != []: self.lock.acquire() print RED + "Host %s, Error while executing %s on script:" % (self.ip, cmd), "".join(sel), "".join(sol) + ENDC self.lock.release() def chmodscript(self): # just in case, as sometimes and on some operating systems the execution flags on the script are not always set self.execcmdonscript('chmod 0755 %s' % self.rspath) def delscript(self): self.execcmdonscript('rm -f %s' % self.rspath) def run(self): self.ssh_connect() so, se = ('', '') res = '' if self.conobj != None: if self.cmd == None: res = self.sendscript() self.setcmdtoscript() self.chmodscript() if res == '': so, se = self.execcmds() if opts.cleanup: time.sleep(0.5) self.delscript() self.lock.acquire() print OKBLUE + "%-20s" % self.ip + ENDC, ":", if self.conobj == None: print RED + "SSH connection failed" + ENDC self.confailed = True elif res != '': print RED + "Sending script failed: %s" % res + ENDC self.confailed = True else: self.confailed = False print OKBLUE + "SSH connection successful" + ENDC print so if se != '': print MAGENTA + "command standard error output:" + ENDC print se if opts.dir != None: if not os.path.isdir(opts.dir): os.mkdir(opts.dir) path = opts.dir + os.sep + self.ip if not os.path.isdir(path): os.mkdir(path) of = open(path + os.sep + 'stdout','w') of.write(so) of.close() of = open(path + os.sep + 'stderr','w') of.write(se) of.close() self.lock.release() self.finished = True def sshclose(self): if self.conobj != None: self.conobj.close() lock = threading.Lock() queue = [] thfinished = [] def getparams(h): ip = h[0] try: username = h[1] except IndexError: username = opts.username try: passw = h[2] except IndexError: passw = opts.password port = None try: port = int(h[3]) except IndexError: port = 22 except ValueError, e: print RED + "%-20s" % ip, ": error converting port:", str(e) + ENDC return (ip, username, passw, port) while len(hosts) > 0: if len(queue) <= opts.maxthreads: h = hosts.pop() (ip, username, passw, port) = getparams(h) if port != None: th = SSHThread(lock, opts.cmd, ip, username=username, sshprivkey=opts.key, passw=passw, port=port, script=opts.script, scriptdir=opts.scriptdir) queue.append((ip, th)) th.daemon = True th.start() else: thfinished.append((ip,None)) else: time.sleep(1) for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) queue.remove((ip,th)) while len(queue) > 0: for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) queue.remove((ip,th)) time.sleep(1) if not opts.quiet: print print OKBLUE + 'Communication SUCCEEDED for following IP addresses (SSH could open connection):' + ENDC for ip, th in thfinished: if th != None and not th.confailed: print ip print print OKBLUE + 'Communication FAILED for following IP addresses (SSH could not open connection / error in parameters):' + ENDC for ip, th in thfinished: if th == None or th.confailed: print ip From s.selvamsiva at gmail.com Wed Nov 4 09:04:27 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Wed, 4 Nov 2009 19:34:27 +0530 Subject: how to remove the same words in the paragraph In-Reply-To: <4AF0B54A.7090602@tim.thechases.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote: > kylin wrote: > >> I need to remove the word if it appears in the paragraph twice. could >> some give me some clue or some useful function in the python. >> > > Sounds like homework. To fail your class, use this one: > > >>> p = "one two three four five six seven three four eight" > >>> s = set() > >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) > one two three four five six seven eight > > which is absolutely horrible because it mutates the set within the list > comprehension. The passable solution would use a for-loop to iterate over > each word in the paragraph, emitting it if it hadn't already been seen. > Maintain those words in set, so your words know how not to be seen. ("Mr. > Nesbitt, would you please stand up?") > > Can we use inp_paragraph.count(iter_word) to make it simple ? This also assumes your paragraph consists only of words and whitespace. But > since you posted your previous homework-sounding question on stripping out > non-word/whitespace characters, you'll want to look into using a regexp like > "[\w\s]" to clean up the cruft in the paragraph. Neither solution above > preserves non white-space/word characters, for which I'd recommend using a > re.sub() with a callback. Such a callback class might look something like > > >>> class Dedupe: > ... def __init__(self): > ... self.s = set() > ... def __call__(self, m): > ... w = m.group(0) > ... if w in self.s: return '' > ... self.s.add(w) > ... return w > ... > >>> r.sub(Dedupe(), p) > > where I leave the definition of "r" to the student. Also beware of > case-differences for which you might have to normalize. > > You'll also want to use more descriptive variable names than my one-letter > tokens. > > -tkc > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From lutz.horn at fastmail.fm Wed Nov 4 09:06:45 2009 From: lutz.horn at fastmail.fm (Lutz Horn) Date: Wed, 04 Nov 2009 15:06:45 +0100 Subject: How to test urllib|urllib2-using code? In-Reply-To: References: Message-ID: Hi, kj wrote: > I want to write some tests for code that uses both urllib and > urllib2. Take a look at the discussion under the title "How can one mock/stub python module like urllib" at stackoverflow: http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python-module-like-urllib Lutz From goon12 at gmail.com Wed Nov 4 09:08:12 2009 From: goon12 at gmail.com (Joe Riopel) Date: Wed, 4 Nov 2009 09:08:12 -0500 Subject: unittest & setup In-Reply-To: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> References: <6e8dae020911032002v223e1e85tf7af55f2c5eca0a0@mail.gmail.com> Message-ID: <6a2ccd190911040608o72f5a971lfd3ad73d6e74fa3f@mail.gmail.com> On Tue, Nov 3, 2009 at 11:02 PM, Jonathan Haddad wrote: > I've got a class, in the constructor it loads a CSV file from disc.? I'd > like only 1 instance of the class to be instantiated.? However, when running > multiple unit tests, multiple instances of the class are created.? What's > the best way for me to avoid this?? It takes about a few seconds to load the > CSV file. This post that might be worth reading, as it relates to testing with singletons. http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ As is this http://misko.hevery.com/code-reviewers-guide/ From ethan at stoneleaf.us Wed Nov 4 09:36:46 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Nov 2009 06:36:46 -0800 Subject: self.__dict__ tricks In-Reply-To: <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: <4AF1917E.5090806@stoneleaf.us> Dennis Lee Bieber wrote: > Perfectly valid answer -- there are no fish as there is no > Atlantic sea Steven D'Aprano wrote: > Once in the distant past, there were no fish in what would become the > Atlantic Ocean (not sea) What's with the bias against the word 'sea'? sea ?noun 1. the salt waters that cover the greater part of the earth's surface. 2. a division of these waters, of considerable extent, more or less definitely marked off by land boundaries: the North Sea. 3. one of the seven seas; ocean. I'd say the Atlantic qualifies! ;-) ~Ethan~ From james at agentultra.com Wed Nov 4 09:39:32 2009 From: james at agentultra.com (J Kenneth King) Date: Wed, 04 Nov 2009 09:39:32 -0500 Subject: substituting list comprehensions for map() References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> Message-ID: <87pr7ywdzv.fsf@agentultra.com> Steven D'Aprano writes: > On Tue, 03 Nov 2009 10:22:28 -0500, J Kenneth King wrote: > >> However in this case the procedure by which we derive the value is not >> important or even interesting. It is much more succinct to think of the >> operation as a value and express it accordingly. There's no need to >> clutter the mind with extra name bindings and iteration keywords. They >> won't make our idea any more clear. >> >> dot_product = map(mul, vec1, vec2) >> >> vs >> >> dot_product = [a * b for a, b in zip(vec1, vec2)] >> >> It's very clear, at least to me, what a dot-product is in this case. > > Except it's not. > > The dot product of two vectors returns a scalar, not another vector: > http://en.wikipedia.org/wiki/Dot_product > > So what you want is: > > dot_product = sum(map(mul, vec1, vec2)) Derh. Thanks for the catch. My bad. >> Adding in the loop construct and name bindings doesn't enhance my >> understanding of what a dot-product is. I don't need to see the loop >> construct at all in this case. A dot product is simply the >> multiplication of each element in a vector sequence. > > What you need is to define a function dot-product, and not hijack the > name for a local value. Then the function's implementation is irrelevant > to you: it could use a list comp, or could use map, it could use a for- > loop, a while loop, recursion, or black magic: > > scalar = dot_product(vec1, vec2) Even better. But now I'm afraid the example is running away from the point. So to summarize: 1. Extra name bindings and loop keywords aren't always easier to read. 2. Expressing what we want rather than how we get it is much more clear. and (third dirty argument added) 3. List comprehensions leak their name bindings to the surrounding scope. :p Have a nice day. :) From ethan at stoneleaf.us Wed Nov 4 09:47:35 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 04 Nov 2009 06:47:35 -0800 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <7l9asbF3c7qa2U1@mid.uni-berlin.de> <87my33heq1.fsf@benfinney.id.au> <4AF0959D.2020307@stoneleaf.us> Message-ID: <4AF19407.6050508@stoneleaf.us> Daniel Fetchinson wrote: >>>>>I was referring to this comment by Ben: >>>>> >>>>>"Suggestion: Please don't make efforts to fragment the community." >>>>> >>>>>This IMHO is hostile, because it presupposes that the mere goal of the >>>>>OP is fragmenting the community >>>> >>>>It presupposes nothing of any goal. It describes a predictable result of >>>>the OP's efforts, and requests those efforts to cease. >>>> >>>>So I deny the characterisation of that request as hostile. >>> >>[mass snippitude] >> >> >>>If yes, with the substitution A = Ben and B = OP we get "in order for >>>Ben's request to make sense, Ben has to assume that the OP is making >>>an effort to fragment the community". This assumption on the part of >>>Ben, I think, is hostile, since it assumes that the OP is making an >>>effort to do something not nice. Whether the OP is indeed doing >>>something not nice, is irrelevant. If the OP does do something not >>>nice, the hostility is warranted. If the OP is not doing anything not >>>nice, the hostility is unwarranted. But the fact that Ben was hostile >>>is a fact :) >> >>You were doing fine until you brought in the hostility. I must agree >>with Ben that his comment was not hostile. It was merely a statement. >>Not an exclamation, no name calling, just a plain request rooted in reality. > > > Okay, before we get to quarks let's see what 'hostile' means :) >>From Merriam-Webster http://www.learnersdictionary.net/dictionary/hostile : > > 1 a : of or relating to an enemy > b : marked by malevolence > c : openly opposed or resisting > d (1) : not hospitable > (2) : having an intimidating, antagonistic, or offensive nature > > > Now, I think the OP was perceived by Ben as doing something which he > thinks is not good. We most probably agree on this. In other words, > Ben was opposing the OP's ideas. Yet in other words, Ben was resisting > the OP's ideas. And yet in other words, Ben was not hospitable. So > perhaps 1a and 1b doesn't quite fit the bill since Ben didn't go as > far as call the OP an enemy and he wasn't evil or wished harm to the > OP, but 1c and d(1) are certainly correctly describing his behavior > and to a lesser extent d(2) as well. AH hahahahahahah. Okay, you got me. However, if we're going to start looking up the exact denotations of words to justify our remarks, surely we should also pay attention to the connotations? In normal, everyday speach the denotations of 'resisting' and 'opposed to' are very different from 'hostile' -- hence such phrases as 'resisting with hostility' and 'hostiley opposed to'. In other words, I'll grant you the win of that hair, but I still would not characterize it as hostile. ;-) ~Ethan~ From simon at mullis.co.uk Wed Nov 4 09:54:39 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 4 Nov 2009 15:54:39 +0100 Subject: Calling a method with a variable name Message-ID: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Hi All, I'm collating a bunch of my utility scripts into one, creating a single script to which I will symbolic link multiple times. This way I only have to write code for error checking, output-formatting etc a single time. So, I have ~/bin/foo -> ~/Code/python/mother_of_all_utility_scripts.py ~/bin/bar -> ~/Code/python/mother_of_all_utility_scripts.py ~/bin/baz -> ~/Code/python/mother_of_all_utility_scripts.py I would like "bar" to run the bar method (and so on). ------------- class Statistic() def __init__(self): pass def foo(self): return "foo!" def bar(self): return "bar!" # ... and so on... def main(): stats_obj = Statistic() name = re.sub("[^A-Za-z]", "", sys.argv[0]) method = getattr(stats_obj, name, None) if callable(method): stats_obj.name() # <------------HERE else: print "nope, not sure what you're after...." ----------- However, as I'm sure you've all noticed already, there is no method called "name". I would really prefer to get a nudge in the right direction before I start evaling variables and so on. Does my approach make sense? If not, please give me a hint... Thanks SM From deets at nospam.web.de Wed Nov 4 09:57:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 04 Nov 2009 15:57:24 +0100 Subject: Calling a method with a variable name References: Message-ID: <7ldj2kF38sg9oU1@mid.uni-berlin.de> Simon Mullis wrote: > Hi All, > > I'm collating a bunch of my utility scripts into one, creating a > single script to which I will symbolic link multiple times. This way > I only have to write code for error checking, output-formatting etc a > single time. > > So, I have > > ~/bin/foo -> ~/Code/python/mother_of_all_utility_scripts.py > ~/bin/bar -> ~/Code/python/mother_of_all_utility_scripts.py > ~/bin/baz -> ~/Code/python/mother_of_all_utility_scripts.py > > I would like "bar" to run the bar method (and so on). > > ------------- > class Statistic() > def __init__(self): > pass > > def foo(self): > return "foo!" > > def bar(self): > return "bar!" > > # ... and so on... > > def main(): > stats_obj = Statistic() > name = re.sub("[^A-Za-z]", "", sys.argv[0]) > method = getattr(stats_obj, name, None) > if callable(method): > stats_obj.name() # <------------HERE > else: > print "nope, not sure what you're after...." > ----------- > > However, as I'm sure you've all noticed already, there is no method > called "name". I would really prefer to get a nudge in the right > direction before I start evaling variables and so on. > > Does my approach make sense? If not, please give me a hint... You are almost there. Why don't you do if callable(method): method() ? Diez From lallous at lgwm.org Wed Nov 4 10:00:33 2009 From: lallous at lgwm.org (lallous) Date: Wed, 4 Nov 2009 16:00:33 +0100 Subject: C api and exception handling References: Message-ID: Thanks for your help Carl as usual. Will go with the getattr override method which is cleaner as you explained. Regards, Elias "Carl Banks" wrote in message news:f02c069c-e536-4c6b-b114-2215aa61129e at k17g2000yqh.googlegroups.com... > On Nov 2, 7:16 am, "lallous" wrote: >> Hello, >> >> Is there is a way, using the Python C api, to install an exception >> handler >> that: >> - will be triggered when an exception occurs >> - analyze the reason of the exception >> - correct the situation and try again (something like exception handling >> on >> windows where the exception handler can retrieve the registers >> context->faulting instruction->fix situation if needed->restart execution >> from the same point) > > Python has no concept of "retrying", at either the Python or C API > level. You might be able to do something Evil in C to get this effect > but I don't recommend it, it'll be fundamentally averse to how Python > works and future versions are likely to break it. > > >> Since I will be asked: "what are you trying to achieve?", this is what I >> want: >> >> func_call("hello") <- no exceptions, good code: function is defined and >> called properly >> SomeUndefinedFunction("x", "y") <- undefined function call will trigger >> an >> exception. I want my python/C exception handler to inspect the reason of >> the >> exception, if it was a call to an undefined function call then redirect >> the >> execution to a certain method, say: >> ExecuteByName("SomeUndefinedFunction", >> "x", "y") >> >> I know if I create a small class with getattr hooked, what I want can be >> achieved. > > > I'd do it that way. There is ordinarily no way to hook into a plain > function call like SomeUndefinedFunction() in Python; if you go around > hacking up the interpreter to do that users will be highly confused > and surprised. > > OTOH, hooking into attributes is pretty well-known. When a person > sees attribute notation they know there's an opportunity to do weird > stuff. When a strange function is called, they will be like, "oh, > someone overrode __getattr__". > > >> But can it be done otherwise (without using a class and instead relying >> on >> exception handlers and correcting the exception)? > > Just forget about exception handling. If you REALLY insist on doing > this, and I highly recommend against it, the best chance you have is > to try to hook into the importing process and load a module that uses > a custom dictionary object. > > > Carl Banks From carsten.haese at gmail.com Wed Nov 4 10:04:55 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 10:04:55 -0500 Subject: Calling a method with a variable name In-Reply-To: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> References: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Message-ID: Simon Mullis wrote: > def main(): > stats_obj = Statistic() > name = re.sub("[^A-Za-z]", "", sys.argv[0]) > method = getattr(stats_obj, name, None) > if callable(method): > stats_obj.name() # <------------HERE > else: > print "nope, not sure what you're after...." > ----------- > > However, as I'm sure you've all noticed already, there is no method > called "name". I would really prefer to get a nudge in the right > direction before I start evaling variables and so on. At the point you marked "HERE", you've already found the method, and you have determined that it is callable. You just need to call it. Like this: method(). HTH, -- Carsten Haese http://informixdb.sourceforge.net From python.list at tim.thechases.com Wed Nov 4 10:09:12 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 04 Nov 2009 09:09:12 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: <4AF19918.9050406@tim.thechases.com> > Can we use inp_paragraph.count(iter_word) to make it simple ? It would work, but the performance will drop off sharply as the length of the paragraph grows, and you'd still have to keep track of which words you already printed so you can correctly print the first one. So you might as well not bother with counting. -tkc From simon at mullis.co.uk Wed Nov 4 10:20:50 2009 From: simon at mullis.co.uk (Simon Mullis) Date: Wed, 4 Nov 2009 16:20:50 +0100 Subject: Calling a method with a variable name In-Reply-To: References: <23d7e1bb0911040654t435ad26bm4070b0217b299e9c@mail.gmail.com> Message-ID: <23d7e1bb0911040720s211f14b7l9c961bdaa17d6efa@mail.gmail.com> May I be the first to say "Doh!" Problem solved, many thanks to both Carsten and Diez! SM 2009/11/4 Carsten Haese : > Simon Mullis wrote: >> def main(): >> ? ? stats_obj = Statistic() >> ? ? name = re.sub("[^A-Za-z]", "", sys.argv[0]) >> ? ? method = getattr(stats_obj, name, None) >> ? ? if callable(method): >> ? ? ? ? stats_obj.name() ? ? ? ? ? ? ?# ?<------------HERE >> ? ? else: >> ? ? ? ? print "nope, not sure what you're after...." >> ----------- >> >> However, as I'm sure you've all noticed already, there is no method >> called "name". I would really prefer to get a nudge in the right >> direction before I start evaling variables and so on. > > At the point you marked "HERE", you've already found the method, and you > have determined that it is callable. You just need to call it. Like > this: method(). > > HTH, > > -- > Carsten Haese > http://informixdb.sourceforge.net > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Simon Mullis _________________ simon at mullis.co.uk From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 4 10:53:56 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Nov 2009 16:53:56 +0100 Subject: About one class/function per module In-Reply-To: <87639rizob.fsf@benfinney.id.au> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <7lajrkF3c97onU1@mid.uni-berlin.de> <87639rizob.fsf@benfinney.id.au> Message-ID: <4af1a394$0$428$426a74cc@news.free.fr> Ben Finney a ?crit : > "Diez B. Roggisch" writes: > >> Don't get me wrong - innovation often comes from scratching ones >> personal itch. But you seem to be suffering from a rather bad case of >> neurodermatitis. > > +1 QOTW > Make it +2 QOTW !-) From victorsubervi at gmail.com Wed Nov 4 10:57:47 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 4 Nov 2009 10:57:47 -0500 Subject: Calendar Problem In-Reply-To: <4AF0C317.3010109@ieee.org> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> <4AF0C317.3010109@ieee.org> Message-ID: <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> Well, you're right. That's what I initially had. My server, that I am in the process of leaving, rejected that syntax. Lovely. Thanks, V On Tue, Nov 3, 2009 at 6:56 PM, Dave Angel wrote: > > > MichaB Klich wrote: > >> Dnia wtorek 03 listopada 2009 o 20:50:10 Victor Subervi napisa?(a): >> >> >>> Hi; >>> I have the following: >>> >>> import calendar, datetime >>> >>> myCal =alendar.calendar(6) >>> today =atetime.date.today() >>> day =oday.day >>> mo =oday.month >>> yr =oday.year >>> month =yCal.monthdayscalendar(yr, mo) >>> >>> >>> The last line throws errors no matter how I try and tweak it. The current >>> incarnation complains about myCal being a string. What do? >>> TIA, >>> Victor >>> >>> >>> >> >> You should use >> >> myCal =calendar.Calendar(6) >> >> This creates calendar.Calendar object. >> >> >> > Right. But I wanted to tell the OP what to do with an error like this. > > > You should post the actual error traceback, and tell us what version of > Python you're using: > > Traceback (most recent call last): > File "M:\Programming\Python\sources\dummy\stuff2.py", line 15, in > > month = myCal.monthdayscalendar(yr, mo) > AttributeError: 'str' object has no attribute 'monthdayscalendar' > > > Now, since it says that myCal is a 'str' object, the next thing you should > do is look at the value. I get an actual printable calendar for a year. So > clearly, it's not the Calendar object you were looking for. So you need to > change from the calendar() function to the Calendar() constructor. > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Nov 4 11:07:00 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 04 Nov 2009 17:07:00 +0100 Subject: About one class/function per module In-Reply-To: References: <4aeea07e$0$713$426a34cc@news.free.fr> Message-ID: <4af1a6a4$0$420$426a74cc@news.free.fr> Peng Yu a ?crit : > On Mon, Nov 2, 2009 at 3:03 AM, Bruno Desthuilliers > wrote: >> Peng Yu a ?crit : >> (snip) >>> I prefer organized my code one class/function per file (i.e per module >>> in python). I know the majority of programmers don't use this >>> approach. Therefore, I'm wondering what its disadvantage is. >> Hmmm... As far as I'm concerned, you already answered your own question: >> "the majority of programmers don't use this approach". >> >> Now, for a much more practical answer: >> 1/ having to handle thousands of files for even a simple project is a >> king-size PITA for the maintainer. >> 2/ having to load thousands of modules will add quite a lot of overhead when >> actually running the code. >> 3/ as a result, the poor guy that will end up maintaining your code will >> positively hate you. Beware : this poor guy might as well be you. > > I still don't understand why it is a nightmare to maintain the code. Been here, done that. You obviously don't have enough experience with Python to understand why your "organization" suck. And given your apparent tendency to insist on imposing your own views / preconceptions on the language instead of learning how to use it properly (the canonical "I can write Java in any language" syndrom), it will probably take a long time before you get there - if you ever get there at all. My friendly (really) advice is to stop fighting the langage and start going with the flow. (snip lots of stuff that require neither "one line of code per file" nor fancy scripts) From Nadav.C at qualisystems.com Wed Nov 4 11:29:52 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 18:29:52 +0200 Subject: regexp help Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> Hello all, I'm trying to write regexp that find all files that are not with next extensions: exe|dll|ocx|py, but can't find any command that make it. Please, help me Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: From VBoycheva at jonesedmunds.com Wed Nov 4 11:34:52 2009 From: VBoycheva at jonesedmunds.com (Valentina Boycheva) Date: Wed, 4 Nov 2009 11:34:52 -0500 Subject: Pyfora, a place for python References: Message-ID: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> >>Daniel Fetchinson writes: > >Probably this thread is going by far too far :) >Ben Finney [ben+python at benfinney.id.au] writes: > Agreed. I was following this discussion first with curiosity and then with increasing disbelief. As a scientist and a programmer, I always considered myself belonging to a group of people who are broad-minded and task-oriented. Being an occasional Python programmer, I subscribed to this list in the hopes of learning from the pros. Most of the time I do. But I also see a disturbing trend of petty bickering, splitting hairs and one-upmanship. I understand there will be occasional language slips and misconstrued jokes but can we please stick to the topic and remain courteous at all times? I am seriously considering unsubscribing from this UL (and maybe joining Pyfora.) From carsten.haese at gmail.com Wed Nov 4 11:35:48 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 11:35:48 -0500 Subject: Calendar Problem In-Reply-To: <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> References: <4dc0cfea0911031150v1aec1de4o4372831e82863552@mail.gmail.com> <200911032112.15288.klich.michal@gmail.com> <4AF0C317.3010109@ieee.org> <4dc0cfea0911040757l1462abecs9a556fed5fee0bcc@mail.gmail.com> Message-ID: Victor Subervi wrote: > That's what I initially had. My server, that I am in > the process of leaving, rejected that syntax. What version of Python does that server use? The calendar.Calendar class first appeared in Python 2.5. I suspect your server is using an older version. -- Carsten Haese http://informixdb.sourceforge.net From simon at brunningonline.net Wed Nov 4 11:43:48 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 16:43:48 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> Message-ID: <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> 2009/11/4 Nadav Chernin : > I?m trying to write regexp that find all files that are not with next > extensions: ?exe|dll|ocx|py, ?but can?t find any command that make it. http://code.activestate.com/recipes/499305/ should be a good start. Use the re module and your regex instead of fnmatch.filter(), and you should be good to go. -- Cheers, Simon B. From rustompmody at gmail.com Wed Nov 4 11:57:41 2009 From: rustompmody at gmail.com (rustom) Date: Wed, 4 Nov 2009 08:57:41 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> Message-ID: On Oct 30, 6:23?pm, Dotan Cohen wrote: > The point is that I want to use only _Python_ features, not > Django/Mako/whatever features. Pure python has a builtin templating system -- its called % See http://simonwillison.net/2003/Jul/28/simpleTemplates/ From Nadav.C at qualisystems.com Wed Nov 4 12:05:51 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 19:05:51 +0200 Subject: regexp help In-Reply-To: <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Thanks, but my question is how to write the regex. -----Original Message----- From: simon.brunning at gmail.com [mailto:simon.brunning at gmail.com] On Behalf Of Simon Brunning Sent: ? 04 ?????? 2009 18:44 To: Nadav Chernin; Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > I?m trying to write regexp that find all files that are not with next > extensions: ?exe|dll|ocx|py, ?but can?t find any command that make it. http://code.activestate.com/recipes/499305/ should be a good start. Use the re module and your regex instead of fnmatch.filter(), and you should be good to go. -- Cheers, Simon B. From simon at brunningonline.net Wed Nov 4 12:12:47 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 17:12:47 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Message-ID: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> 2009/11/4 Nadav Chernin : > Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. -- Cheers, Simon B. From carsten.haese at gmail.com Wed Nov 4 12:13:55 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 04 Nov 2009 12:13:55 -0500 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> Message-ID: Nadav Chernin wrote: > Thanks, but my question is how to write the regex. See http://www.amk.ca/python/howto/regex/ . -- Carsten Haese http://informixdb.sourceforge.net From Nadav.C at qualisystems.com Wed Nov 4 12:16:14 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Wed, 4 Nov 2009 19:16:14 +0200 Subject: regexp help In-Reply-To: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> No, I need all files except exe|dll|ocx|py -----Original Message----- From: simon.brunning at gmail.com [mailto:simon.brunning at gmail.com] On Behalf Of Simon Brunning Sent: ? 04 ?????? 2009 19:13 To: Nadav Chernin Cc: Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. -- Cheers, Simon B. From simon at brunningonline.net Wed Nov 4 12:18:51 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 4 Nov 2009 17:18:51 +0000 Subject: regexp help In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BC5@exchange.qualisystems.local> Message-ID: <8c7f10c60911040918h41222b02p6bee89ada1601157@mail.gmail.com> 2009/11/4 Nadav Chernin : > No, I need all files except exe|dll|ocx|py not re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) Now that wasn't so hard, was it? ;-) -- Cheers, Simon B. From NOSPAM_chuckwhite8 at charter.net Wed Nov 4 12:27:36 2009 From: NOSPAM_chuckwhite8 at charter.net (chuck) Date: Wed, 04 Nov 2009 12:27:36 -0500 Subject: unable to compile Python 2.6.4 on AIX using gcc In-Reply-To: References: Message-ID: <4AF1B988.2080206@charter.net> Thanks Mark. That was indeed very helpful. Here's the current status: ======================= 1. applied changes suggested by Bob Atkins in that thread. 2. setting env variables. export OBJECT_MODE=64 export CC="gcc" export CFLAGS="-maix64 -mcpu=power5" export LDFLAGS="-maix64 -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freeware/lib" export CPPFLAGS="-I/opt/freeware/include -I/usr/lpp/X11/include/X11" 3. configuring and compiling using configure --with-gcc --enable-shared --prefix=/usr/local/Python-2.6.4 > config_264.log 2>&1 ; make > make_264.log 2>&1 ======================= Both python (executable) and libpython2.6.a build just fine and are in the same directory as configure. However, none of the extensions build. I keep getting libpython2.6 not found error. Here's an example: building 'math' extension gcc -pthread -fno-strict-aliasing -maix64 -mcpu=power5 -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -I/usr/local/build/python/Python-2.6.4/./Include -I. - IInclude -I./Include -I/opt/freeware/include -I/usr/lpp/X11/include/X11 -I/usr/local/include -I/usr/local/build/python/Python-2.6.4/Include -I/usr/local /build/python/Python-2.6.4 -c /usr/local/build/python/Python-2.6.4/Modules/mathmodule.c -o build/temp.aix-5.3-2.6/usr/local/build/python/Python-2.6.4/Mo dules/mathmodule.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp -maix64 -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/usr/X11R6/lib -L/opt/freewa re/lib -fno-strict-aliasing -maix64 -mcpu=power5 -DNDEBUG -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/opt/freeware/include -I/usr/lpp/X11 /include/X11 build/temp.aix-5.3-2.6/usr/local/build/python/Python-2.6.4/Modules/mathmodule.o -L/usr/lib64 -L/opt/freeware/lib64 -L/opt/freeware/64/lib - L/usr/X11R6/lib -L/opt/freeware/lib -L/usr/local/lib -lm -lpython2.6 -o build/lib.aix-5.3-2.6/math.so collect2: library libpython2.6 not found I hacked Makefile to LDFLAGS= <> -L./ I now get: ld: 0711-224 WARNING: Duplicate symbol: PyObject_Size ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. Fatal Python error: Interpreter not initialized (version mismatch?) make: The signal code from the last command is 6. There are no other versions of python on that machine. I would appreciate any help. Do I need to set the exec_prefix as well? Thanks. Mark Dickinson wrote: > On Nov 3, 10:40 pm, chuck wrote: >> Hello -- I am trying to compile Python 2.6.4 on a Power 5 PC with AIX >> 5.3. Here are the settings: > Take a look at: > > http://bugs.python.org/issue1628484 > > Mark From python at mrabarnett.plus.com Wed Nov 4 12:45:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 04 Nov 2009 17:45:42 +0000 Subject: Request for comments - concurrent ssh client In-Reply-To: References: Message-ID: <4AF1BDC6.3070705@mrabarnett.plus.com> mk wrote: > Hello everyone, > > Since I'm not happy with shmux or pssh, I wrote my own "concurrent ssh" > program for parallel execution of SSH commands on multiple hosts. Before > I release program to the wild, I would like to hear (constructive) > comments on what may be wrong with the program and/or how to fix it. > (note: the program requires paramiko ssh client module) > [snip] > if opts.cmd == None and opts.script == None: > print "You have to specify one of the following: command to run, > using -c command or --cmd command, or script to run, using -s scriptfile > or --script scriptfile." > print > failit = True > The normal way to test for None is to use "is None" or "is not None". You do actually do that in some places! [snip] > hosts = [ s.strip() for s in hosts if s != '' and s != None and s != '\n' ] > hosts = [ s.split() for s in hosts ] > [snip] Both '' and None are treated as false by 'if' and 'while'; non-empty strings are treated as true. Also, "s.split()" splits on whitespace and disregards leading and trailing whitespace. The preceding lines can be simplified to: hosts = [ s.split() for s in hosts if s and s != '\n' ] > if hosts == []: [snip] Empty lists are also treated as false and non-empty lists as true. The Pythonic way to write the preceding line is: if not hosts: [snip] > scriptcomp = script.strip().split() As mentioned earlier, ".strip().split()" can be simplified to just ".split()": scriptcomp = script.split() [snip] > try: > self.conobj.connect(self.ip, username=self.username, > password=self.passw, port=self.port, timeout=opts.timeout, > allow_agent=False, look_for_keys = False) > loginsuccess = True > except: > pass [snip] Avoid bare "except" wherever possible. In this case you're ignoring _every_ exception that might occur. VERY BAD IDEA! > def execcmds(self): > so = se = '' > try: > si, so, se = self.conobj.exec_command(self.cmd) > sol = so.readlines() > sel = se.readlines() > so = ''.join([ s.replace('\r\n','\n') for s in sol ]) > se = ''.join([ s.replace('\r\n','\n') for s in sel ]) [snip] Recent versions of Python will accept generator expressions here, so instead of iterating through a list and creating a new list, which is then passed to '.join', you can let '.join' do the iterating. This can save time and memory: so = ''.join( s.replace('\r\n','\n') for s in sol ) se = ''.join( s.replace('\r\n','\n') for s in sel ) > if sol != [] or sel != []: As mentioned earlier, non-empty lists are treated as true: if sol or sel: > def chmodscript(self): > # just in case, as sometimes and on some operating systems the > execution flags on the script are not always set > self.execcmdonscript('chmod 0755 %s' % self.rspath) > [snip] You could also use: os.chmod(self.rspath, 0755) > def delscript(self): > self.execcmdonscript('rm -f %s' % self.rspath) > [snip] You could also use: os.remove(self.rspath) > for ip, th in queue: > if th.finished: > th.sshclose() > th.join() > thfinished.append((ip,th)) > queue.remove((ip,th)) > Never modify a list (or any container, in fact) while iterating through it. Some containers handle iteration by using an index, but if you remove an item from the container then the index might no longer be correct. Instead, build a new list of the items you want to keep: new_queue = [] for ip, th in queue: if th.finished: th.sshclose() th.join() thfinished.append((ip,th)) else: new_queue.append((ip,th)) queue = new_queue If there are other references to the queue itself then it might be better to replace the contents of the existing queue with those of the new one instead by changing: queue = new_queue to: queue[:] = new_queue From reckoner at gmail.com Wed Nov 4 12:59:00 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 09:59:00 -0800 (PST) Subject: set pdb break condition based upon number of hits? Message-ID: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> Is it possible to set pdb break condition based upon number of hits? I mean something like (Pdb) break line_number (number_of_hits_for_this_breakpoint >10) any help appreciated. From kevinar18 at hotmail.com Wed Nov 4 13:06:53 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Wed, 4 Nov 2009 13:06:53 -0500 Subject: How do I install dlls and exes for libtidy and others? Message-ID: 1. I already asked how to setup libxml2 and libxslt, but nobody answered how to... so if anyone knows I'm still having those problems. 2. I now can't get libtidy to work, which requires the same thing: I need to put some dlls and exes somewhere to make it work in Python. Thing is, I don't know where. There are no instructions on this part. Details: I get the following error: import tidy OSError: Couldn't find libtidy, please make sure it is installed. I downloaded these two files (the exe and the dll): http://www.paehl.com/open_source/?HTML_Tidy_for_Windows I copied the exe and dll to the Python directory and Python\Lib and Python\Dlls ... nothing worked I ran this installer (didn't solve the problem): http://int64.org/projects/tidy-binaries So, how can I setup libtidy to work with Python? What do I do with the exe and dll files? Do I need to make additional changes to the system? How do I get other programs like libxml2 and libxslt to work with python -- as in what do I do with the exe and dlls? _________________________________________________________________ Bing brings you maps, menus, and reviews organized in one place. http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1 From jeanmichel at sequans.com Wed Nov 4 13:15:01 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 04 Nov 2009 19:15:01 +0100 Subject: About one class/function per module In-Reply-To: <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> Message-ID: <4AF1C4A5.70604@sequans.com> Peng Yu wrote: > With some automated script, I don't think it is a nightmare to change > function names. I can change function names and filenames and their > reference with a simple command. > > I'd think that this is the limitation of current version control > system. I don't aware of any version control system that allows easy > change of filenames. But why such features can not be implemented in > the version control system? > So one function per files bring so many problems that you need an automated script to change one function name and complain about version control systems messing up with your file history. Still you insist on stating that this is the solution and that version control system have to adapt. It has already been told to you, and you should really consider the following advice: When everything is wrong except you, it may happen that *your* are somehow wrong. Among all the responses you got, I don't remember any one that would suggest you are in the right way. So what is your conclusion now ? JM From luke.leighton at googlemail.com Wed Nov 4 13:17:23 2009 From: luke.leighton at googlemail.com (Luke Kenneth Casson Leighton) Date: Wed, 4 Nov 2009 18:17:23 +0000 Subject: [ANN] Pyjamas 0.7pre1 Web Widget Set and python-to-javascript Compiler released Message-ID: Current Release: 0.7~pre1 --------------- This is a 0.7 prerelease of Pyjamas, to invite users to help test the latest version. The latest svn is regularly but informally tested against the regression tests and the examples, and used in production, but not extensively tested against all known browsers on each commit. Community assistance by running against a wider range of browsers ensures that *you* get a stable release. Pyjamas ------- Pyjamas is a port of Google Web Toolkit to Python, and thus enables the development of Rich Media AJAX applications in Python, with no need for special browser plugins. Pyjamas contains a stand-alone python-to-javascript compiler, and also a Widget Set API that looks very similar to Desktop Widget Set APIs (such as PyQT4 or PyGTK2). Pyjamas also contains a Desktop Widget Set version, running as pure python. Using web browser technology provides an alternative to PyQT4 and PyGTK2 that has the advantage of having full support for HTML, CSS, Plugin and other web-related features already built-in. For the windows port, this can save users around 30mb of downloads, as MSHTML is preinstalled as part of IE. For more information, see: http://pyjs.org http://pyjs.org/FAQ.html http://pyjs.org/features.html Known bugs: http://code.google.com/p/pyjamas/issues #290, #227, #228, #230, #304 Changelog Summary ----------------- Features and enhancements of the stand-alone 0.7 series javascript compiler include: * the addition of generators (support for yield, by rewriting the function so that it can be re-called and continue from the previous state); * the beginnings of decorators support, and support for properties; * some dramatic performance improvements due to a rewrite of for-loops; * improved support for import syntax (from . import module); * the addition of a built-in AST parser, use of which allows python 2.4 to compile programs with python 2.5 / 2.6 syntax into javascript; * addition of int and long types, and support for operator functions, so that e.g list multiplication by numbers and list addition now work, along with coercion between int, float and long types, and support for floating point exceptions. Overall, this release is a significant "pythonic" upgrade: for full details, see the CHANGELOG. In the User-Interface suite, which is separate from the Pyjamas stand-alone python-to-javascript compiler, the features and enhancements include: * An SVG / VML Canvas Library (a port of GWTCanvas). This has been ported to pure python, and consequently work under Pyjamas-Desktop as well. * A Graphical Chart Library (a port of GChart). This has been ported to pure python, and consequently work under Pyjamas-Desktop as well. For the same speed optimisations present in GChart, GChart for Pyjamas can also use the python port of GWTCanvas. * An internal restructure of Event handling, similar to GWT 1.7, providing Focus, Mouse and Click "Mixin" modules so that developers creating their own widgets have a minimal amount of work to do. This redesign could only take place once Pyjamas supported multiple inheritance (added in 0.6). Pyjamas-Desktop --------------- Pyjamas runs your application in a Web Browser (as javascript); Pyjamas-Desktop runs exactly the same python application on the Desktop (as python) http://pyjd.org Release 0.6 of Pyjamas incorporated Pyjamas-Desktop directly into the Pyjamas Distribution. To use Pyjamas-Desktop there are three choices, with more planned [MacOSX PyObjC; KDE's PyKHTML]. All ports of Pyjamas-Desktop will require a JSON library to be installed: as there are plenty already, it is counter-productive to write yet another one. Simplejson is recommended. 1) - XULRunner install hulahop and python-xpcom. hulahop is distributed with both Debian and Ubuntu; python-xpcom is part of XULRunner and is also distributed with both Debian and Ubuntu. Other users should investigate the installation instructions for python-xpcom and hulahop for the operating system of their choice on the appropriate web sites. GNU/Linux, FreeBSD and other POSIX systems are strongly advised to use XULRunner for Pyjamas-Desktop: it is the most stable of the PyJD ports. 2) - PyWebKitGtk you will need a patched version of pywebkitgtk: http://code.google.com/p/pywebkitgtk/issues/detail?id=13 you will need a patched version of webkit: http://github.com/lkcl/webkit/16401.master Detailed build instructions are available here: http://wiki.github.com/lkcl/webkit/helping-with-16401master 3) - MSHTML For Windows users, all that's required, other than installing python and Internet Explorer, is one further package: Win32 "comtypes". Win32 "comtypes" can be downloaded here: * http://sourceforge.net/projects/comtypes/ From sebas0 at gmail.com Wed Nov 4 13:37:39 2009 From: sebas0 at gmail.com (Sebastian) Date: Wed, 4 Nov 2009 16:37:39 -0200 Subject: a is b Message-ID: I have a question from the pyar list that may have been discussed on this list, but i didn't catch it. Have some common objects been somewhat hardcoded into python, like some integers as shown in the examples below? What other object have been hardcoded (strings ,etc) and what was the criteria used to select them? Any hints? cheers, - Seb >>> p = 500 >>> q = 500 >>> p == q True >>> p is q False >>> n = 50 >>> m = 50 >>> n == m True >>> n is m True >>> p = 500; q = 500 >>> p is q True >>> for i in range(-20,258): ... a = i ... b = i+0 ... if not (a is b): print i ... -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 257 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 4 13:42:27 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 4 Nov 2009 10:42:27 -0800 Subject: a is b In-Reply-To: References: Message-ID: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> On Wed, Nov 4, 2009 at 10:37 AM, Sebastian wrote: > I have a question from the pyar? list that may have been discussed on this > list, but i didn't catch it. > Have some common objects been somewhat hardcoded into python, like some > integers as shown in the examples below? What other object have been > hardcoded (strings ,etc) and what was the criteria used to select them?? Any > hints? See recent thread on the subject: http://www.mail-archive.com/python-list at python.org/msg264434.html Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Nov 4 13:46:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 13:46:39 -0500 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: Alf P. Steinbach wrote: > However, the natural semantics is that various logical properties, such > as left, top, right, bottom, width and height, can be varied independently. But they *CANNOT* be varied independently. A rectangle with side parallel to the axes has exactly 4 degress of freedom, not 6. Terry Jan Reedy From tjreedy at udel.edu Wed Nov 4 13:51:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 13:51:02 -0500 Subject: import from a string In-Reply-To: References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: >> On Nov 4, 3:10 am, "Gabriel Genellina" wrote: > >>> txt = """ >>> def foo(x): >>> print 'x=', x >>> >>> def bar(x): >>> return x + x >>> """ >>> >>> py> namespace = {} >>> py> exec txt in namespace >>> py> namespace.keys() >>> ['__builtins__', 'foo', 'bar'] >>> py> namespace['foo']('hello') >>> x= hello > >> What happens if both global and local dictionaries are supplied: where >> are the newly created entities created? In the local dict? > > The amazing thing about Python is how easy is to experiment in the > interpreter. > Just see it by yourself! Hint: they are created in the same namespace they always are (ignoring nested functions and nonlocal namespaces). But I agree with Gabriel: just try it. n1,n2={},{}; exec.... Terry Jan Reedy From kevinar18 at hotmail.com Wed Nov 4 14:07:54 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Wed, 4 Nov 2009 14:07:54 -0500 Subject: How do I install dlls and exes for libtidy and others? Message-ID: Lme clarify my problems. My earlier emails were pretty vague... so this should help. Problem: I have been wanting to try out many libraries that use Python to C/C++ app bindings. This means I install the Python library using easy_install and then install the pre-compiled Windows binaries and/or dlls... but that is where the problem arises: * I do not know where to install the pre-compiled binaries. There are no instructions on this -- it's like everyone assumes I know what to do. * I tried copying the exe and/or dlls to Python, Python\Lib, Python\Dll * import libxml2, import libxslt, and import libtidy do not work. For example for libtidy, I get: import tidy OSError: Couldn't find libtidy, please make sure it is installed. * The problem is always when a library requires pre-compiled Windows binaries. I can't every get any such libraries to work. My questions. What is the proper way to setup these pre-compiled binaries so that they will work with Python libraries? What are all the steps? Is there some things I can do to help diagnose problems? Could the problems be something different? _________________________________________________________________ Windows 7: Unclutter your desktop. http://go.microsoft.com/?linkid=9690331&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen:112009 From tjreedy at udel.edu Wed Nov 4 14:10:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Nov 2009 14:10:19 -0500 Subject: Pyfora, a place for python In-Reply-To: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> References: <82347ACEFB791E479B7E9C20F3567217026684D3@mailje08.jea.net> Message-ID: Valentina Boycheva wrote: > I was following this discussion first with curiosity and then with > increasing disbelief. > So stop following it. Really. > As a scientist and a programmer, I always > considered myself belonging to a group of people who are broad-minded > and task-oriented. Ditto. I read python-list as the newgroup gmane.comp.python.general and only download the posts I select, which is well less than half, depending on my mood;-). -- which is to say, whether or not I am looking for time-wasting entertainment ;-) > Being an occasional Python programmer, I subscribed to this list in the > hopes of learning from the pros. Most of the time I do. But I also see a > disturbing trend of petty bickering, splitting hairs and one-upmanship. I have been reading for over 10 years and see no increasing trend. The worst times were definitely in the past. > I understand there will be occasional language slips and misconstrued > jokes but can we please stick to the topic and remain courteous at all > times? I completely agree, but have given up most admonishments ;-) > I am seriously considering unsubscribing from this UL That would be a shame. > (and maybe joining Pyfora.) That should be an independent decision. Most PHPBBS web forums I have seen are about the same or worse as far as civility. Terry Jan Reedy From starglider101 at gmail.com Wed Nov 4 14:17:21 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 4 Nov 2009 19:17:21 +0000 Subject: comparing alternatives to py2exe In-Reply-To: <4af163cc$0$6279$4f793bc4@news.tdc.fi> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> <4af163cc$0$6279$4f793bc4@news.tdc.fi> Message-ID: <6e5b31840911041117q7dbbe3fw718b9f7f6761c050@mail.gmail.com> Hi, in this discussion I read that we con create a bundle executable for our application, since I'm having troubles with create a exe due problems with kinterbasdb, can you show me tutorials for creating exe from bundle. thanks in advance. On Wed, Nov 4, 2009 at 11:21 AM, Vesa K?pp? wrote: > iu2 wrote: > >> Another thing that I think is of interest is whether the application >> support modifying the version and description of the exe (that is, on >> Windows, when you right-click on an application and choose >> 'properties' you view the version number and description of the >> application, it is a resource inside the exe). I think py2exe supports >> it. >> > > Pyinstaller supports this. > > Vesa > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reckoner at gmail.com Wed Nov 4 14:40:41 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 11:40:41 -0800 (PST) Subject: Using logging module for conditional nested logs Message-ID: Hi, I am getting started with your logging module and I went through the tutorial and know-how to create a top-level 'root' logger with the appropriate handlers. I have a number of functions,say, def foo1() def foo2() ... foo1() # foo2 calls foo1 and I know how to connect each of these functions to the 'root' logger by doing something like def foo1() logger = getLogger('root.foo1') but I want to arrange it so that foo1 adds to the logfile that foo2 is using ONLY when foo2 calls foo1. In other words, if I do def foo2() logger = getLogger('root.foo2') or def foo1() logger = getLogger('root.foo2.foo1') it responds to the 'root' logger when I want it to respond to *any* logger that is attached to foo2. Then, the question is how can I set up foo1 to log to whatever logger foo2 is using. The purpose of doing this is that I am interested in capturing when and by whom foo1 is called in whatever logger foo2 is using. So, if I attach a separate logger to a third function, say, foo3 (), then I can avoid reporting those instances when foo3 calls foo1. I hope that made some sense. From davea at ieee.org Wed Nov 4 16:03:57 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 04 Nov 2009 16:03:57 -0500 Subject: regexp help In-Reply-To: <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> References: <97FB089C6E1F404CB0132AC3BB3E5C2701873BAD@exchange.qualisystems.local> <8c7f10c60911040843y658f8f5wef66339114ca27f2@mail.gmail.com> <97FB089C6E1F404CB0132AC3BB3E5C2701873BBA@exchange.qualisystems.local> <8c7f10c60911040912ic36119w715ff5bd2613bbbd@mail.gmail.com> Message-ID: <4AF1EC3D.5070707@ieee.org> Simon Brunning wrote: > 2009/11/4 Nadav Chernin : > >> Thanks, but my question is how to write the regex. >> > > re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. > > How about: os.path.splitext(x)[1] in (".exe", ".dll", ".ocx", ".py"): DaveA From alfps at start.no Wed Nov 4 16:08:49 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 04 Nov 2009 22:08:49 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Terry Reedy: > Alf P. Steinbach wrote: > >> However, the natural semantics is that various logical properties, >> such as left, top, right, bottom, width and height, can be varied >> independently. > > But they *CANNOT* be varied independently. A rectangle with side > parallel to the axes has exactly 4 degress of freedom, not 6. Yes . That's the basic idea of the example I presented up-thread, that's discussed here. With R1's state variables width and heigh can be varied independently by direct modification, with R2 it's right and bottom. The public interface must also make this choice, but it's an independent choice: the internal rectangle representation can have the opposite choice. And conversely, that means that if the internal representation isn't used directly, then it can be changed without affecting the public interface. Cheers, - Alf From vinay_sajip at yahoo.co.uk Wed Nov 4 16:30:42 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 4 Nov 2009 13:30:42 -0800 (PST) Subject: Using logging module for conditional nested logs References: Message-ID: On Nov 4, 7:40?pm, Reckoner wrote: > > I hope that made some sense. Not especially :-( Sorry I don't understand exactly what you mean, because I find your terminology confusing. For example, "logger that is attached to foo2" - loggers are not attached to functions. "It responds to the 'root' logger" - what responds? What's meant by "respond"? Loggers correspond to specific code components in an application. Normally these areas are modules and sometimes they're classes. You can certainly treat functions as areas but this will typically become unwieldy in any sizeable application. It doesn't (in general) make sense to have a specific logger for foo1 for use only when it's called by foo2. These seem like anti-patterns to me. Handlers are attached to loggers to make events logged via those loggers available to different audiences - via console, file, email etc. If you want to log that foo1 is being called by foo2, you can do this. For example, you could have a utility function which walks (a sufficient part of) the call stack to see the function call hierarchy, then log this as additional information (e.g. using the 'extra' parameter to the logging call). You can attach Filters to loggers and handlers which use this information to decide where and whether to actually record the event. As well as the Python logging documentation, you may also find the following link useful: http://plumberjack.blogspot.com/2009/09/python-logging-101.html Regards, Vinay Sajip From aahz at pythoncraft.com Wed Nov 4 16:57:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Nov 2009 13:57:06 -0800 Subject: python os.path.exists failure References: <9aaf6a31-a34e-454b-a8f0-e206ad9b7040@t2g2000yqn.googlegroups.com> Message-ID: In article <9aaf6a31-a34e-454b-a8f0-e206ad9b7040 at t2g2000yqn.googlegroups.com>, koranthala wrote: > >path = r'C:/"Program Files"/testfolder/2.3/test.txt' >if os.path.lexists(path): > print 'Path Exists' >else: > print 'No file found in path - %s' %path >print Popen(path, stdout=PIPE, shell=True).stdout.read() Avoiding shell=True is a Good Idea -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From irmen at -nospam-xs4all.nl Wed Nov 4 17:04:49 2009 From: irmen at -nospam-xs4all.nl (Irmen de Jong) Date: Wed, 04 Nov 2009 23:04:49 +0100 Subject: disable image loading to speed up webpage load In-Reply-To: References: <26155440.post@talk.nabble.com> <7l7nklF3cgpk3U1@mid.uni-berlin.de> Message-ID: <4af1fa58$0$83241$e4fe514c@news.xs4all.nl> On 4-11-2009 8:32, elca wrote: > Diez B. Roggisch-2 wrote: >> >> Use urllib2. >> > > you can show me some more specific sample or demo? > It's not even more than 1 click away in the Python standard lib documentation... how hard can it be? http://docs.python.org/library/urllib2.html#examples -irmen From threaderslash at gmail.com Wed Nov 4 17:07:04 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 5 Nov 2009 09:07:04 +1100 Subject: problem in installing wxwidgets for python. Message-ID: This additional links should come in hand: http://www.gossamer-threads.com/lists/python/python/785413?page=last http://www.daniweb.com/forums/thread235862.html# http://forum.amule.org/index.php?topic=11728.0 http://www.linuxquestions.org/questions/linux-software-2/problem-in-installing-wxwidgets...-766666/ I hope it can help. Good luck and have fun! ThreaderSladh ---------- Forwarded message ---------- From: Ishwor Gurung To: python-list at python.org Date: Wed, 4 Nov 2009 23:11:39 +1100 Subject: Re: problem in installing wxwidgets for python.. Hi, 2009/11/4 Jebagnana Das : > Hello friends, > I've tried to install wxwidgets in my mandriva 2009 spring > for GUI interaction with python. In the installation instruction it said > that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i got > the message You probably want wxpython binding instead - http://www.wxpython.org/ Use binaries provided by Mandriva's package manager where possible unless you _really_ want to do a source installation. > checking for BASE_DEPENDENCIES... configure: error: Package requirements > (glib-2.0 >= 2.21.3 atk >= 1.13.0 pango >= 1.20 cairo >= 1.6) were > not met: > > > Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1 > > Consider adjusting the PKG_CONFIG_PATH environment variable if you > installed software in a non-standard prefix. $ export PKG_CONFIG_PATH=/usr/lib/ pkgconfig:/usr/local/lib/pkgconfig (considering that your local installs went to those directories. Try replacing those directories accordingly for glib, atk, pango and cairo). The files you're after is a ".pc" (pkg-config need them) file. A quick find will tell you where it is if it is installed. Run configure script again. > Alternatively, you may set the environment variables > BASE_DEPENDENCIES_CFLAGS > > and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config. > See the pkg-config man page for more details. > > Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I > installed all the packages using the following commands. [...] > tar xvzf filename.tar.gz > cd folder > ./configure > > make > make install Yep. Check where it installed them one by one. In short, you need access to a ".pc" file that they provide. If not, write one yourself. > I've not specified anf options like --prefix and i installed in the folder > itself. man pkg-config for further info. > when i tried to install gtk+ after installing all this it showed the same > error. What should i do to install wxwidgets? Plz. reply as soon as > possible.. Coz. i've to finish my proj. quickly.. Thanks and regards... See above. -------------- next part -------------- An HTML attachment was scrubbed... URL: From doesnotexist at franzoni.invalid Wed Nov 4 17:28:47 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Wed, 04 Nov 2009 22:28:47 GMT Subject: Pyfora, a place for python In-Reply-To: <7l89j4F3bl107U1@mid.uni-berlin.de> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > Being from germany, I can say that we *have* this fragmentation, and > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > with those visually rather noisy and IMHO suboptimal forums. E.g. it That's right... forums, although more "accessible" to all the people who can't/doesn't want to use specific email or nntp clients, are quite slow to use. But I think Ubuntu forums support threads and are kind of "channeled" between ML and webinterface... something like Google Groups; I think THAT would be a good idea. What about trying to "channel" comp.lang.python and a forum? -- Alan Franzoni contact me at public@[mysurname].eu From martin at v.loewis.de Wed Nov 4 17:47:55 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 04 Nov 2009 23:47:55 +0100 Subject: restricted mode??? In-Reply-To: References: Message-ID: <4AF2049B.1050709@v.loewis.de> > I thought that restricted mode died ages ago. > > Any ideas what could be causing this? Restricted mode is still available, and activated whenever a frame's builtins directory is different from the interpreter's; see PyFrame_IsRestricted. Regards, Martin From reckoner at gmail.com Wed Nov 4 18:14:54 2009 From: reckoner at gmail.com (Reckoner) Date: Wed, 4 Nov 2009 15:14:54 -0800 (PST) Subject: Using logging module for conditional nested logs References: Message-ID: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> On Nov 4, 1:30 pm, Vinay Sajip wrote: > On Nov 4, 7:40 pm, Reckoner wrote: > > > > > I hope that made some sense. > > Not especially :-( > > Sorry I don't understand exactly what you mean, because I find your > terminology confusing. For example, "logger that is attached to foo2" > - loggers are not attached to functions. "It responds to the 'root' > logger" - what responds? What's meant by "respond"? > > Loggers correspond to specific code components in an application. > Normally these areas are modules and sometimes they're classes. > > You can certainly treat functions as areas but this will typically > become unwieldy in any sizeable application. It doesn't (in general) > make sense to have a specific logger for foo1 for use only when it's > called by foo2. These seem like anti-patterns to me. > > Handlers are attached to loggers to make events logged via those > loggers available to different audiences - via console, file, email > etc. > > If you want to log that foo1 is being called by foo2, you can do this. > For example, you could have a utility function which walks (a > sufficient part of) the call stack to see the function call hierarchy, > then log this as additional information (e.g. using the 'extra' > parameter to the logging call). You can attach Filters to loggers and > handlers which use this information to decide where and whether to > actually record the event. > > As well as the Python logging documentation, you may also find the > following link useful: > > http://plumberjack.blogspot.com/2009/09/python-logging-101.html > > Regards, > > Vinay Sajip I appreciate your patience, as I am new to this. Your comments have put me on the right track. I will look at the link you specify. Thanks again. From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:44:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:44:50 GMT Subject: Python 3 [was Re: substituting list comprehensions for map()] References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> Message-ID: On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote: >> > from numpy import dot >> > >> > scalar = dot(vec1, vec2) >> >> Why would I want to use an already existing library that is fast, well- >> written and well-supported, when I can toss together a nasty kludge >> myself? > > Because using that library will ensure you can't migrate to Python 3 any > time soon? Why would I want to migrate to Python 3 any time soon? 2.5 and 2.6 meet my needs (so far), and the new features in Python 3 aren't especially compelling to me. Particularly if migrating to 3 requires me to re-write all the libraries, where's the advantage? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:47:52 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:47:52 GMT Subject: How to test urllib|urllib2-using code? References: Message-ID: On Wed, 04 Nov 2009 15:06:45 +0100, Lutz Horn wrote: > Hi, > > kj wrote: >> I want to write some tests for code that uses both urllib and urllib2. > > Take a look at the discussion under the title "How can one mock/stub > python module like urllib" at stackoverflow: > > http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python- module-like-urllib Oh noes!!! Ur fragmenting teh python communities!!!!1!!! DO NOT WANT!!! *grin* (And for those who don't know what on earth I'm referring to, see the thread "Pyfora, a place for python".) -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 18:50:49 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Nov 2009 23:50:49 GMT Subject: self.__dict__ tricks References: <02fa5899$0$1357$c3e8da3@news.astraweb.com> <007526ff$0$26860$c3e8da3@news.astraweb.com> <02fd0c85$0$1326$c3e8da3@news.astraweb.com> <8c7f10c60911030326k1fc75afaj689d3bebfebb9040@mail.gmail.com> Message-ID: On Wed, 04 Nov 2009 06:36:46 -0800, Ethan Furman wrote: > Dennis Lee Bieber wrote: > > Perfectly valid answer -- there are no fish as there is no Atlantic > > sea > > > Steven D'Aprano wrote: > > Once in the distant past, there were no fish in what would become the > > Atlantic Ocean (not sea) > > What's with the bias against the word 'sea'? The Atlantic Ocean is named the Atlantic Ocean, not the Atlantic Lake or Atlantic Puddle or Atlantic Dewdrop or Atlantic Sea. Otherwise, sea is a perfectly good word, for describing what the Atlantic Ocean *is* rather than what it is *named*. -- Steven From toby.o.h.white at googlemail.com Wed Nov 4 19:08:20 2009 From: toby.o.h.white at googlemail.com (tow) Date: Wed, 4 Nov 2009 16:08:20 -0800 (PST) Subject: module imports and st_mtime Message-ID: I'm seeing a very strange effect which is confusing me - in brief, one python process appears to temporarily affect the os.stat results of another - perhaps someone can enlighten me. This is on Mac OS X Leopard, using the system python (2.5) The issue arises using Django. The default Django http server runs a watcher thread, which checks if any code is changing, and reloads itself. It does this by iterating over all loaded modules, and checking the mtime of each __file__. This was behaving oddly, and finding out why exposed this strangeness. (The relevant code is in django/utils/autoreload.py) Some of the code running under this django server imports simplejson, the C-implemented module of which has been put at /Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so This hasn't been touched since it was installed: ls -l ~/.python-eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/ simplejson/_speedups.so -rwxr-xr-x 1 tow staff 77596 12 Aug 17:56 /Users/tow/.python-eggs/ simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so If I check the mtime of that file from within django, it finds it correctly: print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so").st_mtime) 2009-08-12 17:56:02 The strange effect occurs when I open another python process, and import simplejson there as well. As soon as I've done that, the mtime that Django sees slips by an hour: print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python- eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/ _speedups.so").st_mtime) 2009-08-12 16:56:02 In fact, to be precise, this happens as soon as the simplejson._speedups module *finishes* being imported. (Tested by stepping through every line with pdb) The second Python process still sees the correct mtime, though, both before and after it imports simplejson. Restarting the Django process resets its view of the world, and it sees the correct mtime again. The current time as seen by the Django process is correct both before and after the mtime slippage. This seems to be 100% reproducible here, except for the time offset. Usually it loses one hour, sometimes it gains 5 hours. (For what it's worth, I'm currently on GMT, but the file was created during daylight savings time). I haven't managed to replicate it when the first process is something other than Django. I've seen the effect on other Mac OS machines, but haven't tested it on Linux so far. I've only seen the effect with simplejson's C module, but I think this is the only C module which might be being imported twice in this way for me. Does anyone have any ideas what might be going on, or where further to look? I'm at a bit of a loss. Toby From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 19:39:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2009 00:39:25 GMT Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: > * Gabriel Genellina: >> >> I don't understand either. R1 and R2 have *different* semantics. > > Assume that they have the very exact same semantics Why would we assume that when you have explicitly told us that they don't? You stated categorically that they behave differently when you assign to the attribute/property "top". According to your own description, setting R1.top moves the rectangle, while setting R2.top resizes it. Perhaps the difference between "move" and "resize" is too subtle for you, but you can trust us on this, they are different semantics. > -- like two TV > sets that look the same and work the same except when you open 'em up > and poke around in there, oh holy cow, in this one there's stuff that > isn't in the other. Whether "top" is an attribute or a property is irrelevant, it is still part of the public API of the class. Such public attributes are NOT private internal details, they are part of the public interface. You've been told this repeatedly. Perhaps one more time may help: Public attributes are public. -- Steven From pavlovevidence at gmail.com Wed Nov 4 20:05:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 4 Nov 2009 17:05:45 -0800 (PST) Subject: module imports and st_mtime References: fb1b6b88-ccef-4f35-aaa9-b9d263969b61@k19g2000yqc.googlegroups.com Message-ID: On Nov 4, 4:08?pm, tow wrote: > Does anyone have any ideas what might be going on, or where further to > look? I'm at a bit of a loss. Does Mac OS have a concept of process-local filesystem modification? I.e. when loading the library does it create a process-local copy of the file with an updated timestamp? Only thing I can think of, and if so it's probably not something you want to turn off. Carl Banks From deets at nospam.web.de Wed Nov 4 20:41:31 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Nov 2009 02:41:31 +0100 Subject: set pdb break condition based upon number of hits? In-Reply-To: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> References: <3de95e28-b650-4816-b3e3-3bfc79398435@g1g2000pra.googlegroups.com> Message-ID: <7leoqbF3cbcagU1@mid.uni-berlin.de> Reckoner schrieb: > Is it possible to set pdb break condition based upon number of hits? I > mean something like > > (Pdb) break line_number (number_of_hits_for_this_breakpoint >10) > > any help appreciated. MY_GLOBAL_COUNTER = 0 MY_GLOBAL_COUNTER += 1 if MY_GLOBAL_COUNTER >= 10: import pdb; pdb.set_trace() Diez From alfps at start.no Wed Nov 4 20:48:00 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 02:48:00 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Steven D'Aprano: > On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: > >> * Gabriel Genellina: >>> I don't understand either. R1 and R2 have *different* semantics. >> Assume that they have the very exact same semantics > > > Why would we assume that when you have explicitly told us that they don't? > > You stated categorically that they behave differently when you assign to > the attribute/property "top". Uh, severe reading difficulties ... referring to self in plural ... Hm. :-) But anyway, in the example description I wrote "With R1 direct changes of left and top keeps the rectangle's size" and this is in the context of a discussion of modifying data attributes directly versus using properties. Anyway, if that formulation was confusing I have clarified it later, so you really, ideally, should have no problem grasping this. > According to your own description, setting > R1.top moves the rectangle, while setting R2.top resizes it. Perhaps the > difference between "move" and "resize" is too subtle for you, but you can > trust us on this, they are different semantics. No, I would absolutely not trust you Steven, whether that's plural or singular, to assign semantics to my examples. >> -- like two TV >> sets that look the same and work the same except when you open 'em up >> and poke around in there, oh holy cow, in this one there's stuff that >> isn't in the other. > > > Whether "top" is an attribute or a property is irrelevant, Sorry, that's incorrect. For example, if it is a read only property than you can't assign to the property. For another example, if it is a read/write property than it can update any parts of the rectangle represention. > it is still > part of the public API of the class. Sorry, that's incorrect; it depends on the class. > Such public attributes are NOT > private internal details, they are part of the public interface. Sorry, that's incorrect; it depends on the class, and as far as I know and have been informed here there are no private attributes in Python, just a notational convention. > You've > been told this repeatedly. Sorry, but repeating what you want me to have meant in my example, contrary to the direct text of the example, contrary to its context, choosing a meaningless interpreteration of what's left when you have ignored the text, plus contrary to further clarifications, well that's daft to say the least. > Perhaps one more time may help: > > Public attributes are public. It would be nice if Python had private ones, yes. Cheers & hth., - Alf From sebastianthegreatful at gmail.com Wed Nov 4 21:03:49 2009 From: sebastianthegreatful at gmail.com (Seb) Date: Wed, 4 Nov 2009 18:03:49 -0800 (PST) Subject: multicast Message-ID: I'm trying to implement a multicast module. I'm inspired by this blog http://chaos.weblogs.us/archives/164 I'd like to get some comments on the code so far but more importantly some suggestions on how I can implement reliable multicasting. best regards, Seb From sebastianthegreatful at gmail.com Wed Nov 4 21:05:24 2009 From: sebastianthegreatful at gmail.com (Seb) Date: Wed, 4 Nov 2009 18:05:24 -0800 (PST) Subject: multicast References: Message-ID: <63a0c482-367e-4bae-a4d8-b0e95d2d454d@z41g2000yqz.googlegroups.com> Forgot the code... doh! :) #! /usr/bin/env python import socket import time class MulticastSender(object): def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600): self.MCAST_ADDR = MCAST_ADDR self.MCAST_PORT = MCAST_PORT ANY = "0.0.0.0" SENDERPORT=1501 #create a UDP socket self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) #allow multiple sockets to use the same PORT number self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) #The sender is bound on (0.0.0.0:1501) self.sock.bind((ANY,SENDERPORT)) #Tell the kernel that we want to multicast and that the data is sent #to everyone (255 is the level of multicasting) self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255) def send(self, data): self.sock.sendto(data, (self.MCAST_ADDR, self.MCAST_PORT)); class MulticastReceiver(object): def __init__(self, MCAST_ADDR = "224.168.2.9", MCAST_PORT = 1600): ANY = "0.0.0.0" #create a UDP socket self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) #allow multiple sockets to use the same PORT number self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) #Bind to the port that we know will receive multicast data self.sock.bind((ANY,MCAST_PORT)) #tell the kernel that we are a multicast socket self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255) #Tell the kernel that we want to add ourselves to a multicast group #The address for the multicast group is the third param status = self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_ADDR) + socket.inet_aton(ANY)); self.sock.setblocking(0) def setblocking(self, flag): self.sock.setblocking(flag) def recv(self, size = 1024): return self.sock.recvfrom(size) class Multicast(object): def __init__(self): self.__ms = MulticastSender() self.__mr = MulticastReceiver() def send(self, data): self.__ms.send(data) def recv(self, size = 1024): return self.__mr.recv() if __name__ == "__main__": mc = Multicast() while 1: try: data, addr = mc.recv() except socket.error, e: #print "sock.error: ", e pass else: print "FROM: ", addr print "DATA: ", data From nad at acm.org Wed Nov 4 21:18:43 2009 From: nad at acm.org (Ned Deily) Date: Wed, 04 Nov 2009 18:18:43 -0800 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: In article , Alan Franzoni wrote: > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > Being from germany, I can say that we *have* this fragmentation, and > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > That's right... forums, although more "accessible" to all the people who > can't/doesn't want to use specific email or nntp clients, are quite slow > to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? comp.lang.python *is* already "channel"ed in multiple venues: the Usenet group itself, the base python.org mailing list, gmane.org (NNTP newsgroup from the mailing list, various web interfaces, RSS feed), google groups, and others. -- Ned Deily, nad at acm.org From ben+python at benfinney.id.au Wed Nov 4 21:25:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2009 13:25:31 +1100 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <87k4y5d7xg.fsf@benfinney.id.au> Alan Franzoni writes: > That's right... forums, although more "accessible" to all the people > who can't/doesn't want to use specific email or nntp clients, are > quite slow to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? Please, be more specific. As I said earlier in this thread, a ?forum? could be a mailing list, a Usenet newsgroup, a walled-garden web application, an IRC channel, or a face-to-face meeting in a pub. So speaking of comp.lang.python as though it's *not* a forum is confusing. Please choose a term that makes it clear why what one is speaking about is distinct from the comp.lang.python forum. -- \ ?Just because nobody complains doesn't mean all parachutes are | `\ perfect.? ?Benny Hill | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Nov 4 21:27:09 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Nov 2009 13:27:09 +1100 Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> Message-ID: <87fx8td7uq.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > >> Why would I want to use an already existing library that is fast, > >> well- written and well-supported, when I can toss together a nasty > >> kludge myself? > > > > Because using that library will ensure you can't migrate to Python 3 > > any time soon? > > Why would I want to migrate to Python 3 any time soon? Sounds like you've answered the questions posed, then. Good for you! -- \ ?The whole area of [treating source code as intellectual | `\ property] is almost assuring a customer that you are not going | _o__) to do any innovation in the future.? ?Gary Barnett | Ben Finney From alfps at start.no Wed Nov 4 21:55:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 03:55:53 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Alf P. Steinbach: > * Steven D'Aprano: >> On Wed, 04 Nov 2009 08:50:42 +0100, Alf P. Steinbach wrote: >> >>> * Gabriel Genellina: >>>> I don't understand either. R1 and R2 have *different* semantics. >>> Assume that they have the very exact same semantics >> >> >> Why would we assume that when you have explicitly told us that they >> don't? >> >> You stated categorically that they behave differently when you assign >> to the attribute/property "top". > > Uh, severe reading difficulties ... referring to self in plural ... Hm. :-) > > But anyway, in the example description I wrote > > "With R1 direct changes of left and top keeps the rectangle's size" > > and this is in the context of a discussion of modifying data attributes > directly versus using properties. Perhaps this makes it more clear: in R1, which has a width/height based rectangle representation, assigning directly to the top data attribute /effectively/ moves the rectangle vertically without changing its height, since the height attribute is unchanged. But that does not reflect any intended semantics, it's not a requirement; it's an implementation artifact, a behavior that just results from direct modification and the choice of a particular rectangle representation. Real world Python example of that kind of artifact: as discussed in some other thread here, doing open( ..., 'r+' ) followed by write followed directly by read will on some implementations/systems produce garbage. Presumably because those implementations use C "FILE*" to implement the functionality, and implements it by a fairly direct mapping of calls down to the C level, where this sequence is in general Undefined Behavior. You might regard it as semantics, and it's quite real and presumably in a sense well-defined for the particular implementation on the particular system, but it's not part of any intended semantics, and any who relies on that behavior is doing it at other's risk. For the R1 class the indended semantics, the specification that the programmer was handed down or produced or had in mind, might include just rectangle construction, checking intersection with other rectangle, and obtaining any of three pairs of values: left upper corner, right lower corner and width+height. For example. :-) Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Wed Nov 4 22:00:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Nov 2009 03:00:08 GMT Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> >> Why would I want to use an already existing library that is fast, >> >> well- written and well-supported, when I can toss together a nasty >> >> kludge myself? >> > >> > Because using that library will ensure you can't migrate to Python 3 >> > any time soon? >> >> Why would I want to migrate to Python 3 any time soon? > > Sounds like you've answered the questions posed, then. Good for you! I was actually only being *half* tongue in cheek, which is why I left out the smiley. On the python-dev list at the moment is a lot of discussion on why uptake of Python 3.1 has been slower than hoped. But one of the things that people haven't really discussed -- or at least that I haven't seen -- is why one would prefer 3.1 over 2.5 or 2.6. I've played around with 3.0, and I've read the What's New for 3.1 (and am installing 3.1 now), and while the changes look nice, I'm not sure that they're nice enough to deal with the pain of 2to3 migration. So how about that, 3.1 fans? What are the most compelling reasons for you that convinced you to change? -- Steven From wuwei23 at gmail.com Wed Nov 4 22:18:21 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 4 Nov 2009 19:18:21 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: Daniel Fetchinson wrote: > Yes, this is about the right kind of response I think everybody > deserves who puts energy/enthusiasm/effort/time into putting together > a python-related forum. So what's the right kind of response deserved by those who put energy/ enthusiasm/effort/time into sustaining _this_ python-related forum? Accusations of hostility? Second-guessing their intentions? What right do you have to demand different behaviour from that which you yourself have demonstrated? From alfps at start.no Wed Nov 4 22:33:52 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 04:33:52 +0100 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: * Steven D'Aprano: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > >> Steven D'Aprano writes: >> >>> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >>> >>>> Steven D'Aprano writes: >>>>> Why would I want to use an already existing library that is fast, >>>>> well- written and well-supported, when I can toss together a nasty >>>>> kludge myself? >>>> Because using that library will ensure you can't migrate to Python 3 >>>> any time soon? >>> Why would I want to migrate to Python 3 any time soon? >> Sounds like you've answered the questions posed, then. Good for you! > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Since I'm just learning Python and am an utter Python novice this might not amount to much, but it's in the nature of language evolution that the new more or less incompatible version *does* become the dominant one, and for new things it's then a good idea to adopt the coming in future generally used version of the language, instead of being left in a quagmire trying to catch up with new versions of tools and libs suddenly not so compatible with the old code. This happened with e.g. C++ standardization in 1998. The whole standard library was revamped and put in a namespace, and old headers like [iostream.h] were removed. And as with the Python "/" operator core language functionality was changed: in C++98 'new' suddenly threw (Pythoneese raised) an exception instead of returning 0 on failure, and templates were suddenly "two phase" with quite different semantics, so that much old code didn't even compile, and when it did, didn't work correctly. But those who chose to stay behind paid and still for some pay the price, having to use ages old tools and libs. One amusing or sad (depending one's point of view) variant was where firms chose to get along with the language evolution, tools etc., but still restrict themselves to not only pre-standard C++ but some early 1980's version, not much more than "C with classes" or "better C". For example, at Google they generally don't use C++ exceptions, presumably because they have a large code base of non-exception-safe code. Still, assuming that's the rationale, it would surprise me if they don't use exceptions in their new code. This is perhaps an heretical view, that the new language version's advantages don't matter so much as the fact that the new language version is incompatible, viewing that incompatibility as a /reason/ to change. But I think it's realistic; getting the advantages (such as with Python 3.x improved efficiency for range etc., and thus also more clear notation) is just an added bonus. Cheers & hth., - Alf From israelu at elbit.co.il Thu Nov 5 00:53:17 2009 From: israelu at elbit.co.il (iu2) Date: Wed, 4 Nov 2009 21:53:17 -0800 (PST) Subject: import from a string References: <11e4ba59-1516-4c49-b57c-023b7b2b0769@m38g2000yqd.googlegroups.com> <347bbd4b-97f4-4509-a4e6-f77c91e6206c@b2g2000yqi.googlegroups.com> Message-ID: <8851a23b-7935-4e82-9647-4ce0cc3365d6@a31g2000yqn.googlegroups.com> On Nov 4, 8:51?pm, Terry Reedy wrote: > Gabriel Genellina wrote: > > En Wed, 04 Nov 2009 02:45:23 -0300, iu2 escribi?: > >> On Nov 4, 3:10 am, "Gabriel Genellina" wrote: > > >>> txt = """ > >>> def foo(x): > >>> ? ?print 'x=', x > > >>> def bar(x): > >>> ? ?return x + x > >>> """ > > >>> py> namespace = {} > >>> py> exec txt in namespace > >>> py> namespace.keys() > >>> ['__builtins__', 'foo', 'bar'] > >>> py> namespace['foo']('hello') > >>> x= hello > > >> What happens if both global and local dictionaries are supplied: where > >> are the newly created entities created? In the local dict? > > > The amazing thing about Python is how easy is to experiment in the > > interpreter. > > Just see it by yourself! > > Hint: they are created in the same namespace they always are (ignoring > nested functions and nonlocal namespaces). But I agree with Gabriel: > just try it. n1,n2={},{}; exec.... > > Terry Jan Reedy- Hide quoted text - > > - Show quoted text - n2 :-) From mensanator at aol.com Thu Nov 5 01:25:46 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 4 Nov 2009 22:25:46 -0800 (PST) Subject: Python 3 References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: <56f7b929-025c-4ae4-bbba-9f46d8eea0db@z41g2000yqz.googlegroups.com> On Nov 4, 9:00?pm, Steven D'Aprano wrote: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > > Steven D'Aprano writes: > > >> On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: > > >> > Steven D'Aprano writes: > >> >> Why would I want to use an already existing library that is fast, > >> >> well- written and well-supported, when I can toss together a nasty > >> >> kludge myself? > > >> > Because using that library will ensure you can't migrate to Python 3 > >> > any time soon? > > >> Why would I want to migrate to Python 3 any time soon? > > > Sounds like you've answered the questions posed, then. Good for you! > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Itertools is worth the price of admission. As far as the "pain of migration" is concerned, less annoying than a mosquito bite. > > -- > Steven- Hide quoted text - > > - Show quoted text - From jitu.icfai at gmail.com Thu Nov 5 01:29:50 2009 From: jitu.icfai at gmail.com (jitendra gupta) Date: Thu, 5 Nov 2009 11:59:50 +0530 Subject: a is b In-Reply-To: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> References: <50697b2c0911041042y2fb67adal5829e4312c695cfc@mail.gmail.com> Message-ID: Hi Sebas >>> w = "q" >>>a = "q" >>>id(w) 11160864 >>>id(a) 11160864 >>> z = "big string" >>> s = "big string" >>> id(z) 13675120 >>> id(s) 13674520 This is applicable for number also.. , python caches is using same id for small numbers and string. Jitendra Kumar On Thu, Nov 5, 2009 at 12:12 AM, Chris Rebert wrote: > On Wed, Nov 4, 2009 at 10:37 AM, Sebastian wrote: > > I have a question from the pyar list that may have been discussed on > this > > list, but i didn't catch it. > > Have some common objects been somewhat hardcoded into python, like some > > integers as shown in the examples below? What other object have been > > hardcoded (strings ,etc) and what was the criteria used to select them? > Any > > hints? > > See recent thread on the subject: > http://www.mail-archive.com/python-list at python.org/msg264434.html > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Thu Nov 5 02:33:26 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 5 Nov 2009 13:03:26 +0530 Subject: Python 3 Message-ID: Steven D'Aprano wrote: > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Why I am back on 2.5/2.6 Case 1 I need to use the library construct for parsing binary files http://construct.wikispaces.com/ I tried porting it to python 3 but was not successful. Dont pretend to have tried very hard but... 1. The library is quite well written but I dont know its internals 2. In fact I am just familiarisng myself with its usage 3. Intricacies of 2to3 changes their whys and wherefores are quite foreign to me -- specifically unicode matters have always frightened me. Case 2 I prefer to use python-mode in emacs for development python 3 has broken python-mode by removing execfile I suggested a (1-line) fix https://bugs.launchpad.net/python-mode/+bug/450552 Its still pending. Case 3 Python3 has a windows installer but no deb packages for ubuntu/debian I installed with the installer on windows and compiled the sources on linux (with some help of this list) However compilation takes time and converts my laptop into a toaster Given the above 2 cases I seem to have wasted the wearntear of my laptop. Summary: The attraction of python is not primarily in the language. Its not even in the batteries that are *included* but the non-included ones that are available. If that set is significantly sparser for 3 than for 2.x I dont see how many people can adopt it even if they wish to [Excludes the academics in ivory towers who discuss the subtle qualities of different languages. Been-there-done-that (was in a university for 20 years) and if I was in that context I would not use 2 or 3 but lisp, haskell or some other beautiful wonderment from arcanaland] From gagsl-py2 at yahoo.com.ar Thu Nov 5 02:34:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 04:34:16 -0300 Subject: Tkinter callback arguments References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: En Wed, 04 Nov 2009 18:08:49 -0300, Alf P. Steinbach escribi?: > * Terry Reedy: >> Alf P. Steinbach wrote: >> >>> However, the natural semantics is that various logical properties, >>> such as left, top, right, bottom, width and height, can be varied >>> independently. >> But they *CANNOT* be varied independently. A rectangle with side >> parallel to the axes has exactly 4 degress of freedom, not 6. > > Yes . That's the basic idea of the example I presented up-thread, > that's discussed here. With R1's state variables width and heigh can be > varied independently by direct modification, with R2 it's right and > bottom. > > The public interface must also make this choice, but it's an independent > choice: the internal rectangle representation can have the opposite > choice. > > And conversely, that means that if the internal representation isn't > used directly, then it can be changed without affecting the public > interface. And that's exactly what everyone is saying - so we all agree then! -- Gabriel Genellina From peter at www.pjb.com.au Thu Nov 5 02:45:02 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 05 Nov 2009 07:45:02 GMT Subject: MIDI.py version 3.4 Message-ID: Version 3.4 of the Python3 module MIDI.py is available through http://www.pjb.com.au/midi/MIDI.html and is believed to be pretty stable - in other words, I've actually tested it :-) (against Sean Burke's MIDI-Perl CPAN module) and it passes the tests. It's used by midisox: http://www.pjb.com.au/midi/midisox.html which can therefore also be considered increasingly stable. MIDI.py breaks out the .mid data into a simple list-of-lists structure, e.g. (in the closer-to-the-data "opus" format) [ 96, # Ticks [ # Track 0... ['note_on', 6, 1, 60, 100], ['note_off', 192, 1, 60, 100] ] ] which you can manipulate using all the resources of Python3, and then reconvert into MIDI. Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From georgeolivergo at gmail.com Thu Nov 5 03:10:54 2009 From: georgeolivergo at gmail.com (George Oliver) Date: Thu, 5 Nov 2009 00:10:54 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> Message-ID: <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> I think it's long past the point where you could contain everyone who uses Python into a single community even if you tried. Besides, everyone knows about python-forum.org, right? ;) From gagsl-py2 at yahoo.com.ar Thu Nov 5 03:16:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 05:16:08 -0300 Subject: How to test urllib|urllib2-using code? References: Message-ID: En Wed, 04 Nov 2009 10:33:53 -0300, kj escribi?: > I'm sure I could find > some good answers to my question above if I could look at the test > suites for urllib and urllib2, but I can't find them anywhere. In > fact, I don't even know what exactly I should be looking for.) > Where can I find the equivalent for Python distributions? Most of the Python test suite is in the "test" subdirectory below the standard library; on Windows that's c:\PythonNN\Lib\test, on Linux /usr/lib/pythonN.N/test or /usr/local/... > dir /s/b test_url*.py D:\apps\Python26\Lib\test\test_urllib.py D:\apps\Python26\Lib\test\test_urllib2.py D:\apps\Python26\Lib\test\test_urllib2net.py D:\apps\Python26\Lib\test\test_urllib2_localnet.py D:\apps\Python26\Lib\test\test_urllibnet.py D:\apps\Python26\Lib\test\test_urlparse.py -- Gabriel Genellina From rpjday at crashcourse.ca Thu Nov 5 03:26:47 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 5 Nov 2009 03:26:47 -0500 (EST) Subject: starting with python 3.1 vs 3.2, and "test_telnetlib" Message-ID: a couple short questions. on my primary linux distro -- fedora -- python 2.x is going to be around for quite some time, but if some folks want to *start* programming in python, it seems reasonable to just co-install python 3.x and let them cut their teeth on that, invoking it with "python3". does that make sense as there seems to be little value in getting started on python 2.x. and in terms of installing python 3.x, just for fun, i used "svn" to check out the two relevant repositories: * release31-maint (for 3.1) * py3k (for 3.2) since i figured, if people are going to be using this strictly for hacking around, i can live life on the edge. however, on my f11 system, doing the configure/make/make test sequence, the 3.1 maintenance release failed two tests: multiprocessing and telnetlib, while the 3.2 branch failed only the telnetlib test. i've checked and, apparently, that telnetlib test failure has been around for a while. is there a tweak i can make to the configure and/or make to avoid that test? it would be nice to resolve it as it's the only test out of 315 that failed for me. rday p.s. the test output for telnetlib on the py3k (3.2) branch: test_telnetlib test test_telnetlib failed -- Traceback (most recent call last): File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 470, in test_debuglevel_reads self._test_debuglevel([a, EOF_sigil], b) File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 451, in _test_debuglevel txt = telnet.read_all() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 325, in read_all self.fill_rawq() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 516, in fill_rawq buf = self.sock.recv(50) socket.error: [Errno 104] Connection reset by peer i'm not running telnet on this host, and i have no intention of doing so -- it's all ssh, of course. is that what this test error is complaining about -- that it can't find a listening telnet server? -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From alfps at start.no Thu Nov 5 04:04:15 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 10:04:15 +0100 Subject: Tkinter callback arguments In-Reply-To: References: <7l83sqF3bac80U1@mid.uni-berlin.de> <7l881tF3dbb00U1@mid.uni-berlin.de> <7l942mF3c94mlU1@mid.uni-berlin.de> Message-ID: * Gabriel Genellina: > En Wed, 04 Nov 2009 18:08:49 -0300, Alf P. Steinbach > escribi?: >> * Terry Reedy: >>> Alf P. Steinbach wrote: >>> >>>> However, the natural semantics is that various logical properties, >>>> such as left, top, right, bottom, width and height, can be varied >>>> independently. >>> But they *CANNOT* be varied independently. A rectangle with side >>> parallel to the axes has exactly 4 degress of freedom, not 6. >> >> Yes . That's the basic idea of the example I presented up-thread, >> that's discussed here. With R1's state variables width and heigh can >> be varied independently by direct modification, with R2 it's right and >> bottom. >> >> The public interface must also make this choice, but it's an >> independent choice: the internal rectangle representation can have the >> opposite choice. >> >> And conversely, that means that if the internal representation isn't >> used directly, then it can be changed without affecting the public >> interface. > > And that's exactly what everyone is saying - so we all agree then! Well, it may be that we *violently* agree. :-) Cheers, - Alf From gagsl-py2 at yahoo.com.ar Thu Nov 5 04:15:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 06:15:25 -0300 Subject: Cast into custom type References: <4aeffad1$0$6577$9b4e6d93@newsspool3.arcor-online.net> <02fff1ce$0$1326$c3e8da3@news.astraweb.com> <4af01ce5$0$6577$9b4e6d93@newsspool3.arcor-online.net> <4af18733$0$6591$9b4e6d93@newsspool3.arcor-online.net> Message-ID: En Wed, 04 Nov 2009 10:52:51 -0300, Henning Bredel escribi?: > On Tue, 03 Nov 2009 21:31:27 -0300, Gabriel Genellina wrote: >> >> Then forget about the code you read in that blog post, doesn't apply to >> your use case. > > Well, but it shows how to mount plugins into the application without > creating instances instantly. I only use one plugin/module at a time, > so I'd like to avoid holding instances which aren't used. Ah, I see. Well, but you don't have to do anything special to collect plugin subclasses -- somebaseclass.__subclasses__() returns a list with all direct subclasses, without requiring a custom metaclass. This recipe [1] shows how to recursively collect all of them. (Perhaps some people prefer the metaclass approach, but not me) > Yes, I get your point. But you instantiate all available plugins. I'd > like > to avoid that. Will a callable like `plugin().initialize' avoid > that, or is an instance created immediately when passing this callable? plugin().initialize() creates a plugin instance, calls its initialize method, and then discards the instance. You probably want to create a plugin instance, store it somewhere as the "current plugin", call its initialize method, and use the "current plugin" to do some work. (Or, are the missing () after plugin().initialize intentional? Yes, this is a bound method, and it knows the plugin instance from which you got it. The instance is created at the time you ask for the bound method. You may call it later at any time. I'd probably use a bound method like that only if "initialize" is the only method you ever call on the plugin instance. In other cases, I'd store a plugin instance somewhere as described above. > Well, as far I understand it, I'd say that the ActionProvider class from > the blogpost is the (nearly) the same as your Plugin base class. All new > plugins has to implement the abstract ActionProvider class. The module > loading/recognizing is done by my main application. So what would be the > main difference here? Instead of relying on a custom metaclass, I excplicitely scan all module objects, testing for subclasses. That's all my code does, no rocket science involved :) [1] http://code.activestate.com/recipes/576949/ -- Gabriel Genellina From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 04:23:44 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 10:23:44 +0100 Subject: Web development with Python 3.1 In-Reply-To: References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> Message-ID: <4af2999c$0$11893$426a34cc@news.free.fr> rustom a ?crit : > On Oct 30, 6:23 pm, Dotan Cohen wrote: > >> The point is that I want to use only _Python_ features, not >> Django/Mako/whatever features. > > Pure python has a builtin templating system -- its called % Poor man's template... It only do variable substitutions - no branching nor iteration (and let's not talk about macros, inclusions, filters etc). From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 04:25:21 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 10:25:21 +0100 Subject: join , split question In-Reply-To: References: Message-ID: <4af299fc$0$11893$426a34cc@news.free.fr> elca a ?crit : > Hello, > i have some text file list such like following format. > i want to change text format to other format. > i was upload it pastebin site > http://elca.pastebin.com/d71261168 Dead link. > if anyone help With what ? From threaderslash at gmail.com Thu Nov 5 04:31:22 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 5 Nov 2009 20:31:22 +1100 Subject: Clean PyQt selection comboBox Message-ID: Hello Everybody, [image: 8)] I am using Qt and need to build a selection comboBox -- e.g.: http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG . The problem is - after one choice was made, and the code run, for the next time the user select a different choice, both, the present and all past choices run. See what I mean: [image: ;(] Code: selected color - blue we are on runBlue selected color - red we are on runBlue we are on runRed Here is the code: ......................................... QtCore.QObject.connect(self.selectComboBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.combo_activateInput) ......................................... def combo_activateInput(self): color=unicode(self.selectComboBox.currentText()) if(color == "blue"): print "selected color - blue" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) if(color == "red"): print "selected color - red" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runRed) if(color == "yellow"): print "selected color - yellow" QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runYellow) del color ......................................... def combo_runBlue(self): print "we are on runBlue" def combo_runRed(self): print "we are on runRed" def combo_runYellow(self): print "we are on runYellow" I run "del color" to clean the content returned by selectComboBox.currentText, but it didn't clean the content indeed. So, any suggestion? All comments and suggestions are highly appreciated. [image: :D] [image: :D] [image: :D] -------------- next part -------------- An HTML attachment was scrubbed... URL: From tartley at tartley.com Thu Nov 5 04:47:06 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 5 Nov 2009 01:47:06 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <2f382bd8-07d0-4d5f-9448-c3a7e1589076@j19g2000yqk.googlegroups.com> <4af163cc$0$6279$4f793bc4@news.tdc.fi> Message-ID: <1076c0fe-81f5-4d75-94ab-a82c15439505@k17g2000yqb.googlegroups.com> On Nov 4, 11:21?am, Vesa K?pp? wrote: > iu2 wrote: > > Another thing that I think is of interest is whether the application > > support modifying the version and description of the exe (that is, on > > Windows, when you right-click on an application and choose > > 'properties' you view the version number and description of the > > application, it is a resource inside the exe). I think py2exe supports > > it. > > Pyinstaller supports this. > > Vesa Thanks all for the inputs. I've updated my little chart and will continue to refine and fill in the blanks. From robin at reportlab.com Thu Nov 5 04:50:42 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Nov 2009 09:50:42 +0000 Subject: restricted mode??? In-Reply-To: <4AF2049B.1050709@v.loewis.de> References: <4AF2049B.1050709@v.loewis.de> Message-ID: <4AF29FF2.3050109@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >> I thought that restricted mode died ages ago. >> >> Any ideas what could be causing this? > > Restricted mode is still available, and activated whenever > a frame's builtins directory is different from the interpreter's; > see PyFrame_IsRestricted. > > Regards, > Martin thanks very much, I saw some references to mod_python & threading related to this, but nothing very obvious. -- Robin Becker From robin at reportlab.com Thu Nov 5 04:50:42 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 05 Nov 2009 09:50:42 +0000 Subject: restricted mode??? In-Reply-To: <4AF2049B.1050709@v.loewis.de> References: <4AF2049B.1050709@v.loewis.de> Message-ID: <4AF29FF2.3050109@chamonix.reportlab.co.uk> Martin v. L?wis wrote: >> I thought that restricted mode died ages ago. >> >> Any ideas what could be causing this? > > Restricted mode is still available, and activated whenever > a frame's builtins directory is different from the interpreter's; > see PyFrame_IsRestricted. > > Regards, > Martin thanks very much, I saw some references to mod_python & threading related to this, but nothing very obvious. -- Robin Becker From eight32 at gmail.com Thu Nov 5 04:54:50 2009 From: eight32 at gmail.com (Stuart Murray-Smith) Date: Thu, 5 Nov 2009 11:54:50 +0200 Subject: join , split question In-Reply-To: <4af299fc$0$11893$426a34cc@news.free.fr> References: <4af299fc$0$11893$426a34cc@news.free.fr> Message-ID: >> Hello, i have some text file list such like following format. >> i want to change text format to other format. >> ?i was upload it pastebin site >> http://elca.pastebin.com/d71261168 > Dead link. > With what ? http://elca.pastebin.com/d4d57929a :) From jeanmichel at sequans.com Thu Nov 5 05:10:33 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 05 Nov 2009 11:10:33 +0100 Subject: Using logging module for conditional nested logs In-Reply-To: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> References: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> Message-ID: <4AF2A499.3000701@sequans.com> Reckoner wrote: > On Nov 4, 1:30 pm, Vinay Sajip wrote: > >> On Nov 4, 7:40 pm, Reckoner wrote: >> >> >> >> >>> I hope that made some sense. >>> >> Not especially :-( >> >> Sorry I don't understand exactly what you mean, because I find your >> terminology confusing. For example, "logger that is attached to foo2" >> - loggers are not attached to functions. "It responds to the 'root' >> logger" - what responds? What's meant by "respond"? >> >> Loggers correspond to specific code components in an application. >> Normally these areas are modules and sometimes they're classes. >> >> You can certainly treat functions as areas but this will typically >> become unwieldy in any sizeable application. It doesn't (in general) >> make sense to have a specific logger for foo1 for use only when it's >> called by foo2. These seem like anti-patterns to me. >> >> Handlers are attached to loggers to make events logged via those >> loggers available to different audiences - via console, file, email >> etc. >> >> If you want to log that foo1 is being called by foo2, you can do this. >> For example, you could have a utility function which walks (a >> sufficient part of) the call stack to see the function call hierarchy, >> then log this as additional information (e.g. using the 'extra' >> parameter to the logging call). You can attach Filters to loggers and >> handlers which use this information to decide where and whether to >> actually record the event. >> >> As well as the Python logging documentation, you may also find the >> following link useful: >> >> http://plumberjack.blogspot.com/2009/09/python-logging-101.html >> >> Regards, >> >> Vinay Sajip >> > > I appreciate your patience, as I am new to this. > > Your comments have put me on the right track. I will look at the link > you specify. > > Thanks again. > _foo2Logger = None def foo2(): global _foo2Logger _foo2Logger = whateverLogger foo1() def foo1(): foo1Logger = logging.getLogger(_foo2Logger.name + '.foo1') # this is how you can "attach" dynamically a logger to another foo1Logger.info('') But for all the reasons expressed by Vinay, you don't want to do that. Jean-Michel From rustompmody at gmail.com Thu Nov 5 05:54:55 2009 From: rustompmody at gmail.com (rustom) Date: Thu, 5 Nov 2009 02:54:55 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> Message-ID: <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> On Nov 5, 2:23?pm, Bruno Desthuilliers wrote: > rustom a ?crit : > > > On Oct 30, 6:23 pm, Dotan Cohen wrote: > > >> The point is that I want to use only _Python_ features, not > >> Django/Mako/whatever features. > > > Pure python has a builtin templating system -- its called ?% > > Poor man's template... It only do variable substitutions - no branching > nor iteration (and let's not talk about macros, inclusions, filters etc). I realised that that link http://simonwillison.net/2003/Jul/28/simpleTemplates/ was written in 2003 Subsequently python has sprouted something explicitly templateish http://docs.python.org/library/string.html#template-strings From deets at nospam.web.de Thu Nov 5 06:08:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 05 Nov 2009 12:08:04 +0100 Subject: About one class/function per module References: <4aeea07e$0$713$426a34cc@news.free.fr> <7l852dF3c5gi1U1@mid.uni-berlin.de> <4AEEF493.5010505@sequans.com> <366c6f340911021706y3360ba7fga28557607ad0b9e4@mail.gmail.com> Message-ID: <7lfq0kF3d079sU1@mid.uni-berlin.de> Jean-Michel Pichavant wrote: > Peng Yu wrote: >> With some automated script, I don't think it is a nightmare to change >> function names. I can change function names and filenames and their >> reference with a simple command. >> >> I'd think that this is the limitation of current version control >> system. I don't aware of any version control system that allows easy >> change of filenames. But why such features can not be implemented in >> the version control system? >> > > So one function per files bring so many problems that you need an > automated script to change one function name and complain about version > control systems messing up with your file history. > Still you insist on stating that this is the solution and that version > control system have to adapt. > It has already been told to you, and you should really consider the > following advice: > When everything is wrong except you, it may happen that *your* are > somehow wrong. > > Among all the responses you got, I don't remember any one that would > suggest you are in the right way. So what is your conclusion now ? Simple: not only are the languages he uses not proper, nor the revision control systems, and neither the editors/IDEs out there - the whole communities are of course also dysfunctional, not supporting his cause :) Diez From doesnotexist at franzoni.invalid Thu Nov 5 06:47:22 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Thu, 05 Nov 2009 11:47:22 GMT Subject: Pyfora, a place for python In-Reply-To: <87k4y5d7xg.fsf@benfinney.id.au> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <87k4y5d7xg.fsf@benfinney.id.au> Message-ID: On 11/5/09 3:25 AM, Ben Finney wrote: Please, be more specific. As I said earlier in this thread, a ?forum? > could be a mailing list, a Usenet newsgroup, a walled-garden web > application, an IRC channel, or a face-to-face meeting in a pub. > > So speaking of comp.lang.python as though it's *not* a forum is > confusing. Please choose a term that makes it clear why what one is > speaking about is distinct from the comp.lang.python forum. Ok, when speaking about "forums" I meant a web-accessible public discussion group, something like those based on phpBB or Invision. But, as they correctly told me, this newgroup/mailing list is already web-accessible via Google Groups, so there would be no need for other web-based mirrors. -- Alan Franzoni contact me at public@[mysurname].eu From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 07:16:36 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 13:16:36 +0100 Subject: Web development with Python 3.1 In-Reply-To: <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> Message-ID: <4af2c21f$0$4917$426a74cc@news.free.fr> rustom a ?crit : > On Nov 5, 2:23 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> rustom a ?crit : >> >>> On Oct 30, 6:23 pm, Dotan Cohen wrote: >>>> The point is that I want to use only _Python_ features, not >>>> Django/Mako/whatever features. >>> Pure python has a builtin templating system -- its called % >> Poor man's template... It only do variable substitutions - no branching >> nor iteration (and let's not talk about macros, inclusions, filters etc). > > I realised that that link > http://simonwillison.net/2003/Jul/28/simpleTemplates/ > was written in 2003 > > Subsequently python has sprouted something explicitly templateish > http://docs.python.org/library/string.html#template-strings Still poor man's template. Just don't hope to do any realworld web templating with this. From rustompmody at gmail.com Thu Nov 5 07:38:40 2009 From: rustompmody at gmail.com (rustom) Date: Thu, 5 Nov 2009 04:38:40 -0800 (PST) Subject: Web development with Python 3.1 References: <4AE4E4A7.5060708@baselinedata.co.uk> <4ae82bcb$0$712$426a74cc@news.free.fr> <7kr09vF3as5smU1@mid.uni-berlin.de> <880dece00910281242t7dc5829eh1388c1dab9674924@mail.gmail.com> <4ae9580e$0$29446$426a74cc@news.free.fr> <4ae9a6aa$0$279$426a74cc@news.free.fr> <4af2999c$0$11893$426a34cc@news.free.fr> <15dccbe5-2e05-4d94-9f65-b1e775b38366@u36g2000prn.googlegroups.com> <4af2c21f$0$4917$426a74cc@news.free.fr> Message-ID: On Nov 5, 5:16?pm, Bruno Desthuilliers wrote: > rustom a ?crit : > > > > > On Nov 5, 2:23 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > >> rustom a ?crit : > > >>> On Oct 30, 6:23 pm, Dotan Cohen wrote: > >>>> The point is that I want to use only _Python_ features, not > >>>> Django/Mako/whatever features. > >>> Pure python has a builtin templating system -- its called ?% > >> Poor man's template... It only do variable substitutions - no branching > >> nor iteration (and let's not talk about macros, inclusions, filters etc). > > > I realised that that link > >http://simonwillison.net/2003/Jul/28/simpleTemplates/ > > was written in 2003 > > > Subsequently python has sprouted something explicitly templateish > >http://docs.python.org/library/string.html#template-strings > > Still poor man's template. Just don't hope to do any realworld web > templating with this. This is said in the context of some of Dotan's quotes eg. > I am not a programmer by trade, only by hobby. > I want to learn Python not Django etc Python is generally imperative. Templates are by and large declarative. To get this 'Aha' across to him (remember he said hes a mechanical engineer) is (IMHO) more important than converting him to some moral high ground of reusability or some other nice software engineering jargon. From fetchinson at googlemail.com Thu Nov 5 08:10:17 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 5 Nov 2009 14:10:17 +0100 Subject: Pyfora, a place for python In-Reply-To: <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> Message-ID: > I think it's long past the point where you could contain everyone who > uses Python into a single community even if you tried. > > Besides, everyone knows about python-forum.org, right? ;) Well, no, I actually didn't :) There! Another fragmenter! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From paul at boddie.org.uk Thu Nov 5 08:48:05 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 5 Nov 2009 05:48:05 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> <87k4y5d7xg.fsf@benfinney.id.au> Message-ID: On 5 Nov, 12:47, Alan Franzoni wrote: > > Ok, when speaking about "forums" I meant a web-accessible public > discussion group, something like those based on phpBB or Invision. > > But, as they correctly told me, this newgroup/mailing list is already > web-accessible via Google Groups, so there would be no need for other > web-based mirrors. I think that the community should try and make people more aware of the options. For example: http://www.python.org/community/lists/ http://wiki.python.org/moin/MailingListsAndNewsgroups (These resources need work, of course, and I encourage people to edit the Wiki-based resources and make them better.) Certainly, it's possible to read existing discussion venues - to avoid the overloaded term "forum" ;-) - using Web browsers, and I've seen Nabble promoted in some communities for this very purpose when people wanted to set up a "Web forum" because they didn't like mailing lists. I find Web forums inefficient, often full of "low-density" content (which then clogs up search results), and many of them give the impression that they won't be around for very long anyway. That said, there can still be understandable reasons why people want to have such forums, not limited to cultivating a small-scale community with an emphasis on getting to know others who are at the same level of expertise, typically with a social dimension that probably seems superfluous to those of us who use comp.lang.python and prefer that the discussion mostly remains focused on the topic of the group. Paul From bruno.42.desthuilliers at websiteburo.invalid Thu Nov 5 09:08:06 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 05 Nov 2009 15:08:06 +0100 Subject: join , split question In-Reply-To: References: <4af299fc$0$11893$426a34cc@news.free.fr> Message-ID: <4af2dc40$0$21867$426a34cc@news.free.fr> Stuart Murray-Smith a ?crit : >>> Hello, i have some text file list such like following format. >>> i want to change text format to other format. >>> i was upload it pastebin site >>> http://elca.pastebin.com/d71261168 > >> Dead link. > >> With what ? > > http://elca.pastebin.com/d4d57929a > Yeah, fine. And where's the code you or the OP (if not the same person) have problems with ? From paul at boddie.org.uk Thu Nov 5 09:26:12 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 5 Nov 2009 06:26:12 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <54b5ecab-bd7b-4106-9401-785e9813823d@c3g2000yqd.googlegroups.com> On 3 Nov, 16:58, Jonathan Hartley wrote: > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... Nice comparison! Perhaps this could join the material on the Wiki eventually: http://wiki.python.org/moin/DistributionUtilities If you don't want to spend time marking the table up, I'm sure I could help you out. Paul From jaybode at gmail.com Thu Nov 5 09:37:46 2009 From: jaybode at gmail.com (jay) Date: Thu, 5 Nov 2009 06:37:46 -0800 (PST) Subject: list to table Message-ID: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Hi All, Am new to using newgroup for help, but have exhausted my searching online for a solution I have a long list of data of associations between values with a value to that association as follows.. (var) to (var) = (var) hits A B 1 B A 1 A B 3 B A 3 A C 7 C A 2 And need to build a table as follows that accumulates the above: row is (from) column is (to) A B C A 0 4 7 B 4 0 0 C 2 0 0 Just can't seam to figure out how to manage this programatically. Any help or guidance much appreciated !!! Cheers, Jay From fabiofz at gmail.com Thu Nov 5 09:45:31 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 5 Nov 2009 12:45:31 -0200 Subject: Python 2.6 Global Variables In-Reply-To: References: Message-ID: On Wed, Oct 28, 2009 at 10:50 PM, mattofak wrote: > Hi All; > > I'm new to Python and moving from C, which is probably a big source of > my confusion. I'm struggling with something right now though and I > hope you all can help. > > I have a global configuration that I would like all my classes and > modules to be able to access. What is the correct way to do this? > > Thanks; > Matthew Walker > -- > http://mail.python.org/mailman/listinfo/python-list > I'd usually use the singleton pattern in this case (or you can just create a class and put things in the class -- and just as a note, I'd try to avoid declaring anything as global unless really needed). Cheers, Fabio From no.email at please.post Thu Nov 5 10:15:56 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:15:56 +0000 (UTC) Subject: How to test urllib|urllib2-using code? References: Message-ID: In Lutz Horn writes: >Hi, >kj wrote: >> I want to write some tests for code that uses both urllib and >> urllib2. >Take a look at the discussion under the title "How can one mock/stub >python module like urllib" at stackoverflow: >http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python-module-like-urllib Thanks, that helped. kynn From no.email at please.post Thu Nov 5 10:16:49 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:16:49 +0000 (UTC) Subject: How to test urllib|urllib2-using code? References: Message-ID: In "Gabriel Genellina" writes: >En Wed, 04 Nov 2009 10:33:53 -0300, kj escribi?: >> I'm sure I could find >> some good answers to my question above if I could look at the test >> suites for urllib and urllib2, but I can't find them anywhere. In >> fact, I don't even know what exactly I should be looking for.) >> Where can I find the equivalent for Python distributions? >Most of the Python test suite is in the "test" subdirectory below the >standard library; on Windows that's c:\PythonNN\Lib\test, on Linux >/usr/lib/pythonN.N/test or /usr/local/... >> dir /s/b test_url*.py >D:\apps\Python26\Lib\test\test_urllib.py >D:\apps\Python26\Lib\test\test_urllib2.py >D:\apps\Python26\Lib\test\test_urllib2net.py >D:\apps\Python26\Lib\test\test_urllib2_localnet.py >D:\apps\Python26\Lib\test\test_urllibnet.py >D:\apps\Python26\Lib\test\test_urlparse.py Muy agradecido, kynn From no.email at please.post Thu Nov 5 10:24:02 2009 From: no.email at please.post (kj) Date: Thu, 5 Nov 2009 15:24:02 +0000 (UTC) Subject: Read handle concatenation Message-ID: I want to be able to take two or more open read handles and concatenate them into an object that behaves like a regular read handle (i.e. a file object open for reading), but behind the scenes it reads from the concatenated handles in sequence. I.e. I want the read-handle equivalent of the standard Unix utility cat. (The reason I can't use subprocess and cat for this is that I want to concatenate read handles that do not necessarily come from files.) The only way I know to do this from scratch is straightforward but tedious, so I thought I'd better ask to see if there's already some module that would facilitate this task. TIA! kynn From Scott.Daniels at Acm.Org Thu Nov 5 10:33:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 05 Nov 2009 07:33:40 -0800 Subject: list to table In-Reply-To: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: jay wrote: > ... > I have a long list of data of associations between values with a value > to that association as follows... > A B 1 > B A 1 > ... And need to build a table as follows that accumulates the above: > > row is (from) > column is (to) > > A B C > A 0 4 7 > B 4 0 0 > C 2 0 0 > > Just can't seam to figure out how to manage this programatically. How to solve this: Define (quite carefully) what you mean by "build a table" for yourself. Then, determine a single step that either gets you closer to the answer (going forward) or (working backward) determine something (typically some data structure) that you could use to produce the result you need. Keep pushing at both ends until you can get them to meet in the middle. --Scott David Daniels Scott.Daniels at Acm.Org From joncle at googlemail.com Thu Nov 5 10:33:41 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 07:33:41 -0800 (PST) Subject: Read handle concatenation References: Message-ID: On Nov 5, 3:24?pm, kj wrote: > I want to be able to take two or more open read handles and > concatenate them into an object that behaves like a regular read > handle (i.e. a file object open for reading), but behind the scenes > it reads from the concatenated handles in sequence. ?I.e. I want > the read-handle equivalent of the standard Unix utility cat. ?(The > reason I can't use subprocess and cat for this is that I want to > concatenate read handles that do not necessarily come from files.) > > The only way I know to do this from scratch is straightforward but > tedious, so I thought I'd better ask to see if there's already some > module that would facilitate this task. > > TIA! > > kynn Does the fileinput module do what you want? From python at mrabarnett.plus.com Thu Nov 5 10:37:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 05 Nov 2009 15:37:49 +0000 Subject: Clean PyQt selection comboBox In-Reply-To: References: Message-ID: <4AF2F14D.6090202@mrabarnett.plus.com> Threader Slash wrote: > Hello Everybody, 8) > > I am using Qt and need to build a selection comboBox -- e.g.: > http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG . > > The problem is - after one choice was made, and the code run, for the > next time the user select a different choice, both, the present and all > past choices run. See what I mean: ;( > > Code: > > selected color - blue > we are on runBlue > > selected color - red > we are on runBlue > we are on runRed > > > Here is the code: > > ......................................... > QtCore.QObject.connect(self.selectComboBox, > QtCore.SIGNAL("currentIndexChanged(QString)"), > self.combo_activateInput) > ......................................... > > def combo_activateInput(self): > color=unicode(self.selectComboBox.currentText()) > if(color == "blue"): > print "selected color - blue" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) > > if(color == "red"): > print "selected color - red" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runRed) > if(color == "yellow"): > > print "selected color - yellow" > QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runYellow) > del color > ......................................... > > def combo_runBlue(self): > print "we are on runBlue" > > def combo_runRed(self): > print "we are on runRed" > > def combo_runYellow(self): > print "we are on runYellow" > > I run "del color" to clean the content returned by > selectComboBox.currentText, but it didn't clean the content indeed. > "del color" doesn't "clean the content", it just says "forget this name", in this case "forget the local variable called 'color'". > So, any suggestion? All comments and suggestions are highly appreciated. > :D :D :D > The ".connect" method connects something each time it's called. If you call it multiple times then multiple things will be connected. Try using ".disconnect" to disconnect what you no longer want connected. From ethan at stoneleaf.us Thu Nov 5 11:04:44 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Nov 2009 08:04:44 -0800 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: <4AF2F79C.1070202@stoneleaf.us> Steven D'Aprano wrote: > On Thu, 05 Nov 2009 13:27:09 +1100, Ben Finney wrote: > > >>Steven D'Aprano writes: >> >> >>>On Wed, 04 Nov 2009 23:08:54 +1100, Ben Finney wrote: >>> >>> >>>>Steven D'Aprano writes: >>>> >>>>>Why would I want to use an already existing library that is fast, >>>>>well- written and well-supported, when I can toss together a nasty >>>>>kludge myself? >>>> >>>>Because using that library will ensure you can't migrate to Python 3 >>>>any time soon? >>> >>>Why would I want to migrate to Python 3 any time soon? >> >>Sounds like you've answered the questions posed, then. Good for you! > > > I was actually only being *half* tongue in cheek, which is why I left out > the smiley. > > On the python-dev list at the moment is a lot of discussion on why uptake > of Python 3.1 has been slower than hoped. But one of the things that > people haven't really discussed -- or at least that I haven't seen -- is > why one would prefer 3.1 over 2.5 or 2.6. > > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. > > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? Python 3 is more pythonic. ;-) Cleaner, more consistent, etc. ~Ethan~ From mwilson at the-wire.com Thu Nov 5 11:05:49 2009 From: mwilson at the-wire.com (Mel) Date: Thu, 05 Nov 2009 11:05:49 -0500 Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <473291cc-fce8-462e-8693-5beb31b7972c@f16g2000yqm.googlegroups.com> <02fff632$0$1326$c3e8da3@news.astraweb.com> <9da6b593-3fab-4342-824f-44084e01d8b6@u16g2000pru.googlegroups.com> Message-ID: George Oliver wrote: > I think it's long past the point where you could contain everyone who > uses Python into a single community even if you tried. > > Besides, everyone knows about python-forum.org, right? ;) Or ohloh.net . Unless people use multiple pen names, there's a gang of Python developers there who don't hang out here. "stani" is the only name I recognize. Mel. From python.list at tim.thechases.com Thu Nov 5 11:06:05 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 05 Nov 2009 10:06:05 -0600 Subject: Read handle concatenation In-Reply-To: References: Message-ID: <4AF2F7ED.9030009@tim.thechases.com> > I want to be able to take two or more open read handles and > concatenate them into an object that behaves like a regular read > handle (i.e. a file object open for reading), but behind the scenes > it reads from the concatenated handles in sequence. I.e. I want > the read-handle equivalent of the standard Unix utility cat. (The > reason I can't use subprocess and cat for this is that I want to > concatenate read handles that do not necessarily come from files.) Sounds like itertools.chain would do what you want: for line in itertools.chain( file('a.txt'), file('b.txt'), ): do_something(line) or more generically if you have a list of file objects: lst = [file('a.txt'), file('b.txt'), ...] for line in itertools.chain(*lst): do_something(line) -tkc From alfps at start.no Thu Nov 5 11:09:48 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 05 Nov 2009 17:09:48 +0100 Subject: list to table In-Reply-To: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: * jay: > > I have a long list of data of associations between values with a value > to that association as follows.. > > (var) to (var) = (var) hits > A B 1 > B A 1 > A B 3 > B A 3 > A C 7 > C A 2 > > And need to build a table as follows that accumulates the above: > > row is (from) > column is (to) > > A B C > A 0 4 7 > B 4 0 0 > C 2 0 0 > > Just can't seam to figure out how to manage this programatically. You're not very clear on what A, B and C are. Assuming that they're constants that denote unique values you can do something like table = dict() for k1, k2, n in list: position = (k1, k2) if position not in table: table[position] = n else: table[position] += n Disclaimer: I'm a Python newbie so there may be some much easier way... Cheers & hth., - Alf From rpjday at crashcourse.ca Thu Nov 5 11:12:18 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 5 Nov 2009 11:12:18 -0500 (EST) Subject: can i configure IDLE to use python 3.2 on fedora? Message-ID: on fedora 11 system, there is no python 3 package so i downloaded and manually installed (svn checkout) python pre-3.2 in /usr/local/bin. works fine, but if i install the python-tools package, "idle" that comes with it is hard-coded(?) to still refer to the officially-installed python-2.6. i see no way to configure idle to use the "python3" executable instead. is there a way? or am i just out of luck? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From peter.n.green at gmail.com Thu Nov 5 11:13:53 2009 From: peter.n.green at gmail.com (Peter Green) Date: Thu, 5 Nov 2009 08:13:53 -0800 (PST) Subject: Differentiating file attachments from inline attachments in Exchange Message-ID: <7154bd1c-9b5e-47ef-b7f4-990a9d1e511b@s15g2000yqs.googlegroups.com> I am trying to write some code that will scan an Exchange 2003 mailbox, detach file attachments from messages into the file system and replace them in the message with links. My initial attempt is based on Tim Golden's approach at http://timgolden.me.uk/python/win32_how_do_i/replace-outlook-attachments-with-links.html, using CDO. A typical message may contain AutoCAD drawings, PDFs, site photographs and Excel spreadsheet schedules as separate file attachments, together with inline graphics such as a corporate logo in the signature. The problem is that iterating over the message attachments using CDO detaches *everything*. I want to leave the inline images in the message body. I've looked at the CDO documentation and cannot see any property that distinguishes inline images from file attachments. I suspect I am barking up the wrong tree and need to be automating Outlook instead, but if so, any suggestions as to how I can achieve what I want? I imagine Content-Disposition Headers are going to be involved somehow... Thanks in advance, Peter From rafalgulinski at gmail.com Thu Nov 5 11:17:23 2009 From: rafalgulinski at gmail.com (Rafal Gulinski) Date: Thu, 5 Nov 2009 08:17:23 -0800 (PST) Subject: XML-RPC(using SimpleXMLRPCServer) slow on the first call References: <83d424980910121458r7518401fod78bef7104a2155e@mail.gmail.com> Message-ID: <85e125f3-614c-4e00-b436-67217509f6b1@v25g2000yqk.googlegroups.com> On 14 Pa?, 04:52, "Gabriel Genellina" wrote: > En Mon, 12 Oct 2009 18:58:45 -0300, Mahi Haile ? > escribi?: > > > Hello all,I have an xml-rpc server running on a machine in the same LAN ? > > as > > the client. Both the server and the client are in Python. > > > When I have a series of xmlrepc calls from the client to the server, the > > first call usually takes much longer than it should - orders of ? > > magnitude. > > The latency is usually sub-10ms on the other calls, but the first call ? > > takes > > up to 10 seconds or so. This are very simple functions, with almost no > > computation. > > > Do you have any ideas? > > I doubt this is a Python problem. I'd look into the network: DNS ? > resolution, IPv6 (Windows XP has some timeout issues with IPv6 enabled). > > -- > Gabriel Genellina Hi, I had quite similar issue and it was caused by some DNS settings. I solved it by changing host name to host ip (f.e. for 'localhost' it was '127.0.0.1'). I hope it will help you. Regards, Rafal From joncle at googlemail.com Thu Nov 5 11:57:23 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 08:57:23 -0800 (PST) Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> Message-ID: <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> On Nov 5, 4:09?pm, "Alf P. Steinbach" wrote: > * jay: > > > > > > > I have a long list of data of associations between values with a value > > to that association as follows.. > > > (var) to (var) = (var) hits > > A B 1 > > B A 1 > > A B 3 > > B A 3 > > A C 7 > > C A 2 > > > And need to build a table as follows that accumulates the above: > > > row is (from) > > column is (to) > > > ? ?A B C > > A 0 4 7 > > B 4 0 0 > > C 2 0 0 > > > Just can't seam to figure out how to manage this programatically. > > You're not very clear on what A, B and C are. Assuming that they're constants > that denote unique values you can do something like > > > table = dict() > for k1, k2, n in list: > ? ? ?position = (k1, k2) > ? ? ?if position not in table: > ? ? ? ? ?table[position] = n > ? ? ?else: > ? ? ? ? ?table[position] += n > > > Disclaimer: I'm a Python newbie so there may be some much easier way... > > Cheers & hth., > > - Alf I read the OP as homework (I'm thinking Scott did as well), however, your code would be much nicer re-written using collections.defaultdict (int)... which I don't think is giving anything away... However, the challenge of making it 'tabular' or whatever the requirement of 'table' is, is still there. Jon. From tepperly at llnl.gov Thu Nov 5 12:20:28 2009 From: tepperly at llnl.gov (Tom Epperly) Date: Thu, 05 Nov 2009 09:20:28 -0800 Subject: Looking for portable what to determine directory where extensions are installed? Message-ID: <4AF3095C.6060906@llnl.gov> I work on a language interoperability tool, Babel https://computation.llnl.gov/casc/components/components.html; and I need a portable way to determine the directory where Python extension modules are installed by distutils (i.e., lib or lib64) to resolve this issue: https://www.cca-forum.org/bugs/babel/issue670 For example, I will invoke "python setup.py install --prefix=/home/foo/_inst --exec-prefix=/home/foo/_inst", and it usually installs the extensions in either /home/foo/_inst/lib/python2.5/site-packages or /home/foo/_inst/lib64/python2.5/site-packages. Initially, I did the following to determine where the extensions actually got installed: # assume exec_prefix=/home/foo/_inst # assume python_version=`python -c 'import sys; print sys.version' | sed '1s/^\(...\).*/\1/g;1q'` RUNTIME_PYTHON="$exec_prefix/lib/python$python_verbose/site-packages" This worked fine until I started running on 64-bit Python machines where the correct result was RUNTIME_PYTHON="$exec_prefix/lib64/python$python_verbose/site-packages" The first 64-bit machine I was using seemed to have this patch: http://bugs.python.org/file14726/Python-2.6.2-multilib.patch, so I amended my script to the following: pylib=`$PYTHON -c "import sys; print sys.__dict__.get('lib','lib')"` RUNTIME_PYTHON="$exec_prefix/$pylib/python$python_version/site-packages" However, this approach doesn't work with Fedora Core 12 prerelease or some other 64-bit Linux distributions. They don't define "sys.lib". I thought distutils.sysconfig.get_python_lib() might be helpful, but it returns "/usr/lib/python2.6/site-packages" even on the system where "/usr/lib64/python2.6/site-packages" is the right answer. Is there a canonical, Pythonic way to determine whether an installation of Python uses "lib" or "lib64"? Or is there a way to determine the full path of where distutils will install extensions relative to the specified exec prefix? Regards, Tom Epperly From joncle at googlemail.com Thu Nov 5 12:40:31 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 5 Nov 2009 09:40:31 -0800 (PST) Subject: join , split question References: <4af299fc$0$11893$426a34cc@news.free.fr> <4af2dc40$0$21867$426a34cc@news.free.fr> Message-ID: <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> On Nov 5, 2:08?pm, Bruno Desthuilliers wrote: > Stuart Murray-Smith a ?crit : > > >>> Hello, i have some text file list such like following format. > >>> i want to change text format to other format. > >>> ?i was upload it pastebin site > >>>http://elca.pastebin.com/d71261168 > > >> Dead link. > > >> With what ? > > >http://elca.pastebin.com/d4d57929a > > Yeah, fine. And where's the code you or the OP (if not the same person) > have problems with ? I'd certainly be curious to see it, especially with the pagecheck() line 22 @ http://elca.pastebin.com/f5c69fe41 From jim.vickroy at noaa.gov Thu Nov 5 14:15:06 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Thu, 05 Nov 2009 12:15:06 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? Message-ID: Hello, I have just upgraded from Python 2.5 to 2.6 and am unable to locate any trace of the --install-script option, in release 2.6.4 (MS Windows XP), for distutils.core.setup. I also have been unable to locate any mention of it on-line. My v2.5 setup.py scripts are failing with the falling error: error: option --install-script not recognized I apologize for missing something obvious here, but I am stuck. Thanks in advance for your feedback. -- jv From lelandpeng at gmail.com Thu Nov 5 15:02:53 2009 From: lelandpeng at gmail.com (Leland) Date: Thu, 5 Nov 2009 12:02:53 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary Message-ID: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Hi, I always use readline(), strip(), split() and so on to parse a string. Is there some elegant way to parse the following string into a dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? NET_NAME '50MHZ_CLK_SRC' '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; NODE_NAME U122 2 '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': 'CLK2': CDS_PINID='CLK2'; NODE_NAME R1395 1 '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': 'A': CDS_PINID='A'; Thanks, Leland From flashk at gmail.com Thu Nov 5 16:00:17 2009 From: flashk at gmail.com (Farshid) Date: Thu, 5 Nov 2009 13:00:17 -0800 (PST) Subject: 2to3 ParseError with UTF-8 BOM Message-ID: I'm using Python 2.6.2 and when I run the 2to3 script on a file that contains a UTF-8 BOM I get the following error: RefactoringTool: Can't parse : ParseError: bad token: type=55, value='\xef', context=('', (1, 0)) If I remove the BOM then it works fine. Is this expected behavior or a bug in the 2to3 script? -farshid From emile at fenx.com Thu Nov 5 16:05:25 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 05 Nov 2009 13:05:25 -0800 Subject: parse a string (Cadence Allegro Netlist) to dictionary In-Reply-To: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On 11/5/2009 12:02 PM Leland said... > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; > > Thanks, > Leland This does it, but not very elegantly... mydict = dict( (kk[0].replace("'",""),",".join(kk[1:])) for kk in [ [ [ jj for jj in ii.split("\n") if jj.strip() ][0] for ii in txt.split("_NAME")[1:] ] ]) Emile From sjmachin at lexicon.net Thu Nov 5 16:18:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 5 Nov 2009 13:18:39 -0800 (PST) Subject: elementtree XML() unicode References: <482a71e7-0a5b-4c2e-8278-4afc4d9a18d1@y28g2000prd.googlegroups.com> <4af18322$0$7620$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <1fddd745-14ba-4dac-8379-20841c15dd0a@y28g2000prd.googlegroups.com> On Nov 5, 12:35?am, Stefan Behnel wrote: > John Machin, 04.11.2009 02:56: > > > On Nov 4, 12:14 pm, Kee Nethery wrote: > >> The reason I am confused is that getResponse2 is classified as an ? > >> "str" in the Komodo IDE. I want to make sure I don't lose the non- > >> ASCII characters coming from the URL. > > > str is all about 8-bit bytes. > > True in Py2.x, false in Py3. And the context was 2.x. > What you mean is the "bytes" type, which, sadly, was named "str" in Python 2.x. What you mean is the "bytes" concept. > The problem the OP ran into was due to the fact that Python 2.x handled > "ASCII characters in a unicode string" <-> "ASCII encoded byte string" > conversion behind the scenes, which lead to all sorts of trouble to loads > of people, and was finally discarded in Python 3.0. What you describe is the symptom. The problems are (1) 2.X ET expects a str object but the OP supplied a unicode object, and (2) 2.X ET didn't check that, so it accidentally "worked" provided the contents were ASCII-only, and otherwise gave a novice-mystifying error message. From tjreedy at udel.edu Thu Nov 5 17:31:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Nov 2009 17:31:46 -0500 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87y6mpvy4n.fsf@agentultra.com> <87ljiok21e.fsf@benfinney.id.au> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > I've played around with 3.0, and I've read the What's New for 3.1 (and am > installing 3.1 now), and while the changes look nice, I'm not sure that > they're nice enough to deal with the pain of 2to3 migration. I am in a different position since I did not have current code that would need migrating. > So how about that, 3.1 fans? What are the most compelling reasons for you > that convinced you to change? I am writing a book on algorithms that uses a subset of 3.1 as the algorithm language. It it simply cleaner and easier to explain to people not already familiar with the quirks of 2.x. One small but important-to-me example. I do not need to put 'from __future__ import integerdivision' (or whatever the incantation is) as the top of files. Hence I do not need to waste energy (mime and readers) explaining furture imports and the specifics of the old versus new meaning of int/int. While I initially resisted the text==unicode change, I now see it as essential to the future of Python as a world algorithm language. I admit that I am more bothered about the leftover quirks (to me -- sludge) in 2.x than most. Unless you are the author/maintainer of an essential library, I have no opinion as to what you do with old code, or even what you use for new code. I do care about people trying to disparage or sabotage 3.x. Terry Jan Reedy From debatem1 at gmail.com Thu Nov 5 17:42:42 2009 From: debatem1 at gmail.com (geremy condra) Date: Thu, 5 Nov 2009 17:42:42 -0500 Subject: Python 3 In-Reply-To: References: <80092882-0159-4622-a636-ba086456c88c@b36g2000prf.googlegroups.com> <87tyxbws3v.fsf@agentultra.com> <87aaz2ebl5.fsf@benfinney.id.au> <87fx8td7uq.fsf@benfinney.id.au> Message-ID: On Thu, Nov 5, 2009 at 5:31 PM, Terry Reedy wrote: > Steven D'Aprano wrote: > >> I've played around with 3.0, and I've read the What's New for 3.1 (and am >> installing 3.1 now), and while the changes look nice, I'm not sure that >> they're nice enough to deal with the pain of 2to3 migration. > > I am in a different position since I did not have current code that would > need migrating. > >> So how about that, 3.1 fans? What are the most compelling reasons for you >> that convinced you to change? > > I am writing a book on algorithms that uses a subset of 3.1 as the algorithm > language. It it simply cleaner and easier to explain to people not already > familiar with the quirks of 2.x. One small but important-to-me example. I do > not need to put 'from __future__ import integerdivision' (or whatever the > incantation is) as the top of files. Hence I do not need to waste energy > (mime and readers) explaining furture imports and the specifics of the old > versus new meaning of int/int. I agree. Most of my code is primarily mathematical, and while I personally see the move away from functional programming techniques as a minor misstep, the cleanliness of it all more than makes up for that. Geremy Condra From threaderslash at gmail.com Thu Nov 5 17:55:56 2009 From: threaderslash at gmail.com (Threader Slash) Date: Fri, 6 Nov 2009 09:55:56 +1100 Subject: Clean PyQt selection comboBox Message-ID: > ---------- Original message ---------- > From: MRAB > To: python-list at python.org > Date: Thu, 05 Nov 2009 15:37:49 +0000 > Subject: Re: Clean PyQt selection comboBox > Threader Slash wrote: > >> Hello Everybody, 8) >> >> I am using Qt and need to build a selection comboBox -- e.g.: >> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG. >> >> The problem is - after one choice was made, and the code run, for the next >> time the user select a different choice, both, the present and all past >> choices run. See what I mean: ;( >> >> Code: >> >> selected color - blue >> we are on runBlue >> >> selected color - red >> we are on runBlue >> we are on runRed >> >> >> Here is the code: >> >> ......................................... >> QtCore.QObject.connect(self.selectComboBox, >> QtCore.SIGNAL("currentIndexChanged(QString)"), >> self.combo_activateInput) ......................................... >> >> def combo_activateInput(self): >> color=unicode(self.selectComboBox.currentText()) >> if(color == "blue"): >> print "selected color - blue" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runBlue) >> >> if(color == "red"): >> print "selected color - red" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runRed) if(color >> == "yellow"): >> >> print "selected color - yellow" >> QtCore.QObject.connect(self.okButton, >> QtCore.SIGNAL("clicked()"), self.combo_runYellow) >> del color ......................................... >> >> def combo_runBlue(self): >> print "we are on runBlue" >> >> def combo_runRed(self): >> print "we are on runRed" >> >> def combo_runYellow(self): >> print "we are on runYellow" >> >> I run "del color" to clean the content returned by >> selectComboBox.currentText, but it didn't clean the content indeed. >> >> "del color" doesn't "clean the content", it just says "forget this > name", in this case "forget the local variable called 'color'". > > So, any suggestion? All comments and suggestions are highly appreciated. >> :D :D :D >> >> The ".connect" method connects something each time it's called. If you > call it multiple times then multiple things will be connected. > > Try using ".disconnect" to disconnect what you no longer want connected. > > ---------- ---------- > Thanks Man! You saved the day. It solved the problem... ................................................................ def combo_runBlue(self): print "we are on runBlue" QtCore.QObject.disconnect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue) ................................................................ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nuffnough at gmail.com Thu Nov 5 18:10:51 2009 From: nuffnough at gmail.com (Nuff Nuff) Date: Thu, 5 Nov 2009 15:10:51 -0800 (PST) Subject: Need help dumping exif data in canon raw files Message-ID: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> So I've looked at all sorts of things, gone through as many different things as I can find, but I fear python just can't do it. I just need to be able to extract the exif info from a canon CR2 file. The info from canon suggest that it's just the same as a tiff, but anytime I try to get PIL to open one, it says that it tastes bad. And canon don't seem to be all that forthcoming on the details. Ideally I'd be able to update the file with new exif info too, but that would just be a bonus. Right now I just want to open a file (say /home/nuffi/IMG_0001.CR2 or d:\pic\IMG_0001.CR2) and print out all the exif info attached to the file. Is it impossible in Python? TIA! Nuffi From gagsl-py2 at yahoo.com.ar Thu Nov 5 18:11:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 05 Nov 2009 20:11:32 -0300 Subject: Looking for portable what to determine directory where extensions are installed? References: <4AF3095C.6060906@llnl.gov> Message-ID: En Thu, 05 Nov 2009 14:20:28 -0300, Tom Epperly escribi?: > I work on a language interoperability tool, Babel > https://computation.llnl.gov/casc/components/components.html; and I need > a portable way to determine the directory where Python extension modules > are installed by distutils (i.e., lib or lib64) to resolve this issue: > https://www.cca-forum.org/bugs/babel/issue670 The distutils SIG is probably a better place to ask: http://www.python.org/community/sigs/current/distutils-sig/ -- Gabriel Genellina From shawjacob4 at gmail.com Thu Nov 5 18:19:00 2009 From: shawjacob4 at gmail.com (Jacob Shaw) Date: Thu, 5 Nov 2009 15:19:00 -0800 (PST) Subject: PiCloud Beta Release References: <47ab340d-befa-4ad8-99db-fd4494ace7fa@x25g2000prf.googlegroups.com> Message-ID: <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> On Nov 1, 5:13?pm, Ken Elkabany wrote: > Hello, > > PiCloud has just released a Python library, cloud, which allows you to > easily offload the execution of a function to a cluster of servers > running on Amazon Web Services. As a beta product, we are currently > free to all users who sign up with beta code "PYTHONLIST". To > register, go tohttp://www.picloud.com > > Full service description: > PiCloud is a cloud-computing platform that integrates into the Python > Programming Language. It enables you to leverage the compute power of > Amazon Web Services without having to manage, maintain, or configure > virtual servers. > > PiCloud integrates seamlessly into your existing code base through a > custom Python library, cloud. To offload the execution of a function > to the cloud, all you must do is pass your desired function into the > cloud library. PiCloud will then run the function on its > high-performance and automatically-scaling cluster. We quickly scale > our server capacity, both up and down, to meet your computational > needs, and only charge you for the resources you actually consume. > Getting on the cloud has never been this easy! > > PiCloud improves the full cycle of software development and > deployment. Functions that are run on PiCloud have their resource > usage monitored, performance analyzed, and errors traced; we further > aggregate all your functions to give you a bird's eye view of your > service. Through these introspective capabilities, PiCloud enables you > to develop faster, easier, and smarter. > > Common use cases for our platform: > * Crawling the web > * Manipulating images and videos > * Generating charts and graphs > * Statistical/Mathematical analysis of data sets > * Real-time data processing > > Cheers, > > Ken Elkabany > PiCloud, Inc. Wow, amazing service. I used PiCloud for some scraping work, and my script ran about 10x as fast. Some questions though: 1) I have another project which uses a custom python extension written in C++. Is there a way to use it on PiCloud? 2) I noticed you guys only support python 2.5 and 2.6. Will there be 3.1 support eventually? From http Thu Nov 5 18:27:02 2009 From: http (Paul Rubin) Date: 05 Nov 2009 15:27:02 -0800 Subject: Need help dumping exif data in canon raw files References: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> Message-ID: <7xd43w1rjt.fsf@ruckus.brouhaha.com> Nuff Nuff writes: > I just need to be able to extract the exif info from a canon CR2 > file. The info from canon suggest that it's just the same as a tiff, > but anytime I try to get PIL to open one, it says that it tastes > bad. And canon don't seem to be all that forthcoming on the details. CR2 is a hardware-specific raw format and PIL should not be expected to understand it. Try a websearch for dcraw.c to find a decoder for it. From sajmikins at gmail.com Thu Nov 5 18:48:35 2009 From: sajmikins at gmail.com (Simon Forman) Date: Thu, 5 Nov 2009 18:48:35 -0500 Subject: Why do you use python? In-Reply-To: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> Message-ID: <50f98a4c0911051548y5d020128xe4879586c4395100@mail.gmail.com> On Sat, Oct 31, 2009 at 2:11 AM, sk wrote: > What would be your answer if this question is asked to you in an > interview? > > a modified version might be: > "Where would you use python over C/C++/Java?" > > (because my resume says I know C/C++/Java)? Mark Miller has some adages posted on his homepage. [1] One of my favorites is this: "A Computer's Perspective on Moore's Law: Humans are getting more expensive at an exponential rate." Python saves you human-time. Python allows you to write software that runs, is readable, can be maintained and modified easily, etc... far better than any other language I've ever used. You can write working code, and read and understand already-written code /faster/ in Python than any other language I've ever used. Use Python. I would use C (to write Python extensions) only where profiling had shown a definite hotspot, and then only when there were no better algorithmic choices available. I would never use C++ or Java. (N.B. I've managed to be gainfully, and blissfully, employed programming in Python for about six years now. I've passed on otherwise interesting jobs because the folks involved were using something other than Python.) I'm actually working at a startup at the moment that originally hired me to "do python" and then decided to use PHP because more of the team (two out of three) knew it and didn't know python. I figured "what the heck, it's been awhile, and it will look good on my resume" so I have stuck with them. PHP isn't as horrible as I remembered, but it's still horrible. /Everything/ is horrible compared to Python. WTF is wrong with people? (Disclaimer: Smalltalk and LISP are not horrible... *grin*) Anyway, I wouldn't say all that in an interview, heh, but that's my $0.02. My strong advice to you or any programmer is, don't bother interviewing with a company that's not already committed to using Python as their main language (modulo extraordinary circumstances.) [1] http://www.caplet.com/adages.html From alfps at start.no Thu Nov 5 19:23:27 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 01:23:27 +0100 Subject: list to table In-Reply-To: <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: * Jon Clements: > > I read the OP as homework (I'm thinking Scott did as well), Sorry. Need to recalibrate that neural network. Back-propagation initiated... Done! :-) > however, > your code would be much nicer re-written using collections.defaultdict > (int)... which I don't think is giving anything away... Thanks! This sent me searching everywhere, because the documentation of '+=' and other "augmented assignment statements" says "The target is only evaluated once.", like in C++, which implies a kind of reference to mutable object. I couldn't immediately see how subscription could apparently return a reference to mutable int object in Python in a way so that it worked transparently (the idiom in C++). However, it worked to replace collections.defaultdict with a class overriding __getitem__ and __setitem__, so I guess that's how it works, that in this case '+=' is simply translated like 'x += n' -> 'temp = x; x = temp + n'. Is this a correct understanding, and if so, what exactly does the documentation mean for the general case? E.g. def foo(): print( "foo" ) d = dict(); d[43] = 666 return d def bar(): print( "bar" ) return 43; foo()[bar()] += 1 produces foo bar so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but evidently more like 'a = foo(); i = bar(); a.__setitem__(i, a.__getitem__(i) + 1)'? If so, is this behavior defined anywhere? I did find discussion (end of ?6.2 of the language reference) of the case where the target is an attibute reference, with this example: class A: x = 3 # class variable a = A() a.x += 1 # writes a.x as 4 leaving A.x as 3 :-) Cheers, & thanks, - Alf From metal29a at gmail.com Thu Nov 5 19:23:55 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:23:55 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On 11?6?, ??4?02?, Leland wrote: > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; > > Thanks, > Leland not very elegantly too. x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s) """ print {x[0]: x[1:]} >>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']} """ From metal29a at gmail.com Thu Nov 5 19:34:37 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:34:37 -0800 (PST) Subject: join , split question References: Message-ID: On 11?4?, ??5?39?, elca wrote: > Hello, > i have some text file list such like following format. > i want to change text format to other format. > ?i was upload it pastebin sitehttp://elca.pastebin.com/d71261168 > > if anyone help ,much appreciate thanks in advance > -- > View this message in context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html > Sent from the Python - python-list mailing list archive at Nabble.com. s = """uji708 uhodih utus29 agamu4 azi340 ekon62 """ from itertools import cycle for i, x in zip(cycle(range(3)), s.splitlines()): print x + ',', if i == 2: print """ uji708, uhodih, utus29, agamu4, azi340, ekon62, """ From rhodri at wildebst.demon.co.uk Thu Nov 5 19:42:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 06 Nov 2009 00:42:39 -0000 Subject: parse a string (Cadence Allegro Netlist) to dictionary In-Reply-To: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On Thu, 05 Nov 2009 20:02:53 -0000, Leland wrote: > Hi, > > I always use readline(), strip(), split() and so on to parse a string. > Is there some elegant way to parse the following string into a > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > NET_NAME > '50MHZ_CLK_SRC' > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > NODE_NAME U122 2 > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > 'CLK2': CDS_PINID='CLK2'; > NODE_NAME R1395 1 > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > 'A': CDS_PINID='A'; Here's an inelegant way: **** CODE **** results = {} net_name_next = False net_name = None node_names = [] for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): if net_name is not None: results[net_name] = ", ".join(node_names) net_name = None node_names = [] net_name_next = True elif net_name_next: net_name = line.strip("'") net_name_next = False elif line.startswith('NODE_NAME'): node_names.append("{1}.{2}".format(*line.split())) # Last time through if net_name is not None: results[net_name] = ", ".join(node_names) **** END CODE **** If you're prepared to allow the dictionary values to be lists rather than strings, we can squash that down: **** CODE **** results = {None: []} net_name = None for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): net_name = sourcefile.next().strip(" \t\n'") results[net_name] = [] elif line.startswith('NODE_NAME'): results[net_name].append("{1}.{2}".format(*line.split())) del results[None] **** END CODE **** If you can guarantee that you won't meet a NODE_NAME before you see a NET_NAME then you can lose the messing about with results[None]. Having spent today picking up the pieces from an assumption that's rotted after several years, I'm not feeling that brave. A slightly less messy version of that would be: **** CODE **** results = {} entry = [] for line in sourcefile: line = line.strip() if line.startswith('NET_NAME'): entry = [] results[sourcefile.next().strip(" \t\n'")] = entry elif line.startswith('NODE_NAME'): entry.append("{1}.{2}".format(*line.split())) **** END CODE **** I'm a little dubious about doing mutable magic like this without copious comments, though. -- Rhodri James *-* Wildebeest Herder to the Masses From metal29a at gmail.com Thu Nov 5 19:46:04 2009 From: metal29a at gmail.com (metal) Date: Thu, 5 Nov 2009 16:46:04 -0800 (PST) Subject: join , split question References: Message-ID: On 11?6?, ??8?34?, metal wrote: > On 11?4?, ??5?39?, elca wrote: > > > Hello, > > i have some text file list such like following format. > > i want to change text format to other format. > > ?i was upload it pastebin sitehttp://elca.pastebin.com/d71261168 > > > if anyone help ,much appreciate thanks in advance > > -- > > View this message in context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > s = """uji708 > uhodih > utus29 > agamu4 > azi340 > ekon62 > """ > > from itertools import cycle > for i, x in zip(cycle(range(3)), s.splitlines()): > ? ? print x + ',', > ? ? if i == 2: > ? ? ? ? print > > """ > uji708, uhodih, utus29, > agamu4, azi340, ekon62, > """ yet another version, a little evil s = """uji708 uhodih utus29 agamu4 azi340 ekon62 """ from itertools import * print '\n'.join(','.join(x for i, x in g) for k, g in groupby(enumerate (s.splitlines()), lambda (i, x): i/3)) """ uji708,uhodih,utus29 agamu4,azi340,ekon62 """ From skip at pobox.com Thu Nov 5 20:50:57 2009 From: skip at pobox.com (Skip Montanaro) Date: Thu, 05 Nov 2009 19:50:57 -0600 Subject: 2to3 on Mac - unknown encoding: mbcs Message-ID: I tried naively running 2to3 over the SpamBayes source code on my Mac and got this traceback: Traceback (most recent call last): File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py", line 281, in find_cookie codec = lookup(encoding) LookupError: unknown encoding: mbcs SpamBayes does have several files which contain the "mbcs" coding cookie: ./windows/py2exe/gen_py/addin-designer.py ./windows/py2exe/gen_py/office-9.py ./windows/py2exe/gen_py/outlook-9.py After a little hunting I came across the docs for the codecs module, which for "mbcs" states: Windows only: Encode operand according to the ANSI codepage (CP_ACP) Is there something I can use to replace the mbcs coding cookies which will allow 2to3 to process these Windows-specific files? Thanks, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From aahz at pythoncraft.com Thu Nov 5 20:54:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Nov 2009 17:54:19 -0800 Subject: Freezing python files into executables References: Message-ID: In article , Mike Driscoll wrote: > >Something that you might want to try in the future is GUI2Exe, which >allows you to play with a whole slew of freezing modules: Does GUI2Exe work from just the command-line? I spent a fair amount of time getting rid of the Mac GUI .pkg creator and I sure don't want to introduce more GUI into our ant build process. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From highcar at gmail.com Thu Nov 5 21:08:08 2009 From: highcar at gmail.com (elca) Date: Thu, 5 Nov 2009 18:08:08 -0800 (PST) Subject: join , split question In-Reply-To: <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> References: <26193334.post@talk.nabble.com> <4af299fc$0$11893$426a34cc@news.free.fr> <4af2dc40$0$21867$426a34cc@news.free.fr> <66fa1d20-b700-4c67-8013-cae02a4063a0@j24g2000yqa.googlegroups.com> Message-ID: <26225646.post@talk.nabble.com> Jon Clements-2 wrote: > > On Nov 5, 2:08?pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Stuart Murray-Smith a ?crit : >> >> >>> Hello, i have some text file list such like following format. >> >>> i want to change text format to other format. >> >>> ?i was upload it pastebin site >> >>>http://elca.pastebin.com/d71261168 >> >> >> Dead link. >> >> >> With what ? >> >> >http://elca.pastebin.com/d4d57929a >> >> Yeah, fine. And where's the code you or the OP (if not the same person) >> have problems with ? > > I'd certainly be curious to see it, especially with the pagecheck() > line 22 @ http://elca.pastebin.com/f5c69fe41 > > -- > http://mail.python.org/mailman/listinfo/python-list > > thanks all! i was resolved :) -- View this message in context: http://old.nabble.com/join-%2C-split-question-tp26193334p26225646.html Sent from the Python - python-list mailing list archive at Nabble.com. From brian at sweetapp.com Thu Nov 5 21:24:03 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 6 Nov 2009 13:24:03 +1100 Subject: futures - a new package for asynchronous execution Message-ID: Hey all, I recently implemented a package that I'd like to have include in the Python 3.x standard library (and maybe Python 2.x) and I'd love to have the feedback of this list. The basic idea is to implement an asynchronous execution method patterned heavily on java.util.concurrent (but less lame because Python has functions as first-class objects). Here is a fairly advanced example: import futures import functools import urllib.request URLS = [ 'http://www.foxnews.com/', 'http://www.cnn.com/', 'http://europe.wsj.com/', 'http://www.bbc.co.uk/', 'http://some-made-up-domain.com/'] def load_url(url, timeout): return urllib.request.urlopen(url, timeout=timeout).read() # Use a thread pool with 5 threads to download the URLs. Using a pool # of processes would involve changing the initialization to: # with futures.ProcessPoolExecutor(max_processes=5) as executor with futures.ThreadPoolExecutor(max_threads=5) as executor: future_list = executor.run_to_futures( [functools.partial(load_url, url, 30) for url in URLS]) # Check the results of each future. for url, future in zip(URLS, future_list): if future.exception() is not None: print('%r generated an exception: %s' % (url, future.exception())) else: print('%r page is %d bytes' % (url, len(future.result()))) In this example, executor.run_to_futures() returns only when every url has been retrieved but it is possible to return immediately, on the first completion or on the first failure depending on the desired work pattern. The complete docs are here: http://sweetapp.com/futures/ A draft PEP is here: http://code.google.com/p/pythonfutures/source/browse/trunk/PEP.txt And the code is here: http://pypi.python.org/pypi/futures3/ All feedback appreciated! Cheers, Brian From benjamin at python.org Thu Nov 5 22:18:54 2009 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 6 Nov 2009 03:18:54 +0000 (UTC) Subject: 2to3 ParseError with UTF-8 BOM References: Message-ID: Farshid gmail.com> writes: > If I remove the BOM then it works fine. Is this expected behavior or a > bug in the 2to3 script? Try the 2to3 distributed in Python 3.1. From pengyu.ut at gmail.com Thu Nov 5 22:41:22 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 21:41:22 -0600 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? Message-ID: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> I looked though the os.path manual. I don't find a function that can test if a path is in a directory or its sub-directory (recursively). For example, /a/b/c/d is in /a its sub-directory (recursively). Could somebody let me know if such function is available somewhere? From clp2 at rebertia.com Thu Nov 5 22:53:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 19:53:14 -0800 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> Message-ID: <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: > I looked though the os.path manual. I don't find a function that can > test if a path is in a directory or its sub-directory (recursively). > > For example, /a/b/c/d is in /a its sub-directory (recursively). Could > somebody let me know if such function is available somewhere? Couldn't you just canonicalize the paths using os.path.abspath() and friends and then do subdirectory.startswith(parent_directory) [as strings]? Cheers, Chris -- http://blog.rebertia.com From pengyu.ut at gmail.com Thu Nov 5 23:19:08 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 22:19:08 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? Message-ID: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> Suppose I have a list of strings, A. I want to compute the list (call it B) of strings that are elements of A but doesn't match a regex. I could use a for loop to do so. In a functional language, there is way to do so without using the for loop. I'm wondering what is the best way to compute B in python. From clp2 at rebertia.com Thu Nov 5 23:25:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 20:25:24 -0800 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> Message-ID: <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. > > I'm wondering what is the best way to compute B in python. Since this sounds rather homework-y, I'll only give you a pointer: http://docs.python.org/tutorial/datastructures.html#list-comprehensions Cheers, Chris -- http://blog.rebertia.com From groups at tolomea.com Thu Nov 5 23:57:18 2009 From: groups at tolomea.com (Gordon) Date: Thu, 5 Nov 2009 20:57:18 -0800 (PST) Subject: ctypes exception in callback handlind Message-ID: This post concerns the situation where Python code calls C code via ctypes, the C code then calls a callback back into Python code which in turn raises an exception. Currently as I understand things when the callback finishes and control is returning to C land ctypes will catch and print the exception and then return normally back to C. The standard way of doing something meaningful with the exception is to catch it in the callback, set a global flag, somehow encourage the C code to unwind back to the original Python call and there check the flag and re-raise the exception. My current problems involves a non recoverable error being raised in the callback. The intermediate C code is not at all setup to deal with a failure like this and I can't find a way to "somehow encourage the C code to unwind". For extra giggles I can't just hit sys.exit as this stack got invoked as a callback out of a third party python library that needs to do some clean up. All of which leaves me wishing that ctypes would propgate the exception back to the python calling context for me. One approach I can think of that I would like to get some feedback on is the following: Create a new ctypes calling convention that does a setjmp on entry. When using that calling convention if an exception is raised by a call back, catch it and store it somewhere, longjmp back to the setjmp point and re-raise it. I appreciate that this will generally leave the intervening C code in an undefined state and as such would definitely have to be an optional feature. I realize that I could in theory do this myself by wrapping each of the C calls with a wrapper that does the setjmp work, but there are quite a few of them. So any comments or suggestions? G From gagsl-py2 at yahoo.com.ar Thu Nov 5 23:58:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 01:58:31 -0300 Subject: distutils.core.setup --install-script option in Python 2.6 ? References: Message-ID: En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy escribi?: > I have just upgraded from Python 2.5 to 2.6 and am unable to locate any > trace of the --install-script option, in release 2.6.4 (MS Windows XP), > for distutils.core.setup. I also have been unable to locate any mention > of it on-line. Do you mean this option? http://docs.python.org/distutils/builtdist.html#the-postinstallation-script Probably the distutils SIG is a better place to ask: http://www.python.org/community/sigs/current/distutils-sig/ -- Gabriel Genellina From pengyu.ut at gmail.com Fri Nov 6 00:23:12 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 5 Nov 2009 23:23:12 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> Message-ID: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: > On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >> Suppose I have a list of strings, A. I want to compute the list (call >> it B) of strings that are elements of A but doesn't match a regex. I >> could use a for loop to do so. In a functional language, there is way >> to do so without using the for loop. >> >> I'm wondering what is the best way to compute B in python. > > Since this sounds rather homework-y, I'll only give you a pointer: > http://docs.python.org/tutorial/datastructures.html#list-comprehensions Now, I want to in-place delete elements in A that matches the regex. I know that I need to use del. But I'm not sure how to use the functional style programming for this problem. Would you please let me know? From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:26:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:26:52 -0300 Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach escribi?: > * Jon Clements: > This sent me searching everywhere, because the documentation of '+=' and > other "augmented assignment statements" says > > "The target is only evaluated once.", > > like in C++, which implies a kind of reference to mutable object. Not exactly. For an augmented assignment, the target (left side) may be an identifier, an atttribute reference, or a subscription/slicing. In the first case, the comment simply does not apply (there is a single one opportunity to evaluate the target). a += some(expression) means: evaluate "a", evaluate some(expression), perform the operation +=, bind the resulting object to the name "a". a.attr += some(expression) means: evaluate "a", ask it for its attribute "attr", evaluate some(expression), perform the operation +=, ask the (already known) object "a" to store the resulting object as its attribute "attr". a[index] += some(expression) performs a similar sequence of steps; "a" is evaluated only once, then it is asked to retrieve its element at [index], the computation is performed, and finally the (already known) object "a" is asked to store the result at [index]. "The target is only evaluated once." means that it is NOT reevaluated before the final result is stored. Same applies to "index" above, although this is not explicited. Perhaps it is more clear with a longer expression: a[b+c].c[d(e[f])].h += 1 computes the a[b+c].c[d(e[f])] part only once. > I couldn't immediately see how subscription could apparently return a > reference to mutable int object in Python in a way so that it worked > transparently (the idiom in C++). It does not. It perform first a "getitem" operation followed by a "setitem" to store the result. A normal dictionary would fail when asked for an inexistent item; a defaultdict creates and returns a default value in such case. py> import collections py> d = collections.defaultdict(int) py> d['a'] += 1 py> d['a'] += 1 py> d['a'] 2 py> d['b'] 0 note: int() returns 0; defaultdict(lambda: 0) could have been used. > However, it worked to replace collections.defaultdict with a class > overriding __getitem__ and __setitem__, so I guess that's how it works, > that in this case '+=' is simply translated like 'x += n' -> 'temp = x; > x = temp + n'. > > Is this a correct understanding, and if so, what exactly does the > documentation mean for the general case? If x is a simple name, the only difference between x += n and x = x+n is the method invoked to perform the operation (__iadd__ vs __add__ in arbitrary objects). Both x and n are evaluated only once - and this is not an optimization, nor a shortcut, simply there is no need to do otherwise (please make sure you understand this). From the docs for the operator module: "Many operations have an ?in-place? version. The following functions provide a more primitive access to in-place operators than the usual syntax does; for example, the statement x += y is equivalent to x = operator.iadd(x, y). Another way to put it is to say that z = operator.iadd(x, y) is equivalent to the compound statement z = x; z += y." http://docs.python.org/library/operator.html > foo()[bar()] += 1 > > so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but > evidently more like 'a = foo(); i = bar(); a.__setitem__(i, > a.__getitem__(i) + 1)'? Yes, something like that. > If so, is this behavior defined anywhere? Isn't the description at http://docs.python.org/reference/simple_stmts.html#assignment-statements enough? It goes to some detail describing, e.g., what a.x = 1 means. The next section explains what a.x += 1 means in terms of the former case. > I did find discussion (end of ?6.2 of the language reference) of the > case where the target is an attibute reference, with this example: > > class A: > x = 3 # class variable > a = A() > a.x += 1 # writes a.x as 4 leaving A.x as 3 Do you want to discuss this example? -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:42:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:42:30 -0300 Subject: 2to3 on Mac - unknown encoding: mbcs References: Message-ID: En Thu, 05 Nov 2009 22:50:57 -0300, Skip Montanaro escribi?: > I tried naively running 2to3 over the SpamBayes source code on my Mac > and got this traceback: > > Traceback (most recent call last): > File "/Users/skip/local/lib/python3.2/lib2to3/pgen2/tokenize.py", > line 281, in find_cookie > codec = lookup(encoding) > LookupError: unknown encoding: mbcs > > SpamBayes does have several files which contain the "mbcs" coding > cookie: > > ./windows/py2exe/gen_py/addin-designer.py > ./windows/py2exe/gen_py/office-9.py > ./windows/py2exe/gen_py/outlook-9.py > > After a little hunting I came across the docs for the codecs module, > which for "mbcs" states: > > Windows only: Encode operand according to the ANSI codepage (CP_ACP) > > Is there something I can use to replace the mbcs coding cookies which > will allow 2to3 to process these Windows-specific files? Using mbcs as the source encoding declaration is evil (and stupid too). mbcs means "whatever encoding is currently configured in Windows", it is not a specific encoding. You have to guess which encoding those files are in. windows-1252 (almost the same as latin-1) is the one used in "Western Europe", which covers an area much broader than its name. Good luck, -- Gabriel Genellina From rpjday at crashcourse.ca Fri Nov 6 01:48:48 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 01:48:48 -0500 (EST) Subject: listing an object's methods/attributes? Message-ID: getting back into python after a long hiatus and "diving" into python 3 (http://www.diveintopython3.org/), but i can't remember how to list an object's full set of methods or attributes. how does that go again? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:49:15 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:49:15 -0300 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> Message-ID: En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert escribi?: > On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >> I looked though the os.path manual. I don't find a function that can >> test if a path is in a directory or its sub-directory (recursively). >> >> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >> somebody let me know if such function is available somewhere? > > Couldn't you just canonicalize the paths using os.path.abspath() and > friends and then do subdirectory.startswith(parent_directory) [as > strings]? Beware of directories starting with the same letters. I'd canonicalize, split the strings on os.sep, and compare the resulting lists up to the shortest one. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:52:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:52:50 -0300 Subject: ctypes exception in callback handlind References: Message-ID: En Fri, 06 Nov 2009 01:57:18 -0300, Gordon escribi?: > This post concerns the situation where Python code calls C code via > ctypes, the C code then calls a callback back into Python code which > in turn raises an exception. I'd ask in a ctypes specific list: -- Gabriel Genellina From timr at probo.com Fri Nov 6 01:52:58 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Nov 2009 22:52:58 -0800 Subject: disable image loading to speed up webpage load References: Message-ID: <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> elca wrote: > >im using win32com 's webbrowser module. Win32com does not have a webbrowser module. Do you mean you are using Internet Explorer via win32com? >i have some question about it.. >is it possible to disable image loading to speed up webpage load? If you are using IE, then you need to tell IE to disable image loading. I don't know a way to do that through the IE COM interface. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Fri Nov 6 01:57:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 5 Nov 2009 22:57:03 -0800 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: <50697b2c0911052257g292ab4feg5889aa56b1efbb23@mail.gmail.com> On Thu, Nov 5, 2009 at 9:23 PM, Peng Yu wrote: > On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: >> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >>> Suppose I have a list of strings, A. I want to compute the list (call >>> it B) of strings that are elements of A but doesn't match a regex. I >>> could use a for loop to do so. In a functional language, there is way >>> to do so without using the for loop. >>> >>> I'm wondering what is the best way to compute B in python. >> >> Since this sounds rather homework-y, I'll only give you a pointer: >> http://docs.python.org/tutorial/datastructures.html#list-comprehensions > > Now, I want to in-place delete elements in A that matches the regex. I > know that I need to use del. But I'm not sure how to use the > functional style programming for this problem. Would you please let me > know? Deletion is an imperative operation which has no direct equivalent in functional languages, so your question is nonsensical. To do it functionally, instead of deleting, you simply build a new list that omits the undesired elements. See also the built-in function filter(). Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Fri Nov 6 01:59:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 03:59:39 -0300 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: En Fri, 06 Nov 2009 02:23:12 -0300, Peng Yu escribi?: > On Thu, Nov 5, 2009 at 10:25 PM, Chris Rebert wrote: >> On Thu, Nov 5, 2009 at 8:19 PM, Peng Yu wrote: >>> Suppose I have a list of strings, A. I want to compute the list (call >>> it B) of strings that are elements of A but doesn't match a regex. I >>> could use a for loop to do so. In a functional language, there is way >>> to do so without using the for loop. >>> >>> I'm wondering what is the best way to compute B in python. >> >> Since this sounds rather homework-y, I'll only give you a pointer: >> http://docs.python.org/tutorial/datastructures.html#list-comprehensions > > Now, I want to in-place delete elements in A that matches the regex. I > know that I need to use del. But I'm not sure how to use the > functional style programming for this problem. Would you please let me > know? Functional and del don't mix. What about: B = [item for item in A if regex.match(item) is None] B = filter(lambda item: regex.match(item) is None, A) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 6 02:10:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 04:10:02 -0300 Subject: listing an object's methods/attributes? References: Message-ID: En Fri, 06 Nov 2009 03:48:48 -0300, Robert P. J. Day escribi?: > getting back into python after a long hiatus and "diving" into > python 3 (http://www.diveintopython3.org/), but i can't remember how > to list an object's full set of methods or attributes. how does that > go again? Try dir(the_object), vars(the_object), help(the_object), see(the_object) - this last one a hidden gem from http://github.com/inky/see (see is "dir for humans") -- Gabriel Genellina From alfps at start.no Fri Nov 6 02:29:05 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 08:29:05 +0100 Subject: list to table In-Reply-To: References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: * Gabriel Genellina: > En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach > escribi?: > [snip] > From the docs for the operator module: "Many operations have an > ?in-place? version. The following functions provide a more primitive > access to in-place operators than the usual syntax does; for example, > the statement x += y is equivalent to x = operator.iadd(x, y). Another > way to put it is to say that z = operator.iadd(x, y) is equivalent to > the compound statement z = x; z += y." > http://docs.python.org/library/operator.html Thanks! >> foo()[bar()] += 1 >> >> so here it's not translated like 'foo()[bar()] = foo()[bar()] + 1' but >> evidently more like 'a = foo(); i = bar(); a.__setitem__(i, >> a.__getitem__(i) + 1)'? > > Yes, something like that. > >> If so, is this behavior defined anywhere? > > Isn't the description at > http://docs.python.org/reference/simple_stmts.html#assignment-statements > enough? It goes to some detail describing, e.g., what a.x = 1 means. The > next section explains what a.x += 1 means in terms of the former case. No, it wasn't exactly enough for me, coming most recently from a C++ background. One reason was as mentioned that the C++ standard has essentially the /same wording/ about "only evaluated once" but with a more strict meaning; in C++, with the built-in += operator a()[foo()] += 1; not only avoids calling a() and foo() twice, it also avoids doing the internal indexing twice, while in python the internal indexing, locating that item, is performed first in __getitem__ and then in __setitem__ (unless that is optimized away at lower level by caching last access, but that in itself has overhead). Another reason was that ?6.2 does explicitly discuss attribute references as targets, but not subscription as target. It would have been more clear to me if all (four?) possible target forms were discussed. Happily you did now discuss that in the part that I snipped above, but would've been nice, and easier for for an other-language-thinking person :-), if it was in documentation. >> I did find discussion (end of ?6.2 of the language reference) of the >> case where the target is an attibute reference, with this example: >> >> class A: >> x = 3 # class variable >> a = A() >> a.x += 1 # writes a.x as 4 leaving A.x as 3 > > Do you want to discuss this example? Thanks but no, it's OK, I understand it. Cheers, - Alf From lie.1296 at gmail.com Fri Nov 6 02:30:18 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 06 Nov 2009 18:30:18 +1100 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: Message-ID: <4af3d0ae@dnews.tpgi.com.au> Peng Yu wrote: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. In functional language, there is no looping, so that argument is kind of pointless. The looping construct in many functional language is a syntax sugar for recursion. In python, instead of explicit loop, you can use either: map(pattern.match, list_of_strs) or [pattern.match(mystr) for mystr in list_of_strs] or if you want to be wicked evil, you can write a recursive function as such: def multimatcher(list_of_strs, index=0): return [] if index >= len(list_of_strs) else ( multimatcher( list_of_strs[index + 1] ).append( pattern.match(list_of_strs[index]) ) ) From clp2 at rebertia.com Fri Nov 6 03:19:56 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 00:19:56 -0800 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> Message-ID: <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> On Thu, Nov 5, 2009 at 10:49 PM, Gabriel Genellina wrote: > En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert > escribi?: >> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >>> I looked though the os.path manual. I don't find a function that can >>> test if a path is in a directory or its sub-directory (recursively). >>> >>> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >>> somebody let me know if such function is available somewhere? >> >> Couldn't you just canonicalize the paths using os.path.abspath() and >> friends and then do subdirectory.startswith(parent_directory) [as >> strings]? > > Beware of directories starting with the same letters. > I'd canonicalize, split the strings on os.sep, and compare the resulting > lists up to the shortest one. Ah, I thought there was some edge case I must've missed; my solution seemed too simple. Cheers, Chris From samuelrobertson at gmail.com Fri Nov 6 03:48:47 2009 From: samuelrobertson at gmail.com (sam) Date: Fri, 6 Nov 2009 00:48:47 -0800 (PST) Subject: decoding a byte array that is unicode escaped? Message-ID: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> I have a byte stream read over the internet: responseByteStream = urllib.request.urlopen( httpRequest ); responseByteArray = responseByteStream.read(); The characters are encoded with unicode escape sequences, for example a copyright symbol appears in the stream as the bytes: 5C 75 30 30 61 39 which translates to: \u00a9 which is unicode for the copyright symbol. I am simply trying to display this copyright symbol on a webpage, so how do I encode the byte array to utf-8 given that it is 'escape encoded' in the above way? I tried: responseByteArray.decode('utf-8') and responseByteArray.decode('unicode_escape') and str(responseByteArray). I am using Python 3.1. From __peter__ at web.de Fri Nov 6 03:59:24 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2009 09:59:24 +0100 Subject: decoding a byte array that is unicode escaped? References: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> Message-ID: sam wrote: > I have a byte stream read over the internet: > > responseByteStream = urllib.request.urlopen( httpRequest ); > responseByteArray = responseByteStream.read(); > > The characters are encoded with unicode escape sequences, for example > a copyright symbol appears in the stream as the bytes: > > 5C 75 30 30 61 39 > > which translates to: > \u00a9 > > which is unicode for the copyright symbol. > > I am simply trying to display this copyright symbol on a webpage, so > how do I encode the byte array to utf-8 given that it is 'escape > encoded' in the above way? I tried: > > responseByteArray.decode('utf-8') > and responseByteArray.decode('unicode_escape') > and str(responseByteArray). > > I am using Python 3.1. Convert the bytes to unicode first: >>> u = b"\\u00a9".decode("unicode-escape") >>> u '?' Then convert the string to bytes: >>> u.encode("utf-8") b'\xc2\xa9' From deets at nospam.web.de Fri Nov 6 04:05:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Nov 2009 10:05:30 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: Message-ID: <7li76qF3cq9l0U1@mid.uni-berlin.de> Peng Yu schrieb: > Suppose I have a list of strings, A. I want to compute the list (call > it B) of strings that are elements of A but doesn't match a regex. I > could use a for loop to do so. In a functional language, there is way > to do so without using the for loop. Nonsense. For processing over each element, you have to loop over them, either with or without growing a call-stack at the same time. FP languages can optimize away the stack-frame-growth (tail recursion) - but this isn't reducing complexity in any way. So use a loop, either directly, or using a list-comprehension. Diez From gagsl-py2 at yahoo.com.ar Fri Nov 6 04:28:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 06:28:58 -0300 Subject: list to table References: <553f664c-a83f-4338-9c82-4a8db35b9eb8@z4g2000prh.googlegroups.com> <522c2bd1-d9e8-4466-8fe5-4306e34e26c6@m26g2000yqb.googlegroups.com> Message-ID: En Fri, 06 Nov 2009 04:29:05 -0300, Alf P. Steinbach escribi?: > * Gabriel Genellina: >> En Thu, 05 Nov 2009 21:23:27 -0300, Alf P. Steinbach >> escribi?: >> >>> foo()[bar()] += 1 >>> > One reason was as mentioned that the C++ standard has essentially the > /same wording/ about "only evaluated once" but with a more strict > meaning; in C++, with the built-in += operator > > a()[foo()] += 1; > > not only avoids calling a() and foo() twice, it also avoids doing the > internal indexing twice, while in python the internal indexing, locating > that item, is performed first in __getitem__ and then in __setitem__ > (unless that is optimized away at lower level by caching last access, > but that in itself has overhead). Yes, that's a common misunderstanding in people coming from other languages with a different semantics for "assignment" and "variable". You're not alone :) Python does not have "lvalues" as in C++. In the statement x=1, the left hand side does not denote an object, but a name. x.attr=1 and x[index]=1 act more like a function call (they *are* function calls actually) than assignments. > Another reason was that ?6.2 does explicitly discuss attribute > references as targets, but not subscription as target. It would have > been more clear to me if all (four?) possible target forms were > discussed. Happily you did now discuss that in the part that I snipped > above, but would've been nice, and easier for for an > other-language-thinking person :-), if it was in documentation. Yes, probably that section should be improved (except the final example added, the text hasn't changed since it was first written, more than 9 years ago). Reading reference material may be terribly boring, I admit. Most people read only the specific sections required to solve a specific problem; and some concepts that are introduced earlier in the book are missed or skipped. If you haven't already done so, try at least to read these two sections from the Language Reference: 3.1. Objects, values and types, and 4.1. Naming and binding. They define the most important concepts in Python; the rest are just details. -- Gabriel Genellina From rpjday at crashcourse.ca Fri Nov 6 04:56:34 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 04:56:34 -0500 (EST) Subject: why does "help(import)" not work? Message-ID: i'm sure there's a painfully obvious answer to this, but is there a reason i can't do: >>> help(import) File "", line 1 help(import) ^ SyntaxError: invalid syntax >>> on the other hand, i can certainly go into "help()" and type "import" to get that help. it seems counter-intuitive to have the first variation fail but the second succeed. what is the rule for this in python3? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From simon at brunningonline.net Fri Nov 6 05:10:37 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:10:37 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <8c7f10c60911060210j47f8b46oa400158f64096d44@mail.gmail.com> 2009/11/6 Robert P. J. Day : > > ?i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > ?File "", line 1 > ? ?help(import) > ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax import is a keyword, not an object. -- Cheers, Simon B. From deets at nospam.web.de Fri Nov 6 05:11:44 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 06 Nov 2009 11:11:44 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <7lib31F3ekkv5U1@mid.uni-berlin.de> Robert P. J. Day schrieb: > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. > > what is the rule for this in python3? import is a keyword, so the parser can't comprehend the expression you created. In the same way it can't do it for help(class) or help(def) or any other keyword. Diez From clp2 at rebertia.com Fri Nov 6 05:12:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 02:12:09 -0800 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > ?i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > ?File "", line 1 > ? ?help(import) > ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax >>>> > > ?on the other hand, i can certainly go into "help()" and type > "import" to get that help. ?it seems counter-intuitive to have the > first variation fail but the second succeed. > > ?what is the rule for this in python3? "Special cases aren't special enough to break the rules." -- Zen of Python (http://www.python.org/dev/peps/pep-0020/) It would take a hideous kludge to make help(import) work. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 6 05:12:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 06 Nov 2009 11:12:38 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <4af3f68b$0$31102$426a74cc@news.free.fr> Robert P. J. Day a ?crit : > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) Yes, there's a very painfully obvious reason : 'import' is a statement, 'help' is a function, and you can't (syntactically) pass a statement as an argument to function !-) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. Would you find it more "intuitive" to have different syntactic rules for the interactive shell ?-) FWIW, the way to get help on a statement (or on a non-already defined name) is to pass a string to help, ie: help("import") HTH From jim.vickroy at noaa.gov Fri Nov 6 05:12:40 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:12:40 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: References: Message-ID: <4AF3F698.50309@noaa.gov> Gabriel Genellina wrote: > En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy > escribi?: > >> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >> any trace of the --install-script option, in release 2.6.4 (MS Windows >> XP), for distutils.core.setup. I also have been unable to locate any >> mention of it on-line. > > Do you mean this option? > http://docs.python.org/distutils/builtdist.html#the-postinstallation-script ... actually, I really do mean the --install-script option > Probably the distutils SIG is a better place to ask: > http://www.python.org/community/sigs/current/distutils-sig/ > Thanks for the tip, I'll give that a try. From Jim.Vickroy at noaa.gov Fri Nov 6 05:12:40 2009 From: Jim.Vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:12:40 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: References: Message-ID: <4AF3F698.50309@noaa.gov> Gabriel Genellina wrote: > En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy > escribi?: > >> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >> any trace of the --install-script option, in release 2.6.4 (MS Windows >> XP), for distutils.core.setup. I also have been unable to locate any >> mention of it on-line. > > Do you mean this option? > http://docs.python.org/distutils/builtdist.html#the-postinstallation-script ... actually, I really do mean the --install-script option > Probably the distutils SIG is a better place to ask: > http://www.python.org/community/sigs/current/distutils-sig/ > Thanks for the tip, I'll give that a try. From brian at sweetapp.com Fri Nov 6 05:14:02 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 6 Nov 2009 21:14:02 +1100 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: Hi Robert, help() is just a regular function that must be called with correct Python syntax and the import keyword is not allowed in an argument list. The correct syntax is: help('import') Cheers, Brian On 6 Nov 2009, at 20:56, Robert P. J. Day wrote: > > i'm sure there's a painfully obvious answer to this, but is there a > reason i can't do: > >>>> help(import) > File "", line 1 > help(import) > ^ > SyntaxError: invalid syntax >>>> > > on the other hand, i can certainly go into "help()" and type > "import" to get that help. it seems counter-intuitive to have the > first variation fail but the second succeed. > > what is the rule for this in python3? > > rday > -- > > > = > = > ====================================================================== > Robert P. J. Day Waterloo, Ontario, > CANADA > > Linux Consulting, Training and Kernel Pedantry. > > Web page: http://crashcourse.ca > Twitter: http://twitter.com/rpjday > = > = > ====================================================================== > -- > http://mail.python.org/mailman/listinfo/python-list From rpjday at crashcourse.ca Fri Nov 6 05:28:19 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:28:19 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Chris Rebert wrote: > On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > > ?i'm sure there's a painfully obvious answer to this, but is there a > > reason i can't do: > > > >>>> help(import) > > ?File "", line 1 > > ? ?help(import) > > ? ? ? ? ? ? ?^ > > SyntaxError: invalid syntax > >>>> > It would take a hideous kludge to make help(import) work. > > Cheers, > Chris um ... ok, i'll take your word for it, but is there at least a generalizable pattern for what is directly help()able and what isn't? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From Jim.Vickroy at noaa.gov Fri Nov 6 05:30:32 2009 From: Jim.Vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:30:32 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: <4AF3F698.50309@noaa.gov> References: <4AF3F698.50309@noaa.gov> Message-ID: <4AF3FAC8.4080601@noaa.gov> j vickroy wrote: > Gabriel Genellina wrote: >> En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy >> escribi?: >> >>> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >>> any trace of the --install-script option, in release 2.6.4 (MS >>> Windows XP), for distutils.core.setup. I also have been unable to >>> locate any mention of it on-line. >> >> Do you mean this option? >> http://docs.python.org/distutils/builtdist.html#the-postinstallation-script >> > ... actually, I really do mean the --install-script option Oh my, you are exactly right. That is it. That is what happens when I work at 3:00 AM. What I did not communicate clearly in my initial posting is that --install-script does not seem to be accepted in 2.6.4 and I could find no mention of that being the case on-line. Nor could I find this option in the 2.6.4 distutils source code of my Python installation. > >> Probably the distutils SIG is a better place to ask: >> http://www.python.org/community/sigs/current/distutils-sig/ >> > > Thanks for the tip, I'll give that a try. From jim.vickroy at noaa.gov Fri Nov 6 05:30:32 2009 From: jim.vickroy at noaa.gov (j vickroy) Date: Fri, 06 Nov 2009 03:30:32 -0700 Subject: distutils.core.setup --install-script option in Python 2.6 ? In-Reply-To: <4AF3F698.50309@noaa.gov> References: <4AF3F698.50309@noaa.gov> Message-ID: <4AF3FAC8.4080601@noaa.gov> j vickroy wrote: > Gabriel Genellina wrote: >> En Thu, 05 Nov 2009 16:15:06 -0300, j vickroy >> escribi?: >> >>> I have just upgraded from Python 2.5 to 2.6 and am unable to locate >>> any trace of the --install-script option, in release 2.6.4 (MS >>> Windows XP), for distutils.core.setup. I also have been unable to >>> locate any mention of it on-line. >> >> Do you mean this option? >> http://docs.python.org/distutils/builtdist.html#the-postinstallation-script >> > ... actually, I really do mean the --install-script option Oh my, you are exactly right. That is it. That is what happens when I work at 3:00 AM. What I did not communicate clearly in my initial posting is that --install-script does not seem to be accepted in 2.6.4 and I could find no mention of that being the case on-line. Nor could I find this option in the 2.6.4 distutils source code of my Python installation. > >> Probably the distutils SIG is a better place to ask: >> http://www.python.org/community/sigs/current/distutils-sig/ >> > > Thanks for the tip, I'll give that a try. From rpjday at crashcourse.ca Fri Nov 6 05:31:50 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:31:50 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: On Fri, 6 Nov 2009, Brian Quinlan wrote: > Hi Robert, > > help() is just a regular function that must be called with correct > Python syntax and the import keyword is not allowed in an argument > list. > > The correct syntax is: > help('import') ah, ok, now it makes sense. so python3 just lets me be sloppy about it, as in: >>> help(print) got it. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From clp2 at rebertia.com Fri Nov 6 05:36:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 02:36:14 -0800 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <50697b2c0911060236r7b0eff66q728c38a6a24b80e2@mail.gmail.com> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Chris Rebert wrote: > >> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: >> > ?i'm sure there's a painfully obvious answer to this, but is there a >> > reason i can't do: >> > >> >>>> help(import) >> > ?File "", line 1 >> > ? ?help(import) >> > ? ? ? ? ? ? ?^ >> > SyntaxError: invalid syntax >> >>>> > >> It would take a hideous kludge to make help(import) work. > > ?um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what isn't? Language keywords aren't help()-able: http://docs.python.org/reference/lexical_analysis.html#keywords Neither are punctuation/operators (see other sections on same webpage). help() is run-of-the-mill function, no different than any other, is not treated specially, and doesn't perform magic. You can't pass raw syntax elements to functions (whether the functions are built-in or user-defined). Cheers, Chris -- http://blog.rebertia.com From rpjday at crashcourse.ca Fri Nov 6 05:36:21 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 05:36:21 -0500 (EST) Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Chris Rebert wrote: > > > On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day wrote: > > > ?i'm sure there's a painfully obvious answer to this, but is there a > > > reason i can't do: > > > > > >>>> help(import) > > > ?File "", line 1 > > > ? ?help(import) > > > ? ? ? ? ? ? ?^ > > > SyntaxError: invalid syntax > > >>>> > > > It would take a hideous kludge to make help(import) work. > > > > Cheers, > > Chris > > um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what > isn't? never mind, i was just educated on the proper usage of help(). i *knew* i was going to embarrass myself when i asked that. :-P back to reading. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From simon at brunningonline.net Fri Nov 6 05:45:38 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:45:38 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <8c7f10c60911060245vb5a2fa7r8475c8ca393d4f1b@mail.gmail.com> 2009/11/6 Robert P. J. Day : > ?um ... ok, i'll take your word for it, but is there at least a > generalizable pattern for what is directly help()able and what isn't? If it's an object (or to be precise, a name bound to an object), it's helpable. If it's a keyword, it's not - and in fact can't be, since as you've found, it's a syntax error - so you fall back to passing a string. -- Cheers, Simon B. From simon at brunningonline.net Fri Nov 6 05:47:00 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 6 Nov 2009 10:47:00 +0000 Subject: why does "help(import)" not work? In-Reply-To: References: Message-ID: <8c7f10c60911060247q54101abcs5c98b17ee502ab02@mail.gmail.com> 2009/11/6 Robert P. J. Day : > ?ah, ok, now it makes sense. ?so python3 just lets me be sloppy about > it, as in: print is a function in Python 3, so that's fine. In Python 2, that would also be a syntax error. -- Cheers, Simon B. From paul.nospam at rudin.co.uk Fri Nov 6 05:49:17 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 06 Nov 2009 10:49:17 +0000 Subject: why does "help(import)" not work? References: Message-ID: <87iqdoc4ia.fsf@rudin.co.uk> "Robert P. J. Day" writes: > On Fri, 6 Nov 2009, Brian Quinlan wrote: > >> Hi Robert, >> >> help() is just a regular function that must be called with correct >> Python syntax and the import keyword is not allowed in an argument >> list. >> >> The correct syntax is: >> help('import') > > ah, ok, now it makes sense. so python3 just lets me be sloppy about > it, as in: > > >>> help(print) > > got it. In python 3 print is a function. From sion at viridian.paintbox Fri Nov 6 05:51:46 2009 From: sion at viridian.paintbox (Sion Arrowsmith) Date: Fri, 06 Nov 2009 10:51:46 GMT Subject: why does "help(import)" not work? References: Message-ID: <6dTIm.43163$%%3.9141@newsfe23.ams2> Robert P. J. Day wrote: >On Fri, 6 Nov 2009, Brian Quinlan wrote: >> The correct syntax is: >> help('import') > > ah, ok, now it makes sense. so python3 just lets me be sloppy about >it, as in: > > >>> help(print) No, "print" is a function in python3, not a statement as it is in earlier versions. There's nothing sloppy about it, and nothing in help has changed from 2 to 3: if it's a language keyword, you need to pass help it's name; if it's a function or a class, you can pass help the object itself. -- \S under construction From ldo at geek-central.gen.new_zealand Fri Nov 6 07:09:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 07 Nov 2009 01:09:51 +1300 Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: In message <87eioghrsk.fsf at benfinney.id.au>, Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> -- ?ScrolledCavas? should be >> ?ScrolledCanvas?. > > Thanks for finding and describing a fault with the Python documentation. > This is not the right place for reporting it, though: this is the Python > user forum, not an appropriate place for reporting faults. > > If you would like the issue to be addressed, please report it to the > Python bug tracking system . What do you want, a bloody HTML patch? Just fix the damn typo, already! From no.email at please.post Fri Nov 6 07:12:40 2009 From: no.email at please.post (kj) Date: Fri, 6 Nov 2009 12:12:40 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? Message-ID: In Perl one can assign a value to any element of an array, even to ones corresponding to indices greater or equal than the length of the array: my @arr; $arr[999] = 42; perl grows the array as needed to accommodate this assignment. In fact one common optimization in Perl is to "pre-grow" the array to its final size, rather than having perl grow it piecemeal as required by assignments like the one above: my @arr; $#arr = 999_999; After assigning to $#arr (the last index of @arr) as shown above, @arr has length 1,000,000, and all its elements are initialized to undef. In Python the most literal translation of the first code snippet above triggers an IndexError exception: >>> arr = list() >>> arr[999] = 42 Traceback (most recent call last): File "", line 1, in IndexError: list assignment index out of range In fact, one would need to pre-grow the list sufficiently to be able to make an assignment like this one. I.e. one needs the equivalent of the second Perl snippet above. The best I can come up with is this: arr = [None] * 1000000 Is this the most efficient way to achieve this result? TIA! kynn From http Fri Nov 6 07:34:08 2009 From: http (Paul Rubin) Date: 06 Nov 2009 04:34:08 -0800 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <7x7hu3g7cv.fsf@ruckus.brouhaha.com> kj writes: > >>> arr[999] = 42 > ... > The best I can come up with is this: > arr = [None] * 1000000 > Is this the most efficient way to achieve this result? If you're talking about an array of ints, use the array module. You might also look at numpy. From mrkafk at gmail.com Fri Nov 6 08:20:42 2009 From: mrkafk at gmail.com (mk) Date: Fri, 06 Nov 2009 14:20:42 +0100 Subject: is None or == None ? Message-ID: Hello, Some claim that one should test for None using: if x is None: ..but the standard equality which is theoretically safer works as well: if x == None: So, which one is recommended? Can there be two None objects in interpreter's memory? Is testing for identity of some variable with None safe? Does language guarantee that? Or is it just property of implementation? Regards, mk From dickinsm at gmail.com Fri Nov 6 08:28:44 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 6 Nov 2009 05:28:44 -0800 (PST) Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: On Nov 6, 12:09?pm, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.... at benfinney.id.au>, Ben Finney wrote: > > > Lawrence D'Oliveiro writes: > > >> -- ?ScrolledCavas? should be > >> ?ScrolledCanvas?. > > > Thanks for finding and describing a fault with the Python documentation. > > This is not the right place for reporting it, though: this is the Python > > user forum, not an appropriate place for reporting faults. > > > If you would like the issue to be addressed, please report it to the > > Python bug tracking system . > > What do you want, a bloody HTML patch? Nope; just the first two lines of your original post in a bugs.python.org report would be plenty. If you make sure to mark 'Documentation' in the Components field, I think this will get corrected pretty quickly. > Just fix the damn typo, already! Who is this addressed to? The chances are that the people most likely to fix this aren't reading this thread. I'd fix it myself, but I'm at work at the moment with no commit access to the Python svn repo. And by the time I get home, I'll probably have forgotten about it. Filing a bugs.python.org issue makes sure that this *will* get noticed by someone. Mark From cokofreedom at gmail.com Fri Nov 6 08:32:58 2009 From: cokofreedom at gmail.com (hob) Date: Fri, 6 Nov 2009 05:32:58 -0800 (PST) Subject: Best way for permutating using multiple lists? Message-ID: if __name__ == '__main__': permutations = list() for i in list('def'): for j in list('abc'): for k in list('mno'): for l in list('mno'): for m in list('wxyz'): permutations.append() print '\t'.join("%s" % i for i in permutations) I'd rather find a way that can perform a permutation over any number of lists. I know there should be a way of doing this but my head isn't working today, any advice people? From stefan_ml at behnel.de Fri Nov 6 08:33:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 06 Nov 2009 14:33:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> mk, 06.11.2009 14:20: > Some claim that one should test for None using: > > if x is None: Which is the correct and safe way of doing it. > ..but the standard equality which is theoretically safer works as well: > > if x == None: Absolutely not safe, think of class Test(object): def __eq__(self, other): return other == None print Test() == None, Test() is None Stefan From dickinsm at gmail.com Fri Nov 6 08:33:47 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 6 Nov 2009 05:33:47 -0800 (PST) Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: On Nov 6, 12:09?pm, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.... at benfinney.id.au>, Ben Finney wrote: > > > Lawrence D'Oliveiro writes: > > >> -- ?ScrolledCavas? should be > >> ?ScrolledCanvas?. > > > Thanks for finding and describing a fault with the Python documentation. > > This is not the right place for reporting it, though: this is the Python > > user forum, not an appropriate place for reporting faults. > > > If you would like the issue to be addressed, please report it to the > > Python bug tracking system . > > What do you want, a bloody HTML patch? Just fix the damn typo, already! http://bugs.python.org/issue7271 Mark From alfps at start.no Fri Nov 6 08:35:14 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 14:35:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: * mk: > Hello, > > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? > > Can there be two None objects in interpreter's memory? Is testing for > identity of some variable with None safe? Does language guarantee that? > Or is it just property of implementation? As I understand it, 'is' will always work and will always be efficient (it just checks the variable's type), while '==' can depend on the implementation of equality checking for the other operand's class. Cheers & hth., - Alf From joncle at googlemail.com Fri Nov 6 08:39:44 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 05:39:44 -0800 (PST) Subject: Best way for permutating using multiple lists? References: Message-ID: On Nov 6, 1:32?pm, hob wrote: > if __name__ == '__main__': > ? ? permutations = list() > ? ? for i in list('def'): > ? ? ? ? for j in list('abc'): > ? ? ? ? ? ? for k in list('mno'): > ? ? ? ? ? ? ? ? for l in list('mno'): > ? ? ? ? ? ? ? ? ? ? for m in list('wxyz'): > ? ? ? ? ? ? ? ? ? ? ? ? permutations.append() > ? ? print '\t'.join("%s" % i for i in permutations) > > I'd rather find a way that can perform a permutation over any number > of lists. I know there should be a way of doing this but my head isn't > working today, any advice people? itertools.permutations (maybe with itertools.chain)? hth Jon. From motoom at xs4all.nl Fri Nov 6 08:43:07 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Fri, 06 Nov 2009 14:43:07 +0100 Subject: Best way for permutating using multiple lists? In-Reply-To: References: Message-ID: <4AF427EB.8010804@xs4all.nl> hob wrote: > any advice people? import itertools alt=itertools.product("def","abc","mno","mno","wxyz") -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From youngde811 at gmail.com Fri Nov 6 08:59:00 2009 From: youngde811 at gmail.com (david) Date: Fri, 6 Nov 2009 05:59:00 -0800 (PST) Subject: Why do you use python? References: <2a7e7d01-a0f2-472d-b340-2592e4eddbc4@y10g2000prg.googlegroups.com> Message-ID: <63004d17-0f51-48bb-85a5-ab17b8cc27d9@z41g2000yqz.googlegroups.com> I liked your disclaimer (I'm done a lot of commercial Common Lisp), and I agree with your comments regarding python. I've turned down recruiters who have offered otherwise interesting positions, but Java was being used. This is just personal, and I'm not going to disparage anyone who enjoys Java, C++, whatever. But for me, dynamic languages (particularly python and Lisp) are so far ahead of anything else. -- david From sjmachin at lexicon.net Fri Nov 6 09:09:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 6 Nov 2009 06:09:03 -0800 (PST) Subject: is None or == None ? References: Message-ID: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> On Nov 7, 12:35?am, "Alf P. Steinbach" wrote: > * mk: > > > Hello, > > > Some claim that one should test for None using: > > > if x is None: > > > ..but the standard equality which is theoretically safer works as well: > > > if x == None: > > > So, which one is recommended? > > > As I understand it, 'is' will always work and will always be efficient (it just > checks the variable's type), It doesn't check the type. It doesn't need to. (x is y) is true if x and y are the same object. If that is so, then of course (type(x) is type(y)) is true, and if not so, their types are irrelevant. "is" testing is very efficient in the CPython implementation: addressof(x) == addressof(y) From joncle at googlemail.com Fri Nov 6 09:11:44 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 06:11:44 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On Nov 6, 12:12?pm, kj wrote: [snip] > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? That's a good as it gets I think. If sparsely populated I might be tempted to use a dict (or maybe defaultdict): d = {999: 42, 10673: 123} for idx in xrange(1000000): # Treat it as though it's a list of 1,000,000 items... print 'index %d has a value of %d' % (idx, d.get(idx, None)) Efficiency completely untested. Jon. From marco at sferacarta.com Fri Nov 6 09:13:14 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 06 Nov 2009 15:13:14 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: <_9WIm.27714$813.11966@tornado.fastwebnet.it> Alf P. Steinbach wrote: > As I understand it, 'is' will always work and will always be efficient > (it just checks the variable's type), while '==' can depend on the > implementation of equality checking for the other operand's class. "== None" makes sense, for instance, in the context of the SQLAlchemy sql construction layer, where the underlying machinery defines __eq__() / __ne__() and generates the appropriate 'IS NULL' SQL code when appropriate. From san82moon at gmail.com Fri Nov 6 09:15:06 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 06:15:06 -0800 (PST) Subject: newbie question - python lists Message-ID: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> hi, rfids= ['01','02'] i = 01 row = {} items = [] for rfid in rfids: brains = ['1','2'] if brains: for brain in brains: # this loop must run only once for each value of i row['itemnos'] = 'item_0'+str(i)+'s' print 'hi' items.append(row) print items break i=i+1 the above code produces output a: [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] but i want it to be, [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] can anyone point wer am erroring. Thanks in advance. From mrkafk at gmail.com Fri Nov 6 09:32:52 2009 From: mrkafk at gmail.com (mk) Date: Fri, 06 Nov 2009 15:32:52 +0100 Subject: is None or == None ? In-Reply-To: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> References: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > mk, 06.11.2009 14:20: >> Some claim that one should test for None using: >> >> if x is None: > > Which is the correct and safe way of doing it. ok >> ..but the standard equality which is theoretically safer works as well: >> >> if x == None: > > Absolutely not safe, think of > > class Test(object): > def __eq__(self, other): > return other == None > > print Test() == None, Test() is None Err, I don't want to sound daft, but what is wrong in this example? It should work as expected: >>> class Test(object): ... def __eq__(self, other): ... return other == None ... >>> Test() is None False >>> Test() == None True My interpretation of 1st call is that it is correct: instance Test() is not None (in terms of identity), but it happens to have value equal to None (2nd call). Or perhaps your example was supposed to show that I should test for identity with None, not for value with None? That, however, opens a can of worms, sort of: whether one should compare Test() for identity with None or for value with None depends on what programmer meant at the moment. Regards, mk From jim.hefferon at gmail.com Fri Nov 6 09:48:52 2009 From: jim.hefferon at gmail.com (Jim) Date: Fri, 6 Nov 2009 06:48:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Nov 6, 9:15 am, lee wrote: > can anyone point wer am erroring. I'm not sure what you are trying to do, but it is odd, isn't it, that you never refer to brain in the "for brain in brains:" loop? I think you are mixing i and brain somehow. Jim From fetchinson at googlemail.com Fri Nov 6 09:51:56 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 6 Nov 2009 15:51:56 +0100 Subject: is None or == None ? In-Reply-To: References: Message-ID: > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? It depends on what you want to do. There is no single answer to your question, until you tell us what your context is. The None object in python is a singleton. If you want to check whether a given object is this singleton None object (note that this is unambiguous, it either occupies the same address in memory as the singleton None or it doesn't) then you should use 'x is None'. If, however you want to test for equality, you should use 'x == None'. An object 'x' may implement equality checks in a funny way and it may be that 'x == None' is True although 'x is None' is False. But it may be that this is exactly what you want, because the author of the object 'x' intentionally has written the equality check code to make this so. In this case you need 'x == None'. So unless you tell us in what context you are asking this question, there is no single answer to it. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mah at spam.la Fri Nov 6 09:52:18 2009 From: mah at spam.la (Marco Bazzani) Date: Fri, 06 Nov 2009 15:52:18 +0100 Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: On Tue, 03 Nov 2009 16:58:16 +0100, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > blank page ? -- reply at: echo "nntp at marcobazzani dot name" |sed s/\ at\ /@/ |sed s/\ dot\ /./ From brian.curtin at gmail.com Fri Nov 6 09:56:28 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Fri, 6 Nov 2009 08:56:28 -0600 Subject: newbie question - python lists In-Reply-To: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, Nov 6, 2009 at 08:15, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. > Your call to items.append(row) passes row by reference. You added a row dictionary with key "itemnos" set to value "item_01s" the first time through the loop. The second time, you added a row dictionary with key "itemnos" set to value "item_02s". This modified the underlying `row` dictionary, so it also modified what you thought you put in the list in the first time through the loop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.weismueller at gmail.com Fri Nov 6 09:56:45 2009 From: jonas.weismueller at gmail.com (Jonas) Date: Fri, 6 Nov 2009 06:56:45 -0800 (PST) Subject: Securing a multiprocessing.BaseManager connection via SSL Message-ID: Hi, how can I secure the communication between two BaseManager objects? Regarding the socket/SSL documentation I just need to secure the socket by SSL. How can i get the socket object within the multiprocessing module? Best regards, Jonas From brian.curtin at gmail.com Fri Nov 6 10:04:28 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Fri, 6 Nov 2009 09:04:28 -0600 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: On Fri, Nov 6, 2009 at 06:12, kj wrote: > > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > my @arr; > $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > my @arr; > $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > Traceback (most recent call last): > File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn > Is there a reason you need to pre-allocate the list other than the fact that you do it that way in Perl? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Fri Nov 6 10:07:23 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 06 Nov 2009 10:07:23 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <4AF43BAB.5000201@codebykevin.com> On 11/3/09 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > I noticed information on py2app was mostly missing from your chart. --single exe file: yes, with qualification. On the Mac, standalone applications are actually directories called "application bundles" designed to look like a single file that can be double-clicked on. So, a lot of stuff--the Python libraries, icons, other resource files--are hidden inside the app bundle. --without unzipping at runtime--Yes. --control over output directory structure--no. --creates installer too: yes, with qualification. If you're building an app, you don't use an installer--the standard Mac method is drag-and-drop installation. You can also use py2app to package up Python libraries, and for these, it can create a standard Mac pkg installer. --Python 3--not yet, as far as I know. --can run as -O--not sure. --control over process/ouput--not sure what this means. --distribution size--Varies widely. A big Python application with lots of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with no other extensions would weigh in at about 20 megabytes--that's the smallest. --active development--some, but only in svn. Last stable release was a few years ago. --active mailing list--no standalone mailing list, but the PythonMac-sig mailing list has lots of discussion and bug reporting on py2app. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From andreengels at gmail.com Fri Nov 6 10:12:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 6 Nov 2009 16:12:59 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: <6faf39c90911060712s6e410168k726b95d84bcf1d8b@mail.gmail.com> On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: > > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ?my @arr; > ?$arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ?my @arr; > ?$#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > >>>> arr = list() >>>> arr[999] = 42 > Traceback (most recent call last): > ?File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? It depends - what do you want to do with it? My first hunch would be to use a dictionary instead of a list, then the whole problem disappears. If there is a reason you don't want to do that, what is it? -- Andr? Engels, andreengels at gmail.com From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 6 10:15:11 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 06 Nov 2009 16:15:11 +0100 Subject: why does "help(import)" not work? In-Reply-To: References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> Message-ID: <4af43d73$0$11898$426a74cc@news.free.fr> Chris Rebert a ?crit : > On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day wrote: > >> um ... ok, i'll take your word for it, but is there at least a >> generalizable pattern for what is directly help()able and what isn't? > > Language keywords aren't help()-able: > http://docs.python.org/reference/lexical_analysis.html#keywords > Neither are punctuation/operators (see other sections on same webpage). Ever tried help("import") or help("if") or help("+") ? From alfps at start.no Fri Nov 6 10:16:54 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 16:16:54 +0100 Subject: is None or == None ? In-Reply-To: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * John Machin: > On Nov 7, 12:35 am, "Alf P. Steinbach" wrote: >> * mk: >> >>> Hello, >>> Some claim that one should test for None using: >>> if x is None: >>> ..but the standard equality which is theoretically safer works as well: >>> if x == None: >>> So, which one is recommended? >> >> As I understand it, 'is' will always work and will always be efficient (it just >> checks the variable's type), > > It doesn't check the type. > It doesn't need to. (x is y) is true if x > and y are the same object. If that is so, then of course (type(x) is > type(y)) is true, and if not so, their types are irrelevant. "is" > testing is very efficient in the CPython implementation: addressof(x) > == addressof(y) Maybe. I imagined it wouldn't waste additional space for e.g. (Python 2.x) int values, but just use the same space as used for pointer in the case of e.g. string, in which case it would have to check the type -- an integer can very easily have the same bitpattern as a pointer residing there. If you imagine that instead, for an integer variable x it stores the integer value in the variable in some other place than ordinarily used for pointer, and let the pointer point to that place in the same variable, then without checking type the 'is' operator should report false for 'x = 3; y = 3; x is y', but it doesn't with my Python installation, so if it doesn't check the type then even this half-measure (just somewhat wasteful of space) optimization isn't there. In short, you're saying that there is an extreme inefficiency with every integer dynamically allocated /plus/, upon production of an integer by e.g. + or *, inefficiently finding the previously allocated integer of that value and pointing there, sort of piling inefficiency on top of inefficiency, which is absurd but I have seen absurd things before so it's not completely unbelievable. I hope someone else can comment on these implications of your statement. Cheers, - Alf From joncle at googlemail.com Fri Nov 6 10:17:24 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 07:17:24 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <54adc2ba-d4f7-4d70-97cb-fcc474b005ab@t2g2000yqn.googlegroups.com> On Nov 6, 2:15?pm, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > ? ? brains = ['1','2'] > > ? ? if brains: > ? ? ? ? for brain in brains: > ? ? ? ? ? ? # this loop must run only once for each value of i > ? ? ? ? ? ? row['itemnos'] = 'item_0'+str(i)+'s' > ? ? ? ? ? ? print 'hi' > ? ? ? ? ? ? items.append(row) > ? ? ? ? ? ? print items > ? ? ? ? ? ? break > ? ? i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. You've made a good effort (and discovered at least one major common gotcha). There's lots in your code that needs highlighting. However, probably a good starting point would to be describe in plain english, what you're trying to achieve; Are you really sure you want a list of single item dict's? Jon. From rpjday at crashcourse.ca Fri Nov 6 10:31:17 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 10:31:17 -0500 (EST) Subject: newbie question - python lists In-Reply-To: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, 6 Nov 2009, lee wrote: > hi, > > rfids= ['01','02'] > i = 01 for what it's worth, that statement above isn't even legal python3. > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From jjposner at optimum.net Fri Nov 6 10:44:38 2009 From: jjposner at optimum.net (John Posner) Date: Fri, 06 Nov 2009 10:44:38 -0500 Subject: list to table In-Reply-To: References: Message-ID: <4AF44466.4040200@optimum.net> Gabriel Genellina said: > >> Another reason was that ?6.2 does explicitly discuss attribute >> references as targets, but not subscription as target. It would have >> been more clear to me if all (four?) possible target forms were >> discussed. Happily you did now discuss that in the part that I >> snipped above, but would've been nice, and easier for for an >> other-language-thinking person :-), if it was in documentation. > > Yes, probably that section should be improved (except the final > example added, the text hasn't changed since it was first written, > more than 9 years ago). > FWIW ... following on a discussion in this forum in March of this year [1], I submitted issue #5621 at bugs.python.org, along with a proposed rewording of the documentation of this case: self.x = self.x + 1 I did *not* address the case in which the target is a subscription -- it wasn't the focus of the forum discussion. IMHO, the subscription case is much less subject to misunderstanding than the instance-attribute-vs-class-attribute case. My change was accepted (with some rearrangements made by Georg Brandl), but has not yet been included in any Py2 or Py3 release, AFAIK. -John [1] http://mail.python.org/pipermail/python-list/2009-March/175054.html From marco at sferacarta.com Fri Nov 6 10:51:18 2009 From: marco at sferacarta.com (Marco Mariani) Date: Fri, 06 Nov 2009 16:51:18 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > If you imagine that instead, for an integer variable x it stores the > integer value in the variable in some other place than ordinarily used > for pointer, and let the pointer point to that place in the same > variable, then without checking type the 'is' operator should report > false for 'x = 3; y = 3; x is y', but it doesn't with my Python Yes, CPython caches a handful of small, "commonly used" integers, and creates objects for them upon startup. Using "x is y" with integers makes no sense and has no guaranteed behaviour AFAIK > In short, you're saying that there is an extreme inefficiency with every > integer dynamically allocated /plus/, upon production of an integer by > e.g. + or *, inefficiently finding the previously allocated integer of > that value and pointing there, no, it doesn't "point there": >>>> a=1E6 >>>> a is 1E6 > False >>>> a=100 >>>> a is 100 > True From jjkk73 at gmail.com Fri Nov 6 11:04:37 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 6 Nov 2009 16:04:37 +0000 Subject: Defining re pattern for matching list of numbers Message-ID: Hi, I'm trying to write a re pattern to match a list of one or more numbers, each number is in the range of 1-15 value and the numbers are separated by spaces (but there are no spaces at the beginning and end of the string). For instance: "3" "1 14 8" but not: "22" " 5 11" I've come up with something like this re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") but I can't believe this has to be so complicated. Does anyone know some simpler re pattern to match this kind of string Many thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Fri Nov 6 11:16:58 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 6 Nov 2009 10:16:58 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <7li76qF3cq9l0U1@mid.uni-berlin.de> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> Message-ID: <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: > Peng Yu schrieb: >> >> Suppose I have a list of strings, A. I want to compute the list (call >> it B) of strings that are elements of A but doesn't match a regex. I >> could use a for loop to do so. In a functional language, there is way >> to do so without using the for loop. > > Nonsense. For processing over each element, you have to loop over them, > either with or without growing a call-stack at the same time. > > FP languages can optimize away the stack-frame-growth (tail recursion) - but > this isn't reducing complexity in any way. > > So use a loop, either directly, or using a list-comprehension. What is a list-comprehension? I tried the following code. The list 'l' will be ['a','b','c'] rather than ['b','c'], which is what I want. It seems 'remove' will disrupt the iterator, right? I am wondering how to make the code correct. l = ['a', 'a', 'b', 'c'] for x in l: if x == 'a': l.remove(x) print l From rpjday at crashcourse.ca Fri Nov 6 11:42:45 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 11:42:45 -0500 (EST) Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: On Fri, 6 Nov 2009, Peng Yu wrote: > On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: > > Peng Yu schrieb: > >> > >> Suppose I have a list of strings, A. I want to compute the list (call > >> it B) of strings that are elements of A but doesn't match a regex. I > >> could use a for loop to do so. In a functional language, there is way > >> to do so without using the for loop. > > > > Nonsense. For processing over each element, you have to loop over them, > > either with or without growing a call-stack at the same time. > > > > FP languages can optimize away the stack-frame-growth (tail recursion) - but > > this isn't reducing complexity in any way. > > > > So use a loop, either directly, or using a list-comprehension. > > What is a list-comprehension? > > I tried the following code. The list 'l' will be ['a','b','c'] rather > than ['b','c'], which is what I want. It seems 'remove' will disrupt > the iterator, right? I am wondering how to make the code correct. > > l = ['a', 'a', 'b', 'c'] > for x in l: > if x == 'a': > l.remove(x) > > print l list comprehension seems to be what you want: l = [i for i in l if i != 'a'] rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From san82moon at gmail.com Fri Nov 6 11:47:33 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:47:33 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From san82moon at gmail.com Fri Nov 6 11:49:52 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:49:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From info at egenix.com Fri Nov 6 11:51:18 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Fri, 06 Nov 2009 17:51:18 +0100 Subject: ANN: eGenix mxODBC - Python ODBC Database Interface 3.0.4 Message-ID: <4AF45406.3040407@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - Python ODBC Database Interface Version 3.0.4 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.0.4-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS mxODBC 3.0.4 is a patch-level release and includes the following updates: * Fixed Mac OS X Intel builds: The Mac OS X builds for 3.0.3 had a problem finding the installed iODBC administrator libraries on Intel Macs. This problem has now been resolved. Note: If you are having trouble finding the ODBC administrator on Mac OS X 10.6 (Snow Leopard), this is because the initial release of 10.6 did not include the administrator GUI. You can download the update with the ODBC administrator from the Apple support site: http://support.apple.com/downloads/ODBC_Administrator_Tool_for_Mac_OS_X Since mxODBC for Mac OS X is currently only available for 32-bit PPC and Intel platforms, be sure to use the Python.org 32-bit Mac OS X installer for installing Python and 32-bit ODBC drivers on Snow Leopard. * Enhanced support detecting platform mismatches: We have added better support for detecting mismatches between the downloaded prebuilt archive and the installation target configuration to the prebuilt archive installers. The setup.py script now prints an error message explaining the mismatch rather then trying to rebuild the extension. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC release, especially if you are using MS SQL Server or Informix as database server. Customers who have purchased mxODBC 3.0 licenses can download and install this patch-level release on top of their existing installations. The licenses will continue to work with version 3.0.4. Users of mxODBC 1.0 and 2.0 will have to purchase new licenses from our online shop in order to upgrade to mxODBC 3.0.4. You can request 30-day evaluation licenses by visiting our web-site at http://www.egenix.com/products/python/mxODBC/#Evaluation or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 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 alfps at start.no Fri Nov 6 11:54:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 17:54:53 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Marco Mariani: > Alf P. Steinbach wrote: > >> If you imagine that instead, for an integer variable x it stores the >> integer value in the variable in some other place than ordinarily used >> for pointer, and let the pointer point to that place in the same >> variable, then without checking type the 'is' operator should report >> false for 'x = 3; y = 3; x is y', but it doesn't with my Python > > Yes, CPython caches a handful of small, "commonly used" integers, and > creates objects for them upon startup. Using "x is y" with integers > makes no sense and has no guaranteed behaviour AFAIK > >> In short, you're saying that there is an extreme inefficiency with >> every integer dynamically allocated /plus/, upon production of an >> integer by e.g. + or *, inefficiently finding the previously allocated >> integer of that value and pointing there, > > no, it doesn't "point there": > >>>>> a=1E6 >>>>> a is 1E6 >> False >>>>> a=100 >>>>> a is 100 >> True I stand corrected on that issue, I didn't think of cache for small values. On my CPython 3.1.1 the cache seems to support integer values -5 to +256, inclusive, apparently using 16 bytes of storage per value (this last assuming id() just returns the address). But wow. That's pretty hare-brained: dynamic allocation for every stored value outside the cache range, needless extra indirection for every operation. Even Microsoft COM managed to get this right. On the positive side, except that it would probably break every C module (I don't know), in consultant speak that's definitely a potential for improvement. :-p Cheers, - Alf From san82moon at gmail.com Fri Nov 6 11:56:34 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 08:56:34 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <33ef111d-fa99-4788-8bda-631819929d03@g1g2000pra.googlegroups.com> On Nov 6, 7:48?pm, Jim wrote: > On Nov 6, 9:15 am, lee wrote: > > > can anyone point wer am erroring. > > I'm not sure what you are trying to do, but it is odd, isn't it, that > you never refer to brain in the "for brain in brains:" loop? ?I think > you are mixing i and brain somehow. > > Jim ok let me make it clear, brains = ['1','2'] for brain in brains: row['item'] = brain items.append(row) print items This produces [{'item': '1'}] [{'item': '2'}, {'item': '2'}] but i want [{'item': '1'}] [{'item': '1'}, {'item': '2'}] if i do items.append(brain), it gives, ['1', '2'] but i want dictionary inside list. @Jon - Yes i want single item dict's @Robert - i use python 2.4 . Thanks Lee. From pengyu.ut at gmail.com Fri Nov 6 11:58:13 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 6 Nov 2009 10:58:13 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: > On Fri, 6 Nov 2009, Peng Yu wrote: > >> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >> > Peng Yu schrieb: >> >> >> >> Suppose I have a list of strings, A. I want to compute the list (call >> >> it B) of strings that are elements of A but doesn't match a regex. I >> >> could use a for loop to do so. In a functional language, there is way >> >> to do so without using the for loop. >> > >> > Nonsense. For processing over each element, you have to loop over them, >> > either with or without growing a call-stack at the same time. >> > >> > FP languages can optimize away the stack-frame-growth (tail recursion) - but >> > this isn't reducing complexity in any way. >> > >> > So use a loop, either directly, or using a list-comprehension. >> >> What is a list-comprehension? >> >> I tried the following code. The list 'l' will be ['a','b','c'] rather >> than ['b','c'], which is what I want. It seems 'remove' will disrupt >> the iterator, right? I am wondering how to make the code correct. >> >> l = ['a', 'a', 'b', 'c'] >> for x in l: >> ? if x == 'a': >> ? ? l.remove(x) >> >> print l > > ?list comprehension seems to be what you want: > > ?l = [i for i in l if i != 'a'] My problem comes from the context of using os.walk(). Please see the description of the following webpage. Somehow I have to modify the list inplace. I have already tried 'dirs = [i for i in l if dirs != 'a']'. But it seems that it doesn't "prune the search". So I need the inplace modification of list. http://docs.python.org/library/os.html When topdown is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again. Modifying dirnames when topdown is False is ineffective, because in bottom-up mode the directories in dirnames are generated before dirpath itself is generated. From emily at nospam.com Fri Nov 6 12:00:30 2009 From: emily at nospam.com (Emily Rodgers) Date: Fri, 6 Nov 2009 17:00:30 -0000 Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: "lee" wrote in message news:8d1009a4-54c8-4bb3-9862-8b22e6b42a3b at y10g2000prg.googlegroups.com... > hi, > > rfids= ['01','02'] > i = 01 > row = {} > items = [] > for rfid in rfids: > > brains = ['1','2'] > > if brains: > for brain in brains: > # this loop must run only once for each value of i > row['itemnos'] = 'item_0'+str(i)+'s' > print 'hi' > items.append(row) > print items > break > i=i+1 > > the above code produces output a: > [{'itemnos': 'item_02s'}, {'itemnos': 'item_02s'}] > but i want it to be, > [{'itemnos': 'item_01s'}, {'itemnos': 'item_02s'}] > > can anyone point wer am erroring. > Thanks in advance. Hi, As some others have pointed out, it is not totally clear from your code what you are trying to do, but I will forgive you for that because you are clearly not used to python! I think what you are trying to do is: items = [] rfids= ['01','02'] for rfid in rfids: items.append({'itemnos': 'item_%ss' % rfid}) print items This can also be done using a list comprehension which is one of the (many) most useful features of python (imo): rfids= ['01','02'] print [{'itemnos': 'item_%ss' % rfid} for rfid in rfids] Or on one line (although it is always to be clearer rather trying to fit stuff into one line - it is not perl!) print [{'itemnos': 'item_%ss' % rfid} for rfid in ['01', '02']] Hope this helps. Emily From rami.chowdhury at gmail.com Fri Nov 6 12:04:18 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:04:18 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach wrote: > But wow. That's pretty hare-brained: dynamic allocation for every stored > value outside the cache range, needless extra indirection for every > operation. > Perhaps I'm not understanding this thread at all but how is dynamic allocation hare-brained, and what's the 'needless extra indirection'? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From __peter__ at web.de Fri Nov 6 12:05:11 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Nov 2009 18:05:11 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> Message-ID: Peng Yu wrote: > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs = [i for i in l if dirs != > 'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. Use dirs[:] = [d for d in dirs if d != "a"] or try: dirs.remove("a") except ValueError: pass From rpjday at crashcourse.ca Fri Nov 6 12:05:17 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Fri, 6 Nov 2009 12:05:17 -0500 (EST) Subject: newbie question - python lists In-Reply-To: References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: On Fri, 6 Nov 2009, lee wrote: > brains = ['1','2'] > for brain in brains: > row['item'] = brain > items.append(row) > print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . this seems to work: items = [] brains = ['1','2','3','4'] for brain in brains: items.append({'item':brain}) print(items) >>> import t1 [{'item': '1'}] [{'item': '1'}, {'item': '2'}] [{'item': '1'}, {'item': '2'}, {'item': '3'}] [{'item': '1'}, {'item': '2'}, {'item': '3'}, {'item': '4'}] rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From benjamin.kaplan at case.edu Fri Nov 6 12:07:17 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 6 Nov 2009 12:07:17 -0500 Subject: newbie question - python lists In-Reply-To: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> Message-ID: On Fri, Nov 6, 2009 at 11:49 AM, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: >> On Nov 6, 9:15 am, lee wrote: >> >> > can anyone point wer am erroring. >> >> I'm not sure what you are trying to do, but it is odd, isn't it, that >> you never refer to brain in the "for brain in brains:" loop? ?I think >> you are mixing i and brain somehow. >> >> Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > ? ?row['item'] = brain > ? ?items.append(row) > ? ?print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . > > Thanks > Lee. With Python, you're always dealing with objects, not with values. It isn't apparent with immutable objects like strings and ints, but here's what's actually happening. At the end, your list is [row, row]. It's the exact same dictionary. The value wasn't copied in. Try this row = {} row['item'] = 1 items = [row] row['item'] = 2 print row You get the same thing- you're changing the dict that's already in items. In order to get two different elements, you have to use 2 different dicts. if brains: for brain in brains: # this loop must run only once for each value of i row = { 'itemnos': 'item_0'+str(i)+'s'} print 'hi' items.append(row) print items break i=i+1 > -- > http://mail.python.org/mailman/listinfo/python-list > From rami.chowdhury at gmail.com Fri Nov 6 12:12:32 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:12:32 -0800 Subject: newbie question - python lists In-Reply-To: <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <578cc5f5-0f98-4a22-aca5-7e2b24417e58@g1g2000pra.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 08:49:52 -0800, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: >> On Nov 6, 9:15 am, lee wrote: >> >> > can anyone point wer am erroring. >> >> I'm not sure what you are trying to do, but it is odd, isn't it, that >> you never refer to brain in the "for brain in brains:" loop? ?I think >> you are mixing i and brain somehow. >> >> Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > row['item'] = brain > items.append(row) > print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > Lee, When you do > row['item'] = brain you are actually modifying the existing dictionary object called 'row' -- and I get the impression this is not what you want to do. I'd suggest creating a new dictionary on each pass, which should give you the desired behavior. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From flashk at gmail.com Fri Nov 6 12:12:57 2009 From: flashk at gmail.com (Farshid) Date: Fri, 6 Nov 2009 09:12:57 -0800 (PST) Subject: 2to3 ParseError with UTF-8 BOM References: Message-ID: <50ad856e-8118-4374-82a4-58243ae3434b@13g2000prl.googlegroups.com> On Nov 5, 7:18?pm, Benjamin Peterson wrote: > Try the 2to3 distributed in Python 3.1. I get the same error with the 2to3 script in Python 3.1 -farshid From san82moon at gmail.com Fri Nov 6 12:19:00 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 09:19:00 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> Message-ID: <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> On Nov 6, 9:47?pm, lee wrote: > On Nov 6, 7:48?pm, Jim wrote: > > > On Nov 6, 9:15 am, lee wrote: > > > > can anyone point wer am erroring. > > > I'm not sure what you are trying to do, but it is odd, isn't it, that > > you never refer to brain in the "for brain in brains:" loop? ?I think > > you are mixing i and brain somehow. > > > Jim > > ok let me make it clear, > > brains = ['1','2'] > for brain in brains: > ? ? row['item'] = brain > ? ? items.append(row) > ? ? print items > > This produces > [{'item': '1'}] > [{'item': '2'}, {'item': '2'}] > but i want > [{'item': '1'}] > [{'item': '1'}, {'item': '2'}] > > if i do items.append(brain), it gives, > ['1', '2'] > but i want dictionary inside list. > @Jon - Yes i want single item dict's > @Robert - i use python 2.4 . > > Thanks > Lee. i got it solved , items = [] for brain in brains: dict = {'itemnos': 'item_0' + brain + 's'} items.append(dict) print(items) thanks all. Lee. From python at rcn.com Fri Nov 6 12:21:55 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 Nov 2009 09:21:55 -0800 (PST) Subject: is None or == None ? References: Message-ID: <0bd9e58f-12dd-4ead-9401-1a38b0aa4bea@y32g2000prd.googlegroups.com> On Nov 6, 5:20?am, mk wrote: > Some claim that one should test for None using: > > if x is None: > > ..but the standard equality which is theoretically safer works as well: > > if x == None: > > So, which one is recommended? In the standard library, we use "x is None". The official recommendation in PEP 8 reads: ''' Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Also, beware of writing "if x" when you really mean "if x is not None" -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context! ''' Raymond From hniksic at xemacs.org Fri Nov 6 12:22:40 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 06 Nov 2009 18:22:40 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <87r5sbh8kf.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > But wow. That's pretty hare-brained: dynamic allocation for every > stored value outside the cache range, needless extra indirection for > every operation. > > Even Microsoft COM managed to get this right. > > On the positive side, except that it would probably break every C > module (I don't know), in consultant speak that's definitely a > potential for improvement. :-p Tagged integers have been tried, shown not really worth it, and ultimately rejected by the BDFL: http://mail.python.org/pipermail/python-dev/2004-July/thread.html#46139 From alfps at start.no Fri Nov 6 12:28:08 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 18:28:08 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Rami Chowdhury: > On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach > wrote: > >> But wow. That's pretty hare-brained: dynamic allocation for every >> stored value outside the cache range, needless extra indirection for >> every operation. >> > > Perhaps I'm not understanding this thread at all but how is dynamic > allocation hare-brained, and what's the 'needless extra indirection'? Dynamic allocation isn't hare-brained, but doing it for every stored integer value outside a very small range is, because dynamic allocation is (relatively speaking, in the context of integer operations) very costly even with a (relatively speaking, in the context of general dynamic allocation) very efficient small-objects allocator - here talking order(s) of magnitude. A typical scheme for representing dynamically typed objects goes like, in C++, enum TypeId { int_type_id, dyn_object_type_id }; struct Object { int type_id; union { void* p; int i; // Perhaps other special cased type's values in this union. }; }; This would then be the memory layout of what's regarded as a variable at the script language level. Then getting the integer value reduces to int intValueOf( Object const& o ) { if( o.type_id != int_type_id ) { throw TypeError(); } return o.i; } If on the other hand int (and perhaps floating point type, whatever) isn't special-cased, then it goes like int intValueOf( Object const& o ) { if( o.type_id != int_type_id ) { throw TypeError(); } return static_cast( o.p )->value; // Extra indirection } and depending on where the basic type id is stored it may be more extra indirection, and worse, creating that value then involves a dynamic allocation. Cheers & hth. - Alf From patrol at invisibleroads.com Fri Nov 6 12:33:16 2009 From: patrol at invisibleroads.com (Roy Hyunjin Han) Date: Fri, 06 Nov 2009 12:33:16 -0500 Subject: Cpython optimization In-Reply-To: References: Message-ID: <4AF45DDC.4080408@invisibleroads.com> On 10/21/2009 01:28 PM, Qrees wrote: > As my Master's dissertation I chose Cpython optimization. That's why > i'd like to ask what are your suggestions what can be optimized. Well, > I know that quite a lot. I've downloaded the source code (I plan to > work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at > the code I've found comment's like "this can be optimized by..." etc. > but maybe you guide me what should I concentrate on in my work? > > I've 6-7 month for this and If I create something decent I can > publish it. > Hi Qrees, Have you heard of the Unladen Swallow project? It is an optimization branch of CPython. Perhaps you can talk to some of the people working on the project. http://code.google.com/p/unladen-swallow/ RHH -- Get customized Python tutorials and live instruction for your business, research or programming problem Tuesday November 17 2009 6:30pm ? 10pm NYC Seminar and Conference Center (71 W 23rd St @ 6th Ave, New York, NY) 11/12 slots available for $30 each http://invisibleroads.com From python at mrabarnett.plus.com Fri Nov 6 12:33:54 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Nov 2009 17:33:54 +0000 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> Message-ID: <4AF45E02.50304@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: >> On Fri, 6 Nov 2009, Peng Yu wrote: >> >>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >>>> Peng Yu schrieb: >>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>> could use a for loop to do so. In a functional language, there is way >>>>> to do so without using the for loop. >>>> Nonsense. For processing over each element, you have to loop over them, >>>> either with or without growing a call-stack at the same time. >>>> >>>> FP languages can optimize away the stack-frame-growth (tail recursion) - but >>>> this isn't reducing complexity in any way. >>>> >>>> So use a loop, either directly, or using a list-comprehension. >>> What is a list-comprehension? >>> >>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>> the iterator, right? I am wondering how to make the code correct. >>> >>> l = ['a', 'a', 'b', 'c'] >>> for x in l: >>> if x == 'a': >>> l.remove(x) >>> >>> print l >> list comprehension seems to be what you want: >> >> l = [i for i in l if i != 'a'] > > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs = [i for i in l if dirs != > 'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. > [snip] You can replace the contents of a list like this: l[:] = [i for i in l if i != 'a'] From python at rcn.com Fri Nov 6 12:39:09 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 6 Nov 2009 09:39:09 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: [kj] > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? Yes. Raymond From damienlmoore at gmail.com Fri Nov 6 12:44:49 2009 From: damienlmoore at gmail.com (dmoore) Date: Fri, 6 Nov 2009 09:44:49 -0800 (PST) Subject: Need help dumping exif data in canon raw files References: <4c544eb4-0f90-4959-9798-c0163a24907e@x25g2000prf.googlegroups.com> <7xd43w1rjt.fsf@ruckus.brouhaha.com> Message-ID: <5fc08548-b164-4f63-9f01-10936e01d322@37g2000yqm.googlegroups.com> On Nov 5, 6:27?pm, Paul Rubin wrote: > Nuff Nuff writes: > > I just need to be able to extract the exif info from a canon CR2 > > file. ?The info from canon suggest that it's just the same as a tiff, > > but anytime I try to get PIL to open one, ?it says that it tastes > > bad. ?And canon don't seem to be all that forthcoming on the details. > >CR2 is a hardware-specific raw format and PIL should not be expected >to understand it. Try a websearch for dcraw.c to find a decoder for it. also check out pyexiv2 (a python binding of exiv2), available in many linux distros: http://tilloy.net/dev/pyexiv2/index.htm the current version of pyexiv2 doesn't yet support XMP metadata (the underlying exiv2 lib does) but should be able to read Exif and IPTC data ok. Looking at http://dev.exiv2.org/wiki/exiv2/Supported_image_formats you may be SOL for writing to CR2. You can also try calling exiftool from your python script: http://www.sno.phy.queensu.ca/~phil/exiftool/ From rami.chowdhury at gmail.com Fri Nov 6 12:47:37 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 09:47:37 -0800 Subject: newbie question - python lists In-Reply-To: <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 09:19:00 -0800, lee wrote: > On Nov 6, 9:47?pm, lee wrote: >> On Nov 6, 7:48?pm, Jim wrote: >> >> > On Nov 6, 9:15 am, lee wrote: >> >> > > can anyone point wer am erroring. >> >> > I'm not sure what you are trying to do, but it is odd, isn't it, that >> > you never refer to brain in the "for brain in brains:" loop? ?I think >> > you are mixing i and brain somehow. >> >> > Jim >> >> ok let me make it clear, >> >> brains = ['1','2'] >> for brain in brains: >> ? ? row['item'] = brain >> ? ? items.append(row) >> ? ? print items >> >> This produces >> [{'item': '1'}] >> [{'item': '2'}, {'item': '2'}] >> but i want >> [{'item': '1'}] >> [{'item': '1'}, {'item': '2'}] >> >> if i do items.append(brain), it gives, >> ['1', '2'] >> but i want dictionary inside list. >> @Jon - Yes i want single item dict's >> @Robert - i use python 2.4 . >> >> Thanks >> Lee. > > i got it solved , > > items = [] > for brain in brains: > dict = {'itemnos': 'item_0' + brain + 's'} > items.append(dict) > print(items) > Glad to see you solved it! A couple of minor considerations: - I would suggest you use a variable name other than 'dict', as that shadows the built-in 'dict' type - I would suggest using the idiom 'item_0%ss' % brain rather than 'item_0' + brain + 's', in case at some point you want to change the type of 'brain' -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From san82moon at gmail.com Fri Nov 6 13:01:52 2009 From: san82moon at gmail.com (lee) Date: Fri, 6 Nov 2009 10:01:52 -0800 (PST) Subject: newbie question - python lists References: <8d1009a4-54c8-4bb3-9862-8b22e6b42a3b@y10g2000prg.googlegroups.com> <394a516a-4bc3-444a-b21c-457d4b7fe811@h40g2000prf.googlegroups.com> Message-ID: <5b6ff9ff-ba71-47ed-88e3-bba13361582b@x25g2000prf.googlegroups.com> On Nov 6, 10:47?pm, "Rami Chowdhury" wrote: > On Fri, 06 Nov 2009 09:19:00 -0800, lee wrote: > > On Nov 6, 9:47?pm, lee wrote: > >> On Nov 6, 7:48?pm, Jim wrote: > > >> > On Nov 6, 9:15 am, lee wrote: > > >> > > can anyone point wer am erroring. > > >> > I'm not sure what you are trying to do, but it is odd, isn't it, that > >> > you never refer to brain in the "for brain in brains:" loop? ?I think > >> > you are mixing i and brain somehow. > > >> > Jim > > >> ok let me make it clear, > > >> brains = ['1','2'] > >> for brain in brains: > >> ? ? row['item'] = brain > >> ? ? items.append(row) > >> ? ? print items > > >> This produces > >> [{'item': '1'}] > >> [{'item': '2'}, {'item': '2'}] > >> but i want > >> [{'item': '1'}] > >> [{'item': '1'}, {'item': '2'}] > > >> if i do items.append(brain), it gives, > >> ['1', '2'] > >> but i want dictionary inside list. > >> @Jon - Yes i want single item dict's > >> @Robert - i use python 2.4 . > > >> Thanks > >> Lee. > > > i got it solved , > > > items = [] > > for brain in brains: > > ? ? ? ?dict = {'itemnos': 'item_0' + brain + 's'} > > ? ? ? ?items.append(dict) > > print(items) > > Glad to see you solved it! A couple of minor considerations: > ? ? ? ? - I would suggest you use a variable name other than 'dict', as that ? > shadows the built-in 'dict' type > ? ? ? ? - I would suggest using the idiom 'item_0%ss' % brain rather than ? > 'item_0' + brain + 's', in case at some point you want to change the type ? > of 'brain' > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- ? > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) i greatly value your suggestion. i have made changes as indicted by you. The code looks more clean now. Thank you, Lee. From clp2 at rebertia.com Fri Nov 6 13:04:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 10:04:21 -0800 Subject: why does "help(import)" not work? In-Reply-To: <4af43d73$0$11898$426a74cc@news.free.fr> References: <50697b2c0911060212h7f719815icc5f4a6e81850efc@mail.gmail.com> <4af43d73$0$11898$426a74cc@news.free.fr> Message-ID: <50697b2c0911061004l5b8cf6fdoa5c2a373535949b7@mail.gmail.com> On Fri, Nov 6, 2009 at 7:15 AM, Bruno Desthuilliers wrote: > Chris Rebert a ?crit : >> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day >> wrote: >>> ?um ... ok, i'll take your word for it, but is there at least a >>> generalizable pattern for what is directly help()able and what isn't? >> >> Language keywords aren't help()-able: >> http://docs.python.org/reference/lexical_analysis.html#keywords >> Neither are punctuation/operators (see other sections on same webpage). > > Ever tried help("import") or help("if") or help("+") ? help()-able in this context meaning you can drop the quotes and not get a syntax error. Cheers, Chris -- http://blog.rebertia.com From emily at nospam.com Fri Nov 6 13:11:47 2009 From: emily at nospam.com (Emily Rodgers) Date: Fri, 6 Nov 2009 18:11:47 -0000 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: "Andre Engels" wrote in message news:mailman.2696.1257520404.2807.python-list at python.org... >On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: [snip] >> arr = [None] * 1000000 >> >> Is this the most efficient way to achieve this result? > > It depends - what do you want to do with it? My first hunch would be > to use a dictionary instead of a list, then the whole problem > disappears. If there is a reason you don't want to do that, what is > it? > > -- > Andr? Engels, andreengels at gmail.com I second this. It might seem a sensible thing to do in perl, but I can't imagine what you would actually want to do it for! Seems like an odd thing to want to do! From VerweijA at tass-safe.com Fri Nov 6 13:15:41 2009 From: VerweijA at tass-safe.com (Verweij, Arjen) Date: Fri, 6 Nov 2009 19:15:41 +0100 Subject: safely returning objects from a Process to the parent through a Queue() Message-ID: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> Hi, I'm trying to parallelize a loop using Process and Queue. My code looks similar to the example in http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.managers It looks like this: def pp(q, t, s, a, h, p): doStuff() c.generate() q.put(c, True) #stuff a in a queue main: for a in aa: processes = [] q = Queue() for b in bb: try: if bla > 24: print "too old" continue except: print "etc" + t #file not found pass try: p = Process(target=pp, args=(q, t, s, a, h, p,)) #trailing comma, do not touch m'kay p.start() processes.append(p) #end for b in bb for p in processes: # p.join() # this deadlocks in combination with the Queue() at some point ss = q.get() bigcontainer.add(ss) bigcontainer.generate() world.add(bigcontainer) #end for a in aa world.generate() So I have some XML, that requires translation into HTML. I take a sublist, traverse it, spawn a process for every XML file in that list and generate HTML inside that process. Then I would very much like to have the results back in the original main() so it can be used. Is there a way to guarantee that the a in aa loop will not start the next loop? In other words, I'm worried that q will be depleted due to some unknown factor while a subprocess from b in bb still has to write to the Queue() and it will continue somehow leaking/destroying data. Before I found the example in the webpage that pointed out the deadlock I couldn't get the program to finish, but finishing without all the data would be equally bad. Thanks, Arjen Arjen Verweij QA/Test Engineer Schoemakerstraat 97 2628 VK? Delft The Netherlands Phone:??+31?88?827 7086 Fax:???????+31?88 827? 7003 Email:??arjen.verweij at tass-safe.com www.tass-safe.com This e-mail and its contents are subject to a DISCLAIMER with important RESERVATIONS. From clp2 at rebertia.com Fri Nov 6 13:16:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 10:16:31 -0800 Subject: Defining re pattern for matching list of numbers In-Reply-To: References: Message-ID: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> On Fri, Nov 6, 2009 at 8:04 AM, jorma kala wrote: > Hi, > I'm trying to write a re pattern to match a list of one or more numbers, > each number is in the range of 1-15 value and the numbers are separated by > spaces (but?there are no?spaces at the beginning and end of the string). For > instance: > > "3" > "1 14 8" > > but not: > > "22" > " 5 11" > > I've come up with something like this > > re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") > > but I can't believe this has to be so complicated. Your format seems so simple I have to ask why you're using regexes in the first place. try: nums = [int(num) for num in line.split(" ")] except ValueError: print "Invalid input" for num in nums: if num < 1 or num > 15: raise ValueError, "Number present which is outside of valid range" Cheers, Chris -- http://blog.rebertia.com From tartley at tartley.com Fri Nov 6 13:30:12 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:30:12 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <54b5ecab-bd7b-4106-9401-785e9813823d@c3g2000yqd.googlegroups.com> Message-ID: <8176e961-7e5b-4f5a-9fd1-53093160a07a@l2g2000yqd.googlegroups.com> On Nov 5, 2:26?pm, Paul Boddie wrote: > On 3 Nov, 16:58, Jonathan Hartley wrote: > > > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > Nice comparison! Perhaps this could join the material on the Wiki > eventually: > > http://wiki.python.org/moin/DistributionUtilities > > If you don't want to spend time marking the table up, I'm sure I could > help you out. > > Paul Nice idea Paul, and thanks for the offer. I'll ping you for guidance at least, as and when I reckon I've got the table into half decent shape. I notice the wiki page you linked to contains a bunch of options and information I wasn't even aware of, so I've probably got some work to do before that happens. Best, Jonathan From tartley at tartley.com Fri Nov 6 13:33:07 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:33:07 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <8bbdf9ae-bd36-4530-bde5-2f15a84561a5@g23g2000yqh.googlegroups.com> On Nov 6, 2:52?pm, "Marco Bazzani" wrote: > On Tue, 03 Nov 2009 16:58:16 +0100, Jonathan Hartley ? > wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > blank page ? > > -- > reply at: > echo "nntp at marcobazzani dot name" |sed s/\ at\ /@/ |sed s/\ dot\ /./ Hey Marco. Thanks for the heads-up. It's suppose to be a link to a shared google docs spreadsheet. At least some other people are able to see it without problems. If you're keen to see it, and it remains non- functional for you, and you're willing to help me try and debug this, then email me off list and maybe we could try some alternative ways of publishing it. Do you happen to know if other google docs spreadsheets work for you? Best, Jonathan From tartley at tartley.com Fri Nov 6 13:33:52 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:33:52 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <4AF43BAB.5000201@codebykevin.com> Message-ID: <899f4709-250c-4623-81ad-84af21008bce@n35g2000yqm.googlegroups.com> On Nov 6, 3:07?pm, Kevin Walzer wrote: > On 11/3/09 10:58 AM, Jonathan Hartley wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > I noticed information on py2app was mostly missing from your chart. > > --single exe file: yes, with qualification. On the Mac, standalone > applications are actually directories called "application bundles" > designed to look like a single file that can be double-clicked on. So, a > lot of stuff--the Python libraries, icons, other resource files--are > hidden inside the app bundle. > > --without unzipping at runtime--Yes. > --control over output directory structure--no. > > --creates installer too: yes, with qualification. If you're building an > app, you don't use an installer--the standard Mac method is > drag-and-drop installation. You can also use py2app to package up Python > libraries, and for these, it can create a standard Mac pkg installer. > > --Python 3--not yet, as far as I know. > --can run as -O--not sure. > --control over process/ouput--not sure what this means. > --distribution size--Varies widely. A big Python application with lots > of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with > no other extensions would weigh in at about 20 megabytes--that's the > smallest. > --active development--some, but only in svn. Last stable release was a > few years ago. > --active mailing list--no standalone mailing list, but the PythonMac-sig > mailing list has lots of discussion and bug reporting on py2app. > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Thanks heaps Kevin - I don't have a Mac, so I was just inferring information about py2app. Although my app does run on Macs and one of my Mac-loving friends has kindly agreed to help me produce Mac binaries, so this information is brilliant to know. Many thanks! Jonathan From tartley at tartley.com Fri Nov 6 13:41:51 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 6 Nov 2009 10:41:51 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <4AF43BAB.5000201@codebykevin.com> Message-ID: On Nov 6, 3:07?pm, Kevin Walzer wrote: > On 11/3/09 10:58 AM, Jonathan Hartley wrote: > > > Hi, > > > Recently I put together this incomplete comparison chart in an attempt > > to choose between the different alternatives to py2exe: > > >http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > I noticed information on py2app was mostly missing from your chart. > > --single exe file: yes, with qualification. On the Mac, standalone > applications are actually directories called "application bundles" > designed to look like a single file that can be double-clicked on. So, a > lot of stuff--the Python libraries, icons, other resource files--are > hidden inside the app bundle. > > --without unzipping at runtime--Yes. > --control over output directory structure--no. > > --creates installer too: yes, with qualification. If you're building an > app, you don't use an installer--the standard Mac method is > drag-and-drop installation. You can also use py2app to package up Python > libraries, and for these, it can create a standard Mac pkg installer. > > --Python 3--not yet, as far as I know. > --can run as -O--not sure. > --control over process/ouput--not sure what this means. > --distribution size--Varies widely. A big Python application with lots > of libraries can exceed 100 megabytes, easily. A Python/Tkinter app with > no other extensions would weigh in at about 20 megabytes--that's the > smallest. > --active development--some, but only in svn. Last stable release was a > few years ago. > --active mailing list--no standalone mailing list, but the PythonMac-sig > mailing list has lots of discussion and bug reporting on py2app. > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Kevin, Also: You are right that my 'control over process/output' is not at all clear. I shall think about what actual goal I'm trying to achieve with this, and re-describe it in those terms. Plus, as others have suggested, my guesstimate of 'distribution size' would probably be more usefully described as 'size overhead', ie. how big would the distribution be for a one-line python console 'hello world' script. I hope to try it out and see. Best regards, Jonathan From alfps at start.no Fri Nov 6 13:45:02 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 19:45:02 +0100 Subject: is None or == None ? In-Reply-To: <87r5sbh8kf.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> But wow. That's pretty hare-brained: dynamic allocation for every >> stored value outside the cache range, needless extra indirection for >> every operation. >> >> Even Microsoft COM managed to get this right. >> >> On the positive side, except that it would probably break every C >> module (I don't know), in consultant speak that's definitely a >> potential for improvement. :-p > > Tagged integers have been tried, shown not really worth it, and > ultimately rejected by the BDFL: > > http://mail.python.org/pipermail/python-dev/2004-July/thread.html#46139 Yah, as I suspected. I looked at the first few postings in that thread and it seems an inefficient baroque implementation was created and tested, not realizing more than 50% speedup in a test not particularly much exercising its savings, and against that counts as mentioned in the thread and as I mentioned in quoted material above, breaking lots of existing C code. Speedup would likely be more realistic with normal implementation (not fiddling with bit-fields and stuff) not to mention when removing other inefficiencies that likely dwarf and hide the low-level performance increase, but still I agree wholeheartedly with those who argue compatibility, not breaking code. As long as it Works, don't fix it... ;-) Cheers, (still amazed, though) - Alf From jjkk73 at gmail.com Fri Nov 6 14:12:11 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 6 Nov 2009 20:12:11 +0100 Subject: Defining re pattern for matching list of numbers In-Reply-To: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> References: <50697b2c0911061016l18e7f49fq9dfa1f2f84a5af95@mail.gmail.com> Message-ID: Thanks for your reply. But I need to use a regex; my program deals with a large number of patterns, and I want to treat them in a uniform way (through regex). On 11/6/09, Chris Rebert wrote: > > On Fri, Nov 6, 2009 at 8:04 AM, jorma kala wrote: > > Hi, > > I'm trying to write a re pattern to match a list of one or more numbers, > > each number is in the range of 1-15 value and the numbers are separated > by > > spaces (but there are no spaces at the beginning and end of the string). > For > > instance: > > > > "3" > > "1 14 8" > > > > but not: > > > > "22" > > " 5 11" > > > > I've come up with something like this > > > > re.compile("^((([1-9])|(1[0-8]))( +(?=[1-9]))*)+$") > > > > but I can't believe this has to be so complicated. > > > Your format seems so simple I have to ask why you're using regexes in > the first place. > > try: > nums = [int(num) for num in line.split(" ")] > except ValueError: > print "Invalid input" > > for num in nums: > if num < 1 or num > 15: > raise ValueError, "Number present which is outside of valid range" > > Cheers, > Chris > > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Nov 6 14:20:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 6 Nov 2009 11:20:40 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Nov 6, 9:28?am, "Alf P. Steinbach" wrote: > * Rami Chowdhury: > > > On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach > > wrote: > > >> But wow. That's pretty hare-brained: dynamic allocation for every > >> stored value outside the cache range, needless extra indirection for > >> every operation. > > > Perhaps I'm not understanding this thread at all but how is dynamic > > allocation hare-brained, and what's the 'needless extra indirection'? > > Dynamic allocation isn't hare-brained, but doing it for every stored integer > value outside a very small range is, because dynamic allocation is (relatively > speaking, in the context of integer operations) very costly even with a > (relatively speaking, in the context of general dynamic allocation) very > efficient small-objects allocator - here talking order(s) of magnitude. Python made a design trade-off, it chose a simpler implementation and uniform object semantic behavior, at a cost of speed. C# made a different trade-off, choosing a more complex implementation, a language with two starkly different object semantic behaviors, so as to allow better performance. You don't have to like the decision Python made, but I don't think it's fair to call a deliberate design trade-off hare-brained. Carl Banks From rami.chowdhury at gmail.com Fri Nov 6 14:28:15 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 11:28:15 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >> wrote: >> >>> But wow. That's pretty hare-brained: dynamic allocation for every >>> stored value outside the cache range, needless extra indirection for >>> every operation. >>> >> Perhaps I'm not understanding this thread at all but how is dynamic >> allocation hare-brained, and what's the 'needless extra indirection'? > > Dynamic allocation isn't hare-brained, but doing it for every stored > integer value outside a very small range is, because dynamic allocation > is (relatively speaking, in the context of integer operations) very > costly even with a (relatively speaking, in the context of general > dynamic allocation) very efficient small-objects allocator - here > talking order(s) of magnitude. Well, sure, it may seem that way. But how large a cache would you want to preallocate? I can't see the average Python program needing to use the integers from -10000 to 10000, for instance. In my (admittedly limited) experience Python programs typically deal with rather more complex objects than plain integers. > int intValueOf( Object const& o ) > { > if( o.type_id != int_type_id ) { throw TypeError(); } > return static_cast( o.p )->value; // Extra > indirection > } If a large cache were created and maintained, would it not be equally indirect to check for the presence of a value in the cache, and return that value if it's present? > creating that value then involves a dynamic allocation. Creating which value, sorry -- the type object? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From alfps at start.no Fri Nov 6 14:41:41 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 20:41:41 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Carl Banks: > On Nov 6, 9:28 am, "Alf P. Steinbach" wrote: >> * Rami Chowdhury: >> >>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>> wrote: >>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>> stored value outside the cache range, needless extra indirection for >>>> every operation. >>> Perhaps I'm not understanding this thread at all but how is dynamic >>> allocation hare-brained, and what's the 'needless extra indirection'? >> Dynamic allocation isn't hare-brained, but doing it for every stored integer >> value outside a very small range is, because dynamic allocation is (relatively >> speaking, in the context of integer operations) very costly even with a >> (relatively speaking, in the context of general dynamic allocation) very >> efficient small-objects allocator - here talking order(s) of magnitude. > > > Python made a design trade-off, it chose a simpler implementation Note that the object implementation's complexity doesn't have to affect to any other code since it's trivial to provide abstract accessors (even macros), i.e., this isn't part of a trade-off except if the original developer(s) had limited resources -- and if so then it wasn't a trade-off at the language design level but a trade-off of getting things done then and there. > and uniform object semantic behavior, Also note that the script language level semantics of objects is /unaffected/ by the implementation, except for speed, i.e., this isn't part of a trade-off either. ;-) > at a cost of speed. In summary, the trade-off, if any, couldn't as I see it be what you describe, but there could have been a different kind of getting-it-done trade-off. It is usually better with Something Usable than waiting forever (or too long) for the Perfect... ;-) Or, it could be that things just evolved, constrained by frozen earlier decisions. That's the main reason for the many quirks in C++. Not unlikely that it's also that way for Python. > C# made a > different trade-off, choosing a more complex implementation, a > language with two starkly different object semantic behaviors, so as > to allow better performance. Don't know about the implementation of C#, but whatever it is, if it's bad in some respect then that has nothing to do with Python. > You don't have to like the decision Python made, but I don't think > it's fair to call a deliberate design trade-off hare-brained. OK. :-) Cheers, - Alf From dan.winsor at gmail.com Fri Nov 6 14:41:47 2009 From: dan.winsor at gmail.com (Dan Winsor) Date: Fri, 6 Nov 2009 11:41:47 -0800 (PST) Subject: username/password dialog prompt Message-ID: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> Hi, To preface, I'm a bit of a python novice, but I have been poking around for the solution for a bit and have found actually too many leads which has wedged me. I'm looking to impliment a dialog, preferably using Tkinter, that will prompt for a username and password. I'd like to have the password field blanked (via show="*"), and have the dialog return both fields to the command line script that I'm launching it from. Can someone recommend a good example or tutorial to work from? Thanks very much in advance. -- Dan Winsor Soy un poco loco en el coco. From alfps at start.no Fri Nov 6 14:50:33 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 20:50:33 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Rami Chowdhury: > On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach > wrote: > >> * Rami Chowdhury: >>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>> wrote: >>> >>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>> stored value outside the cache range, needless extra indirection for >>>> every operation. >>>> >>> Perhaps I'm not understanding this thread at all but how is dynamic >>> allocation hare-brained, and what's the 'needless extra indirection'? >> >> Dynamic allocation isn't hare-brained, but doing it for every stored >> integer value outside a very small range is, because dynamic >> allocation is (relatively speaking, in the context of integer >> operations) very costly even with a (relatively speaking, in the >> context of general dynamic allocation) very efficient small-objects >> allocator - here talking order(s) of magnitude. > > Well, sure, it may seem that way. But how large a cache would you want > to preallocate? I can't see the average Python program needing to use > the integers from -10000 to 10000, for instance. In my (admittedly > limited) experience Python programs typically deal with rather more > complex objects than plain integers. Uhm, you've misunderstood or failed to understand something basic, but what? The CPython implementation uses a cache to alleviate problems with performance. A tagged scheme (the usual elsewhere, e.g. Windows' Variant) doesn't need any cache and can't benefit from such a cache, since then an integer's value is directly available in any variable that logically holds an int. In short, a cache for integer values is maningless for the tagged scheme. >> int intValueOf( Object const& o ) >> { >> if( o.type_id != int_type_id ) { throw TypeError(); } >> return static_cast( o.p )->value; // Extra >> indirection >> } > > If a large cache were created and maintained, would it not be equally > indirect to check for the presence of a value in the cache, and return > that value if it's present? Again, that's meaningless. See above. >> creating that value then involves a dynamic allocation. > > Creating which value, sorry -- the type object? Well it's an out-of-context quote, but t'was about creating the value object that a variable contains a pointer to with the current CPython implementation. I'm sure that more information about tagged variant schemes are available on the net. E.g. Wikipedia. Cheers & hth., - Alf From python at mrabarnett.plus.com Fri Nov 6 14:53:59 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Nov 2009 19:53:59 +0000 Subject: safely returning objects from a Process to the parent through a Queue() In-Reply-To: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> References: <6C436D7E5F26C6489A08D826FBE3FCA49E8BB8FB37@SW003.wdm.local> Message-ID: <4AF47ED7.3090807@mrabarnett.plus.com> Verweij, Arjen wrote: > Hi, > > I'm trying to parallelize a loop using Process and Queue. My code looks similar to the example in http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.managers > > It looks like this: > > def pp(q, t, s, a, h, p): > doStuff() > c.generate() > q.put(c, True) #stuff a in a queue > > main: > > for a in aa: > processes = [] > q = Queue() > for b in bb: > try: > if bla > 24: > print "too old" > continue > except: > print "etc" + t #file not found > pass > try: > p = Process(target=pp, args=(q, t, s, a, h, p,)) #trailing comma, do not touch m'kay > p.start() > processes.append(p) > #end for b in bb > for p in processes: > # p.join() # this deadlocks in combination with the Queue() at some point > ss = q.get() > bigcontainer.add(ss) > bigcontainer.generate() > world.add(bigcontainer) > #end for a in aa > world.generate() > > So I have some XML, that requires translation into HTML. I take a sublist, traverse it, spawn a process for every XML file in that list and generate HTML inside that process. Then I would very much like to have the results back in the original main() so it can be used. Is there a way to guarantee that the a in aa loop will not start the next loop? In other words, I'm worried that q will be depleted due to some unknown factor while a subprocess from b in bb still has to write to the Queue() and it will continue somehow leaking/destroying data. > > Before I found the example in the webpage that pointed out the deadlock I couldn't get the program to finish, but finishing without all the data would be equally bad. > Here the answer I gave to an earlier question about multiprocessing: """It think it's down to the difference between multithreading and multiprocessing. When multithreading, the threads share the same address space, so items can be passed between the threads directly. However, when multiprocessing, the processes don't share the same address space, so items need to be passed from process to process via a pipe. Unfortunately, the pipe has a limited capacity, so if a process doesn't read from one end then the pipe will eventually fill up and the sender will block. Also, a process won't terminate until it has finished writing to the pipe, and it can't be joined until it has terminated. You can therefore get into a deadlock where: * Process A won't read from the queue until it has joined process B. * The join won't succeed until process B has terminated. * Process B won't terminate until it has finished writing to the queue. * Process B can't finish writing to the queue because it's full. * The queue is full because process A isn't reading from it. """ I suggest you get all the results from the queue and then join all the processes: for p in processes: ss = q.get() bigcontainer.add(ss) for p in processes: p.join() From philip at semanchuk.com Fri Nov 6 15:00:17 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 6 Nov 2009 15:00:17 -0500 Subject: comparing alternatives to py2exe In-Reply-To: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> Message-ID: <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Hi Jonathan, I'm asking similar questions for the app suite that we're developing on my current project, so I thank you for doing my work for me. ;) I was interested in py2exe because we'd like to provide a one download, one click install experience for our Windows users. I think a lot of people are interested in py2exe for the same reason. Well, one thing that I came across in my travels was the fact that distutils can create MSIs. Like py2exe, MSIs provide a one download, one click install experience under Windows and therefore might be a replacement for py2exe. For me, the following command was sufficient to create an msi, although it only worked under Windows (not under Linux or OS X): python setup.py bdist_msi The resulting MSI worked just fine in my extensive testing (read: I tried it on one machine). It seems, then, that creating an MSI is even within the reach of someone like me who spends very little time in Windows-land, so it might be worth a column on your chart alongside rpm/deb. Thanks again for your work Philip From mwilson at the-wire.com Fri Nov 6 15:12:43 2009 From: mwilson at the-wire.com (Mel) Date: Fri, 06 Nov 2009 15:12:43 -0500 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > Note that the object implementation's complexity doesn't have to affect to > any other code since it's trivial to provide abstract accessors (even > macros), i.e., this isn't part of a trade-off except if the original > developer(s) had limited > resources -- and if so then it wasn't a trade-off at the language design > level but a trade-off of getting things done then and there. But remember what got us in here: your belief (which followed from your assumptions) that computing `is` required testing the object types. You might optimize out the "extra indirection" to get an object's value, but you'd need the "extra indirection" anyway to find out what type it was before you could use it. Mel. From rami.chowdhury at gmail.com Fri Nov 6 15:19:14 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 12:19:14 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On Fri, 06 Nov 2009 11:50:33 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach >> wrote: >> >>> * Rami Chowdhury: >>>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach >>>> wrote: >>>> >>>>> But wow. That's pretty hare-brained: dynamic allocation for every >>>>> stored value outside the cache range, needless extra indirection for >>>>> every operation. >>>>> >>>> Perhaps I'm not understanding this thread at all but how is dynamic >>>> allocation hare-brained, and what's the 'needless extra indirection'? >>> >>> Dynamic allocation isn't hare-brained, but doing it for every stored >>> integer value outside a very small range is, because dynamic >>> allocation is (relatively speaking, in the context of integer >>> operations) very costly even with a (relatively speaking, in the >>> context of general dynamic allocation) very efficient small-objects >>> allocator - here talking order(s) of magnitude. >> Well, sure, it may seem that way. But how large a cache would you want >> to preallocate? I can't see the average Python program needing to use >> the integers from -10000 to 10000, for instance. In my (admittedly >> limited) experience Python programs typically deal with rather more >> complex objects than plain integers. > > Uhm, you've misunderstood or failed to understand something basic, but > what? Oh, I see, you were referring to a tagging scheme as an alternative. Sorry for the misunderstanding. > > Well it's an out-of-context quote, but t'was about creating the value > object that a variable contains a pointer to with the current CPython > implementation. > Again, perhaps I'm just misunderstanding what you're saying, but as I understand it, in CPython if you're looking for the value of a PyIntObject, that's stored right there in the structure, so no value object needs to be created... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From alfps at start.no Fri Nov 6 15:49:41 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 06 Nov 2009 21:49:41 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: * Mel: > Alf P. Steinbach wrote: >> Note that the object implementation's complexity doesn't have to affect to >> any other code since it's trivial to provide abstract accessors (even >> macros), i.e., this isn't part of a trade-off except if the original >> developer(s) had limited >> resources -- and if so then it wasn't a trade-off at the language design >> level but a trade-off of getting things done then and there. > > But remember what got us in here: your belief (which followed from your > assumptions) that computing `is` required testing the object types. Yes, I couldn't believe what I've now been hearing. Uh, reading. :-) > You > might optimize out the "extra indirection" to get an object's value, but > you'd need the "extra indirection" anyway to find out what type it was > before you could use it. No, that type checking is limited (it just checks whether the type is special cased), doesn't involve indirection, and is there anyway except for 'is'. It can be moved around but it's there, or something more costly is there. 'is' is about the only operation you /can/ do without checking the type, but I don't see the point in optimizing 'is' at cost of all other operations on basic types. Cheers & hth., - Alf From pavlovevidence at gmail.com Fri Nov 6 15:53:10 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 6 Nov 2009 12:53:10 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <3f169204-50e5-483d-bcf6-0fe2c874614e@k19g2000yqc.googlegroups.com> On Nov 6, 11:41?am, "Alf P. Steinbach" wrote: > Note that the object implementation's complexity doesn't have to affect to any > other code since it's trivial to provide abstract accessors (even macros), i.e., > this isn't part of a trade-off except if the original developer(s) had limited > resources ?-- ?and if so then it wasn't a trade-off at the language design level > but a trade-off of getting things done then and there. I totally disagree with this; it would be like squaring the implementation complexity. It is far from "trivial" as you claim. Even if it were just a matter of accessor macros (and it isn't) they don't write themselves, especially when you focused on speed, so that's a non-trivial complexity increase already. But you besides writing code you now have reading code (which is now cluttered with all kinds of ugly accessor macros, as if the Python API wasn't ugly enough), debugging code, maintaining code, understanding semantics and nuances, handling all the extra corner cases. To say it's trivial is absurd. > > ?C# made a > > different trade-off, choosing a more complex implementation, a > > language with two starkly different object semantic behaviors, so as > > to allow better performance. > > Don't know about the implementation of C#, but whatever it is, if it's bad in > some respect then that has nothing to do with Python. C# is a prototypical example of a language that does what you were suggesting (also it draws upon frameworks like COM, which you mentioned) so it is a basis of comparison of the benefits versus drawbacks of the two approaches. Carl Banks From no.email at please.post Fri Nov 6 16:03:31 2009 From: no.email at please.post (kj) Date: Fri, 6 Nov 2009 21:03:31 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: In "Emily Rodgers" writes: >"Andre Engels" wrote in message >news:mailman.2696.1257520404.2807.python-list at python.org... >>On Fri, Nov 6, 2009 at 1:12 PM, kj wrote: >[snip] >>> arr = [None] * 1000000 >>> >>> Is this the most efficient way to achieve this result? >> >> It depends - what do you want to do with it? My first hunch would be >> to use a dictionary instead of a list, then the whole problem >> disappears. If there is a reason you don't want to do that, what is >> it? >I second this. It might seem a sensible thing to do in perl, but I can't >imagine what you would actually want to do it for! Seems like an odd thing >to want to do! As I said, this is considered an optimization, at least in Perl, because it lets the interpreter allocate all the required memory in one fell swoop, instead of having to reallocate it repeatedly as the array grows. (Of course, like with all optimizations, whether it's worth the bother is another question.) Another situation where one may want to do this is if one needs to initialize a non-sparse array in a non-sequential order, e.g. if that's the way the data is initially received by the code. Of course, there are many ways to skin such a cat; pre-allocating the space and using direct list indexing is just one of them. I happen to think it is a particularly straighforward one, but I realize that others (you, Andre, etc.) may not agree. kynn From davea at ieee.org Fri Nov 6 16:08:49 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 16:08:49 -0500 Subject: Is there a function that can test if a path is in a directory or one of its sub-directory (recursively)? In-Reply-To: <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> References: <366c6f340911051941s47a7b91cj7f906faee99175a@mail.gmail.com> <50697b2c0911051953v2cd898doe85c481c53901860@mail.gmail.com> <50697b2c0911060019g31de29d2t59961eb5d8b70b7c@mail.gmail.com> Message-ID: <4AF49061.8000408@ieee.org> Chris Rebert wrote: > On Thu, Nov 5, 2009 at 10:49 PM, Gabriel Genellina > wrote: > >> En Fri, 06 Nov 2009 00:53:14 -0300, Chris Rebert >> escribi?: >> >>> On Thu, Nov 5, 2009 at 7:41 PM, Peng Yu wrote: >>> >>>> I looked though the os.path manual. I don't find a function that can >>>> test if a path is in a directory or its sub-directory (recursively). >>>> >>>> For example, /a/b/c/d is in /a its sub-directory (recursively). Could >>>> somebody let me know if such function is available somewhere? >>>> >>> Couldn't you just canonicalize the paths using os.path.abspath() and >>> friends and then do subdirectory.startswith(parent_directory) [as >>> strings]? >>> >> Beware of directories starting with the same letters. >> I'd canonicalize, split the strings on os.sep, and compare the resulting >> lists up to the shortest one. >> > > Ah, I thought there was some edge case I must've missed; my solution > seemed too simple. > > Cheers, > Chris > > But you can probably add a trailing '/' (os.sep) to the shorter string before doing the startswith(). DaveA From irmen at -nospam-xs4all.nl Fri Nov 6 16:09:09 2009 From: irmen at -nospam-xs4all.nl (Irmen de Jong) Date: Fri, 06 Nov 2009 22:09:09 +0100 Subject: username/password dialog prompt In-Reply-To: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> Message-ID: <4af4904b$0$83240$e4fe514c@news.xs4all.nl> On 6-11-2009 20:41, Dan Winsor wrote: > Hi, > > To preface, I'm a bit of a python novice, but I have been poking > around for the solution for a bit and have found actually too many > leads which has wedged me. I'm looking to impliment a dialog, > preferably using Tkinter, that will prompt for a username and > password. I'd like to have the password field blanked (via show="*"), > and have the dialog return both fields to the command line script that > I'm launching it from. Can someone recommend a good example or > tutorial to work from? Thanks very much in advance. My Tkinter is very rusty but perhaps you could do it something like this: http://pastebin.com/m5e49da19 I forgot how to get rid of the empty root window that appears, sorry. -irmen From aahz at pythoncraft.com Fri Nov 6 16:15:32 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Nov 2009 13:15:32 -0800 Subject: Microsoft research on code quality Message-ID: http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From SD_V897 at NoSuchMail.Com Fri Nov 6 16:19:44 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Fri, 06 Nov 2009 21:19:44 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: Rhodri James wrote: > On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 wrote: > >> I have a perplexing issue, I have four users set up on a W7 computer. >> The program runs fine for all users except the admin user who needs it >> for school assignments. > > A little more information, please. How does it not work for the admin > user? Is there a traceback? What do you get if you try to invoke it > from a command line? > Hi Rhodri, here's a dump file, don't know if this helps or not.. Thanks SD Version=1 EventType=AppHangB1 EventTime=129003071519208984 ReportType=3 Consent=1 ReportIdentifier=6a6f168c-bb8f-11de-bef3-044b80808003 IntegratorReportIdentifier=6a6f168d-bb8f-11de-bef3-044b80808003 Response.type=4 Sig[0].Name=Application Name Sig[0].Value=pythonw.exe Sig[1].Name=Application Version Sig[1].Value=0.0.0.0 Sig[2].Name=Application Timestamp Sig[2].Value=49e4f60b Sig[3].Name=Hang Signature Sig[3].Value=ae24 Sig[4].Name=Hang Type Sig[4].Value=0 DynamicSig[1].Name=OS Version DynamicSig[1].Value=6.1.7600.2.0.0.256.1 DynamicSig[2].Name=Locale ID DynamicSig[2].Value=4105 DynamicSig[22].Name=Additional Hang Signature 1 DynamicSig[22].Value=ae248dc299fdb8350ad54ca616b9d7ab DynamicSig[23].Name=Additional Hang Signature 2 DynamicSig[23].Value=39ea DynamicSig[24].Name=Additional Hang Signature 3 DynamicSig[24].Value=39ea45ef52dc245a0c9d687814d64151 DynamicSig[25].Name=Additional Hang Signature 4 DynamicSig[25].Value=ae24 DynamicSig[26].Name=Additional Hang Signature 5 DynamicSig[26].Value=ae248dc299fdb8350ad54ca616b9d7ab DynamicSig[27].Name=Additional Hang Signature 6 DynamicSig[27].Value=39ea DynamicSig[28].Name=Additional Hang Signature 7 DynamicSig[28].Value=39ea45ef52dc245a0c9d687814d64151 UI[3]=pythonw.exe is not responding UI[4]=Windows can check online for a solution. If you close the program, you might lose information. UI[5]=Check for a solution and close the program UI[6]=Check for a solution and close the program UI[7]=Close the program LoadedModule[0]=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll LoadedModule[2]=C:\Windows\system32\kernel32.dll LoadedModule[3]=C:\Windows\system32\KERNELBASE.dll LoadedModule[4]=C:\Windows\system32\python26.dll LoadedModule[5]=C:\Windows\system32\USER32.dll LoadedModule[6]=C:\Windows\system32\GDI32.dll LoadedModule[7]=C:\Windows\system32\LPK.dll LoadedModule[8]=C:\Windows\system32\USP10.dll LoadedModule[9]=C:\Windows\system32\msvcrt.dll LoadedModule[10]=C:\Windows\system32\ADVAPI32.dll LoadedModule[11]=C:\Windows\SYSTEM32\sechost.dll LoadedModule[12]=C:\Windows\system32\RPCRT4.dll LoadedModule[13]=C:\Windows\system32\SHELL32.dll LoadedModule[14]=C:\Windows\system32\SHLWAPI.dll LoadedModule[15]=C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_508ed732bcbc0e5a\MSVCR90.dll LoadedModule[16]=C:\Windows\system32\IMM32.DLL LoadedModule[17]=C:\Windows\system32\MSCTF.dll LoadedModule[18]=C:\Windows\system32\guard32.dll LoadedModule[19]=C:\Windows\system32\VERSION.dll LoadedModule[20]=C:\Windows\system32\fltlib.dll LoadedModule[21]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_socket.pyd LoadedModule[22]=C:\Windows\system32\WS2_32.dll LoadedModule[23]=C:\Windows\system32\NSI.dll LoadedModule[24]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_ssl.pyd LoadedModule[25]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_ctypes.pyd LoadedModule[26]=C:\Windows\system32\ole32.dll LoadedModule[27]=C:\Windows\system32\OLEAUT32.dll LoadedModule[28]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\_tkinter.pyd LoadedModule[29]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\tcl85.dll LoadedModule[30]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\tk85.dll LoadedModule[31]=C:\Windows\system32\COMDLG32.dll LoadedModule[32]=C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16400_none_ebf9dccf6c73e561\COMCTL32.dll LoadedModule[33]=C:\Windows\system32\CRYPTSP.dll LoadedModule[34]=C:\Windows\system32\rsaenh.dll LoadedModule[35]=C:\Windows\system32\CRYPTBASE.dll LoadedModule[36]=C:\Program Files\Utilities\Python Scripting v2.62\DLLs\select.pyd LoadedModule[37]=C:\Windows\system32\WSOCK32.dll LoadedModule[38]=C:\Windows\system32\uxtheme.dll LoadedModule[39]=C:\Program Files\Utilities\RocketDock\RocketDock.dll LoadedModule[40]=C:\Windows\system32\PSAPI.DLL LoadedModule[41]=C:\Program Files\Utilities\Logitech Drivers\SetPoint\lgscroll.dll LoadedModule[42]=C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_d08a205e442db5b5\MSVCR80.dll LoadedModule[43]=C:\Windows\system32\ntmarta.dll LoadedModule[44]=C:\Windows\system32\WLDAP32.dll LoadedModule[45]=C:\Windows\system32\dwmapi.dll LoadedModule[46]=C:\Program Files\Utilities\Python Scripting v2.62\tcl\reg1.2\tclreg12.dll LoadedModule[47]=C:\Windows\system32\apphelp.dll LoadedModule[48]=C:\Windows\system32\mswsock.dll LoadedModule[49]=C:\Windows\System32\wshtcpip.dll LoadedModule[50]=C:\Windows\System32\ctagent.DLL LoadedModule[51]=C:\Program Files\Utilities\Directory Opus\dopushlp.dll LoadedModule[52]=C:\Windows\system32\MPR.dll LoadedModule[53]=C:\Windows\system32\CLBCatQ.DLL LoadedModule[54]=C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16400_none_4209f94e2b866170\comctl32.dll LoadedModule[55]=C:\Windows\system32\SETUPAPI.dll LoadedModule[56]=C:\Windows\system32\CFGMGR32.dll LoadedModule[57]=C:\Windows\system32\DEVOBJ.dll LoadedModule[58]=C:\Windows\system32\propsys.dll LoadedModule[59]=C:\Windows\system32\profapi.dll LoadedModule[60]=C:\Windows\system32\SearchFolder.dll LoadedModule[61]=C:\Windows\system32\XmlLite.dll LoadedModule[62]=C:\Windows\system32\LINKINFO.dll LoadedModule[63]=C:\Windows\system32\RpcRtRemote.dll LoadedModule[64]=C:\Windows\system32\explorerframe.dll LoadedModule[65]=C:\Windows\system32\DUser.dll LoadedModule[66]=C:\Windows\system32\DUI70.dll LoadedModule[67]=C:\Windows\system32\WindowsCodecs.dll LoadedModule[68]=C:\Windows\system32\EhStorShell.dll LoadedModule[69]=C:\Windows\System32\cscui.dll LoadedModule[70]=C:\Windows\System32\CSCDLL.dll LoadedModule[71]=C:\Windows\system32\CSCAPI.dll LoadedModule[72]=C:\Windows\system32\ntshrui.dll LoadedModule[73]=C:\Windows\system32\srvcli.dll LoadedModule[74]=C:\Windows\system32\slc.dll LoadedModule[75]=C:\Windows\system32\msls31.dll LoadedModule[76]=C:\Program Files\Common Files\microsoft shared\ink\tiptsf.dll LoadedModule[77]=C:\Windows\System32\StructuredQuery.dll LoadedModule[78]=C:\Windows\System32\Secur32.dll LoadedModule[79]=C:\Windows\System32\SSPICLI.DLL LoadedModule[80]=C:\Windows\system32\actxprxy.dll LoadedModule[81]=C:\Program Files\Internet Explorer\ieproxy.dll LoadedModule[82]=C:\Windows\system32\thumbcache.dll LoadedModule[83]=C:\Windows\system32\SHDOCVW.dll LoadedModule[84]=C:\Windows\system32\ieframe.DLL LoadedModule[85]=C:\Windows\system32\OLEACC.dll LoadedModule[86]=C:\Windows\system32\iertutil.dll LoadedModule[87]=C:\Windows\System32\drprov.dll LoadedModule[88]=C:\Windows\System32\WINSTA.dll LoadedModule[89]=C:\Windows\System32\ntlanman.dll LoadedModule[90]=C:\Windows\System32\davclnt.dll LoadedModule[91]=C:\Windows\System32\DAVHLPR.dll LoadedModule[92]=C:\Windows\system32\NetworkExplorer.dll LoadedModule[93]=C:\Windows\system32\wkscli.dll LoadedModule[94]=C:\Windows\system32\netutils.dll LoadedModule[95]=C:\Windows\system32\WINMM.dll LoadedModule[96]=C:\Windows\system32\PortableDeviceApi.dll LoadedModule[97]=C:\Windows\system32\WINTRUST.dll LoadedModule[98]=C:\Windows\system32\CRYPT32.dll LoadedModule[99]=C:\Windows\system32\MSASN1.dll LoadedModule[100]=C:\Windows\system32\EhStorAPI.dll LoadedModule[101]=C:\Windows\system32\mssprxy.dll LoadedModule[102]=C:\Windows\system32\IconCodecService.dll LoadedModule[103]=C:\Windows\system32\urlmon.dll FriendlyEventName=Stopped responding and was closed ConsentKey=AppHangXProcB1 AppName=pythonw.exe AppPath=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe ReportDescription=A problem caused this program to stop interacting with Windows. From davea at ieee.org Fri Nov 6 16:32:05 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 16:32:05 -0500 Subject: Best way for permutating using multiple lists? In-Reply-To: <4AF427EB.8010804@xs4all.nl> References: <4AF427EB.8010804@xs4all.nl> Message-ID: <4AF495D5.7090703@ieee.org> Michiel Overtoom wrote: >
    hob wrote: > >> any advice people? > > import itertools > alt=itertools.product("def","abc","mno","mno","wxyz") > > Note to the OP. You called this permutation, but it's not. It's the crossproduct. Thus itertools.product DaveA From stef.mientki at gmail.com Fri Nov 6 16:33:37 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 06 Nov 2009 22:33:37 +0100 Subject: imputil.py, is this a bug ? Message-ID: <4AF49631.8090003@gmail.com> hello, I get an error compiling with pyjamas, in the standard module imputil, _import_top_module Traceback (most recent call last): File "D:\Data_Python_25\PyLab_Works\pylab_works_programs\PyJamas_Test\Vraag_Test1.py", line 22, in from Vragenlijsten import Get_Vragenlijst File "P:\Python\Lib\site-packages\pyjd\imputil.py", line 109, in _import_hook top_module = self._import_top_module(parts[0]) File "P:\Python\Lib\site-packages\pyjd\imputil.py", line 217, in _import_top_module module = item.import_top(name) AttributeError: 'unicode' object has no attribute 'import_top' It seems that elements of sys.path can be of the type unicode def _import_top_module(self, name): # scan sys.path looking for a location in the filesystem that contains # the module, or an Importer object that can import the module. for item in sys.path: if isinstance(item, _StringType): module = self.fs_imp.import_from_dir(item, name) else: module = item.import_top(name) if module: return module return None so by adding the next 2 lines, everything works ok. elif isinstance ( item, basestring ) : module = self.fs_imp.import_from_dir ( str(item), name) is this a bug ? (I'm using Python 2.5.2 on Windows ) thanks, Stef Mientki From cousinstanley at gmail.com Fri Nov 6 16:40:18 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 6 Nov 2009 21:40:18 +0000 (UTC) Subject: username/password dialog prompt References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> <4af4904b$0$83240$e4fe514c@news.xs4all.nl> Message-ID: > > My Tkinter is very rusty but perhaps you could do it > something like this : http://pastebin.com/m5e49da19 > > I forgot how to get rid of the empty root window > that appears, sorry. root.withdraw() # should do it -- Stanley C. Kitching Human Being Phoenix, Arizona From exarkun at twistedmatrix.com Fri Nov 6 16:47:18 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 06 Nov 2009 21:47:18 -0000 Subject: Microsoft research on code quality In-Reply-To: References: Message-ID: <20091106214718.3229.36519750.divmod.xquotient.208@localhost.localdomain> On 09:15 pm, aahz at pythoncraft.com wrote: >http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx Thanks for passing on the link. It's really encouraging to see people starting to do empirical research in this area. Jean-Paul From jabba.laci at gmail.com Fri Nov 6 16:50:16 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 Nov 2009 16:50:16 -0500 Subject: regexp question Message-ID: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Hi, How to find all occurences of a substring in a string? I want to convert the following Perl code to Python. Thanks, Laszlo ========== my $text = 'sdqssdsqs'; while ($text =~ m#href="?(.*?)"?>#g) { print $1, "\n"; } # output: # # ad1 # ad2 # ad3 From tjreedy at udel.edu Fri Nov 6 16:58:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Nov 2009 16:58:31 -0500 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> References: <366c6f340911052019h73ddd3d2u2c1546c66dd5b134@mail.gmail.com> <50697b2c0911052025x1559b96bt45a81dd2591e5991@mail.gmail.com> <366c6f340911052123n79b9204vc3e2d180e33c69bf@mail.gmail.com> Message-ID: Peng Yu wrote: > Now, I want to in-place delete elements in A that matches the regex. You can to this with a for-loop *IF YOU ITERATE BACKWARDS*. It is O(n**2) in anycase. From bowman.joseph at gmail.com Fri Nov 6 17:06:18 2009 From: bowman.joseph at gmail.com (bowman.joseph at gmail.com) Date: Fri, 6 Nov 2009 14:06:18 -0800 (PST) Subject: Question about creating dictionary like objects Message-ID: I'm working on a memcached based session library, and I've run into an interesting problem. Here's the full code for the session library - http://pastebin.com/m295fdfc2 What I'm doing is using __setitem__ to set an element as a list. When I call .append() on that list, it appears to be modifying the list in memory, but not running __setitem__ on the parent in order for the information to get saved in memcached. For example, here's a test I wrote in Tornado class TestHandler(BaseHandler): def get(self): session = sessions.Session(req_obj = self) if "test" in session: self.write("should be appending") session["test"].append(datetime.datetime.now()) else: session["test"] = ["first"] self.write(str(session)) This should have just "test" in the list on first load (which it does), the append the datetime object on every refresh, so the list should keep growing. What I'm seeing is that the datetime does get appended to the list in the session object that is printed, but the __setitem__() item is never called, so it never gets updated in memcached. Can someone tell me what I'm doing wrong? From joncle at googlemail.com Fri Nov 6 17:06:26 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 6 Nov 2009 14:06:26 -0800 (PST) Subject: regexp question References: Message-ID: <8e537139-518f-46f3-b6d2-23c5ec0259e4@15g2000yqy.googlegroups.com> On Nov 6, 9:50?pm, Jabba Laci wrote: > Hi, > > How to find all occurences of a substring in a string? I want to > convert the following Perl code to Python. > > Thanks, > > Laszlo > > ========== > > my $text = 'sdqssdsqs'; > > while ($text =~ m#href="?(.*?)"?>#g) > { > ? ?print $1, "\n";} > > # output: > # > # ad1 > # ad2 > # ad3 There's numerous threads on why using regexp's to process html is not a great idea. Search GGs. You're better off using beautifulsoup (an HTML parsing library). The API is simple, and for real-world data is a much better choice. hth Jon. From rami.chowdhury at gmail.com Fri Nov 6 17:10:00 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 06 Nov 2009 14:10:00 -0800 Subject: regexp question In-Reply-To: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> References: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Message-ID: On Fri, 06 Nov 2009 13:50:16 -0800, Jabba Laci wrote: > Hi, > > How to find all occurences of a substring in a string? I want to > convert the following Perl code to Python. > > Thanks, > > Laszlo > > ========== > > my $text = 'sdqssds href=ad3>qs'; > > while ($text =~ m#href="?(.*?)"?>#g) > { > print $1, "\n"; > } > # output: > # > # ad1 > # ad2 > # ad3 Your regular expression pattern should work unchanged, and you probably want to use http://docs.python.org/library/re.html#re.findall or similar to do the actual matching. If all you want to do is iterate over the matches, I would use re.finditer :-) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From jabba.laci at gmail.com Fri Nov 6 17:19:29 2009 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 6 Nov 2009 17:19:29 -0500 Subject: regexp question In-Reply-To: References: <310fbb00911061350w41817ae8m8c1085985a4507cb@mail.gmail.com> Message-ID: <310fbb00911061419ra4ba8beva4ed029f61197664@mail.gmail.com> > Your regular expression pattern should work unchanged, and you probably want > to use ?http://docs.python.org/library/re.html#re.findall or similar to do > the actual matching. If all you want to do is iterate over the matches, I > would use re.finditer :-) Thank you, I found the solution: for m in re.finditer(r'href="?(.*?)"?>', text): print m.group(1) Laszlo From clp2 at rebertia.com Fri Nov 6 17:55:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 14:55:53 -0800 Subject: Question about creating dictionary like objects In-Reply-To: References: Message-ID: <50697b2c0911061455r4ff60f48k96e1d87975be23e1@mail.gmail.com> On Fri, Nov 6, 2009 at 2:06 PM, bowman.joseph at gmail.com wrote: > I'm working on a memcached based session library, and I've run into an > interesting problem. > > Here's the full code for the session library - http://pastebin.com/m295fdfc2 > > What I'm doing is using __setitem__ to set an element as a list. When > I call .append() on that list, it appears to be modifying the list in > memory, but not running __setitem__ on the parent in order for the > information to get saved in memcached. list.append() just appends the item to the list object. That's all it does *and nothing else*. It doesn't call __setitem__ on the "parent" object containing the list; how would it even know about that object to begin with? (pointers aren't reversible) With normal containers, there's no need to store modified, mutable items back in the container: the item got modified in-place, the reference to it from the container is still valid, so storing it back would be pointless (sounds like memcached is quirky (but probably justifiably so) in not having this work). Perhaps you thought some copying occurs when getting items out of containers? That's not the case. Since it sounds like you need to force a __setitem__ call on `session` to have memcached update its storage, you'll have to do it explicitly. Change: session["test"].append(datetime.datetime.now()) To: #use some name better than "foo" obviously foo = session["test"] #fetch foo.append(datetime.datetime.now()) #mutate session["test"] = foo #store back explicitly so memcached knows there was a change Cheers, Chris -- http://blog.rebertia.com From subnibhatt at gmail.com Fri Nov 6 18:37:50 2009 From: subnibhatt at gmail.com (Subrahmanya Bhat) Date: Fri, 6 Nov 2009 18:37:50 -0500 Subject: Editing PDF files usig Python Message-ID: Hi All, Greetings, I am a newbie in Python, i have a requirement to develop a component in python that can "text" water mark the PDF file both digitallly and visibly. I have already devloped this kind of a component in .Net using iTextSharp library. So i know a thing or 2 about water marking :-) i also need to able to read back the water mark text that was put in to the PDF (both digital and visible). I looked around on google and found that pyPDF, win32Client etc which may be the one i will have to use. using neither of them i could put a text and hidden text in to the pdf files. Any light thrown in this direction will be of great help to me. Appcreciate your help with this. Thanks Subrah -------------- next part -------------- An HTML attachment was scrubbed... URL: From e1safdar at gmail.com Fri Nov 6 18:48:32 2009 From: e1safdar at gmail.com (safdar) Date: Fri, 6 Nov 2009 15:48:32 -0800 (PST) Subject: Earn Money Message-ID: <927fe7cc-8720-458c-804a-2396a09641c9@s21g2000prm.googlegroups.com> Hello Friend How R U I am fine Plz visit my Blogs http://howweearn.blogspot.com http://safdar-culturefashion.blogspot.com/ http://onlineearningmoneysites.blogspot.com/ http://workonadsense.blogspot.com/ http://safdarhussain2.wordpress.com/ http://chinapakistan.blogspot.com/ http://usamericaol.blogspot.com/ http://americavsmuslimworld.blogspot.com/ http://www.onlineork.cc.cc From davea at ieee.org Fri Nov 6 18:57:28 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 06 Nov 2009 18:57:28 -0500 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> Message-ID: <4AF4B7E8.1030807@ieee.org> Peng Yu wrote: > On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day wrote: > >> On Fri, 6 Nov 2009, Peng Yu wrote: >> >> >>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch wrote: >>> >>>> Peng Yu schrieb: >>>> >>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>> could use a for loop to do so. In a functional language, there is way >>>>> to do so without using the for loop. >>>>> >>>> Nonsense. For processing over each element, you have to loop over them, >>>> either with or without growing a call-stack at the same time. >>>> >>>> FP languages can optimize away the stack-frame-growth (tail recursion) - but >>>> this isn't reducing complexity in any way. >>>> >>>> So use a loop, either directly, or using a list-comprehension. >>>> >>> What is a list-comprehension? >>> >>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>> the iterator, right? I am wondering how to make the code correct. >>> >>> l ='a', 'a', 'b', 'c'] >>> for x in l: >>> if x ='a': >>> l.remove(x) >>> >>> print l >>> >> list comprehension seems to be what you want: >> >> l =i for i in l if i != 'a'] >> > > My problem comes from the context of using os.walk(). Please see the > description of the following webpage. Somehow I have to modify the > list inplace. I have already tried 'dirs =i for i in l if dirs !'a']'. But it seems that it doesn't "prune the search". So I need the > inplace modification of list. > > http://docs.python.org/library/os.html > > When topdown is True, the caller can modify the dirnames list in-place > (perhaps using del or slice assignment), and walk() will only recurse > into the subdirectories whose names remain in dirnames; this can be > used to prune the search, impose a specific order of visiting, or even > to inform walk() about directories the caller creates or renames > before it resumes walk() again. Modifying dirnames when topdown is > False is ineffective, because in bottom-up mode the directories in > dirnames are generated before dirpath itself is generated. > > The context is quite important in this case. The os.walk() iterator gives you a tuple of three values, and one of them is a list. You do indeed want to modify that list, but you usually don't want to do it "in-place." I'll show you the in-place version first, then show you the slice approach. If all you wanted to do was to remove one or two specific items from the list, then the remove method would be good. So in your example, you don' t need a loop. Just say: if 'a' in dirs: dirs.remove('a') But if you have an expression you want to match each dir against, the list comprehension is the best answer. And the trick to stuffing that new list into the original list object is to use slicing on the left side. The [:] notation is a default slice that means the whole list. dirs[:] = [ item for item in dirs if bool_expression_on_item ] HTH DaveA From gagsl-py2 at yahoo.com.ar Fri Nov 6 21:20:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 06 Nov 2009 23:20:01 -0300 Subject: imputil.py, is this a bug ? References: <4AF49631.8090003@gmail.com> Message-ID: En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki escribi?: > I get an error compiling with pyjamas, in the standard module imputil, > _import_top_module Note that imputil is undocumented in 2.5, deprecated in 2.6 and definitively gone in 3.0 > AttributeError: 'unicode' object has no attribute 'import_top' > > def _import_top_module(self, name): > # scan sys.path looking for a location in the filesystem that > contains > # the module, or an Importer object that can import the module. > for item in sys.path: > if isinstance(item, _StringType): > module = self.fs_imp.import_from_dir(item, name) > else: > module = item.import_top(name) > if module: > return module > return None > > It seems that elements of sys.path can be of the type unicode > so by adding the next 2 lines, everything works ok. > elif isinstance ( item, basestring ) : > module = self.fs_imp.import_from_dir ( str(item), name) > > is this a bug ? > (I'm using Python 2.5.2 on Windows ) Yes, seems to be a bug. But given the current status of imputil, it's not likely to be fixed; certainly not in 2.5 which only gets security fixes now. I cannot test it at this moment, but I'd use the unicode item directly (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps item.encode(sys.getdefaultfilesystemencoding()). str(item) definitively won't work with directory names containing non-ascii characters. Why are you using imputil in the first place? -- Gabriel Genellina From gil_johnson at earthlink.net Fri Nov 6 21:46:33 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Fri, 6 Nov 2009 18:46:33 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On Nov 6, 6:12?am, kj wrote: > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ? my @arr; > ? $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ? my @arr; > ? $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > > Traceback (most recent call last): > ? File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn I don't have the code with me, but for huge arrays, I have used something like: >>> arr[0] = initializer >>> for i in range N: >>> arr.extend(arr) This doubles the array every time through the loop, and you can add the powers of 2 to get the desired result. Gil From rt8396 at gmail.com Fri Nov 6 22:06:29 2009 From: rt8396 at gmail.com (r) Date: Fri, 6 Nov 2009 19:06:29 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <1cda743f-5231-4b76-9322-db0e4d474472@p19g2000vbq.googlegroups.com> On Nov 6, 6:12?am, kj wrote: > In Perl one can assign a value to any element of an array, even to > ones corresponding to indices greater or equal than the length of > the array: > > ? my @arr; > ? $arr[999] = 42; > > perl grows the array as needed to accommodate this assignment. ?In > fact one common optimization in Perl is to "pre-grow" the array to > its final size, rather than having perl grow it piecemeal as required > by assignments like the one above: > > ? my @arr; > ? $#arr = 999_999; > > After assigning to $#arr (the last index of @arr) as shown above, > @arr has length 1,000,000, and all its elements are initialized to > undef. > > In Python the most literal translation of the first code snippet > above triggers an IndexError exception: > > >>> arr = list() > >>> arr[999] = 42 > > Traceback (most recent call last): > ? File "", line 1, in > IndexError: list assignment index out of range > > In fact, one would need to pre-grow the list sufficiently to be > able to make an assignment like this one. ?I.e. one needs the > equivalent of the second Perl snippet above. > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > > TIA! > > kynn You mean sum'in like dis? class PerlishList(list): '''Hand holding list object for even the most demanding Perl hacker''' def __init__(self, dim=0): list.__init__(self) if dim: self.__setitem__(dim, None) def __setitem__(self, idx, v): lenkeys = len(self) sup = super(PerlishList, self) if idx > lenkeys: for idx in range(lenkeys, idx): sup.append(None) sup.__setitem__(idx, v) def __getitem__(self, idx): return self[idx] l = PerlishList(3) l.append('a') l.append('b') print l l[10] = 10 print l ;-) From gagsl-py2 at yahoo.com.ar Fri Nov 6 22:31:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 07 Nov 2009 00:31:35 -0300 Subject: list to table References: <4AF44466.4040200@optimum.net> Message-ID: En Fri, 06 Nov 2009 12:44:38 -0300, John Posner escribi?: > Gabriel Genellina said: >> Yes, probably that section should be improved (except the final example >> added, the text hasn't changed since it was first written, more than 9 >> years ago). > FWIW ... following on a discussion in this forum in March of this year I > submitted issue #5621 at bugs.python.org [...] > My change was accepted (with some rearrangements made by Georg Brandl), > but has not yet been included in any Py2 or Py3 release, AFAIK. That's strange. Your modified text appears in the online version of the documentation for 2.6.4: http://www.python.org/doc/2.6.4/reference/simple_stmts.html#assignment-statements but not in the source package nor the .chm file included in the Windows binaries for the same release. Same with 3.1.1 Looks like an error in the build process. -- Gabriel Genellina From pict100 at gmail.com Fri Nov 6 23:12:02 2009 From: pict100 at gmail.com (DarkBlue) Date: Fri, 6 Nov 2009 20:12:02 -0800 (PST) Subject: PyQt processEvents not processing Message-ID: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> qt 4.5.3 pyqt 4.6.1 python 2.6 I have this QtTable widget which I want to refresh once about every 2 seconds with new data. so I do : def updateSchedule(self): for j in range(0,10): doUpdate() QtCore.processEvents() sleep(2) unfortunately QT appears to wait until the for loop finishes and only then paints the QtTable widget on the screen showing only the latest updated result. if I connect the doUpdate() to a Qtpushbutton widget and physically click the pushbutton , everything is fine and the updates get shown on every click. What is the right way to simulate this pushbutton click so that the table widget gets 'visibly' refreshed for every iteration of the loop ? Thanks Db From nagle at animats.com Sat Nov 7 00:27:55 2009 From: nagle at animats.com (John Nagle) Date: Fri, 06 Nov 2009 21:27:55 -0800 Subject: Aborting a read with pySerial Message-ID: <4af50316$0$1610$742ec2ed@news.sonic.net> I'm using pySerial to read from a serial port. One thread reads from the port, with no timeout. Another thread handles output and other tasks. This works fine until I want to shut down the program. I can't reliably break the program out of the read when it's waiting. On Windows, closing the serial port will abort the read, but that seems to have no effect on Linux. I know, I could put a timeout on the read and handle all those null returns. Is there a better way? John Nagle From jleihe at gmail.com Sat Nov 7 00:40:24 2009 From: jleihe at gmail.com (Joshua Leihe) Date: Fri, 6 Nov 2009 21:40:24 -0800 Subject: Py2exe error Message-ID: Hello, I was wondering if anyone know how to fix this. When I try to import py2exe version 0.6.9, using the command "import py2exe" I get the following error message. Warning (from warnings module): File "C:\Program Files\Python25\lib\site-packages\py2exe\build_exe.py", line 16 import sets DeprecationWarning: the sets module is deprecated Apparently something is wrong with the sets module, but I don't know how to fix it. Any ideas? Thanks a million, Joshua -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 7 01:12:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 6 Nov 2009 22:12:32 -0800 Subject: Py2exe error In-Reply-To: References: Message-ID: <50697b2c0911062212l39c45eb5r1cccb7054d627220@mail.gmail.com> On Fri, Nov 6, 2009 at 9:40 PM, Joshua Leihe wrote: > Hello, I was wondering if anyone know how to fix this. > When I try to import py2exe version 0.6.9, using the command "import py2exe" > I get the following error message. > > Warning (from warnings module): > ? File "C:\Program Files\Python25\lib\site-packages\py2exe\build_exe.py", > line 16 > ??? import sets > DeprecationWarning: the sets module is deprecated > > Apparently something is wrong with the sets module, but I don't know how to > fix it. > Any ideas? It's a warning, not an error, so you don't truly need to fix it. You can safely ignore it. Apparently your version of py2exe was written for a Python version before sets became a built-in type and thus importing the `sets` module was required in order to use them. Since sets are now built-in, the `sets` module is being phased out, hence the warning; nothing is erroneous with the `sets` module, you're just being told the py2exe code is using it and that it's being deprecated. The py2exe code will /eventually/ need to be changed when it's ported to a version of Python that completely removes the `sets` module (e.g. 3.x), but it's nothing you personally need to worry about. Cheers, Chris -- http://blog.rebertia.com From callmeclaudius at gmail.com Sat Nov 7 01:25:47 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Fri, 6 Nov 2009 22:25:47 -0800 (PST) Subject: parse a string (Cadence Allegro Netlist) to dictionary References: <2d9e2ecc-19b1-4af1-bc6a-a366f4b29ed7@a21g2000yqc.googlegroups.com> Message-ID: On Nov 5, 7:23 pm, metal wrote: > On 11?6?, ??4?02?, Leland wrote: > > > > > Hi, > > > I always use readline(), strip(), split() and so on to parse a string. > > Is there some elegant way to parse the following string into a > > dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}? > > > NET_NAME > > '50MHZ_CLK_SRC' > > '@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC': > > C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\'; > > NODE_NAME U122 2 > > '@TEST_LIB.TEST(SCH_1):PAGE92_I223 at INF_LOGIC.CY2305(CHIPS)': > > 'CLK2': CDS_PINID='CLK2'; > > NODE_NAME R1395 1 > > '@TEST_LIB.TEST(SCH_1):PAGE92_I232 at INF_RESISTORS.RESISTOR(CHIPS)': > > 'A': CDS_PINID='A'; > > > Thanks, > > Leland > > not very elegantly too. > > x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s) > """ > print {x[0]: x[1:]}>>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']} > > """ @metal Apparently you and I differ considerably on our conceptions of elegance. From stefan_ml at behnel.de Sat Nov 7 02:20:20 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 07 Nov 2009 08:20:20 +0100 Subject: is None or == None ? In-Reply-To: References: <4af4259a$0$6577$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4af521a4$0$7614$9b4e6d93@newsspool1.arcor-online.net> mk, 06.11.2009 15:32: > Stefan Behnel wrote: >> class Test(object): >> def __eq__(self, other): >> return other == None >> >> print Test() == None, Test() is None > > Err, I don't want to sound daft, but what is wrong in this example? It > should work as expected: > > >>> class Test(object): > ... def __eq__(self, other): > ... return other == None > ... > >>> Test() is None > False > >>> Test() == None > True Yes, and it shows you that things can compare equal to None without being None. > Or perhaps your example was supposed to show that I should test for > identity with None, not for value with None? Instead of "value" you mean "equality" here, I suppose. While there are certain rare use cases where evaluating non-None objects as equal to None makes sense, in normal use, you almost always want to know if a value is exactly None, not just something that happens to return True when calculating its equality to None, be it because of a programmer's concious consideration or buggy implementation. Stefan From saketh.bhamidipati at gmail.com Sat Nov 7 02:58:15 2009 From: saketh.bhamidipati at gmail.com (Saketh) Date: Fri, 6 Nov 2009 23:58:15 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: On Nov 4, 5:28?pm, Alan Franzoni wrote: > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > > Being from germany, I can say that we *have* this fragmentation, and > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > That's right... forums, although more "accessible" to all the people who > can't/doesn't want to use specific email or nntp clients, are quite slow > to use. > > But I think Ubuntu forums support threads and are kind of "channeled" > between ML and webinterface... something like Google Groups; I think > THAT would be a good idea. What about trying to "channel" > comp.lang.python and a forum? > > -- > Alan Franzoni > contact me at public@[mysurname].eu Hi everyone, My small effort to create a place for discussing Python seems to have sparked a larger discussion than I had anticipated. My intent in creating Pyfora is not to splinter the community or encroach upon comp.lang.python users, but to create an alternative location where users can discuss Python. If this offends or irritates anyone, please accept my humble apologies. I understand that forums can be degenerate and uncivil, but my hope is that with Pyfora, beginners will have a place to freely ask questions in a genial environment. A large part of my computer upbringing was on forums, and I wanted to share that experience with new Python users. Sincerely, Saketh From michele.simionato at gmail.com Sat Nov 7 02:59:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 6 Nov 2009 23:59:32 -0800 (PST) Subject: extracting info from media files Message-ID: I would like to extract some simple info from media files, such as size, resolution, duration, codec. What's the simplest way to do it? Once in a time there was pymedia but I see the latest release is of February 2006. The solution should work on Linux and provide support for a large set of video formats. From david at bibliolabs.com Sat Nov 7 04:29:35 2009 From: david at bibliolabs.com (David Williams) Date: Sat, 7 Nov 2009 03:29:35 -0600 (CST) Subject: Editing PDF files usig Python In-Reply-To: References: Message-ID: <58124.76.26.219.35.1257586175.squirrel@www.bibliobazaar.com> Maybe try ReportLab, its pretty much the most advanced Python PDF toolkit I know of: http://www.reportlab.org/ > Hi All, > > Greetings, > > I am a newbie in Python, i have a requirement to develop a component in > python that can "text" water mark the PDF file both digitallly and > visibly. > I have already devloped this kind of a component in .Net using iTextSharp > library. So i know a thing or 2 about water marking :-) > i also need to able to read back the water mark text that was put in to > the > PDF (both digital and visible). > > I looked around on google and found that pyPDF, win32Client etc which may > be > the one i will have to use. using neither of them i could put a text and > hidden text in to the pdf files. Any light thrown in this direction will > be > of great help to me. Appcreciate your help with this. > > Thanks > Subrah > -- > http://mail.python.org/mailman/listinfo/python-list > From raluk_th3blu3_star at yahoo.com Sat Nov 7 04:30:40 2009 From: raluk_th3blu3_star at yahoo.com (Raluca Spanu) Date: Sat, 7 Nov 2009 01:30:40 -0800 (PST) Subject: smtpd and custom MAIL_FROM/RCPT_TO validation Message-ID: <942240.55529.qm@web112306.mail.gq1.yahoo.com> Am o ?ntrebare, v? rug?m: De ce nu-mi trimit messages from Romania to America? :( -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sat Nov 7 04:55:31 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 07 Nov 2009 10:55:31 +0100 Subject: imputil.py, is this a bug ? In-Reply-To: References: <4AF49631.8090003@gmail.com> Message-ID: <4AF54413.9080502@gmail.com> Gabriel Genellina wrote: > En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki > escribi?: > >> I get an error compiling with pyjamas, in the standard module >> imputil, _import_top_module > > Note that imputil is undocumented in 2.5, deprecated in 2.6 and > definitively gone in 3.0 > >> AttributeError: 'unicode' object has no attribute 'import_top' >> >> def _import_top_module(self, name): >> # scan sys.path looking for a location in the filesystem that >> contains >> # the module, or an Importer object that can import the module. >> for item in sys.path: >> if isinstance(item, _StringType): >> module = self.fs_imp.import_from_dir(item, name) >> else: >> module = item.import_top(name) >> if module: >> return module >> return None >> >> It seems that elements of sys.path can be of the type unicode >> so by adding the next 2 lines, everything works ok. >> elif isinstance ( item, basestring ) : >> module = self.fs_imp.import_from_dir ( str(item), name) >> >> is this a bug ? >> (I'm using Python 2.5.2 on Windows ) > > Yes, seems to be a bug. But given the current status of imputil, it's > not likely to be fixed; certainly not in 2.5 which only gets security > fixes now. > > I cannot test it at this moment, but I'd use the unicode item directly > (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps > item.encode(sys.getdefaultfilesystemencoding()). str(item) > definitively won't work with directory names containing non-ascii > characters. > > Why are you using imputil in the first place? > thanks Gabriel, well PyJamas is using (a copy) of it and I bumped into problems using PyJamas. I'll send this message to the PyJamas developers, because this stuff is far beyond my knowledge. cheers, Stef From luke.leighton at googlemail.com Sat Nov 7 06:29:24 2009 From: luke.leighton at googlemail.com (lkcl) Date: Sat, 7 Nov 2009 03:29:24 -0800 (PST) Subject: imputil.py, is this a bug ? References: <4AF49631.8090003@gmail.com> Message-ID: On Nov 7, 2:20 am, "Gabriel Genellina" wrote: > Yes, seems to be a bug. But given the current status of imputil, it's not > likely to be fixed; certainly not in 2.5 which only gets security fixes > now. well, that bug's not the only one. the other one that i found, which i have been specifically ordered not to report (that or _any_ python bugs, of which there have been several discovered in the past eight months), will have to wait until the python developers rescind that order. if the python community is lucky, by the time that decision is made, i will not have forgotten what those bugs are. > (that is, self.fs_imp.import_from_dir(item, name)). Or perhaps > item.encode(sys.getdefaultfilesystemencoding()). str(item) definitively > won't work with directory names containing non-ascii characters. > > Why are you using imputil in the first place? it's an absolutely necessary and integral part of pyjamas-desktop "platform overrides". it's absolutely essential to track, in exactly the same manner in which python "normally" performs importing, and to give the platform- specific "overrides" a chance to get in there, first. so, it is absolutely essential to have a correct working version of imputil.py - and due to the bugs present, and the unwillingness of the python team to fix those bugs, pyjamas-desktop is forced to maintain a copy of imputil.py the "platform" is set to e.g. hulahop, pywebkitgtk or mshtml, depending on the decision made by the user or the developer to use a particular browser engine. the platform name is stored in pyjd.platform in exactly the same way that the system name is stored in sys.platform. the way that the platform-specific overrides works is to perform AST translation of the module, and then to look for the exact same module but in platform/{modulename}{platformname}.py and perform AST translation of _that_ module as well. then, at the top level, any global functions in the platform-specific AST tree *replace* those in the "main" AST. likewise, a node-walk along all methods in all classes of the platform-specific AST tree. in this way, god-awful messy code like this: Widget.py class Widget: def do_something(self): if platform == 'mshtml': # do something terrible and ugly elif platform == 'pywebkitgtk': # do something only marginally better else: # do the default W3C standards-compliant thing def a_standard_function(self): # do something normal that all the browser engines get right can be replaced by three files, each of which encodes *only* the logic associated with the god-awful ugliness of each browser: Widget.py class Widget: def do_something(self): # do the default W3C standards-compliant thing def a_standard_function(self): # do something normal that all the browser engines get right platform/Widgetpywebkitgtk.py class Widget: def do_something(self): # do something only marginally better platform/Widgetmshtml.py class Widget: def do_something(self): # do something terrible and ugly a similar trick could in fact be deployed to drastically simplify the layout of e.g. distutils, _espeeecially_ the compiler and linker modules, by using sys.platform as the "override", or, given that that's not entirely the whole decision-making process, as i noted when doing the mingw32 port of python, it would be better to set something like distutils.platform and to use that. however, although the technique could be used in the distutils/ ccompiler.py case, the level of complexity of the code (the size of each "override"), and the small number of actual modules, means that there isn't actually that much benefit in deploying this AST- overriding technique. in the pyjamas API, however, with over 75 user-interface modules, and over 1200 functions, any one of which could be over-ridden by _eight_ separate platforms, each with their own quirks that can usually be handled with one or two lines of code, the AST-merging idea that james tauber came up with is an absolute god-send. l. From vinay_sajip at yahoo.co.uk Sat Nov 7 06:45:58 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 7 Nov 2009 03:45:58 -0800 (PST) Subject: Using logging module for conditional nested logs References: <3d615fad-bab7-4ebc-9360-7605e01836f9@h40g2000prf.googlegroups.com> Message-ID: <09c60941-c594-4773-b0dd-8ec2270926b1@o10g2000yqa.googlegroups.com> On Nov 4, 11:14?pm, Reckoner wrote: > Thanks again. You're welcome. You asked (on a Logging 101 blog comment) for a tutorial on how to use Filters. I can point you this Stack Overflow question: http://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams The answer is perhaps the tutorial you asked for. Another example is given in this test script: http://opensolaris.org/sc/src/xen-gate/xvm-3.3+xen.hg/tools/python/logging/logging-0.4.9.2/test/log_test18.py Hope it helps. Regards, Vinay Sajip From baptiste.lepilleur at gmail.com Sat Nov 7 06:56:54 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sat, 7 Nov 2009 12:56:54 +0100 Subject: What is the correct way to port codecs.open to python 3.1? Message-ID: After applying 2to3.py to port a 2.6 script to 3.1, I get the following error when running my script: File "purekeyworddbtest.py", line 143, in __init__ f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') File "c:\Python31\lib\codecs.py", line 870, in open file = builtins.open(filename, mode, buffering) ValueError: can't have text and binary mode at once I skimmed through python 3.0 release notes, and I haven't seen anything indicating that codecs.open behaviour has changed in incompatible way (just that it is no longer useful). Have I missed something? Do I need to replace all codecs.open with the built-in open function? If so, why does codecs.open still exist? -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Sat Nov 7 06:58:50 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 07 Nov 2009 11:58:50 +0000 Subject: ErrorHandler 1.1.0 Released! Message-ID: <4AF560FA.7080506@simplistix.co.uk> I'm pleased to announce a new release of ErrorHandler. This is a handler for the python standard logging framework that can be used to tell whether messages have been logged at or above a certain level. The only change for this release is that there is now a full set of documentation available courtesy of Sphinx: http://packages.python.org/errorhandler/ For more information, please see: http://www.simplistix.co.uk/software/python/errorhandler cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From john_re at fastmail.us Sat Nov 7 07:11:14 2009 From: john_re at fastmail.us (john_re) Date: Sat, 07 Nov 2009 04:11:14 -0800 Subject: Nov 7 TODAY & Nov 22 - Join Global FreeSW Python GNU(Linux) HW Culture meeting via VOIP - BerkeleyTIP GlobalTIP - For Forwarding Message-ID: <1257595874.3681.1344041095@webmail.messagingengine.com> Guido Van Rossum SciPy talk this month! CONTENTS: Meeting days/times & Howto - Mark your calendar's dates; Videos; Hot topics; Opportunities; Announcement Flyers; New webpages ===== Come join in with the Global Free SW HW & Culture community at the BerkeleyTIP/GlobalTIP meeting, via VOIP. Two meetings this month: Sat Nov 7, 12Noon - 3PM Pacific Time (=UTC-8) Sun Nov 22, 12Noon - 3PM Pacific Time (=UTC-8) Mark your calendars, 1st Sat, 3rd Sun every month. {Note: 4th Sunday this November, to give 2 week spacing.} Join online #berkeleytip on irc.freenode.net & we'll help you get your voip HW & SW working: http://sites.google.com/site/berkeleytip/remote-attendance Or come to the FreeSpeech Cafe at UC Berkeley in person meeting. Join the global mailing list http://groups.google.com/group/BerkTIPGlobal I hope to see you there. :) ===== Talk Videos for November 2009: Django Development - Richard Kiss, Eddy Mulyono, Glen Jarvis, Simeon Franklin; BayPiggies Python for scientific research, discussion with Guido van Rossum; UCBSciPy Netbooks - Michael Gorven, Dave Mackie, and Jonathan Carter; CLUG Japan Linux Symposium Keynote, Linus Torvalds & Jim Zemlin; Linux Foundation http://sites.google.com/site/berkeleytip/talk-videos Download & watch them before the meetings, discuss at the meetings. Thanks to all the Speakers, Videographers, & Groups! :) [Record your local meeting! Put the video online, & email me for inclusion for next month. :) ] ===== Hot topics: Ubuntu 9.10 - Problems? Fixes? Upgrade? Install? Freeswitch VOIP server - setup for BTIP Flyers & outreach to UCBerkeley. Outreach to other UC campuses next semester. ===== Opportunities - Learn new, or increase your job skills, &/or volunteer & help the community: Set up any of: a BTIP Mailing List, web server/site, Freeswitch VOIP server, or Virtual Private Network & SSL ===== Announcement Flyers: Print & Post them in your community. 4/5 available - Freedom, Karmic Koala, Free Culture, SciPy, OLPC. See bottom of page: http://groups.google.com/group/BerkTIPGlobal ===== New BTIP Webpages @ http://sites.google.com/site/berkeleytip/ UC Campus local groups; Free Hardware; System Administration; Announcement Flyers; Opportunities For Forwarding - You are invited to forward this announcement wherever it would be appreciated. From python at mrabarnett.plus.com Sat Nov 7 08:11:47 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 07 Nov 2009 13:11:47 +0000 Subject: What is the correct way to port codecs.open to python 3.1? In-Reply-To: References: Message-ID: <4AF57213.5080203@mrabarnett.plus.com> Baptiste Lepilleur wrote: > After applying 2to3.py to port a 2.6 script to 3.1, I get the following > error when running my script: > File "purekeyworddbtest.py", line 143, in __init__ > f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') > File "c:\Python31\lib\codecs.py", line 870, in open > file = builtins.open(filename, mode, buffering) > ValueError: can't have text and binary mode at once > > I skimmed through python 3.0 release notes, and I haven't seen anything > indicating that codecs.open behaviour has changed in incompatible way > (just that it is no longer useful). Have I missed something? > > Do I need to replace all codecs.open with the built-in open function? If > so, why does codecs.open still exist? > The documentation says of codecs.open() that "Files are always opened in binary mode, even if no binary mode was specified", but you've given the mode as 'rt', so you're asking it to open the file both in text mode _and_ binary mode. This is the same as in Python 2.6. If it works in 2.6 but not in 3.1, perhaps it's just that in 2.6 it ignores the 't' whereas in 3.1 it complains. From ryan at rfk.id.au Sat Nov 7 08:20:23 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Sun, 08 Nov 2009 00:20:23 +1100 Subject: ANN: esky 0.2.1 Message-ID: <1257600023.9188.1.camel@durian> I'm pleased to announce the latest release of esky, a tool for keeping your frozen apps fresh: Downloads: http://pypi.python.org/pypi/esky/ Latest Version: 0.2.1 License: BSD Esky is an auto-update framework for frozen python apps, built on top of bbfreeze. It provides a simple API through which apps can find, fetch and install updates, and a bootstrapping mechanism that keeps the app safe in the face of failed or partial updates. A frozen app that wants to auto-update itself might run the following in a background thread: if hasattr(sys,"frozen"): app = esky.Esky(sys.executable,"http://myapp.com/downloads/") new_version = app.find_update() if new_version is not None: app.install_update(new_version) The new version of the application is linked into the app directory in the safest possible manner: using a carefully-ordered sequence of atomic renames on POSIX, using MoveFileTransacted on Windows Vista or later, and using the "rename-and-pray" method on older versions of Windows. Failed or partial updates are detected and cleaned up automatically. Enjoy! Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From victorsubervi at gmail.com Sat Nov 7 09:13:11 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 09:13:11 -0500 Subject: Serious Privileges Problem: Please Help Message-ID: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> I have a serious privileges problem that is making it impossible to serve python pages on a CentOS server. It appears that nobody on the CentOS discussion list has a solution to this problem. I'm desperate and hoping someone on this list can help. [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ Now, the file does exist: [root at 13gems global_solutions]# pwd /var/www/html/angrynates.com/global_solutions [root at 13gems global_solutions]# ls .... -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py .... and it serves just fine on another server, so there is no "premature end of script headers". Here's where it gets really weird. If I copy the code for index.py and template.py which the former calls, and create files test.py and test2.py and paste the code from the former files in those new files changing only the import statement from "template" to "test2", the tests will resolve!! Now, the ownership and mode are identical on all of them!! [root at 13gems global_solutions]# ls -al | grep test.py -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py [root at 13gems global_solutions]# ls -al | grep test2.py -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py [root at 13gems global_solutions]# ls -al | grep index.py -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py [root at 13gems global_solutions]# ls -al | grep template.py -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc where test.py is identical to index.py (other than the necessary import) and template is identical to test2.py fixfiles relabel /var/www/html # might just work It didn't touch /.autorelabel # and then reboot will relabel all copied files to the correct contexts for the location I rebooted apache with no luck or you could turn off SELinux and reboot I did that and the following two solutions with no luck: echo 0 >/selinux/enforce [root at 13gems ~]# cd /etc/ [root at 13gems etc]# mv selinux/ selinux.BAK [root at 13gems etc]# mkdir selinux [root at 13gems etc]# echo 0>/selinux/enforce ...and the problem continues: [root at 13gems etc]# tail /var/log/httpd/error_log [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of script headers: index.py [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not exist: /var/www/html/angrynates.com/robots.txt [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end of script headers: index.py, referer: http://angrynates.com/global_solutions/ [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not exist: /var/www/html/angrynates.com/favicon.ico [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not exist: /var/www/html/angrynates.com/favicon.ico [root at 13gems etc]# Please help. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From baptiste.lepilleur at gmail.com Sat Nov 7 09:41:01 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sat, 7 Nov 2009 15:41:01 +0100 Subject: What is the correct way to port codecs.open to python 3.1? In-Reply-To: <4AF57213.5080203@mrabarnett.plus.com> References: <4AF57213.5080203@mrabarnett.plus.com> Message-ID: 2009/11/7 MRAB > Baptiste Lepilleur wrote: > [..] >> Do I need to replace all codecs.open with the built-in open function? If >> so, why does codecs.open still exist? >> >> The documentation says of codecs.open() that "Files are always opened in > binary mode, even if no binary mode was specified", but you've given the > mode as 'rt', so you're asking it to open the file both in text mode > _and_ binary mode. This is the same as in Python 2.6. > > If it works in 2.6 but not in 3.1, perhaps it's just that in 2.6 it > ignores the 't' whereas in 3.1 it complains. > So I did miss something, but it was in 2.6. Thanks for the clarification. Though, I think the documentation is somewhat confusing in 3.x as it says that it opens the file in binary mode, but the opened file iterator returns str not bytes... -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrholtsr at sbcglobal.net Sat Nov 7 09:44:43 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sat, 7 Nov 2009 09:44:43 -0500 Subject: Program to compute and print 1000th prime number Message-ID: <36B2917E90F0414EA90B73D7E896005F@ray> I am taking the MIT online course Introduction to Computer Science and Programming. I have a assignment to write a program to compute and print the 1000th. prime number. Can someone give me some leads on the correct code? Thanks, Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sat Nov 7 09:49:50 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 7 Nov 2009 09:49:50 -0500 Subject: Program to compute and print 1000th prime number In-Reply-To: <36B2917E90F0414EA90B73D7E896005F@ray> References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > I am taking the MIT online course Introduction to Computer Science > and Programming. I have a assignment to write a program to compute > and print the 1000th. prime number. Can someone give me some leads > on the correct code? Thanks, Ray Copying code != doing an assignment. Try Knuth. S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 09:54:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 14:54:18 GMT Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> Message-ID: <0305785b$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 10:16:58 -0600, Peng Yu wrote: > What is a list-comprehension? Time for you to Read The Fine Manual. http://docs.python.org/tutorial/index.html > I tried the following code. The list 'l' will be ['a','b','c'] rather > than ['b','c'], which is what I want. It seems 'remove' will disrupt the > iterator, right? I am wondering how to make the code correct. > > l = ['a', 'a', 'b', 'c'] > for x in l: > if x == 'a': > l.remove(x) Oh lordy, it's Shlemiel the Painter's algorithm. Please don't do that for lists with more than a handful of items. Better still, please don't do that. http://www.joelonsoftware.com/articles/fog0000000319.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:04:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:04:39 GMT Subject: Docs Typo References: <87eioghrsk.fsf@benfinney.id.au> Message-ID: <03057ac9$0$1290$c3e8da3@news.astraweb.com> On Sat, 07 Nov 2009 01:09:51 +1300, Lawrence D'Oliveiro wrote: > In message <87eioghrsk.fsf at benfinney.id.au>, Ben Finney wrote: > >> Lawrence D'Oliveiro writes: >> >>> -- ?ScrolledCavas? should >>> be ?ScrolledCanvas?. >> >> Thanks for finding and describing a fault with the Python >> documentation. This is not the right place for reporting it, though: >> this is the Python user forum, not an appropriate place for reporting >> faults. >> >> If you would like the issue to be addressed, please report it to the >> Python bug tracking system . > > What do you want, a bloody HTML patch? Just fix the damn typo, already! I tried abusing strangers on the Internet, but the typo is still there. So I tried waving my hands in the air, but the typo is still there. Then I tried chanting magical incantations, but the typo is still there. I tried kicking the dog across the room, but the typo is still there. Next I'm going to try wishing really, really hard, and if that fails I'll try abusing strangers on the Internet again, and if that still fails, well, I guess that there just is no possible way to fix typos in the Python documentation. Such a pity. If only there was, oh I don't know, a Python bug tracker or something, where one could report bugs and have them fixed. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:05:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:05:26 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: <03057af7$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 16:51:18 +0100, Marco Mariani wrote: > Using "x is y" with integers > makes no sense and has no guaranteed behaviour AFAIK Of course it makes sense. `x is y` means *exactly the same thing* for ints as it does with any other object: it tests for object identity. That's all it does, and it does it perfectly. Python makes no promise whether x = 3; y = 3 will use the same object for both x and y or not. That's an implementation detail. That's not a problem with `is`, it is a problem with developers who make unjustified assumptions. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:07:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:07:15 GMT Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <03057b64$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 18:46:33 -0800, gil_johnson wrote: > I don't have the code with me, but for huge arrays, I have used > something like: > >>>> arr[0] = initializer >>>> for i in range N: >>>> arr.extend(arr) > > This doubles the array every time through the loop, and you can add the > powers of 2 to get the desired result. Gil Why is it better to grow the list piecemeal instead of just allocating a list the size you want in one go? arr = [x]*size_wanted -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 10:14:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 15:14:10 GMT Subject: Defining re pattern for matching list of numbers References: Message-ID: <03057d03$0$1290$c3e8da3@news.astraweb.com> On Fri, 06 Nov 2009 10:16:31 -0800, Chris Rebert wrote: > Your format seems so simple I have to ask why you're using regexes in > the first place. Raymond Hettinger has described some computing techniques as "code prions" -- programming advice or techniques which are sometimes useful but often actively harmful. http://www.mail-archive.com/python-list%40python.org/msg262651.html As useful as regexes are, I think they qualify as code prions too: people insist on using them in production code, even when a simple string method or function would do the job far more efficiently and readably. -- Steven From rpjday at crashcourse.ca Sat Nov 7 10:21:40 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 10:21:40 -0500 (EST) Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Sat, 7 Nov 2009, ssteinerX at gmail.com wrote: > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > I am taking the MIT online course Introduction to Computer Science and > Programming. I have a assignment to write a program to compute and print > the 1000th. prime number. Can someone give me some leads on the correct > code? Thanks, Ray > > > Copying code != doing an assignment. ?Try Knuth. i was going to say much the same, but it's also worth pointing out that, using standard techniques, there is no straightforward way to print the n'th prime number, given some initial value of n. the ubiquitous sieve of eratosthenes requires you to pre-specify your maximum value, after which -- once the sieve completes -- all you know is that you have all of the prime numbers up to n. whether you'll have 1000 of them isn't clear, which means that you might have to start all over with a larger maximum value. (being able to directly determine the n'th prime number would solve a *lot* of prime number problems. :-) and given that one can google and, in seconds, have the solution, i feel no guilt in referring to http://code.activestate.com/recipes/366178/. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From aneeshvkulkarni at gmail.com Sat Nov 7 10:43:15 2009 From: aneeshvkulkarni at gmail.com (Aneesh Kulkarni) Date: Sat, 7 Nov 2009 07:43:15 -0800 (PST) Subject: Pyfora, a place for python References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: <92e6ede8-7437-4f96-8751-f67749e490c0@m26g2000yqb.googlegroups.com> Imagine if no one ever created anything new out of fear of "fragmenting the community". Should we hurl the same accusation at Guido for fragmenting the programmer community and creating Python, when perfectly fine languages like Perl, Lisp & Smalltalk already existed? Creating new things is a part of the natural evolution of the web ecosystem. Some of them will succeed, like Python itself did, and ultimately improve the ecosystem. New places hardly fragment the community, because at the early stages, they usually don't draw many resources away from existing communities; by the time they do, they can be valuable contributors to the larger community in their own right. Aneesh On Nov 7, 2:58?am, Saketh wrote: > On Nov 4, 5:28?pm, Alan Franzoni > wrote: > > > > > > > On 11/2/09 3:44 PM, Diez B. Roggisch wrote: > > > > Being from germany, I can say that we *have* this fragmentation, and > > > frankly: I don't like it. I prefer my communication via NNTP/ML, and not > > > with those visually rather noisy and IMHO suboptimal forums. E.g. it > > > That's right... forums, although more "accessible" to all the people who > > can't/doesn't want to use specific email or nntp clients, are quite slow > > to use. > > > But I think Ubuntu forums support threads and are kind of "channeled" > > between ML and webinterface... something like Google Groups; I think > > THAT would be a good idea. What about trying to "channel" > > comp.lang.python and a forum? > > > -- > > Alan Franzoni > > contact me at public@[mysurname].eu > > Hi everyone, > > My small effort to create a place for discussing Python seems to have > sparked a larger discussion than I had anticipated. My intent in > creatingPyforais not to splinter the community or encroach upon > comp.lang.python users, but to create an alternative location where > users can discuss Python. If this offends or irritates anyone, please > accept my humble apologies. > > I understand that forums can be degenerate and uncivil, but my hope is > that withPyfora, beginners will have a place to freely ask questions > in a genial environment. A large part of my computer upbringing was on > forums, and I wanted to share that experience with new Python users. > > Sincerely, > Saketh From david at boddie.org.uk Sat Nov 7 11:04:13 2009 From: david at boddie.org.uk (David Boddie) Date: Sat, 07 Nov 2009 17:04:13 +0100 Subject: PyQt processEvents not processing References: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> Message-ID: On Saturday 07 November 2009 05:12, DarkBlue wrote: > qt 4.5.3 > pyqt 4.6.1 > python 2.6 > > I have this QtTable widget which I want to refresh once about every 2 > seconds with new data. > > so I do : > > def updateSchedule(self): > for j in range(0,10): > doUpdate() > QtCore.processEvents() > sleep(2) > > unfortunately QT appears to wait until the for loop finishes > and only then paints the QtTable widget on the screen showing > only the latest updated result. It's difficult to know exactly why this is without more context. Calling the application's processEvents() method should give the user interface the chance to update itself, but perhaps you need to explicitly call update() on the QTableView or QTableWidget instance to ensure that it is refreshed. An alternative way to do this is to use a timer to update the table every two seconds. David From pengyu.ut at gmail.com Sat Nov 7 11:12:25 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 10:12:25 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <0305785b$0$1290$c3e8da3@news.astraweb.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <0305785b$0$1290$c3e8da3@news.astraweb.com> Message-ID: <366c6f340911070812r2d3da9f6r74dcdb29d26c1263@mail.gmail.com> On Sat, Nov 7, 2009 at 8:54 AM, Steven D'Aprano wrote: > On Fri, 06 Nov 2009 10:16:58 -0600, Peng Yu wrote: > >> What is a list-comprehension? > > Time for you to Read The Fine Manual. > > http://docs.python.org/tutorial/index.html > > >> I tried the following code. The list 'l' will be ['a','b','c'] rather >> than ['b','c'], which is what I want. It seems 'remove' will disrupt the >> iterator, right? I am wondering how to make the code correct. >> >> l = ['a', 'a', 'b', 'c'] >> for x in l: >> ? if x == 'a': >> ? ? l.remove(x) > > > Oh lordy, it's Shlemiel the Painter's algorithm. Please don't do that for > lists with more than a handful of items. Better still, please don't do > that. > > http://www.joelonsoftware.com/articles/fog0000000319.html I understand what is Shlemiel the Painter's algorithm. But if the iterator can be intelligently adjusted in my code upon 'remove()', is my code Shlemiel the Painter's algorithm? From pengyu.ut at gmail.com Sat Nov 7 11:13:52 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 10:13:52 -0600 Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <4AF4B7E8.1030807@ieee.org> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> Message-ID: <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > > > Peng Yu wrote: >> >> On Fri, Nov 6, 2009 at 10:42 AM, Robert P. J. Day >> wrote: >> >>> >>> On Fri, 6 Nov 2009, Peng Yu wrote: >>> >>> >>>> >>>> On Fri, Nov 6, 2009 at 3:05 AM, Diez B. Roggisch >>>> wrote: >>>> >>>>> >>>>> Peng Yu schrieb: >>>>> >>>>>> >>>>>> Suppose I have a list of strings, A. I want to compute the list (call >>>>>> it B) of strings that are elements of A but doesn't match a regex. I >>>>>> could use a for loop to do so. In a functional language, there is way >>>>>> to do so without using the for loop. >>>>>> >>>>> >>>>> Nonsense. For processing over each element, you have to loop over them, >>>>> either with or without growing a call-stack at the same time. >>>>> >>>>> FP languages can optimize away the stack-frame-growth (tail recursion) >>>>> - but >>>>> this isn't reducing complexity in any way. >>>>> >>>>> So use a loop, either directly, or using a list-comprehension. >>>>> >>>> >>>> What is a list-comprehension? >>>> >>>> I tried the following code. The list 'l' will be ['a','b','c'] rather >>>> than ['b','c'], which is what I want. It seems 'remove' will disrupt >>>> the iterator, right? I am wondering how to make the code correct. >>>> >>>> l ='a', 'a', 'b', 'c'] >>>> for x in l: >>>> ?if x ='a': >>>> ? ?l.remove(x) >>>> >>>> print l >>>> >>> >>> ?list comprehension seems to be what you want: >>> >>> ?l =i for i in l if i != 'a'] >>> >> >> My problem comes from the context of using os.walk(). Please see the >> description of the following webpage. Somehow I have to modify the >> list inplace. I have already tried 'dirs =i for i in l if dirs !'a']'. But >> it seems that it doesn't "prune the search". So I need the >> inplace modification of list. >> >> http://docs.python.org/library/os.html >> >> When topdown is True, the caller can modify the dirnames list in-place >> (perhaps using del or slice assignment), and walk() will only recurse >> into the subdirectories whose names remain in dirnames; this can be >> used to prune the search, impose a specific order of visiting, or even >> to inform walk() about directories the caller creates or renames >> before it resumes walk() again. Modifying dirnames when topdown is >> False is ineffective, because in bottom-up mode the directories in >> dirnames are generated before dirpath itself is generated. >> >> > > The context is quite important in this case. ?The os.walk() iterator gives > you a tuple of three values, and one of them is a list. ?You do indeed want > to modify that list, but you usually don't want to do it "in-place." ? I'll > show you the in-place version first, then show you the slice approach. > > If all you wanted to do was to remove one or two specific items from the > list, then the remove method would be good. ?So in your example, you don' t > need a loop. ?Just say: > ? if 'a' in dirs: > ? ? ? ?dirs.remove('a') > > But if you have an expression you want to match each dir against, the list > comprehension is the best answer. ?And the trick to stuffing that new list > into the original list object is to use slicing on the left side. ?The [:] > notation is a default slice that means the whole list. > > ? dirs[:] = [ item for item in dirs if ? ? bool_expression_on_item ] I suggest to add this example to the document of os.walk() to make other users' life easier. From victorsubervi at gmail.com Sat Nov 7 11:59:29 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 11:59:29 -0500 Subject: Can't Find Module Message-ID: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> Hi; I'm getting this error: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line 204, in handler module = page_cache[req] File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 82, in __getitem__ return self._checkitem(name)[2] File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 124, in _checkitem value = self.build(key, name, opened, entry) File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line 77, in build return ModuleCache.build(self, key, req, opened, entry) File "/usr/lib64/python2.4/site-packages/mod_python/cache.py", line 371, in build exec opened in module.__dict__ File "/var/www/html/angrynates.com/global_solutions/index.py", line 8, in ? from template import template ImportError: No module named template Here's the code: #!/usr/bin/python import string import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from template import template ourFile = string.split(__file__, "/") page = ourFile[len(ourFile) - 1][:-3] form = cgi.FieldStorage() w = form.getfirst('w', '1024') print page template(page, w) I can import this just fine from the python command prompt. So, what gives? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Sat Nov 7 12:23:06 2009 From: python at rcn.com (Raymond Hettinger) Date: Sat, 7 Nov 2009 09:23:06 -0800 (PST) Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > ? ? ? I am taking the MIT online course Introduction to Computer Science and > > ? ? ? Programming. I have a assignment to write a program to compute and print > > ? ? ? the 1000th. prime number. Can someone give me some leads on the correct > > ? ? ? code? Thanks, Ray Tongue in cheek solution: import urllib2 url = 'http://primes.utm.edu/lists/small/10000.txt' primes = [] for line in urllib2.urlopen(url).read().splitlines(): values = line.split() if len(values) == 10: primes.extend(values) print primes[1000-1] Raymond From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:29:58 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:29:58 +0100 Subject: how to display the return type of an os method? In-Reply-To: References: Message-ID: <4af5bc28$0$13899$426a74cc@news.free.fr> Robert P. J. Day a ?crit : > once again, a thoroughly newbie question but what's the quickest way > to display the return type of, say, os.stat()? i can obviously do > this in two steps: > >>>> x=os.stat('/etc/passwd') >>>> type(x) > > > i'd just like to see that os.stat() returns a posix.stat_result > object in one line. => type(os.stat('/etc/passwd')) But reading the doc might help too: => help(os.stat) From rpjday at crashcourse.ca Sat Nov 7 12:32:45 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 12:32:45 -0500 (EST) Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Sat, 7 Nov 2009, Raymond Hettinger wrote: > > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > > > ? ? ? I am taking the MIT online course Introduction to Computer > > > Science and ? ? ? Programming. I have a assignment to write a > > > program to compute and print ? ? ? the 1000th. prime number. Can > > > someone give me some leads on the correct ? ? ? code? Thanks, > > > Ray > > Tongue in cheek solution: > > import urllib2 > > url = 'http://primes.utm.edu/lists/small/10000.txt' > primes = [] > for line in urllib2.urlopen(url).read().splitlines(): > values = line.split() > if len(values) == 10: > primes.extend(values) > print primes[1000-1] reminds me of a variation of an old joke: using nothing but this barometer, determine the height of that building. answer: go to the building manager and say, "i'll give you this really neat barometer if you tell me how tall this building is." rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:36:08 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:36:08 +0100 Subject: exception due to NoneType In-Reply-To: References: Message-ID: <4af5bd9a$0$22506$426a74cc@news.free.fr> asit a ?crit : > In my program I want to catch exception which is caused by accessing > NoneType object. > > Can anyone suggest me how this can be done ?? Not without the minimal working code exposing your problem, or the full traceback you got. Merely "accessing NoneType object" doesn't by itself raise any exception... I suspect you get the None object where you expected something else and try to access an attribute of this 'something else', and ends up getting an AttributeError, but there are other possible scenarii that might fit your (very poor) description of the problem, so no way too help you without more informations. As a general rule, remember that the traceback is actually meant to *help* finding out what went wring. From contact at xavierho.com Sat Nov 7 12:37:48 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 8 Nov 2009 03:37:48 +1000 Subject: Program to compute and print 1000th prime number In-Reply-To: <36B2917E90F0414EA90B73D7E896005F@ray> References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <2d56febf0911070937u1114220fk140cbc4f1bfc30ed@mail.gmail.com> On Sun, Nov 8, 2009 at 12:44 AM, Ray Holt wrote: > I have a assignment to write a program to compute and print the 1000th. > prime number. Can someone give me some leads on the correct code? > Ray, if you really want an answer out of this list, you'll have to at least show us what efforts you've put into solving this problem. Perhaps if you post your code that doesn't quite work, we can make suggestions on how to improve/fix it. Other than that, it's generally considered bad karma to give any kind of code, and we need to know where you are. my 2c, Xavier -------------- next part -------------- An HTML attachment was scrubbed... URL: From half.italian at gmail.com Sat Nov 7 12:38:04 2009 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 7 Nov 2009 09:38:04 -0800 (PST) Subject: extracting info from media files References: Message-ID: <240b5019-c9d3-4a08-aee4-ec8e8924b42a@x5g2000prf.googlegroups.com> MediaInfo is your best bet. http://mediainfo.sourceforge.net/en ~Sean On Nov 6, 11:59?pm, Michele Simionato wrote: > I would like to extract some simple info from media files, such as > size, resolution, duration, codec. What's the simplest way to do it? > Once in a time there was pymedia but I see the latest release is of > February 2006. The solution should work on Linux and provide support > for a large set of video formats. From mensanator at aol.com Sat Nov 7 12:40:31 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 09:40:31 -0800 (PST) Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: On Nov 7, 11:23?am, Raymond Hettinger wrote: > > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > > ? ? ? I am taking the MIT online course Introduction to Computer Science and > > > ? ? ? Programming. I have a assignment to write a program to compute and print > > > ? ? ? the 1000th. prime number. Can someone give me some leads on the correct > > > ? ? ? code? Thanks, Ray > > Tongue in cheek solution: > > import urllib2 > > url = 'http://primes.utm.edu/lists/small/10000.txt' > primes = [] > for line in urllib2.urlopen(url).read().splitlines(): > ? ? values = line.split() > ? ? if len(values) == 10: > ? ? ? ? primes.extend(values) > print primes[1000-1] Nice, but you can do better. >>> import gmpy >>> n = 1 >>> for i in xrange(1000): n = gmpy.next_prime(n) >>> print n 7919 > > Raymond From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:43:35 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:43:35 +0100 Subject: Microsoft research on code quality In-Reply-To: References: Message-ID: <4af5bf58$0$20947$426a74cc@news.free.fr> Aahz a ?crit : > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx An interesting reading. Thanks for the link. From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 12:55:14 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 18:55:14 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: References: Message-ID: <4af5c216$0$715$426a74cc@news.free.fr> kj a ?crit : > > As I said, this is considered an optimization, at least in Perl, > because it lets the interpreter allocate all the required memory > in one fell swoop, instead of having to reallocate it repeatedly > as the array grows. IIRC, CPython has it's own way to optimize list growth. > (Of course, like with all optimizations, > whether it's worth the bother is another question.) My very humble opinion is that unless you spot a bottleneck (that is, you have real performance issues AND the profiler identified list growth as the culprit), the answer is a clear and obvious NO. > Another situation where one may want to do this is if one needs to > initialize a non-sparse array in a non-sequential order, Then use a dict. From lipun4u at gmail.com Sat Nov 7 13:06:43 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 10:06:43 -0800 (PST) Subject: exception due to NoneType Message-ID: In my program I want to catch exception which is caused by accessing NoneType object. Can anyone suggest me how this can be done ?? From solipsis at pitrou.net Sat Nov 7 13:10:24 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 7 Nov 2009 18:10:24 +0000 (UTC) Subject: What is the correct way to port codecs.open to python 3.1? References: Message-ID: Le Sat, 07 Nov 2009 12:56:54 +0100, Baptiste Lepilleur a ?crit?: > > After applying 2to3.py to port a 2.6 script to 3.1, I get the following > error when running my script: > File "purekeyworddbtest.py", line 143, in __init__ > f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') > File "c:\Python31\lib\codecs.py", line 870, in open > file = builtins.open(filename, mode, buffering) > ValueError: can't have text and binary mode at once I would suggest not using codecs.open() in 3.x, since the built-in open() will do the same thing, but faster. So just write: f = open(EXCLUDED_KEYWORDS_FILE, 'r', encoding='utf-8') and you'll get a fast file object giving you str (unicode) objects after an implicit utf-8 decoding of file data. Regards Antoine. From rpjday at crashcourse.ca Sat Nov 7 13:12:27 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:12:27 -0500 (EST) Subject: how to display the return type of an os method? Message-ID: once again, a thoroughly newbie question but what's the quickest way to display the return type of, say, os.stat()? i can obviously do this in two steps: >>> x=os.stat('/etc/passwd') >>> type(x) >>> i'd just like to see that os.stat() returns a posix.stat_result object in one line. how dumb a question is that? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From jjposner at optimum.net Sat Nov 7 13:18:18 2009 From: jjposner at optimum.net (John Posner) Date: Sat, 07 Nov 2009 13:18:18 -0500 Subject: Program to compute and print 1000th prime number In-Reply-To: References: Message-ID: <4AF5B9EA.2070307@optimum.net> Robert P. J. Day said: > the ubiquitous sieve of eratosthenes requires you to pre-specify > your maximum value, after which -- once the sieve completes -- all you > know is that you have all of the prime numbers up to n. whether > you'll have 1000 of them isn't clear, which means that you might have > to start all over with a larger maximum value. (being able to > directly determine the n'th prime number would solve a *lot* of prime > number problems. :-) > > In April of this year, members of this forum helped me to devise a prime-number iterator [1]. So here's a simple solution for the OP: #--------------- from itertools import ifilter, count # create iterator prime_iter = ifilter( lambda n, P=[]: all(n%p for p in P) and not P.append(n), count(2)) # throw away lots of primes for i in range(999): prime_iter.next() # here's the one we want print prime_iter.next() #7919 #--------------- I don't think this is a solution that a course instructor would expect, though! As mentioned in [1], optimizations of this algorithm (using itertools.takewhile() and/or caching previously-computed squares) are still at cl1p.net [2]. -John [1] http://mail.python.org/pipermail/python-list/2009-April/177415.html [2] http://www.cl1p.net/python_prime_generators From rpjday at crashcourse.ca Sat Nov 7 13:20:47 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:20:47 -0500 (EST) Subject: What is the best way to delete strings in a string list that that match certain pattern? In-Reply-To: <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> Message-ID: On Sat, 7 Nov 2009, Peng Yu wrote: > On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > > But if you have an expression you want to match each dir against, > > the list comprehension is the best answer. ?And the trick to > > stuffing that new list into the original list object is to use > > slicing on the left side. ?The [:] notation is a default slice > > that means the whole list. > > > > ? dirs[:] = [ item for item in dirs if ? ? bool_expression_on_item ] > > I suggest to add this example to the document of os.walk() to make > other users' life easier. huh? why do you need the slice notation on the left? why can't you just assign to "dirs" as opposed to "dirs[:]"? using the former seems to work just fine. is this some kind of python optimization or idiom? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From andreengels at gmail.com Sat Nov 7 13:34:47 2009 From: andreengels at gmail.com (Andre Engels) Date: Sat, 7 Nov 2009 19:34:47 +0100 Subject: Program to compute and print 1000th prime number In-Reply-To: References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <6faf39c90911071034y3723541btfdfc684bc6ec771b@mail.gmail.com> On Sat, Nov 7, 2009 at 6:40 PM, Mensanator wrote: >> Tongue in cheek solution: >> >> import urllib2 >> >> url = 'http://primes.utm.edu/lists/small/10000.txt' >> primes = [] >> for line in urllib2.urlopen(url).read().splitlines(): >> ? ? values = line.split() >> ? ? if len(values) == 10: >> ? ? ? ? primes.extend(values) >> print primes[1000-1] > > Nice, but you can do better. > >>>> import gmpy >>>> n = 1 >>>> for i in xrange(1000): > ? ? ? ?n = gmpy.next_prime(n) >>>> print n > 7919 With the help of the solutions given so far, I can do even better than that: n = 7919 print n -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Sat Nov 7 13:47:41 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Nov 2009 19:47:41 +0100 Subject: What is the best way to delete strings in a string list that that match certain pattern? References: <7li76qF3cq9l0U1@mid.uni-berlin.de> <366c6f340911060816r7ce91d31j2d9476831158916@mail.gmail.com> <366c6f340911060858r139a50c7xb64a8f7a732529e5@mail.gmail.com> <4AF4B7E8.1030807@ieee.org> <366c6f340911070813n41e6705byd28df500388aff4e@mail.gmail.com> Message-ID: Robert P. J. Day wrote: > On Sat, 7 Nov 2009, Peng Yu wrote: > >> On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > >> > But if you have an expression you want to match each dir against, >> > the list comprehension is the best answer. And the trick to >> > stuffing that new list into the original list object is to use >> > slicing on the left side. The [:] notation is a default slice >> > that means the whole list. >> > >> > dirs[:] = [ item for item in dirs if bool_expression_on_item ] >> >> I suggest to add this example to the document of os.walk() to make >> other users' life easier. > > huh? why do you need the slice notation on the left? why can't you > just assign to "dirs" as opposed to "dirs[:]"? using the former seems > to work just fine. is this some kind of python optimization or idiom? dirs = [...] rebinds the name "dirs" while dirs[:] = [...] updates the contents of the list currently bound to the "dirs" name. The latter is necessary in the context of os.walk() because it yields a list of subdirectories, gives the user a chance to update it and than uses this potentially updated list to decide which subdirectories to descend into. A simplified example: >>> def f(): ... items = ["a", "b", "c"] ... yield items ... print items ... >>> for items in f(): ... items = ["x", "y"] ... ['a', 'b', 'c'] >>> for items in f(): ... items[:] = ["x", "y"] ... ['x', 'y'] Peter From rpjday at crashcourse.ca Sat Nov 7 13:50:19 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 13:50:19 -0500 (EST) Subject: how to display the return type of an os method? In-Reply-To: <4af5bc28$0$13899$426a74cc@news.free.fr> References: <4af5bc28$0$13899$426a74cc@news.free.fr> Message-ID: On Sat, 7 Nov 2009, Bruno Desthuilliers wrote: > Robert P. J. Day a ?crit : > > once again, a thoroughly newbie question but what's the quickest way > > to display the return type of, say, os.stat()? i can obviously do > > this in two steps: > > > >>>> x=os.stat('/etc/passwd') > >>>> type(x) > > > > > > i'd just like to see that os.stat() returns a posix.stat_result > > object in one line. > > => type(os.stat('/etc/passwd')) > > But reading the doc might help too: > > => help(os.stat) never mind, i realize now it was a dumb question since the return type is based on the routine logic, of course. argh. carry on. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From lipun4u at gmail.com Sat Nov 7 14:08:18 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 11:08:18 -0800 (PST) Subject: exception due to NoneType References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: On Nov 7, 10:36?pm, Bruno Desthuilliers wrote: > asit a ?crit : > > > In my program I want to catch exception which is caused by accessing > > NoneType object. > > > Can anyone suggest me how this can be done ?? > > Not without the minimal working code exposing your problem, or the full > traceback you got. Merely "accessing NoneType object" doesn't by itself > raise any exception... I suspect you get the None object where you > expected something else and try to access an attribute of this > 'something else', and ends up getting an AttributeError, but there are > other possible scenarii that might fit your (very poor) description of > the problem, so no way too help you without more informations. As a > general rule, remember that the traceback is actually meant to *help* > finding out what went wring. I could have described the error, but the problem is that it's dependent of a third party library.. Let me write the code here... import twitter api = twitter.Api('asitdhal','swordfish') users = api.GetFriends() for s in users: print print "##########################################" try: print "user id : " + str(s.id) print "user name : " + s.name print "user location : " + s.location print "user description : " + s.description print "user profile image url : " + s.profile_image_url print "user url : " + s.url print "user status : " + str(s.status) except TypeError: pass look at the except TypeError. This is supposed to catch only exception thrown by NoneType. please help me. From lipun4u at gmail.com Sat Nov 7 14:24:20 2009 From: lipun4u at gmail.com (asit) Date: Sat, 7 Nov 2009 11:24:20 -0800 (PST) Subject: database handling Message-ID: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> I need some tutorial about python-mysql connectivity(database handling). Somebody please help me !! From kyrie at uh.cu Sat Nov 7 14:25:19 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Sat, 07 Nov 2009 14:25:19 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <4af5c216$0$715$426a74cc@news.free.fr> References: <4af5c216$0$715$426a74cc@news.free.fr> Message-ID: <1257621919.4af5c99fcd1f6@mail.uh.cu> Quoting Bruno Desthuilliers : > > Another situation where one may want to do this is if one needs to > > initialize a non-sparse array in a non-sequential order, > > Then use a dict. Ok, he has a dict. Now what? He needs a non-sparse array. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From andreengels at gmail.com Sat Nov 7 14:33:29 2009 From: andreengels at gmail.com (Andre Engels) Date: Sat, 7 Nov 2009 20:33:29 +0100 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <1257621919.4af5c99fcd1f6@mail.uh.cu> References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> Message-ID: <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez wrote: > > Quoting Bruno Desthuilliers : > >> > Another situation where one may want to do this is if one needs to >> > initialize a non-sparse array in a non-sequential order, >> >> Then use a dict. > > Ok, he has a dict. > > Now what? He needs a non-sparse array. Let d be your dict. Call the zeroeth place in your array d[0], the first d[1], the 10000th d[100000]. -- Andr? Engels, andreengels at gmail.com From tjreedy at udel.edu Sat Nov 7 15:31:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 15:31:02 -0500 Subject: is None or == None ? In-Reply-To: <03057af7$0$1290$c3e8da3@news.astraweb.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <03057af7$0$1290$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 06 Nov 2009 16:51:18 +0100, Marco Mariani wrote: > >> Using "x is y" with integers >> makes no sense and has no guaranteed behaviour AFAIK > > Of course it makes sense. `x is y` means *exactly the same thing* for > ints as it does with any other object: it tests for object identity. > That's all it does, and it does it perfectly. > > Python makes no promise whether x = 3; y = 3 will use the same object for > both x and y or not. That's an implementation detail. That's not a > problem with `is`, it is a problem with developers who make unjustified > assumptions. Which is to say, it normally makes no sense to write 'm is n' for m, n ints. The *exception* is when one is exploring implementation details, either to discover them or to test that they are as intended. So, last I looked, the test suite for ints makes such tests. If the implementation changes, the test should change also. The problem comes when newbies use 'is' without realizing that they are doing black-box exploration of otherwise irrelevant internals. (White-box exploration would be reading the code, which makes it plain what is going on ;-). Terry Jan Reedy From tjreedy at udel.edu Sat Nov 7 15:39:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 15:39:50 -0500 Subject: Pyfora, a place for python In-Reply-To: References: <0ee5e065-ea9e-4fe1-84da-51adbb8b2883@z41g2000yqz.googlegroups.com> <87my36my79.fsf@benfinney.id.au> <7l89j4F3bl107U1@mid.uni-berlin.de> Message-ID: Saketh wrote: > On Nov 4, 5:28 pm, Alan Franzoni > My small effort to create a place for discussing Python seems to have > sparked a larger discussion than I had anticipated. My intent in > creating Pyfora is not to splinter the community or encroach upon > comp.lang.python users, but to create an alternative location where > users can discuss Python. If this offends or irritates anyone, please > accept my humble apologies. > > I understand that forums can be degenerate and uncivil, but my hope is > that with Pyfora, beginners will have a place to freely ask questions > in a genial environment. A large part of my computer upbringing was on > forums, and I wanted to share that experience with new Python users. I have no problem with efforts to create something new and different. I am curious whether you were or have become aware of http://www.python-forum.org/pythonforum/index.php It seems to already do what you intended to do, so if you want to continue, you might think of how to differentiate PyFora. Terry Jan Reedy From kyrie at uh.cu Sat Nov 7 15:40:02 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Sat, 07 Nov 2009 15:40:02 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: <1257626402.4af5db225e233@mail.uh.cu> Quoting Andre Engels : > On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez > wrote: > > > > Ok, he has a dict. > > > > Now what? He needs a non-sparse array. > > Let d be your dict. > > Call the zeroeth place in your array d[0], the first d[1], the 10000th > d[100000]. Following that reasoning, we could get rid of lists and arrays altogether. Here's why that wouldn't work: for x,y in zip(d,other): ... do something ... Yes, we could also ignore zip and just use range/xrange to iterate for the indices... Lists and dictionaries have different semantics. One thing is to argue that you shouldn't be thinking on pre-growing a list for performance reasons before being sure that it is a bottleneck, and a very different one is to argue that because one operation (__setitem__) is the same with both structures, we should not use lists for what may need, depending on the problem, list semantics. ?Have you ever tried to read list/matrix that you know it is not sparse, but you don't know the size, and it may not be in order? A "grow-able" array would just be the right thing to use - currently I have to settle with either hacking together my own grow-able array, or preloading the data into a dict, growing a list with the [0]*size trick, and updating that list. Not hard, not worthy of a PEP, but certainly not so easy to dismiss. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From partofthething at gmail.com Sat Nov 7 15:51:32 2009 From: partofthething at gmail.com (Nick Touran) Date: Sat, 7 Nov 2009 12:51:32 -0800 Subject: database handling In-Reply-To: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> References: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> Message-ID: <6de163580911071251i2f97213bx58fde9f88e734323@mail.gmail.com> The mysqldb module works well for me. It's available on sourceforge. Find some examples in the documentation here: http://mysql-python.sourceforge.net/MySQLdb.html#some-mysql-examples -Nick On Sat, Nov 7, 2009 at 11:24 AM, asit wrote: > I need some tutorial about python-mysql connectivity(database > handling). > > Somebody please help me !! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 7 16:00:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 16:00:20 -0500 Subject: imputil.py, is this a bug ? In-Reply-To: <4AF54413.9080502@gmail.com> References: <4AF49631.8090003@gmail.com> <4AF54413.9080502@gmail.com> Message-ID: Stef Mientki wrote: > Gabriel Genellina wrote: >> En Fri, 06 Nov 2009 18:33:37 -0300, Stef Mientki >> escribi?: >> >>> I get an error compiling with pyjamas, in the standard module >>> imputil, _import_top_module >> >> Note that imputil is undocumented in 2.5, deprecated in 2.6 and >> definitively gone in 3.0 It was deprecated because it is buggy and unmaintainable. In 3.1 it has been replaced with the new written-in-Python importlib. That has also been added to the upcoming 2.7. Anyone using imputil and having problems with it should try the 2.7 version of importlib and see if it runs well-enough on earlier versions. Terry Jan Reedy From rami.chowdhury at gmail.com Sat Nov 7 16:09:39 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 7 Nov 2009 13:09:39 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> Message-ID: <200911071309.40437.rami.chowdhury@gmail.com> On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > I have a serious privileges problem that is making it impossible to serve > python pages on a CentOS server. It appears that nobody on the CentOS > discussion list has a solution to this problem. I'm desperate and hoping > someone on this list can help. > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > > Now, the file does exist: > > [root at 13gems global_solutions]# pwd > /var/www/html/angrynates.com/global_solutions > [root at 13gems global_solutions]# ls > .... > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > .... > and it serves just fine on another server, so there is no "premature end of > script headers". > > > Here's where it gets really weird. If I copy the code for index.py and > template.py which the former calls, and create files test.py and test2.py > and paste the code from the former files in those new files changing only > the import statement from "template" to "test2", the tests will resolve!! > Now, the ownership and mode are identical on all of them!! > > > [root at 13gems global_solutions]# ls -al | grep test.py > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > [root at 13gems global_solutions]# ls -al | grep test2.py > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > [root at 13gems global_solutions]# ls -al | grep index.py > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > [root at 13gems global_solutions]# ls -al | grep template.py > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > where test.py is identical to index.py (other than the necessary import) > and template is identical to test2.py > > > fixfiles relabel /var/www/html > # might just work > It didn't > > touch /.autorelabel > # and then reboot will relabel all copied files to the correct contexts for > the location > I rebooted apache with no luck > > or you could turn off SELinux and reboot > I did that and the following two solutions with no luck: > echo 0 >/selinux/enforce > > [root at 13gems ~]# cd /etc/ > [root at 13gems etc]# mv selinux/ selinux.BAK > [root at 13gems etc]# mkdir selinux > [root at 13gems etc]# echo 0>/selinux/enforce > > ...and the problem continues: > [root at 13gems etc]# tail /var/log/httpd/error_log > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file or > directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' > failed > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of > script headers: index.py > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > exist: /var/www/html/angrynates.com/robots.txt > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file > or directory: exec of > '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: > http://angrynates.com/global_solutions/ > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end of > script headers: index.py, referer: http://angrynates.com/global_solutions/ > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [root at 13gems etc]# > > Please help. > Victor > Can we see the output of 'ls -lZ' and 'fixfiles check' on those directories, and see what the Apache (httpd.conf or .htaccess) configuration is for them? ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From tjreedy at udel.edu Sat Nov 7 16:13:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 16:13:46 -0500 Subject: imputil.py, is this a bug ? In-Reply-To: References: <4AF49631.8090003@gmail.com> Message-ID: lkcl wrote: > On Nov 7, 2:20 am, "Gabriel Genellina" wrote: >> Yes, seems to be a bug. But given the current status of imputil, it's not >> likely to be fixed; certainly not in 2.5 which only gets security fixes >> now. > > well, that bug's not the only one. the other one that i found, which > i have been specifically ordered not to report Imputil has been deprecated and has in 3.1 and will-be in 2.7 replaced by importlib, written in Python. So reporting more bugs in imputil is rather useless noise. So either use your patched version or try shifting to the 2.7 importlib and see if it runs well enough on earlier versions. >(that or _any_ python bugs, of which there have been several discovered in the past eight > months), will have to wait until the python developers rescind that > order. Without seeing documentary proof, I am dubious that you have been ordered to not properly report bugs in supported, not deprecated, modules. If really so, post reports here and interested parties can try to verify and possibly report them themselves. I, for instance, would be interested in 3.1 bugs that do not require outside resources to verify. Terry Jan Reedy From vicente.soler at gmail.com Sat Nov 7 16:39:07 2009 From: vicente.soler at gmail.com (vsoler) Date: Sat, 7 Nov 2009 13:39:07 -0800 (PST) Subject: My own accounting python euler problem Message-ID: In the accounting department I am working for we are from time to time confronted to the following problem: A customer sends us a check for a given amount, but without specifying what invoices it cancels. It is up to us to find out which ones the payment corresponds to. For example, say that the customer has the following outstanding invoices: $300, $200, $50; and say that the check is for $250. This time it is clear, the customer is paying bills $200 and $50. However, let's now say that the outstanding invoices are $300, $200, $100 and that the check is for $300. In this case there are already two possibilities. The customer is paying the $300 invoice or the $200 and $100. In other words, there is more than one solution to the problem. My first question is: 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a check Ch=600 how can I print all the different combinations of invoices that the check is possibly cancelling 1.a. first approach using "brute force", that is, exploring all different combinations: every single invoice, all of 2-element tuples, 3-element tuples, etc... 1.b can all the solutions be found without exploring all possible combinations? some problems can be solved by discarding some invoices, for example those whose amounts are greater than the amount of the check. Any ideas? My second question is: 2. this time there are also credit notes outstanding, that is, invoices with negative amounts. For example, I=[500, 400, -100, 450, 200, 600, -200, 700] and a check Ch=600 2.a is the "brute force" method used in 1.a still applicable now that "I" contains negative values? 2.b same as 1.b. However, this time I can imagen that the number of invoices that can be discarded is a lot more reduced. I am a fan of Python, which I find very elegant, powerful and easy to develop with. I would like to find answers to the problems described above, partially because I am still learning python, and I would like to make use of it. Can anybody help? From jackdied at gmail.com Sat Nov 7 16:45:15 2009 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 7 Nov 2009 16:45:15 -0500 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, Nov 7, 2009 at 4:39 PM, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. [big snip] http://en.wikipedia.org/wiki/Knapsack_problem Unless your customers are giant defense contractors you should be able to brute force a solution. If they are so big that it doesn't take micro seconds to brute force a solution then you probably have more problems than just matching checks to invoices... -Jack From rpjday at crashcourse.ca Sat Nov 7 16:47:36 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 16:47:36 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: 1. given a list of invoives I=[500, 400, 450, > 200, 600, 700] and a check Ch=600 how can I print all the different > combinations of invoices that the check is possibly cancelling that sounds like the classic knapsack problem: http://www.itl.nist.gov/div897/sqg/dads/HTML/knapsackProblem.html it's NP-complete. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From victorsubervi at gmail.com Sat Nov 7 16:51:06 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 7 Nov 2009 16:51:06 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911071309.40437.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> httpd.conf: ServerAdmin me at creative.vi DocumentRoot /var/www/html/angrynates.com ServerName angrynates.com Options +ExecCGI -IncludesNoExec Options +ExecCGI AllowOverride Options AllowOverride FileInfo #AddHandler mod_python .py #PythonHandler mod_python.publisher #PythonDebug On #ls -lZ drwxr-xr-x root root 1024 drwxr-xr-x root root 1132 drwxr-xr-x root root 1255 -rwxr-xr-x root root About_Us_frame.py -rwxr-xr-x root root About_Us.py -rwxr-xr-x root root ajax.cgi.txt -rwxr-xr-x root root ajax.html -rwxr-xr-x root root Catalog_frame.py -rwxr-xr-x root root Catalog.py -rwxr-xr-x root root cats_edit2.py -rwxr-xr-x root root cats_edit.py -rwxr-xr-x root root client2.py -rwxr-xr-x root root client_delete2.py -rwxr-xr-x root root client_delete.py -rwxr-xr-x root root client_edit2.py -rwxr-xr-x root root client_edit3.py -rwxr-xr-x root root client_edit.py -rwxr-xr-x root root client.py -rwxr-xr-x root root Contact_Us_frame.py -rwxr-xr-x root root Contact_Us.py -rwxr-xr-x root root credit_app.doc -rwxr-xr-x root root Credit Application DP Dist .doc -rwxr-xr-x root root Customer_Templates_frame.py -rwxr-xr-x root root Customer_Templates.py -rwxr-xr-x root root display_spreadsheet2.py -rwxr-xr-x root root display_spreadsheet.py -rwxr-xr-x root root EDDIE-Tool-1.0.0.tar.gz -rwxr-xr-x root root email.py -rwxr-xr-x root root error.log.0 -rwxr-xr-x root root favicon.gif -rwxr-xr-x root root favicon.ico -rwxr-xr-x root root Forms_frame.py -rwxr-xr-x root root Forms.py -rwxr-xr-x root root fw9.pdf -rwxr-xr-x root root getResolution.py -rw-r--r-- root root hello.py drwxr-xr-x root root images drwxr-xr-x root root images1024 drwxr-xr-x root root images1132 drwxr-xr-x root root images1255 drwxr-xr-x root root images-old -rwxr-xr-x root root index_frame.py -rwxr-xr-x root root index.html -rwxr-xr-x root root index.py -rwxr-xr-x root root login.py -rwxr-xr-x root root login.pyc -rwxr-xr-x root root Office_Supplies_frame.py -rwxr-xr-x root root Office_Supplies.py -rwxr-xr-x root root Paper_Plastics_frame.py -rwxr-xr-x root root Paper_Plastics.py -rwxr-xr-x root root particulars.py -rwxr-xr-x root root particulars.pyc drwxr-xr-x root root pics -rwxr-xr-x root root ping.py -rwxr-xr-x root root products2.py -rwxr-xr-x root root products3.py -rwxr-xr-x root root products_cats.py -rwxr-xr-x root root products_delete2.py -rwxr-xr-x root root products_delete3.py -rwxr-xr-x root root products_delete.py -rwxr-xr-x root root products_edit2.py -rwxr-xr-x root root products_edit3.py -rwxr-xr-x root root products_edit.py -rwxr-xr-x root root products_items.py -rwxr-xr-x root root products_move2.py -rwxr-xr-x root root products_move3.py -rwxr-xr-x root root products_move.py -rwxr-xr-x root root salesperson2.py -rwxr-xr-x root root salesperson_delete2.py -rwxr-xr-x root root salesperson_delete.py -rwxr-xr-x root root salesperson_edit2.py -rwxr-xr-x root root salesperson_edit3.py -rwxr-xr-x root root salesperson_edit.py -rwxr-xr-x root root salesperson.py drwxr-xr-x root root simplemail -rwxr-xr-x root root spreadsheet2.py -rwxr-xr-x root root spreadsheet3.py -rwxr-xr-x root root spreadsheet4.py -rwxr-xr-x root root spreadsheet_delete2.py -rwxr-xr-x root root spreadsheet_delete.py -rwxr-xr-x root root spreadsheet_delete_rows2.py -rwxr-xr-x root root spreadsheet_delete_rows3.py -rwxr-xr-x root root spreadsheet_delete_rows.py -rwxr-xr-x root root spreadsheet_edit2.py -rwxr-xr-x root root spreadsheet_edit3.py -rwxr-xr-x root root spreadsheet_edit.py -rwxr-xr-x root root spreadsheet.py drwxr-xr-x root root spreadsheets -rwxr-xr-x root root start.py -rwxr-xr-x root root stuff.txt -rwxr-xr-x root root templateFrame.py -rwxr-xr-x root root templateFrame.pyc -rwxr-xr-x root root template.py -rwxrwxrwx root root template.pyc -rwxr-xr-x root root test2.py -rw-r--r-- root root test2.pyc -rwxr-xr-x root root test.html -rwxr-xr-x root root test.py -rwxr-xr-x root root tsd_sales_tax_dealer_or_purchaser_exemption_certificate_st5.pdf On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury wrote: > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > I have a serious privileges problem that is making it impossible to serve > > python pages on a CentOS server. It appears that nobody on the CentOS > > discussion list has a solution to this problem. I'm desperate and hoping > > someone on this list can help. > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > > > Now, the file does exist: > > > > [root at 13gems global_solutions]# pwd > > /var/www/html/angrynates.com/global_solutions > > [root at 13gems global_solutions]# ls > > .... > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > .... > > and it serves just fine on another server, so there is no "premature end > of > > script headers". > > > > > > Here's where it gets really weird. If I copy the code for index.py and > > template.py which the former calls, and create files test.py and test2.py > > and paste the code from the former files in those new files changing only > > the import statement from "template" to "test2", the tests will resolve!! > > Now, the ownership and mode are identical on all of them!! > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > [root at 13gems global_solutions]# ls -al | grep test2.py > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > [root at 13gems global_solutions]# ls -al | grep index.py > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > [root at 13gems global_solutions]# ls -al | grep template.py > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > where test.py is identical to index.py (other than the necessary import) > > and template is identical to test2.py > > > > > > fixfiles relabel /var/www/html > > # might just work > > It didn't > > > > touch /.autorelabel > > # and then reboot will relabel all copied files to the correct contexts > for > > the location > > I rebooted apache with no luck > > > > or you could turn off SELinux and reboot > > I did that and the following two solutions with no luck: > > echo 0 >/selinux/enforce > > > > [root at 13gems ~]# cd /etc/ > > [root at 13gems etc]# mv selinux/ selinux.BAK > > [root at 13gems etc]# mkdir selinux > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > ...and the problem continues: > > [root at 13gems etc]# tail /var/log/httpd/error_log > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such file > or > > directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' > > failed > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end of > > script headers: index.py > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > > exist: /var/www/html/angrynates.com/robots.txt > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such file > > or directory: exec of > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > referer: > > http://angrynates.com/global_solutions/ > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end > of > > script headers: index.py, referer: > http://angrynates.com/global_solutions/ > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > > exist: /var/www/html/angrynates.com/favicon.ico > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > > exist: /var/www/html/angrynates.com/favicon.ico > > [root at 13gems etc]# > > > > Please help. > > Victor > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > directories, > and see what the Apache (httpd.conf or .htaccess) configuration is for > them? > > ---- > Rami Chowdhury > "Passion is inversely proportional to the amount of real information > available." -- Benford's Law of Controversy > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 17:02:53 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 23:02:53 +0100 Subject: exception due to NoneType In-Reply-To: References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <4af5fc1f$0$400$426a74cc@news.free.fr> asit a ?crit : > On Nov 7, 10:36 pm, Bruno Desthuilliers > wrote: >> asit a ?crit : >> >>> In my program I want to catch exception which is caused by accessing >>> NoneType object. >>> Can anyone suggest me how this can be done ?? >> Not without the minimal working code exposing your problem, or the full >> traceback you got. Merely "accessing NoneType object" doesn't by itself >> raise any exception... I suspect you get the None object where you >> expected something else and try to access an attribute of this >> 'something else', and ends up getting an AttributeError, but there are >> other possible scenarii that might fit your (very poor) description of >> the problem, so no way too help you without more informations. As a >> general rule, remember that the traceback is actually meant to *help* >> finding out what went wring. > > I could have described the error, but the problem is that it's > dependent of a third party library.. This more often than not translates to "dependent of a wrong use of a 3rd part library". > Let me write the code here... > > import twitter > > api = twitter.Api('asitdhal','swordfish') I hope this is not your actual login. > users = api.GetFriends() > for s in users: > print > print "##########################################" > try: > print "user id : " + str(s.id) Please learn to use print and string formatting. Here are two ways to get rid of the need to use str(): 1/ print "user id : %s" % s.id 2/ print "user id : ", s.id > print "user name : " + s.name > print "user location : " + s.location > print "user description : " + s.description > print "user profile image url : " + s.profile_image_url > print "user url : " + s.url > print "user status : " + str(s.status) > except TypeError: > pass Silently passing exception is 99.999 out of 100 a very stupid thing to do. > > look at the except TypeError. Yes, I've seen it. It's stupid, and actually make debugging harder. Any statement in this try block could raise a TypeError if the looked up attribute of 's' is not a string. Python is NOT php, and will not happily adds apples and parrots - you can only concatenate strings with strings, not with ints or None or whatever... > This is supposed to catch only exception > thrown by NoneType. Please get your facts straight. 1/ The NoneType doesn't "throw" (the appropriate python term is "raise") any exception by itself 2/ this except clause will catch any TypeError. Try this: try: x = "aaa" + 42 except TypeError, e: print "This has nothing to do with NoneType" > please help me. Help yourself and read the FineManual. Then make appropriate use of string formatting (your best friend for simple formatted outputs) instead of useless string concatenations. From bdesth.quelquechose at free.quelquepart.fr Sat Nov 7 17:04:34 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 07 Nov 2009 23:04:34 +0100 Subject: database handling In-Reply-To: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> References: <7ea50447-c627-4a0e-854e-bfb7b9fe1158@k17g2000yqh.googlegroups.com> Message-ID: <4af5fc83$0$400$426a74cc@news.free.fr> asit a ?crit : > I need some tutorial about python-mysql connectivity(database > handling). > > Somebody please help me !! You didn't search very far, did you ? http://wiki.python.org/moin/DatabaseProgramming/ From rpjday at crashcourse.ca Sat Nov 7 17:13:11 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sat, 7 Nov 2009 17:13:11 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > check Ch=600 > how can I print all the different combinations of invoices that the > check is possibly cancelling by the way, there's a bit more to it than just seeing if you can match the cheque amount exactly. some python solutions are here: http://rosettacode.org/wiki/Knapsack_Problem and a general solution allows you to place different "values" on which items you pack into your knapsack. say a customer has outstanding invoices for 200, 400 and 600, and you get a cheque for 600. what do you apply that against? the single invoice for 600, or the two for 200 and 400? that depends. if all invoices have the same "value", it won't matter. but if the invoice for 600 just went out, while the two others are just about to become, say, overdue so that a penalty is about to be applied, your customer would probably *really* appreciate it if you applied that cheque to the older invoices. in general, then, you can not only see what matches exactly but, for the sake of your customer, you can give higher value to paying off older invoices. that's how the general knapsack problem works. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From deets at nospam.web.de Sat Nov 7 17:16:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 07 Nov 2009 23:16:28 +0100 Subject: exception due to NoneType In-Reply-To: References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <7lm9tsF3ds91uU1@mid.uni-berlin.de> > api = twitter.Api('asitdhal','swordfish') You just gave the world the account-information to your twitter-account. You'd rather change these asap, or somebody hijacks your account... Diez From tjreedy at udel.edu Sat Nov 7 17:19:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 07 Nov 2009 17:19:20 -0500 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <03057b64$0$1290$c3e8da3@news.astraweb.com> References: <03057b64$0$1290$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 06 Nov 2009 18:46:33 -0800, gil_johnson wrote: > >> I don't have the code with me, but for huge arrays, I have used >> something like: >> >>>>> arr[0] = initializer >>>>> for i in range N: >>>>> arr.extend(arr) >> This doubles the array every time through the loop, and you can add the >> powers of 2 to get the desired result. Gil > > Why is it better to grow the list piecemeal instead of just allocating a > list the size you want in one go? It isn't. > arr = [x]*size_wanted Is what I would do. From sturlamolden at yahoo.no Sat Nov 7 17:22:28 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:22:28 -0800 (PST) Subject: is None or == None ? References: Message-ID: On 6 Nov, 14:35, "Alf P. Steinbach" wrote: > As I understand it, 'is' will always work and will always be efficient (it just > checks the variable's type), while '==' can depend on the implementation of > equality checking for the other operand's class. '==' checks for logical equality. 'is' checks for object identity. None is a singleton of type NoneType. Since None evaluates to True only when compared against itself, it is safe to use both operators. From ivan.illarionov at gmail.com Sat Nov 7 17:24:15 2009 From: ivan.illarionov at gmail.com (Ivan Illarionov) Date: Sat, 7 Nov 2009 14:24:15 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <622d92f9-b930-443c-82cd-0773780b1320@t2g2000yqn.googlegroups.com> On Nov 6, 3:12?pm, kj wrote: > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? It is the most efficient SAFE way to achieve this result. In fact, there IS the more efficient way, but it's dangerous, unsafe, unpythonic and plain evil: >>> import ctypes >>> ctypes.pythonapi.PyList_New.restype = ctypes.py_object >>> ctypes.pythonapi.PyList_New(100) -- Ivan From sturlamolden at yahoo.no Sat Nov 7 17:27:05 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:27:05 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On 6 Nov, 18:28, "Alf P. Steinbach" wrote: > Dynamic allocation isn't hare-brained, but doing it for every stored integer > value outside a very small range is, because dynamic allocation is (relatively > speaking, in the context of integer operations) very costly even with a > (relatively speaking, in the context of general dynamic allocation) very > efficient small-objects allocator - here talking order(s) of magnitude. When it matters, we use NumPy and/or Cython. From henk at pa3btl.demon.nl Sat Nov 7 17:27:15 2009 From: henk at pa3btl.demon.nl (van Asselt) Date: Sat, 7 Nov 2009 23:27:15 +0100 Subject: Command parsing... best module to use? References: <94dbc92b-0682-4995-b358-0c615c95a27a@x6g2000prc.googlegroups.com> Message-ID: <4af5f44c$0$83239$e4fe514c@news.xs4all.nl> Hello Colin, I have been using 'cmdloop.py' from Crutcher Dunnavant in a few programs.... See http://py-cmdloop.googlecode.com/svn/trunk/cmdloop.py Regards, Henk --------------------- "Collin D" wrote in message news:94dbc92b-0682-4995-b358-0c615c95a27a at x6g2000prc.googlegroups.com... > Hey everyone. > > I am writing a game in python, and it includes a text console somewhat > like the one in WoW and Runescape. I want to be able to include "/" > commands, like IRC, and was wondering what the best module would be to > parse these. > > Thanks a lot, > Collin D From wbrehaut at mcsnet.ca Sat Nov 7 17:43:13 2009 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Sat, 07 Nov 2009 15:43:13 -0700 Subject: Program to compute and print 1000th prime number References: <36B2917E90F0414EA90B73D7E896005F@ray> Message-ID: <9vtbf510qrsl09conn773hal8jo7bttpa0@4ax.com> On Sat, 7 Nov 2009 19:34:47 +0100, Andre Engels wrote: >On Sat, Nov 7, 2009 at 6:40 PM, Mensanator wrote: > >>> Tongue in cheek solution: >>> >>> import urllib2 >>> >>> url = 'http://primes.utm.edu/lists/small/10000.txt' >>> primes = [] >>> for line in urllib2.urlopen(url).read().splitlines(): >>> ? ? values = line.split() >>> ? ? if len(values) == 10: >>> ? ? ? ? primes.extend(values) >>> print primes[1000-1] >> >> Nice, but you can do better. >> >>>>> import gmpy >>>>> n = 1 >>>>> for i in xrange(1000): >> ? ? ? ?n = gmpy.next_prime(n) >>>>> print n >> 7919 > >With the help of the solutions given so far, I can do even better than that: > >n = 7919 >print n >>> 7919 7919 ? From ubershmekel at gmail.com Sat Nov 7 17:45:31 2009 From: ubershmekel at gmail.com (Yuv) Date: Sat, 7 Nov 2009 14:45:31 -0800 (PST) Subject: feedback on function introspection in argparse Message-ID: This was posted to the argparse mailing list by Steven Bethard and now we'd like some feedback from comp.lang.python. We now have a branch[5] of argparse that supports an ``argparse.run`` function[6] which does some function introspection to build a command line parser from a function definition: ------------------------------ prog.py ------------------------------ import argparse def func(foo, bar, baz): """A function that foo's a bar with a baz. foo - The foo bar - The bar to be foo'd baz - The baz with which to foo. """ print foo, bar, baz if __name__ == '__main__': argparse.run(func) ------------------------------ cmdline ------------------------------ $ prog.py -h usage: prog.py [-h] foo bar baz A function that foo's a bar with a baz. positional arguments: foo The foo bar The bar to be foo'd baz The baz with which to foo. optional arguments: -h, --help show this help message and exit ---------------------------------------------------------------------- I'd love to hear some feedback on this. At the moment, the code can introspect argument names, types from defaults, types from annotations (in Python 3), help messages from docstrings, and knows how to convert multiple functions into subcommands. The code's compatible and tested on python 2.3 - 3.1. There are probably more things we could support [7], but I'd like to get some feedback on what we have so far. Some specific questions: * Do you think this is worth including in argparse? * Would you use the current ``argparse.run`` API in your own code? * If you wouldn't use it as-is, what additional features/modifications would you require? --Steve and Yuv PS: The authors of pyopt[1], opster[2], optfunc[3] and simpleopt[4] were CC'd, in the hopes that we can converge to a common API, but they didn't reply other than the pyopt guy (me) who wrote the patch. [0] SVN branch at: http://argparse.googlecode.com/svn/branches/function-arguments/ [1] http://code.google.com/p/pyopt/ [2] http://hg.piranha.org.ua/opster/ [3] http://github.com/simonw/optfunc/ [4] http://pypi.python.org/pypi/simpleopt/ [5] http://argparse.googlecode.com/svn/branches/function-arguments/ [6] The branch also adds ``ArgumentParser.add_function_arguments`` which ``argparse.run`` is built on top of. This method allows you to match function based arguments with other arguments as necessary, e.g.:: def items(n=10): return range(n) parser = argparse.ArgumentParser() parser.add_function_arguments(items) parser.add_argument('output_file') args = parser.parse_args() with open(args.output_file, 'w') as output_file: for item in args.items(): output_file.write("%d\n" % item) [7] I can imagine allowing the introspected values to be overridden with decorators, though it may be out of the scope of this patch. e.g.:: @annotate( dirname=positional(help='...'), listen=optional('-l', default='localhost', help='ip to listen on'), port=optional('-p', default=8000, help='port to listen on'), ...) def func(dirname, listen='localhost', port=8000, ...): From rami.chowdhury at gmail.com Sat Nov 7 17:49:28 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 7 Nov 2009 14:49:28 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> Message-ID: <200911071449.28713.rami.chowdhury@gmail.com> On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > httpd.conf: > > > ServerAdmin me at creative.vi > DocumentRoot /var/www/html/angrynates.com > ServerName angrynates.com > Options +ExecCGI -IncludesNoExec > You may want to change this to: If you want regular expression syntax, I would advise using the syntax or > #ls -lZ > drwxr-xr-x root root 1024 > drwxr-xr-x root root 1132 > drwxr-xr-x root root 1255 [snip] It looks like you don't have *any* SELinux context information; if SELinux is on, this will cause problems. Try using the 'restorecon' command to put the defaults in place, and consider using 'chcon' to change the security context to an appropriate one (I believe you want something like 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > I have a serious privileges problem that is making it impossible to > > > serve python pages on a CentOS server. It appears that nobody on the > > > CentOS discussion list has a solution to this problem. I'm desperate > > > and hoping someone on this list can help. > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > Now, the file does exist: > > > > > > [root at 13gems global_solutions]# pwd > > > /var/www/html/angrynates.com/global_solutions > > > [root at 13gems global_solutions]# ls > > > .... > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > .... > > > and it serves just fine on another server, so there is no "premature > > > end > > > > of > > > > > script headers". > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py and > > > template.py which the former calls, and create files test.py and > > > test2.py and paste the code from the former files in those new files > > > changing only the import statement from "template" to "test2", the > > > tests will resolve!! Now, the ownership and mode are identical on all > > > of them!! > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > where test.py is identical to index.py (other than the necessary > > > import) and template is identical to test2.py > > > > > > > > > fixfiles relabel /var/www/html > > > # might just work > > > It didn't > > > > > > touch /.autorelabel > > > # and then reboot will relabel all copied files to the correct contexts > > > > for > > > > > the location > > > I rebooted apache with no luck > > > > > > or you could turn off SELinux and reboot > > > I did that and the following two solutions with no luck: > > > echo 0 >/selinux/enforce > > > > > > [root at 13gems ~]# cd /etc/ > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > [root at 13gems etc]# mkdir selinux > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > ...and the problem continues: > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > file > > > > or > > > > > directory: exec of '/var/www/html/ > > > > angrynates.com/global_solutions/index.py' > > > > > failed > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature end > > > of script headers: index.py > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does not > > > exist: /var/www/html/angrynates.com/robots.txt > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such > > > file or directory: exec of > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > referer: > > > http://angrynates.com/global_solutions/ > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature end > > > > of > > > > > script headers: index.py, referer: > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does not > > > exist: /var/www/html/angrynates.com/favicon.ico > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does not > > > exist: /var/www/html/angrynates.com/favicon.ico > > > [root at 13gems etc]# > > > > > > Please help. > > > Victor > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > directories, > > and see what the Apache (httpd.conf or .htaccess) configuration is for > > them? > > > > ---- > > Rami Chowdhury > > "Passion is inversely proportional to the amount of real information > > available." -- Benford's Law of Controversy > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > ---- Rami Chowdhury "Strangers are just friends who haven't had enough gin." -- Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From sturlamolden at yahoo.no Sat Nov 7 17:54:34 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 14:54:34 -0800 (PST) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> Message-ID: On 6 Nov, 17:54, "Alf P. Steinbach" wrote: > But wow. That's pretty hare-brained: dynamic allocation for every stored value > outside the cache range, needless extra indirection for every operation. First, integers are not used the same way in Python as they are in C+ +. E.g. you typically don't iterate over them in a for loop, but rather iterate on the container itself. Second, if you need an array of integers or floats, that is usually not done with a list: you would use numpy.ndarray or array.array, and values are stored compactly. A Python list is a list, it is not an array. If you were to put integers in dynamic data structures in other languages (Java, C++), you would use dynamic allocation as well. Yes a list is implemented as an array of pointers, amortized to O(1) for appends, but that is an implementation detail. Python is not the only language that works like this. There are also MATLAB and Lisp. I know you have a strong background in C++, but when you are using Python you must unlearn that way of thinking. Finally: if none of these helps, we can always resort to Cython. In 99% of cases where integers are bottlenecks in Python, it is indicative of bad style. We very often see this from people coming form C++ and Java background, and subsequent claims that "Python is slow". Python is not an untyped Java. If you use it as such, it will hurt. Languages like Python, Perl, Common Lisp, and MATLAB require a different mindset from the programmer. From debatem1 at gmail.com Sat Nov 7 18:05:37 2009 From: debatem1 at gmail.com (geremy condra) Date: Sat, 7 Nov 2009 18:05:37 -0500 Subject: feedback on function introspection in argparse In-Reply-To: References: Message-ID: On Sat, Nov 7, 2009 at 5:45 PM, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some function introspection to build a command line parser from a > function definition: > > ------------------------------ prog.py ------------------------------ > import argparse > > def func(foo, bar, baz): > ? """A function that foo's a bar with a baz. > ? foo - The foo > ? bar - The bar to be foo'd > ? baz - The baz with which to foo. > ? """ > ? print foo, bar, baz > > if __name__ == '__main__': > ? argparse.run(func) > ------------------------------ cmdline ------------------------------ > $ prog.py -h > usage: prog.py [-h] foo bar baz > > A function that foo's a bar with a baz. > > positional arguments: > ?foo ? ? ? ? The foo > ?bar ? ? ? ? The bar to be foo'd > ?baz ? ? ? ? The baz with which to foo. > > optional arguments: > ?-h, --help ?show this help message and exit > ---------------------------------------------------------------------- Looks great! Very handy. > I'd love to hear some feedback on this. At the moment, the code can > introspect argument names, types from defaults, types from annotations > (in Python 3), help messages from docstrings, and knows how to convert > multiple functions into subcommands. The code's compatible and tested > on python 2.3 - 3.1. There are probably more things we could support > [7], but I'd like to get some feedback on what we have so > far. Some specific questions: > > * Do you think this is worth including in argparse? > * Would you use the current ``argparse.run`` API in your own code? yes. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Sat Nov 7 18:09:58 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Nov 2009 23:09:58 GMT Subject: is None or == None ? References: Message-ID: <0305ec85$0$1371$c3e8da3@news.astraweb.com> On Sat, 07 Nov 2009 14:22:28 -0800, sturlamolden wrote: > On 6 Nov, 14:35, "Alf P. Steinbach" wrote: > >> As I understand it, 'is' will always work and will always be efficient >> (it just checks the variable's type), while '==' can depend on the >> implementation of equality checking for the other operand's class. > > '==' checks for logical equality. 'is' checks for object identity. So far so good, although technically == merely calls __eq__, which can be over-ridden to do (nearly) anything you like: >>> class Funny(object): ... def __eq__(self, other): ... return self.payload + other ... >>> f = Funny() >>> f.payload = 5 >>> f == 10 15 > None is a singleton of type NoneType. Since None evaluates to True only > when compared against itself, That's wrong. None never evaluates to True, it always evaluates as None, in the same way that 42 evaluates as 42 and [1,2,3] evaluates as [1,2,3]. Python literals evaluate as themselves, always. Perhaps you mean that *comparisons* of None evaluate to True only if both operands are None. That's incorrect too: >>> None > None False You have to specify the comparison. It would be a pretty strange language if both None==None and None!=None returned True. > it is safe to use both operators. Only if you want unexpected results if somebody passes the wrong sort of object to your code. >>> class NoneProxy: ... def __eq__(self, other): ... if other is None: return True ... return False ... >>> o = NoneProxy() >>> o is None False >>> o == None True You should use == *only* if you want to test for objects which are equal to None, *whatever that object may be*, and is if you want to test for None itself. -- Steven From ben+python at benfinney.id.au Sat Nov 7 18:14:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 10:14:31 +1100 Subject: exception due to NoneType References: <4af5bd9a$0$22506$426a74cc@news.free.fr> Message-ID: <871vka6i7c.fsf@benfinney.id.au> asit writes: > for s in users: > print > print "##########################################" > try: > print "user id : " + str(s.id) > print "user name : " + s.name > print "user location : " + s.location > print "user description : " + s.description > print "user profile image url : " + s.profile_image_url > print "user url : " + s.url > print "user status : " + str(s.status) > except TypeError: > pass Why are you catching TypeError, only to discard it? Ignoring an error doesn't make it go away. The above code should rather use string formatting to interpolate the values you want into a string for output:: import textwrap for user in users: print textwrap.dedent(""" ########################################## user id: %(id)s user name: %(name)s user location: %(location)s user description: %(description)s user profile image url: %(profile_image_url)s user url: %(url)s user status: %(status)s """) % vars(user) -- \ ?My classmates would copulate with anything that moved, but I | `\ never saw any reason to limit myself.? ?Emo Philips | _o__) | Ben Finney From mensanator at aol.com Sat Nov 7 18:22:26 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 15:22:26 -0800 (PST) Subject: Microsoft research on code quality References: Message-ID: <76d705f7-457d-41a1-90d0-714d860da735@r5g2000yqb.googlegroups.com> On Nov 6, 3:15?pm, a... at pythoncraft.com (Aahz) wrote: > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > [on old computer technologies and programmers] ?"Fancy tail fins on a > brand new '59 Cadillac didn't mean throwing out a whole generation of > mechanics who started with model As." ?--Andrew Dalke Microsoft has more to answer for for the fuckups they install deliberately than for the bugs that get in accidentally. From pavlovevidence at gmail.com Sat Nov 7 18:33:40 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 15:33:40 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: On Nov 7, 2:45?pm, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some function introspection to build a command line parser from a > function definition: > > ------------------------------ prog.py ------------------------------ > import argparse > > def func(foo, bar, baz): > ? ?"""A function that foo's a bar with a baz. > ? ?foo - The foo > ? ?bar - The bar to be foo'd > ? ?baz - The baz with which to foo. > ? ?""" > ? ?print foo, bar, baz > > if __name__ == '__main__': > ? ?argparse.run(func) > ------------------------------ cmdline ------------------------------ > $ prog.py -h > usage: prog.py [-h] foo bar baz > > A function that foo's a bar with a baz. > > positional arguments: > ?foo ? ? ? ? The foo > ?bar ? ? ? ? The bar to be foo'd > ?baz ? ? ? ? The baz with which to foo. > > optional arguments: > ?-h, --help ?show this help message and exit > ---------------------------------------------------------------------- > > I'd love to hear some feedback on this. At the moment, the code can > introspect argument names, types from defaults, types from annotations > (in Python 3), help messages from docstrings, and knows how to convert > multiple functions into subcommands. The code's compatible and tested > on python 2.3 - 3.1. There are probably more things we could support > [7], but I'd like to get some feedback on what we have so > far. Some specific questions: > > * Do you think this is worth including in argparse? > * Would you use the current ``argparse.run`` API in your own code? > * If you wouldn't use it as-is, what additional features/modifications > would you require? Looks quite useful. I am not sure I like the name "run", seems to short and innocent for a function this magical. Is the docstring expected to be formatted according to some convention? I don't recognize a docstring convention in the example, but then I don't bother with them much in my own code, that's why I ask. Carl Banks From ubershmekel at gmail.com Sat Nov 7 18:44:33 2009 From: ubershmekel at gmail.com (Yuv) Date: Sat, 7 Nov 2009 15:44:33 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: On Nov 8, 1:33?am, Carl Banks wrote: > Is the docstring expected to be formatted according to some > convention? Yes it does, we parse the docstring as explained in argparse.py: def _parse_docstring(function): """Parses a function's docstring for a description of the function and for help on the individual parameters. The parsing algorithm currently looks for lines that start with a parameter name immediately followed by any amount of whitespace, hyphens or colons. The rest of the line following the colon/hyphen/whitespace is the help. Keyword Arguments: function - the function whose docstring is parsed. Returns a (description, help_dict) tuple: description - all text before the first documented parameter help_dict - a dictionary mapping parameter names to their help strings """ We tried to comply to PEP 257 and we're open to suggestions on this. --yuv From no.email at please.post Sat Nov 7 19:23:18 2009 From: no.email at please.post (kj) Date: Sun, 8 Nov 2009 00:23:18 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: In Luis Alberto Zarrabeitia Gomez writes: >Quoting Andre Engels : >> On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez >> wrote: >> > >> > Ok, he has a dict. >> > >> > Now what? He needs a non-sparse array. >> >> Let d be your dict. >> >> Call the zeroeth place in your array d[0], the first d[1], the 10000th >> d[100000]. >Following that reasoning, we could get rid of lists and arrays altogether. >Here's why that wouldn't work: >for x,y in zip(d,other): > ... do something ... >Yes, we could also ignore zip and just use range/xrange to iterate for the >indices... >Lists and dictionaries have different semantics. One thing is to argue that you >shouldn't be thinking on pre-growing a list for performance reasons before being >sure that it is a bottleneck, and a very different one is to argue that because >one operation (__setitem__) is the same with both structures, we should not use >lists for what may need, depending on the problem, list semantics. >?Have you ever tried to read list/matrix that you know it is not sparse, but you >don't know the size, and it may not be in order? A "grow-able" array would just >be the right thing to use - currently I have to settle with either hacking >together my own grow-able array, or preloading the data into a dict, growing a >list with the [0]*size trick, and updating that list. Not hard, not worthy of a >PEP, but certainly not so easy to dismiss. Thanks. Well said. Saludos, kynn From fordhaivat at gmail.com Sat Nov 7 20:00:18 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 20:00:18 -0500 Subject: Spam Bot, broken pipe Message-ID: I have a irc spam bot (only testing on my channel :P ) whose main loop is the following: privc="PRIVMSG "+self.channel while True: self.sock.send(privc=" :SPAM SPAM SPAM!"); time.sleep(2); And it gives an error "Broken Pipe". How can I fix this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Sat Nov 7 20:03:37 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:03:37 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <28737d4e-c83b-403a-948a-abf0a97d03aa@g27g2000yqn.googlegroups.com> On 6 Nov, 13:12, kj wrote: > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? Yes, but why would you want to? Appending to a Python list has amortized O(1) complexity. I am not sure about Perl, but in MATLAB arrays are preallocated because resize has complexity O(n), instead of amortized O(1). You don't need to worry about that in Python. Python lists are resized with empty slots at the end, in proportion to the size of the list. On average, this has the same complexity as pre- allocation. From sturlamolden at yahoo.no Sat Nov 7 20:05:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:05:53 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> On 7 Nov, 03:46, gil_johnson wrote:> > I don't have the code with me, but for huge arrays, I have used > something like: > > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil You should really use append instead of extend. The above code is O (N**2), with append it becomes O(N) on average. From pavlovevidence at gmail.com Sat Nov 7 20:08:56 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 17:08:56 -0800 (PST) Subject: feedback on function introspection in argparse References: Message-ID: <2d2e7306-739c-46d5-8432-1bbeb538442e@g1g2000pra.googlegroups.com> On Nov 7, 3:44?pm, Yuv wrote: > On Nov 8, 1:33?am, Carl Banks wrote: > > > Is the docstring expected to be formatted according to some > > convention? [snippage] > We tried to comply to PEP 257 and we're open to suggestions on this. Ah, so we finally get to the answer: the convention is PEP 257. :) Carl Banks From sturlamolden at yahoo.no Sat Nov 7 20:13:07 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 7 Nov 2009 17:13:07 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: On 6 Nov, 22:03, kj wrote: > As I said, this is considered an optimization, at least in Perl, > because it lets the interpreter allocate all the required memory > in one fell swoop, instead of having to reallocate it repeatedly > as the array grows. Python does not need to reallocate repeatedly as a list grows. That is why it's called a 'list' and not an array. There will be empty slots at the end of a list you can append to, without reallocating. When the list is resized, it is reallocated with even more of these. Thus the need to reallocate becomes more and more rare as the list grows, and on average the complexity of appending is just O(1). From pengyu.ut at gmail.com Sat Nov 7 20:17:09 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 7 Nov 2009 19:17:09 -0600 Subject: How convert string '1e7' to an integer? Message-ID: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> It seems that int() does not convert '1e7'. I'm wondering what function to use to convert '1e7' to an integer? >>> int('1e7') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1e7' From pavlovevidence at gmail.com Sat Nov 7 20:18:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 17:18:38 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> Message-ID: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> On Nov 7, 5:05?pm, sturlamolden wrote: > On 7 Nov, 03:46, gil_johnson wrote:> > > > I don't have the code with me, but for huge arrays, I have used > > something like: > > > >>> arr[0] = initializer > > >>> for i in range N: > > >>> ? ? ?arr.extend(arr) > > > This doubles the array every time through the loop, and you can add > > the powers of 2 to get the desired result. > > Gil > > You should really use append instead of extend. The above code is O > (N**2), with append it becomes O(N) on average. I think the top one is O(N log N), and I'm suspicious that it's even possible to grow a list in less than O(N log N) time without knowing the final size in advance. Citation? Futhermore why would it matter to use extend instead of append; I'd assume extend uses the same growth algorithm. (Although in this case since the extend doubles the size of the list it most likely reallocates after each call.) [None]*N is linear time and is better than growing the list using append or extend. Carl Banks From hniksic at xemacs.org Sat Nov 7 20:25:42 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 08 Nov 2009 02:25:42 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> Message-ID: <87my2xhko9.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > Speedup would likely be more realistic with normal implementation (not > fiddling with bit-fields and stuff) I'm not sure I understand this. How would you implement tagged integers without encoding type information in bits of the pointer value? From exarkun at twistedmatrix.com Sat Nov 7 20:32:30 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 08 Nov 2009 01:32:30 -0000 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> Message-ID: <20091108013230.3229.565954700.divmod.xquotient.346@localhost.localdomain> On 01:18 am, pavlovevidence at gmail.com wrote: >On Nov 7, 5:05?pm, sturlamolden wrote: >>On 7 Nov, 03:46, gil_johnson wrote:> >> >> > I don't have the code with me, but for huge arrays, I have used >> > something like: >> >> > >>> arr[0] = initializer >> > >>> for i in range N: >> > >>> ? ? ?arr.extend(arr) >> >> > This doubles the array every time through the loop, and you can add >> > the powers of 2 to get the desired result. >> > Gil >> >>You should really use append instead of extend. The above code is O >>(N**2), with append it becomes O(N) on average. > >I think the top one is O(N log N), and I'm suspicious that it's even >possible to grow a list in less than O(N log N) time without knowing >the final size in advance. Citation? Futhermore why would it matter >to use extend instead of append; I'd assume extend uses the same >growth algorithm. (Although in this case since the extend doubles the >size of the list it most likely reallocates after each call.) > >[None]*N is linear time and is better than growing the list using >append or extend. The wikipedia page for http://en.wikipedia.org/wiki/Amortized_analysis conveniently uses exactly this example to explain the concept of amortized costs. Jean-Paul From mensanator at aol.com Sat Nov 7 20:41:03 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 7 Nov 2009 17:41:03 -0800 (PST) Subject: How convert string '1e7' to an integer? References: Message-ID: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> On Nov 7, 7:17?pm, Peng Yu wrote: > It seems that int() does not convert '1e7'. Because 'e' isn't a valid character in base 10. > I'm wondering what > function to use to convert '1e7' to an integer? > > >>> int('1e7') >>> int(1e7) 10000000 > > Traceback (most recent call last): > ? File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' From mad.mick at gmx.de Sat Nov 7 20:42:21 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 02:42:21 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: Message-ID: Peng Yu wrote: > It seems that int() does not convert '1e7'. It seems it does, though: >>> int('1e7', base=16) 487 Mick. From python at mrabarnett.plus.com Sat Nov 7 20:45:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 01:45:57 +0000 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: <4AF622D5.7090301@mrabarnett.plus.com> Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? > >>>> int('1e7') > Traceback (most recent call last): > File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' In Python the e-form indicates a float, as does the presence of a decimal point, but you can convert to float and then to int: >>> int(float('1e7')) 10000000 From ben+python at benfinney.id.au Sat Nov 7 20:49:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 12:49:48 +1100 Subject: How convert string '1e7' to an integer? References: Message-ID: <87d43t6b0j.fsf@benfinney.id.au> Mick Krippendorf writes: > Peng Yu wrote: > > It seems that int() does not convert '1e7'. > It seems it does, though: > > >>> int('1e7', base=16) > 487 Well played, sir. -- \ ?It is wrong to think that the task of physics is to find out | `\ how nature *is*. Physics concerns what we can *say* about | _o__) nature?? ?Niels Bohr | Ben Finney From gherron at islandtraining.com Sat Nov 7 20:50:53 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 07 Nov 2009 17:50:53 -0800 Subject: How convert string '1e7' to an integer? In-Reply-To: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: <4AF623FD.7060306@islandtraining.com> Mensanator wrote: > On Nov 7, 7:17 pm, Peng Yu wrote: > >> It seems that int() does not convert '1e7'. >> > > Because 'e' isn't a valid character in base 10. > But 1e7 is a valid float, so this works: >>> int(float('1e7')) 10000000 That has a problem though, if you surpass the ability of a float: >>> int(float('1e20')) 100000000000000000000L >>> int(float('1e30')) 1000000000000000019884624838656L Gary Herron > >> I'm wondering what >> function to use to convert '1e7' to an integer? >> >> >>>>> int('1e7') >>>>> > > >>>> int(1e7) >>>> > 10000000 > > > >> Traceback (most recent call last): >> File "", line 1, in >> ValueError: invalid literal for int() with base 10: '1e7' >> > > From benjamin.kaplan at case.edu Sat Nov 7 20:52:37 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 7 Nov 2009 20:52:37 -0500 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? > >>>> int('1e7') > Traceback (most recent call last): > ?File "", line 1, in > ValueError: invalid literal for int() with base 10: '1e7' Whenever you use that notation, you always get a float >>> 1e7 10000000.0 So to convert '1e7' to a number, you need to use float('1e7') which you can then convert to an int >>> int(float('1e7')) 10000000 > -- > http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Sat Nov 7 20:55:08 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 08 Nov 2009 02:55:08 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> References: <366c6f340911071717k1ff772c0ie2b417eb7db52b1a@mail.gmail.com> Message-ID: Peng Yu wrote: > It seems that int() does not convert '1e7'. I'm wondering what > function to use to convert '1e7' to an integer? 1e7 is a way to express a float in science and math. Try float("1e7") Christian From sven at pantoffel-wg.de Sat Nov 7 21:04:04 2009 From: sven at pantoffel-wg.de (Sven Marnach) Date: Sun, 8 Nov 2009 03:04:04 +0100 Subject: Cancelling a python thread (revisited...) Message-ID: <20091108020404.GE4998@pantoffel-wg.de> Hi, the Python threading module does not seem to provide a means to cancel a running thread. There are many discussions on the web dealing with this issue and many solutions are offered, but none of them seems to be applicable to my situation, which is as follows: I have a C library which does some very computationally intensive stuff. Some functions in this library might run for a long time, and the code in the library is optimized for speed. The library is used in C programs and also from a PyGTK GUI program. In the GUI, you can choose the computation parameters and than start the computation. It is run in a separate thread, which calls a function in the C library via ctypes. Now it should be possible to cancel the computation from the GUI. In the C programs, I can just kill or cancel the thread (there is no cleanup to be done -- the thread does not use any system resources apart from CPU time). In Python, this is not possible. The solutions for this problem I found on the web usually recommend to have the thread regularly check some variable and exit if this variable indicates to do so. This would have to be included in the C library and would include quite a bit of code refactoring. The check cannot be included in the inner loop because it would lead to significant performance loss. Furthermore, I just do not want to mess up an elegant and efficient library design which works perfect when used from C just to make up for shortcomings in Python. So do I really have to refactor my C library just because Python Thread objects lack a cancel method? Is there really no other way? And why on earth doesn't that cancel method exist? There *are* good reasons to cancel a thread, just google for "terminate a Python thread" for tons of examples. I would be grateful for any suggestions. Greetings from Germany and have a nice day, Sven From python.list at tim.thechases.com Sat Nov 7 21:05:22 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 07 Nov 2009 20:05:22 -0600 Subject: How convert string '1e7' to an integer? In-Reply-To: References: Message-ID: <4AF62762.7070800@tim.thechases.com> Mick Krippendorf wrote: > Peng Yu wrote: >> It seems that int() does not convert '1e7'. > It seems it does, though: > >>>> int('1e7', base=16) > 487 Bah...so narrow-minded ;-) >>> print '\n'.join("Base %i: %i" % (base, int('1e7', base=base)) for base in range(15,37)) Base 15: 442 Base 16: 487 Base 17: 534 Base 18: 583 Base 19: 634 Base 20: 687 Base 21: 742 Base 22: 799 Base 23: 858 Base 24: 919 Base 25: 982 Base 26: 1047 Base 27: 1114 Base 28: 1183 Base 29: 1254 Base 30: 1327 Base 31: 1402 Base 32: 1479 Base 33: 1558 Base 34: 1639 Base 35: 1722 Base 36: 1807 I feel so dirty interpreting numbers in convenient ways...like an accountant. ("whaddaya mean I can't file my tax-return in base 17?! There's nothing in the supporting documentation that mentions such draconian restrictions!") -tkc From fordhaivat at gmail.com Sat Nov 7 21:06:12 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 21:06:12 -0500 Subject: Spam Bot, broken pipe In-Reply-To: References: <2cf430a60911071707r50701c20wa552ca5ae05eec15@mail.gmail.com> Message-ID: I'm just testing it on my channel! I promise! Besides, I'm doing it to learn about sockets! Please! On Sat, Nov 7, 2009 at 8:07 PM, Krister Svanlund wrote: > On Sun, Nov 8, 2009 at 2:00 AM, Someone Something > wrote: > > I have a irc spam bot (only testing on my channel :P ) whose main loop is > > the following: > > > > privc="PRIVMSG "+self.channel > > while True: > > self.sock.send(privc=" :SPAM SPAM SPAM!"); > > time.sleep(2); > > > > And it gives an error "Broken Pipe". > > How can I fix this? > > By doing it right... unfortunaly I don't approve of spam and can > therefor not tell you how to do that. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan at baselinedata.co.uk Sat Nov 7 21:08:22 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Sun, 08 Nov 2009 02:08:22 +0000 Subject: Web development with Python 3.1 In-Reply-To: References: <4AE4E4A7.5060708@baselinedata.co.uk> <880dece00910271211l5e1ecf89i1d2b85c930998689@mail.gmail.com> <7kp7brF3an909U1@mid.uni-berlin.de> <880dece00910280118j14f40763k60cd376425b8d9c@mail.gmail.com> <7kqgg4F3aqqf9U1@mid.uni-berlin.de> <6f7e015d-deba-499b-bc5d-66c0a35610b0@y23g2000yqd.googlegroups.com> Message-ID: <4AF62816.20807@baselinedata.co.uk> mario ruggier wrote: > With respect to to original question regarding web frameworks + > database and Python 3, all the following have been available for > Python 3 since the day Python 3.0 was released: > > QP, a Web Framework > http://pypi.python.org/pypi/qp/ > > Durus, a Python Object Database (the "default" in qp, for user > sessions, etc) > http://pypi.python.org/pypi/Durus/ > > Evoque, state-of-the-art templating engine > http://pypi.python.org/pypi/evoque/ > (this one is available for py3.0 since a little later, 21-jan-2009) > > All the above also runs on python 2.4 (thru to python 3) > > For the record, you may see the list of all pypi packages availabe for > Python 3 at: > http://pypi.python.org/pypi?:action=browse&show=all&c=533 > > m. Thanks for those links Mario - I'll check them out asap.. Regards, Alan From pict100 at gmail.com Sat Nov 7 21:16:50 2009 From: pict100 at gmail.com (DarkBlue) Date: Sat, 7 Nov 2009 18:16:50 -0800 (PST) Subject: PyQt processEvents not processing References: <7dae4aa6-feb4-41eb-8cfd-95cf21be3c82@z4g2000prh.googlegroups.com> Message-ID: On Nov 8, 12:04?am, David Boddie wrote: > On Saturday 07 November 2009 05:12, DarkBlue wrote: > > > > > qt 4.5.3 > > pyqt 4.6.1 > > python 2.6 > > > I have this QtTable widget which I want to refresh once about every 2 > > seconds with new data. > > > so I do : > > > ?def updateSchedule(self): > > ? ? ? ? ?for j in range(0,10): > > ? ? ? ? ? ? ? ? ? ? ? doUpdate() > > ? ? ? ? ? ? ? ? ? ? ? QtCore.processEvents() > > ? ? ? ? ? ? ? ? ? ? ? sleep(2) > > > ?unfortunately QT appears to wait until the for loop finishes > > ?and only then paints the QtTable widget on the screen showing > > ?only the latest updated result. > > It's difficult to know exactly why this is without more context. Calling > the application's processEvents() method should give the user interface the > chance to update itself, but perhaps you need to explicitly call update() > on the QTableView or QTableWidget instance to ensure that it is refreshed. > > An alternative way to do this is to use a timer to update the table every > two seconds. > > David As per your suggestion I added a timer to the init part and now the update works as expected , even without calls to processEvents. self.myTimer = QtCore.QTimer(self) QtCore.QObject.connect(self.myTimer,QtCore.SIGNAL("timeout()"), self.doUpdate) self.timerTime = 0 self.myTimer.start(2000) Thanks Db From fordhaivat at gmail.com Sat Nov 7 21:37:34 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 7 Nov 2009 21:37:34 -0500 Subject: Spam Bot, broken pipe In-Reply-To: References: <2cf430a60911071707r50701c20wa552ca5ae05eec15@mail.gmail.com> Message-ID: anyone? On Sat, Nov 7, 2009 at 9:06 PM, Someone Something wrote: > > > I'm just testing it on my channel! I promise! Besides, I'm doing it to > learn about sockets! Please! > > > On Sat, Nov 7, 2009 at 8:07 PM, Krister Svanlund < > krister.svanlund at gmail.com> wrote: > >> On Sun, Nov 8, 2009 at 2:00 AM, Someone Something >> wrote: >> > I have a irc spam bot (only testing on my channel :P ) whose main loop >> is >> > the following: >> > >> > privc="PRIVMSG "+self.channel >> > while True: >> > self.sock.send(privc=" :SPAM SPAM SPAM!"); >> > time.sleep(2); >> > >> > And it gives an error "Broken Pipe". >> > How can I fix this? >> >> By doing it right... unfortunaly I don't approve of spam and can >> therefor not tell you how to do that. >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sat Nov 7 21:57:26 2009 From: rt8396 at gmail.com (r) Date: Sat, 7 Nov 2009 18:57:26 -0800 (PST) Subject: An assessment of Tkinter and IDLE References: <55a0833d-3f1f-402a-8eb7-cb4b7861cce5@q5g2000yqh.googlegroups.com> <7b9665f6-8fa8-47d5-9636-da55da0fa78f@j19g2000yqk.googlegroups.com> Message-ID: <10463631-978d-4d1d-9d9a-e94af831ef15@p32g2000vbi.googlegroups.com> More on canvas widget... The Canvas widget should return objects and not simple tags/ids for canvas items *OR* at least allow for me to add attributes to the canvasitems "obj". I find that the id/tag system --while quite simple and strait forward-- can really leave you with both hands tied behind you back whilst suffering a wicked itch on the tip of your nose that is just not reachable! (god i hate that!) From pavlovevidence at gmail.com Sat Nov 7 22:27:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 7 Nov 2009 19:27:52 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: Message-ID: On Nov 7, 6:04?pm, Sven Marnach wrote: > So do I really have to refactor my C library just because Python > Thread objects lack a cancel method? ?Is there really no other way? It doesn't sound like the thread is communicating with the process much. Therefore: 1. Run the C code in a separate process, or 2. Create the thread from a C extension, maybe even straight from ctypes, and kill it from C or ctypes. > And why on earth doesn't that cancel method exist? There *are* good > reasons to cancel a thread, just google for "terminate a Python > thread" for tons of examples. Arguing that there are good reasons to allow killing threads isn't going to get you very far. The language developers already know killing a thread is useful, yet the disallowed it anyway. The drawbacks were judged too severe (it makes enforcing invariants pretty much impossible). Carl Banks From kevinar18 at hotmail.com Sat Nov 7 22:39:31 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 22:39:31 -0500 Subject: How to parse HTTP time header? Message-ID: Basically, I'm wondering if it is part of the standard library somewhere before I code my own. Page 20 of RFC2616 (HTTP) describes the format(s) for the time header. It wouldn't be too difficult for me to code up a solution for the 3 standard formats, but what get's me is the little note about how some servers may still send badly format time headers. :( So, I'm curious if this has already been done in the standard Python library? How about in one of the Python web frameworks? Do any have a more robust solution already done? _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Nov 7 22:48:28 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 7 Nov 2009 22:48:28 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: <5BC7AEB5-C854-4D51-A1EF-2B3540771343@semanchuk.com> On Nov 7, 2009, at 10:39 PM, Kevin Ar18 wrote: > > Basically, I'm wondering if it is part of the standard library > somewhere before I code my own. > > Page 20 of RFC2616 (HTTP) describes the format(s) for the time > header. It wouldn't be too difficult for me to code up a solution > for the 3 standard formats, but what get's me is the little note > about how some servers may still send badly format time headers. :( > So, I'm curious if this has already been done in the standard Python > library? The parsedate() function in the rfc822 module does this and claims to be tolerant of slightly malformed dates, but that module is deprecated as of Python 2.5 in favor of the email module which hopefully has an equivalent function. HTH Philip From kevinar18 at hotmail.com Sat Nov 7 22:56:27 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 22:56:27 -0500 Subject: How to parse HTTP time header? Message-ID: >> Basically, I'm wondering if it is part of the standard library >> somewhere before I code my own. >> >> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >> header. It wouldn't be too difficult for me to code up a solution >> for the 3 standard formats, but what get's me is the little note >> about how some servers may still send badly format time headers. :( >> So, I'm curious if this has already been done in the standard Python >> library? > > The parsedate() function in the rfc822 module does this and claims to > be tolerant of slightly malformed dates, but that module is deprecated > as of Python 2.5 in favor of the email module which hopefully has an > equivalent function.Thanks, I'll give 'em a look. :) _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Sat Nov 7 23:19:11 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 7 Nov 2009 23:19:11 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: <0F9A9052-4C33-4BF0-95BA-3CD41E90AAFB@semanchuk.com> On Nov 7, 2009, at 10:56 PM, Kevin Ar18 wrote: > >>> Basically, I'm wondering if it is part of the standard library >>> somewhere before I code my own. >>> >>> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >>> header. It wouldn't be too difficult for me to code up a solution >>> for the 3 standard formats, but what get's me is the little note >>> about how some servers may still send badly format time headers. :( >>> So, I'm curious if this has already been done in the standard Python >>> library? >> >> The parsedate() function in the rfc822 module does this and claims to >> be tolerant of slightly malformed dates, but that module is >> deprecated >> as of Python 2.5 in favor of the email module which hopefully has an >> equivalent function. > Thanks, I'll give 'em a look. :) Sorry, my mistake -- 2616 != 2822. I'm not sure if there's something in the standard library for parsing RFC 2616 dates. When I faced the problem of parsing HTTP dates, I wrote my own function although this was in an application that was deliberately unforgiving of invalid input and therefore my code makes no allowances for it. FWIW, it parsed over 1 million dates without encountering any that raised an error. Here it is, written in a time when I obviously didn't have total respect for PEP 8. ASCTIME_FORMAT = "%a %b %d %H:%M:%S %Y" RFC_850_FORMAT = "%A, %d-%b-%y %H:%M:%S GMT" RFC_1123_FORMAT = "%a, %d %b %Y %H:%M:%S GMT" def HttpDateToFloat(HttpDateString): # Per RFC 2616 section 3.3, HTTP dates can come in three flavors -- # Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 # Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 # Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format if not HttpDateString.endswith("GMT"): date = time.strptime(HttpDateString, ASCTIME_FORMAT) else: if "-" in HttpDateString: # RFC 850 format date = time.strptime(HttpDateString, RFC_850_FORMAT) else: # RFC 822/1123 date = time.strptime(HttpDateString, RFC_1123_FORMAT) return calendar.timegm(date) bye Philip From kevinar18 at hotmail.com Sat Nov 7 23:46:42 2009 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Sat, 7 Nov 2009 23:46:42 -0500 Subject: How to parse HTTP time header? In-Reply-To: References: Message-ID: >>>> Page 20 of RFC2616 (HTTP) describes the format(s) for the time >>>> header. It wouldn't be too difficult for me to code up a solution >>>> for the 3 standard formats, but what get's me is the little note >>>> about how some servers may still send badly format time headers. :( >>>> So, I'm curious if this has already been done in the standard Python >>>> library? >>> >>> The parsedate() function in the rfc822 module does this and claims to >>> be tolerant of slightly malformed dates, but that module is >>> deprecated >>> as of Python 2.5 in favor of the email module which hopefully has an >>> equivalent function. >> Thanks, I'll give 'em a look. :) > Sorry, my mistake -- 2616 != 2822. I'm not sure if there's something > in the standard library for parsing RFC 2616 dates. > > When I faced the problem of parsing HTTP dates, I wrote my own > function although this was in an application that was deliberately > unforgiving of invalid input and therefore my code makes no allowances > for it. FWIW, it parsed over 1 million dates without encountering any > that raised an error. > > Here it is, written in a time when I obviously didn't have total > respect for PEP 8. That's exactly what I had in mind when I said, I could write one quickly. :) I guess I can always do it that way if the email.util one doesn't work right. :)Thanks,Kevin _________________________________________________________________ Hotmail: Trusted email with Microsoft's powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/ http://clk.atdmt.com/GBL/go/177141664/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Sun Nov 8 00:14:33 2009 From: nagle at animats.com (John Nagle) Date: Sat, 07 Nov 2009 21:14:33 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: Message-ID: <4af65174$0$1638$742ec2ed@news.sonic.net> Carl Banks wrote: > Arguing that there are good reasons to allow killing threads isn't > going to get you very far. The language developers already know > killing a thread is useful, yet the disallowed it anyway. The > drawbacks were judged too severe (it makes enforcing invariants pretty > much impossible). While outright thread cancellation is generally unsafe, it would be useful if there was a way to force another thread to unblock from a wait condition, like a blocking read, with an exception. This is, among other things, why control-C won't terminate some threaded programs. Python 2.6 and 3 have some steps in this direction. There's "signal.set_wakeup_fd(fd)", and "siginterrupt()". But the real problem, that signals are associated only with the first thread, hasn't been addressed. Question: if "signal.set_wakeup_fd(fd)" is used, and the thread waiting on "fd" is not the main thread, will a signal cause the waiting thread to get a read completion? Or is this another "first thread only" thing"? John Nagle From alfps at start.no Sun Nov 8 01:27:27 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 08 Nov 2009 07:27:27 +0100 Subject: is None or == None ? In-Reply-To: <87my2xhko9.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> Speedup would likely be more realistic with normal implementation (not >> fiddling with bit-fields and stuff) > > I'm not sure I understand this. How would you implement tagged integers > without encoding type information in bits of the pointer value? A normal tag field, as illustrated in code earlier in the thread. Cheers & hth., - Alf From paul.nospam at rudin.co.uk Sun Nov 8 02:07:25 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 08 Nov 2009 07:07:25 +0000 Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <87k4y1ebpu.fsf@rudin.co.uk> kj writes: > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result? > Depends on what you take as given. You can do it with ctypes more efficiently, but you can also shoot yourself in the foot. Another possibility is to use a numpy array. From martin.hellwig at dcuktec.org Sun Nov 8 02:27:43 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 08 Nov 2009 07:27:43 +0000 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: vsoler wrote: As mentioned in the other answers, your problem is best solved by a long overdue organisational decision instead of a technical one. Most popular solutions are: - All invoices are essential a single credit amount, money coming in is taken of from the big pile. - Invoices are split by date, creating multiple credit amounts, any money coming in is used the pay of the oldest one. The latter one allows more easily for different interest and penalty rates. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From victorsubervi at gmail.com Sun Nov 8 02:59:23 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 8 Nov 2009 02:59:23 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911071449.28713.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071309.40437.rami.chowdhury@gmail.com> <4dc0cfea0911071351v3c538767h222f4259ef9e977f@mail.gmail.com> <200911071449.28713.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> restorecon didn't change ls -lZ output Can you give me the exact command for chcon? It complains there are too few arguments, and I couldn't figure it out. Does this really matter? I moved the selinux folder and its contents as well as sent an "echo 0>..." command to kill it. Furthermore, [root at 13gems global_solutions]# ps wax|grep selinux 17645 pts/0 S+ 0:00 grep selinux Please advise. V On Sat, Nov 7, 2009 at 5:49 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > > httpd.conf: > > > > > > ServerAdmin me at creative.vi > > DocumentRoot /var/www/html/angrynates.com > > ServerName angrynates.com > > Options +ExecCGI -IncludesNoExec > > > > You may want to change this to: > > > If you want regular expression syntax, I would advise using the syntax > > or > > > > #ls -lZ > > drwxr-xr-x root root 1024 > > drwxr-xr-x root root 1132 > > drwxr-xr-x root root 1255 > [snip] > > It looks like you don't have *any* SELinux context information; if SELinux > is > on, this will cause problems. Try using the 'restorecon' command to put the > defaults in place, and consider using 'chcon' to change the security > context > to an appropriate one (I believe you want something like > 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > > > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury > wrote: > > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > > I have a serious privileges problem that is making it impossible to > > > > serve python pages on a CentOS server. It appears that nobody on the > > > > CentOS discussion list has a solution to this problem. I'm desperate > > > > and hoping someone on this list can help. > > > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > Now, the file does exist: > > > > > > > > [root at 13gems global_solutions]# pwd > > > > /var/www/html/angrynates.com/global_solutions > > > > [root at 13gems global_solutions]# ls > > > > .... > > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > > .... > > > > and it serves just fine on another server, so there is no "premature > > > > end > > > > > > of > > > > > > > script headers". > > > > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py > and > > > > template.py which the former calls, and create files test.py and > > > > test2.py and paste the code from the former files in those new files > > > > changing only the import statement from "template" to "test2", the > > > > tests will resolve!! Now, the ownership and mode are identical on all > > > > of them!! > > > > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > > > where test.py is identical to index.py (other than the necessary > > > > import) and template is identical to test2.py > > > > > > > > > > > > fixfiles relabel /var/www/html > > > > # might just work > > > > It didn't > > > > > > > > touch /.autorelabel > > > > # and then reboot will relabel all copied files to the correct > contexts > > > > > > for > > > > > > > the location > > > > I rebooted apache with no luck > > > > > > > > or you could turn off SELinux and reboot > > > > I did that and the following two solutions with no luck: > > > > echo 0 >/selinux/enforce > > > > > > > > [root at 13gems ~]# cd /etc/ > > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > > [root at 13gems etc]# mkdir selinux > > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > > > ...and the problem continues: > > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > > file > > > > > > or > > > > > > > directory: exec of '/var/www/html/ > > > > > > angrynates.com/global_solutions/index.py' > > > > > > > failed > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature > end > > > > of script headers: index.py > > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does > not > > > > exist: /var/www/html/angrynates.com/robots.txt > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No such > > > > file or directory: exec of > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > referer: > > > > http://angrynates.com/global_solutions/ > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature > end > > > > > > of > > > > > > > script headers: index.py, referer: > > > > > > http://angrynates.com/global_solutions/ > > > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does > not > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does > not > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > [root at 13gems etc]# > > > > > > > > Please help. > > > > Victor > > > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > > directories, > > > and see what the Apache (httpd.conf or .htaccess) configuration is for > > > them? > > > > > > ---- > > > Rami Chowdhury > > > "Passion is inversely proportional to the amount of real information > > > available." -- Benford's Law of Controversy > > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > > > ---- > Rami Chowdhury > "Strangers are just friends who haven't had enough gin." -- Howdle's Saying > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rschroev_nospam_ml at fastmail.fm Sun Nov 8 04:37:34 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 08 Nov 2009 10:37:34 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Gary Herron schreef: > Mensanator wrote: >> On Nov 7, 7:17 pm, Peng Yu wrote: >> >>> It seems that int() does not convert '1e7'. >>> >> Because 'e' isn't a valid character in base 10. >> > > But 1e7 is a valid float, so this works: > > >>> int(float('1e7')) > 10000000 > > That has a problem though, if you surpass the ability of a float: > > >>> int(float('1e20')) > 100000000000000000000L > >>> int(float('1e30')) > 1000000000000000019884624838656L If that is a concern, decimal can help: >>> import decimal >>> int(decimal.Decimal('1e30')) 1000000000000000000000000000000L -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From hniksic at xemacs.org Sun Nov 8 05:00:17 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 08 Nov 2009 11:00:17 +0100 Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> Message-ID: <87iqdlgwum.fsf@busola.homelinux.net> "Alf P. Steinbach" writes: > * Hrvoje Niksic: >> "Alf P. Steinbach" writes: >> >>> Speedup would likely be more realistic with normal implementation (not >>> fiddling with bit-fields and stuff) >> >> I'm not sure I understand this. How would you implement tagged integers >> without encoding type information in bits of the pointer value? > > A normal tag field, as illustrated in code earlier in the thread. Ah, I see it now. That proposal effectively doubles the size of what is now a PyObject *, meaning that lists, dicts, etc., would also double their memory requirements, so it doesn't come without downsides. On the other hand, tagged pointers have been used in various Lisp implementations for decades, nothing really "baroque" (or inherently slow) about them. From alfps at start.no Sun Nov 8 05:34:55 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 08 Nov 2009 11:34:55 +0100 Subject: is None or == None ? In-Reply-To: <87iqdlgwum.fsf@busola.homelinux.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic: > "Alf P. Steinbach" writes: > >> * Hrvoje Niksic: >>> "Alf P. Steinbach" writes: >>> >>>> Speedup would likely be more realistic with normal implementation (not >>>> fiddling with bit-fields and stuff) >>> I'm not sure I understand this. How would you implement tagged integers >>> without encoding type information in bits of the pointer value? >> A normal tag field, as illustrated in code earlier in the thread. > > Ah, I see it now. That proposal effectively doubles the size of what is > now a PyObject *, meaning that lists, dicts, etc., would also double > their memory requirements, so it doesn't come without downsides. Whether it increases memory usage depends on the data mix in the program's execution. For a program primarily handling objects of atomic types (like int) it saves memory, since each value (generally) avoids a dynamically allocated object. Bit-field fiddling may save a little more memory, and is nearly guaranteed to save memory. But memory usage isn't an issue except to the degree it affects the OS's virtual memory manager. Slowness is an issue -- except that keeping compatibility is IMO a more important issue (don't fix, at cost, what works). > On the > other hand, tagged pointers have been used in various Lisp > implementations for decades, nothing really "baroque" (or inherently > slow) about them. Unpacking of bit fields generally adds overhead. The bit fields need to be unpacked for (e.g.) integer operations. Lisp once ran on severely memory constrained machines. Cheers & hth., - Alf From kbalavignesh at gmail.com Sun Nov 8 05:37:09 2009 From: kbalavignesh at gmail.com (balavignesh) Date: Sun, 8 Nov 2009 02:37:09 -0800 (PST) Subject: 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) Message-ID: Hello friends, I am using pyWPS + GRASS to generate the maps for the given request XML. As my requestxml contains scandinavian letters , i got the following error, " 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) " The Request xml also contains encoding specification like Then i traced the pywps code and added the following line, inputXml = inputXml.encode("utf-8") But it gives the following error, 'module' object has no attribute 'parsers'. Whats the wrong in my code? Do any one implemented the pywps with scandinavian letters successfully? Do i need to change anything on pywps part or request xml? Waiting for suggestions, Thanks & Regards, Bala From notvalid at wathever.com Sun Nov 8 05:43:42 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 11:43:42 +0100 Subject: My own accounting python euler problem In-Reply-To: References: Message-ID: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Hi, > My first question is: > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > check Ch=600 > how can I print all the different combinations of invoices that the > check is possibly cancelling > Incidentally, I'm currently learning python myself, and was working on more or less the same problem as an exercise; For listing all different subsets of a list (This is what I came up with. Can it be implemented shorter, btw?): def subsets(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets(L[1:]): S.append(s) S.append(s + [ L[0]]) return S Now, to use the above piece of code (after 'import subset'): >>> subset.subsets([4,7,8,2]) [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, 4], [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] >>> map(sum,subset.subsets([4,7,8,2])) [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] It's not a real solution yet, and as others have pointed out the problem is NP complete but it might help to get you going. cheers, Ozz From rami.chowdhury at gmail.com Sun Nov 8 05:49:54 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 8 Nov 2009 02:49:54 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911071449.28713.rami.chowdhury@gmail.com> <4dc0cfea0911072359t41a9e96wadb46f4adad71f32@mail.gmail.com> Message-ID: <200911080249.55097.rami.chowdhury@gmail.com> On Saturday 07 November 2009 23:59:23 Victor Subervi wrote: > restorecon didn't change ls -lZ output Did the suggested changes to the Apache configuration help at all? > Can you give me the exact command for chcon? It complains there are too few > arguments, and I couldn't figure it out. For chcon, you probably want the 'unconfined_u' user setting, the 'object_r' role setting, and the 'httpd_sys_content_t' type setting. As 'chcon --help' tells us, you need to call it as follows: chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... Of course, here FILE can also be a directory, or the root of a directory tree, and the -R option will make chcon run recursively. > Does this really matter? I moved the selinux folder and its contents as > well as sent an "echo 0>..." command to kill it. I'm not certain -- have you tried confirming through programs such as system- config-securitylevel that it's off? > Furthermore, > [root at 13gems global_solutions]# ps wax|grep selinux > 17645 pts/0 S+ 0:00 grep selinux SELinux is a kernel subsystem -- it won't show up in the process list. > Please advise. > V > > On Sat, Nov 7, 2009 at 5:49 PM, Rami Chowdhury wrote: > > On Saturday 07 November 2009 13:51:06 Victor Subervi wrote: > > > httpd.conf: > > > > > > > > > ServerAdmin me at creative.vi > > > DocumentRoot /var/www/html/angrynates.com > > > ServerName angrynates.com > > > Options +ExecCGI -IncludesNoExec > > > > > > > You may want to change this to: > > > > > > If you want regular expression syntax, I would advise using the syntax > > > > or > > > > > > > #ls -lZ > > > drwxr-xr-x root root 1024 > > > drwxr-xr-x root root 1132 > > > drwxr-xr-x root root 1255 > > > > [snip] > > > > It looks like you don't have *any* SELinux context information; if > > SELinux is > > on, this will cause problems. Try using the 'restorecon' command to put > > the defaults in place, and consider using 'chcon' to change the security > > context > > to an appropriate one (I believe you want something like > > 'unconfined_u:object_r:httpd_sys_content_t' for Apache content). > > > > > On Sat, Nov 7, 2009 at 4:09 PM, Rami Chowdhury > > > > wrote: > > > > On Saturday 07 November 2009 06:13:11 Victor Subervi wrote: > > > > > I have a serious privileges problem that is making it impossible to > > > > > serve python pages on a CentOS server. It appears that nobody on > > > > > the CentOS discussion list has a solution to this problem. I'm > > > > > desperate and hoping someone on this list can help. > > > > > > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 11:50:40 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > Now, the file does exist: > > > > > > > > > > [root at 13gems global_solutions]# pwd > > > > > /var/www/html/angrynates.com/global_solutions > > > > > [root at 13gems global_solutions]# ls > > > > > .... > > > > > -rwxr-xr-x 1 victor victor 275 Nov 6 07:05 index.py > > > > > .... > > > > > and it serves just fine on another server, so there is no > > > > > "premature end > > > > > > > > of > > > > > > > > > script headers". > > > > > > > > > > > > > > > Here's where it gets really weird. If I copy the code for index.py > > > > and > > > > > > > template.py which the former calls, and create files test.py and > > > > > test2.py and paste the code from the former files in those new > > > > > files changing only the import statement from "template" to > > > > > "test2", the tests will resolve!! Now, the ownership and mode are > > > > > identical on all of them!! > > > > > > > > > > > > > > > [root at 13gems global_solutions]# ls -al | grep test.py > > > > > -rwxr-xr-x 1 root root 298 Nov 6 12:24 test.py > > > > > [root at 13gems global_solutions]# ls -al | grep test2.py > > > > > -rwxr-xr-x 1 root root 5716 Nov 6 12:25 test2.py > > > > > [root at 13gems global_solutions]# ls -al | grep index.py > > > > > -rwxr-xr-x 1 root root 316 Nov 6 07:05 index.py > > > > > [root at 13gems global_solutions]# ls -al | grep template.py > > > > > -rwxr-xr-x 1 root root 5806 Nov 6 07:06 template.py > > > > > -rwxr-xr-x 1 root root 6093 Nov 6 07:06 template.pyc > > > > > > > > > > where test.py is identical to index.py (other than the necessary > > > > > import) and template is identical to test2.py > > > > > > > > > > > > > > > fixfiles relabel /var/www/html > > > > > # might just work > > > > > It didn't > > > > > > > > > > touch /.autorelabel > > > > > # and then reboot will relabel all copied files to the correct > > > > contexts > > > > > > for > > > > > > > > > the location > > > > > I rebooted apache with no luck > > > > > > > > > > or you could turn off SELinux and reboot > > > > > I did that and the following two solutions with no luck: > > > > > echo 0 >/selinux/enforce > > > > > > > > > > [root at 13gems ~]# cd /etc/ > > > > > [root at 13gems etc]# mv selinux/ selinux.BAK > > > > > [root at 13gems etc]# mkdir selinux > > > > > [root at 13gems etc]# echo 0>/selinux/enforce > > > > > > > > > > ...and the problem continues: > > > > > [root at 13gems etc]# tail /var/log/httpd/error_log > > > > > [Fri Nov 06 12:51:49 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 12:56:18 2009] [error] [client 66.248.168.98] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] (2)No such > > > > > file > > > > > > > > or > > > > > > > > > directory: exec of '/var/www/html/ > > > > > > > > angrynates.com/global_solutions/index.py' > > > > > > > > > failed > > > > > [Fri Nov 06 12:56:20 2009] [error] [client 67.96.172.81] Premature > > > > end > > > > > > > of script headers: index.py > > > > > [Fri Nov 06 13:52:15 2009] [error] [client 66.249.67.153] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/robots.txt > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] (2)No > > > > > such file or directory: exec of > > > > > '/var/www/html/angrynates.com/global_solutions/index.py' failed, > > > > > > > > referer: > > > > > http://angrynates.com/global_solutions/ > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] Premature > > > > end > > > > > > of > > > > > > > > > script headers: index.py, referer: > > > > > > > > http://angrynates.com/global_solutions/ > > > > > > > > > [Fri Nov 06 13:52:52 2009] [error] [client 208.84.198.58] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > > [Fri Nov 06 13:52:53 2009] [error] [client 208.84.198.58] File does > > > > not > > > > > > > exist: /var/www/html/angrynates.com/favicon.ico > > > > > [root at 13gems etc]# > > > > > > > > > > Please help. > > > > > Victor > > > > > > > > Can we see the output of 'ls -lZ' and 'fixfiles check' on those > > > > directories, > > > > and see what the Apache (httpd.conf or .htaccess) configuration is > > > > for them? > > > > > > > > ---- > > > > Rami Chowdhury > > > > "Passion is inversely proportional to the amount of real information > > > > available." -- Benford's Law of Controversy > > > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > > ---- > > Rami Chowdhury > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From ben+python at benfinney.id.au Sun Nov 8 05:51:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Nov 2009 21:51:54 +1100 Subject: 'ascii' codec can't encode character u'\xe4' in position 4: ordinal not in range(128) References: Message-ID: <87ocnd47cl.fsf@benfinney.id.au> balavignesh writes: > Whats the wrong in my code? Without seeing your code, all we could do is guess, poorly. Far better would be if you can construct a very small example, one that you post here so any reader here could run it, that demonstrates the behaviour you want explained. Don't forget to say what you expect the code to do differently. -- \ ?I can picture in my mind a world without war, a world without | `\ hate. And I can picture us attacking that world, because they'd | _o__) never expect it.? ?Jack Handey | Ben Finney From rpjday at crashcourse.ca Sun Nov 8 07:14:00 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sun, 8 Nov 2009 07:14:00 -0500 (EST) Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, 8 Nov 2009, Ozz wrote: > > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning python myself, and was working > on more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] > else: > for s in subsets(L[1:]): > S.append(s) > S.append(s + [ L[0]]) > return S > > Now, to use the above piece of code (after 'import subset'): > > >>> subset.subsets([4,7,8,2]) > [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, 4], > [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] > >>> map(sum,subset.subsets([4,7,8,2])) > [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] > > It's not a real solution yet, and as others have pointed out the > problem is NP complete but it might help to get you going. does your solution allow for the possibility of different invoices of equal amounts? i would be reluctant to use the word "subset" in a context where you can have more than one element with the same value. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From notvalid at wathever.com Sun Nov 8 07:20:42 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 13:20:42 +0100 Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af6b799$0$83247$e4fe514c@news.xs4all.nl> Oops, > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] better to check for the empty set too, thus; if (len(L) == 0): return [[]] The order of the sets looks better too; >>> subset.subsets([1,2,3]) [[], [1], [2], [2, 1], [3], [3, 1], [3, 2], [3, 2, 1]] cheers, From notvalid at wathever.com Sun Nov 8 07:27:46 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 13:27:46 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Robert P. J. Day schreef: > does your solution allow for the possibility of different invoices > of equal amounts? i would be reluctant to use the word "subset" in a > context where you can have more than one element with the same value. I think it handles different invoices of equal amounts correctly. I agree with you though that the term subset may not be the best name in this context because of those duplicates. cheers, Ozz From sven at uni-hd.de Sun Nov 8 07:40:26 2009 From: sven at uni-hd.de (sven) Date: Sun, 8 Nov 2009 04:40:26 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: Message-ID: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> On Nov 8, 4:27?am, Carl Banks wrote: > It doesn't sound like the thread is communicating with the process > much. ?Therefore: There is quite a bit of communication -- the computation results are visulized while they are generated. > 1. Run the C code in a separate process, or > 2. Create the thread from a C extension, maybe even straight from > ctypes, and kill it from C or ctypes. The second option is a good idea. Thanks a lot, Carl! > > And why on earth doesn't that cancel method exist? There *are* good > > reasons to cancel a thread, just google for "terminate a Python > > thread" for tons of examples. > > Arguing that there are good reasons to allow killing threads isn't > going to get you very far. ?The language developers already know > killing a thread is useful, yet the disallowed it anyway. ?The > drawbacks were judged too severe (it makes enforcing invariants pretty > much impossible). I really don't get that. If the reason would be that it is too much work to implement, then I could accept it. But saying: We know it is useful, but we won't allow to do it, just does not seem reasonable. Thread cancellation might be generally unsafe, but there are cases when it is safe. It should be up to the user to decide it. There are many things that do harm if you don't use them correctly, and of course it would be a bad idea to remove all of them from Python. Well, I won't complain too much. At least some volunteers created that great language and gave it away for free :) Thanks again for your suggestion. Cheers, Sven From thom1948 at gmail.com Sun Nov 8 07:40:29 2009 From: thom1948 at gmail.com (Thomas) Date: Sun, 8 Nov 2009 04:40:29 -0800 (PST) Subject: How convert string '1e7' to an integer? References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Just a curiosity, why does Python do this? >>> l = [(base, int('1e7', base=base)) for base in range(15,37)] >>> l [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31, 1402), (32, 1479), (33, 1558), (34, 1639), (35, 1722), (36, 1807)] >>> l = ([base, int('1e7', base=base)] for base in range(15,37)) >>> l >>> From gil_johnson at earthlink.net Sun Nov 8 07:45:20 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Sun, 8 Nov 2009 04:45:20 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <2187be2d-56c0-4a5c-96d6-e0da13c30c76@j19g2000yqk.googlegroups.com> On Nov 6, 8:46?pm, gil_johnson wrote: > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil To all who asked about my previous post, I'm sorry I posted such a cryptic note before, I should have waited until I had the code available. I am still new to Python, and I couldn't find a way to create an array of size N, with each member initialized to a given value. If there is one, please let me know. I think Paul Rubin and Paul Rudin are right, if they really are 2 different people, an array is a better solution if you're dealing with integers. They both mention numpy, which I know nothing about, or the array module. kj, what *are* you going to do with this list/array? As others have pointed out, there are differences between lists, arrays, and dictionaries. The problem I was solving was this: I wanted an array of 32-bit integers to be used as a bit array, and I wanted it initialized with all bits set, that is, each member of the array had to be set to 4294967295. Of course, you could set your initializer to 0, or any other 32-bit number. Originally I found that the doubling method I wrote about before was a LOT faster than appending the elements one at a time, and tonight I tried the "list = initializer * N" method. Running the code below, the doubling method is still fastest, at least on my system. Of course, as long as you avoid the 'one at a time' method, we're talking about fractions of a second, even for arrays that I think are huge, like the 536,870,912 byte beastie below. [code] # Written in Python 3.x import array import time #* * * * * * * * * * * * * * * * * * * * * * # Doubling method, run time = 0.413938045502 t0 = time.time() newArray = array.array('I') # 32-bit unsigned integers newArray.append(4294967295) for i in range(27): # 2**27 integers, 2**29 bytes newArray.extend(newArray) print(time.time() - t0) print(newArray[134217727]) # confirm array is fully initialized #* * * * * * * * * * * * * * * * * * * * * * # One at a time, run time = 28.5479729176 t0 = time.time() newArray2 = array.array('I') for i in range(134217728): # the same size as above newArray2.append(4294967295) print(time.time() - t0) print(newArray2[134217727]) # confirm array #* * * * * * * * * * * * * * * * * * * * * * # List with "*", run time = 1.06160402298 t0 = time.time() newList = [4294967295] * 134217728 print(time.time() - t0) print(newList[134217727]) # confirm list [/code] If, instead of 134,217,728 integers, I want something different, like 100,000,000, the method I use is: [code] #* * * * * * * * * * * * * * * * * * * * * * # Not a power of 2, run time = 0.752086162567 t0 = time.time() newArray = array.array('I') tempArray = array.array('I') tempArray.append(4294967295) size = 100000000 while size: # chew through 'size' until it's gone if (size & 1): # if this bit of 'size' is 1 newArray.extend(tempArray) # add a copy of the temp array size >>= 1 # chew off one bit tempArray.extend(tempArray) # double the size of the temp array print(time.time() - t0) print(newArray[99999999]) #* * * * * * * * * * * * * * * * * * * * * * # # Not a power of 2, list with "*", run time = 1.19271993637 t0 = time.time() newList = [4294967295] * 100000000 print(time.time() - t0) print(newList[99999999]) [/code] I think it is interesting that the shorter list takes longer than the one that is a power of 2 in length. I think this may say that the "list = initializer * N" method uses something similar to the doubling method. Also, tempArray (above) gets reallocated frequently, and demonstrates that reallocation is not a big problem. Finally, I just looked into calling C functions, and found PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management section of the Python/C API Reference Manual. This gives you uninitialized memory, and should be really fast, but it's 6:45 AM here, and I don't have the energy to try it. Gil From gil_johnson at earthlink.net Sun Nov 8 08:08:35 2009 From: gil_johnson at earthlink.net (gil_johnson) Date: Sun, 8 Nov 2009 05:08:35 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: Message-ID: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> On Nov 6, 8:46?pm, gil_johnson wrote: > I don't have the code with me, but for huge arrays, I have used > something like: > > >>> arr[0] = initializer > >>> for i in range N: > >>> ? ? ?arr.extend(arr) > > This doubles the array every time through the loop, and you can add > the powers of 2 to get the desired result. > Gil To all who asked about my previous post, I'm sorry I posted such a cryptic note before, I should have waited until I had the code available. I am still new to Python, and I couldn't find a way to create an array of size N, with each member initialized to a given value. If there is one, please let me know. I think Paul Rubin and Paul Rudin are right, if they really are 2 different people, an array is a better solution if you're dealing with integers. They both mention numpy, which I know nothing about, or the array module. kj, what *are* you going to do with this list/array? As others have pointed out, there are differences between lists, arrays, and dictionaries. The problem I was solving was this: I wanted an array of 32-bit integers to be used as a bit array, and I wanted it initialized with all bits set, that is, each member of the array had to be set to 4294967295. Of course, you could set your initializer to 0, or any other 32-bit number. Originally I found that the doubling method I wrote about before was a LOT faster than appending the elements one at a time, and tonight I tried the "list = initializer * N" method. Running the code below, the doubling method is still fastest, at least on my system. Of course, as long as you avoid the 'one at a time' method, we're talking about fractions of a second, even for arrays that I think are huge, like the 536,870,912 byte beastie below. [code] # Written in Python 3.x import array import time #* * * * * * * * * * * * * * * * * * * * * * # Doubling method, run time = 0.413938045502 t0 = time.time() newArray = array.array('I') # 32-bit unsigned integers newArray.append(4294967295) for i in range(27): # 2**27 integers, 2**29 bytes newArray.extend(newArray) print(time.time() - t0) print(newArray[134217727]) # confirm array is fully initialized #* * * * * * * * * * * * * * * * * * * * * * # One at a time, run time = 28.5479729176 t0 = time.time() newArray2 = array.array('I') for i in range(134217728): # the same size as above newArray2.append(4294967295) print(time.time() - t0) print(newArray2[134217727]) # confirm array #* * * * * * * * * * * * * * * * * * * * * * # List with "*", run time = 1.06160402298 t0 = time.time() newList = [4294967295] * 134217728 print(time.time() - t0) print(newList[134217727]) # confirm list [/code] If, instead of 134,217,728 integers, I want something different, like 100,000,000, the method I use is: [code] #* * * * * * * * * * * * * * * * * * * * * * # Not a power of 2, run time = 0.752086162567 t0 = time.time() newArray = array.array('I') tempArray = array.array('I') tempArray.append(4294967295) size = 100000000 while size: # chew through 'size' until it's gone if (size & 1): # if this bit of 'size' is 1 newArray.extend(tempArray) # add a copy of the temp array size >>= 1 # chew off one bit tempArray.extend(tempArray) # double the size of the temp array print(time.time() - t0) print(newArray[99999999]) #* * * * * * * * * * * * * * * * * * * * * * # # Not a power of 2, list with "*", run time = 1.19271993637 t0 = time.time() newList = [4294967295] * 100000000 print(time.time() - t0) print(newList[99999999]) [/code] I think it is interesting that the shorter list takes longer than the one that is a power of 2 in length. I think this may say that the "list = initializer * N" method uses something similar to the doubling method. Also, tempArray (above) gets reallocated frequently, and demonstrates that reallocation is not a big problem. Finally, I just looked into calling C functions, and found PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management section of the Python/C API Reference Manual. This gives you uninitialized memory, and should be really fast, but it's 6:45 AM here, and I don't have the energy to try it. Gil From mad.mick at gmx.de Sun Nov 8 08:39:05 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 14:39:05 +0100 Subject: How convert string '1e7' to an integer? In-Reply-To: References: <5e01e423-5442-4d81-9bba-b7a80cdfde96@v30g2000yqm.googlegroups.com> Message-ID: Thomas wrote: > Just a curiosity, why does Python do this? > >>>> [(base, int('1e7', base=base)) for base in range(15,37)] > [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), > (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), > (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31, 1402), (32, > 1479), (33, 1558), (34, 1639), (35, 1722), (36, 1807)] >>>> ([base, int('1e7', base=base)] for base in range(15,37)) > Because the former is a list comprehension, whereas the latter is a generator expression. Mick. From exarkun at twistedmatrix.com Sun Nov 8 08:50:07 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 08 Nov 2009 13:50:07 -0000 Subject: Cancelling a python thread (revisited...) In-Reply-To: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <20091108135007.3229.420540105.divmod.xquotient.363@localhost.localdomain> On 12:40 pm, sven at uni-hd.de wrote: >On Nov 8, 4:27?am, Carl Banks wrote: >>It doesn't sound like the thread is communicating with the process >>much. ?Therefore: > >There is quite a bit of communication -- the computation results are >visulized while they are generated. I'm curious how this visualization works, since earlier you said something to the affect that there were no shared resources. If you kill a thread and it had opened a window and was drawing on it, with most toolkits, you'll end up with a window stuck in your screen, won't you? >[snip] > >I really don't get that. If the reason would be that it is too much >work to >implement, then I could accept it. But saying: We know it is useful, >but we >won't allow to do it, just does not seem reasonable. Thread >cancellation >might be generally unsafe, but there are cases when it is safe. It >should be >up to the user to decide it. There are many things that do harm if >you don't >use them correctly, and of course it would be a bad idea to remove all >of >them from Python. The CPython philosophy sort of follows the guideline that you should be allowed to do bad stuff if you want, except when that bad stuff would crash the interpreter (clearly ctypes is an exception to this rule of thumb). I think this is the argument that has been applied in opposition to adding thread termination in the past, though I don't remember for sure. Jean-Paul From solipsis at pitrou.net Sun Nov 8 08:52:17 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 8 Nov 2009 13:52:17 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: Le Sun, 08 Nov 2009 04:40:26 -0800, sven a ?crit?: > > I really don't get that. If the reason would be that it is too much > work to > implement, then I could accept it. It would probably be a lot of work and even then it would still be unsafe. Read for example: http://msdn.microsoft.com/en-us/library/ms686717%28VS.85%29.aspx ? TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems: * If the target thread owns a critical section, the critical section will not be released. * If the target thread is allocating memory from the heap, the heap lock will not be released. * If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent. * If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL. ? From rdbriggs at mun.ca Sun Nov 8 09:56:18 2009 From: rdbriggs at mun.ca (Rob Briggs) Date: Sun, 08 Nov 2009 11:26:18 -0330 Subject: Query about doing fortran-esque repeat formatting Message-ID: <1257692178.27566.38.camel@vostok.physics.mun.ca> Hello, Is there a way to do a repeat formatting command like in Fortran? Rather that doing this: print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) Something like this: print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], tmp[i][8], tmp[i][9]) regards, Rob From gb345 at invalid.com Sun Nov 8 10:20:42 2009 From: gb345 at invalid.com (gb345) Date: Sun, 8 Nov 2009 15:20:42 +0000 (UTC) Subject: Most efficient way to "pre-grow" a list? References: <4af5c216$0$715$426a74cc@news.free.fr> <1257621919.4af5c99fcd1f6@mail.uh.cu> <6faf39c90911071133k411b6de1r23f719b16b41eac@mail.gmail.com> Message-ID: In Luis Alberto Zarrabeitia Gomez writes: >?Have you ever tried to read list/matrix that you know it is not sparse, but you jdon't know the size, and it may not be in order? A "grow-able" array would just >be the right thing to use - currently I have to settle with either hacking >together my own grow-able array, or... >...Not hard, not worthy of a >PEP, but certainly not so easy to dismiss. I'm pretty new to Python, and I thought I'd give this a try: class array(list): """A list that grows as needed upon assignment. Any required padding is done with the value of the fill option. Attempts to retrieve an index greater than the maximum assigned index still produces an IndexError. """ def __init__(self, seq='', fill=None): super(array, self).__init__(seq) self.fill = fill @property def max(self): return len(self) - 1 def __setitem__(self, index, item): m = self.max while m < index: self.append(self.fill) m += 1 super(array, self).__setitem__(index, item) if __name__ == '__main__': x = array(('zero',)) x[3] = 'it works!' print x --------------------------------------------------------------------------- ['zero', None, None, 'it works!'] Looks like it works, but it seems almost too easy. Did I miss anything? Comments welcome. (E.g. I'm not sure that '' is the best choice of default value for the seq parameter to __init__.) Thanks in advance, Gabe From vasudevram at gmail.com Sun Nov 8 10:34:23 2009 From: vasudevram at gmail.com (vasudevram) Date: Sun, 8 Nov 2009 07:34:23 -0800 (PST) Subject: PySiteCreator v0.1 released Message-ID: <41ff557a-d691-4c1b-a94f-493cc3f3c620@h40g2000prf.googlegroups.com> Hi group, I've released a tool for creating HTML pages or Web sites by writing them in Python - PySiteCreator v0.1. Description of PySiteCreator: PySiteCreator is a tool that allows the user to create Web (HTML) sites by writing them entirely in Python. A user creates one or more Python source files in each of which they import a PySiteCreator helper module, and then call helper functions defined in that module, in order to emit HTML elements and associated content. They can then run the PySiteCreator program to process all those Python files; processing each Python file will result in the creation of a corresponding HTML file with the desired HTML elements and content. Some more details and the download link are available here on my blog: http://jugad2.blogspot.com/2009/11/early-release-of-pysitecreator-v01.html I appreciate any feedback on PySiteCreator. Thanks, Vasudev Ram Biz: www.dancingbison.com Products: www.dancingbison.com/products.html Blog on software innovation: jugad2.blogspot.com From luca at keul.it Sun Nov 8 10:57:37 2009 From: luca at keul.it (Luca Fabbri) Date: Sun, 8 Nov 2009 16:57:37 +0100 Subject: Need help for my system python Message-ID: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> Hi all. I've recently updated my system to the last Kubuntu 9.10. On my system I use: python2.6 (default system python) python 2.4 (needed for the Zope application server) Also I have 2 easy_install script for installing my eggs. The default one for python2.6 works normally, but I've some problems with using eggs for python 2.4 The easy_install procedure works (eggs are installed and I see no errors) but after that if I run the interpreter, it seems that no new libraries are installed. I know that this is very general question, but I'm wondering if some one had the same problem. Where I can look at for solving this? -- -- luca From mensanator at aol.com Sun Nov 8 11:08:55 2009 From: mensanator at aol.com (Mensanator) Date: Sun, 8 Nov 2009 08:08:55 -0800 (PST) Subject: Query about doing fortran-esque repeat formatting References: Message-ID: On Nov 8, 8:56?am, Rob Briggs wrote: > Hello, > > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], ?tmp[i][6], ?tmp[i][7], > tmp[i][8], ?tmp[i][9]) > > Something like this: > > print "%s 7%-5.3f % (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], > tmp[i][6], ?tmp[i][7], tmp[i][8], ?tmp[i][9]) > >>> s = '%s ' + ' %-5.4f' * 7 >>> s '%s %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f %-5.4f' >>> print s % ('s',1,2,3,4,5,6,7) s 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 > regards, > > Rob From luca at keul.it Sun Nov 8 11:27:29 2009 From: luca at keul.it (Luca Fabbri) Date: Sun, 8 Nov 2009 17:27:29 +0100 Subject: Need help for my system python In-Reply-To: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> References: <27308d500911080757x2eae59ecpb3f3caed70bf1bad@mail.gmail.com> Message-ID: <27308d500911080827q70c6ab8dy8a0f85ab03fe2f6c@mail.gmail.com> SOLVED. For some reason a "zope" directory were inside my site-packages folder, so the zope.interface egg was not visible... On Sun, Nov 8, 2009 at 4:57 PM, Luca Fabbri wrote: > Hi all. > > I've recently updated my system to the last Kubuntu 9.10. > > On my system I use: > python2.6 (default system python) > python 2.4 (needed for the Zope application server) > > Also I have 2 easy_install script for installing my eggs. > > The default one for python2.6 works normally, but I've some problems > with using eggs for python 2.4 > > The easy_install procedure works (eggs are installed and I see no > errors) but after that if I run the interpreter, it seems that no new > libraries are installed. > > I know that this is very general question, but I'm wondering if some > one had the same problem. > Where I can look at for solving this? > > -- > -- luca > -- -- luca From danb_83 at yahoo.com Sun Nov 8 11:52:37 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Sun, 8 Nov 2009 08:52:37 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 4:43?am, Ozz wrote: > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning python myself, and was working on > more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > ? ? ? ? ?S = [] > ? ? ? ? ?if (len(L) == 1): > ? ? ? ? ? ? ? ? ?return [L, []] > ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): > ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) > ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) > ? ? ? ? ?return S You can avoid the S list my making it a generator: def subsets(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] From redplusbluemakespurple at gmail.com Sun Nov 8 11:57:18 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Sun, 8 Nov 2009 08:57:18 -0800 (PST) Subject: Help with OS X installation Message-ID: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> I have python 2.6 on OS X 10.5.8: $ python --version Python 2.6.2 $ which python /Library/Frameworks/Python.framework/Versions/2.6/bin/python When installing an egg, python 2.5 shows up: """ $ sudo easy_install ipython-0.10-py2.6.egg Password: Processing ipython-0.10-py2.6.egg removing '/Library/Python/2.5/site-packages/ipython-0.10- py2.6.egg' (and everything under it) creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages """ But 2.6 is not here: $ ls /Library/Python 2.3/ 2.5/ Launching ipython happens with Python 2.5.1 though. Is there something I did incorrectly when installing python 2.6? Stephen From ngabonzizap72 at gmail.com Sun Nov 8 12:01:09 2009 From: ngabonzizap72 at gmail.com (NGABONZIZA PROSPER) Date: Sun, 8 Nov 2009 19:01:09 +0200 Subject: ODES Message-ID: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> Hi all; Help! Could you Tell me where I may find documentation on Solving Differential equations with Scipy or Numpy. Thank you all From deets at nospam.web.de Sun Nov 8 12:12:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 08 Nov 2009 18:12:12 +0100 Subject: Help with OS X installation In-Reply-To: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: <7locfcF3f1q68U1@mid.uni-berlin.de> stephen_b schrieb: > I have python 2.6 on OS X 10.5.8: > > $ python --version > Python 2.6.2 > > $ which python > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > When installing an egg, python 2.5 shows up: > > """ > $ sudo easy_install ipython-0.10-py2.6.egg > Password: > Processing ipython-0.10-py2.6.egg > removing '/Library/Python/2.5/site-packages/ipython-0.10- > py2.6.egg' (and everything under it) > creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg > Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages > """ > > But 2.6 is not here: > > $ ls /Library/Python > 2.3/ 2.5/ > > Launching ipython happens with Python 2.5.1 though. Is there something > I did incorrectly when installing python 2.6? You use the wrong easy_install - use easy_install-2.6. Diez From vicente.soler at gmail.com Sun Nov 8 12:16:27 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 8 Nov 2009 09:16:27 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 1:27?pm, Ozz wrote: > Robert P. J. Day schreef: > > > ? does your solution allow for the possibility of different invoices > > of equal amounts? ?i would be reluctant to use the word "subset" in a > > context where you can have more than one element with the same value. > > I think it handles different invoices of equal amounts correctly. > I agree with you though that the term subset may not be the best name in > this context because of those duplicates. > > cheers, > Ozz Ozz, Instead of subsets, do you mean permutations/combinations? Since 2 invoices can have the same amount perhaps the terms permutation is better. Vicente Soler From python at mrabarnett.plus.com Sun Nov 8 12:27:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 17:27:01 +0000 Subject: My own accounting python euler problem In-Reply-To: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4AF6FF65.9060603@mrabarnett.plus.com> Ozz wrote: > > Hi, > >> My first question is: >> 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >> check Ch=600 >> how can I print all the different combinations of invoices that the >> check is possibly cancelling >> > > Incidentally, I'm currently learning python myself, and was working on > more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] > else: > for s in subsets(L[1:]): > S.append(s) > S.append(s + [ L[0]]) > return S > > Now, to use the above piece of code (after 'import subset'): > > >>> subset.subsets([4,7,8,2]) > [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, > 4], [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] > >>> map(sum,subset.subsets([4,7,8,2])) > [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] > > It's not a real solution yet, and as others have pointed out the problem > is NP complete but it might help to get you going. > Here's my own take on it: def list_possible_invoices(invoices, check): if check: # The check hasn't yet been fully consumed. for index, inv in enumerate(invoices): # If this invoice doesn't exceed the check then it consume some of the check. if inv <= check: # Try to consume the remainder of the check. for inv_list in list_possible_invoices(invoices[index + 1 : ], check - inv): yield [inv] + inv_list else: # The check has been fully consumed. yield [] invoices = [500, 400, 450, 200, 600, 700] check = 600 # List all the possible subsets of invoices. # Sorting the invoices first in descending order lets us reduce the number of possibilities to try. for inv_list in list_possible_invoices(sorted(invoices, reverse=True), check): print inv_list From rami.chowdhury at gmail.com Sun Nov 8 12:28:41 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 8 Nov 2009 09:28:41 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> Message-ID: <200911080928.41802.rami.chowdhury@gmail.com> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t > httpd_sys_content_t global_solutions > chcon: can't apply partial context to unlabeled file global_solutions > Please advise. Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t global_solutions/*', which should specify the whole context at once and avoid that error, as well as apply it recursively to all files and subdirectories. Also, to narrow down the error, can you let us have the output of: tail /var/log/messages tail /var/log/httpd/error_log HTH, Rami ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From debatem1 at gmail.com Sun Nov 8 12:31:26 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:31:26 -0500 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: > On Nov 8, 4:43?am, Ozz wrote: >> Hi, >> >> > My first question is: >> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >> > check Ch=600 >> > how can I print all the different combinations of invoices that the >> > check is possibly cancelling >> >> Incidentally, I'm currently learning python myself, and was working on >> more or less the same problem as an exercise; >> >> For listing all different subsets of a list (This is what I came up >> with. Can it be implemented shorter, btw?): >> >> def subsets(L): >> ? ? ? ? ?S = [] >> ? ? ? ? ?if (len(L) == 1): >> ? ? ? ? ? ? ? ? ?return [L, []] >> ? ? ? ? ?else: >> ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): >> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) >> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) >> ? ? ? ? ?return S > > You can avoid the S list my making it a generator: > > def subsets(L): > ? ?if L: > ? ? ? ?for s in subsets(L[1:]): > ? ? ? ? ? ?yield s > ? ? ? ? ? ?yield s + [L[0]] > ? ?else: > ? ? ? ?yield [] What you're describing is the powerset operation. Here's the example from the python docs: def powerset(iterable): "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) What I find interesting is that running it through timeit, it is much slower than the code suggested by Dan Bishop. setup = """ from itertools import chain, combinations x = list(range(100)) def subsets1(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets1(L[1:]): S.append(s) S.append(s + [ L[0]]) return S def subsets2(L): if L: for s in subsets(L[1:]): yield s yield s + [L[0]] else: yield [] def subsets3(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) """ #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate timeit.timeit("subsets2(x)", setup) timeit.timeit("subsets3(x)", setup) I'm getting numbers roughly 3:1 in Dan's favor. Geremy Condra From debatem1 at gmail.com Sun Nov 8 12:36:39 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:36:39 -0500 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: On Sun, Nov 8, 2009 at 12:31 PM, geremy condra wrote: > On Sun, Nov 8, 2009 at 11:52 AM, Dan Bishop wrote: >> On Nov 8, 4:43?am, Ozz wrote: >>> Hi, >>> >>> > My first question is: >>> > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a >>> > check Ch=600 >>> > how can I print all the different combinations of invoices that the >>> > check is possibly cancelling >>> >>> Incidentally, I'm currently learning python myself, and was working on >>> more or less the same problem as an exercise; >>> >>> For listing all different subsets of a list (This is what I came up >>> with. Can it be implemented shorter, btw?): >>> >>> def subsets(L): >>> ? ? ? ? ?S = [] >>> ? ? ? ? ?if (len(L) == 1): >>> ? ? ? ? ? ? ? ? ?return [L, []] >>> ? ? ? ? ?else: >>> ? ? ? ? ? ? ? ? ?for s in subsets(L[1:]): >>> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s) >>> ? ? ? ? ? ? ? ? ? ? ? ? ?S.append(s + [ L[0]]) >>> ? ? ? ? ?return S >> >> You can avoid the S list my making it a generator: >> >> def subsets(L): >> ? ?if L: >> ? ? ? ?for s in subsets(L[1:]): >> ? ? ? ? ? ?yield s >> ? ? ? ? ? ?yield s + [L[0]] >> ? ?else: >> ? ? ? ?yield [] > > What you're describing is the powerset operation. Here's the example > from the python docs: > > def powerset(iterable): > ? ?"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" > ? ?s = list(iterable) > ? ?return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) > > What I find interesting is that running it through timeit, it is much > slower than the code suggested by Dan Bishop. > > setup = """ > from itertools import chain, combinations > > x = list(range(100)) > > def subsets1(L): > ? ? ? S = [] > ? ? ? if (len(L) == 1): > ? ? ? ? ? ? ? return [L, []] > ? ? ? else: > ? ? ? ? ? ? ? for s in subsets1(L[1:]): > ? ? ? ? ? ? ? ? ? ? ? S.append(s) > ? ? ? ? ? ? ? ? ? ? ? S.append(s + [ L[0]]) > ? ? ? return S > > def subsets2(L): > ? if L: > ? ? ? for s in subsets(L[1:]): > ? ? ? ? ? yield s > ? ? ? ? ? yield s + [L[0]] > ? else: > ? ? ? yield [] > > def subsets3(iterable): > ? ?s = list(iterable) > ? ?return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) > """ > > #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate > timeit.timeit("subsets2(x)", setup) > timeit.timeit("subsets3(x)", setup) > > > I'm getting numbers roughly 3:1 in Dan's favor. > > Geremy Condra > I made a mistake copying it on line 18 of the above; it should be subsets2, rather than just subsets. Geremy Condra From victorsubervi at gmail.com Sun Nov 8 12:40:58 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 8 Nov 2009 12:40:58 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <200911080928.41802.rami.chowdhury@gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> Message-ID: <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> [root at 13gems angrynates.com]# chcon -R -h unconfined_u:object_r:httpd_sys_content_t global_solutions/* Then I surfed to http://209.216.9.56/global_solutions/index.py [root at 13gems angrynates.com]# tail /var/log/messages Nov 8 04:26:02 13gems syslogd 1.4.1: restart. [root at 13gems angrynates.com]# tail /var/log/httpd/error_log [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest authentication ... [Sun Nov 08 05:35:10 2009] [notice] Digest: done [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session mutexes based on 10 max processes and 0 max threads. [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not exist: /var/www/html/angrynates.com/favicon.ico [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not exist: /var/www/html/angrynates.com/favicon.ico [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file or directory: exec of '/var/www/html/angrynates.com/global_solutions/index.py' failed, referer: http://209.216.9.56/global_solutions/ [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end of script headers: index.py, referer: http://209.216.9.56/global_solutions/ TIA, V On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury wrote: > On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: > > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t > > httpd_sys_content_t global_solutions > > chcon: can't apply partial context to unlabeled file global_solutions > > Please advise. > > Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t > global_solutions/*', which should specify the whole context at once and > avoid > that error, as well as apply it recursively to all files and > subdirectories. > > Also, to narrow down the error, can you let us have the output of: > tail /var/log/messages > tail /var/log/httpd/error_log > > HTH, > Rami > > ---- > Rami Chowdhury > "As an online discussion grows longer, the probability of a comparison > involving Nazis or Hitler approaches one." -- Godwin's Law > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Sun Nov 8 12:53:45 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 8 Nov 2009 12:53:45 -0500 Subject: ODES In-Reply-To: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> References: <42575ecd0911080901r5a249718x42a0c7a13bfd494e@mail.gmail.com> Message-ID: On Sun, Nov 8, 2009 at 12:01 PM, NGABONZIZA PROSPER wrote: > Hi all; > > > Help! > > Could you Tell me where I may find documentation ?on Solving > Differential equations ?with Scipy or Numpy. > > > > Thank you all > -- > http://mail.python.org/mailman/listinfo/python-list > http://lmgtfy.com/?q=solving+differential+equations+with+scipy ;) From benjamin.kaplan at case.edu Sun Nov 8 13:12:54 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Nov 2009 13:12:54 -0500 Subject: Help with OS X installation In-Reply-To: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: On Sun, Nov 8, 2009 at 11:57 AM, stephen_b wrote: > I have ?python 2.6 on OS X 10.5.8: > > $ python --version > Python 2.6.2 > > $ which python > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > When installing an egg, python 2.5 shows up: > > """ > $ sudo easy_install ipython-0.10-py2.6.egg > Password: > Processing ipython-0.10-py2.6.egg > removing '/Library/Python/2.5/site-packages/ipython-0.10- > py2.6.egg' (and everything under it) > creating /Library/Python/2.5/site-packages/ipython-0.10-py2.6.egg > Extracting ipython-0.10-py2.6.egg to /Library/Python/2.5/site-packages > """ > > But 2.6 is not here: > > $ ls /Library/Python > 2.3/ 2.5/ > > Launching ipython happens with Python 2.5.1 though. Is there something > I did incorrectly when installing python 2.6? > easy_install is not a part of Python- you have to download and install setuptools yourself. You never installed setuptools for python2.6 so the 2.5 version is still the default. http://pypi.python.org/pypi/setuptools > Stephen > -- > http://mail.python.org/mailman/listinfo/python-list > From wells at submute.net Sun Nov 8 13:15:06 2009 From: wells at submute.net (Wells) Date: Sun, 8 Nov 2009 10:15:06 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? Message-ID: I'm not quite understanding why a tuple is hashable but a list is not. Any pointers? Thanks! From digitalxero at gmail.com Sun Nov 8 13:31:09 2009 From: digitalxero at gmail.com (Dj Gilcrease) Date: Sun, 8 Nov 2009 11:31:09 -0700 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: On Sun, Nov 8, 2009 at 11:15 AM, Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! tuple is hashable because it is immutable whereas a list is mutable. From tycho at tycho.ws Sun Nov 8 13:33:12 2009 From: tycho at tycho.ws (Tycho Andersen) Date: Sun, 8 Nov 2009 12:33:12 -0600 (CST) Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: On Sun, 8 Nov 2009, Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! The keys of a dict have to be immutable. Lists are mutable, tuples are not. \t From nagle at animats.com Sun Nov 8 13:39:27 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 10:39:27 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <4af70e1b$0$1622$742ec2ed@news.sonic.net> Antoine Pitrou wrote: > Le Sun, 08 Nov 2009 04:40:26 -0800, sven a ?crit : >> I really don't get that. If the reason would be that it is too much >> work to >> implement, then I could accept it. > > It would probably be a lot of work and even then it would still be unsafe. > > Read for example: > http://msdn.microsoft.com/en-us/library/ms686717%28VS.85%29.aspx I'd argue against general thread cancellation. Inter-thread signals, though, have safety problems no worse than the first-thread only signals we have now. You're allowed to raise an exception in a signal handler, which is effectively thread cancellation. So right now, you can kill the first thread from another thread. John Nagle From python at mrabarnett.plus.com Sun Nov 8 13:52:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 08 Nov 2009 18:52:06 +0000 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: <4AF71356.9080602@mrabarnett.plus.com> Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! A hash is created from the object. If the object is mutable then the hash can change. Lists are mutable but tuples aren't. From mrholtsr at sbcglobal.net Sun Nov 8 14:01:37 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sun, 8 Nov 2009 14:01:37 -0500 Subject: Indentation problems Message-ID: I am having problems with indentation some times. When I hit the enter key after if statements or while statemt there are times when the indentation is too much and other times too little. When I try to manually make sure the indentation is correct and try to print, I ge the error message of invalid syntax or incorrect indentation. Can someone help me. Also when I open the edit window instead of the shell the programs tend not to run. Help! Ray -------------- next part -------------- An HTML attachment was scrubbed... URL: From notvalid at wathever.com Sun Nov 8 14:33:54 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 20:33:54 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <4af71d21$0$83241$e4fe514c@news.xs4all.nl> Dan Bishop schreef: > > You can avoid the S list my making it a generator: > > def subsets(L): > if L: > for s in subsets(L[1:]): > yield s > yield s + [L[0]] > else: > yield [] Nice one. Thanks! Ozz From solipsis at pitrou.net Sun Nov 8 14:34:00 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 8 Nov 2009 19:34:00 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> Message-ID: John Nagle animats.com> writes: > > I'd argue against general thread cancellation. Inter-thread > signals, though, have safety problems no worse than the first-thread > only signals we have now. You're allowed to raise an exception > in a signal handler, which is effectively thread cancellation. Can you give an example of such "cancellation"? In any case, this would be a side-effect of the current implementation, not officially supported behaviour. Regards Antoine. From nagle at animats.com Sun Nov 8 14:36:33 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 11:36:33 -0800 Subject: pyserial vs. Linux power save hibernate/resume - program hangs Message-ID: <4af71b7e$0$1645$742ec2ed@news.sonic.net> I have an application running with pyserial talking to a USB to serial converter on a Linux EeePC 2G Surf. This works. Until the lid on the PC is closed and the device suspends. The application has /dev/ttyUSB0 open, and has a read pending with a 1 second timeout. When the device comes out of suspend, the USB devices are enumerated again. The serial device moves to /dev/ttyUSB1, and the application continues to poll /dev/ttyUSB0. No error results from polling the removed device. So the application is stuck and doesn't know it. An attempt to write to the disconnected serial port produces an IOError exception, but the read side doesn't seem to notice. Any ideas? John Nagle From shoebox56carson at gmail.com Sun Nov 8 14:38:31 2009 From: shoebox56carson at gmail.com (Shue Boks) Date: Sun, 8 Nov 2009 11:38:31 -0800 (PST) Subject: Looking for help getting tkinter to work. References: <9e15ab12-c826-4227-9a0c-82d3eccb96a0@r24g2000prf.googlegroups.com> <9d0c476a-86f7-4a8a-a01b-e260060c7bcc@a31g2000yqn.googlegroups.com> Message-ID: <6d6c1d60-4cea-44b0-b309-95f13f94bba7@12g2000pri.googlegroups.com> On Nov 1, 6:27 am, Francesco Bochicchio wrote: > On Nov 1, 4:06 am, Shue Boks wrote: > > > > > I tried to compile Python and Tcl/Tk on Linux using the following > > files: > > > Python-3.1.1.tar.gz > > tcl8.5.7-src.tar.gz > > > Cannot get tkinter to work after compiling & installing Tcl/Tk. I get > > the following error after compiling Python: > > > "Python build finished, but the necessary bits to build these modules > > were not found: > > _tkinter > > To find the necessary bits, look in setup.py in detect_modules() for > > the module's name." > > > Are the above files the correct versions to get tkinter to work? > > > Thanks. > > The version should be ok. I just compiled python3.1 against tcl/tk > 8.5, only I used > the tcl/tk development packages coming with my distribution (Ubuntu). > I used > ./configure --with-tk, so if you did not, try that first. > > Did you run 'make install' during tcl/tk installation _before_ doing ./ > configure in python source > directory? > > If so, look where the library files ( e.g. libtk8.5.so ) and include > files (e.g tk.h ) have been placed > and check against the places where the function 'detect_tkinter' in > 'setup.py' looks for them. > > Ciao > ----- > FB Sorry for the late response, I only get a chance to play with this on the weekends. I tried everything mentioned above, but nothing seems to work. I did a "find / " on the two files libtk8.5.so and tk.h, it doesn't appear anywhere. I am really thinking that tcl8.5.7-src.tar.gz doesn't have the necessary files I need. I am using Puppy Linux which I am slowly giving up on. I love Puppy, but their distribution doesn't come with the tcl/tk development package that Ubuntu has. From torriem at gmail.com Sun Nov 8 14:39:10 2009 From: torriem at gmail.com (Michael Torrie) Date: Sun, 08 Nov 2009 12:39:10 -0700 Subject: Spam Bot, broken pipe In-Reply-To: References: Message-ID: <4AF71E5E.30300@gmail.com> Someone Something wrote: > I have a irc spam bot (only testing on my channel :P ) whose main loop is > the following: Poor choice of words on your part. Anything spam-related is evil and will not get a response. That said, "IRC bots" are certainly okay and common, and are useful tools. Some are even written in Python. From notvalid at wathever.com Sun Nov 8 14:42:09 2009 From: notvalid at wathever.com (Ozz) Date: Sun, 08 Nov 2009 20:42:09 +0100 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> Message-ID: <4af71f11$0$83241$e4fe514c@news.xs4all.nl> vsoler schreef: > > Instead of subsets, do you mean permutations/combinations? Since 2 > invoices can have the same amount perhaps the terms permutation is > better. > As some other poster already suggested 'powerset' ( http://en.wikipedia.org/wiki/Power_set ) may be a better name, except for those duplicates, of course. On the other hand, I think viewing it as a powerset is the most 'natural' in this case. (imo permutations are about the order of objects, not about whether the objects are included in a set or not) cheers, Ozz From tjreedy at udel.edu Sun Nov 8 14:45:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 Nov 2009 14:45:31 -0500 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: Alf P. Steinbach wrote: > * Hrvoje Niksic: >> "Alf P. Steinbach" writes: >> >>> * Hrvoje Niksic: >>>> "Alf P. Steinbach" writes: >>>> >>>>> Speedup would likely be more realistic with normal implementation (not >>>>> fiddling with bit-fields and stuff) >>>> I'm not sure I understand this. How would you implement tagged >>>> integers >>>> without encoding type information in bits of the pointer value? >>> A normal tag field, as illustrated in code earlier in the thread. >> >> Ah, I see it now. That proposal effectively doubles the size of what is >> now a PyObject *, meaning that lists, dicts, etc., would also double >> their memory requirements, so it doesn't come without downsides. > > Whether it increases memory usage depends on the data mix in the > program's execution. > > For a program primarily handling objects of atomic types (like int) it > saves memory, since each value (generally) avoids a dynamically > allocated object. > > Bit-field fiddling may save a little more memory, and is nearly > guaranteed to save memory. > > But memory usage isn't an issue except to the degree it affects the OS's > virtual memory manager. > > Slowness is an issue -- except that keeping compatibility is IMO a > more important issue (don't fix, at cost, what works). I believe the use of tagged pointers has been considered and so far rejected by the CPython developers. And no one else that I know of has developed a fork for that. It would seem more feasible with 64 bit pointers where there seem to be spare bits. But CPython will have to support 32 bit machines for several years. Terry Jan Reedy From python.list at tim.thechases.com Sun Nov 8 14:48:06 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 08 Nov 2009 13:48:06 -0600 Subject: Indentation problems In-Reply-To: References: Message-ID: <4AF72076.8020806@tim.thechases.com> > I am having problems with indentation some times. When I hit the enter key > after if statements or while statemt there are times when the indentation is > too much and other times too little. Which editor are you using? On which operating system? Check for settings regarding spaces-per-tab, whether the editor expands tabs to spaces, and where your tab-stops are. If you were using Vim, I'd tell you to look at your settings for :set ai? ts? sts? sw? et? cpo? si? cin? inde? any of which can be tweaked to adjust the behavior of automatic indenting. Your unnamed editor may have some similar options you can control. -tkc From nad at acm.org Sun Nov 8 15:21:13 2009 From: nad at acm.org (Ned Deily) Date: Sun, 08 Nov 2009 12:21:13 -0800 Subject: pyserial vs. Linux power save hibernate/resume - program hangs References: <4af71b7e$0$1645$742ec2ed@news.sonic.net> Message-ID: In article <4af71b7e$0$1645$742ec2ed at news.sonic.net>, John Nagle wrote: > I have an application running with pyserial talking to a USB to serial > converter on a Linux EeePC 2G Surf. This works. Until the lid on the PC is > closed and the device suspends. > > The application has /dev/ttyUSB0 open, and has a read pending > with a 1 second timeout. When the device comes out of suspend, > the USB devices are enumerated again. The serial device moves > to /dev/ttyUSB1, and the application continues to poll /dev/ttyUSB0. > No error results from polling the removed device. So the > application is stuck and doesn't know it. > > An attempt to write to the disconnected serial port produces > an IOError exception, but the read side doesn't seem to notice. If your Linux is new enough, you should be able to create a permanent device name for the serial converter using a udev rule. Then your code won't need to be dependent on the /dev/ttyUSBx device name. -- Ned Deily, nad at acm.org From mad.mick at gmx.de Sun Nov 8 15:42:21 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 08 Nov 2009 21:42:21 +0100 Subject: list vs tuple for a dict key- why aren't both hashable? In-Reply-To: References: Message-ID: Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. The short answer has already been given. Here is the long answer: For objects p and q, p==q implies hash(p)==hash(q). It is essential for dicts and sets that objects used as keys/elements uphold this law, and also that, for an object o, hash(o) doesn't change during the lifetime of o. What if you write a class that doesn't? Let's see: >>> class Thing(object): ... def __init__(self, value): ... self.value = value ... def __eq__(self, other): ... return self.value == other.value ... def __hash__(self): ... return hash(self.value) ... def __repr__(self): ... return "Thing(%s)" % self.value ... >>> >>> thinglist = [Thing(i) for i in xrange(10)] >>> >>> thingdict = dict((y,x) for x,y in enumerate(thinglist)) >>> >>> print thingdict[thinglist[5]] 5 >>> >>> thinglist[5].value = 99 >>> >>> print thingdict[thinglist[5]] Traceback (most recent call last): File "", line 1, in KeyError: Thing(99) What happened? __eq__ and __hash__ both depend on a mutable attribute, and when that attribute was changed, their outcome changed as well. If a Thing is stored as key in a dict and later it's value attribute is changed, it cannot be found anymore. Too bad. BTW, this doesn't work either: >>> print thingdict[Thing(5)] Traceback (most recent call last): File "", line 1, in KeyError: Thing(5) wheras this works: >>> print thingdict[Thing(6)] 6 What has this got to do with lists and tuples? Well, two tuples x and y are considered equal, iff: >>> all(a==b for a,b in zip(x,y)) Also, by the law above, hash(x)==hash(y). Since tuples are immutable, x and y (and hash(x) and hash(y)) will be equal as long as they live. Lists have the same properties regarding equality, but are mutable. If we'd use a list as key in a dict and append an element to the list, __eq__ and __hash__ would return something different than before the append. The list couldn't be found anymore, just like the instance of the broken Thing class above. Lists are not hashable, because it would lead to untraceable bugs otherwise, and it would confuse beginners. This also teaches a lesson on how to implement __eq__ and __hash__, if you must. Just make sure your objects always do uphold the law above, and do not change in respect to __hash__ during their lifetime. OTOH it is possible to do otherwise, as long as you don't try to use these objects as elements of a set or keys in a dictionary. But then, why would you bother to implement your own __hash__ method? Regards, Mick. From webtourist at gmail.com Sun Nov 8 16:20:23 2009 From: webtourist at gmail.com (webtourist) Date: Sun, 8 Nov 2009 13:20:23 -0800 (PST) Subject: on "Namespaces" Message-ID: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> New bie Question: in "Zen of Python" - what exactly does the last one mean ? - Namespaces are one honking great idea -- let's do more of those! I mean why the emphasis ? Is it like saying "put modules into packages" in other programming paradigm s ? thanks From emile at fenx.com Sun Nov 8 16:59:53 2009 From: emile at fenx.com (Emile van Sebille) Date: Sun, 08 Nov 2009 13:59:53 -0800 Subject: Most efficient way to "pre-grow" a list? In-Reply-To: <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> References: <9707e494-0041-4f2a-8ddc-ffe5a4e2b679@p35g2000yqh.googlegroups.com> <89e9f0ea-3e47-484a-be6a-0b615cb18bb0@y28g2000prd.googlegroups.com> Message-ID: On 11/7/2009 5:18 PM Carl Banks said... > I think the top one is O(N log N), and I'm suspicious that it's even > possible to grow a list in less than O(N log N) time without knowing > the final size in advance. Citation? Quoting Tim -- Python uses mildly exponential over-allocation, sufficient so that growing a list takes *amortized* O(1) time per append. Speed of indexed list access is much more important in most apps than speed of append, but Python has good O() behavior for both. O() behavior for deleting (or inserting) "in the middle" of a list is atrocious, though (O(len(list)). Life is a never-ending sequence of tradeoffs . -- For full context see http://groups.google.com/g/2e77fef2/t/82ee7a80757e84ab/d/6d1c154901794bb Emile From marko.loparic at gmail.com Sun Nov 8 17:41:27 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 8 Nov 2009 14:41:27 -0800 (PST) Subject: advice needed for lazy evaluation mechanism Message-ID: Hi, Could you please give me some advice on the piece of code I am writing? My system has several possible outputs, some of them are not always needed. I started to get confused with the code flow conditions needed to avoid doing unnecessary work. So I am trying to restructure it using lazy evaluation. In the new mechanism I am coding I have a repository with two types of objects: infos and routines. In the begining I have a list of routines. Each routine tells which infos it can compute. The execution is triggered when the value of an info is requested. In the example below I have 3 routines Routine "ReadData" computes info "gender" and info "birth_year" Routine "YearToAge" computes info "age" (using info "birth_year") Routine "ComputeMHF" computes info "max_heart_frequency" (using info "gender" and info "age") /--> gender ----------------------------\ ReadData --| | --> ComputeMHF -- > max_heart_frequency \--> birth_year --> YearToAge --> age --/ So for instance if all I need is info "age", only the routines "ReadData" and "YearToAge" are computed. The code below implements the example. There are 3 files: - test.py: the test case for the example - routines.py: the routines (classes) of the example - repository.py: the lazy evaluation mechanism (independent of the example) My questions are: - Is there a more standard (pythonic) way to do what I am trying to do? Are there libraries, design patterns, functional programming structures to use to achieve what I am looking for (i.e. am I trying to reinvent the wheel)? - Is the coding style good? - Can I avoid the eval command in Repository.add_routine? What I want there is to be able to have a generic code for the repository which does not depend on the files containing the routines I want it to hold. Note: The routines do not need to declare the info they depend on. They request the info in the computation phase. test.py === import unittest from repository import Repository ROUTINE_LIST = """ ReadData routines YearToAge routines ComputeMHF routines """ class Test(unittest.TestCase): def test_age(self): repo = Repository(ROUTINE_LIST) self.assertEqual(repo['age'], 30) def test_max_heart_frequency(self): repo = Repository(ROUTINE_LIST) self.assertEqual(repo['max_heart_frequency'], 181) === routines.py === from repository import AbstractRoutine class ReadData(AbstractRoutine): def __init__(self): super(ReadData, self).__init__(self.__class__.__name__, ['birth_year', 'gender']) def compute(self, repo): repo['birth_year'] = 1979 repo['gender'] = 'F' class YearToAge(AbstractRoutine): def __init__(self): super(YearToAge, self).__init__(self.__class__.__name__, ['age']) def compute(self, repo): repo['age'] = 2009 - repo['birth_year'] class ComputeMHF(AbstractRoutine): def __init__(self): super(ComputeMHF, self).__init__(self.__class__.__name__, ['max_heart_frequency']) def compute(self, repo): gender = repo['gender'] age = repo['age'] mhf = 211 - age if gender == 'F' else 205 - age repo['max_heart_frequency'] = mhf === repostory.py === from StringIO import StringIO class AbstractRoutine(object): def __init__(self, name, infos_provided): self.name = name self.infos_provided = infos_provided self.computed = False def compute(self): raise NotImplementedError class Info(object): def __init__(self, name, routine): self.name = name self.routine = routine self.computed = False self.value = None class Repository(object): def __init__(self, routine_definition_lines): self._infos = {} self.add_routines(routine_definition_lines) def add_routines(self, definition_lines): for line in StringIO(definition_lines): line = line.strip() if line == '': continue name, file_name = line.split() self.add_routine(name, file_name) def add_routine(self, class_name, file_name): routine = None # only to cheat pylint cmd = "from %s import %s\nroutine = %s()" % (file_name, class_name, class_name) exec(cmd) # XXX: ugly if not isinstance(routine, AbstractRoutine): raise ValueError('Class %s is not AbstractRoutine' % class_name) for info_name in routine.infos_provided: info = Info(info_name, routine) self._infos[info_name] = info def __setitem__(self, key, value): if key not in self._infos: raise ValueError('info %s not defined in repository' % key) info = self._infos[key] if info.computed: raise ValueError('info %s has already been computed' % key) info.value = value info.computed = True def __getitem__(self, key): if key not in self._infos: raise ValueError('info %s not defined in repository' % key) info = self._infos[key] if not info.computed: print('Calling routine %s to compute info %s' % (info.routine.name, info.name)) info.routine.compute(self) if not info.computed: raise ValueError('routine %s did not compute info %s' % (info.routine.name, key)) return info.value === Thanks a lot! Marko From lipun4u at gmail.com Sun Nov 8 17:46:24 2009 From: lipun4u at gmail.com (asit) Date: Sun, 8 Nov 2009 14:46:24 -0800 (PST) Subject: fetch all tweets.. Message-ID: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> This question is for any python-twitter developer I want to develop an application using python twitter . Just look at the code... import twitter api = twitter.Api(); sta = api.GetUserTimeline('ShashiTharoor') i = 0 for s in sta: i +=1 print str(i) + " " + s.text print print The above code only fetches 20 tweets. How can I fetch all tweets ?? From wells at submute.net Sun Nov 8 18:01:15 2009 From: wells at submute.net (Wells) Date: Sun, 8 Nov 2009 15:01:15 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? References: Message-ID: <659c7696-7cbe-426e-83b8-b8af5c6a3457@k19g2000yqc.googlegroups.com> On Nov 8, 2:42?pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. Here is the long answer: > > For objects p and q, p==q implies hash(p)==hash(q). It is essential for > dicts and sets that objects used as keys/elements uphold this law, and > also that, for an object o, hash(o) doesn't change during the lifetime > of o. What if you write a class that doesn't? Let's see: > > >>> class Thing(object): > > ... ? ? def __init__(self, value): > ... ? ? ? ? self.value = value > ... ? ? def __eq__(self, other): > ... ? ? ? ? return self.value == other.value > ... ? ? def __hash__(self): > ... ? ? ? ? return hash(self.value) > ... ? ? def __repr__(self): > ... ? ? ? ? return "Thing(%s)" % self.value > ... > > >>> thinglist = [Thing(i) for i in xrange(10)] > > >>> thingdict = dict((y,x) for x,y in enumerate(thinglist)) > > >>> print thingdict[thinglist[5]] > 5 > > >>> thinglist[5].value = 99 > > >>> print thingdict[thinglist[5]] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: Thing(99) > > What happened? __eq__ and __hash__ both depend on a mutable attribute, > and when that attribute was changed, their outcome changed as well. If a > Thing is stored as key in a dict and later it's value attribute is > changed, it cannot be found anymore. Too bad. > > BTW, this doesn't work either: > > >>> print thingdict[Thing(5)] > > Traceback (most recent call last): > ? File "", line 1, in > KeyError: Thing(5) > > wheras this works: > > >>> print thingdict[Thing(6)] > > 6 > > What has this got to do with lists and tuples? Well, two tuples x and y > are considered equal, iff: > > >>> all(a==b for a,b in zip(x,y)) > > Also, by the law above, hash(x)==hash(y). Since tuples are immutable, x > and y (and hash(x) and hash(y)) will be equal as long as they live. > > Lists have the same properties regarding equality, but are mutable. > If we'd use a list as key in a dict and append an element to the list, > __eq__ and __hash__ would return something different than before the > append. The list couldn't be found anymore, just like the instance of > the broken Thing class above. Lists are not hashable, because it would > lead to untraceable bugs otherwise, and it would confuse beginners. > > This also teaches a lesson on how to implement __eq__ and __hash__, if > you must. Just make sure your objects always do uphold the law above, > and do not change in respect to __hash__ during their lifetime. OTOH it > is possible to do otherwise, as long as you don't try to use these > objects as elements of a set or keys in a dictionary. But then, why > would you bother to implement your own __hash__ method? > > Regards, > Mick. Thanks Mick - this was very enlightening! From marko.loparic at gmail.com Sun Nov 8 18:04:54 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 8 Nov 2009 15:04:54 -0800 (PST) Subject: advice needed for lazy evaluation mechanism References: Message-ID: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Hi again, I put a copy of the message and the tarball of the code here (because of the problem of line breaks): http://python-advocacy.wikidot.com/comp-lang-python-question Thanks! Marko From mrholtsr at sbcglobal.net Sun Nov 8 18:13:15 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sun, 8 Nov 2009 18:13:15 -0500 Subject: Commenting and uncommenting from the shell Message-ID: <647DC539150C4636B450973AEDB318F9@ray> Can you comment and uncomment code from the shell. I know that the format meny only shows in the edit window. I tried crtl + 3, which is what it said in the configuration window to use, and nothing happens. Also can you write executable code from the edit window. I can't see to get code that I write there to execute. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 8 18:21:23 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 08 Nov 2009 17:21:23 -0600 Subject: fetch all tweets.. In-Reply-To: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> References: <2784b563-e8db-47c1-8872-09387e738a2a@g27g2000yqn.googlegroups.com> Message-ID: <4AF75273.6060708@tim.thechases.com> > This question is for any python-twitter developer while I don't use python-twitter, I do use Andrew Price's Twyt for my python+twitter scripting (I started to type "python+twitter scripting needs", but "needs" is SOOOOoooo not the right word for anything regarding twitter). > import twitter > > api = twitter.Api(); > sta = api.GetUserTimeline('ShashiTharoor') > i = 0 > for s in sta: > i +=1 > print str(i) + " " + s.text > print > > The above code only fetches 20 tweets. How can I fetch all tweets ?? I believe the API limits to 200 tweets. With twyt, I can just ask for .status_user_timeline(count=200) and get the last 200 tweets. I can also specify .status_user_timeline(count=200, since=tweet_id) to get those since a particular tweet. Your twitter API may have similar tools to specify the count, the starting ID, or the "page#" like twyt does. -tkc From sven at uni-hd.de Sun Nov 8 18:59:53 2009 From: sven at uni-hd.de (sven) Date: Sun, 8 Nov 2009 15:59:53 -0800 (PST) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> Message-ID: <310944e8-ee2e-4bcc-b7f3-6d736c2000a4@z41g2000yqz.googlegroups.com> On Nov 8, 2:50?pm, exar... at twistedmatrix.com wrote: > I'm curious how this visualization works, since earlier you said > something to the affect that there were no shared resources. ?If you > kill a thread and it had opened a window and was drawing on it, with > most toolkits, you'll end up with a window stuck in your screen, won't > you? The Python code passes an array to the C library which in the end contains the computation results. This array only contains some kind of counts which are incremented during the computation. The PyGTK GUI simply visualizes the current state of this array in regular intervals. The C library does not do any GUI stuff. Cancelling the thread really would not do any harm -- the thread only allocates memory on the stack, and the stack will vanish with the thread. > The CPython philosophy sort of follows the guideline that you should be > allowed to do bad stuff if you want, except when that bad stuff would > crash the interpreter (clearly ctypes is an exception to this rule of > thumb). Well, I am really glad about that exception. And following the hint of Carl, I will use it to call pthread_cancel or pthread_kill directly from the library. (Most certainly I also have to use ctypes to create my threads to be able to do this.) Cheers, Sven From clp2 at rebertia.com Sun Nov 8 19:18:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 8 Nov 2009 16:18:54 -0800 Subject: Commenting and uncommenting from the shell In-Reply-To: <647DC539150C4636B450973AEDB318F9@ray> References: <647DC539150C4636B450973AEDB318F9@ray> Message-ID: <50697b2c0911081618n47bca13bt1e227c7376422e06@mail.gmail.com> On Sun, Nov 8, 2009 at 3:13 PM, Ray Holt wrote: > Can you comment and uncomment code from the shell. I know that the format > meny only shows in the edit window. I tried crtl + 3, which is what it said > in the configuration window to use, and nothing happens. I'm assuming by "the shell" you mean IDLE's Python shell. You would do better to be less vague in the future. No, you can't use the un/comment features in the shell. Using them wouldn't make much sense anyway given the shell's interactive nature. > Also can you write > executable code from the edit window. I can't see to get code that I write > there to execute. Yes, of course. Press F5 or choose Run -> Run Module from the menu. Cheers, Chris -- http://blog.rebertia.com From fordhaivat at gmail.com Sun Nov 8 19:22:16 2009 From: fordhaivat at gmail.com (Someone Something) Date: Sun, 8 Nov 2009 19:22:16 -0500 Subject: Tax Calculator--Tkinter Message-ID: I'm writing a simple tax calculator with Tkinter (just for fun). Here's my current code: from Tkinter import *; class TaxCalc: def __init__(self, root): rate=Frame(root) rate.pack() income=Frame(root) income.pack() result=Frame(root) result.pack() self.rate=Entry(rate); self.rate.pack(); self.enterr=Button(rate) self.enterr['text']="Enter tax rate"; self.enterr['command']=self.getRate; self.enterr.pack() self.income=Entry(income); self.income.pack(); self.enteri=Button(income); self.enteri['text']="Enter income"; self.enterr['command']=self.getIncome; self.enteri.pack(); self.result=Entry(result); self.result.pack(); self.entere=Button(result); self.entere['text']="Get result"; self.entere['command']=self.printResult; self.entere.pack(); def getRate(self): srate=self.rate.get(); print "srate: ", srate; def getIncome(self): sincome=self.income.get(); print "sincome: ", sincome; def printResult(self): if self.nrate is None | self.nincome is None: print "Clear everything and start again."; print "Don't fool around with me."; else: self.nresult=float(((100-self.nrate)/100)*self.nincome); self.result.insert(END, str(self.nresult)); root=Tk() MyCalc=TaxCalc(root) root.mainloop() The thing is, that even if I put "12" in the result text field, get returns an empty string. How can I fix this? From python at mrabarnett.plus.com Sun Nov 8 19:34:24 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Nov 2009 00:34:24 +0000 Subject: advice needed for lazy evaluation mechanism In-Reply-To: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> References: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Message-ID: <4AF76390.5010103@mrabarnett.plus.com> markolopa wrote: > Hi again, > > I put a copy of the message and the tarball of the code here (because > of the problem of line breaks): > > http://python-advocacy.wikidot.com/comp-lang-python-question > Here's a slightly different approach: repository.py ============= class Repository(object): def __init__(self): self._providers = {} self._values = {} def add_provider(self, func, keys): for k in keys: self._providers[k] = func def __getitem__(self, key): if key not in self._values: self._providers[key](self) return self._values[key] def __setitem__(self, key, value): self._values[key] = value def register(*modules): "Register the provider modules and return a repository." repo = Repository() for mod in modules: # Scan the module for providers. # A provider is a function which lists what it provides in its __doc__ string. for name, value in mod.__dict__.items(): if callable(value) and value.__doc__: repo.add_provider(value, value.__doc__.split()) return repo routines.py =========== # The providers are functions which list what they provide in their __doc__ strings. def ReadData(repo): 'birth_year gender' repo['birth_year'] = 1979 repo['gender'] = 'F' def YearToAge(repo): 'age' repo['age'] = 2009 - repo['birth_year'] def ComputeMHF(repo): 'max_heart_frequency' gender = repo['gender'] age = repo['age'] mhf = 211 - age if gender == 'F' else 205 - age repo['max_heart_frequency'] = mhf test.py ======= import unittest import repository import routines class Test(unittest.TestCase): def test_age(self): repo = repository.register(routines) self.assertEqual(repo['age'], 30) def test_max_heart_frequency(self): repo = repository.register(routines) self.assertEqual(repo['max_heart_frequency'], 181) unittest.main() From python at mrabarnett.plus.com Sun Nov 8 19:50:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Nov 2009 00:50:58 +0000 Subject: Tax Calculator--Tkinter In-Reply-To: References: Message-ID: <4AF76772.20408@mrabarnett.plus.com> Someone Something wrote: > I'm writing a simple tax calculator with Tkinter (just for fun). > Here's my current code: > [snip] > def printResult(self): > if self.nrate is None | self.nincome is None: There's no such attribute as nrate or nincome. Also, "|" is the bitwise operator. You probably intended "or" instead. > print "Clear everything and start again."; > print "Don't fool around with me."; > else: > self.nresult=float(((100-self.nrate)/100)*self.nincome); > self.result.insert(END, str(self.nresult)); > Try this instead: def printResult(self): try: rate = float(self.rate.get()) income = float(self.income.get()) result = ((100.0 - rate) / 100.0) * income self.result.insert(END, str(result)) except ValueError: print "Clear everything and start again." print "Don't fool around with me." From gregory.j.baker at gmail.com Sun Nov 8 19:56:40 2009 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Sun, 8 Nov 2009 16:56:40 -0800 (PST) Subject: Query about doing fortran-esque repeat formatting References: Message-ID: <789ba085-5199-450f-9c5b-b5bf4e8767d7@r24g2000prf.googlegroups.com> How about: print ('%s ' + '%-5.4f ' * 7) % ('text',1,2,3,4,5,6,7) From patf at well.com Sun Nov 8 21:36:50 2009 From: patf at well.com (menomnon) Date: Sun, 8 Nov 2009 18:36:50 -0800 (PST) Subject: Debugging python in emacs isn't working. Message-ID: <4a54b1ba-0fd8-4947-9ca0-67d5c98de2d9@k13g2000prh.googlegroups.com> Hi, Emacs 22.3, python 2.6.4 Put the following into my .emacs: (setq pdb-path 'c:\\python26\\lib\\pdb.py gud-pdb-command-name (symbol-name pdb-path)) (defadvice pdb (before gud-query-cmdline activate) "Provide a better default command line when called interactively." (interactive (list (gud-query-cmdline pdb-path (file-name-nondirectory buffer-file-name))))) So when I'm in a python buffer (I've tried both python.el and python- mode.el) and do M-x pdb I get, say: c:\python26\lib\pdb.py rpytest.py hit and get an empty buffer that says "Comint: no process". And the status line says: "Spawning child process: invalid argument". I've run into "spawning child process: invalid argument" before but not being an emacs uber-geek I never solved it directly. Hope someone has an idea of what I'm doing wrong. From alan at baselinedata.co.uk Sun Nov 8 21:38:16 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 02:38:16 +0000 Subject: String prefix question Message-ID: <4AF78098.1060509@baselinedata.co.uk> In the Python.org 3.1 documentation (section 20.4.6), there is a simple ?Hello World? WSGI application which includes the following method... def hello_world_app(environ, start_response): status = b'200 OK' # HTTP Status headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers start_response(status, headers) # The returned object is going to be printed return [b"Hello World"] Question - Can anyone tell me why the 'b' prefix is present before each string? The method seems to work equally well with and without the prefix. From what I can gather from the documentation the b prefix represents a bytes literal, but can anyone explain (in simple english) what this means? Many thanks, Alan From ben+python at benfinney.id.au Sun Nov 8 22:01:23 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Nov 2009 14:01:23 +1100 Subject: String prefix question References: Message-ID: <87vdhk2ygs.fsf@benfinney.id.au> Alan Harris-Reid writes: > From what I can gather from the documentation the b prefix represents > a bytes literal Yes. In Python 3 there are two types with similar-looking literal syntax: ?str? and ?bytes?. The types are mutually incompatible (though they can be explicitly converted). > but can anyone explain (in simple english) what this means? It means the difference between ?a sequence of bytes? and ?a sequence of characters?. The two are not the same, have not ever been the same despite a long history in computing of handwaving the differences, and Python 3 finally makes them unambiguously distinct. A general solution wasn't even feasible for a long time, but now we have Unicode, a mature standard for uniformly representing all the world's writing systems in software. So Python 3 made ?str? the Unicode ?string of characters? type, and the ?'foo'? literal syntax creates objects of this type. The Python 3.1 documentation has a Unicode HOWTO that you should read . -- \ ?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 benjamin.kaplan at case.edu Sun Nov 8 22:04:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Nov 2009 22:04:04 -0500 Subject: String prefix question In-Reply-To: <4AF78098.1060509@baselinedata.co.uk> References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: On Sun, Nov 8, 2009 at 9:38 PM, Alan Harris-Reid wrote: > In the Python.org 3.1 documentation (section 20.4.6), there is a simple > ?Hello World? WSGI application which includes the following method... > > def hello_world_app(environ, start_response): > status = b'200 OK' # HTTP Status > headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers > start_response(status, headers) > > # The returned object is going to be printed > return [b"Hello World"] > > Question - Can anyone tell me why the 'b' prefix is present before each > string? The method seems to work equally well with and without the prefix. > From what I can gather from the documentation the b prefix represents a > bytes literal, but can anyone explain (in simple english) what this means? > > Many thanks, > Alan The rather long version: read http://www.joelonsoftware.com/articles/Unicode.html A somewhat shorter summary, along with how Python deals with this: Once upon a time, someone decided to allocate 1 byte for each character. Since everything the Americans who made the computers needed fit into 7 bits, this was alright. And they called this the American Standard Code for Information Interchange (ASCII). When computers came along, device manufacturers realized that they had 128 characters that didn't mean anything, so they all made their own characters to show for the upper 128. And when they started selling computers internationally, they used the upper 128 to store the characters they needed for the local language. This had several problems. 1) Files made by on one computer in one country wouldn't display right in a computer made by a different manufacturer or for a different country 2) The 256 characters were enough for most Western languages, but Chinese and Japanese need a whole lot more. To solve this problem, Unicode was created. Rather than thinking of each character as a distinct set of bits, it just assigns a number to each one (a code point). The bottom 128 characters are the original ASCII set, and everything else you could think of was added on top of that - other alphabets, mathematical symbols, music notes, cuneiform, dominos, mah jong tiles, and more. Unicode is harder to implement than a simple byte array, but it means strings are universal- every program will interpret them exactly the same. Unicode strings in python are the default ('') in Python 3.x and created in 2.x by putting a u in front of the string declaration (u'') Unicode, however, is a concept, and concepts can't be mapped to bits that can be sent through the network or stored on the hard drive. So instead we deal with strings internally as Unicode and then give them an encoding when we send them back out. Some encodings, such as UTF-8, can have multiple bytes per character and, as such, can deal with the full range of Unicode characters. Other times, programs still expect the old 8-bit encodings like ISO-8859-1 or the Windows Ansi code pages. In Python, to declare that the string is a literal set of bytes and the program should not try and interpret it, you use b'' in Python 3.x, or just declare it normally in Python 2.x (''). ------------------------------------------------------ What happens in your program: When you print a Unicode string, Python has to decide what encoding to use. If you're printing to a terminal, Python looks for the terminal's encoding and uses that. In the event that it doesn't know what encoding to use, Python defaults to ASCII because that's compatible with almost everything. Since the string you're sending to the web page only contains ASCII characters, the automatic conversion works fine if you don't specify the b''. Since the resulting page uses UTF-8 (which you declare in the header), which is compatible with ASCII, the output looks fine. If you try sending a string that has non-ASCII characters, the program might throw a UnicodeEncodeError because it doesn't know what bytes to use for those characters. It may be able to guess, but since I haven't used WSGI directly before, I can't say for sure. From SD_V897 at NoSuchMail.Com Sun Nov 8 22:04:55 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Mon, 09 Nov 2009 03:04:55 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Fri, 06 Nov 2009 21:19:44 GMT, SD_V897 > declaimed the following in gmane.comp.python.general: > >> AppPath=C:\Program Files\Utilities\Python Scripting v2.62\pythonw.exe > > That's an interesting path... Did the install path for Python (from > either python.org or activestate) change that much from 2.5.x, or is > that a custom install path (and is it the same path for the accounts it > works in). Especially as there is no "v2.62" to my knowledge... a 2.6.2, > OTOH... > > Now... I did change the upper level directory for mine (E:\; my C: > partition is rather packed, and I tend to install a lot of packages from > my user account), but the installer named top level was > "\Python25\pythonw.exe" > > I've added the folder directory to my PATH statement and also tried installing to the root but it doesn't make a difference. The 2.62 should be 2.64 my bad.. SD From redplusbluemakespurple at gmail.com Sun Nov 8 22:18:28 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Sun, 8 Nov 2009 19:18:28 -0800 (PST) Subject: Help with OS X installation References: <01b985ae-1e38-4a83-b54c-ec4c1c0b9a1f@m38g2000yqd.googlegroups.com> Message-ID: <81a156f8-47a3-4690-9df1-59ed62326c64@o10g2000yqa.googlegroups.com> Thanks all. That did it. From highcar at gmail.com Sun Nov 8 23:39:59 2009 From: highcar at gmail.com (elca) Date: Sun, 8 Nov 2009 20:39:59 -0800 (PST) Subject: disable image loading to speed up webpage load In-Reply-To: <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> References: <26155440.post@talk.nabble.com> <4gh7f5pqi17fijjbifur67ecufkkq8kti6@4ax.com> Message-ID: <26261219.post@talk.nabble.com> Tim Roberts wrote: > > elca wrote: >> >>im using win32com 's webbrowser module. > > Win32com does not have a webbrowser module. Do you mean you are using > Internet Explorer via win32com? > >>i have some question about it.. >>is it possible to disable image loading to speed up webpage load? > > If you are using IE, then you need to tell IE to disable image loading. I > don't know a way to do that through the IE COM interface. > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, yes right, i mean IE com interface. thanks for your reply.. if anyone can help much appreciate ! -- View this message in context: http://old.nabble.com/disable-image-loading-to-speed-up-webpage-load-tp26155440p26261219.html Sent from the Python - python-list mailing list archive at Nabble.com. From anthoniraja at gmail.com Sun Nov 8 23:49:13 2009 From: anthoniraja at gmail.com (Antony) Date: Sun, 8 Nov 2009 20:49:13 -0800 (PST) Subject: Choosing GUI Module for Python Message-ID: Hi all I just wanted to know which module is best for developing designing interface in python . i have come across some modules which are listed here . please tell your suggestions and comments to choose best one 1. PyGTK 2. PyQT 3. PySide 4. wxPython 5 . TKinter Also i need to know is there any IDE for developing these things . . . From nagle at animats.com Mon Nov 9 00:04:06 2009 From: nagle at animats.com (John Nagle) Date: Sun, 08 Nov 2009 21:04:06 -0800 Subject: Cancelling a python thread (revisited...) In-Reply-To: References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> Message-ID: <4af7a083$0$1677$742ec2ed@news.sonic.net> Antoine Pitrou wrote: > John Nagle animats.com> writes: >> I'd argue against general thread cancellation. Inter-thread >> signals, though, have safety problems no worse than the first-thread >> only signals we have now. You're allowed to raise an exception >> in a signal handler, which is effectively thread cancellation. > > Can you give an example of such "cancellation"? > In any case, this would be a side-effect of the current implementation, not > officially supported behaviour. It's not only documented behavior, it's an example in the official documentation. See http://docs.python.org/library/signal.html#example where an exception is raised in a signal handler. John Nagle From rt8396 at gmail.com Mon Nov 9 01:49:19 2009 From: rt8396 at gmail.com (r) Date: Sun, 8 Nov 2009 22:49:19 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> On Nov 8, 10:49?pm, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . You may want to offer a little more info, like what exactly you are looking to do with such GUI. are your needs for a VW, Corvette, or Mercedes? etc, etc. All these kits have pros and cons, some better for this some for that, yadda yadda From s.selvamsiva at gmail.com Mon Nov 9 02:21:33 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Mon, 9 Nov 2009 12:51:33 +0530 Subject: how to remove the same words in the paragraph In-Reply-To: <4AF0B54A.7090602@tim.thechases.com> References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: On Wed, Nov 4, 2009 at 4:27 AM, Tim Chase wrote: > kylin wrote: > >> I need to remove the word if it appears in the paragraph twice. could >> some give me some clue or some useful function in the python. >> > > Sounds like homework. To fail your class, use this one: > > >>> p = "one two three four five six seven three four eight" > >>> s = set() > >>> print ' '.join(w for w in p.split() if not (w in s or s.add(w))) > one two three four five six seven eight > > which is absolutely horrible because it mutates the set within the list > comprehension. The passable solution would use a for-loop to iterate over > each word in the paragraph, emitting it if it hadn't already been seen. > Maintain those words in set, so your words know how not to be seen. ("Mr. > Nesbitt, would you please stand up?") > > This also assumes your paragraph consists only of words and whitespace. > But since you posted your previous homework-sounding question on stripping > out non-word/whitespace characters, you'll want to look into using a regexp > like "[\w\s]" to clean up the cruft in the paragraph. Neither solution > above preserves non white-space/word characters, for which I'd recommend > using a re.sub() with a callback. Such a callback class might look > something like > > >>> class Dedupe: > ... def __init__(self): > ... self.s = set() > ... def __call__(self, m): > ... w = m.group(0) > ... if w in self.s: return '' > ... self.s.add(w) > ... return w > ... > >>> r.sub(Dedupe(), p) > > where I leave the definition of "r" to the student. Also beware of > case-differences for which you might have to normalize. > > You'll also want to use more descriptive variable names than my one-letter > tokens. > > -tkc > > > I think simple regex may come handy, p=re.compile(r'(.+) .*\1') #note the space s=p.search("python and i love python") s.groups() (' python',) But that matches for only one double word.Someone else could light up here to extract all the double words.Then they can be removed from the original paragraph. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam Sent from Bangalore, KA, India -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 9 02:39:34 2009 From: rt8396 at gmail.com (r) Date: Sun, 8 Nov 2009 23:39:34 -0800 (PST) Subject: Indentation problems References: Message-ID: <3de2d9d6-f4a8-4ecc-b86b-c3f4dd2373d3@n35g2000yqm.googlegroups.com> On Nov 8, 1:48?pm, Tim Chase wrote: > > I am having problems with indentation some times. When I hit the enter key > > after if statements or while statemt there are times when the indentation is > > too much and other times too little. Check for omitted brackets, braces and parenthesis. If you editor uses an auto indent function like even IDLE does then this will be the culprit! From anthoniraja at gmail.com Mon Nov 9 03:59:33 2009 From: anthoniraja at gmail.com (Antony) Date: Mon, 9 Nov 2009 00:59:33 -0800 (PST) Subject: Choosing GUI Module for Python References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> Message-ID: <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> On Nov 9, 11:49?am, r wrote: > On Nov 8, 10:49?pm, Antony wrote: > > > Hi all > > ? ?I just wanted to know which module is best for developing designing > > interface in python . > > i have come across some modules which are listed here . please tell > > your suggestions and comments to choose best one > > ?1. PyGTK > > ?2. PyQT > > ?3. PySide > > ?4. ?wxPython > > ?5 . TKinter > > > Also i need to know is there any IDE for developing these > > things . . . > > You may want to offer a little more info, like what exactly you are > looking to do with such GUI. are your needs for a ?VW, Corvette, or > Mercedes? etc, etc. All these kits have pros and cons, some better for > this some for that, yadda yadda I would like to know about that pros and cons only ... From highcar at gmail.com Mon Nov 9 06:48:19 2009 From: highcar at gmail.com (elca) Date: Mon, 9 Nov 2009 03:48:19 -0800 (PST) Subject: how to close not response win32 IE com interface Message-ID: <26265055.post@talk.nabble.com> hello, these day im making some script that use win32 IE com interface. one of problem is , my internet line is very slow, so sometimes my IE.navigate("http://www.example.com") not response timely. it looks hang and open status, not complete status. so my IE.navigate function is not correctly working. anyone can help me? in that case ,how to close or restart my script from start. thanks in advance Paul -- View this message in context: http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26265055.html Sent from the Python - python-list mailing list archive at Nabble.com. From deets at nospam.web.de Mon Nov 9 07:04:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 09 Nov 2009 13:04:30 +0100 Subject: installing library on MAC OS X 10.5.8 In-Reply-To: <9e367ea7-8a7d-4665-aa64-52a5cc705a18@h34g2000yqm.googlegroups.com> References: <9e367ea7-8a7d-4665-aa64-52a5cc705a18@h34g2000yqm.googlegroups.com> Message-ID: <7lqeqeF3e33mrU1@mid.uni-berlin.de> Xbiton schrieb: > Hi, > I'm new to mac and I'm having a lot of problems installing library on > mac ox x 10.5.8. > I want to install PyXML and although the install procedure - just done > like described on the web page of PyXML - That's a 5-years-old XML package. Don't use it. Your python2.5 already features element-tree, which is much nicer to use. Or is there a specific reason you need PyXML? Diez From zondo42 at googlemail.com Mon Nov 9 07:05:54 2009 From: zondo42 at googlemail.com (Glenn Hutchings) Date: Mon, 9 Nov 2009 12:05:54 +0000 (UTC) Subject: Query about doing fortran-esque repeat formatting References: <1257692178.27566.38.camel@vostok.physics.mun.ca> Message-ID: Rob Briggs mun.ca> writes: > Is there a way to do a repeat formatting command like in Fortran? Rather > that doing this: > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > tmp[i][8], tmp[i][9]) There certainly is. You can use python's string concatenation and repeat operators: print "%s" + " %-5.3f" * 7 % Glenn From dan.winsor at gmail.com Mon Nov 9 07:10:25 2009 From: dan.winsor at gmail.com (Dan Winsor) Date: Mon, 9 Nov 2009 04:10:25 -0800 (PST) Subject: username/password dialog prompt References: <10a1fedd-6e18-4cee-8243-a9be74032745@g23g2000yqh.googlegroups.com> <4af4904b$0$83240$e4fe514c@news.xs4all.nl> Message-ID: <6431ce76-6290-449d-a491-f884bf2ec2bc@e34g2000vbc.googlegroups.com> On Nov 6, 4:40?pm, Cousin Stanley wrote: > > My Tkinter is very rusty but perhaps you could do it > > something like this : ?http://pastebin.com/m5e49da19 > > > I forgot how to get rid of the empty root window > > that appears, sorry. > > ? root.withdraw() ? # should do it Thanks to you both - exactly what I was looking for. Much appreciated. -- Dan Winsor Soy un poco loco en el coco. From python.list at tim.thechases.com Mon Nov 9 07:13:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 09 Nov 2009 06:13:30 -0600 Subject: how to remove the same words in the paragraph In-Reply-To: References: <4db31091-dc03-4012-b6cb-87f0ab0f39cd@d9g2000prh.googlegroups.com> <4AF0B54A.7090602@tim.thechases.com> Message-ID: <4AF8076A.30005@tim.thechases.com> > I think simple regex may come handy, > > p=re.compile(r'(.+) .*\1') #note the space > s=p.search("python and i love python") > s.groups() > (' python',) > > But that matches for only one double word.Someone else could light up here > to extract all the double words.Then they can be removed from the original > paragraph. This has multiple problems: >>> p = re.compile(r'(.+) .*\1') >>> s = p.search("python one two one two python") >>> s.groups() ('python',) >>> s = p.search("python one two one two python one") >>> s.groups() # guess what happened to the 2nd "one"... ('python one',) and even once you have the list of theoretical duplicates (by changing the regexp to r'\b(\w+)\b.*?\1' perhaps), you still have to worry about emitting the first instance but not subsequent instances. -tkc From solipsis at pitrou.net Mon Nov 9 07:20:44 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 9 Nov 2009 12:20:44 +0000 (UTC) Subject: Cancelling a python thread (revisited...) References: <91c80174-6b60-4018-a208-3cf6973f5305@m26g2000yqb.googlegroups.com> <4af70e1b$0$1622$742ec2ed@news.sonic.net> <4af7a083$0$1677$742ec2ed@news.sonic.net> Message-ID: Le Sun, 08 Nov 2009 21:04:06 -0800, John Nagle a ?crit?: > Antoine Pitrou wrote: >> John Nagle animats.com> writes: >>> I'd argue against general thread cancellation. Inter-thread >>> signals, though, have safety problems no worse than the first-thread >>> only signals we have now. You're allowed to raise an exception in a >>> signal handler, which is effectively thread cancellation. >> >> Can you give an example of such "cancellation"? In any case, this would >> be a side-effect of the current implementation, not officially >> supported behaviour. > > It's not only documented behavior, it's an example in the official > documentation. See > > http://docs.python.org/library/signal.html#example Well, the only supported behaviour is to send signals to the main thread. Besides, it doesn't "cancel" the thread, it just raises an exception in it, which can be caught and silenced. Just try the following: import signal, time def handler(signum, frame): print 'Signal handler called with signal', signum raise IOError # Set the signal handler and a 5-second alarm signal.signal(signal.SIGALRM, handler) signal.alarm(2) try: time.sleep(10) except IOError: print "got IOError!" From jeanmichel at sequans.com Mon Nov 9 07:31:00 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 09 Nov 2009 13:31:00 +0100 Subject: Query about doing fortran-esque repeat formatting In-Reply-To: References: <1257692178.27566.38.camel@vostok.physics.mun.ca> Message-ID: <4AF80B84.2010200@sequans.com> Glenn Hutchings wrote: > Rob Briggs mun.ca> writes: > > >> Is there a way to do a repeat formatting command like in Fortran? Rather >> that doing this: >> >> print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % >> (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], >> tmp[i][8], tmp[i][9]) >> > > There certainly is. You can use python's string concatenation > and repeat operators: > > print "%s" + " %-5.3f" * 7 % > > Glenn > > data = tuple(parmName[i]) + tuple(tmp[i]) print "%s" + " %-5.3f" * len(tmp[i]) % data That should do the trick. JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From emin.shopper at gmail.com Mon Nov 9 07:45:32 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 9 Nov 2009 07:45:32 -0500 Subject: ANN: superpy 1.2.1 Message-ID: <32e43bb70911090445jf654264ha79d20a9edb3bc7e@mail.gmail.com> I am pleased to announce the release of superpy 1.2.1 available from http://code.google.com/p/superpy. As this is the first announcement of superpy, any comments and feedback would be much appreciated. ------------------ Superpy distributes python programs across a cluster of machines or across multiple processors on a single machine. This is a coarse-grained form of parallelism in the sense that remote tasks generally run in separate processes and do not share memory with the caller. Key features of superpy include: * Send tasks to remote servers or to same machine via XML RPC call * GUI to launch, monitor, and kill remote tasks * GUI can automatically launch tasks every day, hour, etc. * Works on the Microsoft Windows operating system o Can run as a windows service o Jobs submitted to windows can run as submitting user or as service user * Inputs/outputs are python objects via python pickle * Pure python implementation * Supports simple load-balancing to send tasks to best servers The ultimate vision for superpy is that you: 1. Install it as an always on service on a cloud of machines 2. Use the superpy scheduler to easily send python jobs into the cloud as needed 3. Use the SuperWatch GUI to track progress, kill tasks, etc. For smaller deployments, you can use superpy to take advantage of multiple processors on a single machine or multiple machines to maximize computing power. What makes superpy different than the many other excellent parallel processing packages already available for python? The superpy package is designed to allow sending jobs across a large number of machines (both Windows and LINUX). This requires the ability to monitor, debug, and otherwise get information about the status of jobs. While superpy is currently used in production for a number of different purposes, there are still many features we want to add. For a list of future plans and opportunities to help out or add to the discussion, please visit http://code.google.com/p/superpy/wiki/HelpImproveSuperpy. For a quick example of some of the the things superpy can do, check out http://code.google.com/p/superpy/wiki/Demos or in particular the demo application PyFog at http://code.google.com/p/superpy/wiki/PyFog. To install, you can use easy_install to try superpy via "easy_install superpy" or download a python egg from downloads. Of course, you will need python installed and if you are using windows, you should also install the python windows tools from http://sourceforge.net/projects/pywin32/files. See http://code.google.com/p/superpy/wiki/InstallFAQ if you have more questions about installation. From marko.loparic at gmail.com Mon Nov 9 08:14:19 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 9 Nov 2009 05:14:19 -0800 (PST) Subject: advice needed for lazy evaluation mechanism References: <11030418-2cc8-4707-83b2-658ad133111e@a31g2000yqn.googlegroups.com> Message-ID: <05e1446a-c579-43ef-89b3-324e1a2f32a5@37g2000yqm.googlegroups.com> On Nov 9, 1:34?am, MRAB wrote: > markolopa wrote: > > Hi again, > > > I put a copy of the message and the tarball of the code here (because > > of the problem of line breaks): > > >http://python-advocacy.wikidot.com/comp-lang-python-question > > Here's a slightly different approach: A clean and elegant solution, very impressive! Also a collection of nice Python features I had never used. Thanks a lot! Marko From pinkisntwell at gmail.com Mon Nov 9 08:53:00 2009 From: pinkisntwell at gmail.com (pinkisntwell) Date: Mon, 9 Nov 2009 05:53:00 -0800 (PST) Subject: OT: regular expression matching multiple occurrences of one group Message-ID: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> How can I make a regular expression that will match every occurrence of a group and return each occurrence as a group match? For example, for a string "-c-c-c-c-c", how can I make a regex which will return a group match for each occurrence of "-c"? From ssteinerx at gmail.com Mon Nov 9 09:21:33 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 09:21:33 -0500 Subject: Choosing GUI Module for Python In-Reply-To: <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> Message-ID: <2B0D56A2-8CEC-4FF1-AFF2-D7DA66F9A171@gmail.com> On Nov 9, 2009, at 3:59 AM, Antony wrote: >> >> You may want to offer a little more info, like what exactly you are >> looking to do with such GUI. are your needs for a VW, Corvette, or >> Mercedes? etc, etc. All these kits have pros and cons, some better >> for >> this some for that, yadda yadda > > I would like to know about that pros and cons only ... What might be a "pro" for one use case could easily be a "con" for another. For example, Kit-X may be infinitely configurable to run on everything from 800x600 to 1680x1050 pixel monitors with full viewport control, full zoom, pan, etc. and requires that all those cases be handled with correct configuration. That's great if you're writing an application that requires that. But, if you're writing a Pref Pane for OS X, which will never be any bigger than the pref-pane window and will only run on OS X, that particular kit might be a huge waste of time. The "pro" of infinite flexibility becomes a huge "con" for the OS X Pref Pane use-case. S From __peter__ at web.de Mon Nov 9 09:27:28 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Nov 2009 15:27:28 +0100 Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: J Wolfe wrote: > I would like to sort this dictionary by the values of the inner > dictionary ?ob? key. Python's built-in dictionary is unsorted by design. > mydict = > {?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?}, > ?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?} > } > > In this case, this would become: > > mysorteddic = > {?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?}, > ?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?} > } > > I have had no luck in trying to figure this out. I am restricted to > using python 2.4.3. > > Any help would be appreciated! You may be able to work around that limitation by putting the dict items into a list and sort that: >>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), reverse=True): ... print item ... ('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'}) ('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'}) ('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'}) Peter From victorsubervi at gmail.com Mon Nov 9 09:32:21 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 09:32:21 -0500 Subject: CGI vs mod_python Message-ID: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> Hi; I've been told by a server farm that they're having trouble getting my scripts to work because they're written with cgi calls as opposed to mod_python. Is there a basis for their complaint? These pages serve fine on another server. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Mon Nov 9 09:46:54 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 09:46:54 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> Message-ID: <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote: > Hi; > I've been told by a server farm that they're having trouble getting > my scripts to work because they're written with cgi calls as opposed > to mod_python. Is there a basis for their complaint? These pages > serve fine on another server. Does the server they're working fine on use CGI? Yes, they're different. S From rdbriggs at mun.ca Mon Nov 9 09:53:23 2009 From: rdbriggs at mun.ca (Rob Briggs) Date: Mon, 09 Nov 2009 11:23:23 -0330 Subject: Query about doing fortran-esque repeat formatting In-Reply-To: <4AF80B84.2010200@sequans.com> References: <1257692178.27566.38.camel@vostok.physics.mun.ca> <4AF80B84.2010200@sequans.com> Message-ID: <1257778403.19016.2.camel@vostok.physics.mun.ca> Thanks to the chaps who answered, I knew there would be an efficient answer to this. regards, Rob On Mon, 2009-11-09 at 13:31 +0100, Jean-Michel Pichavant wrote: > Glenn Hutchings wrote: > > Rob Briggs mun.ca> writes: > > > > > > > Is there a way to do a repeat formatting command like in Fortran? Rather > > > that doing this: > > > > > > print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" % > > > (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7], > > > tmp[i][8], tmp[i][9]) > > > > > > > There certainly is. You can use python's string concatenation > > and repeat operators: > > > > print "%s" + " %-5.3f" * 7 % > > > > Glenn > > > > > > data = tuple(parmName[i]) + tuple(tmp[i]) > print "%s" + " %-5.3f" * len(tmp[i]) % data > > That should do the trick. > > JM From kw at codebykevin.com Mon Nov 9 10:02:48 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 09 Nov 2009 10:02:48 -0500 Subject: Choosing GUI Module for Python In-Reply-To: References: Message-ID: <692af$4af82f19$4275d90a$2778@FUSE.NET> On 11/8/09 11:49 PM, Antony wrote: > Hi all > I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > 1. PyGTK > 2. PyQT > 3. PySide > 4. wxPython > 5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . > http://lmgtfy.com/?q=gui+toolkit+for+python -- Kevin Walzer Code by Kevin http://www.codebykevin.com From victorsubervi at gmail.com Mon Nov 9 10:18:36 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 10:18:36 -0500 Subject: CGI vs mod_python In-Reply-To: <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> Message-ID: <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Yes, obviously. But if CGI is enabled, it should work anyway, should it not? V On Mon, Nov 9, 2009 at 9:46 AM, ssteinerX at gmail.com wrote: > > On Nov 9, 2009, at 9:32 AM, Victor Subervi wrote: > > Hi; >> I've been told by a server farm that they're having trouble getting my >> scripts to work because they're written with cgi calls as opposed to >> mod_python. Is there a basis for their complaint? These pages serve fine on >> another server. >> > > Does the server they're working fine on use CGI? Yes, they're different. > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Mon Nov 9 10:29:54 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 10:29:54 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Message-ID: <6B4B78D7-110E-48AF-9307-1FCD04614717@gmail.com> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: > Yes, obviously. But if CGI is enabled, it should work anyway, should > it not? Depends on what "CGI is enabled" means. Usually, web servers are not set to just handle cgi scripts from anywhere, but only from specific file system locations. Otherwise, an an anonymous upload could be executed as CGI and wreak havoc. And "it should work anyway, should it not" is already answered by "they're having trouble getting my scripts to work." S From jamuah at gmail.com Mon Nov 9 10:45:57 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 17:45:57 +0200 Subject: [PYTHON] How to set the range for x-axis Message-ID: Hi Everyone, I have written a script in python to plot a graph. However, the range for the x-axis starts from 0.5 to 1.0. However, I would like to start from 0 to 1. Any pointer to this shall be appreciated. Thanks, Moses -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 9 10:46:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 09 Nov 2009 16:46:58 +0100 Subject: OT: regular expression matching multiple occurrences of one group In-Reply-To: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <7lqrriF3evehhU1@mid.uni-berlin.de> pinkisntwell schrieb: > How can I make a regular expression that will match every occurrence > of a group and return each occurrence as a group match? For example, > for a string "-c-c-c-c-c", how can I make a regex which will return a > group match for each occurrence of "-c"? Why is this flagged "OT"? And in python, you can't do that. Groups are based upon the lexical structure of the regexp, and thus have a fixed number of groups. Either use repetitive searches over the input, or postprocess the combined group by e.g. splitting it. Diez From clp2 at rebertia.com Mon Nov 9 10:49:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Nov 2009 07:49:33 -0800 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: Message-ID: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: > I have written a script in python to plot a graph. However, the > range for the x-axis starts from 0.5 to 1.0. However, I would like > to start from 0 to 1. Any pointer to this shall be appreciated. Some /very/ basic information such as what plotting library you're using would be necessary to answer your question. What version of Python you're using would also be useful. Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Mon Nov 9 10:52:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 10:52:39 -0500 Subject: CGI vs mod_python In-Reply-To: <65E266A7-DB3C-44D0-9085-8F0338FA29BC@gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <6B4B78D7-110E-48AF-9307-1FCD04614717@gmail.com> <4dc0cfea0911090741k5674c529xb6f9b4eb8fdc631a@mail.gmail.com> <65E266A7-DB3C-44D0-9085-8F0338FA29BC@gmail.com> Message-ID: <4dc0cfea0911090752t4d09587ap588d5e57329889ca@mail.gmail.com> Uuuuh. Thanks! V On Mon, Nov 9, 2009 at 10:45 AM, ssteinerX at gmail.com wrote: > On Nov 9, 2009, at 10:41 AM, Victor Subervi wrote: > > On Mon, Nov 9, 2009 at 10:29 AM, ssteinerX at gmail.com wrote: > >> >> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: >> >> Yes, obviously. But if CGI is enabled, it should work anyway, should it >>> not? >>> >> >> Depends on what "CGI is enabled" means. >> >> Usually, web servers are not set to just handle cgi scripts from anywhere, >> but only from specific file system locations. Otherwise, an an anonymous >> upload could be executed as CGI and wreak havoc. >> > > Of course, yes. > >> >> And "it should work anyway, should it not" is already answered by "they're >> having trouble getting my scripts to work." >> > > They're having _all_sorts_of_trouble_ getting my scripts to work, not just > this issue. These scripts worked fine on another server. I don't understand > what the problems are, and I'm trying to parameterize. > > > Gotcha. > > Do you have access to and have you given them the old httpd.conf? > > That could certainly give them some clues about what's different. > > Also, there is (on apache 2.x+ anyway) a whole directory tree full of > included files that get sucked in as the configuration is getting built so > that whole tree would give them everything they would need (if they know how > to work from it which they should if they're running a "server farm"). > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Mon Nov 9 10:59:53 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 07:59:53 -0800 (PST) Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <6236e9a0-7662-4935-a65d-6cbcd61c6f92@o10g2000yqa.googlegroups.com> On Nov 9, 1:53?pm, pinkisntwell wrote: > How can I make a regular expression that will match every occurrence > of a group and return each occurrence as a group match? For example, > for a string "-c-c-c-c-c", how can I make a regex which will return a > group match for each occurrence of "-c"? As well as what Diez has said, unless you absolutely want regexp's, and by the sounds of it I'm guessing you may be after something more flexible: what about the pyparsing module [1]. It handles your situation quite nicely. >>> import pyparsing >>> parser = pyparsing.ZeroOrMore('-c') >>> parser.parseString('-c-c-c-c-c-c') (['-c', '-c', '-c', '-c', '-c', '-c'], {}) hth, Jon. [1] http://pyparsing.wikispaces.com/ From alfps at start.no Mon Nov 9 11:10:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 17:10:31 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) Message-ID: Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. It's now Python 3.x, and reworked with lots of graphical examples and more explanatory text, plus limited in scope to Basic Concepts (which I previously just had as a first ch 2 section -- but there's rather a lot of concepts!). I think it's wise to invite comments even when it's not 100% completed. First, because as opposed to ch 1 there is quite a bit of code here, and since I'm a Python newbie I may be using non-idiomatic constructs, not to mention doing worse things. :-) Second, because comments in general can improve the text. Contents: 2.1 Super-basic concept: why programming is not DWIM. 1 2.2 Reported errors. 4 2.2.1 Case-sensitity. 4 2.2.2 Syntax / compilation errors. 4 2.2.3 Runtime errors / crashes. 5 2.3 A programming exploration tool: turtle graphics. 6 2.4 Naming things. 8 2.4.1 Naming actions: routines. 8 2.4.2 Naming data part I: variables. 11 2.4.3 Naming data part II: routine arguments. 13 2.5 Controlling the flow of execution. 14 2.5.1 Repeating actions automatically: loops. 14 2.5.2 Basic comparisions & boolean values. 16 2.5.3 Interlude I: a function graph program / about types. 17 2.5.4 Automated action choices. 21 2.5.5 Value-producing (function-like) routines. 23 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 2.5.7 Dynamically nested actions: recursive routines. 28 2.6 Objects. [Not started on this] 31 2.7 Collections. [Not started on this] 31 In Google Docs (both chapters available here): Formats: PDF Cheers, - Alf From jamuah at gmail.com Mon Nov 9 11:43:25 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 18:43:25 +0200 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: Hi Chris, I am using python 2.6 and am using scipy and pylab. See the code below. Cheers. from scipy import * from pylab import * x1 = [0.5,0.6,0.7,0.8,0.9,1.0] x2 = [0,1,2,3,4,5,6,7,8,9,10] plot(x1,y01,linewidth=5.0) show() Thanks. . On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert wrote: > On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: > > I have written a script in python to plot a graph. However, the > > range for the x-axis starts from 0.5 to 1.0. However, I would like > > to start from 0 to 1. Any pointer to this shall be appreciated. > > Some /very/ basic information such as what plotting library you're > using would be necessary to answer your question. What version of > Python you're using would also be useful. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jamuah at gmail.com Mon Nov 9 11:46:09 2009 From: jamuah at gmail.com (Moses) Date: Mon, 9 Nov 2009 18:46:09 +0200 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: Hi Chris, The code is from scipy import * from pylab import * x = [0.5,0.6,0.7,0.8,0.9,1.0] y = [2,6,8,10,10,10] plot(x,y,linewidth=5.0) show() and not from scipy import * from pylab import * x1 = [0.5,0.6,0.7,0.8,0.9,1.0] x2 = [0,1,2,3,4,5,6,7,8,9,10] plot(x1,y01,linewidth=5.0) show() Moses On Mon, Nov 9, 2009 at 6:43 PM, Moses wrote: > > Hi Chris, > > I am using python 2.6 and am using scipy and pylab. See the code below. > Cheers. > > from scipy import * > from pylab import * > > x1 = [0.5,0.6,0.7,0.8,0.9,1.0] > x2 = [0,1,2,3,4,5,6,7,8,9,10] > > plot(x1,y01,linewidth=5.0) > show() > > Thanks. > . > > > > On Mon, Nov 9, 2009 at 5:49 PM, Chris Rebert wrote: > >> On Mon, Nov 9, 2009 at 7:45 AM, Moses wrote: >> > I have written a script in python to plot a graph. However, the >> > range for the x-axis starts from 0.5 to 1.0. However, I would like >> > to start from 0 to 1. Any pointer to this shall be appreciated. >> >> Some /very/ basic information such as what plotting library you're >> using would be necessary to answer your question. What version of >> Python you're using would also be useful. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Mon Nov 9 11:53:43 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 09 Nov 2009 16:53:43 +0000 Subject: String prefix question In-Reply-To: <4AF78098.1060509@baselinedata.co.uk> References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: Alan Harris-Reid wrote: > In the Python.org 3.1 documentation (section 20.4.6), there is a simple > ?Hello World? WSGI application which includes the following method... > > def hello_world_app(environ, start_response): > status = b'200 OK' # HTTP Status > headers = [(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers > start_response(status, headers) > > # The returned object is going to be printed > return [b"Hello World"] > > Question - Can anyone tell me why the 'b' prefix is present before each > string? The method seems to work equally well with and without the > prefix. From what I can gather from the documentation the b prefix > represents a bytes literal, but can anyone explain (in simple english) > what this means? > > Many thanks, > Alan Another link: http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror From joncle at googlemail.com Mon Nov 9 11:54:40 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 08:54:40 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: Message-ID: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> On Nov 9, 4:10?pm, "Alf P. Steinbach" wrote: > Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > It's now Python 3.x, and reworked with lots of graphical examples and more > explanatory text, plus limited in scope to Basic Concepts (which I previously > just had as a first ch 2 section ?-- ?but there's rather a lot of concepts!). > > I think it's wise to invite comments even when it's not 100% completed. First, > because as opposed to ch 1 there is quite a bit of code here, and since I'm a > Python newbie I may be using non-idiomatic constructs, not to mention doing > worse things. :-) Second, because comments in general can improve the text. > > Contents: > > 2.1 Super-basic concept: why programming is not DWIM. ? 1 > 2.2 Reported errors. ? ?4 > 2.2.1 ? Case-sensitity. 4 > 2.2.2 ? Syntax / compilation errors. ? ?4 > 2.2.3 ? Runtime errors / crashes. ? 5 > 2.3 A programming exploration tool: turtle graphics. ? ?6 > 2.4 Naming things. ?8 > 2.4.1 ? Naming actions: routines. ? 8 > 2.4.2 ? Naming data part I: variables. ?11 > 2.4.3 ? Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. ?14 > 2.5.1 ? Repeating actions automatically: loops. 14 > 2.5.2 ? Basic comparisions & boolean values. ? ?16 > 2.5.3 ? Interlude I: a function graph program / about types. ? ?17 > 2.5.4 ? Automated action choices. ? 21 > 2.5.5 ? Value-producing (function-like) routines. ? 23 > 2.5.6 ? Interlude II: a graph with zeroes marked / about program structure. 26 > 2.5.7 ? Dynamically nested actions: recursive routines. 28 > 2.6 Objects. ? ? [Not started on this] 31 > 2.7 Collections. ? ?[Not started on this] 31 > > In Google Docs (both chapters available here): > > ? ? ? > ? ? ?Formats: PDF > > Cheers, > > - Alf Well, you may not like it, but it is perfectly acceptable and indeed promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use of a well understood and oft-used idiom. I they're a lot of them, you generally have a settings module, that just lists all of the 'constants' (.h files effectively). "Technically line_length is a variable"...: No - it's a name that binds to an object that happens to be an integer. You've participated in discussions re: this. Similarly 'number_of_apples = number_of_apples + 1' is not an assignment ;) It's nit-picky and I realise you're trying to keep it simple, but as it's meant for new programmers to the Python language, then introduce them to Python's way of "variables", they'll thank you for it later... (or run screaming, or start another thread here...) I've never seen/heard != described as "different from"; what's wrong with "not equal to"? And why no mention of 'not' (should be mentioned with booleans surely?). That's as far as I've got; might get around to reading more later... Cool tree at the end :) Cheers, Jon From sln at netherlands.com Mon Nov 9 11:55:33 2009 From: sln at netherlands.com (sln at netherlands.com) Date: Mon, 09 Nov 2009 08:55:33 -0800 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: On Mon, 9 Nov 2009 05:53:00 -0800 (PST), pinkisntwell wrote: >How can I make a regular expression that will match every occurrence >of a group and return each occurrence as a group match? For example, >for a string "-c-c-c-c-c", how can I make a regex which will return a >group match for each occurrence of "-c"? Is this a ludicrous question, or is it meant for the python group? use strict; use warnings; my @matches = "-c-c-c-c-c" =~ /(-c)/g; print "\n at matches\n"; @matches = (); "-c-a-c-c-c" =~ /(?:(-c)(?{push @matches, $^N})|.)+/x; print "@matches\n"; -sln From jurgenex at hotmail.com Mon Nov 9 12:18:54 2009 From: jurgenex at hotmail.com (Jürgen Exner) Date: Mon, 09 Nov 2009 09:18:54 -0800 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> Message-ID: <1jjgf5h1jutiqcdfld6atgv5i87djb4iqp@4ax.com> pinkisntwell wrote: >How can I make a regular expression that will match every occurrence >of a group and return each occurrence as a group match? For example, >for a string "-c-c-c-c-c", how can I make a regex which will return a >group match for each occurrence of "-c"? Where is the problem? The most straight-forward, simplest approach works just fine: use strict; use warnings; my $s = '-c-c-c-c-c'; my @matched = $s=~/-c/g; print "Found ". @matched . " occurences of '-c':\n"; print join "\n", @matched; Or did you forget to use the g modifier? jue From alfps at start.no Mon Nov 9 12:22:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 18:22:36 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: * Jon Clements: > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. >> >> It's now Python 3.x, and reworked with lots of graphical examples and more >> explanatory text, plus limited in scope to Basic Concepts (which I previously >> just had as a first ch 2 section -- but there's rather a lot of concepts!). >> >> I think it's wise to invite comments even when it's not 100% completed. First, >> because as opposed to ch 1 there is quite a bit of code here, and since I'm a >> Python newbie I may be using non-idiomatic constructs, not to mention doing >> worse things. :-) Second, because comments in general can improve the text. >> >> Contents: >> >> 2.1 Super-basic concept: why programming is not DWIM. 1 >> 2.2 Reported errors. 4 >> 2.2.1 Case-sensitity. 4 >> 2.2.2 Syntax / compilation errors. 4 >> 2.2.3 Runtime errors / crashes. 5 >> 2.3 A programming exploration tool: turtle graphics. 6 >> 2.4 Naming things. 8 >> 2.4.1 Naming actions: routines. 8 >> 2.4.2 Naming data part I: variables. 11 >> 2.4.3 Naming data part II: routine arguments. 13 >> 2.5 Controlling the flow of execution. 14 >> 2.5.1 Repeating actions automatically: loops. 14 >> 2.5.2 Basic comparisions & boolean values. 16 >> 2.5.3 Interlude I: a function graph program / about types. 17 >> 2.5.4 Automated action choices. 21 >> 2.5.5 Value-producing (function-like) routines. 23 >> 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 >> 2.5.7 Dynamically nested actions: recursive routines. 28 >> 2.6 Objects. [Not started on this] 31 >> 2.7 Collections. [Not started on this] 31 >> >> In Google Docs (both chapters available here): >> >> >> Formats: PDF >> >> Cheers, >> >> - Alf > > Well, you may not like it, but it is perfectly acceptable and indeed > promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use > of a well understood and oft-used idiom. I they're a lot of them, you > generally have a settings module, that just lists all of the > 'constants' (.h files effectively). Yeah, I thought of that angle so I emphasized 'programs'. As it happens about half or more of the variables in the examples are constants. All uppercase convention for that would be ugly to me. :-) > "Technically line_length is a variable"...: No - it's a name that > binds to an object that happens to be an integer. You've participated > in discussions re: this. Similarly 'number_of_apples = > number_of_apples + 1' is not an assignment ;) Ah, you're kidding. Probably. Anyways, that's the terminology employed by the language reference, and even if it wasn't I'd use it because this is primarily introduction to programming in general, where Python just happens to be the vehicle; thus, language independent terminology preferred (e.g., I use "routine" instead of C/Python "function"). > It's nit-picky and I > realise you're trying to keep it simple, but as it's meant for new > programmers to the Python language, then introduce them to Python's > way of "variables", they'll thank you for it later... (or run > screaming, or start another thread here...) Yeah, good point, thanks! But it will have to wait till I get down into details... ;-) > I've never seen/heard != described as "different from"; what's wrong > with "not equal to"? Thanks! > And why no mention of 'not' (should be mentioned > with booleans surely?). Again, I'll discuss that later. It's just too much to bring up. Most of my work with this has been to pare down to essentials and *remove* stuff I'd written. > That's as far as I've got; might get around to reading more later... > > Cool tree at the end :) Thanks! Cheers, - Alf From ssteinerx at gmail.com Mon Nov 9 12:32:18 2009 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 9 Nov 2009 12:32:18 -0500 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: <3C4B9B96-2852-4755-B5B1-A5E0F5439F49@gmail.com> On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >> First, because as opposed to ch 1 there is quite a bit of code >> here, and since I'm a >> Python newbie I may be using non-idiomatic constructs, Welp, there goes my last excuse. I'm off to write my book: Heart Surgery at Home *************** How to Save Thousands and Get Results Just Like in Hospital ******** Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan That's as far as I've gotten... Amazon best seller list, here I come! S From alan at baselinedata.co.uk Mon Nov 9 12:37:20 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 17:37:20 +0000 Subject: String prefix question In-Reply-To: References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: <4AF85350.6060401@baselinedata.co.uk> Gerard Flanagan wrote: >
    Alan Harris-Reid wrote: >> In the Python.org 3.1 documentation (section 20.4.6), there is a >> simple ?Hello World? WSGI application which includes the following >> method... >> >> def hello_world_app(environ, start_response): >> status ='200 OK' # HTTP Status >> headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers >> start_response(status, headers) >> >> # The returned object is going to be printed >> return [b"Hello World"] >> >> Question - Can anyone tell me why the 'b' prefix is present before >> each string? The method seems to work equally well with and without >> the prefix. From what I can gather from the documentation the b >> prefix represents a bytes literal, but can anyone explain (in simple >> english) what this means? >> >> Many thanks, >> Alan > > Another link: > > http://www.stereoplex.com/two-voices/python-unicode-and-unicodedecodeerror > > > > >
    > Gerard - thanks for the link - explains it well. Many thanks, Alan From alfps at start.no Mon Nov 9 12:42:53 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 09 Nov 2009 18:42:53 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: * ssteinerX at gmail.com: > > On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: > >> On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >>> First, because as opposed to ch 1 there is quite a bit of code here, >>> and since I'm a >>> Python newbie I may be using non-idiomatic constructs, > > Welp, there goes my last excuse. > > I'm off to write my book: > > Heart Surgery at Home > > *************** > How to Save Thousands and > Get Results Just Like in Hospital > ******** > > Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? > Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? > Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery > Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 > Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? > Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan > > That's as far as I've gotten... > > Amazon best seller list, here I come! > > S It helps if you have some experience with surgery on other parts of the body. Cheers & hth., - Alf From victorsubervi at gmail.com Mon Nov 9 12:44:24 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 12:44:24 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> Message-ID: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Did you give up on me? V On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi wrote: > [root at 13gems angrynates.com]# chcon -R -h > unconfined_u:object_r:httpd_sys_content_t global_solutions/* > > Then I surfed to > http://209.216.9.56/global_solutions/index.py > > [root at 13gems angrynates.com]# tail /var/log/messages > Nov 8 04:26:02 13gems syslogd 1.4.1: restart. > [root at 13gems angrynates.com]# tail /var/log/httpd/error_log > [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest > authentication ... > [Sun Nov 08 05:35:10 2009] [notice] Digest: done > [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session mutexes > based on 10 max processes and 0 max threads. > [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- > resuming normal operations > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' failed, referer: > http://209.216.9.56/global_solutions/ > [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://209.216.9.56/global_solutions/ > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not > exist: /var/www/html/angrynates.com/favicon.ico > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file > or directory: exec of '/var/www/html/ > angrynates.com/global_solutions/index.py' failed, referer: > http://209.216.9.56/global_solutions/ > [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end of > script headers: index.py, referer: http://209.216.9.56/global_solutions/ > > TIA, > V > > On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury wrote: > >> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >> > httpd_sys_content_t global_solutions >> > chcon: can't apply partial context to unlabeled file global_solutions >> > Please advise. >> >> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >> global_solutions/*', which should specify the whole context at once and >> avoid >> that error, as well as apply it recursively to all files and >> subdirectories. >> >> Also, to narrow down the error, can you let us have the output of: >> tail /var/log/messages >> tail /var/log/httpd/error_log >> >> HTH, >> Rami >> >> ---- >> Rami Chowdhury >> "As an online discussion grows longer, the probability of a comparison >> involving Nazis or Hitler approaches one." -- Godwin's Law >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sajmikins at gmail.com Mon Nov 9 12:55:42 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 9 Nov 2009 12:55:42 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: <50f98a4c0911090955v3c8737afp205225d4477ccc6c@mail.gmail.com> On Mon, Nov 9, 2009 at 12:44 PM, Victor Subervi wrote: > Did you give up on me? > V > Please don't top-post. From rami.chowdhury at gmail.com Mon Nov 9 13:14:28 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 10:14:28 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi wrote: > Did you give up on me? > V > > On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi > wrote: > >> [root at 13gems angrynates.com]# chcon -R -h >> unconfined_u:object_r:httpd_sys_content_t global_solutions/* >> >> Then I surfed to >> http://209.216.9.56/global_solutions/index.py >> >> [root at 13gems angrynates.com]# tail /var/log/messages >> Nov 8 04:26:02 13gems syslogd 1.4.1: restart. >> [root at 13gems angrynates.com]# tail /var/log/httpd/error_log >> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest >> authentication ... >> [Sun Nov 08 05:35:10 2009] [notice] Digest: done >> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session >> mutexes >> based on 10 max processes and 0 max threads. >> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- >> resuming normal operations >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not >> exist: /var/www/html/angrynates.com/favicon.ico >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such >> file >> or directory: exec of '/var/www/html/ >> angrynates.com/global_solutions/index.py' failed, referer: >> http://209.216.9.56/global_solutions/ >> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end >> of >> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not >> exist: /var/www/html/angrynates.com/favicon.ico >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such >> file >> or directory: exec of '/var/www/html/ >> angrynates.com/global_solutions/index.py' failed, referer: >> http://209.216.9.56/global_solutions/ >> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end >> of >> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >> >> TIA, >> V >> >> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury >> wrote: >> >>> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >>> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >>> > httpd_sys_content_t global_solutions >>> > chcon: can't apply partial context to unlabeled file global_solutions >>> > Please advise. >>> >>> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >>> global_solutions/*', which should specify the whole context at once and >>> avoid >>> that error, as well as apply it recursively to all files and >>> subdirectories. >>> >>> Also, to narrow down the error, can you let us have the output of: >>> tail /var/log/messages >>> tail /var/log/httpd/error_log >>> OK, after all this I've forgotten what your .py file looked like -- can you post that please? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From gonatan at gmx.de Mon Nov 9 13:24:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Mon, 09 Nov 2009 19:24:10 +0100 Subject: Tax Calculator--Tkinter In-Reply-To: References: Message-ID: <4AF85E4A.4020603@gmx.de> Someone Something wrote: > > from Tkinter import *; Try to avoid this. Better import Tkinter. And don't forget to import Tkconstants too! > > rate=Frame(root) > > income=Frame(root) > > result=Frame(root) Why do you use three frames? You only need one. And you can make your class TaxCalc inherit from Tkinter.Frame ... > > The thing is, that even if I put "12" in the result text field, get > > returns an empty string. How can I fix this? I haven't found the reason for that, but this should work. I also added MRABs version of printResult(). import Tkinter, Tkconstants class TaxCalc(Tkinter.Frame): def __init__(self, root): Tkinter.Frame.__init__(self, root) Tkinter.Button(self, text='Enter tax rate', command=self.getRate).pack() self.rate=Tkinter.Entry(self) self.rate.pack() Tkinter.Button(self, text='Enter income', command=self.getIncome).pack() self.income=Tkinter.Entry(self) self.income.pack() Tkinter.Button(self, text='Get result', command=self.printResult).pack() self.result=Tkinter.Entry(self) self.result.pack() self.pack() def getRate(self): print "srate: ", self.rate.get() def getIncome(self): print "sincome: ", self.income.get() def printResult(self): try: rate = float(self.rate.get()) income = float(self.income.get()) result = ((100.0 - rate) / 100.0) * income self.result.insert(Tkconstants.END, str(result)) except ValueError: print "Clear everything and start again." print "Don't fool around with me." root=Tkinter.Tk() MyCalc=TaxCalc(root) root.mainloop() From victorsubervi at gmail.com Mon Nov 9 13:36:31 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 13:36:31 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> Message-ID: <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Of course. Let me start with some updates to httpd.conf, which didn't help anyway: ServerAdmin me at creative.vi DocumentRoot /var/www/html/angrynates.com ServerName angrynates.com Options +ExecCGI -IncludesNoExec Options +ExecCGI AllowOverride All AllowOverride FileInfo #AddHandler mod_python .py #PythonHandler mod_python.publisher #PythonDebug On AddHandler cgi-script .cgi .py Options Includes Indexes SymLinksIfOwnerMatch ExecCGI SecFilterEngine Off SecRuleEngine Off AddHandler cgi-script .cgi .py Options Includes Indexes SymLinksIfOwnerMatch ExecCGI SecFilterEngine Off SecRuleEngine Off Here's index.py: #!/usr/bin/python import string import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from template import template ourFile = string.split(__file__, "/") page = ourFile[len(ourFile) - 1][:-3] form = cgi.FieldStorage() w = form.getfirst('w', '1024') template(page, w) Here's template.py: #!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) p = 'template' def template(page, w): wn = int(w)/1024 print "Content-Type: text/html" print print ''' Global Solutions Group ''' print "\n' % (a, w) This is looped through for every value of pic/id returned from the database, producing the following code on the Web page: The problem here is that only one of the images prints on the said page! However, if I surf to those URLs, the images appear! Is it possible that because I'm passing values to the variables and perhaps simultaneously calling the script, that it can only fulfill the first request? Is there a way around that? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From yosato16 at gmail.com Fri Nov 27 12:17:33 2009 From: yosato16 at gmail.com (Yo Sato) Date: Fri, 27 Nov 2009 17:17:33 +0000 Subject: debugger on system with Python 2 and 3 Message-ID: Hi, I am a relative newcomer to the Python language, and only write Python 3. Now I would very much like to a more-than-basic debugger. However it seems as if the fact that I have both Python 2 and 3 on the system complicates the matter... First I tried to use something called pydb, but it seems to invoke python 2, and I don't know quite how to (or whether I can) configure it for Python 3. Secondly I installed something called IDLE3, which complains that TK is not configured for Python 3. I don't want to remove or default to Python 2, as there seem to be a number of programs that rely on it. I wonder how best to avoid my problems. Would perhaps somebody in the same sort of situation share their wisdom?? Yo From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 12:21:54 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Nov 2009 17:21:54 GMT Subject: why do I get this behavior from a while loop? References: Message-ID: <00998f26$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? "What Every Computer Scientist Should Know About Floating Point" http://docs.sun.com/source/806-3568/ncg_goldberg.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 12:30:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Nov 2009 17:30:26 GMT Subject: Filling in a tuple from unknown size list References: Message-ID: <00999127$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: > Here's my question: Given a list of onknown length, I'd like to be able > to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining tuple > elements to be set to "None". If the list is longer, I'd like the excess > elements to be ignored. I'd call that a code-smell. If I saw that in code, I'd think long and hard about why it was there and if I could eliminate the names a...f and just work directly with the list. But if you really do need it, I think the simplest and best way is to use the technique Stefan suggested: a, b, c, d, e, f = (list + [None]*6)[:6] provided list is short. If you fear that list might be huge and copying it will be prohibitively expensive: a, b, c, d, e, f = (list[:6] + [None]*6)[:6] -- Steven From mwilson at the-wire.com Fri Nov 27 12:47:40 2009 From: mwilson at the-wire.com (Mel) Date: Fri, 27 Nov 2009 12:47:40 -0500 Subject: Filling in a tuple from unknown size list References: <00999127$0$26925$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: >> Here's my question: Given a list of onknown length, I'd like to be able >> to do the following: >> >> (a, b, c, d, e, f) = list >> >> If the list has fewer items than the tuple, I'd like the remaining tuple >> elements to be set to "None". If the list is longer, I'd like the excess >> elements to be ignored. > I'd call that a code-smell. If I saw that in code, I'd think long and > hard about why it was there and if I could eliminate the names a...f and > just work directly with the list. It's a common enough thing at the boundaries of your program, letting user input in through the gates, as it were. Deeper in, I agree; that stuff should have been dealt with at the gates. Mel. From coldtortuga at gmail.com Fri Nov 27 13:12:36 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Fri, 27 Nov 2009 10:12:36 -0800 (PST) Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: I was really inspired by this discussion thread! :-) After much tinkering, I think I have a simpler solution. Just make the inverse mapping accessible via an attribute, -AND- bind the inverse of -THAT- mapping back to the original. The result is a python dict with NO NEW METHODS except this inverse-mapping attribute. I have posted it on code.activestate.com as Recipe 576968: Flipdict -- python dict that also maintains a one-to-one inverse mapping -- F. Carr From aljosa.mohorovic at gmail.com Fri Nov 27 13:22:51 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 27 Nov 2009 10:22:51 -0800 (PST) Subject: setup.py and MANIFEST.in - duplicating inclusion of files? Message-ID: the only way i can get to distribute template files when using "python setup.py sdist" is to declare it both in setup.py and MANIFEST.in. setup.py: > package_data={'myapp':['templates/*.html', 'templates/admin/*.html'],} MANIFEST.in: > recursive-include myapp/templates *.html am i doing something wrong or is this correct? if it's correct, why? Aljosa Mohorovic From victorsubervi at gmail.com Fri Nov 27 13:26:18 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 27 Nov 2009 14:26:18 -0400 Subject: Can't Encode Pic In-Reply-To: References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911260819q4340bb1at9a02422f3226df87@mail.gmail.com> <4B0EB244.7050703@mrabarnett.plus.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> Message-ID: <4dc0cfea0911271026x240d869du80148727ec4de238@mail.gmail.com> On Fri, Nov 27, 2009 at 1:43 PM, Dennis Lee Bieber wrote: > On Fri, 27 Nov 2009 05:59:39 -0500, Victor Subervi > declaimed the following in > gmane.comp.python.general: > > > > > > > > The following complained that there weren't enough arguments: > > > > for pic in pics: > > sql = 'update %s set %s=%%s where ID=%s;' % (t, colNamesPics[i], > > '%s', str(id)) > > cursor.execute(sql, (MySQLdb.Binary(pics[int(i)]),), ) > > > I'm pretty sure that isn't what I had typed too... Count the % > > sql = "update %s set %s=%%s where ID = %%s" % (t, colNamesPics[i]) > Thank you, Dennis. This problem is resolved. Since our posts most likely crossed, and since yours has inadvertently appeared below mine with the latest problem, I'm reposting it here: Now, I have this line of code on another page that calls the images once the database is populated: print '\n' % (a, w) This is looped through for every value of pic/id returned from the database, producing the following code on the Web page: The problem here is that only one of the images prints on the said page! However, if I surf to those URLs, the images appear! Is it possible that because I'm passing values to the variables and perhaps simultaneously calling the script, that it can only fulfill the first request? Is there a way around that? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From doesnotexist at franzoni.invalid Fri Nov 27 14:03:10 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Fri, 27 Nov 2009 19:03:10 GMT Subject: debugger on system with Python 2 and 3 In-Reply-To: References: Message-ID: On 11/27/09 6:17 PM, Yo Sato wrote: > Hi, > > I am a relative newcomer to the Python language, and only write Python > 3. Now I would very much like to a more-than-basic debugger. However > it seems as if the fact that I have both Python 2 and 3 on the system > complicates the matter... You haven't told OS which OS you're using, and what are your exact problems, BTW I think two good debuggers for Python are winpdb/rpdb2 (work on any platform, despite the name) and the one you get in Eclipse+Pydev. You should be able to pick your platform, even though I've never tested them in Python 3. -- Alan Franzoni contact me at public@[mysurname].eu From carsten.haese at gmail.com Fri Nov 27 14:21:30 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 27 Nov 2009 14:21:30 -0500 Subject: Can't Encode Pic In-Reply-To: <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911260819q4340bb1at9a02422f3226df87@mail.gmail.com> <4B0EB244.7050703@mrabarnett.plus.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> <2f79f590911270602u17a1cfcex83aa2f4ffe0fdf29@mail.gmail.com> <4dc0cfea0911270708o64a12fe1pbdd12ad5b5edd56a@mail.gmail.com> <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Fri, Nov 27, 2009 at 12:13 PM, Carsten Haese > wrote: > > Victor Subervi wrote: > > The difficulty I am having is that for > > some reason it's not inserting. The form inserts the first image > but not > > the second. > > My guess is that you're not calling db.commit() after inserting the > second image. (If you had shown your code, I wouldn't have to guess.) > > > That was the logical guess and yes, it hit the target. I should have > known better. Thank you. > Now, I have this line of code on another page that calls the images once > the database is populated: > > print ' width="100">\n' % (a, w) > > This is looped through for every value of pic/id returned from the > database, producing the following code on the Web page: > > > > > The problem here is that only one of the images prints on the said page! > However, if I surf to those URLs, the images appear! Are you sure that you're surfing to *exactly* those URLs? When I go to http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get an error message. I am guessing that you have your pic and id parameter switched around. > Is it possible that > because I'm passing values to the variables and perhaps simultaneously > calling the script, that it can only fulfill the first request? That's possible if your script is doing something stupid, but I find my above guess much more likely. HTH, -- Carsten Haese http://informixdb.sourceforge.net From sccolbert at gmail.com Fri Nov 27 15:00:42 2009 From: sccolbert at gmail.com (S. Chris Colbert) Date: Fri, 27 Nov 2009 21:00:42 +0100 Subject: why do I get this behavior from a while loop? In-Reply-To: <00998f26$0$26925$c3e8da3@news.astraweb.com> References: <00998f26$0$26925$c3e8da3@news.astraweb.com> Message-ID: <200911272100.42168.sccolbert@gmail.com> What a newbie mistake for me to make. I appreciate the replies everyone! Cheers, Chris > On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > > I would think that second loop should terminate at 9.9, no? > > > > I am missing something fundamental? > > "What Every Computer Scientist Should Know About Floating Point" > http://docs.sun.com/source/806-3568/ncg_goldberg.html > From stefan_ml at behnel.de Fri Nov 27 15:11:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 27 Nov 2009 21:11:01 +0100 Subject: Filling in a tuple from unknown size list In-Reply-To: References: <00999127$0$26925$c3e8da3@news.astraweb.com> Message-ID: <4b103255$0$6566$9b4e6d93@newsspool4.arcor-online.net> Mel, 27.11.2009 18:47: > Steven D'Aprano wrote: >> On Fri, 27 Nov 2009 04:18:08 -0800, boblatest wrote: >>> Here's my question: Given a list of onknown length, I'd like to be able >>> to do the following: >>> >>> (a, b, c, d, e, f) = list >>> >>> If the list has fewer items than the tuple, I'd like the remaining tuple >>> elements to be set to "None". If the list is longer, I'd like the excess >>> elements to be ignored. > >> I'd call that a code-smell. If I saw that in code, I'd think long and >> hard about why it was there and if I could eliminate the names a...f and >> just work directly with the list. > > It's a common enough thing at the boundaries of your program, letting user > input in through the gates, as it were. Deeper in, I agree; that stuff > should have been dealt with at the gates. But that may have a code smell on it, too. In most cases, when users provide excessive arguments that the program would ignore, that's best treated as an error. Stefan From victorsubervi at gmail.com Fri Nov 27 15:18:58 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 27 Nov 2009 16:18:58 -0400 Subject: Can't Encode Pic In-Reply-To: References: <4dc0cfea0911260547p9078013gef3dc9acdd58adb3@mail.gmail.com> <4dc0cfea0911261010l2004d244q39a7aa9e4644d700@mail.gmail.com> <4dc0cfea0911261032l794bac7dr3992ae8b898e1986@mail.gmail.com> <4dc0cfea0911270259u106f8c61s197ddb5ad95da251@mail.gmail.com> <2f79f590911270602u17a1cfcex83aa2f4ffe0fdf29@mail.gmail.com> <4dc0cfea0911270708o64a12fe1pbdd12ad5b5edd56a@mail.gmail.com> <4dc0cfea0911270858w36983073p6244f374b26efc55@mail.gmail.com> Message-ID: <4dc0cfea0911271218x160a585fxab91530b0fec945b@mail.gmail.com> > > > > > > > > > The problem here is that only one of the images prints on the said page! > > However, if I surf to those URLs, the images appear! > > Are you sure that you're surfing to *exactly* those URLs? When I go to > http://www.angrynates.com/cart/getpic.py?pic=2&id=1, I get an image, but > when I go to http://www.angrynates.com/cart/getpic.py?pic=1&id=2, I get > an error message. I am guessing that you have your pic and id parameter > switched around. > Yes. Sorry. Thanks. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Fri Nov 27 15:26:52 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 12:26:52 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: Testing, testing...is this thing on? Hang on guys, I'm having some trouble posting to the mailing list suddenly. From subhakolkata1234 at gmail.com Fri Nov 27 15:41:42 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 12:41:42 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys Message-ID: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> Dear Group, I have written a small and simple program like the following: def alphabet1(n): file_open=open("/python26/alphabetlist1.txt","r") file_read=file_open.read() file_word=file_read.split() print file_word Here, I am using a file ?alphabetlist1.txt? which I am reading and then splitting them into words. In this file ?alphabetlist1.txt? I have arranged few alphabets like the following: a A b B c C d D E e F f Where, a/b/c/d/e/f are in lower case and A/B/C/D/E/F are in upper case which I can say as SHIFT+a SHIFT+b SHIFT+c SHIFT+d SHIFT+e SHIFT+f Now, in the list or anywhere in the program if I want to write CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I may feel not only cut/copy/paste. How would I represent them? It may not be a Python specific question but as this room is full with many expert programmers if someone can help me out. I copied the above program from .py file to a word processor like MS- WORD so some indentation might have changed, I am sorry for the same. Regards, Subhabrata Banerjee. From anand.ibmgsi at gmail.com Fri Nov 27 16:23:42 2009 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Sat, 28 Nov 2009 02:53:42 +0530 Subject: Render a xml graph as an image Message-ID: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> hi all. Am looking to display a graph as an image.. the graph is in the format of a xml file(basically the output of a python-graph package).......... Is there a package that already does it?? ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with no accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Nov 27 16:23:55 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 28 Nov 2009 10:23:55 +1300 Subject: Intro To Python Using Turtle Graphics Message-ID: Done by Northland Polytechnic, available for download under CC-BY-NC-ND here . Thanks to Colin Jackson for the link. From rossgk at gmail.com Fri Nov 27 16:27:43 2009 From: rossgk at gmail.com (Ross) Date: Fri, 27 Nov 2009 13:27:43 -0800 (PST) Subject: My Python / wxPython app crashing - suggestions? Message-ID: <2bed9cbd-2bc7-4cfb-8b93-4a3dc4bbaaea@x16g2000vbk.googlegroups.com> I have a rather elaborate app on python 2.5.2 on mac osx 10.4.11. The GUI elements are built on wxPython 2.8.10.1. Development has gone pretty well, but I've got an intermittent rather silent crash that happens without spewing any error messages to my console at all. I'm developing in Eclipse with PyDev, and I build with py2app to make an executable app. Whether in Eclipse/PyDev or running standalone, the crash occurs randomly without any messages almost every run, though it takes me 10 -15min of usage before I get the fateful crash. The only data I can get is from the CrashReporter Log directory where a MyApp.crash.log tells me that Thread 4 crashed with: Thread: 4 Exception: EXC_BAD_ACCESS (0x0001) Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000004 and: Thread 4 crashed with X86 Thread State (32-bit): eax: 0x00000000 ebx: 0x9083d561 ecx: 0x00000074 edx: 0x92e341ac edi: 0x14442b60 esi: 0x00000000 ebp: 0xb0370b58 esp: 0xb0370b58 ss: 0x0000001f efl: 0x00010286 eip: 0x92e30522 cs: 0x00000017 ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037 Given the lack of other info, this doesn't tell me much. Any suggestions? One other (perhaps related issue?) very rarely, much less common than the crash is a spurious malloc error from deep in python somewhere. Not sure that my code is responsible. I don't recognize this format of complaint. Python(9544,0xa000d000) malloc: *** error for object 0x1a05c8f0: double free Python(9544,0xa000d000) malloc: *** set a breakpoint in szone_error to debug Can anyone suggest somewhere to start? If I start putting random breakpoints and prints in trying to catch the crash, I could be here for years as I can't yet nail down the conditions that precipitate it. Regards, Ross. From tjreedy at udel.edu Fri Nov 27 16:42:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 27 Nov 2009 16:42:42 -0500 Subject: extending optionparser to accept multiple comma delimited input for one arg In-Reply-To: <4734689a-1e89-4bbd-9a1b-f811f897a344@f16g2000yqm.googlegroups.com> References: <9230223a-2907-478a-ba30-15419b6db020@b2g2000yqi.googlegroups.com> <4734689a-1e89-4bbd-9a1b-f811f897a344@f16g2000yqm.googlegroups.com> Message-ID: cmptrwhz wrote: > On Nov 27, 2:33 am, Peter Otten <__pete... at web.de> wrote: >> If you had problems understanding the documentation perhaps you can suggest >> an improvement. >> >> Peter > First I would like to thank you very much for the quick and concise > answer this is very clear to me as to what I need to do now. Thank you > so much. > > The one thing that threw me off and confused me is that I went back in > the docs to see what actions are available to see if extend was an > allowable action. in section 14.3.2.4 Other actions, I did not see > that extend was a valid action so I looked thru section 14.3.3.3 > Defining options and this section did not show extend as a valid > action. I believe that if there was a complete disclosure of actions > available then I would have seen the error in my thinking. Everything > else made sense up to the point of where the subclass was described in > the docs as above but if the next couple lines you gave me was added > to this section (14.3.5.2 Adding new actions) it was have completed > the confirmation I needed that it was ok to type in extend as an > action. Maybe I am still not understanding this concept fully still > but I hope I am making sense with my point. > > So my suggestion would be to include this tidbit of extra as you have > described to me in the section 14.3.5.2 and all would have been as > clear as sunshine. :) thank you again for your time and listening to > my thoughts. > > parser = OptionParser(option_class=MyOption) > parser.add_option("-i", "--input", action="extend") > > options, args = parser.parse_args() > print options Please go to bugs.python.org, register if you have not, and add a type: feature request, component: documentation issue giving the exact sentence you suggest adding (keeping in mind the existing doc style) and the exact proposed location. Then explain, briefly, why. From david at bibliolabs.com Fri Nov 27 17:02:05 2009 From: david at bibliolabs.com (David Williams) Date: Fri, 27 Nov 2009 16:02:05 -0600 (CST) Subject: Render a xml graph as an image In-Reply-To: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> References: <1a3a139e0911271323v64e86d2em9a53329a409ab50a@mail.gmail.com> Message-ID: <51310.68.58.172.242.1259359325.squirrel@www.bibliobazaar.com> Maybe I am missing something, but according to this example, http://code.google.com/p/python-graph/wiki/Example, python-graph can export to at least PNG format. Another option, transform the XML into GraphML (http://graphml.graphdrawing.org/) using XSLT (assuming it is not already in that format), and then to SVG (http://www.w3.org/Graphics/SVG/). From there it should be easy to either directly display or get it into any bitmap format you want. On the GraphML website their is an XSL to transform GraphML to SVG. David > hi all. > Am looking to display a graph as an image.. the graph is in the > format of a xml file(basically the output of a python-graph > package).......... Is there a package that already does it?? > ============================================== > Anand J > http://sites.google.com/a/cbcs.ac.in/students/anand > ============================================== > The man who is really serious, > with the urge to find out what truth is, > has no style at all. He lives only in what is. > ~Bruce Lee > > Love is a trade with no accounting policies. > ~Aang Jie > -- > http://mail.python.org/mailman/listinfo/python-list > From bthate at gmail.com Fri Nov 27 18:38:58 2009 From: bthate at gmail.com (Bart Thate) Date: Fri, 27 Nov 2009 15:38:58 -0800 (PST) Subject: cmndbot 0.1 beta 1 released Message-ID: So once again i bite the bullet because i can no longer wait on going public with this. I'm pleased to announce CMNDBOT 0.1 BETA1 to the world as this is the first released of my port of GOZERBOT to the Google Application Engine, enabling it on wave, web and xmpp. I'll paste here the README to explain what it does: CMNDBOT is a port of gozerbot to google wave platform. GOZERBOT needed to be completely rewritten as programs running on google application engine (GAE) run within a CGI model which means that the bot get loaded on every request (unless its cached). Core functionality is available right now but most plugins need to be ported still. Besides wave the bot also supports web and jabber (XMPP) access. this is the code that is being run by the cmndbot.appspot.com bot and is free code (BSD license). you can clone it to run your own cmndbot or just to read how things are being done. no fear in reading cmndbot code ! as the name says cmndbot allows you to execute commands that you can program easily through the use of plugins. example: from gozerlib.commands import cmnds def handle_hello(bot, event): event.reply("hello %s" % event.userhost) cmnds.add('hello', handle_hello, 'USER') as of now a few gozerbot plugins are being ported to cmndbot, namely: * eight ball * ipcalc * todo * wikipedia * infoitem * gcalc * RSS other plugins will follow but the focus is now mainly on the bots core. CMNDBOT is accessible at http://cmndbot.appspot.com (WEB) or cmndbot at appspot.com (WAVE/XMPP). A gadget is also in the works at http://cmndbot.appspot.com/cmnd.xml but it only works with google chrome for now .. my javascript skills are very *kuch* young ;] actualy this code is still young as docs are mostely missing and the bot really needs to be tested, but thats what this release is for, rememer this is still version 0.1 ! code is at http://cmndbot.googlecode.com/hg I hope people are interested in developing this bot with me, if you do you can contact me at bthate at gmail.com or bthate at googlewave.com Bart From sjmachin at lexicon.net Fri Nov 27 19:02:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 27 Nov 2009 16:02:39 -0800 (PST) Subject: Filling in a tuple from unknown size list References: Message-ID: <5c5f1f89-e1f5-4814-bdfa-ea71c8b4d29a@z10g2000prh.googlegroups.com> On Nov 27, 11:18?pm, boblatest wrote: > Hello all, > > (sorry for posting from Google. I currently don't have access to my > normal nntp account.) > > Here's my question: Given a list of onknown length, I'd like to be > able to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining > tuple elements to be set to "None". If the list is longer, I'd like > the excess elements to be ignored. WRONG -- sweeping excess input under the carpet is a nasssssty perlish trick. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 19:35:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 00:35:16 GMT Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> Message-ID: <0099f4b9$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > Dear Group, > > I have written a small and simple program like the following: > > def alphabet1(n): > file_open=open("/python26/alphabetlist1.txt","r") > file_read=file_open.read() > file_word=file_read.split() > print file_word > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > splitting them into words. > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > following: > > a A > b B > c C > d D > E e > F f > > Where, a/b/c/d/e/f are in lower case and A/B/C/D/E/F are in upper case > which I can say as > SHIFT+a > SHIFT+b > SHIFT+c > SHIFT+d > SHIFT+e > SHIFT+f > > Now, in the list or anywhere in the program if I want to write > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > may feel not only cut/copy/paste. > > How would I represent them? This question is badly defined. What are your constraints? Is this meant to be a human-readable program? If so, you need to stick to ASCII text and probably want something like: a A CTRL-A ALT-A b B CTRL-B ALT-B ... but I'm not sure what the point of that would be. Normally, control-combinations generate control-characters. For example, CTRL-M would normally generate a carriage-return character. Depending on your needs, you can write this as any of the following: a description: CTRL-M an escape sequence: \r caret notation: ^M the standard abbreviation: CR the Unicode display glyph: ? or an actual carriage-return character. Note that in ASCII control characters only have a standard definition for the following: ctrl-@ ctrl-A through ctrl-Z ctrl-[ ctrl-\ ctrl-] ctrl-^ ctrl-_ ctrl-? See here for more: http://en.wikipedia.org/wiki/Control_characters As for Alt-combinations, I don't think there is any standard for what they are. I believe that they are operating system specific, and possibly even program specific. -- Steven From enkidu.com at com.cliffp.com Fri Nov 27 20:02:31 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:02:31 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: References: Message-ID: <4b1076a8$1@news2.actrix.gen.nz> Lawrence D'Oliveiro wrote: > > Done by Northland Polytechnic, available for download under CC-BY-NC-ND here > . > Urgh. Is that all that python is good for, drawing pretty pictures? Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From ben+python at benfinney.id.au Fri Nov 27 20:20:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 12:20:20 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> Message-ID: <873a3zwiln.fsf@benfinney.id.au> Enkidu writes: > Urgh. Is that all that python is good for, drawing pretty pictures? Yep, that's all . Rackspace, Google, NASA, Philips, Honeywell, AstraZeneca; they're *all* organisations focussed on drawing pretty pictures, and that's all they use Python for. -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Fri Nov 27 20:32:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 01:32:06 GMT Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> Message-ID: <009a020b$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 14:02:31 +1300, Enkidu wrote: > Lawrence D'Oliveiro wrote: > > >> Done by Northland Polytechnic, available for download under CC-BY-NC-ND >> here >> . >> > Urgh. Is that all that python is good for, drawing pretty pictures? [sarcasm] Yes, yes it is. When they talk about "batteries included", they mean the batteries that run the turtle. [end sarcasm] Are you trolling or just a little sleep-deprived today? The movie is an introduction aimed at 13-16 year old school children. It's explicitly labelled as "an introduction using turtle graphics". What on earth makes you think that because the introduction uses turtle graphics, that's the ONLY thing that Python can do? -- Steven From aioe.org at technicalbloke.com Fri Nov 27 20:35:36 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 01:35:36 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. Message-ID: Hi, I'm writing a reliability monitoring app but I've run into a problem. I was hoping to keep it very simple and single threaded at first but that's looking unlikely now! The crux of it is this... gethostbyname ignores setdefaulttimeout. It seems gethostbyname asks the OS to resolve the address and the OS uses it's own timeout value ( 25 seconds ) rather than the one provided in setdefaulttimeout. 25 seconds of blocking is way too long for me, I want the response within 5 seconds or not at all but I can see no reasonable way to do this without messing with the OS which naturally I am loathe to do! The two ideas I've had so far are... Implement a cache. For this to work I'd need to avoid issuing gethostbyname until the cached address fails. Of course it will fail a little bit further down i the calling code when the app tries to use it and I'd then need it to refresh the cache and try again. That seems very kludgey to me :/ A pure python DNS lookup. This seems better but is an unknown quantity. How big a job is it to use non-blocking sockets to write a DNS lookup function with a customisable timeout? A few lines? A few hundred? I'd only need to resolve v4 addresses for the foreseeable. Any comments on these strategies, or any suggestions of methods you think might work better or be a lot easier to implement, warmly received. Roger. From enkidu.com at com.cliffp.com Fri Nov 27 20:52:11 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:52:11 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <873a3zwiln.fsf@benfinney.id.au> References: <4b1076a8$1@news2.actrix.gen.nz> <873a3zwiln.fsf@benfinney.id.au> Message-ID: <4b10824b$1@news2.actrix.gen.nz> Ben Finney wrote: > Enkidu writes: > >> Urgh. Is that all that python is good for, drawing pretty pictures? > > Yep, that's all . Rackspace, > Google, NASA, Philips, Honeywell, AstraZeneca; they're *all* > organisations focussed on drawing pretty pictures, and that's all they > use Python for. > Sorry, I did not mean to post to the CLP list. It would be a stupid troll to do so on purpose. My apologies. I *AM* a Perl fan but there is room for both languages. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From enkidu.com at com.cliffp.com Fri Nov 27 20:55:32 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 14:55:32 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <009a020b$0$26925$c3e8da3@news.astraweb.com> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> Message-ID: <4b108315$1@news2.actrix.gen.nz> Steven D'Aprano wrote: > On Sat, 28 Nov 2009 14:02:31 +1300, Enkidu wrote: > > Are you trolling or just a little sleep-deprived today? > Heh! Maybe a little sleep-deprived, but I didn't realise that the original post was cross-posted to comp.lang.python. If I'd purposely posted it to CLP it *would* have been a stupid troll. I did it by accident, and apologise for doing so. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From john at castleamber.com Fri Nov 27 21:04:51 2009 From: john at castleamber.com (John Bokma) Date: 28 Nov 2009 02:04:51 GMT Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > It seems gethostbyname asks the OS to resolve the address and the OS > uses it's own timeout value ( 25 seconds ) rather than the one provided > in setdefaulttimeout. 25 seconds of blocking is way too long for me, I > want the response within 5 seconds or not at all but I can see no > reasonable way to do this without messing with the OS which naturally I > am loathe to do! use signal.alarm(time) to send SIGALRM to your process: http://docs.python.org/library/signal.html#signal.alarm See example at bottom. John From gagsl-py2 at yahoo.com.ar Fri Nov 27 21:15:09 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Nov 2009 23:15:09 -0300 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: En Fri, 27 Nov 2009 22:35:36 -0300, r0g escribi?: > gethostbyname ignores setdefaulttimeout. > > How big a job is it to use non-blocking sockets to write a DNS lookup > function with a customisable timeout? A few lines? A few hundred? I'd > only need to resolve v4 addresses for the foreseeable. This guy reports good results using GNU adns to perform asynchronous queries: http://www.catonmat.net/blog/asynchronous-dns-resolution/ Also, look for pydns. Don't be afraid of its age; it always worked fine for me. -- Gabriel Genellina From ben+python at benfinney.id.au Fri Nov 27 21:15:46 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 13:15:46 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> Message-ID: <87ocmnv1gt.fsf@benfinney.id.au> Enkidu writes: > Heh! Maybe a little sleep-deprived, but I didn't realise that the > original post was cross-posted to comp.lang.python. If I'd purposely > posted it to CLP it *would* have been a stupid troll. I did it by > accident, and apologise for doing so. Oh, so trash-talking in *other* forums where you feel safe from being caught is okay? ;-) -- \ ?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 gagsl-py2 at yahoo.com.ar Fri Nov 27 21:36:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 27 Nov 2009 23:36:13 -0300 Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: En Fri, 27 Nov 2009 15:12:36 -0300, Francis Carr escribi?: > I was really inspired by this discussion thread! :-) > > After much tinkering, I think I have a simpler solution. Just make > the inverse mapping accessible via an attribute, -AND- bind the > inverse of -THAT- mapping back to the original. The result is a > python dict with NO NEW METHODS except this inverse-mapping > attribute. I have posted it on code.activestate.com as href="http://code.activestate.com/recipes/576968/">Recipe 576968: > Flipdict -- python dict that also maintains a one-to-one inverse > mapping Nice idea! Just a couple of comments: Instead of: self._flip = dict.__new__(self.__class__) I'd write: self._flip = self.__class__() unless I'm missing something (but see the next point). Also, although Python's GC is able to handle them, I prefer to avoid circular references like those between x and x._flip. Making self._flip a weak reference (and dereferencing it in the property) should be enough. -- Gabriel Genellina From showell30 at yahoo.com Fri Nov 27 22:04:31 2009 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 27 Nov 2009 19:04:31 -0800 (PST) Subject: a 100-line indentation-based preprocessor for HTML Message-ID: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Python has this really neat idea called indentation-based syntax, and there are folks that have caught on to this idea in the HTML community. AFAIK the most popular indentation-based solution for generating HTML is a tool called HAML, which actually is written in Ruby. I have been poking around with the HAML concepts in Python, with the specific goal of integrating with Django. But before releasing that, I thought it would be useful to post code that distills the basic concept with no assumptions about your target renderer. I hope it also serves as a good example of what you can do in exactly 100 lines of Python code. Here is what it does... You can use indentation syntax for HTML tags like table. From this... table tr td Left td Center td Right ...you get this:
    Homeoffice suppliescatalogcustomer templateformsabout uscontact us
    \n' % (getpic) count2 += 1 except: print '' else: print '\n' % (field) x += 1 TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ralaxmyself at gmail.com Wed Nov 11 09:01:13 2009 From: ralaxmyself at gmail.com (Ralax) Date: Wed, 11 Nov 2009 06:01:13 -0800 (PST) Subject: Basic list/dictionary question References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Message-ID: <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> On Nov 11, 8:58?pm, Chris Rebert wrote: > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett wrote: > > Greetings, > > > I'm trying to categorize items in a list, by copying them into a > > dictionary... > > A simple example with strings doesn't seem to work how I'd expect: > > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] > >>>> d = {} > >>>> d = d.fromkeys(basket, []) > >>>> d > > {'orange': [], 'pear': [], 'apple': [], 'banana': []} > >>>> for fruit in basket: > > ...???? d[fruit].append(fruit) > > ... > > > No if I print d I'd EXPECT.... > >>>> d > > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > > 'apple'], 'banana': ['banana']} > > > But what I GET is.... > >>>> d > > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': > > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana']} > > > From what I can work out, there is only ONE list that is referenced from the > > dictionary 4 times. Which would be because the same empty list is assigned > > to every key in the dictionary by the "fromkeys" line. But that seems > > seriously counter-intuitive to me... > > Python doesn't do any extra copying in most places unless you > /explicitly/ do so yourself or ask it to; so yes, in this case, Python > just copies references to the same object and does not copy the object > itself. > > You'd probably be better off using a defaultdict in your particular usecase:http://docs.python.org/library/collections.html#collections.defaultdict > > Or and so you avoid running into it, default argument values aren't > copied either: > In [2]: def foo(z, a=[]): > ? ?...: ? ? ? ? a.append(z) > ? ?...: ? ? return a > ? ?...: > > In [3]: foo(1) > Out[3]: [1] > > In [4]: foo(2) > Out[4]: [1, 2] > > In [5]: foo(2) > Out[5]: [1, 2, 2] > > In [6]: foo(3) > Out[6]: [1, 2, 2, 3] > > In [7]: foo(4,[]) > Out[7]: [4] > > In [8]: foo(5) > Out[8]: [1, 2, 2, 3, 5] > > Cheers, > Chris > --http://blog.rebertia.com Usefull! From ralaxmyself at gmail.com Wed Nov 11 09:11:31 2009 From: ralaxmyself at gmail.com (Ralax) Date: Wed, 11 Nov 2009 06:11:31 -0800 (PST) Subject: Unexpected python exception References: Message-ID: <7d121326-ab5f-4151-8edb-f69bc6f9dee5@b36g2000prf.googlegroups.com> On Nov 11, 6:59?pm, Richard Purdie wrote: > I've been having problems with an unexpected exception from python which > I can summarise with the following testcase: > > def A(): > ? ? import __builtin__ > ? ? import os > > ? ? __builtin__.os = os > > def B(): > ? ? os.stat("/") > ? ? import os > > A() > B() > > which results in: > > Traceback (most recent call last): > ? File "./test.py", line 12, in > ? ? B() > ? File "./test.py", line 8, in B > ? ? os.stat("/") > UnboundLocalError: local variable 'os' referenced before assignment > > If I remove the "import os" from B(), it works as expected. > > >From what I've seen, its very unusual to have something operate > > "backwards" in scope in python. Can anyone explain why this happens? > > Cheers, > > Richard One word, Python treat objects in a function or method-scope as locals. So os is not defined in B(), is it right? From deets at nospam.web.de Wed Nov 11 09:23:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 15:23:06 +0100 Subject: installing lxml ? In-Reply-To: References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <7lvvmaF3ga6r2U1@mid.uni-berlin.de> Chris Rebert schrieb: > On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: >> I'm trying to install lxml, but I can't figure out the installation >> instructions. Here: >> >> http://codespeak.net/lxml/installation.html >> >> it says: >> >> 1) Get the easy_install tool. > >> My os is mac os x 10.4.11. > > I would recommend installing fink (http://www.finkproject.org/) and > then `sudo fink install setuptools-py26`. > As a bonus, you'll get a more up-to-date Python installed separate > from the system one (so you don't need to worry about hosing it). Which doesn't run any cocoa or other osx-specific code. Which some might call "hosed from the very beginning". Diez From starglider101 at gmail.com Wed Nov 11 09:28:11 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 11 Nov 2009 14:28:11 +0000 Subject: PyQt 2 Exe In-Reply-To: References: <6e5b31840911110607r5357d8amfec6205f81be6f23@mail.gmail.com> Message-ID: <6e5b31840911110628y1a4c9500o110502a07efdbdb7@mail.gmail.com> search the web, find the sites and follow the instructions. On Wed, Nov 11, 2009 at 2:11 PM, baboucarr sanneh wrote: > > How can i use it ? > > *$LIM $H at DY* > > > > > ------------------------------ > Date: Wed, 11 Nov 2009 14:07:47 +0000 > Subject: Re: PyQt 2 Exe > From: starglider101 at gmail.com > To: sanneh27 at hotmail.com > > > py2exe > pyinstaller > > On Wed, Nov 11, 2009 at 1:29 PM, baboucarr sanneh wrote: > > Hi guys, > > I wan to make a gui app using pyqt so i have done some thing already now i > want to save it as an exe file so that i can give it out to users who dont > have pyqt installed (windows users)..Please help me out on this one..thnx > > Regards > > *$LIM $H at DY* > > > > ------------------------------ > Keep your friends updated? even when you?re not signed in. > > -- > http://mail.python.org/mailman/listinfo/python-list > > > > ------------------------------ > Windows Live: Keep your friends up to date with what you do online. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpurdie at rpsys.net Wed Nov 11 09:29:21 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 14:29:21 +0000 Subject: Unexpected python exception In-Reply-To: <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> Message-ID: <1257949761.29038.399.camel@dax.rpnet.com> On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: > On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: > > > Is there a way to make the "global x" apply to all functions without > > adding it to each one? > > Thankfully, no. Hmm :(. > > What I'm trying to do is to avoid having "import X" statements > > everywhere by changing __builtin__. It seems my approach doesn't have > > quite the same effect as a true import though. > > And you can't just put all your imports together at the top of the > file because...? The application in question is bitbake, the parsing tool for the OpenEmbedded and Poky projects. We're talking about python code fragments spread across about 8,000 files which make up the "metadata" some of which is public and some of which is not. Rightly or wrongly bitbake does some interesting things with its execution contexts for these code fragments. Lets just say its not a traditional use case, we know the way bitbake does some things is evil but it does other things rather well and we can't break those. Cheers, Richard From deets at nospam.web.de Wed Nov 11 09:37:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 15:37:15 +0100 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <7m00grF3fr11qU1@mid.uni-berlin.de> 7stud schrieb: > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > Installing easy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > > 2) ...run the following as super-user (or administrator): > > easy_install lxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_install lxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_install lxml > > ----------- > > My os is mac os x 10.4.11. But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_install lxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. Nonsense. First of all, developers aren't "the average user". Second, the inability of others doesn't make a programmer worse. And third, there are limits to what extend one can anticipate the ineptness of others to read. The page you cite from starts with: For special installation instructions regarding MS Windows and MacOS-X, see below. And below you find this link: http://codespeak.net/lxml/build.html#building-lxml-on-macos-x Which contains the proper command STATIC_DEPS=true sudo easy_install lxml Diez From benjamin.kaplan at case.edu Wed Nov 11 09:40:43 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:40:43 -0500 Subject: PyQt 2 Exe In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 8:29 AM, baboucarr sanneh wrote: > Hi guys, > > I wan to make a gui app using pyqt so i have done some thing already now i > want to save it as an exe file so that i can give it out to users who dont > have pyqt installed? (windows users)..Please help me out on this one..thnx > > Regards > > $LIM $H at DY > http://lmgtfy.com/?q=python+exe the second link is to http://www.py2exe.org which is a program that bundles Python apps, the interpreter itself, and any libraries they need into a single executable. > > ________________________________ > Keep your friends updated? even when you?re not signed in. > -- > http://mail.python.org/mailman/listinfo/python-list > > From benjamin.kaplan at case.edu Wed Nov 11 09:46:35 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:46:35 -0500 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: On Wed, Nov 11, 2009 at 7:49 AM, 7stud wrote: > I'm trying to install lxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > Installing easy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > > 2) ...run the following as super-user (or administrator): > > easy_install lxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_install lxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_install lxml > > ----------- > > My os is mac os x 10.4.11. ? But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_install lxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installing easy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found > > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. > > 1) It's not Python's fault that OS X doesn't add things to the path when its in a framework (like Python). 2) You almost got the command right. Environment variables are set before *any* command, including sudo. STATIC_DEPS=true sudo easy_install lxml > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From bbxx789_05ss at yahoo.com Wed Nov 11 09:54:23 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 06:54:23 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <3b94f11a-f4c8-4a84-aa71-93aed98b7bdc@f10g2000vbl.googlegroups.com> On Nov 11, 6:31?am, Jussi Piitulainen wrote: > 7stud writes: > > I'm trying to install lxml, but I can't figure out the installation > > instructions. ?Here: > ... > > My os is mac os x 10.4.11. ? But this: > > > STATIC_DEPS=true easy_install lxml > > > is not a valid command: > > > $ sudo STATIC_DEPS=true easy_install lxml > > Password: > > sudo: STATIC_DEPS=true: command not found > > Maybe > > ? ?STATIC_DEPS=true sudo easy_install lxml > > And be running Bash or some other Bourne type shell. > That worked. (The Terminal app on my mac uses bash by default.) Unfortunately, easy_install was not able to install lxml! Here is the output: --- $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: sudo: STATIC_DEPS=true: command not found $ STATIC_DEPS=true sudo /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: Searching for lxml Reading http://pypi.python.org/simple/lxml/ Reading http://codespeak.net/lxml Best match: lxml 2.2.3 Downloading http://codespeak.net/lxml/lxml-2.2.3.tgz Processing lxml-2.2.3.tgz Running lxml-2.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install- r2obQa/lxml-2.2.3/egg-dist-tmp-7v5A1n Building lxml version 2.2.3. Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.6/bin/ easy_install", line 8, in load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1712, in main File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1700, in with_ei_usage File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 1716, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 211, in run File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 446, in easy_install File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 476, in install_item File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 655, in install_eggs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 930, in build_and_install File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ easy_install.py", line 919, in run_setup File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 62, in run_setup File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 105, in run File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ sandbox.py", line 64, in File "setup.py", line 119, in File "/tmp/easy_install-r2obQa/lxml-2.2.3/setupinfo.py", line 51, in ext_modules TypeError: build_libxml2xslt() got an unexpected keyword argument 'libiconv_version' From benjamin.kaplan at case.edu Wed Nov 11 09:56:08 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 09:56:08 -0500 Subject: installing lxml ? In-Reply-To: <7lvvmaF3ga6r2U1@mid.uni-berlin.de> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7lvvmaF3ga6r2U1@mid.uni-berlin.de> Message-ID: On Wed, Nov 11, 2009 at 9:23 AM, Diez B. Roggisch wrote: > Chris Rebert schrieb: >> >> On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: >>> >>> I'm trying to install lxml, but I can't figure out the installation >>> instructions. ?Here: >>> >>> http://codespeak.net/lxml/installation.html >>> >>> it says: >>> >>> 1) Get the easy_install tool. >> >> >>> >>> My os is mac os x 10.4.11. >> >> I would recommend installing fink (http://www.finkproject.org/) and >> then `sudo fink install setuptools-py26`. >> As a bonus, you'll get a more up-to-date Python installed separate >> from the system one (so you don't need to worry about hosing it). > > Which doesn't run any cocoa or other osx-specific code. Which some might > call "hosed from the very beginning". > http://pdb.finkproject.org/pdb/package.php/pyobjc-py26 I personally use Macports (it's got more stuff and more up to date from what I've found), but compiling all those packages can take a while especially for something with as many dependencies as Python. > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From bbxx789_05ss at yahoo.com Wed Nov 11 10:12:39 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 07:12:39 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> Message-ID: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> On Nov 11, 7:37?am, "Diez B. Roggisch" wrote: > And third, > there are limits to what extend one can anticipate the ineptness of > others to read. The page you cite from starts with: > > ? ?For special installation instructions regarding MS Windows and > MacOS-X, see below. > > And below you find this link: > > ? ?http://codespeak.net/lxml/build.html#building-lxml-on-macos-x > > Which contains the proper command > > ? ?STATIC_DEPS=true sudo easy_install lxml > Your characterization of that web page is so fraudulent that I can only say one thing in response: You are a damn liar. From mad.mick at gmx.de Wed Nov 11 10:14:59 2009 From: mad.mick at gmx.de (Mick Krippendorf) Date: Wed, 11 Nov 2009 16:14:59 +0100 Subject: Basic list/dictionary question In-Reply-To: <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> <150fecd6-5d1d-461b-93e1-f1e5307704d1@u16g2000pru.googlegroups.com> Message-ID: Ralax wrote: > On Nov 11, 8:58 pm, Chris Rebert wrote: >> In [2]: def foo(z, a=[]): >> ...: a.append(z) >> ...: return a >> ...: >> >> In [3]: foo(1) >> Out[3]: [1] >> >> In [4]: foo(2) >> Out[4]: [1, 2] >> >> In [5]: foo(2) >> Out[5]: [1, 2, 2] >> >> In [6]: foo(3) >> Out[6]: [1, 2, 2, 3] >> >> In [7]: foo(4,[]) >> Out[7]: [4] >> >> In [8]: foo(5) >> Out[8]: [1, 2, 2, 3, 5] > > Usefull! I think Chris post was meant as a warning, but yes, it is useful sometimes. Here's a less error-prone version: >>> def bar(): ... def foo(z, a=[]): ... a.append(z) ... return a ... return foo ... >>> f = bar() >>> f(1) [1] >>> f(2) [1, 2] >>> g = bar() >>> g(3) [3] >>> g(4) [3, 4] Regards, Mick. From stefan_ml at behnel.de Wed Nov 11 10:17:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 11 Nov 2009 16:17:49 +0100 Subject: installing lxml ? In-Reply-To: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: <4afad59d$0$6736$9b4e6d93@newsspool2.arcor-online.net> 7stud, 11.11.2009 16:12: > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: >> And third, >> there are limits to what extend one can anticipate the ineptness of >> others to read. The page you cite from starts with: >> >> For special installation instructions regarding MS Windows and >> MacOS-X, see below. >> >> And below you find this link: >> >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x >> >> Which contains the proper command >> >> STATIC_DEPS=true sudo easy_install lxml > > Your characterization of that web page is so fraudulent that I can > only say one thing in response: You are a damn liar. PLONK. Stefan From highcar at gmail.com Wed Nov 11 10:20:10 2009 From: highcar at gmail.com (elca) Date: Wed, 11 Nov 2009 07:20:10 -0800 (PST) Subject: win32com IE interface PAMIE javascript click Message-ID: <26302679.post@talk.nabble.com> Hello, these day im making some script. i have encounter some problem with my script work. problem is i want to click emulate javascript on following site. http://news.naver.com/main/presscenter/category.nhn this site is news site. and everyday news content also changed, but javascript is not changed. for example i want to click javascript every inside 'li' element . how can i make it work with Pamie or win32com IE interface? thanks in advance
  • http://www.bloter.net/wp-content/bloter_html/2009/11/11/19083.html ???? ??? ?? ?? ???????? MS vs. VM??,
  • http://www.bloter.net/wp-content/bloter_html/2009/11/11/19105.html http://static.naver.com/newscast/2009/1111/1615301154902609.jpg "??????? PLM ?? ??"
  • -- View this message in context: http://old.nabble.com/win32com-IE-interface-PAMIE-javascript-click-tp26302679p26302679.html Sent from the Python - python-list mailing list archive at Nabble.com. From coldtortuga at gmail.com Wed Nov 11 11:13:54 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Wed, 11 Nov 2009 08:13:54 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: Hmmm. I am trying some algorithms, and timeit reports that a list.extend variant is fastest... WTH?! Really this seems like it must be a "bug" in implementing the "[None]*x" idiom. As expected, appending one-at-a-time is slowest (by an order of magnitude): % python -m timeit -s "N=1000000" \ "z=[2**32-1]" \ "while len(z) References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi wrote: > On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > >> Victor Subervi wrote: >> Wrong? >> 2) you don't show the error traceback >> > because there are none > > try: # It does this, because I've printed 'getpic1.py' etc. > getpic = "getpic" + str(w) + ".py" > try: > os.remove(getpic) > except: > pass There are no error tracebacks because you're deliberately suppressing them with the except: clause above. A bare except: clause *may* be acceptable in production code, where you may *want* to silently ignore all errors, but if you're trying to debug something then it's really not helpful. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Wed Nov 11 11:42:27 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 11:42:27 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury wrote: > On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >> >> Victor Subervi wrote: >>> >> > Wrong? >>> >>> 2) you don't show the error traceback >>> >>> because there are none >> >> try: # It does this, because I've printed 'getpic1.py' etc. >> getpic = "getpic" + str(w) + ".py" >> try: >> os.remove(getpic) >> except: >> pass >> > > There are no error tracebacks because you're deliberately suppressing them > with the except: clause above. A bare except: clause *may* be acceptable in > production code, where you may *want* to silently ignore all errors, but if > you're trying to debug something then it's really not helpful. > Well, that's the *only* place where I do so, and I dare say that in that case, it makes all the sense in the world. If there is no file getpic to remove, then don't worry about it! No, that's not where the error is. Please suggest something else. TIA, V > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jenn.duerr at gmail.com Wed Nov 11 11:43:29 2009 From: jenn.duerr at gmail.com (noydb) Date: Wed, 11 Nov 2009 08:43:29 -0800 (PST) Subject: Pause a script before termination Message-ID: Hi All, I want to pause my script before it terminates, just so a user can have a moment to read some print statements I include at the end. How can this be accomplished? Thanks! From jenn.duerr at gmail.com Wed Nov 11 11:47:05 2009 From: jenn.duerr at gmail.com (noydb) Date: Wed, 11 Nov 2009 08:47:05 -0800 (PST) Subject: Pause a script before termination References: Message-ID: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> On Nov 11, 11:43?am, noydb wrote: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. ?How > can this be accomplished? > > Thanks! Never mind, duh, found my answer now import time time.sleep(10) #10 second pause From lenz at joinville.udesc.br Wed Nov 11 11:49:02 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Wed, 11 Nov 2009 08:49:02 -0800 Subject: Unexpected python exception In-Reply-To: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <200911110849.02346.lenz@joinville.udesc.br> Em Qua 11 Nov 2009, ?s 03:21:55, Diez B. Roggisch escreveu: > Richard Purdie schrieb: > > I've been having problems with an unexpected exception from python which > > I can summarise with the following testcase: > > > > def A(): > > import __builtin__ > > import os > > > > __builtin__.os = os > > > > def B(): > > os.stat("/") > > import os > > > > A() > > B() > > > > which results in: > > > > Traceback (most recent call last): > > File "./test.py", line 12, in > > B() > > File "./test.py", line 8, in B > > os.stat("/") > > UnboundLocalError: local variable 'os' referenced before assignment > > > > If I remove the "import os" from B(), it works as expected. > > > >>From what I've seen, its very unusual to have something operate > > > > "backwards" in scope in python. Can anyone explain why this happens? > > As the import-statement in a function/method-scope doesn't leak the > imported names into the module scope, python treats them as locals. > Which makes your code equivalent to > > > x = 1000 > > def foo(): > print x > x = 10 > > Throws the same error. The remedy is to inform python that a specific > name belongs to global scope, using the "global"-statement. > > def foo(): > global x > print x > x = 10 > > > Beware though that then of course *assigning* to x is on global level. > This shouldn't be of any difference in your case though, because of the > import-only-once-mechanics of python. > > Diez > So...it should not work def A(): import __builtin__ import os __builtin__.os = os A() os.stat("/") but it does. Why ? B() cannot see the import, but the global level can ? Thanks. Eduardo. -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From rami.chowdhury at gmail.com Wed Nov 11 11:54:45 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 11 Nov 2009 08:54:45 -0800 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 08:42:27 -0800, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury > wrote: > >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >>> >>> Victor Subervi wrote: >>>> >>> >> Wrong? >>>> >>>> 2) you don't show the error traceback >>>> >>>> because there are none >>> >>> try: # It does this, because I've printed 'getpic1.py' etc. >>> getpic = "getpic" + str(w) + ".py" >>> try: >>> os.remove(getpic) >>> except: >>> pass >>> >> >> There are no error tracebacks because you're deliberately suppressing >> them >> with the except: clause above. A bare except: clause *may* be >> acceptable in >> production code, where you may *want* to silently ignore all errors, >> but if >> you're trying to debug something then it's really not helpful. >> > > Well, that's the *only* place where I do so, and I dare say that in that > case, it makes all the sense in the world. If there is no file getpic to > remove, then don't worry about it! Sure, and that's your decision to make... in an environment where you know everything else is working fine and the *only reason* that os.remove file is failing is that the file isn't present. If it's failing due to a permissions error, for instance, you won't be any wiser. I'd suggest removing that except clause, seeing what exception is actually raised, and posting that to the list. > No, that's not where the error is.Please > suggest something else. if os.path.exists(getpic): os.unlink(getpic) else: print "File %s could not be found!" % getpic -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From carsten.haese at gmail.com Wed Nov 11 11:58:31 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 11 Nov 2009 11:58:31 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: Victor Subervi wrote: > Here's > a bigger code snippet with the entire try clause: > > if 14 < x < 20: # This just shows that it's a pic, not some > other type of data > y += 1 > w += 1 > try: # It does this, because I've printed 'getpic1.py' etc. > getpic = "getpic" + str(w) + ".py" > try: > os.remove(getpic) > except: > pass > code = """#! /usr/bin/python > import cgitb; cgitb.enable() > import MySQLdb > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > def pic(): > user, passwd, db, host = login() > form = cgi.FieldStorage() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > sql = "select pic%s from products where ID=%s;" > cursor.execute(sql) > content = cursor.fetchone()[0] > cursor.close() > print content > print 'Content-type: image/jpeg' > print > pic()""" % (str(w), str(i)) > script = open(getpic, "w") # I've deleted everything below > this line to the except to test > script.write(code) > print '
  • \n' % > (getpic) > count2 += 1 > except: > print '' > else: > print '\n' % (field) > x += 1 If I'm understanding correctly what you're doing here, you're generating an HTML page with image tags, and at the same time you're generating the scripts whose purpose it is to serve the corresponding images' data. This is a terrible approach for the following reason: If two different users request this page for two different product IDs at roughly the same time, the getpic scripts for the first user will be overwritten by the getpic scripts for the second user before the first user's browser had a chance to issue its requests for the results for his getpic scripts. Rather than auto-generating on-the-fly variants of the getpic scripts that only differ in the picture number and product ID, you should have just one static getpic script that takes parameters from the URL that tell it which image number and product ID to use. This will fix your problem indirectly because then your script won't have to write out any files at all. -- Carsten Haese http://informixdb.sourceforge.net From philip at semanchuk.com Wed Nov 11 11:58:58 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 11 Nov 2009 11:58:58 -0500 Subject: Pause a script before termination In-Reply-To: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> References: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> Message-ID: <5EE56713-3E25-4DFF-A61F-0B53E0B5189C@semanchuk.com> On Nov 11, 2009, at 11:47 AM, noydb wrote: > On Nov 11, 11:43 am, noydb wrote: >> Hi All, >> >> I want to pause my script before it terminates, just so a user can >> have a moment to read some print statements I include at the end. >> How >> can this be accomplished? >> >> Thanks! > > Never mind, duh, found my answer now > > import time > time.sleep(10) #10 second pause Good for you for tracking that down. However, might I suggest that you replace that with a message like "Press to clear this message and end the program"? From gherron at islandtraining.com Wed Nov 11 11:59:12 2009 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 11 Nov 2009 08:59:12 -0800 Subject: Pause a script before termination In-Reply-To: References: Message-ID: <4AFAED60.9050902@islandtraining.com> noydb wrote: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. How > can this be accomplished? > > Thanks! > If your IO is to/from a command line window, try this: raw_input('Hit ENTER to exit: ') Gary Herron From sanneh27 at hotmail.com Wed Nov 11 12:00:41 2009 From: sanneh27 at hotmail.com (baboucarr sanneh) Date: Wed, 11 Nov 2009 17:00:41 +0000 Subject: Pause a script before termination In-Reply-To: <210cc765-7176-4ffd-8f05-076fe808a694@s31g2000yqs.googlegroups.com> References: Message-ID: $LIM $H at DY > From: jenn.duerr at gmail.com > Subject: Re: Pause a script before termination > Date: Wed, 11 Nov 2009 08:47:05 -0800 > To: python-list at python.org > > On Nov 11, 11:43 am, noydb wrote: > > Hi All, > > > > I want to pause my script before it terminates, just so a user can > > have a moment to read some print statements I include at the end. How > > can this be accomplished? > > > > Thanks! > > Never mind, duh, found my answer now > > import time > time.sleep(10) #10 second pause > -- > http://mail.python.org/mailman/listinfo/python-list okay thank you _________________________________________________________________ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at seehart.com Wed Nov 11 12:10:26 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 11 Nov 2009 09:10:26 -0800 Subject: Authentication session with urllib2 In-Reply-To: References: Message-ID: <4AFAF002.2040906@seehart.com> An HTML attachment was scrubbed... URL: From no.email at please.post Wed Nov 11 12:16:43 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 17:16:43 +0000 (UTC) Subject: How to specify Python version in script? Message-ID: I have a script that must be run with Python 2.6.x. If one tries to run it with, say, 2.5.x, *eventually* it runs into problems and crashes. (The failure is quicker if one attempts to run it with Python 3.x.) Is there some way to specify at the very beginning of the script the acceptable range of Python versions? TIA! kynn P.S. I know that I can hardcode the path to a specific intpreter in the #! line, but I'm trying to keep the code a bit more general than that. From lifeofsun at gmail.com Wed Nov 11 12:18:01 2009 From: lifeofsun at gmail.com (leo zhao) Date: Wed, 11 Nov 2009 09:18:01 -0800 (PST) Subject: ask a question about the module Message-ID: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> when I run a program, it list the hint: Could not import module "Gnuplot" - it is not installed on your system. You need to install the Gnuplot.py package. \easyviz\gnuplot_.py(41) : Traceback (most recent call last): File "E:\study\python\commodity modle 10.23.py", line 3, in import multipleloop as mp File "E:\study\python\multipleloop.py", line 81, in from scitools.misc import str2obj File "C:\Python26\lib\site-packages\scitools\__init__.py", line 67, in import sys, std File "C:\Python26\lib\site-packages\scitools\std.py", line 26, in from scitools.easyviz import * File "C:\Python26\lib\site-packages\scitools\easyviz\__init__.py", line 1819, in exec(cmd) File "", line 1, in File "C:\Python26\lib\site-packages\scitools\easyviz\gnuplot_.py", line 42, in import Gnuplot ImportError: No module named Gnuplot the above is the hint from python window, I know Gnuplot is a software and it can help us to make graphs, however, after I download Gnuplot and run it, the problem still exist. Is there any expert can help me solve this problem? Thank you very much! From victorsubervi at gmail.com Wed Nov 11 12:30:04 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 12:30:04 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> On Wed, Nov 11, 2009 at 11:58 AM, Carsten Haese wrote: > Victor Subervi wrote: > > Here's > > a bigger code snippet with the entire try clause: > > > > if 14 < x < 20: # This just shows that it's a pic, not some > > other type of data > > y += 1 > > w += 1 > > try: # It does this, because I've printed 'getpic1.py' etc. > > getpic = "getpic" + str(w) + ".py" > > try: > > os.remove(getpic) > > except: > > pass > > code = """#! /usr/bin/python > > import cgitb; cgitb.enable() > > import MySQLdb > > import cgi > > import sys,os > > sys.path.append(os.getcwd()) > > from login import login > > def pic(): > > user, passwd, db, host = login() > > form = cgi.FieldStorage() > > db = MySQLdb.connect(host, user, passwd, db) > > cursor= db.cursor() > > sql = "select pic%s from products where ID=%s;" > > cursor.execute(sql) > > content = cursor.fetchone()[0] > > cursor.close() > > print content > > print 'Content-type: image/jpeg' > > print > > pic()""" % (str(w), str(i)) > > script = open(getpic, "w") # I've deleted everything below > > this line to the except to test > > script.write(code) > > print '\n' % > > (getpic) > > count2 += 1 > > except: > > print '' > > else: > > print '\n' % (field) > > x += 1 > > If I'm understanding correctly what you're doing here, you're generating > an HTML page with image tags, and at the same time you're generating the > scripts whose purpose it is to serve the corresponding images' data. > This is a terrible approach for the following reason: If two different > users request this page for two different product IDs at roughly the > same time, the getpic scripts for the first user will be overwritten by > the getpic scripts for the second user before the first user's browser > had a chance to issue its requests for the results for his getpic scripts. > > Rather than auto-generating on-the-fly variants of the getpic scripts > that only differ in the picture number and product ID, you should have > just one static getpic script that takes parameters from the URL that > tell it which image number and product ID to use. > I will do that after I fix the problem > > This will fix your problem indirectly because then your script won't > have to write out any files at all. > No files are being written at all! No, this doesn't fix the problem! Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Wed Nov 11 12:33:25 2009 From: drobinow at gmail.com (David Robinow) Date: Wed, 11 Nov 2009 12:33:25 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: <4eb0089f0911110933l1eed6ecamf9904bd107634cf1@mail.gmail.com> On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: > > > > > I have a script that must be run with Python 2.6.x. ?If one tries > to run it with, say, 2.5.x, *eventually* it runs into problems and > crashes. ?(The failure is quicker if one attempts to run it with > Python 3.x.) > > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? > > TIA! > > kynn > > P.S. I know that I can hardcode the path to a specific intpreter > in the #! line, but I'm trying to keep the code a bit more general > than that. > -- > http://mail.python.org/mailman/listinfo/python-list > sys.version ? sys.version_info ? From carsten.haese at gmail.com Wed Nov 11 12:46:51 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Wed, 11 Nov 2009 12:46:51 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110930h2abfa918oea487f9e58bc6e80@mail.gmail.com> Message-ID: Victor Subervi wrote: > I will do that after I fix the problem "Doing that" is the fix. > No, this doesn't fix the problem! How do you know? You obviously haven't tried it, since you say you have yet to do it. -- Carsten Haese http://informixdb.sourceforge.net From benjamin.kaplan at case.edu Wed Nov 11 13:18:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:18:39 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: > > > > > I have a script that must be run with Python 2.6.x. ?If one tries > to run it with, say, 2.5.x, *eventually* it runs into problems and > crashes. ?(The failure is quicker if one attempts to run it with > Python 3.x.) > > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? > min_version = (2,6) import sys if sys.version_info < min_version : print >> stderr, "must be run with at least Python 2.6" sys.exit(1) > TIA! > > kynn > > P.S. I know that I can hardcode the path to a specific intpreter > in the #! line, but I'm trying to keep the code a bit more general > than that. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Wed Nov 11 13:20:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:20:58 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury > wrote: >> >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi >> wrote: >> >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >>> >>>> Victor Subervi wrote: >> >>>> Wrong? >>>> 2) you don't show the error traceback >>>> >>> because there are none >>> >>> ? ? ? ? ? ?try: # It does this, because I've printed 'getpic1.py' etc. >>> ? ? ? ? ? ? ?getpic = "getpic" + str(w) + ".py" >>> ? ? ? ? ? ? ?try: >>> ? ? ? ? ? ? ? ?os.remove(getpic) >>> ? ? ? ? ? ? ?except: >>> ? ? ? ? ? ? ? ?pass >> >> There are no error tracebacks because you're deliberately suppressing them >> with the except: clause above. A bare except: clause *may* be acceptable in >> production code, where you may *want* to silently ignore all errors, but if >> you're trying to debug something then it's really not helpful. > > Well, that's the *only* place where I do so, and I dare say that in that > case, it makes all the sense in the world. If there is no file getpic to > remove, then don't worry about it! No, that's not where the error is. Please > suggest something else. > TIA, > V Even so, a bare except is a bad idea. Just catch the OSError. That way, you won't catch something like an NameError if you misspell getpic or something like that. >> >> >> -- >> Rami Chowdhury >> "Never attribute to malice that which can be attributed to stupidity" -- >> Hanlon's Razor >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From javier.collado at gmail.com Wed Nov 11 13:28:37 2009 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 11 Nov 2009 19:28:37 +0100 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: Hello, If you are working on linux, you can change the shebang line from: #!/usr/bin/python to: #!/usr/bin/python2.6 Best regards, Javier P.S. If you just want to avoid python 3 while running the latest python 2.x version, this should also work: #!/usr/bin/python2 2009/11/11 Benjamin Kaplan : > On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >> >> >> >> >> I have a script that must be run with Python 2.6.x. ?If one tries >> to run it with, say, 2.5.x, *eventually* it runs into problems and >> crashes. ?(The failure is quicker if one attempts to run it with >> Python 3.x.) >> >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >> > > min_version = (2,6) > import sys > if sys.version_info < min_version : > ? print >> stderr, "must be run with at least Python 2.6" > ? sys.exit(1) > > >> TIA! >> >> kynn >> >> P.S. I know that I can hardcode the path to a specific intpreter >> in the #! line, but I'm trying to keep the code a bit more general >> than that. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Wed Nov 11 13:39:17 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Nov 2009 13:39:17 -0500 Subject: How to specify Python version in script? In-Reply-To: References: Message-ID: On Wed, Nov 11, 2009 at 1:28 PM, Javier Collado wrote: > Hello, > > If you are working on linux, you can change the shebang line from: > #!/usr/bin/python > > to: > #!/usr/bin/python2.6 > > Best regards, > ? ?Javier > > P.S. If you just want to avoid python 3 while running the latest > python 2.x version, this should also work: > #!/usr/bin/python2 > True, except that it doesn't meet the OP's requirements. The OP wanted to be able to specify a range of versions. The problem with changing the shebang line is that there's no way to say "python 2.5 or 2.6 or 2.7" Regardless, it's much better to do #!/usr/bin/evn python2.6 instead of hard-coding the path because not everyone has their interpreter in the same spot. I have the Macports python 2.6.4 installed in /opt/local/bin and I'd get kind of annoyed if a script, insisted on using the 2.6.1 that came with the system, especially if it depends on 3rd party libraries. > 2009/11/11 Benjamin Kaplan : >> On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >>> >>> >>> >>> >>> I have a script that must be run with Python 2.6.x. ?If one tries >>> to run it with, say, 2.5.x, *eventually* it runs into problems and >>> crashes. ?(The failure is quicker if one attempts to run it with >>> Python 3.x.) >>> >>> Is there some way to specify at the very beginning of the script >>> the acceptable range of Python versions? >>> >> >> min_version = (2,6) >> import sys >> if sys.version_info < min_version : >> ? print >> stderr, "must be run with at least Python 2.6" >> ? sys.exit(1) >> >> >>> TIA! >>> >>> kynn >>> >>> P.S. I know that I can hardcode the path to a specific intpreter >>> in the #! line, but I'm trying to keep the code a bit more general >>> than that. >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From boblatest at yahoo.com Wed Nov 11 14:01:33 2009 From: boblatest at yahoo.com (Robert Latest) Date: 11 Nov 2009 19:01:33 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> Message-ID: <7m0g0cF3d568fU1@mid.uni-berlin.de> r wrote: > Just thinking out loud here...what if variable assignments could > return a value... hmmm? Not to them selfs of course but to a caller, > like an if statement... > > if a=openfile: > # do something with a That's like in C. I sometimes miss it in Python. robert From victorsubervi at gmail.com Wed Nov 11 14:26:53 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:26:53 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> Message-ID: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> On Wed, Nov 11, 2009 at 1:20 PM, Benjamin Kaplan wrote: > On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi > wrote: > > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury < > rami.chowdhury at gmail.com> > > wrote: > >> > >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi > >> wrote: > >> > >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > >>> > >>>> Victor Subervi wrote: > >> > >>>> Wrong? > >>>> 2) you don't show the error traceback > >>>> > >>> because there are none > >>> > >>> try: # It does this, because I've printed 'getpic1.py' etc. > >>> getpic = "getpic" + str(w) + ".py" > >>> try: > >>> os.remove(getpic) > >>> except: > >>> pass > >> > Ok, I rewrote the script so that it calls one file called "getpic.py" with parameters: #! /usr/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login form = cgi.FieldStorage() w = form.getfirst('w', '') i = form.getfirst('i', '') def pic(): user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic%s from products where ID=%s;" % (w, i) cursor.execute(sql) content = cursor.fetchone()[0] cursor.close() print content print 'Content-type: image/jpeg' print pic() Now, the problem is that it doesn't print the picture. It prints only the url. Please try: http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 Now, if I go into mysql and the correct database and enter: select pic1 from products where ID=1; it starts printing out all sorts of crap (indicative of an image) and I have to close my ssh client. So it's there, all right. So, here I am back to trying to figure out how to get that stupid image to print. Please take a look at the code above and advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Nov 11 14:33:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 14:33:09 -0500 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: Steven D'Aprano wrote: >>> Why is the third example, with an if... test, so special that it needs >>> special syntax to make it a two-liner? >> ...because Beautiful is better than ugly. > > I can quote the Zen too: > > Special cases aren't special enough to break the rules. > > You haven't demonstrated that your construct is "beautiful", or the > existing way of writing it is "ugly". > > # apparently not ugly > x = func() > y = x + 1 > z = 2*x > > # also not ugly > var = range(N) > var.append(42) > find(23, var) > > # still not ugly > var = range(N) > for x in var: > do_something_with(x, var) > > # not ugly > var = MyClass() > with var.magic as x: > process(var) > > > # why is this ugly? > var = range(N) > if var: > process(var) This is the first time I have seen this explanation and justification of the status quo. Thanks for posting it so clearly. ... > What's so special about "truth-seeking"? as a second use > > for x in range(N) as var: > do_something_with(x, var) > > > That would save a line too, it would behave exactly as you specified, and > it uses virtually the identical syntax: "expr as name". I know that Guido does not want to generalize 'as' as a substitute for '=' except where really necessary. The three current uses in import, with, and except statements are necessary because the object being bound is produced in the statement itself and so the assignment cannot be separated into a prior proper assignment statement. Terry Jan Reedy From sridhar.ratna at gmail.com Wed Nov 11 14:38:23 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 11:38:23 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <8d874346-b5d7-4fd6-9ffe-391340145885@e4g2000prn.googlegroups.com> Much of these non-trivial build steps are abstracted in the ActiveState build repository. 1. Download ActivePython: http://www.activestate.com/activepython/ 2. Run "pypm install lxml" (on Mac, Linux or Windows) $ pypm install lxml Ready to perform these actions: The following packages will be installed: lxml-2.2.2 Get: [pypm.activestate.com] lxml 2.2.2-2 Installing lxml-2.2.2 $ python -c "import lxml; print lxml.__file__" /Users/sridharr/.local/lib/python2.6/site-packages/lxml/__init__.py $ -srid On Nov 11, 4:49?am, 7stud wrote: > I'm trying to installlxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > > Ok, I went to the easy_install website, downloaded, and installed it. > The last two lines of the output during installation said this: > > Installingeasy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/binInstallingeasy_install-2.6 script to /Library/Frameworks/ > Python.framework/Versions/2.6/bin > > 2) ...run the following as super-user (or administrator): > > easy_installlxml > > On MS Windows, the above will install the binary builds that we > provide. If there is no binary build of the latest release yet, please > search PyPI for the last release that has them and pass that version > to easy_install like this: > easy_installlxml==2.2.2 > > On Linux (and most other well-behaved operating systems), easy_install > will manage to build the source distribution as long as libxml2 and > libxslt are properly installed, including development packages, i.e. > header files, etc. Use your package management tool to look for > packages like libxml2-dev or libxslt-devel if the build fails, and > make sure they are installed. > > On MacOS-X, use the following to build the source distribution, and > make sure you have a working Internet connection, as this will > download libxml2 and libxslt in order to build them: > STATIC_DEPS=true easy_installlxml > > ----------- > > My os is mac os x 10.4.11. ? But this: > > STATIC_DEPS=true easy_installlxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > > In any case, if I do this: > > $ sudo easy_installlxml > sudo: easy_install: command not found > > In other words, when I installed easy_install it did not add anything > to my PATH which points to the installation directory mentioned during > installation: > > Installingeasy_install script to /Library/Frameworks/Python.framework/ > Versions/2.6/bin > > Ok, so I need to use the full path to the easy_install program (which > is not mentioned ANYWHERE in the installation instructions), i.e. > > /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install > > ...but this still isn't going to work: > > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the average > user, then you are the equivalent of one of the worst programmers on > the planet. From sridhar.ratna at gmail.com Wed Nov 11 14:39:54 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 11:39:54 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <3b94f11a-f4c8-4a84-aa71-93aed98b7bdc@f10g2000vbl.googlegroups.com> Message-ID: <4ad5ade3-1212-4cd7-b279-b280adea9503@i12g2000prg.googlegroups.com> On Nov 11, 6:54?am, 7stud wrote: > > Unfortunately, easy_install was not able to installlxml! ?Here is the > output: > > --- > $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > sudo: STATIC_DEPS=true: command not found > $ STATIC_DEPS=true sudo /Library/Frameworks/Python.framework/Versions/ > 2.6/bin/easy_installlxml > Password: > Searching forlxml > Readinghttp://pypi.python.org/simple/lxml/ > Readinghttp://codespeak.net/lxml > Best match:lxml2.2.3 > Downloadinghttp://codespeak.net/lxml/lxml-2.2.3.tgz > Processinglxml-2.2.3.tgz > Runninglxml-2.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install- > r2obQa/lxml-2.2.3/egg-dist-tmp-7v5A1n > Buildinglxmlversion 2.2.3. > Traceback (most recent call last): > ? File "/Library/Frameworks/Python.framework/Versions/2.6/bin/ > easy_install", line 8, in > ? ? load_entry_point('setuptools==0.6c11', 'console_scripts', > 'easy_install')() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1712, in main > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1700, in with_ei_usage > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 1716, in > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/core.py", line 152, in setup > ? ? dist.run_commands() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/dist.py", line 975, in run_commands > ? ? self.run_command(cmd) > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/distutils/dist.py", line 995, in run_command > ? ? cmd_obj.run() > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 211, in run > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 446, in easy_install > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 476, in install_item > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 655, in install_eggs > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 930, in build_and_install > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/command/ > easy_install.py", line 919, in run_setup > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 62, in run_setup > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 105, in run > ? File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/site-packages/setuptools-0.6c11-py2.6.egg/setuptools/ > sandbox.py", line 64, in > ? File "setup.py", line 119, in > > ? File "/tmp/easy_install-r2obQa/lxml-2.2.3/setupinfo.py", line 51, in > ext_modules > TypeError: build_libxml2xslt() got an unexpected keyword argument > 'libiconv_version' https://bugs.launchpad.net/lxml/+bug/480225 -srid From victorsubervi at gmail.com Wed Nov 11 14:42:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:42:39 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: <4dc0cfea0911111142hbac8862nf649cc80dbf43d14@mail.gmail.com> Never mind. It appears my old original file from a couple of years ago prints out the image nicely. Thanks all! V On Wed, Nov 11, 2009 at 2:26 PM, Victor Subervi wrote: > On Wed, Nov 11, 2009 at 1:20 PM, Benjamin Kaplan > wrote: > >> On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi >> wrote: >> > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury < >> rami.chowdhury at gmail.com> >> > wrote: >> >> >> >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi >> >> wrote: >> >> >> >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: >> >>> >> >>>> Victor Subervi wrote: >> >> >> >>>> Wrong? >> >>>> 2) you don't show the error traceback >> >>>> >> >>> because there are none >> >>> >> >>> try: # It does this, because I've printed 'getpic1.py' etc. >> >>> getpic = "getpic" + str(w) + ".py" >> >>> try: >> >>> os.remove(getpic) >> >>> except: >> >>> pass >> >> >> > > Ok, I rewrote the script so that it calls one file called "getpic.py" with > parameters: > > #! /usr/bin/python > import cgitb; cgitb.enable() > import MySQLdb > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > form = cgi.FieldStorage() > w = form.getfirst('w', '') > i = form.getfirst('i', '') > def pic(): > user, passwd, db, host = login() > form = cgi.FieldStorage() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > sql = "select pic%s from products where ID=%s;" % (w, i) > cursor.execute(sql) > content = cursor.fetchone()[0] > cursor.close() > print content > print 'Content-type: image/jpeg' > print > pic() > > Now, the problem is that it doesn't print the picture. It prints only the > url. Please try: > http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 > Now, if I go into mysql and the correct database and enter: > select pic1 from products where ID=1; > it starts printing out all sorts of crap (indicative of an image) and I > have to close my ssh client. So it's there, all right. So, here I am back to > trying to figure out how to get that stupid image to print. Please take a > look at the code above and advise. > TIA, > V > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Wed Nov 11 14:46:40 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 11 Nov 2009 11:46:40 -0800 Subject: Can't Write File In-Reply-To: <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: > Now, the problem is that it doesn't print the picture. It prints only the > url. Please try: > http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 > Now, if I go into mysql and the correct database and enter: > select pic1 from products where ID=1; > it starts printing out all sorts of crap (indicative of an image) and I > have > to close my ssh client. So it's there, all right. So, here I am back to > trying to figure out how to get that stupid image to print. Please take a > look at the code above and advise. I'm fairly sure this was gone through before -- what I'm getting is being properly sent as a JPEG, but it *doesn't contain valid JPEG data*, so the browser can't render it. What the URL you pointed me at seems to contain is the 'readable' representation of an array object. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Wed Nov 11 14:47:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 14:47:52 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> <4dc0cfea0911110842q431a13e0hcb0f6376325009f1@mail.gmail.com> <4dc0cfea0911111126p2dc7fdb1w265c33bce367df87@mail.gmail.com> Message-ID: <4dc0cfea0911111147l406d786fg930e51c2f67c1371@mail.gmail.com> On Wed, Nov 11, 2009 at 2:46 PM, Rami Chowdhury wrote: > Now, the problem is that it doesn't print the picture. It prints only the >> url. Please try: >> http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1 >> Now, if I go into mysql and the correct database and enter: >> select pic1 from products where ID=1; >> it starts printing out all sorts of crap (indicative of an image) and I >> have >> to close my ssh client. So it's there, all right. So, here I am back to >> trying to figure out how to get that stupid image to print. Please take a >> look at the code above and advise. >> > > I'm fairly sure this was gone through before -- what I'm getting is being > properly sent as a JPEG, but it *doesn't contain valid JPEG data*, so the > browser can't render it. What the URL you pointed me at seems to contain is > the 'readable' representation of an array object. > Yep. A million times before. The problem was the faulty hardware on the cheap server farm. I've moved ;) Thanks, V > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 71david at libero.it Wed Nov 11 14:50:35 2009 From: 71david at libero.it (David) Date: Wed, 11 Nov 2009 20:50:35 +0100 Subject: Pause a script before termination References: Message-ID: Il Wed, 11 Nov 2009 08:43:29 -0800 (PST), noydb ha scritto: > Hi All, > > I want to pause my script before it terminates, just so a user can > have a moment to read some print statements I include at the end. How > can this be accomplished? http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user D. From tjreedy at udel.edu Wed Nov 11 15:15:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 15:15:02 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: Robert P. J. Day wrote: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > > thoughts? Program_cost = human_writing&maintance_cost + running_cost*number_of_runs Nothing new here. The builtin types and many modules are written in C to reduce running cost for frequency used components. The first killer ap for Python was scientific computing with early numerical python, where people often run one-time combinations of inputs and constantly reused linear algebra functions. Google has an unusually high number of runs for many programs, making running_cost minimization important. At one time, C was not 'scaleable enough' for constantly rerun aps. Hotspots were hand rewritten in assembler. Apparently now, with processors more complex and compilers much improved, that is not longer much the case. I can imagine a day when code compiled from Python is routinely time-competitive with hand-written C. Terry Jan Reedy From no.email at please.post Wed Nov 11 15:16:50 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 20:16:50 +0000 (UTC) Subject: How can a module know the module that imported it? Message-ID: The subject line says it all. Thanks! kynn From no.email at please.post Wed Nov 11 15:19:00 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 20:19:00 +0000 (UTC) Subject: How to specify Python version in script? References: Message-ID: In Benjamin Kaplan writes: >On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >> >> >> >> >> I have a script that must be run with Python 2.6.x. =A0If one tries >> to run it with, say, 2.5.x, *eventually* it runs into problems and >> crashes. =A0(The failure is quicker if one attempts to run it with >> Python 3.x.) >> >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >> >min_version =3D (2,6) >import sys >if sys.version_info < min_version : > print >> stderr, "must be run with at least Python 2.6" > sys.exit(1) Thanks! kynn From davea at ieee.org Wed Nov 11 15:32:51 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 11 Nov 2009 15:32:51 -0500 Subject: CGI vs mod_python In-Reply-To: <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> Message-ID: <4AFB1F73.5070508@ieee.org> Victor Subervi wrote: > > The problem was not CGI. It turned out to be line-endings being mangled by > Windoze and __invisible __ in my unix editor. Lovely. > Thanks anyway, > V > > That's twice you've blamed Windows for the line-ending problem. Windows didn't create those crlf endings, your text editor did. If your editor can't control that, you could try a different one. Komodo for example can do it either way, or it can preserve whatever is being used in the loaded file. Similarly metapad, in spite of its huge simplicity, lets you decide, and can convert an existing file in either direction. And I'm a great believer in visible control characters. I configure Komodo to show me spaces in the lines, so I can see whether it's a tab or a space. It can also be configured to show end-of-line characters, so I presume that'd work here. See whether your Unix editor can show you this sort of thing. Finally, many FTP programs can be told to automatically convert line-endings when transferring text files. There's probably some risk that it'll mangle a non-text file, but it's worth considering. DaveA From tjreedy at udel.edu Wed Nov 11 15:37:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 15:37:00 -0500 Subject: installing lxml ? In-Reply-To: <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: 7stud wrote: > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: >> And third, >> there are limits to what extend one can anticipate the ineptness of Calling you inept was unnecessary, but.... >> others to read. The page you cite from starts with: You wrote " I'm trying to install lxml, but I can't figure out the installation instructions. Here: http://codespeak.net/lxml/installation.html " >> For special installation instructions regarding MS Windows and >> MacOS-X, see below. and that page indeed begins with the words above. >> And below you find this link: >> >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x >> >> Which contains the proper command >> >> STATIC_DEPS=true sudo easy_install lxml And this is also true. > Your characterization of that web page is so fraudulent that I can > only say one thing in response: You are a damn liar. So this makes no sense. If, when you have calmed down a bit, you have suggestions for improving the installation instructions, that might be more constructive. The lxml developers have obviously gone to some effort to give comprehensible instructions. Writing such is not easy. So if they have failed in your case, feedback might be considered. tjr From zac256 at gmail.com Wed Nov 11 15:40:38 2009 From: zac256 at gmail.com (Zac Burns) Date: Wed, 11 Nov 2009 12:40:38 -0800 Subject: Threaded import hang in cPickle.dumps In-Reply-To: References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <333edbe80911111240v27f17516y69f3d4e18d388fdf@mail.gmail.com> On Tue, Nov 10, 2009 at 2:27 PM, Benjamin Peterson wrote: > Zac Burns gmail.com> writes: >> What can I do about this? > > Not run it in a thread. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Isn't requesting that pickle not be used in a thread a bit of a tall order? Just thinking through the common use cases - database access, server request threads, file IO... pickle is commonly used in threads. Furthermore, the pickle documentation makes no mention of not being threadsafe. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From aahz at pythoncraft.com Wed Nov 11 16:06:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 13:06:07 -0800 Subject: Securing a multiprocessing.BaseManager connection via SSL References: Message-ID: In article , Jonas wrote: > >how can I secure the communication between two BaseManager objects? >Regarding the socket/SSL documentation I just need to secure the socket >by SSL. How can i get the socket object within the multiprocessing >module? You'll need to create subclasses of the objects in connection.py, but I'm not sure how to make multiprocessing use them. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Wed Nov 11 16:12:26 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 13:12:26 -0800 Subject: How can a module know the module that imported it? References: Message-ID: In article , kj wrote: > >The subject line says it all. You are probably trying to remove a screw with a hammer -- why don't you tell us what you really want to do and we'll come up with a Pythonic solution? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ethan at stoneleaf.us Wed Nov 11 16:44:06 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Nov 2009 13:44:06 -0800 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: <4AFB3026.2020408@stoneleaf.us> Aahz wrote: > In article , kj wrote: > >>The subject line says it all. > > > You are probably trying to remove a screw with a hammer -- why don't you > tell us what you really want to do and we'll come up with a Pythonic > solution? Well, I don't know what kj is trying to do, but my project is another (!) configuration program. (Don't worry, I won't release it... unless somebody is interested, of course !) So here's the idea so far: The configuration data is stored in a python module (call it settings.py). In order to be able to do things like add settings to it, save the file after changes are made, etc., settings.py will import the configuration module, called configure.py. A sample might look like this: import configure paths = configure.Item() paths.tables = 'c:\\app\\data' paths.temp = 'c:\\temp' And in the main program I would have: import settings main_table = dbf.Table('%s\\main' % paths.tables) # user can modify path locations, and does, so update # we'll say it changes to \work\temp settings.paths.temp = user_setting() settings.configure.save() And of course, at this point settings.py now looks like import configure paths = configure.Item() paths.tables = 'c:\\app\\data' paths.temp = 'c:\\work\\temp' Now, the tricky part is the line settings.configure.save() How will save know which module it's supposed to be re-writing? The solution that I have for now is def _get_module(): "get the calling module -- should be the config'ed module" target = os.path.splitext(inspect.stack()[2][1])[0] target = __import__(target) return target If there's a better way, I'd love to know about it! Oh, and I'm using 2.5.4, but I suspect kj is using 2.6. ~Ethan~ From solipsis at pitrou.net Wed Nov 11 16:48:36 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 11 Nov 2009 21:48:36 +0000 (UTC) Subject: Threaded import hang in cPickle.dumps References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: Le Tue, 10 Nov 2009 10:50:33 -0800, Zac Burns a ?crit?: > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running cPickle.dumps > in a thread, which leads me to believe that the first restriction here > is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? Please report a bug at http://bugs.python.org Better even if you can provide a small snippet of code which reproduces the problem reliably. Regards Antoine. From no.email at please.post Wed Nov 11 16:55:58 2009 From: no.email at please.post (kj) Date: Wed, 11 Nov 2009 21:55:58 +0000 (UTC) Subject: How can a module know the module that imported it? References: Message-ID: In aahz at pythoncraft.com (Aahz) writes: >In article , kj wrote: >> >>The subject line says it all. >You are probably trying to remove a screw with a hammer Worse: I'm trying to write Perl using Python! >-- why don't you >tell us what you really want to do and we'll come up with a Pythonic >solution? Because the problem that gave rise to this question is insignificant. I would want to know the answer in any case. *Can* it be done in Python at all? OK, if you must know: With Perl one can set a module-global variable before the module is loaded. This provides a very handy backdoor during testing. E.g. # in t/some_test.t script ... BEGIN { $My::Module::TESTING = 1; } use My::Module; ... and in My/Module.pm: package My::Module; our $TESTING ||= 0; # set to 0 unless already initialized to !0 ... if ($TESTING) { # throw testing switches } This does not work in Python, because setting my.module.TESTING variable can happen only after my.module has been imported, but by this point, the module's top-level code has already been executed, so setting my.module.TESTING would have no effect. But one way to get a similar effect would be to have my.module set its TESTING (or whatever) variable equal to the value of this variable in the *importing* module. kynn From lists at cheimes.de Wed Nov 11 17:16:25 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 11 Nov 2009 23:16:25 +0100 Subject: Threaded import hang in cPickle.dumps In-Reply-To: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <4AFB37B9.8020309@cheimes.de> Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running > cPickle.dumps in a thread, which leads me to believe that the first > restriction here is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? You can do two things to stop the import lock from dead locking. * Never ever start a thread as a side effect of an import. This means you must not start a thread in the body of a module. As I explained in numerous other messages a well designed application imports all its modules first. After all modules have been imported the components are initialized and the threads are started. * Import all modules that are referred inside your pickled data before you unpickle. Christian From alain at dpt-info.u-strasbg.fr Wed Nov 11 17:31:35 2009 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 11 Nov 2009 23:31:35 +0100 Subject: python simply not scaleable enough for google? References: Message-ID: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. Have a look at http://code.google.com/p/unladen-swallow/downloads/detail?name=Unladen_Swallow_PyCon.pdf&can=2&q= Slide 6 is impressive. The bottom of slide/page 22 explains why python is so slow: in most cases "the program is less dynamic than the language". -- Alain. From deets at nospam.web.de Wed Nov 11 17:47:31 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 23:47:31 +0100 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: <7m0t83F3e6v3rU1@mid.uni-berlin.de> > Because the problem that gave rise to this question is insignificant. > I would want to know the answer in any case. *Can* it be done in > Python at all? No. > > OK, if you must know: > > With Perl one can set a module-global variable before the module > is loaded. This provides a very handy backdoor during testing. > E.g. > > # in t/some_test.t script > ... > BEGIN { $My::Module::TESTING = 1; } > use My::Module; > ... > > and in My/Module.pm: > > package My::Module; > our $TESTING ||= 0; # set to 0 unless already initialized to !0 > ... > if ($TESTING) { > # throw testing switches > } > > > This does not work in Python, because setting my.module.TESTING > variable can happen only after my.module has been imported, but by > this point, the module's top-level code has already been executed, > so setting my.module.TESTING would have no effect. But one way to > get a similar effect would be to have my.module set its TESTING > (or whatever) variable equal to the value of this variable in the > *importing* module. I don't understand enough (actually nothing) from perl, but I *am* a heavily test-driven developer in Python. And never felt that need. Sure, sometimes one wants to change behavior of a module under test, e.g. replacing something with a stub or some such. But where is the problem doing --- mytest.py --- import moduletobetested as m m.SOME_GLOBAL = "whatever" m.do_something() --- Diez From lists at cheimes.de Wed Nov 11 17:50:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 11 Nov 2009 23:50:20 +0100 Subject: How can a module know the module that imported it? In-Reply-To: References: Message-ID: kj wrote: > Because the problem that gave rise to this question is insignificant. > I would want to know the answer in any case. *Can* it be done in > Python at all? > > OK, if you must know: > > With Perl one can set a module-global variable before the module > is loaded. This provides a very handy backdoor during testing. > E.g. > > # in t/some_test.t script > .... > BEGIN { $My::Module::TESTING = 1; } > use My::Module; > .... > > and in My/Module.pm: > > package My::Module; > our $TESTING ||= 0; # set to 0 unless already initialized to !0 > .... > if ($TESTING) { > # throw testing switches > } > That's terrible style! Code should not react differently if you run it inside an unit test harness. If you need to change the environment for tests because you can test all aspects of your runtime environment, use a mock up system. Please read http://www.voidspace.org.uk/python/articles/mocking.shtml if you don't know the term. Christian From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 18:21:26 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 23:21:26 GMT Subject: How can a module know the module that imported it? References: Message-ID: On Wed, 11 Nov 2009 21:55:58 +0000, kj wrote: > With Perl one can set a module-global variable before the module is > loaded. This provides a very handy backdoor during testing. E.g. Any time somebody justifies a features as "a very handy backdoor", a billion voices cry out and then are suddenly silenced... [...] > This does not work in Python, because setting my.module.TESTING variable > can happen only after my.module has been imported, but by this point, > the module's top-level code has already been executed, so setting > my.module.TESTING would have no effect. (1) Then change your design so you're not relying on changing the behaviour of top-level code. Instead of: chant_incantation(arg) # effect module.magic, somehow... import module do_something_with( module.magic ) (where magic is created by the top-level code) do this instead: import module do_something_with( module.make_magic(arg) ) (2) If you still want a back-door, encapsulate it in another module: # Contents of module.py import _secret_backdoor if _secret_backdoor.manna > 17: magic = 42 else: magic = 23 Then in your calling code: # chant an incantation to change the behaviour of module import _secret_backdoor _secret_backdoor.manna = 1003 import module do_something_with(module.magic) (3) Abuse __builtins__ by polluting it with your own junk: # Contents of module.py try: my_secret_name12761 except NameError: magic = 23 else: magic = 42 Then in your calling code: # chant an incantation to change the behaviour of module import __builtins__ __builtins__.my_secret_name12761 = None import module do_something_with(module.magic) But if you do this one, hundreds of Python developers carrying flaming torches and pitchforks will track you down and do terrible things to your corpse... *wink* -- Steven From rhodri at wildebst.demon.co.uk Wed Nov 11 18:35:08 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 11 Nov 2009 23:35:08 -0000 Subject: Can't Write File In-Reply-To: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: On Wed, 11 Nov 2009 14:00:44 -0000, Victor Subervi wrote: >> 6) you don't indicate which user is executing this script (only root can >> write to it) >> > Help me on this. All scripts are owned by root. Is it not root that is > executing the script? Not unless your server setup is very, very stupid. CGI scripts normally run as a user with *very* limited permissions to limit (amongst other things) the damage ineptly written scripts can do. -- Rhodri James *-* Wildebeest Herder to the Masses From sridhar.ratna at gmail.com Wed Nov 11 18:39:07 2009 From: sridhar.ratna at gmail.com (srid) Date: Wed, 11 Nov 2009 15:39:07 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <7610c270-23a6-46f7-855b-0071ce4147c4@e4g2000prn.googlegroups.com> On Nov 10, 8:25?pm, Phlip wrote: > On Nov 10, 3:11?pm, Wolodja Wentland > wrote: > > > The pip requirement file would contain the following line: > > > -e git+git://example.com/repo.git#egg=rep > > > I hope this answers your questions :-D > > Let me ask it like this. What happens when a user types..? > > ? ?sudo pip install repo Hey Phlip, If you run "pip install repo", it will try to find a package in http://pypi.python.org/ named "repo". Run the following commands: $ pip install pastescript $ paster create myapp $ cd myapp/ $ python setup.py sdist register upload That's all you need to do .. to have your "myapp" project uploaded to PyPI. From now onwards, anyone connected to the internet will be able to run "pip install myapp" to get your package. For more details, may I suggest you to read the official distutils tutorial: http://wiki.python.org/moin/Distutils/Tutorial -srid PS: Another advantage of using distutils (or setuptools/distribute) and uploading your package to PyPI is that you would automatically enable other package managers (such as PyPM - http://pypm.activestate.com/ ) to support your package. From rhodri at wildebst.demon.co.uk Wed Nov 11 18:55:15 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 11 Nov 2009 23:55:15 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: On Wed, 11 Nov 2009 04:51:38 -0000, SD_V897 wrote: > > Rhodri James wrote: >> On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 >> wrote: > >> No, I'm asking you -- or rather your admin user -- to invoke the >> program that is giving you grief from the command line, i.e. "python >> myscript.py", and tell me what happens. "It doesn't work" won't be >> considered at all helpful; without details we might as well just print >> out your script, throw darts at it, and tell you the problem is where >> the darts land. >> The rest of your answer however suggests that I've fundamentally >> misunderstood what you've said. Please tell me *exactly* what happens >> when it doesn't "run fine" for your admin user. >> > > I fixed it for some reason deleting my idlerc folder allows it to work > again.. > > http://bugs.python.org/issue7206 Then I'd hazard a guess that it was a permissions problem. If it recurs, please actually answer questions when we ask them, otherwise we really might as well not bother. -- Rhodri James *-* Wildebeest Herder to the Masses From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:12:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:12:08 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 03:52:45 -0800, Carl Banks wrote: >> This is where a helper function is good. You want a dispatcher: > > No I really don't. I want to be able to see the action performed > adjacent to the test, and not have to scroll up to down ten pages to > find whatever function it dispatched to. Then re-write the dispatcher to return a tuple (match_object, method_to_call) and then call them there at the spot. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:17:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:17:34 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 04:00:09 -0800, Carl Banks wrote: >> as has been posted before and again in a slightly different form in >> Steve's post. > > I'm well aware of it, but I didn't think the proposal deserved to be > called stupid when it was a reasonable solution to a real need, even > though a workable and less intrusive option exists. Fair enough, I was feeling grumpy at the time. Perhaps "stupid" was unfair. Perhaps. -- Steven From peteRE at MpeteOzilla.Vco.ukE Wed Nov 11 19:20:36 2009 From: peteRE at MpeteOzilla.Vco.ukE (Peter Chant) Date: Thu, 12 Nov 2009 00:20:36 +0000 Subject: python simply not scaleable enough for google? References: Message-ID: Terry Reedy wrote: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. In my very limited experience it was very informative programming in C for PIC microcontrollers and inspecting the assembly code produced. If I just threw together loops and complex if statements the assembly produced was very long and impossible to follow whereas if I though carefully about what I was doing, tried to parallel what I would have done in assembly I found the assembly produced looked a lot like I imagined it would if I were programming in assembler directly. Except that the whole process was 10x faster and actually worked. Pete -- http://www.petezilla.co.uk From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 19:22:53 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 00:22:53 GMT Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 08:13:54 -0800, Francis Carr wrote: > Hmmm. I am trying some algorithms, and timeit reports that a > list.extend variant is fastest... WTH?! Really this seems like it must > be a "bug" in implementing the "[None]*x" idiom. > The straightforward "pythonic" solution is better yet: > % python -m timeit -s "N=1000000" \ > "z=[2**32-1]*N" > 100 loops, best of 3: 8.81 msec per loop You're possibly including the time taken to calculate 2**32-1 in each test, which is unnecessary. The peek-hole optimizer *may* be optimizing that away to "z=[4294967295L]*N", or it may not. In any case, why not make the test even simpler and use z=[None]*N? You're testing list methods, not arithmetic and longs. But regardless of what's inside the list, what Python does internally is create an array of some size M, where M is some multiple of two and larger than N, then set the first N elements to the same item, leaving the rest unallocated. (That's what CPython does, other Pythons may behave differently.) Then each time you grow the list, it doubles in size. So over-allocating doesn't necessarily have the cost you think it does. > And the winner for speed is... over-allocate using list.extend, then > delete! > % python -m timeit -s "N=1000000" \ > "z=[2**32-1]" \ > "while len(z) "del z[N:]" > 100 loops, best of 3: 6.93 msec per loop I can't confirm that. I suspect you're running into a hardware specific cache effect or some side-effect of your specific setup. For what it's worth, my timings compared to your timings are: Append one-at-a-time: Me : You 520 : 223 list.extend doubling: 18.5 : 22.2 Multiplication: 9.36 : 8.81 over-allocate then delete 9.42 : 6.93 -- Steven From vmanis at telus.net Wed Nov 11 19:38:50 2009 From: vmanis at telus.net (Vincent Manis) Date: Wed, 11 Nov 2009 16:38:50 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <59997FA1-8E3F-4745-A42C-1B38C69E1047@telus.net> On 2009-11-11, at 14:31, Alain Ketterlin wrote: > Terry Reedy writes: > >> I can imagine a day when code compiled from Python is routinely >> time-competitive with hand-written C. > > Have a look at > http://code.google.com/p/unladen-swallow/downloads/detail?name=Unladen_Swallow_PyCon.pdf&can=2&q= > > Slide 6 is impressive. The bottom of slide/page 22 explains why python > is so slow: in most cases "the program is less dynamic than the > language". I'm having some trouble understanding this thread. My comments aren't directed at Terry's or Alain's comments, but at the thread overall. 1. The statement `Python is slow' doesn't make any sense to me. Python is a programming language; it is implementations that have speed or lack thereof. 2. A skilled programmer could build an implementation that compiled Python code into Common Lisp or Scheme code, and then used a high-performance Common Lisp compiler such as SBCL, or a high-performance Scheme compiler such as Chez Scheme, to produce quite fast code; Python's object model is such that this can be accomplished (and not using CLOS); a Smalltalk-80-style method cache can be used to get good method dispatch. This whole approach would be a bad idea, because the compile times would be dreadful, but I use this example as an existence proof that Python implementations can generate reasonably efficient executable programs. In the Lisp world, optional declarations and flow analysis are used to tell the compiler the types of various variables. Python 3's annotations could be used for this purpose as well. This doesn't impact the learner (or even the casual programmer) for who efficiency is not that important. Unladen Swallow's JIT approach is, IMHO, better than this; my point here is that we don't know what the speed limits of Python implementations might be, and therefore, again, we don't know the limits of performance scalability. 3. It is certainly true that CPython doesn't scale up to environments where there are a significant number of processors with shared memory. It is also true that similar languages for highly parallel architectures have been produced (Connection Machine Lisp comes to mind). Whether the current work being done on the GIL will resolve this I don't know. Still, even if CPython had to be thrown away completely (something I don't believe is necessary), a high-performance multiprocessor/shared memory implementation could be built, if resources were available. 4. As to the programming language Python, I've never seen any evidence one way or the other that Python is more or less scalable to large problems than Java. My former employers build huge programs in C++, and there's lots of evidence (most of which I'm NDA'd from repeating) that it's possible to build huge programs in C++, but that they will be horrible :) -- v From no.email at please.post Wed Nov 11 19:53:22 2009 From: no.email at please.post (kj) Date: Thu, 12 Nov 2009 00:53:22 +0000 (UTC) Subject: Python & Go Message-ID: I'm just learning about Google's latest: the GO (Go?) language. (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). There are some distinctly Pythonoid features to the syntax, such as "import this_or_that", the absence of parentheses at the top of flow control constructs, and quite a few statements without a trailing semicolon. Then again, there's a lot that looks distinctly un-Pythonlike, such as the curly brackets all over the place. And among the un-Pythonlike stuff there's a lot that looks like nothing else that I've ever seen... Just out of curiosity, how much did GvR contribute to this effort? Cheers, G. P.S. Keeping up with Google is becoming a full-time job. It's friggin non-stop. Who can handle it? Truly incredible. From bbxx789_05ss at yahoo.com Wed Nov 11 19:59:51 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 16:59:51 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> Message-ID: <1e499750-0e4f-496c-b7ff-d7bd8014f989@o10g2000yqa.googlegroups.com> On Nov 11, 1:37 pm, Terry Reedy wrote: > 7stud wrote: > > On Nov 11, 7:37 am, "Diez B. Roggisch" wrote: > >> And third, > >> there are limits to what extend one can anticipate the ineptness of > > Calling you inept was unnecessary, but.... > > >> others to read. The page you cite from starts with: > > You wrote > " > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: > > http://codespeak.net/lxml/installation.html > " > > >> For special installation instructions regarding MS Windows and > >> MacOS-X, see below. > > and that page indeed begins with the words above. > > >> And below you find this link: > > >> http://codespeak.net/lxml/build.html#building-lxml-on-macos-x > > >> Which contains the proper command > > >> STATIC_DEPS=true sudo easy_install lxml > > And this is also true. > Is it? First, that in fact was not the proper command. I posted the actual command I had to issue in my previous post: $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/ Versions/ 2.6/bin/easy_install lxml Shall I continue? Here is what the top of the web page that contains the installation instructions looks like (with my comments inserted in the text): ===== For special installation instructions regarding MS Windows and MacOS- X, see below. <<<****Ok, now I'm scrolling down looking for the *installation instructions*.>>> 1 Requirements 2 Installation 3 Installation in ActivePython 4 Building lxml from sources 5 MS Windows 6 MacOS-X Requirements You need Python 2.3 or later. Unless you are using a static binary distribution (e.g. a Windows binary egg from PyPI), you need to install libxml2 and libxslt, in particular: libxml 2.6.21 or later. It can be found here: http://xmlsoft.org/downloads.html If you want to use XPath, do not use libxml2 2.6.27. We recommend libxml2 2.7.2 or later. libxslt 1.1.15 or later. It can be found here: http://xmlsoft.org/XSLT/downloads.html Newer versions generally contain less bugs and are therefore recommended. XML Schema support is also still worked on in libxml2, so newer versions will give you better complience with the W3C spec. <<<***Ok, I better read the requirements. Uhg, those dependencies look ugly. Things are looking doubtful at this point. Back to looking for those special installation instructions for mac os x...>>> Installation Get the easy_install tool and run the following as super-user (or administrator): easy_install lxml On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to easy_install like this: easy_install lxml==2.2.2 On Linux (and most other well-behaved operating systems), easy_install will manage to build the source distribution as long as libxml2 and libxslt are properly installed, including development packages, i.e. header files, etc. Use your package management tool to look for packages like libxml2-dev or libxslt-devel if the build fails, and make sure they are installed. On MacOS-X, use the following to build the source distribution, and make sure you have a working Internet connection, as this will download libxml2 and libxslt in order to build them: STATIC_DEPS=true easy_install lxml <<<***Ah, hah. There are the special installation instructions for mac os x. I'm ready to go. Uh oh, what the heck is the easy_install tool? Oh, that's a link hiding behind the bolded text(hmm...this website has some usability issues). Time goes by, tetonic plates shift...Ok, I've got the easy_install tool installed. Let's install lxml now.>> > > Your characterization of that web page is so fraudulent that I can > > only say one thing in response: You are a damn liar. > > So this makes no sense. > If someone were viewing the web page containing the installation instructions with a screen that was 2 feet high, AND they happened to see the additional section buried at the bottom of the page, AND they chose to skip over instructions in the installation section for some reason, the first part of the section at the bottom of the page reads: === MacOS-X A macport of lxml is available. Try port install py25-lxml. If you want to use a more recent lxml release, you may have to build it yourself. Apple doesn't help here, as the system libraries of libxml2 and libxslt installed under MacOS-X are horribly outdated, and ***updating them is everything but easy***. In any case, you cannot run lxml 2.x with the system provided libraries, so you have to use newer libraries... === ...which would probably make their eyes roll back in their head, or dissuade them from reading any further, and therefore they would return to the relevant installation instructions. I, in fact, was not viewing the web page with a screen that was two feet high, therefore that section wasn't even visible when I was looking at the special installation instructions for mac osx. > If, when you have calmed down a bit, you have > suggestions for improving the installation instructions, that might be > more constructive. The lxml developers have obviously gone to some > effort to give comprehensible instructions. Writing such is not easy. So > if they have failed in your case, feedback might be considered. > That harks back to an earlier point that was made: Benjamin Kaplan wrote: > 1) It's not Python's fault that OS X doesn't add things to the path > when its in a framework (like Python). > 1) Maybe the installation instructions for mac osx should read: ==== Installation Instructions .... .... MAC OS X: We're not sure how mac osx works with easy_install. Apple's system installations of libxml and libxslt are pretty bad--and they are difficult to upgrade. As a result, the following instructions may or may not work for you... ==== 2) Stop proclaiming that lxml is cross platform and/or stop recommending easy_install. 3) Don't split up relevant installation instructions over two web pages and then bury the link connecting the two web pages at the bottom of one of the pages. In any case, thanks for all the help. I'll stick to BeautifulSoup. From aahz at pythoncraft.com Wed Nov 11 20:03:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 11 Nov 2009 17:03:23 -0800 Subject: Aborting a read with pySerial References: <4af50316$0$1610$742ec2ed@news.sonic.net> Message-ID: In article <4af50316$0$1610$742ec2ed at news.sonic.net>, John Nagle wrote: > >I'm using pySerial to read from a serial port. One thread reads from >the port, with no timeout. Another thread handles output and other >tasks. This works fine until I want to shut down the program. I can't >reliably break the program out of the read when it's waiting. On >Windows, closing the serial port will abort the read, but that seems to >have no effect on Linux. > >I know, I could put a timeout on the read and handle all those null >returns. Is there a better way? No -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From bbxx789_05ss at yahoo.com Wed Nov 11 20:16:41 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 17:16:41 -0800 (PST) Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> <7m00grF3fr11qU1@mid.uni-berlin.de> <6fff9a34-b584-4da9-9ac6-db06fd111481@g7g2000vbi.googlegroups.com> <1e499750-0e4f-496c-b7ff-d7bd8014f989@o10g2000yqa.googlegroups.com> Message-ID: On Nov 11, 5:59?pm, 7stud wrote: > > 1) Maybe the installation instructions for mac osx should read: > > ==== > Installation Instructions > .... > .... > MAC OS X: > We're not sure how mac osx works with easy_install. ?Apple's system > installations of libxml and libxslt are pretty bad--and they are > difficult to upgrade. ?As a result, the following instructions may or > may not work for you... > ==== > > 2) Stop proclaiming that lxml is cross platform and/or stop > recommending easy_install. > > 3) Don't split up relevant installation instructions over two web > pages and then bury the link connecting the two web pages at the > bottom of one of the pages. > ...and most importantly: 4) The path to easy_install may not get added to your PATH environment variable, so using the full path to easy_install might be necessary when issuing the easy_install command. If you get an error that says: easy_install: command not found then you will need to use the full path to easy_install. Some installs will put easy_install here: /Library/Frameworks/Python.framework/ Versions/2.6/bin/easy_install Others will put it here: .... If can't locate easy_install in any of those directories, you can locate easy_install using the find command: find / -name easy_install From henryzhang62 at yahoo.com Wed Nov 11 20:24:37 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 11 Nov 2009 17:24:37 -0800 (PST) Subject: python with echo Message-ID: <369236.94583.qm@web57902.mail.re3.yahoo.com> List, I have a question of python using echo. POWER = 14 return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') can assign 14 to tx_power But return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') return_value is 256 not 0. It cannot assign 14 to tx_power. What problem is it? os.system("echo $POWER") returns 0 but os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. Appreciate any help! Thanks. ---henry From jeremiahsavage at gmail.com Wed Nov 11 20:41:07 2009 From: jeremiahsavage at gmail.com (Jeremiah) Date: Wed, 11 Nov 2009 17:41:07 -0800 (PST) Subject: python parser overridden by pymol Message-ID: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Hello, I'm fairly new to python (version 2.5.4), and am writing a program which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from debian. It appears that when I add pymol to $PYTHONPATH, that parser.expr() is no longer available, and so I am unable to use numpy.load(). I have looked for where parser.expr() is defined in the python system so I could place that directory first in $PYTHONPATH, but I have not been able to find the file that defines expr(). My reason for using numpy.load() is that I have a numpy array which takes an hour to generate. Therefore, I'd like to use numpy.save() so I could generate the array one time, and then load it later as needed with numpy.load(). I've successfully tested the use of numpy.save() and numpy.load() with a small example when the pymol path is not defined in $PYTHONPATH : >>> import numpy >>> numpy.save('123',numpy.array([1,2,3])) >>> numpy.load('123.npy') array([1, 2, 3]) However, a problem arises once $PYTHONPATH includes the pymol directory. To use the pymol api, I add the following to ~/.bashrc: PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol export PYMOL_PATH PYTHONPATH=$PYMOL_PATH export PYTHONPATH Once this is done, numpy.load() no longer works correctly, as pymol contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ parser.py ), which apparently prevents python from using its native parser. >>> numpy.load('123.npy') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line 195, in load return format.read_array(fid) File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", line 353, in read_array shape, fortran_order, dtype = read_array_header_1_0(fp) File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", line 250, in read_array_header_1_0 d = safe_eval(header) File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line 840, in safe_eval ast = compiler.parse(source, "eval") File "/usr/lib/python2.5/compiler/transformer.py", line 54, in parse return Transformer().parseexpr(buf) File "/usr/lib/python2.5/compiler/transformer.py", line 133, in parseexpr return self.transform(parser.expr(text)) AttributeError: 'module' object has no attribute 'expr' If I understand the problem correctly, can anyone tell me where python.expr() is defined, or suggest a better method to fix this problem? Thanks, Jeremiah From mensanator at aol.com Wed Nov 11 21:00:07 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 18:00:07 -0800 (PST) Subject: Python & Go References: Message-ID: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> On Nov 11, 6:53?pm, kj wrote: > I'm just learning about Google's latest: the GO (Go?) language. > (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", There's more to Python than import statements. In fact, this Go language is nothing like Python. > the absence of parentheses at the top of > flow control constructs, Huh? > and quite a few statements without a > trailing semicolon. ? Those are exceptions, the rule appears to be "ends with semicolon". In this example, I see semicolons all over the place. 05 package main 07 import ( 08 "./file"; 09 "fmt"; 10 "os"; 11 ) 13 func main() { 14 hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'}; 15 file.Stdout.Write(hello); 16 file, err := file.Open("/does/not/exist", 0, 0); 17 if file == nil { 18 fmt.Printf("can't open file; err=%s\n", err.String()); 19 os.Exit(1); 20 } 21 } > Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. ? Duh. > And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... Go look at a C++ program sometime. > > Just out of curiosity, how much did GvR contribute to this effort? I hope none that he would admit to. > > Cheers, > > G. > > P.S. Keeping up with Google is becoming a full-time job. ?It's > friggin non-stop. ?Who can handle it? ?Truly incredible. From ethan at stoneleaf.us Wed Nov 11 21:15:22 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Nov 2009 18:15:22 -0800 Subject: using inspect Message-ID: <4AFB6FBA.3080908@stoneleaf.us> Greetings! How wise is it to base code on inspect? Specifically on things like live frames on the stack and whatnot. It occurs to me that this is leaning towards implementation details, and away from pure, pristine Python. As an example, I have this routine in a module I'm working on: def _get_module(): "get the calling module -- should be the config'ed module" target = os.path.splitext(inspect.stack()[2][1])[0] target = __import__(target) return target How brittle is this technique? ~Ethan~ From himanshu.garg at gmail.com Wed Nov 11 21:30:57 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 08:00:57 +0530 Subject: python with echo In-Reply-To: <369236.94583.qm@web57902.mail.re3.yahoo.com> References: <369236.94583.qm@web57902.mail.re3.yahoo.com> Message-ID: <6f82a7270911111830y732cfd39i97d1d993c182525@mail.gmail.com> 2009/11/12 hong zhang : > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. > > What problem is it? > > os.system("echo $POWER") returns 0 but > os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. > Sorry cannot try it myself to confirm. Could it be that $POWER is not set. Does it write to a regular file. Thank You, ++imanshu From python at mrabarnett.plus.com Wed Nov 11 21:49:54 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 02:49:54 +0000 Subject: python with echo In-Reply-To: <369236.94583.qm@web57902.mail.re3.yahoo.com> References: <369236.94583.qm@web57902.mail.re3.yahoo.com> Message-ID: <4AFB77D2.1000502@mrabarnett.plus.com> hong zhang wrote: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. > > What problem is it? > > os.system("echo $POWER") returns 0 but > os.system("echo $POWER > /sys/class/net/wlan1/device/tx_power") returns 256. > Did you think that you could say: POWER = 14 return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') in a Python script and that would do the same as: return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') That won't work because 'POWER' exists only in Python and 'echo' is being run in the (Linux?) shell. You could try creating the command-line and then passing it to 'system': return_value = os.system('echo %s > /sys/class/net/wlan1/device/tx_power' % POWER) From pavlovevidence at gmail.com Wed Nov 11 22:04:36 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 19:04:36 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 11, 4:12?pm, Steven D'Aprano wrote: > On Wed, 11 Nov 2009 03:52:45 -0800, Carl Banks wrote: > >> This is where a helper function is good. You want a dispatcher: > > > No I really don't. ?I want to be able to see the action performed > > adjacent to the test, and not have to scroll up to down ten pages to > > find whatever function it dispatched to. > > Then re-write the dispatcher to return a tuple (match_object, > method_to_call) and then call them there at the spot. Well I don't just want to call a method, so I can't take that advice. Some actions will do more than just to call a method. And I don't want to scroll up or down ten screens to see what the actions associated with the regexp are. A dispatcher is out. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 22:07:12 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 03:07:12 GMT Subject: python with echo References: Message-ID: On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > > /sys/class/net/wlan1/device/tx_power') POWER = 14 doesn't create an environment variable visible to echo. It is a Python variable. >>> POWER = 14 >>> import os >>> return_value = os.system('echo $POWER') >>> return_value 0 > return_value is 256 not 0. It cannot assign 14 to tx_power. I don't understand that. Exit status codes on all systems I'm familiar with are limited to 0 through 255. What operating system are you using? Assuming your system allows two-byte exit statuses, you should check the documentation for echo and the shell to see why it is returning 256. Have you tried this in the shell, without involving Python? I will almost guarantee that Python is irrelevant to the problem. -- Steven From robert.kern at gmail.com Wed Nov 11 22:12:42 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Nov 2009 21:12:42 -0600 Subject: python parser overridden by pymol In-Reply-To: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: Jeremiah wrote: > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH Don't change your PYTHONPATH like that. You want to put /usr/lib/pymodules/python2.5 onto your PYTHONPATH and import PyMOL's stuff from the pymol package. I.e., instead of import api Do from pymol import api pymol is a package for precisely this reason. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 22:16:32 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 03:16:32 GMT Subject: python parser overridden by pymol References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 17:41:07 -0800, Jeremiah wrote: > Hello, > > I'm fairly new to python (version 2.5.4), and am writing a program which > uses both pymol (version 1.2r1) and numpy (version 1.3.0) from debian. > > It appears that when I add pymol to $PYTHONPATH, that parser.expr() is > no longer available, and so I am unable to use numpy.load(). I have > looked for where parser.expr() is defined in the python system so I > could place that directory first in $PYTHONPATH, but I have not been > able to find the file that defines expr(). >>> import parser >>> parser.__file__ '/usr/lib/python2.5/lib-dynload/parsermodule.so' >>> parser.expr [...] > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH Change that to PYMOL_PATH=/usr/lib/pymodules/python2.5 and it should work, assuming pymol uses a package, as it should. If it doesn't, if it's just a hodge-podge of loose modules in a directory, then they should be slapped with a wet fish for shadowing a standard library module. -- Steven From davea at ieee.org Wed Nov 11 22:48:34 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 11 Nov 2009 22:48:34 -0500 Subject: python parser overridden by pymol In-Reply-To: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> Message-ID: <4AFB8592.7040300@ieee.org> Jeremiah wrote: > Hello, > > I'm fairly new to python (version 2.5.4), and am writing a program > which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from > debian. > > It appears that when I add pymol to $PYTHONPATH, that parser.expr() is > no longer available, and so I am unable to use numpy.load(). I have > looked for where parser.expr() is defined in the python system so I > could place that directory first in $PYTHONPATH, but I have not been > able to find the file that defines expr(). > > My reason for using numpy.load() is that I have a numpy array which > takes an hour to generate. Therefore, I'd like to use numpy.save() so > I could generate the array one time, and then load it later as needed > with numpy.load(). > > I've successfully tested the use of numpy.save() and numpy.load() with > a small example when the pymol path is not defined in $PYTHONPATH : > > >>> import numpy > >>> numpy.save('123',numpy.array([1,2,3])) > >>> numpy.load('123.npy') > array([1, 2, 3]) > > > However, a problem arises once $PYTHONPATH includes the pymol > directory. To use the pymol api, I add the following to ~/.bashrc: > > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > PYTHONPATH=$PYMOL_PATH > export PYTHONPATH > > Once this is done, numpy.load() no longer works correctly, as pymol > contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ > parser.py ), which apparently prevents python from using its native > parser. > > >>> numpy.load('123.npy') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line > 195, in load > return format.read_array(fid) > File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", > line 353, in read_array > shape, fortran_order, dtype = read_array_header_1_0(fp) > File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", > line 250, in read_array_header_1_0 > d = safe_eval(header) > File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line > 840, in safe_eval > ast = compiler.parse(source, "eval") > File "/usr/lib/python2.5/compiler/transformer.py", line 54, in > parse > return Transformer().parseexpr(buf) > File "/usr/lib/python2.5/compiler/transformer.py", line 133, in > parseexpr > return self.transform(parser.expr(text)) > AttributeError: 'module' object has no attribute 'expr' > > If I understand the problem correctly, can anyone tell me where > python.expr() is defined, or suggest a better method to fix this > problem? > > Thanks, > Jeremiah > > Generic answers, I have no experience with pymol If pymol really needs that parser.py, you have a problem, as there can only be one module by that name in the application. But assuming it's needed for some obscure feature that you don't need, you could try the following sequence. 1) temporarily rename the pymol's parser.py file to something else, like pymolparser.py, and see what runs. 2) rather than changing the PYTHONPATH, fix up sys.path during your script initialization. In particular, do an import parser near the beginning of the script. This gets it loaded, even though you might not need to use it from this module. After that import, then add the following line (which could be generalized later) sys.path.append( "/usr/lib/pymodules/python2.5/pymol") If this works, then you can experiment a bit more, perhaps you don't need the extra import parser, just putting the pymol directory at the end of the sys.path rather than the beginning may be good enough. If the parser.py in the pymol is actually needed, you might need to rename its internal references to some other name, like pymolparser. HTH, DaveA From debatem1 at gmail.com Wed Nov 11 22:56:26 2009 From: debatem1 at gmail.com (geremy condra) Date: Wed, 11 Nov 2009 22:56:26 -0500 Subject: Python & Go In-Reply-To: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > On Nov 11, 6:53?pm, kj wrote: >> I'm just learning about Google's latest: the GO (Go?) language. >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). >> There are some distinctly Pythonoid features to the syntax, such >> as "import this_or_that", > > There's more to Python than import statements. > In fact, this Go language is nothing like Python. Actually, numerous analogies have been drawn between the two both by whoever wrote the docs and the tech media, including slashdot and techcrunch. >> the absence of parentheses at the top of >> flow control constructs, > > Huh? The OP is referring to the fact that for and if do not have mandatory parenthesis. >> and quite a few statements without a >> trailing semicolon. > > Those are exceptions, the rule appears to be "ends with semicolon". > In this example, I see semicolons all over the place. The rule is that if its between parens, it needs semicolons. >> Then again, there's a lot that looks distinctly >> un-Pythonlike, such as the curly brackets all over the place. > > Duh. > >> And >> among the un-Pythonlike stuff there's a lot that looks like nothing >> else that I've ever seen... > > Go look at a C++ program sometime. Go doesn't support inheritance, so C++ is pretty much out. C is a lot closer, but still not all that close. Geremy Condra From timr at probo.com Wed Nov 11 23:35:36 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Nov 2009 20:35:36 -0800 Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: Ognjen Bezanov wrote: > >I'm trying to see if there is any way I can make Python share data >between two hosts using DMA transfers over a firewire connection, so >avoiding the need for another layer on top such as IPv4 + Python sockets. > >Thanks to some old python bindings which I updated to python 2.6, I can >read any write to the RAM of any firewire connected host within python. >Because it uses DMA (the cpu is not involved in this at all), I can only >specify a physical address within the 4GB ram limit to read from and >write to. >... > From what I've been told so far, it's not possible to do this without >some OS-specific (Linux in this case) syscall. Is this correct? Correct. User-mode programs cannot find physical addresess, and they cannot lock pages into memory (which is required for DMA). You need the assistance of a driver for this. The driver will find the physical addresses. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pavlovevidence at gmail.com Wed Nov 11 23:42:53 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 20:42:53 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> On Nov 11, 7:56?pm, geremy condra wrote: > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > On Nov 11, 6:53?pm, kj wrote: > >> I'm just learning about Google's latest: the GO (Go?) language. > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> There are some distinctly Pythonoid features to the syntax, such > >> as "import this_or_that", > > > There's more to Python than import statements. > > In fact, this Go language is nothing like Python. > > Actually, numerous analogies have been drawn between the two > both by whoever wrote the docs and the tech media, including > slashdot and techcrunch. Superficially it looks quite hideous, at least this sample does, but underneath the covers might be another question. Javascript looks like Java but behaves more like Python. Such might also be the case for Go. I'll reserve judgment till I've looked at it, but it's advertised as natively supporting something I've always wanted in a static language: signatures (and, presumably, a culture to support them). [snip] > > Go look at a C++ program sometime. > > Go doesn't support inheritance, so C++ is pretty much out. C > is a lot closer, but still not all that close. Well, it's hard to argue with not being like C++, but the lack of inheritance is a doozie. Carl Banks From pengyu.ut at gmail.com Wed Nov 11 23:46:34 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 11 Nov 2009 22:46:34 -0600 Subject: Why Error is derived from EnvironmentError in shutil.py? Message-ID: <366c6f340911112046q2e9737d7tec36cfff42e79e5a@mail.gmail.com> I see Error is derived from EnvironmentError in shutil.py. class Error(EnvironmentError): pass I'm wondering why EnvironmentError can not be raised directly. Why Error is raised instead? From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 23:51:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 04:51:17 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Wed, 11 Nov 2009 16:38:50 -0800, Vincent Manis wrote: > I'm having some trouble understanding this thread. My comments aren't > directed at Terry's or Alain's comments, but at the thread overall. > > 1. The statement `Python is slow' doesn't make any sense to me. Python > is a programming language; it is implementations that have speed or lack > thereof. Of course you are right, but in common usage, "Python" refers to CPython, and in fact since all the common (and possibly uncommon) implementations of Python are as slow or slower than CPython, it's not an unreasonable short-hand. But of course "slow" is relative. And many applications are bound by I/O time, not CPU time. > 2. A skilled programmer could build an implementation that compiled > Python code into Common Lisp or Scheme code, and then used a > high-performance Common Lisp compiler such as SBCL, or a > high-performance Scheme compiler such as Chez Scheme, to produce quite > fast code; Unless you can demonstrate this, it's all theoretical. And probably not as straight-forward as you think: http://codespeak.net/pypy/dist/pypy/doc/faq.html#id29 > Python's object model is such that this can be accomplished > (and not using CLOS); a Smalltalk-80-style method cache can be used to > get good method dispatch. This whole approach would be a bad idea, > because the compile times would be dreadful, but I use this example as > an existence proof that Python implementations can generate reasonably > efficient executable programs. I think a better existence proof is implementations that *actually* exist, not theoretical ones. There's good work happening with Psycho and PyPy, and you can write C extensions using almost-Python code with Cython and Pyrex. There's very little reason why Python *applications* have to be slow, unless the application itself is inherently slow. > In the Lisp world, optional declarations and flow analysis are used to > tell the compiler the types of various variables. Python 3's annotations > could be used for this purpose as well. This doesn't impact the learner > (or even the casual programmer) for who efficiency is not that > important. > > Unladen Swallow's JIT approach is, IMHO, better than this; my point here > is that we don't know what the speed limits of Python implementations > might be, and therefore, again, we don't know the limits of performance > scalability. Absolutely. It's early days for Python. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 23:55:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 04:55:50 GMT Subject: Why Error is derived from EnvironmentError in shutil.py? References: Message-ID: On Wed, 11 Nov 2009 22:46:34 -0600, Peng Yu wrote: > I see Error is derived from EnvironmentError in shutil.py. > > class Error(EnvironmentError): > pass > > I'm wondering why EnvironmentError can not be raised directly. Why Error > is raised instead? Probably to do with the personal taste of the author. http://docs.python.org/library/shutil.html#shutil.Error -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Nov 12 00:05:57 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 05:05:57 GMT Subject: using inspect References: Message-ID: On Wed, 11 Nov 2009 18:15:22 -0800, Ethan Furman wrote: > Greetings! > > How wise is it to base code on inspect? Specifically on things like > live frames on the stack and whatnot. It occurs to me that this is > leaning towards implementation details, and away from pure, pristine > Python. > > As an example, I have this routine in a module I'm working on: > > def _get_module(): > "get the calling module -- should be the config'ed module" target = > os.path.splitext(inspect.stack()[2][1])[0] > target = __import__(target) > return target > > How brittle is this technique? Download and install PyPy, CLPython, IronPython and Jython and see how many it breaks on :) I think it's a brittle technique because it is creating a dependency where there shouldn't be one. What happens if somebody runs your module directly? It might not need to do anything sensible, but it shouldn't fail merely because there's no calling module. But I don't think it's inherently dangerous. It's a bit hacky, well, probably a lot hacky, but it doesn't seem to use anything specifically documented as implementation specific: http://docs.python.org/library/inspect.html#inspect.stack -- Steven From rt8396 at gmail.com Thu Nov 12 00:07:12 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 21:07:12 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: <31772cad-c255-4c2e-88af-f5cfc59c0386@g31g2000vbr.googlegroups.com> On Nov 11, 9:04 pm, Carl Banks wrote: (Carl's reply to Steven's comments...) > Well I don't just want to call a method, so I can't take that advice. > Some actions will do more than just to call a method. And I don't > want to scroll up or down ten screens to see what the actions > associated with the regexp are. A dispatcher is out. +1 The if... elif... construct that Carl provided coupled with the proposed new syntax is much cleaner. And i'm not just saying that because Steven called my idea stupid, well, *maybe* not? ;-) PS: Does anyone know the textual smiley for apathy? From mensanator at aol.com Thu Nov 12 00:27:31 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 21:27:31 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> Message-ID: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> On Nov 11, 9:56?pm, geremy condra wrote: > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > On Nov 11, 6:53?pm, kj wrote: > >> I'm just learning about Google's latest: the GO (Go?) language. > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> There are some distinctly Pythonoid features to the syntax, such > >> as "import this_or_that", > > > There's more to Python than import statements. > > In fact, this Go language is nothing like Python. > > Actually, numerous analogies have been drawn between the two > both by whoever wrote the docs and the tech media, including > slashdot and techcrunch. > > >> the absence of parentheses at the top of > >> flow control constructs, > > > Huh? > > The OP is referring to the fact that for and if do not have > mandatory parenthesis. > > >> and quite a few statements without a > >> trailing semicolon. > > > Those are exceptions, the rule appears to be "ends with semicolon". > > In this example, I see semicolons all over the place. > > The rule is that if its between parens, it needs semicolons. > > Why did you snip the example that proves you're wrong? > > >> Then again, there's a lot that looks distinctly > >> un-Pythonlike, such as the curly brackets all over the place. > > > Duh. > > >> And > >> among the un-Pythonlike stuff there's a lot that looks like nothing > >> else that I've ever seen... > > > Go look at a C++ program sometime. > > Go doesn't support inheritance, so C++ is pretty much out. C > is a lot closer, but still not all that close. > > Geremy Condra From wuwei23 at gmail.com Thu Nov 12 01:00:48 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 Nov 2009 22:00:48 -0800 (PST) Subject: Why Error is derived from EnvironmentError in shutil.py? References: Message-ID: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> On Nov 12, 2:46?pm, Peng Yu wrote: > I see Error is derived from EnvironmentError in shutil.py. > > class Error(EnvironmentError): > ? ? pass > > I'm wondering why EnvironmentError can not be raised directly. Why > Error is raised instead? This way you can explicitly trap on shutil.Error and not intercept any other EnvironmentError that might be raised. And as it's a descendent of EnvironmentError, it can still be caught by any handlers looking for such exceptions. From alfps at start.no Thu Nov 12 01:21:01 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 07:21:01 +0100 Subject: Does turtle graphics have the wrong associations? Message-ID: One reaction to has been that turtle graphics may be off-putting to some readers because it is associated with children's learning. What do you think? Cheers, - Alf From debatem1 at gmail.com Thu Nov 12 01:44:23 2009 From: debatem1 at gmail.com (geremy condra) Date: Thu, 12 Nov 2009 01:44:23 -0500 Subject: Python & Go In-Reply-To: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 12:27 AM, Mensanator wrote: > On Nov 11, 9:56?pm, geremy condra wrote: >> On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: >> > On Nov 11, 6:53?pm, kj wrote: >> >> I'm just learning about Google's latest: the GO (Go?) language. >> >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). >> >> There are some distinctly Pythonoid features to the syntax, such >> >> as "import this_or_that", >> >> > There's more to Python than import statements. >> > In fact, this Go language is nothing like Python. >> >> Actually, numerous analogies have been drawn between the two >> both by whoever wrote the docs and the tech media, including >> slashdot and techcrunch. >> >> >> the absence of parentheses at the top of >> >> flow control constructs, >> >> > Huh? >> >> The OP is referring to the fact that for and if do not have >> mandatory parenthesis. >> >> >> and quite a few statements without a >> >> trailing semicolon. >> >> > Those are exceptions, the rule appears to be "ends with semicolon". >> > In this example, I see semicolons all over the place. >> >> The rule is that if its between parens, it needs semicolons. >> >> > > Why did you snip the example that proves you're wrong? For the very simple reason that I'm not. From the roughly 20 minute tutorial: "Semicolons aren't needed here; in fact, semicolons are unnecessary after any top-level declaration, although they are needed as separators within a parenthesized list of declarations." In fact, you can clearly see this in action even in the example you posted- there is no semicolon after the import, nor is one required after any initialization or where line endings are unambiguous, such as immediately preceding the end of a block. Geremy Condra From vmanis at telus.net Thu Nov 12 01:53:37 2009 From: vmanis at telus.net (Vincent Manis) Date: Wed, 11 Nov 2009 22:53:37 -0800 Subject: Python & Go In-Reply-To: <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: <5E7279DF-62BC-4DF3-A277-0FE330D16A73@telus.net> On 2009-11-11, at 21:27, Mensanator wrote: >> Go doesn't support inheritance, so C++ is pretty much out. C >> is a lot closer, but still not all that close. OK, if that's the case (I haven't read the Go documents), then Go is nothing like Python, no matter how many or few semicolons there are in Go programs, or whether one imports external code modules with `import', `require', or `iwant'. Programming languages are similar if their *semantics* are similar, not if their *syntaxes* are similar. A device that apparently has brake and accelerator pedals is similar to a car if the functions of these two pedals match those of a car, and is different from a car if the `brake' causes bread to be inserted into a toaster and the `accelerator' drops a 16ton weight on the driver. -- v From mensanator at aol.com Thu Nov 12 02:01:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 11 Nov 2009 23:01:59 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2dd9b2-9c5b-4fae-bbb0-3f85ca813e71@d5g2000yqm.googlegroups.com> Message-ID: <1c248687-ec58-41db-ad4f-c2028ed428c3@c3g2000yqd.googlegroups.com> On Nov 12, 12:44?am, geremy condra wrote: > On Thu, Nov 12, 2009 at 12:27 AM, Mensanator wrote: > > On Nov 11, 9:56?pm, geremy condra wrote: > >> On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > >> > On Nov 11, 6:53?pm, kj wrote: > >> >> I'm just learning about Google's latest: the GO (Go?) language. > >> >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > >> >> There are some distinctly Pythonoid features to the syntax, such > >> >> as "import this_or_that", > > >> > There's more to Python than import statements. > >> > In fact, this Go language is nothing like Python. > > >> Actually, numerous analogies have been drawn between the two > >> both by whoever wrote the docs and the tech media, including > >> slashdot and techcrunch. > > >> >> the absence of parentheses at the top of > >> >> flow control constructs, > > >> > Huh? > > >> The OP is referring to the fact that for and if do not have > >> mandatory parenthesis. > > >> >> and quite a few statements without a > >> >> trailing semicolon. > > >> > Those are exceptions, the rule appears to be "ends with semicolon". > >> > In this example, I see semicolons all over the place. > > >> The rule is that if its between parens, it needs semicolons. > > >> > > > Why did you snip the example that proves you're wrong? > > For the very simple reason that I'm not. From the roughly > 20 minute tutorial: > > "Semicolons aren't needed here; in fact, semicolons are unnecessary > after any top-level declaration, although they are needed as > separators within a parenthesized list of declarations." > > In fact, you can clearly see this in action even in the example > you posted- there is no semicolon after the import, nor is one > required after any initialization or where line endings are > unambiguous, So, where line endings ARE ambiguous requires semicolons. The above statement may be true for top-level statements, but not within blocks, as the example clearly shows. The lines were NOT within parens, yet had trailing semicolons. You're still wrong. > such as immediately preceding the end of a > block. > > Geremy Condra From ak at nothere.com Thu Nov 12 02:24:23 2009 From: ak at nothere.com (AK) Date: Thu, 12 Nov 2009 02:24:23 -0500 Subject: Create video with text? Message-ID: <4afbb851$0$22531$607ed4bc@cv.net> Hi, what would be the best python package (or a framework that can be scripted in python) that can make a video with text moving around, jumping, zooming in/out and various other text effects? See the following link for an example: From anacrolix at gmail.com Thu Nov 12 02:51:54 2009 From: anacrolix at gmail.com (Matthew Joiner) Date: Wed, 11 Nov 2009 23:51:54 -0800 (PST) Subject: Matthew Joiner wants to stay in touch on LinkedIn Message-ID: <284081918.7836296.1258012314856.JavaMail.app@ech3-cdn13.prod> LinkedIn ------------ Matthew Joiner requested to add you as a connection on LinkedIn: ------------------------------------------ Jaime, I'd like to add you to my professional network on LinkedIn. - Matthew Joiner Accept invitation from Matthew Joiner http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I420651809_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvej0UcjkSc38QiiZ9jj19qBdVkOYVdPgUd3wSdjwLrCBxbOYWrSlI/EML_comm_afe/ View invitation from Matthew Joiner http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I420651809_3/0PnPAMe34Rdz0Od4ALqnpPbOYWrSlI/svi/ ------------------------------------------ Why might connecting with Matthew Joiner be a good idea? Matthew Joiner's connections could be useful to you: After accepting Matthew Joiner's invitation, check Matthew Joiner's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. ------ (c) 2009, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Thu Nov 12 02:53:57 2009 From: dieter at handshake.de (Dieter Maurer) Date: 12 Nov 2009 08:53:57 +0100 Subject: advice needed for lazy evaluation mechanism In-Reply-To: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> References: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes on 10 Nov 2009 19:11:07 GMT: > ... > > So I am trying to restructure it using lazy evaluation. > > Oh great, avoiding confusion with something even more confusing. Lazy evaluation may be confusing if it is misused. But, it may be very clear and powerful if used appropriately. Lazy evaluation essentially means: you describe beforehand how a computation should be performed but do this computation only when its result is immediately required. Of course, this makes it more difficult to predict when the computation actually happens -- something potentially very confusing when the computation has side effects. If the computation is side effect free, potentially great gains can be achieved without loss of clarity. Python supports lazy evaluation e.g. by its genenerators (and generator expressions). Its "itertools" module provides examples to efficiently use iterators (and by inclusion generators) without sacrificing clarity. -- Dieter From michele.simionato at gmail.com Thu Nov 12 03:07:36 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 00:07:36 -0800 (PST) Subject: Python & Go References: Message-ID: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> Well, Go looks like Python in the philosophy (it is a minimalist, keep it simple language) more than in the syntax. The one thing that I really like is the absence of classes and the presence of interfaces (I have been advocating something like that for years). I am dubious about the absence of exceptions, though. If I can attempt a prediction, I would say that if the language will be adopted internally in Google it will make a difference; otherwise, it will be rapidly forgotten. From yinon.me at gmail.com Thu Nov 12 03:13:52 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Thu, 12 Nov 2009 00:13:52 -0800 (PST) Subject: How to specify Python version in script? References: Message-ID: <77b812a9-d82c-4aaa-8037-ec30366fc14f@h34g2000yqm.googlegroups.com> > Is there some way to specify at the very beginning of the script > the acceptable range of Python versions? sys.hexversion, see http://mail.python.org/pipermail/python-list/2009-June/185939.html -- Yinon From michele.simionato at gmail.com Thu Nov 12 03:18:55 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 00:18:55 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> Message-ID: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> I forgot to post a link to a nice analysis of Go: http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php From steven at REMOVE.THIS.cybersource.com.au Thu Nov 12 03:27:08 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 08:27:08 GMT Subject: advice needed for lazy evaluation mechanism References: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 08:53:57 +0100, Dieter Maurer wrote: > Steven D'Aprano writes on 10 Nov > 2009 19:11:07 GMT: >> ... >> > So I am trying to restructure it using lazy evaluation. >> >> Oh great, avoiding confusion with something even more confusing. > > Lazy evaluation may be confusing if it is misused. But, it may be very > clear and powerful if used appropriately. I was referring to the specific example given, not the general concept of lazy evaluation. I went on to give another example of simple, straightforward lazy evaluation: using properties for computed attributes. -- Steven From naughtysriram at gmail.com Thu Nov 12 03:31:57 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 00:31:57 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' Message-ID: I guess why every programming language has some kind of a 'standard library' built in within it. In my view it must not be called as a 'library' at all. what it does is like a 'bunch of built-in programs ready-made to do stuff'. Lets see what a 'library' does: 1. offers books for customers 1.1 lets user select a book by genre, etc 1.2 lets user to use different books of same genre, etc 1.3 lets user to use books by same author, etc for different genre 2. keeps track of all the books + their genre 2.1 first knows what all books it has at present 2.2 when new book comes it is added to the particular shelf sorted by genre,author,edition, etc. 2.3 when books become old they are kept separately for future reference 2.4 very old books can be sent to a museum/discarded I guess no standard library does the minimum of this but wants to be called a library. As a python user I always wanted the standard library to have such features so the user/developer decides to use what set of libraries he want. consider the libraries for 2.5 ,2.6, 3K are all available to the user, the user selects what he wants with something like. use library 2.5 or use library 2.6 etc. The 2 main things that the library management interface has to do is intra library management and inter library management. intra library mgmt- consider books to be different libraries (standard, commercial, private, hobby, etc) inter library mgmt- consider books to be modules inside a library ( standard, commercial, private, hobby, etc) if somehow we could accomplish this kind of mother of a all plugin/ad- hoc system that is a real breakthrough. Advantages: 1. new modules can be added to the stream quickly 2. let the user select what he want to do 3. modules (that interdepend on each other) can be packed into small distribution and added to the stream quickly without waiting for new releases 4. solution to problems like py 2.x and 3.x 5. users can be up to date 6. documentation becomes easy + elaborate to users 7. bug managing is easy too 8. more feed back 9. testing also becomes easy 10. many more , i don't know.. you have to find. Python already has some thing like that __future__ stuff. but my question is how many people know that? and how many use that? most of them wait until old crust gets totally removed. that is bad for user and python. that is why problems like py2.x py3.x originate. If there is a newer book collection it must always be available at the library. i must not go to another library to get that book. These are just my views on the state of the standard libraries and to make them state-of-the-art..! ;) From pavlovevidence at gmail.com Thu Nov 12 03:54:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 00:54:55 -0800 (PST) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: <569e15fe-6791-4f9e-9757-0e232a57e698@o9g2000prg.googlegroups.com> On Nov 11, 8:42?pm, Carl Banks wrote: > On Nov 11, 7:56?pm, geremy condra wrote: > > > On Wed, Nov 11, 2009 at 9:00 PM, Mensanator wrote: > > > On Nov 11, 6:53?pm, kj wrote: > > >> I'm just learning about Google's latest: the GO (Go?) language. > > >> (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > > >> There are some distinctly Pythonoid features to the syntax, such > > >> as "import this_or_that", > > > > There's more to Python than import statements. > > > In fact, this Go language is nothing like Python. > > > Actually, numerous analogies have been drawn between the two > > both by whoever wrote the docs and the tech media, including > > slashdot and techcrunch. > > Superficially it looks quite hideous, at least this sample does, but > underneath the covers might be another question. ?Javascript looks > like Java but behaves more like Python. ?Such might also be the case > for Go. ?I'll reserve judgment till I've looked at it, but it's > advertised as natively supporting something I've always wanted in a > static language: signatures (and, presumably, a culture to support > them). Ok, I've read up on the language and I've seen enough. I, for one, won't be using it. I don't think it has any possibility of gaining traction without serious changes. If Google decides to throw money at it and/or push it internally (and I am skeptical Google's software engineers would let themselved be browbeaten into using it) it'll be Lisp 2: Electric Boogaloo. Carl Banks From sraji.me at gmail.com Thu Nov 12 04:07:22 2009 From: sraji.me at gmail.com (Raji Seetharaman) Date: Thu, 12 Nov 2009 14:37:22 +0530 Subject: Error in Windmill Message-ID: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> Hi Im learning Web scraping with Python from here http://www.packtpub.com/article/web-scraping-with-python-part-2 >From the above link, the complete code is here http://pastebin.com/m10046dc6 When i run the program in the terminal i receive following errors File "nasa.py", line 41, in test_scrape_iotd_gallery() File "nasa.py", line 24, in test_scrape_iotd_gallery client = WindmillTestClient(__name__) File "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", line 142, in __init__ method_proxy = windmill.tools.make_jsonrpc_client() File "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", line 35, in make_jsonrpc_client url = urlparse(windmill.settings['TEST_URL']) AttributeError: 'module' object has no attribute 'settings' Suggest me Thanks Raji. S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Nov 12 04:23:54 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 10:23:54 +0100 Subject: Python C API and references Message-ID: Hello, Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't need the reference to py_val I should decrement the reference after this call? So for example: PyObject *py_val = PyInt_FromLong(5) PyObject_SetAttrString(py_obj, "val", py_val); Py_DECREF(py_val) Right? If so, take sysmodule.c: if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) return NULL; Shouldn't they also call Py_DECREF(Py_None) ? Same logic applies to PyDict_SetItemString() and the reference should be decrement after setting the item (ofcourse if the value is not needed). -- Elias From lallous at lgwm.org Thu Nov 12 04:28:32 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 10:28:32 +0100 Subject: C api and checking for integers Message-ID: Hello, I am a little confused on how to check if a python variable is an integer or not. Sometimes PyInt_Check() fails and PyLong_Check() succeeds. How to properly check for integer values? OTOH, I tried PyNumber_Check() and: (1) The doc says: Returns 1 if the object o provides numeric protocols, and false otherwise. This function always succeeds. What do they mean: "always succeeds" ? (2) It seems PyNumber_check(py_val) returns true when passed an instance! Please advise. -- Elias From duncan.booth at invalid.invalid Thu Nov 12 04:55:52 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Nov 2009 09:55:52 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> Message-ID: Michele Simionato wrote: > I forgot to post a link to a nice analysis of Go: > http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php > Thanks for that link. I think it pretty well agrees with my first impressions of Go: there are some nice bits but there are also some bits they really should be so embarassed that they even considered. The lack of any kind of error handling, whether exceptions or anything else is, I think, a killer. When you access a value out of a map you have a choice of syntax: one way gives you a boolean flag you can test to see whether or not the item was in the map, the other either gives you the value or crashes the program (yes, the documentation actually says 'crash'). Both of these are wrong: the flag is wrong because it forces you to handle every lookup error immediately and at the same place in the code; the crash is wrong for obvious reasons. The lack of inheritance is a bit weird, so far as I can tell you can have what is effectively a base class providing some concrete implementation but there are no virtual methods so no way to override anything. What that article didn't mention, and what is possibly Go's real strong point is that it has built-in support for parallel processing. Again though the implementation looks weak: any attempt to read from a channel is either non-blocking or blocks forever. I guess you can probably implement timeouts by using a select to read from multiple channels, but as with accessing values from a map it doesn't sound like it will scale well to producing robust applications. It has too many special cases: a lot of the builtin types can exist only as builtin types: if they weren't part of the language you couldn't implement an equivalent. e.g. A map has a key and value. The key can be any type which implements equality, but you can't implement equality tests for your own types so you cannot define additional key types. -- Duncan Booth http://kupuguy.blogspot.com From ankita.dutta09 at gmail.com Thu Nov 12 04:59:40 2009 From: ankita.dutta09 at gmail.com (ankita dutta) Date: Thu, 12 Nov 2009 15:29:40 +0530 Subject: query regarding file handling. Message-ID: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> hi all, i have a file of 3x3 matrix of decimal numbers(tab separated). like this : 0.02 0.38 0.01 0.04 0.32 0.00 0.03 0.40 0.02 now i want to read 1 row and get the sum of a particular row. but when i am trying with the following code, i am getting errors : *code*: " ln1=open("A.txt","r+") # file "A.txt" contains my matrix lines1=ln1.readlines() n_1=[ ] for p1 in range (0,len(lines1)): f1=lines1[p1] n_1.append((f1) ) print n_1 print sum(n_1[0]) " *output*: ['0.0200\t0.3877\t0.0011\n', '0.0040\t0.3292\t0.0001\n', '0.0355\t0.4098\t0.0028\n', '0.0035\t0.3063\t0.0001\n', '0.0080\t0.3397\t0.0002\n'] Traceback (most recent call last): File "A_1.py", line 20, in print sum(nodes_1[0]) File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 993, in sum return _wrapit(a, 'sum', axis, dtype, out) File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 37, in _wrapit result = getattr(asarray(obj),method)(*args, **kwds) TypeError: cannot perform reduce with flexible type * what I think:* as the list is in form of '0.0200\t0.3877\t0.0011\n' , n_1[0] takes it as a whole string which includes "\t" , i think thats why they are giving error. now how can i read only required numbers from this line '0.0200\t0.3877\t0.0011\n' and find their sum ? can you kindly help me out how to properly code thing . thank you, regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Nov 12 05:15:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Nov 2009 02:15:24 -0800 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: <50697b2c0911120215t79472c7bkc37e8fb9c69b5977@mail.gmail.com> On Thu, Nov 12, 2009 at 1:59 AM, ankita dutta wrote: > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this : > > 0.02??? 0.38??? 0.01 > 0.04??? 0.32??? 0.00 > 0.03??? 0.40??? 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i am > trying with the following code, i am getting errors : Try using the `csv` module, which despite its name, works on the tab-delimited variant of the format as well: http://docs.python.org/library/csv.html Cheers, Chris -- http://blog.rebertia.com From gatti at dsdata.it Thu Nov 12 05:34:04 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Thu, 12 Nov 2009 02:34:04 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: <83d76e51-7844-47f0-912f-0bc764f91360@s31g2000yqs.googlegroups.com> On Nov 11, 9:48?am, Lorenzo Gatti wrote: > On a more constructive note, I started to follow the instructions athttp://www.pyside.org/docs/pyside/howto-build/index.html(which are > vague and terse enough to be cross-platform) with Microsoft VC9 > Express. > Hurdle 0: recompile Qt because the provided DLLs have hardcoded wrong > paths that confuse CMake. > How should Qt be configured? My first compilation attempt had to be > aborted (and couldn't be resumed) after about 2 hours: trial and error > at 1-2 builds per day could take weeks. Update: I successfully compiled Qt (with WebKit disabled since it gives link errors), as far as I can tell, and I'm now facing apiextractor. Hurdle 1a: convince CMake that I actually have Boost headers and compiled libraries. The Boost directory structure is confusing (compiled libraries in two places), and CMake's script (FindBoost.cmake) is inconsistent (should I set BOOST_INCLUDEDIR or BOOST_INCLUDE_DIR?), obsolete (last known version is 1.38 rather than the requisite 1.40) and rather fishy (e.g. hardcoded "c:\boost" paths). Would the Cmake-based branch of Boost work better? Any trick or recipe to try? Hurdle 1b: the instructions don't mention a dependency from libxml2. Lorenzo Gatti From deets at nospam.web.de Thu Nov 12 05:41:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 11:41:12 +0100 Subject: python with echo In-Reply-To: References: Message-ID: <7m2729F3fjr14U1@mid.uni-berlin.de> hong zhang schrieb: > List, > > I have a question of python using echo. > > POWER = 14 > return_value = os.system('echo 14 > /sys/class/net/wlan1/device/tx_power') > > can assign 14 to tx_power > > But > return_value = os.system('echo $POWER > /sys/class/net/wlan1/device/tx_power') > > return_value is 256 not 0. It cannot assign 14 to tx_power. Because $POWER is an environment-variable, but POWER is a python-variable, which isn't magically becoming an environment variable. There are various ways to achieve what you want, but IMHO you should ditch the whole echo-business as it's just needless in python itself: with open("/sys/class/net/wlan1/device/tx_power", "w") as f: f.write("%i" % POWER) Diez From s.selvamsiva at gmail.com Thu Nov 12 05:55:44 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Thu, 12 Nov 2009 16:25:44 +0530 Subject: regex remove closest tag Message-ID: Hi all, 1) I need to remove the tags which is just before the keyword(i.e some_text2 ) excluding others. 2) input string may or may not contain tags. 3) Sample input: inputstr = """start some_text1 some_text2 keyword anything""" 4) I came up with the following regex, p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) s=p.search(inputstr) but second group matches both tags,while i need to match the recent one only. I would like to get your suggestions. Note: If i leave group('good1') as greedy, then it matches both the tag. -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Nov 12 05:56:02 2009 From: lallous at lgwm.org (lallous) Date: Thu, 12 Nov 2009 11:56:02 +0100 Subject: Python C API and references References: <3012832.N8HyCQ2AdE@nntp.coder.cl> Message-ID: Hello Daniel, Thanks for the reply. >> >> Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I >> don't >> need the reference to py_val I should decrement the reference after this >> call? > > It really depends on /how/ the object is created. If the > method used to create *py_val* increases the reference count > on the object and another function any other function is > used to increase the reference count, you should use Py_DECREF > or Py_XDECREF. > >> >> So for example: >> >> PyObject *py_val = PyInt_FromLong(5) >> PyObject_SetAttrString(py_obj, "val", py_val); >> Py_DECREF(py_val) >> >> Right? > > In this case is right. *PyInt_FromLong()* returns a new > reference: 'Return value: New reference.', which is increasing > the reference count and PyObject_SetAttrString does it twice, > then you have a reference count of two and you need to decrement > the initial reference counting of the object, or you will have > a memory leak. > [quote] int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) Set the value of the attribute named attr_name, for object o, to the value v. Returns -1 on failure. This is the equivalent of the Python statement o.attr_name = v. int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) Set the value of the attribute named attr_name, for object o, to the value v. Returns -1 on failure. This is the equivalent of the Python statement o.attr_name = v. [/quote] Looking at the documentation, should I have understood that the passed value reference will be incremented and that I should decrement it if I don't need it? Or I should have understood just because of the fact that whenever we have x = b (be it from the C api in a form of SetAttr()) then we should know that b's reference will be incremented. ? Because, before this discussion I did not know I should decrease the reference after SetAttr() >> >> If so, take sysmodule.c: >> >> if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) >> return NULL; >> >> Shouldn't they also call Py_DECREF(Py_None) ? > > No, I think that Py_None do not needs to decrease the > reference count... > None is an object like other objects. I think its reference must be taken into consideration too, for instance why there is the convenience macro: Py_RETURN_NONE ? -- Elias From deets at nospam.web.de Thu Nov 12 05:56:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 11:56:05 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: Message-ID: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > I guess why every programming language has some kind of a 'standard > library' built in within it. > In my view it must not be called as a 'library' at all. what it does > is like a 'bunch of built-in programs ready-made to do stuff'. > > Lets see what a 'library' does: > > 1. offers books for customers > 1.1 lets user select a book by genre, etc > 1.2 lets user to use different books of same genre, etc > 1.3 lets user to use books by same author, etc for different genre > > 2. keeps track of all the books + their genre > 2.1 first knows what all books it has at present > 2.2 when new book comes it is added to the particular shelf sorted by > genre,author,edition, etc. > 2.3 when books become old they are kept separately for future > reference > 2.4 very old books can be sent to a museum/discarded > > I guess no standard library does the minimum of this but wants to be > called a library. > > As a python user I always wanted the standard library to have such > features so the user/developer decides to use what set of libraries he > want. > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > the user selects what he wants with something like. > > use library 2.5 or use library 2.6 etc. > > The 2 main things that the library management interface has to do is > intra library management and inter library management. > > intra library mgmt- consider books to be different libraries > (standard, commercial, private, hobby, etc) > inter library mgmt- consider books to be modules inside a library > ( standard, commercial, private, hobby, etc) > > if somehow we could accomplish this kind of mother of a all plugin/ad- > hoc system that is a real breakthrough. > > Advantages: > > 1. new modules can be added to the stream quickly > 2. let the user select what he want to do > 3. modules (that interdepend on each other) can be packed into small > distribution and added to the stream quickly without waiting for new > releases > 4. solution to problems like py 2.x and 3.x > 5. users can be up to date > 6. documentation becomes easy + elaborate to users > 7. bug managing is easy too > 8. more feed back > 9. testing also becomes easy > 10. many more , i don't know.. you have to find. > > Python already has some thing like that __future__ stuff. but my > question is how many people know that? and how many use that? most of > them wait until old crust gets totally removed. that is bad for user > and python. that is why problems like py2.x py3.x originate. If there > is a newer book collection it must always be available at the library. > i must not go to another library to get that book. You are greatly oversimplifying things, and ignoring a *lot* of issues here. The reason for __future__ is that it can *break* things if new features were just introduced. Take the with-statement, reachable in python2.5 throug from __future__ import with_statement It introduces a new keyword, which until then could be happily used as variable name. So you can't arbirtarily mix code that is written with one or the other feature missing. Then there is the issue of evolving C-APIs (or ABI), wich makes modules incompatible between interpreters. And frankly, for most of your list I don't see how you think your "approach" reaches the stated advantages. Why is documentation becoming easier? Why bug managing? Why testing? I'm sorry, but this isn't thought out in any way, it's just wishful thinking IMHO. Diez From dickinsm at gmail.com Thu Nov 12 06:02:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 12 Nov 2009 03:02:12 -0800 (PST) Subject: Python C API and references References: Message-ID: <8c62bd48-9281-4422-b526-5d0b8cfd4b9d@l2g2000yqd.googlegroups.com> On Nov 12, 9:23?am, "lallous" wrote: > Hello, > > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't > need the reference to py_val I should decrement the reference after this > call? Not necessarily: it depends where py_val came from. I find the 'ownership' model described in the docs quite helpful: http://docs.python.org/c-api/intro.html#reference-count-details It's probably better to read the docs, but here's a short version: If you create a reference to some Python object in a function in your code, you then 'own' that reference, and you're responsible for getting rid of it by the time the function exits. There are various ways this can happen: you can return the reference, thereby transferring ownership to the calling function; you can explicitly discard the reference by calling Py_DECREF; or you can transfer ownership by calling a function that 'steals' the reference (most functions in the C-API don't steal references, but rather borrow them for the duration of the function call). > > So for example: > > PyObject *py_val = PyInt_FromLong(5) > PyObject_SetAttrString(py_obj, "val", py_val); > Py_DECREF(py_val) > > Right? Yes. Here you've created the reference in the first place, so you should Py_DECREF it before you exit. Right after the PyObject_SetAttrString call is a good place to do this. > > If so, take sysmodule.c: > > ? ? ? ? if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) > ? ? ? ? ? ? ? ? return NULL; > > Shouldn't they also call Py_DECREF(Py_None) ? No, I don't think so. I assume you're looking at the sys_displayhook function? This function doesn't create new references to Py_None (well, except when it's about to return Py_None to the caller), so at this point it doesn't own any reference to Py_None: it's not responsible for decrementing the reference count. > Same logic applies to PyDict_SetItemString() Yes. -- Mark From naughtysriram at gmail.com Thu Nov 12 06:18:03 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:18:03 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: On Nov 12, 3:56?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > I guess why every programming language has some kind of a 'standard > > library' built in within it. > > In my view it must not be called as a 'library' at all. what it does > > is like a 'bunch of built-in programs ready-made to do stuff'. > > > Lets see what a 'library' does: > > > 1. offers books for customers > > ?1.1 lets user select a book by genre, etc > > ?1.2 lets user to use different books of same genre, etc > > ?1.3 lets user to use books by same author, etc for different genre > > > 2. keeps track of all the books + their genre > > ?2.1 first knows what all books it has at present > > ?2.2 when new book comes it is added to the particular shelf sorted by > > genre,author,edition, etc. > > ?2.3 when books become old they are kept separately for future > > reference > > ?2.4 very old books can be sent to a museum/discarded > > > I guess no standard library does the minimum of this but wants to be > > called a library. > > > As a python user I always wanted the standard library to have such > > features so the user/developer decides to use what set of libraries he > > want. > > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > > the user selects what he wants with something like. > > > use library 2.5 or use library 2.6 etc. > > > The 2 main things that the library management interface has to do is > > intra library management and inter library management. > > > intra library mgmt- consider books to be different libraries > > (standard, commercial, private, hobby, etc) > > inter library mgmt- consider books to be modules inside a library > > ( standard, commercial, private, hobby, etc) > > > if somehow we could accomplish this kind of mother of a all plugin/ad- > > hoc system that is a real breakthrough. > > > Advantages: > > > 1. new modules can be added to the stream quickly > > 2. let the user select what he want to do > > 3. modules (that interdepend on each other) can be packed into small > > distribution and added to the stream quickly without waiting for new > > releases > > 4. solution to problems like py 2.x and 3.x > > 5. users can be up to date > > 6. documentation becomes easy + elaborate to users > > 7. bug managing is easy too > > 8. more feed back > > 9. testing also becomes easy > > 10. many more , i don't know.. you have to find. > > > Python already has some thing like that __future__ stuff. but my > > question is how many people know that? and how many use that? most of > > them wait until old crust gets totally removed. that is bad for user > > and python. that is why problems like py2.x py3.x originate. If there > > is a newer book collection it must always be available at the library. > > i must not go to another library to get that book. > > You are greatly oversimplifying things, and ignoring a *lot* of issues > here. The reason for __future__ is that it can *break* things if new > features were just introduced. Take the with-statement, reachable in > python2.5 throug > > ? ?from __future__ import with_statement > > It introduces a new keyword, which until then could be happily used as > variable name. > > So you can't arbirtarily mix code that is written with one or the other > feature missing. > > Then there is the issue of evolving C-APIs (or ABI), wich makes modules > incompatible between interpreters. > > And frankly, for most of your list I don't see how you think your > "approach" reaches the stated advantages. Why is documentation becoming > easier? Why bug managing? Why testing? > > I'm sorry, but this isn't thought out in any way, it's just wishful > thinking IMHO. > > Diez I don't know if you have used Dev-C++. It has a 'package management' mechanism for the standard libraries. please see the webpage where all the packaged libraries are stored. In python we have the PyPI which is equivalent to the http://devpacks.org but in PyPI the packages are mostly user made applications. What I want is similar to PyPI but for the python standard libraries, so that they (libraries) are as add-on as possible. check this out too.. I guess you understand what I am thinking... and do pardon my english too.. -- Regards, Sriram. From deets at nospam.web.de Thu Nov 12 06:27:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 12:27:12 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: <7m29p0F3fng2lU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: >> Sriram Srinivasan schrieb: >> >> >> >>> I guess why every programming language has some kind of a 'standard >>> library' built in within it. >>> In my view it must not be called as a 'library' at all. what it does >>> is like a 'bunch of built-in programs ready-made to do stuff'. >>> Lets see what a 'library' does: >>> 1. offers books for customers >>> 1.1 lets user select a book by genre, etc >>> 1.2 lets user to use different books of same genre, etc >>> 1.3 lets user to use books by same author, etc for different genre >>> 2. keeps track of all the books + their genre >>> 2.1 first knows what all books it has at present >>> 2.2 when new book comes it is added to the particular shelf sorted by >>> genre,author,edition, etc. >>> 2.3 when books become old they are kept separately for future >>> reference >>> 2.4 very old books can be sent to a museum/discarded >>> I guess no standard library does the minimum of this but wants to be >>> called a library. >>> As a python user I always wanted the standard library to have such >>> features so the user/developer decides to use what set of libraries he >>> want. >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, >>> the user selects what he wants with something like. >>> use library 2.5 or use library 2.6 etc. >>> The 2 main things that the library management interface has to do is >>> intra library management and inter library management. >>> intra library mgmt- consider books to be different libraries >>> (standard, commercial, private, hobby, etc) >>> inter library mgmt- consider books to be modules inside a library >>> ( standard, commercial, private, hobby, etc) >>> if somehow we could accomplish this kind of mother of a all plugin/ad- >>> hoc system that is a real breakthrough. >>> Advantages: >>> 1. new modules can be added to the stream quickly >>> 2. let the user select what he want to do >>> 3. modules (that interdepend on each other) can be packed into small >>> distribution and added to the stream quickly without waiting for new >>> releases >>> 4. solution to problems like py 2.x and 3.x >>> 5. users can be up to date >>> 6. documentation becomes easy + elaborate to users >>> 7. bug managing is easy too >>> 8. more feed back >>> 9. testing also becomes easy >>> 10. many more , i don't know.. you have to find. >>> Python already has some thing like that __future__ stuff. but my >>> question is how many people know that? and how many use that? most of >>> them wait until old crust gets totally removed. that is bad for user >>> and python. that is why problems like py2.x py3.x originate. If there >>> is a newer book collection it must always be available at the library. >>> i must not go to another library to get that book. >> You are greatly oversimplifying things, and ignoring a *lot* of issues >> here. The reason for __future__ is that it can *break* things if new >> features were just introduced. Take the with-statement, reachable in >> python2.5 throug >> >> from __future__ import with_statement >> >> It introduces a new keyword, which until then could be happily used as >> variable name. >> >> So you can't arbirtarily mix code that is written with one or the other >> feature missing. >> >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules >> incompatible between interpreters. >> >> And frankly, for most of your list I don't see how you think your >> "approach" reaches the stated advantages. Why is documentation becoming >> easier? Why bug managing? Why testing? >> >> I'm sorry, but this isn't thought out in any way, it's just wishful >> thinking IMHO. >> >> Diez > > I don't know if you have used Dev-C++. packages/index.html> It has a 'package management' mechanism for the > standard libraries. No, it hasn't. It has packages for *additional* libraries. C++ has only a very dim concept of standard-libraries. And those usually ship with the compiler, as standard-libraries shipped with python. > please see the webpage where all the packaged > libraries are stored. > > In python we have the PyPI which is equivalent to the http://devpacks.org > but in PyPI the packages are mostly user made applications. > What I want is similar to PyPI but for the python standard libraries, > so that they (libraries) are as add-on as possible. > check this out too.. Why do you want that? What is the actual issue you are addressing? Python's strength is that it comes with a certain set of libs bundled. Artificially to unbundle them, forcing users to install them separatly makes little sense, if any. Sure, updating a bug might be *slightly* easier, but then the standard-libraries are well-tested and decoupling their evolving from the releases of the core interpreter opens up a whole can of worms of problems. There is a tradeoff for both approaches, and one can argue if the current balance is the right one - but if so, then over concrete packages, not over the system in general. Diez From naughtysriram at gmail.com Thu Nov 12 06:28:41 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:28:41 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> Message-ID: <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> On Nov 12, 3:56?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > I guess why every programming language has some kind of a 'standard > > library' built in within it. > > In my view it must not be called as a 'library' at all. what it does > > is like a 'bunch of built-in programs ready-made to do stuff'. > > > Lets see what a 'library' does: > > > 1. offers books for customers > > ?1.1 lets user select a book by genre, etc > > ?1.2 lets user to use different books of same genre, etc > > ?1.3 lets user to use books by same author, etc for different genre > > > 2. keeps track of all the books + their genre > > ?2.1 first knows what all books it has at present > > ?2.2 when new book comes it is added to the particular shelf sorted by > > genre,author,edition, etc. > > ?2.3 when books become old they are kept separately for future > > reference > > ?2.4 very old books can be sent to a museum/discarded > > > I guess no standard library does the minimum of this but wants to be > > called a library. > > > As a python user I always wanted the standard library to have such > > features so the user/developer decides to use what set of libraries he > > want. > > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > > the user selects what he wants with something like. > > > use library 2.5 or use library 2.6 etc. > > > The 2 main things that the library management interface has to do is > > intra library management and inter library management. > > > intra library mgmt- consider books to be different libraries > > (standard, commercial, private, hobby, etc) > > inter library mgmt- consider books to be modules inside a library > > ( standard, commercial, private, hobby, etc) > > > if somehow we could accomplish this kind of mother of a all plugin/ad- > > hoc system that is a real breakthrough. > > > Advantages: > > > 1. new modules can be added to the stream quickly > > 2. let the user select what he want to do > > 3. modules (that interdepend on each other) can be packed into small > > distribution and added to the stream quickly without waiting for new > > releases > > 4. solution to problems like py 2.x and 3.x > > 5. users can be up to date > > 6. documentation becomes easy + elaborate to users > > 7. bug managing is easy too > > 8. more feed back > > 9. testing also becomes easy > > 10. many more , i don't know.. you have to find. > > > Python already has some thing like that __future__ stuff. but my > > question is how many people know that? and how many use that? most of > > them wait until old crust gets totally removed. that is bad for user > > and python. that is why problems like py2.x py3.x originate. If there > > is a newer book collection it must always be available at the library. > > i must not go to another library to get that book. > > You are greatly oversimplifying things, and ignoring a *lot* of issues > here. The reason for __future__ is that it can *break* things if new > features were just introduced. Take the with-statement, reachable in > python2.5 throug > > ? ?from __future__ import with_statement > > It introduces a new keyword, which until then could be happily used as > variable name. > > So you can't arbirtarily mix code that is written with one or the other > feature missing. > > Then there is the issue of evolving C-APIs (or ABI), wich makes modules > incompatible between interpreters. > > And frankly, for most of your list I don't see how you think your > "approach" reaches the stated advantages. Why is documentation becoming > easier? Why bug managing? Why testing? > > I'm sorry, but this isn't thought out in any way, it's just wishful > thinking IMHO. > > Diez __future__ as you said helps in stop breaking things. what i suggest that if both the libraries (in yr case-with is defined in one and other with is not defined is a simple one) like py2.x and py3.x exists and i want to use 3.x features in the morning then in the evening i want to use 2.x or something like that just add on the library and i get the require functionality From tartley at tartley.com Thu Nov 12 06:29:59 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Thu, 12 Nov 2009 03:29:59 -0800 (PST) Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: On Nov 10, 1:34?pm, Philip Semanchuk wrote: > On Nov 9, 2009, at 9:16 PM, Gabriel Genellina wrote: > > > > > En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk > > escribi?: > >> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: > > >>> Recently I put together this incomplete comparison chart in an ? > >>> attempt > >>> to choose between the different alternatives to py2exe: > > >>>http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output... > > >> I was interested in py2exe because we'd like to provide a one ? > >> download, one click install experience for our Windows users. I ? > >> think a lot of people are interested in py2exe for the same reason. ? > >> Well, one thing that I came across in my travels was the fact that ? > >> distutils can create MSIs. Like py2exe, MSIs provide a one ? > >> download, one click install experience under Windows and therefore ? > >> might be a replacement for py2exe. > > > But py2exe and .msi are complementary, not a replacement. > > py2exe collects in onedirectory(or even in one file in some cases) ? > > all the pieces necesary to run your application. That is,Python? > > itself + your application code + all referenced libraries + other ? > > required pieces. > > The resulting files must beinstalledin the client machine; you ? > > either build a .msi file (a database for the Microsoft Installer) or ? > > use any other installer (like InnoSetup, the one I like). > > >> For me, the following command was sufficient to create an msi, ? > >> although it only worked under Windows (not under Linux or OS X): > >>pythonsetup.py bdist_msi > > >> The resulting MSI worked just fine in my extensive testing (read: I ? > >> tried it on one machine). > > > The resulting .msi file requiresPythonalreadyinstalledon the ? > > target machine, if I'm not mistaken. The whole point of py2exe is to ? > > avoid requiring a previousPythoninstall. > > You're right; the MSI I created doesn't include prerequisites. It ? > packaged up our app, that's it. To be fair to MSIs, they might be ? > capable of including prerequisites, the app, and the kitchen sink. But ? > I don't thinkPython'screation process through distutils makes that ? > possible. > > That's why I suggested MSIs belong alongside RPM/DEB in the chart (if ? > they're to be included at all). > > I wouldn't say that the whole point of py2exe is to bundlePython. ? > That's certainly a big benefit, but another benefit is that it can ? > bundle an app into a one-click download. That's why we were interested ? > in it. > > > > >> It seems, then, that creating an MSI is even within the reach of ? > >> someone like me who spends very little time in Windows-land, so it ? > >> might be worth a column on your chart alongside rpm/deb. > > > As said inhttp://wiki.python.org/moin/DistributionUtilitiesthe ? > > easiest way is to use py2exe + InnoSetup. > > Easiest for you. =) The list of packages and modules that might ? > require special treatment is almost a perfect superset of the modules ? > we're using in our application:http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules > > py2exe looks great, but it remains to be seen if it's the easiest way ? > to solve our problem. The MSI isn't nearly as nice for the end user, ? > but we created it using only thePythonstandard library and our ? > existing setup.py. Simplicity has value. > > Cheers > Philip Hey Philip and Gabriel, Interesting to hear your respective perspectives - you've given me much to ponder and to read about. Personally I'm keen to find a method that doesn't require the end-user to have to manually install (the correct version of) Python separately from my app, so I think that rules out the distutils-generated MSI for me. I can see it has value for others though. From deets at nospam.web.de Thu Nov 12 06:35:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 12:35:11 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> Message-ID: <7m2a7fF3g36nnU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: >> Sriram Srinivasan schrieb: >> >> >> >>> I guess why every programming language has some kind of a 'standard >>> library' built in within it. >>> In my view it must not be called as a 'library' at all. what it does >>> is like a 'bunch of built-in programs ready-made to do stuff'. >>> Lets see what a 'library' does: >>> 1. offers books for customers >>> 1.1 lets user select a book by genre, etc >>> 1.2 lets user to use different books of same genre, etc >>> 1.3 lets user to use books by same author, etc for different genre >>> 2. keeps track of all the books + their genre >>> 2.1 first knows what all books it has at present >>> 2.2 when new book comes it is added to the particular shelf sorted by >>> genre,author,edition, etc. >>> 2.3 when books become old they are kept separately for future >>> reference >>> 2.4 very old books can be sent to a museum/discarded >>> I guess no standard library does the minimum of this but wants to be >>> called a library. >>> As a python user I always wanted the standard library to have such >>> features so the user/developer decides to use what set of libraries he >>> want. >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, >>> the user selects what he wants with something like. >>> use library 2.5 or use library 2.6 etc. >>> The 2 main things that the library management interface has to do is >>> intra library management and inter library management. >>> intra library mgmt- consider books to be different libraries >>> (standard, commercial, private, hobby, etc) >>> inter library mgmt- consider books to be modules inside a library >>> ( standard, commercial, private, hobby, etc) >>> if somehow we could accomplish this kind of mother of a all plugin/ad- >>> hoc system that is a real breakthrough. >>> Advantages: >>> 1. new modules can be added to the stream quickly >>> 2. let the user select what he want to do >>> 3. modules (that interdepend on each other) can be packed into small >>> distribution and added to the stream quickly without waiting for new >>> releases >>> 4. solution to problems like py 2.x and 3.x >>> 5. users can be up to date >>> 6. documentation becomes easy + elaborate to users >>> 7. bug managing is easy too >>> 8. more feed back >>> 9. testing also becomes easy >>> 10. many more , i don't know.. you have to find. >>> Python already has some thing like that __future__ stuff. but my >>> question is how many people know that? and how many use that? most of >>> them wait until old crust gets totally removed. that is bad for user >>> and python. that is why problems like py2.x py3.x originate. If there >>> is a newer book collection it must always be available at the library. >>> i must not go to another library to get that book. >> You are greatly oversimplifying things, and ignoring a *lot* of issues >> here. The reason for __future__ is that it can *break* things if new >> features were just introduced. Take the with-statement, reachable in >> python2.5 throug >> >> from __future__ import with_statement >> >> It introduces a new keyword, which until then could be happily used as >> variable name. >> >> So you can't arbirtarily mix code that is written with one or the other >> feature missing. >> >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules >> incompatible between interpreters. >> >> And frankly, for most of your list I don't see how you think your >> "approach" reaches the stated advantages. Why is documentation becoming >> easier? Why bug managing? Why testing? >> >> I'm sorry, but this isn't thought out in any way, it's just wishful >> thinking IMHO. >> >> Diez > > __future__ as you said helps in stop breaking things. what i suggest > that if both the libraries (in yr case-with is defined in one and > other with is not defined is a simple one) like py2.x and py3.x exists > and i want to use 3.x features in the morning then in the evening i > want to use 2.x or something like that just add on the library and i > get the require functionality This doesn't make sense to me. What are you doing in the morning, and what in the evening, and to what extend is the code the same or are you talking about different pieces of code? Diez From naughtysriram at gmail.com Thu Nov 12 06:54:00 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 03:54:00 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> Message-ID: <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> On Nov 12, 4:35?pm, "Diez B. Roggisch" wrote: > Sriram Srinivasan schrieb: > > > > > On Nov 12, 3:56 pm, "Diez B. Roggisch" wrote: > >> Sriram Srinivasan schrieb: > > >>> I guess why every programming language has some kind of a 'standard > >>> library' built in within it. > >>> In my view it must not be called as a 'library' at all. what it does > >>> is like a 'bunch of built-in programs ready-made to do stuff'. > >>> Lets see what a 'library' does: > >>> 1. offers books for customers > >>> ?1.1 lets user select a book by genre, etc > >>> ?1.2 lets user to use different books of same genre, etc > >>> ?1.3 lets user to use books by same author, etc for different genre > >>> 2. keeps track of all the books + their genre > >>> ?2.1 first knows what all books it has at present > >>> ?2.2 when new book comes it is added to the particular shelf sorted by > >>> genre,author,edition, etc. > >>> ?2.3 when books become old they are kept separately for future > >>> reference > >>> ?2.4 very old books can be sent to a museum/discarded > >>> I guess no standard library does the minimum of this but wants to be > >>> called a library. > >>> As a python user I always wanted the standard library to have such > >>> features so the user/developer decides to use what set of libraries he > >>> want. > >>> consider the libraries for 2.5 ,2.6, 3K are all available to the user, > >>> the user selects what he wants with something like. > >>> use library 2.5 or use library 2.6 etc. > >>> The 2 main things that the library management interface has to do is > >>> intra library management and inter library management. > >>> intra library mgmt- consider books to be different libraries > >>> (standard, commercial, private, hobby, etc) > >>> inter library mgmt- consider books to be modules inside a library > >>> ( standard, commercial, private, hobby, etc) > >>> if somehow we could accomplish this kind of mother of a all plugin/ad- > >>> hoc system that is a real breakthrough. > >>> Advantages: > >>> 1. new modules can be added to the stream quickly > >>> 2. let the user select what he want to do > >>> 3. modules (that interdepend on each other) can be packed into small > >>> distribution and added to the stream quickly without waiting for new > >>> releases > >>> 4. solution to problems like py 2.x and 3.x > >>> 5. users can be up to date > >>> 6. documentation becomes easy + elaborate to users > >>> 7. bug managing is easy too > >>> 8. more feed back > >>> 9. testing also becomes easy > >>> 10. many more , i don't know.. you have to find. > >>> Python already has some thing like that __future__ stuff. but my > >>> question is how many people know that? and how many use that? most of > >>> them wait until old crust gets totally removed. that is bad for user > >>> and python. that is why problems like py2.x py3.x originate. If there > >>> is a newer book collection it must always be available at the library. > >>> i must not go to another library to get that book. > >> You are greatly oversimplifying things, and ignoring a *lot* of issues > >> here. The reason for __future__ is that it can *break* things if new > >> features were just introduced. Take the with-statement, reachable in > >> python2.5 throug > > >> ? ?from __future__ import with_statement > > >> It introduces a new keyword, which until then could be happily used as > >> variable name. > > >> So you can't arbirtarily mix code that is written with one or the other > >> feature missing. > > >> Then there is the issue of evolving C-APIs (or ABI), wich makes modules > >> incompatible between interpreters. > > >> And frankly, for most of your list I don't see how you think your > >> "approach" reaches the stated advantages. Why is documentation becoming > >> easier? Why bug managing? Why testing? > > >> I'm sorry, but this isn't thought out in any way, it's just wishful > >> thinking IMHO. > > >> Diez > > > __future__ as you said helps in stop breaking things. what i suggest > > that if both the libraries (in yr case-with is defined in one and > > other with is not defined is a simple one) like py2.x and py3.x exists > > and i want to use 3.x features in the morning then in the evening i > > want to use 2.x or something like that just add on the library and i > > get the require functionality > > This doesn't make sense to me. What are you doing in the morning, and > what in the evening, and to what extend is the code the same or are you > talking about different pieces of code? > > Diez ok let me make it more clear.. forget how you use python now.. i am talking about __futuristic__ python programming. there is no more python2.x or python3.x or python y.x releases. there is only updates of python and standard library say 1.1.5 and 1.1.6. let the difference be an old xml library updated with a new regex support. i am coding my program now. i want my application to be compatible with 1.1.5 library use library 1.1.5 import blah form blahblah ... ... i cannot use regex feature of xml in this application i then update my library in the evening now both the libraries are present in my system. now i try using the new feature use library 1.1.6 #thats all now i get all features import blah from blahblah ... ... From himanshu.garg at gmail.com Thu Nov 12 07:16:55 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 18:16:55 +0600 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: <6f82a7270911120416o76ebaf69p6c439fd36150e026@mail.gmail.com> 2009/11/12 ankita dutta : > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this : > > 0.02??? 0.38??? 0.01 > 0.04??? 0.32??? 0.00 > 0.03??? 0.40??? 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i am > trying with the following code, i am getting errors : > > code: > " > ln1=open("A.txt","r+")??? # file "A.txt" contains my matrix > lines1=ln1.readlines() > n_1=[ ] > > for p1 in range (0,len(lines1)): > ??? f1=lines1[p1] > ??? n_1.append((f1) ) > print n_1 > print? sum(n_1[0]) > > " > > output: > > ['0.0200\t0.3877\t0.0011\n', '0.0040\t0.3292\t0.0001\n', > '0.0355\t0.4098\t0.0028\n', '0.0035\t0.3063\t0.0001\n', > '0.0080\t0.3397\t0.0002\n'] > > Traceback (most recent call last): > ? File "A_1.py", line 20, in > ??? print sum(nodes_1[0]) > ? File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line > 993, in sum > ??? return _wrapit(a, 'sum', axis, dtype, out) > ? File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line > 37, in _wrapit > ??? result = getattr(asarray(obj),method)(*args, **kwds) > TypeError: cannot perform reduce with flexible type > > > what I think: > > as the list is in form of?? '0.0200\t0.3877\t0.0011\n'??? ,? n_1[0]? takes > it as a whole string?? which includes "\t" , i think thats why they are > giving error. > > now how can i read only required numbers from this line > '0.0200\t0.3877\t0.0011\n'? and find their sum ? > can you kindly help me out how to properly code thing . > Yes you have it right. Split the string at spaces and convert the numeric parts to floats before summing. Something along these lines :- 1 ln1=open("A.txt","r+") # file "A.txt" contains my matrix 2 lines1=ln1.readlines() 3 n_1=[ ] 4 5 for p1 in range (0,len(lines1)): 6 f1=lines1[p1] 7 n_1.append((f1) ) 8 print n_1 9 import re 10 nos = [] 11 for s in re.split('\s+', n_1[0]): 12 if s != '': 13 nos.append(float(s)) 14 print nos 15 print sum(nos) Better still use the csv module as suggested. Thank You, ++imanshu From arnaud.sig at gmail.com Thu Nov 12 07:25:41 2009 From: arnaud.sig at gmail.com (Arnaud Vandecasteele) Date: Thu, 12 Nov 2009 13:25:41 +0100 Subject: NetCDF to ascii file Message-ID: <166b86070911120425k69cc1e3co3dd1f4c7f2b1b4cb@mail.gmail.com> Hi all, I would like to know if it's possible to read data from a netcdf file and export it into an ASCII file. I'm trying to get the latitude, longitude and a determinate value of a netcdf file. But I don't know exactly how to do it. I succeed to open and read a netcdf file but i don't know how to export the data. Here is my simple script : import Scientific.IO.NetCDF as nc from Numeric import * import sys try : ncFile = nc.NetCDFFile("tos_O1_2001-2002.nc","r") except : print "can't open the file" sys.exit(1) try : print "################# Dimensions #################" print ncFile.dimensions.keys() print "################# Variables #################" print ncFile.variables.keys() #return ['time_bnds', 'lat_bnds', 'lon', 'lon_bnds', 'time', 'lat', 'tos' print "################# Var Dim #################" tos = ncFile.variables["tos"] print tos.dimensions #return : ('time', 'lat', 'lon') tosValue = tos.getValue() except : ncFile.close() Do you know how I can get for each tos feature the lat, lon and time values. Best regards Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From himanshu.garg at gmail.com Thu Nov 12 07:28:58 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Thu, 12 Nov 2009 18:28:58 +0600 Subject: Error in Windmill In-Reply-To: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> References: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> Message-ID: <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> 2009/11/12 Raji Seetharaman : > > Hi > > Im learning Web scraping with Python from here > http://www.packtpub.com/article/web-scraping-with-python-part-2 > > From the above link, the complete code is here http://pastebin.com/m10046dc6 > > When i run the program in the terminal i receive following errors > > File "nasa.py", line 41, in > ??? test_scrape_iotd_gallery() > ? File "nasa.py", line 24, in test_scrape_iotd_gallery > ??? client = WindmillTestClient(__name__) > ? File > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", > line 142, in __init__ > ??? method_proxy = windmill.tools.make_jsonrpc_client() > ? File > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", > line 35, in make_jsonrpc_client > ??? url = urlparse(windmill.settings['TEST_URL']) > AttributeError: 'module' object has no attribute 'settings' > > Suggest me > > Thanks > Raji. S > > -- > http://mail.python.org/mailman/listinfo/python-list > > Google or See http://groups.google.com/group/windmill-dev/browse_thread/thread/c921f7a25c0200c9 From sromero at gmail.com Thu Nov 12 07:35:07 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 04:35:07 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) Message-ID: Hi. I'm trying to port (just for fun), my old Sinclair Spectrum emulator, ASpectrum, from C to Python + pygame. Although the Sinclair Spectrum has a simple Z80 8 bit 3.5Mhz microprocessor, and no aditional hardware (excluding the +2/+3 model's AYsound chip), I'm not sure if my loved scripted language, python, will be fast enought to emulate the Sinclair Spectrum at 100% speed. There are Java Spectrum emulators available, so it should be possible. Anyway, this message is directed to prepare the DESIGN so that the code can run as fast as possible. I mean, I want to know the best way to do some emulation tasks before starting to write a single line of code. My questions: GLOBAL VARIABLES VS OBJECTS: ================================== I need the emulation to be as fastest as possible. In my C program I have an struct called "Z80_Processor" that contains all the registers, memory structures, and so on. I pass that struct to the Z80Decode(), Z80Execute() or Z80Dissassemble() functions, i.e.. This allows me (in my C emulator) to emulate multiple z80 processors If I want. As Python is scripted and I imagine that emulation will be slower than the emulator written in C, I've thought of not creating a Z80_Processor *object* and declare global variables such as reg_A, reg_B, reg_PC, array main_memory[] and so on, and let the z80 functions to directly access that global variables. I'm doing this to avoid OOP's extra processing... but this makes the program less modular. Do you think using processor "objects" would make the execution slower, or I'm doing right using global variables and avoiding objects in this type of program? Should I start writing all the code with a Z80CPU object and if performance is low, just remove the "object" layer and declare it as globals, or I should go directly for globals? HIGH AND LOW PART OF REGISTERS: ================================= - In C, I have the following structs and code for emulating registers: typedef union { struct { unsigned char l, h; } B; unsigned short W; } eword; eword reg_A; This means that reg_A is a 16 bit "variable" that I can directly access with reg_A.w=value, and I can access also the LOW BYTE and HIGH BYTES with reg_A.B.h and reg_A.B.l. And more importante, changing W modifies l and h, and changing l or h modifies W. How can I implement this in Python, I mean, define a 16 byte variable so that high and low bytes can be accessed separately and changing W, H or L affects the entire variable? I would like to avoid doing BIT masks to get or change HIGH or LOW parts of a variable and let the compiled code to do it by itself. I know I can write an "object" with set and get methods that implement that (that could be done in C too), but for emulation, I need the FASTEST implementation possible (something like the C's Union trick). MEMORY (ARRAYS): =========================== To emulate Spectrum's memory in C, I have a 64KB array like: unsigned char memory_array[65535]. Then I can access memory_array[reg_PC] to fetch the next opcode (or data for an opcode) and just increment reg_PC. Is python's array module the best (and fastest) implementation to "emulate" the memory? MEMORY (PAGES): ============================= The Sinclair Spectrum 8 bit computer can address 64KB of memory and that memory is based on 16KB pages (so it can see 4 pages simultaneously, where page 0 is always ROM). Programs can change "pages" to point to aditional 16KB pages in 128KB memory models. I don't know how to emulate paging in python... My first approach would be to have eight 16KB arrays, and "memcpy()" memory to the main 64KB array when the user calls page swapping. I mean (C + pseudocode): main_memory[65536]; memory_blocks[8][16384]; // Initial settings current_pages[4] = [0, 1, 2, 3] // User swaps last memory page (3) to block 7, so I: page_to_swap_from = 3 page_to_map = 7 // Save the contents of current page (page being unmapped): memcpy( main_memory, // Source 16384*page_to_swap_from, // Starting at memory_blocks[current_pages[page_to_swap_from], // To 16384 ); // 16K // Now map page 7 to memory block 3: memcpy( memory_blocks[page_to_map], // Source 0, // Starting at main_memory[page_to_swap_from*16384], // To 16384 ); // 16K current_pages[page_to_swap_from] = page_to_map; Memcpy is very fast in C, but I don't know if doing the same in python with arrays would be fast enough, or if there is a better approach to simulate paging of 16KB blocks in a 64KB memory windows (4 mappable memory blocks). Maybe another approach based in pointers or something like that? From deets at nospam.web.de Thu Nov 12 08:07:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 14:07:48 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> Message-ID: <7m2fl4F3g3usmU1@mid.uni-berlin.de> > > ok let me make it more clear.. > forget how you use python now.. i am talking about __futuristic__ > python programming. > > > there is no more python2.x or python3.x or python y.x releases. there > is only updates of python and standard library say 1.1.5 and 1.1.6. > let the difference be an old xml library updated with a new regex > support. > > i am coding my program now. > i want my application to be compatible with 1.1.5 library > > use library 1.1.5 > import blah form blahblah > ... > ... > > i cannot use regex feature of xml in this application > i then update my library in the evening > now both the libraries are present in my system. > now i try using the new feature > > use library 1.1.6 #thats all now i get all features > import blah from blahblah This is not futuristic, this is state of the art with PyPI & setuptools. You still haven't addressed all the issues that arise though, regarding different python interpreter versions having different syntax and ABI. Diez From hpj at urpla.net Thu Nov 12 08:10:32 2009 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 12 Nov 2009 14:10:32 +0100 Subject: About one class/function per module In-Reply-To: <7lajrkF3c97onU1@mid.uni-berlin.de> References: <7lajrkF3c97onU1@mid.uni-berlin.de> Message-ID: <200911121410.32298.hpj@urpla.net> On Tuesday 03 November 2009, 12:52:20 Diez B. Roggisch wrote: > Peng Yu wrote: > > On Mon, Nov 2, 2009 at 9:39 PM, alex23 wrote: > >> Peng Yu wrote: > >>> I don't think that this is a problem that can not be overcome. A > >>> simple solution might be to associate a unique identifier to each > >>> file, so that even the filename has been changed, the new version and > >>> the old version can still be identified as actually the same file. > >> > >> Or, again, you could work _with_ the tools you're using in the way > >> they're meant to be used, rather than re-inventing the whole process > >> of version control yourself. > > > > I'm not trying to reinvent a new version control. But due to this > > drawback, I avoid use a version control system. Rather, I compressed > > my source code in a tar file whenever necessary. But if a version > > control system has this capability, I'd love to use it. And I don't > > think that no version control system support this is because of any > > technical difficult but rather because of practical issue (maybe it > > takes a lot efforts to add this feature to an existing version control > > system?). > > There are those people who realize if *everything* they encounter needs > adjustment to fit their needs, their needs need adjustment. > > Others fight an uphill battle & bicker about things not being as they > want them. > > Don't get me wrong - innovation often comes from scratching ones personal > itch. But you seem to be suffering from a rather bad case of > neurodermatitis. Diez, sorry for chiming in that lately, but while the whole thread is spilled over for no good reason, your QOTW remembered me on a quote of R.A.W., that sounds like a perfect fit: Whatever the Thinker thinks, the Prover will prove. And if the Thinker thinks passionately enough, the Prover will prove the thought so conclusively that you will never talk a person out of such a belief, even if it is something as remarkable as the notion that there is a gaseous vertebrate of astronomical heft ("GOD") who will spend all eternity torturing people who do not believe in his religion. From "Prometheus Rising" by Robert Anton Wilson Pete http://en.wikiquote.org/wiki/Robert_Anton_Wilson From sraji.me at gmail.com Thu Nov 12 08:20:35 2009 From: sraji.me at gmail.com (Raji Seetharaman) Date: Thu, 12 Nov 2009 18:50:35 +0530 Subject: Error in Windmill In-Reply-To: <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> References: <23e3fbb60911120107q4e503234pbe5944c327517eff@mail.gmail.com> <6f82a7270911120428x43eb8dcey5a40a934b19c0731@mail.gmail.com> Message-ID: <23e3fbb60911120520o2314bb15p2934c30eb7b54a6d@mail.gmail.com> On Thu, Nov 12, 2009 at 5:58 PM, Himanshu wrote: > 2009/11/12 Raji Seetharaman : > > > > Hi > > > > Im learning Web scraping with Python from here > > http://www.packtpub.com/article/web-scraping-with-python-part-2 > > > > From the above link, the complete code is here > http://pastebin.com/m10046dc6 > > > > When i run the program in the terminal i receive following errors > > > > File "nasa.py", line 41, in > > test_scrape_iotd_gallery() > > File "nasa.py", line 24, in test_scrape_iotd_gallery > > client = WindmillTestClient(__name__) > > File > > > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/authoring/__init__.py", > > line 142, in __init__ > > method_proxy = windmill.tools.make_jsonrpc_client() > > File > > > "/usr/local/lib/python2.6/dist-packages/windmill-1.3-py2.6.egg/windmill/tools/__init__.py", > > line 35, in make_jsonrpc_client > > url = urlparse(windmill.settings['TEST_URL']) > > AttributeError: 'module' object has no attribute 'settings' > > > > Suggest me > > > > Thanks > > Raji. S > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > Google or See > http://groups.google.com/group/windmill-dev/browse_thread/thread/c921f7a25c0200c9 > Thanks for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 08:21:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 13:21:32 GMT Subject: standard libraries don't behave like standard 'libraries' References: Message-ID: <00859027$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 00:31:57 -0800, Sriram Srinivasan wrote: > I guess why every programming language has some kind of a 'standard > library' built in within it. > In my view it must not be called as a 'library' at all. what it does is > like a 'bunch of built-in programs ready-made to do stuff'. > > Lets see what a 'library' does: > > 1. offers books for customers [...] You are describing a lending library, which is not the only sort of library. My personal library doesn't do any of those things. It is just a room with shelves filled with books. Words in English can have more than one meaning. Horses run, refrigerators run, and even though they don't have either legs or motors, programs run too. The argument that code libraries don't behave like lending libraries won't get you anywhere. > As a python user I always wanted the standard library to have such > features so the user/developer decides to use what set of libraries he > want. > > consider the libraries for 2.5 ,2.6, 3K are all available to the user, > the user selects what he wants with something like. > > use library 2.5 or use library 2.6 etc. Since library features are tied closely to the features available in the Python interpreter, the way to use library 2.5 is to use Python 2.5. You *might* be able to use library 2.5 with Python 2.6 or 2.4; you absolutely won't be able to use it with Python 1.5 or 3.1. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 08:33:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 13:33:21 GMT Subject: How can a module know the module that imported it? References: Message-ID: <008592ec$0$26916$c3e8da3@news.astraweb.com> On Wed, 11 Nov 2009 13:44:06 -0800, Ethan Furman wrote: > Well, I don't know what kj is trying to do, but my project is another > (!) configuration program. (Don't worry, I won't release it... unless > somebody is interested, of course !) > > So here's the idea so far: > The configuration data is stored in a python module (call it > settings.py). In order to be able to do things like add settings to it, > save the file after changes are made, etc., settings.py will import the > configuration module, called configure.py. > > A sample might look like this: > > > import configure > > paths = configure.Item() > paths.tables = 'c:\\app\\data' > paths.temp = 'c:\\temp' > > > And in the main program I would have: > > > import settings > > main_table = dbf.Table('%s\\main' % paths.tables) > > # user can modify path locations, and does, so update # we'll say it > changes to \work\temp > > settings.paths.temp = user_setting() > settings.configure.save() > > > And of course, at this point settings.py now looks like > > > import configure > > paths = configure.Item() > paths.tables = 'c:\\app\\data' > paths.temp = 'c:\\work\\temp' > Self-modifying code? UNCLEAN!!! UNCLEAN!!! > Now, the tricky part is the line > > settings.configure.save() > > How will save know which module it's supposed to be re-writing? In my opinion, the cleanest way is to tell it which module to re-write. Or better still, tell it which *file* to write to: settings.configure.save(settings.__file__) which is still self-modifying, but at least it doesn't need magic to modify itself. -- Steven From naughtysriram at gmail.com Thu Nov 12 08:43:20 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 05:43:20 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> Message-ID: <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> On Nov 12, 6:07?pm, "Diez B. Roggisch" wrote: > > ok let me make it more clear.. > > forget how you use python now.. i am talking about __futuristic__ > > python programming. > > > there is no more python2.x or python3.x or python y.x releases. there > > is only updates of python and standard library say 1.1.5 and 1.1.6. > > let the difference be an old xml library updated with a new regex > > support. > > > i am coding my program now. > > i want my application to be compatible with 1.1.5 library > > > use library 1.1.5 > > import blah form blahblah > > ... > > ... > > > i cannot use regex feature of xml in this application > > i then update my library in the evening > > now both the libraries are present in my system. > > now i try using the new feature > > > use library 1.1.6 #thats all now i get all features > > import blah from blahblah > > This is not futuristic, this is state of the art with PyPI & setuptools. > > You still haven't addressed all the issues that arise though, regarding > different python interpreter versions having different syntax and ABI. > > Diez haha... it would be awesome if they implement it in the 'future' .. i posted the same to python-dev at python.org, it seems the distutil is getting a big overhaul. (i hope they make a new uninstall option for setuptools n easy_install) they say there are many ways to do that using pkg tools... but python wants one and only one way- the python way. regarding issues: 1.security is always a issue 2. regarding problems like with statement you mentioned earlier.. i think there will be a basic feature set that is common for all versions of add-on libraries. 3.when you want the new feature you have to update your python interpreter use interpreter 1.5.2 may trigger the proper interpreter plugin(responsible for additional feature) to load and add functionality.. its simple to say but it is hard to make the compiler pluggable, may be they figure out. use library x.y.z while issuing this command the default interpreter has to automatically resolve dependencies of the core c/cpp static libraries and other shared libraries. so that must not be an issue. if they have implemented this much, dep solving is nothing. futuristic python may also contain an option for compiling a module into a static library. so we can code python libraries in python (mostly) itself. think of pypy. it is already state of the art. From pavlovevidence at gmail.com Thu Nov 12 08:58:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 05:58:45 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: Message-ID: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> On Nov 12, 4:35?am, Santiago Romero wrote: > ?Hi. > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > ASpectrum, from C to Python + pygame. The answer to your question is, "Use numpy". More details below. [snip] > ?Should I start writing all the code with a Z80CPU object and if > performance is low, just remove the "object" layer and declare it as > globals, Yes, but I'd suggest to index a numpy array rather than structures. See below. [snip] > ?How can I implement this in Python, I mean, define a 16 byte variable > so that high and low bytes can be accessed separately and changing W, > H or L affects the entire variable? I would like to avoid doing BIT > masks to get or change HIGH or LOW parts of a variable and let the > compiled code to do it by itself. You can do clever memory slicing like this with numpy. For instance: breg = numpy.zeros((16,),numpy.uint8) wreg = numpy.ndarray((8,),numpy.uint16,breg) This causes breg and wreg to share the same 16 bytes of memory. You can define constants to access specific registers: R1L = 1 R1H = 2 R1 = 1 breg[R1H] = 2 print wreg[R1] [snip] > ?Is python's array module the best (and fastest) implementation to > "emulate" the memory? I'd use numpy for this as well. (I doubt the Z80 had a 16-bit bus, but if it did you could use the same memory sharing trick I showed you with the registers to simulate word reads and writes.) Note that, when performing operations on single values, neither numpy nor array module are necessarily a lot faster than Python lists, might even be slower. But they use a LOT less memory, which is important for largish arrays. [snip] > ?The Sinclair Spectrum 8 bit computer can address 64KB of memory and > that memory is based on 16KB pages (so it can see 4 pages > simultaneously, where page 0 is always ROM). Programs can change > "pages" to point to aditional 16KB pages in 128KB memory models. > > ?I don't know how to emulate paging in python... numpy again. This would mean you'd have to fiddle with addresses a bit, but that shouldn't be too big a deal. Create the physical memory: mem = numpy.zeros((128*1024,),numpy.uint8) Then create the pages. (This is a regular Python list containing numpy slices. numpy slices share memory so there is no copying of underlying data.) page = [mem[0:16*1024], mem[16*1024:32*1024], mem[32*1024:48*1024], mem[48*1024:64*1024]] To access the byte at address 42432, you'd have use bit operations to get a page number and index (2 and 9664 in this case), then you can access the memory like this: page[2][9664] = 33 p = page[3][99] To swap a page, reassign the slice of main memory, page[2] = mem[96*1024:112*1024] Now, accessing address 42432 will access a byte from a different page. If you don't want to fiddle with indirect pages and would just rather copy memory around when a page swap occurs, you can do that, too. (Assigning to a slice copies the data rather than shares.) I don't know if it's as fast as memset but it should be pretty quick. . Hope these brief suggestions help. If you don't want third party libraries, then numpy will be of no use. But I guess if you're using pygame third party modules are ok. So get numpy, it'll make things a lot easier. It can be a bit daunting to learn, though. Carl Banks From naughtysriram at gmail.com Thu Nov 12 09:21:21 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 06:21:21 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <00859027$0$26916$c3e8da3@news.astraweb.com> Message-ID: <8f0c9f6a-35d1-43cf-8a90-250fadb217a8@m38g2000yqd.googlegroups.com> > You are describing a lending library, which is not the only sort of > library. My personal library doesn't do any of those things. It is just a > room with shelves filled with books. how i see is all libraries are libraries, for a personal library you are the only customer and you are the management too.! > Words in English can have more than one meaning. Horses run, > refrigerators run, and even though they don't have either legs or motors, > programs run too. The argument that code libraries don't behave like > lending libraries won't get you anywhere. first this is not an argument at all...i clearly stated these were my imaginations cum ideas. > Since library features are tied closely to the features available in the > Python interpreter, the way to use library 2.5 is to use Python 2.5. You > *might* be able to use library 2.5 with Python 2.6 or 2.4; you absolutely > won't be able to use it with Python 1.5 or 3.1. i am not talking about the past..past were experiences! that the developers had and what is happening today *might be* another experience for the future. From sromero at gmail.com Thu Nov 12 09:37:55 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 06:37:55 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > ASpectrum, from C to Python + pygame. > > The answer to your question is, "Use numpy". ?More details below. Let's see :-) > > ?How can I implement this in Python, I mean, define a 16 byte variable > > so that high and low bytes can be accessed separately and changing W, > > H or L affects the entire variable? I would like to avoid doing BIT > > masks to get or change HIGH or LOW parts of a variable and let the > > compiled code to do it by itself. > > You can do clever memory slicing like this with numpy. ?For instance: > > breg = numpy.zeros((16,),numpy.uint8) > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > This causes breg and wreg to share the same 16 bytes of memory. ?You > can define constants to access specific registers: > > R1L = 1 > R1H = 2 > R1 = 1 > > breg[R1H] = 2 > print wreg[R1] And how about speed? Assuming a 16 bit register named BC which contains 2 8 bit regiters (B and C)... Will the above be faster than shifts and bit operations (<<, and, >> ) with new B and C values to "recalculate" BC when reading or changing either B, C or BC? > > ?Is python's array module the best (and fastest) implementation to > > "emulate" the memory? > > I'd use numpy for this as well. ?(I doubt the Z80 had a 16-bit bus, > but if it did you could use the same memory sharing trick I showed you > with the registers to simulate word reads and writes.) Z80 has a 16 bit ADDRESS bus, 8 bit DATA bus. This means you can address from 0 to 65535 memory cells of 8 bytes. Z80 has 16 bit bus operations, but currently in C I write 16 bit values as two 8 bit consecutive values without using (unsigned short *) pointers. But it seems that numpy would allow me to do it better than C in this case... > Note that, when performing operations on single values, neither numpy > nor array module are necessarily a lot faster than Python lists, might > even be slower. ?But they use a LOT less memory, which is important > for largish arrays. Well, we're talking about a 128KB 1-byte array, that's the maximum memory size a Sinclair Spectrum can have, and always by using page swapping of 16KB blocks in a 64KB addressable space... If you really think that python lists can be faster that numpy or array modules, let me know. Maybe I'll make a "benchmark test", by making some millions of read / write operations and timing the results. I wan't to write the emulator as "pythonic" as possible... > > ?I don't know how to emulate paging in python... > > numpy again. ?This would mean you'd have to fiddle with addresses a > bit, but that shouldn't be too big a deal. ?Create the physical > memory: > > mem = numpy.zeros((128*1024,),numpy.uint8) A 128K array of zeroes... > Then create the pages. ?(This is a regular Python list containing > numpy slices. numpy slices share memory so there is no copying of > underlying data.) > > page = [mem[0:16*1024], > ? ? ? ? mem[16*1024:32*1024], > ? ? ? ? mem[32*1024:48*1024], > ? ? ? ? mem[48*1024:64*1024]] Those are just like pointers to the "mem" numpy array, pointing to concrete start indexes, aren't they? > To access the byte at address 42432, you'd have use bit operations to > get a page number and index (2 and 9664 in this case), then you can > access the memory like this: Do you mean: page = address / 16384 index = address MOD 16384 ? Or, better, with: page = address >> 14 index = address & 16383 ? > page[2][9664] = 33 > p = page[3][99] > > To swap a page, reassign the slice of main memory, > > page[2] = mem[96*1024:112*1024] > > Now, accessing address 42432 will access a byte from a different page. But the above calculations (page, index) wouldn't be slower than a simple play 64KB numpy array (and make no paging mechanism when reading or writing) and copy memory slices when page swappings are requested? > If you don't want to fiddle with indirect pages and would just rather > copy memory around when a page swap occurs, you can do that, too. > (Assigning to a slice copies the data rather than shares.) I don't > know if it's as fast as memset but it should be pretty quick. That's what I was talking about. With "page and index" I'm slowing down EACH memory read and write, and that includes opcode and data fetching... With "memory copying in page swaps", memory is always read and write quickly, and if "slice copies" are fast enough, the emulation will be >100% of speed (I hope) for a 3.5Mhz system ... > Hope these brief suggestions help. ?If you don't want third party > libraries, then numpy will be of no use. ?But I guess if you're using > pygame third party modules are ok. ?So get numpy, it'll make things a > lot easier. ?It can be a bit daunting to learn, though. Yes, you've been very helpful! How about numpy portability? Is array more portable? And finally, do you think I'm doing right by using global variables for registers, memory, and so, or should I put ALL into a single object and pass it to functions? Ummm ... I think I'm going to do some tests with some "for i in range (1,100000000000)" + time :-) Thanks a lot for your help :-) Any other suggestion is welcome. From no.email at please.post Thu Nov 12 09:38:19 2009 From: no.email at please.post (kj) Date: Thu, 12 Nov 2009 14:38:19 +0000 (UTC) Subject: Python & Go References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: In <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44 at p8g2000yqb.googlegroups.com> Carl Banks writes: >...but the lack of >inheritance is a doozie. That's what I like most about it. Inheritance introduces at least as many headaches as it solves. For one, it leads to spaghetti code. When reading such code, to follow any method call one must check in at least two places: the base class and the subclass. The deeper the inheritance chain, the more places one must check. For every method call. Yeecch. Good riddance. kj From casevh at gmail.com Thu Nov 12 09:38:40 2009 From: casevh at gmail.com (casevh) Date: Thu, 12 Nov 2009 06:38:40 -0800 (PST) Subject: C api and checking for integers References: Message-ID: <11dcc7b8-31a5-4245-8eda-a7cfa2f61d68@d9g2000prh.googlegroups.com> On Nov 12, 1:28?am, "lallous" wrote: > Hello, > > I am a little confused on how to check if a python variable is an integer or > not. > > Sometimes PyInt_Check() fails and PyLong_Check() succeeds. I assume you are using Python 2.x. There are two integer types: (1) PyInt which stores small values that can be stored in a single C long and (2) PyLong which stores values that may or may not fit in a single C long. The number 2 could arrive as either a PyInt or a PyLong. Try something like the following: if PyInt_CheckExact() myvar = PyInt_AS_LONG() else if PyLong_CheckExact() myvar = PyLong_As_Long() if ((myvar == -1) && (PyErr_Occurred()) # Too big to fit in a C long Python 3.x is a little easier since everything is a PyLong. > > How to properly check for integer values? > > OTOH, I tried PyNumber_Check() and: > > (1) The doc says: Returns 1 if the object o provides numeric protocols, and > false otherwise. This function always succeeds. > > What do they mean: "always succeeds" ? That it will always return true or false; it won't raise an error. > > (2) It seems PyNumber_check(py_val) returns true when passed an instance! > > Please advise. > > -- > Elias casevh From mcherm at gmail.com Thu Nov 12 10:07:23 2009 From: mcherm at gmail.com (mcherm) Date: Thu, 12 Nov 2009 07:07:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 11, 7:38?pm, Vincent Manis wrote: > 1. The statement `Python is slow' doesn't make any sense to me. > Python is a programming language; it is implementations that have > speed or lack thereof. [...] > 2. A skilled programmer could build an implementation that compiled > Python code into Common Lisp or Scheme code, and then used a > high-performance Common Lisp compiler... I think you have a fundamental misunderstanding of the reasons why Python is slow. Most of the slowness does NOT come from poor implementations: the CPython implementation is extremely well-optimized; the Jython and Iron Python implementations use best-in-the-world JIT runtimes. Most of the speed issues come from fundamental features of the LANGUAGE itself, mostly ways in which it is highly dynamic. In Python, a piece of code like this: len(x) needs to watch out for the following: * Perhaps x is a list OR * Perhaps x is a dict OR * Perhaps x is a user-defined type that declares a __len__ method OR * Perhaps a superclass of x declares __len__ OR * Perhaps we are running the built-in len() function OR * Perhaps there is a global variable 'len' which shadows the built-in OR * Perhaps there is a local variable 'len' which shadows the built-in OR * Perhaps someone has modified __builtins__ In Python it is possible for other code, outside your module to go in and modify or replace some methods from your module (a feature called "monkey-patching" which is SOMETIMES useful for certain kinds of testing). There are just so many things that can be dynamic (even if 99% of the time they are NOT dynamic) that there is very little that the compiler can assume. So whether you implement it in C, compile to CLR bytecode, or translate into Lisp, the computer is still going to have to to a whole bunch of lookups to make certain that there isn't some monkey business going on, rather than simply reading a single memory location that contains the length of the list. Brett Cannon's thesis is an example: he attempted desperate measures to perform some inferences that would allow performing these optimizations safely and, although a few of them could work in special cases, most of the hoped-for improvements were impossible because of the dynamic nature of the language. I have seen a number of attempts to address this, either by placing some restrictions on the dynamic nature of the code (but that would change the nature of the Python language) or by having some sort of a JIT optimize the common path where we don't monkey around. Unladen Swallow and PyPy are two such efforts that I find particularly promising. But it isn't NEARLY as simple as you make it out to be. -- Michael Chermside From victorsubervi at gmail.com Thu Nov 12 10:10:23 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:10:23 -0500 Subject: Can't Write File In-Reply-To: References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> Message-ID: <4dc0cfea0911120710n4bdbffc3m4bd96307c2e848af@mail.gmail.com> On Wed, Nov 11, 2009 at 6:35 PM, Rhodri James wrote: > On Wed, 11 Nov 2009 14:00:44 -0000, Victor Subervi < > victorsubervi at gmail.com> wrote: > > 6) you don't indicate which user is executing this script (only root can >>> write to it) >>> >>> Help me on this. All scripts are owned by root. Is it not root that is >> executing the script? >> > > Not unless your server setup is very, very stupid. CGI scripts normally > run as a user with *very* limited permissions to limit (amongst other > things) the damage ineptly written scripts can do. > Thanks. I'll change it. V > > -- > Rhodri James *-* Wildebeest Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Thu Nov 12 10:10:24 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 12 Nov 2009 09:10:24 -0600 Subject: Why Error is derived from EnvironmentError in shutil.py? In-Reply-To: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> References: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> Message-ID: <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> On Thu, Nov 12, 2009 at 12:00 AM, alex23 wrote: > On Nov 12, 2:46?pm, Peng Yu wrote: >> I see Error is derived from EnvironmentError in shutil.py. >> >> class Error(EnvironmentError): >> ? ? pass >> >> I'm wondering why EnvironmentError can not be raised directly. Why >> Error is raised instead? > > This way you can explicitly trap on shutil.Error and not intercept any > other EnvironmentError that might be raised. > > And as it's a descendent of EnvironmentError, it can still be caught > by any handlers looking for such exceptions. It is true that an exception class is usually defined in a module and all the exceptions raised in this module should be of this derived class? Is it the general practice in python? From victorsubervi at gmail.com Thu Nov 12 10:12:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:12:43 -0500 Subject: CGI vs mod_python In-Reply-To: <4AFB1F73.5070508@ieee.org> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> <4AFB1F73.5070508@ieee.org> Message-ID: <4dc0cfea0911120712k28986b5amc11f8ebba4c99ff3@mail.gmail.com> On Wed, Nov 11, 2009 at 3:32 PM, Dave Angel wrote: > > > Victor Subervi wrote: > >> >> >> The problem was not CGI. It turned out to be line-endings being mangled by >> Windoze and __invisible __ in my unix editor. Lovely. >> Thanks anyway, >> V >> >> >> > That's twice you've blamed Windows for the line-ending problem. Windows > didn't create those crlf endings, your text editor did. If your editor > can't control that, you could try a different one. Komodo for example can > do it either way, or it can preserve whatever is being used in the loaded > file. Similarly metapad, in spite of its huge simplicity, lets you decide, > and can convert an existing file in either direction. > > And I'm a great believer in visible control characters. I configure Komodo > to show me spaces in the lines, so I can see whether it's a tab or a space. > It can also be configured to show end-of-line characters, so I presume > that'd work here. See whether your Unix editor can show you this sort of > thing. > > Finally, many FTP programs can be told to automatically convert > line-endings when transferring text files. There's probably some risk that > it'll mangle a non-text file, but it's worth considering. > Wonderful, wonderful. I'll take both of those pieces of advice. Thank you. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Nov 12 10:37:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 12 Nov 2009 07:37:41 -0800 Subject: Why Error is derived from EnvironmentError in shutil.py? In-Reply-To: <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> References: <24dc9737-d3de-4925-bb4a-fa8c0dd1f765@g1g2000pra.googlegroups.com> <366c6f340911120710r3e2d65bbr2077346912f4943b@mail.gmail.com> Message-ID: <50697b2c0911120737p5b7999c6pe7a86d71352bab8c@mail.gmail.com> On Thu, Nov 12, 2009 at 7:10 AM, Peng Yu wrote: > On Thu, Nov 12, 2009 at 12:00 AM, alex23 wrote: >> On Nov 12, 2:46?pm, Peng Yu wrote: >>> I see Error is derived from EnvironmentError in shutil.py. >>> >>> class Error(EnvironmentError): >>> ? ? pass >>> >>> I'm wondering why EnvironmentError can not be raised directly. Why >>> Error is raised instead? >> >> This way you can explicitly trap on shutil.Error and not intercept any >> other EnvironmentError that might be raised. >> >> And as it's a descendent of EnvironmentError, it can still be caught >> by any handlers looking for such exceptions. > > It is true that an exception class is usually defined in a module and > all the exceptions raised in this module should be of this derived > class? Is it the general practice in python? It is common, but not universal. Several of the modules in the stdlib use the technique. Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Thu Nov 12 10:43:56 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 10:43:56 -0500 Subject: (OT) Recommend FTP Client Message-ID: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Hi; Someone on this list just recommended I find an ftp client that enables me to change line endings. He indicated that it would be easy, but googling I haven't been able to find one. I would prefer a free client, but whatever. Please send me a recommendation. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Nov 12 10:44:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 16:44:13 +0100 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> Message-ID: <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Sriram Srinivasan schrieb: > On Nov 12, 6:07 pm, "Diez B. Roggisch" wrote: >>> ok let me make it more clear.. >>> forget how you use python now.. i am talking about __futuristic__ >>> python programming. >>> there is no more python2.x or python3.x or python y.x releases. there >>> is only updates of python and standard library say 1.1.5 and 1.1.6. >>> let the difference be an old xml library updated with a new regex >>> support. >>> i am coding my program now. >>> i want my application to be compatible with 1.1.5 library >>> use library 1.1.5 >>> import blah form blahblah >>> ... >>> ... >>> i cannot use regex feature of xml in this application >>> i then update my library in the evening >>> now both the libraries are present in my system. >>> now i try using the new feature >>> use library 1.1.6 #thats all now i get all features >>> import blah from blahblah >> This is not futuristic, this is state of the art with PyPI & setuptools. >> >> You still haven't addressed all the issues that arise though, regarding >> different python interpreter versions having different syntax and ABI. >> >> Diez > > haha... it would be awesome if they implement it in the 'future' .. i > posted the same to python-dev at python.org, it seems the distutil is > getting a big overhaul. (i hope they make a new uninstall option for > setuptools n easy_install) they say there are many ways to do that > using pkg tools... but python wants one and only one way- the python > way. > regarding issues: > > 1.security is always a issue > 2. regarding problems like with statement you mentioned earlier.. i > think there will be a basic feature set that is common for all > versions of add-on libraries. So all libraries written have to use the common subset, which - unless things are *removed*, which with python3 actually happened - is always the oldest interpreter. And if a feature goes away, they have to be rewritten with the then common subset. In other words: as a library writer, I can't use shiny, new & better features, I'm stuck with the old stuff, and whenever the intepreter evolves I have to rewrite even the old ones. Not appealing. Why develop the interpreter at all then? > 3.when you want the new feature you have to update your python > interpreter > > use interpreter 1.5.2 > > may trigger the proper interpreter plugin(responsible for additional > feature) to load and add functionality.. its simple to say but it is > hard to make the compiler pluggable, may be they figure out. > > > use library x.y.z > > while issuing this command the default interpreter has to > automatically resolve dependencies of the core c/cpp static libraries > and other shared libraries. so that must not be an issue. if they have > implemented this much, dep solving is nothing. In other words: the problem is solved by somehow solving the problem - but not by a concrete solution you propose? > > futuristic python may also contain an option for compiling a module > into a static library. so we can code python libraries in python > (mostly) itself. think of pypy. it is already state of the art. PyPy is cool, but by far not advanced enough to replace external, C-based libraries such as NUMPY and PyQt and whatnot. I don't say that the current situation is by any means ideal. There is a lot to be said about package creation, distribution, installation, removal, dependency handling, and even system-packaging-integration if one likes. You IMHO just add another layer of complexity on top of it, without proposing solutions to any of the layers in between, nor your new one - namely, the interpreter version agnosticism. Diez From callmeclaudius at gmail.com Thu Nov 12 11:35:23 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Thu, 12 Nov 2009 08:35:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 12, 10:07?am, mcherm wrote: > On Nov 11, 7:38?pm, Vincent Manis wrote: > > > 1. The statement `Python is slow' doesn't make any sense to me. > > Python is a programming language; it is implementations that have > > speed or lack thereof. > ? ?[...] > > 2. A skilled programmer could build an implementation that compiled > > Python code into Common Lisp or Scheme code, and then used a > > high-performance Common Lisp compiler... > > I think you have a fundamental misunderstanding of the reasons why > Python is > slow. Most of the slowness does NOT come from poor implementations: > the CPython > implementation is extremely well-optimized; the Jython and Iron Python > implementations use best-in-the-world JIT runtimes. Most of the speed > issues > come from fundamental features of the LANGUAGE itself, mostly ways in > which > it is highly dynamic. > > In Python, a piece of code like this: > ? ? len(x) > needs to watch out for the following: > ? ? * Perhaps x is a list OR > ? ? ? * Perhaps x is a dict OR > ? ? ? * Perhaps x is a user-defined type that declares a __len__ > method OR > ? ? ? * Perhaps a superclass of x declares __len__ OR > ? ? * Perhaps we are running the built-in len() function OR > ? ? ? * Perhaps there is a global variable 'len' which shadows the > built-in OR > ? ? ? * Perhaps there is a local variable 'len' which shadows the > built-in OR > ? ? ? * Perhaps someone has modified __builtins__ > > In Python it is possible for other code, outside your module to go in > and > modify or replace some methods from your module (a feature called > "monkey-patching" which is SOMETIMES useful for certain kinds of > testing). > There are just so many things that can be dynamic (even if 99% of the > time > they are NOT dynamic) that there is very little that the compiler can > assume. > > So whether you implement it in C, compile to CLR bytecode, or > translate into > Lisp, the computer is still going to have to to a whole bunch of > lookups to > make certain that there isn't some monkey business going on, rather > than > simply reading a single memory location that contains the length of > the list. > Brett Cannon's thesis is an example: he attempted desperate measures > to > perform some inferences that would allow performing these > optimizations > safely and, although a few of them could work in special cases, most > of the > hoped-for improvements were impossible because of the dynamic nature > of the > language. > > I have seen a number of attempts to address this, either by placing > some > restrictions on the dynamic nature of the code (but that would change > the > nature of the Python language) or by having some sort of a JIT > optimize the > common path where we don't monkey around. Unladen Swallow and PyPy are > two > such efforts that I find particularly promising. > > But it isn't NEARLY as simple as you make it out to be. > > -- Michael Chermside obviously the GIL is a major reason it's so slow. That's one of the _stated_ reasons why Google has decided to forgo CPython code. As far as how sweeping the directive is, I don't know, since the situation would sort of resolve itself if one committed to Jython application building or just wait until unladen swallow is finished. From davea at ieee.org Thu Nov 12 11:40:12 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 11:40:12 -0500 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <4AFC3A6C.4090505@ieee.org> Santiago Romero wrote: >>> I'm trying to port (just for fun), my old Sinclair Spectrum emulator, >>> A >> > Do you mean: > > page =ddress / 16384 > index =ddress MOD 16384 > > ? > > Or, better, with: > > page =ddress >> 14 > index =ddress & 16383 > > ? > > How about page, index = divmod(address, 16384) From sromero at gmail.com Thu Nov 12 11:43:29 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 08:43:29 -0800 (PST) Subject: #define (from C) in Python Message-ID: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Is there a Python version of C's language #define statements? Example: #define ReadMem( (x) ) memory[ (x) ] Instead of using a function, when you call to ReadMem(), the code is INCLUDED, (no function is called, the "compiler" just substitues the ReadMem( expression ) with memory[ (expression) ] . I want to avoid function calls to speed up a program by sacrifizing the resulting size ... Is that possible? From sromero at gmail.com Thu Nov 12 11:44:45 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 08:44:45 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: > How about > ? ? page, index = divmod(address, 16384) Surely, much better and faster :-) Thanks a lot. From deets at nospam.web.de Thu Nov 12 11:45:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 17:45:15 +0100 Subject: #define (from C) in Python In-Reply-To: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <7m2scsF3gfnc5U1@mid.uni-berlin.de> Santiago Romero schrieb: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) memory[ (x) ] > > Instead of using a function, when you call to ReadMem(), the code is > INCLUDED, (no function is called, the "compiler" just substitues the > ReadMem( expression ) with memory[ (expression) ] . > > I want to avoid function calls to speed up a program by sacrifizing > the resulting size ... > > Is that possible? Not without taking the extra step of a ... preprocessor. As C does. Diez From michele.simionato at gmail.com Thu Nov 12 11:53:26 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 12 Nov 2009 08:53:26 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <592ed6b8-9c6b-4fad-ae75-693068033ae8@k17g2000yqh.googlegroups.com> On Nov 12, 5:43?pm, Santiago Romero wrote: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) ? ?memory[ (x) ] > > ?Instead of using a function, when you call to ReadMem(), the code is > INCLUDED, (no function is called, the "compiler" just substitues the > ReadMem( expression ) with memory[ (expression) ] . > > ?I want to avoid function calls to speed up a program by sacrifizing > the resulting size ... > > ?Is that possible? Python is a slow language and people usually do not even think of such micro-optimizations. From naughtysriram at gmail.com Thu Nov 12 12:05:06 2009 From: naughtysriram at gmail.com (Sriram Srinivasan) Date: Thu, 12 Nov 2009 09:05:06 -0800 (PST) Subject: standard libraries don't behave like standard 'libraries' References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Message-ID: > So all libraries written have to use the common subset, which - unless > things are *removed*, which with python3 actually happened - is always > the oldest interpreter. And if a feature goes away, they have to be > rewritten with the then common subset. you see that's the problem with py3. instead of slowly removing the features one by one till the end they made a jump. the problem is not with the jump but with other libraries/packages that depend on py2. what i felt was if the new version was available as soon as it is into the stream, developers/users try to use them and get accustomed. now they follow this. they have frozen py3 for may be 2-3 years so ppl would move slowly to py2.6 ,2.7, 2.8... most. also the corporate companies are the most influential. also a point to note: if new updates keep on coming (for eg. daily antivirus update) developers tend to accept and move on *easily*. i am not an expert in programming/interpreter design/library writing/ packaging. i just wanted the standard library *too* to be pluggable, not just the applications based on it. i am not even experienced in python to make bold accusations so all i can say is 'how it would be if?' and i always stick to one thing 'why not?'. > In other words: as a library writer, I can't use shiny, new & better > features, I'm stuck with the old stuff, and whenever the interpreter > evolves I have to rewrite even the old ones. Not appealing. Why develop > the interpreter at all then? if you are app developer you needn't rewrite anything. that is the main point here! just specifying the interpreter and library version is enough every thing has to work like magic. as the previous library&interpreter wont be removed (unless and until it is your will) u can use them. thats how everybody would like it to be. as for a library writer is concerned: as you say it depends on certain things like other libraries,interpreter,etc. but i would like to say that change is inevitable. if some core developer has to change something he might change. and if you have to update your library you have to. this applies to the interpreter too. what python now does is make every update work with the minimal set (giving minimal backward compatibility) plus the new features too. which is exactly the right thing. what i wanted is the users have to be aware now and then when of the modification, deletion, addition stuff not in every release as in py3k. then the whole backward incompatibility issue would be *dissolved* or what i mean is *diffused* and ppl dont even know that they have switched over to a very new thing. > In other words: the problem is solved by somehow solving the problem - > but not by a concrete solution you propose? as i told before i neither know the problem nor the solution. i just wrote my ideas/imagination down > PyPy is cool, but by far not advanced enough to replace external, > C-based libraries such as NUMPY and PyQt and whatnot. > > I don't say that the current situation is by any means ideal. There is a > lot to be said about package creation, distribution, installation, > removal, dependency handling, and even system-packaging-integration if > one likes. > > You IMHO just add another layer of complexity on top of it, without > proposing solutions to any of the layers in between, nor your new one - > namely, the interpreter version agnosticism. yes you are right. python has a lot of bindings to a lot of stuff. but it is the strength and weakness. not exactly pythons weakness but with the thing on the other side. yes it may be looking complex because most of the 'standard library' system was not designed to be adhoc/add- on/pluggable from the start. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 12:12:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Nov 2009 17:12:53 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <0085c660$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 08:35:23 -0800, Joel Davis wrote: > obviously the GIL is a major reason it's so slow. No such "obviously" about it. There have been attempts to remove the GIL, and they lead to CPython becoming *slower*, not faster, for the still common case of single-core processors. And neither Jython nor IronPython have the GIL. Jython appears to scale slightly better than CPython, but for small data sets, is slower than CPython. IronPython varies greatly in performance, ranging from nearly twice as fast as CPython on some benchmarks to up to 6000 times slower! http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/ http://ironpython-urls.blogspot.com/2009/05/python-jython-and-ironpython.html Blaming CPython's supposed slowness on the GIL is superficially plausible but doesn't stand up to scrutiny. The speed of an implementation depends on many factors, and it also depends on *what you measure* -- it is sheer nonsense to talk about "the" speed of an implementation. Different tasks run at different speeds, and there is no universal benchmark. -- Steven From stefan_ml at behnel.de Thu Nov 12 12:16:02 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 12 Nov 2009 18:16:02 +0100 Subject: #define (from C) in Python In-Reply-To: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> Message-ID: <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Santiago Romero, 12.11.2009 17:43: > Is there a Python version of C's language #define statements? > > Example: > > #define ReadMem( (x) ) memory[ (x) ] Yes: ReadMem = memory.__getitem__ Stefan From fetchinson at googlemail.com Thu Nov 12 12:21:58 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 12 Nov 2009 18:21:58 +0100 Subject: ask a question about the module In-Reply-To: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> References: <8e8f48f3-63f3-409b-bb4d-633021f12e33@l2g2000yqd.googlegroups.com> Message-ID: > Could not import module "Gnuplot" - it is not installed on your > system. You need to install the Gnuplot.py package. > \easyviz\gnuplot_.py(41) : > Traceback (most recent call last): > File "E:\study\python\commodity modle 10.23.py", line 3, in > import multipleloop as mp > File "E:\study\python\multipleloop.py", line 81, in > from scitools.misc import str2obj > File "C:\Python26\lib\site-packages\scitools\__init__.py", line 67, > in > import sys, std > File "C:\Python26\lib\site-packages\scitools\std.py", line 26, in > > from scitools.easyviz import * > File "C:\Python26\lib\site-packages\scitools\easyviz\__init__.py", > line 1819, in > exec(cmd) > File "", line 1, in > File "C:\Python26\lib\site-packages\scitools\easyviz\gnuplot_.py", > line 42, in > import Gnuplot > ImportError: No module named Gnuplot > > > the above is the hint from python window, I know Gnuplot is a software > and it can help us to make graphs, however, after I download Gnuplot > and run it, the problem still exist. Is there any expert can help me > solve this problem? > Thank you very much! Did you also install the python bindings for gnuplot? If not, you can get it from http://gnuplot-py.sourceforge.net/ HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From sromero at gmail.com Thu Nov 12 12:23:23 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:23:23 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On 12 nov, 18:16, Stefan Behnel wrote: > Santiago Romero, 12.11.2009 17:43: > > > Is there a Python version of C's language #define statements? > > > Example: > > > #define ReadMem( (x) ) ? ?memory[ (x) ] > > Yes: > > ? ? ? ? ReadMem = memory.__getitem__ > > Stefan Well, In the above concrete example, that would work, but I was talking for multiple code lines, like: #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ r_oph = Z80ReadMem(r_PC); r_PC++; \ reg = r_op #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ r_oph = Z80ReadMem(r_PC); r_PC++; \ r_tmpl = Z80ReadMem(r_op); \ r_tmph = Z80ReadMem((r_op)+1); \ dreg=r_tmp #define STORE_nn_rr(dreg) \ r_opl = Z80ReadMem(r_PC); r_PC++;\ r_oph = Z80ReadMem(r_PC); r_PC++; \ r_tmp = dreg; \ Z80WriteMem((r_op),r_tmpl, regs); \ Z80WriteMem((r_op+1),r_tmph, regs) But it seems that is not possible :-( From alfps at start.no Thu Nov 12 12:32:28 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 18:32:28 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: <0085c660$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 12 Nov 2009 08:35:23 -0800, Joel Davis wrote: > >> obviously the GIL is a major reason it's so slow. http://en.wikipedia.org/wiki/Global_Interpreter_Lock Uh oh... > No such "obviously" about it. > > There have been attempts to remove the GIL, and they lead to CPython > becoming *slower*, not faster, for the still common case of single-core > processors. > > And neither Jython nor IronPython have the GIL. Jython appears to scale > slightly better than CPython, but for small data sets, is slower than > CPython. IronPython varies greatly in performance, ranging from nearly > twice as fast as CPython on some benchmarks to up to 6000 times slower! > > http://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/ > > http://ironpython-urls.blogspot.com/2009/05/python-jython-and-ironpython.html > > > Blaming CPython's supposed slowness Hm, this seems religious. Of course Python is slow: if you want speed, pay for it by complexity. It so happens that I think CPython could have been significantly faster, but (1) doing that would amount to creating a new implementation, say, C++Python , and (2) what for, really?, since CPU-intensive things should be offloaded to other language code anyway. > on the GIL is superficially plausible > but doesn't stand up to scrutiny. The speed of an implementation depends > on many factors, and it also depends on *what you measure* -- it is sheer > nonsense to talk about "the" speed of an implementation. Different tasks > run at different speeds, and there is no universal benchmark. This also seems religious. It's like in Norway it became illegal to market lemon soda, since umpteen years ago it's soda with lemon flavoring. This has to do with the *origin* of the citric acid, whether natural or chemist's concoction, no matter that it's the same chemical. So, some people think that it's wrong to talk about interpreted languages, hey, it should be a "language designed for interpretation", or better yet, "dynamic language", or bestest, "language with dynamic flavor". And slow language, oh no, should be "language whose current implementations are perceived as somewhat slow by some (well, all) people", but of course, that's just silly. Cheers, - Alf From james at agentultra.com Thu Nov 12 12:33:36 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 12 Nov 2009 12:33:36 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <87my2r7imn.fsf@agentultra.com> mcherm writes: > On Nov 11, 7:38?pm, Vincent Manis wrote: >> 1. The statement `Python is slow' doesn't make any sense to me. >> Python is a programming language; it is implementations that have >> speed or lack thereof. > [...] >> 2. A skilled programmer could build an implementation that compiled >> Python code into Common Lisp or Scheme code, and then used a >> high-performance Common Lisp compiler... > > I think you have a fundamental misunderstanding of the reasons why > Python is > slow. Most of the slowness does NOT come from poor implementations: > the CPython > implementation is extremely well-optimized; the Jython and Iron Python > implementations use best-in-the-world JIT runtimes. Most of the speed > issues > come from fundamental features of the LANGUAGE itself, mostly ways in > which > it is highly dynamic. > > In Python, a piece of code like this: > len(x) > needs to watch out for the following: > * Perhaps x is a list OR > * Perhaps x is a dict OR > * Perhaps x is a user-defined type that declares a __len__ > method OR > * Perhaps a superclass of x declares __len__ OR > * Perhaps we are running the built-in len() function OR > * Perhaps there is a global variable 'len' which shadows the > built-in OR > * Perhaps there is a local variable 'len' which shadows the > built-in OR > * Perhaps someone has modified __builtins__ > > In Python it is possible for other code, outside your module to go in > and > modify or replace some methods from your module (a feature called > "monkey-patching" which is SOMETIMES useful for certain kinds of > testing). > There are just so many things that can be dynamic (even if 99% of the > time > they are NOT dynamic) that there is very little that the compiler can > assume. > > So whether you implement it in C, compile to CLR bytecode, or > translate into > Lisp, the computer is still going to have to to a whole bunch of > lookups to > make certain that there isn't some monkey business going on, rather > than > simply reading a single memory location that contains the length of > the list. > Brett Cannon's thesis is an example: he attempted desperate measures > to > perform some inferences that would allow performing these > optimizations > safely and, although a few of them could work in special cases, most > of the > hoped-for improvements were impossible because of the dynamic nature > of the > language. > > I have seen a number of attempts to address this, either by placing > some > restrictions on the dynamic nature of the code (but that would change > the > nature of the Python language) or by having some sort of a JIT > optimize the > common path where we don't monkey around. Unladen Swallow and PyPy are > two > such efforts that I find particularly promising. > > But it isn't NEARLY as simple as you make it out to be. > > -- Michael Chermside You might be right for the wrong reasons in a way. Python isn't slow because it's a dynamic language. All the lookups you're citing are highly optimized hash lookups. It executes really fast. The OP is talking about scale. Some people say Python is slow at a certain scale. I say that's about true for any language. Large amounts of IO is a tough problem. Where Python might get hit *as a language* is that the Python programmer has to drop into C to implement optimized data-structures for dealing with the kind of IO that would slow down the Python interpreter. That's why we have numpy, scipy, etc. The special cases it takes to solve problems with custom types wasn't special enough to alter the language. Scale is a special case believe it or not. As an implementation though, the sky really is the limit and Python is only getting started. Give it another 40 years and it'll probably realize that it's just another Lisp. ;) From stefan_ml at behnel.de Thu Nov 12 12:34:09 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 12 Nov 2009 18:34:09 +0100 Subject: #define (from C) in Python In-Reply-To: References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> Santiago Romero, 12.11.2009 18:23: > #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) > > #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > reg = r_op > > #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) > > #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmpl = Z80ReadMem(r_op); \ > r_tmph = Z80ReadMem((r_op)+1); \ > dreg=r_tmp > > #define STORE_nn_rr(dreg) \ > r_opl = Z80ReadMem(r_PC); r_PC++;\ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmp = dreg; \ > Z80WriteMem((r_op),r_tmpl, regs); \ > Z80WriteMem((r_op+1),r_tmph, regs) > > But it seems that is not possible :-( As Michele said, this is a micro optimisation, likely premature. A function is usually good enough for this. If you need more speed (and you seem to be targeting direct memory access or something like that), take a look at Cython. Stefan From sromero at gmail.com Thu Nov 12 12:41:47 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:41:47 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <6ebe56b4-e43e-44bb-b5d3-12b7acd40fbc@u7g2000yqm.googlegroups.com> > You can do clever memory slicing like this with numpy. ?For instance: > > breg = numpy.zeros((16,),numpy.uint8) > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > This causes breg and wreg to share the same 16 bytes of memory. ?You > can define constants to access specific registers: What I'm doing wrong? [sromero at compiler:~]$ cat test.py #!/usr/bin/python import numpy # Register array breg = numpy.zeros((16,),numpy.uint8) wreg = numpy.ndarray((8,), numpy.uint16, breg ) reg_A = 1 reg_F = 2 reg_AF = 1 reg_B = 3 reg_C = 4 reg_BC = 3 breg[reg_B] = 5 breg[reg_C] = 10 print breg[reg_B] print breg[reg_C] print wreg[reg_BC] [sromero at compiler:~]$ python test.py 5 10 0 ? From warpcat at sbcglobal.net Thu Nov 12 12:49:53 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 09:49:53 -0800 (PST) Subject: How can a module know the module that imported it? References: <008592ec$0$26916$c3e8da3@news.astraweb.com> Message-ID: <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> so: # moduleA.py import moduleB # moduleB.py import sys stuff = sys._getframe(1).f_locals print stuff Prints: {'__builtins__': , '__file__': 'C:\\Documents and Settings\\\\My Documents\ \python\\moduleA.py', '__name__': '__main__', '__doc__': None} Looks like you could query stuff['__file__'] to pull what you're after. ? From sromero at gmail.com Thu Nov 12 12:51:50 2009 From: sromero at gmail.com (Santiago Romero) Date: Thu, 12 Nov 2009 09:51:50 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <6ebe56b4-e43e-44bb-b5d3-12b7acd40fbc@u7g2000yqm.googlegroups.com> Message-ID: <4b1370fa-373c-463a-8f50-3e8c3411dc62@g23g2000yqh.googlegroups.com> Oops, numpy arrays start with index=0 :-) From benjamin.kaplan at case.edu Thu Nov 12 13:05:45 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 13:05:45 -0500 Subject: standard libraries don't behave like standard 'libraries' In-Reply-To: References: <7m27u5F3dvpo4U1@mid.uni-berlin.de> <1873f011-aecf-48ef-84ff-6cf1829679cf@t2g2000yqn.googlegroups.com> <7m2a7fF3g36nnU1@mid.uni-berlin.de> <88d7d2dd-0bd7-4c7f-b52b-d7e4b04b83fe@c3g2000yqd.googlegroups.com> <7m2fl4F3g3usmU1@mid.uni-berlin.de> <20bdcd67-fb3e-452f-bcd5-642d3226e54b@m16g2000yqc.googlegroups.com> <7m2oqfF3fvh4jU1@mid.uni-berlin.de> Message-ID: On Thu, Nov 12, 2009 at 12:05 PM, Sriram Srinivasan wrote: >> So all libraries written have to use the common subset, which - unless >> things are *removed*, which with python3 actually happened - is always >> the oldest interpreter. And if a feature goes away, they have to be >> rewritten with the then common subset. > > you see that's the problem with py3. instead of slowly removing the > features one by one till the end they made a jump. the problem is not > with the jump but with other libraries/packages that depend on py2. > what i felt was if the new version was available as soon as it is into > the stream, developers/users try to use them and get accustomed. now > they follow this. they have frozen py3 for may be 2-3 years so ppl > would move slowly to py2.6 ,2.7, 2.8... most. also the corporate > companies are the most influential. > The freeze was put in place so that the other implementations of Python, like Jython and IronPython, have a chance to catch up with the reference CPython implementation. It's not so people will slowly move up. FWIW, people knew for years what was going to change in Python 3. > also a point to note: if new updates keep on coming (for eg. daily > antivirus update) developers tend to accept and move on *easily*. > > i am not an expert in programming/interpreter design/library writing/ > packaging. i just wanted the standard library *too* to be pluggable, > not just the applications based on it. > i am not even experienced in python to make bold accusations so all i > can say is 'how it would be if?' and i always stick to one thing 'why > not?'. > >> In other words: as a library writer, I can't use shiny, new & better >> features, I'm stuck with the old stuff, and whenever the interpreter >> evolves I have to rewrite even the old ones. Not appealing. Why develop >> the interpreter at all then? > > if you are app developer you needn't rewrite anything. that is the > main point here! just specifying the interpreter and library version > is enough every thing has to work like magic. as the previous > library&interpreter wont be removed (unless and until it is your will) > u can use them. thats how everybody would like it to be. > So you're saying that we'd have multiple versions of the interpreter running at the same time, but they all have access to the same memory. That wouldn't just require a change to Python, that would require a change to the way all modern operating systems work. > as for a library writer is concerned: as you say it depends on certain > things like other libraries,interpreter,etc. but i would like to say > that change is inevitable. if some core developer has to change > something he might change. and if you have to update your library you > have to. this applies to the interpreter too. what python now does is > make every update work with the minimal set (giving minimal backward > compatibility) plus the new features too. which is exactly the right > thing. what i wanted is the users have to be aware now and then when > of the modification, deletion, addition stuff not in every release as > in py3k. then the whole backward incompatibility issue would be > *dissolved* or what i mean is *diffused* and ppl dont even know that > they have switched over to a very new thing. > > Actually, that's not entirely true. New versions to break things Consider these statements as = ['a','a','a'] with = [1,2,3] It's legal in Python 2.4 or earlier, a warning in Python 2.5, but illegal in Python 2.6 > >> In other words: the problem is solved by somehow solving the problem - >> but not by a concrete solution you propose? > > as i told before i neither know the problem nor the solution. i just > wrote my ideas/imagination down > >> PyPy is cool, but by far not advanced enough to replace external, >> C-based libraries such as NUMPY and PyQt and whatnot. >> >> I don't say that the current situation is by any means ideal. There is a >> lot to be said about package creation, distribution, installation, >> removal, dependency handling, and even system-packaging-integration if >> one likes. >> >> You IMHO just add another layer of complexity on top of it, without >> proposing solutions to any of the layers in between, nor your new one - >> namely, the interpreter version agnosticism. > > yes you are right. python has a lot of bindings to a lot of stuff. but > it is the strength and weakness. not exactly pythons weakness but with > the thing on the other side. yes it may be looking complex because > most of the 'standard library' system was not designed to be adhoc/add- > on/pluggable from the start. It is pluggable. The standard library consists of Python modules like any other. 2.6's multiprocessing module is just an incorporation of the pyprocessing module for instance. The point of the standard library is that you can count on it being there, and you can count on it having certain features, given your interpreter version. You can also be sure that anytime a new version of Python comes out, those modules will be compatible. > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Thu Nov 12 13:10:53 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 Nov 2009 10:10:53 -0800 Subject: How can a module know the module that imported it? In-Reply-To: <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> References: <008592ec$0$26916$c3e8da3@news.astraweb.com> <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> Message-ID: <4AFC4FAD.50307@stoneleaf.us> AK Eric wrote: > so: > > # moduleA.py > import moduleB > > # moduleB.py > import sys > stuff = sys._getframe(1).f_locals > print stuff > > Prints: > > {'__builtins__': , > '__file__': 'C:\\Documents and Settings\\\\My Documents\ > \python\\moduleA.py', > '__name__': '__main__', > '__doc__': None} > > Looks like you could query stuff['__file__'] to pull what you're > after. > ? The leading _ in _getframe indicates a private function to sys (aka implementation detail); in other words, something that could easily change between one Python version and the next. I'm using the inspect module (for the moment, at least), and my question boils down to: Will it work correctly on all versions of Python in the 2.x range? 3.x range? ~Ethan~ From warpcat at sbcglobal.net Thu Nov 12 13:35:55 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 10:35:55 -0800 (PST) Subject: How can a module know the module that imported it? References: <008592ec$0$26916$c3e8da3@news.astraweb.com> <341aed9f-2d2a-458c-b930-1787ec76c0fd@13g2000prl.googlegroups.com> Message-ID: On Nov 12, 10:10?am, Ethan Furman wrote: > AK Eric wrote: > > so: > > > # moduleA.py > > import moduleB > > > # moduleB.py > > import sys > > stuff = sys._getframe(1).f_locals > > print stuff > > > Prints: > > > {'__builtins__': , > > '__file__': 'C:\\Documents and Settings\\\\My Documents\ > > \python\\moduleA.py', > > '__name__': '__main__', > > '__doc__': None} > > > Looks like you could query stuff['__file__'] to pull what you're > > after. > > ? > > The leading _ in _getframe indicates a private function to sys (aka > implementation detail); in other words, something that could easily > change between one Python version and the next. > > I'm using the inspect module (for the moment, at least), and my question > boils down to: ?Will it work correctly on all versions of Python in the > 2.x range? ?3.x range? > Good point, I totally missed that. Someone had passed that solution to me at one point and I was so excited I kind of looked that over :P From mark.kecko at gmail.com Thu Nov 12 13:39:33 2009 From: mark.kecko at gmail.com (scoopseven) Date: Thu, 12 Nov 2009 10:39:33 -0800 (PST) Subject: QuerySets in Dictionaries Message-ID: I need to create a dictionary of querysets. I have code that looks like: query1 = Myobject.objects.filter(status=1) query2 = Myobject.objects.filter(status=2) query3 = Myobject.objects.filter(status=3) d={} d['a'] = query1 d['b'] = query2 d['c'] = query3 Is there a way to do this that I'm missing? Thanks. From python.list at tim.thechases.com Thu Nov 12 13:58:08 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 12 Nov 2009 12:58:08 -0600 Subject: (OT) Recommend FTP Client In-Reply-To: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Message-ID: <4AFC5AC0.9000900@tim.thechases.com> > Someone on this list just recommended I find an ftp client that enables me > to change line endings. He indicated that it would be easy, but googling I > haven't been able to find one. I would prefer a free client, but whatever. > Please send me a recommendation. How about the command line client that comes with every modern OS? Just use the ASCII (default) and BIN commands to switch between line-ending translation. -tkc From rami.chowdhury at gmail.com Thu Nov 12 13:58:49 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 10:58:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach wrote: > > This also seems religious. It's like in Norway it became illegal to > market lemon soda, since umpteen years ago it's soda with lemon > flavoring. This has to do with the *origin* of the citric acid, whether > natural or chemist's concoction, no matter that it's the same chemical. > So, some people think that it's wrong to talk about interpreted > languages, hey, it should be a "language designed for interpretation", > or better yet, "dynamic language", or bestest, "language with dynamic > flavor". And slow language, oh no, should be "language whose current > implementations are perceived as somewhat slow by some (well, all) > people", but of course, that's just silly. Perhaps I'm missing the point of what you're saying but I don't see why you're conflating interpreted and dynamic here? Javascript is unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically JIT it. Does that make Javascript non-dynamic, because it's compiled? What about Common Lisp, which is a compiled language when it's run with CMUCL or SBCL? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From bigboss1964 at gmail.com Thu Nov 12 14:01:48 2009 From: bigboss1964 at gmail.com (TerryP) Date: Thu, 12 Nov 2009 11:01:48 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> If it's such a big hairy deal, just recompile a copy of the C Pre Processor to use something other then #, and hook it up to your python scripts in a pipe line from a shell wrapper. Personally, I'd rather have Lisps lambda or perls sub then Cs preprocessor, and even in those cases, Python suffices perfectly fine ;). From simon at brunningonline.net Thu Nov 12 14:06:33 2009 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 12 Nov 2009 19:06:33 +0000 Subject: QuerySets in Dictionaries In-Reply-To: References: Message-ID: <8c7f10c60911121106l58ff77fbpd88f44b42e15439b@mail.gmail.com> 2009/11/12 scoopseven : > I need to create a dictionary of querysets. ?I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? Untested: wanted = (('a', 1), ('b', 2), ('c', 2)) d = dict((key, Myobject.objects.filter(status=number)) for (key, number) in wanted) -- Cheers, Simon B. From deets at nospam.web.de Thu Nov 12 14:08:26 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 12 Nov 2009 20:08:26 +0100 Subject: QuerySets in Dictionaries In-Reply-To: References: Message-ID: <7m34p9F3df2blU1@mid.uni-berlin.de> scoopseven schrieb: > I need to create a dictionary of querysets. I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? d = dict(a=Myobject.objects.filter(status=1), b=Myobject.objects.filter(status=2), c=Myobject.objects.filter(status=3)) Diez From mrholtsr at sbcglobal.net Thu Nov 12 14:11:45 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Thu, 12 Nov 2009 14:11:45 -0500 Subject: Computing the 1000th prime Message-ID: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> I have an assigment to find the 1000th. prime using python. What's wrong with the following code: PrimeCount = 0 PrimeCandidate = 1 while PrimeCount < 2000: IsPrime = True PrimeCandidate = PrimeCandidate + 2 for x in range(2, PrimeCandidate): if PrimeCandidate % x == 0: ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x print PrimeCandidate IsPrime = False break if IsPrime: PrimeCount = PrimeCount + 1 PrimeCandidate = PrimeCandidate + 2 print PrimeCandidate Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Nov 12 14:17:16 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:17:16 +0000 Subject: regex remove closest tag In-Reply-To: References: Message-ID: <4AFC5F3C.6010302@mrabarnett.plus.com> S.Selvam wrote: > Hi all, > > > 1) I need to remove the tags which is just before the keyword(i.e > some_text2 ) excluding others. > > 2) input string may or may not contain tags. > > 3) Sample input: > > inputstr = """start some_text1 href="">some_text2 keyword anything""" > > 4) I came up with the following regex, > > > p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) > s=p.search(inputstr) > but second group matches both tags,while i need to match the > recent one only. > > I would like to get your suggestions. > > Note: > > If i leave group('good1') as greedy, then it matches both the tag. > ".*?" can match any number of any character, so it can match any intervening "" tags. Try "[^<]*?" instead. From alfps at start.no Thu Nov 12 14:24:18 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 20:24:18 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach > wrote: >> >> This also seems religious. It's like in Norway it became illegal to >> market lemon soda, since umpteen years ago it's soda with lemon >> flavoring. This has to do with the *origin* of the citric acid, >> whether natural or chemist's concoction, no matter that it's the same >> chemical. So, some people think that it's wrong to talk about >> interpreted languages, hey, it should be a "language designed for >> interpretation", or better yet, "dynamic language", or bestest, >> "language with dynamic flavor". And slow language, oh no, should be >> "language whose current implementations are perceived as somewhat slow >> by some (well, all) people", but of course, that's just silly. > > Perhaps I'm missing the point of what you're saying but I don't see why > you're conflating interpreted and dynamic here? Javascript is unarguably > a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all typically > JIT it. Does that make Javascript non-dynamic, because it's compiled? > What about Common Lisp, which is a compiled language when it's run with > CMUCL or SBCL? Yeah, you missed it. Blurring and coloring and downright hiding reality by insisting on misleading but apparently more precise terminology for some vague concept is a popular sport, and chiding others for using more practical and real-world oriented terms, can be effective in politics and some other arenas. But in a technical context it's silly. Or dumb. Whatever. E.g. you'll find it impossible to define interpretation rigorously in the sense that you're apparently thinking of. It's not that kind of term or concept. The nearest you can get is in a different direction, something like "a program whose actions are determined by data external to the program (+ x qualifications and weasel words)", which works in-practice, conceptually, but try that on as a rigorous definition and you'll see that when you get formal about it then it's completely meaningless: either anything qualifies or nothing qualifies. You'll also find it impossible to rigorously define "dynamic language" in a general way so that that definition excludes C++. So, to anyone who understands what one is talking about, "interpreted", or e.g. "slow language" (as was the case here), conveys the essence. And to anyone who doesn't understand it trying to be more precise is an exercise in futility and pure silliness -- except for the purpose of misleading. Cheers & hth., - Alf From davea at ieee.org Thu Nov 12 14:26:50 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 14:26:50 -0500 Subject: (OT) Recommend FTP Client In-Reply-To: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> Message-ID: <4AFC617A.2070201@ieee.org> Victor Subervi wrote: > Hi; > Someone on this list just recommended I find an ftp client that enables me > to change line endings. He indicated that it would be easy, but googling I > haven't been able to find one. I would prefer a free client, but whatever. > Please send me a recommendation. > TIA, > Victor > > Try http://fireftp.mozdev.org/ fireftp is an (free) addon to Firefox. If you're already using Firefox, it's painless to download it, and easy to use. You can set up account(s) complete with passwords and default directories, and then transfer individual files or directory trees full just by selecting and pressing the Arrow icons (one for upload, one for download). You can sort by timestamp, so it's not hard to just transfer new stuff. One of the Tools->Options tabs is "Downloads/Uploads". First box looks like: When transferring files use: o - Automatic mode o - Binary mode o - ASCII mode According to the help, Automatic mode is very useful for CGI scripts, where you specify which extensions will get the line-endings converted. http://fireftp.mozdev.org/help.html But please understand: I personally use Binary mode in FireFTP because I'm a control freak. Python can handle Unix line-endings just fine, so any files that are bound for CGI I just edit in that mode in the first place. DaveA From python at mrabarnett.plus.com Thu Nov 12 14:30:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:30:01 +0000 Subject: python with echo In-Reply-To: References: Message-ID: <4AFC6239.40905@mrabarnett.plus.com> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > >> List, >> >> I have a question of python using echo. >> >> POWER = 14 >> return_value = os.system('echo 14 > >> /sys/class/net/wlan1/device/tx_power') >> >> can assign 14 to tx_power >> >> But >> return_value = os.system('echo $POWER > >> /sys/class/net/wlan1/device/tx_power') > > POWER = 14 doesn't create an environment variable visible to echo. It is > a Python variable. > > >>>> POWER = 14 >>>> import os >>>> return_value = os.system('echo $POWER') > >>>> return_value > 0 > > > >> return_value is 256 not 0. It cannot assign 14 to tx_power. > > > I don't understand that. Exit status codes on all systems I'm familiar > with are limited to 0 through 255. What operating system are you using? > > Assuming your system allows two-byte exit statuses, you should check the > documentation for echo and the shell to see why it is returning 256. > In some OSs the exit status consists of 2 fields, one being the child process's exit status and the other being supplied by the OS. The reason is simple. What if the child process terminated abnormally? You'd like an exit status to tell you that, but you wouldn't want it to be confused with the child process's own exit status, assuming that it had terminated normally. > Have you tried this in the shell, without involving Python? I will almost > guarantee that Python is irrelevant to the problem. > From tjreedy at udel.edu Thu Nov 12 14:31:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2009 14:31:41 -0500 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > graphics may be off-putting to some readers because it is associated > with children's learning. > > What do you think? I just started using the module for simple plots. I am not a child. You cannot please everyone. From warpcat at sbcglobal.net Thu Nov 12 14:36:39 2009 From: warpcat at sbcglobal.net (AK Eric) Date: Thu, 12 Nov 2009 11:36:39 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: On Nov 12, 11:31?am, Terry Reedy wrote: > Alf P. Steinbach wrote: > > One reaction to >http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > > graphics may be off-putting to some readers because it is associated > > with children's learning. > > > What do you think? > > I just started using the module for simple plots. > I am not a child. > You cannot please everyone. I used Turtle back on the Apple in the early 80's... so I personally have very positive feelings towards it ;) To each their own eh? From rami.chowdhury at gmail.com Thu Nov 12 14:42:05 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 11:42:05 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach wrote: > * Rami Chowdhury: >> On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach >> wrote: >>> >>> This also seems religious. It's like in Norway it became illegal to >>> market lemon soda, since umpteen years ago it's soda with lemon >>> flavoring. This has to do with the *origin* of the citric acid, >>> whether natural or chemist's concoction, no matter that it's the same >>> chemical. So, some people think that it's wrong to talk about >>> interpreted languages, hey, it should be a "language designed for >>> interpretation", or better yet, "dynamic language", or bestest, >>> "language with dynamic flavor". And slow language, oh no, should be >>> "language whose current implementations are perceived as somewhat slow >>> by some (well, all) people", but of course, that's just silly. >> Perhaps I'm missing the point of what you're saying but I don't see >> why you're conflating interpreted and dynamic here? Javascript is >> unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 all >> typically JIT it. Does that make Javascript non-dynamic, because it's >> compiled? What about Common Lisp, which is a compiled language when >> it's run with CMUCL or SBCL? > > Yeah, you missed it. > > Blurring and coloring and downright hiding reality by insisting on > misleading but apparently more precise terminology for some vague > concept is a popular sport, and chiding others for using more practical > and real-world oriented terms, can be effective in politics and some > other arenas. > > But in a technical context it's silly. Or dumb. Whatever. > > E.g. you'll find it impossible to define interpretation rigorously in > the sense that you're apparently thinking of. Well, sure. Can you explain, then, what sense you meant it in? > You'll also find it impossible to rigorously define "dynamic language" > in a general way so that that definition excludes C++. Or, for that matter, suitably clever assembler. I'm not arguing with you there. > So, to anyone who understands what one is talking about, "interpreted", > or e.g. "slow language" (as was the case here), conveys the essence. Not when the context isn't clear, it doesn't. > And to anyone who doesn't understand it trying to be more precise is an > exercise in futility and pure silliness -- except for the purpose of > misleading. Or for the purpose of greater understanding, surely - and isn't that the point? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From python at mrabarnett.plus.com Thu Nov 12 14:43:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Nov 2009 19:43:38 +0000 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: <4AFC656A.7010505@mrabarnett.plus.com> Ray Holt wrote: > I have an assigment to find the 1000th. prime using python. What's wrong > with the following code: > PrimeCount = 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > IsPrime = True > PrimeCandidate = PrimeCandidate + 2 > for x in range(2, PrimeCandidate): > if PrimeCandidate % x == 0: > ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x > print PrimeCandidate > IsPrime = False > break > if IsPrime: > PrimeCount = PrimeCount + 1 > PrimeCandidate = PrimeCandidate + 2 > print PrimeCandidate > Thanks > The indentation starting from the second 'if'. From victorsubervi at gmail.com Thu Nov 12 14:48:35 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 12 Nov 2009 14:48:35 -0500 Subject: (OT) Recommend FTP Client In-Reply-To: <4AFC617A.2070201@ieee.org> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> <4AFC617A.2070201@ieee.org> Message-ID: <4dc0cfea0911121148m2f10cd3tc09f3db58958d0ce@mail.gmail.com> Thanks. V On Thu, Nov 12, 2009 at 2:26 PM, Dave Angel wrote: > > > Victor Subervi wrote: > >> Hi; >> Someone on this list just recommended I find an ftp client that enables me >> to change line endings. He indicated that it would be easy, but googling I >> haven't been able to find one. I would prefer a free client, but whatever. >> Please send me a recommendation. >> TIA, >> Victor >> >> >> > Try http://fireftp.mozdev.org/ > > fireftp is an (free) addon to Firefox. If you're already using Firefox, > it's painless to download it, and easy to use. You can set up account(s) > complete with passwords and default directories, and then transfer > individual files or directory trees full just by selecting and pressing the > Arrow icons (one for upload, one for download). You can sort by timestamp, > so it's not hard to just transfer new stuff. > > > One of the Tools->Options tabs is "Downloads/Uploads". First box looks > like: > > When transferring files use: > o - Automatic mode > o - Binary mode > o - ASCII mode > > > According to the help, Automatic mode is very useful for CGI scripts, where > you specify which extensions will get the line-endings converted. > http://fireftp.mozdev.org/help.html > > But please understand: I personally use Binary mode in FireFTP because I'm > a control freak. Python can handle Unix line-endings just fine, so any > files that are bound for CGI I just edit in that mode in the first place. > > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Thu Nov 12 14:52:18 2009 From: rantingrick at gmail.com (rantingrick) Date: Thu, 12 Nov 2009 11:52:18 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) Message-ID: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Hello, Currently i am using 2.6 on Windows and need to start writing code in 3.0. I cannot leave 2.x yet because 3rd party modules are still not converted. So i want to install 3.0 without disturbing my current Python2.x. What i'm afraid of is that some SYSVARIABLE will get changed to Python3.0 and when i double click a Python script it will try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts from the command line... > python3.x myscript.py So how do i do this? Is my fear unfounded? Thanks From alfps at start.no Thu Nov 12 15:02:11 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 12 Nov 2009 21:02:11 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 11:24:18 -0800, Alf P. Steinbach > wrote: > >> * Rami Chowdhury: >>> On Thu, 12 Nov 2009 09:32:28 -0800, Alf P. Steinbach >>> wrote: >>>> >>>> This also seems religious. It's like in Norway it became illegal to >>>> market lemon soda, since umpteen years ago it's soda with lemon >>>> flavoring. This has to do with the *origin* of the citric acid, >>>> whether natural or chemist's concoction, no matter that it's the >>>> same chemical. So, some people think that it's wrong to talk about >>>> interpreted languages, hey, it should be a "language designed for >>>> interpretation", or better yet, "dynamic language", or bestest, >>>> "language with dynamic flavor". And slow language, oh no, should be >>>> "language whose current implementations are perceived as somewhat >>>> slow by some (well, all) people", but of course, that's just silly. >>> Perhaps I'm missing the point of what you're saying but I don't see >>> why you're conflating interpreted and dynamic here? Javascript is >>> unarguably a dynamic language, yet Chrome / Safari 4 / Firefox 3.5 >>> all typically JIT it. Does that make Javascript non-dynamic, because >>> it's compiled? What about Common Lisp, which is a compiled language >>> when it's run with CMUCL or SBCL? >> >> Yeah, you missed it. >> >> Blurring and coloring and downright hiding reality by insisting on >> misleading but apparently more precise terminology for some vague >> concept is a popular sport, and chiding others for using more >> practical and real-world oriented terms, can be effective in politics >> and some other arenas. >> > >> But in a technical context it's silly. Or dumb. Whatever. >> >> E.g. you'll find it impossible to define interpretation rigorously in >> the sense that you're apparently thinking of. > > Well, sure. Can you explain, then, what sense you meant it in? I think that was in the part you *snipped* here. Just fill in the mentioned qualifications and weasel words. And considering that a routine might be an intepreter of data produced elsewhere in program, needs some fixing... >> You'll also find it impossible to rigorously define "dynamic language" >> in a general way so that that definition excludes C++. > > Or, for that matter, suitably clever assembler. I'm not arguing with you > there. > >> So, to anyone who understands what one is talking about, >> "interpreted", or e.g. "slow language" (as was the case here), conveys >> the essence. > > Not when the context isn't clear, it doesn't. > >> And to anyone who doesn't understand it trying to be more precise is >> an exercise in futility and pure silliness -- except for the purpose >> of misleading. > > Or for the purpose of greater understanding, surely - and isn't that the > point? I don't think that was the point. Specifically, I reacted to the statement that <>, made in response to someone upthread, in the context of Google finding CPython overall too slow. It is quite slow. ;-) Cheers, - Alf From russ.paielli at gmail.com Thu Nov 12 15:06:18 2009 From: russ.paielli at gmail.com (Russ P.) Date: Thu, 12 Nov 2009 12:06:18 -0800 (PST) Subject: Psyco on 64-bit machines Message-ID: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> I have a Python program that runs too slow for some inputs. I would like to speed it up without rewriting any code. Psyco seemed like exactly what I need, until I saw that it only works on a 32-bit architecture. I work in an environment of Sun Ultras that are all 64- bit. However, the Psyco docs say this: "Psyco does not support the 64-bit x86 architecture, unless you have a Python compiled in 32-bit compatibility mode." Would it make sense to compile Python in the 32-bit compatibility mode so I can use Psyco? What would I lose in that mode, if anything? Thanks. From benjamin.kaplan at case.edu Thu Nov 12 15:07:29 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:07:29 -0500 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: On Thursday, November 12, 2009, Ray Holt wrote: > > > > > > I have an assigment > to find the 1000th. prime using python. What's wrong with the following > code: > PrimeCount = > 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > > IsPrime = True > ??? PrimeCandidate = PrimeCandidate + > 2 > ??? for x in range(2, > PrimeCandidate): > ??????? if PrimeCandidate > % x == > 0: > ##??????????? print > PrimeCandidate, 'equals', x, '*', > PrimeCandidate/x > > print PrimeCandidate > > > IsPrime = > False > > break > ??????? if > IsPrime: > > PrimeCount = PrimeCount + > 1 > > PrimeCandidate = PrimeCandidate + > 2 > ??????? print > PrimeCandidate > Thanks > You break on the first composite number, which means you immediately exit the loop. Just let it fall through Also, a couple of things to speed in up: 1) you look at all numbers from 2 to n to check if n is a prime number. You only need to check from 2 to int(math.sqrt(n)) 2) to really speed it up, keep a list of all the prime numbers. Then you only need to check if a number is divisible by those By combining the two, you'll only use a fraction of the comparisons. For 23, you'd only loop twice (2 and 3) instead of 20 times to determine that it's prime. The difference is even more dramatic on large numbers. From benjamin.kaplan at case.edu Thu Nov 12 15:11:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:11:39 -0500 Subject: Computing the 1000th prime In-Reply-To: References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: On Thursday, November 12, 2009, Benjamin Kaplan wrote: > On Thursday, November 12, 2009, Ray Holt wrote: >> >> >> >> >> >> I have an assigment >> to find the 1000th. prime using python. What's wrong with the following >> code: >> PrimeCount = >> 0 >> PrimeCandidate = 1 >> while PrimeCount < 2000: >> >> IsPrime = True >> ??? PrimeCandidate = PrimeCandidate + >> 2 >> ??? for x in range(2, >> PrimeCandidate): >> ??????? if PrimeCandidate >> % x == >> 0: >> ##??????????? print >> PrimeCandidate, 'equals', x, '*', >> PrimeCandidate/x >> >> print PrimeCandidate >> >> >> IsPrime = >> False >> >> break >> ??????? if >> IsPrime: > > You break on the first composite number, which means you immediately > exit the loop. Just let it fall through Also, a couple of things to > speed in up: > Nevermind MRAB is right. I missed the indentation error there. I guess that's what I get for trying to evaluate code on my iPod touch instead of getting my computer out and actually seeing what it's doing. >.< > 1) you look at all numbers from 2 to n to check if n is a prime > number. You only need to check from 2 to int(math.sqrt(n)) > > 2) to really speed it up, keep a list of all the prime numbers. Then > you only need to check if a number is divisible by those > > By combining the two, you'll only use a fraction of the comparisons. > For 23, you'd only loop twice (2 and 3) instead of 20 times to > determine that it's prime. The difference is even more dramatic on > large numbers. > From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:27:31 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:27:31 +0100 Subject: New syntax for blocks In-Reply-To: <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> Message-ID: <4afc7d43$0$7712$426a74cc@news.free.fr> r a ?crit : -snip) > Just thinking out loud here...what if variable assignments could > return a value... hmmm? Not to them selfs of course but to a caller, > like an if statement... > > if a=openfile: > # do something with a Congratulations, you just reinvented one of the most infamous source of bugs in C, C++, Java, PHP, javascript and quite a few other languages. Believe it or not, but not allowing this in Python was a very deliberate design choice. Now whether it was a good choice is another troll^Mtopic !-) From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:29:02 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:29:02 +0100 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <4afc7d9e$0$7712$426a74cc@news.free.fr> Steven D'Aprano a ?crit : (snip) > Hint to would-be language designers: if you start off by claiming that a > new feature will save an indent level, when in fact it *doesn't* save an > indent level, you can save yourself from embarrassment by pressing Close > on your post instead of Send. Mouaaaaaaaa !-) Thanks Steven, you made my day (me ---> go back mouaaaaaa) From rami.chowdhury at gmail.com Thu Nov 12 15:33:05 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 12:33:05 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach wrote: > I think that was in the part you *snipped* here. Just fill in the > mentioned qualifications and weasel words. OK, sure. I don't think they're weasel words, because I find them useful, but I think I see where you're coming from. > Specifically, I reacted to the statement that < talk about "the" speed of an implementation>>, made in response to > someone upthread, in the context of Google finding CPython overall too > slow. IIRC it was "the speed of a language" that was asserted to be nonsense, wasn't it? Which IMO is fair -- a physicist friend of mine works with a C++ interpreter which is relatively sluggish, but that doesn't mean C++ is slow... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From bdesth.quelquechose at free.quelquepart.fr Thu Nov 12 15:37:48 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 12 Nov 2009 21:37:48 +0100 Subject: New syntax for blocks In-Reply-To: <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> Message-ID: <4afc7fad$0$7712$426a74cc@news.free.fr> r a ?crit : > On Nov 11, 2:37 am, Steven D'Aprano > wrote: >> On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: > >>> Yea it's called a NameError. Would it not also blow up in the current >>> state of syntax usage? >> No. >> >>> if var: >>> print 'var' >>> Traceback (most recent call last): >>> File "", line 1, in >>> if var: >>> NameError: name 'var' is not defined >> You missed a line: >> >> var = range(N) >> if var: > > Oh i get it now! If i assign a valid value to a variable the variable > is also valid...thats...thats... GENUIS! *sarcasm* It's not about "assigning a valid value to a variable", it's about the name being created (or not) in the current namespace, whatever it's bound to. From ckaynor at zindagigames.com Thu Nov 12 15:40:57 2009 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 12 Nov 2009 12:40:57 -0800 Subject: Psyco on 64-bit machines In-Reply-To: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 12:06 PM, Russ P. wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > The only things you should lose by using a 32-bit version of Python is access to the memory beyond the 4GB limit (approximate - the OS takes some of that), and any compiled extension modules you cannot find or recompile for 32-bit (.pyd on Windows - I think .so on Linux). Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Nov 12 15:44:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:44:00 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 12, 2009 at 2:24 PM, Alf P. Steinbach wrote: > > You'll also find it impossible to rigorously define "dynamic language" in a > general way so that that definition excludes C++. > > So, to anyone who understands what one is talking about, "interpreted", or > e.g. "slow language" (as was the case here), conveys the essence. > > And to anyone who doesn't understand it trying to be more precise is an > exercise in futility and pure silliness ?-- ?except for the purpose of > misleading. You just made Rami's point. You can't define a language as . You can however describe what features it has - static vs. dynamic typing, duck-typing, dynamic dispatch, and so on. Those are features of the language. Other things, like "interpreted" vs "compiled" are features of the implementation. C++ for instance is considered language that gets compiled to machine code. However, Visual Studio can compile C++ programs to run on the .NET framework which makes them JIT compiled. Some one could even write an interpreter for C++ if they wanted to. From benjamin.kaplan at case.edu Thu Nov 12 15:49:41 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Nov 2009 15:49:41 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: On Thu, Nov 12, 2009 at 2:52 PM, rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? > At least on *nix (including OS X), installing Python 3 does exactly what you want by default. I don't know how it handles it on Windows. > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Thu Nov 12 15:51:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Nov 2009 15:51:13 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? When you install 3.1 (not 3.0), it asks whether to make 'this' the default Python. Make sure the box is unchecked. From davea at ieee.org Thu Nov 12 15:51:44 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 15:51:44 -0500 Subject: Computing the 1000th prime In-Reply-To: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> References: <08706070C8F4473DBDAE8B27B0ABBB9E@ray> Message-ID: <4AFC7560.50104@ieee.org> Ray Holt wrote: > I have an assigment to find the 1000th. prime using python. What's wrong > with the following code: > PrimeCount = 0 > PrimeCandidate = 1 > while PrimeCount < 2000: > IsPrime = True > PrimeCandidate = PrimeCandidate + 2 > for x in range(2, PrimeCandidate): > if PrimeCandidate % x == 0: > ## print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x > print PrimeCandidate > IsPrime = False > break > if IsPrime: > PrimeCount = PrimeCount + 1 > PrimeCandidate = PrimeCandidate + 2 > print PrimeCandidate > Thanks > > There are a bunch of things wrong here. Did you write this code, or was it copied from somewhere else? Because it looks like there are several typos, that you could catch by inspection. First, at what point in the loop do you decide that you have a prime? Why not add a print there, printing the prime, instead of printing a value that's already been incremented beyond it. And put labels on your prints, or you'll never be able to decipher the output. Chnage the limit for PrimeCount to something small while you're debugging, because you can figure out small primes and composites by hand. Second, you have a loop which divides by x. But you change the PrimeCandidate within the loop, so it's not dividing the same value each time through. Check your indentation. Third, your limit value is too high. You aren't looking for 2000 primes, but 1000 of them. Further, your count is off by 1, as this loop doesn't identify 2 as a prime. I'd recommend making this whole thing a function, and have it actually build and return a list of primes. Then the caller can check both the size of the list and do a double check of the primality of each member. And naturally you'll be able to more readily check it yourself, either by eye or by comparing it to one of the standard list of primes you can find on the internet. The function should take a count, and loop until the len(primelist) matches the count. Then just return the primelist. DaveA From patrick.just4fun at gmail.com Thu Nov 12 16:04:51 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Thu, 12 Nov 2009 22:04:51 +0100 Subject: Python & Go In-Reply-To: <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> References: <426705a0-abe5-40be-9dd4-987171f1d876@a32g2000yqm.googlegroups.com> <3e2ec71b-1bd6-4fc7-b2fd-12ddb6fbdd44@p8g2000yqb.googlegroups.com> Message-ID: <4AFC7873.4020808@gmail.com> Carl Banks wrote: > Well, it's hard to argue with not being like C++, but the lack of > inheritance is a doozie. Well it has the concept of embedding, which seems to be similar to inheritance. - Patrick From davidb at panix.com Thu Nov 12 16:05:46 2009 From: davidb at panix.com (David M. Besonen) Date: Thu, 12 Nov 2009 13:05:46 -0800 Subject: (OT) Recommend FTP Client In-Reply-To: <4AFC617A.2070201@ieee.org> References: <4dc0cfea0911120743g4c31d57flc1df3c9501df098d@mail.gmail.com> <4AFC617A.2070201@ieee.org> Message-ID: <4AFC78AA.3070807@panix.com> On 11/12/2009 11:26 AM, Dave Angel wrote: > Try http://fireftp.mozdev.org/ in the past i found this to be buggy. i'd recommend something different. what is your OS? -- david From rami.chowdhury at gmail.com Thu Nov 12 16:08:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 12 Nov 2009 13:08:27 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 12:44:00 -0800, Benjamin Kaplan wrote: > Some one could even write an > interpreter for C++ if they wanted to. Someone has (http://root.cern.ch/drupal/content/cint)! -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From hansmu at xs4all.nl Thu Nov 12 16:20:47 2009 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 12 Nov 2009 22:20:47 +0100 Subject: python with echo In-Reply-To: References: Message-ID: <4afc7c9d$0$22941$e4fe514c@news.xs4all.nl> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 17:24:37 -0800, hong zhang wrote: > >> List, >> >> I have a question of python using echo. >> >> POWER = 14 >> return_value = os.system('echo 14 > >> /sys/class/net/wlan1/device/tx_power') >> >> can assign 14 to tx_power >> >> But >> return_value = os.system('echo $POWER > >> /sys/class/net/wlan1/device/tx_power') > > POWER = 14 doesn't create an environment variable visible to echo. It is > a Python variable. > >>>> POWER = 14 >>>> import os >>>> return_value = os.system('echo $POWER') > >>>> return_value > 0 You can set environment variables from within Python using os.putenv: >>> import os >>> os.putenv('POWER', '14') >>> return_value = os.system('echo $POWER') 14 >>> return_value 0 Keep in mind that putenv() only affects processes started by Python after you call putenv. It does not, for example, affect the shell process you used to invoke Python: $ POWER=14 $ python -c 'import os os.putenv("POWER", "42") os.system("echo $POWER")' 42 $ echo $POWER 14 $ >> return_value is 256 not 0. It cannot assign 14 to tx_power. > > I don't understand that. Exit status codes on all systems I'm familiar > with are limited to 0 through 255. What operating system are you using? Probably some form of Unix. The value returned by os.system() is the exit status shifted left one byte, for example: >>> os.system("exit 1") 256 Hope this helps, -- HansM From patrick.just4fun at gmail.com Thu Nov 12 16:22:42 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Thu, 12 Nov 2009 22:22:42 +0100 Subject: Python & Go In-Reply-To: References: Message-ID: <4AFC7CA2.3090606@gmail.com> kj wrote: > > I'm just learning about Google's latest: the GO (Go?) language. > (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", the absence of parentheses at the top of > flow control constructs, and quite a few statements without a > trailing semicolon. Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... I don't see many similarities with python, especially it's syntax looks completely different to me. Google Go introduces many new concepts. Interfaces work a little bit like duck typing. You may call that python-style. And it has go-routines, which are a bit similar to generators (although I haven't look at them in detail). There is no exception handling, but channels should be able to substitute them, although I haven't checked that. At a first look it seems, that using Google Go effectively, someone has to relinquish many programming habits and adapt lots of new ones. - Patrick From jaredatwork0 at gmail.com Thu Nov 12 16:25:41 2009 From: jaredatwork0 at gmail.com (Jared Klumpp) Date: Thu, 12 Nov 2009 13:25:41 -0800 (PST) Subject: JSR223 Access Python class instances through Java Message-ID: <1c8e4788-8ce5-4baa-818f-141f04f33997@l2g2000yqd.googlegroups.com> I am trying to access (from Java) a python class that extends a Java interface. The following program runs fine in the jython console (I can instantiate Tada, call t.getName() and everything prints correctly.) However, if I invoke test1() from Java using JSR223, the returned object is inaccessible (proxy type) and none of the "in init", "in getName" strings will print. Furthermore, none of the lines print unless I convert ITest to a concrete class, but then the getName methods return the concrete implementation's string. Has anyone successfully had this situation work, and how did you do it? Thanks in advance Code: =========== import ITest class Tada(ITest): def __init__(self): print "In Init" def getName(self): print "In getName" return "Joe Schmoe" def test1(): t = Tada() print t.getName() print "Hello, World" return t From invalid at invalid.invalid Thu Nov 12 16:37:30 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 12 Nov 2009 21:37:30 +0000 (UTC) Subject: Python & Go References: Message-ID: On 2009-11-12, Patrick Sabin wrote: > kj wrote: >> >> I'm just learning about Google's latest: the GO (Go?) language. >> (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). >> There are some distinctly Pythonoid features to the syntax, such >> as "import this_or_that", the absence of parentheses at the top of >> flow control constructs, and quite a few statements without a >> trailing semicolon. Then again, there's a lot that looks distinctly >> un-Pythonlike, such as the curly brackets all over the place. And >> among the un-Pythonlike stuff there's a lot that looks like nothing >> else that I've ever seen... > > I don't see many similarities with python, Same here. Go syntax is much more like C/Java than Python. Sematically, I don't see much that's similar either. Go is statically typed. Go has no inheritence. Go has no exceptions ( no practical error handling AFAICT). Despite all the people who keep saying it's similar to Python, I don't really see what they're talking about. It seems more like C with garbage collection and interfaces, or maybe cleaned-up Java. -- Grant Edwards grante Yow! I have a VISION! It's at a RANCID double-FISHWICH on visi.com an ENRICHED BUN!! From tschmidt at sacfoodcoop.com Thu Nov 12 17:04:40 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Thu, 12 Nov 2009 14:04:40 -0800 (PST) Subject: open source linux -> windows database connectivity? Message-ID: I am trying to read a Pervasive database on a Windows machine from a Python script on a Linux machine. I understand that this can be done with a proprietary ODBC-to-ODBC bridge called mxODBC or Easysoft OOB. Is there anyway to do this with existing free/ open source tools? Thanks in advance for any tips. From sridharr at activestate.com Thu Nov 12 17:12:44 2009 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 12 Nov 2009 14:12:44 -0800 Subject: ANN: ActivePython 2.6.4.8 is now available Message-ID: I'm happy to announce that ActivePython 2.6.4.8 is now available for download from: http://www.activestate.com/activepython/ This is a patch release that updates ActivePython to core Python 2.6.4. We recommend that you try 2.6 version first. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. Beginning the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC - Solaris/x86 - HP-UX/PA-RISC - AIX/PowerPC - AIX/PowerPC 64-bit Extra Bits ---------- ActivePython releases also include the following: - ActivePython26.chm: An MS compiled help collection of the full ActivePython documentation set. Linux users of applications such as xCHM might find this useful. This package is installed by default on Windows. Extra bits are available from: http://downloads.activestate.com/ActivePython/etc/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From rantingrick at gmail.com Thu Nov 12 17:15:10 2009 From: rantingrick at gmail.com (rantingrick) Date: Thu, 12 Nov 2009 14:15:10 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: <852fa408-a61d-4fa1-80fc-ef0424d96767@s31g2000yqs.googlegroups.com> On Nov 12, 2:51?pm, Terry Reedy wrote: > rantingrick wrote: > > Hello, > > > Currently i am using 2.6 on Windows and need to start writing code in > > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > > converted. So i want to install 3.0 without disturbing my current > > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > > changed to Python3.0 and when i double click a Python script it will > > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > > from the command line... > python3.x myscript.py > > > So how do i do this? Is my fear unfounded? > > When you install 3.1 (not 3.0), it asks whether to make 'this' the > default Python. Make sure the box is unchecked. Thanks for both of your replies, just to be safe though i'm going to back up everything ... Python 3000, here i come and i hope your ready for me!?!? Later Guy's! From lists at cheimes.de Thu Nov 12 17:31:00 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 12 Nov 2009 23:31:00 +0100 Subject: python with echo In-Reply-To: <7m2729F3fjr14U1@mid.uni-berlin.de> References: <7m2729F3fjr14U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > with open("/sys/class/net/wlan1/device/tx_power", "w") as f: > f.write("%i" % POWER) IIRC the sys and proc virtual file system requires new line at the end of a modifier. At least echo appends \n unless it's told otherwise. Christian From rt8396 at gmail.com Thu Nov 12 17:55:12 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 14:55:12 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> Message-ID: <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> On Nov 12, 2:37?pm, Bruno Desthuilliers wrote: > > Oh i get it now! If i assign a valid value to a variable the variable > > is also valid...thats...thats... GENUIS! *sarcasm* > > It's not about "assigning a valid value to a variable", it's about the > name being created (or not) in the current namespace, whatever it's > bound to. And thats what my sarcasm was alluding to. Steven's argument is moot because it will blow up either way due to the fact that "value" is non- existent! Every argument that has been brought forth about how this will break is just False and basically a bunch of FUD! It just garbage so you can discredit the idea. It's actually quite funny when someone as small as me can bring down the iron curtain of c.l.py. '''Mr. Gorbachev, Tear down this wall!''' How about one of you "esteemed" Pythonista's show me a real example where it will break. Show me (and the world) this H.G Wells nightmarish scenario you speak of but show no solid proofs. Sorry chaps, I don't buy snake oil! Going, Going, Gonnnne, out the park! PS: And if it were so dangerous why would someone as knowledgeable as Carl have stepped in and supported it. I think because (like me) Carl put's the language before sewing circles. I think it's just personal like all the times before, that's OK, i have very thick skin! If it's wrong for a good reason i will graciously accept that, but no one has proven it's non-worth, not yet! From mal at egenix.com Thu Nov 12 17:56:22 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Thu, 12 Nov 2009 23:56:22 +0100 Subject: open source linux -> windows database connectivity? In-Reply-To: References: Message-ID: <4AFC9296.2040309@egenix.com> Tony Schmidt wrote: > I am trying to read a Pervasive database on a Windows machine from a > Python script on a Linux machine. > > I understand that this can be done with a proprietary ODBC-to-ODBC > bridge called mxODBC or Easysoft OOB. The product is called "mxODBC Connect" and allows connecting from Python (running on pretty much any major platform) to a Windows or Linux server running the database: http://www.egenix.com/products/python/mxODBCConnect/ Note: The client part of this product is free. You only need to get a license for the server part. Alternatively, you can also our mxODBC single-tier product with the Pervasive ODBC driver available for Linux: http://ww1.pervasive.com/developerzone/platforms/linux.asp Regards, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 12 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 dc.loco at gmail.com Thu Nov 12 19:47:36 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 16:47:36 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? Message-ID: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Hi, I recently asked our IT department how to gain access to an addressbook. After carefully explaining that I was on a Linux system using Python, I got the reply: "You should use our LDAP. With LDAP you can pull any data you want from Active Directory. On our network, the serverless binding address for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." with the actual "..." filled in. I don't know squat about LDAP, but installed the python-ldap deb, and started glancing at the documentation on-line. I didn't see anything obvious for working with the URI above. Can I work w/ it? If so, a short example, please? Thanx. From wuwei23 at gmail.com Thu Nov 12 20:01:47 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Nov 2009 17:01:47 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 13, 10:47?am, Kevin Cole wrote: > Hi, > > I recently asked our IT department how to gain access to an > addressbook. ?After carefully explaining that I was on a Linux system > using Python, I got the reply: > > "You should use our LDAP. With LDAP you can pull any data you want > from Active Directory. On our network, the serverless binding address > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > with the actual "..." filled in. > > I don't know squat about LDAP, but installed the python-ldap deb, and > started glancing at the documentation on-line. I didn't see anything > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > short example, please? > > Thanx. http://www.python-ldap.org/doc/html/ldapurl.html#example From dc.loco at gmail.com Thu Nov 12 20:27:03 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 17:27:03 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 12, 8:01?pm, alex23 wrote: > On Nov 13, 10:47?am, Kevin Cole wrote: > > > > > Hi, > > > I recently asked our IT department how to gain access to an > > addressbook. ?After carefully explaining that I was on a Linux system > > using Python, I got the reply: > > > "You should use our LDAP. With LDAP you can pull any data you want > > from Active Directory. On our network, the serverless binding address > > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > > with the actual "..." filled in. > > > I don't know squat about LDAP, but installed the python-ldap deb, and > > started glancing at the documentation on-line. I didn't see anything > > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > > short example, please? > > > Thanx. > > http://www.python-ldap.org/doc/html/ldapurl.html#example Ah, it wasn't clear to me that "localhost:1389" meant serverless. Armed with that, I'm off to experiment. Thanks. From jeremiahsavage at gmail.com Thu Nov 12 20:38:00 2009 From: jeremiahsavage at gmail.com (Jeremiah H. Savage) Date: Thu, 12 Nov 2009 17:38:00 -0800 Subject: python parser overridden by pymol In-Reply-To: <4AFB8592.7040300@ieee.org> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> Message-ID: <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> On Wed, Nov 11, 2009 at 7:48 PM, Dave Angel wrote: > > > Jeremiah wrote: >> >> Hello, >> >> I'm fairly new to python (version 2.5.4), and am writing a program >> which uses both pymol (version 1.2r1) and numpy (version 1.3.0) from >> debian. >> >> It appears that when I add pymol to $PYTHONPATH, that parser.expr() is >> no longer available, and so I am unable to use numpy.load(). I have >> looked for where parser.expr() is defined in the python system so I >> could place that directory first in $PYTHONPATH, but I have not been >> able to find the file that defines expr(). >> >> My reason for using numpy.load() is that I have a numpy array which >> takes an hour to generate. Therefore, I'd like to use numpy.save() so >> I could generate the array one time, and then load it later as needed >> with numpy.load(). >> >> I've successfully tested the use of numpy.save() and numpy.load() with >> a small example when the pymol path is not defined in $PYTHONPATH ?: >> >> ? >>> import numpy >> ? >>> numpy.save('123',numpy.array([1,2,3])) >> ? >>> numpy.load('123.npy') >> ? array([1, 2, 3]) >> >> >> However, a problem arises once $PYTHONPATH includes the pymol >> directory. To use the pymol api, I add the following to ~/.bashrc: >> >> ? PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol >> ? export PYMOL_PATH >> ? PYTHONPATH=$PYMOL_PATH >> ? export PYTHONPATH >> >> Once this is done, numpy.load() no longer works correctly, as pymol >> contains a file named parser.py ( /usr/lib/pymodules/python2.5/pymol/ >> parser.py ), which apparently prevents python from using its native >> parser. >> >> ? >>> numpy.load('123.npy') >> ? Traceback (most recent call last): >> ? ? File "", line 1, in >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line >> 195, in load >> ? ? ? return format.read_array(fid) >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", >> line 353, in read_array >> ? ? ? shape, fortran_order, dtype = read_array_header_1_0(fp) >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/format.py", >> line 250, in read_array_header_1_0 >> ? ? ? d = safe_eval(header)Thank you. That really helped. To use pymol and numpy to >> ? ? File "/usr/lib/python2.5/site-packages/numpy/lib/utils.py", line >> 840, in safe_eval >> ? ? ? ast = compiler.parse(source, "eval") >> ? ? File "/usr/lib/python2.5/compiler/transformer.py", line 54, in >> parse >> ? ? ? return Transformer().parseexpr(buf) >> ? ? File "/usr/lib/python2.5/compiler/transformer.py", line 133, in >> parseexpr >> ? ? ? return self.transform(parser.expr(text)) >> ? AttributeError: 'module' object has no attribute 'expr' >> >> If I understand the problem correctly, can anyone tell me where >> python.expr() is defined, or suggest a better method to fix this >> problem? >> >> Thanks, >> Jeremiah >> >> > > Generic answers, I have no experience with pymol > > If pymol really needs that parser.py, you have a problem, as there can only > be one module by that name in the application. ?But assuming it's needed for > some obscure feature that you don't need, you could try the following > sequence. > > 1) temporarily rename the pymol's ?parser.py ?file to something else, like > pymolparser.py, and see what runs. > 2) rather than changing the PYTHONPATH, fix ?up ?sys.path during your script > initialization. > ? In particular, do an ? ?import parser ? ?near the beginning of the script. > ?This gets it loaded, even though you might not need to use it from this > module. > ? After that import, then add the following line (which could be generalized > later) > ? sys.path.append( "/usr/lib/pymodules/python2.5/pymol") > > > If this works, then you can experiment a bit more, perhaps you don't need > the extra import parser, just putting the pymol directory at the end of the > sys.path rather than the beginning may be good enough. > > If the parser.py in the pymol is actually needed, you might need to rename > its internal references to some other name, like pymolparser. > > HTH, > DaveA > > Thank you. Your second suggestion really helped. To use pymol and numpy together, I now do the following: To ~/.bashrc add: PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol export PYMOL_PATH Then I can do the following in python: import numpy numpy.save('123',numpy.array([1,2,3])) numpy.load('123.npy') array([1, 2, 3]) import sys sys.path.append( "/usr/lib/pymodules/python2.5/pymol") import pymol pymol.finish_launching() pymol.importing.load("/path/to/file.pdb") Thanks, Jeremiah From dc.loco at gmail.com Thu Nov 12 20:39:55 2009 From: dc.loco at gmail.com (Kevin Cole) Date: Thu, 12 Nov 2009 17:39:55 -0800 (PST) Subject: Linux, Python 2.5.2, serverless binding LDAP? References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: On Nov 12, 8:01?pm, alex23 wrote: > On Nov 13, 10:47?am, Kevin Cole wrote: > > > > > Hi, > > > I recently asked our IT department how to gain access to an > > addressbook. ?After carefully explaining that I was on a Linux system > > using Python, I got the reply: > > > "You should use our LDAP. With LDAP you can pull any data you want > > from Active Directory. On our network, the serverless binding address > > for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." > > > with the actual "..." filled in. > > > I don't know squat about LDAP, but installed the python-ldap deb, and > > started glancing at the documentation on-line. I didn't see anything > > obvious for working with the URI above. ?Can I work w/ it? ?If so, a > > short example, please? > > > Thanx. > > http://www.python-ldap.org/doc/html/ldapurl.html#example On second thought... That didn't help at all. The example just shows how to parse a URI. I'm trying to connect to a service (if I understand correctly) that is NOT on my Linux box, but somewhere out in our IT department's ether, and I do not have host/domain to work with. I interpreted "serverless binding" to mean that I was connecting by some means other than host.domain:port. Yes? From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:44:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:44:22 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> Message-ID: <00863e42$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > Congratulations, you just reinvented one of the most infamous source of > bugs in C, C++, Java, PHP, javascript and quite a few other languages. > Believe it or not, but not allowing this in Python was a very deliberate > design choice. Oh, but those hundreds of thousands of man-hours lost to bugs caused by assignment-as-an-expression is nothing compared to the dozens of man- minutes saved by having one fewer line of code! *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:49:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:49:08 GMT Subject: python with echo References: Message-ID: <00863f61$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 19:30:01 +0000, MRAB wrote: >> I don't understand that. Exit status codes on all systems I'm familiar >> with are limited to 0 through 255. What operating system are you using? >> >> Assuming your system allows two-byte exit statuses, you should check >> the documentation for echo and the shell to see why it is returning >> 256. >> > In some OSs the exit status consists of 2 fields, one being the child > process's exit status and the other being supplied by the OS. Which OSes? > The reason is simple. What if the child process terminated abnormally? > You'd like an exit status to tell you that, Which it does. Anything other than 0 is an error. I see that, for example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it to exit normally, it returns with an exit status of 130. [steve at soy ~]$ sleep 3 # no interrupt [steve at soy ~]$ echo $? 0 [steve at soy ~]$ sleep 3 # interrupt with ctrl-C [steve at soy ~]$ echo $? 130 I get the same result on a Linux box and a Solaris box, both running bash. > but you wouldn't want it to > be confused with the child process's own exit status, assuming that it > had terminated normally. I don't understand what you mean here. Why are you assuming it terminated normally if it terminated abnormally? -- Steven From tschmidt at sacfoodcoop.com Thu Nov 12 20:50:20 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Thu, 12 Nov 2009 17:50:20 -0800 (PST) Subject: open source linux -> windows database connectivity? References: Message-ID: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> >Note: The client part of this product is free. You only need to >get a license for the server part. Yeah, but don't I need the server part to make the connection? Would it be possible to use Jython and the Pervasive JDBC driver for this? On Nov 12, 2:56?pm, "M.-A. Lemburg" wrote: > Tony Schmidt wrote: > > I am trying to read a Pervasive database on a Windows machine from a > > Python script on a Linux machine. > > > I understand that this can be done with a proprietary ODBC-to-ODBC > > bridge called mxODBC or Easysoft OOB. > > The product is called "mxODBC Connect" and allows connecting from > Python (running on pretty much any major platform) to a Windows > or Linux server running the database: > > ? ?http://www.egenix.com/products/python/mxODBCConnect/ > > Note: The client part of this product is free. You only need to > get a license for the server part. > > Alternatively, you can also our mxODBC single-tier product with > the Pervasive ODBC driver available for Linux: > > ? ?http://ww1.pervasive.com/developerzone/platforms/linux.asp > > Regards, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 12 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 steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 20:55:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 01:55:57 GMT Subject: QuerySets in Dictionaries References: Message-ID: <008640fa$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: > I need to create a dictionary of querysets. I have code that looks > like: > > query1 = Myobject.objects.filter(status=1) > query2 = Myobject.objects.filter(status=2) > query3 = Myobject.objects.filter(status=3) > > d={} > d['a'] = query1 > d['b'] = query2 > d['c'] = query3 > > Is there a way to do this that I'm missing? I don't understand your problem. Assuming Myobject is defined, and has the appropriate attribute objects.filter, the above should work exactly as you give it. What is your actual problem? Are you asking for help in defining a queryset? -- Steven From python at mrabarnett.plus.com Thu Nov 12 21:22:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Nov 2009 02:22:26 +0000 Subject: python with echo In-Reply-To: <00863f61$0$26916$c3e8da3@news.astraweb.com> References: <00863f61$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4AFCC2E2.5050007@mrabarnett.plus.com> Steven D'Aprano wrote: > On Thu, 12 Nov 2009 19:30:01 +0000, MRAB wrote: > >>> I don't understand that. Exit status codes on all systems I'm familiar >>> with are limited to 0 through 255. What operating system are you using? >>> >>> Assuming your system allows two-byte exit statuses, you should check >>> the documentation for echo and the shell to see why it is returning >>> 256. >>> >> In some OSs the exit status consists of 2 fields, one being the child >> process's exit status and the other being supplied by the OS. > > Which OSes? > >> The reason is simple. What if the child process terminated abnormally? >> You'd like an exit status to tell you that, > > Which it does. Anything other than 0 is an error. I see that, for > example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it > to exit normally, it returns with an exit status of 130. > > [steve at soy ~]$ sleep 3 # no interrupt > [steve at soy ~]$ echo $? > 0 > [steve at soy ~]$ sleep 3 # interrupt with ctrl-C > > [steve at soy ~]$ echo $? > 130 > > I get the same result on a Linux box and a Solaris box, both running bash. > > > >> but you wouldn't want it to >> be confused with the child process's own exit status, assuming that it >> had terminated normally. > > I don't understand what you mean here. Why are you assuming it terminated > normally if it terminated abnormally? > You want to be able to distinguish between a child process terminating with an exit status, and failing to run a child process for some reason. From greg at cosc.canterbury.ac.nz Thu Nov 12 21:29:03 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:29:03 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> Message-ID: <7m3ujtF3gd1d7U1@mid.individual.net> Carl Banks wrote: > You > can define constants to access specific registers: > > R1L = 1 > R1H = 2 > R1 = 1 > > breg[R1H] = 2 > print wreg[R1] But keep in mind that named "constants" at the module level are really global variables, and therefore incur a dictionary lookup every time they're used. For maximum speed, nothing beats writing the numeric literals directly into the code, unfortunately. Generally, I think you're going to have quite a battle on your hands to get a pure Python implementation to run as fast as a real Z80, if it's even possible at all. And if you do succeed, the code will be pretty awful (due to things such as not being able to use named constants). I would be taking a different approach -- develop a prototype in Python, concentrating on clarity rather than speed, and later reimplement the core of the emulator as an extension module, using Pyrex or Cython or otherwise. -- Greg From robert.kern at gmail.com Thu Nov 12 21:32:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 Nov 2009 20:32:32 -0600 Subject: python parser overridden by pymol In-Reply-To: <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> Message-ID: Jeremiah H. Savage wrote: > To use pymol and numpy together, I now do the following: > > To ~/.bashrc add: > PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol > export PYMOL_PATH > > Then I can do the following in python: > > import numpy > numpy.save('123',numpy.array([1,2,3])) > numpy.load('123.npy') > array([1, 2, 3]) > import sys > sys.path.append( "/usr/lib/pymodules/python2.5/pymol") > import pymol > pymol.finish_launching() > pymol.importing.load("/path/to/file.pdb") No, do not do this. Add /usr/lib/pymodules/python2.5/ to your $PYTHONPATH, *not* /usr/lib/pymodules/python2.5/pymol/. You will continue to run into problems if you do it this way. You are not supposed to put the directory *of* the package onto sys.path but rather the directory that *contains* the package directory. -- 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 greg at cosc.canterbury.ac.nz Thu Nov 12 21:33:53 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:33:53 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <7m3usvF3gec23U1@mid.individual.net> Santiago Romero wrote: >>How about >> page, index = divmod(address, 16384) > > Surely, much better and faster :-) Not necessarily, because it involves a function call, and constructing and deconstructing a result tuple. If you time them, you may well find that the explicit shift and mask operations turn out to be faster. That also goes for any of the other things being discussed here. Especially if you're used to C, one's intuitions about speed can go badly astray where Python is concerned. The only way to be sure is to measure! -- Greg From greg at cosc.canterbury.ac.nz Thu Nov 12 21:36:42 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 13 Nov 2009 15:36:42 +1300 Subject: #define (from C) in Python In-Reply-To: <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <4afc4711$0$6581$9b4e6d93@newsspool3.arcor-online.net> <47742318-c454-4545-beb7-44a7b7eaeb4c@v25g2000yqk.googlegroups.com> Message-ID: <7m3v25F3gec23U2@mid.individual.net> TerryP wrote: > If it's such a big hairy deal, just recompile a copy of the C Pre > Processor to use something other then #, and hook it up to your python > scripts in a pipe line from a shell wrapper. Or use a different preprocessor, such as m4, that doesn't clash with the # character. -- Greg From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 21:50:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 02:50:33 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <00864dc6$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 21:02:11 +0100, Alf P. Steinbach wrote: > Specifically, I reacted to the statement that < talk about "the" speed of an implementation>>, made in response to > someone upthread, in the context of Google finding CPython overall too > slow. > > It is quite slow. ;-) Quite slow to do what? Quite slow compared to what? I think you'll find using CPython to sort a list of ten million integers will be quite a bit faster than using bubblesort written in C, no matter how efficient the C compiler. And why are we limiting ourselves to integers representable by the native C int? What if the items in the list were of the order of 2**100000? Of if they were mixed integers, fractions, fixed-point decimals, and floating-point binaries? How fast is your C code going to be now? That's going to depend on the C library you use, isn't it? In other words, it is an *implementation* issue, not a *language* issue. Okay, let's keep it simple. Stick to numbers representable by native C ints. Around this point, people start complaining that it's not fair, I'm not comparing apples with apples. Why am I comparing a highly-optimized, incredibly fast sort method in CPython with a lousy O(N**2) algorithm in C? To make meaningful comparisons, you have to make sure the algorithms are the same, so the two language implementations do the same amount of work. (Funnily enough, it's "unfair" to play to Python's strengths, and "fair" to play to C's strengths.) Then people invariable try to compare (say) something in C involving low- level bit-twiddling or pointer arithmetic with something in CPython involving high-level object-oriented programming. Of course CPython is "slow" if you use it to do hundreds of times more work in every operation -- that's comparing apples with oranges again, but somehow people think that's okay when your intention is to prove "Python is slow". An apples-to-apples comparison would be to use a framework in C which offered the equivalent features as Python: readable syntax ("executable pseudo-code"), memory management, garbage disposal, high-level objects, message passing, exception handling, dynamic strong typing, and no core dumps ever. If you did that, you'd get something that runs much closer to the speed of CPython, because that's exactly what CPython is: a framework written in C that provides all those extra features. (That's not to say that Python-like high-level languages can't, in theory, be significantly faster than CPython, or that they can't have JIT compilers that emit highly efficient -- in space or time -- machine code. That's what Psyco does, now, and that's the aim of PyPy.) However, there is one sense that Python *the language* is slower than (say) C the language. Python requires that an implementation treat the built-in function (say) int as an object subject to modification by the caller, while C requires that it is a reserved word. So when a C compiler sees "int", it can optimize the call to a known low-level routine, while a Python compiler can't make this optimization. It *must* search the entire scope looking for the first object called 'int' it finds, then search the object's scope for a method called '__call__', then execute that. That's the rules for Python, and an implementation that does something else isn't Python. Even though the searching is highly optimized, if you call int() one million times, any Python implementation *must* perform that search one million times, which adds up. Merely identifying what function to call is O(N) at runtime for Python and O(1) at compile time for C. Note though that JIT compilers like Psyco can often take shortcuts and speed up code by a factor of 2, or up to 100 in the best cases, which brings the combination of CPython + Psyco within shouting distance of the speed of the machine code generated by good optimizing C compilers. Or you can pass the work onto an optimized library or function call that avoids the extra work. Like I said, there is no reason for Python *applications* to be slow. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 22:00:16 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 03:00:16 GMT Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <0086500d$0$26916$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 15:29:03 +1300, greg wrote: > Generally, I think you're going to have quite a battle on your hands to > get a pure Python implementation to run as fast as a real Z80, if it's > even possible at all. And if you do succeed, the code will be pretty > awful (due to things such as not being able to use named constants). I don't know about that... Python on a 2GHz processor (which is more or less entry-level for desktop PCs these days), emulating something which used to run at 2.5MHz? Even if the Python code does 1000 times more work, the modern processor is nearly 1000 times faster, so your Python code won't be much slower than the first generation Z80. The latest Z80 processors operate at 50MHz. That still gives you a factor of 40 to work with. Write your Python carefully, optimizing only the bits that *need* optimizing, and perhaps using a few C extensions or Psyco, and I think you have a good chance of being close enough to the speed of a real Z80. -- Steven From http Thu Nov 12 22:08:39 2009 From: http (Paul Rubin) Date: 12 Nov 2009 19:08:39 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> Message-ID: <7x8webruiw.fsf@ruckus.brouhaha.com> Duncan Booth writes: > > http://scienceblogs.com/goodmath/2009/11/googles_new_language_go.php > > > Thanks for that link. I think it pretty well agrees with my first > impressions of Go: It looks like a not-so-interesting C follow-on, but the article doesn't describe any of the parallelism stuff. > The lack of any kind of error handling, whether exceptions or > anything else is, I think, a killer. When you access a value out of > a map you have a choice of syntax: one way gives you a boolean flag > you can test to see whether or not the item was in the map, the > other either gives you the value or crashes the program (yes, the > documentation actually says 'crash'). Both of these are wrong: the > flag is wrong because it forces you to handle every lookup error > immediately and at the same place in the code; the crash is wrong > for obvious reasons. Nah, exceptions are an ugly effect that gets in the way of parallelism. Haskell handles lookups through its type system; dealing with lookup errors (say by chaining the Maybe type) is clean and elegant. Erlang handles it by crashing the process, and dealing with the crash through a supervision tree that cleans up after crashes and restarts the crashed processes. > What that article didn't mention, and what is possibly Go's real strong > point is that it has built-in support for parallel processing. Again though > the implementation looks weak... I'd like to know more about this; is there a link with a short write-up? I haven't gotten around to looking at the reference materials. > It has too many special cases: a lot of the builtin types can exist > only as builtin types: if they weren't part of the language you > couldn't implement an equivalent. I'd also like to have seen a more serious type system, like ML's or better. But they seemed to really be after a fast, lightweight compiler. Anyway, it doesn't like even slightly intended to be in the same space as Python. It's more like a de-bureaucratized replacement for Java. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 12 22:12:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 03:12:52 GMT Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> <7m3usvF3gec23U1@mid.individual.net> Message-ID: <00865301$0$26916$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 15:33:53 +1300, greg wrote: > Santiago Romero wrote: >>>How about >>> page, index = divmod(address, 16384) >> >> Surely, much better and faster :-) > > Not necessarily, because it involves a function call, and constructing > and deconstructing a result tuple. If you time them, you may well find > that the explicit shift and mask operations turn out to be faster. It's easy enough to test: >>> from timeit import Timer >>> t1 = Timer('a = n>>14; b = n & 16384', 'n=2137902') >>> t2 = Timer('a,b = divmod(n, 16384)', 'n=2137902') >>> min(t1.repeat(repeat=5)) 0.32850909233093262 >>> min(t2.repeat(repeat=5)) 0.54839301109313965 The shift and mask are a little faster on my machine, but that's certainly what I would call a micro-optimization. Unless the divmod call is the bottleneck in your code -- and it almost certainly won't be -- I don't think it's worth the obfuscation to use shift/mask. What should be done is write the code in the clearest way you can, then, only if it is it too slow, profile it to see where it actually needs optimizing. -- Steven From airia at acay.com.au Thu Nov 12 22:13:18 2009 From: airia at acay.com.au (Peter Nilsson) Date: Thu, 12 Nov 2009 19:13:18 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: "Alf P. Steinbach" wrote: > One reaction to has > been that turtle graphics may be off-putting to some > readers because it is associated with children's learning. [I'll be honest and say that I merely glanced at the two pdf files.] Who is your target audience? The opening Getting Started paragraph would probably put off many beginners right from the get go! You're talking about a 'first language' but throwing 'syntax', 'windows', 'graphics', 'networking', 'file and database access' and 'standard libraries' at them. The success of 'XXXX for Dummies' is certainly not their accuracy, but rather that they make far fewer assumptions that people already know the subject being tought! That assumption seems almost ingrained in every 'beginner' programming book I've ever seen! > What do you think? Whilst everyone knows children tend to think visually more than abstractly, the same is precisely true of adults. However, the ultimate problem with Turtle is that it ends up teaching a 'mathematical' perspective and it's far from intuitive how you map that perspective to tackling more real world issues. It's simply substituting one difficult abstraction with another. My recollection is that many children struggled with Turtle graphics because they had very little concept of trigonometry. [Why would they? Many wouldn't learn for another 2-10 years.] Adults tend to have even less concept since they almost never use trig (or much else from school ;-) in the real world. They can see the patterns and understand there's a logic to it, but they struggle replicating it. Get an angle wrong and you end up with a mess where it's not clear whether it's your algorithm or the maths that's at fault. The visual aspect might pique interest, but may put just as many people off. In any case, it won't relieve the difficulty of having to teach what is fundamentally an abstraction that doesn't have very good parallels with how people approach problems in the real world. Humans simply don't think like mathematicians^W computers. :-) I've met a lot of mathematics and comp sci teachers who honestly believe that you can't teach these subjects without a mathematical perspective. That stands in contrast to the number of people I see using spreadsheets with a very high proficiency who would never dream of saying they were good at mathematics or programming. -- Peter From aahz at pythoncraft.com Thu Nov 12 22:19:55 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Nov 2009 19:19:55 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >Esky is an auto-update framework for frozen python apps, built on top of >bbfreeze. It provides a simple API through which apps can find, fetch >and install updates, and a bootstrapping mechanism that keeps the app >safe in the face of failed or partial updates. Recently I was looking into distribution mechanisms, and I passed over bbfreeze because I saw no indication that Python 2.6 was supported. Kind of a bummer because esky looks pretty cool. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From hetchkay at gmail.com Thu Nov 12 22:27:31 2009 From: hetchkay at gmail.com (H Krishnan) Date: Fri, 13 Nov 2009 08:57:31 +0530 Subject: Python 2.6 and sys.exit() Message-ID: <1ab787d80911121927j1992416dl4d0007f8b4d3875b@mail.gmail.com> Hello, I have the following in exit.py: import sys sys.exit(0) I now try 'python -i exit.py': In 2.5, the script exits as I would expect. In 2.6, the following error is printed: Traceback (most recent call last): File "exit.py", line 2, in sys.exit(0) SystemExit: 0 >>> I couldn't find anything related to this in "What's new in 2.6". Is there any way I can get 2.6 to behave like 2.5? Thank you for your help, Regards, H. Krishnan -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Thu Nov 12 22:33:38 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 12 Nov 2009 22:33:38 -0500 Subject: python parser overridden by pymol In-Reply-To: References: <9556c163-98b5-4797-a8da-e8f2341cabca@g22g2000prf.googlegroups.com> <4AFB8592.7040300@ieee.org> <25a4e3b90911121738h1cb5d8adja77d128b093a2366@mail.gmail.com> Message-ID: <4AFCD392.6010106@ieee.org> Robert Kern wrote: >
    Jeremiah > H. Savage wrote: > >> To use pymol and numpy together, I now do the following: >> >> To ~/.bashrc add: >> PYMOL_PATH=/usr/lib/pymodules/python2.5/pymol >> export PYMOL_PATH >> >> Then I can do the following in python: >> >> import numpy >> numpy.save('123',numpy.array([1,2,3])) >> numpy.load('123.npy') >> array([1, 2, 3]) >> import sys >> sys.path.append( "/usr/lib/pymodules/python2.5/pymol") >> import pymol >> pymol.finish_launching() >> pymol.importing.load("/path/to/file.pdb") > > No, do not do this. Add /usr/lib/pymodules/python2.5/ to your > $PYTHONPATH, *not* /usr/lib/pymodules/python2.5/pymol/. You will > continue to run into problems if you do it this way. You are not > supposed to put the directory *of* the package onto sys.path but > rather the directory that *contains* the package directory. > As I said before, I don't know pymol. But if that is the package name, then Robert is certainly right. You need to read the docs on pymol to see what they require. For example, it's surprising they require a separate PYMOL_PATH environment variable, since they can find their own directory path with the __file__ attribute of one of the modules. Anyway, one more generic comment. Rather than having that directory in both the bashrc file AND in your python source, I'd consider deriving the latter from the environment variable, once you determine that it's actually necessary. And of course you could strip the last node from the path in the environment variable before appending it to sys.path, if that's what's appropriate. DaveA From ryan at rfk.id.au Thu Nov 12 22:39:54 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 13 Nov 2009 14:39:54 +1100 Subject: ANN: esky 0.2.1 In-Reply-To: References: Message-ID: <1258083594.2715.18.camel@durian> > >Esky is an auto-update framework for frozen python apps, built on top of > >bbfreeze. It provides a simple API through which apps can find, fetch > >and install updates, and a bootstrapping mechanism that keeps the app > >safe in the face of failed or partial updates. > > Recently I was looking into distribution mechanisms, and I passed over > bbfreeze because I saw no indication that Python 2.6 was supported. Not sure if it's officially supported, but I do most of my development on Python 2.6 and bbfreeze hasn't given me any problems as yet. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From hetchkay at gmail.com Thu Nov 12 23:07:15 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 20:07:15 -0800 (PST) Subject: 2.6 and sys.exit() Message-ID: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Hello, I have the following in exit.py: import sys sys.exit(0) I now try 'python -i exit.py': In 2.5, the script exits as I would expect. In 2.6, the following error is printed: Traceback (most recent call last): File "exit.py", line 2, in sys.exit(0) SystemExit: 0 >>> I couldn't find anything related to this in "What's new in 2.6". Is there any way I can get 2.6 to behave like 2.5? Thank you for your help, Regards, H. Krishnan From rt8396 at gmail.com Thu Nov 12 23:10:29 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:10:29 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> On Nov 12, 7:44?pm, Steven D'Aprano wrote > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > assignment-as-an-expression is nothing compared to the dozens of man- > minutes saved by having one fewer line of code! OK, what *if* the variable would only be valid in *that* block and *that* block only! My first idea was to have the variable avaiable in the local scope (if that is correct terminology?) so if the conditional was in global space the value would be available in global space, alright? You follow me? Now forget all that and observe the following. ;-) if value=range(10): #this block *would* execute and "value" would be a valid name #but only IN this block!!! value.append(1) elif value=fetch(0): #this block would *never* execute value.append(1) value.append(1) -> this throws a NameError Is that different than how other languages handle "assignment-by- expression"? Will that avoid the cataclysmic downward spiral you speak of? I can't see any problems with it AND it can still be applied to myself and Carl's use cases. Anybody is welcome to comment...? From rt8396 at gmail.com Thu Nov 12 23:22:38 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:22:38 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Message-ID: <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> On Nov 12, 10:07?pm, hetchkay wrote: > Hello, > > I have the following in exit.py: > import sys > sys.exit(0) > > I now try 'python -i exit.py': > > In 2.5, the script exits as I would expect. > > In 2.6, the following error is printed: > > Traceback (most recent call last): > ? File "exit.py", line 2, in > ? ? sys.exit(0) > SystemExit: 0 > > > > I couldn't find anything related to this in "What's new in 2.6". Look here ;-) http://docs.python.org/library/exceptions.html#exceptions.SystemExit From rt8396 at gmail.com Thu Nov 12 23:26:43 2009 From: rt8396 at gmail.com (r) Date: Thu, 12 Nov 2009 20:26:43 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <71261a1b-1b56-4c37-bc0f-01049565c0ab@p28g2000vbi.googlegroups.com> PS: Python even answers questions: >>> import sys >>> help(sys.exit) Help on built-in function exit in module sys: exit(...) exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure). Just think of Python as a programmers version of the "Magic 8 balls". From hetchkay at gmail.com Thu Nov 12 23:32:38 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 20:32:38 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <8f5c9c64-cf21-4a1f-ba54-68d9f90ca8b1@f20g2000prn.googlegroups.com> Hello, Thanks for your help. I know what SystemExit is. In 2.5 as well SystemExit is raised when sys.exit() is called. For example: try: import sys sys.exit(0) except SystemExit: print "system exit raised" raise But I don't understand why the interpreter does not exit in 2.6 but does exit in 2.5. Well, I do not need to understand that but I need to know how to get the interpreter to exit in 2.6. Regards, Krishnan From highcar at gmail.com Thu Nov 12 23:32:57 2009 From: highcar at gmail.com (elca) Date: Thu, 12 Nov 2009 20:32:57 -0800 (PST) Subject: how to install python-spidermonkey on windows Message-ID: <26331307.post@talk.nabble.com> Hello all, im making some script with python mechanize, one of problem is it really hard to find which support javascript supported web client scraping or crawler. actually i was found some such as python-spidermonkey and pykhtml and so on. but most of all only support on linux . i want to make my python script with exe file. so definitely i have to install on windows platform. my question is ..are there any method to can install python-spidermonkey or pykhtml on windows platform? i really need to support windows platform. if anyone can hint or help really appreicate! thanks in advance Paul -- View this message in context: http://old.nabble.com/how-to-install-python-spidermonkey-on-windows-tp26331307p26331307.html Sent from the Python - python-list mailing list archive at Nabble.com. From gallium.arsenide at gmail.com Thu Nov 12 23:50:39 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 12 Nov 2009 20:50:39 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: On Nov 12, 11:22 pm, r wrote: > On Nov 12, 10:07 pm, hetchkay wrote: > > I have the following in exit.py: > > import sys > > sys.exit(0) > > > I now try 'python -i exit.py': > > > In 2.5, the script exits as I would expect. > > > In 2.6, the following error is printed: > > > Traceback (most recent call last): > > File "exit.py", line 2, in > > sys.exit(0) > > SystemExit: 0 > > > I couldn't find anything related to this in "What's new in 2.6". > > Look here ;-) > http://docs.python.org/library/exceptions.html#exceptions.SystemExit How does that answer the OP's question? Namely, how to make 2.6 behave like 2.5? (Even saying "You can't make 2.6 behave like 2.5" would have been a better answer.) Failing that, how about something that explains why 2.6 behaves differently than 2.5, and why one of them is better or more correct than the other? Personally, I think 2.6's is probably the more correct behavior. Specifically, if the point of the -i command line option is to force interactive mode after completion of the script (which in this case completed with sys.exit), then it should go to interactive mode regardless of whether the script terminates "normally" or not. I think 2.5's behavior of allowing interactive mode to be skipped is against the spirit of -i. Unless -i meant something different in 2.5. Is there some kind of environment variable to set up to control this? John From gallium.arsenide at gmail.com Fri Nov 13 00:02:56 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 12 Nov 2009 21:02:56 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> <8f5c9c64-cf21-4a1f-ba54-68d9f90ca8b1@f20g2000prn.googlegroups.com> Message-ID: <3eef8061-6422-4b1c-b60c-8770e233b1d5@h34g2000yqm.googlegroups.com> On Nov 12, 11:32?pm, hetchkay wrote: > But I don't understand why the interpreter does not exit in 2.6 but > does exit in 2.5. Well, I do not need to understand that but I need to > know how to get the interpreter to exit in 2.6. Well, taken at face value, I would say the answer is to not use the -i option. ;) But I assume you would like to be able to sometimes enter interactive mode after the script completes but sometimes not? That I don't know how to do, but I would think it is either very simple or impossible. Surely someone more knowledgeable will be able to say which it is. Also, if you present your reason for wanting such behavior, maybe people can suggest alternatives that will serve your needs, even if not exactly replicating what you had in 2.5. John From pavlovevidence at gmail.com Fri Nov 13 00:07:14 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 21:07:14 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <006b1022-3c39-4baa-9715-de84d8105755@d5g2000yqm.googlegroups.com> Message-ID: <02f602e1-30f0-4b12-8048-75ecb44313b9@u7g2000yqm.googlegroups.com> On Nov 12, 6:37?am, Santiago Romero wrote: > > > ?I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > > ASpectrum, from C to Python + pygame. > > > The answer to your question is, "Use numpy". ?More details below. > > ?Let's see :-) > > > > ?How can I implement this in Python, I mean, define a 16 byte variable > > > so that high and low bytes can be accessed separately and changing W, > > > H or L affects the entire variable? I would like to avoid doing BIT > > > masks to get or change HIGH or LOW parts of a variable and let the > > > compiled code to do it by itself. > > > You can do clever memory slicing like this with numpy. ?For instance: > > > breg = numpy.zeros((16,),numpy.uint8) > > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > > This causes breg and wreg to share the same 16 bytes of memory. ?You > > can define constants to access specific registers: > > > R1L = 1 > > R1H = 2 > > R1 = 1 > > > breg[R1H] = 2 > > print wreg[R1] > > ?And how about speed? > > Assuming a 16 bit register named BC which contains 2 8 bit regiters (B > and C)... > > ?Will the above be faster than shifts and bit operations (<<, and,>> ) with new B and C values to "recalculate" BC when reading or > > changing either B, C or BC? I don't know. Strange thing about Python, the community generally isn't hellbent on speed so we don't usually memorize a bunch of facts like "X is faster than Y". I'm personally aware of only a few general rules of thumb on speed (like "local variables are much faster than globals" and "function calls have rather high overhead"). Obviously, given the problem you chose, you know you're going to have to worry about speed from the beginning. But since not many of us know speed details off-hand, you'll probably get a faster answer by just running the speed tests yourself. Having said that, I *suspect* the numpy approach I mentioned will be quite a bit faster than using bit operations and recalculating BC, but I really don't know. Carl Banks From pavlovevidence at gmail.com Fri Nov 13 00:10:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 12 Nov 2009 21:10:04 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <0ceed898-487f-4b1f-ae45-0796b5bd3a9b@b2g2000yqi.googlegroups.com> On Nov 12, 6:29?pm, greg wrote: > I would be taking a different approach -- develop a prototype > in Python, concentrating on clarity rather than speed, and > later reimplement the core of the emulator as an extension > module, using Pyrex or Cython or otherwise. But keep in mind he said he was doing it just for fun. I don't know about you, but I find it much more fun to try to write fast Python than to write the fast stuff in C. Not as effective, but more fun. Carl Banks From nad at acm.org Fri Nov 13 00:10:32 2009 From: nad at acm.org (Ned Deily) Date: Thu, 12 Nov 2009 21:10:32 -0800 Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> Message-ID: In article <008aa7ef-b945-4f70-b5e4-def66546eca2 at 2g2000prl.googlegroups.com>, hetchkay wrote: > I have the following in exit.py: > import sys > sys.exit(0) > > I now try 'python -i exit.py': > > In 2.5, the script exits as I would expect. > > In 2.6, the following error is printed: > > Traceback (most recent call last): > File "exit.py", line 2, in > sys.exit(0) > SystemExit: 0 > >>> > > I couldn't find anything related to this in "What's new in 2.6". > > Is there any way I can get 2.6 to behave like 2.5? Perhaps you don't want to be using the -i option? "-i When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command ..." http://docs.python.org/using/cmdline.html#generic-options If you don't want the interpreter to gain control on exit, don't use -i when you run the script. -- Ned Deily, nad at acm.org From s.selvamsiva at gmail.com Fri Nov 13 00:18:31 2009 From: s.selvamsiva at gmail.com (S.Selvam) Date: Fri, 13 Nov 2009 10:48:31 +0530 Subject: regex remove closest tag In-Reply-To: <4AFC5F3C.6010302@mrabarnett.plus.com> References: <4AFC5F3C.6010302@mrabarnett.plus.com> Message-ID: On Fri, Nov 13, 2009 at 12:47 AM, MRAB wrote: > S.Selvam wrote: > >> Hi all, >> >> >> 1) I need to remove the tags which is just before the keyword(i.e >> some_text2 ) excluding others. >> >> 2) input string may or may not contain tags. >> >> 3) Sample input: inputstr = """start > href="some_url">some_text1 some_text2 keyword anything""" >> >> 4) I came up with the following regex, >> >> >> p=re.compile(r'(?P.*?)(\s*keyword|\s*keyword)(?P.*)',re.DOTALL|re.I) >> s=p.search(inputstr) >> but second group matches both tags,while i need to match the recent >> one only. >> >> I would like to get your suggestions. >> >> Note: >> >> If i leave group('good1') as greedy, then it matches both the tag. >> >> ".*?" can match any number of any character, so it can match any > intervening "" tags. Try "[^<]*?" instead. > > Thanks a lot, p=re.compile(r'(?:\s*%s)'%(keyword),re.I|re.S) has done it ! -- > http://mail.python.org/mailman/listinfo/python-list > -- Yours, S.Selvam -------------- next part -------------- An HTML attachment was scrubbed... URL: From hetchkay at gmail.com Fri Nov 13 00:28:04 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 21:28:04 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: On Nov 13, 9:50?am, John Yeung wrote: > On Nov 12, 11:22 pm, r wrote: > > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > I have the following in exit.py: > > > import sys > > > sys.exit(0) > > > > I now try 'python -i exit.py': > > > > In 2.5, the script exits as I would expect. > > > > In 2.6, the following error is printed: > > > > Traceback (most recent call last): > > > ? File "exit.py", line 2, in > > > ? ? sys.exit(0) > > > SystemExit: 0 > > > > I couldn't find anything related to this in "What's new in 2.6". > > > Look here ;-) > >http://docs.python.org/library/exceptions.html#exceptions.SystemExit > > How does that answer the OP's question? ?Namely, how to make 2.6 > behave like 2.5? ?(Even saying "You can't make 2.6 behave like 2.5" > would have been a better answer.) > > Failing that, how about something that explains why 2.6 behaves > differently than 2.5, and why one of them is better or more correct > than the other? > > Personally, I think 2.6's is probably the more correct behavior. > Specifically, if the point of the -i command line option is to force > interactive mode after completion of the script (which in this case > completed with sys.exit), then it should go to interactive mode > regardless of whether the script terminates "normally" or not. ?I > think 2.5's behavior of allowing interactive mode to be skipped is > against the spirit of -i. ?Unless -i meant something different in 2.5. > > Is there some kind of environment variable to set up to control this? > > John I can understand the behavior from a '-i' point of view. My requirement is somewhat different. Consider a geometry tool that can be used to create objects, merge objects etc. I have python 'commands' for doing any of these operations and for saving the objects to a file. The user could write a file containing a set of commands (in python format) and load this file in the GUI. Optionally, one of the commands could be to exit in which case the GUI should shut down. I am using 'execfile' to execute the file, and this does not exit if the user has used sys.exit (or even if I expose a command called 'Exit' which calls sys.exit). May be I should not be using execfile but I am not sure what else I should use. The user-written file could contain loops and other constructs as well. -Krishnan From hetchkay at gmail.com Fri Nov 13 01:19:41 2009 From: hetchkay at gmail.com (hetchkay) Date: Thu, 12 Nov 2009 22:19:41 -0800 (PST) Subject: 2.6 and sys.exit() References: <008aa7ef-b945-4f70-b5e4-def66546eca2@2g2000prl.googlegroups.com> <81797bde-cf9b-427d-8be3-2089fa3b3b19@31g2000vbf.googlegroups.com> Message-ID: <57f0c9b2-e63f-40b9-b638-96e710218261@w37g2000prg.googlegroups.com> On Nov 13, 10:28?am, hetchkay wrote: > On Nov 13, 9:50?am, John Yeung wrote: > > > > > On Nov 12, 11:22 pm, r wrote: > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > > I have the following in exit.py: > > > > import sys > > > > sys.exit(0) > > > > > I now try 'python -i exit.py': > > > > > In 2.5, the script exits as I would expect. > > > > > In 2.6, the following error is printed: > > > > > Traceback (most recent call last): > > > > ? File "exit.py", line 2, in > > > > ? ? sys.exit(0) > > > > SystemExit: 0 > > > > > I couldn't find anything related to this in "What's new in 2.6". > > > > Look here ;-) > > >http://docs.python.org/library/exceptions.html#exceptions.SystemExit > > > How does that answer the OP's question? ?Namely, how to make 2.6 > > behave like 2.5? ?(Even saying "You can't make 2.6 behave like 2.5" > > would have been a better answer.) > > > Failing that, how about something that explains why 2.6 behaves > > differently than 2.5, and why one of them is better or more correct > > than the other? > > > Personally, I think 2.6's is probably the more correct behavior. > > Specifically, if the point of the -i command line option is to force > > interactive mode after completion of the script (which in this case > > completed with sys.exit), then it should go to interactive mode > > regardless of whether the script terminates "normally" or not. ?I > > think 2.5's behavior of allowing interactive mode to be skipped is > > against the spirit of -i. ?Unless -i meant something different in 2.5. > > > Is there some kind of environment variable to set up to control this? > > > John > > I can understand the behavior from a '-i' point of view. My > requirement is somewhat different. Consider a geometry tool that can > be used to create objects, merge objects etc. I have python 'commands' > for doing any of these operations and for saving the objects to a > file. The user could write a file containing a set of commands (in > python format) and load this file in the GUI. Optionally, one of the > commands could be to exit in which case the GUI should shut down. I am > using 'execfile' to execute the file, and this does not exit if the > user has used sys.exit (or even if I expose a command called 'Exit' > which calls sys.exit). > > May be I should not be using execfile but I am not sure what else I > should use. The user-written file could contain loops and other > constructs as well. > > -Krishnan Hi, I had been starting my application with -i option. I have removed this now and made a few other changes and things work OK now. Thanks to everyone who helped in this. Regards, Krishnan From vmanis at telus.net Fri Nov 13 01:20:11 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 22:20:11 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <00864dc6$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <38E3CD73-E0D2-43A6-A757-6DB6A829D1A6@telus.net> When I was approximately 5, everybody knew that higher level languages were too slow for high-speed numeric computation (I actually didn't know that then, I was too busy watching Bill and Ben the Flowerpot Men), and therefore assembly languages were mandatory. Then IBM developed Fortran, and higher-level languages were not too slow for numeric computation. When I was in university, IBM released a perfectly horrible implementation of PL/I, which dynamically allocated and freed stack frames for each procedure entry and exit (`Do Not Use Procedures: They Are Inefficient': section heading from the IBM PL/I (G) Programmer's Guide, circa 1968). Everyone knew PL/I was an abomination of a language, which could not be implemented efficiently. Then MIT/Bell Labs/GE/Honeywell wrote Multics in a PL/I subset, and (eventually) it ran quite efficiently. When Bell Labs pulled out of the Multics effort, some of their researchers wrote the first version of Unix in assembly language, but a few years later rewrote the kernel in C. Their paper reporting this included a sentence that said in effect, `yes, the C version is bigger and slower than the assembler version, but it has more functionality, so C isn't so bad'. Everybody knew that high-level languages were too inefficient to write an operating system in (in spite of the fact that Los Alamos had already written an OS in a Fortran dialect). Nobody knew that at about that time, IBM had started writing new OS modules in a company-confidential PL/I subset. When I was in grad school, everybody knew that an absolute defence to a student project running slowly was `I wrote it in Lisp'; we only had a Lisp interpreter running on our system. We didn't have MacLisp, which had been demonstrated to compile carefully-written numerical programs into code that ran more efficiently than comparable programs compiled by DEC's PDP-10 Fortran compiler in optimizing mode. In an earlier post, I mentioned SBCL and Chez Scheme, highly optimizing compiler-based implementations of Common Lisp and Scheme, respectively. I don't have numbers for SBCL, but I know that (again with carefully-written Scheme code) Chez Scheme can produce code that runs in the same order of magnitude as optimized C code. These are both very old systems that, at least in the case of Chez Scheme, use techniques that have been reported in the academic literature. My point in the earlier post about translating Python into Common Lisp or Scheme was essentially saying `look, there's more than 30 years experience building high-performance implementations of Lisp languages, and Python isn't really that different from Lisp, so we ought to be able to do it too'. All of which leads me to summarize the current state of things. 1. Current Python implementations may or may not be performance-scalable in ways we need. 2. Reorganized interpreters may give us a substantial improvement in performance. More significant improvements would require a JIT compiler, and there are good projects such as Unladen Swallow that may well deliver a substantial improvement. 3. We might also get improvements from good use of Python 3 annotations, or other pragma style constructs that might be added to the language after the moratorium, which would give a compiler additional information about the programmer's intent. (For example, Scheme has a set of functions that essentially allow a programmer to say, `I am doing integer arithmetic with values that are limited in range to what can be stored in a machine word'.) These annotations wouldn't destroy the dynamic nature of Python, because they are purely optional. This type of language feature would allow a programmer to exploit the high-performance compilation technologies that are common in the Lisp world. Even though points (2) and (3) between them offer a great deal of hope for future Python implementations, there is much that can be done with our current implementations. Just ask the programmer who writes a loop that laboriously does what could be done much more quickly with a list comprehension or with map. -- v From danb_83 at yahoo.com Fri Nov 13 01:30:24 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Thu, 12 Nov 2009 22:30:24 -0800 (PST) Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> Message-ID: <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> On Nov 12, 1:52?pm, rantingrick wrote: > Hello, > > Currently i am using 2.6 on Windows and need to start writing code in > 3.0. I cannot leave 2.x yet because 3rd party modules are still not > converted. So i want to install 3.0 without disturbing my current > Python2.x. What i'm afraid of is that some SYSVARIABLE will get > changed to Python3.0 and when i double click a Python script it will > try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts > from the command line... > python3.x myscript.py > > So how do i do this? Is my fear unfounded? Windows determines the double-click action based on the file extension. You just have to make sure that *.py files are associated with 2.x. http://support.microsoft.com/kb/307859 From vmanis at telus.net Fri Nov 13 01:36:09 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 22:36:09 -0800 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: <8FE6D77F-41DF-49ED-8C1F-C851D1CFC094@telus.net> On 2009-11-12, at 11:36, AK Eric wrote: > On Nov 12, 11:31 am, Terry Reedy wrote: >> Alf P. Steinbach wrote: >>> One reaction to >> http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle >>> graphics may be off-putting to some readers because it is associated >>> with children's learning. Take a look at Abelson and diSessa's _Turtle Geometry: The Computer as a Medium for Exploring Mathematics_ (MIT Press, 1986). This is most definitely not a kids' book. Chapter titles include `Topology of Turtle Paths', `Piecewise Flat Surfaces', and `Curved Space and General Relativity'. As well as being a very nice 2D graphics API, turtles let you explore very deep math. Of course, they also let you explore cybernetics and feedback; see some of the old MIT AI Lab reports on LOGO for that (you can find them at MIT's CSAIL lab website). For a lot of that, you actually need a robot turtle, like perhaps a LEGO Mindstorms robot. Seymour Papert (who did a lot of the MIT LOGO work) was, before his terrible motor accident, in research chair endowed by...LEGO. Hmmm... :) Of course, some people don't like Python itself because they are afraid of snakes. > I used Turtle back on the Apple in the early 80's... so I personally > have very positive feelings towards it ;) To each their own eh? I did my master's thesis on LOGO about 10 years before that, and I have VERY warm and fuzzy feelings about turtles :) -- v From apt.shansen at gmail.com Fri Nov 13 01:53:12 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 12 Nov 2009 22:53:12 -0800 Subject: New syntax for blocks In-Reply-To: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> Message-ID: <7a9c25c20911122253u6451e611ldfa2be88eb36aa32@mail.gmail.com> On Thu, Nov 12, 2009 at 8:10 PM, r wrote: > On Nov 12, 7:44 pm, Steven D'Aprano cybersource.com.au> wrote > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > > assignment-as-an-expression is nothing compared to the dozens of man- > > minutes saved by having one fewer line of code! > > OK, what *if* the variable would only be valid in *that* block and > *that* block only! My first idea was to have the variable avaiable in > the local scope (if that is correct terminology?) so if the > conditional was in global space the value would be available in global > space, alright? You follow me? Now forget all that and observe the > following. ;-) > > Assignment is a statement and not an expression in Python intentionally; its not just some random artifact. It was a decision. If you really want to overcome it, you need to show a SERIOUSLY huge amount of justification that goes far beyond 'hey, it saves me one line in certain situations'. You keep mentioning "elegant" and "clean" in the examples you've provided, but those terms (while often applied to Pythonisms) are very subjective. What you find elegant and clean, others may find prone to confusion or misunderstanding. There's a certain class of languages which treat assignments as expressions-- the C family most prominently. And some people love them and will forever seek it, as there is indeed a reduction of lines and/or code to express certain ideas if you use assignments as expressions. No one is really arguing against that. The argument against it is that it is extremely easy to screw up in ways which are extremely difficult to debug. > if value=range(10): > The problem with this is, its far too easy to type this but mean, "if value==range(10):" or some such. And then its far too hard to figure out why your program is wrong when it starts producing incorrect results. This has been a source of countless bugs over the years and years of C programming-- true, an excellent programmer will never make the mistake. But get some group of people together maintaining some codebase, and someone's gonna miss something, and others just will fail to see it as they scan over the code trying to figure out what's wrong. Granted, you can produce shorter and more concise code if you can make assignments expressions instead of statements. However, your code isn't anymore READABLE. And readability is more important then concise in Python, /on purpose/. It's true that you can usually produce a program in far fewer lines of Python code then you can in certain other languages not to be named; but that isn't the overriding goal. That's not a zen. There's no doctrine of, "Shorter is better". Readability counts is, though. The expression, "x=y" in a statement is far too easy to mess up with "x==y". You can try to do screwy things with the syntax like your original proposal of, "if x as y" to make it so a single missed = won't mess it up, but that doesn't really improve readability. It makes it less likely to accidentally screw things up, but also makes it very hard to scan code and determine where names are created and assigned to objects. Yeah, we use "as" in a few situations for assignment already. But those are all special constructs which stand on their own. Try/except, with, and import support it; but when scanning code those stand out on their own anyways, and none of them support arbitrarily complex expressions. The if statement does. The "as" can become lost within that expression, and when looking in the block of code you can easily miss where the binding occurs. The proposal that the variable exists only within the 'if' block is a non-starter; Python's namespaces don't work like that, they don't have arbitrary blocks of private variables. You just have your local, global, and builtin namespace (and static nested namespaces for closures)... changing that is a whooooooooole other can of worms, and this is not the proposal to do it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Fri Nov 13 01:58:27 2009 From: python at rcn.com (Raymond Hettinger) Date: Thu, 12 Nov 2009 22:58:27 -0800 (PST) Subject: Does turtle graphics have the wrong associations? References: Message-ID: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> On Nov 11, 10:21?pm, "Alf P. Steinbach" wrote: > One reaction to has > been that turtle graphics may be off-putting to some readers because it is > associated with children's learning. > > What do you think? How about calling it Raptor Graphics that will please everyone ;-) Raymond From vmanis at telus.net Fri Nov 13 02:09:57 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 23:09:57 -0800 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: <812E8D48-258E-4164-935E-F2810D21E9F7@telus.net> On 2009-11-12, at 19:13, Peter Nilsson wrote: > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > This paragraph is based upon a complete misunderstanding of turtle geometry. You do NOT use trigonometry to teach it, because the goal isn't to replicate cartesian geometry. The whole point about turtle geometry is that the student viscerally imagines him/herself BEING the turtle, and moving around the room according to the succession of FORWARD and TURNRIGHT commands. This is easier to visualize when one has an actual robot that draws pictures on butcher paper, as the second iteration of the MIT/BBN turtle work did (and they worked in middle schools, Grades 4-8, so there was no issue of trigonometry). > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. Kindly explain to me the difference between `algorithm' and `maths' here. I believe you just said that if there's a bug in the design, the program won't work. Hmmm. This reminds me of a well-known anecdote about the original LOGO study done at Muzzey High in Lexington, MA, in 1968. A group of NSF funding people was doing a tour of the school, and they came across a Grade 5 student who was doing a family tree program. The NSF people were impressed by the complexity of the program. One of them said in a patronizing tone, `I guess this stuff really helps you learn math'. She got quite angry, and responded, `This stuff has NOTHING to do with math!' > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) Having taught grade 8 math, I can tell you that cartesian geometry is much LESS intuitive to people that are learning it than the relative polar coordinates of turtle geometry are. (`Oh, you want to get to the mall food court? Turn left, and walk past about 10 stores. The food court is right after the Gap.') > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. It is true that you can't teach computer science to children without having a strong understanding of the mathematical foundations. It is also true that when you teach it to children that you very carefully hide the mathematical formalism. I might point out that the people who had most to do with the invention of turtle geometry were Wally Feurzeig (who was my boss when I worked at BBN in the 1970s) and Seymour Papert. Papert had spent a lot of time working with Jean Piaget in Switzerland. If you read the original LOGO memos, you will see his clear explanations on how this material ought to be taught to people with no math background, including children who are too young to do symbolic thinking (that kicks in in the early teens). That's why the visceral `I am a turtle' approach works well with middle-school kids. -- v > > -- > Peter > -- > http://mail.python.org/mailman/listinfo/python-list From steve at REMOVE-THIS-cybersource.com.au Fri Nov 13 02:19:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 07:19:08 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <00868cb9$0$26916$c3e8da3@news.astraweb.com> On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > When I was approximately 5, everybody knew that higher level languages were too slow for high-speed numeric computation (I actually didn't know that then, I was too busy watching Bill and Ben the Flowerpot Men), and therefore assembly languages were mandatory. Then IBM developed Fortran, and higher-level languages were not too slow for numeric computation. Vincent, could you please fix your mail client, or news client, so that it follows the standard for mail and news (that is, it has a hard-break after 68 or 72 characters? Having to scroll horizontally to read your posts is a real pain. -- Steven From alfps at start.no Fri Nov 13 02:51:30 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 13 Nov 2009 08:51:30 +0100 Subject: Does turtle graphics have the wrong associations? In-Reply-To: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> References: <757c46c8-8218-4397-a7d1-aaaa95583d52@k13g2000prh.googlegroups.com> Message-ID: * Raymond Hettinger: > On Nov 11, 10:21 pm, "Alf P. Steinbach" wrote: >> One reaction to has >> been that turtle graphics may be off-putting to some readers because it is >> associated with children's learning. >> >> What do you think? > > How about calling it Raptor Graphics that will please everyone ;-) He he. :-) import turtle as raptor raptor.shape( "triangle" ) def draw_poison_bush( level, angle, stem_length ): start_pos = raptor.pos() raptor.left( angle ) raptor.forward( stem_length ) if level > 0: draw_poison_bush( level-1, 30, 0.7*stem_length ) draw_poison_bush( level-1, 0, 0.85*stem_length ) draw_poison_bush( level-1, -37, 0.65*stem_length ) raptor.right( angle ) raptor.goto( start_pos ) raptor.title( "A DANGEROUS poison bush!" ) raptor.left( 90 ) raptor.back( 180 ) draw_poison_bush( 6, 0, 80 ) raptor.mainloop() Cheers, - Alf From vmanis at telus.net Fri Nov 13 02:53:10 2009 From: vmanis at telus.net (Vincent Manis) Date: Thu, 12 Nov 2009 23:53:10 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9F5C4977-87BC-446B-AFE7-7C7BAE83ABAC@telus.net> On 2009-11-12, at 23:19, Steven D'Aprano wrote: > On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > > Vincent, could you please fix your mail client, or news client, so > that it follows the standard for mail and news (that is, it has a > hard-break after 68 or 72 characters? My apologies. Will do. > Having to scroll horizontally to read your posts is a real pain. At least you're reading them. :) -- v -------------- next part -------------- An HTML attachment was scrubbed... URL: From catalinfest at gmail.com Fri Nov 13 03:06:20 2009 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Fri, 13 Nov 2009 00:06:20 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: Tkinter is deafult on python . Is more easy to use any editor text (geany). I don?t see a good IDE for GUI On Nov 9, 6:49?am, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these > things . . . From alfps at start.no Fri Nov 13 03:11:29 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 13 Nov 2009 09:11:29 +0100 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: * Peter Nilsson: > "Alf P. Steinbach" wrote: >> One reaction to has >> been that turtle graphics may be off-putting to some >> readers because it is associated with children's learning. > > [I'll be honest and say that I merely glanced at the two > pdf files.] > > Who is your target audience? Someone intelligent who doesn't know anything or very much about programming and wants to learn general programming. > The opening Getting Started > paragraph would probably put off many beginners right from > the get go! You're talking about a 'first language' but > throwing 'syntax', 'windows', 'graphics', 'networking', > 'file and database access' and 'standard libraries' at them. > > The success of 'XXXX for Dummies' is certainly not their > accuracy, but rather that they make far fewer assumptions > that people already know the subject being tought! That > assumption seems almost ingrained in every 'beginner' > programming book I've ever seen! Yes, I totally agree with not assuming knowledge. However, (without implying that you think so) lack of knowledge is not lack of brains. I assume an intelligent reader, someone who doesn't balk at a few technical terms here and there. Pedagogically it's a challenge, because a correspondence between knowledge and brains is so often assumed, and the field of knowledge accordingly (but mostly by historical accident) divided up into "basic", "medium level" and "advanced". And so an explanation of something that's trivial to someone who already knows, something in the "basic" category, might seem (to someone who confuses knowledge with brains) to assume a dumb or childish reader. But in reality the intellectual challenge of something in the traditional "basic" category can be greater than for something conventionally regarded as "advanced". So I strive to not make any distinction between traditional levels of knowledge in the field, but rather to focus on what's relevant and on how hard something would be to grasp for someone without the base knowledge and experience. >> What do you think? > > Whilst everyone knows children tend to think visually more > than abstractly, the same is precisely true of adults. > However, the ultimate problem with Turtle is that it ends > up teaching a 'mathematical' perspective and it's far from > intuitive how you map that perspective to tackling more > real world issues. It's simply substituting one difficult > abstraction with another. > > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. > > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) > > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. Uhm, yes, I agree. I've tried to limit the math to what most anyone can handle. No geometry so far! Although it will have to be discussed for graphics. But although most ch 2 examples are graphical, graphics generation as such is not discussed. It's like the difference between driving a car and designing one. You don't need an engineering degree to drive a car. :-) Cheers, & thanks, - Alf From rjh at see.sig.invalid Fri Nov 13 03:27:00 2009 From: rjh at see.sig.invalid (Richard Heathfield) Date: Fri, 13 Nov 2009 08:27:00 +0000 Subject: Does turtle graphics have the wrong associations? References: Message-ID: In , Alf P. Steinbach wrote: > But in reality the intellectual challenge of something in the > traditional "basic" category can be greater than for something > conventionally regarded as "advanced". And consequently is much harder to teach. I have nothing but admiration for primary school children and their teachers, because children can *actually learn to read*. Once you can read, future learning objectives become much easier to achieve. Same with programming - once you've grokked the core ideas, the rest is more or less window dressing in comparison. The gap between nought and one is much greater than the gap between one and a thousand. > It's like > the difference between driving a car and designing one. You don't > need an engineering degree to drive a car. :-) Right. Nowadays, you need a degree in electronics instead. -- Richard Heathfield Email: -http://www. +rjh@ "Usenet is a strange place" - dmr 29 July 1999 Sig line vacant - apply within From catalinfest at gmail.com Fri Nov 13 03:39:19 2009 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Fri, 13 Nov 2009 00:39:19 -0800 (PST) Subject: Create video with text? References: <4afbb851$0$22531$607ed4bc@cv.net> Message-ID: On Nov 12, 9:24?am, AK wrote: > Hi, what would be the best python package (or a framework that can be > scripted in python) that can make a video with text moving around, > jumping, zooming in/out and various other text effects? See the > following link for an example: > > Yes, If you using both blender 3d and python . From eckhardt at satorlaser.com Fri Nov 13 03:43:14 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 13 Nov 2009 09:43:14 +0100 Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <2qivs6-v5e.ln1@satorlaser.homedns.org> Santiago Romero wrote: > Well, In the above concrete example, that would work, but I was > talking for multiple code lines, like: > > > #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) > > #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > reg = r_op > > #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) > > #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmpl = Z80ReadMem(r_op); \ > r_tmph = Z80ReadMem((r_op)+1); \ > dreg=r_tmp > > #define STORE_nn_rr(dreg) \ > r_opl = Z80ReadMem(r_PC); r_PC++;\ > r_oph = Z80ReadMem(r_PC); r_PC++; \ > r_tmp = dreg; \ > Z80WriteMem((r_op),r_tmpl, regs); \ > Z80WriteMem((r_op+1),r_tmph, regs) Someone writing such code and calling it C should be taken behind the barn and shot. Which system runs Python but doesn't have a C compiler that knows inlining? > But it seems that is not possible :-( Thank getenv("DEITY") not! Uli From anders.u.persson at gmail.com Fri Nov 13 03:55:00 2009 From: anders.u.persson at gmail.com (uap12) Date: Fri, 13 Nov 2009 00:55:00 -0800 (PST) Subject: A beginner question about GUI use and development Message-ID: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Hi! I have written som Python programs but no one with a GUI yet, i have look around and found a lot of diffrent gui module. I will develop program that will use a small amout of GUI part eg. program to show status about server etc. I have looked att wxWidget, but i like a rekommendation here (Will develop Windows program but somtimes OSX to) When i givet the program away i like to pack it, so the enduser just run it, i don't like to tell the user to install Python, and/or som GUI package. is this possible. In the beginning it is okej to code the gui "by hand" to learn but after that i like som kind of GUI-designtool, and god to recommade ?? I know this is basic question, but i have't found any god answer so if some takes time to answer i would be happy. Best regards Anders From mal at egenix.com Fri Nov 13 04:03:54 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 13 Nov 2009 10:03:54 +0100 Subject: open source linux -> windows database connectivity? In-Reply-To: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> References: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> Message-ID: <4AFD20FA.2010408@egenix.com> Tony Schmidt wrote: >> Note: The client part of this product is free. You only need to >> get a license for the server part. > > Yeah, but don't I need the server part to make the connection? Sure, but you don't need to get a license per client, unlike for e.g. the combination mxODBC + EasySoft OOB. Regards, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 13 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 dpalmboom at evafoam.co.za Fri Nov 13 04:40:57 2009 From: dpalmboom at evafoam.co.za (Dylan Palmboom) Date: Fri, 13 Nov 2009 11:40:57 +0200 Subject: Choosing GUI Module for Python Message-ID: -----Original Message----- From: catalinfest at gmail.com [mailto:catalinfest at gmail.com] Sent: 13 November 2009 10:06 AM To: python-list at python.org Subject: Re: Choosing GUI Module for Python Tkinter is deafult on python . Is more easy to use any editor text (geany). I don?t see a good IDE for GUI On Nov 9, 6:49?am, Antony wrote: > Hi all > ? ?I just wanted to know which module is best for developing designing > interface in python . > i have come across some modules which are listed here . please tell > your suggestions and comments to choose best one > ?1. PyGTK > ?2. PyQT > ?3. PySide > ?4. ?wxPython > ?5 . TKinter > > Also i need to know is there any IDE for developing these things . . . PyQt is an excellent toolkit for us at work. It has nice documentation and very easy to learn. We use Eclipse IDE at work with the PyDev workspace loaded for the coding. Eclipse has nice features for integration with subversion all from one place, so it makes it more manageable when you have more than 1 person working on a project. There's only 2 of us here working together, but the subversion integration makes our lives so much easier. We use eclipse for gui design in code or we use Qt Creator which is very intuitive to use if you want to design a gui visually. Also, there's a python script we use called MakePyQt that you can find here: http://www.qtrac.eu/pyqtbook.tar.gz to convert the ui files from Qt Creator to python files. Then all you need to do is implement these generated python files in your program and add functionality etc. From michael at stroeder.com Fri Nov 13 05:04:57 2009 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 13 Nov 2009 11:04:57 +0100 Subject: Linux, Python 2.5.2, serverless binding LDAP? In-Reply-To: References: <1eb44a37-65b0-4a41-aa48-f69d4268018d@37g2000yqm.googlegroups.com> Message-ID: <9jnvs6-s4f.ln1@nb2.stroeder.com> Kevin Cole wrote: > On Nov 12, 8:01 pm, alex23 wrote: >> On Nov 13, 10:47 am, Kevin Cole wrote: >>> I recently asked our IT department how to gain access to an >>> addressbook. After carefully explaining that I was on a Linux system >>> using Python, I got the reply: >>> "You should use our LDAP. With LDAP you can pull any data you want >>> from Active Directory. On our network, the serverless binding address >>> for our LDAP is ldap://dc=...,dc=...,dc=...,dc=..." >>> with the actual "..." filled in. >>> I don't know squat about LDAP, but installed the python-ldap deb, and >>> started glancing at the documentation on-line. I didn't see anything >>> obvious for working with the URI above. Can I work w/ it? If so, a >>> short example, please? >>> Thanx. >> http://www.python-ldap.org/doc/html/ldapurl.html#example > > Ah, it wasn't clear to me that "localhost:1389" meant serverless. > Armed with that, I'm off to experiment. localhost:1389 means localhost on port 1389. It has nothing to do with server-less bind. Server-less bind is based on a DNS lookup: Let's say you want to query the DNS server for returning the LDAP server(s) for naming context dc=uninett,dc=no then invoke on the command-line: $ host -t srv _ldap._tcp.uninett.no. _ldap._tcp.uninett.no has SRV record 0 0 389 ldap.uninett.no. That is also heavily used with MS AD. Off course you can do this SRV lookup with http://pydns.sf.net which is actually done in my LDAP client http://web2ldap.de: http://demo.web2ldap.de:1760/web2ldap?ldap:///dc=uninett,dc=no??one Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com From gonatan at gmx.de Fri Nov 13 05:24:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Fri, 13 Nov 2009 11:24:10 +0100 Subject: A beginner question about GUI use and development In-Reply-To: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <4AFD33CA.8030804@gmx.de> uap12 wrote: > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. So Tkinter would be your choice, cause its shipped with Python ... > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? http://wiki.python.org/moin/GuiProgramming From 4564 at 755189.45 Fri Nov 13 05:38:08 2009 From: 4564 at 755189.45 (Enrico) Date: Fri, 13 Nov 2009 11:38:08 +0100 Subject: A beginner question about GUI use and development References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> "uap12" ha scritto nel messaggio news:1a446fef-4250-4152-8c30-cfe2edb61089 at j4g2000yqe.googlegroups.com... > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) You have a lot of option. I use wx since I need an OS native interface and work on Windows, Linux and Mac. But your needs could be different.so maybe QT could be a good choice for you, or Tk. I suggest to give them a try and decide. You can find many examples and without writing to much code you can have an idea on the library. For example for the wx you have a complete suite of example that you can run and modify. > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. This is not related to the GUI. If you don't want your user to have Python and other packages installed you need to "build" the application. Look at py2exe and friends (freeze, py2app,...). You can prepare an application with everything needed to run it and install/copy it on the user machine. Regards, Enrico From tartley at tartley.com Fri Nov 13 05:40:28 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Fri, 13 Nov 2009 02:40:28 -0800 (PST) Subject: bootstrapping on machines without Python Message-ID: While examining py2exe et al of late, my thoughts keep returning to the idea of writing, in C or similar, a compiled stand-alone executable 'bootstrapper', which: 1) downloads and install a Python interpreter if none exists 2) runs the application's Python source code using this interpreter. An application source code could be distributed with this small exe to wrap its top level 'main.py', and the application could then be run on machines which do not (yet) have Python installed. The goal of this is to provide a way for end-users to download and double-click a Python application, without having to know what Python is or whether (an appropriate version of) it is installed. This method has some disadvantages compared to using py2exe et al, but it has the advantage that a small application would remain small: there is no need to bundle a whole interpreter with every application. From an advocacy point of view, it also must help that merely running such an application would seamlessly put a usable Python interpreter installed and on the PATH on Windows boxes. Even my very limited understanding of the issues is enough to see that the idea is far from trivial. I'm aware that great minds are working on related and overlapping problems, so I thought I'd ask whether many people have done this already, and if not, is there any value in taking the trivial first step described above? ie. Ignore all complications, and write a simple C program to download & install an interpreter, then use that to run my Python. In the long run, to be useful for real projects, the bootstrapper would need to manage some nasty details: * different versions of the interpreter for different applications * download required packages * manage conflicting versions of packages I'm hoping that these thorny problems will be solved, if they aren't already, by the great minds working on packaging, etc. I'm very aware that I don't know anything at all about this, compared to many on the list. Be gentle with me. :-) From python.list at tim.thechases.com Fri Nov 13 05:48:59 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 13 Nov 2009 04:48:59 -0600 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4AFD399B.4060705@tim.thechases.com> Steven D'Aprano wrote: > Vincent, could you please fix your mail client, or news > client, so that it follows the standard for mail and news > (that is, it has a hard-break after 68 or 72 characters? This seems an awfully curmudgeonly reply, given that word-wrapping is also client-controllable. Every MUA I've used has afforded word-wrap including the venerable command-line "mail", mutt, Thunderbird/Seamonkey, pine, Outlook & Outlook Express...the list goes on. If you're reading via web-based portal, if the web-reader doesn't support wrapped lines, (1) that sounds like a lousy reader and (2) if you absolutely must use such a borked web-interface, you can always hack it in a good browser with a greasemonkey-ish script or a user-level CSS "!" important attribute to ensure that the
    or

    in question wraps even if the site tries to specify otherwise. There might be some stand-alone news-readers that aren't smart enough to support word-wrapping/line-breaking, in which case, join the 80's and upgrade to one that does. Or even just pipe to your text editor of choice: vi, emacs, ed, cat, and even Notepad has a "wrap long lines" sort of setting or does the right thing by default (okay, so cat relies on your console to do the wrapping, but it does wrap). I can see complaining about HTML content since not all MUA's support it. I can see complaining about top-posting vs. inline responses because that effects readability. But when the issue is entirely controllable on your end, it sounds like a personal issue. -tkc From davea at ieee.org Fri Nov 13 06:05:48 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 13 Nov 2009 06:05:48 -0500 Subject: 3.x and 2.x on same machine (is this info at Python.org??) In-Reply-To: <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> Message-ID: <4AFD3D8C.7020108@ieee.org> Dan Bishop wrote: > On Nov 12, 1:52 pm, rantingrick wrote: > >> Hello, >> >> Currently i am using 2.6 on Windows and need to start writing code in >> 3.0. I cannot leave 2.x yet because 3rd party modules are still not >> converted. So i want to install 3.0 without disturbing my current >> Python2.x. What i'm afraid of is that some SYSVARIABLE will get >> changed to Python3.0 and when i double click a Python script it will >> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts >> from the command line... > python3.x myscript.py >> >> So how do i do this? Is my fear unfounded? >> > > Windows determines the double-click action based on the file > extension. You just have to make sure that *.py files are associated > with 2.x. > http://support.microsoft.com/kb/307859 > > > And if someone simply wants to check or change these associations without all the Explorer nonsense, one can use assoc.exe and ftype.exe Using them without parameters lists all association information. Using them with parameters let you examine and/or change a single association. M:\Programming\Python\sources\dummy>assoc .py .py=Python.File M:\Programming\Python\sources\dummy>ftype python.file python.file="C:\PROGFI~1\ACTIVE~1\python.exe" "%1" %* Similarly for .pyw extension DaveA From kmisoft at gmail.com Fri Nov 13 06:06:43 2009 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Fri, 13 Nov 2009 14:06:43 +0300 Subject: A beginner question about GUI use and development In-Reply-To: <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> <4afd375c$0$1097$4fafbaef@reader3.news.tin.it> Message-ID: Hi, I have working with wxPython since about 2003 and still have a "mixed" feeling about it. Periodically I was catched in some traps especially in graphics-related parts of my code (just one example: try to find documentation about DC.Blit behaviour then UserScale != 1.0). For fresh-starters I would recommend to try a PyQT first (IMHO good commercial background/support is a big plus for any open-source project). Another option (my person choise so far) is to switch to web-based interface. My personal choice - web based interface using Django. Vladimir Ignatov >> Hi! >> I have written som Python programs but no one with a GUI yet, >> i have look around and found a lot of diffrent gui module. >> >> I will develop program that will use a small amout of GUI part >> eg. program to show status about server etc. >> >> I have looked att wxWidget, but i like a rekommendation here >> (Will develop Windows program but somtimes OSX to) From sromero at gmail.com Fri Nov 13 06:20:41 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 03:20:41 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> I'm going to quote all the answers in a single post, if you all don't mind: > [greg] > But keep in mind that named "constants" at the module level > are really global variables, and therefore incur a dictionary > lookup every time they're used. > > For maximum speed, nothing beats writing the numeric literals > directly into the code, unfortunately. So, finally, there are not constants available in python? (Like:) #define R1 1 > Generally, I think you're going to have quite a battle on > your hands to get a pure Python implementation to run as > fast as a real Z80, if it's even possible at all. Well... I'm trying to emulate the basic Z80, clocked at 3.5Mhz.. I hope python in a 2Ghz computer can emulate a 3.5Mhz machine ... Finally, if it's not possible... well, then I would just have some fun... :-) > [Steven D'Aprano] > The shift and mask are a little faster on my machine, but that's > certainly what I would call a micro-optimization. Unless the divmod call > is the bottleneck in your code -- and it almost certainly won't be -- It can be a real bottleneck. An emulator executes continously machine code instructions. Those machine code instructions are read from memory, and operands are read from memory too. The minimum opcode (00h -> NOP) requires 1 memory read, and the CPU task is read from mem & decode & execute. My problem is that I would need to "encapsulate" Memory reads and Memory Writes in functions. In C I use #define so that: - No function call is done (?code unrolling?) - I can "call" my function so I don't have to manually repeat my code - I can optimize my "#define" macro just once and all the "calls" are optimized too. This way (in C) I can write readable code and the compiler replaces my "readable macros" with the final code. > I don't think it's worth the obfuscation to use shift/mask. An idea. I think I'm going to write a layer previous to my python program, to allow to use macros in my emulator, and generate the final .py program with a script. VERY SIMPLE EXAMPLE: My program: File emulator.pym: ================================== #!/usr/bin/python import blah import sys MACRO BEGIN Z80WriteMem( address, value ) blablablah inc blah p = p + x MACRO END MACRO BEGIN Z80ReadMem( address ) ( memory[address>>4][blah] ) MACRO END (more code) pepe = @@@Z80ReadMem( reg_A ) (more code) @@@Z80WriteMem( 0x121212, value ) ================================== And then, use a script to replace macro calls @@@ by the final code. This way I could write my emulator with "macros" and my "preprocessor" would rewrite the final .py files for the "binary" releases. While I can keep the .pym files as the "real" source (because .py files would be generated from .pym macro-files). Can the above be easily done with another already-existing application? (example: can m4 do this job)? From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:04:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:04:32 -0300 Subject: 2to3 ParseError with UTF-8 BOM References: <50ad856e-8118-4374-82a4-58243ae3434b@13g2000prl.googlegroups.com> Message-ID: En Fri, 06 Nov 2009 14:12:57 -0300, Farshid escribi?: > On Nov 5, 7:18 pm, Benjamin Peterson wrote: > >> Try the 2to3 distributed in Python 3.1. > > I get the same error with the 2to3 script in Python 3.1 Reported as http://bugs.python.org/issue7313 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:04 -0300 Subject: Python C API and references References: Message-ID: En Thu, 12 Nov 2009 06:23:54 -0300, lallous escribi?: > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I > don't need the reference to py_val I should decrement the reference > after this call? If you own a reference to py_val, and you don't need it anymore, you must decrement it. It doesn't matter if you call PyObject_SetAttrString or whatever, except when the called function says it "steals" a reference. > So for example: > > PyObject *py_val = PyInt_FromLong(5) > PyObject_SetAttrString(py_obj, "val", py_val); > Py_DECREF(py_val) > > Right? Yes, because PyInt_FromLong returns a new reference, and you own it. > If so, take sysmodule.c: > > if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) > return NULL; > > Shouldn't they also call Py_DECREF(Py_None) ? No, because the reference count of Py_None was not incremented previously; the code doesn't own a reference to Py_None at that time. It's not the same as the example above. > Same logic applies to PyDict_SetItemString() and the reference should be > decrement after setting the item (ofcourse if the value is not needed). Yes, same as your first example. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:21 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:21 -0300 Subject: Unexpected python exception References: <7d121326-ab5f-4151-8edb-f69bc6f9dee5@b36g2000prf.googlegroups.com> Message-ID: En Wed, 11 Nov 2009 11:11:31 -0300, Ralax escribi?: > On Nov 11, 6:59 pm, Richard Purdie wrote: >> def B(): >> os.stat("/") >> import os >> >> Traceback (most recent call last): >> File "./test.py", line 12, in >> B() >> File "./test.py", line 8, in B >> os.stat("/") >> UnboundLocalError: local variable 'os' referenced before assignment >> >> If I remove the "import os" from B(), it works as expected. >> From what I've seen, its very unusual to have something operate >> "backwards" in scope in python. Can anyone explain why this happens? > > One word, Python treat objects in a function or method-scope as > locals. Not exactly; from the Language Reference [1]: "The following constructs bind names: formal parameters to functions, import statements, class and function definitions (these bind the class or function name in the defining block), and targets that are identifiers if occurring in an assignment, for loop header, or in the second position of an except clause header. The import statement of the form ?from ...import *? binds all names defined in the imported module, except those beginning with an underscore. This form may only be used at the module level. [...] If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." > So os is not defined in B(), is it right? "os" is a local name due to import, and starts uninitialized; using it before it is initialized raises UnboundLocalError [1] http://docs.python.org/reference/executionmodel.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:07:31 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:07:31 -0300 Subject: questions regarding stack size use for multi-threaded python programs References: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Message-ID: En Mon, 09 Nov 2009 16:05:31 -0300, Eyal Gordon escribi?: > background: > we are using python 2.4.3 on CentOS 5.3 with many threads - and our > shell's > default stack size limit is set to 10240KB (i.e. ~10MB). > > we noticed that python's Threading module appears to create threads with > this value as their stack size (we ran a sample program that creates 10 > threads and measured its virtual memory size, then reduced the stack size > limit of the shell to 5120KB - and saw that the program's virtual memory > size was reduced by ~50MBs). > > the problem: > our program uses numerous threads, and thus the virtual memory size gets > to > be very large. we would like to reduce the size of the stack to reduce > this > size. we were looking for information about recommendation for the stack > size to use, but found none. You can set the thread stack size (for threads that are going to be created, not existing threads) using threading.stack_size(SIZE) http://docs.python.org/library/threading.html#threading.stack_size > questions: > 1. is there some rule-of-thumb for the recommended stack size for python > programs of various sorts? No idea. I've been always happy with the default settings. > 2. is there a way for us, at runtime (from inside the code or outside the > process), to find how much of a thread's stack we are using (in KB or > some > other size units)? see top(1) > 3. when we define local objects - do the objects themselves get > allocated on > the stack - or are they allocated on the heap and only references to them > are kept on the stack? They're allocated on the heap, and most references to objects are on the heap too. The Python stack of execution frames is allocated on the heap too. Basically, the OS stack is used for local variables in C code only. > 4. would the size of the stacks (which are probably not really allocated > by > the linux virtual memory sub-system, unless used) have a noticeable > performance effect on a python program? same question regarding the use > of a > large number of threads? I think it doesn't matter, unless you create so many threads as to exhaust the available addressing space (in 32bits, 4GB address space and 10MB per thread means 400 threads maximum). -- Gabriel Genellina From sromero at gmail.com Fri Nov 13 07:21:00 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 04:21:00 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> Message-ID: <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> > > #define STORE_nn_rr(dreg) \ > > ? ? ? ? ? ? ? ? ? ? ? ? r_opl = Z80ReadMem(r_PC); r_PC++;\ > > ? ? ? ? ? ? ? ? ? ? ? ? r_oph = Z80ReadMem(r_PC); r_PC++; \ > > ? ? ? ? ? ? ? ? ? ? ? ? r_tmp = dreg; \ > > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op),r_tmpl, regs); \ > > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op+1),r_tmph, regs) > > Someone writing such code and calling it C should be taken > behind the barn and shot. That code is mine and maybe you should look the context before doing such kind of affirmations. In the Intel Pentium and P-II ages, I started to wrote the very first Spectrum emulator in C. With that "cpu power", emulators had to be written in ASM to be capable to emulate the destination machines at 100% full speed in multitasking systems. In the emulation world, every CPU cycle you can save is gold, and writing the above code as inline code saved lots of CALLS, PUSHs/POPs (parameters to stack), and RETs. That allowed ASpectrum to run 100% speed on old computers and even to be ported to the Sega Dreamcast's 200Mhz CPU. Think that Z80ReadMem() can be called up to 6 times in each emulated CPU-cycle. Saving 6 CALLs, 6 PUSHes, 6 POPs, and 6 RETs in each cycle of the 3.500.000 of Hz **did** make the difference that allow Aspectrum to run at 100% speed in ancient machines. Obviously, I prefer to write well structured code but I had to sacrifize SIZE by SPEED (size as inline code is included in the binary executable file). Each coding technique has their application environment and using inline macros, like loop unrolling or using "register" variables fall bellow all the techniques needed to write a fast emulator. Now I'm porting the emulator to a scripted language, so I need even more previous design ideas before starting to code, so that I can achieve (I hope I'll be able to do it with this group's help) 100% cpu speed in an standard desktop PC. > > ?But it seems that is not possible :-( > > Thank getenv("DEITY") not! Well, I don't agree with that, "constants" and "macros" wouldn't hurt python, when using them in the right situations. Thanks a lot anyway for all your help :-) From steve at REMOVE-THIS-cybersource.com.au Fri Nov 13 07:24:13 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Nov 2009 12:24:13 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <0086d43a$0$26932$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 04:48:59 -0600, Tim Chase wrote: > There might be some stand-alone news-readers that aren't smart enough to > support word-wrapping/line-breaking, in which case, join the 80's and > upgrade to one that does. Of course I can change my software. That fixes the problem for me. Or the poster can get a clue and follow the standard -- which may be as simple as clicking a checkbox, probably called "Wrap text", under Settings somewhere -- and fix the problem for EVERYBODY, regardless of what mail client or newsreader they're using. -- Steven From duncan.booth at invalid.invalid Fri Nov 13 07:35:07 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Nov 2009 12:35:07 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Nah, exceptions are an ugly effect that gets in the way of > parallelism. Haskell handles lookups through its type system; dealing > with lookup errors (say by chaining the Maybe type) is clean and > elegant. Erlang handles it by crashing the process, and dealing with > the crash through a supervision tree that cleans up after crashes and > restarts the crashed processes. I said exceptions or any other method of error handling. >> What that article didn't mention, and what is possibly Go's real >> strong point is that it has built-in support for parallel processing. >> Again though the implementation looks weak... > > I'd like to know more about this; is there a link with a short > write-up? I haven't gotten around to looking at the reference > materials. I just read the reference manual. As I understand it: Any function or method can be executed in parallel: instead of calling the function you use the go keyword: go doSomething(); go routines are executed using a thread pool, and an individual go routine might vary its execution thread depending on which threads are available. Most types are not thread safe, so you should never access any mutable value from more than one go routine. If you need to access something like a map from multiple parallel routines you need to use channels to protect it. You can declare and pass around channel variables. A channel can hold values or pointers of any type and has a specific number of free slots. e.g. var ch = make(chan int, 3); would create a channel that holds 3 int values. To write to a channel (blocking if it is full): ch <- value; To read from a channel (blocking if empty): value <- ch; To read from a channel blocking and discarding the result (e.g. to wait for a routine to finish): <- ch; To read without blocking: value, ok <- ch; ok set true if something was read. And to write without blocking: ok := ch <- value; or in fact any write in an expression context. You can also use a select statement (syntax similar to a switch statement) to read or write channels in parallel. It arbitrarily chooses one of the case statements that can proceed to execute, otherwise if there is a default statement it executes that. If there is no default statement the entire select blocks until one of the case statements can proceed. e.g. (example from the docs) var c1, c2 chan int; var i1, i2 int; select { case i1 = <-c1: print("received ", i1, " from c1\n"); case c2 <- i2: print("sent ", i2, " to c2\n"); default: print("no communication\n"); } There doesn't seem to be any way to specify a timeout on a read or write. I think you can create a timer channel with regular ticks and select from that to provide an effective timeout, but that sounds like a lot of boilerplate if you have to do very often. -- Duncan Booth http://kupuguy.blogspot.com From gagsl-py2 at yahoo.com.ar Fri Nov 13 07:53:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 13 Nov 2009 09:53:02 -0300 Subject: Writing an emulator in python - implementation questions (for performance) References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> Message-ID: En Thu, 12 Nov 2009 23:29:03 -0300, greg escribi?: > Carl Banks wrote: >> You >> can define constants to access specific registers: >> R1L = 1 >> R1H = 2 >> R1 = 1 >> breg[R1H] = 2 >> print wreg[R1] > > But keep in mind that named "constants" at the module level > are really global variables, and therefore incur a dictionary > lookup every time they're used. > > For maximum speed, nothing beats writing the numeric literals > directly into the code, unfortunately. This recipe may improve speed dramatically in those cases: http://code.activestate.com/recipes/277940/ -- Gabriel Genellina From animator333 at gmail.com Fri Nov 13 07:57:04 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 04:57:04 -0800 (PST) Subject: object indexing and item assignment Message-ID: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> class MyFloat(object): def __init__(self, value=0.): self.value = value def set(self, value): self.value = value def get(self): return self.value class MyColor(object): def __init__(self, value=(0,0,0)): self.value = (MyFloat(value[0]), MyFloat(value[1]), MyFloat(value[2])) def set(self, value): self.value[0].set(value[0]) self.value[1].set(value[1]) self.value[2].set(value[2]) def get(self): return (self.value[0].get(), self.value[1].get(), self.value[2].get()) col = MyColor() col[0].set(0.5) # 'MyColor' object does not support indexing col[0] = 0.5 # 'MyColor' object does not support item assignment The last two lines of the script produce errors. (written as comments). I know it won't work as I am expecting. One solution I can think of is to rewrite MyFloat and MyColor by sub classing default python types "float and "tuple". Is this the only solution? Prashant Python 2.6.2 Win XP 32 From bearophileHUGS at lycos.com Fri Nov 13 07:58:11 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Fri, 13 Nov 2009 04:58:11 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: <83c50eec-be41-4142-8f10-bb4744702c90@w19g2000yqk.googlegroups.com> Santiago Romero: >Obviously, I prefer to write well structured code but I had to sacrifize SIZE by SPEED< In C99 you have "inline" (and gcc/gcc-llvm usually inline small functions anyway) that helps avoid many macros. > ?Now I'm porting the emulator to a scripted language, so I need > even more previous design ideas before starting to code, so that > I can achieve (I hope I'll be able to do it with this group's help) > 100% cpu speed in an standard desktop PC. The tecniques needed to speed up Python code are very different from the ones you use in C. You may need a lot of time to learn Python performance tricks. Psyco helps a lot. > ?Well, I don't agree with that, "constants" and "macros" wouldn't > hurt python, when using them in the right situations. I miss true constants in Python, but it may be impossible to add them to this language, because of how it uses references. In Python you rely on convention, writing their names ALL_UPPERCASE. Bye, bearophile From benjamin.kaplan at case.edu Fri Nov 13 08:10:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 13 Nov 2009 08:10:00 -0500 Subject: object indexing and item assignment In-Reply-To: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> References: <4a1b25a8-5163-48c9-8ad3-71f4244f4847@j19g2000yqk.googlegroups.com> Message-ID: On Fri, Nov 13, 2009 at 7:57 AM, King wrote: > class MyFloat(object): > ? ?def __init__(self, value=0.): > ? ? ? ?self.value = value > > ? ?def set(self, value): > ? ? ? ?self.value = value > > ? ?def get(self): > ? ? ? ?return self.value > > class MyColor(object): > ? ?def __init__(self, value=(0,0,0)): > ? ? ? ?self.value = (MyFloat(value[0]), > ? ? ? ? ? ? ? ? ? ? ? ?MyFloat(value[1]), > ? ? ? ? ? ? ? ? ? ? ? ?MyFloat(value[2])) > > ? ?def set(self, value): > ? ? ? ?self.value[0].set(value[0]) > ? ? ? ?self.value[1].set(value[1]) > ? ? ? ?self.value[2].set(value[2]) > > ? ?def get(self): > ? ? ? ?return (self.value[0].get(), > ? ? ? ? ? ? ? ?self.value[1].get(), > ? ? ? ? ? ? ? ?self.value[2].get()) > > col = MyColor() > col[0].set(0.5) # 'MyColor' object does not support indexing > col[0] = 0.5 # 'MyColor' object does not support item assignment > > > The last two lines of the script produce errors. (written as > comments). I know it won't work as I am expecting. One solution I can > think of is to rewrite MyFloat and MyColor by sub classing default > python types "float and "tuple". Is this the only solution? > > Prashant > > Python 2.6.2 > Win XP 32 > -- In order to support indexing and item assignment, implement the __getitem__ and __setitem__ methods. def __getitem__(self, index) : return self.value[index] def __setitem__(self, index, value) : self.value[index].set(value) > http://mail.python.org/mailman/listinfo/python-list > From bearophileHUGS at lycos.com Fri Nov 13 08:15:35 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Fri, 13 Nov 2009 05:15:35 -0800 (PST) Subject: Writing an emulator in python - implementation questions (for performance) References: Message-ID: <3d203266-8cd1-4fca-8c29-51845944b255@m16g2000yqc.googlegroups.com> Try creation an extension module with ShedSkin. Bye, bearophile From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri Nov 13 08:44:13 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 13 Nov 2009 13:44:13 +0000 (UTC) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: Santiago Romero wrote: > >> > #define STORE_nn_rr(dreg) \ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_opl = Z80ReadMem(r_PC); r_PC++;\ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_oph = Z80ReadMem(r_PC); r_PC++; \ >> > ? ? ? ? ? ? ? ? ? ? ? ? r_tmp = dreg; \ >> > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op),r_tmpl, regs); \ >> > ? ? ? ? ? ? ? ? ? ? ? ? Z80WriteMem((r_op+1),r_tmph, regs) >> >> Someone writing such code and calling it C should be taken >> behind the barn and shot. > > That code is mine and maybe you should look the context > before doing such kind of affirmations. > > In the Intel Pentium and P-II ages, I started to wrote the > very first Spectrum emulator in C. With that "cpu power", emulators > had to be written in ASM to be capable to emulate the destination > machines at 100% full speed in multitasking systems. > Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do not remember the CPU freqeuncy anymore, maybe 25MHz). First emulator in C that appeared on the emu-scene (I guess it was x128) needed 486 (~80MHz?) to run at realtime. Pentium and Pentium II was A LOT of power :-) ... > > Now I'm porting the emulator to a scripted language, so I need > even more previous design ideas before starting to code, so that > I can achieve (I hope I'll be able to do it with this group's help) > 100% cpu speed in an standard desktop PC. > >> > ?But it seems that is not possible :-( http://perl-spectrum.sourceforge.net/ It is quite fast IMHO. Just remember to use psyco... -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From mail at timgolden.me.uk Fri Nov 13 08:57:37 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Nov 2009 13:57:37 +0000 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <4AFD65D1.6040308@timgolden.me.uk> Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. Thinking aloud about what you're describing here... Assuming Windows, as your starting point is py2exe and I imagine that most Unix-like boxes already have Python on them. Step 1: The user downloads a tiny myapp.exe which is basically a zip of the myapp package / files plus an .exe header which will... Step 2a: ... download a minimised? (ie custom-built) Python interpreter and stdlib bundle which is just enough to run the app. Or... Step 2b: ... download and install the official python.org Windows installer for version x.y identified as the highest known to run this app if... Step 2bi) ... that version of the interpreter isn't already installed and registered on that machine (at least: for that user). My step 2a seems to be little better than a bundled py2exe, so I can only assume you mean Step 2b, especially given your comment below about ending up with an installation of Python where one wasn't before. This, though, seems fraught with accusations of backdoor installations etc. Have I misunderstood you? For the Record, I'm entirely in favour of moves to make Python use on Windows more seamless, attractive, consistent, etc. I was going to comment positively on your recent PyChooser widget and to plug a similar but unpublished one of my own. But I'm not sure if this particular proposal has enough wings to make it fly. TJG From philip at semanchuk.com Fri Nov 13 09:05:33 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 13 Nov 2009 09:05:33 -0500 Subject: A beginner question about GUI use and development In-Reply-To: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: <05D89213-4094-4B0F-9281-9CD5FC06063E@semanchuk.com> On Nov 13, 2009, at 3:55 AM, uap12 wrote: > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) Hej Anders, wxWidgets and PyQT are very popular. As Marcus pointed out, Tkinter has the advantage that it ships with Python. These three should be your top candidates. > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. Yes, but the solutions aren't straightforward. Look at py2exe for Windows and py2app for the Mac. I don't know what to recommend for *nix (Linux, FreeBSD, etc.) > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? wxGlade is popular for wxWidgets. I don't know about PyQT or Tkinter. Lycka till, Philip From robince at gmail.com Fri Nov 13 09:14:58 2009 From: robince at gmail.com (Robin) Date: Fri, 13 Nov 2009 06:14:58 -0800 (PST) Subject: bus error in Py_Finalize with ctypes imported Message-ID: <924dc50d-e99f-48d4-bbf8-ba48deaca347@w19g2000yqk.googlegroups.com> Hi, I am trying to embed Python in a MATLAB mex function. This is loaded into the MATLAB interpreter - I would like the Python interpreter to be initialized once and stay there for future calls. I added a call to Py_Finalize as a mexAtExit handler which is called when the library is unloaded in MATLAB (with clear funcname) or when MATLAB shuts down. So far, things were working well, but I get a random but easily repeatable bus error in Py_Finalize if I have imported ctypes. Here is my code: #include #include static int PYRUNNING = 0; static void Cleanup(void) { mexPrintf("Finalising Python...\n"); Py_Finalize(); } void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) { mexPrintf("hello from mex\n"); if (!PYRUNNING) { Py_Initialize(); PYRUNNING = 1; mexAtExit(Cleanup); PyRun_SimpleString("import ctypes"); } PyRun_SimpleString("print 'hello from python'"); } If I load, run the function, and unload many times eventually I get the following stack trace (whcih i don't get if I'm not import ctypes). Does anyone have any idea what might be up? Could it be a bug in Py_Finalize or ctypes? Is there a problem with my approach (ie is it bad to leave the interpreter initialized between mex function calls - it seems to work provided ctypes is not imported - but I need ctypes to access other mex functions from python). ------------------------------------------------------------------------ Bus error detected at Fri Nov 13 14:06:12 2009 ------------------------------------------------------------------------ Configuration: MATLAB Version: 7.8.0.347 (R2009a) MATLAB License: 161051 Operating System: Darwin 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386 Window System: The X.Org Foundation (10402000), display /tmp/ launch-2p1ZWg/:0 Current Visual: 0x24 (class 4, depth 24) Processor ID: x86 Family 6 Model 15 Stepping 10, GenuineIntel Virtual Machine: Java 1.6.0_15-b03-219 with Apple Inc. Java HotSpot (TM) Client VM mixed mode Default Encoding: ISO-8859-1 Fault Count: 1 Register State: eax = 00000000 ebx = 3483d9be ecx = 33ff7620 edx = 00000000 esi = 32fb4dc0 edi = 0000001a ebp = b0b69938 esp = b0b69920 eip = 3485559f flg = 00010282 Stack Trace: [0] Python:type_dealloc~(0x32fb4dc0, 0x33f70818, 0x34854f0b, 0x34844410) + 26 bytes [1] Python:dict_dealloc~(0x33fef930, 0x348e4b40 "__builtin__", 0xb0b699bc, 0xb0b699b8) + 142 bytes [2] Python:dict_dealloc~(0x33f429c0, 0x348ee58c "exitfunc", 0xb0b699d8, 0x348b96b0) + 142 bytes [3] Python:_PyImport_Fini~(0x348ee58c "exitfunc", 0, 0, 0) + 82 bytes [4] Python:Py_Finalize~(673024, 1, 0, 0x00ab4700) + 207 bytes [5] libmex.dylib:SafeExitFunctionCall(void (*)())(0x30365df0, 0xb0b69ab8, 0xb0b69a80, 0x0073d01b) + 66 bytes [6] libmex.dylib:mexClearMexFileDefault(impl_info_tag*)(0x33e0dce0, 1, 0, 0x015fa3d8 "7Mfh_mex") + 80 bytes [7] libmex.dylib:safeMexClearMexFile(impl_info_tag*&)(0xb0b69bec "???3", 1, 0x015fc080, 0) + 76 bytes [8] libmex.dylib:Mlm_mex::unload_file()(0x32b01290, 0, 0, 0) + 250 bytes [9] libmwm_dispatcher.dylib:Mlm_file::unload_mf()(0x32b01290, 0, 0, 0) + 18 bytes [10] libmwm_dispatcher.dylib:Mlm_MATLAB_fn::clear()(0x32b01290, 0, 0xb0b69c9c, 236) + 82 bytes [11] libmwm_dispatcher.dylib:void clear (Mlmmf_string_matcher, int)(0x05319c00, 0x33e24b8c "pytest", 0x30476300, 0x03f3b531 "pytest") + 296 bytes [12] libmwm_dispatcher.dylib:mdClearFunctionsByName(0x33e24b8c "pytest", 42, 0xb0b6adf8, 10) + 650 bytes [13] libmwm_interpreter.dylib:InterpBridge::FullClearFcn(int, mxArray_tag**, int, mxArray_tag**)(0x036225e0, 0, 0xb0b6af6c, 1) + 1234 bytes [14] libmwm_interpreter.dylib:inFullClearFcn(int, mxArray_tag**, int, mxArray_tag**)(0, 0xb0b6af6c, 1, 0xb0b6afcc) + 50 bytes [15] libmwm_dispatcher.dylib:Mfh_builtin::dispatch_mf(int, mxArray_tag**, int, mxArray_tag**)(0x2dd025a0, 0, 0xb0b6af6c, 1) + 95 bytes [16] libmwm_dispatcher.dylib:Mfh_MATLAB_fn::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x2dd025a0, 0, 0xb0b6af6c, 1) + 192 bytes [17] libmwm_interpreter.dylib:inDispatchFromStack(int, char const*, int, int)(0, 0x304fa51c "clear", 0, 1) + 998 bytes [18] libmwm_interpreter.dylib:inDispatchCall(char const*, int, int, int, int*, int*)(1, 0xb0b6b298, 0x33e11a28, 0x9322e76b) + 152 bytes [19] libmwm_interpreter.dylib:inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag volatile*, int*)(1, 0, 1, 0) + 5167 bytes [20] libmwm_interpreter.dylib:protected_inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(1, 0, 1, 0) + 112 bytes [21] libmwm_interpreter.dylib:inInterPcodeSJ(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(0, 0x33e007d0, 0xb0b6b460, 0xb0b6b460) + 266 bytes [22] libmwm_interpreter.dylib:inExecuteMFunctionOrScript(Mfh_mp*, bool)(0x33e263c0, 1, 0xb0b6b99c, 0) + 932 bytes [23] libmwm_interpreter.dylib:inRunMfile(int, mxArray_tag**, int, mxArray_tag**, Mfh_mp*, inWorkSpace_tag*)(0, 0xb0b6b99c, 0, 0) + 696 bytes [24] libmwm_interpreter.dylib:Mfh_mp::dispatch_file(int, mxArray_tag**, int, mxArray_tag**)(0x33e263c0, 0, 0xb0b6b99c, 0) + 56 bytes [25] libmwm_dispatcher.dylib:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x33e263c0, 0, 0xb0b6b99c, 0) + 256 bytes [26] libmwm_interpreter.dylib:inEvalPcodeHeaderToWord (_memory_context*, int, mxArray_tag**, _pcodeheader*, Mfh_mp*, unsigned int)(0x000a2ac8 "?*\n", 0, 0xb0b6b99c, 0xb0b6b83c) + 252 bytes [27] libmwm_interpreter.dylib:inEvalStringWithIsVarFcn (_memory_context*, char const*, EvalType, int, mxArray_tag**, inDebugCheck, _pcodeheader*, int*, bool (*)(void*, char const*), void*, bool, bool)(0, 0xb0b6b99c, 0, 0) + 1835 bytes [28] libmwm_interpreter.dylib:inEvalCmdWithLocalReturn(char const*, int*, bool, bool, bool (*)(void*, char const*))(1, 0x004aeb20, 0, 0) + 148 bytes [29] libmwm_interpreter.dylib:inEvalCmdWithLocalReturn(0x2e3e5e00 "clear pytest\n", 0, 0, 1) + 66 bytes [30] libmwbridge.dylib:evalCommandWithLongjmpSafety(char const*) (0x2e3e5e00 "clear pytest\n", 2, 0x2de28978, 4073223) + 108 bytes [31] libmwbridge.dylib:mnParser(0xb0b6bb34, 0x0501fc00, 1, 0) + 666 bytes [32] libmwmcr.dylib:mcrInstance::mnParser_on_interpreter_thread() (0x0501fc00, 8, 0x05016000, 4) + 43 bytes [33] libmwmcr.dylib:boost::function0::operator()() const (0x2dd33904 "??A", 0, 0xb0b6bc68, 171953) + 41 bytes [34] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::NoResultInvocationRequest::run ()(0x2dd338f0, 0, 0xb0b6bbe8, 172001) + 21 bytes [35] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::invocation_request_handler (long)(0x2dd338f0, 0, 0xb0b6bc38, 3636709) + 24 bytes [36] libmwuix.dylib:uix_DispatchOrProcess(_XEvent*, _XtAppStruct*, int, bool)(0, 15, 0x000f4240 "put_target_string_with_length", 0x4afd6790) + 476 bytes [37] libmwuix.dylib:ws_ProcessPendingEventsHelper(int, int, bool)(1, 0xffffffff, 0, 852585) + 469 bytes [38] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::process_events (boost::shared_ptr const&) (0x036519b0, 0xb0b6be68, 0, 0x03651960 "/Applications/ MATLAB_R2009a.app/..") + 376 bytes [39] libmwmcr.dylib:mcr::runtime::InterpreterThread::Impl::run (boost::shared_ptr const&, mcr::runtime::InterpreterThread::Impl::init_context*)(0x036519b0, 0xb0b6be68, 0xb0182cac, 4078061) + 410 bytes [40] libmwmcr.dylib:run_init_and_handle_events(void*)(0xb0182cac, 0, 0, 0) + 52 bytes [41] MATLAB:create_mcrInstance_and_run_mnParser(0xb0b6bf00 "@?A", 8816, 0, 0) + 553 bytes [42] MATLAB:start(2, 0xbffff4d0 "????????", 0xb0b6c000 "DRHT", 0xffffffff) + -2223 bytes [43] libmwmcr.dylib:runMcrMain(void*)(0xbffff440 "?%", 0x04000000, 1, 0) + 39 bytes [44] libSystem.B.dylib:_pthread_start~(0xb0b6c000 "DRHT", 13827, 0x004075f0, 0xbffff440 "?%") + 345 bytes [45] libSystem.B.dylib:thread_start~(0, 0, 0, 0x54485244) + 34 bytes From cr88192 at hotmail.com Fri Nov 13 09:22:09 2009 From: cr88192 at hotmail.com (BGB / cr88192) Date: Fri, 13 Nov 2009 07:22:09 -0700 Subject: Does turtle graphics have the wrong associations? References: Message-ID: "Peter Nilsson" wrote in message news:ed7d74f6-c84d-40f1-a06b-642f988fb464 at x25g2000prf.googlegroups.com... > "Alf P. Steinbach" wrote: >> One reaction to >> has >> been that turtle graphics may be off-putting to some >> readers because it is associated with children's learning. > > [I'll be honest and say that I merely glanced at the two > pdf files.] > > Who is your target audience? The opening Getting Started > paragraph would probably put off many beginners right from > the get go! You're talking about a 'first language' but > throwing 'syntax', 'windows', 'graphics', 'networking', > 'file and database access' and 'standard libraries' at them. > > The success of 'XXXX for Dummies' is certainly not their > accuracy, but rather that they make far fewer assumptions > that people already know the subject being tought! That > assumption seems almost ingrained in every 'beginner' > programming book I've ever seen! > yep, but I guess it depends some on the type of beginner... many beginner books take the style of lots of examples and verbosity, and trying to gradually ease the person into the topic, ... also common is more of a "crash course" style, where topics are introduced and defined, and where the contents tend to be far more categorical (in these books, often the later chapters and/or appendices are long, and often consist largely of definitions and reference material). there are merits to both styles I think... I have also seen where they try to fictionalize the topic, or turn it into some huge mass of allegories, but I don't really like this style so much... it is possible the 'turtle' may hold these sorts of associations... >> What do you think? > > Whilst everyone knows children tend to think visually more > than abstractly, the same is precisely true of adults. > However, the ultimate problem with Turtle is that it ends > up teaching a 'mathematical' perspective and it's far from > intuitive how you map that perspective to tackling more > real world issues. It's simply substituting one difficult > abstraction with another. > > My recollection is that many children struggled with Turtle > graphics because they had very little concept of trigonometry. > [Why would they? Many wouldn't learn for another 2-10 years.] > Adults tend to have even less concept since they almost never > use trig (or much else from school ;-) in the real world. > yep, much the same as trying to teach trig in a pseudo-fantasy setting by addressing the relative dimensions of the various parts of Excalibur... one gets much more amusement out of just watching a sword fight where all they do is whack the swords into each other and pause momentarily, with whoever was doing the mixing unable to get the delay between the swords hitting and the 'clang' much less than about 300ms... > They can see the patterns and understand there's a logic to > it, but they struggle replicating it. Get an angle wrong > and you end up with a mess where it's not clear whether it's > your algorithm or the maths that's at fault. > yep... simple, unstructured, thinking is easier. if one screws up somewhere, it is a lot easier to find and correct the problem. this is probably part of why procedural and OO have traditionally been more popular than functional programming: one does not have to try to bend their mind so much to get things written or figure out just what the hell is going on... granted, some level of mind-bending in necessary for programming, but IMO it is more of a necessary evil... > The visual aspect might pique interest, but may put just as > many people off. In any case, it won't relieve the difficulty > of having to teach what is fundamentally an abstraction that > doesn't have very good parallels with how people approach > problems in the real world. Humans simply don't think like > mathematicians^W computers. :-) > > I've met a lot of mathematics and comp sci teachers who > honestly believe that you can't teach these subjects without > a mathematical perspective. That stands in contrast to the > number of people I see using spreadsheets with a very high > proficiency who would never dream of saying they were good > at mathematics or programming. > apparently, I don't even approach math in a mathematical manner... I had thought I had understood math, and I use it enough, but I am suspecting that the thing I am familiar with is a good deal different than that seen by mathematicians (partly as a result of some interactions with, and observation of, physics teachers...). or, it could be that my world is severely 'bent' because of my exposure to computers, and almost complete lack of need or desire to write proofs or to expand-out and perform huge amounts of symbolic manipulations by hand... so, I guess my difficulty curve is rather "unusual" as well... I live in a world where vectors and matrices are fairly simple, and quaternions would be, apart from my near inability to intuitively understand or visualize their behaviors... and, in this same world, set theory and predicate logic are evil beasts best avoided at all cost... and, it seems, traditional math screws me over even with seemingly trivial problems... and, it does not take long to figure out that, for example, even a trivial operation such as renormalizing a vector becomes a marathon of pain... A= |A|=sqrt(Ax^2+Bx^2+Cx^2) B=A/|A| = = =... I would far much rather think: N(A)=A/|A| and leave it as that, this way we factor out everything leaving mostly abstract operations... (once we know the operation, we no longer need to care what it is or how it works...). but, other people want to expand everything out and turn it into a big evil-looking mess, bleh... > -- > Peter From robince at gmail.com Fri Nov 13 09:27:23 2009 From: robince at gmail.com (Robin) Date: Fri, 13 Nov 2009 06:27:23 -0800 (PST) Subject: bus error in Py_Finalize with ctypes imported References: <924dc50d-e99f-48d4-bbf8-ba48deaca347@w19g2000yqk.googlegroups.com> Message-ID: <37162f95-b36d-4880-b723-c3d4a337e1a0@k4g2000yqb.googlegroups.com> On Nov 13, 2:14?pm, Robin wrote: > I am trying to embed Python in a MATLAB mex function. This is loaded > into the MATLAB interpreter - I would like the Python interpreter to > be initialized once and stay there for future calls. I added a call to > Py_Finalize as a mexAtExit handler which is called when the library is > unloaded in MATLAB (with clear funcname) or when MATLAB shuts down. So > far, things were working well, but I get a random but easily > repeatable bus error in Py_Finalize if I have imported ctypes. Looks like I've run into this bug: http://bugs.python.org/issue6869 I will try the attached patch - hopefully it will make into a forthcoming release. Cheers Robin From martin.hellwig at dcuktec.org Fri Nov 13 09:31:05 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 13 Nov 2009 14:31:05 +0000 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. I can see two distinctive scenarios: - Local temporarily installation - System wide installation (possible conflicts with older versions) Anyway this reminds me of the web installers where you only download the installer which download the rest from the net, like they used to be available from adobe and for java. It should be doable, for example you have an executable which has only one function; download a second stage installer from a fixed location. That second stage installer is a bit bigger and knows how to check for dependencies for that particular platform and install other dependencies. So you can chain a lot of installers after each other, for example the second stage installer can be a python installer then you could do all the remaining installing from the convenience of python. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From mmitchell at transparent.com Fri Nov 13 09:32:37 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 13 Nov 2009 09:32:37 -0500 Subject: tkFileDialog question Message-ID: Hi, This is my first attempt to write a script with any kind of gui. All I need the script to do is ask the user for a directory and then do stuff with the files in that directory. I used tkFileDialog.askdirectory(). It works great but it pops up an empty tk window. Is there any way to prevent the empty tk window from popping up? Here's the code: import tkFileDialog answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks! Matt From jg.campbell.ng at gmail.com Fri Nov 13 09:54:37 2009 From: jg.campbell.ng at gmail.com (Jonathan Campbell) Date: Fri, 13 Nov 2009 14:54:37 +0000 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > One reaction to http://preview.tinyurl.com/ProgrammingBookP3> has been that turtle > graphics may be off-putting to some readers because it is associated > with children's learning. > Incidentally ... something you may wish to consider for inclusion in you book ... games programming and Pygame. See, e.g., Andy Harris, Game Programming (L Line: The Express Line to Learning), John Wiley & Sons, 2007, ISBN-10: 0470068221 or Will McGugan, Beginning Game Development with Python and Pygame : From Novice to Professional, APRESS, 2007, ISBN-10: 1590598725. I have the impression that there are many young people who could learn programming via games programming. On the other hand, in languages like C++ or Java, the threshold to games programming is extremely high. Not so using Pygame. The additional nice thing about Pygame is that it is based on a Python binding of SDL (Simple DirectMedia Layer) an open-source games API. This could mean easy migration to C++ games programming (using SDL). Best regards, Jon C. -- Jonathan Campbell www.jgcampbell.com BT48, UK. From chris at simplistix.co.uk Fri Nov 13 10:39:19 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 13 Nov 2009 15:39:19 +0000 Subject: Vote on PyPI comments Message-ID: <4AFD7DA7.4010706@simplistix.co.uk> Hi All, Apologies for the cross post, but I'm not sure this has received the publicity it deserves... PyPI grew a commenting and rating system a while back, apparently in response to requests from users. However, since it's been rolled out, there's been a backlash from package maintainers who already have mailing lists, bug trackers, etc for their packages and don't want to have to try and keep track of yet another support forum. The arguments for and against are listed here: http://wiki.python.org/moin/PyPIComments To resolve the future of the commenting and rating system, a vote has been set up so everyone can have their say. To vote, please log in to: http://pypi.python.org/pypi ...and follow the instructions you'll be presented with. I would like to remain neutral on this, and for me that means giving package authors the ability to choose whether they want to receive comments, ratings or neither rather than either forcing package authors to accept comments and ratings or abandoning the idea of comments and ratings completely. The closest option to that is: "Allow package owners to disallow comments (ratings unmodified)" I hope the majority of you feel the same way... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From michele.simionato at gmail.com Fri Nov 13 10:53:05 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 13 Nov 2009 07:53:05 -0800 (PST) Subject: Vote on PyPI comments References: Message-ID: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> On Nov 13, 4:39?pm, Chris Withers wrote: > > PyPI grew a commenting and rating system a while back, apparently in > response to requests from users. However, since it's been rolled out, > there's been a backlash from package maintainers who already have > mailing lists, bug trackers, etc for their packages and don't want to > have to try and keep track of yet another support forum. > I am skeptical about the utility of both rating and comments. If somebody wants to know if a package is good, she should ask here. From aahz at pythoncraft.com Fri Nov 13 11:07:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 08:07:47 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >>>Esky is an auto-update framework for frozen python apps, built on top of >>>bbfreeze. It provides a simple API through which apps can find, fetch >>>and install updates, and a bootstrapping mechanism that keeps the app >>>safe in the face of failed or partial updates. >> >> Recently I was looking into distribution mechanisms, and I passed over >> bbfreeze because I saw no indication that Python 2.6 was supported. > >Not sure if it's officially supported, but I do most of my development >on Python 2.6 and bbfreeze hasn't given me any problems as yet. Also, bbfreeze doesn't seem to have active development. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From lallous at lgwm.org Fri Nov 13 11:30:19 2009 From: lallous at lgwm.org (lallous) Date: Fri, 13 Nov 2009 17:30:19 +0100 Subject: Adding methods to an object instance Message-ID: Hello class __object(object): def __getitem__(self, idx): return getattr(self, idx) class __dobject(object): pass x = __object() setattr(x, "0", "hello") print x["0"] y = __dobject(a=1,b=2) setattr(y, "0", "world") #print y["0"] How can I, given an object of instance "__dobject", add to that instance a __getitem__ method so that I can type: print y["0"] Thanks, Elias From athenka25 at gmail.com Fri Nov 13 11:34:57 2009 From: athenka25 at gmail.com (Alena Bacova) Date: Fri, 13 Nov 2009 11:34:57 -0500 Subject: wsgi with separate css file Message-ID: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> Hi all, I just wanted to know if anybody tried using wsgi as a web server that would be serving html file with separate css file. I managed to make my wsgi server display only on html file ( it has got the form tag, and I'm serving do_get and do_post call to) but I would like to have formatting stored in separate css file, rather then embedded in html code. Plus being able to serve image files with the html would be nice addition. I tried to google the thing, but there wasn't any explicit example of such thing. After I get the do_get request from browser and html is posted I do get "do_get /file.css" request, but I have no idea how to serve that. Any help, examples, suggestions more then welcome. Thanks. Alena -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Fri Nov 13 11:42:20 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 13 Nov 2009 08:42:20 -0800 Subject: wsgi with separate css file In-Reply-To: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> Message-ID: On Fri, 13 Nov 2009 08:34:57 -0800, Alena Bacova wrote: > Hi all, > > I just wanted to know if anybody tried using wsgi as a web server that > would > be serving html file with separate css file. I managed to make my wsgi > server display only on html file ( it has got the form tag, and I'm > serving > do_get and do_post call to) but I would like to have formatting stored in > separate css file, rather then embedded in html code. Plus being able to > serve image files with the html would be nice addition. > > I tried to google the thing, but there wasn't any explicit example of > such > thing. After I get the do_get request from browser and html is posted I > do > get "do_get /file.css" request, but I have no idea how to serve that. > > Any help, examples, suggestions more then welcome. > Hi Alena, Can you tell us a little more about your setup? For instance, are you using the simple_server from the wsgiref module? Where are the application and CSS files being stored and run? Cheers Rami -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From animator333 at gmail.com Fri Nov 13 11:46:55 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 08:46:55 -0800 (PST) Subject: object serialization as python scripts Message-ID: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> I have looked upon various object serialization de-serialization techniques. (shelve, pickle, anydbm, custom xml format etc.) What I personally feel that instead of all these methods for saving the objects it would be easier to save the data as python scripts itself. In this case, loading the data is merely to run the script in the context itself. Need some expert advice and pointers here. Is there any thing (module, script, doc, article) helpful out there for the concern? Prashant Python 2.6.2 Win XP 32 From bruno.42.desthuilliers at websiteburo.invalid Fri Nov 13 11:47:02 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 17:47:02 +0100 Subject: Adding methods to an object instance In-Reply-To: References: Message-ID: <4afd8d6c$0$14707$426a34cc@news.free.fr> lallous a ?crit : > Hello > > class __object(object): the convention for reusing reserved words as identifiers is to *suffix* them with a single underscore, ie: class object_(object): # > def __getitem__(self, idx): > return getattr(self, idx) > > class __dobject(object): pass > > x = __object() > setattr(x, "0", "hello") > print x["0"] > > y = __dobject(a=1,b=2) > > setattr(y, "0", "world") > #print y["0"] > > How can I, given an object of instance "__dobject", add to that instance > a __getitem__ method so that I can type: > print y["0"] Adding per-instance methods won't work for __magic_methods__. But you could use the Decorator pattern here: class IndexableDecorator(object): def __init__(self, other): self._other = other def __getitem__(self, idx): return getattr(self._other, idx) def __setattr__(self, name, value): if name = "_other": object.__setattr__(self, name, value) else: setattr(self._other, name, value) x = IndexableDecorator(x) NB : not tested, so it probably contains at least one obvious error !-) From bryanvick at gmail.com Fri Nov 13 11:59:54 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Nov 2009 08:59:54 -0800 (PST) Subject: Dynamic property names on class Message-ID: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> I have several properties on a class that have very similar behavior. If one of the properties is set, all the other properties need to be set to None. So I wanted to create these properties in a loop like: class Test(object): for prop in ['foo', 'bar', 'spam']: # Attribute that data is actually stored in field = '_' + prop # Create getter/setter def _get(self): return getattr(self, field) def _set(self, val): setattr(self, field, val) for otherProp in prop: if otherProp != prop: setattr(self, '_' + otherProp, None) # Assign property to class setattr(Test, prop, property(_get, _set)) t = Test() t.foo = 1 assert t.bar == t.spam == None But the class Test is not defined yet, so I can't set a property on it. How can I do this? From rami.chowdhury at gmail.com Fri Nov 13 12:16:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 13 Nov 2009 09:16:27 -0800 Subject: wsgi with separate css file In-Reply-To: <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> Message-ID: On Fri, 13 Nov 2009 08:55:33 -0800, Alena Bacova wrote: > Hi, > I'm using: > > from wsgiref import simple_server > httpd = simple_server.make_server(HOST, PORT, Test) > try: > httpd.serve_forever() > except KeyboardInterrupt: > pass > > But I can use something else if needed. Application and htmk, css and > images are stored on the same machine, everything is stored in one > folder. > > Alena. > If you are just using this to learn to develop WSGI applications, I would recommend implementing a method to distinguish requests for static files, and handle them separately. A very naive implementation handling .css files might look like: from wsgiref import util import os def do_get(environ, start_response): REQUEST_URI = util.request_uri(environ) if (REQUEST_URI.endswith('.css')): return do_css(REQUEST_URI, start_response) # your regular code here def do_css(request_uri, start_response): full_path = os.path.abspath(os.path.join(MY_HTTP_DIRECTORY, request_uri)) if os.path.exists(full_path): file_obj = open(full_path, 'r') response_lines = file_obj.readlines() file_obj.close() start_response('200 OK', [('Content-Type', 'text/css')]) return response_lines else: start_response('404 Not Found', []) return [] However, this method is fragile and very inefficient. If you want to eventually deploy this application somewhere, I would suggest starting with a different method. Hope that helps, Rami -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From exarkun at twistedmatrix.com Fri Nov 13 12:23:39 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 13 Nov 2009 17:23:39 -0000 Subject: [ANN] pyOpenSSL 0.10 Message-ID: <20091113172339.3229.1288175132.divmod.xquotient.728@localhost.localdomain> I'm happy to announce the release of pyOpenSSL 0.10. pyOpenSSL 0.10 exposes several more OpenSSL APIs, including support for running TLS connections over in-memory BIOs, access to the OpenSSL random number generator, the ability to pass subject and issuer parameters when creating an X509Extension instance, more control over PKCS12 creation and an API for exporting PKCS12 objects, and APIs for controlling the client CA list servers send to clients. Several bugs have also been fixed, including a crash when certain X509Extension instances are deallocated, a mis-handling of the OpenSSL error queue in the X509Name implementation, Windows build issues, and a possible double free when using a debug build. The style of the docstrings for APIs implemented in C has also been changed throughout the project to be more useful to Python programmers. Extension type objects can also now be used to instantiate those types. Many thanks to numerous people who contributed patches to this release. You can find pyOpenSSL 0.10 on the Python Package Index: http://pypi.python.org/pypi/pyOpenSSL/0.10 You can now also find the pyOpenSSL documentation there: http://packages.python.org/pyOpenSSL/ As part of the ongoing transition away from SourceForge, I won't be uploading the release or the documentation to SourceForge. Please continue to use the pyOpenSSL Launchpad page for bug reports: https://launchpad.net/pyopenssl Enjoy! Jean-Paul Calderone From deets at nospam.web.de Fri Nov 13 12:33:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 18:33:48 +0100 Subject: object serialization as python scripts In-Reply-To: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> Message-ID: <7m5jjsF3egl9mU1@mid.uni-berlin.de> King schrieb: > I have looked upon various object serialization de-serialization > techniques. > (shelve, pickle, anydbm, custom xml format etc.) What I personally > feel that instead of all these > methods for saving the objects it would be easier to save the data as > python scripts itself. > In this case, loading the data is merely to run the script in the > context itself. > Need some expert advice and pointers here. Is there any thing (module, > script, doc, article) > helpful out there for the concern? Why is it easier than the above mentioned - they are *there* (except the custom xml), and just can be used. What don't they do you want to do? Other than that, and even security issues put aside, I don't see much difference between pickle and python code, except the latter being more verbose. Which suits humans, but other than that has no advantage. Diez From deets at nospam.web.de Fri Nov 13 12:34:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 18:34:58 +0100 Subject: Dynamic property names on class In-Reply-To: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> Message-ID: <7m5jm2F3egl9mU2@mid.uni-berlin.de> Bryan schrieb: > I have several properties on a class that have very similar behavior. > If one of the properties is set, all the other properties need to be > set to None. So I wanted to create these properties in a loop like: > > class Test(object): > for prop in ['foo', 'bar', 'spam']: > # Attribute that data is actually stored in > field = '_' + prop > # Create getter/setter > def _get(self): > return getattr(self, field) > def _set(self, val): > setattr(self, field, val) > for otherProp in prop: > if otherProp != prop: setattr(self, '_' + otherProp, None) > # Assign property to class > setattr(Test, prop, property(_get, _set)) > > t = Test() > t.foo = 1 > assert t.bar == t.spam == None > > But the class Test is not defined yet, so I can't set a property on > it. How can I do this? With a metaclass, or a post-class-creation function. Which is a metaclass without being fancy. Just put your above code into a function with the class in question as argument, and invoke it after Test is defined. Diez From tino at wildenhain.de Fri Nov 13 12:52:04 2009 From: tino at wildenhain.de (Tino Wildenhain) Date: Fri, 13 Nov 2009 18:52:04 +0100 Subject: Unexpected python exception In-Reply-To: <1257949761.29038.399.camel@dax.rpnet.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> <1257949761.29038.399.camel@dax.rpnet.com> Message-ID: <4AFD9CC4.4040408@wildenhain.de> Am 11.11.2009 15:29, schrieb Richard Purdie: > On Wed, 2009-11-11 at 05:04 -0800, Chris Rebert wrote: >> On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: >> >>> Is there a way to make the "global x" apply to all functions without >>> adding it to each one? >> >> Thankfully, no. > > Hmm :(. > >>> What I'm trying to do is to avoid having "import X" statements >>> everywhere by changing __builtin__. It seems my approach doesn't have >>> quite the same effect as a true import though. >> >> And you can't just put all your imports together at the top of the >> file because...? > > The application in question is bitbake, the parsing tool for the > OpenEmbedded and Poky projects. > > We're talking about python code fragments spread across about 8,000 > files which make up the "metadata" some of which is public and some of > which is not. Rightly or wrongly bitbake does some interesting things > with its execution contexts for these code fragments. And you can't just use __import__() to programmatically include some of the fragments instead of having this local/global weirdness in funtions in those modules? > Lets just say its not a traditional use case, we know the way bitbake > does some things is evil but it does other things rather well and we > can't break those. I'd need to see the bigger picture because I don't know of bitbake but I have a feeling this can be done much nicer in the end. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From bryanvick at gmail.com Fri Nov 13 13:20:32 2009 From: bryanvick at gmail.com (Bryan) Date: Fri, 13 Nov 2009 10:20:32 -0800 (PST) Subject: Dynamic property names on class References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> <7m5jm2F3egl9mU2@mid.uni-berlin.de> Message-ID: <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> On Nov 13, 9:34?am, "Diez B. Roggisch" wrote: > Bryan schrieb: > > > > > I have several properties on a class that have very similar behavior. > > If one of the properties is set, all the other properties need to be > > set to None. ?So I wanted to create these properties in a loop like: > > > class Test(object): > > ? ?for prop in ['foo', 'bar', 'spam']: > > ? ? ? ? ? ?# Attribute that data is actually stored in > > ? ? ? ? ? ?field = '_' + prop > > ? ? ? ? ? ?# Create getter/setter > > ? ? ? ? ? ?def _get(self): > > ? ? ? ? ? ? ? ? ? ?return getattr(self, field) > > ? ? ? ? ? ?def _set(self, val): > > ? ? ? ? ? ? ? ? ? ?setattr(self, field, val) > > ? ? ? ? ? ? ? ? ? ?for otherProp in prop: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?if otherProp != prop: setattr(self, '_' + otherProp, None) > > ? ? ? ? ? ?# Assign property to class > > ? ? ? ? ? ?setattr(Test, prop, property(_get, _set)) > > > t = Test() > > t.foo = 1 > > assert t.bar == t.spam == None > > > But the class Test is not defined yet, so I can't set a property on > > it. ?How can I do this? > > With a metaclass, or a post-class-creation function. Which is a > metaclass without being fancy. > > Just put your above code into a function with the class in question as > argument, and invoke it after Test is defined. > > Diez I think there are some closure issues with this as I am getting very strange results. I think all properties have the getter/setters of whatever the last item in the list was. t.foo = 'settingFoo' actually sets t.spam, as 'spam' was the last property generated. From jjposner at optimum.net Fri Nov 13 13:21:30 2009 From: jjposner at optimum.net (John Posner) Date: Fri, 13 Nov 2009 13:21:30 -0500 Subject: object indexing and item assignment In-Reply-To: References: Message-ID: <4AFDA3AA.5030403@optimum.net> King wrote: > class MyFloat(object): > def __init__(self, value=0.): > self.value = value > > def set(self, value): > self.value = value > > def get(self): > return self.value > > class MyColor(object): > def __init__(self, value=(0,0,0)): > self.value = (MyFloat(value[0]), > MyFloat(value[1]), > MyFloat(value[2])) > > def set(self, value): > self.value[0].set(value[0]) > self.value[1].set(value[1]) > self.value[2].set(value[2]) > > def get(self): > return (self.value[0].get(), > self.value[1].get(), > self.value[2].get()) > > col = MyColor() > col[0].set(0.5) # 'MyColor' object does not support indexing > col[0] = 0.5 # 'MyColor' object does not support item assignment > King, I think you might be trying too hard. (Since I don't know your "big picture", my suspicion might be wrong.) Python does not *require* you to implement "get" and "set" methods in user-defined classes. More detail ... * You might not need the MyFloat class at all. Try using a plain old Python "float" value. * You don't need the "set" and "get" methods in the MyColor class. So this might suffice: class MyColor(object): def __init__(self, value=(0.,0.,0.)): self.value = list(value) It's important for self.value to be a *list* object only if you want modify individual components of a MyColor instance. If you *do* want to modify individual components, then it *does* make sense to implement "set" and "get" methods: def set_comp(self, index, comp_value): self.value[index] = comp_value def get_comp(self, index): return self.value[index] For debugging, it makes senses to implement a __str__ or __repr__ method, so that "print" produces useful output: def __str__(self): return "MyColor: %3.1f %3.1f %3.1f" % tuple(self.value) Putting it all together ... #----------------- class MyColor(object): def __init__(self, value=(0.,0.,0.)): self.value = list(value) def __str__(self): return "MyColor: %3.1f %3.1f %3.1f" % tuple(self.value) def set_comp(self, index, comp_value): self.value[index] = comp_value def get_comp(self, index): return self.value[index] col = MyColor() print col # output: MyColor: 0.0 0.0 0.0 col.set_comp(0, 0.5) print col # MyColor: 0.5 0.0 0.0 col.set_comp(2, 0.7) print col # MyColor: 0.5 0.0 0.7 col = MyColor((0.2, 0.3, 0.4)) print col # MyColor: 0.2 0.3 0.4 #----------------- -John From animator333 at gmail.com Fri Nov 13 13:26:11 2009 From: animator333 at gmail.com (King) Date: Fri, 13 Nov 2009 10:26:11 -0800 (PST) Subject: object serialization as python scripts References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> Message-ID: <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> > Why is it easier than the above mentioned - they are *there* (except the > custom xml), and just can be used. What don't they do you want to do? > > Other than that, and even security issues put aside, I don't see much > difference between pickle and python code, except the latter being more > verbose. Which suits humans, but other than that has no advantage. > > Diez My application is PyQt based and objects that I am trying to save are couple of QGraphicsItem instances. You can't save instances of QGraphicsItem using pickle or shelve. Custom xml format would be a real pain as you have to write code for writing/reading both. I am aware of security issue but over all there are only 5 statements I have to use to get the entire information back. I can do syntax checking and other stuff before I should execute the script. Another reason is that data should be in human readable form. Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Fri Nov 13 13:45:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 13 Nov 2009 10:45:24 -0800 Subject: object serialization as python scripts In-Reply-To: <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> Message-ID: <50697b2c0911131045k691b4d3fq626ee13306c9ea2c@mail.gmail.com> On Fri, Nov 13, 2009 at 10:26 AM, King wrote: >> Why is it easier than the above mentioned - they are *there* (except the >> custom xml), and just can be used. What don't they do you want to do? >> >> Other than that, and even security issues put aside, I don't see much >> difference between pickle and python code, except the latter being more >> verbose. Which suits humans, but other than that has no advantage. >> >> Diez > > My application is PyQt based and objects that I am trying to save are > couple of QGraphicsItem instances. You can't save instances of > QGraphicsItem > using pickle or shelve. > Custom xml format would be a real pain as you have to write code for > writing/reading both. > > I am aware of security issue but over all there are only 5 statements > I have to use to get the entire > information back. I can do syntax checking and other stuff before I > should execute the script. > > Another reason is that data should be in human readable form. Did you consider the `json` module? JSON is almost identical to Python literal syntax. http://docs.python.org/library/json.html Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Fri Nov 13 14:04:52 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 13 Nov 2009 20:04:52 +0100 Subject: Vote on PyPI comments In-Reply-To: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: >> PyPI grew a commenting and rating system a while back, apparently in >> response to requests from users. However, since it's been rolled out, >> there's been a backlash from package maintainers who already have >> mailing lists, bug trackers, etc for their packages and don't want to >> have to try and keep track of yet another support forum. >> > > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. Hmm, do you really think subscribing to python-list should be a prerequisite for people who want to have some clue which python software they want to use? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ronn.ross at gmail.com Fri Nov 13 14:05:26 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Fri, 13 Nov 2009 14:05:26 -0500 Subject: No subject Message-ID: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> I'm attempting to convert latitude and longitude coordinates from degrees minutes and second to decimal form. I would like to go from: N39 42 36.3 W77 42 51.5 to: -77.739855,39.706666 Does anyone know of a library or some existing out their to help with this conversion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronn.ross at gmail.com Fri Nov 13 14:08:15 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Fri, 13 Nov 2009 14:08:15 -0500 Subject: converting latitude and longitude Message-ID: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> I'm attempting to convert latitude and longitude coordinates from degrees minutes and second to decimal form. I would like to go from: N39 42 36.3 W77 42 51.5 to: -77.739855,39.706666 Does anyone know of a library or some existing out their to help with this conversion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Greg.Tilson at ngc.com Fri Nov 13 14:23:31 2009 From: Greg.Tilson at ngc.com (Tilson, Greg (IS)) Date: Fri, 13 Nov 2009 13:23:31 -0600 Subject: Python 2.6.3 TarFile Module Add odd behavior Message-ID: <49AA837A96E75E4C8CD87901F7F14080032B1228@XMBIL103.northgrum.com> In Windows Python 2.6.3 calling TarFile.add requires arcname= to be set to work with WinZIP or WinRAR Documentation reads: TarFile.add(name, arcname=None, recursive=True, exclude=None) Add the file name to the archive. name may be any type of file (directory, fifo, symbolic link, etc.). If given, arcname specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting recursive to False. If exclude is given it must be a function that takes one filename argument and returns a boolean value. Depending on this value the respective file is either excluded (True) or added (False). Changed in version 2.6: Added the exclude parameter. If arcname= is not set during extraction all filenames are "None" Suggest document change or filing a bug report I am accessing comp.lang.python through email because of Northrop Grumman News server issue -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Nov 13 14:25:28 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Nov 2009 19:25:28 +0000 Subject: converting latitude and longitude In-Reply-To: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> References: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> Message-ID: <4AFDB2A8.5080200@mrabarnett.plus.com> Ronn Ross wrote: > > > I'm attempting to convert latitude and longitude coordinates from > degrees minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this conversion? > The conversion is simple enough. Why do you need a library? BTW, are you sure the values are correct? I get '-77.714306,39.710083'. From mal at egenix.com Fri Nov 13 14:43:19 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 13 Nov 2009 20:43:19 +0100 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <4AFDB6D7.5050903@egenix.com> Jonathan Hartley wrote: > While examining py2exe et al of late, my thoughts keep returning to > the idea of writing, in C or similar, a compiled stand-alone > executable 'bootstrapper', which: > 1) downloads and install a Python interpreter if none exists > 2) runs the application's Python source code using this interpreter. > > An application source code could be distributed with this small exe to > wrap its top level 'main.py', and the application could then be run on > machines which do not (yet) have Python installed. > > The goal of this is to provide a way for end-users to download and > double-click a Python application, without having to know what Python > is or whether (an appropriate version of) it is installed. This method > has some disadvantages compared to using py2exe et al, but it has the > advantage that a small application would remain small: there is no > need to bundle a whole interpreter with every application. There are two major issues with such an approach: * users will not necessarily like it if a small application downloads a several MB from the web somewhere without asking * installing applications on Windows typically requires admin rights or at least user interaction I think a good solution to the problem is wrapping the application's main.py in a batch file which pops up a window to let the user know that s/he will need to install Python first and point him/her to the www.python.org web site, if necessary. Another aspect to consider is whether a py2exe wrapped Python application is really too big at all. We ship a rather complex application using py2exe (mxODBC Connect Server) and the resulting installed footprint is just around 14 MB - that's roughly the size of a typical YouTube video. By comparison, a full Python 2.5 installation is around 84 MB and includes lots of stuff normally not needed for a small Python application. > From an > advocacy point of view, it also must help that merely running such an > application would seamlessly put a usable Python interpreter installed > and on the PATH on Windows boxes. > > Even my very limited understanding of the issues is enough to see that > the idea is far from trivial. I'm aware that great minds are working > on related and overlapping problems, so I thought I'd ask whether many > people have done this already, and if not, is there any value in > taking the trivial first step described above? ie. Ignore all > complications, and write a simple C program to download & install an > interpreter, then use that to run my Python. > > In the long run, to be useful for real projects, the bootstrapper > would need to manage some nasty details: > * different versions of the interpreter for different applications > * download required packages > * manage conflicting versions of packages > I'm hoping that these thorny problems will be solved, if they aren't > already, by the great minds working on packaging, etc. > > I'm very aware that I don't know anything at all about this, compared > to many on the list. Be gentle with me. :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 13 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 deets at nospam.web.de Fri Nov 13 14:46:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 20:46:54 +0100 Subject: Dynamic property names on class In-Reply-To: <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> References: <188eaf88-87b3-425c-bc94-65f37b7a9971@r24g2000yqd.googlegroups.com> <7m5jm2F3egl9mU2@mid.uni-berlin.de> <20582116-3160-4d4a-90ee-0d3073fd1c4b@d10g2000yqh.googlegroups.com> Message-ID: <7m5rdeF3fvmqmU1@mid.uni-berlin.de> Bryan schrieb: > On Nov 13, 9:34 am, "Diez B. Roggisch" wrote: >> Bryan schrieb: >> >> >> >>> I have several properties on a class that have very similar behavior. >>> If one of the properties is set, all the other properties need to be >>> set to None. So I wanted to create these properties in a loop like: >>> class Test(object): >>> for prop in ['foo', 'bar', 'spam']: >>> # Attribute that data is actually stored in >>> field = '_' + prop >>> # Create getter/setter >>> def _get(self): >>> return getattr(self, field) >>> def _set(self, val): >>> setattr(self, field, val) >>> for otherProp in prop: >>> if otherProp != prop: setattr(self, '_' + otherProp, None) >>> # Assign property to class >>> setattr(Test, prop, property(_get, _set)) >>> t = Test() >>> t.foo = 1 >>> assert t.bar == t.spam == None >>> But the class Test is not defined yet, so I can't set a property on >>> it. How can I do this? >> With a metaclass, or a post-class-creation function. Which is a >> metaclass without being fancy. >> >> Just put your above code into a function with the class in question as >> argument, and invoke it after Test is defined. >> >> Diez > > I think there are some closure issues with this as I am getting very > strange results. I think all properties have the getter/setters of > whatever the last item in the list was. > t.foo = 'settingFoo' actually sets t.spam, as 'spam' was the last > property generated. That's a FAQ. Closures capture the *names*, not the values. There are various options to remedy this, e.g. by something like this: def gen_property(prop): def _get(...) # your code return property(_get, _set) setattr(Test, prop, gen_property(prop)) Diez From deets at nospam.web.de Fri Nov 13 14:50:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 13 Nov 2009 20:50:53 +0100 Subject: Vote on PyPI comments In-Reply-To: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: <7m5rktF3fvmqmU2@mid.uni-berlin.de> Michele Simionato schrieb: > On Nov 13, 4:39 pm, Chris Withers wrote: >> PyPI grew a commenting and rating system a while back, apparently in >> response to requests from users. However, since it's been rolled out, >> there's been a backlash from package maintainers who already have >> mailing lists, bug trackers, etc for their packages and don't want to >> have to try and keep track of yet another support forum. >> > > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. The ratio user to posters certainly speaks against that - for any given package, there are so many users that never appear here - but they stil might share insights about the package. Diez From toby at rcsreg.com Fri Nov 13 15:28:43 2009 From: toby at rcsreg.com (Tobiah) Date: Fri, 13 Nov 2009 20:28:43 GMT Subject: run all scripts in sub-directory as subroutines? References: Message-ID: <%jjLm.16238$We2.1157@newsfe09.iad> > This works fine, but in the sub-modules the sys.path appropriately > returns the same as from the parent, I want them to know their own file > names. How?? I can pass it to them, but wondered if there is a more > self-sufficient way for a module to know from where it was invoked. I like the idea of passing the information to the module. Probably by setting a global variable into it. From aaron.watters at gmail.com Fri Nov 13 15:37:59 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 13 Nov 2009 12:37:59 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On Nov 11, 3:15?pm, Terry Reedy wrote: > Robert P. J. Day wrote: > I can imagine a day when code compiled from Python is routinely > time-competitive with hand-written C. That time is now, in many cases. I still stand by my strategy published in Unix World ages ago: get it working in Python, profile it, optimize it, if you need to do it faster code the inner loops in C. Of course on google app engine, the last step is not possible, but I don't think it is needed for 90% of applications or more. My own favorite app on google app engine/appspot is http://listtree.appspot.com/ implemented using whiff http://whiff.sourceforge.net as described in this tutorial http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2300.GAEDeploy not as fast as I would like sporadically. But that's certainly not Python's problem because the same application running on my laptop is *much* faster. By the way: the GO language smells like Rob Pike, and I certainly hope it is more successful than Limbo was. Of course, if Google decides to really push it then it's gonna be successful regardless of all other considerations, just like Sun did to Java... -- Aaron Watters === Limbo: how low can you go? From russ.paielli at gmail.com Fri Nov 13 15:41:40 2009 From: russ.paielli at gmail.com (Russ P.) Date: Fri, 13 Nov 2009 12:41:40 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <95ce4d22-194e-4807-b464-c8fc53709696@12g2000pri.googlegroups.com> On Nov 12, 12:06?pm, "Russ P." wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. Has anyone tried this? From Brian.Mingus at Colorado.EDU Fri Nov 13 15:46:15 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Fri, 13 Nov 2009 13:46:15 -0700 Subject: python simply not scaleable enough for google? In-Reply-To: <00868cb9$0$26916$c3e8da3@news.astraweb.com> References: <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> On Fri, Nov 13, 2009 at 12:19 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Thu, 12 Nov 2009 22:20:11 -0800, Vincent Manis wrote: > > > When I was approximately 5, everybody knew that higher level languages > were too slow for high-speed numeric computation (I actually didn't know > that then, I was too busy watching Bill and Ben the Flowerpot Men), and > therefore assembly languages were mandatory. Then IBM developed Fortran, and > higher-level languages were not too slow for numeric computation. > > Vincent, could you please fix your mail client, or news client, so > that it follows the standard for mail and news (that is, it has a > hard-break after 68 or 72 characters? > > Having to scroll horizontally to read your posts is a real pain. > > You're joking, right? Try purchasing a computer manufactured in this millennium. Monitors are much wider than 72 characters nowadays, old timer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmitchell at transparent.com Fri Nov 13 15:47:52 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 13 Nov 2009 15:47:52 -0500 Subject: tkFileDialog question In-Reply-To: References: Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Matt Mitchell Sent: Friday, November 13, 2009 9:33 AM To: python-list at python.org Subject: tkFileDialog question Hi, This is my first attempt to write a script with any kind of gui. All I need the script to do is ask the user for a directory and then do stuff with the files in that directory. I used tkFileDialog.askdirectory(). It works great but it pops up an empty tk window. Is there any way to prevent the empty tk window from popping up? Here's the code: import tkFileDialog answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks! Matt -- http://mail.python.org/mailman/listinfo/python-list Hi, After a few more hours of googling I answered my own question: import Tkinter, tkFileDialog root = Tk() root.withdraw() answer = tkFileDialog.askdirectory() if answer is not '': #do stuff Thanks!! From theller at python.net Fri Nov 13 15:48:45 2009 From: theller at python.net (Thomas Heller) Date: Fri, 13 Nov 2009 21:48:45 +0100 Subject: bootstrapping on machines without Python In-Reply-To: References: Message-ID: <7m5v1cF3gihrvU1@mid.individual.net> M.-A. Lemburg schrieb: > Jonathan Hartley wrote: >> While examining py2exe et al of late, my thoughts keep returning to >> the idea of writing, in C or similar, a compiled stand-alone >> executable 'bootstrapper', which: >> 1) downloads and install a Python interpreter if none exists >> 2) runs the application's Python source code using this interpreter. >> >> An application source code could be distributed with this small exe to >> wrap its top level 'main.py', and the application could then be run on >> machines which do not (yet) have Python installed. >> >> The goal of this is to provide a way for end-users to download and >> double-click a Python application, without having to know what Python >> is or whether (an appropriate version of) it is installed. This method >> has some disadvantages compared to using py2exe et al, but it has the >> advantage that a small application would remain small: there is no >> need to bundle a whole interpreter with every application. > > There are two major issues with such an approach: > > * users will not necessarily like it if a small application > downloads a several MB from the web somewhere without asking > > * installing applications on Windows typically requires admin > rights or at least user interaction > > I think a good solution to the problem is wrapping the application's > main.py in a batch file which pops up a window to let the user know > that s/he will need to install Python first and point him/her to the > www.python.org web site, if necessary. Here is a batch file that simulates a similar approach, for demonstration purposes it doesn't download and install python, instead it simply copies 'c:\python25\python.exe' to the current directory under a different name (if it is not yet present), and executes the script with it. Batchfile experts should also be able to improve other things: @echo off && if exist py_exe.exe (py_exe.exe -x %0 %* && goto exit) else (goto download) # The python script import sys print "Hi, this is Python", sys.version sys.exit() # rest of the batch file """ :download echo Simulating download... copy c:\python25\python.exe py_exe.exe echo Done. REM start the script again after downloading %0 %* :exit rem """ Thomas From bdesth.quelquechose at free.quelquepart.fr Fri Nov 13 15:53:27 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 21:53:27 +0100 Subject: New syntax for blocks In-Reply-To: <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <1039425e-f923-4add-b19c-21f765d33147@p28g2000vbi.googlegroups.com> Message-ID: <4afdd4d8$0$22644$426a74cc@news.free.fr> r a ?crit : > On Nov 12, 7:44 pm, Steven D'Aprano cybersource.com.au> wrote >> Oh, but those hundreds of thousands of man-hours lost to bugs caused by >> assignment-as-an-expression is nothing compared to the dozens of man- >> minutes saved by having one fewer line of code! > > OK, what *if* the variable would only be valid in *that* block and > *that* block only! Python doesn't have the notion of a "block scope" (or "block namespace"). > My first idea was to have the variable avaiable in > the local scope (if that is correct terminology?) so if the > conditional was in global space the value would be available in global > space, alright? You follow me? Now forget all that and observe the > following. ;-) > > if value=range(10): > #this block *would* execute and "value" would be a valid name > #but only IN this block!!! > value.append(1) > elif value=fetch(0): > #this block would *never* execute > value.append(1) > > value.append(1) -> this throws a NameError Yuck. > > Is that different than how other languages handle "assignment-by- > expression"? Will that avoid the cataclysmic downward spiral you speak > of? It's different, but only worse. It doesn't solve the problem of mystyping "=" instead of "==" - which is the reason why Python's assignement is not an expression, and it's not even consistent with mainstream languages that support "assignement as an expression". > I can't see any problems with it I do see at least two big ones !-) Now I don't mean there's not a use case for some "assign and test" syntax - Carl provided a good one, and indeed there are some cases where a dispatcher is *not* the simplest and obvious solution. But by all means, not *this* syntax. From cgrebeld at gmail.com Fri Nov 13 15:58:39 2009 From: cgrebeld at gmail.com (chris grebeldinger) Date: Fri, 13 Nov 2009 12:58:39 -0800 (PST) Subject: 2.6.4 Mac x86_64 ? Message-ID: Hi All, I've been having some trouble getting a x86_64/i386 universal readline.so to build against libedit, on MacOS 10.5.6 as Apple does. Does anyone have any pointers about what changes I need to make to setup.py or readline.c to achive this? Has someone already done this and would like to share it? Are there any plans to provide 64 bit support in future Mac OS 2.6.x releases? Thanks From cmpython at gmail.com Fri Nov 13 16:08:20 2009 From: cmpython at gmail.com (CM) Date: Fri, 13 Nov 2009 13:08:20 -0800 (PST) Subject: A beginner question about GUI use and development References: <1a446fef-4250-4152-8c30-cfe2edb61089@j4g2000yqe.googlegroups.com> Message-ID: On Nov 13, 3:55?am, uap12 wrote: > Hi! > I have written som Python programs but no one with a GUI yet, > i have look around and found a lot of diffrent gui module. > > I will develop program that will use a small amout of GUI part > eg. program to show status about server etc. > > I have looked att wxWidget, but i like a rekommendation here > (Will develop Windows program but somtimes OSX to) In the context of Python, it is called wxPython. WxWidgets is the C++ version (and around which wxPython is a thin wrapper). > When i givet the program away i like to pack it, so the enduser > just run it, i don't like to tell the user to install Python, and/or > som GUI package. is this possible. As others mentioned, yes. Many people use py2exe for Windows, and py2app for Mac OS X. These have nothing to do with the choice of GUI, though. However, if you choose wxPython as the widget toolkit, you can use a really nice application called GUI2Exe, which is a GUI interface for py2exe, py2app, and a few other such tools, and makes creating a packaged-up executable much easier. > In the beginning it is okej to code the gui "by hand" to learn > but after that i like som kind of GUI-designtool, and god > to recommade ?? Sure--that's one good way. I learned the other way around: by using a GUI designer to teach me what options there were for widgets and how they were coded. One nice IDE and GUI builder for wxPython is Boa Constructor. > I know this is basic question, but i have't found any god answer > so if some takes time to answer i would be happy. Googling these issues or searching this group should turn up dozens of answers and opinions; it has been asked many times. Che From aaron.watters at gmail.com Fri Nov 13 16:13:57 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 13 Nov 2009 13:13:57 -0800 (PST) Subject: wsgi with separate css file References: <341a9a480911130834w271c28b9m8c467f56f509497c@mail.gmail.com> <341a9a480911130855q1b05a7f7jc02e554129bff27e@mail.gmail.com> Message-ID: RE: serving static CSS files using WSGI > ...However, this method is fragile and very inefficient. If you want to ? > eventually deploy this application somewhere, I would suggest starting ? > with a different method. The WHIFF WSGI tools are meant to make this kind of thing easy. In fact the quick start tells you how to do this http://aaron.oirt.rutgers.edu/myapp/docs/W0500.quickstart And if you want to deploy to the Google App Engine there's a tutorial for that too: http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2300.GAEDeploy For example the http://listtree.appspot.com/ service is implemented using WHIFF under the Google App Engine environment. -- Aaron Watters === TO INFINITY... AND BEYOND! From bdesth.quelquechose at free.quelquepart.fr Fri Nov 13 16:20:16 2009 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 13 Nov 2009 22:20:16 +0100 Subject: New syntax for blocks In-Reply-To: <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> Message-ID: <4afddb20$0$27405$426a74cc@news.free.fr> r a ?crit : > On Nov 12, 2:37 pm, Bruno Desthuilliers > wrote: > >>> Oh i get it now! If i assign a valid value to a variable the variable >>> is also valid...thats...thats... GENUIS! *sarcasm* >> It's not about "assigning a valid value to a variable", it's about the >> name being created (or not) in the current namespace, whatever it's >> bound to. > > And thats what my sarcasm was alluding to. Steven's argument is moot > because it will blow up either way due to the fact that "value" is non- > existent! Sorry, but Steve's code, ie: var = range(100) if var: ... will not break - after the first line, the name "var" exists, whether it's bound to true or false value. While with your proposal *as it is* (or at least as I and Steve understood it), the existence of name "var" depends on some unpredictable condition. > Every argument that has been brought forth about how this > will break is just False Actually, identity testing on True or False is considered a very bad practice. You really want equality testing > and basically a bunch of FUD! It just garbage > so you can discredit the idea. Please take a deep breath and calm down. There's no conspiracy, no secret plan, no hidden agenda, and pointing out the shortcomings of a proposals is definitly not "discredit"ing "the idea". > It's actually quite funny when someone as small as me can bring down > the iron curtain of c.l.py. > '''Mr. Gorbachev, Tear down this wall!''' > > How about one of you "esteemed" Pythonista's show me a real example > where it will break. Steve did. But I'm afraid you missed his point. > > PS: And if it were so dangerous why would someone as knowledgeable as > Carl have stepped in and supported it. Carl supported the idea of a syntax for "assignment and test", but that's not what Steve's comments were about - well, it may be that Steve also refuses to consider the whole idea, but he still has a good point wrt/ some shortcoming of your idea in it's current state. > I think because (like me) Carl > put's the language before sewing circles. I think it's just personal > like all the times before, Well, to be true, you did manage to make a clown of yourself more than once, so don't be surprised if some people here tend to treat you as one - even when you come up with something that _may_ have some value. > that's OK, i have very thick skin! If it's > wrong for a good reason i will graciously accept that, but no one has > proven it's non-worth, not yet! wrong != non-worth. I mean: having some possibly valid use case doesn't imply the proposed solution is the good one in it's current state. And pointing out the shortcomings of the proposed solution doesn't imply the problem is not real neither (now whether it's a critical enough problem to _require_ a solution is another problem I won't even debate here). Anyway, just going to personal considerations won't help. If you ever hope to be taken seriously, first behave as a reasonably sensible and mature person. My (hopefully friendly) 2 cents. From no.email at please.post Fri Nov 13 16:26:01 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 21:26:01 +0000 (UTC) Subject: The ol' [[]] * 500 bug... Message-ID: ...just bit me in the "fuzzy posterior". The best I can come up with is the hideous lol = [[] for _ in xrange(500)] Is there something better? What did one do before comprehensions were available? I suppose in that case one would have to go all the way with lol = [None] * 500 for i in xrange(len(lol)): lol[i] = [] Yikes. 10 miles uphill, both ways... kynn From tjreedy at udel.edu Fri Nov 13 16:48:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Nov 2009 16:48:44 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: Aaron Watters wrote: > On Nov 11, 3:15 pm, Terry Reedy wrote: >> Robert P. J. Day wrote: >> I can imagine a day when code compiled from Python is routinely >> time-competitive with hand-written C. > > That time is now, in many cases. By routinely, I meant ***ROUTINELY***, as in "C become the province of specialized tool coders, much like assembly is now, while most programmers use Python (or similar languages) because they cannot (easily) beat it with hand-coded C." We are not yet at *tha* place yet. > I still stand by my strategy published in Unix World > ages ago: get it working in Python, profile it, optimize > it, if you need to do it faster code the inner loops in > C. Agreed By the way: the GO language smells like Rob Pike, and I certainly hope it is more successful than Limbo was. Of course, if Google decides to really push it then it's gonna be successful regardless of all other considerations, just like Sun did to Java... > By the way: the GO language smells like Rob Pike, > and I certainly hope it is more successful than It still has the stupid, unnecessary, redundant C brackets, given that all their example code is nicely indented like Python. That alone is a deal killer for me. Terry Jan Reedy From eugene.druker at gmail.com Fri Nov 13 16:51:55 2009 From: eugene.druker at gmail.com (ezd) Date: Fri, 13 Nov 2009 13:51:55 -0800 (PST) Subject: converting latitude and longitude References: <9c8c445f0911131108ped608e4g2df4481dd78d46fa@mail.gmail.com> Message-ID: On Nov 13, 2:25?pm, MRAB wrote: > Ronn Ross wrote: > > > I'm attempting to convert latitude and longitude coordinates from ... > > Does anyone know of a library or some existing out their to help with > > this conversion? > Some time ago I saw file named LLUTM... for such conversions with more than 20 ellipsoids. Language of the file - C or Python, not sure. Try Google for LLUTM to find more. Regards, Eugene From joncle at googlemail.com Fri Nov 13 16:56:56 2009 From: joncle at googlemail.com (Jon Clements) Date: Fri, 13 Nov 2009 13:56:56 -0800 (PST) Subject: The ol' [[]] * 500 bug... References: Message-ID: <6e20a31b-2218-49c5-a32c-5f0147db3172@k19g2000yqc.googlegroups.com> On 13 Nov, 21:26, kj wrote: > ...just bit me in the "fuzzy posterior". ?The best I can come up with > is the hideous > > ? lol = [[] for _ in xrange(500)] > > Is there something better? ? That's generally the accepted way of creating a LOL. > What did one do before comprehensions > were available? ?I suppose in that case one would have to go all > the way with > > ? lol = [None] * 500 > ? for i in xrange(len(lol)): > ? ? ? lol[i] = [] > > Yikes. ?10 miles uphill, both ways... > >>> lol = map(lambda L: [], xrange(5)) >>> [id(i) for i in lol] [167614956, 167605004, 167738060, 167737996, 167613036] Jon. From mark.kecko at gmail.com Fri Nov 13 17:10:10 2009 From: mark.kecko at gmail.com (scoopseven) Date: Fri, 13 Nov 2009 14:10:10 -0800 (PST) Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> Message-ID: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> On Nov 12, 8:55?pm, Steven D'Aprano wrote: > On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: > > I need to create a dictionary of querysets. ?I have code that looks > > like: > > > query1 = Myobject.objects.filter(status=1) > > query2 = Myobject.objects.filter(status=2) > > query3 = Myobject.objects.filter(status=3) > > > d={} > > d['a'] = query1 > > d['b'] = query2 > > d['c'] = query3 > > > Is there a way to do this that I'm missing? > > I don't understand your problem. Assuming Myobject is defined, and has > the appropriate attribute objects.filter, the above should work exactly > as you give it. > > What is your actual problem? Are you asking for help in defining a > queryset? > > -- > Steven I actually had a queryset that was dynamically generated, so I ended up having to use the eval function, like this... d = {} for thing in things: query_name = 'thing_' + str(thing.id) query_string = 'Thing.objects.filter(type=' + str(thing.id) + ').order_by(\'-date\')[:3]' executable_string = query_name + ' = Thing.objects.filter (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' exec(executable_string) d[query_name] = eval(query_string) And no, this is not based on user-generated input. Thanks for the input. From mmanns at gmx.net Fri Nov 13 17:25:39 2009 From: mmanns at gmx.net (mmanns at gmx.net) Date: Fri, 13 Nov 2009 23:25:39 +0100 Subject: bootstrapping on machines without Python References: Message-ID: <20091113232539.0afbc5fe@Knock> On Fri, 13 Nov 2009 02:40:28 -0800 (PST) Jonathan Hartley wrote: > Even my very limited understanding of the issues is enough to see that > the idea is far from trivial. [...] > In the long run, to be useful for real projects, the bootstrapper > would need to manage some nasty details: > * different versions of the interpreter for different applications > * download required packages > * manage conflicting versions of packages An easy approach could be to use the portable apps version of Python. (I assume that you use Windows.) After installing portable Python on your computer, your application and any additional libraries are put into the site-packages / Scripts folders. Next, the install folder is zipped and provided for download. A batch script, which is downloaded and run by the user, downloads the zip file and extracts it. The script executes python.exe with your Python script as command line argument. In this scenario, the user would not need Administrator privileges. You could also get around compatibility problems by providing preferred versions of additional libraries in the site-packages folder of portable Python. However, the download size would probably exceed 100 MB. I also do not know if there are licensing issues using portable Python like this. Martin From sromero at gmail.com Fri Nov 13 17:35:28 2009 From: sromero at gmail.com (Santiago Romero) Date: Fri, 13 Nov 2009 14:35:28 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> Message-ID: <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> > Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do > not remember the CPU freqeuncy anymore, maybe 25MHz). Yes, in ASM a simple 25 or 33Mhz 386 computer was able to emulate the Spectrum. At least, under MSDOS, like did Warajevo, Z80, x128 and "Spectrum" from Pedro Gimeno. > First emulator in C that appeared on the emu-scene (I guess it > was x128) needed 486 (~80MHz?) to run at realtime. Pentium and > Pentium II was A LOT of power :-) x128 was not pure C. The first emulator written in pure C was Aspectrum, although Philip Kendall "finished" FUSE (Free UNIX Spectrum Emulator) before my emulator was able to emulate 128K models. But currently only FUSE and ASpectrum can be compiled in lost of platforms (Wii, Dreamcast, PocketPC, NDS...) just by translating the O.S. dependent functions or if the destination platform supports the Allegro library... And at least a P1-P2 is needed for that :-) > http://perl-spectrum.sourceforge.net/ > > It is quite fast IMHO. It does not run 100% in my 1.8Ghz centrino computer :-(, but almost. At least, is a good start to see that is possible, at least no current DualCore computers :-) Thanks! From malaclypse2 at gmail.com Fri Nov 13 17:37:09 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 13 Nov 2009 17:37:09 -0500 Subject: QuerySets in Dictionaries In-Reply-To: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <16651e80911131437r56df712fh2cd5055ffaa5a087@mail.gmail.com> On Fri, Nov 13, 2009 at 5:10 PM, scoopseven wrote: > I actually had a queryset that was dynamically generated, so I ended > up having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) > > And no, this is not based on user-generated input. > I don't get it. If you're already storing the name to query mapping in a dictionary, why do you also need to use exec to do the same thing in the local namespace? If you're generating these names dynamically (which you obviously are, based on this snippet), it's going to be faster and more legible if you just look them up in the dictionary, instead of having to use exec and eval all over the place. Then all you'd need is something like: d = {} for thing in things: query_name = 'thing_%d' % thing.id d[query_name] = Thing.objects.filter(type=thing.id ).order_by('-date')[:3] then later you just look them up as d['thing_1'] (or d[thing_name] if you're dynamically generating the names again). -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Fri Nov 13 17:53:56 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 14 Nov 2009 11:53:56 +1300 Subject: ANN: PyGUI 2.1 Message-ID: PyGUI 2.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Highlights of this version: * Win32: Fixed bug preventing PyGUI apps from working under pythonw Fixed incorrect mouse coordinates in ScrollableView Added more standard cursors * MacOSX: Application menu now has working Hide, Hide Others and Show All commands. Plus a few other bug fixes and improvements. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. From no.email at please.post Fri Nov 13 18:05:57 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 23:05:57 +0000 (UTC) Subject: The ol' [[]] * 500 bug... References: <6e20a31b-2218-49c5-a32c-5f0147db3172@k19g2000yqc.googlegroups.com> Message-ID: In <6e20a31b-2218-49c5-a32c-5f0147db3172 at k19g2000yqc.googlegroups.com> Jon Clements writes: >>>> lol =3D map(lambda L: [], xrange(5)) >>>> [id(i) for i in lol] >[167614956, 167605004, 167738060, 167737996, 167613036] Oh yeah, map! I'd forgotten all about it. Thanks! kynn From aahz at pythoncraft.com Fri Nov 13 18:26:57 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 15:26:57 -0800 Subject: Compiler malware rebutted Message-ID: Ken Thompson's classic paper on bootstrapped malware finally gets a rebuttal: http://lwn.net/Articles/360040/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From zac256 at gmail.com Fri Nov 13 18:27:29 2009 From: zac256 at gmail.com (Zac Burns) Date: Fri, 13 Nov 2009 15:27:29 -0800 Subject: __import__ returns module without it's attributes? Message-ID: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From ryan at rfk.id.au Fri Nov 13 18:28:45 2009 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 14 Nov 2009 10:28:45 +1100 Subject: ANN: esky 0.2.1 In-Reply-To: References: Message-ID: <1258154925.2755.6.camel@durian> > >> Recently I was looking into distribution mechanisms, and I passed over > >> bbfreeze because I saw no indication that Python 2.6 was supported. > > > >Not sure if it's officially supported, but I do most of my development > >on Python 2.6 and bbfreeze hasn't given me any problems as yet. > > Also, bbfreeze doesn't seem to have active development. It's slow but certainly active. Development was recently moved to github with almost no fanfare (in fact I only discovered the github site by accident): http://github.com/schmir/bbfreeze Out of curiosity, what freezer package did you settle on in the end? I'm curious it see if esky could easily switch between different freezers (although it currently depends on some rather deep details of the bbfreeze format). Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: This is a digitally signed message part URL: From no.email at please.post Fri Nov 13 18:29:07 2009 From: no.email at please.post (kj) Date: Fri, 13 Nov 2009 23:29:07 +0000 (UTC) Subject: A "terminators' club" for clp Message-ID: This is "meta-question" about comp.lang.python. I apologize in advance if it has been already discussed. Also, I don't know enough about the underlying mechanics of comp.lang.python, so this may be *totally unfeasible*, but how about giving a few bona fide *and frequent* clp posters the ability to *easily* delete spam from the comp.lang.python server? Or it could be set up so that at least n > 1 "delete" votes and no "keep" votes are required to get something nixed. Etc. This seems simpler than all-out moderation. ("all-out moderation"? now, there's an oxymoron for ya!) One possible *initial* criterion for selecting these "terminators" would be the number of posts to clp between, say, January 2009 and July 2009. The members of this seed set could then select new members for the terminators' club. Just a thought. kynn From http Fri Nov 13 18:32:52 2009 From: http (Paul Rubin) Date: 13 Nov 2009 15:32:52 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7x8wea57bv.fsf@ruckus.brouhaha.com> Tim Chase writes: > Or even just pipe to > your text editor of choice: vi, emacs, ed, cat, and even Notepad > has a "wrap long lines" sort of setting or does the right thing > by default (okay, so cat relies on your console to do the > wrapping, but it does wrap). No, auto wrapping long lines looks like crap. It's better to keep the line length reasonable when you write the posts. This is Usenet so please stick with Usenet practices. If you want a web forum there are plenty of them out there. From http Fri Nov 13 18:43:28 2009 From: http (Paul Rubin) Date: 13 Nov 2009 15:43:28 -0800 Subject: A "terminators' club" for clp References: Message-ID: <7x3a4i56u7.fsf@ruckus.brouhaha.com> kj writes: > frequent* clp posters the ability to *easily* delete spam from the > comp.lang.python server? Um, this is usenet; there is no comp.lang.python server. Are you saying you want a moderated newsgroup? Hmm, maybe this group is busy enough that there is some merit to that idea. From rt8396 at gmail.com Fri Nov 13 19:13:42 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 16:13:42 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: <4d9e5296-6e8d-46fc-8783-ef8e8eb65403@l35g2000vba.googlegroups.com> On Nov 13, 5:29?pm, kj wrote: > This is "meta-question" about comp.lang.python. ?I apologize in > advance if it has been already discussed. ?Also, I don't know enough > about the underlying mechanics of comp.lang.python, so this may be > *totally unfeasible*, but how about giving a few bona fide *and > frequent* clp posters the ability to *easily* delete spam from the > comp.lang.python server? How long you been hanging around here? There are problems inherent in all moderated groups. When you give anyone the power to delete post they can use it for good and for evil. c.l.py like all groups has good and bad followers, spam, and trollers like anywhere else. What you consider spam and trolling i may consider freedom of speech although like anyone here i vehemently hate spammers and would like to put them out of business permanently! Trolls don't bother me so much because i just skip past their posts -- And there are many levels of trolling. However if you are selling something (that is *not* directly python related) then i think we could *safely* say that you are spamming this group. Nobody has come here to buy a knockoff Rolex's or Nike tennis shoes at ten bucks each. If you are posting porn links then we could *safely* say that porn is in no way applicable to this group and delete them on that merit. I'm OK with that, but would it stop there? If you look back through history you will find many instances of the powerful robbing the innocent peoples of freedoms in the name of good, or even the name of God, despicable hypocrite's!. Heck people where murdered by nation states just because of fear and ignorance ("Salem witch trials" ring a bell, the holocaust ring a bell?, and many many more sad cases). So if i had a choice between trollers, spammers, and power hungry murderers, i'll buy the rolex and listen to x-and-lee's all day long thank you very much! Power is corrupting, and absolute power is absolutely corrupting! From davidb at panix.com Fri Nov 13 19:54:21 2009 From: davidb at panix.com (David M. Besonen) Date: Fri, 13 Nov 2009 16:54:21 -0800 Subject: Compiler malware rebutted In-Reply-To: References: Message-ID: <4AFDFFBD.3010707@panix.com> On 11/13/2009 3:26 PM, Aahz wrote: > Ken Thompson's classic paper on bootstrapped malware > finally gets a rebuttal: > > http://lwn.net/Articles/360040/ thanks for pointing this out. -- david From andymac at bullseye.apana.org.au Fri Nov 13 19:57:39 2009 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Sat, 14 Nov 2009 11:57:39 +1100 Subject: questions regarding stack size use for multi-threaded python programs In-Reply-To: References: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Message-ID: <4AFE0083.30003@bullseye.andymac.org> Gabriel Genellina wrote: > En Mon, 09 Nov 2009 16:05:31 -0300, Eyal Gordon > escribi?: > >> background: >> we are using python 2.4.3 on CentOS 5.3 with many threads - and our >> shell's >> default stack size limit is set to 10240KB (i.e. ~10MB). >> >> we noticed that python's Threading module appears to create threads with >> this value as their stack size (we ran a sample program that creates 10 >> threads and measured its virtual memory size, then reduced the stack size >> limit of the shell to 5120KB - and saw that the program's virtual memory >> size was reduced by ~50MBs). >> >> the problem: >> our program uses numerous threads, and thus the virtual memory size >> gets to >> be very large. we would like to reduce the size of the stack to reduce >> this >> size. we were looking for information about recommendation for the stack >> size to use, but found none. > > You can set the thread stack size (for threads that are going to be > created, not existing threads) using threading.stack_size(SIZE) > http://docs.python.org/library/threading.html#threading.stack_size Sadly for the OP, that capability was introduced in Python 2.5. Prior to that, the only way to adjust thread stack size is via a compile time option (THREAD_STACK_SIZE). In the absence of that compile time option, the platform default is used - on pthread systems (incl Linux) refer to the manpage for pthread_attr_setstacksize() for more info, but I believe what the OP reports could reasonably be expected for his platform. The threading.stack_size() support would not be hard to backport to Python 2.4. >> questions: >> 1. is there some rule-of-thumb for the recommended stack size for python >> programs of various sorts? There is no rule of thumb because there are too many variables amongst the supported platforms. Extensive testing would be required to validate any selected size. I would suggest starting with 1MB and working down. On a 32bit platform I would suggest that 64kb might be adequate for child threads but most likely not for the primary thread (the thread that the Python interpreter starts in). If your app uses regexes, your stack space requirements are likely to be larger. FWIW the default thread stack size on Win32 is 1MB which anecdotally seems sufficient for a wide variety of applications on that platform. {...} >> 4. would the size of the stacks (which are probably not really >> allocated by >> the linux virtual memory sub-system, unless used) have a noticeable >> performance effect on a python program? same question regarding the >> use of a >> large number of threads? > > I think it doesn't matter, unless you create so many threads as to exhaust > the available addressing space (in 32bits, 4GB address space and 10MB per > thread means 400 threads maximum). The performance of course will degrade once the committed memory in the active working set exceeds the available real memory, as the OS will start swapping. How the OS treats unused stack space will affect that threshold. -- ------------------------------------------------------------------------- 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 rt8396 at gmail.com Fri Nov 13 20:00:53 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 17:00:53 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> <4afc7fad$0$7712$426a74cc@news.free.fr> <9e13ac65-00dc-4887-8cb9-1715f4990fd0@r5g2000yqb.googlegroups.com> <4afddb20$0$27405$426a74cc@news.free.fr> Message-ID: <2b3a0aab-8551-4c23-be71-9a5e1fc8a812@h2g2000vbd.googlegroups.com> On Nov 13, 3:20?pm, Bruno Desthuilliers wrote: (...snip...) > > I think because (like me) Carl > > put's the language before sewing circles. I think it's just personal > > like all the times before, > > Well, to be true, you did manage to make a clown of yourself more than > once, so don't be surprised if some people here tend to treat you as one > - even when you come up with something that _may_ have some value. Well, i must agree with that assessment. There have been some *interesting* post from me here. I am human and prone to make mistakes like anyone 0:-) > My (hopefully friendly) 2 cents. Thanks, the tone of this message was very good! But anyway this is all moot now. I received a message last night from a very intelligent person who i will not name since the message was only addressed to me (no it's not Guido! I don't want to start any crazy rumors people!) This "persons" response was *so* intelligent and informative i was awe struck whilst reading it and concluded i have no further basis to argue for this syntax change (not at this time anyway). I would like to post this person's message for all to see but i will not without their permission. I can now see how the pros *may* not outweigh the cons and so with that i concede to my opponents. Anyway, good discussion chaps! From aahz at pythoncraft.com Fri Nov 13 20:14:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 17:14:30 -0800 Subject: ANN: esky 0.2.1 References: Message-ID: In article , Ryan Kelly wrote: > >Out of curiosity, what freezer package did you settle on in the end? >I'm curious it see if esky could easily switch between different >freezers (although it currently depends on some rather deep details of >the bbfreeze format). We're currently using py2app and py2exe and are planning to use cx_freeze for Linux. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From aahz at pythoncraft.com Fri Nov 13 20:25:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 17:25:38 -0800 Subject: Compiler malware rebutted References: Message-ID: In article , David M. Besonen wrote: >On 11/13/2009 3:26 PM, Aahz wrote: >> >> Ken Thompson's classic paper on bootstrapped malware >> finally gets a rebuttal: >> >> http://lwn.net/Articles/360040/ > >thanks for pointing this out. Actually, I found out about it on panix.chat ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From bbrown at speakeasy.net Fri Nov 13 20:42:51 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 20:42:51 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > On 2009-11-11, at 14:31, Alain Ketterlin wrote: > I'm having some trouble understanding this thread. My comments aren't > directed at Terry's or Alain's comments, but at the thread overall. > > 1. The statement `Python is slow' doesn't make any sense to me. Python is a > programming language; it is implementations that have speed or lack thereof. This is generally true, but Python *the language* is specified in a way that makes executing Python programs quickly very very difficult. I'm tempted to say it's impossible, but great strides have been made recently with JITs, so we'll see. > 2. A skilled programmer could build an implementation that compiled Python > code into Common Lisp or Scheme code, and then used a high-performance > Common Lisp compiler such as SBCL, or a high-performance Scheme compiler > such as Chez Scheme, to produce quite fast code ... A skilled programmer has done this for Common Lisp. The CLPython implementation converts Python souce code to Common Lisp code at read time, which is then is compiled. With SBCL you get native machine code for every Python expression. http://github.com/franzinc/cl-python/ http://common-lisp.net/project/clpython/ If you want to know why Python *the language* is slow, look at the Lisp code CLPython generates and at the code implementing the run time. Simple operations end up being very expensive. Does the object on the left side of a comparison implement compare? No, then does the right side implement it? No, then try something else .... I'm sure someone can come up with a faster Python implementation, but it will have to be very clever. > This whole approach would be a bad idea, because the compile times would be > dreadful, but I use this example as an existence proof that Python > implementations can generate reasonably efficient executable programs. The compile times are fine, not dreadful. Give it a try. > 3. It is certainly true that CPython doesn't scale up to environments where > there are a significant number of processors with shared memory. Even on one processor, CPython has problems. I last seriously used CPython to analyze OCRed books. The code read in the OCR results for one book at a time, which included the position of every word on every page. My books were long, 2000 pages, and dense and I was constantly fighting address space limitations and CPython slowness related to memory usage. I had to resort to packing and unpacking data into Python integers in order to fit all the OCR data into RAM. bob From bbrown at speakeasy.net Fri Nov 13 21:02:06 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 21:02:06 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis writes: > My point in the earlier post about translating Python into Common Lisp or > Scheme was essentially saying `look, there's more than 30 years experience > building high-performance implementations of Lisp languages, and Python > isn't really that different from Lisp, so we ought to be able to do it too'. Common Lisp and Scheme were designed by people who wanted to write complicated systems on machines with a tiny fraction of the horsepower of current workstations. They were carefully designed to be compiled efficiently, which is not the case with Python. There really is a difference here. Python the language has features that make fast implementations extremely difficult. bob From rhodri at wildebst.demon.co.uk Fri Nov 13 21:11:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 14 Nov 2009 02:11:33 -0000 Subject: query regarding file handling. In-Reply-To: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> References: <52ab11f40911120159v70da9864nd6130ba65bc8262f@mail.gmail.com> Message-ID: On Thu, 12 Nov 2009 09:59:40 -0000, ankita dutta wrote: > hi all, > > i have a file of 3x3 matrix of decimal numbers(tab separated). like this > : > > 0.02 0.38 0.01 > 0.04 0.32 0.00 > 0.03 0.40 0.02 > > now i want to read 1 row and get the sum of a particular row. but when i > am > trying with the following code, i am getting errors : > > *code*: > " > ln1=open("A.txt","r+") # file "A.txt" contains my matrix > lines1=ln1.readlines() You can iterate through the file line by line, so there's no need to read the whole thing in one go like this. > n_1=[ ] > > for p1 in range (0,len(lines1)): > f1=lines1[p1] If you ever write range(len(some_list)) in a 'for' statement, you're almost certainly making life harder for yourself than you need to. Since all you use 'pl' for is pulling out the 'current' line, you might as well just iterate through the list, i.e. replace those two lines with this: for fl in lines1: Better, as I mentioned earlier you can skip the whole business of slurping the file in using 'readlines' and read it one line at a time: for fl in ln1: > n_1.append((f1) ) > print n_1 > print sum(n_1[0]) > [snip] > * what I think:* > > as the list is in form of '0.0200\t0.3877\t0.0011\n' , n_1[0] > takes > it as a whole string which includes "\t" , i think thats why they are > giving error. You think right. > now how can i read only required numbers from this line > '0.0200\t0.3877\t0.0011\n' and find their sum ? > can you kindly help me out how to properly code thing . Read the line (as before), then split it on whitespace (the tabs in this case), and then sum the resulting list. Or as Chris said, get the 'csv' module to do the hard work for you. -- Rhodri James *-* Wildebeest Herder to the Masses From bbrown at speakeasy.net Fri Nov 13 21:13:04 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Fri, 13 Nov 2009 21:13:04 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <87my2r7imn.fsf@agentultra.com> Message-ID: J Kenneth King writes: > mcherm writes: >> I think you have a fundamental misunderstanding of the reasons why Python >> is slow. Most of the slowness does NOT come from poor implementations: the >> CPython implementation is extremely well-optimized; the Jython and Iron >> Python implementations use best-in-the-world JIT runtimes. Most of the >> speed issues come from fundamental features of the LANGUAGE itself, mostly >> ways in which it is highly dynamic. >> >> -- Michael Chermside > You might be right for the wrong reasons in a way. Python isn't slow > because it's a dynamic language. All the lookups you're citing are highly > optimized hash lookups. It executes really fast. Sorry, but Michael is right for the right reason. Python the *language* is slow because it's "too dynamic". All those hash table lookups are unnecessary in some other dynamic languages and they slow down Python. A fast implementation is going to have to be very clever about memoizing method lookups and invalidating assumptions when methods are dynamically redefined. > As an implementation though, the sky really is the limit and Python is > only getting started. Yes, but Python is starting in the basement. bob From vmanis at telus.net Fri Nov 13 21:15:12 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:15:12 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> References: <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <9839a05c0911131246v557643e2yc878e0807664066f@mail.gmail.com> Message-ID: <89D07812-FF73-4FE7-9AF0-772FFAFB2DC7@telus.net> On 2009-11-13, at 12:46, Brian J Mingus wrote: > You're joking, right? Try purchasing a computer manufactured in this millennium. Monitors are much wider than 72 characters nowadays, old timer. I have already agreed to make my postings VT100-friendly. Oh, wait, the VT-100, or at least some models of it, had a mode where you could have a line width of 132 characters. And what does this have to do with Python? About as much as an exploding penguin on your television. -- v From vmanis at telus.net Fri Nov 13 21:25:59 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:25:59 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7x8wea57bv.fsf@ruckus.brouhaha.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-13, at 15:32, Paul Rubin wrote: > This is Usenet so > please stick with Usenet practices. Er, this is NOT Usenet. 1. I haven't, to the best of my recollection, made a Usenet post in this millennium. 2. I haven't fired up a copy of rn or any other news reader in at least 2 decades. 3. I'm on the python-list mailing list, reading this with Apple's Mail application, which actually doesn't have convenient ways of enforcing `Usenet practices' regarding message format. 4. If we're going to adhere to tried-and-true message format rules, I want my IBM 2260 circa 1970, with its upper-case-only display and weird little end-of-line symbols. Stephen asked me to wrap my posts. I'm happy to do it. Can we please finish this thread off and dispose of it? -- v From rhodri at wildebst.demon.co.uk Fri Nov 13 21:30:13 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 14 Nov 2009 02:30:13 -0000 Subject: #define (from C) in Python In-Reply-To: <2qivs6-v5e.ln1@satorlaser.homedns.org> References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> Message-ID: On Fri, 13 Nov 2009 08:43:14 -0000, Ulrich Eckhardt wrote: > Santiago Romero wrote: >> Well, In the above concrete example, that would work, but I was >> talking for multiple code lines, like: >> >> >> #define LD_r_n(reg) (reg) = Z80ReadMem(r_PC++) >> >> #define LD_rr_nn(reg) r_opl = Z80ReadMem(r_PC); r_PC++; \ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> reg = r_op >> >> #define LOAD_r(dreg, saddreg) (dreg)=Z80ReadMem((saddreg)) >> >> #define LOAD_rr_nn(dreg) r_opl = Z80ReadMem(r_PC); r_PC++; \ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> r_tmpl = Z80ReadMem(r_op); \ >> r_tmph = Z80ReadMem((r_op)+1); \ >> dreg=r_tmp >> >> #define STORE_nn_rr(dreg) \ >> r_opl = Z80ReadMem(r_PC); r_PC++;\ >> r_oph = Z80ReadMem(r_PC); r_PC++; \ >> r_tmp = dreg; \ >> Z80WriteMem((r_op),r_tmpl, regs); \ >> Z80WriteMem((r_op+1),r_tmph, regs) > > Someone writing such code and calling it C should be taken behind the > barn > and shot. Having spent all day working on C code with *much* more complex #defines than that, I beg to disagree. Particularly in embedded applications, there are occasions when you absolutely must have bits of code inlined rather than as function calls. In those cases, declaring a function 'inline' is insufficient, as the compiler can choose to ignore you. In Python, however, the point is moot; you don't get to play those games without using a separate preprocessor. I've never particularly felt the urge to try, either. -- Rhodri James *-* Wildebeest Herder to the Masses From rt8396 at gmail.com Fri Nov 13 21:33:11 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 18:33:11 -0800 (PST) Subject: tkFileDialog question References: Message-ID: <51e9fd1a-cfe4-4370-9d95-783010328757@z7g2000vbl.googlegroups.com> On Nov 13, 2:47?pm, "Matt Mitchell" wrote: > ----------------------------------- > The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. > > > > -----Original Message----- > From: python-list-bounces+mmitchell=transparent.... at python.org > > [mailto:python-list-bounces+mmitchell=transparent.... at python.org] On > Behalf Of Matt Mitchell > Sent: Friday, November 13, 2009 9:33 AM > To: python-l... at python.org > Subject: tkFileDialog question > > Hi, > > This is my first attempt to write a script with any kind of gui. ? All I > need the script to do is ask the user for a directory and then do stuff > with the files in that directory. ?I used tkFileDialog.askdirectory(). > It works great but it pops up an empty tk window. ?Is there any way to > prevent the empty tk window from popping up? Here's the code: > > import tkFileDialog > > answer = tkFileDialog.askdirectory() > > if answer is not '': > ? ? ? ? #do stuff > > Thanks! > Matt > --http://mail.python.org/mailman/listinfo/python-list > > Hi, > > After a few more hours of googling I answered my own question: > > import Tkinter, tkFileDialog > > root = Tk() > root.withdraw() > > answer = tkFileDialog.askdirectory() > > if answer is not '': > ? ? ? ? #do stuff > > Thanks!! hello Matt, Here is one way import Tkinter as tk from tkFileDialog import askdirectory import os root = tk.Tk() root.withdraw() folder = askdirectory() if folder: root.destroy() #make sure to do this!!!! print os.listdir(folder) root.mainloop() good luck! From rt8396 at gmail.com Fri Nov 13 21:37:04 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 18:37:04 -0800 (PST) Subject: tkFileDialog question References: Message-ID: <2e71c92c-d63f-441e-b0c1-c2cfd56992ab@g31g2000vbr.googlegroups.com> Opps, i see you answered your own question ;-) To save you more hours of Googling take a look at these two sites! #great reference http://infohost.nmt.edu/tcc/help/pubs/tkinter/ #more in-depth http://effbot.org/tkinterbook/ you'll want to keep them both under your pillow. From vmanis at telus.net Fri Nov 13 21:39:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 18:39:01 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: > ... Python *the language* is specified in a way that > makes executing Python programs quickly very very difficult. That is untrue. I have mentioned before that optional declarations integrate well with dynamic languages. Apart from CL and Scheme, which I have mentioned several times, you might check out Strongtalk (typed Smalltalk), and Dylan, which was designed for high-performance compilation, though to my knowledge no Dylan compilers ever really achieved it. > I'm tempted to > say it's impossible, but great strides have been made recently with JITs, so > we'll see. > If you want to know why Python *the language* is slow, look at the Lisp code > CLPython generates and at the code implementing the run time. Simple > operations end up being very expensive. Does the object on the left side of a > comparison implement compare? No, then does the right side implement it? No, > then try something else .... I've never looked at CLPython. Did it use a method cache (see Peter Deutsch's paper on Smalltalk performance in the unfortunately out-of-print `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years old now. I have more to say, but I'll do that in responding to Bob's next post. -- v From drobinow at gmail.com Fri Nov 13 21:44:49 2009 From: drobinow at gmail.com (David Robinow) Date: Fri, 13 Nov 2009 18:44:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7x8wea57bv.fsf@ruckus.brouhaha.com> References: <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <4eb0089f0911131844t7032db07i3e9c15fd37427e9a@mail.gmail.com> On Fri, Nov 13, 2009 at 3:32 PM, Paul Rubin wrote: > ... ?This is Usenet so > please stick with Usenet practices. ?If you want a web forum there are > plenty of them out there. Actually this is python-list at python.org I don't use usenet and I have no intention to stick with Usenet practices. From rt8396 at gmail.com Fri Nov 13 22:05:32 2009 From: rt8396 at gmail.com (r) Date: Fri, 13 Nov 2009 19:05:32 -0800 (PST) Subject: tkFileDialog question References: <2e71c92c-d63f-441e-b0c1-c2cfd56992ab@g31g2000vbr.googlegroups.com> Message-ID: <1a9d0b84-2f89-44ec-a70e-b4ae56bf343b@x15g2000vbr.googlegroups.com> Opps: And here i go making a clown of myself again... import Tkinter as tk from tkFileDialog import askdirectory import os root = tk.Tk() root.withdraw() folder = askdirectory() #make sure to do this somewhere that will always execute! root.destroy() if folder: print os.listdir(folder) root.mainloop() r... just another would be language designer From vmanis at telus.net Fri Nov 13 22:15:09 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 19:15:09 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <017DAB27-652D-40ED-9E96-5D7AA26DAA7A@telus.net> On 2009-11-13, at 18:02, Robert Brown wrote: > Common Lisp and Scheme were designed by people who wanted to write complicated > systems on machines with a tiny fraction of the horsepower of current > workstations. They were carefully designed to be compiled efficiently, which > is not the case with Python. There really is a difference here. Python the > language has features that make fast implementations extremely difficult. Not true. Common Lisp was designed primarily by throwing together all of the features in every Lisp implementation the design committee was interested in. Although the committee members were familiar with high-performance compilation, the primary impetus was to achieve a standardized language that would be acceptable to the Lisp community. At the time that Common Lisp was started, there was still some sentiment that Lisp machines were the way to go for performance. As for Scheme, it was designed primarily to satisfy an aesthetic of minimalism. Even though Guy Steele's thesis project, Rabbit, was a Scheme compiler, the point here was that relatively simple compilation techniques could produce moderately reasonable object programs. Chez Scheme was indeed first run on machines that we would nowadays consider tiny, but so too was C++. Oh, wait, so was Python! I would agree that features such as exec and eval hurt the speed of Python programs, but the same things do the same thing in CL and in Scheme. There is a mystique about method dispatch, but again, the Smalltalk literature has dealt with this issue in the past. Using Python 3 annotations, one can imagine a Python compiler that does the appropriate thing (shown in the comments) with the following code. import my_module # static linking __private_functions__ = ['my_fn'] # my_fn doesn't appear in the module dictionary. def my_fn(x: python.int32): # Keeps x in a register def inner(z): # Lambda-lifts the function, no nonlocal vars return z // 2 # does not construct a closure y = x + 17 # Via flow analysis, concludes that y can be registerized; return inner(2 * y) # Uses inline integer arithmetic instructions. def blarf(a: python.int32): return my_fn(a // 2) # Because my_fn isn't exported, it can be inlined. A new pragma statement (which I am EXPLICITLY not proposing; I respect and support the moratorium) might be useful in telling the implementation that you don't mind integer overflow. Similarly, new library classes might be created to hold arrays of int32s or doubles. Obviously, no Python system does any of these things today. But there really is nothing stopping a Python system from doing any of these things, and the technology is well-understood in implementations of other languages. I am not claiming that this is _better_ than JIT. I like JIT and other runtime things such as method caches better than these because you don't have to know very much about the implementation in order to take advantage of them. But there may be some benefit in allowing programmers concerned with speed to relax some of Python's dynamism without ruining it for the people who need a truly dynamic language. If I want to think about scalability seriously, I'm more concerned about problems that Python shares with almost every modern language: if you have lots of processors accessing a large shared memory, there is a real GC efficiency problem as the number of processors goes up. On the other hand, if you have a lot of processors with some degree of private memory sharing a common bus (think the Cell processor), how do we build an efficient implementation of ANY language for that kind of environment? Somehow, the issues of Python seem very orthogonal to performance scalability. -- v From http Fri Nov 13 22:15:32 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:15:32 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <7x7httvlt7.fsf@ruckus.brouhaha.com> Vincent Manis writes: > 3. I'm on the python-list mailing list, reading this with Apple's > Mail application, which actually doesn't have convenient ways of > enforcing `Usenet practices' regarding message format. Oh, I see. Damn gateway. > Stephen asked me to wrap my posts. I'm happy to do it. Can we please > finish this thread off and dispose of it? Please wrap to 72 columns or less. It's easier to read that way. (I actually don't care if you do it or not. If you don't, I'll just stop responding to you, which might even suit your wishes.) From http Fri Nov 13 22:38:04 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:38:04 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> Message-ID: <7xpr7lixnn.fsf@ruckus.brouhaha.com> Duncan Booth writes: > > Haskell handles lookups through its type system; dealing with > > lookup errors (say by chaining the Maybe type) is clean and elegant. > I said exceptions or any other method of error handling. I think the use of an option type (like Maybe) is pretty standard and works fine. Go's use of multiple-value returns isn't so bad, but seems old-fashioned. > go routines are executed using a thread pool,... > Most types are not thread safe, so you should never access any mutable > value from more than one go routine. If you need to access something > like a map from multiple parallel routines you need to use channels to > protect it. OK, this sounds sort of like Erlang. > var ch = make(chan int, 3); > would create a channel that holds 3 int values. ... > You can also use a select statement (syntax similar to a switch > statement) to read or write channels in parallel. It arbitrarily chooses > one of the case statements that can proceed to execute,... Thanks, that is informative. The mechanism looks kind of primitive and it would be nice if there were a higher level wrapper of some sort. But again, it seems sort of Erlang-like (though I haven't used Erlang so I only have a vague sense of its similarity). > There doesn't seem to be any way to specify a timeout on a read or > write. I think you can create a timer channel with regular ticks and > select from that to provide an effective timeout, but that sounds like a > lot of boilerplate if you have to do very often. I wonder how Erlang handles this. It seems a little weird to me that they (Google) are concerned with the speed of the compiler, indicating that they plan to write enormous programs in the language. I've heard they use a 1000-node cluster to compile their large C++ apps. Go seems too primitive (so far) to really be suitable for such large-scale development, and (for a newly designed language) seems to be missing a lot of the latest ideas. From greg at cosc.canterbury.ac.nz Fri Nov 13 22:44:07 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 14 Nov 2009 16:44:07 +1300 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> Message-ID: <7m6nclF3gnlqfU1@mid.individual.net> Santiago Romero wrote: > Can the above be easily done with another already-existing > application? (example: can m4 do this job)? The problem you're going to have with something like m4 is indentation. When you inline a function call, somehow the inserted code has to be shifted to the same indentation level as the statement containing the call. I don't know of any off-the-shelf macro processor that can handle that sort of thing easily. You may want to consider writing a custom one in Python. You could use the ast facilities to parse the code, operate on the parse tree and then write it back out as code. You might be able to get some ideas from 2to3, which does similar kinds of source-to-source translations. -- Greg From http Fri Nov 13 22:53:00 2009 From: http (Paul Rubin) Date: 13 Nov 2009 19:53:00 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: <7xlji9iwyr.fsf@ruckus.brouhaha.com> "Robert P. J. Day" writes: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > thoughts? I'd bet it's not just about multicore scaling and general efficiency, but also the suitability of the language itself for large, complex projects. It's just not possible to be everything for everybody. Python is beginner-friendly, has a very fast learning curve for experienced programmers in other languages, and is highly productive for throwing small and medium sized scripts together, that are debugged through iterated testing. One might say it's optimized for those purposes. I use it all the time because a lot of my programming fits the pattern. The car analogy is the no-frills electric commuter car, just hop in and aim it where you want to go; if you crash it, brush yourself off and restart. But there are times (large production applications) when you really want the Airbus A380 with the 100's of automatic monitoring systems and checkout procedures to follow before you take off, even if the skill level needed to use it is much higher than the commuter car. From michele.simionato at gmail.com Fri Nov 13 23:09:27 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 13 Nov 2009 20:09:27 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> On Nov 14, 4:38?am, Paul Rubin wrote: > It seems a little weird to me that they (Google) are concerned with > the speed of the compiler, indicating that they plan to write enormous > programs in the language. ?I've heard they use a 1000-node cluster to > compile their large C++ apps. ?Go seems too primitive (so far) to > really be suitable for such large-scale development, and (for a newly > designed language) seems to be missing a lot of the latest ideas. It does not look so primitive to me, compared to commonly used languages. I am pretty sure that they are "missing a lot of the latest ideas" on purpose. If they want to succeed and make Go a popular language in the Google infrastructure (ideally replacing C++) their selling point must be a nearly zero learning curve. Python succeded with the low learning curve idea. I wish them the best. Certainly it is time to replace C with something more modern, be it Go or some other language. From aahz at pythoncraft.com Fri Nov 13 23:44:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Nov 2009 20:44:58 -0800 Subject: Choosing GUI Module for Python References: Message-ID: In article , Antony wrote: > > I just wanted to know which module is best for developing designing >interface in python . Haven't tried it, but a new release was just announced for this: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From ethan at stoneleaf.us Sat Nov 14 00:33:53 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Nov 2009 21:33:53 -0800 Subject: the unicode saga continues... Message-ID: <4AFE4141.4020102@stoneleaf.us> So I've added unicode support to my dbf package, but I also have some rather large programs that aren't ready to make the switch over yet. So as a workaround I added a (rather lame) option to convert the unicode-ified data that was decoded from the dbf table back into an encoded format. Here's the fun part: in figuring out what the option should be for use with my system, I tried some tests... Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print u'\xed' ? >>> print u'\xed'.encode('cp437') ? >>> print u'\xed'.encode('cp850') ? >>> print u'\xed'.encode('cp1252') ? >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') My confusion lies in my apparant codepage (cp1252), and the discrepancy with character u'\xed' which is absolutely an i with an accent; yet when I encode with cp1252 and print it, I get an o with a line. Can anybody clue me in to what's going on here? ~Ethan~ From zvezdan at zope.com Sat Nov 14 00:53:36 2009 From: zvezdan at zope.com (Zvezdan Petkovic) Date: Sat, 14 Nov 2009 00:53:36 -0500 Subject: 2.6.4 Mac x86_64 ? In-Reply-To: References: Message-ID: <83EE66A8-C926-4D77-8FD4-6187B4D12899@zope.com> On Nov 13, 2009, at 3:58 PM, chris grebeldinger wrote: > Hi All, > I've been having some trouble getting a x86_64/i386 universal > readline.so to build against libedit, on MacOS 10.5.6 as Apple does. > Does anyone have any pointers about what changes I need to make to > setup.py or readline.c to achive this? > Has someone already done this and would like to share it? The fix for use of native editline (readline emulation) was done and is already implemented on the trunk (2.7). Please see: http://bugs.python.org/issue6877 You can find the patch in that tracker issue or here: http://svn.python.org/view?view=rev&revision=74970 It was marked for a backport to a future 2.6.5 release too. > Are there any plans to provide 64 bit support in future Mac OS 2.6.x > releases? AFAIK, it is already supported. Perhaps you should specify the exact problems you have. I believe that a more appropriate place for that would be pythonmac-sig mailing list, though. Best regards, Zvezdan From vmanis at telus.net Sat Nov 14 01:38:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 22:38:01 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <7xlji9iwyr.fsf@ruckus.brouhaha.com> References: <7xlji9iwyr.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-13, at 19:53, Paul Rubin wrote: > "Robert P. J. Day" writes: >> http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 >> thoughts? > > I'd bet it's not just about multicore scaling and general efficiency, > but also the suitability of the language itself for large, complex > projects. It's just not possible to be everything for everybody. > Python is beginner-friendly, has a very fast learning curve for > experienced programmers in other languages, and is highly productive > for throwing small and medium sized scripts together, that are > debugged through iterated testing. One might say it's optimized for > those purposes. I use it all the time because a lot of my programming > fits the pattern. The car analogy is the no-frills electric commuter > car, just hop in and aim it where you want to go; if you crash it, > brush yourself off and restart. But there are times (large production > applications) when you really want the Airbus A380 with the 100's of > automatic monitoring systems and checkout procedures to follow before > you take off, even if the skill level needed to use it is much higher > than the commuter car. OK. The quoted link deals with Unladen Swallow, which is an attempt to deal with the very real performance limitations of current Python systems. The remarks above deal with productivity scalability, which is a totally different matter. So... People can and do write large programs in Python, not just `throwing...medium sized scripts together'. Unlike, say, Javascript, it has the necessary machinery to build very large programs that are highly maintainable. One can reasonably compare it with Java, C#, and Smalltalk; the facilities are comparable, and all of those (as well as Python) are used for building enterprise systems. I believe that the A380's control software is largely written in Ada, which is a perfectly fine programming language that I would prefer not to write code in. For approximately 10 years, US DOD pretty much required the use of Ada in military (and aerospace) software (though a a couple of years ago I discovered that there is still one remaining source of Jovial compilers that still sells to DOD). According to a presentation by Lt. Colonel J. A. Hamilton, `Programming Language Policy in the DOD: After The Ada Mandate', given in 1999, `We are unlikely to see a return of a programming language mandate' (www.drew-hamilton.com/stc99/stcAda_99.pdf). As I understand it, the removal of the Ada mandate came from the realization (20 years after many computer scientists *told* DOD this) that software engineering processes contribute more to reliability than do programming language structures (c.f. Fred Brooks, `No Silver Bullet'). So: to sum up, there are lots of large systems where Python might be totally appropriate, especially if complemented with processes that feature careful specification and strong automated testing. There are some large systems where Python would definitely NOT be the language of choice, or even usable at all, because different engineering processes were in place. From a productivity viewpoint, there is no data to say that Python is more, less, or equally scalable than in that it produces correctly-tested, highly-maintainable programs at a lower, higher, or equal cost. I would appreciate it if people who wanted to comment on Python's scalability or lack thereof would give another programming language that they would compare it with. -- v From alfps at start.no Sat Nov 14 01:51:03 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 07:51:03 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury: > On Thu, 12 Nov 2009 12:02:11 -0800, Alf P. Steinbach > wrote: >> I think that was in the part you *snipped* here. Just fill in the >> mentioned qualifications and weasel words. > > OK, sure. I don't think they're weasel words, because I find them > useful, but I think I see where you're coming from. > >> Specifically, I reacted to the statement that <> to talk about "the" speed of an implementation>>, made in response to >> someone upthread, in the context of Google finding CPython overall too >> slow. > > IIRC it was "the speed of a language" that was asserted to be nonsense, > wasn't it? Yes, upthread. It's sort of hilarious. Alain Ketterlin: "slide/page 22 explains why python is so slow" Vincent Manis (response): "Python is a programming language; it is implementations that have speed or lack thereof" This was step 1 of trying to be more precise than the concept warranted. Then Steven D'Aprano chimed in, adding even more precision: Steven D'Aprano (further down response stack): "it is sheer nonsense to talk about "the" speed of an implementation" So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. Hip hurray, Google's observation annuled, by the injections of /precision/. :-) > Which IMO is fair -- a physicist friend of mine works with a > C++ interpreter which is relatively sluggish, but that doesn't mean C++ > is slow... Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. Cheers, - Alf From metolone+gmane at gmail.com Sat Nov 14 01:52:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 13 Nov 2009 22:52:16 -0800 Subject: the unicode saga continues... References: <4AFE4141.4020102@stoneleaf.us> Message-ID: "Ethan Furman" wrote in message news:4AFE4141.4020102 at stoneleaf.us... > So I've added unicode support to my dbf package, but I also have some > rather large programs that aren't ready to make the switch over yet. So > as a workaround I added a (rather lame) option to convert the > unicode-ified data that was decoded from the dbf table back into an > encoded format. > > Here's the fun part: in figuring out what the option should be for use > with my system, I tried some tests... > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print u'\xed' > ? > >>> print u'\xed'.encode('cp437') > ? > >>> print u'\xed'.encode('cp850') > ? > >>> print u'\xed'.encode('cp1252') > ? > >>> import locale > >>> locale.getdefaultlocale() > ('en_US', 'cp1252') > > My confusion lies in my apparant codepage (cp1252), and the discrepancy > with character u'\xed' which is absolutely an i with an accent; yet when I > encode with cp1252 and print it, I get an o with a line. > > Can anybody clue me in to what's going on here? Yes, your console window actually uses cp437, cp850 happens to map to the same character, and cp1252 does not. cp1252 is the default Windows encoding (what Notepad uses, for example): Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') >>> import sys >>> sys.stdout.encoding 'cp437' >>> print u'\xed'.encode('cp437') ? >>> print u'\xed'.encode('cp1252') ? -Mark From bbrown at speakeasy.net Sat Nov 14 02:20:44 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 02:20:44 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: >> ... Python *the language* is specified in a way that >> makes executing Python programs quickly very very difficult. > That is untrue. I have mentioned before that optional declarations integrate > well with dynamic languages. Apart from CL and Scheme, which I have > mentioned several times, you might check out Strongtalk (typed Smalltalk), > and Dylan, which was designed for high-performance compilation, though to my > knowledge no Dylan compilers ever really achieved it. You are not making an argument, just mentioning random facts. You claim I've made a false statement, then talk about optional type declarations, which Python doesn't have. Then you mention Smalltalk and Dylan. What's your point? To prove me wrong you have to demonstrate that it's not very difficult to produce a high performance Python system, given current Python semantics. >> I'm tempted to say it's impossible, but great strides have been made >> recently with JITs, so we'll see. > >> If you want to know why Python *the language* is slow, look at the Lisp >> code CLPython generates and at the code implementing the run time. Simple >> operations end up being very expensive. Does the object on the left side >> of a comparison implement compare? No, then does the right side implement >> it? No, then try something else .... > I've never looked at CLPython. Did it use a method cache (see Peter > Deutsch's paper on Smalltalk performance in the unfortunately out-of-print > `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years > old now. Please look at CLPython. The complexity of some Python operations will make you weep. CLPython uses Common Lisp's CLOS method dispatch in various places, so yes, those method lookups are definitely cached. Method lookup is just the tip if the iceburg. How about comparison? Here are some comments from CLPython's implementation of compare. There's a lot going on. It's complex and SLOW. ;; This function is used in comparisons like <, <=, ==. ;; ;; The CPython logic is a bit complicated; hopefully the following ;; is a correct translation. ;; If the class is equal and it defines __cmp__, use that. ;; The "rich comparison" operations __lt__, __eq__, __gt__ are ;; now called before __cmp__ is called. ;; ;; Normally, we take these methods of X. However, if class(Y) ;; is a subclass of class(X), the first look at Y's magic ;; methods. This allows the subclass to override its parent's ;; comparison operations. ;; ;; It is assumed that the subclass overrides all of ;; __{eq,lt,gt}__. For example, if sub.__eq__ is not defined, ;; first super.__eq__ is called, and after that __sub__.__lt__ ;; (or super.__lt__). ;; ;; object.c - try_rich_compare_bool(v,w,op) / try_rich_compare(v,w,op) ;; Try each `meth'; if the outcome it True, return `res-value'. ;; So the rich comparison operations didn't lead to a result. ;; ;; object.c - try_3way_compare(v,w) ;; ;; Now, first try X.__cmp__ (even if y.class is a subclass of ;; x.class) and Y.__cmp__ after that. ;; CPython now does some number coercion attempts that we don't ;; have to do because we have first-class numbers. (I think.) ;; object.c - default_3way_compare(v,w) ;; ;; Two instances of same class without any comparison operator, ;; are compared by pointer value. Our function `py-id' fakes ;; that. ;; None is smaller than everything (excluding itself, but that ;; is catched above already, when testing for same class; ;; NoneType is not subclassable). ;; Instances of different class are compared by class name, but ;; numbers are always smaller. ;; Probably, when we arrive here, there is a bug in the logic ;; above. Therefore print a warning. From doomster at knuut.de Sat Nov 14 02:32:07 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sat, 14 Nov 2009 08:32:07 +0100 Subject: the unicode saga continues... References: Message-ID: <7m74npF3fpqptU1@mid.uni-berlin.de> Ethan Furman wrote: > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print u'\xed' > ? > >>> print u'\xed'.encode('cp437') > ? > >>> print u'\xed'.encode('cp850') > ? > >>> print u'\xed'.encode('cp1252') > ? > >>> import locale > >>> locale.getdefaultlocale() > ('en_US', 'cp1252') > > My confusion lies in my apparant codepage (cp1252), and the discrepancy > with character u'\xed' which is absolutely an i with an accent; yet when > I encode with cp1252 and print it, I get an o with a line. ^^^^^^^^^^^^^^^^^^^^^^ For the record: I read a small Greek letter phi in your posting, not an o with a line. If I encode according to my default locale (UTF-8), I get the letter i with the accent. If I encode with codepage 1252, I get a marker for an invalid character on my terminal. This is using Debian though, not MS Windows. Try printing the repr() of that. The point is that internally, you have the codepoint u00ED (u'\xed'). Then, you encode this thing in various codepages, which yields a string of bytes representing this thing ('\xa1', '\xa1' and '\xed'), useful for storing on disk when the file uses said codepage or other forms of IO. Now, with a Unicode string, the output (print) knows what to do, it encodes it according to the defaultlocale and sends the resulting bytes to stdout. With a byte string, I think it directly forwards the content to stdout. Note: * If you want to verify your code, rather use 'print repr(..)'. * I could imagine that your locale is simply not set up correctly. Uli From paul.nospam at rudin.co.uk Sat Nov 14 02:32:48 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 07:32:48 +0000 Subject: python-daemonize and upstart Message-ID: <87my2pimsf.fsf@rudin.co.uk> I'm experimenting with the daemon module and upstart . There's something I don't understand, which may be more of an upstart issue than a python issue, but I thought I'd start by posting here. Here's a test script: #!/usr/bin/python2.6 import daemon import time def work(): count = 0 while True: with open('/tmp/test.txt', 'a') as f: f.write(str(count)) f.write('\n') count += 1 time.sleep(5) def main(): with daemon.DaemonContext(working_directory='/tmp'): work() if __name__ == "__main__": main() and here's a testdaemon.conf upstart configuration: description "test daemon" expect daemon chdir /tmp exec /tmp/testdaemon.py If I do "sudo start testdaemon" I see the "testdaemon.py" process starting, and the file '/tmp/test.txt' is being written to every 5 seconds, so everything has kicked off. The thing I don't understand is why start does not return. I guess it doesn't think that the process and properly started and daemonized itself? Quite possibly it's just that I don't understand this stuff well... From vmanis at telus.net Sat Nov 14 02:33:25 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 23:33:25 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <699FB81C-6711-487A-86C0-726C08B7EDD0@telus.net> On 2009-11-13, at 22:51, Alf P. Steinbach wrote: > It's sort of hilarious. It really is, see below. > So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. Because `language is slow' is meaningless. An earlier post of mine listed four examples where the common wisdom was `XXX is slow' and yet where that turned out not to be the case. Some others. 1. I once owned a Commodore 64. I got Waterloo Pascal for it. I timed the execution of some program (this was 25 years ago, I forget what the program did) at 1 second per statement. Therefore: `Pascal is slow'. 2. Bell Labs produced a fine programming language called Snobol 4. It was slow. But some folks at IIT in Chicago did their own implementation, Spitbol, which was fast and completely compatible. Presto: Snobol 4 was slow, but then it became fast. 3. If you write the following statements in Fortran IV (the last version of Fortran I learned) DO 10 I=1, 1000000 DO 10 J=1, 1000000 A(I, J) = 0.0 10 CONTINUE you would paralyze early virtual memory systems, because Fortran IV defined arrays to be stored in column major order, and the result was extreme thrashing. Many programmers did not realize this, and would naturally write code like that. Fortran cognoscenti would interchange the two DO statements and thus convert Fortran from being a slow language to being a fast one. 4. When Sun released the original Java system, programs ran very slowly, and everybody said `I will not use Java, it is a slow language'. Then Sun improved their JVM, and other organizations wrote their own JVMs which were fast. Therefore Java became a fast language. > Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. OK, let me work this one out. Because most iostreams implementations are very slow, C++ is a slow language. But since Kuhl did a high-performance implementation, he made C++ into a fast language. But since most people don't use his iostreams implementation, C++ is a slow language again, except for organizations that have banned iostreams (as my previous employers did) because it's too slow, therefore C++ is a fast language. Being imprecise is so much fun! I should write my programs this imprecisely. More seriously, when someone says `xxx is a slow language', the only thing they can possibly mean is `there is no implementation in existence, and no likelihood of an implementation being possible, that is efficient enough to solve my problem in the required time' or perhaps `I must write peculiar code in order to get programs to run in the specified time; writing code in the way the language seems to encourage produces programs that are too slow'. This is a very sweeping statement, and at the very least ought to be accompanied by some kind of proof. If Python is indeed a slow language, then Unladen Swallow and pypy, and many other projects, are wastes of time, and should not be continued. Again, this doesn't have anything to do with features of an implementation that are slow or fast. The only criterion that makes sense is `do programs run with the required performance if written in the way the language's inventors encourage'. Most implementations of every language have a nook or two where things get embarrassingly slow; the question is `are most programs unacceptably slow'. But, hey, if we are ok with being imprecise, let's go for it. Instead of saying `slow' and `fast', why not say `good' and `bad'? -- v From bbrown at speakeasy.net Sat Nov 14 02:39:48 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 02:39:48 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis writes: > On 2009-11-13, at 18:02, Robert Brown wrote: > >> Common Lisp and Scheme were designed by people who wanted to write >> complicated systems on machines with a tiny fraction of the horsepower of >> current workstations. They were carefully designed to be compiled >> efficiently, which is not the case with Python. There really is a >> difference here. Python the language has features that make fast >> implementations extremely difficult. > > Not true. Common Lisp was designed primarily by throwing together all of the > features in every Lisp implementation the design committee was interested > in. Although the committee members were familiar with high-performance > compilation, the primary impetus was to achieve a standardized language that > would be acceptable to the Lisp community. At the time that Common Lisp was > started, there was still some sentiment that Lisp machines were the way to > go for performance. Common Lisp blends together features of previous Lisps, which were designed to be executed efficiently. Operating systems were written in these variants. Execution speed was important. The Common Lisp standardization committee included people who were concerned about performance on C-optimized hardware. > As for Scheme, it was designed primarily to satisfy an aesthetic of > minimalism. Even though Guy Steele's thesis project, Rabbit, was a Scheme > compiler, the point here was that relatively simple compilation techniques > could produce moderately reasonable object programs. Chez Scheme was indeed > first run on machines that we would nowadays consider tiny, but so too was > C++. Oh, wait, so was Python! The Scheme standard has gone through many revisions. I think we're up to version 6 at this point. The people working on it are concerned about performance. For instance, see the discussions about whether the order of evaluating function arguments should be specified. Common Lisp evaluates arguments left to right, but Scheme leaves the order unspecified so the compiler can better optimize. You can't point to Rabbit (1978 ?) as representative of the Scheme programming community over the last few decades. > Using Python 3 annotations, one can imagine a Python compiler that does the > appropriate thing (shown in the comments) with the following code. I can imagine a lot too, but we're talking about Python as it's specified *today*. The Python language as it's specified today is hard to execute quickly. Not impossible, but very hard, which is why we don't see fast Python systems. bob From sturlamolden at yahoo.no Sat Nov 14 02:51:33 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 13 Nov 2009 23:51:33 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <80ea1c52-c845-4802-b77a-d742e789b9b6@m26g2000yqb.googlegroups.com> On 14 Nov, 08:39, Robert Brown wrote: > > Using Python 3 annotations, one can imagine a Python compiler that does the > > appropriate thing (shown in the comments) with the following code. > > I can imagine a lot too, but we're talking about Python as it's specified > *today*. ?The Python language as it's specified today is hard to execute > quickly. ?Not impossible, but very hard, which is why we don't see fast Python > systems. It would not be too difficult to have a compiler like Cython recognize those annotations instead of current "cdef"s. With Cython we can get "Python" to run at "the speed of C" just by adding in optional type declarations for critical variables (most need not be declared). With CMUCL and SBCL we can make Common Lisp perform at "the speed of C", for the same reason. Also a Cython program will usually out-perform most C code. It combines the strengths of C, Fortran 90 and Python. From vmanis at telus.net Sat Nov 14 02:55:22 2009 From: vmanis at telus.net (Vincent Manis) Date: Fri, 13 Nov 2009 23:55:22 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2009-11-13, at 23:20, Robert Brown wrote, quoting me: > On 2009-11-13, at 17:42, Robert Brown wrote, quoting me: > >>> ... Python *the language* is specified in a way that >>> makes executing Python programs quickly very very difficult. > >> That is untrue. I have mentioned before that optional declarations integrate >> well with dynamic languages. Apart from CL and Scheme, which I have >> mentioned several times, you might check out Strongtalk (typed Smalltalk), >> and Dylan, which was designed for high-performance compilation, though to my >> knowledge no Dylan compilers ever really achieved it. > > You are not making an argument, just mentioning random facts. You claim I've > made a false statement, then talk about optional type declarations, which > Python doesn't have. Then you mention Smalltalk and Dylan. What's your > point? To prove me wrong you have to demonstrate that it's not very difficult > to produce a high performance Python system, given current Python semantics. The false statement you made is that `... Python *the language* is specified in a way that makes executing Python programs quickly very very difficult. I refuted it by citing several systems that implement languages with semantics similar to those of Python, and do so efficiently. >> I've never looked at CLPython. Did it use a method cache (see Peter >> Deutsch's paper on Smalltalk performance in the unfortunately out-of-print >> `Smalltalk-80: Bits of History, Words of Advice'? That technique is 30 years >> old now. > > Please look at CLPython. The complexity of some Python operations will make > you weep. CLPython uses Common Lisp's CLOS method dispatch in various places, > so yes, those method lookups are definitely cached. Ah, that does explain it. CLOS is most definitely the wrong vehicle for implementing Python method dispatch. CLOS is focused around generic functions that themselves do method dispatch, and do so in a way that is different from Python's. If I were building a Python implementation in CL, I would definitely NOT use CLOS, but do my own dispatch using funcall (the CL equivalent of the now-vanished Python function apply). > Method lookup is just the tip if the iceburg. How about comparison? Here are > some comments from CLPython's implementation of compare. There's a lot going > on. It's complex and SLOW. Re comparison. Python 3 has cleaned comparison up a fair bit. In particular, you can no longer compare objects of different types using default comparisons. However, it could well be that there are nasty little crannies of inefficiency there, they could be the subject of PEPs after the moratorium is over. > > ;; The CPython logic is a bit complicated; hopefully the following > ;; is a correct translation. I can see why CLPython has such troubles. The author has endeavoured to copy CPython faithfully, using an implementation language (CLOS) that is hostile to Python method dispatch. OK, let me try this again. My assertion is that with some combination of JITting, reorganization of the Python runtime, and optional static declarations, Python can be made acceptably fast, which I define as program runtimes on the same order of magnitude as those of the same programs in C (Java and other languages have established a similar goal). I am not pushing optional declarations, as it's worth seeing what we can get out of JITting. If you wish to refute this assertion, citing behavior in CPython or another implementation is not enough. You have to show that the stated feature *cannot* be made to run in an acceptable time. For example, if method dispatch required an exponential-time algorithm, I would agree with you. But a hypothetical implementation that did method dispatch in exponential time for no reason would not be a proof, but would rather just be a poor implementation. -- v From sturlamolden at yahoo.no Sat Nov 14 03:05:59 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:05:59 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <87my2r7imn.fsf@agentultra.com> Message-ID: <840a4457-1973-4cdd-9cb5-92781fab8255@b2g2000yqi.googlegroups.com> On 12 Nov, 18:33, J Kenneth King wrote: > Where Python might get hit *as a language* is that the Python programmer > has to drop into C to implement optimized data-structures for dealing > with the kind of IO that would slow down the Python interpreter. ?That's > why we have numpy, scipy, etc. That's not a Python specific issue. We drop to SciPy/NumPy for certain compute-bound tasks that operates on vectors. If that does not help, we drop further down to Cython, C or Fortran. If that does not help, we can use assembly. In fact, if we use SciPy linked against GotoBLAS, a lot of compute-intensive work solving linear algebra is delegated to hand-optimized assembly. With Python we can stop at the level of abstraction that gives acceptable performance. When using C, we start out at a much lower level. The principle that premature optimization is the root of all evil applies here: Python code that is fast enough is fast enough. It does not matter that hand-tuned assembly will be 1000 times faster. We can direct our optimization effort to the parts of the code that needs it. From http Sat Nov 14 03:10:50 2009 From: http (Paul Rubin) Date: 14 Nov 2009 00:10:50 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <80ea1c52-c845-4802-b77a-d742e789b9b6@m26g2000yqb.googlegroups.com> Message-ID: <7xk4xta5md.fsf@ruckus.brouhaha.com> sturlamolden writes: > With Cython we can get "Python" to run at "the speed of C" just by > adding in optional type declarations for critical variables (most need > not be declared). I think there are other semantic differences too. For general thoughts on such differences (Cython is not mentioned though), see: http://dirtsimple.org/2005/10/children-of-lesser-python.html From vmanis at telus.net Sat Nov 14 03:20:13 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 00:20:13 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <3E25D697-E753-4D05-92DE-F80ED167F7EE@telus.net> On 2009-11-13, at 23:39, Robert Brown wrote, quoting me: > Common Lisp blends together features of previous Lisps, which were designed to > be executed efficiently. Operating systems were written in these variants. > Execution speed was important. The Common Lisp standardization committee > included people who were concerned about performance on C-optimized hardware. Guy L Steele, Jr., `Common Lisp The Language' 1/e (1984). p. 1 `COMMON LISP is intended to meet these goals: Commonality [...] Portability [...] Consistency [...] Expressiveness [...] Compatibility [...] Efficiency [...] Power [...] Stability [...]' The elided text amplifies each of the points. I repeat: the purpose of Common Lisp was to have a standard Lisp dialect; efficiency was less of an issue for those investigators. As for C-optimized hardware, well, the dialects it aims to be compatible with are ZetaLisp (Symbolics Lisp Machine), MacLisp (PDP-10), and Interlisp (PDP-10, originally). CLtL mentions S-1 Lisp as its exemplar of high numerical performance. Unfortunately, S-1 Lisp, written by Richard Gabriel and Rod Brooks was never finished. MacLisp was a highly efficient implementation, as I've mentioned. I worked at BBN at the time Interlisp flourished; it was many things, some of them quite wonderful, but efficiency was NOT its goal. > The Scheme standard has gone through many revisions. I think we're up to > version 6 at this point. The people working on it are concerned about > performance. Yes, they are. You should see 's rants about how specified certain features so they'd be efficient on his implementation. I had real people's names there, but I deleted them in the interests of not fanning flamewar flames. > For instance, see the discussions about whether the order of > evaluating function arguments should be specified. That was a long time ago, and had as much if not more to do with making arguments work the same as let forms as it had to do with efficiency. But I'll point out that the big feature of Scheme is continuations, and it took quite a few years after the first Scheme implementations came out to make continuations stop being horrendously *IN*efficient. > You can't point to Rabbit (1978 ?) as > representative of the Scheme programming community over the last few decades. I didn't. I used it to buttress YOUR argument that Schemers have always been concerned with performance. >> Using Python 3 annotations, one can imagine a Python compiler that does the >> appropriate thing (shown in the comments) with the following code. > I can imagine a lot too, but we're talking about Python as it's specified > *today*. The Python language as it's specified today is hard to execute > quickly. Not impossible, but very hard, which is why we don't see fast Python > systems. Python 3 annotations exist. Check the Python 3 Language Reference. I notice you've weakened your claim. Now we're down to `hard to execute quickly'. That I would agree with you on, in that building an efficient Python system would be a lot of work. However, my claim is that that work is engineering, not research: most of the bits and pieces of how to implement Python reasonably efficiently are known and in the public literature. And that has been my claim since the beginning. -- v From alfps at start.no Sat Nov 14 03:22:03 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 09:22:03 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-13, at 22:51, Alf P. Steinbach wrote: >> It's sort of hilarious. > It really is, see below. > >> So no, it's not a language that is slow, it's of course only concrete implementations that may have slowness flavoring. And no, not really, they don't, because it's just particular aspects of any given implementation that may exhibit slowness in certain contexts. And expanding on that trend, later in the thread the observation was made that no, not really that either, it's just (if it is at all) at this particular point in time, what about the future? Let's be precise! Can't have that vague touchy-feely impression about a /language/ being slow corrupting the souls of readers. > Because `language is slow' is meaningless. > > An earlier post of mine listed four examples where the common wisdom was `XXX is slow' and yet where that > turned out not to be the case. > > Some others. > > 1. I once owned a Commodore 64. I got Waterloo Pascal for it. I timed the execution of some program > (this was 25 years ago, I forget what the program did) at 1 second per statement. Therefore: `Pascal > is slow'. > > 2. Bell Labs produced a fine programming language called Snobol 4. It was slow. But some folks at > IIT in Chicago did their own implementation, Spitbol, which was fast and completely compatible. > Presto: Snobol 4 was slow, but then it became fast. > > 3. If you write the following statements in Fortran IV (the last version of Fortran I learned) > > DO 10 I=1, 1000000 > DO 10 J=1, 1000000 > A(I, J) = 0.0 > 10 CONTINUE > > you would paralyze early virtual memory systems, because Fortran IV defined arrays to be stored > in column major order, and the result was extreme thrashing. Many programmers did not realize > this, and would naturally write code like that. Fortran cognoscenti would interchange the two > DO statements and thus convert Fortran from being a slow language to being a fast one. > > 4. When Sun released the original Java system, programs ran very slowly, and everybody said > `I will not use Java, it is a slow language'. Then Sun improved their JVM, and other organizations > wrote their own JVMs which were fast. Therefore Java became a fast language. > >> Actually, although C++ has the potential for being really really fast (and some C++ programs are), the amount of work you have to add to realize the potential can be staggering. This is most clearly evidenced by C++'s standard iostreams, which have the potential of being much much faster than C FILE i/o (in particular Dietmar Kuhl made such an implementation), but where the complexity of and the guidance offered by the "design" is such that nearly all extant implementations are painfully slow, even compared to C FILE. So, we generally talk about iostreams being slow, knowing full well what we mean and that fast implementations are theoretically possible (as evidenced by Dietmar's) -- but "fast" and "slow" are in-practice terms, and so what matters is in-practice, like, how does your compiler's iostreams implementation hold up. > OK, let me work this one out. Because most iostreams implementations are very slow, C++ is a slow > language. But since Kuhl did a high-performance implementation, he made C++ into a fast language. > But since most people don't use his iostreams implementation, C++ is a slow language again, except > for organizations that have banned iostreams (as my previous employers did) because it's too slow, > therefore C++ is a fast language. > > Being imprecise is so much fun! I should write my programs this imprecisely. > > More seriously, when someone says `xxx is a slow language', the only thing they can possibly mean > is `there is no implementation in existence, and no likelihood of an implementation being possible, > that is efficient enough to solve my problem in the required time' or perhaps `I must write peculiar > code in order to get programs to run in the specified time; writing code in the way the language seems > to encourage produces programs that are too slow'. This is a very sweeping statement, and at the very > least ought to be accompanied by some kind of proof. If Python is indeed a slow language, then Unladen > Swallow and pypy, and many other projects, are wastes of time, and should not be continued. > > Again, this doesn't have anything to do with features of an implementation that are slow or fast. > The only criterion that makes sense is `do programs run with the required performance if written > in the way the language's inventors encourage'. Most implementations of every language have a nook > or two where things get embarrassingly slow; the question is `are most programs unacceptably slow'. > > But, hey, if we are ok with being imprecise, let's go for it. Instead of saying `slow' and `fast', > why not say `good' and `bad'? :-) You're piling up so extremely many fallacies in one go that I just quoted it all. Anyways, it's a good example of focusing on irrelevant and meaningless precision plus at the same time utilizing imprecision, higgedly-piggedly as it suits one's argument. Mixing hard precise logic with imprecise concepts and confound e.g. universal quantification with existential quantification, for best effect several times in the same sentence. Like the old Very Hard Logic + imprecision adage: "we must do something. this is something. ergo, we must do this". It's just idiocy. But fun. Cheers & hth., - Alf From ben+python at benfinney.id.au Sat Nov 14 03:28:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 14 Nov 2009 19:28:31 +1100 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> Message-ID: <87tywxse6o.fsf@benfinney.id.au> Paul Rudin writes: > I'm experimenting with the daemon module > and upstart > . First: Thank you for using ?python-daemon?; it's getting more widespread use all the time, which is really helping to find all the quirks of API and implementation. (And good for my ego at the same time.) > There's something I don't understand, which may be more of an upstart > issue than a python issue, but I thought I'd start by posting here. I'm unfamiliar with ?upstart?, I hope others with more experience can offer more insight. > Here's a test script: [?] The program looks fine to me. What happens if you run the program, without getting ?upstart? involved? > and here's a testdaemon.conf upstart configuration: > > description "test daemon" > expect daemon > chdir /tmp > exec /tmp/testdaemon.py > > If I do "sudo start testdaemon" I see the "testdaemon.py" process > starting, and the file '/tmp/test.txt' is being written to every 5 > seconds, so everything has kicked off. Good to know. > The thing I don't understand is why start does not return. I guess it > doesn't think that the process and properly started and daemonized > itself? Quite possibly it's just that I don't understand this stuff > well... As I say, I'm completely unfamiliar with the details of ?upstart?. Can you point me to whatever you used to understand it? -- \ ?I bought some batteries, but they weren't included; so I had | `\ to buy them again.? ?Steven Wright | _o__) | Ben Finney From deets at nospam.web.de Sat Nov 14 03:32:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 09:32:53 +0100 Subject: QuerySets in Dictionaries In-Reply-To: <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <7m789lF3gaf1qU1@mid.uni-berlin.de> scoopseven schrieb: > On Nov 12, 8:55 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 12 Nov 2009 10:39:33 -0800, scoopseven wrote: >>> I need to create a dictionary of querysets. I have code that looks >>> like: >>> query1 = Myobject.objects.filter(status=1) >>> query2 = Myobject.objects.filter(status=2) >>> query3 = Myobject.objects.filter(status=3) >>> d={} >>> d['a'] = query1 >>> d['b'] = query2 >>> d['c'] = query3 >>> Is there a way to do this that I'm missing? >> I don't understand your problem. Assuming Myobject is defined, and has >> the appropriate attribute objects.filter, the above should work exactly >> as you give it. >> >> What is your actual problem? Are you asking for help in defining a >> queryset? >> >> -- >> Steven > > I actually had a queryset that was dynamically generated, so I ended > up having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) > > And no, this is not based on user-generated input. Why do you need this to use exec? And it seems that executable_string is superflous - or do you want the side-effect? But then, you have the results in d already. query = Thing.objects.filter(type="%i" % thing.id).order_by('-date')[:3] d[query_name] = query As a rule of thumb: if you think you need exec, you don't. Diez From sturlamolden at yahoo.no Sat Nov 14 03:36:23 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:36:23 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > Of course Python is slow: if you want speed, pay for it by complexity. Python is slow is really a misconception. Python is used for scientific computing at HPC centres around the world. NumPy's predecessor numarray was made by NASA for the Hubble space telescope. Python is slow for certain types of tasks, particularly iterative compute-bound work. But who says you have to use Python for this? It can easily be delegated to libraries written in C or Fortran. I can easily demonstrate Python being faster than C. For example, I could compare the speed of appending strings to a list and "".join (strlist) with multiple strcats in C. I can easily demonstrate C being faster than Python as well. To get speed from a high-level language like Python you have to leverage on high-level data types. But then you cannot compare algorithms in C and Python directly. Also consider that most program today are not CPU-bound: They are i/o bound or memory-bound. Using C does not give you faster disk access, faster ethernet connection, or faster RAM... It does not matter that computation is slow if the CPU is starved anyway. We have to consider what actually limits the speed of a program. Most of all I don't care that computation is slow if slow is fast enough. For example, I have a Python script that parses OpenGL headers and writes a declaration file for Cython. It takes a fraction of a second to complete. Should I migrate it to C to make it 20 times faster? Or do you really think I care if it takes 20 ms or just 1 ms to complete? The only harm the extra CPU cycles did was a minor contribution to global warming. From vmanis at telus.net Sat Nov 14 03:37:23 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 00:37:23 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <425A32A3-0714-4C34-A133-697D5B25B546@telus.net> On 2009-11-14, at 00:22, Alf P. Steinbach wrote, in response to my earlier post. > Anyways, it's a good example of focusing on irrelevant and meaningless precision plus at the same time utilizing imprecision, higgedly-piggedly as it suits one's argument. Mixing hard precise logic with imprecise concepts and confound e.g. universal quantification with existential quantification, for best effect several times in the same sentence. Like the old Very Hard Logic + imprecision adage: "we must do something. this is something. ergo, we must do this". OK, now we've reached a total breakdown in communication, Alf. You appear to take exception to distinguishing between a language and its implementation. My academic work, before I became a computer science/software engineering instructor, was in programming language specification and implementation, so I *DO* know what I'm talking about here. However, you and I apparently are speaking on different wavelengths. > It's just idiocy. Regretfully, I must agree. > But fun. Not so much, from my viewpoint. -- v From deets at nospam.web.de Sat Nov 14 03:40:42 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 09:40:42 +0100 Subject: The ol' [[]] * 500 bug... In-Reply-To: References: Message-ID: <7m78oaF3fgtcfU1@mid.uni-berlin.de> kj schrieb: > ...just bit me in the "fuzzy posterior". The best I can come up with > is the hideous > > lol = [[] for _ in xrange(500)] If you call that hideous, I suggest you perform the same exercise in Java or C++ - and then come back to python and relax.... Diez From sturlamolden at yahoo.no Sat Nov 14 03:43:19 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 00:43:19 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <027b5ed1-91ed-4b72-b2e0-0c86673ebc87@p8g2000yqb.googlegroups.com> On 14 Nov, 02:42, Robert Brown wrote: > If you want to know why Python *the language* is slow, look at the Lisp code > CLPython generates and at the code implementing the run time. ?Simple > operations end up being very expensive. You can also see this by looking at the C that Cython or Pyrex generates. You can also see the dramatic effect by a handful of strategically placed type declarations. From alfps at start.no Sat Nov 14 03:47:28 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 09:47:28 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: * sturlamolden: > On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > >> Of course Python is slow: if you want speed, pay for it by complexity. > > Python is slow is really a misconception. Sorry, no, I don't think so. But we can't know that without ESP powers. Which seem to be in short supply. > Python is used for > scientific computing at HPC centres around the world. NumPy's > predecessor numarray was made by NASA for the Hubble space telescope. > Python is slow for certain types of tasks, particularly iterative > compute-bound work. But who says you have to use Python for this? It > can easily be delegated to libraries written in C or Fortran. Yes, that's what I wrote immediately following what you quoted. > I can easily demonstrate Python being faster than C. For example, I > could compare the speed of appending strings to a list and "".join > (strlist) with multiple strcats in C. I can easily demonstrate C being > faster than Python as well. That is a straw man argument (which is one of the classic fallacies), that is, attacking a position that nobody's argued for. > To get speed from a high-level language like Python you have to > leverage on high-level data types. But then you cannot compare > algorithms in C and Python directly. > > Also consider that most program today are not CPU-bound: They are i/o > bound or memory-bound. Using C does not give you faster disk access, > faster ethernet connection, or faster RAM... It does not matter that > computation is slow if the CPU is starved anyway. We have to consider > what actually limits the speed of a program. > > Most of all I don't care that computation is slow if slow is fast > enough. For example, I have a Python script that parses OpenGL headers > and writes a declaration file for Cython. It takes a fraction of a > second to complete. Should I migrate it to C to make it 20 times > faster? Or do you really think I care if it takes 20 ms or just 1 ms > to complete? The only harm the extra CPU cycles did was a minor > contribution to global warming. Yeah, that's what I wrote immediately following what you quoted. So, except for the straw man arg and to what degree there is a misconception, which we can't know without ESP, it seems we /completely agree/ on this :-) ) Cheers & hth., - Alf From http Sat Nov 14 03:50:41 2009 From: http (Paul Rubin) Date: 14 Nov 2009 00:50:41 -0800 Subject: The ol' [[]] * 500 bug... References: Message-ID: <7xbpj5trq6.fsf@ruckus.brouhaha.com> kj writes: > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] lol = map(list, [()] * 500) From sturlamolden at yahoo.no Sat Nov 14 04:02:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 01:02:49 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > Hm, this seems religious. > > Of course Python is slow: if you want speed, pay for it by complexity. Not really. The speed problems of Python can to a large extent be attributed to a sub-optimal VM. Perl tends to be much faster than Python. Certain Common Lisp and Scheme implementations can often perform comparable to C++. There are JIT-compiled JavaScript which are very efficient. Java's Hotspot JIT comes from StrongTalk, a fast version of SmallTalk. It's not the static typing that makes Java run fast. It is a JIT originally developed for a dynamic language. Without Hotspot, Java can be just as bad as Python. Even more remarkable: Lua with LuaJIT performs about ~80% of GCC on Debian benchmarks. Question: Why is Lua so fast and Python so slow? Here we have two very similar dynamic scripting languages. One beats JIT-compiled Java and almost competes with C. The other is the slowest there is. Why? Lot of it has to do with the simple fact that Python' VM is stack-based whereas Lua's VM is register based. Stack-based VM's are bad for branch prediction and work against the modern CPUs. Python has reference counting which is bad for cache. Lua has a tracing GC. But these are all implementation details totally orthogonal to the languages. Python on a better VM (LuaJIT, Parrot, LLVM, several JavaScript) will easily outperform CPython by orders of magnitide. Sure, Google can brag about Go running at 80% of C speed, after introducing static typing. But LuaJIT does the same without any typing at all. From alfps at start.no Sat Nov 14 04:11:40 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 10:11:40 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-14, at 00:22, Alf P. Steinbach wrote, in response to my earlier post. > >> Anyways, it's a good example of focusing on irrelevant and meaningless >> precision plus at the same time utilizing imprecision, higgedly-piggedly >> as it suits one's argument. Mixing hard precise logic with imprecise >> concepts and confound e.g. universal quantification with existential >> quantification, for best effect several times in the same sentence. Like >> the old Very Hard Logic + imprecision adage: "we must do something. this >> is something. ergo, we must do this". > > OK, now we've reached a total breakdown in communication, Alf. You appear > to take exception to distinguishing between a language and its implementation. Not at all. But that doesn't mean that making that distinction is always meaningful. It's not like "there exists a context where making the distinction is not meaningful" means that "in all contexts making the distinction is meaningful". So considering that, my quoted comment about confounding universal quantification with existential quantification was spot on... :-) In some contexts, such as here, it is meaningless and just misleading to add the extra precision of the distinction between language and implementation. Academically it's there. But it doesn't influence anything (see below). Providing a counter example, a really fast Python implementation for the kind of processing mix that Google does, available for the relevant environments, would be relevant. Bringing in the hypothethical possibility of a future existence of such an implementation is, OTOH., only hot air. If someone were to apply the irrelevantly-precise kind of argument to that, then one could say that future hypotheticals don't have anything to do with what Python "is", today. Now, there's a fine word-splitting distinction... ;-) > My academic work, before I became a computer science/software engineering > instructor, was in programming language specification and implementation, > so I *DO* know what I'm talking about here. However, you and I apparently > are speaking on different wavelengths. Granted that you haven't related incorrect facts, and I don't think anyone here has, IMO the conclusions and implied conclusions still don't follow. Cheers & hth., - Alf From alfps at start.no Sat Nov 14 04:17:15 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 10:17:15 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * sturlamolden: > On 12 Nov, 18:32, "Alf P. Steinbach" wrote: > >> Hm, this seems religious. >> >> Of course Python is slow: if you want speed, pay for it by complexity. > > Not really. The speed problems of Python can to a large extent be > attributed to a sub-optimal VM. > > Perl tends to be much faster than Python. > > Certain Common Lisp and Scheme implementations can often perform > comparable to C++. > > There are JIT-compiled JavaScript which are very efficient. > > Java's Hotspot JIT comes from StrongTalk, a fast version of SmallTalk. > It's not the static typing that makes Java run fast. It is a JIT > originally developed for a dynamic language. Without Hotspot, Java can > be just as bad as Python. > > Even more remarkable: Lua with LuaJIT performs about ~80% of GCC on > Debian benchmarks. Question: Why is Lua so fast and Python so slow? > Here we have two very similar dynamic scripting languages. One beats > JIT-compiled Java and almost competes with C. The other is the slowest > there is. Why? Lot of it has to do with the simple fact that Python' > VM is stack-based whereas Lua's VM is register based. Stack-based VM's > are bad for branch prediction and work against the modern CPUs. Python > has reference counting which is bad for cache. Lua has a tracing GC. > But these are all implementation details totally orthogonal to the > languages. Python on a better VM (LuaJIT, Parrot, LLVM, several > JavaScript) will easily outperform CPython by orders of magnitide. > > Sure, Google can brag about Go running at 80% of C speed, after > introducing static typing. But LuaJIT does the same without any typing > at all. Good points and good facts. And you dispensed with the word-splitting terminology discussion, writing just "The other [language] is the slowest". Currently. He he. :-) And it is, as you imply, totally in the in-practice domain. Cheers, - Alf From Brian.Mingus at Colorado.EDU Sat Nov 14 04:26:52 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 14 Nov 2009 02:26:52 -0700 Subject: The ol' [[]] * 500 bug... In-Reply-To: <7xbpj5trq6.fsf@ruckus.brouhaha.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> Message-ID: <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin wrote: > kj writes: > > lol = [None] * 500 > > for i in xrange(len(lol)): > > lol[i] = [] > > lol = map(list, [()] * 500) Could someone explain what the deal is with this thread? Thanks. [[]]*500 -------------- next part -------------- An HTML attachment was scrubbed... URL: From vmanis at telus.net Sat Nov 14 04:48:25 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 01:48:25 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >> OK, now we've reached a total breakdown in communication, Alf. You appear >> to take exception to distinguishing between a language and its implementation. > > Not at all. > > But that doesn't mean that making that distinction is always meaningful. It certainly is. A language is a (normally) infinite set of strings with a way of ascribing a meaning to each string. A language implementation is a computer program of some sort, which is a finite set of bits representing a program in some language, with the effect that the observed behavior of the implementation is that strings in the language are accepted, and the computer performs the operations defined by the semantics. These are always different things. > It's not like "there exists a context where making the distinction is not meaningful" means that "in all contexts making the distinction is meaningful". Because they are different things, in all cases the distinction is meaningful. > > So considering that, my quoted comment about confounding universal quantification with existential quantification was spot on... :-) It was not spot on. The examples I provided were just that, examples to help people see the difference. They were not presented as proof. The proof comes from the definitions above. > In some contexts, such as here, it is meaningless and just misleading to add the extra precision of the distinction between language and implementation. Academically it's there. But it doesn't influence anything (see below). Your assertion that this distinction is meaningless must be based upon YOUR definitions of words like `language' and `implementation'. Since I don't know your definitions, I cannot respond to this charge. > Providing a counter example, a really fast Python implementation for the kind of processing mix that Google does, available for the relevant environments, would be relevant. I have presented arguments that the technologies for preparing such an implementation are basically known, and in fact there are projects that aim to do exactly that. > > Bringing in the hypothethical possibility of a future existence of such an implementation is, OTOH., only hot air. Hmm...in every programming project I have ever worked on, the goal was to write code that didn't already exist. > If someone were to apply the irrelevantly-precise kind of argument to that, then one could say that future hypotheticals don't have anything to do with what Python "is", today. Now, there's a fine word-splitting distinction... ;-) Python is a set of strings, with a somewhat sloppily-defined semantics that ascribes meaning to the legal strings in the language. It was thus before any implementation existed, although I imagine that the original Python before GvR wrote any code had many differences from what Python is today. It is quite common for language designers to specify a language completely without regard to an implementation, or only a `reference' implementation that is not designed for performance or robustness. The `good' implementation comes after the language has been defined (though again languages and consequently implementations are almost always modified after the original release). If you like, a language is part of (but not all of) the set of requirements for the implementation. Alf, if you want to say that this is a difference that makes no difference, don't let me stop you. You are, however, completely out of step with the definitions of these terms as used in the field of programming languages. >> My academic work, before I became a computer science/software engineering >> instructor, was in programming language specification and implementation, so I *DO* know what I'm talking about here. However, you and I apparently >> are speaking on different wavelengths. > > Granted that you haven't related incorrect facts, and I don't think anyone here has, IMO the conclusions and implied conclusions still don't follow. The fact that you see the situation that way is a consequence of the fact that we're on different wavelengths. -- v From vlastimil.brom at gmail.com Sat Nov 14 04:50:58 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 14 Nov 2009 10:50:58 +0100 Subject: The ol' [[]] * 500 bug... In-Reply-To: <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> Message-ID: <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> 2009/11/14 Brian J Mingus : > > > On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin > wrote: >> >> kj writes: >> > ? lol = [None] * 500 >> > ? for i in xrange(len(lol)): >> > ? ? ? lol[i] = [] >> >> lol = map(list, [()] * 500) > > Could someone explain what the deal is with this thread? Thanks. > [[]]*500 > Try >>> lst=[[]]*500 >>> lst[7].append(2) >>> lst to see... vbr From Brian.Mingus at Colorado.EDU Sat Nov 14 05:08:46 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 14 Nov 2009 03:08:46 -0700 Subject: The ol' [[]] * 500 bug... In-Reply-To: <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> References: <7xbpj5trq6.fsf@ruckus.brouhaha.com> <9839a05c0911140126w6a69f095w8df350fd470947e3@mail.gmail.com> <9fdb569a0911140150j4243b89fp5901f50aaa94c576@mail.gmail.com> Message-ID: <9839a05c0911140208y4429adefx7882e45446753bd7@mail.gmail.com> On Sat, Nov 14, 2009 at 2:50 AM, Vlastimil Brom wrote: > 2009/11/14 Brian J Mingus : > > > > > > On Sat, Nov 14, 2009 at 1:50 AM, Paul Rubin @nospam.invalid> > > wrote: > >> > >> kj writes: > >> > lol = [None] * 500 > >> > for i in xrange(len(lol)): > >> > lol[i] = [] > >> > >> lol = map(list, [()] * 500) > > > > Could someone explain what the deal is with this thread? Thanks. > > [[]]*500 > > > > Try > >>> lst=[[]]*500 > >>> lst[7].append(2) > >>> lst > to see... > > vbr > -- > I see.. Here's what I came up with: list(eval('[],'*500)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Sat Nov 14 05:22:54 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 02:22:54 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: On 14 Nov, 09:47, "Alf P. Steinbach" wrote: > > Python is slow is really a misconception. > > Sorry, no, I don't think so. No, i really think a lot of the conveived slowness in Python comes from bad programming practices. Sure we can deomstrate that C or LuaJIT is faster by orders of magnitude for CPU-bound tasks like comparing DNA-sequences or or calculating the value of pi. But let me give an example to the opposite from graphics programming, one that we often run into when using OpenGL. This is not a toy benchmark problem but one that is frequently encountered in real programs. We all know that calling functions in Python has a big overhead. There are a dictionary lookup for the attribute name, and arguments are packed into a tuple (and somtimes a dictionary). Thus calling glVertex* repeatedly from Python will hurt. Doing it from C or Fortran might still be ok (albeit not always recommended). So should we conclude that Python is too slow and use C instead? No! What if we use glVertexArray or a display list instead? In case of a vertex array (e.g. using NumPy ndarray for storage), there is practically no difference in performance of C and Python. With a display list, there is a difference on creation, but not on invocation. So slowness from calling glVertex* multiple times is really slowness from bad Python programming. I use numpy ndarrays to store vertices, and pass them to OpenGL as a vertex arrays, instead of hammering on glVertex* in a tight loop. And speed wise, it does not really matter if I use C or Python. But what if we need some computation in the graphics program as well? We might use OpenCL, DirectCompute or OpenGL vertex shaders to control the GPU. Will C be better than Python for this? Most likely not. A program for the GPU is compiled by the graphics driver at run-time from a text string passed to it. It is much better to use Python than C to generate these. Will C on the CPU be better than OpenCL or a vertex shader on the GPU? Most likely not. So we might perhaps conclude that Python (with numpy) is better than C for high-performance graphics? Even though Python is slower than C, we can do just as well as C programmers by not falling into a few stupid pitfalls. Is Python really slower than C for practical programming like this? Superficially, perhaps yes. In practice, only if you use it badly. But that's not Python's fault. But if you make a CPU-bound benchmark like Debian, or time thousands of calls to glVertex*, yes it will look like C is much better. But it does not directly translate to the performance of a real program. The slower can be the faster, it all depends on the programmer. Two related issues: - For the few cases where a graphics program really need C, we can always resort to using ctypes, f2py or Cython. Gluing Python with C or Fortran is very easy using these tools. That is much better than keeping it all in C++. - I mostly find myself using Cython instead of Python for OpenGL. That is because I am unhappy with PyOpenGL. It was easier to expose the whole of OpenGL to Cython than create a full or partial wrapper for Python. With Cython there is no extra overhead from calling glVertex* in a tight loop, so we get the same performance as C in this case. But because I store vertices in NumPy arrays on the Python side, I mostly end up using glVertexArray anyway. From rschroev_nospam_ml at fastmail.fm Sat Nov 14 05:28:48 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 14 Nov 2009 11:28:48 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: Vincent Manis schreef: > On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >>> OK, now we've reached a total breakdown in communication, Alf. You appear >>> to take exception to distinguishing between a language and its implementation. >> Not at all. >> >> But that doesn't mean that making that distinction is always meaningful. > It certainly is. A language is a (normally) infinite set of strings with a way of ascribing > a meaning to each string. That's true, for sure. But when people in the Python community use the word Python, the word is not used in the strict sense of Python the language. They use it to refer to both the language and one or more of implementations, mostly one of the existing and working implementations, and in most cases CPython (and sometimes it can also include the documentation, the website or the community). Example: go to http://python.org. Click Download. That page says "Download Python The current product versions are Python 2.6.4 and Python 3.1.1 ..." You can't download a language, but you can download an implementation. Clearly, even the project's website itself uses Python not only to refer to the language, but also to it's main implementation (and in a few places to other implementations). >From that point of view, your distinction between languages and implementations is correct but irrelevant. What is relevant is that all currently usable Python implementations are slow, and it's not incorrect to say that Python is slow. If and when a fast Python implementation gets to a usable state and gains traction (in the hopefully not too distant future), that changes. We'll have to say that Python can be fast if you use the right implementation. And once the most commonly used implementation is a fast one, we'll say that Python is fast, unless you happen to use a slow implementation for one reason or another. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From alfps at start.no Sat Nov 14 05:30:36 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 11:30:36 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: * Vincent Manis: > On 2009-11-14, at 01:11, Alf P. Steinbach wrote: >>> OK, now we've reached a total breakdown in communication, Alf. You appear >>> to take exception to distinguishing between a language and its implementation. >> Not at all. >> >> But that doesn't mean that making that distinction is always meaningful. > It certainly is. A language is a (normally) infinite set of strings with a way of ascribing > a meaning to each string. > > A language implementation is a computer program of some sort, which is a finite set of bits > representing a program in some language, with the effect that the observed behavior of the > implementation is that strings in the language are accepted, and the computer performs the > operations defined by the semantics. > > These are always different things. Well, there you have it, your basic misconception. Sometimes, when that's practically meaningful, people use the name of a language to refer to both, as whoever it was did up-thread. Or, they might mean just the latter. :-) Apply some intelligence and it's all clear. Stick boneheadedly to preconceived distinctions and absolute context independent meanings, and statements using other meanings appear to be meaningless or very unclear. [snippety] Cheers & hth., - Alf PS: You might, or might not, benefit from looking up Usenet discussions on the meaning of "character code", which is classic case of the confusion you have here. There's even a discussion of that in some RFC somewhere, I think it was MIME-related. Terms mean different things in different *contexts*. From rschroev_nospam_ml at fastmail.fm Sat Nov 14 05:35:42 2009 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 14 Nov 2009 11:35:42 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> Message-ID: <2KvLm.59963$TK7.5365@newsfe18.ams2> Vincent Manis schreef: > I notice you've weakened your claim. Now we're down to `hard to execute > quickly'. That I would agree with you on, in that building an efficient > Python system would be a lot of work. However, my claim is that that work > is engineering, not research: most of the bits and pieces of how to implement > Python reasonably efficiently are known and in the public literature. And > that has been my claim since the beginning. You talk about what can be and what might be. We talk about what is. The future is an interesting place, but it's not here. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From jjunho at gmail.com Sat Nov 14 05:37:31 2009 From: jjunho at gmail.com (Juliano) Date: Sat, 14 Nov 2009 02:37:31 -0800 (PST) Subject: Help with database planning Message-ID: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Hello, everybody. I'm a linguist with practical skills on computers/programming. We've been working with an ontology at my department, and now I need to create a GUI viewer for the flat file we have. I tried to write an Ontology class which manages the data read and parsed from the flat file, but it takes a relatively long time. Besides, we have plans to set up a website for online display of said ontology. So, I have been being pushed towards changing the basic plan and build a DB so that data access will be faster and easier for both the desktop GUI and the web app. Right now, I'm trying to work with sqlite, since it can be used as a separate file for the GUI and as a DB for Django (which may be the choice for the web interface). I have been redaing some books on DBs but I kind of get stuck when it comes to the normalization and the planning of the tables. The problem is that we have basically four fields that can be arranged in a tree- like structure. Eg: Concept |----- Slot | `------ Facet | `------ Filler `----- Slot `------ Facet `------ Filler `------ Filler ... So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. Besides, some *slots* and *fillers* are themselves *concepts*, creating a sort of recursive reference. line_no concepts slots facets fillers ------------------------------------------------------------------------------ 00000 ABANDON DEFINITION VALUE "to leave or desert something or someone" 00001 ABANDON IS-A VALUE EXIT 00002 ABANDON LEXE MAP-LEX "leave behind-V1" 00003 ABANDON LEXE MAP-LEX abandon-V1 (...) 97420 ZULU DEFINITION VALUE "a language or dialect spoken in south africa and others" 97421 ZULU INSTANCE-OF VALUE OTHER-NIGER-KORDOFANIAN-LANGUAGE 97422 ZULU LANGUAGE-OF INV LESOTHO 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA I tried to create index tables for concepts, slots, facets and fillers, which gave me the following table: line_no concepts slots facets fillers ------------------------------------------------------------------------------ 00000 cn_00000 sl_00048 fc_00007 fl_07349 00001 cn_00000 cn_02605 fc_00007 cn_01768 00002 cn_00000 sl_00121 fc_00002 fl_04329 00003 cn_00000 sl_00121 fc_00002 fl_15009 (...) 97420 cn_05429 sl_00048 fc_00007 fl_01340 97421 cn_05429 cn_02493 fc_00007 cn_03526 97422 cn_05429 cn_02750 fc_00001 cn_02816 97423 cn_05429 cn_02750 fc_00001 cn_04580 (cn_XXXXX from concept index, sl_XXXXX from slot index, fc_XXXXX from facet index, fl_XXXXX from filler index.) As you can see, only concepts and facets are populated by their own type of data. Whereas slots and fillers can be populated by their own types or by concepts. What would be a good way to create tables for this situation? In fact, this is the first time I've ever tried to create a DB, so I'm completely lost. I'm looking forward to a reply... Thank you very much, Juliano From no.email at please.post Sat Nov 14 05:59:41 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 10:59:41 +0000 (UTC) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: In <7x3a4i56u7.fsf at ruckus.brouhaha.com> Paul Rubin writes: >kj writes: >> frequent* clp posters the ability to *easily* delete spam from the >> comp.lang.python server? >Um, this is usenet; there is no comp.lang.python server. Are you >saying you want a moderated newsgroup? Hmm, maybe this group is busy >enough that there is some merit to that idea. Sorry, I had a mistaken view of how usenet was implemented. But yeah, I guess I'm thinking of a moderated newsgroup, but with a large number of moderators working in parallel, and a very lax acceptance policy. The goal is to filter out only the obvious spam, and let through all the other non-spam traffic as quickly as possible... What do I mean by "obvious spam"? Well, among the most recent messages (that have survived my killfile policies) I see the following subject lines: * Top 10 US mp3 songs.....Cheers * www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red monkey gino green global true religion ed-hardy kidrobot jeans hoodies china supplier wholesaler exporters,manufacture * "jobs in france" "jobs in france for english people" "jobs in france for foreigners" "jobs in france for australians" "jobs in france for foreigners " "jobs in france for new zealanders" "jobs" "paris jobs" http://jobs-in-fr ance.blogspot.com/ * "germany jobs" "germany job sites" "germany job search" "jobs in germany" "german jobs" "germany jobs it" "germany jobs for foreigners" "germany jobsite" "germany jobs in english" on http://jobs-germany.blogspot.com/ Those look pretty obvious to me. But, as I already showed, I'm out of my depth here, so I'd better shut up. kynn From no.email at please.post Sat Nov 14 06:14:04 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:14:04 +0000 (UTC) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: In <7xpr7lixnn.fsf at ruckus.brouhaha.com> Paul Rubin writes: >It seems a little weird to me that they (Google) are concerned with >the speed of the compiler, indicating that they plan to write enormous >programs in the language. Fast compilation also means that Go can conceivably become an attractive alternative to interpreted languages, because the compilation stage can be made as unobtrusive as, say, Python's byte-compilation stage (except that the Go compiler is generating native code). I believe that OCaml already offers a way to run code via such on-the-fly compilation, but I doubt that OCaml's compilers are as fast as Go's. kynn From no.email at please.post Sat Nov 14 06:26:00 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:26:00 +0000 (UTC) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: In <129a67e4-328c-42b9-9bf3-152f1b76fa5a at k19g2000yqc.googlegroups.com> Michele Simionato writes: >It does not look so primitive to me, compared to commonly used >languages. >I am pretty sure that they are "missing a lot of the latest ideas" on >purpose. If they want to succeed and make Go a popular language in the >Google >infrastructure (ideally replacing C++) their selling point must be a >nearly zero >learning curve. Python succeded with the low learning curve idea. I >wish them >the best. Certainly it is time to replace C with something more >modern, be it Go >or some other language. The two goals of replacing C with "something more modern" and at the same time have a "nearly zero learning curve" seem to me mutually negating. The closer to zero the learning curve is, the closer to C/C++, and therefore the less modern, that language will be. The "dark matter" in this discussion Google's projected OS, Chrome. Will Go be to Chrome what C was/is to Unix? The close collaboration between Rob Pike and Ken Thompson in this project gives reason to think so. And if so, how has the design of Chrome shaped the design of Go? One more thing: I found Rob Pike's mutterings on generics (towards the end of his rollout video) rather offputting, because he gave the impression that some important aspects of the language were not even considered before major decisions for it were set in stone. It looks like, if they ever get around to supporting generics, it will be a late-in-the-day hack. kynn From rt8396 at gmail.com Sat Nov 14 06:26:41 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 03:26:41 -0800 (PST) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> On Nov 14, 4:59?am, kj wrote: > But, as I already showed, I'm out of my depth here, > so I'd better shut up. Don't give up so easy! The idea is great, what Paul is saying is that most people who read this group use newsreaders and that has nothing to do with google groups. These guy's have kill filters for just this sort of thing but either way the emails are on their puters so they have to deal with them on an individual basis. It would be nice however to clean up the Google group version and rid it of the plagues of spam infestations. From no.email at please.post Sat Nov 14 06:28:02 2009 From: no.email at please.post (kj) Date: Sat, 14 Nov 2009 11:28:02 +0000 (UTC) Subject: How to specify Python version in script? References: <77b812a9-d82c-4aaa-8037-ec30366fc14f@h34g2000yqm.googlegroups.com> Message-ID: In <77b812a9-d82c-4aaa-8037-ec30366fc14f at h34g2000yqm.googlegroups.com> Yinon Ehrlich writes: >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >sys.hexversion, >see http://mail.python.org/pipermail/python-list/2009-June/185939.html Cool. Thanks. kynn From himanshu.garg at gmail.com Sat Nov 14 06:43:11 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Sat, 14 Nov 2009 17:13:11 +0530 Subject: Help with database planning In-Reply-To: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <6f82a7270911140343u4ae027d8s91475442f7bf8381@mail.gmail.com> 2009/11/14 Juliano : > Hello, everybody. > > I'm a linguist with practical skills on computers/programming. > > We've been working with an ontology at my department, and now I need > to create a GUI viewer for the flat file we have. > I tried to write an Ontology class which manages the data read and > parsed from the flat file, but it takes a relatively long time. > Besides, we have plans to set up a website for online display of said > ontology. So, I have been being pushed towards changing the basic plan > and build a DB so that data access will be faster and easier for both > the desktop GUI and the web app. Right now, I'm trying to work with > sqlite, since it can be used as a separate file for the GUI and as a > DB for Django (which may be the choice for the web interface). > > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. The problem > is that we have basically four fields that can be arranged in a tree- > like structure. Eg: > > Concept > ?|----- Slot > ?| ? ? ? ?`------ Facet > ?| ? ? ? ? ? ? ? ? ?`------ Filler > ?`----- Slot > ? ? ? ? ? `------ Facet > ? ? ? ? ? ? ? ? ? ? `------ Filler > ? ? ? ? ? ? ? ? ? ? `------ Filler > ? ?... > > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. > > > line_no concepts ? ? ? ?slots ? facets ?fillers > ------------------------------------------------------------------------------ > 00000 ? ABANDON DEFINITION ? ? ?VALUE ? "to leave or desert something or > someone" > 00001 ? ABANDON IS-A ? ?VALUE ? EXIT > 00002 ? ABANDON LEXE ? ?MAP-LEX "leave behind-V1" > 00003 ? ABANDON LEXE ? ?MAP-LEX abandon-V1 > (...) > 97420 ? ZULU ? ?DEFINITION ? ? ?VALUE ? "a language or dialect spoken in south > africa and others" > 97421 ? ZULU ? ?INSTANCE-OF ? ? VALUE ? OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ? ZULU ? ?LANGUAGE-OF ? ? INV ? ? LESOTHO > 97423 ? ZULU ? ?LANGUAGE-OF ? ? INV ? ? SOUTH-AFRICA > > > I tried to create index tables for concepts, slots, facets and > fillers, which gave me the following table: > > > line_no concepts ? ? ? ?slots ? facets ?fillers > ------------------------------------------------------------------------------ > 00000 ? cn_00000 ? ? ? ?sl_00048 ? ? ? ?fc_00007 ? ? ? ?fl_07349 > 00001 ? cn_00000 ? ? ? ?cn_02605 ? ? ? ?fc_00007 ? ? ? ?cn_01768 > 00002 ? cn_00000 ? ? ? ?sl_00121 ? ? ? ?fc_00002 ? ? ? ?fl_04329 > 00003 ? cn_00000 ? ? ? ?sl_00121 ? ? ? ?fc_00002 ? ? ? ?fl_15009 > (...) > 97420 ? cn_05429 ? ? ? ?sl_00048 ? ? ? ?fc_00007 ? ? ? ?fl_01340 > 97421 ? cn_05429 ? ? ? ?cn_02493 ? ? ? ?fc_00007 ? ? ? ?cn_03526 > 97422 ? cn_05429 ? ? ? ?cn_02750 ? ? ? ?fc_00001 ? ? ? ?cn_02816 > 97423 ? cn_05429 ? ? ? ?cn_02750 ? ? ? ?fc_00001 ? ? ? ?cn_04580 > > > (cn_XXXXX from concept index, sl_XXXXX from slot index, > fc_XXXXX from facet index, fl_XXXXX from filler index.) > > As you can see, only concepts and facets are populated by their own > type of data. > Whereas slots and fillers can be populated by their own types or by > concepts. > > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. > > I'm looking forward to a reply... > > Thank you very much, > Juliano If you have an ontology that doesn't run into GB's of data you could also consider this. Load it into an in memory data structure of your choice from the text file. Here are the arguments in favour :- 1) The structure doesn't lend itself nicely to tables. So a relational database may not be the best choice when you start traversing the data. Imagine writing a query to get the data and show it as a tree. 2) Changes to the ontology are infrequent so you don't use most of the ACID facilities the database offers. 3) cyc uses its own proprietory data format which is probably not a _relational_ database 4) With your own data structure you know where to fix if the performance is bad. The current poor performance could be due to some other problem which may not go away on its own on switching to db. 5) Keeping the data in a flat file has the advantage of making it easy to update and version control. Otherwise you need another program for editing it. I am no database expert so let's see if someone has a better table design suggestion. Thank You, ++imanshu From ken at seehart.com Sat Nov 14 07:15:06 2009 From: ken at seehart.com (Ken Seehart) Date: Sat, 14 Nov 2009 04:15:06 -0800 Subject: Help with database planning In-Reply-To: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <4AFE9F4A.8020509@seehart.com> Good idea to use Django. I've just started using it and I really like it. However, I should give you a heads-up: You will probably want to use a Django migration tool (I'm using South) because the alternative is basically to rebuild your database each time your model changes. Unfortunately, South can sometimes get confused when using anything less sophisticated than PostgreSQL (I switched from MySQL to PostgreSQL for this reason). I don't know if South or the other various Django migration tools work with MySQL. Applying the DRY (don't repeat yourself), you might even consider running the same code as a local web server instead of implementing a separate desktop version. But it is just a suggestion; there are various reasons why you might not want to do that. On to the DB design question... One approach would be to make a Generic class that can represent a concept, slot, or filler, which would have a type field to identify which of these to use. class Concept(models.Model): ... class Slot(models.Model): ... class Filler(models.Model): ... class Facet(models.Model): ... class Generic(models.Model): TYPE_CHOICES = ( (u'c', u'concept'), (u's', u'slot'), (u'f', u'filler'), } # Only one of the following is used. The other two are blank. concept = models.ForeignKey(Concept) slot = models.ForeignKey(Slot) filler = models.ForeignKey(Filler) class ConceptDef(models.Model): concept = models.ForeignKey(Concept) slot = models.ForeignKey(Generic) facet = models.ForeignKey(Facet) filler = models.ForeignKey(Generic) Juliano wrote: > Hello, everybody. > > I'm a linguist with practical skills on computers/programming. > > We've been working with an ontology at my department, and now I need > to create a GUI viewer for the flat file we have. > I tried to write an Ontology class which manages the data read and > parsed from the flat file, but it takes a relatively long time. > Besides, we have plans to set up a website for online display of said > ontology. So, I have been being pushed towards changing the basic plan > and build a DB so that data access will be faster and easier for both > the desktop GUI and the web app. Right now, I'm trying to work with > sqlite, since it can be used as a separate file for the GUI and as a > DB for Django (which may be the choice for the web interface). > > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. The problem > is that we have basically four fields that can be arranged in a tree- > like structure. Eg: > > Concept > |----- Slot > | `------ Facet > | `------ Filler > `----- Slot > `------ Facet > `------ Filler > `------ Filler > ... > > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. > > > line_no concepts slots facets fillers > ------------------------------------------------------------------------------ > 00000 ABANDON DEFINITION VALUE "to leave or desert something or > someone" > 00001 ABANDON IS-A VALUE EXIT > 00002 ABANDON LEXE MAP-LEX "leave behind-V1" > 00003 ABANDON LEXE MAP-LEX abandon-V1 > (...) > 97420 ZULU DEFINITION VALUE "a language or dialect spoken in south > africa and others" > 97421 ZULU INSTANCE-OF VALUE OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ZULU LANGUAGE-OF INV LESOTHO > 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA > > > I tried to create index tables for concepts, slots, facets and > fillers, which gave me the following table: > > > line_no concepts slots facets fillers > ------------------------------------------------------------------------------ > 00000 cn_00000 sl_00048 fc_00007 fl_07349 > 00001 cn_00000 cn_02605 fc_00007 cn_01768 > 00002 cn_00000 sl_00121 fc_00002 fl_04329 > 00003 cn_00000 sl_00121 fc_00002 fl_15009 > (...) > 97420 cn_05429 sl_00048 fc_00007 fl_01340 > 97421 cn_05429 cn_02493 fc_00007 cn_03526 > 97422 cn_05429 cn_02750 fc_00001 cn_02816 > 97423 cn_05429 cn_02750 fc_00001 cn_04580 > > > (cn_XXXXX from concept index, sl_XXXXX from slot index, > fc_XXXXX from facet index, fl_XXXXX from filler index.) > > As you can see, only concepts and facets are populated by their own > type of data. > Whereas slots and fillers can be populated by their own types or by > concepts. > > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. > > I'm looking forward to a reply... > > Thank you very much, > Juliano > From ken at seehart.com Sat Nov 14 07:28:02 2009 From: ken at seehart.com (Ken Seehart) Date: Sat, 14 Nov 2009 04:28:02 -0800 Subject: Help with database planning In-Reply-To: <4AFE9F4A.8020509@seehart.com> References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> <4AFE9F4A.8020509@seehart.com> Message-ID: <4AFEA252.3090400@seehart.com> Oops, forgot the blank arg. Anyway, this is of course untested code... # Only one of the following is used. The other two are blank. concept = models.ForeignKey(Concept, blank=True) slot = models.ForeignKey(Slot, blank=True) filler = models.ForeignKey(Filler, blank=True) Ken Seehart wrote: > Good idea to use Django. I've just started using it and I really like > it. However, I should give you a heads-up: You will probably want to > use a Django migration tool (I'm using South) because the alternative > is basically to rebuild your database each time your model changes. > Unfortunately, South can sometimes get confused when using anything > less sophisticated than PostgreSQL (I switched from MySQL to > PostgreSQL for this reason). I don't know if South or the other > various Django migration tools work with MySQL. > > Applying the DRY (don't repeat yourself), you might even consider > running the same code as a local web server instead of implementing a > separate desktop version. But it is just a suggestion; there are > various reasons why you might not want to do that. > > On to the DB design question... > > One approach would be to make a Generic class that can represent a > concept, slot, or filler, which would have a type field to identify > which of these to use. > > class Concept(models.Model): > ... > > class Slot(models.Model): > ... > > class Filler(models.Model): > ... > > class Facet(models.Model): > ... > > class Generic(models.Model): > TYPE_CHOICES = ( > (u'c', u'concept'), > (u's', u'slot'), > (u'f', u'filler'), > } > > # Only one of the following is used. The other two are blank. > concept = models.ForeignKey(Concept) > slot = models.ForeignKey(Slot) > filler = models.ForeignKey(Filler) > > class ConceptDef(models.Model): > concept = models.ForeignKey(Concept) > slot = models.ForeignKey(Generic) > facet = models.ForeignKey(Facet) > filler = models.ForeignKey(Generic) > > Juliano wrote: >> Hello, everybody. >> >> I'm a linguist with practical skills on computers/programming. >> >> We've been working with an ontology at my department, and now I need >> to create a GUI viewer for the flat file we have. >> I tried to write an Ontology class which manages the data read and >> parsed from the flat file, but it takes a relatively long time. >> Besides, we have plans to set up a website for online display of said >> ontology. So, I have been being pushed towards changing the basic plan >> and build a DB so that data access will be faster and easier for both >> the desktop GUI and the web app. Right now, I'm trying to work with >> sqlite, since it can be used as a separate file for the GUI and as a >> DB for Django (which may be the choice for the web interface). >> >> I have been redaing some books on DBs but I kind of get stuck when it >> comes to the normalization and the planning of the tables. The problem >> is that we have basically four fields that can be arranged in a tree- >> like structure. Eg: >> >> Concept >> |----- Slot >> | `------ Facet >> | `------ Filler >> `----- Slot >> `------ Facet >> `------ Filler >> `------ Filler >> ... >> >> So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has >> ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. >> Besides, some *slots* and *fillers* are themselves *concepts*, >> creating a sort of recursive reference. >> >> >> line_no concepts slots facets fillers >> ------------------------------------------------------------------------------ >> >> 00000 ABANDON DEFINITION VALUE "to leave or desert >> something or >> someone" >> 00001 ABANDON IS-A VALUE EXIT >> 00002 ABANDON LEXE MAP-LEX "leave behind-V1" >> 00003 ABANDON LEXE MAP-LEX abandon-V1 >> (...) >> 97420 ZULU DEFINITION VALUE "a language or dialect spoken >> in south >> africa and others" >> 97421 ZULU INSTANCE-OF VALUE >> OTHER-NIGER-KORDOFANIAN-LANGUAGE >> 97422 ZULU LANGUAGE-OF INV LESOTHO >> 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA >> >> >> I tried to create index tables for concepts, slots, facets and >> fillers, which gave me the following table: >> >> >> line_no concepts slots facets fillers >> ------------------------------------------------------------------------------ >> >> 00000 cn_00000 sl_00048 fc_00007 fl_07349 >> 00001 cn_00000 cn_02605 fc_00007 cn_01768 >> 00002 cn_00000 sl_00121 fc_00002 fl_04329 >> 00003 cn_00000 sl_00121 fc_00002 fl_15009 >> (...) >> 97420 cn_05429 sl_00048 fc_00007 fl_01340 >> 97421 cn_05429 cn_02493 fc_00007 cn_03526 >> 97422 cn_05429 cn_02750 fc_00001 cn_02816 >> 97423 cn_05429 cn_02750 fc_00001 cn_04580 >> >> >> (cn_XXXXX from concept index, sl_XXXXX from slot index, >> fc_XXXXX from facet index, fl_XXXXX from filler index.) >> >> As you can see, only concepts and facets are populated by their own >> type of data. >> Whereas slots and fillers can be populated by their own types or by >> concepts. >> >> What would be a good way to create tables for this situation? >> In fact, this is the first time I've ever tried to create a DB, so I'm >> completely lost. >> >> I'm looking forward to a reply... >> >> Thank you very much, >> Juliano >> > From sturlamolden at yahoo.no Sat Nov 14 07:29:55 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 04:29:55 -0800 (PST) Subject: Python & Go References: Message-ID: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> On 12 Nov, 01:53, kj wrote: > I'm just learning about Google's latest: the GO (Go?) language. > (e.g.http://golang.orgorhttp://www.youtube.com/watch?v=rKnDgT73v8s). > There are some distinctly Pythonoid features to the syntax, such > as "import this_or_that", the absence of parentheses at the top of > flow control constructs, and quite a few statements without a > trailing semicolon. ?Then again, there's a lot that looks distinctly > un-Pythonlike, such as the curly brackets all over the place. ?And > among the un-Pythonlike stuff there's a lot that looks like nothing > else that I've ever seen... It seems that the argument for using Go over Python is speed. They achieve that by static typing. According to Debian benchmarks, LuaJIT delivers the same performance as Google cleaims for Go (about 20% loss compared to C), and that is from a completely dynamic language. (Lua is Python's sibling.) It makes me wonder what Python would be like on LuaJIT. Perhaps we should make a Python frontend for the Lua VM and try? It would be fun :-) Anyway, the impressive performance of LuaJIT on Debian benchmarks just tells med that static typing a la Go is not needed for fast execution of CPU-bound code. And looking at Go, I cannot understand why Google prefer this over e.g. Lua. From sturlamolden at yahoo.no Sat Nov 14 07:39:20 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 04:39:20 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> On 9 Nov, 05:49, Antony wrote: > ? ?I just wanted to know which module is best for developing designing > interface in python . I personally feel the wxPython support in the 3.1 beta of wxFormBuilder makes the choise rather simple. It generates a Python file with classes for all WYSIWYG GUI forms/windows/dialogs. Then in our Python code, we just import and inherit the form, and implement the event handlers. It can't be done easier. GUI programming with Python is now comparable to programming with VB, Delphi or C#. I am using it for all my projects now. It just feels right. From martin at v.loewis.de Sat Nov 14 08:16:45 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 14 Nov 2009 14:16:45 +0100 Subject: the unicode saga continues... In-Reply-To: References: Message-ID: <4AFEADBD.90506@v.loewis.de> > Can anybody clue me in to what's going on here? It's as Mark says: the console encoding is cp437 on your system, cp1252. Windows has *two* default code pages at any point in time: the OEM code page, and the ANSI code page. Either one depends on the Windows release (Western, Japanese, etc.), and can be set by the administrator. The OEM code page is primarily used for the console (and then also as the encoding on the FAT filesystem); the ANSI code page is used in all other places (that don't use Unicode APIs). In addition, the console code page may deviate from the OEM code page, if you run chcp.exe. Regards, Martin From ben+python at benfinney.id.au Sat Nov 14 08:23:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 00:23:48 +1100 Subject: Help with database planning References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: <87my2ps0ij.fsf@benfinney.id.au> Juliano writes: > We've been working with an ontology at my department [?] I have been > being pushed towards changing the basic plan and build a DB so that > data access will be faster and easier for both the desktop GUI and the > web app. Right now, I'm trying to work with sqlite, since it can be > used as a separate file for the GUI and as a DB for Django (which may > be the choice for the web interface). You're also working with a relational database system, which will make it relatively easy to migrate your database structure to a different relational database system if that proves necessary. > I have been redaing some books on DBs but I kind of get stuck when it > comes to the normalization and the planning of the tables. No shame in that; it's somewhat counter-intuitive, though it's an essential topic when working with databases. Try the Wikipedia article . > The problem is that we have basically four fields that can be arranged > in a tree- like structure. Tree-like structures don't fit into table-like relations very well; but it's not hopeless. > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. Recursive references, on the other hand, are deadly to storing data sanely in a relational database: while recursion is algorithmically elegant, it makes for hideously slow operations querying, and especially modifying, the database. The focus, then, should be on teasing out a non-recursive, declarative schema for the data. This is a well-known problem, with many possible solutions. Several popular approaches (each with different trade-offs) are ?Adjacency list? , ?Materialized path?, and ?Nested sets?. Use those terms in database-savvy circles and you'll get lots of explanations. > What would be a good way to create tables for this situation? > In fact, this is the first time I've ever tried to create a DB, so I'm > completely lost. This topic is rather orthogonal to Python. You would do well to seek further guidance from a Usenet group such as . Good fortune, and persist; you're going into databases off the deep end with a problem domain like this :-) -- \ ?I distrust those people who know so well what God wants them | `\ to do to their fellows, because it always coincides with their | _o__) own desires.? ?Susan Brownell Anthony, 1896 | Ben Finney From lusvehla at gmail.com Sat Nov 14 08:24:26 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 05:24:26 -0800 (PST) Subject: COM Server wirh MS Excel Message-ID: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Hi, I would lake use win32com with Excel. I tried to use python COM example from 'The Quick Python Book' on page 250 but without success. The COM Module is successfully registetred but MS Excel reported this message http://home.tiscali.cz/fotogalerie7/Error80004005.gif I tried omitted following statement (how counselling on http://manning-sandbox.com/thread.jspa?messageID=7263): #_reg_class_spec_ = "ar_com_servers.DemoServer and new registration but not successful :-( Pleas help me From x7-g5W_rt at earthlink.net Sat Nov 14 08:28:30 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Sat, 14 Nov 2009 05:28:30 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: On Nov 13, 5:29?pm, kj wrote: [...] > Or it could be set up so that at least n > 1 "delete" votes and no > "keep" votes are required to get something nixed. ?Etc. > > This seems simpler than all-out moderation. > > ("all-out moderation"? now, there's an oxymoron for ya!) > How about using a "rank this post" feature? Anybody could rank a post as spam, and a sufficiently large number of negatives would quickly draw the attention of someone with the power to kill the message. I suppose even this is subject to abuse, allowing harassment of a legitimate poster., but my guess is that the votes against counterfeit Nike shoes, etc., would outnumber the most energetic "vote troll." Gil From chris at simplistix.co.uk Sat Nov 14 08:34:42 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 13:34:42 +0000 Subject: COM Server wirh MS Excel In-Reply-To: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: <4AFEB1F2.5080808@simplistix.co.uk> Cannonbiker wrote: > Hi, > I would lake use win32com with Excel. I tried to use python COM > example from 'The Quick Python Book' on page 250 but without success. I suggest you have a good read of http://www.python-excel.org. You may well find you don't need to use COM at all...# Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From lusvehla at gmail.com Sat Nov 14 08:44:34 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 05:44:34 -0800 (PST) Subject: COM Server wirh MS Excel References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: On 14 lis, 14:24, Cannonbiker wrote: The ServerCOM file is here http://home.tiscali.cz/fotogalerie7/ServerCOM.py From urbangabo at gmail.com Sat Nov 14 08:45:48 2009 From: urbangabo at gmail.com (Gabor Urban) Date: Sat, 14 Nov 2009 14:45:48 +0100 Subject: More Python versions on an XP machine Message-ID: Hi guys, this a very MS specific question. I do use a rather old Python version, because we have a couple of applications written for that. Porting them to a newer Python is not allowed by the bosses. Now we will start a new project with latest stable Python. Can I have them both on my computer, and how should I do that. Thanks, PS: This is my computer at the office.... :-) -- Linux: Choice of a GNU Generation From alfps at start.no Sat Nov 14 08:52:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 14 Nov 2009 14:52:31 +0100 Subject: A "terminators' club" for clp In-Reply-To: References: Message-ID: * gil_johnson: > On Nov 13, 5:29 pm, kj wrote: > [...] >> Or it could be set up so that at least n > 1 "delete" votes and no >> "keep" votes are required to get something nixed. Etc. >> >> This seems simpler than all-out moderation. >> >> ("all-out moderation"? now, there's an oxymoron for ya!) >> > > How about using a "rank this post" feature? Anybody could rank a post > as spam, and a sufficiently large number of negatives would quickly > draw the attention of someone with the power to kill the message. I > suppose even this is subject to abuse, allowing harassment of a > legitimate poster., but my guess is that the votes against counterfeit > Nike shoes, etc., would outnumber the most energetic "vote troll." The problem with moderation isn't getting rid of spam and trolls etc., but turnaround time. In some cases trivial questions cause a flood of essentially identical trivial responses to pile up before the mods can get at them. And then there's the dilemma of whether to approve all that or make judgements based on /content/. The latter leads to a very slippery slope, you really don't want the mods to do that, plus that in some cases what might appear trivial leads to very fruitful discussion of not-so-trivial aspects. But it's not either/or: it's possible to have both an unmoderated group (fast turnaround, much spam, some heated discussion) and a corresponding moderated group (slow turnaround, no spam, far less heat, presence of more experts), e.g. as [comp.lang.c++] and [oomp.lang.c++.moderated]. :-) Cheers & hth., - Alf From deets at nospam.web.de Sat Nov 14 08:59:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 14:59:07 +0100 Subject: More Python versions on an XP machine In-Reply-To: References: Message-ID: <7m7rdbF3g7k6dU1@mid.uni-berlin.de> Gabor Urban schrieb: > Hi guys, > > this a very MS specific question. I do use a rather old Python > version, because we have a couple of applications written for that. > Porting them to a newer Python is not allowed by the bosses. Now we > will start a new project with latest stable Python. Can I have them > both on my computer, and how should I do that. As numerous posts here have indicated over the past years, and even this week - and to say it with a somewhate prematurely awarded Nobel Prize Winner: YES, YOU CAN! Diez From metawilm at gmail.com Sat Nov 14 09:13:47 2009 From: metawilm at gmail.com (Willem Broekema) Date: Sat, 14 Nov 2009 06:13:47 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: On Nov 14, 8:55 am, Vincent Manis wrote: > On 2009-11-13, at 23:20, Robert Brown wrote, quoting me: > > Please look atCLPython. [...] > Ah, that does explain it. I bet you didn't even look at it. FWIW, I'm the author of CLPython. > CLOS is most definitely the wrong vehicle for implementing > Python method dispatch. CLOS is focused around generic functions that themselves > do method dispatch, and do so in a way that is different from Python's. If I were > building a Python implementation in CL, I would definitely NOT use CLOS, but > do my own dispatch using funcall (the CL equivalent of the now-vanished Python > function apply). CLOS is way more than method dispatch, it's an infrastructure for classes, metaclasses, slots, method combinations. And within method dispatch there are lots of opportunities to customize the behaviour. Ignoring all that functinality when implementing an object-oriented language, and using "dispatch using funcall" whatever that means, just sounds ridiculous. (And funcall != apply.) > > Method lookup is just the tip if the iceburg. How about comparison? Here are > > some comments fromCLPython'simplementation of compare. There's a lot going > > on. It's complex and SLOW. Right, although by special-casing the most common argument types you can save most of that lookup. > Re comparison. Python 3 has cleaned comparison up a fair bit. In particular, you > can no longer compare objects of different types using default comparisons. > However, it could well be that there are nasty little crannies of inefficiency > there, they could be the subject of PEPs after the moratorium is over. It might have gotten a bit better, but the central message still stands: Python has made design choices that make efficient compilation hard. > OK, let me try this again. My assertion is that with some combination of JITting, > reorganization of the Python runtime, and optional static declarations, Python > can be made acceptably fast, That does not contradict that, had other language design choices been made, it could be much easier to get better performance. Python may in general be about as dynamic as Common Lisp from a _user_ perspective, but from an implementator's point of view Python is harder to make it run efficiently. Here are some examples of design choices in Common Lisp that help it perform very well; while in Python there is more freedom at the cost of performance: - Lisp hashtables, arrays, numbers, and strings are not subclassable. The specialized operations on them, like function aref for array index referencing, don't invoke arbitrary user-level code, and also not lookup of magic methods. - Certain Lisp sequence objects, like lists and arrays, can easily be allocated on the stack; - Lisp allows type declarations, like for variables, array types, function arguments and return values. - Even if Python had type declarations, it is possible to define a subclass that redefines semantics. E.g. it's possible to subclass 'int' and redefine what '+' means, making a declaration that "x is of type int" not as valuable as in Lisp. - A recursive function defined at module level, can not assume that its name refers to itself. - Every function can be called using keyword arguments or positional arguments. E.g. with the definition "def f(x,y): ..", some possible calls are: f(1), f(1,2), f(x=1, y=2), f(1,y=2) so every function must be prepared to do keyword argument processing. (This can be considered a lack of separation between internal details and external interface.) - Every function call could potentially be a call to locals() (e.g. f=locals; f()), which means every function that contains a function call must store the value of all locals, even of "dead" variables. - Built-in functions can be shadowed. - The potential fields of a Python object are often not defined, as arbitrary attributes can be set. Accessors for fields generally generally have to retrieve the value from a dict. - When limiting the potential fields of a class instance using __slots__, subclasses may override __slots__ thus this is hardly limiting. - Python attribute lookup and comparison (as shown in a previous mail) are examples of hairy behaviour that often mean the lookup of several (!) __magic__ methods and could invoke arbitrary user code. (Lisp in particular offers "structures" whose definition is fixed, that inline all accessors, for maximum efficiency.) This is just to show how language design leads to efficieny characteristics. That there is a need for projects like NumPy and Cython, follows in my eyes from Python being too dynamic for its own good, with no way to tame it. In Common Lisp there would be less need to go to C for speed, because of user-supplied type declarations and compiler-based type inferencing. It has been said that CLPython is a very good counterargument for "just write a Python to Lisp compiler to make things fast", and even I as its developer agree. Lisp offers lots of readily available optimization opportunities, but Python simply doesn't. I remember reading some years ago about a Smalltalk compiler guru who said he would come up with a ridiculously fast Python implementation based on all the message sending optimizations he knew. It does not surprise me that we've never heard from him yet. - Willem From lusvehla at gmail.com Sat Nov 14 09:15:17 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 06:15:17 -0800 (PST) Subject: COM Server wirh MS Excel References: <72dc6a43-862a-4ff3-b8e5-3034c8fa114e@s15g2000yqs.googlegroups.com> Message-ID: <82f867e7-4808-46f0-861e-e3814cc20db7@n35g2000yqm.googlegroups.com> On 14 lis, 14:34, Chris Withers wrote: > Cannonbiker wrote: > > Hi, > > I would lake use win32com with Excel. I tried to use python COM > > example from 'The Quick Python Book' on page 250 but without success. > > I suggest you have a good read ofhttp://www.python-excel.org. > > You may well find you don't need to use COM at all...# > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk Thanks but this isn't solution for me. I need call Python functions from Excel and receive result back in Excel... From news at schwertberger.de Sat Nov 14 09:35:35 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 14 Nov 2009 15:35:35 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> Message-ID: <7m7thpF3g6c3gU1@mid.individual.net> sturlamolden schrieb: > I personally feel the wxPython support in the 3.1 beta of > wxFormBuilder makes the choise rather simple. It generates a Python > file with classes for all WYSIWYG GUI forms/windows/dialogs. Then in > our Python code, we just import and inherit the form, and implement > the event handlers. It can't be done easier. GUI programming with > Python is now comparable to programming with VB, Delphi or C#. I am > using it for all my projects now. It just feels right. Yes, wxFormBuilder looks very promising. But I don't think that 3.1 in it's current state it can be recommended for general use already. I just tried the latest version (from August) and it does not even generate correct Python code: self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 ) m_toolBar1.AddControl( m_button1 ) (i.e. "self." is missing) Regards, Dietmar From doomster at knuut.de Sat Nov 14 10:13:08 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sat, 14 Nov 2009 16:13:08 +0100 Subject: The ol' [[]] * 500 bug... References: <7m78oaF3fgtcfU1@mid.uni-berlin.de> Message-ID: <7m7vo6F3glkboU1@mid.uni-berlin.de> Diez B. Roggisch wrote: > kj schrieb: >> lol = [[] for _ in xrange(500)] > > If you call that hideous, I suggest you perform the same exercise in > Java or C++ - and then come back to python and relax.... I might be missing something that's not explicitly mentioned here, but I'd say that all non-associative containers in C++ have a resize() method, some even taking an initial size in their constructor. That said, [[]]*500 is IMHO more readable. Uli From davea at ieee.org Sat Nov 14 10:36:21 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 14 Nov 2009 10:36:21 -0500 Subject: run all scripts in sub-directory as subroutines? In-Reply-To: <%jjLm.16238$We2.1157@newsfe09.iad> References: <%jjLm.16238$We2.1157@newsfe09.iad> Message-ID: <4AFECE75.9000600@ieee.org> Tobiah wrote: >> This works fine, but in the sub-modules the sys.path appropriately >> returns the same as from the parent, I want them to know their own file >> names. How?? I can pass it to them, but wondered if there is a more >> self-sufficient way for a module to know from where it was invoked. >> > > I like the idea of passing the information to the module. > Probably by setting a global variable into it. > > > > As ryles pointed out in this thread, over a month ago, that's already there. The system loader creates a global variable __file__ with the full path to the module. So any module can see exactly where it was loaded from. From chris at simplistix.co.uk Sat Nov 14 10:44:55 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 15:44:55 +0000 Subject: feedback on function introspection in argparse In-Reply-To: References: Message-ID: <4AFED077.5040902@simplistix.co.uk> Yuv wrote: > On Nov 8, 1:33 am, Carl Banks wrote: >> Is the docstring expected to be formatted according to some >> convention? > > We tried to comply to PEP 257 and we're open to suggestions on this. I'd suggest at the very least supporting Sphinx docstrings that have the parameters in them... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From roy at panix.com Sat Nov 14 10:48:39 2009 From: roy at panix.com (Roy Smith) Date: Sat, 14 Nov 2009 07:48:39 -0800 (PST) Subject: Anything better than shutil? Message-ID: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> I'm converting some old bash scripts to python. There's lots of places where I'm doing things like "rm $source_dir/*.conf". The best way I can see to convert this into python is: configs = glob.glob(os.path.join(source_dir, '*.conf')) for conf_file in configs: shutil.copy(conf_file, conf_dir) which is pretty clunky. The old bash script ran under cygwin on windows, and the cygwin layer handled the slash-backslash business for me. Is there a better way to do what I'm doing? I don't want to use any of the popen() variants to call a real shell. The problem I'm trying to solve is that fork/exec is painfully slow under cygwin, so that would defeat the whole purpose. The idea interface I see would be one like: shutil.copy([source_dir, '*.conf'], conf_dir) the idea is that if the first argument is a list (or maybe any iterable other than a string?), it would automatically get run through os.path.join(). And, the result would always get passed through glob (), just like a normal shell would. Does anything like this exist? I'm currently using python 2.5.1. It's possible, but moderately painful, to move to a newer version. From chris at simplistix.co.uk Sat Nov 14 10:54:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Nov 2009 15:54:51 +0000 Subject: Anything better than shutil? In-Reply-To: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> References: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> Message-ID: <4AFED2CB.2050106@simplistix.co.uk> Roy Smith wrote: > The idea interface I see would be one like: > > shutil.copy([source_dir, '*.conf'], conf_dir) > > the idea is that if the first argument is a list (or maybe any > iterable other than a string?), it would automatically get run through > os.path.join(). And, the result would always get passed through glob > (), just like a normal shell would. Does anything like this exist? Why don't you wrap up your earlier code: > configs = glob.glob(os.path.join(source_dir, '*.conf')) > for conf_file in configs: > shutil.copy(conf_file, conf_dir) ...in a module with the exact interface you're after? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From luca at keul.it Sat Nov 14 11:02:29 2009 From: luca at keul.it (Luca Fabbri) Date: Sat, 14 Nov 2009 17:02:29 +0100 Subject: How to know if a file is a text file Message-ID: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Hi all. I'm looking for a way to be able to load a generic file from the system and understand if he is plain text. The mimetype module has some nice methods, but for example it's not working for file without extension. Any suggestion? -- -- luca From joost at h-labahn.de Sat Nov 14 11:04:32 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 08:04:32 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects Message-ID: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> Hello, this page http://docs.python.org/3.1/c-api/typeobj.html has a bad error: " PyTypeObject* PyObject.ob_type This is the type?s type, in other words its metatype. It is initialized by the argument to the PyObject_HEAD_INIT macro, and its value should normally be &PyType_Type. However, for dynamically loadable extension modules that must be usable on Windows (at least), the compiler complains that this is not a valid initializer. Therefore, the convention is to pass NULL to the PyObject_HEAD_INIT macro and to initialize this field explicitly at the start of the module?s initialization function, before doing anything else. This is typically done like this: Foo_Type.ob_type = &PyType_Type; " This cannot work, because Foo_Type is no PyObject but a PyVarObject (independent of the use of PyVarObject_HEAD_INIT or PyObject_HEAD_INIT). The code line would work so: ((PyObject *)&Foo_Type)->ob_type = &PyType_Type But in the Tutorial for Extensions and Embedding we are advised as follows: " This is so important that we?re going to pick the top of it apart still further: PyVarObject_HEAD_INIT(NULL, 0) This line is a bit of a wart; what we?d like to write is: PyVarObject_HEAD_INIT(&PyType_Type, 0) as the type of a type object is ?type?, but this isn?t strictly conforming C and some compilers complain. Fortunately, this member will be filled in for us by PyType_Ready(). " What now ? Another problem, which might be a documentation bug, is the last sentence here: " destructor PyTypeObject.tp_dealloc A pointer to the instance destructor function. This function must be defined unless the type guarantees that its instances will never be deallocated (as is the case for the singletons None and Ellipsis). The destructor function is called by the Py_DECREF() and Py_XDECREF() macros when the new reference count is zero. At this point, the instance is still in existence, but there are no references to it. The destructor function should free all references which the instance owns, free all memory buffers owned by the instance (using the freeing function corresponding to the allocation function used to allocate the buffer), and finally (as its last action) call the type?s tp_free function. If the type is not subtypable (doesn?t have the Py_TPFLAGS_BASETYPE flag bit set), it is permissible to call the object deallocator directly instead of via tp_free. " What ? Where do we "call" these methods ? Primarily we write them down to get members of the Foo_Type struct and our question is where. Shall this sentence mean, that we write the function, we'd normally use for tp_dealloc und which behaves like it, to the place of tp_free ? I've run into terrible trouble with extension classes, which have neither members nor init. They work (and i am quite happy about that) but finding out, that tp_dictoffset had to be set (for what i wanted) took more than a day of searching - including ?ecture of typeobject.c and object.c - and i cannot derive from them. class(my_extension_class): ... doesn't crash, but results in objects, which have the type my_extension_class, what means, that they do not call their __init__. In certain circumstances a correct tp_free seems to be a premise for inheritance, thus i'd very like to understand the quoted passage. Joost From davea at ieee.org Sat Nov 14 11:05:44 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 14 Nov 2009 11:05:44 -0500 Subject: __import__ returns module without it's attributes? In-Reply-To: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> References: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> Message-ID: <4AFED558.60703@ieee.org> Zac Burns wrote: > I've overloaded __import__ to modify modules after they are > imported... but running dir(module) on the result only returns > __builtins__, __doc__, __file__, > __name__, __package__, and __path__. > > Why is this? More importantly, where can I hook in that would allow me > to see the contents of the module? > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > > I'm probably not the one to give you the actual answer (at least not in the next couple of days), but I could help you ask a better question. Provide a simple example of your code, and what it does. Describe the python version and OS platform you're running it on. And detail the contents of any extra files or environment values that are needed to reproduce the problem. (You may find http://www.catb.org/~esr/faqs/smart-questions.html useful) BTW, I don't know of any method __import__(), only a builtin function, so I don't see how you can overload it. But your example should make it clear what you really meant. HTH DaveA From paul.nospam at rudin.co.uk Sat Nov 14 11:29:55 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 16:29:55 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> Message-ID: <87iqddhxx8.fsf@rudin.co.uk> Ben Finney writes: > Paul Rudin writes: > >> I'm experimenting with the daemon module >> and upstart >> . > > First: Thank you for using ?python-daemon?; it's getting more widespread > use all the time, which is really helping to find all the quirks of API > and implementation. (And good for my ego at the same time.) > > Thanks for writing it. > There's something I don't understand, which may be more of an upstart >> issue than a python issue, but I thought I'd start by posting here. > > I'm unfamiliar with ?upstart?, I hope others with more experience can > offer more insight. > On Karmic it seems to be the standard way for starting and stopping system processes. >> Here's a test script: > [?] > > The program looks fine to me. What happens if you run the program, > without getting ?upstart? involved? > As for as I can tell everything is ok invoking the script from the command line. >> and here's a testdaemon.conf upstart configuration: >> >> description "test daemon" >> expect daemon >> chdir /tmp >> exec /tmp/testdaemon.py >> >> If I do "sudo start testdaemon" I see the "testdaemon.py" process >> starting, and the file '/tmp/test.txt' is being written to every 5 >> seconds, so everything has kicked off. > > Good to know. > >> The thing I don't understand is why start does not return. I guess it >> doesn't think that the process and properly started and daemonized >> itself? Quite possibly it's just that I don't understand this stuff >> well... > > As I say, I'm completely unfamiliar with the details of ?upstart?. Can > you point me to whatever you used to understand it? The man pages on Karmic - "man start" etc. and the documentation on the upstart website: - check the getting started page and the wiki. Also some blog pages by its author: From joost at h-labahn.de Sat Nov 14 11:33:09 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 08:33:09 -0800 (PST) Subject: More Python versions on an XP machine References: Message-ID: <09651910-e61b-4ae1-8ac8-84bd83b8f06b@v30g2000yqm.googlegroups.com> Hi, there are several ways to do that besides starting python scripts with a double-click on a desktop icon (that can only work with the one and only python version of the registry). One is to start the new python version directly from a "DosBox". You could copy python.exe or pythonw.exe from the new version directly into the directory, where your python script is - both are only some kB large - and then execute "python your_script" in the cmd.exe. After some "cd"s to the directory of your script. Besides - it is no bad idea to have some copies of the cmd.exe at several places of your file system - the correct run of cmd.exe is not depending on its place in C:\Windows\system32. It also runs from external disks. This is, how i do that, not optimal probably, but easy to understand. Joost From tartley at tartley.com Sat Nov 14 11:51:36 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 14 Nov 2009 08:51:36 -0800 (PST) Subject: bootstrapping on machines without Python References: Message-ID: On Nov 13, 1:57?pm, Tim Golden wrote: > Jonathan Hartley wrote: > > While examining py2exe et al of late, my thoughts keep returning to > > the idea of writing, in C or similar, a compiled stand-alone > > executable 'bootstrapper', which: > > 1) downloads and install a Python interpreter if none exists > > 2) runs the application's Python source code using this interpreter. > > Thinking aloud about what you're describing here... Assuming Windows, > as your starting point is py2exe and I imagine that most Unix-like > boxes already have Python on them. > > Step 1: The user downloads a tiny myapp.exe which is basically a zip of the > myapp package / files plus an .exe header which will... > > Step 2a: ... download a minimised? (ie custom-built) Python interpreter > and stdlib bundle which is just enough to run the app. Or... > > Step 2b: ... download and install the official python.org Windows > installer for version x.y identified as the highest known to run > this app if... > > Step 2bi) ... that version of the interpreter isn't already installed > and registered on that machine (at least: for that user). > > My step 2a seems to be little better than a bundled py2exe, so I can > only assume you mean Step 2b, especially given your comment below > about ending up with an installation of Python where one wasn't > before. This, though, seems fraught with accusations of backdoor > installations etc. > > Have I misunderstood you? For the Record, I'm entirely in favour of moves > to make Python use on Windows more seamless, attractive, consistent, > etc. I was going to comment positively on your recent PyChooser widget > and to plug a similar but unpublished one of my own. But I'm not sure > if this particular proposal has enough wings to make it fly. > > TJG Hi Tim. Thanks for that. Yes, you have understood pretty much perfectly. I was envisaging something like 2b. I'm very much enamored of creating cross-platform apps, but I'm focused on deployment on Windows first, because this is where most users are, and also where the problem seems to need the most work. Your input is very much appreciated. It may be that you are right that I haven't thought this through clearly enough. Incidentally, I'd love to see your approach of dealing with the problem that pychoose addresses - Since creating it, I'm gripped with paranoia that it is failing to take account of lots of things which will trip me up later (or worse- trip other people up too, if anyone uses it) From michele.simionato at gmail.com Sat Nov 14 11:54:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 08:54:39 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <149ddcc2-ffee-4363-8123-fbb516574a06@m16g2000yqc.googlegroups.com> On Nov 14, 12:26?pm, kj wrote: > > The two goals of replacing C with "something more modern" and at > the same time have a "nearly zero learning curve" seem to me mutually > negating. ?The closer to zero the learning curve is, the closer to > C/C++, and therefore the less modern, that language will be. Not at all. A language with a small learning curve should be as far as possible for C++! Go is in many ways simpler than C (no header files, a simpler compilation process, no pointer arithmetic, no ternary operator, no while loop, in a sense no threads, etc) and it has an object orientation simpler than most languages; actually it looks even simpler than Python in many respects (no properties, no decorators, no metaclasses, a much simpler version of inheritance ...). It has static typing that makes things a bit more complicated, but also safer in same respect. It has also reflection and the ability to do a lot of things at runtime. If people starts writing libraries it has the potential to cover both C and Python niches at the same time! From paul.nospam at rudin.co.uk Sat Nov 14 11:56:47 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 16:56:47 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> <87iqddhxx8.fsf@rudin.co.uk> Message-ID: <87bpj5hwog.fsf@rudin.co.uk> Paul Rudin writes: > Ben Finney writes: > >> Paul Rudin writes: >>> description "test daemon" >>> expect daemon >>> chdir /tmp >>> exec /tmp/testdaemon.py Further experimentation reveals that by omitting the "expect daemon" stanza everything works fine. But I'm still a confused - the manpage says: expect daemon Specifies that the job's main process is a daemon, and will fork twice after being run. init(8) will follow this daemonisation, and will wait for this to occur before running the job's post- start script or considering the job to be running. Without this stanza init(8) is unable to supervise daemon pro? cesses and will believe them to have stopped as soon as they daemonise on startup. So I would have expected it to be necessary in this case. Maybe this is more an upstart issue than a python-daemon one - not sure. From sturlamolden at yahoo.no Sat Nov 14 11:58:02 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 08:58:02 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: On 14 Nov, 15:35, Dietmar Schwertberger wrote: > ? ?self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) > ? ?self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", > wx.DefaultPosition, wx.DefaultSize, 0 ) > ? ?m_toolBar1.AddControl( m_button1 ) > > (i.e. "self." is missing) I had problem like that with the first beta, but not the one from August. From tartley at tartley.com Sat Nov 14 12:06:56 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 14 Nov 2009 09:06:56 -0800 (PST) Subject: bootstrapping on machines without Python References: <20091113232539.0afbc5fe@Knock> Message-ID: <7d205b8d-01b5-4f95-ab2c-e21122fdb975@e23g2000yqd.googlegroups.com> On Nov 13, 10:25?pm, mma... at gmx.net wrote: > On Fri, 13 Nov 2009 02:40:28 -0800 (PST) > > Jonathan Hartley wrote: > > Even my very limited understanding of the issues is enough to see that > > the idea is far from trivial. Thanks heaps for the input from everyone. Martin Lemburg's 'chained' approach does sound like the smart way to do it, and Thomas does demonstrate pretty much the simplest possible example of what I'm thinking of. Martin Manns' portable Python sounds useful too, and is not disimilar to a suggestion made by Michael Foord off list. However, the problems that Tim, Martin, Marc and Martin point out do seem very real. I think users could be placated about 'backdoor installation' if we tell them what's going on, with an OK button. But I confess I wasn't aware that a full Python install is quite so large compared to the bundle produced by py2exe et al. Perhaps this idea is overly idealistic then - I was maybe transfixed by the 'needless consistency' of sharing a single interpreter between many applications. Thanks for helping me straighten out my thoughts on the subject. Best! Jonathan From philip at semanchuk.com Sat Nov 14 12:51:30 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 14 Nov 2009 12:51:30 -0500 Subject: How to know if a file is a text file In-Reply-To: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: On Nov 14, 2009, at 11:02 AM, Luca Fabbri wrote: > Hi all. > > I'm looking for a way to be able to load a generic file from the > system and understand if he is plain text. > The mimetype module has some nice methods, but for example it's not > working for file without extension. Hi Luca, You have to define what you mean by "text" file. It might seem obvious, but it's not. Do you mean just ASCII text? Or will you accept Unicode too? Unicode text can be more difficult to detect because you have to guess the file's encoding (unless it has a BOM; most don't). And do you need to verify that every single byte in the file is "text"? What if the file is 1GB, do you still want to examine every single byte? If you give us your own (specific!) definition of what "text" means, or perhaps a description of the problem you're trying to solve, then maybe we can help you better. Cheers Philip From news at schwertberger.de Sat Nov 14 13:02:14 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 14 Nov 2009 19:02:14 +0100 Subject: Choosing GUI Module for Python In-Reply-To: References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: <7m89l8F3g1lnpU1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 15:35, Dietmar Schwertberger wrote: > >> self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) >> self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", >> wx.DefaultPosition, wx.DefaultSize, 0 ) >> m_toolBar1.AddControl( m_button1 ) >> >> (i.e. "self." is missing) > > I had problem like that with the first beta, but not the one from > August. Which one? There are two: 08/23/2009 Version 3.01.63 (Beta) 08/19/2009 Version 3.01.62 (Beta) I tried 3.01.63. I can see in the Python window already that the code is not correct. Regards, Dietmar From rt8396 at gmail.com Sat Nov 14 13:08:59 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 10:08:59 -0800 (PST) Subject: A "terminators' club" for clp References: Message-ID: <70529349-696e-4f67-8b65-068dc84b71f4@e20g2000vbb.googlegroups.com> On Nov 14, 7:28?am, gil_johnson wrote: > How about using a "rank this post" feature? Anybody could rank a post > as spam, and a sufficiently large number of negatives would quickly > draw the attention of someone with the power to kill the message. I > suppose even this is subject to abuse, allowing harassment of a > legitimate poster., but my guess is that the votes against counterfeit > Nike shoes, etc., would outnumber the most energetic "vote troll." > Gil Actually there is a "rank this post" (gotta be careful with that verbage!) AND a "report this post as spam". Of course it only exists in GG's and not Usenet. I *do* know that the star system is used quite frequently, but i doubt anyone bothers to use the "report as spam" link since it seems have no effect whatsoever. From http Sat Nov 14 13:10:43 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:10:43 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7xr5s1t1ss.fsf@ruckus.brouhaha.com> sturlamolden writes: > Python on a better VM (LuaJIT, Parrot, LLVM, several > JavaScript) will easily outperform CPython by orders of magnitide. Maybe Python semantics make it more difficult to optimize than those other languages. For example, in a = foo.bar(1) b = muggle() c = foo.bar(2) it is not ok to cache the value of foo.bar after the first assignment. Maybe the second one goes and modifies it through foo.__dict__ . See "Children of a Lesser Python" (linked in another post, or websearch) for discussion. From deets at nospam.web.de Sat Nov 14 13:15:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 14 Nov 2009 19:15:41 +0100 Subject: Psyco on 64-bit machines In-Reply-To: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <7m8aedF3hrgipU1@mid.uni-berlin.de> Russ P. schrieb: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. Isn't the SUN Ultra using an ULTRA-Sparc core? If so, the point is moot. Diez From http Sat Nov 14 13:16:16 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:16:16 -0800 Subject: The ol' [[]] * 500 bug... References: <7m78oaF3fgtcfU1@mid.uni-berlin.de> <7m7vo6F3glkboU1@mid.uni-berlin.de> Message-ID: <7xmy2pt1jj.fsf@ruckus.brouhaha.com> Ulrich Eckhardt writes: > That said, [[]]*500 is IMHO more readable. But the issue in the thread is that it does the wrong thing. From nagle at animats.com Sat Nov 14 13:18:24 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Nov 2009 10:18:24 -0800 Subject: Python & Go In-Reply-To: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> Message-ID: <4afef1f5$0$1586$742ec2ed@news.sonic.net> sturlamolden wrote: > On 12 Nov, 01:53, kj wrote: >> I'm just learning about Google's latest: the GO (Go?) language. It's interesting. The semantics are closer to Java than any other mainstream language. While Java usually is run with a "virtual machine", Go is more like Java hard-compiled (which you can do with GCC.) It's far less dynamic than Python, which is good for performance. (That's not an inherent problem with Python. It's a problem with the CPython implementation. See Shed Skin.) The declaration syntax is borrowed from the Pascal/Modula/Ada family of languages, and it's an improvement over the C/C++ approach. I suspect that Go is LALR(1), which means it can be parsed with a simple context-independent parser. C and C++ are very difficult to parse, and modules can't be parsed independently. (Because of the C/C++ type syntax, you have to look up type names to find out how to parse declarations. So the include files have to be present to parse declarations. This is why there aren't many tools that manipulate C and C++ source code.) Having concurrency in the language is a win. Syntax for queues is a minor win. But the language doesn't directly address the issue of "who locks what". There are shared variables, and mutexes, but the language doesn't let you talk about which variables are shared. When the language doesn't know that, you either have to restrict optimization (as in Python) or have painful mechanisms like "mutable" as in C++. Leaving out exceptions was a mistake. Exceptions are well understood now, and they're far better than the usual "ignore errors" approach one sees in lamer C programs. The interface mechanism is simple enough. In a static language, you can convert "duck typing" to inheritance at link time, when you have the chance to see what can match what. So the implementation doesn't actually have to search for a match at run time. John Nagle From http Sat Nov 14 13:18:46 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:18:46 -0800 Subject: A "terminators' club" for clp References: Message-ID: <7xiqddt1fd.fsf@ruckus.brouhaha.com> "Alf P. Steinbach" writes: > The problem with moderation isn't getting rid of spam and trolls etc., > but turnaround time. There is automatic moderation software that auto-approves any post from an address that has had one or two posts manually approved. While that's susceptible to address forgery, the typical spammer doesn't do that. From http Sat Nov 14 13:23:57 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:23:57 -0800 Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> Message-ID: <7xd43lt16q.fsf@ruckus.brouhaha.com> sturlamolden writes: > And looking at Go, I cannot understand why Google prefer this over > e.g. Lua. I thought Lua had no type system and no concurrency. From http Sat Nov 14 13:34:44 2009 From: http (Paul Rubin) Date: 14 Nov 2009 10:34:44 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <7x8we9t0or.fsf@ruckus.brouhaha.com> kj writes: > One more thing: I found Rob Pike's mutterings on generics (towards > the end of his rollout video) rather offputting, because he gave > the impression that some important aspects of the language were > not even considered before major decisions for it were set in stone. > It looks like, if they ever get around to supporting generics, it > will be a late-in-the-day hack. Mark Chu-Carroll has a new post about Go: http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php Someone named Mightybyte also has a post about Go, and its comment thread is similarly pretty good: http://softwaresimply.blogspot.com/2009/11/standardizing-go.html One of the commenters wrote something that I felt was similar to my own impression of the language: From a PLT perspective Go isn't that interesting. The concurrency and "goroutines" look promising for possibly being able to do what Erlang does. The type system is pretty weak. From a practical perspective people are singing praise for how fast it compiles, but not much mention so far of how fast the resulting code is. Compare tinycc vs gcc for speed of compilation vs resulting code performace to see why I'm skeptical. From invalid at invalid.invalid Sat Nov 14 13:40:19 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 14 Nov 2009 18:40:19 +0000 (UTC) Subject: python simply not scaleable enough for google? References: <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-14, David Robinow wrote: > On Fri, Nov 13, 2009 at 3:32 PM, Paul Rubin > wrote: >> ... ?This is Usenet so >> please stick with Usenet practices. ?If you want a web forum there are >> plenty of them out there. > Actually this is python-list at python.org Actually this is comp.lang.python > I don't use usenet and I have no intention to stick with Usenet practices. From pedro.al at fenhi.uh.cu Sat Nov 14 14:26:11 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 14:26:11 -0500 Subject: Run a external program. Message-ID: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Hi all!! I'm writing a script where i call a external program which receive some arguments. One of this arguments is stored in a variable, that is passed as argument as well: import os ... f = open(file1, 'r') s = 'command $f -i file2 -w 1.4 -o file3.out' os.system(s) ... When i run the script i get the next message... '-i: No such file or directory' ... with a obvious error in the exit of the program. If i remove the option -i i get the same error with every option, even with those who don't get any file as argument. (file2 exist). BUT, when i run the external program in a python shell, it works... What's wrong? Please help me... Thanks -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From paul.nospam at rudin.co.uk Sat Nov 14 14:41:10 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 14 Nov 2009 19:41:10 +0000 Subject: python-daemon and upstart References: <87my2pimsf.fsf@rudin.co.uk> <87tywxse6o.fsf@benfinney.id.au> <87iqddhxx8.fsf@rudin.co.uk> <87bpj5hwog.fsf@rudin.co.uk> Message-ID: <877htsj3mx.fsf@rudin.co.uk> Paul Rudin writes: > > So I would have expected it to be necessary in this case. Maybe this is > more an upstart issue than a python-daemon one - not sure. Aha - so I discover that if detach_process is not explicitly passed to the DaemonContext initialiser it tries to guess whether it needs to do the double fork thing or not, passing it through explicitly makes every work as I expected. So it's probably an rtfm error on my part. Although I suppose that there may be an argument the the DaemonContext guessing should try and detect this situation.... not sure. From sturlamolden at yahoo.no Sat Nov 14 14:52:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 11:52:06 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> Message-ID: <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> On 14 Nov, 19:02, Dietmar Schwertberger wrote: > 08/23/2009 Version 3.01.63 (Beta) > 08/19/2009 Version 3.01.62 (Beta) > > I tried 3.01.63. > I can see in the Python window already that the code is not correct. 3.01.63 Did you remember to install the wxAdditions? Could you send me an .fbp file demonstrating the error? From python at mrabarnett.plus.com Sat Nov 14 14:53:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 14 Nov 2009 19:53:50 +0000 Subject: Run a external program. In-Reply-To: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Message-ID: <4AFF0ACE.6060803@mrabarnett.plus.com> Yasser Almeida Hern?ndez wrote: > Hi all!! > > I'm writing a script where i call a external program which receive some > arguments. > One of this arguments is stored in a variable, that is passed as > argument as well: > > import os > ... > f = open(file1, 'r') > s = 'command $f -i file2 -w 1.4 -o file3.out' > os.system(s) > ... > > When i run the script i get the next message... > '-i: No such file or directory' > ... with a obvious error in the exit of the program. If i remove the > option -i i get the same error with every option, even with those who > don't get any file as argument. (file2 exist). > BUT, when i run the external program in a python shell, it works... > > What's wrong? > The name 'f' in the Python script exists only in Python and is unrelated to the '$f' that the shell sees. From metolone+gmane at gmail.com Sat Nov 14 15:03:23 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 14 Nov 2009 12:03:23 -0800 Subject: Run a external program. References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> Message-ID: "Yasser Almeida Hern?ndez" wrote in message news:20091114142611.sj45qput2c84s0w0 at correo.fenhi.uh.cu... > Hi all!! > > I'm writing a script where i call a external program which receive some > arguments. > One of this arguments is stored in a variable, that is passed as argument > as well: > > import os > ... > f = open(file1, 'r') > s = 'command $f -i file2 -w 1.4 -o file3.out' > os.system(s) > ... > > When i run the script i get the next message... > '-i: No such file or directory' > ... with a obvious error in the exit of the program. If i remove the > option -i i get the same error with every option, even with those who > don't get any file as argument. (file2 exist). > BUT, when i run the external program in a python shell, it works... > > What's wrong? Please post a small, complete example of your code and the error message. Cut-and-paste them exactly. Also provide the shell command you are running that works. -Mark From pedro.al at fenhi.uh.cu Sat Nov 14 15:07:26 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 15:07:26 -0500 Subject: Run a external program. In-Reply-To: <4AFF0ACE.6060803@mrabarnett.plus.com> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> Message-ID: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> So, how can i pass an argument as a variable in this context...? Quoting MRAB : > Yasser Almeida Hern?ndez wrote: >> Hi all!! >> >> I'm writing a script where i call a external program which receive >> some arguments. >> One of this arguments is stored in a variable, that is passed as >> argument as well: >> >> import os >> ... >> f = open(file1, 'r') >> s = 'command $f -i file2 -w 1.4 -o file3.out' >> os.system(s) >> ... >> >> When i run the script i get the next message... >> '-i: No such file or directory' >> ... with a obvious error in the exit of the program. If i remove >> the option -i i get the same error with every option, even with >> those who don't get any file as argument. (file2 exist). >> BUT, when i run the external program in a python shell, it works... >> >> What's wrong? >> > The name 'f' in the Python script exists only in Python and is unrelated > to the '$f' that the shell sees. > -- > http://mail.python.org/mailman/listinfo/python-list -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From sturlamolden at yahoo.no Sat Nov 14 15:15:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 14 Nov 2009 12:15:53 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: On 14 Nov, 19:18, John Nagle wrote: > Syntax for queues is a minor win. No, that's syntax bloat. The go keyword could be a problem as well. I suspect it could infringe on Cilk++ patents. Perhaps Go cannot be used without a licence from Cilk Arts? From http Sat Nov 14 15:23:40 2009 From: http (Paul Rubin) Date: 14 Nov 2009 12:23:40 -0800 Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: <7xocn4rh2r.fsf@ruckus.brouhaha.com> sturlamolden writes: > The go keyword could be a problem as well. I suspect it could infringe > on Cilk++ patents. Perhaps Go cannot be used without a licence from > Cilk Arts? Also as somebody said, if after a while they decide to make a new version of the language, they'll have to call it Go2, which will necessarily be considered harmful. From clp2 at rebertia.com Sat Nov 14 15:50:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 12:50:14 -0800 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: <50697b2c0911141250p26f70f3co1367c816493d36b5@mail.gmail.com> > Quoting MRAB : >> Yasser Almeida Hern?ndez wrote: >>> >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive ?some >>> arguments. >>> One of this arguments is stored in a variable, that is passed as >>> ?argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove ?the >>> option -i i get the same error with every option, even with ?those who don't >>> get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. 2009/11/14 Yasser Almeida Hern?ndez : > So, how can i pass an argument as a variable in this context...? Use the string variable's value when specifying the arguments to the command. Here's how you'd do it using the newer `subprocess` module: import sys import subprocess args = ['command', file1, '-i', 'file2', '-w', '1.4', '-o', 'file3.out'] #assuming only file1 is variable return_code = subprocess.call(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr) Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sat Nov 14 15:56:30 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 14 Nov 2009 20:56:30 +0000 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: <4AFF197E.6080304@mrabarnett.plus.com> Yasser Almeida Hern?ndez wrote: > So, how can i pass an argument as a variable in this context...? > You can't pass arbitrary values on a command line. In this case, why not just pass the path of the file? s = 'command "%s" -i file2 -w 1.4 -o file3.out' % file1 > > Quoting MRAB : > >> Yasser Almeida Hern?ndez wrote: >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive >>> some arguments. >>> One of this arguments is stored in a variable, that is passed as >>> argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove the >>> option -i i get the same error with every option, even with those >>> who don't get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. > From rtw at freenet.co.uk Sat Nov 14 16:14:50 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sat, 14 Nov 2009 15:14:50 -0600 Subject: Help with database planning References: <0e64893a-af82-4004-bf3c-f397f2022846@g22g2000prf.googlegroups.com> Message-ID: Juliano wrote in news:0e64893a-af82-4004-bf3c-f397f2022846 at g22g2000prf.googlegroups.com in comp.lang.python: [snip] > So, for ONE *concept*, we have, usually, MANY *slots*, each *slot* has > ONE *facet*, and each *facet* can have MORE THAN ONE *filler*. > Besides, some *slots* and *fillers* are themselves *concepts*, > creating a sort of recursive reference. What I'm grokking from the data you show is that a "Concept" is a table (or a python class), "slots" are attributes of the concept and facets are the type of "slot", finally the "fillers" are (mostly) the data. But also you seem to have "slots" that represent relationships between "Concepts" and other tables, in this case the "slots" should be tables. For example with the slot type "INSTANCE-OF", what is "OTHER-NIGER-KORDOFANIAN-LANGUAGE" is it another concept or a list of concepts or a concept "OTHER-NIGER-KORDOFANIAN" and a type "LANGUAGE", I suspect you have a table "Language" and also an table "Region" in there too. It may be time to start thinking in terms of what you are modeling and what the entities are (as apposed to trying to convert the data you have), once you have that, work out how to load that data from your current file and check that you can query your model correctly. Maybe something like (using a made up ORM): class Concept: name = TextField() definition = TextField() primary_key = PrimaryKey( name ) class IsASlot: concept = ForeignKey( Concept ) is_a = ForeignKey( Concept ) primary_key = PrimaryKey( concept, is_a ) class LexeSlot: concept = ForeignKey( Concept ) value = TextField() primary_key = PrimaryKey( concept, value ) class Region: region = TextField() primary_key = PrimaryKey( region ) class Language: language = ForeignKey( Concept ) # or is it TextField() ? primary_key = PrimaryKey( language ) class LanguageOfSlot: language = ForeignKey( Language ) region = ForeignKey( Region ) primary_key = PrimaryKey( language, region ) To reiterate, you should use your domain expertise to create the model. > > > line_no concepts slots facets fillers > ----------------------------------------------------------------------- > ------- 00000 ABANDON DEFINITION VALUE "to leave or > desert something or someone" > 00001 ABANDON IS-A VALUE EXIT > 00002 ABANDON LEXE MAP-LEX "leave behind-V1" > 00003 ABANDON LEXE MAP-LEX abandon-V1 The "-V1" in the above looks worryingly like you have structure embedded in the data field, if so you should extract is so its in its own field or table. > (...) > 97420 ZULU DEFINITION VALUE "a language or dialect > spoken in south africa and others" > 97421 ZULU INSTANCE-OF VALUE > OTHER-NIGER-KORDOFANIAN-LANGUAGE > 97422 ZULU LANGUAGE-OF INV LESOTHO > 97423 ZULU LANGUAGE-OF INV SOUTH-AFRICA Rob. From pedro.al at fenhi.uh.cu Sat Nov 14 16:23:22 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Sat, 14 Nov 2009 16:23:22 -0500 Subject: Run a external program. In-Reply-To: <4AFF197E.6080304@mrabarnett.plus.com> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> <4AFF197E.6080304@mrabarnett.plus.com> Message-ID: <20091114162322.04wbz2hgtccssc8s@correo.fenhi.uh.cu> All ran ok!! Thanks a lot Quoting MRAB : > Yasser Almeida Hern?ndez wrote: >> So, how can i pass an argument as a variable in this context...? >> > You can't pass arbitrary values on a command line. In this case, why not > just pass the path of the file? > > s = 'command "%s" -i file2 -w 1.4 -o file3.out' % file1 > >> >> Quoting MRAB : >> >>> Yasser Almeida Hern?ndez wrote: >>>> Hi all!! >>>> >>>> I'm writing a script where i call a external program which >>>> receive some arguments. >>>> One of this arguments is stored in a variable, that is passed as >>>> argument as well: >>>> >>>> import os >>>> ... >>>> f = open(file1, 'r') >>>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>>> os.system(s) >>>> ... >>>> >>>> When i run the script i get the next message... >>>> '-i: No such file or directory' >>>> ... with a obvious error in the exit of the program. If i remove >>>> the option -i i get the same error with every option, even with >>>> those who don't get any file as argument. (file2 exist). >>>> BUT, when i run the external program in a python shell, it works... >>>> >>>> What's wrong? >>>> >>> The name 'f' in the Python script exists only in Python and is unrelated >>> to the '$f' that the shell sees. >> > > -- > http://mail.python.org/mailman/listinfo/python-list -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From nobody at nowhere.com Sat Nov 14 16:55:25 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 14 Nov 2009 21:55:25 +0000 Subject: 3.x and 2.x on same machine (is this info at Python.org??) References: <5292b320-537c-4647-9c0f-f47742ab0f73@g1g2000vbr.googlegroups.com> <4947f0f7-897c-430f-944f-82e85bd73a27@j24g2000yqa.googlegroups.com> Message-ID: On Fri, 13 Nov 2009 06:05:48 -0500, Dave Angel wrote: >>> Currently i am using 2.6 on Windows and need to start writing code in >>> 3.0. I cannot leave 2.x yet because 3rd party modules are still not >>> converted. So i want to install 3.0 without disturbing my current >>> Python2.x. What i'm afraid of is that some SYSVARIABLE will get >>> changed to Python3.0 and when i double click a Python script it will >>> try and run Python 3.x instead of 2.x. I only want to run 3.0 scripts >>> from the command line... > python3.x myscript.py >>> >>> So how do i do this? Is my fear unfounded? >>> >> >> Windows determines the double-click action based on the file >> extension. You just have to make sure that *.py files are associated >> with 2.x. >> http://support.microsoft.com/kb/307859 >> >> >> > And if someone simply wants to check or change these associations > without all the Explorer nonsense, one can use > assoc.exe and ftype.exe That isn't reliable. The Windows registry has two distinct sets of mappings. HKEY_LOCAL_MACHINE\Software\Classes contains system-wide mappings, while HKEY_CURRENT_USER\Software\Classes contains per-user mappings. The per-user mappings are checked first, with the system-wide mappings acting as a fall-back. AFAICT, assoc and ftype modify the system-wide mappings, so if you have a per-user mapping, they have no effect. Note that HKEY_CLASSES_ROOT is a "virtual" key obtained by merging the above two keys (analogous to a view in an RDBMS). http://msdn.microsoft.com/en-us/library/ms724475(VS.85).aspx From tjreedy at udel.edu Sat Nov 14 17:02:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:02:19 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <66c03518-57c6-426a-96a8-55e465826c7e@s31g2000yqs.googlegroups.com> Message-ID: sturlamolden wrote: > - For the few cases where a graphics program really need C, we can > always resort to using ctypes, f2py or Cython. Gluing Python with C or > Fortran is very easy using these tools. That is much better than > keeping it all in C++. In case anyone thinks resorting to C or Fortran is cheating, they should know that CPython, the implementation, was designed for this. That is why there is a documented C-API and why the CPython devs are slow to change it. Numerical Python dates back to at least 1.3 and probably earlier. The people who wrote it were some of the first production users of Python. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 17:10:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:10:50 -0500 Subject: Python & Go In-Reply-To: <7x8we9t0or.fsf@ruckus.brouhaha.com> References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Mark Chu-Carroll has a new post about Go: > > http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php In a couple of minutes, I wrote his toy prime filter example in Python, mostly from the text rather than the code, which I can barely stand to read. It ran the first time without error. def plurals(): i = 2 while True: yield i i += 1 def primefilter(src, prime): for i in src: if i % prime: yield i src = plurals() while True: i = next(src) print(i) src = primefilter(src, i) As I commented there "It stopped at 7877 when it hit the default recursion limit of 1000, which could easily be increased to get out-of-memory error instead. I think Google is making a blunder if it moves to another old-fashioned language whose code is bloated with junky boilerplate that doubles the size. It would be much better, for instance, to tweak Python, which it has had great success with, to better run on multiple cores." Terry Jan Reedy From falk at mauve.rahul.net Sat Nov 14 17:34:20 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Sat, 14 Nov 2009 22:34:20 +0000 (UTC) Subject: python simply not scaleable enough for google? References: Message-ID: In article , Terry Reedy wrote: > >I can imagine a day when code compiled from Python is routinely >time-competitive with hand-written C. I can't. Too much about the language is dynamic. The untyped variables alone are a killer. int a,b,c; ... a = b + c; In C, this compiles down to just a few machine instructions. In Python, the values in the variables need to be examined *at run time* to determine how to add them or if they can even be added at all. You'll never in a million years get that down to just two or three machine cycles. Yes, technically, the speed of a language depends on its implementation, but the nature of the language constrains what you can do in an implementation. Python the language is inherently slower than C the language, no matter how much effort you put into the implementation. This is generally true for all languages without strongly typed variables. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From yoav.goldberg at gmail.com Sat Nov 14 17:42:33 2009 From: yoav.goldberg at gmail.com (Yoav Goldberg) Date: Sun, 15 Nov 2009 00:42:33 +0200 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy wrote: > Paul Rubin wrote: > > Mark Chu-Carroll has a new post about Go: >> >> >> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> > > In a couple of minutes, I wrote his toy prime filter example in Python, > mostly from the text rather than the code, which I can barely stand to read. > It ran the first time without error. > > Yes, but the cool thing about the Go version is that it does each generator in a different thread, so in theory it could run twice as fast on a multi-core machine. Y -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 14 17:45:00 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:45:00 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Willem Broekema wrote: > It might have gotten a bit better, but the central message still > stands: Python has made design choices that make efficient compilation > hard. > >> OK, let me try this again. My assertion is that with some combination of JITting, >> reorganization of the Python runtime, and optional static declarations, Python >> can be made acceptably fast, > > That does not contradict that, had other language design choices been > made, it could be much easier to get better performance. Python may in > general be about as dynamic as Common Lisp from a _user_ perspective, > but from an implementator's point of view Python is harder to make it > run efficiently. I think you are right about the design choices. The reason for those design choices is that Guido intended from the beginning that Python implementations be part of open computational systems, and not islands to themselves like Smalltalk and some Lisps. While the public CPython C-API is *not* part of the Python language, Python was and has been designed with the knowledge that there *would be* such an interface, and that speed-critical code would be written in C or Fortran, or that Python programs would interface with and use such code already written. So: Python the language was designed for human readability, with the knowledge that CPython the implementation (originally and still today just called python.exe) would exist in a world where intensive computation could be pushed onto C or Fortan when necessary. So: to talk about the 'speed of Python', one should talk about the speed of human reading and writing. On this score, Python, I believe, beats most other algorithm languages, as intended. It certainly does for me. To talk about the speed of CPython, one must, to be fair, talk about the speed of CPython + extensions compiled to native code. In the scale of human readability, I believe Google go is a step backwards from Python. Terry Jan Reedy From russ.paielli at gmail.com Sat Nov 14 17:51:45 2009 From: russ.paielli at gmail.com (Russ P.) Date: Sat, 14 Nov 2009 14:51:45 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> <7m8aedF3hrgipU1@mid.uni-berlin.de> Message-ID: <96271b5f-9a52-4033-b56e-f772ce763c52@x6g2000prc.googlegroups.com> On Nov 14, 10:15?am, "Diez B. Roggisch" wrote: > Russ P. schrieb: > > > I have a Python program that runs too slow for some inputs. I would > > like to speed it up without rewriting any code. Psyco seemed like > > exactly what I need, until I saw that it only works on a 32-bit > > architecture. I work in an environment of Sun Ultras that are all 64- > > bit. However, the Psyco docs say this: > > > "Psyco does not support the 64-bit x86 architecture, unless you have a > > Python compiled in 32-bit compatibility mode." > > > Would it make sense to compile Python in the 32-bit compatibility mode > > so I can use Psyco? What would I lose in that mode, if anything? > > Thanks. > > Isn't the SUN Ultra using an ULTRA-Sparc core? If so, the point is moot. > > Diez No, it's Intel based. From tjreedy at udel.edu Sat Nov 14 17:52:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 17:52:01 -0500 Subject: A "terminators' club" for clp In-Reply-To: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: r wrote: > On Nov 14, 4:59 am, kj wrote: >> But, as I already showed, I'm out of my depth here, >> so I'd better shut up. > > Don't give up so easy! The idea is great, what Paul is saying is that > most people who read this group use newsreaders and that has nothing > to do with google groups. These guy's have kill filters for just this > sort of thing but either way the emails are on their puters so they > have to deal with them on an individual basis. It would be nice > however to clean up the Google group version and rid it of the plagues > of spam infestations. Anyone with a newsreader can, like me, read gmane.comp.python.general, which mirrors python-list, which now filters out much/most of the spam on c.l.p from G.g. To post from g.c.p.g, one must use a real email address and respond once to an email sent to that address. So, the only reason to use c.l.p is if one wants to post anonymously, like the spammers do ;-). Terry Jan Reedy From bbrown at speakeasy.net Sat Nov 14 17:56:39 2009 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 14 Nov 2009 17:56:39 -0500 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: Vincent Manis writes: > The false statement you made is that `... Python *the language* is specified > in a way that makes executing Python programs quickly very very difficult. > I refuted it by citing several systems that implement languages with > semantics similar to those of Python, and do so efficiently. The semantic details matter. Please read Willem's reply to your post. It contains a long list of specific differences between Python (CPython) language semantics and Common Lisp language semantics that cause Python performance to suffer. > OK, let me try this again. My assertion is that with some combination of > JITting, reorganization of the Python runtime, and optional static > declarations, Python can be made acceptably fast, which I define as program > runtimes on the same order of magnitude as those of the same programs in C > (Java and other languages have established a similar goal). I am not pushing > optional declarations, as it's worth seeing what we can get out of > JITting. If you wish to refute this assertion, citing behavior in CPython or > another implementation is not enough. You have to show that the stated > feature *cannot* be made to run in an acceptable time. It's hard to refute your assertion. You're claiming that some future hypothetical Python implementation will have excellent performance via a JIT. On top of that you say that you're willing to change the definition of the Python language, say by adding type declarations, if an implementation with a JIT doesn't pan out. If you change the Python language to address the semantic problems Willem lists in his post and also add optional type declarations, then Python becomes closer to Common Lisp, which we know can be executed efficiently, within the same ballpark as C and Java. bob From http Sat Nov 14 18:03:55 2009 From: http (Paul Rubin) Date: 14 Nov 2009 15:03:55 -0800 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <7x639cyahw.fsf@ruckus.brouhaha.com> Terry Reedy writes: > To post from g.c.p.g, one must use a real email address and respond > once to an email sent to that address. > > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). No I don't think so. "Unwilling to disclose email address or enroll yet another computer account" is not the same as "anonymous". From aonlazio at gmail.com Sat Nov 14 18:25:07 2009 From: aonlazio at gmail.com (AON LAZIO) Date: Sat, 14 Nov 2009 18:25:07 -0500 Subject: Simple object reference Message-ID: Hi, I have some problem with object reference Say I have this code a = b = c = None slist = [a,b,c] for i in range(len(slist)): slist[i] = 5 print slist print a,b,c I got this [5, 5, 5] None None None Question is how can I got all a,b,c variable to have value 5 also? Thanks in advance -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 14 18:40:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 15:40:05 -0800 Subject: Simple object reference In-Reply-To: References: Message-ID: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: > Hi, I have some problem with object reference > Say I have this code > > a = b = c = None > slist = [a,b,c] Values are stored in the list, not references to names. Modifying the list does not change what values the names a, b, and c have. There is no Python-level notion of pointers. > for i in range(len(slist)): > slist[i] = 5 This modifies the contents of the list, it does not affect any other variables/names. > print slist > print a,b,c > > I got this > [5, 5, 5] > None None None > > ??? Question is how can I got all a,b,c variable to have value 5 also? Use tuple unpacking: #at start of code slist = [None]*3 #... #at end of code a, b, c = slist I would also recommend reading http://effbot.org/zone/call-by-object.htm for a good explanation of how Python's variables work. Cheers, Chris -- http://blog.rebertia.com From russ.paielli at gmail.com Sat Nov 14 18:48:49 2009 From: russ.paielli at gmail.com (Russ P.) Date: Sat, 14 Nov 2009 15:48:49 -0800 (PST) Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: On Nov 12, 12:06?pm, "Russ P." wrote: > I have a Python program that runs too slow for some inputs. I would > like to speed it up without rewriting any code. Psyco seemed like > exactly what I need, until I saw that it only works on a 32-bit > architecture. I work in an environment of Sun Ultras that are all 64- > bit. However, the Psyco docs say this: > > "Psyco does not support the 64-bit x86 architecture, unless you have a > Python compiled in 32-bit compatibility mode." > > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. I just stumbled across "unladen swallow," a "faster implementation of Python." Is it ready for operational usage? How does it compare to Psyco? I poked around their website a bit, but I don't see answers to those questions. Thanks. From rt8396 at gmail.com Sat Nov 14 18:52:51 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 15:52:51 -0800 (PST) Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> On Nov 14, 4:52?pm, Terry Reedy wrote: > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). I don't think that completely correct. Lots of people find GG's to be more suited to their news reading pleasures, i am one of them. I hate to have an email just overflowing with mails all the time. Here in GG's, i just come and go without worrying about deleting messages or kill filters or whatever. Maybe even Guido himself uses GG's? Heck for all we know Guido could have a "pybot" sending all these spams just so Python's TIOBE index will increase! ;-) From james.harris.1 at googlemail.com Sat Nov 14 19:12:39 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 14 Nov 2009 16:12:39 -0800 (PST) Subject: Easy way to play single musical notes in Python Message-ID: Is there a simple way to play musical notes in Python? Something like voice.play("c4") to play C in octave 4 would be ideal. I included a voice parameter as I'd like to play proper notes, not just beeps. This is for recognition of pitch. For example, the program plays a note and the user tries to identify the note played. There are many options at http://wiki.python.org/moin/PythonInMusic but which to choose? They generally seem too complex. I'm looking for something really basic. It would help if it was cross platform and didn't need Tkinter as the snack library does. I presume pure Python is not possible. Any suggestions? James From ben+python at benfinney.id.au Sat Nov 14 19:20:14 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 11:20:14 +1100 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: <877htsskox.fsf@benfinney.id.au> Terry Reedy writes: > So, the only reason to use c.l.p is if one wants to post anonymously, > like the spammers do ;-). Or if one has an ISP who provides a Usenet feed, like mine does. A pox upon Andrew Cuomo for bashing ISPs in the USA with the stick of ?child pornography? (which he discovered on 88 out of many thousands of forums). Faced with the unreasonable role of policing Usenet, they shut it all off . -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From james.harris.1 at googlemail.com Sat Nov 14 19:21:51 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 14 Nov 2009 16:21:51 -0800 (PST) Subject: Easy way to play single musical notes in Python References: Message-ID: On 15 Nov, 00:12, James Harris wrote: > Is there a simple way to play musical notes in Python? Something like > > ? voice.play("c4") > > to play C in octave 4 would be ideal. I included a voice parameter as > I'd like to play proper notes, not just beeps. This is for recognition > of pitch. For example, the program plays a note and the user tries to > identify the note played. > > There are many options at > > ?http://wiki.python.org/moin/PythonInMusic > > but which to choose? They generally seem too complex. I'm looking for > something really basic. It would help if it was cross platform and > didn't need Tkinter as the snack library does. I presume pure Python > is not possible. > > Any suggestions? Oh, it would be OK if the system allowed numeric pitches such as voice.play(440) to play a note at 440 Hertz. Anything like the above should be good enough. James From ben+python at benfinney.id.au Sat Nov 14 19:36:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 15 Nov 2009 11:36:25 +1100 Subject: Simple object reference References: Message-ID: <873a4gsjxy.fsf@benfinney.id.au> Chris Rebert writes: > On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: > > Hi, I have some problem with object reference > > Say I have this code > > > > a = b = c = None > > slist = [a,b,c] > > Values are stored in the list, not references to names. Modifying the > list does not change what values the names a, b, and c have. There is > no Python-level notion of pointers. There *is*, though, a notion of references, which is what the OP is asking about. The list does not store values, it stores references to values (just as a name references a value). You're right that the names are irrelevant for the items in the list; the name ?a? and the item ?slist[0]? are always independent references. > > for i in range(len(slist)): > > slist[i] = 5 Hence, this has no effect on what the names ?a?, ?b?, ?c? reference; those names continue to reference whatever they were already referencing. It is changing only what the list items ?slist[0]?, ?slist[1]?, ?slist[2]? reference. > I would also recommend reading > http://effbot.org/zone/call-by-object.htm for a good explanation of > how Python's variables work. Yes, the Effbot's explanations are good. It's also worth noting that the Python reference documentation has become much more readable recently, and the language reference has good explanations of the data model and what assignment statements do . -- \ ?As we enjoy great advantages from the inventions of others, we | `\ should be glad to serve others by any invention of ours; and | _o__) this we should do freely and generously.? ?Benjamin Franklin | Ben Finney From vincent at vincentdavis.net Sat Nov 14 20:01:48 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 14 Nov 2009 18:01:48 -0700 Subject: A different take on finding primes Message-ID: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Out of pure curiosity I would like to compare the efficiency of different methods of finding primes (need not be consecutive). Let me be clear, given 2min, how many primes can you find, they need not be in order or consecutive. I have not seen any examples of this. I am assume the solution is different depending on the time give, 2min or 2 hours. I assume a sieve solution would be best for larger times. When the numbers get really large checking to see if they are a prime gets costly. So what do you think? *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Nov 14 20:14:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 20:14:23 -0500 Subject: Run a external program. In-Reply-To: <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> References: <20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu> <4AFF0ACE.6060803@mrabarnett.plus.com> <20091114150726.hiycbh4ewwco8go0@correo.fenhi.uh.cu> Message-ID: Top-posting makes things more confusing. You cannot pass a Python file object to an external process. Pass the name instead. Yasser Almeida Hern?ndez wrote: > So, how can i pass an argument as a variable in this context...? > > > Quoting MRAB : > >> Yasser Almeida Hern?ndez wrote: >>> Hi all!! >>> >>> I'm writing a script where i call a external program which receive >>> some arguments. >>> One of this arguments is stored in a variable, that is passed as >>> argument as well: >>> >>> import os >>> ... >>> f = open(file1, 'r') >>> s = 'command $f -i file2 -w 1.4 -o file3.out' >>> os.system(s) >>> ... >>> >>> When i run the script i get the next message... >>> '-i: No such file or directory' >>> ... with a obvious error in the exit of the program. If i remove the >>> option -i i get the same error with every option, even with those >>> who don't get any file as argument. (file2 exist). >>> BUT, when i run the external program in a python shell, it works... >>> >>> What's wrong? >>> >> The name 'f' in the Python script exists only in Python and is unrelated >> to the '$f' that the shell sees. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > From martin at v.loewis.de Sat Nov 14 20:53:29 2009 From: martin at v.loewis.de (=?windows-1252?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 02:53:29 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> Message-ID: <4AFF5F19.3040809@v.loewis.de> > This cannot work, because Foo_Type is no PyObject but a PyVarObject > (independent > of the use of PyVarObject_HEAD_INIT or PyObject_HEAD_INIT). The code > line would > work so: > > ((PyObject *)&Foo_Type)->ob_type = &PyType_Type However, this is not what you should use. Instead, use Py_Type(&Foo_Type) = &PyType_Type > If the type is not subtypable (doesn?t have the > Py_TPFLAGS_BASETYPE flag bit set), it is permissible to call the > object deallocator directly instead of via tp_free. > " > > What ? Where do we "call" these methods ? You should typically call tp_free inside of tp_dealloc. For example, string_dealloc ends with Py_TYPE(op)->tp_free(op); In the specific case (Py_TYPE(op) is not subtypeable), you could alternatively also call PyObject_Del(op); If there are subclasses, they might have used a different allocator (rather than the object allocator), hence you must call the deallocator through tp_free. HTH, Martin From tjreedy at udel.edu Sat Nov 14 21:00:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:00:25 -0500 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: Yoav Goldberg wrote: > > On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy > wrote: > > Paul Rubin wrote: > > Mark Chu-Carroll has a new post about Go: > > http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php > > > In a couple of minutes, I wrote his toy prime filter example in > Python, mostly from the text rather than the code, which I can > barely stand to read. It ran the first time without error. > > > Yes, but the cool thing about the Go version is that it does each > generator in a different thread, so in theory it could run twice as fast > on a multi-core machine. Which is why I added, in my opinion, that "It would be much better, for instance, to tweak Python, which it has had great success with, to better run on multiple cores." For instance, add a new keyword 'go' such that go def f(): yield 1 runs the generator in a different thread, possibly on a different core. To go further, restrict Python's dynamism, require 3.x annotations, and call the result GoPython ;-). Actually, it is already possible to post-process code objects to, in effect, remove the effect of many dynamic assumptions http://code.activestate.com/recipes/277940/ Perhaps, with a different implementation, not even a keyword is needed, just a built-in decorator: @go def f(): yield 1 The go decorator would replace f with a wrapper that runs instances gf of f in threads or whatever, calls next(gf) immediately for parallel opereation, and caches the first yielded value until the calling function calls next(wrapper) to retrieve it. It seems to me that generators are already 'channels' that connect the calling code to the __next__ method, a semi-coroutine based on the body of the generator function. At present, the next method waits until an object is requested. Then it goes into action, yields an object, and rests again. For parallel operations, we need eager, anticipatory evaluation that produces things that *will* be needed rather than lazy evaluation of things that *are* needed and whose absence is holding up everything else. I see no reason why we cannot have that with Python. I not even sure we cannot have it with CPython, but I am not familiar enough with threads, processes, and CPython internals. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:09:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:09:02 -0500 Subject: A "terminators' club" for clp In-Reply-To: <7x639cyahw.fsf@ruckus.brouhaha.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <7x639cyahw.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Terry Reedy writes: >> To post from g.c.p.g, one must use a real email address and respond >> once to an email sent to that address. >> >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > No I don't think so. "Unwilling to disclose email address or enroll > yet another computer account" is not the same as "anonymous". There is no 'enrolling' except for hitting reply to an email *when you first post*, but never to just read. You point your news reader to gmane just like to any other newsserver. Once you do, you have access to a couple hundred other Python mailing lists and 1000s of others. I believe c.l.p is one of the few that also appear on gmane, and only because of its gateway to/from python-list. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:13:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:13:19 -0500 Subject: A "terminators' club" for clp In-Reply-To: <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <806206f9-4e49-4e7c-954d-e1e42b2e1613@m20g2000vbp.googlegroups.com> Message-ID: r wrote: > On Nov 14, 4:52 pm, Terry Reedy wrote: >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > I don't think that completely correct. Lots of people find GG's to be > more suited to their news reading pleasures, I was referring to c.l.p on a nntp newsserver read by a newsreader program. That was the context of the previous discussion. G.G. is different, read through a browser (and only that, as far as I know). i am one of them. I hate > to have an email just overflowing with mails all the time. Here in > GG's, i just come and go without worrying about deleting messages or > kill filters or whatever. That is why I read python-list and other mailing lists (that are not available as a g.g.) via gmane. Terry Jan Reedy From tjreedy at udel.edu Sat Nov 14 21:25:08 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:25:08 -0500 Subject: A "terminators' club" for clp In-Reply-To: <877htsskox.fsf@benfinney.id.au> References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <877htsskox.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Terry Reedy writes: > >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > > Or if one has an ISP who provides a Usenet feed, like mine does. Gmane is a nntp news feed, just not a usenet feed. If you can read usenet, you can read gmane, probably in the time it took you to write this post -- and get access to 1000s of mirrer mailing lists. I switched to gmane's mirror of python-list *before* I had to because it was superior, overall, to my ISP at the time. Hoever, if you like the extra spam, don't spend the minute it takes. But my comment is directed at those complaining about it. Just tell your newsreader to make a new news 'account' for news.gmane.org or snews.gmane.org (port 563) to use ssl - either at the corresponding default ports. tjr From vmanis at telus.net Sat Nov 14 21:42:07 2009 From: vmanis at telus.net (Vincent Manis) Date: Sat, 14 Nov 2009 18:42:07 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> This whole thread has now proceeded to bore me senseless. I'm going to respond once with a restatement of what I originally said. Then I'm going to drop it, and never respond to the thread again. Much of what's below has been said by others as well; I'm taking no credit for it, just trying to put it together into a coherent framework. 1. The original question is `Is Python scalable enough for Google' (or, I assume any other huge application). That's what I was responding to. 2. `Scalable' can mean performance or productivity/reliability/maintenance quality. A number of posters conflated those. I'll deal with p/r/m by saying I'm not familiar with any study that has taken real enterprise-type programs and compared, e.g., Java, Python, and C++ on the p/r/m criteria. Let's leave that issue by saying that we all enjoy programming in Python, and Python has pretty much the same feature set (notably modules) as any other enterprise language. This just leaves us with performance. 3. Very clearly CPython can be improved. I don't take most benchmarks very seriously, but we know that CPython interprets bytecode, and thus suffers relative to systems that compile into native code, and likely to some other interpretative systems. (Lua has been mentioned, and I recall looking at a presentation by the Lua guys on why they chose a register rather than stack-based approach.) 4. Extensions such as numpy can produce tremendous improvements in productivity AND performance. One answer to `is Python scalable' is to rephrase it as `is Python+C scalable'. 5. There are a number of JIT projects being considered, and one or more of these might well hold promise. 6. Following Scott Meyers' outstanding advice (from his Effective C++ books), one should prefer compile time to runtime wherever possible, if one is concerned about performance. An implementation that takes hints from programmers, e.g., that a certain variable is not to be changed, or that a given argument is always an int32, can generate special-case code that is at least in the same ballpark as C, if not as fast. This in no way detracts from Python's dynamic nature: these hints would be completely optional, and would not change the semantics of correct programs. (They might cause programs running on incorrect data to crash, but if you want performance, you are kind of stuck). These hints would `turn off' features that are difficult to compile into efficient code, but would do so only in those parts of a program where, for example, it was known that a given variable contains an int32. Dynamic (hint-free) and somewhat less-dynamic (hinted) code would coexist. This has been done for other languages, and is not a radically new concept. Such hints already exist in the language; __slots__ is an example. The language, at least as far as Python 3 is concerned, has pretty much all the machinery needed to provide such hints. Mechanisms that are recognized specially by a high-performance implementation (imported from a special module, for example) could include: annotations, decorators, metaclasses, and assignment to special variables like __slots__. 7. No implementation of Python at present incorporates JITting and hints fully. Therefore, the answer to `is CPython performance-scalable' is likely `NO'. Another implementation that exploited all of the features described here might well have satisfactory performance for a range of computation-intensive problems. Therefore, the answer to `is the Python language performance-scalable' might be `we don't know, but there are a number of promising implementation techniques that have been proven to work well in other languages, and may well have tremendous payoff for Python'. -- v From tjreedy at udel.edu Sat Nov 14 21:53:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Nov 2009 21:53:39 -0500 Subject: Simple object reference In-Reply-To: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> References: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: >> Hi, I have some problem with object reference >> Say I have this code >> >> a = b = c = None >> slist = [a,b,c] > > Values are stored in the list, not references to names. That is not right either, or else newbies would not be surprised by >>> a = [0] >>> b = [a] >>> b[0][0] = 1 >>> a [1] Subscriptable collections associate subscripts with objects. Namespaces associated names with objects. In either case, if you change the object, you change it, regardless of how you access it, such as by means of other associations. If you replace an association by associating a name or subscript with a new object, the old object is untouched (unless that was its last association) and other access methods by means of other associations are not affected. Terry Jan Reedy From clp2 at rebertia.com Sat Nov 14 22:19:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 14 Nov 2009 19:19:19 -0800 Subject: Simple object reference In-Reply-To: References: <50697b2c0911141540w6894a74fradb4ab59fa84fd06@mail.gmail.com> Message-ID: <50697b2c0911141919j2bbd7a40j9d6dd19ffd7ff84b@mail.gmail.com> On Sat, Nov 14, 2009 at 6:53 PM, Terry Reedy wrote: > Chris Rebert wrote: >> On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO wrote: >>> Hi, I have some problem with object reference >>> Say I have this code >>> >>> a = b = c = None >>> slist = [a,b,c] >> >> Values are stored in the list, not references to names. > > That is not right either, or else newbies would not be surprised by >>>> a = [0] >>>> b = [a] >>>> b[0][0] = 1 >>>> a > [1] > > Subscriptable collections associate subscripts with objects. > Namespaces associated names with objects. > In either case, if you change the object, you change it, regardless of how > you access it, such as by means of other associations. > If you replace an association by associating a name or subscript with a new > object, the old object is untouched (unless that was its last association) > and other access methods by means of other associations are not affected. Okay, I should have technically said "references to objects" rather than "values", but in any case, names themselves are certainly not referenced or the following would print "[1]". >>> a = [0] >>> b = [a] >>> a = [42] >>> b[0][0] = 1 >>> a [42] Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 22:55:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 03:55:21 GMT Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> <00864dc6$0$26916$c3e8da3@news.astraweb.com> <00868cb9$0$26916$c3e8da3@news.astraweb.com> <7x8wea57bv.fsf@ruckus.brouhaha.com> Message-ID: <030f69bf$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 18:25:59 -0800, Vincent Manis wrote: > On 2009-11-13, at 15:32, Paul Rubin wrote: >> This is Usenet so >> please stick with Usenet practices. > Er, this is NOT Usenet. Actually it is. I'm posting to comp.lang.python. > 1. I haven't, to the best of my recollection, made a Usenet post in this > millennium. Actually you have, you just didn't know it. > 2. I haven't fired up a copy of rn or any other news reader in at least > 2 decades. > > 3. I'm on the python-list mailing list, reading this with Apple's Mail > application, which actually doesn't have convenient ways of enforcing > `Usenet practices' regarding message format. Nevertheless, the standards for line length for email and Usenet are compatible. > 4. If we're going to adhere to tried-and-true message format rules, I > want my IBM 2260 circa 1970, with its upper-case-only display and weird > little end-of-line symbols. No you don't, you're just taking the piss. > Stephen asked me to wrap my posts. I'm happy to do it. Can we please > finish this thread off and dispose of it? My name is actually Steven, but thank you for wrapping your posts. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:17:24 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:17:24 GMT Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> Message-ID: <030f6eea$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 07:53:05 -0800, Michele Simionato wrote: > I am skeptical about the utility of both rating and comments. If > somebody wants to know > if a package is good, she should ask here. Because unlike people writing comments, people here are never incompetent, misinformed, dishonest, confused, trolling or just wrong. But sometimes sarcastic. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:19:55 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:19:55 GMT Subject: The ol' [[]] * 500 bug... References: Message-ID: <030f6f81$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 21:26:01 +0000, kj wrote: > ...just bit me in the "fuzzy posterior". It's not a bug. Just because it doesn't behave as you would like it to behave doesn't mean it isn't behaving as designed. > The best I can come up with is the hideous > > lol = [[] for _ in xrange(500)] That's not hideous. > Is there something better? What did one do before comprehensions were > available? I suppose in that case one would have to go all the way with > > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] > > Yikes. 10 miles uphill, both ways... What's wrong with that? lol = [] for _ in xrange(500): lol.append([]) is a simple alternative too, although the list comp is better. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:21:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:21:57 GMT Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> Message-ID: <030f6ffb$0$1313$c3e8da3@news.astraweb.com> On Sat, 14 Nov 2009 11:14:04 +0000, kj wrote: > In <7xpr7lixnn.fsf at ruckus.brouhaha.com> Paul Rubin > writes: > >>It seems a little weird to me that they (Google) are concerned with the >>speed of the compiler, indicating that they plan to write enormous >>programs in the language. > > Fast compilation also means that Go can conceivably become an attractive > alternative to interpreted languages, because the compilation stage can > be made as unobtrusive as, say, Python's byte-compilation stage (except > that the Go compiler is generating native code). Python (like many other languages) already has unobtrusive compilation. That's why you get .pyc files, and that's what the compile() built-in function does. It is compilation to byte-code rather than machine-code, but still. Psyco does JIT compilation to machine-code for CPython, at the cost of much extra memory. It's also limited to 32-bit Intel processors. The aim of the PyPy project is to (eventually) make JIT machine-code compilation available to any Python, on any machine. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:29:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:29:44 GMT Subject: Anything better than shutil? References: <19b72d81-210e-40de-a6c4-32b2babec625@k4g2000yqb.googlegroups.com> Message-ID: <030f71ce$0$1313$c3e8da3@news.astraweb.com> On Sat, 14 Nov 2009 07:48:39 -0800, Roy Smith wrote: > I'm converting some old bash scripts to python. There's lots of places > where I'm doing things like "rm $source_dir/*.conf". The best way I can > see to convert this into python is: > > configs = glob.glob(os.path.join(source_dir, '*.conf')) > for conf_file in configs: > shutil.copy(conf_file, conf_dir) > > which is pretty clunky. Particularly since you're converting a remove to a copy... I suppose if you're used to the sort of terse code filled with magic characters that you find in bash, then the Python code might seem a bit verbose. And I suppose you would be right :) But trying to do something complicated in bash rapidly becomes *far* more verbose, unreadable and clunky than Python. > The idea interface I see would be one like: > > shutil.copy([source_dir, '*.conf'], conf_dir) Then write a helper function, and call that. # Untested. def copy(glb, destination): if not isinstance(glb, str): glb = os.path.join(*glb) glb = glob.glob(glb) for source in glb: shutil.copy(source, destination) -- Steven From nagle at animats.com Sat Nov 14 23:41:49 2009 From: nagle at animats.com (John Nagle) Date: Sat, 14 Nov 2009 20:41:49 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> Message-ID: <4aff8413$0$1588$742ec2ed@news.sonic.net> Steven D'Aprano wrote: > On Wed, 11 Nov 2009 16:38:50 -0800, Vincent Manis wrote: > >> I'm having some trouble understanding this thread. My comments aren't >> directed at Terry's or Alain's comments, but at the thread overall. >> >> 1. The statement `Python is slow' doesn't make any sense to me. Python >> is a programming language; it is implementations that have speed or lack >> thereof. > > Of course you are right, but in common usage, "Python" refers to CPython, > and in fact since all the common (and possibly uncommon) implementations > of Python are as slow or slower than CPython, it's not an unreasonable > short-hand. Take a good look at Shed Skin. One guy has been able to build a system that compiles Python to C++, without requiring the user to add "annotations" about types. The system uses type inference to figure it out itself. You give up some flexibility; a variable can have only one primitive type in its life, or it can be a class object. That's enough to simplify the type analysis to the point that most types can be nailed down before the program is run. (Note, though, that the entire program may have to be analyzed as a whole. Separate compilation may not work; you need to see the callers to figure out how to compile the callees.) It's 10 to 60x faster than CPython. It's the implementation, not the language. Just because PyPy was a dud doesn't mean it's impossible. There are Javascript JIT systems far faster than Python. Nor do you really need a JIT system. (Neither does Java; GCC has a hard-code Java compiler. Java is JIT-oriented for historical reasons. Remember browser applets?) If you're doing server-side work, the program's structure and form have usually been fully determined by the time the program begins execution. John Nagle From steve at REMOVE-THIS-cybersource.com.au Sat Nov 14 23:55:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Nov 2009 04:55:51 GMT Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> Message-ID: <030f77ec$0$1313$c3e8da3@news.astraweb.com> On Fri, 13 Nov 2009 14:10:10 -0800, scoopseven wrote: > I actually had a queryset that was dynamically generated, so I ended up > having to use the eval function, like this... > > d = {} > for thing in things: > query_name = 'thing_' + str(thing.id) > query_string = 'Thing.objects.filter(type=' + str(thing.id) + > ').order_by(\'-date\')[:3]' > executable_string = query_name + ' = Thing.objects.filter > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > exec(executable_string) > d[query_name] = eval(query_string) What an unmaintainable mess. If I've understood it, you can make it less crap by (1) getting rid of the unnecessary escaped quotes, (2) avoiding generating the same strings multiple times, and (3) avoiding string concatenation. d = {} for thing in things: expr = "Thing.objects.filter(type=%s).order_by('-date')[:3]" expr = rhs % thing.id name = "thing_%s" % thing.id exec("%s = %s" % (name, expr)) d[name] = eval(expr) What else can we do to fix it? Firstly, why are you creating local variables "thing_XXX" (where XXX is the thing ID) *and* dictionary keys of exactly the same name? I'm sure you don't need the local variables. (If you think you do, you almost certainly don't.) That gets rid of the exec. Next, let's get rid of the eval: d = {} for thing in things: x = thing.id name = "thing_%s" % x d[name] = Thing.objects.filter(type=x).order_by('-date')[:3] About half the size, ten times the speed, and 1000 times the readability. Unless I've missed something, you don't need either exec or eval. -- Steven From michele.simionato at gmail.com Sun Nov 15 00:03:50 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 21:03:50 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> Message-ID: <166b80fe-0c13-4e97-ae47-a0c093f5f897@f16g2000yqm.googlegroups.com> On Nov 14, 7:18?pm, John Nagle wrote: > ? ? ?Leaving out exceptions was a mistake. ?Exceptions are well understood now, > and they're far better than the usual "ignore errors" approach one sees in lamer > C programs. I am also surprised about the lack of exceptions. I could infer that Rob Pike and Ken Thompson are idiots that lack experience with languages with exceptions, or I could infer that they have reasons for doing so. I do not know about exceptions enough to have an opinion myself. However I will notice that in Python, when using threads, exceptions do not work so well: if I forget to trap an exception in a thread I see a traceback on stderr, but the other threads continue to run, basically ignoring the exception. Probably the language that get things right is Erlang, which is supervising all crashed process and it is designed to safely recover for unexpected events. From michele.simionato at gmail.com Sun Nov 15 00:15:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 21:15:11 -0800 (PST) Subject: Python & Go References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Nov 15, 3:00?am, Terry Reedy wrote: > It seems to me that generators are already 'channels' that connect the > calling code to the __next__ method, a semi-coroutine based on the body > of the generator function. At present, the next method waits until an > object is requested. Then it goes into action, yields an object, and > rests again. > > I see no reason why we cannot have that with Python. I not even sure we > cannot have it with CPython, but I am not familiar enough with threads, > processes, and CPython internals. Of course we can have Go capabilities with Python. We already have generators and the multiprocessing module. It is just a matter of performance: I assume the Go implementation is more efficient. It would be nice to have numbers to quantify this claim. One can still write prototypes in Python and convert them in Go and the process looks less cumbersome than converting them in C or C++. I could never force myself to write C or C++; but I do not have any particular resistence to coding in Go, should I need a performance-oriented language. From aahz at pythoncraft.com Sun Nov 15 00:32:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 21:32:51 -0800 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: In article , ssteinerX at gmail.com wrote: >On Nov 9, 2009, at 11:54 AM, Jon Clements wrote: >> On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: >>> First, because as opposed to ch 1 there is quite a bit of code >>> here, and since I'm a >>> Python newbie I may be using non-idiomatic constructs, > >Welp, there goes my last excuse. > >I'm off to write my book: > >Heart Surgery at Home > > *************** >How to Save Thousands and >Get Results Just Like in Hospital > ******** > >Chapter 1: Sanitation, Schmanitation: How Clean is Clean Enough? >Chapter 2: Surgical Tools vs. Ginsu: How Sharp is Sharp Enough? >Chapter 3: Gray's Anatomy and Sharpies: Laying out The Surgery >Chapter 4: Before You Start: Charging Your Cell Phone, and Testing 911 >Chapter 5: Anesthesia: Jack Daniels or Smirnoffs; How Much is Enough? >Chapter 6: The Insanity Defense: Laying the Groundwork with 6 Month Plan > >That's as far as I've gotten... > >Amazon best seller list, here I come! +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From rt8396 at gmail.com Sun Nov 15 00:41:03 2009 From: rt8396 at gmail.com (r) Date: Sat, 14 Nov 2009 21:41:03 -0800 (PST) Subject: Easy way to play single musical notes in Python References: Message-ID: <163ac43b-4d63-4db2-99c7-9b022c2e1f23@m20g2000vbp.googlegroups.com> On Nov 14, 6:21?pm, James Harris wrote: > Is there a simple way to play musical notes in Python? Something like > ? voice.play("c4") Uhh, tksnack is pretty easy to use IMO, see this link... http://www.daniweb.com/code/snippet216655.html No python does not have access to cross platform soundcard capabilities built into the language. I think there is a wrapper for csound somewhere. But there are many 3rd party modules that do have capabilities to some extent. You could make calls to the underlying OS machinery and there is the winsound module (not exactly what you want though). Just look over this Google splooge... http://www.google.com/search?hl=en&rlz=1C1CHMI_enUS340US340&q=Python+sound&aq=f&oq=&aqi=g10 From davea at ieee.org Sun Nov 15 01:22:14 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 15 Nov 2009 01:22:14 -0500 Subject: A different take on finding primes In-Reply-To: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: <4AFF9E16.506@ieee.org> Vincent Davis wrote: > Out of pure curiosity I would like to compare the efficiency of different > methods of finding primes (need not be consecutive). Let me be clear, given > 2min, how many primes can you find, they need not be in order or > consecutive. I have not seen any examples of this. I am assume the solution > is different depending on the time give, 2min or 2 hours. I assume a sieve > solution would be best for larger times. When the numbers get really large > checking to see if they are a prime gets costly. > So what do you think? > > *Vincent Davis > 720-301-3003 * > vincent at vincentdavis.net > my blog | > LinkedIn > > The sieve can be very efficiently written, but you have to decide whether to optimize for memory size or for speed. At a minimum for size you need an object for each prime currently found, and you will be looking through that list for each new candidate. Incidentally this approach can be done without any division. If you have memory to burn, you make a bit array equal in size to the largest prime you expect to encounter. There are also good algorithms for deciding whether a number of a particular form is prime. For example, there's a test for numbers of the form 2**n + 1. And don't forget the Miller-Rabin test. DaveA From aahz at pythoncraft.com Sun Nov 15 01:22:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:22:30 -0800 Subject: Python as network protocol References: Message-ID: In article , Cooch wrote: > >I want to implement such specific feature: >I have a server written in Python. I have a client written in C++. I >want to use Python as network protocol between them. I mean: client >send to server such string: "a = MyObject()", so object of this type >will appear in server. Any ideas how to simplify this implementation? >I make XML-RPC/SOAP server using twisted which just execute sended >string. But I don't know how to: >1. Restrict usage of some modules on client side (os, sys etc..) >2. Divide variables of different clients. Generally, I know that I >should use "exec .. in .. " construct, but don't know how to >distinguish between clients in twisted. What you want is a DSL -- domain-specific language. That might be a subset of Python that you parse yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From michele.simionato at gmail.com Sun Nov 15 01:24:01 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sat, 14 Nov 2009 22:24:01 -0800 (PST) Subject: Python & Go References: <422a4ad2-b6a9-45ed-9adb-a09ec1d628ac@m16g2000yqc.googlegroups.com> <4afef1f5$0$1586$742ec2ed@news.sonic.net> <166b80fe-0c13-4e97-ae47-a0c093f5f897@f16g2000yqm.googlegroups.com> Message-ID: <6b0a2e86-49ec-4756-bcec-f658a0890edd@j4g2000yqe.googlegroups.com> Let me add a quote from the FAQ: """ Why does Go not have exceptions? Exceptions are a similar story. A number of designs for exceptions have been proposed but each adds significant complexity to the language and run-time. By their very nature, exceptions span functions and perhaps even goroutines; they have wide-ranging implications. There is also concern about the effect they would have on the libraries. They are, by definition, exceptional yet experience with other languages that support them show they have profound effect on library and interface specification. It would be nice to find a design that allows them to be truly exceptional without encouraging common errors to turn into special control flow that requires every programmer to compensate. Like generics, exceptions remain an open issue. """ From aahz at pythoncraft.com Sun Nov 15 01:25:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:25:34 -0800 Subject: A "terminators' club" for clp References: <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> <877htsskox.fsf@benfinney.id.au> Message-ID: In article <877htsskox.fsf at benfinney.id.au>, Ben Finney wrote: >Terry Reedy writes: >> >> So, the only reason to use c.l.p is if one wants to post anonymously, >> like the spammers do ;-). > >Or if one has an ISP who provides a Usenet feed, like mine does. Mine does, too. >A pox upon Andrew Cuomo for bashing ISPs in the USA with the stick of >???child pornography??? (which he discovered on 88 out of many thousands of >forums). Faced with the unreasonable role of policing Usenet, they shut >it all off . Actually, my ISP is in New York City. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From joost at h-labahn.de Sun Nov 15 01:25:38 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 14 Nov 2009 22:25:38 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> Message-ID: <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> Thanks ! Okay, i've already used the call of tp_free as the last statement in tp_dealloc and do understand now, that a call of tp_dealloc should be the last statement in the code for tp_free in specific cases. And yes, "Py_Type(&Foo_Type) = &PyType_Type" will be more stable against changes of the object implementation. Still there remains the difference to what is told with the Noddy_Type in the tutorial. Skimmimg through PyType_Ready in typeobject.c i find, that 3760 if (Py_TYPE(type) == NULL && base != NULL) 3761 Py_TYPE(type) = Py_TYPE(base); are the only lines referring to what is ob_type now. Thus the quoted lines from the tutorial ending with "Fortunately, this member will be filled in for us by PyType_Ready()." are possibly wrong (respective outdated) too. The two lines above are, what happens to my extension classes, if i want to derive application classes from them. class(my_extension_class): ... will of course call more from Python than PyTypeReady, but PyType(type) = Py_TYPE(base) is not getting corrected by this "more" here and the class statement doesn't create a new type. I will examine now, why this happens (without a crash of the calling application !), but still welcome every hint. Seen from a strict perspective this is a bug in Python's C-API. I'll save a freeze of the code for my extension for anyone, who might interested to reproduce this. Joost From aahz at pythoncraft.com Sun Nov 15 01:26:46 2009 From: aahz at pythoncraft.com (Aahz) Date: 14 Nov 2009 22:26:46 -0800 Subject: A "terminators' club" for clp References: <7xiqddt1fd.fsf@ruckus.brouhaha.com> Message-ID: In article <7xiqddt1fd.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >There is automatic moderation software that auto-approves any post >from an address that has had one or two posts manually approved. >While that's susceptible to address forgery, the typical spammer >doesn't do that. There's even auto-mod with e-mail confirmation (similar to subscribing to a mailing list), see soc.singles.moderated. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From rami.chowdhury at gmail.com Sun Nov 15 01:46:12 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 14 Nov 2009 22:46:12 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> References: <4B7842AB-DC38-415B-83B6-4E403CFD0A19@telus.net> Message-ID: <200911142246.12411.rami.chowdhury@gmail.com> On Saturday 14 November 2009 18:42:07 Vincent Manis wrote: > > 3. Very clearly CPython can be improved. I don't take most benchmarks > very seriously, but we know that CPython interprets bytecode, and > thus suffers relative to systems that compile into native code, and > likely to some other interpretative systems. (Lua has been > mentioned, and I recall looking at a presentation by the Lua guys on > why they chose a register rather than stack-based approach.) > For those interested in exploring the possible performance benefits of Python on a register-based VM, there's Pynie (http://code.google.com/p/pynie/)... and there's even a JIT in the works for that (http://docs.parrot.org/parrot/1.0.0/html/docs/jit.pod.html)... ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From tjreedy at udel.edu Sun Nov 15 01:53:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 01:53:06 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <4aff8413$0$1588$742ec2ed@news.sonic.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Steven D'Aprano wrote: > > Take a good look at Shed Skin. One guy has been able to build a system > that compiles Python to C++, without requiring the user to add > "annotations" about types. In *only* compiles a subset of Python, as does Cython. Both cannot (currently) do generators, but that can be done and probably will eventually at least for Cython. Much as I love them, they can be rewritten by hand as iterator classes and even then are not needed for a lot of computational code. I think both are good pieces of work so far. > The system uses type inference to figure it out itself. > You give up some flexibility; a variable can have only one primitive type > in its life, or it can be a class object. That's enough to simplify the > type analysis to the point that most types can be nailed down before the > program is run. (Note, though, that the entire program may have to > be analyzed as a whole. Separate compilation may not work; you need > to see the callers to figure out how to compile the callees.) > > It's 10 to 60x faster than CPython. > > It's the implementation, not the language. Just because PyPy was a > dud doesn't mean it's impossible. There are Javascript JIT systems > far faster than Python. > > Nor do you really need a JIT system. (Neither does Java; GCC has > a hard-code Java compiler. Java is JIT-oriented for historical reasons. > Remember browser applets?) If you're doing server-side work, the > program's structure and form have usually been fully determined by > the time the program begins execution. > > John Nagle From lusvehla at gmail.com Sun Nov 15 02:20:35 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Sat, 14 Nov 2009 23:20:35 -0800 (PST) Subject: Calling Python functions from Excel Message-ID: Hi, unfortunately is my question about server COM (win32com) http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# without answer. Please I need Calling Python functions from Excel and receive result back in Excel. Can me somebody advise simplest solution please? I am more VBA programmer than Python. Thanks From greg at cosc.canterbury.ac.nz Sun Nov 15 02:25:39 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 15 Nov 2009 20:25:39 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: <4aff8413$0$1588$742ec2ed@news.sonic.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> Message-ID: <7m9oo1F3f2dcmU1@mid.individual.net> John Nagle wrote: > Take a good look at Shed Skin. ... > You give up some flexibility; a variable can have only one primitive type > in its life, or it can be a class object. That's enough to simplify the > type analysis to the point that most types can be nailed down before the > program is run. These restrictions mean that it isn't really quite Python, though. -- Greg From carsten.haese at gmail.com Sun Nov 15 02:53:49 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sun, 15 Nov 2009 02:53:49 -0500 Subject: Calling Python functions from Excel In-Reply-To: References: Message-ID: Cannonbiker wrote: > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. Maybe this will help: http://oreilly.com/catalog/pythonwin32/chapter/ch12.html (Scroll down to "Implementing a COM Server.") -- Carsten Haese http://informixdb.sourceforge.net From michele.simionato at gmail.com Sun Nov 15 03:12:44 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 15 Nov 2009 00:12:44 -0800 (PST) Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> Message-ID: <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> On Nov 15, 5:17?am, Steven D'Aprano wrote: > On Fri, 13 Nov 2009 07:53:05 -0800, Michele Simionato wrote: > > I am skeptical about the utility of both rating and comments. If > > somebody wants to know > > if a package is good, she should ask here. > > Because unlike people writing comments, people here are never > incompetent, misinformed, dishonest, confused, trolling or just wrong. > > But sometimes sarcastic. > > -- > Steven All right, but the newsgroup has interactivity and the presence of true Python experts too. A blind vote given by an anonymous person does not look more informative to me. From tjreedy at udel.edu Sun Nov 15 03:30:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 03:30:55 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <7m9oo1F3f2dcmU1@mid.individual.net> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> Message-ID: greg wrote: > John Nagle wrote: >> Take a good look at Shed Skin. ... >> You give up some flexibility; a variable can have only one primitive type >> in its life, or it can be a class object. That's enough to simplify the >> type analysis to the point that most types can be nailed down before the >> program is run. > > These restrictions mean that it isn't really quite > Python, though. Python code that only uses a subset of features very much *is* Python code. The author of ShedSkin makes no claim that is compiles all Python code. From fetchinson at googlemail.com Sun Nov 15 04:21:35 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 15 Nov 2009 10:21:35 +0100 Subject: Vote on PyPI comments In-Reply-To: <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> Message-ID: >> > I am skeptical about the utility of both rating and comments. If >> > somebody wants to know >> > if a package is good, she should ask here. >> >> Because unlike people writing comments, people here are never >> incompetent, misinformed, dishonest, confused, trolling or just wrong. >> >> But sometimes sarcastic. >> > > All right, but the newsgroup has interactivity and the presence of > true Python experts too. > A blind vote given by an anonymous person does not look more > informative to me. You are right about a single vote, but the way these things usually work is that out of 1000 votes the non-informative ones average out ("wow! awsome package!" vs "this sucks bad!") and the net vote result is generally indicative of the actual thing that was voted on especially when there is no direct financial incentive to cheat. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Nov 15 04:59:53 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 15 Nov 2009 09:59:53 +0000 (UTC) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> Message-ID: Santiago Romero wrote: >> Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do >> not remember the CPU freqeuncy anymore, maybe 25MHz). > > Yes, in ASM a simple 25 or 33Mhz 386 computer was able to emulate > the > Spectrum. At least, under MSDOS, like did Warajevo, Z80, x128 and > "Spectrum" > from Pedro Gimeno. And my very own, (sadly, rather little known at the time) 'Nuclear ZX' :-) It did not use a dispatch table - rather, each Z80 instruction was taken as a high byte of the pointer to a 64KB block of 8086 code, low byte being zero for unprefixed instructions or a given value for prefixed ones. This approach saved one lookup (several cycles) and one indirect jump (another several cycles) per instruction. Another optimization would be to unroll the return jump from each of the emulated instructions and replace it directly with inline read-the-next-instruction-and-jump-there code, but I never got around to that (would save one 8086 jump per one Z80 instruction :-)) >> http://perl-spectrum.sourceforge.net/ >> >> It is quite fast IMHO. > > It does not run 100% in my 1.8Ghz centrino computer :-(, but almost. > At least, is a good start to see that is possible, at least no current > DualCore computers :-) Python IS slower than perl, especially since you are dealing with objects. However, I'd suggest go the cPickle route - have a Z80Cpu module, and its C equivalent, cZ80, and use that one if available. This way, the emulator will be actually usable everywhere. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From tartley at tartley.com Sun Nov 15 05:56:29 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Sun, 15 Nov 2009 02:56:29 -0800 (PST) Subject: Vote on PyPI comments References: <9443026d-7cd6-4991-90d5-886f04f1e1aa@b15g2000yqd.googlegroups.com> <030f6eea$0$1313$c3e8da3@news.astraweb.com> <70b1fa2d-1047-4604-990a-afb1d962f73a@n35g2000yqm.googlegroups.com> Message-ID: <153f9f72-342c-4a3f-9105-2a4596bd12d3@w19g2000yqk.googlegroups.com> On Nov 15, 9:21?am, Daniel Fetchinson wrote: > >> > I am skeptical about the utility of both rating and comments. If > >> > somebody wants to know > >> > if a package is good, she should ask here. > > >> Because unlike people writing comments, people here are never > >> incompetent, misinformed, dishonest, confused, trolling or just wrong. > > >> But sometimes sarcastic. > > > All right, but the newsgroup has interactivity and the presence of > > true Python experts too. > > A blind vote given by an anonymous person does not look more > > informative to me. > > You are right about a single vote, but the way these things usually > work is that out of 1000 votes the non-informative ones average out > ("wow! awsome package!" vs "this sucks bad!") and the net vote result > is generally indicative of the actual thing that was voted on > especially when there is no direct financial incentive to cheat. > > Cheers, > Daniel > > -- > Psss, psss, put it down! -http://www.cafepress.com/putitdown I haven't used the PyPI rating / comments system at all. Can comments accrue which complain about bugs or missing features of old versions of the package? If so, they could be misleading for users coming to view a package before trying it. Or do comments and ratings only apply to a particular version of a package, and get removed from the package's 'front page' every time a new version is released? Thanks, Jonathan Hartley From sromero at gmail.com Sun Nov 15 06:17:08 2009 From: sromero at gmail.com (Santiago Romero) Date: Sun, 15 Nov 2009 03:17:08 -0800 (PST) Subject: #define (from C) in Python References: <6fd01230-5e35-4f86-bc2a-69219783c0b9@r5g2000yqb.googlegroups.com> <4afc42d2$0$6590$9b4e6d93@newsspool3.arcor-online.net> <2qivs6-v5e.ln1@satorlaser.homedns.org> <3af7a5b4-b2ed-43f0-8fe6-e2d96d54a06d@p8g2000yqb.googlegroups.com> <0ce690b6-96ef-4e7b-ad9b-db27f5b66b34@d5g2000yqm.googlegroups.com> Message-ID: > Python IS slower than perl, especially since you are dealing with > objects. However, I'd suggest go the cPickle route - have a Z80Cpu > module, and its C equivalent, cZ80, and use that one if available. This > way, the emulator will be actually usable everywhere. Thanks for the advice but ... my (currently working) emulator is already written in C, I don't see the point of calling it from a python module. I had 2 options: port the emulator from C+Allegro to C +SDL or port it to Python+Pygame+SDL... And the fun is trying to write it in pure python with pygame, without external C :-) I'll do a quick test, if I see that I can't achieve 100% speed in my other computer (DualCore2 1.82Ghz, the basic-standard-minimum computer nowadays), then I'll give up, but at least I want to try it X-D Today or tomorrow I'm finishing the pyinliner.py preprocessor X-D. I'll paste the results here :-) Thanks for your answer :-) From vicente.soler at gmail.com Sun Nov 15 06:59:29 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 15 Nov 2009 03:59:29 -0800 (PST) Subject: Changing the current directory Message-ID: <68faefbe-f1a8-4358-b65d-c9f0d562f7ff@r5g2000yqb.googlegroups.com> Ever since I installed my Python 2.6 interpreter, I've been saving my *.py files in the C:\Program Files\Python26 directory, which is the default directory for such files in my system. However, I have realised that the above is not the best practice. Therefore I created the C:\Program Files\Python26\test directory and I want it to be my default directory for saving *.py files, importing modules, etc. I'd like to do something like the DOS equivalent of "CD test" but I do not know kow to do it. I am currently doing something really awful: I open a *.py file in the est subdirectory, I run it with the F5 key and it works! but I am doing really something stupid. I can see that it works because if I do From nobody at nowhere.com Sun Nov 15 07:01:53 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 12:01:53 +0000 Subject: More Python versions on an XP machine References: Message-ID: On Sat, 14 Nov 2009 14:45:48 +0100, Gabor Urban wrote: > this a very MS specific question. I do use a rather old Python > version, because we have a couple of applications written for that. > Porting them to a newer Python is not allowed by the bosses. Now we > will start a new project with latest stable Python. Can I have them > both on my computer, and how should I do that. You can have multiple versions, but you can only associate one specific version with the ".py" suffix. This matters if you need to be able to execute .py files as if they were executables, e.g. double-clicking on the script in Explorer or typing the script's name in the command prompt. You can run scripts which use other versions of Python by specifying the interpreter explicitly, e.g.: "C:\Program Files\Python25\python.exe" "C:\Program Files\MyApp\myscript.py" From vicente.soler at gmail.com Sun Nov 15 07:04:06 2009 From: vicente.soler at gmail.com (vsoler) Date: Sun, 15 Nov 2009 04:04:06 -0800 (PST) Subject: Changing the current directory (full post) Message-ID: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Oops!!! something went wrong with my keyboard. Here you have my full post: Ever since I installed my Python 2.6 interpreter (I use IDLE), I've been saving my *.py files in the C:\Program Files\Python26 directory, which is the default directory for such files in my system. However, I have realised that the above is not the best practice. Therefore I created the C:\Program Files\Python26\test directory and I want it to be my default directory for saving *.py files, importing modules, etc. I'd like to do something like the DOS equivalent of "CD test" but I do not know kow to do it. I am currently doing something really awful: I open a *.py file in the test subdirectory, I run it with the F5 key and it works! but I am doing really something stupid. I can see that it works because if I do import sys sys.path ... the first directory in the list is the test one. How should I proceed, if I want to proceed properly? Vicente Soler From nobody at nowhere.com Sun Nov 15 07:06:48 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 12:06:48 +0000 Subject: How to know if a file is a text file References: Message-ID: On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote: > I'm looking for a way to be able to load a generic file from the > system and understand if he is plain text. > The mimetype module has some nice methods, but for example it's not > working for file without extension. > > Any suggestion? You could use the "file" command. It's normally installed by default on Unix systems, but you can get a Windows version from: http://gnuwin32.sourceforge.net/packages/file.htm From clp2 at rebertia.com Sun Nov 15 07:34:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 Nov 2009 04:34:10 -0800 Subject: How to know if a file is a text file In-Reply-To: References: Message-ID: <50697b2c0911150434n33c1c7cdud346f3dd9a88ea97@mail.gmail.com> On Sun, Nov 15, 2009 at 4:06 AM, Nobody wrote: > On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote: > >> I'm looking for a way to be able to load a generic file from the >> system and understand if he is plain text. >> The mimetype module has some nice methods, but for example it's not >> working for file without extension. >> >> Any suggestion? > > You could use the "file" command. It's normally installed by default on > Unix systems, but you can get a Windows version from: FWIW, IIRC the heuristic `file` uses to check whether a file is text or not is whether it contains any null bytes; if it does, it classifies it as binary (i.e. not text). Cheers, Chris -- http://blog.rebertia.com From sungsuha at gmail.com Sun Nov 15 07:40:00 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 04:40:00 -0800 (PST) Subject: basic class question.. Message-ID: class rawDNA: import string trans = string.maketrans("GATC","CTAG") def __init__(self, template = "GATTACA"): self.template = template //shouldn't this make "template" accessible within the scope of "rawDNA"?? def noncoding(self): print template.translate(trans) // >>>test = rawDNA() >>>test.noncoding() Traceback (most recent call last): File "", line 1, in test.noncoding() File "", line 7, in noncoding print template.translate(trans) NameError: global name 'template' is not defined I'm curious .. what am I doing wrong?? P.S class rawDNA: import string trans = string.maketrans("GATC","CTAG") def __init__(self, template = "GATTACA"): self.template = template def noncoding(self): print self.template.translate(trans) this works as intended. Thanks in advance From lucafbb at gmail.com Sun Nov 15 07:49:54 2009 From: lucafbb at gmail.com (Luca) Date: Sun, 15 Nov 2009 13:49:54 +0100 Subject: How to know if a file is a text file In-Reply-To: References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: <27308d500911150449g2c3f375anc73ed7ad88f92a02@mail.gmail.com> On Sat, Nov 14, 2009 at 6:51 PM, Philip Semanchuk wrote: > Hi Luca, > You have to define what you mean by "text" file. It might seem obvious, but > it's not. > > Do you mean just ASCII text? Or will you accept Unicode too? Unicode text > can be more difficult to detect because you have to guess the file's > encoding (unless it has a BOM; most don't). > > And do you need to verify that every single byte in the file is "text"? What > if the file is 1GB, do you still want to examine every single byte? > > If you give us your own (specific!) definition of what "text" means, or > perhaps a description of the problem you're trying to solve, then maybe we > can help you better. > Thanks all. I was quite sure that this is not a very simple task. Right now search only inside ASCII encode is not enough for me (my native language is outside this encode :-) Checking every single byte can be a good solution... I can start using the mimetype module and, if the file has no extension, check byte one by one (commonly) as "file" command does. Better: I can check use the "file" command if available. Again: thanks all! -- -- luca From deets at nospam.web.de Sun Nov 15 07:52:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 13:52:55 +0100 Subject: basic class question.. In-Reply-To: References: Message-ID: <7mabt8F3gdudpU1@mid.uni-berlin.de> Pyrot schrieb: > class rawDNA: > import string Importing here is unusual. Unless you have good reasons to do so, I suggest you put the imports on top of the file. > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > self.template = template //shouldn't this make "template" > accessible within the scope of "rawDNA"?? No. > > > def noncoding(self): > print template.translate(trans) // This needs to be print self.template.translate(trans) Thes scopes insied a class are only the method-locals (to which the parameters count of course), and globals. Diez From highcar at gmail.com Sun Nov 15 08:08:31 2009 From: highcar at gmail.com (elca) Date: Sun, 15 Nov 2009 05:08:31 -0800 (PST) Subject: python win32com problem Message-ID: <26358976.post@talk.nabble.com> hello , these day im very stress of one of some strange thing. i want to enumurate inside list of url, and every enumurated url i want to visit i was uplod incompleted script source in here => http://elca.pastebin.com/m6f911584 if anyone can help me really appreciate thanks in advance Paul -- View this message in context: http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html Sent from the Python - python-list mailing list archive at Nabble.com. From python.list at tim.thechases.com Sun Nov 15 08:15:28 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 15 Nov 2009 07:15:28 -0600 Subject: basic class question.. In-Reply-To: References: Message-ID: <4AFFFEF0.1000900@tim.thechases.com> Pyrot wrote: > class rawDNA: > import string > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > self.template = template //shouldn't this make "template" > accessible within the scope of "rawDNA"?? No. Python's scope resolution consists only of "local, global, or explicit". There is no "try to find this in the instance or class" scope-resolution guessing. Your code makes "template" accessible within the scope of "self", not in a global unqualified scope. So this: > def noncoding(self): > print template.translate(trans) // tries to reference "template" first in the local scope (within noncoding(), but it doesn't exist there), then in the global scope (it also doesn't exist there), and stops. It should be as you have it here: > class rawDNA: > import string > trans = string.maketrans("GATC","CTAG") > def __init__(self, template = "GATTACA"): > self.template = template > def noncoding(self): > print self.template.translate(trans) Here, you start with "self" which *is* in the local scope, which *does* contain "template" and so it successfully finds it and all is [qualifiedly] good. However, you'll also find that "trans" isn't found because it's neither in the local nor global scope: >>> class RawDNA: ... import string ... trans = string.maketrans("GATC", "CTAG") ... def __init__(self, template="GATTACA"): ... self.template = template ... def noncoding(self): ... print self.template.translate(trans) ... >>> r = RawDNA() >>> r.noncoding() Traceback (most recent call last): File "", line 1, in File "", line 7, in noncoding NameError: global name 'trans' is not defined so you need to fully qualify it as "RawDNA.trans" for Python to find it. (I also shifted to using the PEP-8 naming convention "RawDNA" instead of "rawDNA"). Which you indeed discovered: > this works as intended. Being explicit is part of "Python Zen" (from the python command-prompt, type "import this" to see the whole list) -tkc From deets at nospam.web.de Sun Nov 15 09:20:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 15:20:49 +0100 Subject: basic class question.. In-Reply-To: <7mabt8F3gdudpU1@mid.uni-berlin.de> References: <7mabt8F3gdudpU1@mid.uni-berlin.de> Message-ID: <7mah21F3fopovU1@mid.uni-berlin.de> Diez B. Roggisch schrieb: > Pyrot schrieb: >> class rawDNA: >> import string > > Importing here is unusual. Unless you have good reasons to do so, I > suggest you put the imports on top of the file. > >> trans = string.maketrans("GATC","CTAG") >> >> >> def __init__(self, template = "GATTACA"): >> self.template = template //shouldn't this make "template" >> accessible within the scope of "rawDNA"?? > > No. >> >> >> def noncoding(self): >> print template.translate(trans) // > > This needs to be > > print self.template.translate(trans) Ah, sorry, that should have been self.template.translate(self.trans) Diez From mrholtsr at gmail.com Sun Nov 15 09:30:50 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Sun, 15 Nov 2009 06:30:50 -0800 (PST) Subject: Code for finding the 1000th prime Message-ID: I am absolutely new to python and barely past beginner in programming. Also I am not a mathematician. Can some one give me pointers for finding the 1000th. prime for a course I am taking over the internet on Introduction to Computer Science and Programming. Thanks, Ray From rpjday at crashcourse.ca Sun Nov 15 09:44:43 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Sun, 15 Nov 2009 09:44:43 -0500 (EST) Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: On Sun, 15 Nov 2009, mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray it's 7919. rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From deets at nospam.web.de Sun Nov 15 10:02:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 16:02:09 +0100 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <7majfhF2j43tpU1@mid.uni-berlin.de> mrholtsr schrieb: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray Do you really think we are so retarded that we don't remember you posted the same question a week ago? Diez From loftusoft at yahoo.com Sun Nov 15 10:13:41 2009 From: loftusoft at yahoo.com (Mike) Date: Sun, 15 Nov 2009 07:13:41 -0800 (PST) Subject: Stagnant Frame Data? Message-ID: I'll apologize first for this somewhat lengthy example. It does however recreate the problem I've run into. This is stripped-down code from a much more meaningful system. I have two example classes, "AutoChecker" and "Snapshot" that evaluate variables in their caller's namespace using the frame stack. As written, the output is not what is expected: the variables evaluate to "stagnant" values. However, if the one indicated line is uncommented, then the result is as expected. So my questions are: Is this a bug in Python? Is this an invalid use of frame data? Why does the single line "sys._getframe(1).f_locals" fix the behavior? Thanks, Mike import sys class Snapshot(object): def __init__(self, caller_globals, caller_locals): self.signals = [] self.caller_globals = caller_globals self.caller_locals = caller_locals def get_values(self): samples = {} for signal in self.signals: samples[signal] = eval(signal, self.caller_globals, self.caller_locals) return samples def print_values(self): print 'snapshot data' for name, value in self.get_values().items(): print '\t', name, '=', value class AutoChecker(object): def __init__(self, statement): self.statement = statement self.caller_globals = sys._getframe(1).f_globals self.caller_locals = sys._getframe(1).f_locals self.snapshot = Snapshot(self.caller_globals, self.caller_locals) self.snapshot_history = [] def check(self): # uncomment following line to get expected behavior #sys._getframe(1).f_locals if eval(self.statement, self.caller_globals, self.caller_locals) == False: print self.statement, 'failed' self.snapshot.print_values() self.snapshot_history.append(self.snapshot.get_values()) def report(self): if len(self.snapshot_history): return print 'snapshot history' for samples in self.snapshot_history: for name, value in samples.items(): print '\t', name, '=', value def f(): x = 0.0 y = 0.0 ac1 = AutoChecker('x < 2.0') ac1.snapshot.signals.append('x') ac1.snapshot.signals.append('y') for i in range(5): x = i / 2.0 y = x / 2 print i, x ac1.check() ac1.snapshot.print_values() ac1.report() From joncle at googlemail.com Sun Nov 15 10:36:25 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 07:36:25 -0800 (PST) Subject: python win32com problem References: Message-ID: On Nov 15, 1:08?pm, elca wrote: > hello , these day im very stress of one of some strange thing. > > i want to enumurate inside list of url, and every enumurated url i want to > visit > > i was uplod incompleted script source in here => > > http://elca.pastebin.com/m6f911584 > > if anyone can help me really appreciate > > thanks in advance > > Paul > > -- > View this message in context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html > Sent from the Python - python-list mailing list archive at Nabble.com. How much effort have you put into this? It looks like you've just whacked together code (that isn't valid -- where'd the magical 'buttons' variable come from), given up and cried for help. Besides, I would suggest you're taking completely the wrong route. You'll find it one hell of a challenge to automate a browser as you want, that's if it supports exposing the DOM anyway. And without being rude, would definitely be beyond your abilities from your posts to c.l.p. Download and install BeautifulSoup from http://www.crummy.com/software/BeautifulSoup/ - you seem to have quite a few HTML based needs in your pastebin, so it'll come in useful for the future. Here's a snippet to get you started: from urllib2 import urlopen from BeautifulSoup import BeautifulSoup as BS url = urlopen('http://news.naver.com/main/presscenter/category.nhn') urldata = url.read() soup = BS(urldata) atags = soup('a', attrs={'href': lambda L: L and L.startswith('http:// news.khan.co.kr')}) for atag in atags: print atag['href'] I'll leave it to you where you want to go from there (ie, follow the links, or automate IE to open said pages etc...) I strongly suggest reading the urllib2 and BeautifulSoup docs, and documenting the above code snippet -- you should then understand it, should be less stressed, and have something to refer to for similar requirements in the future. hth, Jon. From __peter__ at web.de Sun Nov 15 11:00:17 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Nov 2009 17:00:17 +0100 Subject: Stagnant Frame Data? References: Message-ID: Mike wrote: > I'll apologize first for this somewhat lengthy example. It does > however recreate the problem I've run into. This is stripped-down code > from a much more meaningful system. > > I have two example classes, "AutoChecker" and "Snapshot" that evaluate > variables in their caller's namespace using the frame stack. As > written, the output is not what is expected: the variables evaluate to > "stagnant" values. > > However, if the one indicated line is uncommented, then the result is > as expected. > > So my questions are: Is this a bug in Python? Is this an invalid use > of frame data? Why does the single line "sys._getframe(1).f_locals" > fix the behavior? A simplified demonstration of your problem: >>> def f(update): ... a = locals() ... x = 42 ... if update: locals() ... print a ... >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} The local namespace is not a dictionary, and the locals()/f_locals dictionary contains a snapshot of the local namespace. Accessing the f_locals attribute is one way to trigger an update of that snapshot. What's puzzling is that the same dictionary is reused. Peter From news at schwertberger.de Sun Nov 15 11:05:54 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 15 Nov 2009 17:05:54 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> Message-ID: <7man75F3gh0lgU1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 19:02, Dietmar Schwertberger wrote: >> I tried 3.01.63. >> I can see in the Python window already that the code is not correct. > > 3.01.63 > > Did you remember to install the wxAdditions? No. I think that they should not be required (a minimal version seems to be included in wxFormBuilder) and I don't get any error message. Also using wxAdditions for wx Python doesn't seem to be straightforward. > Could you send me an .fbp file demonstrating the error? Sent by email. Did you receive it? Regards, Dietmar From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:08:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:08:23 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > I'm attempting to convert latitude and longitude coordinates from degrees > minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this > conversion? Should be: decimal = degrees + minutes/60.0 + seconds/3600.0 N,E are positive; S,W are negative. But the above numbers don't match. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:08:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:08:23 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > I'm attempting to convert latitude and longitude coordinates from degrees > minutes and second to decimal form. I would like to go from: > N39 42 36.3 W77 42 51.5 > to: > -77.739855,39.706666 > > Does anyone know of a library or some existing out their to help with > this > conversion? Should be: decimal = degrees + minutes/60.0 + seconds/3600.0 N,E are positive; S,W are negative. But the above numbers don't match. -- Gabriel Genellina From exarkun at twistedmatrix.com Sun Nov 15 11:19:19 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 15 Nov 2009 16:19:19 -0000 Subject: Stagnant Frame Data? In-Reply-To: References: Message-ID: <20091115161919.27565.1296418538.divmod.xquotient.167@localhost.localdomain> On 04:00 pm, __peter__ at web.de wrote: >Mike wrote: >>I'll apologize first for this somewhat lengthy example. It does >>however recreate the problem I've run into. This is stripped-down code >>from a much more meaningful system. >> >>I have two example classes, "AutoChecker" and "Snapshot" that evaluate >>variables in their caller's namespace using the frame stack. As >>written, the output is not what is expected: the variables evaluate to >>"stagnant" values. >> >>However, if the one indicated line is uncommented, then the result is >>as expected. >> >>So my questions are: Is this a bug in Python? Is this an invalid use >>of frame data? Why does the single line "sys._getframe(1).f_locals" >>fix the behavior? > >A simplified demonstration of your problem: >>>>def f(update): >... a = locals() >... x = 42 >... if update: locals() >... print a >... >>>>f(False) >{'update': False} >>>>f(True) >{'a': {...}, 'x': 42, 'update': True} > >The local namespace is not a dictionary, and the locals()/f_locals >dictionary contains a snapshot of the local namespace. Accessing the >f_locals attribute is one way to trigger an update of that snapshot. > >What's puzzling is that the same dictionary is reused. http://bugs.python.org/issue6116 is vaguely related. Jean-Paul From ecir.hana at gmail.com Sun Nov 15 11:28:07 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Sun, 15 Nov 2009 08:28:07 -0800 (PST) Subject: Redirect stdout to a buffer Message-ID: Hello, I'm trying to write a simple Win32 app, which may run some Python scripts. Since it is a Windows GUI app, I would like to redirect all output (Python print, C printf, fprinf stderr, ...) to a text area inside the app. In other words, I'm trying to log all the output from the app (C, Python) to a window. So far, this works for C printf(): int fds[2]; _pipe(fds, 1024, O_TEXT); _dup2(fds[1], 1); ... and then I read from pipe's read-end and append the text to the text area. But when I try to run: Py_Initialize(); PyRun_SimpleString("print 'abc'"); Py_Finalize(); I get an error: IOError: [Errno 9] Bad file descriptor What am I doing wrong? How to redirect standard IO, both for C and for Python? PS: Maybe I'm doind something wrong, but SetStdHandle() does not work at all.... From gagsl-py2 at yahoo.com.ar Sun Nov 15 11:32:01 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 13:32:01 -0300 Subject: __import__ returns module without it's attributes? References: <333edbe80911131527o998fcbbp5dc48777632956b5@mail.gmail.com> Message-ID: En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns escribi?: > I've overloaded __import__ to modify modules after they are > imported... but running dir(module) on the result only returns > __builtins__, __doc__, __file__, > __name__, __package__, and __path__. > > Why is this? More importantly, where can I hook in that would allow me > to see the contents of the module? Post some code. This works for me: py> import __builtin__ py> builtin_import = __builtin__.__import__ py> def __import__(*args): ... module = builtin_import(*args) ... module.__signature__ = "kilroywashere" ... return module ... py> __builtin__.__import__ = __import__ py> py> import htmllib py> dir(htmllib) ['AS_IS', 'HTMLParseError', 'HTMLParser', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__signature__', 'sgmllib', 'test'] py> htmllib.__signature__ 'kilroywashere' -- Gabriel Genellina From pengyu.ut at gmail.com Sun Nov 15 12:09:05 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 15 Nov 2009 09:09:05 -0800 (PST) Subject: IDE for python Message-ID: There had been some discussion on IDE. But I'm not sure what pros and cons of each choice. Current, I'm using vim and ctags. Could somebody give some advices on choosing the best IDE for me? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gst&q=IDE#e934bd5b9f2d0f8c From deets at nospam.web.de Sun Nov 15 12:15:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 18:15:16 +0100 Subject: IDE for python In-Reply-To: References: Message-ID: <7mar95F3g85n0U1@mid.uni-berlin.de> Peng Yu schrieb: > There had been some discussion on IDE. But I'm not sure what pros and > cons of each choice. Current, I'm using vim and ctags. > > Could somebody give some advices on choosing the best IDE for me? > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gst&q=IDE#e934bd5b9f2d0f8c I suggest you use your google foo that you just showed to search in this group for the numerous discussions about emacs, vi, eclipse+pydev, wing ide, komodo and notepad. Diez From phlip2005 at gmail.com Sun Nov 15 12:16:11 2009 From: phlip2005 at gmail.com (Phlip) Date: Sun, 15 Nov 2009 09:16:11 -0800 (PST) Subject: How can pip install a GitHub code drop? Message-ID: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> Not Hyp: Suppose I have a Python library, complete with a respectable setup.py. How can I point pip at the repo to install the library? if I use this... sudo pip -e git+git://github.com/Phlip/Kozmiq.git ...I get an editable drop in a ~/src/ folder. -- Phlip http://c2.com/cgi/wiki?ZeekLand From paul at boddie.org.uk Sun Nov 15 12:16:58 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 15 Nov 2009 09:16:58 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> Message-ID: <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> On 15 Nov, 09:30, Terry Reedy wrote: > greg wrote: > [Shed Skin] > > These restrictions mean that it isn't really quite > > Python, though. > > Python code that only uses a subset of features very much *is* Python > code. The author of ShedSkin makes no claim that is compiles all Python > code. Of course, Shed Skin doesn't support all the usual CPython features, but the code you would write for Shed Skin's benefit should be Python code that runs under CPython. It's fair to say that Shed Skin isn't a "complete" implementation of what CPython defines as being "the full Python", but you're still writing Python. One can argue that the restrictions imposed by Shed Skin inhibit the code from being "proper" Python, but every software project has restrictions in the form of styles, patterns and conventions. This is where the "Lesser Python" crowd usually step in and say that they won't look at anything which doesn't support "the full Python", but I think it's informative to evaluate which features of Python give the most value and which we could do without. The "Lesser Python" attitude is to say, "No! We want it all! It's all necessary for everything!" That doesn't really help the people implementing "proper" implementations or those trying to deliver better-performing implementations. In fact, the mentality that claims that "it's perfect, or it will be if we keep adding features" could drive Python into a diminishing niche over time. In contrast, considering variations of Python as some kind of "Greater Python" ecosystem could help Python (the language) adapt to the changing demands on programming languages to which Go (the Google language, not Go! which existed already) is supposedly a response. Paul P.S. And PyPy is hardly a dud: they're only just getting started delivering the performance benefits, and it looks rather promising. From highcar at gmail.com Sun Nov 15 12:29:34 2009 From: highcar at gmail.com (elca) Date: Sun, 15 Nov 2009 09:29:34 -0800 (PST) Subject: python win32com problem In-Reply-To: References: <26358976.post@talk.nabble.com> Message-ID: <26361229.post@talk.nabble.com> Jon Clements-2 wrote: > > On Nov 15, 1:08?pm, elca wrote: >> hello , these day im very stress of one of some strange thing. >> >> i want to enumurate inside list of url, and every enumurated url i want >> to >> visit >> >> i was uplod incompleted script source in here => >> >> http://elca.pastebin.com/m6f911584 >> >> if anyone can help me really appreciate >> >> thanks in advance >> >> Paul >> >> -- >> View this message in >> context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > How much effort have you put into this? It looks like you've just > whacked together code (that isn't valid -- where'd the magical > 'buttons' variable come from), given up and cried for help. > > Besides, I would suggest you're taking completely the wrong route. > You'll find it one hell of a challenge to automate a browser as you > want, that's if it supports exposing the DOM anyway. And without being > rude, would definitely be beyond your abilities from your posts to > c.l.p. > > Download and install BeautifulSoup from > http://www.crummy.com/software/BeautifulSoup/ > - you seem to have quite a few HTML based needs in your pastebin, so > it'll come in useful for the future. > > Here's a snippet to get you started: > > from urllib2 import urlopen > from BeautifulSoup import BeautifulSoup as BS > > url = urlopen('http://news.naver.com/main/presscenter/category.nhn') > urldata = url.read() > soup = BS(urldata) > atags = soup('a', attrs={'href': lambda L: L and L.startswith('http:// > news.khan.co.kr')}) > for atag in atags: > print atag['href'] > > I'll leave it to you where you want to go from there (ie, follow the > links, or automate IE to open said pages etc...) > > I strongly suggest reading the urllib2 and BeautifulSoup docs, and > documenting the above code snippet -- you should then understand it, > should be less stressed, and have something to refer to for similar > requirements in the future. > > hth, > Jon. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, thanks for your kind reply. your script is working very well im making scraper now. and im making with PAMIE but still slow module but i have no choice because of javascript support. before i was try to look for method with mechanize but almost failed. if mechanize can support javascript maybe my best choice will be mechanize. ok anyway..there is almost no choice so i have to go "automate IE to open said pages etc.." i want to visit every collect link with IE com interface.. for example i was collect 10 url ...i want to visit every 10 url. would you help me some more? if so much appreciate thanks -- View this message in context: http://old.nabble.com/python-win32com-problem-tp26358976p26361229.html Sent from the Python - python-list mailing list archive at Nabble.com. From pengyu.ut at gmail.com Sun Nov 15 12:39:17 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 15 Nov 2009 09:39:17 -0800 (PST) Subject: IDE for python References: <7mar95F3g85n0U1@mid.uni-berlin.de> Message-ID: On Nov 15, 11:15?am, "Diez B. Roggisch" wrote: > Peng Yu schrieb: > > > There had been some discussion on IDE. But I'm not sure what pros and > > cons of each choice. Current, I'm using vim and ctags. > > > Could somebody give some advices on choosing the best IDE for me? > > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > I suggest you use your google foo that you just showed to search in this > group for the numerous discussions about emacs, vi, eclipse+pydev, wing > ide, komodo and notepad. I see too many threads. But I don't any of them give me a complete comparison between different choices. If you are familiar with different choices, would you please give me some advices? http://groups.google.com/group/comp.lang.python/search?group=comp.lang.python&q=IDE&qt_g=Search+this+group From arve.knudsen at gmail.com Sun Nov 15 12:56:56 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 09:56:56 -0800 (PST) Subject: How to get directory of Python C library Message-ID: Hi I need to link against Python, is there a way to get the path to the directory containing Python's C library (e.g., /libs on Windows)? Thanks, Arve From joost at h-labahn.de Sun Nov 15 13:21:30 2009 From: joost at h-labahn.de (DreiJane) Date: Sun, 15 Nov 2009 10:21:30 -0800 (PST) Subject: Documentation bugs in 3.1 - C-API - TypeObjects References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> Message-ID: <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> Thanks a second time - the picture has gotten clearer indeed. But for third-party readers the complexities of this matter require the correction, that "Py_Type(&Foo_Type) = &PyType_Type" must be: "Py_TYPE(&Foo_Type) = &PyType_Type " - or am i completely wrong ? Joost From showell30 at yahoo.com Sun Nov 15 13:25:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 10:25:43 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict Message-ID: I ran the following program, and found its output surprising in one place: class OnlyAl: def __getitem__(self, key): return 'al' class OnlyBob(dict): def __getitem__(self, key): return 'bob' import sys; print sys.version al = OnlyAl() bob = OnlyBob() print al['whatever'] al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' print al['whatever'] print bob['whatever'] bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems impossible' print bob['whatever'] 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] al NEW AND IMPROVED AL! bob bob In attempting to change the behavior for bob's dictionary lookup, I am clearly doing something wrong, or maybe even impossible. Obviously the examples are contrived, but I am interested on a purely academic level why setting __getitem__ on bob does not seem to change the behavior of bob['foo']. Note that OnlyBob subclasses dict; OnlyAl does not. On a more practical level, I will explain what I am trying to do. Basically, I am trying to create some code that allows me to spy on arbitrary objects in a test environment. I want to write a spy() method that takes an arbitrary object and overrides its implementation of __getitem__ and friends so that I can see how library code is invoking the object (with print statements or whatever). Furthermore, I want spy() to recursively spy on objects that get produced from my original object. The particular use case is that I am creating a context for Django templates, and I want to see which objects are getting rendered, all the way down the tree. It would be pretty easy to just create a subclass of the context method to spy at the top level, but I want to recursively spy on all its children, and that is why I need a monkeypatching approach. The original version had spy recursively returning proxy/masquerade objects that intercepted __getitem__ calls, but it becomes brittle when the proxy objects go off into places like template filters, where I am not prepared to intercept all calls to the object, and where in some cases it is impossible to gain control. Although I am interested in comments on the general problems (spying on objects, or spying on Django template rendering), I am most interested in the specific mechanism for changing the __getitem__ method for a subclass on a dictionary. Thanks in advance! From tjreedy at udel.edu Sun Nov 15 13:36:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Nov 2009 13:36:47 -0500 Subject: Stagnant Frame Data? In-Reply-To: References: Message-ID: Peter Otten wrote: > Mike wrote: > >> I'll apologize first for this somewhat lengthy example. It does >> however recreate the problem I've run into. This is stripped-down code >> from a much more meaningful system. >> >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate >> variables in their caller's namespace using the frame stack. As >> written, the output is not what is expected: the variables evaluate to >> "stagnant" values. >> >> However, if the one indicated line is uncommented, then the result is >> as expected. >> >> So my questions are: Is this a bug in Python? No. The existence and use of sys._getframe -- notice the leading underscore -- is a CPython implementation artifact. Use at your own risk. >> Is this an invalid use of frame data? Up to you to decide. >> Why does the single line "sys._getframe(1).f_locals" >> fix the behavior? It updates the dictionary. > A simplified demonstration of your problem: > >>>> def f(update): > ... a = locals() > ... x = 42 > ... if update: locals() > ... print a > ... >>>> f(False) > {'update': False} >>>> f(True) > {'a': {...}, 'x': 42, 'update': True} > > The local namespace is not a dictionary, and the locals()/f_locals > dictionary contains a snapshot of the local namespace. Accessing the > f_locals attribute is one way to trigger an update of that snapshot. > > What's puzzling is that the same dictionary is reused. Efficiency? Consistency? The doc for locals says "locals() Update and return a dictionary representing the current local symbol table." In class statements, where (currently) the local namespace *is* a dict, no update is needed and locals() simply returns the dict, the same one each time. Terry Jan Reedy From yoav.goldberg at gmail.com Sun Nov 15 13:40:53 2009 From: yoav.goldberg at gmail.com (Yoav Goldberg) Date: Sun, 15 Nov 2009 20:40:53 +0200 Subject: Python & Go In-Reply-To: References: <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Nov 15, 2009 at 4:00 AM, Terry Reedy wrote: > Yoav Goldberg wrote: > > >> On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy > tjreedy at udel.edu>> wrote: >> >> Paul Rubin wrote: >> >> Mark Chu-Carroll has a new post about Go: >> >> >> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> >> In a couple of minutes, I wrote his toy prime filter example in >> Python, mostly from the text rather than the code, which I can >> barely stand to read. It ran the first time without error. >> >> Yes, but the cool thing about the Go version is that it does each >> generator in a different thread, so in theory it could run twice as fast on >> a multi-core machine. >> > > Which is why I added, in my opinion, that "It would be much better, for > instance, to tweak Python, which it has had great success with, to better > run on multiple cores." > > For instance, add a new keyword 'go' such that > go def f(): yield 1 > runs the generator in a different thread, possibly on a different core. > > [...] > I see no reason why we cannot have that with Python. I not even sure we > cannot have it with CPython, but I am not familiar enough with threads, > processes, and CPython internals. > > > Yes, this could work, and would really cool. I believe you can go a long way with annotations, and maybe even provide a full working demo. So we can definitely have this in python, and it could be a really cool feature. Having it in CPython, though, is a different story altogether -- CPython way of handling threads is problematic, and not going to change soon, see here about the problem: http://blog.snaplogic.org/?p=94 and here about it no going away soon: http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock http://www.artima.com/weblogs/viewpost.jsp?thread=214235 So, yes, we could have this in python, but no I don't see it happening very soon.. And the compiled Go is really different in design than python -- easy to parse, easy to compile, static, works fast, etc. Different language. Is it a good thing to have a different language and not base yourself on an existing one? Not sure. But that's a different debate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Nov 15 13:50:43 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2009 10:50:43 -0800 Subject: Slicing history? Message-ID: Anyone remember or know why Python slices function like half-open intervals? I find it incredibly convenient myself, but an acquaintance familiar with other programming languages thinks it's bizarre and I'm wondering how it happened. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From nobody at nowhere.com Sun Nov 15 13:50:55 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 18:50:55 +0000 Subject: How to know if a file is a text file References: Message-ID: On Sun, 15 Nov 2009 04:34:10 -0800, Chris Rebert wrote: >>> I'm looking for a way to be able to load a generic file from the >>> system and understand if he is plain text. >>> The mimetype module has some nice methods, but for example it's not >>> working for file without extension. >>> >>> Any suggestion? >> >> You could use the "file" command. It's normally installed by default on >> Unix systems, but you can get a Windows version from: > > FWIW, IIRC the heuristic `file` uses to check whether a file is text > or not is whether it contains any null bytes; if it does, it > classifies it as binary (i.e. not text). "file" provides more granularity than that, recognising many specific formats, both text and binary. First, it uses "magic number" checks, checking for known signature bytes (e.g. "#!" or "JFIF") at the beginning of the file. If those checks fail it checks for common text encodings. If those also fail, it reports "data". Also, UTF-16-encoded text is recognised as text, even though it may contain a high proportion of NUL bytes. From nobody at nowhere.com Sun Nov 15 13:56:01 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 18:56:01 +0000 Subject: How to know if a file is a text file References: <27308d500911140802r58687331h67ec55dee754f56b@mail.gmail.com> Message-ID: On Sun, 15 Nov 2009 13:49:54 +0100, Luca wrote: > I was quite sure that this is not a very simple task. Right now search > only inside ASCII encode is not enough for me (my native language is > outside this encode :-) > Checking every single byte can be a good solution... > > I can start using the mimetype module and, if the file has no > extension, check byte one by one (commonly) as "file" command does. > Better: I can check use the "file" command if available. Another possible solution: Universal Encoding Detector Character encoding auto-detection in Python 2 and 3 http://chardet.feedparser.org/ From joncle at googlemail.com Sun Nov 15 14:01:49 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 11:01:49 -0800 (PST) Subject: Slicing history? References: Message-ID: On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > Anyone remember or know why Python slices function like half-open > intervals? ?I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > [on old computer technologies and programmers] ?"Fancy tail fins on a > brand new '59 Cadillac didn't mean throwing out a whole generation of > mechanics who started with model As." ?--Andrew Dalke Good ol' zero based indexing. It makes a lot more sense that range(len (my_list)) returns 'n' values which are valid indicies, otherwise they'd be a lot of IndexError's being raised. Besides, when you really want the full range (a corner case), it's a lot easier to do a +1, than to force people to write -1 for the vast majority of cases. Jon. From showell30 at yahoo.com Sun Nov 15 14:03:08 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:03:08 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> Message-ID: <7dc79b2a-22e6-4d2f-8002-b3a6583030b1@13g2000prl.googlegroups.com> On Nov 14, 3:26?am, kj wrote: > One more thing: I found Rob Pike's mutterings on generics (towards > the end of his rollout video) rather offputting, because he gave > the impression that some important aspects of the language were > not even considered before major decisions for it were set in stone. > It looks like, if they ever get around to supporting generics, it > will be a late-in-the-day hack. > By "set in stone," do you mean "implemented"? Or have Rob Pike and friends literally put a redesign freeze on the language that was just released this month? From deets at nospam.web.de Sun Nov 15 14:03:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 20:03:48 +0100 Subject: IDE for python In-Reply-To: References: <7mar95F3g85n0U1@mid.uni-berlin.de> Message-ID: <7mb1kkF3h5cpfU1@mid.uni-berlin.de> Peng Yu schrieb: > On Nov 15, 11:15 am, "Diez B. Roggisch" wrote: >> Peng Yu schrieb: >> >>> There had been some discussion on IDE. But I'm not sure what pros and >>> cons of each choice. Current, I'm using vim and ctags. >>> Could somebody give some advices on choosing the best IDE for me? >>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> I suggest you use your google foo that you just showed to search in this >> group for the numerous discussions about emacs, vi, eclipse+pydev, wing >> ide, komodo and notepad. > > I see too many threads. But I don't any of them give me a complete > comparison between different choices. If you are familiar with > different choices, would you please give me some advices? > > http://groups.google.com/group/comp.lang.python/search?group=comp.lang.python&q=IDE&qt_g=Search+this+group Again: read the threads. They discuss the various aspects. They arose because of the same question asked as yours. If you don't find in them what you are looking for, chances are hight that you won't get it. This is very much a question of personal preferences, not of feature-matrices and strict metrics. So go, read, and them make an informed choice on what at least to try. Stick with what you prefer. And given your track record in this group here, I assume regardless of *what* beautiful scheme of explaining various IDEs and their respective merits, they all fall short of your "unique" way of doing things. Diez From deets at nospam.web.de Sun Nov 15 14:05:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 20:05:48 +0100 Subject: How to get directory of Python C library In-Reply-To: References: Message-ID: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > Hi > > I need to link against Python, is there a way to get the path to the > directory containing Python's C library (e.g., /libs on > Windows)? Most probably from the registry somehow. In general, try & locate a python-executable, and make it execute python -c "import sys; print sys.prefix" Capture that, and you're done. Depending on the OS, the libs then are placed in e.g. /lib. Diez From nobody at nowhere.com Sun Nov 15 14:19:01 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 15 Nov 2009 19:19:01 +0000 Subject: Slicing history? References: Message-ID: On Sun, 15 Nov 2009 10:50:43 -0800, Aahz wrote: > Anyone remember or know why Python slices function like half-open > intervals? I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. How else would they function? Closed intervals? Using a closed interval (for just about anything) indicates that the designer has very limited programming experience. Anyone with a modicum of programming experience knows that half-open intervals are the norm, and that using closed intervals will confuse anyone else with a modicum of programming experience. That's aside from the objective merits, i.e. the fact that they can be used to partition an interval into subintervals without having to adjust the upper bound (which requires knowing how much to adjust the upper bound by, if that's even possible (for reals, it isn't)). From gherron at islandtraining.com Sun Nov 15 14:19:11 2009 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 15 Nov 2009 11:19:11 -0800 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: Message-ID: <4B00542F.4030105@islandtraining.com> Steve Howell wrote: > I ran the following program, and found its output surprising in one > place: > > class OnlyAl: > def __getitem__(self, key): return 'al' > > class OnlyBob(dict): > def __getitem__(self, key): return 'bob' > > import sys; print sys.version > > al = OnlyAl() > bob = OnlyBob() > > print al['whatever'] > al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' > print al['whatever'] > > print bob['whatever'] > bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems > impossible' > print bob['whatever'] > > 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] > al > NEW AND IMPROVED AL! > bob > bob > It's the difference between old-style and new-style classes. Type dict and therefore OnlyBob are new style. OnlyAl defaults to old-style. If you derive OnlyAl from type object, you'll get consistent results. Gary Herron > In attempting to change the behavior for bob's dictionary lookup, I am > clearly doing something wrong, or maybe even impossible. > > Obviously the examples are contrived, but I am interested on a purely > academic level why setting __getitem__ on bob does not seem to change > the behavior of bob['foo']. Note that OnlyBob subclasses dict; > OnlyAl does not. > > On a more practical level, I will explain what I am trying to do. > Basically, I am trying to create some code that allows me to spy on > arbitrary objects in a test environment. I want to write a spy() > method that takes an arbitrary object and overrides its implementation > of __getitem__ and friends so that I can see how library code is > invoking the object (with print statements or whatever). Furthermore, > I want spy() to recursively spy on objects that get produced from my > original object. The particular use case is that I am creating a > context for Django templates, and I want to see which objects are > getting rendered, all the way down the tree. It would be pretty easy > to just create a subclass of the context method to spy at the top > level, but I want to recursively spy on all its children, and that is > why I need a monkeypatching approach. The original version had spy > recursively returning proxy/masquerade objects that intercepted > __getitem__ calls, but it becomes brittle when the proxy objects go > off into places like template filters, where I am not prepared to > intercept all calls to the object, and where in some cases it is > impossible to gain control. > > Although I am interested in comments on the general problems (spying > on objects, or spying on Django template rendering), I am most > interested in the specific mechanism for changing the __getitem__ > method for a subclass on a dictionary. Thanks in advance! > > From showell30 at yahoo.com Sun Nov 15 14:23:01 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:23:01 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: Message-ID: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> On Nov 15, 10:25?am, Steve Howell wrote: > [see original post...] > I am most > interested in the specific mechanism for changing the __getitem__ > method for a subclass on a dictionary. ?Thanks in advance! Sorry for replying to myself, but I just realized that the last statement in my original post was a little imprecise. I am more precisely looking for a way to change the behavior of foo ['bar'] (side effects and possibly return value) where "foo" is an instance of a class that subclasses "dict," and where "foo" is not created by me. The original post gives more context and example code that does not work as I expect/desire. From showell30 at yahoo.com Sun Nov 15 14:29:38 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 11:29:38 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: Message-ID: On Nov 15, 11:19?am, Gary Herron wrote: > Steve Howell wrote: > > I ran the following program, and found its output surprising in one > > place: > > > ? ? class OnlyAl: > > ? ? ? ? def __getitem__(self, key): return 'al' > > > ? ? class OnlyBob(dict): > > ? ? ? ? def __getitem__(self, key): return 'bob' > > > ? ? import sys; print sys.version > > > ? ? al = OnlyAl() > > ? ? bob = OnlyBob() > > > ? ? print al['whatever'] > > ? ? al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!' > > ? ? print al['whatever'] > > > ? ? print bob['whatever'] > > ? ? bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems > > impossible' > > ? ? print bob['whatever'] > > > ? ? 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > > ? ? [GCC 4.3.3] > > ? ? al > > ? ? NEW AND IMPROVED AL! > > ? ? bobe > > ? ? bob > > It's the difference between old-style and new-style classes. ?Type dict > and therefore OnlyBob are new style. ?OnlyAl defaults to old-style. ?If > you derive OnlyAl from type object, you'll get consistent results. > Thanks, Gary. My problem is that I am actually looking for the behavior that the old-style OnlyAl provides, not OnlyBob--allowing me to override the behavior of al['foo'] and bob['foo']. I (hopefully) clarified my intent in a follow-up post that was sent before I saw your reply. Here it is re-posted for convenience of discussion: "I am more precisely looking for a way to change the behavior of foo ['bar'] (side effects and possibly return value) where "foo" is an instance of a class that subclasses "dict," and where "foo" is not created by me." From falk at mauve.rahul.net Sun Nov 15 14:33:10 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Sun, 15 Nov 2009 19:33:10 +0000 (UTC) Subject: python simply not scaleable enough for google? References: Message-ID: In article , Robert Brown wrote: > >It's hard to refute your assertion. You're claiming that some future >hypothetical Python implementation will have excellent performance via a JIT. >On top of that you say that you're willing to change the definition of the >Python language, say by adding type declarations, if an implementation with a >JIT doesn't pan out. If you change the Python language to address the >semantic problems Willem lists in his post and also add optional type >declarations, then Python becomes closer to Common Lisp, which we know can be >executed efficiently, within the same ballpark as C and Java. Ya know; without looking at Go, I'd bet that this was some of the thought process that was behind it. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From martin at v.loewis.de Sun Nov 15 14:35:23 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 20:35:23 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> <062af2de-254d-41a3-84a1-c108be1b3bd8@d5g2000yqm.googlegroups.com> Message-ID: <4B0057FB.3070504@v.loewis.de> > Still there remains the difference to what is told with the > Noddy_Type in the tutorial. Please report that to bugs.python.org. Regards, Martin From martin at v.loewis.de Sun Nov 15 14:36:10 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Nov 2009 20:36:10 +0100 Subject: Documentation bugs in 3.1 - C-API - TypeObjects In-Reply-To: <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> References: <459fecd3-490c-4a33-b3f9-5a9e77385c59@u7g2000yqm.googlegroups.com> <4AFF5F19.3040809@v.loewis.de> <65b02935-524b-4b5b-aed3-cc86a5b6dfd4@p8g2000yqb.googlegroups.com> Message-ID: <4B00582A.1030604@v.loewis.de> DreiJane wrote: > Thanks a second time - the picture has > gotten clearer indeed. But for third-party > readers the complexities of this matter > require the correction, that > > "Py_Type(&Foo_Type) = &PyType_Type" > > must be: > "Py_TYPE(&Foo_Type) = &PyType_Type " > > - or am i completely wrong ? Joost No, you are right - I forgot that the spelling had been changed to upper case. Regards, Martin From joncle at googlemail.com Sun Nov 15 15:01:00 2009 From: joncle at googlemail.com (Jon Clements) Date: Sun, 15 Nov 2009 12:01:00 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> Message-ID: <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> On Nov 15, 7:23?pm, Steve Howell wrote: > On Nov 15, 10:25?am, Steve Howell wrote: > > > [see original post...] > > I am most > > interested in the specific mechanism for changing the __getitem__ > > method for a subclass on a dictionary. ?Thanks in advance! > > Sorry for replying to myself, but I just realized that the last > statement in my original post was a little imprecise. > > I am more precisely looking for a way to change the behavior of foo > ['bar'] (side effects and possibly return value) where "foo" is an > instance of a class that subclasses "dict," and where "foo" is not > created by me. ?The original post gives more context and example code > that does not work as I expect/desire. [quote from http://docs.python.org/reference/datamodel.html] For instance, if a class defines a method named __getitem__(), and x is an instance of this class, then x[i] is roughly equivalent to x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) for new-style classes. [/quote] A quick hack could be: class Al(dict): def __getitem__(self, key): return self.spy(key) def spy(self, key): return 'Al' >>> a = Al() >>> a[3] 'Al' >>> a.spy = lambda key: 'test' >>> a[3] 'test' >>> b = Al() >>> b[3] 'Al' Seems to be what you're after anyway... hth, Jon. From http Sun Nov 15 15:01:57 2009 From: http (Paul Rubin) Date: 15 Nov 2009 12:01:57 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: <7xpr7jpney.fsf@ruckus.brouhaha.com> falk at mauve.rahul.net (Edward A. Falk) writes: > >If you change the Python language to address the semantic problems > >Willem lists in his post and also add optional type declarations, > >then Python becomes closer to Common Lisp, which we know can be > >executed efficiently, within the same ballpark as C and Java. > > Ya know; without looking at Go, I'd bet that this was some of the thought > process that was behind it. I don't have the slightest impression that Python had any significant influence on Go. Go has C-like syntax, static typing with mandatory declarations, and concurrency inspired by Occam. It seems to be a descendant of Oberon and Newsqueak (Pike's earlier language used in Plan 9). It also seems to be decades behind the times in some ways. Its creators are great programmers and system designers, but I wish they had gotten some PL theorists involved in designing Go. From showell30 at yahoo.com Sun Nov 15 15:09:21 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 12:09:21 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> Message-ID: <3b2918da-a5cd-47b6-9e3b-5ef6fc800b7c@t11g2000prh.googlegroups.com> On Nov 15, 12:01?pm, Jon Clements wrote: > On Nov 15, 7:23?pm, Steve Howell wrote: > > > I am more precisely looking for a way to change the behavior of foo > > ['bar'] (side effects and possibly return value) where "foo" is an > > instance of a class that subclasses "dict," and where "foo" is not > > created by me. ?The original post gives more context and example code > > that does not work as I expect/desire. > > [quote fromhttp://docs.python.org/reference/datamodel.html] > For instance, if a class defines a method named __getitem__(), and x > is an instance of this class, then x[i] is roughly equivalent to > x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) > for new-style classes. > [/quote] > > A quick hack could be: > > class Al(dict): > ? def __getitem__(self, key): > ? ? return self.spy(key) > ? def spy(self, key): > ? ? return 'Al' > > >>> a = Al() > >>> a[3] > 'Al' > >>> a.spy = lambda key: 'test' > >>> a[3] > 'test' > >>> b = Al() > >>> b[3] > > 'Al' > > Seems to be what you're after anyway... > This is very close to what I want, but the problem is that external code is defining Al, and I do not seem to be able to get this statement to have any effect: a.__getitem__ = lambda key: test How can I change the behavior of a['foo'] without redefining Al? From dickinsm at gmail.com Sun Nov 15 15:11:40 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 15 Nov 2009 12:11:40 -0800 (PST) Subject: Slicing history? References: Message-ID: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > Anyone remember or know why Python slices function like half-open > intervals? ?I find it incredibly convenient myself, but an acquaintance > familiar with other programming languages thinks it's bizarre and I'm > wondering how it happened. Sounds like an excuse to post this Dijkstra link: http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF -- Mark From arve.knudsen at gmail.com Sun Nov 15 15:14:59 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 12:14:59 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> Message-ID: <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > Hi > > > I need to link against Python, is there a way to get the path to the > > directory containing Python's C library (e.g., /libs on > > Windows)? > > Most probably from the registry somehow. In general, try & locate a > python-executable, and make it execute > > ? python -c "import sys; print sys.prefix" > > Capture that, and you're done. Depending on the OS, the libs then are > placed in e.g. /lib. That doesn't solve anything, the hard part is figuring out the part after .. Arve From deets at nospam.web.de Sun Nov 15 15:24:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 21:24:01 +0100 Subject: How to get directory of Python C library In-Reply-To: <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> Message-ID: <7mb6b2F3h8d4pU1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >>> Hi >>> I need to link against Python, is there a way to get the path to the >>> directory containing Python's C library (e.g., /libs on >>> Windows)? >> Most probably from the registry somehow. In general, try & locate a >> python-executable, and make it execute >> >> python -c "import sys; print sys.prefix" >> >> Capture that, and you're done. Depending on the OS, the libs then are >> placed in e.g. /lib. > > That doesn't solve anything, the hard part is figuring out the part > after .. AFAIK is that only varying based on the OS. Under unix, it's /lib/python/ You can get the platform via sys.platform. Diez From showell30 at yahoo.com Sun Nov 15 15:40:44 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 12:40:44 -0800 (PST) Subject: Slicing history? References: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> Message-ID: <07a7b5ef-4993-47c8-92e9-3a8ed3a35625@o9g2000prg.googlegroups.com> On Nov 15, 12:11?pm, Mark Dickinson wrote: > On Nov 15, 6:50?pm, a... at pythoncraft.com (Aahz) wrote: > > > Anyone remember or know why Python slices function like half-open > > intervals? ?I find it incredibly convenient myself, but an acquaintance > > familiar with other programming languages thinks it's bizarre and I'm > > wondering how it happened. > > Sounds like an excuse to post this Dijkstra link: > > http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF > That is really good stuff! Like Aahz I have Python's slicing mechanism (and zero-based indexing) burnt into my brain, but I never had a good way to explain why it makes sense, other than just an intuitive notion that it works for me. It is interesting how the link actually seems to explain zero-based indexing as a consequence of the slicing approach, not a cause. I always understood zero-based indexing as a relic of memory management, which was fine, but I guess the reasons go deeper than that. From arve.knudsen at gmail.com Sun Nov 15 16:08:22 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 13:08:22 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> Message-ID: On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> Hi > >>> I need to link against Python, is there a way to get the path to the > >>> directory containing Python's C library (e.g., /libs on > >>> Windows)? > >> Most probably from the registry somehow. In general, try & locate a > >> python-executable, and make it execute > > >> ? python -c "import sys; print sys.prefix" > > >> Capture that, and you're done. Depending on the OS, the libs then are > >> placed in e.g. /lib. > > > That doesn't solve anything, the hard part is figuring out the part > > after .. > > AFAIK is that only varying based on the OS. Under unix, it's > > ? /lib/python/ > > You can get the platform via sys.platform. Well, my point is that I should like a way to query for this directory, just as I can query distutils.sysconfig for the include directory and Python library (i.e., the standard Python library) directory. It's not trivial to figure out Python's installation scheme so long as it's not written in stone .. Arve From deets at nospam.web.de Sun Nov 15 16:11:38 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 22:11:38 +0100 Subject: How to get directory of Python C library In-Reply-To: References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> Message-ID: <7mb94aF3f97c1U1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 21:24, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >> >> >> >> >>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >>>> arve.knud... at gmail.com schrieb: >>>>> Hi >>>>> I need to link against Python, is there a way to get the path to the >>>>> directory containing Python's C library (e.g., /libs on >>>>> Windows)? >>>> Most probably from the registry somehow. In general, try & locate a >>>> python-executable, and make it execute >>>> python -c "import sys; print sys.prefix" >>>> Capture that, and you're done. Depending on the OS, the libs then are >>>> placed in e.g. /lib. >>> That doesn't solve anything, the hard part is figuring out the part >>> after .. >> AFAIK is that only varying based on the OS. Under unix, it's >> >> /lib/python/ >> >> You can get the platform via sys.platform. > > Well, my point is that I should like a way to query for this > directory, just as I can query distutils.sysconfig for the include > directory and Python library (i.e., the standard Python library) > directory. It's not trivial to figure out Python's installation scheme > so long as it's not written in stone .. Well, than how about you word your question like that? But there is no simple function to call. So the answer to the question you asked is: no. I showed you a way that works for current python, and consists of stitching together a number of informations. Diez From aahz at pythoncraft.com Sun Nov 15 17:06:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Nov 2009 14:06:47 -0800 Subject: Slicing history? References: <667394cb-d505-4906-8c6b-ab2d361b3a4d@j24g2000yqa.googlegroups.com> Message-ID: In article <667394cb-d505-4906-8c6b-ab2d361b3a4d at j24g2000yqa.googlegroups.com>, Mark Dickinson wrote: >On Nov 15, 6:50=A0pm, a... at pythoncraft.com (Aahz) wrote: >> >> Anyone remember or know why Python slices function like half-open >> intervals? =A0I find it incredibly convenient myself, but an acquaintance >> familiar with other programming languages thinks it's bizarre and I'm >> wondering how it happened. > >Sounds like an excuse to post this Dijkstra link: > >http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF Many thanks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 baptiste.lepilleur at gmail.com Sun Nov 15 17:12:53 2009 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Sun, 15 Nov 2009 23:12:53 +0100 Subject: Writing an emulator in python - implementation questions (for performance) In-Reply-To: <7m6nclF3gnlqfU1@mid.individual.net> References: <061b21f5-de5b-47d0-8949-d374c58dbb4e@a39g2000pre.googlegroups.com> <7m3ujtF3gd1d7U1@mid.individual.net> <60d3b8a7-b5db-4433-bcd4-4e1762e3ecd6@d5g2000yqm.googlegroups.com> <7m6nclF3gnlqfU1@mid.individual.net> Message-ID: I think you can use python itself for "pre-processing". Here is an (shortened) example from PyPy RPython paper: # operators: the docstrings contain the # symbol associated with each operator class Op_Add(BinaryExpr): ?+? class Op_Sub(BinaryExpr): ?-? # INIT-TIME only: build the table of # opcodes and add the ?eval? methods def gen_eval(ch): code = """ def eval(self): return self.l.eval() %s self.r.eval() """ d = {} exec code.strip() % (ch) in d return d['eval'] OPCODES = {} def build_opcodes(): for name, value in globals().items(): if name.startswith(?Op_?): value.eval = gen_eval(value.__doc__) OPCODES[value.__doc__] = value build_opcodes() >From the paper: """ The eval method is generated via a call to the helper routine gen_eval, which creates a string of Python code that performs the desired computation and uses exec to compile this string into a Python method. Adding the class object to the OPCODES dictionary is done by simple assignment, using the class docstring as the key and the class object itself as the value. """ You might also want to have a look at PyGirl, the Nintendo Gameboy emulator of the PyPy project written in RPython (a subset of Python that allow static type inference). There is probably some ideas to borrow. The paper on PyGirl also details some of the "pre-processing" trick they used. They sometime call it meta-programming but its all the same, generating code with code :). See http://codespeak.net/pypy/dist/pypy/doc/extradoc.html for more info and look-up the rpython and pygirl docs. 2009/11/14 greg > Santiago Romero wrote: > > Can the above be easily done with another already-existing >> application? (example: can m4 do this job)? >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arve.knudsen at gmail.com Sun Nov 15 17:50:54 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 14:50:54 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> Message-ID: <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> On 15 Nov, 22:11, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >>>> arve.knud... at gmail.com schrieb: > >>>>> Hi > >>>>> I need to link against Python, is there a way to get the path to the > >>>>> directory containing Python's C library (e.g., /libs on > >>>>> Windows)? > >>>> Most probably from the registry somehow. In general, try & locate a > >>>> python-executable, and make it execute > >>>> ? python -c "import sys; print sys.prefix" > >>>> Capture that, and you're done. Depending on the OS, the libs then are > >>>> placed in e.g. /lib. > >>> That doesn't solve anything, the hard part is figuring out the part > >>> after .. > >> AFAIK is that only varying based on the OS. Under unix, it's > > >> ? /lib/python/ > > >> You can get the platform via sys.platform. > > > Well, my point is that I should like a way to query for this > > directory, just as I can query distutils.sysconfig for the include > > directory and Python library (i.e., the standard Python library) > > directory. It's not trivial to figure out Python's installation scheme > > so long as it's not written in stone .. > > Well, than how about you word your question like that? But there is no > simple function to call. So the answer to the question you asked is: no. > > I showed you a way that works for current python, and consists of > stitching together a number of informations. > > Diez My original question was pretty clear I think. And I don't have the required information to deduce what the library path may look like on any given platform, there really should be a standard function for this. Arve From showell30 at yahoo.com Sun Nov 15 17:52:54 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 14:52:54 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> Message-ID: <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> On Nov 15, 12:01?pm, Jon Clements wrote: > On Nov 15, 7:23?pm, Steve Howell wrote: > > > On Nov 15, 10:25?am, Steve Howell wrote: > > > > [see original post...] > > > I am most > > > interested in the specific mechanism for changing the __getitem__ > > > method for a subclass on a dictionary. ?Thanks in advance! > > > Sorry for replying to myself, but I just realized that the last > > statement in my original post was a little imprecise. > > > I am more precisely looking for a way to change the behavior of foo > > ['bar'] (side effects and possibly return value) where "foo" is an > > instance of a class that subclasses "dict," and where "foo" is not > > created by me. ?The original post gives more context and example code > > that does not work as I expect/desire. > > [quote fromhttp://docs.python.org/reference/datamodel.html] > For instance, if a class defines a method named __getitem__(), and x > is an instance of this class, then x[i] is roughly equivalent to > x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i) > for new-style classes. > [/quote] > Ok, thanks to Jon and Gary pointing me in the right direction, I think I can provide an elaborate answer my own question now. Given an already instantiated instance foo of Foo where Foo subclasses dict, you cannot change the general behavior of calls of the form foo [bar]. (Obviously you can change the behavior for specific examples of bar after instantiation by setting foo['apple'] and foo['banana'] as needed, but that's not what I mean.) This may be surprising to naive programmers like myself, given that is possible to change the behavior of foo.bar() after instantiation by simply saying "foo.bar = some_method". Also, with old-style classes, you can change the behavior of foo[bar] by setting foo.__getitem__. Even in new-style classes, you can change the behavior of foo.__getitem__(bar) by saying foo.__getitem__ = some_method, but it is a pointless exercise, since foo.__getitem__ will have no bearing on the processing of "foo[bar]." Finally, you can define __getitem__ on the Foo class itself to change how foo[bar] gets resolved, presumably even after instantiation of foo itself (but this does not allow for instance-specific behavior). Here is the difference: foo.value looks for a definition of value on the instance before looking in the class hierarchy foo[bar] can find __getitem__ on foo before looking at Foo and its superclasses, if Foo is old-style foo[bar] will only look for __getitem__ in the class hierarchy if Foo derives from a new-style class Does anybody have any links that points to the rationale for ignoring instance definitions of __getitem__ when new-style classes are involved? I assume it has something to do with performance or protecting us from our own mistakes? So now I am still in search of a way to hook into calls to foo[bar] after foo has been instantiated. It is all test code, so I am not particularly concerned about safety or future compatibility. I can do something really gross like monkeypatch Foo class instead of foo instance and keep track of the ids to decide when to override behavior, but there must be a simpler way to do this. From deets at nospam.web.de Sun Nov 15 17:59:04 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 15 Nov 2009 23:59:04 +0100 Subject: How to get directory of Python C library In-Reply-To: <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> Message-ID: <7mbfdpF3hr2s9U1@mid.uni-berlin.de> arve.knudsen at gmail.com schrieb: > On 15 Nov, 22:11, "Diez B. Roggisch" wrote: >> arve.knud... at gmail.com schrieb: >> >> >> >> >> >>> On 15 Nov, 21:24, "Diez B. Roggisch" wrote: >>>> arve.knud... at gmail.com schrieb: >>>>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: >>>>>> arve.knud... at gmail.com schrieb: >>>>>>> Hi >>>>>>> I need to link against Python, is there a way to get the path to the >>>>>>> directory containing Python's C library (e.g., /libs on >>>>>>> Windows)? >>>>>> Most probably from the registry somehow. In general, try & locate a >>>>>> python-executable, and make it execute >>>>>> python -c "import sys; print sys.prefix" >>>>>> Capture that, and you're done. Depending on the OS, the libs then are >>>>>> placed in e.g. /lib. >>>>> That doesn't solve anything, the hard part is figuring out the part >>>>> after .. >>>> AFAIK is that only varying based on the OS. Under unix, it's >>>> /lib/python/ >>>> You can get the platform via sys.platform. >>> Well, my point is that I should like a way to query for this >>> directory, just as I can query distutils.sysconfig for the include >>> directory and Python library (i.e., the standard Python library) >>> directory. It's not trivial to figure out Python's installation scheme >>> so long as it's not written in stone .. >> Well, than how about you word your question like that? But there is no >> simple function to call. So the answer to the question you asked is: no. >> >> I showed you a way that works for current python, and consists of >> stitching together a number of informations. >> >> Diez > > My original question was pretty clear I think. And I don't have the > required information to deduce what the library path may look like on > any given platform, there really should be a standard function for > this. I at least misunderstood it - which might be my fault. However, as there is no such function. I suggest you discuss this on the devel-list - however, anything before python2.7 is unlikely to grow such a function, so you are stuck with the ways I described. Diez From arve.knudsen at gmail.com Sun Nov 15 18:23:10 2009 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Sun, 15 Nov 2009 15:23:10 -0800 (PST) Subject: How to get directory of Python C library References: <7mb1ocF3h5cpfU2@mid.uni-berlin.de> <3b1db70f-20b0-4e60-a9c0-6cbfca07e85d@z41g2000yqz.googlegroups.com> <7mb6b2F3h8d4pU1@mid.uni-berlin.de> <7mb94aF3f97c1U1@mid.uni-berlin.de> <448974cc-7ab5-4945-b94d-4bfd2a28a2cb@b2g2000yqi.googlegroups.com> <7mbfdpF3hr2s9U1@mid.uni-berlin.de> Message-ID: <63acc587-3575-4db1-a142-5783dda694eb@d5g2000yqm.googlegroups.com> On 15 Nov, 23:59, "Diez B. Roggisch" wrote: > arve.knud... at gmail.com schrieb: > > > > > > > On 15 Nov, 22:11, "Diez B. Roggisch" wrote: > >> arve.knud... at gmail.com schrieb: > > >>> On 15 Nov, 21:24, "Diez B. Roggisch" wrote: > >>>> arve.knud... at gmail.com schrieb: > >>>>> On 15 Nov, 20:05, "Diez B. Roggisch" wrote: > >>>>>> arve.knud... at gmail.com schrieb: > >>>>>>> Hi > >>>>>>> I need to link against Python, is there a way to get the path to the > >>>>>>> directory containing Python's C library (e.g., /libs on > >>>>>>> Windows)? > >>>>>> Most probably from the registry somehow. In general, try & locate a > >>>>>> python-executable, and make it execute > >>>>>> ? python -c "import sys; print sys.prefix" > >>>>>> Capture that, and you're done. Depending on the OS, the libs then are > >>>>>> placed in e.g. /lib. > >>>>> That doesn't solve anything, the hard part is figuring out the part > >>>>> after .. > >>>> AFAIK is that only varying based on the OS. Under unix, it's > >>>> ? /lib/python/ > >>>> You can get the platform via sys.platform. > >>> Well, my point is that I should like a way to query for this > >>> directory, just as I can query distutils.sysconfig for the include > >>> directory and Python library (i.e., the standard Python library) > >>> directory. It's not trivial to figure out Python's installation scheme > >>> so long as it's not written in stone .. > >> Well, than how about you word your question like that? But there is no > >> simple function to call. So the answer to the question you asked is: no. > > >> I showed you a way that works for current python, and consists of > >> stitching together a number of informations. > > >> Diez > > > My original question was pretty clear I think. And I don't have the > > required information to deduce what the library path may look like on > > any given platform, there really should be a standard function for > > this. > > I at least misunderstood it - which might be my fault. However, as there > is no such function. I suggest you discuss this on the devel-list - > however, anything before python2.7 is unlikely to grow such a function, > so you are stuck with the ways I described. > > Diez OK, thanks. Perhaps I'll try distutils-sig, given that it looks natural to extend distutils.sysconfig. Arve From rt8396 at gmail.com Sun Nov 15 18:30:23 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 15:30:23 -0800 (PST) Subject: ANN: PyGUI 2.1 References: Message-ID: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> OK this is my third attempt, someone please email me if these messages are getting through. I mailed this only to c.l.py and not the announce group this time, that may have been my previous problems??? Here we go... Hello Greg, I have looked over this kit in the past and it looks quite promising for meeting it stated goals (and mine). One the the best things about it (for me anyway) is the small size and the fact you have an OpenGL widget! I think all GUI kits should support OpenGL out of the box! This is the 21st century as we all know. Also these stated goals are what every GUI package should aspire to. (Hope you don't mind me quoting your site??) """ Develop a GUI API that is designed specifically for Python, taking advantage of Python's unique language features and working smoothly with Python's data types. Provide implementations of the API for the three major platforms (Unix, Macintosh and Windows) that are small and lightweight, interposing as little code as possible between the Python application and the platform's underlying GUI facilities, and not bloating the Python installations or applications which use them. """ I really like this! """ Document the API purely in Python terms, so that the programmer does not need to read the documentation for another GUI library, in terms of another language, and translate into Python. """ This is *so* important for any GUI. wxPython IMO lacks greatly in this department. I very much wish we had docs for wxPython as we do for Tkinter. But even Tkinter needs more details! You should never need to consult the TCL/TK doc's unless you are doing something really advanced. (or evil!) """ Get the library and its documentation included in the core Python distribution, so that truly cross-platform GUI applications may be written that will run on any Python installation, anywhere. """ This i also agree with! While we currently have Tkinter in Python we lack the real docs "in Python" for Tkinter. There are a few very good sites (effbot, NMT, and others) but users must bounce around from site to site to find all this. I want visit one place for a reference and one place only. Tuts can exist on the web. And by "reference" look at this site to see what i mean http://infohost.nmt.edu/tcc/help/pubs/tkinter/ I actually like Tkinter (because of "ease of use") however!, having an embedded TCL interpretor and wrapping TK calls with Python just seems wrong, and Tkinter is notoriously slow (probably due to this fact) as we all know. But after looking over your pyGUI it does "seem" that Tkinter has a richer widget set. (i could be wrong) What are the comparisons between Tkinter and PyGUI. I would love to use a kit that is lighter weight and has better cross platform abilities (and a glWidget to boot!), but i can't sacrifice the widget set. Can you give us a pros and cons of pyGUI versus Tkinter? This will help me decide and i think many others would benefit also. Here is the main widgets of Tkinter: -Entry -Label -Button -RadioButton -CheckButton -Frame -LabelFrame -Text -Listbox -Scrollbar -Scale -Toplevel -Canvas (2d) -Menu -MenuButton -OptionMenu -PanedWindow -Spinbox Easy to use dialogs from: -tkFileDialog -tkSimpleDialog -tkMessageBox Thanks From db3l.net at gmail.com Sun Nov 15 18:42:38 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 15 Nov 2009 18:42:38 -0500 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> <87ac68f2-e26e-4d33-a049-bbf2219b24a5@z41g2000yqz.googlegroups.com> Message-ID: Terry Reedy writes: > r wrote: >> On Nov 14, 4:59 am, kj wrote: >>> But, as I already showed, I'm out of my depth here, >>> so I'd better shut up. >> >> Don't give up so easy! The idea is great, what Paul is saying is that >> most people who read this group use newsreaders and that has nothing >> to do with google groups. These guy's have kill filters for just this >> sort of thing but either way the emails are on their puters so they >> have to deal with them on an individual basis. It would be nice >> however to clean up the Google group version and rid it of the plagues >> of spam infestations. > > Anyone with a newsreader can, like me, read gmane.comp.python.general, > which mirrors python-list, which now filters out much/most of the spam > on c.l.p from G.g. The same is true on some (not sure if it qualifies for many) Usenet servers. I use news.individual.net for example (for a modest yearly fee as of a few years ago) and in my experience it does a great job at filtering spam. I'm sure there are other services that do as well. I don't have to manage any special filters and don't seem to see any of the stuff in this group, for example, mentioned in this thread. I do use gmane for a lot of other lists (including python-dev) that aren't operated as a Usenet newsgroups and it's an excellent service. -- David From lists at cheimes.de Sun Nov 15 19:03:13 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 16 Nov 2009 01:03:13 +0100 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: Steve Howell wrote: > Does anybody have any links that points to the rationale for ignoring > instance definitions of __getitem__ when new-style classes are > involved? I assume it has something to do with performance or > protecting us from our own mistakes? Most magic methods are implemented as descriptors. Descriptors only looked up on the type to increase the performance of the interpreter and to simply the C API. The same is true for other descriptors like properties. The interpreter invokes egg.__getitem__(arg) as type(egg).__getitem__(egg, arg). > So now I am still in search of a way to hook into calls to foo[bar] > after foo has been instantiated. It is all test code, so I am not > particularly concerned about safety or future compatibility. I can do > something really gross like monkeypatch Foo class instead of foo > instance and keep track of the ids to decide when to override > behavior, but there must be a simpler way to do this. Try this untested code: class Spam(dict): def __getitem__(self, key): getitem = self.__dict__.get("__getitem__", dict.__getitem__) return getitem(self, key) Because dict is the most important and speed critical type in Python it has some special behaviors. If you are going to overwrite __getitem__ of a dict subclass then you have to overwrite all methods that call __getitem__, too. These are get, pop, update and setdefault. Christian From wentland at cl.uni-heidelberg.de Sun Nov 15 19:11:42 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 16 Nov 2009 01:11:42 +0100 Subject: How can pip install a GitHub code drop? In-Reply-To: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> References: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> Message-ID: <20091116001142.GC9776@kinakuta.local> On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote: > How can I point pip at the repo to install the library? > sudo pip -e git+git://github.com/Phlip/Kozmiq.git Make that: pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq and (preferably) don't install into system paths ;-) kind regards Wolodja -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From sungsuha at gmail.com Sun Nov 15 19:17:31 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 16:17:31 -0800 (PST) Subject: basic class question.. References: Message-ID: On 11?15?, ??10?15?, Tim Chase wrote: > Pyrot wrote: > > class rawDNA: > > import string > > trans = string.maketrans("GATC","CTAG") > > > def __init__(self, template = "GATTACA"): > > self.template = template //shouldn't this make "template" > > accessible within the scope of "rawDNA"?? > > No. Python's scope resolution consists only of "local, global, > or explicit". There is no "try to find this in the instance or > class" scope-resolution guessing. Your code makes "template" > accessible within the scope of "self", not in a global > unqualified scope. > > So this: > > > def noncoding(self): > > print template.translate(trans) // > > tries to reference "template" first in the local scope (within > noncoding(), but it doesn't exist there), then in the global > scope (it also doesn't exist there), and stops. > > It should be as you have it here: > > > class rawDNA: > > import string > > trans = string.maketrans("GATC","CTAG") > > def __init__(self, template = "GATTACA"): > > self.template = template > > def noncoding(self): > > print self.template.translate(trans) > > Here, you start with "self" which *is* in the local scope, which > *does* contain "template" and so it successfully finds it and all > is [qualifiedly] good. However, you'll also find that "trans" > isn't found because it's neither in the local nor global scope: > > >>> class RawDNA: > ... import string > ... trans = string.maketrans("GATC", "CTAG") > ... def __init__(self, template="GATTACA"): > ... self.template = template > ... def noncoding(self): > ... print self.template.translate(trans) > ... > >>> r = RawDNA() > >>> r.noncoding() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in noncoding > NameError: global name 'trans' is not defined > > so you need to fully qualify it as "RawDNA.trans" for Python to > find it. (I also shifted to using the PEP-8 naming convention > "RawDNA" instead of "rawDNA"). > > Which you indeed discovered: > > > this works as intended. > > Being explicit is part of "Python Zen" (from the python > command-prompt, type "import this" to see the whole list) > > -tkc thanks! one last question, is "self.template.translate(trans)" the right way to go(pythonic?)? I found it to be cumbersome(and a mouthful) and thought I might have been doing it wrong :-) From python at mrabarnett.plus.com Sun Nov 15 19:24:19 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 00:24:19 +0000 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <4B009BB3.90805@mrabarnett.plus.com> Christian Heimes wrote: > Steve Howell wrote: >> Does anybody have any links that points to the rationale for ignoring >> instance definitions of __getitem__ when new-style classes are >> involved? I assume it has something to do with performance or >> protecting us from our own mistakes? > > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. The same is true for other descriptors like > properties. The interpreter invokes egg.__getitem__(arg) as > type(egg).__getitem__(egg, arg). > >> So now I am still in search of a way to hook into calls to foo[bar] >> after foo has been instantiated. It is all test code, so I am not >> particularly concerned about safety or future compatibility. I can do >> something really gross like monkeypatch Foo class instead of foo >> instance and keep track of the ids to decide when to override >> behavior, but there must be a simpler way to do this. > > Try this untested code: > > class Spam(dict): > def __getitem__(self, key): > getitem = self.__dict__.get("__getitem__", dict.__getitem__) > return getitem(self, key) > > Because dict is the most important and speed critical type in Python it > has some special behaviors. If you are going to overwrite __getitem__ of > a dict subclass then you have to overwrite all methods that call > __getitem__, too. These are get, pop, update and setdefault. > I wonder whether it's possible to define 2 behaviours, an optimised one for instances of a class and another non-optimised one for instances of a subclasses. That would make it easier to subclass built-in classes without losing their speed. From sungsuha at gmail.com Sun Nov 15 19:26:59 2009 From: sungsuha at gmail.com (Pyrot) Date: Sun, 15 Nov 2009 16:26:59 -0800 (PST) Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> Message-ID: <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> On 11?15?, ??9?52?, "Diez B. Roggisch" wrote: > Pyrot schrieb: > > > class rawDNA: > > ? ?import string > > Importing here is unusual. Unless you have good reasons to do so, I > suggest you put the imports on top of the file. > > > ? ?trans = string.maketrans("GATC","CTAG") > > > ? ?def __init__(self, template = "GATTACA"): > > ? ? ? ? ? ?self.template = template ?//shouldn't this make "template" > > accessible within the scope of "rawDNA"?? > > No. > > > > > ? ?def noncoding(self): > > ? ? ? ? ? ?print template.translate(trans) ?// > > This needs to be > > ? ?print self.template.translate(trans) > > Thes scopes insied a class are only the method-locals (to which the > parameters count of course), and globals. > > Diez Thanks for the tip Diez. (Tthe core reason that I'm bothering with this at all is because I heard imports are costly(in time, space, processing power). If this turns out to be a non-issue, than my questions regarding Imports are all moot :->) I forgot to write about my second question which was: what happens when I use the import statement within a class/function declaration? I'm thinking either 1) It imports during the class/function declaration 2) It imports the first time a class/function call(x = rawDNA() ) occurs But if it's 2) then is the import valid outside of the function/class? what happens when the last function reference is removed?(del x) obviously this is a lot of questions... I respect your(or anyone who would like to help me) time, so all I ask is some kind of document or "Best practices" guide dealing all about "import".(because sadly, http://docs.python.org/reference/simple_stmts.html#the-import-statement does not ask my questions) From wentland at cl.uni-heidelberg.de Sun Nov 15 19:39:39 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 16 Nov 2009 01:39:39 +0100 Subject: How can pip install a GitHub code drop? In-Reply-To: <20091116001142.GC9776@kinakuta.local> References: <79989d7b-84db-48fe-aca2-2acfcc263c0f@b25g2000prb.googlegroups.com> <20091116001142.GC9776@kinakuta.local> Message-ID: <20091116003939.GD9776@kinakuta.local> On Mon, Nov 16, 2009 at 01:11 +0100, Wolodja Wentland wrote: > On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote: > > How can I point pip at the repo to install the library? > > sudo pip -e git+git://github.com/Phlip/Kozmiq.git > pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq err... pip install -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq ^^^^^^^ ^^^^^^^^^^^ Hope it works -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From showell30 at yahoo.com Sun Nov 15 19:58:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 16:58:43 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <35243ea1-60c6-4bb6-afba-7673a060768a@g1g2000pra.googlegroups.com> On Nov 15, 4:03?pm, Christian Heimes wrote: > Steve Howell wrote: > > Does anybody have any links that points to the rationale for ignoring > > instance definitions of __getitem__ when new-style classes are > > involved? ?I assume it has something to do with performance or > > protecting us from our own mistakes? > > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. The same is true for other descriptors like > properties. The interpreter invokes egg.__getitem__(arg) as > type(egg).__getitem__(egg, arg). > Is the justification along performance lines documented anywhere? > > So now I am still in search of a way to hook into calls to foo[bar] > > after foo has been instantiated. ?It is all test code, so I am not > > particularly concerned about safety or future compatibility. ?I can do > > something really gross like monkeypatch Foo class instead of foo > > instance and keep track of the ids to decide when to override > > behavior, but there must be a simpler way to do this. > > Try this untested code: > > class Spam(dict): > ? ? def __getitem__(self, key): > ? ? ? ? getitem = self.__dict__.get("__getitem__", dict.__getitem__) > ? ? ? ? return getitem(self, key) > [...] Not sure how this helps me, unless I am misunderstanding... It is the futility of writing lowercase_spam.__getitem__ that is setting me back. For my use case I do not want to override __getitem__ for all Spam objects, nor do I even have the option to modify the Spam class in some cases. From missive at hotmail.com Sun Nov 15 20:20:32 2009 From: missive at hotmail.com (Lee Harr) Date: Mon, 16 Nov 2009 05:50:32 +0430 Subject: [ANNC] acromania-0.5 Message-ID: Acromania is a word game of acronyms. This program is a computer moderator for networked games of acromania. It can connect to a channel on IRC, or start a standalone server which can be accessed much like a MUD. http://acromania.googlecode.com/ Acromania uses Twisted and SQLite. Optionally, it can use NLTK to generate computer opponents. Acromania is released under GPLv3. Changes in acromania-0.5: ??? - add versioning for database ??? - make building and loading bots more resilient ??? - sort score report ??? - add info command for in-game contact information ??? - allow listing top10 acros per player ??? - make leaderboard and top10 more resilient when empty ??? - improve color usage ??? - allow user to change password ??? - add admin user account ??? - allow admin user to change any user's password Notes: ??? I have only played the game using the standalone ??? server on a secure network. If you have experience ??? with programming IRC bots securely, please take ??? a look and contact me if you see any problems. ??? If you decide to connect it to IRC, please let me ??? know, because I'd like to play :o) _________________________________________________________________ Windows Live: Make it easier for your friends to see what you?re up to on Facebook. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009 From gagsl-py2 at yahoo.com.ar Sun Nov 15 20:35:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 22:35:14 -0300 Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Message-ID: En Sun, 15 Nov 2009 09:04:06 -0300, vsoler escribi?: > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > been saving my > *.py files in the C:\Program Files\Python26 directory, which is the > default directory for such files in my system. > > However, I have realised that the above is not the best practice. > Therefore I created the C:\Program Files\Python26\test directory and I > want it to be my default directory for saving *.py files, importing > modules, etc. This is *not* a good place either. Non-privileged users should not have write permission in the C:\Program Files directory. > I'd like to do something like the DOS equivalent of "CD test" but I > do not know kow to do it. > > I am currently doing something really awful: I open a *.py file in the > test subdirectory, I run it with the F5 key and it works! but I am > doing really something stupid. "it works!" What's the problem then? > How should I proceed, if I want to proceed properly? Sorry but I don't even see your problem. You can save your .py files anywhere you like... -- Gabriel Genellina From showell30 at yahoo.com Sun Nov 15 20:35:53 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 15 Nov 2009 17:35:53 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <35243ea1-60c6-4bb6-afba-7673a060768a@g1g2000pra.googlegroups.com> Message-ID: <77cf9e89-0e99-405c-ad3b-fea6e916cef7@j9g2000prh.googlegroups.com> On Nov 15, 4:58?pm, Steve Howell wrote: > On Nov 15, 4:03?pm, Christian Heimes wrote: > > > Try this untested code: > > > class Spam(dict): > > ? ? def __getitem__(self, key): > > ? ? ? ? getitem = self.__dict__.get("__getitem__", dict.__getitem__) > > ? ? ? ? return getitem(self, key) > > [...] > > [I originally responded...] Not sure how this helps me, unless I am misunderstanding... > Ok, now I get where you were going with the idea. The following code runs as expected. Even in pure testing mode, I would want to make it a little more robust, but it illustrates the basic idea that you can monitor just particular objects by overriding the class method to look for an attribute on the instance before doing any special processing. class MyDict(dict): pass dict1 = MyDict() dict1['foo'] = 'bar' dict2 = MyDict() dict2['spam'] = 'eggs' dict3 = MyDict() dict3['BDFL'] = 'GvR' def spy(dict): def mygetitem(self, key): if hasattr(self, '__SPYING__'): value = self.__class__.__old_getitem__(self, key) print 'derefing %s to %s on %s' % (key, value, self) return value if not hasattr(dict.__class__, '__HOOKED__'): setattr(dict.__class__, '__old_getitem__', dict.__class__.__getitem__) setattr(dict.__class__, '__getitem__', mygetitem) setattr(dict.__class__, '__HOOKED__', True) dict.__SPYING__ = True dict1['foo'] # not spied yet spy(dict1) # this changes class and instance dict1['foo'] # spied dict2['spam'] # not spied spy(dict3) # this only changes instance dict3['BDFL'] # spied dict2['spam'] # spied Thanks, Christian! From gagsl-py2 at yahoo.com.ar Sun Nov 15 21:56:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 15 Nov 2009 23:56:18 -0300 Subject: tkFileDialog question References: Message-ID: En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell escribi?: > answer = tkFileDialog.askdirectory() > > if answer is not '': > #do stuff Although it "reads well", this is *wrong*. You want != here, not the `is not` operator. if answer != '': ... If you want to compare the *values* of two objects, to see if they are equal or not, use == or !=. If you want to compare *identity*, to see if two results refer to the very same object or not, use `is` or `is not` (In your example, it *may* appear to work, because CPython optimizes very short strings like 'a' or '', but you should not rely on this optimization) -- Gabriel Genellina From rt8396 at gmail.com Sun Nov 15 22:27:38 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 19:27:38 -0800 (PST) Subject: tkFileDialog question References: Message-ID: On Nov 15, 8:56?pm, "Gabriel Genellina" wrote: > En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell ? > escribi?: > > > answer = tkFileDialog.askdirectory() > > > if answer is not '': > > ? ?#do stuff > > Although it "reads well", this is *wrong*. You want != here, not the `is ? > not` operator. > > if answer != '': ... > > If you want to compare the *values* of two objects, to see if they are ? > equal or not, use == or !=. > If you want to compare *identity*, to see if two results refer to the very ? > same object or not, use `is` or `is not` Actually "Gabe" your right and wrong.. the pythonic way to check for True/False is.. path = tkFileDialog.askwhatever() if path: #do something here NOT if path != '': #do something here Both work equally but the first is more Pythonic! UNLESS you are specifically testing for anything but the empty string that is. In that case your way *is* correct. But that is not the case with a file dialog return value. Yes the dialog returns either an empty string OR a valid path but True False is all that matters here when deciding whether to act on that path -- or not act on it. NOT whether or not it is an empty string. From sturlamolden at yahoo.no Sun Nov 15 22:29:08 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:29:08 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> <7man75F3gh0lgU1@mid.individual.net> Message-ID: <75d106a6-c2a1-4640-90d9-510864bd2fd1@b15g2000yqd.googlegroups.com> On 15 Nov, 17:05, Dietmar Schwertberger wrote: > > Could you send me an .fbp file demonstrating the error? > > Sent by email. Did you receive it? No... could you please resend to sturla at molden.no? From sturlamolden at yahoo.no Sun Nov 15 22:32:25 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:32:25 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <7m89l8F3g1lnpU1@mid.individual.net> <9bb1185e-0fbc-4fa0-adc2-704ae8b1b358@l13g2000yqb.googlegroups.com> <7man75F3gh0lgU1@mid.individual.net> Message-ID: <13e60e57-3e67-402e-9182-5ae13b5ec46f@b15g2000yqd.googlegroups.com> On 15 Nov, 17:05, Dietmar Schwertberger wrote: > Sent by email. Did you receive it? > Yes I did, thank you :) (I thought I didn't, but it was just a problem with my e-mail filter.) From sturlamolden at yahoo.no Sun Nov 15 22:42:40 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 19:42:40 -0800 (PST) Subject: Choosing GUI Module for Python References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> Message-ID: <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> On 14 Nov, 15:35, Dietmar Schwertberger wrote: > ? ?self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) > ? ?self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", > wx.DefaultPosition, wx.DefaultSize, 0 ) > ? ?m_toolBar1.AddControl( m_button1 ) I can confirm this. There seems to be a bug in the generation of Python code for wxToolBar. From nagle at animats.com Sun Nov 15 23:09:44 2009 From: nagle at animats.com (John Nagle) Date: Sun, 15 Nov 2009 20:09:44 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> Message-ID: <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Paul Boddie wrote: > On 15 Nov, 09:30, Terry Reedy wrote: >> greg wrote: >> > > [Shed Skin] > >>> These restrictions mean that it isn't really quite >>> Python, though. >> Python code that only uses a subset of features very much *is* Python >> code. The author of ShedSkin makes no claim that is compiles all Python >> code. > > Of course, Shed Skin doesn't support all the usual CPython features, > but the code you would write for Shed Skin's benefit should be Python > code that runs under CPython. It's fair to say that Shed Skin isn't a > "complete" implementation of what CPython defines as being "the full > Python", but you're still writing Python. One can argue that the > restrictions imposed by Shed Skin inhibit the code from being "proper" > Python, but every software project has restrictions in the form of > styles, patterns and conventions. > > This is where the "Lesser Python" crowd usually step in and say that > they won't look at anything which doesn't support "the full Python", > but I think it's informative to evaluate which features of Python give > the most value and which we could do without. The "Lesser Python" > attitude is to say, "No! We want it all! It's all necessary for > everything!" That doesn't really help the people implementing "proper" > implementations or those trying to deliver better-performing > implementations. > > In fact, the mentality that claims that "it's perfect, or it will be > if we keep adding features" could drive Python into a diminishing > niche over time. In contrast, considering variations of Python as some > kind of "Greater Python" ecosystem could help Python (the language) > adapt to the changing demands on programming languages to which Go > (the Google language, not Go! which existed already) is supposedly a > response. Yes. Niklaus Wirth, who designed Pascal, Modula, and Oberon, had that happen to his languages. He's old and bitter now; a friend of mine knows him. The problem is that "Greater Python" is to some extent "the set of features that are easy to implement if we look up everything at run time." You can insert a variable into a running function of another thread. This feature of very marginal utility is free in a naive lookup-based interpreter, and horribly expensive in anything that really compiles. Obsession with the CPython implementation as the language definition tends to overemphasize such features. The big headache from a compiler perspective is "hidden dynamism" - use of dynamic features that isn't obvious from examining the source code. (Hidden dynamism is a big headache to maintenance programmers, too.) For example, if you had the rule that you can't use "getattr" and "setattr" on an object from the outside unless the class itself implements or uses getattr and setattr, then you know at compile time if the machinery for dynamic attributes needs to be provided for that class. This allows the "slots" optimization, and direct compilation into struct-type code. Python is a very clean language held back from widespread use by slow implementations. If Python ran faster, Go would be unnecessary. And yes, performance matters when you buy servers in bulk. John Nagle From sturlamolden at yahoo.no Sun Nov 15 23:10:06 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 20:10:06 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <030f6ffb$0$1313$c3e8da3@news.astraweb.com> Message-ID: On 15 Nov, 05:21, Steven D'Aprano wrote: > Psyco does JIT compilation to machine-code for CPython, at the cost of > much extra memory. It's also limited to 32-bit Intel processors. The aim > of the PyPy project is to (eventually) make JIT machine-code compilation > available to any Python, on any machine. Who wants a JIT when it's orders of magnitude slower than interpreted Python? From sturlamolden at yahoo.no Sun Nov 15 23:51:29 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 20:51:29 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: On 16 Nov, 05:09, John Nagle wrote: > ? ? ? Python is a very clean language held back from widespread use by slow > implementations. ?If Python ran faster, Go would be unnecessary. That boggles me. NASA can find money to build a space telescope and put it in orbit. They don't find money to create a faster Python, which they use for analyzing the data. Google is a multi-billion dollar business. They are using Python extensively. Yes I know about Unladen Swallow, but why can't they put 1 mill dollar into making a fast Python? And then there is IBM and Cern's Blue Brain project. They can set up the fastest supercomputer known to man, but finance a faster Python? No... I saw this myself. At work I could get money to buy a ? 30,000 recording equipment. I could not get money for a MATLAB license. It seems software and software development is heavily underfinanced. The big bucks goes into fancy hardware. But fancy hardware is not so fancy without equally fancy software. From sturlamolden at yahoo.no Mon Nov 16 00:02:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:02:13 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <15e9625a-4cac-49f3-a16c-d6d0b854d97c@c3g2000yqd.googlegroups.com> On 16 Nov, 05:09, John Nagle wrote: > ? ? ? Python is a very clean language held back from widespread use by slow > implementations. Python is clean, minimalistic, and beautiful. Python don't have bloat like special syntax for XML or SQL databases (cf C#) or queues (Go). Most of all, it is easier to express ideas in Python than any computer language I know. Python's major drawback is slow implementations. I always find myself resorting to Cython (or C, C++, Fortran 95) here and there. But truth being told, I wrote an awful lot of C mex files when using MATLAB as well. MATLAB can easily be slower than Python by orders of magnitude, but it has not preventet it from widespread adoption. What's keeping it back is an expensive license. From sturlamolden at yahoo.no Mon Nov 16 00:09:21 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:09:21 -0800 (PST) Subject: IDE for python References: Message-ID: On 15 Nov, 18:09, Peng Yu wrote: > There had been some discussion on IDE. But I'm not sure what pros and > cons of each choice. Current, I'm using vim and ctags. > > Could somebody give some advices on choosing the best IDE for me? There is a plug-in to develop (amd debug) Python using MS Visual Studio. It works with IronPython and CPython. There is the PyDev plug-in for Eclipse. There is Komodo from ActiveState. There is KDevelop in KDE4. Which is better? I don't know. My impression is that Python development does noe need an IDE like e.g. C++ development do. There is no build process, which takes the major advantage of the IDE away. I am fine with a editor like IDLE or Kate. From sajmikins at gmail.com Mon Nov 16 00:10:47 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 16 Nov 2009 00:10:47 -0500 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy wrote: > Paul Rubin wrote: > >> Mark Chu-Carroll has a new post about Go: >> >> >> ?http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php > > In a couple of minutes, I wrote his toy prime filter example in Python, > mostly from the text rather than the code, which I can barely stand to read. > It ran the first time without error. > > def plurals(): > ?i = 2 > ?while True: > ? ?yield i > ? ?i += 1 > > def primefilter(src, prime): > ?for i in src: > ? ?if i % prime: > ? ? ?yield i > > src = plurals() > while True: > ?i = next(src) > ?print(i) > ?src = primefilter(src, i) > > As I commented there > "It stopped at 7877 when it hit the default recursion limit of 1000, which > could easily be increased to get out-of-memory error instead. > > I think Google is making a blunder if it moves to another old-fashioned > language whose code is bloated with junky boilerplate that doubles the size. > It would be much better, for instance, to tweak Python, which it has had > great success with, to better run on multiple cores." > > Terry Jan Reedy FWIW, def plurals(): i = 3 while True: yield i i += 2 From rt8396 at gmail.com Mon Nov 16 00:15:41 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 21:15:41 -0800 (PST) Subject: tkFileDialog question References: Message-ID: Matt, There is also a nice thing you need to know about Python if you already do not know. That is the fact that all empty collections bool to False. This makes Truth testing easier. >>> bool([]) False >>> bool('') False >>> bool({}) False >>> bool([1]) True >>> bool([[]]) True >>> bool(' ') True any empty collection, string, or 0 always bools to False. From sturlamolden at yahoo.no Mon Nov 16 00:25:53 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 15 Nov 2009 21:25:53 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: On 14 Nov, 23:10, Terry Reedy wrote: > It would be much better, for instance, to tweak Python, which it > has had great success with, to better run on multiple cores." Python run well on multiple cores, you just have to use processes instead of threads. From arts.martijn at gmail.com Mon Nov 16 01:37:58 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Mon, 16 Nov 2009 07:37:58 +0100 Subject: Pokemon gamestyle in Python Message-ID: <23739e0a0911152237r3a4da2bfle0c20e3fe773f8a9@mail.gmail.com> First; sorry, the title might be somewhat unclear about what I mean. Then; I know PyGame and I've worked with it, but I want to make a Pokemon/Legend of Zelda style game with a moving guy on a map. So what I'm asking is; is there anything better than PyGame for this gamestyle? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 16 02:10:40 2009 From: rt8396 at gmail.com (r) Date: Sun, 15 Nov 2009 23:10:40 -0800 (PST) Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> Message-ID: <6b2330ff-ae25-43c2-accc-9b12208240c6@a31g2000yqn.googlegroups.com> On Nov 15, 6:26?pm, Pyrot wrote: > what happens when I use the import statement within a class/function > declaration? > I'm thinking either > 1) It imports during the class/function declaration > 2) It imports the first time a class/function call(x = rawDNA() ) > occurs > > But if it's 2) then is the import valid outside of the function/class? > what happens when the last function reference is removed?(del x) Well just fire up you interpretor fella! >>> class A(): def __init__(self): import sys print sys.version >>> a = A() 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] >>> 'sys' in dir() False >>> print sys.version Traceback (most recent call last): File "", line 1, in print sys.version NameError: name 'sys' is not defined ;-) From gagsl-py2 at yahoo.com.ar Mon Nov 16 02:27:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 04:27:37 -0300 Subject: Python 2.6.3 TarFile Module Add odd behavior References: <49AA837A96E75E4C8CD87901F7F14080032B1228@XMBIL103.northgrum.com> Message-ID: En Fri, 13 Nov 2009 16:23:31 -0300, Tilson, Greg (IS) escribi?: > In Windows Python 2.6.3 calling TarFile.add requires arcname= to be set > to work with WinZIP or WinRAR [...]If arcname= is not set during > extraction all filenames are "None" > > Suggest document change or filing a bug report Post some code showing your problem. I wrote a quick test and worked fine for me. -- Gabriel Genellina From tjreedy at udel.edu Mon Nov 16 04:00:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 04:00:59 -0500 Subject: Python & Go In-Reply-To: <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> <50f98a4c0911152110x42db8f3dle62b053963d14a1@mail.gmail.com> Message-ID: Simon Forman wrote: > On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy wrote: >> Paul Rubin wrote: >> >>> Mark Chu-Carroll has a new post about Go: >>> >>> >>> http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php >> In a couple of minutes, I wrote his toy prime filter example in Python, >> mostly from the text rather than the code, which I can barely stand to read. >> It ran the first time without error. >> >> def plurals(): >> i = 2 >> while True: >> yield i >> i += 1 >> >> def primefilter(src, prime): >> for i in src: >> if i % prime: >> yield i >> >> src = plurals() >> while True: >> i = next(src) >> print(i) >> src = primefilter(src, i) >> >> As I commented there >> "It stopped at 7877 when it hit the default recursion limit of 1000, which >> could easily be increased to get out-of-memory error instead. >> >> I think Google is making a blunder if it moves to another old-fashioned >> language whose code is bloated with junky boilerplate that doubles the size. >> It would be much better, for instance, to tweak Python, which it has had >> great success with, to better run on multiple cores." >> >> Terry Jan Reedy > > FWIW, > > def plurals(): > i = 3 > while True: > yield i > i += 2 Of course, in fact, I thought of at the time def plurals(): i = 6 while True: yield i-1 yield i+1 i += 6 5,7, 11,13, 17,19, 23,(25-first miss), 29,31, (35-2nd miss),37, 41,43, 47,(49 erd)...Reduced the base cases by another 1/3. I *think* without measuring, that that compensates for the extra -1,+1. But I was implementing *Mark's* toy example, and first posted it on his blog, so I copied his naive version. Even better, to avoid extra -1, +1 def plurals(): yield 2 yield 3 i = 5 while True: yield i i += 2 yield i i += 4 Of course, testing with primes greater that square root(candidate) is wasteful, and recusion should be converted to iteration to avoid recursion limit. Terry Jan Reedy From tartley at tartley.com Mon Nov 16 04:05:54 2009 From: tartley at tartley.com (Jonathan Hartley) Date: Mon, 16 Nov 2009 01:05:54 -0800 (PST) Subject: IDE for python References: Message-ID: On Nov 16, 5:09?am, sturlamolden wrote: > On 15 Nov, 18:09, Peng Yu wrote: > > > There had been some discussion on IDE. But I'm not sure what pros and > > cons of each choice. Current, I'm using vim and ctags. > > > Could somebody give some advices on choosing the best IDE for me? > > There is a plug-in to develop (amd debug) Python using MS Visual > Studio. It works with IronPython and CPython. > > There is the PyDev plug-in for Eclipse. > > There is Komodo from ActiveState. > > There is KDevelop in KDE4. > > Which is better? I don't know. > > My impression is that Python development does noe need an IDE like > e.g. C++ development do. There is no build process, which takes the > major advantage of the IDE away. I am fine with a editor like IDLE or > Kate. I'd like to offer the group the anecdote of the great Resolver IDE migration. Developers at Resolver, where I work, choose their own IDE. Being developers, that meant every single person chose a different one. We had them all. Which turned out, slightly unexpectedly, to be just fine. We pair on all production code. So this meant we all spent a lot of time sitting at each other's desks. We soon all became pretty familiar with each other's environments - there's nothing like 8 hours a day of hands-on usage, coupled with sitting right next to a bone-fide expert to get you up to speed pretty quick. I even learned a little Emacs, holy cow! Occasionally, after seeing the details of how well some other IDE worked, developers would switch from one to another. Then, after about a year, a curious thing happened. One by one, in entirely independent decisions, almost all developers decided to migrate to either Emacs or Vi.* Each person decided that the fancy features of their IDE wasn't as useful to them as having a flexible, powerful and lightweight editor which can easily be scripted to provide whatever ad-hoc features they need. I regard this as an example of the way pairing spreads knowledge. * I say 'most developers' - there were two notable exceptions: Michael Foord, who's prodigious contributions are legend, who likes Wing, and Will Reade, our tame brainiac, responsible for the exceedingly clever 'IronClad' open-source project, who likes the uncomplicated simplicity of TextPad. As far as I can make out, TextPad has only two features, syntax highlighting and the ability to define a 'make' command, and a regex that is used to extract filenames and line-numbers from the resulting output of that make command. These are, it turns out, sufficient to transform a program that would otherwise simply be 'Notepad' into an entirely credible development environment. From tjreedy at udel.edu Mon Nov 16 04:06:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 04:06:07 -0500 Subject: Python & Go In-Reply-To: References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: sturlamolden wrote: > On 14 Nov, 23:10, Terry Reedy wrote: > >> It would be much better, for instance, to tweak Python, which it >> has had great success with, to better run on multiple cores." > > Python run well on multiple cores, you just have to use processes > instead of threads. But not so trivially as to add one word to an existing function. Hence by tweak, I meant, as explained in another post, to add a keyword or just a decorator that will do what the go keyword does in go. From lallous at lgwm.org Mon Nov 16 05:03:27 2009 From: lallous at lgwm.org (lallous) Date: Mon, 16 Nov 2009 11:03:27 +0100 Subject: C api question and determining PyObject type Message-ID: Hello I have an a class defined as: class __object(object): pass Now, I call a C function that takes a PyObject* and checks its type: if (PyString_Check(obj)) ... if (PySequence_Check(obj)) .... Before doing the check, I print the passed object with PyObject_Str() and get: passed object: <__main__.__object object at 0x040E4050> However, the C code returns true on the: if (PySequence_Check(obj)) .... Why? That is not a sequence? Please advise. -- Elias From not_here at nowhere.com Mon Nov 16 05:06:02 2009 From: not_here at nowhere.com (me) Date: Mon, 16 Nov 2009 02:06:02 -0800 Subject: python gui builders Message-ID: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Good People I do not write stuff for humans, as it has been my job to remove humans from the loop. But I have to make a front end to a component database where everything was built in Python. I have looked at the Tk stuff that is built into Python -> not acceptable. So looking at wxGlade, Boa Constructor, Python Card. Also looked at the frames/forms created with QtDesigner, which can be used by Python via pyuic. BlackAdder IDE seems to have this built-in, but am loathe to buy into another GUI tool for a single job. I have not been able to find a decent Python gui builder. The last time I did gui garbage was with Borland C++ Builder which was ok because I was only using win boxen for that project. This time I am using both Linux and Win. What Python gui builder is well supported, does not require me to learn another framework/library, and can crank out stuff for multiple platforms ? thanks much, me From vs at it.uu.se Mon Nov 16 05:14:26 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 16 Nov 2009 11:14:26 +0100 Subject: Accessing a Web server --- how? Message-ID: <4B012602.7000606@it.uu.se> If one goes to the following URL: http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html it contains a link (click on "Current courses NBD AT99 3113A") to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& and if you now click on the tab labeled "history and compare" this will take you to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& Finally...This is where I would like to "connect to" the data on a daily basis or to gather data over different time intervals. I believe that if I can get some help on this, then I will be able to customize the code as needed for my own purposes. It should be clear that this is financial data on a fond managed by Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. Note, that I do have some experience with Python (2.6 mainly), and find it a very useful and powerful language. However, I have no experience with it in the area of Web services. Any suggestions/comments on how to set up this financial data service project would be greatly appreciated, and I would be glad to share this project with any interested parties. Note, I posted a similar message to the list pywebsvcs; but, received no responses. -- V. Stokes From sturlamolden at yahoo.no Mon Nov 16 05:27:28 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:27:28 -0800 (PST) Subject: IDE for python References: Message-ID: <79fcc08c-b904-4850-80c3-0be030447f52@a31g2000yqn.googlegroups.com> On 16 Nov, 10:05, Jonathan Hartley wrote: > As far as I can make out, TextPad has only two features, syntax > highlighting and the ability to define a 'make' command, and a regex > that is used to extract filenames and line-numbers from the resulting > output of that make command. These are, it turns out, sufficient to > transform a program that would otherwise simply be 'Notepad' into an > entirely credible development environment. When working with Java or C++ I like and IDE like KDevelop because it makes makefiles for me. And when debugging it is easier to insert break points graphically than use gdb from the terminal. But apart from that, I prefer a tiny editor like Kate (yes I know, call me a heretic for not using emacs). From pavlovevidence at gmail.com Mon Nov 16 05:35:07 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 02:35:07 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Nov 15, 2:52?pm, Steve Howell wrote: > Does anybody have any links that points to the rationale for ignoring > instance definitions of __getitem__ when new-style classes are > involved? ?I assume it has something to do with performance or > protecting us from our own mistakes? "Not important enough to justify complexity of implementation." I doubt they would have left if out of new-style classes if it had been straightforward to implement (if for no other reason than to retain backwards compatibility), but it wasn't. The way attribute lookups work meant it would have required all kinds of double lookups and edge cases. Some regarded it as dubious to begin with. And it's easily worked around by simply having __getitem__ call another method, as you've seen. Given all this it made better sense to just leave it out of new-style classes. Unfortunately not all such decisions and justifications are collected in a tidy place. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 05:39:10 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:39:10 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> On 16 Nov, 11:06, me wrote: > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? I use wxFormBuilder. The 3.1 beta can even create wxPython code, but it still has some minor issues (e.g. not always creating correct code due to missing "self."). wxFormBuilder 3.0 can create XRC files, which work excellently with wxPython. The drawback is that you must bind event handlers manually, instead of having it done automatically (as you can with Python code generation in 3.1 beta). If you are fine with GPL, or can afford the commercial license, there is QtDesigner which works with PyQt. This is a fantastic cross- platform GUI tool, if not hte best there is. If you are fine with Microsoft only, you can use Windows Forms with MS Visual Studio and IronPython. If you can use Jython, there are many tools for working with Java Swing or SWT. From news at schwertberger.de Mon Nov 16 05:39:51 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Mon, 16 Nov 2009 11:39:51 +0100 Subject: IDE for python In-Reply-To: References: Message-ID: <7mcofsF3hl5c5U1@mid.individual.net> sturlamolden schrieb: > On 15 Nov, 18:09, Peng Yu wrote: >> There had been some discussion on IDE. But I'm not sure what pros and >> cons of each choice. Current, I'm using vim and ctags. >> >> Could somebody give some advices on choosing the best IDE for me? > > There is a plug-in to develop (amd debug) Python using MS Visual > Studio. It works with IronPython and CPython. > > There is the PyDev plug-in for Eclipse. > > There is Komodo from ActiveState. > > There is KDevelop in KDE4. > > Which is better? I don't know. > > My impression is that Python development does noe need an IDE like > e.g. C++ development do. There is no build process, which takes the > major advantage of the IDE away. I am fine with a editor like IDLE or > Kate. For more than ten years I had the same opinion. I found that a very lightweight "IDE" like PythonWin is sufficient for me together with print statements and the built-in post-mortem debugger for debugging. But then, last year I had to find a tricky bug in my GUI code (wxPython) and thought that for this problem a debugger would be helpful. So I gave the Wing IDE with it's debugger a try and have been using it since then. Even though an IDE is not an absolute must, I found that my productivity increased a lot (25%?) and I would not want to miss: - code completion - powerful debugger (even if you only use the post-mortem debugger it will save you a lot of time compared to pdb.pm() as it takes only a mouse click to move to the exception point in the editor instead of looking at the line number and then find the same point in the editor...) - Mercurial integration - PyFlakes integration Regards, Dietmar From pavlovevidence at gmail.com Mon Nov 16 05:42:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 02:42:05 -0800 (PST) Subject: IDE for python References: Message-ID: On Nov 16, 1:05?am, Jonathan Hartley wrote: > Then, after about a year, a curious thing happened. One by one, in > entirely independent decisions, almost all developers decided to > migrate to either Emacs or Vi.* > > Each person decided that the fancy features of their IDE wasn't as > useful to them as having a flexible, powerful and lightweight editor > which can easily be scripted to provide whatever ad-hoc features they > need. > > I regard this as an example of the way pairing spreads knowledge. That's the best justification for pair programming I've seen yet. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 05:42:51 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 02:42:51 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> Message-ID: On 16 Nov, 11:39, sturlamolden wrote: > If you are fine with Microsoft only, you can use Windows Forms with MS > Visual Studio and IronPython. I also forgot to mention: If you can restrict yourself to Windows, you can always use Visual Basic or Borland Delphi with pywin32. Either expose your GUI as an ActiveX to pywin32 (you have e.g. an MFC binding) or expose your Python as an ActiveX to VB/Delphi. The same approach should work (with a little bit more work) for C# and VB.NET. From lallous at lgwm.org Mon Nov 16 05:44:34 2009 From: lallous at lgwm.org (lallous) Date: Mon, 16 Nov 2009 11:44:34 +0100 Subject: C api question and determining PyObject type References: Message-ID: Actually, the object class is defined as: class __object(object): def __getitem__(self, idx): return getattr(self, idx) Anyway, now I check like this: bool PyIsSequenceType(PyObject *obj) { if (!PySequence_Check(obj)) return false; Py_ssize_t sz = PySequence_Size(obj); if (sz == -1 || PyErr_Occurred() != NULL) { PyErr_Clear(); return false; } return true; } I don't like it, any other suggestions? -- Elias "lallous" wrote in message news:hdr80a$vsg$1 at aioe.org... > Hello > > I have an a class defined as: > > class __object(object): > pass > > Now, I call a C function that takes a PyObject* and checks its type: > > if (PyString_Check(obj)) ... > if (PySequence_Check(obj)) .... > > Before doing the check, I print the passed object with PyObject_Str() and > get: > > passed object: <__main__.__object object at 0x040E4050> > > However, the C code returns true on the: > if (PySequence_Check(obj)) .... > > > Why? That is not a sequence? > From sturlamolden at yahoo.no Mon Nov 16 06:05:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 03:05:13 -0800 (PST) Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <99fff8de-5ecc-4bde-b486-f66b018532dc@g27g2000yqn.googlegroups.com> On 16 Nov, 10:06, Terry Reedy wrote: > > Python run well on multiple cores, you just have to use processes > > instead of threads. > > But not so trivially as to add one word to an existing function. > Hence by tweak, I meant, as explained in another post, to add a keyword > or just a decorator that will do what the go keyword does in go. A decorator function like @go could just call os.fork and run the function in the child. We already have a between-process Queue in multiprocessing to use as channels. Or we could have a context manager that forks in __enter__ and waitpids or exits in __exit__. The body of the with-statement would then be executed in the child process, the parent would just raise an exception to skip directly to __exit__. Not rocket science as all. Yes that would give us a new isolated process, but such isolation is present in Erlang as well. (Windows is more tricky though, as there is no efficent fork.) From eden at bicikl. Mon Nov 16 07:08:10 2009 From: eden at bicikl. (Eden Kirin) Date: Mon, 16 Nov 2009 13:08:10 +0100 Subject: SCGIServer and unusal termination Message-ID: Hi there, I'm playing with SCGIServer (http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), everything works just fine, but one thing bothers me. All prints after try-except block are executed twice after the Ctrl+C is pressed! test.py: #------------------------- from scgi.scgi_server import SCGIServer n = 0 print "Starting server." try: SCGIServer().serve() except (KeyboardInterrupt, SystemExit): print "Exception!" # print lines are executed twice (?!) n += 1 print "Terminating server, attempt %d." % n n += 1 print "Check n: %d." % n #------------------------- This is the output: eden at sunce:~/data/project/ScgiServer/src> python test.py Starting server. ^CException! Exception! Terminating server, attempt 1. Check n: 2. Terminating server, attempt 1. Check n: 2. eden at sunce:~/data/project/ScgiServer/src> If I put something else in try-except block, code after is executed normally: try: while 1: pass except (KeyboardInterrupt, SystemExit): print "Exception!" eden at sunce:~/data/project/ScgiServer/src> python test.py Starting server. ^CException! Terminating server, attempt 1. Check n: 2. eden at sunce:~/data/project/ScgiServer/src> Environment is 64bit Ubuntu with Python v2.6.4. Is there some reasonable explanation for this behaviour? Thanks in advance. -- www.vikendi.net -/- www.supergrupa.com From chen_zhitao at yahoo.com Mon Nov 16 07:50:09 2009 From: chen_zhitao at yahoo.com (Kuhl) Date: Mon, 16 Nov 2009 04:50:09 -0800 (PST) Subject: import subprocess in python Message-ID: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> I am a Linux user beginning to learn Python now. Below is the first Python script that I copied from the text book. It works, so it confirmed that there is python installed in my system: #!/usr/bin/env python for a in [1, 2]: for b in ['a', 'b']: print a, b But when I continue to learn Python, I come across with issue. The text book instructed me to use ipython, but ipython command is not found in my system, so I have to use python instead. However, "import subprocess" still failed, see below. # which python /usr/bin/python # which ipython ipython: Command not found. # python Python 2.2.3 (#1, Feb 2 2005, 12:22:48) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess Traceback (most recent call last): File "", line 1, in ? ImportError: No module named subprocess >>> So I guess that there should be a file named subprocess.py somewhere. But there are too many files on the huge disk, I don't know where I should start to search for it. Then I tried to key in a function file python_func_00.py by myself. def pyfunc(): print "Hello function" # python Python 2.2.3 (#1, Feb 2 2005, 12:22:48) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import python_func_00 >>> pyfunc() Traceback (most recent call last): File "", line 1, in ? NameError: name 'pyfunc' is not defined >>> >>> There's a binary file of 240 bytes created: python_func_00.pyc But as we can see above, the function pyfunc() does not work. I guess that I should add the following statement at first line of python_func_00.py, then redo the import: #!/usr/bin/env python But after adding this line and redoing the import, pyfunc() still failed like above. What's the mistake that I am making? How to solve it? Thanks. From sturlamolden at yahoo.no Mon Nov 16 07:58:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 04:58:00 -0800 (PST) Subject: import subprocess in python References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> Message-ID: <0834aa40-c2f8-4865-aa8d-cc9c4c272b0a@v25g2000yqk.googlegroups.com> On 16 Nov, 13:50, Kuhl wrote: > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > What's the mistake that I am making? How to solve it? Your Python version is too old. From clp2 at rebertia.com Mon Nov 16 08:04:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 05:04:02 -0800 Subject: import subprocess in python In-Reply-To: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> Message-ID: <50697b2c0911160504k3a634c23le9867f583b01bd0f@mail.gmail.com> On Mon, Nov 16, 2009 at 4:50 AM, Kuhl wrote: > found in my system, so I have to use python instead. However, "import > subprocess" still failed, see below. > > # which python > /usr/bin/python > # which ipython > ipython: Command not found. > # python > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import subprocess > Traceback (most recent call last): > ?File "", line 1, in ? > ImportError: No module named subprocess >>>> The `subprocess` modules was added in Python 2.4. You're using Python 2.2.3; you need to update. > should start to search for ?it. Then I tried to key in a function > file ?python_func_00.py ?by myself. > > def pyfunc(): > ? ? ? ?print "Hello function" > > > # python > Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import python_func_00 >>>> pyfunc() > Traceback (most recent call last): > ?File "", line 1, in ? > NameError: name 'pyfunc' is not defined > What's the mistake that I am making? How to solve it? The `import foo` statement only adds the name of the module itself to your namespace, so you need to refer to pyfunc by way of the module name. To wit: import python_func_00 python_func_00.pyfunc() Alternatively, you can specify a set of names to import from the module namespace into your own using the `from foo import bar` syntax: from python_func_00 import pyfunc pyfunc() Regarding ipython, it's a third-party package that is not part of Python itself and must be installed separately. Exactly how you do so will obviously depend on which distro you're using. Cheers, Chris -- http://blog.rebertia.com From hvictor at bluewin.ch Mon Nov 16 08:04:48 2009 From: hvictor at bluewin.ch (hvictor) Date: Mon, 16 Nov 2009 05:04:48 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API Message-ID: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> I have C++ a void function pointer stored in a variable call. The pointed function takes an int and a char* as arguments. I have a python module containing this function: def yeah(x): x(int(0),"text argument") return "pointer called" As you can see I'm trying to use the argument x of the function like a method object. In the C++ side I'm doing following (note that I only paste relevant parts of code because this system is working fine, C++ is able to call function yeah and get its return value, but only with a string- oriented test): ... PyObject *pValue; // the argument for python pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn ptr, required from the api. PyObject *pFunc = PyObject_GetAttrString(pModule, "yeah"); ... PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the arguments, I insert pValue in it. pValue = PyObject_CallObject(pFunc, pArgs); ... It does not work. can anyone help me please? I just want python to call this function pointer. Thank you From ian at excess.org Mon Nov 16 08:24:26 2009 From: ian at excess.org (Ian Ward) Date: Mon, 16 Nov 2009 08:24:26 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B01528A.90303@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From ian at excess.org Mon Nov 16 08:24:52 2009 From: ian at excess.org (Ian Ward) Date: Mon, 16 Nov 2009 08:24:52 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B0152A4.7050307@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From pavlovevidence at gmail.com Mon Nov 16 08:25:05 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 05:25:05 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API References: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> Message-ID: <3dde088d-859b-41f7-9aad-11a6c2887b96@j14g2000yqm.googlegroups.com> On Nov 16, 5:04?am, hvictor wrote: > I have C++ a void function pointer stored in a variable call. The > pointed function takes an int and a char* as arguments. > > I have a python module containing this function: > > def yeah(x): > ? ? ? ? x(int(0),"text argument") > ? ? ? ? return "pointer called" > > As you can see I'm trying to use the argument x of the function like a > method object. > In the C++ side I'm doing following (note that I only paste relevant > parts of code because this system is working fine, C++ is able to call > function yeah and get its return value, but only with a string- > oriented test): > ... > PyObject *pValue; // the argument for python > > pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn > ptr, required from the api. > > PyObject *pFunc = PyObject_GetAttrString(pModule, "yeah"); > > ... > PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the > arguments, I insert pValue in it. > > pValue = PyObject_CallObject(pFunc, pArgs); > > ... > > It does not work. can anyone help me please? I just want python to > call this function pointer. Python can't call C function pointers. You have to write a function in C that accepts a CObject and some arguments, unpacks the arguments, retrieves the function pointer from the CObject, and calls it. Quick and dirty function that might do that (untested, not robust). static PyObject* call_user_void_ptr(PyObject* self, PyObject* args) { PyObject* cobj; int ival; char* sval; void (*func)(int,char*); if (!PyArg_ParseTuple("O!is",&PyCObject_Type,&cobj,&ival,&sval)) return 0; func = PyCObject_AsVoidPtr(cobj); func(ival,sval); Py_RETURN_NONE; } def yeah(x): call_user_void_ptr(x,int(i),"text_argument") print "pointer called" In a pinch, you could call the function pointer from ctypes. Since you're already writing a C extension I wouldn't recommend it as a final solution, though. Carl Banks From sturlamolden at yahoo.no Mon Nov 16 08:26:57 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 05:26:57 -0800 (PST) Subject: Let python call a C function pointer passed from the C Python API References: <854d1660-2cad-42c6-99e5-b66fb01fcacd@p8g2000yqb.googlegroups.com> <3dde088d-859b-41f7-9aad-11a6c2887b96@j14g2000yqm.googlegroups.com> Message-ID: <17ffa382-7fcb-4862-9b9d-f210252f50b0@r5g2000yqb.googlegroups.com> On 16 Nov, 14:25, Carl Banks wrote: > Python can't call C function pointers. ? Yes it can, use ctypes... From james at agentultra.com Mon Nov 16 08:27:18 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 16 Nov 2009 08:27:18 -0500 Subject: object serialization as python scripts References: <8623b4f0-5da5-4192-a68e-1d06909f90f7@l2g2000yqd.googlegroups.com> <7m5jjsF3egl9mU1@mid.uni-berlin.de> <276d2903-8fee-4916-a352-eb278886fa1c@r5g2000yqb.googlegroups.com> Message-ID: <87lji6mwg9.fsf@agentultra.com> King writes: >> Why is it easier than the above mentioned - they are *there* (except the >> custom xml), and just can be used. What don't they do you want to do? >> >> Other than that, and even security issues put aside, I don't see much >> difference between pickle and python code, except the latter being more >> verbose. Which suits humans, but other than that has no advantage. >> >> Diez > > My application is PyQt based and objects that I am trying to save are > couple of QGraphicsItem instances. You can't save instances of > QGraphicsItem > using pickle or shelve. > Custom xml format would be a real pain as you have to write code for > writing/reading both. > > I am aware of security issue but over all there are only 5 statements > I have to use to get the entire > information back. I can do syntax checking and other stuff before I > should execute the script. > > Another reason is that data should be in human readable form. > > Prashant > > Python 2.6.2 > Win XP 32 Pickling should work just fine. If you cannot pickle the class with the default pickler, you can hook into the pickler protocol to tell pickle how to pickle instances of the class. Failing that you can write your own pickler class for handling the special case. Python scripts aren't really a good data format. They're not structured in a way that would be easy to parse and extract information from in a non-python context without a lot of work. From robin at reportlab.com Mon Nov 16 08:28:36 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 13:28:36 +0000 Subject: Psyco on 64-bit machines In-Reply-To: References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <4B015384.9050104@chamonix.reportlab.co.uk> Russ P. wrote: ........ > I just stumbled across "unladen swallow," a "faster implementation of > Python." Is it ready for operational usage? How does it compare to > Psyco? I poked around their website a bit, but I don't see answers to > those questions. Thanks. I've tried a few things with it. It mostly works, but it isn't actually faster at normal programs. I've been told their target is for long running processes where JIT and similar can speed up the inner loops etc etc. Certainly makes sense for google apps in python so perhaps that's the intended end use. -- Robin Becker From robin at reportlab.com Mon Nov 16 08:28:36 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 13:28:36 +0000 Subject: Psyco on 64-bit machines In-Reply-To: References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: <4B015384.9050104@chamonix.reportlab.co.uk> Russ P. wrote: ........ > I just stumbled across "unladen swallow," a "faster implementation of > Python." Is it ready for operational usage? How does it compare to > Psyco? I poked around their website a bit, but I don't see answers to > those questions. Thanks. I've tried a few things with it. It mostly works, but it isn't actually faster at normal programs. I've been told their target is for long running processes where JIT and similar can speed up the inner loops etc etc. Certainly makes sense for google apps in python so perhaps that's the intended end use. -- Robin Becker From darcymason at gmail.com Mon Nov 16 08:34:27 2009 From: darcymason at gmail.com (Darcy Mason) Date: Mon, 16 Nov 2009 05:34:27 -0800 (PST) Subject: Calling Python functions from Excel References: Message-ID: <93c20779-ceca-4a10-82ef-33878047b4dc@h34g2000yqm.googlegroups.com> On Nov 15, 2:20?am, Cannonbiker wrote: > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. A couple of years ago I used MSScriptControl for this. Couldn't find a great reference just now, but here is a discussion which should give enough information: http://www.velocityreviews.com/forums/t319222-re-python-in-excel.html Check from around message 3 on. From mrholtsr at gmail.com Mon Nov 16 09:00:18 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Mon, 16 Nov 2009 06:00:18 -0800 (PST) Subject: Code for finding the 1000th prime References: <7majfhF2j43tpU1@mid.uni-berlin.de> Message-ID: <0382cc5d-9800-49b0-a98f-55dc06a0e30f@p35g2000yqh.googlegroups.com> On Nov 15, 10:02?am, "Diez B. Roggisch" wrote: > mrholtsr schrieb: > > > I am absolutely new to python and barely past beginner in programming. > > Also I am not a mathematician. Can some one give me pointers for > > finding the 1000th. prime for a course I am taking over the internet > > on Introduction to Computer Science and Programming. Thanks, Ray > > Do you really think we are so retarded that we don't remember you posted > the same question a week ago? > > Diez Mea Culpa. I didn't realize at the time that this group was the same as the newsletter. Won't do it again. From jeremy+complangpython at jeremysanders.net Mon Nov 16 09:00:25 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Mon, 16 Nov 2009 14:00:25 +0000 Subject: Psyco on 64-bit machines References: <16cc2999-337d-4951-a8b7-0dc7266441fa@z41g2000yqz.googlegroups.com> Message-ID: Russ P. wrote: > Would it make sense to compile Python in the 32-bit compatibility mode > so I can use Psyco? What would I lose in that mode, if anything? > Thanks. You won't be able to access large amounts of memory in 32 bit mode. Also, the x86-64 mode has more CPU registers than x86 mode, so Python will typically run faster in 64 bit mode (this is more pronounced in AMD processors, in my experience). It will depend on your application whether 32 bit mode plus Psyco is faster than 64 bit mode. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ From mrholtsr at gmail.com Mon Nov 16 09:01:44 2009 From: mrholtsr at gmail.com (mrholtsr) Date: Mon, 16 Nov 2009 06:01:44 -0800 (PST) Subject: Newsgroup for beginners Message-ID: Is there a Python newsgroup for those who are strictly beginners at programming and python? From mr.spoon21 at gmail.com Mon Nov 16 09:02:28 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Mon, 16 Nov 2009 15:02:28 +0100 Subject: Logic operators with "in" statement Message-ID: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Hi, I'm trying to use logical operators (or, and) with the "in" statement, but I'm having some problems to understand their behavior. In [1]: l = ['3', 'no3', 'b3'] In [2]: '3' in l Out[2]: True In [3]: '3' and '4' in l Out[3]: False In [4]: '3' and 'no3' in l Out[4]: True This seems to work as I expected. ------------ In [5]: '3' and 'no3' or '3' and '4' in l Out[5]: 'no3' In [6]: ('3' and 'no3') or ('3' and '4') in l Out[6]: 'no3' I don't understand these outputs. --------------- In [7]: (('3' and 'no3') or ('3' and '4')) in l Out[7]: True In [10]: (('b3' and '4') or ('3' and 'no3')) in l Out[10]: False Here I expected to get True in the second case too, so clearly I don't really get how they work. Can you help me? What I really need is to create a sequence of "if" statements to check the presence of elements in a list, because some of them are mutually exclusive, so if for example there are both "3" and "no3" it should return an error. Thanks, Carlo From sturlamolden at yahoo.no Mon Nov 16 09:06:55 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 16 Nov 2009 06:06:55 -0800 (PST) Subject: Code for finding the 1000th prime References: Message-ID: <92dc62d9-330c-4638-95ae-e19998b09add@m16g2000yqc.googlegroups.com> On 15 Nov, 15:30, mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray print "7919" From deets at nospam.web.de Mon Nov 16 09:07:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Nov 2009 15:07:05 +0100 Subject: Newsgroup for beginners References: Message-ID: <7md4k9F3fo2umU1@mid.uni-berlin.de> mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? Yes, the tutor-list. http://mail.python.org/mailman/listinfo/tutor Diez From mr.spoon21 at gmail.com Mon Nov 16 09:08:54 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Mon, 16 Nov 2009 15:08:54 +0100 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Sorry for replying to myself, but I think I understood why I was wrong. The correct statement should be something like this: In [13]: ('b3' and '5') in l or ('3' and 'b3') in l Out[13]: True From tgrav at me.com Mon Nov 16 09:11:20 2009 From: tgrav at me.com (Tommy Grav) Date: Mon, 16 Nov 2009 09:11:20 -0500 Subject: (unknown) In-Reply-To: References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> Message-ID: <3F923692-C191-4477-879B-1921C0268EB4@me.com> On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote: > En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross escribi?: > >> I'm attempting to convert latitude and longitude coordinates from degrees >> minutes and second to decimal form. I would like to go from: >> N39 42 36.3 W77 42 51.5 >> to: >> -77.739855,39.706666 >> >> Does anyone know of a library or some existing out their to help with this >> conversion? > > Should be: > > decimal = degrees + minutes/60.0 + seconds/3600.0 > N,E are positive; S,W are negative. > > But the above numbers don't match. It is more complicated than that. For negative numbers the value is degrees -minutes/60. - seconds/3600. And people always trip up on numbers that start with -00 :) Cheers Tommy From exarkun at twistedmatrix.com Mon Nov 16 09:12:27 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 16 Nov 2009 14:12:27 -0000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <20091116141227.27565.1164868262.divmod.xquotient.183@localhost.localdomain> On 02:02 pm, mr.spoon21 at gmail.com wrote: >Hi, >I'm trying to use logical operators (or, and) with the "in" statement, >but I'm having some problems to understand their behavior. "and" and "or" have no particular interaction with "in". > >In [1]: l = ['3', 'no3', 'b3'] > >In [2]: '3' in l >Out[2]: True > >In [3]: '3' and '4' in l >Out[3]: False > >In [4]: '3' and 'no3' in l >Out[4]: True > >This seems to work as I expected. What this actually does is '3' and ('no3' in l). So it might have produced the result you expected, but it didn't work how you expected. :) Jean-Paul From clp2 at rebertia.com Mon Nov 16 09:14:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:14:30 -0800 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: <50697b2c0911160614h71033b1eg714351ef695a6fb4@mail.gmail.com> On Mon, Nov 16, 2009 at 6:01 AM, mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? python-tutor: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://blog.rebertia.com From R.Brodie at rl.ac.uk Mon Nov 16 09:17:20 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 16 Nov 2009 14:17:20 -0000 Subject: Logic operators with "in" statement References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: "Mr.SpOOn" wrote in message news:mailman.492.1258380560.2873.python-list at python.org... > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True For anything more than the simplest cases, you might want use sets. That might be the correct data type from the start, depending on whether the ordering is important anywhere. From clp2 at rebertia.com Mon Nov 16 09:21:10 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:21:10 -0800 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <50697b2c0911160621s7d8d734bi88a83adddd2cbd4d@mail.gmail.com> On Mon, Nov 16, 2009 at 6:02 AM, Mr.SpOOn wrote: > Hi, > I'm trying to use logical operators (or, and) with the "in" statement, > but I'm having some problems to understand their behavior. > > In [1]: l = ['3', 'no3', 'b3'] > > In [2]: '3' in l > Out[2]: True > > In [3]: '3' and '4' in l > Out[3]: False > > In [4]: '3' and 'no3' in l > Out[4]: True > > This seems to work as I expected. No, it doesn't. You are misinterpreting. Membership tests via `in` do NOT distribute over `and` and `or`. '3' and '4' in l is equivalent to: ('3') and ('4' in l) Recall that non-empty sequences and containers are conventionally True in Python, so your expression is logically equivalent to: '4' in l With '3' not being checked for membership at all. To check multiple items for membership in a contains, you must write each `in` test separately and then conjoin then by the appropriate boolean operator: '3' in l and '4' in l Cheers, Chris -- http://blog.rebertia.com From contact at xavierho.com Mon Nov 16 09:23:01 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 00:23:01 +1000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> On Tue, Nov 17, 2009 at 12:02 AM, Mr.SpOOn wrote: > Hi, > I'm trying to use logical operators (or, and) with the "in" statement, > but I'm having some problems to understand their behavior. > Hey Carlo, I think your issue here is mistaking 'in' as a statement. It's just another logic operator, much like 'and' and 'or'... it's not a statement in itself. At least, I don't think that's how you'd call 'in'. You have to remember that Python's logical operators (and, or) works slightly different than most languages. It doesn't return True or False, if the things compared aren't boolean values. Instead, it returns the first thing that makes the decision. For example a statement such as >>>'3' and '4' '4' returns the string literal 4. 1. Python's AND operator returns the first element if the first one is False; else, it returns the second element. That's all it does. Python's OR operator returns the first element if the first one is True; else, it returns the second element. Think about it. It's a little strange, but they don't return a pure Boolean value. 2. Only the empty string is considered False. Any non-empty strings have True values. 3. The proper way of using the in operator is probably such: (There may be a better way I'm not aware of.) >>> '3' in l and '4' in l False >>> '3' in l and 'no3' in l True AND operator has a higher precedence, so you don't need any brackets here, I think. But anyway, you have to use it like that. So that's something you'll have to fix first. > What I really need is to create a sequence of "if" statements to check > the presence of elements in a list, because some of them are mutually > exclusive, so if for example there are both "3" and "no3" it should > return an error One idea I can think of is to have a presence count; assuming the input is non-repeating, you increase this count by 1, starting at 0. If you get anything above one, return this error you speak of, and that might be a good start. Good luck, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Nov 16 09:30:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:30:30 -0800 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Message-ID: <50697b2c0911160630k3ed20c5sa5218ab4d53c27ff@mail.gmail.com> On Mon, Nov 16, 2009 at 6:08 AM, Mr.SpOOn wrote: > Sorry for replying to myself, but I think I understood why I was wrong. > > The correct statement should be something like this: > > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True No, you've just run into another misunderstanding. Given the expression `X and Y`: If bool(X) is False, it evaluates to X. Otherwise, it evaluates to Y. In other words, the subexpression which ends up determining the truth of the conjunction is what the conjunction evaluates to. `or` works similarly. This allows for tricky tricks like: foo = possiblyFalse or default # use default if given value is false Thus, due to the parentheses, your expression is equivalent to: '5' in l or 'b3' in l Which I trust is not what you intended. Again, you need to write separate `in`s for each item you need to check the membership of: ('b3' in l and '5' in l) or ('3' in l and 'b3' in l) Cheers, Chris -- Python language lawyer at your service http://blog.rebertia.com From contact at xavierho.com Mon Nov 16 09:30:33 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 00:30:33 +1000 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <8f67b6f80911160608j6870d2a8h40158bfea51761e6@mail.gmail.com> Message-ID: <2d56febf0911160630m68f1148o6f1c9ff5bc42af73@mail.gmail.com> On Tue, Nov 17, 2009 at 12:08 AM, Mr.SpOOn wrote: > Sorry for replying to myself, but I think I understood why I was wrong. > > The correct statement should be something like this: > > In [13]: ('b3' and '5') in l or ('3' and 'b3') in l > Out[13]: True > > Carlo, I'm not sure what that achieves. Care to enlighten me? Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Nov 16 09:38:49 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 08:38:49 -0600 Subject: Logic operators with "in" statement In-Reply-To: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> Message-ID: <4B0163F9.5020600@tim.thechases.com> > Here I expected to get True in the second case too, so clearly I don't > really get how they work. You're seeing short-circuit evaluation: >>> "3" or "4" # true '3' >>> '4' or '3' # true '4' >>> '4' in l # false False >>> '3' or False # true '3' >>> '4' or '42' in l # true: same as "'4' or ('42' in l)" '4' >>> '4' or '42' '4' >>> ('4' or '42') in l # true: same as "'4' in l" '4' It just happens that sometimes you get unexpected results that happen to be right because of how Python handles strings/numbers as booleans and order-of-operations. > What I really need is to create a sequence of "if" statements to check > the presence of elements in a list, because some of them are mutually > exclusive, so if for example there are both "3" and "no3" it should > return an error. The "in" operator only checks containment of one item, not multiples, so you have to manage the checking yourself. This is fairly easy with the any()/all() functions added in 2.5: any(i in l for i in ("3", "4")) all(i in l for i in ("3", "4")) For more complex containment testing, using sets will be more efficient and offers a richer family of batch operators (contains, intersection, union, difference, issubset, issuperset) -tkc From python.list at tim.thechases.com Mon Nov 16 09:44:37 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 08:44:37 -0600 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: <4B016555.1070300@tim.thechases.com> mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? http://mail.python.org/mailman/listinfo/tutor -tkc From x31eq at cnntp.org Mon Nov 16 09:45:05 2009 From: x31eq at cnntp.org (Graham Breed) Date: Mon, 16 Nov 2009 22:45:05 +0800 Subject: Python & Go In-Reply-To: References: <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> Message-ID: <4b016573$0$9750$6e1ede2f@read.cnntp.org> Terry Reedy wrote: > It seems to me that generators are already 'channels' that connect the > calling code to the __next__ method, a semi-coroutine based on the body > of the generator function. At present, the next method waits until an > object is requested. Then it goes into action, yields an object, and > rests again. For parallel operations, we need eager, anticipatory > evaluation that produces things that *will* be needed rather than lazy > evaluation of things that *are* needed and whose absence is holding up > everything else. Yes, generators look very much like channels. The obvious thing, from where I'm sitting, is to have a function called "channel" that takes an iterator, runs it in a different thread/process/goroutine, and returns an iterator that reads from the channel. A single threaded version would look very much like "iter" so let's use iter to get a working example: #!/usr/bin/python2 -u channel = iter # placeholder for missing feature def generate(): i = 2 while True: yield i i += 1 def filter(input, prime): for i in input: if i%prime != 0: yield i ch = channel(generate()) try: while True: prime = ch.next() print prime ch = channel(filter(ch, prime)) except IOError: pass That works fine in a single thread. It's close to the original go example, hence the evil shadowing of a builtin. I don't think the "channel" function would present any problems given an appropriate library to wrap. I got something like this working with Jython and the E language but, as I recall, had an accident and lost the code. If somebody wants to implement it using multiprocessing, go to it! Graham From clp2 at rebertia.com Mon Nov 16 09:46:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 06:46:48 -0800 Subject: Logic operators with "in" statement In-Reply-To: <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> Message-ID: <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote: >>>> '3' in l and 'no3' in l > True > > AND operator has a higher precedence, so you don't need any brackets here, I > think. But anyway, you have to use it like that. So that's something you'll > have to fix first. Er, you mean lower precedence. Higher precedence means it would bind tighter, thus the expression would mean: '3' in (l and 'no3') in l which is certainly incorrect. Cheers, Chris -- http://blog.rebertia.com From paul at boddie.org.uk Mon Nov 16 10:03:34 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 16 Nov 2009 07:03:34 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <7de63a99-dce9-47b0-9e05-b36f8283236d@b2g2000yqi.googlegroups.com> On 16 Nov, 05:51, sturlamolden wrote: > > NASA can find money to build a space telescope and put it in orbit. > They don't find money to create a faster Python, which they use for > analyzing the data. Is the analysis in Python really what slows it all down? > Google is a multi-billion dollar business. They are using Python > extensively. Yes I know about Unladen Swallow, but why can't they put > 1 mill dollar into making a fast Python? Isn't this where we need those Ohloh figures on how much Unladen Swallow is worth? ;-) I think Google is one of those organisations where that Steve Jobs mentality of shaving time off a once-per-day activity actually pays off. A few more cycles here and there is arguably nothing to us, but it's a few kW when running on thousands of Google nodes. > And then there is IBM and Cern's Blue Brain project. They can set up > the fastest supercomputer known to man, but finance a faster Python? > No... Businesses and organisations generally don't spend any more money than they need to. And if choosing another technology is cheaper for future work then they'll just do that instead. In a sense, Python's extensibility using C, C++ and Fortran have helped adoption of the language considerably, but it hasn't necessarily encouraged a focus on performance. Paul From carlo.dicelico at gmail.com Mon Nov 16 10:19:49 2009 From: carlo.dicelico at gmail.com (Carlo DiCelico) Date: Mon, 16 Nov 2009 07:19:49 -0800 (PST) Subject: Image to SVG conversion with Python Message-ID: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> I need to convert JPEG and PNG files to SVG. I'm currently using PIL to generate the JPEG/PNG files to begin with. However, I need to be able to scale the generated images up in size without a loss of image quality. Using SVG seems to be the best way to do this, other than generating the images in the maximum size/resolution in the first place, which would be too resource intensive. I've looked around online and have found some tools for creating SVGs but none for converting an image into SVG. Does anyone have any experience doing this? What would be the best way to go about this? Thanks, Carlo From python-url at phaseit.net Mon Nov 16 10:22:40 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Mon, 16 Nov 2009 15:22:40 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 16) Message-ID: QOTW: "The promise is 'batteries included.' Nobody promised you a nickel metal hydride battery that you can use as a replacement in your Prius." - Stephen J. Turnbull http://mail.python.org/pipermail/python-dev/2009-November/094014.html Google's new language, Go, has similarities to Python: http://groups.google.com/group/comp.lang.python/t/c1c4a8fe741c689a/ Is Python scalable enough for Google (or any other huge application)? http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/ Is it possible to get the physical memory address of a variable in python? http://groups.google.com/group/comp.lang.python/t/969462b9a3b452/ Serialize objects as Python code: http://groups.google.com/group/comp.lang.python/t/98536e7910e65256/ Overriding __getitem__ for a subclass of dict: http://groups.google.com/group/comp.lang.python/t/d9b822119fc0917c/ Ensure a script is run with a certain range of Python versions: http://groups.google.com/group/comp.lang.python/t/d21a492be99c90e8/ How to install applications when Python is not already present: http://groups.google.com/group/comp.lang.python/t/495794a40d18fbc/ Turtle graphics are just for kids - or not? Its advantages when teaching Python programming: http://groups.google.com/group/comp.lang.python/t/d55388b0fdd9ed2f/ Using dynamic property names: http://groups.google.com/group/comp.lang.python/t/f7b8829c97dcc3f9/ How can a module react differently when imported from one place or another? http://groups.google.com/group/comp.lang.python/t/da162dc08f1c3550/ Sharing distributed objects between Python and C++: http://groups.google.com/group/comp.lang.python/t/5a567a1a180511eb/ Beware: threads + import don't mix well! http://groups.google.com/group/comp.lang.python/t/a60c83590a016528/ locals() and frame.f_locals return old data: http://groups.google.com/group/comp.lang.python/t/fa17941218c6e89e/ Instantiate classes using names from the command line: http://groups.google.com/group/comp.lang.python/t/d597a1a42b88c0d1/ New syntax proposal: if some_expression as x: do_something_with(x) http://groups.google.com/group/comp.lang.python/t/55e7578903747dc4/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 gagsl-py2 at yahoo.com.ar Mon Nov 16 11:03:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:03:16 -0300 Subject: C api question and determining PyObject type References: Message-ID: En Mon, 16 Nov 2009 07:44:34 -0300, lallous escribi?: > Actually, the object class is defined as: > class __object(object): > def __getitem__(self, idx): > return getattr(self, idx) > > Anyway, now I check like this: > > bool PyIsSequenceType(PyObject *obj) > { > if (!PySequence_Check(obj)) > return false; > Py_ssize_t sz = PySequence_Size(obj); > if (sz == -1 || PyErr_Occurred() != NULL) > { > PyErr_Clear(); > return false; > } > return true; > } > > I don't like it, any other suggestions? Yes: find another name for the "thing" you're checking for. It's not the same as a "sequence" in the Python sense. Perhaps you want to consider your type a mapping? Sequences and mappings have a lot in common (mappings have length too.) In C you have separate slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is used for both meanings (and goes into both set of pointers.) tp_as_mapping takes precedence over tp_as_sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 16 11:03:16 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:03:16 -0300 Subject: C api question and determining PyObject type References: Message-ID: En Mon, 16 Nov 2009 07:44:34 -0300, lallous escribi?: > Actually, the object class is defined as: > class __object(object): > def __getitem__(self, idx): > return getattr(self, idx) > > Anyway, now I check like this: > > bool PyIsSequenceType(PyObject *obj) > { > if (!PySequence_Check(obj)) > return false; > Py_ssize_t sz = PySequence_Size(obj); > if (sz == -1 || PyErr_Occurred() != NULL) > { > PyErr_Clear(); > return false; > } > return true; > } > > I don't like it, any other suggestions? Yes: find another name for the "thing" you're checking for. It's not the same as a "sequence" in the Python sense. Perhaps you want to consider your type a mapping? Sequences and mappings have a lot in common (mappings have length too.) In C you have separate slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is used for both meanings (and goes into both set of pointers.) tp_as_mapping takes precedence over tp_as_sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Nov 16 11:20:00 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 13:20:00 -0300 Subject: (unknown) References: <9c8c445f0911131105j2cad4d19ufe23ffa1002a859@mail.gmail.com> <3F923692-C191-4477-879B-1921C0268EB4@me.com> Message-ID: En Mon, 16 Nov 2009 11:11:20 -0300, Tommy Grav escribi?: > On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote: >> En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross >> escribi?: >> >>> I'm attempting to convert latitude and longitude coordinates from >>> degrees >>> minutes and second to decimal form. I would like to go from: >>> N39 42 36.3 W77 42 51.5 >>> to: >>> -77.739855,39.706666 >> >> decimal = degrees + minutes/60.0 + seconds/3600.0 >> N,E are positive; S,W are negative. >> But the above numbers don't match. > > It is more complicated than that. For negative numbers the value is > degrees -minutes/60. - seconds/3600. > And people always trip up on numbers that start with -00 :) I set the sign of the result *after* computing it, so it doesn't matter. py> 39 + 42/60.0 + 36.3/3600 39.710083333333337 py> 77 + 42/60.0 + 51.5/3600 77.714305555555555 Either the example above is incorrect, or there is another thing involved. -- Gabriel Genellina From tjreedy at udel.edu Mon Nov 16 11:22:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 11:22:49 -0500 Subject: A "terminators' club" for clp In-Reply-To: References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: kj wrote: > In <7x3a4i56u7.fsf at ruckus.brouhaha.com> Paul Rubin writes: > >> kj writes: >>> frequent* clp posters the ability to *easily* delete spam from the >>> comp.lang.python server? > >> Um, this is usenet; there is no comp.lang.python server. Are you >> saying you want a moderated newsgroup? Hmm, maybe this group is busy >> enough that there is some merit to that idea. > > Sorry, I had a mistaken view of how usenet was implemented. But > yeah, I guess I'm thinking of a moderated newsgroup, but with a > large number of moderators working in parallel, and a very lax > acceptance policy. The goal is to filter out only the obvious > spam, and let through all the other non-spam traffic as quickly as > possible... What do I mean by "obvious spam"? Well, among the > most recent messages (that have survived my killfile policies) I > see the following subject lines: > > * Top 10 US mp3 songs.....Cheers > * www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red monkey gino green global true religion ed-hardy kidrobot jeans hoodies china supplier wholesaler exporters,manufacture > * "jobs in france" "jobs in france for english people" "jobs in france for foreigners" "jobs in france for australians" "jobs in france for foreigners " "jobs in france for new zealanders" "jobs" "paris jobs" http://jobs-in-fr ance.blogspot.com/ > * "germany jobs" "germany job sites" "germany job search" "jobs in germany" "german jobs" "germany jobs it" "germany jobs for foreigners" "germany jobsite" "germany jobs in english" on http://jobs-germany.blogspot.com/ > > Those look pretty obvious to me. > > But, as I already showed, I'm out of my depth here, > so I'd better shut up. Some usenet newsgroups were/are moderated either by a robot, a person, or a team (as you suggested). But a particular newsgroup has to be set up that way from the beginning. Last I knew, it wan/is? difficult to convert an unmoderated group to moderation. Terry Jan Reedy From tjreedy at udel.edu Mon Nov 16 11:35:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Nov 2009 11:35:40 -0500 Subject: Newsgroup for beginners In-Reply-To: References: Message-ID: mrholtsr wrote: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? gmane.comp.python.tutor, which I believe mirrors the tutor-list From davea at ieee.org Mon Nov 16 11:48:12 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 11:48:12 -0500 Subject: Image to SVG conversion with Python In-Reply-To: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: <4B01824C.2080109@ieee.org> Carlo DiCelico wrote: > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > to generate the JPEG/PNG files to begin with. However, I need to be > able to scale the generated images up in size without a loss of image > quality. Using SVG seems to be the best way to do this, other than > generating the images in the maximum size/resolution in the first > place, which would be too resource intensive. > > I've looked around online and have found some tools for creating SVGs > but none for converting an image into SVG. > > Does anyone have any experience doing this? What would be the best way > to go about this? > > Thanks, > Carlo > > I have no direct experience with SVG, but have used and analyzed other formats. I expect it's unreasonable to convert jpg or png files to SVG. The latter is a vector format, and can't efficiently represent pixels, which is all you have in the jpg files. And even if you did it brute force, it still wouldn't scale any better than the original jpg. If the jpg file was generated from lines, and wasn't too crowded, it *might* be possible to analyze it to reconstruct the vectors, but it would be both very slow, and inaccurate. In Photoshop PSD files, you can have vector layers and RGB layers (plus other kinds). You convert a vector layer (such as text) to bits by rasterizing (or flattening). And once you do, it no longer scales cleanly. For instance, when I'm sending composite images to a printer, I get much better quality sending the raster portion separate from the text, either as layers in a PSD file, or in a PDF file, or even as two separate files that they will merge later. (In that case, I usually send a low-res flattened file, so they can see how it's supposed to look) I'd say you should change your python code to generate the svg files first (perhaps using http://code.activestate.com/recipes/325823/ ) Then you might want to use ( http://www.imagemagick.org/script/index.php ) to convert it to jpg or other format. DaveA From steve.ferg.bitbucket at gmail.com Mon Nov 16 11:54:28 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 16 Nov 2009 08:54:28 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? Message-ID: This is a question for the language mavens that I know hang out here. It is not Python related, except that recent comparisons of Python to Google's new Go language brought it to mind. NOTE that this is *not* a suggestion to change Python. I like Python just the way it is. I'm just curious about language design. For a long time I've wondered why languages still use blocks (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. I've often thought that a language with this kind of block-free syntax would be nice and intuitive: if then do stuff elif then do stuff else do stuff endif Note that you do not need block delimiters. Obviously, you could make a more Pythonesque syntax by using a colon rather then "then" for the condition terminator. You could make it more PL/I-like by using "do", etc. You can write shell scripts using if ... fi, but other than that I don't recall a language with this kind of syntax. Does anybody know a language with this kind of syntax for ifThenElseEndif? Is there any particular reason why this might be a *bad* language- design idea? From robin at reportlab.com Mon Nov 16 12:03:20 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:03:20 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B0185D8.8040305@chamonix.reportlab.co.uk> Steve Ferg wrote: ......... > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? ....... modern sh seems to use this with "fi" as endif eg ~: $ if true; then > echo true > elif false; then > echo false > else > echo hostile logic > fi true ~: $ -- Robin Becker From carlo.dicelico at gmail.com Mon Nov 16 12:06:42 2009 From: carlo.dicelico at gmail.com (Carlo DiCelico) Date: Mon, 16 Nov 2009 09:06:42 -0800 (PST) Subject: Image to SVG conversion with Python References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: <396dc22b-0dde-4434-9c38-d150d9bb027c@m20g2000vbp.googlegroups.com> On Nov 16, 11:48?am, Dave Angel wrote: > Carlo DiCelico wrote: > > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > > to generate the JPEG/PNG files to begin with. However, I need to be > > able to scale the generated images up in size without a loss of image > > quality. Using SVG seems to be the best way to do this, other than > > generating the images in the maximum size/resolution in the first > > place, which would be too resource intensive. > > > I've looked around online and have found some tools for creating SVGs > > but none for converting an image into SVG. > > > Does anyone have any experience doing this? What would be the best way > > to go about this? > > > Thanks, > > Carlo > > I have no direct experience with SVG, but have used and analyzed other > formats. > > I expect it's unreasonable to convert jpg or png files to SVG. ?The > latter is a vector format, and can't efficiently represent pixels, which > is all you have in the jpg files. ?And even if you did it brute force, > it still wouldn't scale any better than the original jpg. ?If the jpg > file was generated from lines, and wasn't too crowded, it *might* be > possible to analyze it to reconstruct the vectors, but it would be both > very slow, and inaccurate. > > In Photoshop PSD files, you can have vector layers and RGB layers (plus > other kinds). ?You convert a vector layer (such as text) to bits by > rasterizing (or flattening). ?And once you do, it no longer scales > cleanly. ?For instance, when I'm sending composite images to a printer, > I get much better quality sending the raster portion separate from the > text, either as layers in a PSD file, or in a PDF file, or even as two > separate files that they will merge later. ?(In that case, I usually > send a low-res flattened file, so they can see how it's supposed to look) > > I'd say you should change your python code to generate the svg files > first (perhaps usinghttp://code.activestate.com/recipes/325823/) > > Then you might want to use (http://www.imagemagick.org/script/index.php > ) to convert it to jpg or other format. > > DaveA Thanks, this makes perfect sense. From james.harris.1 at googlemail.com Mon Nov 16 12:09:12 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Mon, 16 Nov 2009 09:09:12 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <80bb6965-475f-4a7a-906e-09736d92e6a2@k17g2000yqh.googlegroups.com> On 16 Nov, 16:54, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? There are some. For example, Ada uses similar. See http://en.wikipedia.org/wiki/Ada_%28programming_language%29#Control_structures These other newsgroups may be of interest: comp.programming comp.lang.misc The latter is used by people designing programming languages where you can find knowledgeable comments aplenty. James From acherry at btinternet.com Mon Nov 16 12:16:46 2009 From: acherry at btinternet.com (Adrian Cherry) Date: 16 Nov 2009 17:16:46 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: Steve Ferg wrote in news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 at p36g2000vbn.googlegro ups.com: > This is a question for the language mavens that I know hang > out here. It is not Python related, except that recent > comparisons of Python to Google's new Go language brought it > to mind. > > NOTE that this is *not* a suggestion to change Python. I > like Python just the way it is. I'm just curious about > language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse > statements. > > I've often thought that a language with this kind of > block-free syntax would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using > a colon rather then "then" for the condition terminator. > You could make it more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than > that I don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* > language- design idea? I believe MATLAB has similar if syntax - please correct me if I'm wrong. From http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html "The if function can be used alone or with the else and elseif functions. When using elseif and/or else within an if statement, the general form of the statement is" if expression1 statements1 elseif expression2 statements2 else statements3 end Adrian From ecir.hana at gmail.com Mon Nov 16 12:17:52 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Mon, 16 Nov 2009 09:17:52 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: Message-ID: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> On Nov 15, 5:28?pm, Ecir Hana wrote: > Hello, > > I'm trying to write a simple Win32 app, which may run some Python > scripts. Since it is a Windows GUI app, I would like to redirect all > output (Python print, C printf, fprinf stderr, ...) to a text area > inside the app. In other words, I'm trying to log all the output from > the app (C, Python) to a window. So far, this works for C printf(): > > int fds[2]; > _pipe(fds, 1024, O_TEXT); > _dup2(fds[1], 1); > ... > and then I read from pipe's read-end and append the text to the text > area. > > But when I try to run: > Py_Initialize(); > PyRun_SimpleString("print 'abc'"); > Py_Finalize(); > > I get an error: > IOError: [Errno 9] Bad file descriptor > > What am I doing wrong? How to redirect standard IO, both for C and for > Python? > PS: Maybe I'm doind something wrong, but SetStdHandle() does not work > at all.... Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. From georgeolivergo at gmail.com Mon Nov 16 12:33:13 2009 From: georgeolivergo at gmail.com (George Oliver) Date: Mon, 16 Nov 2009 09:33:13 -0800 (PST) Subject: Newsgroup for beginners References: Message-ID: On Nov 16, 8:35?am, Terry Reedy wrote: > mrholtsr wrote: > > Is there a Python newsgroup for those who are strictly beginners at > > programming and python? > > gmane.comp.python.tutor, which I believe mirrors the tutor-list There also is a beginner's forum at python-forum.org: http://www.python-forum.org/pythonforum/viewforum.php?f=3 From python at mrabarnett.plus.com Mon Nov 16 12:39:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 17:39:20 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B018E48.8030505@mrabarnett.plus.com> Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. I like Python > just the way it is. I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? Ada and Turing have: if then do stuff elsif then do stuff else do stuff end if Comal has: if then do stuff elif then do stuff else do stuff end if Modula-2 has: if then do stuff elsif then do stuff else do stuff end From robin at reportlab.com Mon Nov 16 12:42:12 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:42:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <4B0185D8.8040305@chamonix.reportlab.co.uk> References: <4B0185D8.8040305@chamonix.reportlab.co.uk> Message-ID: <4B018EF4.7080603@chamonix.reportlab.co.uk> Robin Becker wrote: ....... > modern sh seems to use this with "fi" as endif eg > > ~: > $ if true; then > > echo true > > elif false; then > > echo false > > else > > echo hostile logic > > fi > true > ~: > $ > I meant to say that since sh uses this construct it cannot be too bad as a language construct since the world is built with sh and bash and similar. Of course that's a bad argument since there's more cobol than everything else put together (allegedly). -- Robin Becker From robin at reportlab.com Mon Nov 16 12:42:12 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 16 Nov 2009 17:42:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <4B0185D8.8040305@chamonix.reportlab.co.uk> References: <4B0185D8.8040305@chamonix.reportlab.co.uk> Message-ID: <4B018EF4.7080603@chamonix.reportlab.co.uk> Robin Becker wrote: ....... > modern sh seems to use this with "fi" as endif eg > > ~: > $ if true; then > > echo true > > elif false; then > > echo false > > else > > echo hostile logic > > fi > true > ~: > $ > I meant to say that since sh uses this construct it cannot be too bad as a language construct since the world is built with sh and bash and similar. Of course that's a bad argument since there's more cobol than everything else put together (allegedly). -- Robin Becker From nobody at nowhere.com Mon Nov 16 12:53:01 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 17:53:01 +0000 Subject: import subprocess in python References: <4605aa41-c286-45b4-a4f4-ff7eb1925683@f20g2000prn.googlegroups.com> <0834aa40-c2f8-4865-aa8d-cc9c4c272b0a@v25g2000yqk.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 04:58:00 -0800, sturlamolden wrote: > On 16 Nov, 13:50, Kuhl wrote: > >> Python 2.2.3 (#1, Feb ?2 2005, 12:22:48) > >> What's the mistake that I am making? How to solve it? > > Your Python version is too old. Your Python version is *way* too old. If you're lucky, people who use features of Python 2.5 or 2.6 will mention that you need Python 2.5 or 2.6, but having at least Python 2.4 is generally taken for granted. From nobody at nowhere.com Mon Nov 16 12:58:07 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 17:58:07 +0000 Subject: Image to SVG conversion with Python References: <8cde555b-e0b0-47a1-9cba-fdc13fe13005@e20g2000vbb.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 07:19:49 -0800, Carlo DiCelico wrote: > I need to convert JPEG and PNG files to SVG. I'm currently using PIL > to generate the JPEG/PNG files to begin with. However, I need to be > able to scale the generated images up in size without a loss of image > quality. Using SVG seems to be the best way to do this, other than > generating the images in the maximum size/resolution in the first > place, which would be too resource intensive. > > I've looked around online and have found some tools for creating SVGs > but none for converting an image into SVG. > > Does anyone have any experience doing this? What would be the best way > to go about this? JPEG/PNG are raster formats, SVG is a vector format. To convert raster graphics to vector graphics, you need a "tracing" program (aka "image tracing", "vector tracing", "vectorizing"), e.g. potrace (this program is often bundled with InkScape): http://potrace.sourceforge.net/ From nobody at nowhere.com Mon Nov 16 13:17:12 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 16 Nov 2009 18:17:12 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote: > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > Does anybody know a language with this kind of syntax for > ifThenElseEndif? BBC BASIC V had if/then/else/endif (it didn't have elif). "make" has if/else/else/endif (it doesn't have a dedicated elif, but "else if ..." behaves like elif rather than starting a nested "if"). > Is there any particular reason why this might be a *bad* language- > design idea? Blocks can be useful for other reasons (e.g. limiting variable scope), so if you already have them, you don't need to provide dedicated blocks for control constructs. From toby at rcsreg.com Mon Nov 16 13:21:08 2009 From: toby at rcsreg.com (Tobiah) Date: Mon, 16 Nov 2009 18:21:08 GMT Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: >> Let me >> be clear, given 2min, how many primes can you find, they need not be in >> order or consecutive. Do they have to go from low to high? :( ) From gagsl-py2 at yahoo.com.ar Mon Nov 16 13:21:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 15:21:10 -0300 Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> Message-ID: En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana escribi?: >> I'm trying to write a simple Win32 app, which may run some Python >> scripts. Since it is a Windows GUI app, I would like to redirect all >> output (Python print, C printf, fprinf stderr, ...) to a text area >> inside the app. In other words, I'm trying to log all the output from >> the app (C, Python) to a window. So far, this works for C printf(): >> [...] >> PS: Maybe I'm doind something wrong, but SetStdHandle() does not work >> at all.... This worked for me: #include #include "Python.h" int main() { HANDLE hReadPipe, hWritePipe; DWORD nr, nw; char buffer[100]; CreatePipe( &hReadPipe, &hWritePipe, NULL, 1024); SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe); Py_Initialize(); PyRun_SimpleString("print 'from Python'"); Py_Finalize(); puts("from C\n"); CloseHandle(hWritePipe); ReadFile(hReadPipe, buffer, 19, &nr, NULL); CloseHandle(hReadPipe); WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); } > Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. I'm using Visual Studio 2008 Express Edition. -- Gabriel Genellina From mmitchell at transparent.com Mon Nov 16 13:30:02 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Mon, 16 Nov 2009 13:30:02 -0500 Subject: tkFileDialog question In-Reply-To: References: Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of r Sent: Monday, November 16, 2009 12:16 AM To: python-list at python.org Subject: Re: tkFileDialog question Matt, There is also a nice thing you need to know about Python if you already do not know. That is the fact that all empty collections bool to False. This makes Truth testing easier. >>> bool([]) False >>> bool('') False >>> bool({}) False >>> bool([1]) True >>> bool([[]]) True >>> bool(' ') True any empty collection, string, or 0 always bools to False. -- http://mail.python.org/mailman/listinfo/python-list Thank you both for all the help. Your suggestions have helped clean up a bunch of my code. Thanks! Matt From showell30 at yahoo.com Mon Nov 16 13:32:19 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 10:32:19 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Nov 16, 2:35?am, Carl Banks wrote: > On Nov 15, 2:52?pm, Steve Howell wrote: > > > Does anybody have any links that points to the rationale for ignoring > > instance definitions of __getitem__ when new-style classes are > > involved? ?I assume it has something to do with performance or > > protecting us from our own mistakes? > > "Not important enough to justify complexity of implementation." > > I doubt they would have left if out of new-style classes if it had > been straightforward to implement (if for no other reason than to > retain backwards compatibility), but it wasn't. ?The way attribute > lookups work meant it would have required all kinds of double lookups > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > easily worked around by simply having __getitem__ call another method, > as you've seen. ?Given all this it made better sense to just leave it > out of new-style classes. Actually, the __getitem__ workaround that I proposed earlier only works on subclasses of dict, not dict themselves. So given a pure dictionary object, it is impossible to hook into attribute lookups after instantiation in debugging/tracing code. I know it's not a super common thing to do, but it is a legitimate use case from my perspective. But I understand the tradeoffs. They seem kind of 20th century to me, but with Moore's Law declining and all, maybe it's a bad time to bring up the "flexibility trumps performance" argument. ;) The backward compatibility argument also seems a little dubious, because if anybody *had* put __getitem__ on a dictionary instance before, it would have already been broken code, and if they hadn't done it, there would be no semantic change, just a performance hit, albeit a pervasive one. > Unfortunately not all such decisions and justifications are collected > in a tidy place. > Yep, that's why I was asking here. I figured somebody might remember a thread on python-dev where this was discussed, or something like that. From python at mrabarnett.plus.com Mon Nov 16 13:37:22 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Nov 2009 18:37:22 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <4B019BE2.1050105@mrabarnett.plus.com> Nobody wrote: > On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote: > >> For a long time I've wondered why languages still use blocks >> (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. >> >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. > >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? > > BBC BASIC V had if/then/else/endif (it didn't have elif). > I forgot about that one. :-( I used to do this in order if I wanted to avoid a lot of indentation: CASE TRUE OF WHEN do something WHEN do something OTHERWISE do something ENDCASE > "make" has if/else/else/endif (it doesn't have a dedicated elif, but > "else if ..." behaves like elif rather than starting a nested "if"). > >> Is there any particular reason why this might be a *bad* language- >> design idea? > > Blocks can be useful for other reasons (e.g. limiting variable scope), so > if you already have them, you don't need to provide dedicated blocks > for control constructs. > From x7-g5W_rt at earthlink.net Mon Nov 16 13:57:36 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Mon, 16 Nov 2009 10:57:36 -0800 (PST) Subject: A "terminators' club" for clp References: <70529349-696e-4f67-8b65-068dc84b71f4@e20g2000vbb.googlegroups.com> Message-ID: On Nov 14, 12:08?pm, r wrote: > On Nov 14, 7:28?am, gil_johnson wrote: > Actually there is a "rank this post" (gotta be careful with that > verbage!) AND a "report this post as spam". Of course it only exists > in GG's and not Usenet. I *do* know that the star system is used quite > frequently, but i doubt anyone bothers to use the "report as spam" > link since it seems have no effect whatsoever. Heh. I should look around more before posting. It does prove your point, though. The 'spam' button is ubiquitous, but so seldom used it's forgotten. Actually, my enthusiasm for my idea faded with a little thought. It is an extra effort to open spam to get to the 'spam' button, and sends the message to the spammer that people are, indeed opening their junk. I'd use it if I opened a message with a deceptive subject. Gil From vs at it.uu.se Mon Nov 16 14:17:18 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 16 Nov 2009 20:17:18 +0100 Subject: Web servers Message-ID: <4B01A53E.1030903@it.uu.se> Any suggestions on using Python to connect to Web servers (e.g. to access financial time series data)? --V. Stokes From clp2 at rebertia.com Mon Nov 16 14:20:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:20:29 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50697b2c0911161120n5669d0caqf259d3fcca2a5e13@mail.gmail.com> On Mon, Nov 16, 2009 at 8:54 AM, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ?if then > ? ? ? ?do stuff > ? ?elif then > ? ? ? ?do stuff > ? ?else > ? ? ? ?do stuff > ? ?endif > > Note that you do not need block delimiters. > Does anybody know a language with this kind of syntax for > ifThenElseEndif? Ruby: if count > 10 puts "Try again" elsif tries == 3 puts "You lose" else puts "Enter a number" end Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Nov 16 14:22:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:22:26 -0800 Subject: Web servers In-Reply-To: <4B01A53E.1030903@it.uu.se> References: <4B01A53E.1030903@it.uu.se> Message-ID: <50697b2c0911161122m7be41b8eoeec1acc787d1a503@mail.gmail.com> On Mon, Nov 16, 2009 at 11:17 AM, Virgil Stokes wrote: > Any suggestions on using Python to connect to Web servers (e.g. to access > financial time series data)? In what format? Using what protocol? (*Insert other basic questions that need answering in order to answer your question here*) Cheers, Chris -- http://blog.rebertia.com From vicente.soler at gmail.com Mon Nov 16 14:36:49 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 16 Nov 2009 11:36:49 -0800 (PST) Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> Message-ID: <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> On Nov 16, 2:35?am, "Gabriel Genellina" wrote: > En Sun, 15 Nov 2009 09:04:06 -0300, vsoler > escribi?: > > > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > > been saving my > > *.py files in the C:\Program Files\Python26 directory, which is the > > default directory for such files in my system. > > > However, I have realised that the above is not the best practice. > > Therefore I created the C:\Program Files\Python26\test directory and I > > want it to be my default directory for saving *.py files, importing > > modules, etc. > > This is *not* a good place either. Non-privileged users should not have > write permission in the C:\Program Files directory. > > > I'd like to do something like the DOS equivalent of ? "CD test" but I > > do not know kow to do it. > > > I am currently doing something really awful: I open a *.py file in the > > test subdirectory, I run it with the F5 key and it works! but I am > > doing really something stupid. > > "it works!" What's the problem then? > > > How should I proceed, if I want to proceed properly? > > Sorry but I don't even see your problem. You can save your .py files ? > anywhere you like... > > -- > Gabriel Genellina Gabriel, When I enter IDLE, I'd like to say at the prompt: "my current directory is... ...test" and then be able to run a module in that directory. This is what my problem is!!! Thank you if you can help From clp2 at rebertia.com Mon Nov 16 14:45:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 11:45:31 -0800 Subject: Changing the current directory (full post) In-Reply-To: <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> Message-ID: <50697b2c0911161145q1b0d7ae6w2c6bcea56663c38d@mail.gmail.com> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: > On Nov 16, 2:35?am, "Gabriel Genellina" > wrote: >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> escribi?: >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> > been saving my >> > *.py files in the C:\Program Files\Python26 directory, which is the >> > default directory for such files in my system. >> >> > However, I have realised that the above is not the best practice. >> > Therefore I created the C:\Program Files\Python26\test directory and I >> > want it to be my default directory for saving *.py files, importing >> > modules, etc. >> >> This is *not* a good place either. Non-privileged users should not have >> write permission in the C:\Program Files directory. >> >> > I'd like to do something like the DOS equivalent of ? "CD test" but I >> > do not know kow to do it. >> >> > I am currently doing something really awful: I open a *.py file in the >> > test subdirectory, I run it with the F5 key and it works! but I am >> > doing really something stupid. >> >> "it works!" What's the problem then? >> >> > How should I proceed, if I want to proceed properly? >> >> Sorry but I don't even see your problem. You can save your .py files >> anywhere you like... >> >> -- >> Gabriel Genellina > > Gabriel, > > When I enter IDLE, I'd like to say at the prompt: "my current > directory is... ?...test" and then be able to run a module in that > directory. This is what my problem is!!! 1. File -> Open 2. Navigate to file and choose it 3. Press F5 Cheers, Chris -- http://blog.rebertia.com From vicente.soler at gmail.com Mon Nov 16 14:56:49 2009 From: vicente.soler at gmail.com (vsoler) Date: Mon, 16 Nov 2009 11:56:49 -0800 (PST) Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> Message-ID: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> On Nov 16, 8:45?pm, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: > > On Nov 16, 2:35?am, "Gabriel Genellina" > > wrote: > >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler > >> escribi?: > > >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've > >> > been saving my > >> > *.py files in the C:\Program Files\Python26 directory, which is the > >> > default directory for such files in my system. > > >> > However, I have realised that the above is not the best practice. > >> > Therefore I created the C:\Program Files\Python26\test directory and I > >> > want it to be my default directory for saving *.py files, importing > >> > modules, etc. > > >> This is *not* a good place either. Non-privileged users should not have > >> write permission in the C:\Program Files directory. > > >> > I'd like to do something like the DOS equivalent of ? "CD test" but I > >> > do not know kow to do it. > > >> > I am currently doing something really awful: I open a *.py file in the > >> > test subdirectory, I run it with the F5 key and it works! but I am > >> > doing really something stupid. > > >> "it works!" What's the problem then? > > >> > How should I proceed, if I want to proceed properly? > > >> Sorry but I don't even see your problem. You can save your .py files > >> anywhere you like... > > >> -- > >> Gabriel Genellina > > > Gabriel, > > > When I enter IDLE, I'd like to say at the prompt: "my current > > directory is... ?...test" and then be able to run a module in that > > directory. This is what my problem is!!! > > 1. File -> Open > 2. Navigate to file and choose it > 3. Press F5 > > Cheers, > Chris > --http://blog.rebertia.com Say that you wanted to import a file in the test directory after just entering IDLE. How would you do it? From rami.chowdhury at gmail.com Mon Nov 16 15:10:56 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 16 Nov 2009 12:10:56 -0800 Subject: Changing the current directory (full post) In-Reply-To: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 11:56:49 -0800, vsoler wrote: > On Nov 16, 8:45?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler >> wrote: >> > On Nov 16, 2:35?am, "Gabriel Genellina" >> > wrote: >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> >> escribi?: >> >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> >> > been saving my >> >> > *.py files in the C:\Program Files\Python26 directory, which is the >> >> > default directory for such files in my system. >> >> >> > However, I have realised that the above is not the best practice. >> >> > Therefore I created the C:\Program Files\Python26\test directory >> and I >> >> > want it to be my default directory for saving *.py files, importing >> >> > modules, etc. >> >> >> This is *not* a good place either. Non-privileged users should not >> have >> >> write permission in the C:\Program Files directory. >> >> >> > I'd like to do something like the DOS equivalent of ? "CD test" >> but I >> >> > do not know kow to do it. >> >> >> > I am currently doing something really awful: I open a *.py file in >> the >> >> > test subdirectory, I run it with the F5 key and it works! but I am >> >> > doing really something stupid. >> >> >> "it works!" What's the problem then? >> >> >> > How should I proceed, if I want to proceed properly? >> >> >> Sorry but I don't even see your problem. You can save your .py files >> >> anywhere you like... >> >> >> -- >> >> Gabriel Genellina >> >> > Gabriel, >> >> > When I enter IDLE, I'd like to say at the prompt: "my current >> > directory is... ?...test" and then be able to run a module in that >> > directory. This is what my problem is!!! >> >> 1. File -> Open >> 2. Navigate to file and choose it >> 3. Press F5 >> >> Cheers, >> Chris >> --http://blog.rebertia.com > > Say that you wanted to import a file in the test directory after just > entering IDLE. How would you do it? http://docs.python.org/library/os.html#os.chdir and http://docs.python.org/library/sys.html#sys.path may be able to help you... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From clp2 at rebertia.com Mon Nov 16 15:11:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 12:11:19 -0800 Subject: Changing the current directory (full post) In-Reply-To: <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> Message-ID: <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> On Mon, Nov 16, 2009 at 11:56 AM, vsoler wrote: > On Nov 16, 8:45?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: >> > On Nov 16, 2:35?am, "Gabriel Genellina" >> > wrote: >> >> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >> >> escribi?: >> >> >> > Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >> >> > been saving my >> >> > *.py files in the C:\Program Files\Python26 directory, which is the >> >> > default directory for such files in my system. >> >> >> > However, I have realised that the above is not the best practice. >> >> > Therefore I created the C:\Program Files\Python26\test directory and I >> >> > want it to be my default directory for saving *.py files, importing >> >> > modules, etc. >> >> >> This is *not* a good place either. Non-privileged users should not have >> >> write permission in the C:\Program Files directory. >> >> >> > I'd like to do something like the DOS equivalent of ? "CD test" but I >> >> > do not know kow to do it. >> >> >> > I am currently doing something really awful: I open a *.py file in the >> >> > test subdirectory, I run it with the F5 key and it works! but I am >> >> > doing really something stupid. >> >> >> "it works!" What's the problem then? >> >> >> > How should I proceed, if I want to proceed properly? >> >> >> Sorry but I don't even see your problem. You can save your .py files >> >> anywhere you like... >> >> > When I enter IDLE, I'd like to say at the prompt: "my current >> > directory is... ?...test" and then be able to run a module in that >> > directory. This is what my problem is!!! >> >> 1. File -> Open >> 2. Navigate to file and choose it >> 3. Press F5 > > Say that you wanted to import a file in the test directory after just > entering IDLE. How would you do it? import sys sys.path.insert(0, "C:/path/to/test/dir/here") import something_in_test_dir Cheers, Chris -- http://blog.rebertia.com From rt8396 at gmail.com Mon Nov 16 15:11:22 2009 From: rt8396 at gmail.com (r) Date: Mon, 16 Nov 2009 12:11:22 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 10:54?am, Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif WHY? Python's syntax is by far the most elegant of all, no need to show the end of a block. Python is the smartest kid on the block. And are you saying you would rather type "then" instead of ":" and "endif" instead of "\n"? No thanks! From pedro.al at fenhi.uh.cu Mon Nov 16 15:27:24 2009 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Mon, 16 Nov 2009 15:27:24 -0500 Subject: TODO and FIXME tags Message-ID: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Hi all.. Sorry if this question sound elemental. How is the sintaxis for set the TODO and FIXME tags...? Thanks -- Lic. Yasser Almeida Hern?ndez Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 271-7933, ext. 221 ---------------------------------------------------------------- Correo FENHI From davea at ieee.org Mon Nov 16 15:29:24 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 15:29:24 -0500 Subject: Web servers In-Reply-To: <4B01A53E.1030903@it.uu.se> References: <4B01A53E.1030903@it.uu.se> Message-ID: <4B01B624.7030102@ieee.org> Virgil Stokes wrote: >

    Any > suggestions on using Python to connect to Web servers (e.g. to access > financial time series data)? > > --V. Stokes > > > You can open a web page for reading with urllib2 module. You can parse html with beautiful soup, or if it's clean xhtml, with the xml module. But parsing raw html is error prone, and subject to change as the web designer reorganizes things. So many web servers also have a protocol intended for data (as opposed to intended for a browser). This is specific to each service, however. If you want to get started in your reading, you could google for "web services", which is one approach using SOAP & WSDL. Note also that most servers have restrictions on the data you access this way. They may or may not be enforceable, but if you access a lot of data from a server, you may be too big a drain on its resources, if it's configured for browser access only. DaveA From henryzhang62 at yahoo.com Mon Nov 16 15:33:15 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Mon, 16 Nov 2009 12:33:15 -0800 (PST) Subject: directory wildcard Message-ID: <637551.57013.qm@web57906.mail.re3.yahoo.com> List, I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) Any right way to do it? Thanks. --henry From falk at mauve.rahul.net Mon Nov 16 15:40:30 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 16 Nov 2009 20:40:30 +0000 (UTC) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: In article , Steve Ferg wrote: >I've often thought that a language with this kind of block-free syntax >would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > >Note that you do not need block delimiters. "then", "else", and "endif" *are* the block delimiters -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From robert.kern at gmail.com Mon Nov 16 15:51:43 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 Nov 2009 14:51:43 -0600 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: On 2009-11-16 14:40 PM, Edward A. Falk wrote: > In article, > Steve Ferg wrote: >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. > > "then", "else", and "endif" *are* the block delimiters I think he meant that you don't need *extra* block delimiters or generic block delimiters like {}. -- 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 deets at nospam.web.de Mon Nov 16 15:54:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 16 Nov 2009 21:54:36 +0100 Subject: directory wildcard In-Reply-To: References: Message-ID: <7mdsgcF3hdui1U1@mid.uni-berlin.de> hong zhang schrieb: > List, > > I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: > > os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? Don't use os system. Use subprocess. Which incidentially is mentioned in the docs for os.system: http://docs.python.org/library/os.html#os.system Then you can pass the "use_shell=True" parameter - which should work in your case. Diez From jeff at jmcneil.net Mon Nov 16 16:01:59 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 16 Nov 2009 13:01:59 -0800 (PST) Subject: directory wildcard References: Message-ID: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> On Nov 16, 3:33?pm, hong zhang wrote: > List, > > I try to assign value to force_mcs sitting in a wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as: > > os.system("echo %i > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? > > Thanks. > > --henry I'd ditch the echo business altogether. 2.x. Not tested. import glob mcs = get_mcs_from_somewhere() for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/ force_mcs'): with open(i, 'w') as f: print >>f, mcs Thanks, Jeff mcjeff.blogspot.com From ecir.hana at gmail.com Mon Nov 16 16:04:21 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Mon, 16 Nov 2009 13:04:21 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> Message-ID: <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> On Nov 16, 7:21?pm, "Gabriel Genellina" wrote: > En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana ? > escribi?: > > >> I'm trying to write a simple Win32 app, which may run some Python > >> scripts. Since it is a Windows GUI app, I would like to redirect all > >> output (Python print, C printf, fprinf stderr, ...) to a text area > >> inside the app. In other words, I'm trying to log all the output from > >> the app (C, Python) to a window. So far, this works for C printf(): > >> [...] > >> PS: Maybe I'm doind something wrong, but SetStdHandle() does not work > >> at all.... > > This worked for me: > > #include > #include "Python.h" > > int main() > { > ? ?HANDLE hReadPipe, hWritePipe; > ? ?DWORD nr, nw; > ? ?char buffer[100]; > > ? ?CreatePipe( > ? ? ?&hReadPipe, > ? ? ?&hWritePipe, > ? ? ?NULL, > ? ? ?1024); > ? ?SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe); > > ? ?Py_Initialize(); > ? ?PyRun_SimpleString("print 'from Python'"); > ? ?Py_Finalize(); > > ? ?puts("from C\n"); > > ? ?CloseHandle(hWritePipe); > ? ?ReadFile(hReadPipe, buffer, 19, &nr, NULL); > ? ?CloseHandle(hReadPipe); > ? ?WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); > > } > > Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC. > > I'm using Visual Studio 2008 Express Edition. > > -- > Gabriel Genellina Hi, thanks for the reply! However, please, could you tell me how many bytes it read here: ReadFile(hReadPipe, buffer, 19, &nr, NULL); because for me, it has read 0. When I run your code, it prints from both C and Python, but it prints straight to the console, not to the buffer. Could you also please try to add: WriteFile(GetStdHandle(STD_ERROR_HANDLE), "----\n", 5, &nw, NULL); before: WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, &nw, NULL); Does it print "----" before "from Python" and "from C" for you? Because for me it comes afterwards (as nr is 0)... From davea at ieee.org Mon Nov 16 16:10:51 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 16 Nov 2009 16:10:51 -0500 Subject: Changing the current directory (full post) In-Reply-To: <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> Message-ID: <4B01BFDB.7090806@ieee.org> Chris Rebert wrote: > On Mon, Nov 16, 2009 at 11:56 AM, vsoler wrote: > >> On Nov 16, 8:45 pm, Chris Rebert wrote: >> >>> On Mon, Nov 16, 2009 at 11:36 AM, vsoler wrote: >>> >>>> On Nov 16, 2:35 am, "Gabriel Genellina" >>>> wrote: >>>> >>>>> En Sun, 15 Nov 2009 09:04:06 -0300, vsoler >>>>> escribi?: >>>>> >>>>>> Ever since I installed my Python 2.6 interpreter (I use IDLE), I've >>>>>> been saving my >>>>>> *.py files in the C:\Program Files\Python26 directory, which is the >>>>>> default directory for such files in my system. >>>>>> >>>>>> However, I have realised that the above is not the best practice. >>>>>> Therefore I created the C:\Program Files\Python26\test directory and I >>>>>> want it to be my default directory for saving *.py files, importing >>>>>> modules, etc. >>>>>> >>>>> This is *not* a good place either. Non-privileged users should not have >>>>> write permission in the C:\Program Files directory. >>>>> >>>>>> I'd like to do something like the DOS equivalent of "CD test" but I >>>>>> do not know kow to do it. >>>>>> >>>>>> I am currently doing something really awful: I open a *.py file in the >>>>>> test subdirectory, I run it with the F5 key and it works! but I am >>>>>> doing really something stupid. >>>>>> >>>>> "it works!" What's the problem then? >>>>> >>>>>> How should I proceed, if I want to proceed properly? >>>>>> >>>>> Sorry but I don't even see your problem. You can save your .py files >>>>> anywhere you like... >>>>> >>>> When I enter IDLE, I'd like to say at the prompt: "my current >>>> directory is... ...test" and then be able to run a module in that >>>> directory. This is what my problem is!!! >>>> >>> 1. File -> Open >>> 2. Navigate to file and choose it >>> 3. Press F5 >>> >> Say that you wanted to import a file in the test directory after just >> entering IDLE. How would you do it? >> > > import sys > sys.path.insert(0, "C:/path/to/test/dir/here") > import something_in_test_dir > > Cheers, > Chris > -- > http://blog.rebertia.com > > Change directory to the test-directory Then run idle From ben+python at benfinney.id.au Mon Nov 16 16:17:17 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 08:17:17 +1100 Subject: IDE for python References: Message-ID: <87vdhanp9e.fsf@benfinney.id.au> Jonathan Hartley writes: > I'd like to offer the group the anecdote of the great Resolver IDE > migration. [?] It's great to see something refreshing and new ? data beyond a single person's subjective experience! ? come out of a topic that looked like it was just going to re-hash the same tired topic. Thank you. -- \ ?What I resent is that the range of your vision should be the | `\ limit of my action.? ?Henry James | _o__) | Ben Finney From python.list at tim.thechases.com Mon Nov 16 16:22:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 15:22:25 -0600 Subject: directory wildcard In-Reply-To: <637551.57013.qm@web57906.mail.re3.yahoo.com> References: <637551.57013.qm@web57906.mail.re3.yahoo.com> Message-ID: <4B01C291.7000807@tim.thechases.com> > I try to assign value to force_mcs sitting in a wildcard > subdirectory /sys/kernel/debug/ieee80211/phy*, but python does > not work for that such as: > > os.system("echo %i > > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % mcs) > > Any right way to do it? I'm not sure your code works if there's more than one phy* directory in that folder anyways since ">" piping usually only works for a single destination. Though I'd imagine this is only a problem for folks that have more than one 802.11 card in their machine (which I've done...a useless on-board and a PCMCIA on an older laptop). I'd use python's built-in glob module to do something like from glob import glob def set_force_mcs(mcs): for fname in glob('/sys/kernel/debug/' 'ieee80211/phy*/iwlagn/data/force_mcs'): f = open(fname, 'w') f.write('%i\n' % mcs) f.close() #the following should all work set_force_mcs(True) set_force_mcs(False) set_force_mcs(1) set_force_mcs(0) (I broke the for/glob line intentionally in a way that python transparently restores in case mailers munged them between here in there...normally, I'd just use a single string parameter for glob() instead of line-breaking it if it fit in 80 chars) If you're using a more recent version of python that has the "with" command (I think it was added in 2.6, and available from 2.5's future), it could be tidied to with open(fname, 'w') as f: f.write('%i\n' % mcs) -tkc From heintest at web.de Mon Nov 16 16:49:30 2009 From: heintest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Mon, 16 Nov 2009 22:49:30 +0100 Subject: mySQL access speed Message-ID: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Hello, I have some programs doing a lot sql IO in some mySQL databases. This works very fine and the DBAPI is quite simple to understand. Now I came to the point where I had to insert millions of lines into a table. My first aproach was to insert the data using executemany(). That's not bad and fairly simple to use. But it isn't very fast. For executemany I have some hundred thousend lines in a list of tuples. I joined() these lines to form an insert into table values (....) statement and blew it into the mysql cmdline client via os.popen(). This was 60(!) times faster and loaded my table in seconds! Is the mySQL module so slow ? Any ideas to have the mySQL module working faster ? The popen() way seems quite clumsy and not very pythonic for me, Greetings Hans From brownbar at gmail.com Mon Nov 16 17:14:33 2009 From: brownbar at gmail.com (Barry W Brown) Date: Mon, 16 Nov 2009 14:14:33 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 10:54?am, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? Fortran95. You can even label the IF...END IF structure -- handy for immense blocks. This is not a criticism of Python (or of Fortran). From henryzhang62 at yahoo.com Mon Nov 16 17:19:16 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Mon, 16 Nov 2009 14:19:16 -0800 (PST) Subject: directory wildcard In-Reply-To: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> Message-ID: <484826.59786.qm@web57901.mail.re3.yahoo.com> --- On Mon, 11/16/09, Jeff McNeil wrote: > From: Jeff McNeil > Subject: Re: directory wildcard > To: python-list at python.org > Date: Monday, November 16, 2009, 3:01 PM > On Nov 16, 3:33?pm, hong zhang > > wrote: > > List, > > > > I try to assign value to force_mcs sitting in a > wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but > python does not work for that such as: > > > > os.system("echo %i > > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs" % > mcs) > > > > Any right way to do it? > > > > Thanks. > > > > --henry > > I'd ditch the echo business altogether. 2.x. Not tested. > > import glob > > mcs = get_mcs_from_somewhere() > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/ > force_mcs'): > ? ? with open(i, 'w') as f: > ? ? ? ? print >>f, mcs This assigns decimal value, how can I assign Hex here to mcs? > From dikkie at nospam.org Mon Nov 16 17:28:35 2009 From: dikkie at nospam.org (Dikkie Dik) Date: Mon, 16 Nov 2009 23:28:35 +0100 Subject: mySQL access speed In-Reply-To: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> References: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b01d215$0$8788$bf4948fe@news.tele2.nl> > ... But it isn't very fast. > For executemany I have some hundred thousend lines in a list of tuples. > I joined() these lines to form an insert into table values (....) statement and > blew it into the mysql cmdline client via os.popen(). > This was 60(!) times faster and loaded my table in seconds! > > Is the mySQL module so slow ? No. The fact that each statement is atomic makes it slow. Try the multiple queries, but precede them with a "SET AUTOCOMMIT=0" statement or use a transaction. You will probably see a tremendous speed increase. When you combine all the queries into one statement, you are effectively doing the same. Best regards, Dikkie. From hyunchul.mailing at gmail.com Mon Nov 16 17:30:27 2009 From: hyunchul.mailing at gmail.com (Hyunchul Kim) Date: Tue, 17 Nov 2009 07:30:27 +0900 Subject: faster than list.extend() Message-ID: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Hi, all. I want to improve speed of following simple function. Any suggestion? ********** def triple(inputlist): results = [] for x in inputlist: results.extend([x,x,x]) return results ********** Thank you in advance, Hyunchul -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Mon Nov 16 17:37:11 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 16 Nov 2009 14:37:11 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <362dnUU5fJKKSZzWnZ2dnUVZ_jRi4p2d@giganews.com> r wrote: > On Nov 16, 10:54 am, Steve Ferg > wrote: > >> I've often thought that a language with this kind of block-free syntax >> would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif > > WHY? Python's syntax is by far the most elegant of all, no need to > show the end of a block. Python is the smartest kid on the block. And > are you saying you would rather type "then" instead of ":" and "endif" > instead of "\n"? > > No thanks! You clipped out the part where he explicitly said it was not a suggestion to change Python. -- 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/Skype erikmaxfrancis Mona Lisa / Come to discover / I am your daughter -- Lamya From max at alcyone.com Mon Nov 16 17:38:33 2009 From: max at alcyone.com (Erik Max Francis) Date: Mon, 16 Nov 2009 14:38:33 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <362dnUQ5fJL0SZzWnZ2dnUVZ_jRi4p2d@giganews.com> Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. It's the same syntax, with `fi` written instead of `endif` -- not sure why the difference in keyword is that big of a deal to you. As others have pointed out, either way, there are quite a few languages that use this type of syntax. -- 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/Skype erikmaxfrancis Mona Lisa / Come to discover / I am your daughter -- Lamya From clp2 at rebertia.com Mon Nov 16 17:41:25 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 14:41:25 -0800 Subject: faster than list.extend() In-Reply-To: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <50697b2c0911161441l1d9a7bc0k283db2617a3954ee@mail.gmail.com> On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim wrote: > Hi, all. > > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > ? results = [] > ? for x in inputlist: > ??? results.extend([x,x,x]) > ? return results > ********** You'd probably be better off calling .append() 3 times instead of .extend() as it would avoid the creation of all those intermediate 3-element lists. Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Mon Nov 16 17:54:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 19:54:45 -0300 Subject: Changing the current directory (full post) References: <32b681eb-914c-4669-a75e-2225932ee65b@s15g2000yqs.googlegroups.com> <234494db-b790-4026-99f9-76e36e5a91a1@a31g2000yqn.googlegroups.com> <81531fb9-93bb-4f0f-a84d-f63f8b59b7de@j14g2000yqm.googlegroups.com> <50697b2c0911161211p17addb43m9063763fdc4c5052@mail.gmail.com> <4B01BFDB.7090806@ieee.org> Message-ID: En Mon, 16 Nov 2009 18:10:51 -0300, Dave Angel escribi?: > Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 11:56 AM, vsoler >> wrote: >>>>> When I enter IDLE, I'd like to say at the prompt: "my current >>>>> directory is... ...test" and then be able to run a module in that >>>>> directory. This is what my problem is!!! > Change directory to the test-directory > Then run idle Or, modify the Initial Directory in the menu shortcut that you use to start IDLE (right click, Properties). Or create another shortcut in your desktop using your desired initial directory. -- Gabriel Genellina From python.list at tim.thechases.com Mon Nov 16 17:55:55 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 16:55:55 -0600 Subject: faster than list.extend() In-Reply-To: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <4B01D87B.30102@tim.thechases.com> Hyunchul Kim wrote: > Hi, all. > > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > results = [] > for x in inputlist: > results.extend([x,x,x]) > return results > ********** Several ways occur to me: def t1(i): for x in i: yield x yield x yield x def t2(i): r = range(3) return (x for x in i for _ in r) I prefer to return generators in case the input is large, but in both cases, you can just wrap it in list() like list(t1(inputlist)) or in t2(), you can just change it to use return [x for x in i for _ in r] -tkc From rantingrick at gmail.com Mon Nov 16 18:18:23 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 16 Nov 2009 15:18:23 -0800 (PST) Subject: Command line arguments?? Message-ID: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> I am currently having "fun" with command line arguments in a windows environment. If i get a path that has spaces anywhere in it my script gets the wrong arguments from sys.argv. You guy's probably know what i am talking about. Heres and example. 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' inside my script i get the following result from sys.argv ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ \text.txt'] So i've got a few options 1. have people replace every space in all file paths system wide (sucks) 2. Create a custom parser, join the argv list, parse it...(maybe) 3. please tell me there is an option 3? (hopefully) From benjamin.kaplan at case.edu Mon Nov 16 18:23:58 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 16 Nov 2009 18:23:58 -0500 Subject: Command line arguments?? In-Reply-To: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, Nov 16, 2009 at 6:18 PM, rantingrick wrote: > I am currently having "fun" with command line arguments in a windows > environment. If i get a path that has spaces anywhere in it my script > gets the wrong arguments from sys.argv. You guy's probably know what i > am talking about. Heres and example. > > 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' > > inside my script i get the following result from sys.argv > > ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ > \text.txt'] > > So i've got a few options > ?1. have people replace every space in all file paths system wide > (sucks) > ?2. Create a custom parser, join the argv list, parse it...(maybe) > ?3. please tell me there is an option 3? (hopefully) > -- > http://mail.python.org/mailman/listinfo/python-list > The same thing you have to do with every command line program - wrap it in quotes. C:\\Python26\\python.exe C:\\echo.py "C:\\New Folder\\text.txt" From python at rcn.com Mon Nov 16 18:28:40 2009 From: python at rcn.com (Raymond Hettinger) Date: Mon, 16 Nov 2009 15:28:40 -0800 (PST) Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: On Nov 16, 2:41?pm, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim > > wrote: > > Hi, all. > > > I want to improve speed of following simple function. > > Any suggestion? > > > ********** > > def triple(inputlist): > > ? results = [] > > ? for x in inputlist: > > ??? results.extend([x,x,x]) > > ? return results Here's an itertools variant that is somewhat speedy when the inputlist is long: from itertools import * def triple3(inputlist, list=list, chain_from_iterable=chain.from_iterable, izip=izip): return list(chain_from_iterable(izip(inputlist, inputlist, inputlist))) Raymond From rhodri at wildebst.demon.co.uk Mon Nov 16 18:30:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 16 Nov 2009 23:30:09 -0000 Subject: Command line arguments?? In-Reply-To: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 23:18:23 -0000, rantingrick wrote: > I am currently having "fun" with command line arguments in a windows > environment. If i get a path that has spaces anywhere in it my script > gets the wrong arguments from sys.argv. You guy's probably know what i > am talking about. Heres and example. > > 'C:\\Python26\\Python.exe C:\\echo.py C:\\New Folder\\text.txt' > > inside my script i get the following result from sys.argv > > ['C:\\Python26\\Python.exe', 'C:\\echo.py', 'C:\\New', 'Folder\ > \text.txt'] > > So i've got a few options > 1. have people replace every space in all file paths system wide > (sucks) > 2. Create a custom parser, join the argv list, parse it...(maybe) > 3. please tell me there is an option 3? (hopefully) Quote the filenames or escape the spaces: C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" We've been living with this pain ever since windowed GUIs encouraged users to put spaces in their file names (Apple, I'm looking at you!). Fundamentally, if people want the pretty they have to live with the consequences. -- Rhodri James *-* Wildebeest Herder to the Masses From threaderslash at gmail.com Mon Nov 16 18:34:34 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 10:34:34 +1100 Subject: QtPython QtreeWidget - sortingEnabled Problem Message-ID: Hello Everybody, I trying to do a Qtreewidget to attend a customer design suggestion. I am coding it on QtPython. I did a first try using Qt Designer, then generated the code. But when I try to run it, an error comes out: self.centralwidget.setSortingEnabled(__sortingEnabled) AttributeError: setSortingEnabled I googled around, but didn't find any solution for this problem, except some suggestion just to simply delete the lines in the code that results in the compiling error. But it didn't really help, because if you do so, it triggers more error, just like that: self.treeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Item Name", None, QtGui.QApplication.UnicodeUTF8)) AttributeError: 'NoneType' object has no attribute 'setText' Here is my current code to generate a nice simple QtreeWidget/View: #//===========================================================//# def color_setupUi(self, MainWindow,phrase): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.eqpt_centralwdg(MainWindow) self.eqpt_retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) #//===========================================================//# def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") item = QtGui.QTreeWidgetItem(self.colorTreeWidget) item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.centralwidget.setSortingEnabled(__sortingEnabled) MainWindow.setCentralWidget(self.centralwidget) #//===========================================================//# def eqpt_retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "color", None, QtGui.QApplication.UnicodeUTF8) __sortingEnabled = self.colorTreeWidget.isSortingEnabled() self.colorTreeWidget.setSortingEnabled(False) self.colorTreeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Blue", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.setSortingEnabled(__sortingEnabled) #//===========================================================//# All other object I needed to implement on Qt using Designer and a little bit of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I just got stuck with this TreeWidget error. Any hints or suggestion are highly appreciated and welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Mon Nov 16 19:06:37 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 17 Nov 2009 13:06:37 +1300 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <7me7osF3hikpfU1@mid.individual.net> Christian Heimes wrote: > Most magic methods are implemented as descriptors. Descriptors only > looked up on the type to increase the performance of the interpreter and > to simply the C API. There's also a semantic problem. Since new-style classes are also instances (of class 'type') and you can create subclasses of 'type', if special methods were looked up on instances, it would be ambiguous whether an attribute '__getitem__' on a class was meant to specify the behaviour of the [] operation on its instances, or on the class itself. This problem didn't arise with old-style classes, because classes and instances were clearly separated (i.e. old-style classes were not old-style instances). -- Geg From glenn at zewt.org Mon Nov 16 19:23:51 2009 From: glenn at zewt.org (Glenn Maynard) Date: Mon, 16 Nov 2009 19:23:51 -0500 Subject: ZipFile - file adding API incomplete? Message-ID: I want to do something fairly simple: read files from one ZIP and add them to another, so I can remove and replace files. This led me to a couple things that seem to be missing from the API. The simple approach would be to open each file in the source ZIP, and hand it off to newzip.write(). There's a missing piece, though: there's no API that lets me pass in a file-like object and a ZipInfo, to preserve metadata. zip.write() only takes the filename and compression method, not a ZipInfo; writestr takes a ZipInfo but only accepts a string, not a file. Is there an API call I'm missing? (This seems like the fundamental API for adding files, that write and writestr should be calling.) The correct approach is to copy the data directly, so it's not recompressed. This would need two new API calls: rawopen(), acting like open() but returning a direct file slice and not decompressing data; and rawwrite(zinfo, file), to pass in pre-compressed data, where the compression method in zinfo matches the compression type used. I was surprised that I couldn't find the former. The latter is an advanced one, important for implementing any tool that modifies large ZIPs. Short-term, at least, I'll probably implement these externally. -- Glenn Maynard From contact at xavierho.com Mon Nov 16 19:32:43 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Nov 2009 10:32:43 +1000 Subject: Logic operators with "in" statement In-Reply-To: <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> Message-ID: <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> On Tue, Nov 17, 2009 at 12:46 AM, Chris Rebert wrote: > On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote: > > AND operator has a higher precedence, so you don't need any brackets > here, I > > think. But anyway, you have to use it like that. So that's something > you'll > > have to fix first. > > Er, you mean lower precedence. Higher precedence means it would bind > tighter, thus the expression would mean: > '3' in (l and 'no3') in l > which is certainly incorrect. > > Thanks for the correction, Chris. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Nov 16 20:46:05 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Nov 2009 01:46:05 GMT Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 10:32:19 -0800, Steve Howell wrote: > Actually, the __getitem__ workaround that I proposed earlier only works > on subclasses of dict, not dict themselves. So given a pure dictionary > object, it is impossible to hook into attribute lookups after > instantiation in debugging/tracing code. If you have written your application to avoid unnecessary isinstance and type checks, i.e. to use duck-typing, then a technique you might find useful is delegation. class DebuggingDict(object): def __init__(self, dict_to_wrap, hook=None): self.__dict__['_d'] = dict_to_wrap self.__dict__['getitem_hook'] = hook def __getattr__(self, name): return getattr(self._d, name) def __setattr__(self, name, value): setattr(self._d, name, value) def __getitem__(self, key): if self.getitem_hook is not None: self.getitem_hook(self, key) return self._d[key] And in use: >>> def hook(self, key): ... print "Looking for key", key ... >>> d = DebuggingDict({1:'a', 2: 'b'}, hook) >>> d[1] Looking for key 1 'a' >>> d[2] Looking for key 2 'b' -- Steven From gagsl-py2 at yahoo.com.ar Mon Nov 16 21:15:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 16 Nov 2009 23:15:06 -0300 Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: En Mon, 16 Nov 2009 19:30:27 -0300, Hyunchul Kim escribi?: > I want to improve speed of following simple function. > Any suggestion? > > ********** > def triple(inputlist): > results = [] > for x in inputlist: > results.extend([x,x,x]) > return results > ********** These are my best attempts: def triple3(inputlist): results = [] append = results.append for x in inputlist: append(x); append(x); append(x) return results def triple4(inputlist, _three=xrange(3)): return [x for x in inputlist for _ in _three] For a 400-items list, triple3 is 40% faster and triple4 25% faster than yours. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Mon Nov 16 21:19:30 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Nov 2009 02:19:30 GMT Subject: basic class question.. References: <7mabt8F3gdudpU1@mid.uni-berlin.de> <3aac5257-9d95-4de7-97db-563ee5a812a4@b36g2000prf.googlegroups.com> Message-ID: On Sun, 15 Nov 2009 16:26:59 -0800, Pyrot wrote: > On 11?15?, ??9?52?, "Diez B. Roggisch" wrote: >> Pyrot schrieb: >> >> > class rawDNA: >> > ? ?import string [...] > (Tthe core reason that I'm bothering with this at all is because I heard > imports are costly(in time, space, processing power). If this turns out > to be a non-issue, than my questions regarding Imports are all moot :->) Importing a module is only costly the first time (in any session) that you do so. Modules are cached, so the second time it is relatively fast. > I forgot to write about my second question which was: > > what happens when I use the import statement within a class/function > declaration? > I'm thinking either > 1) It imports during the class/function declaration > 2) It imports the first time a class/function call(x = rawDNA() ) occurs It imports when the class/function statement is *run*. def f(): import math The body of the function doesn't run until you call the function, so the import doesn't happen until you call f(). class K: import math def method(self): import string The class definition runs when you create the class, which imports math. But string is only imported when you call K().method(). > But if it's 2) then is the import valid outside of the function/class? No. The *name* "math" exists only inside the scope of the function, or class, and is not visible outside. >>> class K: ... import math ... >>> K.math >>> math Traceback (most recent call last): File "", line 1, in NameError: name 'math' is not defined > what happens when the last function reference is removed?(del x) You wrote: x = rawDNA() Deleting x won't do anything to the class rawDNA, or to the module string which is referenced by the rawDNA class. If you delete the rawDNA class, that won't do anything to the string module cached in sys. > I respect your(or anyone who would like to help me) time, so all I ask > is some kind of document or "Best practices" guide dealing all about > "import". 99.9% of the time you don't need to worry about it. Just import the modules you want at the top level of your program, and be happy that it all works fine. The other 0.1% of the time, you might have one or two good reasons for putting imports inside functions: (1) Encapsulation: you want to import a module to use in a function, without making it visible to other functions. (2) Just In Time importing. Imports at the top level slow down your program's start up. Normally, this is trivial and it is not worth the extra complexity to do something about it, but if you have a particularly expensive module which happens to be used only in one function which is rarely needed, then you can speed up your program for the majority of times by putting the import inside that one function. However, putting imports inside functions which are then called by threads can lead to deadlocks. So you also have to balance the risk of that happening. -- Steven From http Mon Nov 16 21:20:30 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:20:30 -0800 Subject: Python & Go References: <9e1bff5b-5311-427b-b417-6d31fa352538@j24g2000yqa.googlegroups.com> <24c0305e-e77b-4f76-9687-6bafa85f9848@w19g2000yqk.googlegroups.com> <7x8webruiw.fsf@ruckus.brouhaha.com> <7xpr7lixnn.fsf@ruckus.brouhaha.com> <129a67e4-328c-42b9-9bf3-152f1b76fa5a@k19g2000yqc.googlegroups.com> <7x8we9t0or.fsf@ruckus.brouhaha.com> <99fff8de-5ecc-4bde-b486-f66b018532dc@g27g2000yqn.googlegroups.com> Message-ID: <7xr5rxyjrl.fsf@ruckus.brouhaha.com> sturlamolden writes: > A decorator function like @go could just call os.fork and run the > function in the child. We already have a between-process Queue in > multiprocessing to use as channels. Unlike with interthread queues, you have to serialize the values sent through those multiprocessing channels. I don't think you can send functions, generators, file descriptors, etc. From http Mon Nov 16 21:27:05 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:27:05 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> Message-ID: <7xmy2lyjgm.fsf@ruckus.brouhaha.com> sturlamolden writes: > > ? ? ? Python is a very clean language held back from widespread use by slow > > implementations. ?If Python ran faster, Go would be unnecessary. > > Google is a multi-billion dollar business. They are using Python > extensively. Yes I know about Unladen Swallow, but why can't they put > 1 mill dollar into making a fast Python? I don't think Python and Go address the same set of programmer desires. For example, Go has a static type system. Some programmers find static type systems to be useless or undesirable. Others find them extremely helpful and want to use them them. If you're a programmer who wants a static type system, you'll probably prefer Go to Python, and vice versa. That has nothing to do with implementation speed or development expenditures. If Google spent a million dollars adding static types to Python, it wouldn't be Python any more. From http Mon Nov 16 21:31:44 2009 From: http (Paul Rubin) Date: 16 Nov 2009 18:31:44 -0800 Subject: Newsgroup for beginners References: Message-ID: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> mrholtsr writes: > Is there a Python newsgroup for those who are strictly beginners at > programming and python? This group has its grouchy moments but for the most part it's reasonably friendly to beginners. The worst thing that usually happens is that if you ask a simple question, a bunch of experts will show off their knowledge to each other by giving you insanely complicated answers that you have no reason to want to understand. But they're not exactly being hostile when they do that. They're just really really into advanced Python programming. So go ahead and ask your questions. The first responses will probably be the most helpful, after which the response thread will go off into nerdy tangents that you can ignore. From jasonsewall at gmail.com Mon Nov 16 21:56:31 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Mon, 16 Nov 2009 21:56:31 -0500 Subject: faster than list.extend() In-Reply-To: References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: <31e9dd080911161856g56751d52sf22514550644d5b9@mail.gmail.com> On Mon, Nov 16, 2009 at 6:28 PM, Raymond Hettinger wrote: > On Nov 16, 2:41?pm, Chris Rebert wrote: >> On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim >> >> wrote: >> > Hi, all. >> >> > I want to improve speed of following simple function. >> > Any suggestion? >> >> > ********** >> > def triple(inputlist): >> > ? results = [] >> > ? for x in inputlist: >> > ??? results.extend([x,x,x]) >> > ? return results > > > Here's an itertools variant that is somewhat speedy when the inputlist > is long: > > ? ?from itertools import * > > ? ?def triple3(inputlist, list=list, > chain_from_iterable=chain.from_iterable, izip=izip): > ? ? ? ?return list(chain_from_iterable(izip(inputlist, inputlist, > inputlist))) Even (slightly) faster: def triple3_mk2(inputlist): return list(chain.from_iterable(izip(*repeat(inputlist, 3)))) I tried something like this when I saw Hyunchul's original email, but I didn't know about chain.from_iterable and it was pretty slow compared to the original. Adding (itertools.)repeat to Raymonds speeds it up 5-10% more. I'm pretty surprised this is faster than Tim's t2 (which is actually a little slower than the original); I always thought of comprehensions as the fastest way to do this find of stuff. Jason From threaderslash at gmail.com Mon Nov 16 22:07:10 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 14:07:10 +1100 Subject: Solved: QtPython QtreeWidget - sortingEnabled Problem Message-ID: > ---------- ---------- > From: Threader Slash > To: python-list at python.org > Date: Tue, 17 Nov 2009 10:34:34 +1100 > Subject: QtPython QtreeWidget - sortingEnabled Problem > Hello Everybody, > > I trying to do a Qtreewidget to attend a customer design suggestion. I am > coding it on QtPython. I did a first try using Qt Designer, then generated > the code. But when I try to run it, an error comes out: > > self.centralwidget.setSortingEnabled(__sortingEnabled) > AttributeError: setSortingEnabled > > I googled around, but didn't find any solution for this problem, except > some suggestion just to simply delete the lines in the code that results in > the compiling error. But it didn't really help, because if you do so, it > triggers more error, just like that: > > self.treeWidget.topLevelItem(0).child(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Item Name", None, > QtGui.QApplication.UnicodeUTF8)) > AttributeError: 'NoneType' object has no attribute 'setText' > > Here is my current code to generate a nice simple QtreeWidget/View: > > #//===========================================================//# > def color_setupUi(self, MainWindow,phrase): > MainWindow.setObjectName("MainWindow") > MainWindow.resize(800, 600) > self.eqpt_centralwdg(MainWindow) > self.eqpt_retranslateUi(MainWindow) > QtCore.QMetaObject.connectSlotsByName(MainWindow) > #//===========================================================//# > def eqpt_centralwdg(self,MainWindow): > self.centralwidget = QtGui.QWidget(MainWindow) > self.centralwidget.setObjectName("centralwidget") > > self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) > self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) > self.colorTreeWidget.setObjectName("colorTreeWidget") > > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > > self.centralwidget.setSortingEnabled(__sortingEnabled) > MainWindow.setCentralWidget(self.centralwidget) > #//===========================================================//# > def eqpt_retranslateUi(self, MainWindow): > > MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", > "MainWindow", None, QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.headerItem().setText(0, > QtGui.QApplication.translate("MainWindow", "color", None, > QtGui.QApplication.UnicodeUTF8) > __sortingEnabled = self.colorTreeWidget.isSortingEnabled() > self.colorTreeWidget.setSortingEnabled(False) > self.colorTreeWidget.topLevelItem(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow", None, > QtGui.QApplication.UnicodeUTF8) > self.colorTreeWidget.topLevelItem(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Blue", None, > QtGui.QApplication.UnicodeUTF8) > self.colorTreeWidget.setSortingEnabled(__sortingEnabled) > #//===========================================================//# > > All other object I needed to implement on Qt using Designer and a little > bit of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I > just got stuck with this TreeWidget error. > > Any hints or suggestion are highly appreciated and welcome. > > ---------- ---------- > Here is the solution: 1. delete/comment only the following line: #self.centralwidget.setSortingEnabled(__sortingEnabled) Then code: [code] def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") item = QtGui.QTreeWidgetItem(self.colorTreeWidget) item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.connect(self.colorTreeWidget, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.eqpt_activateInput) MainWindow.setCentralWidget(self.centralwidget) def eqpt_activateInput(self,item,col): print "Qtree ok! pressed" print item.text(col) [/code] Hope this may help others too. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From fred at bsdhost.net Mon Nov 16 22:16:21 2009 From: fred at bsdhost.net (Fred C) Date: Mon, 16 Nov 2009 19:16:21 -0800 Subject: ReverseProxy Message-ID: I have to write a quick and dirty ReverseProxy with Twisted, for one of our internal project. I never used Twisted before, and I was wondering of someone have an handy example of a ReverseProxy with Twisted to help that I can use as bootstrap. Many thanks. Fred -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Mon Nov 16 22:28:54 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 16 Nov 2009 19:28:54 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: Steve Ferg wrote: > Does anybody know a language with this kind of syntax for > ifThenElseEndif? VBScript. > Is there any particular reason why this might be a *bad* language- > design idea? VBScript. From yuzhichang at gmail.com Mon Nov 16 22:40:29 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Mon, 16 Nov 2009 19:40:29 -0800 (PST) Subject: Is pexpect unmaintained now? Message-ID: <252facf7-f9c6-4c6a-9d7f-ac69a830e6f0@h14g2000pri.googlegroups.com> Pexpect 2.4 is only available at Pypi. Both the homepage of pexpect(http://www.noah.org/wiki/Pexpect) and download page (http://sourceforge.net/projects/pexpect/files/) are outdated. The repository on Github (http://github.com/noahspurrier/pexpect/) has been removed. I ever contacted the author(noah at noah.org) but no response till now. I'm going to fork pexpect on Github and add some features... From invalid at invalid.invalid Mon Nov 16 22:56:42 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 17 Nov 2009 03:56:42 +0000 (UTC) Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: On 2009-11-17, Paul Rubin wrote: > mrholtsr writes: >> Is there a Python newsgroup for those who are strictly beginners at >> programming and python? > > This group has its grouchy moments You've really got to try pretty hard to create one. But if you want to, here's how to do it: 1) Start by complaining that your program doesn't work because of a bug in Python. 2) Python programs are portable, so don't reveal what OS or Python version you're using. People will ask. Just ignore them. 2) State that your program "doesn't work", but don't explain either what you expect it to do or what it actually does. 3) Don't post the code that you're having problems with. 4) Once people start to get annoyed that you won't post any example code showing the problem you're having, then you post code. a) Post lots of code. The bigger the program the better; try for at least 500 lines -- but make sure that you leave out a few functions and "import" some libraries nobody has ever heard of. b) Post code that doesn't match the code who's behaviour you're describing (remember: be vague and be careful not to actually show real input or output at this point). c) For maximum effect try to make sure that what you post won't compile by inserting typos and changing the indentation in a few places. 5) Once you've stalled as long as possible you want to post code that will comipile and run. Now we move on to example inout and output. a) post output from a _different_ version of the program than what you're running. b) post input to and output from your program, but make sure that the output was generated with input differenent that what was posted. c) rather than cutting/pasting input and output, make sure you manually retype it into your posting -- inaccurately. In any other newsgroup, you'd have been burnt to a crisp and plonked long before getting this far, but in c.l.p there are still going to be a few people trying to help you. Now is the time to start making snide comments about how it would be so much easier in VB/Perl/C++ (pick whichever one you know the most about). Pick a feature from VB/Perl/C++ unrelated to the original problem and start demanding that it be added to Python so that you can use it to make your program work. For the final touch, forget about the original "bug" and start to wax philosophic about how this is just another typical example of the problems with Python, open-source, mass transit, the designated hitter, auto-tune, people who like cats, and the dewey decimal system. Use lots of poetic-sounding but nonsensical metaphors. It'll take several days and a fair bit of work, but you will be able to produce a some grouchy responses in c.l.p. > but for the most part it's reasonably friendly to beginners. > The worst thing that usually happens is that if you ask a > simple question, a bunch of experts will show off their > knowledge to each other by giving you insanely complicated > answers that you have no reason to want to understand. That usually happens when the question is vague and incomplete enough so that people have to guess what is being asked. Some people tend to guess more "interesting" questions than others. One will also get rather arcane answers when a poorly thought out question is answered literally. IOW, somebody asks "how to I do B?" when B _really_ isn't something anybody is going to want to in Python, but if you twist the language around enough you can actually _do_ B (even if it's quite pointless). The real question was "how do I accomplish A", but the poster having incorrectly assumed the answer is B, didn't ask "how do I accomplish A?" They're really not trying to torture beginners, they just think it's interesting trying to figure out a way to do B. Even if you do get some obscure answers, others will always figure out that what you really wanted to know was "how do I accomplish A" and tell you the best way to accomplish A and why B isn't what you want to do. -- Grant From ben+python at benfinney.id.au Mon Nov 16 23:08:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 15:08:18 +1100 Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <877htpokst.fsf@benfinney.id.au> Grant Edwards writes: > 2) State that your program "doesn't work", but don't explain > either what you expect it to do or what it actually does. A different flavour of this is also good for setting the seeds of grouchiness: 2a) Write a Subject field that doesn't say anything about what you're asking, so the thread doesn't garner any attention from busy people. For bonus points, put something like ?newbie question? there instead of anything actually relevant to the problem. No, this thread is not an example; the Subject field is an entirely relevant concise description of the information being sought. -- \ ?bash awk grep perl sed, df du, du-du du-du, vi troff su fsck | `\ rm * halt LART LART LART!? ?The Swedish BOFH, | _o__) alt.sysadmin.recovery | Ben Finney From rantingrick at gmail.com Mon Nov 16 23:18:55 2009 From: rantingrick at gmail.com (rantingrick) Date: Mon, 16 Nov 2009 20:18:55 -0800 (PST) Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Nov 16, 5:30?pm, "Rhodri James" wrote: > We've been living with this pain ever since windowed GUIs encouraged users ? > to put spaces in their file names (Apple, I'm looking at you!). ? > Fundamentally, if people want the pretty they have to live with the ? > consequences. Thanks everyone , problem solved! From python.list at tim.thechases.com Mon Nov 16 23:40:53 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Nov 2009 22:40:53 -0600 Subject: Newsgroup for beginners In-Reply-To: References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <4B022955.7000204@tim.thechases.com> > 1) Start by complaining that your program doesn't work because > of a bug in Python. 1b) Omit the fact that this is a homework problem, and you want c.l.p to do your homework for you > 4) Once people start to get annoyed that you won't post any > example code showing the problem you're having, then you > post code. > > a) Post lots of code. The bigger the program the better; > try for at least 500 lines -- but make sure that you > leave out a few functions and "import" some libraries > nobody has ever heard of. > > b) Post code that doesn't match the code who's behaviour > you're describing (remember: be vague and be careful > not to actually show real input or output at this > point). > > c) For maximum effect try to make sure that what you post > won't compile by inserting typos and changing the > indentation in a few places. d) you post a link to your uploaded code on some code-sharing site that requires the latest versions of JavaScript, Flash, Silverlight, Java, and requires cookies to be enabled just to read your flippin' code. > c) rather than cutting/pasting input and output, make sure > you manually retype it into your posting -- > inaccurately. [sheepish grin] Guilty as charged on at least one occasion. > It'll take several days and a fair bit of work, but you will be > able to produce a some grouchy responses in c.l.p. oh, shut up! ;-) > One will also get rather arcane answers when a poorly thought > out question is answered literally. IOW, somebody asks "how to > I do B?" when B _really_ isn't something anybody is going to > want to in Python, but if you twist the language around enough > you can actually _do_ B (even if it's quite pointless). The > real question was "how do I accomplish A", but the poster > having incorrectly assumed the answer is B, didn't ask "how do > I accomplish A?" "But why can't I use regular expressions to do...?" :-) Even the best Pythoneers get grouchy ("This parrot wouldn't VOOM if you put 4 million volts through it!") -tkc From showell30 at yahoo.com Mon Nov 16 23:53:50 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 20:53:50 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> On Nov 16, 5:46?pm, Steven D'Aprano wrote: > On Mon, 16 Nov 2009 10:32:19 -0800, Steve Howell wrote: > > Actually, the __getitem__ workaround that I proposed earlier only works > > on subclasses of dict, not dict themselves. ?So given a pure dictionary > > object, it is impossible to hook into attribute lookups after > > instantiation in debugging/tracing code. > > If you have written your application to avoid unnecessary isinstance and > type checks, i.e. to use duck-typing, then a technique you might find > useful is delegation. > > class DebuggingDict(object): > ? ? def __init__(self, dict_to_wrap, hook=None): > ? ? ? ? self.__dict__['_d'] = dict_to_wrap > ? ? ? ? self.__dict__['getitem_hook'] = hook > ? ? def __getattr__(self, name): > ? ? ? ? return getattr(self._d, name) > ? ? def __setattr__(self, name, value): > ? ? ? ? setattr(self._d, name, value) > ? ? def __getitem__(self, key): > ? ? ? ? if self.getitem_hook is not None: > ? ? ? ? ? ? self.getitem_hook(self, key) > ? ? ? ? return self._d[key] > > And in use: > > >>> def hook(self, key): > > ... ? ? print "Looking for key", key > ...>>> d = DebuggingDict({1:'a', 2: 'b'}, hook) > >>> d[1] > > Looking for key 1 > 'a'>>> d[2] > > Looking for key 2 > 'b' > Yep, this basically resembles the approach that I originally took for the broader problem, which was that I wanted to see how a third party library (the Django templating system) was accessing dictionaries that referred to objects that my tracing code did not create. Although I did not instantiate the original objects, I did have the ability to substitute masquerade objects for the original objects before passing them along, and my code for the masquerading objects was similar in spirit to your DebuggingDict. It actually worked pretty well, except that eventually my masquerade objects went off to places where I was not fully able to maintain the illusion of being the original object. My original post on this thread sheds some light on what I'm doing, but basically I was trying to masquerade down the whole tree of calls from Django, which worked fine as long as Django was trying first to access my objects like dictionaries, which it always does first when rendering template variables, but all bets are off after that (custom filters, etc.). Eventually, I realized that it was easier to just monkeypatch Django while I was in test mode to get a more direct hook into the behavior I was trying to monitor, and then I didn't need to bother with overriding __getitem__ or creating complicated wrapper objects. I wrote about it here if anybody is morbidly interested: http://showellonprogramming.blogspot.com/ From showell30 at yahoo.com Tue Nov 17 00:17:48 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 16 Nov 2009 21:17:48 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <7me7osF3hikpfU1@mid.individual.net> Message-ID: <4c84db77-31a7-48ce-b315-b9a1ab53463b@m33g2000pri.googlegroups.com> On Nov 16, 4:06?pm, greg wrote: > Christian Heimes wrote: > > Most magic methods are implemented as descriptors. Descriptors only > > looked up on the type to increase the performance of the interpreter and > > to simply the C API. > > There's also a semantic problem. Since new-style > classes are also instances (of class 'type') and you > can create subclasses of 'type', if special methods > were looked up on instances, it would be ambiguous > whether an attribute '__getitem__' on a class was > meant to specify the behaviour of the [] operation > on its instances, or on the class itself. > > This problem didn't arise with old-style classes, > because classes and instances were clearly separated > (i.e. old-style classes were not old-style instances). That explanation makes some sense to me. Given the ambiguity and the backward compatibility issues, I would argue that both of the commented lines in the program below should fail hard with a useful warning. Only one of them actually does. The other just silently no- ops. class A(dict): pass a = A() a['ignore'] = 'x' a.__getitem__ = lambda key: 'foo' # exercise in futility b = dict() b['ignore'] = 'x' b.__getitem__ = lambda key: 'foo' # hard failure Tested under 2.6. It seems like if __getitem__ is truly a special method, it should get special treatment whenever you try to use it, even if that special treatment is just an explicit error message that its use makes no sense in a particular context. If you allow __getitem__ to exist on a, then you create situations where __getitem__ is basically an instance method on an instance of a subtype of dict, which sounds awfully ambiguous to me, given that the whole intent of __getitem__ is to define the behavior of [] on classes. From gagsl-py2 at yahoo.com.ar Tue Nov 17 00:51:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 Nov 2009 02:51:07 -0300 Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> Message-ID: En Mon, 16 Nov 2009 18:04:21 -0300, Ecir Hana escribi?: > On Nov 16, 7:21 pm, "Gabriel Genellina" > wrote: >> En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana >> escribi?: >> >> >> I'm trying to write a simple Win32 app, which may run some Python >> >> scripts. Since it is a Windows GUI app, I would like to redirect all >> >> output (Python print, C printf, fprinf stderr, ...) to a text area >> >> inside the app. In other words, I'm trying to log all the output from >> >> the app (C, Python) to a window. So far, this works for C printf(): >> >> [...] > > thanks for the reply! Sorry, my earlier code was not working as I expected; I wrongly assumed the output was being redirected but that was not the case. The version below ("set paranoid mode on") does redirect printf(), fwrite(stdout,...), write(1,...), WriteFile(consolehandle,...), all those calls in C, but fails in Python with IOError: [Errno 9] Bad file descriptor. I'm unable to figure out *where* it fails just by reading the Python source; one should set a breakpoint in python26.dll to see what actually happens. > However, please, could you tell me how many bytes it read here: > > ReadFile(hReadPipe, buffer, 19, &nr, NULL); The code below now reads from the pipe everything that has been written -- except from Python :( #include #include #include #include "Python.h" int error(char* lpszText) { LPVOID lpMsgBuf; DWORD lasterror = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lasterror, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); fprintf(stderr, "%s: error %d: %s", lpszText, lasterror, lpMsgBuf); LocalFree(lpMsgBuf); return 1; } int main() { HANDLE hReadPipe, hWritePipe; DWORD nr, nw; char buffer[100]; int fd, i; BOOL bResult; if (!CreatePipe( &hReadPipe, &hWritePipe, NULL, 0)) return error("cannot create pipe"); if (!SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe)) return error("SetStdHandle"); // this was missing in previous version fd = _open_osfhandle((intptr_t)hWritePipe, _O_TEXT); if (fd==-1) return error("_open_osfhandle"); if (_dup2(fd, 1)!=0) return error("dup2"); if (!WriteFile(hWritePipe, "WriteFile(pipe)\n", 16, &nr, NULL)) return error("WriteFile(pipe)"); if (!WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "WriteFile(stdout)\n", 18, &nr, NULL)) return error("WriteFile(stdout)"); fputs("fputs from C\n", stdout); if (fwrite("fwrite from C\n", 1, 14, stdout)!=14) return error("fwrite!=14"); if (write(1, "write from C\n", 13)<0) return error("write"); fflush(stdout); fprintf(stderr, "before Python\n"); Py_Initialize(); PyRun_SimpleString("import sys;sys.stdout.write('from Python\\n')\n"); Py_Finalize(); fprintf(stderr, "before flush 2\n"); fflush(stdout); fprintf(stderr, "before close pipe w\n"); if (!CloseHandle(hWritePipe)) return error("CloseHandle(hWritePipe)"); fprintf(stderr, "before close STDOUT Handle\n"); if (!CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE))) return error("CloseHandle(STDOUT)"); fprintf(stderr, "before read pipe\n"); // read one char at a time... for (i = 0; i -- Gabriel Genellina From animator333 at gmail.com Tue Nov 17 01:04:14 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 22:04:14 -0800 (PST) Subject: Get attribute this way Message-ID: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Python's getattr, setattr and __getattribute__ commands works fine with python types. For example: print o.__getattribute__("name") print getattr(o, "name") This is the easiest way to get an attribute using a string. In my case the "Node" class load/creates all the attributes from a xml file. Example There are certain atrributes of compound type. Example: # Array of colors, Here we are referring first color and second element (green) self.gradient.colors[0][1] = 0.5 # Array of floats, referring first element self.gradient.positions[0] = 1.0 Color, color array and floats are all custom classes. Now question is how to get these compound attributes using string as we do with default singular attributes. Example: getattr(o, "gradient.colors[0][1] ") I need this to save the data of nodes->attributes into a custom xml format, when loading this data back, I create the node first and then setup values from the saved xml file. Prashant Python 2.6.2 Win XP 32 From pavlovevidence at gmail.com Tue Nov 17 01:11:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 16 Nov 2009 22:11:50 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> Message-ID: <58066d51-e47f-4d3f-934c-8255916e0684@j9g2000prh.googlegroups.com> On Nov 16, 10:32?am, Steve Howell wrote: > On Nov 16, 2:35?am, Carl Banks wrote: > > > > > On Nov 15, 2:52?pm, Steve Howell wrote: > > > > Does anybody have any links that points to the rationale for ignoring > > > instance definitions of __getitem__ when new-style classes are > > > involved? ?I assume it has something to do with performance or > > > protecting us from our own mistakes? > > > "Not important enough to justify complexity of implementation." > > > I doubt they would have left if out of new-style classes if it had > > been straightforward to implement (if for no other reason than to > > retain backwards compatibility), but it wasn't. ?The way attribute > > lookups work meant it would have required all kinds of double lookups > > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > > easily worked around by simply having __getitem__ call another method, > > as you've seen. ?Given all this it made better sense to just leave it > > out of new-style classes. > > Actually, the __getitem__ workaround that I proposed earlier only > works on subclasses of dict, not dict themselves. ?So given a pure > dictionary object, it is impossible to hook into attribute lookups > after instantiation in debugging/tracing code. ?I know it's not a > super common thing to do, but it is a legitimate use case from my > perspective. ?But I understand the tradeoffs. ?They seem kind of 20th > century to me, but with Moore's Law declining and all, maybe it's a > bad time to bring up the "flexibility trumps performance" > argument. ;) It's not performance, it's code complexity. Implementing this would have to added a lot of extra code to the Python codebase--more than you seem to realize--all in support of a dubious behavior. This would have meant more opporunities for bugs, and an increased maintainence burden. >?The backward compatibility argument also seems a little > dubious, because if anybody *had* put __getitem__ on a dictionary > instance before, it would have already been broken code, and if they > hadn't done it, there would be no semantic change, just a performance > hit, albeit a pervasive one. Wrong. It's only dubious from your narrow mindset that focuses on your own problem and ignores the greater problem. When new-style classes were introduced, they made a decision that magic methods would no longer work when defined on any instance. It affected a *lot* more than just your dictionary use-case. So please spare me any suggestions that the change didn't carry a significant backwards incompatibility. It did, and they made the change anyway. That should tell you how difficult it would have been to implement. Carl Banks From kev0960 at gmail.com Tue Nov 17 01:18:10 2009 From: kev0960 at gmail.com (Psi) Date: Mon, 16 Nov 2009 22:18:10 -0800 (PST) Subject: Please recommend the books that might be helpful to learn Python :) Message-ID: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> as the subject says, any books? From ben+python at benfinney.id.au Tue Nov 17 01:21:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 17:21:44 +1100 Subject: Please recommend the books that might be helpful to learn Python :) References: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> Message-ID: <87y6m5n01z.fsf@benfinney.id.au> Psi writes: > as the subject says, > > any books? Any web search would lead you to , no? -- \ ?There's no excuse to be bored. Sad, yes. Angry, yes. | `\ Depressed, yes. Crazy, yes. But there's no excuse for boredom, | _o__) ever.? ?Viggo Mortensen | Ben Finney From threaderslash at gmail.com Tue Nov 17 01:24:26 2009 From: threaderslash at gmail.com (Threader Slash) Date: Tue, 17 Nov 2009 17:24:26 +1100 Subject: Qt Python : QTreeWidget Child Problem Message-ID: Hello Everybody, I have a QTreewidget that works fine if I have just one level on my treelist. If I decide to add child sublevels, it gives me an error. Here is the code, that works nice only without the "childs" lines on it (see after "child 1" and "child 2"). def eqpt_centralwdg(self,MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) self.colorTreeWidget.setObjectName("colorTreeWidget") # father root 1 item = QtGui.QTreeWidgetItem(self.colorTreeWidget) #child 1 - from father 1 item = QtGui.QTreeWidgetItem(item) #child 2 - from father 1 item = QtGui.QTreeWidgetItem(item) # father root 2 item = QtGui.QTreeWidgetItem(self.colorTreeWidget) self.connect(self.colorTreeWidget, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.eqpt_activateInput) MainWindow.setCentralWidget(self.centralwidget) def eqpt_retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "color", None, QtGui.QApplication.UnicodeUTF8) __sortingEnabled = self.colorTreeWidget.isSortingEnabled() self.colorTreeWidget.setSortingEnabled(False) # father root 1 self.colorTreeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow", None, QtGui.QApplication.UnicodeUTF8) #child 1 - from father 1 self.colorTreeWidget.topLevelItem(0).child(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Sun", None, QtGui.QApplication.UnicodeUTF8)) #child 2 - from father 1 self.colorTreeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Gold", None, QtGui.QApplication.UnicodeUTF8)) # father root 2 self.colorTreeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Blue", None, QtGui.QApplication.UnicodeUTF8) self.colorTreeWidget.setSortingEnabled(__sortingEnabled) Here is the output, when it works def eqpt_activateInput(self,item,col): print "Qtree ok! pressed" print item.text(col) if I exclude the lines related to the "child 1" and "child 2" from the code, it runs. Otherwise, it gives me the error: AttributeError: 'NoneType' object has no attribute 'setText' I used the Qt Designer to generate the code, and added some lines to trigger events. Any hints or suggestions are highly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Nov 17 01:31:25 2009 From: nagle at animats.com (John Nagle) Date: Mon, 16 Nov 2009 22:31:25 -0800 Subject: mySQL access speed In-Reply-To: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> References: <4b01c8f0$0$7622$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b0240c5$0$1581$742ec2ed@news.sonic.net> Hans M?ller wrote: > Hello, > > I have some programs doing a lot sql IO in some mySQL databases. > This works very fine and the DBAPI is quite simple to understand. > > Now I came to the point where I had to insert millions of lines into a table. If you're loading into an empty table, use the LOAD command. That's far faster than doing vast numbers of INSERT operations. The LOAD command loads all the data, unindexed, then builds the indices. Expect a 10x speed improvement or better. John Nagle From clp2 at rebertia.com Tue Nov 17 01:35:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 22:35:43 -0800 Subject: Get attribute this way In-Reply-To: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <50697b2c0911162235i7e01623bn4be8535f93f3fc8b@mail.gmail.com> On Mon, Nov 16, 2009 at 10:04 PM, King wrote: > Python's getattr, setattr and __getattribute__ commands works fine > with python types. > For example: > print o.__getattribute__("name") > print getattr(o, "name") > This is the easiest way to get an attribute using a string. > > In my case the "Node" class load/creates all the attributes from a xml > file. > Example > > > > There are certain atrributes of compound type. > Example: > # Array of colors, Here we are referring first color and second element > (green) > self.gradient.colors[0][1] = 0.5 > # Array of floats, referring first element > self.gradient.positions[0] = 1.0 > > Color, color array and floats are all custom classes. > > Now question is how to get these compound attributes using string as > we do with default singular attributes. > Example: > getattr(o, "gradient.colors[0][1] ") > I need this to save the data of nodes->attributes into a custom xml > format, when loading this data back, I create the node first and then > setup values from the saved xml file. Can't you just iterate over the data structure? I'm not seeing why you'd need to use getattr() and friends in the first place. for color in self.gradient.colors: for element in color: #output XML fragment #repeat for self.gradient.positions, etc. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Nov 17 01:53:59 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 22:53:59 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: Writing/Reading data to xml is not a problem. The problem is when I have to write to attributes in xml, where a connections has been established. XML: While reading back I have to convert both source and destination strings into object so that I can call connections function using source and target attributes. Prashant Python 2.6.2 Win XP 32 From clp2 at rebertia.com Tue Nov 17 02:21:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Nov 2009 23:21:46 -0800 Subject: Get attribute this way In-Reply-To: References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <50697b2c0911162321k5bc80008gff8101340afdd9d3@mail.gmail.com> On Mon, Nov 16, 2009 at 10:53 PM, King wrote: > Writing/Reading data to xml is not a problem. The problem is when I > have to write to attributes in xml, where a connections has been > established. > XML: > destattribute="node2.gradient.colors[1][2]"/> You did not include an example like this in your original post. I'd say you're stuck using eval() unless you want to change your format or write a parser for the subset of Python involved. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Nov 17 02:37:02 2009 From: animator333 at gmail.com (King) Date: Mon, 16 Nov 2009 23:37:02 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: "eval" can solve this problem right away but I am concerned about security issues. If not "eval" could you suggest something more efficient way. It won't be a big deal to change the format as application is still at development stage? Thanks Prashant Python 2.6.2 Win XP 32 From eden at bicikl. Tue Nov 17 02:44:24 2009 From: eden at bicikl. (Eden Kirin) Date: Tue, 17 Nov 2009 08:44:24 +0100 Subject: SCGIServer and unusal termination In-Reply-To: References: Message-ID: Anyone? -- www.vikendi.net -/- www.supergrupa.com From hyunchul.mailing at gmail.com Tue Nov 17 03:07:42 2009 From: hyunchul.mailing at gmail.com (Hyunchul Kim) Date: Tue, 17 Nov 2009 17:07:42 +0900 Subject: faster than list.extend() In-Reply-To: <4B01D87B.30102@tim.thechases.com> References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> <4B01D87B.30102@tim.thechases.com> Message-ID: <573a3abd0911170007s62537a45y3233cf21018c5d2d@mail.gmail.com> Thank Tim, Raymond, and all. In my test, Tim's t1 was fastest and Raymond's triple3 is very near to Tim's t1. Anyway both of them took only 6~7% time of my original .extend() version. I think that following n_ple() is a good generalized function that was 1~3% slower than t1() and triple3() for "triple". ********* from itertools import * def n_ple(inputlist, n): chain_from_iterable = chain.from_iterable; izip = izip return chain_from_iterable(izip(*[inputlist]*n)) ********* def t2(i): r = range(3) return (x for x in i for _ in r) def t2_1(i): r = range(3) return [x for x in i for _ in r] I didn't know that list(t2(inputlist)) is much faster than t2_1(inputlist), it's gonna be a helpful tip for me. Thank you all. Hyunchul On Tue, Nov 17, 2009 at 7:55 AM, Tim Chase wrote: > Hyunchul Kim wrote: > >> Hi, all. >> >> I want to improve speed of following simple function. >> Any suggestion? >> >> ********** >> def triple(inputlist): >> results = [] >> for x in inputlist: >> results.extend([x,x,x]) >> return results >> ********** >> > > Several ways occur to me: > > def t1(i): > for x in i: > yield x > yield x > yield x > > def t2(i): > r = range(3) > return (x for x in i for _ in r) > > > I prefer to return generators in case the input is large, but in both > cases, you can just wrap it in list() like > > list(t1(inputlist)) > > or in t2(), you can just change it to use > > return [x for x in i for _ in r] > > -tkc > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From donn.ingle at gmail.com Tue Nov 17 03:10:01 2009 From: donn.ingle at gmail.com (Donn) Date: Tue, 17 Nov 2009 10:10:01 +0200 Subject: Python & Go In-Reply-To: <7xocn4rh2r.fsf@ruckus.brouhaha.com> References: <7xocn4rh2r.fsf@ruckus.brouhaha.com> Message-ID: <200911171010.01537.donn.ingle@gmail.com> On Saturday 14 November 2009 22:23:40 Paul Rubin wrote: > they'll have to call it Go2 Lol. Or we could fork it and call it Gosub ... and never return! \d From deets at nospam.web.de Tue Nov 17 03:20:44 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 09:20:44 +0100 Subject: Get attribute this way In-Reply-To: References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <7mf4muF3eokmqU1@mid.uni-berlin.de> King schrieb: > "eval" can solve this problem right away but I am concerned about > security issues. If not "eval" could you suggest something more > efficient way. It won't be a big deal to change the format as > application is still at development stage? If you don't want to use eval (which is a good thing not to want), you'd end up (as Chris already told you) writing your own parser for python subexpressions. Which is laborous. Or you create a XML-representation of these expressions, which saves you the parser, but not the evaluator, and bloats the XML. It could look like this: <... # close them all Is this *really* all worth doing, or can't you just overcome your preconceptions - and use pickle, as it has been suggested to you before? Potentially with __getstate__/__setstate__ overridden for specific objects. Diez From pavlovevidence at gmail.com Tue Nov 17 03:29:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 17 Nov 2009 00:29:38 -0800 (PST) Subject: Get attribute this way References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <6592fecb-0a94-4372-bdf0-d2b38979e896@13g2000prl.googlegroups.com> On Nov 16, 11:37?pm, King wrote: > "eval" can solve this problem right away but I am concerned about > security issues. If not "eval" could you suggest something more > efficient way. It won't be a big deal to change the format as > application is still at development stage? You are stuck parsing it yourself, then. Apart from eval, there's not a really handy way to do what you want. Here's something that might help you get started; it is not by any means a final solution. First of all, for simplicity's sake, change the subscript notation to attribute notation; that is, change "gradient.positions[0]" to "gradient.positions.0". Then you can find the object you're seeking like this (untested): obj = self while '.' in attr: next,attr = attr.split('.',1) try: index = int(next) except TypeError: obj = getattr(obj,next) else: obj = obj[index] Notice what's happening: we're splitting the string at the dot and using getattr to descend further into the structure. Also, if the part of the string before the dot is an integer, we index instead. Hopefully this example will help you understand what doing this entails and what you have to do to get it work. Carl Banks From deets at nospam.web.de Tue Nov 17 03:33:41 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 09:33:41 +0100 Subject: ZipFile - file adding API incomplete? In-Reply-To: References: Message-ID: <7mf5f6F3i297hU1@mid.uni-berlin.de> Glenn Maynard schrieb: > I want to do something fairly simple: read files from one ZIP and add > them to another, so I can remove and replace files. This led me to a > couple things that seem to be missing from the API. > > The simple approach would be to open each file in the source ZIP, and > hand it off to newzip.write(). There's a missing piece, though: > there's no API that lets me pass in a file-like object and a ZipInfo, > to preserve metadata. zip.write() only takes the filename and > compression method, not a ZipInfo; writestr takes a ZipInfo but only > accepts a string, not a file. Is there an API call I'm missing? > (This seems like the fundamental API for adding files, that write and > writestr should be calling.) > > The correct approach is to copy the data directly, so it's not > recompressed. This would need two new API calls: rawopen(), acting > like open() but returning a direct file slice and not decompressing > data; and rawwrite(zinfo, file), to pass in pre-compressed data, where > the compression method in zinfo matches the compression type used. > > I was surprised that I couldn't find the former. The latter is an > advanced one, important for implementing any tool that modifies large > ZIPs. Short-term, at least, I'll probably implement these externally. No idea why the write doesn't accept an open file - OTOH, as passing a string is just writestr(info, in_file.read()) I don't think that's *that* much of an inconvenience.. And regarding your second idea: can that really work? Intuitively, I would have thought that compression is adaptive, and based on prior additions to the file. I might be wrong with this though. Diez From clp2 at rebertia.com Tue Nov 17 04:08:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 01:08:55 -0800 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <50697b2c0911170108x14ac984w9ffe8c1850d4086b@mail.gmail.com> On Mon, Nov 16, 2009 at 2:14 AM, Virgil Stokes wrote: > If one goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > and if you now click on the tab labeled "history and compare" this will take > you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > Finally...This is where I would like to "connect to" the data on a daily > basis or to gather data over different time intervals. I believe that if I > can get some help on this, then I will be able to customize the code as > needed for my own purposes. HTML parsing: http://www.crummy.com/software/BeautifulSoup/ Downloading webpages: http://docs.python.org/library/urllib.html#urllib.urlopen BeautifulSoup is excellently documented: http://www.crummy.com/software/BeautifulSoup/documentation.html You'll probably be interested in the sections on searching and navigating the parse tree. Cheers, Chris -- IANAL and do not condone violating website TOSes http://blog.rebertia.com From clp2 at rebertia.com Tue Nov 17 04:10:11 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 01:10:11 -0800 Subject: TODO and FIXME tags In-Reply-To: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Message-ID: <50697b2c0911170110l7420e2caq9fdb043b3acb3db3@mail.gmail.com> 2009/11/16 Yasser Almeida Hern?ndez : > Hi all.. > Sorry if this question sound elemental. > How is the sintaxis for set the TODO and FIXME tags...? There is no special syntax for those. Some people use them in comments, but it's just a convention. Cheers, Chris -- http://blog.rebertia.com From Juergen.Hermann at 1und1.de Tue Nov 17 04:26:00 2009 From: Juergen.Hermann at 1und1.de (jhermann) Date: Tue, 17 Nov 2009 01:26:00 -0800 (PST) Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> <0083130b$0$26937$c3e8da3@news.astraweb.com> Message-ID: <2dbed67b-e622-4a20-8254-29ddd2687316@a32g2000yqm.googlegroups.com> On 10 Nov., 17:03, NickC wrote: > Many thanks for the replies. ?getattr() works great: You can get a little more versatile and even specify the location of the name (i.e. the module / package name) without pre-importing it, like this... def importName(modulename, name=None): """ Import identifier C{name} from module C{modulename}. If name is omitted, modulename must contain the name after the module path, delimited by a colon. @param modulename: Fully qualified module name, e.g. C{x.y.z}. @param name: Name to import from C{modulename}. @return: Requested object. @rtype: object """ if name is None: modulename, name = modulename.split(':', 1) module = __import__(modulename, globals(), {}, [name]) return getattr(module, name) print importName("socket:gethostname")() This is especially useful if you want to specify factory classes or the like in a non-python config file. The syntax is the same as that of setuptools entry points. From ben+python at benfinney.id.au Tue Nov 17 04:47:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Nov 2009 20:47:00 +1100 Subject: TODO and FIXME tags References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> Message-ID: <87lji5mqjv.fsf@benfinney.id.au> Chris Rebert writes: > 2009/11/16 Yasser Almeida Hern?ndez : > > How is the sintaxis for set the TODO and FIXME tags...? > > There is no special syntax for those. Some people use them in > comments, but it's just a convention. This is true. However, the convention is fairly well established, and many text editor default configurations will highlight the strings ?TODO?, ?FIXME?, and others wherever they appear in comments. There's no widely-followed ?syntax? for this convention, though. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Tue Nov 17 04:49:50 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 17 Nov 2009 10:49:50 +0100 Subject: Get attribute this way In-Reply-To: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> References: <1caab272-dae1-4c24-8e18-ac38e31348d8@o9g2000vbj.googlegroups.com> Message-ID: <4b0271b8$0$17015$426a74cc@news.free.fr> King a ?crit : > Python's getattr, setattr and __getattribute__ commands s/commands/functions/ > works fine > with python types. > For example: > print o.__getattribute__("name") A very few corner cases set aside - the main one being inside a custom __getattribute__ method -, you should not directly access __getattribute__ (nor most __magic_methods__ FWIW). > print getattr(o, "name") > This is the easiest way to get an attribute using a string. > > In my case the "Node" class load/creates all the attributes from a xml > file. > Example > > > > There are certain atrributes of compound type. There's no "compound type" in Python. There are only objects, objects and objects. > Example: > # Array of colors, Here we are referring first color and second element > (green) > self.gradient.colors[0][1] = 0.5 > # Array of floats, referring first element > self.gradient.positions[0] = 1.0 > > Color, color array and floats are all custom classes. > > Now question is how to get these compound attributes using string as > we do with default singular attributes. > Example: > getattr(o, "gradient.colors[0][1] ") You can't (at least OOTB). the expression: gradient.colors[0][1] is a shortcut for: colors = gradients.__getattribute__("color") colors_0 = colors.__getitem__(0) colors_0_1 = colors_0.__getitem__(1) You can of course do something like g = getattr(o, "gradient") c = getattr(g, "colors") # etc... but I guess this is not what you're after. > I need this to save the data of nodes->attributes into a custom xml > format, when loading this data back, I create the node first and then > setup values from the saved xml file. I really don't think you need anything like this to serialize / unserialize your objects (whatever the format FWIW). You should really google for +python +serialize +XML, I bet you'd find at least a couple helpful articles on that topic. From showell30 at yahoo.com Tue Nov 17 05:02:25 2009 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 17 Nov 2009 02:02:25 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <58066d51-e47f-4d3f-934c-8255916e0684@j9g2000prh.googlegroups.com> Message-ID: On Nov 16, 10:11?pm, Carl Banks wrote: > On Nov 16, 10:32?am, Steve Howell wrote: > > > > > On Nov 16, 2:35?am, Carl Banks wrote: > > > > On Nov 15, 2:52?pm, Steve Howell wrote: > > > > > Does anybody have any links that points to the rationale for ignoring > > > > instance definitions of __getitem__ when new-style classes are > > > > involved? ?I assume it has something to do with performance or > > > > protecting us from our own mistakes? > > > > "Not important enough to justify complexity of implementation." > > > > I doubt they would have left if out of new-style classes if it had > > > been straightforward to implement (if for no other reason than to > > > retain backwards compatibility), but it wasn't. ?The way attribute > > > lookups work meant it would have required all kinds of double lookups > > > and edge cases. ?Some regarded it as dubious to begin with. ?And it's > > > easily worked around by simply having __getitem__ call another method, > > > as you've seen. ?Given all this it made better sense to just leave it > > > out of new-style classes. > > > Actually, the __getitem__ workaround that I proposed earlier only > > works on subclasses of dict, not dict themselves. ?So given a pure > > dictionary object, it is impossible to hook into attribute lookups > > after instantiation in debugging/tracing code. ?I know it's not a > > super common thing to do, but it is a legitimate use case from my > > perspective. ?But I understand the tradeoffs. ?They seem kind of 20th > > century to me, but with Moore's Law declining and all, maybe it's a > > bad time to bring up the "flexibility trumps performance" > > argument. ;) > > It's not performance, it's code complexity. > > Implementing this would have to added a lot of extra code to the > Python codebase--more than you seem to realize--all in support of a > dubious behavior. ?This would have meant more opporunities for bugs, > and an increased maintainence burden. > > >?The backward compatibility argument also seems a little > > dubious, because if anybody *had* put __getitem__ on a dictionary > > instance before, it would have already been broken code, and if they > > hadn't done it, there would be no semantic change, just a performance > > hit, albeit a pervasive one. > > Wrong. ?It's only dubious from your narrow mindset that focuses on > your own problem and ignores the greater problem. ?When new-style > classes were introduced, they made a decision that magic methods would > no longer work when defined on any instance. ?It affected a *lot* more > than just your dictionary use-case. > > So please spare me any suggestions that the change didn't carry a > significant backwards incompatibility. ?It did, and they made the > change anyway. ?That should tell you how difficult it would have been > to implement. > I am sorry having for a narrow mindset, and I apologize for not seeming to realize how much extra code would go into the Python codebase to allow me to hook into attribute lookups after instantiation in debugging/tracing code. From dickinsm at gmail.com Tue Nov 17 05:15:40 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 17 Nov 2009 02:15:40 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <383a179a-1e5d-4b47-a5db-87dae03cfb1e@d10g2000yqh.googlegroups.com> On Nov 16, 4:54?pm, Steve Ferg wrote: > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. GAP uses almost exactly this syntax, but with 'fi' instead of 'endif': http://www.gap-system.org/Manuals/doc/htm/ref/CHAP004.htm#SECT016 Mark From __peter__ at web.de Tue Nov 17 05:24:18 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2009 11:24:18 +0100 Subject: faster than list.extend() References: <18839f340911161430h55d35d20i25304162c9ba97ce@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > En Mon, 16 Nov 2009 19:30:27 -0300, Hyunchul Kim > escribi?: > >> I want to improve speed of following simple function. >> Any suggestion? >> >> ********** >> def triple(inputlist): >> results = [] >> for x in inputlist: >> results.extend([x,x,x]) >> return results >> ********** > > These are my best attempts: > > def triple3(inputlist): > results = [] > append = results.append > for x in inputlist: > append(x); append(x); append(x) > return results > > def triple4(inputlist, _three=xrange(3)): > return [x for x in inputlist for _ in _three] > > For a 400-items list, triple3 is 40% faster and triple4 25% faster than > yours. [I didn't see the original post] If inputlist is actually a list or tuple the following should beat them all: def triple_repeat(items): result = [None] * (3*len(items)) result[::3] = result[1::3] = result[2::3] = items return result For small n the generalization should still be quite competitive: def n_repeat(items, n): items = tuple(items) result = [None]*(len(items) * n) for offset in range(n): result[offset::n] = items return result Some measurements: $ cat extend.py from itertools import * def triple_repeat(items): result = [None] * (3*len(items)) result[::3] = result[1::3] = result[2::3] = items return result def n_repeat(items, n): items = tuple(items) result = [None]*(len(items) * n) for offset in range(n): result[offset::n] = items return result def t1(i): for x in i: yield x yield x yield x def triple3(inputlist, list=list, chain_from_iterable=chain.from_iterable, izip=izip): return list(chain_from_iterable(izip(inputlist, inputlist, inputlist))) data = range(1000) $ python -m timeit -s 'from extend import triple_repeat, data' 'triple_repeat(data)' 10000 loops, best of 3: 52.4 usec per loop $ python -m timeit -s 'from extend import n_repeat, data' 'n_repeat(data, 3)' 10000 loops, best of 3: 60.7 usec per loop $ python -m timeit -s 'from extend import t1, data' 'list(t1(data))' 1000 loops, best of 3: 337 usec per loop $ python -m timeit -s 'from extend import triple3, data' 'triple3(data)' 1000 loops, best of 3: 231 usec per loop Peter From martin.hellwig at dcuktec.org Tue Nov 17 06:27:03 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 17 Nov 2009 11:27:03 +0000 Subject: TODO and FIXME tags In-Reply-To: <87lji5mqjv.fsf@benfinney.id.au> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Chris Rebert writes: > >> 2009/11/16 Yasser Almeida Hern?ndez : >>> How is the sintaxis for set the TODO and FIXME tags...? >> There is no special syntax for those. Some people use them in >> comments, but it's just a convention. > > This is true. However, the convention is fairly well established, and > many text editor default configurations will highlight the strings > ?TODO?, ?FIXME?, and others wherever they appear in comments. > > There's no widely-followed ?syntax? for this convention, though. > Except for _not_ doing what is suggested in those comments, which appears to be the biggest convention :-) -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From chris at simplistix.co.uk Tue Nov 17 06:36:33 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 Nov 2009 11:36:33 +0000 Subject: Calling Python functions from Excel In-Reply-To: References: Message-ID: <4B028AC1.8020307@simplistix.co.uk> Cannonbiker wrote: > Hi, > unfortunately is my question about server COM (win32com) > http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# > without answer. > > Please I need Calling Python functions from Excel and receive result > back in Excel. Can me somebody advise simplest solution please? I am > more VBA programmer than Python. Try http://code.google.com/p/pyinex/ cheers, Chris From mr.spoon21 at gmail.com Tue Nov 17 07:00:45 2009 From: mr.spoon21 at gmail.com (Mr.SpOOn) Date: Tue, 17 Nov 2009 13:00:45 +0100 Subject: Logic operators with "in" statement In-Reply-To: <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> References: <8f67b6f80911160602m1ccc78d7wa9de81bce9eae851@mail.gmail.com> <2d56febf0911160623k1dd23e11wc3902c475cd75410@mail.gmail.com> <50697b2c0911160646i371c7449l60d4000e70e44901@mail.gmail.com> <2d56febf0911161632m74b11c1eo198aac6a688818c5@mail.gmail.com> Message-ID: <8f67b6f80911170400g122fd52cwe02a090511c06813@mail.gmail.com> Thanks everybody for all the answers and explanations. In the end maybe it is simpler if I use sets for these tests. Thanks again. From stefan_ml at behnel.de Tue Nov 17 08:00:35 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 17 Nov 2009 14:00:35 +0100 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Robert P. J. Day, 15.11.2009 15:44: > On Sun, 15 Nov 2009, mrholtsr wrote: > >> I am absolutely new to python and barely past beginner in programming. >> Also I am not a mathematician. Can some one give me pointers for >> finding the 1000th. prime for a course I am taking over the internet >> on Introduction to Computer Science and Programming. Thanks, Ray > > it's 7919. Now, all that's left to do is write a prime number generator (a random number generator will do, too, but writing a good one isn't easy), run it repeatedly in a loop, and check if the returned number is 7919. Once it compares equal, you can print the result and you're done. Stefan From aaron.watters at gmail.com Tue Nov 17 08:48:10 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 17 Nov 2009 05:48:10 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> Message-ID: <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> > I don't think Python and Go address the same set of programmer > desires. ?For example, Go has a static type system. ?Some programmers > find static type systems to be useless or undesirable. ?Others find > them extremely helpful and want to use them them. ?If you're a > programmer who wants a static type system, you'll probably prefer Go > to Python, and vice versa. ?That has nothing to do with implementation > speed or development expenditures. ?If Google spent a million dollars > adding static types to Python, it wouldn't be Python any more. ... and I still have an issue with the whole "Python is slow" meme. The reason NASA doesn't build a faster Python is because Python *when augmented with FORTRAN libraries that have been tested and optimized for decades and are worth billions of dollars and don't need to be rewritten* is very fast. The reason they don't replace the Python drivers with Java is because that would be very difficult and just stupid and I'd be willing to bet that when they were done the result would actually be *slower* especially when you consider things like process start-up time. And when someone implements a Mercurial replacement in GO (or C# or Java) which is faster and more useful than Mercurial, I'll be very impressed. Let me know when it happens (but I'm not holding my breath). By the way if it hasn't happened and if he isn't afraid of public speaking someone should invite Matt Mackall to give a Python conference keynote. Or how about Bram Cohen for that matter... -- Aaron Watters http://listtree.appspot.com/ === if you want a friend, get a dog. -Truman From not_here at nowhere.com Tue Nov 17 09:19:39 2009 From: not_here at nowhere.com (me) Date: Tue, 17 Nov 2009 06:19:39 -0800 Subject: python gui builders In-Reply-To: References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <9f74668e-b0be-4e0e-8042-6e2c30879b68@b15g2000yqd.googlegroups.com> Message-ID: Read the OP. No, read it again. sturlamolden wrote: > On 16 Nov, 11:39, sturlamolden wrote: > >> If you are fine with Microsoft only, you can use Windows Forms with MS >> Visual Studio and IronPython. > > I also forgot to mention: > > If you can restrict yourself to Windows, you can always use Visual > Basic or Borland Delphi with pywin32. Either expose your GUI as an > ActiveX to pywin32 (you have e.g. an MFC binding) or expose your > Python as an ActiveX to VB/Delphi. The same approach should work (with > a little bit more work) for C# and VB.NET. From slafs.e at gmail.com Tue Nov 17 09:19:54 2009 From: slafs.e at gmail.com (Slafs) Date: Tue, 17 Nov 2009 06:19:54 -0800 (PST) Subject: XML root node attributes Message-ID: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Hi I'm little confused about adding attributes to the root node when creating an XML document. Can I do this using minidom or something else. I can't find anything that would fit my needs. i would like to have something like this: .... Please help. Regards. From davea at ieee.org Tue Nov 17 09:28:01 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 09:28:01 -0500 Subject: ZipFile - file adding API incomplete? In-Reply-To: <7mf5f6F3i297hU1@mid.uni-berlin.de> References: <7mf5f6F3i297hU1@mid.uni-berlin.de> Message-ID: <4B02B2F1.4030407@ieee.org> Diez B. Roggisch wrote: >
    Glenn > Maynard schrieb: >> I want to do something fairly simple: read files from one ZIP and add >> them to another, so I can remove and replace files. This led me to a >> couple things that seem to be missing from the API. >> >> >> >> The correct approach is to copy the data directly, so it's not >> recompressed. This would need two new API calls: rawopen(), acting >> like open() but returning a direct file slice and not decompressing >> data; and rawwrite(zinfo, file), to pass in pre-compressed data, where >> the compression method in zinfo matches the compression type used. >> >> I was surprised that I couldn't find the former. The latter is an >> advanced one, important for implementing any tool that modifies large >> ZIPs. Short-term, at least, I'll probably implement these externally. > > > > And regarding your second idea: can that really work? Intuitively, I > would have thought that compression is adaptive, and based on prior > additions to the file. I might be wrong with this though. > > I'm pretty sure that the ZIP format uses independent compression for each contained file (member). You can add and remove members from an existing ZIP, and use several different compression methods within the same file. So the adaptive tables start over for each new member. What isn't so convenient is that the sizes are apparently at the end. So if you're trying to unzip "over the wire" you can't readily do it without somehow seeking to the end. That same feature is a good thing when it comes to spanning zip files across multiple disks. The zip file format is documented on the net, but I haven't read the spec in at least 15 years. DaveA From cournape at gmail.com Tue Nov 17 09:28:09 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 17 Nov 2009 23:28:09 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: > >> I don't think Python and Go address the same set of programmer >> desires. ?For example, Go has a static type system. ?Some programmers >> find static type systems to be useless or undesirable. ?Others find >> them extremely helpful and want to use them them. ?If you're a >> programmer who wants a static type system, you'll probably prefer Go >> to Python, and vice versa. ?That has nothing to do with implementation >> speed or development expenditures. ?If Google spent a million dollars >> adding static types to Python, it wouldn't be Python any more. > > ... and I still have an issue with the whole "Python is slow" > meme. ?The reason NASA doesn't build a faster Python is because > Python *when augmented with FORTRAN libraries that have been > tested and optimized for decades and are worth billions of dollars > and don't need to be rewritten* is very fast. It is a bit odd to dismiss "python is slow" by saying that you can extend it with fortran. One of the most significant point of python IMO is its readability, even for people not familiar with it, and that's important when doing scientific work. Relying on a lot of compiled libraries goes against it. I think that python with its scientific extensions is a fantastic tool, but I would certainly not mind if it were ten times faster. In particular, the significant cost of function calls makes it quickly unusable for code which cannot be easily "vectorized" - we have to resort to using C, etc... to circumvent this ATM. Another point which has not been mentioned much, maybe because it is obvious: it seems that it is possible to makes high level languages quite fast, but doing so while keeping memory usage low is very difficult. Incidentally, the same tradeoff appears when working with vectorized code in numpy/scipy. David From carsten.haese at gmail.com Tue Nov 17 09:33:34 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Tue, 17 Nov 2009 09:33:34 -0500 Subject: Code for finding the 1000th prime In-Reply-To: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert P. J. Day, 15.11.2009 15:44: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray >> it's 7919. > > Now, all that's left to do is write a prime number generator (a random > number generator will do, too, but writing a good one isn't easy), run it > repeatedly in a loop, and check if the returned number is 7919. Once it > compares equal, you can print the result and you're done. Just do a brute-force search: for i in range(10000): if i==7919: # Found it! print i ;-) -- Carsten Haese http://informixdb.sourceforge.net From stefan_ml at behnel.de Tue Nov 17 09:36:47 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 17 Nov 2009 15:36:47 +0100 Subject: XML root node attributes In-Reply-To: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Message-ID: <4b02b4ff$0$7615$9b4e6d93@newsspool1.arcor-online.net> Slafs, 17.11.2009 15:19: > I'm little confused about adding attributes to the root node when > creating an XML document. > Can I do this using minidom or something else. Yes, you /can/, but you /should/ use something else. > I can't find anything that would fit my needs. > > i would like to have something like this: > > > > .... > Use ElementTree: import xml.etree.ElementTree as ET root = ET.Element("root", dict(a='v', b='v2', c='v3')) root.SubElement('d') print ET.tostring(root) Stefan From mmitchell at transparent.com Tue Nov 17 09:40:36 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Tue, 17 Nov 2009 09:40:36 -0500 Subject: XML root node attributes In-Reply-To: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> Message-ID: ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Slafs Sent: Tuesday, November 17, 2009 9:20 AM To: python-list at python.org Subject: XML root node attributes Hi I'm little confused about adding attributes to the root node when creating an XML document. Can I do this using minidom or something else. I can't find anything that would fit my needs. i would like to have something like this: .... Please help. Regards. -- http://mail.python.org/mailman/listinfo/python-list Hi, I'm sure someone will point out a better way to do it but yes, you can do it with minidom. from xml.dom.minidom import Document doc = Document() root = doc.createElement('root') root.setAttribute('a', 'v') root.setAttribute('b', 'v2') root.setAttribute('c', '3') doc.appendChild(root) d = doc.createElement('d') root.appendChild(d) print doc.toprettyxml() From chandrakant.silver at gmail.com Tue Nov 17 09:42:42 2009 From: chandrakant.silver at gmail.com (silvercl) Date: Tue, 17 Nov 2009 06:42:42 -0800 (PST) Subject: Please recommend the books that might be helpful to learn Python :) References: <2ccf65e6-4cab-4094-b0fc-dc7cdcf96010@g22g2000prf.googlegroups.com> Message-ID: <78068b48-784d-45ea-b43b-43c6c05fdba4@a32g2000yqm.googlegroups.com> On Nov 17, 7:18?am, Psi wrote: > as the subject says, > > any books? This is one of the good books available on the internet... http://diveintopython.org/ I myself liked this book very much (to start with). Also, on the website, on the right-hand-side it mentions about other books. -- Silver, Chandrakant. From tsize69 at gmail.com Tue Nov 17 09:55:03 2009 From: tsize69 at gmail.com (Tsize) Date: Tue, 17 Nov 2009 06:55:03 -0800 (PST) Subject: ast manipulation Message-ID: Hello, I am hoping for a little help. I have been playing with the python ast module and have run into an issue that I need a little push on. I would like to be able to change a specific element in a specific node in an ast then compile the resulting ast. Consider the simplified example below with its output. In this example I would like a way to change a specific addition operation. With the NodeTransformer I see how to change every addition operator but not how to change a specific one. I would like this to work on both the 2.6 and 3.1 branches. Ideally I would like to read a file, count the instances of an operation of interest and then use an index to make the changes. I am probably missing something simple but I am lost right now. import ast class SwitchMinusPlus(ast.NodeTransformer): def visit_BinOp(self, node): node = self.generic_visit(node) if isinstance(node.op, ast.Add): node.op = ast.Sub() return node myfile = open('trivial.py').read() print myfile tree = compile(myfile, '', 'exec', ast.PyCF_ONLY_AST) print ast.dump(tree, annotate_fields=False, include_attributes=False) node = SwitchMinusPlus().visit(ast.parse(myfile)) print ast.dump(node, annotate_fields=False, include_attributes=False) Which gives the following output: Note that this code changes the addition operator to an subtraction operator at the AST level for every instance. a = 8 b = 6 c = b + a d = c + a Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store ())], Num(6)), Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a', Load()))), Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a', Load())))]) Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store ())], Num(6)), Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a', Load()))), Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a', Load())))]) Thanks in advance, Thomas From davea at ieee.org Tue Nov 17 10:02:13 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 10:02:13 -0500 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <4B02BAF5.8090005@ieee.org> Virgil Stokes wrote: >
    If one > goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > > and if you now click on the tab labeled "history and compare" this > will take you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > > Finally...This is where I would like to "connect to" the data on a > daily basis or to gather data over different time intervals. I believe > that if I can get some help on this, then I will be able to customize > the code as needed for my own purposes. > > It should be clear that this is financial data on a fond managed by > Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. > > Note, that I do have some experience with Python (2.6 mainly), and > find it a very useful and powerful language. However, I have no > experience with it in the area of Web services. Any > suggestions/comments on how to set up this financial data service > project would be greatly appreciated, and I would be glad to share > this project with any interested parties. > > Note, I posted a similar message to the list pywebsvcs; but, received > no responses. > > -- V. Stokes > > I still say you should contact the bank and see if they have any API or interface defined, so you don't have to do web-scraping. The following text is on the XHTML page for that last link:
    ''' TIA, V On Mon, Nov 9, 2009 at 1:14 PM, Rami Chowdhury wrote: > On Mon, 09 Nov 2009 09:44:24 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > Did you give up on me? >> V >> >> On Sun, Nov 8, 2009 at 12:40 PM, Victor Subervi > >wrote: >> >> [root at 13gems angrynates.com]# chcon -R -h >>> unconfined_u:object_r:httpd_sys_content_t global_solutions/* >>> >>> Then I surfed to >>> http://209.216.9.56/global_solutions/index.py >>> >>> [root at 13gems angrynates.com]# tail /var/log/messages >>> Nov 8 04:26:02 13gems syslogd 1.4.1: restart. >>> [root at 13gems angrynates.com]# tail /var/log/httpd/error_log >>> [Sun Nov 08 05:35:10 2009] [notice] Digest: generating secret for digest >>> authentication ... >>> [Sun Nov 08 05:35:10 2009] [notice] Digest: done >>> [Sun Nov 08 05:35:10 2009] [notice] mod_python: Creating 4 session >>> mutexes >>> based on 10 max processes and 0 max threads. >>> [Sun Nov 08 05:35:10 2009] [notice] Apache/2.2.3 (CentOS) configured -- >>> resuming normal operations >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] File does not >>> exist: /var/www/html/angrynates.com/favicon.ico >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] (2)No such file >>> or directory: exec of '/var/www/html/ >>> angrynates.com/global_solutions/index.py' failed, referer: >>> http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 07:29:40 2009] [error] [client 66.248.168.98] Premature end >>> of >>> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] File does not >>> exist: /var/www/html/angrynates.com/favicon.ico >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] (2)No such file >>> or directory: exec of '/var/www/html/ >>> angrynates.com/global_solutions/index.py' failed, referer: >>> http://209.216.9.56/global_solutions/ >>> [Sun Nov 08 09:38:44 2009] [error] [client 66.248.168.98] Premature end >>> of >>> script headers: index.py, referer: http://209.216.9.56/global_solutions/ >>> >>> TIA, >>> V >>> >>> On Sun, Nov 8, 2009 at 12:28 PM, Rami Chowdhury < >>> rami.chowdhury at gmail.com>wrote: >>> >>> On Sunday 08 November 2009 05:44:31 Victor Subervi wrote: >>>> > [root at 13gems angrynates.com]# chcon -u unconfined_u -r object_r -t >>>> > httpd_sys_content_t global_solutions >>>> > chcon: can't apply partial context to unlabeled file global_solutions >>>> > Please advise. >>>> >>>> Try 'chcon -R -h unconfined_u:object_r:httpd_sys_content_t >>>> global_solutions/*', which should specify the whole context at once and >>>> avoid >>>> that error, as well as apply it recursively to all files and >>>> subdirectories. >>>> >>>> Also, to narrow down the error, can you let us have the output of: >>>> tail /var/log/messages >>>> tail /var/log/httpd/error_log >>>> >>>> > OK, after all this I've forgotten what your .py file looked like -- can you > post that please? > > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 9 13:43:22 2009 From: rt8396 at gmail.com (r) Date: Mon, 9 Nov 2009 10:43:22 -0800 (PST) Subject: Choosing GUI Module for Python References: <91fc195f-aa4a-4dfb-a411-d32e9e12a016@j19g2000yqk.googlegroups.com> <8b2226ce-032a-4680-a550-742a41f78587@15g2000yqy.googlegroups.com> Message-ID: <6ee3b0be-9cff-42d6-b14e-f0277af79374@u13g2000vbb.googlegroups.com> On Nov 9, 3:59?am, Antony wrote: > I would like to know about that pros and cons only ... I'll reiterate what i have said and others have said. WE NEED MORE INFO TO PROPERLY GUIDE YOU!!! Survey: What GUI is right for you? 1. What is your level of GUI programming? (0 1 2 3 4 5) 2. Will you be using this GUI for your own apps or distributing the apps? 3. What is the primary OS that this app will be used on (or any)? 4. What type of app (graphics(2D/3D), texteditor, hello world)? 5. Are themes/customizable look and feel important? *. You mentioned IDE's. That of course will narrow your choice pool substantially. Tkinter: +Is included in Python as a built-in module! +very easy to learn! +adequate docs! -lacks professional appearance -lacks many important widgets http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://effbot.org/tkinterbook/ wxPython: +larger richer widget set than tk! +better look and feel than tk! +opengl canvas built-in! -not as easy to learn as tk -docs are lacking at best (i really wish this were better!) -not built-in to Python (rightly so, too big!) i won't comment on the others. If you have absolutely no experience try out Tkinter just to a feel for GUI in a hand holding environment. If you are not happy with Tkinter's simplicity then move on to a full featured GUI kit if you need the more advanced stuff. I would say try them all! I would also suggest you learn to code GUI's without an IDE. I think the experience is more rewarding. You should know every bit of code you create personally! From joncle at googlemail.com Mon Nov 9 13:49:35 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 10:49:35 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> Message-ID: <5dface4a-ffa0-41b1-9f42-eeae9e80c91b@v25g2000yqk.googlegroups.com> On Nov 9, 5:22?pm, "Alf P. Steinbach" wrote: > * Jon Clements: > > > > > On Nov 9, 4:10 pm, "Alf P. Steinbach" wrote: > >> Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > >> It's now Python 3.x, and reworked with lots of graphical examples and more > >> explanatory text, plus limited in scope to Basic Concepts (which I previously > >> just had as a first ch 2 section ?-- ?but there's rather a lot of concepts!). > > >> I think it's wise to invite comments even when it's not 100% completed. First, > >> because as opposed to ch 1 there is quite a bit of code here, and since I'm a > >> Python newbie I may be using non-idiomatic constructs, not to mention doing > >> worse things. :-) Second, because comments in general can improve the text. > > >> Contents: > > >> 2.1 Super-basic concept: why programming is not DWIM. ? 1 > >> 2.2 Reported errors. ? ?4 > >> 2.2.1 ? Case-sensitity. 4 > >> 2.2.2 ? Syntax / compilation errors. ? ?4 > >> 2.2.3 ? Runtime errors / crashes. ? 5 > >> 2.3 A programming exploration tool: turtle graphics. ? ?6 > >> 2.4 Naming things. ?8 > >> 2.4.1 ? Naming actions: routines. ? 8 > >> 2.4.2 ? Naming data part I: variables. ?11 > >> 2.4.3 ? Naming data part II: routine arguments. 13 > >> 2.5 Controlling the flow of execution. ?14 > >> 2.5.1 ? Repeating actions automatically: loops. 14 > >> 2.5.2 ? Basic comparisions & boolean values. ? ?16 > >> 2.5.3 ? Interlude I: a function graph program / about types. ? ?17 > >> 2.5.4 ? Automated action choices. ? 21 > >> 2.5.5 ? Value-producing (function-like) routines. ? 23 > >> 2.5.6 ? Interlude II: a graph with zeroes marked / about program structure. 26 > >> 2.5.7 ? Dynamically nested actions: recursive routines. 28 > >> 2.6 Objects. ? ? [Not started on this] 31 > >> 2.7 Collections. ? ?[Not started on this] 31 > > >> In Google Docs (both chapters available here): > > >> ? ? ? > >> ? ? ?Formats: PDF > > >> Cheers, > > >> - Alf > > > Well, you may not like it, but it is perfectly acceptable and indeed > > promoted to use CONSTANT_VAR_NAMES. You're almost discouraging the use > > of a well understood and oft-used idiom. I they're a lot of them, you > > generally have a settings module, that just lists all of the > > 'constants' (.h files effectively). > > Yeah, I thought of that angle so I emphasized 'programs'. > > As it happens about half or more of the variables in the examples are constants. > > All uppercase convention for that would be ugly to me. :-) Okies, maybe introducing the fact that lots of 'programs' often have constants, which are quite often settings or whatever and they would use the uppercase notation (and if numerous, in a separate module). Also maybe you can introduce the fundamental idea of a 'namespace', maybe something like: class const: pi = 3.14 name = 'Alf' language = 'Python' or whatever, then reference const. ? I'm not 100% sure I'm keen on this idea, but it's an option you can consider at least. Introduces a couple of bits that may be discussed later, but I'd be a little scared that people would start thinking 'const.' was something magical. > > > "Technically line_length is a variable"...: No - it's a name that > > binds to an object that happens to be an integer. You've participated > > in discussions re: this. Similarly 'number_of_apples = > > number_of_apples + 1' is not an assignment ;) > > Ah, you're kidding. > > Probably. > > Anyways, that's the terminology employed by the language reference, and even if > it wasn't I'd use it because this is primarily introduction to programming in > general, where Python just happens to be the vehicle; thus, language independent > terminology preferred (e.g., I use "routine" instead of C/Python "function"). > > > It's nit-picky and I > > realise you're trying to keep it simple, but as it's meant for new > > programmers to the Python language, then introduce them to Python's > > way of "variables", they'll thank you for it later... (or run > > screaming, or start another thread here...) > > Yeah, good point, thanks! > > But it will have to wait till I get down into details... ;-) > Fair enough. It would be nice though to cover stuff like: a = [1,2,3] b = a - b is not a *copy* of a - b is not a *reference* to a - b just happens to be another name for the list object. And stuff about mutable/immutable: it would certainly help with a lot of gotcha's. > > I've never seen/heard != described as "different from"; what's wrong > > with "not equal to"? > > Thanks! > > > And why no mention of 'not' (should be mentioned > > with booleans surely?). > > Again, I'll discuss that later. It's just too much to bring up. Most of my work > with this has been to pare down to essentials and *remove* stuff I'd written. > Well, should you re-write != as "not equal to", it wouldn't hurt to mention a little later that not False is True and vice versa... > > That's as far as I've got; might get around to reading more later... > > > Cool tree at the end :) > > Thanks! > > Cheers, > > - Alf Cheers, Jon. From rami.chowdhury at gmail.com Mon Nov 9 13:53:04 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 10:53:04 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi wrote: > Of course. Let me start with some updates to httpd.conf, which didn't > help > anyway: > > > ServerAdmin me at creative.vi > DocumentRoot /var/www/html/angrynates.com > ServerName angrynates.com > Options +ExecCGI -IncludesNoExec > > Options +ExecCGI > AllowOverride All > AllowOverride FileInfo > #AddHandler mod_python .py > #PythonHandler mod_python.publisher > #PythonDebug On > AddHandler cgi-script .cgi .py > Options Includes Indexes SymLinksIfOwnerMatch ExecCGI > > SecFilterEngine Off > > > SecRuleEngine Off > > AddHandler cgi-script .cgi .py > Options Includes Indexes SymLinksIfOwnerMatch ExecCGI > > > SecFilterEngine Off > > > SecRuleEngine Off > > > > > > Here's index.py: > > #!/usr/bin/python > > import string > import cgitb; cgitb.enable() > import cgi > import sys,os > sys.path.append(os.getcwd()) > from template import template > > ourFile = string.split(__file__, "/") > page = ourFile[len(ourFile) - 1][:-3] > > form = cgi.FieldStorage() > w = form.getfirst('w', '1024') > > template(page, w) > > Can you try running index.py from the command-line, and let me know if that works? Also, as you've already been asked - please start your replies *below* the text you are replying to. Putting your replies above the last email, or "top-posting" makes reading long email threads with lots of text distracting and frustrating. -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From eyal.gordon at gmail.com Mon Nov 9 14:05:31 2009 From: eyal.gordon at gmail.com (Eyal Gordon) Date: Mon, 9 Nov 2009 21:05:31 +0200 Subject: questions regarding stack size use for multi-threaded python programs Message-ID: <4ebf5d590911091105s21c32746y3208d02883215116@mail.gmail.com> Hi, background: we are using python 2.4.3 on CentOS 5.3 with many threads - and our shell's default stack size limit is set to 10240KB (i.e. ~10MB). we noticed that python's Threading module appears to create threads with this value as their stack size (we ran a sample program that creates 10 threads and measured its virtual memory size, then reduced the stack size limit of the shell to 5120KB - and saw that the program's virtual memory size was reduced by ~50MBs). the problem: our program uses numerous threads, and thus the virtual memory size gets to be very large. we would like to reduce the size of the stack to reduce this size. we were looking for information about recommendation for the stack size to use, but found none. questions: 1. is there some rule-of-thumb for the recommended stack size for python programs of various sorts? 2. is there a way for us, at runtime (from inside the code or outside the process), to find how much of a thread's stack we are using (in KB or some other size units)? 3. when we define local objects - do the objects themselves get allocated on the stack - or are they allocated on the heap and only references to them are kept on the stack? 4. would the size of the stacks (which are probably not really allocated by the linux virtual memory sub-system, unless used) have a noticeable performance effect on a python program? same question regarding the use of a large number of threads? thanks, Eyal -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan at baselinedata.co.uk Mon Nov 9 14:18:56 2009 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Mon, 09 Nov 2009 19:18:56 +0000 Subject: String prefix question In-Reply-To: References: <4AF78098.1060509@baselinedata.co.uk> Message-ID: <4AF86B20.3080208@baselinedata.co.uk> Benjamin Kaplan wrote: > On Sun, Nov 8, 2009 at 9:38 PM, Alan Harris-Reid > wrote: > >> In the Python.org 3.1 documentation (section 20.4.6), there is a simple >> "Hello World" WSGI application which includes the following method... >> >> def hello_world_app(environ, start_response): >> status ='200 OK' # HTTP Status >> headers =(b'Content-type', b'text/plain; charset=utf-8')] # HTTP Headers >> start_response(status, headers) >> >> # The returned object is going to be printed >> return [b"Hello World"] >> >> Question - Can anyone tell me why the 'b' prefix is present before each >> string? The method seems to work equally well with and without the prefix. >> From what I can gather from the documentation the b prefix represents a >> bytes literal, but can anyone explain (in simple english) what this means? >> >> Many thanks, >> Alan >> > > The rather long version: > read http://www.joelonsoftware.com/articles/Unicode.html > > A somewhat shorter summary, along with how Python deals with this: > > Once upon a time, someone decided to allocate 1 byte for each > character. Since everything the Americans who made the computers > needed fit into 7 bits, this was alright. And they called this the > American Standard Code for Information Interchange (ASCII). When > computers came along, device manufacturers realized that they had 128 > characters that didn't mean anything, so they all made their own > characters to show for the upper 128. And when they started selling > computers internationally, they used the upper 128 to store the > characters they needed for the local language. This had several > problems. > > 1) Files made by on one computer in one country wouldn't display right > in a computer made by a different manufacturer or for a different > country > > 2) The 256 characters were enough for most Western languages, but > Chinese and Japanese need a whole lot more. > > To solve this problem, Unicode was created. Rather than thinking of > each character as a distinct set of bits, it just assigns a number to > each one (a code point). The bottom 128 characters are the original > ASCII set, and everything else you could think of was added on top of > that - other alphabets, mathematical symbols, music notes, cuneiform, > dominos, mah jong tiles, and more. Unicode is harder to implement than > a simple byte array, but it means strings are universal- every program > will interpret them exactly the same. Unicode strings in python are > the default ('') in Python 3.x and created in 2.x by putting a u in > front of the string declaration (u'') > > Unicode, however, is a concept, and concepts can't be mapped to bits > that can be sent through the network or stored on the hard drive. So > instead we deal with strings internally as Unicode and then give them > an encoding when we send them back out. Some encodings, such as UTF-8, > can have multiple bytes per character and, as such, can deal with the > full range of Unicode characters. Other times, programs still expect > the old 8-bit encodings like ISO-8859-1 or the Windows Ansi code > pages. In Python, to declare that the string is a literal set of bytes > and the program should not try and interpret it, you use b'' in Python > 3.x, or just declare it normally in Python 2.x (''). > > ------------------------------------------------------ > What happens in your program: > > When you print a Unicode string, Python has to decide what encoding to > use. If you're printing to a terminal, Python looks for the terminal's > encoding and uses that. In the event that it doesn't know what > encoding to use, Python defaults to ASCII because that's compatible > with almost everything. Since the string you're sending to the web > page only contains ASCII characters, the automatic conversion works > fine if you don't specify the b''. Since the resulting page uses UTF-8 > (which you declare in the header), which is compatible with ASCII, the > output looks fine. If you try sending a string that has non-ASCII > characters, the program might throw a UnicodeEncodeError because it > doesn't know what bytes to use for those characters. It may be able to > guess, but since I haven't used WSGI directly before, I can't say for > sure. > Thanks Benjamin - great 'history' lesson - explains it well. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 9 14:24:33 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 14:24:33 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> Message-ID: <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury wrote: > On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < > victorsubervi at gmail.com> wrote: > > Of course. Let me start with some updates to httpd.conf, which didn't help >> anyway: >> >> >> ServerAdmin me at creative.vi >> DocumentRoot /var/www/html/angrynates.com >> ServerName angrynates.com >> Options +ExecCGI -IncludesNoExec >> >> Options +ExecCGI >> AllowOverride All >> AllowOverride FileInfo >> #AddHandler mod_python .py >> #PythonHandler mod_python.publisher >> #PythonDebug On >> AddHandler cgi-script .cgi .py >> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >> >> SecFilterEngine Off >> >> >> SecRuleEngine Off >> >> AddHandler cgi-script .cgi .py >> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >> >> >> SecFilterEngine Off >> >> >> SecRuleEngine Off >> >> >> >> >> >> Here's index.py: >> >> #!/usr/bin/python >> >> import string >> import cgitb; cgitb.enable() >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from template import template >> >> ourFile = string.split(__file__, "/") >> page = ourFile[len(ourFile) - 1][:-3] >> >> form = cgi.FieldStorage() >> w = form.getfirst('w', '1024') >> >> template(page, w) >> >> >> > Can you try running index.py from the command-line, and let me know if that > works? > It runs fine. So I created a test file of the same, chmod and tried it on my browser. Rendered. So I deleted index.py and recreated it from the command line, chmod. Rendered! Apparently, somehow in the translation from uploading it via ftp to moving the files to a new dir, something got screwed up in the permissions that I can't see! Any idea what the heck that could possibly be?? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Mon Nov 9 14:27:25 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 09 Nov 2009 11:27:25 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080249.55097.rami.chowdhury@gmail.com> <4dc0cfea0911080544q6441f617x35c624def348eda@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> Message-ID: On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi wrote: > On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury > wrote: > >> On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> Of course. Let me start with some updates to httpd.conf, which didn't >> help >>> anyway: >>> >>> >>> ServerAdmin me at creative.vi >>> DocumentRoot /var/www/html/angrynates.com >>> ServerName angrynates.com >>> Options +ExecCGI -IncludesNoExec >>> >>> Options +ExecCGI >>> AllowOverride All >>> AllowOverride FileInfo >>> #AddHandler mod_python .py >>> #PythonHandler mod_python.publisher >>> #PythonDebug On >>> AddHandler cgi-script .cgi .py >>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>> >>> SecFilterEngine Off >>> >>> >>> SecRuleEngine Off >>> >>> AddHandler cgi-script .cgi .py >>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>> >>> >>> SecFilterEngine Off >>> >>> >>> SecRuleEngine Off >>> >>> >>> >>> >>> >>> Here's index.py: >>> >>> #!/usr/bin/python >>> >>> import string >>> import cgitb; cgitb.enable() >>> import cgi >>> import sys,os >>> sys.path.append(os.getcwd()) >>> from template import template >>> >>> ourFile = string.split(__file__, "/") >>> page = ourFile[len(ourFile) - 1][:-3] >>> >>> form = cgi.FieldStorage() >>> w = form.getfirst('w', '1024') >>> >>> template(page, w) >>> >>> >>> >> Can you try running index.py from the command-line, and let me know if >> that >> works? >> > > It runs fine. So I created a test file of the same, chmod and tried it > on my > browser. Rendered. So I deleted index.py and recreated it from the > command > line, chmod. Rendered! Apparently, somehow in the translation from > uploading > it via ftp to moving the files to a new dir, something got screwed up in > the > permissions that I can't see! Any idea what the heck that could possibly > be?? > TIA, > V What platform did you upload from? Something as seemingly insignificant as Windows line-endings can mess up file execution... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From joncle at googlemail.com Mon Nov 9 14:36:08 2009 From: joncle at googlemail.com (Jon Clements) Date: Mon, 9 Nov 2009 11:36:08 -0800 (PST) Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) References: <8c1e1a34-dfc4-4b1a-ab2c-8c953d937f31@v30g2000yqm.googlegroups.com> <5dface4a-ffa0-41b1-9f42-eeae9e80c91b@v25g2000yqk.googlegroups.com> Message-ID: <85ebdc3a-5ed3-4567-80a7-a319832de68c@n35g2000yqm.googlegroups.com> [posts snipped] The only other thing is that line_length is used as a constant in one of the programs. However, it's being mutated in the while loop example. It may still be in the reader's mind that line_length == 10. (Or maybe not) Cheers, Jon. From davecook at nowhere.net Mon Nov 9 14:55:35 2009 From: davecook at nowhere.net (Dave Cook) Date: 09 Nov 2009 19:55:35 GMT Subject: Choosing GUI Module for Python References: Message-ID: <0056b1e8$0$16924$c3e8da3@news.astraweb.com> On 2009-11-09, Antony wrote: > 1. PyGTK > 2. PyQT > 3. PySide > 4. wxPython > 5 . TKinter For cross-platform work, I'd choose either PyQt or wxPython. If you're not too worried about the dual license, I find PyQt the best combination of ease of use and features, particularly when used with Qt Designer. For commercial work, I'd use wxPython, which has a very liberal license. It's fairly featureful, but not very pleasant to use. Dave Cook From simon.hibbs at gmail.com Mon Nov 9 15:01:51 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Mon, 9 Nov 2009 12:01:51 -0800 (PST) Subject: Choosing GUI Module for Python References: Message-ID: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Having tried most of the options out there, personaly I've settled on two. I use Tkinter for ver simple GUIs such as single dialog boxes or results displays. The advantage of it being built-in to Python outweighs it's limitations. For anything more complex, I go for PyQT every time. QTDesigner is a full drag-and-drop GUI builder that rivals Visual Studio, and PyQT comes with a script to convert QTDesigner XML files into Python code, which you then subclass in your own script and attach your own code to the GUI widgets. There's a longer learning curve than Tkinter, but it's very much worth it for access to QTs mature and rich framework, with excellent professional-class documentation. Sorry, but wxWidgets which I have used doesn't come anywhere close. The main objection to using PyQT untill now was that for commercial development you needed to buy a license (it was free for GPL projects). That's rapidly becoming a non-issue as the core QT framework is now LGPL and Nokia have a project underway to produce PyQT compatible LGPL python bindings under the PySide project. Simon Hibbs From invalid at invalid.invalid Mon Nov 9 15:07:14 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 9 Nov 2009 20:07:14 +0000 (UTC) Subject: Choosing GUI Module for Python References: <0056b1e8$0$16924$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-09, Dave Cook wrote: > On 2009-11-09, Antony wrote: > >> 1. PyGTK >> 2. PyQT >> 3. PySide >> 4. wxPython >> 5 . TKinter > > For cross-platform work, I'd choose either PyQt or wxPython. > > If you're not too worried about the dual license, I find PyQt > the best combination of ease of use and features, particularly > when used with Qt Designer. > > For commercial work, I'd use wxPython, which has a very > liberal license. It's fairly featureful, but not very > pleasant to use. NB: One thing to I've noticed about wxPython is that if you follow the rules carefully, the cross-platform behavior consistency is pretty decent. However, if you're not careful, it's easy to do something the "wrong" way and have it still work fine on one platform, but not on another. During development, you need to test frequently on all the platforms you care about. If you wait until the end to test on that second/third platform, you may have accumulated enough minor problems that it becomes a real chore to try to figure them all out. -- Grant Edwards grante Yow! Why don't you ever at enter any CONTESTS, visi.com Marvin?? Don't you know your own ZIPCODE? From drobinow at gmail.com Mon Nov 9 15:27:10 2009 From: drobinow at gmail.com (David Robinow) Date: Mon, 9 Nov 2009 15:27:10 -0500 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: <4eb0089f0911091227l497c9342h74db66bf3b8a6140@mail.gmail.com> On Mon, Nov 9, 2009 at 11:46 AM, Moses wrote: > Hi Chris, > > The code is > > from scipy import * > from pylab import * > > x = [0.5,0.6,0.7,0.8,0.9,1.0] > y = [2,6,8,10,10,10] > > plot(x,y,linewidth=5.0) > show() > > and not > > from scipy import * > from pylab import * > > x1 = [0.5,0.6,0.7,0.8,0.9,1.0] > x2 = [0,1,2,3,4,5,6,7,8,9,10] > > plot(x1,y01,linewidth=5.0) > show() > Don't top-post use: axis([xmin,xmax,ymin,ymax]) See the documentation for details From robert.kern at gmail.com Mon Nov 9 15:45:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 Nov 2009 14:45:41 -0600 Subject: [PYTHON] How to set the range for x-axis In-Reply-To: References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: On 2009-11-09 10:43 AM, Moses wrote: > > Hi Chris, > > I am using python 2.6 and am using scipy and pylab. See the code below. You will want to ask matplotlib questions 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 victorsubervi at gmail.com Mon Nov 9 15:46:26 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 9 Nov 2009 15:46:26 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> Message-ID: <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote: > > On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury wrote: > >> On Mon, 09 Nov 2009 11:24:33 -0800, Victor Subervi < >> victorsubervi at gmail.com> wrote: >> >> On Mon, Nov 9, 2009 at 1:53 PM, Rami Chowdhury >> >wrote: >>> >>> On Mon, 09 Nov 2009 10:36:31 -0800, Victor Subervi < >>>> victorsubervi at gmail.com> wrote: >>>> >>>> Of course. Let me start with some updates to httpd.conf, which didn't >>>> help >>>> >>>>> anyway: >>>>> >>>>> >>>>> ServerAdmin me at creative.vi >>>>> DocumentRoot /var/www/html/angrynates.com >>>>> ServerName angrynates.com >>>>> Options +ExecCGI -IncludesNoExec >>>>> >>>>> Options +ExecCGI >>>>> AllowOverride All >>>>> AllowOverride FileInfo >>>>> #AddHandler mod_python .py >>>>> #PythonHandler mod_python.publisher >>>>> #PythonDebug On >>>>> AddHandler cgi-script .cgi .py >>>>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>>>> >>>>> SecFilterEngine Off >>>>> >>>>> >>>>> SecRuleEngine Off >>>>> >>>>> AddHandler cgi-script .cgi .py >>>>> Options Includes Indexes SymLinksIfOwnerMatch ExecCGI >>>>> >>>>> >>>>> SecFilterEngine Off >>>>> >>>>> >>>>> SecRuleEngine Off >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Here's index.py: >>>>> >>>>> #!/usr/bin/python >>>>> >>>>> import string >>>>> import cgitb; cgitb.enable() >>>>> import cgi >>>>> import sys,os >>>>> sys.path.append(os.getcwd()) >>>>> from template import template >>>>> >>>>> ourFile = string.split(__file__, "/") >>>>> page = ourFile[len(ourFile) - 1][:-3] >>>>> >>>>> form = cgi.FieldStorage() >>>>> w = form.getfirst('w', '1024') >>>>> >>>>> template(page, w) >>>>> >>>>> >>>>> >>>>> Can you try running index.py from the command-line, and let me know if >>>> that >>>> works? >>>> >>>> >>> It runs fine. So I created a test file of the same, chmod and tried it on >>> my >>> browser. Rendered. So I deleted index.py and recreated it from the >>> command >>> line, chmod. Rendered! Apparently, somehow in the translation from >>> uploading >>> it via ftp to moving the files to a new dir, something got screwed up in >>> the >>> permissions that I can't see! Any idea what the heck that could possibly >>> be?? >>> TIA, >>> V >>> >> >> What platform did you upload from? Something as seemingly insignificant as >> Windows line-endings can mess up file execution... >> > > OS is Windoze XL. Have we caught the thief? How can I upload from this box > and not have this problem, or undo it at the server? You know, of course, I > don't see this line-ending from the command prompt when I vi it. > TIA, > V > > Hold everything. Apparently line-endings got mangled. What I don't understand is why I didn't see them when I opened the file to edit, and why they didn't copy and paste when I did that. But dos2unix cleaned up a couple of files so I presume it will clean up the rest. However, I tried one file, that reads exactly the same as index.py, and when I surfed to it got a 500 error. Here's what the log said: [Mon Nov 09 12:30:27 2009] [notice] mod_python: (Re)importing module 'mptest' [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: Traceback (most recent call last):, referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch\n log=debug), referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 461, in import_module\n f, p, d = imp.find_module(parts[i], path), referer: http://www.angrynates.com/global_solutions/ [Mon Nov 09 12:30:27 2009] [error] [client 98.189.137.242] PythonHandler mptest: ImportError: No module named mptest, referer: http://www.angrynates.com/global_solutions/ Huh? Got no "mptest" anywhere. Not even using mod_python. Why doesn't it refer to a specific file in the folder? Any ideas on this one? TIA, V > >> >> >> -- >> Rami Chowdhury >> "Never attribute to malice that which can be attributed to stupidity" -- >> Hanlon's Razor >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdekauwe at gmail.com Mon Nov 9 17:02:56 2009 From: mdekauwe at gmail.com (Martin) Date: Mon, 9 Nov 2009 14:02:56 -0800 (PST) Subject: How to set the range for x-axis References: <50697b2c0911090749p1813ea13i575e7be8c490be6d@mail.gmail.com> Message-ID: <07c2fcef-87d1-4b9a-a552-8c63fee3e02c@p8g2000yqb.googlegroups.com> On Nov 9, 8:45?pm, Robert Kern wrote: > On 2009-11-09 10:43 AM, Moses wrote: > > > > > Hi Chris, > > > I am using python 2.6 and am using scipy and pylab. See the code below. > > You will want to ask matplotlib questions 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 import matplotlib.pyplot as plt plt.xlim(0., 1.) From mchl.dodd at gmail.com Mon Nov 9 17:08:18 2009 From: mchl.dodd at gmail.com (Michael) Date: Mon, 9 Nov 2009 14:08:18 -0800 (PST) Subject: IDLE python shell freezes after running show() of matplotlib References: <4c44996a-0a6a-4a4f-9607-e0323fbd1aa9@l35g2000vba.googlegroups.com> Message-ID: <07733d48-37a4-4216-92fb-40285efd4bef@a31g2000yqn.googlegroups.com> On Oct 28, 11:09?pm, Chris Colbert wrote: > This is a threading issue that is very common when using gui toolkits > with the interactive interpreter. > > You're better off just using ipython, which already has builtin > support for matplotlib when you start it via "ipython -pylab" > > On Wed, Oct 28, 2009 at 7:41 PM, OKB (not okblacke) > > > > wrote: > > Forrest Sheng Bao wrote: > > >> I am having a weird problem on IDLE. After I plot something using show > >> () of matplotlib, the python shell prompt in IDLE just freezes that I > >> cannot enter anything and there is no new ">>>" prompt show up. I > >> tried ctrl - C and it didn't work. I have to restart IDLE to use it > >> again. > > >> My system is Ubuntu Linux 9.04. I used apt-get to install IDLE. > > > ? ? ? ?I believe this is the intended behavior. ?Look in matplotlib > > documentation on the difference between interactive and non-interactive > > modes. > > > -- > > --OKB (not okblacke) > > Brendan Barnwell > > "Do not follow where the path may lead. ?Go, instead, where there is > > no path, and leave a trail." > > ? ? ? ?--author unknown > > -- > >http://mail.python.org/mailman/listinfo/python-list Same problem for me using IDLE 1.2.4, python 2.5.4, and matplotlib 0.99.1.1. Windows XP 32bit. Turning on interactive mode solved the problem with IDLE freezing, however the plot window still comes up empty and frozen. Using iPython now with no problems so far. Hopefully the problem with IDLE gets fixed. From rhodri at wildebst.demon.co.uk Mon Nov 9 18:01:00 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 09 Nov 2009 23:01:00 -0000 Subject: Can't Find Module In-Reply-To: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> References: <4dc0cfea0911070859t1041bd69j9ac6e5540b9897ee@mail.gmail.com> Message-ID: On Sat, 07 Nov 2009 16:59:29 -0000, Victor Subervi wrote: > ImportError: No module named template [snip] > > I can import this just fine from the python command prompt. So, what > gives? Is template.py in your current directory when you run the script from the command line? -- Rhodri James *-* Wildebeest Herder to the Masses From powderdrop at gmail.com Mon Nov 9 18:29:03 2009 From: powderdrop at gmail.com (Penn) Date: Mon, 9 Nov 2009 15:29:03 -0800 (PST) Subject: NEWB problem with urllib2 Message-ID: I just installed PyDev into Eclipse using the 'update' method and did the standard installation. I allowed it to Auto Configure itself and ran a "Hello World" module to make sure I was in the ballpark. I got an starting module up and have run "Hello World" but now am stuck on getting urlopen to import from urllib2 for the following example. from urllib2 import * # doesn't give me an error ur = urlopen("http://www.daniweb.com/forums/thread161312.html") # gives me Undefined Variable: urlopen so I tried just import urllib2 # Eclipse gives "Unresolved Import" Is urllib2 not on my path? Isn't urllib2 in the standard installation and shouldn't that automatically be on my path? If not, how can I get it on the path? ThankS!! From Ken at Elkabany.com Mon Nov 9 19:20:12 2009 From: Ken at Elkabany.com (Ken Elkabany) Date: Mon, 9 Nov 2009 16:20:12 -0800 Subject: PiCloud Beta Release In-Reply-To: <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> References: <47ab340d-befa-4ad8-99db-fd4494ace7fa@x25g2000prf.googlegroups.com> <0b9e98cf-993c-4ae5-9e02-64e7067f29b5@12g2000pri.googlegroups.com> Message-ID: On Thu, Nov 5, 2009 at 3:19 PM, Jacob Shaw wrote: > On Nov 1, 5:13?pm, Ken Elkabany wrote: >> Hello, >> >> PiCloud has just released a Python library, cloud, which allows you to >> easily offload the execution of a function to a cluster of servers >> running on Amazon Web Services. As a beta product, we are currently >> free to all users who sign up with beta code "PYTHONLIST". To >> register, go tohttp://www.picloud.com >> >> Full service description: >> PiCloud is a cloud-computing platform that integrates into the Python >> Programming Language. It enables you to leverage the compute power of >> Amazon Web Services without having to manage, maintain, or configure >> virtual servers. >> >> PiCloud integrates seamlessly into your existing code base through a >> custom Python library, cloud. To offload the execution of a function >> to the cloud, all you must do is pass your desired function into the >> cloud library. PiCloud will then run the function on its >> high-performance and automatically-scaling cluster. We quickly scale >> our server capacity, both up and down, to meet your computational >> needs, and only charge you for the resources you actually consume. >> Getting on the cloud has never been this easy! >> >> PiCloud improves the full cycle of software development and >> deployment. Functions that are run on PiCloud have their resource >> usage monitored, performance analyzed, and errors traced; we further >> aggregate all your functions to give you a bird's eye view of your >> service. Through these introspective capabilities, PiCloud enables you >> to develop faster, easier, and smarter. >> >> Common use cases for our platform: >> * Crawling the web >> * Manipulating images and videos >> * Generating charts and graphs >> * Statistical/Mathematical analysis of data sets >> * Real-time data processing >> >> Cheers, >> >> Ken Elkabany >> PiCloud, Inc. > > Wow, amazing service. ?I used PiCloud for some scraping work, and my > script ran about 10x as fast. > > Some questions though: > 1) I have another project which uses a custom python extension written > in C++. ?Is there a way to use it on PiCloud? > 2) I noticed you guys only support python 2.5 and 2.6. ?Will there be > 3.1 support eventually? > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the compliments. 1) PiCloud will not automatically transfer libraries that require python C++ extensions. However, in your control panel, you can upload a tarball or synchronize an svn repository that contains your extension's code and we'll automatically compile/install it on our systems. 2) We are currently working on support for python 3.x (we've had requests from a fair number of users), and plan to release a compatible client library in a couple of weeks. Ken From swindle at ifa.hawaii.edu Mon Nov 9 19:24:19 2009 From: swindle at ifa.hawaii.edu (Ryan Swindle) Date: Mon, 9 Nov 2009 14:24:19 -1000 Subject: Socket programming with NetCom serial-to-ethernet module Message-ID: <69f048730911091624u732af9cfga612b51cedd17a24@mail.gmail.com> Hi, This is my first Python-list post; I hope it's going to the right place. Here's my problem: I've read many tutorials on socket programming, but I can't seem to piece them together for my particular case. I have 3 serial ports, each of which individually connects to a port on a NetCom box, which converts them to TCP/IP ports (see e.g. http://www.serialgear.com/4--Port-Serial-TCP-IP-NETCOM-411.html). But I'll just focus on communicating with 1 serial port right now (assume that I have a 1-port NetCom box). So, the flow pattern goes like this -- ascii string from my Python program via the ethernet card to the NetCom box, which feeds the serial port; this serial port is the input/output to a board that controls a motor. So, I can send an ascii string like "MI100\n", which tells that motor to move 100 steps. Currently, I can accomplish this using sockets. But if I instead want to request something from the motor, like it's current position, how do I return this information back to my Python program and still keep the socket alive and listening for say another position request? FYI, the NetCom box works on DHCP. So, I could use 'arp' or another method to actually find it's IP address, and I can connect to it using say port 2000. At this point, it looks as if I would setup a server socket for the NetCom box, and then create a client socket for the motor controller board to talk to the NetCom box (and e.g. give the current position of the motor, upon my request). But the hard part seems to be how to retrieve that information from the controller board, once it responds. For instance, if I were to just use pySerial, I open up a connection to the serial port, then serial.send(ascii) sends the request, and serial.readline() reads the response. I need to know how to implement this basic functionality with sockets, where the sockets remain alive and listening after each request/response, just as pySerial does. Any advice, sockets or not, is helpful and appreciated, and I can elaborate further on the problem, if requested. (Again, I hope this was not a misuse of the list in some way; I apologize, if so). Many thanks. -Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Nov 9 19:44:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 00:44:45 -0000 Subject: Indentation problems In-Reply-To: References: Message-ID: I'm going to make a whole bunch of wild guesses here, since you don't give us a lot to go on. Wild Guess #1: you're using IDLE. On Sun, 08 Nov 2009 19:01:37 -0000, Ray Holt wrote: > I am having problems with indentation some times. When I hit the enter > key > after if statements or while statemt there are times when the > indentation is > too much Wild Guess #2: you've forgotten to close a bracket of some sort. > and other times too little. Wild Guess #3: you've forgotten the colon on the end of the line > When I try to manually make sure the > indentation is correct and try to print, I ge the error message of > invalid > syntax or incorrect indentation. Ah. Wild Guess 1a: you're using IDLE in interactive mode. In that case, bear in mind Wild Guesses 2 and 3, but they aren't the whole story. In interactive mode, IDLE executes the code that you type Right Now This Instant And No Messing. When you type a compound statement like "if" or "while", that presents a bit of a problem since the statement isn't really finished until you've typed in all the statements that belong to that "if" or "while". Knowing this, IDLE puts off executing it, and helpfully adds the indentation that it knows you'll need. If you fiddle with that extra space and delete too much of it (easily done here), IDLE will tick you off for getting your indentation wrong. If you hit Return without typing anything else, IDLE will do exactly the same thing since it knows Python requires you to have at least one statement inside the "if". Once you've typed that one statement, you can carry on typing more to your hearts content; at this point, IDLE treats a blank line as meaning "I'm done." At this point it goes away and executes what you've typed Right Now This Instant And No Messing, and may end up complaining about something you got wrong three lines ago. > Can someone help me. Also when I open the > edit window instead of the shell the programs tend not to run. Help! Ray Well, no. Unlike the interactive window, typing into the edit window doesn't cause anything to be executed Right Now Etc Etc. It doesn't even cause anything to be executed Sometime Soon Honest Guv'nor. It just saves up what you've done so that it can be run later, assuming you remember to save it to a file. Unlike the interactive window, you can go back and change what you've written earlier to correct a mistake, and re-run the entire script rather than type it in again line by line. To actually run your program you have two alternatives. Either you can use the "Run Module" entry in the "Run" menu (F5 on my version: it may be called something slightly different in a slightly different menu with a slightly different shortcut key depending on your operating system and which version of IDLE you're running), or you can pull up a console (command line, terminal, xterm, whatever your OS calls it) and invoke Python on your file directly. If that last bit didn't make any sense to you, don't worry, just leave that particular adventure in computing for another day. -- Rhodri James *-* Wildebeest Herder to the Masses From Ognjen at mailshack.com Mon Nov 9 19:47:20 2009 From: Ognjen at mailshack.com (Ognjen Bezanov) Date: Tue, 10 Nov 2009 00:47:20 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? Message-ID: <4AF8B818.5090109@mailshack.com> Hello all, Say I have a python variable: a = "hello" Is it possible for me to get the physical address of that variable (i.e. where it is in RAM)? I know that id(a) will give me it's memory address, but the address given does not seem to correlate with the physical memory. Is this even possible? Thank you! Ognjen From rhodri at wildebst.demon.co.uk Mon Nov 9 20:02:49 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 01:02:49 -0000 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy wrote: > I believe the use of tagged pointers has been considered and so far > rejected by the CPython developers. And no one else that I know of has > developed a fork for that. It would seem more feasible with 64 bit > pointers where there seem to be spare bits. But CPython will have to > support 32 bit machines for several years. I've seen that mistake made twice (IBM 370 architecture (probably 360 too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see it a third time, thank you. -- Rhodri James *-* Wildebeest Herder to the Masses From benjamin.kaplan at case.edu Mon Nov 9 20:34:56 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 9 Nov 2009 20:34:56 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF8B818.5090109@mailshack.com> References: <4AF8B818.5090109@mailshack.com> Message-ID: On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address given > does not seem to correlate with the physical memory. Is this even possible? > > > Thank you! > > > Ognjen > When you use Python, program in Python and not C. What do you need the memory location of a variable for? Python, like Java and .NET is a higher level language. You're not supposed to worry about things like the physical location in memory. There's probably some ugly hack using ctypes, or just writing the code in C but I don't know enough about Python's C API to know what it is. FWIW, even the id(x) == address of x is only an implementation detail of CPython. Other Python implementations don't use that scheme. > -- > http://mail.python.org/mailman/listinfo/python-list > From sajmikins at gmail.com Mon Nov 9 20:39:59 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 9 Nov 2009 20:39:59 -0500 Subject: NEWB problem with urllib2 In-Reply-To: References: Message-ID: <50f98a4c0911091739n33a1a62eo39add8908566ba71@mail.gmail.com> On Mon, Nov 9, 2009 at 6:29 PM, Penn wrote: > I just installed PyDev into Eclipse using the 'update' method and did > the standard installation. ?I allowed it to Auto Configure itself and > ran a "Hello World" module to make sure I was in the ballpark. > > I got an starting module up and have run "Hello World" but now am > stuck on getting urlopen to import from urllib2 for the following > example. > > from urllib2 import * ? ?# doesn't give me an error > ur = urlopen("http://www.daniweb.com/forums/thread161312.html") # > gives me Undefined Variable: urlopen > > so I tried just > > import urllib2 ? ? ? ?# Eclipse gives "Unresolved Import" > > Is urllib2 not on my path? ?Isn't urllib2 in the standard installation > and shouldn't that automatically be on my path? ?If not, how can I get > it on the path? > > ThankS!! This sounds more like a PyDev and/or Eclipse problem than an urllib2 problem. :) One thing you can check: open the "raw" python interpreter outside of Eclipse and try importing urllib2 there. You might also try the interpreter interface within Eclipse (if it provides one.) HTH From python at mrabarnett.plus.com Mon Nov 9 20:44:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 01:44:57 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF8B818.5090109@mailshack.com> References: <4AF8B818.5090109@mailshack.com> Message-ID: <4AF8C599.9040202@mrabarnett.plus.com> Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address > given does not seem to correlate with the physical memory. Is this even > possible? > Python doesn't have variables as such. The variable's name is just a key in a dict and the variable's value is the corresponding value for that key (or, to be exact, a reference to the value). A particular value can be referred to by any number of 'variables'. From rhodri at wildebst.demon.co.uk Mon Nov 9 20:47:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 01:47:37 -0000 Subject: on "Namespaces" In-Reply-To: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: On Sun, 08 Nov 2009 21:20:23 -0000, webtourist wrote: > > New bie Question: > in "Zen of Python" - what exactly does the last one mean ? - > Namespaces are one honking great idea -- let's do more of those! > > I mean why the emphasis ? Is it like saying "put modules into > packages" in other programming paradigm s ? Like all things zen, 'meaning' as applied to this koan is a shifting concept best considered after deep meditiation on... oh, who am I kidding. If you keep names in separate namespaces, you are less likely to screw up by forgetting that you meant something else by that name 30 lines above. It's less about "put modules in packages" and more about "put code in modules." Corollary: what happens after "from somewhere import *" is all your own fault. -- Rhodri James *-* Wildebeest Herder to the Masses From powderdrop at gmail.com Mon Nov 9 20:48:01 2009 From: powderdrop at gmail.com (Penn) Date: Mon, 9 Nov 2009 17:48:01 -0800 (PST) Subject: NEWB problem with urllib2 References: Message-ID: Thanks Simon! You are right.. I also believe it is something with Eclipse. I've been working since... the module below runs.. but Eclipse is still showing an error when I reference urlopen with a little red X... saying it is an undefined variable in the IDE.. but not giving me an runtime errors. #URL LIBRARY from urllib2 import * def openfilereadaline(a): f = open(a) print f for line in f: print line.rstrip() f.close() def openWebSite(a): ur = urlopen(a) #open url contents = ur.readlines()#readlines from url file fo = open("test.txt", "w")#open test.txt for line in contents: print "writing %s to a file" %(line,) fo.write(line)#write lines from url file to text file fo.close()#close text file if __name__ == '__main__': openWebSite("http://www.daniweb.com/forums/thread161312.html") print "Hello World" From rhodri at wildebst.demon.co.uk Mon Nov 9 21:02:22 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 02:02:22 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 wrote: > Rhodri James wrote: >> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >> wrote: >> >>> I have a perplexing issue, I have four users set up on a W7 computer. >>> The program runs fine for all users except the admin user who needs it >>> for school assignments. >> A little more information, please. How does it not work for the admin >> user? Is there a traceback? What do you get if you try to invoke it >> from a command line? >> > > > Hi Rhodri, here's a dump file, don't know if this helps or not.. So Windows is reporting a crash, then. I'll repeat my last question in particular; what happens when your admin user runs the program you're trying to invoke from the command line? -- Rhodri James *-* Wildebeest Herder to the Masses From davea at ieee.org Mon Nov 9 21:12:21 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 09 Nov 2009 21:12:21 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> Message-ID: <4AF8CC05.8090902@ieee.org> Victor Subervi wrote: > On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi wrote: > > >> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury wrote: >> >> >>> >> >> >> Hold everything. Apparently line-endings got mangled. What I don't >> > understand is why I didn't see them when I opened the file to edit, and why > they didn't copy and paste when I did that. But dos2unix cleaned up a couple > of files so I presume it will clean up the rest. However, I tried one file, > that reads exactly the same as index.py, and when I surfed to it got a 500 > error. Here's what the log said: > > > > What I've diagnosed as happening when a python script with Windows line-ending was posted on my server's cgi environment: The actual error seemed to be a failure to find the python interpreter, since some Unix shells take the shebang line to include the \r character that preceded the newline. Seems to me they could be more tolerant, since I don't think control characters are likely in the interpreter file name. DaveA From gagsl-py2 at yahoo.com.ar Mon Nov 9 21:16:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 09 Nov 2009 23:16:40 -0300 Subject: comparing alternatives to py2exe References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk escribi?: > On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: >> >> Recently I put together this incomplete comparison chart in an attempt >> to choose between the different alternatives to py2exe: >> >> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > I was interested in py2exe because we'd like to provide a one download, > one click install experience for our Windows users. I think a lot of > people are interested in py2exe for the same reason. Well, one thing > that I came across in my travels was the fact that distutils can create > MSIs. Like py2exe, MSIs provide a one download, one click install > experience under Windows and therefore might be a replacement for py2exe. But py2exe and .msi are complementary, not a replacement. py2exe collects in one directory (or even in one file in some cases) all the pieces necesary to run your application. That is, Python itself + your application code + all referenced libraries + other required pieces. The resulting files must be installed in the client machine; you either build a .msi file (a database for the Microsoft Installer) or use any other installer (like InnoSetup, the one I like). > For me, the following command was sufficient to create an msi, although > it only worked under Windows (not under Linux or OS X): > python setup.py bdist_msi > > The resulting MSI worked just fine in my extensive testing (read: I > tried it on one machine). The resulting .msi file requires Python already installed on the target machine, if I'm not mistaken. The whole point of py2exe is to avoid requiring a previous Python install. > It seems, then, that creating an MSI is even within the reach of someone > like me who spends very little time in Windows-land, so it might be > worth a column on your chart alongside rpm/deb. As said in http://wiki.python.org/moin/DistributionUtilities the easiest way is to use py2exe + InnoSetup. -- Gabriel Genellina From patf at well.com Mon Nov 9 21:25:56 2009 From: patf at well.com (menomnon) Date: Mon, 9 Nov 2009 18:25:56 -0800 (PST) Subject: Debugging python in emacs isn't working. References: <4a54b1ba-0fd8-4947-9ca0-67d5c98de2d9@k13g2000prh.googlegroups.com> Message-ID: <082dffc7-6bd8-4733-bdd6-46a06a80a540@u36g2000prn.googlegroups.com> On Nov 8, 6:36?pm, menomnon wrote: > Hi, > > Emacs 22.3, python 2.6.4 > > Put the following into my .emacs: > > (setq pdb-path 'c:\\python26\\lib\\pdb.py > ? ? ? gud-pdb-command-name (symbol-name pdb-path)) > (defadvice pdb (before gud-query-cmdline activate) > ? "Provide a better default command line when called interactively." > ? (interactive > ? ?(list (gud-query-cmdline pdb-path > ? ? ? ? ? ? ? ? ? ? ? ? ? ? (file-name-nondirectory buffer-file-name))))) > > So when I'm in a python buffer (I've tried both python.el and python- > mode.el) and do M-x pdb I get, say: > > c:\python26\lib\pdb.py rpytest.py > > hit and get an empty buffer that says "Comint: no process". ?And > the status line says: "Spawning child process: invalid argument". > > I've run into "spawning child process: invalid argument" before but > not being an emacs uber-geek I never solved it directly. > > Hope someone has an idea of what I'm doing wrong. python -i. It's the -i part that's important. From davea at ieee.org Mon Nov 9 21:30:01 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 09 Nov 2009 21:30:01 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: References: <4AF8B818.5090109@mailshack.com> Message-ID: <4AF8D029.5040400@ieee.org> Benjamin Kaplan wrote: > On Mon, Nov 9, 2009 at 7:47 PM, Ognjen Bezanov wrote: > >> Hello all, >> >> Say I have a python variable: >> >> a = "hello" >> >> Is it possible for me to get the physical address of that variable (i.e. >> where it is in RAM)? >> >> I know that id(a) will give me it's memory address, but the address given >> does not seem to correlate with the physical memory. Is this even possible? >> >> >> Thank you! >> >> >> Ognjen >> >> > > When you use Python, program in Python and not C. What do you need the > memory location of a variable for? Python, like Java and .NET is a > higher level language. You're not supposed to worry about things like > the physical location in memory. There's probably some ugly hack using > ctypes, or just writing the code in C but I don't know enough about > Python's C API to know what it is. > > FWIW, even the id(x) == address of x is only an implementation detail > of CPython. Other Python implementations don't use that scheme. > > > Following is for the CPython implementation. As Benjamin says, each implementation can do different things, as long as the documented semantics are preserved. The "variable" aaa is not at any particular location, and will quite likely move when you define a new "variable" bbb or ccc in the same scope. aaa is just a dictionary entry after all, in some scope. (Although it may be optimized, for locals, and for slots) aaa is bound to a particular object, and that object won't move. That object has an id() value, and I believe that id value is the address. And when you bind aaa to a different object, there'll be a different id() and address. But unless you're writing a C extension, the actual address is kind of irrelevant, isn't it? DaveA From pavlovevidence at gmail.com Mon Nov 9 21:30:13 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 9 Nov 2009 18:30:13 -0800 (PST) Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: On Nov 9, 4:47?pm, Ognjen Bezanov wrote: > Hello all, > > Say I have a python variable: > > a = "hello" > > Is it possible for me to get the physical address of that variable (i.e. > where it is in RAM)? > > I know that id(a) will give me it's memory address, but the address > given does not seem to correlate with the physical memory. Is this even > possible? I'm going to guess that A. You don't really want physical address but logical address (i.e., the address where you might access the memory with a C pointer), and B. You want the address not of the object itself, but of the data within (that is, you'd want the "pointer" you receive to point to the ASCII string hello) Python's way to handle cases like this is called buffer protocol, but it only operates at the C-extension level. There is a set of functions in the C API that look like this PyObject_AsReadBuffer(obj,**buffer,*len) Calling this will return the address of the string "hello" in *buffer. See C API Reference Manual for more details. This function can also be called from ctypes, but I don't remember the exact procedure for modifying input arguments through a pointer. Note: If you really want a PHYSCIAL RAM address you'll have to make some OS-specific system call (I think) with the logical address, probably needing superuser privileges. Obviously this call isn't exposed in Python, because there's no use for it in Python. Unless you're programming DMA transfers or something like that, there's no use for it in C, either. Carl Banks From phlip2005 at gmail.com Mon Nov 9 22:48:26 2009 From: phlip2005 at gmail.com (Phlip) Date: Mon, 9 Nov 2009 19:48:26 -0800 (PST) Subject: how to create a pip package Message-ID: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Py hont: I have a single file that I need my crew to pip install. When I Google for "how to create a pip package" I don't hit anything. Of course that info is out there; I can't seem to pick up the trail of breadcrumbs to it. While I'm looking, could someone push the link in here? Purely for posterity? Thanks! -- Phlip http://c2.com/cgi/wiki?ZeekLand From steven at REMOVE.THIS.cybersource.com.au Mon Nov 9 23:52:42 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 04:52:42 GMT Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: On Mon, 09 Nov 2009 06:02:09 -0800, J Wolfe wrote: > Hi, > > I would like to sort this dictionary by the values of the inner > dictionary ?ob? key. You can't sort dictionaries in Python, because they are unordered hash tables. Giving up the ability to store items in order is one of the things which makes them so fast. You have five choices: (1) Create your own implementation of a sortable dictionary, perhaps using a red-black tree or similar. Unless you write it in C, expect it to be massively slower than the built-in dict type. If you write it in C, expect it to be merely slower than the built-in dict type. (2) Write small helper functions that sort the keys from the dict when you need them sorted. Since you (probably) only have a small number of items in each dict, it should be fast. (3) Use a subclass of dict that sorts the items as needed. (4) Give up on using dictionaries for this, and use some other mapping, like a list of (key, value) tuples. Expect it to be massively slower than the built-in dict type. (5) Give up on the need to have them sorted. My advice is to go with #2, 3 or 5. Here's a basic version of 3 to get you started: class SortedDict(dict): # Untested. def items(self): """Return items of self in sorted order.""" L = super(SortedDict, self).items() L.sort() return L You may even find a version with an appropriate licence you can freely use if you google for "Python Sorted Dict". -- Steven From gagsl-py2 at yahoo.com.ar Mon Nov 9 23:56:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 01:56:30 -0300 Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: En Sun, 08 Nov 2009 10:08:35 -0300, gil_johnson escribi?: > On Nov 6, 8:46 pm, gil_johnson wrote: > > The problem I was solving was this: I wanted an array of 32-bit > integers to be used as a bit array, and I wanted it initialized with > all bits set, that is, each member of the array had to be set to > 4294967295. Of course, you could set your initializer to 0, or any > other 32-bit number. > > Originally I found that the doubling method I wrote about before was a > LOT faster than appending the elements one at a time, and tonight I > tried the "list = initializer * N" method. Running the code below, the > doubling method is still fastest, at least on my system. > > Of course, as long as you avoid the 'one at a time' method, we're > talking about fractions of a second, even for arrays that I think are > huge, like the 536,870,912 byte beastie below. I don't get your same results; one_item*N is faster on my tests. Note that you're comparing disparate things: > # Doubling method, run time = 0.413938045502 > newArray = array.array('I') # 32-bit unsigned > integers Method 1 creates an array object; this takes roughly 2**29 bytes > # One at a time, run time = 28.5479729176 > newArray2 = array.array('I') > for i in range(134217728): # the same size as above > newArray2.append(4294967295) This creates also an array object, *and* 134 million integer objects in the meantime. > # List with "*", run time = 1.06160402298 > newList = [4294967295] * 134217728 And this creates a list object, not an array. Note that all your 3 methods create global objects and you never delete them - so the last method is at a disadvantage. A more fair test would use timeit, and run just one method at a time: # Written in Python 3.x # use xrange everywhere with Python 2.x import array INITIAL_VALUE = 4294967295 LOG2SIZE=25 SIZE = 2**LOG2SIZE def method1a(): newArray = array.array('I') newArray.append(INITIAL_VALUE) for i in range(LOG2SIZE): newArray.extend(newArray) assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method2a(): newArray = array.array('I') for i in range(SIZE): newArray.append(INITIAL_VALUE) assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method3a(): newArray = array.array('I', [INITIAL_VALUE]) * SIZE assert len(newArray)==SIZE assert newArray[SIZE-1]==INITIAL_VALUE def method1l(): newList = [INITIAL_VALUE] for i in range(LOG2SIZE): newList.extend(newList) assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE def method2l(): newList = [] for i in range(SIZE): newList.append(INITIAL_VALUE) assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE def method3l(): newList = [INITIAL_VALUE] * SIZE assert len(newList)==SIZE assert newList[SIZE-1]==INITIAL_VALUE D:\temp>python31 -m timeit -s "from arraygrow import method1a" "method1a()" 10 loops, best of 3: 411 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method2a" "method2a()" ...aborted, too long... D:\temp>python31 -m timeit -s "from arraygrow import method3a" "method3a()" 10 loops, best of 3: 377 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method1l" "method1l()" 10 loops, best of 3: 628 msec per loop D:\temp>python31 -m timeit -s "from arraygrow import method3l" "method3l()" 10 loops, best of 3: 459 msec per loop So arrays are faster than lists, and in both cases one_item*N outperforms your doubling algorithm. Adding one item at a time is -at least- several hundred times slower; I was not patient enough to wait. > Finally, I just looked into calling C functions, and found > PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management > section of the Python/C API Reference Manual. This gives you > uninitialized memory, and should be really fast, but it's 6:45 AM > here, and I don't have the energy to try it. No, those are for internal use only, you can't use the resulting pointer in Python code. An array object is a contiguous memory block, so you don't miss anything. -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 00:02:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 05:02:25 GMT Subject: on "Namespaces" References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: On Sun, 08 Nov 2009 13:20:23 -0800, webtourist wrote: > New bie Question: > in "Zen of Python" - what exactly does the last one mean ? - Namespaces > are one honking great idea -- let's do more of those! > > I mean why the emphasis ? Is it like saying "put modules into packages" > in other programming paradigm s ? Modules are namespaces. So are packages. Classes and class instances are namespaces. Even function scopes are namespaces. When you write: n = None def spam(n): print "spam" * n def ham(n): print "ham" * n the n inside spam() and ham() and the global n are in different namespaces, and so independent. http://en.wikipedia.org/wiki/Namespace http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces -- Steven From gagsl-py2 at yahoo.com.ar Tue Nov 10 01:43:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 03:43:08 -0300 Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: En Tue, 10 Nov 2009 00:48:26 -0300, Phlip escribi?: > I have a single file that I need my crew to pip install. > > When I Google for "how to create a pip package" I don't hit anything. > Of course that info is out there; I can't seem to pick up the trail of > breadcrumbs to it. See http://pip.openplans.org/ You're looking for the "freeze" command. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Nov 10 01:57:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 10 Nov 2009 03:57:40 -0300 Subject: OT: regular expression matching multiple occurrences of one group References: <8fcc863d-dd85-43ba-bdc7-7c3575431fb6@j19g2000yqk.googlegroups.com> <6236e9a0-7662-4935-a65d-6cbcd61c6f92@o10g2000yqa.googlegroups.com> Message-ID: En Mon, 09 Nov 2009 12:59:53 -0300, Jon Clements escribi?: > On Nov 9, 1:53 pm, pinkisntwell wrote: >> How can I make a regular expression that will match every occurrence >> of a group and return each occurrence as a group match? For example, >> for a string "-c-c-c-c-c", how can I make a regex which will return a >> group match for each occurrence of "-c"? > > As well as what Diez has said, unless you absolutely want regexp's, > and by the sounds of it I'm guessing you may be after something more > flexible: what about the pyparsing module [1]. It handles your > situation quite nicely. > >>>> import pyparsing >>>> parser = pyparsing.ZeroOrMore('-c') >>>> parser.parseString('-c-c-c-c-c-c') > (['-c', '-c', '-c', '-c', '-c', '-c'], {}) Not that I like regexes very much, but findall does exactly that: py> re.findall('-c', '-c-c-c-c-c-c') ['-c', '-c', '-c', '-c', '-c', '-c'] Now, the OP said "return each occurrence as a group match": py> for g in re.finditer("-c", '-c-c-c-c-c-c'): print g, g.span(), g.group() ... <_sre.SRE_Match object at 0x00C096E8> (0, 2) -c <_sre.SRE_Match object at 0x00C09410> (2, 4) -c <_sre.SRE_Match object at 0x00C096E8> (4, 6) -c <_sre.SRE_Match object at 0x00C09410> (6, 8) -c <_sre.SRE_Match object at 0x00C096E8> (8, 10) -c <_sre.SRE_Match object at 0x00C09410> (10, 12) -c -- Gabriel Genellina From kochkin.dmitry at gmail.com Tue Nov 10 03:39:44 2009 From: kochkin.dmitry at gmail.com (Cooch) Date: Tue, 10 Nov 2009 00:39:44 -0800 (PST) Subject: Python as network protocol Message-ID: Hi, guys! I want to implement such specific feature: I have a server written in Python. I have a client written in C++. I want to use Python as network protocol between them. I mean: client send to server such string: "a = MyObject()", so object of this type will appear in server. Any ideas how to simplify this implementation? I make XML-RPC/SOAP server using twisted which just execute sended string. But I don't know how to: 1. Restrict usage of some modules on client side (os, sys etc..) 2. Divide variables of different clients. Generally, I know that I should use "exec .. in .. " construct, but don't know how to distinguish between clients in twisted. Dmitry. From deets at nospam.web.de Tue Nov 10 03:55:11 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Nov 2009 09:55:11 +0100 Subject: Python as network protocol In-Reply-To: References: Message-ID: <7lso3fF3fivalU1@mid.uni-berlin.de> Cooch schrieb: > Hi, guys! > > I want to implement such specific feature: > I have a server written in Python. I have a client written in C++. I > want to use Python as network protocol between them. I mean: client > send to server such string: "a = MyObject()", so object of this type > will appear in server. Any ideas how to simplify this implementation? > I make XML-RPC/SOAP server using twisted which just execute sended > string. But I don't know how to: > 1. Restrict usage of some modules on client side (os, sys etc..) > 2. Divide variables of different clients. Generally, I know that I > should use "exec .. in .. " construct, but don't know how to > distinguish between clients in twisted. This is a *really* bad idea. Because there is no real way to restrict execution in python, and thus you allow clients to inject arbitrary code into your server. Including the notorious "os.system('rm -rf /')". So - don't do that. Use e.g. CORBA if you need a richer, object-base protocol than XMLRPC. Diez From enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Nov 10 04:33:35 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 10 Nov 2009 10:33:35 +0100 Subject: how to close not response win32 IE com interface References: Message-ID: <4af93373$0$1001$ba4acef3@news.orange.fr> Hi! The only way I know is to use sendkeys. @+ Michel Claveau From wentland at cl.uni-heidelberg.de Tue Nov 10 04:54:39 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Tue, 10 Nov 2009 10:54:39 +0100 Subject: how to create a pip package In-Reply-To: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: <20091110095439.GF20601@kinakuta.local> On Mon, Nov 09, 2009 at 19:48 -0800, Phlip wrote: > I have a single file that I need my crew to pip install. Where do you plan to host this file? Will it be available on PiPy? > When I Google for "how to create a pip package" I don't hit anything. > Of course that info is out there; I can't seem to pick up the trail of > breadcrumbs to it. As has already been noted in this thread you do not create a file specifically for pip, but rather use the standard (or soon to be) way of distributing Python distributions outlined in: http://docs.python.org/library/distutils.html#module-distutils http://packages.python.org/distribute/ If you do not plan to host your "file" on pypi you can easily create a pip requirements file that references a VCS of your choice. Read how to do this in the pip documentation on "editable" packages: http://pypi.python.org/pypi/pip/ kind regards Wolodja -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From gatti at dsdata.it Tue Nov 10 05:40:52 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Tue, 10 Nov 2009 02:40:52 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On Nov 9, 9:01?pm, Simon Hibbs wrote: > The main objection to using PyQT untill now was that for commercial > development you needed to buy a license (it was free for GPL > projects). That's rapidly becoming a non-issue as the core QT > framework is now LGPL and Nokia have a project underway to produce > PyQT compatible LGPL python bindings under the PySide project. I also would like to use PySide, but unlike PyQt and Qt itself it doesn't seem likely to support Windows in the foreseeable future. A pity, to put it mildly. Regards, Lorenzo Gatti From highcar at gmail.com Tue Nov 10 06:00:41 2009 From: highcar at gmail.com (elca) Date: Tue, 10 Nov 2009 03:00:41 -0800 (PST) Subject: how to close not response win32 IE com interface In-Reply-To: <4af93373$0$1001$ba4acef3@news.orange.fr> References: <26265055.post@talk.nabble.com> <4af93373$0$1001$ba4acef3@news.orange.fr> Message-ID: <26281603.post@talk.nabble.com> Michel Claveau - MVP-2 wrote: > > Hi! > > The only way I know is to use sendkeys. > > @+ > > Michel Claveau > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello, actually this is not hang status, i mean..it slow response, so in that case, i would like to close IE and want to restart from start. so closing is no problem ,problem is ,how to set timeout ,for example if i set 15sec, if not webpage open less than 15 sec i want to close it and restart from start. is this possible to use with IE com interface? really hard to find solution Paul, -- View this message in context: http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26281603.html Sent from the Python - python-list mailing list archive at Nabble.com. From Ognjen at mailshack.com Tue Nov 10 06:32:46 2009 From: Ognjen at mailshack.com (Ognjen Bezanov) Date: Tue, 10 Nov 2009 11:32:46 +0000 Subject: Is it possible to get the Physical memory address of a variable in python? Message-ID: <4AF94F5E.8020806@mailshack.com> Hey, Thanks for all the responses guys. In hindsight I probably should have explained why on earth I'd need the physical address from an interpreted language. I'm trying to see if there is any way I can make Python share data between two hosts using DMA transfers over a firewire connection, so avoiding the need for another layer on top such as IPv4 + Python sockets. Thanks to some old python bindings which I updated to python 2.6, I can read any write to the RAM of any firewire connected host within python. Because it uses DMA (the cpu is not involved in this at all), I can only specify a physical address within the 4GB ram limit to read from and write to. Now what I've done so far is on the remote host I run python and set a variable as so: a = "foo" print a 'foo' Then on the local host I run a python script that scans the entire RAM looking for the string "foo", and replaces it with the string "oof". I have had success with this method. Once it's done and I do "print a" on the remote host, I get "oof" as the variable value, so in theory it can work. Problem is that it's slow. Scanning 3GB of RAM every time you want to do this is not a good method. I thought that if I could get python to return the physical address of where the value of a variable is, then I can just jump to that address and write the data. From what I've been told so far, it's not possible to do this without some OS-specific (Linux in this case) syscall. Is this correct? Thanks! Ognjen From mkhitrov at gmail.com Tue Nov 10 06:41:47 2009 From: mkhitrov at gmail.com (Maxim Khitrov) Date: Tue, 10 Nov 2009 06:41:47 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF94F5E.8020806@mailshack.com> References: <4AF94F5E.8020806@mailshack.com> Message-ID: <26ddd1750911100341g368f1e70mb70e491717d2cdd5@mail.gmail.com> On Tue, Nov 10, 2009 at 6:32 AM, Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an interpreted > language. > > I'm trying to see if there is any way I can make Python share data between > two hosts using DMA transfers over a firewire connection, so avoiding the > need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I can read > any write to the RAM of any firewire connected host within python. Because > it uses DMA (the cpu is not involved in this at all), I can only specify a > physical address within the 4GB ram limit to read from and write to. > > Now what I've done so far is on the remote host I run python and set a > variable as so: > > a = "foo" > print a > 'foo' > > Then on the local host I run a python script that scans the entire RAM > looking for the string "foo", and replaces it with the string "oof". I have > had success with this method. Once it's done and I do "print a" on the > remote host, I get "oof" as the variable value, so in theory it can work. > > Problem is that it's slow. Scanning 3GB of RAM every time you want to do > this is not a good method. I thought that if I could get python to return > the physical address of where the value of a variable is, then I can just > jump to that address and write the data. > > From what I've been told so far, it's not possible to do this without some > OS-specific (Linux in this case) syscall. Is this correct? > > Thanks! > > > Ognjen If all you need is a memory buffer, array.array provides a buffer_info() method that tells you the current (virtual) address. For DMA, I think there are dma_map_* functions in linux that you may be able to call through ctypes. - Max From luke.leighton at googlemail.com Tue Nov 10 07:48:03 2009 From: luke.leighton at googlemail.com (lkcl) Date: Tue, 10 Nov 2009 04:48:03 -0800 (PST) Subject: Newbie advice References: <69658d99-72de-4ad4-b4fe-315065f24dae@e34g2000vbc.googlegroups.com> Message-ID: On Oct 29, 7:00 am, alex23 wrote: > However, if you're already comfortable with HTML/CSS, I'd recommend > taking a look atPyjamas, which started as a port of the Google Web > Toolkit, taking Python code and compiling it into javascript. The > associated project,Pyjamas-Desktop, is a webkit-based desktop client/ > widget set; so ideally you only have to write one UI and it'll run > both on the web & the desktop. > > Pyjamas:http://pyjs.org/ > Pyjamas-Desktop:http://pyjd.sourceforge.net/ thank you for mentioning these, chris. the information on pyjd is slightly out-of-date. * pyjamas-desktop was merged into pyjamas as of the 0.6 release. * there are now three alternative back-ends for pyjamas-desktop, (just as there are three major web browser engines). MSHTML, xulrunner and webkit. Opera's engine cannot be included because Opera's developers have not responded to invitations to provide an engine / library to which python bindings can be added. when they have provided python bindings, a port of pyjd to use them can be done in approximately two weeks. * the webkit-based back-end is the least-recommended, due to intransigence of the webkit developer, mark rowe. mark rowe has shown consistent disrespect for free software contributions to make webkit with glib/ gobject bindings actually useful and useable, and has ensured that anyone who wishes to proceed with getting webkit its glib/gobject bindings will have an unacceptably hard time. efforts to work with the other webkit developers, which were proving successful, were deliberately destroyed by, and terminated by, mark rowe. * the MSHTML-based back-end is surprisingly the most successful of the three pyjd ports. it requires _very_ little in the way of libraries to be installed: only python-comtypes (at 250k) which is in complete contrast to the other ports, which require whopping 30mbyte installs of libraries and dependencies. * the xulrunner-based back-end is the best option for unix-based systems. the design of xulrunner's core infrastructure, XPCOM, however, is slightly ... "incomplete". it is based on DCOM, but does not provide the exact same capabilities as DCOM (no coclasses). the upshot is that current releases of xulrunner work perfectly well for _everything_ but 2D SVG Canvas "Image" loading. (i have a patch for xulrunner which fixes this one single error) so - it's a mixed and interesting bag of tricks. full and comprehensive non-javascript bindings to web technology seems to be a thoroughly misunderstood and underexploited area, with several variations on the same theme being available from several competitive sources. the nice thing about pyjamas is that just as pyjs makes all the differences "go away" when pyjamas apps are compiled to run in web browsers, pyjamas-desktop makes those differences "go away" when pyjamas apps are run as pure python on the desktop. l. From gerard.blais at gmail.com Tue Nov 10 07:57:04 2009 From: gerard.blais at gmail.com (Gerry) Date: Tue, 10 Nov 2009 04:57:04 -0800 (PST) Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: On Nov 8, 2:42?pm, Ozz wrote: > vsoler schreef: > And, of course, you'd want to take a look a this: http://xkcd.com/287/ Gerry > > > Instead of subsets, do you mean permutations/combinations? ?Since 2 > > invoices can have the same amount perhaps the terms permutation is > > better. > > As some other poster already suggested 'powerset' (http://en.wikipedia.org/wiki/Power_set) may be a better name, except > for those duplicates, of course. On the other hand, I think viewing it > as a powerset is the most 'natural' in this case. (imo permutations are > about the order of objects, not about whether the objects are included > in a set or not) > > cheers, > Ozz From philip at semanchuk.com Tue Nov 10 08:34:31 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 10 Nov 2009 08:34:31 -0500 Subject: comparing alternatives to py2exe In-Reply-To: References: <9a51a702-cd41-4252-859a-ca0c8d0a0454@k19g2000yqc.googlegroups.com> <114D704D-DFD1-4F2B-AFDB-77995EB0019C@semanchuk.com> Message-ID: On Nov 9, 2009, at 9:16 PM, Gabriel Genellina wrote: > En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk > escribi?: >> On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote: >>> >>> Recently I put together this incomplete comparison chart in an >>> attempt >>> to choose between the different alternatives to py2exe: >>> >>> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html >> >> I was interested in py2exe because we'd like to provide a one >> download, one click install experience for our Windows users. I >> think a lot of people are interested in py2exe for the same reason. >> Well, one thing that I came across in my travels was the fact that >> distutils can create MSIs. Like py2exe, MSIs provide a one >> download, one click install experience under Windows and therefore >> might be a replacement for py2exe. > > But py2exe and .msi are complementary, not a replacement. > py2exe collects in one directory (or even in one file in some cases) > all the pieces necesary to run your application. That is, Python > itself + your application code + all referenced libraries + other > required pieces. > The resulting files must be installed in the client machine; you > either build a .msi file (a database for the Microsoft Installer) or > use any other installer (like InnoSetup, the one I like). > >> For me, the following command was sufficient to create an msi, >> although it only worked under Windows (not under Linux or OS X): >> python setup.py bdist_msi >> >> The resulting MSI worked just fine in my extensive testing (read: I >> tried it on one machine). > > The resulting .msi file requires Python already installed on the > target machine, if I'm not mistaken. The whole point of py2exe is to > avoid requiring a previous Python install. You're right; the MSI I created doesn't include prerequisites. It packaged up our app, that's it. To be fair to MSIs, they might be capable of including prerequisites, the app, and the kitchen sink. But I don't think Python's creation process through distutils makes that possible. That's why I suggested MSIs belong alongside RPM/DEB in the chart (if they're to be included at all). I wouldn't say that the whole point of py2exe is to bundle Python. That's certainly a big benefit, but another benefit is that it can bundle an app into a one-click download. That's why we were interested in it. > >> It seems, then, that creating an MSI is even within the reach of >> someone like me who spends very little time in Windows-land, so it >> might be worth a column on your chart alongside rpm/deb. > > As said in http://wiki.python.org/moin/DistributionUtilities the > easiest way is to use py2exe + InnoSetup. Easiest for you. =) The list of packages and modules that might require special treatment is almost a perfect superset of the modules we're using in our application: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules py2exe looks great, but it remains to be seen if it's the easiest way to solve our problem. The MSI isn't nearly as nice for the end user, but we created it using only the Python standard library and our existing setup.py. Simplicity has value. Cheers Philip From x7-g5W_rt at earthlink.net Tue Nov 10 08:49:03 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Tue, 10 Nov 2009 05:49:03 -0800 (PST) Subject: Most efficient way to "pre-grow" a list? References: <2fb80377-c3fa-4eaf-a5de-3c1cb4d215a2@a21g2000yqc.googlegroups.com> Message-ID: <7a9c4398-c5e7-40fe-9334-fdeffe12f9a4@l13g2000yqb.googlegroups.com> On Nov 9, 10:56?pm, "Gabriel Genellina" wrote: > > [much cutting] > > def method3a(): > ? ?newArray = array.array('I', [INITIAL_VALUE]) * SIZE > ? ?assert len(newArray)==SIZE > ? ?assert newArray[SIZE-1]==INITIAL_VALUE > > [more cutting] > > So arrays are faster than lists, and in both cases one_item*N outperforms ? > your doubling algorithm. > Adding one item at a time is -at least- several hundred times slower; I ? > was not patient enough to wait. > > > Finally, I just looked into calling C functions, and found > > PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management > > section of the Python/C API Reference Manual. This gives you > > uninitialized memory, and should be really fast, but it's 6:45 AM > > here, and I don't have the energy to try it. > > No, those are for internal use only, you can't use the resulting pointer ? > in Python code. An array object is a contiguous memory block, so you don't ? > miss anything. > Gabriel, Thanks for the reply - your method 3a was what I wanted, I missed "array.array('I', [INITIAL_VALUE]) * SIZ" on my earlier pass through the Python documentation. I included the 'one at a time' method because that was my first shot at the problem - I was so happy to find a method that would get the job done today that I didn't look farther than the doubling method. Yes, I know that I was comparing lists and arrays. Part of the confusion in this thread is that the problem hasn't been defined very well. The original post asked about arrays but the solution proposed generated a list. At this point, I have learned a lot about arrays, lists and dictionaries, and will be better able to chose the right solution to future problems. It's too bad about the C functions, they sure sounded good. And with that, I think I will withdraw from the field, and go write some code and learn about timeit. Gil From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 08:59:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 13:59:56 GMT Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> Message-ID: <0309600d$0$1340$c3e8da3@news.astraweb.com> On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > What you're describing is the powerset operation. Here's the example > from the python docs: [...] > What I find interesting is that running it through timeit, it is much > slower than the code suggested by Dan Bishop. Your test doesn't show what you think it shows. You shouldn't just blindly apply timeit without testing to see that the functions return what you think they return. Your test is, I'm afraid, totally bogus and the conclusion you draw is completely wrong. [...] > #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate > timeit.timeit("subsets2(x)", setup) > timeit.timeit("subsets3(x)", setup) For the sake of speed, I've used a smaller x. Here are the results of calling the three functions: >>> x = range(3) >>> subsets1(x) [[2], [2, 0], [2, 1], [2, 1, 0], [], [0], [1], [1, 0]] >>> subsets2(x) >>> subsets3(x) The reason subsets1() "doesn't appear to terminate" is that you are trying to list all the subsets of x = range(100). That's a LOT of subsets: 2**100 to be precise, or approximately 1.2e30. subsets2() and subsets3() return a generator function and an iterator object respectively. There may be some overhead difference between those, but that's trivial compared to the cost of generating the subsets themselves. A better way of doing the timing is as follows: from itertools import chain, combinations from timeit import Timer # use a number small enough to calculate in a reasonable time x = list(range(10)) def subsets1(L): S = [] if (len(L) == 1): return [L, []] else: for s in subsets1(L[1:]): S.append(s) S.append(s + [ L[0]]) return S def subsets2(L): if L: for s in subsets2(L[1:]): yield s yield s + [L[0]] else: yield [] def subsets3(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) setup = "from __main__ import subsets1, subsets2, subsets3, x" # Check the three functions return the same results: x1 = sorted(subsets1(x)) x2 = sorted(subsets2(x)) x3 = sorted(list(t) for t in subsets1(x)) assert x1 == x2 == x3 # Set up some timers. t1 = Timer("subsets1(x)", setup) t2 = Timer("list(subsets2(x))", setup) t3 = Timer("list(subsets3(x))", setup) # And run them! for t in (t1, t2, t3): print min(t.repeat(number=1000, repeat=5)) The results I get are: 1.19647693634 0.901714801788 0.175387859344 Which as you can see, shows that the recipe in the docs is nearly ten times faster than Dan's version. That's not surprising -- the docs version uses highly optimized C code from itertools, while Dan's version uses slow-ish Python code and recursion. To show this is no fluke, I increased the size of x and ran the tests again: >>> x = list(range(15)) # 32000+ subsets >>> x1 = sorted(subsets1(x)) >>> x2 = sorted(subsets2(x)) >>> x3 = sorted(list(t) for t in subsets1(x)) >>> assert x1 == x2 == x3 >>> >>> t1 = Timer("subsets1(x)", setup) >>> t2 = Timer("list(subsets2(x))", setup) >>> t3 = Timer("list(subsets3(x))", setup) >>> for t in (t1, t2, t3): ... print min(t.repeat(number=1000, repeat=5)) ... 45.283468008 33.9274909496 7.40781188011 -- Steven From debatem1 at gmail.com Tue Nov 10 09:24:56 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 09:24:56 -0500 Subject: My own accounting python euler problem In-Reply-To: <0309600d$0$1340$c3e8da3@news.astraweb.com> References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <0309600d$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 8:59 AM, Steven D'Aprano wrote: > On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote: > >> What you're describing is the powerset operation. Here's the example >> from the python docs: > [...] >> What I find interesting is that running it through timeit, it is much >> slower than the code suggested by Dan Bishop. > > Your test doesn't show what you think it shows. You shouldn't just > blindly apply timeit without testing to see that the functions return > what you think they return. Your test is, I'm afraid, totally bogus and > the conclusion you draw is completely wrong. Doh! I even noticed that the asymptotic times didn't match up and still blew right past the obvious answer. Thanks (again) for the correction, Steven. Geremy Condra From phlip2005 at gmail.com Tue Nov 10 09:30:53 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 06:30:53 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> Message-ID: <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> On Nov 10, 1:54?am, Wolodja Wentland wrote: > http://docs.python.org/library/distutils.html#module-distutils > http://packages.python.org/distribute/ ktx... now some utterly retarded questions to prevent false starts. the distutils page starts with "from distutils.core import setup". but a sample project on github, presumably a pippable project, starts with: from setuptools import setup, find_packages (and it also has ez_setup()) I don't foresee my project growing larger than one* file any time soon. 'pip freeze' prob'ly won't write a setup.py. What is the absolute simplest setup.py to stick my project on the PYTHONPATH, and be done with it? [*but rest assured it has a developer test suite and a customer test script!] -- Phlip http://c2.com/cgi/wiki?ZeekLand From victorsubervi at gmail.com Tue Nov 10 09:37:57 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 09:37:57 -0500 Subject: Serious Privileges Problem: Please Help In-Reply-To: <4AF8CC05.8090902@ieee.org> References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> <4AF8CC05.8090902@ieee.org> Message-ID: <4dc0cfea0911100637m4712c7canebae37e6cead7698@mail.gmail.com> For others who discover this error, here's what happened as I've traced it: 1) I never before had built a python interpreter on my Windoze box. That was kind of silly, since I was uploading to my server every time I wanted to test. So I built on my Windoze box. Thereafter, Windoze assumed that all *.py files were native to its environment. That's where the little devil crept in. 2) When I went to edit my files on the server, I never saw any lines ending in "^M", the dead giveaway that Windoze has mangled the line endings. So the problem was __invisible__. Wow. What a pain in the &(%( Thanks for everyone's help! V On Mon, Nov 9, 2009 at 9:12 PM, Dave Angel wrote: > Victor Subervi wrote: > >> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi > >wrote: >> >> >> >>> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury >> >wrote: >>> >>> >>> >>>> >>>> >>> >>> >>> Hold everything. Apparently line-endings got mangled. What I don't >>> >>> >> understand is why I didn't see them when I opened the file to edit, and >> why >> they didn't copy and paste when I did that. But dos2unix cleaned up a >> couple >> of files so I presume it will clean up the rest. However, I tried one >> file, >> that reads exactly the same as index.py, and when I surfed to it got a 500 >> error. Here's what the log said: >> >> >> >> > What I've diagnosed as happening when a python script with Windows > line-ending was posted on my server's cgi environment: > > The actual error seemed to be a failure to find the python interpreter, > since some Unix shells take the shebang line to include the \r character > that preceded the newline. Seems to me they could be more tolerant, since > I don't think control characters are likely in the interpreter file name. > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reply-to at works.fine.invalid Tue Nov 10 09:59:25 2009 From: reply-to at works.fine.invalid (NickC) Date: 10 Nov 2009 14:59:25 GMT Subject: Create object from variable indirect reference? Message-ID: <00830413$0$26937$c3e8da3@news.astraweb.com> I can't seem to find a way to do something that seems straighforward, so I must have a mental block. I want to reference an object indirectly through a variable's value. Using a library that returns all sorts of information about "something", I want to provide the name of the "something" via a variable (command line argument). The something is a class in the library and I want to instantiate an object of the class so I can start querying it. I can't figure out how to pass the name of the class to the library. Or, put another way, I can't figure out how to indirectly reference the value of the command line argument to create the object. To make it clearer, it's roughly equivalent to this in bash: Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". command line: $ ./ephemeris.py Moon code: import ephem import optparse # various option parsing (left out for brevity), # so variable options.body contains string "Moon", # or even "Moon()" if that would make it easier. # Want to instantiate an object of class Moon. # Direct way: moon1 = ephem.Moon() # Indirect way from command line with a quasi bashism that obviously fails: moon2 = ephem.${!options.body}() Can someone point me in the right direction here? (The library is PyEphem, an extraordinarily useful library for anyone interested in astronomy.) Many thanks, -- NickC From Scott.Daniels at Acm.Org Tue Nov 10 10:08:03 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Nov 2009 07:08:03 -0800 Subject: Serious Privileges Problem: Please Help In-Reply-To: References: <4dc0cfea0911070613m633e5624k8bfa12a7583876ed@mail.gmail.com> <200911080928.41802.rami.chowdhury@gmail.com> <4dc0cfea0911080940u303352c0iaf3b19a659bbd6c7@mail.gmail.com> <4dc0cfea0911090944h3b767fd1j3d61c8658e8d66fc@mail.gmail.com> <4dc0cfea0911091036gdf6d974j1f45a801fb98a9a1@mail.gmail.com> <4dc0cfea0911091124j443f7b1fv3a143f230c77a79b@mail.gmail.com> <4dc0cfea0911091130v120bddbaged56c310d4fc52dd@mail.gmail.com> <4dc0cfea0911091246x6ca9cb1cj67bf248e5ad33821@mail.gmail.com> Message-ID: Dave Angel wrote: > Victor Subervi wrote: >> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi >> wrote: >>> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury >>> wrote: >>> >>> >>> Hold everything. Apparently line-endings got mangled. What I don't ... >> > What I've diagnosed as happening when a python script with Windows > line-ending was posted on my server's cgi environment: > > The actual error seemed to be a failure to find the python interpreter, > since some Unix shells take the shebang line to include the \r character > that preceded the newline. Seems to me they could be more tolerant, > since I don't think control characters are likely in the interpreter > file name. You could work around this by creating a symlink (or even hard link to the python executable named "python\r" --Scott David Daniels Scott.Daniels at Acm.Org From joncle at googlemail.com Tue Nov 10 10:08:47 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 10 Nov 2009 07:08:47 -0800 (PST) Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> On Nov 10, 2:59?pm, NickC wrote: > I can't seem to find a way to do something that seems straighforward, so I > must have a mental block. ?I want to reference an object indirectly > through a variable's value. > > Using a library that returns all sorts of information about "something", I > want to provide the name of the "something" via a variable (command line > argument). ?The something is a class in the library and I want to > instantiate an object of the class so I can start querying it. ?I can't > figure out how to pass the name of the class to the library. > > Or, put another way, I can't figure out how to indirectly reference the > value of the command line argument to create the object. > > To make it clearer, it's roughly equivalent to this in bash: > ?Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". > > command line: > $ ./ephemeris.py Moon > > code: > import ephem > import optparse > > # various option parsing (left out for brevity), > # so variable options.body contains string "Moon", > # or even "Moon()" if that would make it easier. > > # Want to instantiate an object of class Moon. > # Direct way: > moon1 = ephem.Moon() > # Indirect way from command line with a quasi bashism that obviously fails: > moon2 = ephem.${!options.body}() > > Can someone point me in the right direction here? > > (The library is PyEphem, an extraordinarily useful library for anyone > interested in astronomy.) > > Many thanks, > > -- > NickC A direct way is to use: moon1 = getattr(ephem, 'Moon')() hth Jon. From rami.chowdhury at gmail.com Tue Nov 10 10:13:54 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 10 Nov 2009 07:13:54 -0800 Subject: Create object from variable indirect reference? In-Reply-To: <00830413$0$26937$c3e8da3@news.astraweb.com> References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Nov 2009 06:59:25 -0800, NickC wrote: > I can't seem to find a way to do something that seems straighforward, so > I > must have a mental block. I want to reference an object indirectly > through a variable's value. > > Using a library that returns all sorts of information about "something", > I > want to provide the name of the "something" via a variable (command line > argument). The something is a class in the library and I want to > instantiate an object of the class so I can start querying it. I can't > figure out how to pass the name of the class to the library. > > Or, put another way, I can't figure out how to indirectly reference the > value of the command line argument to create the object. > > To make it clearer, it's roughly equivalent to this in bash: > Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". > > command line: > $ ./ephemeris.py Moon > > code: > import ephem > import optparse > > # various option parsing (left out for brevity), > # so variable options.body contains string "Moon", > # or even "Moon()" if that would make it easier. > > # Want to instantiate an object of class Moon. > # Direct way: > moon1 = ephem.Moon() > # Indirect way from command line with a quasi bashism that obviously > fails: > moon2 = ephem.${!options.body}() > > Can someone point me in the right direction here? > > (The library is PyEphem, an extraordinarily useful library for anyone > interested in astronomy.) > > Many thanks, > Since Python 'variables' are really keys in a namespace dictionary, it's fairly straightforward to get at them given a string value -- what you probably want in this case is the built-in function getattr() (http://www.diveintopython.org/power_of_introspection/getattr.html)... So getattr(ephem, "Moon") should give you the class object ephem.Moon, which you can then instantiate... -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From wentland at cl.uni-heidelberg.de Tue Nov 10 10:14:18 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Tue, 10 Nov 2009 16:14:18 +0100 Subject: how to create a pip package In-Reply-To: <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <20091110151418.GH20601@kinakuta.local> On Tue, Nov 10, 2009 at 06:30 -0800, Phlip wrote: > On Nov 10, 1:54?am, Wolodja Wentland > wrote: > > > http://docs.python.org/library/distutils.html#module-distutils > > http://packages.python.org/distribute/ > > ktx... now some utterly retarded questions to prevent false starts. > the distutils page starts with "from distutils.core import setup". [..] > from setuptools import setup, find_packages It will be enough to use the method outlined in the distutils documentation. Setuptools is a third-party library that used to be the de-facto standard for Python packaging. I don't want to go into detail why setuptools might not be the best choice for a project and leave that to [1] and [2]. The Distribute project was started in order to fix several bugs in setuptools which was essentially unmaintained for a year and provides a backward compatible fork in the 0.6 branch. kind regards Wolodja [1] http://www.b-list.org/weblog/2008/dec/14/packaging/ [2] http://blog.ianbicking.org/2008/12/14/a-few-corrections-to-on-packaging/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From fetchinson at googlemail.com Tue Nov 10 10:31:13 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 16:31:13 +0100 Subject: Python as network protocol In-Reply-To: <7lso3fF3fivalU1@mid.uni-berlin.de> References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: >> I want to implement such specific feature: >> I have a server written in Python. I have a client written in C++. I >> want to use Python as network protocol between them. I mean: client >> send to server such string: "a = MyObject()", so object of this type >> will appear in server. Any ideas how to simplify this implementation? >> I make XML-RPC/SOAP server using twisted which just execute sended >> string. But I don't know how to: >> 1. Restrict usage of some modules on client side (os, sys etc..) >> 2. Divide variables of different clients. Generally, I know that I >> should use "exec .. in .. " construct, but don't know how to >> distinguish between clients in twisted. Have you considered using pyro? http://pyro.sourceforge.net/ > This is a *really* bad idea. How do you know for sure? Maybe the OP wants to use this thing with 3 known researchers working on a cluster that is not even visible to the outside world. In such a setup the model the OP suggested is a perfectly reasonable one. I say this because I often work in such an environment and security is never an issue for us. And I find it always amusing that whenever I outline our code to a non-scientist programmer they always run away in shock and never talk to us again :) Nevertheless our code works perfectly for our purposes. > Because there is no real way to restrict > execution in python, and thus you allow clients to inject arbitrary code > into your server. Including the notorious "os.system('rm -rf /')". > > So - don't do that. Use e.g. CORBA if you need a richer, object-base > protocol than XMLRPC. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From SD_V897 at NoSuchMail.Com Tue Nov 10 10:39:46 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Tue, 10 Nov 2009 15:39:46 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: Message-ID: <6PfKm.51354$Db2.3028@edtnps83> Rhodri James wrote: > On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 wrote: > >> Rhodri James wrote: >>> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >>> wrote: >>> >>>> I have a perplexing issue, I have four users set up on a W7 >>>> computer. The program runs fine for all users except the admin user >>>> who needs it for school assignments. >>> A little more information, please. How does it not work for the admin >>> user? Is there a traceback? What do you get if you try to invoke it >>> from a command line? >>> >> >> >> Hi Rhodri, here's a dump file, don't know if this helps or not.. > > So Windows is reporting a crash, then. I'll repeat my last question in > particular; what happens when your admin user runs the program you're > trying to invoke from the command line? > Hi Rhodri, Python Command-Line works fine. Are toy recommending to invoke IDLE from there or from windows command line? Sorry I'm not to up on Python is there a command that would run IDLE from command? If I run idle.py -c -d I get idle is not defined. Thanks SD From invalid at invalid.invalid Tue Nov 10 10:46:10 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 15:46:10 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, Rhodri James wrote: > On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy wrote: > >> I believe the use of tagged pointers has been considered and so far >> rejected by the CPython developers. And no one else that I know of has >> developed a fork for that. It would seem more feasible with 64 bit >> pointers where there seem to be spare bits. But CPython will have to >> support 32 bit machines for several years. > > I've seen that mistake made twice (IBM 370 architecture (probably 360 too, > I'm too young to have used it) and ARM2/ARM3). I'd rather not see it a > third time, thank you. MacOS applications made the same mistake on the 68K. They reserved the high-end bits in a 32-bit pointer and used them to contain meta-information. After all, those bits were "extra" -- nobody could ever hope to actually address more than 4MB of memory, right? Heck, those address lines weren't even brought out of the CPU package. Guess what happened? It wasn't the decades-long global debacle that was the MS-DOS memory model, but it did cause problems when CPUs came out that implemented those address lines and RAM became cheap enough that people needed to use them. -- Grant Edwards grante Yow! Either CONFESS now or at we go to "PEOPLE'S COURT"!! visi.com From hniksic at xemacs.org Tue Nov 10 10:46:34 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 10 Nov 2009 16:46:34 +0100 Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> Message-ID: <87vdhil6w5.fsf@busola.homelinux.net> NickC writes: > moon2 = ephem.${!options.body}() moon2 = getattr(ephem, options.body)() From martin at marcher.name Tue Nov 10 10:46:45 2009 From: martin at marcher.name (Martin) Date: Tue, 10 Nov 2009 16:46:45 +0100 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> On Tue, Nov 10, 2009 at 16:31, Daniel Fetchinson wrote: >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a > perfectly reasonable one. I say this because I often work in such an > environment and security is never an issue for us. And I find it > always amusing that whenever I outline our code to a non-scientist > programmer they always run away in shock and never talk to us again :) > Nevertheless our code works perfectly for our purposes. It is a bad idea because that's exactly why we now have a spam problem. It _was_ a trusted environment once upon a time. Just check your spam messages to see why ignoring security can lead to really bad results. Do you know for sure that in say 3-5 years from now on your software isn't released into the wild and then has no security at all? regards, Martin -- 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 marco at sferacarta.com Tue Nov 10 10:56:06 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 10 Nov 2009 16:56:06 +0100 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: Grant Edwards wrote: > MacOS applications made the same mistake on the 68K. And and awful lot of the Amiga software, with the same 24/32 bit CPU. I did it too, every pointer came with 8 free bits so why not use them? > It wasn't the decades-long global debacle that was the MS-DOS > memory model, but it did cause problems when CPUs came out that > implemented those address lines and RAM became cheap enough > that people needed to use them. I suppose that's the reason many games didn't work on the 68020+ From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 10:56:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 15:56:56 GMT Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <03097b78$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using exec: >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a perfectly > reasonable one. I say this because I often work in such an environment > and security is never an issue for us. And I find it always amusing that > whenever I outline our code to a non-scientist programmer they always > run away in shock and never talk to us again You might be a great scientist, but perhaps you should pay attention to the experts on programming who tell you that this is opening a potential security hole in your system. No, it's not a "perfectly reasonable" tactic. It's a risky tactic that only works because the environment you use it in is so limited and the users so trusted. Can you guarantee that will never change? If not, then you should rethink your tactic of using exec. Besides, as a general rule, exec is around an order of magnitude slower than running code directly. If performance matters at all, you are better off to try to find an alternative to exec. > Nevertheless our code works perfectly for our purposes. Until the day that some manager decides that it would be great to make your code into a service available over the Internet, or until one of the other scientists decides that he really needs to access it from home, or somebody pastes the wrong text into the application and it blows up in your face... it's not just malice you need to be careful of, but also accidents. The history of computing is full of systems that were designed with no security because it wasn't needed, until it was needed, but it was too late by then. There's no need, or at least very little need, to put locks on the internal doors of your house, because we're not in the habit of taking internal doors and turning them into outside doors. But code designed to run inside your secure, safe network has a tendency to be re-purposed to run in insecure, unsafe networks, usually by people who have forgotten, or never knew, that they were opening up their system to code injection attacks. -- Steven From reply-to at works.fine.invalid Tue Nov 10 11:03:17 2009 From: reply-to at works.fine.invalid (NickC) Date: 10 Nov 2009 16:03:17 GMT Subject: Create object from variable indirect reference? References: <00830413$0$26937$c3e8da3@news.astraweb.com> <8c541a5b-f908-485a-b347-9f2234be6615@o10g2000yqa.googlegroups.com> Message-ID: <0083130b$0$26937$c3e8da3@news.astraweb.com> Many thanks for the replies. getattr() works great: >>> name='Moon' >>> m2 = getattr(ephem,name)() >>> m2.compute(home) >>> print ephem.localtime(m2.rise_time) 2009-11-11 01:30:36.000002 shows the moon will rise at 1:30am localtime tonight at my home location. Excellent. -- NickC From floris.bruynooghe at gmail.com Tue Nov 10 11:06:33 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Tue, 10 Nov 2009 08:06:33 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <02718583-8643-4983-a312-373a5fe3a480@j4g2000yqe.googlegroups.com> On Nov 10, 2:30?pm, Phlip wrote: > On Nov 10, 1:54?am, Wolodja Wentland > wrote: > > >http://docs.python.org/library/distutils.html#module-distutils > >http://packages.python.org/distribute/ > > ktx... now some utterly retarded questions to prevent false starts. > > the distutils page starts with "from distutils.core import setup". > > but a sample project on github, presumably a pippable project, starts > with: > > ? ? from setuptools import setup, find_packages > > (and it also has ez_setup()) > > I don't foresee my project growing larger than one* file any time > soon. 'pip freeze' prob'ly won't write a setup.py. What is the > absolute simplest setup.py to stick my project on the PYTHONPATH, and > be done with it? Do what the distutils page says, setuptools tries to extend distutils with many fancy things but if you don't need those (and that's what it sounds like) then sticking to distutils is better as you only require the python stdlib. Regards Floris From python at mrabarnett.plus.com Tue Nov 10 11:08:13 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 16:08:13 +0000 Subject: My own accounting python euler problem In-Reply-To: References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: <4AF98FED.5080500@mrabarnett.plus.com> Gerry wrote: > On Nov 8, 2:42 pm, Ozz wrote: >> vsoler schreef: >> > And, of course, you'd want to take a look a this: http://xkcd.com/287/ > I've found 2 solutions. (And I really should get back to what I was doing...) > Gerry >>> Instead of subsets, do you mean permutations/combinations? Since 2 >>> invoices can have the same amount perhaps the terms permutation is >>> better. >> As some other poster already suggested 'powerset' (http://en.wikipedia.org/wiki/Power_set) may be a better name, except >> for those duplicates, of course. On the other hand, I think viewing it >> as a powerset is the most 'natural' in this case. (imo permutations are >> about the order of objects, not about whether the objects are included >> in a set or not) >> >> cheers, >> Ozz > From mwilson at the-wire.com Tue Nov 10 11:14:24 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 10 Nov 2009 11:14:24 -0500 Subject: My own accounting python euler problem References: <4af6a0dd$0$83248$e4fe514c@news.xs4all.nl> <4af6b941$0$83242$e4fe514c@news.xs4all.nl> <4af71f11$0$83241$e4fe514c@news.xs4all.nl> Message-ID: Gerry wrote: > On Nov 8, 2:42 pm, Ozz wrote: >> vsoler schreef: >> > And, of course, you'd want to take a look a this: http://xkcd.com/287/ :) I remember that. mwilson at tecumseth:~/sandbox$ python xkcd_complete.py [1, 0, 0, 2, 0, 1] 1505 [7] 1505 Mel. From ckaynor at zindagigames.com Tue Nov 10 11:32:55 2009 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 10 Nov 2009 08:32:55 -0800 Subject: is None or == None ? In-Reply-To: References: <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Tue, Nov 10, 2009 at 7:56 AM, Marco Mariani wrote: > Grant Edwards wrote: > > MacOS applications made the same mistake on the 68K. >> > > And and awful lot of the Amiga software, with the same 24/32 bit CPU. > > I did it too, every pointer came with 8 free bits so why not use them? > > > > It wasn't the decades-long global debacle that was the MS-DOS >> memory model, but it did cause problems when CPUs came out that >> implemented those address lines and RAM became cheap enough >> that people needed to use them. >> > > I suppose that's the reason many games didn't work on the 68020+ > > > -- > http://mail.python.org/mailman/listinfo/python-list > As a note, the official specification (Ihttp:// www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf), the 64-bit pointers are required to be in canonical form for the exact reason of helping prevent these mistakes from being repeated. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Nov 10 11:46:38 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 16:46:38 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, Marco Mariani wrote: > Grant Edwards wrote: > >> MacOS applications made the same mistake on the 68K. > And and awful lot of the Amiga software, with the same 24/32 > bit CPU. > > I did it too, every pointer came with 8 free bits so why not > use them? TANSTAFB ;) I should probably add that MacOS itself used the same trick until system 7. >> It wasn't the decades-long global debacle that was the MS-DOS >> memory model, but it did cause problems when CPUs came out that >> implemented those address lines and RAM became cheap enough >> that people needed to use them. > > I suppose that's the reason many games didn't work on the 68020+ Probably. IIRC, it took a while for some vendors to come out with "32-bit clean" versions of products. http://en.wikipedia.org/wiki/Mac_OS_memory_management#32-bit_clean -- Grant Edwards grante Yow! I know how to do at SPECIAL EFFECTS!! visi.com From invalid at invalid.invalid Tue Nov 10 11:50:43 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Nov 2009 16:50:43 +0000 (UTC) Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: On 2009-11-10, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using > exec: > >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing >> with 3 known researchers working on a cluster that is not even >> visible to the outside world. And those three researchers are perfect? They've never even made a typographical error? >> In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an >> environment and security is never an issue for us. And I find >> it always amusing that whenever I outline our code to a >> non-scientist programmer they always run away in shock and >> never talk to us again > > You might be a great scientist, but perhaps you should pay > attention to the experts on programming who tell you that this > is opening a potential security hole in your system. > > No, it's not a "perfectly reasonable" tactic. It's a risky > tactic that only works because the environment you use it in > is so limited and the users so trusted. Even then it only works until a trusted user makes a mistake and types the wrong thing. A stupid mistake can do just as much damage as an evil mastermind. -- Grant Edwards grante Yow! Is this an out-take at from the "BRADY BUNCH"? visi.com From phlip2005 at gmail.com Tue Nov 10 12:14:47 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 09:14:47 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: > > ? ? from setuptools import setup, find_packages > > It will be enough to use the method outlined in the distutils > documentation. Setuptools is a third-party library that used to be the > de-facto standard for Python packaging. I don't want to go into detail > why setuptools might not be the best choice for a project... Good - thanks, all! Those were the exact details I sought to avoid... From python-url at phaseit.net Tue Nov 10 12:19:53 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 10 Nov 2009 17:19:53 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Nov 10) Message-ID: QOTW: "Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis." - Diez B. Roggisch, on ... well, personal style in problem-solving http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b Why aren't lists usable as dictionary keys? What do you mean, "hashable"? http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/ `x == None` or `x is None` -- which one is the right way? http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/ At Microsoft, they performed empirical research about common software engineering assumptions: "high test coverage is better", "write test code first", "use assertions", and others: http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/ The best way to populate a list of size N: http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/ A new variant of an old problem: I got a single check from my customer - which ones among all pending invoices did he intend to pay? http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/ How to test code that uses urllib without depending on external resources? http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/ Singletons are hard to test too: http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/ How to use Filters in the logging module: http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/ Delete items from a list that match a certain pattern: http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/ What is the correct way to port codecs.open to python 3.1? http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/ py2exe, cx_freeze, py2app: a comparison http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/ How to cancel a thread from another one: http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/ Why does "help(import)" not work? http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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 deets at nospam.web.de Tue Nov 10 12:22:32 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 10 Nov 2009 18:22:32 +0100 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> Message-ID: <7ltlqpF3e7kvsU1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >>> I want to implement such specific feature: >>> I have a server written in Python. I have a client written in C++. I >>> want to use Python as network protocol between them. I mean: client >>> send to server such string: "a = MyObject()", so object of this type >>> will appear in server. Any ideas how to simplify this implementation? >>> I make XML-RPC/SOAP server using twisted which just execute sended >>> string. But I don't know how to: >>> 1. Restrict usage of some modules on client side (os, sys etc..) >>> 2. Divide variables of different clients. Generally, I know that I >>> should use "exec .. in .. " construct, but don't know how to >>> distinguish between clients in twisted. > > Have you considered using pyro? > > http://pyro.sourceforge.net/ Have you considered that C++ doesn't support Pyro? > >> This is a *really* bad idea. > > How do you know for sure? Maybe the OP wants to use this thing with 3 > known researchers working on a cluster that is not even visible to the > outside world. In such a setup the model the OP suggested is a > perfectly reasonable one. I say this because I often work in such an > environment and security is never an issue for us. And I find it > always amusing that whenever I outline our code to a non-scientist > programmer they always run away in shock and never talk to us again :) > Nevertheless our code works perfectly for our purposes. If you read the OP message, he himself stated that he wants to lock down the interpreter. Which isn't possible. So (scientific) reasoning can tell us that his application might not run in a happy-go-lucky environment of scientific research. Additionally, there is always the option of mistakes being made involuntarily, so desigining a system that encourages these is a bad idea. And last but not least, instead of having a well-defined protocol relying on arbitrary in-process manipulation is a nightmare to maintain, and might well lead to nasty bugs, crashes or even subtler problems (think changing a global constant for all the others...) that are nearly impossible to debug. Plus the issues the others mentioned. Diez From debatem1 at gmail.com Tue Nov 10 12:28:49 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 12:28:49 -0500 Subject: Python as network protocol In-Reply-To: <03097b78$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 10:56 AM, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using > exec: > >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an environment >> and security is never an issue for us. And I find it always amusing that >> whenever I outline our code to a non-scientist programmer they always >> run away in shock and never talk to us again > > You might be a great scientist, but perhaps you should pay attention to > the experts on programming who tell you that this is opening a potential > security hole in your system. > > No, it's not a "perfectly reasonable" tactic. It's a risky tactic that > only works because the environment you use it in is so limited and the > users so trusted. Can you guarantee that will never change? If not, then > you should rethink your tactic of using exec. > > Besides, as a general rule, exec is around an order of magnitude slower > than running code directly. If performance matters at all, you are better > off to try to find an alternative to exec. > > >> Nevertheless our code works perfectly for our purposes. > > Until the day that some manager decides that it would be great to make > your code into a service available over the Internet, or until one of the > other scientists decides that he really needs to access it from home, or > somebody pastes the wrong text into the application and it blows up in > your face... it's not just malice you need to be careful of, but also > accidents. > > The history of computing is full of systems that were designed with no > security because it wasn't needed, until it was needed, but it was too > late by then. > > There's no need, or at least very little need, to put locks on the > internal doors of your house, because we're not in the habit of taking > internal doors and turning them into outside doors. But code designed to > run inside your secure, safe network has a tendency to be re-purposed to > run in insecure, unsafe networks, usually by people who have forgotten, > or never knew, that they were opening up their system to code injection > attacks. > > > > -- > Steven Steven, remember a few weeks ago when you tried to explain to me that the person who was storing windows administrative passwords using a 40 byte xor cipher with the hardcoded password might not be doing something stupid because I didn't know what their threat model was? Yeah- what you just said is what I was trying to explain then. Geremy Condra From syeberman at hotmail.com Tue Nov 10 12:44:55 2009 From: syeberman at hotmail.com (Syeberman) Date: Tue, 10 Nov 2009 09:44:55 -0800 (PST) Subject: list vs tuple for a dict key- why aren't both hashable? References: Message-ID: <34954068-e546-4a42-9521-c0b0417f56c5@b2g2000yqi.googlegroups.com> On Nov 8, 3:42?pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. > The short answer isn't entirely correct, however. Tuples are only hashable so long as their elements are all hashable. The documentation, though, doesn't properly describe this: http://docs.python.org/glossary.html#term-hashable "All of Python?s immutable built-in objects are hashable" From victorsubervi at gmail.com Tue Nov 10 12:53:03 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 12:53:03 -0500 Subject: Calendar Stuff Message-ID: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Hi; I have the following code: import calendar, datetime def cal(): ... myCal = calendar.Calendar(calendar.SUNDAY) today = datetime.date.today() day = today.day mo = today.month yr = today.year # month = myCal.monthdayscalendar(int(time.strftime("%Y")) month = myCal.monthdayscalendar(yr, mo) print 'hi' html headers are included. No matter which one of the last two lines I comment out, I never get to the point of printing 'hi'. (If I comment them both out, it does print.) What do? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Nov 10 13:47:41 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 19:47:41 +0100 Subject: Python as network protocol In-Reply-To: <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <5fa6c12e0911100746r4daecb2dub398199d2434cef9@mail.gmail.com> Message-ID: >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a >> perfectly reasonable one. I say this because I often work in such an >> environment and security is never an issue for us. And I find it >> always amusing that whenever I outline our code to a non-scientist >> programmer they always run away in shock and never talk to us again :) >> Nevertheless our code works perfectly for our purposes. > > It is a bad idea because that's exactly why we now have a spam > problem. It _was_ a trusted environment once upon a time. Just check > your spam messages to see why ignoring security can lead to really bad > results. > > Do you know for sure that in say 3-5 years from now on your software > isn't released into the wild and then has no security at all? In my case, yes, I know for sure that the software I was talking about will only be used by my colleagues (3-4 people) and will only be used on our system. Why? Because the code is completely unportable and undocumented and was made to serve one purpose alone: to just work on our clusters which are not visible from the internet. And it serves this purpose great. In case we need to share this code, release it, modify it, etc, etc, we will think about all the security issues. But not until then. The point I'm trying to make is that of course I'm aware of the risks in our approach, the environment we are working in allows for these risks. In another situation I wouldn't use this type of approach. As a programmer I decide what solution to use in which environment and I intend to not over kill. No risk environment = security holes are okay. Risky environment = secure code from day one. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From zac256 at gmail.com Tue Nov 10 13:50:33 2009 From: zac256 at gmail.com (Zac Burns) Date: Tue, 10 Nov 2009 10:50:33 -0800 Subject: Threaded import hang in cPickle.dumps Message-ID: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Using python 2.6 cPickle.dumps has an import which is causing my application to hang. (figured out by overriding builtin.__import__ with a print and seeing that this is the last line of code being run. I'm running cPickle.dumps in a thread, which leads me to believe that the first restriction here is the cause: http://docs.python.org/library/threading.html#importing-in-threaded-code What can I do about this? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From zac256 at gmail.com Tue Nov 10 13:55:25 2009 From: zac256 at gmail.com (Zac Burns) Date: Tue, 10 Nov 2009 10:55:25 -0800 Subject: Threaded import hang in cPickle.dumps In-Reply-To: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: <333edbe80911101055u271c1f94nea4ef4160b8f57ef@mail.gmail.com> Oh, I'm pickling an NotImplementedError and it's importing exceptions. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Nov 10, 2009 at 10:50 AM, Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import which is causing my application to hang. > (figured out by overriding builtin.__import__ with a print and seeing > that this is the last line of code being run. I'm running > cPickle.dumps in a thread, which leads me to believe that the first > restriction here is the cause: > http://docs.python.org/library/threading.html#importing-in-threaded-code > > What can I do about this? > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 13:55:25 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 18:55:25 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <0309a54d$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 15:46:10 +0000, Grant Edwards wrote: > On 2009-11-10, Rhodri James wrote: >> On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy >> wrote: >> >>> I believe the use of tagged pointers has been considered and so far >>> rejected by the CPython developers. And no one else that I know of has >>> developed a fork for that. It would seem more feasible with 64 bit >>> pointers where there seem to be spare bits. But CPython will have to >>> support 32 bit machines for several years. >> >> I've seen that mistake made twice (IBM 370 architecture (probably 360 >> too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see >> it a third time, thank you. > > MacOS applications made the same mistake on the 68K. They reserved the > high-end bits in a 32-bit pointer and used them to contain > meta-information. Obviously that was their mistake. They should have used the low-end bits for the metadata, instead of the more valuable high-end. High-end-is-always-better-right?-ly y'rs, -- Steven From fetchinson at googlemail.com Tue Nov 10 13:58:31 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 19:58:31 +0100 Subject: Python as network protocol In-Reply-To: <03097b78$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: >>> This is a *really* bad idea. >> >> How do you know for sure? Maybe the OP wants to use this thing with 3 >> known researchers working on a cluster that is not even visible to the >> outside world. In such a setup the model the OP suggested is a perfectly >> reasonable one. I say this because I often work in such an environment >> and security is never an issue for us. And I find it always amusing that >> whenever I outline our code to a non-scientist programmer they always >> run away in shock and never talk to us again > > You might be a great scientist, but perhaps you should pay attention to > the experts on programming who tell you that this is opening a potential > security hole in your system. Well, I'm completely aware of the potential security threats. It's not something I'm overlooking, rather, I'm taking them into account according to their real importance in our specific environment. And by the way, I'm not a great scientist :) However if the environment is such that the potential risks can not be exploited (not even in theory), because exactly 3 people have access to a machine and all of them are trustworthy and the clusters on which the code runs is not accessible from the internet, well, then the 'security hole' which would be dangerous otherwise, is risk free in this case. > No, it's not a "perfectly reasonable" tactic. I believe it is. > It's a risky tactic that > only works because the environment you use it in is so limited and the > users so trusted. Exactly! > Can you guarantee that will never change? Yes. I will simply not release the code to anyone. > If not, then you should rethink your tactic of using exec. I agree. > Besides, as a general rule, exec is around an order of magnitude slower > than running code directly. If performance matters at all, you are better > off to try to find an alternative to exec. That is a good point, thanks. If we'll have performance issues, I'll remember this. >> Nevertheless our code works perfectly for our purposes. > > Until the day that some manager decides that it would be great to make > your code into a service available over the Internet, or until one of the > other scientists decides that he really needs to access it from home, or > somebody pastes the wrong text into the application and it blows up in > your face I agree. If any of those things would occur, our software would be pretty dangerous. > ... it's not just malice you need to be careful of, but also accidents. Agreed. If we mistype something (as suggested by others), well, it's our fault. We know what will happen, if we still do it, well, it's our fault, we'll fix it. Believe it or not, so far (after about 1.5 years of operation) there were no typos that created problems. > The history of computing is full of systems that were designed with no > security because it wasn't needed, until it was needed, but it was too > late by then. > > There's no need, or at least very little need, to put locks on the > internal doors of your house, because we're not in the habit of taking > internal doors and turning them into outside doors. But code designed to > run inside your secure, safe network has a tendency to be re-purposed to > run in insecure, unsafe networks, usually by people who have forgotten, > or never knew, that they were opening up their system to code injection > attacks. On general grounds, you are right, of course. My point is that hacking can still be a fun and easy-going activity when one writes code for himself (almost) without regards to security and nasty things like that creeping in from the outside. I'm the king in my castle, although I'm fully aware of the fact that my castle might be ugly from the outside :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at mrabarnett.plus.com Tue Nov 10 14:02:04 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Nov 2009 19:02:04 +0000 Subject: Calendar Stuff In-Reply-To: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Message-ID: <4AF9B8AC.7080101@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have the following code: > > import calendar, datetime > > def cal(): > ... > myCal = calendar.Calendar(calendar.SUNDAY) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > # month = myCal.monthdayscalendar(int(time.strftime("%Y")) > month = myCal.monthdayscalendar(yr, mo) > print 'hi' > > html headers are included. No matter which one of the last two lines I > comment out, I never get to the point of printing 'hi'. (If I comment > them both out, it does print.) What do? > Read the tracebacks? The commented line will raise an exception because: 1. There's a final ')' missing. 2. You haven't imported 'time'. 3. .monthdayscalendar() requires the year and month. I don't know why you're writing 'int(time.strftime("%Y"))' because you already have the year in 'yr'. The code above works for me if I comment out the line '...'. From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 14:08:35 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 19:08:35 GMT Subject: Python as network protocol References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: <0309a863$0$1340$c3e8da3@news.astraweb.com> On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote: > Steven, remember a few weeks ago when you tried to explain to me that > the person who was storing windows administrative passwords using a 40 > byte xor cipher with the hardcoded password might not be doing something > stupid because I didn't know what their threat model was? Yeah- what you > just said is what I was trying to explain then. No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from the Evil Dimension... *wink* Seriously, I'm not sure if I knew that the person was storing Windows admin passwords at the time. If I had, I probably would have agreed with you. But using a 40 byte xor cipher to obfuscate some strings in a game is perfectly valid -- not every locked box needs to be a safe with 18 inch tempered steel walls. I can only repeat what I said to Daniel: can you guarantee that the nice safe, low-risk environment will never change? If not, then choose a more realistic threat model, and build the walls of your locked box accordingly. -- Steven From lallous at lgwm.org Tue Nov 10 14:09:54 2009 From: lallous at lgwm.org (lallous) Date: Tue, 10 Nov 2009 20:09:54 +0100 Subject: Python C api: create a new object class Message-ID: Hello I have 3 questions, hope someone can help: 1) How can I create an instance class in Python, currently I do: class empty: pass Then anytime I want that class (which I treat like a dictionary): o = empty() o.myattr = 1 etc.... Is there is a one line syntax to instantiate an instance? Any other ways than this: o = new.classobj('object', (), {}) 2) How can I, similarly, create an object "o" in C api: PyObject *o = what_to_call(....) .... PyObject_SetAttrString(o, "attrname", py_val) ... One way I found was first calling PyClass_New() (to create an empty class) and then passing the return value to PyInstance_NewRaw to get a new instance of that empty class. Can I achieve the same otherwise? 3) Given a PyObject* is there is a way to tell if one can call PyObject_SetAttrString() on that object w/o getting an error? For example, before calling a PyObject* one can see if it is callable, but can I test if an object supports setattr? (from C api) Thank you, Elias From steve at REMOVE-THIS-cybersource.com.au Tue Nov 10 14:11:07 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Nov 2009 19:11:07 GMT Subject: advice needed for lazy evaluation mechanism References: Message-ID: <0309a8fa$0$1340$c3e8da3@news.astraweb.com> On Sun, 08 Nov 2009 14:41:27 -0800, markolopa wrote: > Hi, > > Could you please give me some advice on the piece of code I am writing? > > My system has several possible outputs, some of them are not always > needed. I started to get confused with the code flow conditions needed > to avoid doing unnecessary work. How many dozens of man-hours (yours, and the people who have to maintain the software after you have moved on) of confusion are you going to spend to avoid how many microseconds of execution time? So what if your system takes 35ms instead of 18ms to calculate the result? As Tony Hoare famously said: "We should forget about the small efficiencies, say about 97% of the time: Premature optimization is the root of all evil." Of course, all of this assumes that the routines you are trying to avoid calling don't require hours of running time each time you call them... > So I am trying to restructure it using lazy evaluation. Oh great, avoiding confusion with something even more confusing. > - Is there a more standard (pythonic) way to do what I am trying to do? Yes. Avoid it. Do the simplest thing that works until you *know* -- because you have profiled it -- that it is too slow. Until then, all that complication you've built, all that over-engineered jungle of classes and abstract classes, is unnecessary. I find it beyond all credibility that your data is so complicated that you need a plug-in system just to manage the methods you need to calculate your data. Just create some properties, like this one: class Example(object): def __init__(self, birth_year): self.birth_year = birth_year @property def age(self): return 2009 - self.birth_year # FIXME -- it won't be 2009 forever And there you have a lazily-evaluated age property. Not complicated enough? The 3ms it takes to calculate the age is too long? Cache it! class Example(object): def __init__(self, birth_year): self.birth_year = birth_year self._age = None @property def age(self): a = self._age if a is None: a = 2009 - self.birth_year self._age = a return a Now all you need is to invalidate the cache if the birth_year changes. So you make birth_year a property too: class Example(object): def __init__(self, birth_year): self.birth_year = birth_year @property def birth_year(self): return self._birth_year @property.setter # Requires Python 2.6. Also untested. def birth_year(self, year): self._birth_year = year self._age = None @property def age(self): a = self._age if a is None: a = 2009 - self.birth_year self._age = a return a > Are there libraries, design patterns, functional programming structures > to use to achieve what I am looking for (i.e. am I trying to reinvent > the wheel)? The most important buzzwords you want are YAGNI and Premature Generalisation, and perhaps a touch of Architecture Astronaut: http://www.joelonsoftware.com/items/2008/05/01.html > - Is the coding style good? > - Can I avoid the eval command in Repository.add_routine? What I want > there is to be able to have a generic code for the repository which does > not depend on the files containing the routines I want it to hold. You mean the exec? cmd = "from %s import %s\nroutine = %s()" % (file_name, class_name, class_name) exec(cmd) # XXX: ugly Yes. Untested: module = __import__(filename) class_object = getattr(module, class_name) routine = class_object() Of course you can turn that into a one-liner: routine = getattr(__import__(filename), class_name)() -- Steven From rt8396 at gmail.com Tue Nov 10 14:23:35 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 11:23:35 -0800 (PST) Subject: New syntax for blocks Message-ID: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Forgive me if i don't properly explain the problem but i think the following syntax would be quite beneficial to replace some redundant "if's" in python code. if something_that_returns_value() as value: #do something with value # Which can replace the following syntactical construct... value = something_that_returns_value() if value: #do something with value i dunno, just seems to make good sense. You save one line of code but more importantly one indention level. However i have no idea how much trouble the implementation would be? Now i know you could write a function and do the following to forgo the indention... value = something_that_returns_value() if not value: return #do something with value ....but that's even uglier and i would like the construct to work in both sinlge 'ifs' and also conditional's Now some might say...Whats the big deal, you only save one line of code?...True, but if you can save one line of code 100 or 1000 times how many lines of code is that my inquisitive friend? ;-) From jim.valenza at gmail.com Tue Nov 10 14:33:16 2009 From: jim.valenza at gmail.com (Jim Valenza) Date: Tue, 10 Nov 2009 13:33:16 -0600 Subject: New to Python need on advice on this script Message-ID: <12ef9e020911101133rc28b7cbld19621ee0f667c89@mail.gmail.com> Hello all - I'm new to the world of Python as I am a GIS guy who would like to broaden his horizons. I have a question about a script that we've been working on: The purpose of the code is to *Syncronize SDE DropBox with Regulatory Project working files. I am looking for where the script dumps the domain list to a table and loops through the table? Is It necessary? Seems like you should be able to simply loop through the domain list. I was just trying to see if there was a more straitforward way. Thanks The script is as follows:* ** # Create the Geoprocessor import sys, string, os, arcgisscripting, shutil, time gp = arcgisscripting.create() # Jim V testing # Allow output to overwrite gp.OverwriteOutput = 1 gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data Management Tools.tbx") #---create a logging file named "YYYYMMDD HH_MM_QualityControlLog.txt" theTime = time.strftime('%Y%m%d %H_%M') #logfilename = "H:\\Development\\Python\\" + theTime + "_PODsQAQCLog.txt" logfilename = "L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\" + theTime + "_PODsQAQCLog.txt" log = open(logfilename,'w') log.write(time.ctime() + "\n") print time.ctime() THE_WORKSPACE = os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin") + "\\" #REAL MODE LINE #THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\" #TEST MODE LINE log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n") print "THE_WORKSPACE IS " + THE_WORKSPACE P_CODE = "P_CODE" #Create table of valid P_CODEs and convert to List gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb", \ "regulatory_p_code", r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table", \ "pcode", "pdesc", "") #searchRows = gp.searchCursor(r"H:\Development\temp\test.mdb\code_table") searchRows = gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table") searchRow = searchRows.next() domainList = [] while searchRow: domainList.append(searchRow.pcode) searchRow = searchRows.next() #print domainList try: #Get Workspaces from text file #for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE for line in open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QAQC_Scripts/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE #for line in open("H:/Development/testdata/workspaces.txt", 'r'): #TEST MODE LINE if not line: break line = line.strip() if not line.startswith("#"): # skip lines that start with # ws, P = line.split("RMP_2_5_",1) #parse line to get path and P_CODE log.write(" " + "\n") log.write(" " + "\n") log.write(P + "\n") print " " print P src = THE_WORKSPACE + line #defines each workspace path #If the Geodatabase exists, perform the operations if os.path.exists(src): #Archive Geodatabase before running script log.write("The Geodatabase exists " + src + "\n") print "The Geodatabase exists " + src archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" + "RMP_2_5_" + P log.write("archiveFolder is " + archiveFolder + "\n") print "archiveFolder is " + archiveFolder shutil.copy(src, archiveFolder) #Archive the Geodatabase #Set workspace and variables gp.workspace = src log.write(gp.workspace + "\n") print gp.workspace P_Value = (P.strip(".mdb")) #Valitate P_Code value against Domain list if P_Value in domainList: log.write("P_Code is valid: " + P_Value + "\n") print "P_Code is valid: " + P_Value # List all feature classes in feature datasets fdss = gp.ListDatasets("","") fds = fdss.Next() while fds: fcs = gp.ListFeatureClasses("*","",fds) fc = fcs.Next() while fc: gp.CalculateField_management(fc, P_CODE, "'" + P_Value + "'", "PYTHON") #Calc P_Code gp.RepairGeometry(fc, r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\outy.shp") fc = fcs.Next() print fc fds = fdss.Next() #Copy the Geodatabase to the SDE InBox sdeInbox = "S:/Production/DropBox/InBox" #REAL MODE LINE #sdeInbox = "H:/Development/testInbox" #TEST MODE LINE log.write("sdeInbox is " + sdeInbox + "\n") print "sdeInbox is " + sdeInbox shutil.copy(src, sdeInbox) #Copy Geodatabase to SDE Inbox else: log.write("P_Code is NOT valid: " + P_Value + "\n") print "P_Code is NOT valid: " + P_Value else: log.write("The Geodatabase does not exist " + src + "\n") print "The Geodatabase does not exist " + src except: # If an error occurred, print the messages returned by the tool log.write(gp.GetMessages() + "\n") print gp.GetMessages() log.write(time.ctime() + "\n") log.write("FINISHED" + "\n") os.startfile("L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\") log.close() print "FINISHED" print time.ctime() -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Tue Nov 10 14:56:17 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 10 Nov 2009 14:56:17 -0500 Subject: Is it possible to get the Physical memory address of a variable in python? In-Reply-To: <4AF94F5E.8020806@mailshack.com> References: <4AF94F5E.8020806@mailshack.com> Message-ID: <4AF9C561.1080403@ieee.org> Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an > interpreted language. > > I'm trying to see if there is any way I can make Python share data > between two hosts using DMA transfers over a firewire connection, so > avoiding the need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I > can read any write to the RAM of any firewire connected host within > python. Because it uses DMA (the cpu is not involved in this at all), > I can only specify a physical address within the 4GB ram limit to read > from and write to. > > Now what I've done so far is on the remote host I run python and set a > variable as so: > > a = "foo" > print a > 'foo' > > Then on the local host I run a python script that scans the entire RAM > looking for the string "foo", and replaces it with the string "oof". I > have had success with this method. Once it's done and I do "print a" > on the remote host, I get "oof" as the variable value, so in theory it > can work. > > Problem is that it's slow. Scanning 3GB of RAM every time you want to > do this is not a good method. I thought that if I could get python to > return the physical address of where the value of a variable is, then > I can just jump to that address and write the data. > > From what I've been told so far, it's not possible to do this without > some OS-specific (Linux in this case) syscall. Is this correct? > > Thanks! > > > Ognjen > > I'm sure you realize that scanning for a 3 byte tag is not only slow, but very dangerous. It could easily have been three other bytes which just happened to match this string. And those bytes could have been part of a disk directory entry (result disk corruption) or some other application. Further, between the time you did the search and the time when you updated, the relevant bytes could have been swapped to disk, and something else put in the same physical address. Anyway, I've been assuming all along that you meant address in the sense that a C program uses it, which is a linear address. But as long as you're running on an OS that has virtual memory running, there's another translation going on invisibly to the application, which converts linear to physical. So even after you get a memory address, you need to convince the OS to lock such memory in place for awhile, and then tell you where (physical address) it locked it. Note also that if a range of addresses spans a 4k boundary (for Intel architecture), it's possible that the physical addresses are not even contiguous. But the system calls from Windows (and presumably also from Linux) can hide that from you, via double-buffering. DaveA From victorsubervi at gmail.com Tue Nov 10 14:58:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 10 Nov 2009 14:58:43 -0500 Subject: Calendar Stuff In-Reply-To: <4AF9B8AC.7080101@mrabarnett.plus.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> <4AF9B8AC.7080101@mrabarnett.plus.com> Message-ID: <4dc0cfea0911101158q3f91879enfdb7717e2012f2f@mail.gmail.com> On Tue, Nov 10, 2009 at 2:02 PM, MRAB wrote: > Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> import calendar, datetime >> >> def cal(): >> ... >> myCal = calendar.Calendar(calendar.SUNDAY) >> today = datetime.date.today() >> day = today.day >> mo = today.month >> yr = today.year >> # month = myCal.monthdayscalendar(int(time.strftime("%Y")) >> month = myCal.monthdayscalendar(yr, mo) >> print 'hi' >> >> html headers are included. No matter which one of the last two lines I >> comment out, I never get to the point of printing 'hi'. (If I comment them >> both out, it does print.) What do? >> >> Read the tracebacks? > > The commented line will raise an exception because: > > 1. There's a final ')' missing. > > 2. You haven't imported 'time'. > > 3. .monthdayscalendar() requires the year and month. > > I don't know why you're writing 'int(time.strftime("%Y"))' because you > already have the year in 'yr'. > > The code above works for me if I comment out the line '...'. > -- > It works fine for me in the python interpreter but not in the page from which it's called! You say import time, but where do I call time in my script? Here's the code (abbreviated just to print something out to see it work), please advise if you can: #!/usr/bin/python import string import sys,os sys.path.append(os.getcwd()) import calendar, datetime, time import MySQLdb import string, re from login import login def calendarPrint(): print "Content-Type: text/html" print print """ NR Electric The slash must appear directly before the 'script' > """ > myCal = calendar.Calendar(calendar.SUNDAY) > today = datetime.date.today() > day = today.day > mo = today.month > yr = today.year > month = myCal.monthdayscalendar(yr, mo) > print month > > calendarPrint() > > I haven't tried to upload it to a server. But running it locally, then taking the output and feeding it to Firefox, I see a few things wrong. It's declared asw HTML, but you don't have a opening tag. And you're missing closing tags for /body and /html Tidy complains that the DOCTYPE url is malformed, but you couldn't prove it by me. And month is a list of lists, so I don't know why you're printing it. DaveA From phlip2005 at gmail.com Tue Nov 10 16:09:57 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 13:09:57 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> Message-ID: <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> except... will pip pull from a simple GitHub repo? or do I need to package something up and put it in a pythonic repository somewhere? From aahz at pythoncraft.com Tue Nov 10 16:19:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 13:19:59 -0800 Subject: module imports and st_mtime References: Message-ID: In article , tow wrote: > >Does anyone have any ideas what might be going on, or where further to >look? I'm at a bit of a loss. Try asking on pythonmac-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From VBoycheva at jonesedmunds.com Tue Nov 10 16:21:18 2009 From: VBoycheva at jonesedmunds.com (Valentina Boycheva) Date: Tue, 10 Nov 2009 16:21:18 -0500 Subject: New to Python need on advice on this script References: <12ef9e020911101133rc28b7cbld19621ee0f667c89@mail.gmail.com> Message-ID: <82347ACEFB791E479B7E9C20F3567217026E29A3@mailje08.jea.net> Jim, In Python 2.5 under ArcMap 9.3 domains can be only listed. To get to the domain values, they need to be converted to tables. Also, the default value cannot be obtained from the existing GP API. Very annoying! The workaround is to use VBA ArcObjects or connect to the database directly, if possible, and extract the information from the GDB. This latter will work for PGDB, not sure about FGDB. Regards, Valentina Boycheva From: Jim Valenza [mailto:jim.valenza at gmail.com] Sent: Tuesday, November 10, 2009 2:33 PM To: python-list at python.org Subject: New to Python need on advice on this script Hello all - I'm new to the world of Python as I am a GIS guy who would like to broaden his horizons. I have a question about a script that we've been working on: The purpose of the code is to Syncronize SDE DropBox with Regulatory Project working files. I am looking for where the script dumps the domain list to a table and loops through the table? Is It necessary? Seems like you should be able to simply loop through the domain list. I was just trying to see if there was a more straitforward way. Thanks The script is as follows: # Create the Geoprocessor import sys, string, os, arcgisscripting, shutil, time gp = arcgisscripting.create() # Jim V testing # Allow output to overwrite gp.OverwriteOutput = 1 gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data Management Tools.tbx") #---create a logging file named "YYYYMMDD HH_MM_QualityControlLog.txt" theTime = time.strftime('%Y%m%d %H_%M') #logfilename = "H:\\Development\\Python\\" + theTime + "_PODsQAQCLog.txt" logfilename = "L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\ QAQC_Scripts\\" + theTime + "_PODsQAQCLog.txt" log = open(logfilename,'w') log.write(time.ctime() + "\n") print time.ctime() THE_WORKSPACE = os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin ") + "\\" #REAL MODE LINE #THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\" #TEST MODE LINE log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n") print "THE_WORKSPACE IS " + THE_WORKSPACE P_CODE = "P_CODE" #Create table of valid P_CODEs and convert to List gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder _River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb", \ "regulatory_p_code", r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_S cripts\test.mdb\code_table", \ "pcode", "pdesc", "") #searchRows = gp.searchCursor(r"H:\Development\temp\test.mdb\code_table") searchRows = gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin \Pipeline\QAQC_Scripts\test.mdb\code_table") searchRow = searchRows.next() domainList = [] while searchRow: domainList.append(searchRow.pcode) searchRow = searchRows.next() #print domainList try: #Get Workspaces from text file #for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE for line in open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QA QC_Scripts/PRB_POD_Paths.txt", 'r'): #REAL MODE LINE #for line in open("H:/Development/testdata/workspaces.txt", 'r'): #TEST MODE LINE if not line: break line = line.strip() if not line.startswith("#"): # skip lines that start with # ws, P = line.split("RMP_2_5_",1) #parse line to get path and P_CODE log.write(" " + "\n") log.write(" " + "\n") log.write(P + "\n") print " " print P src = THE_WORKSPACE + line #defines each workspace path #If the Geodatabase exists, perform the operations if os.path.exists(src): #Archive Geodatabase before running script log.write("The Geodatabase exists " + src + "\n") print "The Geodatabase exists " + src archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" + "RMP_2_5_" + P log.write("archiveFolder is " + archiveFolder + "\n") print "archiveFolder is " + archiveFolder shutil.copy(src, archiveFolder) #Archive the Geodatabase #Set workspace and variables gp.workspace = src log.write(gp.workspace + "\n") print gp.workspace P_Value = (P.strip(".mdb")) #Valitate P_Code value against Domain list if P_Value in domainList: log.write("P_Code is valid: " + P_Value + "\n") print "P_Code is valid: " + P_Value # List all feature classes in feature datasets fdss = gp.ListDatasets("","") fds = fdss.Next() while fds: fcs = gp.ListFeatureClasses("*","",fds) fc = fcs.Next() while fc: gp.CalculateField_management(fc, P_CODE, "'" + P_Value + "'", "PYTHON") #Calc P_Code gp.RepairGeometry(fc, r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_S cripts\outy.shp") fc = fcs.Next() print fc fds = fdss.Next() #Copy the Geodatabase to the SDE InBox sdeInbox = "S:/Production/DropBox/InBox" #REAL MODE LINE #sdeInbox = "H:/Development/testInbox" #TEST MODE LINE log.write("sdeInbox is " + sdeInbox + "\n") print "sdeInbox is " + sdeInbox shutil.copy(src, sdeInbox) #Copy Geodatabase to SDE Inbox else: log.write("P_Code is NOT valid: " + P_Value + "\n") print "P_Code is NOT valid: " + P_Value else: log.write("The Geodatabase does not exist " + src + "\n") print "The Geodatabase does not exist " + src except: # If an error occurred, print the messages returned by the tool log.write(gp.GetMessages() + "\n") print gp.GetMessages() log.write(time.ctime() + "\n") log.write("FINISHED" + "\n") os.startfile("L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basi n\\Pipeline\\QAQC_Scripts\\") log.close() print "FINISHED" print time.ctime() -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Nov 10 16:27:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 10 Nov 2009 22:27:19 +0100 Subject: Python as network protocol In-Reply-To: <7ltv3aF3ftjjpU1@mid.uni-berlin.de> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <7ltv3aF3ftjjpU1@mid.uni-berlin.de> Message-ID: >> My point is that hacking can still be a fun and easy-going activity >> when one writes code for himself (almost) without regards to security >> and nasty things like that creeping in from the outside. I'm the king >> in my castle, although I'm fully aware of the fact that my castle >> might be ugly from the outside :) > > Which is a relevant statement in the context of the OP seeking advice on > *secure ways* of executing code in a restricted environment in exactly > what way? Okay, I reread the original message and you are right, the OP did want restricted scope, so probably his environment is not completely risk free. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Tue Nov 10 16:33:51 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 10 Nov 2009 16:33:51 -0500 Subject: Can't Write File In-Reply-To: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> Message-ID: <4AF9DC3F.7020505@ieee.org> Victor Subervi wrote: > Hi; > I've determined the problem in a script is I can't open a file to write it: > script = open(getpic, "w") # where getpic is already defined > Here are the permissions: > -rwxr-xr-x 1 root root 4649 Nov 10 12:31 start.py > What am I doing wrong? > TIA, > Victor > > Wrong? 1) you don't specify the environment, python version, OS, etc. 2) you don't show the error traceback 3) you don't indicate the value of getpic at the time this statement executes 4) you don't indicate what the current working directory is, os.getcwd() 5) you don't indicate what directory the start.py is located in 6) you don't indicate which user is executing this script (only root can write to it) 7) you don't tell what the filename of the script is, specif. if it's called start.py 8) you don't say what happens if you do an open(getpic, "r"), or os.path.isfile(getpic) By the time you answer each of those questions, you may notice the answer to your own question. DaveA From ethan at stoneleaf.us Tue Nov 10 16:40:17 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Nov 2009 13:40:17 -0800 Subject: Python as network protocol In-Reply-To: References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> Message-ID: <4AF9DDC1.4010901@stoneleaf.us> Daniel Fetchinson wrote: > I'm the king in my castle, although I'm fully aware of the fact that my castle > might be ugly from the outside :) +1 QOTW From ethan at stoneleaf.us Tue Nov 10 16:43:02 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 10 Nov 2009 13:43:02 -0800 Subject: Python as network protocol In-Reply-To: <0309a863$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <0309a863$0$1340$c3e8da3@news.astraweb.com> Message-ID: <4AF9DE66.5010301@stoneleaf.us> Steven D'Aprano wrote: > I can only repeat what I said to Daniel: can you guarantee that the nice > safe, low-risk environment will never change? If not, then choose a more > realistic threat model, and build the walls of your locked box > accordingly. Seems to me you can't really *guarentee* anything, especially something as elusive as the distant future. Program for what your needs are, and document accordingly. ~Ethan~ From claird.visiprise at gmail.com Tue Nov 10 16:56:50 2009 From: claird.visiprise at gmail.com (Cameron Laird) Date: Tue, 10 Nov 2009 13:56:50 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Nov 10) Message-ID: <05645648-fe4e-4554-8087-e2ccd5f879e2@s15g2000yqs.googlegroups.com> QOTW: "Don't get me wrong - innovation often comes from scratching ones personal itch. But you seem to be suffering from a rather bad case of neurodermatitis." - Diez B. Roggisch, on ... well, personal style in problem-solving http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b [It's actually Gabriel Genellina who wrote these entries.] Why aren't lists usable as dictionary keys? What do you mean, "hashable"? http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/ `x == None` or `x is None` -- which one is the right way? http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/ At Microsoft, they performed empirical research about common software engineering assumptions: "high test coverage is better", "write test code first", "use assertions", and others: http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/ The best way to populate a list of size N: http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/ A new variant of an old problem: I got a single check from my customer - which ones among all pending invoices did he intend to pay? http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/ How to test code that uses urllib without depending on external resources? http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/ Singletons are hard to test too: http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/ How to use Filters in the logging module: http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/ Delete items from a list that match a certain pattern: http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/ What is the correct way to port codecs.open to python 3.1? http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/ py2exe, cx_freeze, py2app: a comparison http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/ How to cancel a thread from another one: http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/ Why does "help(import)" not work? http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/ ======================================================================== 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 enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: 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/ 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.com p.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 Enjoy the *Python Magazine*. http://pymag.phparch.com/ *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.p ython.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 rt8396 at gmail.com Tue Nov 10 16:59:24 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 13:59:24 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> Message-ID: <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> On Nov 10, 2:08?pm, Robert Latest wrote: (..snip..) > Also it's not the "if" that is (if at all) redundant here but the assignment. Not exactly. The assignment happens only once just as the boolean check of "if " happens once. The redundancy is in validating the existence of a truthful value contained in a variable after assignment of a value to that same variable. It's like putting on your tennis shoes and then asking yourself 'am i wearing tennis shoes?'. Of course we all know *why* we must verify the existence of value afterward and the shoe analogy doesn't translate 1:1 to programming. It's more like... shoes = grab_a_pair_of_shoes_or_none_and_apply_to_feet() if shoes: shoes.this() shoes.that() Now did we find a pair of shoes or did we fail because the lights were out and all we accomplished was to toil around in the closet for half an hour bumping our head before finally giving up and returning empty handed? Just thinking out loud here...what if variable assignments could return a value... hmmm? Not to them selfs of course but to a caller, like an if statement... if a=openfile: # do something with a (if(a.__eq__(openfile))) Python would need to stuff the value of openfile into "a", then add the variable "a" to the proper namespace, then evaluate if "a" is True. This would read more naturally than even my first postulation. I bet it would confuse the crap out of noobies though! So basically with the new syntax what your saying is this: if the value of this expression bools to False, toss it away because i don't need it, else assign the value to a local variable and run the block. Basically your encaspulating an if..else block in one line of code. From aahz at pythoncraft.com Tue Nov 10 17:02:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 14:02:52 -0800 Subject: can i configure IDLE to use python 3.2 on fedora? References: Message-ID: In article , Robert P. J. Day wrote: > > on fedora 11 system, there is no python 3 package so i downloaded >and manually installed (svn checkout) python pre-3.2 in >/usr/local/bin. works fine, but if i install the python-tools >package, "idle" that comes with it is hard-coded(?) to still refer to >the officially-installed python-2.6. i see no way to configure idle >to use the "python3" executable instead. Just find your python3 IDLE, I think it's in Tools/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From simon.hibbs at gmail.com Tue Nov 10 17:08:14 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 10 Nov 2009 14:08:14 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On 10 Nov, 10:40, Lorenzo Gatti wrote: > I also would like to use PySide, but unlike PyQt and Qt itself it > doesn't seem likely to support Windows in the foreseeable future. A > pity, to put it mildly. It's not been ruled out. They don't officialy support the Mac either, but according to posts on the mailing list a independent developer has got it working in MacOS X at some level. Since QT runs on Windows, porting to the Windows version of QT shouldn't be hard. PySide is for the future, not the present, but it gives me a lot more confidence in using and recomending PyQT to know that there is so much work being put in to make sure it has a great future. Simon Hibbs From martin at v.loewis.de Tue Nov 10 17:08:33 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Nov 2009 23:08:33 +0100 Subject: DHT for Python 3.x? In-Reply-To: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: <4AF9E461.1030902@v.loewis.de> Salim Fadhley wrote: > There are plenty of good DHT projects for Python 2.x, however from > what I can tell none of them have made the jump to 3.x yet. > > I'm really keen to support Python 3.x for a project I'm working on. I > know that many developers (correctly) consider switching to Python 3 > foolish since it is less supported at the moment, but nevertheless I > am keen to carry on. > > So can somebody recommend me a working implementation of a DHT which > will work on Python 3.x and preferably Python 2.6 as well. I can't. But I recommend to port the library that you like most to 3.x, and provide any necessary changes to the author. Regards, Martin From martin at v.loewis.de Tue Nov 10 17:17:27 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Nov 2009 23:17:27 +0100 Subject: Python C api: create a new object class In-Reply-To: References: Message-ID: <4AF9E677.9050502@v.loewis.de> > How can I create an instance class in Python, currently I do: > > class empty: > pass > > Then anytime I want that class (which I treat like a dictionary): > > o = empty() > o.myattr = 1 > etc.... > > Is there is a one line syntax to instantiate an instance? > > Any other ways than this: > o = new.classobj('object', (), {}) Most certainly: o = empty(1) # or: o = empty(1, etc) This requires you to define class empty: def __init__(self, myattr, etc): self.myattr = myattr etc > 2) > > How can I, similarly, create an object "o" in C api: > > PyObject *o = what_to_call(....) o = PyObject_CallFunction(pointer_to_class_object, "") > 3) > > Given a PyObject* is there is a way to tell if one can call > PyObject_SetAttrString() on that object w/o getting an error? > > For example, before calling a PyObject* one can see if it is callable, > but can I test if an object supports setattr? > > (from C api) You could check whether the object supports setattr at all, but that would be pretty useless, since most objects do. What you want to test (would it support setting "myattr" to the specific value, at this point) is impossible to test: the object may give you an exception on every third call only (or only if the value is not an integer, etc). So just call SetAttr, and clear any exception you get that you don't want to get. Regards, Martin From benjamin at python.org Tue Nov 10 17:20:15 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Nov 2009 22:20:15 +0000 (UTC) Subject: Python C api: create a new object class References: Message-ID: lallous lgwm.org> writes: > Is there is a one line syntax to instantiate an instance? You can't instantiate an instance; it's already instantiated. > > Any other ways than this: > o = new.classobj('object', (), {}) class x: pass > How can I, similarly, create an object "o" in C api: Use PyObject_CallFunction(PyType_Type, [arguments]) > Given a PyObject* is there is a way to tell if one can call > PyObject_SetAttrString() on that object w/o getting an error? No. From benjamin at python.org Tue Nov 10 17:27:17 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 10 Nov 2009 22:27:17 +0000 (UTC) Subject: Threaded import hang in cPickle.dumps References: <333edbe80911101050y127d7c78l56ec1bf556d490c3@mail.gmail.com> Message-ID: Zac Burns gmail.com> writes: > What can I do about this? Not run it in a thread. From ben+python at benfinney.id.au Tue Nov 10 17:45:59 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Nov 2009 09:45:59 +1100 Subject: on "Namespaces" References: <7210ab54-d22d-421b-a14e-4af52fc40088@m35g2000vbi.googlegroups.com> Message-ID: <87my2u0ziw.fsf@benfinney.id.au> Steven D'Aprano writes: > Modules are namespaces. So are packages. > > Classes and class instances are namespaces. > > Even function scopes are namespaces. Steven implies it with his wording, but to make it explicit: When you have a module, package, class, or instance-of-a-class object, those objects are themselves namespaces. That is, the name used to refer to the object can be a component in a namespace reference:: import foo_package import bar_module class Parrot(object): widget = object() parrot = Parrot() # Use a package as a namespace. foo_package.spam_module.frobnicate() # Use a module as a namespace. bar_module.spangulate() # Use a class as a namespace. print Parrot.widget # Use an arbitrary instance as a namespace. parrot.state = "Restin'" When you have a function object, the ?function scope? is not available in this way: you can't access the ?inside? of the function from the outside via the function object. (The function object, like any other object, has a namespace, but that's not the *function scope* namespace.) > When you write: > > > n = None > > def spam(n): > print "spam" * n > > def ham(n): > print "ham" * n > > the n inside spam() and ham() and the global n are in different > namespaces, and so independent. Right. And neither of them is available from outside those functions (since the reference only exists while the function is executing). -- \ ?Roll dice!? ?Why?? ?Shut up! I don't need your fucking | `\ *input*, I need you to roll dice!? ?Luke Crane, demonstrating | _o__) his refined approach to play testing, 2009 | Ben Finney From sjmachin at lexicon.net Tue Nov 10 17:46:49 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Nov 2009 14:46:49 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: <2f951ad3-df8c-44ec-ac27-e9a9395d722c@x6g2000prc.googlegroups.com> On Nov 8, 8:39?am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the $200 > and $100. In other words, there is more than one solution to the > problem. The problems that you mention are only a SUBSET of the total problem. Example: oustanding invoices are for 300, 200, and 100 and the cheque is for 450 -- in general the total of the cheque amounts does not equal the total of any possible selection of outstanding invoice amounts. I would be very surprised if a real accounting department did not already have a set of business rules for dealing with a problem that has existed since invoices and cheques were invented. I would be extremely surprised if a real accounting department could be persuaded to imagine a subset of their unpaid/underpaid/overpaid invoice problem as being an instance of the (extended) knapsack problem :-) From sjmachin at lexicon.net Tue Nov 10 17:59:13 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 10 Nov 2009 14:59:13 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: On Nov 8, 8:39?am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > My second question is: > 2. this time there are also credit notes outstanding, that is, > invoices with negative amounts. For example, ?I=[500, 400, -100, 450, > 200, 600, -200, 700] and a check Ch=600 How can a credit note be "outstanding"? The accounting department issues a credit note without recording what invoice it relates to? From wentland at cl.uni-heidelberg.de Tue Nov 10 18:11:57 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Wed, 11 Nov 2009 00:11:57 +0100 Subject: how to create a pip package In-Reply-To: <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <20091110231157.GA672@kinakuta.local> On Tue, Nov 10, 2009 at 13:09 -0800, Phlip wrote: > will pip pull from a simple GitHub repo? or do I need to package > something up and put it in a pythonic repository somewhere? I don't quite understand, but would say: both ;-) You can't tell pip to pull from arbitrary git repositories, but only from those that contain the packaging code as outlined in the distutils documentation. These git repositories do *not* have to be hosted on pypi. You should however be able to do the following: $ git clone git://example.com/repo.git $ cd repo $ python setup.py install The pip requirement file would contain the following line: -e git+git://example.com/repo.git#egg=rep I hope this answers your questions :-D -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From nagle at animats.com Tue Nov 10 18:12:35 2009 From: nagle at animats.com (John Nagle) Date: Tue, 10 Nov 2009 15:12:35 -0800 Subject: CGI vs mod_python In-Reply-To: References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> Message-ID: <4af9f122$0$1659$742ec2ed@news.sonic.net> ssteinerX at gmail.com wrote: > > On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: > >> Yes, obviously. But if CGI is enabled, it should work anyway, should >> it not? > > Depends on what "CGI is enabled" means. > > Usually, web servers are not set to just handle cgi scripts from > anywhere, but only from specific file system locations. Otherwise, an > an anonymous upload could be executed as CGI and wreak havoc. If it won't work as a CGI program, which is relatively straightforward, it probably won't work at all. First, write some trivial CGI program in Python and make sure the environment works - Python loads, the Python program loads, and you can get a response back. Bear in mind that most hosting services don't make much of an attempt to support Python. Expect important libraries to be missing or obsolete. John Nagle From rhodri at wildebst.demon.co.uk Tue Nov 10 18:18:20 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 23:18:20 -0000 Subject: is None or == None ? In-Reply-To: <0309a54d$0$1340$c3e8da3@news.astraweb.com> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> <0309a54d$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, 10 Nov 2009 18:55:25 -0000, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 15:46:10 +0000, Grant Edwards wrote: > >> On 2009-11-10, Rhodri James wrote: >>> On Sun, 08 Nov 2009 19:45:31 -0000, Terry Reedy >>> wrote: >>> >>>> I believe the use of tagged pointers has been considered and so far >>>> rejected by the CPython developers. And no one else that I know of has >>>> developed a fork for that. It would seem more feasible with 64 bit >>>> pointers where there seem to be spare bits. But CPython will have to >>>> support 32 bit machines for several years. >>> >>> I've seen that mistake made twice (IBM 370 architecture (probably 360 >>> too, I'm too young to have used it) and ARM2/ARM3). I'd rather not see >>> it a third time, thank you. >> >> MacOS applications made the same mistake on the 68K. They reserved the >> high-end bits in a 32-bit pointer and used them to contain >> meta-information. > > > Obviously that was their mistake. They should have used the low-end bits > for the metadata, instead of the more valuable high-end. Oh, ARM used the low bits too. After all, instructions were 4-byte aligned, so the PC had all those bits going spare... -- Rhodri James *-* Wildebeest Herder to the Masses From aahz at pythoncraft.com Tue Nov 10 18:23:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 10 Nov 2009 15:23:40 -0800 Subject: futures - a new package for asynchronous execution References: Message-ID: In article , Brian Quinlan wrote: > >I recently implemented a package that I'd like to have include in the >Python 3.x standard library (and maybe Python 2.x) and I'd love to >have the feedback of this list. Any recently implemented library has an extremely high bar before it gets adopted into the standard library. You should concentrate on persuading people to use your library; for example, you should make regular feature and bugfix releases and announce them on c.l.py.announce. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke From python at rcn.com Tue Nov 10 18:35:12 2009 From: python at rcn.com (Raymond Hettinger) Date: Tue, 10 Nov 2009 15:35:12 -0800 (PST) Subject: My own accounting python euler problem References: Message-ID: <498f3fbd-93bd-448d-8acd-9401b04daad6@m7g2000prd.googlegroups.com> [vsoler] > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: ?$300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. I worked on a similar problem involving frequent bank deposits (the bank recorded only the amount of the deposit with no other tracking information to let us know which store made the deposit) and reconciling those deposits to general ledger entries. As pointed-out by others, the purest statement of the problem is computationally unfeasible; however, the real-world application can provide useful heuristics to that limit the search space. 1) Dates can be used to provide some alignment. Customers tend to pay the oldest invoices first and they don't pay before the first invoice is sent. Also, there can be a typical time lag that helps identify where to start a search (i.e. the customer typically takes 45 days to pay an invoice). 2) Search smallest groupings first (eliminate exact matches) then groupings of two items and groupings of three items. 3) Sometime the values on the list possess properties that make them stand-out and easier to match-up. Given invoices of [10, 11, 12, 1000, 13, 14], the 1000 should be easy to match-up in any grouping of payments. Likewise, when looking for groupings, start with the most unique values. Given [2, 2, 2, 3, 3, 5, 5, 5, 6.1, 7], start by trying to match the 6.1 since there is only one occurrence. Raymond From rhodri at wildebst.demon.co.uk Tue Nov 10 18:35:47 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 10 Nov 2009 23:35:47 -0000 Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: <6PfKm.51354$Db2.3028@edtnps83> References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 wrote: > Rhodri James wrote: >> On Fri, 06 Nov 2009 21:19:44 -0000, SD_V897 >> wrote: >> >>> Rhodri James wrote: >>>> On Tue, 03 Nov 2009 16:00:16 -0000, SD_V897 >>>> wrote: >>>> >>>>> I have a perplexing issue, I have four users set up on a W7 >>>>> computer. The program runs fine for all users except the admin user >>>>> who needs it for school assignments. >>>> A little more information, please. How does it not work for the >>>> admin >>>> user? Is there a traceback? What do you get if you try to invoke it >>>> from a command line? >>>> >>> >>> >>> Hi Rhodri, here's a dump file, don't know if this helps or not.. >> So Windows is reporting a crash, then. I'll repeat my last question >> in particular; what happens when your admin user runs the program >> you're trying to invoke from the command line? >> > > Hi Rhodri, Python Command-Line works fine. I'm sure it does. That's not what I asked you. > Are toy recommending to invoke IDLE from there or from windows command > line? No, I'm asking you -- or rather your admin user -- to invoke the program that is giving you grief from the command line, i.e. "python myscript.py", and tell me what happens. "It doesn't work" won't be considered at all helpful; without details we might as well just print out your script, throw darts at it, and tell you the problem is where the darts land. The rest of your answer however suggests that I've fundamentally misunderstood what you've said. Please tell me *exactly* what happens when it doesn't "run fine" for your admin user. -- Rhodri James *-* Wildebeest Herder to the Masses From pavlovevidence at gmail.com Tue Nov 10 18:38:24 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 15:38:24 -0800 (PST) Subject: Is it possible to get the Physical memory address of a variable in python? References: Message-ID: On Nov 10, 3:32?am, Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an interpreted > language. > > I'm trying to see if there is any way I can make Python share data > between two hosts using DMA transfers over a firewire connection, so > avoiding the need for another layer on top such as IPv4 + Python sockets. > > Thanks to some old python bindings which I updated to python 2.6, I can > read any write to the RAM of any firewire connected host within python. > Because it uses DMA (the cpu is not involved in this at all), I can only > specify a physical address within the 4GB ram limit to read from and > write to. [snip] > ?From what I've been told so far, it's not possible to do this without > some OS-specific (Linux in this case) syscall. Is this correct? What you'd normally need to do it to use system calls to allocate a DMA-able memory buffer, then copy contents of your Python object (which you get at using buffer protocol) to this buffer, then initiate the DMA transfer. At this point it probably would be easier to just write a C-extension to do that, but I see no reason it can't be done with ctypes. However, I'm not sure how that would interact with your pre-existing module. I'd expect a module that does DMA to take care of physical address mapping itself, you just pass it a logical address, or an object that supports buffer protocol, and it does the rest. It seems just getting a physical address and starting a DMA transfer from it is prone to danger if memory pages are discontiguous (and they often are), but maybe OSes these days can handle that automatically. Carl Banks From debatem1 at gmail.com Tue Nov 10 18:48:55 2009 From: debatem1 at gmail.com (geremy condra) Date: Tue, 10 Nov 2009 18:48:55 -0500 Subject: Python as network protocol In-Reply-To: <0309a863$0$1340$c3e8da3@news.astraweb.com> References: <7lso3fF3fivalU1@mid.uni-berlin.de> <03097b78$0$1340$c3e8da3@news.astraweb.com> <0309a863$0$1340$c3e8da3@news.astraweb.com> Message-ID: On Tue, Nov 10, 2009 at 2:08 PM, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote: > >> Steven, remember a few weeks ago when you tried to explain to me that >> the person who was storing windows administrative passwords using a 40 >> byte xor cipher with the hardcoded password might not be doing something >> stupid because I didn't know what their threat model was? Yeah- what you >> just said is what I was trying to explain then. > > No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from > the Evil Dimension... > > *wink* I think I saw a mustache on him. Probably evil. > Seriously, I'm not sure if I knew that the person was storing Windows > admin passwords at the time. If I had, I probably would have agreed with > you. But using a 40 byte xor cipher to obfuscate some strings in a game > is perfectly valid -- not every locked box needs to be a safe with 18 > inch tempered steel walls. Granted, and I am going to be able to give a very nice talk on how not to do cryptography partially as a result of that particularly egregious bit of silliness, so I guess I can't complain too much. > I can only repeat what I said to Daniel: can you guarantee that the nice > safe, low-risk environment will never change? If not, then choose a more > realistic threat model, and build the walls of your locked box > accordingly. Or, plan on becoming part of one of my presentations in a few years. Either way works for me. Geremy Condra From vmanis at telus.net Tue Nov 10 19:05:01 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 16:05:01 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-10, at 07:46, Grant Edwards wrote: > MacOS applications made the same mistake on the 68K. They > reserved the high-end bits At the time the 32-bit Macs were about to come on the market, I saw an internal confidential document that estimated that at least over 80% of the applications that the investigators had looked at (including many from that company named after a fruit, whose head office is on Infinite Loop) were not 32-bit clean. This in spite of the original edition of Inside Mac (the one that looked like a telephone book) that specifically said always to write 32-bit clean apps, as 32-bit machines were expected in the near future. It's not quite as bad as the program I once looked at that was released in 1999 and was not Y2K compliant, but it's pretty close. --v From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 21:25:47 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 02:25:47 GMT Subject: My own accounting python euler problem References: <2f951ad3-df8c-44ec-ac27-e9a9395d722c@x6g2000prc.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 14:46:49 -0800, John Machin wrote: > The problems that you mention are only a SUBSET of the total problem. > Example: oustanding invoices are for 300, 200, and 100 and the cheque is > for 450 -- in general the total of the cheque amounts does not equal the > total of any possible selection of outstanding invoice amounts. > > I would be very surprised if a real accounting department did not > already have a set of business rules for dealing with a problem that has > existed since invoices and cheques were invented. As a sometimes accounts department, let me put my hand up for that. Yes. Generally the rule is, "call the damn customer and ask them what they're smoking", only more politely. Usually they'll have some convoluted breakdown of what amount they are paying off each invoice. Sometimes they will have taken off a settlement discount for prompt payment (often whether or not they actually paid promptly). Sometimes they overpay, or underpay, or apply credits to the wrong invoice, or pay invoices twice, or pay the wrong amount, or just make up a number from thin air. Sometimes they themselves will have no idea what the amount represents. And, I can guarantee, they will *ALWAYS* use a different rounding scheme to whatever accounting software you use, so there's always odd one or two cents that need to be manually adjusted somewhere. > I would be extremely surprised if a real accounting department could be > persuaded to imagine a subset of their unpaid/underpaid/overpaid invoice > problem as being an instance of the (extended) knapsack problem :-) That's because the average accounting department is mathematically illiterate :) Nevertheless, many accounting software packages, like Quickbooks, will take a wild stab at allocating payments for you, usually using some variation of "if you can't find an exact match for a single invoice, just blindly allocate it to the oldest invoices you can". Frankly, I'd much prefer a knapsack solution. -- Steven From anthoniraja at gmail.com Tue Nov 10 21:26:48 2009 From: anthoniraja at gmail.com (Antony) Date: Tue, 10 Nov 2009 18:26:48 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: <53e5095a-aec3-4268-9b23-d822949b47e3@12g2000pri.googlegroups.com> On Nov 11, 3:08?am, Simon Hibbs wrote: > On 10 Nov, 10:40, Lorenzo Gatti wrote: > > > I also would like to use PySide, but unlike PyQt and Qt itself it > > doesn't seem likely to support Windows in the foreseeable future. A > > pity, to put it mildly. > > It's not been ruled out. They don't officialy support the Mac either, > but according to posts on the mailing list a independent developer has > got it working in MacOS X at some level. Since QT runs on Windows, > porting to the Windows version of QT shouldn't be hard. > > PySide is for the future, not the present, but it gives me a lot more > confidence in using and recomending PyQT to know that there is so much > work being put in to make sure it has a great future. > > Simon Hibbs Thanks All I have got an idea,the way i need to choose GUI module in Python , As "r" said i am going to start from tkinter without any IDE . if i need any advanced feature then i will move on to some other module.... First i have to try the code ... From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 21:30:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 02:30:15 GMT Subject: My own accounting python euler problem References: Message-ID: On Tue, 10 Nov 2009 14:59:13 -0800, John Machin wrote: > On Nov 8, 8:39?am, vsoler wrote: >> In the accounting department I am working for we are from time to time >> confronted to the following problem: > [snip] > >> My second question is: >> 2. this time there are also credit notes outstanding, that is, invoices >> with negative amounts. For example, ?I=[500, 400, -100, 450, 200, 600, >> -200, 700] and a check Ch=600 > > How can a credit note be "outstanding"? The accounting department issues > a credit note without recording what invoice it relates to? Yes, that can happen. (1) Human error, or laziness, or dumb software that doesn't understand credits apply to specific invoices. (2) The credit note represents a settlement discount, rebate, "advertising allowance" or other kickback, or similar. (3) An invoice is paid in full, then later the client claims a refund against it. If granted, the credit can't be applied to the invoice that is already flagged as paid, so it remains as an "unallocated" credit note. (4) Or simply that the boss forbids you from allocating credit notes until payment is received. -- Steven From communication at linkedin.com Tue Nov 10 21:38:42 2009 From: communication at linkedin.com (LinkedIn Communication) Date: Tue, 10 Nov 2009 18:38:42 -0800 (PST) Subject: LinkedIn Messages, 11/10/2009 Message-ID: <1736753274.2985675.1257907122901.JavaMail.app@ech3-cdn09.prod> LinkedIn ------------ REMINDERS: Invitation Reminders: * View Invitation from Frank Pan http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I379833192_3/0PnP8VcjcPe3ATcQALqnpPbOYWrSlI/svi/ PENDING MESSAGES: There are a total of 4 messages awaiting your response. Visit your InBox now: http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/inb/ ------ Don't want to receive email notifications? Adjust your message settings: https://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/prv/ LinkedIn values your privacy. At no time has LinkedIn made your email address available to any other LinkedIn user without your permission. (c) 2009, LinkedIn Corporation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 22:07:36 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 03:07:36 GMT Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On Tue, 10 Nov 2009 16:05:01 -0800, Vincent Manis wrote: > At the time the 32-bit Macs were about to come on the market, I saw an > internal confidential document that estimated that at least over 80% of > the applications that the investigators had looked at (including many > from that company named after a fruit, whose head office is on Infinite > Loop) were not 32-bit clean. This in spite of the original edition of > Inside Mac (the one that looked like a telephone book) that specifically > said always to write 32-bit clean apps, as 32-bit machines were expected > in the near future. That is incorrect. The original Inside Mac Volume 1 (published in 1985) didn't look anything like a phone book. The original Macintosh's CPU (the Motorola 68000) already used 32-bit addressing, but the high eight pins were ignored since the CPU physically lacked the pins corresponding to those bits. In fact, in Inside Mac Vol II, Apple explicitly gives the format of pointers: the low-order three bytes are the address, the high-order byte is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 the resource bit. The other five bits were unused. By all means criticize Apple for failing to foresee 32-bit apps, but criticizing them for hypocrisy (in this matter) is unfair. By the time they recognized the need for 32-bit clean applications, they were stuck with a lot of legacy code that were not clean. Including code burned into ROMs. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Nov 10 22:12:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 03:12:55 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > r: > >> i think the following syntax would be quite beneficial to replace some >> redundant "if's" in python code. > > http://python.org/dev/peps/pep-3003/ I knew it wouldn't take long for people to start responding to any proposal with "don't bother, there's a moratorium". Of course in this case, the correct response would have been "don't bother, it's a stupid idea, moratorium or no moratorium". Hint to would-be language designers: if you start off by claiming that a new feature will save an indent level, when in fact it *doesn't* save an indent level, you can save yourself from embarrassment by pressing Close on your post instead of Send. -- Steven From invalid at invalid.invalid Tue Nov 10 22:39:54 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 11 Nov 2009 03:39:54 +0000 (UTC) Subject: is None or == None ? References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: On 2009-11-11, Steven D'Aprano wrote: > By all means criticize Apple for failing to foresee 32-bit > apps, but criticizing them for hypocrisy (in this matter) is > unfair. By the time they recognized the need for 32-bit clean > applications, they were stuck with a lot of legacy code that > were not clean. Including code burned into ROMs. They did manage to climb out of the hole they had dug and fix things up -- something Microsoft has yet to do after 25 years. Maybe it's finally going to be different this time around with Windows 7... -- Grant From phlip2005 at gmail.com Tue Nov 10 23:00:52 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:00:52 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <831422a4-bdaa-4be0-b448-7abf9bece3e6@2g2000prl.googlegroups.com> On Nov 10, 3:11?pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep I thought pip didn't do eggs. did I read a stale blog? > I hope this answers your questions :-D oooo we are so close! Pages like this... http://blog.ianbicking.org/2008/12/16/using-pip-requirements/ ...are answering the question "what if I have ten billion requirements?" I have one, Python. What's the simplest pip requirement file? I will post here if I figure it out first. From pavlovevidence at gmail.com Tue Nov 10 23:02:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 20:02:03 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 10, 11:23?am, r wrote: > if something_that_returns_value() as value: > ? ? #do something with value Been proposed before. No one has bothered to write a PEP for it, so I can't say for sure how the Python gods would react, but I suspect a "meh, don't think it's important enough". This, even though it's more useful than you are giving it credit for. It's a minor improvement. Carl Banks From pavlovevidence at gmail.com Tue Nov 10 23:13:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 10 Nov 2009 20:13:21 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> On Nov 10, 7:12?pm, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > > r: > > >> i think the following syntax would be quite beneficial to replace some > >> redundant "if's" in python code. > > >http://python.org/dev/peps/pep-3003/ > > I knew it wouldn't take long for people to start responding to any > proposal with "don't bother, there's a moratorium". > > Of course in this case, the correct response would have been "don't > bother, it's a stupid idea, moratorium or no moratorium". r didn't actually give a good example. Here is case where it's actually useful. (Pretend the regexps are too complicated to be parsed with string method.) if re.match(r'go\s+(north|south|east|west)',cmd) as m: hero.move(m.group(1)) elif re.match(r'take\s+(\w+)',cmd) as m: hero.pick_up(m.group(1)) elif re.match(r'drop\s+(\w+)',cmd) as m: here.put_Down(m.group(1)) I wouldn't mind seeing this in Python for this exact use case, although I'd rather the syntax to be more like the following so that you can bind something other than the condition if need be. if m with m as re.match(regexp,command): Moot point for the next two years, and probably forever as I doubt it would ever happen. Carl Banks From rt8396 at gmail.com Tue Nov 10 23:23:03 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 20:23:03 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> Message-ID: <0f547bb8-838e-4835-9216-ecd32fc711a1@n35g2000yqm.googlegroups.com> On Nov 10, 9:12?pm, Steven D'Aprano wrote: (..snip..) > Hint to would-be language designers: if you start off by claiming that a > new feature will save an indent level, when in fact it *doesn't* save an > indent level, you can save yourself from embarrassment by pressing Close > on your post instead of Send. Does anyone out there know the textual smiley for conveying an overwhelming feeling of embarrassment? Also may want to send the one for feeling of confusion too ;-) From phlip2005 at gmail.com Tue Nov 10 23:25:57 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:25:57 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: On Nov 10, 3:11?pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep > > I hope this answers your questions :-D Let me ask it like this. What happens when a user types..? sudo pip install repo Is github one of the default sites pip scans? If so, will it rip a requirements file in the root of repo.git? If so, what file name should that have? All the pages I'm reading start at the complex end of the requirements file concept. They don't seem to mention simple things like the name of the file, or how to lead pip to the file. From phlip2005 at gmail.com Tue Nov 10 23:35:47 2009 From: phlip2005 at gmail.com (Phlip) Date: Tue, 10 Nov 2009 20:35:47 -0800 (PST) Subject: how to create a pip package References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> <831422a4-bdaa-4be0-b448-7abf9bece3e6@2g2000prl.googlegroups.com> Message-ID: <90e132d9-1b16-45f8-89dc-d5a4eb7ebf21@f20g2000prn.googlegroups.com> > > -e git+git://example.com/repo.git#egg=rep Okay. -e is an argument to pip install. If anyone said that, I overlooked it. So, yes I can rip from github, just with a longer command line, for now. Tx! From SD_V897 at NoSuchMail.Com Tue Nov 10 23:51:38 2009 From: SD_V897 at NoSuchMail.Com (SD_V897) Date: Wed, 11 Nov 2009 04:51:38 GMT Subject: pythonw.exe under Windows-7 (Won't run for one admin user) In-Reply-To: References: <6PfKm.51354$Db2.3028@edtnps83> Message-ID: Rhodri James wrote: > On Tue, 10 Nov 2009 15:39:46 -0000, SD_V897 wrote: > No, I'm asking you -- or rather your admin user -- to invoke the program > that is giving you grief from the command line, i.e. "python > myscript.py", and tell me what happens. "It doesn't work" won't be > considered at all helpful; without details we might as well just print > out your script, throw darts at it, and tell you the problem is where > the darts land. > > The rest of your answer however suggests that I've fundamentally > misunderstood what you've said. Please tell me *exactly* what happens > when it doesn't "run fine" for your admin user. > I fixed it for some reason deleting my idlerc folder allows it to work again.. http://bugs.python.org/issue7206 Thanks everybody.. SD From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 00:37:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 05:37:13 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 20:13:21 -0800, Carl Banks wrote: > On Nov 10, 7:12?pm, Steven D'Aprano > wrote: >> On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: >> > r: >> >> >> i think the following syntax would be quite beneficial to replace >> >> some redundant "if's" in python code. >> >> >http://python.org/dev/peps/pep-3003/ >> >> I knew it wouldn't take long for people to start responding to any >> proposal with "don't bother, there's a moratorium". >> >> Of course in this case, the correct response would have been "don't >> bother, it's a stupid idea, moratorium or no moratorium". > > r didn't actually give a good example. Here is case where it's actually > useful. (Pretend the regexps are too complicated to be parsed with > string method.) > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > hero.move(m.group(1)) > elif re.match(r'take\s+(\w+)',cmd) as m: > hero.pick_up(m.group(1)) > elif re.match(r'drop\s+(\w+)',cmd) as m: > here.put_Down(m.group(1)) This is where a helper function is good. You want a dispatcher: COMMANDS = { r'go\s+(north|south|east|west)': hero.move, r'take\s+(\w+)': hero.pick_up, r'drop\s+(\w+)': here.put_Down, } def dispatch(cmd): for regex in COMMANDS: m = re.match(regex, cmd) if m: COMMANDS[regex](m.group(1)) break dispatch(cmd) If you need the regexes to be tested in a specific order, change the dict to an OrderedDict, or use a list of tuples and the obvious change to the for loop. -- Steven From tjreedy at udel.edu Wed Nov 11 00:44:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 00:44:55 -0500 Subject: New syntax for blocks In-Reply-To: <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: Carl Banks wrote: > > r didn't actually give a good example. Here is case where it's > actually useful. (Pretend the regexps are too complicated to be > parsed with string method.) > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > hero.move(m.group(1)) > elif re.match(r'take\s+(\w+)',cmd) as m: > hero.pick_up(m.group(1)) > elif re.match(r'drop\s+(\w+)',cmd) as m: > here.put_Down(m.group(1)) The effect of this proposal can already be accomplished with a 'pocket' class as has been posted before and again in a slightly different form in Steve's post. tjr From tjreedy at udel.edu Wed Nov 11 00:50:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Nov 2009 00:50:36 -0500 Subject: DHT for Python 3.x? In-Reply-To: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: Salim Fadhley wrote: > There are plenty of good DHT dihydrotestosterone? distributed hash table? DHT Maritime Inc.? DHT routing algorithm? D.H.T. the music group? digital home theater? (from first 20 Google hits) tjr From vmanis at telus.net Wed Nov 11 01:07:43 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 22:07:43 -0800 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> On 2009-11-10, at 19:07, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 16:05:01 -0800, Vincent Manis wrote: > That is incorrect. The original Inside Mac Volume 1 (published in 1985) > didn't look anything like a phone book. The original Macintosh's CPU (the > Motorola 68000) already used 32-bit addressing, but the high eight pins > were ignored since the CPU physically lacked the pins corresponding to > those bits. > > In fact, in Inside Mac Vol II, Apple explicitly gives the format of > pointers: the low-order three bytes are the address, the high-order byte > is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 > the resource bit. The other five bits were unused. You are correct. On thinking about it further, my source was some kind of internal developer seminar I attended round about 1985 or so, where an Apple person said `don't use the high order bits, we might someday produce machines that use all 32 address bits', and then winked at us. You are also correct (of course) about the original `Inside Mac', my copy was indeed 2 volumes in looseleaf binders; the phonebook came later. > By all means criticize Apple for failing to foresee 32-bit apps, but > criticizing them for hypocrisy (in this matter) is unfair. By the time > they recognized the need for 32-bit clean applications, they were stuck > with a lot of legacy code that were not clean. Including code burned into > ROMs. That's my point. I first heard about Moore's Law in 1974 from a talk given by Alan Kay. At about the same time, Gordon Bell had concluded, independently, that one needs extra address bit every 18 months (he was looking at core memory, so the cost factors were somewhat different). All of this should have suggested that relying on any `reserved' bits is always a bad idea. I am most definitely not faulting Apple for hypocrisy, just saying that programmers sometimes assume that just because something works on one machine, it will work forevermore. And that's unwise. -- v From sajmikins at gmail.com Wed Nov 11 01:12:41 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 11 Nov 2009 01:12:41 -0500 Subject: Calendar Stuff In-Reply-To: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> Message-ID: <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi wrote: > Hi; > I have the following code: > > import calendar, datetime > > def cal(): > ? ... > ? myCal = calendar.Calendar(calendar.SUNDAY) > ? today = datetime.date.today() > ? day = today.day > ? mo = today.month > ? yr = today.year > #? month = myCal.monthdayscalendar(int(time.strftime("%Y")) > ? month = myCal.monthdayscalendar(yr, mo) > ? print 'hi' > > html headers are included. No matter which one of the last two lines I > comment out, I never get to the point of printing 'hi'. (If I comment them > both out, it does print.) What do? > TIA, > Victor Have you tried walking through the code line-by-line in the interactive interpreter? That should give you an idea of why those lines aren't working. Also, if your code never prints 'hi', what does it do instead? Hang? Or give you a traceback? From vmanis at telus.net Wed Nov 11 01:14:14 2009 From: vmanis at telus.net (Vincent Manis) Date: Tue, 10 Nov 2009 22:14:14 -0800 Subject: is None or == None ? In-Reply-To: <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> <473B8E06-9008-475A-B7A3-F5A296C7A8FB@telus.net> Message-ID: On 2009-11-10, at 22:07, Vincent Manis wrote: > On 2009-11-10, at 19:07, Steven D'Aprano wrote: >> In fact, in Inside Mac Vol II, Apple explicitly gives the format of >> pointers: the low-order three bytes are the address, the high-order byte >> is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 >> the resource bit. The other five bits were unused. I inadvertently must have deleted a paragraph in the response I just posted. Please add: The pointer format would have caused me to write macros or the like (that was still in the days when Apple liked Pascal) to hide the bit representation of pointers. -- v From martin at v.loewis.de Wed Nov 11 01:20:50 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 11 Nov 2009 07:20:50 +0100 Subject: DHT for Python 3.x? In-Reply-To: References: <0354bc47-9d84-45ba-9e0d-c5c02b7a25bf@f16g2000yqm.googlegroups.com> Message-ID: <4AFA57C2.2000104@v.loewis.de> Terry Reedy wrote: > Salim Fadhley wrote: >> There are plenty of good DHT > distributed hash table? I think it's that one. Regards, Martin From rt8396 at gmail.com Wed Nov 11 02:00:09 2009 From: rt8396 at gmail.com (r) Date: Tue, 10 Nov 2009 23:00:09 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 10, 2:49?pm, steve wrote: (..snip..) > However, the same 'effect' can be obtained with the 'with' statement: (..snip..) Hardly!,Here is an interactive session with your test case #----------------------------------------------------------# >>> class something_that_returns_value: def __init__(self, x): # do something with x, self.value is what ought to be 'returned' self.value = x def __enter__(self): if self.value: return self.value else: return ValueError() def __exit__(self, type, value, traceback): return True >>> with something_that_returns_value(1) as value: print 'block' block >>> with something_that_returns_value(0) as value: print 'block' block >>> with something_that_returns_value(False) as value: print 'block' block >>> with something_that_returns_value([1,2,3]) as value: print 'block' block #----------------------------------------------------------# The block obviously executes every time no matter what value is returned from something_that_returns_value(*). The with statement is meant to only cleanup an exception in a "nice-clean-way" not to evaluate a variable assignment as evidenced by this simple testing of your code. If anything executes in the block following the "if" (when the assignment value is None) it undermines the whole reason for using the new syntax in the first place! I think what has escaped everyone (including myself until my second post) is the fact that what really needs to happen is for variable *assignments* to return a boolean to any "statements" that evaluate the assignment -- like in an "if" or "elif" construct. The current "with" statement cannot replace that action and was never meant for such things. if range(0) as var: #python will never execute even one line #in this block because bool(var) == None #also since bool(var) equals None, the #variable "var" will never be created! elif range(10) as var: #this block will execute and the variable "var" #will be added to appropriate namespace containing #a list of 10 ints var = 100 #var is still available in this namespace! Very clean, very elegant solution to a messy problem that pops up in python code quite often. It not only saves one distracting line of code per usage but makes the code more readable. If there is an existing solution, Steve's is not it. From ken at seehart.com Wed Nov 11 02:02:39 2009 From: ken at seehart.com (Ken Seehart) Date: Tue, 10 Nov 2009 23:02:39 -0800 Subject: Authentication session with urllib2 Message-ID: <4AFA618F.3030606@seehart.com> I'm having some difficulty implementing a client that needs to maintain an authenticated https: session. I'd like to avoid the approach of receiving a 401 and resubmit with authentication, for two reasons: 1. I control the server, and it was easy for me to make a url that receives a POST with username, password and authenticates the session. The server keeps a session correctly when I test with a browser. This part works fine. 2. I don't want to send every request twice. See http://bugs.python.org/issue7159 There's no reason why I should have to do this since I have the ability to keep the server simple. What I would really like to do is send one request with the username and password to establish the session, and then make multiple authenticated requests where the session information remembers the authentication. Is there a way to make this happen in python 2.5.2? Keep in mind that this only needs to work with a particular server which I control. It does not need to function as a general purpose browser. The server is powered by Django. - Ken From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 02:25:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 07:25:35 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Tue, 10 Nov 2009 23:00:09 -0800, r wrote: > I think what has escaped everyone (including myself until my second > post) is the fact that what really needs to happen Why? > is for variable > *assignments* to return a boolean to any "statements" that evaluate the > assignment -- like in an "if" or "elif" construct. I don't even understand what that means. > The current "with" > statement cannot replace that action and was never meant for such > things. > > if range(0) as var: > #python will never execute even one line > #in this block because bool(var) == None No, that's impossible. bool() always returns True or False, not None. > #also since bool(var) equals None, the Incorrect. >>> True == None False >>> False == None False > #variable "var" will never be created! That will cause no end of trouble. if range(N) as var: do_something_with_var() if var: print "Oops, this blows up if N <= 0" Conditional assignments are a terrible idea. > elif range(10) as var: > #this block will execute and the variable "var" > #will be added to appropriate namespace containing > #a list of 10 ints > > var = 100 #var is still available in this namespace! > > > Very clean, very elegant solution to a messy problem that pops up in > python code quite often. You haven't actually explained what the messy problem is. var = range(N) if var: ... is not a messy problem. It's perfectly reasonable. If you need to do two things with a value, you assign it to a name first: var = range(N) p = var.index(5) var.append(42) x = func(10) y = x + 1 z = x*2 x = func(10) if x: y = x + 1 Why is the third example, with an if... test, so special that it needs special syntax to make it a two-liner? Would you suggest we can write this? # instead of var = range(N) p = range(N).index(5) as var # var might be range(N), or undefined. var.append(42) > It not only saves one distracting line of code > per usage but makes the code more readable. What distracting line of code? -- Steven From rt8396 at gmail.com Wed Nov 11 03:08:58 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 00:08:58 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Nov 11, 1:25?am, Steven D'Aprano wrote: (snip) > Incorrect. > >>> True == None > False > >>> False == None > False Of course i meant True/False but my fingers were thinking None at the time. And besides if i don't make a mistake here or there what ever would you do with your time? ;-) Seven += 1 > > ? ?#variable "var" will never be created! > That will cause no end of trouble. > if range(N) as var: > ? ? do_something_with_var() > if var: > ? ? print "Oops, this blows up if N <= 0" > Conditional assignments are a terrible idea. Yea it's called a NameError. Would it not also blow up in the current state of syntax usage? if var: print 'var' Traceback (most recent call last): File "", line 1, in if var: NameError: name 'var' is not defined Steven -= 1 > Why is the third example, with an if... test, so special that it needs > special syntax to make it a two-liner? ...because Beautiful is better than ugly. > Would you suggest we can write this? > # instead of var = range(N) > p = range(N).index(5) as var ?# var might be range(N), or undefined. > var.append(42) No if you read my post my usage of this syntax only includes "if" and "elif" constructs and nothing "else" because usage outside of such a "truth-seeking" construct is pointless. print Steven -> 0 Hmm, just as i suspected. From steven at REMOVE.THIS.cybersource.com.au Wed Nov 11 03:37:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Nov 2009 08:37:35 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: >> > ? ?#variable "var" will never be created! >> That will cause no end of trouble. >> if range(N) as var: >> ? ? do_something_with_var() >> if var: >> ? ? print "Oops, this blows up if N <= 0" >> Conditional assignments are a terrible idea. > > Yea it's called a NameError. Would it not also blow up in the current > state of syntax usage? No. > if var: > print 'var' > > Traceback (most recent call last): > File "", line 1, in > if var: > NameError: name 'var' is not defined You missed a line: var = range(N) if var: ... The problem isn't the if statement, it is the conditional assignment. Sometimes "x as y" creates y, sometimes it doesn't, according to some mysterious rule something to do without whether the assignment is true or false, whatever that means. >> Why is the third example, with an if... test, so special that it needs >> special syntax to make it a two-liner? > > ...because Beautiful is better than ugly. I can quote the Zen too: Special cases aren't special enough to break the rules. You haven't demonstrated that your construct is "beautiful", or the existing way of writing it is "ugly". # apparently not ugly x = func() y = x + 1 z = 2*x # also not ugly var = range(N) var.append(42) find(23, var) # still not ugly var = range(N) for x in var: do_something_with(x, var) # not ugly var = MyClass() with var.magic as x: process(var) # why is this ugly? var = range(N) if var: process(var) >> Would you suggest we can write this? >> # instead of var = range(N) >> p = range(N).index(5) as var ?# var might be range(N), or undefined. >> var.append(42) > > No if you read my post my usage of this syntax only includes "if" and > "elif" constructs and nothing "else" because usage outside of such a > "truth-seeking" construct is pointless. What's so special about "truth-seeking"? for x in range(N) as var: do_something_with(x, var) That would save a line too, it would behave exactly as you specified, and it uses virtually the identical syntax: "expr as name". -- Steven From gatti at dsdata.it Wed Nov 11 03:48:26 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Wed, 11 Nov 2009 00:48:26 -0800 (PST) Subject: Choosing GUI Module for Python References: <2d36f11e-5514-4c3a-bedb-9cb7d2ed72d7@m38g2000yqd.googlegroups.com> Message-ID: On Nov 10, 11:08?pm, Simon Hibbs wrote: > Since QT runs on Windows, > porting to the Windows version of QT shouldn't be hard. The PySide developers, who are better judges of their own project than you and me, consider a Windows port so hard (and time consuming) that they didn't even try; a second iteration of the already working binding generator has a higher priority than supporting a large portion of the potential user base with a Windows port, so don't hold your breath. On a more constructive note, I started to follow the instructions at http://www.pyside.org/docs/pyside/howto-build/index.html (which are vague and terse enough to be cross-platform) with Microsoft VC9 Express. Hurdle 0: recompile Qt because the provided DLLs have hardcoded wrong paths that confuse CMake. How should Qt be configured? My first compilation attempt had to be aborted (and couldn't be resumed) after about 2 hours: trial and error at 1-2 builds per day could take weeks. Regards, Lorenzo Gatti From wentland at cl.uni-heidelberg.de Wed Nov 11 04:25:05 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Wed, 11 Nov 2009 10:25:05 +0100 Subject: how to create a pip package In-Reply-To: References: <033ede53-03a2-4533-8dd2-621ff23eccfa@f18g2000prf.googlegroups.com> <75b035c6-37f0-419e-90b4-086df216b72a@u36g2000prn.googlegroups.com> <4f54ae12-feff-4508-aa00-7b63ff83f1cc@b2g2000yqi.googlegroups.com> Message-ID: <20091111092505.GA29290@kinakuta.local> On Tue, Nov 10, 2009 at 20:25 -0800, Phlip wrote: > On Nov 10, 3:11?pm, Wolodja Wentland > wrote: > > > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep > Let me ask it like this. What happens when a user types..? > sudo pip install repo pip will check for 'repo' on pypi, find nothing and stop processing. > Is github one of the default sites pip scans? No. > If so, will it rip a requirements file in the root of repo.git? No. >If so, what file name should that have? You can choose any name you like. I think I have to explain a bit more. The requirement file is basically a list of *all installed distributions* in a Python environment and is usually created by 'pip freeze'. It is merely a way to tell pip later which distributions it should try to install. The basic way of working with requirement files if this: 1. Create virtual environment [1] 2. Install *your* package and all of its dependencies within the virtual environment 3. Run 'pip freeze' to get the list of installed distributions and write it to a file. This file is the requirement file. 4. Give the requirement file to someone else 5. Create a virtual environment 6. Run 'pip install -r requirement_file.txt' to install all distributions 'frozen' in the requirements file 7. PROFIT!!! A requirements file is not really meant to state the dependencies of a single distribution, but rather describe the complete state an environment is in *so it can be reconstructed later* exactly like is has been before. This is quite important if you want to deploy application and you want to make sure that only tested versions of you dependency get installed. I think of it rather in the terms of: pip freeze --> dpkg --get-selections pip install -r r.txt --> dpkg --set-selections aptitude install AFAIK you can also host the distribution on another site than pypi, but I am not sure how to tell pip to check there for distributions as well. You might want to ask this on the virtualenv list. -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 853 bytes Desc: Digital signature URL: From greg at cosc.canterbury.ac.nz Wed Nov 11 04:32:30 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 11 Nov 2009 22:32:30 +1300 Subject: is None or == None ? In-Reply-To: References: <6a26bc27-9f9e-4cb1-8024-2302c53f8d20@d9g2000prh.googlegroups.com> <87r5sbh8kf.fsf@busola.homelinux.net> <87my2xhko9.fsf@busola.homelinux.net> <87iqdlgwum.fsf@busola.homelinux.net> Message-ID: <7lvelqF3f3bq7U1@mid.individual.net> Vincent Manis wrote: > That's my point. I first heard about Moore's Law in 1974 from a talk given > by Alan Kay. At about the same time, Gordon Bell had concluded, independently, > that one needs extra address bit every 18 months Hmmm. At that rate, we'll use up the extra 32 bits in our 64 bit pointers in another 48 years. So 128-bit machines ought to be making an appearance around about 2057, and then we'll be all set until 2153 -- if we're still using anything as quaintly old-fashioned as binary memory addresses by then... -- Greg From rpjday at crashcourse.ca Wed Nov 11 04:57:28 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Wed, 11 Nov 2009 04:57:28 -0500 (EST) Subject: python simply not scaleable enough for google? Message-ID: http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 thoughts? rday -- ======================================================================== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday ======================================================================== From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 05:06:32 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 11:06:32 +0100 Subject: YIELD_VALUE Byte Code Message-ID: <1257933992.2784.16.camel@laptop> Hi, I am not sure if this is the right newsgroup, so if not don't hesitate to tell me. I am developed a Python to C compiler, so that Byte Code files automatically can be translated into C Extension Modules. (And it works pretty well --> http://www.coremountains.com/products/bytecoat/) While developing, I found something strange concerning the YIELD_VALUE OpCode. Since Python Version 2.5 it behaves the following: 1. pop yield value from stack and return it to a former gen_send_ex() call from Objects/genobject.c 2. push the yield value on the stack in gen_send_ex() and return it 3. when the generator is executed again, the yield value is 'poped' from the stack again with the POP_TOP opcode Now I found that a little strange: 1. why is the value removed from the stack, than pushed on the stack to remove it finally again? the combination of YIELD_VALUE and TOP_POP seems hard coded in compile.c which means that a TOP_POP follows every YIELD_VALUE TOP_POP 2. If the semantic of the YIELD_VALUE OpCode has changed, why is this reached by using another function? Such thing should be done in the OpCode. (e.a.: instead of retval = POP() --> retval = TOP(); Py_INCREF(retval); ) I am a little confused about this. Best, Andreas From rt8396 at gmail.com Wed Nov 11 05:50:37 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 02:50:37 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <5dce542d-b2f6-4c7a-9ae6-7c81846d6391@u7g2000yqm.googlegroups.com> On Nov 11, 2:37?am, Steven D'Aprano wrote: > On Wed, 11 Nov 2009 00:08:58 -0800, r wrote: > > Yea it's called a NameError. Would it not also blow up in the current > > state of syntax usage? > > No. > > > if var: > > ? ? print 'var' > > > Traceback (most recent call last): > > ? File "", line 1, in > > ? ? if var: > > NameError: name 'var' is not defined > > You missed a line: > > var = range(N) > if var: Oh i get it now! If i assign a valid value to a variable the variable is also valid...thats...thats... GENUIS! *sarcasm* > The problem isn't the if statement, it is the conditional assignment. > Sometimes "x as y" creates y, sometimes it doesn't, according to some > mysterious rule something to do without whether the assignment is true or > false, whatever that means. i don't find True or False, Black or White, 1 or 0, Alpha or Omega to be mysterious...? If you still cannot grasp this simple concept then i fear i may not be able to help you understand Steven. (snip: excessive inane blubbering) > > No if you read my post my usage of this syntax only includes "if" and > > "elif" constructs and nothing "else" because usage outside of such a > > "truth-seeking" construct is pointless. > > What's so special about "truth-seeking"? > > for x in range(N) as var: > ? ? do_something_with(x, var) You could do that but why would you want to. A "for x in range(N)" is just so you can loop N times. And since changing the values in a list whilst looping over it is the sport of fools then what usefulness would a variable be for such a construct? You have failed to prove the usefulness of this syntax Steven. I suggest you go back and read over my posts again and then marinate on the contents for a while. THEN come back with an argument based in reality and we will try again...You know at one time i actually considered you a formidable foe, well these times they are a chang'in right Dylan? From rpurdie at rpsys.net Wed Nov 11 05:59:46 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 10:59:46 +0000 Subject: Unexpected python exception Message-ID: <1257937186.29038.305.camel@dax.rpnet.com> I've been having problems with an unexpected exception from python which I can summarise with the following testcase: def A(): import __builtin__ import os __builtin__.os = os def B(): os.stat("/") import os A() B() which results in: Traceback (most recent call last): File "./test.py", line 12, in B() File "./test.py", line 8, in B os.stat("/") UnboundLocalError: local variable 'os' referenced before assignment If I remove the "import os" from B(), it works as expected. >From what I've seen, its very unusual to have something operate "backwards" in scope in python. Can anyone explain why this happens? Cheers, Richard From deets at nospam.web.de Wed Nov 11 06:21:55 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 11 Nov 2009 12:21:55 +0100 Subject: Unexpected python exception In-Reply-To: References: Message-ID: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Richard Purdie schrieb: > I've been having problems with an unexpected exception from python which > I can summarise with the following testcase: > > def A(): > import __builtin__ > import os > > __builtin__.os = os > > def B(): > os.stat("/") > import os > > A() > B() > > which results in: > > Traceback (most recent call last): > File "./test.py", line 12, in > B() > File "./test.py", line 8, in B > os.stat("/") > UnboundLocalError: local variable 'os' referenced before assignment > > If I remove the "import os" from B(), it works as expected. > >>From what I've seen, its very unusual to have something operate > "backwards" in scope in python. Can anyone explain why this happens? As the import-statement in a function/method-scope doesn't leak the imported names into the module scope, python treats them as locals. Which makes your code equivalent to x = 1000 def foo(): print x x = 10 Throws the same error. The remedy is to inform python that a specific name belongs to global scope, using the "global"-statement. def foo(): global x print x x = 10 Beware though that then of course *assigning* to x is on global level. This shouldn't be of any difference in your case though, because of the import-only-once-mechanics of python. Diez From hugo.leveille at visionglobale.com Wed Nov 11 06:25:04 2009 From: hugo.leveille at visionglobale.com (=?iso-8859-1?Q?Hugo_L=E9veill=E9?=) Date: Wed, 11 Nov 2009 06:25:04 -0500 Subject: Knob label justification Message-ID: By default, a boolean knob has the text label on the right. How can I make it on the left? thx -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 06:25:53 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 12:25:53 +0100 Subject: Unexpected python exception In-Reply-To: References: Message-ID: <1257938753.11260.6.camel@laptop> Hi, unfortunatley I cannot reproduce your error. Which Python Version do you use? The expected case in this scenario is that the exception is thrown, as you import os in A() where it is stored in the local namespace of the function. I tested it with Python 2.4, 2.5 and 2.6 and in both cases an exception is thrown. Best, Andreas From pavlovevidence at gmail.com Wed Nov 11 06:52:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 03:52:45 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 10, 9:37?pm, Steven D'Aprano wrote: > On Tue, 10 Nov 2009 20:13:21 -0800, Carl Banks wrote: > > On Nov 10, 7:12?pm, Steven D'Aprano > > wrote: > >> On Tue, 10 Nov 2009 12:45:13 -0800, Bearophile wrote: > >> > r: > > >> >> i think the following syntax would be quite beneficial to replace > >> >> some redundant "if's" in python code. > > >> >http://python.org/dev/peps/pep-3003/ > > >> I knew it wouldn't take long for people to start responding to any > >> proposal with "don't bother, there's a moratorium". > > >> Of course in this case, the correct response would have been "don't > >> bother, it's a stupid idea, moratorium or no moratorium". > > > r didn't actually give a good example. ?Here is case where it's actually > > useful. ?(Pretend the regexps are too complicated to be parsed with > > string method.) > > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > > ? ? hero.move(m.group(1)) > > elif re.match(r'take\s+(\w+)',cmd) as m: > > ? ? hero.pick_up(m.group(1)) > > elif re.match(r'drop\s+(\w+)',cmd) as m: > > ? ? here.put_Down(m.group(1)) > > This is where a helper function is good. You want a dispatcher: No I really don't. I want to be able to see the action performed adjacent to the test, and not have to scroll up to down ten pages to find whatever function it dispatched to. Carl Banks From alfps at start.no Wed Nov 11 06:57:09 2009 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 11 Nov 2009 12:57:09 +0100 Subject: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows) In-Reply-To: References: Message-ID: * Alf P. Steinbach: > Chapter 2 "Basic Concepts" is about 0.666 completed and 30 pages so far. > > It's now Python 3.x, and reworked with lots of graphical examples and > more explanatory text, plus limited in scope to Basic Concepts (which I > previously just had as a first ch 2 section -- but there's rather a > lot of concepts!). > > I think it's wise to invite comments even when it's not 100% completed. > First, because as opposed to ch 1 there is quite a bit of code here, and > since I'm a Python newbie I may be using non-idiomatic constructs, not > to mention doing worse things. :-) Second, because comments in general > can improve the text. > > > Contents: > > 2.1 Super-basic concept: why programming is not DWIM. 1 > 2.2 Reported errors. 4 > 2.2.1 Case-sensitity. 4 > 2.2.2 Syntax / compilation errors. 4 > 2.2.3 Runtime errors / crashes. 5 > 2.3 A programming exploration tool: turtle graphics. 6 > 2.4 Naming things. 8 > 2.4.1 Naming actions: routines. 8 > 2.4.2 Naming data part I: variables. 11 > 2.4.3 Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. 14 > 2.5.1 Repeating actions automatically: loops. 14 > 2.5.2 Basic comparisions & boolean values. 16 > 2.5.3 Interlude I: a function graph program / about types. 17 > 2.5.4 Automated action choices. 21 > 2.5.5 Value-producing (function-like) routines. 23 > 2.5.6 Interlude II: a graph with zeroes marked / about program > structure. 26 > 2.5.7 Dynamically nested actions: recursive routines. 28 > 2.6 Objects. [Not started on this] 31 > 2.7 Collections. [Not started on this] 31 > > > In Google Docs (both chapters available here): > > > Formats: PDF Added discussion and examples of C curve and dragon curve to section 2.5.7 on recursive routines. Enjoy. :-) I'm especially interested in comments from novices/newbies. E.g., is something unclear or hard to understand, or is it all as clear as military pea soup? Cheers, - Alf From pavlovevidence at gmail.com Wed Nov 11 07:00:09 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 11 Nov 2009 04:00:09 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <852531f9-afe2-4f53-9a1f-129e83161e18@k4g2000yqb.googlegroups.com> <3bf32010-324c-45a1-9399-102fcab794b3@k19g2000yqc.googlegroups.com> Message-ID: On Nov 10, 9:44?pm, Terry Reedy wrote: > Carl Banks wrote: > > > r didn't actually give a good example. ?Here is case where it's > > actually useful. ?(Pretend the regexps are too complicated to be > > parsed with string method.) > > > if re.match(r'go\s+(north|south|east|west)',cmd) as m: > > ? ? hero.move(m.group(1)) > > elif re.match(r'take\s+(\w+)',cmd) as m: > > ? ? hero.pick_up(m.group(1)) > > elif re.match(r'drop\s+(\w+)',cmd) as m: > > ? ? here.put_Down(m.group(1)) > > The effect of this proposal can already be accomplished with a 'pocket' > class Nice metaphorical name. > as has been posted before and again in a slightly different form > in Steve's post. I'm well aware of it, but I didn't think the proposal deserved to be called stupid when it was a reasonable solution to a real need, even though a workable and less intrusive option exists. Carl Banks From daniel.jowett at gmail.com Wed Nov 11 07:16:22 2009 From: daniel.jowett at gmail.com (Daniel Jowett) Date: Wed, 11 Nov 2009 12:16:22 +0000 Subject: Basic list/dictionary question Message-ID: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Greetings, I'm trying to categorize items in a list, by copying them into a dictionary... A simple example with strings doesn't seem to work how I'd expect: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> d = {} >>> d = d.fromkeys(basket, []) >>> d {'orange': [], 'pear': [], 'apple': [], 'banana': []} >>> for fruit in basket: ... d[fruit].append(fruit) ... No if I print d I'd EXPECT.... >>> d {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', 'apple'], 'banana': ['banana']} But what I GET is.... >>> d {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']} >>> >From what I can work out, there is only ONE list that is referenced from the dictionary 4 times. Which would be because the *same empty list* is assigned to every key in the dictionary by the "fromkeys" line. But that seems *seriously *counter-intuitive to me... Would anyone beg to differ and try to rewire my thinking? (I'm from a Java background if that helps) I've already solved the problem a different way, but I am concerned about this counter-intuitiveness as I see it. rgds, Daniel Jowett -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 11 07:20:24 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:20:24 -0800 Subject: Knob label justification In-Reply-To: References: Message-ID: <50697b2c0911110420l9aab83bpb736f28927307369@mail.gmail.com> On Wed, Nov 11, 2009 at 3:25 AM, Hugo L?veill? wrote: > By default, a boolean knob has the text label on the right. How can I make > it on the left? We're not mind readers. We'll need to know which GUI toolkit you're using. Cheers, Chris -- http://blog.rebertia.com From hugo.leveille at visionglobale.com Wed Nov 11 07:21:48 2009 From: hugo.leveille at visionglobale.com (Hugo Leveille) Date: Wed, 11 Nov 2009 07:21:48 -0500 Subject: Knob label justification In-Reply-To: <50697b2c0911110420l9aab83bpb736f28927307369@mail.gmail.com> Message-ID: Sorry, Im using the PythonPanel module of nuke. On 11/11/09 7:20 AM, "Chris Rebert" wrote: > On Wed, Nov 11, 2009 at 3:25 AM, Hugo L?veill? > wrote: >> By default, a boolean knob has the text label on the right. How can I make >> it on the left? > > We're not mind readers. We'll need to know which GUI toolkit you're using. > > Cheers, > Chris > -- > http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 11 07:23:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:23:18 -0800 Subject: Unexpected python exception In-Reply-To: <200911110849.02346.lenz@joinville.udesc.br> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <200911110849.02346.lenz@joinville.udesc.br> Message-ID: <50697b2c0911110423g71b11853wf0fd9b582b23d4cd@mail.gmail.com> On Wed, Nov 11, 2009 at 8:49 AM, Eduardo Lenz wrote: > Em Qua 11 Nov 2009, ?s 03:21:55, Diez B. Roggisch escreveu: >> Richard Purdie schrieb: >> > I've been having problems with an unexpected exception from python which >> > I can summarise with the following testcase: >> > >> > def A(): >> > ? ? import __builtin__ >> > ? ? import os >> > >> > ? ? __builtin__.os = os >> > >> > def B(): >> > ? ? os.stat("/") >> > ? ? import os >> > >> > A() >> > B() >> > >> > which results in: >> > >> > Traceback (most recent call last): >> > ? File "./test.py", line 12, in >> > ? ? B() >> > ? File "./test.py", line 8, in B >> > ? ? os.stat("/") >> > UnboundLocalError: local variable 'os' referenced before assignment >> > >> > If I remove the "import os" from B(), it works as expected. >> > >> >>From what I've seen, its very unusual to have something operate >> > >> > "backwards" in scope in python. Can anyone explain why this happens? >> >> As the import-statement in a function/method-scope doesn't leak the >> imported names into the module scope, python treats them as locals. >> Which makes your code equivalent to >> >> >> x = 1000 >> >> def foo(): >> ? ? ?print x >> ? ? ?x = 10 >> >> Throws the same error. The remedy is to inform python that a specific >> name belongs to global scope, using the "global"-statement. >> >> def foo(): >> ? ? ?global x >> ? ? ?print x >> ? ? ?x = 10 >> >> >> Beware though that then of course *assigning* to x is on global level. >> This shouldn't be of any difference in your case though, because of the >> import-only-once-mechanics of python. >> >> Diez >> > > So...it should not work > > def A(): > ? ? import __builtin__ > ? ? import os > ? ? __builtin__.os = os > > A() > os.stat("/") > > but it does. ?Why ? B() cannot see the import, but the global level can ? The optimization which results in the behavior in question is only done on functions scopes, not global scope. Cheers, Chris -- http://blog.rebertia.com From andreas.loescher at s2005.tu-chemnitz.de Wed Nov 11 07:23:30 2009 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Wed, 11 Nov 2009 13:23:30 +0100 Subject: Unexpected python exception In-Reply-To: References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <1257942210.14502.3.camel@laptop> Python searches for Variables not only in local or global scoop but also in __builtins__. If you do something like __builtins__.os = os, than this variable should be accessible global. If you then write something like: def B(): os.stat("/") import os Python recognises on compile time, that os is a local variable in B and allocates memory for it. All reading or writing now goes to the local variable and not the one in __builtins__. And the local variable has never been assigned to a value and an Exception is thrown. Best From rpurdie at rpsys.net Wed Nov 11 07:37:04 2009 From: rpurdie at rpsys.net (Richard Purdie) Date: Wed, 11 Nov 2009 12:37:04 +0000 Subject: Unexpected python exception In-Reply-To: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> Message-ID: <1257943024.29038.379.camel@dax.rpnet.com> On Wed, 2009-11-11 at 12:21 +0100, Diez B. Roggisch wrote: > As the import-statement in a function/method-scope doesn't leak the > imported names into the module scope, python treats them as locals. > Which makes your code equivalent to > > > x = 1000 > > def foo(): > print x > x = 10 Aha, thanks. This makes it clear whats happening. > Throws the same error. The remedy is to inform python that a specific > name belongs to global scope, using the "global"-statement. > > def foo(): > global x > print x > x = 10 > > > Beware though that then of course *assigning* to x is on global level. > This shouldn't be of any difference in your case though, because of the > import-only-once-mechanics of python. Is there a way to make the "global x" apply to all functions without adding it to each one? I suspect this equates to intentionally "leaking the imported names into the module scope"? :) What I'm trying to do is to avoid having "import X" statements everywhere by changing __builtin__. It seems my approach doesn't have quite the same effect as a true import though. Cheers, Richard From bbxx789_05ss at yahoo.com Wed Nov 11 07:49:48 2009 From: bbxx789_05ss at yahoo.com (7stud) Date: Wed, 11 Nov 2009 04:49:48 -0800 (PST) Subject: installing lxml ? Message-ID: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> I'm trying to install lxml, but I can't figure out the installation instructions. Here: http://codespeak.net/lxml/installation.html it says: 1) Get the easy_install tool. Ok, I went to the easy_install website, downloaded, and installed it. The last two lines of the output during installation said this: Installing easy_install script to /Library/Frameworks/Python.framework/ Versions/2.6/bin Installing easy_install-2.6 script to /Library/Frameworks/ Python.framework/Versions/2.6/bin 2) ...run the following as super-user (or administrator): easy_install lxml On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to easy_install like this: easy_install lxml==2.2.2 On Linux (and most other well-behaved operating systems), easy_install will manage to build the source distribution as long as libxml2 and libxslt are properly installed, including development packages, i.e. header files, etc. Use your package management tool to look for packages like libxml2-dev or libxslt-devel if the build fails, and make sure they are installed. On MacOS-X, use the following to build the source distribution, and make sure you have a working Internet connection, as this will download libxml2 and libxslt in order to build them: STATIC_DEPS=true easy_install lxml ----------- My os is mac os x 10.4.11. But this: STATIC_DEPS=true easy_install lxml is not a valid command: $ sudo STATIC_DEPS=true easy_install lxml Password: sudo: STATIC_DEPS=true: command not found In any case, if I do this: $ sudo easy_install lxml sudo: easy_install: command not found In other words, when I installed easy_install it did not add anything to my PATH which points to the installation directory mentioned during installation: Installing easy_install script to /Library/Frameworks/Python.framework/ Versions/2.6/bin Ok, so I need to use the full path to the easy_install program (which is not mentioned ANYWHERE in the installation instructions), i.e. /Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install ...but this still isn't going to work: $ sudo STATIC_DEPS=true /Library/Frameworks/Python.framework/Versions/ 2.6/bin/easy_install lxml Password: sudo: STATIC_DEPS=true: command not found So what the heck is going on?? Attention developers: you may be one of the best programmers in the world, but if you can't convey how to use your software to the average user, then you are the equivalent of one of the worst programmers on the planet. From mark.leander at topicbranch.net Wed Nov 11 07:52:11 2009 From: mark.leander at topicbranch.net (Mark Leander) Date: Wed, 11 Nov 2009 04:52:11 -0800 (PST) Subject: Microsoft research on code quality References: Message-ID: > http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx Thanks for the link! Hope he next takes on verifying that less code implies less bugs when other factors are constant, thus proving that Python is better than C and Java :-). Mark From joncle at googlemail.com Wed Nov 11 07:55:46 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 11 Nov 2009 04:55:46 -0800 (PST) Subject: Authentication session with urllib2 References: Message-ID: On 11 Nov, 07:02, Ken Seehart wrote: > I'm having some difficulty implementing a client that needs to maintain > an authenticated https: session. > > I'd like to avoid the approach of receiving a 401 and resubmit with > authentication, for two reasons: > > 1. I control the server, and it was easy for me to make a url that > receives a POST with username, password and authenticates the session. ? > The server keeps a session correctly when I test with a browser. ?This > part works fine. > > 2. I don't want to send every request twice. ?Seehttp://bugs.python.org/issue7159?There's no reason why I should have to > do this since I have the ability to keep the server simple. > > What I would really like to do is send one request with the username and > password to establish the session, and then make multiple authenticated > requests where the session information remembers the authentication. > > Is there a way to make this happen in python 2.5.2? > > Keep in mind that this only needs to work with a particular server which > I control. ?It does not need to function as a general purpose browser. ? > The server is powered by Django. > > - Ken How about http://docs.djangoproject.com/en/dev/topics/auth/ and using a urllib2 opener with cookie support ala some examples on http://personalpages.tds.net/~kent37/kk/00010.html ? hth, Jon. From clp2 at rebertia.com Wed Nov 11 07:58:55 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 04:58:55 -0800 Subject: Basic list/dictionary question In-Reply-To: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> Message-ID: <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett wrote: > Greetings, > > I'm trying to categorize items in a list, by copying them into a > dictionary... > A simple example with strings doesn't seem to work how I'd expect: > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>>> d = {} >>>> d = d.fromkeys(basket, []) >>>> d > {'orange': [], 'pear': [], 'apple': [], 'banana': []} >>>> for fruit in basket: > ...???? d[fruit].append(fruit) > ... > > No if I print d I'd EXPECT.... >>>> d > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > 'apple'], 'banana': ['banana']} > > But what I GET is.... >>>> d > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'pear': > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': ['apple', > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > 'orange', 'apple', 'pear', 'orange', 'banana']} >>>> > > From what I can work out, there is only ONE list that is referenced from the > dictionary 4 times. Which would be because the same empty list is assigned > to every key in the dictionary by the "fromkeys" line. But that seems > seriously counter-intuitive to me... Python doesn't do any extra copying in most places unless you /explicitly/ do so yourself or ask it to; so yes, in this case, Python just copies references to the same object and does not copy the object itself. You'd probably be better off using a defaultdict in your particular usecase: http://docs.python.org/library/collections.html#collections.defaultdict Or and so you avoid running into it, default argument values aren't copied either: In [2]: def foo(z, a=[]): ...: a.append(z) ...: return a ...: In [3]: foo(1) Out[3]: [1] In [4]: foo(2) Out[4]: [1, 2] In [5]: foo(2) Out[5]: [1, 2, 2] In [6]: foo(3) Out[6]: [1, 2, 2, 3] In [7]: foo(4,[]) Out[7]: [4] In [8]: foo(5) Out[8]: [1, 2, 2, 3, 5] Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Nov 11 08:04:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 05:04:57 -0800 Subject: Unexpected python exception In-Reply-To: <1257943024.29038.379.camel@dax.rpnet.com> References: <7lvl2kF3gaq2dU1@mid.uni-berlin.de> <1257943024.29038.379.camel@dax.rpnet.com> Message-ID: <50697b2c0911110504k31545b0cr177d9bdbeba118ae@mail.gmail.com> On Wed, Nov 11, 2009 at 4:37 AM, Richard Purdie wrote: > Is there a way to make the "global x" apply to all functions without > adding it to each one? Thankfully, no. > What I'm trying to do is to avoid having "import X" statements > everywhere by changing __builtin__. It seems my approach doesn't have > quite the same effect as a true import though. And you can't just put all your imports together at the top of the file because...? If you're importing the same stuff across multiple modules, I'd say you have a code smell on your hands. Injecting stuff into the builtin namespace purely for convenience's sake is Just Evil (tm). At the least, you can put all the imports in one module and then use `from all_imports import *`, which is just slightly less evil. Cheers, Chris -- http://blog.rebertia.com From steve at lonetwin.net Wed Nov 11 08:10:03 2009 From: steve at lonetwin.net (steve) Date: Wed, 11 Nov 2009 18:40:03 +0530 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <4AFAB7AB.2040309@lonetwin.net> Hi, On 11/11/2009 12:30 PM, r wrote: > [...snip...] > I think what has escaped everyone (including myself until my second > post) is the fact that what really needs to happen is for variable > *assignments* to return a boolean to any "statements" that evaluate > the assignment -- like in an "if" or "elif" construct. The current > "with" statement cannot replace that action and was never meant for > such things. > True. It escaped me too that the assignment was happening and I was only relying on the side-effect to break out of the with statement. So, I'm sorry. > > Very clean, very elegant solution to a messy problem that pops up in > python code quite often. It not only saves one distracting line of > code per usage but makes the code more readable. If there is an > existing solution, Steve's is not it. However, if it is /only/ about saving that one 'distracting' line of the final code that you are concerned about (which I think is the case), how about: ----------------------------------------------------- def deco(f): def assign(x): if x: globals()['value'] = f(x) return True else: globals()['value'] = False return assign @deco def something_that_returns_value(x): # do something with x and return a value return x if something_that_returns_value(1) and value: print value if something_that_returns_value(0) and value: print value # or if you cannot decorate something_that_returns_value in it's definition # for instance, a method from another module, then ... if deco(something_that_returns_value)(0) and value: print value # Note that we've just siphoned off the assignment elsewhere. One problem # tho' is, irrespective of the conditional code being entered 'value' would # be initialized, which is what your ... # # if something_that_returns_value(x) as value: # # ... would also have done (if such a thing existed). # To avoid this side effect we could also do: if (something_that_returns_value(0) and value) or globals().pop('value'): print value # ...but that is beginning to look too much like the perl. Well, that's all i could think of to overcome one line of extra code. cheers, - steve -- random non tech spiel: http://lonetwin.blogspot.com/ tech randomness: http://lonehacks.blogspot.com/ what i'm stumbling into: http://lonetwin.stumbleupon.com/ From samwyse at gmail.com Wed Nov 11 08:11:21 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:11:21 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> Message-ID: <992a972d-15fb-48bc-b019-f931a9aa59b3@a32g2000yqm.googlegroups.com> On Nov 10, 1:23?pm, r wrote: > Forgive me if i don't properly explain the problem but i think the > following syntax would be quite beneficial to replace some redundant > "if's" in python code. > > if something_that_returns_value() as value: > ? ? #do something with value > > # Which can replace the following syntactical construct... > > value = something_that_returns_value() > if value: > ? ? #do something with value I don't like the proposed syntax. I know, it's copied from the "with" statement, but it makes the assignment look like an afterthought. Plus, it's not good English when read aloud. If you want something useful, wait two years for the moratorium to expire and then figure out how to augment the "for" statement with an "if" clause, as is currently done in comprehensions. In other words, instead of this: "for" target_list "in" expression_list ":" suite let's have this: "for" target_list "in" expression_list [ "if" expression_nocond ] ":" suite You don't save much typing, but you really do save one indention level. OTOH, I can see the use of an else-clause following the 'for' as being even more confusing to anyone new to the language. And there's also the fact that an expression_list consists of conditional_expressions, which potentially use "if". You could probably get the parser to figure it out based on the presence of the "else" clause, but it wouldn't be easy. From rt8396 at gmail.com Wed Nov 11 08:11:28 2009 From: rt8396 at gmail.com (r) Date: Wed, 11 Nov 2009 05:11:28 -0800 (PST) Subject: Microsoft research on code quality References: <76d705f7-457d-41a1-90d0-714d860da735@r5g2000yqb.googlegroups.com> Message-ID: <55f3f2c8-5d77-4bf0-96e3-72a6e4445ee2@m26g2000yqb.googlegroups.com> On Nov 7, 5:22?pm, Mensanator wrote: > Microsoft has more to answer for for the fuckups they install > deliberately than for the bugs that get in accidentally. Here!, Here! Very well put Mensanator! From clp2 at rebertia.com Wed Nov 11 08:12:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 11 Nov 2009 05:12:40 -0800 Subject: installing lxml ? In-Reply-To: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: <50697b2c0911110512q3453c30do3a4719dd1fa25151@mail.gmail.com> On Wed, Nov 11, 2009 at 4:49 AM, 7stud wrote: > I'm trying to install lxml, but I can't figure out the installation > instructions. ?Here: > > http://codespeak.net/lxml/installation.html > > it says: > > 1) Get the easy_install tool. > My os is mac os x 10.4.11. I would recommend installing fink (http://www.finkproject.org/) and then `sudo fink install setuptools-py26`. As a bonus, you'll get a more up-to-date Python installed separate from the system one (so you don't need to worry about hosing it). Cheers, Chris -- http://blog.rebertia.com From daniel.jowett at gmail.com Wed Nov 11 08:15:59 2009 From: daniel.jowett at gmail.com (Daniel Jowett) Date: Wed, 11 Nov 2009 13:15:59 +0000 Subject: Basic list/dictionary question In-Reply-To: <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> References: <1119af330911110416j54af18d0g339d671a82c03727@mail.gmail.com> <50697b2c0911110458w3bf6188fo19306cfac1ce1abd@mail.gmail.com> Message-ID: <1119af330911110515r6d388f65u3271b2824fa8bc44@mail.gmail.com> Thanks Chris, yes it's becoming clearer now. And defaultdict looks nice - unfortunately I'm stuck to python 2.4 as I'm using Plone. Thanks again, Daniel 2009/11/11 Chris Rebert > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett > wrote: > > Greetings, > > > > I'm trying to categorize items in a list, by copying them into a > > dictionary... > > A simple example with strings doesn't seem to work how I'd expect: > > > >>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] > >>>> d = {} > >>>> d = d.fromkeys(basket, []) > >>>> d > > {'orange': [], 'pear': [], 'apple': [], 'banana': []} > >>>> for fruit in basket: > > ... d[fruit].append(fruit) > > ... > > > > No if I print d I'd EXPECT.... > >>>> d > > {'orange': ['orange', 'orange'], 'pear': ['pear'], 'apple': ['apple', > > 'apple'], 'banana': ['banana']} > > > > But what I GET is.... > >>>> d > > {'orange': ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], > 'pear': > > ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'], 'apple': > ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana'], 'banana': ['apple', > > 'orange', 'apple', 'pear', 'orange', 'banana']} > >>>> > > > > From what I can work out, there is only ONE list that is referenced from > the > > dictionary 4 times. Which would be because the same empty list is > assigned > > to every key in the dictionary by the "fromkeys" line. But that seems > > seriously counter-intuitive to me... > > Python doesn't do any extra copying in most places unless you > /explicitly/ do so yourself or ask it to; so yes, in this case, Python > just copies references to the same object and does not copy the object > itself. > > You'd probably be better off using a defaultdict in your particular > usecase: > http://docs.python.org/library/collections.html#collections.defaultdict > > Or and so you avoid running into it, default argument values aren't > copied either: > In [2]: def foo(z, a=[]): > ...: a.append(z) > ...: return a > ...: > > In [3]: foo(1) > Out[3]: [1] > > In [4]: foo(2) > Out[4]: [1, 2] > > In [5]: foo(2) > Out[5]: [1, 2, 2] > > In [6]: foo(3) > Out[6]: [1, 2, 2, 3] > > In [7]: foo(4,[]) > Out[7]: [4] > > In [8]: foo(5) > Out[8]: [1, 2, 2, 3, 5] > > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Nov 11 08:23:48 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 08:23:48 -0500 Subject: Calendar Stuff In-Reply-To: <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> References: <4dc0cfea0911100953s106f63arf9b5495ed7b785bc@mail.gmail.com> <50f98a4c0911102212xdfcd740yc042dd74bd389208@mail.gmail.com> Message-ID: <4dc0cfea0911110523j68d6bd41webac713736505140@mail.gmail.com> On Wed, Nov 11, 2009 at 1:12 AM, Simon Forman wrote: > On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi > wrote: > > Hi; > > I have the following code: > > > > import calendar, datetime > > > > def cal(): > > ... > > myCal = calendar.Calendar(calendar.SUNDAY) > > today = datetime.date.today() > > day = today.day > > mo = today.month > > yr = today.year > > # month = myCal.monthdayscalendar(int(time.strftime("%Y")) > > month = myCal.monthdayscalendar(yr, mo) > > print 'hi' > > > > html headers are included. No matter which one of the last two lines I > > comment out, I never get to the point of printing 'hi'. (If I comment > them > > both out, it does print.) What do? > > TIA, > > Victor > > Have you tried walking through the code line-by-line in the > interactive interpreter? > Yes. It works just fine in the interactive interpreter, darn it. > > That should give you an idea of why those lines aren't working. Also, > if your code never prints 'hi', what does it do instead? Hang? Or > give you a traceback? > Hangs. I'd love a traceback! V > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Nov 11 08:25:01 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 08:25:01 -0500 Subject: CGI vs mod_python In-Reply-To: <4af9f122$0$1659$742ec2ed@news.sonic.net> References: <4dc0cfea0911090632q12c4be9amcb66cb29644c3fd4@mail.gmail.com> <968ACD01-6CB8-4C0B-B83A-E4A8FCE9EE90@gmail.com> <4dc0cfea0911090718g5067dc8cl2798a94a3ea7ccff@mail.gmail.com> <4af9f122$0$1659$742ec2ed@news.sonic.net> Message-ID: <4dc0cfea0911110525r44fec7e9jcec78ee30485448c@mail.gmail.com> On Tue, Nov 10, 2009 at 6:12 PM, John Nagle wrote: > ssteinerX at gmail.com wrote: > >> >> On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote: >> >> Yes, obviously. But if CGI is enabled, it should work anyway, should it >>> not? >>> >> >> Depends on what "CGI is enabled" means. >> >> Usually, web servers are not set to just handle cgi scripts from anywhere, >> but only from specific file system locations. Otherwise, an an anonymous >> upload could be executed as CGI and wreak havoc. >> > > If it won't work as a CGI program, which is relatively straightforward, > it probably won't work at all. > > First, write some trivial CGI program in Python and make sure the > environment works - Python loads, the Python program loads, and you > can get a response back. > > Bear in mind that most hosting services don't make much of an attempt > to support Python. Expect important libraries to be missing or obsolete. > The problem was not CGI. It turned out to be line-endings being mangled by Windoze and __invisible __ in my unix editor. Lovely. Thanks anyway, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From samwyse at gmail.com Wed Nov 11 08:26:01 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:26:01 -0800 (PST) Subject: Python C api: create a new object class References: Message-ID: <5e150c6b-4eff-40ee-be93-ea195d674e79@f16g2000yqm.googlegroups.com> On Nov 10, 1:09?pm, "lallous" wrote: > Hello > > I have 3 questions, hope someone can help: > > 1) > How can I create an instance class in Python, currently I do: > > class empty: > ? pass > > Then anytime I want that class (which I treat like a dictionary): > > o = empty() > o.myattr = 1 > etc.... > > Is there is a one line syntax to instantiate an instance? I think that you want this: class c(object): def __init__(self, **kwds): self.__dict__ = kwds x = c(a=1, b=2) print x.a, x.b From sanneh27 at hotmail.com Wed Nov 11 08:29:36 2009 From: sanneh27 at hotmail.com (baboucarr sanneh) Date: Wed, 11 Nov 2009 13:29:36 +0000 Subject: PyQt 2 Exe Message-ID: Hi guys, I wan to make a gui app using pyqt so i have done some thing already now i want to save it as an exe file so that i can give it out to users who dont have pyqt installed (windows users)..Please help me out on this one..thnx Regards $LIM $H at DY _________________________________________________________________ Keep your friends updated?even when you?re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Wed Nov 11 08:31:32 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Nov 2009 15:31:32 +0200 Subject: installing lxml ? References: <63c11baf-3639-4100-8f98-937dc6d77955@r31g2000vbi.googlegroups.com> Message-ID: 7stud writes: > I'm trying to install lxml, but I can't figure out the installation > instructions. Here: ... > My os is mac os x 10.4.11. But this: > > STATIC_DEPS=true easy_install lxml > > is not a valid command: > > $ sudo STATIC_DEPS=true easy_install lxml > Password: > sudo: STATIC_DEPS=true: command not found Maybe STATIC_DEPS=true sudo easy_install lxml And be running Bash or some other Bourne type shell. ... > So what the heck is going on?? > > Attention developers: you may be one of the best programmers in the > world, but if you can't convey how to use your software to the > average user, then you are the equivalent of one of the worst > programmers on the planet. Harsh, but clearly there are problems with the installation procedure. Not nice, especially when running with admin rights. From samwyse at gmail.com Wed Nov 11 08:35:25 2009 From: samwyse at gmail.com (samwyse) Date: Wed, 11 Nov 2009 05:35:25 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: <7ce4f4d8-398e-4080-b874-02338f6c36ef@g23g2000yqh.googlegroups.com> On Nov 11, 3:57?am, "Robert P. J. Day" wrote: > http://groups.google.com/group/unladen-swallow/browse_thread/thread/4... > > ? thoughts? Google's already given us its thoughts: http://developers.slashdot.org/story/09/11/11/0210212/Go-Googles-New-Open-Source-Programming-Language From victorsubervi at gmail.com Wed Nov 11 09:00:44 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 11 Nov 2009 09:00:44 -0500 Subject: Can't Write File In-Reply-To: <4AF9DC3F.7020505@ieee.org> References: <4dc0cfea0911101238n4e010536ga8c24aec80eaca6c@mail.gmail.com> <4AF9DC3F.7020505@ieee.org> Message-ID: <4dc0cfea0911110600l705bb727va6e95e6f6f5df4d8@mail.gmail.com> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel wrote: > Victor Subervi wrote: > >> Hi; >> I've determined the problem in a script is I can't open a file to write >> it: >> script = open(getpic, "w") # where getpic is already defined >> Here are the permissions: >> -rwxr-xr-x 1 root root 4649 Nov 10 12:31 start.py >> What am I doing wrong? >> TIA, >> Victor >> >> >> > Wrong? > > 1) you don't specify the environment, python version, OS, etc. > python 2.4.3 CentOS 5.4 final > 2) you don't show the error traceback > because there are none > 3) you don't indicate the value of getpic at the time this statement > executes > As mentioned earlier, it increments: getpic1.py getpic2.py getpic3.py getpic4.py getpic5.py > 4) you don't indicate what the current working directory is, os.getcwd() > /var/www/html/angrynates.com/stxresort/cart > 5) you don't indicate what directory the start.py is located in > ditto > 6) you don't indicate which user is executing this script (only root can > write to it) > Help me on this. All scripts are owned by root. Is it not root that is executing the script? > 7) you don't tell what the filename of the script is, specif. if it's > called start.py yes, start.py > 8) you don't say what happens if you do an open(getpic, "r"), or > os.path.isfile(getpic) > It doesn't like either of those. Goes to the except in the try. By the time you answer each of those questions, you may notice the answer to > your own question. > I wish that were so. I have written a little script that does nothing but test the line in question [open(getpic, 'w')] and that works. Here's a bigger code snippet with the entire try clause: if 14 < x < 20: # This just shows that it's a pic, not some other type of data y += 1 w += 1 try: # It does this, because I've printed 'getpic1.py' etc. getpic = "getpic" + str(w) + ".py" try: os.remove(getpic) except: pass code = """#! /usr/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login def pic(): user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic%s from products where ID=%s;" cursor.execute(sql) content = cursor.fetchone()[0] cursor.close() print content print 'Content-type: image/jpeg' print pic()""" % (str(w), str(i)) script = open(getpic, "w") # I've deleted everything below this line to the except to test script.write(code) print '
    \n' % str(x) os.chmod(getpic, 0755) print '

    nope%s\n' % str(x) > os.chmod(getpic, 0755) > print '

    nope%s\n' % str(x) > > os.chmod(getpic, 0755) > > print '

    nope%s
    Nordea Bank Finland Abp utf?rdad av Nordea Bank Finland Abp
    B?rskod K?p S?lj Senast F?rfallodag Tid
     NBF AT99 3113A  95,69  97,69  95,69  2011-06-03  12:33
    I didn't try it, but you could presumably use urllib2 to download that url (prob. to a file, so you can repeat the test often without loading the server). One caution, it did ask to store a cookie, and I know nothing about cookie handling in Python. Several cautions: I don't know how target= and magic= were derived, or whether they'll remain stable for more than a day or so. So you can download this file and figure how to parse it, but you'll probably need to also parse the earlier pages, and that could be easier or harder. This page format is very straightforward. If you know you're looking for NBF AT99, you could look for that particular line, then just parse all the td's till the next /tr. No XML logic needed. If you don't know the NBF string, you could look for B?rskod instead. But the big risk you run is the bank could easily change this format quite drastically, at any time. Those td elements don't have to be on separate lines, the browser doesn't care. And the class attribute could change if the CSS also changes correspondingly. Or they could come up with an entirely different way to display the data. All they care about is whether it's readable by the human looking at the browser page. Using xml..elementtree would be a good start; You could build the DOM, look for the table of class 'tableb3', and go in from there But you still run the risk of them changing things. The class name, for example, is just a link to the CSS page which describes how that class object should be displayed. If the name is changed at both ends, no change occurs, except to your script. At this point, you need to experiment. But build a sloppy skeleton first, so you don't invest too much time in any one aspect of the problem. Make sure you can cover the corner cases, then fill in the tough parts. I'd say roughly this order: 1. write code that download the page to a file, given an exact URL. For now, keep that code separate, as it'll probably end up being much more complex, walking through other pages. 2. parse that page, using a simple for loop that looks for some of the key strings mentioned above. 3. Repeat that for a few different URL's, presumably one per bond fund. 4. Make sure the URL's don't go stale over a few days. If they do, you'll have to back up to an earlier link (URL), and parse forward from there. Keep the various pieces in different modules, so that when an assumption breaks, you can recode that assumption pretty much independent of the others. HTH DaveA From Scott.Daniels at Acm.Org Tue Nov 17 10:11:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:11:01 -0800 Subject: overriding __getitem__ for a subclass of dict In-Reply-To: <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> Message-ID: Steve Howell wrote: ... > Eventually, I realized that it was easier to just monkeypatch Django > while I was in test mode to get a more direct hook into the behavior I > was trying to monitor, and then I didn't need to bother with > overriding __getitem__ or creating complicated wrapper objects.... Since nobody else has mentioned it, I'd point you at Mock objects: http://python-mock.sourceforge.net/ for another way to skin the cat that it sounds like has been biting you. They are surprisingly useful for exploratory and regression testing. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Tue Nov 17 10:20:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:20:21 -0800 Subject: python gui builders In-Reply-To: <8u9Mm.35397$Wd1.32454@newsfe15.iad> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: me wrote: > I have looked at the Tk stuff that is built into Python -> not > acceptable. Such insightful analysis, and it is _so_ helpful in stating your needs. > [a lot of guff about unacceptable things] > What Python gui builder is well supported, does not require me to learn > another framework/library, and can crank out stuff for multiple platforms ? Well, let's see. You want to do gui work without learning things. Good luck with that. If you discover how, I'd like to learn tensor analysis without using symbols or operations more complex than addition and subtraction. Maybe your groundwork can help me out with that. I must be in a really cranky mood today. --Scott David Daniels Scott.Daniels at Acm.Org From jsaxton at appsecinc.com Tue Nov 17 10:28:36 2009 From: jsaxton at appsecinc.com (Jonathan Saxton) Date: Tue, 17 Nov 2009 10:28:36 -0500 Subject: New syntax for blocks In-Reply-To: <00863e42$0$26916$c3e8da3@news.astraweb.com> References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: >> Congratulations, you just reinvented one of the most infamous source of >> bugs in C, C++, Java, PHP, javascript and quite a few other languages. >> Believe it or not, but not allowing this in Python was a very deliberate >> design choice. > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > assignment-as-an-expression is nothing compared to the dozens of man- > minutes saved by having one fewer line of code! > > > *wink* And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. (Come to think of it, plagiarizing a bad idea is probably the worse evil.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list From sjmsoft at gmail.com Tue Nov 17 10:29:56 2009 From: sjmsoft at gmail.com (sjm) Date: Tue, 17 Nov 2009 07:29:56 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> On Nov 16, 12:54?pm, Steve Ferg wrote: > Does anybody know a language with this kind of syntax for > ifThenElseEndif? Modern-day COBOL: IF some-condition do-something ELSE do-something-else END-IF. The period is also meaningful as a statement terminator in COBOL, so it's not as clean as one might like. I, too, like the Python way. Cheers, Steve J. Martin From lee_merrill at yahoo.com Tue Nov 17 10:37:55 2009 From: lee_merrill at yahoo.com (Lee Merrill) Date: Tue, 17 Nov 2009 07:37:55 -0800 (PST) Subject: Time travel Message-ID: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> I'm seeing an anomaly in the python time function on March 9, 2008 (the "spring foward" time): >>> time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1)) 1205049599.0 >>> time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1)) 1205046000.0 Does anyone have an idea as to what might cause a 4000 seconds backwards jump on March 9th of last year? I would have expected 3600 seconds. Thanks, Lee P.S. A full program demonstrating the question: #!/usr/bin/env python import time, datetime d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() #!/usr/bin/env python import time, datetime d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple() t1 = time.mktime(d1) t2 = time.mktime(d2) print t1, t2 From himanshu.garg at gmail.com Tue Nov 17 10:41:09 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Tue, 17 Nov 2009 21:11:09 +0530 Subject: Code for finding the 1000th prime In-Reply-To: References: Message-ID: <6f82a7270911170741m6b23e3f8if047bb639ccef76a@mail.gmail.com> 2009/11/15 mrholtsr : > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray > -- > http://mail.python.org/mailman/listinfo/python-list > Consider skipping such "mathematically oriented" exercises in an introductory course on python if targeted to a general audience. From lee_merrill at yahoo.com Tue Nov 17 10:43:04 2009 From: lee_merrill at yahoo.com (Lee Merrill) Date: Tue, 17 Nov 2009 07:43:04 -0800 (PST) Subject: Time travel References: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> Message-ID: <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> And I can't do arithmetic, it is actually about 3600--never mind! On Nov 17, 10:37?am, Lee Merrill wrote: > I'm seeing an anomaly in the python time function on March 9, 2008 > (the "spring foward" time): > > >>> time.mktime((2008, 3, 9, 2, 59, 59, 0, 0, -1)) > 1205049599.0 > >>> time.mktime((2008, 3, 9, 3, 0, 0, 0, 0, -1)) > > 1205046000.0 > > Does anyone have an idea as to what might cause a 4000 seconds > backwards jump on March 9th of last year? I would have expected 3600 > seconds. > > Thanks, > Lee > > P.S. A full program demonstrating the question: > > #!/usr/bin/env python > > import time, datetime > > d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() > #!/usr/bin/env python > > import time, datetime > > d1 = datetime.datetime(2008, 3, 9, 2, 59, 0).timetuple() > d2 = datetime.datetime(2008, 3, 9, 3, 0, 0).timetuple() > t1 = time.mktime(d1) > t2 = time.mktime(d2) > > print t1, t2 From paul at boddie.org.uk Tue Nov 17 10:53:55 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 17 Nov 2009 07:53:55 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <6edf04af-abd3-4034-aa2c-fc8af296fac7@b15g2000yqd.googlegroups.com> On 17 Nov, 14:48, Aaron Watters wrote: > > ... and I still have an issue with the whole "Python is slow" > meme. ?The reason NASA doesn't build a faster Python is because > Python *when augmented with FORTRAN libraries that have been > tested and optimized for decades and are worth billions of dollars > and don't need to be rewritten* is very fast. That's why I wrote that Python's "extensibility using C, C++ and Fortran [has] helped adoption of the language considerably", and Python was particularly attractive to early adopters of the language precisely because of the "scripting" functionality it could give to existing applications, but although there are some reasonable solutions for writing bottlenecks of a system in lower-level programming languages, it can be awkward if those bottlenecks aren't self-contained components or if the performance issues permeate the entire system. [...] > And when someone implements a Mercurial replacement in GO (or C# > or Java) which is faster and more useful than Mercurial, I'll > be very impressed. ?Let me know when it happens (but I'm not > holding my breath). Mercurial is a great example of a Python-based tool with good performance. However, it's still interesting to consider why the implementers chose to rewrite precisely those parts that are implemented using C. I'm sure many people have had the experience of looking at a piece of code and being quite certain of what that code does, and yet wondering why it's so inefficient in vanilla Python. It's exactly this kind of issue that has never really been answered convincingly, other than claims that "Python must be that dynamic and no less" and "it's doing so much more than you think", leaving people to try and mitigate the design issues using clever implementation techniques as best they can. > By the way if it hasn't happened and if he isn't afraid > of public speaking someone should invite Matt Mackall > to give a Python conference keynote. ?Or how about > Bram Cohen for that matter... Bryan O'Sullivan gave a talk on Mercurial at EuroPython 2006, and although I missed that talk for various reasons beyond my control, I did catch his video lightning talk which emphasized performance. That's not to say that we couldn't do with more talks of this nature at Python conferences, however. Paul From Scott.Daniels at Acm.Org Tue Nov 17 10:54:30 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 07:54:30 -0800 Subject: ZipFile - file adding API incomplete? In-Reply-To: References: Message-ID: Glenn Maynard wrote: > I want to do something fairly simple: read files from one ZIP and add > them to another, so I can remove and replace files. This led me to a > couple things that seem to be missing from the API. > > .... zip.write() only takes the filename and > compression method, not a ZipInfo; writestr takes a ZipInfo but only > accepts a string, not a file. Is there an API call I'm missing? > (This seems like the fundamental API for adding files, that write and > writestr should be calling.) Simple answer: its not there in the API. Defining that API correctly is tricky, and fraught with issues about access to the ZipFile object (from both the same thread and from other threads) while it is mid-modification. Nonetheless, a carefully done API that addresses those issues would be valuable. If you do spend the time to get something reliable going, put it someplace public and I predict it will get use. The approach I fiddled with was: * Define a calls to read _portions_ of the raw (compressed, encrypted, whatever) data. * Define a call that locks the ZipFile object and returns a write handle for a single new file. At that point the new file doesn't exist, but reading of other portions of the zip file are allowed. * Only on successful close of the "write handle" is the new directory written. Unfortunately, I never worked very hard at the directory entries, and I realize that the big flaw in this design is that from the moment you start overwriting the existing master directory until you write a new master at the end, your do not have a valid zip file. Also note that you'll have to research standards about _exactly_ what the main header should look like if you use particular features. My stuff did bzip compression as well, and about the "find which bits means what" was where my process broke down. --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Tue Nov 17 10:59:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 16:59:40 +0100 Subject: SCGIServer and unusal termination References: Message-ID: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Eden Kirin wrote: > Hi there, > > I'm playing with SCGIServer > (http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), > everything works just fine, but one thing bothers me. All prints after > try-except block are executed twice after the Ctrl+C is pressed! > > test.py: > #------------------------- > from scgi.scgi_server import SCGIServer > > n = 0 > print "Starting server." > > try: > SCGIServer().serve() > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > # print lines are executed twice (?!) > n += 1 > print "Terminating server, attempt %d." % n > n += 1 > print "Check n: %d." % n > #------------------------- > > This is the output: > > eden at sunce:~/data/project/ScgiServer/src> python test.py > Starting server. > ^CException! > Exception! > Terminating server, attempt 1. > Check n: 2. > Terminating server, attempt 1. > Check n: 2. > eden at sunce:~/data/project/ScgiServer/src> > > > If I put something else in try-except block, code after is executed > normally: > > try: > while 1: > pass > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > eden at sunce:~/data/project/ScgiServer/src> python test.py > Starting server. > ^CException! > Terminating server, attempt 1. > Check n: 2. > eden at sunce:~/data/project/ScgiServer/src> > > Environment is 64bit Ubuntu with Python v2.6.4. > > Is there some reasonable explanation for this behaviour? Thanks in > advance. I can only guess that SCGIServer does something to stdout. Your code isn't executed twice, so the doubling seems to come from writing it twice. Try e.g. redirecting stdout and stderr to different files, and see if things appear once in both. Diez From showell30 at yahoo.com Tue Nov 17 11:12:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 17 Nov 2009 08:12:09 -0800 (PST) Subject: overriding __getitem__ for a subclass of dict References: <649a6f94-3273-4030-9e76-34bd8a6337df@z3g2000prd.googlegroups.com> <7d4d062b-d103-4700-93dc-a874dac8f705@m38g2000yqd.googlegroups.com> <0aae0206-ca56-475b-a1ac-ca3636aae8da@s21g2000prm.googlegroups.com> <874ff7c8-a3d7-46c3-a5e1-80925626958d@y10g2000prg.googlegroups.com> Message-ID: On Nov 17, 7:11?am, Scott David Daniels wrote: > Steve Howell wrote: > > ... > > > Eventually, I realized that it was easier to just monkeypatch Django > > while I was in test mode to get a more direct hook into the behavior I > > was trying to monitor, and then I didn't need to bother with > > overriding __getitem__ or creating complicated wrapper objects.... > > Since nobody else has mentioned it, I'd point you at Mock objects: > ? ? ?http://python-mock.sourceforge.net/ > for another way to skin the cat that it sounds like has been > biting you. ?They are surprisingly useful for exploratory > and regression testing. > Thanks, Scott. We do indeed use mocks in our development, and they are useful. In a way I am trying to emulate some of what mock objects do, but in more on an integration testing mode. For testing the rendering of whole templates, it sometimes becomes convenient for at least some of the objects that your code depends on to maintain their implementation under the hood, but you also want to see where they're going, which is why I want to be able to hook into the dictionary lookup mechanism. Even outside of pure unit testing, mock objects have been pretty versatile in terms of giving us the lay of the land, even when we start getting down into the Django template stack. It is mostly when you start interacting with the ORM that you want to start using real objects. On the one hand you want to isolate yourselves from the ORM behavior to validate the rest of your code, but sometimes it is difficult to emulate the exact semantics of the ORM, or maybe you are trying to get a handle on where the ORM is hitting the database, etc. The so-called "real world" situations are when you start wanting a messy hybrid of mock objects, merely-spied-on objects, real objects, etc. From metolone+gmane at gmail.com Tue Nov 17 11:23:39 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 17 Nov 2009 08:23:39 -0800 Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> Message-ID: "Chris Withers" wrote in message news:4B028AC1.8020307 at simplistix.co.uk... > Cannonbiker wrote: >> Hi, >> unfortunately is my question about server COM (win32com) >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee804cec7f58c6a7# >> without answer. >> >> Please I need Calling Python functions from Excel and receive result >> back in Excel. Can me somebody advise simplest solution please? I am >> more VBA programmer than Python. > > Try http://code.google.com/p/pyinex/ The book Python: Programming on Win32 has a whole chapter on COM, and a section on COM servers. -Mark From __peter__ at web.de Tue Nov 17 11:27:36 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Nov 2009 17:27:36 +0100 Subject: Code for finding the 1000th prime References: Message-ID: mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray When you encounter a problem that you find hard try to split it into simpler subproblems. Example: To find the 1000th prime start with a program that finds all integers i = 1 while True: print i i = i + 1 If you run that it will print integers until you hit Ctrl-C. Python offers an elegant construct that helps you encapsulate the logic of a loop, called "generator". With that we can rewrite the all-integers program as def all_natural_numbers(): i = 1 while True: yield i i = i + 1 for i in all_natural_numbers(): print i Now let's tackle the next step: we want only prime numbers, but don't know how to check for them. How can we postpone that problem and still continue with our program? Easy: introduce a function where the check will ultimately go but have it do something that we do understand right now: def isprime(candidate): return candidate != 42 Why not check for candidate == 42? We would only ever get one "pseudo- prime", but we need at least 1000 of them. With the above bold assumption the program becomes def isprime(candidate): return candidate != 42 def all_natural_numbers(): i = 1 while True: yield i i = i + 1 for i in all_natural_numbers(): if isprime(i): print i While the actual output is a bit unorthodox we now have the structure to print all prime numbers. Again we can wrap the logic into a generator: def isprime(candidate): return candidate != 42 def all_natural_numbers(): i = 1 while True: yield i i = i + 1 def all_prime_numbers(): for i in all_natural_numbers(): if isprime(i): yield i for p in all_prime_numbers(): print p We are actually only interested in the 1000th prime. We can find that by counting over all prime numbers: i = 1 for p in all_prime_numbers(): if i == 1000: print p break i = i + 1 We can wrap this step in a function for future reuse: # all_natural_numbers(), all_prime_numbers(), # and isprime() as before def nth_item(items, n): i = 1 for item in items: if i == n: return item i = i + 1 # raise Exception("here be dragons") print nth_item(all_prime_numbers(), 1000) OK, we now have a nice clean python script that tells us that the 1000th prime number is 1001, a finding that will meet some opposition among mathematicians. Let's turn to wikipedia for help: """ a prime number (or a prime) is a natural number which has exactly two distinct natural number divisors: 1 and itself. ... The number 1 is by definition not a prime number. """ Translated into Python: def isprime(candidate): if candidate == 1: return False # 1 is not a prime for potential_divisor in range(2, candidate): if int(candidate/potential_divisor)*potential_divisor == candidate: # candidate could be divided by potential divisor # without rest, so it's not a prime return False # we didn't find a divisor for candidate # -- it must be a prime return True Now while this test for primality is not the most beautiful code I've ever written it should give you the correct result. As a first step to improve it have a look at the % ("modulo") operator in your textbook. Then try to reduce the number of potential divisors. Peter From eden at bicikl. Tue Nov 17 11:32:58 2009 From: eden at bicikl. (Eden Kirin) Date: Tue, 17 Nov 2009 17:32:58 +0100 Subject: SCGIServer and unusal termination In-Reply-To: <7mfvjcF3hnir0U1@mid.uni-berlin.de> References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: >> Is there some reasonable explanation for this behaviour? Thanks in >> advance. > > I can only guess that SCGIServer does something to stdout. Your code isn't > executed twice, so the doubling seems to come from writing it twice. Yes I know that code isn't executed twice since the value of n remains the same, only print lines are doubled. > Try e.g. redirecting stdout and stderr to different files, and see if things > appear once in both. Redirection of stdout: eden at sunce:~/data/project/ScgiServer/test> python test.py 1> output.txt ^Ceden at sunce:~/data/project/ScgiServer/test> cat output.txt Starting server. Exception! Terminating server, attempt 1. Check n: 2. Starting server. Exception! Terminating server, attempt 1. Check n: 2. Redirecting stderr creates an empty file. I still haven't found the solution. -- www.vikendi.net -/- www.supergrupa.com From reply-to at works.fine.invalid Tue Nov 17 11:33:30 2009 From: reply-to at works.fine.invalid (NickC) Date: 17 Nov 2009 16:33:30 GMT Subject: Vim breaks after Python upgrade Message-ID: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Perhaps OT, but I figure here is where people have seen this commonly. I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now complaining every startup about missing libraries, presumably as some plugins run some python code on initialisation. I'm guessing vim is complaining as it was compiled with python support, and that was 2.5.2, and the compiled-in python library locations no longer exist. I compiled a new vim, so things are ok-ish, but now my system is even further away from standard distro. I'm also a little surprised vim is so clunky as to use hard-coded locations. Do I really have to compile a new vim every python upgrade? 'strings vim' shows some ascii that could be the python library locations. Being quite ignorant of how the linux loader works, could I in future use sed on the vim binary to change every string of "2.5.2" to "2.6.2", or are the library locations used by the loader coded in binary rather than ascii (and so, harder to find)? Thanks, -- NickC From garrickp at gmail.com Tue Nov 17 11:34:49 2009 From: garrickp at gmail.com (Falcolas) Date: Tue, 17 Nov 2009 08:34:49 -0800 (PST) Subject: TODO and FIXME tags References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: <958474ea-f217-49cb-a9f4-0516e955eb14@u16g2000pru.googlegroups.com> On Nov 17, 4:27?am, "Martin P. Hellwig" wrote: > Ben Finney wrote: > > Chris Rebert writes: > > >> 2009/11/16 Yasser Almeida Hern?ndez : > >>> How is the sintaxis for set the TODO and FIXME tags...? > >> There is no special syntax for those. Some people use them in > >> comments, but it's just a convention. > > > This is true. However, the convention is fairly well established, and > > many text editor default configurations will highlight the strings > > ?TODO?, ?FIXME?, and others wherever they appear in comments. > > > There's no widely-followed ?syntax? for this convention, though. I have noticed that within Python XXX as an identifier is fairly popular as well - it's used throughout the standard libraries, and is recognized by many syntax highlighting schemes, as well as Pylint. Garrick From news at schwertberger.de Tue Nov 17 11:38:44 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Tue, 17 Nov 2009 17:38:44 +0100 Subject: Choosing GUI Module for Python In-Reply-To: <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> References: <7888fd98-60e3-48ef-a937-3f6a90e6e047@v30g2000yqm.googlegroups.com> <7m7thpF3g6c3gU1@mid.individual.net> <9b71f81a-951d-434c-a5be-613715b4d4a0@b2g2000yqi.googlegroups.com> Message-ID: <7mg1ssF3fbbi7U1@mid.individual.net> sturlamolden schrieb: > On 14 Nov, 15:35, Dietmar Schwertberger wrote: > >> self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) >> self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, u"MyButton", >> wx.DefaultPosition, wx.DefaultSize, 0 ) >> m_toolBar1.AddControl( m_button1 ) > > I can confirm this. There seems to be a bug in the generation of > Python code for wxToolBar. If anybody faces this problem before a new revision of wxFormBuilder will be available: an XML file need to be updated to correctly include self. The modification: wxformbuilder\output\plugins\common\xml\menutoolbar.pythoncode: Regards, Dietmar From chris at simplistix.co.uk Tue Nov 17 11:40:03 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 Nov 2009 16:40:03 +0000 Subject: Calling Python functions from Excel In-Reply-To: References: <4B028AC1.8020307@simplistix.co.uk> Message-ID: <4B02D1E3.6080308@simplistix.co.uk> Mark Tolonen wrote: > >>> Please I need Calling Python functions from Excel and receive result >>> back in Excel. Can me somebody advise simplest solution please? I am >>> more VBA programmer than Python. >> >> Try http://code.google.com/p/pyinex/ > > The book Python: Programming on Win32 has a whole chapter on COM, and a > section on COM servers. ...and it's generally accepted that COM sucks rocks through straws, so explore alternatives when they're available ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rustompmody at gmail.com Tue Nov 17 11:41:42 2009 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 17 Nov 2009 22:11:42 +0530 Subject: python simply not scaleable enough for google? Message-ID: "Language L is (in)efficient. No! Only implementations are (in)efficient" I am reminded of a personal anecdote. It happened about 20 years ago but is still fresh and this thread reminds me of it. I was attending some workshop on theoretical computer science. I gave a talk on Haskell. I showed off all the good-stuff -- pattern matching, lazy lists, infinite data structures, etc etc. Somebody asked me: Isnt all this very inefficient? Now at that time I was a strong adherent of the Dijkstra-religion and this viewpoint "efficiency has nothing to do with languages, only implementations" traces to him. So I quoted that. Slowing the venerable P S Thiagarajan got up and asked me: Lets say that I have a language with a type 'Proposition' And I have an operation on proposition called sat [ sat(p) returns true if p is satisfiable]... I wont complete the tale other than to say that Ive never had the wind in my sails taken out so completely! So Vincent? I wonder what you would have said in my place? From james at agentultra.com Tue Nov 17 11:42:44 2009 From: james at agentultra.com (J Kenneth King) Date: Tue, 17 Nov 2009 11:42:44 -0500 Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <87hbstqf0b.fsf@agentultra.com> David Cournapeau writes: > On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: >> >>> I don't think Python and Go address the same set of programmer >>> desires. ?For example, Go has a static type system. ?Some programmers >>> find static type systems to be useless or undesirable. ?Others find >>> them extremely helpful and want to use them them. ?If you're a >>> programmer who wants a static type system, you'll probably prefer Go >>> to Python, and vice versa. ?That has nothing to do with implementation >>> speed or development expenditures. ?If Google spent a million dollars >>> adding static types to Python, it wouldn't be Python any more. >> >> ... and I still have an issue with the whole "Python is slow" >> meme. ?The reason NASA doesn't build a faster Python is because >> Python *when augmented with FORTRAN libraries that have been >> tested and optimized for decades and are worth billions of dollars >> and don't need to be rewritten* is very fast. > > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. Relying on a lot of > compiled libraries goes against it. > > I think that python with its scientific extensions is a fantastic > tool, but I would certainly not mind if it were ten times faster. In > particular, the significant cost of function calls makes it quickly > unusable for code which cannot be easily "vectorized" - we have to > resort to using C, etc... to circumvent this ATM. > > Another point which has not been mentioned much, maybe because it is > obvious: it seems that it is possible to makes high level languages > quite fast, but doing so while keeping memory usage low is very > difficult. Incidentally, the same tradeoff appears when working with > vectorized code in numpy/scipy. I think this is the only interesting point in the whole conversation so far. It is possible for highly dynamic languages to be optimized, compiled, and run really fast. The recent versions of SBCL can compile Common Lisp into really fast and efficient binaries. And Lisp could be considered even more dynamic than Python (but that is debateable and I have very little evidence... so grain of salt on that statement). It's possible, it just hasn't been done yet. PyPy is getting there, but development is slow and they could probably use a hand. Instead of waiting on the sidelines for a company to back PyPy developemnt, the passionate Python programmers worth a salt that care about Python development should contribute at least a patch or two. The bigger problem though is probably attention span. A lot of developers today are more apt to simply try the next new language than to roll of their sleeves and think deeply enough to improve the tools they're already invested in. > > David From james.harris.1 at googlemail.com Tue Nov 17 11:55:33 2009 From: james.harris.1 at googlemail.com (James Harris) Date: Tue, 17 Nov 2009 08:55:33 -0800 (PST) Subject: Easy way to play single musical notes in Python References: <163ac43b-4d63-4db2-99c7-9b022c2e1f23@m20g2000vbp.googlegroups.com> Message-ID: <88d19e11-631c-4c72-950c-d213625e5039@x31g2000yqx.googlegroups.com> On 15 Nov, 05:41, r wrote: > On Nov 14, 6:21?pm, James Harris > wrote: > > > Is there a simple way to play musical notes in Python? Something like > > ? voice.play("c4") > > Uhh, tksnack is pretty easy to use IMO, see this link... http://www.daniweb.com/code/snippet216655.html > > No python does not have access to cross platform soundcard > capabilities built into the language. I think there is a wrapper for > csound somewhere. But there are many 3rd party modules that do have > capabilities to some extent. You could make calls to the underlying OS > machinery and there is the winsound module (not exactly what you want > though). Just look over this Google splooge... > > http://www.google.com/search?hl=en&rlz=1C1CHMI_enUS340US340&q=Python+... As I say I was hoping to avoid tk. Thanks for the feedback though. If nothing else is suggested I'll have to try snack. James From J.Fine at open.ac.uk Tue Nov 17 11:59:44 2009 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Tue, 17 Nov 2009 16:59:44 +0000 Subject: FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you Message-ID: Hi A big thanks to Armin Ronacher and Raymond Hettinger for PEP 372: Adding an ordered dictionary to collections I'm using ConfigParser and I just assumed that the options in a section were returned in the order they were given. In fact, I relied on this fact. http://docs.python.org/library/configparser.html And then when I came to test the code it went wrong. After some anguish I looked at ConfigParser and saw I could pass it a dict_type. So I could fix the problem myself by writing an OrderDict. Which I duly prototyped (in about an hour). I then thought - maybe someone has been down this path before. A Google search quickly led me to PEP 372 and hence to http://docs.python.org/dev/py3k/library/configparser.html which says class configparser.RawConfigParser(defaults=None, dict_type=collections.OrderedDict) So all that I want has been done already, and will be waiting for me when I move to Python3. So a big thank you is in order. -- Jonathan From arts.martijn at gmail.com Tue Nov 17 12:09:53 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Tue, 17 Nov 2009 18:09:53 +0100 Subject: CTypes problem. Message-ID: <23739e0a0911170909m2c51782eoe56f31293939d5a0@mail.gmail.com> I wanted to use PyWiiUse, but, well, it sucks Then I thought; it can't be THAT hard, can it? So I began porting WiiUse to Python using ctypes, but apparently, I did something wrong. poll() gives back an event, *but* (there's always a but) the event doesn't register. Or... Well... See for yourself, I think it has something to do with Pointers, but I have no idea, really ;) So, here's the code: Code :-P -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Tue Nov 17 12:27:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 18:27:49 +0100 Subject: Code for finding the 1000th prime References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7mg4olF3idnj9U1@mid.uni-berlin.de> Stefan Behnel wrote: > Robert P. J. Day, 15.11.2009 15:44: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray >> >> it's 7919. > > Now, all that's left to do is write a prime number generator (a random > number generator will do, too, but writing a good one isn't easy), run it > repeatedly in a loop, and check if the returned number is 7919. Once it > compares equal, you can print the result and you're done. That reminds me of the only algorithm I really invented myself: debil sort. It goes like this: L = while not sorted(L): p = generate_random_permutation(len(L)) L = apply_permutation(L, p) print L Great algorithm. Actually works. And the saddest thing: somebody out there certainly has written something like that by accident... I've spotted sorting in O(n^3) (with non-deterministic exceptional termination conditions) already in the wild. Diez From deets at nospam.web.de Tue Nov 17 12:30:05 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 17 Nov 2009 18:30:05 +0100 Subject: SCGIServer and unusal termination References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> Message-ID: <7mg4stF3idnj9U2@mid.uni-berlin.de> Eden Kirin wrote: > Diez B. Roggisch wrote: > >>> Is there some reasonable explanation for this behaviour? Thanks in >>> advance. >> >> I can only guess that SCGIServer does something to stdout. Your code >> isn't executed twice, so the doubling seems to come from writing it >> twice. > > Yes I know that code isn't executed twice since the value of n remains > the same, only print lines are doubled. > >> Try e.g. redirecting stdout and stderr to different files, and see if >> things appear once in both. > > Redirection of stdout: > > eden at sunce:~/data/project/ScgiServer/test> python test.py 1> output.txt > ^Ceden at sunce:~/data/project/ScgiServer/test> cat output.txt > Starting server. > Exception! > Terminating server, attempt 1. > Check n: 2. > Starting server. > Exception! > Terminating server, attempt 1. > Check n: 2. > > Redirecting stderr creates an empty file. I still haven't found the > solution. > Then - save a reference to sys.stdout *before* invoking the server - compare to it after interruption. If it has changed, you at least know that somebody messed with it, and can beat him or whatever you see fit. Diez From python at mrabarnett.plus.com Tue Nov 17 12:31:18 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Nov 2009 17:31:18 +0000 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <4B02DDE6.2050001@mrabarnett.plus.com> Jonathan Saxton wrote: > On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > >>> Congratulations, you just reinvented one of the most infamous >>> source of bugs in C, C++, Java, PHP, javascript and quite a few >>> other languages. Believe it or not, but not allowing this in >>> Python was a very deliberate design choice. >> Oh, but those hundreds of thousands of man-hours lost to bugs >> caused by assignment-as-an-expression is nothing compared to the >> dozens of man- minutes saved by having one fewer line of code! >> >> >> *wink* > > And if I ever find the genius who had the brilliant idea of using = > to mean assignment then I have a particularly nasty dungeon reserved > just for him. Also a foul-smelling leech-infested swamp for those > language designers and compiler writers who followed his example. > (Come to think of it, plagiarizing a bad idea is probably the worse > evil.) > C was derived from BCPL, which used ":=" and "=". Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes did. It's a pity that Guido chose to follow C. From pruebauno at latinmail.com Tue Nov 17 12:39:42 2009 From: pruebauno at latinmail.com (nn) Date: Tue, 17 Nov 2009 09:39:42 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <908f2c47-ee00-4094-993f-764fa7fce9f4@n35g2000yqm.googlegroups.com> On Nov 16, 11:54?am, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? I personally like the "END X" syntax (not that I would want it for Python mind you). It makes it easier to read programs backwards. Foxpro used that syntax form extensively: http://msdn.microsoft.com/en-us/library/b660264t%28VS.80%29.aspx DO CASE ... ENDCASE DO WHILE ... ENDDO FOR EACH ... ENDFOR FOR ... ENDFOR IF ... ENDIF PRINTJOB ... ENDPRINTJOB SCAN ... ENDSCAN TEXT ... ENDTEXT WITH ... ENDWITH From abegong at gmail.com Tue Nov 17 13:02:04 2009 From: abegong at gmail.com (Abe) Date: Tue, 17 Nov 2009 10:02:04 -0800 (PST) Subject: Is there a way to load multiple wxhtmlwindow at the same time? Message-ID: <35f37d98-0605-4912-bd6c-ec98f6541751@m26g2000yqb.googlegroups.com> All - I'm working on a program that loads a series of web pages so the user can view them quickly one after another. I'm using python and wxhtmlwindow, and the page loading is really slow. Is there a simple way to load up the next few pages in the queue while the user is looking at the current page? thanks! - Abe PS - If the answer involves threading, can you please point me to some resources on threading in wx? I know the basics of GUI programming in wx and threading in python, but I have no idea how to put them together. From rt8396 at gmail.com Tue Nov 17 13:15:41 2009 From: rt8396 at gmail.com (r) Date: Tue, 17 Nov 2009 10:15:41 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Nov 17, 9:28?am, Jonathan Saxton wrote: > And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. ?Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. ?(Come to think of it, plagiarizing a bad idea is probably the worse evil.) I think every new programmer wrestles with this dilemma in their first days but very soon after accepts it as reality. As for me it made perfect sense from day one to have '=' mean "assignment" and '==' to mean "equality". Programming is not mathematics (on the contrary) they are two sides of a mountain forever unknowing of each other but sharing the same space. I think the syntax was chosen because the alternatives are even worse AND since assignment is SO common in programming, would you *really* rather type two chars instead of one? From simon.hibbs at gmail.com Tue Nov 17 13:20:12 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Tue, 17 Nov 2009 10:20:12 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> On 16 Nov, 10:06, me wrote: > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? You're looking for a framework/library that doesn't require you to learn it. OK.... I've had this problem for a few years. I've tried PythonCard, WxWidgets with WxDesigner, BoaConstructor, etc. None of them come anywhere close to PyQT/QTDesigner. Dion't get Blackadder It hasn't been updated for several years and is a dead project. In any case it uses QTDesigner for GUI layout anyway. You're better off using Eric or Wing if you want a decent IDE. QT does have a learning curve of course, but you get a lot of power back in return for the investment. I'm just coming to grips with it's MVC framework and the book "Rapid GUI Programming with Python and Qt" is very helpful with that. I wouldn't completely dismiss Tkinter. It's too simple for complex GUIs but I still think it has it's place for basic utilities. Simon Hibbs From clp2 at rebertia.com Tue Nov 17 13:21:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 10:21:15 -0800 Subject: Code for finding the 1000th prime In-Reply-To: <7mg4olF3idnj9U1@mid.uni-berlin.de> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> <7mg4olF3idnj9U1@mid.uni-berlin.de> Message-ID: <50697b2c0911171021k35c757e1qb9453e507334f0e7@mail.gmail.com> On Tue, Nov 17, 2009 at 9:27 AM, Diez B. Roggisch wrote: > Stefan Behnel wrote: >> Robert P. J. Day, 15.11.2009 15:44: >> Now, all that's left to do is write a prime number generator (a random >> number generator will do, too, but writing a good one isn't easy), run it >> repeatedly in a loop, and check if the returned number is 7919. Once it >> compares equal, you can print the result and you're done. > > That reminds me of the only algorithm I really invented myself: debil sort. There's prior art for this algorithm: http://en.wikipedia.org/wiki/Bogosort > It goes like this: > > L = > > while not sorted(L): > ? p = generate_random_permutation(len(L)) > ? L = apply_permutation(L, p) > > print L > > > Great algorithm. Actually works. And the saddest thing: somebody out there > certainly has written something like that by accident... I've spotted > sorting in O(n^3) (with non-deterministic exceptional termination > conditions) already in the wild. Cheers, Chris -- http://blog.rebertia.com From cgrebeld at gmail.com Tue Nov 17 13:22:04 2009 From: cgrebeld at gmail.com (chris grebeldinger) Date: Tue, 17 Nov 2009 10:22:04 -0800 (PST) Subject: 2.6.4 Mac x86_64 ? References: Message-ID: <8c7cd73e-1e0b-43c7-a50f-ded80e656669@h14g2000pri.googlegroups.com> On Nov 14, 12:53?am, Zvezdan Petkovic wrote: > On Nov 13, 2009, at 3:58 PM, chris grebeldinger wrote: > > > Hi All, > > I've been having some trouble getting ax86_64/i386 universal > > readline.so to build against libedit, on MacOS 10.5.6 as Apple does. > > Does anyone have any pointers about what changes I need to make to > > setup.py or readline.c to achive this? > > Has someone already done this and would like to share it? > > The fix for use of native editline (readline emulation) was done and is already implemented on the trunk (2.7). > Please see:http://bugs.python.org/issue6877 > You can find the patch in that tracker issue or here:http://svn.python.org/view?view=rev&revision=74970 > > It was marked for a backport to a future 2.6.5 release too. > > > Are there any plans to provide 64 bit support in future Mac OS 2.6.x > > releases? > > AFAIK, it is already supported. > Perhaps you should specify the exact problems you have. > I believe that a more appropriate place for that would be pythonmac-sig mailing list, though. > > Best regards, > > ? ? ? ? Zvezdan Thank-you, doing a manual backport was easy once I knew where to find the diff =) - Chris From rt8396 at gmail.com Tue Nov 17 13:34:55 2009 From: rt8396 at gmail.com (r) Date: Tue, 17 Nov 2009 10:34:55 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> On Nov 17, 12:20?pm, Simon Hibbs wrote: > I wouldn't completely dismiss Tkinter. It's too simple for complex > GUIs but I still think it has it's place for basic utilities. Agreed! Tkinter (besides myself) seems to be the whipping boy of c.l.py. Tkinter has it's place in Python because of the same simplicity people laboriously lament about! Until something else comes along that can offer the same benefits of Tkinter and a little extra, we are going to keep seeing Tkinter release after release. Guido knows what he is doing people, don't sell the guy short! From cmpython at gmail.com Tue Nov 17 13:36:31 2009 From: cmpython at gmail.com (CM) Date: Tue, 17 Nov 2009 10:36:31 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: On Nov 16, 5:06?am, me wrote: > Good People > > I do not write stuff for humans, as it has been my job to remove > humans from the loop. But I have to make a front end to a > component database where everything was built in Python. > > I have looked at the Tk stuff that is built into Python -> not > acceptable. So looking at wxGlade, Boa Constructor, Python Card. > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. BlackAdder IDE seems to have > this built-in, but am loathe to buy into another GUI tool for a > single job. > > I have not been able to find a decent Python gui builder. The What was your issue with Boa Constructor? It produces wxPython code and I find it works quite well (less well on Linux, but if you use it in Windows, the app will run in Linux w/ minimal need for changes). Of course, whatever route you go, you have to learn the widget toolkit. Che From nick at stinemates.org Tue Nov 17 13:46:25 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 13:46:25 -0500 Subject: Vim breaks after Python upgrade In-Reply-To: <008c54b4$0$26908$c3e8da3@news.astraweb.com> References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: <20091117184625.GA20149@stinemates.org> At least with Gentoo, there's a command to recompile all of the plugins you have installed when upgrading python versions. Your issue is probably related to that. I don't think VIM uses hardcoded locations for scripts at the core. If you have any specific questions about the errors you're receiving, feel free to submit to the VIM mailing list or stop by the IRC channel: #vim on irc.freenode.org On Tue, Nov 17, 2009 at 04:33:30PM +0000, NickC wrote: > > Perhaps OT, but I figure here is where people have seen this commonly. > > I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now > complaining every startup about missing libraries, presumably as > some plugins run some python code on initialisation. I'm guessing vim is > complaining as it was compiled with python support, and that was 2.5.2, > and the compiled-in python library locations no longer exist. > > I compiled a new vim, so things are ok-ish, but now my system is even > further away from standard distro. I'm also a little surprised vim is so > clunky as to use hard-coded locations. Do I really have to compile a new > vim every python upgrade? > > 'strings vim' shows some ascii that could be the python library > locations. Being quite ignorant of how the linux loader works, could I in > future use sed on the vim binary to change every string of "2.5.2" to > "2.6.2", or are the library locations used by the loader coded in binary > rather than ascii (and so, harder to find)? > > Thanks, > > -- > NickC > -- > http://mail.python.org/mailman/listinfo/python-list From randall.walls at gmail.com Tue Nov 17 13:51:12 2009 From: randall.walls at gmail.com (Randall Walls) Date: Tue, 17 Nov 2009 13:51:12 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey Message-ID: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> Greetings, I'm writing a python script to automate creating ODBC connections on a Windows2008 Server (64bit) platform. I created an ODBC manually (using the GUI), for the purposes of fleshing out the 'check for existing' section of the script. Problem: though I can see the key in regedit (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the file specified'. Googling the error brought up the possibility that this key is being impacted by registry redirection ( http://mail.python.org/pipermail/python-win32/2009-February/008862.html), and thus the need to use _winreg.DisableReflectionKey to correct this. I'm new to using _winreg (but not new to python), and though it sounds simple, I can't figure out how to properly use _winreg.DisableReflectionKey to make the _winreg.OpenKey work properly, and there is nearly 0 documentation on how to use _winreg.DisableReflectionKey (though I would be happy to write something up if I could figure the damned thing out). any help is appreciated. Has anyone else run into this before? I realize that Server 2008 is new and that _winreg.DisableReflectionKey was just added, but I'm still hoping SOMEBODY has run into this before. Many thanks, -- Randall Walls Tyler Technologies, Inc -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at stinemates.org Tue Nov 17 13:51:55 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 13:51:55 -0500 Subject: Accessing a Web server --- how? In-Reply-To: <4B012602.7000606@it.uu.se> References: <4B012602.7000606@it.uu.se> Message-ID: <20091117185154.GB20149@stinemates.org> This is what the History and Compare URL translates to: http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=(cc+(detail+(tsid+310746)+(view+hist)))& Some questions.. Do you have an idea on what the tsid is? It looks like it's a unique identifier for the chart and the only thing you'll need to change. Are you only interested in this chart or others? How would you like to extract the data? Is saving the chart enough or would you like to extract values from the chart? On Mon, Nov 16, 2009 at 11:14:26AM +0100, Virgil Stokes wrote: > If one goes to the following URL: > http://www.nordea.se/Privat/Spara%2boch%2bplacera/Strukturerade%2bprodukter/Aktieobligation%2bNr%2b99%2bEuropa%2bAlfa/973822.html > > it contains a link (click on "Current courses NBD AT99 3113A") to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29%29%29& > > and if you now click on the tab labeled "history and compare" this will > take you to: > http://service.nordea.com/nordea-openpages/six.action?target=/nordea.public/bond/nordeabond.page&magic=%28cc+%28detail+%28tsid+310746%29+%28view+hist%29%29%29& > > Finally...This is where I would like to "connect to" the data on a daily > basis or to gather data over different time intervals. I believe that if > I can get some help on this, then I will be able to customize the code > as needed for my own purposes. > > It should be clear that this is financial data on a fond managed by > Nordea Bank AB. Nordea is one of the largest banks in Scandinavia. > > Note, that I do have some experience with Python (2.6 mainly), and find > it a very useful and powerful language. However, I have no experience > with it in the area of Web services. Any suggestions/comments on how to > set up this financial data service project would be greatly appreciated, > and I would be glad to share this project with any interested parties. > > Note, I posted a similar message to the list pywebsvcs; but, received no responses. > > -- V. Stokes > > > -- > http://mail.python.org/mailman/listinfo/python-list From nobody at nowhere.com Tue Nov 17 14:09:22 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:09:22 +0000 Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: On Tue, 17 Nov 2009 17:31:18 +0000, MRAB wrote: >> And if I ever find the genius who had the brilliant idea of using = >> to mean assignment then I have a particularly nasty dungeon reserved >> just for him. Also a foul-smelling leech-infested swamp for those >> language designers and compiler writers who followed his example. >> (Come to think of it, plagiarizing a bad idea is probably the worse >> evil.) >> > C was derived from BCPL, which used ":=" and "=". ISTR that Ritchie said that he chose "=" because assignment is more common than testing for equality, so C's approach meant less typing. > Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes > did. > > It's a pity that Guido chose to follow C. OTOH, functional languages use "=" for binding (let x = ... in ...), which is more like C initialisation (which also uses "="). Python's "=" is somewhere between assignment and binding. It's arguable that Python should also have ":=" for in-place modification (as opposed to re-binding a name). E.g. for an array, "foo := bar" would be equivalent to "foo[:] = bar". From nobody at nowhere.com Tue Nov 17 14:18:23 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:18:23 +0000 Subject: directory wildcard References: Message-ID: On Mon, 16 Nov 2009 14:19:16 -0800, hong zhang wrote: >> ? ? ? ? print >>f, mcs > > This assigns decimal value, how can I assign Hex here to mcs? print >>f, "%x" % mcs From nick at stinemates.org Tue Nov 17 14:18:52 2009 From: nick at stinemates.org (Nick Stinemates) Date: Tue, 17 Nov 2009 14:18:52 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> Message-ID: <20091117191852.GC20149@stinemates.org> >From _winreg.c: "Disables registry reflection for 32-bit processes running on a 64-bit OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit Operating System. If the key is not on the reflection list, the function succeeds but has noeffect. Disabling reflection for a key does not affect reflection of any subkeys." Are there any subkeys which you also need to disable? Parent keys? On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote: > Greetings, > > I'm writing a python script to automate creating ODBC connections on a > Windows2008 Server (64bit) platform. I created an ODBC manually (using the > GUI), for the purposes of fleshing out the 'check for existing' section of > the script. > > Problem: though I can see the key in regedit > (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an > _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find the > file specified'. Googling the error brought up the possibility that this key > is being impacted by registry redirection ( > http://mail.python.org/pipermail/python-win32/2009-February/008862.html), > and thus the need to use _winreg.DisableReflectionKey to correct this. > > I'm new to using _winreg (but not new to python), and though it sounds > simple, I can't figure out how to properly use _winreg.DisableReflectionKey > to make the _winreg.OpenKey work properly, and there is nearly 0 > documentation on how to use _winreg.DisableReflectionKey (though I would be > happy to write something up if I could figure the damned thing out). > > any help is appreciated. Has anyone else run into this before? I realize > that Server 2008 is new and that _winreg.DisableReflectionKey was just > added, but I'm still hoping SOMEBODY has run into this before. > > Many thanks, > > -- > Randall Walls > Tyler Technologies, Inc > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Nov 17 14:19:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 14:19:59 -0500 Subject: YIELD_VALUE Byte Code In-Reply-To: <1257933992.2784.16.camel@laptop> References: <1257933992.2784.16.camel@laptop> Message-ID: Andreas L?scher wrote: > Hi, > I am not sure if this is the right newsgroup, so if not don't hesitate > to tell me. Since there is no CPython internals list, this is the right place to start, even though you might end up having to post a slightly off-topic query to python-devel just to get the attention of whoever has the answer. But there are a few deveoopers who read and post here also. > I am developed a Python to C compiler, so that Byte Code files > automatically can be translated into C Extension Modules. (And it works > pretty well --> http://www.coremountains.com/products/bytecoat/) > > While developing, I found something strange concerning the YIELD_VALUE > OpCode. > > Since Python Version 2.5 it behaves the following: > 1. pop yield value from stack and return it to > a former gen_send_ex() call from Objects/genobject.c > > 2. push the yield value on the stack in gen_send_ex() and return it > > 3. when the generator is executed again, the yield value is > 'poped' from the stack again with the POP_TOP opcode > > Now I found that a little strange: > 1. why is the value removed from the stack, than pushed on the > stack to remove it finally again? the combination of > YIELD_VALUE and TOP_POP seems hard coded in compile.c > which means that a TOP_POP follows every YIELD_VALUE > TOP_POP > > 2. If the semantic of the YIELD_VALUE OpCode has changed, why > is this reached by using another function? Such thing > should be done in the OpCode. > > (e.a.: instead of retval = POP() > --> retval = TOP(); Py_INCREF(retval); ) > > I am a little confused about this. I suspect that what you see reflects the 2.5 change of 'yield x' from a statement to an expression to enable gen.send(). It is possible that someone did the simplest thing that worked, rather than properly rewriting the code. Or maybe the trickery is needed. You can always try a simplyfing patch against the test suite and even submit it if it passes. Terry Jan Reedy From ian at excess.org Tue Nov 17 14:24:43 2009 From: ian at excess.org (Ian Ward) Date: Tue, 17 Nov 2009 14:24:43 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library Message-ID: <4B02F87B.4090305@excess.org> Announcing Urwid 0.9.9 ---------------------- Urwid home page: http://excess.org/urwid/ Updated screen shots: http://excess.org/urwid/examples.html Tarball: http://excess.org/urwid/urwid-0.9.9.tar.gz RSS: http://excess.org/feeds/tag/urwid/ About this release: =================== This release includes many new features developed since the last major release. Urwid now supports 256 and 88 color terminals. A new MainLoop class has been introduced to tie together widgets, user input, screen display and an event loop. Twisted and GLib-based event loops are now supported directly. A new AttrMap class now allows mapping any attribute to any other attribute. Most of the code base has been cleaned up and now has better documentation and testing. Lots of other improvements are listed below. New in this release: ==================== * New support for 256 and 88 color terminals with raw_display and html_fragment display modules * New palette_test example program to demonstrate high color modes * New AttrSpec class for specifying specific colors instead of using attributes defined in the screen's palette * New MainLoop class ties together widgets, user input, screen display and one of a number of new event loops, removing the need for tedious, error-prone boilerplate code * New GLibEventLoop allows running Urwid applications with GLib (makes D-Bus integration easier) * New TwistedEventLoop allows running Urwid with a Twisted reactor * Added new docstrings and doctests to many widget classes * New AttrMap widget supports mapping any attribute to any other attribute, replaces AttrWrap widget * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, Filler and LineBox widgets creates a common method for accessing and updating their contained widgets * New left and right values may be specified in Padding widgets * New command_map for specifying which keys cause actions such as clicking Button widgets and scrolling ListBox widgets * New tty_signal_keys() method of raw_display.Screen and curses_display.Screen allows changing or disabling the keys used to send signals to the application * Added helpful __repr__ for many widget classes * Updated all example programs to use MainLoop class * Updated tutorial with MainLoop usage and improved examples * Renamed WidgetWrap.w to _w, indicating its intended use as a way to implement a widget with other widgets, not necessarily as a container for other widgets * Replaced all tabs with 4 spaces, code is now more aerodynamic (and PEP 8 compliant) * Added saving of stdin and stdout in raw_display module allowing the originals to be redirected * Updated BigText widget's HalfBlock5x4Font * Fixed graph example CPU usage when animation is stopped * Fixed a memory leak related to objects listening for signals * Fixed a Popen3 deprecation warning About Urwid =========== Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. From nobody at nowhere.com Tue Nov 17 14:26:46 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 19:26:46 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > Quote the filenames or escape the spaces: > > C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" > > We've been living with this pain ever since windowed GUIs encouraged users > to put spaces in their file names (Apple, I'm looking at you!). > Fundamentally, if people want the pretty they have to live with the > consequences. We've been living with much worse ever since Unix allowed users to put not only spaces but even newlines in their filenames. At least, those of us who prefer "works" over "sort of works most of the time" have. Then Python 3 decides to pretend that argv and environ and stdin contain text rather than bytes, thereby ensuring that Python 2 will outlive Python 3. From steven.oldner at gmail.com Tue Nov 17 14:27:06 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Tue, 17 Nov 2009 11:27:06 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <908f2c47-ee00-4094-993f-764fa7fce9f4@n35g2000yqm.googlegroups.com> Message-ID: Along the COBOl line is ABAP, the 4gl language from SAP. If today = 'Mon'. message 'oh boy'. elseif today = 'Wed'. message 'Hump day'. elseif today = 'Fri'. message 'TGIF'. else. message 'get to work'. endif. The period is the statement teminator. Indentation and separte lines are just to make it readable. From randall.walls at gmail.com Tue Nov 17 14:29:52 2009 From: randall.walls at gmail.com (Randall Walls) Date: Tue, 17 Nov 2009 14:29:52 -0500 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <20091117191852.GC20149@stinemates.org> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> Message-ID: <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> I don't believe so, but it seems like I'm in a catch 22, where I need to _winreg.OpenKey the key first before I can pass it to _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. I did find out that I can open the key using: hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ODBC\ODBC.INI\ DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells the system to look in the 64bit key area, and not under the Wow6432Node. That brings up problem #2, though... I can't seem to CREATE a key in the above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY (in fact it doesn't accept any options other than key, sub_key). _winreg.CreateKey does work, it just puts the key in SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to use one or the other, and not have to account for both. much obliged On Tue, Nov 17, 2009 at 2:18 PM, Nick Stinemates wrote: > From _winreg.c: > > "Disables registry reflection for 32-bit processes running on a 64-bit > OperatingSystem. Will generally raise NotImplemented if executed on a 32-bit > Operating System. If the key is not on the reflection list, the function > succeeds but has noeffect. Disabling reflection for a key does not affect > reflection of any subkeys." > > Are there any subkeys which you also need to disable? Parent keys? > > > On Tue, Nov 17, 2009 at 01:51:12PM -0500, Randall Walls wrote: > > Greetings, > > > > I'm writing a python script to automate creating ODBC connections on a > > Windows2008 Server (64bit) platform. I created an ODBC manually (using > the > > GUI), for the purposes of fleshing out the 'check for existing' section > of > > the script. > > > > Problem: though I can see the key in regedit > > (HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\DRSQL2000_muXXXX), calling an > > _winreg.OpenKey returns 'WindowsError: [Error 2] The system cannot find > the > > file specified'. Googling the error brought up the possibility that this > key > > is being impacted by registry redirection ( > > http://mail.python.org/pipermail/python-win32/2009-February/008862.html > ), > > and thus the need to use _winreg.DisableReflectionKey to correct this. > > > > I'm new to using _winreg (but not new to python), and though it sounds > > simple, I can't figure out how to properly use > _winreg.DisableReflectionKey > > to make the _winreg.OpenKey work properly, and there is nearly 0 > > documentation on how to use _winreg.DisableReflectionKey (though I would > be > > happy to write something up if I could figure the damned thing out). > > > > any help is appreciated. Has anyone else run into this before? I realize > > that Server 2008 is new and that _winreg.DisableReflectionKey was just > > added, but I'm still hoping SOMEBODY has run into this before. > > > > Many thanks, > > > > -- > > Randall Walls > > Tyler Technologies, Inc > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- Randall -------------- next part -------------- An HTML attachment was scrubbed... URL: From russ.paielli at gmail.com Tue Nov 17 14:36:23 2009 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 17 Nov 2009 11:36:23 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <235b457e-767d-461a-bf45-19d53d7affd8@13g2000prl.googlegroups.com> On Nov 17, 7:28?am, Jonathan Saxton wrote: > On Thu, 12 Nov 2009 21:27:31 +0100, Bruno Desthuilliers wrote: > >> Congratulations, you just reinvented one of the most infamous source of > >> bugs in C, C++, Java, PHP, javascript and quite a few other languages. > >> Believe it or not, but not allowing this in Python was a very deliberate > >> design choice. > > > Oh, but those hundreds of thousands of man-hours lost to bugs caused by > > assignment-as-an-expression is nothing compared to the dozens of man- > > minutes saved by having one fewer line of code! > > > *wink* > > And if I ever find the genius who had the brilliant idea of using = to mean assignment then I have a particularly nasty dungeon reserved just for him. ?Also a foul-smelling leech-infested swamp for those language designers and compiler writers who followed his example. ?(Come to think of it, plagiarizing a bad idea is probably the worse evil.) There is absolutely nothing wrong with using = for assignment. The problem in C was allowing an assignment within a conditional expression. Now *that* was a bonehead idea! (Hingsight is 20/20, of course.) Python does not allow that, so there is no problem. Nor do most other languages allow it. From gerard.blais at gmail.com Tue Nov 17 14:47:46 2009 From: gerard.blais at gmail.com (Gerry) Date: Tue, 17 Nov 2009 11:47:46 -0800 (PST) Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> On Nov 17, 2:26?pm, Nobody wrote: > On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > > Quote the filenames or escape the spaces: > > > C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" > > > We've been living with this pain ever since windowed GUIs encouraged users ? > > to put spaces in their file names (Apple, I'm looking at you!). ? > > Fundamentally, if people want the pretty they have to live with the ? > > consequences. > > We've been living with much worse ever since Unix allowed users to put > not only spaces but even newlines in their filenames. > > At least, those of us who prefer "works" over "sort of works most of the > time" have. > > Then Python 3 decides to pretend that argv and environ and stdin contain > text rather than bytes, thereby ensuring that Python 2 will outlive Python > 3. How about this: lastarg = " ".join(sys.argv[2:]) From falk at mauve.rahul.net Tue Nov 17 14:48:46 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Tue, 17 Nov 2009 19:48:46 +0000 (UTC) Subject: Code for finding the 1000th prime References: Message-ID: In article , mrholtsr wrote: >I am absolutely new to python and barely past beginner in programming. >Also I am not a mathematician. Can some one give me pointers for >finding the 1000th. prime for a course I am taking over the internet >on Introduction to Computer Science and Programming. Thanks, Ray OK, newbie soccer is over. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes Everything you need is in there. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From apt.shansen at gmail.com Tue Nov 17 14:55:47 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 17 Nov 2009 11:55:47 -0800 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c20911171155k3771e054q1476ed78625e2536@mail.gmail.com> On Tue, Nov 17, 2009 at 10:15 AM, r wrote: > On Nov 17, 9:28 am, Jonathan Saxton wrote: > > > And if I ever find the genius who had the brilliant idea of using = to > mean assignment then I have a particularly nasty dungeon reserved just for > him. Also a foul-smelling leech-infested swamp for those language designers > and compiler writers who followed his example. (Come to think of it, > plagiarizing a bad idea is probably the worse evil.) > > I think every new programmer wrestles with this dilemma in their first > days but very soon after accepts it as reality. As for me it made > perfect sense from day one to have '=' mean "assignment" and '==' to > mean "equality". Programming is not mathematics (on the contrary) they > are two sides of a mountain forever unknowing of each other but > sharing the same space. I think the syntax was chosen because the > alternatives are even worse AND since assignment is SO common in > programming, would you *really* rather type two chars instead of one? > Well, equality testing is very very common too... I concede, a bit less common (probably) then assignment, but still. I too never had any issue with getting assignment verses equality-testing with the operations as concepts (except that it is a not terribly uncommon typo for me to type = and mean ==, and I'm quite happy its a syntax error as a result), but in an ideal world? If I were today making my own private little programming language to share with the world... I wish no one would use a single "=" by itself for anything. Neither assignment nor equality testing. For me, the problem comes down to readability; when one sees "x = y", what do they say in their head? "x equals y" -- the meaning of which for an individual can depend on the context and intonation, how they are reading the word "equal" in their head. They might be saying it as a verb, declaring "let x become y", or they my be saying it as an noun, testing "x is equal to y". I don't ever have that problem, but I know a lot of new programmers do and its something which can stick for quite awhile. The word "equal" is just sort of dodgy and fuzzy to the initiate and they start to confuse the two entirely separate concepts (equality testing, assignment) by having the same symbol in programming represent both. Personally! I wish that equality and assignment both got their hands off the bare "=" and let mathematics keep it, and programming take say, ":=" for assignment and "==" for equality testing (or whatever, not advocating a specific syntax) and have "=" by itself be an error all around. So yes, I'd actually much rather type two characters instead of one-- purely in the hypothetical sense that this conversation has gone down. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From kee at kagi.com Tue Nov 17 15:06:27 2009 From: kee at kagi.com (Kee Nethery) Date: Tue, 17 Nov 2009 12:06:27 -0800 Subject: Sample CGI for use with Unit Tests In-Reply-To: References: <1257933992.2784.16.camel@laptop> Message-ID: <85F4B6C5-04F2-478D-B44F-BC51629BAC41@kagi.com> I've been looking for examples of how to run unit tests on a CGI. Didn't find any so I came up with this pared down sample. Don't know where to post example code so I figured I'd just email it to this list. Perhaps it will be findable by others in the future. This CGI with unit test examples takes three separate files to make it work. Copy the example code into the files with the names provided and put them all into the same directory. In my current project, I have lots of unit tests for all the functions I have created, but the main CGI code itself had no unit tests and it really needed them. In this example, the CGI itself is a handful of lines that should never change and the bulk of the processing is in a function. This allows me to create unit tests on everything except the few unchanging lines that are the generic CGI in the cgiRunner.py file. Kee Nethery ---------- cgiRunner.py ------------ #!/usr/bin/env python # 2009-11-17 # this is a simple CGI that is structured to allow for unit tests. # this CGI responds to a GET or a POST # send it anything and it will parrot it back along with client # browser info. # This sample has three files: # cgiRunner.py this file # cgiFunctions.py does the bulk of the CGI processing # cgiUnitTest.py the unittest file for this CGI # In this example, the bulk of the CGI processing occurs in a # function. The function is in a separate file so that the # unit tests can be run against it. All this main does is # convert the URL parameters into a dictionary and # feed that dictionary to the CGI function formatClientData() # This is written for Python 2.6.x I'm using 2.6.4 and am trying to use # code that works with Python 3.x and up. import cgi ## so that I can be a web server CGI import cgiFunctions ## where formatClientData() is located def main(): # give me a list of all the user inputs posted to the cgi formPostData = cgi.FieldStorage() # and turn it into a key value pair dictionary # this uses a list comprehension which I modelled after others # examples. Normally I'd do a for loop but figured this # should be as fast as possible. formPostDict = dict((keyValue,formPostData[keyValue].value) \ for keyValue in formPostData) # this is the call to the actual CGI code. cgiResponseList = cgiFunctions.formatClientData(formPostDict) # I like to return a list from functions so that I can put # validity tests in the function. This one basically returns # True if the GET or POST had any parameters sent to the # CGI, False if none. Just an example. if cgiResponseList[1] == True: cgiResponseData = cgiResponseList[0] else: # if no parameters were sent to the CGI, the response # describes how to add parameters to the URL that # triggers this CGI. cgiResponseData = cgiResponseList[0] + '\n\n' + 'The POST \ or GET you submitted had no user supplied parameters so other than \ client data. The only data that can be returned is the data \ provided by your web client. Most CGIs accept parameters and \ return results based upon those parameters. To provide GET data \ try adding a parameter like "sample=some_text". A URL with \ "sample" as a parameter (and sample2 as a second parameter) might \ look like \n"http://machine.domain.com/cgi-bin/SimpleCgiUnittest.\ py?sample=some_text&sample2=more_text".' # Python 3.x style print statement that works in Python 2.6.x print('Content-type: text/html') print('') print(cgiResponseData) main() ---------- cgiFunctions.py ------------ #!/usr/bin/env python # 2009-11-17 import os ## gets the CGI client values like IP and URL def formatClientData(formPostDict): """ This function contains the guts of the CGI response. It is designed as a function so that I can use unittest to test it. """ # create the output variable and then add stuff to it cgiResponseData = '' # I like to return lists from functions so that more than # some kind of validity checking comes back from the # function. In this case it's a lame validity check but # it's an example. hasFormPostData = (len(formPostDict) > 0) # for something interesting to return, CGI client data cgiResponseData = cgiResponseData + 'from client browser:\n' for cgiKey in list(os.environ.keys()): # for each client data value, add a line to the output cgiResponseData = cgiResponseData + \ str(cgiKey) + ' = ' + os.environ[cgiKey] + '\n' cgiResponseData = cgiResponseData + '\n\nfrom the URL \ POST or GET:\n\n' # cycle through and output the POST or GET inputs for keyValuePair in formPostDict: cgiResponseData = cgiResponseData + \ keyValuePair + ' = ' + formPostDict[keyValuePair] + '\n' return [cgiResponseData, hasFormPostData] ---------- cgiUnitTest.py ------------ #!/usr/bin/env python import cgiFunctions import unittest class cgiTests(unittest.TestCase): ## For debugging of unit tests, to get one unit test ## to run first, UPPERCASE the first char of the unittext ## name (after "test_") so that it runs first then lower ## case it when it should be part of the group. def setUp(self): # this is for setting external stuff before unit tests # this gets called before EVERY test pass def test_formatClientData_With(self): inputDict = {'sample': 'test_text', 'drink': 'tea'} cgiResponse = '''from the URL POST or GET: sample = test_text drink = tea ''' expected0 = True expected1 = True outputList = cgiFunctions.formatClientData(inputDict) outputBoolean0 = (cgiResponse in outputList[0]) self.assertEqual(outputBoolean0,expected0) self.assertEqual(outputList[1],expected1) def test_formatClientData_Without(self): inputDict = {} expected1 = False outputList = cgiFunctions.formatClientData(inputDict) self.assertEqual(outputList[1],expected1) if __name__ == '__main__': testSuite=unittest.TestLoader().loadTestsFromTestCase(cgiTests) unittest.TextTestRunner(verbosity=2).run(testSuite) From tjreedy at udel.edu Tue Nov 17 15:29:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 15:29:47 -0500 Subject: Code for finding the 1000th prime In-Reply-To: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b029e73$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: >> On Sun, 15 Nov 2009, mrholtsr wrote: >> >>> I am absolutely new to python and barely past beginner in programming. >>> Also I am not a mathematician. Can some one give me pointers for >>> finding the 1000th. prime for a course I am taking over the internet >>> on Introduction to Computer Science and Programming. Thanks, Ray Now for a serious answer ;-) The intent of the problem is that you write a function prime_n(n) that returns the nth prime, where 2 is the first. This is different from prime(n), which would return True/False depending on whether n is a prime or not. Then you are to execute prime_n(1000) and submit that. The person who set the problem expects that you will have learned and still remember the definition of prime numbers and a few basic facts about them. Or that you will look these up on a site such as Wikipedia. Since you are not taking a math course, you should expect that the basic facts will be enough. For this problem, the relevant fact is that there is no formula that will directly compute the nth prime from n. Instead, one must generate the first, the second, the third, ...., until reaching the nth. The easiest and direct way to do this is to use primes 1 to i to test whether counts greater than prime i are primes, until you find the (i+1)th prime. You may find references to the Sieve of Eratosthenes. It generates all the primes up to a certain number N by testing prime divisors in a different order. But to use it find the nth, one has to guess that some N will be larger than the nth, run the Sieve, and see whether you got the nth or have to try a larger value of N. For the 1000th, it turns out that N=10000 works. In general picking an N such that N * log(N) is 'comfortably' larger than n will work. But this guessing is not actually necessary in Python which has *expandable* arrays. A different approach, at least as difficult, is to write a program that looks up the answer by accessing a public database of primes. http://en.wikipedia.org/wiki/List_of_primes lists some of these in its External Links section. Terry Jan Reedy From mark.kecko at gmail.com Tue Nov 17 15:30:49 2009 From: mark.kecko at gmail.com (scoopseven) Date: Tue, 17 Nov 2009 12:30:49 -0800 (PST) Subject: QuerySets in Dictionaries References: <008640fa$0$26916$c3e8da3@news.astraweb.com> <5e601dd6-4504-4404-9a75-c523a2df518b@m16g2000yqc.googlegroups.com> <030f77ec$0$1313$c3e8da3@news.astraweb.com> Message-ID: On Nov 14, 11:55?pm, Steven D'Aprano wrote: > On Fri, 13 Nov 2009 14:10:10 -0800, scoopseven wrote: > > I actually had a queryset that was dynamically generated, so I ended up > > having to use the eval function, like this... > > > d = {} > > for thing in things: > > ? ? ? ? query_name = 'thing_' + str(thing.id) > > ? ? ? ? query_string = 'Thing.objects.filter(type=' + str(thing.id) + ? > > ').order_by(\'-date\')[:3]' > > ? ? ? ? executable_string = query_name + ' = Thing.objects.filter > > (type=' + str(thing.id) + ').order_by(\'-date\')[:3]' > > ? ? ? ? exec(executable_string) > > ? ? ? ? d[query_name] = eval(query_string) > > What an unmaintainable mess. > > If I've understood it, you can make it less crap by (1) getting rid of > the unnecessary escaped quotes, (2) avoiding generating the same strings > multiple times, and (3) avoiding string concatenation. > > d = {} > for thing in things: > ? ? expr = "Thing.objects.filter(type=%s).order_by('-date')[:3]" > ? ? expr = rhs % thing.id > ? ? name = "thing_%s" % thing.id > ? ? exec("%s = %s" % (name, expr)) > ? ? d[name] = eval(expr) > > What else can we do to fix it? Firstly, why are you creating local > variables "thing_XXX" (where XXX is the thing ID) *and* dictionary keys > of exactly the same name? I'm sure you don't need the local variables. > (If you think you do, you almost certainly don't.) That gets rid of the > exec. > > Next, let's get rid of the eval: > > d = {} > for thing in things: > ? ? x = thing.id > ? ? name = "thing_%s" % x > ? ? d[name] = Thing.objects.filter(type=x).order_by('-date')[:3] > > About half the size, ten times the speed, and 1000 times the readability. > > Unless I've missed something, you don't need either exec or eval. > > -- > Steven Steven, This worked like a charm! Thank you for your insight, it's greatly appreciated. Mark From http Tue Nov 17 15:48:05 2009 From: http (Paul Rubin) Date: 17 Nov 2009 12:48:05 -0800 Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <7x1vjwswsa.fsf@ruckus.brouhaha.com> Aaron Watters writes: > ... and I still have an issue with the whole "Python is slow" > meme. The reason NASA doesn't build a faster Python is because > Python when augmented with FORTRAN libraries... Do you think that numerics is the only area of programming where users care about speed? > And when someone implements a Mercurial replacement in GO (or C# > or Java) which is faster and more useful than Mercurial, I'll > be very impressed. What about Git? Some people prefer it. From callmeclaudius at gmail.com Tue Nov 17 16:19:53 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Tue, 17 Nov 2009 13:19:53 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <4e29dc6f-0dec-4249-ade8-7ace85eb810c@c3g2000yqd.googlegroups.com> On Nov 16, 5:06?am, me wrote: > Good People > > I do not write stuff for humans, as it has been my job to remove > humans from the loop. But I have to make a front end to a > component database where everything was built in Python. > > I have looked at the Tk stuff that is built into Python -> not > acceptable. So looking at wxGlade, Boa Constructor, Python Card. > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. BlackAdder IDE seems to have > this built-in, but am loathe to buy into another GUI tool for a > single job. > > I have not been able to find a decent Python gui builder. The > last time I did gui garbage was with Borland C++ Builder which > was ok because I was only using win boxen for that project. This > time I am using both Linux and Win. > > What Python gui builder is well supported, does not require me > to learn another framework/library, and can crank out stuff for > multiple platforms ? > > thanks much, > me Glade is pretty easy to use, especially for a simple front end, if you already know python, then the amount of GTK you'd have to learn would be very minimal (5-15 minute crash course in it should suffice.) build your GUI in Glade, link the python code to the xml file, and the go back to coding non-gui stuff in no time. The Glade utility is free software so there's no expense (unless you get charged by the byte on your downloads.) From pengyu.ut at gmail.com Tue Nov 17 16:19:56 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 15:19:56 -0600 Subject: Anything equivalent to cassert in C++? Message-ID: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> There are some assertion code (testing if a condition is false, if it is false, raise an Error object) in my python, which is useful when I test my package. But such case would never occur when in the produce code. If I keep them in if statement, it will take some runtime. I'm wondering what is the practice that take care of the assertion code in python. From ben+python at benfinney.id.au Tue Nov 17 16:21:40 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 18 Nov 2009 08:21:40 +1100 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <87hbssn8yj.fsf@benfinney.id.au> Scott David Daniels writes: > Well, let's see. You want to do gui work without learning things. Good > luck with that. If you discover how, I'd like to learn tensor analysis > without using symbols or operations more complex than addition and > subtraction. Maybe your groundwork can help me out with that. > > I must be in a really cranky mood today. Yeah, it seems that way. Best to let such replies stew in your ?Drafts? folder, get the catharsis from having vented your frustration, then delete them unsent once you feel better. Works wonders for me :-) -- \ ?If society were bound to invent technologies which could only | `\ be used entirely within the law, then we would still be sitting | _o__) in caves sucking our feet.? ?Gene Kan, creator of Gnutella | Ben Finney From tundra at tundraware.com Tue Nov 17 16:25:32 2009 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 17 Nov 2009 15:25:32 -0600 Subject: python gui builders In-Reply-To: <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: Simon Hibbs wrote: > On 16 Nov, 10:06, me wrote: > >> What Python gui builder is well supported, does not require me >> to learn another framework/library, and can crank out stuff for >> multiple platforms ? > > You're looking for a framework/library that doesn't require you to > learn it. OK.... > > I've had this problem for a few years. I've tried PythonCard, > WxWidgets with WxDesigner, BoaConstructor, etc. None of them come > anywhere close to PyQT/QTDesigner. > > Dion't get Blackadder It hasn't been updated for several years and is > a dead project. In any case it uses QTDesigner for GUI layout anyway. > You're better off using Eric or Wing if you want a decent IDE. > > QT does have a learning curve of course, but you get a lot of power > back in return for the investment. I'm just coming to grips with it's > MVC framework and the book "Rapid GUI Programming with Python and Qt" > is very helpful with that. > > I wouldn't completely dismiss Tkinter. It's too simple for complex > GUIs but I still think it has it's place for basic utilities. > > Simon Hibbs +1 Tkinter for the simple stuff -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From sajmikins at gmail.com Tue Nov 17 17:01:38 2009 From: sajmikins at gmail.com (Simon Forman) Date: Tue, 17 Nov 2009 17:01:38 -0500 Subject: Anything equivalent to cassert in C++? In-Reply-To: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> References: <366c6f340911171319m4b1ba31aka1fa45250d141758@mail.gmail.com> Message-ID: <50f98a4c0911171401l5eac45f5sc29267d89f244b61@mail.gmail.com> On Tue, Nov 17, 2009 at 4:19 PM, Peng Yu wrote: > There are some assertion code (testing if a condition is false, if it > is false, raise an Error object) in my python, which is useful when I > test my package. ?But such case would never occur when in the produce > code. If I keep them in if statement, it will take some runtime. I'm > wondering what is the practice that take care of the assertion code in > python. Read the manual: http://docs.python.org/reference/simple_stmts.html#the-assert-statement "In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time." HTH, ~Simon From nobody at nowhere.com Tue Nov 17 17:19:49 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 17 Nov 2009 22:19:49 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote: > How about this: > > lastarg = " ".join(sys.argv[2:]) What about it? IOW, why would you want to do that? From azeynel1 at gmail.com Tue Nov 17 17:38:55 2009 From: azeynel1 at gmail.com (Zeynel) Date: Tue, 17 Nov 2009 14:38:55 -0800 (PST) Subject: Beautifulsoup code that is not running Message-ID: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Hello, Please help with this code suggested in the beautifulsoup group http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa >>> from BeautifulSoup import BeautifulSoup >>> soup = BeautifulSoup (file("test.html").read()) >>> title = soup.find('title') >>> titleString = title.string >>> open('extract.text', 'w').write(titleString) This runs without an error, but nothing is written into the extract.text file. test.html has tags in it. Thank you. From cournape at gmail.com Tue Nov 17 17:43:44 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 18 Nov 2009 07:43:44 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: <7x1vjwswsa.fsf@ruckus.brouhaha.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7x1vjwswsa.fsf@ruckus.brouhaha.com> Message-ID: <5b8d13220911171443o466d72b6s28748a495b823b09@mail.gmail.com> On Wed, Nov 18, 2009 at 5:48 AM, Paul Rubin wrote: > > What about Git? ?Some people prefer it. Git is an interesting example, because it both really pushes performance into its core structure and reasonably complete implementations exist in other languages. In particular, jgit is implemented in java by one of the core git developer, here is what he has to say: http://marc.info/?l=git&m=124111702609723&w=2 I found the comment on "optimizing 5% here and 5 % there" interesting. It is often claimed that optimization should be done after having found the hotspot, but that does not always apply, and I think git is a good example of that. In those cases, using python as the main language does not work well, at least in my experience. Rewriting the slow parts in a compiled language only works if you can identify the slow parts, and even in numerical code, that's not always possible (this tends to happen when you need to deal with many objects interacting together, for example). David From tjreedy at udel.edu Tue Nov 17 17:50:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 17:50:04 -0500 Subject: ast manipulation In-Reply-To: References: Message-ID: Tsize wrote: > Hello, > > I am hoping for a little help. I have been playing with the python > ast module and have run into > an issue that I need a little push on. I would like to be able to > change a specific element in a > specific node in an ast then compile the resulting ast. If you can identify the specific nodes you want to change, no problem > Consider the simplified example below > with its output. In this example I would like a way to change a > specific addition operation. With the NodeTransformer I see how to > change every addition operator but not how to change a specific one. Which specific one or one? > I would like this to work on both the 2.6 and 3.1 branches. Ideally I > would like to read a file, count the instances of an operation of > interest and then use an index to make the changes. If 'specific one' means number i, great. In not, not. > > I am probably missing something simple but I am lost right now. You have not said what 'specific one' means. Nor what your general goal is, why you want to change asts. > > import ast > > class SwitchMinusPlus(ast.NodeTransformer): > > def visit_BinOp(self, node): > node = self.generic_visit(node) > if isinstance(node.op, ast.Add): if isinstance(node.op, ast.Add) and isspecificnode(node): > node.op = ast.Sub() > return node > > myfile = open('trivial.py').read() > print myfile > tree = compile(myfile, '', 'exec', ast.PyCF_ONLY_AST) > print ast.dump(tree, annotate_fields=False, include_attributes=False) > node = SwitchMinusPlus().visit(ast.parse(myfile)) > print ast.dump(node, annotate_fields=False, include_attributes=False) > > Which gives the following output: Note that this code changes the > addition operator to an > subtraction operator at the AST level for every instance. > > a = 8 > b = 6 > c = b + a > d = c + a > Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store > ())], Num(6)), > Assign([Name('c', Store())], BinOp(Name('b', Load()), Add(), Name('a', > Load()))), > Assign([Name('d', Store())], BinOp(Name('c', Load()), Add(), Name('a', > Load())))]) > > Module([Assign([Name('a', Store())], Num(8)), Assign([Name('b', Store > ())], Num(6)), > Assign([Name('c', Store())], BinOp(Name('b', Load()), Sub(), Name('a', > Load()))), > Assign([Name('d', Store())], BinOp(Name('c', Load()), Sub(), Name('a', > Load())))]) From tjreedy at udel.edu Tue Nov 17 17:56:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 17:56:44 -0500 Subject: Vim breaks after Python upgrade In-Reply-To: <008c54b4$0$26908$c3e8da3@news.astraweb.com> References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: NickC wrote: > Perhaps OT, but I figure here is where people have seen this commonly. > > I upgraded Python from my distro's default of 2.5.2 to 2.6.2. Vim is now > complaining every startup about missing libraries, presumably as > some plugins run some python code on initialisation. I'm guessing vim is > complaining as it was compiled with python support, and that was 2.5.2, > and the compiled-in python library locations no longer exist. I believe you should have added 2.6.2 as an alternate installation and left 2.5.x alone. There have been several threads discussing this. > I compiled a new vim, so things are ok-ish, but now my system is even > further away from standard distro. I'm also a little surprised vim is so > clunky as to use hard-coded locations. Do I really have to compile a new > vim every python upgrade? Not if you add rather than substitute. > > 'strings vim' shows some ascii that could be the python library > locations. Being quite ignorant of how the linux loader works, could I in > future use sed on the vim binary to change every string of "2.5.2" to > "2.6.2", or are the library locations used by the loader coded in binary > rather than ascii (and so, harder to find)? > > Thanks, > From greg at cosc.canterbury.ac.nz Tue Nov 17 18:05:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:05:55 +1300 Subject: ANN: PyGUI 2.1 In-Reply-To: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> References: <64f76344-ead5-4544-9276-c70ff183e44a@f20g2000vbl.googlegroups.com> Message-ID: <4B032C53.9030406@cosc.canterbury.ac.nz> r wrote: > I really like this! > > But after looking over your pyGUI it does "seem" that Tkinter has a > richer widget set. PyGUI is a work in progress. I plan to add more widgets, but it will take a while to catch up with what's available in Tkinter and other GUI toolkits. I tend to add widgets as and when I need them for something I'm doing. If anyone has a widget they particularly want, let me know and I'll try to give it priority. From fabio at aptana.com Tue Nov 17 18:09:07 2009 From: fabio at aptana.com (Fabio Zadrozny) Date: Tue, 17 Nov 2009 21:09:07 -0200 Subject: Pydev 1.5.1 Released Message-ID: Hi All, Pydev 1.5.1 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Improvements in the AST rewriter * Improvements on the refactoring engine: o No longer using BRM o Merged with the latest PEPTIC o Inline local available o Extract method bug-fixes o Extract local on multi-line o Generating properties using coding style defined in preferences o Add after current method option added to extract method o A bunch of other corner-case situations were fixed * Bug-fixes: o Minor editor improvements o Adding default forced builtins on all platforms (e.g.: time, math, etc) which wouldn't be on sys.builtin_module_names on some python installations o Adding 'numpy' and 'Image' to the forced builtins always o Ctrl+1: Generate docstring minor fixes o Ctrl+1: Assign to local now follows coding style preferences properly o Exponential with uppercase E working on code-formatting o When a set/get method is found in code-completion for a java class an NPE is no longer thrown o Backspace properly treated in block mode o Setting IRONPYTHONPATH when dealing with Iron Python (projects could not be referenced) o No longer giving spurious 'statement has no effect' inside of lambda and decorators o Fixed new exec in python 3k o Fixed NPE when breakpoint is related to a resource in a removed project o Fixed import problem on regexp that could lead to a recursion. o No longer giving NPE when debugging with the register view open o List access be treated as __getitem__() in the list -- patch from Tassilo Barth o Fix for invalid auto-self added when typing What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and Iron Python 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 - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From greg at cosc.canterbury.ac.nz Tue Nov 17 18:24:37 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:24:37 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> Message-ID: <7mgpm5F27pqogU1@mid.individual.net> David Cournapeau wrote: > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. Relying on a lot of > compiled libraries goes against it. If it were necessary to write a new compiled library every time you wanted to solve a new problem, that would be true. But it's not like that if you pick the right libraries. NumPy, for example, is *extremely* flexible. Someone put in the effort, once, to write it and make it fast -- and now an endless variety of programs can be written very easily in Python to make use of it. -- Greg From fetchinson at googlemail.com Tue Nov 17 18:24:51 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 18 Nov 2009 00:24:51 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <4B0152A4.7050307@excess.org> References: <4B0152A4.7050307@excess.org> Message-ID: On 11/16/09, Ian Ward wrote: > Announcing Urwid 0.9.9 > ---------------------- > > Urwid home page: > http://excess.org/urwid/ > > Updated screen shots: > http://excess.org/urwid/examples.html How did you make the html 'screenshots'? I guess you have some kind of urwid2html tool or some such or is it plain ncurses? Urwid is really cool! Cheers, Daniel > Tarball: > http://excess.org/urwid/urwid-0.9.9.tar.gz > > RSS: > http://excess.org/feeds/tag/urwid/ > > > About this release: > =================== > > This release includes many new features developed since the last major > release. Urwid now supports 256 and 88 color terminals. A new MainLoop > class has been introduced to tie together widgets, user input, screen > display and an event loop. Twisted and GLib-based event loops are now > supported directly. A new AttrMap class now allows mapping any > attribute to any other attribute. Most of the code base has been > cleaned up and now has better documentation and testing. Lots of other > improvements are listed below. > > > New in this release: > ==================== > > * New support for 256 and 88 color terminals with raw_display > and html_fragment display modules > > * New palette_test example program to demonstrate high color > modes > > * New AttrSpec class for specifying specific colors instead of > using attributes defined in the screen's palette > > * New MainLoop class ties together widgets, user input, screen > display and one of a number of new event loops, removing the > need for tedious, error-prone boilerplate code > > * New GLibEventLoop allows running Urwid applications with GLib > (makes D-Bus integration easier) > > * New TwistedEventLoop allows running Urwid with a Twisted reactor > > * Added new docstrings and doctests to many widget classes > > * New AttrMap widget supports mapping any attribute to any other > attribute, replaces AttrWrap widget > > * New WidgetDecoration base class for AttrMap, BoxAdapter, Padding, > Filler and LineBox widgets creates a common method for accessing > and updating their contained widgets > > * New left and right values may be specified in Padding widgets > > * New command_map for specifying which keys cause actions such as > clicking Button widgets and scrolling ListBox widgets > > * New tty_signal_keys() method of raw_display.Screen and > curses_display.Screen allows changing or disabling the keys used > to send signals to the application > > * Added helpful __repr__ for many widget classes > > * Updated all example programs to use MainLoop class > > * Updated tutorial with MainLoop usage and improved examples > > * Renamed WidgetWrap.w to _w, indicating its intended use as a way > to implement a widget with other widgets, not necessarily as > a container for other widgets > > * Replaced all tabs with 4 spaces, code is now more aerodynamic > (and PEP 8 compliant) > > * Added saving of stdin and stdout in raw_display module allowing > the originals to be redirected > > * Updated BigText widget's HalfBlock5x4Font > > * Fixed graph example CPU usage when animation is stopped > > * Fixed a memory leak related to objects listening for signals > > * Fixed a Popen3 deprecation warning > > > About Urwid > =========== > > Urwid is a console UI library for Python. It features fluid interface > resizing, UTF-8 support, multiple text layouts, simple attribute markup, > powerful scrolling list boxes and flexible interface design. > > Urwid is released under the GNU LGPL. > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kw at codebykevin.com Tue Nov 17 18:25:21 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 17 Nov 2009 18:25:21 -0500 Subject: python gui builders In-Reply-To: References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <5634a$4b0330e1$4275d90a$22348@FUSE.NET> On 11/17/09 4:25 PM, Tim Daneliuk wrote: > > +1 Tkinter for the simple stuff > You can actually use Tkinter to do quite sophisticated GUI's that rival anything found in Qt or wx... -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tjreedy at udel.edu Tue Nov 17 18:31:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Nov 2009 18:31:25 -0500 Subject: python simply not scaleable enough for google? In-Reply-To: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: David Cournapeau wrote: > On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters wrote: >>> I don't think Python and Go address the same set of programmer >>> desires. For example, Go has a static type system. Some programmers >>> find static type systems to be useless or undesirable. Others find >>> them extremely helpful and want to use them them. If you're a >>> programmer who wants a static type system, you'll probably prefer Go >>> to Python, and vice versa. That has nothing to do with implementation >>> speed or development expenditures. If Google spent a million dollars >>> adding static types to Python, it wouldn't be Python any more. >> ... and I still have an issue with the whole "Python is slow" >> meme. The reason NASA doesn't build a faster Python is because >> Python *when augmented with FORTRAN libraries that have been >> tested and optimized for decades and are worth billions of dollars >> and don't need to be rewritten* is very fast. > > It is a bit odd to dismiss "python is slow" by saying that you can > extend it with fortran. I find it a bit odd that people are so resistant to evaluating Python as it was designed to be. As Guido designed the language, he designed the implementation to be open and easily extended by assembler, Fortran, and C. No one carps about the fact the dictionary key lookup, say, is writen in (optimized) C rather than pretty Python. Why should Basic Linear Algebra Subroutines (BLAS) be any different? > One of the most significant point of python > IMO is its readability, even for people not familiar with it, and > that's important when doing scientific work. It is readable by humans because it was designed for that purpose. > Relying on a lot of compiled libraries goes against it. On the contrary, Python could be optimized for human readability because it was expected that heavy computation would be delegated to other code. There is no need for scientists to read the optimized code in BLAS, LINPACK, and FFTPACK, in assembler, Fortran, and/or C, which are incorporated in Numpy. It is unfortunate that there is not yet a 3.1 version of Numpy. That is what 3.1 most needs to run faster, as fast as intended. > I think that python with its scientific extensions is a fantastic > tool, but I would certainly not mind if it were ten times faster. Python today is at least 100x as fast as 1.4 (my first version) was in its time. Which is to say, Python today is as fast as C was then. The problem for the future is the switch to multiple cores for further speedups. Terry Jan Reedy From Brian.Mingus at Colorado.EDU Tue Nov 17 18:33:01 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Tue, 17 Nov 2009 16:33:01 -0700 Subject: Beautifulsoup code that is not running In-Reply-To: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Message-ID: <9839a05c0911171533p3ed4162dyae5171d4a7d0101b@mail.gmail.com> On Tue, Nov 17, 2009 at 3:38 PM, Zeynel wrote: > Hello, > > Please help with this code suggested in the beautifulsoup group > > http://groups.google.com/group/beautifulsoup/browse_frm/thread/d288555c6992ceaa > > >>> from BeautifulSoup import BeautifulSoup > > >>> soup = BeautifulSoup (file("test.html").read()) > >>> title = soup.find('title') > >>> titleString = title.string > >>> open('extract.text', 'w').write(titleString) The problem has nothing to do with BeautifulSoup >>> from BeautifulSoup import BeautifulSoup >>> print BeautifulSoup('mytitle').title.string mytitle -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Tue Nov 17 18:33:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 12:33:55 +1300 Subject: python simply not scaleable enough for google? In-Reply-To: References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7x1vjwswsa.fsf@ruckus.brouhaha.com> Message-ID: <7mgq7jF3hp04tU1@mid.individual.net> David Cournapeau wrote: > It is often claimed that optimization should be done after having > found the hotspot, but that does not always apply It's more that if you *do* have a hotspot, you had better find it and direct your efforts there first. E.g. if there is a hotspot taking 99% of the time, then optimising elsewhere can't possibly improve the overall time by more than 1% at the very most. Once there are no hotspots left, then there may be further spread-out savings to be made. -- Greg From rhodri at wildebst.demon.co.uk Tue Nov 17 18:57:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 17 Nov 2009 23:57:55 -0000 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 19:26:46 -0000, Nobody wrote: > On Mon, 16 Nov 2009 23:30:09 +0000, Rhodri James wrote: > >> Quote the filenames or escape the spaces: >> >> C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" >> >> We've been living with this pain ever since windowed GUIs encouraged >> users >> to put spaces in their file names (Apple, I'm looking at you!). >> Fundamentally, if people want the pretty they have to live with the >> consequences. > > We've been living with much worse ever since Unix allowed users to put > not only spaces but even newlines in their filenames. You'll notice I said "encouraged", not "allowed". -- Rhodri James *-* Wildebeest Herder to the Masses From henryzhang62 at yahoo.com Tue Nov 17 19:02:57 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 16:02:57 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <366fee58-612f-491b-8d3f-e8db66122407@x16g2000vbk.googlegroups.com> Message-ID: <89884.96844.qm@web57901.mail.re3.yahoo.com> List, My python script has a strange error. cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx work perfectly. But following get error like: print >>f, cont_tx IOError: [Errno 28] No space left on device def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx Too many layers? Thanks for help. ---henry From bigboss1964 at gmail.com Tue Nov 17 19:03:27 2009 From: bigboss1964 at gmail.com (TerryP) Date: Tue, 17 Nov 2009 16:03:27 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 16, 4:54?pm, Steve Ferg wrote: > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ? if then > ? ? ? ? do stuff > ? ? elif then > ? ? ? ? do stuff > ? ? else > ? ? ? ? do stuff > ? ? endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > > Is there any particular reason why this might be a *bad* language- > design idea? If you search Google, you will likely find some huge comparason of if or flow control statements in general, in zillions of languages. I personally like if expr [then | { | do | :] the code [done | } | ] As long as it starts with if and is immediately followed by expr, I could care less about the rest, unless someone forgets to document it ;-). Lisps cond is also sexy. From bigboss1964 at gmail.com Tue Nov 17 19:06:05 2009 From: bigboss1964 at gmail.com (TerryP) Date: Tue, 17 Nov 2009 16:06:05 -0800 (PST) Subject: Vim breaks after Python upgrade References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: In my experience (FreeBSD), compiling vim with Python, Perl, or Ruby support (etc), generally requires recompiling vim after upgrading the corresponding language. Note also that (if like me) you manage vim installations `by hand` on all systems, rather then use the systems package management system, upgrade tools can not magically do it. From wolfgang at rohdewald.de Tue Nov 17 19:17:49 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 18 Nov 2009 01:17:49 +0100 Subject: python simply not scaleable enough for google? In-Reply-To: References: <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: <200911180117.49361.wolfgang@rohdewald.de> On Wednesday 18 November 2009, Terry Reedy wrote: > Python today is at least 100x as fast as 1.4 (my first version) was > in its time. Which is to say, Python today is as fast as C was > then on the same hardware? That must have been a very buggy C compiler. Or was it a C interpreter? -- Wolfgang From wuwei23 at gmail.com Tue Nov 17 19:25:16 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 16:25:16 -0800 (PST) Subject: ANN: Urwid 0.9.9 - Console UI Library References: <4B0152A4.7050307@excess.org> Message-ID: <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> Daniel Fetchinson wrote: > How did you make the html 'screenshots'? I guess you have some kind of > urwid2html tool or some such or is it plain ncurses? It's all handled in the demo code. This is from tour.py: if urwid.web_display.is_web_request(): screen = urwid.web_display.Screen() else: screen = urwid.raw_display.Screen() > Urwid is really cool! No argument there :) From cournape at gmail.com Tue Nov 17 19:45:28 2009 From: cournape at gmail.com (David Cournapeau) Date: Wed, 18 Nov 2009 09:45:28 +0900 Subject: python simply not scaleable enough for google? In-Reply-To: References: <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: <5b8d13220911171645r5bd56cd5n1021e3aa8336b2bb@mail.gmail.com> On Wed, Nov 18, 2009 at 8:31 AM, Terry Reedy wrote: > David Cournapeau wrote: >> >> On Tue, Nov 17, 2009 at 10:48 PM, Aaron Watters >> wrote: >>>> >>>> I don't think Python and Go address the same set of programmer >>>> desires. ?For example, Go has a static type system. ?Some programmers >>>> find static type systems to be useless or undesirable. ?Others find >>>> them extremely helpful and want to use them them. ?If you're a >>>> programmer who wants a static type system, you'll probably prefer Go >>>> to Python, and vice versa. ?That has nothing to do with implementation >>>> speed or development expenditures. ?If Google spent a million dollars >>>> adding static types to Python, it wouldn't be Python any more. >>> >>> ... and I still have an issue with the whole "Python is slow" >>> meme. ?The reason NASA doesn't build a faster Python is because >>> Python *when augmented with FORTRAN libraries that have been >>> tested and optimized for decades and are worth billions of dollars >>> and don't need to be rewritten* is very fast. >> >> It is a bit odd to dismiss "python is slow" by saying that you can >> extend it with fortran. > > I find it a bit odd that people are so resistant to evaluating Python as it > was designed to be. As Guido designed the language, he designed the > implementation to be open and easily extended by assembler, Fortran, and C. I am well aware of that fact - that's one of the major reason why I decided to go the python route a few years ago instead of matlab, because matlab C api is so limited. > No one carps about the fact the dictionary key lookup, say, is writen in > (optimized) C rather than pretty Python. Why should Basic Linear Algebra > Subroutines (BLAS) be any different? BLAS/LAPACK explicitly contains stuff that can easily be factored out in a library. Linear algebra in general works well because the basic data structures are well understood. You can deal with those as black boxes most of the time (I for example have no idea how most of LAPACK algo work, except for the simple ones). But that's not always the case for numerical computations. Sometimes, you need to be able to go inside the black box, and that's where python is sometimes limited for me because of its cost. To be more concrete, one of my area is speech processing/speech recognition. Most of current engines are based on Hidden Markov Models, and there are a few well known libraries to deal with those, most of the time written in C/C++. You can wrap those in python (and people do), but you cannot really use those unless you deal with them at a high level. If you want to change some core algorithms (to deal with new topology, etc....), you cannot do it without going into C. It would be great to write my own HMM library in python, but I cannot do it because it would be way too slow. There is no easy black-box which I could wrap so that I keep enough flexibility without sacrificing too much speed. Said differently, I would be willing to be one order of magnitude slower than say C, but not 2 to 3 as currently in python when you cannot leverage existing libraries. When the code can be vectorized, numpy and scipy give me this. >> Relying on a lot of compiled libraries goes against it. > > On the contrary, Python could be optimized for human readability because it > was expected that heavy computation would be delegated to other code. There > is no need for scientists to read the optimized code in BLAS, LINPACK, and > FFTPACK, in assembler, Fortran, and/or C, which are incorporated in Numpy. I know all that (I am one of the main numpy develop nowadays), and indeed, writing blas/lapack in python does not make much sense. I am talking about libraries *I* would write. Scipy, for example, contains more fortran and C code than python, without counting the libraries we wrap, and a lot of it is because of speed/memory concern. David From lie.1296 at gmail.com Tue Nov 17 19:59:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 18 Nov 2009 11:59:08 +1100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: References: Message-ID: <4b034728$1@dnews.tpgi.com.au> hong zhang wrote: > List, > > My python script has a strange error. > > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx > > work perfectly. > > But following get error like: > print >>f, cont_tx > IOError: [Errno 28] No space left on device > > def do_cont_tx( is_start): > global cont_tx_started, stdscr > if is_start == START and not cont_tx_started: > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx > > Too many layers? > Thanks for help. Apparently the harddisk where you stored the file is full? From clp2 at rebertia.com Tue Nov 17 20:14:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 17:14:22 -0800 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <50697b2c0911171714y1f3e8eadre495b0dc948798db@mail.gmail.com> On Tue, Nov 17, 2009 at 8:41 AM, Rustom Mody wrote: > "Language L is (in)efficient. No! Only implementations are (in)efficient" > > I am reminded of a personal anecdote. ?It happened about 20 years ago > but is still fresh and this thread reminds me of it. > > I was attending some workshop on theoretical computer science. > I gave a talk on Haskell. > > I showed off all the good-stuff -- pattern matching, lazy lists, > infinite data structures, etc etc. > Somebody asked me: Isnt all this very inefficient? > Now at that time I was a strong adherent of the Dijkstra-religion and > this viewpoint "efficiency has nothing to do with languages, only > implementations" traces to him. So I quoted that. > > Slowing the venerable P S Thiagarajan got up and asked me: > Lets say that I have a language with a type 'Proposition' > And I have an operation on proposition called sat [ sat(p) returns > true if p is satisfiable]... > > I wont complete the tale other than to say that Ive never had the wind > in my sails taken out so completely! > > So Vincent? I wonder what you would have said in my place? I'm not Vincent, but: The sat() operation is by definition in inefficient, regardless of language? Cheers, Chris -- http://blog.rebertia.com From see at signature.invalid Tue Nov 17 20:33:24 2009 From: see at signature.invalid (Nigel Rowe) Date: Wed, 18 Nov 2009 12:33:24 +1100 Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: On Tue, 17 Nov 2009 05:21, Tobiah wrote in comp.lang.python <>: > >>> Let me >>> be clear, given 2min, how many primes can you find, they need not be in >>> order or consecutive. > > Do they have to go from low to high? :( ) 1) google list of prime numbers 2) see "Prime numbers list" in the results (number 3 in the results) 3) click link that leads to www.prime-numbers.org I found 455042511 prime numbers in approx 15 seconds. Is that what you wanted? -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) fisheggs (stop) name From henryzhang62 at yahoo.com Tue Nov 17 20:40:05 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 17:40:05 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b034728$1@dnews.tpgi.com.au> Message-ID: <530564.99251.qm@web57905.mail.re3.yahoo.com> --- On Tue, 11/17/09, Lie Ryan wrote: > From: Lie Ryan > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Tuesday, November 17, 2009, 6:59 PM > hong zhang wrote: > > List, > > > > My python script has a strange error. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > ??? with open(i, 'w') as f: > > ??? ??? print >>f, > cont_tx > > > > work perfectly. > > > > But following get error like: > > print >>f, cont_tx > > IOError: [Errno 28] No space left on device > > > > def do_cont_tx( is_start): > > ??? global cont_tx_started, stdscr > > ??? if is_start == START and not > cont_tx_started: > > ??? ??? cont_tx = 1 > > ??? ??? for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > ??? ??? > ??? with open(i, 'w') as f: > > ??? ??? > ??? ??? print >>f, > cont_tx > > > > Too many layers? > > Thanks for help. > > Apparently the harddisk where you stored the file is full? I have plenty space see: $ df -l Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 74027808 4910016 65357380 7% / but following is good. cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx > -- http://mail.python.org/mailman/listinfo/python-list > From python.list at tim.thechases.com Tue Nov 17 20:47:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Nov 2009 19:47:25 -0600 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b034728$1@dnews.tpgi.com.au> References: <4b034728$1@dnews.tpgi.com.au> Message-ID: <4B03522D.90909@tim.thechases.com> >> for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> with open(i, 'w') as f: >> print >>f, cont_tx >> >> work perfectly. >> >> But following get error like: >> print >>f, cont_tx >> IOError: [Errno 28] No space left on device > > Apparently the harddisk where you stored the file is full? Likely a misinterpretation of the error. I'm guessing either one needs to be root to write to this [likely virtual] file, or a member of an associated group. It would help to have the output of bash$ whoami bash$ id and bash$ ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx I'd be particularly interested in the group association and the permission bits. -tkc From henryzhang62 at yahoo.com Tue Nov 17 20:54:57 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Tue, 17 Nov 2009 17:54:57 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4B03522D.90909@tim.thechases.com> Message-ID: <646737.85745.qm@web57908.mail.re3.yahoo.com> --- On Tue, 11/17/09, Tim Chase wrote: > From: Tim Chase > Subject: Re: IOError: [Errno 28] No space left on device > To: "Lie Ryan" > Cc: python-list at python.org > Date: Tuesday, November 17, 2009, 7:47 PM > >> for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> ??? with open(i, 'w') as f: > >> ??? ??? print > >>f, cont_tx > >> > >> work perfectly. > >> > >> But following get error like: > >> print >>f, cont_tx > >> IOError: [Errno 28] No space left on device > > > > Apparently the harddisk where you stored the file is > full? > > Likely a misinterpretation of the error.? I'm guessing > either one needs to be root to write to this [likely > virtual] file, or a member of an associated group.? It > would help to have the output of > > bash$ whoami > bash$ id > > and > > bash$ ls -lsF > /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx It is root. see following. File "./henry-cont-tx", line 186, in do_cont_tx print >>f, cont_tx IOError: [Errno 28] No space left on device root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# whoami root root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id uid=0(root) gid=0(root) groups=0(root) root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx 0 -rw------- 1 root root 0 2009-11-17 17:51 /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx > > I'd be particularly interested in the group association and > the permission bits. > > -tkc > > > > > > > -- http://mail.python.org/mailman/listinfo/python-list > From skippy.hammond at gmail.com Tue Nov 17 20:59:32 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 18 Nov 2009 12:59:32 +1100 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> Message-ID: <4B035504.4050508@gmail.com> On 18/11/2009 6:29 AM, Randall Walls wrote: > I don't believe so, but it seems like I'm in a catch 22, where I need to > _winreg.OpenKey the key first before I can pass it to > _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. > > I did find out that I can open the key using: > hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ODBC\ODBC.INI\ > DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) > > The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells > the system to look in the 64bit key area, and not under the Wow6432Node. > That brings up problem #2, though... I can't seem to CREATE a key in the > above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY > (in fact it doesn't accept any options other than key, sub_key). > _winreg.CreateKey does work, it just puts the key in > SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to > use one or the other, and not have to account for both. It looks like _winreg needs to be enhanced to make the RegCreateKeyEx API function available. It can be called via the win32api module of pywin32, or could also be called via ctypes. HTH, Mark From bartc at freeuk.com Tue Nov 17 21:00:42 2009 From: bartc at freeuk.com (bartc) Date: Wed, 18 Nov 2009 02:00:42 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: "Steve Ferg" wrote in message news:ff92db5b-9cb0-4a72-b339-2c5ac02fbad0 at p36g2000vbn.googlegroups.com... > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. I like Python > just the way it is. I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > if then > do stuff > elif then > do stuff > else > do stuff > endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? I think Algol 68 was responsible for a lot of this syntax, but there must be huge numbers of languages using that those forms now, apart from C-family languages which evolved their own syntax (and even in C, the preprocessor uses #if, #elif, #endif). Some syntaxes insist on ugly begin...end blocks, but the bracketing introduced by Algol68 (maybe even earlier) showed that these are redundant: if s then s [elsif s]* [else s] fi where s is any sequence of statements. The statements after the 'then' are delimited by an elsif, else or fi (endif) keyword. The endif (or fi) is necessary to show where the final statement sequence ends, and fixes the dangling-else problem. (And Algol68 also allowed this short form: (a | b | c) which is just if a then b else c fi, although it gets a bit hairy with elsif in there too..) > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: ... You're not the first to think that.. I use these forms in my own language designs for that reason. And when people write pseudo-code, it always seems to look like this, then they go and implement it in some god-forsaken syntax like C++... ...For some reason I can't quite understand, this sort of clear syntax seems to be looked down on by 'real' programmers, who perhaps think code like this can't be taken seriously. -- Bartc From metolone+gmane at gmail.com Tue Nov 17 21:09:13 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 17 Nov 2009 18:09:13 -0800 Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: "Chris Withers" wrote in message news:4B02D1E3.6080308 at simplistix.co.uk... > Mark Tolonen wrote: >> >>>> Please I need Calling Python functions from Excel and receive result >>>> back in Excel. Can me somebody advise simplest solution please? I am >>>> more VBA programmer than Python. >>> >>> Try http://code.google.com/p/pyinex/ >> >> The book Python: Programming on Win32 has a whole chapter on COM, and a >> section on COM servers. > > ...and it's generally accepted that COM sucks rocks through straws, so > explore alternatives when they're available ;-) > > Chris True, but as usual Python makes it pretty darn easy (requires PyWin32): ------------- ex.py ------------------------------- class Example(object): _public_methods_ = ['Add','Mul'] _reg_progid_ = 'MyPython.Example' _reg_clsid_ = '{insert_GUID_here}' def Add(self,a,b): return a+b def Mul(self,a,b): return a*b if __name__ == '__main__': import win32com.server.register win32com.server.register.UseCommandLine(Example) --------------------------------------------------------- -------------- Excel Macro ---------------------- Sub Testit() Set ex = CreateObject("MyPython.Example") Range("A1") = ex.Add(1, 2) Range("A2") = ex.Mul(3, 4) End Sub -------------------------------------------------------- Just run the script to register the server. "ex.py --unregister" will remove it. -Mark From pengyu.ut at gmail.com Tue Nov 17 21:18:19 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:18:19 -0600 Subject: WindowsError is not available on linux? Message-ID: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> It's not clear to me whether WindowsError is available on linux or not, after I read the document. But I see WindowsError in shutil.py. Could you somebody let me know what cause the following error? >>> try: ... raise WindowsError('WindowsError') ... except WindowsError as e: ... print e ... Traceback (most recent call last): File "", line 3, in NameError: name 'WindowsError' is not defined From lie.1296 at gmail.com Tue Nov 17 21:23:41 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 18 Nov 2009 13:23:41 +1100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: References: Message-ID: <4b035afa$1@dnews.tpgi.com.au> hong zhang wrote: > > --- On Tue, 11/17/09, Tim Chase wrote: > >> From: Tim Chase >> Subject: Re: IOError: [Errno 28] No space left on device >> To: "Lie Ryan" >> Cc: python-list at python.org >> Date: Tuesday, November 17, 2009, 7:47 PM >>>> for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>>> with open(i, 'w') as f: >>>> print >>>> f, cont_tx >>>> >>>> work perfectly. >>>> >>>> But following get error like: >>>> print >>f, cont_tx >>>> IOError: [Errno 28] No space left on device >>> Apparently the harddisk where you stored the file is >> full? >> >> Likely a misinterpretation of the error. I'm guessing >> either one needs to be root to write to this [likely >> virtual] file, or a member of an associated group.. It >> would help to have the output of >> >> bash$ whoami >> bash$ id >> >> and >> >> bash$ ls -lsF >> /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx > > It is root. see following. > > File "../henry-cont-tx", line 186, in do_cont_tx > print >>f, cont_tx > IOError: [Errno 28] No space left on device > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# whoami > root > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id > uid=0(root) gid=0(root) groups=0(root) > root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx > 0 -rw------- 1 root root 0 2009-11-17 17:51 /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx > Where is the output file? Could it possibly be located in a device that is impossible to write even for root (e.g. filesystem mounted as read-only or CD or floppy with the readonly switch active or NTFS partition without ntfs-3g driver)? Can you write to this file from outside python (try echo-ing to the file)? What's the permission of the folder? The output of your 'df' shows that you only have one partition (for root) and nothing else; it is quite uncommon for linux/unix to be setup with only one partition, you didn't trim anything right? What's the output of: $ mount From benjamin.kaplan at case.edu Tue Nov 17 21:25:20 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Nov 2009 21:25:20 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: > It's not clear to me whether WindowsError is available on linux or > not, after I read the document. But I see WindowsError in shutil.py. > Could you somebody let me know what cause the following error? > >>>> try: > ... ? raise WindowsError('WindowsError') > ... except WindowsError as e: > ... ? print e > ... > Traceback (most recent call last): > ?File "", line 3, in > NameError: name 'WindowsError' is not defined > -- does this answer your question? Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import shutil >>> print shutil.WindowsError None > http://mail.python.org/mailman/listinfo/python-list > From pengyu.ut at gmail.com Tue Nov 17 21:28:16 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:28:16 -0600 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' Message-ID: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> I don't see any different between the following code in terms of output. Are they exactly the same ('as' v.s. ',')? try: raise IOError('IOError') except IOError as e: print e try: raise IOError('IOError') except IOError, e: print e From steven at REMOVE.THIS.cybersource.com.au Tue Nov 17 21:32:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 02:32:06 GMT Subject: python simply not scaleable enough for google? References: Message-ID: On Tue, 17 Nov 2009 22:11:42 +0530, Rustom Mody wrote: > "Language L is (in)efficient. No! Only implementations are > (in)efficient" > > I am reminded of a personal anecdote. It happened about 20 years ago > but is still fresh and this thread reminds me of it. > > I was attending some workshop on theoretical computer science. I gave a > talk on Haskell. > > I showed off all the good-stuff -- pattern matching, lazy lists, > infinite data structures, etc etc. > Somebody asked me: Isnt all this very inefficient? Now at that time I > was a strong adherent of the Dijkstra-religion and this viewpoint > "efficiency has nothing to do with languages, only implementations" > traces to him. So I quoted that. > > Slowing the venerable P S Thiagarajan got up and asked me: Lets say that > I have a language with a type 'Proposition' And I have an operation on > proposition called sat [ sat(p) returns true if p is satisfiable]... I assume you're referring to this: http://en.wikipedia.org/wiki/Boolean_satisfiability_problem which is N-P complete and O(2**N) (although many such problems can be solved rapidly in polynomial time). > I wont complete the tale other than to say that Ive never had the wind > in my sails taken out so completely! > > So Vincent? I wonder what you would have said in my place? I won't answer for Vincent, but I would have made five points: (1) The existence of one inherently slow function in a language does not mean that the language itself is slow overall. It's not clear exactly what "overall" means in the context of a language, but one function out of potentially thousands obviously isn't it. (2) Obviously the quality of implementation for the sat function will make a major difference as far as speed goes, so the speed of the function is dependent on the implementation. (3) Since the language definition doesn't specify an implementation, no prediction of the time needed to execute the function can be made. At most we know how many algorithmic steps the function will take, given many assumptions, but we have no idea of the constant term. The language definition would be satisfied by having an omniscient, omnipotent deity perform the O(2**N) steps required by the algorithm infinitely fast, i.e. in constant (zero) time, which would make it pretty fast. The fact that we don't have access to such deities to do our calculations for us is an implementation issue, not a language issue. (4) In order to justify the claim that the language is slow, you have to define what you are comparing it against and how you are measuring the speed. Hence different benchmarks give different relative ordering between language implementations. You must have a valid benchmark, and not stack the deck against one language: compared to (say) integer addition in C, yes the sat function is slow, but that's an invalid comparison, as invalid as comparing the sat function against factorizing a one million digit number. ("Time to solve sat(P) -- sixty milliseconds. Time to factorize N -- sixty million years.") You have to compare similar functionality, not two arbitrary operations. Can you write a sat function in (say) C that does better than the one in your language? If you can't, then you have no justification for saying that C is faster than your language, for the amount of work your language does. If you can write a faster implementation of sat, then you can improve the implementation of your language by using that C function, thus demonstrating that speed depends on the implementation, not the language. (5) There's no need for such hypothetical examples. Let's use a more realistic example... disk IO is expensive and slow. I believe that disk IO is three orders of magnitude slower than memory access, and heaven help you if you're reading from tape instead of a hard drive! Would anyone like to argue that every language which supports disk IO (including C, Lisp, Fortran and, yes, Python) are therefore "slow"? Since the speed of the hard drive dominates the time taken, we might even be justified as saying that all languages are equally slow! Obviously this conclusion is nonsense. Since the conclusion is nonsense, we have to question the premise, and the weakest premise is the idea that talking about the speed of a *language* is even meaningful (except as a short-hand for "state of the art implementations of that language"). -- Steven From ethan at stoneleaf.us Tue Nov 17 21:33:21 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 17 Nov 2009 18:33:21 -0800 Subject: Calling Python functions from Excel In-Reply-To: <4B02D1E3.6080308@simplistix.co.uk> References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: <4B035CF1.4040400@stoneleaf.us> Chris Withers wrote: > Mark Tolonen wrote: >> The book Python: Programming on Win32 has a whole chapter on COM, and >> a section on COM servers. > > ...and it's generally accepted that COM sucks rocks through straws, so > explore alternatives when they're available ;-) +1 QOTW :D From contact at xavierho.com Tue Nov 17 21:33:43 2009 From: contact at xavierho.com (Xavier Ho) Date: Wed, 18 Nov 2009 12:33:43 +1000 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> Message-ID: <2d56febf0911171833w29dca025n613c6e2643b36019@mail.gmail.com> On Wed, Nov 18, 2009 at 12:28 PM, Peng Yu wrote: > I don't see any different between the following code in terms of > output. Are they exactly the same ('as' v.s. ',')? > Yes, they're exactly the same. However, the syntax with "as" is newer, introducted in Python 3.x, and eventually backported to 2.6. If you have used Python 2.5, only the comma syntax would work. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Tue Nov 17 21:38:36 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 02:38:36 GMT Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' References: Message-ID: On Tue, 17 Nov 2009 20:28:16 -0600, Peng Yu wrote: > I don't see any different between the following code in terms of output. > Are they exactly the same ('as' v.s. ',')? > > try: > raise IOError('IOError') > except IOError as e: > print e This is the preferred syntax. It is used in Python 2.6 and better. It is a syntax error in Python 2.5 and older. > try: > raise IOError('IOError') > except IOError, e: > print e This is the obsolete syntax, used in Python 2.5 and older. -- Steven From pengyu.ut at gmail.com Tue Nov 17 21:40:52 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 20:40:52 -0600 Subject: WindowsError is not available on linux? In-Reply-To: References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan wrote: > On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >> It's not clear to me whether WindowsError is available on linux or >> not, after I read the document. But I see WindowsError in shutil.py. >> Could you somebody let me know what cause the following error? >> >>>>> try: >> ... ? raise WindowsError('WindowsError') >> ... except WindowsError as e: >> ... ? print e >> ... >> Traceback (most recent call last): >> ?File "", line 3, in >> NameError: name 'WindowsError' is not defined >> -- > > does this answer your question? > > Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import shutil >>>> print shutil.WindowsError > None But the document doesn't say shutil need to be imported in order to use WindowsError. Shall the document or the code be corrected? http://docs.python.org/library/exceptions.html From davea at ieee.org Tue Nov 17 21:43:05 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 21:43:05 -0500 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> <00fce5a2-ada1-45e5-b69d-b39b1d2c2225@o13g2000vbl.googlegroups.com> Message-ID: <4B035F39.7010409@ieee.org> Nobody wrote: > On Tue, 17 Nov 2009 11:47:46 -0800, Gerry wrote: > > >> How about this: >> >> lastarg = " ".join(sys.argv[2:]) >> > > What about it? > > IOW, why would you want to do that? > > > Like many tricks, it'd work if several conditions applied: 1) there's exactly two arguments expected on the command line 2) you know that the second argument may have one or more spaces in it, but not consecutively, and no quotes immediately after any such space. 3) you don't mind fooling the user by making *most* cases work, so he's not trained for the general case. This one reminds me of CreateProcess() in Windows, which parses for the program by looking for each space, and seeing if there's an appropriate EXE file there. So if you have stuff installed in "C:\Program Files\My Dir\yyy" directory, you can be blindsided by someone creating a program in the root called c:\program.exe, or "c:\Program Files\My.exe" CreateProcess() keeps trying till one works, instead of immediately giving a diagnosable error. That was my (correct) diagnosis of an actual customer problem, referred to me by tech support. Customer described error message, and I studied what could cause it. Called back and asked whether there was a program.exe in the root directory. Told him to (temporarily) remove it. Problem vanished. Customer astounded how we could know about its existence. Of course it was really a bug in one of the products at my company, where quotes weren't used. Not usually needed, because of this "flexibility" on the part of CreateProcess() DaveA From python at mrabarnett.plus.com Tue Nov 17 21:44:47 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Nov 2009 02:44:47 +0000 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <4B035F9F.5090800@mrabarnett.plus.com> Peng Yu wrote: > It's not clear to me whether WindowsError is available on linux or > not, after I read the document. But I see WindowsError in shutil.py. > Could you somebody let me know what cause the following error? > >>>> try: > ... raise WindowsError('WindowsError') > ... except WindowsError as e: > ... print e > ... > Traceback (most recent call last): > File "", line 3, in > NameError: name 'WindowsError' is not defined WindowsError is for Windows-specific errors (hence the name!). You shouldn't rely on it being defined on non-Windows machines. From threaderslash at gmail.com Tue Nov 17 21:47:32 2009 From: threaderslash at gmail.com (Threader Slash) Date: Wed, 18 Nov 2009 13:47:32 +1100 Subject: Qt Python : QTreeWidget Child Problem In-Reply-To: References: Message-ID: > Hello Everybody, > > I have a QTreewidget that works fine if I have just one level on my > treelist. If I decide to add child sublevels, it gives me an error. Here is > the code, that works nice only without the "childs" lines on it (see after > > "child 1" and "child 2"). > > def eqpt_centralwdg(self,MainWindow): > self.centralwidget = QtGui.QWidget(MainWindow) > self.centralwidget.setObjectName("centralwidget") > > self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget) > self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141)) > self.colorTreeWidget.setObjectName("colorTreeWidget") > > # father root 1 > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > #child 1 - from father 1 > item = QtGui.QTreeWidgetItem(item) > #child 2 - from father 1 > item = QtGui.QTreeWidgetItem(item) > > # father root 2 > item = QtGui.QTreeWidgetItem(self.colorTreeWidget) > > self.connect(self.colorTreeWidget, > QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), > self.eqpt_activateInput) > > MainWindow.setCentralWidget(self.centralwidget) > > def eqpt_retranslateUi(self, MainWindow): > MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", > "MainWindow", None, QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.headerItem().setText(0, > QtGui.QApplication.translate("MainWindow", "color", None, > QtGui.QApplication.UnicodeUTF8) > __sortingEnabled = self.colorTreeWidget.isSortingEnabled() > > self.colorTreeWidget.setSortingEnabled(False) > # father root 1 > self.colorTreeWidget.topLevelItem(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow", None, > > QtGui.QApplication.UnicodeUTF8) > #child 1 - from father 1 > self.colorTreeWidget.topLevelItem(0).child(0).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow Sun", None, > > QtGui.QApplication.UnicodeUTF8)) > #child 2 - from father 1 > self.colorTreeWidget.topLevelItem(0).child(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Yellow Gold", None, > > QtGui.QApplication.UnicodeUTF8)) > > # father root 2 > self.colorTreeWidget.topLevelItem(1).setText(0, > QtGui.QApplication.translate("MainWindow", "Blue", None, > QtGui.QApplication.UnicodeUTF8) > > self.colorTreeWidget.setSortingEnabled(__sortingEnabled) > > > Here is the output, when it works > > def eqpt_activateInput(self,item,col): > print "Qtree ok! pressed" > print item.text(col) > > if I exclude the lines related to the "child 1" and "child 2" from the code, > it runs. Otherwise, it gives me the error: > > AttributeError: 'NoneType' object has no attribute 'setText' > > > I used the Qt Designer to generate the code, and added some lines to trigger > events. > > Any hints or suggestions are highly appreciated. > > Solved! Here is the solution: parent1 = QtGui.QTreeWidgetItem(self.colorTreeWidget) child1_1 = QtGui.QTreeWidgetItem() child1_2 = QtGui.QTreeWidgetItem() parent1.addChild(child1_1) parent1.addChild(child1_2) Now it works properly. Hope this may help others too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Nov 17 21:52:44 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Nov 2009 02:52:44 +0000 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> Message-ID: <4B03617C.5070905@mrabarnett.plus.com> Peng Yu wrote: > I don't see any different between the following code in terms of > output. Are they exactly the same ('as' v.s. ',')? > > try: > raise IOError('IOError') > except IOError as e: > print e > > try: > raise IOError('IOError') > except IOError, e: > print e The second form is the old form. Later versions of Python introduced the first form because it is less confusing. If you wanted a single 'except' to catch 2 exceptions you would need to write: try: ... except (IOError, OSError): ... Sometimes people who are new to Python mistakenly write: try: ... except IOError, OSError: ... thinking that that form will catch 2 exceptions, and they'll then be puzzled when it doesn't work properly. From wuwei23 at gmail.com Tue Nov 17 22:18:21 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 19:18:21 -0800 (PST) Subject: WindowsError is not available on linux? References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> Message-ID: <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Peng Yu wrote: > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? Neither, it's your understanding that needs correction. Benjamin wasn't trying to say that WindowsError is defined within shutil, he was showing that it _isn't_ defined within shutil on a non- Windows machine. As you're looking in shutil.py, you should have noticed this at the very top, just beneath the declaration of the Error exception: try: WindowsError except NameError: WindowsError = None This looks for the existence of the WindowsError exception - present only under Windows - and if it's not there it binds the name to None. You'll notice that the only place it's used in shutil.py is prefixed by the test WindowsError is not None... I think the mention of the exception being raised when a "Windows- specific error occurs" should make it pretty clear that this is a Windows-only exception. From benjamin.kaplan at case.edu Tue Nov 17 22:19:05 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Nov 2009 22:19:05 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> Message-ID: On Tue, Nov 17, 2009 at 9:40 PM, Peng Yu wrote: > On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan > wrote: >> On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. But I see WindowsError in shutil.py. >>> Could you somebody let me know what cause the following error? >>> >>>>>> try: >>> ... ? raise WindowsError('WindowsError') >>> ... except WindowsError as e: >>> ... ? print e >>> ... >>> Traceback (most recent call last): >>> ?File "", line 3, in >>> NameError: name 'WindowsError' is not defined >>> -- >> >> does this answer your question? >> >> Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import shutil >>>>> print shutil.WindowsError >> None > > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? > > http://docs.python.org/library/exceptions.html The exception WindowsError is not defined on my computer (a Mac). The *name* is defined in shutil, but it's mapped to None, not to an exception. > -- > http://mail.python.org/mailman/listinfo/python-list > From davecook at nowhere.net Tue Nov 17 22:21:17 2009 From: davecook at nowhere.net (Dave Cook) Date: 18 Nov 2009 03:21:17 GMT Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> Message-ID: <007f3944$0$23487$c3e8da3@news.astraweb.com> On 2009-11-16, me wrote: > Also looked at the frames/forms created with QtDesigner, which > can be used by Python via pyuic. That's what I would recommend. What did you not like about it? Dave Cook From aurfalien at gmail.com Tue Nov 17 22:25:24 2009 From: aurfalien at gmail.com (aurfalien at gmail.com) Date: Tue, 17 Nov 2009 19:25:24 -0800 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' Message-ID: Hi all, I tried to make the subject as specific as possible rather then just "help me" or "its broke" or "my server is down", etc... So please excuse me if its too specific as I wasn't trying to be ridiculous. So I've been handed some one else's work to fix. While its fun and all, I haven't had much luck in debugging this particular issue. The error I get; File "myscript.py", Line 18, in ? projectpath = ourHome+"/etc/TEMPLATE" TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Python 2.4.3 I've read were when passing a string to exec may need to end with a '\n' I've tried a few diff variations on the below line 18 w/o luck. Any one mind helping out a bratha from anatha ... planet that is? line 18; projectpath = ourHome+"/etc/TEMPLATE" line 17; ourHome = os.environ.get('some_env') Thanks in advance, - aurf From Scott.Daniels at Acm.Org Tue Nov 17 22:25:26 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 17 Nov 2009 19:25:26 -0800 Subject: TODO and FIXME tags In-Reply-To: References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> Message-ID: <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Martin P. Hellwig wrote: > Ben Finney wrote: >> Chris Rebert writes: >> >>> 2009/11/16 Yasser Almeida Hern?ndez : >>>> How is the sintaxis for set the TODO and FIXME tags...? ... >> There's no widely-followed ?syntax? for this convention, though. > Except for _not_ doing what is suggested in those comments, which > appears to be the biggest convention :-) Perhaps: "The comments are a directive to delete the comment if you happen do this." --Scott David Daniels Scott.Daniels at Acm.Org From pengyu.ut at gmail.com Tue Nov 17 22:37:07 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 17 Nov 2009 21:37:07 -0600 Subject: WindowsError is not available on linux? In-Reply-To: <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Message-ID: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: > Peng Yu wrote: >> But the document doesn't say shutil need to be imported in order to >> use WindowsError. Shall the document or the code be corrected? > > Neither, it's your understanding that needs correction. > > Benjamin wasn't trying to say that WindowsError is defined within > shutil, he was showing that it _isn't_ defined within shutil on a non- > Windows machine. > > As you're looking in shutil.py, you should have noticed this at the > very top, just beneath the declaration of the Error exception: > > ? ?try: > ? ? ? ?WindowsError > ? ?except NameError: > ? ? ? ?WindowsError = None > > This looks for the existence of the WindowsError exception - present > only under Windows - and if it's not there it binds the name to None. > You'll notice that the only place it's used in shutil.py is prefixed > by the test WindowsError is not None... > > I think the mention of the exception being raised when a "Windows- > specific error occurs" should make it pretty clear that this is a > Windows-only exception. I don't know about others. The wording "Windows-specific error occurs" was ambiguous to me. It could refers to some errors resulted from copying (on a linux machine) some files from linux file systems to windows files systems (via samba, maybe). I recommend to revise the document a little bit to avoid confusion. From davea at ieee.org Tue Nov 17 22:57:53 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 17 Nov 2009 22:57:53 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <366c6f340911171840h7bbcf216j68e4bf2d302e6219@mail.gmail.com> Message-ID: <4B0370C1.6020309@ieee.org> Peng Yu wrote: > On Tue, Nov 17, 2009 at 8:25 PM, Benjamin Kaplan > wrote: > >> On Tue, Nov 17, 2009 at 9:18 PM, Peng Yu wrote: >> >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. But I see WindowsError in shutil.py. >>> Could you somebody let me know what cause the following error? >>> >>> >>>>>> try: >>>>>> >>> ... raise WindowsError('WindowsError') >>> ... except WindowsError as e: >>> ... print e >>> ... >>> Traceback (most recent call last): >>> File "", line 3, in >>> NameError: name 'WindowsError' is not defined >>> -- >>> >> does this answer your question? >> >> Python 2.6.4 (r264:75706, Oct 28 2009, 23:01:00) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import shutil >>>>> print shutil.WindowsError >>>>> >> None >> > > But the document doesn't say shutil need to be imported in order to > use WindowsError. Shall the document or the code be corrected? > > http://docs.python.org/library/exceptions.html > > The WindowsError is available in a Windows build, and I don't directly know if it's available on Linux. I think shutil is a red-herring here, however. The docs show the implementation of copyTree(), and that function uses WindowsError. However, earlier in the shutil.py file, there is the following trick: try: WindowsError except NameError: WindowsError = None This has the effect of defining a dummy attribute "WindowsError" WITHIN THIS ONE MODULE, if it's not already in the global namespace. This lets the code in function copytree() deal with an OSError differently on Windows than in other systems. I do not expect that the name WindowsError of that module was intended to be accessed by user's code. And because some of you see a None value, that tells me that it is indeed not defined for some systems. I think that fact should be documented in the URL you mention, exceptions.html But in the meantime, if you're not on a Windows system, you won't see that exception, and if you need to be portable, you may pull the same trick that shutil did. DaveA From glenn at zewt.org Tue Nov 17 23:10:51 2009 From: glenn at zewt.org (Glenn Maynard) Date: Tue, 17 Nov 2009 23:10:51 -0500 Subject: ZipFile - file adding API incomplete? In-Reply-To: <4B02B2F1.4030407@ieee.org> References: <7mf5f6F3i297hU1@mid.uni-berlin.de> <4B02B2F1.4030407@ieee.org> Message-ID: On Tue, Nov 17, 2009 at 9:28 AM, Dave Angel wrote: > I'm pretty sure that the ZIP format uses independent compression for each > contained file (member). ?You can add and remove members from an existing > ZIP, and use several different compression methods within the same file. ?So > the adaptive tables start over for each new member. This is correct. It doesn't do solid compression, which is what you get with .tar.gz (and RARs, optionally). > What isn't so convenient is that the sizes are apparently at the end. ?So if > you're trying to unzip "over the wire" you can't readily do it without > somehow seeking to the end. ?That same feature is a good thing when it comes > to spanning zip files across multiple disks. Actually, there are two copies of the headers: one immediately before the file data (the local file header), and one at the end (the central directory); both contain copies of the compressed and uncompressed file size. Very few programs actually use the local file headers, but it's very nice to have the option. It also helps makes ZIPs very recoverable. If you've ever run a ZIP recovery tool, they're usually just reconstructing the central directory from the local file headers (and probably recomputing the CRCs). (This is no longer true if bit 3 of the bitflags is set, which puts the CRC and filesizes after the data. In that case, it's not possible to stream data--largely defeating the benefit of the local headers.) > Define a calls to read _portions_ of the raw (compressed, encrypted, whatever) data. I think the clean way is to return a file-like object for a specified file, eg.: # Read raw bytes 1024-1152 from each file in the ZIP: zip = ZipFile("file.zip", "r") for info in zip.infolist(): f = zip.rawopen(info) # or a filename f.seek(1024) f.read(128) > Define a call that locks the ZipFile object and returns a write handle for a single new file. I'd use a file-like object here, too, for probably obvious reasons--you can pass it to anything expecting a file object to write data to (eg. shutil.copyfile). > Only on successful close of the "write handle" is the new directory written. Rather, when the new file is closed, its directory entry is saved to ZipFile.filelist. The new directory on disk should be written when the zip's own close() method is called, just as when writing files with the other methods. Otherwise, writing lots of files in this way would write and overwrite the central directory repeatedly. Any thoughts about this rough API outline: ZipFile.rawopen(zinfo_or_arcname) Same definition as open(), but returns the raw data. No mode (no newline translation for raw files); no pwd (raw files aren't decrypted). ZipFile.writefile(zinfo[, raw]) Definition like ZipInfo.writestr. Relax writestr()'s "at least the filename, date, and time must be given" rule: if not specified, use the current date and time. Returns a file-like object (ZipWriteFile) which file data is written to. If raw is True, no actual compression is performed, and the file data should already be compressed with the specified compression type (no checking is performed). If raw is False (the default), the data will be compressed before being written. When finished writing data, the file must be closed. Only one ZipWriteFile may be open for each ZipFile at a time. Calls to ZipFile.writefile while a ZipWriteFile is already open will result in ValueError[1]. Another detail: is the CRC recomputed when writing in raw mode? No. If I delete a file from a ZIP (causing me to rewrite the ZIP) and another file in the ZIP is corrupt, it should just move the file as-is, invalid CRC and all; it should not rewrite the file with a new CRC (masking the corruption) or throw an error (I should not get errors about file X being corrupt if I'm deleting file Y). When writing in raw mode, if zinfo.CRC is already specified (not None), it should be used as-is. I don't like how this results in three different APIs for adding data (write, writestr, writefile), but trying to squeeze the APIs together feels unnatural--the parameters don't really line up too well. I'd expect the other two to become thin wrappers around ZipFile.writefile(). This never opens files directly like ZipFile.write, so it only takes a zinfo and not a filename (set the filename through the ZipInfo). Now you can stream data into a ZIP, specify all metadata for the file, and you can stream in compressed data from another ZIP (for deleting files and other cases) without recompressing. This also means you can do all of these things to encrypted files without the password, and to files compressed with unknown methods, which is currently impossible. > and I realize that the big flaw in this design is that from the moment you start overwriting the existing master directory until you write a new master at the end, your do not have a valid zip file. The same is true when appending to a ZIP with ZipFile.write(); until it finishes, the file on disk isn't a valid ZIP. That's unavoidable. Files in the ZIP can still be opened by the existing ZipFile object, since it keeps the central directory in memory. For what it's worth, I've written ZIP parsing code several times over the years (https://svn.stepmania.com/svn/trunk/stepmania/src/RageFileDriverZip.cpp), so I'm familiar with the more widely-used parts of the file format, but I havn't dealt with ZIP writing very much. I'm not sure if I'll have time to get to this soon, but I'll keep thinking about it. [1] seems odd, but mimicing http://docs.python.org/library/stdtypes.html#file.close -- Glenn Maynard From clp2 at rebertia.com Tue Nov 17 23:11:32 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 20:11:32 -0800 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' In-Reply-To: References: Message-ID: <50697b2c0911172011o4a8bc9b1kf8810386761c4576@mail.gmail.com> On Tue, Nov 17, 2009 at 7:25 PM, wrote: > The error I get; > > File "myscript.py", Line 18, in ? > projectpath = ourHome+"/etc/TEMPLATE" > TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' > > Python 2.4.3 > > I've read were when passing a string to exec may need to end with a '\n' > > I've tried a few diff variations on the below line 18 w/o luck. ?Any one > mind helping out a bratha from anatha ... planet that is? > > line 18; > > projectpath = ourHome+"/etc/TEMPLATE" > > line 17; > ourHome = os.environ.get('some_env') >From the `os` docs: os.environ A mapping object representing the string environment. >From the `dict` docs (`dict` being the built-in and prototypical mapping class): D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. >From this, I conclude that the environment variable `some_env` does not exist for you, thus .get() returns None, thus causing an error when you try and concatenate it with a string. Solution: Either fix things so the environment variable does exist or add code to handle the case of the environment variable not existing. Cheers, Chris -- http://blog.rebertia.com From wuwei23 at gmail.com Tue Nov 17 23:11:45 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 17 Nov 2009 20:11:45 -0800 (PST) Subject: WindowsError is not available on linux? References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> Message-ID: <8e5bd0b8-0bec-4360-ab02-e3f28efbff1c@m33g2000pri.googlegroups.com> Peng Yu wrote: > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. So file a bug: http://docs.python.org/bugs.html From clp2 at rebertia.com Tue Nov 17 23:18:33 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 20:18:33 -0800 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> Message-ID: <50697b2c0911172018tcb052acrc995b916c22251a7@mail.gmail.com> On Tue, Nov 17, 2009 at 7:37 PM, Peng Yu wrote: > On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: >> Peng Yu wrote: >>> But the document doesn't say shutil need to be imported in order to >>> use WindowsError. Shall the document or the code be corrected? >> >> Neither, it's your understanding that needs correction. >> >> Benjamin wasn't trying to say that WindowsError is defined within >> shutil, he was showing that it _isn't_ defined within shutil on a non- >> Windows machine. >> >> As you're looking in shutil.py, you should have noticed this at the >> very top, just beneath the declaration of the Error exception: >> >> ? ?try: >> ? ? ? ?WindowsError >> ? ?except NameError: >> ? ? ? ?WindowsError = None >> >> This looks for the existence of the WindowsError exception - present >> only under Windows - and if it's not there it binds the name to None. >> You'll notice that the only place it's used in shutil.py is prefixed >> by the test WindowsError is not None... >> >> I think the mention of the exception being raised when a "Windows- >> specific error occurs" should make it pretty clear that this is a >> Windows-only exception. > > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. But your example isn't even Windows-specific because Samba server exists; any error would network-related or specific to the SMB protocol rather than Windows-related. Cheers, Chris -- http://blog.rebertia.com From ashwiniyal at gmail.com Tue Nov 17 23:56:12 2009 From: ashwiniyal at gmail.com (ashwini yal) Date: Wed, 18 Nov 2009 10:26:12 +0530 Subject: Running a python script from interactive mode Message-ID: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Hi, I am trying to run a python script from interactive mode ,but i am not able to know how to run it? Is it possible? if yes please let me how to run the script? -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Wed Nov 18 00:02:01 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 00:02:01 -0500 Subject: TypeError: unsupported operand types for +: 'NoneType' and 'str' In-Reply-To: References: Message-ID: <4B037FC9.9020409@ieee.org> aurfalien at gmail.com wrote: >
    Hi all, > > I tried to make the subject as specific as possible rather then just > "help me" or "its broke" or "my server is down", etc... > > So please excuse me if its too specific as I wasn't trying to be > ridiculous. > > So I've been handed some one else's work to fix. > > While its fun and all, I haven't had much luck in debugging this > particular issue. > > The error I get; > > File "myscript.py", Line 18, in ? > projectpath = ourHome+"/etc/TEMPLATE" > TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' > > Python 2.4.3 > > I've read were when passing a string to exec may need to end with a '\n' > > I've tried a few diff variations on the below line 18 w/o luck. Any > one mind helping out a bratha from anatha ... planet that is? > > line 18; > > projectpath = ourHome+"/etc/TEMPLATE" > > line 17; > ourHome = os.environ.get('some_env') > > > Thanks in advance, > - aurf > > Short answer: you (the program) don't have any such environment variable, and forgot to check for it, just implicitly assuming that it'll be present. When it isn't, the + doesn't make any sense. Longer answer: When you get an error on a line, try to figure out which of the variables on the line might be in doubt, and look at them in your debugger. Since the error is complaining about operands to + you'd look at both the ourHome variable and the literal. And then you'd look, and see that ourHome is equal to None. Which is what the error said. Now you look at the last place which bound that variable and it's os.environ.get(). How can get() return a None? Answer: when there's no such variable. As to how to fix it, you have to decide what behavior you want when the user doesn't have such a variable. Read the manual you wrote for the user, telling him to define it. If no such paragraph exists, then perhaps you intended a default value to be used, such as "/default/special" Add a paragraph to the manual, and a corresponding field to the get(). ourHome = os.environ.get("some_env", "/default/special") Now it'll always have a text value, either specified by the environment var, or /default/special. Alternatively, you could catch the exception, print an error to the user, telling him exactly how to fix his environment, and exit. Of course, this assumes you do the check pretty early in the program's run. DaveA From greg at cosc.canterbury.ac.nz Wed Nov 18 00:06:15 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:06:15 +1300 Subject: Command line arguments?? In-Reply-To: References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: <7mhdmnF3hrf2fU1@mid.individual.net> Rhodri James wrote: > We've been living with this pain ever since windowed GUIs encouraged > users to put spaces in their file names (Apple, I'm looking at you!). It's not really Apple's fault. There was no problem with spaces in filenames in the classic MacOS environment, because there was no textual command language (at least not one that people used in day-to-day work). There's a slight problem sometimes in MacOSX when you use the shell, but at least unix passes args to a program as separate strings, so as long as you exec() something directly and avoid the shell, you're safe. Windows, on the other hand, passes all the args as a single string, whether a shell is involved or not (due to blindly adopting CP/M's argument passing mechanism into MSDOS). Microsoft screwed up by trying to partially implement Apple's ideas on top of a system that wasn't engineered to cope with them. -- Greg From davea at ieee.org Wed Nov 18 00:08:18 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 00:08:18 -0500 Subject: WindowsError is not available on linux? In-Reply-To: <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> Message-ID: <4B038142.2090302@ieee.org> Peng Yu wrote: > On Tue, Nov 17, 2009 at 9:18 PM, alex23 wrote: > >> Peng Yu wrote: >> >>> But the document doesn't say shutil need to be imported in order to >>> use WindowsError. Shall the document or the code be corrected? >>> >> Neither, it's your understanding that needs correction. >> >> Benjamin wasn't trying to say that WindowsError is defined within >> shutil, he was showing that it _isn't_ defined within shutil on a non- >> Windows machine. >> >> As you're looking in shutil.py, you should have noticed this at the >> very top, just beneath the declaration of the Error exception: >> >> try: >> WindowsError >> except NameError: >> WindowsError =one >> >> This looks for the existence of the WindowsError exception - present >> only under Windows - and if it's not there it binds the name to None. >> You'll notice that the only place it's used in shutil.py is prefixed >> by the test WindowsError is not None... >> >> I think the mention of the exception being raised when a "Windows- >> specific error occurs" should make it pretty clear that this is a >> Windows-only exception. >> > > I don't know about others. The wording "Windows-specific error occurs" > was ambiguous to me. It could refers to some errors resulted from > copying (on a linux machine) some files from linux file systems to > windows files systems (via samba, maybe). I recommend to revise the > document a little bit to avoid confusion. > > Worse, even if the exception cannot be thrown on a non-Windows environment, leaving it undefined makes it very awkward to write portable code. An except clause that can never happen in a particular environment is pretty innocent. Or somebody can use a base class for his except clause, to catch this error and other related ones. But it blows up if you explicitly use this exception. I think that needs documentation, at a minimum. DaveA From clp2 at rebertia.com Wed Nov 18 00:10:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 17 Nov 2009 21:10:23 -0800 Subject: Running a python script from interactive mode In-Reply-To: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> References: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Message-ID: <50697b2c0911172110s65ca16c1ra22f3808e0bf9fca@mail.gmail.com> On Tue, Nov 17, 2009 at 8:56 PM, ashwini yal wrote: > Hi, > > I am trying to run a python script from interactive mode ,but i am not able > to know how to run it? Is it possible? if yes please let me how to run the > script? execfile("/path/to/the/script.py") or if it's on your sys.path and doesn't use the `if __name__ == "__main__":` idiom then just importing it works: import script_name Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Wed Nov 18 00:17:25 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:17:25 +1300 Subject: YIELD_VALUE Byte Code In-Reply-To: <1257933992.2784.16.camel@laptop> References: <1257933992.2784.16.camel@laptop> Message-ID: <7mheblF3h98o5U1@mid.individual.net> Andreas L?scher wrote: > Since Python Version 2.5 it behaves the following: > 1. pop yield value from stack and return it to > a former gen_send_ex() call from Objects/genobject.c > > 2. push the yield value on the stack in gen_send_ex() and return Are you sure about that? I would expect the value pushed to be the one sent back into the generator using a send() call if any, or None if the generator is resumed using next() rather than send(). > 3. when the generator is executed again, the yield value is > 'poped' from the stack again with the POP_TOP opcode This will happen if the result of the yield expression is not used for anything in the Python code. -- Greg From himanshu.garg at gmail.com Wed Nov 18 00:21:04 2009 From: himanshu.garg at gmail.com (Himanshu) Date: Wed, 18 Nov 2009 11:21:04 +0600 Subject: Running a python script from interactive mode In-Reply-To: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> References: <771960b20911172056m4b4f35e3h8287dc44ce176b7a@mail.gmail.com> Message-ID: <6f82a7270911172121x1c1936eam47438de934b34541@mail.gmail.com> 2009/11/18 ashwini yal : > Hi, > > I am trying to run a python script from interactive mode ,but i am not able > to know how to run it? Is it possible? if yes please let me how to run the > script? > a) If you want to debug it then see http://docs.python.org/library/pdb.html b) If you want to accept simple input from user see http://docs.python.org/library/functions.html?highlight=raw_input#raw_input c) If you want to enter interactive mode after the script has finished execution use the -i option with python. See http://docs.python.org/tutorial/interpreter.html?highlight=interactive%20mode From greg at cosc.canterbury.ac.nz Wed Nov 18 00:22:44 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:22:44 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7mhelkF3go4saU1@mid.individual.net> MRAB wrote: > Fortran uses "=" and ".EQ.", probably because (some) earlier autocodes > did. I think Fortran used .LT. and .GT. because some early character sets didn't have < and > symbols. Having done that, it probably seemed more consistent to use .EQ. for comparison than to break the pattern and use =. -- Greg From greg at cosc.canterbury.ac.nz Wed Nov 18 00:28:11 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:28:11 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> Message-ID: <7mhevoF3ht32sU1@mid.individual.net> r wrote: > I think the syntax was chosen because the > alternatives are even worse AND since assignment is SO common in > programming, would you *really* rather type two chars instead of one? Smalltalk solved the problem by using a left-arrow character for assignment. But they had an unfair advantage in being able to use a non-standard character set on their custom-built machines. We should be able to do a lot better now using Unicode. We could even heal the <> vs != rift by using a real not-equal symbol! -- Greg From greg at cosc.canterbury.ac.nz Wed Nov 18 00:34:16 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 18 Nov 2009 18:34:16 +1300 Subject: Time travel In-Reply-To: <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> References: <9617511c-600a-439b-bbc3-4961db0f9b8b@r24g2000yqd.googlegroups.com> <7a4f077c-944c-4d79-8a9a-bd01d33c0449@w19g2000yqk.googlegroups.com> Message-ID: <7mhfb8F3i93hnU1@mid.individual.net> Lee Merrill wrote: > And I can't do arithmetic, it is actually about 3600--never mind! Don't feel too bad. Obviously Guido nipped back to March 8 2008 in his time machine and fixed the problem, making it *look* like you can't do arithmetic. Time travel often leads to embarrassments like that. -- Greg From sturlamolden at yahoo.no Wed Nov 18 01:10:00 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Nov 2009 22:10:00 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> Message-ID: On 17 Nov, 19:34, r wrote: > Agreed! Tkinter (besides myself) seems to be the whipping boy of > c.l.py. Tkinter has it's place in Python because of the same > simplicity people laboriously lament about! Until something else comes > along that can offer the same benefits of Tkinter and a little extra, > we are going to keep seeing Tkinter release after release. Guido knows > what he is doing people, don't sell the guy short! Tkinter is fine, particularly with Tix. But I want a GUI designer. I don't like the tedious work of hand- coding a GUI! From threaderslash at gmail.com Wed Nov 18 01:12:31 2009 From: threaderslash at gmail.com (Threader Slash) Date: Wed, 18 Nov 2009 17:12:31 +1100 Subject: Qt Python radiobutton: activate event Message-ID: Hi Everybody, I am developing a project for one customer, where the design has a radio button with exclusive options. Here is a piece of the code that runs and show two nice radio buttons: self.performGroupBox = QtGui.QGroupBox(self.centralwidget) self.performGroupBox.setGeometry(QtCore.QRect(50, 20, 181, 121)) self.performGroupBox.setObjectName("performGroupBox") self.consultRadioButton = QtGui.QRadioButton(self.performGroupBox) self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18)) self.consultRadioButton.setObjectName("consultRadioButton") self.insertRadioButton = QtGui.QRadioButton(self.performGroupBox) self.insertRadioButton.setGeometry(QtCore.QRect(40, 60, 84, 18)) self.insertRadioButton.setObjectName("insertRadioButton") it just looks like: perform: () Consult () Insert The point here is, how to know what choice was marked: "consultRadioButton" or "insertRadioButton"? Here is a sample on trying to get this information: if self.consultRadioButton.isChecked(): self.call_Consult() if self.insertRadioButton.isChecked(): self.call_Insert() But it didn't do anything when the radiobutton is chosen. Otherwise, using connect should be another option: QtCore.QObject.connect(self.consultRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Consult) QtCore.QObject.connect(self.insertRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Insert) But it didn't work either. What is missing here... Any suggestion? All comments are highly welcome and appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From yinon.me at gmail.com Wed Nov 18 01:22:59 2009 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 17 Nov 2009 22:22:59 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <4be94046-3b7d-4189-9827-c64131042e81@o23g2000vbi.googlegroups.com> Message-ID: On Nov 18, 8:10?am, sturlamolden wrote: > On 17 Nov, 19:34, r wrote: > > > Agreed! Tkinter (besides myself) seems to be the whipping boy of > > c.l.py. Tkinter has it's place in Python because of the same > > simplicity people laboriously lament about! Until something else comes > > along that can offer the same benefits of Tkinter and a little extra, > > we are going to keep seeing Tkinter release after release. Guido knows > > what he is doing people, don't sell the guy short! > > Tkinter is fine, particularly with Tix. > > But I want a GUI designer. I don't like the tedious work of hand- > coding a GUI! http://stackoverflow.com/questions/1693939/need-a-gui-builder-for-tkinter-python From dotancohen at gmail.com Wed Nov 18 02:33:38 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 Nov 2009 09:33:38 +0200 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <880dece00911172333o793e97a1u3a4e08b67c3dacce@mail.gmail.com> 2009/11/16 Steve Ferg : > This is a question for the language mavens that I know hang out here. > It is not Python related, except that recent comparisons of Python to > Google's new Go language brought it to mind. > > NOTE that this is *not* a suggestion to change Python. ?I like Python > just the way it is. ?I'm just curious about language design. > > For a long time I've wondered why languages still use blocks > (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. > > I've often thought that a language with this kind of block-free syntax > would be nice and intuitive: > > ? ?if then > ? ? ? ?do stuff > ? ?elif then > ? ? ? ?do stuff > ? ?else > ? ? ? ?do stuff > ? ?endif > > Note that you do not need block delimiters. > > Obviously, you could make a more Pythonesque syntax by using a colon > rather then "then" for the condition terminator. ?You could make it > more PL/I-like by using "do", etc. > > You can write shell scripts using if ... fi, but other than that I > don't recall a language with this kind of syntax. > > Does anybody know a language with this kind of syntax for > ifThenElseEndif? > PHP has exactly this: if (condition) { // stuff } elseif (otherContition) { // otherStuff } elseif (yetAnotherCondition) { // yetOtherStuff } Furthermore, PHP has the switch statement: http://php.net/manual/en/control-structures.switch.php switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; } The break commands end the switch, and they can be removed to have multiple matches perform multiple functions. > Is there any particular reason why this might be a *bad* language- > design idea? It is about as far from OO as one could get. Whether or not that is "bad" depends on the use case. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From sturlamolden at yahoo.no Wed Nov 18 02:51:31 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 17 Nov 2009 23:51:31 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> Message-ID: <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> On 18 Nov, 04:21, Dave Cook wrote: > On 2009-11-16, me wrote: > > > Also looked at the frames/forms created with QtDesigner, which > > can be used by Python via pyuic. > > That's what I would recommend. ?What did you not like about it? GPL From showell30 at yahoo.com Wed Nov 18 03:49:34 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 00:49:34 -0800 (PST) Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures Message-ID: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> During the last few days I have written code in support of a small DDL language that encapsulates a concise representation of the manipulations needed to make a deep subcopy of a Python-like data structure. It is inspired by syntax from mainstream modern languages, including, of course, Python. The DDL can be converted to an AST. That AST can be walked to either generate Python code that expresses the mapping or to generate Python objects that can execute the mapping. Either of the prior outputs can then subsequently be applied to real world inputs to create new Python data structures from old ones, using the mechanisms specified in the original DDL for attribute access, dictionary lookup, iteration, method invocation, etc. Here is an example of the DDL (and I hate the terminology "DDL," just cannot think of anything better): { 'show_table_of_contents', 'author' { .person 'name', .person 'location' as city, .favorite_books()[ .title, .cost() as expense ] as books} } There are more details here: http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html Apart from shamelessly plugging my blog, I am hoping to generate ideas, constructive criticism, etc. Feel free to comment here or on the blog. So far there are three entries on the blog, all pertaining to Python. The implementation of the idea is quite new, but it is a topic that I have been pondering for a long time--no matter how expressive your programming language of choice might be, there are certain programming tasks that just seem needlessly tedious. The mini-language above proposes to solve one problem but solve it well. I am particularly interested to find out whether somebody has tried something like this before. From deets at nospam.web.de Wed Nov 18 03:57:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 09:57:12 +0100 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <4b035afa$1@dnews.tpgi.com.au> References: <4b035afa$1@dnews.tpgi.com.au> Message-ID: <7mhr78F3hrl1kU1@mid.uni-berlin.de> Lie Ryan schrieb: > hong zhang wrote: >> >> --- On Tue, 11/17/09, Tim Chase wrote: >> >>> From: Tim Chase >>> Subject: Re: IOError: [Errno 28] No space left on device >>> To: "Lie Ryan" >>> Cc: python-list at python.org >>> Date: Tuesday, November 17, 2009, 7:47 PM >>>>> for i in >>> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>>>> with open(i, 'w') as f: >>>>> print >>>>> f, cont_tx >>>>> >>>>> work perfectly. >>>>> >>>>> But following get error like: >>>>> print >>f, cont_tx >>>>> IOError: [Errno 28] No space left on device >>>> Apparently the harddisk where you stored the file is >>> full? >>> >>> Likely a misinterpretation of the error. I'm guessing >>> either one needs to be root to write to this [likely >>> virtual] file, or a member of an associated group.. It >>> would help to have the output of >>> >>> bash$ whoami >>> bash$ id >>> >>> and >>> >>> bash$ ls -lsF >>> /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx >> >> It is root. see following. >> File "../henry-cont-tx", line 186, in do_cont_tx >> print >>f, cont_tx >> IOError: [Errno 28] No space left on device >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# >> whoami >> root >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# id >> uid=0(root) gid=0(root) groups=0(root) >> root at tester-laptop:/home/tester/Desktop/sv-project/scripts/scripts# ls >> -lsF /sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx >> 0 -rw------- 1 root root 0 2009-11-17 17:51 >> /sys/kernel/debug/ieee80211/phy2/iwlagn/data/continuous_tx >> > > Where is the output file? Could it possibly be located in a device that > is impossible to write even for root (e.g. filesystem mounted as > read-only or CD or floppy with the readonly switch active or NTFS > partition without ntfs-3g driver)? > > Can you write to this file from outside python (try echo-ing to the > file)? What's the permission of the folder? > > The output of your 'df' shows that you only have one partition (for > root) and nothing else; it is quite uncommon for linux/unix to be setup > with only one partition, you didn't trim anything right? /sys is not a block-device, it's similar to /proc (or replaces it, I forgot). It displays system-information and device-trees and whatnot, and some of those files can be written to change settings. I think the error the OP sees is a mis-interpretion or unlucky re-map of an error-code the kernel gives when things go wrong, I can only guess but maybe he writes to fast to the files, or to often. Diez From slafs.e at gmail.com Wed Nov 18 04:13:11 2009 From: slafs.e at gmail.com (Slafs) Date: Wed, 18 Nov 2009 01:13:11 -0800 (PST) Subject: XML root node attributes References: <63f8882f-2d3d-46aa-abaa-2dda0a0525c9@f16g2000yqm.googlegroups.com> <4b02b4ff$0$7615$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Thanks But this doesn't work. I've ended using something like this: import xml.etree.ElementTree as ET root = ET.Element("root", dict(a='v', b='v2', c='v3')) n = ET.SubElement(root,'d') tree = ET.ElementTree(root) import sys tree.write(sys.stdout) On 17 Lis, 15:36, Stefan Behnel wrote: > Slafs, 17.11.2009 15:19: > > > I'm little confused about adding attributes to the root node when > > creating an XML document. > > Can I do this using minidom or something else. > > Yes, you /can/, but you /should/ use something else. > > > I can't find anything that would fit my needs. > > > i would like to have something like this: > > > > > > ? ? > > ? ?.... > > > > Use ElementTree: > > ? ? import xml.etree.ElementTree as ET > ? ? root = ET.Element("root", dict(a='v', b='v2', c='v3')) > ? ? root.SubElement('d') > > ? ? print ET.tostring(root) > > Stefan From showell30 at yahoo.com Wed Nov 18 04:15:32 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 01:15:32 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On the topic of "switch" statements and even-more-concise-then-we-have- already if/elif/else/end constructs, I have to say that Python does occasionally force you to write code like the code below. Maybe "force" is too strong a word, but Python lends itself to if/elif blocks like below, which get the job done just fine, but which are not syntactically pretty, due to the "(el){0,1}if kind ==" duplication. There are often cases where if/elif statements are just a smell that you do not know how to do dictionary lookups, but if you converted the below code to use dictionary lookups, you would complicate the code almost as much as you abstracted the code, if not more, unless I am just being very naive. Anonymous methods would help to a certain degree. I am not saying I want either anonymous methods or switch statements, but the lack of either in a language leads to very procedural looking code when you use number-of-lines-of-code as a (possibly dubious) metric. Maybe this excerpt can be golfed down to something simpler, I would love to see it! if kind == 'dict': return dictionary_schema(ast) elif kind == 'list': method = dictionary_schema(ast) return lambda lst: map(method, lst) elif kind == 'attr': return ((lambda obj: getattr(obj, ast.field)), ast.field) elif kind == 'key': return (lambda obj: obj.get(ast.field), ast.field) elif kind == 'as': method, old_name = schema(ast.parent) return (method, ast.synonym) elif kind == 'call': method, old_name = schema(ast.parent) def call(obj): return method(obj)() return (call, old_name) elif kind == 'recurse': expr = ast.expr kind = expr.kind method, field_name = schema(ast.parent) if kind in ['attr', 'key']: new_method, new_field_name = schema(expr) field_name = new_field_name elif kind in ['dict', 'list']: new_method = schema(expr) else: raise Exception('unknown kind!') def recurse(obj): obj = method(obj) return new_method(obj) return (recurse, field_name) else: raise Exception('unknown kind!') From gonatan at gmx.de Wed Nov 18 04:27:10 2009 From: gonatan at gmx.de (=?ISO-8859-1?Q?Marcus_Gna=DF?=) Date: Wed, 18 Nov 2009 10:27:10 +0100 Subject: What is the difference between 'except IOError as e:' and 'except IOError, e:' In-Reply-To: <4B03617C.5070905@mrabarnett.plus.com> References: <366c6f340911171828h44dbc595o2770196862a3e0e@mail.gmail.com> <4B03617C.5070905@mrabarnett.plus.com> Message-ID: <4B03BDEE.6080906@gmx.de> See also http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110-exception-handling-changes From clp2 at rebertia.com Wed Nov 18 04:32:30 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 01:32:30 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50697b2c0911180132k399ba891uc5424ce4ecc19bde@mail.gmail.com> On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > On the topic of "switch" statements and even-more-concise-then-we-have- > already if/elif/else/end constructs, I have to say that Python does > occasionally force you to write code like the code below. ?Maybe > "force" is too strong a word, but Python lends itself to if/elif > blocks like below, which get the job done just fine, but which are not > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > There are often cases where if/elif statements are just a smell that > you do not know how to do dictionary lookups, but if you converted the > below code to use dictionary lookups, you would complicate the code > almost as much as you abstracted the code, if not more, unless I am > just being very naive. I'm gonna have to disagree and say using the dictionary dispatch technique would clean it up a good bit. Yes, it would entail creating several functions, but those functions could then be documented (vs. the currently opaque code blocks); and due to their separation and smaller length, they would be easier to understand and test than the given code. Additionally, the sheer length of the given code segment probably constitutes a code smell in and of itself for the function containing that code. Cheers, Chris -- http://blog.rebertia.com From jarausch at igpm.rwth-aachen.de Wed Nov 18 04:42:03 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Wed, 18 Nov 2009 10:42:03 +0100 Subject: pygtk - icons? Message-ID: <7mhtr5F3itsg6U1@mid.dfncis.de> Hi, please bear in mind that I'm an absolute newcomer to (py)gtk. I'm trying to install the nice synchronization tool http://live.gnome.org/Conduit which is written in Python and use pyGTK. This installed several icons e.g. /usr/share/icons/hicolor/16x16/apps/conduit.png When run, Conduit fails to find its icons. For testing purposes I've tried import gtk info=gtk.icon_theme_get_default().lookup_icon("conduit",16,0) which produces the error message GtkWarning: Could not find the icon 'conduit'. The 'hicolor' theme was not found either, perhaps you need to install it. You can get a copy from: http://icon-theme.freedesktop.org/releases On my Gentoo system lots of packages have placed icons under /usr/share/icons/hicolor So, what am I missing. Many thanks for a hint, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From showell30 at yahoo.com Wed Nov 18 04:53:50 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 01:53:50 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 18, 1:32?am, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > > On the topic of "switch" statements and even-more-concise-then-we-have- > > already if/elif/else/end constructs, I have to say that Python does > > occasionally force you to write code like the code below. ?Maybe > > "force" is too strong a word, but Python lends itself to if/elif > > blocks like below, which get the job done just fine, but which are not > > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > > There are often cases where if/elif statements are just a smell that > > you do not know how to do dictionary lookups, but if you converted the > > below code to use dictionary lookups, you would complicate the code > > almost as much as you abstracted the code, if not more, unless I am > > just being very naive. > > I'm gonna have to disagree and say using the dictionary dispatch > technique would clean it up a good bit. > Yes, it would entail creating several functions, but those functions > could then be documented (vs. the currently opaque code blocks); and > due to their separation and smaller length, they would be easier to > understand and test than the given code. > Additionally, the sheer length of the given code segment probably > constitutes a code smell in and of itself for the function containing > that code. > If you introduce seven tiny little methods, aren't you increasing the length of the module by seven lines and introducing more complexity with the dispatch mechanism? (Actually, it's 14 lines more if you put a line of whitespace between your methods, and then you are also blurring an important cue that each of the seven code blocks all perform within the same context.) I do agree with your point that separate methods lead to easier unit testing. I'm a little more skeptical about the documentation/understanding argument, since code is often best understood within the context of surrounding code. I am also a bit skeptical of any coding technique that leads to lexical duplication like {'attr': process_attr, 'key': process_key, 'call': process_call}(ast); that is just replacing one smell with another. Of course, you could do something like __modules__ [kind](ast) too, but that gets a bit overly abstract for a simple dispatch. Having said all that, I'm gonna take your suggestion...thanks for the response! From anh.hai.trinh at gmail.com Wed Nov 18 04:55:24 2009 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Wed, 18 Nov 2009 01:55:24 -0800 (PST) Subject: A different take on finding primes References: <77e831100911141701y206b501fk7e124f706e6db7f3@mail.gmail.com> Message-ID: <50a6c08d-51c6-4a51-b246-dbdc19f34b71@f18g2000prf.googlegroups.com> > 1) google list of prime numbers > 2) see "Prime numbers list" in the results (number 3 in the results) > 3) click link that leads towww.prime-numbers.org > > I found 455042511 prime numbers in approx 15 seconds. Not bad at all. How about using http://www.sagemath.org/ (written in Python). sage: time primes_first_n(10^7); CPU times: user 4.36 s, sys: 2.43 s, total: 6.79 s Wall time: 6.88 s That used 3G of RAM, you could certainly go higher if you have more memory. ----aht From showell30 at yahoo.com Wed Nov 18 05:06:49 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 02:06:49 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> On Nov 18, 1:32?am, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > > On the topic of "switch" statements and even-more-concise-then-we-have- > > already if/elif/else/end constructs, I have to say that Python does > > occasionally force you to write code like the code below. ?Maybe > > "force" is too strong a word, but Python lends itself to if/elif > > blocks like below, which get the job done just fine, but which are not > > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > > There are often cases where if/elif statements are just a smell that > > you do not know how to do dictionary lookups, but if you converted the > > below code to use dictionary lookups, you would complicate the code > > almost as much as you abstracted the code, if not more, unless I am > > just being very naive. > > I'm gonna have to disagree and say using the dictionary dispatch > technique would clean it up a good bit. > Yes, it would entail creating several functions, but those functions > could then be documented (vs. the currently opaque code blocks); and > due to their separation and smaller length, they would be easier to > understand and test than the given code. > Additionally, the sheer length of the given code segment probably > constitutes a code smell in and of itself for the function containing > that code. > Here's the rewrite. The indirection from the definition of _dict to the first use of _dict is a little painful (36 lines away), but apart from that I am pleased with how the new code looks, so your points are well taken: kind = ast.kind def _dict(ast): return dictionary(ast, metavar) def _list(ast): ignore, code = dictionary(ast, 'item') code = '[%s for item in %s]' % (code, metavar) return label, code def _attr(ast): return ast.field, '%s.%s' % (metavar, ast.field) def _key(ast): return ast.field, '%s[%s]' % (metavar, repr(ast.field)) def _as(ast): ignore, parent = _code_generate(ast.parent, metavar) return ast.synonym, parent def _call(ast): parent_name, parent = _code_generate(ast.parent, metavar) parent += '()' return parent_name, parent def _recurse(ast): parent = ast.parent expr = ast.expr parent_name, parent = _code_generate(parent, metavar) kind = expr.kind if kind in ['attr', 'key', 'list']: parent_name, parent = _code_generate(expr, parent, parent_name) else: subparent_name, subparent = _code_generate(expr, parent_name) parent = '(lambda %s:\n' % parent_name + indent_block (subparent+')(%s)' % parent) return parent_name, parent dispatches = { 'dict': _dict, 'list': _list, 'attr': _attr, 'key': _key, 'as': _as, 'call': _call, 'recurse': _recurse, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') Thanks! P.S. The underscores before the method names might look a little funny for inner methods, but it's the nature of the code..._dict and _list would lead to confusion with builtins, if not actual conflict. From loftusoft at yahoo.com Wed Nov 18 05:10:09 2009 From: loftusoft at yahoo.com (Mike) Date: Wed, 18 Nov 2009 02:10:09 -0800 (PST) Subject: Stagnant Frame Data? References: Message-ID: <5e6f6aaf-903c-4219-a464-ea6c199d485b@b15g2000yqd.googlegroups.com> On Nov 15, 1:36?pm, Terry Reedy wrote: > Peter Otten wrote: > > Mike wrote: > > >> I'll apologize first for this somewhat lengthy example. It does > >> however recreate the problem I've run into. This is stripped-down code > >> from a much more meaningful system. > > >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate > >> variables in their caller's namespace using the frame stack. As > >> written, the output is not what is expected: the variables evaluate to > >> "stagnant" values. > > >> However, if the one indicated line is uncommented, then the result is > >> as expected. > > >> So my questions are: Is this a bug in Python? > > No. The existence and use of sys._getframe -- notice the leading > underscore -- is a CPython implementation artifact. Use at your own risk. > > ?>> Is this an invalid use of frame data? > > Up to you to decide. > > ?>> Why does the single line "sys._getframe(1).f_locals" > > >> fix the behavior? > > It updates the dictionary. > > > > > A simplified demonstration of your problem: > > >>>> def f(update): > > ... ? ? a = locals() > > ... ? ? x = 42 > > ... ? ? if update: locals() > > ... ? ? print a > > ... > >>>> f(False) > > {'update': False} > >>>> f(True) > > {'a': {...}, 'x': 42, 'update': True} > > > The local namespace is not a dictionary, and the locals()/f_locals > > dictionary contains a snapshot of the local namespace. Accessing the > > f_locals attribute is one way to trigger an update of that snapshot. > > > What's puzzling is that the same dictionary is reused. > > Efficiency? Consistency? The doc for locals says "locals() > Update and return a dictionary representing the current local symbol > table." In class statements, where (currently) the local namespace *is* > a dict, no update is needed and locals() simply returns the dict, the > same one each time. > > Terry Jan Reedy Thanks for the replies. If Peter's concise and much-appreciated example were to be modified as such: >>> def f(update): .....: a = inspect.stack()[0][0].f_locals .....: x = 42 .....: if update: .....: inspect.stack()[0][0].f_locals .....: print a .....: >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} Now there's no use of locals() to perform its documented "Update", but just a simple access of a dictionary. This behavior is curious. Further modification by accessing 'a' instead of '...f_locals' upon update produces: >>> f(False) {'update': False} >>> f(True) {'update': True} Checking the id() of 'a' and '...f_locals' shows the same "address". How is it that '...f_locals' gets updated in this example? Is it done in "stack()"? Where exactly is the frame data stored prior to updating the dictionary and can I get to it? Thanks, Mike From loftusoft at yahoo.com Wed Nov 18 05:10:29 2009 From: loftusoft at yahoo.com (Mike) Date: Wed, 18 Nov 2009 02:10:29 -0800 (PST) Subject: Stagnant Frame Data? References: Message-ID: <5fb36344-c61c-46a9-ba0c-907c0eec9bfc@l13g2000yqb.googlegroups.com> On Nov 15, 1:36?pm, Terry Reedy wrote: > Peter Otten wrote: > > Mike wrote: > > >> I'll apologize first for this somewhat lengthy example. It does > >> however recreate the problem I've run into. This is stripped-down code > >> from a much more meaningful system. > > >> I have two example classes, "AutoChecker" and "Snapshot" that evaluate > >> variables in their caller's namespace using the frame stack. As > >> written, the output is not what is expected: the variables evaluate to > >> "stagnant" values. > > >> However, if the one indicated line is uncommented, then the result is > >> as expected. > > >> So my questions are: Is this a bug in Python? > > No. The existence and use of sys._getframe -- notice the leading > underscore -- is a CPython implementation artifact. Use at your own risk. > > ?>> Is this an invalid use of frame data? > > Up to you to decide. > > ?>> Why does the single line "sys._getframe(1).f_locals" > > >> fix the behavior? > > It updates the dictionary. > > > > > A simplified demonstration of your problem: > > >>>> def f(update): > > ... ? ? a = locals() > > ... ? ? x = 42 > > ... ? ? if update: locals() > > ... ? ? print a > > ... > >>>> f(False) > > {'update': False} > >>>> f(True) > > {'a': {...}, 'x': 42, 'update': True} > > > The local namespace is not a dictionary, and the locals()/f_locals > > dictionary contains a snapshot of the local namespace. Accessing the > > f_locals attribute is one way to trigger an update of that snapshot. > > > What's puzzling is that the same dictionary is reused. > > Efficiency? Consistency? The doc for locals says "locals() > Update and return a dictionary representing the current local symbol > table." In class statements, where (currently) the local namespace *is* > a dict, no update is needed and locals() simply returns the dict, the > same one each time. > > Terry Jan Reedy Thanks for the replies. If Peter's concise and much-appreciated example were to be modified as such: >>> def f(update): .....: a = inspect.stack()[0][0].f_locals .....: x = 42 .....: if update: .....: inspect.stack()[0][0].f_locals .....: print a .....: >>> f(False) {'update': False} >>> f(True) {'a': {...}, 'x': 42, 'update': True} Now there's no use of locals() to perform its documented "Update", but just a simple access of a dictionary. This behavior is curious. Further modification by accessing 'a' instead of '...f_locals' upon update produces: >>> f(False) {'update': False} >>> f(True) {'update': True} Checking the id() of 'a' and '...f_locals' shows the same "address". How is it that '...f_locals' gets updated in this example? Is it done in "stack()"? Where exactly is the frame data stored prior to updating the dictionary and can I get to it? Thanks, Mike From jeanmichel at sequans.com Wed Nov 18 05:16:20 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 18 Nov 2009 11:16:20 +0100 Subject: TODO and FIXME tags In-Reply-To: <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Message-ID: <4B03C974.9000106@sequans.com> Scott David Daniels wrote: > Martin P. Hellwig wrote: >> Ben Finney wrote: >>> Chris Rebert writes: >>> >>>> 2009/11/16 Yasser Almeida Hern?ndez : >>>>> How is the sintaxis for set the TODO and FIXME tags...? > ... >>> There's no widely-followed ?syntax? for this convention, though. >> Except for _not_ doing what is suggested in those comments, which >> appears to be the biggest convention :-) > > Perhaps: "The comments are a directive to delete the comment if > you happen do this." > > --Scott David Daniels > Scott.Daniels at Acm.Org I guess the world is split in two categories, those how come back to fix the TODO, and those how don't. I for myself belong to the second, that is why I never write TODO comments, I either do the stuff or consider this is not important enough to waste time on it. In other words I mostly agree with Martin, and envy people belonging to the first category. JM From alexis.flesch at free.fr Wed Nov 18 05:47:02 2009 From: alexis.flesch at free.fr (Snouffy) Date: Wed, 18 Nov 2009 02:47:02 -0800 (PST) Subject: PyQt4 4.4.4 : a bug with highlightBlock ? Message-ID: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Hello everybody, I've been trying to do some syntax highlighting using PyQt4. I ported the example given in the documentation of Qt4 to Python. It works fine on my computer at work (which has PyQt4 version 4.3.3) but doesn't on my home computer (which has version 4.4.4) : it gets stuck in an infinite loop. Here is the code : class MyHighlighter(QtGui.QSyntaxHighlighter): def __init__(self, edit): QtGui.QSyntaxHighlighter.__init__(self,edit) def highlightBlock(self, text): myClassFormat = QtGui.QTextCharFormat() myClassFormat.setFontWeight(QtGui.QFont.Bold) myClassFormat.setForeground(QtCore.Qt.darkMagenta) pattern = "\\b[A-Z_]+\\b" expression = QtCore.QRegExp(pattern) index = text.indexOf(expression); while (index >= 0): length = expression.matchedLength() self.setFormat(index, length, myClassFormat) index = text.indexOf(expression, index + length) What am I missing ? Is this a known bug of version 4.4.4 ? Thank you, Alexis. From jeanmichel at sequans.com Wed Nov 18 06:25:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 18 Nov 2009 12:25:14 +0100 Subject: getting properly one subprocess output Message-ID: <4B03D99A.1040509@sequans.com> Hi python fellows, I'm currently inspecting my Linux process list, trying to parse it in order to get one particular process (and kill it). I ran into an annoying issue: The stdout display is somehow truncated (maybe a terminal length issue, I don't know), breaking my parsing. import subprocess commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, stderr=subprocess.PIPE) processList, stderrdata = process.communicate() Here is a sample of what I get in processList.split('\n'): ' "25487 1122 4344 ? 7-17:48:32 2.5 firefox-bin /usr/lib/iceweasel/firefox-"', ' "25492 1122 4892 pts/6 00:08 57.2 ipython /usr/bin/python /usr/bin/ip"', As you can see, to complete process command line is truncated. Any clue on how to get the full version ? JM (python 2.5) From bartc at freeuk.com Wed Nov 18 06:31:45 2009 From: bartc at freeuk.com (bartc) Date: Wed, 18 Nov 2009 11:31:45 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF"syntax? In-Reply-To: References: Message-ID: Dotan Cohen wrote: > 2009/11/16 Steve Ferg steve.ferg.bitbucket at gmail.com: >> I've often thought that a language with this kind of block-free >> syntax would be nice and intuitive: >> >> if then >> do stuff >> elif then >> do stuff >> else >> do stuff >> endif >> >> Note that you do not need block delimiters. >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? >> > > PHP has exactly this: > > if (condition) { > // stuff > } elseif (otherContition) { > // otherStuff > } elseif (yetAnotherCondition) { > // yetOtherStuff > } The OP explicitly said no block delimiters. Your example uses {..}, and doesn't have endif. -- Bartc From sturlamolden at yahoo.no Wed Nov 18 06:31:56 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Nov 2009 03:31:56 -0800 (PST) Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <5b8d13220911170628g76b0faa1vfa47d6dc035b18c5@mail.gmail.com> Message-ID: On 18 Nov, 00:31, Terry Reedy wrote: > The > problem for the future is the switch to multiple cores for further speedups. The GIL is not a big problem for scientists. Scientists are not so dependent on threads as the Java/webdeveloper crowd: - We are used to running multiple processes with MPI. - Numerical libraries running C/Fortran/Assembler will often release the GIL. Python threads are ok for multicores then. - Numerical libraries can be written or compiles for multicores e.g. using OpenMP or special compilers. If FFTW is compiled for multiple cores it does not matter that Python has a GIL. LAPACK will use multiple cores if you use MKL or GotoBLAS, regardless of the GIL. Etc. - A scientist used to MATLAB will think "MEX function" (i.e. C or Fortran) if something is too slow. A web developer used to Java will think "multithreading". From sturlamolden at yahoo.no Wed Nov 18 06:42:13 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 18 Nov 2009 03:42:13 -0800 (PST) Subject: python simply not scaleable enough for google? References: <4aff8413$0$1588$742ec2ed@news.sonic.net> <7m9oo1F3f2dcmU1@mid.individual.net> <753f38cd-3a67-4eaf-b6e9-10bc8cb89d70@r5g2000yqb.googlegroups.com> <4b00ce0f$0$1613$742ec2ed@news.sonic.net> <7xmy2lyjgm.fsf@ruckus.brouhaha.com> <6949d099-51a8-4093-b717-a209cf0efeb4@n35g2000yqm.googlegroups.com> <7mgpm5F27pqogU1@mid.individual.net> Message-ID: On 18 Nov, 00:24, greg wrote: > NumPy, for example, is *extremely* flexible. Someone put > in the effort, once, to write it and make it fast -- and > now an endless variety of programs can be written very easily > in Python to make use of it. I'm quite sure David Cournapeau knows about NumPy... By the way, NumPy is not particularly fast because of the way it is written. It's performance is hampered by the creation of temporary arrays. But NumPy provides a flexible way of managing memory in scientific programs. From fetchinson at googlemail.com Wed Nov 18 06:55:57 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 18 Nov 2009 12:55:57 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> References: <4B0152A4.7050307@excess.org> <72d718d3-4260-4d66-9dc1-bcd66c7e3f38@d9g2000prh.googlegroups.com> Message-ID: >> How did you make the html 'screenshots'? I guess you have some kind of >> urwid2html tool or some such or is it plain ncurses? > > It's all handled in the demo code. This is from tour.py: > > if urwid.web_display.is_web_request(): > screen = urwid.web_display.Screen() > else: > screen = urwid.raw_display.Screen() Thanks, I missed that. >> Urwid is really cool! > > No argument there :) None, indeed. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From looris at gmail.com Wed Nov 18 07:05:14 2009 From: looris at gmail.com (Lo'oris) Date: Wed, 18 Nov 2009 04:05:14 -0800 (PST) Subject: break LABEL vs. exceptions + PROPOSAL Message-ID: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> I've found this email, back from 10 years ago: http://mail.python.org/pipermail/python-list/1999-September/009983.html I guess it went unnoticed, because that proposal looks really intresting. ? break labels have been refused into python ? we can do it anyway using exceptions ? this is a proposal for something better, resembling "the exception way" and much more powerful and python-like than break labels From simon at brunningonline.net Wed Nov 18 07:31:11 2009 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 18 Nov 2009 12:31:11 +0000 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> References: <95d3590d-16f3-45b6-ac90-8130c2f25f12@e7g2000vbi.googlegroups.com> Message-ID: <8c7f10c60911180431t66053892y7fa6324dd3a59a46@mail.gmail.com> 2009/11/17 sjm : > On Nov 16, 12:54?pm, Steve Ferg > wrote: > >> Does anybody know a language with this kind of syntax for >> ifThenElseEndif? > > Modern-day COBOL: > > IF ? ? ?some-condition > ? ? ? ?do-something > ELSE > ? ? ? ?do-something-else > END-IF. RPG/400's SELEC statement: http://bit.ly/2LDegk Thing of beauty. Cheers, Simon B. From clp2 at rebertia.com Wed Nov 18 07:31:51 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 04:31:51 -0800 Subject: break LABEL vs. exceptions + PROPOSAL In-Reply-To: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> Message-ID: <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> On Wed, Nov 18, 2009 at 4:05 AM, Lo'oris wrote: > I've found this email, back from 10 years ago: > http://mail.python.org/pipermail/python-list/1999-September/009983.html > > I guess it went unnoticed, because that proposal looks really > intresting. > > ? break labels have been refused into python > ? we can do it anyway using exceptions > ? this is a proposal for something better, resembling "the exception > way" and much more powerful and python-like than break labels You're gonna have to wait 18-24 months: http://www.python.org/dev/peps/pep-3003/ Also, the python-ideas list might be a better forum for discussing this than the general-interest list: http://mail.python.org/mailman/listinfo/python-ideas Cheers, Chris -- http://blog.rebertia.com From mal at egenix.com Wed Nov 18 07:34:14 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Wed, 18 Nov 2009 13:34:14 +0100 Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures In-Reply-To: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> References: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> Message-ID: <4B03E9C6.4060303@egenix.com> Steve Howell wrote: > During the last few days I have written code in support of a small DDL > language that encapsulates a concise representation of the > manipulations needed to make a deep subcopy of a Python-like data > structure. It is inspired by syntax from mainstream modern languages, > including, of course, Python. The DDL can be converted to an AST. That > AST can be walked to either generate Python code that expresses the > mapping or to generate Python objects that can execute the mapping. > Either of the prior outputs can then subsequently be applied to real > world inputs to create new Python data structures from old ones, using > the mechanisms specified in the original DDL for attribute access, > dictionary lookup, iteration, method invocation, etc. > > Here is an example of the DDL (and I hate the terminology "DDL," just > cannot think of anything better): > > > { > 'show_table_of_contents', > 'author' { > .person 'name', > .person 'location' as city, > .favorite_books()[ > .title, > .cost() as expense > ] as books} > } > > > There are more details here: > > http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html Personally, I find the explicit approach more intuitive, since you immediately see what you are going to get: show_table_of_contents = context['show_table_of_contents'] author = context['author'] d = { 'show_table_of_contents': show_table_of_contents, 'author': { 'name': author.person['name'], 'city': author.person['location'], 'books': [{ 'title': item.title, 'expense': item.cost(), } for item in author.favorite_books()], }, } I particularly find this part non-intuitive: > .favorite_books()[ > .title, > .cost() as expense > ] as books} and would leave in the square brackets for __getitem__ lookups on these: > .person 'name', > .person 'location' as city, For additional inspiration, you might want to look at XSLT which provides similar transformations on XML data structures. There are also a number of other transformation languages: http://en.wikipedia.org/wiki/Model_Transformation_Language http://en.wikipedia.org/wiki/Data_transformation Regarding the term "DDL": that's normally used for "data definition language" and doesn't really have all that much to do with transforming data. You normally define data structures using DDL - without actually putting data into those structures. Why not "PyDTL".... Python data transformation language ?! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 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 thomas at thomas-lotze.de Wed Nov 18 07:55:52 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 13:55:52 +0100 Subject: Minimally intrusive XML editing using Python Message-ID: I wonder what Python XML library is best for writing a program that makes small modifications to an XML file in a minimally intrusive way. By that I mean that information the program doesn't recognize is kept, as are comments and whitespace, the order of attributes and even whitespace around attributes. In short, I want to be able to change an XML file while producing minimal textual diffs. Most libraries don't allow controlling the order of and the whitespace around attributes, so what's generally left to do is store snippets of original text along with the model objects and re-use that for writing the edited XML if the model wasn't modified by the program. Does a library exist that helps with this? Does any XML library at all allow structured access to the text representation of a tag with its attributes? Thank you very much. -- Thomas From ecir.hana at gmail.com Wed Nov 18 08:02:10 2009 From: ecir.hana at gmail.com (Ecir Hana) Date: Wed, 18 Nov 2009 05:02:10 -0800 (PST) Subject: Redirect stdout to a buffer [Errno 9] References: <7c067b92-8d37-45e1-8b2e-bb79daff6a4c@v30g2000yqm.googlegroups.com> <745efa54-d7d1-45de-a830-296e4e221e1f@m38g2000yqd.googlegroups.com> Message-ID: <32d3502c-f335-42a7-be1c-bb8ddf72d568@d10g2000yqh.googlegroups.com> On Nov 17, 6:51?am, "Gabriel Genellina" wrote: > > The code below now reads from the pipe everything that has been written -- ? > except from Python :( Thanks a lot for the fine code! So far I don't know why it fails to print from Python - I'll post here any news I get... From stefan_ml at behnel.de Wed Nov 18 08:15:07 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 18 Nov 2009 14:15:07 +0100 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4b03f35b$0$7618$9b4e6d93@newsspool1.arcor-online.net> Thomas Lotze, 18.11.2009 13:55: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. Take a look at canonical XML (C14N). In short, that's the only way to get a predictable XML serialisation that can be used for textual diffs. It's supported by lxml. Stefan From clp2 at rebertia.com Wed Nov 18 08:23:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 05:23:54 -0800 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <50697b2c0911180523l6026e984m492806ca0993f3b5@mail.gmail.com> On Wed, Nov 18, 2009 at 4:55 AM, Thomas Lotze wrote: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. > > Most libraries don't allow controlling the order of and the whitespace > around attributes, so what's generally left to do is store snippets of > original text along with the model objects and re-use that for writing the > edited XML if the model wasn't modified by the program. Does a library > exist that helps with this? Does any XML library at all allow structured > access to the text representation of a tag with its attributes? Have you considered using an XML-specific diff tool such as: * One off this list: http://www.manageability.org/blog/stuff/open-source-xml-diff-in-java * xmldiff (it's in Python even): http://www.logilab.org/859 * diffxml: http://diffxml.sourceforge.net/ [Note: I haven't actually used any of these.] Cheers, Chris -- http://blog.rebertia.com From thomas at thomas-lotze.de Wed Nov 18 08:27:00 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 14:27:00 +0100 Subject: Minimally intrusive XML editing using Python References: <4b03f35b$0$7618$9b4e6d93@newsspool1.arcor-online.net> Message-ID: Stefan Behnel wrote: > Take a look at canonical XML (C14N). In short, that's the only way to get a > predictable XML serialisation that can be used for textual diffs. It's > supported by lxml. Thank you for the pointer. IIUC, c14n is about changing an XML document so that its textual representation is reproducible. While this representation would certainly solve my problem if I were to deal with input that's already in c14n form, it doesn't help me handling arbitrarily formatted XML in a minimally intrusive way. IOW, I don't want the XML document to obey the rules of a process, but instead I want a process that respects the textual form my input happens to have. -- Thomas From thomas at thomas-lotze.de Wed Nov 18 08:30:54 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Wed, 18 Nov 2009 14:30:54 +0100 Subject: Minimally intrusive XML editing using Python References: Message-ID: Chris Rebert wrote: > Have you considered using an XML-specific diff tool such as: I'm afraid I'll have to fall back to using such a thing if I don't find a solution to what I actually want to do. I do realize that XML isn't primarily about its textual representation, so I guess I shouldn't be surprised if what I'm looking for doesn't exist. Still, it would be nice if it did... -- Thomas From tsize69 at gmail.com Wed Nov 18 08:32:57 2009 From: tsize69 at gmail.com (Tsize) Date: Wed, 18 Nov 2009 05:32:57 -0800 (PST) Subject: ast manipulation References: Message-ID: Terry, Thank you for responding. I actually figured out how to do this shortly after posting the message. Sorry I wasn't quite clear enough in my post, I will try to be a little more explict in the future. Just to mention it I want to go to each node in the ast including child nodes and change the values. I am making a limited mutation analysis program. If it looks generally useful as I get further along I will release the code. I did an early prototype that worked on the text of the code itself but I thought that using the ast for this would be better and maybe a little faster. Regards, Thomas From keith.hughitt at gmail.com Wed Nov 18 09:09:11 2009 From: keith.hughitt at gmail.com (Keith Hughitt) Date: Wed, 18 Nov 2009 06:09:11 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Message-ID: Hi all, I ran into a problem recently when trying to add support for earlier versions of Python (2.4 and 2.5) to some database related code which uses MySQLdb, and was wondering if anyone has any suggestions. With later versions of Python (2.6), inserting Unicode is very simple, e.g.: # -*- coding: utf-8 -*- ... cursor.execute('''INSERT INTO `table` VALUES (0, '?ngstr?m'),...''') When the same code is run on earlier versions, however, the results is either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or an exception being thrown (Python 2.4): UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 60: ordinal not in range(128) So far I've tried a number of different things, including: 1. Using Unicode strings (e.g. u"\u212B") 2. Manually specifying the encoding using sys.setdefaultencoding ('utf-8') 3. Manually enabling Unicode support in MySQLdb (use_unicode=False, charset = "utf8") ...but no combination of any of the above resulted in proper database content. To be certain that the issue was related to Python/MySQLdb and not MySQL itself, I manually inserted the text and it worked just fine. Furthermore, when working in a Python console, both print "?" and print u"\u212B" display the correct output. Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 (Python 2.4), and 1.2.2-10 (Python 2.5). Thanks! Keith From deets at nospam.web.de Wed Nov 18 09:38:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 15:38:06 +0100 Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? References: Message-ID: <7mif6fF3hmd7eU1@mid.uni-berlin.de> Keith Hughitt wrote: > Hi all, > > I ran into a problem recently when trying to add support for earlier > versions of Python (2.4 and 2.5) to some database related code which > uses MySQLdb, and was wondering if anyone has any suggestions. > > With later versions of Python (2.6), inserting Unicode is very simple, > e.g.: > > # -*- coding: utf-8 -*- > ... > cursor.execute('''INSERT INTO `table` VALUES (0, > '?ngstr?m'),...''') You are aware that the coding-declaration only affects unicode-literals (the ones like u"i'm unicode")? So the above insert-statement is *not* unicode, it's a byte-string in whatever encoding your editor happens to save the file in. And that's point two: make sure your editor reads and writes the file in the same encoding you specified in the comment in the beginning. > > When the same code is run on earlier versions, however, the results is > either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or > an exception being thrown (Python 2.4): > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in > position 60: ordinal not in range(128) Makes sense if the execute tries to encode to unicode first - as you didn't give it a unicode-object. > > So far I've tried a number of different things, including: > > 1. Using Unicode strings (e.g. u"\u212B") > > 2. Manually specifying the encoding using sys.setdefaultencoding > ('utf-8') > > 3. Manually enabling Unicode support in MySQLdb > (use_unicode=False, charset = "utf8") You *disabled* unicode here!!!!! Unicode is NOT utf-8!!! http://www.joelonsoftware.com/articles/Unicode.html > > ...but no combination of any of the above resulted in proper database > content. > > To be certain that the issue was related to Python/MySQLdb and not > MySQL itself, I manually inserted the text and it worked just fine. > Furthermore, when working in a Python console, both print "?" and > print u"\u212B" display the correct output. > > Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 > (Python 2.4), and 1.2.2-10 (Python 2.5). Try the above, and better yet provide self-contained examples that show the behavior. Diez From tschmidt at sacfoodcoop.com Wed Nov 18 10:02:23 2009 From: tschmidt at sacfoodcoop.com (Tony Schmidt) Date: Wed, 18 Nov 2009 07:02:23 -0800 (PST) Subject: open source linux -> windows database connectivity? References: <55f152d5-7005-4d03-bbbf-91999770c981@a32g2000yqm.googlegroups.com> Message-ID: <632b4319-ba2c-4895-9357-4086f668ea67@f10g2000vbl.googlegroups.com> Woo-hoo! Forget ODBC. Got this working with Jython and JDBC drivers! On Nov 13, 1:03?am, "M.-A. Lemburg" wrote: > TonySchmidtwrote: > >> Note: The client part of this product is free. You only need to > >> get a license for the server part. > > > Yeah, but don't I need the server part to make the connection? > > Sure, but you don't need to get a license per client, unlike for > e.g. the combination mxODBC + EasySoft OOB. > > Regards, > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source ?(#1, Nov 13 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 victorsubervi at gmail.com Wed Nov 18 10:04:22 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 18 Nov 2009 11:04:22 -0400 Subject: base64MIME problem, Or Just New Email Client Message-ID: <4dc0cfea0911180704h4cdec41ava74249d859bc0c98@mail.gmail.com> Hi; I'm using SimpleMail, available from SF, that used to work fine for me but now I can't build it on my new server. I get this error: [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] import smtplib, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] File "/usr/lib64/python2.4/smtplib. py", line 49, in ?, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] from email.base64MIME import encode as encode_base64, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] ImportError: No module named base64MIME, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py [Tue Nov 17 09:53:13 2009] [error] [client 208.84.198.58] Premature end of script headers: mail.py, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py So, let's try this: [root at 13gems simplemail]# find . |xargs grep 'base64MIME' [root at 13gems simplemail]# What gives? Well, if there ain't no solving this one, can someone recommend a good client for easily generating emails from forms to inject into qmail? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidj411 at gmail.com Wed Nov 18 10:12:33 2009 From: davidj411 at gmail.com (davidj411) Date: Wed, 18 Nov 2009 07:12:33 -0800 (PST) Subject: best performance for storage of server information for python CGI web app? Message-ID: <58e5cd75-75be-4785-8e79-4903643965ce@e31g2000vbm.googlegroups.com> I am wondering what will give me the best performance for storing information about the servers in our environment. currently i store all info about all servers in a single shelve file, but i have concerns. 1) as the size of the shelve file increases, will performance suffer ? 2) what about if 2 updates occur at the same time to the shelve file? when a shelve file is opened, is the whole file read into memory? if either scenario (1 or 2) is true, then should i think about creating a shelve file per server? i was also thinking about using SQL Lite with one DB to store all the info. with this option, i would not have to worry about concurrent updates, but as the file size increases, i could expect performance to suffer again? I am running Python 2.6 CGI scripts on Apache web server on windows platform. they interact with the current shelve file to pull info or request info from a python service which will go collect the info and put it into the shelve file. From invalid at invalid.invalid Wed Nov 18 10:22:38 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Nov 2009 15:22:38 +0000 (UTC) Subject: IOError: [Errno 28] No space left on device References: Message-ID: On 2009-11-18, hong zhang wrote: >> Apparently the harddisk where you stored the file is full? It's not a real file, and takes up no space. > I have plenty space see: > $ df -l > Filesystem 1K-blocks Used Available Use% Mounted on > /dev/sda1 74027808 4910016 65357380 7% / That doesn't matter. /sys doesn't contain real files. It's an API to access kernel internals. > but following is good. > > cont_tx = 1 > for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: > print >>f, cont_tx Well, if that works, then what's your problem? -- Grant Edwards grante Yow! I wonder if I ought at to tell them about my visi.com PREVIOUS LIFE as a COMPLETE STRANGER? From tbourden at doc.ic.ac.uk Wed Nov 18 10:34:59 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Wed, 18 Nov 2009 15:34:59 +0000 Subject: non-copy slices Message-ID: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Hi, I was looking for a facility similar to slices in python library that would avoid the implicit creation of a new list and copy of elements that is the default behaviour. Instead I'd rather have a lazy iteratable object on the original sequence. Well, in the end I wrote it myself but I was wondering if I missed sth in the library. If I didn't is there a particular reason there isn't sth like that? I find it hard to believe that all slice needs have strictly copy semantics. Cheers, Themis -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Wed Nov 18 10:44:47 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 18 Nov 2009 07:44:47 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <4B04166F.7060507@stoneleaf.us> tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that > would avoid the implicit creation of a new list and copy of elements > that is the default behaviour. Instead I'd rather have a lazy iteratable > object on the original sequence. Well, in the end I wrote it myself but > I was wondering if I missed sth in the library. If I didn't is there a > particular reason there isn't sth like that? I find it hard to believe > that all slice needs have strictly copy semantics. > > Cheers, > Themis Two questions: 1) What is "sth"? and 2), What copy? Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] In [1]: class dummy(object): ...: pass ...: In [2]: a = dummy() In [3]: b = dummy() In [4]: c = dummy() In [5]: d = dummy() In [6]: e = dummy() In [7]: list1 = [a, b, c, d, e] In [8]: list1 Out[8]: [<__main__.dummy object at 0x0130C510>, <__main__.dummy object at 0x013F1A50>, <__main__.dummy object at 0x00A854F0>, <__main__.dummy object at 0x00A7EF50>, <__main__.dummy object at 0x00A7E650>] In [9]: list2 = list1[1:3] In [10]: list2 Out[10]: [<__main__.dummy object at 0x013F1A50>, <__main__.dummy object at 0x00A854F0>] In [11]: list2[0] is list1[1] Out[11]: *True* In [12]: list2[1] is list1[2] Out[12]: *True* No copying of items going on here. What do you get? ~Ethan~ From mail at timgolden.me.uk Wed Nov 18 10:44:51 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 18 Nov 2009 15:44:51 +0000 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <4B041673.8060503@timgolden.me.uk> tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that would > avoid the implicit creation of a new list and copy of elements that is the > default behaviour. Instead I'd rather have a lazy iteratable object on the > original sequence. Well, in the end I wrote it myself but I was wondering if > I missed sth in the library. If I didn't is there a particular reason there > isn't sth like that? I find it hard to believe that all slice needs have > strictly copy semantics. I suspect that itertools is your friend, specifically itertools.islice TJG From tbourden at doc.ic.ac.uk Wed Nov 18 10:52:47 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Wed, 18 Nov 2009 15:52:47 +0000 Subject: non-copy slices In-Reply-To: <4B041673.8060503@timgolden.me.uk> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B041673.8060503@timgolden.me.uk> Message-ID: <7fd737460911180752x5c685164ia33fa205271f2920@mail.gmail.com> Ahhh yes! that's exactly it. Thanks for pointing out! Themis On Wed, Nov 18, 2009 at 3:44 PM, Tim Golden wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > would > > avoid the implicit creation of a new list and copy of elements that is > the > > default behaviour. Instead I'd rather have a lazy iteratable object on > the > > original sequence. Well, in the end I wrote it myself but I was wondering > if > > I missed sth in the library. If I didn't is there a particular reason > there > > isn't sth like that? I find it hard to believe that all slice needs have > > strictly copy semantics. > > I suspect that itertools is your friend, specifically itertools.islice > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Wed Nov 18 11:14:29 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 08:14:29 -0800 (PST) Subject: getting properly one subprocess output References: Message-ID: <8116484c-3438-419c-a30e-0a1d9fe7481b@37g2000yqm.googlegroups.com> On Nov 18, 11:25?am, Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. > > import subprocess > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > processList, stderrdata = process.communicate() > > Here is a sample of what I get in processList.split('\n'): > > ?' "25487 1122 ? ? ?4344 ? ? ? ? ? 7-17:48:32 ?2.5 firefox-bin ? ? > /usr/lib/iceweasel/firefox-"', > ?' "25492 1122 ? ? ?4892 pts/6 ? ? ? ? ?00:08 57.2 ipython ? ? ? ? > /usr/bin/python /usr/bin/ip"', > > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? > > JM > > (python 2.5) What about "ps -eo pid,tty,cmd" ? Sample: 12680 ? geany /usr/share/gramps/ReportBase/ _CommandLineReport.py 12682 ? gnome-pty-helper 12683 pts/0 /bin/bash 13038 ? gnome-terminal 13039 ? gnome-pty-helper 13040 pts/1 bash 13755 pts/1 ps -eo pid,tty,cmd ...etc... hth, Jon. From joncle at googlemail.com Wed Nov 18 11:28:28 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 08:28:28 -0800 (PST) Subject: getting properly one subprocess output References: <8116484c-3438-419c-a30e-0a1d9fe7481b@37g2000yqm.googlegroups.com> Message-ID: On Nov 18, 4:14?pm, Jon Clements wrote: > On Nov 18, 11:25?am, Jean-Michel Pichavant > wrote: > > > > > Hi python fellows, > > > I'm currently inspecting my Linux process list, trying to parse it in > > order to get one particular process (and kill it). > > I ran into an annoying issue: > > The stdout display is somehow truncated (maybe a terminal length issue, > > I don't know), breaking my parsing. > > > import subprocess > > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > processList, stderrdata = process.communicate() > > > Here is a sample of what I get in processList.split('\n'): > > > ?' "25487 1122 ? ? ?4344 ? ? ? ? ? 7-17:48:32 ?2.5 firefox-bin ? ? > > /usr/lib/iceweasel/firefox-"', > > ?' "25492 1122 ? ? ?4892 pts/6 ? ? ? ? ?00:08 57.2 ipython ? ? ? ? > > /usr/bin/python /usr/bin/ip"', > > > As you can see, to complete process command line is truncated. > > Any clue on how to get the full version ? > > > JM > > > (python 2.5) > > What about "ps -eo pid,tty,cmd" ? > > Sample: > 12680 ? ? ? ? ?geany /usr/share/gramps/ReportBase/ > _CommandLineReport.py > 12682 ? ? ? ? ?gnome-pty-helper > 12683 pts/0 ? ?/bin/bash > 13038 ? ? ? ? ?gnome-terminal > 13039 ? ? ? ? ?gnome-pty-helper > 13040 pts/1 ? ?bash > 13755 pts/1 ? ?ps -eo pid,tty,cmd > > ...etc... > > hth, > > Jon. Another thought: if you're only wanting to find and kill a process, what about pkill? Saves you having to filter the list in Python and then issue a kill command. Jon. From doomster at knuut.de Wed Nov 18 11:42:11 2009 From: doomster at knuut.de (Ulrich Eckhardt) Date: Wed, 18 Nov 2009 17:42:11 +0100 Subject: using struct module on a file Message-ID: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Hia! I need to read a file containing packed "binary" data. For that, I find the struct module pretty convenient. What I always need to do is reading a chunk of data from the file (either using calcsize() or a struct.Struct instance) and then parsing it with unpack(). For that, I repeatedly write utility functions that help me do just that, but I can't imagine that there is no better way for that. Questions: 0. Am I approaching this from the wrong direction? I'm not a programming noob, but rather new to Python still. 1. The struct module has pack_into() or unpack_from(), could I somehow combine that with a file? 2. Is there some easier way to read files? I know about array and xdrlib, but neither really fit my desires. 3. Failing all that, would you consider this a useful addition to the struct module, i.e. should I write a feature request? Thanks! Uli From "knutjbj(nospam)" at online.no Wed Nov 18 11:48:04 2009 From: "knutjbj(nospam)" at online.no (nospam) Date: Wed, 18 Nov 2009 17:48:04 +0100 Subject: question about tree in python Message-ID: How should I write a tree using diconary. I have used a dictonary to make a tree. tree={best:collections.defaultdict(lambda:default)} in a id3 tree. Is there a way to multple values and when then only return on type of values. I tried this apporach but it did not work. class Tree: def __init__(self): pass def ini(self,default_tree,d_attr): self.tree={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_A={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_I={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_p={d_attr:collections.defaultdict(lambda:default_tree)} self.tree_n={d_attr:collections.defaultdict(lambda:default_tree)} return self.tree def __call__(self,best,val,subtree): self.tree[best][val]=subtree def input_tree(self,best,val,subtree,postive,negative,attribute_value,info_gain): tree=self.tree print best print val tree[best][val]=subtree print self.tree self.tree_A[best][val]= attribute_value self.tree_I[best][val]= info_gain self.tree_p[best][val]= postive self.tree_n=negative tree=self.tree return tree From ppearson at nowhere.invalid Wed Nov 18 11:50:44 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Nov 2009 16:50:44 GMT Subject: Beautifulsoup code that is not running References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> Message-ID: <7mimv4F3g0n2uU1@mid.individual.net> On Tue, 17 Nov 2009 14:38:55 -0800 (PST), Zeynel wrote: [snip] >>>> from BeautifulSoup import BeautifulSoup > >>>> soup = BeautifulSoup (file("test.html").read()) >>>> title = soup.find('title') >>>> titleString = title.string >>>> open('extract.text', 'w').write(titleString) > > This runs without an error, but nothing is written into the > extract.text file. test.html has tags in it. Hmm. Works for me, but of course I don't have your test.html. Why don't you try examining "title" and "titleString"? Perhaps has resulted in titleString being the empty string. -- To email me, substitute nowhere->spamcop, invalid->net. From showell30 at yahoo.com Wed Nov 18 12:09:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 09:09:09 -0800 (PST) Subject: ANN: a mini-language for encapsulating deep-copy operations on Python data structures References: <4ed77976-8e48-4fc4-bede-bfd192e96d60@g1g2000pra.googlegroups.com> Message-ID: <73c2ab31-8277-4f30-b27e-0fe6d7b40390@g1g2000pra.googlegroups.com> On Nov 18, 4:34?am, "M.-A. Lemburg" wrote: > Steve Howell wrote: > > [...] > > Here is an example of the DDL (and I hate the terminology "DDL," just > > cannot think of anything better): > > > ? ? ? ? ? ? { > > ? ? ? ? ? ? ? ? 'show_table_of_contents', > > ? ? ? ? ? ? ? ? 'author' { > > ? ? ? ? ? ? ? ? ? ? .person 'name', > > ? ? ? ? ? ? ? ? ? ? .person 'location' as city, > > ? ? ? ? ? ? ? ? ? ? .favorite_books()[ > > ? ? ? ? ? ? ? ? ? ? ? ? .title, > > ? ? ? ? ? ? ? ? ? ? ? ? .cost() as expense > > ? ? ? ? ? ? ? ? ? ? ? ? ] as books} > > ? ? ? ? ? ? } > > > There are more details here: > > >http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-... Thanks for your feedback, Marc-Andre! Comments inline... > > Personally, I find the explicit approach more intuitive, since > you immediately see what you are going to get: > > show_table_of_contents = context['show_table_of_contents'] > author = context['author'] > d = { > ? ? 'show_table_of_contents': show_table_of_contents, > ? ? 'author': { > ? ? ? ? 'name': author.person['name'], > ? ? ? ? 'city': author.person['location'], > ? ? ? ? 'books': [{ > ? ? ? ? ? ? 'title': item.title, > ? ? ? ? ? ? 'expense': item.cost(), > ? ? ? ? ? ? } > ? ? ? ? ? ? for item in author.favorite_books()], > ? ? ? ? }, > ? ? } > I understand what you mean about the explicit approach. When you go for brevity, you sacrifice some explicitness. One of the things I'm actually looking to do next is to be able to generate code like what you've written above. You could make the generated code even more procedural in terms of how it walks the structure--for example, replace the list comprehension with a for loop. This could be useful for inserting tracing code, for example. > I particularly find this part non-intuitive: > > > ? ? ? ? ? ? ? ? ? ? .favorite_books()[ > > ? ? ? ? ? ? ? ? ? ? ? ? .title, > > ? ? ? ? ? ? ? ? ? ? ? ? .cost() as expense > > ? ? ? ? ? ? ? ? ? ? ? ? ] as books} > Yep, I think what I really want is this: .favorite_books()[{ .title, .cost() as expense }] as books} I am not sure the curlies make the transformation completely intuitive, but they are more suggestive that you are generating a list of dictionaries. > and would leave in the square brackets for __getitem__ > lookups on these: > > > ? ? ? ? ? ? ? ? ? ? .person 'name', > > ? ? ? ? ? ? ? ? ? ? .person 'location' as city, > Yep, I agree. The square brackets were not a deliberate omission. They were just slightly more tricky to implement because of '[' having double syntactical meaning. > For additional inspiration, you might want to look at XSLT > which provides similar transformations on XML data structures. > > There are also a number of other transformation languages: > > http://en.wikipedia.org/wiki/Model_Transformation_Languagehttp://en.wikipedia.org/wiki/Data_transformation > Thanks for the links! > Regarding the term "DDL": that's normally used for "data definition > language" and doesn't really have all that much to do with > transforming data. You normally define data structures using > DDL - without actually putting data into those structures. > > Why not "PyDTL".... Python data transformation language ?! > Yep, I like that suggestion. The language does indeed describe a transformation. In some ways I was wanting to think of it more broadly, in terms that the transformation also acts as a schema for any input objects. For example, you could use '{.title, .publisher, {.name} }' as a schema to validate that an object behaves like a book. I suppose that's still a transformation in an abstract sense, where the output is just True, False, or maybe even the slice of the transformation that can/cannot be executed. From joncle at googlemail.com Wed Nov 18 12:12:14 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 18 Nov 2009 09:12:14 -0800 (PST) Subject: using struct module on a file References: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Message-ID: On Nov 18, 4:42?pm, Ulrich Eckhardt wrote: > Hia! > > I need to read a file containing packed "binary" data. For that, I find the > struct module pretty convenient. What I always need to do is reading a chunk > of data from the file (either using calcsize() or a struct.Struct instance) > and then parsing it with unpack(). For that, I repeatedly write utility > functions that help me do just that, but I can't imagine that there is no > better way for that. > > Questions: > 0. Am I approaching this from the wrong direction? I'm not a programming > noob, but rather new to Python still. > 1. The struct module has pack_into() or unpack_from(), could I somehow > combine that with a file? > 2. Is there some easier way to read files? I know about array and xdrlib, > but neither really fit my desires. > 3. Failing all that, would you consider this a useful addition to the struct > module, i.e. should I write a feature request? > > Thanks! > > Uli First time I've seen zero based indexing for paragraph markers :) unpack_from() will work on anything that supports the buffer interface. To work with files you can use something like: my4chars = struct.Struct('4c') def struct_read(s, f): return s.unpack_from(f.read(s.size)) Which isn't hideously painful. Jon. From brian.curtin at gmail.com Wed Nov 18 12:50:52 2009 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 18 Nov 2009 11:50:52 -0600 Subject: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey In-Reply-To: <4B035504.4050508@gmail.com> References: <26e06c080911171051v6d97577cu46055d49665ade46@mail.gmail.com> <20091117191852.GC20149@stinemates.org> <26e06c080911171129o2b82cfcr2cd5140c72d8aef0@mail.gmail.com> <4B035504.4050508@gmail.com> Message-ID: On Tue, Nov 17, 2009 at 19:59, Mark Hammond wrote: > On 18/11/2009 6:29 AM, Randall Walls wrote: > >> I don't believe so, but it seems like I'm in a catch 22, where I need to >> _winreg.OpenKey the key first before I can pass it to >> _winreg.DisableReflectionKey, but it doesn't exist, so I can't open it. >> >> I did find out that I can open the key using: >> hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, >> r"SOFTWARE\ODBC\ODBC.INI\ >> DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY) >> >> The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells >> the system to look in the 64bit key area, and not under the Wow6432Node. >> That brings up problem #2, though... I can't seem to CREATE a key in the >> above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY >> (in fact it doesn't accept any options other than key, sub_key). >> _winreg.CreateKey does work, it just puts the key in >> SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to >> use one or the other, and not have to account for both. >> > > It looks like _winreg needs to be enhanced to make the RegCreateKeyEx API > function available. It can be called via the win32api module of pywin32, or > could also be called via ctypes. > > HTH, > > Mark > Created http://bugs.python.org/issue7347 and added a patch which I think will solve the problem moving forward. -------------- next part -------------- An HTML attachment was scrubbed... URL: From henryzhang62 at yahoo.com Wed Nov 18 12:56:46 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 09:56:46 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <299935.11323.qm@web57901.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 9:22 AM > On 2009-11-18, hong zhang > wrote: > > >> Apparently the harddisk where you stored the file > is full? > > It's not a real file, and takes up no space. > > > I have plenty space see: > > $ df -l > > Filesystem? ? ? ? > ???1K-blocks? ? ? Used > Available Use% Mounted on > > /dev/sda1? ? ? ? ? > ???74027808???4910016? > 65357380???7% / > > That doesn't matter.? /sys doesn't contain real > files.? It's an > API to access kernel internals. > > > but following is good. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >? ? ? with open(i, 'w') as f: > >? ? ? ? ? print >>f, > cont_tx > > Well, if that works, then what's your problem? But error comes from following, above is good. That is point here. def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx -- > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? > ???visi.com? ? ? ? ? > ? PREVIOUS LIFE as a COMPLETE > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? > ???STRANGER? > -- > http://mail.python.org/mailman/listinfo/python-list > From highcar at gmail.com Wed Nov 18 13:04:10 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 10:04:10 -0800 (PST) Subject: DOM related question and problem Message-ID: <26412730.post@talk.nabble.com> Hello, these day im making python script related with DOM. problem is these day many website structure is very complicate . what is best method to check DOM structure and path.. i mean...following is some example. what is best method to check can extract such like following info quickly? before i was spent much time to extract such info . and yes im also new to python and DOM. IE.Document.Frames(1).Document.forms('comment').value = 'hello' if i use DOM inspector, can i extract such info quickly ? if so would you show me some sample? here is some site . i want to extract some dom info. today i was spent all day long to extract what is dom info. but failed http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 at the end of this page,can find some comment input box. i want to know what kind of dom element should have to use, such like IE.Document.Frames(1).Document.forms('comment').value = 'hello' anyhelp much appreciate thanks -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26412730.html Sent from the Python - python-list mailing list archive at Nabble.com. From cjns1989 at gmail.com Wed Nov 18 13:07:53 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Wed, 18 Nov 2009 13:07:53 -0500 Subject: ANN: Urwid 0.9.9 - Console UI Library In-Reply-To: <4B0152A4.7050307@excess.org> References: <4B0152A4.7050307@excess.org> Message-ID: <20091118180753.GC3385@turki.gavron.org> I noticed that when run on a 256-color capable xterm, upon exiting the demo programs the colors in the bash shell are modified - e.g the bash prompt, the output of colored ls commands. For instance, due to my fiddling with dircolors, a file with executable flags on is normally displayed in light green and it now appears in bright green, presumably #00ff00. CJ From clp2 at rebertia.com Wed Nov 18 13:10:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 10:10:44 -0800 Subject: DOM related question and problem In-Reply-To: <26412730.post@talk.nabble.com> References: <26412730.post@talk.nabble.com> Message-ID: <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> On Wed, Nov 18, 2009 at 10:04 AM, elca wrote: > Hello, > these day im making python script related with DOM. > > problem is these day many website structure is very complicate . > > what is best method to check DOM structure and path.. > > i mean...following is some example. > > what is best method to check ?can extract such like following info quickly? > > before i was spent much time to extract such info . > > and yes im also new to python and DOM. > > ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' > > if i use DOM inspector, can i extract such info quickly ? if so would you > show me some sample? > > here is some site . i want to extract some dom info. > > today i was spent all day long to extract what is dom info. but failed > > http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 > > at the end of this page,can find some comment input box. > > i want to know what kind of dom element should have to use, such like > > ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' > > anyhelp much appreciate thanks This sounds suspiciously like a spambot. Why do you want to submit comments in an automated fashion exactly? Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Wed Nov 18 13:11:51 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 18 Nov 2009 19:11:51 +0100 Subject: IOError: [Errno 28] No space left on device References: Message-ID: <7mirn7F3g7f0qU1@mid.uni-berlin.de> hong zhang wrote: > > > --- On Wed, 11/18/09, Grant Edwards wrote: > >> From: Grant Edwards >> Subject: Re: IOError: [Errno 28] No space left on device >> To: python-list at python.org >> Date: Wednesday, November 18, 2009, 9:22 AM >> On 2009-11-18, hong zhang >> wrote: >> >> >> Apparently the harddisk where you stored the file >> is full? >> >> It's not a real file, and takes up no space. >> >> > I have plenty space see: >> > $ df -l >> > Filesystem >> 1K-blocks? ? ? Used >> Available Use% Mounted on >> > /dev/sda1 >> 74027808???4910016 >> 65357380???7% / >> >> That doesn't matter.? /sys doesn't contain real >> files.? It's an >> API to access kernel internals. >> >> > but following is good. >> > >> > cont_tx = 1 >> > for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> >with open(i, 'w') as f: >> >print >>f, >> cont_tx >> >> Well, if that works, then what's your problem? > > But error comes from following, above is good. That is point here. > > def do_cont_tx( is_start): > global cont_tx_started, stdscr > if is_start == START and not cont_tx_started: > cont_tx = 1 > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > with open(i, 'w') as f: print >>f, cont_tx -- "cont_x --" doesn't work. So the above can't be the actual code. Diez From tjreedy at udel.edu Wed Nov 18 13:13:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2009 13:13:11 -0500 Subject: break LABEL vs. exceptions + PROPOSAL In-Reply-To: <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Wed, Nov 18, 2009 at 4:05 AM, Lo'oris wrote: >> I've found this email, back from 10 years ago: >> http://mail.python.org/pipermail/python-list/1999-September/009983.html >> >> I guess it went unnoticed, because that proposal looks really >> intresting. I think it went unnoticed because it is not very good, once looked at. >> >> ? break labels have been refused into python >> ? we can do it anyway using exceptions So the proposal is not needed >> ? this is a proposal for something better, resembling "the exception >> way" and much more powerful and python-like than break labels It amounts to duplicating raise x...exception x as break x....continue x in the name of aesthetics and supposed efficiency. There would be no new functionality nor any abbreviation of code. The semantics of break/continue as specific loop subcommands would be changed to 'use anyplace'. The OP gives as a reason the possibility of a typo creating a raise x ... except y mis-match. But a break x ... continue y mismatch is equally likely. Anyway, I think the example given would be better written with immediate assignment followed by simple break, rather than the proposed delayed assignment. The exception example as given would have to be rewritten to work in 3.x. > You're gonna have to wait 18-24 months: > http://www.python.org/dev/peps/pep-3003/ > > Also, the python-ideas list might be a better forum for discussing > this than the general-interest list: > http://mail.python.org/mailman/listinfo/python-ideas This is a fine place to discuss it. Terry Jan Reedy From anthra.norell at bluewin.ch Wed Nov 18 13:17:35 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 18 Nov 2009 19:17:35 +0100 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4B043A3F.8010908@bluewin.ch> Thomas Lotze wrote: > Chris Rebert wrote: > > >> Have you considered using an XML-specific diff tool such as: >> > > I'm afraid I'll have to fall back to using such a thing if I don't find a > solution to what I actually want to do. > > I do realize that XML isn't primarily about its textual representation, so > I guess I shouldn't be surprised if what I'm looking for doesn't exist. > Still, it would be nice if it did... > > Thomas, I just might have what you are looking for. But I want to be sure I understand your problem. So, please show a small sample and explain how you want it modified. Frederic From nobody at nowhere.com Wed Nov 18 13:19:27 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 18:19:27 +0000 Subject: Command line arguments?? References: <51040860-ab72-4012-b11e-d9a971f45c09@o23g2000vbi.googlegroups.com> Message-ID: On Tue, 17 Nov 2009 23:57:55 +0000, Rhodri James wrote: >>> Quote the filenames or escape the spaces: >>> >>> C:\Python26\Python.exe C:\echo.py "C:\New Folder\text.txt" >>> >>> We've been living with this pain ever since windowed GUIs encouraged >>> users >>> to put spaces in their file names (Apple, I'm looking at you!). >>> Fundamentally, if people want the pretty they have to live with the >>> consequences. >> >> We've been living with much worse ever since Unix allowed users to put >> not only spaces but even newlines in their filenames. > > You'll notice I said "encouraged", not "allowed". You'll notice I said "allowed", not "encouraged". Code which can't handle spaces in filenames is broken from the outset; it doesn't suddenly break the first time that someone passes a filename containing spaces. I have a suspicion that Win95 put spaces in two of the most important directory names specifically to force developers to deal with this. Nowadays, any Windows program which cannot handle spaces in pathnames is usually a port of a Unix program (and a shoddy one at that). OTOH, I'm surprised at how much Windows software still cannot handle filenames outside of the system codepage (i.e. it's using the byte-oriented API rather than the Unicode API). From lusvehla at gmail.com Wed Nov 18 13:38:19 2009 From: lusvehla at gmail.com (Cannonbiker) Date: Wed, 18 Nov 2009 10:38:19 -0800 (PST) Subject: Calling Python functions from Excel References: <4B028AC1.8020307@simplistix.co.uk> <4B02D1E3.6080308@simplistix.co.uk> Message-ID: <3381becb-3a90-40f6-a923-1c22ed4068d1@s31g2000yqs.googlegroups.com> On 18 lis, 03:09, "Mark Tolonen" wrote: > "Chris Withers" wrote in message > > news:4B02D1E3.6080308 at simplistix.co.uk... > > > Mark Tolonen wrote: > > >>>> Please I need Calling Python functions from Excel and receive result > >>>> back in Excel. Can me somebody advise simplest solution please? I am > >>>> more VBA programmer than Python. > > >>> Tryhttp://code.google.com/p/pyinex/ > > >> The book Python: Programming on Win32 has a whole chapter on COM, and a > >> section on COM servers. > > > ...and it's generally accepted that COM sucks rocks through straws, so > > explore alternatives when they're available ;-) > > > Chris > > True, but as usual Python makes it pretty darn easy (requires PyWin32): > > ------------- ex.py ------------------------------- > class Example(object): > ? ? _public_methods_ = ['Add','Mul'] > ? ? _reg_progid_ = 'MyPython.Example' > ? ? _reg_clsid_ = '{insert_GUID_here}' > > ? ? def Add(self,a,b): > ? ? ? ? return a+b > > ? ? def Mul(self,a,b): > ? ? ? ? return a*b > > if __name__ == '__main__': > ? ? import win32com.server.register > ? ? win32com.server.register.UseCommandLine(Example) > --------------------------------------------------------- > > -------------- Excel Macro ---------------------- > Sub Testit() > ? ? Set ex = CreateObject("MyPython.Example") > ? ? Range("A1") = ex.Add(1, 2) > ? ? Range("A2") = ex.Mul(3, 4) > End Sub > -------------------------------------------------------- > > Just run the script to register the server. ?"ex.py --unregister" will > remove it. > > -Mark Thanks very much. It works perfectly!!! :-) From nobody at nowhere.com Wed Nov 18 13:44:10 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 18:44:10 +0000 Subject: getting properly one subprocess output References: Message-ID: On Wed, 18 Nov 2009 12:25:14 +0100, Jean-Michel Pichavant wrote: > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? If you only need it to work on Linux, you can just enumerate /proc/[1-9]*/exe or /proc/[1-9]*/cmdline. Or you can add -ww to "ps" to avoid truncating the output. Note that the /proc/*/exe report the actual executable. The command line reported by "ps" (from /proc/*/cmdline) can be modified by the program, so it doesn't necessarily reflect the program being run. From tjreedy at udel.edu Wed Nov 18 13:49:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Nov 2009 13:49:27 -0500 Subject: non-copy slices In-Reply-To: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: tbourden at doc.ic.ac.uk wrote: > Hi, > > I was looking for a facility similar to slices in python library that > would avoid the implicit creation of a new list and copy of elements > that is the default behaviour. Instead I'd rather have a lazy iteratable > object on the original sequence. Well, in the end I wrote it myself but > I was wondering if I missed sth in the library If I didn't is there a > particular reason there isn't sth like that? I find it hard to believe > that all slice needs have strictly copy semantics. It is a strict *shallow* copy. There is no copying of contents. That aside, you are right, hence itertools.islice as already mentioned. In the design of 3.0, I believe the idea was raised of making slices iterables in 3.0, just as was done for map, filter, and range. However, it would have been highly disruptive, and not save much space. Map and range create an unbounded number of new objects, rather than just a sequence of references to existing objects (or bytes or words for bytes and str slices). There is also the problem of virtual slices preventing garbage collection of the source sequence when it is not otherwise needed. Terry Jan Reedy From henryzhang62 at yahoo.com Wed Nov 18 14:15:53 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 11:15:53 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <12689.15967.qm@web57904.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 9:22 AM > On 2009-11-18, hong zhang > wrote: > > >> Apparently the harddisk where you stored the file > is full? > > It's not a real file, and takes up no space. > > > I have plenty space see: > > $ df -l > > Filesystem? ? ? ? > ???1K-blocks? ? ? Used > Available Use% Mounted on > > /dev/sda1? ? ? ? ? > ???74027808???4910016? > 65357380???7% / > > That doesn't matter.? /sys doesn't contain real > files.? It's an > API to access kernel internals. > > > but following is good. > > > > cont_tx = 1 > > for i in > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >? ? ? with open(i, 'w') as f: > >? ? ? ? ? print >>f, > cont_tx > > Well, if that works, then what's your problem? But error comes from following, above is good. That is point here. def do_cont_tx( is_start): global cont_tx_started, stdscr if is_start == START and not cont_tx_started: cont_tx = 1 for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): with open(i, 'w') as f: print >>f, cont_tx From davea at ieee.org Wed Nov 18 14:16:42 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 14:16:42 -0500 Subject: Minimally intrusive XML editing using Python In-Reply-To: References: Message-ID: <4B04481A.3000707@ieee.org> Thomas Lotze wrote: > Chris Rebert wrote: > > >> Have you considered using an XML-specific diff tool such as: >> > > I'm afraid I'll have to fall back to using such a thing if I don't find a > solution to what I actually want to do. > > I do realize that XML isn't primarily about its textual representation, so > I guess I shouldn't be surprised if what I'm looking for doesn't exist. > Still, it would be nice if it did... > > What's your real problem, or use case? Are you just concerned with diffing, or are others likely to read the xml, and want it formatted the way it already is? And how general do you need this tool to be? For example, if the only thing you're doing is modifying existing attributes or existing tags, the "minimal change" would be pretty unambiguous. But if you're adding tags, or adding content on what was an empty element, then the requirement gets fuzzy And finding an existing library for something "fuzzy" is unlikely. Sample input, change list, and desired output would be very useful. DaveA From henryzhang62 at yahoo.com Wed Nov 18 14:16:47 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 11:16:47 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: <7mirn7F3g7f0qU1@mid.uni-berlin.de> Message-ID: <9734.42752.qm@web57906.mail.re3.yahoo.com> --- On Wed, 11/18/09, Diez B. Roggisch wrote: > From: Diez B. Roggisch > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 12:11 PM > hong zhang wrote: > > > > > > > --- On Wed, 11/18/09, Grant Edwards > wrote: > > > >> From: Grant Edwards > >> Subject: Re: IOError: [Errno 28] No space left on > device > >> To: python-list at python.org > >> Date: Wednesday, November 18, 2009, 9:22 AM > >> On 2009-11-18, hong zhang > >> wrote: > >> > >> >> Apparently the harddisk where you stored > the file > >> is full? > >> > >> It's not a real file, and takes up no space. > >> > >> > I have plenty space see: > >> > $ df -l > >> > Filesystem > >> 1K-blocks? ? ? Used > >> Available Use% Mounted on > >> > /dev/sda1 > >> 74027808???4910016 > >> 65357380???7% / > >> > >> That doesn't matter.? /sys doesn't contain real > >> files.? It's an > >> API to access kernel internals. > >> > >> > but following is good. > >> > > >> > cont_tx = 1 > >> > for i in > >> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> >with open(i, 'w') as f: > >> >print >>f, > >> cont_tx > >> > >> Well, if that works, then what's your problem? > > > > But error comes from following, above is good. That is > point here. > > > > def do_cont_tx( is_start): > > global cont_tx_started, stdscr > > if is_start == START and not cont_tx_started: > > cont_tx = 1 > > for i in > > > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > > with open(i, 'w') as f: print >>f, cont_tx -- > > "cont_x --" doesn't work. So the above can't be the actual > code. Sorry, -- is typo. From nobody at nowhere.com Wed Nov 18 14:17:14 2009 From: nobody at nowhere.com (Nobody) Date: Wed, 18 Nov 2009 19:17:14 +0000 Subject: Minimally intrusive XML editing using Python References: Message-ID: On Wed, 18 Nov 2009 13:55:52 +0100, Thomas Lotze wrote: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitespace, the order of attributes and even whitespace > around attributes. In short, I want to be able to change an XML file while > producing minimal textual diffs. > > Most libraries don't allow controlling the order of and the whitespace > around attributes, so what's generally left to do is store snippets of > original text along with the model objects and re-use that for writing the > edited XML if the model wasn't modified by the program. Does a library > exist that helps with this? Does any XML library at all allow structured > access to the text representation of a tag with its attributes? Expat parsers have a CurrentByteIndex field, while SAX parsers have locators. You can use this to identify the portions of the input which need to be processed, and just copy everything else. One downside is that these only report either the beginning (Expat) or end (SAX) of the tag; you'll have to deduce the other side yourself. OTOH, "diff" is probably the wrong tool for the job. From davecook at nowhere.net Wed Nov 18 14:19:40 2009 From: davecook at nowhere.net (Dave Cook) Date: 18 Nov 2009 19:19:40 GMT Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> Message-ID: <00759512$0$8173$c3e8da3@news.astraweb.com> On 2009-11-18, sturlamolden wrote: > GPL If it's an issue for your project, I suggest wxPython. It's cross-platform, fairly complete, and extensible. But the API is clunky compared to Qt. Dave Cook From victorsubervi at gmail.com Wed Nov 18 14:27:11 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 18 Nov 2009 15:27:11 -0400 Subject: A Good Mailer Message-ID: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> Hi; I need a good mailer that will enable me to mail email from web forms. Suggestions? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Wed Nov 18 14:53:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Nov 2009 11:53:34 -0800 Subject: WindowsError is not available on linux? References: Message-ID: In article , Peng Yu wrote: > >It's not clear to me whether WindowsError is available on linux or >not, after I read the document. Here's what I told a co-worker to do yesterday: if os.name == 'nt': DiskError = (OSError, WindowsError) else: DiskError = WindowsError try: disk_operation() except DiskError: logit() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 invalid at invalid.invalid Wed Nov 18 15:00:29 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 18 Nov 2009 20:00:29 +0000 (UTC) Subject: IOError: [Errno 28] No space left on device References: <7mirn7F3g7f0qU1@mid.uni-berlin.de> Message-ID: On 2009-11-18, Diez B. Roggisch wrote: > hong zhang wrote: >>> >>> > but following is good. >>> > >>> > cont_tx = 1 >>> > for i in >>> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >>> >with open(i, 'w') as f: >>> >print >>f, >>> cont_tx >>> >>> Well, if that works, then what's your problem? >> >> But error comes from following, above is good. That is point here. >> >> def do_cont_tx( is_start): >> global cont_tx_started, stdscr >> if is_start == START and not cont_tx_started: >> cont_tx = 1 >> for i in >> glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): >> with open(i, 'w') as f: print >>f, cont_tx -- > > "cont_x --" doesn't work. So the above can't be the actual code. You never want to post the actual code you're running. That would make it too easy for people to help. -- Grant Edwards grante Yow! My mind is making at ashtrays in Dayton ... visi.com From sajmikins at gmail.com Wed Nov 18 15:10:25 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 18 Nov 2009 15:10:25 -0500 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? In-Reply-To: References: Message-ID: <50f98a4c0911181210y48f5970eg9bdc14ede7225851@mail.gmail.com> On Wed, Nov 18, 2009 at 4:15 AM, Steve Howell wrote: > On the topic of "switch" statements and even-more-concise-then-we-have- > already if/elif/else/end constructs, I have to say that Python does > occasionally force you to write code like the code below. ?Maybe > "force" is too strong a word, but Python lends itself to if/elif > blocks like below, which get the job done just fine, but which are not > syntactically pretty, due to the "(el){0,1}if kind ==" duplication. > There are often cases where if/elif statements are just a smell that > you do not know how to do dictionary lookups, but if you converted the > below code to use dictionary lookups, you would complicate the code > almost as much as you abstracted the code, if not more, unless I am > just being very naive. ?Anonymous methods would help to a certain > degree. ?I am not saying I want either anonymous methods or switch > statements, but the lack of either in a language leads to very > procedural looking code when you use number-of-lines-of-code as a > (possibly dubious) metric. > > Maybe this excerpt can be golfed down to something simpler, I would > love to see it! > > ? ? ? ?if kind == 'dict': > ? ? ? ? ? ?return dictionary_schema(ast) > ? ? ? ?elif kind == 'list': > ? ? ? ? ? ?method = dictionary_schema(ast) > ? ? ? ? ? ?return lambda lst: map(method, lst) > ? ? ? ?elif kind == 'attr': > ? ? ? ? ? ?return ((lambda obj: getattr(obj, ast.field)), ast.field) > ? ? ? ?elif kind == 'key': > ? ? ? ? ? ?return (lambda obj: obj.get(ast.field), ast.field) > ? ? ? ?elif kind == 'as': > ? ? ? ? ? ?method, old_name = schema(ast.parent) > ? ? ? ? ? ?return (method, ast.synonym) > ? ? ? ?elif kind == 'call': > ? ? ? ? ? ?method, old_name = schema(ast.parent) > ? ? ? ? ? ?def call(obj): > ? ? ? ? ? ? ? ?return method(obj)() > ? ? ? ? ? ?return (call, old_name) > ? ? ? ?elif kind == 'recurse': > ? ? ? ? ? ?expr = ast.expr > ? ? ? ? ? ?kind = expr.kind > ? ? ? ? ? ?method, field_name = schema(ast.parent) > ? ? ? ? ? ?if kind in ['attr', 'key']: > ? ? ? ? ? ? ? ?new_method, new_field_name = schema(expr) > ? ? ? ? ? ? ? ?field_name = new_field_name > ? ? ? ? ? ?elif kind in ['dict', 'list']: > ? ? ? ? ? ? ? ?new_method = schema(expr) > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?raise Exception('unknown kind!') > ? ? ? ? ? ?def recurse(obj): > ? ? ? ? ? ? ? ?obj = method(obj) > ? ? ? ? ? ? ? ?return new_method(obj) > ? ? ? ? ? ?return (recurse, field_name) > ? ? ? ?else: > ? ? ? ? ? ?raise Exception('unknown kind!') This code is perhaps not a great example of your point. Every "(el){0,1}if" clause (other than the ones in the 'recurse' branch) end in return statements, so the "el's" are pointless. FWIW I might write it like so: class ASTthing: def processAST(self, ast, kind): try: method = getattr(self, 'do_' + kind) except AttributeError: raise Exception('unknown kind!') self.ast = ast return method() def do_dict(self): return dictionary_schema(self.ast) def do_list(self): method = dictionary_schema(self.ast) return lambda lst: map(method, lst) def do_attr(self): field_name = self.ast.field return lambda obj: getattr(obj, field_name), field_name def do_key(self): field_name = self.ast.field return lambda obj: obj.get(field_name), field_name def do_as(self): method, old_name = schema(self.ast.parent) return method, self.ast.synonym def do_call(self): method, old_name = schema(self.ast.parent) return lambda obj: method(obj)(), old_name def do_recurse(self): expr = self.ast.expr kind = expr.kind method, field_name = schema(self.ast.parent) if kind in 'attrkey': new_method, field_name = schema(expr) elif kind in 'dictlist': new_method = schema(expr) else: raise Exception('unknown kind!') def recurse(obj): obj = method(obj) return new_method(obj) return recurse, field_name IMO, that's more pythonic and less complicated. From dotancohen at gmail.com Wed Nov 18 15:20:15 2009 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 18 Nov 2009 22:20:15 +0200 Subject: Language mavens: Is there a programming with "if then else ENDIF"syntax? In-Reply-To: References: Message-ID: <880dece00911181220s6ca1db17wd7326a1988eef5ae@mail.gmail.com> > The OP explicitly said no block delimiters. Your example uses {..}, and > doesn't have endif. > Just out of habit. I think that PHP, like C, lets you avoid the block deliminators so long as the block all fits on one line. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il From t.bourdenas07 at imperial.ac.uk Wed Nov 18 15:22:11 2009 From: t.bourdenas07 at imperial.ac.uk (Themis Bourdenas) Date: Wed, 18 Nov 2009 20:22:11 +0000 Subject: non-copy slices In-Reply-To: References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> Message-ID: <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> Sth else that I noticed as I started using islice. The name is somewhat misleading. Having the slice part in the name I would expect it to imitate the functionality of normal slices. Random access, sub-slicing etc. However, it is only iteratable. Any particular reasons for that? My guess is that it's inside the itertools so it's meant only for iteration and not random access. However, as I told before the name implies the same functionality while the only thing they share is iteration. It's nothing in the library that completely imitates the slice without the copies, right? Cheers, Themis On Wed, Nov 18, 2009 at 6:49 PM, Terry Reedy wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > > would avoid the implicit creation of a new list and copy of elements > > that is the default behaviour. Instead I'd rather have a lazy iteratable > > object on the original sequence. Well, in the end I wrote it myself but > > I was wondering if I missed sth in the library If I didn't is there a > > particular reason there isn't sth like that? I find it hard to believe > > that all slice needs have strictly copy semantics. > > It is a strict *shallow* copy. There is no copying of contents. > That aside, you are right, hence itertools.islice as already mentioned. > In the design of 3.0, I believe the idea was raised of making slices > iterables in 3.0, just as was done for map, filter, and range. However, > it would have been highly disruptive, and not save much space. Map and > range create an unbounded number of new objects, rather than just a > sequence of references to existing objects (or bytes or words for bytes > and str slices). There is also the problem of virtual slices preventing > garbage collection of the source sequence when it is not otherwise needed. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Nov 18 15:38:32 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Nov 2009 15:38:32 -0500 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: On Wed, Nov 18, 2009 at 2:53 PM, Aahz wrote: > In article , > Peng Yu ? wrote: >> >>It's not clear to me whether WindowsError is available on linux or >>not, after I read the document. > > Here's what I told a co-worker to do yesterday: > > if os.name == 'nt': > ? ?DiskError = (OSError, WindowsError) > else: > ? ?DiskError = WindowsError > > try: > ? ?disk_operation() > except DiskError: > ? ?logit() > -- Shouldn't that be the other way? if os.name == 'nt': DiskError = OSError, WindowsError else : DiskError = OSError > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > "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 > -- > http://mail.python.org/mailman/listinfo/python-list > From nagle at animats.com Wed Nov 18 15:53:33 2009 From: nagle at animats.com (John Nagle) Date: Wed, 18 Nov 2009 12:53:33 -0800 Subject: Using "setup.py" for an application, not a library module. Message-ID: <4b045c57$0$1603$742ec2ed@news.sonic.net> Most of the documentation for "setup.py" assumes you're packaging a library module. (Ref: "http://docs.python.org/distutils/setupscript.html") How do you properly package an application? What happens on "setup.py install"? Where does the application get installed? Where does the main program go? If I package and build my app, it packages properly, and unpacks and builds into Messager1.0/build/lib which is appropriate for a library, but not an application. Here's the setup file. distutils.core.setup( name='Messager', description="Baudot Teletype RSS and SMS program", version='1.0', author="John Nagle", author_email="nagle at animats.com", packages=['messager'], requires=['pyserial', 'feedparser'] ) John Nagle From hsiehp at ohsu.edu Wed Nov 18 15:57:11 2009 From: hsiehp at ohsu.edu (Ping-Hsun Hsieh) Date: Wed, 18 Nov 2009 12:57:11 -0800 Subject: make two tables having same orders in both column and row names Message-ID: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Hi, I would like to compare values in two table with same column and row names, but with different orders in column and row names. For example, table_A in a file looks like the follows: AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20 Table_B in the other file looks like the follows: AA101 AA109 AA100 AA103 AA102 BB1 2 9 2.3 2 28 BB2 2 9 2.3 1 28 BB9 2 9 2.3 1 28 BB3 2 2 2 1 28 Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? Thanks, PingHsun From exarkun at twistedmatrix.com Wed Nov 18 15:58:51 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Wed, 18 Nov 2009 20:58:51 -0000 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: <20091118205851.27565.344498845.divmod.xquotient.318@localhost.localdomain> On 07:53 pm, aahz at pythoncraft.com wrote: >In article , >Peng Yu wrote: >> >>It's not clear to me whether WindowsError is available on linux or >>not, after I read the document. > >Here's what I told a co-worker to do yesterday: > >if os.name == 'nt': > DiskError = (OSError, WindowsError) >else: > DiskError = WindowsError > >try: > disk_operation() >except DiskError: > logit() This isn't necessary. WindowsError subclasses OSError. Jean-Paul From simon.hibbs at gmail.com Wed Nov 18 16:02:59 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Wed, 18 Nov 2009 13:02:59 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> Message-ID: <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> On 18 Nov, 07:51, sturlamolden wrote: > > GPL PyQT is GPL for now, but Qt itself is available under the LGPL as is PySide. Eventualy PySide, which tracks the PyQT API, will supplant it and the issue will be moot. For now it can be a problem, but PyQT developer licenses are very afordable at only a few hundred dollars. If a commercial project can't aford that, it's got problems. Only you can know enough to make an informed decision. Wx does look more usable than last time I used it for a project and is a fine option too, for me though QT is the gold standard against all others are measured, and generaly found wanting. Simon Hibbs From henryzhang62 at yahoo.com Wed Nov 18 16:08:34 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 13:08:34 -0800 (PST) Subject: IOError: [Errno 28] No space left on device In-Reply-To: Message-ID: <762634.99131.qm@web57906.mail.re3.yahoo.com> --- On Wed, 11/18/09, Grant Edwards wrote: > From: Grant Edwards > Subject: Re: IOError: [Errno 28] No space left on device > To: python-list at python.org > Date: Wednesday, November 18, 2009, 2:00 PM > On 2009-11-18, Diez B. Roggisch > > wrote: > > hong zhang wrote: > >>> > >>> > but following is good. > >>> > > >>> > cont_tx = 1 > >>> > for i in > >>> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >>> >with open(i, 'w') as f: > >>> >print >>f, > >>> cont_tx > >>> > >>> Well, if that works, then what's your > problem? > >> > >> But error comes from following, above is good. > That is point here. > >> > >> def do_cont_tx( is_start): > >> global cont_tx_started, stdscr > >> if is_start == START and not cont_tx_started: > >> cont_tx = 1 > >> for i in > >> > glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/continuous_tx'): > >> with open(i, 'w') as f: print >>f, cont_tx > -- > > > > "cont_x --" doesn't work. So the above can't be the > actual code. > > You never want to post the actual code you're > running.? That > would make it too easy for people to help. > > -- It is typo. > http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Wed Nov 18 16:09:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 18 Nov 2009 22:09:20 +0100 Subject: WindowsError is not available on linux? In-Reply-To: <4B038142.2090302@ieee.org> References: <366c6f340911171818s215f6ad6m32c8f5fa468ec33b@mail.gmail.com> <586a3f05-7ab2-4313-8fb3-225011cbf11b@t11g2000prh.googlegroups.com> <366c6f340911171937h1280d553y85e65210cdafda61@mail.gmail.com> <4B038142.2090302@ieee.org> Message-ID: Dave Angel wrote: > Worse, even if the exception cannot be thrown on a non-Windows > environment, leaving it undefined makes it very awkward to write > portable code. An except clause that can never happen in a particular > environment is pretty innocent. Or somebody can use a base class for > his except clause, to catch this error and other related ones. But it > blows up if you explicitly use this exception. I think that needs > documentation, at a minimum. WindowsError is a subclass of OSError that contains additional Windows specific error information. Just catch OSError and you are on the safe side. Christian From simon.hibbs at gmail.com Wed Nov 18 16:15:25 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Wed, 18 Nov 2009 13:15:25 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> Message-ID: <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> On 17 Nov, 23:25, Kevin Walzer wrote: > On 11/17/09 4:25 PM, Tim Daneliuk wrote: > > > +1 Tkinter for the simple stuff > > You can actually use Tkinter to do quite sophisticated GUI's that rival > anything found in Qt or wx... Neither Tkinteror Wx have anything that come close to QGraphicsView, the Model-View-Delegate framework, the Phonon multimedia framework integration, QtSQL, QtXML, QtSVG, and the many other first grade components in Qt. You can substitute components from other frameworks, e.g. for database access, but then you lose the integration QtSQL has with the model-view-delegate features in other parts of the Qt world. Qt is much more than just a GUI framework, it's more of a rival to something like the MacOS development libraries, or the .NET framework in terms of the library facilities it offers. I think that's why Nokia bought into it. Qt provides them with a platform with the potential to rival the iPhone dev environment. Of course to take full advantage of it you need to invest in learning it all, which is non-trivial. It comes at a cost in time and potential lock-in. But the point is you can't just say Qt is just like Wx. Simon Hibbs From db3l.net at gmail.com Wed Nov 18 16:18:28 2009 From: db3l.net at gmail.com (David Bolen) Date: Wed, 18 Nov 2009 16:18:28 -0500 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: Simon Hibbs writes: > I've had this problem for a few years. I've tried PythonCard, > WxWidgets with WxDesigner, BoaConstructor, etc. None of them come > anywhere close to PyQT/QTDesigner. For me, the killer feature missing from of all of the wx-based designers is that they require sizer based designs at all stages, not even permitting a fixed layout up front as a first draft. Either that or any case I've found permitting a fixed layout, then didn't permit turning that easily into a sizer-based layout. >From an overall design perspective, that was the feature I found most intriguing in QTDesigner. I could randomly drop stuff around the window while doing an initial layout, which is especially helpful when you aren't quite sure yet how you want the layout to look. Then you can select groups of objects and apply the containers to provide for flexible layout. I absolutely prefer sizer-based layouts for a final implementation, but early in the design stages find it more helpful, and freeing, not to be as tied to the containers. With that said, for various reasons I still prefer wxPython to Qt, and at the moment, find wxFormBuilder the best fit for my own designs (even before the direct Python support, just using XRC). -- David From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 16:35:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 21:35:35 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Wed, 18 Nov 2009 09:33:38 +0200, Dotan Cohen wrote: >> Is there any particular reason why this might be a *bad* language- >> design idea? > > It is about as far from OO as one could get. Whether or not that is > "bad" depends on the use case. That's crazy talk. IF...ENDIF is *syntax*, not a programming model. How is this hypothetical Python-like syntax not object oriented? class Parrot: def speak(self): if self.name is None: name = "Polly" else: name = self.name endif return "%s wants a cracker!" % name Syntax controls *how* you instruct the compiler, the programming model controls *what* you instruct the compiler to do. -- Steven From davea at ieee.org Wed Nov 18 17:00:45 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 18 Nov 2009 17:00:45 -0500 Subject: WindowsError is not available on linux? In-Reply-To: References: Message-ID: <4B046E8D.2070100@ieee.org> Benjamin Kaplan wrote: > On Wed, Nov 18, 2009 at 2:53 PM, Aahz wrote: > >> In article , >> Peng Yu wrote: >> >>> It's not clear to me whether WindowsError is available on linux or >>> not, after I read the document. >>> >> Here's what I told a co-worker to do yesterday: >> >> if os.name ='nt': >> DiskError =OSError, WindowsError) >> else: >> DiskError =indowsError >> >> try: >> disk_operation() >> except DiskError: >> logit() >> -- >> > > Shouldn't that be the other way? > if os.name ='nt': > DiskError =SError, WindowsError > else : > DiskError =SError > > > Doesn't matter. It's not needed anyway, since WindowsError is derived from OSError. So just use OSError in the except clause. DaveA From lie.1296 at gmail.com Wed Nov 18 17:01:21 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 19 Nov 2009 09:01:21 +1100 Subject: question about tree in python In-Reply-To: References: Message-ID: <4b046f00$1@dnews.tpgi.com.au> nospam wrote: > How should I write a tree using diconary. I have used a dictonary to > make a tree. dictionary tree? root = { 'node_a': { 'node_a_a': 'blah', 'node_a_b': 'foo', 'node_a_c': 'bar', }, 'node_b': { 'node_b_a': 'soo', 'node_b_b': 'flee', 'node_b_c': { 'node_b_c_a': 'bee', 'node_b_c_b': 'fee', 'node_b_c_c': 'dee', }, }, } you can throw in some default dicts as well as necessary... Am I misunderstanding something? From threaderslash at gmail.com Wed Nov 18 17:07:01 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 19 Nov 2009 09:07:01 +1100 Subject: Solved: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Message-ID: ---------- Forwarded message ---------- From: Keith Hughitt To: python-list at python.org Date: Wed, 18 Nov 2009 06:09:11 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? Hi all, I ran into a problem recently when trying to add support for earlier versions of Python (2.4 and 2.5) to some database related code which uses MySQLdb, and was wondering if anyone has any suggestions. With later versions of Python (2.6), inserting Unicode is very simple, e.g.: # -*- coding: utf-8 -*- ... cursor.execute('''INSERT INTO `table` VALUES (0, '?ngstr?m'),...''') When the same code is run on earlier versions, however, the results is either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or an exception being thrown (Python 2.4): UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 60: ordinal not in range(128) So far I've tried a number of different things, including: 1. Using Unicode strings (e.g. u"\u212B") 2. Manually specifying the encoding using sys.setdefaultencoding ('utf-8') 3. Manually enabling Unicode support in MySQLdb (use_unicode=False, charset = "utf8") ...but no combination of any of the above resulted in proper database content. To be certain that the issue was related to Python/MySQLdb and not MySQL itself, I manually inserted the text and it worked just fine. Furthermore, when working in a Python console, both print "?" and print u"\u212B" display the correct output. Any ideas? The versions of the MySQLdb adapter tested were 1.2.1 (Python 2.4), and 1.2.2-10 (Python 2.5). Thanks! Keith ---- Hello Keithm, Here is your answer... I run on Python2.5, this syntax works fine for me -- a piece of my code: getMaxID_Query = """SELECT MAX(customerID) FROM customer;""" self.cursorMySQL.execute(getMaxID_Query) Try to use: """ instead of ''' . It will solve your problem. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Wed Nov 18 17:11:23 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 18 Nov 2009 23:11:23 +0100 Subject: python gui builders In-Reply-To: <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> Message-ID: <4B04710B.5050101@gmail.com> Simon Hibbs wrote: > On 18 Nov, 07:51, sturlamolden wrote: > > >> GPL >> > > PyQT is GPL for now, but Qt itself is available under the LGPL as is > PySide. Eventualy PySide, which tracks the PyQT API, will supplant it > and the issue will be moot. For now it can be a problem, but PyQT > developer licenses are very afordable at only a few hundred dollars. > If a commercial project can't aford that, it's got problems. > > Only you can know enough to make an informed decision. Wx does look > more usable than last time I used it for a project and is a fine > option too, for me though QT is the gold standard against all others > are measured, and generaly found wanting. > > Simon Hibbs > Wouldn't it be nice if each fan of some form of GUI-package, would post it's code (and resulting images) for generating one or two standard GUI-forms ? Then everyone can judge the differences, and see what's simple and not so simple !! And of course I'm willing to contribute the wxPython (wrapped in some convenience procedures) for it. cheers, Stef From philip at semanchuk.com Wed Nov 18 17:17:47 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 18 Nov 2009 17:17:47 -0500 Subject: Using "setup.py" for an application, not a library module. In-Reply-To: <4b045c57$0$1603$742ec2ed@news.sonic.net> References: <4b045c57$0$1603$742ec2ed@news.sonic.net> Message-ID: On Nov 18, 2009, at 3:53 PM, John Nagle wrote: > Most of the documentation for "setup.py" assumes you're packaging a > library module. (Ref: "http://docs.python.org/distutils/setupscript.html > ") > How do you properly package an application? What happens > on "setup.py install"? Where does the application get installed? > Where does > the main program go? > > If I package and build my app, it packages properly, and > unpacks and builds into > > Messager1.0/build/lib > > which is appropriate for a library, but not an application. > Here's the setup file. > > > distutils.core.setup( > name='Messager', > description="Baudot Teletype RSS and SMS program", > version='1.0', > author="John Nagle", > author_email="nagle at animats.com", > packages=['messager'], > requires=['pyserial', 'feedparser'] > ) Hi John, I'm not sure what part you find unpalatable other than "lib" being in the pathname. I recently wrote a setup.py for an app called Analysis. Under OS X, Linux and Windows it installs into the site-packages directory so I can run it like so: python C:\Python25\Lib\site-packages\analysis\main.py or: python /usr/local/lib/python2.6/dist-packages/analysis/main.py Now, packaging an application according to the expectations of the platform to provide a double-clickable icon will require something like py2exe or py2app. distutils doesn't provide a facility for that. DOes that give you an idea about what you were asking? bye Philip From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 17:22:51 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 22:22:51 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > P.S. The underscores before the method names might look a little funny > for inner methods, but it's the nature of the code..._dict and _list > would lead to confusion with builtins, if not actual conflict. Then name them something sensible that tells what they do! The convention (which you break at your peril) is that functions are verbs, and classes are nouns. Even "handle_dict" is better than _dict -- the latter looks like you're calling a private mapping type. -- Steven From nick at stinemates.org Wed Nov 18 17:30:41 2009 From: nick at stinemates.org (Nick Stinemates) Date: Wed, 18 Nov 2009 17:30:41 -0500 Subject: A Good Mailer In-Reply-To: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> References: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> Message-ID: <20091118223041.GA30691@stinemates.org> On Wed, Nov 18, 2009 at 03:27:11PM -0400, Victor Subervi wrote: > Hi; > I need a good mailer that will enable me to mail email from web forms. smtplib > Suggestions? silly example.. #!/usr/bin/env python import smtplib session = smtplib.SMTP("localhost") username = "abc" password = "def" session.login(username, password) # only if it requires auth subject = "Hello, " header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" message = "world!" email_from = "victor at is.awesome" email_to = ["email at myhost.com"] session.sendmail(email_from, email_to, header+messages) HTH, Nick Stinemates > TIA, > Victor > -- > http://mail.python.org/mailman/listinfo/python-list From sajmikins at gmail.com Wed Nov 18 17:42:21 2009 From: sajmikins at gmail.com (Simon Forman) Date: Wed, 18 Nov 2009 17:42:21 -0500 Subject: using struct module on a file In-Reply-To: <7mimf5F3ikmbuU1@mid.uni-berlin.de> References: <7mimf5F3ikmbuU1@mid.uni-berlin.de> Message-ID: <50f98a4c0911181442w44868e0dva88296521478bbef@mail.gmail.com> On Wed, Nov 18, 2009 at 11:42 AM, Ulrich Eckhardt wrote: > Hia! > > I need to read a file containing packed "binary" data. For that, I find the > struct module pretty convenient. What I always need to do is reading a chunk > of data from the file (either using calcsize() or a struct.Struct instance) > and then parsing it with unpack(). For that, I repeatedly write utility > functions that help me do just that, but I can't imagine that there is no > better way for that. > > Questions: > 0. Am I approaching this from the wrong direction? I'm not a programming > noob, but rather new to Python still. > 1. The struct module has pack_into() or unpack_from(), could I somehow > combine that with a file? > 2. Is there some easier way to read files? I know about array and xdrlib, > but neither really fit my desires. > 3. Failing all that, would you consider this a useful addition to the struct > module, i.e. should I write a feature request? > > Thanks! > > Uli You might look at "Construct": http://construct.wikispaces.com/ ~Simon From doesnotexist at franzoni.invalid Wed Nov 18 17:55:19 2009 From: doesnotexist at franzoni.invalid (Alan Franzoni) Date: Wed, 18 Nov 2009 22:55:19 GMT Subject: Using "setup.py" for an application, not a library module. In-Reply-To: <4b045c57$0$1603$742ec2ed@news.sonic.net> References: <4b045c57$0$1603$742ec2ed@news.sonic.net> Message-ID: On 11/18/09 9:53 PM, John Nagle wrote: > Most of the documentation for "setup.py" assumes you're packaging a > library module. (Ref: "http://docs.python.org/distutils/setupscript.html") > How do you properly package an application? What happens > on "setup.py install"? Where does the application get installed? Where > does > the main program go? Usually, just package the lib and from your "main program" (e.g. the script that goes in /usr/bin, for instance), do just something like that: #!/usr/bin/python from mylib import main import sys sys.exit(main()) -- Alan Franzoni contact me at public@[mysurname].eu From kw at codebykevin.com Wed Nov 18 17:56:58 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 18 Nov 2009 17:56:58 -0500 Subject: python gui builders In-Reply-To: <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> Message-ID: <4B047BBA.5040405@codebykevin.com> On 11/18/09 4:15 PM, Simon Hibbs wrote: > On 17 Nov, 23:25, Kevin Walzer wrote: >> On 11/17/09 4:25 PM, Tim Daneliuk wrote: >> >>> +1 Tkinter for the simple stuff >> >> You can actually use Tkinter to do quite sophisticated GUI's that rival >> anything found in Qt or wx... > > Neither Tkinteror Wx have anything that come close to QGraphicsView, > the Model-View-Delegate framework, the Phonon multimedia framework > integration, QtSQL, QtXML, QtSVG, and the many other first grade > components in Qt. You can substitute components from other frameworks, > e.g. for database access, but then you lose the integration QtSQL has > with the model-view-delegate features in other parts of the Qt world. A few points of response: -I was focusing primarily on the UI bits, not the other parts of Qt. People tend to think that Tkinter only has labels, listboxes, buttons and menus: recent advances in Tk have greatly expanded and modernized the available widgets. There's also a rich econsystem of widget packages within Tk that can be wrapped in Tkinter. -Qt's support for things like SQL and XML make sense in a Pythonic context mainly if you're focusing on their integration with other parts of Qt. Python has many of these things just fine on its own, as you doubtless know. > > Qt is much more than just a GUI framework, it's more of a rival to > something like the MacOS development libraries, or the .NET framework > in terms of the library facilities it offers. I think that's why Nokia > bought into it. Qt provides them with a platform with the potential to > rival the iPhone dev environment. Of course, and I certainly wasn't claiming otherwise. > > Of course to take full advantage of it you need to invest in learning > it all, which is non-trivial. It comes at a cost in time and potential > lock-in. But the point is you can't just say Qt is just like Wx. > wxWidgets (the C++ library) has support for a lot of things other than UI bits, as well. wxPython itself is mainly a GUI library because the additional features of wxWidgets in C++ are redundant in Python. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 18:02:31 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 23:02:31 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Wed, 18 Nov 2009 01:53:50 -0800, Steve Howell wrote: > On Nov 18, 1:32?am, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell >> wrote: >> > On the topic of "switch" statements and >> > even-more-concise-then-we-have- already if/elif/else/end constructs, >> > I have to say that Python does occasionally force you to write code >> > like the code below. ?Maybe "force" is too strong a word, but Python >> > lends itself to if/elif blocks like below, which get the job done >> > just fine, but which are not syntactically pretty, due to the >> > "(el){0,1}if kind ==" duplication. There are often cases where >> > if/elif statements are just a smell that you do not know how to do >> > dictionary lookups, but if you converted the below code to use >> > dictionary lookups, you would complicate the code almost as much as >> > you abstracted the code, if not more, unless I am just being very >> > naive. >> >> I'm gonna have to disagree and say using the dictionary dispatch >> technique would clean it up a good bit. Yes, it would entail creating >> several functions, but those functions could then be documented (vs. >> the currently opaque code blocks); and due to their separation and >> smaller length, they would be easier to understand and test than the >> given code. Additionally, the sheer length of the given code segment >> probably constitutes a code smell in and of itself for the function >> containing that code. >> >> > If you introduce seven tiny little methods, aren't you increasing the > length of the module by seven lines and introducing more complexity with > the dispatch mechanism? (Actually, it's 14 lines more if you put a line > of whitespace between your methods, and then you are also blurring an > important cue that each of the seven code blocks all perform within the > same context.) Dear me, the 1960s called, they want their controversy over structured programming back *wink* Yes, you increase the length of the module by having function headers. You also increase the length of the module by using meaningful names instead of calling everything "a", "b", "c" etc. We're not playing code golf, there's no reward for making unreadable code. The dispatch mechanism is no more complicated than a series of if...elif statements. In fact, you can replace an arbitrary number of "if x == y" statements with a *single* lookup: if x == 1: return 27 elif x == 2: return 14 elif x == 5: return 7 else: return -1 becomes the single line: return {1: 27, 2: 14, 5: 7}.get(x, -1) (although for more complicated examples, you would put the dict into its own line, or even lines). Dispatching isn't a panacea. You can't (easily) replace a series of if...elif statements where the conditions being tested aren't equality tests, e.g.: if 0 <= x <= 1: return 27 elif 1 < x < 1.5 or x == 2: return 14 elif ... is hard to turn into a dispatcher. But it's still a very useful technique when it applies. > I do agree with your point that separate methods lead to easier unit > testing. > > I'm a little more skeptical about the documentation/understanding > argument, since code is often best understood within the context of > surrounding code. That depends on the code. In particular, it depends on how coupled the code is. Ideally, you should have loosely coupled code, not highly coupled. If the code is loosely coupled, then there's no problem with understanding it in isolation. If the code is highly coupled, then it is hard to refactor it into a separate function, but that's a side-effect of the original problem, namely the high degree of coupling. As a general rule, if you need to know the context of the surrounding code to understand a function, you have too much coupling. > I am also a bit skeptical of any coding technique > that leads to lexical duplication like {'attr': process_attr, 'key': > process_key, 'call': process_call}(ast); that is just replacing one > smell with another. But how is that different from this? if condition(x, 'attr'): return process_attr(x)(ast) elif condition(x, 'key'): return process_key(x)(ast) elif ... Lexical duplication is one of the weakest code smells around, because it is so prone to false negatives. You often can't avoid referring to the same lexical element multiple times: def sinc(x): if x != 0: return sin(x)/x return 1 That's four references to x in a four line function. Is this a problem? No, of course not. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 18:27:15 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Nov 2009 23:27:15 GMT Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: On Wed, 18 Nov 2009 18:28:11 +1300, greg wrote: > r wrote: >> I think the syntax was chosen because the alternatives are even worse >> AND since assignment is SO common in programming, would you *really* >> rather type two chars instead of one? > > Smalltalk solved the problem by using a left-arrow character for > assignment. But they had an unfair advantage in being able to use a > non-standard character set on their custom-built machines. > > We should be able to do a lot better now using Unicode. We could even > heal the <> vs != rift by using a real not-equal symbol! The problem isn't with the available characters, but with *typing* them. It is hard to enter arbitrary Unicode characters by the keyboard, which frankly boggles my mind. I don't know what the state of the art on Mac is these days, but in 1984s Macs had a standard keyboard layout that let you enter most available characters via the keyboard, using sensible mnemonics. E.g. on a US keyboard layout, you could get ? by holding down the Option key and typing =. For me, I had to: Click Start menu > Utilities > More Applications > KCharSelect. Click through thirty-four(!) tables scanning by eye for the symbol I wanted. Click the ? character. Click To Clipboard. Go back to my editor window and paste. -- Steven From wells at submute.net Wed Nov 18 18:28:04 2009 From: wells at submute.net (Wells) Date: Wed, 18 Nov 2009 15:28:04 -0800 (PST) Subject: Arcane question regarding white space, editors, and code collapsing Message-ID: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> I work in TextMate a lot, which I generally love, but it's code collapsing confounds me. Essentially you have to indent blank lines to the proper level for the current block. Then it will collapse that section as one section. If you have simply a new line, it will see it as a break, and not collapse, though the python interpreter doesn't care- it only cares about lines of actual code. Is it... pythonic, then, to have these lines of tabs/spaces to support code collapsing? Is it proper, improper, or irrelevant? Thanks. From ben+python at benfinney.id.au Wed Nov 18 18:56:35 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 10:56:35 +1100 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> Message-ID: <87fx8bl74c.fsf@benfinney.id.au> Wells writes: > Is it... pythonic, then, to have these lines of tabs/spaces to support > code collapsing? Is it proper, improper, or irrelevant? It's quite improper (though syntactically null, in Python) to have trailing whitespace on lines. That includes blank lines. One major reason is that trailing whitespace causes spurious invisible differences between otherwise-identical lines when doing an automatic comparison, which is done quite a lot in collaboration and version control. Fix your text editor (which may entail switching to a better text editor) to respect blank lines and the conventions of the language. -- \ ?Hey Homer! You're late for English!? ?Pff! English, who needs | `\ that? I'm never going to England!? ?Barney & Homer, _The | _o__) Simpsons_ | Ben Finney From showell30 at yahoo.com Wed Nov 18 18:58:24 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 15:58:24 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Nov 18, 2:22?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > > P.S. The underscores before the method names might look a little funny > > for inner methods, but it's the nature of the code..._dict and _list > > would lead to confusion with builtins, if not actual conflict. > > Then name them something sensible that tells what they do! > > The convention (which you break at your peril) is that functions are > verbs, and classes are nouns. Even "handle_dict" is better than _dict -- > the latter looks like you're calling a private mapping type. > Do you verbify functions with no side effects? Do you prefer calculate_cosine(angle) to cosine(angle)? From caldwellinva at verizon.net Wed Nov 18 19:14:13 2009 From: caldwellinva at verizon.net (Doug) Date: Wed, 18 Nov 2009 16:14:13 -0800 (PST) Subject: Writing a Carriage Return in Unicode Message-ID: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Hi! I am trying to write a UTF-8 file of UNICODE strings with a carriage return at the end of each line (code below). filOpen = codecs.open("c:\\temp\\unicode.txt",'w','utf-8') str1 = u'This is a test.' str2 = u'This is the second line.' str3 = u'This is the third line.' strCR = u"\u240D" filOpen.write(str1 + strCR) filOpen.write(str2 + strCR) filOpen.write(str3 + strCR) filOpen.close() The output looks like This is a test.???This is the second line.???This is the third line.??? when opened in Wordpad as a UNICODE file. Thanks for your help!! From showell30 at yahoo.com Wed Nov 18 19:44:09 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 16:44:09 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: On Nov 18, 3:02?pm, Steven D'Aprano wrote: > > That depends on the code. In particular, it depends on how coupled the > code is. Ideally, you should have loosely coupled code, not highly > coupled. If the code is loosely coupled, then there's no problem with > understanding it in isolation. If the code is highly coupled, then it is > hard to refactor it into a separate function, but that's a side-effect of > the original problem, namely the high degree of coupling. > Different blocks of an if/elif/elif/elif/elif/end are never directly coupled to each other, since you know that only one of the blocks is gonna execute. The blocks inherently do not effect each other. What you really achieve by extracting the code from an inside an elif block into a method is decoupling the elif block from the code ABOVE the if. This in and of itself is a good thing, of course, because you get a nice clean namespace in the extracted method, and you make the coupling between the code ABOVE the if and the extracted method explicit by specifying which parameters get passed. And in the case of my original code, all seven methods that were extracted only depended on a single parameter, the variable I was calling "ast," so it was easy to dispatch them all using the same mechanism. (In my case I didn't achieve much in terms of cleaning the local namespace, since the only variable defined above the if/elif/elif/elif/end was "kind," but I did make my code less brittle to future changes.) I am not going to defend "if/elif/elif/elif/elif/end" too vigorously here. There are obvious advantages to extracting methods, even methods that only ever get called from one parent. I do not miss switch statements one bit in Python. I am little more ambivalent about anonymous methods. It pains me just a tiny bit whenever I have write code like this: dispatches = { 'dict': handle_dict, 'list': handle_list, 'attr': handle_attr, 'key': handle_key, 'as': handle_as, 'call': handle_call, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') I have used the idiom that Simon suggested in an earlier post, shown below, but it is still brittle to name changes in a way that anonymous methods are not, because you can't break an inline anonymous method with a name change (the benefits on anonymity!!): try: method = getattr(self, 'do_' + kind) except AttributeError: raise Exception('unknown kind!') self.ast = ast return method() From highcar at gmail.com Wed Nov 18 19:50:08 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 16:50:08 -0800 (PST) Subject: DOM related question and problem In-Reply-To: <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> References: <26412730.post@talk.nabble.com> <50697b2c0911181010k600aa65an7d20b931f6644da1@mail.gmail.com> Message-ID: <26418556.post@talk.nabble.com> Chris Rebert-6 wrote: > > On Wed, Nov 18, 2009 at 10:04 AM, elca wrote: >> Hello, >> these day im making python script related with DOM. >> >> problem is these day many website structure is very complicate . >> >> what is best method to check DOM structure and path.. >> >> i mean...following is some example. >> >> what is best method to check ?can extract such like following info >> quickly? >> >> before i was spent much time to extract such info . >> >> and yes im also new to python and DOM. >> >> ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' >> >> if i use DOM inspector, can i extract such info quickly ? if so would you >> show me some sample? >> >> here is some site . i want to extract some dom info. >> >> today i was spent all day long to extract what is dom info. but failed >> >> http://www.segye.com/Articles/News/Politics/Article.asp?aid=20091118001261&ctg1=06&ctg2=00&subctg1=06&subctg2=00&cid=0101010600000 >> >> at the end of this page,can find some comment input box. >> >> i want to know what kind of dom element should have to use, such like >> >> ? ?IE.Document.Frames(1).Document.forms('comment').value = 'hello' >> >> anyhelp much appreciate thanks > > This sounds suspiciously like a spambot. Why do you want to submit > comments in an automated fashion exactly? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > > Hello this is not spambot actually. it related with my blog scraper.. anyone can help me or advice much appreciate -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26418556.html Sent from the Python - python-list mailing list archive at Nabble.com. From phlip2005 at gmail.com Wed Nov 18 19:58:42 2009 From: phlip2005 at gmail.com (Phlip) Date: Wed, 18 Nov 2009 16:58:42 -0800 (PST) Subject: combinatorics via __future__ generators Message-ID: Python: I have a quaint combinatorics problem. Before I solve it, or find a solution among "generators", I thought y'all might like to show off any solutions. Given an array like this... [0, 4, 3] Produce an array like this: [ [0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 1, 2], [0, 2, 2], [0, 3, 2], ] The first array is the counts of options in 4 slots, and the second is all combinations of indexes of each option, such that every option associates once with every other option. The leading 0 simply represents a slot with no options; the algorithm must preserve those. This should be child's play for the generator package, right? -- Phlip http://zeekland.zeroplayer.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:06:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:06:07 GMT Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: On Thu, 19 Nov 2009 10:56:35 +1100, Ben Finney wrote: > Wells writes: > >> Is it... pythonic, then, to have these lines of tabs/spaces to support >> code collapsing? Is it proper, improper, or irrelevant? > > It's quite improper (though syntactically null, in Python) to have > trailing whitespace on lines. That includes blank lines. Blank lines are far from improper in Python, they're recommended by PEP 8. > One major reason is that trailing whitespace causes spurious invisible > differences between otherwise-identical lines when doing an automatic > comparison, which is done quite a lot in collaboration and version > control. Then you need better comparison software that doesn't give so many false matches due to insignificant differences. > Fix your text editor (which may entail switching to a better text > editor) to respect blank lines and the conventions of the language. Yes, if the editor's handling of code collapsing is broken, it needs to be fixed, or replaced. -- Steven From python at mrabarnett.plus.com Wed Nov 18 20:06:33 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 19 Nov 2009 01:06:33 +0000 Subject: Writing a Carriage Return in Unicode In-Reply-To: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <4B049A19.6050600@mrabarnett.plus.com> Doug wrote: > Hi! > > I am trying to write a UTF-8 file of UNICODE strings with a carriage > return at the end of each line (code below). > > filOpen = codecs.open("c:\\temp\\unicode.txt",'w','utf-8') > > str1 = u'This is a test.' > str2 = u'This is the second line.' > str3 = u'This is the third line.' > > strCR = u"\u240D" > > filOpen.write(str1 + strCR) > filOpen.write(str2 + strCR) > filOpen.write(str3 + strCR) > > filOpen.close() > > The output looks like > This is a test.???This is the second line.???This is the third > line.??? when opened in Wordpad as a UNICODE file. > > Thanks for your help!! u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a visible "CR" graphic) for carriage return. Windows programs normally expect lines to end with '\r\n'; just use u'\n' in programs and open the text files in text mode ('r' or 'w'). Some Windows programs won't recognise UTF-8 text as UTF-8 in files unless they start with a BOM; this will be handled automatically in Python if you specify the encoding as 'utf-8-sig'. From phlip2005 at gmail.com Wed Nov 18 20:07:28 2009 From: phlip2005 at gmail.com (Phlip) Date: Wed, 18 Nov 2009 17:07:28 -0800 (PST) Subject: combinatorics via __future__ generators References: Message-ID: <88c8996b-3e8c-41a5-95b8-87fcb89e70d1@n35g2000yqm.googlegroups.com> On Nov 18, 4:58?pm, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > > ? [0, 4, 3] > > Produce an array like this: > > ? [ > ? ? [0, 0, 0], > ? ? [0, 1, 0], > ? ? [0, 2, 0], > ? ? [0, 3, 0], [0, 0, 1], > [0, 1, 1], > ? ? [0, 2, 1], > ? ? [0, 3, 1], [0, 0, 2], > [0, 1, 2], > ? ? [0, 2, 2], > ? ? [0, 3, 2], > ] I forgot those combinations! > > The first array is the counts of options in 4 slots, and the second is > all combinations of indexes of each option, such that every option > associates once with every other option. The leading 0 simply > represents a slot with no options; the algorithm must preserve those. > > This should be child's play for the generator package, right? > > -- > ? Phlip > ?http://zeekland.zeroplayer.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:13:22 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:13:22 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 15:58:24 -0800, Steve Howell wrote: > On Nov 18, 2:22?pm, Steven D'Aprano > wrote: >> On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: >> > P.S. The underscores before the method names might look a little >> > funny for inner methods, but it's the nature of the code..._dict and >> > _list would lead to confusion with builtins, if not actual conflict. >> >> Then name them something sensible that tells what they do! >> >> The convention (which you break at your peril) is that functions are >> verbs, and classes are nouns. Even "handle_dict" is better than _dict >> -- the latter looks like you're calling a private mapping type. >> >> > Do you verbify functions with no side effects? Do you prefer > calculate_cosine(angle) to cosine(angle)? Neither, I prefer cos(angle). Mathematical functions are a special case. They have been around since long before computers, and there is a whole different tradition for them. (The tradition is that most functions are named after Euler, or the first person to discover them after Euler.) But you're right, the convention of using verbs for functions isn't as strong as the convention of using nouns for classes and types. Functions that return some property of a noun are often named after the property: len(x) rather than get_len(x) sqrt(x) rather than calculate_sqrt(x) and similar. Likewise, conversion functions are often named after the return result: int(x) returns an int str(x) returns a str [pedant] these are actually types, not functions, in Python [/pedant] But I'm not sure what naming convention you used. It seems fairly arbitrary to me, but whatever it is, it clashes with built-ins, which is a good sign that you need a different set of names. Since naming the functions with leading underscores also clashes with the convention that such functions are private, that's a further sign that you should use a different naming convention. At the point that you are apologizing for the convention you use, maybe you should rethink it. But of course it's your code, and you're free to use whatever convention you like. -- Steven From showell30 at yahoo.com Wed Nov 18 20:14:27 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 17:14:27 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> On Nov 18, 3:02?pm, Steven D'Aprano wrote: > Lexical duplication is one of the weakest code smells around, because it > is so prone to false negatives. You often can't avoid referring to the > same lexical element multiple times: > > def sinc(x): > ? ? if x != 0: > ? ? ? ? return sin(x)/x > ? ? return 1 > The existence of one code sample where lexical duplication is a false negative should not get you into the habit of disregarding it all together. In my rewritten code, here is the smell: dispatches = { 'dict': _dict, 'list': _list, 'attr': _attr, 'key': _key, 'as': _as, 'call': _call, 'recurse': _recurse, } if kind in dispatches: return dispatches[kind](ast) else: raise Exception('unknown kind!') There is nothing wrong with the code taken out of context, but one of the first things that lexical duplication should alert you to is the fact that you are creating code that is brittle to extension. In my example, the reference to _dict is 36 lines of code away from its implementation, which forces indirection on the reader. So maybe the methods in between def _dict and _dict are too long. I can pretty quickly rule that out, as the methods average about four lines each. So maybe the dispatch method is calling out the need for a class, as Simon suggested in another post. I also wonder if an inline decorator is in order. One thing I promise not to do is revert the code to if/elif/elif. :) From azeynel1 at gmail.com Wed Nov 18 20:23:07 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 17:23:07 -0800 (PST) Subject: DeprecationWarning on md5 Message-ID: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Hello, I am a newbie both in Scrapy and Python. When I create a project with Scrapy I get these errors: C:\Python26\lib\site-packages\twisted\python\filepath.py:12: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha C:\Python26\lib\site-packages\twisted\spread\pb.py:30: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: DeprecationWarning: the MimeWriter module is deprecated; use the email package instead I found several references to this "bug" but I could not understand how to fix it. Can anyone help? Thanks From showell30 at yahoo.com Wed Nov 18 20:25:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 17:25:43 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <3f466a96-70f2-4b0e-bbd1-558fb9292b65@u25g2000prh.googlegroups.com> Message-ID: <17aa3a4b-57da-414b-846f-f78bbcdf2120@f20g2000prn.googlegroups.com> On Nov 18, 5:13?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 15:58:24 -0800, Steve Howell wrote: > > On Nov 18, 2:22?pm, Steven D'Aprano > > wrote: > >> On Wed, 18 Nov 2009 02:06:49 -0800, Steve Howell wrote: > >> > P.S. The underscores before the method names might look a little > >> > funny for inner methods, but it's the nature of the code..._dict and > >> > _list would lead to confusion with builtins, if not actual conflict. > [...] > > But I'm not sure what naming convention you used. It seems fairly > arbitrary to me, but whatever it is, it clashes with built-ins, which is > a good sign that you need a different set of names. Since naming the > functions with leading underscores also clashes with the convention that > such functions are private, that's a further sign that you should use a > different naming convention. At the point that you are apologizing for > the convention you use, maybe you should rethink it. > > But of course it's your code, and you're free to use whatever convention > you like. > The code in question, with the _list and _dict, is used as a part of mini-compiler-like-thingy that generates code from an expression syntax. If you've ever worked with code to implement compilers, interpreters, VMs, etc., you probably know the naming challenges involved. The whole reason I mentioned the wierd names in a "P.S." was to say that I realized it was a little wierd, and it was kind of besides the point. But I have enjoyed your responses. They are slightly pedantic, of course, but in a good way! Makes me think about the code more... If you want more context on the code itself (apart from if/elif discussion and other digressions), I describe it in more detail here: http://showellonprogramming.blogspot.com/2009/11/more-on-python-deep-copy-schema.html From ben+python at benfinney.id.au Wed Nov 18 20:27:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 12:27:41 +1100 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: <87skcbjoc2.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 19 Nov 2009 10:56:35 +1100, Ben Finney wrote: > > > It's quite improper (though syntactically null, in Python) to have > > trailing whitespace on lines. That includes blank lines. > > Blank lines are far from improper in Python, they're recommended by > PEP 8. I phrased that poorly. I meant ?That [admonishment against trailing whitespace] includes trailing whitespace on otherwise-empty lines?. > > One major reason is that trailing whitespace causes spurious > > invisible differences between otherwise-identical lines when doing > > an automatic comparison, which is done quite a lot in collaboration > > and version control. > > Then you need better comparison software that doesn't give so many > false matches due to insignificant differences. I have such tools, but I shouldn't require others to also have and use them. It would be irresponsible of me to spew output that causes breakage in the absence of such tools. My position on this is: be strict in what you emit (i.e. no trailing whitespace), and construct your output to function well with lowest-common-denominator standard tools (i.e. don't expect sophistication above the standard ?diff -u? etc.). -- \ ?It's up to the masses to distribute [music] however they want | `\ ? The laws don't matter at that point. People sharing music in | _o__) their bedrooms is the new radio.? ?Neil Young, 2008-05-06 | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Nov 18 20:42:44 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 01:42:44 GMT Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> Message-ID: On Wed, 18 Nov 2009 17:14:27 -0800, Steve Howell wrote: > In my rewritten code, here is the smell: > > dispatches = { > 'dict': _dict, > 'list': _list, > 'attr': _attr, > 'key': _key, > 'as': _as, > 'call': _call, > 'recurse': _recurse, > } > if kind in dispatches: > return dispatches[kind](ast) > else: > raise Exception('unknown kind!') > > > There is nothing wrong with the code taken out of context, but one of > the first things that lexical duplication should alert you to is the > fact that you are creating code that is brittle to extension. Really? It is very simple to extend it by adding another key:item to the dict. > In my > example, the reference to _dict is 36 lines of code away from its > implementation, which forces indirection on the reader. It gets worse -- the reference to the in operator is in a completely different module to the implementation of the in operator, which may be in a completely different language! (C in this case.) I'm being sarcastic, of course, but I do have a serious point. I'm not impressed by complaints that the definition of the function is oh-so-very- far-away from where you use it. Well duh, that's one of the reasons we have functions, so they can be used anywhere, not just where they're defined. If a function *only* makes sense immediately where you use it, then the level of coupling is too great and you should either reduce the coupling or bite the bullet and live with all the hassles of inline code. (Code duplication, difficulty in testing, etc.) Of course it would be convenient if, having noticed the reference to (say) function _recurse, you could see its definition without needing to do more than just glance up a line or two. But you should rarely need to care about the implementation -- that's another point of functions. You should be able to treat _recurse as a black box, just as you use the built-in function len as a black box without needing to see its implementation every time you use it. -- Steven From caldwellinva at gmail.com Wed Nov 18 20:46:15 2009 From: caldwellinva at gmail.com (Doug) Date: Wed, 18 Nov 2009 17:46:15 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <399ce95b-311d-4af4-acfe-d4bdd1b74bda@g27g2000yqn.googlegroups.com> Hi! Thanks for clearing this up!! From tbourden at doc.ic.ac.uk Wed Nov 18 20:47:09 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Thu, 19 Nov 2009 01:47:09 +0000 Subject: non-copy slices In-Reply-To: <4B04166F.7060507@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> Message-ID: <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> Hi, sth == something :) sorry for the abbreviation. I'm talking about the shallow copy, still it's a copy. Unnecessary in my case and the worst part in my scenario is the creation (allocation) and deletion of a very large number of lists of moderate size (a few hundred objects) generated due to slices, while I only need to have a restricted view on the original list. The islice class partially solves the problem as I mentioned in the previous emails. Cheers, Themis On Wed, Nov 18, 2009 at 3:44 PM, Ethan Furman wrote: > tbourden at doc.ic.ac.uk wrote: > > Hi, > > > > I was looking for a facility similar to slices in python library that > > would avoid the implicit creation of a new list and copy of elements > > that is the default behaviour. Instead I'd rather have a lazy iteratable > > object on the original sequence. Well, in the end I wrote it myself but > > I was wondering if I missed sth in the library. If I didn't is there a > > particular reason there isn't sth like that? I find it hard to believe > > that all slice needs have strictly copy semantics. > > > > Cheers, > > Themis > > Two questions: 1) What is "sth"? and 2), What copy? > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > (Intel)] > In [1]: class dummy(object): > ...: pass > ...: > > In [2]: a = dummy() > In [3]: b = dummy() > In [4]: c = dummy() > In [5]: d = dummy() > In [6]: e = dummy() > In [7]: list1 = [a, b, c, d, e] > In [8]: list1 > Out[8]: > [<__main__.dummy object at 0x0130C510>, > <__main__.dummy object at 0x013F1A50>, > <__main__.dummy object at 0x00A854F0>, > <__main__.dummy object at 0x00A7EF50>, > <__main__.dummy object at 0x00A7E650>] > > In [9]: list2 = list1[1:3] > In [10]: list2 > Out[10]: > [<__main__.dummy object at 0x013F1A50>, > <__main__.dummy object at 0x00A854F0>] > > In [11]: list2[0] is list1[1] > Out[11]: *True* > In [12]: list2[1] is list1[2] > Out[12]: *True* > > No copying of items going on here. What do you get? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Wed Nov 18 21:06:16 2009 From: rt8396 at gmail.com (r) Date: Wed, 18 Nov 2009 18:06:16 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: On Nov 18, 5:27?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 18:28:11 +1300, greg wrote: > > r wrote: > >> I think the syntax was chosen because the alternatives are even worse > >> AND since assignment is SO common in programming, would you *really* > >> rather type two chars instead of one? > > > Smalltalk solved the problem by using a left-arrow character for > > assignment. But they had an unfair advantage in being able to use a > > non-standard character set on their custom-built machines. > > > We should be able to do a lot better now using Unicode. We could even > > heal the <> vs != rift by using a real not-equal symbol! > > The problem isn't with the available characters, but with *typing* them. > > It is hard to enter arbitrary Unicode characters by the keyboard, which > frankly boggles my mind. I don't know what the state of the art on Mac is > these days, but in 1984s Macs had a standard keyboard layout that let you > enter most available characters via the keyboard, using sensible > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > the Option key and typing =. > > For me, I had to: > > Click Start menu > Utilities > More Applications > KCharSelect. > Click through thirty-four(!) tables scanning by eye for the symbol I > wanted. > Click the ? character. > Click To Clipboard. > Go back to my editor window and paste. > > -- > Steven ? <-- Heres a free lesson... Stephen, hold down and press twice, then release . ;-) PS: But please lets not start using Unicode chars in programming, you guy's already know how much i *hate* Unicode. From clp2 at rebertia.com Wed Nov 18 21:12:45 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:12:45 -0800 Subject: DeprecationWarning on md5 In-Reply-To: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> References: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Message-ID: <50697b2c0911181812k32736d7cuc3075daa29ea1a6e@mail.gmail.com> On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > Hello, > > I am a newbie both in Scrapy and Python. When I create a project with > Scrapy I get these errors: > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > DeprecationWarning: the sha module is deprecated; use the hashlib > module instead import sha > C:\Python26\lib\site-packages\twisted\spread\pb.py:30: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > import md5 > C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: > DeprecationWarning: the MimeWriter module is deprecated; use the email > package instead > > I found several references to this "bug" but I could not understand > how to fix it. Can anyone help? This is a "bug" in the version of Twisted you're using. What Python is saying is that Twisted is using some modules from the Python stdlib that are deprecated and will be removed in some future version of Python, thus Twisted will /eventually/ need to be changed to use the newer replacement library. However, this is only a warning, not an error; the code will run just fine until you update to the eventual Python version that removed said deprecated libraries (by which time a new Twisted version will probably be available with the necessary fixes made). So, basically you can safely ignore the warnings, unless you want to custom-patch your Twisted installation, which I wouldn't particularly recommend. It's also entirely possible your Twisted is outdated and a new version fixed to avoid using the deprecated modules is already available. If you want to suppress the output of the warnings, see the docs for the `warnings` module: http://docs.python.org/library/warnings.html Cheers, Chris -- http://blog.rebertia.com From bluefisher80 at gmail.com Wed Nov 18 21:16:13 2009 From: bluefisher80 at gmail.com (Jim Qiu) Date: Wed, 18 Nov 2009 18:16:13 -0800 (PST) Subject: Invitation to connect on LinkedIn Message-ID: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> LinkedIn ------------ Jim Qiu requested to add you as a connection on LinkedIn: ------------------------------------------ Jaime, I'd like to add you to my professional network on LinkedIn. - Jim Accept invitation from Jim Qiu http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I431163609_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvej0ScPoNcjcQiiZNnSFSd55EjiYTcP4NejgPdPwLrCBxbOYWrSlI/EML_comm_afe/ View invitation from Jim Qiu http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I431163609_3/0PnPAMdzcScj4Pd4ALqnpPbOYWrSlI/svi/ ------------------------------------------ Why might connecting with Jim Qiu be a good idea? Jim Qiu's connections could be useful to you: After accepting Jim Qiu's invitation, check Jim Qiu's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. ------ (c) 2009, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Wed Nov 18 21:27:47 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 20:27:47 -0600 Subject: What is the naming convention for accessor of a 'private' variable? Message-ID: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> http://www.python.org/dev/peps/pep-0008/ The above webpage states the following naming convention. Such a variable can be an internal variable in a class. I'm wondering what is the naming convention for the method that access such variable. - _single_leading_underscore: weak "internal use" indicator. E.g. "from M import *" does not import objects whose name starts with an underscore. From showell30 at yahoo.com Wed Nov 18 21:28:06 2009 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 18 Nov 2009 18:28:06 -0800 (PST) Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: <0aecca47-8517-4ccc-8a6b-394863b26f99@13g2000prl.googlegroups.com> Message-ID: <0b37cc8c-9ef8-4ae1-a64d-957e161f74b8@2g2000prl.googlegroups.com> On Nov 18, 5:42?pm, Steven D'Aprano wrote: > On Wed, 18 Nov 2009 17:14:27 -0800, Steve Howell wrote: > > In my rewritten code, here is the smell: > > > ? ? dispatches = { > > ? ? ? ? ? ? 'dict': _dict, > > ? ? ? ? ? ? 'list': _list, > > ? ? ? ? ? ? 'attr': _attr, > > ? ? ? ? ? ? 'key': _key, > > ? ? ? ? ? ? 'as': _as, > > ? ? ? ? ? ? 'call': _call, > > ? ? ? ? ? ? 'recurse': _recurse, > > ? ? ? ? ? ? } > > ? ? if kind in dispatches: > > ? ? ? ? return dispatches[kind](ast) > > ? ? else: > > ? ? ? ? raise Exception('unknown kind!') > > > There is nothing wrong with the code taken out of context, but one of > > the first things that lexical duplication should alert you to is the > > fact that you are creating code that is brittle to extension. > > Really? It is very simple to extend it by adding another key:item to the > dict. > Easy for me to extend, of course, since I wrote the code. It's the maintainers I am worried about. I can make their lives easier, of course, by changing the text of the exception to say something like this: "Silly maintenance programmer, you now have to update the dispatch table!" I have no problem with that. > > In my > > example, the reference to _dict is 36 lines of code away from its > > implementation, which forces indirection on the reader. > > It gets worse -- the reference to the in operator is in a completely > different module to the implementation of the in operator, which may be > in a completely different language! (C in this case.) > > I'm being sarcastic, of course, but I do have a serious point. I'm not > impressed by complaints that the definition of the function is oh-so-very- > far-away from where you use it. Well duh, that's one of the reasons we > have functions, so they can be used anywhere, not just where they're > defined. > The slippery slope here is that every block of code that you ever write should be extracted out into a method. Now I am all in favor of tiny methods, but the whole point of if/elif/elif/elif/elif/end code is that you are actually calling out to the maintenance programmer that this code is only applicable in certain conditions. That's why "if" statements are called "conditionals"! You are actually telling the maintenance programmer that is only sensible to use these statements under these conditions. It is actually extremely explicit. Now I'm being sarcastic too, but I also have a serious point. Nine times out of ten if/elif/elif/end calls out the smell of spaghetti code. But it can also occasionally be a false negative. It can be a case of avoiding premature abstraction and indirection. From henryzhang62 at yahoo.com Wed Nov 18 21:29:59 2009 From: henryzhang62 at yahoo.com (hong zhang) Date: Wed, 18 Nov 2009 18:29:59 -0800 (PST) Subject: hex In-Reply-To: <50697b2c0911181812k32736d7cuc3075daa29ea1a6e@mail.gmail.com> Message-ID: <441732.63062.qm@web57901.mail.re3.yahoo.com> List, I want to input hex number instead of int number. in type="int" in following, parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", default=0, help="index of 11n mcs table. Default: 0.") How can I do it? Thanks. --henry From clp2 at rebertia.com Wed Nov 18 21:42:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:42:07 -0800 Subject: combinatorics via __future__ generators In-Reply-To: References: Message-ID: <50697b2c0911181842x3b791e7bwc37fbe097ad9ef2@mail.gmail.com> On Wed, Nov 18, 2009 at 4:58 PM, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > > ?[0, 4, 3] > > Produce an array like this: > > ?[ > ? ?[0, 0, 0], > ? ?[0, 1, 0], > ? ?[0, 2, 0], > ? ?[0, 3, 0], > ? ?[0, 1, 1], > ? ?[0, 2, 1], > ? ?[0, 3, 1], > ? ?[0, 1, 2], > ? ?[0, 2, 2], > ? ?[0, 3, 2], > ] > > The first array is the counts of options in 4 slots, and the second is > all combinations of indexes of each option, such that every option > associates once with every other option. The leading 0 simply > represents a slot with no options; the algorithm must preserve those. > > This should be child's play for the generator package, right? from itertools import imap, product def special_range(n): return (xrange(n) if n else [0]) def something(arr): return product(*imap(special_range, arr)) print list(something([0,4,3])) Cheers, Chris -- http://blog.rebertia.com From daniel at stutzbachenterprises.com Wed Nov 18 21:47:07 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 18 Nov 2009 20:47:07 -0600 Subject: non-copy slices In-Reply-To: <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <7fd737460911181222q66b2c4f7me25bc81e30c63039@mail.gmail.com> Message-ID: On Wed, Nov 18, 2009 at 2:22 PM, Themis Bourdenas < t.bourdenas07 at imperial.ac.uk> wrote: > It's nothing in the library that completely imitates the slice without the > copies, right? You might be interested in my blist extension type (link below). Syntactically, using a blist is just like using a list, but it has different performance characteristics. In particular for your needs, taking a slice is cheap. The blist implements copy-on-write behind the scenes, so taking a slice takes O(log n) time, where n is the size of the initial blist. http://pypi.python.org/pypi/blist/ Here is a simple example, which creates a blist with over 500 million elements and takes a slice of over 500 million elements. In under 22 microseconds. :-) from blist import blist small_list = blist([0]) BIG_list = small_list * 2**29 BIG_slice = BIG_list[4:-5] Cashew:~$ python2.5 -m timeit -s 'from blist import blist' 'small_list=blist([0])' ''BIG_list=small_list*2**29' 'BIG_slice=BIG_list[4:-5]' 10000 loops, best of 3: 21.5 usec per loop -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Nov 18 21:47:34 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 18:47:34 -0800 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: > http://www.python.org/dev/peps/pep-0008/ > > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. > > ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M > ? ? ?import *" does not import objects whose name starts with an underscore. If there's a method to access the variable, then it's not all that private, is it? Accessor methods are not Pythonic. Just make the attribute public by not prefixing it with an underscore. See also "Python is Not Java": http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris -- http://blog.rebertia.com From benjamin.kaplan at case.edu Wed Nov 18 21:50:14 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Nov 2009 21:50:14 -0500 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: On Wed, Nov 18, 2009 at 9:27 PM, Peng Yu wrote: > http://www.python.org/dev/peps/pep-0008/ > > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. > > ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M > ? ? ?import *" does not import objects whose name starts with an underscore. > -- You never have any convention for a method that accesses the private variable. In a language that has scope declarations, a method that uses private variables is still declared public or private- there's no special keyword for it. > http://mail.python.org/mailman/listinfo/python-list > From pengyu.ut at gmail.com Wed Nov 18 21:51:37 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 20:51:37 -0600 Subject: convert a string to a regex? Message-ID: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> There are many special characters listed on http://docs.python.org/library/re.html I'm wondering if there is a convenient function that can readily convert a string with the special characters to its corresponding regex. For example, "some.thing" => "some\.thing" From rami.chowdhury at gmail.com Wed Nov 18 22:00:17 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 18 Nov 2009 19:00:17 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> Message-ID: <200911181900.17759.rami.chowdhury@gmail.com> On Wednesday 18 November 2009 17:47:09 tbourden at doc.ic.ac.uk wrote: > Hi, > > sth == something :) sorry for the abbreviation. I'm talking about the > shallow copy, still it's a copy. I'm not sure you're understanding the point others have been making. A list item is merely another reference to an existing object -- it doesn't copy the object in any way. > Unnecessary in my case and the worst > part in my scenario is the creation (allocation)> and deletion of a > very large number of lists of moderate size (a few hundred objects) > generated due to slices, while I only need to have a restricted view > on the original list. > The islice class partially solves the problem > as I mentioned in the previous emails. > > Cheers, > Themis > > On Wed, Nov 18, 2009 at 3:44 PM, Ethan Furman wrote: > > tbourden at doc.ic.ac.uk wrote: > > > Hi, > > > > > > I was looking for a facility similar to slices in python library > > > that would avoid the implicit creation of a new list and copy of > > > elements that is the default behaviour. Instead I'd rather have a > > > lazy iteratable object on the original sequence. Well, in the end > > > I wrote it myself but I was wondering if I missed sth in the > > > library. If I didn't is there a particular reason there isn't sth > > > like that? I find it hard to believe that all slice needs have > > > strictly copy semantics. > > > > > > Cheers, > > > Themis > > > > Two questions: 1) What is "sth"? and 2), What copy? > > > > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit > > (Intel)] > > In [1]: class dummy(object): > > ...: pass > > ...: > > > > In [2]: a = dummy() > > In [3]: b = dummy() > > In [4]: c = dummy() > > In [5]: d = dummy() > > In [6]: e = dummy() > > In [7]: list1 = [a, b, c, d, e] > > In [8]: list1 > > Out[8]: > > [<__main__.dummy object at 0x0130C510>, > > <__main__.dummy object at 0x013F1A50>, > > <__main__.dummy object at 0x00A854F0>, > > <__main__.dummy object at 0x00A7EF50>, > > <__main__.dummy object at 0x00A7E650>] > > > > In [9]: list2 = list1[1:3] > > In [10]: list2 > > Out[10]: > > [<__main__.dummy object at 0x013F1A50>, > > <__main__.dummy object at 0x00A854F0>] > > > > In [11]: list2[0] is list1[1] > > Out[11]: *True* > > In [12]: list2[1] is list1[2] > > Out[12]: *True* > > > > No copying of items going on here. What do you get? > > > > ~Ethan~ > > -- > > http://mail.python.org/mailman/listinfo/python-list > ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From ben+python at benfinney.id.au Wed Nov 18 22:01:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 14:01:45 +1100 Subject: What is the naming convention for accessor of a 'private' variable? References: Message-ID: <87iqd7jjza.fsf@benfinney.id.au> Peng Yu writes: > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable. A property named with a regular public attribute name:: class Foo(object): def __init__(self, spam): self._spam = spam @property def spam(self): return self._spam -- \ ?The only tyrant I accept in this world is the still voice | `\ within.? ?Mahatma Gandhi | _o__) | Ben Finney From pengyu.ut at gmail.com Wed Nov 18 22:03:02 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:03:02 -0600 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <366c6f340911181903s7b956696q2949aa898a1b10df@mail.gmail.com> On Wed, Nov 18, 2009 at 8:50 PM, Benjamin Kaplan wrote: > On Wed, Nov 18, 2009 at 9:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >> ? ? ?import *" does not import objects whose name starts with an underscore. >> -- > > You never have any convention for a method that accesses the private > variable. In a language that has scope declarations, a method that > uses private variables is still declared public or private- there's no > special keyword for it. I knew this. That's why I put quote around 'private' in the email subject. From clp2 at rebertia.com Wed Nov 18 22:03:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:03:59 -0800 Subject: Invitation to connect on LinkedIn In-Reply-To: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> References: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> Message-ID: <50697b2c0911181903p1b5e981ek88fea19aa89537f5@mail.gmail.com> On Wed, Nov 18, 2009 at 6:16 PM, Jim Qiu wrote: > > LinkedIn > > Jim Qiu requested to add you as a connection on LinkedIn: > > Jaime, > > I'd like to add you to my professional network on LinkedIn. > > - Jim > > > Accept View invitation from Jim Qiu > > > WHY MIGHT CONNECTING WITH JIM QIU BE A GOOD IDEA? > > Jim Qiu's connections could be useful to you > After accepting Jim Qiu's invitation, check Jim Qiu's connections to see who else you may know and who you might want an introduction to. Building these connections can create opportunities in the future. > > > > ? 2009, LinkedIn Corporation > > -- > http://mail.python.org/mailman/listinfo/python-list Could one of the list admins please reset the password and change the email on this guy's LinkedIn account? How the heck someone sets their account email to a mailinglist, I'll never figure out. Cheers, Chris -- http://blog.rebertia.com From pengyu.ut at gmail.com Wed Nov 18 22:04:46 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:04:46 -0600 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> Message-ID: <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >> ? ? ?import *" does not import objects whose name starts with an underscore. > > If there's a method to access the variable, then it's not all that > private, is it? > Accessor methods are not Pythonic. Just make the attribute public by > not prefixing it with an underscore. > > See also "Python is Not Java": > http://dirtsimple.org/2004/12/python-is-not-java.html I don't quite understand the following paragraph from the above webpage. Would you please give me an example to help me understand it? "Here's what you do. You write a function that contains a function. The inner function is a template for the functions that you're writing over and over again, but with variables in it for all the things that vary from one case of the function to the next. The outer function takes parameters that have the same names as those variables, and returns the inner function. Then, every place where you'd otherwise be writing yet another function, simply call the outer function, and assign the return value to the name you want the "duplicated" function to appear. Now, if you need to change how the pattern works, you only have to change it in one place: the template." From clp2 at rebertia.com Wed Nov 18 22:06:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:06:04 -0800 Subject: convert a string to a regex? In-Reply-To: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> Message-ID: <50697b2c0911181906p10127fafv493f4c3f82d3e01f@mail.gmail.com> On Wed, Nov 18, 2009 at 6:51 PM, Peng Yu wrote: > There are many special characters listed on > http://docs.python.org/library/re.html > > I'm wondering if there is a convenient function that can readily > convert a string with the special characters to its corresponding > regex. For example, > > "some.thing" => "some\.thing" If you'd taken 45 seconds to scan the documentation: http://docs.python.org/library/re.html#re.escape re.escape(string) Return string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it. Cheers, Chris -- http://blog.rebertia.com From python.list at tim.thechases.com Wed Nov 18 22:12:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 18 Nov 2009 21:12:29 -0600 Subject: convert a string to a regex? In-Reply-To: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> Message-ID: <4B04B79D.7090908@tim.thechases.com> > There are many special characters listed on > http://docs.python.org/library/re.html > > I'm wondering if there is a convenient function that can readily > convert a string with the special characters to its corresponding > regex. For example, > > "some.thing" => "some\.thing" Did you try bothering to *read* the page you linked to? There's a function for escaping strings right there... Literacy...a worthwhile skill to obtain. -tkc From pengyu.ut at gmail.com Wed Nov 18 22:27:58 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 18 Nov 2009 21:27:58 -0600 Subject: convert a string to a regex? In-Reply-To: <4B04B79D.7090908@tim.thechases.com> References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> <4B04B79D.7090908@tim.thechases.com> Message-ID: <366c6f340911181927q79542233x7b770a3ec5ee0511@mail.gmail.com> On Wed, Nov 18, 2009 at 9:12 PM, Tim Chase wrote: >> There are many special characters listed on >> http://docs.python.org/library/re.html >> >> I'm wondering if there is a convenient function that can readily >> convert a string with the special characters to its corresponding >> regex. For example, >> >> "some.thing" => "some\.thing" > > Did you try bothering to *read* the page you linked to? > > There's a function for escaping strings right there... > > Literacy...a worthwhile skill to obtain. Sorry, I didn't see it. If there are examples besides explanations for each command, it will help people see the usage of each command more easily. From clp2 at rebertia.com Wed Nov 18 22:32:03 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Nov 2009 19:32:03 -0800 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> <366c6f340911181904g12b933d0mb2592ef7bc97baa8@mail.gmail.com> Message-ID: <50697b2c0911181932r4c65cdd7ted8c638224f3b5a1@mail.gmail.com> On Wed, Nov 18, 2009 at 7:04 PM, Peng Yu wrote: > On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >>> http://www.python.org/dev/peps/pep-0008/ >>> >>> The above webpage states the following naming convention. Such a >>> variable can be an internal variable in a class. I'm wondering what is >>> the naming convention for the method that access such variable. >>> >>> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. "from M >>> ? ? ?import *" does not import objects whose name starts with an underscore. >> >> If there's a method to access the variable, then it's not all that >> private, is it? >> Accessor methods are not Pythonic. Just make the attribute public by >> not prefixing it with an underscore. >> >> See also "Python is Not Java": >> http://dirtsimple.org/2004/12/python-is-not-java.html > > I don't quite understand the following paragraph from the above > webpage. Would you please give me an example to help me understand it? > > "Here's what you do. You write a function that contains a function. > The inner function is a template for the functions that you're writing > over and over again, but with variables in it for all the things that > vary from one case of the function to the next. The outer function > takes parameters that have the same names as those variables, and > returns the inner function. Then, every place where you'd otherwise be > writing yet another function, simply call the outer function, and > assign the return value to the name you want the "duplicated" function > to appear. Now, if you need to change how the pattern works, you only > have to change it in one place: the template." #untested off-the-cuff example: from time import time def add_timing(func): # takes a function as an argument """Wraps functions so they output their execution time when called""" def wrapper(*args, **kwargs): #defines a new function start = time() # thanks to closures, we can access func here result = func(*args, **kwargs) # have the new function call the given function end = time() duration = end-start print "Call to", func.__name__, "took", duration, "seconds" return result return wrapper # return the new function so that it can replace the function it calls def long_calculation(x, y, z): # some code long_calculation = add_timing(long_calculation) print long_calculation(1, 7, 42) #Example output: #Call to long_calculation took 135.5 seconds #99 Now imaging applying add_timing to multiple functions and note the amount of code you'd save and how the unrelated concerns of timing and mathematical calculation (or whatever the functions you apply add_timing() to do) would then be cleanly separated. The same technique can be applied to logging and other repetitive code to factor it out. It's sort of like aspect-oriented programming, but not as kludgey. Cheers, Chris -- http://blog.rebertia.com From threaderslash at gmail.com Wed Nov 18 22:51:27 2009 From: threaderslash at gmail.com (Threader Slash) Date: Thu, 19 Nov 2009 14:51:27 +1100 Subject: Qt Python radiobutton: activate event Message-ID: Hi Guys, I am trying to get the choice made by the user on Python Qt with radiobutton. QtCore.QObject.connect(self.radioButton1, QtCore.SIGNAL("toggled()"),self.radio_activateInput) QtCore.QObject.connect(self.radioButton2, QtCore.SIGNAL("toggled()"),self.radio_activateInput) and that QtCore.QObject.connect(self.performGroupBox, QtCore.SIGNAL("toggled()"),self.radio_activateInput) But it didn't make anything when I click on the option. Yes, I have enabled it: self.radioButton1.setCheckable(True) self.radioButton1.setChecked(True) self.radioButton2.setCheckable(True) Any suggestion? -------------- next part -------------- An HTML attachment was scrubbed... URL: From highcar at gmail.com Wed Nov 18 23:18:28 2009 From: highcar at gmail.com (elca) Date: Wed, 18 Nov 2009 20:18:28 -0800 (PST) Subject: mechanize login problem with website Message-ID: <26420202.post@talk.nabble.com> Hello I'm making auto-login script by use mechanize python. Before I was used mechanize with no problem, but http://www.gmarket.co.kr in this site I couldn't make it . whenever i try to login always login page was returned even with correct gmarket id , pass, i can't login and I saw some suspicious message "" I think this related with my problem, but don't know exactly how to handle . i was upload my script in here http://paste.pocoo.org/show/151607/ if anyone can help me much appreciate thanks in advance -- View this message in context: http://old.nabble.com/mechanize-login-problem-with-website-tp26420202p26420202.html Sent from the Python - python-list mailing list archive at Nabble.com. From azeynel1 at gmail.com Wed Nov 18 23:59:24 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 20:59:24 -0800 (PST) Subject: Beautifulsoup code that is not running References: <4a1192f0-6798-4ab7-bd76-2a57aa6bc1fe@j19g2000yqk.googlegroups.com> <7mimv4F3g0n2uU1@mid.individual.net> Message-ID: Yes, it shows as empty string. But I learned about Scrapy and now I am studying the tutorial. I like it better than BeautifulSoup. For beginners it is better, I think. On Nov 18, 11:50?am, Peter Pearson wrote: > On Tue, 17 Nov 2009 14:38:55 -0800 (PST), Zeynel wrote: > > [snip] > > >>>> from BeautifulSoup import BeautifulSoup > > >>>> soup = BeautifulSoup (file("test.html").read()) > >>>> title = soup.find('title') > >>>> titleString = title.string > >>>> open('extract.text', 'w').write(titleString) > > > This runs without an error, but nothing is written into the > > extract.text file. test.html has tags in it. > > Hmm. ?Works for me, but of course I don't have your test.html. > Why don't you try examining "title" and "titleString"? ?Perhaps > has resulted in titleString being the empty string. > > -- > To email me, substitute nowhere->spamcop, invalid->net. From azeynel1 at gmail.com Thu Nov 19 00:04:44 2009 From: azeynel1 at gmail.com (Zeynel) Date: Wed, 18 Nov 2009 21:04:44 -0800 (PST) Subject: DeprecationWarning on md5 References: <36eecbe7-5cc3-4812-9b73-9ef70567cb6c@u7g2000yqm.googlegroups.com> Message-ID: <398bca0b-900c-4e8c-b6a0-b4a3af7c2c54@k17g2000yqh.googlegroups.com> Thanks. I tried the suppress it but no success. I need to read the documentation more carefully. But since this is not error, I will ignore them for now. On Nov 18, 9:12?pm, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > > Hello, > > > I am a newbie both in Scrapy and Python. When I create a project with > > Scrapy I get these errors: > > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > > DeprecationWarning: the sha module is deprecated; use the hashlib > > module instead import sha > > C:\Python26\lib\site-packages\twisted\spread\pb.py:30: > > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > import md5 > > C:\Python26\lib\site-packages\twisted\mail\smtp.py:10: > > DeprecationWarning: the MimeWriter module is deprecated; use the email > > package instead > > > I found several references to this "bug" but I could not understand > > how to fix it. Can anyone help? > > This is a "bug" in the version of Twisted you're using. What Python is > saying is that Twisted is using some modules from the Python stdlib > that are deprecated and will be removed in some future version of > Python, thus Twisted will /eventually/ need to be changed to use the > newer replacement library. > However, this is only a warning, not an error; the code will run just > fine until you update to the eventual Python version that removed said > deprecated libraries (by which time a new Twisted version will > probably be available with the necessary fixes made). > > So, basically you can safely ignore the warnings, unless you want to > custom-patch your Twisted installation, which I wouldn't particularly > recommend. > It's also entirely possible your Twisted is outdated and a new version > fixed to avoid using the deprecated modules is already available. > > If you want to suppress the output of the warnings, see the docs for > the `warnings` module:http://docs.python.org/library/warnings.html > > Cheers, > Chris > --http://blog.rebertia.com From 54wutong at gmail.com Thu Nov 19 00:21:02 2009 From: 54wutong at gmail.com (Stephen.Wu) Date: Wed, 18 Nov 2009 21:21:02 -0800 (PST) Subject: is there any FIX message handle modules in Python? Message-ID: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> FIX message is the "Financial information Exchange" protocol messages... any 3rd libs we have? From wuwei23 at gmail.com Thu Nov 19 00:25:27 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 18 Nov 2009 21:25:27 -0800 (PST) Subject: is there any FIX message handle modules in Python? References: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> Message-ID: <591b3af9-3db7-4d3d-bf69-bdbd48bc51e4@h14g2000pri.googlegroups.com> On Nov 19, 3:21?pm, "Stephen.Wu" <54wut... at gmail.com> wrote: > FIX message is the "Financial information Exchange" protocol > messages... > any 3rd libs we have? You mean like this one that was the first result when I googled 'python "financial information exchange"'? http://www.quickfixengine.org/ From tjreedy at udel.edu Thu Nov 19 01:11:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Nov 2009 01:11:46 -0500 Subject: IOError: [Errno 28] No space left on device In-Reply-To: <762634.99131.qm@web57906.mail.re3.yahoo.com> References: <762634.99131.qm@web57906.mail.re3.yahoo.com> Message-ID: hong zhang wrote: > >>> "cont_x --" doesn't work. So the above can't be the >> actual code. >> >> You never want to post the actual code you're >> running. That would make it too easy for people to help. > It is typo. To avoid typos, copy and paste, as has been suggested many times. From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:14:34 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:14:34 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2ca$0$964$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:14:47 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:14:47 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2d7$0$930$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From enleverLesX_XXmcX at XmclavXeauX.com.invalid Thu Nov 19 01:15:06 2009 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Thu, 19 Nov 2009 07:15:06 +0100 Subject: ANN: Urwid 0.9.9 - Console UI Library References: Message-ID: <4b04e2ea$0$963$ba4acef3@news.orange.fr> Hi! You forget to write "urwid" do not run under Windows. @-salutations -- Michel Claveau From d.dalton at iinet.net.au Thu Nov 19 02:10:32 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 19 Nov 2009 18:10:32 +1100 Subject: python and web pages Message-ID: <20091119071032.GA8462@debian-hp.lan> Hi, Here is my situation: I'm using the command line, as in, I'm not starting gnome or kde (I'm on linux.) I have a string of text attached to a variable,. So I need to use one of the browsers on linux, that run under the command line, eg. lynx, elinks, links, links2 and do the following. 1. Open a certain web page and find the first text box on the page, and put this text into the form. 2. Press the submit button, and wait for the result page to load. 3. Click on the 15th link down the page. So, how do I do this, can anyone point me to some docs or modules that may help out here? Thank you, -- Cheers, Dan http://members.iinet.net.au/~ddalton/ From andrethehunter at gmail.com Thu Nov 19 03:02:59 2009 From: andrethehunter at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 19 Nov 2009 00:02:59 -0800 (PST) Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The specified module could not be found." Message-ID: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> Hello, I'm trying to get Python 3.1 and cx_Oracle 5.02 (cx_Oracle-5.0.2-10g.win32-py3.0.msi) to connect to an Oracle 11.1.0.7.0 database via OraClient10g 10.2.0.3.0 with Pydev 1.5.1.1258496115 in Eclipse 20090920-1017 on Windows XP SP 3 v2002. The import cx_Oracle line appears as an unresolved import and when I run the application I get the following error to console: Traceback (most recent call last): File "FILEPATHHERE", line 1, in import cx_Oracle ImportError: DLL load failed: The specified module could not be found. Apparently the error is caused by cx_Oracle not being able to find the Oracle client DLLs (oci.dll and others). The client home path and the client home path bin directory are in the PATH System Variable and oci.dll is there. I tried getting the Oracle Instant Client (instantclient-basic- win32-11.1.0.7.0.zip from http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html) and installing it as directed. I added the instant client path to the PATH System Variable but that didn't work either. I have scoured the internet and have not found a solution. Please help! From greg.ewing at canterbury.ac.nz Thu Nov 19 03:03:23 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 19 Nov 2009 21:03:23 +1300 Subject: ANN: PyGUI 2.1.1 Message-ID: PyGUI 2.1.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This is an emergency bugfix release to repair some major breakage in the gtk version. Also corrects some other problems. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From simon.hibbs at gmail.com Thu Nov 19 03:08:02 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Thu, 19 Nov 2009 00:08:02 -0800 (PST) Subject: is there any FIX message handle modules in Python? References: <9d44333e-80c5-4561-9280-60fc8d464657@a39g2000pre.googlegroups.com> <591b3af9-3db7-4d3d-bf69-bdbd48bc51e4@h14g2000pri.googlegroups.com> Message-ID: <8edb47fa-fbbe-405e-8939-41ae64b3f0b6@k4g2000yqb.googlegroups.com> On 19 Nov, 05:25, alex23 wrote: > On Nov 19, 3:21?pm, "Stephen.Wu" <54wut... at gmail.com> wrote: > > > FIX message is the "Financial information Exchange" protocol > > messages... > > any 3rd libs we have? > > You mean like this one that was the first result when I googled > 'python "financial information exchange"'? > > http://www.quickfixengine.org/ There are no prebuilt Python modules available based on quickfix, at least that I'm aware of. It has Python bindings available, but you have to complie it with them yourself from the C++ source. Simon Hibbs From sturlamolden at yahoo.no Thu Nov 19 03:11:45 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Nov 2009 00:11:45 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <00759512$0$8173$c3e8da3@news.astraweb.com> Message-ID: On 18 Nov, 20:19, Dave Cook wrote: > If it's an issue for your project, I suggest wxPython. ?It's > cross-platform, fairly complete, and extensible. ?But the API is > clunky compared to Qt. Not if we use wxFormBuilder 3.1. From greg.ewing at canterbury.ac.nz Thu Nov 19 03:20:34 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Nov 2009 21:20:34 +1300 Subject: New syntax for blocks In-Reply-To: References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> Message-ID: <7mkdf2F3i7k16U1@mid.individual.net> Steven D'Aprano wrote: > I don't know what the state of the art on Mac is > these days, but in 1984s Macs had a standard keyboard layout that let you > enter most available characters via the keyboard, using sensible > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > the Option key and typing =. They all still seem to work -- presumably generating the appropriate unicode characters now instead of MacRoman. I don't think there's any left-arrow character available on the keyboard though, unfortunately. -- Greg From jebagnanadas at gmail.com Thu Nov 19 03:42:33 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Thu, 19 Nov 2009 14:12:33 +0530 Subject: Communication between python and wxWidgets.. Help needed... Message-ID: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> Hi Friends, I want to thank you all for doing a great job.. I seek your suggestions and valuable guidance regarding two things. 1) I'm using python 3.1.1 and wxWidgets for GUI development in my project .. I want to have a half-duplex communication between widgets and python(say passing something from wxWidgets to python and processing there and sending it back to display the results in widgets). When i googled around i found that we have to have SWIG or Boost::Python and some other third party applications to make this to work.. I'm wondering why it's really tough to establish a communication between the two though wxWidgets which is an excellent tool is mainly projected as a GUI toolkit especially for c++ and python and python is described as a powerful scripting language.. Can u suggest an efficient way by which i could make these two programs to interact(back and forth) easily?? 2) My second question is even if i did that successfully if i want to convert my project into an executable file how would i do that? (Bcoz. i will be having two executables or binaries in linux one for python and other for widgets) Do i need to convert it to lib or dll file with respect to python and c++ or is there any other way for making a build-script? What are the tools and libraries needed(like cx-freeze,pyWin32) to accomplish this?? Please give me some useful links... All of your suggestions are highly welcomed.. Thanks & Regards, Jebagnanadas A, Python-Developer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Thu Nov 19 03:43:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:43:50 +0100 Subject: python and web pages In-Reply-To: References: Message-ID: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> Daniel Dalton schrieb: > Hi, > > Here is my situation: > I'm using the command line, as in, I'm not starting gnome or kde (I'm on > linux.) > I have a string of text attached to a variable,. So I need to use one of > the browsers on linux, that run under the command line, eg. lynx, > elinks, links, links2 and do the following. > 1. Open a certain web page and find the first text box on the page, and > put this text into the form. > 2. Press the submit button, and wait for the result page to load. > 3. Click on the 15th link down the page. > > So, how do I do this, can anyone point me to some docs or modules that > may help out here? Use the module "mechanize". It will mimic a browser, and allows you to navigate to pages, fill in forms & submit them. And with lxml or BeatifulSoup, you can extract the link you need to press, and then make mechanize visit it. Diez From deets at nospam.web.de Thu Nov 19 03:45:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:45:36 +0100 Subject: convert a string to a regex? In-Reply-To: References: <366c6f340911181851o192cf5b9l8639ee31d1091570@mail.gmail.com> <4B04B79D.7090908@tim.thechases.com> Message-ID: <7mkethF3ijnhnU2@mid.uni-berlin.de> Peng Yu schrieb: > On Wed, Nov 18, 2009 at 9:12 PM, Tim Chase > wrote: >>> There are many special characters listed on >>> http://docs.python.org/library/re.html >>> >>> I'm wondering if there is a convenient function that can readily >>> convert a string with the special characters to its corresponding >>> regex. For example, >>> >>> "some.thing" => "some\.thing" >> Did you try bothering to *read* the page you linked to? >> >> There's a function for escaping strings right there... >> >> Literacy...a worthwhile skill to obtain. > > Sorry, I didn't see it. If there are examples besides explanations for > each command, it will help people see the usage of each command more > easily. Or it will clutter the whole page. That's not to say the docs can't be improved. But *reading* them will always be required. Diez From deets at nospam.web.de Thu Nov 19 03:48:03 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 19 Nov 2009 09:48:03 +0100 Subject: hex In-Reply-To: References: Message-ID: <7mkf24F3ijnhnU3@mid.uni-berlin.de> hong zhang schrieb: > List, > > I want to input hex number instead of int number. in type="int" in following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? You can't. You can get a string, and convert that with e.g. int("FF", 16) Or you can extend optparse to know a new type, should be possible. That would have the advantage that the parser already knows about it & can reject faulty input. Diez From jocjo at mail.dk Thu Nov 19 03:50:44 2009 From: jocjo at mail.dk (Hans Larsen) Date: Thu, 19 Nov 2009 09:50:44 +0100 Subject: real numbers with infinity precission Message-ID: <4b0506e3$0$36574$edfadb0f@dtext01.news.tele.dk> I have a READ.me file for real.py, but where could I get that module? I use Python 3.+ I hope that sombody can help me mailto: jocjo at mail.dk From nyamatongwe+thunder at gmail.com Thu Nov 19 03:57:05 2009 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Thu, 19 Nov 2009 08:57:05 GMT Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The specified module could not be found." In-Reply-To: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> References: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com> Message-ID: Andr?: > Apparently the error is caused by cx_Oracle not being able to find the > Oracle client DLLs (oci.dll and others). The client home path and the > client home path bin directory are in the PATH System Variable and > oci.dll is there. Open the cx_Oracle extension with Dependency Walker (http://www.dependencywalker.com/) to get a better idea about what the problem is in more detail. Neil From yuzhichang at gmail.com Thu Nov 19 04:11:22 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Thu, 19 Nov 2009 01:11:22 -0800 (PST) Subject: Where to find pexpect References: Message-ID: <1f57bf3e-d5b1-40da-8973-7b588a600b30@2g2000prl.googlegroups.com> On 10?13?, ??9?42?, Jean-Michel Pichavant wrote: > Antoon Pardon wrote: > > I have been looking forpexpect. The links I find like > >http://pexpect.sourceforge.netall end up at > >http://www.noah.org/wiki/Pexpectwhich produces a 404 not > > found problem. > > > Does someone know the current location? > > maybe they removed the distribution so you may use "subprocess" :o) > > JM http://pexpect.sourceforge.net seems outdated. I've forked, ported to Python 3.1, and added more features to pexpect. See http://github.com/yuzhichang/pexpect. From yuzhichang at gmail.com Thu Nov 19 04:14:21 2009 From: yuzhichang at gmail.com (yuzhichang) Date: Thu, 19 Nov 2009 01:14:21 -0800 (PST) Subject: Is pexpect unmaintained now? References: <252facf7-f9c6-4c6a-9d7f-ac69a830e6f0@h14g2000pri.googlegroups.com> Message-ID: On 11?17?, ??11?40?, yuzhichang wrote: > Pexpect2.4 is only available at Pypi. Both the homepage ofpexpect(http://www.noah.org/wiki/Pexpect) and download page > (http://sourceforge.net/projects/pexpect/files/) are outdated. The > repository on Github (http://github.com/noahspurrier/pexpect/) has > been removed. > > I ever contacted the author(n... at noah.org) but no response till now. > > I'm going to forkpexpecton Github and add some features... I've forked, ported it to Python 3.1, and added some features. See http://github.com/yuzhichang/pexpect. Regards, Zhichang Yu From eden at bicikl. Thu Nov 19 04:32:55 2009 From: eden at bicikl. (Eden Kirin) Date: Thu, 19 Nov 2009 10:32:55 +0100 Subject: SCGIServer and unusal termination In-Reply-To: <7mg4stF3idnj9U2@mid.uni-berlin.de> References: <7mfvjcF3hnir0U1@mid.uni-berlin.de> <7mg4stF3idnj9U2@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > - save a reference to sys.stdout *before* invoking the server > - compare to it after interruption. If it has changed, you at least know > that somebody messed with it, and can beat him or whatever you see fit. Thanks for the help. Finally, I dropped python-scgi module and I wrote my own SCGI server. There was not only the problem with stdout, but one much serious which made it unusable to me. Every SCGI request was forked as a new process, without the ability to access the shared globals within the project. -- www.vikendi.net -/- www.supergrupa.com From marco at sferacarta.com Thu Nov 19 04:44:52 2009 From: marco at sferacarta.com (Marco Mariani) Date: Thu, 19 Nov 2009 10:44:52 +0100 Subject: TODO and FIXME tags In-Reply-To: References: <20091116152724.icvkggis1wgcgwwg@correo.fenhi.uh.cu> <87lji5mqjv.fsf@benfinney.id.au> <_aqdnfsQraTL-57WnZ2dnUVZ_rBi4p2d@pdx.net> Message-ID: Jean-Michel Pichavant wrote: > I guess the world is split in two categories, those how come back to fix > the TODO, and those how don't. I for myself belong to the second, that > is why I never write TODO comments, I either do the stuff or consider > this is not important enough to waste time on it. In other words I > mostly agree with Martin, and envy people belonging to the first category. I am in a third category, I added this line to my python.vim syntax file syn keyword pythonTodo WTF LOL SNAFU contained and envy those who didn't :) From sturlamolden at yahoo.no Thu Nov 19 04:54:07 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 19 Nov 2009 01:54:07 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> <5634a$4b0330e1$4275d90a$22348@FUSE.NET> <31198269-2184-43f0-ae6b-bfda2d7800ba@j19g2000yqk.googlegroups.com> <4B047BBA.5040405@codebykevin.com> Message-ID: <55a576b4-857d-498f-b69f-ed2b7038a415@m16g2000yqc.googlegroups.com> On 18 Nov, 23:56, Kevin Walzer wrote: > wxWidgets (the C++ library) has support for a lot of things other than > UI bits, as well. wxPython itself is mainly a GUI library because the > additional features of wxWidgets in C++ are redundant in Python. That is true. Nobody uses wxPython for socket programming in Python. Qt is also much more than a C++ GUI framework, but in Python it's mainly (only?) used for GUI. From seeWebInstead at rem.intarweb.org Thu Nov 19 05:00:58 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Thu, 19 Nov 2009 02:00:58 -0800 Subject: Does turtle graphics have the wrong associations? References: Message-ID: > > Who is your target audience? > From: "Alf P. Steinbach" > Someone intelligent who doesn't know anything or very much about > programming and wants to learn general programming. I think of what a computer *does* as data processing, and then programing is simply telling the computer what data processing to do. In calculator mode, you just tell the computer one step at a time and immediately see the result before giving the next command. In program mode, you tell the computer the whole sequences of steps before the computer does even the first, which requires planning the whole sequence in your mind ahead of time. Lisp's REP allows you to use calculator mode when doing a dry run, then just wrap PROG around it and viola you have a program of all the steps together, thus bridging the gap between calculator and program mode painlessly. The two "hard" things about programming are syntax and planning. REP gets rid of the need to plan in your mind before writing the code, but you're still stuck with the syntax. My proposed no-syntax IDE *also* gets rid of the need to bother with any programming-language syntax. I've been proposing it for years, but nobody has shown any interest, so I'm spending my time on other things, but sometime in the next several months I am very likely to go ahead and implement no-syntax IDE as part of http://TinyURL.Com/NewEco. > I assume an intelligent reader, someone who doesn't balk at a few > technical terms here and there. There's a **major** difference between the ability to figure out complex puzzles and the ability to memorize jargon. Case in point: I placed top-five in Putnam math context despite disability whereby it was very difficult for me to memorize vocabulary/jargon. Then I flunked out of graduate school because suddenly I was expected to (but unable to) memorize ten definitions/lemmas to solve each homework problem. Ideally, with either somebody like me with memorization disability, or a very young child who just naturally by age has trouble learning more than one concept or term simultaneously, you should introduce only one concept or term at a time, and exerecise the person's mind with that concept or term for a while before moving to the next. > It's like the difference between driving a car and designing one. > You don't need an engineering degree to drive a car. :-) Sure some humans can be trained like pigeons to do the motions of driving a car through a fixed course without having the slightest concept of what's really happening. But to be able to respond appropriately to new situations, it really helps to understand that the brake pedal does *not* stop the car, it merely pulls a lever that presses a plate against a wheel causing excess friction causing the wheel to gradualy slow down, which is connected to the tires causing *them* to resist motion of car against road, which on non-slippery surfaces and with *gentle* braking results in the car slowing down, but with **sudden** pressure on brake, or on slick surfaces, the wheels stop turning completely and simply slide against the roadway, causing loss of control of both yaw and momentum, so suddenly your whole car is spinning about a vertical axis as well as no longer going around the road-curve but instead veering in a straight line across opposing traffic lanes or over the edge of the "S curve" of the Bay Bridge and then 200 feet down to a rather violent meeting with Yerba Buena Island. I hate that "CHECK ENGINE" light, because there's usually no way the driver of the vehicle actually *can* check the engine in any meaningful way to determine why the light is on. I think it really means "check" in the sense of a cloak-room, where you "check" your raincoat and umbrella by handing them to a clerk, thus you really do "check" your automobile by handing it over to a mechanic. By the way, I don't want Python running on my Macintosh, because it might eat my mouse. From __peter__ at web.de Thu Nov 19 05:01:24 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Nov 2009 11:01:24 +0100 Subject: hex References: Message-ID: hong zhang wrote: > I want to input hex number instead of int number. in type="int" in > following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", > default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? Workaround for the lazy: '0xff' on the command line instead of 'ff'. From looris at gmail.com Thu Nov 19 05:38:34 2009 From: looris at gmail.com (Lo'oris) Date: Thu, 19 Nov 2009 02:38:34 -0800 (PST) Subject: break LABEL vs. exceptions + PROPOSAL References: <1e36d271-e16b-4879-85c8-e94f85abb220@d10g2000yqh.googlegroups.com> <50697b2c0911180431y6c025e18n31f1f955d8d59c70@mail.gmail.com> Message-ID: On Nov 18, 7:13?pm, Terry Reedy wrote: > It amounts to duplicating raise x...exception x as break x....continue x > in the name of aesthetics and supposed efficiency. There would be no new > functionality nor any abbreviation of code. The semantics of there would be abbreviation: you wouldn't have to declare somewhere a dummy exception class. > anyplace'. The OP gives as a reason the possibility of a typo creating a > raise x ... except y mis-match. But a break x ... continue y mismatch is > equally likely. no: if you mismatch a label in this case, it should be treated as a syntax error, not as an unhandled exception which you might not notice. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 05:39:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 10:39:39 GMT Subject: real numbers with infinity precission References: <4b0506e3$0$36574$edfadb0f@dtext01.news.tele.dk> Message-ID: <03150e68$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 09:50:44 +0100, Hans Larsen wrote: > I have a READ.me file for real.py, but where could I get that module? I > use Python 3.+ > > I hope that sombody can help me Have you googled for "real.py"? -- Steven From tbourden at doc.ic.ac.uk Thu Nov 19 05:39:42 2009 From: tbourden at doc.ic.ac.uk (tbourden at doc.ic.ac.uk) Date: Thu, 19 Nov 2009 10:39:42 +0000 Subject: non-copy slices In-Reply-To: <200911181900.17759.rami.chowdhury@gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> Message-ID: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> No I'm well aware that there is no deep copy of the objects and the lists only keep references to the objects and in essence they have the same objects in there. But this doesn't mean they are the same list. Modifications to slices are not written back to the original list. x = range(5) y = x[1:3] y[0] = 13 x[1] == y[0] --> False Of course if I modify the object in the slice then the original list will see the change, but this is not what I was saying. Second and more importantly it's the performance penalty from allocating a large number of lists produced from the slices and the copy of the references. islice does not have this penalty, it should only instantiate a small object that iterates on the original list. Themis On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury wrote: > > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.hibbs at gmail.com Thu Nov 19 05:50:32 2009 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Thu, 19 Nov 2009 02:50:32 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> Message-ID: <40330c10-d52f-45f1-be40-b2a711cfa03b@d10g2000yqh.googlegroups.com> On 18 Nov, 22:11, Stef Mientki wrote: > Simon Hibbs wrote: > > On 18 Nov, 07:51, sturlamolden wrote: > > >> GPL > > > PyQT is GPL for now, but Qt itself is available under the LGPL as is > > PySide. Eventualy PySide, which tracks the PyQT API, will supplant it > > and the issue will be moot. For now it can be a problem, but PyQT > > developer licenses are very afordable at only a few hundred dollars. > > If a commercial project can't aford that, it's got problems. > > > Only you can know enough to make an informed decision. Wx does look > > more usable than last time I used it for a project and is a fine > > option too, for me though QT is the gold standard against all others > > are measured, and generaly found wanting. > > > Simon Hibbs > > Wouldn't it be nice > if each fan of some form of GUI-package, > would post it's code (and resulting images) for generating one or two > standard GUI-forms ? > > Then everyone can judge the differences, > and see what's simple and not ?so simple !! I don't think a list like this is a great way to do that. There are plenty of examples and tutorials available for each option. Simon Hibbs From ben+python at benfinney.id.au Thu Nov 19 06:38:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 22:38:18 +1100 Subject: Input characters not available on the keyboard (was: New syntax for blocks) References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> Message-ID: <87zl6iiw2d.fsf_-_@benfinney.id.au> Gregory Ewing writes: > Steven D'Aprano wrote: > > I don't know what the state of the art on Mac is these days, but in > > 1984s Macs had a standard keyboard layout that let you enter most > > available characters via the keyboard, using sensible mnemonics. > > E.g. on a US keyboard layout, you could get ? by holding down the > > Option key and typing =. [?] > I don't think there's any left-arrow character available on the > keyboard though, unfortunately. I'm glad to live in an age when free-software ?Input Methods? for many different character entry purposes are available in good operating systems. I switch between them using SCIM . At a pinch, when I'm without my GUI, I can turn some of them on with Emacs. Common input methods ? joy. I usually default to the ?rfc1345? input method which has many non-keyboard characters available via two-character mnemonics from the eponymous RFC document ? which appears to be about the only purpose that document has any more. -- \ ?The most dangerous man to any government is the man who is | `\ able to think things out for himself, without regard to the | _o__) prevailing superstitions and taboos.? ?Henry L. Mencken | Ben Finney From pavlovevidence at gmail.com Thu Nov 19 07:32:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Nov 2009 04:32:44 -0800 (PST) Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> Message-ID: <02026493-a48f-4fa7-8f74-c5b1e2897be1@l2g2000yqd.googlegroups.com> On Nov 19, 12:20?am, Gregory Ewing wrote: > Steven D'Aprano wrote: > > I don't know what the state of the art on Mac is > > these days, but in 1984s Macs had a standard keyboard layout that let you > > enter most available characters via the keyboard, using sensible > > mnemonics. E.g. on a US keyboard layout, you could get ? by holding down > > the Option key and typing =. > > They all still seem to work -- presumably generating the > appropriate unicode characters now instead of MacRoman. ?It?s about time.? Carl Banks From ben+python at benfinney.id.au Thu Nov 19 07:44:22 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 19 Nov 2009 23:44:22 +1100 Subject: New syntax for blocks References: <5036933a-b110-4e02-bb2f-64df205d798b@h10g2000vbm.googlegroups.com> <7ltvheF3ecu5rU2@mid.uni-berlin.de> <778934e8-d73f-4f88-afd6-7cc839d2cff3@x15g2000vbr.googlegroups.com> <4afc7d43$0$7712$426a74cc@news.free.fr> <00863e42$0$26916$c3e8da3@news.astraweb.com> <7mhevoF3ht32sU1@mid.individual.net> <7mkdf2F3i7k16U1@mid.individual.net> <02026493-a48f-4fa7-8f74-c5b1e2897be1@l2g2000yqd.googlegroups.com> Message-ID: <87ocmyit09.fsf@benfinney.id.au> Carl Banks writes: > On Nov 19, 12:20?am, Gregory Ewing > wrote: > > They all still seem to work -- presumably generating the appropriate > > unicode characters now instead of MacRoman. > > ?It?s about time.? I ? Unicode. (lrf, gung *vf* qryvorengr, sbe gur uhzbhe-vzcnverq nzbat lbh) -- \ ?Courteous and efficient self-service.? ?caf?, southern France | `\ | _o__) | Ben Finney From jeanmichel at sequans.com Thu Nov 19 07:58:01 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 19 Nov 2009 13:58:01 +0100 Subject: getting properly one subprocess output In-Reply-To: References: Message-ID: <4B0540D9.4060304@sequans.com> Nobody wrote: > On Wed, 18 Nov 2009 12:25:14 +0100, Jean-Michel Pichavant wrote: > > >> I'm currently inspecting my Linux process list, trying to parse it in >> order to get one particular process (and kill it). >> I ran into an annoying issue: >> The stdout display is somehow truncated (maybe a terminal length issue, >> I don't know), breaking my parsing. >> > > >> As you can see, to complete process command line is truncated. >> Any clue on how to get the full version ? >> > > If you only need it to work on Linux, you can just enumerate > /proc/[1-9]*/exe or /proc/[1-9]*/cmdline. > > Or you can add -ww to "ps" to avoid truncating the output. > > Note that the /proc/*/exe report the actual executable. The command line > reported by "ps" (from /proc/*/cmdline) can be modified by the program, so > it doesn't necessarily reflect the program being run. > > > That is what I was searching for. It's in ps man page, I don't know why I missed it in the first place. Thanks. JM From daniel at stutzbachenterprises.com Thu Nov 19 08:16:45 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 19 Nov 2009 07:16:45 -0600 Subject: non-copy slices In-Reply-To: <200911181900.17759.rami.chowdhury@gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> Message-ID: On Wed, Nov 18, 2009 at 9:00 PM, Rami Chowdhury wrote: > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > It still has to copy the reference, though. That takes O(n) time if you're taking a big slice. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas at geiregat.org Thu Nov 19 08:33:46 2009 From: jonas at geiregat.org (Jonas Geiregat) Date: Thu, 19 Nov 2009 14:33:46 +0100 Subject: Communication between python and wxWidgets.. Help needed... In-Reply-To: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> References: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> Message-ID: <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> Op 19-nov-09, om 09:42 heeft Jebagnana Das het volgende geschreven: > Hi Friends, > > I want to thank you all for doing a great job.. I > seek your suggestions and valuable guidance regarding two things. > > 1) I'm using python 3.1.1 and wxWidgets for GUI development in my > project .. I want to have a half-duplex communication between > widgets and python(say passing something from wxWidgets to python > and processing there and sending it back to display the results in > widgets). When i googled around i found that we have to have SWIG or > Boost::Python and some other third party applications to make this > to work.. I'm wondering why it's really tough to establish a > communication between the two though wxWidgets which is an excellent > tool is mainly projected as a GUI toolkit especially for c++ and > python and python is described as a powerful scripting language.. > Can u suggest an efficient way by which i could make these two > programs to interact(back and forth) easily?? > For your first question check out: wx.lib.pubsub: http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From wegwerp at gmail.com Thu Nov 19 09:21:09 2009 From: wegwerp at gmail.com (Bas) Date: Thu, 19 Nov 2009 06:21:09 -0800 (PST) Subject: getting properly one subprocess output References: Message-ID: On Nov 18, 12:25?pm, Jean-Michel Pichavant wrote: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length issue, > I don't know), breaking my parsing. Below is the script I use to automatically kill firefox if it is not behaving, maybe you are looking for something similar. HTH, Bas #!/usr/bin/env python import commands, os lines = os.popen('ps ax|grep firefox').readlines() lines = [line for line in lines if 'grep' not in line] print lines[0] pid = int(lines[0][:5]) print 'Found pid: %d' %pid os.system('kill -9 %d' %pid) From ethan at stoneleaf.us Thu Nov 19 09:44:19 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 Nov 2009 06:44:19 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> Message-ID: <4B0559C3.5020707@stoneleaf.us> Please don't top post. :) tbourden at doc.ic.ac.uk wrote: > On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury > > wrote: > > I'm not sure you're understanding the point others have been making. A > list item is merely another reference to an existing object -- it > doesn't copy the object in any way. > > No I'm well aware that there is no deep copy of the objects and the > lists only keep references to the objects and in essence they have the > same objects in there. But this doesn't mean they are the same list. > Modifications to slices are not written back to the original list. > > x = range(5) > y = x[1:3] > y[0] = 13 > x[1] == y[0] --> False > > Of course if I modify the object in the slice then the original list > will see the change, but this is not what I was saying. Second and more > importantly it's the performance penalty from allocating a large number > of lists produced from the slices and the copy of the references. islice > does not have this penalty, it should only instantiate a small object > that iterates on the original list. > > Themis So "shallow copy" == "new label created for existing object". So is your desired behavior to write back to the original list if your sub-list is modified? In other words, you are creating a window onto an existing list? If not, what would happen when a sublist element was modified (or deleted, or appended, or ...)? ~Ethan~ From victorsubervi at gmail.com Thu Nov 19 09:51:33 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 10:51:33 -0400 Subject: A Good Mailer In-Reply-To: <20091118223041.GA30691@stinemates.org> References: <4dc0cfea0911181127y5809fa14u7097ed43cf48bd7f@mail.gmail.com> <20091118223041.GA30691@stinemates.org> Message-ID: <4dc0cfea0911190651g186ba8b7ta9c390e6a483234c@mail.gmail.com> On Wed, Nov 18, 2009 at 6:30 PM, Nick Stinemates wrote: > On Wed, Nov 18, 2009 at 03:27:11PM -0400, Victor Subervi wrote: > > Hi; > > I need a good mailer that will enable me to mail email from web forms. > > smtplib > > > Suggestions? > > silly example.. > > #!/usr/bin/env python > import smtplib > > session = smtplib.SMTP("localhost") > username = "abc" > password = "def" > session.login(username, password) # only if it requires auth > > subject = "Hello, " > > header = "Subject: %s \r\nContent-type: text/html; > charset=utf-8\r\n\r\n" > > message = "world!" > > email_from = "victor at is.awesome" > email_to = ["email at myhost.com"] > > session.sendmail(email_from, email_to, header+messages) > > HTH, > Helps a lot! Thanks! V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rami.chowdhury at gmail.com Thu Nov 19 10:21:27 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 19 Nov 2009 07:21:27 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> Message-ID: On Thu, 19 Nov 2009 02:39:42 -0800, wrote: > Second and more > importantly it's the performance penalty from allocating a large number > of > lists produced from the slices and the copy of the references. Ah, I see what you were getting at -- thanks for clarifying. > > On Thu, Nov 19, 2009 at 3:00 AM, Rami Chowdhury > wrote: > >> >> I'm not sure you're understanding the point others have been making. A >> list item is merely another reference to an existing object -- it >> doesn't copy the object in any way. >> >> -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From victorsubervi at gmail.com Thu Nov 19 10:28:37 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 11:28:37 -0400 Subject: Python Will Not Send Email!! Message-ID: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Hi; I created this testMail.py file as root: #!/usr/bin/env python import smtplib session = smtplib.SMTP("localhost") subject = "Hello, " header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" message = "world!" email_from = "victor at is.awesome" email_to = ["email at myhost.com"] session.sendmail(email_from, email_to, header+messages) [root at 13gems globalsolutionsgroup.vi]# chmod 755 testMail.py [root at 13gems globalsolutionsgroup.vi]# python testMail.py Traceback (most recent call last): File "testMail.py", line 2, in ? import smtplib File "/usr/lib64/python2.4/smtplib.py", line 49, in ? from email.base64MIME import encode as encode_base64 ImportError: No module named base64MIME What gives?? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Thu Nov 19 10:29:34 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 19 Nov 2009 11:29:34 -0400 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: <4dc0cfea0911190729p46fe1db8pf387242f8c284cff@mail.gmail.com> On Thu, Nov 19, 2009 at 11:28 AM, Victor Subervi wrote: > Hi; > I created this testMail.py file as root: > > #!/usr/bin/env python > import smtplib > session = smtplib.SMTP("localhost") > subject = "Hello, " > header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" > message = "world!" > email_from = "victor at is.awesome" > email_to = ["email at myhost.com"] > session.sendmail(email_from, email_to, header+messages) > > [root at 13gems globalsolutionsgroup.vi]# chmod 755 testMail.py > [root at 13gems globalsolutionsgroup.vi]# python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > > What gives?? > TIA, > Victor > PS Python 2.4 on CentOS -------------- next part -------------- An HTML attachment was scrubbed... URL: From gdamjan at gmail.com Thu Nov 19 10:45:16 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Thu, 19 Nov 2009 16:45:16 +0100 Subject: SCGIServer and unusal termination References: Message-ID: > everything works just fine, but one thing bothers me. All prints after > try-except block are executed twice after the Ctrl+C is pressed! > > test.py: > #------------------------- > from scgi.scgi_server import SCGIServer > > n = 0 > print "Starting server." > > try: > SCGIServer().serve() > except (KeyboardInterrupt, SystemExit): > print "Exception!" > > # print lines are executed twice (?!) > n += 1 > print "Terminating server, attempt %d." % n > n += 1 > print "Check n: %d." % n > #------------------------- SCGIServer().serve() forks, so it seems that there are 2 python processes continuing to run after SCGIServer().serve() -- ?????? ((( http://damjan.softver.org.mk/ ))) Spammers scratch here with a diamond to find my address: ||||||||||||||||||||||||||||||||||||||||||||||| From keith.hughitt at gmail.com Thu Nov 19 10:48:16 2009 From: keith.hughitt at gmail.com (Keith Hughitt) Date: Thu, 19 Nov 2009 07:48:16 -0800 (PST) Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? References: <7mif6fF3hmd7eU1@mid.uni-berlin.de> Message-ID: <9c3a6286-b502-40ef-a94a-a471f327f887@j4g2000yqe.googlegroups.com> Hello, Thanks for the suggestions and information Diez! On Nov 18, 9:38?am, "Diez B. Roggisch" wrote: > > You are aware that the coding-declaration only affects unicode-literals (the > ones like u"i'm unicode")? So the above insert-statement is *not* unicode, > it's a byte-string in whatever encoding your editor happens to save the > file in. Thanks. I didn't know that, but that is helpful. > > And that's point two: make sure your editor reads and writes the file in the > same encoding you specified in the comment in the beginning. That is taken care of: the files are opened/saved as UTF-8. > > Makes sense if the execute tries to encode to unicode first - as you didn't > give it a unicode-object. > In Python 2.6 where I originally developed the code, it wasn't necessary to explicitly specify the type of some text: it was basically handled for you. It does make sense though. > > > > So far I've tried a number of different things, including: > > > ? ? 1. Using Unicode strings (e.g. u"\u212B") > > > ? ? 2. Manually specifying the encoding using sys.setdefaultencoding > > ('utf-8') > > > ? ? 3. Manually enabling Unicode support in MySQLdb > > (use_unicode=False, charset = "utf8") > > You *disabled* unicode here!!!!! Unicode is NOT utf-8!!! Oops. It was enabled when I ran it, I just copied the above text from somewhere else and forgot to change it. I am aware that Unicode does not equal utf-8, but utf-8 is a Unicode encoding, right? > > http://www.joelonsoftware.com/articles/Unicode.html Thanks! > > Try the above, and better yet provide self-contained examples that show the > behavior. > > Diez Still no luck. I also tried using double-quotes instead of single- quotes around the relevant strings (as suggested over email by ThreaderSlash), however, that did not work for me. Here is a small example of what I'm trying to do. Notice that if you run it in Python 2.5-2.6, everything works fine. It is only in Python 2.4 that the below example doesn't work. ============= Begin Example ================== #!/usr/bin/env python #-*- coding:utf-8 -*- import sys def main(): import MySQLdb, getpass admin = raw_input("Database admin: ") pw = getpass.getpass("Password: ") db = MySQLdb.connect(user=admin, passwd=pw) cursor = db.cursor() cursor.execute("CREATE DATABASE IF NOT EXISTS unicode_test;") cursor.execute(''' CREATE TABLE `unicode_test`.`test` ( `id` SMALLINT unsigned NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), INDEX (`id`) ) DEFAULT CHARSET=utf8;''') cursor.execute(''' INSERT INTO `unicode_test`.`test` VALUES (NULL, '?ngstr?m'); ''') # Test 1 print "Just printing: %s" % '?ngstr?m' # Test 2 cursor.execute("SELECT name FROM unicode_test.test;") print "From database: %s" % cursor.fetchone()[0].decode('utf-8') # Test 3 (Manual) print 'To verify manually: mysql -u %s -p -e "SELECT name FROM unicode_test.test"' % admin if __name__ == '__main__': sys.exit(main()) ============= End Example ==================== Any suggestions? Thanks! Keith From paul.nospam at rudin.co.uk Thu Nov 19 10:55:09 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 19 Nov 2009 15:55:09 +0000 Subject: getting properly one subprocess output References: Message-ID: <87ocmyecgy.fsf@rudin.co.uk> Jean-Michel Pichavant writes: > Hi python fellows, > > I'm currently inspecting my Linux process list, trying to parse it in > order to get one particular process (and kill it). > I ran into an annoying issue: > The stdout display is somehow truncated (maybe a terminal length > issue, I don't know), breaking my parsing. > > import subprocess > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > processList, stderrdata = process.communicate() > > Here is a sample of what I get in processList.split('\n'): > > ' "25487 1122 4344 ? 7-17:48:32 2.5 firefox-bin > /usr/lib/iceweasel/firefox-"', > ' "25492 1122 4892 pts/6 00:08 57.2 ipython > /usr/bin/python /usr/bin/ip"', > > > As you can see, to complete process command line is truncated. > Any clue on how to get the full version ? > You need to pass -ww to ps, otherwise it tries to guess the width of your terminal and adjust output line lengths accordingly. From gh at ghaering.de Thu Nov 19 11:19:14 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Thu, 19 Nov 2009 17:19:14 +0100 Subject: python and web pages In-Reply-To: <20091119071032.GA8462@debian-hp.lan> References: <20091119071032.GA8462@debian-hp.lan> Message-ID: Daniel Dalton wrote: > Hi, > > Here is my situation: > I'm using the command line, as in, I'm not starting gnome or kde (I'm on > linux.) > I have a string of text attached to a variable,. So I need to use one of > the browsers on linux, that run under the command line, eg. lynx, > elinks, links, links2 and do the following. No, you don't need any text mode browser. It's much easier to do with modules from the Python standard library. > 1. Open a certain web page and find the first text box on the page, and > put this text into the form. I assume you know HTML and HTTP. You can use urllib or urllib2 to submit the form. > 2. Press the submit button, and wait for the result page to load. > 3. Click on the 15th link down the page. You will then get the returned HTML from a function and you will have to parse it for the link you're interested in. There are many approaches to get there. Manual parsing, regular expressions or one of the XML parsers in the standard library (etree is the easiest). > So, how do I do this, can anyone point me to some docs or modules that > may help out here? While all of this may seem overwhelming at first, I guess the solution can be written in 20 - 30 lines of code. -- Gerhard From nagle at animats.com Thu Nov 19 11:22:09 2009 From: nagle at animats.com (John Nagle) Date: Thu, 19 Nov 2009 08:22:09 -0800 Subject: Does Python 3.x support Unicode-named attributes? Message-ID: <4b056e3b$0$1588$742ec2ed@news.sonic.net> Does Python 3.x support Unicode-named attributes? There are several modules which operate on HTML and try to hammer HTML/XML into Python object attributes. I've had BeautifulSoup and "urllib" blow up at various times when running on non-English HTML/XML. Got this error today: urllib.py:1197: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal res = map(safe_map.__getitem__, s) John Nagle From aahz at pythoncraft.com Thu Nov 19 11:22:22 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:22:22 -0800 Subject: Invitation to connect on LinkedIn References: <2002010896.1808409.1258596973029.JavaMail.app@ech3-cdn12.prod> Message-ID: In article , Chris Rebert wrote: > >How the heck someone sets their account email to a mailinglist, I'll >never figure out. This probably is not Jaime's fault. LinkedIn has an expletive b0rken implementation where they randomly pick addresses that have been used in your account when your primary address bounces. Still a bit odd that LinkedIn got that address in the first place, but I'm betting on them being at fault. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:25:20 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:25:20 -0800 Subject: A "terminators' club" for clp References: <7x3a4i56u7.fsf@ruckus.brouhaha.com> Message-ID: In article , Terry Reedy wrote: > >Some usenet newsgroups were/are moderated either by a robot, a person, >or a team (as you suggested). But a particular newsgroup has to be set >up that way from the beginning. Last I knew, it wan/is? difficult to >convert an unmoderated group to moderation. It has gotten exponentially more difficult over the last decade. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:27:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:27:07 -0800 Subject: Language mavens: Is there a programming with "if then else ENDIF" syntax? References: Message-ID: In article , Steve Ferg wrote: > >Does anybody know a language with this kind of syntax for >ifThenElseEndif? Several templating systems, including Cheetah. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:33:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:33:09 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: In article , Robert P. J. Day wrote: > >http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 > > thoughts? Haven't seen this elsewhere in the thread: http://dalkescientific.com/writings/diary/archive/2009/11/15/100000_tasklets.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 aahz at pythoncraft.com Thu Nov 19 11:35:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Nov 2009 08:35:28 -0800 Subject: Newsgroup for beginners References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: In article , Grant Edwards wrote: > >You've really got to try pretty hard to create one. But if you >want to, here's how to do it: > > 1) Start by complaining that your program doesn't work because > of a bug in Python. > > [...] Post of the month! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 jaraco at jaraco.com Thu Nov 19 11:37:35 2009 From: jaraco at jaraco.com (Jason R. Coombs) Date: Thu, 19 Nov 2009 08:37:35 -0800 (PST) Subject: Relative versus absolute paths on Windows Message-ID: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> The current implementation of Python (2.6.4, 3.1.1) treats \bar as a relative path but reports it as an absolute path. >>> ntpath.isabs('\\bar') True >>> ntpath.abspath('\\bar') 'C:\\bar' >>> os.chdir('d:\\') >>> ntpath.abspath('\\bar') 'd:\\bar' >>> os.chdir('\\\\server\\share') >>> ntpath.abspath('\\bar') '\\\\server\\share\\bar' In other words, paths without a drive letter are reported as absolute, but treated as relative, except in a few special cases. >>> ntpath.join('d:\\foo', '\\bar') '\\bar' In this case, \bar is treated as absolute, and not relative to d:\foo. This inconsistency means that to effectively resolve one path relative to another, one has to resort to explicit drive letter manipulation. See http://stackoverflow.com/questions/1654659/find-a-path-in-windows-relative-to-another for a case in point. My understanding is that in Windows, a path is only absolute if it contains a drive letter or it begins with a double-backslash. Curiously, the .Net Framework seems to be subject to the same limitation # using IronPython 2.6RC2 >>> System.IO.Path.IsPathRooted('\\bar') True >>> System.IO.Path.Combine('d:\\foo', '\\bar') # expect d:\bar '\\bar' The documentation for Combine raises this issue in the Community Content (http://msdn.microsoft.com/en-us/library/fyy7a5kt.aspx). Furthermore, the Windows API utility is also consistent with this odd behavior (http://msdn.microsoft.com/en-us/library/bb773660%28VS. 85%29.aspx). The discussion here (http://groups.google.com/group/comp.os.ms- windows.programmer.win32/browse_thread/thread/b2ff7a9d1d7c9b5e) describes absolute paths consistent with my understanding: Absolute paths have these characteristics. Length is at least 2 characters, AND ( Second character is ":", OR First two characters is "\\" ) And according to WikiPedia (http://en.wikipedia.org/wiki/Path_ %28computing%29), "[an] absolute path is a path that points to the same location on one file system regardless of the working directory." By this definition, \bar is a relative path on Windows. Ultimately, I don't care what the definition is. It seems to me, however, that Python should have a function that can resolve one path name relative to another, but due to these limitations, it does not. I should point out that os.path.relpath is not the solution either as the first parameter is always treated as relative to the current directory (more info at http://bugs.python.org/issue7195). I've built workarounds in https://svn.jaraco.com/jaraco/python/jaraco.windows/jaraco/windows/filesystem.py as join() and resolve_path(). I'm happy to continue using these workarounds, but I wanted to bring this issue to the attention of the community for any comments or suggestions or answers to the following questions. What is the benefit of treating \path as absolute? Should Python have built-in support for resolving one path relative to another (such as is jaraco.windows.filesystem.resolve_path does)? Given the long established behavior of Python and other platforms for handling absolute paths in Windows, is there a way forward that handles these cases more elegantly, or is the best approach to just mumble something nasty under our breath and work around these issues on a case-by-case basis? From nobody at nowhere.com Thu Nov 19 11:40:10 2009 From: nobody at nowhere.com (Nobody) Date: Thu, 19 Nov 2009 16:40:10 +0000 Subject: getting properly one subprocess output References: Message-ID: On Thu, 19 Nov 2009 06:21:09 -0800, Bas wrote: > Below is the script I use to automatically kill firefox if it is not > behaving, maybe you are looking for something similar. > lines = os.popen('ps ax|grep firefox').readlines() This isn't robust. It will kill any process with "firefox" anywhere in its command line, which isn't limited to processes which are actually running the firefox web browser. > lines = [line for line in lines if 'grep' not in line] This line excludes one such process, but there may be others. A more robust approach would be to check for the string in the command name (i.e. argv[0]) rather than the complete command-line, by using e.g. "ps ... -o pid,comm": lines = os.popen('ps axheo pid,comm').readlines() lines = [line.strip().split(' ', 1) for line in lines] lines = [(int(pid), cmd) for pid, cmd in lines if 'firefox' in cmd] Better still would be to check that "firefox" is a complete word, not part of one, e.g. with the regular expression r"\bfirefox\b". This would match "firefox", "/usr/bin/firefox", "firefox-bin", etc, but not e.g. "kill_firefox", e.g.: lines = [(int(pid), cmd) for pid, cmd in lines if re.search(r'\bfirefox\b', cmd)] That's about as good as you can get without using non-portable mechanisms such as /proc/*/exe. From eden at bicikl. Thu Nov 19 12:03:21 2009 From: eden at bicikl. (Eden Kirin) Date: Thu, 19 Nov 2009 18:03:21 +0100 Subject: SCGIServer and unusal termination In-Reply-To: References: Message-ID: ?????? ??????????? wrote: > SCGIServer().serve() forks, so it seems that there are 2 python > processes continuing to run after SCGIServer().serve() I noticed that which makes it unusable to me. Also, it took me almost whole day to realize this. I'm adopting a huge application to work with SCGI which shares a certain amount of data between working threads and SCGI handler. I couldn't realize the cause of erratic and unconsistent data behaviour. After diving into python-scgi code, I gave it up and wrote my own SCGI server. -- www.vikendi.net -/- www.supergrupa.com From carsten.haese at gmail.com Thu Nov 19 12:32:28 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Thu, 19 Nov 2009 12:32:28 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > I created this testMail.py file as root: > > #!/usr/bin/env python > import smtplib > session = smtplib.SMTP("localhost") > subject = "Hello, " > header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" > message = "world!" > email_from = "victor at is.awesome" > email_to = ["email at myhost.com "] > session.sendmail(email_from, email_to, header+messages) > > [root at 13gems globalsolutionsgroup.vi ]# > chmod 755 testMail.py > [root at 13gems globalsolutionsgroup.vi ]# > python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > > What gives?? Do you have a file called "email.py" in your current directory or anywhere else on Python's path outside of the standard library? If so, it's hiding the real email module from your script and you'll need to get rid of "your" email.py by renaming or moving it. -- Carsten Haese http://informixdb.sourceforge.net From t.bourdenas07 at imperial.ac.uk Thu Nov 19 12:55:26 2009 From: t.bourdenas07 at imperial.ac.uk (Themis Bourdenas) Date: Thu, 19 Nov 2009 17:55:26 +0000 Subject: non-copy slices In-Reply-To: <4B0559C3.5020707@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> Message-ID: <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> On Thu, Nov 19, 2009 at 2:44 PM, Ethan Furman wrote: > Please don't top post. :) > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? In other words, you are creating a window onto an > existing list? If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > Yes a window / view on the existing list describes it best. So every modification you make in this view is actually modifying the original list accordingly. Blist that was suggested in a previous email in the thread seems lightweight but it does create a new list when a modification is made. In any case, I've already implemented the object myself and I can post it if you care to have a look, but I was just wondering if there was already something in the standard library. Themis -------------- next part -------------- An HTML attachment was scrubbed... URL: From hippostech at gmail.com Thu Nov 19 13:53:00 2009 From: hippostech at gmail.com (papa hippo) Date: Thu, 19 Nov 2009 10:53:00 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released Message-ID: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> The prime goal of 'phileas' is to enable html code to be seamlessly included in python code in a natural looking syntax, without resorting to templatng language. see: http://larry.myerscough.nl/phileas_project/ I intend to submit phileas to the python.announce forum within the next few days. Any feedback received now will be gratefully received and may lead to improved quality of that submission. Larry Myerscough Eindhoven NL hippos at chello.nl From showell30 at yahoo.com Thu Nov 19 14:18:32 2009 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 19 Nov 2009 11:18:32 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> On Nov 19, 10:53?am, papa hippo wrote: > The prime goal of 'phileas' is to enable html code to be seamlessly > included in python code in a natural looking syntax, without resorting > to templatng language. > > see: > > http://larry.myerscough.nl/phileas_project/ > > I intend to submit phileas to the python.announce ?forum within the > next few days. Any feedback received now will be gratefully received > and may lead to improved quality of that submission. > Hi Larry, looks like interesting stuff! There appears to be a problem with this page: http://larry.myerscough.nl/show_python_source.py?script_filename=./MyPage.py IOError: [Errno 2] No such file or directory: './MyPage.py' I do like the idea of having a more Python-oriented way to generate HTML. From martin at v.loewis.de Thu Nov 19 15:21:48 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 19 Nov 2009 21:21:48 +0100 Subject: Does Python 3.x support Unicode-named attributes? In-Reply-To: <4b056e3b$0$1588$742ec2ed@news.sonic.net> References: <4b056e3b$0$1588$742ec2ed@news.sonic.net> Message-ID: <4b05a8dd$0$20089$9b622d9e@news.freenet.de> > Does Python 3.x support Unicode-named attributes? Most certainly, yes. All identifiers (and thus all attribute names) are Unicode strings in Python 3.x. > There are several modules which operate on HTML and try to > hammer HTML/XML into Python object attributes. I've had > BeautifulSoup and "urllib" blow up at various times when > running on non-English HTML/XML. > > Got this error today: > > urllib.py:1197: UnicodeWarning: Unicode equal comparison failed to > convert both arguments to Unicode - interpreting > them as being unequal > res = map(safe_map.__getitem__, s) Perhaps the library you were using modified __dict__ directly, thus getting non-string attribute names into the dict? Or perhaps s is not a Unicode string? Regards, Martin From alfps at start.no Thu Nov 19 15:37:17 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 19 Nov 2009 21:37:17 +0100 Subject: Is an interactive command a block? Message-ID: The CPython 3.1.1 language reference ?4.1 says "Each command typed interactively is a block." It also says "If a name is bound in a block, it is a local variable of that block, unless declared as nonlocal" Even with a non-literal try-for-best-meaning reading I can't get this to mesh with the actual behavior of the interpreter, e.g. >>> for x in "poi": ... fandango = 666 ... >>> fandango 666 >>> _ My current understanding is (A) that the interpreter is correct in this respect (for one would harldly want the effects of statements to be fundamentally different in interpreted mode, except the presentation of expression results), and (B), but here I'm less sure, that the documentation is incorrect. So what I'm asking about is mainly (B), because if the documentation is correct after all, then there's something I haven't grokked. :-) Cheers, - Alf From highcar at gmail.com Thu Nov 19 15:50:09 2009 From: highcar at gmail.com (elca) Date: Thu, 19 Nov 2009 12:50:09 -0800 (PST) Subject: mechanize login problem with website In-Reply-To: <26420202.post@talk.nabble.com> References: <26420202.post@talk.nabble.com> Message-ID: <26421474.post@talk.nabble.com> elca wrote: > > Hello > > I'm making auto-login script by use mechanize python. > > Before I was used mechanize with no problem, but http://www.gmarket.co.kr > in this site I couldn't make it . > > whenever i try to login always login page was returned even with correct > gmarket id , pass, i can't login and I saw some suspicious message > > "" > > I think this related with my problem, but don't know exactly how to handle > . > > i was upload my script in here > > # -*- coding: cp949 -*- > from lxml.html import parse, fromstring > import sys,os > import mechanize, urllib > import cookielib > import re > from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag > > try: > > params = urllib.urlencode({'command':'login', > 'url':'http%3A%2F%2Fwww.gmarket.co.kr%2F', > 'member_type':'mem', > 'member_yn':'Y', > 'login_id':'tgi177', > 'image1.x':'31', > 'image1.y':'26', > 'passwd':'tk1047', > 'buyer_nm':'', > 'buyer_tel_no1':'', > 'buyer_tel_no2':'', > 'buyer_tel_no3':'' > > }) > rq = mechanize.Request("http://www.gmarket.co.kr/challenge/login.asp") > rs = mechanize.urlopen(rq) > data = rs.read() > > > logged_in = r'input_login_check_value' in data > if logged_in: > print ' login success !' > rq = mechanize.Request("http://www.gmarket.co.kr") > rs = mechanize.urlopen(rq) > data = rs.read() > print data > > else: > print 'login failed!' > pass > quit() > except: > pass > > > if anyone can help me much appreciate thanks in advance > > i was updated my script source -- View this message in context: http://old.nabble.com/mechanize-login-problem-with-website-tp26420202p26421474.html Sent from the Python - python-list mailing list archive at Nabble.com. From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:08:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:08:15 GMT Subject: Is an interactive command a block? References: Message-ID: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: > The CPython 3.1.1 language reference ?4.1 says > > "Each command typed interactively is a block." > > It also says > > "If a name is bound in a block, it is a local variable of that block, > unless > declared as nonlocal" > > Even with a non-literal try-for-best-meaning reading I can't get this to > mesh with the actual behavior of the interpreter, e.g. > > >>> for x in "poi": > ... fandango = 666 > ... > >>> fandango > 666 > >>> _ > > My current understanding is (A) that the interpreter is correct in this > respect (for one would harldly want the effects of statements to be > fundamentally different in interpreted mode, except the presentation of > expression results), and (B), but here I'm less sure, that the > documentation is incorrect. Why do you say that? I don't see what it is in the command you typed that leads you to think the documentation is incorrect. The first command you type is: for x in "poi": fandango = 666 which binds two names, x and fandango. Since you are not typing them in a function or class definition, locals() is globals() and the two local names you create happen to also be globals. The next two commands you type: fandango _ don't bind anything, so aren't relevant. If it helps: >>> for x in "poi": ... fandango = 666 ... >>> locals() is globals() True >>> fandango 666 >>> locals()['fandango'] 666 >>> import __main__ >>> __main__.fandango 666 -- Steven From davea at ieee.org Thu Nov 19 16:14:18 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 19 Nov 2009 16:14:18 -0500 Subject: Communication between python and wxWidgets.. Help needed... In-Reply-To: <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> References: <5ff1e7d40911190042n3d65042ai4091f341f3fe9b14@mail.gmail.com> <8B0E4F40-B9F5-4946-ACF3-96E003775023@geiregat.org> Message-ID: <4B05B52A.6010308@ieee.org> Jonas Geiregat wrote: > > Op 19-nov-09, om 09:42 heeft Jebagnana Das het volgende geschreven: > >> Hi Friends, >> >> I want to thank you all for doing a great job.. I >> seek your suggestions and valuable guidance regarding two things. >> >> 1) I'm using python 3.1.1 and wxWidgets for GUI development in my >> project .. I want to have a half-duplex communication between widgets >> and python(say passing something from wxWidgets to python and >> processing there and sending it back to display the results in >> widgets). When i googled around i found that we have to have SWIG or >> Boost::Python and some other third party applications to make this to >> work.. I'm wondering why it's really tough to establish a >> communication between the two though wxWidgets which is an excellent >> tool is mainly projected as a GUI toolkit especially for c++ and >> python and python is described as a powerful scripting language.. Can >> u suggest an efficient way by which i could make these two programs >> to interact(back and forth) easily?? >> > > > For your first question check out: wx.lib.pubsub: > http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html > > I looked at your query a couple of times, and I don't see wxPython listed there anywhere. You don't need SWIG or Boost or anything else -- that's what wxPython is. Instead of just getting wxWidgets, get wxPython, which includes wxWidgets as a black box underneath. binaries here: http://wxpython.org/download.php#binaries dos here: http://www.wxpython.org/docs/api/wx-module.html Of course, the catch is that this whole project supports Python 2.4 through 2.6. If you want to get it to work on 3.1, you have to either wait, or do it yourself. DaveA From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:22:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:22:15 GMT Subject: What is the naming convention for accessor of a 'private' variable? References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> Message-ID: <0315a502$0$1327$c3e8da3@news.astraweb.com> On Wed, 18 Nov 2009 18:47:34 -0800, Chris Rebert wrote: > On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >> http://www.python.org/dev/peps/pep-0008/ >> >> The above webpage states the following naming convention. Such a >> variable can be an internal variable in a class. I'm wondering what is >> the naming convention for the method that access such variable. >> >> ? ?- _single_leading_underscore: weak "internal use" indicator. ?E.g. >> ? ?"from M >> ? ? ?import *" does not import objects whose name starts with an >> ? ? ?underscore. > > If there's a method to access the variable, then it's not all that > private, is it? True, but it might be read-only, or the accessor might do validation to ensure that the caller doesn't stuff a string in something expected to be a float, or some sort of computed attribute. That's why we have properties. > Accessor methods are not Pythonic. Accessor methods are *usually* not Pythonic, at least not the way they are commonly used in Java. In fact, Python has at least two built-in accessor functions: globals() locals() There may be others. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 16:28:42 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Nov 2009 21:28:42 GMT Subject: Does turtle graphics have the wrong associations? References: Message-ID: <0315a685$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 02:00:58 -0800, Robert Maas, http://tinyurl.com/uh3t wrote: > My proposed no-syntax > IDE *also* gets rid of the need to bother with any programming-language > syntax. I've been proposing it for years, but nobody has shown any > interest I'm interested. No-syntax IDE? How is this even possible? The only way I can think of is some sort of wizard interface. E.g. instead of having to remember the syntax for a slice, you click the "Slice" button and the computer prompts you to enter some combination of start, end, step, then generates the syntax [a:b:c] for you. -- Steven From emile at fenx.com Thu Nov 19 16:38:00 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 19 Nov 2009 13:38:00 -0800 Subject: make two tables having same orders in both column and row names In-Reply-To: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> References: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Message-ID: On 11/18/2009 12:57 PM Ping-Hsun Hsieh said... > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 AA109 AA101 AA103 AA102 > BB1 2 9 2.3 1 28 > BB3 12 9 2.3 1 28 > BB9 0.5 2 2.3 1 28 > BB2 2 9 21 1 20 > > Table_B in the other file looks like the follows: > AA101 AA109 AA100 AA103 AA102 > BB1 2 9 2.3 2 28 > BB2 2 9 2.3 1 28 > BB9 2 9 2.3 1 28 > BB3 2 2 2 1 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun > This is one way... (python 2.4.1) #For example, table_A in a file looks like the follows: table_A = [ line.split() for line in """AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20""".split('\n') ] #Table_B in the other file looks like the follows: table_B = [ line.split() for line in """AA101 AA109 AA100 AA103 AA102 BB1 2 9 2.3 2 28 BB2 2 9 2.3 1 28 BB9 2 9 2.3 1 28 BB3 2 2 2 1 28""".split('\n') ] for table in table_A,table_B: table[:] = [['']+table[0]]+sorted(table[1:]) table = zip(*sorted(zip(*table))) for ii in table: print ii Emile From alfps at start.no Thu Nov 19 16:42:31 2009 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 19 Nov 2009 22:42:31 +0100 Subject: Is an interactive command a block? In-Reply-To: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: > >> The CPython 3.1.1 language reference ?4.1 says >> >> "Each command typed interactively is a block." >> >> It also says >> >> "If a name is bound in a block, it is a local variable of that block, >> unless >> declared as nonlocal" >> >> Even with a non-literal try-for-best-meaning reading I can't get this to >> mesh with the actual behavior of the interpreter, e.g. >> >> >>> for x in "poi": >> ... fandango = 666 >> ... >> >>> fandango >> 666 >> >>> _ >> >> My current understanding is (A) that the interpreter is correct in this >> respect (for one would harldly want the effects of statements to be >> fundamentally different in interpreted mode, except the presentation of >> expression results), and (B), but here I'm less sure, that the >> documentation is incorrect. > > > Why do you say that? I don't see what it is in the command you typed that > leads you to think the documentation is incorrect. > > The first command you type is: > > for x in "poi": > fandango = 666 > > > which binds two names, x and fandango. Since you are not typing them in a > function or class definition, locals() is globals() and the two local > names you create happen to also be globals. Thanks, that may be it. In most other languages I'm familiar with, if a name is local then it isn't global (and vice versa), and I had that as an underlying assumption since it doesn't appear to be mentioned in the documentation. However, I find a language reference statement that alludes to this: "(The variables of the module code block are local and global.)" Hm... > The next two commands you type: > > fandango > _ > > don't bind anything, so aren't relevant. Well it showed that 'fandango' had been defined as a global. :-) > If it helps: > > >>>> for x in "poi": > ... fandango = 666 > ... >>>> locals() is globals() > True >>>> fandango > 666 >>>> locals()['fandango'] > 666 >>>> import __main__ >>>> __main__.fandango > 666 Yeah, helps. I feel that there's still something lacking in my understanding though, like how/where the "really actually just pure local not also global" is defined for function definition, but it's now just a vague feeling of something missing, not a feeling of direct contradiction as I had when I believed local != global. Cheers, & thanks, - Alf From threaderslash at gmail.com Thu Nov 19 17:00:36 2009 From: threaderslash at gmail.com (Threader Slash) Date: Fri, 20 Nov 2009 09:00:36 +1100 Subject: Python-list Digest, Vol 74, Issue 245 In-Reply-To: References: Message-ID: On Thu, Nov 19, 2009 at 7:05 PM, wrote: > > ---------- ---------- > From: Threader Slash > To: python-list at python.org > Date: Thu, 19 Nov 2009 14:51:27 +1100 > Subject: Qt Python radiobutton: activate event > Hi Guys, > > I am trying to get the choice made by the user on Python Qt with > radiobutton. > > QtCore.QObject.connect(self.radioButton1, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > QtCore.QObject.connect(self.radioButton2, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > > and that > > QtCore.QObject.connect(self.performGroupBox, > QtCore.SIGNAL("toggled()"),self.radio_activateInput) > > But it didn't make anything when I click on the option. > > Yes, I have enabled it: > > self.radioButton1.setCheckable(True) > self.radioButton1.setChecked(True) > self.radioButton2.setCheckable(True) > > Any suggestion? > > > ---------- Forwarded message ---------- > Here is solution... now working: QtCore.QObject.connect(self.radioButton1,QtCore.SIGNAL("toggled(bool)"),self.radio_activateInput) when have the parameter bool included into toggled to signal, it worked. ThreadeSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Thu Nov 19 17:00:45 2009 From: joncle at googlemail.com (Jon Clements) Date: Thu, 19 Nov 2009 14:00:45 -0800 (PST) Subject: make two tables having same orders in both column and row names References: Message-ID: On Nov 18, 8:57?pm, Ping-Hsun Hsieh wrote: > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 ? AA109 ? AA101 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 12 ? ? ?9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 0.5 ? ? 2 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 21 ? ? ?1 ? ? ? 20 > > Table_B in the other file looks like the follows: > AA101 ? AA109 ? AA100 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 2 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 2 ? ? ? 2 ? ? ? 2 ? ? ? 1 ? ? ? 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun Use a dictionary with a tuple of the row 'name' and column 'name' as the key. The following was put together in a hurry, so take with a pinch of salt (and brandy or something :))... t1data = """AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20""" def create_table(what): from itertools import imap, islice, izip, cycle, repeat table = filter(None, imap(str.split, what.split('\n'))) table_dict = {} for cols in islice(table, 1, None): for row_name, col_name, col in izip(cycle(table[0]), repeat (cols[0]), islice(cols, 1, None)): table_dict[(row_name, col_name)] = col return table_dict print create_table(t1data) hth Jon. From kevin.p.dwyer at gmail.com Thu Nov 19 17:01:15 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Thu, 19 Nov 2009 22:01:15 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: Hello Victor, There are some pages on the internet that suggest that this problem my be caused by a module named email.py (or email.pyc) in your pythonpath. If you try import smtplib in the interpreter do you get this error message? If so, start a new interpreter session and try import email - is the email module imported from the stdlib? If these steps don't help, it might be useful if you can tell us which Linux distribution you are using. Cheers, Kev From sajmikins at gmail.com Thu Nov 19 17:48:11 2009 From: sajmikins at gmail.com (Simon Forman) Date: Thu, 19 Nov 2009 17:48:11 -0500 Subject: make two tables having same orders in both column and row names In-Reply-To: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> References: <3836C699CC6CD04B937FE27A388BE41502EC5F73ED@EX-MB07.ohsu.edu> Message-ID: <50f98a4c0911191448i44a3b6d7w8c78f8068b72f903@mail.gmail.com> On Wed, Nov 18, 2009 at 3:57 PM, Ping-Hsun Hsieh wrote: > Hi, > > I would like to compare values in two table with same column and row names, but with different orders in column and row names. > For example, table_A in a file looks like the follows: > AA100 ? AA109 ? AA101 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 12 ? ? ?9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 0.5 ? ? 2 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 21 ? ? ?1 ? ? ? 20 > > Table_B in the other file looks like the follows: > AA101 ? AA109 ? AA100 ? AA103 ? AA102 > BB1 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 2 ? ? ? 28 > BB2 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB9 ? ? 2 ? ? ? 9 ? ? ? 2.3 ? ? 1 ? ? ? 28 > BB3 ? ? 2 ? ? ? 2 ? ? ? 2 ? ? ? 1 ? ? ? 28 > > Can anyone give an efficient way to make the two tables having same orders in column and row names so I can easily and correctly compare the values in positions? > > Thanks, > PingHsun Depending on the kind of comparisons you want to do and the sizes of your input files you could build a dict of dicts. For example: def generate_dict_values(F): column_names = f.readline().split() for line in F: row = line.split() yield row[0], dict(zip(column_names, row[1:])) # Fake a file. from StringIO import StringIO f = StringIO('''\ AA100 AA109 AA101 AA103 AA102 BB1 2 9 2.3 1 28 BB3 12 9 2.3 1 28 BB9 0.5 2 2.3 1 28 BB2 2 9 21 1 20 ''') d = dict(generate_dict_values(f)) # Now you can access the values without regards to the order in the file like so: d['BB9']['AA109'] # "Pretty print" the dict of dicts. from pprint import pprint pprint(d) # Prints: # # {'BB1': {'AA100': '2', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '9'}, # 'BB2': {'AA100': '2', # 'AA101': '21', # 'AA102': '20', # 'AA103': '1', # 'AA109': '9'}, # 'BB3': {'AA100': '12', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '9'}, # 'BB9': {'AA100': '0.5', # 'AA101': '2.3', # 'AA102': '28', # 'AA103': '1', # 'AA109': '2'}} From reply-to at works.fine.invalid Thu Nov 19 18:15:05 2009 From: reply-to at works.fine.invalid (NickC) Date: 19 Nov 2009 23:15:05 GMT Subject: Vim breaks after Python upgrade References: <008c54b4$0$26908$c3e8da3@news.astraweb.com> Message-ID: <008f55d8$0$26926$c3e8da3@news.astraweb.com> On Tue, 17 Nov 2009 13:46:25 -0500, Nick Stinemates wrote: > At least with Gentoo, there's a command to recompile all of the plugins > you have installed when upgrading python versions. > > Your issue is probably related to that. I don't think VIM uses hardcoded > locations for scripts at the core. > > If you have any specific questions about the errors you're receiving, > feel free to submit to the VIM mailing list or stop by the IRC channel: > #vim on irc.freenode.org > Ok, thanks. I'm sorry for calling vim clunky; the choice of words probably reflected my disbelief at the time. FWIW, sed'ing 's:2\.5:2\.6:g' doesn't work. It does change some strings, but not (apparently) the numbers that matter. -- NickC From jabronson at gmail.com Thu Nov 19 18:24:46 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 15:24:46 -0800 (PST) Subject: python bijection Message-ID: I couldn't find a library providing a bijective map data structure (allowing for constant-time lookups by value) in the few minutes I looked, so I took a few more minutes to code one up: http://bitbucket.org/jab/toys/src/tip/bijection.py Is this at all worth releasing? Comments and suggestions welcome. Josh From rhodri at wildebst.demon.co.uk Thu Nov 19 18:45:56 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 19 Nov 2009 23:45:56 -0000 Subject: hex In-Reply-To: <441732.63062.qm@web57901.mail.re3.yahoo.com> References: <441732.63062.qm@web57901.mail.re3.yahoo.com> Message-ID: On Thu, 19 Nov 2009 02:29:59 -0000, hong zhang wrote: > List, > > I want to input hex number instead of int number. in type="int" in > following, > > parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", > default=0, help="index of 11n mcs table. Default: 0.") > > How can I do it? Assuming you're talking about "optparse", just prefix the number with "0x" on the command line: python myscript.py -F 0xDEAD If you don't want to have to type the leading "0x", you'll either have to make yourself a custom type for optparse, or treat it as a string and do the parsing and error handling afterwards. My recommendation is that you don't do this: not prefixing your constants if they aren't decimal is an accident waiting to happen. -- Rhodri James *-* Wildebeest Herder to the Masses From david at boddie.org.uk Thu Nov 19 18:55:51 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 20 Nov 2009 00:55:51 +0100 Subject: PyQt4 4.4.4 : a bug with highlightBlock ? References: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Message-ID: On Wednesday 18 November 2009 11:47, Snouffy wrote: > I've been trying to do some syntax highlighting using PyQt4. I ported > the example given in the documentation of Qt4 to Python. It works fine > on my computer at work (which has PyQt4 version 4.3.3) but doesn't on > my home computer (which has version 4.4.4) : it gets stuck in an > infinite loop. This is a known issue. There are examples distributed with PyQt that should have been updated to use a slightly different approach. > Here is the code : > > class MyHighlighter(QtGui.QSyntaxHighlighter): > def __init__(self, edit): > QtGui.QSyntaxHighlighter.__init__(self,edit) > > def highlightBlock(self, text): > myClassFormat = QtGui.QTextCharFormat() > myClassFormat.setFontWeight(QtGui.QFont.Bold) > myClassFormat.setForeground(QtCore.Qt.darkMagenta) > pattern = "\\b[A-Z_]+\\b" > > expression = QtCore.QRegExp(pattern) > index = text.indexOf(expression); > while (index >= 0): > length = expression.matchedLength() > self.setFormat(index, length, myClassFormat) > index = text.indexOf(expression, index + length) You need to change the indexOf() calls to indexIn() calls on the QRegExp object: index = expression.indexIn(text, index + length) > What am I missing ? Is this a known bug of version 4.4.4 ? I think there was a behavioural change at some point that affected regular expression searching in QStrings. David From steve at REMOVE-THIS-cybersource.com.au Thu Nov 19 19:05:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 00:05:45 GMT Subject: python bijection References: Message-ID: <0315cb54$0$1327$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 15:24:46 -0800, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up: > http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? You just did :) > Comments and suggestions welcome. If I want a mapping a <-> b, I generally just create a dict {a:b, b:a}. What is the advantages or disadvantages of your code over the simplicity of the dict approach? (That is, sell us on the features of your approach.) -- Steven From ethan at stoneleaf.us Thu Nov 19 19:08:36 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 19 Nov 2009 16:08:36 -0800 Subject: non-copy slices In-Reply-To: <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> <7fd737460911190955l5cb53eacr79f47366a861782e@mail.gmail.com> Message-ID: <4B05DE04.9080101@stoneleaf.us> Themis Bourdenas wrote: > On Thu, Nov 19, 2009 at 2:44 PM, Ethan Furman > wrote: > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? In other words, you are creating a window onto an > existing list? If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? > > ~Ethan~ > > Yes a window / view on the existing list describes it best. So every > modification you make in this view is actually modifying the original > list accordingly. Blist that was suggested in a previous email in the > thread seems lightweight but it does create a new list when a > modification is made. In any case, I've already implemented the object > myself and I can post it if you care to have a look, but I was just > wondering if there was already something in the standard library. > > Themis Unfortunately, I am not very familiar with the stdlib yet (gotta buy that book!). I'm going to guess 'No' since nobody has chimed in with a 'Yes', though. I'd love to see what you have for that. Does in support a stepped window, or only contiguous sequences? The one I put together this afternoon only does contiguous sequences, as I had no use cases to decide how assignments of multiple items should be handled, and not a lot of time to implement something generic -- so, to answer John's question from a completely different thread, yes I do enjoy working on small projects even if IAGNI. :) Cheers! ~Ethan~ From david at boddie.org.uk Thu Nov 19 19:33:05 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 20 Nov 2009 01:33:05 +0100 Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <007f3944$0$23487$c3e8da3@news.astraweb.com> <05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> <863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> <40330c10-d52f-45f1-be40-b2a711cfa03b@d10g2000yqh.googlegroups.com> Message-ID: On Thursday 19 November 2009 11:50, Simon Hibbs wrote: > I don't think a list like this is a great way to do that. There are > plenty of examples and tutorials available for each option. This site has a selection of tutorials that can be used to compare API and code styles: http://zetcode.com/ David From jabronson at gmail.com Thu Nov 19 19:39:37 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 16:39:37 -0800 (PST) Subject: python bijection References: <0315cb54$0$1327$c3e8da3@news.astraweb.com> Message-ID: <55b3949d-2424-41ef-90fd-6e8184cbbcd7@o10g2000yqa.googlegroups.com> On Nov 19, 7:05?pm, Steven D'Aprano wrote: > If I want a mapping a <-> b, I generally just create a dict {a:b, b:a}. > What is the advantages or disadvantages of your code over the simplicity > of the dict approach? Well for one, you don't have to manually update the mapping from b -> a if ever the mapping from a -> b changes. With your method you have to write something like "d[a] = c; d[c] = a; del d[b]" instead of just "d[a] = c", "del d[d.pop(a)]" instead of just "del d[a]", etc. More significantly, your approach doesn't actually model a bijection since there's no distinction between keys (the domain) and values (the range). In other words, you lose information about which way is the forward mapping and which is the inverse mapping. Worse, d.keys() and d.values() would each give you the combination of your keys and values, neither of which would be right, and d.items() would also return twice as many elements as you expect with no way to distinguish which side of the mapping a given pair comes from. From magicus23REMOVE-THIS at gmail.com Thu Nov 19 21:01:26 2009 From: magicus23REMOVE-THIS at gmail.com (furlan) Date: Fri, 20 Nov 2009 02:01:26 +0000 (UTC) Subject: Whom Must We Worship References: <90a98e7d-daff-466a-9060-6a4a789d892c@k4g2000yqb.googlegroups.com> Message-ID: On Sun, 15 Nov 2009 00:17:43 -0800, Mary wrote: > Whom Must We Worship > The Decision is yours! Thank you, I got that. I choose Python. Thanks for sharing. ciao, f -- aa #2301 "...The word that separates that which is dead from that which is living....In the beginning was the word and that word was...CHOICE" -- Tom Robbins (SLWW) From pavlovevidence at gmail.com Thu Nov 19 21:17:36 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 19 Nov 2009 18:17:36 -0800 (PST) Subject: python bijection References: Message-ID: On Nov 19, 3:24?pm, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? Comments and suggestions welcome. Apart from the GPL, it seems perfectly fine to release, and looks like an interesting strategy. I've wanted one of those once in a while, never enough to bother looking for one or writing one myself. But you should absolutely not inherit from dict if you're overriding all it's methods. It's useless and wasteful to do that, perhaps dangerous. You end up using bytes for a small hash table that's never used. Plus Python 3 has a notion of Abstract Base Classes: it will allow customization of isinstance to advertise that your class implements MutableMapping, which is the right way to do it. Carl Banks From ben+python at benfinney.id.au Thu Nov 19 21:36:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 20 Nov 2009 13:36:19 +1100 Subject: python bijection References: Message-ID: <87aayhgbx8.fsf@benfinney.id.au> Carl Banks writes: > On Nov 19, 3:24?pm, Joshua Bronson wrote: > > I couldn't find a library providing a bijective map data structure > > (allowing for constant-time lookups by value) in the few minutes I > > looked, so I took a few more minutes to code one > > up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > > > Is this at all worth releasing? Comments and suggestions welcome. > > Apart from the GPL, it seems perfectly fine to release, and looks like > an interesting strategy. I've wanted one of those once in a while, > never enough to bother looking for one or writing one myself. I would think GPL is an excellent choice for such a library then, if the author's intention is to encourage more software to be free software so that it can incorporate a unique library like this. -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From pengyu.ut at gmail.com Thu Nov 19 22:18:04 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 19 Nov 2009 21:18:04 -0600 Subject: Is there something similar to list comprehension in dict? Message-ID: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> I'm wondering if there is something similar to list comprehension for dict (please see the example code below). d = dict(one=1, two=2) print d def fun(d):#Is there a way similar to list comprehension to change the argument d so that d is changed? d=dict(three=3) fun(d) print d def fun1(d): d['one']=-1 fun1(d) print d L = [1, 2] print L def fun2(L):#this doesn't have any effect on the argument L L=[] fun2(L) print L#[1, 2] def fun3(L):# argument L is changed L[:]=[1, 2, 3] fun3(L) print L#[1, 2, 3] From jabronson at gmail.com Fri Nov 20 00:33:18 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Thu, 19 Nov 2009 21:33:18 -0800 (PST) Subject: python bijection References: Message-ID: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> On Nov 19, 9:17 pm, Carl Banks wrote: > Apart from the GPL what Ben said :) > it seems perfectly fine to release, and looks like > an interesting strategy. I've wanted one of those once in a while, > never enough to bother looking for one or writing one myself. glad to hear it! i'll release it to pypi if such feedback continues. > But you should absolutely not inherit from dict if you're overriding > all it's methods. It's useless and wasteful to do that, perhaps > dangerous. You end up using bytes for a small hash table that's never > used. > > Plus Python 3 has a notion of Abstract Base Classes: it will allow > customization of isinstance to advertise that your class implements > MutableMapping, which is the right way to do it. Actually that's what I was originally thinking of doing but didn't go through with it in my first pass out of concern that users might want isinstance(bijection(), dict) to be True. Now that you bring it up, I agree that it's the correct way to do it, and have reimplemented bijection as a MutableMapping (ABCs are actually in Python 2.6). Take a peek at the new and improved http://bitbucket.org/jab/toys/src/tip/bijection.py if you get a chance and let me know how it looks! Anyone have any other feedback? For instance, is offering the __call__ syntax for the inverse mapping wonderful or terrible, or maybe both? Thanks, Josh From Scott.Daniels at Acm.Org Fri Nov 20 00:55:46 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Nov 2009 21:55:46 -0800 Subject: FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you In-Reply-To: References: Message-ID: Jonathan Fine wrote:... > A big thanks to Armin Ronacher and Raymond Hettinger for > PEP 372: Adding an ordered dictionary to collections > ... I prototyped (in about an hour). > > I then thought - maybe someone has been down this path before.... > > So all that I want has been done already, and will be waiting for me > when I move to Python3. > > So a big thank you is in order. And thank you for, having done that, not simply smiling because your work was lighter. Instead you described a great work path and handed an attaboy to a pair of people that richly deserve attaboys. --Scott David Daniels Scott.Daniels at Acm.Org From nagle at animats.com Fri Nov 20 01:52:10 2009 From: nagle at animats.com (John Nagle) Date: Thu, 19 Nov 2009 22:52:10 -0800 Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5? In-Reply-To: References: Message-ID: <4b063a25$0$1668$742ec2ed@news.sonic.net> Keith Hughitt wrote: > Hi all, > > I ran into a problem recently when trying to add support for earlier > versions of Python (2.4 and 2.5) to some database related code which > uses MySQLdb, and was wondering if anyone has any suggestions. > > With later versions of Python (2.6), inserting Unicode is very simple, > e.g.: > > # -*- coding: utf-8 -*- > ... > cursor.execute('''INSERT INTO `table` VALUES (0, > '?ngstr?m'),...''') > > When the same code is run on earlier versions, however, the results is > either garbled text (e.g. "? or "?" instead of "?" in Python 2.5), or > an exception being thrown (Python 2.4): > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in > position 60: ordinal not in range(128) > > So far I've tried a number of different things, including: > > 1. Using Unicode strings (e.g. u"\u212B") > > 2. Manually specifying the encoding using sys.setdefaultencoding > ('utf-8') > > 3. Manually enabling Unicode support in MySQLdb > (use_unicode=False, charset = "utf8") No, that's backwards. Try: db = MySQLdb.connect(host="localhost", use_unicode = True, charset = "utf8", user=username, passwd=password, db=database) "use_unicode" means that you want MySQLdb to accept and return Unicode strings. "charset="utf8" means you want MySQLdb to negotiate with the server to use UTF8 on the socket connecting it to the database. This works fine in Python 2.4 and 2.5. Returned strings will be in Unicode. At the database end, you have to make sure that 1) MySQL was built with Unicode support (it usually is), 2) the database fields of interest are in Unicode. I suggest ALTER DATABASE dbname DEFAULT CHARACTER SET utf8; before doing any CREATE TABLE operations. Then strings will be UTF8 in the database. Read this: http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html It all works quite well. John Nagle From Scott.Daniels at Acm.Org Fri Nov 20 02:22:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Nov 2009 23:22:22 -0800 Subject: Writing a Carriage Return in Unicode In-Reply-To: References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: MRAB wrote: > u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a visible > "CR" graphic) for carriage return. Windows programs normally expect > lines to end with '\r\n'; just use u'\n' in programs and open the text > files in text mode ('r' or 'w'). This is the one thing from standards that I believe Microsoft got right where others did not. The ASCII (American Standard for Information Interchange) standard end of line is _both_ carriage return (\r) _and_ line feed (\n) -- I believe in that order. The Unix operating system, in its enthusiasm to make _everything_ simpler (against Einstein's advice, "Everything should be made as simple as possible, but not simpler.") decided that end-of-line should be a simple line feed and not carriage return line feed. Before they made that decision, there was debate about the order of cr-lf or lf-cr, or inventing a new EOL character ('\037' == '\x1F' was the candidate). If you've actually typed on a physical typewriter, you know that moving the carriage back is a distinct operation from rolling the platen forward; both operations are accomplished when you push the carriage back using the bar, but you know they are distinct. Hell, MIT even had "line starve" character that moved the cursor up (or rolled the platen back). Lots of people talk about "dos-mode files" and "windows files" as if Microsoft got it wrong; it did not -- Unix made up a convenient fiction and people went along with it. (And, yes, if Unix had been there first, their convention was, in fact, better). So, sorry for venting, but I have bee wanting to say this in public for years. --Scott David Daniels Scott.Daniels at Acm.Org From timr at probo.com Fri Nov 20 02:27:00 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Nov 2009 23:27:00 -0800 Subject: ANN: Urwid 0.9.9 - Console UI Library References: <4b04e2d7$0$930$ba4acef3@news.orange.fr> Message-ID: "Michel Claveau - MVP" wrote: > >Hi! > >You forget to write "urwid" do not run under Windows. He also forgot to write "urwid" do not run under CP/M or OS/360. Why did you feel compelled to post this three times? If it supported Windows, it would say so. The fact that it doesn't say so means it isn't supported. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan_ml at behnel.de Fri Nov 20 02:55:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 08:55:40 +0100 Subject: DOM related question and problem In-Reply-To: References: Message-ID: <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> elca, 18.11.2009 19:04: > these day im making python script related with DOM. > > problem is these day many website structure is very complicate . > [...] > what is best method to check can extract such like following info quickly? This should help: http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciated-web-scraping-library/ Stefan From stefan_ml at behnel.de Fri Nov 20 03:02:30 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:02:30 +0100 Subject: Python/HTML integration: phileas v0.3 released In-Reply-To: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> papa hippo, 19.11.2009 19:53: > The prime goal of 'phileas' is to enable html code to be seamlessly > included in python code in a natural looking syntax, without resorting > to templatng language. I assume you know XIST, ElementTree's ElementMaker, and all those other ways of generating XML/HTML from Python code in a natural looking way? Stefan From michele.simionato at gmail.com Fri Nov 20 03:19:43 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 20 Nov 2009 00:19:43 -0800 (PST) Subject: Is there something similar to list comprehension in dict? References: Message-ID: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> On Nov 20, 4:18?am, Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict Yes, but only in Python 3: >>> {(i, x) for i, x in enumerate('abc')} {(0, 'a'), (1, 'b'), (2, 'c')} From stefan_ml at behnel.de Fri Nov 20 03:24:31 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:24:31 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: References: Message-ID: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> Peng Yu, 20.11.2009 04:18: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). A list comprehension is an expression that produces a list, e.g. [ i**2 for i in range(10) ] Your example below uses a slice assignment. > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > d=dict(three=3) > [...] > def fun3(L):# argument L is changed > L[:]=[1, 2, 3] You can use d.update(...) It accepts both another dict as well as a generator expression that produces item tuples, e.g. d.update( (i, i**2) for i in range(10) ) Does that help? Stefan From stefan_ml at behnel.de Fri Nov 20 03:26:21 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Nov 2009 09:26:21 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> References: <4b065240$0$7617$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <4b0652ad$0$7617$9b4e6d93@newsspool1.arcor-online.net> Stefan Behnel, 20.11.2009 09:24: > You can use d.update(...) > > It accepts both another dict as well as a generator expression that > produces item tuples, e.g. > > d.update( (i, i**2) for i in range(10) ) This also works, BTW: >>> d = {} >>> d.update(value=5) >>> d {'value': 5} Stefan From ajtkmr at gmail.com Fri Nov 20 04:17:28 2009 From: ajtkmr at gmail.com (Ajit Kumar) Date: Fri, 20 Nov 2009 14:47:28 +0530 Subject: non-copy slices In-Reply-To: <4B0559C3.5020707@stoneleaf.us> References: <7fd737460911180734t72f4a11fl2be95ccd3bf0ad94@mail.gmail.com> <4B04166F.7060507@stoneleaf.us> <7fd737460911181747l4af5cbdbi4dbd8f8dc85349a6@mail.gmail.com> <200911181900.17759.rami.chowdhury@gmail.com> <7fd737460911190239l66126f3xda1589d9fe249bf5@mail.gmail.com> <4B0559C3.5020707@stoneleaf.us> Message-ID: <413d5b60911200117t5737f64dy83658728f996b010@mail.gmail.com> On Thu, Nov 19, 2009 at 8:14 PM, Ethan Furman wrote: >> No I'm well aware that there is no deep copy of the objects and the lists >> only keep references to the objects and in essence they have the same >> objects in there. But this doesn't mean they are the same list. >> Modifications to slices are not written back to the original list. >> >> x = range(5) >> y = x[1:3] >> y[0] = 13 >> x[1] == y[0] ?--> False >> >> Of course if I modify the object in the slice then the original list will >> see the change, but this is not what I was saying. Second and more >> importantly it's the performance penalty from allocating a large number of >> lists produced from the slices and the copy of the references. islice does >> not have this penalty, it should only instantiate a small object that >> iterates on the original list. >> >> Themis > > So "shallow copy" == "new label created for existing object". > > So is your desired behavior to write back to the original list if your > sub-list is modified? ?In other words, you are creating a window onto an > existing list? ?If not, what would happen when a sublist element was > modified (or deleted, or appended, or ...)? On a related note, GO encourages use of slices. http://golang.org/doc/effective_go.html#slices From patrick.just4fun at gmail.com Fri Nov 20 04:21:40 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Fri, 20 Nov 2009 10:21:40 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <4B065FA4.4050700@gmail.com> Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). Do you mean something like this: >>> {i:i+1 for i in [1,2,3,4]} {1: 2, 2: 3, 3: 4, 4: 5} This works in python3, but not in python2 - Patrick From paul.nospam at rudin.co.uk Fri Nov 20 04:29:47 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 20 Nov 2009 09:29:47 +0000 Subject: Is there something similar to list comprehension in dict? References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <87zl6hilx0.fsf@rudin.co.uk> Patrick Sabin writes: > Peng Yu wrote: >> I'm wondering if there is something similar to list comprehension for >> dict (please see the example code below). > > Do you mean something like this: > >>>> {i:i+1 for i in [1,2,3,4]} > {1: 2, 2: 3, 3: 4, 4: 5} > > This works in python3, but not in python2 Of course in python 2 you can do: >>> dict((i, i+1) for i in [1,2,3,4]) {1: 2, 2: 3, 3: 4, 4: 5} From tjreedy at udel.edu Fri Nov 20 04:32:03 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 04:32:03 -0500 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). Python 3 has list, set, and dict comprehensions. Don't know about 2.6/7 From mrkafk at gmail.com Fri Nov 20 05:10:18 2009 From: mrkafk at gmail.com (mk) Date: Fri, 20 Nov 2009 11:10:18 +0100 Subject: checking 'type' programmatically Message-ID: Disclaimer: this is for exploring and debugging only. Really. I can check type or __class__ in the interactive interpreter: Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) >>> p >>> (so, se) = p.communicate() >>> so 'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmultbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nworkspace\n' >>> se '' >>> so.__class__ >>> type(so) >>> type(se) But when I do smth like this in code that is ran non-interactively (as normal program): req.write('stderr type %s
    ' % type(se)) req.write('stderr class %s
    ' % str(se.__class__)) then I get empty output. WTF? How do I get the type or __class__ into some object that I can display? Why do that: e.g. if documentation is incomplete, e.g. documentation on Popen.communicate() says "communicate() returns a tuple (stdoutdata, stderrdata)" but doesn't say what is the class of stdoutdata and stderrdata (a file object to read? a string?). Regards, mk From robin at reportlab.com Fri Nov 20 05:12:26 2009 From: robin at reportlab.com (Robin Becker) Date: Fri, 20 Nov 2009 10:12:26 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B066B8A.9000103@chamonix.reportlab.co.uk> Aahz wrote: > In article , > Robert P. J. Day wrote: >> http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 >> >> thoughts? > > Haven't seen this elsewhere in the thread: > > http://dalkescientific.com/writings/diary/archive/2009/11/15/100000_tasklets.html I looked at this and it looks very good in that stackless appears twice as fast as go(lang) (I used to be in the department of computing at Imperial so I suppose I have to side with McCabe). Anyhow, my reading of why Pike was so proud of his set up and tear down of the tasks example was that these were real threads. Presumably that means they could potentially run in parallel on the 100000 cpu machines of the future. I'm not so clear on whether the threadless tasklets will run on separate cpus. -- Robin Becker From list at qtrac.plus.com Fri Nov 20 05:20:17 2009 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 20 Nov 2009 02:20:17 -0800 (PST) Subject: Book: Programming Python 3 (Second Edition) now available Message-ID: <27f9ed25-db38-40ef-8512-5708a3a04901@r5g2000yqb.googlegroups.com> Hi, I'm delighted to announce that a new edition of my Python 3 book is now available in the U.S. "Programming in Python 3 (Second Edition): A Complete Introduction to the Python Language" ISBN 0321680561 http://www.qtrac.eu/py3book.html The book has been fully revised and updated and now covers both Python 3.0 and 3.1, and with the language moratorium (PEP 3003), this second edition should be useful for many years to come. And in addition to the thorough updating, the book has been extended with new chapters on debugging, testing, and profiling, and on parsing (including coverage of the PyParsing and PLY modules), as well as a new section on coroutines in the advanced chapter. The book is aimed at a wide audience, but assumes some programming experience (not necessarily Python, not necessarily object-oriented). It teaches solid procedural style programming, then builds on that to teach solid object-oriented programming, and then goes on to more advanced topics (e.g., including a nice way to create validated attributes by combining class decorators with descriptors). But even newcomers to Python 3 should be able to write useful (although small and basic) programs after reading chapter 1, and then go on to create larger and more sophisticated programs as they work through the chapters. All the examples are available for download from the book's web site. From seeWebInstead at rem.intarweb.org Fri Nov 20 05:35:47 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Fri, 20 Nov 2009 02:35:47 -0800 Subject: Does turtle graphics have the wrong associations? References: <0315a685$0$1327$c3e8da3@news.astraweb.com> Message-ID: > > My proposed no-syntax > > IDE *also* gets rid of the need to bother with any programming-language > > syntax. I've been proposing it for years, but nobody has shown any > > interest > From: Steven D'Aprano > I'm interested. No-syntax IDE? How is this even possible? I guess you missed what I previously posted. The basic idea is that you start with test data, and you use menus to select appropriate data-processing actions to perform on that data. For example, you manually key in a file name containing test data, or copy and paste that same file name. Then you select "open file by that name" or "load all lines from file by that name" etc. from a menu. If you just opened the file, you now have a stream of input, and you can select to read one line or one s-expression or one character etc. from that file. After loading the whole file or one unit of data, you now have some *real* data to work from. For example, with a line of input, you might break it into words. Caveat: When I said "no syntax", I mean no programming syntax, no syntax to indicate function calls or variable assignment etc. You still must deal with visual representation of strings and integers and other essential data objects, which in a way may be considered to be syntax. But if you want, you can avoid *all* syntax, even for data, by drawing a *picture* of the individual bits. For some low-level machine-language training, or boolean algebra lessons, this might actually be preferable to Arabic numerals and English letters to represent data values. Seeing a *picture* of something that looks like a paper tape seems more binary-friendly than seeing arabic digits "0" and "1" in rows across a page, when studying operations upon boolean values or bitmasks. Now if you don't like the burden of navigating the multi-level menus, a search engine can be available, whereby you key in keywords for the name of some data-processing operation you either saw before or a name you can construct in your mind based on naming conventions. The extreme case of search engine would be if English-language pseudo-code can be automatically converted into a very short menu of most likely data-processing operations. I actually am seriously considering doing NewEco software development by this means. Basically I contract people to brainstorm with me in a Delphi fashion to create the toplevel design of a new computer algorithm, then we do top-down break into pieces, and continue top-down break-down as far as it takes until the search engine recognizes some step as something it already knows how to do. > The only way I can think of is some sort of wizard interface. > E.g. instead of having to remember the syntax for a slice, you > click the "Slice" button and the computer prompts you to enter > some combination of start, end, step, then generates the syntax > [a:b:c] for you. Yeah, it'll be vaguely like that in some ways. For major data, we'll have the data first, all parameters to the next function to apply, and *then* we select what function to call on those parameters. But for minor parameters, we might allow you to choose the function before filling in the minor-parameter slots. For example, to select the nth character of string, we might have both the string and the integer N before we select the NTH function, but if N is a constant we might instead have just the string and select the NTH function and fill in the constant N. With the pseudo-code translation, some of the constant parameters might be apparent in the English. For example, we have a string, and we say "select the second word" (actually that's almost HyperTalk, the scripting language of HyperCard on Macintosh computers), at which point the constant parameter 2 would be supplied from the word "second" in the English. From joost at h-labahn.de Fri Nov 20 05:51:10 2009 From: joost at h-labahn.de (DreiJane) Date: Fri, 20 Nov 2009 02:51:10 -0800 (PST) Subject: Announcement: depikt - the minimalistic python gate to gtk Message-ID: <11b6b3ac-e406-4550-b812-12dedb4a4e64@p35g2000yqh.googlegroups.com> Hi all, these days i make depikt, a python C-extension for building apps with gtk. It was a challenge for me and big fun. From its short description on sourceforge.net: "Python-3 wrappers for GTK. A minimalistic approach - just suited for GUI-building of apps, in no way for widget-building. Currently 1250 lines for 15 widgets with about 100 methods ... " depikt is advanced enough now to begin the transition of an 8MB python app of me to it - simultaneously with the transition to Python-3 and English. During this process depikt will grow to support for perhaps 25 widgets and 200 methods. From gobject it has connect(), connect_after(), handler_block(), handler_unblock() and handler_is_connected(). Still its status is marked as PreAlpha and depikt not entered to the Python wiki, because gtk_container_set_focus_chain() is defunct now - a vital method for fine usable applications. It's difficult to find out why - as it is the code was working for some time. depikt is very minimalistic: No python attributes of its classes, let alone properties No __repr__, no standard __init__ No support for set_property, get_property No real class hierarchy, there is one abstract base class Pikt, from which all concrete widgets are inheriting directly No exposing of Glib to python (but all i need from pango, cairo and gdk) Thus the code is very petty, well understandable and easy to extend to support for other widgets. That was the primary design goal, together with exact control of encoding issues, support for Python-3 and registry- and autoconf-free installation. Exception handling is about average now - there no mimimalism is intended, quite the contrary (for the long run). depikt will get to some mature state in 2010 - with perhaps about 3.000 lines then. One C-file will always be sufficient. atk might be added by means of a second file, also support for gtk.TreeView might get an own file - but both directly inserted by #include (no .h planned). Enjoy, Joost From fetchinson at googlemail.com Fri Nov 20 05:52:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 20 Nov 2009 11:52:19 +0100 Subject: Python/HTML integration: phileas v0.3 released In-Reply-To: <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> Message-ID: >> The prime goal of 'phileas' is to enable html code to be seamlessly >> included in python code in a natural looking syntax, without resorting >> to templatng language. >> >> see: >> >> http://larry.myerscough.nl/phileas_project/ >> >> I intend to submit phileas to the python.announce forum within the >> next few days. Any feedback received now will be gratefully received >> and may lead to improved quality of that submission. >> > > Hi Larry, looks like interesting stuff! > > There appears to be a problem with this page: > > http://larry.myerscough.nl/show_python_source.py?script_filename=./MyPage.py > > IOError: [Errno 2] No such file or directory: './MyPage.py' > > I do like the idea of having a more Python-oriented way to generate > HTML. Have you guys considered markup.py from http://markup.sourceforge.net/ ? It's comparable to your project as far as I can see, a more detailed comparison would probably be useful. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From joost at h-labahn.de Fri Nov 20 06:08:01 2009 From: joost at h-labahn.de (DreiJane) Date: Fri, 20 Nov 2009 03:08:01 -0800 (PST) Subject: Is there something similar to list comprehension in dict? References: Message-ID: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, two:2} ? Since you do not write L=list((1, 2)) either. These composed objects as basic building blocks make Python code so dense and beautiful, thus using "{}" means embracing the language's concept. From andreengels at gmail.com Fri Nov 20 06:41:10 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 20 Nov 2009 12:41:10 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <6faf39c90911200341u35ad9514m2a1f7f2e6a8712b6@mail.gmail.com> On Fri, Nov 20, 2009 at 4:18 AM, Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). > > > d = dict(one=1, two=2) > print d > > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > ?d=dict(three=3) > > fun(d) > print d > > def fun1(d): > ?d['one']=-1 > > fun1(d) > print d > > > L = [1, 2] > print L > > def fun2(L):#this doesn't have any effect on the argument L > ?L=[] > > fun2(L) > print L#[1, 2] > > def fun3(L):# argument L is changed > ?L[:]=[1, 2, 3] > > fun3(L) > print L#[1, 2, 3] > -- > http://mail.python.org/mailman/listinfo/python-list > def fun(d): d.clear() d[three] = 3 -- Andr? Engels, andreengels at gmail.com From davea at ieee.org Fri Nov 20 06:45:27 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 06:45:27 -0500 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> References: <366c6f340911191918s1268ef86t9dd5bd27c7918e8e@mail.gmail.com> Message-ID: <4B068157.3060003@ieee.org> Peng Yu wrote: > I'm wondering if there is something similar to list comprehension for > dict (please see the example code below). > > > d = dict(one=1, two=2) > print d > > def fun(d):#Is there a way similar to list comprehension to change the > argument d so that d is changed? > d=dict(three=3) > > fun(d) > print d > > def fun1(d): > d['one']=-1 > > fun1(d) > print d > > > L = [1, 2] > print L > > def fun2(L):#this doesn't have any effect on the argument L > L=[] > > fun2(L) > print L#[1, 2] > > def fun3(L):# argument L is changed > L[:]=[1, 2, 3] > > fun3(L) > print L#[1, 2, 3] > > You confused me by calling it a list comprehension. All you're using in fun3() is a slice. Using a slice, you can give a new set of values to an existing list. For a dictionary, it's just a bit trickier. You need two steps in the most general case. def fun4(d): d.clear() #clear out existing entries d.update(new_dict) #copy in new key:val pairs from a different dictionary This function will modify the caller's dictionary, completely replacing the contents. DaveA From mail at timgolden.me.uk Fri Nov 20 06:47:26 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 Nov 2009 11:47:26 +0000 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> References: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> Message-ID: <4B0681CE.1050404@timgolden.me.uk> Michele Simionato wrote: > On Nov 20, 4:18 am, Peng Yu wrote: >> I'm wondering if there is something similar to list comprehension for >> dict > > Yes, but only in Python 3: > >>>> {(i, x) for i, x in enumerate('abc')} > {(0, 'a'), (1, 'b'), (2, 'c')} Although the 2.x syntax is hardly onerous: dict ((i+5, x) for i, x in enumerate ('abc')) -- obviously without something like the i+5, the example equates to dict (enumerate ('abc')) :) TJG From simon at brunningonline.net Fri Nov 20 07:00:53 2009 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 20 Nov 2009 12:00:53 +0000 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> References: <07690063-85a0-4a58-bca9-91c1569c5fcb@o10g2000yqa.googlegroups.com> Message-ID: <8c7f10c60911200400j2d58c9a5y1bd84083ea8ee415@mail.gmail.com> 2009/11/20 Michele Simionato : > Yes, but only in Python 3: > >>>> {(i, x) for i, x in enumerate('abc')} > {(0, 'a'), (1, 'b'), (2, 'c')} In Python 2.x, you can do: >>> dict((i, x) for i, x in enumerate('abc')) {0: 'a', 1: 'b', 2: 'c'} (Works in 2.5 - I can't remember when generator expressions were introduced.) -- Cheers, Simon B. From mrkafk at gmail.com Fri Nov 20 07:03:04 2009 From: mrkafk at gmail.com (mk) Date: Fri, 20 Nov 2009 13:03:04 +0100 Subject: Regexp and multiple groups (with repeats) Message-ID: Hello, >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') >>> r.search(r'c:/tmp/spam/eggs').groups() ('/eggs',) Obviously, I would like to capture all groups: ('/tmp', '/spam', '/eggs') But it seems that re captures only the last group. Is there any way to capture all groups with repeat following it, i.e. (...)+ or (...)* ? Even better would be: ('tmp', 'spam', 'eggs') Yes, I know about re.split: >>> re.split( r'(?:\w:)?[/\\]', r'c:/tmp/spam\\eggs/' ) ['', 'tmp', 'spam', '', 'eggs', ''] My interest is more general in this case: how to capture many groups with a repeat? Regards, mk From hippostech at gmail.com Fri Nov 20 07:31:51 2009 From: hippostech at gmail.com (papa hippo) Date: Fri, 20 Nov 2009 04:31:51 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <5bbed1d7-3f03-43bc-b263-deffbfa27403@u8g2000prd.googlegroups.com> Message-ID: <59a9e5da-d615-4820-821a-cc1f02e9db77@z41g2000yqz.googlegroups.com> On 19 nov, 20:18, Steve Howell wrote: > On Nov 19, 10:53?am, papa hippo wrote: > > > The prime goal of 'phileas' is to enable html code to be seamlessly > > included in python code in a natural looking syntax, without resorting > > to templatng language. > > > see: > > >http://larry.myerscough.nl/phileas_project/ > > > I intend to submit phileas to the python.announce ?forum within the > > next few days. Any feedback received now will be gratefully received > > and may lead to improved quality of that submission. > > Hi Larry, looks like interesting stuff! > > There appears to be a problem with this page: > > http://larry.myerscough.nl/show_python_source.py?script_filename=./My... > > IOError: [Errno 2] No such file or directory: './MyPage.py' > Oh dear! my blunder; While syncing (with meld) from my test environment to the live environment, I missed a file. It seems to be fixed now. > I do like the idea of having a more Python-oriented way to generate > HTML. That's good to hear. Larry From victorsubervi at gmail.com Fri Nov 20 07:58:55 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 07:58:55 -0500 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> Message-ID: <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer wrote: > On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: > > Hello Victor, > > There are some pages on the internet that suggest that this problem my be > caused by a module named email.py (or email.pyc) in your pythonpath. If > you try import smtplib in the interpreter do you get this error message? > If so, start a new interpreter session and try import email - is the > email module imported from the stdlib? > Both of these import just fine. > > If these steps don't help, it might be useful if you can tell us which > Linux distribution you are using. > Python 2.4.3 [root at 13gems ~]# uname -a Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25 MSK 2009 x86_64 x86_64 x86_64 GNU/Linux CentOS 5.4 final TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Fri Nov 20 08:06:24 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 20 Nov 2009 08:06:24 -0500 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: > * Steven D'Aprano: >> >> On Thu, 19 Nov 2009 21:37:17 +0100, Alf P. Steinbach wrote: >> >>> The CPython 3.1.1 language reference ?4.1 says >>> >>> ? "Each command typed interactively is a block." >>> >>> It also says >>> >>> ? "If a name is bound in a block, it is a local variable of that block, >>> ? unless >>> ? ?declared as nonlocal" >>> >>> Even with a non-literal try-for-best-meaning reading I can't get this to >>> mesh with the actual behavior of the interpreter, e.g. >>> >>> ? >>> for x in "poi": >>> ? ... ? ?fandango = 666 >>> ? ... >>> ? >>> fandango >>> ? 666 >>> ? >>> _ >>> >>> My current understanding is (A) that the interpreter is correct in this >>> respect (for one would harldly want the effects of statements to be >>> fundamentally different in interpreted mode, except the presentation of >>> expression results), and (B), but here I'm less sure, that the >>> documentation is incorrect. >> >> >> Why do you say that? I don't see what it is in the command you typed that >> leads you to think the documentation is incorrect. >> >> The first command you type is: >> >> for x in "poi": >> ? ?fandango = 666 >> >> >> which binds two names, x and fandango. Since you are not typing them in a >> function or class definition, locals() is globals() and the two local names >> you create happen to also be globals. > > Thanks, that may be it. > > In most other languages I'm familiar with, if a name is local then it isn't > global (and vice versa), and I had that as an underlying assumption since it > doesn't appear to be mentioned in the documentation. > > However, I find a language reference statement that alludes to this: "(The > variables of the module code block are local and global.)" > > Hm... > > >> The next two commands you type: >> >> fandango >> _ >> >> don't bind anything, so aren't relevant. > > Well it showed that 'fandango' had been defined as a global. :-) > > >> If it helps: >> >> >>>>> for x in "poi": >> >> ... ? ? fandango = 666 >> ... >>>>> >>>>> locals() is globals() >> >> True >>>>> >>>>> fandango >> >> 666 >>>>> >>>>> locals()['fandango'] >> >> 666 >>>>> >>>>> import __main__ >>>>> __main__.fandango >> >> 666 > > Yeah, helps. > > I feel that there's still something lacking in my understanding though, like > how/where the "really actually just pure local not also global" is defined > for function definition, but it's now just a vague feeling of something > missing, not a feeling of direct contradiction as I had when I believed > local != global. > It's because the only blocks in python that have their own scope are classes and functions. For loops don't have their own scope- they use the enclosing one, which in this case is globals. > > Cheers, & thanks, > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > From hippostech at gmail.com Fri Nov 20 08:18:06 2009 From: hippostech at gmail.com (papa hippo) Date: Fri, 20 Nov 2009 05:18:06 -0800 (PST) Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On 20 nov, 09:02, Stefan Behnel wrote: > papa hippo, 19.11.2009 19:53: > > > The prime goal of 'phileas' is to enable html code to be seamlessly > > included in python code in a natural looking syntax, without resorting > > to templatng language. > > I assume you know XIST, ElementTree's ElementMaker, and all those other > ways of generating XML/HTML from Python code in a natural looking way? > > Stefan Hi Stefan, Thanks for your feedback. Yes, I am aware that phileas might - on the basis of the short description on this post - come across like a 're-invented wheel'. There is, however, one big difference between phileas and all other other similar packages (XIST, ELementTree, HTMLgen, HyperText, pyhtmloo etc.) that I inspected: Phileas uses distinct objects to generate each start and end tag, whereas all the others use a single function call (in some cases itself generated by a function call) to generate a complete well- formed element including start-tag and (where required) end-tag. In theory this is less neat and indeed it means one can write 'bad' HTML (e.g. missing end of paragraphs) with phileas just as easily as when writing pure html. In practice, however, I find it at a lot easier to use. While using pyhtmloo (my previous favourite HTML generator), I had found myself using awkward complicated artificial constructions in order to generate all but the simplest HTML - and spent much time playing 'hunt the missing bracket'. With phileas, these complexities seem to just fall away. Put another way, Phileas generates HTML4.0 - warts and all; it is not a parser or generator of XML. I'm considering building in checks/warnings for unclosed elements etc., probably in the next-but-one pre-release. Larry From deets at nospam.web.de Fri Nov 20 09:03:35 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 15:03:35 +0100 Subject: Is there something similar to list comprehension in dict? In-Reply-To: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> References: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> Message-ID: <7mnltnF3iv96rU1@mid.uni-berlin.de> DreiJane schrieb: > NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, > two:2} ? Since you do not write L=list((1, 2)) either. These composed because it's not working. >>> {one : 1} Traceback (most recent call last): File "", line 1, in NameError: name 'one' is not defined Yes, that looks nitpicky, but that is exactly the reason one often prefers the dict(...)-variant. Because it uses python keywords, it spares you to type quotes around all the keys. Which IMHO is more aesthetic. > objects as basic building blocks make Python code so dense and > beautiful, thus using "{}" means embracing the language's concept. The collection-literals are a great thing, no doubt. But these alternatives are not against any concept. Diez From sturlamolden at yahoo.no Fri Nov 20 09:37:23 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 06:37:23 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: On 19 Nov, 01:14, Doug wrote: > Thanks for your help!! A carriage return in unicode is u"\r" how this is written as bytes is dependent on the encoder. Don't try to outsmart the UTF-8 codec, it knows how to translate "\r" to UTF-8. Sturla Molden From exarkun at twistedmatrix.com Fri Nov 20 10:01:28 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 20 Nov 2009 15:01:28 -0000 Subject: checking 'type' programmatically In-Reply-To: References: Message-ID: <20091120150128.27565.1834940229.divmod.xquotient.339@localhost.localdomain> On 10:10 am, mrkafk at gmail.com wrote: > >Disclaimer: this is for exploring and debugging only. Really. > >I can check type or __class__ in the interactive interpreter: > >Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) >[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >>> import subprocess > >>> >p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) > >>> p > > >>> (so, se) = p.communicate() > >>> so >'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmultbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nworkspace\n' > >>> se >'' > >>> so.__class__ > > >>> type(so) > > >>> type(se) > > >But when I do smth like this in code that is ran non-interactively (as >normal program): > >req.write('stderr type %s
    ' % type(se)) >req.write('stderr class %s
    ' % str(se.__class__)) > >then I get empty output. WTF? > >How do I get the type or __class__ into some object that I can display? Hooray for HTML. You asked a browser to render "stderr type
    ". This isn't valid HTML, so pretty much any behavior goes. In this case, the browser seems to be discarding the entire - not too suprising, as it has some features in common with an html tag. Try properly quoting your output (perhaps by generating your html with a real html generation library). Jean-Paul From kevin.p.dwyer at gmail.com Fri Nov 20 10:05:38 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 20 Nov 2009 15:05:38 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: On Fri, 20 Nov 2009 07:58:55 -0500, Victor Subervi wrote: > On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > wrote: > >> On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: >> >> Hello Victor, >> >> There are some pages on the internet that suggest that this problem my >> be caused by a module named email.py (or email.pyc) in your pythonpath. >> If you try import smtplib in the interpreter do you get this error >> message? If so, start a new interpreter session and try import email - >> is the email module imported from the stdlib? >> >> > Both of these import just fine. > > >> If these steps don't help, it might be useful if you can tell us which >> Linux distribution you are using. >> >> > Python 2.4.3 > [root at 13gems ~]# uname -a > Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6 > 11:28:25 MSK 2009 x86_64 x86_64 x86_64 GNU/Linux CentOS 5.4 final > TIA, > V >
    On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > < href="mailto:kevin.p.dwyer at gmail.com">kevin.p.dwyer at gmail.com> > wrote:
    On Thu, 19 Nov 2009 > 11:28:37 -0400, Victor Subervi wrote:

    > Hello Victor,
    >
    > There are some pages on the internet that suggest that this problem my > be
    caused by a module named email.py (or email.pyc) in your > pythonpath. ?If
    you try import smtplib in the interpreter do you get > this error message?
    If so, start a new interpreter session and try > import email - is the
    email module imported from the > stdlib?

    Both of these import just > fine.?

    > If these steps don't help, it might be useful if you can tell us > which
    Linux distribution you are > using.

    Python > 2.4.3
    [root at 13gems ~]# uname -a
    Linux href="http://13gems.com.13gems.com">13gems.com.13gems.com > 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25 MSK 2009 x86_64 x86_64 > x86_64 GNU/Linux
    CentOS 5.4 > final
    TIA,
    V
    Hello Victor, I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as yours but also running python 2.4.3). It ran without error. So I suspect that either you have a rogue email module/package on your machine or there's something wrong with the python install. You could try: import email email.__version__ My interpreter responds "3.0.1" If you get a different response that suggests a dodgy module somewhere - try email.__file__ and see where it's located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc). If the version number is "3.0.1" on your machine then I would check the contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module is missing. Cheers, Kev From billy.earney at gmail.com Fri Nov 20 10:06:09 2009 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 20 Nov 2009 09:06:09 -0600 Subject: checking 'type' programmatically In-Reply-To: References: Message-ID: <4b06b063.e402be0a.68e8.5fe5@mx.google.com> Try looking at the function 'isinstance', so for example if isinstance(obj, str): print "object is a string.." elif isinstance(obj, int): print "object is an integer.." -----Original Message----- From: python-list-bounces+billy.earney=gmail.com at python.org [mailto:python-list-bounces+billy.earney=gmail.com at python.org] On Behalf Of mk Sent: Friday, November 20, 2009 4:10 AM To: python-list at python.org Subject: checking 'type' programmatically Disclaimer: this is for exploring and debugging only. Really. I can check type or __class__ in the interactive interpreter: Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE ) >>> p >>> (so, se) = p.communicate() >>> so 'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmul tbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nwork space\n' >>> se '' >>> so.__class__ >>> type(so) >>> type(se) But when I do smth like this in code that is ran non-interactively (as normal program): req.write('stderr type %s
    ' % type(se)) req.write('stderr class %s
    ' % str(se.__class__)) then I get empty output. WTF? How do I get the type or __class__ into some object that I can display? Why do that: e.g. if documentation is incomplete, e.g. documentation on Popen.communicate() says "communicate() returns a tuple (stdoutdata, stderrdata)" but doesn't say what is the class of stdoutdata and stderrdata (a file object to read? a string?). Regards, mk -- http://mail.python.org/mailman/listinfo/python-list From carsten.haese at gmail.com Fri Nov 20 10:14:01 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 10:14:01 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer > wrote: > > On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote: > > Hello Victor, > > There are some pages on the internet that suggest that this problem > my be > caused by a module named email.py (or email.pyc) in your pythonpath. If > you try import smtplib in the interpreter do you get this error message? > If so, start a new interpreter session and try import email - is the > email module imported from the stdlib? > > > Both of these import just fine. Kevin neglected to mention that the new interpreter session must be started in the same directory as the one you're in when you run your testMail.py script. Since he didn't mention that, we can't be sure that that's what you did, so this experiment doesn't prove anything. Please show us a copy-and-paste of your command line window contents that result from executing <> and then executing <> immediately thereafter. -- Carsten Haese http://informixdb.sourceforge.net From alfps at start.no Fri Nov 20 10:23:48 2009 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 20 Nov 2009 16:23:48 +0100 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: * Benjamin Kaplan: > On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: >> * Steven D'Aprano: >> >> I feel that there's still something lacking in my understanding though, like >> how/where the "really actually just pure local not also global" is defined >> for function definition, but it's now just a vague feeling of something >> missing, not a feeling of direct contradiction as I had when I believed >> local != global. >> > > It's because the only blocks in python that have their own scope are > classes and functions. For loops don't have their own scope- they use > the enclosing one, which in this case is globals. Thanks, but hey, contradiction: you mention globals as an "enclosing" scope, i.e. that a module can have a scope, while stating that only classes and functions have their own scope (so, would a module have it's not own scope?). I think, having now read up and down and sideways in the docs, that the proper term in Python is "namespace", and that "scope" in Python refers to where the names in a namespace are directly accessible, with a special case for classes, namely that the scope of a class' namespace doesn't penetrate down into function definitions, hence problem with comprehensions expressed directly in a class definition. I believe that's a so called language "wart" -- which C++ is full of, just now discovering some of Python's :-). It's almost like C++'s "most vexing parse", a natural and apparently meaningful source code construct that due to the detailed rules turns out to be meaningless. I wish language designers could be a little less hooked on low level consistency. Because it makes for high level inconsistency, very difficult to explain without zillions of details. But anyways, it's starting to make more sense, yes. Cheers, - Alf From victorsubervi at gmail.com Fri Nov 20 10:45:15 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:45:15 -0400 Subject: Too Many Values To Unpack Message-ID: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Hi; At one point Dennis Lee Bieber helped me with the following slightly modified code: #!/usr/bin/python import sys,os sys.path.append(os.getcwd()) import MySQLdb from login import login import re, string def printTree(aTree, level=0): tree = [] for name in sorted(aTree.keys()): tree.append("%s%s") % ("\t" * level, name) printTree(aTree[name], level + 1) def expand(fetched): aDict = {} for (name, ) in fetched: aDict[name] = {} return aDict def getChildren(levelDict, level = 0): MAXLEVEL = 7 if level > MAXLEVEL: return #possibly the data has a cycle/loop for (nm, dt) in levelDict: cursor.execute('''select c.name from categories as c inner join relationship as r on c.ID = r.Child inner join categories as p on r.Parent = p.ID where p.category = %s order by c.name''', (nm,)) levelDict[nm] = expand(cursor.fetchall()) # recursive call to do next level getChildren(levelDict[nm], level + 1) # no data return as we are mutating dictionaries in place def catTree(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('''create table if not exists categories (ID int(3) unsigned primary key, Category varchar(40), Parent varchar(40))''') cursor.execute('select Category, Parent from categories;') data = cursor.fetchall() cursor.execute('select Category from categories order by Parent, ID') print data Categories = [itm[0] for itm in cursor] #untuple single column if len(Categories) > 0: cursor.execute('select Parent from categories order by Parent, ID') Parents = [itm[0] for itm in cursor] MAXLEVEL = 15 cursor.execute('''create table if not exists categories (ID integer auto_increment primary key, Name varchar(40) not null, unique (Name) )''') cursor.execute('''create table if not exists Relationship (ID integer auto_increment primary key, Parent integer not null, foreign key (Parent) references categories (ID), Child integer not null, foreign key (Child) references categories (ID), check (Parent <> Child) );''') # get top level print 'ok' cursor.execute('select category from categories order by category') theTree = expand(cursor.fetchall()) getChildren(theTree) connection.commit() return printTree(theTree) else: return ['There are no categories yet.'] catTree() This throws the error: [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] Traceback (most recent call last): [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/createCats.py", line 8, in ? [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] from catTree import catTree [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 77, in ? [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] catTree() [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 71, in catTree [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] getChildren(theTree) [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in getChildren [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] for (nm, dt) in levelDict: [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] ValueError: too many values to unpack There is only one category in "categories". Please advise. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Nov 20 10:49:17 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:49:17 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: <4dc0cfea0911200749n35f51909ie78f42c175a55162@mail.gmail.com> On Fri, Nov 20, 2009 at 11:05 AM, Kev Dwyer wrote: > I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as > yours but also running python 2.4.3). It ran without error. So I > suspect that either you have a rogue email module/package on your machine > or there's something wrong with the python install. > > You could try: > > import email > email.__version__ > > My interpreter responds "3.0.1" If you get a different response that > suggests a dodgy module somewhere - try email.__file__ and see where it's > located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc). > > If the version number is "3.0.1" on your machine then I would check the > contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module > is missing. > >>> import email >>> email.__version__ '3.0.1' >>> [root at 13gems cart]# ls /usr/lib64/python2.4/email/ base64MIME.py Encoders.pyo Generator.pyc Iterators.py MIMEAudio.pyo MIMEMessage.pyc MIMEText.py Parser.pyo base64MIME.pyc Errors.py Generator.pyo Iterators.pyc MIMEBase.py MIMEMessage.pyo MIMEText.pyc quopriMIME.py base64MIME.pyo Errors.pyc Header.py Iterators.pyo MIMEBase.pyc MIMEMultipart.py MIMEText.pyo quopriMIME.pyc Charset.py Errors.pyo Header.pyc Message.py MIMEBase.pyo MIMEMultipart.pyc _parseaddr.py quopriMIME.pyo Charset.pyc FeedParser.py Header.pyo Message.pyc MIMEImage.py MIMEMultipart.pyo _parseaddr.pyc test Charset.pyo FeedParser.pyc __init__.py Message.pyo MIMEImage.pyc MIMENonMultipart.py _parseaddr.pyo Utils.py Encoders.py FeedParser.pyo __init__.pyc MIMEAudio.py MIMEImage.pyo MIMENonMultipart.pyc Parser.py Utils.pyc Encoders.pyc Generator.py __init__.pyo MIMEAudio.pyc MIMEMessage.py MIMENonMultipart.pyo Parser.pyc Utils.pyo Any other ideas? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Nov 20 10:52:30 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 20 Nov 2009 15:52:30 GMT Subject: Regexp and multiple groups (with repeats) References: Message-ID: <7mns9uF3i7o34U1@mid.individual.net> On 2009-11-20, mk wrote: > Hello, > > >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') > > >>> r.search(r'c:/tmp/spam/eggs').groups() > ('/eggs',) > > Obviously, I would like to capture all groups: > ('/tmp', '/spam', '/eggs') You'll have to do something else, for example: >>> s = re.compile(r'(?:[a-zA-Z]:)') >>> n = re.compile(r'[\\/]\w+') >>> m = s.match('c:/tmp/spam/eggs') >>> n.findall(m.string[m.end():]) ['/tmp', '/spam', '/eggs'] -- Neil Cerutti From victorsubervi at gmail.com Fri Nov 20 10:58:00 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 11:58:00 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> Message-ID: <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese wrote: > Kevin neglected to mention that the new interpreter session must be > started in the same directory as the one you're in when you run your > testMail.py script. Since he didn't mention that, we can't be sure that > that's what you did, so this experiment doesn't prove anything. > > Please show us a copy-and-paste of your command line window contents > that result from executing <> and then executing > <> immediately thereafter. > [root at 13gems globalsolutionsgroup.vi]# python testMail.py Traceback (most recent call last): File "testMail.py", line 2, in ? import smtplib File "/usr/lib64/python2.4/smtplib.py", line 49, in ? from email.base64MIME import encode as encode_base64 ImportError: No module named base64MIME [root at 13gems globalsolutionsgroup.vi]# python -c "import email; print email" TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Nov 20 11:02:38 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 08:02:38 -0800 Subject: Is an interactive command a block? In-Reply-To: References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: <4B06BD9E.80303@stoneleaf.us> Alf P. Steinbach wrote: > * Benjamin Kaplan: >> On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach wrote: >>> >>> I feel that there's still something lacking in my understanding >>> though, like >>> how/where the "really actually just pure local not also global" is >>> defined >>> for function definition, but it's now just a vague feeling of something >>> missing, not a feeling of direct contradiction as I had when I believed >>> local != global. >>> >> >> It's because the only blocks in python that have their own scope are >> classes and functions. For loops don't have their own scope- they use >> the enclosing one, which in this case is globals. > > > Thanks, but hey, contradiction: you mention globals as an "enclosing" > scope, i.e. that a module can have a scope, while stating that only > classes and functions have their own scope (so, would a module have it's > not own scope?). module scope == global scope That is, there is nothing higher than module scope. (So, yes, global is a slight misnomer... in Python it means 'global to a module'.) ~Ethan~ From metolone+gmane at gmail.com Fri Nov 20 11:03:51 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 20 Nov 2009 08:03:51 -0800 Subject: Regexp and multiple groups (with repeats) References: Message-ID: "mk" wrote in message news:he60ha$ivv$1 at ger.gmane.org... > Hello, > > >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') > > >>> r.search(r'c:/tmp/spam/eggs').groups() > ('/eggs',) > > Obviously, I would like to capture all groups: > ('/tmp', '/spam', '/eggs') > > But it seems that re captures only the last group. Is there any way to > capture all groups with repeat following it, i.e. (...)+ or (...)* ? > > Even better would be: > > ('tmp', 'spam', 'eggs') > > Yes, I know about re.split: > > >>> re.split( r'(?:\w:)?[/\\]', r'c:/tmp/spam\\eggs/' ) > ['', 'tmp', 'spam', '', 'eggs', ''] > > My interest is more general in this case: how to capture many groups with > a repeat? re.findall is what you're looking for. Here's all words not followed by a colon: >>> import re >>> re.findall(u'(\w+)(?!:)',r'c:\tmp\spam/eggs') ['tmp', 'spam', 'eggs'] -Mark From sturlamolden at yahoo.no Fri Nov 20 11:11:12 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 08:11:12 -0800 (PST) Subject: python gui builders References: <8u9Mm.35397$Wd1.32454@newsfe15.iad> <0f25c82f-1ab0-4dde-b7e9-c44a3ae84d8a@n35g2000yqm.googlegroups.com> Message-ID: <764c524e-9b1e-4e88-9ec4-806f8416d90d@b2g2000yqi.googlegroups.com> On 18 Nov, 22:18, David Bolen wrote: > With that said, for various reasons I still prefer wxPython to Qt, and > at the moment, find wxFormBuilder the best fit for my own designs > (even before the direct Python support, just using XRC). Personally I prefer wxFormBuilder over QtDesigner for sizer-based designs. For quickly creating mock-up designs (GUI or web) there is a Windows program called "DesignerVista". From eric.frederich at gmail.com Fri Nov 20 11:14:23 2009 From: eric.frederich at gmail.com (eric.frederich) Date: Fri, 20 Nov 2009 08:14:23 -0800 (PST) Subject: Split class across multiple files Message-ID: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> I have a class which holds a connection to a server and a bunch of services. In this class I have methods that need to work with that connection and services. Right now there are about 50 methods some of which can be quite long. >From an organizational standpoint, I'd like to have method implementations in their own files. Is this possible? It is recommended? Should I just stop worrying about it and have a 5,000 line class? From shashank.sunny.singh at gmail.com Fri Nov 20 11:14:44 2009 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Fri, 20 Nov 2009 21:44:44 +0530 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Message-ID: <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> On Fri, Nov 20, 2009 at 9:15 PM, Victor Subervi wrote: > Hi; > At one point Dennis Lee Bieber helped me with the following slightly > modified code: > > #!/usr/bin/python > > import sys,os > sys.path.append(os.getcwd()) > import MySQLdb > from login import login > import re, string > > def printTree(aTree, level=0): > tree = [] > for name in sorted(aTree.keys()): > tree.append("%s%s") % ("\t" * level, name) > printTree(aTree[name], level + 1) > > def expand(fetched): > aDict = {} > for (name, ) in fetched: > aDict[name] = {} > return aDict > def getChildren(levelDict, level = 0): > MAXLEVEL = 7 > if level > MAXLEVEL: > return #possibly the data has a cycle/loop > for (nm, dt) in levelDict: > Are you sure your key values are 2-tuples in levelDict? For-each on dicts enumerates the keys AFAIK -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Fri Nov 20 11:15:49 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 12:15:49 -0400 Subject: Serve Pages Under Different Ownership Message-ID: <4dc0cfea0911200815x54f910abv41323cb2ecbc512b@mail.gmail.com> Hi; I'm building a new server after many years hiatus. I currently can only serve python pages chown'd to root. How do I change this? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Fri Nov 20 11:15:55 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 11:15:55 -0500 Subject: semantics of [:] Message-ID: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) ############# 1 ################## b = a[:] # b receives a copy of a, but they are independent # The following two are equivalent ############# 2 ################## c = [] c = a[:] # c receives a copy of a, but they are independent ############# 3 ################## d = [] d[:] = a # d receives a copy of a, but they are independent ### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ## do. Am I correct with this? Thanks. From deets at nospam.web.de Fri Nov 20 11:21:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:21:49 +0100 Subject: semantics of [:] In-Reply-To: References: Message-ID: <7mnu0tF3itudnU1@mid.uni-berlin.de> Esmail schrieb: > Could someone help confirm/clarify the semantics of the [:] operator > in Python? > > a = range(51,55) > > ############# 1 ################## > b = a[:] # b receives a copy of a, but they are independent > > > > # The following two are equivalent > ############# 2 ################## > c = [] > c = a[:] # c receives a copy of a, but they are independent No, the both above are equivalent. Both just bind a name (b or c) to a list. This list is in both cases a shallow copy of a. > > > ############# 3 ################## > d = [] > d[:] = a # d receives a copy of a, but they are independent This is a totally different beast. It modifies d in place, no rebinding a name. So whover had a refernce to d before, now has a changed object, whereas in the two cases above, the original lists aren't touched. Of course, in your concrete example, the looks of it are the same. The distinction is crucial in larger contexts. Diez From deets at nospam.web.de Fri Nov 20 11:31:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:31:27 +0100 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <7mnuivF3ih0p9U1@mid.uni-berlin.de> eric.frederich schrieb: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? It is recommended? Should I just stop worrying > about it and have a 5,000 line class? It is pretty easy to do, as python allows multiple inheritance. Just group together methods into a class, and create one that inherits from all. However, I'd say something that even splitted up is essentially one class with 5000 lines cries for a huge refactoring. Of course this depends on the use-case, but I for once don't have a single such beast. Looks like a god-object to me... http://en.wikipedia.org/wiki/God_object Diez From carsten.haese at gmail.com Fri Nov 20 11:32:32 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 11:32:32 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > At one point Dennis Lee Bieber helped me with the following slightly > modified code: > > [snippage...] > > def getChildren(levelDict, level = 0): > MAXLEVEL = 7 > if level > MAXLEVEL: > return #possibly the data has a cycle/loop > for (nm, dt) in levelDict: > cursor.execute('''select c.name from categories as c > inner join relationship as r > on c.ID = r.Child > inner join categories as p > on r.Parent = p.ID > where p.category = %s > order by c.name ''', (nm,)) > levelDict[nm] = expand(cursor.fetchall()) > # recursive call to do next level > getChildren(levelDict[nm], level + 1) > # no data return as we are mutating dictionaries in place > > [snippage...] > > [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] for (nm, > dt) in levelDict: > [Fri Nov 20 07:41:11 2009] [error] [client 208.84.198.58] ValueError: > too many values to unpack Iterating over a dictionary, such as what you're doing in the line <>, only produces the keys that are in the dictionary. This means that this line only works if the keys in levelDict are pairs of "nm"s and "dt"s, whatever "nm" and "dt" represent. (In case the foregoing is too subtle a clue: Choose better variable names.) However, the line <> indicates that the keys in levelDict are only "nm"s, which are presumably single objects, not pairs. Also, the "dt" that you're trying to unpack from levelDict's keys is not used anywhere in your function. So, this would indicate that changing the offending line to <> should fix this particular error. HTH, -- Carsten Haese http://informixdb.sourceforge.net From pavlovevidence at gmail.com Fri Nov 20 11:36:15 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 20 Nov 2009 08:36:15 -0800 (PST) Subject: Split class across multiple files References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <5a896672-2670-4268-adff-bbce2e3f5752@p23g2000vbl.googlegroups.com> On Nov 20, 8:14?am, "eric.frederich" wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? Yes, define all your different methods in separate classes in separate files. Then subclasses all of those separate classes into one big class. > It is recommended? Debateable. Personally, I have no problem using inheritance for purely mechanical reasons. Others might. (In my case, it was a separation into general and customized behavior. I wanted to define generic behavior in one package, and specialized behavior in another, but there was no internal logical difference between specialized and generic methods.) However.... > Should I just stop worrying > about it and have a 5,000 line class? Five thousand lines is pushing the comfort level of how big a class ought to be. I suggest instead of worrying about how to mechanically split off methods into different files, you should consider whether there's a way to refactor that one big class into smaller ones. Then the problem you have goes away. Carl Banks From carsten.haese at gmail.com Fri Nov 20 11:38:42 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 11:38:42 -0500 Subject: Python Will Not Send Email!! In-Reply-To: <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese > wrote: > Please show us a copy-and-paste of your command line window contents > that result from executing <> and then executing > <> immediately thereafter. > > > [root at 13gems globalsolutionsgroup.vi ]# > python testMail.py > Traceback (most recent call last): > File "testMail.py", line 2, in ? > import smtplib > File "/usr/lib64/python2.4/smtplib.py", line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > [root at 13gems globalsolutionsgroup.vi ]# > python -c "import email; print email" > Thank you. This proves conclusively that there IS in fact a file called email.pyc (and/or email.py) in your directory next to testMail.py. It is this email.pyc that is being imported instead of the email.py from the Python library. Getting rid of both email.py and email.pyc (by renaming them, deleting them, or moving them somewhere else) will fix your problem. -- Carsten Haese http://informixdb.sourceforge.net From animator333 at gmail.com Fri Nov 20 11:38:54 2009 From: animator333 at gmail.com (King) Date: Fri, 20 Nov 2009 08:38:54 -0800 (PST) Subject: No duplicate variable Message-ID: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> class A(object): def __init__(self, value=0.): self.value = value class B(A): def __init__(self, value=None): A.__init__(self) self.value = value obj = B() When "B" initializes, it overwrite "value" variable of "A". How do I make sure that no variable should not be defined with names of "A" in "B"? Prashant From deets at nospam.web.de Fri Nov 20 11:46:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 20 Nov 2009 17:46:16 +0100 Subject: No duplicate variable In-Reply-To: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> References: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> Message-ID: <7mnveoF3hq8cmU1@mid.uni-berlin.de> King schrieb: > class A(object): > def __init__(self, value=0.): > self.value = value > > class B(A): > def __init__(self, value=None): > A.__init__(self) > self.value = value > > obj = B() > > When "B" initializes, it overwrite "value" variable of "A". How do I > make sure that no variable should not be defined with names of "A" in > "B"? To avoid these kinds of clashes, you can use the double-undescore syntax. It will create a mangled name that looks like _module_class_variablename By this, the two different variable get distinct names. *However*, this is neither a proper way of making variables private, nor are name-clashes something that should arise more than every now-and-then. Instead, try rather renaming value to something more meaningful. Diez From azeynel1 at gmail.com Fri Nov 20 11:46:30 2009 From: azeynel1 at gmail.com (Zeynel) Date: Fri, 20 Nov 2009 08:46:30 -0800 (PST) Subject: Newbie question about scrapy tutorial Message-ID: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> Hello, I have a question about scrapy tutorial and I put 2 questions in the scrapy group http://groups.google.com/group/scrapy-users/t/d5afae7d88672e02 http://groups.google.com/group/scrapy-users/t/4d52fa8c589a412a but there were no answers. Can anyone here help me? The spider works fine but I couldn't figure out where the items file is so that I can print it to a file to transfer it to my database. The same question in stackoverflow http://stackoverflow.com/questions/1771151/newbie-q-about-scrapy-pipeline-py Thanks! From kevin.p.dwyer at gmail.com Fri Nov 20 11:56:19 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 20 Nov 2009 16:56:19 +0000 (UTC) Subject: Python Will Not Send Email!! References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: On Fri, 20 Nov 2009 11:58:00 -0400, Victor Subervi wrote: Hello Victor, Carsten's well-specified instruction has identified your problem. >[root at 13gems globalsolutionsgroup.vi]# python -c "import email; print >email" > There is a file named email.pyc, most likely in your current directory, that is masking the email package in the standard library. Remove/rename email.pyc and email.py, if it exists. Cheers, Kevin From victorsubervi at gmail.com Fri Nov 20 12:13:32 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 13:13:32 -0400 Subject: Too Many Values To Unpack In-Reply-To: <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> Message-ID: <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> On Fri, Nov 20, 2009 at 12:14 PM, Shashank Singh < shashank.sunny.singh at gmail.com> wrote: > Are you sure your key values are 2-tuples in levelDict? > No. Here's some tweaked code: cursor.execute('select category from categories order by category') theTree = expand(cursor.fetchall()) print theTree Now, categories only has one category called 'cat1'. Here's what it prints: {'cat1': {}} Now what I don't understand about the above code, provided by Dennis Lee Bieber, is the "expand" statement. Nor could I find any documentation googling either "expand python" or "expand fetchall python". Could someone please explain what this code does? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Nov 20 12:17:54 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 20 Nov 2009 11:17:54 -0600 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06CF42.3040905@tim.thechases.com> Diez B. Roggisch wrote: > Esmail schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no rebinding > a name. So whover had a refernce to d before, now has a changed object, > whereas in the two cases above, the original lists aren't touched. To demonstrate what Diez is saying: a = range(51,55) d = [] x = d d[:] = a print x #hey, I didn't change x...oh, yeah -tkc From davea at ieee.org Fri Nov 20 12:29:09 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 12:29:09 -0500 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06D1E5.20601@ieee.org> Diez B. Roggisch wrote: >
    Esmail > schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no > rebinding a name. So whover had a refernce to d before, now has a > changed object, whereas in the two cases above, the original lists > aren't touched. > > Of course, in your concrete example, the looks of it are the same. The > distinction is crucial in larger contexts. > > Diez > > While Diez is correct, I think it could be less confusing. So I'll try to put it clearer. If it's not, sorry. (2) binds an empty list to c, and immediately rebinds it to a new list, copied from a.. So the c=[] line is totally irrelevant, unless there's some other code in between. (3) again binds an empty list to d, but this is important, because the following line wouldn't be legal if there weren't already a list. The only time this has a different practical effect from the other two is if there's some other code between the two lines. If that other code binds something to the same object then it definitely matters. I'd say (1) is the preferable form, as no visible object is in an in-between state. The copy is built anonymously, then bound only when it has its full value. DaveA From victorsubervi at gmail.com Fri Nov 20 12:39:30 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 20 Nov 2009 13:39:30 -0400 Subject: Python Will Not Send Email!! In-Reply-To: References: <4dc0cfea0911190728o9b9bf48n2dab72f1cf955096@mail.gmail.com> <4dc0cfea0911200458k3759f0c4q5d2aa2c6a9078c1@mail.gmail.com> <4dc0cfea0911200758p769900e6ha030d54ae7a25aed@mail.gmail.com> Message-ID: <4dc0cfea0911200939i3fc5e821l8bedbacb821ecbd7@mail.gmail.com> On Fri, Nov 20, 2009 at 12:38 PM, Carsten Haese wrote: > Thank you. This proves conclusively that there IS in fact a file called > email.pyc (and/or email.py) in your directory next to testMail.py. It is > this email.pyc that is being imported instead of the email.py from the > Python library. Getting rid of both email.py and email.pyc (by renaming > them, deleting them, or moving them somewhere else) will fix your problem. > Thank you! It did indeed fix that problem. Now I get this traceback: /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py 52 session.sendmail(clientEmail, ourEmail1, header+msg) 53 # session.sendmail(clientEmail, ourEmail2, header+msg) 54 55 mailSpreadsheet() 56 *mailSpreadsheet* = /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet *() 47 order += 'TOTAL: $' + str(total) 48 msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) 49 session = smtplib.SMTP("localhost") 50 session.login(user, passwd) # only if it requires auth 51 header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject session *undefined*, *global* *smtplib* = , smtplib.*SMTP* = /usr/lib64/python2.4/smtplib.py in *__init__*(self=, host='localhost', port=0, local_hostname=None) 242 self.esmtp_features = {} 243 if host: 244 (code, msg) = self.connect(host, port) 245 if code != 220: 246 raise SMTPConnectError(code, msg) code *undefined*, msg *undefined*, *self* = , self.* connect* = >, *host* = 'localhost', *port* = 0 /usr/lib64/python2.4/smtplib.py in *connect*(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* = , self.*getreply* = > /usr/lib64/python2.4/smtplib.py in *getreply*(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) *global* *SMTPServerDisconnected* = * SMTPServerDisconnected*: Connection unexpectedly closed args = ('Connection unexpectedly closed',) Why did this connection close? How do I fix it? TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kyrie at uh.cu Fri Nov 20 12:45:11 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Fri, 20 Nov 2009 12:45:11 -0500 Subject: semantics of [:] In-Reply-To: References: Message-ID: <200911201245.11995.kyrie@uh.cu> On Friday 20 November 2009 11:15:55 am Esmail wrote: > Could someone help confirm/clarify the semantics of the [:] operator > in Python? In short, a[:], when "a" is a list, returns a slice ("sublist") of "a" that happens to contain all the elemnts of "a". In general, a[low:upper:step] will give you the sublist containing all the items from low to upper, with the specified step size. When you omit the three arguments, you get the whole list. When used on the left side, it means "replace the contents of this slice with the contents of this iterable". (The get slice and set slice behaviors are defined by the class of ?a?, so while this explanation applies to list, it may not apply, and will likely not apply, to other data structures). Note that the sublist is always another list (even when you get the full slice). So, in your experiments: > ############# 1 ################## > b = a[:] # b receives a copy of a, but they are independent Indeed, a[:] would return a full slice, i.e, another list containing the same elements as ?a? > # The following two are equivalent > ############# 2 ################## > c = [] > c = a[:] # c receives a copy of a, but they are independent > ############# 3 ################## > d = [] > d[:] = a # d receives a copy of a, but they are independent Not exactly, but the difference is not big in this particular circumstance. In (2), you create an empty list, discard it immediately, create another list a[:] with the contents of ?a?, and assign it to ?c?. In (3) you create an empty list, and then fill it with the elements of ?a?. To see the difference, try: e = [] g = e e = a[:] print g and e = [] g = e e[:] = a print g > ### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ## > do. Depends on what you want to achieve. Some times, you need to keep the list and change the contents. That would be (3). For instance, when updating the "dirnames" output of the iterator returned by os.walk . Some times, you need to discard de old list, and get a new one. (1) would be the way to go. Note that (2) and (1) are the same, in both you discard the old value, if it exists, but in (2) you are creating a new list only to discard it right away - you shouldn't do that. > Am I correct with this? I hope I could help. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From sturlamolden at yahoo.no Fri Nov 20 12:51:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 09:51:49 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On 20 Nov, 11:12, Robin Becker wrote: > Presumably that means they could potentially run in parallel on the 100000 cpu > machines of the future. > > I'm not so clear on whether the threadless tasklets will run on separate cpus. You can make a user-space scheduler and run a 100000 tasklets on a threadpool. But there is a GIL in stackless as well. Nobody wants 100000 OS threads, not with Python, not with Go, not with C. Also note that Windows has native support for "taskelets", regardless of language. They are called "fibers" (as opposed to "threads") and are created using the CreateFiber system call. I would not be surprised if Unix'es has this as well. We do not need Stackless for light-weight threads. We can just take Python's threading modules' C code and replace CreateThread with CreateFiber. From alexis.flesch at gmail.com Fri Nov 20 12:58:47 2009 From: alexis.flesch at gmail.com (Snouffy) Date: Fri, 20 Nov 2009 09:58:47 -0800 (PST) Subject: PyQt4 4.4.4 : a bug with highlightBlock ? References: <4ea3a990-e9cd-4f70-8c0b-9e75a9d23c8d@o10g2000yqa.googlegroups.com> Message-ID: <7a44700d-24a3-4161-a899-ffc57fbb1baf@o10g2000yqa.googlegroups.com> > You need to change the indexOf() calls to indexIn() calls on the QRegExp > object: > > ? index = expression.indexIn(text, index + length) Thank you so much ! After looking a bit more I found out that when using indexOf the command : length = expression.matchedLength() was the one causing a problem. Thus I also had to change the line : index = text.indexOf(expression) to : index = expression.indexIn(text) Now it works like a charm ! I'll test it at work where we have PyQt 4.3.3. Thanks again ! From ebonak at hotmail.com Fri Nov 20 13:04:39 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 13:04:39 -0500 Subject: semantics of [:] In-Reply-To: <7mnu0tF3itudnU1@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Esmail schrieb: >> Could someone help confirm/clarify the semantics of the [:] operator >> in Python? >> >> a = range(51,55) >> >> ############# 1 ################## >> b = a[:] # b receives a copy of a, but they are independent > > >> >> >> # The following two are equivalent >> ############# 2 ################## >> c = [] >> c = a[:] # c receives a copy of a, but they are independent > > No, the both above are equivalent. Both just bind a name (b or c) to a > list. This list is in both cases a shallow copy of a. > >> >> >> ############# 3 ################## >> d = [] >> d[:] = a # d receives a copy of a, but they are independent > > > This is a totally different beast. It modifies d in place, no rebinding > a name. So whover had a refernce to d before, now has a changed object, I follow all of this up to here, the next sentence is giving me pause > whereas in the two cases above, the original lists aren't touched. The original list 'a', isn't changed in any of these cases right? And modifying b, c or d would not change 'a' either - or am I not understanding this correctly? ## 1 ## creates a new list and copies all elements from a to b ## 2 ## take an already existing list (empty) and copies all elements from a to it (no data is lost by c since c was empty to start out with) ## 3 ## d is a list, and all of its contents (if it had any) would be filled with that of a .. but changes to a still are not reflected in d .. this is confusing... Semi-aside, if I wanted to make local copy of a list sent to me as a parameter, which of these is the most appropriate to use (I don't want changes to change the original list sent). Thanks again. From carsten.haese at gmail.com Fri Nov 20 13:07:49 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Fri, 20 Nov 2009 13:07:49 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> Message-ID: Victor Subervi wrote: > Now what I don't understand about the above code, provided by Dennis Lee > Bieber, is the "expand" statement. It's not a statement. It's a function. The function is defined in your code. Or rather, it's defined in the code that you copied from Dennis Lee Bieber, apparently. Look at the function definition. It'll tell you what the function does. > Could > someone please explain what this code does? Maybe you should ask the person that wrote the code. -- Carsten Haese http://informixdb.sourceforge.net From eric.frederich at gmail.com Fri Nov 20 13:28:41 2009 From: eric.frederich at gmail.com (eric.frederich) Date: Fri, 20 Nov 2009 10:28:41 -0800 (PST) Subject: Split class across multiple files References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> <7mnuivF3ih0p9U1@mid.uni-berlin.de> Message-ID: Yeah... it does seem like a God Object. My reasoning for putting them all into one big class is that the class has references to all the required resources, connections, and services. The other option would be to have a simple object called Session which did nothing but login and hold those references. The problem then is that I'd have 50 methods all of which would need to take that session object as an argument. That is what I was trying to avoid, having a ton of methods all taking the same first parameter. In most cases there would only be one session. Perhaps I could do a singleton approach and have each of these methods implicitly use the single session object unless called with a session= keyword argument. How does this look?..... # Begin Session.py class Session(): def __init__(self, host=None, username=None, password=None): if host and username and password: self.login(host, username, password) def login(self, host, username, password): self.host = host self.username = username self.password = password self.connection = Something.login(host, username, password) self.someService = SomeService.getService(connection) self.anotherService = AnotherService.getService(connection) def logout(self): return self.connection.logout() defaultSession = Session() # Begin MyLibrary.py from session import defaultSession def doSomethig(x, y, z, session=defaultSession): return session.someService.doSomething(x, y, z) def anotherFunction(x, y, session=defaultSession): ret = 0 for item in session.anotherService.getStuff(x): if session.someService.foo(item, y): session.anotherService.bar(item, x) ret += 1 return ret On Nov 20, 11:31?am, "Diez B. Roggisch" wrote: > eric.frederich schrieb: > > > I have a class which holds a connection to a server and a bunch of > > services. > > In this class I have methods that need to work with that connection > > and services. > > > Right now there are about 50 methods some of which can be quite long. > > From an organizational standpoint, I'd like to have method > > implementations in their own files. > > > Is this possible? ?It is recommended? ?Should I just stop worrying > > about it and have a 5,000 line class? > > It is pretty easy to do, as python allows multiple inheritance. Just > group together methods into a class, and create one that inherits from all. > > However, I'd say something that even splitted up is essentially one > class with 5000 lines cries for a huge refactoring. Of course this > depends on the use-case, but I for once don't have a single such beast. > Looks like a god-object to me... > > http://en.wikipedia.org/wiki/God_object > > Diez From apt.shansen at gmail.com Fri Nov 20 13:40:02 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 20 Nov 2009 13:40:02 -0500 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <7a9c25c20911201040p3330f309s197b557f7da026f0@mail.gmail.com> > > The original list 'a', isn't changed in any of these cases right? And > modifying b, c or d would not change 'a' either - or am I not understanding > this correctly? > > ## 1 ## > > creates a new list and copies all elements from a to b > > Yes. > ## 2 ## > > take an already existing list (empty) and copies all elements from a to > it (no data is lost by c since c was empty to start out with) > > No. The 'already existing list' is simply completely discarded. You're creating it on one line, then destroying it. A brand new list is being created and returned and bound to the same name as the already existing list. > ## 3 ## > > d is a list, and all of its contents (if it had any) would be > filled with that of a .. but changes to a still are not reflected in d > .. this is confusing... > Not exactly, if I understand you correctly. D is a list, but its contents (if it had any) would be completely replaced. Any previous content would be gone, and it would now contain a copy of a. > Semi-aside, if I wanted to make local copy of a list sent to me as a > parameter, which of these is the most appropriate to use (I don't want > changes to change the original list sent). > my_copy = original[:] --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Fri Nov 20 14:08:23 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 20 Nov 2009 14:08:23 -0500 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <4B06E927.5070407@ieee.org> Esmail wrote: >
    Diez B. > Roggisch wrote: >> Esmail schrieb: >>> Could someone help confirm/clarify the semantics of the [:] operator >>> in Python? >>> >>> a = range(51,55) >>> >>> ############# 1 ################## >>> b = a[:] # b receives a copy of a, but they are independent >> > >>> >>> > > > Semi-aside, if I wanted to make local copy of a list sent to me as a > parameter, which of these is the most appropriate to use (I don't want > changes to change the original list sent). > > Thanks again. > > (1) is most appropriate in that case. In fact, unless there is other code mixed in between, it's always the most appropriate. DaveA From ethan at stoneleaf.us Fri Nov 20 14:22:58 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 11:22:58 -0800 Subject: semantics of [:] In-Reply-To: <4B06E927.5070407@ieee.org> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> <4B06E927.5070407@ieee.org> Message-ID: <4B06EC92.1000701@stoneleaf.us> Dave Angel wrote: > Esmail wrote: >>> Esmail schrieb: >>> >>>> Could someone help confirm/clarify the semantics of the [:] operator >>>> in Python? >>>> >>>> a = range(51,55) >>>> >>>> ############# 1 ################## >>>> b = a[:] # b receives a copy of a, but they are independent >> >> Semi-aside, if I wanted to make local copy of a list sent to me as a >> parameter, which of these is the most appropriate to use (I don't want >> changes to change the original list sent). >> > (1) is most appropriate in that case. In fact, unless there is other > code mixed in between, it's always the most appropriate. Be aware: this is only a shallow copy -- if your copied list contains mutable objects that you mutate, those changes *will* show up in the original list. Shallow copies are useful when, for example, you won't be mutating objects in the copied list but are adding, removing, or reordering the copied list. Hope this helps. ~Ethan~ From tjreedy at udel.edu Fri Nov 20 14:39:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 14:39:51 -0500 Subject: Does turtle graphics have the wrong associations? In-Reply-To: References: <0315a685$0$1327$c3e8da3@news.astraweb.com> Message-ID: Robert Maas, http://tinyurl.com/uh3t wrote: >>> My proposed no-syntax >>> IDE *also* gets rid of the need to bother with any programming-language >>> syntax. I've been proposing it for years, but nobody has shown any >>> interest What you describe below is similar to various systems that have been proposed and even implemented, including visual programming systems. And there has been some success with non-programmers. But for most people, it is simply easier to say/write what one means rather than point and click. Point-and-click writing reminds me of point-and-click speaking. Great for those who need it but a hindrance to those who do not. This is not to say that traditional editors cannot be improved with better backup memory aids. Indeed, even IDLE recognizes function names and pops up a bar listing parameters. Feel free to develop a Visual Python environment. I might even give it a try. >> From: Steven D'Aprano >> I'm interested. No-syntax IDE? How is this even possible? > > I guess you missed what I previously posted. I did too and had the same question. > The basic idea is that > you start with test data, and you use menus to select appropriate > data-processing actions to perform on that data. For example, you > manually key in a file name containing test data, or copy and paste > that same file name. Then you select "open file by that name" or > "load all lines from file by that name" etc. from a menu. If you > just opened the file, you now have a stream of input, and you can > select to read one line or one s-expression or one character etc. > from that file. After loading the whole file or one unit of data, > you now have some *real* data to work from. For example, with a > line of input, you might break it into words. Processing a single data file is a common programming task, but not the only general category. A specialized Visual Data Analysis with Python might be a better and more focused project. When I was doing statistical data analysis on a daily basis for a living, I would have loved to have had a system that would read in the first line and let me define (and name) the fields by point and click. (I usually worked with fixed-width, column-delimited fields.) Instead, I had to write a format statement and some summary analysis code, run it, look at it for sanity, and decide if my format had been correct. Terry Jan Reedy From ethan at stoneleaf.us Fri Nov 20 14:42:20 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 11:42:20 -0800 Subject: Newsgroup for beginners In-Reply-To: References: <7xiqd9yj8v.fsf@ruckus.brouhaha.com> Message-ID: <4B06F11C.2030806@stoneleaf.us> Aahz wrote: > In article , > Grant Edwards wrote: > >>You've really got to try pretty hard to create one. But if you >>want to, here's how to do it: >> >>1) Start by complaining that your program doesn't work because >> of a bug in Python. >> >> [...] > > > Post of the month! I'll second that! I really needed a good laugh. Many thanks! From vorticitywolfe at gmail.com Fri Nov 20 15:07:35 2009 From: vorticitywolfe at gmail.com (J Wolfe) Date: Fri, 20 Nov 2009 12:07:35 -0800 (PST) Subject: sort values from dictionary of dictionaries python 2.4 References: Message-ID: <68b0e959-6054-422a-a1e0-aac2161f6558@37g2000yqm.googlegroups.com> On Nov 9, 2:27?pm, Peter Otten <__pete... at web.de> wrote: > J Wolfe wrote: > > I would like to sort this dictionary by the values of the inner > > dictionary ?ob? key. > > Python's built-in dictionary is unsorted by design. > > > > > mydict = > > {?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?}, > > ?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?} > > } > > > In this case, this would become: > > > mysorteddic = > > {?NASW1?: {?fx?: ?6.8?, ?obtime?: ?2009-11-07 06:30:00?, ?ob?: ?7.1?}, > > ?WILW1?: {?fx?: ?8.1?, ?obtime?: ?2009-11-07 06:45:00?, ?ob?: ?6.9?}, > > ?GRRW1?: {?fx?: ?12.8?, ?obtime?: ?2009-11-07 04:15:00?, ?ob?: ?6.7?} > > } > > > I have had no luck in trying to figure this out. I am restricted to > > using python 2.4.3. > > > Any help would be appreciated! > > You may be able to work around that limitation by putting the dict items > into a list and sort that: > > >>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), > > reverse=True): > ... ? ? print item > ... > ('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'}) > ('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'}) > ('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'}) > > Peter Thanks Peter, That worked! :-) From tjreedy at udel.edu Fri Nov 20 15:09:41 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:09:41 -0500 Subject: python bijection In-Reply-To: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: Joshua Bronson wrote: > Anyone have any other feedback? For instance, is offering the __call__ > syntax for the inverse mapping wonderful or terrible, or maybe both? Terrible ;-) Use standard subscripting with slices, and only that, to both get and set. Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition Then m[:'abc'] == 4 m[4:] passes slice(4,None,None) to __getitem__ m[:'abc'] passes slice(None,'abc',None) It just happens that dict items and slices use the same notation, but they do, so take advantage of that. In fact, to emphasize the symmetry of the bijective map, consider disallowing m[key] as ambiguous and require m[key:], along with m[:key] to access and set. Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so this approach does not even prevent using slices as keys/values. In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an error. In __getitem__, it could either be a error or return True/False depending on whether the pair is in the map. But this depends on whether __contains__ only tests keys or is modified to test pairs. Terry Jan Reedy From duncan.booth at invalid.invalid Fri Nov 20 15:20:49 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Nov 2009 20:20:49 GMT Subject: semantics of [:] References: Message-ID: Dave Angel wrote: > > > Esmail wrote: >>
    Diez B. >> Roggisch wrote: >>> Esmail schrieb: >>>> Could someone help confirm/clarify the semantics of the [:] operator >>>> in Python? >>>> >>>> a = range(51,55) >>>> >>>> ############# 1 ################## >>>> b = a[:] # b receives a copy of a, but they are independent >>> > >>>> >>>> >> > (1) is most appropriate in that case. In fact, unless there is other > code mixed in between, it's always the most appropriate. An alternative view is that it is most appropriate to do: b = list(a) as that accepts any type of sequence for a and you don't have to remember obscure punctuation to know what it does. The exception of course is when (a) 'a' is sliceable and (b) you need to 'b' to be of the same type as 'a'. From tjreedy at udel.edu Fri Nov 20 15:26:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:26:33 -0500 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: eric.frederich wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. >>From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? A method is just function that is a class attribute. from somemethod import somemethod # has def somemethod class Huge: somemethod = somemethod # or class Huge: defs ... Huge.somemethod = somemethod > It is recommended? Should I just stop worrying > about it and have a 5,000 line class? I suspect some refactoring would be useful. From lfscripter at gmail.com Fri Nov 20 15:31:06 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Fri, 20 Nov 2009 21:31:06 +0100 Subject: Gray Hat Python: Python Programming for Hackers Soft copy Message-ID: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> Hi i`m looking for a place to get a soft copy of 'Gray Hat Python: Python Programming for Hackers' may be a pdf or chm format. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Nov 20 15:31:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Nov 2009 15:31:17 -0500 Subject: No duplicate variable In-Reply-To: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> References: <7ee1d744-89a3-43cb-a64e-f5ab901b2ce9@s15g2000yqs.googlegroups.com> Message-ID: King wrote: > class A(object): > def __init__(self, value=0.): > self.value = value > > class B(A): > def __init__(self, value=None): > A.__init__(self) > self.value = value > > obj = B() > > When "B" initializes, it overwrite "value" variable of "A". How do I > make sure that no variable should not be defined with names of "A" in > "B"? By knowing the public interface of A before you inherit from it, so you do not do that. From steve at REMOVE-THIS-cybersource.com.au Fri Nov 20 15:37:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 20:37:12 GMT Subject: Is an interactive command a block? References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> Message-ID: <0316ebed$0$1379$c3e8da3@news.astraweb.com> On Fri, 20 Nov 2009 08:02:38 -0800, Ethan Furman wrote: >> Thanks, but hey, contradiction: you mention globals as an "enclosing" >> scope, i.e. that a module can have a scope, while stating that only >> classes and functions have their own scope (so, would a module have >> it's not own scope?). > > module scope == global scope > > That is, there is nothing higher than module scope. (So, yes, global is > a slight misnomer... in Python it means 'global to a module'.) Actually there is: built-ins. That's why you can access (e.g.) len without having to define it, or import it, first. And what's more, you can do this: >>> len([1,2,3]) 3 >>> def len(x): # Shadow the built-in ... return -3 ... >>> len([1,2,3]) -3 >>> del len >>> len([1,2,3]) # It's back! 3 -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Nov 20 15:37:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Nov 2009 20:37:22 GMT Subject: Is there something similar to list comprehension in dict? References: <4ebe0a9f-1f34-40fc-8b0d-6f05b88d98a1@s31g2000yqs.googlegroups.com> Message-ID: <0316ebf7$0$1379$c3e8da3@news.astraweb.com> On Fri, 20 Nov 2009 03:08:01 -0800, DreiJane wrote: > NB: I wondered about about dict(one=1, two=2) - why not d = {one:1, > two:2} ? Because it doesn't work unless you have defined names one and two. dict(one=1, two=2) uses keyword arguments, namely one and two. This is the same standard mechanism by which you call functions with keyword arguments: myfunc(widget=x, width=5, name='fred', flag=True) The dict literal syntax requires names one and two to already exist, otherwise you have to quote them to make them strings: d = {'one': 1, 'two': 2} > Since you do not write L=list((1, 2)) either. But you certainly can. It would be wasteful, since first it constructs a tuple (1, 2), then it creates a list from that tuple. > These composed > objects as basic building blocks make Python code so dense and > beautiful, thus using "{}" means embracing the language's concept. I don't understand this sentence. -- Steven From ethan at stoneleaf.us Fri Nov 20 15:52:50 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 12:52:50 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <4B0701A2.9040603@stoneleaf.us> Jason R. Coombs wrote: > The current implementation of Python (2.6.4, 3.1.1) treats \bar as a > relative path but reports it as an absolute path. > > >>>>ntpath.isabs('\\bar') > > True > >>>>ntpath.abspath('\\bar') > > 'C:\\bar' > >>>>os.chdir('d:\\') >>>>ntpath.abspath('\\bar') > > 'd:\\bar' > >>>>os.chdir('\\\\server\\share') >>>>ntpath.abspath('\\bar') > > '\\\\server\\share\\bar' > > In other words, paths without a drive letter are reported as absolute, > but treated as relative, except in a few special cases. > > >>>>ntpath.join('d:\\foo', '\\bar') > > '\\bar' > > In this case, \bar is treated as absolute, and not relative to d:\foo. It is often said on this list that 'Python is not Java'. It is also true that 'Windows is not Unix'. Unlike the *nix world where there is a *single* root, and everything else is relative to that, in the Windows world there are several roots -- every drive has one! So \bar is both an absolute path on whichever drive is active (or specified), as well as relative if you happen to have more than one drive, but it will not ever be relative on any specific drive. If you want 'bar' to be relative to the current directory, do not specify a leading '\'. [snip] > Ultimately, I don't care what the definition is. It seems to me, > however, that Python should have a function that can resolve one path > name relative to another, but due to these limitations, it does not. I > should point out that os.path.relpath is not the solution either as > the first parameter is always treated as relative to the current > directory (more info at http://bugs.python.org/issue7195). Please note that there *is not* a relative path that can take you from c:\foo to d:\bar (see the point about multiple roots above). > I've built workarounds in https://svn.jaraco.com/jaraco/python/jaraco.windows/jaraco/windows/filesystem.py > as join() and resolve_path(). I'm happy to continue using these > workarounds, but I wanted to bring this issue to the attention of the > community for any comments or suggestions or answers to the following > questions. > > What is the benefit of treating \path as absolute? That was not Python's decision, but Windows'. > Should Python have built-in support for resolving one path relative to > another (such as is jaraco.windows.filesystem.resolve_path does)? As I noted above, you are not returning a relative path when the paths cross drive letter boundaries, or one of the paths specified is a drive-absolute path (such as '\bar'). > Given the long established behavior of Python and other platforms for > handling absolute paths in Windows, is there a way forward that > handles these cases more elegantly, or is the best approach to just > mumble something nasty under our breath and work around these issues > on a case-by-case basis? I just go with the mumbling, myself. Hope this helps. ~Ethan~ P.S. And now that I look up the comments in the bug-tracker, I see this was all already pointed out to you. From ethan at stoneleaf.us Fri Nov 20 16:03:43 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 20 Nov 2009 13:03:43 -0800 Subject: Is an interactive command a block? In-Reply-To: <0316ebed$0$1379$c3e8da3@news.astraweb.com> References: <0315a1b9$0$1327$c3e8da3@news.astraweb.com> <0316ebed$0$1379$c3e8da3@news.astraweb.com> Message-ID: <4B07042F.1010702@stoneleaf.us> Steven D'Aprano wrote: > On Fri, 20 Nov 2009 08:02:38 -0800, Ethan Furman wrote: >> >> module scope == global scope >> >> That is, there is nothing higher than module scope. (So, yes, global is >> a slight misnomer... in Python it means 'global to a module'.) > > Actually there is: built-ins. > > That's why you can access (e.g.) len without having to define it, or > import it, first. And what's more, you can do this: > >>>>len([1,2,3]) > > 3 > >>>>def len(x): # Shadow the built-in > ... return -3 > ... >>>>len([1,2,3]) > -3 > >>>>del len >>>>len([1,2,3]) # It's back! > > 3 Very good point, I had forgotten. Of course, injecting into built-ins is not recommended. ~Ethan~ From ebonak at hotmail.com Fri Nov 20 16:30:26 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 16:30:26 -0500 Subject: semantics of [:] In-Reply-To: References: Message-ID: Thank you all for your posts - this was very enlightening and I printed this thread off for future reference. From aahz at pythoncraft.com Fri Nov 20 16:45:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2009 13:45:04 -0800 Subject: python simply not scaleable enough for google? References: Message-ID: In article , sturlamolden wrote: > >Also note that Windows has native support for "taskelets", regardless >of language. They are called "fibers" (as opposed to "threads") and are >created using the CreateFiber system call. I would not be surprised if >Unix'es has this as well. We do not need Stackless for light-weight >threads. We can just take Python's threading modules' C code and >replace CreateThread with CreateFiber. Are you advocating a high-fiber diet? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 mmitchell at transparent.com Fri Nov 20 16:45:43 2009 From: mmitchell at transparent.com (Matt Mitchell) Date: Fri, 20 Nov 2009 16:45:43 -0500 Subject: Gray Hat Python: Python Programming for Hackers Soft copy In-Reply-To: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> References: <6be1e1a30911201231q360fc21i59c76450e7765daa@mail.gmail.com> Message-ID: You mean like: http://nostarch.com/ghpython.htm From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of Elf Scripter Sent: Friday, November 20, 2009 3:31 PM To: python-list at python.org Subject: Gray Hat Python: Python Programming for Hackers Soft copy Hi i`m looking for a place to get a soft copy of 'Gray Hat Python: Python Programming for Hackers' may be a pdf or chm format. Thank you ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jabronson at gmail.com Fri Nov 20 16:59:24 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 13:59:24 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <131ecb11-f1e0-480f-98b9-46b0359abe27@x16g2000vbk.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Joshua Bronson wrote: > > Anyone have any other feedback? For instance, is offering the __call__ > > syntax for the inverse mapping wonderful or terrible, or maybe both? > > Terrible ;-) > > Use standard subscripting with slices, and only that, to both get and set. > > Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition > Then m[:'abc'] == 4 > > m[4:] passes slice(4,None,None) to __getitem__ > m[:'abc'] passes slice(None,'abc',None) > > It just happens that dict items and slices use the same notation, but > they do, so take advantage of that. In fact, to emphasize the symmetry > of the bijective map, consider disallowing m[key] as ambiguous and > require m[key:], along with m[:key] to access and set. > > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. > > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. But this depends on whether > __contains__ only tests keys or is modified to test pairs. > > Terry Jan Reedy absolutely genius. implemented in the latest version: http://bitbucket.org/jab/toys/src/tip/bijection.py thank you for the terrific idea! From jabronson at gmail.com Fri Nov 20 16:59:24 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 13:59:24 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <131ecb11-f1e0-480f-98b9-46b0359abe27@x16g2000vbk.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Joshua Bronson wrote: > > Anyone have any other feedback? For instance, is offering the __call__ > > syntax for the inverse mapping wonderful or terrible, or maybe both? > > Terrible ;-) > > Use standard subscripting with slices, and only that, to both get and set. > > Let m[4] == m[4:] == 'abc' # m[4:] is suggested alternative addition > Then m[:'abc'] == 4 > > m[4:] passes slice(4,None,None) to __getitem__ > m[:'abc'] passes slice(None,'abc',None) > > It just happens that dict items and slices use the same notation, but > they do, so take advantage of that. In fact, to emphasize the symmetry > of the bijective map, consider disallowing m[key] as ambiguous and > require m[key:], along with m[:key] to access and set. > > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. > > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. But this depends on whether > __contains__ only tests keys or is modified to test pairs. > > Terry Jan Reedy absolutely genius. implemented in the latest version: http://bitbucket.org/jab/toys/src/tip/bijection.py thank you for the terrific idea! From deets at nospam.web.de Fri Nov 20 18:42:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 21 Nov 2009 00:42:00 +0100 Subject: semantics of [:] In-Reply-To: References: <7mnu0tF3itudnU1@mid.uni-berlin.de> Message-ID: <7monqaF3icnf3U2@mid.uni-berlin.de> Esmail schrieb: > Diez B. Roggisch wrote: >> Esmail schrieb: >>> Could someone help confirm/clarify the semantics of the [:] operator >>> in Python? >>> >>> a = range(51,55) >>> >>> ############# 1 ################## >>> b = a[:] # b receives a copy of a, but they are independent >> > >>> >>> >>> # The following two are equivalent >>> ############# 2 ################## >>> c = [] >>> c = a[:] # c receives a copy of a, but they are independent >> >> No, the both above are equivalent. Both just bind a name (b or c) to a >> list. This list is in both cases a shallow copy of a. >> >>> >>> >>> ############# 3 ################## >>> d = [] >>> d[:] = a # d receives a copy of a, but they are independent >> >> >> This is a totally different beast. It modifies d in place, no >> rebinding a name. So whover had a refernce to d before, now has a >> changed object, > > I follow all of this up to here, the next sentence is giving me pause > >> whereas in the two cases above, the original lists aren't touched. > > The original list 'a', isn't changed in any of these cases right? And > modifying b, c or d would not change 'a' either - or am I not > understanding this correctly? None of your operations changes a. But I talked about the lists you bound b and c to before. Those aren't changed as well - they simply are not pointed to anymore. In your example, that means the will be garbage-collected, in other scenarios, such as this, the stay: a = [] foo = [] bar = foo assert bar is foo bar = a[:] assert bar is not foo Diez From ebonak at hotmail.com Fri Nov 20 18:58:10 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 20 Nov 2009 18:58:10 -0500 Subject: semantics of [:] In-Reply-To: <7monqaF3icnf3U2@mid.uni-berlin.de> References: <7mnu0tF3itudnU1@mid.uni-berlin.de> <7monqaF3icnf3U2@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Esmail schrieb: > > None of your operations changes a. But I talked about the lists you > bound b and c to before. Those aren't changed as well - they simply are > not pointed to anymore. In your example, that means the will be > garbage-collected, in other scenarios, such as this, the stay: > > a = [] > foo = [] > bar = foo > assert bar is foo > bar = a[:] > assert bar is not foo Got it :-) .. thanks for helping out Diez Esmail From greg.ewing at canterbury.ac.nz Fri Nov 20 19:26:57 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 13:26:57 +1300 Subject: ANN: PyGUI Mailing List Message-ID: There is now a mailing list for discussion of PyGUI: http://mail.python.org/mailman/listinfo/pygui What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From greg.ewing at canterbury.ac.nz Fri Nov 20 19:57:39 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 13:57:39 +1300 Subject: Relative versus absolute paths on Windows In-Reply-To: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <7mos8lF3is0n7U1@mid.individual.net> Jason R. Coombs wrote: > In other words, paths without a drive letter are reported as absolute, > but treated as relative, except in a few special cases. It's not clear what the result ought to be here, since Windows drive-relative paths don't really fit into the unix absolute/relative dichotomy. Arguments could be made either way, and what's right probably depends on the reason you're asking. For cross-platform code, it's probably safest to avoid drive-relative paths altogether -- convert them to fully absolute paths at the earliest opportunity. >>>>ntpath.join('d:\\foo', '\\bar') > > '\\bar' This does seem like a bug, though -- the correct result should really be 'd:\\bar', since that's what you would get if you used the name '\\bar' with 'd:' as your current drive. -- Greg From aahz at pythoncraft.com Fri Nov 20 20:12:36 2009 From: aahz at pythoncraft.com (Aahz) Date: 20 Nov 2009 17:12:36 -0800 Subject: Go versus Brand X Message-ID: Comparing Go to another computer language -- do you recognize it? http://www.cowlark.com/2009-11-15-go/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "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 greg.ewing at canterbury.ac.nz Fri Nov 20 20:16:52 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 21 Nov 2009 14:16:52 +1300 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: <0315a502$0$1327$c3e8da3@news.astraweb.com> References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <0315a502$0$1327$c3e8da3@news.astraweb.com> Message-ID: <7motclF3if17eU1@mid.individual.net> Steven D'Aprano wrote: > On Wed, 18 Nov 2009 18:47:34 -0800, Chris Rebert wrote: > >>Accessor methods are not Pythonic. > > Accessor methods are *usually* not Pythonic, at least not the way they > are commonly used in Java. To elaborate, accessor methods that *only* read and write another, ordinary attribute are completely unnecessary in Python. In that case there is no harm in exposing the underlying attribute directly, because you can always replace it with a property later if you change your mind, without requiring any change in calling code. Also, even when you do need accessor methods, it's more elegant to hide them behind a property than to expect callers to use them directly. It makes the calling code more concise, and allows for changing your mind in the opposite direction. -- Greg From mensanator at aol.com Fri Nov 20 20:40:19 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 20 Nov 2009 17:40:19 -0800 (PST) Subject: Go versus Brand X References: Message-ID: <76168195-defb-4119-bf66-649da83ea306@s31g2000yqs.googlegroups.com> On Nov 20, 7:12?pm, a... at pythoncraft.com (Aahz) wrote: > Comparing Go to another computer language -- do you recognize it? No, it predates my entry into the computer biz. > > http://www.cowlark.com/2009-11-15-go/ > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "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 d.dalton at iinet.net.au Fri Nov 20 20:47:01 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sat, 21 Nov 2009 12:47:01 +1100 Subject: python and web pages In-Reply-To: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> References: <7mkeq7F3ijnhnU1@mid.uni-berlin.de> Message-ID: <20091121014701.GA14070@gwsc.vic.edu.au> On Thu, Nov 19, 2009 at 09:43:50AM +0100, Diez B. Roggisch wrote: > >elinks, links, links2 and do the following. > >1. Open a certain web page and find the first text box on the page, and > >put this text into the form. > >2. Press the submit button, and wait for the result page to load. > >3. Click on the 15th link down the page. > > > >So, how do I do this, can anyone point me to some docs or modules that > >may help out here? > > Use the module "mechanize". It will mimic a browser, and allows you > to navigate to pages, fill in forms & submit them. Well, what seemed a very daunting task at first, proved to be quite easy, after a little bit of research. Thanks very much, I've written my script, and it works correctly, using the mechanize module. Thanks for everyone's help -- Cheers, Dan http://members.iinet.net.au/~ddalton/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From aaron.watters at gmail.com Fri Nov 20 21:05:45 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 20 Nov 2009 18:05:45 -0800 (PST) Subject: python simply not scaleable enough for google? References: <87ljiclmm0.fsf@dpt-info.u-strasbg.fr> <0085c660$0$26916$c3e8da3@news.astraweb.com> Message-ID: <9ece38d9-8052-4703-b4bb-a948f21adca5@m33g2000vbi.googlegroups.com> > Because `language is slow' is meaningless. Yes. Everyone knows java is faster than Python right? But look here: http://gaejava.appspot.com/ (you might want to run it a couple times to see what it does when it is 'warm'). I don't think this is a biased test -- I think the author expected to see Java faster. In my runs Python is usually a bit faster on a majority of these metrics consistently. Why? My guess is the reason is that Python is less bloated than Java so more of it can stay resident on a shared machine whereas big hunks of Java have to be swapped in for every access -- but it's just a guess. By the way: I see this all the time -- for web use Python always seems to be faster than Java in my experience. (With programs that I write: I tend to avoid some of the larger Python web tools available out there and code close to the protocol.) Comparing language platforms using small numeric benchmarks often completely misses the point. -- Aaron Watters http://whiffdoc.appspot.com http://listtree.appspot.com === an apple every 8 hours will keep 3 doctors away. - kliban From sturlamolden at yahoo.no Fri Nov 20 22:45:26 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 20 Nov 2009 19:45:26 -0800 (PST) Subject: python simply not scaleable enough for google? References: Message-ID: On 20 Nov, 22:45, a... at pythoncraft.com (Aahz) wrote: > Are you advocating a high-fiber diet? Only if you are a ruminant. No really... Windows has user-space threads natively. But you must reserve some stack space for them (from virtual memory), which mainly makes them useful on 64 bit systems. From jabronson at gmail.com Sat Nov 21 02:34:15 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 23:34:15 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <63105bbf-7276-4296-ac91-7e2f6ff05007@h10g2000vbm.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Use standard subscripting with slices, and only that, to both get and set. i did this for __delitem__ too, so you can do e.g. del m[:'abc']. > In fact, to emphasize the symmetry of the bijective map, consider > disallowing m[key] as ambiguous and require m[key:] my initial feeling is that i'd prefer to be able to say m[key], the defense being that it's not ambiguous if it's documented, and users who don't like it don't have to use it, while users who do like it won't be alienated. but i am definitely still open to this. > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. except slices aren't hashable. but props for even thinking of that! > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. i went with raising an error for __getitem__(slice(a,b,None)). returning True/False for this usage based on whether a -> b is in the bijection is an interesting idea, but i feel like it complicates things for no good reason: if that's what you wanted to know you'd just ask whether m[a] == b. > But this depends on whether __contains__ only tests keys or is modified to test pairs. i have __contains__ only testing keys, and similarly [i for i in bijection] only gives you the keys, again on the theory that deviating too much from the dict api increases the learning (adoption) curve, so i think we should only do it if it buys us a tremendous usability win. thanks again for your insightful input, i'm pretty psyched about how this is coming along! any further feedback is always welcome. josh From jabronson at gmail.com Sat Nov 21 02:34:15 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Fri, 20 Nov 2009 23:34:15 -0800 (PST) Subject: python bijection References: <46c1419a-4208-441b-a60e-472796ae9b64@v25g2000yqk.googlegroups.com> Message-ID: <63105bbf-7276-4296-ac91-7e2f6ff05007@h10g2000vbm.googlegroups.com> On Nov 20, 3:09?pm, Terry Reedy wrote: > Use standard subscripting with slices, and only that, to both get and set. i did this for __delitem__ too, so you can do e.g. del m[:'abc']. > In fact, to emphasize the symmetry of the bijective map, consider > disallowing m[key] as ambiguous and require m[key:] my initial feeling is that i'd prefer to be able to say m[key], the defense being that it's not ambiguous if it's documented, and users who don't like it don't have to use it, while users who do like it won't be alienated. but i am definitely still open to this. > Note that m[slice(1,2,3):] passes slice(slice(1, 2, 3), None, None), so > this approach does not even prevent using slices as keys/values. except slices aren't hashable. but props for even thinking of that! > In __setitem__, m[a:b] which passes slice(a,b,None) would have to be an > error. In __getitem__, it could either be a error or return True/False > depending on whether the pair is in the map. i went with raising an error for __getitem__(slice(a,b,None)). returning True/False for this usage based on whether a -> b is in the bijection is an interesting idea, but i feel like it complicates things for no good reason: if that's what you wanted to know you'd just ask whether m[a] == b. > But this depends on whether __contains__ only tests keys or is modified to test pairs. i have __contains__ only testing keys, and similarly [i for i in bijection] only gives you the keys, again on the theory that deviating too much from the dict api increases the learning (adoption) curve, so i think we should only do it if it buys us a tremendous usability win. thanks again for your insightful input, i'm pretty psyched about how this is coming along! any further feedback is always welcome. josh From steve at REMOVE-THIS-cybersource.com.au Sat Nov 21 03:12:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2009 08:12:51 GMT Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: <03178ef5$0$1379$c3e8da3@news.astraweb.com> On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote: > MRAB wrote: >> u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a >> visible "CR" graphic) for carriage return. Windows programs normally >> expect lines to end with '\r\n'; just use u'\n' in programs and open >> the text files in text mode ('r' or 'w'). > > > This is the one thing from standards that I believe Microsoft got right > where others did not. Oh please, that's historical revisionism -- \r\n wasn't invented by Microsoft. Microsoft didn't "get it right", they simply copied what CP/M did, on account of the original MS-DOS being essentially a clone of CP/M. And of course the use of \r\n predates computers -- CR+LF (Carriage Return + LineFeed) were necessary to instruct the print head on teletype printers to move down one line and return to the left. It was a physical necessity for the oldest computer operating systems, because the only printers available were teletypes. > The ASCII (American Standard for Information > Interchange) standard end of line is _both_ carriage return (\r) _and_ > line feed (\n) I doubt that very much. Do you have a reference for this? It is true that the predecessor to ANSI (not ASCII), ASA, specified \r\n as the line terminator, but ISO specified that both \n and \r\n should be accepted. > I believe in that order. You "believe" in that order? But you're not sure? That's the trouble with \r\n, or \n\r -- it's an arbitrary choice, and therefore hard to remember which it is. I've even seen proprietary business-to-business software where the developers (apparently) couldn't remember which was the standard, so when exporting data to text, you had to choose which to use for line breaks. Of course, being Windows software, they didn't think that you might want to transfer the text file to a Unix system, or a Mac, and so didn't offer \n or \r alone as line terminators. > The Unix operating system, in its enthusiasm to make _everything_ > simpler (against Einstein's advice, "Everything should be made as simple > as possible, but not simpler.") decided that end-of-line should be a > simple line feed and not carriage return line feed. Why is it "too simple" to have line breaks be a single character? What is the downside of the Unix way? Why is \r\n "better"? We're not using teletypes any more. Or for that matter, classic Mac OS, which used a single \r as newline. Likewise for other OSes, such as Commodore, Amiga, Multics... > Before they made > that decision, there was debate about the order of cr-lf or lf-cr, or > inventing a new EOL character ('\037' == '\x1F' was the candidate). IBM operating systems that use EBCDIC used the NEL (NExt Line) character for line breaks, keeping CR and LF for other uses. The Unicode standard also specifies that any of the following be recognised as line separators or terminators: LF, CR, CR+LF, NEL, FF (FormFeed, \f), LS (LineSeparator, U+2028) and PS (ParagraphSeparator, U+2029). > If you've actually typed on a physical typewriter, you know that moving > the carriage back is a distinct operation from rolling the platen > forward; I haven't typed on a physical typewriter for nearly a quarter of a century. If you've typed on a physical typewriter, you'll know that to start a new page, you have to roll the platen forward until the page ejects, then move the typewriter guide forward to leave space, then feed a new piece of paper into the typewriter by hand, then roll the platen again until the page is under the guide, then push the guide back down again. That's FIVE distinct actions, and if you failed to do them, you would type but no letters would appear on the (non-existent) page. Perhaps we should specify that text files need a five-character sequence to specify a new page too? > both operations are accomplished when you push the carriage > back using the bar, but you know they are distinct. Hell, MIT even had > "line starve" character that moved the cursor up (or rolled the platen > back). > > > Lots of people talk about "dos-mode files" and "windows files" as if > Microsoft got it wrong; it did not -- Unix made up a convenient fiction > and people went along with it. (And, yes, if Unix had been there first, > their convention was, in fact, better). This makes zero sense. If Microsoft "got it right", then why is the Unix convention "convenient" and "better"? Since we're not using teletype machines, I would say Microsoft is now using an *inconvenient* fiction. -- Steven From "knutjbj(nospam)" at online.no Sat Nov 21 03:25:38 2009 From: "knutjbj(nospam)" at online.no (nospam) Date: Sat, 21 Nov 2009 09:25:38 +0100 Subject: extending dictonary Message-ID: Is there any way to extend the dictonary in such manner that I can insert muliplay value to each keys and return one of the value as the default value. I would like to have similar syste that I drawed out below. tree[nucelotide_postionc][nucleotide]=default(value subtree) This should be returned when doing lookup without any tree[nucelotide_postionc][nucleotide]=Postive value tree[nucelotide_postionc][nucleotide]=Negative value From sturlamolden at yahoo.no Sat Nov 21 04:48:44 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 21 Nov 2009 01:48:44 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> Message-ID: <595c7dca-7715-4081-8a5b-a47b1ed78bdf@d10g2000yqh.googlegroups.com> On 21 Nov, 09:12, Steven D'Aprano wrote: > Oh please, that's historical revisionism -- \r\n wasn't invented by > Microsoft. Microsoft didn't "get it right", they simply copied what CP/M > did, on account of the original MS-DOS being essentially a clone of CP/M. Actyually \r\n goes back to early mechanical typewriters with typebars, such as the Hermes. The operator would hit CR to return the paper carriage and LF to move down to the next line. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 21 04:50:28 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Nov 2009 09:50:28 GMT Subject: extending dictonary References: Message-ID: <0317a5d6$0$1379$c3e8da3@news.astraweb.com> On Sat, 21 Nov 2009 09:25:38 +0100, nospam wrote: > Is there any way to extend the dictonary in such manner that I can > insert muliplay value to each keys and return one of the value as the > default value. I would like to have similar syste that I drawed out > below. > > > tree[nucelotide_postionc][nucleotide]=default(value subtree) This should > be returned when doing lookup without any > tree[nucelotide_postionc][nucleotide]=Postive value > tree[nucelotide_postionc][nucleotide]=Negative value I'm sorry, I don't understand what you are asking. What are tree, nucelotide_postionc, nucleotide, subtree? What are positive value and negative value? If each key has multiple values, how do you want to specify which value to return? The simplest way to associate multiple values with a key is to use a list: >>> d = {} >>> d['a'] = [2, 3, 4] >>> d['b'] = [5, 6] >>> d['a'].append(0) >>> d {'a': [2, 3, 4, 0], 'b': [5, 6]} If you like, you can take the convention that the first item in the list is the default, and write this: >>> print d['b'][0] 5 -- Steven From sturlamolden at yahoo.no Sat Nov 21 04:59:09 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 21 Nov 2009 01:59:09 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: On 21 Nov, 08:10, Dennis Lee Bieber wrote: > ? ? ? ? Of course, if you are describing a /real/ /manual/ typewriter, you > would rapidly discover that the sequence is -- since pushing > the bar would often trigger the line feed before it would slide the > carriage to the right. > > ? ? ? ? But on a teletype, it would be , and maybe a few > for timing -- as the was the slower operation, and would complete > while the other characters were operated upon... Ah, yes you are right :-) The sequence is on a typewriter. Which is why the RETURN button often had the symbol | <----| From highcar at gmail.com Sat Nov 21 06:49:36 2009 From: highcar at gmail.com (elca) Date: Sat, 21 Nov 2009 03:49:36 -0800 (PST) Subject: DOM related question and problem In-Reply-To: <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> References: <26412730.post@talk.nabble.com> <4b064b7c$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <26455800.post@talk.nabble.com> Stefan Behnel-3 wrote: > > elca, 18.11.2009 19:04: >> these day im making python script related with DOM. >> >> problem is these day many website structure is very complicate . >> [...] >> what is best method to check can extract such like following info >> quickly? > > This should help: > > http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciated-web-scraping-library/ > > Stefan > -- > http://mail.python.org/mailman/listinfo/python-list > > hello yes..i know this website already. but failed to use it lxml solution -- View this message in context: http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26455800.html Sent from the Python - python-list mailing list archive at Nabble.com. From lyarmulka at gmail.com Sat Nov 21 07:44:02 2009 From: lyarmulka at gmail.com (someone) Date: Sat, 21 Nov 2009 04:44:02 -0800 (PST) Subject: How do I print to text browser with Qthread? (in PyQt) Message-ID: <9aa71ac7-9ab9-4903-ae23-caf564814b3f@37g2000yqm.googlegroups.com> Hello, I wrote Qthread that gets in the constructor a textBrowser from PyQt application and I tryed to print in this widget text that is updated each 5 seconds (Like application that counts numbers of the text brouser) Is anyone can explain me how to do this? I would glad if you can attach a code example. thanks someone From victorsubervi at gmail.com Sat Nov 21 08:19:52 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 08:19:52 -0500 Subject: Problem w/ smtplib Message-ID: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Hi; I get the following error: /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py 52 session.sendmail(clientEmail, ourEmail1, header+msg) 53 # session.sendmail(clientEmail, ourEmail2, header+msg) 54 55 mailSpreadsheet() 56 *mailSpreadsheet* = /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet *() 47 order += 'TOTAL: $' + str(total) 48 msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) 49 session = smtplib.SMTP("localhost") 50 session.login(user, passwd) # only if it requires auth 51 header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject session *undefined*, *global* *smtplib* = , smtplib.*SMTP* = /usr/lib64/python2.4/smtplib.py in *__init__*(self=, host='localhost', port=0, local_hostname=None) 242 self.esmtp_features = {} 243 if host: 244 (code, msg) = self.connect(host, port) 245 if code != 220: 246 raise SMTPConnectError(code, msg) code *undefined*, msg *undefined*, *self* = , self.* connect* = >, *host* = 'localhost', *port* = 0 /usr/lib64/python2.4/smtplib.py in *connect*(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* = , self.*getreply* = > /usr/lib64/python2.4/smtplib.py in *getreply*(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) *global* *SMTPServerDisconnected* = * SMTPServerDisconnected*: Connection unexpectedly closed args = ('Connection unexpectedly closed',) Why did this connection close? How do I fix it? I tried commenting out the authentication line. I have imported smtplib. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From aaron.bobby1 at gmail.com Sat Nov 21 08:44:07 2009 From: aaron.bobby1 at gmail.com (Bobby) Date: Sat, 21 Nov 2009 05:44:07 -0800 (PST) Subject: python server developer Message-ID: <1ece1b55-63b7-43dc-a6ca-fbed83062346@u18g2000pro.googlegroups.com> Hello, We are looking for Python server developer location : Hyderabad Experience : 3 years . Send me your updated resume with availability for Telephonic interview From victorsubervi at gmail.com Sat Nov 21 08:47:14 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 08:47:14 -0500 Subject: crontab problem Message-ID: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> Hi; I have the following in crontab -eu root: @daily /usr/local/bin/mysql-backup-daily.sh @weekly /usr/local/bin/mysql-backup-weekly.sh @monthly /usr/local/bin/mysql-backup-monthly.sh [root at 13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-* /usr/local/bin/mysql-daily.sh /usr/local/bin/mysql-monthly.sh /usr/local/bin/mysql-weekly.sh These scripts worked on another server. The daily writes to: /usr/backup/database/mysql-backups/mysql-backup-dailys/ However, a day later, nothing is there. Please advise. TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From jebagnanadas at gmail.com Sat Nov 21 08:47:56 2009 From: jebagnanadas at gmail.com (Jebagnana Das) Date: Sat, 21 Nov 2009 19:17:56 +0530 Subject: problem with pyqt.. help please... Message-ID: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> Hi friends, I've recently changed to ubuntu 9.04.. I've not had any problem with the installation of pyqt as it is available from the ubuntu repositories with umpteen number of packages.. Anyhow i've to download tarball file for python 3.1 and installed it.. I found that PyQt4 supports python 3.1(Am i right?).. I wanted to check the pyqt installation with a sample program.. import sys from PyQt4 import QtGui app=QtGui.QApplication(sys.argv) widget=QtGui.QWidget() widget.resize(250,150) widget.setWindowTitle('Simple') widget.show() sys.exit(app.exec_()) when i issued the command $python simple.py it worked perfectly since it's executed with 2.6 installation.. But when i tried to execute it with $python3 simple.py it showed the error like ImportError: No module named PyQt4 So i searched the sys.path for 2.6 and included /usr/lib/python2.6/dist-packages in python3 sys.path... Now when i tried to run this with python3 the error is like.. ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined symbol: PyString_FromString I got the same error when i tried to execute another program... So can u please tell me how to solve this problem?? Am i heading in the right direction???... Thanks & Regards... Jebagnanadas, Python Learner.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Nov 21 08:59:04 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 Nov 2009 05:59:04 -0800 Subject: crontab problem In-Reply-To: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> References: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> Message-ID: <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> On Sat, Nov 21, 2009 at 5:47 AM, Victor Subervi wrote: > Hi; > I have the following in crontab -eu root: > @daily /usr/local/bin/mysql-backup-daily.sh > @weekly /usr/local/bin/mysql-backup-weekly.sh > @monthly /usr/local/bin/mysql-backup-monthly.sh > > [root at 13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-* > /usr/local/bin/mysql-daily.sh? /usr/local/bin/mysql-monthly.sh > /usr/local/bin/mysql-weekly.sh > > These scripts worked on another server. The daily writes to: > /usr/backup/database/mysql-backups/mysql-backup-dailys/ > However, a day later, nothing is there. Please advise. And this is germane to Python (and not instead say, *nix) how exactly? Cheers, Chris -- http://blog.rebertia.com From benjamin.kaplan at case.edu Sat Nov 21 09:05:00 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 21 Nov 2009 09:05:00 -0500 Subject: problem with pyqt.. help please... In-Reply-To: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> References: <5ff1e7d40911210547t377d565ci797751e51ea10352@mail.gmail.com> Message-ID: On Sat, Nov 21, 2009 at 8:47 AM, Jebagnana Das wrote: > Hi friends, > I've recently changed to ubuntu 9.04.. I've not had any > problem with the installation of pyqt as it is available from the ubuntu > repositories with umpteen number of packages.. Anyhow i've to download > tarball file for python 3.1 and installed it.. I found that PyQt4 supports > python 3.1(Am i right?).. > > I wanted to check the pyqt installation with a sample program.. > > import sys > from PyQt4 import QtGui > app=QtGui.QApplication(sys.argv) > widget=QtGui.QWidget() > widget.resize(250,150) > widget.setWindowTitle('Simple') > widget.show() > sys.exit(app.exec_()) > > when i issued the command > $python simple.py > it worked perfectly since it's executed with 2.6 installation.. > But when i tried to execute it with > $python3 simple.py > it showed the error like > ImportError: No module named PyQt4 > So i searched the sys.path for 2.6 and included > /usr/lib/python2.6/dist-packages > in python3 sys.path... > Now when i tried to run this with python3 the error is like.. > ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined > symbol: PyString_FromString > I got the same error when i tried to execute another program... So can u > please tell me how to solve this problem?? Am i heading in the right > direction???... > > Thanks & Regards... > > Jebagnanadas, > Python Learner.. > > As a general rule, never add packages that were installed for another version of Python . There are inconsistencies between versions, so the C libraries (like PyQT) always need to be recompiled. This is especially true between Python 2.x and Python 3.x, where there were some fundamental changes to the language. If you want to use PyQT on Python 3, download it and compile it yourself. > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 09:08:34 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 09:08:34 -0500 Subject: crontab problem In-Reply-To: <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> References: <4dc0cfea0911210547v7fe5cc83j4c7eb39854b8e619@mail.gmail.com> <50697b2c0911210559r1b0cbdd6r22b80859dc840272@mail.gmail.com> Message-ID: <4dc0cfea0911210608o32f933c7gb8b5165c92ce94e8@mail.gmail.com> On Sat, Nov 21, 2009 at 8:59 AM, Chris Rebert wrote: > > And this is germane to Python (and not instead say, *nix) how exactly? > Oops! Wrong list! -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 09:27:21 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 09:27:21 -0500 Subject: Too Many Values To Unpack In-Reply-To: References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> Message-ID: <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber wrote: > And my follow-up to that original thread stated that it /was/ > pseudo-code, not something tested. My goal was to illustrate the > general concepts of processing a recursive/nested data set stored in a > flat/relational table. > Of course and appreciated. > > "expand()" was responsible for taking each "key" from a select query > and creating an empty dictionary with that "key" as, well, key. Then the > recursive operation would perform a select query used to populate the > empty dictionary, ad infinitum. > Here is the output with just one test category: {'cat1': {}} Here is the code to which that output is fed: def getChildren(levelDict, level = 0): MAXLEVEL = 7 if level > MAXLEVEL: return #possibly the data has a cycle/loop for (nm, dt) in levelDict: cursor.execute('''select c.name from categories as c inner join relationship as r on c.ID = r.Child inner join categories as p on r.Parent = p.ID where p.category = %s order by c.name''', (nm,)) levelDict[nm] = expand(cursor.fetchall()) # recursive call to do next level getChildren(levelDict[nm], level + 1) # no data return as we are mutating dictionaries in place When this script is called from another script, the python interpreter throws the following error: Traceback (most recent call last): File "createCats.py", line 8, in ? from catTree import catTree File "/var/www/html/angrynates.com/cart/catTree.py", line 85, in ? catTree() File "/var/www/html/angrynates.com/cart/catTree.py", line 76, in catTree getChildren(theTree) File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in getChildren for (nm, dt) in levelDict: ValueError: too many values to unpack Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From joost at h-labahn.de Sat Nov 21 11:21:26 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 21 Nov 2009 08:21:26 -0800 (PST) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> Message-ID: <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Sorry, i have no idea what scrapy is - but i see, that you try to use idle with pipes or anything like that. That cannot work. idle doesn't even handle __file__ correctly. Use a full-fledged python IDE (PyDev under Eclipse leaves very few wishes open) or test in a python interpreter shell. Good luck, DreiJane From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sat Nov 21 11:49:52 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sat, 21 Nov 2009 16:49:52 +0000 (UTC) Subject: python server developer References: <1ece1b55-63b7-43dc-a6ca-fbed83062346@u18g2000pro.googlegroups.com> Message-ID: Bobby wrote: > Hello, > We are looking for Python server developer > location : Hyderabad > Experience : 3 years . > Send me your updated resume with availability for Telephonic interview Hyderabad, India or Hyderabad, Pakistan? (no, I am not going to apply in either case, even if I think I do qualify - I already have a nice, reasonably python related job). -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From kevin.p.dwyer at gmail.com Sat Nov 21 12:04:32 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 21 Nov 2009 17:04:32 +0000 (UTC) Subject: Problem w/ smtplib References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Message-ID: On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: Hello Victor, The information that you have sent comes from the client side of the transaction, so it isn't possible to tell why the server disconnected. Assuming that there is an SMTP server listening on port 25, you need to check the SMTP server logs. You might need to crank up the logging to get useful output. If the information that you pasted in comes from a Django traceback then you could check the Django page on e-mail at http://docs.djangoproject.com/en/dev/topics/email/#topics-email (dev version, you might need to view an older version). Cheers, Kev From victorsubervi at gmail.com Sat Nov 21 12:27:26 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 12:27:26 -0500 Subject: Problem w/ smtplib In-Reply-To: References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> Message-ID: <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: > On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: > > Hello Victor, > > The information that you have sent comes from the client side of the > transaction, so it isn't possible to tell why the server disconnected. > Assuming that there is an SMTP server listening on port 25, you need to > check the SMTP server logs. There wasn't anything in /var/log/maillog. Is that where I should have checked? > You might need to crank up the logging to > get useful output. > How? Look at the output below: [root at 13gems stcroixresort]# netstat -tulp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 *:mysql *:* LISTEN 24488/mysqld tcp 0 0 *:pop3 *:* LISTEN 5278/tcpserver tcp 0 0 *:ftp *:* LISTEN 26564/vsftpd tcp 0 0 localhost.localdomai:domain *:* LISTEN 11845/named tcp 0 0 *:smtp *:* LISTEN 5274/tcpserver tcp 0 0 localhost.localdomain:rndc *:* LISTEN 11845/named tcp 0 0 *:http *:* LISTEN 5201/httpd tcp 0 0 localhost:domain *:* LISTEN 11845/named tcp 0 0 *:ssh *:* LISTEN 15509/sshd tcp 0 0 localhost:rndc *:* LISTEN 11845/named udp 0 0 localhost.locald:domain *:* 11845/named udp 0 0 localhost:domain *:* 11845/named [root at 13gems stcroixresort]# qmailctl stat /service/qmail-send: up (pid 5266) 594565 seconds /service/qmail-send/log: up (pid 5271) 594565 seconds /service/qmail-smtpd: up (pid 5274) 594565 seconds /service/qmail-smtpd/log: up (pid 5276) 594565 seconds /service/qmail-pop3d: up (pid 5278) 594565 seconds /service/qmail-pop3d/log: up (pid 5279) 594565 seconds messages in queue: 0 messages in queue but not yet preprocessed: 0 Please advise. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sat Nov 21 13:16:52 2009 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 21 Nov 2009 18:16:52 +0000 Subject: Problem w/ smtplib In-Reply-To: <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> Message-ID: <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> 2009/11/21 Victor Subervi > On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: > >> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: >> >> Hello Victor, >> >> The information that you have sent comes from the client side of the >> transaction, so it isn't possible to tell why the server disconnected. >> Assuming that there is an SMTP server listening on port 25, you need to >> check the SMTP server logs. > > > There wasn't anything in /var/log/maillog. Is that where I should have > checked? > > >> You might need to crank up the logging to >> get useful output. >> > > How? > Look at the output below: > > [root at 13gems stcroixresort]# netstat -tulp > Active Internet connections (only servers) > Proto Recv-Q Send-Q Local Address Foreign Address > State PID/Program name > tcp 0 0 *:mysql *:* > LISTEN 24488/mysqld > tcp 0 0 *:pop3 *:* > LISTEN 5278/tcpserver > tcp 0 0 *:ftp *:* > LISTEN 26564/vsftpd > tcp 0 0 localhost.localdomai:domain *:* > LISTEN 11845/named > tcp 0 0 *:smtp *:* > LISTEN 5274/tcpserver > tcp 0 0 localhost.localdomain:rndc *:* > LISTEN 11845/named > tcp 0 0 *:http *:* > LISTEN 5201/httpd > tcp 0 0 localhost:domain *:* > LISTEN 11845/named > tcp 0 0 *:ssh *:* > LISTEN 15509/sshd > tcp 0 0 localhost:rndc *:* > LISTEN 11845/named > udp 0 0 localhost.locald:domain > *:* 11845/named > udp 0 0 localhost:domain > *:* 11845/named > [root at 13gems stcroixresort]# qmailctl stat > /service/qmail-send: up (pid 5266) 594565 seconds > /service/qmail-send/log: up (pid 5271) 594565 seconds > /service/qmail-smtpd: up (pid 5274) 594565 seconds > /service/qmail-smtpd/log: up (pid 5276) 594565 seconds > /service/qmail-pop3d: up (pid 5278) 594565 seconds > /service/qmail-pop3d/log: up (pid 5279) 594565 seconds > messages in queue: 0 > messages in queue but not yet preprocessed: 0 > > Please advise. > TIA, > V > Hello Victor, I'm afraid I don't know much about mail servers, you need to check the server docs or ask on a qmail mailing list. If you really think this is a python issue, then you could try: >>> import smtplib >>> server = smtplib.SMTP() >>> server.set_debuglevel(1) >>> server.connect() connect: ('localhost', 25) connect: (25, 'localhost') reply: '220 pluto.site ESMTP Postfix\r\n' reply: retcode (220); Msg: pluto.site ESMTP Postfix connect: pluto.site ESMTP Postfix (220, 'pluto.site ESMTP Postfix') >>> server.quit() send: 'quit\r\n' reply: '221 2.0.0 Bye\r\n' reply: retcode (221); Msg: 2.0.0 Bye (221, '2.0.0 Bye') and see if there are any error messages/tracebacks in the output; but if you still get a disconnect exception then it's unlikely that this is a python issue. Cheers, Kev -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sat Nov 21 13:59:13 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 21 Nov 2009 13:59:13 -0500 Subject: Problem w/ smtplib In-Reply-To: <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> References: <4dc0cfea0911210519s28ff1e13i9fa2f145519003e5@mail.gmail.com> <4dc0cfea0911210927h3ff43cecsadb556d39ecfb99c@mail.gmail.com> <4d3439f90911211016p4fccebcer268502d1b5e49119@mail.gmail.com> Message-ID: <4dc0cfea0911211059h787b5815oecc90c1d1fe561f@mail.gmail.com> On Sat, Nov 21, 2009 at 1:16 PM, Kev Dwyer wrote: > > 2009/11/21 Victor Subervi > > On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote: >> >>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote: >>> >>> Hello Victor, >>> >>> The information that you have sent comes from the client side of the >>> transaction, so it isn't possible to tell why the server disconnected. >>> Assuming that there is an SMTP server listening on port 25, you need to >>> check the SMTP server logs. >> >> >> There wasn't anything in /var/log/maillog. Is that where I should have >> checked? >> >> >>> You might need to crank up the logging to >>> get useful output. >>> >> >> How? >> Look at the output below: >> >> [root at 13gems stcroixresort]# netstat -tulp >> Active Internet connections (only servers) >> Proto Recv-Q Send-Q Local Address Foreign >> Address State PID/Program name >> tcp 0 0 *:mysql >> *:* LISTEN 24488/mysqld >> tcp 0 0 *:pop3 >> *:* LISTEN 5278/tcpserver >> tcp 0 0 *:ftp >> *:* LISTEN 26564/vsftpd >> tcp 0 0 localhost.localdomai:domain >> *:* LISTEN 11845/named >> tcp 0 0 *:smtp >> *:* LISTEN 5274/tcpserver >> tcp 0 0 localhost.localdomain:rndc >> *:* LISTEN 11845/named >> tcp 0 0 *:http >> *:* LISTEN 5201/httpd >> tcp 0 0 localhost:domain >> *:* LISTEN 11845/named >> tcp 0 0 *:ssh >> *:* LISTEN 15509/sshd >> tcp 0 0 localhost:rndc >> *:* LISTEN 11845/named >> udp 0 0 localhost.locald:domain >> *:* 11845/named >> udp 0 0 localhost:domain >> *:* 11845/named >> [root at 13gems stcroixresort]# qmailctl stat >> /service/qmail-send: up (pid 5266) 594565 seconds >> /service/qmail-send/log: up (pid 5271) 594565 seconds >> /service/qmail-smtpd: up (pid 5274) 594565 seconds >> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds >> /service/qmail-pop3d: up (pid 5278) 594565 seconds >> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds >> messages in queue: 0 >> messages in queue but not yet preprocessed: 0 >> >> Please advise. >> TIA, >> V >> > > Hello Victor, > > I'm afraid I don't know much about mail servers, you need to check the > server docs or ask on a qmail mailing list. > > If you really think this is a python issue, then you could try: > >>> import smtplib > >>> server = smtplib.SMTP() > >>> server.set_debuglevel(1) > >>> server.connect() > connect: ('localhost', 25) > connect: (25, 'localhost') > reply: '220 pluto.site ESMTP Postfix\r\n' > reply: retcode (220); Msg: pluto.site ESMTP Postfix > connect: pluto.site ESMTP Postfix > (220, 'pluto.site ESMTP Postfix') > >>> server.quit() > send: 'quit\r\n' > reply: '221 2.0.0 Bye\r\n' > reply: retcode (221); Msg: 2.0.0 Bye > (221, '2.0.0 Bye') > > > and see if there are any error messages/tracebacks in the output; but if > you still get a disconnect exception then it's unlikely that this is a > python issue. > Thank you. Yes, there was an error. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From azeynel1 at gmail.com Sat Nov 21 14:00:58 2009 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 21 Nov 2009 11:00:58 -0800 (PST) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Message-ID: Now I use EditpadPro and IDLE which appears to be adequate for beginning level. But PyDev looks fun, I'll try it. By the way, I realized that the spider sends the scraped data to the pipelines.py. Now everything is working. On Nov 21, 11:21?am, DreiJane wrote: > Sorry, > > i have no idea what scrapy is - but i see, that you try to use > idle with pipes or anything like that. That cannot work. > idle doesn't even handle __file__ correctly. Use a full-fledged > python IDE (PyDev under Eclipse leaves very few wishes open) or > test in a python interpreter shell. > > Good luck, DreiJane From mrholtsr at sbcglobal.net Sat Nov 21 14:10:20 2009 From: mrholtsr at sbcglobal.net (Ray Holt) Date: Sat, 21 Nov 2009 14:10:20 -0500 Subject: pythonpath Message-ID: Is there a way to make python point to a different directory for modules. I don't like to keep my modules in the program directory, but I can't figure out from the shell how to get the program to look in another directory. I am using XP Pro as an operating system and python2.6 -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Sat Nov 21 14:10:47 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sat, 21 Nov 2009 19:10:47 +0000 (UTC) Subject: Newbie question about scrapy tutorial References: <1d285ba2-0cbe-48f9-a298-8b398166627a@j11g2000vbi.googlegroups.com> <213a7fb7-51fc-4103-8e52-a9d83c420b8f@k4g2000yqb.googlegroups.com> Message-ID: > i have no idea what scrapy is > .... http://scrapy.org/ Scrapy is a fast high-level screen scraping and web crawling framework, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from data mining to monitoring and automated testing. Also, previously unknown to me before google-izing .... -- Stanley C. Kitching Human Being Phoenix, Arizona From dadapapa at googlemail.com Sat Nov 21 14:19:02 2009 From: dadapapa at googlemail.com (Harold Fellermann) Date: Sat, 21 Nov 2009 11:19:02 -0800 (PST) Subject: Problem combining Scientific (leastSquaresFit) and scipy (odeint) Message-ID: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> Hi, I need to perform leastSquaresFit of a model that is given by a differential equation for which there seems to be no analytic solution. So, I am trying to solve the ODE numerically (using scipy.integrate.odeint) within the function I provide to leastSquaresFit as a model: def func(L, t, a, k) : return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.) def model((k, L0, a), t) : solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) ) return L0 - solution[1][0] params, chisq = leastSquaresFit(model, params, data) Unfortunately, this approach runs into an error (ValueError: shape mismatch: objects cannot be broadcast to a single shape) that seems to stem from the fact that leastSquaresFit is based on automatic derivation (DerivVar), and according to the manual "the function [that defines the model] may only use the mathematical functions known to the module FirstDerivatives". What is a good solution or workaround to this problem which appears to be quite a standard situation to me? Thanks for any help, harold. From johnroth1 at gmail.com Sat Nov 21 14:20:51 2009 From: johnroth1 at gmail.com (John Roth) Date: Sat, 21 Nov 2009 11:20:51 -0800 (PST) Subject: Go versus Brand X References: Message-ID: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> On Nov 21, 8:40?am, Duncan Booth wrote: > a... at pythoncraft.com (Aahz) wrote: > > Comparing Go to another computer language -- do you recognize it? > > >http://www.cowlark.com/2009-11-15-go/ > > Yes, spotted it at the first 'fi'. This isn't the first time anyone has criticized Go. The interesting, and somewhat sad, thing is that the entire mess can be explained very easily by looking at the beginning of the language design FAQ on the Go web site. See if you recognize the names of the principle people who designed it. Yep. Go is simply C with most (but not all) of the warts removed and some more modern features added. Brought to you by the same people who brought you C and Unix all those years ago. The use of the Plan 9 toolchain is not a coincidence. John Roth From nobody at nowhere.com Sat Nov 21 14:22:36 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 21 Nov 2009 19:22:36 +0000 Subject: python simply not scaleable enough for google? References: Message-ID: On Fri, 20 Nov 2009 09:51:49 -0800, sturlamolden wrote: > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. POSIX.1-2001 and POSIX.1-2004 have makecontext(), setcontext(), getcontext() and swapcontext(), but obsoleted by POSIX.1-2008. They are available on Linux; I don't know about other Unices. From nobody at nowhere.com Sat Nov 21 14:44:39 2009 From: nobody at nowhere.com (Nobody) Date: Sat, 21 Nov 2009 19:44:39 +0000 Subject: Go versus Brand X References: Message-ID: On Fri, 20 Nov 2009 17:12:36 -0800, Aahz wrote: > Comparing Go to another computer language -- do you recognize it? "Here is a language so far ahead of its time that it was not only an improvement on its predecessors but also on nearly all its successors." - C. A. R. Hoare (although he was actually referring to ALGOL-60). From yota.news at gmail.com Sat Nov 21 14:44:57 2009 From: yota.news at gmail.com (yota.news at gmail.com) Date: Sat, 21 Nov 2009 11:44:57 -0800 (PST) Subject: memoize again Message-ID: I spent a lot of time looking for tips on how to properly write cache / memoize function. Testing, merging and fixing contributed but half finished pieces of code. Here is the summary of what I learned through a clean example, might it be useful for beginners. #!/usr/bin/env python3.1 (should work in python 2.5) def dcache(function) : """ simple, dict based cache """ return memoize(function, cache={}) def ccache(cache = {}): """ with dict-like custom cache. Can be any class with at least __contains__, __setitem__ and __getitem__ methods """ def xcache(function): return memoize(function, cache=cache) return xcache class memoize(object): def __init__(self, function, cache): self.function=function self.cache=cache def __get__(self, instance, cls=None): self.instance = instance return self def __call__(self, *args): if args not in self.cache: self.cache[args] = self.function(self.instance, *args) return self.cache[args] which can be used as this: - with the custom cache @ccache(cache=customCache()) def compute(self, alpha, beta): return alpha + beta - or with a default dict() cache @dcache def compute(self, alpha, beta): return alpha + beta Each time compute() is called, the memoize decorator looks first into the cache for a value whose key is the *args tuple. The full content of the cache can be acessed as compute.cache. ~? From rnichols at mightyheave.com Sat Nov 21 15:49:23 2009 From: rnichols at mightyheave.com (rnichols at mightyheave.com) Date: Sat, 21 Nov 2009 14:49:23 -0600 (CST) Subject: How do I create a vanilla object in C? Message-ID: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> I need to create a vanilla object in C, something I can do PyObject_SetAttr on. Obviously, I do something somewhat like this every time I create a minimal python class. I need to know how to do this in C though. From bnrj.rudra at gmail.com Sat Nov 21 16:24:24 2009 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 21 Nov 2009 13:24:24 -0800 (PST) Subject: plotting arrow in python Message-ID: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Dear friends, I am very new in python. Actually, I think I will not do much python then using it to plotting data. I have not done any "real" thing in python, so plz be easy. Now , the problem I have a data set: 0.0 0.0 0.1 0.0 0.1 0.1 0.1 0.0 0.5 like that! the first two column are coordinate and 3rd one is magnitude of moment (say: x y,m)!! so what i want to do is draw an arrow of magnitude(m) in the position (x,y). I know how python read array, and how to draw an array(via matplotlib)...but totally confused with this one. can you people plz help? From carsten.haese at gmail.com Sat Nov 21 16:41:04 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Sat, 21 Nov 2009 16:41:04 -0500 Subject: Too Many Values To Unpack In-Reply-To: <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: Victor Subervi wrote: > File "/var/www/html/angrynates.com/cart/catTree.py > ", line 25, in getChildren > for (nm, dt) in levelDict: > ValueError: too many values to unpack > > Please advise. I already explained what's causing this error. Read my first response on this thread. (http://mail.python.org/pipermail/python-list/2009-November/1227008.html) -- Carsten Haese http://informixdb.sourceforge.net From mmanns at gmx.net Sat Nov 21 17:39:29 2009 From: mmanns at gmx.net (Martin Manns) Date: Sat, 21 Nov 2009 23:39:29 +0100 Subject: pyspread 0.0.12a released Message-ID: Pyspread is getting close to the first Beta. This new release should work with Windows as well as with Linux. About ----- Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Pyspread runs on Linux, Windows and *nix platforms with GTK+ support. I have reports that it works with MacOS X as well. Homepage -------- http://pyspread.sf.net New features in 0.0.12a ----------------------- * pys file support more secure * ODF file support removed * Left and right alignment to cell attributes added * Custom grid & cell drawing on refresh added * Save functionality for row and column size added * Problem with update of cells that contain strings, lists solved * Frozen cells toolbar update fixed * Windows missing cell background bug removed Martin From acangiano at gmail.com Sat Nov 21 17:53:53 2009 From: acangiano at gmail.com (Antonio Cangiano) Date: Sat, 21 Nov 2009 14:53:53 -0800 (PST) Subject: Are you happy with the current web deployment options? Message-ID: Phusion is a Dutch company that vastly improved the status quo of Ruby and Rails deployment through their open source module for Apache and nginx. Now they are publicly asking whether Pythonistas would be interested in a similar solution for Python (and Django of course). Not many Pythonistas read their Ruby-oriented blog, so I thought I'd share the link here: http://izumi.plan99.net/blog/index.php/2009/11/21/phusion-passenger-for-python/ Cheers, Antonio -- http://ThinkCode.TV - High-quality programming screencasts http://antoniocangiano.com - Zen and the Art of Programming Follow me on Twitter: http://twitter.com/acangiano Author of "Ruby on Rails for Microsoft Developers" (Wrox, 2009) From stef.mientki at gmail.com Sat Nov 21 18:19:55 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 22 Nov 2009 00:19:55 +0100 Subject: plotting arrow in python In-Reply-To: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <4B08759B.90109@gmail.com> rudra wrote: > Dear friends, > I am very new in python. Actually, I think I will not do much python > then using it to plotting data. I have not done any "real" thing in > python, so plz be easy. Now , the problem > I have a data set: > 0.0 0.0 0.1 > 0.0 0.1 0.1 > 0.1 0.0 0.5 > > like that! the first two column are coordinate and 3rd one is > magnitude of moment (say: x y,m)!! so what i want to do is draw an > arrow of magnitude(m) in the position (x,y). > I know how python read array, and how to draw an array(via > matplotlib)...but totally confused with this one. > can you people plz help? > maybe take a look at VPython cheers, Stef From cjwilliams43 at gmail.com Sat Nov 21 18:22:48 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sat, 21 Nov 2009 18:22:48 -0500 Subject: Problem combining Scientific (leastSquaresFit) and scipy (odeint) In-Reply-To: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> References: <0cb05db3-cbf5-4e5c-a46d-0cd3efe6a4ad@w19g2000yqk.googlegroups.com> Message-ID: Harold Fellermann wrote: > Hi, > > I need to perform leastSquaresFit of a model that is given by a > differential equation for which there seems to be no analytic > solution. So, I am trying to solve the ODE numerically (using > scipy.integrate.odeint) within the function I provide to > leastSquaresFit as a model: > > def func(L, t, a, k) : > return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.) > > def model((k, L0, a), t) : > solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) ) > return L0 - solution[1][0] > > params, chisq = leastSquaresFit(model, params, data) > > Unfortunately, this approach runs into an error (ValueError: shape > mismatch: objects cannot be broadcast to a single shape) that seems to > stem from the fact that leastSquaresFit is based on automatic > derivation (DerivVar), and according to the manual "the function [that > defines the model] may only use the mathematical functions known to > the module FirstDerivatives". > > What is a good solution or workaround to this problem which appears to > be quite a standard situation to me? > > Thanks for any help, harold. You might consider using numpy. Colin W. From showell30 at yahoo.com Sat Nov 21 18:23:26 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 15:23:26 -0800 (PST) Subject: parallel class structures for AST-based objects Message-ID: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> I have been writing some code that parses a mini-language, and I am running into what I know is a pretty common design pattern problem, but I am wondering the most Pythonic way to solve it. Basically, I have a bunch of really simple classes that work together to define an expression--in my oversimplified example code below, those are Integer, Sum, and Product. Then I want to write different modules that work with those expression objects. In my example, I have a parallel set of classes that enable you to evaluate an expression, and another set of objects that enable you to pretty-print the expression. The below code works as intended so far (tested under 2.6), but before I go too much further with this design, I want to get a sanity check and some ideas on other ways to represent the interrelationships within the code. Basically, the issue here is that you have varying behavior in two dimensions--a node right now is only a Product/Integer/ Sum so far, but I might want to introduce new concepts like Difference, Quotient, etc. And right now the only things that you can do to expressions is eval() them and pprint() them, but you eventually might want to operate on the expressions in new ways, including fairly abstract operations that go beyond a simple walking of the tree. Here is the code: ####### # base classes just represents the expression itself, which # get created by a parser or unit tests # example usage is # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) class Integer: def __init__(self, val): self.val = val class BinaryOp: def __init__(self, a,b): self.a = a self.b = b class Sum(BinaryOp): pass class Product(BinaryOp): pass ######## class EvalNode: def __init__(self, node): self.node = node def evaluatechild(self, child): return EvalNode.factory(child).eval() @staticmethod def factory(child): mapper = { 'Sum': SumEvalNode, 'Product': ProductEvalNode, 'Integer': IntegerEvalNode } return abstract_factory(child, mapper) class SumEvalNode(EvalNode): def eval(self): a = self.evaluatechild(self.node.a) b = self.evaluatechild(self.node.b) return a + b class ProductEvalNode(EvalNode): def eval(self): a = self.evaluatechild(self.node.a) b = self.evaluatechild(self.node.b) return a * b class IntegerEvalNode(EvalNode): def eval(self): return self.node.val ####### class PrettyPrintNode: def __init__(self, node): self.node = node def pprint_child(self, child): return PrettyPrintNode.factory(child).pprint() @staticmethod def factory(child): mapper = { 'Sum': SumPrettyPrintNode, 'Product': ProductPrettyPrintNode, 'Integer': IntegerPrettyPrintNode } return abstract_factory(child, mapper) class SumPrettyPrintNode(PrettyPrintNode): def pprint(self): a = self.pprint_child(self.node.a) b = self.pprint_child(self.node.b) return '(the sum of %s and %s)' % (a, b) class ProductPrettyPrintNode(PrettyPrintNode): def pprint(self): a = self.pprint_child(self.node.a) b = self.pprint_child(self.node.b) return '(the product of %s and %s)' % (a, b) class IntegerPrettyPrintNode(PrettyPrintNode): def pprint(self): return self.node.val ############## # Not sure where this method really "wants to be" structurally, # or what it should be named, but it reduces some duplication def abstract_factory(node, node_class_mapper): return node_class_mapper[node.__class__.__name__](node) expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) evaluator = EvalNode.factory(expression) print evaluator.eval() pprinter = PrettyPrintNode.factory(expression) print pprinter.pprint() From tjreedy at udel.edu Sat Nov 21 18:24:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 Nov 2009 18:24:19 -0500 Subject: ANN: PyGUI Mailing List In-Reply-To: References: Message-ID: Gregory Ewing wrote: > There is now a mailing list for discussion of PyGUI: > > http://mail.python.org/mailman/listinfo/pygui Having it mirrored to news.gmane,org, if you have not yet, like other python.org lists, would make it easier to follow or join. Perhaps it will happen automatically, I do not know. From python at mrabarnett.plus.com Sat Nov 21 19:07:05 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 00:07:05 +0000 Subject: parallel class structures for AST-based objects In-Reply-To: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <4B0880A9.4080101@mrabarnett.plus.com> Steve Howell wrote: > I have been writing some code that parses a mini-language, and I am > running into what I know is a pretty common design pattern problem, > but I am wondering the most Pythonic way to solve it. > > Basically, I have a bunch of really simple classes that work together > to define an expression--in my oversimplified example code below, > those are Integer, Sum, and Product. > > Then I want to write different modules that work with those expression > objects. In my example, I have a parallel set of classes that enable > you to evaluate an expression, and another set of objects that enable > you to pretty-print the expression. > > The below code works as intended so far (tested under 2.6), but before > I go too much further with this design, I want to get a sanity check > and some ideas on other ways to represent the interrelationships > within the code. Basically, the issue here is that you have varying > behavior in two dimensions--a node right now is only a Product/Integer/ > Sum so far, but I might want to introduce new concepts like > Difference, Quotient, etc. And right now the only things that you can > do to expressions is eval() them and pprint() them, but you eventually > might want to operate on the expressions in new ways, including fairly > abstract operations that go beyond a simple walking of the tree. > > Here is the code: > > ####### > # base classes just represents the expression itself, which > # get created by a parser or unit tests > # example usage is > # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > class Integer: > def __init__(self, val): > self.val = val > > class BinaryOp: > def __init__(self, a,b): > self.a = a > self.b = b > > class Sum(BinaryOp): > pass > > class Product(BinaryOp): > pass > > ######## > > class EvalNode: > def __init__(self, node): > self.node = node > > def evaluatechild(self, child): > return EvalNode.factory(child).eval() > > @staticmethod > def factory(child): > mapper = { > 'Sum': SumEvalNode, > 'Product': ProductEvalNode, > 'Integer': IntegerEvalNode > } > return abstract_factory(child, mapper) > > class SumEvalNode(EvalNode): > def eval(self): > a = self.evaluatechild(self.node.a) > b = self.evaluatechild(self.node.b) > return a + b > > class ProductEvalNode(EvalNode): > def eval(self): > a = self.evaluatechild(self.node.a) > b = self.evaluatechild(self.node.b) > return a * b > > class IntegerEvalNode(EvalNode): > def eval(self): return self.node.val > > ####### > > class PrettyPrintNode: > def __init__(self, node): > self.node = node > > def pprint_child(self, child): > return PrettyPrintNode.factory(child).pprint() > > @staticmethod > def factory(child): > mapper = { > 'Sum': SumPrettyPrintNode, > 'Product': ProductPrettyPrintNode, > 'Integer': IntegerPrettyPrintNode > } > return abstract_factory(child, mapper) > > class SumPrettyPrintNode(PrettyPrintNode): > def pprint(self): > a = self.pprint_child(self.node.a) > b = self.pprint_child(self.node.b) > return '(the sum of %s and %s)' % (a, b) > > class ProductPrettyPrintNode(PrettyPrintNode): > def pprint(self): > a = self.pprint_child(self.node.a) > b = self.pprint_child(self.node.b) > return '(the product of %s and %s)' % (a, b) > > class IntegerPrettyPrintNode(PrettyPrintNode): > def pprint(self): return self.node.val > > ############## > # Not sure where this method really "wants to be" structurally, > # or what it should be named, but it reduces some duplication > > def abstract_factory(node, node_class_mapper): > return node_class_mapper[node.__class__.__name__](node) > > > expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > evaluator = EvalNode.factory(expression) > print evaluator.eval() > > pprinter = PrettyPrintNode.factory(expression) > print pprinter.pprint() I don't see the point of EvalNode and PrettyPrintNode. Why don't you just give Integer, Sum and Product 'eval' and 'pprint' methods? From showell30 at yahoo.com Sat Nov 21 19:11:36 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 16:11:36 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: On Nov 21, 11:20?am, John Roth wrote: > On Nov 21, 8:40?am, Duncan Booth wrote: > > > a... at pythoncraft.com (Aahz) wrote: > > > Comparing Go to another computer language -- do you recognize it? > > > >http://www.cowlark.com/2009-11-15-go/ > > > Yes, spotted it at the first 'fi'. > > This isn't the first time anyone has criticized Go. The interesting, > and somewhat sad, thing is that the entire mess can be explained > very easily by looking at the beginning of the language design > FAQ on the Go web site. See if you recognize the names of the > principle people who designed it. > > Yep. Go is simply C with most (but not all) of the warts > removed and some more modern features added. Brought to you > by the same people who brought you C and Unix all those years ago. > The use of the Plan 9 toolchain is not a coincidence. > The assertion that Go is simply C with warts removed and modern features added is not surprising. If you read the Go FAQ, you will see that there is no claim anywhere that they are trying to solve the problem that 40 years of language development since Algol has not produced super-sexy quantum leaps of improvement. Instead, they are trying to solve the problem that in the last ten years, there haven not seen ANY improvement in systems programming languages ("No major systems language has emerged in over a decade"). The critics of Go probably fall into four categories: 1) Some do not understand the goals of the Go project itself, so they are criticizing Go for not solving problems that were never in Go's bailiwick to begin with. 2) Some believe that Go does not deliver on its goal to modernize systems programming languages. 3) Some do not accept the premise that there has been no progress outside of Go in the last ten years with regards to systems programming languages, and they are wondering why Google invented Go instead of embracing other technologies. 4) Some people do not even believe that the problem is important--do we actually need a modern systems programming language, or do we just need modern programming languages to perform well under all circumstances, or at least be adaptable? My list probably isn't even nearly exhaustive. From showell30 at yahoo.com Sat Nov 21 19:18:47 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 16:18:47 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> On Nov 21, 4:07?pm, MRAB wrote: > > I don't see the point of EvalNode and PrettyPrintNode. Why don't you > just give Integer, Sum and Product 'eval' and 'pprint' methods? That's a good question, and it's the crux of my design dilemma. If ALL I ever wanted to to with Integer/Sum/Product was to eval() and pprint(), then I would just add those methods to Integer, Sum, and Product, and be done with it, as you suggest. But what happens when somebody wants to extend capability? Should every future software developer that wants to use Integer/Sum/Product extend those classes to get work done? What if they want to store additional state for nodes? From fetchinson at googlemail.com Sat Nov 21 19:21:47 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 22 Nov 2009 01:21:47 +0100 Subject: How do I create a vanilla object in C? In-Reply-To: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> References: <58873.212.189.46.155.1258836563.squirrel@www.mightyheave.com> Message-ID: > I need to create a vanilla object in C, something I can do > PyObject_SetAttr on. Obviously, I do something somewhat like this every > time I create a minimal python class. I need to know how to do this in C > though. Please see http://docs.python.org/extending/index.html http://docs.python.org/c-api/index.html http://docs.python.org/c-api/object.html HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chardster at gmail.com Sat Nov 21 19:33:28 2009 From: chardster at gmail.com (Richard Thomas) Date: Sat, 21 Nov 2009 16:33:28 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> Message-ID: <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> On 22 Nov, 00:07, MRAB wrote: > Steve Howell wrote: > > I have been writing some code that parses a mini-language, and I am > > running into what I know is a pretty common design pattern problem, > > but I am wondering the most Pythonic way to solve it. > > > Basically, I have a bunch of really simple classes that work together > > to define an expression--in my oversimplified example code below, > > those are Integer, Sum, and Product. > > > Then I want to write different modules that work with those expression > > objects. ?In my example, I have a parallel set of classes that enable > > you to evaluate an expression, and another set of objects that enable > > you to pretty-print the expression. > > > The below code works as intended so far (tested under 2.6), but before > > I go too much further with this design, I want to get a sanity check > > and some ideas on other ways to represent the interrelationships > > within the code. ?Basically, the issue here is that you have varying > > behavior in two dimensions--a node right now is only a Product/Integer/ > > Sum so far, but I might want to introduce new concepts like > > Difference, Quotient, etc. ?And right now the only things that you can > > do to expressions is eval() them and pprint() them, but you eventually > > might want to operate on the expressions in new ways, including fairly > > abstract operations that go beyond a simple walking of the tree. > > > Here is the code: > > > ? ? ####### > > ? ? # base classes just represents the expression itself, which > > ? ? # get created by a parser or unit tests > > ? ? # example usage is > > ? ? # expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > ? ? class Integer: > > ? ? ? ? def __init__(self, val): > > ? ? ? ? ? ? self.val = val > > > ? ? class BinaryOp: > > ? ? ? ? def __init__(self, a,b): > > ? ? ? ? ? ? self.a = a > > ? ? ? ? ? ? self.b = b > > > ? ? class Sum(BinaryOp): > > ? ? ? ? pass > > > ? ? class Product(BinaryOp): > > ? ? ? ? pass > > > ? ? ######## > > > ? ? class EvalNode: > > ? ? ? ? def __init__(self, node): > > ? ? ? ? ? ? self.node = node > > > ? ? ? ? def evaluatechild(self, child): > > ? ? ? ? ? ? return EvalNode.factory(child).eval() > > > ? ? ? ? @staticmethod > > ? ? ? ? def factory(child): > > ? ? ? ? ? ? mapper = { > > ? ? ? ? ? ? ? ? 'Sum': SumEvalNode, > > ? ? ? ? ? ? ? ? 'Product': ProductEvalNode, > > ? ? ? ? ? ? ? ? 'Integer': IntegerEvalNode > > ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? return abstract_factory(child, mapper) > > > ? ? class SumEvalNode(EvalNode): > > ? ? ? ? def eval(self): > > ? ? ? ? ? ? a = self.evaluatechild(self.node.a) > > ? ? ? ? ? ? b = self.evaluatechild(self.node.b) > > ? ? ? ? ? ? return a + b > > > ? ? class ProductEvalNode(EvalNode): > > ? ? ? ? def eval(self): > > ? ? ? ? ? ? a = self.evaluatechild(self.node.a) > > ? ? ? ? ? ? b = self.evaluatechild(self.node.b) > > ? ? ? ? ? ? return a * b > > > ? ? class IntegerEvalNode(EvalNode): > > ? ? ? ? def eval(self): return self.node.val > > > ? ? ####### > > > ? ? class PrettyPrintNode: > > ? ? ? ? def __init__(self, node): > > ? ? ? ? ? ? self.node = node > > > ? ? ? ? def pprint_child(self, child): > > ? ? ? ? ? ? return PrettyPrintNode.factory(child).pprint() > > > ? ? ? ? @staticmethod > > ? ? ? ? def factory(child): > > ? ? ? ? ? ? mapper = { > > ? ? ? ? ? ? ? ? 'Sum': SumPrettyPrintNode, > > ? ? ? ? ? ? ? ? 'Product': ProductPrettyPrintNode, > > ? ? ? ? ? ? ? ? 'Integer': IntegerPrettyPrintNode > > ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? return abstract_factory(child, mapper) > > > ? ? class SumPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): > > ? ? ? ? ? ? a = self.pprint_child(self.node.a) > > ? ? ? ? ? ? b = self.pprint_child(self.node.b) > > ? ? ? ? ? ? return '(the sum of %s and %s)' % (a, b) > > > ? ? class ProductPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): > > ? ? ? ? ? ? a = self.pprint_child(self.node.a) > > ? ? ? ? ? ? b = self.pprint_child(self.node.b) > > ? ? ? ? ? ? return '(the product of %s and %s)' % (a, b) > > > ? ? class IntegerPrettyPrintNode(PrettyPrintNode): > > ? ? ? ? def pprint(self): return self.node.val > > > ? ? ############## > > ? ? # Not sure where this method really "wants to be" structurally, > > ? ? # or what it should be named, but it reduces some duplication > > > ? ? def abstract_factory(node, node_class_mapper): > > ? ? ? ? return node_class_mapper[node.__class__.__name__](node) > > > ? ? expression = Product(Sum(Integer(5),Integer(2)), Integer(6)) > > > ? ? evaluator = EvalNode.factory(expression) > > ? ? print evaluator.eval() > > > ? ? pprinter = PrettyPrintNode.factory(expression) > > ? ? print pprinter.pprint() > > I don't see the point of EvalNode and PrettyPrintNode. Why don't you > just give Integer, Sum and Product 'eval' and 'pprint' methods? This looks more structurally sound: class Node(object): def eval(self): raise NotImplementedError def pprint(self): raise NotImplementedError class BinaryOperatorNode(Node): operator = None def __init__(self, first, second): self.first = first self.second = second def eval(self): return self.operator(self.first.eval(), self.second.eval()) def pprint(self): "%s(%s, %s)" % (type(self).__name__, self.first.pprint(), self.second.pprint()) class Sum(BinaryOperatorNode): operator = lambda x, y: x + y class Product(BinaryOperatorNode): operator = lambda x, y: x * y I don't know what you're doing exactly but if all you need is to be able to parse and evaluate expressions then you can get very decent mileage out of overriding operators, to the extent that the whole thing you are trying to do could be a single class: class Expression(object): def __init__(self, func): self.func = func def __call__(self, **context): while isinstance(self, Expression): self = self.func(context) return self def __add__(self, other): return Expression(lambda context: self.func(context) + other) def __mul__(self, other): return Expression(lambda context: self.func(context) * other) def __radd__(self, other): return Expression(lambda context: other + self.func(context)) def __rmul__(self, other): return Expression(lambda context: other * self.func(context)) # ... and so forth ... def integer(value): return Expression(lambda context: value) def variable(name, default): return Expression(lambda context: context.get(name, default)) X = Expression("X", 0) expr = 2 * X + 1 assert expr(X=3) == 7 But maybe that's not what you need. No need to overengineer if it is though, keep it simple, simple is better than complex. From showell30 at yahoo.com Sat Nov 21 20:19:46 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 17:19:46 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> Message-ID: <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> On Nov 21, 4:33?pm, Richard Thomas wrote: > > This looks more structurally sound: > > class Node(object): > ? ?def eval(self): > ? ? ? raise NotImplementedError > ? ?def pprint(self): > ? ? ? raise NotImplementedError > My objection to the interface you describe is that Node defines the type of operations that can be done to it by third-party code, which is something that I cannot predict, and which (pscouples every subclass of Node to eval() and pprint(), even though those subclasses might not care about either operation. They might be reimplementing only one of those operations, or some completely different operation. > > class Sum(BinaryOperatorNode): > ? ?operator = lambda x, y: x + y > > class Product(BinaryOperatorNode): > ? ?operator = lambda x, y: x * y > I do like the notion of driving up Sum/Product abstractions like "operator" into BinaryOperatorNode, but that is sort of an artifact of my toy example, not my main design dilemma. > I don't know what you're doing exactly but if all you need is to be > able to parse and evaluate expressions then you can get very decent > mileage out of overriding operators, to the extent that the whole > thing you are trying to do could be a single class... > > class Expression(object): > def __init__(self, func): > self.func = func > def __call__(self, **context): > while isinstance(self, Expression): > self = self.func(context) > return self > def __add__(self, other): > return Expression(lambda context: self.func(context) + other) > def __mul__(self, other): > [snipped] It is my fault for muddying the conversation with a toy example that evaluates arithmetic expressions. My particular problem involves a mini-language that describes how you want to descend Python data structures. > But maybe that's not what you need. No need to overengineer if it is > though, keep it simple, simple is better than complex. Yep! I am trying to keep things simple, but my wish to extend is not speculative at this point; it is real. I have an expression syntax, which I call pyDTL, that I want these operations on: * generate two different versions of Python code that expresses the operation * eagerly evaluate the expression on some object * pretty-print the expression itself * use the expression as a prototype for stub objects to determine what operations they allow * etc.... All of those requirements create the need to somehow create new objects or functions that correspond to the same AST. I describe pyDTL here: http://showellonprogramming.blogspot.com/2009/11/mini-ddl-for-python.html Here is a simple example: echo '{.foo, .bar(){.spam, .eggs} }' | python dtl/parse.py dict( foo = obj.foo, bar = (lambda bar: dict( spam = bar.spam, eggs = bar.eggs, ))(obj.bar()), ) ### From lie.1296 at gmail.com Sat Nov 21 20:36:01 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 22 Nov 2009 12:36:01 +1100 Subject: plotting arrow in python In-Reply-To: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <4b0895d7$1@dnews.tpgi.com.au> rudra wrote: > Dear friends, > I am very new in python. Actually, I think I will not do much python > then using it to plotting data. I have not done any "real" thing in > python, so plz be easy. Now , the problem > I have a data set: > 0.0 0.0 0.1 > 0.0 0.1 0.1 > 0.1 0.0 0.5 > > like that! the first two column are coordinate and 3rd one is > magnitude of moment (say: x y,m)!! so what i want to do is draw an > arrow of magnitude(m) in the position (x,y). > I know how python read array, and how to draw an array(via > matplotlib)...but totally confused with this one. > can you people plz help? If you want to stay with regular python distribution, take a look on pygame (http://www.pygame.org/ ). If you want to avoid 3rd party modules, take a look at turtle and Tkinter in the standard library. From showell30 at yahoo.com Sat Nov 21 20:48:48 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 21 Nov 2009 17:48:48 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> Message-ID: <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> On Nov 21, 12:12?am, Steven D'Aprano wrote: > On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote: > > > If you've actually typed on a physical typewriter, you know that moving > > the carriage back is a distinct operation from rolling the platen > > forward; > > I haven't typed on a physical typewriter for nearly a quarter of a > century. > > If you've typed on a physical typewriter, you'll know that to start a new > page, you have to roll the platen forward until the page ejects, then > move the typewriter guide forward to leave space, then feed a new piece > of paper into the typewriter by hand, then roll the platen again until > the page is under the guide, then push the guide back down again. That's > FIVE distinct actions, and if you failed to do them, you would type but > no letters would appear on the (non-existent) page. Perhaps we should > specify that text files need a five-character sequence to specify a new > page too? > > > both operations are accomplished when you push the carriage > > back using the bar, but you know they are distinct. ?Hell, MIT even had > > "line starve" character that moved the cursor up (or rolled the platen > > back). > > > > > Lots of people talk about "dos-mode files" and "windows files" as if > > Microsoft got it wrong; it did not -- Unix made up a convenient fiction > > and people went along with it. (And, yes, if Unix had been there first, > > their convention was, in fact, better). > > This makes zero sense. If Microsoft "got it right", then why is the Unix > convention "convenient" and "better"? Since we're not using teletype > machines, I would say Microsoft is now using an *inconvenient* fiction. > > -- > Steven It's been a long time since I have typed on a physical typewriter as well, but I still vaguely remember all the crazy things I had to do to get the tab key to produce a predictable indentation on the paper output. I agree with Steven that "\r\n" is completely insane. If you are going to couple character sets to their legacy physical implementations, you should also have a special extra character to dot your i's and cross your t's. Apparently neither Unix or Microsoft got that right. I mean, think about it, dotting the i is a distinct operation from creating the undotted "i." ;) From davea at ieee.org Sat Nov 21 20:58:14 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 21 Nov 2009 20:58:14 -0500 Subject: pythonpath In-Reply-To: References: Message-ID: <4B089AB6.20803@ieee.org> Ray Holt wrote: > Is there a way to make python point to a different directory for modules. I > don't like to keep my modules in the program directory, but I can't figure > out from the shell how to get the program to look in another directory. I am > using XP Pro as an operating system and python2.6 > > There are a few standard places that Python already looks for module imports. To see what they are on your system, you could simply look at sys.path. import sys for path in sys.path: print path In particular, you probably want to use the directory under appdata: C:\Documents and Settings\XXXX\Application Data\Python\Python26\site-packages where XXXX is your user-name. DaveA From rt8396 at gmail.com Sat Nov 21 21:01:53 2009 From: rt8396 at gmail.com (r) Date: Sat, 21 Nov 2009 18:01:53 -0800 (PST) Subject: plotting arrow in python References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> <4b0895d7$1@dnews.tpgi.com.au> Message-ID: On Nov 21, 7:36?pm, Lie Ryan wrote: (..snip..) > If you want to avoid 3rd party modules, take a look at turtle and > Tkinter in the standard library. Just to add to Ryans words... If you want to avoid 3rd party modules, take a look at turtle and the Tkinter *Canvas* widget in the standard library. Here is an example. #-- start code --# try: import Tkinter as tk except ImportError: import tkinter as tk #python 3+ app = tk.Tk() canvas = tk.Canvas(app) canvas.create_line(0,0, 50,50, arrow='last') canvas.pack() app.mainloop() #-- end code --# remove the try/except when you know which one to use. I just wanted to make sure it ran out-the-box for you, have fun! From python at rcn.com Sat Nov 21 21:22:30 2009 From: python at rcn.com (Raymond Hettinger) Date: Sat, 21 Nov 2009 18:22:30 -0800 (PST) Subject: python bijection References: Message-ID: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> On Nov 19, 3:24?pm, Joshua Bronson wrote: > I couldn't find a library providing a bijective map data structure > (allowing for constant-time lookups by value) in the few minutes I > looked, so I took a few more minutes to code one up:http://bitbucket.org/jab/toys/src/tip/bijection.py > > Is this at all worth releasing? Comments and suggestions welcome. > > Josh Hello Joshua, I have a few design ideas and comments for you. * The idea of using __call__ for looking-up inverse values was inspired. That is useable, clean, and easy to remember; however, as discussed below, there are issues though with its actual use in real code. * Am not excited by the inverse iterators. With just a regular mapping you can write: for a, b in m.items() ... # consider either a or b be the key and the other to be the value That meets all of the needs that would have been served by iter_inverse_keys() or iter_inverse_values() or whatnot. The mirrored API doesn't really provide much in the way of value added. * After exercising the API on a couple of samples, I'm worried that almost any inverse-method based API makes it difficult to review code while keeping straight the intended meaning of the forward and inverse relationships. Am thinking that it is simpler, faster, and clearer to just use two dictionaries -- that approach lets the variable names communicate the important info. For example, the following code helps keep the coder and code reviewer from conflating the forward and inverse directions: myurl = ip2url[myip] myip = url2ip[myurl] Contrast that with: myurl = site_bijection[myip] myip = site_bijection(myurl) With the latter, it is darned difficult to detect accidental conflation of brackets with parentheses. * So, I'm thinking that code needing a bijection would be better-off with two ordinary dicts, perhaps augmented by a couple of convenience functions: biject_add(site_bijection, ip=myip, url=myurl) # Create a new pairing, raise ValueError if either key # maps to more than one value (in violation of the # bijection invariant: one-to-one and onto) biject_remove(ip=myip) # Clear an entry from both dicts or biject_remove(url=myurl) Alternatively, another possible approach is to used use the class generation approach (such as that used by named_tuple()) to generate a custom bijection class with either attribute based or keyworded accessors: Attribute based accessors: site = Bijection('ip', 'url') site.url[myip] = myurl for ip, url in site.items() ... print site.ip[myurl] myurl = site.url.pop(myip) Keyword accessors: site = Bijection('ip', 'url') site.set(ip=myip, url=myurl) myurl = site.get(ip=myip) myip = set.get(url=myurl) myurl = site.pop(ip=myip) site.del(ip=myip) site.del(url=myurl) Hope these ideas help. The ultimate success of the Bijection code will depend on its clarity, simplicity, and speed. Experiment with various approaches to find-out which looks the best in real code. It cannot be error-prone or it is doomed. Also, it should not introduce much overhead processing or else people will avoid it. The API should be trivially simple so that people remember how to use it months after seeing it for the first time. Good luck and happy hunting, Raymond From ivoras at gmail.com Sat Nov 21 21:43:31 2009 From: ivoras at gmail.com (Ivan Voras) Date: Sun, 22 Nov 2009 03:43:31 +0100 Subject: Imitating "tail -f" Message-ID: I'm trying to simply imitate what "tail -f" does, i.e. read a file, wait until it's appended to and process the new data, but apparently I'm missing something. The code is: 54 f = file(filename, "r", 1) 55 f.seek(-1000, os.SEEK_END) 56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL) 57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK) 58 59 pe = select.poll() 60 pe.register(f) 61 while True: 62 print repr(f.read()) 63 print pe.poll(1000) The problem is: poll() always returns that the fd is ready (without waiting), but read() always returns an empty string. Actually, it doesn't matter if I turn O_NDELAY on or off. select() does the same. Any advice? From mensanator at aol.com Sat Nov 21 21:51:39 2009 From: mensanator at aol.com (Mensanator) Date: Sat, 21 Nov 2009 18:51:39 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: <8b2bec1b-59e1-4f54-a115-e56aaa9dd120@w19g2000yqk.googlegroups.com> On Nov 21, 6:11?pm, Steve Howell wrote: > On Nov 21, 11:20?am, John Roth wrote: > > > > > > > On Nov 21, 8:40?am, Duncan Booth wrote: > > > > a... at pythoncraft.com (Aahz) wrote: > > > > Comparing Go to another computer language -- do you recognize it? > > > > >http://www.cowlark.com/2009-11-15-go/ > > > > Yes, spotted it at the first 'fi'. > > > This isn't the first time anyone has criticized Go. The interesting, > > and somewhat sad, thing is that the entire mess can be explained > > very easily by looking at the beginning of the language design > > FAQ on the Go web site. See if you recognize the names of the > > principle people who designed it. > > > Yep. Go is simply C with most (but not all) of the warts > > removed and some more modern features added. Brought to you > > by the same people who brought you C and Unix all those years ago. > > The use of the Plan 9 toolchain is not a coincidence. > > The assertion that Go is simply C with warts removed and modern > features added is not surprising. > > If you read the Go FAQ, you will see that there is no claim anywhere > that they are trying to solve the problem that 40 years of language > development since Algol has not produced super-sexy quantum leaps of > improvement. ?Instead, they are trying to solve the problem that in > the last ten years, there haven not seen ANY improvement in systems > programming languages ("No major systems language has emerged in over > a decade"). ?The critics of Go probably fall into four categories: > > ? 1) Some do not understand the goals of the Go project itself, so > they are criticizing Go for not solving problems that were never in > Go's bailiwick to begin with. > ? 2) Some believe that Go does not deliver on its goal to modernize > systems programming languages. > ? 3) Some do not accept the premise that there has been no progress > outside of Go in the last ten years with regards to systems > programming languages, and they are wondering why Google invented Go > instead of embracing other technologies. > ? 4) Some people do not even believe that the problem is important--do > we actually need a modern systems programming language, or do we just > need modern programming languages to perform well under all > circumstances, or at least be adaptable? > > My list probably isn't even nearly exhaustive. Like those who think Python programmers would be interedted in Go because it has an import statement. From pavlovevidence at gmail.com Sat Nov 21 22:05:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 21 Nov 2009 19:05:30 -0800 (PST) Subject: How do I create a vanilla object in C? References: Message-ID: <6617094f-6c01-4997-998c-032da4797c88@x31g2000yqx.googlegroups.com> On Nov 21, 12:49?pm, rnich... at mightyheave.com wrote: > I need to create a vanilla object in C, something I can do > PyObject_SetAttr on. ?Obviously, I do something somewhat like this every > time I create a minimal python class. ?I need to know how to do this in C > though. First of all, if you don't need to share this object with any Python code, then I'd suggest you just use a dict (create with PyDict_New). If you do need to share it with Python, one thing to consider is whether it isn't easier to create the object in Python and pass it to the C code. If these suggestions aren't suitable, then you'll have to create a new vanilla type, then create an instance of that type. Unfortunately it's not too convenient from C. It's easy enough to define types and C (see the C-API documentation), but in order to use PyObject_SetAttr on it you'll have to make sure the type has a dictionary, so you'd have to set the tp_dictoffset member to the offset of your dict in the Python structure. Another thing you can do is to call type directly (as you can do in Python) with the name, bases, dict, as in the following example (error checking and reference counting omitted): name = PyString_FromString("vanilla"); bases = PyTuple_New(0); dict = PyDict_New(); vanilla_type = PyObject_CallObject( &PyType_Type,name,bases,dict,0); Then call the vanilla type (however you create it) to get a vanilla object: vanilla_object = PyObject_CallObject(vanilla_type,0); Definitely not the most straightforward thing to do from C. Carl Banks From exarkun at twistedmatrix.com Sat Nov 21 23:10:02 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 22 Nov 2009 04:10:02 -0000 Subject: Imitating "tail -f" In-Reply-To: References: Message-ID: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> On 02:43 am, ivoras at gmail.com wrote: >I'm trying to simply imitate what "tail -f" does, i.e. read a file, >wait >until it's appended to and process the new data, but apparently I'm >missing something. > >The code is: > >54 f = file(filename, "r", 1) >55 f.seek(-1000, os.SEEK_END) >56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL) >57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK) >58 >59 pe = select.poll() >60 pe.register(f) >61 while True: >62 print repr(f.read()) >63 print pe.poll(1000) > >The problem is: poll() always returns that the fd is ready (without >waiting), but read() always returns an empty string. Actually, it >doesn't matter if I turn O_NDELAY on or off. select() does the same. > >Any advice? select(), poll(), epoll, etc. all have the problem where they don't support files (in the thing-on-a-filesystem sense) at all. They just indicate the descriptor is readable or writeable all the time, regardless. "tail -f" is implemented by sleeping a little bit and then reading to see if there's anything new. Jean-Paul From jasonsewall at gmail.com Sat Nov 21 23:32:16 2009 From: jasonsewall at gmail.com (Jason Sewall) Date: Sat, 21 Nov 2009 23:32:16 -0500 Subject: Imitating "tail -f" In-Reply-To: <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> Message-ID: <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> FWIW, GNU tail on Linux uses inotify for tail -f: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c The wikipedia page for inotify lists several python bindings: http://en.wikipedia.org/wiki/Inotify Not much help for non-Linux users, but there it is. Too bad, because inotify is pretty cool. Jason On Nov 21, 2009 11:11 PM, wrote: On 02:43 am, ivoras at gmail.com wrote: > > I'm trying to simply imitate what "tail -f" does, i.e. read... select(), poll(), epoll, etc. all have the problem where they don't support files (in the thing-on-a-filesystem sense) at all. They just indicate the descriptor is readable or writeable all the time, regardless. "tail -f" is implemented by sleeping a little bit and then reading to see if there's anything new. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sun Nov 22 00:19:49 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 18:19:49 +1300 Subject: Too Many Values To Unpack In-Reply-To: References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: <7ms008F3ibrvmU1@mid.individual.net> Dennis Lee Bieber wrote: > I apparently thought "for ... in dictionary" would return (key, > value) pairs, but it appears that it only returns the key itself -- and > a single key can't be unpacked. > > Misleading error... too many /targets/ to unpack... My guess is that the keys are strings, which means it's unpacking them into characters, in which case a key of length 3 or more will produce that message. -- Greg From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 00:37:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 05:37:17 GMT Subject: Too Many Values To Unpack References: <4dc0cfea0911200745o242049aawe07c3f7d5aa9a69@mail.gmail.com> <332972a20911200814o30bfc8bfgc5069fe1120ae629@mail.gmail.com> <4dc0cfea0911200913t1d90701dpac79f9d26b20da99@mail.gmail.com> <4dc0cfea0911210627r399e59f7v306a1e31352eabf1@mail.gmail.com> Message-ID: <0318bbfb$0$1336$c3e8da3@news.astraweb.com> On Sat, 21 Nov 2009 21:06:08 -0800, Dennis Lee Bieber wrote: > I apparently thought "for ... in dictionary" would return (key, > value) pairs, but it appears that it only returns the key itself -- and > a single key can't be unpacked. > > Misleading error... too many /targets/ to unpack... No, the error is fine. >>> for x, y in {1:'a'}: ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: unpack non-sequence >>> >>> for x, y in {'a':1}: ... pass ... Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack >>> >>> for x, y in {'parrot':1}: ... pass ... Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack Strings are iterable, and so unpack into individual characters. -- Steven From greg.ewing at canterbury.ac.nz Sun Nov 22 00:58:50 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 18:58:50 +1300 Subject: plotting arrow in python In-Reply-To: References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> Message-ID: <7ms299F3jvhbiU1@mid.individual.net> > rudra wrote: > >> 0.0 0.0 0.1 >> 0.0 0.1 0.1 >> 0.1 0.0 0.5 >> >> like that! the first two column are coordinate and 3rd one is >> magnitude of moment (say: x y,m)!! so what i want to do is draw an >> arrow of magnitude(m) in the position (x,y). There seems to be some information missing there. How do you know what direction to draw the arrow in? -- Greg From sergiomb at sapo.pt Sun Nov 22 01:15:01 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Sun, 22 Nov 2009 06:15:01 +0000 Subject: python setup.py build 32-bits on x86_64 machine Message-ID: <4b08d6e9$0$28097$a729d347@news.telepac.pt> Hi, I am in x86_64 arch , but I need compile things on 32 bits. python setup.py build Can't change the fact that distutils creates x86_64 directories: gcc -pthread -shared build/temp.linux-x86_64-2.3/ Also if I try with a python compile in 32bits and installed in system . how I force distutils build to 32-bits ? Thanks in advance, From mnordhoff at mattnordhoff.com Sun Nov 22 01:32:27 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sun, 22 Nov 2009 06:32:27 +0000 Subject: Imitating "tail -f" In-Reply-To: <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: <4B08DAFB.4030203@mattnordhoff.com> Jason Sewall wrote: > FWIW, GNU tail on Linux uses inotify for tail -f: > > http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c > > The wikipedia page for inotify lists several python bindings: > > http://en.wikipedia.org/wiki/Inotify > > Not much help for non-Linux users, but there it is. Too bad, because > inotify is pretty cool. > > Jason Some other operating systems have similar facilities, e.g. FSEvents on OS X. -- Matt Nordhoff From greg.ewing at canterbury.ac.nz Sun Nov 22 01:48:34 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 19:48:34 +1300 Subject: parallel class structures for AST-based objects In-Reply-To: <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <5e5b5061-fa4b-4aaf-8511-066fe7c09d49@j14g2000yqm.googlegroups.com> <81a2a83b-41cc-4cb3-838b-257055ada0a1@d9g2000prh.googlegroups.com> Message-ID: <4B08DEC2.3080709@canterbury.ac.nz> Steve Howell wrote: > My objection to the interface you describe is that Node defines the > type of operations that can be done to it by third-party code, which > is something that I cannot predict I think you have the right idea with a mapping from node classes to implementations of operations, but your intermediate classes SumPrettyPrintNode etc. are not necessary. Just put functions implementing the operations directly into the mapping. Another thing is that the mappings should be somewhere global that can be extended, perhaps through a registration interface. Putting the mapping dicts inside the node classes doesn't gain you anything over simply using methods. All you've done is reimplement method dispatch. A third thing is that instead of just looking up the node class in the mapping, you may want to walk up the MRO and try each of the base classes until you find a match. That way, nodes will effectively inherit implementations from their base classes for any operations that they don't explicitly implement. This inheritance behaviour becomes important if you have two developers A and B, where A adds new classes and B adds new operations. If A and B don't talk to each other, you necessarily end up with gaps in the matrix: A's classes won't have implementations for B's operations. The best you can hope for is that the missing operations will somehow fall back gracefully on default implementations. Inheritance allows this to be achieved: if A derives all his classes from existing node classes, and B provides default implementations of all his operations for the root Node class, then some implementation will always be found for every class/operation combination. Now, there's actually a very easy way of implementing all this. Your registration interface could simply be def register_operation(klass, operation_name, function): setattr(klass, operation_name, function) In other words, monkey-patch the classes to add the new functions directly as methods. Since it's so simple, you could even do away with the registration function altogether and just have developers insert methods directly into the classes. Some people might consider this an ugly hack, but the end result is almost exactly the same, it's very simple, and it's very efficient, making use of Python's existing method dispatch machinery instead of reinventing it yourself. One reason you might want to keep the registration function, even if all it's doing is modifying the classes, is to make it easier to find where operations are being defined, by searching for calls to register_operation(). -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 02:26:02 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 20:26:02 +1300 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> Message-ID: <7ms7ctF3k2a79U1@mid.individual.net> > On Nov 21, 11:20 am, John Roth wrote: > >>Go is simply C with most (but not all) of the warts >>removed and some more modern features added. Syntax-wise, I find myself disappointed that they didn't do as good a job of removing the warts as they could have. For example, there are good reasons for putting types after variable names, but just swapping them around doesn't quite work. C's "int x" reads well because it mimics similar constructs in English which qualify a noun with another noun, e.g. "President Obama". If you say "Obama President", it doesn't sound right. You need some extra punctuation to make it meaningful: "Obama, President". Similarly, I think just a little bit more punctuation is needed to make name-first declarations readable. For my money, it's hard to beat the Wirth style: func foo(x: int; y: char): float However, Go's designers seem to favour using the absolute minimum number of characters they can get away with. Although if they *really* wanted that, they would have dropped most of the semicolons and used indentation-based block structure instead of curly braces. I would have forgiven them several other sins if they'd done that. :-) -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 02:33:00 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 20:33:00 +1300 Subject: Writing a Carriage Return in Unicode In-Reply-To: <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> Message-ID: <7ms7puF3jgcldU1@mid.individual.net> Steve Howell wrote: > If you are > going to couple character sets to their legacy physical > implementations, you should also have a special extra character to dot > your i's and cross your t's. No, no, no. For that device you need to output a series of motion vectors for the scribing point. Plus control characters for "dip nib" and "apply blotter", and possibly also "pluck goose" for when the print head becomes worn. -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 22 03:20:01 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 22 Nov 2009 21:20:01 +1300 Subject: ANN: PyGUI Mailing List In-Reply-To: References: Message-ID: <4B08F431.5080707@canterbury.ac.nz> Terry Reedy wrote: > Having it mirrored to news.gmane,org, if you have not yet, like other > python.org lists, would make it easier to follow or join. Perhaps it > will happen automatically, I do not know. I don't think it's automatic. I've submitted a request to gmane to have it added and I'm waiting to see what happens. -- Greg From wentland at cl.uni-heidelberg.de Sun Nov 22 04:11:44 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sun, 22 Nov 2009 10:11:44 +0100 Subject: Imitating "tail -f" In-Reply-To: References: Message-ID: <20091122091144.GB9247@kinakuta.local> On Sun, Nov 22, 2009 at 03:43 +0100, Ivan Voras wrote: > I'm trying to simply imitate what "tail -f" does, i.e. read a file, wait > until it's appended to and process the new data, but apparently I'm > missing something. [..] > Any advice? Have a look at [1], which mimics "tail -f" perfectly. It comes from a talk by David Beazley on generators which you can find at [2] and [3]. Enjoy! [1] http://www.dabeaz.com/generators/follow.py [2] http://www.dabeaz.com/generators-uk/ [3] http://www.dabeaz.com/coroutines/ -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From n00m at narod.ru Sun Nov 22 04:21:42 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 01:21:42 -0800 (PST) Subject: Sorting: too different times. Why? Message-ID: Any comment: class Vector: def __init__(self, x, y): self.x = x self.y = y def __cmp__(self, v): if self.x < v.x and self.y > v.y: return -1 return 0 def v_cmp(v1, v2): if v1.x < v2.x and v1.y > v2.y: return -1 return 0 from random import randint from time import time a = [] for i in range(200000): a += [Vector(randint(0, 500000), randint(0, 500000))] b = a[:] c = a[:] print 'Sorting...' t = time() b.sort(cmp=v_cmp) print time() - t t = time() c.sort() print time() - t print b == c >>> ===================================== RESTART ====== >>> Sorting... 0.906000137329 6.57799983025 True From deets at nospam.web.de Sun Nov 22 04:50:27 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 10:50:27 +0100 Subject: parallel class structures for AST-based objects In-Reply-To: <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> Message-ID: <7msfr3F3j1ilfU1@mid.uni-berlin.de> Steve Howell schrieb: > On Nov 21, 4:07 pm, MRAB wrote: >> I don't see the point of EvalNode and PrettyPrintNode. Why don't you >> just give Integer, Sum and Product 'eval' and 'pprint' methods? > > That's a good question, and it's the crux of my design dilemma. If > ALL I ever wanted to to with Integer/Sum/Product was to eval() and > pprint(), then I would just add those methods to Integer, Sum, and > Product, and be done with it, as you suggest. But what happens when > somebody wants to extend capability? Should every future software > developer that wants to use Integer/Sum/Product extend those classes > to get work done? What if they want to store additional state for > nodes? > What's usually done is to create visitors/matchers. Those traverse the AST, and either only visit, or return transformed versions of it (think e.g. algebraic optimization) A visitor will roughly look like this: class ASTVisitor(object): def visit(self, node): name = node.__class__.__name__.lower() if hasattr(self, "visit_%s" % name): getattr(self, "visit_%s" % name)(node) for child in node: self.visit(child) You can of course chose another type of dispatch, using e.g. a generic method. Then you create Visitors for specific tasks - pretty-printing, evaluation, rewriting. Those don't have the overhead of your current design with all those factory-mapping stuff, and yet you aren't forced to put logic into AST you don't want there. Diez From sturlamolden at yahoo.no Sun Nov 22 04:57:49 2009 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 22 Nov 2009 01:57:49 -0800 (PST) Subject: How do I create a vanilla object in C? References: <6617094f-6c01-4997-998c-032da4797c88@x31g2000yqx.googlegroups.com> Message-ID: <5f5f5385-16b6-44e2-84e0-34749824bc69@z41g2000yqz.googlegroups.com> On 22 Nov, 04:05, Carl Banks wrote: > name = PyString_FromString("vanilla"); > bases = PyTuple_New(0); > dict = PyDict_New(); > vanilla_type = PyObject_CallObject( > ? ? ? ? &PyType_Type,name,bases,dict,0); > > Then call the vanilla type (however you create it) to get a vanilla > object: > > vanilla_object = PyObject_CallObject(vanilla_type,0); > > Definitely not the most straightforward thing to do from C. It is much easier to do this from Cython. cdef class foo: # fields stored in C struct pass class foo: # fields stored in Python dict pass The let the Cython compiler generate the C code you need. http://docs.cython.org/src/tutorial/cdef_classes.html From showell30 at yahoo.com Sun Nov 22 05:38:36 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 02:38:36 -0800 (PST) Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> <03178ef5$0$1379$c3e8da3@news.astraweb.com> <551b0485-9993-4a7d-88cf-61918536ee56@y28g2000prd.googlegroups.com> <7ms7puF3jgcldU1@mid.individual.net> Message-ID: <5c28ec26-0e48-4b59-9003-ebb50613420a@y32g2000prd.googlegroups.com> On Nov 21, 11:33?pm, Gregory Ewing wrote: > Steve Howell wrote: > > If you are > > going to couple character sets to their legacy physical > > implementations, you should also have a special extra character to dot > > your i's and cross your t's. > > No, no, no. For that device you need to output a series > of motion vectors for the scribing point. Plus control > characters for "dip nib" and "apply blotter", and > possibly also "pluck goose" for when the print head > becomes worn. > Greg, at the first reading of your response, it sounded overly complicated for me to have to "dip nib" and "pluck goose" every time I just want to semantically indicate the ninth letter of the English alphabet, but that's easily solved with a wizard interface, I guess. Maybe every time I am trying to decide which letter to type in Word, there could be some kind of animated persona that helps me choose the character. There could be a visual icon of an "eye" that reminds me of the letter that I am trying to type, and I could configure the depth to which I dib the nib with some kind of slider interface. It actually sounds quite simple and elegant, the more that I think about it. From sumerc at gmail.com Sun Nov 22 05:44:48 2009 From: sumerc at gmail.com (k3xji) Date: Sun, 22 Nov 2009 02:44:48 -0800 (PST) Subject: yappi v0.3 Message-ID: <9ca5964d-21cb-4cce-9fbb-261c4766182b@b15g2000yqd.googlegroups.com> Hi, yappi(yet another python profiler) is a Python Profiler with multithreading support. This is the last beta version with some major changes and bugfixes: v0.3 Changes --------- [+] yappi did not compile out of box on VS2008. Fix the compile issues. (Thanks to Kevin Watters) [+] tidy up stat formatting code. that's previously messy. [+] BUGFIX:application total time is calculated wrong. [+] BUGFIX:change some int's to long long's to prevent simple integer overflows. [+] show profiler status. [+] show memory usage of the yappi itself. [+] show thread class name in the thread stats. [+] make thread/profiler stats column separated. [+] big endian support for core hash function. [+] BUGFIX: CURRENTCTX macro can return NULL on rare occassions, handle that. [+] BUGFIX: Shows wrong thread class name as we call it in the profile_thread. [+] OPTIMIZATION:some hashtable enhancements are done. For documentation and download see: http://code.google.com/p/yappi/ -- twitter.com/sumercip Sumer Cip From ben+python at benfinney.id.au Sun Nov 22 05:50:41 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 22 Nov 2009 21:50:41 +1100 Subject: Sorting: too different times. Why? References: Message-ID: <87y6lyal4u.fsf@benfinney.id.au> n00m writes: > Any comment: I get similar output. What were you expecting to happen? Did you have any questions? -- \ ?The right to search for truth implies also a duty; one must | `\ not conceal any part of what one has recognized to be true.? | _o__) ?Albert Einstein | Ben Finney From n00m at narod.ru Sun Nov 22 05:56:03 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 02:56:03 -0800 (PST) Subject: Sorting: too different times. Why? References: <87y6lyal4u.fsf@benfinney.id.au> Message-ID: <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> I was expecting the 1st method would be *slower* than the 2nd one :-) Or at least equal... Just random ("intuitive") expectations From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 06:04:19 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 11:04:19 GMT Subject: Sorting: too different times. Why? References: Message-ID: <031908a0$0$1336$c3e8da3@news.astraweb.com> In the subject line, you write "too different times". You actually want "two", the number, not "too" as in "too many", "too much". Lots of native English speakers get this wrong too :) On Sun, 22 Nov 2009 01:21:42 -0800, n00m wrote: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 Modern versions of Python (since 2.2 I think?) use __lt__ or __gt__ for sorting. If the class doesn't have a __lt__ method, Python falls back on __cmp__. > b.sort(cmp=v_cmp) This is relatively fast, because you pass a comparison function directly, so Python doesn't need to look for a __lt__ method then fall back to __cmp__. It just uses v_cmp, every time. > c.sort() This is slower, because every comparison looks up the __lt__ and fails, then tries the __cmp__. If you change the definition of Vector to include rich comparison methods as detailed here: http://docs.python.org/reference/datamodel.html#object.__lt__ sorting will probably be significantly faster still. -- Steven From deets at nospam.web.de Sun Nov 22 06:06:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 12:06:01 +0100 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B091B19.9040807@nospam.web.de> n00m schrieb: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 > > from random import randint > from time import time > > a = [] > for i in range(200000): Use xrange instead (unless you are under python3), because for loops you don't need the full list range creates - xrange is just a generator. > a += [Vector(randint(0, 500000), randint(0, 500000))] Better use .append here, looks nicer and should also be a bit faster. > b = a[:] > c = a[:] > > print 'Sorting...' > > t = time() > b.sort(cmp=v_cmp) > print time() - t > > t = time() > c.sort() > print time() - t > > print b == c > > > >>>> ===================================== RESTART ====== >>>> > Sorting... > 0.906000137329 > 6.57799983025 I think the main reason is that method-dispatch is more expensive than function-dispatch. The former must create a bound method before calling, the latter just works out of the box. Things get better if you do this: t = time() c.sort(cmp=Vector.__cmp__) print time() - t Although not the exact same performance - I get Sorting... 0.677843093872 1.4283311367 True Diez From duncan.booth at invalid.invalid Sun Nov 22 06:06:56 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Nov 2009 11:06:56 GMT Subject: Sorting: too different times. Why? References: Message-ID: n00m wrote: > Any comment: > > class Vector: > def __init__(self, x, y): > self.x = x > self.y = y > def __cmp__(self, v): > if self.x < v.x and self.y > v.y: > return -1 > return 0 > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 What's that comparison function supposed to be doing? >>> print Vector(1, 1) < Vector(2, 0) True >>> print Vector(2, 0) == Vector(1, 1) True If you use a broken comparison function then you must expect strange results, and your list of vectors isn't going to end up in any particular order (try adding "c.reverse()" before the call to "c.sort()" and the two 'sorted' lists won't match any more). In this case though the time difference may simply be down to creating in excess of 1 million bound methods. From clp2 at rebertia.com Sun Nov 22 06:07:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Nov 2009 03:07:08 -0800 Subject: Sorting: too different times. Why? In-Reply-To: <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> References: <87y6lyal4u.fsf@benfinney.id.au> <401486f9-5d05-4c28-a870-89fc42a9db79@s15g2000yqs.googlegroups.com> Message-ID: <50697b2c0911220307v15bb99c8if89e071e6d57aed3@mail.gmail.com> On Sun, Nov 22, 2009 at 2:56 AM, n00m wrote: > I was expecting the 1st method would be *slower* than the 2nd one :-) > Or at least equal... Just random ("intuitive") expectations The second method repeatedly looks up left_item.__class__.__cmp__ (i.e. Vector.__cmp__) when doing the necessary comparisons between the list items; while these lookups are optimized and are fast, they are not free and cannot be skipped because Python doesn't know the list contains only Vectors. The first method uses the single provided comparison function and thus does no such lookups; hence, it's faster. That's my guess anyway. Cheers, Chris -- http://blog.rebertia.com From dickinsm at gmail.com Sun Nov 22 06:44:58 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 22 Nov 2009 03:44:58 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: On Nov 22, 9:21?am, n00m wrote: > Any comment: > > class Vector: > ? ? def __init__(self, x, y): > ? ? ? ? self.x = x > ? ? ? ? self.y = y > ? ? def __cmp__(self, v): > ? ? ? ? if self.x < v.x and self.y > v.y: > ? ? ? ? ? ? return -1 > ? ? ? ? return 0 > > def v_cmp(v1, v2): > ? ? if v1.x < v2.x and v1.y > v2.y: > ? ? ? ? return -1 > ? ? return 0 > > from random import randint > from time import time > > a = [] > for i in range(200000): > ? ? a += [Vector(randint(0, 500000), randint(0, 500000))] > b = a[:] > c = a[:] > > print 'Sorting...' > > t = time() > b.sort(cmp=v_cmp) > print time() - t > > t = time() > c.sort() > print time() - t > > print b == c > > >>> ===================================== RESTART ====== > > Sorting... > 0.906000137329 > 6.57799983025 > True Do you get the same magnitude difference if you make Vector a new- style class? (I.e., use "class Vector(object)" instead of "class Vector ()".) Mark From seeWebInstead at rem.intarweb.org Sun Nov 22 07:03:28 2009 From: seeWebInstead at rem.intarweb.org (Robert Maas, http://tinyurl.com/uh3t) Date: Sun, 22 Nov 2009 04:03:28 -0800 Subject: No-syntax Web-programming-IDE (was: Does turtle graphics have the wrong associations?) References: <0315a685$0$1327$c3e8...@news.astraweb.com> Message-ID: > >>> My proposed no-syntax > >>> IDE *also* gets rid of the need to bother with any programming-language > >>> syntax. I've been proposing it for years, but nobody has shown any > >>> interest > From: Terry Reedy > What you describe below is similar to various systems that have > been proposed and even implemented, including visual programming > systems. Are any of them integrated with tutorial material and available over the Web, as mine will be? If so, will you tell me the URLs so that I can play with them? > And there has been some success with non-programmers. The purpose of *my* system will be to start with mostly non-programmers and *teach* them algorithm design from examples of tasks they get paid (labor-credits, not $money$) to perform, without needing to simultaneously bother them with programming-language syntax. They learn how to take one step at a time towards a long journey (Chinese proverb) without needing to first learn a language for stating with ultra-precision *how* exactly to take each one step. Thus they learn algorithm design with maximal efficiency, because nearly their whole attention is on *that* without distraction of syntax too. > But for most people, it is simply easier to say/write what one > means rather than point and click. That works only after you already know to say/write what you mean for the computer *precisely*exactly*analRetentively* what you want the computer to do. If you don't already know *how* to say precisely what you mean for the computer to do, it's impossible. For example, show somebody this data: [12 15 19 26 43 62 92 71 78 85 93] Point to this item ...^^ Ask that person, who has *never* even seen a computer program much less written one him/herself, and also who has never studied formal mathematics such as set theory, and ask that person to say in precise terms how a computer should find that indicated item among the data. Look at the data. You see what's special about that one item among the data, right? So how to express to a computer how to find it? Answer: It's the item that's out-of-sequence relative to its neighbors. How many non-computer non-math beginners would even notice what's special about that item? (my guess: about half) How many would be able to express either the mathematical definition of the desired result, or an algorithm for finding it, clearly enough that even a human seeing the expression but *not* seeing the sample would be able to write a computer program per that spec to solve the problem? (my guess: less than 1%) Example of a valid informal mathematical expression: There's a sequence of numbers. Mostly they are in correct sequence. But exactly one of them is in the wrong place relative to the others around it. Find that one that's out of place. Example of a valid semi-formal mathematical expression: Given an index set [0..N], and a function F from that index set into the integers; Such that the predicate "lambda (i) F(i-1) < F(i) < F(i+1)" is true for all but one member of the interval [1..N-1]; Find the element of [1..N-1] for which the predicate is not true. Formal mathematical expression depends on the notation conventions, so I won't bother to even attempt to concoct such here for example. Computer algorithms are several in overall algorithm, depending on which primitives are available from declarative or imperative programming, from functional or prodedural etc. programming, and within each choice of *that*, the actual syntax can be any of several per programming language such as Lisp or APL or Forth etc. (Yeah, I deliberately avoided mentionning C or Fortran or Java etc.) If my guess is correct that less than 1% of absolute beginners can even state what is desired, so that a human can understand it unambiguously, much less how to obtain it, likewise, expecting that such an absolute beginner would simply "say/write what one means" is IMO unreasonable. Hence my idea is a sort of friendly "wizard" to take as much of a crude ambiguous statment as the student is capable of and willing to key in, use that to narrow and/or prioritize the number of possible data-processing steps that are reasonably possible given the data we have to work from, and then show the prioritized options to the student, clearly expressed moderately verbosely, and let the student either pick one of them or clarify what had been keyed in just before. At the start, before the student has said *anything* about what the next D/P step will be, *all* possible operations on existing data are available, organized in some meaningful way that would support a fully menu-driven method as you presume. But a hybrid of vague statement what to do (such as my first "answer" above which said nothing about there being any sequence or that the numbers were ascending except for that one out of place) and limited set of known options available a priori, would be available whenever the student *can* at least partially express what to do with the data. Now in the example given above, the desired processing step is too complicated to be directly available in most programming languages, and so I would treat that as a high-level problem to be broken into pieces rather than a low-level task to be directly expressed in primitives available at the start. So in a sense it wasn't a fair example, but it's what I thought of at the moment while composing this article. And it *does* serve as a good example of the *other* part of my proposed integrated NewEco contract-work team-programming system, namely the discussion forum and concensus-achiever process of how to break a complicated task down into pieces so that each piece can be solved separately by recursive application of the system and then the pieces can be applied in combination to solve the given toplevel problem. (Caveat: The problem example I stated above is probably not the actual highest-level problem, but more likely some intermediate problem that comprises the toplevel problem. But recursively it's the toplevel problem at the moment.) > Point-and-click writing reminds me of point-and-click speaking. > Great for those who need it but a hindrance to those who do not. The hybrid system would satisfy people at both ends of your spectrum, as well as people anywhere in the middle, such as a person who knew only fifty words and had only a vague idea of just a little of the grammar and needed to express something that used about half known words that can be keyed in and half unknown words that must be obtained from a thesaurus or menu. And actually if you compare programming with ordering food in a restaurant, unless you know in advance the entire menu of the restaurant or the entire set of functions/methods of the programming language, you really *do* need to consult the menu from time to time to see what's available, rather than make a fool of yourself by trying to ask for thousands of entrees not available in that restaurant (just **try** going into your local Jack in the Box and standing at the counter (or using the drive-thru intercom) and ordering a plate of escargot, then a plate of lasagna, then a pizza, then some marzipan candies, then a sundae, then a T-bone steak, then a souffle, then a mug of beer, then some fresh walnuts in the shell, then a can of corn beef hash, then some potstickers, then a bowl of chili, then a half pound of chicken almond chow mein, then a glass of Grey Reisling, then a plate of spaghetti, then a baked potato with sour cream, then ... see if you even get that far before the manager comes out to tell you to either read the menu or go away and stop bothering them) So yeah I have a grand idea of a system that represents data per intentional datatype rather than any specific implementational datatype used in any particular programming language, and uses generic intentional-datatype functions/methods not directly related to anything in any regular programming language (at least it'll be rare when by chance there's a function in an existing language that is *exactly* as general as what I offer), but uses a hierarchy of general-to-specific datatypes so that algorithms can be expressed very generally at first then at some point pinned down if necessary to a specific type of representation in order to be able to write algorithms dependent on that representation, or just left in abstract form if my system happens to have a built-in function to do exactly what is needed so that no further splitting of the task is necessary. For example, Java has the concept of a "Set", and functions to do various set-theoretic operations on it, with the *same* method specification regardless of whether the Set is implemented as a TreeSet or HashSet. By comparison, Common Lisp doesn't have such a generic set of methods defined, instead has separate functions defined for linked-list acting as a set or bitmap acting as a set or hashtable acting as a set. So depending on how large a system I have implemented, various of those operations might or might not be available at the get-go. Let me go back to that example I gave earlier. If users are presented with that problem, by example, and asked to think of ways to solve it, some might prefer the mathematical approach, similar to what I expressed earlier, similar to a declarational programming language, while others might prefer a procedural or functional expression of the algorithm. If both viewpoints had sufficient voters, the project might split into two different programming teams, one analyzing the problem mathematically, and the other analyzing the problem imperatively. These teams would then break the main goal into sub-tasks in somewhat different ways. And within each team, there might be further differences of opinion, such as whether to iterate sequentially (as might be done in C) or to use a mapping operation to emulate set-theoretic operations (as might be done in Lisp) or to use set-theoretical operations directly (as in SQL). At an even finer level of analysis, the iterative team might prefer linear search or parallel-processing (process-forking) recursive binary search, depending on their perception of the CPU and system-level task software available. And the linear-search team might prefer either explicit array indexing, i.e. for (ix=0; ix This is not to say that traditional editors cannot be improved > with better backup memory aids. Indeed, even IDLE recognizes > function names and pops up a bar listing parameters. But I assume the student using IDLE is *forced* into one particular syntax for the given programming language? > Feel free to develop a Visual Python environment. Like I said, there won't be *any* programming-language syntax. No Lisp, no PHP, no Java, no C (the C examples of array indexing vs. streams were just the best way I could think of expressing the *algorithm* style to reaaders of this thread, no intention that students would actually *see* that syntax anywhere in my system) and no Python, sorry, but I have to emphasize that point again. > I might even give it a try. Would you give it a try if it didn't show you any Python syntax at any point, but after an algorithm is *completed* it gave you the option of rendering the algorithm in any of several different programming languages, maybe even more than one way in each language if the abstract intentional datatypes were never resolved to specific implementational datatypes, hence could be emulated multiple ways per multiple implementational datatypes in each single language? For example, the sequence given in the example above could be represented in Java as a generic Vector using instance methods from the Vector class, or as a generic Array using primitive C-like code within static methods, or as an explicit user-defined class with user-defined methods, or as a user-defined sub-class of Vector that used a mix of Vector methods and sub-class methods, or in Java version 6 as a specialized type of Vector. Oops, somehow when I downloaded the above and below articles, for purpose of later responding to each, the newsgroup header from the article below was lost. Google Groups advanced search for phrase: I did too and had the same question turns up *nothing*, as if your article was never posted! Processing a single data file turns up only one false match. (I hate how Google Groups has been grossly broken for the past several months, as if they just don't care any more.) So I have no way find your article (below) to get the header, hence no way to post a followup to it, so I'll just append my reply here: > >> From: Steven D'Aprano > >> I'm interested. No-syntax IDE? How is this even possible? > > I guess you missed what I previously posted. > I did too and had the same question. ;Note the following is just *one* example of a test-rig set-up: > > The basic idea is that > > you start with test data, and you use menus to select appropriate > > data-processing actions to perform on that data. For example, you > > manually key in a file name containing test data, or copy and paste > > that same file name. Then you select "open file by that name" or > > "load all lines from file by that name" etc. from a menu. If you > > just opened the file, you now have a stream of input, and you can > > select to read one line or one s-expression or one character etc. > > from that file. After loading the whole file or one unit of data, > > you now have some *real* data to work from. For example, with a > > line of input, you might break it into words. > Processing a single data file is a common programming task, but > not the only general category. That was just an example, but in fact often when devising algorithms the sample test input data *is* given either in a disk file or in a Web page, so when writing *most* of the code, the input data might indeed come from such a test-data-file, even though the finished algorithm will in practice get its data *live* from some other source such as the URL-encoded form contents. For purpose of teaching absolute-beginning computer algorithm design, I think working from a disk-file of test-data is sufficiently general. That test-data file can in fact have either the URL-encoded form contents, or associative arrays for GET and POST and COOKIE already decoded as given. Then later after the student practices setting up CGI-hello-world demos on his/her own personal Web site, simply putting the two pieces together is enough to achieve an online server-side Web application. > A specialized Visual Data Analysis with Python might be a better > and more focused project. How would that be presented to the user via CGI or PHP? > When I was doing statistical data analysis on a daily basis for a > living, I would have loved to have had a system that would read > in the first line and let me define (and name) the fields by > point and click. (I usually worked with fixed-width, > column-delimited fields.) The first task is to *recognize* the boundaries between the various column-delimited fields. If there is always a blank column between adjacent data columns, and there's never an accidental blank column throughout all rows of any data column, it's pretty simple by algorithm to find where the columns are located, so as to show the user the columns already delimited and then all the user has to do is name each one (and if the first row is column headers, with no repeat names, then even the naming can be done automatically). 2008.Aug I wrote such a column-finder function-set in Lisp: ;Given a list of rows of the table, such as lines read from a file: ;Build an array of column counts. Each count is the number of lines that ; have non-white in that column. Short lines don't ever count past the ; end, hence as if all white after end. ;Note: Omit any header line(s) when passing data to this function, ; so that only the actual data columns will be tabulated. ;Return that array, of length exactly equal to the longest line in the list. (defun lines-count-nonwhite-cols (lines) ...) ;Given an array listing counts of non-white characters per column: ;Find start and end of each non-white multi-column. ;Return alternating list (startix1 endix1 startix2 endix2 ...) (defun arrcolnw-to-ixpairs (arr) ...) ;Given alternating list of start..end indices for multi-columns: ;Make a function object to parse strings per those multi-columns. (defun ixpairs-make-splitter-function-object (ixpairs) ...) Those three together effect a parse of each line into a vector, whereby positional indexing can pull out the nth field of each. Then to automatically match user-defined column-header strings against column headers given as top line of the file: ;Given the parsed form of the header line, hopefully with each field ; trimmed already, and a list of strings that are supposed to match ; some of these fields: ;Make sure each given string actually does match one of the fields. ;Note: The given string need only be a substring of the field name. ;Return a list of corresponding indexes into the record. (defun hdrrec+hdrstrs-find-field-indexes (hdrrec hdrstrs) ...) Now we have a way to map user-defined names to fields within records, thus retrieve a field by name instead of index. The rest of 2008-8-cols.lisp was a specific application of that to parsing and further processing of the report from FileList, which is a directory listing for Macintosh. Here's what one of those reports looks like (just the header line and a few file-lines): FILE NAME TYPE CREA BYTES CREATED MODIFIED VOLUME PATH About System 7.5 ttro ttxt 22032 96/05/31 12:00:00 96/05/31 12:00:00 HD: About System 7.5.5 Update ttro ttxt 17592 96/09/11 12:00:00 96/09/11 12:00:00 HD: About the Control Panels folder ttro ttxt 16410 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:About the MacOS: About the Extensions folder ttro ttxt 20558 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:About the MacOS: About the System Folder ttro ttxt 4618 96/01/17 12:00:00 96/01/17 12:00:00 HD:Apple Extras:About the MacOS: AppleCD Audio Player APPL aucd 141160 95/06/19 12:00:00 95/06/19 12:00:00 HD:Apple Extras:AppleCD Audio Player: AppleCD Audio Player Guide poco reno 114948 95/12/22 12:00:00 95/12/22 12:00:00 HD:Apple Extras:AppleCD Audio Player: About Automated Tasks ttro ttxt 5742 96/05/28 12:00:00 96/05/28 12:00:00 HD:Apple Extras:AppleScript:Automated Tasks: Add Alias to Apple Menu APPL dplt 8559 94/08/02 00:00:00 94/08/02 00:00:00 HD:Apple Extras:AppleScript:Automated Tasks: Find Original from Alias APPL dplt 8580 94/08/02 00:00:00 94/08/02 00:00:00 HD:Apple Extras:AppleScript:Automated Tasks: .. Note the blank column between "Apple" and "Extras" in the last field, which would cause that field to appear to be two different fields, if this were the *whole* datafile. There are various work-arounds for such a case if it occurs. > Instead, I had to write a format statement and some summary > analysis code, run it, look at it for sanity, and decide if my > format had been correct. Pain! Too bad you didn't have 2008-8-cols.lisp available to use, and didn't think to invent something similar yourself. From newptcai at gmail.com Sun Nov 22 07:03:30 2009 From: newptcai at gmail.com (=?UTF-8?B?5LiA6aaW6K+X?=) Date: Sun, 22 Nov 2009 04:03:30 -0800 (PST) Subject: Why Python allows comparison of a callable and a number? Message-ID: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> I used python to write an assignment last week, here is a code snippet #================================ def departTime(): ''' Calculate the time to depart a packet. ''' if(random.random < 0.8): t = random.expovariate(1.0 / 2.5) else: t = random.expovariate(1.0 / 10.5) return t #================================ Can you see the problem? I compare random.random with 0.8, which should be random.random(). Of course this because of my careless, but I don't get it. In my opinion, this kind of comparison should invoke a least a warning in any programming language. So why does python just ignore it? From clp2 at rebertia.com Sun Nov 22 07:09:08 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 22 Nov 2009 04:09:08 -0800 Subject: Why Python allows comparison of a callable and a number? In-Reply-To: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> References: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> Message-ID: <50697b2c0911220409m420b6747i54396f7e67d9f9de@mail.gmail.com> On Sun, Nov 22, 2009 at 4:03 AM, ??? wrote: > I used python to write an assignment last week, here is a code snippet > > #================================ > > def departTime(): > ? ?''' > ? ?Calculate the time to depart a packet. > ? ?''' > ? ?if(random.random < 0.8): > ? ? ? ?t = random.expovariate(1.0 / 2.5) > ? ?else: > ? ? ? ?t = random.expovariate(1.0 / 10.5) > ? ?return t > > #================================ > > Can you see the problem? ?I compare random.random with 0.8, ?which > should be random.random(). > > Of course this because of my careless, but I don't get it. ?In my > opinion, this kind of comparison should invoke a least a warning in > any programming language. > > So why does python just ignore it? It's an historical anomaly that's been rectified in Python 3, where such non-equality comparisons between unrelated types *do* now raise an error. Cheers, Chris -- http://blog.rebertia.com From paul.nospam at rudin.co.uk Sun Nov 22 07:20:45 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 22 Nov 2009 12:20:45 +0000 Subject: Imitating "tail -f" References: <20091122041002.26747.1033090494.divmod.xquotient.2@localhost.localdomain> <31e9dd080911212019t60855ae7q34a530dbe3c438a2@mail.gmail.com> <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: <87ws1i3g4i.fsf@rudin.co.uk> Matt Nordhoff writes: > Jason Sewall wrote: >> FWIW, GNU tail on Linux uses inotify for tail -f: >> >> http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c >> >> The wikipedia page for inotify lists several python bindings: >> >> http://en.wikipedia.org/wiki/Inotify >> >> Not much help for non-Linux users, but there it is. Too bad, because >> inotify is pretty cool. >> >> Jason > > Some other operating systems have similar facilities, e.g. FSEvents on OS X. Yeah, and there's a similar kind of thing in the windows api. A nice python project would be a cross-platform solution that presented a uniform api and just did the right thing behind the scenes on each OS. (Incidentally on linux you need to watch out for the value of /proc/sys/fs/inotify/max_user_watches - if you're using inotify in anger it's easy to exceed the default set by a lot of distributions.) From davea at ieee.org Sun Nov 22 07:28:55 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 07:28:55 -0500 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B092E87.9060904@ieee.org> n00m wrote: > Any comment: > > > def v_cmp(v1, v2): > if v1.x < v2.x and v1.y > v2.y: > return -1 > return 0 > > > The second part of the compound if is backwards. So if this is headed for production code, it better get fixed. DaveA From bnrj.rudra at gmail.com Sun Nov 22 07:30:38 2009 From: bnrj.rudra at gmail.com (rudra) Date: Sun, 22 Nov 2009 04:30:38 -0800 (PST) Subject: plotting arrow in python References: <4422fd81-d605-44dc-8b83-11f5633e50ba@l13g2000yqb.googlegroups.com> <7ms299F3jvhbiU1@mid.individual.net> Message-ID: On Nov 22, 6:58?am, Gregory Ewing wrote: > > rudra wrote: > > >> 0.0 0.0 0.1 > >> 0.0 0.1 0.1 > >> 0.1 0.0 0.5 > > >> like that! the first two column are coordinate and 3rd one is > >> magnitude of moment (say: x y,m)!! so what i want to do is draw an > >> arrow of magnitude(m) in the position (x,y). > > There seems to be some information missing there. > How do you know what direction to draw the arrow in? > > -- > Greg Greg, you are right direction is also needed. But as a beginner, I am trying to make it simple and all arrows are collinear along x axis!! then i have to try non collinear as well. thank you From n00m at narod.ru Sun Nov 22 07:45:54 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 04:45:54 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: > Do you get the same magnitude difference > if you make Vector a new-style class? Yes (I mean "No"): new-style's much faster And now it's elephants instead of vectors. Def: an elephant is smarter than another one IIF its size is strictly less but its IQ is strictly greater I.e. you can't compare (2, 8) to (20, 50) or let count them as equally smart elephants. ================================================ class Elephant(object): def __init__(self, size, iq): self.size = size self.iq = iq def __cmp__(self, e): if self.size < e.size and self.iq > e.iq: return -1 if self.size > e.size and self.iq < e.iq: return 1 return 0 def e_cmp(e1, e2): if e1.size < e2.size and e1.iq > e2.iq: return -1 if e1.size > e2.size and e1.iq < e2.iq: return 1 return 0 from random import randint from time import time a = [] for i in xrange(200000): a.append(Elephant(randint(1, 50000), randint(1, 50000))) b = a[:] c = a[:] print 'Sorting...' t = time() b.sort(cmp=e_cmp) print time() - t t = time() c.sort() print time() - t print b == c >>> ===================================== RESTART ===== >>> Sorting... 1.56299996376 1.95300006866 True From n00m at narod.ru Sun Nov 22 07:49:46 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 04:49:46 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> > The second part of the compound if is backwards. ?So if this is headed > for production code, it better get fixed. > > DaveA Not sure I'm understanding your remark. From jelle at smetj.net Sun Nov 22 08:58:09 2009 From: jelle at smetj.net (Jelle Smet) Date: Sun, 22 Nov 2009 14:58:09 +0100 Subject: python regex "negative lookahead assertions" problems Message-ID: <58e207482b8723b1adf21a2345eb3396@smetj.net> Hi List, I'm trying to match lines in python using the re module. The end goal is to have a regex which enables me to skip lines which have ok and warning in it. But for some reason I can't get negative lookaheads working, the way it's explained in "http://docs.python.org/library/re.html". Consider this example: Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>> re.match('.*(?!warning)',line) <_sre.SRE_Match object at 0xb75b1598> I would expect that this would NOT match as it's a negative lookahead and warning is in the string. Thanks, -- Jelle Smet http://www.smetj.net From g.ricioppo at gmail.com Sun Nov 22 09:36:09 2009 From: g.ricioppo at gmail.com (Kill Joy) Date: Sun, 22 Nov 2009 06:36:09 -0800 (PST) Subject: MySQLdb Message-ID: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Hi all. I have a mod_python script with two query: cursor = db.cursor() sql = 'SELECT * FROM users where username=\'' + username +'\'' cursor.execute(sql) result = cursor.fetchall() num = int(cursor.rowcount) if num == 0 : sql2 = 'insert into users values (null, \'' + username + '\', \'' + password +'\', \'no\',\'fdfdf\')' cursor.execute(sql2) warning = "Registration ok" else : warning = "EXIST!" The first query is executed... but not the second. It doesn't insert. Why? I'm a newbie... sorry. Many thanks. K From python.list at tim.thechases.com Sun Nov 22 09:52:39 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 22 Nov 2009 08:52:39 -0600 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <58e207482b8723b1adf21a2345eb3396@smetj.net> References: <58e207482b8723b1adf21a2345eb3396@smetj.net> Message-ID: <4B095037.9010901@tim.thechases.com> >>>> import re >>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>> re.match('.*(?!warning)',line) > <_sre.SRE_Match object at 0xb75b1598> > > I would expect that this would NOT match as it's a negative lookahead and warning is in the string. This first finds everything (".*") and then asserts that "warning" doesn't follow it, which is correct in your example. You may have to assert that "warning" doesn't exist at every point along the way: re.match(r'(?:(?!warning).)*',line) which will match up-to-but-not-including the "warning" text. If you don't want it at all, you'd have to also anchor the far end re.match(r'^(?:(?!warning).)*$',line) but in the 2nd case I'd just as soon invert the test: if 'warning' not in line: do_stuff() -tkc From geraldwalkerx at gmail.com Sun Nov 22 10:00:03 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Sun, 22 Nov 2009 10:00:03 -0500 Subject: MySQLdb In-Reply-To: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> References: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Message-ID: Kill Joy wrote: > Hi all. > > I have a mod_python script with two query: > > cursor = db.cursor() > > sql = 'SELECT * FROM users where username=\'' + username +'\'' > cursor.execute(sql) > result = cursor.fetchall() > num = int(cursor.rowcount) > > if num == 0 : > sql2 = 'insert into users values (null, \'' + username + '\', \'' + > password +'\', \'no\',\'fdfdf\')' > cursor.execute(sql2) db.commit() > warning = "Registration ok" > > else : > warning = "EXIST!" > > The first query is executed... but not the second. It doesn't insert. > Why? > I'm a newbie... sorry. > > Many thanks. > I added db.commit() after cursor.execute(sql2). From g.ricioppo at gmail.com Sun Nov 22 10:03:18 2009 From: g.ricioppo at gmail.com (Kill Joy) Date: Sun, 22 Nov 2009 07:03:18 -0800 (PST) Subject: MySQLdb References: <327d3f60-e132-4cb2-b61f-3b1a7a9d4201@g23g2000yqh.googlegroups.com> Message-ID: On 22 Nov, 16:00, Gerald Walker wrote: > Kill Joy wrote: > > Hi all. > > > I have a mod_python script with two query: > > > ? ?cursor = db.cursor() > > > ? ?sql = 'SELECT * FROM users where username=\'' + username +'\'' > > ? ?cursor.execute(sql) > > ? ?result = cursor.fetchall() > > ? ?num = ?int(cursor.rowcount) > > > ? ?if num == 0 : > > ? ? ? ? ? ?sql2 = 'insert into users values (null, \'' + username + '\', \'' + > > password +'\', \'no\',\'fdfdf\')' > > ? ? ? ? ? ?cursor.execute(sql2) > > ? ? ? ? ? ? ? ? db.commit() > > > ? ? ? ? ? ?warning = "Registration ok" > > > ? ?else : > > ? ? ? ? ? ?warning = "EXIST!" > > > The first query is executed... but not the second. It doesn't insert. > > Why? > > I'm a newbie... sorry. > > > Many thanks. > > I added db.commit() after cursor.execute(sql2). ohhh... many thanks many thanks. Gius. From jarausch at skynet.be Sun Nov 22 10:05:47 2009 From: jarausch at skynet.be (Helmut Jarausch) Date: Sun, 22 Nov 2009 16:05:47 +0100 Subject: python regex "negative lookahead assertions" problems In-Reply-To: References: Message-ID: <4b09534c$0$2868$ba620e4c@news.skynet.be> On 11/22/09 14:58, Jelle Smet wrote: > Hi List, > > I'm trying to match lines in python using the re module. > The end goal is to have a regex which enables me to skip lines which have ok and warning in it. > But for some reason I can't get negative lookaheads working, the way it's explained in "http://docs.python.org/library/re.html". > > Consider this example: > > Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import re >>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>> re.match('.*(?!warning)',line) > <_sre.SRE_Match object at 0xb75b1598> > > I would expect that this would NOT match as it's a negative lookahead and warning is in the string. > '.*' eats all of line. Now, when at end of line, there is no 'warning' anymore, so it matches. What are you trying to achieve? If you just want to single out lines with 'ok' or warning in it, why not just if re.search('(ok|warning)') : call_skip Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From duncan.booth at invalid.invalid Sun Nov 22 10:08:28 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Nov 2009 15:08:28 GMT Subject: Sorting: too different times. Why? References: Message-ID: n00m wrote: > And now it's elephants instead of vectors. > Def: an elephant is smarter than another one IIF > its size is strictly less but its IQ is strictly > greater > > I.e. you can't compare (2, 8) to (20, 50) > or let count them as equally smart elephants. and that still isn't a relationship where you can get any meaningful order out of sorting them: >>> Elephant(1, 20) < Elephant(2, 10) True >>> Elephant(1, 20) == Elephant(2, 20) == Elephant(2, 10) True From sajmikins at gmail.com Sun Nov 22 10:55:08 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 22 Nov 2009 10:55:08 -0500 Subject: parallel class structures for AST-based objects In-Reply-To: <7msfr3F3j1ilfU1@mid.uni-berlin.de> References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> <7msfr3F3j1ilfU1@mid.uni-berlin.de> Message-ID: <50f98a4c0911220755l53768729n62b982df03075474@mail.gmail.com> On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch wrote: > Steve Howell schrieb: >> >> On Nov 21, 4:07 pm, MRAB wrote: >>> >>> I don't see the point of EvalNode and PrettyPrintNode. Why don't you >>> just give Integer, Sum and Product 'eval' and 'pprint' methods? >> >> That's a good question, and it's the crux of my design dilemma. ?If >> ALL I ever wanted to to with Integer/Sum/Product was to eval() and >> pprint(), then I would just add those methods to Integer, Sum, and >> Product, and be done with it, as you suggest. ?But what happens when >> somebody wants to extend capability? ?Should every future software >> developer that wants to use Integer/Sum/Product extend those classes >> to get work done? ?What if they want to store additional state for >> nodes? >> > > What's usually done is to create visitors/matchers. Those traverse the AST, > and either only visit, or return transformed versions of it (think e.g. > algebraic optimization) > > A visitor will roughly look like this: > > > class ASTVisitor(object): > > > > ? def visit(self, node): > ? ? ? name = node.__class__.__name__.lower() > ? ? ? if hasattr(self, "visit_%s" % name): > ? ? ? ? ? getattr(self, "visit_%s" % name)(node) > ? ? ? for child in node: > ? ? ? ? ? self.visit(child) > > > > You can of course chose another type of dispatch, using e.g. a generic > method. > > Then you create Visitors for specific tasks - pretty-printing, evaluation, > rewriting. Those don't have the overhead of your current design with all > those factory-mapping stuff, and yet you aren't forced to put logic into AST > you don't want there. > FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting Kit) for this sort of thing. It has a GenericASTTraversal which "is a Visitor pattern according to Design Patterns." http://pages.cpsc.ucalgary.ca/~aycock/spark/ It's apparently distributed with the python source, but it's not in the standard library, more's the pity IMO. There's a bit of a learning curve but it's well worth it. ~Simon From python at mrabarnett.plus.com Sun Nov 22 11:17:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:17:12 +0000 Subject: Sorting: too different times. Why? In-Reply-To: <031908a0$0$1336$c3e8da3@news.astraweb.com> References: <031908a0$0$1336$c3e8da3@news.astraweb.com> Message-ID: <4B096408.2000601@mrabarnett.plus.com> Steven D'Aprano wrote: > In the subject line, you write "too different times". You actually want > "two", the number, not "too" as in "too many", "too much". Lots of native > English speakers get this wrong too :) > [snip] It could mean that the times are not just different, they're _too_ different, ie a lot more than they are expected to be. From python at mrabarnett.plus.com Sun Nov 22 11:23:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:23:26 +0000 Subject: Why Python allows comparison of a callable and a number? In-Reply-To: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> References: <058ac180-7247-4d93-96fe-2d811ce3b026@f20g2000prn.googlegroups.com> Message-ID: <4B09657E.2090405@mrabarnett.plus.com> ??? wrote: > I used python to write an assignment last week, here is a code snippet > > #================================ > > def departTime(): > ''' > Calculate the time to depart a packet. > ''' > if(random.random < 0.8): > t = random.expovariate(1.0 / 2.5) > else: > t = random.expovariate(1.0 / 10.5) > return t > > #================================ > > Can you see the problem? I compare random.random with 0.8, which > should be random.random(). > > Of course this because of my careless, but I don't get it. In my > opinion, this kind of comparison should invoke a least a warning in > any programming language. > > So why does python just ignore it? In Python 2 you can compare any 2 objects, for example an int with a string. The result is arbitrary but consistent. In Python 3 if the 2 objects aren't 'compatible' you'll get a TypeError at runtime. BTW, you don't need to put parentheses around the conditions in 'if' and 'while' statements. Python isn't C, etc. :-) From n00m at narod.ru Sun Nov 22 11:23:53 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 08:23:53 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: Here "meaningful order" is: if elephant "a[i]" is smarter than elephant "a[j]" then "i" must be strictly less than "j" Of course, to the same effect we could sort them simply by sizes, but then time of sorting would increase by ~ 2 times -- due to decreasing of number of equally smart things. But here it does not matter -- for my initial question. I like all above explanations. Especially that by Chris Rebert. From n00m at narod.ru Sun Nov 22 11:26:59 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 08:26:59 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: :-) Of course, by "too" I meant "too", as in "tooooo much" From python at mrabarnett.plus.com Sun Nov 22 11:32:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:32:49 +0000 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <4B095037.9010901@tim.thechases.com> References: <58e207482b8723b1adf21a2345eb3396@smetj.net> <4B095037.9010901@tim.thechases.com> Message-ID: <4B0967B1.80408@mrabarnett.plus.com> Tim Chase wrote: >>>>> import re >>>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh >>>>> qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf >>>>> lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>>> re.match('.*(?!warning)',line) >> <_sre.SRE_Match object at 0xb75b1598> >> >> I would expect that this would NOT match as it's a negative lookahead >> and warning is in the string. > > This first finds everything (".*") and then asserts that "warning" > doesn't follow it, which is correct in your example. You may have to > assert that "warning" doesn't exist at every point along the way: > > re.match(r'(?:(?!warning).)*',line) > > which will match up-to-but-not-including the "warning" text. If you > don't want it at all, you'd have to also anchor the far end > > re.match(r'^(?:(?!warning).)*$',line) > > but in the 2nd case I'd just as soon invert the test: > > if 'warning' not in line: > do_stuff() > The trick is to think what positive lookahead you'd need if you wanted check whether 'warning' is present: '(?=.*warning)' and then negate it: '(?!.*warning)' giving you: re.match(r'(?!.*warning)', line) From python at mrabarnett.plus.com Sun Nov 22 11:44:16 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 16:44:16 +0000 Subject: Sorting: too different times. Why? In-Reply-To: References: Message-ID: <4B096A60.3030607@mrabarnett.plus.com> n00m wrote: > :-) Of course, by "too" I meant "too", as in "tooooo much" Although it's OK in English to say "too much x" or "too many x", it's somewhat unnatural to say "too different xs"; it would have to be "the xs are too different". Nobody said English was logical! :-) From n00m at narod.ru Sun Nov 22 12:15:57 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 09:15:57 -0800 (PST) Subject: Sorting: too different times. Why? References: Message-ID: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> > it's somewhat unnatural to say "too different xs" Aha. Thanks. PS For years I thought that song's title "No Woman No Cry" by Bob Marley means "No Woman -- No Cry". As if a man got rid of his woman and stopped crying, out of her bad behaviour etc. It turned out to mean "No, woman,.. no cry..." Or take "Drips" by Eminem. What on earth do the drips mean? Album: The Eminem Show Song: Drips [Eminem] Obie.. yo [Trice] {*coughing*} I'm sick [Eminem] Damn, you straight dog? [Chorus] That's why I ain't got no time for these games and stupid tricks or these bitches on my dick That's how dudes be gettin sick That's how dicks be gettin drips Fallin victims to this shit... ... ... From showell30 at yahoo.com Sun Nov 22 12:27:08 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 09:27:08 -0800 (PST) Subject: parallel class structures for AST-based objects References: <407fefb1-ae7c-4f66-8317-2f0fd36260f7@x25g2000prf.googlegroups.com> <9fc76417-3110-4c4b-8982-c73cd89684fa@b36g2000prf.googlegroups.com> <7msfr3F3j1ilfU1@mid.uni-berlin.de> Message-ID: On Nov 22, 7:55?am, Simon Forman wrote: > On Sun, Nov 22, 2009 at 4:50 AM, Diez B. Roggisch wrote: > > > > > Steve Howell schrieb: > > >> On Nov 21, 4:07 pm, MRAB wrote: > > >>> I don't see the point of EvalNode and PrettyPrintNode. Why don't you > >>> just give Integer, Sum and Product 'eval' and 'pprint' methods? > > >> That's a good question, and it's the crux of my design dilemma. ?If > >> ALL I ever wanted to to with Integer/Sum/Product was to eval() and > >> pprint(), then I would just add those methods to Integer, Sum, and > >> Product, and be done with it, as you suggest. ?But what happens when > >> somebody wants to extend capability? ?Should every future software > >> developer that wants to use Integer/Sum/Product extend those classes > >> to get work done? ?What if they want to store additional state for > >> nodes? > > > What's usually done is to create visitors/matchers. Those traverse the AST, > > and either only visit, or return transformed versions of it (think e.g. > > algebraic optimization) > > > A visitor will roughly look like this: > > > class ASTVisitor(object): > > > ? def visit(self, node): > > ? ? ? name = node.__class__.__name__.lower() > > ? ? ? if hasattr(self, "visit_%s" % name): > > ? ? ? ? ? getattr(self, "visit_%s" % name)(node) > > ? ? ? for child in node: > > ? ? ? ? ? self.visit(child) > > > You can of course chose another type of dispatch, using e.g. a generic > > method. > > > Then you create Visitors for specific tasks - pretty-printing, evaluation, > > rewriting. Those don't have the overhead of your current design with all > > those factory-mapping stuff, and yet you aren't forced to put logic into AST > > you don't want there. > > FWIW I often use John Aycock's SPARK (Scanning, Parsing, and Rewriting > Kit) for this sort of thing. ?It has a GenericASTTraversal which "is a > Visitor pattern according to Design Patterns." > > http://pages.cpsc.ucalgary.ca/~aycock/spark/ > > It's apparently distributed with the python source, but it's not in > the standard library, more's the pity IMO. > > There's a bit of a learning curve but it's well worth it. > Thanks, Simon, I think something like GenericASTTraversal should work for me in most cases. A couple of folks have suggested an idea that is in his paper, which is to use a single class for something PrettyPrinter, and then use reflection to find methods on PrettyPrinter to pretty-print sums, products, integers, etc. From news123 at free.fr Sun Nov 22 12:32:03 2009 From: news123 at free.fr (News123) Date: Sun, 22 Nov 2009 18:32:03 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) Message-ID: <4b097593$0$30269$426a74cc@news.free.fr> Hi, I'm trying to scan a document from a python 2.6 script without user interaction. I found a code snippet, that allows me to scan under Vista, but that doesn't allow me to select the dpi / color mode / etc. The snippet uses win32com.client # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end My problems are: - This script works fine for me under Windows 7, however I'm unable to specify additional parameters, like dpi and color mode. - The script doesn't work under windows XP, though the scanner driver is installed. (Gimp finds the scanner (as WIA scanner)). Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL. The error message is: -------------------------------------------------------------------- Traceback (most recent call last): File "C:\work\python\minidemos\wia_get_simple.py", line 7, in wia = win32com.client.Dispatch("WIA.CommonDialog") File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid class string', None, None) --------------------------------------------------------------------- As I have no knowledge of Win32com and WIA I would appreciate some help or good documentation about wincom32 / WIA with python thanks for your help and bye N From victorsubervi at gmail.com Sun Nov 22 12:39:10 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 22 Nov 2009 12:39:10 -0500 Subject: Scripts Only Run In Root Message-ID: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Hi; I can only run my python scripts on my server if they are owned by root. How do I change that? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sun Nov 22 12:48:45 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 04:48:45 +1100 Subject: Sorting: too different times. Why? In-Reply-To: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> References: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> Message-ID: <4b0979d3$1@dnews.tpgi.com.au> n00m wrote: >> The second part of the compound if is backwards. So if this is headed >> for production code, it better get fixed. >> >> DaveA > > Not sure I'm understanding your remark. Maybe he meant, that this: if v1.x < v2.x and v1.y > v2.y should be: if v1.x < v2.x and v1.y < v2.y ? From lutfioduncuoglu at gmail.com Sun Nov 22 12:59:29 2009 From: lutfioduncuoglu at gmail.com (Lutfi Oduncuoglu) Date: Sun, 22 Nov 2009 19:59:29 +0200 Subject: TypeError: an integer is required Message-ID: Hello, I am a newbie on oython and I am taking the error at subject my code is below, I am trying to develop a qgis plugin and lines begin with # is the thing that I tried. Thus sys.stdout gives the type error. When I comment that line it turns an error like below. What may be the problem? thanks for help:) ...\ReadData.py", line 128, in run print "%d %s" %(k, attr.toString()) IOError: [Errno 9] Bad file descriptor # Import the PyQt and QGIS libraries from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from os import * from qgis.gui import * import sys import pdb # Initialize Qt resources from file resources.py import resources # Import the code for the dialog from ReadDataDialog import ReadDataDialog class ReadData: def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface def initGui(self): # Create action that will start plugin configuration self.action = QAction(QIcon(":/plugins/readdata/icon.png"), \ "Read shp for calculations", self.iface.mainWindow()) # connect the action to the run method QObject.connect(self.action, SIGNAL("triggered()"), self.run) # Add toolbar button and menu item self.iface.addToolBarIcon(self.action) self.iface.addPluginToMenu("&Read shp for calculations", self.action) def unload(self): # Remove the plugin menu item and icon self.iface.removePluginMenu("&Read shp for calculations",self.action) self.iface.removeToolBarIcon(self.action) # run method that performs all the real work def run(self): # fileName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select a file:"),"", "*.shp *.gml") # if fileName.isNull(): # QMessageBox.information(None, "Cancel", "File selection canceled") # else: # print fileName vlayer = QgsVectorLayer("C:\\Users\\lutfi\\Documents\\tezzzz\\deneme2\\ownership.shp", "hebe", "ogr") print vlayer.source() print vlayer.featureCount() QgsMapLayerRegistry.instance().addMapLayer(vlayer) QMessageBox.information(self.iface.mainWindow(), "info", "file: "+str(vlayer.source())+" is added.") if not vlayer.isValid(): print "Couldn't open the layer" pdb.set_trace() else: # QMessageBox.information(None, "Cancel", "File selection canceled") provider = vlayer.dataProvider() feat = QgsFeature() allAttrs = provider.attributeIndexes() provider.select(allAttrs) while provider.nextFeature(feat): geom = feat.geometry() import sys import os # win32api.SetFileAttributes('C://Users//lutfi//Documents//tezzzz//log.txt', win32con.FILE_ATTRIBUTE_NORMAL) # sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt', 777 ) print geom # QMessageBox.information(None, "Cancel", "File selection canceled") print "Feature ID %d: " % feat.id() if geom.type() == QGis.Point: x = geom.asPoint() print "Point: " + str(x) elif geom.type() == QGis.Line: x = geom.asPolyline() print "Line: %d points" % len(x) elif geom.type() == QGis.Polygon: x = geom.asPolygon() numPts = 0 for ring in x: numPts += len(ring) print "Polygon: %d rings with %d points" % (len(x), numPts) else: print "Unknown" attrs = feat.attributeMap() for (k,attr) in attrs.iteritems(): sys.stdout = os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) print "%d %s" %(k, attr.toString()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Sun Nov 22 13:28:43 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 13:28:43 -0500 Subject: Sorting: too different times. Why? In-Reply-To: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> References: <004244fd-c31f-4d50-985e-5d736f1eee39@j24g2000yqa.googlegroups.com> Message-ID: <4B0982DB.8090004@ieee.org> n00m wrote: >> The second part of the compound if is backwards. So if this is headed >> for production code, it better get fixed. >> >> DaveA >> > > Not sure I'm understanding your remark. > > Well, others in the thread have observed the same thing, so maybe it doesn't matter. But the quoted code had only one if statement: >>def v_cmp(v1, v2): >> if v1.x < v2.x and v1.y > v2.y: >> return -1 >> return 0 And the first part of the compound if is a "<" comparison, while the second part is a ">" comparison This produces a different sort order than the default tuple comparison. So it needs fixing. DaveA From python at mrabarnett.plus.com Sun Nov 22 13:29:25 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Nov 2009 18:29:25 +0000 Subject: TypeError: an integer is required In-Reply-To: References: Message-ID: <4B098305.7060901@mrabarnett.plus.com> Lutfi Oduncuoglu wrote: > Hello, > > I am a newbie on oython and I am taking the error at subject my code is > below, I am trying to develop a qgis plugin and lines begin with # is > the thing that I tried. Thus sys.stdout gives the type error. When I > comment that line it turns an error like below. What may be the problem? > thanks for help:) > > ...\ReadData.py", line 128, in run > print "%d %s" %(k, attr.toString()) > IOError: [Errno 9] Bad file descriptor > > [snip] > > for (k,attr) in attrs.iteritems(): > sys.stdout = > os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) > print "%d %s" %(k, attr.toString()) > I think the problem is that you're binding a low-level file id to sys.stdout instead of a file object. Try: sys.stdout = open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) Actually, changing sys.stdout just to use print a single string is a bad idea. Try this instead: log_file = open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) print >> log_file, "%d %s" %(k, attr.toString()) log_file.close() From debatem1 at gmail.com Sun Nov 22 13:36:56 2009 From: debatem1 at gmail.com (geremy condra) Date: Sun, 22 Nov 2009 13:36:56 -0500 Subject: Scripts Only Run In Root In-Reply-To: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Message-ID: On Sun, Nov 22, 2009 at 12:39 PM, Victor Subervi wrote: > Hi; > I can only run my python scripts on my server if they are owned by root. How > do I change that? > TIA, > Victor Almost certainly going to need more information. On that note, you are probably going to get better help with less explaining from the appropriate OS support channels. Geremy Condra From lie.1296 at gmail.com Sun Nov 22 13:41:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 05:41:08 +1100 Subject: Split class across multiple files In-Reply-To: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> References: <9016d6b2-e46e-420f-ab96-c366afe3617e@k17g2000yqh.googlegroups.com> Message-ID: <4b098619$1@dnews.tpgi.com.au> eric.frederich wrote: > I have a class which holds a connection to a server and a bunch of > services. > In this class I have methods that need to work with that connection > and services. > > Right now there are about 50 methods some of which can be quite long. > From an organizational standpoint, I'd like to have method > implementations in their own files. > > Is this possible? It is recommended? Should I just stop worrying > about it and have a 5,000 line class? If you're not joking about the 5000 lines estimation, then with 50 methods, each method would be ~100 lines? That stinks of huge refactoring. From aahz at pythoncraft.com Sun Nov 22 13:44:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Nov 2009 10:44:23 -0800 Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: In article <7ms7ctF3k2a79U1 at mid.individual.net>, Gregory Ewing wrote: > >However, Go's designers seem to favour using the absolute minimum >number of characters they can get away with. > >Although if they *really* wanted that, they would have dropped most of >the semicolons and used indentation-based block structure instead of >curly braces. I would have forgiven them several other sins if they'd >done that. :-) That's essentially my issue with Go based on the code samples I've seen: no over-arching design sensibility at the syntax level. It looks like an aggolomeration of semi-random C-like syntax. There's nothing that shouts out, "This is a Go program," unlike Python, C, and even Perl. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sun Nov 22 13:53:44 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 05:53:44 +1100 Subject: What is the naming convention for accessor of a 'private' variable? In-Reply-To: References: <366c6f340911181827h4d816090u1655dc43b3b6e2ff@mail.gmail.com> <50697b2c0911181847n1a87f39fu2a1686425b756519@mail.gmail.com> Message-ID: <4b09890d$1@dnews.tpgi.com.au> Peng Yu wrote: > On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >>> http://www.python.org/dev/peps/pep-0008/ >>> >>> The above webpage states the following naming convention. Such a >>> variable can be an internal variable in a class. I'm wondering what is >>> the naming convention for the method that access such variable. >>> >>> - _single_leading_underscore: weak "internal use" indicator. E..g. "from M >>> import *" does not import objects whose name starts with an underscore. >> If there's a method to access the variable, then it's not all that >> private, is it? >> Accessor methods are not Pythonic. Just make the attribute public by >> not prefixing it with an underscore. >> >> See also "Python is Not Java": >> http://dirtsimple.org/2004/12/python-is-not-java.html > > I don't quite understand the following paragraph from the above > webpage. Would you please give me an example to help me understand it? > > "Here's what you do. You write a function that contains a function. > The inner function is a template for the functions that you're writing > over and over again, but with variables in it for all the things that > vary from one case of the function to the next. The outer function > takes parameters that have the same names as those variables, and > returns the inner function. Then, every place where you'd otherwise be > writing yet another function, simply call the outer function, and > assign the return value to the name you want the "duplicated" function > to appear. Now, if you need to change how the pattern works, you only > have to change it in one place: the template." Basically it sums to (pun not intended): def adder(by): def _adder(num): return num + by return _adder add4 = adder(4) add10 = adder(10) add35 = adder(35) add1 = adder(1) in java, you'll need to manually duplicate the code, equivalent to doing: def add4(num): return num + 4 def add10(num): return num + 10 def add35(num): return num + 35 def add1(num): return num + 1 or passes two arguments (which completely misses the point). From mwilson at the-wire.com Sun Nov 22 13:57:38 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 22 Nov 2009 13:57:38 -0500 Subject: Sorting: too different times. Why? References: Message-ID: MRAB wrote: > n00m wrote: >> :-) Of course, by "too" I meant "too", as in "tooooo much" > > Although it's OK in English to say "too much x" or "too many x", it's > somewhat unnatural to say "too different xs"; it would have to be "the > xs are too different". Nobody said English was logical! :-) Now that James Joyce has written _Finnegans Wake_ there are no grammar errors and there are no spelling errors. There are only unexpected meanings. Mel. From victorsubervi at gmail.com Sun Nov 22 13:59:39 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 22 Nov 2009 13:59:39 -0500 Subject: Scripts Only Run In Root In-Reply-To: <23739e0a0911221030i3854f0fdhec90e1f88681aed@mail.gmail.com> References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> <23739e0a0911221030i3854f0fdhec90e1f88681aed@mail.gmail.com> Message-ID: <4dc0cfea0911221059t60cce481kf4a2d82da73e3c37@mail.gmail.com> On Sun, Nov 22, 2009 at 1:30 PM, Martijn Arts wrote: > If it's a UNIX server you can use Chown in the command line. Try "man > chown" first to see how it works. > This is strange. I'd tried chown'ing before and was always getting 403 errors. Just to make sure that's what the problem was, I did it again and now it works (?!). Ah, well. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Sun Nov 22 15:33:34 2009 From: rt8396 at gmail.com (r) Date: Sun, 22 Nov 2009 12:33:34 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <35cb6163-0edc-4d4a-a562-4f8fc8a1ebbb@31g2000vbf.googlegroups.com> On Nov 22, 11:32 am, News123 wrote: > Hi, > > I'm trying to scan a document from a python 2.6 script without user > interaction. > > I found a code snippet, that allows me to scan under Vista, but that > doesn't allow me to select the dpi / color mode / etc. > > The snippet uses win32com.client Hello, I would also like to know the answer for which i am investigating now, although like yourself i don't know much about the windows API and the MSDN docs aren't helping much :(. All i can understand is that doing anything in windows is a real PITA! I am sure someone (or many) have climbed this mountain before but all of them seemed to have forgotten to leave us the map that shows the easy way up... bummer! The PyWin32extensions are great but lacking detailed information of how to use the thing. And i know some GUI kits like wxPython have Printer support but thats not really what i am talking about here. I want the functionality directly from Python with only win32extentions needed! We need to extend on the great work of PyWin32 *OR* create a new module that will be an abstraction of the Win32 module. The problem with Windows scripting is all the crap you need to do before you can even set parameters. Get a device context or find some cryptic dispatch code, then mull over some even more cryptic options and such. By now your eyeballs are about to pop out of there sockets and your head is ponding from a massive hemorrhage and yet you still have nothing to show for all this jumping through MS hoops!!! There needs to be a drive to make some docs and post them somewhere. This knowledge must be shared! The best place would be in the PyWin32 docs, but i don't expect the creator will do this, he has given us the vehicle now we must forge the path. I am willing to help create this if someone with even a small amount of win32 knowledge could lend their expertise (any takers? send me an email!). I would write all the Python code to implement these actions very easily. (of course i'm not promising ground breaking code here just something that works, but a hack is better than nothing! I think a good start would be two classes for dealing with Printers and Scanners in a very pythonic way (no device contexts!!!), from there the sky is the limit! ##PRINTING RAW STRING## import win32printer printer = win32printer.get_default() if not printer.online(): showerror('', 'Turn it on first you idiot!') sys.exit(1) printer.options.update({ 'orientation':'landscape', 'font':('Times New', 12), 'header':time.ctime(), }) printer.print_raw_string('hello printer, i have have arrived!') ##SCANNING## import win32scanner scanner = win32scanner.get_default() if not scanner.online(): showerror('', 'Turn it on first you idiot!') sys.exit(1) scanner.options['imagetype'] = '.jpg' scanner.scan(file="C:\\tmp\\image1") ##MORE??## All the device context and cryptic mumbo-gumbo are nicly hidden from the user. Of course there will also be option to show dialogs for user input because that will be needed. With this proposed module the bumbling confusion can be avoided. Joe-Scripter can study the source later to learn Win32 more in depth. Yes people i hate windows too, but for now we all have to deal with Windows like it or not! From nobody at nowhere.com Sun Nov 22 15:35:07 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 22 Nov 2009 20:35:07 +0000 Subject: Imitating "tail -f" References: Message-ID: On Sun, 22 Nov 2009 03:43:31 +0100, Ivan Voras wrote: > The problem is: poll() always returns that the fd is ready (without > waiting), but read() always returns an empty string. Actually, it > doesn't matter if I turn O_NDELAY on or off. select() does the same. Regular files are always "ready" for read/write. read() might return EOF, but it will never block (or fail with EAGAIN or EWOULDBLOCK). > Any advice? The Linux version of "tail" uses the Linux-specific inotify_add_watch() mechanism to block waiting for file-modification events. If you don't have access to inotify_add_watch(), you'll just have to keep trying to read from the file, sleep()ing whenever you hit EOF so that you don't tie up the system with a busy-wait. From nobody at nowhere.com Sun Nov 22 15:41:03 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 22 Nov 2009 20:41:03 +0000 Subject: TypeError: an integer is required References: Message-ID: On Sun, 22 Nov 2009 18:29:25 +0000, MRAB wrote: >> os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) > open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" ) Backslashes need to be doubled; forward slashes don't. From patrickstinson.lists at gmail.com Sun Nov 22 16:38:23 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Sun, 22 Nov 2009 14:38:23 -0700 Subject: xmlrpc idea for getting around the GIL Message-ID: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Has anyone every tried wrapping the CPython lib into a daemon with an RPC mechanism in order to move the GIL out of the process? I have multiple audio threads, each of which use the python interpreter but don't have to interact with each other and can might as well use a separate interpreter handled by a daemon with libpython linked in. I've never used a C xmlrpc lib before and would probably need to set up some shared memory to get it to work. Can anyone suggest a library out there that would at do that sort of thing, maybe with some cross-platform process management? I imagine this is how the multiprocessing module works. From davea at ieee.org Sun Nov 22 16:51:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 22 Nov 2009 16:51:31 -0500 Subject: TypeError: an integer is required In-Reply-To: References: Message-ID: <4B09B263.70206@ieee.org> Lutfi Oduncuoglu wrote: > Hello, > > I am a newbie on oython and I am taking the error at subject my code is > below, I am trying to develop a qgis plugin and lines begin with # is the > thing that I tried. Thus sys.stdout gives the type error. When I comment > that line it turns an error like below. What may be the problem? thanks for > help:) > > ...\ReadData.py", line 128, in run > print "%d %s" %(k, attr.toString()) > IOError: [Errno 9] Bad file descriptor > > (Comment #2 is critical, but I didn't notice it right away. Remove that line "from os import *" and use "import os" instead. ) This error is caused by binding the wrong kind of open to stdout. os.open() returns a file descriptor (integer), while stdout is expected to be a "file" object. As for your previous error "an integer is required" it'd certainly be nice if you showed us the error message. You say it was on a line beginning with "#" but there are many of those, none of them near the present error. Taking a wild guess, I see another open for sys.stdout: sys.stdout = open('C://Users//lutfi//Documents//tezzzz//log.txt', 777 ) But that line causes a "file() argument 2 must be string, not int" error. You want "w" or "a" or something like that, rather than a mysterious 777 for that. Just randomly jumping around in your code, consider what happens if you have the following line: print "%d %s" %(k, attr) and k is a string. Then you'd get: "%d format: a number is required, not str" Well, enough guessing. You need to give a complete traceback, as you did for the "bad file descriptor" And you'd also need to specify Python version, as the messages might be different between your version and the 2.6 that I'm trying it with. Other comments: 1) Are you coming from a java background? In Python you do not need to put everything in a class definition. 2) the "from xxxx import *" form is discouraged, and you use it several times. I know some GUI packages specify it, and there you're best off by following their conventions. But for modules like os, you're asking for trouble. In this case, the built-in open() function that you need is being hidden by the os.open() call, which is not the one you wanted. So you'll get syntax errors and funny runtime errors, just because you're calling different functions that what you think you are. 3) You have import within other defs. This is unnecessary if the module has already been imported (such as sys), and is considered bad form in almost all cases. There are only two common cases where an import might not appear right at the top of the module: A) when you want to conditionally import a module, based on some runtime choice. Example would be to import a Unix version or a Windows version of some module. B) When a module will only be used in some unlikely case, such as in error handling. C) when a module is very slow to import, and you need to speed up startup time. 4) Simplified example code would do two things: A) easier for us to follow, especially those of us that don't happen to use the same libraries that you do. B) by simplifying it, you can frequently find the problem yourself, which is a great way to learn 5) If you have two different error messages, but only have one version of the code, make both tracebacks complete, and make sure we know what's changed between the two versions. HTH, DaveA From fetchinson at googlemail.com Sun Nov 22 16:52:49 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 22 Nov 2009 22:52:49 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Message-ID: > Has anyone every tried wrapping the CPython lib into a daemon with an > RPC mechanism in order to move the GIL out of the process? I have > multiple audio threads, each of which use the python interpreter but > don't have to interact with each other and can might as well use a > separate interpreter handled by a daemon with libpython linked in. > > I've never used a C xmlrpc lib before and would probably need to set > up some shared memory to get it to work. Can anyone suggest a library > out there that would at do that sort of thing, maybe with some > cross-platform process management? > > I imagine this is how the multiprocessing module works. Yes, it does seem you need multiprocessing. That would take advantage of multiple cores and the GIL wouldn't bother you at all. Take a look at http://docs.python.org/library/multiprocessing.html For what you describe (separate tasks running concurrently without communicating) the multiprocessing module would be ideal. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 17:05:08 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 22:05:08 GMT Subject: Sorting: too different times. Why? References: Message-ID: <0319a37d$0$1336$c3e8da3@news.astraweb.com> On Sun, 22 Nov 2009 15:08:28 +0000, Duncan Booth wrote: > n00m wrote: > >> And now it's elephants instead of vectors. Def: an elephant is smarter >> than another one IIF its size is strictly less but its IQ is strictly >> greater >> >> I.e. you can't compare (2, 8) to (20, 50) or let count them as equally >> smart elephants. > > and that still isn't a relationship where you can get any meaningful > order out of sorting them: Not everything has, or need have, a total order. There are relationships which are only partial (i.e. not all the items are comparable), or missing transitivity. A real-world example is pecking order in chickens, or social hierarchies in general. Using the > operator to mean "higher ranking", you often get non-transitive hierarchies like the following: A > B, C, D, E B > C, E C > D, E D > B, E That is, A > B > C > D > E except that D > B also. Economic preference is also non-transitive: people may prefer X to Y, and prefer Y to Z, but prefer Z to X. It is perfectly legitimate to sort a non-total ordered list, provided you understand the limitations, including that the order you get will depend on the order you started with. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Nov 22 17:05:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 22 Nov 2009 22:05:11 GMT Subject: Sorting: too different times. Why? References: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> Message-ID: <0319a381$0$1336$c3e8da3@news.astraweb.com> On Sun, 22 Nov 2009 09:15:57 -0800, n00m wrote: > Or take "Drips" by Eminem. What on earth do the drips mean? When you have a cold or flu, your nose drips. Some sexually transmitted diseases make your genitals drip. -- Steven From deets at nospam.web.de Sun Nov 22 17:15:01 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 22 Nov 2009 23:15:01 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> Message-ID: <7mtrf5F3h153dU1@mid.uni-berlin.de> Daniel Fetchinson schrieb: >> Has anyone every tried wrapping the CPython lib into a daemon with an >> RPC mechanism in order to move the GIL out of the process? I have >> multiple audio threads, each of which use the python interpreter but >> don't have to interact with each other and can might as well use a >> separate interpreter handled by a daemon with libpython linked in. >> >> I've never used a C xmlrpc lib before and would probably need to set >> up some shared memory to get it to work. Can anyone suggest a library >> out there that would at do that sort of thing, maybe with some >> cross-platform process management? >> >> I imagine this is how the multiprocessing module works. > > Yes, it does seem you need multiprocessing. That would take advantage > of multiple cores and the GIL wouldn't bother you at all. Take a look > at > > http://docs.python.org/library/multiprocessing.html > > For what you describe (separate tasks running concurrently without > communicating) the multiprocessing module would be ideal. The problem is that the OP has a embedded application running threads. multiprocssing doesn't help there. Diez From perfreem at gmail.com Sun Nov 22 17:49:01 2009 From: perfreem at gmail.com (per) Date: Sun, 22 Nov 2009 14:49:01 -0800 (PST) Subject: creating pipelines in python Message-ID: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> hi all, i am looking for a python package to make it easier to create a "pipeline" of scripts (all in python). what i do right now is have a set of scripts that produce certain files as output, and i simply have a "master" script that checks at each stage whether the output of the previous script exists, using functions from the os module. this has several flaws and i am sure someone has thought of nice abstractions for making these kind of wrappers easier to write. does anyone have any recommendations for python packages that can do this? thanks. From marcglec at free.fr Sun Nov 22 17:50:43 2009 From: marcglec at free.fr (Marc Leconte) Date: Sun, 22 Nov 2009 23:50:43 +0100 Subject: problem manipulating a list belonging to a class Message-ID: <1258930243.11379.8.camel@gondor> Dear all, I have a problem with the following code (ubuntu 8.04, Python 2.5.2): class Toto(object): def __init__(self, number, mylist=[]): self.number=number self.mylist=mylist pass pass listA=Toto(number=1) listB=Toto(number=2) listA.mylist.append(5) print "1) ", listA.mylist print "2) ", listB.mylist >> 1) [5] >> 2) [5] I would have expected >> 1) [5] >> 2) [] Thanks in advance for advice, Marc. From threaderslash at gmail.com Sun Nov 22 17:52:45 2009 From: threaderslash at gmail.com (Threader Slash) Date: Mon, 23 Nov 2009 09:52:45 +1100 Subject: problem with pyqt.. help please... Message-ID: ---------- Forwarded message ---------- From: Jebagnana Das To: python-list at python.org Date: Sat, 21 Nov 2009 19:17:56 +0530 Subject: problem with pyqt.. help please... Hi friends, I've recently changed to ubuntu 9.04.. I've not had any problem with the installation of pyqt as it is available from the ubuntu repositories with umpteen number of packages.. Anyhow i've to download tarball file for python 3.1 and installed it.. I found that PyQt4 supports python 3.1(Am i right?).. I wanted to check the pyqt installation with a sample program.. import sys from PyQt4 import QtGui app=QtGui.QApplication(sys.argv) widget=QtGui.QWidget() widget.resize(250,150) widget.setWindowTitle('Simple') widget.show() sys.exit(app.exec_()) when i issued the command $python simple.py it worked perfectly since it's executed with 2.6 installation.. But when i tried to execute it with $python3 simple.py it showed the error like ImportError: No module named PyQt4 So i searched the sys.path for 2.6 and included /usr/lib/python2.6/dist-packages in python3 sys.path... Now when i tried to run this with python3 the error is like.. ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined symbol: PyString_FromString I got the same error when i tried to execute another program... So can u please tell me how to solve this problem?? Am i heading in the right direction???... Thanks & Regards... Jebagnanadas, Python Learner.. ........................................... it just looks like your problem is on setting your installation paths. Have a look here: http://www.linux.org/docs/ldp/howto/Nvidia-OpenGL-Configuration/instqt.html http://www.linuxforums.org/forum/debian-linux-help/108948-setting-path-qt.html Check and follow the steps. It should fix your problem. - ThreaderSlash. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Nov 22 18:10:19 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 00:10:19 +0100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: Message-ID: <7mtumsF3jg2qtU1@mid.uni-berlin.de> Marc Leconte schrieb: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass > > listA=Toto(number=1) > listB=Toto(number=2) > > listA.mylist.append(5) > print "1) ", listA.mylist > print "2) ", listB.mylist > >>> 1) [5] >>> 2) [5] > > I would have expected >>> 1) [5] >>> 2) [] http://effbot.org/zone/default-values.htm Diez From showell30 at yahoo.com Sun Nov 22 18:14:00 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 15:14:00 -0800 (PST) Subject: problem manipulating a list belonging to a class References: Message-ID: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> On Nov 22, 2:50?pm, Marc Leconte wrote: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > ? ? ? ? def __init__(self, number, mylist=[]) > ? ? ? ? ? ? ? ? self.number=number > ? ? ? ? ? ? ? ? self.mylist=mylist > ? ? ? ? ? ? ? ? pass > ? ? ? ? pass > Change your code to do this: def __init__(self, number, mylist=None): if mylist is None: self.mylist = [] else: self.mylist = mylist Explanations of why you need to write it that will follow... From showell30 at yahoo.com Sun Nov 22 18:16:42 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 15:16:42 -0800 (PST) Subject: problem manipulating a list belonging to a class References: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> Message-ID: On Nov 22, 3:14?pm, Steve Howell wrote: > Explanations of why you need to write it that will follow... I knew this had to be written up somewhere... http://www.ferg.org/projects/python_gotchas.html#contents_item_6 From knny.myer at gmail.com Sun Nov 22 21:06:50 2009 From: knny.myer at gmail.com (~km) Date: Sun, 22 Nov 2009 18:06:50 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) Message-ID: Hi together, I'm a python-proficient newbie and want to tackle a program with Python 2.x, which basically organizes all my digital books (*.pdf, *.chm, etc..) and to give them specific "labels", such as: "Author" -> string "Read" -> boolean "Last Opened:" -> string and so on.. Now my question is: Is it a better method to use a /database/, a /static File/, with some Markup (e.g.: YAML, XML), a Python dictionary or are there better ways I don't know of.., for organizing my books collection? I'm sure you can do it in any way above, but I'm apelling to /your/ personal experience and preference. Please give me at least one reason, why. --- I think we are in Rats' Alley where the dead men lost their bones. -- T.S. Eliot From lie.1296 at gmail.com Sun Nov 22 21:28:56 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 13:28:56 +1100 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <4b09f3c0$1@dnews.tpgi.com.au> per wrote: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? > > thanks. You're currently implementing a pseudo-pipeline: http://en.wikipedia.org/wiki/Pipeline_%28software%29#Pseudo-pipelines If you want to create a unix-style, byte-stream-oriented pipeline, have all scripts write output to stdout and read from stdin (i.e. read with raw_input and write with print). Since unix pipeline's is byte-oriented you will require parsing the input and formatting the output from/to an agreed format between each scripts. A more general approach could use more than two streams, you can use file-like objects to represent stream. For a more pythonic pipeline, you can rewrite your scripts into generators and use generator/list comprehension that reads objects from a FIFO queue and write objects to another FIFO queue (queue can be implemented using list, but take a look at Queue.Queue in standard modules). Basically an Object Pipeline: http://en.wikipedia.org/wiki/Pipeline_%28software%29#Object_pipelines For unix-style pipeline, you shell/batch scripts is the best tool, though you can also use subprocess module and redirect the process's stdin's and stdout's. For object pipeline, it can't be simpler than simply passing an input and output queue to each scripts. For in-script pipelines (c.f. inter-script pipeline), you can use generator/list comprehension and iterators. There are indeed several modules intended for providing slightly neater syntax than comprehension: http://code.google.com/p/python-pipeline/ though I personally prefer comprehension. From roy at panix.com Sun Nov 22 21:31:07 2009 From: roy at panix.com (Roy Smith) Date: Sun, 22 Nov 2009 18:31:07 -0800 (PST) Subject: Trying to understand += better Message-ID: If I've got an object foo, and I execute: foo.bar += baz exactly what happens if foo does not have a 'bar' attribute? It's pretty clear that foo.__getattr__('bar') gets called first, but it's a little murky after that. Assume for the moment that foo.__getattr__ ('bar') returns an object x. I think the complete sequence of calls is: foo.__getattr__('bar') ==> x x.__add__(baz) ==> y foo.__setattr__('bar', y) but I'm not 100% sure. It would be nice if it was, because that would let me do some very neat magic in a system I'm working on :-) How would things change if X defined __iadd__()? From lie.1296 at gmail.com Sun Nov 22 22:28:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:28:17 +1100 Subject: Trying to understand += better In-Reply-To: References: Message-ID: <4b0a01aa$1@dnews.tpgi.com.au> Roy Smith wrote: > If I've got an object foo, and I execute: > > foo.bar += baz > > exactly what happens if foo does not have a 'bar' attribute? It's > pretty clear that foo.__getattr__('bar') gets called first, but it's a > little murky after that. Assume for the moment that foo.__getattr__ > ('bar') returns an object x. I think the complete sequence of calls > is: > > foo.__getattr__('bar') ==> x > x.__add__(baz) ==> y > foo.__setattr__('bar', y) > > but I'm not 100% sure. It would be nice if it was, because that would > let me do some very neat magic in a system I'm working on :-) > > How would things change if X defined __iadd__()? The semantic of the in-place operator is something like: x += y becomes x = x.__iadd__(y) thus foo.bar += baz becomes foo.bar = foo.bar.__iadd__(baz) So the call sequence is, foo.__getattr__('bar') ==> x x.__iadd__(baz) ==> y foo.__setattr__('bar', y) the default definition of object.__iadd__ is something like this: def __iadd__(self, other): # this calls self.__add__ or other.__radd__ according to the # operator call rule, may call __coerce__ or any other magics # in operator calling return self + other From lie.1296 at gmail.com Sun Nov 22 22:49:51 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:49:51 +1100 Subject: Implementation of Book Organization tool (Python2.[x]) In-Reply-To: References: Message-ID: <4b0a06b8$1@dnews.tpgi.com.au> ~km wrote: > Hi together, > > I'm a python-proficient newbie and want to tackle a program with > Python 2.x, which basically organizes all my digital books (*.pdf, > *.chm, etc..) and to give them specific "labels", such as: > > "Author" -> string > "Read" -> boolean > "Last Opened:" -> string > and so on.. > > Now my question is: > > Is it a better method to use a /database/, a /static File/, with some > Markup (e.g.: YAML, XML), a Python dictionary or are there better ways In high-volume systems, it is almost always better to use a database. Database solves many issues with concurrent access and persistent memory. Though many would disagree, I consider XML as a form of database though it is only suitable for data exchange. XML is suitable for low- to medium-volume purpose and when compatibility with various systems is extremely important (nearly any OS and any programming language has XML parsers; porting a DBMS system may not be as easy as that). Python dictionary is stored in memory and closing the program == deleting the database. You can pickle dictionary; and this might be sufficient for quick and dirty, low-volume purpose. Pickled dictionary is the least portable solution; only python program can open a pickled dictionary and even different versions of python may have incompatibilities. > I > don't know of.., for organizing my books collection? I'm sure you can > do > it in any way above, but I'm apelling to /your/ personal experience > and > preference. Please give me at least one reason, why. For a personal book collection where the number of books is around ~300 books and you don't care about porting to another system, pickled dictionary may be just good enough. From lie.1296 at gmail.com Sun Nov 22 22:55:28 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 14:55:28 +1100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: Message-ID: <4b0a0808$1@dnews.tpgi.com.au> Marc Leconte wrote: > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass Why are you using pass to end your blocks? From showell30 at yahoo.com Sun Nov 22 23:01:46 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 20:01:46 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: On Nov 22, 7:28?pm, Lie Ryan wrote: > Roy Smith wrote: > > If I've got an object foo, and I execute: > > > foo.bar += baz > > > exactly what happens if foo does not have a 'bar' attribute? ?It's > > pretty clear that foo.__getattr__('bar') gets called first, but it's a > > little murky after that. ?Assume for the moment that foo.__getattr__ > > ('bar') returns an object x. ?I think the complete sequence of calls > > is: > > > foo.__getattr__('bar') ?==> x > > x.__add__(baz) ?==> y > > foo.__setattr__('bar', y) > > > but I'm not 100% sure. ?It would be nice if it was, because that would > > let me do some very neat magic in a system I'm working on :-) > > > How would things change if X defined __iadd__()? > > The semantic of the in-place operator is something like: > x += y > becomes > x = x.__iadd__(y) > > thus > foo.bar += baz > becomes > foo.bar = foo.bar.__iadd__(baz) > > So the call sequence is, > foo.__getattr__('bar') ==> x > x.__iadd__(baz) ==> y > foo.__setattr__('bar', y) > > the default definition of object.__iadd__ is something like this: > def __iadd__(self, other): > ? ? ?# this calls self.__add__ or other.__radd__ according to the > ? ? ?# operator call rule, may call __coerce__ or any other magics > ? ? ?# in operator calling > ? ? ?return self + other The __iadd__ method will often return self for mutable types. So, for example, these two statements are NOT identical where lst is a list: lst = lst + [3] lst += [3] The first statement is creating a whole new list; the second one isn't. http://docs.python.org/reference/datamodel.html From showell30 at yahoo.com Sun Nov 22 23:27:34 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 20:27:34 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) References: Message-ID: <0b5f6833-d741-4195-ab38-05d7039138b8@o9g2000prg.googlegroups.com> On Nov 22, 6:06?pm, "~km" wrote: > Hi together, > > I'm a python-proficient newbie and want to tackle a program with > Python 2.x, which basically organizes all my digital books (*.pdf, > *.chm, etc..) and to give them specific "labels", such as: > > "Author" -> string > "Read" -> boolean > "Last Opened:" -> string > and so on.. > > Now my question is: > > Is it a better method to use a /database/, a /static File/, with some > Markup (e.g.: YAML, XML), a Python dictionary or are there better ways > I > don't know of.., for organizing my books collection? I'm sure you can > do > it in any way above, but I'm apelling to /your/ personal experience > and > preference. Please give me at least one reason, why. If your data structure is just a list of dictionaries and you do not have any performance/security issues to consider yet, then you can use pure Python for your input, since it is pretty easy to hand-edit, and then occasionally you could use the PrettyPrinter module to format your data. YAML is another option, as it can offer a slightly cleaner syntax, but I do not think it buys you a whole lot more than that for your use case. Same for JSON--I like JSON but you do not need it right away. PrettyPrinter is batteries included. I would avoid XML and pickle. From roy at panix.com Sun Nov 22 23:38:28 2009 From: roy at panix.com (Roy Smith) Date: Sun, 22 Nov 2009 23:38:28 -0500 Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > The semantic of the in-place operator is something like: > x += y > becomes > x = x.__iadd__(y) > > thus > foo.bar += baz > becomes > foo.bar = foo.bar.__iadd__(baz) > > So the call sequence is, > foo.__getattr__('bar') ==> x > x.__iadd__(baz) ==> y > foo.__setattr__('bar', y) I don't get where the __setattr__() call comes from in this situation. I thought the whole idea of __iadd__(self, other) is that it's supposed to mutate self. So, why is there another assignment happening after the __iadd__() call? From alebezh at gmail.com Sun Nov 22 23:50:36 2009 From: alebezh at gmail.com (=?KOI8-R?B?4czFy9PBzsTSIOLF1sHb18nMyQ==?=) Date: Mon, 23 Nov 2009 07:50:36 +0300 Subject: Amoeba OS and Python Message-ID: <9ed87f7c0911222050t641b8684kbec49d068ff6f766@mail.gmail.com> As I know, Python has been started for Amoeba OS. Did anybody try Python with it? What about speed? Python is so slow for big projects and I try to find a way to accelerate it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From n00m at narod.ru Mon Nov 23 00:11:31 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 21:11:31 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: <34471c3a-722f-4811-beb8-58073e01484f@r31g2000vbi.googlegroups.com> > The first statement is creating a whole new list; Yes but *imo* not quite exactly so. We can't think of 2 lists as of absolutely independent things. ... x = [[0]] ... id(x) 19330632 ... id(x[0]) 19316608 ... z = x + [3] ... id(z) 19330312 ... id(z[0]) 19316608 ... ... z[0] is x[0] # ? True ... x[0][0] = 1 ... ... z[0][0] 1 From n00m at narod.ru Mon Nov 23 00:16:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 22 Nov 2009 21:16:16 -0800 (PST) Subject: Sorting: too different times. Why? References: <8633c2f4-58cb-4124-8235-0dc13b249aa2@s15g2000yqs.googlegroups.com> <0319a381$0$1336$c3e8da3@news.astraweb.com> Message-ID: <122415d7-fe2d-4b43-9464-f22193c4a41b@f10g2000vbl.googlegroups.com> > Some sexually transmitted diseases make your genitals drip. I suspected this :-) Eminem is a famous misogynist From showell30 at yahoo.com Mon Nov 23 00:42:26 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 21:42:26 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> <34471c3a-722f-4811-beb8-58073e01484f@r31g2000vbi.googlegroups.com> Message-ID: <658c3e61-de2e-48ab-8235-7e1ae5a8f22c@v15g2000prn.googlegroups.com> On Nov 22, 9:11?pm, n00m wrote: > > The first statement is creating a whole new list; > > Yes but *imo* not quite exactly so. > We can't think of 2 lists as of absolutely independent > things. > [...] You are correct that two lists can both have the same mutable object as items, and if you mutate that object, both lists will see that mutation. Changing the innards of an item doesn't change the list, if you think of the list as just a collection of ids, but your point is well taken. It is probably easiest to understand all this with a more elaborate example. >>> mutable = {'foo': 'bar'} >>> list1 = [mutable, 'bla'] >>> list2 = list1 + ['another element'] >>> list1 [{'foo': 'bar'}, 'bla'] >>> list2 [{'foo': 'bar'}, 'bla', 'another element'] So list2 and list1 are no longer the same list, but... >>> mutable['foo'] = 'new value for mutable' >>> list1 [{'foo': 'new value for mutable'}, 'bla'] >>> list2 [{'foo': 'new value for mutable'}, 'bla', 'another element'] They do still share a common element, as shown above. But you can reassign the first element of list2 without affecting list1: >>> list2[0] = 'only list 2' >>> list1 [{'foo': 'new value for mutable'}, 'bla'] >>> list2 ['only list 2', 'bla', 'another element'] Now look at fred_list and barney_list below. Since you use +=, fred_list and barney_list stay tied together even when you *think* you are only assigning a new value to barney_list[0]. >>> fred_list = [0] >>> barney_list = fred_list >>> barney_list += [1] >>> barney_list [0, 1] >>> fred_list [0, 1] >>> barney_list[0] = 'barney' >>> barney_list ['barney', 1] >>> fred_list ['barney', 1] From showell30 at yahoo.com Mon Nov 23 00:49:07 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 22 Nov 2009 21:49:07 -0800 (PST) Subject: Trying to understand += better References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: On Nov 22, 8:38?pm, Roy Smith wrote: > In article <4b0a01a... at dnews.tpgi.com.au>, Lie Ryan > wrote: > > > The semantic of the in-place operator is something like: > > x += y > > becomes > > x = x.__iadd__(y) > > > thus > > foo.bar += baz > > becomes > > foo.bar = foo.bar.__iadd__(baz) > > > So the call sequence is, > > foo.__getattr__('bar') ==> x > > x.__iadd__(baz) ==> y > > foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. ?I > thought the whole idea of __iadd__(self, other) is that it's supposed to > mutate self. ?So, why is there another assignment happening after the > __iadd__() call? Non-mutable types can also use += syntax. x = MagicalNumber(42) x += 5 # x gets reassigned to MagicalNumber(47) There is nothing that says that __iadd__ has to return self, but if you are designing a mutable type, you will generally do that. http://docs.python.org/reference/datamodel.html ''' These methods are called to implement the augmented arithmetic assignments (+=, -=, *=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=). These methods should attempt to do the operation in-place (modifying self) and return the result (which could be, but does not have to be, self). If a specific method is not defined, the augmented assignment falls back to the normal methods. For instance, to execute the statement x += y, where x is an instance of a class that has an __iadd__() method, x.__iadd__(y) is called. If x is an instance of a class that does not define a __iadd__() method, x.__add__(y) and y.__radd__(x) are considered, as with the evaluation of x + y. ''' From patrickstinson.lists at gmail.com Mon Nov 23 01:58:16 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Sun, 22 Nov 2009 23:58:16 -0700 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <7mtrf5F3h153dU1@mid.uni-berlin.de> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> Message-ID: <6214d7a20911222258q79a07546h2760798cbed3eeed@mail.gmail.com> that's right. I cannot make CPython calls from my original C-based threads. On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: > Daniel Fetchinson schrieb: >>> >>> Has anyone every tried wrapping the CPython lib into a daemon with an >>> RPC mechanism in order to move the GIL out of the process? I have >>> multiple audio threads, each of which use the python interpreter but >>> don't have to interact with each other and can might as well use a >>> separate interpreter handled by a daemon with libpython linked in. >>> >>> I've never used a C xmlrpc lib before and would probably need to set >>> up some shared memory to get it to work. Can anyone suggest a library >>> out there that would at do that sort of thing, maybe with some >>> cross-platform process management? >>> >>> I imagine this is how the multiprocessing module works. >> >> Yes, it does seem you need multiprocessing. That would take advantage >> of multiple cores and the GIL wouldn't bother you at all. Take a look >> at >> >> http://docs.python.org/library/multiprocessing.html >> >> For what you describe (separate tasks running concurrently without >> communicating) the multiprocessing module would be ideal. > > The problem is that the OP has a embedded application running threads. > multiprocssing doesn't help there. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Mon Nov 23 02:18:58 2009 From: rt8396 at gmail.com (r) Date: Sun, 22 Nov 2009 23:18:58 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: On Nov 22, 11:32?am, News123 wrote: > - This script works fine for me under Windows 7, however I'm > ? unable to ? specify additional parameters, like dpi and > ? color mode. I have found something interesting but have no idea HOW to implement it?? It seems the setting for the scanner are in the registry and must be changed that way or by specifically calling these constants on the device. WIA_IPS_YRES (ScannerPictureYres) Contains the current vertical resolution, in pixels per inch, for the device. An application sets this property to set the vertical resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_XRES (ScannerPictureXres) Contains the current horizontal resolution, in pixels per inch, for the device. An application sets this property to set the horizontal resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_OPTICAL_XRES (ScannerPictureOpticalXres) Note This property is supported only by Windows Vista and later. Horizontal Optical Resolution. Highest supported horizontal optical resolution in DPI. This property is a single value. This is not a list of all resolutions that can be generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items. Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_OPTICAL_YRES (ScannerPictureOpticalYres) Note This property is supported only by Windows Vista and later. Vertical Optical Resolution. Highest supported vertical optical resolution in DPI. This property is a single value. This is not a list of all resolutions that are generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items.Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_BRIGHTNESS (ScannerPictureBrightness) The image brightness values available within the scanner.Contains the current hardware brightness setting for the device. An application sets this property to the hardware's brightness value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_CONTRAST (ScannerPictureContrast) Contains the current hardware contrast setting for a device. An application sets this property to the hardware's contrast value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_ORIENTATION (ScannerPictureOrientation) Specifies the current orientation of the documents to be scanned. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_LIST ------------------------ Image Intent Constants ------------------------ Image intent constants specify what type of data the image is meant to represent. The WIA_IPS_CUR_INTENT scanner property uses these flags. To provide an intent, combine an intended image type flag with an intended size/quality flag by using the OR operator. WIA_INTENT_NONE should not be combined with any other flags. Note that an image cannot be both grayscale and color. WIA_INTENT_IMAGE_TYPE_COLOR (ImageTypeColor) WIA_INTENT_IMAGE_TYPE_GRAYSCALE (ImageTypeGrayscale) WIA_INTENT_IMAGE_TYPE_TEXT (ImageTypeText) WIA_INTENT_MINIMIZE_SIZE (MinimizeSize) WIA_INTENT_MAXIMIZE_QUALITY (MaximizeQuality) WIA_INTENT_BEST_PREVIEW (BestPreview) From lie.1296 at gmail.com Mon Nov 23 02:31:42 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 23 Nov 2009 18:31:42 +1100 Subject: Trying to understand += better In-Reply-To: References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: <4b0a3ab8$1@dnews.tpgi.com.au> Roy Smith wrote: > In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan > wrote: > >> The semantic of the in-place operator is something like: >> x += y >> becomes >> x = x.__iadd__(y) >> >> thus >> foo.bar += baz >> becomes >> foo.bar = foo.bar.__iadd__(baz) >> >> So the call sequence is, >> foo.__getattr__('bar') ==> x >> x.__iadd__(baz) ==> y >> foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. I > thought the whole idea of __iadd__(self, other) is that it's supposed to > mutate self. So, why is there another assignment happening after the > __iadd__() call? The formal name of the __iop__ is "agumented assignment". The name doesn't talk about in-place; but it does talk about assignment. The semantic defines that augmented assignment operation is done in-place *when the left-hand side object supports it* (i.e. it does not require in-place mutation). """ The __iadd__ hook should behave similar to __add__, returning the result of the operation (which *could* be `self') which is to be assigned to the variable `x'. """ For a more complete description, see: http://www.python.org/dev/peps/pep-0203/ From pavlovevidence at gmail.com Mon Nov 23 03:01:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 23 Nov 2009 00:01:16 -0800 (PST) Subject: xmlrpc idea for getting around the GIL References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> Message-ID: <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> On Nov 22, 10:58?pm, Patrick Stinson wrote: > On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: icating) the multiprocessing module would be ideal. > > The problem is that the OP has a embedded application running threads. > > multiprocssing doesn't help there. > > that's right. I cannot make CPython calls from my original C-based threads. It's quite possible to do that. A thread started from C can make calls to Python if it first calls PyGILState_Ensure, although you'd have to make sure that the Python interpreter has been previously initialized. See PEP 311 for details. http://www.python.org/dev/peps/pep-0311/ I also suggest that if you want people to be more receptive to write your replies after the quoted text. That is the custom in this newsgroup/mailing list. Carl Banks From ashwiniyal at gmail.com Mon Nov 23 03:06:26 2009 From: ashwiniyal at gmail.com (ashwini yal) Date: Mon, 23 Nov 2009 13:36:26 +0530 Subject: multitasking Message-ID: <771960b20911230006g268d8495l22db994c76e8ecbb@mail.gmail.com> Hi, I want to know diffrent methods of multitasking supported by python(I want to run diffrent jobs simultaneously at same time) which is the good approach. I know about threads,but i also know that using threads leads to less operational speed. Can someone help me -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Mon Nov 23 03:30:53 2009 From: news123 at free.fr (News123) Date: Mon, 23 Nov 2009 09:30:53 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4B0A483D.9020205@free.fr> Hi r, r wrote: > On Nov 22, 11:32 am, News123 wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N From news123 at free.fr Mon Nov 23 03:31:08 2009 From: news123 at free.fr (News123) Date: Mon, 23 Nov 2009 09:31:08 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4b0a484c$0$8915$426a34cc@news.free.fr> Hi r, r wrote: > On Nov 22, 11:32 am, News123 wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N From robert.kern at gmail.com Mon Nov 23 03:36:33 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 02:36:33 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Aahz wrote: > In article <7ms7ctF3k2a79U1 at mid.individual.net>, > Gregory Ewing wrote: >> However, Go's designers seem to favour using the absolute minimum >> number of characters they can get away with. >> >> Although if they *really* wanted that, they would have dropped most of >> the semicolons and used indentation-based block structure instead of >> curly braces. I would have forgiven them several other sins if they'd >> done that. :-) > > That's essentially my issue with Go based on the code samples I've seen: > no over-arching design sensibility at the syntax level. It looks like an > aggolomeration of semi-random C-like syntax. There's nothing that > shouts out, "This is a Go program," unlike Python, C, and even Perl. I think there is an overall design sensibility, it's just not a human-facing one. They claim that they designed the syntax to be very easily parsed by very simple tools in order to make things like syntax highlighters very easy and robust. So indentation-based blocks are right out. -- 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 Nov 23 03:39:35 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 02:39:35 -0600 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: per wrote: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? You may want to try joblib or ruffus. I haven't had a chance to evaluate either one, though. http://pypi.python.org/pypi/joblib/ http://pypi.python.org/pypi/ruffus/ -- 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 rt8396 at gmail.com Mon Nov 23 03:59:20 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 00:59:20 -0800 (PST) Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> Message-ID: more *maybe useful dump? >>> for i in dev.Items: for p in i.Properties: if not p.IsReadOnly: print p.Name, '->', p.Value Color Profile Name -> sRGB Color Space Profile Brightness -> 0 Contrast -> 0 Private Highlight Level -> 0 Private Midtone Level -> 0 Private Shadow Level -> 0 Private Gamma -> 2200 Private Saturation -> 1000 Private Hue X -> 0 Private Hue Y -> 0 Private Sharpen Level -> 3 Threshold -> 55 Horizontal Resolution -> 200 Vertical Resolution -> 200 Horizontal Start Position -> 0 Vertical Start Position -> 0 Horizontal Extent -> 1700 Vertical Extent -> 2338 Current Intent -> 0 Data Type -> 3 Media Type -> 128 Format -> {B96B3CAA-0728-11D3-9D7B-0000F81EF32E} Private Source Depth -> 0 Private Preview -> 0 Private Exposure Method -> 0 Private Smoothing -> 1 Private Color Enhanced -> 0 Private TMA Method -> 0 >>> dev.DeviceID u'{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000' >>> for p in dev.Properties: print p.Name, '->', p.Value Item Name -> Root Full Item Name -> 0000\Root Item Flags -> 76 Unique Device ID -> {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000 Manufacturer -> Hewlett-Packard Description -> HP Deskjet F300 Type -> 65538 Port -> \\.\Usbscan0 Name -> HP Deskjet F300 Server -> local Remote Device ID -> UI Class ID -> {0A8DC120-D685-4247-9CD1-8712F6BB2DED} Hardware Configuration -> 0 BaudRate -> STI Generic Capabilities -> 48 WIA Version -> 2.0 Driver Version -> 0.0.0.216 PnP ID String -> \\?\usb#vid_03f0&pid_5511&mi_00#6&2def7e7&0&0000# {6bdd1fc6-810f-11d0-bec7-08002be2092f} STI Driver Version -> 2 Horizontal Bed Size -> 8500 Vertical Bed Size -> 11690 Horizontal Bed Registration -> 0 Vertical Bed Registration -> 0 Access Rights -> 3 Horizontal Optical Resolution -> 2400 Vertical Optical Resolution -> 2400 Firmware Version -> 1.0.na Max Scan Time -> 500000 Now how to set the values... hmmm? From paul.nospam at rudin.co.uk Mon Nov 23 04:02:01 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 23 Nov 2009 09:02:01 +0000 Subject: creating pipelines in python References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <87y6lxd37a.fsf@rudin.co.uk> per writes: > hi all, > > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > > does anyone have any recommendations for python packages that can do > this? > Not entirely what you're looking for, but the subprocess module is easier to work with for this sort of thing than os. See e.g. From jarausch at igpm.rwth-aachen.de Mon Nov 23 04:20:30 2009 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: Mon, 23 Nov 2009 10:20:30 +0100 Subject: python regex "negative lookahead assertions" problems In-Reply-To: <4b09534c$0$2868$ba620e4c@news.skynet.be> References: <4b09534c$0$2868$ba620e4c@news.skynet.be> Message-ID: <7mv2eqF3j15m8U1@mid.dfncis.de> On 11/22/09 16:05, Helmut Jarausch wrote: > On 11/22/09 14:58, Jelle Smet wrote: >> Hi List, >> >> I'm trying to match lines in python using the re module. >> The end goal is to have a regex which enables me to skip lines which >> have ok and warning in it. >> But for some reason I can't get negative lookaheads working, the way >> it's explained in "http://docs.python.org/library/re.html". >> >> Consider this example: >> >> Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import re >>>>> line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh >>>>> qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf >>>>> lqsuhf lqksjfhqisudfh qiusdfhq iusfh' >>>>> re.match('.*(?!warning)',line) >> <_sre.SRE_Match object at 0xb75b1598> >> >> I would expect that this would NOT match as it's a negative lookahead >> and warning is in the string. >> > > '.*' eats all of line. Now, when at end of line, there is no 'warning' > anymore, so it matches. > What are you trying to achieve? > > If you just want to single out lines with 'ok' or warning in it, why not > just > if re.search('(ok|warning)') : call_skip > Probably you don't want words like 'joke' to match 'ok'. So, a better regex is if re.search('\b(ok|warning)\b',line) : SKIP_ME Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From wentland at cl.uni-heidelberg.de Mon Nov 23 04:20:35 2009 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Mon, 23 Nov 2009 10:20:35 +0100 Subject: creating pipelines in python In-Reply-To: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com> Message-ID: <20091123092035.GC9247@kinakuta.local> On Sun, Nov 22, 2009 at 14:49 -0800, per wrote: > i am looking for a python package to make it easier to create a > "pipeline" of scripts (all in python). what i do right now is have a > set of scripts that produce certain files as output, and i simply have > a "master" script that checks at each stage whether the output of the > previous script exists, using functions from the os module. this has > several flaws and i am sure someone has thought of nice abstractions > for making these kind of wrappers easier to write. > does anyone have any recommendations for python packages that can do > this? There are various possibilities. I would suggest you have a look at [1] which details the creation of pipelines with generators that can be used within *one* program. If you want to chain different programs together you can use the subprocess package in the stdlib of Python 2.6. [1] http://www.dabeaz.com/generators/ -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From threaderslash at gmail.com Mon Nov 23 04:35:26 2009 From: threaderslash at gmail.com (Threader Slash) Date: Mon, 23 Nov 2009 20:35:26 +1100 Subject: QtPython: removeChild/addChild QGroupBox Message-ID: Hi Everybody, I am developing a system for a customer which is displayed in a set of GroupBox. Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table. Here is a piece of the code that runs nicely and shows the a groupBox. Now it starts to show some effects on removeWidget, but it is still didn't clear the box completely.. just the right border of the box is erased. self.vLayout_wdg = QtGui.QWidget(self.centralwidget) self.vLayout_wdg.setGeometry(QtCore.QRect(40, 160, 171, 121)) self.vLayout_wdg.setObjectName("vLayout_wdg") self.vLayoutBoxObj = QtGui.QVBoxLayout(self.vLayout_wdg) self.vLayoutBoxObj.setObjectName("vLayoutBoxObj") self.newGroupBox = QtGui.QGroupBox(self.vLayout_wdg) self.newGroupBox.setObjectName("newGroupBox") self.radioButton1 = QtGui.QRadioButton(self.newGroupBox) self.radioButton1.setGeometry(QtCore.QRect(30, 30, 101, 21)) self.radioButton1.setObjectName("helloRadioButton") self.radioButton2 = QtGui.QRadioButton(self.newGroupBox) self.radioButton2.setGeometry(QtCore.QRect(30, 60, 111, 18 ) self.radioButton2.setObjectName("niceRadioButton") self.vLayoutBoxObj.addWidget(self.newGroupBox) if removeContainer_Button_Pressed: self.vLayoutBoxObj.removeWidget(self.newGroupBox) self.newGroupBox.adjustSize() self.vLayoutBoxObj.deleteLater() self.vLayoutBoxObj.update() All hints and comments are highly welcome and appreciated. ThreaderSlash -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 23 04:43:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 04:43:01 -0500 Subject: problem manipulating a list belonging to a class In-Reply-To: <1258930243.11379.8.camel@gondor> References: <1258930243.11379.8.camel@gondor> Message-ID: Marc Leconte wrote: > Dear all, > > I have a problem with the following code (ubuntu 8.04, Python 2.5.2): > > class Toto(object): > def __init__(self, number, mylist=[]): > self.number=number > self.mylist=mylist > pass > pass > > listA=Toto(number=1) > listB=Toto(number=2) > > listA.mylist.append(5) > print "1) ", listA.mylist > print "2) ", listB.mylist > >>> 1) [5] >>> 2) [5] > > I would have expected >>> 1) [5] >>> 2) [] > > Thanks in advance for advice, Read the Python FAQ and or the reference manual section on def statements (function definition) which specifically has a paragraph with a bold-face statement explaining this. From srijit at yahoo.com Mon Nov 23 04:51:31 2009 From: srijit at yahoo.com (Srijit Kumar Bhadra) Date: Mon, 23 Nov 2009 01:51:31 -0800 (PST) Subject: lxml 2.2.4 for Python 2.6 Message-ID: <9a80baa0-986d-4c17-bcf2-a32d0bf276bf@z10g2000prh.googlegroups.com> Is there any reason why lxml-2.2.4-py2.6-win32.egg (md5) or lxml-2.2.4.win32-py2.6.exe is not available? Best regards, /Srijit From ajd at malcol.org Mon Nov 23 05:03:07 2009 From: ajd at malcol.org (Andy dixon) Date: Mon, 23 Nov 2009 10:03:07 -0000 Subject: python and Postgresq Message-ID: Hi, Does anyone have a link to, or can provide an example script for using python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can recommend an alternative, that would be fantastic. Thanks! Andy Dixon From deets at nospam.web.de Mon Nov 23 05:22:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 11:22:15 +0100 Subject: python and Postgresq References: Message-ID: <7mv62nF3hp171U1@mid.uni-berlin.de> Andy dixon wrote: > Hi, > > Does anyone have a link to, or can provide an example script for using > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can > recommend an alternative, that would be fantastic. I'd recommend psycopg2. This is an introduction: http://www.devx.com/opensource/Article/29071 But google yields tons more. And make sure you read the python db api 2.0 spec, this should give you the general idea on how to work with Python & RDBMS, which is nicely abstracted away from the actual database. http://www.python.org/dev/peps/pep-0249/ Diez From robin at reportlab.com Mon Nov 23 05:35:31 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 Nov 2009 10:35:31 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B0A6573.8070005@chamonix.reportlab.co.uk> sturlamolden wrote: > On 20 Nov, 11:12, Robin Becker wrote: > >> Presumably that means they could potentially run in parallel on the 100000 cpu >> machines of the future. >> >> I'm not so clear on whether the threadless tasklets will run on separate cpus. > > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. > ....... not really sure about all the parallelism that will actually be achievable, but apparently the goroutines are multiplexed onto native threads by the run time. Apparently each real thread is run until it blocks and then another goroutine is allowed to make use of the thread. Apparently the gccgo runtime has 1 goroutine per thread and is different to the fast compilers. -- Robin Becker From robin at reportlab.com Mon Nov 23 05:35:31 2009 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 Nov 2009 10:35:31 +0000 Subject: python simply not scaleable enough for google? In-Reply-To: References: Message-ID: <4B0A6573.8070005@chamonix.reportlab.co.uk> sturlamolden wrote: > On 20 Nov, 11:12, Robin Becker wrote: > >> Presumably that means they could potentially run in parallel on the 100000 cpu >> machines of the future. >> >> I'm not so clear on whether the threadless tasklets will run on separate cpus. > > You can make a user-space scheduler and run a 100000 tasklets on a > threadpool. But there is a GIL in stackless as well. > > Nobody wants 100000 OS threads, not with Python, not with Go, not with > C. > > Also note that Windows has native support for "taskelets", regardless > of language. They are called "fibers" (as opposed to "threads") and > are created using the CreateFiber system call. I would not be > surprised if Unix'es has this as well. We do not need Stackless for > light-weight threads. We can just take Python's threading modules' C > code and replace CreateThread with CreateFiber. > ....... not really sure about all the parallelism that will actually be achievable, but apparently the goroutines are multiplexed onto native threads by the run time. Apparently each real thread is run until it blocks and then another goroutine is allowed to make use of the thread. Apparently the gccgo runtime has 1 goroutine per thread and is different to the fast compilers. -- Robin Becker From ajd at malcol.org Mon Nov 23 05:36:26 2009 From: ajd at malcol.org (Andy dixon) Date: Mon, 23 Nov 2009 10:36:26 -0000 Subject: python and Postgresq In-Reply-To: <7mv62nF3hp171U1@mid.uni-berlin.de> References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" wrote in message news:7mv62nF3hp171U1 at mid.uni-berlin.de... > Andy dixon wrote: > >> Hi, >> >> Does anyone have a link to, or can provide an example script for using >> python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone >> can >> recommend an alternative, that would be fantastic. > > I'd recommend psycopg2. > > This is an introduction: > > http://www.devx.com/opensource/Article/29071 > > But google yields tons more. And make sure you read the python db api 2.0 > spec, this should give you the general idea on how to work with Python & > RDBMS, which is nicely abstracted away from the actual database. > > http://www.python.org/dev/peps/pep-0249/ > > Diez Amazing. Works like a charm! Thanks.. I used the code (stripping out certain bits) if anyone else may find it useful: #!/usr/bin/env python import psycopg def main(): connection = psycopg.connect('host= dbname= user= password=') mark = connection.cursor() query='SELECT * FROM table' mark.execute(query) record = mark.fetchall() for i in record: print i return if __name__ == '__main__': main() From solipsis at pitrou.net Mon Nov 23 05:47:13 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 23 Nov 2009 10:47:13 +0000 (UTC) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit?: > > I think there is an overall design sensibility, it's just not a > human-facing one. They claim that they designed the syntax to be very > easily parsed by very simple tools in order to make things like syntax > highlighters very easy and robust. So indentation-based blocks are right > out. But computer languages should be designed to be readable by humans. It's not like you need to write a new parser once a year, but you have to read code everyday. Besides, if you want parsing to be easy, you don't need to make the syntax minimal, you just have to provide the parsing routines as part of the standard library and/or of an external API. From victorsubervi at gmail.com Mon Nov 23 05:47:20 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 05:47:20 -0500 Subject: Switching Databases Message-ID: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Hi; I have the following code: import MySQLdb ... user, passwd, db, host = login() db = MySQLdb.connect(host, user, passwd, 'cart') cursor= db.cursor() ... cursor.close() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() Now, python complains about me opening a new connection. But I thought I'd closed the first one! So, I replaced the last 3 lines with this: cursor.execute('use %s;' % db) but it didn't like that, either. Any way to switch databases? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From gh at ghaering.de Mon Nov 23 05:49:29 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 23 Nov 2009 11:49:29 +0100 Subject: Python & OpenOffice Spreadsheets Message-ID: Is there a *simple* way to read OpenOffice spreadsheets? Bonus: write them, too? I mean something like: doc.cells[0][0] = "foo" doc.save("xyz.ods") >From a quick look, pyodf offers little more than just using a XML parser directly. -- Gerhard From ben+python at benfinney.id.au Mon Nov 23 06:01:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 23 Nov 2009 22:01:54 +1100 Subject: python and Postgresq References: Message-ID: <873a45a4il.fsf@benfinney.id.au> "Andy dixon" writes: > Does anyone have a link to, or can provide an example script for using > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone > can recommend an alternative, that would be fantastic. "Diez B. Roggisch" writes: > I'd recommend psycopg2. I'd recommend installing ?psycopg2?, but using it at a slight distance by installing ?SQLAlchemy? to give a useful Pythonic access layer while having full access to SQL whenever needed. -- \ ?People come up to me and say, ?Emo, do people really come up | `\ to you??? ?Emo Philips | _o__) | Ben Finney From paul.nospam at rudin.co.uk Mon Nov 23 06:12:37 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 23 Nov 2009 11:12:37 +0000 Subject: Python & OpenOffice Spreadsheets References: Message-ID: <87pr79cx5m.fsf@rudin.co.uk> Gerhard H?ring writes: > Is there a *simple* way to read OpenOffice spreadsheets? > > Bonus: write them, too? > > I mean something like: > > doc.cells[0][0] = "foo" > doc.save("xyz.ods") > >>From a quick look, pyodf offers little more than just using a XML parser > directly. Depends on exactly what you mean by "simple" - but pyuno allows you to read and write openoffice spreadsheets. From hackingkk at gmail.com Mon Nov 23 06:20:04 2009 From: hackingkk at gmail.com (Krishnakant) Date: Mon, 23 Nov 2009 16:50:04 +0530 Subject: python and Postgresq In-Reply-To: <7mv62nF3hp171U1@mid.uni-berlin.de> References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: <1258975204.3770.7.camel@krishna-laptop> On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote: > Andy dixon wrote: > > > Hi, > > > > Does anyone have a link to, or can provide an example script for using > > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can > > recommend an alternative, that would be fantastic. > > I'd recommend psycopg2. > > This is an introduction: > > http://www.devx.com/opensource/Article/29071 > > But google yields tons more. And make sure you read the python db api 2.0 > spec, this should give you the general idea on how to work with Python & > RDBMS, which is nicely abstracted away from the actual database. Python-pgsql is a much better choice when it comes to big applications, specially if you are going to deal with xml-rpc. I have found that python-pgsql handles integers and other such postgresql datatypes better. Happy hacking. Krishnakant. From hackingkk at gmail.com Mon Nov 23 06:25:07 2009 From: hackingkk at gmail.com (Krishnakant) Date: Mon, 23 Nov 2009 16:55:07 +0530 Subject: Python & OpenOffice Spreadsheets In-Reply-To: <87pr79cx5m.fsf@rudin.co.uk> References: <87pr79cx5m.fsf@rudin.co.uk> Message-ID: <1258975507.3770.10.camel@krishna-laptop> On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: > Gerhard H?ring writes: > > > Is there a *simple* way to read OpenOffice spreadsheets? > > > > Bonus: write them, too? > > > > I mean something like: > > > > doc.cells[0][0] = "foo" > > doc.save("xyz.ods") > > > >>From a quick look, pyodf offers little more than just using a XML parser > > directly. > > > Depends on exactly what you mean by "simple" - but pyuno allows you to > read and write openoffice spreadsheets. Odfpy is a good module and is easy too. http://kk.hipatia.net/public/gnukhata/gnukhata-client/ has a deb package I built for ubuntu 9.04. I can even provide you the distutils tarball off the list (because I can't recall the url from I downloaded it, may be sourceforge ). Happy hacking. Krishnakant From deets at nospam.web.de Mon Nov 23 06:37:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 12:37:36 +0100 Subject: python and Postgresq References: <7mv62nF3hp171U1@mid.uni-berlin.de> Message-ID: <7mvag0F3iacc0U1@mid.uni-berlin.de> Krishnakant wrote: > On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote: >> Andy dixon wrote: >> >> > Hi, >> > >> > Does anyone have a link to, or can provide an example script for using >> > python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone >> > can recommend an alternative, that would be fantastic. >> >> I'd recommend psycopg2. >> >> This is an introduction: >> >> http://www.devx.com/opensource/Article/29071 >> >> But google yields tons more. And make sure you read the python db api 2.0 >> spec, this should give you the general idea on how to work with Python & >> RDBMS, which is nicely abstracted away from the actual database. > > Python-pgsql is a much better choice when it comes to big applications, > specially if you are going to deal with xml-rpc. I have found that > python-pgsql handles integers and other such postgresql datatypes > better. Where is the connection between XMLRPC and psql? And can you elaborate on what and how pgsql handles things better than psycopg2? Diez From m.shanmugarajan at gmail.com Mon Nov 23 07:16:49 2009 From: m.shanmugarajan at gmail.com (Shan) Date: Mon, 23 Nov 2009 04:16:49 -0800 (PST) Subject: python and netezza Message-ID: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> Is there any module in python to connect with netezza database?(like cx_Oracle which is used to connect Oracle from python) Thanks for any help. - Shan From chris at simplistix.co.uk Mon Nov 23 07:18:37 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 23 Nov 2009 12:18:37 +0000 Subject: Python & OpenOffice Spreadsheets In-Reply-To: References: Message-ID: <4B0A7D9D.10803@simplistix.co.uk> Gerhard H?ring wrote: > Is there a *simple* way to read OpenOffice spreadsheets? Ironically, if you don't mind working in .xls, which OpenOffice handles just fine, you have xlrd and xlwt to do exactly what you're after: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From mail at anjanesh.net Mon Nov 23 08:07:57 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 18:37:57 +0530 Subject: print function in python3.1 Message-ID: <1a7951080911230507v1273f4c3jd4efe794d9daa084@mail.gmail.com> Python 3.1.1 sql = "INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s');" for row in fp: print (sql, (row[0],row[1],row[2],row[3],row[4])) . INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', 'abc', '2006-04-09 02:19:24', '', '') . Why is it showing %s in the output ? 1. I dont want to sql % () because that doesnt escape the strings 2. I cant use conn.escape_string(r) because Im not connected to a database. Output script to file and import to database loated elsewhere. -- Anjanesh Lekshmnarayanan From deets at nospam.web.de Mon Nov 23 08:16:08 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 14:16:08 +0100 Subject: print function in python3.1 References: Message-ID: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: > Python 3.1.1 > > sql = "INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s');" > for row in fp: > print (sql, (row[0],row[1],row[2],row[3],row[4])) > . > INSERT INTO `tbl` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', > 'abc', '2006-04-09 02:19:24', '', '') > . > Why is it showing %s in the output ? Because you gave it to it. How should it know that you want the %s to be replaced with the other parameters? That's what the %-operator is for. > > 1. I dont want to sql % () because that doesnt escape the strings > 2. I cant use conn.escape_string(r) because Im not connected to a > database. Output script to file and import to database loated > elsewhere. Depending on your DB-adapter, you are out of luck here. Either connect to a db even if you don't need it, or try & see if you can locate the implementation in the module somehow. E.g. MySQLdb has the function exposed as "escape_string", not only on a connection. Diez From bschollnick at gmail.com Mon Nov 23 08:26:18 2009 From: bschollnick at gmail.com (Benjamin Schollnick) Date: Mon, 23 Nov 2009 05:26:18 -0800 (PST) Subject: Perl conversion to python... Message-ID: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com> Folks, I'm having some issues here with pyserial & trying to translate a perl script to python... It's probably my inexperience with PySerial & perl that is troubling me... Can anyone assist? I'm concerned, since I can't seem to receive the data in any reliable manner.. I've tested multiple times, and only once received data... So I suspect that my Transmit & receive code is faulty... def xmit ( data, serialport ): for x in data: xmit_byte (x, serialport) # serialport.write ( binascii.unhexlify ( data ) ) # for x in data: # print str(x).encode ('hex') # serialport.write ( x.encode('hex')) def receive ( serialport ): received = serialport.read (20) print received, "!" ----- Perl Code ---- sub tx_command { my $port = shift; my $cmd = shift; # warn "tx_command($cmd)\n"; my @cmd_bytes = split(/\s/, $cmd); foreach my $byte (@cmd_bytes) { $byte = pack('C', hex($byte)); $port -> write($byte); select(undef, undef, undef, 0.01); } } # returns the rtt, or 0 if no response sub rx_response { my ($port, $address) = @_; $port->read_char_time(0); # don't wait for each character $port->read_const_time(5000); # timeout if we don't get what we're looking for my $buf = ''; my $t_start = time; ### accumulate one byte at a time until we see the substring we're looking for while (1) { my ($count_in, $string_in) = $port->read(1); if ($count_in == 0) { # warn "TIMEOUT\n"; return 0; } $buf .= $string_in; my $bufstring = packed_to_text($buf); #warn "bufstring: ".$bufstring; if ($bufstring =~/02 50 $address (.. .. ..) (..) (.. ..)/) { my $powerlinc_addr = $1; my $flags = $2; my $command = $3; # warn "got response!\n"; my $rtt = time() - $t_start; return $rtt; } } } From joost at h-labahn.de Mon Nov 23 08:37:10 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 05:37:10 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, code-inlining Pixbufs Message-ID: <4690c694-1c7e-4b83-a818-bf98fe8e6e34@t18g2000vbj.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving the utf-8-code sqlite works with alone. And in the long run one of the python-API of the monet database perhaps A preprocessor macro -DDEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this source code would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by pythons distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a little bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro -DDEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter(). Admittedly this isn't really tested now. Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now.. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable but python's array.array.fromstring() and array.array.tostring() are used to provide a well readable and well code-usable representation of these bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) back-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From mail at anjanesh.net Mon Nov 23 08:54:18 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 19:24:18 +0530 Subject: print function in python3.1 In-Reply-To: <7mvg8oF3jof5mU1@mid.uni-berlin.de> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Message-ID: <1a7951080911230554l39ab3eeax16c2ebf3fc8a3a6e@mail.gmail.com> > Depending on your DB-adapter, you are out of luck here. Either connect to a db even if you don't need it, or try & see if you can locate the implementation in the module somehow. ImportError: No module named MySQLdb MySQLdb only available in Python2. -- Anjanesh Lekshmnarayanan From liuxin9023 at gmail.com Mon Nov 23 09:10:03 2009 From: liuxin9023 at gmail.com (liuxin9023 at gmail.com) Date: Mon, 23 Nov 2009 06:10:03 -0800 (PST) Subject: Scripts Only Run In Root References: <4dc0cfea0911220939t6869ef34x7a1c09f2f5409db8@mail.gmail.com> Message-ID: <15228b61-acef-49b0-8b05-3388782d9186@u25g2000prh.googlegroups.com> On Nov 23, 2:36?am, geremy condra wrote: > On Sun, Nov 22, 2009 at 12:39 PM, Victor Subervi > > wrote: > > Hi; > > I can only run my python scripts on my server if they are owned by root. How > > do I change that? > > TIA, > > Victor > > Almost certainly going to need more information. On that note, you are > probably going to get better help with less explaining from the appropriate > OS support channels. > > Geremy Condra I guess you are using *inux. Maybe you don't have enough permission, what you need to do is to change the permission. From deets at nospam.web.de Mon Nov 23 09:10:10 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 15:10:10 +0100 Subject: print function in python3.1 References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> Message-ID: <7mvje2F3inifiU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: >> Depending on your DB-adapter, you are out of luck here. Either connect to >> a db even if you don't need it, or try & see if you can locate the >> implementation in the module somehow. > > ImportError: No module named MySQLdb > MySQLdb only available in Python2. > I don't have the slightest clue what you want to say with that. Diez From joost at h-labahn.de Mon Nov 23 09:12:10 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:12:10 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <1c6296e3-ab9c-4d27-acdd-1d07820a68db@p32g2000vbi.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving the utf-8-code sqlite works with alone. And in the long run one of the python-API of the monet database perhaps A preprocessor macro -DDEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this source code would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a little bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter(). Admittedly gtk-threads aren't really intensively now. Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of these bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) back-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From carsten.haese at gmail.com Mon Nov 23 09:17:44 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 09:17:44 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Message-ID: Victor Subervi wrote: > Hi; > I have the following code: > > import MySQLdb > ... > user, passwd, db, host = login() > db = MySQLdb.connect(host, user, passwd, 'cart') > cursor= db.cursor() > ... > cursor.close() > db = MySQLdb.connect(host, user, passwd, db) > cursor= db.cursor() > > Now, python complains about me opening a new connection. Do not paraphrase error messages. Copy and paste the actual error message and traceback. > But I thought > I'd closed the first one! You thought you did, but did you? The code snippet above doesn't show any code that closes a database connection. > So, I replaced the last 3 lines with this: > > cursor.execute('use %s;' % db) > > but it didn't like that, either. Do not paraphrase error messages. Copy and paste the actual error message and traceback. -- Carsten Haese http://informixdb.sourceforge.net From joost at h-labahn.de Mon Nov 23 09:22:49 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:22:49 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <28a69bfb-f9d1-4ff6-8ae9-c080343c96d5@31g2000vbf.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk-threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From joost at h-labahn.de Mon Nov 23 09:27:38 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:27:38 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <64d2dd31-299d-4a88-a106-0d2273c26f4b@o9g2000vbj.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From mail at anjanesh.net Mon Nov 23 09:27:40 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 19:57:40 +0530 Subject: print function in python3.1 In-Reply-To: <7mvje2F3inifiU1@mid.uni-berlin.de> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> Message-ID: <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> As of now, there is no mysql adaptor for Python3. Hence cant use escape_string() > I don't have the slightest clue what you want to say with that. -- Anjanesh Lekshmnarayanan From joost at h-labahn.de Mon Nov 23 09:30:29 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:30:29 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From joost at h-labahn.de Mon Nov 23 09:33:27 2009 From: joost at h-labahn.de (DreiJane) Date: Mon, 23 Nov 2009 06:33:27 -0800 (PST) Subject: depikt (gtk-wrappers): Threads, inlining Pixbufs to python code Message-ID: <3d72a0d4-a437-4ced-ac00-14ca48ad5f4f@o31g2000vbi.googlegroups.com> Hello, these days i make depikt, my replacement of pygtk. There are several reasons to do this: - Support for Python3 - Exact control of encoding issues. I myself (a German) hope to abandon with any python unicode objects forever in future - that is, why Python3 is an important improvement for me. I'll also make a version of apsw leaving alone the utf-8 sqlite works with. And in the long run perhaps one of the python-API of the monet database. A preprocessor macro DEPIKT_USES_BYTES decides, whether depikt communicates with python via bytes or (unicode) strings - the actual setting in setup.py is, that DEPIKT_USES_BYTES is defined. - Readability and changability of code. pygtk's hundreds of files are too much for me - since i will make own widgets with C, not python, the work of understanding this would be wasted for me. All the more, as pygtk's sources are templates for an own templating system, not .c-files - can this really be called "open source" ? - "Ambulancy". All other tools i use can be installed by simple copying (or compiling via distutils without autoconf) without admin rights: eclipse with pydev, mingw, gcc4.4, apsw, cython, gtk are "ambulant". Only setting the environment variable PATH in a local environment is needed for gtk. Not so pygtk: It searches for python in the windows registry or has to be compiled with autoconf. There are not neglectable traces of trouble with installing pygtk on the web. A drawback: To install depikt you must compile it. But by python's distutils, which make compiling absolutely easy. Still you have to edit the provided setup.py, i will not automatize the use of the output of pkg-config for gtk. But that really doesn't need much C- knowledge (a bit knowledge of how C-compilers work is essential though). depikt comes with new features: depikt.gdk_threads_enter (and leave) is supported. Again controlled by a preprocessor macro DEPIKT_SUPPORTS_THREADS. #ifdef DEPIKT_SUPPORTS_THREADS (what is the default), each gtk.main() has to be prepended by depikt.gdk_threads_enter() and - with more than one - must be followed by gdk_threads_leave(). Admittedly gtk threads aren't really intensively tested now (but gdk_threads_enter is only protecting values in the thread's namespace and is safely ignored, when gtk is initialized without support for threads). Since you must arrange setup.py anyway to use depikt, these macros are no obstacle. Nevertheless i will keep the number of such preprocessor #defines small (certainly below 10). depikt also provides a way of inlining icons (and images at all) in python code now. depikt.gdk_Pixbuf.serialize() renders gdk.pixbufs to a representation in bytes objects of Python3. These are not really well readable or usable, but python's array.array.fromstring() and array.array.tostring() are used to provide well readable and well code-usable representations of those bytes objects. There is PixbufLister.py in tools.tgz now, creating those array-representations (arrays of unsigned 8-bit-ints). Again Python3 is essential here. depikt also provides the standard dialogs in tools.tgz now - they use a serialized (and public domain) "back"-icon of WindowsXP. The script Dialogs.py is also a severe test of depikt's usability, since using moreover grandchildren of depikt.Window and python threads - unfortunately this script crashes sometimes due to the bad support for widget destruction in depikt. Again: I urgently need depikt for a large python project. Adapting depikt for it will make depikt better usable and really stable sometimes in 2010. depikt will prevail. There is no way for me without depikt. Thanks for reading, DreiJane From carsten.haese at gmail.com Mon Nov 23 09:40:30 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 09:40:30 -0500 Subject: print function in python3.1 In-Reply-To: <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: > As of now, there is no mysql adaptor for Python3. Hence cant use escape_string() Maybe it would help if you explained what you are actually trying to accomplish. -- Carsten Haese http://informixdb.sourceforge.net From victorsubervi at gmail.com Mon Nov 23 09:45:36 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 09:45:36 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> Message-ID: <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> On Mon, Nov 23, 2009 at 9:17 AM, Carsten Haese wrote: > You thought you did, but did you? The code snippet above doesn't show > any code that closes a database connection. > Would you be so kind as to tell me exactly what code *does* close a database, then? That would solve this handily. Other than than, when I am at a computer when I can provide you error messages, I will, but it all boils down to that code that closes the database, doesn't it? Since my code, according to you (and it seems logical) didn't, I sure would appreciate your providing the correct code that would. Thank you, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From carsten.haese at gmail.com Mon Nov 23 10:08:36 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 10:08:36 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Mon, Nov 23, 2009 at 9:17 AM, Carsten Haese > wrote: > > You thought you did, but did you? The code snippet above doesn't show > any code that closes a database connection. > > > Would you be so kind as to tell me exactly what code *does* close a > database, then? Assuming that db is the name of the database connection object, db.close() closes the connection. > That would solve this handily. Other than than, when I > am at a computer when I can provide you error messages, I will, but it > all boils down to that code that closes the database, doesn't it? Only if your diagnosis of the problem is accurate, and I have my doubts about that. A MySQL database server is perfectly capable of entertaining multiple simultaneous connections, so I find it unlikely that your inability to open a second connection is caused by not closing the first connection. As I said, the best way we can help you is if you copy the actual error message so that we may diagnose the actual problem and suggest a solution that fixes the problem. -- Carsten Haese http://informixdb.sourceforge.net From brendandetracey at yahoo.com Mon Nov 23 10:22:25 2009 From: brendandetracey at yahoo.com (Brendan) Date: Mon, 23 Nov 2009 07:22:25 -0800 (PST) Subject: KirbyBase : replacing string exceptions Message-ID: In KirbyBase there is a method that uses string exceptions for control, even though it has a defined exception. Is there any reason the string exceptions below could not be replaced? i.e. in code below replace: raise "No Match" with: raise KBError() and except 'No Match': with: except KBError: I have pasted the relevant method and the class definition of KBError below #---------------------------------------------------------------------- # _getMatches #---------------------------------------------------------------------- def _getMatches(self, fptr, fields, patterns, useRegExp): # Initialize a list to hold all records that match the search # criteria. match_list = [] # If one of the fields to search on is 'recno', which is the # table's primary key, then search just on that field and return # at most one record. if 'recno' in fields: return self._getMatchByRecno(fptr,patterns) # Otherwise, search table, using all search fields and patterns # specified in arguments lists. else: new_patterns = [] fieldNrs = [self.field_names.index(x) for x in fields] for fieldPos, pattern in zip(fieldNrs, patterns): if self.field_types[fieldPos] == str: # If useRegExp is True, compile the pattern to a # regular expression object and add it to the # new_patterns list. Otherwise, just add it to # the new_patterns list. This will be used below # when matching table records against the patterns. if useRegExp: new_patterns.append(re.compile(pattern)) # the pattern can be a tuple with re flags like re.I else: new_patterns.append(pattern) elif self.field_types[fieldPos] == bool: # If type is boolean, I am going to coerce it to be # either True or False by applying bool to it. This # is because it could be '' or []. Next, I am going # to convert it to the string representation: either # 'True' or 'False'. The reason I do this is because # that is how it is stored in each record of the table # and it is a lot faster to change this one value from # boolean to string than to change possibly thousands # of table values from string to boolean. And, if they # both are either 'True' or 'False' I can still # compare them using the equality test and get the same # result as if they were both booleans. new_patterns.append(str(bool(pattern))) else: # If type is int, float, date, or datetime, this next # bit of code will split the the comparison string # into the string representing the comparison # operator (i.e. ">=" and the actual value we are going # to compare the table records against from the input # pattern, (i.e. "5"). So, for example, ">5" would be # split into ">" and "5". r = re.search('[\s]*[\+-]?\d', pattern) if self.field_types[fieldPos] == int: patternValue = int(pattern[r.start():]) elif self.field_types[fieldPos] == float: patternValue = float(pattern[r.start():]) else: patternValue = pattern[r.start():] new_patterns.append( [self.cmpFuncs[pattern[:r.start()]], patternValue] ) fieldPos_new_patterns = zip(fieldNrs, new_patterns) maxfield = max(fieldNrs)+1 # Record current position in table. Then read first detail # record. fpos = fptr.tell() line = fptr.readline() # Loop through entire table. while line: # Strip off newline character and any trailing spaces. line = line[:-1].strip() try: # If blank line, skip this record. if line == "": raise 'No Match' # Split the line up into fields. record = line.split("|", maxfield) # Foreach correspond field and pattern, check to see # if the table record's field matches successfully. for fieldPos, pattern in fieldPos_new_patterns: # If the field type is string, it # must be an exact match or a regular expression, # so we will compare the table record's field to it # using either '==' or the regular expression # engine. Since it is a string field, we will need # to run it through the unencodeString function to # change any special characters back to their # original values. if self.field_types[fieldPos] == str: try: if useRegExp: if not pattern.search( self._unencodeString(record [fieldPos]) ): raise 'No Match' else: if record[fieldPos] != pattern: raise 'No Match' except Exception: raise KBError( 'Invalid match expression for %s' % self.field_names[fieldPos]) # If the field type is boolean, then I will simply # do an equality comparison. See comments above # about why I am actually doing a string compare # here rather than a boolean compare. elif self.field_types[fieldPos] == bool: if record[fieldPos] != pattern: raise 'No Match' # If it is not a string or a boolean, then it must # be a number or a date. else: # Convert the table's field value, which is a # string, back into it's native type so that # we can do the comparison. if record[fieldPos] == '': tableValue = None elif self.field_types[fieldPos] == int: tableValue = int(record[fieldPos]) elif self.field_types[fieldPos] == float: tableValue = float(record[fieldPos]) # I don't convert datetime values from strings # back into their native types because it is # faster to just leave them as strings and # convert the comparison value that the user # supplied into a string. Comparing the two # strings works out the same as comparing two # datetime values anyway. elif self.field_types[fieldPos] in ( datetime.date, datetime.datetime): tableValue = record[fieldPos] else: # If it falls through to here, then, # somehow, a bad field type got put into # the table and we show an error. raise KBError('Invalid field type for %s' % self.field_names[fieldPos]) # Now we do the actual comparison. I used to # just do an eval against the pattern string # here, but I found that eval's are VERY slow. # So, now I determine what type of comparison # they are trying to do and I do it directly. # This sped up queries by 40%. if not pattern[0](tableValue, pattern[1]): raise 'No Match' # If a 'No Match' exception was raised, then go to the # next record, otherwise, add it to the list of matches. except 'No Match': pass else: match_list.append([line, fpos]) # Save the file position BEFORE we read the next record, # because after a read it is pointing at the END of the # current record, which, of course, is also the BEGINNING # of the next record. That's why we have to save the # position BEFORE we read the next record. fpos = fptr.tell() line = fptr.readline() # After searching, return the list of matched records. return match_list #---------------------------------------------------------------------- #-------------------------------------------------------------------------- # KBError Class #-------------------------------------------------------------------------- class KBError(Exception): """Exception class for Database Management System. Public Methods: __init__ - Create an instance of exception. """ #---------------------------------------------------------------------- # init #---------------------------------------------------------------------- def __init__(self, value): self.value = value def __str__(self): return `self.value` # I overrode repr so I could pass error objects from the server to the # client across the network. def __repr__(self): format = """KBError("%s")""" return format % (self.value) From victorsubervi at gmail.com Mon Nov 23 10:26:57 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 10:26:57 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> Message-ID: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> On Mon, Nov 23, 2009 at 10:08 AM, Carsten Haese wrote: > As I said, the best way we can help you is if you copy the actual error > message so that we may diagnose the actual problem and suggest a > solution that fixes the problem. > That gave me the idea that I should simply open two separate connections. Here's the error that got thrown with the second connection: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/angrynates.com/cart/createProducts2.py 117 118 119 ''' 120 121 createProducts2() *createProducts2* = /var/www/html/angrynates.com/cart/createProducts2.py in *createProducts2*() 35 sst.append(bits[2]) 36 sstp.append(bits[1]) 37 db2 = MySQLdb.connect(host, user, passwd, db) 38 cursor2 = db.cursor() 39 created = [] db2 *undefined*, *global* *MySQLdb* = , MySQLdb.*connect * = , *host* = 'localhost', *user* = 'beno', *passwd* = 'Kj9rg2', *db* = <_mysql.connection open to 'localhost' at 28772c0> /usr/lib64/python2.4/site-packages/MySQLdb/__init__.py in *Connect*(*args=('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), **kwargs={}) 73 """Factory function for connections.Connection.""" 74 from connections import Connection 75 return Connection(*args, **kwargs) 76 77 connect = Connection = Connect *Connection* = , *args* = ('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), *kwargs* = {} /usr/lib64/python2.4/site-packages/MySQLdb/connections.py in *__init__*(self=<_mysql.connection closed at 28d95c0>, *args=('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), **kwargs={}) 162 kwargs2['client_flag'] = client_flag 163 164 super(Connection, self).__init__(*args, **kwargs2) 165 166 self.encoders = dict([ (k, v) for k, v in conv.items() *builtin* *super* = , *global* *Connection* = , *self* = <_mysql.connection closed at 28d95c0>, ).*__init__* = >, *args* = ('localhost', 'beno', 'Kj9rg2', <_mysql.connection open to 'localhost' at 28772c0>), *kwargs2* = {'client_flag': 196608, 'conv': {0: , 1: , 2: , 3: , 4: , 5: , 7: , 8: , 9: , 10: , ...}}*TypeError*: connect() argument 4 must be string, not Connection args = ('connect() argument 4 must be string, not Connection',) TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at agentultra.com Mon Nov 23 10:37:36 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 10:37:36 -0500 Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> <4b064d16$0$7628$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <85iqd145hb.fsf@agentultra.com> papa hippo writes: > On 20 nov, 09:02, Stefan Behnel wrote: >> papa hippo, 19.11.2009 19:53: >> >> > The prime goal of 'phileas' is to enable html code to be seamlessly >> > included in python code in a natural looking syntax, without resorting >> > to templatng language. >> >> I assume you know XIST, ElementTree's ElementMaker, and all those other >> ways of generating XML/HTML from Python code in a natural looking way? >> >> Stefan > > Hi Stefan, > > Thanks for your feedback. > > Yes, I am aware that phileas might - on the basis of the short > description on this post - come across like a 're-invented wheel'. > There is, however, one big difference between phileas and all other > other similar packages (XIST, ELementTree, HTMLgen, HyperText, > pyhtmloo etc.) that I inspected: > > Phileas uses distinct objects to generate each start and end tag, > whereas all the others use a single function call (in some cases > itself generated by a function call) to generate a complete well- > formed element including start-tag and (where required) end-tag. In > theory this is less neat and indeed it means one can write 'bad' HTML > (e.g. missing end of paragraphs) with phileas just as easily as when > writing pure html. In practice, however, I find it at a lot easier to > use. > > While using pyhtmloo (my previous favourite HTML generator), I had > found myself using awkward complicated artificial constructions in > order to generate all but the simplest HTML - and spent much time > playing 'hunt the missing bracket'. With phileas, these complexities > seem to just fall away. Any decent editor should be able to balance parenthesis for you. > > Put another way, Phileas generates HTML4.0 - warts and all; it is not > a parser or generator of XML. > > I'm considering building in checks/warnings for unclosed elements > etc., probably in the next-but-one pre-release. That your library will require a validation to be executed at run-time seems like it will be tedious to use. A decent text editor can even balance your HTML tags for you. Though you have a neat "DSL" like language for representing HTML elements. I'd suggest taking it one step further and creating a machine that can read in a Python data-structure and with as few hints as possible wrap it in the appropriate tags. > > Larry From mail at anjanesh.net Mon Nov 23 10:55:54 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Mon, 23 Nov 2009 21:25:54 +0530 Subject: print function in python3.1 In-Reply-To: References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: <1a7951080911230755r12307fa5o2dbcf2ca8eb9fde6@mail.gmail.com> > Maybe it would help if you explained what you are actually trying to > accomplish. import csv f = csv.reader(open('data.txt'), delimiter='\t') # 2GB text file sql = "INSERT INTO `data` VALUES (NULL,%s,%s,%s,%s,%s);" for row in f: print (sql, (row[0],row[1],row[2],row[3],row[4])) $ python3 parse.py3 > data.sql But because of print() being a function in Py3, print (sql, (row[0],row[1],row[2],row[3],row[4])) prints INSERT INTO `data` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); ('142', 'abcde', '2006-03-01 05:17:14', '', '') instead of INSERT INTO `data` VALUES (NULL, '142', 'abcde', '2006-03-01 05:17:14', '', ''); Anjanesh From carsten.haese at gmail.com Mon Nov 23 10:59:59 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 10:59:59 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Mon, Nov 23, 2009 at 10:08 AM, Carsten Haese > wrote: > > As I said, the best way we can help you is if you copy the actual error > message so that we may diagnose the actual problem and suggest a > solution that fixes the problem. > > > That gave me the idea that I should simply open two separate > connections. Here's the error that got thrown with the second connection: > > [snip...] > > 37 db2 = MySQLdb.connect(host, user, passwd, db) > > [snip...] > > TypeError: connect() argument 4 must be string, not Connection Have you tried to *read* and *understand* this error message? My guess is no. The error message tells you all you need to know. You need to pass a string as argument 4, but you aren't. <> is a database connection object, not a string. Change <> to a string containing the name of the MySQL database to which you want to connect. -- Carsten Haese http://informixdb.sourceforge.net From victorsubervi at gmail.com Mon Nov 23 11:05:02 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 11:05:02 -0500 Subject: Switching Databases In-Reply-To: References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: <4dc0cfea0911230805h691b3d67u3820a01c251aff68@mail.gmail.com> On Mon, Nov 23, 2009 at 10:59 AM, Carsten Haese wrote: > Have you tried to *read* and *understand* this error message? My guess > is no. The error message tells you all you need to know. You need to > pass a string as argument 4, but you aren't. <> is a database > connection object, not a string. Change <> to a string containing > the name of the MySQL database to which you want to connect. > Yes, Carsten, I did read the error message. And the obvious passed me by LOL! Sorry. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Mon Nov 23 11:07:33 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 17:07:33 +0100 Subject: print function in python3.1 References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> Message-ID: <7mvqa5F3kbrpqU1@mid.uni-berlin.de> Anjanesh Lekshminarayanan wrote: >> Maybe it would help if you explained what you are actually trying to >> accomplish. > > import csv > f = csv.reader(open('data.txt'), delimiter='\t') # 2GB text file > sql = "INSERT INTO `data` VALUES (NULL,%s,%s,%s,%s,%s);" > for row in f: > print (sql, (row[0],row[1],row[2],row[3],row[4])) > > $ python3 parse.py3 > data.sql > > But because of print() being a function in Py3, > print (sql, (row[0],row[1],row[2],row[3],row[4])) > prints > INSERT INTO `data` VALUES (NULL, '%s', '%s', '%s', '%s', '%s'); > ('142', 'abcde', '2006-03-01 05:17:14', '', '') > instead of > INSERT INTO `data` VALUES (NULL, '142', 'abcde', '2006-03-01 05:17:14', > '', ''); No. It does so because you don't use print(sql % (row[0],row[1],row[2],row[3],row[4])) And that has nothing to do with print being a function or not. Diez From showell30 at yahoo.com Mon Nov 23 11:21:10 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 23 Nov 2009 08:21:10 -0800 (PST) Subject: KirbyBase : replacing string exceptions References: Message-ID: <22c066e4-2a4e-4e0b-8c60-2039a2536f81@g22g2000prf.googlegroups.com> On Nov 23, 7:22?am, Brendan wrote: > In KirbyBase there is a method that uses string exceptions for > control, even though it has a defined exception. Is there any reason > the string exceptions below could not be replaced? > i.e. in code below replace: > raise "No Match" > with: > raise KBError() > and > except 'No Match': > with: > except KBError: > It looks like in some cases KBError() should fall through and only 'No Match' was intended to be silently caught. I would consider either leaving it alone if it works, or doing more serious surgery on the code to simplify the control flow. The method is awfully long and nested. > I have pasted the relevant method and the class definition of KBError > below > > #---------------------------------------------------------------------- > ? ? # _getMatches > > #---------------------------------------------------------------------- > ? ? def _getMatches(self, fptr, fields, patterns, useRegExp): > ? ? ? ? # Initialize a list to hold all records that match the search > ? ? ? ? # criteria. > ? ? ? ? match_list = [] > > ? ? ? ? # If one of the fields to search on is 'recno', which is the > ? ? ? ? # table's primary key, then search just on that field and > return > ? ? ? ? # at most one record. > ? ? ? ? if 'recno' in fields: > ? ? ? ? ? ? return self._getMatchByRecno(fptr,patterns) > ? ? ? ? # Otherwise, search table, using all search fields and > patterns > ? ? ? ? # specified in arguments lists. > ? ? ? ? else: > ? ? ? ? ? ? new_patterns = [] > ? ? ? ? ? ? fieldNrs = [self.field_names.index(x) for x in fields] > ? ? ? ? ? ? for fieldPos, pattern in zip(fieldNrs, patterns): > ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > ? ? ? ? ? ? ? ? ? ? # If useRegExp is True, compile the pattern to a > ? ? ? ? ? ? ? ? ? ? # regular expression object and add it to the > ? ? ? ? ? ? ? ? ? ? # new_patterns list. ?Otherwise, ?just add it to > ? ? ? ? ? ? ? ? ? ? # the new_patterns list. ?This will be used below > ? ? ? ? ? ? ? ? ? ? # when matching table records against the > patterns. > ? ? ? ? ? ? ? ? ? ? if useRegExp: > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(re.compile(pattern)) > ? ? ? ? ? ? ? ? ? ? ? ? # the pattern can be a tuple with re flags > like re.I > ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(pattern) > ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > ? ? ? ? ? ? ? ? ? ? # If type is boolean, I am going to coerce it to > be > ? ? ? ? ? ? ? ? ? ? # either True or False by applying bool to it. > This > ? ? ? ? ? ? ? ? ? ? # is because it could be '' or []. ?Next, I am > going > ? ? ? ? ? ? ? ? ? ? # to convert it to the string representation: > either > ? ? ? ? ? ? ? ? ? ? # 'True' or 'False'. ?The reason I do this is > because > ? ? ? ? ? ? ? ? ? ? # that is how it is stored in each record of the > table > ? ? ? ? ? ? ? ? ? ? # and it is a lot faster to change this one value > from > ? ? ? ? ? ? ? ? ? ? # boolean to string than to change possibly > thousands > ? ? ? ? ? ? ? ? ? ? # of table values from string to boolean. ?And, if > they > ? ? ? ? ? ? ? ? ? ? # both are either 'True' or 'False' I can still > ? ? ? ? ? ? ? ? ? ? # compare them using the equality test and get the > same > ? ? ? ? ? ? ? ? ? ? # result as if they were both booleans. > ? ? ? ? ? ? ? ? ? ? new_patterns.append(str(bool(pattern))) > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? # If type is int, float, date, or datetime, this > next > ? ? ? ? ? ? ? ? ? ? # bit of code will split the the comparison string > ? ? ? ? ? ? ? ? ? ? # into the string representing the comparison > ? ? ? ? ? ? ? ? ? ? # operator (i.e. ">=" and the actual value we are > going > ? ? ? ? ? ? ? ? ? ? # to compare the table records against from the > input > ? ? ? ? ? ? ? ? ? ? # pattern, (i.e. "5"). ?So, for example, ">5" > would be > ? ? ? ? ? ? ? ? ? ? # split into ">" and "5". > ? ? ? ? ? ? ? ? ? ? r = re.search('[\s]*[\+-]?\d', pattern) > ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == int: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = int(pattern[r.start():]) > ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = float(pattern[r.start():]) > ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = pattern[r.start():] > ? ? ? ? ? ? ? ? ? ? new_patterns.append( > ? ? ? ? ? ? ? ? ? ? ?[self.cmpFuncs[pattern[:r.start()]], > patternValue] > ? ? ? ? ? ? ? ? ? ? ) > > ? ? ? ? ? ? fieldPos_new_patterns = zip(fieldNrs, new_patterns) > ? ? ? ? ? ? maxfield = max(fieldNrs)+1 > > ? ? ? ? ? ? # Record current position in table. Then read first detail > ? ? ? ? ? ? # record. > ? ? ? ? ? ? fpos = fptr.tell() > ? ? ? ? ? ? line = fptr.readline() > > ? ? ? ? ? ? # Loop through entire table. > ? ? ? ? ? ? while line: > ? ? ? ? ? ? ? ? # Strip off newline character and any trailing spaces. > ? ? ? ? ? ? ? ? line = line[:-1].strip() > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? # If blank line, skip this record. > ? ? ? ? ? ? ? ? ? ? if line == "": raise 'No Match' > ? ? ? ? ? ? ? ? ? ? # Split the line up into fields. > ? ? ? ? ? ? ? ? ? ? record = line.split("|", maxfield) > > ? ? ? ? ? ? ? ? ? ? # Foreach correspond field and pattern, check to > see > ? ? ? ? ? ? ? ? ? ? # if the table record's field matches > successfully. > ? ? ? ? ? ? ? ? ? ? for fieldPos, pattern in fieldPos_new_patterns: > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is string, it > ? ? ? ? ? ? ? ? ? ? ? ? # must be an exact match or a regular > expression, > ? ? ? ? ? ? ? ? ? ? ? ? # so we will compare the table record's field > to it > ? ? ? ? ? ? ? ? ? ? ? ? # using either '==' or the regular expression > ? ? ? ? ? ? ? ? ? ? ? ? # engine. ?Since it is a string field, we will > need > ? ? ? ? ? ? ? ? ? ? ? ? # to run it through the unencodeString > function to > ? ? ? ? ? ? ? ? ? ? ? ? # change any special characters back to their > ? ? ? ? ? ? ? ? ? ? ? ? # original values. > ? ? ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if useRegExp: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern.search( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self._unencodeString(record > [fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? except Exception: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'Invalid match expression for %s' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is boolean, then I will > simply > ? ? ? ? ? ? ? ? ? ? ? ? # do an equality comparison. ?See comments > above > ? ? ? ? ? ? ? ? ? ? ? ? # about why I am actually doing a string > compare > ? ? ? ? ? ? ? ? ? ? ? ? # here rather than a boolean compare. > ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? ? ? ? ? # If it is not a string or a boolean, then it > must > ? ? ? ? ? ? ? ? ? ? ? ? # be a number or a date. > ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Convert the table's field value, which > is a > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # string, back into it's native type so > that > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # we can do the comparison. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] == '': > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = None > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == int: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = int(record[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = float(record[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I don't convert datetime values from > strings > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # back into their native types because it > is > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # faster to just leave them as strings > and > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # convert the comparison value that the > user > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # supplied into a string. ?Comparing the > two > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # strings works out the same as comparing > two > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # datetime values anyway. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] in ( > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?datetime.date, datetime.datetime): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = record[fieldPos] > ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # If it falls through to here, then, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # somehow, a bad field type got put > into > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # the table and we show an error. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError('Invalid field type for > %s' > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Now we do the actual comparison. ?I used > to > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # just do an eval against the pattern > string > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # here, but I found that eval's are VERY > slow. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # So, now I determine what type of > comparison > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # they are trying to do and I do it > directly. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # This sped up queries by 40%. > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern[0](tableValue, pattern[1]): > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > ? ? ? ? ? ? ? ? # If a 'No Match' exception was raised, then go to the > ? ? ? ? ? ? ? ? # next record, otherwise, add it to the list of > matches. > ? ? ? ? ? ? ? ? except 'No Match': > ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? ? ? match_list.append([line, fpos]) > ? ? ? ? ? ? ? ? # Save the file position BEFORE we read the next > record, > ? ? ? ? ? ? ? ? # because after a read it is pointing at the END of > the > ? ? ? ? ? ? ? ? # current record, which, of course, is also the > BEGINNING > ? ? ? ? ? ? ? ? # of the next record. ?That's why we have to save the > ? ? ? ? ? ? ? ? # position BEFORE we read the next record. > ? ? ? ? ? ? ? ? fpos = fptr.tell() > ? ? ? ? ? ? ? ? line = fptr.readline() > > ? ? ? ? # After searching, return the list of matched records. > ? ? ? ? return match_list > > #---------------------------------------------------------------------- > > #-------------------------------------------------------------------------- > # KBError Class > #-------------------------------------------------------------------------- > class KBError(Exception): > ? ? """Exception class for Database Management System. > > ? ? Public Methods: > ? ? ? ? __init__ - Create an instance of exception. > ? ? """ > > #---------------------------------------------------------------------- > ? ? # init > > #---------------------------------------------------------------------- > ? ? def __init__(self, value): > ? ? ? ? self.value = value > > ? ? def __str__(self): > ? ? ? ? return `self.value` > > ? ? # I overrode repr so I could pass error objects from the server to > the > ? ? # client across the network. > ? ? def __repr__(self): > ? ? ? ? format = """KBError("%s")""" > ? ? ? ? return format % (self.value) From james at agentultra.com Mon Nov 23 11:29:33 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 11:29:33 -0500 Subject: Go versus Brand X References: Message-ID: <85d439432q.fsf@agentultra.com> aahz at pythoncraft.com (Aahz) writes: > Comparing Go to another computer language -- do you recognize it? > > http://www.cowlark.com/2009-11-15-go/ If you skip to the conclusion, you'll be better off. The author has an interesting point. Go (the language) is not really ground-breaking. I don't understand why they're so busy creating their own walled garden... Their own browser, their own programming languages, their own file systems, etc. Weird. From thomas at thomas-lotze.de Mon Nov 23 11:45:24 2009 From: thomas at thomas-lotze.de (Thomas Lotze) Date: Mon, 23 Nov 2009 17:45:24 +0100 Subject: Minimally intrusive XML editing using Python References: Message-ID: Please consider this a reply to any unanswered messages I received in response to my original post. Dave Angel wrote: > What's your real problem, or use case? Are you just concerned with > diffing, or are others likely to read the xml, and want it formatted the > way it already is? I'd like to put the XML under revision control along with other stuff. Other people should be able to make sense of the diffs and I'd rather not require them to configure their tools to use some XML differ. > And how general do you need this tool to be? For > example, if the only thing you're doing is modifying existing attributes > or existing tags, the "minimal change" would be pretty unambiguous. But > if you're adding tags, or adding content on what was an empty element, > then the requirement gets fuzzy And finding an existing library for > something "fuzzy" is unlikely. Sure. I guess it's something like an 80/20 problem: Changing attributes in a way that keeps the rest of the XML intact will go a long way and as we're talking about XML that is supposed to be looked at by humans, I would base any further requirements on the assumption that it's pretty-printed in some way so that removing an element, for example, can be defined by touching as few lines as possible, and adding one can be restricted to adding a line in the appropriate place. If more complex stuff isn't as well-defined, that would be entirely OK with me. > Sample input, change list, and desired output would be very useful. I'd like to be able to reliably produce a diff like this using a program that lets me change the value in some useful way, which might be dragging a point across a map with the mouse in this example: --- foo.gpx 2009-05-30 19:45:45.000000000 +0200 +++ bar.gpx 2009-11-23 17:41:36.000000000 +0100 @@ -11,7 +11,7 @@ 0.792244 2d - + 508.300000 15.150000 -- Thomas From lie.1296 at gmail.com Mon Nov 23 11:51:12 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 03:51:12 +1100 Subject: Go versus Brand X In-Reply-To: <85d439432q.fsf@agentultra.com> References: <85d439432q.fsf@agentultra.com> Message-ID: <4b0abddb$1@dnews.tpgi.com.au> J Kenneth King wrote: > aahz at pythoncraft.com (Aahz) writes: > >> Comparing Go to another computer language -- do you recognize it? >> >> http://www.cowlark.com/2009-11-15-go/ > > If you skip to the conclusion, you'll be better off. > > The author has an interesting point. > > Go (the language) is not really ground-breaking. > > I don't understand why they're so busy creating their own walled > garden... > > Their own browser, their own programming languages, their own file > systems, etc. because they can, no? Normal business logic doesn't apply to Google. From james at agentultra.com Mon Nov 23 11:59:38 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 23 Nov 2009 11:59:38 -0500 Subject: Perl conversion to python... References: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com> Message-ID: <858wdx41ol.fsf@agentultra.com> Benjamin Schollnick writes: > Folks, > > I'm having some issues here with pyserial & trying to translate a perl > script to python... It's probably my inexperience with PySerial & > perl that is troubling me... > > Can anyone assist? > > I'm concerned, since I can't seem to receive the data in any reliable > manner.. I've tested multiple times, and only once received data... > So I suspect that my Transmit & receive code is faulty... > > def xmit ( data, serialport ): > for x in data: > xmit_byte (x, serialport) > # serialport.write ( binascii.unhexlify ( data ) ) > # for x in data: > # print str(x).encode ('hex') > # serialport.write ( x.encode('hex')) > > def receive ( serialport ): > received = serialport.read (20) > print received, "!" Gah.. indentation is broken in your post... :S > > ----- Perl Code ---- > sub tx_command { > my $port = shift; > my $cmd = shift; > > # warn "tx_command($cmd)\n"; > > my @cmd_bytes = split(/\s/, $cmd); > > foreach my $byte (@cmd_bytes) { > $byte = pack('C', hex($byte)); > > $port -> write($byte); > select(undef, undef, undef, 0.01); > } > } import struct def tx_command(port, cmd): cmd_bytes = cmd.split(' ') for byte in cmd_bytes: byte = struct.pack('C', hex(int(byte))) port.write(byte) # select() is a system call in Perl.. # insert Python equivalent here > > # returns the rtt, or 0 if no response > sub rx_response { > my ($port, $address) = @_; > > $port->read_char_time(0); # don't wait for each character > $port->read_const_time(5000); # timeout if we don't get what we're > looking for > > my $buf = ''; > > my $t_start = time; > > ### accumulate one byte at a time until we see the substring we're > looking for > > while (1) { > my ($count_in, $string_in) = $port->read(1); > > if ($count_in == 0) { > # warn "TIMEOUT\n"; > return 0; > } > > $buf .= $string_in; > > my $bufstring = packed_to_text($buf); > > #warn "bufstring: ".$bufstring; > > if ($bufstring =~/02 50 $address (.. .. ..) (..) (.. ..)/) { > > my $powerlinc_addr = $1; > my $flags = $2; > my $command = $3; > > # warn "got response!\n"; > > my $rtt = time() - $t_start; > > return $rtt; > } > > } > } This isn't all that more complicated. I dunno, maybe it's just me but I find most Perl pretty easy to read (barring obfuscation which just takes longer to read but is no more difficult). For the most part you can generally substitute the Python equivalent statements for each line of Perl and get good results. Optimize for better Pythonicity afterwards. From johnguenther at me.com Mon Nov 23 12:02:36 2009 From: johnguenther at me.com (John Guenther) Date: Mon, 23 Nov 2009 12:02:36 -0500 Subject: adding a directory to sys.path Message-ID: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> This is Mac related. I am running snow leopard. I am using Python 2.6.3. I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. I have a directory called PythonPrograms in my Documents folder. When I installed Python it had '/Users/johnguenther/Documents' as sys.path[0]. I tried setting PYTHONPATH and this worked for running Python from the bash shell but only until I exited the shell. PYTHONPATH had to be reset each time I restarted the shell. And it had no effect on sys.path when I ran Idle. I tried putting files with names ending with .pth in various directories all of which were already in sys.path. In this file I would put the path name of the directory, i.e., '/Users/johnguenter/Documents/PythonPrograms'. This had absolutely no effect. I searched the web for help and found nothing that worked. Finally I looked at a file that had been installed when I installed wxPython. I modified that file and now the directory I want is always part of sys.path when I start idle. Since I had so much trouble finding an answer to the question "How do I permanently change sys.path?", I thought I might post this message. I created a file called myconfig.pth In this file I included one line: import site; site.addsitedir('/Users/johnguenther/Documents/PythonPrograms') I placed the file in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages. From showell30 at yahoo.com Mon Nov 23 12:05:42 2009 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 23 Nov 2009 09:05:42 -0800 (PST) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On Nov 23, 2:47?am, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit?: > > > > > I think there is an overall design sensibility, it's just not a > > human-facing one. They claim that they designed the syntax to be very > > easily parsed by very simple tools in order to make things like syntax > > highlighters very easy and robust. So indentation-based blocks are right > > out. > > But computer languages should be designed to be readable by humans. > It's not like you need to write a new parser once a year, but you have to > read code everyday. > Besides, if you want parsing to be easy, you don't need to make the > syntax minimal, you just have to provide the parsing routines as part of > the standard library and/or of an external API. You could argue that by keeping the computer-facing part of the language simple, you make it easier for tools to take care of the human-facing side. But when you leave it up to third-party tools (or diligent programmers) to format code, the language designers have a lot less control over the aesthetics of programs in the wild, and you start having style wars over braces, etc., and no two Go programs will look like they reflect the same sensibility. Human readability and computer readability obviously do not have to be completely orthogonal, as proven by Python. But to the extent that they are orthogonal, I think there's a natural inclination to make a systems programming language focus on the computer-facing issues, with the huge caveat that leaving human-side issues to higher levels on the stack (linters, code formatters, etc.) complicates the overall ecosystem. Since Go is designed for building large programs, any failure of the Go community to prescribe a common aesthetic will probably get magnified to a large degree. Finally, a lot of aesthetics transcend syntax, so you can argue that the most important thing to do to enable programmers to create beautiful programs is to make them be more productive, and a fast compiler is pretty crucial for that, since a lot of human programmers work better in a "flow" state. From brendandetracey at yahoo.com Mon Nov 23 12:05:48 2009 From: brendandetracey at yahoo.com (Brendan) Date: Mon, 23 Nov 2009 09:05:48 -0800 (PST) Subject: KirbyBase : replacing string exceptions References: <22c066e4-2a4e-4e0b-8c60-2039a2536f81@g22g2000prf.googlegroups.com> Message-ID: <6c4841d5-6878-4723-800d-0d3200591135@m20g2000vbp.googlegroups.com> On Nov 23, 12:21?pm, Steve Howell wrote: > On Nov 23, 7:22?am, Brendan wrote: > > > In KirbyBase there is a method that uses string exceptions for > > control, even though it has a defined exception. Is there any reason > > the string exceptions below could not be replaced? > > i.e. in code below replace: > > raise "No Match" > > with: > > raise KBError() > > and > > except 'No Match': > > with: > > except KBError: > > It looks like in some cases KBError() should fall through and only 'No > Match' was intended to be silently caught. > > I would consider either leaving it alone if it works, or doing more > serious surgery on the code to simplify the control flow. ?The method > is awfully long and nested. > > > > > I have pasted the relevant method and the class definition of KBError > > below > > > #---------------------------------------------------------------------- > > ? ? # _getMatches > > > #---------------------------------------------------------------------- > > ? ? def _getMatches(self, fptr, fields, patterns, useRegExp): > > ? ? ? ? # Initialize a list to hold all records that match the search > > ? ? ? ? # criteria. > > ? ? ? ? match_list = [] > > > ? ? ? ? # If one of the fields to search on is 'recno', which is the > > ? ? ? ? # table's primary key, then search just on that field and > > return > > ? ? ? ? # at most one record. > > ? ? ? ? if 'recno' in fields: > > ? ? ? ? ? ? return self._getMatchByRecno(fptr,patterns) > > ? ? ? ? # Otherwise, search table, using all search fields and > > patterns > > ? ? ? ? # specified in arguments lists. > > ? ? ? ? else: > > ? ? ? ? ? ? new_patterns = [] > > ? ? ? ? ? ? fieldNrs = [self.field_names.index(x) for x in fields] > > ? ? ? ? ? ? for fieldPos, pattern in zip(fieldNrs, patterns): > > ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > > ? ? ? ? ? ? ? ? ? ? # If useRegExp is True, compile the pattern to a > > ? ? ? ? ? ? ? ? ? ? # regular expression object and add it to the > > ? ? ? ? ? ? ? ? ? ? # new_patterns list. ?Otherwise, ?just add it to > > ? ? ? ? ? ? ? ? ? ? # the new_patterns list. ?This will be used below > > ? ? ? ? ? ? ? ? ? ? # when matching table records against the > > patterns. > > ? ? ? ? ? ? ? ? ? ? if useRegExp: > > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(re.compile(pattern)) > > ? ? ? ? ? ? ? ? ? ? ? ? # the pattern can be a tuple with re flags > > like re.I > > ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? new_patterns.append(pattern) > > ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > > ? ? ? ? ? ? ? ? ? ? # If type is boolean, I am going to coerce it to > > be > > ? ? ? ? ? ? ? ? ? ? # either True or False by applying bool to it. > > This > > ? ? ? ? ? ? ? ? ? ? # is because it could be '' or []. ?Next, I am > > going > > ? ? ? ? ? ? ? ? ? ? # to convert it to the string representation: > > either > > ? ? ? ? ? ? ? ? ? ? # 'True' or 'False'. ?The reason I do this is > > because > > ? ? ? ? ? ? ? ? ? ? # that is how it is stored in each record of the > > table > > ? ? ? ? ? ? ? ? ? ? # and it is a lot faster to change this one value > > from > > ? ? ? ? ? ? ? ? ? ? # boolean to string than to change possibly > > thousands > > ? ? ? ? ? ? ? ? ? ? # of table values from string to boolean. ?And, if > > they > > ? ? ? ? ? ? ? ? ? ? # both are either 'True' or 'False' I can still > > ? ? ? ? ? ? ? ? ? ? # compare them using the equality test and get the > > same > > ? ? ? ? ? ? ? ? ? ? # result as if they were both booleans. > > ? ? ? ? ? ? ? ? ? ? new_patterns.append(str(bool(pattern))) > > ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? # If type is int, float, date, or datetime, this > > next > > ? ? ? ? ? ? ? ? ? ? # bit of code will split the the comparison string > > ? ? ? ? ? ? ? ? ? ? # into the string representing the comparison > > ? ? ? ? ? ? ? ? ? ? # operator (i.e. ">=" and the actual value we are > > going > > ? ? ? ? ? ? ? ? ? ? # to compare the table records against from the > > input > > ? ? ? ? ? ? ? ? ? ? # pattern, (i.e. "5"). ?So, for example, ">5" > > would be > > ? ? ? ? ? ? ? ? ? ? # split into ">" and "5". > > ? ? ? ? ? ? ? ? ? ? r = re.search('[\s]*[\+-]?\d', pattern) > > ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == int: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = int(pattern[r.start():]) > > ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = float(pattern[r.start():]) > > ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? patternValue = pattern[r.start():] > > ? ? ? ? ? ? ? ? ? ? new_patterns.append( > > ? ? ? ? ? ? ? ? ? ? ?[self.cmpFuncs[pattern[:r.start()]], > > patternValue] > > ? ? ? ? ? ? ? ? ? ? ) > > > ? ? ? ? ? ? fieldPos_new_patterns = zip(fieldNrs, new_patterns) > > ? ? ? ? ? ? maxfield = max(fieldNrs)+1 > > > ? ? ? ? ? ? # Record current position in table. Then read first detail > > ? ? ? ? ? ? # record. > > ? ? ? ? ? ? fpos = fptr.tell() > > ? ? ? ? ? ? line = fptr.readline() > > > ? ? ? ? ? ? # Loop through entire table. > > ? ? ? ? ? ? while line: > > ? ? ? ? ? ? ? ? # Strip off newline character and any trailing spaces. > > ? ? ? ? ? ? ? ? line = line[:-1].strip() > > ? ? ? ? ? ? ? ? try: > > ? ? ? ? ? ? ? ? ? ? # If blank line, skip this record. > > ? ? ? ? ? ? ? ? ? ? if line == "": raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? # Split the line up into fields. > > ? ? ? ? ? ? ? ? ? ? record = line.split("|", maxfield) > > > ? ? ? ? ? ? ? ? ? ? # Foreach correspond field and pattern, check to > > see > > ? ? ? ? ? ? ? ? ? ? # if the table record's field matches > > successfully. > > ? ? ? ? ? ? ? ? ? ? for fieldPos, pattern in fieldPos_new_patterns: > > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is string, it > > ? ? ? ? ? ? ? ? ? ? ? ? # must be an exact match or a regular > > expression, > > ? ? ? ? ? ? ? ? ? ? ? ? # so we will compare the table record's field > > to it > > ? ? ? ? ? ? ? ? ? ? ? ? # using either '==' or the regular expression > > ? ? ? ? ? ? ? ? ? ? ? ? # engine. ?Since it is a string field, we will > > need > > ? ? ? ? ? ? ? ? ? ? ? ? # to run it through the unencodeString > > function to > > ? ? ? ? ? ? ? ? ? ? ? ? # change any special characters back to their > > ? ? ? ? ? ? ? ? ? ? ? ? # original values. > > ? ? ? ? ? ? ? ? ? ? ? ? if self.field_types[fieldPos] == str: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? try: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if useRegExp: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not pattern.search( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self._unencodeString(record > > [fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?): > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? except Exception: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise KBError( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'Invalid match expression for %s' > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% self.field_names[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? # If the field type is boolean, then I will > > simply > > ? ? ? ? ? ? ? ? ? ? ? ? # do an equality comparison. ?See comments > > above > > ? ? ? ? ? ? ? ? ? ? ? ? # about why I am actually doing a string > > compare > > ? ? ? ? ? ? ? ? ? ? ? ? # here rather than a boolean compare. > > ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == bool: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] != pattern: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise 'No Match' > > ? ? ? ? ? ? ? ? ? ? ? ? # If it is not a string or a boolean, then it > > must > > ? ? ? ? ? ? ? ? ? ? ? ? # be a number or a date. > > ? ? ? ? ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Convert the table's field value, which > > is a > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # string, back into it's native type so > > that > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # we can do the comparison. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? if record[fieldPos] == '': > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = None > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == int: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = int(record[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] == float: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? tableValue = float(record[fieldPos]) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I don't convert datetime values from > > strings > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # back into their native types because it > > is > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # faster to just leave them as strings > > and > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # convert the comparison value that the > > user > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # supplied into a string. ?Comparing the > > two > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # strings works out the same as comparing > > two > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? # datetime values anyway. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? elif self.field_types[fieldPos] in ( > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?- Hide quoted text - > > - Show quoted text -... > > read more ? Okay. Thanks. From vorticitywolfe at gmail.com Mon Nov 23 12:08:44 2009 From: vorticitywolfe at gmail.com (J Wolfe) Date: Mon, 23 Nov 2009 09:08:44 -0800 (PST) Subject: Print to Printer Tkinter Text Message-ID: <7a6b9bee-1e54-4069-a8e8-215186fac482@z3g2000prd.googlegroups.com> Hi, Is there a way to print the format of a Tkinter text box to a color printer with its tags, e.g. a blue text at font size 18 and bold will like it displays? Thanks, Jonathan From 457r0.jp at gmail.com Mon Nov 23 12:19:03 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 09:19:03 -0800 (PST) Subject: Beginning Question about Python functions, parameters... Message-ID: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Hi, I am trying to teach myself Python and have a good book to help me but I am stuck on something and I would like for someone to explain the following piece of code for me and what it's actually doing. Certain parts are very clear but once it enters the "def store(data, full_name): ...." function and the "def lookup()..." function things get a little confusing for me. Specifically, lines 103-108 *and* Lines 110-111. Lastly, I am not sure how to print the results I've put into this program either, the book I'm reading doesn't tell me. As you can tell, I am a beginner and I don't truly understand everything that is going on here...a lot, but not all.... Here is the code: 92 def init(data): 93 data['first'] = {} 94 data['middle'] = {} 95 data['last'] = {} 96 97 def store(data, full_name): 98 names = full_name.split() 100 if len(names) == 2: names.insert(1, '') 101 labels = 'first', 'middle', 'last' 103 for label, name in zip(labels, names): 104 people = lookup(data, label, name) 105 if people: 106 people.append(full_name) 107 else: 108 data[label][name] = [full_name] 109 110 def lookup(data, label, name): 111 return data[label].get(name) 112 113 114 MyNames = {} 115 init(MyNames) 116 store(MyNames, 'John Larry Smith') 117 lookup(MyNames, 'middle', 'Smith') From neo at picture-art.eu Mon Nov 23 12:37:33 2009 From: neo at picture-art.eu (Neo) Date: Mon, 23 Nov 2009 18:37:33 +0100 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <4B0AC85D.8050703@picture-art.eu> astral orange schrieb: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > 92 def init(data): > 93 data['first'] = {} > 94 data['middle'] = {} > 95 data['last'] = {} > 96 > 97 def store(data, full_name): > 98 names = full_name.split() > 100 if len(names) == 2: names.insert(1, '') > 101 labels = 'first', 'middle', 'last' > 103 for label, name in zip(labels, names): > 104 people = lookup(data, label, name) > 105 if people: > 106 people.append(full_name) > 107 else: > 108 data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 return data[label].get(name) > 112 > 113 > 114 MyNames = {} > 115 init(MyNames) > 116 store(MyNames, 'John Larry Smith') > 117 lookup(MyNames, 'middle', 'Smith') If it tells you so I'm not really sure its a good book - partially for teaching you into the unpythonic way to do things (above stuff, if its not a counter example, should really go into a class) Have you tried the tutorial first? Its online and very easy to follow from the very beginning but you can also skip parts if you are sure you already understand it: http://docs.python.org/tutorial/ HTH Tino From sergiomb at sapo.pt Mon Nov 23 12:39:17 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Mon, 23 Nov 2009 17:39:17 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine Message-ID: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> Hi, I am in x86_64 arch , but I need compile things on 32 bits with python setup.py build Can't change the fact that distutils creates x86_64 directories: build/temp.linux-x86_64-2.3/ Also if I try with a python compile in 32bits and installed in system . how I force distutils build to 32-bits on x86_64 arch? Thanks in advance, From wolftracks at invalid.com Mon Nov 23 12:49:17 2009 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 23 Nov 2009 09:49:17 -0800 Subject: A More Concise Description of Numpy than the Guide to Numpy? Message-ID: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? From robert.kern at gmail.com Mon Nov 23 12:54:19 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 11:54:19 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On 2009-11-23 04:47 AM, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit : >> >> I think there is an overall design sensibility, it's just not a >> human-facing one. They claim that they designed the syntax to be very >> easily parsed by very simple tools in order to make things like syntax >> highlighters very easy and robust. So indentation-based blocks are right >> out. > > But computer languages should be designed to be readable by humans. > It's not like you need to write a new parser once a year, but you have to > read code everyday. You will get no argument from me. My point was only that they had an overall design sensibility, not that it was a good one. > Besides, if you want parsing to be easy, you don't need to make the > syntax minimal, you just have to provide the parsing routines as part of > the standard library and/or of an external API. Not really. The idea was to make the language easily parsed and lexed and analyzed by *other* tools, not written in Go, that may have limited capabilities. Vim isn't written in Go and won't be able to use their API, for example. -- 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 Nov 23 13:03:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 12:03:32 -0600 Subject: A More Concise Description of Numpy than the Guide to Numpy? In-Reply-To: References: Message-ID: On 2009-11-23 11:49 AM, W. eWatson wrote: > I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more > concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists You may also find the NumPy User Guide more up your alley: http://docs.scipy.org/doc/numpy/user/ -- 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 deets at nospam.web.de Mon Nov 23 13:10:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 19:10:24 +0100 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> Message-ID: <7n01ggF3j2qn9U1@mid.uni-berlin.de> S?rgio Monteiro Basto wrote: > Hi, > I am in x86_64 arch , but I need > compile things on 32 bits with > python setup.py build > > Can't change the fact that distutils creates x86_64 > directories: > build/temp.linux-x86_64-2.3/ > > Also if I try with a python compile in 32bits and installed > in system . I doubt that. Distutils will always build based on the architecture of the interpreter you used when building an external module. Are you sure that the python you used to build the extension was the right one? What does -c "from distutils.util import get_platform; print get_platform()" return? Diez From victorsubervi at gmail.com Mon Nov 23 13:10:35 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 13:10:35 -0500 Subject: Don't Understand Error Message-ID: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Hi; I have the following code: #!/usr/bin/env python import smtplib import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from login import login import MySQLdb import re, string def mailSpreadsheet(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor= database.cursor() ourEmail1 = 'anemail at here.com' ourEmail2 = 'anotheremail at here.com' form = cgi.FieldStorage() client = form.getfirst('client', '') clientEmail = form.getfirst('clientEmail', '') po = form.getfirst('po', '') subject = 'Order From Client' sql = 'select clientEmail from clients where client="%s";' % (string.replace(client, '_', ' ')) cursor.execute(sql) clientEmail = cursor.fetchone()[0] cursor.execute('select * from %s;' % (client)) data = cursor.fetchall() i = 0 if po != '': order = 'PO#: %s\n' % (po) else: order = '' total = 0 for row in data: i += 1 quantity = form.getfirst('order_' + str(i), '') if quantity != '0': sql = 'select * from products p join %s c on p.ID=c.ID where c.ID=%s;' % (client, str(i)) cursor.execute(sql) stuff = cursor.fetchone() price = str(int(stuff[5]*100)) price = price[0:len(price)-2] + '.' + price[-2:] item, price, description, discount = stuff[2], price, stuff[3], stuff[8] order += 'Item #: ' + item + '\tQuantity: ' + quantity + '\tPrice: ' + price + '\tDiscount: ' + str(discount) + '\tDescription: ' + description[:20] + '...\n' total += float(price) * int(quantity) * (100 - discount)/100 order += 'TOTAL: $' + str(total) msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order) session = smtplib.SMTP("localhost") session.login(user, passwd) # only if it requires auth header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject # session.sendmail(clientEmail, ourEmail1, header+msg) session.sendmail(clientEmail, ourEmail2, header+msg) mailSpreadsheet() The email does get sent, and it that happens out of the last line of code. If I surround the code with code to make it print a Web page, it prints without any error. However, as it is, it throws the following error: The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, me at creative.vi and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end of script headers: mailSpreadsheet.py, referer: http://globalsolutionsgroup.vi/display_spreadsheet.py Why? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Nov 23 13:15:10 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 23 Nov 2009 19:15:10 +0100 Subject: adding a directory to sys.path In-Reply-To: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> References: <84D804F8-928E-4E58-8A97-B42224A2290B@me.com> Message-ID: <4B0AD12E.50504@cheimes.de> John Guenther schrieb: > This is Mac related. I am running snow leopard. I am using Python 2.6.3. > > I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. I have a directory called PythonPrograms in my Documents folder. When I installed Python it had '/Users/johnguenther/Documents' as sys.path[0]. I tried setting PYTHONPATH and this worked for running Python from the bash shell but only until I exited the shell. PYTHONPATH had to be reset each time I restarted the shell. And it had no effect on sys.path when I ran Idle. See my blog posting: http://lipyrary.blogspot.com/2009/08/how-to-add-new-module-search-path.html Christian From deets at nospam.web.de Mon Nov 23 13:17:12 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 19:17:12 +0100 Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <7n01t8F3jijv0U1@mid.uni-berlin.de> astral orange wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > 92 def init(data): > 93 data['first'] = {} > 94 data['middle'] = {} > 95 data['last'] = {} > 96 > 97 def store(data, full_name): > 98 names = full_name.split() > 100 if len(names) == 2: names.insert(1, '') > 101 labels = 'first', 'middle', 'last' > 103 for label, name in zip(labels, names): The zip-function takes n iterables, and produces a list with n-tuples out of it. Type this into the python-prompt: >>> zip([1, 2, 3], ["a", "b", "c"]) The other thing here is tuple-unpacking. If you know that something has a specific length, you can unpack it into distinct values like this: >>> a, b = (10, 20) >>> print a 10 >>> print b 20 Now for label, name in zip(labels, names): does - create a list of tuples, each tuple having two elements, the first being the label, the second a name - loops over this list - for each item in the list (remember, it's a 2-tuple!), unpack it into label and name > 104 people = lookup(data, label, name) > 105 if people: > 106 people.append(full_name) > 107 else: > 108 data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 return data[label].get(name) Data here is expected to be a dictionary of dictionaries. The first level of keys are the labels. The second is the name. It is expected that labels always exist, but names might be empty, so instead of writing return data[label][name] it uses get(name) on a dict which will return the value for the key, or None: >>> {"foo" : "bar"}.get("foo") bar >>> {"foo" : "bar"}.get("baz") >>> # no output means None That being said, I agree with Neo that this introduction seems to be rather bad. Diez From jimmy.casey.3 at gmail.com Mon Nov 23 13:26:42 2009 From: jimmy.casey.3 at gmail.com (j) Date: Mon, 23 Nov 2009 10:26:42 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> On Nov 23, 12:37?pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > ?92 def init(data): > > ?93 ? ? data['first'] = {} > > ?94 ? ? data['middle'] = {} > > ?95 ? ? data['last'] = {} > > ?96 > > ?97 def store(data, full_name): > > ?98 ? ? names = full_name.split() > > 100 ? ? if len(names) == 2: names.insert(1, '') > > 101 ? ? labels = 'first', 'middle', 'last' > > 103 ? ? for label, name in zip(labels, names): > > 104 ? ? ? ? people = lookup(data, label, name) > > 105 ? ? if people: > > 106 ? ? ? ? people.append(full_name) > > 107 ? ? else: > > 108 ? ? ? ? data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 ? ? return data[label].get(name) > > 112 > > 113 > > 114 MyNames = {} > > 115 init(MyNames) > > 116 store(MyNames, 'John Larry Smith') > > 117 lookup(MyNames, 'middle', 'Smith') > > If it tells you so I'm not really sure its a good book - partially for > teaching you into the unpythonic way to do things (above stuff, if its > not a counter example, should really go into a class) > > Have you tried the tutorial first? Its online and very easy to follow > from the very beginning but you can also skip parts if you are sure you > already understand it: > > http://docs.python.org/tutorial/ > > HTH > Tino The book is "Apress Beginning Python 2nd Edition". I think what you are saying is if I don't understand all of the code I should go into a class? Unfortunately I don't have the money or time to enroll into a class and even if I did they wouldn't be teaching Python it would be Java instead...and I've already taken Java before...so that's not really an option... Regardless, I understand up to the part "for label, name in zip (labels, names):" which zips the two sequences 'names' and 'labels' into a list of tuples... What I am not totally sure about is when the store function callsthe lookup function and does "return data[label].get(name)", that line "trips" me up some....then the lookup function returns that back to the store function, assigns the data to the variable 'people', THEN does this, which also isn't that clear to me what it's all doing: if people: people.append(full_name) else: data[label][name] = [full_name] My main problem is finding out what's it's actually *doing*? I know and understand the terminologies (what 'append' does, what a 'sequence' is, a 'list', a 'tuple', 'if'...'else'...etc...et....) Thanks for the reply back From suzieprogrammer at gmail.com Mon Nov 23 13:45:13 2009 From: suzieprogrammer at gmail.com (Susan Day) Date: Mon, 23 Nov 2009 13:45:13 -0500 Subject: Line Breaks Message-ID: Hi; I have the following line of code I'm sending to postfix: msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' '), msg) Unfortunately, it ignores the line breaks. I also tried %0A but that was ignored also. Please advise. TIA, Suzie -------------- next part -------------- An HTML attachment was scrubbed... URL: From knny.myer at gmail.com Mon Nov 23 13:45:35 2009 From: knny.myer at gmail.com (~km) Date: Mon, 23 Nov 2009 10:45:35 -0800 (PST) Subject: Implementation of Book Organization tool (Python2.[x]) References: <4b0a06b8$1@dnews.tpgi.com.au> Message-ID: <319dbc2f-3f29-4c65-ac18-8b14dda34592@e7g2000vbi.googlegroups.com> > Though many would disagree, I consider XML as a form of database though > it is only suitable for data exchange. XML is suitable for low- to > medium-volume purpose and when compatibility with various systems is > extremely important (nearly any OS and any programming language has XML > parsers; porting a DBMS system may not be as easy as that). Thanks for the feedback. I consider XML as not very readable, so I prefer a Mark-up language like YAML. Cleaner syntax... but well, that's personal preference. > Python dictionary is stored in memory and closing the program == > deleting the database. [...] My error.. although pickling I would only "prefer" if organizing <100 books. From marcglec at free.fr Mon Nov 23 13:47:22 2009 From: marcglec at free.fr (Marc Leconte) Date: Mon, 23 Nov 2009 19:47:22 +0100 Subject: problem manipulating a list belonging to a class In-Reply-To: References: <660590ac-9590-4ce8-bb5e-4145eefe7599@u36g2000prn.googlegroups.com> Message-ID: <1259002042.6674.0.camel@gondor> Thx all, good to know :) Le dimanche 22 novembre 2009 ? 15:16 -0800, Steve Howell a ?crit : > On Nov 22, 3:14 pm, Steve Howell wrote: > > > Explanations of why you need to write it that will follow... > > I knew this had to be written up somewhere... > > http://www.ferg.org/projects/python_gotchas.html#contents_item_6 From sergiomb at sapo.pt Mon Nov 23 13:50:40 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Mon, 23 Nov 2009 18:50:40 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> Message-ID: <4b0ad983$0$13161$a729d347@news.telepac.pt> Diez B. Roggisch wrote: Hi, Thanks, > S?rgio Monteiro Basto wrote: > >> Hi, >> I am in x86_64 arch , but I need >> compile things on 32 bits with >> python setup.py build >> >> Can't change the fact that distutils creates x86_64 >> directories: >> build/temp.linux-x86_64-2.3/ >> >> Also if I try with a python compile in 32bits and installed >> in system . > > I doubt that. Distutils will always build based on the architecture of the > interpreter you used when building an external module. > > Are you sure that the python you used to build the extension was the right > one? What does > > -c "from distutils.util import get_platform; print > get_platform()" python32 -c "from distutils.util import get_platform; print get_platform()" linux-x86_64 ldd ~/bin/python32 linux-gate.so.1 => (0xffffe000) libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) libdl.so.2 => /lib/libdl.so.2 (0x0033f000) libutil.so.1 => /lib/libutil.so.1 (0x006b3000) libm.so.6 => /lib/libm.so.6 (0x00345000) libc.so.6 => /lib/libc.so.6 (0x001e0000) /lib/ld-linux.so.2 (0x001c2000) this a python 2.3, that's make any difference ? > > return? > > Diez From ethan at stoneleaf.us Mon Nov 23 13:52:00 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 10:52:00 -0800 Subject: attributes, properties, and accessors -- philosophy Message-ID: <4B0AD9D0.3000104@stoneleaf.us> The problem I have with properties is my typing. I'll end up assigning to an attribute, but get the spelling slightly wrong (capitalized, or missing an underscore -- non-obvious things when bug-hunting), so now I have an extra attribute which of course has zero effect on what I'm trying to do and I start getting wierd results like viewing deleted records when I *know* I set useDeleted = False... 30 minutes later I notice it was /supposed/ to be use_deleted. *sigh* So -- to keep myself out of trouble -- I have started coding such things as, for example: result = table.use_deleted() # returns True or False table.use_deleted(False) # skip deleted records instead of result = table.use_deleted table.use_deleted = False My question: is this [ severely | mildly | not at all ] un-pythonic? ~Ethan~ From jfabiani at yolo.com Mon Nov 23 14:01:00 2009 From: jfabiani at yolo.com (jfabiani at yolo.com) Date: Mon, 23 Nov 2009 11:01:00 -0800 Subject: Python & OpenOffice Spreadsheets References: <87pr79cx5m.fsf@rudin.co.uk> Message-ID: Krishnakant wrote: > On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: >> Gerhard H?ring writes: >> >> > Is there a *simple* way to read OpenOffice spreadsheets? >> > >> > Bonus: write them, too? >> > >> > I mean something like: >> > >> > doc.cells[0][0] = "foo" >> > doc.save("xyz.ods") >> > >> >>From a quick look, pyodf offers little more than just using a XML >> >>parser >> > directly. >> >> >> Depends on exactly what you mean by "simple" - but pyuno allows you to >> read and write openoffice spreadsheets. > > > Odfpy is a good module and is easy too. > http://kk.hipatia.net/public/gnukhata/gnukhata-client/ has a deb package > I built for ubuntu 9.04. > I can even provide you the distutils tarball off the list (because I > can't recall the url from I downloaded it, may be sourceforge ). > Happy hacking. > Krishnakant Would you including me in your response. I'd really like to find a py module to allow simple use of openoffice. Johnf From david_v_wright at yahoo.com Mon Nov 23 14:05:09 2009 From: david_v_wright at yahoo.com (david wright) Date: Mon, 23 Nov 2009 11:05:09 -0800 (PST) Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <753779.1414.qm@web31811.mail.mud.yahoo.com> ----- Original Message ---- From: j To: python-list at python.org Sent: Mon, November 23, 2009 10:26:42 AM Subject: Re: Beginning Question about Python functions, parameters... On Nov 23, 12:37 pm, Neo wrote: > astral orange schrieb: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > 92 def init(data): > > 93 data['first'] = {} > > 94 data['middle'] = {} > > 95 data['last'] = {} > > 96 > > 97 def store(data, full_name): > > 98 names = full_name.split() > > 100 if len(names) == 2: names.insert(1, '') > > 101 labels = 'first', 'middle', 'last' > > 103 for label, name in zip(labels, names): > > 104 people = lookup(data, label, name) > > 105 if people: > > 106 people.append(full_name) > > 107 else: > > 108 data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 return data[label].get(name) > > 112 > > 113 > > 114 MyNames = {} > > 115 init(MyNames) > > 116 store(MyNames, 'John Larry Smith') > > 117 lookup(MyNames, 'middle', 'Smith') > > If it tells you so I'm not really sure its a good book - partially for > teaching you into the unpythonic way to do things (above stuff, if its > not a counter example, should really go into a class) > > Have you tried the tutorial first? Its online and very easy to follow > from the very beginning but you can also skip parts if you are sure you > already understand it: > > http://docs.python.org/tutorial/ > > HTH > Tino > > > My main problem is finding out what's it's actually *doing*? open it up in IDLE (or whatever development environment you use) and use the debugger to step through the code. the only way to learn stuff is to actually play with it. make a guess as to what will happen, run it, did that happen? what did happen? change something, what happens now? etc. From clp2 at rebertia.com Mon Nov 23 14:06:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 23 Nov 2009 11:06:14 -0800 Subject: attributes, properties, and accessors -- philosophy In-Reply-To: <4B0AD9D0.3000104@stoneleaf.us> References: <4B0AD9D0.3000104@stoneleaf.us> Message-ID: <50697b2c0911231106o3ac9edc5i83fcf75e423eaf04@mail.gmail.com> On Mon, Nov 23, 2009 at 10:52 AM, Ethan Furman wrote: > The problem I have with properties is my typing. ?I'll end up assigning to > an attribute, but get the spelling slightly wrong (capitalized, or missing > an underscore -- non-obvious things when bug-hunting), so now I have an > extra attribute which of course has zero effect on what I'm trying to do and > I start getting wierd results like viewing deleted records when I *know* I > set useDeleted = False... 30 minutes later I notice it was /supposed/ to be > use_deleted. ?*sigh* > > So -- to keep myself out of trouble -- I have started coding such things as, > for example: > > result = table.use_deleted() ? ? ? # returns True or False > table.use_deleted(False) ? ? ? ? ? # skip deleted records > > instead of > > result = table.use_deleted > table.use_deleted = False > > My question: ?is this [ severely | mildly | not at all ] un-pythonic? Yes, it's unpythonic. Use something like pychecker, pylint, or pyflakes, which will catch the sorts of typo errors you talk about. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Mon Nov 23 14:12:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Nov 2009 19:12:12 +0000 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <4B0ADE8C.7010007@mrabarnett.plus.com> j wrote: > On Nov 23, 12:37 pm, Neo wrote: >> astral orange schrieb: >> >> >> >>> Hi, I am trying to teach myself Python and have a good book to help me >>> but I am stuck on something and I would like for someone to explain >>> the following piece of code for me and what it's actually doing. >>> Certain parts are very clear but once it enters the "def store(data, >>> full_name): ...." function and the "def lookup()..." function things >>> get a little confusing for me. Specifically, lines 103-108 *and* Lines >>> 110-111. >>> Lastly, I am not sure how to print the results I've put into this >>> program either, the book I'm reading doesn't tell me. As you can tell, >>> I am a beginner and I don't truly understand everything that is going >>> on here...a lot, but not all.... >>> Here is the code: >>> 92 def init(data): >>> 93 data['first'] = {} >>> 94 data['middle'] = {} >>> 95 data['last'] = {} >>> 96 >>> 97 def store(data, full_name): >>> 98 names = full_name.split() >>> 100 if len(names) == 2: names.insert(1, '') >>> 101 labels = 'first', 'middle', 'last' >>> 103 for label, name in zip(labels, names): >>> 104 people = lookup(data, label, name) >>> 105 if people: >>> 106 people.append(full_name) >>> 107 else: >>> 108 data[label][name] = [full_name] >>> 109 >>> 110 def lookup(data, label, name): >>> 111 return data[label].get(name) >>> 112 >>> 113 >>> 114 MyNames = {} >>> 115 init(MyNames) >>> 116 store(MyNames, 'John Larry Smith') >>> 117 lookup(MyNames, 'middle', 'Smith') >> If it tells you so I'm not really sure its a good book - partially for >> teaching you into the unpythonic way to do things (above stuff, if its >> not a counter example, should really go into a class) >> >> Have you tried the tutorial first? Its online and very easy to follow >> from the very beginning but you can also skip parts if you are sure you >> already understand it: >> >> http://docs.python.org/tutorial/ >> >> HTH >> Tino > > The book is "Apress Beginning Python 2nd Edition". I think what you > are saying is if I don't understand all of the code I should go into a > class? Unfortunately I don't have the money or time to enroll into a > class and even if I did they wouldn't be teaching Python it would be > Java instead...and I've already taken Java before...so that's not > really an option... > [snip] No, he's saying that the _functions_ shown in the code should go into a class, but the main criticism is that judging by the code shown above it doesn't look like a good book, and you should look at the on-line tutorial first if you haven't already done so. From neilc at norwich.edu Mon Nov 23 14:13:44 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Nov 2009 19:13:44 GMT Subject: Line-continuation "Anti-Idiom" and with statement Message-ID: <7n0578F3j7qa6U1@mid.individual.net> I installed Python 3.1 today, and I've been porting my small library of programs to the new system. I happened to read the interesting "Idioms and Anti-Idioms" HOWTO, and saw the '\' continuation character labeled an anti-idiom. I already generally avoided it, so I just nodded. Unfortunately, the new "nested" with statement (which I also read about today) forces me into this anti-idiom. When replacing an appearance of contextlib.nested with the 3K with statement, I ended up with an unexpected syntax error. with (open(roster_path, 'r') as roster_file, open(disb_path, 'w') as out_file, open(report_path, 'w') as report_file): The result was: File "C:\project\codxml.py", line 184 with (open(roster_path, 'r') as roster_file, ^ SyntaxError: invalid syntax Unless I'm missing something, I have to subject my code to a bit of contintuation: with open(roster_path, 'r') as roster_file,\ open(disb_path, 'w') as out_file,\ open(report_path, 'w') as report_file: I was thinking about submitting a enhancement request to the HOWTO, explaining that continuation my be required in this context. Am I missing anything obvious? -- Neil Cerutti From 457r0.jp at gmail.com Mon Nov 23 14:14:35 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 11:14:35 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: On Nov 23, 1:17?pm, "Diez B. Roggisch" wrote: > astral orange wrote: > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): ...." function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all.... > > > Here is the code: > > > ?92 def init(data): > > ?93 ? ? data['first'] = {} > > ?94 ? ? data['middle'] = {} > > ?95 ? ? data['last'] = {} > > ?96 > > ?97 def store(data, full_name): > > ?98 ? ? names = full_name.split() > > 100 ? ? if len(names) == 2: names.insert(1, '') > > 101 ? ? labels = 'first', 'middle', 'last' > > 103 ? ? for label, name in zip(labels, names): > > The zip-function takes n iterables, and produces a list with n-tuples out of > it. Type this into the python-prompt: > > >>> zip([1, 2, 3], ["a", "b", "c"]) > > The other thing here is tuple-unpacking. If you know that something has a > specific length, you can unpack it into distinct values like this: > > >>> a, b = (10, 20) > >>> print a > 10 > >>> print b > > 20 > > Now > > ?for label, name in zip(labels, names): > > does > > ?- create a list of tuples, each tuple having two elements, the first being > the label, the second a name > ?- loops over this list > ?- for each item in the list (remember, it's a 2-tuple!), unpack it into > label and name > > > 104 ? ? ? ? people = lookup(data, label, name) > > 105 ? ? if people: > > 106 ? ? ? ? people.append(full_name) > > 107 ? ? else: > > 108 ? ? ? ? data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 ? ? return data[label].get(name) > > Data here is expected to be a dictionary of dictionaries. The first level of > keys are the labels. The second is the name. It is expected that labels > always exist, but names might be empty, so instead of writing > > ? return data[label][name] > > it uses get(name) on a dict which will return the ?value for the key, or > None: > > > > >>> {"foo" : "bar"}.get("foo") > bar > >>> {"foo" : "bar"}.get("baz") > >>> # no output means None > > That being said, I agree with Neo that this introduction seems to be rather > bad. > > Diez Thanks all for the replies back! I do appreciate it. Yes, lines 104-111 is really where my problem lies in understanding what is going on here. I am beginner so this stuff seems a little unwieldy at the moment. :) I *did* invest $40 into this book so it' what I have to work with. By the way, the book is, "Apress Beginning Python 2nd Edition".... But back to the example, on line 104 I see there's a call to the lookup function, passing 3 parameters ('data', which I think is a nested dictionary, label (first, middle, last) and name). But I am getting lost on line 111 after the parameters are passed in to the lookup function. I'm not exactly sure what it's returning and when it does return, is this assigned the the variable 'people'? And if so, I'm not sure what 'append(full_name)' does here. The else statement which assigns '[full_name]' to 'data[label][name]' is somewhat confusing as I'm saying to myself where the heck did '[full_name]' come "into the picture". If I could understand what's going on with everything in this the rest of the chapter and the next should be fairly easy, but I really need to understand this before I move on. Thanks again for the replies back. I am looking over your comments right now. 457r0 From thomas.robitaille at gmail.com Mon Nov 23 14:14:38 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Mon, 23 Nov 2009 11:14:38 -0800 (PST) Subject: Read IDL save files into Python Message-ID: I would like to briefly advertise the 0.9.2 release of IDLSave, a package I recently developed to read IDL save files into Python. Installation instructions are available at http://idlsave.sourceforge.net/. Please do not hesitate to submit a bug report if you run into any problems! Cheers, Thomas From niklasro at gmail.com Mon Nov 23 14:20:27 2009 From: niklasro at gmail.com (NiklasRTZ) Date: Mon, 23 Nov 2009 11:20:27 -0800 (PST) Subject: IDE+hg Message-ID: Dear experts, Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim Mercurial support not found i.e. buttons to clone, commit and push to repositories to define dev env dvcs, editor and deployment all in 1. I tested Boa Constructor, dr Python, Eric and PIDA none of which has other than commandline access to Mercurial which is faster bound to button. The editor Eric claims "Mercurial support" and no obvious (button or plugin) availability, same with dr Python. Mercurial support these IDEs claim may mean that it's compatible and you must add the hg button customizing the editor. programatically. If you know a good light IDE with hg, please inform. Topic handled earlier, still undecided http://groups.google.com/group/google-appengine-python/browse_thread/... Thanks in advance Niklas Rosencrantz From apt.shansen at gmail.com Mon Nov 23 14:22:44 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:22:44 -0800 Subject: Line Breaks In-Reply-To: References: Message-ID: <7a9c25c20911231122v4049d726gba8d51267998d1da@mail.gmail.com> On Mon, Nov 23, 2009 at 10:45 AM, Susan Day wrote: > Hi; > I have the following line of code I'm sending to postfix: > > msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' '), > msg) > > Unfortunately, it ignores the line breaks. I also tried %0A but that was > ignored also. Please advise. > Does it ignore ALL line breaks-- or just doubled ones like \n\n? E.g., blank lines? I *think* its probably the latter, and doing msg.replace('\n\n', '\n \n') will make it work. That'd end up with a single space on those blank lines. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Mon Nov 23 14:26:38 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 23 Nov 2009 11:26:38 -0800 Subject: Line Breaks In-Reply-To: References: Message-ID: <4B0AE1EE.5070705@islandtraining.com> Susan Day wrote: > Hi; > I have the following line of code I'm sending to postfix: > > msg = 'A Message From %s:\n\n %s' % (string.replace(customer, '_', ' > '), msg) > > Unfortunately, it ignores the line breaks. I also tried %0A but that > was ignored also. Please advise. > TIA, > Suzie That line does not ignore line breaks. Proof: >>> print 'A Message From %s:\n\n %s' % ('someone','some message') A Message From someone: some message So... *Exactly* what are you doing with msg, and *exactly* what is your evidence that line breaks are being ignored. With that information, perhaps we can identify and solve the real problem you're having. Gary Herron From apt.shansen at gmail.com Mon Nov 23 14:33:37 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:33:37 -0800 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <0eeea855-9551-42b1-8036-940558b00f46@j35g2000vbl.googlegroups.com> Message-ID: <7a9c25c20911231133x1be0359t84d8109efcacb9b8@mail.gmail.com> On Mon, Nov 23, 2009 at 10:26 AM, j wrote: > What I am not totally sure about is when the store function callsthe > lookup function and does "return data[label].get(name)", that line > "trips" me up some....then the lookup function returns that back to > the store function, assigns the data to the variable 'people', THEN > does this, which also isn't that clear to me what it's all doing: > > It does it right when it hits it in the code; basically, the for loop runs over the list of items from the zip. In each one, it calls the lookup function. Execution then jumps over to lookup. Once the lookup function is done ('returns' or hits its it), execution jumps right back with a result, and that result is stored int he 'people' variable. Then the next item in the for loop is processed; again, when the function() is called, execution jumps over to that again, and so on. Only when all the things are done in the for loop, does execution move on to... > if people: > people.append(full_name) > else: > data[label][name] = [full_name] > > Basically, "lookup" will return one of two things. If someone with the given part of a name already has been stored, it'll return a list containing the people with that name. Otherwise, it will return None. The if/else above will operate on those two conditions: if 'lookup' returned a list of people, its going to add this person to that list. If it doesn't return a list of people, it's going to add this persons name to the data dictionary as a new list. So anyone in the future who has that name will find them on lookup. The thing is, I think lines 105-108 should be indented deeper one level to be 'inside' the for loop; and thus called with each execution, and not only after the for is all done with. As it is, it seems like a bug. Or I don't get at all what the point of the code is :) > My main problem is finding out what's it's actually *doing*? I know > and understand the terminologies (what 'append' does, what a > 'sequence' is, a 'list', a 'tuple', 'if'...'else'...etc...et....) > I concur with the other people who say this is bad code to learn from; the book could be a LOT clearer. I'd try another resource.. the online Python tutorial is a good place to start. A different book may be in order :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Nov 23 14:40:52 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 11:40:52 -0800 Subject: Beginning Question about Python functions, parameters... In-Reply-To: References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: <7a9c25c20911231140y8a9394cp95d04f52dcd53a1f@mail.gmail.com> On Mon, Nov 23, 2009 at 11:14 AM, astral orange <457r0.jp at gmail.com> wrote: > But back to the example, on line 104 I see there's a call to the > lookup function, passing 3 > parameters ('data', which I think is a nested dictionary, label > (first, middle, last) and name). > > But I am getting lost on line 111 after the parameters are passed in > to the lookup function. I'm > not exactly sure what it's returning The 'get' method of dictionaries returns either the value if it exists, or None. So lookup is returning either a the value from that nested dictionary (the value which will be a list of names), or None. > and when it does return, is this > assigned the the variable > 'people'? Yes. > And if so, I'm not sure what 'append(full_name)' does here. > The else statement which assigns > '[full_name]' to 'data[label][name]' is somewhat confusing as I'm > saying to myself where the heck did > '[full_name]' come "into the picture". > > Look up at line 97. The "purpose" of this code seems-- on a cursory glance-- to be to categorize peoples names into lists where their names are common. The data dictionary contains three dictionaries; one for first names, one for middle names, one for last names. Each dictionary would, over time, contain the name-part as a key and then a list of full names... So, I'd be: data['first']['Stephen'] = ['Stephen Hansen'] data['last']['Hansen'] = ['Stephen Hansen'] Then if Bob Hansen was run through the code, it'd end up as: data['last']['Hansen'] = ['Stephen Hansen', 'Bob Hansen'] At least I think that's what the code is doing. Based upon just a stare. :) (And if that's what its doing, I think it has a bug as I mentioned in a previous email; I think lines 105-108 need to be indented one level more) So, what all this code is doing is breaking apart someoen's full_name which was passed into the function originally, and seeing where to put it. That's what the for loop and lookup function calls are doing... seeing if we need a new list , or if there's an existing one to add the name to... When it decides where it goes, it puts the full_name in. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From suzieprogrammer at gmail.com Mon Nov 23 14:46:23 2009 From: suzieprogrammer at gmail.com (Susan Day) Date: Mon, 23 Nov 2009 14:46:23 -0500 Subject: Line Breaks In-Reply-To: <4B0AE1EE.5070705@islandtraining.com> References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron wrote: > >>> print 'A Message From %s:\n\n %s' % ('someone','some message') > A Message From someone: > > some message > > > So... *Exactly* what are you doing with msg, and *exactly* what is your > evidence that line breaks are being ignored. With that information, perhaps > we can identify and solve the real problem you're having. > First, it does in fact ignore all line breaks, not just double line breaks. Here's what I'm doing: session.sendmail(clientEmail, ourEmail2, header+msg) The email sent out has the message sans breaks. TIA, Suzie -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Nov 23 14:49:49 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 23 Nov 2009 19:49:49 +0000 Subject: Minimally intrusive XML editing using Python References: Message-ID: On Mon, 23 Nov 2009 17:45:24 +0100, Thomas Lotze wrote: >> What's your real problem, or use case? Are you just concerned with >> diffing, or are others likely to read the xml, and want it formatted the >> way it already is? > > I'd like to put the XML under revision control along with other stuff. > Other people should be able to make sense of the diffs and I'd rather not > require them to configure their tools to use some XML differ. In which case, the data format isn't "XML", but a subset of it (and probably an under-defined subset at that, unless you invest a lot of effort in defining it). That defeats one of the advantages of using a standardised "container" format such as XML, i.e. being able to take advantage of existing tools and libraries (which will be written to the offical standard, not to your private "standard"). One option is to require the files to be in a canonical form. Depending upon your revision control system, you may be able to configure it to either check that updated files are in this form, or even to convert them automatically. If your existing files aren't in such a form, there will be a one-time penalty (i.e. a huge diff) when converting the files. From tjreedy at udel.edu Mon Nov 23 14:56:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 14:56:05 -0500 Subject: Switching Databases In-Reply-To: <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> References: <4dc0cfea0911230247r6a2935c1ja0f036566e05aa0f@mail.gmail.com> <4dc0cfea0911230645k33215f8q8deeaa92dbbc3c57@mail.gmail.com> <4dc0cfea0911230726h477bd1bap2e7a54f490021d17@mail.gmail.com> Message-ID: Victor Subervi wrote: > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. [snip hmtl error report] Please post plain text - ascii or utf8. On my newsreader, what you posted, with a mismash of colors, bold, italic, and sizes, is not readable. From mal at egenix.com Mon Nov 23 14:59:43 2009 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 23 Nov 2009 20:59:43 +0100 Subject: python and netezza In-Reply-To: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> References: <183cd964-d567-4352-8168-62f95d68941f@x15g2000vbr.googlegroups.com> Message-ID: <4B0AE9AF.3040606@egenix.com> Shan wrote: > Is there any module in python to connect with netezza database?(like > cx_Oracle which is used to connect Oracle from python) You can use our mxODBC database adapters together with the Netezza ODBC drivers. For single-tier setups (client application and database on the same server or the same platform, e.g. both Windows): http://www.egenix.com/products/python/mxODBC/ For multiple-tier setups (client application on a different server or different platform, e.g. Linux and Windows): http://www.egenix.com/products/python/mxODBCConnect/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 23 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 python at mrabarnett.plus.com Mon Nov 23 15:17:19 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 23 Nov 2009 20:17:19 +0000 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <7n0578F3j7qa6U1@mid.individual.net> References: <7n0578F3j7qa6U1@mid.individual.net> Message-ID: <4B0AEDCF.4060300@mrabarnett.plus.com> Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generally avoided it, so I just nodded. > > Unfortunately, the new "nested" with statement (which I also read > about today) forces me into this anti-idiom. When replacing an > appearance of contextlib.nested with the 3K with statement, I > ended up with an unexpected syntax error. > > with (open(roster_path, 'r') as roster_file, > open(disb_path, 'w') as out_file, > open(report_path, 'w') as report_file): > > The result was: > > File "C:\project\codxml.py", line 184 > with (open(roster_path, 'r') as roster_file, > ^ > SyntaxError: invalid syntax > > Unless I'm missing something, I have to subject my code to a bit > of contintuation: > > with open(roster_path, 'r') as roster_file,\ > open(disb_path, 'w') as out_file,\ > open(report_path, 'w') as report_file: > > I was thinking about submitting a enhancement request to the > HOWTO, explaining that continuation my be required in this > context. Am I missing anything obvious? > The relevant syntax is: with_stmt ::= "with" with_item ("," with_item)* ":" suite with_item ::= expression ["as" target] Parentheses only work around an expression or when they are expected by the syntax, eg in function calls. In this case it sees the '(' and thinks that it's the start of a parenthesised expression. It parses the expression, then sees 'as', hence a SyntaxError. I suppose it could've complained about a missing ')' instead. I wonder whether an end-of-line could be ignored after a comma in a 'with' statement, and, for consistency, in any similar cases. From carsten.haese at gmail.com Mon Nov 23 15:18:05 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 23 Nov 2009 15:18:05 -0500 Subject: Don't Understand Error In-Reply-To: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> References: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Message-ID: Victor Subervi wrote: > [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end > of script headers: mailSpreadsheet.py, referer: > http://globalsolutionsgroup.vi/display_spreadsheet.py > > Why? A CGI script is expected to produce output. Your script doesn't produce any output, and Apache is complaining about that. -- Carsten Haese http://informixdb.sourceforge.net From tjreedy at udel.edu Mon Nov 23 15:18:56 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:18:56 -0500 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Robert Kern wrote: > On 2009-11-23 04:47 AM, Antoine Pitrou wrote: >> Le Mon, 23 Nov 2009 02:36:33 -0600, Robert Kern a ?crit : >>> >>> I think there is an overall design sensibility, it's just not a >>> human-facing one. They claim that they designed the syntax to be very >>> easily parsed by very simple tools in order to make things like syntax >>> highlighters very easy and robust. So indentation-based blocks are right >>> out. >> >> But computer languages should be designed to be readable by humans. >> It's not like you need to write a new parser once a year, but you have to >> read code everyday. > > You will get no argument from me. My point was only that they had an > overall design sensibility, I think you characterized it fairly, even if it is not one many of us here want to work within. Of course, one way they could show the benefit of Go would be to rewrite CPython in Go and have it be faster, at least for appropriate programs on multicore machines. Or write a Python compiler. Either way, include a foreign function interface that could connect to existing C extensions. Google and the rest of the world certainly have lots of code to test such. From timprepscius at gmail.com Mon Nov 23 15:22:02 2009 From: timprepscius at gmail.com (timprepscius) Date: Mon, 23 Nov 2009 12:22:02 -0800 (PST) Subject: sandbox python via module loader Message-ID: <842a6cb7-b735-4362-829e-bcc09b813d06@m11g2000vbo.googlegroups.com> Greetings, in the past I wrote a sandboxing module loader for c++/ python. I am moving away from python.. I can't stand it actually. Call me blasphemous... I'm immune.. So this code is going to just find the trash.. Maybe it will be useful to someone else. Can't post it all, however, if you are trying to integrate python into a system in which you need to restrict access to "safe" modules (meaning, non-native code), and wish also to restrict a script's ability to access other scripts, may be useful to have a look at. Basically, it is modeled after java. Each instantiated script in your system will have a ModuleLoader. That module loader is in charge of enforcing restrictions. Sorry for not being able to post a full compilable segment. But this sure would have helped me to look at before I wrote it. -tim p.s. Man I hope this code is formatted okay after posting.. Will see I guess. Anyway. Cheers. -- .h /** * legal header - public domain * * ============================================================================ * * @author Timothy Prepscius */ #ifndef __SnowCrash_Script_Python_Internal_PScriptModuleLoader_h__ #define __SnowCrash_Script_Python_Internal_PScriptModuleLoader_h__ #include #include #include #include #include #include #define BOOST_PYTHON_STATIC_LIB #include namespace SnowCrash { namespace Script { namespace Python { namespace pInternal { class PModuleLoader { protected: static boost::python::object mainDictionary; static bool importLock; protected: typedef std::set ModuleSources; ModuleSources moduleSources; typedef std::map ModuleMap; typedef std::list ModuleList; ModuleMap moduleMap; // this is to ensure that modules are destroyed in reverse order of construction // because python doesn't seem to keep module references within modules ModuleList moduleList; PyObject *getCachedModule (const Utilities::URL &url); void setCachedModule (const Utilities::URL &url, PyObject *); PyObject *returningModule (PyObject *); PyObject *loadModule (Utilities::Transporter::BufferPtr buffer); Utilities::Transporter::BufferPtr loadCodeString (const Utilities::URL &url); PyObject *getModule(const Utilities::URL &name); PyObject *findModule(const std::wstring &name); typedef std::list ModuleURLList; ModuleURLList modulesLoading; public: PModuleLoader (); virtual ~PModuleLoader(); void addAvailableSource (const Utilities::URL &); PyObject *loadModule (const char *name); PyObject *loadModule (const Common::Script::Signature &); static PyObject *__import__ ( const char *name, PyObject *globals = NULL, PyObject *locals = NULL, PyObject *fromlist = NULL, PyObject *level = NULL ); static void setMainDictionary (boost::python::object); static void setImportLock (bool lock); } ; } // namespace pInternal } // namespace Python } // namespace Script } // namespace SnowCrash #endif -- .cpp /** * legal header - public domain * * ============================================================================ * * @author Timothy Prepscius */ #include "Utilities/BaseInclude/CppInclude.h" #include "PModuleLoader.h" #include #include "Global/Utilities.h" #include "Script/Instance.h" #include "../../Monitor.h" #include "../pScript/PScript.h" #include "../Exception.h" #include // for PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #include "marshal.h" //----------------------------------------------------------------------------- using namespace SnowCrash::Script::Python::pInternal; using namespace SnowCrash::Script::Python; using namespace SnowCrash::Script; using namespace boost::python; // ============================================================================= object PModuleLoader::mainDictionary; bool PModuleLoader::importLock = true; void PModuleLoader::setMainDictionary (object object) { PModuleLoader::mainDictionary = object; } PyObject *PModuleLoader::loadModule (Utilities::Transporter::BufferPtr buffer) { PyObject *m=NULL, *co=NULL, *v=NULL; try { // read the object // this failed once! must investigate co = PyMarshal_ReadObjectFromString (buffer->getData()+8, buffer- >getSize()-8); if (!co) throw Python::Exception (); m = PyModule_New("_private_"); if (!m) throw Python::Exception (); // get the dictionary and fill in the neccessary values.. arbitrary to us. // notice the incref on the dictionary, if it is not there garbage collections dies a // miserable death object dict = object(handle<>(incref(PyModule_GetDict(m)))); dict["__builtins__"] = mainDictionary["__builtins__"]; object fname = object(handle<>(((PyCodeObject *)co)->co_filename)); std::string s = extract(fname); dict["__file__"] = fname; // evaluate the code, I wonder what this returns. v = PyEval_EvalCode((PyCodeObject *)co, dict.ptr(), dict.ptr()); if (v) { decref (v); } else { throw Python::Exception(); } } catch (Python::Exception &e) { std::string pe = handleException (e); LogRelease (PModuleLoader::loadModule, "caught exception " << pe); } catch (...) { LogRelease (PModuleLoader::loadModule, "caught unknown exception."); } return m; } PyObject *PModuleLoader::returningModule (PyObject *module) { if (module) { moduleList.push_back (object(detail::borrowed_reference(module))); incref (module); return module; } Py_RETURN_NONE; } Utilities::Transporter::BufferPtr PModuleLoader::loadCodeString (const Utilities::URL &url) { std::wstring extension = L".pyc"; std::wstring urlString = url; if (urlString.find (extension) == -1) urlString += extension; Utilities::URL fileURL (urlString); Utilities::VFS::InFilePtr inFile = Utilities::VFS::SystemSingleton->getInFile ( Global::getVFSDataPath(fileURL) ); if (inFile) { int size = inFile->size(); char *buffer = new char[size]; inFile->read (buffer, size); return new Utilities::Transporter::AllocatorBuffer (buffer, size); } return NULL; } PModuleLoader::PModuleLoader () { } PModuleLoader::~PModuleLoader () { moduleMap.clear(); while (!moduleList.empty()) moduleList.pop_front(); } void PModuleLoader::addAvailableSource (const Utilities::URL &url) { moduleSources.insert (url); } PyObject *PModuleLoader::getCachedModule (const Utilities::URL &url) { std::wstring moduleName = url; // quick return if we have it ModuleMap::iterator i = moduleMap.find(moduleName); if (i != moduleMap.end()) return i->second; return NULL; } void PModuleLoader::setCachedModule (const Utilities::URL &url, PyObject *module) { std::wstring moduleName = url; moduleMap[moduleName] = module; } PyObject *PModuleLoader::getModule (const Utilities::URL &url) { // see if we have a cached module PyObject *module = getCachedModule (url); if (module) return module; // else try to load the codestring Utilities::Transporter::BufferPtr codeString = loadCodeString (url); if (codeString) { // try to load the module modulesLoading.push_front (url); module = loadModule (codeString); modulesLoading.pop_front (); } setCachedModule (url, module); return module; } PyObject *PModuleLoader::findModule (const std::wstring &name) { // first try to load the relative path from the module if (!modulesLoading.empty()) { const Utilities::URL &url = modulesLoading.front(); Utilities::URL urlWithName (url, name); PyObject *module = getModule (urlWithName); if (module) return module; } ModuleSources::iterator i; for (i=moduleSources.begin(); i!=moduleSources.end(); ++i) { const Utilities::URL &url = *i; Utilities::URL urlWithName = Utilities::URL::join(url, name); PyObject *module = getModule(urlWithName); if (module) return module; } return NULL; } PyObject *PModuleLoader::loadModule (const Common::Script::Signature &signature) { // path/file/class std::wstring invokation = signature.getInvokation(); // path/file std::wstring path = Utilities::File::getDirectory (invokation, false); // zipfile.zip/path/file Utilities::URL zipPath = Utilities::URL::join(signature.getURL (),path); return returningModule (getModule (zipPath)); } PyObject *PModuleLoader::loadModule (const char *name) { std::wstring path = Utilities::String::convert (name); std::replace (path.begin(), path.end(), L'.', L'/'); return returningModule(findModule (path)); } PyObject *PModuleLoader::__import__ ( const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, PyObject *level ) { LogDebug (Script::Python, "__import__ " << name); try { static char *allowedBuiltinModules[] = { "dD.*", "dD_*", NULL } ; bool allowed = !importLock; // check if it matches a given pattern int i; for (i=0; !allowed && allowedBuiltinModules[i]!=NULL; ++i) { char *check = allowedBuiltinModules[i]; int checkLength = strlen(check); // if there is a star at the end, match all thing that have the substring at the beginning if (check[checkLength-1] == '*') { if (strncmp (name, check, checkLength-1)==0) allowed = true; } else { if (strcmp (name, check)==0) allowed = true; } } // only import if it is one of ours, else, must be pure python code, // downloaded with the script if (allowed) { PyObject *module = PyImport_ImportModuleEx ((char *)name, globals, locals, fromlist); if (module) { incref (module); return module; } } } catch (Python::Exception &e) { handleException (e); } Script::Instance *script = Script::MonitorSingleton->getExecutingScript (); if (!script) Py_RETURN_NONE; Python::pScript::PScript *pscript = DynamicCastPtr(Python::pScript::PScript, script); return pscript->getModuleLoader()->loadModule (name); } void PModuleLoader::setImportLock (bool lock) { importLock = lock; } --- Also, for these things to be triggered, you need to override them in the main dictionary /** * legal header - public domain * * ============================================================================ * initials date comments * * @author Timothy Prepscius */ #include "Utilities/BaseInclude/CppInclude.h" #include "PPackage.h" #include "PAccessor.h" #include "PModuleLoader.h" #include "PRestricted.h" #include "PLog.h" #include "PSystem.h" #include "../Defines.h" using namespace SnowCrash::Script::Python::pInternal; using namespace boost::python; BOOST_PYTHON_MODULE(dD_internal) { class_("Log", init()) .def ("println", &PLog::println); class_("System", no_init) .def ("getClientTimeMS", &PSystem::getClientTimeMS) .staticmethod ("getClientTimeMS") .def ("getMetaverseTimeMS", &PSystem::getMetaverseTimeMS) .staticmethod ("getMetaverseTimeMS"); } BOOST_PYTHON_FUNCTION_OVERLOADS(import_overloads, PModuleLoader::__import__, 1, 5); BOOST_PYTHON_FUNCTION_OVERLOADS(compile_overloads, PRestricted::throwPermissionDeniedException, 3, 5); BOOST_PYTHON_FUNCTION_OVERLOADS(open_overloads, PRestricted::throwPermissionDeniedException, 1, 3); bool PPackage::registerNativeMethods () { if (! ( (PyImport_AppendInittab("dD_internal", initdD_internal) != -1) && PyImport_ImportModule ("dD_internal") )) return false; IMPLEMENT_PYTHON_CONVERTER (PAccessor); PModuleLoader::setImportLock (false); { object main = import("__main__"); object dict(main.attr("__dict__")); PModuleLoader::setMainDictionary (dict); object builtins (dict["__builtins__"]); scope within(builtins); def ("__import__", &PModuleLoader::__import__, import_overloads()); def ("compile", &PRestricted::throwPermissionDeniedException, compile_overloads()); def ("exit", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("execfile", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("file", &PRestricted::throwPermissionDeniedException, open_overloads()); def ("open", &PRestricted::throwPermissionDeniedException, open_overloads()); } PModuleLoader::setImportLock (true); return true; } bool PPackage::deregisterNativeMethods () { return true; } From tjreedy at udel.edu Mon Nov 23 15:28:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:28:37 -0500 Subject: Python & OpenOffice Spreadsheets In-Reply-To: <1258975507.3770.10.camel@krishna-laptop> References: <87pr79cx5m.fsf@rudin.co.uk> <1258975507.3770.10.camel@krishna-laptop> Message-ID: Krishnakant wrote: > On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote: >> Gerhard H?ring writes: >> >>> Is there a *simple* way to read OpenOffice spreadsheets? >>> >>> Bonus: write them, too? >>> >>> I mean something like: >>> >>> doc.cells[0][0] = "foo" >>> doc.save("xyz.ods") >>> >>> >From a quick look, pyodf offers little more than just using a XML parser >>> directly. >> >> Depends on exactly what you mean by "simple" - but pyuno allows you to >> read and write openoffice spreadsheets. > > > Odfpy is a good module and is easy too. Tarball at http://pypi.python.org/pypi/odfpy/ Hello world example at http://opendocumentfellowship.com/development/projects/odfpy From mail at anjanesh.net Mon Nov 23 15:30:19 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Tue, 24 Nov 2009 02:00:19 +0530 Subject: Waiting for receiving data Message-ID: <1a7951080911231230v2b76842fx7569c93f934125fd@mail.gmail.com> fp = urllib.urlopen(url) data = fp.read() Retrieving XML data via an XML service API. Very often network gets stuck in between. No errors / exceptions. CTRL+C File "get-xml.py", line 32, in fp = urllib.urlopen(url) File "/usr/lib/python2.6/urllib.py", line 87, in urlopen return opener.open(url) File "/usr/lib/python2.6/urllib.py", line 206, in open return getattr(self, name)(url) File "/usr/lib/python2.6/urllib.py", line 348, in open_http errcode, errmsg, headers = h.getreply() File "/usr/lib/python2.6/httplib.py", line 1048, in getreply response = self._conn.getresponse() File "/usr/lib/python2.6/httplib.py", line 974, in getresponse response.begin() File "/usr/lib/python2.6/httplib.py", line 391, in begin version, status, reason = self._read_status() File "/usr/lib/python2.6/httplib.py", line 349, in _read_status line = self.fp.readline() File "/usr/lib/python2.6/socket.py", line 397, in readline data = recv(1) KeyboardInterrupt Is there I can do to try something else if its taking too long to retrieve from the network ? Like kill previous attempt and retry ? Thanks Anjanesh Lekshmnarayanan From victorsubervi at gmail.com Mon Nov 23 15:33:43 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 23 Nov 2009 15:33:43 -0500 Subject: Don't Understand Error In-Reply-To: References: <4dc0cfea0911231010o44add32pa21e52e29dacb688@mail.gmail.com> Message-ID: <4dc0cfea0911231233g48e32472t5762a603151bf316@mail.gmail.com> On Mon, Nov 23, 2009 at 3:18 PM, Carsten Haese wrote: > Victor Subervi wrote: > > [Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end > > of script headers: mailSpreadsheet.py, referer: > > http://globalsolutionsgroup.vi/display_spreadsheet.py > > > > Why? > > A CGI script is expected to produce output. Your script doesn't produce > any output, and Apache is complaining about that. > Thank you. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 23 15:40:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 15:40:46 -0500 Subject: print function in python3.1 In-Reply-To: References: <7mvg8oF3jof5mU1@mid.uni-berlin.de> <7mvje2F3inifiU1@mid.uni-berlin.de> <1a7951080911230627r197a9aaaw9a715d30eb93d557@mail.gmail.com> <1a7951080911230755r12307fa5o2dbcf2ca8eb9fde6@mail.gmail.com> Message-ID: Dennis Lee Bieber wrote: > Does Python 3.x include SQLite? Of course ;-] >>> import sqlite3 >>> dir(sqlite3) ['Binary', 'Cache', 'Connection', 'Cursor', 'DataError', [snip] adapt', 'adapters', 'apilevel', 'complete_statement', 'connect', 'converters', 'datetime', 'dbapi2', 'enable_callback_tracebacks', 'enable_shared_cache', 'paramstyle', 'register_adapter', 'register_converter', 'sqlite_version', 'sqlite_version_info', 'threadsafety', 'time', 'version', 'version_info'] but is does not seem to have exposed escape_string function From solipsis at pitrou.net Mon Nov 23 15:47:37 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 23 Nov 2009 20:47:37 +0000 (UTC) Subject: Go versus Brand X References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: Le Mon, 23 Nov 2009 11:54:19 -0600, Robert Kern a ?crit?: > > Not really. The idea was to make the language easily parsed and lexed > and analyzed by *other* tools, not written in Go, that may have limited > capabilities. Well, if Go doesn't allow you to write libraries usable from other low- level languages I'm not sure it is a good systems programming language. One point of C is that you can bridge it with everything. > Vim isn't written in Go and won't be able to use their > API, for example. Syntax highlighting doesn't require a full-blown parser. You probably want to handle three types of events: - comments (and docstrings and the like for languages which have them) - keywords - delimiters of basic syntactical blocks (which most of the time is simply matching pairs of parens / square brackets / curly brackets) That is, you need a very small part of the information a complete parser would give you. In particular, you don't need to know about operator precedence. You don't need to know about what kind of block you are inside (function, method, class...). You don't need to know whether an identifier is a local variable, a global variable, a type, etc. You don't even need to know the different operators. You only need to recognize the basic lexemes and that's all. The reason the Go designers gave for the braindead syntax looks dramatically unserious and makes it look a bit like a joke. (actually, what really made me wonder whether Go was a joke was the "iota" keyword) From yota.news at gmail.com Mon Nov 23 15:49:44 2009 From: yota.news at gmail.com (yota.news at gmail.com) Date: Mon, 23 Nov 2009 12:49:44 -0800 (PST) Subject: dbapi2 select where IN (...) Message-ID: hello, I couldn't find how the dbapi2 planned to handle the sql IN statement. ex : SELECT * FROM table WHERE num IN (2,3,8,9); I'd be glad to take advantage of the ? mechanism, but what about tuples ! execute("""SELECT * FROM table WHERE num IN ?;""" , ((2,3,8,9),)) ...fail... what would be the most pythonic way to do this ? From joshua at joshuakugler.com Mon Nov 23 15:52:27 2009 From: joshua at joshuakugler.com (Joshua Kugler) Date: Mon, 23 Nov 2009 11:52:27 -0900 Subject: IDE+hg References: Message-ID: NiklasRTZ wrote: > If you > know > a good light IDE with hg, please inform. Topic handled earlier, still > undecided > http://groups.google.com/group/google-appengine-python/browse_thread/... > Thanks in advance > Niklas Rosencrantz WingIDE support Hg, as well as svn, git, and many others. j From wolftracks at invalid.com Mon Nov 23 15:58:00 2009 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 23 Nov 2009 12:58:00 -0800 Subject: A More Concise Description of Numpy than the Guide to Numpy? In-Reply-To: References: Message-ID: Robert Kern wrote: > On 2009-11-23 11:49 AM, W. eWatson wrote: >> I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more >> concise and practical guide to its use in science and mathematics? > > You will want to ask numpy questions on the numpy mailing list: > > http://www.scipy.org/Mailing_Lists > > You may also find the NumPy User Guide more up your alley: > > http://docs.scipy.org/doc/numpy/user/ > Thanks. I think I'll join the list, and the last link looks like a good alley. From patrickstinson.lists at gmail.com Mon Nov 23 16:02:47 2009 From: patrickstinson.lists at gmail.com (Patrick Stinson) Date: Mon, 23 Nov 2009 14:02:47 -0700 Subject: xmlrpc idea for getting around the GIL In-Reply-To: <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com> On Mon, Nov 23, 2009 at 1:01 AM, Carl Banks wrote: > On Nov 22, 10:58?pm, Patrick Stinson > wrote: >> On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: > icating) the multiprocessing module would be ideal. >> > The problem is that the OP has a embedded application running threads. >> > multiprocssing doesn't help there. >> >> that's right. I cannot make CPython calls from my original C-based threads. > > > It's quite possible to do that. ?A thread started from C can make > calls to Python if it first calls PyGILState_Ensure, although you'd > have to make sure that the Python interpreter has been previously > initialized. ?See PEP 311 for details. > > http://www.python.org/dev/peps/pep-0311/ > > I also suggest that if you want people to be more receptive to write > your replies after the quoted text. ?That is the custom in this > newsgroup/mailing list. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > thanks for the tip. What I meant was that I am *not allowed* to make calls to the CPython API from the threads I currently have because these threads are high priority and are never allowed to make blocking calls. Fortunately, each of these threads can have a completely separate interpreter, so my idea was to create a daemon process for each thread. This daemon would contain the libpython symbols and would make the CPython calls. This would keep my current threads from having to contend over the single GIL. My question was whether or not anyone has done anything like this in C/C++. This situation is slightly unique in that I am trying to maintain separate interpreters within a single app (which is currently kind of hacked out using a single interpreter, but it's ugly), but I could see how this sort of thing would be useful for other C/C++ apps that implement an embedded scripting engine. My reference to multiprocessing was based on the idea that the library hides the details fo the process management, shared memory, and rpc mechanisms. Again, I can't use multiprocessing because it runs *in* python I need this to be implemented *outside* of python to avoid acquiring the GIL. complex, I know. Naturally, the most intimidating part of perusing this kind of idea is the overhead of the processess management and the RPC. Further, libpython executes callable objects using C function pointers, and I can't think of a way that this would be able to re-gain access to the original app's respective functions if the interpreter was living in another processes. That's not to mention the impossibility of debugging. Damn you, Gil. From alfps at start.no Mon Nov 23 16:06:29 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 23 Nov 2009 22:06:29 +0100 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... Message-ID: This is the tragic story of this evening: 1. Aspirins to lessen the pain somewhat. 2. Over in [comp.programming] someone mentions paper on Quicksort. 3. I recall that X once sent me link to paper about how to foil Quicksort, written by was it Doug McIlroy, anyway some Bell Labs guy. Want to post that link in response to [comp.programming] article. 4. Checking in Thunderbird, no mails from X or about QS there. 5. But his mail address in address list so something funny going on! 6. Googling, yes, it seems Thunderbird has a habit of "forgetting" mails. But they're really there after all. It's just the index that's screwed up. 7. OK, opening Thunderbird mailbox file (it's just text) in nearest editor. 8. Machine hangs, Windows says it must increase virtual memory, blah blah. 9. Making little Python script to extract individual mails from file. 10. It says UnicodeDecodeError on mail nr. something something. 11. I switch mode to binary. Didn't know if that would work with std input. 12. It's now apparently ten times faster but *still* UnicodeDecodeError! 13. I ask here! Of course could have googled that paper, but at each step above it seemed just a half minute more to find the link in mails, and now I decided it must be found. And I'm hesitant to just delete index file, hoping that it'll rebuild. Thunderbird does funny things, so best would be if Python script worked. import os import fileinput def write( s ): print( s, end = "" ) msg_id = 0 f = open( "nul", "w" ) for line in fileinput.input( mode = "rb" ): if line.startswith( "From - " ): msg_id += 1; f.close() print( msg_id ) f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) else: f.write( line ) f.close() 955 956 957 958 Traceback (most recent call last): File "C:\test\tbfix\splitmails.py", line 11, in for line in fileinput.input( mode = "rb" ): File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, in __next__ line = self.readline() File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, in readline self._buffer = self._file.readlines(self._bufsize) File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 2188: character maps to Cheers, - Alf From deets at nospam.web.de Mon Nov 23 16:11:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 22:11:47 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <7n0c4jF3jsi7lU1@mid.uni-berlin.de> Patrick Stinson schrieb: > On Mon, Nov 23, 2009 at 1:01 AM, Carl Banks wrote: >> On Nov 22, 10:58 pm, Patrick Stinson >> wrote: >>> On Sun, Nov 22, 2009 at 3:15 PM, Diez B. Roggisch wrote: >> icating) the multiprocessing module would be ideal. >>>> The problem is that the OP has a embedded application running threads. >>>> multiprocssing doesn't help there. >>> that's right. I cannot make CPython calls from my original C-based threads. >> >> It's quite possible to do that. A thread started from C can make >> calls to Python if it first calls PyGILState_Ensure, although you'd >> have to make sure that the Python interpreter has been previously >> initialized. See PEP 311 for details. >> >> http://www.python.org/dev/peps/pep-0311/ >> >> I also suggest that if you want people to be more receptive to write >> your replies after the quoted text. That is the custom in this >> newsgroup/mailing list. >> >> >> Carl Banks >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > thanks for the tip. > > What I meant was that I am *not allowed* to make calls to the CPython > API from the threads I currently have because these threads are high > priority and are never allowed to make blocking calls. Fortunately, > each of these threads can have a completely separate interpreter, so > my idea was to create a daemon process for each thread. This daemon > would contain the libpython symbols and would make the CPython calls. > This would keep my current threads from having to contend over the > single GIL. > > My question was whether or not anyone has done anything like this in > C/C++. This situation is slightly unique in that I am trying to > maintain separate interpreters within a single app (which is currently > kind of hacked out using a single interpreter, but it's ugly), but I > could see how this sort of thing would be useful for other C/C++ apps > that implement an embedded scripting engine. AFAIK, instantiating several interpreters is possible. There seem to be problems with extension modules, but maybe you don't need them, or can work around that problem. http://mail.python.org/pipermail/python-dev/2006-December/070370.html Diez From redplusbluemakespurple at gmail.com Mon Nov 23 16:15:07 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Mon, 23 Nov 2009 13:15:07 -0800 (PST) Subject: Converting a float to a formatted outside of print command Message-ID: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> I'd like to convert a list of floats to formatted strings. The following example raises a TypeError: y = 0.5 x = '.1f' % y From danb_83 at yahoo.com Mon Nov 23 16:17:42 2009 From: danb_83 at yahoo.com (Dan Bishop) Date: Mon, 23 Nov 2009 13:17:42 -0800 (PST) Subject: Converting a float to a formatted outside of print command References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: On Nov 23, 3:15?pm, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y You meant: x = '%.1f' % y From iurisilvio at gmail.com Mon Nov 23 16:24:18 2009 From: iurisilvio at gmail.com (Iuri) Date: Mon, 23 Nov 2009 19:24:18 -0200 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <789aac5a0911231324t4ee11387pc957232ec87ecf43@mail.gmail.com> You forgot a % simbol in your string: y = 0.5 x = '*%*.1f' % y []s iurisilvio On Mon, Nov 23, 2009 at 7:15 PM, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Nov 23 16:25:51 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 23 Nov 2009 16:25:51 -0500 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <5D06A473-6815-4653-9188-C1428762DCE1@semanchuk.com> On Nov 23, 2009, at 4:15 PM, stephen_b wrote: > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y You're missing a percent sign: x = '%.1f' % y or: print '%.1f' % 0.5 Hope this helps Philip From redplusbluemakespurple at gmail.com Mon Nov 23 16:27:45 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Mon, 23 Nov 2009 13:27:45 -0800 (PST) Subject: Converting a float to a formatted outside of print command References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <978da1a2-2e49-4e03-b7f4-f26f5fbc7f0b@p28g2000vbi.googlegroups.com> On Nov 23, 3:17?pm, Dan Bishop wrote: > You meant: > > x = '%.1f' % y Thanks, I'm a dufus today. From vlastimil.brom at gmail.com Mon Nov 23 16:28:53 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 23 Nov 2009 22:28:53 +0100 Subject: Converting a float to a formatted outside of print command In-Reply-To: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> References: <8b6b5b58-5328-45ad-bcc3-d3408f8a5f35@g1g2000vbr.googlegroups.com> Message-ID: <9fdb569a0911231328h4e896b69g2bc34c3eaec63f57@mail.gmail.com> 2009/11/23 stephen_b : > I'd like to convert a list of floats to formatted strings. The > following example raises a TypeError: > > y = 0.5 > x = '.1f' % y > -- > http://mail.python.org/mailman/listinfo/python-list Maybe '%.1f' % y ? hth vbr From robert.kern at gmail.com Mon Nov 23 16:30:16 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 23 Nov 2009 15:30:16 -0600 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: On 2009-11-23 14:47 PM, Antoine Pitrou wrote: > Le Mon, 23 Nov 2009 11:54:19 -0600, Robert Kern a ?crit : >> >> Not really. The idea was to make the language easily parsed and lexed >> and analyzed by *other* tools, not written in Go, that may have limited >> capabilities. > > Well, if Go doesn't allow you to write libraries usable from other low- > level languages I'm not sure it is a good systems programming language. > One point of C is that you can bridge it with everything. That doesn't help tools that are already built with their own capabilities. I don't link Python into my editor to get Python syntax highlighting. The easier it is to write *a* parser/analyzer for the language in any other programming language, the more tools you will get for a broader range of runtime environments, particularly constrained environments like editors that may not be extensible at all. >> Vim isn't written in Go and won't be able to use their >> API, for example. > > Syntax highlighting doesn't require a full-blown parser. Most of the time. FORTRAN does require a full-blown parser if you want to be accurate. And the more regular a language is, the more interesting things one can do with just the tools that are usually available for syntax highlighting. FORTRAN and Go represent two opposite sides of that spectrum. > You probably > want to handle three types of events: > - comments (and docstrings and the like for languages which have them) > - keywords > - delimiters of basic syntactical blocks (which most of the time is > simply matching pairs of parens / square brackets / curly brackets) > > That is, you need a very small part of the information a complete parser > would give you. > In particular, you don't need to know about operator precedence. You > don't need to know about what kind of block you are inside (function, > method, class...). You don't need to know whether an identifier is a > local variable, a global variable, a type, etc. You don't even need to > know the different operators. You only need to recognize the basic > lexemes and that's all. You can get away with just that and have something people recognize as syntax highlighting, yes. But if it is possible to highlight local variables, globals, and types differently, that *is* useful. And you will even see some syntax highlighters doing more advanced things like that even for Python (though mostly with heuristics). But note that the more regular the language is, the less you need to rely on a full parser, and the more interesting things you can do with just lexing and other simpler approaches. That's what they are going for. If I were designing a language, that wouldn't be the tradeoff I would make, but they have their own needs. -- 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 darcy at druid.net Mon Nov 23 16:31:03 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 23 Nov 2009 16:31:03 -0500 Subject: Line Breaks In-Reply-To: References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: <20091123163103.b8d83c24.darcy@druid.net> On Mon, 23 Nov 2009 14:46:23 -0500 Susan Day wrote: > First, it does in fact ignore all line breaks, not just double line breaks. > Here's what I'm doing: > session.sendmail(clientEmail, ourEmail2, header+msg) > The email sent out has the message sans breaks. You should really post an entire script that runs and shows the error so that we can run it (changing the email address of course) to see what it does. -- 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 tjreedy at udel.edu Mon Nov 23 16:35:43 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 16:35:43 -0500 Subject: Beginning Question about Python functions, parameters... In-Reply-To: References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: astral orange wrote: > Yes, lines 104-111 is really where my problem lies in understanding > what is going on here. > I am beginner so this stuff seems a little unwieldy at the moment. :) > I *did* invest $40 Water under the bridge. Focus on the future... > into this book so it' what I have to work with. By the way, the book > is, "Apress Beginning Python 2nd Edition".... The online tutorial is free. Read it along with the book. Two explanations of a particular point are often better than one, at least for me. Now, to where you seem to be stuck. Data is a dict of 3 dicts, one for each part of a full [Western] name. Each subdict maps pieces of fullnames to a list of fullnames that contain that piece in the appropriate position. This is something like a database of names with 3 fields and an index for each field pointing to records in the database, except that there is no database. This is why the structure strikes people as a bit strange. The records are still there, off in anonymous dataspace, but there is no way to access them except via the indexes. If init started with data['names'] = [] # empty list, not dict and the third line of store were data['names'].append(names) then there would be. You might try that as an exercise once you understand what is already there. Anyway, you should "print MyNames" (2.x) or "print(MyNames)" (3.x) after storing the first name so you can see the structure of MyNames. The tutorial, of course, tells you this. DO read it. Then add more data and print again to see what changes. For instance, store(MyNames, 'Susan Smith') print(MyNames) Then try several lookups. store() checks each of the pieces of a name to see whether or not it is already in the corresponding key dict. This is the "people =" line. The important point in lookup is that when dict d does not contain key k, d.get(k) returns None while the usual d[k]raises a KeyError. So lookup() always return something, even if just None. So 'people' is either None or an exiting list of names. In the latter case, the current full names is added to the list. In the former case, the name-piece is associated with a new list with one item. If this is still not clear, add print statements or print function statements at appropriate places inside the code for the store function. This is how many people clarify thier understanding of a function, including when debugging. Good luck. Terry Jan Reedy From marcmagransdeabril at gmail.com Mon Nov 23 16:42:09 2009 From: marcmagransdeabril at gmail.com (marc magrans de abril) Date: Mon, 23 Nov 2009 13:42:09 -0800 (PST) Subject: profiling differences using an extra function call Message-ID: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> Hi, I was a trying to profile a small script and after shrinking the code to the minimum I got a interesting profile difference. Given two test functions test1 and test2, that only differs from an extra level of indirection (i.e. find_substr), I wonder why I got a timming difference >50%? What is the recommended way to factorize the code? Should I write a big method containing everything? #!/usr/bin/python def find_substr(l): return l[15:20] def test1(t): for i in xrange(1000000): s = find_substr(t) def test2(t): for i in xrange(1000000): sub = t[15:20] import cProfile t = "This a long string containing several things apart from the end" cProfile.run("test1(t)") cProfile.run("test2(t)") ----Profiles test1 Profiles results: 1000003 function calls in 0.666 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno (function) 1 0.000 0.000 0.666 0.666 :1() 1000000 0.260 0.000 0.260 0.000 test.py:3(find_substr) 1 0.406 0.406 0.666 0.666 test.py:7(test1) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} ----Profile test2: 3 function calls in 0.248 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno (function) 1 0.000 0.000 0.248 0.248 :1() 1 0.248 0.248 0.248 0.248 test.py:12(test2) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} Thank you very much for the advice! marc From james.b.looney at ulalaunch.com Mon Nov 23 16:53:45 2009 From: james.b.looney at ulalaunch.com (James Looney) Date: Mon, 23 Nov 2009 13:53:45 -0800 (PST) Subject: Compiling Python 2.6.4 on IRIX 6.5 - "don't know how to make Parser/printgrammar.o (bu42)." Message-ID: I'm trying to compile Python 2.6.4 on my IRIX 6.5 machine. I have no idea how to fix this problem, and am hoping someone may know what to do. The closest thread I've found to this is http://bugs.python.org/issue4279, but that patch has already been added, yet I still get the error. The post makes reference to trying gmake, but I don't have that installed on this machine. I'm stuck with regular make. configure line: ../../configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/IRIX6 --enable-shared --with- threads --without-gcc --with-cxx-main=/usr/bin/CC make history: [14:50:54]> make /usr/bin/CC -c -OPT:Olimit=0 -DNDEBUG -O -I. -IInclude - I../../Include -DPy_BUILD_CORE -o Modules/python.o ../../Modules/ python.c don't know how to make Parser/printgrammar.o (bu42). From james.b.looney at ulalaunch.com Mon Nov 23 16:55:03 2009 From: james.b.looney at ulalaunch.com (James Looney) Date: Mon, 23 Nov 2009 13:55:03 -0800 (PST) Subject: Compiling Python 2.6.4 on IRIX 6.5 - "don't know how to make Parser/printgrammar.o (bu42)." Message-ID: <87f4f043-2f8b-4268-9cb4-edb10b08f150@x16g2000vbk.googlegroups.com> I'm trying to compile Python 2.6.4 on my IRIX 6.5 machine. I have no idea how to fix this problem, and am hoping someone may know what to do. The closest thread I've found to this is http://bugs.python.org/issue4279, but that patch has already been added, yet I still get the error. The post makes reference to trying gmake, but I don't have that installed on this machine. I'm stuck with regular make. configure line: ../../configure --prefix=/usr/local/openSource/architectureIndependent --exec-prefix=/usr/local/openSource/IRIX6 --enable-shared --with- threads --without-gcc --with-cxx-main=/usr/bin/CC make history: [14:50:54]> make /usr/bin/CC -c -OPT:Olimit=0 -DNDEBUG -O -I. -IInclude - I../../Include -DPy_BUILD_CORE -o Modules/python.o ../../Modules/ python.c don't know how to make Parser/printgrammar.o (bu42). From andyjian430074 at gmail.com Mon Nov 23 16:57:23 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 13:57:23 -0800 (PST) Subject: sys.stdout is not flushed Message-ID: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> I am trying to use sys.stdout to print out "process-bar" like: -->1% Here is my program ?test.py?: from sys import stdout for v in range(10): stdout.write('-->%d' % v) stdout.flush() else: stdout.write('done!') #end for Then, I use 'python -u test.py' to run this script. But what I get is : -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! I am suppose to get 'done!'. Can anybody help me about this? Thanks. Jankins From jaraco at jaraco.com Mon Nov 23 16:59:33 2009 From: jaraco at jaraco.com (Jason R. Coombs) Date: Mon, 23 Nov 2009 13:59:33 -0800 (PST) Subject: Relative versus absolute paths on Windows References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> Message-ID: <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> On Nov 20, 3:52?pm, Ethan Furman wrote: > It is often said on this list that 'Python is not Java'. ?It is also > true that 'Windows is not Unix'. > > Unlike the *nix world where there is a *single* root, and everything > else is relative to that, in the Windows world there are several roots > -- every drive has one! I acknowledge that the Windows paradigm is messy and less elegant than Unix. I'm not trying to place blame here. I pointed out that even the Windows interfaces don't seem to provide the functions needed to do what I want to do. However, my point is that there is a need for path resolution that respects a rooted path as relative to another path. > So \bar is both an absolute path on whichever drive is active (or > specified), as well as relative if you happen to have more than one > drive, but it will not ever be relative on any specific drive. ?If you > want 'bar' to be relative to the current directory, do not specify a > leading '\'. Precisely. And my point is that if the path "specified" has a drive (d: \foo) and one wants "\bar" relative to d:\foo, the result should be d: \bar, not \bar, which is relative to the current drive. I elaborate below. > > Ultimately, I don't care what the definition is. It seems to me, > > however, that Python should have a function that can resolve one path > > name relative to another, but due to these limitations, it does not. I > > should point out that os.path.relpath is not the solution either as > > the first parameter is always treated as relative to the current > > directory (more info athttp://bugs.python.org/issue7195). > > Please note that there *is not* a relative path that can take you from > c:\foo to d:\bar ?(see the point about multiple roots above). I'm not looking for a relative path from c:\foo to d:\bar. I know the "shortest relative path" from c:\foo to d:\bar is the absolute path d: \bar. What I am looking for is a way to resolve one path relative to another irrespective of the current directory. Here's the use case: A symlink or shortcut (they can both be treated for symbolic links for the sake of this discussion) is defined in a particular location, let's say d:\foo. This symlink points to "\bar". On Windows, the target of the symlink is treated as relative to the location of the symlink itself, not the current directory when accessed. In other words, \bar relative to d:\foo always resolves to d: \bar. To effectively track down the target of a symbolic link, it becomes necessary to perform this resolution. > > What is the benefit of treating \path as absolute? > > That was not Python's decision, but Windows'. Maybe so. My feeling is there's a good reason for it, based on the multiple implementations that follow the same approach. Nevertheless, that doesn't change the fact that despite the APIs, Windows does internally resolve symlinks relative to the symlink location. > > Should Python have built-in support for resolving one path relative to > > another (such as is jaraco.windows.filesystem.resolve_path does)? > > As I noted above, you are not returning a relative path when the paths > cross drive letter boundaries, or one of the paths specified is a > drive-absolute path (such as '\bar'). To be clear, I'm not trying to find a relative path between two paths. I'm trying to resolve one path relative to another. On Unix, os.path.join does this. On Windows, there is no such function (except jaraco.windows.filesystem.join). > Hope this helps. Thanks for taking the time to write a detailed response. I think I understand the problem. What is frustrating is that the current behavior seems buggy (others words, not mine) and a function that does what many would expect isn't available. > P.S. > And now that I look up the comments in the bug-tracker, I see this was > all already pointed out to you. Based on the name and specification, I expected something different from relpath, but after the discussion, I decided it wasn't the tool I was seeking. From deets at nospam.web.de Mon Nov 23 17:04:06 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 23:04:06 +0100 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine In-Reply-To: <4b0ad983$0$13161$a729d347@news.telepac.pt> References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> <4b0ad983$0$13161$a729d347@news.telepac.pt> Message-ID: <7n0f6qF3hgohqU1@mid.uni-berlin.de> S?rgio Monteiro Basto schrieb: > Diez B. Roggisch wrote: > > Hi, Thanks, >> S?rgio Monteiro Basto wrote: >> >>> Hi, >>> I am in x86_64 arch , but I need >>> compile things on 32 bits with >>> python setup.py build >>> >>> Can't change the fact that distutils creates x86_64 >>> directories: >>> build/temp.linux-x86_64-2.3/ >>> >>> Also if I try with a python compile in 32bits and installed >>> in system . >> I doubt that. Distutils will always build based on the architecture of the >> interpreter you used when building an external module. >> >> Are you sure that the python you used to build the extension was the right >> one? What does >> >> -c "from distutils.util import get_platform; print >> get_platform()" > python32 -c "from distutils.util import get_platform; print get_platform()" > linux-x86_64 > > ldd ~/bin/python32 > linux-gate.so.1 => (0xffffe000) > libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) > libdl.so.2 => /lib/libdl.so.2 (0x0033f000) > libutil.so.1 => /lib/libutil.so.1 (0x006b3000) > libm.so.6 => /lib/libm.so.6 (0x00345000) > libc.so.6 => /lib/libc.so.6 (0x001e0000) > /lib/ld-linux.so.2 (0x001c2000) > > this a python 2.3, that's make any difference ? Ok, next try: import distutils print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') What does that yield? Diez Diez From martin at v.loewis.de Mon Nov 23 17:07:28 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 23 Nov 2009 23:07:28 +0100 Subject: xmlrpc idea for getting around the GIL In-Reply-To: References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <7mtrf5F3h153dU1@mid.uni-berlin.de> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> Message-ID: <4b0b07a1$0$22159$9b622d9e@news.freenet.de> > What I meant was that I am *not allowed* to make calls to the CPython > API from the threads I currently have because these threads are high > priority and are never allowed to make blocking calls. Fortunately, > each of these threads can have a completely separate interpreter, so > my idea was to create a daemon process for each thread. This daemon > would contain the libpython symbols and would make the CPython calls. > This would keep my current threads from having to contend over the > single GIL. If this ("never allowed to make blocking calls") is a strict requirement, then this is no solution, either. Communicating to the remote process would involve IO, and all IO operations may block. Of course, you might use non-blocking IO, in which case I wonder how the thread continues if it finds that the IO is blocking. I also wonder how the thread will find out that the result of the computation is available, when it is not allowed to wait for the result. In any case, I don't think you'll need a multi-process solution; a single-process multi-threading approach will do fine. Just create *another* thread, that runs at a low priority and is allowed to block. Run the Python interpreter in that thread (create multiple of these if you need them). Then, use some queuing producer-consumer communication between the high-priority thread and the low priority thread. Have the high priority threads put requests into the queue, and the low priority thread take them from the queue, dispatching them to Python. Make sure you use non-blocking synchronization on the queue, or else priority inheritance if you can get permission to do so. > Damn you, Gil. It may sound to you like the GIL is responsible for that. However, consider a world where the GIL was removed in Python. There would *still* be synchronization for data structures be going on. As you are not allowed to have any blocking operation in the high-priority threads, you *still* couldn't directly call the Python interpreter (or any other thread-safe library) from your high-priority threads. Regards, Martin From deets at nospam.web.de Mon Nov 23 17:08:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 23 Nov 2009 23:08:25 +0100 Subject: sys.stdout is not flushed In-Reply-To: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> Message-ID: <7n0fepF3hgohqU2@mid.uni-berlin.de> Jankins schrieb: > I am trying to use sys.stdout to print out "process-bar" like: > -->1% > > Here is my program ?test.py?: > > from sys import stdout > for v in range(10): > stdout.write('-->%d' % v) > stdout.flush() > else: > stdout.write('done!') > #end for > > Then, I use 'python -u test.py' to run this script. But what I get > is : > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > I am suppose to get 'done!'. > > Can anybody help me about this? You misunderstand what "flush" means. It is not about clearing the screen, or the line. Try printing stdout.write('\r-->%d') Diez From alfps at start.no Mon Nov 23 17:37:58 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 23 Nov 2009 23:37:58 +0100 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... In-Reply-To: References: Message-ID: * Alf P. Steinbach: > > > import os > import fileinput > > def write( s ): print( s, end = "" ) > > msg_id = 0 > f = open( "nul", "w" ) > for line in fileinput.input( mode = "rb" ): > if line.startswith( "From - " ): > msg_id += 1; > f.close() > print( msg_id ) > f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) > else: > f.write( line ) > f.close() > > > > > 955 > 956 > 957 > 958 > Traceback (most recent call last): > File "C:\test\tbfix\splitmails.py", line 11, in > for line in fileinput.input( mode = "rb" ): > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, > in __next__ > line = self.readline() > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, > in readline > self._buffer = self._file.readlines(self._bufsize) > File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line > 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position > 2188: character maps to The following worked: import sys import fileinput def write( s ): print( s, end = "" ) msg_id = 0 f = open( "nul", "w" ) input = sys.stdin.detach() # binary while True: line = input.readline() if len( line ) == 0: break elif line.decode( "ascii", "ignore" ).startswith( "From - " ): msg_id += 1; f.close() print( msg_id ) f = open( "msg_{0:0>6}.txt".format( msg_id ), "wb+" ) else: f.write( line ) f.close() Cheers, - Alf From andyjian430074 at gmail.com Mon Nov 23 17:59:39 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 14:59:39 -0800 (PST) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> Message-ID: <24aa394f-62da-4f3a-bb3b-d646d9df48e7@e31g2000vbm.googlegroups.com> On Nov 23, 4:08?pm, "Diez B. Roggisch" wrote: > Jankins schrieb: > > > > > > > I am trying to use sys.stdout to print out "process-bar" like: > > -->1% > > > Here is my program ?test.py?: > > > from sys import stdout > > for v in range(10): > > ? ? stdout.write('-->%d' % v) > > ? ? stdout.flush() > > else: > > ? ? stdout.write('done!') > > #end for > > > Then, I use 'python -u test.py' to run this script. But what I get > > is : > > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > > I am suppose to get 'done!'. > > > Can anybody help me about this? > > You misunderstand what "flush" means. It is not about clearing the > screen, or the line. > > Try printing > > ? ?stdout.write('\r-->%d') > > Diez It works. I did misunderstood the meaning the 'flush'. Thanks so much. From 457r0.jp at gmail.com Mon Nov 23 18:13:28 2009 From: 457r0.jp at gmail.com (astral orange) Date: Mon, 23 Nov 2009 15:13:28 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> Message-ID: <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> On Nov 23, 4:35?pm, Terry Reedy wrote: > astral orange wrote: > > Yes, lines 104-111 is really where my problem lies in understanding > > what is going on here. > > I am beginner so this stuff seems a little unwieldy at the moment. :) > > I *did* invest $40 > > Water under the bridge. Focus on the future... > > > into this book so it' what I have to work with. By the way, the book > > is, "Apress Beginning Python 2nd Edition".... > > The online tutorial is free. Read it along with the book. Two > explanations of a particular point are often better than one, at least > for me. > > Now, to where you seem to be stuck. Data is a dict of 3 dicts, one for > each part of a full [Western] name. Each subdict maps pieces of > fullnames to a list of fullnames that contain that piece in the > appropriate position. > > This is something like a database of names with 3 fields and an index > for each field pointing to records in the database, except that there is > no database. This is why the structure strikes people as a bit strange. > The records are still there, off in anonymous dataspace, but there is no > way to access them except via the indexes. If init started with > ? ? ?data['names'] = [] # empty list, not dict > and the third line of store were > ? ? ?data['names'].append(names) > then there would be. You might try that as an exercise once you > understand what is already there. > > Anyway, you should "print MyNames" (2.x) or "print(MyNames)" (3.x) after > storing the first name so you can see the structure of MyNames. The > tutorial, of course, tells you this. DO read it. > > Then add more data and print again to see what changes. For instance, > > store(MyNames, 'Susan Smith') > print(MyNames) > > Then try several lookups. > > store() checks each of the pieces of a name to see whether or not it is > already in the corresponding key dict. This is the "people =" line. The > important point in lookup is that when dict d does not contain key k, > d.get(k) returns None while the usual d[k]raises a KeyError. So lookup() > always return something, even if just None. So 'people' is either None > or an exiting list of names. In the latter case, the current full names > is added to the list. In the former case, the name-piece is associated > with a new list with one item. > > If this is still not clear, add print statements or print function > statements at appropriate places inside the code for the store function. > This is how many people clarify thier understanding of a function, > including when debugging. > > Good luck. > > Terry Jan Reedy Wow! First, thanks Terry for the detailed explanation. I'll spend the rest of the night trying to figure all of this out. :) Also, thanks to everyone else that responded as well. I do appreciate you all volunteering your time to help. I should of came here sooner. As far as the program. I did add print statements such as print (MyNames) and got back: {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} 'Smith': ['John Larry Smith'] was in the last key so I will spend some time figuring out just why that is the case. I'll spend more time working with the functions and hopefully figure this out soon. Thanks again! Thanks again for the responses. I'll take all your advice. From ethan at stoneleaf.us Mon Nov 23 18:37:10 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 15:37:10 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <024aba36-9df7-425e-a0f8-806e6c015482@o13g2000vbl.googlegroups.com> Message-ID: <4B0B1CA6.3010508@stoneleaf.us> Jason R. Coombs wrote: > On Nov 20, 3:52 pm, Ethan Furman wrote: > >>It is often said on this list that 'Python is not Java'. It is also >>true that 'Windows is not Unix'. >> >>Unlike the *nix world where there is a *single* root, and everything >>else is relative to that, in the Windows world there are several roots >>-- every drive has one! > > > I acknowledge that the Windows paradigm is messy and less elegant than > Unix. I'm not trying to place blame here. I pointed out that even the > Windows interfaces don't seem to provide the functions needed to do > what I want to do. However, my point is that there is a need for path > resolution that respects a rooted path as relative to another path. I think for this discussion you would be better off using the word 'combine' rather than 'relative'. >>So \bar is both an absolute path on whichever drive is active (or >>specified), as well as relative if you happen to have more than one >>drive, but it will not ever be relative on any specific drive. If you >>want 'bar' to be relative to the current directory, do not specify a >>leading '\'. > > > Precisely. And my point is that if the path "specified" has a drive (d: > \foo) and one wants "\bar" relative to d:\foo, the result should be d: > \bar, not \bar, which is relative to the current drive. s/relative/combined with/ > I elaborate below. > > >>>Ultimately, I don't care what the definition is. It seems to me, >>>however, that Python should have a function that can resolve one path >>>name relative to another, but due to these limitations, it does not. I >>>should point out that os.path.relpath is not the solution either as >>>the first parameter is always treated as relative to the current >>>directory (more info athttp://bugs.python.org/issue7195). >> >>Please note that there *is not* a relative path that can take you from >>c:\foo to d:\bar (see the point about multiple roots above). > > > I'm not looking for a relative path from c:\foo to d:\bar. I know the > "shortest relative path" from c:\foo to d:\bar is the absolute path d: > \bar. What I am looking for is a way to resolve one path relative to > another irrespective of the current directory. > > Here's the use case: A symlink or shortcut (they can both be treated > for symbolic links for the sake of this discussion) is defined in a > particular location, let's say d:\foo. This symlink points to "\bar". > > On Windows, the target of the symlink is treated as relative to the > location of the symlink itself, not the current directory when > accessed. In other words, \bar relative to d:\foo always resolves to d: > \bar. To effectively track down the target of a symbolic link, it > becomes necessary to perform this resolution. > > >>>What is the benefit of treating \path as absolute? >> >>That was not Python's decision, but Windows'. > > > Maybe so. My feeling is there's a good reason for it, based on the > multiple implementations that follow the same approach. Nevertheless, > that doesn't change the fact that despite the APIs, Windows does > internally resolve symlinks relative to the symlink location. The multiple implementations exist because that's the way is has always been on the Microsoft side. You have to play by their rules if you are going to use their OS. >>>Should Python have built-in support for resolving one path relative to >>>another (such as is jaraco.windows.filesystem.resolve_path does)? >> >>As I noted above, you are not returning a relative path when the paths >>cross drive letter boundaries, or one of the paths specified is a >>drive-absolute path (such as '\bar'). > > > To be clear, I'm not trying to find a relative path between two paths. > I'm trying to resolve one path relative to another. On Unix, > os.path.join does this. On Windows, there is no such function (except > jaraco.windows.filesystem.join). > > >>Hope this helps. > > > Thanks for taking the time to write a detailed response. I think I > understand the problem. What is frustrating is that the current > behavior seems buggy (others words, not mine) and a function that does > what many would expect isn't available. > > >>P.S. >>And now that I look up the comments in the bug-tracker, I see this was >>all already pointed out to you. > > > Based on the name and specification, I expected something different > from relpath, but after the discussion, I decided it wasn't the tool I > was seeking. relpath is definitely not the tool you are looking for. I do agree with you that a function to combine two paths would be very handy... of course, since relpath does work if the current drive is the one specified (I think, haven't tested that statement), a wrapper function that saved the current path, then switched drives, did the relpath lookup, then switched back... hmmmm -- that would be a pain if the drive didn't exist on the system doing the work... oh well. Yup, if your function works, keep it! :D ~Ethan~ From rhodri at wildebst.demon.co.uk Mon Nov 23 18:37:18 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 23 Nov 2009 23:37:18 -0000 Subject: IDE+hg In-Reply-To: References: Message-ID: On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ wrote: > Dear experts, > Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim > Mercurial support not found i.e. buttons to clone, commit and push to > repositories to define dev env dvcs, editor and deployment all in 1. I don't really understand this urge to cram everything into a single program, since that inevitably leads to compromises that will compromise just how much of Mercurial's useful and interesting functionality you can get at. Still, if you really must, Emacs (and presumably vim) seems to be capable of working with most source control systems. -- Rhodri James *-* Wildebeest Herder to the Masses From greg.ewing at canterbury.ac.nz Mon Nov 23 18:40:17 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 24 Nov 2009 12:40:17 +1300 Subject: Go versus Brand X In-Reply-To: References: <3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com> <7ms7ctF3k2a79U1@mid.individual.net> Message-ID: <7n0krhF3k0kc4U1@mid.individual.net> Robert Kern wrote: > The easier it is to write *a* parser/analyzer for the > language in any other programming language, the more tools you will get > for a broader range of runtime environments, particularly constrained > environments like editors that may not be extensible at all. Seems to me that having a bit more punctuation in the language would make it easier for things like editors that don't have sophisticated parsing abilities to do a better job of syntax highlighting. -- Greg From tjreedy at udel.edu Mon Nov 23 18:40:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 18:40:33 -0500 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <7n0578F3j7qa6U1@mid.individual.net> References: <7n0578F3j7qa6U1@mid.individual.net> Message-ID: Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generally avoided it, so I just nodded. > > Unfortunately, the new "nested" with statement (which I also read > about today) forces me into this anti-idiom. When replacing an > appearance of contextlib.nested with the 3K with statement, I > ended up with an unexpected syntax error. > > with (open(roster_path, 'r') as roster_file, > open(disb_path, 'w') as out_file, > open(report_path, 'w') as report_file): > > The result was: > > File "C:\project\codxml.py", line 184 > with (open(roster_path, 'r') as roster_file, > ^ > SyntaxError: invalid syntax Right. The first open paren is illegal. > Unless I'm missing something, I have to subject my code to a bit > of contintuation: > > with open(roster_path, 'r') as roster_file,\ > open(disb_path, 'w') as out_file,\ > open(report_path, 'w') as report_file: with open(roster_path, 'r') as roster_file, open( disb_path, 'w') as out_file, open(report_path, 'w') as report_file: would work ;-) > I was thinking about submitting a enhancement request to the > HOWTO, explaining that continuation my be required in this > context. Am I missing anything obvious? I would suggest replacing "It is usually much better to use the implicit continuation inside parenthesis:", which says both too much and too little, with something like "When the desired linebreak is within an expression, it is usually much better to use implicit continuation inside parentheses, brackets, or braces. If necessary, the whole expression can be surrounded by a new pair of parentheses." I would not mention 'with' specifically since there are many other non-expression contexts where one cannot randomly add parentheses. I believe that '\ \n' would always be harmless or a SyntexError outside of expressons. I believe 'subtly wrong' only applies within expressions. So I would not call \ continuation an anti-pattern outside expressions. So you might suggest that the whole entry specify expression context to begin with. To me, your example shows why blanket condemnation is wrong. You might separately request that with-item sequences be optionally surrounded by parens, but I have a suspicion that this was considered and rejected on either technical grounds and/or the grounds that \ continuation was purposefully left in the language in 3.x to be used when implicit continuation is not appropriate, as in this situation. The HOWTOs are not scripture. Terry Jan Reedy From paul.w.miller.please.dont.spam.me at wmich.edu Mon Nov 23 19:05:33 2009 From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller) Date: Tue, 24 Nov 2009 00:05:33 +0000 (UTC) Subject: Any elegant way to construct the complete $k$-partite graph in Python? Message-ID: I was wondering if there were any neat tools (like for instance, something from itertools) that would help me write the following function more elegantly. The return value should, of course, be the complete $k$- partite graph $K_{n_1, n_2, \dots, n_k}$: def completeGraph (*ns): ''' Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed the sequence \code {n_1, n_2, \dots, n_k}. ''' if len (ns) == 1: return completeGraph ( * ([1] * ns[0]) ) n = sum (ns) vertices = range (n) partition_indices = [sum (ns[:i]) for i in range (len (ns))] partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] \ for i in range (len (partition_indices) - 1)] partite_sets.append (vertices[partition_indices [-1]:] ) edges = [] for i in range (len (partite_sets)): for j in range (i + 1, len (partite_sets)): edges.extend ([ (u, v) for u in partite_sets [i] for v in \ partite_sets [j] ]) return graph.Graph (vertices = vertices, edges = edges) Many thanks! From anand.ibmgsi at gmail.com Mon Nov 23 19:25:46 2009 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 24 Nov 2009 05:55:46 +0530 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: <1a3a139e0911231625m6defb19nbccd097c8dc98808@mail.gmail.com> I am not sure what you mean by complete $k$- partite graph.... There is the python-graph package(http://code.google.com/p/python-graph/) you might wanna check out. It does return a complete graph.. may be u can tweak it?? ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with no accounting policies. ~Aang Jie On Tue, Nov 24, 2009 at 05:35, Paul Miller < paul.w.miller.please.dont.spam.me at wmich.edu> wrote: > I was wondering if there were any neat tools (like for instance, > something from itertools) that would help me write the following function > more elegantly. The return value should, of course, be the complete $k$- > partite graph $K_{n_1, n_2, \dots, n_k}$: > > def completeGraph (*ns): > ''' > Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > the sequence \code {n_1, n_2, \dots, n_k}. > ''' > if len (ns) == 1: > return completeGraph ( * ([1] * ns[0]) ) > n = sum (ns) > vertices = range (n) > partition_indices = [sum (ns[:i]) for i in range (len (ns))] > partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > \ > for i in range (len (partition_indices) - 1)] > partite_sets.append (vertices[partition_indices [-1]:] ) > > edges = [] > for i in range (len (partite_sets)): > for j in range (i + 1, len (partite_sets)): > edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > partite_sets [j] ]) > > return graph.Graph (vertices = vertices, edges = edges) > > Many thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rt8396 at gmail.com Mon Nov 23 19:48:48 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 16:48:48 -0800 (PST) Subject: Python & OpenOffice Spreadsheets References: Message-ID: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> On Nov 23, 4:49?am, Gerhard H?ring wrote: > Is there a *simple* way to read OpenOffice spreadsheets? > > Bonus: write them, too? > > I mean something like: > > doc.cells[0][0] = "foo" > doc.save("xyz.ods") > > >From a quick look, pyodf offers little more than just using a XML parser I find the syntax far to complicated than it should be. Here is an example just to insert some text.. import uno """ Here is the sequence of things the lines do: 1. Get the uno component context from the PyUNO runtime 2. Create the UnoUrlResolver 3. Get the central desktop object 4. Declare the ServiceManager 5. Get the central desktop object 6. Access the current writer document 7. Access the document's text property 8. Create a cursor 9. Insert the text into the document """ localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve ( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager desktop = smgr.createInstanceWithContext ( "com.sun.star.frame.Desktop",ctx) model = desktop.getCurrentComponent() text = model.Text cursor = text.createTextCursor() text.insertString( cursor, "Hello World", 0 ) """ Do a nasty thing before exiting the python process. In case the last call is a one-way call (e.g. see idl-spec of insertString), it must be forced out of the remote-bridge caches before python exits the process. Otherwise, the one-way call may or may not reach the target object. I do this here by calling a cheap synchronous call (getPropertyValue).""" ctx.ServiceManager WHAT!?!?!??! I don't mean to discredit these guys but the API should be re-thought, and re-written! I don't care about component contexts, unoresolvers, or little green aliens. I just want to insert 'Hello World' into cell A3! Sheesh, There must be an easier way! From tjreedy at udel.edu Mon Nov 23 20:05:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:05:36 -0500 Subject: Beginning Question about Python functions, parameters... In-Reply-To: <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> <7n01t8F3jijv0U1@mid.uni-berlin.de> <8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com> Message-ID: astral orange wrote: > As far as the program. I did add print statements such as print > (MyNames) and got back: > > {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}} Hmmm, as I understood the code, either that should be ... 'last': {} ... before the first store(), as you seem to be thinking below, or after the first store(), {'middle': {'Larry': ['John Larry Smith'], 'last': {'Smith': ['John Larry Smith'], 'first': {'John' " ['John Larry Smith']} or the same with [['John','Larry','Smith']] for each entry (do not remember exactly what was stored. Maybe a typo. tjr From tjreedy at udel.edu Mon Nov 23 20:09:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:09:18 -0500 Subject: Line-continuation "Anti-Idiom" and with statement In-Reply-To: <4B0AEDCF.4060300@mrabarnett.plus.com> References: <7n0578F3j7qa6U1@mid.individual.net> <4B0AEDCF.4060300@mrabarnett.plus.com> Message-ID: MRAB wrote: > Neil Cerutti wrote: > > I installed Python 3.1 today, and I've been porting my small > > library of programs to the new system. > > > > I happened to read the interesting "Idioms and Anti-Idioms" > > HOWTO, and saw the '\' continuation character labeled an > > anti-idiom. I already generally avoided it, so I just nodded. > > > > Unfortunately, the new "nested" with statement (which I also read > > about today) forces me into this anti-idiom. When replacing an > > appearance of contextlib.nested with the 3K with statement, I > > ended up with an unexpected syntax error. > > > > with (open(roster_path, 'r') as roster_file, > > open(disb_path, 'w') as out_file, > > open(report_path, 'w') as report_file): > > > > The result was: > > > > File "C:\project\codxml.py", line 184 > > with (open(roster_path, 'r') as roster_file, > > ^ > > SyntaxError: invalid syntax > > > > Unless I'm missing something, I have to subject my code to a bit > > of contintuation: > > > > with open(roster_path, 'r') as roster_file,\ > > open(disb_path, 'w') as out_file,\ > > open(report_path, 'w') as report_file: > > > > I was thinking about submitting a enhancement request to the > > HOWTO, explaining that continuation my be required in this > > context. Am I missing anything obvious? > > > The relevant syntax is: > > with_stmt ::= "with" with_item ("," with_item)* ":" suite > > with_item ::= expression ["as" target] > > Parentheses only work around an expression or when they are expected by > the syntax, eg in function calls. > > In this case it sees the '(' and thinks that it's the start of a > parenthesised expression. It parses the expression, then sees 'as', > hence a SyntaxError. I suppose it could've complained about a missing > ')' instead. > > I wonder whether an end-of-line could be ignored after a comma in a > 'with' statement, and, for consistency, in any similar cases. Then a line ending with ', ' would be different from one ending with ',', useless space and tabs at ends of lines were *always* ignored. Not sure whether that would create problems though. From lists at cheimes.de Mon Nov 23 20:23:19 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 24 Nov 2009 02:23:19 +0100 Subject: Relative versus absolute paths on Windows In-Reply-To: <7mos8lF3is0n7U1@mid.individual.net> References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <7mos8lF3is0n7U1@mid.individual.net> Message-ID: Gregory Ewing wrote: >>>>> ntpath.join('d:\\foo', '\\bar') >> '\\bar' > > This does seem like a bug, though -- the correct result > should really be 'd:\\bar', since that's what you would > get if you used the name '\\bar' with 'd:' as your current > drive. No, it's not a bug. Since \bar is an absolute path, all path segments before the absolute path are ignored. This is documented at http://docs.python.org/library/os.path.html#os.path.join >>> ntpath.isabs("\\bar") True >>> ntpath.join("ignored", "\\bar") '\\bar' Posixpath follows the same rules, too. >>> posixpath.join("..", "egg", "/var") '/var' >>> posixpath.join("..", "egg", "var") '../egg/var' Christian From gabutler at acslink.net.au Mon Nov 23 20:27:50 2009 From: gabutler at acslink.net.au (gerry.butler) Date: Mon, 23 Nov 2009 17:27:50 -0800 (PST) Subject: Capturing output of os.system to a string Message-ID: How do I capture output to a string? For example, the output of os.system('whoami'). I guess I need to redirect stdout, but I'm a total beginner, and I haven't been able to find out from the tutorials how to do this. From apt.shansen at gmail.com Mon Nov 23 20:36:35 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 23 Nov 2009 17:36:35 -0800 Subject: Capturing output of os.system to a string In-Reply-To: References: Message-ID: <7a9c25c20911231736y634b68cawc76bdc6b01b8e883@mail.gmail.com> On Mon, Nov 23, 2009 at 5:27 PM, gerry.butler wrote: > How do I capture output to a string? For example, the output of > os.system('whoami'). > > I guess I need to redirect stdout, but I'm a total beginner, and I > haven't been able to find out from the tutorials how to do this. > > You don't; os.system is only usable to send commands off that need no input and which you don't care for the output. Check out the subprocess module. You can do like: popen = subprocess.Popen("whoami", stdout=subprocess.PIPE) Then "out, err = popen.communicate()" The 'out' should contain the output from the command. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 23 20:40:00 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 12:40:00 +1100 Subject: Capturing output of os.system to a string In-Reply-To: References: Message-ID: <4b0b39ca$1@dnews.tpgi.com.au> gerry.butler wrote: > How do I capture output to a string? For example, the output of > os.system('whoami'). > > I guess I need to redirect stdout, but I'm a total beginner, and I > haven't been able to find out from the tutorials how to do this. > You can't with os.system; use subprocess module instead. From ethan at stoneleaf.us Mon Nov 23 20:44:46 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 23 Nov 2009 17:44:46 -0800 Subject: Relative versus absolute paths on Windows In-Reply-To: References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com> <7mos8lF3is0n7U1@mid.individual.net> Message-ID: <4B0B3A8E.2000201@stoneleaf.us> Christian Heimes wrote: > Gregory Ewing wrote: > >>>>>>ntpath.join('d:\\foo', '\\bar') >>> >>>'\\bar' >> >>This does seem like a bug, though -- the correct result >>should really be 'd:\\bar', since that's what you would >>get if you used the name '\\bar' with 'd:' as your current >>drive. > > > No, it's not a bug. Since \bar is an absolute path, all path segments > before the absolute path are ignored. This is documented at > http://docs.python.org/library/os.path.html#os.path.join Given that it's documented to work that way, I'll agree that this is not a bug -- however, that doesn't mean it's /right/. From the documentation: Join one or more path components *intelligently*. To me, that means taking into account the bizarre in the MS world of multiple roots on a system... I know I have looked at os.path.join a couple times also, and found the documented behavior to be completely unsatisfactory. In the MS world a drive letter specifier should trump a mere backslash, not be trumped by it. Are there real world situations where the reverse is desired? >>>>ntpath.isabs("\\bar") > > True > >>>>ntpath.join("ignored", "\\bar") > > '\\bar' > > Posixpath follows the same rules, too. > > >>>>posixpath.join("..", "egg", "/var") > > '/var' > >>>>posixpath.join("..", "egg", "var") > > '../egg/var' Posix has the luxury of running on sane systems with only one root. ~Ethan~ From tjreedy at udel.edu Mon Nov 23 20:48:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Nov 2009 20:48:40 -0500 Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting and... In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > import os > import fileinput > > def write( s ): print( s, end = "" ) I believe this is the same as write = sys.stdout.write though you never use it that I see. > > msg_id = 0 > f = open( "nul", "w" ) > for line in fileinput.input( mode = "rb" ): I presume you are expecting the line to be undecoded bytes, as with open(f,'rb'). To be sure, add write(type(line)). > if line.startswith( "From - " ): > msg_id += 1; > f.close() > print( msg_id ) > f = open( "msg_{0:0>6}.txt".format( msg_id ), "w+" ) I do not understand why you are writing since you just wanted to look. In any case, you open in text mode. > else: > f.write( line ) > f.close() > > > > > 955 > 956 > 957 > 958 > Traceback (most recent call last): > File "C:\test\tbfix\splitmails.py", line 11, in > for line in fileinput.input( mode = "rb" ): > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 254, > in __next__ > line = self.readline() > File "C:\Program Files\cpython\python31\lib\fileinput.py", line 349, > in readline > self._buffer = self._file.readlines(self._bufsize) > File "C:\Program Files\cpython\python31\lib\encodings\cp1252.py", line > 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position > 2188: character maps to After I tried os.path.normpath(), it is clear that the function doesn't return the trailing '/', if the path is a directory. But this fact is not documented. Should this be documented in future release of python. Also, I found the documentation of some functions in os.path are not clear. I have to try them in order to understand them for corner cases. I'm wondering if I can join the people who maintain the document to help improve it. From geraldwalkerx at gmail.com Mon Nov 23 20:53:23 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 20:53:23 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: Anjanesh Lekshminarayanan wrote: > fp = urllib.urlopen(url) > data = fp.read() > > Retrieving XML data via an XML service API. > Very often network gets stuck in between. No errors / exceptions. > > CTRL+C > > File "get-xml.py", line 32, in > fp = urllib.urlopen(url) > File "/usr/lib/python2.6/urllib.py", line 87, in urlopen > return opener.open(url) > File "/usr/lib/python2.6/urllib.py", line 206, in open > return getattr(self, name)(url) > File "/usr/lib/python2.6/urllib.py", line 348, in open_http > errcode, errmsg, headers = h.getreply() > File "/usr/lib/python2.6/httplib.py", line 1048, in getreply > response = self._conn.getresponse() > File "/usr/lib/python2.6/httplib.py", line 974, in getresponse > response.begin() > File "/usr/lib/python2.6/httplib.py", line 391, in begin > version, status, reason = self._read_status() > File "/usr/lib/python2.6/httplib.py", line 349, in _read_status > line = self.fp.readline() > File "/usr/lib/python2.6/socket.py", line 397, in readline > data = recv(1) > KeyboardInterrupt > > Is there I can do to try something else if its taking too long to > retrieve from the network ? Like kill previous attempt and retry ? > > Thanks > Anjanesh Lekshmnarayanan import socket from urllib2 import urlopen # A one-hundredths of a second (0.01) timeout before socket throws # an exception to demonstrate catching the timeout. # Obviously, this you will set this greater than 0.01 in real life. socket.setdefaulttimeout(0.01) # example xml feed xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" try: data = urlopen(xml_source) except urllib2.URLError, e: print 'URLError = ' + str(e.reason) From benjamin.kaplan at case.edu Mon Nov 23 20:59:39 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 23 Nov 2009 20:59:39 -0500 Subject: More precise document on os.path.normpath() In-Reply-To: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> References: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> Message-ID: On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu wrote: > After I tried os.path.normpath(), it is clear that the function > doesn't return the trailing '/', if the path is a directory. But this > fact is not documented. Should this be documented in future release of > python. > > Also, I found the documentation of some functions in os.path are not > clear. I have to try them in order to understand them for corner > cases. I'm wondering if I can join the people who maintain the > document to help improve it. > -- Just file a bug report listing what part you find unclear and what you suggest they put to clarify it. > http://mail.python.org/mailman/listinfo/python-list > From geraldwalkerx at gmail.com Mon Nov 23 21:01:55 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:01:55 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > import socket > from urllib2 import urlopen > > # A one-hundredths of a second (0.01) timeout before socket throws > # an exception to demonstrate catching the timeout. > # Obviously, this you will set this greater than 0.01 in real life. > socket.setdefaulttimeout(0.01) > > # example xml feed > xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" > > try: > data = urlopen(xml_source) > except urllib2.URLError, e: > print 'URLError = ' + str(e.reason) Also, if you are using multiple threads to retrieve the xml source(s) and any thread blocks due to network problems, the thread can go way by itself after the default timeout expires. From debatem1 at gmail.com Mon Nov 23 21:03:38 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:03:38 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller wrote: > I was wondering if there were any neat tools (like for instance, > something from itertools) that would help me write the following function > more elegantly. ?The return value should, of course, be the complete $k$- > partite graph $K_{n_1, n_2, \dots, n_k}$: > > def completeGraph (*ns): > ? ?''' > ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > ? ?the sequence \code {n_1, n_2, \dots, n_k}. > ? ?''' > ? ?if len (ns) == 1: > ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) > ? ?n = sum (ns) > ? ?vertices = range (n) > ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] > ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > \ > ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] > ? ?partite_sets.append (vertices[partition_indices [-1]:] ) > > ? ?edges = [] > ? ?for i in range (len (partite_sets)): > ? ? ? ?for j in range (i + 1, len (partite_sets)): > ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) > > ? ?return graph.Graph (vertices = vertices, edges = edges) > > Many thanks! Graphine does this with the following: from base import Graph def K(n): """Generates a completely connected undirected graph of size n. The verticies are numbered [0, n). The edges are named after the verticies they connect such that an edge connected verticies 1 and 2 is named (1,2). """ # create the graph k = Graph() # generate all the nodes for i in range(n): k.add_node(i) # generate all the edges for i in range(n): for j in range(i+1, n): k.add_edge(i, j, (i,j), is_directed=False) # return the graph return k Disclaimer: I'm the author of graphine. Geremy Condra From geraldwalkerx at gmail.com Mon Nov 23 21:06:05 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:06:05 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > Also, if you are using multiple threads to retrieve the xml source(s) > and any thread blocks due to network problems, the thread can go way by > itself after the default timeout expires. > > Typo, edited for clarity: That is: "..the thread can go *away* by itself after the default timeout expires." You don't need to explicitly kill it. From lie.1296 at gmail.com Mon Nov 23 21:08:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 13:08:24 +1100 Subject: profiling differences using an extra function call In-Reply-To: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> References: <649566cd-af8e-407e-a015-a0d19a316580@g31g2000vbr.googlegroups.com> Message-ID: <4b0b4072$1@dnews.tpgi.com.au> marc magrans de abril wrote: > Hi, > > I was a trying to profile a small script and after shrinking the code > to the minimum I got a interesting profile difference. > Given two test functions test1 and test2, that only differs from an > extra level of indirection (i.e. find_substr), That's because there is a function call overhead. > I wonder why I got a > timming difference >50%? A very simple function body will (in terms of percentage) have larger function overhead. With a slightly more complex function body, the body will takes much more time than the function call overhead. > What is the recommended way to factorize the > code? Should I write a big method containing everything? Look in the absolute numbers: 0.666 CPU seconds vs. 0.248 CPU seconds over 1000000 loops means if you put everything into one big method you'll only save 418 nanoseconds per loop. Even over 1000000 loops; you only save 0.418 seconds. Is it worth optimizing? > ----Profiles test1 > Profiles results: > 1000003 function calls in 0.666 CPU seconds > > ----Profile test2: > 3 function calls in 0.248 CPU seconds I got a more striking difference: 5.291 CPU seconds vs 0.589 CPU seconds. But knowing how the profiler works, this is to be expected. Function call overhead become much (and I mean much) heavier with profiler ON. I get a more sane result with timing manually: import time start = time.time() test1(t) print time.time() - start start = time.time() test2(t) print time.time() - start It's 1.186 vs 0.608, which is blink of an eye vs. blink of an eye. From debatem1 at gmail.com Mon Nov 23 21:10:37 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:10:37 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: > On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller > wrote: >> I was wondering if there were any neat tools (like for instance, >> something from itertools) that would help me write the following function >> more elegantly. ?The return value should, of course, be the complete $k$- >> partite graph $K_{n_1, n_2, \dots, n_k}$: >> >> def completeGraph (*ns): >> ? ?''' >> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed >> ? ?the sequence \code {n_1, n_2, \dots, n_k}. >> ? ?''' >> ? ?if len (ns) == 1: >> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) >> ? ?n = sum (ns) >> ? ?vertices = range (n) >> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] >> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] >> \ >> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] >> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) >> >> ? ?edges = [] >> ? ?for i in range (len (partite_sets)): >> ? ? ? ?for j in range (i + 1, len (partite_sets)): >> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ >> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) >> >> ? ?return graph.Graph (vertices = vertices, edges = edges) >> >> Many thanks! > > Graphine does this with the following: > > from base import Graph > > def K(n): > ? ? ? ?"""Generates a completely connected undirected graph of size n. > > ? ? ? ?The verticies are numbered [0, n). > > ? ? ? ?The edges are named after the verticies they connect such that > ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). > ? ? ? ?""" > ? ? ? ?# create the graph > ? ? ? ?k = Graph() > ? ? ? ?# generate all the nodes > ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ?k.add_node(i) > ? ? ? ?# generate all the edges > ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ?for j in range(i+1, n): > ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) > ? ? ? ?# return the graph > ? ? ? ?return k > > > Disclaimer: I'm the author of graphine. > > Geremy Condra > Sorry, misread- to generate a k-partite graph, you'll need a bit more legwork. Give me a bit and I'll add it to graphine. Geremy Condra From gabutler at acslink.net.au Mon Nov 23 21:11:08 2009 From: gabutler at acslink.net.au (gerry.butler) Date: Mon, 23 Nov 2009 18:11:08 -0800 (PST) Subject: Capturing output of os.system to a string References: <4b0b39ca$1@dnews.tpgi.com.au> Message-ID: <1a88f8fa-e7a9-4754-8e8e-ba22b63ff43f@u1g2000pre.googlegroups.com> Thank you. I'll look at subprocess. I have since found that commands will do it too, eg, (status, txt) = commands.getstatusoutput('whoami') or txt = commands.getoutput('whoami') From andyjian430074 at gmail.com Mon Nov 23 21:14:56 2009 From: andyjian430074 at gmail.com (Jankins) Date: Mon, 23 Nov 2009 18:14:56 -0800 (PST) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> Message-ID: <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> On Nov 23, 4:08?pm, "Diez B. Roggisch" wrote: > Jankins schrieb: > > > > > > > I am trying to use sys.stdout to print out "process-bar" like: > > -->1% > > > Here is my program ?test.py?: > > > from sys import stdout > > for v in range(10): > > ? ? stdout.write('-->%d' % v) > > ? ? stdout.flush() > > else: > > ? ? stdout.write('done!') > > #end for > > > Then, I use 'python -u test.py' to run this script. But what I get > > is : > > -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! > > > I am suppose to get 'done!'. > > > Can anybody help me about this? > > You misunderstand what "flush" means. It is not about clearing the > screen, or the line. > > Try printing > > ? ?stdout.write('\r-->%d') > > Diez But there is still a problem. When you use control character '\r', you actually move to the head of the current buffer line and overwrite it. So if I use this way: for i in range(100, 0,-1) The tail of the buffer is not overwrote. How to solve this problem? Thanks. From geraldwalkerx at gmail.com Mon Nov 23 21:15:10 2009 From: geraldwalkerx at gmail.com (Gerald Walker) Date: Mon, 23 Nov 2009 21:15:10 -0500 Subject: Waiting for receiving data In-Reply-To: References: Message-ID: > > import socket > from urllib2 import urlopen > > # A one-hundredths of a second (0.01) timeout before socket throws > # an exception to demonstrate catching the timeout. > # Obviously, this you will set this greater than 0.01 in real life. > socket.setdefaulttimeout(0.01) > > # example xml feed > xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" > > try: > data = urlopen(xml_source) > except urllib2.URLError, e: > print 'URLError = ' + str(e.reason) Oops, the above doesn't run. This version works: import socket import urllib2 # A one-hundredths of a second (0.01) timeout before socket throws # an exception to demonstrate catching the timeout. # Obviously, this you will set this greater than 0.01 in real life. socket.setdefaulttimeout(0.01) # example xml feed xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml" try: data = urllib2.urlopen(xml_source) except urllib2.URLError, e: print 'URLError = ' + str(e.reason) From limodou at gmail.com Mon Nov 23 21:16:42 2009 From: limodou at gmail.com (limodou) Date: Tue, 24 Nov 2009 10:16:42 +0800 Subject: ANN: UliPad 4.0 released! Message-ID: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> UliPad is a flexible editor, based on wxPython. It's has many features,just like:class browser, code auto-complete, html viewer, directory browser, wizard, etc. The main feature is the usage of mixin. This makes UliPad can be extended easily. So you can write your own mixin or plugin, or simple script, these can be easy and seamless integrated with UliPad.Features - *Cross platform* - based on wxPython, so it can run anywhere that wxPython works, such as: Windows, Linux. - Unicode support. - *Most features of wxStyledTextCtrl(Scintilla)* - Syntax highlighting, support Python, c/c++, html, plain text - Folding - Brace Matching - ... - *Extended selection* - Extended word selection -- You can press Ctrl+`MouseDoubleClick` to select a word including '.' - Matched selection -- Select text in quoted chars like: (), [], {}, '', "". For example: a string just like: def func(self, 'This is a test'): ^ The '^' char represents caret position in above line. If you press Ctrl+E, you will select the whole text in (), i.e. "self, 'This is a test'". Something more in Selection Menu. - *Other editing extension* - Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and more. You can duplicate above or below char, word, line which match the leading chars. - Quoting text -- Add some quoted chars before and after selected text, just as: "", '', (), [], {}, and customized string, etc. - Text convertion and view -- python -> html, reStructured Text -> html, textile -> html, and you can output or view the html text in message window, or html view window, or replace the selected text. - Utf-8 encoding auto detect - Changing document encoding - Auto backup - Last session support -- It'll save all the filenames as closed, and reopen the files as next started. - Smart judge the indent char -- It'll auto guess the indent char, and sets it. - Finding in files - Bookmark supports - *Python support* - built-in python interactive window based on PyShell, support Unicode - Auto completion - Function syntax calltips - Run, run with argument, stop python source - Auto change current path - Python class browser - Syntax and PEP8 style checking?also supply a pylint plugin. - *Code snippets* You can manage your code snippets with categories, and each category can have many items. Every item will represent a code snippet. You can insert an item just by double-clicking on it. It even supports importing and exporting. - *Simple project support* Can create a special file _project, so every file and folder under the folder which has the _project can be considered as a whole project. - *Extension mechanism* - Script -- You can write easy script to manipulate the all resource of UliPad, just like: text conversion, etc. - Plugin -- Customized function. More complex but more powerful. Can easily merge with UliPad, and can be managed via menu. - Shell command -- Add often used shell commands, and execute them. - *Ftp support* You can edit remote files through ftp. You can add, rename, delete, upload, download file/directory. - *Multilanguage support* Currently supports 4 languages: English, Spanish, Simplified Chinese and Traditional Chinese, which can be auto-detected. - *Ships many plugins* (must be configed as used them before) - Django support plugin - Batch rename files plugin - Collaborative Programming support plugin, names as *pairprog*. - Mp3 player plugin - Spell check plugin - wizard plugin - Text to speech(windows only) plugin - ... - *Shipped scripts* - You can find them in ($UliPadInstalled)/scripts. - *Wizard* You can make your own wizard template. The wizard can input user data, combine with template, and output the result. And wizard also support code framework created. This feature will help you improving coding efficiency. - *Direcotry Browser* Browse multiple directories, and you can really add, delete, rename directories and files. Double click will open the file in Editor window. - *`AutoComPlete`(acp)* Suport user autocomplete file, it can help to input code very helpful and functional. - *Column Editing Mode* You can select multilines, and then set a column mode region, so in any line of this region, if you enter a character, other lines will also add this character. If you want to deal with multilines as a similar mode, this functionality will be very handy. - *Smart Navigation* UliPad can remember the visit order of your opened files, and you can go back or go forward in these files. - *Live regular expression searching* You can type some regular expression on the fly, and see the result dynamiclly. - *Spell check plugin* Need to install PyEnchant module. - *Collaborative Programming* Multi-user can modify some files at the same time. You should enable * pairprog* plugin. - *Todo Supports* Auto finds todos and supports several kind of formats. - *Multi-View Supports* User can open a document in multi views, for example in left pane or bottom pane. - *Version Control Support* - svn support. Now you can use svn in UliPad to update, checkout, commit, etc. Links - Project: http://code.google.com/p/ulipad - source version: http://ulipad.googlecode.com/files/ulipad.4.0.zip - windows exe version: http://ulipad.googlecode.com/files/ulipad.4.0.py25.exe - maillist: http://groups.google.com/group/ulipad - ulipad snippets site: http://ulipad.appspot.com (hosted by GAE) Hope you enjoy it. -- I like python! UliPad <>: http://code.google.com/p/ulipad/ UliWeb <>: http://uliwebproject.appspot.com My Blog: http://hi.baidu.com/limodou -------------- next part -------------- An HTML attachment was scrubbed... URL: From gary.wugang at gmail.com Mon Nov 23 21:18:25 2009 From: gary.wugang at gmail.com (Gang(Gary) Wu) Date: Tue, 24 Nov 2009 10:18:25 +0800 Subject: [CPyUG:110052] ANN: UliPad 4.0 released! In-Reply-To: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> References: <505f13c0911231816q7c524616sca6b1e74c7cca3a3@mail.gmail.com> Message-ID: ??????????emacs On Tue, Nov 24, 2009 at 10:16 AM, limodou wrote: > UliPad is a flexible editor, based on wxPython. It's has many > features,just like:class browser, code auto-complete, html viewer, directory > browser, wizard, etc. The main feature is the usage of mixin. This makes > UliPad can be extended easily. So you can write your own mixin or plugin, or > simple script, these can be easy and seamless integrated with UliPad. > Features > > - > > *Cross platform* > - based on wxPython, so it can run anywhere that wxPython works, such > as: Windows, Linux. > - Unicode support. > - > > *Most features of wxStyledTextCtrl(Scintilla)* > - Syntax highlighting, support Python, c/c++, html, plain text > - Folding > - Brace Matching > - ... > - > > *Extended selection* > - > > Extended word selection -- You can press Ctrl+`MouseDoubleClick` to > select a word including '.' > - > > Matched selection -- Select text in quoted chars like: (), [], {}, > '', "". > > For example: a string just like: > > def func(self, 'This is a test'): > ^ > > The '^' char represents caret position in above line. If you press > Ctrl+E, you will select the whole text in (), i.e. "self, 'This is a test'". > Something more in Selection Menu. > - > > *Other editing extension* > - Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and more. You can > duplicate above or below char, word, line which match the leading chars. > - Quoting text -- Add some quoted chars before and after selected > text, just as: "", '', (), [], {}, and customized string, etc. > - Text convertion and view -- python -> html, reStructured Text -> > html, textile -> html, and you can output or view the html text in message > window, or html view window, or replace the selected text. > - Utf-8 encoding auto detect > - Changing document encoding > - Auto backup > - Last session support -- It'll save all the filenames as closed, > and reopen the files as next started. > - Smart judge the indent char -- It'll auto guess the indent char, > and sets it. > - Finding in files > - Bookmark supports > - > > *Python support* > - built-in python interactive window based on PyShell, support Unicode > > - Auto completion > - Function syntax calltips > - Run, run with argument, stop python source > - Auto change current path > - Python class browser > - Syntax and PEP8 style checking?also supply a pylint plugin. > - > > *Code snippets* > > You can manage your code snippets with categories, and each category > can have many items. Every item will represent a code snippet. You can > insert an item just by double-clicking on it. It even supports importing and > exporting. > - > > *Simple project support* > > Can create a special file _project, so every file and folder under the > folder which has the _project can be considered as a whole project. > - > > *Extension mechanism* > - Script -- You can write easy script to manipulate the all resource > of UliPad, just like: text conversion, etc. > - Plugin -- Customized function. More complex but more powerful. Can > easily merge with UliPad, and can be managed via menu. > - Shell command -- Add often used shell commands, and execute them. > - > > *Ftp support* You can edit remote files through ftp. You can add, > rename, delete, upload, download file/directory. > - > > *Multilanguage support* > > Currently supports 4 languages: English, Spanish, Simplified Chinese > and Traditional Chinese, which can be auto-detected. > - > > *Ships many plugins* (must be configed as used them before) > - Django support plugin > - Batch rename files plugin > - Collaborative Programming support plugin, names as *pairprog*. > - Mp3 player plugin > - Spell check plugin > - wizard plugin > - Text to speech(windows only) plugin > - ... > - > > *Shipped scripts* > - You can find them in ($UliPadInstalled)/scripts. > - > > *Wizard* > > You can make your own wizard template. The wizard can input user data, > combine with template, and output the result. And wizard also support code > framework created. This feature will help you improving coding efficiency. > - > > *Direcotry Browser* > > Browse multiple directories, and you can really add, delete, rename > directories and files. Double click will open the file in Editor window. > - > > *`AutoComPlete`(acp)* > > Suport user autocomplete file, it can help to input code very helpful > and functional. > - > > *Column Editing Mode* > > You can select multilines, and then set a column mode region, so in any > line of this region, if you enter a character, other lines will also add > this character. If you want to deal with multilines as a similar mode, this > functionality will be very handy. > - > > *Smart Navigation* > > UliPad can remember the visit order of your opened files, and you can > go back or go forward in these files. > - > > *Live regular expression searching* > > You can type some regular expression on the fly, and see the result > dynamiclly. > - > > *Spell check plugin* > > Need to install PyEnchant module. > - > > *Collaborative Programming* > > Multi-user can modify some files at the same time. You should enable * > pairprog* plugin. > - > > *Todo Supports* > > Auto finds todos and supports several kind of formats. > - > > *Multi-View Supports* > > User can open a document in multi views, for example in left pane or > bottom pane. > - > > *Version Control Support* > - svn support. Now you can use svn in UliPad to update, checkout, > commit, etc. > > Links > > - Project: http://code.google.com/p/ulipad > - source version: http://ulipad.googlecode.com/files/ulipad.4.0.zip > - windows exe version: > http://ulipad.googlecode.com/files/ulipad.4.0.py25.exe > - maillist: http://groups.google.com/group/ulipad > - ulipad snippets site: http://ulipad.appspot.com (hosted by GAE) > > Hope you enjoy it. > > -- > I like python! > UliPad <>: http://code.google.com/p/ulipad/ > UliWeb <>: http://uliwebproject.appspot.com > My Blog: http://hi.baidu.com/limodou > > > --~--~---------~--~----~------------~-------~--~----~ > ??: `python-cn`:CPyUG ~ ????? | ??:python-cn at googlegroups.com > ??: http://tinyurl.com/45a9tb //??163/qq??:http://tinyurl.com/4dg6hc > ??: https://groups.google.com/group/python-cn > ??: ????! ????! http://wiki.woodpecker.org.cn/moin/AskForHelp > -~----------~----~----~----~------~----~------~--~--- > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cousinstanley at gmail.com Mon Nov 23 21:32:50 2009 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 24 Nov 2009 02:32:50 +0000 (UTC) Subject: sys.stdout is not flushed References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> Message-ID: >> .... >> You misunderstand what "flush" means. It is not about >> clearing the screen, or the line. >> >> Try printing >> >> ? ?stdout.write('\r-->%d') >> >> Diez > > > But there is still a problem. When you use control character '\r', > you actually move to the head of the current buffer line and > overwrite it. > > So if I use this way: > for i in range(100, 0,-1) > > The tail of the buffer is not overwrote. > .... The following version works ok for me using python2.5 under debian linux .... import sys import time print for n in range( 11 ) : sys.stdout.write( '\r Working ----> %d ' % n ) sys.stdout.flush() time.sleep( 1 ) else : print "\n" print " That's all, folks !" print " Adios ........... " -- Stanley C. Kitching Human Being Phoenix, Arizona From sergiomb at sapo.pt Mon Nov 23 21:44:56 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Tue, 24 Nov 2009 02:44:56 +0000 Subject: [repost please help me] python setup.py build for 32-bits on x86_64 machine References: <4b0ac8c9$0$13168$a729d347@news.telepac.pt> <7n01ggF3j2qn9U1@mid.uni-berlin.de> <4b0ad983$0$13161$a729d347@news.telepac.pt> <7n0f6qF3hgohqU1@mid.uni-berlin.de> Message-ID: <4b0b48a9$0$11263$a729d347@news.telepac.pt> Diez B. Roggisch wrote: > S?rgio Monteiro Basto schrieb: >> Diez B. Roggisch wrote: >> >> Hi, Thanks, >>> S?rgio Monteiro Basto wrote: >>> >>>> Hi, >>>> I am in x86_64 arch , but I need >>>> compile things on 32 bits with >>>> python setup.py build >>>> >>>> Can't change the fact that distutils creates x86_64 >>>> directories: >>>> build/temp.linux-x86_64-2.3/ >>>> >>>> Also if I try with a python compile in 32bits and installed >>>> in system . >>> I doubt that. Distutils will always build based on the architecture of >>> the interpreter you used when building an external module. >>> >>> Are you sure that the python you used to build the extension was the >>> right one? What does >>> >>> -c "from distutils.util import get_platform; print >>> get_platform()" >> python32 -c "from distutils.util import get_platform; print >> get_platform()" linux-x86_64 >> >> ldd ~/bin/python32 >>linux-gate.so.1 => (0xffffe000) >>libpthread.so.0 => /lib/libpthread.so.0 (0x00326000) >>libdl.so.2 => /lib/libdl.so.2 (0x0033f000) >>libutil.so.1 => /lib/libutil.so.1 (0x006b3000) >>libm.so.6 => /lib/libm.so.6 (0x00345000) >>libc.so.6 => /lib/libc.so.6 (0x001e0000) >>/lib/ld-linux.so.2 (0x001c2000) >> >> this a python 2.3, that's make any difference ? > > Ok, next try: > > import distutils > print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') > > What does that yield? >>> import distutils.sysconfig >>> print distutils.sysconfig.get_config_var('SIZEOF_VOID_P') None Thanks, I found the problem, python doesn't have devel stuff like config/Makefile. A complete python3.5 with config/Makefile solved the problem . "distutils gets its compiler options from Python's Makefile", and I don't have config/Makefile correctly build ... Big thanks, From debatem1 at gmail.com Mon Nov 23 21:45:45 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 23 Nov 2009 21:45:45 -0500 Subject: Any elegant way to construct the complete $k$-partite graph in Python? In-Reply-To: References: Message-ID: On Mon, Nov 23, 2009 at 9:10 PM, geremy condra wrote: > On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: >> On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller >> wrote: >>> I was wondering if there were any neat tools (like for instance, >>> something from itertools) that would help me write the following function >>> more elegantly. ?The return value should, of course, be the complete $k$- >>> partite graph $K_{n_1, n_2, \dots, n_k}$: >>> >>> def completeGraph (*ns): >>> ? ?''' >>> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed >>> ? ?the sequence \code {n_1, n_2, \dots, n_k}. >>> ? ?''' >>> ? ?if len (ns) == 1: >>> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) >>> ? ?n = sum (ns) >>> ? ?vertices = range (n) >>> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] >>> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] >>> \ >>> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] >>> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) >>> >>> ? ?edges = [] >>> ? ?for i in range (len (partite_sets)): >>> ? ? ? ?for j in range (i + 1, len (partite_sets)): >>> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ >>> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) >>> >>> ? ?return graph.Graph (vertices = vertices, edges = edges) >>> >>> Many thanks! >> >> Graphine does this with the following: >> >> from base import Graph >> >> def K(n): >> ? ? ? ?"""Generates a completely connected undirected graph of size n. >> >> ? ? ? ?The verticies are numbered [0, n). >> >> ? ? ? ?The edges are named after the verticies they connect such that >> ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). >> ? ? ? ?""" >> ? ? ? ?# create the graph >> ? ? ? ?k = Graph() >> ? ? ? ?# generate all the nodes >> ? ? ? ?for i in range(n): >> ? ? ? ? ? ? ? ?k.add_node(i) >> ? ? ? ?# generate all the edges >> ? ? ? ?for i in range(n): >> ? ? ? ? ? ? ? ?for j in range(i+1, n): >> ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) >> ? ? ? ?# return the graph >> ? ? ? ?return k >> >> >> Disclaimer: I'm the author of graphine. >> >> Geremy Condra >> Alright, how does this look: def k_partite(*partition_sizes): g = Graph() for pos, num_nodes in enumerate(partition_sizes): for i in range(num_nodes): n = g.add_node(name=(pos,i), partition=pos) for node1 in g.nodes: for node2 in g.nodes: if node1.partition != node2.partition: g.add_edge(node1, node2, is_directed=False) return g Geremy Condra From pavlovevidence at gmail.com Mon Nov 23 21:49:45 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 23 Nov 2009 18:49:45 -0800 (PST) Subject: More precise document on os.path.normpath() References: <366c6f340911231752m119ac037qf0ac5b43991abad8@mail.gmail.com> Message-ID: <0767bed0-bc95-4494-ae3b-6b38f370f37e@p19g2000vbq.googlegroups.com> On Nov 23, 5:59?pm, Benjamin Kaplan wrote: > On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu wrote: > > After I tried os.path.normpath(), it is clear that the function > > doesn't return the trailing '/', if the path is a directory. But this > > fact is not documented. Should this be documented in future release of > > python. > > > Also, I found the documentation of some functions in os.path are not > > clear. I have to try them in order to understand them for corner > > cases. I'm wondering if I can join the people who maintain the > > document to help improve it. > > Just file a bug report listing what part you find unclear and what you > suggest they put to clarify it. The documentation does not and should not try to document every little detail of every function. For that matter, nor should comp.lang.python. Python is open source, anyone can look at the implementation to see how it behaves. The source code is the right place to seek answers about arcane minutae like when os.path.normpath appends a backslash. Not the Python docuementation, and definitely not this newsgroup. Carl Banks From sergiomb at sapo.pt Mon Nov 23 21:50:14 2009 From: sergiomb at sapo.pt (=?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto) Date: Tue, 24 Nov 2009 02:50:14 +0000 Subject: lxml 2.2.4 for Python 2.6 References: <9a80baa0-986d-4c17-bcf2-a32d0bf276bf@z10g2000prh.googlegroups.com> Message-ID: <4b0b49e6$0$11263$a729d347@news.telepac.pt> Hi, Srijit Kumar Bhadra wrote: > Is there any reason why lxml-2.2.4-py2.6-win32.egg (md5) or > lxml-2.2.4.win32-py2.6.exe is not available? > > Best regards, > /Srijit maybe ask on lxml Mailing List , should be more appropriated S?rgio M. B. From davea at ieee.org Mon Nov 23 21:54:56 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 23 Nov 2009 21:54:56 -0500 Subject: sys.stdout is not flushed In-Reply-To: <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com> <7n0fepF3hgohqU2@mid.uni-berlin.de> <45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com> Message-ID: <4B0B4B00.4050105@ieee.org> Jankins wrote: > On Nov 23, 4:08 pm, "Diez B. Roggisch" wrote: > >> Jankins schrieb: >> >> >> >> >> >> >>> I am trying to use sys.stdout to print out "process-bar" like: >>> -->1% >>> >>> Here is my program ?test.py?: >>> >>> from sys import stdout >>> for v in range(10): >>> stdout.write('-->%d' % v) >>> stdout.flush() >>> else: >>> stdout.write('done!') >>> #end for >>> >>> Then, I use 'python -u test.py' to run this script. But what I get >>> is : >>> -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done! >>> >>> I am suppose to get 'done!'. >>> >>> Can anybody help me about this? >>> >> You misunderstand what "flush" means. It is not about clearing the >> screen, or the line. >> >> Try printing >> >> stdout.write('\r-->%d') >> >> Diez >> > > > But there is still a problem. When you use control character '\r', you > actually move to the head of the current buffer line and overwrite it. > So if I use this way: > for i in range(100, 0,-1) > > The tail of the buffer is not overwrote. > > How to solve this problem? > > Thanks. > > No idea what you mean by "buffer line." This is moving the cursor around on the console. Anyway, for such a loop, just make sure all the strings are the same length. Or just cheat and always write a few blanks at the end. sys.stdout.write("\r -- %5d" % i) should do it, for up to 5 digit values DaveA From pengyu.ut at gmail.com Mon Nov 23 22:15:48 2009 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 23 Nov 2009 21:15:48 -0600 Subject: Where to put the error handing test? Message-ID: <366c6f340911231915k31cea424sbe9ad8e77def18b0@mail.gmail.com> Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of g(x) is safer, but the test is not necessary when g() is called by h(). If I put the test in f(), then g() becomes more efficient when other code call g() and guarantee x will pass the test even though the test code in not in g(). But there might be some caller of g() that pass an 'x' that might not pass the test, if there were the test in g(). def g(x): # I can put the code here to test whether x satisfies certain conditions. blah, blah def f(x): blah, blah #do something on x # I can also put the code here to test whether x satisfies certain conditions. g(x) def h() blah g(x)#x here are guaranteed to pass the test From rt8396 at gmail.com Mon Nov 23 22:37:09 2009 From: rt8396 at gmail.com (r) Date: Mon, 23 Nov 2009 19:37:09 -0800 (PST) Subject: Beginning Question about Python functions, parameters... References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com> Message-ID: <207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com> On Nov 23, 11:19?am, astral orange <457r0... at gmail.com> wrote: > Hi, I am trying to teach myself Python and have a good book to help me > but I am stuck on something and I would like for someone to explain > the following piece of code for me and what it's actually doing. > Certain parts are very clear but once it enters the "def store(data, > full_name): ...." function and the "def lookup()..." function things > get a little confusing for me. Specifically, lines 103-108 *and* Lines > 110-111. > > Lastly, I am not sure how to print the results I've put into this > program either, the book I'm reading doesn't tell me. As you can tell, > I am a beginner and I don't truly understand everything that is going > on here...a lot, but not all.... > > Here is the code: > > ?92 def init(data): > ?93 ? ? data['first'] = {} > ?94 ? ? data['middle'] = {} > ?95 ? ? data['last'] = {} > ?96 > ?97 def store(data, full_name): > ?98 ? ? names = full_name.split() > 100 ? ? if len(names) == 2: names.insert(1, '') > 101 ? ? labels = 'first', 'middle', 'last' > 103 ? ? for label, name in zip(labels, names): > 104 ? ? ? ? people = lookup(data, label, name) > 105 ? ? if people: > 106 ? ? ? ? people.append(full_name) > 107 ? ? else: > 108 ? ? ? ? data[label][name] = [full_name] > 109 > 110 def lookup(data, label, name): > 111 ? ? return data[label].get(name) > 112 > 113 > 114 MyNames = {} > 115 init(MyNames) > 116 store(MyNames, 'John Larry Smith') > 117 lookup(MyNames, 'middle', 'Smith') This is a horrible example to show noobs. I think the OP could better understand this as a class EVEN though the OP may or may not know what a class *is* yet. >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last >>> name1 = Name('Guido', 'van', 'Rossum') >>> name1.first 'Guido' >>> name1.middle 'van' >>> name1.last 'Rossum' >>> print name1 <__main__.Name instance at 0x029BFD78> This time we add a __str__ method, the result will speak louder than words!! >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last def __str__(self): return '%s %s %s' %(self.first, self.middle, self.last) >>> name2 = Name('Terry', 'J', 'Reedy') >>> name2.first 'Terry' >>> name2.middle 'J' >>> name2.last 'Reedy' >>> print name2 Terry J Reedy See the difference in the print statements. Now lets have some real fun and access each sub name by index haha! >>> class Name(): def __init__(self, first, middle, last): self.first = first self.middle = middle self.last = last def __str__(self): return '%s %s %s' %(self.first, self.middle, self.last) def __len__(self): return 3 def __getitem__(self, item): if item == 0: return self.first elif item == 1: return self.middle elif item == 2: return self.last else: raise IndexError("Index must be in range 0, 2") >>> name = Name('Joe', 'blow', 'scripter') >>> name[0] 'Joe' >>> name[1] 'blow' >>> name[2] 'scripter' >>> len(name) 3 WOW, thats more info in a few lines than any tut i ever seen! I wish i could have seen that in my initial days, could have save some countless hours of confusion!!! Maybe i am in the wrong line of work? Should i keep going...? From lie.1296 at gmail.com Mon Nov 23 22:44:16 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 14:44:16 +1100 Subject: Where to put the error handing test? In-Reply-To: References: Message-ID: <4b0b56ea$1@dnews.tpgi.com.au> Peng Yu wrote: > Suppose that I have function f() that calls g(), I can put a test on > the argument 'x' in either g() or f(). I'm wondering what is the > common practice. > > My thought is that if I put the test in g(x), the code of g(x) is > safer, but the test is not necessary when g() is called by h(). > > If I put the test in f(), then g() becomes more efficient when other > code call g() and guarantee x will pass the test even though the test > code in not in g(). But there might be some caller of g() that pass an > 'x' that might not pass the test, if there were the test in g(). Typically, you test for x as early as possible, e.g. just after user input (or file or url load or whatever). After that test, you can (or should be able to) assume that all function calls will always be called with the correct argument. This is the ideal situation, it's not always easy to do. In any case though, don't optimize early. From chardster at gmail.com Mon Nov 23 22:57:05 2009 From: chardster at gmail.com (Richard Thomas) Date: Mon, 23 Nov 2009 19:57:05 -0800 (PST) Subject: Any elegant way to construct the complete $k$-partite graph in Python? References: Message-ID: <45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com> On Nov 24, 2:45?am, geremy condra wrote: > On Mon, Nov 23, 2009 at 9:10 PM, geremy condra wrote: > > On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote: > >> On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller > >> wrote: > >>> I was wondering if there were any neat tools (like for instance, > >>> something from itertools) that would help me write the following function > >>> more elegantly. ?The return value should, of course, be the complete $k$- > >>> partite graph $K_{n_1, n_2, \dots, n_k}$: > > >>> def completeGraph (*ns): > >>> ? ?''' > >>> ? ?Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed > >>> ? ?the sequence \code {n_1, n_2, \dots, n_k}. > >>> ? ?''' > >>> ? ?if len (ns) == 1: > >>> ? ? ? ?return completeGraph ( * ([1] * ns[0]) ) > >>> ? ?n = sum (ns) > >>> ? ?vertices = range (n) > >>> ? ?partition_indices = [sum (ns[:i]) for i in range (len (ns))] > >>> ? ?partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] > >>> \ > >>> ? ? ? ? ? ? ? ? ? ?for i in range (len (partition_indices) - 1)] > >>> ? ?partite_sets.append (vertices[partition_indices [-1]:] ) > > >>> ? ?edges = [] > >>> ? ?for i in range (len (partite_sets)): > >>> ? ? ? ?for j in range (i + 1, len (partite_sets)): > >>> ? ? ? ? ? ?edges.extend ([ (u, v) for u in partite_sets [i] for v in \ > >>> ? ? ? ? ? ? ? ? ? ? ? ? ? partite_sets [j] ]) > > >>> ? ?return graph.Graph (vertices = vertices, edges = edges) > > >>> Many thanks! > > >> Graphine does this with the following: > > >> from base import Graph > > >> def K(n): > >> ? ? ? ?"""Generates a completely connected undirected graph of size n. > > >> ? ? ? ?The verticies are numbered [0, n). > > >> ? ? ? ?The edges are named after the verticies they connect such that > >> ? ? ? ?an edge connected verticies 1 and 2 is named (1,2). > >> ? ? ? ?""" > >> ? ? ? ?# create the graph > >> ? ? ? ?k = Graph() > >> ? ? ? ?# generate all the nodes > >> ? ? ? ?for i in range(n): > >> ? ? ? ? ? ? ? ?k.add_node(i) > >> ? ? ? ?# generate all the edges > >> ? ? ? ?for i in range(n): > >> ? ? ? ? ? ? ? ?for j in range(i+1, n): > >> ? ? ? ? ? ? ? ? ? ? ? ?k.add_edge(i, j, (i,j), is_directed=False) > >> ? ? ? ?# return the graph > >> ? ? ? ?return k > > >> Disclaimer: I'm the author of graphine. > > >> Geremy Condra > > Alright, how does this look: > > def k_partite(*partition_sizes): > ? ? ? ? g = Graph() > ? ? ? ? for pos, num_nodes in enumerate(partition_sizes): > ? ? ? ? ? ? ? ? for i in range(num_nodes): > ? ? ? ? ? ? ? ? ? ? ? ? n = g.add_node(name=(pos,i), partition=pos) > ? ? ? ? for node1 in g.nodes: > ? ? ? ? ? ? ? ? for node2 in g.nodes: > ? ? ? ? ? ? ? ? ? ? ? ? if node1.partition != node2.partition: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g.add_edge(node1, node2, is_directed=False) > ? ? ? ? return g > > Geremy Condra Not sure exactly how you're representing graphs, this seems like the simplest way of listing the edges. def complete_partite(*sizes): total = sum(sizes) nodes, edges = range(total), [] for group in xrange(len(sizes)): low = sum(sizes[:group-1]) high = sum(sizes[:group]) edges.extend((i, j) for i in xrange(low, high) for j in xrange(high, total)) return nodes, edges Chard From lie.1296 at gmail.com Mon Nov 23 22:57:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 14:57:06 +1100 Subject: More precise document on os.path.normpath() In-Reply-To: References: Message-ID: <4b0b59ef@dnews.tpgi.com.au> Peng Yu wrote: > After I tried os.path.normpath(), it is clear that the function > doesn't return the trailing '/', if the path is a directory. But this > fact is not documented. Should this be documented in future release of > python. > > Also, I found the documentation of some functions in os.path are not > clear. I have to try them in order to understand them for corner > cases. I'm wondering if I can join the people who maintain the > document to help improve it. os.path is designed for OS-agnostic path manipulation. The textual representation of the output of os.path is irrelevant. If a trailing '/' doesn't affect the ability to open the directory or file or os.path.join or whatever, it is irrelevant to os.path. If the trailing / does affect those abilities, though, it is a bug in os.path. From lie.1296 at gmail.com Mon Nov 23 23:01:34 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 24 Nov 2009 15:01:34 +1100 Subject: Line Breaks In-Reply-To: References: <4B0AE1EE.5070705@islandtraining.com> Message-ID: <4b0b5aff@dnews.tpgi.com.au> D'Arcy J.M. Cain wrote: > On Mon, 23 Nov 2009 14:46:23 -0500 > Susan Day wrote: >> First, it does in fact ignore all line breaks, not just double line breaks. >> Here's what I'm doing: >> session.sendmail(clientEmail, ourEmail2, header+msg) >> The email sent out has the message sans breaks. > > You should really post an entire script that runs and shows the error > so that we can run it (changing the email address of course) to see > what it does. > My guess: you're writing HTML email? In HTML, superfluous whitespace is ignored. Use
    for line break   for space, or enclose the text in
    
    
    From lie.1296 at gmail.com  Mon Nov 23 23:02:23 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Tue, 24 Nov 2009 15:02:23 +1100
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: 
    References: 
    Message-ID: <4b0b5b2b@dnews.tpgi.com.au>
    
    Alf P. Steinbach wrote:
    > 
    > And I'm hesitant to just delete index file, hoping that it'll rebuild.
    
    it'll be rebuild the next time you start Thunderbird:
    (MozillaZine: http://kb.mozillazine.org/Disappearing_mail)
    *  It's possible that the ".msf" files (index files) are corrupted. To 
    rebuild the index of a folder, right-click it, select Properties, and 
    choose "Rebuild Index" from the General Information tab. You can also 
    close Thunderbird and manually delete them from your profile folder; 
    they will be rebuilt when Thunderbird starts.
    
    
    
    From pengyu.ut at gmail.com  Mon Nov 23 23:08:39 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Mon, 23 Nov 2009 22:08:39 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <4b0b56ea$1@dnews.tpgi.com.au>
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    Message-ID: <366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    
    On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    > Peng Yu wrote:
    >>
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> My thought is that if I put the test in g(x), the code of g(x) is
    >> safer, but the test is not necessary when g() is called by h().
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    >
    > Typically, you test for x as early as possible, e.g. just after user input
    > (or file or url load or whatever). After that test, you can (or should be
    > able to) assume that all function calls will always be called with the
    > correct argument. This is the ideal situation, it's not always easy to do.
    >
    > In any case though, don't optimize early.
    
    Let's suppose that g() is refactored out from f() and is call by not
    only f() but other functions, and g() is likely to be called by new
    functions.
    
    If I don't optimize early, I should put the test in g(), rather than f(), right?
    
    
    From andyjian430074 at gmail.com  Tue Nov 24 00:09:36 2009
    From: andyjian430074 at gmail.com (Jankins)
    Date: Mon, 23 Nov 2009 21:09:36 -0800 (PST)
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    	<45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com>
    	
    Message-ID: 
    
    On Nov 23, 8:32?pm, Cousin Stanley  wrote:
    > >> ....
    > >> You misunderstand what "flush" means. It is not about
    > >> clearing the screen, or the line.
    >
    > >> Try printing
    >
    > >> ? ?stdout.write('\r-->%d')
    >
    > >> Diez
    >
    > > But there is still a problem. When you use control character '\r',
    > > you actually move to the head of the current buffer line and
    > > overwrite it.
    >
    > > So if I use this way:
    > > for i in range(100, 0,-1)
    >
    > > The tail of the buffer is not overwrote.
    > > ....
    >
    > ? The following version works ok for me
    > ? using python2.5 under debian linux ....
    >
    > import sys
    > import time
    >
    > print
    >
    > for n in range( 11 ) :
    > ? ? sys.stdout.write( '\r ? ?Working ----> %d ' % n )
    > ? ? sys.stdout.flush()
    > ? ? time.sleep( 1 )
    >
    > else :
    > ? ? print "\n"
    > ? ? print " ? ?That's all, folks !"
    > ? ? print " ? ?Adios ........... "
    >
    > --
    > Stanley C. Kitching
    > Human Being
    > Phoenix, Arizona
    
    Thanks. It works. Put some space at the end of the output string.
    
    
    From andyjian430074 at gmail.com  Tue Nov 24 00:11:04 2009
    From: andyjian430074 at gmail.com (Jankins)
    Date: Mon, 23 Nov 2009 21:11:04 -0800 (PST)
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    	<45455fd8-c50c-4583-b85e-c0f66393aebc@o9g2000vbj.googlegroups.com>
    	
    Message-ID: <22e5bc5f-0dc4-4334-9446-5a60c1ba9ed4@g1g2000vbr.googlegroups.com>
    
    On Nov 23, 8:54?pm, Dave Angel  wrote:
    > Jankins wrote:
    > > On Nov 23, 4:08 pm, "Diez B. Roggisch"  wrote:
    >
    > >> Jankins schrieb:
    >
    > >>> I am trying to use sys.stdout to print out "process-bar" like:
    > >>> -->1%
    >
    > >>> Here is my program ?test.py?:
    >
    > >>> from sys import stdout
    > >>> for v in range(10):
    > >>> ? ? stdout.write('-->%d' % v)
    > >>> ? ? stdout.flush()
    > >>> else:
    > >>> ? ? stdout.write('done!')
    > >>> #end for
    >
    > >>> Then, I use 'python -u test.py' to run this script. But what I get
    > >>> is :
    > >>> -->0-->1-->2-->3-->4-->5-->6-->7-->8-->9done!
    >
    > >>> I am suppose to get 'done!'.
    >
    > >>> Can anybody help me about this?
    >
    > >> You misunderstand what "flush" means. It is not about clearing the
    > >> screen, or the line.
    >
    > >> Try printing
    >
    > >> ? ?stdout.write('\r-->%d')
    >
    > >> Diez
    >
    > > But there is still a problem. When you use control character '\r', you
    > > actually move to the head of the current buffer line and overwrite it.
    > > So if I use this way:
    > > for i in range(100, 0,-1)
    >
    > > The tail of the buffer is not overwrote.
    >
    > > How to solve this problem?
    >
    > > Thanks.
    >
    > No idea what you mean by "buffer line." ?This is moving the cursor
    > around on the console.
    >
    > Anyway, for such a loop, just make sure all the strings are the same
    > length. ?Or just cheat and always write a few blanks at the end.
    >
    > ? ? ? ?sys.stdout.write("\r -- %5d" % i)
    >
    > should do it, for up to 5 digit values
    >
    > DaveA
    
    '%5d' is elegant. I prefer adding some space at the end of the output
    string.
    Thanks.
    
    
    From sean_mcilroy at yahoo.com  Tue Nov 24 00:15:52 2009
    From: sean_mcilroy at yahoo.com (Sean McIlroy)
    Date: Mon, 23 Nov 2009 21:15:52 -0800 (PST)
    Subject: midi file parser
    Message-ID: 
    
    
    """
    
    A Sequence is a list [FormatType, TimeDivision, Tracks] where
    
    *) FormatType is in [0,1,2]
    *) TimeDivision is either [TicksPerBeat] with TicksPerBeat in range
    (2**15) or
       [FramesPerSecond, TicksPerFrame] with FramesPerSecond in range
    (2**7)
       and TicksPerFrame in range(2**8)
    *) Tracks is a list of Events
    
    An Event is either a ChannelEvent or a MetaEvent.
    A ChannelEvent is  [DeltaTime, EventType, Channel, Parameters]
    and a MetaEvent is [DeltaTime, MetaType, Message] where
    
    *) DeltaTime  is a nonnegative integer
    *) EventType  is in range(7)
    *) Channel    is in range(2**4)
    *) Parameters is a list with elements in range(2**7)
    *) MetaType   is in range(2**7)
    *) Message    is a string
    
    The EventTypes and Parameters of ChannelEvents have the following
    verbal handles:
    
    EventType                        Parameters
    
    0 = NoteOff                      [NoteNumber, Velocity]
    1 = NoteOn                       [NoteNumber, Velocity]
    2 = NoteAftertouch               [NoteNumber, Amount]
    3 = Controller                   [ControllerType, Value]
    4 = ProgramChange                [ProgramNumber]
    5 = ChannelAftertouch            [Amount]
    6 = PitchBend                    [ValueLSB, ValueMSB]
    
    """
    
    def concat(xs):
        from itertools import chain
        return list(chain(*xs))
    
    def zeropadded(digits,minlength):
        return [0]*(minlength-len(digits)) + digits
    
    def noleadingzeros(digits):
        while digits[0]==0 and len(digits)>1: digits = digits[1:]
        return digits
    
    def number2digits(number,base):
        digits = [number]
        while digits[0]>=base: digits[0:1] = [digits[0]//base, digits
    [0]%base]
        return digits
    
    def digits2number(digits,base):
        reversedigits = reversed(noleadingzeros(digits))
        basepowers = [base**n for n in range(len(digits))]
        return sum([x*y for (x,y) in zip(reversedigits,basepowers)])
    
    def number2fixedlength(number,length):
        return zeropadded(number2digits(number,2**8),length)
    
    def fixedlength2number(digits):
        return digits2number(digits,2**8)
    
    def number2variablelength(number):
        digits = number2digits(number,2**7)
        padding = [2**7]*(len(digits)-1) + [0]
        return [x+y for (x,y) in zip(digits,padding)]
    
    def variablelength2number(variablelength):
        padding = [2**7]*(len(variablelength)-1) + [0]
        digits = [x-y for (x,y) in zip(variablelength,padding)]
        return digits2number(digits,2**7)
    
    def smallbyte(number):
        return number < (2**7)
    
    def getfixedlength(numbers,startindex,numbytes):
        endindex = startindex + numbytes
        return (endindex, numbers[startindex:endindex])
    
    def getvariablelength(numbers,startindex):
        index = startindex
        while not smallbyte(numbers[index]): index = index + 1
        endindex = index + 1
        return (endindex, numbers[startindex:endindex])
    
    def analyzetimedivision(numbers):
        [byte1, byte2]  = numbers
        indicator  = byte1 // (2**7)
        firstbyte  = byte1 % (2**7)
        secondbyte = byte2
        if indicator==0:
            ticksperbeat = (2**8) * firstbyte + secondbyte
            return [ticksperbeat]
        if indicator==1:
            framespersecond = firstbyte
            ticksperframe   = secondbyte
            return [framespersecond, ticksperframe]
    
    def synthesizetimedivision(numbers):
        if len(numbers)==1:
            [ticksperbeat] = numbers
            firstbyte  = ticksperbeat // (2**8)
            secondbyte = ticksperbeat  % (2**8)
            indicator = 0
        if len(numbers)==2:
            [framespersecond, ticksperframe] = numbers
            firstbyte  = framespersecond
            secondbyte = ticksperframe
            indicator = 1
        byte1 = indicator * (2**7) + firstbyte
        byte2 = secondbyte
        return [byte1, byte2]
    
    def analyzeheaderdata(numbers):
        formattype   =  fixedlength2number(numbers[0:2])
        numtracks    =  fixedlength2number(numbers[2:4])
        timedivision = analyzetimedivision(numbers[4:6])
        return (formattype, numtracks, timedivision)
    
    def synthesizeheaderdata(formattype,numtracks,timedivision):
        formattype   = number2fixedlength(formattype, 2)
        numtracks    = number2fixedlength(numtracks,  2)
        timedivision = synthesizetimedivision(timedivision)
        return formattype + numtracks + timedivision
    
    def analyzestatus(statusbyte):
        number = statusbyte - (2**7)
        eventtype = number // (2**4)
        channel   = number  % (2**4)
        return (eventtype, channel)
    
    def synthesizestatus(eventtype,channel):
        statusbyte = (2**7) + (2**4) * eventtype + channel
        return [statusbyte]
    
    def synthesizeevent(event):
        if len(event)==4:
            [deltatime, eventtype, channel, parameters] = event
            return number2variablelength(deltatime) + synthesizestatus
    (eventtype,channel) + parameters
        if len(event)==3:
            [deltatime, metatype, message] = event
            quantifiedmessage = number2variablelength(len(message)) + [ord
    (x) for x in message]
            return number2variablelength(deltatime) + synthesizestatus
    (7,15) + [metatype] + quantifiedmessage
    
    def makechunk(identifier,numbers):
        return identifier + number2fixedlength(len(numbers),4) + numbers
    
    def makeheader(formattype,numtracks,timedivision):
        headeridentifier = [77, 84, 104, 100]
        return makechunk(headeridentifier,synthesizeheaderdata
    (formattype,numtracks,timedivision))
    
    def maketrack(events):
        trackidentifier  = [77, 84, 114, 107]
        return makechunk(trackidentifier,concat([synthesizeevent(x) for x
    in events]))
    
    def getchunks(numbers):
        numbytes = len(numbers)
        index = 0
        chunks = []
        while index < numbytes:
            i = index + 4
            j = index + 8
            k = j + fixedlength2number(numbers[i:j])
            index = k
            chunks.append(numbers[j:k])
        return chunks
    
    def getevent(numbers,startindex,runningstatus):
        (i, deltatime)       = getvariablelength(numbers,startindex)
        deltatime            = variablelength2number(deltatime)
        (j, status)          = smallbyte(numbers[i]) and (i, []) or (i+1,
    [numbers[i]])
        nextrunningstatus    = status or runningstatus
        (eventtype, channel) = analyzestatus(nextrunningstatus[0])
        if not eventtype==7:
            numparameters                = eventtype in [4,5] and 1 or 2
            (nextstartindex, parameters) = getfixedlength
    (numbers,j,numparameters)
            event                        = [deltatime, eventtype, channel,
    parameters]
        if eventtype==7 and channel==15:
            (k, metatype)             = (j+1, numbers[j])
            (m, messagelength)        = getvariablelength(numbers,k)
            (nextstartindex, message) = getfixedlength
    (numbers,m,variablelength2number(messagelength))
            message                   = ''.join([chr(x) for x in message])
            event                     = [deltatime, metatype, message]
        if eventtype==7 and not channel==15:
            (k, messagelength)        = getvariablelength(numbers,j)
            (nextstartindex, message) = getfixedlength
    (numbers,k,variablelength2number(messagelength))
            event                     = None
        return (nextstartindex, nextrunningstatus, event)
    
    def getevents(numbers):
        numbytes = len(numbers)
        index = 0
        runningstatus = []
        events = []
        while index < numbytes:
            (nextindex, nextrunningstatus, event) = getevent
    (numbers,index,runningstatus)
            index = nextindex
            runningstatus = nextrunningstatus
            if not event==None: events.append(event)
        return events
    
    def parse(filedata):
        numbers = list(filedata)
        chunks = getchunks(numbers)
        (formattype, numtracks, timedivision) = analyzeheaderdata(chunks
    [0])
        tracks = [getevents(x) for x in chunks[1:]]
        return [formattype, timedivision, tracks]
    
    def unparse(sequence):
        [formattype, timedivision, tracks] = sequence
        numtracks = len(tracks)
        header = makeheader(formattype,numtracks,timedivision)
        numbers = header + concat([maketrack(x) for x in tracks])
        return bytes(numbers)
    
    ########################################
    ## from midiparser import parse, unparse
    
    def readmidi(filepath):
        return parse(open(filepath,'rb').read())
    
    def writemidi(sequence,filepath):
        open(filepath,'wb').write(unparse(sequence))
    
    def replace(replacee,replacer,string):
        return replacer.join(string.split(replacee))
    
    def notename(notenumber):
        names = ('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')
        return names[notenumber % 12] + '-' + str(notenumber // 12)
    
    def gettrackname(track):
        names = [event[2] for event in track if len(event)==3 and event[1]
    ==3]
        return names and numbers2string(names[0]) or None
    
    def noteevent(event):
        return len(event)==4 and event[1] in range(3)
    
    def switchevent(event):
        return len(event)==4 and event[1] in range(2)
    
    def firstnoteindices(track):
        for i in range(len(track)):
            if noteevent(track[i]): return [i]
        return []
    
    def lastnoteindices(track):
        for i in reversed(range(len(track))):
            if noteevent(track[i]): return [i]
        return []
    
    def explodefile(filepath,directorypath):
        [formattype, timedivision, tracks] = readmidi(filepath)
        index = formattype==1 and not firstnoteindices(tracks[0]) and 1 or
    0
        temposettings, tracks = tracks[:index], tracks[index:]
        for i in range(len(tracks)):
            trackname = gettrackname(tracks[i]) or ('track_' + str(i))
            rewrite = lambda basename: basename + '_' + replace('/', '_',
    trackname)
            singletrackfilepath = changefilepath
    (filepath,directorypath,rewrite)
            singletrackfile = (formattype, timedivision, temposettings +
    [tracks[i]])
            writemidi(singletrackfile,singletrackfilepath)
    
    def reflectpitch(event):
        if not noteevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        newparameters = [(2**7)-notenumber, velocity]
        return [deltatime, eventtype, channel, newparameters]
    
    def translatepitch(event,deltapitch):
        if not noteevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        newnotenumber = notenumber + deltapitch
        assert newnotenumber in range(2**7)
        newparameters = [newnotenumber, velocity]
        return [deltatime, eventtype, channel, newparameters]
    
    def switch(event):
        noteoff, noteon = range(2)
        if not switchevent(event): return event
        [deltatime, eventtype, channel, parameters] = event
        [notenumber, velocity] = parameters
        neweventtype = noteon
        newvelocity = (eventtype==noteoff or velocity==0) and (2**6) or 0
        newparameters = [notenumber, newvelocity]
        return [deltatime, neweventtype, channel, newparameters]
    
    def invert(track):
        return [reflectpitch(x) for x in track]
    
    def transpose(track,deltapitch):
        return [translatepitch(x,deltapitch) for x in track]
    
    def retrograde(track):
        prefixindex = firstnoteindices(track)[0]
        suffixindex = lastnoteindices(track)[0] + 1
        prefix, noteevents, suffix = track[:prefixindex], track
    [prefixindex: suffixindex], track[suffixindex:]
        newnoteevents = [switch(event) for event in reversed(noteevents)]
        nextdeltatime = noteevents[-1][0]
        for i in range(len(newnoteevents)):
            [deltatime, eventtype, channel, parameters] = newnoteevents[i]
            newnoteevents[i] = [nextdeltatime, eventtype, channel,
    parameters]
            nextdeltatime = deltatime
        return prefix + newnoteevents + suffix
    
    def sequences(length,elements):
        if length==0: return [[]]
        return [[x] + ys for x in elements for ys in sequences
    (length-1,elements)]
    
    def toggle(notenumber):
        on  = [0,   1, 0, [notenumber, (2**7)-1]]
        off = [300, 0, 0, [notenumber, 0]]
        return [on, off]
    
    def eartrainer(notenumbers):
        from functools import reduce
        endoftrack = [0, 47, []]
        track = reduce(lambda x,y: x+y, [toggle(x) for x in notenumbers])
    + [endoftrack]
        return [0, [120], [track]]
    
    def makeflashcards(length,lowest,highest):
        from os import mkdir
        from random import shuffle
        mkdir('questions')
        mkdir('answers')
        notesequences = sequences(length, range(lowest, highest + 1))
        shuffle(notesequences)
        for i in range(len(notesequences)):
            writemidi(eartrainer(notesequences[i]), 'questions/sequence_'
    + str(i) + '.mid')
            open('answers/sequence_' + str(i) + '.txt','w').write(' '.join
    ([notename(x) for x in notesequences[i]]))
    
    def noemptytracks(mididata):
        [formattype, timedivision, tracks] = mididata
        index = (formattype==1 and not firstnoteindices(tracks[0])) and 1
    or 0
        temposettings, tracks = tracks[:index], tracks[index:]
        newtracks = temposettings + [track for track in tracks if
    firstnoteindices(track)]
        return [formattype, timedivision, newtracks]
    
    def nocountin(mididata):
        [formattype, timedivision, tracks] = mididata
        TrackEventOldTime = [(i,j,tracks[i][j][0]) for i in range(len
    (tracks)) for j in firstnoteindices(tracks[i])]
        starttime = min([t for (i,j,t) in TrackEventOldTime])
        TrackEventNewTime = [(i,j,t-starttime) for (i,j,t) in
    TrackEventOldTime]
        newtracks = tracks[:]
        for (i,j,t) in TrackEventNewTime: newtracks[i][j][0] = t
        return [formattype, timedivision, newtracks]
    
    def processfiles(directorypath,function):
        from os import listdir, mkdir
        filenames = listdir(directorypath)
        subdirectorypath = directorypath + '/preprocessed'
        mkdir(subdirectorypath)
        for filename in filenames:
            oldfilepath = directorypath    + '/' + filename
            newfilepath = subdirectorypath + '/' + filename
            writemidi(function(readmidi(oldfilepath)),newfilepath)
    
    
    
    
    
    
    From gherron at islandtraining.com  Tue Nov 24 00:23:41 2009
    From: gherron at islandtraining.com (Gary Herron)
    Date: Mon, 23 Nov 2009 21:23:41 -0800
    Subject: Line Breaks
    In-Reply-To: 
    References: 	<4B0AE1EE.5070705@islandtraining.com>
    	
    Message-ID: <4B0B6DDD.3000301@islandtraining.com>
    
    Susan Day wrote:
    > On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron 
    > > wrote:
    >
    >     >>> print 'A Message From %s:\n\n %s' % ('someone','some message')
    >     A Message From someone:
    >
    >     some message
    >
    >
    >     So...  *Exactly* what are you doing with msg, and *exactly* what
    >     is your evidence that line breaks are being ignored.  With that
    >     information, perhaps we can identify and solve the real problem
    >     you're having.
    >
    >
    > First, it does in fact ignore all line breaks, not just double line 
    > breaks.
    > Here's what I'm doing:
    > session.sendmail(clientEmail, ourEmail2, header+msg)
    > The email sent out has the message sans breaks.
    > TIA,
    > Suzie
    
    
    You say "it does in fact ignore all line breaks", but which "IT" are you 
    talking about.  The line of code you originally showed us
            msg = 'A Message From %s:\n\n %s' % (string.replace(customer, 
    '_', ' '), msg)
    in fact does NOT ignore line breaks, and I demonstrated that to you.    
    Your problem is somewhere else. 
    
    Now you've shown us one more line of code.  But why only one?   Why make 
    it so hard for us to help you?   I for one will consider volunteering 
    more time on this problem only if I get a small, complete program, which 
    demonstrates the problem, and which I can cut and paste.
    
    Gary Herron
    
    
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:02:15 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:02:15 +0000
    Subject: Relative versus absolute paths on Windows
    References: <9069b2a1-e9d2-4fcb-b501-4d9d75485be5@z41g2000yqz.googlegroups.com>
    	<7mos8lF3is0n7U1@mid.individual.net>
    	
    Message-ID: 
    
    On Tue, 24 Nov 2009 02:23:19 +0100, Christian Heimes wrote:
    
    > Gregory Ewing wrote:
    >>>>>> ntpath.join('d:\\foo', '\\bar')
    >>> '\\bar'
    >> 
    >> This does seem like a bug, though -- the correct result
    >> should really be 'd:\\bar', since that's what you would
    >> get if you used the name '\\bar' with 'd:' as your current
    >> drive.
    > 
    > No, it's not a bug. Since \bar is an absolute path, all path segments
    > before the absolute path are ignored.
    
    Except that a path without a drive letter *isn't* an absolute path in
    any meaningful sense. The fact that os.path.isabs() disagrees is a defect
    in os.path.isabs() (I won't call it a bug, as it's documented as behaving
    that way).
    
    The upshot is that the standard library is missing important functionality
    on Windows, i.e. testing whether a path is absolute, and resolving a
    relative path relative to an absolute path.
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:15:18 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:15:18 +0000
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    Message-ID: 
    
    On Mon, 23 Nov 2009 22:06:29 +0100, Alf P. Steinbach wrote:
    
    > 10. It says UnicodeDecodeError on mail nr. something something.
    
    That's what you get for using Python 3.x ;)
    
    If you must use 3.x, don't use the standard descriptors. If you must use
    the standard descriptors in 3.x, call detach() on them to get the
    underlying binary stream, i.e.
    
    	stdin = sys.stdin.detach()
    	stdout = sys.stdout.detach()
    
    and use those instead.
    
    Or set LC_ALL or LC_CTYPE to an ISO-8859-* locale (any stream of bytes can
    be decoded, and any string resulting from decoding can be encoded).
    
    
    
    From nobody at nowhere.com  Tue Nov 24 01:19:00 2009
    From: nobody at nowhere.com (Nobody)
    Date: Tue, 24 Nov 2009 06:19:00 +0000
    Subject: sys.stdout is not flushed
    References: <5c57941a-11fb-47e6-a892-3e77ceb289f5@g31g2000vbr.googlegroups.com>
    	<7n0fepF3hgohqU2@mid.uni-berlin.de>
    Message-ID: 
    
    On Mon, 23 Nov 2009 23:08:25 +0100, Diez B. Roggisch wrote:
    
    > Try printing
    > 
    >    stdout.write('\r-->%d')
    
    ^M-->0^M-->1^M-->2^M-->3... ;)
    
    But it's probably good enough for the OP's purposes.
    
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 01:23:53 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 06:23:53 +0000 (UTC)
    Subject: Any elegant way to construct the complete $k$-partite graph in 
    	Python?
    References: 
    	
    	
    	
    	<45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com>
    Message-ID: 
    
    On Mon, 23 Nov 2009 19:57:05 -0800, Richard Thomas wrote:
    
    > Not sure exactly how you're representing graphs, this seems like the
    > simplest way of listing the edges.
    > 
    > def complete_partite(*sizes):
    >     total = sum(sizes)
    >     nodes, edges = range(total), []
    >     for group in xrange(len(sizes)):
    >         low = sum(sizes[:group-1])
    >         high = sum(sizes[:group])
    >         edges.extend((i, j) for i in xrange(low, high)
    >                             for j in xrange(high, total))
    >     return nodes, edges
    
    Thanks!  I think this is what I was looking for (unless the collective 
    wisdom of c.l.py can come up with something *even more* elegant). :-)
    
    
    From wuwei23 at gmail.com  Tue Nov 24 01:27:24 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Mon, 23 Nov 2009 22:27:24 -0800 (PST)
    Subject: Where to put the error handing test?
    References: 
    Message-ID: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    
    On Nov 24, 1:15?pm, Peng Yu  wrote:
    > Suppose that I have function f() that calls g(), I can put a test on
    > the argument 'x' in either g() or f(). I'm wondering what is the
    > common practice.
    >
    > If I put the test in f(), then g() becomes more efficient when other
    > code call g() and guarantee x will pass the test even though the test
    > code in not in g(). But there might be some caller of g() that pass an
    > 'x' that might not pass the test, if there were the test in g().
    
    What you should try to do is make each function as self-contained as
    possible. f() shouldn't have to know what is a valid argument for g(),
    that's the responsibility of g(). What f() needs to know is how to
    deal with any problems that arise while using g().
    
    As a very rough example:
    
        def g(x):
            try:
                assert isinstance(x, int)
            except AssertionError:
                raise TypeError, "excepted int, got %s" % type(x)
            # ... function code goes here
    
        def f(x):
            try:
                g(x)
            except TypeError:
                # handle the problem here
            # ... function code goes here
    
    > My thought is that if I put the test in g(x), the code of g(x) is
    > safer, but the test is not necessary when g() is called by h().
    
    This sounds strange to me. Are you stating that h() can pass values to
    g() that would be illegal for f() to pass? That sounds like a very
    dangerous design...you want each function's behaviour to be as
    consistent and predictable as it possibly can.
    
    
    From wuwei23 at gmail.com  Tue Nov 24 01:28:39 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Mon, 23 Nov 2009 22:28:39 -0800 (PST)
    Subject: midi file parser
    References: 
    Message-ID: <21e09eb7-06a0-47c7-9049-4630cc3d7243@13g2000prl.googlegroups.com>
    
    On Nov 24, 3:15?pm, Sean McIlroy  wrote:
    > [code snipped]
    
    Great stuff. Have you considered bundling it up and putting it onto
    PyPI?
    
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 01:49:26 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 06:49:26 +0000 (UTC)
    Subject: adding a directory to sys.path
    References: 
    Message-ID: 
    
    On Mon, 23 Nov 2009 12:02:36 -0500, John Guenther wrote:
    
    > This is Mac related. I am running snow leopard. I am using Python 2.6.3.
    > 
    > I had a lot of difficulty figuring out how to add a directory to
    > sys.path that would be there every time I launched Idle.
    [...]
    
    For a comprehensive discussion of how to modify sys.path, see 
    
    http://docs.python.org/install/index.html#modifying-python-s-search-path
    
    If you really just need to modify sys.path for one particular user, what 
    I would do is add the line
    
    export PYTHONSTARTUP="/home/my_user/python/startup.py"
    
    to my .bashrc.  Then, in the file /home/my_user/python/startup.py, 
    include the following code:
    
    import sys
    
    sys.path.append ("/home/my_user/some_dir")
    
    This will add the directory /home/my_user/some_dir to sys.path every time 
    you start up Python.  
    
    The reason I like using PYTHONSTARTUP is that you can do other sorts of 
    customizations in that file, as well.  For example, I hate not having any 
    way to clear the screen when I'm typing at the Python prompt, so I added 
    this code to my $PYTHONSTARTUP file:
    
    import os
    
    def clear():
        os.system ('clear')
    
    Hope that all helps!
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Tue Nov 24 03:02:22 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 09:02:22 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 
    Message-ID: <4b0b92de$0$14677$426a74cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > The problem I have with properties is my typing.  I'll end up assigning 
    > to an attribute, but get the spelling slightly wrong (capitalized, or 
    > missing an underscore -- non-obvious things when bug-hunting), so now I 
    > have an extra attribute which of course has zero effect on what I'm 
    > trying to do and I start getting wierd results like viewing deleted 
    > records when I *know* I set useDeleted = False... 30 minutes later I 
    > notice it was /supposed/ to be use_deleted.  *sigh*
    > 
    > So -- to keep myself out of trouble -- I have started coding such things 
    > as, for example:
    > 
    > result = table.use_deleted()       # returns True or False
    > table.use_deleted(False)           # skip deleted records
    > 
    > instead of
    > 
    > result = table.use_deleted
    > table.use_deleted = False
    > 
    > My question:  is this [ severely | mildly | not at all ] un-pythonic?
    
    Definitly and totally unpythonic. The first solution to your problem is 
    to stick to standard naming conventions. If this is not enough, Chris 
    pointed you to really useful tools. Also, you can override __setattr__ 
    to catch such errors - at least during the coding/debug phase.
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Tue Nov 24 03:11:24 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 09:11:24 +0100
    Subject: Where to put the error handing test?
    In-Reply-To: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: <4b0b94fd$0$2717$426a74cc@news.free.fr>
    
    alex23 a ?crit :
    > On Nov 24, 1:15 pm, Peng Yu  wrote:
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    > 
    > What you should try to do is make each function as self-contained as
    > possible. f() shouldn't have to know what is a valid argument for g(),
    > that's the responsibility of g(). 
    
    There's no such clear-cut IMHO - it really depends on the context. If f 
    is a user-interface function - a function that deals with user inputs in 
    whatever form - and g is a domain-specific library function, then it's 
    f's responsability to validate user inputs before calling on g (_and_ of 
    course to deal with any exception raised withing g).
    
    As a general rule, "defensive code" should go at the interface level - 
    program's inputs of course, but also, sometimes, at "sub-systems" 
    boundaries.
    
    
    From paul.w.miller.please.dont.spam.me at wmich.edu  Tue Nov 24 04:31:28 2009
    From: paul.w.miller.please.dont.spam.me at wmich.edu (Paul Miller)
    Date: Tue, 24 Nov 2009 09:31:28 +0000 (UTC)
    Subject: Where to put the error handing test?
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: 
    
    On Mon, 23 Nov 2009 22:27:24 -0800, alex23 wrote:
    
    > As a very rough example:
    > 
    >     def g(x):
    >         try:
    >             assert isinstance(x, int)
    >         except AssertionError:
    >             raise TypeError, "excepted int, got %s" % type(x)
    >         # ... function code goes here
    > 
    >     def f(x):
    >         try:
    >             g(x)
    >         except TypeError:
    >             # handle the problem here
    >         # ... function code goes here
    
    I know you say this is a "very rough" example, but, generally you don't 
    want to do this kind of "type checking" with isinstance.  Rather, it's 
    better to just simply manipulate x as if it were an integer and rely on 
    Python to check to see if x supports the operations you're trying to do 
    with it.  For instance, say we have
    
    def g(x):
        return x * x
    
    def f(x):
        return g(x) + 2
    
    If you try to pass any value to either of these functions that doesn't 
    support the required operations, Python itself will complain with a 
    TypeError.  Since the interpreter needs to do this check *anyway*, 
    there's no real sense in repeating it manually by checking isinstance.
    
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 05:53:30 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 02:53:30 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    Message-ID: <9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    
    On 22 Nov, 22:38, Patrick Stinson 
    wrote:
    
    > Has anyone every tried wrapping the CPython lib into a daemon with an
    > RPC mechanism in order to move the GIL out of the process?
    
    > I imagine this is how the multiprocessing module works.
    
    It does not.
    
    
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 05:58:35 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 02:58:35 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> 
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de> 
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	
    Message-ID: 
    
    On 23 Nov, 22:02, Patrick Stinson 
    wrote:
    
    > What I meant was that I am *not allowed* to make calls to the CPython
    > API from the threads I currently have because these threads are high
    > priority and are never allowed to make blocking calls. Fortunately,
    > each of these threads can have a completely separate interpreter,
    
    This seems confused. What would they do with the interpreter if they
    cannot call the CPython API?
    
    
    > My question was whether or not anyone has done anything like this in
    > C/C++.
    
    I have programmed parallel numerical software in Python, including on-
    line signal processing. I have yet to find the GIL gets in my way.
    
    Usually people complaining about the GIL does not know what they are
    talking about.
    
    
    
    
    
    From davea at ieee.org  Tue Nov 24 05:58:42 2009
    From: davea at ieee.org (Dave Angel)
    Date: Tue, 24 Nov 2009 05:58:42 -0500
    Subject: Where to put the error handing test?
    In-Reply-To: <366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    References: 	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    Message-ID: <4B0BBC62.7020702@ieee.org>
    
    Peng Yu wrote:
    > On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    >   
    >> Peng Yu wrote:
    >>     
    >>> Suppose that I have function f() that calls g(), I can put a test on
    >>> the argument 'x' in either g() or f(). I'm wondering what is the
    >>> common practice.
    >>>
    >>> My thought is that if I put the test in g(x), the code of g(x) is
    >>> safer, but the test is not necessary when g() is called by h().
    >>>
    >>> If I put the test in f(), then g() becomes more efficient when other
    >>> code call g() and guarantee x will pass the test even though the test
    >>> code in not in g(). But there might be some caller of g() that pass an
    >>> 'x' that might not pass the test, if there were the test in g().
    >>>       
    >> Typically, you test for x as early as possible, e.g. just after user input
    >> (or file or url load or whatever). After that test, you can (or should be
    >> able to) assume that all function calls will always be called with the
    >> correct argument. This is the ideal situation, it's not always easy to do.
    >>
    >> In any case though, don't optimize early.
    >>     
    >
    > Let's suppose that g() is refactored out from f() and is call by not
    > only f() but other functions, and g() is likely to be called by new
    > functions.
    >
    > If I don't optimize early, I should put the test in g(), rather than f(), right?
    >
    >   
    Your question is so open-ended as to be unanswerable.  All we should do 
    in this case is supply some guidelines so you can guess which one might 
    apply in your particular case.
    
    You could be referring to a test that triggers alternate handling.  Or 
    you could be referring to a test that notices bad input by a user, or 
    bad data from an untrusted source.  Or you could be referring to a test 
    that discovers bugs in your code.  And there are variations of these, 
    depending on whether your user is also writing code (eval, or even 
    import of user-supplied mixins), etc.
    
    The first thing that's needed in the function g() is a docstring, 
    defining what inputs it expects, and what it'll do with them.  Then if 
    it gets any input that doesn't meet those requirements, it might throw 
    an exception.  Or it might just get an arbitrary result.  That's all up 
    to the docstring.  Without any documentation, nothing is correct.
    
    Functions that are only called by trusted code need not have explicit 
    tests on their inputs, since you're writing it all.  Part of debugging 
    is catching those cases where f () can pass bad data to g().  If it's 
    caused because bad data is passed to f(), then you have a bug in that 
    caller.  Eventually, you get to the user.  If the bad data comes from 
    the user, it should be caught as soon as possible, and feedback supplied 
    right then.
    
    assert() ought to be the correct way to add tests in g() that test 
    whether there's such a bug in f().  Unfortunately, in CPython it 
    defaults to debug mode, so scripts that are run will execute those tests 
    by default.  Consequently, people leave them out, to avoid slowing down 
    code.
    
    
    
    It comes down to trust.  If you throw the code together without a test 
    suite, you'll be a long time finding all the bugs in non-trivial code.  
    So add lots of defensive tests throughout the code, and pretend that's 
    equivalent to a good test system.  If you're writing a library to be 
    used by others, then define your public interfaces with exceptions for 
    any invalid code, and write careful documentation describing what's 
    invalid.  And if you're writing an end-user application, test their 
    input as soon as you get it, so none of the rest of the application ever 
    gets "invalid" data.
    
    
    DaveA
    
    
    From fetchinson at googlemail.com  Tue Nov 24 06:15:39 2009
    From: fetchinson at googlemail.com (Daniel Fetchinson)
    Date: Tue, 24 Nov 2009 12:15:39 +0100
    Subject: xmlrpc idea for getting around the GIL
    In-Reply-To: <6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com>
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com>
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de>
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	<6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com>
    Message-ID: 
    
    >> icating) the multiprocessing module would be ideal.
    >>> > The problem is that the OP has a embedded application running threads.
    >>> > multiprocssing doesn't help there.
    >>>
    >>> that's right. I cannot make CPython calls from my original C-based
    >>> threads.
    >>
    >>
    >> It's quite possible to do that.  A thread started from C can make
    >> calls to Python if it first calls PyGILState_Ensure, although you'd
    >> have to make sure that the Python interpreter has been previously
    >> initialized.  See PEP 311 for details.
    >>
    >> http://www.python.org/dev/peps/pep-0311/
    >>
    >> I also suggest that if you want people to be more receptive to write
    >> your replies after the quoted text.  That is the custom in this
    >> newsgroup/mailing list.
    >>
    >
    > What I meant was that I am *not allowed* to make calls to the CPython
    > API from the threads I currently have because these threads are high
    > priority and are never allowed to make blocking calls. Fortunately,
    > each of these threads can have a completely separate interpreter, so
    > my idea was to create a daemon process for each thread. This daemon
    > would contain the libpython symbols and would make the CPython calls.
    > This would keep my current threads from having to contend over the
    > single GIL.
    >
    > My question was whether or not anyone has done anything like this in
    > C/C++. This situation is slightly unique in that I am trying to
    > maintain separate interpreters within a single app (which is currently
    > kind of hacked out using a single interpreter, but it's ugly), but I
    > could see how this sort of thing would be useful for other C/C++ apps
    > that implement an embedded scripting engine.
    >
    > My reference to multiprocessing was based on the idea that the library
    > hides the details fo the process management, shared memory, and rpc
    > mechanisms. Again, I can't use multiprocessing because it runs *in*
    > python I need this to be implemented *outside* of python to avoid
    > acquiring the GIL. complex, I know.
    >
    > Naturally, the most intimidating part of perusing this kind of idea is
    > the overhead of the processess management and the RPC. Further,
    > libpython executes callable objects using C function pointers, and I
    > can't think of a way that this would be able to re-gain access to the
    > original app's respective functions if the interpreter was living in
    > another processes.
    >
    > That's not to mention the impossibility of debugging.
    >
    > Damn you, Gil.
    
    
    By the way, you might be interested in this thread as well:
    
    http://groups.google.com/group/comp.lang.python/browse_thread/thread/2d537ad8df9dab67/cc4cb2b493c98170
    
    HTH,
    Daniel
    
    
    -- 
    Psss, psss, put it down! - http://www.cafepress.com/putitdown
    
    
    From sturlamolden at yahoo.no  Tue Nov 24 06:29:29 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 03:29:29 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> 
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de> 
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	<6214d7a20911231302j5231b01fw4ca5416ac2773aa6@mail.gmail.com> 
    	
    Message-ID: <261ce8df-e152-4c1a-9da9-0994962da496@p36g2000vbn.googlegroups.com>
    
    On 24 Nov, 12:15, Daniel Fetchinson  wrote:
    
    > By the way, you might be interested in this thread as well:
    >
    > http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
    
    It is Windows specific, and it does not work with extension modules.
    
    Yes we can embed multiple interpreters just by making multiple copies
    of Python26.dll. It's an ugly hack and not one I'd recommend for
    production servers.
    
    
    
    
    From mrkafk at gmail.com  Tue Nov 24 07:03:44 2009
    From: mrkafk at gmail.com (mk)
    Date: Tue, 24 Nov 2009 13:03:44 +0100
    Subject: pointless musings on performance
    Message-ID: 
    
    #!/usr/local/bin/python
    
    import timeit
    
    
    def pythonic():
         nonevar = None
         zerovar = 0
         for x in range(1000000):
             if nonevar:
                 pass
             if zerovar:
                 pass
    
    def unpythonic():
         nonevar = None
         zerovar = 0
         for x in range(1000000):
             if nonevar is not None:
                 pass
             if zerovar > 0:
                 pass
    
    for f in [pythonic, unpythonic]:
         print f.func_name, timeit.timeit(f, number=10)
    
    
    
    # ./t.py
    pythonic 2.13092803955
    unpythonic 2.82064604759
    
    Decidedly counterintuitive: are there special optimizations for "if 
    nonevar:" type of statements in cpython implementation?
    
    
    regards,
    mk
    
    
    
    
    From python at mrabarnett.plus.com  Tue Nov 24 07:26:12 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Tue, 24 Nov 2009 12:26:12 +0000
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    Message-ID: <4B0BD0E4.8030707@mrabarnett.plus.com>
    
    mk wrote:
    > #!/usr/local/bin/python
    > 
    > import timeit
    > 
    > 
    > def pythonic():
    >     nonevar = None
    >     zerovar = 0
    >     for x in range(1000000):
    >         if nonevar:
    >             pass
    >         if zerovar:
    >             pass
    > 
    > def unpythonic():
    >     nonevar = None
    >     zerovar = 0
    >     for x in range(1000000):
    >         if nonevar is not None:
    >             pass
    >         if zerovar > 0:
    >             pass
    > 
    > for f in [pythonic, unpythonic]:
    >     print f.func_name, timeit.timeit(f, number=10)
    > 
    > 
    > 
    > # ./t.py
    > pythonic 2.13092803955
    > unpythonic 2.82064604759
    > 
    > Decidedly counterintuitive: are there special optimizations for "if 
    > nonevar:" type of statements in cpython implementation?
    > 
    In what way is it counterintuitive? In 'pythonic' the conditions are
    simpler, less work is being done, therefore it's faster.
    
    
    From rtw at freenet.co.uk  Tue Nov 24 07:31:37 2009
    From: rtw at freenet.co.uk (Rob Williscroft)
    Date: Tue, 24 Nov 2009 06:31:37 -0600
    Subject: pointless musings on performance
    References: 
    Message-ID: 
    
    mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in 
    comp.lang.python:
    
    > 
    > def pythonic():
     
    > def unpythonic():
     
     
    > Decidedly counterintuitive: are there special optimizations for "if 
    > nonevar:" type of statements in cpython implementation?
    > 
    
    from dis import dis
    
    dis( unpythonic )
    
    18          31 LOAD_FAST                0 (nonevar)
                 34 LOAD_CONST               0 (None)
                 37 COMPARE_OP               9 (is not)
                 40 JUMP_IF_FALSE            4 (to 47)
    
    dis( pythonic )
    
    11          31 LOAD_FAST                0 (nonevar)
                 34 JUMP_IF_FALSE            4 (to 41)
     
    Rob.
     
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 07:33:18 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 12:33:18 GMT
    Subject: Where to put the error handing test?
    References: 
    Message-ID: <031bc06f$0$1336$c3e8da3@news.astraweb.com>
    
    On Mon, 23 Nov 2009 21:15:48 -0600, Peng Yu wrote:
    
    > Suppose that I have function f() that calls g(), I can put a test on the
    > argument 'x' in either g() or f(). I'm wondering what is the common
    > practice.
    > 
    > My thought is that if I put the test in g(x), the code of g(x) is safer,
    > but the test is not necessary when g() is called by h().
    
    If the function g requires the test, then put it in g. If it does not 
    require the test, then don't put it in g.
    
    If the test is only required by f, then it belongs in f.
    
    
    
    -- 
    Steven
    
    
    From clp2 at rebertia.com  Tue Nov 24 07:43:50 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 04:43:50 -0800
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    	
    Message-ID: <50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft  wrote:
    > mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in
    > comp.lang.python:
    >
    >>
    >> def pythonic():
    >
    >> def unpythonic():
    >
    >
    >> Decidedly counterintuitive: are there special optimizations for "if
    >> nonevar:" type of statements in cpython implementation?
    >>
    >
    > from dis import dis
    >
    > dis( unpythonic )
    >
    > 18 ? ? ? ? ?31 LOAD_FAST ? ? ? ? ? ? ? ?0 (nonevar)
    > ? ? ? ? ? ? 34 LOAD_CONST ? ? ? ? ? ? ? 0 (None)
    > ? ? ? ? ? ? 37 COMPARE_OP ? ? ? ? ? ? ? 9 (is not)
    > ? ? ? ? ? ? 40 JUMP_IF_FALSE ? ? ? ? ? ?4 (to 47)
    >
    > dis( pythonic )
    >
    > 11 ? ? ? ? ?31 LOAD_FAST ? ? ? ? ? ? ? ?0 (nonevar)
    > ? ? ? ? ? ? 34 JUMP_IF_FALSE ? ? ? ? ? ?4 (to 41)
    
    In other words, CPython doesn't happen to optimize `if nonevar is not
    None` as much as it theoretically could (which would essentially
    require a JUMP_IF_NONE opcode). Since CPython isn't known for doing
    fancy optimizations, this isn't surprising.
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From Ron.Barak at lsi.com  Tue Nov 24 07:59:05 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 12:59:05 +0000
    Subject: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD05@enbmail01.lsi.com>
    
    Hi,
    
    I'm trying to add the logging module to my application, but I seem to be missing something.
    My application (a wxPython one) has a main script that calls various helper classes.
    I want the log messages from all modules to go to one central log file.
    
    When I implement logging, I think that due to preparation, I get the same message more than once.
    
    Here's an example:
    
    $ cat -n server.py
         1  import logging
         2  import logging.handlers
         3
         4  class Server():
         5      def __init__(self):
         6          self.client_logger = logging.getLogger("client")
         7          self.client_logger.setLevel(logging.DEBUG)
         8          h = logging.FileHandler("client.log")
         9          h.setLevel(logging.DEBUG)
        10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        11          h.setFormatter(formatter)
        12          self.client_logger.addHandler(h)
        13
        14      def util(self):
        15          self.client_logger.warning('This message comes from Server module')
    
    $ cat -n client.py
         1  import logging
         2  import logging.handlers
         3  from server import Server
         4
         5  class Client():
         6      def __init__(self):
         7          self.client_logger = logging.getLogger("client")
         8          self.client_logger.setLevel(logging.DEBUG)
         9          h = logging.FileHandler("client.log")
        10          h.setLevel(logging.DEBUG)
        11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        12          h.setFormatter(formatter)
        13          self.client_logger.addHandler(h)
        14
        15      def client_test(self):
        16          self.client_logger.warning("This message comes from Client module")
        17
        18  if __name__ == "__main__":
        19      ser = Server()
        20      cli = Client()
        21      ser.util()
        22      cli.client_test()
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    
    Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    
    Thanks,
    Ron.
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: image001.jpg
    Type: image/jpeg
    Size: 1512 bytes
    Desc: image001.jpg
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: image003.jpg
    Type: image/jpeg
    Size: 1650 bytes
    Desc: image003.jpg
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.log
    Type: application/octet-stream
    Size: 340 bytes
    Desc: client.log
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.py
    Type: application/octet-stream
    Size: 669 bytes
    Desc: client.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: server.py
    Type: application/octet-stream
    Size: 533 bytes
    Desc: server.py
    URL: 
    
    From helmert at informatik.uni-freiburg.de  Tue Nov 24 08:02:04 2009
    From: helmert at informatik.uni-freiburg.de (Malte Helmert)
    Date: Tue, 24 Nov 2009 14:02:04 +0100
    Subject: Any elegant way to construct the complete $k$-partite graph in
    	Python?
    In-Reply-To: 
    References: 				<45cc6ada-72ae-4353-8b2a-0ab7bf5e6112@1g2000vbm.googlegroups.com>
    	
    Message-ID: 
    
    Paul Miller wrote:
    > On Mon, 23 Nov 2009 19:57:05 -0800, Richard Thomas wrote:
    > 
    >> Not sure exactly how you're representing graphs, this seems like the
    >> simplest way of listing the edges.
    >>
    >> def complete_partite(*sizes):
    >>     total = sum(sizes)
    >>     nodes, edges = range(total), []
    >>     for group in xrange(len(sizes)):
    >>         low = sum(sizes[:group-1])
    >>         high = sum(sizes[:group])
    
    I think this has a conceptual off-by-one error. Add
    
               print group, low, high
    
    to see what I mean (especially the first iteration). It still works, but
    I think this would be clearer:
    
               low = sum(sizes[:group])
               high = sum(sizes[:group + 1])
    
    or to avoid doing essentially the same summation twice:
    
               low = sum(sizes[:group])
               high = low + sizes[group]
    
    >>         edges.extend((i, j) for i in xrange(low, high)
    >>                             for j in xrange(high, total))
    >>     return nodes, edges
    
    Here's a variant that uses a running total instead of recomputing the
    sum in every iteration, thus getting rid of xrange(len(...)).
    
    def complete_partite(*sizes):
        total = sum(sizes)
        nodes, edges = range(total), []
        curr_total = 0
        for size in sizes:
            edges.extend((i, j) for i in xrange(curr_total, curr_total+size)
                                for j in xrange(curr_total+size, total))
            curr_total += size
        return nodes, edges
    
    Finally, here is a variant that is a bit shorter because it produces the
    edges in a different way and hence gets rid of the need for knowing the
    total up front and uses total as running total instead. It has the
    drawback of not generating the edges in ascending order though, so I
    think the previous one is nicer:
    
    def complete_partite(*sizes):
        total, edges = 0, []
        for size in sizes:
            edges.extend((i, j) for i in xrange(total)
                                for j in xrange(total, total + size))
            total += size
        return range(total), edges
    
    Finally, here's a variation on the same theme:
    
    def complete_partite(*sizes):
        nodes, edges = [], []
        for size in sizes:
            partition = xrange(len(nodes), len(nodes) + size)
            edges.extend((i, j) for i in nodes for j in partition)
            nodes.extend(partition)
        return nodes, edges
    
    Malte
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 08:02:09 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 13:02:09 GMT
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    Message-ID: <031bc732$0$1336$c3e8da3@news.astraweb.com>
    
    On Mon, 23 Nov 2009 22:06:29 +0100, Alf P. Steinbach wrote:
    
    
    > 6. Googling, yes, it seems Thunderbird has a habit of "forgetting"
    > mails. But they're really there after all. It's just the index that's
    > screwed up.
    [...]
    > And I'm hesitant to just delete index file, hoping that it'll rebuild.
    
    Right-click on the mailbox and choose "Rebuild Index".
    
    If you're particularly paranoid, and you probably should be, make a 
    backup copy of the entire mail folder first.
    
    http://kb.mozillazine.org/Compacting_folders
    http://kb.mozillazine.org/Recover_messages_from_a_corrupt_folder
    http://kb.mozillazine.org/Disappearing_mail
    
    
    Good grief, it's about six weeks away from 2010 and Thunderbird still 
    uses mbox as it's default mail box format. Hello, the nineties called, 
    they want their mail formats back! Are the tbird developers on crack or 
    something? I can't believe that they're still using that crappy format.
    
    No, I tell a lie. I can believe it far too well.
    
    
    
    -- 
    Steven
    
    
    From __peter__ at web.de  Tue Nov 24 08:11:58 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 14:11:58 +0100
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<7n01t8F3jijv0U1@mid.uni-berlin.de>
    	
    	
    	<8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com>
    	
    Message-ID: 
    
    Terry Reedy wrote:
    
    > astral orange wrote:
    > 
    >> As far as the program. I did add print statements such as print
    >> (MyNames) and got back:
    >> 
    >> {'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}}
    > 
    > Hmmm, as I understood the code, either that should be ... 'last': {} ...
    > before the first store(), as you seem to be thinking below, or after the
    > first store(),
    > 
    > {'middle': {'Larry': ['John Larry Smith'],
    >   'last':   {'Smith': ['John Larry Smith'],
    >   'first':  {'John' " ['John Larry Smith']}
    > 
    > or the same with [['John','Larry','Smith']] for each entry (do not
    > remember exactly what was stored. Maybe a typo.
    
    That's a bug in the store() function
    
    # as posted
    def store(data, full_name):
        names = full_name.split()
        if len(names) == 2: names.insert(1, '')
        labels = 'first', 'middle', 'last'
        for label, name in zip(labels, names):
            people = lookup(data, label, name)
        if people:
            people.append(full_name)
        else:
            data[label][name] = [full_name]
    
    # what was probably intended
    def store(data, full_name):
        names = full_name.split()
        if len(names) == 2: names.insert(1, '')
        labels = 'first', 'middle', 'last'
        for label, name in zip(labels, names):
            people = lookup(data, label, name)
            if people:
                people.append(full_name)
            else:
                data[label][name] = [full_name]
    
    
    Peter
    
    
    
    From Ron.Barak at lsi.com  Tue Nov 24 08:17:05 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 13:17:05 +0000
    Subject: Recall: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD07@enbmail01.lsi.com>
    
    Barak, Ron would like to recall the message, "How to log messages _only once_ from all modules ?".
    
    From Ron.Barak at lsi.com  Tue Nov 24 08:20:43 2009
    From: Ron.Barak at lsi.com (Barak, Ron)
    Date: Tue, 24 Nov 2009 13:20:43 +0000
    Subject: How to log messages _only once_ from all modules ?
    Message-ID: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    
    Hi,
    
    I'm trying to add the logging module to my application, but I seem to be missing something.
    My application (a wxPython one) has a main script that calls various helper classes.
    I want the log messages from all modules to go to one central log file.
    
    When I implement logging, I think that due to preparation, I get the same message more than once.
    
    Here's an example:
    
    $ cat -n server.py
         1  import logging
         2  import logging.handlers
         3
         4  class Server():
         5      def __init__(self):
         6          self.client_logger = logging.getLogger("client")
         7          self.client_logger.setLevel(logging.DEBUG)
         8          h = logging.FileHandler("client.log")
         9          h.setLevel(logging.DEBUG)
        10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        11          h.setFormatter(formatter)
        12          self.client_logger.addHandler(h)
        13
        14      def util(self):
        15          self.client_logger.warning('This message comes from Server module')
    
    $ cat -n client.py
         1  import logging
         2  import logging.handlers
         3  from server import Server
         4
         5  class Client():
         6      def __init__(self):
         7          self.client_logger = logging.getLogger("client")
         8          self.client_logger.setLevel(logging.DEBUG)
         9          h = logging.FileHandler("client.log")
        10          h.setLevel(logging.DEBUG)
        11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
        12          h.setFormatter(formatter)
        13          self.client_logger.addHandler(h)
        14
        15      def client_test(self):
        16          self.client_logger.warning("This message comes from Client module")
        17
        18  if __name__ == "__main__":
        19      ser = Server()
        20      cli = Client()
        21      ser.util()
        22      cli.client_test()
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    
    Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    
    Thanks,
    Ron.
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: server.py
    Type: application/octet-stream
    Size: 533 bytes
    Desc: server.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.py
    Type: application/octet-stream
    Size: 669 bytes
    Desc: client.py
    URL: 
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: client.log
    Type: application/octet-stream
    Size: 340 bytes
    Desc: client.log
    URL: 
    
    From solipsis at pitrou.net  Tue Nov 24 08:31:45 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 13:31:45 +0000 (UTC)
    Subject: Go versus Brand X
    References: 
    	<3684716c-e817-46ae-93d3-d4fa30e5ed40@y28g2000prd.googlegroups.com>
    	
    	<7ms7ctF3k2a79U1@mid.individual.net> 
    	 
    	 
    	
    Message-ID: 
    
    Le Mon, 23 Nov 2009 15:30:16 -0600, Robert Kern a ?crit?:
    > particularly constrained environments like editors that may not be 
    > extensible at all.
    
    I'm not really an expert on this, but I think most good editors /are/ 
    extensible (through plugins, scripts or other things).
    
    > You can get away with just that and have something people recognize as
    > syntax highlighting, yes. But if it is possible to highlight local
    > variables, globals, and types differently, that *is* useful. And you
    > will even see some syntax highlighters doing more advanced things like
    > that even for Python (though mostly with heuristics).
    
    I suppose it's a matter of taste. I don't expect syntax highlighting to 
    do anything else than make the source code more readable and make some 
    important things stick out (comments, keywords etc.). It's probably the 
    same debate as text editor vs. full IDE. Users of text editors view 
    programming as a literary practice where they manipulate text, while 
    users of IDEs view programming as bringing technologies together through 
    specialized tools.
    
    Interestingly, we don't know how easy to parse Go is. We just have to 
    trust their word on that, but perhaps Python is easier to parse (while 
    being less ugly).
    
    
    
    From mrkafk at gmail.com  Tue Nov 24 08:41:19 2009
    From: mrkafk at gmail.com (mk)
    Date: Tue, 24 Nov 2009 14:41:19 +0100
    Subject: pointless musings on performance
    In-Reply-To: <4B0BD0E4.8030707@mrabarnett.plus.com>
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    Message-ID: 
    
    MRAB wrote:
    > In what way is it counterintuitive? In 'pythonic' the conditions are
    > simpler, less work is being done, therefore it's faster.
    
    But the pythonic condition is more general: nonevar or zerovar can be 
    '', 0, or None. So I thought it was more work for interpreter to compare 
    those, while I thought that "is not None" is translated to one, more 
    low-level and faster action. Apparently not.
    
    As Rob pointed out (thanks):
    
    11          31 LOAD_FAST                0 (nonevar)
                  34 JUMP_IF_FALSE            4 (to 41)
    
    I'm no good at py compiler or implementation internals and so I have no 
    idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    Regards,
    mk
    
    
    
    
    From bblais at bryant.edu  Tue Nov 24 08:42:04 2009
    From: bblais at bryant.edu (Brian Blais)
    Date: Tue, 24 Nov 2009 08:42:04 -0500
    Subject: xmlrpc idea for getting around the GIL
    In-Reply-To: 
    References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com>
    	
    	<7mtrf5F3h153dU1@mid.uni-berlin.de>
    	
    	<83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com>
    	
    	
    Message-ID: <78DF8A0D-9C1C-4ADD-8569-861DF31EC257@bryant.edu>
    
    On Nov 24, 2009, at 5:58 , sturlamolden wrote:
    
    > I have programmed parallel numerical software in Python, including on-
    > line signal processing. I have yet to find the GIL gets in my way.
    >
    > Usually people complaining about the GIL does not know what they are
    > talking about.
    >
    
    
    I'd love to know which tools/libraries/approach you have found most  
    profitable, and which were a waste of time.  Seems as if many people  
    feel the GIL gets in the way, but perhaps they've been trying methods  
    of parallelization that just aren't as effective.  What do you do?   
    Do you have any sample code?
    
    
    			bb
    
    
    -- 
    Brian Blais
    bblais at bryant.edu
    http://web.bryant.edu/~bblais
    
    
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From soltys at noabuse.com  Tue Nov 24 08:45:02 2009
    From: soltys at noabuse.com (Soltys)
    Date: Tue, 24 Nov 2009 14:45:02 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    Barak, Ron pisze:
    > Hi,
    > 
    > I'm trying to add the logging module to my application, but I seem to be missing something.
    > My application (a wxPython one) has a main script that calls various helper classes.
    > I want the log messages from all modules to go to one central log file.
    > 
    > When I implement logging, I think that due to preparation, I get the same message more than once.
    > 
    > Here's an example:
    > 
    > $ cat -n server.py
    >      1  import logging
    >      2  import logging.handlers
    >      3
    >      4  class Server():
    >      5      def __init__(self):
    >      6          self.client_logger = logging.getLogger("client")
    >      7          self.client_logger.setLevel(logging.DEBUG)
    >      8          h = logging.FileHandler("client.log")
    >      9          h.setLevel(logging.DEBUG)
    >     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >     11          h.setFormatter(formatter)
    >     12          self.client_logger.addHandler(h)
    >     13
    >     14      def util(self):
    >     15          self.client_logger.warning('This message comes from Server module')
    > 
    > $ cat -n client.py
    >      1  import logging
    >      2  import logging.handlers
    >      3  from server import Server
    >      4
    >      5  class Client():
    >      6      def __init__(self):
    >      7          self.client_logger = logging.getLogger("client")
    >      8          self.client_logger.setLevel(logging.DEBUG)
    >      9          h = logging.FileHandler("client.log")
    >     10          h.setLevel(logging.DEBUG)
    >     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >     12          h.setFormatter(formatter)
    >     13          self.client_logger.addHandler(h)
    >     14
    >     15      def client_test(self):
    >     16          self.client_logger.warning("This message comes from Client module")
    >     17
    >     18  if __name__ == "__main__":
    >     19      ser = Server()
    >     20      cli = Client()
    >     21      ser.util()
    >     22      cli.client_test()
    > $ rm client.log ; python client.py ; cat client.log
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > Googling and reading http://docs.python.org/library/logging.html didn't enlighten me.
    > 
    > Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    > 
    > Thanks,
    > Ron.
    > 
    > 
    
    Have a look at http://docs.python.org/library/logging.html#logger-objects
    First thing mentioned is Logger.propagate which is, what I believe, you're
    looking for ;)
    
    -- 
    Soltys
    
    "Free software is a matter of liberty not price"
    
    
    From rbarakx at gmail.com  Tue Nov 24 09:07:49 2009
    From: rbarakx at gmail.com (Ron Barak)
    Date: Tue, 24 Nov 2009 06:07:49 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    Message-ID: 
    
    On Nov 24, 3:45 pm, Soltys  wrote:
    > Barak, Ron pisze:
    >
    >
    >
    >
    >
    > > Hi,
    >
    > > I'm trying to add the logging module to my application, but I seem to be missing something.
    > > My application (a wxPython one) has a main script that calls various helper classes.
    > > I want the log messages from all modules to go to one central log file.
    >
    > > When I implement logging, I think that due to preparation, I get the same message more than once.
    >
    > > Here's an example:
    >
    > > $ cat -n server.py
    > >      1  import logging
    > >      2  import logging.handlers
    > >      3
    > >      4  class Server():
    > >      5      def __init__(self):
    > >      6          self.client_logger = logging.getLogger("client")
    > >      7          self.client_logger.setLevel(logging.DEBUG)
    > >      8          h = logging.FileHandler("client.log")
    > >      9          h.setLevel(logging.DEBUG)
    > >     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >     11          h.setFormatter(formatter)
    > >     12          self.client_logger.addHandler(h)
    > >     13
    > >     14      def util(self):
    > >     15          self.client_logger.warning('This message comes from Server module')
    >
    > > $ cat -n client.py
    > >      1  import logging
    > >      2  import logging.handlers
    > >      3  from server import Server
    > >      4
    > >      5  class Client():
    > >      6      def __init__(self):
    > >      7          self.client_logger = logging.getLogger("client")
    > >      8          self.client_logger.setLevel(logging.DEBUG)
    > >      9          h = logging.FileHandler("client.log")
    > >     10          h.setLevel(logging.DEBUG)
    > >     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >     12          h.setFormatter(formatter)
    > >     13          self.client_logger.addHandler(h)
    > >     14
    > >     15      def client_test(self):
    > >     16          self.client_logger.warning("This message comes from Client module")
    > >     17
    > >     18  if __name__ == "__main__":
    > >     19      ser = Server()
    > >     20      cli = Client()
    > >     21      ser.util()
    > >     22      cli.client_test()
    > > $ rm client.log ; python client.py ; cat client.log
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > > 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > > Googling and readinghttp://docs.python.org/library/logging.htmldidn't enlighten me.
    >
    > > Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    >
    > > Thanks,
    > > Ron.
    >
    > Have a look athttp://docs.python.org/library/logging.html#logger-objects
    > First thing mentioned is Logger.propagate which is, what I believe, you're
    > looking for ;)
    >
    > --
    > Soltys
    >
    > "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > - Show quoted text -
    
    Hi Soltys,
    I actually tried that, without any noticeable effects, viz.:
    
    $ cat server.py
    import logging
    import logging.handlers
    
    class Server():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
            self.client_logger.propagate = 0
    
        def util(self):
            self.client_logger.warning('This message comes from Server
    module')
    
    $ cat client.py
    import logging
    import logging.handlers
    from server import Server
    
    class Client():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
            self.client_logger.propagate = 0
    
        def client_test(self):
            self.client_logger.warning("This message comes from Client
    module")
    
    if __name__ == "__main__":
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Server module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Server module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Client module
    2009-11-24 16:06:35,710 client       WARNING  This message comes from
    Client module
    
    $
    
    
    
    From neilc at norwich.edu  Tue Nov 24 09:20:59 2009
    From: neilc at norwich.edu (Neil Cerutti)
    Date: 24 Nov 2009 14:20:59 GMT
    Subject: Line-continuation "Anti-Idiom" and with statement
    References: <7n0578F3j7qa6U1@mid.individual.net>
    	
    Message-ID: <7n28ebF3k2ba7U1@mid.individual.net>
    
    On 2009-11-23, Terry Reedy  wrote:
    > Neil Cerutti wrote:
    >> Unfortunately, the new "nested" with statement (which I also read
    >> about today) forces me into this anti-idiom. When replacing an
    >> appearance of contextlib.nested with the 3K with statement, I
    >> ended up with an unexpected syntax error.
    >> 
    >> with (open(roster_path, 'r') as roster_file,
    >>       open(disb_path, 'w') as out_file,
    >>       open(report_path, 'w') as report_file):
    >> 
    >> The result was:
    >> 
    >>   File "C:\project\codxml.py", line 184
    >>     with (open(roster_path, 'r') as roster_file,
    >>                                   ^
    >> SyntaxError: invalid syntax
    >
    > Right. The first open paren is illegal.
    >
    > I believe that '\ \n' would always be harmless or a SyntexError
    > outside of expressons. I believe 'subtly wrong' only applies
    > within expressions. 
    >
    > So I would not call \ continuation an anti-pattern outside
    > expressions. So you might suggest that the whole entry specify
    > expression context to begin with. To me, your example shows why
    > blanket condemnation is wrong.
    >
    > The HOWTOs are not scripture.
    
    I like your suggestion. Changing the title of the anti-idiom to
    "Using Backslash to Continue Expressions" seems like a good fix.
    I submitted it as issue 7391.
    
    I've done a search of the PEP's, Python-Dev, and Python-Ideas,
    but I couldn't find much official discussion. The change was made
    because contextlib.nested was not semantically equivalent to
    actual nested with statments.
    
    GvR noted in Python Ideas that he liked the idea of making the
    new syntax parallel to the import statement sytax variant:
    
    "import" module  ["as" name] ( ", " ["as" name] )*
    
    So that's where the 'multi-with' statement found its model.
    
    -- 
    Neil Cerutti
    
    
    From gh at ghaering.de  Tue Nov 24 09:35:08 2009
    From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=)
    Date: Tue, 24 Nov 2009 15:35:08 +0100
    Subject: IDE+hg
    In-Reply-To: 
    References: 
    	
    Message-ID: 
    
    Rhodri James wrote:
    > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    > 
    >> Dear experts,
    >> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    >> Mercurial support not found i.e. buttons to clone, commit and push to
    >> repositories to define dev env dvcs, editor and deployment all in 1.
    > 
    > I don't really understand this urge to cram everything into a single
    > program, since that inevitably leads to compromises that will compromise
    > just how much of Mercurial's useful and interesting functionality you
    > can get at.  Still, if you really must, Emacs (and presumably vim) seems
    > to be capable of working with most source control systems.
    
    I prefer the commandline tools, too.
    
    FWIW, Eclipse supports Mercurial through
    http://www.vectrace.com/mercurialeclipse/
    
    -- Gerhard
    
    
    
    
    From rtw at freenet.co.uk  Tue Nov 24 09:44:24 2009
    From: rtw at freenet.co.uk (Rob Williscroft)
    Date: Tue, 24 Nov 2009 08:44:24 -0600
    Subject: pointless musings on performance
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    	
    Message-ID: 
    
    mk wrote in news:mailman.923.1259070092.2873.python-list at python.org in 
    comp.lang.python:
    
    > MRAB wrote:
    >> In what way is it counterintuitive? In 'pythonic' the conditions are
    >> simpler, less work is being done, therefore it's faster.
    > 
    > But the pythonic condition is more general: nonevar or zerovar can be 
    > '', 0, or None. So I thought it was more work for interpreter to compare 
    > those, while I thought that "is not None" is translated to one, more 
    > low-level and faster action. Apparently not.
    > 
    > As Rob pointed out (thanks):
    > 
    > 11          31 LOAD_FAST                0 (nonevar)
    >               34 JUMP_IF_FALSE            4 (to 41)
    > 
    > I'm no good at py compiler or implementation internals and so I have no 
    > idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    IIUC it implements:
    
    http://docs.python.org/3.1/reference/expressions.html#boolean-operations
    
    "In the context of Boolean operations, and also when expressions are used 
    by control flow statements, the following values are interpreted as false: 
    False, None, numeric zero of all types, and empty strings and containers 
    (including strings, tuples, lists, dictionaries, sets and frozensets). All 
    other values are interpreted as true. User-defined objects can customize 
    their truth value by providing a __bool__() method."
    
    In particular its implementing "... Boolean operation ... used by 
    control flow ...", all in one handy op code.
    
    Rob.
    
    
    From soltys at noabuse.com  Tue Nov 24 10:08:09 2009
    From: soltys at noabuse.com (Soltys)
    Date: Tue, 24 Nov 2009 16:08:09 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: 
    References: 
    	
    	
    Message-ID: 
    
    Ron Barak pisze:
    > On Nov 24, 3:45 pm, Soltys  wrote:
    >> Barak, Ron pisze:
    >>
    >>
    >>
    >>
    >>
    >>> Hi,
    >>> I'm trying to add the logging module to my application, but I seem to be missing something.
    >>> My application (a wxPython one) has a main script that calls various helper classes.
    >>> I want the log messages from all modules to go to one central log file.
    >>> When I implement logging, I think that due to preparation, I get the same message more than once.
    >>> Here's an example:
    >>> $ cat -n server.py
    >>>      1  import logging
    >>>      2  import logging.handlers
    >>>      3
    >>>      4  class Server():
    >>>      5      def __init__(self):
    >>>      6          self.client_logger = logging.getLogger("client")
    >>>      7          self.client_logger.setLevel(logging.DEBUG)
    >>>      8          h = logging.FileHandler("client.log")
    >>>      9          h.setLevel(logging.DEBUG)
    >>>     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >>>     11          h.setFormatter(formatter)
    >>>     12          self.client_logger.addHandler(h)
    >>>     13
    >>>     14      def util(self):
    >>>     15          self.client_logger.warning('This message comes from Server module')
    >>> $ cat -n client.py
    >>>      1  import logging
    >>>      2  import logging.handlers
    >>>      3  from server import Server
    >>>      4
    >>>      5  class Client():
    >>>      6      def __init__(self):
    >>>      7          self.client_logger = logging.getLogger("client")
    >>>      8          self.client_logger.setLevel(logging.DEBUG)
    >>>      9          h = logging.FileHandler("client.log")
    >>>     10          h.setLevel(logging.DEBUG)
    >>>     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    >>>     12          h.setFormatter(formatter)
    >>>     13          self.client_logger.addHandler(h)
    >>>     14
    >>>     15      def client_test(self):
    >>>     16          self.client_logger.warning("This message comes from Client module")
    >>>     17
    >>>     18  if __name__ == "__main__":
    >>>     19      ser = Server()
    >>>     20      cli = Client()
    >>>     21      ser.util()
    >>>     22      cli.client_test()
    >>> $ rm client.log ; python client.py ; cat client.log
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    >>> Googling and readinghttp://docs.python.org/library/logging.htmldidn't enlighten me.
    >>> Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    >>> Thanks,
    >>> Ron.
    >> Have a look athttp://docs.python.org/library/logging.html#logger-objects
    >> First thing mentioned is Logger.propagate which is, what I believe, you're
    >> looking for ;)
    >>
    >> --
    >> Soltys
    >>
    >> "Free software is a matter of liberty not price"- Hide quoted text -
    >>
    >> - Show quoted text -
    > 
    > Hi Soltys,
    > I actually tried that, without any noticeable effects, viz.:
    > 
    > $ cat server.py
    > import logging
    > import logging.handlers
    > 
    > class Server():
    >     def __init__(self):
    >         self.client_logger = logging.getLogger("client")
    >         self.client_logger.setLevel(logging.DEBUG)
    >         h = logging.FileHandler("client.log")
    >         h.setLevel(logging.DEBUG)
    >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > (levelname)-8s %(message)s")
    >         h.setFormatter(formatter)
    >         self.client_logger.addHandler(h)
    >         self.client_logger.propagate = 0
    > 
    >     def util(self):
    >         self.client_logger.warning('This message comes from Server
    > module')
    > 
    > $ cat client.py
    > import logging
    > import logging.handlers
    > from server import Server
    > 
    > class Client():
    >     def __init__(self):
    >         self.client_logger = logging.getLogger("client")
    >         self.client_logger.setLevel(logging.DEBUG)
    >         h = logging.FileHandler("client.log")
    >         h.setLevel(logging.DEBUG)
    >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > (levelname)-8s %(message)s")
    >         h.setFormatter(formatter)
    >         self.client_logger.addHandler(h)
    >         self.client_logger.propagate = 0
    > 
    >     def client_test(self):
    >         self.client_logger.warning("This message comes from Client
    > module")
    > 
    > if __name__ == "__main__":
    >     ser = Server()
    >     cli = Client()
    >     ser.util()
    >     cli.client_test()
    > 
    > $ rm client.log ; python client.py ; cat client.log
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Server module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Server module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Client module
    > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > Client module
    > 
    > $
    > 
    
    Rename logger in server.py to server:
    self.client_logger = logging.getLogger("server")
    
    Rerun, you should get sth. like this:
    $ cat client.log
    2009-11-24 16:06:54,990 server       WARNING  This message comes from Server module
    2009-11-24 16:06:54,990 client       WARNING  This message comes from Client module
    
    
    
    -- 
    Soltys
    
    "Free software is a matter of liberty not price"
    
    
    From solipsis at pitrou.net  Tue Nov 24 10:11:29 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 15:11:29 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    Message-ID: 
    
    
    Hello,
    
    Le Tue, 24 Nov 2009 14:41:19 +0100, mk a ?crit?:
    > 
    > As Rob pointed out (thanks):
    > 
    > 11          31 LOAD_FAST                0 (nonevar)
    >               34 JUMP_IF_FALSE            4 (to 41)
    > 
    > I'm no good at py compiler or implementation internals and so I have no
    > idea what bytecode "JUMP_IF_FALSE" is actually doing.
    
    It tries to evaluate the op of the stack (here nonevar) in a boolean 
    context (which theoretically involves calling __nonzero__ on the type) 
    and then jumps if the result is False (rather than True).
    
    You are totally right that it does /more/ than "is not None", but since 
    it is executed as a single opcode rather than a sequence of several 
    opcodes, the additional work it has to do is compensated (in this case) 
    by the smaller overhead in bytecode interpretation.
    
    As someone pointed out, the Python interpreter could grow CISC-like 
    opcodes so as to collapse "is not None" (or generically "is not 
    ") into a single JUMP_IF_IS_NOT_CONST opcode. Actually, it is 
    the kind of optimizations wpython does (http://code.google.com/p/
    wpython/).
    
    Regards
    
    Antoine.
    
    
    
    From rileyrgdev at gmail.com  Tue Nov 24 10:13:27 2009
    From: rileyrgdev at gmail.com (Richard Riley)
    Date: Tue, 24 Nov 2009 16:13:27 +0100
    Subject: IDE+hg
    References: 
    	
    	
    Message-ID: 
    
    Gerhard H?ring  writes:
    
    > Rhodri James wrote:
    >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >> 
    >>> Dear experts,
    >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    >>> Mercurial support not found i.e. buttons to clone, commit and push to
    >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >> 
    >> I don't really understand this urge to cram everything into a single
    >> program, since that inevitably leads to compromises that will
    >> compromise
    
    Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    merely programmed to hook into the external tools
    
    >> just how much of Mercurial's useful and interesting functionality you
    >> can get at.  Still, if you really must, Emacs (and presumably vim) seems
    >> to be capable of working with most source control systems.
    >
    > I prefer the commandline tools, too.
    >
    > FWIW, Eclipse supports Mercurial through
    > http://www.vectrace.com/mercurialeclipse/
    >
    > -- Gerhard
    
    Why would you prefer the command line tools in a shell when the same
    tools can be used in a way which makes navigating the output so much
    easier? It strikes me as a kind of intransigence. it's a common
    misconception that IDEs use their own tools all the time. They
    don't. They integrate the very same tools. e.g Why the hell would I drop
    to a command line to diff a file with a back version in GIT when I can
    do the same in the buffer in emacs with a single hot key? Why would I
    pipe the output of compile into a file then open that file when a single
    hot key can fire off the SAME compiler and then list the errors in an
    emacs buffer and another hot key can take me directly to the source
    lines in question? Living in the past has its mements, but really.
    
    e.g I have pylint working live in python buffers. Big time
    saver. Similar with C.
    
    
    From solipsis at pitrou.net  Tue Nov 24 10:13:29 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 15:13:29 +0000 (UTC)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 02:53:30 -0800, sturlamolden a ?crit?:
    > On 22 Nov, 22:38, Patrick Stinson 
    > wrote:
    > 
    >> Has anyone every tried wrapping the CPython lib into a daemon with an
    >> RPC mechanism in order to move the GIL out of the process?
    > 
    >> I imagine this is how the multiprocessing module works.
    > 
    > It does not.
    
    Actually, it is how multiprocessing works under Windows (for lack of the 
    fork() function), except that it uses pickle by default (but it does have 
    xmlrpc support).
    
    Regards
    
    Antoine.
    
    
    
    
    From rbarakx at gmail.com  Tue Nov 24 10:14:56 2009
    From: rbarakx at gmail.com (Ron Barak)
    Date: Tue, 24 Nov 2009 07:14:56 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    	
    	
    Message-ID: <9750596d-4d09-478a-a9df-942e44a4e83a@t18g2000vbj.googlegroups.com>
    
    On Nov 24, 5:08 pm, Soltys  wrote:
    > Ron Barak pisze:
    >
    >
    >
    >
    >
    > > On Nov 24, 3:45 pm, Soltys  wrote:
    > >> Barak, Ron pisze:
    >
    > >>> Hi,
    > >>> I'm trying to add the logging module to my application, but I seem to be missing something.
    > >>> My application (a wxPython one) has a main script that calls various helper classes.
    > >>> I want the log messages from all modules to go to one central log file.
    > >>> When I implement logging, I think that due to preparation, I get the same message more than once.
    > >>> Here's an example:
    > >>> $ cat -n server.py
    > >>>      1  import logging
    > >>>      2  import logging.handlers
    > >>>      3
    > >>>      4  class Server():
    > >>>      5      def __init__(self):
    > >>>      6          self.client_logger = logging.getLogger("client")
    > >>>      7          self.client_logger.setLevel(logging.DEBUG)
    > >>>      8          h = logging.FileHandler("client.log")
    > >>>      9          h.setLevel(logging.DEBUG)
    > >>>     10          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >>>     11          h.setFormatter(formatter)
    > >>>     12          self.client_logger.addHandler(h)
    > >>>     13
    > >>>     14      def util(self):
    > >>>     15          self.client_logger.warning('This message comes from Server module')
    > >>> $ cat -n client.py
    > >>>      1  import logging
    > >>>      2  import logging.handlers
    > >>>      3  from server import Server
    > >>>      4
    > >>>      5  class Client():
    > >>>      6      def __init__(self):
    > >>>      7          self.client_logger = logging.getLogger("client")
    > >>>      8          self.client_logger.setLevel(logging.DEBUG)
    > >>>      9          h = logging.FileHandler("client.log")
    > >>>     10          h.setLevel(logging.DEBUG)
    > >>>     11          formatter = logging.Formatter("%(asctime)s %(name)-12s %(levelname)-8s %(message)s")
    > >>>     12          h.setFormatter(formatter)
    > >>>     13          self.client_logger.addHandler(h)
    > >>>     14
    > >>>     15      def client_test(self):
    > >>>     16          self.client_logger.warning("This message comes from Client module")
    > >>>     17
    > >>>     18  if __name__ == "__main__":
    > >>>     19      ser = Server()
    > >>>     20      cli = Client()
    > >>>     21      ser.util()
    > >>>     22      cli.client_test()
    > >>> $ rm client.log ; python client.py ; cat client.log
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Server module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > >>> 2009-11-24 14:40:39,762 client       WARNING  This message comes from Client module
    > >>> Googling and readinghttp://docs.python.org/library/logging.htmldidn'tenlighten me.
    > >>> Could you suggest what should I change in the above scripts so that the log messages would appear only once ?
    > >>> Thanks,
    > >>> Ron.
    > >> Have a look athttp://docs.python.org/library/logging.html#logger-objects
    > >> First thing mentioned is Logger.propagate which is, what I believe, you're
    > >> looking for ;)
    >
    > >> --
    > >> Soltys
    >
    > >> "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > >> - Show quoted text -
    >
    > > Hi Soltys,
    > > I actually tried that, without any noticeable effects, viz.:
    >
    > > $ cat server.py
    > > import logging
    > > import logging.handlers
    >
    > > class Server():
    > >     def __init__(self):
    > >         self.client_logger = logging.getLogger("client")
    > >         self.client_logger.setLevel(logging.DEBUG)
    > >         h = logging.FileHandler("client.log")
    > >         h.setLevel(logging.DEBUG)
    > >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > > (levelname)-8s %(message)s")
    > >         h.setFormatter(formatter)
    > >         self.client_logger.addHandler(h)
    > >         self.client_logger.propagate = 0
    >
    > >     def util(self):
    > >         self.client_logger.warning('This message comes from Server
    > > module')
    >
    > > $ cat client.py
    > > import logging
    > > import logging.handlers
    > > from server import Server
    >
    > > class Client():
    > >     def __init__(self):
    > >         self.client_logger = logging.getLogger("client")
    > >         self.client_logger.setLevel(logging.DEBUG)
    > >         h = logging.FileHandler("client.log")
    > >         h.setLevel(logging.DEBUG)
    > >         formatter = logging.Formatter("%(asctime)s %(name)-12s %
    > > (levelname)-8s %(message)s")
    > >         h.setFormatter(formatter)
    > >         self.client_logger.addHandler(h)
    > >         self.client_logger.propagate = 0
    >
    > >     def client_test(self):
    > >         self.client_logger.warning("This message comes from Client
    > > module")
    >
    > > if __name__ == "__main__":
    > >     ser = Server()
    > >     cli = Client()
    > >     ser.util()
    > >     cli.client_test()
    >
    > > $ rm client.log ; python client.py ; cat client.log
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Server module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Server module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Client module
    > > 2009-11-24 16:06:35,710 client       WARNING  This message comes from
    > > Client module
    >
    > > $
    >
    > Rename logger in server.py to server:
    > self.client_logger = logging.getLogger("server")
    >
    > Rerun, you should get sth. like this:
    > $ cat client.log
    > 2009-11-24 16:06:54,990 server       WARNING  This message comes from Server module
    > 2009-11-24 16:06:54,990 client       WARNING  This message comes from Client module
    >
    > --
    > Soltys
    >
    > "Free software is a matter of liberty not price"- Hide quoted text -
    >
    > - Show quoted text -
    
    Many thanks Soltys, that did the trick (actually, no need for setting
    propagate to 0), namely,
    
    $ cat client.py
    import logging
    import logging.handlers
    from server import Server
    
    class Client():
        def __init__(self):
            self.client_logger = logging.getLogger("client")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
    
        def client_test(self):
            self.client_logger.warning("This message comes from Client
    module")
    
    if __name__ == "__main__":
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    $ cat server.py
    import logging
    import logging.handlers
    
    class Server():
        def __init__(self):
            self.client_logger = logging.getLogger("server")
            self.client_logger.setLevel(logging.DEBUG)
            h = logging.FileHandler("client.log")
            h.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s %(name)-12s %
    (levelname)-8s %(message)s")
            h.setFormatter(formatter)
            self.client_logger.addHandler(h)
    
        def util(self):
            self.client_logger.warning('This message comes from Server
    module')
    
    $ rm client.log ; python client.py ; cat client.log
    2009-11-24 17:13:15,989 server       WARNING  This message comes from
    Server module
    2009-11-24 17:13:15,989 client       WARNING  This message comes from
    Client module
    
    
    
    From 457r0.jp at gmail.com  Tue Nov 24 10:45:00 2009
    From: 457r0.jp at gmail.com (astral orange)
    Date: Tue, 24 Nov 2009 07:45:00 -0800 (PST)
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    Message-ID: 
    
    On Nov 23, 10:37?pm, r  wrote:
    > On Nov 23, 11:19?am, astral orange <457r0... at gmail.com> wrote:
    >
    >
    >
    > > Hi, I am trying to teach myself Python and have a good book to help me
    > > but I am stuck on something and I would like for someone to explain
    > > the following piece of code for me and what it's actually doing.
    > > Certain parts are very clear but once it enters the "def store(data,
    > > full_name): ...." function and the "def lookup()..." function things
    > > get a little confusing for me. Specifically, lines 103-108 *and* Lines
    > > 110-111.
    >
    > > Lastly, I am not sure how to print the results I've put into this
    > > program either, the book I'm reading doesn't tell me. As you can tell,
    > > I am a beginner and I don't truly understand everything that is going
    > > on here...a lot, but not all....
    >
    > > Here is the code:
    >
    > > ?92 def init(data):
    > > ?93 ? ? data['first'] = {}
    > > ?94 ? ? data['middle'] = {}
    > > ?95 ? ? data['last'] = {}
    > > ?96
    > > ?97 def store(data, full_name):
    > > ?98 ? ? names = full_name.split()
    > > 100 ? ? if len(names) == 2: names.insert(1, '')
    > > 101 ? ? labels = 'first', 'middle', 'last'
    > > 103 ? ? for label, name in zip(labels, names):
    > > 104 ? ? ? ? people = lookup(data, label, name)
    > > 105 ? ? if people:
    > > 106 ? ? ? ? people.append(full_name)
    > > 107 ? ? else:
    > > 108 ? ? ? ? data[label][name] = [full_name]
    > > 109
    > > 110 def lookup(data, label, name):
    > > 111 ? ? return data[label].get(name)
    > > 112
    > > 113
    > > 114 MyNames = {}
    > > 115 init(MyNames)
    > > 116 store(MyNames, 'John Larry Smith')
    > > 117 lookup(MyNames, 'middle', 'Smith')
    >
    > This is a horrible example to show noobs. I think the OP could better
    > understand this as a class EVEN though the OP may or may not know what
    > a class *is* yet.
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    >
    > >>> name1 = Name('Guido', 'van', 'Rossum')
    > >>> name1.first
    > 'Guido'
    > >>> name1.middle
    > 'van'
    > >>> name1.last
    > 'Rossum'
    > >>> print name1
    >
    > <__main__.Name instance at 0x029BFD78>
    >
    > This time we add a __str__ method, the result will speak louder than
    > words!!
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    > ? ? ? ? def __str__(self):
    > ? ? ? ? ? ? ? ? return '%s %s %s' %(self.first, self.middle, self.last)
    >
    > >>> name2 = Name('Terry', 'J', 'Reedy')
    > >>> name2.first
    > 'Terry'
    > >>> name2.middle
    > 'J'
    > >>> name2.last
    > 'Reedy'
    > >>> print name2
    >
    > Terry J Reedy
    >
    > See the difference in the print statements. Now lets have some real
    > fun and access each sub name by index haha!
    >
    > >>> class Name():
    >
    > ? ? ? ? def __init__(self, first, middle, last):
    > ? ? ? ? ? ? ? ? self.first = first
    > ? ? ? ? ? ? ? ? self.middle = middle
    > ? ? ? ? ? ? ? ? self.last = last
    > ? ? ? ? def __str__(self):
    > ? ? ? ? ? ? ? ? return '%s %s %s' %(self.first, self.middle, self.last)
    > ? ? ? ? def __len__(self):
    > ? ? ? ? ? ? ? ? return 3
    > ? ? ? ? def __getitem__(self, item):
    > ? ? ? ? ? ? ? ? if item == 0:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.first
    > ? ? ? ? ? ? ? ? elif item == 1:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.middle
    > ? ? ? ? ? ? ? ? elif item == 2:
    > ? ? ? ? ? ? ? ? ? ? ? ? return self.last
    > ? ? ? ? ? ? ? ? else:
    > ? ? ? ? ? ? ? ? ? ? ? ? raise IndexError("Index must be in range 0, 2")
    >
    > >>> name = Name('Joe', 'blow', 'scripter')
    > >>> name[0]
    > 'Joe'
    > >>> name[1]
    > 'blow'
    > >>> name[2]
    > 'scripter'
    > >>> len(name)
    >
    > 3
    >
    > WOW, thats more info in a few lines than any tut i ever seen! I wish i
    > could have seen that in my initial days, could have save some
    > countless hours of confusion!!! Maybe i am in the wrong line of work?
    >
    > Should i keep going...?
    
    Yeah, I don't think the example in the book is the best for someone
    starting out. I still
    am "not getting" certain parts of the program so I think I'll move on
    in hopes that it will
    *not* came back to haunt me and the book (along with the online
    tutorial) will help me grab
    more of the basics of Python programming.
    
    As for the "class Name():" example above? Even though I haven't seen
    exactly what purpose 'self' serves
    yet I can follow and understand what is going on very easily, that
    helps out tremendously.
    Very clearly written...Thank you!
    
    And thanks again to everyone...
    
    
    From marcu.nicolae at gmail.com  Tue Nov 24 10:47:40 2009
    From: marcu.nicolae at gmail.com (NMarcu)
    Date: Tue, 24 Nov 2009 07:47:40 -0800 (PST)
    Subject: Need help to understand a getattr syntax.
    Message-ID: <5b2a9e74-2958-4f54-bdea-0075c2ebcc32@o31g2000vbi.googlegroups.com>
    
    Hello all,
        I need some help to understand a getattr syntax. The syntax is:
    
    try:
        getattr(self, command)(cursor, row)
    except Exception, e:
        print "Action failed : '%s'" % command
        raise e
    
    I don't understand why is not like this: a = getattr(), and what are
    the scope of the second (): (cursor, row)
    
    Thanks.
    
    
    From pengyu.ut at gmail.com  Tue Nov 24 10:47:58 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 09:47:58 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    References: 
    	<617ab253-81f5-4c6f-b6f9-d5f59906a3a9@b25g2000prb.googlegroups.com>
    Message-ID: <366c6f340911240747k5e55fea5kb63f603c5baa5268@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 12:27 AM, alex23  wrote:
    > On Nov 24, 1:15?pm, Peng Yu  wrote:
    >> Suppose that I have function f() that calls g(), I can put a test on
    >> the argument 'x' in either g() or f(). I'm wondering what is the
    >> common practice.
    >>
    >> If I put the test in f(), then g() becomes more efficient when other
    >> code call g() and guarantee x will pass the test even though the test
    >> code in not in g(). But there might be some caller of g() that pass an
    >> 'x' that might not pass the test, if there were the test in g().
    >
    > What you should try to do is make each function as self-contained as
    > possible. f() shouldn't have to know what is a valid argument for g(),
    > that's the responsibility of g(). What f() needs to know is how to
    > deal with any problems that arise while using g().
    
    This may not always be possible, because g() might call a third party
    software, that I don't have the complete knowledge of. What would you
    do if this case?
    
    Another scenario:
    
    Suppose that f_1(),...,f_(), g() are in a package, where g() is an
    internal function that the end users are not suppose to call, and
    f_1(),...,f_() are the functions that the end users may call.
    
    Since all the f_1 ... f_ functions knows g(), they can be
    programmed to guarantee not to pass any arguments that can not be
    handled by g(). In this case, I think it is reasonable to move the
    test code from g()? Is it the general accepted practice?
    
    > As a very rough example:
    >
    > ? ?def g(x):
    > ? ? ? ?try:
    > ? ? ? ? ? ?assert isinstance(x, int)
    > ? ? ? ?except AssertionError:
    > ? ? ? ? ? ?raise TypeError, "excepted int, got %s" % type(x)
    > ? ? ? ?# ... function code goes here
    >
    > ? ?def f(x):
    > ? ? ? ?try:
    > ? ? ? ? ? ?g(x)
    > ? ? ? ?except TypeError:
    > ? ? ? ? ? ?# handle the problem here
    > ? ? ? ?# ... function code goes here
    >
    >> My thought is that if I put the test in g(x), the code of g(x) is
    >> safer, but the test is not necessary when g() is called by h().
    >
    > This sounds strange to me. Are you stating that h() can pass values to
    > g() that would be illegal for f() to pass? That sounds like a very
    > dangerous design...you want each function's behaviour to be as
    > consistent and predictable as it possibly can.
    
    You misunderstood me.
    
    h() doesn't pass any illegal arguments to g(). If I put the test code
    in g(), it would be a waste of run time when h() calls g(). In this
    case, and under the condition that g() is an internal function of a
    package as I mentioned above, I think I should move the test code from
    g() to f(). What do you think?
    
    
    From deets at nospam.web.de  Tue Nov 24 10:51:55 2009
    From: deets at nospam.web.de (Diez B. Roggisch)
    Date: Tue, 24 Nov 2009 16:51:55 +0100
    Subject: Need help to understand a getattr syntax.
    References: <5b2a9e74-2958-4f54-bdea-0075c2ebcc32@o31g2000vbi.googlegroups.com>
    Message-ID: <7n2dorF3jv2q5U1@mid.uni-berlin.de>
    
    NMarcu wrote:
    
    > Hello all,
    >     I need some help to understand a getattr syntax. The syntax is:
    > 
    > try:
    >     getattr(self, command)(cursor, row)
    > except Exception, e:
    >     print "Action failed : '%s'" % command
    >     raise e
    > 
    > I don't understand why is not like this: a = getattr(), and what are
    > the scope of the second (): (cursor, row)
    
    The attribute in question is a callable, a method most probably. So 
    
     getattr(self, command)
    
    returns a reference to the method, and the following
    
     (cursor, row)
    
    calls it with cursor and row as parameters.
    
    You could rewrite it as 
    
      method = getattr(self, command)
      print method
      method(cursor, row)
    
    Diez
    
    
    From neilc at norwich.edu  Tue Nov 24 11:00:59 2009
    From: neilc at norwich.edu (Neil Cerutti)
    Date: 24 Nov 2009 16:00:59 GMT
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    Message-ID: <7n2e9rF3k5ehtU1@mid.individual.net>
    
    On 2009-11-24, Antoine Pitrou  wrote:
    > It tries to evaluate the op of the stack (here nonevar) in a
    > boolean context (which theoretically involves calling
    > __nonzero__ on the type) 
    
    ...or __bool__ in Py3K.
    
    -- 
    Neil Cerutti
    
    
    From solipsis at pitrou.net  Tue Nov 24 11:05:01 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 16:05:01 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    Message-ID: 
    
    Le Tue, 24 Nov 2009 15:11:29 +0000, Antoine Pitrou a ?crit?:
    > Hello,
    > 
    > Le Tue, 24 Nov 2009 14:41:19 +0100, mk a ?crit?:
    >> 
    >> As Rob pointed out (thanks):
    >> 
    >> 11          31 LOAD_FAST                0 (nonevar)
    >>               34 JUMP_IF_FALSE            4 (to 41)
    >> 
    >> I'm no good at py compiler or implementation internals and so I have no
    >> idea what bytecode "JUMP_IF_FALSE" is actually doing.
    > 
    > It tries to evaluate the op of the stack (here nonevar)
    
    I meant "the top of the stack" obviously.
    
    
    
    
    From rustompmody at gmail.com  Tue Nov 24 11:09:41 2009
    From: rustompmody at gmail.com (rustom)
    Date: Tue, 24 Nov 2009 08:09:41 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    Message-ID: 
    
    On Nov 24, 8:13?pm, Richard Riley  wrote:
    > Gerhard H?ring  writes:
    > > Rhodri James wrote:
    > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >>> Dear experts,
    > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > >> I don't really understand this urge to cram everything into a single
    > >> program, since that inevitably leads to compromises that will
    > >> compromise
    >
    > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > merely programmed to hook into the external tools
    >
    > >> just how much of Mercurial's useful and interesting functionality you
    > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > >> to be capable of working with most source control systems.
    >
    > > I prefer the commandline tools, too.
    >
    > > FWIW, Eclipse supports Mercurial through
    > >http://www.vectrace.com/mercurialeclipse/
    >
    > > -- Gerhard
    >
    > Why would you prefer the command line tools in a shell when the same
    > tools can be used in a way which makes navigating the output so much
    > easier? It strikes me as a kind of intransigence. it's a common
    > misconception that IDEs use their own tools all the time. They
    > don't. They integrate the very same tools. e.g Why the hell would I drop
    > to a command line to diff a file with a back version in GIT when I can
    > do the same in the buffer in emacs with a single hot key? Why would I
    > pipe the output of compile into a file then open that file when a single
    > hot key can fire off the SAME compiler and then list the errors in an
    > emacs buffer and another hot key can take me directly to the source
    > lines in question? Living in the past has its mements, but really.
    >
    > e.g I have pylint working live in python buffers. Big time
    > saver. Similar with C.
    
    I sometimes think that the amount of time I spend tweaking emacs to
    save my time is more than the time I spend on anything else :-)
    
    But more seriously:
    I tried to use emacs with git recently -- it was a sorry experience.
    The git.el that comes with git is broken (on windows)
    vc was too old for git like systems
    dvc is a joke (its supposedly generic for all Distributed Version
    Systems -- but everything is couched in terms of tla.
    TLA! For heavens sake!
    magit would not run on windows and to use egg http://github.com/bogolisk/egg
    I must read magit docs.
    Finally I decided to stay with what Ive used for the last 25 years --
    the shell
    
    
    
    From pengyu.ut at gmail.com  Tue Nov 24 11:14:19 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 10:14:19 -0600
    Subject: Where to put the error handing test?
    In-Reply-To: <4B0BBC62.7020702@ieee.org>
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    	<4B0BBC62.7020702@ieee.org>
    Message-ID: <366c6f340911240814o4b02642bude4c306cf160bc01@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel  wrote:
    > Peng Yu wrote:
    >>
    >> On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan  wrote:
    >>
    >>>
    >>> Peng Yu wrote:
    >>>
    >>>>
    >>>> Suppose that I have function f() that calls g(), I can put a test on
    >>>> the argument 'x' in either g() or f(). I'm wondering what is the
    >>>> common practice.
    >>>>
    >>>> My thought is that if I put the test in g(x), the code of g(x) is
    >>>> safer, but the test is not necessary when g() is called by h().
    >>>>
    >>>> If I put the test in f(), then g() becomes more efficient when other
    >>>> code call g() and guarantee x will pass the test even though the test
    >>>> code in not in g(). But there might be some caller of g() that pass an
    >>>> 'x' that might not pass the test, if there were the test in g().
    >>>>
    >>>
    >>> Typically, you test for x as early as possible, e.g. just after user
    >>> input
    >>> (or file or url load or whatever). After that test, you can (or should be
    >>> able to) assume that all function calls will always be called with the
    >>> correct argument. This is the ideal situation, it's not always easy to
    >>> do.
    >>>
    >>> In any case though, don't optimize early.
    >>>
    >>
    >> Let's suppose that g() is refactored out from f() and is call by not
    >> only f() but other functions, and g() is likely to be called by new
    >> functions.
    >>
    >> If I don't optimize early, I should put the test in g(), rather than f(),
    >> right?
    >>
    >>
    >
    > Your question is so open-ended as to be unanswerable. ?All we should do in
    > this case is supply some guidelines so you can guess which one might apply
    > in your particular case.
    >
    > You could be referring to a test that triggers alternate handling. ?Or you
    > could be referring to a test that notices bad input by a user, or bad data
    > from an untrusted source. ?Or you could be referring to a test that
    > discovers bugs in your code. ?And there are variations of these, depending
    > on whether your user is also writing code (eval, or even import of
    > user-supplied mixins), etc.
    >
    > The first thing that's needed in the function g() is a docstring, defining
    > what inputs it expects, and what it'll do with them. ?Then if it gets any
    > input that doesn't meet those requirements, it might throw an exception. ?Or
    > it might just get an arbitrary result. ?That's all up to the docstring.
    > ?Without any documentation, nothing is correct.
    >
    > Functions that are only called by trusted code need not have explicit tests
    > on their inputs, since you're writing it all. ?Part of debugging is catching
    > those cases where f () can pass bad data to g(). ?If it's caused because bad
    > data is passed to f(), then you have a bug in that caller. ?Eventually, you
    > get to the user. ?If the bad data comes from the user, it should be caught
    > as soon as possible, and feedback supplied right then.
    
    I'll still confused by the guideline that an error should be caught as
    early as possible.
    
    Suppose I have the following call chain
    
    f1() --> f2() --> f3() --> f4()
    
    The input in f1() might cause an error in f4(). However, this error
    can of cause be caught by f1(), whenever I want to do so. In the worst
    case, I could duplicate the code of f2 and f3, and the test code in f4
    to f1(), to catch the error in f1 rather than f4. But I don't think
    that this is what you mean.
    
    Then the problem is where to put the test code more effectively. I
    would consider 'whether it is obvious to test the condition in the
    give function' as the guideline. However, it might be equal obvious to
    test the same thing two functions, for example, f1 and f4.
    
    In this case, I thought originally that I should put the test code in
    f1 rather than f4, if f1, f2, f3 and f4 are all the functions that I
    have in the package that I am making. But it is possible that some
    time later I added the function f5(),...,f10() that calls f4(). Since
    f4 doesn't have the test code, f5(),...,f10() should have the same
    test code. This is clearly a redundancy to the code. If I move the
    test code to f4(), there is a redundancy of the code between f1 and
    f4.
    
    I'm wondering how you would solve the above problem?
    
    > assert() ought to be the correct way to add tests in g() that test whether
    > there's such a bug in f(). ?Unfortunately, in CPython it defaults to debug
    > mode, so scripts that are run will execute those tests by default.
    > ?Consequently, people leave them out, to avoid slowing down code.
    >
    >
    >
    > It comes down to trust. ?If you throw the code together without a test
    > suite, you'll be a long time finding all the bugs in non-trivial code. ?So
    > add lots of defensive tests throughout the code, and pretend that's
    > equivalent to a good test system. ?If you're writing a library to be used by
    > others, then define your public interfaces with exceptions for any invalid
    > code, and write careful documentation describing what's invalid. ?And if
    > you're writing an end-user application, test their input as soon as you get
    > it, so none of the rest of the application ever gets "invalid" data.
    
    Having the test code for any function and any class (even the ones
    that are internal in the package) is basically what I am doing.
    However, if I decided to put the test code in f1(), then I can not
    have my test code test the error case for f4(). If the rule is to test
    each function/class extensively, then I have to put the error handling
    code in f4(). But this is contradictory to catch the error as early as
    possible and removing code redundancy.
    
    Would you put a global solution to all the above problems that I mentioned?
    
    
    From wadienil at gmail.com  Tue Nov 24 11:14:35 2009
    From: wadienil at gmail.com (wadi wadi)
    Date: Tue, 24 Nov 2009 16:14:35 +0000
    Subject: fixing xml output format
    Message-ID: <3282bd0c0911240814s304840bdree681c18e9f6e0e0@mail.gmail.com>
    
     Hi all,
    
    I am creating some xml output using minidom and saving it to a file using
    doc.writexml()
    The output however is as follows:
    
    
    
    
            bill catman
    
    
    
    
    Is there a way to save xml output in a file such as xml is formatted the
    right way? I mean with the right indentation and the elements values with no
    new lines?
    
    
    
      bill catman
    
    
    Note: writexml() with parameters and toprettyxml() are not giving the
    desired output.
    
    Thanks.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From nulla.epistola at web.de  Tue Nov 24 11:42:57 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Tue, 24 Nov 2009 17:42:57 +0100
    Subject: csv and mixed lists of unicode and numbers
    Message-ID: 
    
    Hello,
    
    I want to put data from a database into a tab separated text file. This
    looks like a typical application for the csv module, but there is a
    snag: the rows I get from the database module (kinterbasdb in this case)
    contain unicode objects and numbers. And of course the unicode objects
    contain lots of non-ascii characters.
    
    If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    the UnicodeWriter from the module documentation, I get TypeErrors with
    the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    would cause other complications.)
    
    So do I have to process the rows myself and treat numbers and text
    fields differently? Or what's the best way?
    
    Here is a small example:
    
    ########################################################################
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import csv, codecs, cStringIO
    import tempfile
    
    cData = [u'?rger', u'?dland', 5, u'S??igkeit', u'?l?ve', 6.9, u'for?t']
    
    class UnicodeWriter:
         """
         A CSV writer which will write rows to CSV file "f",
         which is encoded in the given encoding.
         """
    
         def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
             # Redirect output to a queue
             self.queue = cStringIO.StringIO()
             self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
             self.stream = f
             self.encoder = codecs.getincrementalencoder(encoding)()
    
         def writerow(self, row):
             self.writer.writerow([s.encode("utf-8") for s in row])
             # Fetch UTF-8 output from the queue ...
             data = self.queue.getvalue()
             data = data.decode("utf-8")
             # ... and reencode it into the target encoding
             data = self.encoder.encode(data)
             # write to the target stream
             self.stream.write(data)
             # empty queue
             self.queue.truncate(0)
    
         def writerows(self, rows):
             for row in rows:
                 self.writerow(row)
    
    def writewithcsv(outfile, datalist):
         wrt = csv.writer(outfile, dialect=csv.excel)
         wrt.writerow(datalist)
    
    def writeunicode(outfile, datalist):
         wrt = UnicodeWriter(outfile)
         wrt.writerow(datalist)
    
    def main():
         with tempfile.NamedTemporaryFile() as csvfile:
             print "CSV file:", csvfile.name
             print "Try with csv.writer"
             try:
                 writewithcsv(csvfile, cData)
             except UnicodeEncodeError as e:
                 print e
             print "Try with UnicodeWriter"
             writeunicode(csvfile, cData)
         print "Ready."
    
    if __name__ == "__main__":
         main()
    
    
    ##############################################################################
    
    Hoping for advice,
    
    Sibylle
    
    
    From paul at boddie.org.uk  Tue Nov 24 11:58:40 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Tue, 24 Nov 2009 08:58:40 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	
    Message-ID: <4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    
    On 24 Nov, 16:11, Antoine Pitrou  wrote:
    >
    
    [JUMP_IF_FALSE]
    
    > It tries to evaluate the op of the stack (here nonevar) in a boolean
    > context (which theoretically involves calling __nonzero__ on the type)
    > and then jumps if the result is False (rather than True).
    
    [...]
    
    > As someone pointed out, the Python interpreter could grow CISC-like
    > opcodes so as to collapse "is not None" (or generically "is not
    > ") into a single JUMP_IF_IS_NOT_CONST opcode.
    
    Of course, JUMP_IF_FALSE is already quite CISC-like, whereas testing
    if something is not None could involve some fairly RISC-like
    instructions: just compare the address of an operand with the address
    of None. As you point out, a lot of this RISC vs. CISC analysis (and
    inferences drawn from Python bytecode analysis) is somewhat academic:
    the cost of the JUMP_IF_FALSE instruction is likely to be minimal in
    the context of all the activity going on to evaluate the bytecodes.
    
    I imagine that someone (or a number of people) must have profiled the
    Python interpreter and shown how much time goes on the individual
    bytecode implementations and how much goes on the interpreter's own
    housekeeping activities. It would be interesting to see such figures.
    
    Paul
    
    
    From bheemesh at gmail.com  Tue Nov 24 12:17:36 2009
    From: bheemesh at gmail.com (bheemesh v)
    Date: Tue, 24 Nov 2009 22:47:36 +0530
    Subject: howto send signal to a OS daemon on linux
    Message-ID: <670534840911240917u119aae1fmb05a48cc77cdab8b@mail.gmail.com>
    
    Hello,
    
    Greetings.
    
    I am a newbie to python programming.
    Can anybody please help me with options to send a user defined signal to a
    OS daemon (example a daemon snmpd).
    
    I tried finding options to get pid of a daemon (process) by passing it's
    name.
    Once a pid is available thenwe can use os.kill(signal_type, signalhandler);
    
    But how to get pid of a process by passing it's name and then how to send
    signal whichis userdefind.
    
    Kindly let me know.
    Thanks in advance.
    
    Best Regards,
    Bheemesh
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From sturlamolden at yahoo.no  Tue Nov 24 12:27:24 2009
    From: sturlamolden at yahoo.no (sturlamolden)
    Date: Tue, 24 Nov 2009 09:27:24 -0800 (PST)
    Subject: xmlrpc idea for getting around the GIL
    References:  
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com> 
    	
    Message-ID: <1bafb82e-fe19-4a4f-a172-f1224cb1a314@h10g2000vbm.googlegroups.com>
    
    On 24 Nov, 16:13, Antoine Pitrou  wrote:
    
    > >> Has anyone every tried wrapping the CPython lib into a daemon with an
    > >> RPC mechanism in order to move the GIL out of the process?
    >
    > >> I imagine this is how the multiprocessing module works.
    >
    > > It does not.
    >
    > Actually, it is how multiprocessing works under Windows (for lack of the
    > fork() function), except that it uses pickle by default (but it does have
    > xmlrpc support).
    
    Windows does not have daemons, so this is obviously incorrect. (There
    are something called Windows Services, but multiprocessing does not
    use them.)
    
    Multiprocessing on Windows uses the subprocess module.
    
    
    
    
    
    
    
    
    
    
    
    
    
    From ethan at stoneleaf.us  Tue Nov 24 12:39:26 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Tue, 24 Nov 2009 09:39:26 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4b0b92de$0$14677$426a74cc@news.free.fr>
    References: 
    	<4b0b92de$0$14677$426a74cc@news.free.fr>
    Message-ID: <4B0C1A4E.7050204@stoneleaf.us>
    
    Bruno Desthuilliers wrote:
    > Ethan Furman a ?crit :
    > 
    >> The problem I have with properties is my typing.  I'll end up 
    >> assigning to an attribute, but get the spelling slightly wrong 
    >> (capitalized, or missing an underscore -- non-obvious things when 
    >> bug-hunting), so now I have an extra attribute which of course has 
    >> zero effect on what I'm trying to do and I start getting wierd results 
    >> like viewing deleted records when I *know* I set useDeleted = False... 
    >> 30 minutes later I notice it was /supposed/ to be use_deleted.  *sigh*
    >>
    >> So -- to keep myself out of trouble -- I have started coding such 
    >> things as, for example:
    >>
    >> result = table.use_deleted()       # returns True or False
    >> table.use_deleted(False)           # skip deleted records
    >>
    >> instead of
    >>
    >> result = table.use_deleted
    >> table.use_deleted = False
    >>
    >> My question:  is this [ severely | mildly | not at all ] un-pythonic?
    > 
    > 
    > Definitly and totally unpythonic. The first solution to your problem is 
    > to stick to standard naming conventions. If this is not enough, Chris 
    > pointed you to really useful tools. Also, you can override __setattr__ 
    > to catch such errors - at least during the coding/debug phase.
    
    Good tools to know about, and a consistent naming pattern also makes 
    life easier (which I have since done ;).
    
    Let's head towards murkier waters (at least murkier to me -- hopefully 
    they can be easily clarified):  some of the attributes are read-only, 
    such as record count; others are not directly exposed, but still 
    settable, such as table version; and still others require a small amount 
    of processing... at which point do I switch from simple attribute access 
    to method access?
    
    ~Ethan~
    
    
    From gd_usenet at spamfence.net  Tue Nov 24 12:47:37 2009
    From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich)
    Date: Tue, 24 Nov 2009 18:47:37 +0100
    Subject: IDE+hg
    References: 
    Message-ID: 
    
    NiklasRTZ  wrote:
    
    >Since no py IDE I found has easy hg access.
    
    Obviously, you didn't try Eclipse with PyDev () 
    and Mercurial Eclipse () 
    plugins.
    This combination is also available stuffed into one package as 
    'EasyEclipse for Python' ().
    
    Both, pure Eclipse with plugins installed by hand, and EasyEclipse, are 
    very convenient for python development.
    
    
    
    Best regards,
    
    G?nther
    
    
    From benjamin.kaplan at case.edu  Tue Nov 24 12:50:29 2009
    From: benjamin.kaplan at case.edu (Benjamin Kaplan)
    Date: Tue, 24 Nov 2009 12:50:29 -0500
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    Message-ID: 
    
    On Tue, Nov 24, 2009 at 11:42 AM, Sibylle Koczian  wrote:
    > Hello,
    >
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    >
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    >
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    >
    > Here is a small example:
    >
    > ########################################################################
    > #!/usr/bin/env python
    > # -*- coding: utf-8 -*-
    >
    > import csv, codecs, cStringIO
    > import tempfile
    >
    > cData = [u'?rger', u'?dland', 5, u'S??igkeit', u'?l?ve', 6.9, u'for?t']
    >
    > class UnicodeWriter:
    > ? ?"""
    > ? ?A CSV writer which will write rows to CSV file "f",
    > ? ?which is encoded in the given encoding.
    > ? ?"""
    >
    > ? ?def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
    > ? ? ? ?# Redirect output to a queue
    > ? ? ? ?self.queue = cStringIO.StringIO()
    > ? ? ? ?self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
    > ? ? ? ?self.stream = f
    > ? ? ? ?self.encoder = codecs.getincrementalencoder(encoding)()
    >
    > ? ?def writerow(self, row):
    > ? ? ? ?self.writer.writerow([s.encode("utf-8") for s in row])
    
    try doing [s.encode("utf-8") if isinstance(s,unicode) else s for s in row]
    That way, you'll only encode the unicode strings
    
    
    > ? ? ? ?# Fetch UTF-8 output from the queue ...
    > ? ? ? ?data = self.queue.getvalue()
    > ? ? ? ?data = data.decode("utf-8")
    > ? ? ? ?# ... and reencode it into the target encoding
    > ? ? ? ?data = self.encoder.encode(data)
    > ? ? ? ?# write to the target stream
    > ? ? ? ?self.stream.write(data)
    > ? ? ? ?# empty queue
    > ? ? ? ?self.queue.truncate(0)
    >
    > ? ?def writerows(self, rows):
    > ? ? ? ?for row in rows:
    > ? ? ? ? ? ?self.writerow(row)
    >
    > def writewithcsv(outfile, datalist):
    > ? ?wrt = csv.writer(outfile, dialect=csv.excel)
    > ? ?wrt.writerow(datalist)
    >
    > def writeunicode(outfile, datalist):
    > ? ?wrt = UnicodeWriter(outfile)
    > ? ?wrt.writerow(datalist)
    >
    > def main():
    > ? ?with tempfile.NamedTemporaryFile() as csvfile:
    > ? ? ? ?print "CSV file:", csvfile.name
    > ? ? ? ?print "Try with csv.writer"
    > ? ? ? ?try:
    > ? ? ? ? ? ?writewithcsv(csvfile, cData)
    > ? ? ? ?except UnicodeEncodeError as e:
    > ? ? ? ? ? ?print e
    > ? ? ? ?print "Try with UnicodeWriter"
    > ? ? ? ?writeunicode(csvfile, cData)
    > ? ?print "Ready."
    >
    > if __name__ == "__main__":
    > ? ?main()
    >
    >
    > ##############################################################################
    >
    > Hoping for advice,
    >
    > Sibylle
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    
    
    From gd_usenet at spamfence.net  Tue Nov 24 12:54:45 2009
    From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich)
    Date: Tue, 24 Nov 2009 18:54:45 +0100
    Subject: IDE+hg
    References: 
    	
    Message-ID: <68jtt6-oi.ln1@spamfence.net>
    
    In article ,
     "G?nther Dietrich"  wrote:
    
    >>Since no py IDE I found has easy hg access.
    >
    >Obviously, you didn't try Eclipse with PyDev () 
    >and Mercurial Eclipse () 
    >plugins.
    >This combination is also available stuffed into one package as 
    >'EasyEclipse for Python' ().
    
    Correction: EasyEclipse for Python does not contain the Mercurial 
    Eclipse plugin. That has to be installed by hand in both cases.
    
    
    
    Sorry,
    
    G?nther
    
    
    From claird.visiprise at gmail.com  Tue Nov 24 12:59:28 2009
    From: claird.visiprise at gmail.com (Cameron Laird)
    Date: Tue, 24 Nov 2009 09:59:28 -0800 (PST)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    Message-ID: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    
    QOTW:  "... it's generally accepted that COM sucks rocks through
    straws, so
    explore alternatives when they're available ;-)" - Chris Withers
        http://groups.google.com/group/comp.lang.python/msg/29577c851ceed167
    
    
        From nothing to a complete working program - Peter Otten on
    stepwise
        refinement:
            http://groups.google.com/group/comp.lang.python/t/f6f44b646af5b09e/8f59b2585da524a1?#8f59b2585da524a1
    
        Handling whitespace in command line arguments:
            http://groups.google.com/group/comp.lang.python/t/9a828279953b45a2/
    
        Recognizing hex arguments in the command line:
            http://groups.google.com/group/comp.lang.python/t/31d4c9386291c/
    
        A pipeline of Python programs:
            http://groups.google.com/group/comp.lang.python/t/cc06520602ae3f42/
    
        Calling Python functions from Excel
            http://groups.google.com/group/comp.lang.python/t/83aa60666c555d87/
    
        The scope of interactive commands:   =20
            http://groups.google.com/group/comp.lang.python/t/3f0d7607ed5a4a78/
    
        List comprehensions and slice assignments - which are the
    corresponding
        operations for dictionaries?
            http://groups.google.com/group/comp.lang.python/t/7aa443ac48f58851/
    
        The precise semantics of [:]=20
            http://groups.google.com/group/comp.lang.python/t/84b5ec30cdd26cde/
    
        The 'with' statement doesn't allow () for implicit line
    continuation:
            http://comments.gmane.org/gmane.comp.python.general/645508
    
        Grant Edwards on the best way to get help from this group :)
            http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    
        Finding the root cause of slowness when sorting certain objects:
            http://groups.google.com/group/comp.lang.python/t/44d80224360e085/
    
        The fastest alternative to list.extend()
            http://groups.google.com/group/comp.lang.python/t/614bfc36a09d9ab7/
    
        A library for bijective mappings:
            http://groups.google.com/group/comp.lang.python/t/785d100681f7d101/
    
        GUI builders reviewed:
            http://groups.google.com/group/comp.lang.python/t/3db5b18d77974b8/
    
        A long thread started two weeks ago: is Python not scalable enough
    for
        Google?
            http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/
    
    
    ========================================================================
    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
    enthusiasts":
            http://pythonpapers.org/
        The Python Magazine is a technical monthly devoted to Python:
            http://pythonmagazine.com
    
        Readers have recommended the "Planet" site:
            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/
    
        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.com
    p.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
    
        Enjoy the *Python Magazine*.
            http://pymag.phparch.com/
    
        *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.p
    ython.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 python-url at phaseit.net  Tue Nov 24 13:14:19 2009
    From: python-url at phaseit.net (Gabriel Genellina)
    Date: Tue, 24 Nov 2009 18:14:19 +0000 (UTC)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    Message-ID: 
    
    QOTW:  "... it's generally accepted that COM sucks rocks through straws, so
    explore alternatives when they're available ;-)" - Chris Withers
        http://groups.google.com/group/comp.lang.python/msg/29577c851ceed167
        
        
        From nothing to a complete working program - Peter Otten on stepwise
        refinement:
            http://groups.google.com/group/comp.lang.python/t/f6f44b646af5b09e/8f59b2585da524a1?#8f59b2585da524a1
        
        Handling whitespace in command line arguments:
            http://groups.google.com/group/comp.lang.python/t/9a828279953b45a2/
        
        Recognizing hex arguments in the command line:
            http://groups.google.com/group/comp.lang.python/t/31d4c9386291c/
        
        A pipeline of Python programs:
            http://groups.google.com/group/comp.lang.python/t/cc06520602ae3f42/
        
        Calling Python functions from Excel
            http://groups.google.com/group/comp.lang.python/t/83aa60666c555d87/
        
        The scope of interactive commands:   =20
            http://groups.google.com/group/comp.lang.python/t/3f0d7607ed5a4a78/
        
        List comprehensions and slice assignments - which are the corresponding
        operations for dictionaries?
            http://groups.google.com/group/comp.lang.python/t/7aa443ac48f58851/
        
        The precise semantics of [:]=20
            http://groups.google.com/group/comp.lang.python/t/84b5ec30cdd26cde/
        
        The 'with' statement doesn't allow () for implicit line continuation:
            http://comments.gmane.org/gmane.comp.python.general/645508
        
        Grant Edwards on the best way to get help from this group :)
            http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
        
        Finding the root cause of slowness when sorting certain objects:
            http://groups.google.com/group/comp.lang.python/t/44d80224360e085/
        
        The fastest alternative to list.extend()
            http://groups.google.com/group/comp.lang.python/t/614bfc36a09d9ab7/
        
        A library for bijective mappings:
            http://groups.google.com/group/comp.lang.python/t/785d100681f7d101/
        
        GUI builders reviewed:
            http://groups.google.com/group/comp.lang.python/t/3db5b18d77974b8/
        
        A long thread started two weeks ago: is Python not scalable enough for
        Google?
            http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/
        
        
    ========================================================================
    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 enthusiasts":
    	http://pythonpapers.org/
        The Python Magazine is a technical monthly devoted to Python:
    	http://pythonmagazine.com
    
        Readers have recommended the "Planet" site:
    	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/
    
        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
    
        Enjoy the *Python Magazine*.
    	http://pymag.phparch.com/
    
        *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 solipsis at pitrou.net  Tue Nov 24 13:17:17 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 18:17:17 +0000 (UTC)
    Subject: xmlrpc idea for getting around the GIL
    References: 
    	<9ec21af9-d690-4b6a-9732-a1b76481b8b2@j35g2000vbl.googlegroups.com>
    	
    	<1bafb82e-fe19-4a4f-a172-f1224cb1a314@h10g2000vbm.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 09:27:24 -0800, sturlamolden a ?crit?:
    > 
    > Windows does not have daemons, so this is obviously incorrect. (There
    > are something called Windows Services, but multiprocessing does not use
    > them.)
    
    This is nitpicking. Technically it might not be a daemon but it's used as 
    such.
    The important point is that it does use a (custom) form of RPC through 
    marshalling, which is what the original question was about.
    
    
    
    From cjns1989 at gmail.com  Tue Nov 24 13:19:10 2009
    From: cjns1989 at gmail.com (Chris Jones)
    Date: Tue, 24 Nov 2009 13:19:10 -0500
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: <031bc732$0$1336$c3e8da3@news.astraweb.com>
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <20091124181910.GB3122@turki.gavron.org>
    
    On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    
    > Good grief, it's about six weeks away from 2010 and Thunderbird still 
    > uses mbox as it's default mail box format. Hello, the nineties called, 
    > they want their mail formats back! Are the tbird developers on crack or 
    > something? I can't believe that they're still using that crappy format.
    > 
    > No, I tell a lie. I can believe it far too well.
    
    :-)
    
    I realize that's somewhat OT, but what mail box format do you recommend,
    and why?
    
    Thanks,
    
    CJ
    
    
    From jabronson at gmail.com  Tue Nov 24 13:21:58 2009
    From: jabronson at gmail.com (Joshua Bronson)
    Date: Tue, 24 Nov 2009 10:21:58 -0800 (PST)
    Subject: python bijection
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com>
    Message-ID: 
    
    Hey Raymond,
    
    Thanks for your thoughtful reply! I think your idea for a class-
    generation approach in the spirit of namedtuple is brilliant; looking
    forward to coding this up and seeing how it feels to use it.
    
    (By the way, it occurred to me that "bijection" is perhaps the wrong
    term to use for this data structure; really it's just an injective
    mapping, as it has no idea whether the function whose mappings it
    contains is also surjective. (Unless we take the domain, codomain, and
    range of the function being modeled to be exactly defined by the state
    of the mapping at any given time. But it feels more correct to me to
    interpret the mapping as a sampling of some underlying function, where
    the sampling can change but the function stays the same.) So I'm
    thinking of renaming the class injectivedict or idict instead of
    bijection. Is that crazy?)
    
    More responses inline:
    
    On Nov 21, 9:22?pm, Raymond Hettinger  wrote:
    > * The idea of using __call__ for looking-up inverse values was
    > inspired. ?That is useable, clean, and easy to remember; however, as
    > discussed below, there are issues though with its actual use in real
    > code.
    
    Totally agree the call syntax has issues. Did you happen to see
    Terry's suggestion to use slice syntax instead? Now *that* was
    inspired. It's also much better because it works for setitem and
    delitem too. I replaced the call syntax with the slice syntax on
    Friday night -- would be interested to hear whether you think it's an
    improvement.
    
    
    > * Am not excited by the inverse iterators. ?With just a regular
    > mapping you can write:
    >
    > ? ? ? ? for a, b in m.items() ... ? # consider either a or b be the
    > key and the other to be the value
    >
    > ? That meets all of the needs that would have been served by
    > iter_inverse_keys() or iter_inverse_values() or whatnot. ?The mirrored
    > API doesn't really provide much in the way of value added.
    
    Hm, the one value I see the latest version of ``inverted`` adding (may
    not have been in the version you saw) is that you can pass it either a
    mapping, an iterable, or any object implementing an __inverted__
    method. So in one case it's just syntax sugar for writing [(v, k) for
    (k, v) in d.items()], but in other cases it's providing some
    abstraction.
    
    
    
    > Hope these ideas help. ?The ultimate success of the Bijection code
    > will depend on its clarity, simplicity, and speed. ?Experiment with
    > various approaches to find-out which looks the best in real code. ?It
    > cannot be error-prone or it is doomed. ?Also, it should not introduce
    > much overhead processing or else people will avoid it. ?The API should
    > be trivially simple so that people remember how to use it months after
    > seeing it for the first time.
    
    Thank you for the sage advice.
    
    Best,
    Josh
    
    
    From clp2 at rebertia.com  Tue Nov 24 13:25:37 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 10:25:37 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4B0C1A4E.7050204@stoneleaf.us>
    References: 
    	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	<4B0C1A4E.7050204@stoneleaf.us>
    Message-ID: <50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 9:39 AM, Ethan Furman  wrote:
    > Bruno Desthuilliers wrote:
    >> Ethan Furman a ?crit :
    >>> The problem I have with properties is my typing. ?I'll end up assigning
    >>> to an attribute, but get the spelling slightly wrong (capitalized, or
    >>> missing an underscore -- non-obvious things when bug-hunting), so now I have
    >>> an extra attribute which of course has zero effect on what I'm trying to do
    >>> and I start getting wierd results like viewing deleted records when I *know*
    >>> I set useDeleted = False... 30 minutes later I notice it was /supposed/ to
    >>> be use_deleted. ?*sigh*
    >>>
    >>> So -- to keep myself out of trouble -- I have started coding such things
    >>> as, for example:
    >>>
    >>> result = table.use_deleted() ? ? ? # returns True or False
    >>> table.use_deleted(False) ? ? ? ? ? # skip deleted records
    >>>
    >>> instead of
    >>>
    >>> result = table.use_deleted
    >>> table.use_deleted = False
    >>>
    >>> My question: ?is this [ severely | mildly | not at all ] un-pythonic?
    >>
    >>
    >> Definitly and totally unpythonic. The first solution to your problem is to
    >> stick to standard naming conventions. If this is not enough, Chris pointed
    >> you to really useful tools. Also, you can override __setattr__ to catch such
    >> errors - at least during the coding/debug phase.
    >
    > Good tools to know about, and a consistent naming pattern also makes life
    > easier (which I have since done ;).
    >
    > Let's head towards murkier waters (at least murkier to me -- hopefully they
    > can be easily clarified): ?some of the attributes are read-only, such as
    > record count; others are not directly exposed, but still settable, such as
    > table version; and still others require a small amount of processing... at
    > which point do I switch from simple attribute access to method access?
    
    Thanks to the magic of properties, the end-user-programmer need not
    know which you're using:
    
    http://docs.python.org/library/functions.html#property
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From solipsis at pitrou.net  Tue Nov 24 13:25:37 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Tue, 24 Nov 2009 18:25:37 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a ?crit?:
    > As you
    > point out, a lot of this RISC vs. CISC analysis (and inferences drawn
    > from Python bytecode analysis) is somewhat academic: the cost of the
    > JUMP_IF_FALSE instruction is likely to be minimal in the context of all
    > the activity going on to evaluate the bytecodes.
    
    Sorry, I have trouble parsing your sentence. Do you mean bytecode 
    interpretation overhead is minimal compared to the cost of actual useful 
    work, or the contrary?
    (IMO both are wrong by the way)
    
    > I imagine that someone (or a number of people) must have profiled the
    > Python interpreter and shown how much time goes on the individual
    > bytecode implementations and how much goes on the interpreter's own
    > housekeeping activities.
    
    Well the one problem is that it's not easy to draw a line. Another 
    problem is that it depends on the workload. If you are compressing large 
    data or running expensive regular expressions the answer won't be the 
    same as if you compute a Mandelbrot set in pure Python.
    
    One data point is that the "computed gotos" option in py3k generally 
    makes the interpreter faster by ~15%. Another data point I've heard is 
    that people who have tried a very crude form of Python-to-C compilation 
    (generating the exact C code corresponding to a function or method, using 
    Python's C API and preserving dynamicity without attempting to be clever) 
    have apparently reached speedups of up to 50% (in other words, "twice as 
    fast"). So you could say that the interpretation overhead is generally 
    between 15% and 50%.
    
    
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 13:45:27 2009
    From: x.sanz35 at gmail.com (Xavier)
    Date: Tue, 24 Nov 2009 10:45:27 -0800 (PST)
    Subject: multiprocessing.connection with ssl
    Message-ID: <8ff1698c-8205-4171-9e41-2e382bd52e89@g23g2000vbr.googlegroups.com>
    
    Hello
    
    I've hacked multiprocessing.connection (in a basic way) to allow ssl
    encryption using ssl.wrap_socket.
    
    Anybody knows how i can contribute this to main developers?
    
    Thanks in advance
    
    
    From __peter__ at web.de  Tue Nov 24 14:04:42 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 20:04:42 +0100
    Subject: csv and mixed lists of unicode and numbers
    References: 
    Message-ID: 
    
    Sibylle Koczian wrote:
    
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    > 
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    > 
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    
    I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    up with. Example:
    
    def recode_rows(rows, source_encoding, target_encoding):
        def recode(field):
            if isinstance(field, unicode):
                return field.encode(target_encoding)
            elif isinstance(field, str):
                return unicode(field, source_encoding).encode(target_encoding)
            return unicode(field).encode(target_encoding)
    
        return (map(recode, row) for row in rows)
    
    rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    writer = csv.writer(sys.stdout)
    writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    
    The only limitation I can see: target_encoding probably has to be a superset 
    of ASCII.
    
    Peter
    
    
    
    From tim.wintle at teamrubber.com  Tue Nov 24 14:16:18 2009
    From: tim.wintle at teamrubber.com (Tim Wintle)
    Date: Tue, 24 Nov 2009 19:16:18 +0000
    Subject: pointless musings on performance
    In-Reply-To: 
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	
    Message-ID: <1259090178.661.34.camel@localhost>
    
    On Tue, 2009-11-24 at 18:25 +0000, Antoine Pitrou wrote:
    > Le Tue, 24 Nov 2009 08:58:40 -0800, Paul Boddie a ?crit :
    > > As you
    > > point out, a lot of this RISC vs. CISC analysis (and inferences
    > drawn
    > > from Python bytecode analysis) is somewhat academic: the cost of the
    > > JUMP_IF_FALSE instruction is likely to be minimal in the context of
    > all the activity going on to evaluate the bytecodes.
    > 
    > Sorry, I have trouble parsing your sentence. Do you mean bytecode 
    > interpretation overhead is minimal compared to the cost of actual
    > useful work, or the contrary?
    > (IMO both are wrong by the way)
    
    Out of interest - has anyone else spotted that the call to
    PyObject_IsTrue in the XXX_JUMP_IF_YYYY blocks performs two unnecessary
    pointer comparisons?
    
    ==== ceval.c ====
    if (w == Py_True) {
        Py_DECREF(w);
        FAST_DISPATCH();
    }
    if (w == Py_False) {
        Py_DECREF(w);
        JUMPTO(oparg);
        FAST_DISPATCH();
    }
    err = PyObject_IsTrue(w);
    Py_DECREF(w);
    .
    .
    .
    ==================
    
    ==== object.c ====
    PyObject_IsTrue(PyObject *v)
    {
            Py_ssize_t res;
            if (v == Py_True)
                    return 1;
            if (v == Py_False)
                    return 0;
    .
    .
    .
    ==================
    
    Would it be worth in-lining the remaining part of PyObject_IsTrue in
    ceval?
    
    > Another data point I've heard is that people who have tried a very
    > crude form of Python-to-C compilation (generating the exact C code
    > corresponding to a function or method, using Python's C API and
    > preserving dynamicity without attempting to be clever) have apparently
    > reached speedups of up to 50% (in other words, "twice as fast").
    
    That's roughly what I get with Cython - which does exactly that.
    
    Tim
    
    
    
    From utabintarbo at gmail.com  Tue Nov 24 14:52:24 2009
    From: utabintarbo at gmail.com (utabintarbo)
    Date: Tue, 24 Nov 2009 11:52:24 -0800 (PST)
    Subject: Raw strings as input from File?
    Message-ID: 
    
    I have a log file with full Windows paths on a line. eg:
    K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    
    As I try to pull in the line and process it, python changes the "\10"
    to a "\x08". This is before I can do anything with it. Is there a way
    to specify that incoming lines (say, when using .readlines() ) should
    be treated as raw strings?
    
    TIA
    
    
    From lie.1296 at gmail.com  Tue Nov 24 15:04:06 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Wed, 25 Nov 2009 07:04:06 +1100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	
    Message-ID: <4b0c3c90$1@dnews.tpgi.com.au>
    
    Ethan Furman wrote:
    > 
    > Good tools to know about, and a consistent naming pattern also makes 
    > life easier (which I have since done ;).
    > 
    > Let's head towards murkier waters (at least murkier to me -- hopefully 
    > they can be easily clarified):  some of the attributes are read-only, 
    > such as record count; others are not directly exposed, but still 
    > settable, such as table version; and still others require a small amount 
    > of processing... at which point do I switch from simple attribute access 
    > to method access?
    > 
    > ~Ethan~
    
    method accessor is not pythonic, use property
    
    property can be read-only, write-only (!), and it can process data 
    before returning and setting the real attributes.
    
    
    From bdesth.quelquechose at free.quelquepart.fr  Tue Nov 24 15:21:01 2009
    From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
    Date: Tue, 24 Nov 2009 21:21:01 +0100
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    In-Reply-To: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    Message-ID: <4b0c4dbb$0$8926$426a74cc@news.free.fr>
    
    Cameron Laird a ?crit :
    
    > 
    >     Grant Edwards on the best way to get help from this group :)
    >         http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    > 
    
    This one really deserves a POTM award !-)
    
    
    From python at mrabarnett.plus.com  Tue Nov 24 15:27:39 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Tue, 24 Nov 2009 20:27:39 +0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: <4B0C41BB.40401@mrabarnett.plus.com>
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08". This is before I can do anything with it. Is there a way
    > to specify that incoming lines (say, when using .readlines() ) should
    > be treated as raw strings?
    > 
    .readlines() doesn't change the "\10" in a file to "\x08" in the string
    it returns.
    
    Could you provide some code which shows your problem?
    
    
    From carsten.haese at gmail.com  Tue Nov 24 15:28:30 2009
    From: carsten.haese at gmail.com (Carsten Haese)
    Date: Tue, 24 Nov 2009 15:28:30 -0500
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08".
    
    Python does no such thing. When Python reads bytes from a file, it
    doesn't interpret or change those bytes in any way. Either there is
    something else going on here that you're not telling us, or the file
    doesn't contain what you think it contains. Please show us the exact
    code you're using to process this file, and show us the exact contents
    of the file you're processing.
    
    --
    Carsten Haese
    http://informixdb.sourceforge.net
    
    
    
    From ethan at stoneleaf.us  Tue Nov 24 15:59:15 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Tue, 24 Nov 2009 12:59:15 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    References: 	
    	<4b0b92de$0$14677$426a74cc@news.free.fr>	
    	<4B0C1A4E.7050204@stoneleaf.us>
    	<50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    Message-ID: <4B0C4923.6080008@stoneleaf.us>
    
    Chris Rebert wrote:
    > On Tue, Nov 24, 2009 at 9:39 AM, Ethan Furman  wrote:
    > 
    >>Bruno Desthuilliers wrote:
    >>
    >>>Ethan Furman a ?crit :
    >>>
    >>>>The problem I have with properties is my typing.  I'll end up assigning
    >>>>to an attribute, but get the spelling slightly wrong (capitalized, or
    >>>>missing an underscore -- non-obvious things when bug-hunting), so now I have
    >>>>an extra attribute which of course has zero effect on what I'm trying to do
    >>>>and I start getting wierd results like viewing deleted records when I *know*
    >>>>I set useDeleted = False... 30 minutes later I notice it was /supposed/ to
    >>>>be use_deleted.  *sigh*
    >>>>
    >>>>So -- to keep myself out of trouble -- I have started coding such things
    >>>>as, for example:
    >>>>
    >>>>result = table.use_deleted()       # returns True or False
    >>>>table.use_deleted(False)           # skip deleted records
    >>>>
    >>>>instead of
    >>>>
    >>>>result = table.use_deleted
    >>>>table.use_deleted = False
    >>>>
    >>>>My question:  is this [ severely | mildly | not at all ] un-pythonic?
    >>>
    >>>
    >>>Definitly and totally unpythonic. The first solution to your problem is to
    >>>stick to standard naming conventions. If this is not enough, Chris pointed
    >>>you to really useful tools. Also, you can override __setattr__ to catch such
    >>>errors - at least during the coding/debug phase.
    >>
    >>Good tools to know about, and a consistent naming pattern also makes life
    >>easier (which I have since done ;).
    >>
    >>Let's head towards murkier waters (at least murkier to me -- hopefully they
    >>can be easily clarified):  some of the attributes are read-only, such as
    >>record count; others are not directly exposed, but still settable, such as
    >>table version; and still others require a small amount of processing... at
    >>which point do I switch from simple attribute access to method access?
    > 
    > 
    > Thanks to the magic of properties, the end-user-programmer need not
    > know which you're using:
    > 
    > http://docs.python.org/library/functions.html#property
    
    You know, when I first read that bit on properties a while back, the 
    explanation of the decorators and how a property was also a decorator 
    for the setter and deleter bits completely lost me.  Since then I've 
    played with decorators a bit, written a configaration module that uses 
    them, and just now, reading the description... it was so elegantly 
    simple it almost brought tears to my eyes *sniff*.  I love Python.
    
    Okay, I'll go back and switch all my attributes *back* to attributes -- 
    and properties will be much nicer than my original implementation (using 
    __getattr__ and __setattr__).
    
    Many thanks to all who answered!
    
    ~Ethan~
    
    
    From vinay_sajip at yahoo.co.uk  Tue Nov 24 15:59:52 2009
    From: vinay_sajip at yahoo.co.uk (Vinay Sajip)
    Date: Tue, 24 Nov 2009 12:59:52 -0800 (PST)
    Subject: How to log messages _only once_ from all modules ?
    References:  
    	
    	
    	
    	<9750596d-4d09-478a-a9df-942e44a4e83a@t18g2000vbj.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 3:14?pm, Ron Barak  wrote:
    > Many thanks Soltys, that did the trick (actually, no need for setting
    > propagate to 0), namely,
    >
    [snip]
    
    It might work for now, but instantiating a handler in an instance
    constructor can be an anti-pattern. If you ever create multiple client
    instances, for example, you would create multiple handlers and add
    those to the logger (which is essentially persistent for the lifetime
    of the process), which could result in multiple messages, corrupted
    output or exceptions (in the general case).
    
    It's generally better to declare module-level loggers via
    
    logger = logging.getLogger(__name__)
    
    or, if better granularity is wanted, loggers with names prefixed by
    __name__ + '.' - and handler set up should typically be done in one
    place in such a way as to not inadvertently create handlers multiple
    times. A common pattern is to just add handlers to the root logger
    (e.g. the basicConfig() API does this) - other loggers automatically
    get to use them, under normal circumstances.
    
    Regards,
    
    Vinay Sajip
    
    
    From nulla.epistola at web.de  Tue Nov 24 16:01:55 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Tue, 24 Nov 2009 22:01:55 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    	
    Message-ID: 
    
    Peter Otten schrieb:
    > I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    > up with. Example:
    > 
    > def recode_rows(rows, source_encoding, target_encoding):
    >     def recode(field):
    >         if isinstance(field, unicode):
    >             return field.encode(target_encoding)
    >         elif isinstance(field, str):
    >             return unicode(field, source_encoding).encode(target_encoding)
    >         return unicode(field).encode(target_encoding)
    > 
    >     return (map(recode, row) for row in rows)
    > 
    
    For this case isinstance really seems to be quite reasonable. And it was
    silly of me not to think of sys.stdout as file object for the example!
    
    > rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    > writer = csv.writer(sys.stdout)
    > writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    > 
    > The only limitation I can see: target_encoding probably has to be a superset 
    > of ASCII.
    > 
    
    Coping with umlauts and accents is quite enough for me.
    
    This problem really goes away with Python 3 (tried it on another
    machine), but something else changes too: in Python 2.6 the
    documentation for the csv module explicitly says "If csvfile is a file
    object, it must be opened with the ?b? flag on platforms where that
    makes a difference." The documentation for Python 3.1 doesn't have this
    sentence, and if I do that in Python 3.1 I get for all sorts of data,
    even for a list with only one integer literal:
    
    TypeError: must be bytes or buffer, not str
    
    I don't really understand that.
    
    Regards,
    Sibylle
    
    
    From keith.hughitt at gmail.com  Tue Nov 24 16:04:18 2009
    From: keith.hughitt at gmail.com (Keith Hughitt)
    Date: Tue, 24 Nov 2009 13:04:18 -0800 (PST)
    Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5?
    References: 
    	<4b063a25$0$1668$742ec2ed@news.sonic.net>
    Message-ID: 
    
    Hi John,
    
    Thanks for the suggestions: I have finally been able to get it
    working :)
    
    In anyone else runs into the same problem, here is some example code
    that works in Python 2.4+:
    
    ============= Begin Example ==================
    
    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    import sys
    def main():
        import MySQLdb, getpass
    
        admin = raw_input("Database admin: ")
        pw = getpass.getpass("Password: ")
        db = MySQLdb.connect(use_unicode=True, charset = "utf8",
    user=admin, passwd=pw)
    
        cursor = db.cursor()
        try:
            cursor.execute("DROP DATABASE IF EXISTS unicode_test;")
            cursor.execute("CREATE DATABASE unicode_test DEFAULT CHARACTER
    SET utf8;")
        except:
            print ""
    
        cursor.execute('''
        CREATE TABLE `unicode_test`.`test` (
          `id`          SMALLINT unsigned NOT NULL AUTO_INCREMENT,
          `name`        VARCHAR(255) NOT NULL,
           PRIMARY KEY (`id`), INDEX (`id`)
        ) DEFAULT CHARSET=utf8;''')
    
        cursor.execute("INSERT INTO `unicode_test`.`test` VALUES (NULL,
    '%s');" % u"?ngstr?m")
    
        # Test 1
        print "Just printing: %s" % '?ngstr?m'
    
        # Test 2
        cursor.execute("SELECT name FROM unicode_test.test;")
        print "From database: %s" % cursor.fetchone()[0]
    
        # Test 3 (Manual)
        print 'To verify manually: mysql -u %s -p -e "SELECT name FROM
    unicode_test.test"' % admin
    
    if __name__ == '__main__':
        sys.exit(main())
    
    ============= End Example ====================
    
    Thanks all for taking the time to help!
    
    Best,
    Keith
    
    
    From jasewarren at gmail.com  Tue Nov 24 16:08:27 2009
    From: jasewarren at gmail.com (Jase)
    Date: Tue, 24 Nov 2009 13:08:27 -0800 (PST)
    Subject: Creating a drop down filter in Admin site
    Message-ID: <46ba87ce-6843-4d89-b80c-4f3c1e20bc09@e22g2000vbm.googlegroups.com>
    
    Hoping someone could help me out. I am updating an admin site and
    added a couple "list_filter"s. They are rather long so I wanted to
    turn them into a drop down filter. Can this be done? Any suggestions?
    
    Thanks,
    
    Jase
    
    
    From lie.1296 at gmail.com  Tue Nov 24 16:17:09 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Wed, 25 Nov 2009 08:17:09 +1100
    Subject: Where to put the error handing test?
    In-Reply-To: 
    References: 	<4b0b56ea$1@dnews.tpgi.com.au>	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>	<4B0BBC62.7020702@ieee.org>
    	
    Message-ID: <4b0c4db0@dnews.tpgi.com.au>
    
    Peng Yu wrote:
    > On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel  wrote:
    
    I'll put an extra emphasis on this:
    >> Your question is so open-ended as to be unanswerable.  
    ========================================================
    
    > I'll still confused by the guideline that an error should be caught as
    > early as possible.
    
    but not too early. Errors must be RAISED as early as possible. Errors 
    must be CAUGHT as soon as there is enough information to handle the errors.
    
    > Suppose I have the following call chain
    > 
    > f1() --> f2() --> f3() --> f4()
    > 
    > The input in f1() might cause an error in f4(). However, this error
    > can of cause be caught by f1(), whenever I want to do so. In the worst
    > case, I could duplicate the code of f2 and f3, and the test code in f4
    > to f1(), to catch the error in f1 rather than f4. But I don't think
    > that this is what you mean.
    
    Why would f1() have faulty data? Does it come from external input? Then 
    the input must be invalidated at f1(). Then f2(), f3(), and f4() does 
    not require any argument checking since it is assumed that f1() calls 
    them with good input.
    
    Of course, there is cases where data validation may not be on f1. For 
    example, if f1() is a function that receives keyboard input for a 
    filename f1 validates whether the filename is valid. Then f2 might open 
    the file and validate that the file is of the expected type (if f2 
    expect a .csv file, but given an .xls file, f2 would scream out an 
    error). f3 received rows/lines of data from f2 and extracts 
    fields/columns from the rows; but some of the data might be faulty and 
    these must be filtered out before the data is transformed by the f4. f4 
    assumes f3 cleans the row and so f4 is does not do error-checking. The 
    transformed data then is rewritten back by f3. Now there is an f5 which 
    creates new data, the new data needs to be transformed by f4 as well and 
    since f5 creates a new data, there is no way for it to create invalid 
    data. Now assume f6 merges new data from another csv file; f6's data 
    will also be transformed by f4, f6 can use the same validation as in f3 
    but why not turn f2,f3 instead to open the other file? Now f7 will merge 
    data from multiple f3 streams and transforms by f4. Then comes f8 which 
    creates new data from user input, the user-inputted data will need some 
    checking; and now we have trouble since the data validation is inside 
    f3. But we can easily factor out the validation part into f9 and call f9 
    from f3 and f8.
    
    The example case still checks for problem as early as possible. It 
    checks for problem when it is possible to determine whether a particular 
    condition is problematic. The as early as possible guideline does not 
    mean f1, a filename input function, must check whether the csv fields 
    contains valid data. But f2, the file opening function, must be given a 
    valid filename; f3, the file parser, must be given a valid file object 
    with the proper type; f4, the transformer, must be given a valid row to 
    transform; etc. f2 should not need to check it is given a valid 
    filename, it's f1 job to validate it; f3 should not need to check 
    whether the file object is of the proper type; f4 should not need to 
    check it is given a valid row tuple; and so on...
    
    > Then the problem is where to put the test code more effectively. I
    > would consider 'whether it is obvious to test the condition in the
    > give function' as the guideline. However, it might be equal obvious to
    > test the same thing two functions, for example, f1 and f4.
    > 
    > In this case, I thought originally that I should put the test code in
    > f1 rather than f4, if f1, f2, f3 and f4 are all the functions that I
    > have in the package that I am making. But it is possible that some
    > time later I added the function f5(),...,f10() that calls f4(). Since
    > f4 doesn't have the test code, f5(),...,f10() should have the same
    > test code. This is clearly a redundancy to the code. If I move the
    > test code to f4(), there is a redundancy of the code between f1 and
    > f4.
    
    I can't think of a good example where such redundancy would happen and 
    there is no other, better way to walk around it. Could you provide a 
    CONCRETE example? One that might happen, instead one that could 
    theoretically happen.
    
    
    From bruno.desthuilliers at gmail.com  Tue Nov 24 16:17:13 2009
    From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com)
    Date: Tue, 24 Nov 2009 13:17:13 -0800 (PST)
    Subject: Newsgroup for beginners
    References: 
    	<7xiqd9yj8v.fsf@ruckus.brouhaha.com>  
    	
    	
    Message-ID: <4e0945a3-61e8-4772-9093-231e470a6641@x15g2000vbr.googlegroups.com>
    
    On 20 nov, 20:42, Ethan Furman  wrote:
    > Aahz wrote:
    > > In article ,
    > > Grant Edwards ? wrote:
    >
    > >>You've really got to try pretty hard to create one. ?But if you
    > >>want to, here's how to do it:
    >
    > >>1) Start by complaining that your program doesn't work because
    > >> ? of a bug in Python.
    >
    > >> [...]
    >
    > > Post of the month!
    >
    > I'll second that! ?I really needed a good laugh. ?Many thanks!
    
    So I'll thrice it - FWIW it indeed made it's way to the weekly python
    (thanks the python-url team), but deserves much more than that. I was
    so hilarious my son came out of it's room and even tried to read the
    post by himself - I just wasn't able to calm down and explain him what
    this was about.
    
    Grant, if we ever meet, remind me to pay you a couple beers. Cheers !
    
    
    From utabintarbo at gmail.com  Tue Nov 24 16:20:25 2009
    From: utabintarbo at gmail.com (utabintarbo)
    Date: Tue, 24 Nov 2009 13:20:25 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    Message-ID: 
    
    On Nov 24, 3:27?pm, MRAB  wrote:
    >
    > .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > it returns.
    >
    > Could you provide some code which shows your problem?
    
    Here is the code block I have so far:
    for l in open(CONTENTS, 'r').readlines():
        f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
        if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
            shutil.rmtree(os.path.join(DIR1,f))
    	if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    		shutil.rmtree(os.path.join(DIR2,f))
    
    I am trying to find dirs with the basename of the initial path less
    the extension in both DIR1 and DIR2
    
    A minimally obfuscated line from the log file:
    K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602
    
    What I get from the debugger/python shell:
    'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602'
    
    TIA
    
    
    
    From joncle at googlemail.com  Tue Nov 24 16:36:58 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:36:58 -0800 (PST)
    Subject: Creating a drop down filter in Admin site
    References: <46ba87ce-6843-4d89-b80c-4f3c1e20bc09@e22g2000vbm.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 9:08?pm, Jase  wrote:
    > Hoping someone could help me out. I am updating an admin site and
    > added a couple "list_filter"s. They are rather long so I wanted to
    > turn them into a drop down filter. Can this be done? Any suggestions?
    >
    > Thanks,
    >
    > Jase
    
    I'm guessing you mean Django - You may well get advice here, but the
    "Django Users" google group and the associated documentation of
    djangoproject and how to customise the admin interface is your best
    start.
    
    hth,
    Jon.
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 16:45:37 2009
    From: x.sanz35 at gmail.com (Xavier Sanz)
    Date: Tue, 24 Nov 2009 13:45:37 -0800 (PST)
    Subject: Securing a multiprocessing.BaseManager connection via SSL
    References: 
    Message-ID: <221434b3-839d-49db-8c08-4c1f1ececd5f@p33g2000vbn.googlegroups.com>
    
    Hi Jonas
    
    I've having same need so i found a solution but you need to hack a bit
    
    I am using python 2.6.3 but i suppose it could be applicable to your
    case.
    
    First of all u need to edit /usr/lib/python2.6/lib/python2.6/
    multiprocessing/connection.py
    
    This is mine:
    
    #
    # A higher level module for using sockets (or Windows named pipes)
    #
    # multiprocessing/connection.py
    #
    # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
    #
    
    __all__ = [ 'Client', 'Listener', 'Pipe' ]
    
    import os
    import sys
    import socket
    import errno
    import time
    import tempfile
    import itertools
    # Added by Xavi
    import ssl
    
    import _multiprocessing
    from multiprocessing import current_process, AuthenticationError
    from multiprocessing.util import get_temp_dir, Finalize, sub_debug,
    debug
    from multiprocessing.forking import duplicate, close
    
    
    #
    #
    #
    
    BUFSIZE = 8192
    
    _mmap_counter = itertools.count()
    
    default_family = 'AF_INET'
    families = ['AF_INET']
    
    if hasattr(socket, 'AF_UNIX'):
        default_family = 'AF_UNIX'
        families += ['AF_UNIX']
    
    if sys.platform == 'win32':
        default_family = 'AF_PIPE'
        families += ['AF_PIPE']
    
    #
    #
    #
    
    def arbitrary_address(family):
        '''
        Return an arbitrary free address for the given family
        '''
        if family == 'AF_INET':
            return ('localhost', 0)
        elif family == 'AF_UNIX':
            return tempfile.mktemp(prefix='listener-', dir=get_temp_dir())
        elif family == 'AF_PIPE':
            return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
                                   (os.getpid(), _mmap_counter.next()))
        else:
            raise ValueError('unrecognized family')
    
    
    def address_type(address):
        '''
        Return the types of the address
    
        This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
        '''
        if type(address) == tuple:
            return 'AF_INET'
        elif type(address) is str and address.startswith('\\\\'):
            return 'AF_PIPE'
        elif type(address) is str:
            return 'AF_UNIX'
        else:
            raise ValueError('address type of %r unrecognized' % address)
    
    #
    # Public functions
    #
    
    class Listener(object):
        '''
        Returns a listener object.
    
        This is a wrapper for a bound socket which is 'listening' for
        connections, or for a Windows named pipe.
        '''
        def __init__(self, address=None, family=None, backlog=1,
    authkey=None, sslsock=True):
            family = family or (address and address_type(address)) \
                     or default_family
            address = address or arbitrary_address(family)
    
            if family == 'AF_PIPE':
                self._listener = PipeListener(address, backlog)
            else:
                self._listener = SocketListener(address, family, backlog,
    sslsock)
            if authkey is not None and not isinstance(authkey, bytes):
                raise TypeError, 'authkey should be a byte string'
    
            self._authkey = authkey
    
        def accept(self):
            '''
            Accept a connection on the bound socket or named pipe of
    `self`.
    
            Returns a `Connection` object.
            '''
            c = self._listener.accept()
            if self._authkey:
                deliver_challenge(c, self._authkey)
                answer_challenge(c, self._authkey)
            return c
    
        def close(self):
            '''
            Close the bound socket or named pipe of `self`.
            '''
            return self._listener.close()
    
        address = property(lambda self: self._listener._address)
        last_accepted = property(lambda self:
    self._listener._last_accepted)
    
    
    def Client(address, family=None, authkey=None, sslsock=True):
        '''
        Returns a connection to the address of a `Listener`
        '''
        family = family or address_type(address)
        if family == 'AF_PIPE':
            c = PipeClient(address)
        else:
            c = SocketClient(address,sslsock)
    
        if authkey is not None and not isinstance(authkey, bytes):
            raise TypeError, 'authkey should be a byte string'
    
        if authkey is not None:
            answer_challenge(c, authkey)
            deliver_challenge(c, authkey)
    
        return c
    
    
    if sys.platform != 'win32':
    
        def Pipe(duplex=True):
            '''
            Returns pair of connection objects at either end of a pipe
            '''
            if duplex:
                s1, s2 = socket.socketpair()
                c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
                c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
                s1.close()
                s2.close()
            else:
                fd1, fd2 = os.pipe()
                c1 = _multiprocessing.Connection(fd1, writable=False)
                c2 = _multiprocessing.Connection(fd2, readable=False)
    
            return c1, c2
    
    else:
    
        from ._multiprocessing import win32
    
        def Pipe(duplex=True):
            '''
            Returns pair of connection objects at either end of a pipe
            '''
            address = arbitrary_address('AF_PIPE')
            if duplex:
                openmode = win32.PIPE_ACCESS_DUPLEX
                access = win32.GENERIC_READ | win32.GENERIC_WRITE
                obsize, ibsize = BUFSIZE, BUFSIZE
            else:
                openmode = win32.PIPE_ACCESS_INBOUND
                access = win32.GENERIC_WRITE
                obsize, ibsize = 0, BUFSIZE
    
            h1 = win32.CreateNamedPipe(
                address, openmode,
                win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
                win32.PIPE_WAIT,
                1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                )
            h2 = win32.CreateFile(
                address, access, 0, win32.NULL, win32.OPEN_EXISTING, 0,
    win32.NULL
                )
            win32.SetNamedPipeHandleState(
                h2, win32.PIPE_READMODE_MESSAGE, None, None
                )
    
            try:
                win32.ConnectNamedPipe(h1, win32.NULL)
            except WindowsError, e:
                if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                    raise
    
            c1 = _multiprocessing.PipeConnection(h1, writable=duplex)
            c2 = _multiprocessing.PipeConnection(h2, readable=duplex)
    
            return c1, c2
    
    #
    # Definitions for connections based on sockets
    #
    
    class SocketListener(object):
        '''
        Representation of a socket which is bound to an address and
    listening
        '''
    # Aadido sslsock por xavi
        def __init__(self, address, family, backlog=1, sslsock=True):
            self._socket = socket.socket(getattr(socket, family))
            if sslsock == True:
                print "SSL Enabled"
                self._socket = ssl.wrap_socket
    (self._socket,certfile="cert.pem",server_side=True,ssl_version=ssl.PROTOCOL_TLSv1)
            self._socket.setsockopt(socket.SOL_SOCKET,
    socket.SO_REUSEADDR, 1)
            self._socket.bind(address)
            self._socket.listen(backlog)
            self._address = self._socket.getsockname()
            self._family = family
            self._last_accepted = None
    
            if family == 'AF_UNIX':
                self._unlink = Finalize(
                    self, os.unlink, args=(address,), exitpriority=0
                    )
            else:
                self._unlink = None
    
    
        def accept(self):
            s, self._last_accepted = self._socket.accept()
            fd = duplicate(s.fileno())
            conn = _multiprocessing.Connection(fd)
            s.close()
            return conn
    
        def close(self):
            self._socket.close()
            if self._unlink is not None:
                self._unlink()
    
    
    def SocketClient(address, sslsock=True):
        '''
        Return a connection object connected to the socket given by
    `address`
        '''
        family = address_type(address)
        s = socket.socket( getattr(socket, family) )
        if sslsock == True:
            '''
            print "SSL Enabled"
            '''
            s = ssl.wrap_socket
    (s,ssl_version=ssl.PROTOCOL_TLSv1,cert_reqs=ssl.CERT_NONE,ca_certs=None)
        while 1:
            try:
                s.connect(address)
            except socket.error, e:
                if e.args[0] != errno.ECONNREFUSED: # connection refused
                    debug('failed to connect to address %s', address)
                    raise
                time.sleep(0.01)
            else:
                break
        else:
            raise
    
        fd = duplicate(s.fileno())
        conn = _multiprocessing.Connection(fd)
        s.close()
        return conn
    
    #
    # Definitions for connections based on named pipes
    #
    
    if sys.platform == 'win32':
    
        class PipeListener(object):
            '''
            Representation of a named pipe
            '''
            def __init__(self, address, backlog=None):
                self._address = address
                handle = win32.CreateNamedPipe(
                    address, win32.PIPE_ACCESS_DUPLEX,
                    win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    |
                    win32.PIPE_WAIT,
                    win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
                    win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                    )
                self._handle_queue = [handle]
                self._last_accepted = None
    
                sub_debug('listener created with address=%r',
    self._address)
    
                self.close = Finalize(
                    self, PipeListener._finalize_pipe_listener,
                    args=(self._handle_queue, self._address),
    exitpriority=0
                    )
    
            def accept(self):
                newhandle = win32.CreateNamedPipe(
                    self._address, win32.PIPE_ACCESS_DUPLEX,
                    win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    |
                    win32.PIPE_WAIT,
                    win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
                    win32.NMPWAIT_WAIT_FOREVER, win32.NULL
                    )
                self._handle_queue.append(newhandle)
                handle = self._handle_queue.pop(0)
                try:
                    win32.ConnectNamedPipe(handle, win32.NULL)
                except WindowsError, e:
                    if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                        raise
                return _multiprocessing.PipeConnection(handle)
    
            @staticmethod
            def _finalize_pipe_listener(queue, address):
                sub_debug('closing listener with address=%r', address)
                for handle in queue:
                    close(handle)
    
        def PipeClient(address):
            '''
            Return a connection object connected to the pipe given by
    `address`
            '''
            while 1:
                try:
                    win32.WaitNamedPipe(address, 1000)
                    h = win32.CreateFile(
                        address, win32.GENERIC_READ | win32.GENERIC_WRITE,
                        0, win32.NULL, win32.OPEN_EXISTING, 0, win32.NULL
                        )
                except WindowsError, e:
                    if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
                                         win32.ERROR_PIPE_BUSY):
                        raise
                else:
                    break
            else:
                raise
    
            win32.SetNamedPipeHandleState(
                h, win32.PIPE_READMODE_MESSAGE, None, None
                )
            return _multiprocessing.PipeConnection(h)
    
    #
    # Authentication stuff
    #
    
    MESSAGE_LENGTH = 20
    
    CHALLENGE = b'#CHALLENGE#'
    WELCOME = b'#WELCOME#'
    FAILURE = b'#FAILURE#'
    
    def deliver_challenge(connection, authkey):
        import hmac
        assert isinstance(authkey, bytes)
        message = os.urandom(MESSAGE_LENGTH)
        connection.send_bytes(CHALLENGE + message)
        digest = hmac.new(authkey, message).digest()
        response = connection.recv_bytes(256)        # reject large
    message
        if response == digest:
            connection.send_bytes(WELCOME)
        else:
            connection.send_bytes(FAILURE)
            raise AuthenticationError('digest received was wrong')
    
    def answer_challenge(connection, authkey):
        import hmac
        assert isinstance(authkey, bytes)
        message = connection.recv_bytes(256)         # reject large
    message
        assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' %
    message
        message = message[len(CHALLENGE):]
        digest = hmac.new(authkey, message).digest()
        connection.send_bytes(digest)
        response = connection.recv_bytes(256)        # reject large
    message
        if response != WELCOME:
            raise AuthenticationError('digest sent was rejected')
    
    #
    # Support for using xmlrpclib for serialization
    #
    
    class ConnectionWrapper(object):
        def __init__(self, conn, dumps, loads):
            self._conn = conn
            self._dumps = dumps
            self._loads = loads
            for attr in ('fileno', 'close', 'poll', 'recv_bytes',
    'send_bytes'):
                obj = getattr(conn, attr)
                setattr(self, attr, obj)
        def send(self, obj):
            s = self._dumps(obj)
            self._conn.send_bytes(s)
        def recv(self):
            s = self._conn.recv_bytes()
            return self._loads(s)
    
    def _xml_dumps(obj):
        return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf8')
    
    def _xml_loads(s):
        (obj,), method = xmlrpclib.loads(s.decode('utf8'))
        return obj
    
    class XmlListener(Listener):
        def accept(self):
            global xmlrpclib
            import xmlrpclib
            obj = Listener.accept(self)
            return ConnectionWrapper(obj, _xml_dumps, _xml_loads)
    
    def XmlClient(*args, **kwds):
        global xmlrpclib
        import xmlrpclib
        return ConnectionWrapper(Client(*args, **kwds), _xml_dumps,
    _xml_loads)
    
    ================================
    
    If u take a look u can observe i've imported ssl module and added a
    sslsock parameter in SocketListener and SocketClient.
    
    There is a certificate file required called 'cert.pem', you can
    generate one by typing this:
    
    openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
    
    In same directory where your python server program runs.
    
    Encryption it's setup to AES-256 and mandatory, so it would raise and
    error if certificate file is missing.
    
    U don't need to change any code in your program.
    
    U can use tcpdump or wireshark to test that it works.
    
    
    
    
    
    
    
    
    On 6 nov, 15:56, Jonas  wrote:
    > Hi,
    > how can I secure the communication between two BaseManager objects?
    > Regarding the socket/SSL documentation I just need to secure the
    > socket by SSL. How can i get the socket object within themultiprocessing
    > module?
    >
    > Best regards,
    >
    > Jonas
    
    
    
    From joncle at googlemail.com  Tue Nov 24 16:50:57 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:50:57 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    Message-ID: <040a9c29-a8f2-4485-ab5f-4babd9484a0b@m20g2000vbp.googlegroups.com>
    
    On Nov 24, 9:20?pm, utabintarbo  wrote:
    > On Nov 24, 3:27?pm, MRAB  wrote:
    >
    >
    >
    > > .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > > it returns.
    >
    > > Could you provide some code which shows your problem?
    >
    > Here is the code block I have so far:
    > for l in open(CONTENTS, 'r').readlines():
    > ? ? f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    > ? ? if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    > ? ? ? ? shutil.rmtree(os.path.join(DIR1,f))
    > ? ? ? ? if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    > ? ? ? ? ? ? ? ? shutil.rmtree(os.path.join(DIR2,f))
    >
    > I am trying to find dirs with the basename of the initial path less
    > the extension in both DIR1 and DIR2
    >
    > A minimally obfuscated line from the log file:
    > K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602
    >
    > What I get from the debugger/python shell:
    > 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602'
    >
    > TIA
    
    jon at jon-desktop:~/pytest$ cat log.txt
    K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    11/24/2009 08:16:42 ; 1259068602
    
    >>> log = open('/home/jon/pytest/log.txt', 'r').readlines()
    >>> log
    ['K:\\sm\\SMI\\des\\RS\\Pat\\10DJ\\121.D5-30\\1215B-B-D5-BSHOE-MM.smz-
    >/arch_m1/\n', 'smi/des/RS/Pat/10DJ/121.D5-30\\1215B-B-D5-BSHOE-
    MM.smz ; t9480rc ;\n', '11/24/2009 08:16:42 ; 1259068602\n']
    
    See -- it's not doing anything :)
    
    Although, "Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" and "Pat
    \x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" seem to be fairly different -- are
    you sure you're posting the correct output!?
    
    Jon.
    
    
    From joncle at googlemail.com  Tue Nov 24 16:54:13 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:54:13 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	<040a9c29-a8f2-4485-ab5f-4babd9484a0b@m20g2000vbp.googlegroups.com>
    Message-ID: 
    
    On Nov 24, 9:50?pm, Jon Clements  wrote:
    > On Nov 24, 9:20?pm, utabintarbo  wrote:
    [snip]
    > Although, "Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" and "Pat
    > \x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" seem to be fairly different -- are
    > you sure you're posting the correct output!?
    >
    
    Ugh... let's try that...
    
    Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz
    Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz
    
    Jon.
    
    
    From joncle at googlemail.com  Tue Nov 24 16:59:54 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Tue, 24 Nov 2009 13:59:54 -0800 (PST)
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    	<4b0c4dbb$0$8926$426a74cc@news.free.fr>
    Message-ID: <783624a8-4591-4360-aebe-6b8e6702c132@x15g2000vbr.googlegroups.com>
    
    On Nov 24, 8:21?pm, Bruno Desthuilliers
     wrote:
    > Cameron Laird a ?crit :
    >
    >
    >
    > > ? ? Grant Edwards on the best way to get help from this group :)
    > > ? ? ? ?http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21...
    >
    > This one really deserves a POTM award !-)
    
    Absolutely -- thumbs up to Grant.
    
    All we need to do is merge in the other bullet points, and put it as a
    "How-To-Not-Post-FAQ" :)
    
    Jon.
    
    
    From __peter__ at web.de  Tue Nov 24 17:02:27 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Tue, 24 Nov 2009 23:02:27 +0100
    Subject: csv and mixed lists of unicode and numbers
    References: 
    	
    	
    Message-ID: 
    
    Sibylle Koczian wrote:
    
    > This problem really goes away with Python 3 (tried it on another
    > machine), but something else changes too: in Python 2.6 the
    > documentation for the csv module explicitly says "If csvfile is a file
    > object, it must be opened with the ?b? flag on platforms where that
    > makes a difference." The documentation for Python 3.1 doesn't have this
    > sentence, and if I do that in Python 3.1 I get for all sorts of data,
    > even for a list with only one integer literal:
    > 
    > TypeError: must be bytes or buffer, not str
    
    Read the documentation for open() at
    
    http://docs.python.org/3.1/library/functions.html#open
    
    There are significant changes with respect to 2.x; you won't even get a file 
    object anymore:
    
    >>> open("tmp.txt", "w")
    <_io.TextIOWrapper name='tmp.txt' encoding='UTF-8'>
    >>> _.write("yadda")
    5
    >>> open("tmp.dat", "wb")
    <_io.BufferedWriter name='tmp.dat'>
    >>> _.write("yadda")
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: write() argument 1 must be bytes or buffer, not str
    >>> open("tmp.dat", "wb").write(b"yadda")
    5
    
    If you specify the "b" flag in 3.x the write() method expects bytes, not 
    str. The translation of newlines is now controlled by the "newline" 
    argument.
    
    Peter
    
    
    
    From benjamin at python.org  Tue Nov 24 17:08:19 2009
    From: benjamin at python.org (Benjamin Peterson)
    Date: Tue, 24 Nov 2009 22:08:19 +0000 (UTC)
    Subject: pointless musings on performance
    References:  <4B0BD0E4.8030707@mrabarnett.plus.com>
    	
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	 <1259090178.661.34.camel@localhost>
    Message-ID: 
    
    Tim Wintle  teamrubber.com> writes:
    > Out of interest - has anyone else spotted that the call to
    > PyObject_IsTrue in the XXX_JUMP_IF_YYYY blocks performs two unnecessary
    > pointer comparisons?
    
    I doubt two pointer comparisons will make much of a difference.
    
    > Would it be worth in-lining the remaining part of PyObject_IsTrue in
    > ceval?
    
    Inlining by hand is prone to error and maintainability problems.
    
    
    
    
    
    
    From x.sanz35 at gmail.com  Tue Nov 24 17:11:45 2009
    From: x.sanz35 at gmail.com (Xavier Sanz)
    Date: Tue, 24 Nov 2009 14:11:45 -0800 (PST)
    Subject: Securing a multiprocessing.BaseManager connection via SSL
    References: 
    	<221434b3-839d-49db-8c08-4c1f1ececd5f@p33g2000vbn.googlegroups.com>
    Message-ID: <6a9a14a7-6493-4655-b773-dca7fe2640d9@f10g2000vbl.googlegroups.com>
    
    I recommend u to test it before use it in production environment.
    
    On 24 nov, 22:45, Xavier Sanz  wrote:
    > Hi Jonas
    >
    > I've having same need so i found a solution but you need to hack a bit
    >
    > I am using python 2.6.3 but i suppose it could be applicable to your
    > case.
    >
    > First of all u need to edit /usr/lib/python2.6/lib/python2.6/multiprocessing/connection.py
    >
    > This is mine:
    >
    > #
    > # A higher level module for using sockets (or Windows named pipes)
    > #
    > #multiprocessing/connection.py
    > #
    > # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
    > #
    >
    > __all__ = [ 'Client', 'Listener', 'Pipe' ]
    >
    > import os
    > import sys
    > import socket
    > import errno
    > import time
    > import tempfile
    > import itertools
    > # Added by Xavi
    > import ssl
    >
    > import _multiprocessing
    > frommultiprocessingimport current_process, AuthenticationError
    > frommultiprocessing.util import get_temp_dir, Finalize, sub_debug,
    > debug
    > frommultiprocessing.forking import duplicate, close
    >
    > #
    > #
    > #
    >
    > BUFSIZE = 8192
    >
    > _mmap_counter = itertools.count()
    >
    > default_family = 'AF_INET'
    > families = ['AF_INET']
    >
    > if hasattr(socket, 'AF_UNIX'):
    > ? ? default_family = 'AF_UNIX'
    > ? ? families += ['AF_UNIX']
    >
    > if sys.platform == 'win32':
    > ? ? default_family = 'AF_PIPE'
    > ? ? families += ['AF_PIPE']
    >
    > #
    > #
    > #
    >
    > def arbitrary_address(family):
    > ? ? '''
    > ? ? Return an arbitrary free address for the given family
    > ? ? '''
    > ? ? if family == 'AF_INET':
    > ? ? ? ? return ('localhost', 0)
    > ? ? elif family == 'AF_UNIX':
    > ? ? ? ? return tempfile.mktemp(prefix='listener-', dir=get_temp_dir())
    > ? ? elif family == 'AF_PIPE':
    > ? ? ? ? return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
    > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(os.getpid(), _mmap_counter.next()))
    > ? ? else:
    > ? ? ? ? raise ValueError('unrecognized family')
    >
    > def address_type(address):
    > ? ? '''
    > ? ? Return the types of the address
    >
    > ? ? This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    > ? ? '''
    > ? ? if type(address) == tuple:
    > ? ? ? ? return 'AF_INET'
    > ? ? elif type(address) is str and address.startswith('\\\\'):
    > ? ? ? ? return 'AF_PIPE'
    > ? ? elif type(address) is str:
    > ? ? ? ? return 'AF_UNIX'
    > ? ? else:
    > ? ? ? ? raise ValueError('address type of %r unrecognized' % address)
    >
    > #
    > # Public functions
    > #
    >
    > class Listener(object):
    > ? ? '''
    > ? ? Returns a listener object.
    >
    > ? ? This is a wrapper for a bound socket which is 'listening' for
    > ? ? connections, or for a Windows named pipe.
    > ? ? '''
    > ? ? def __init__(self, address=None, family=None, backlog=1,
    > authkey=None, sslsock=True):
    > ? ? ? ? family = family or (address and address_type(address)) \
    > ? ? ? ? ? ? ? ? ?or default_family
    > ? ? ? ? address = address or arbitrary_address(family)
    >
    > ? ? ? ? if family == 'AF_PIPE':
    > ? ? ? ? ? ? self._listener = PipeListener(address, backlog)
    > ? ? ? ? else:
    > ? ? ? ? ? ? self._listener = SocketListener(address, family, backlog,
    > sslsock)
    > ? ? ? ? if authkey is not None and not isinstance(authkey, bytes):
    > ? ? ? ? ? ? raise TypeError, 'authkey should be a byte string'
    >
    > ? ? ? ? self._authkey = authkey
    >
    > ? ? def accept(self):
    > ? ? ? ? '''
    > ? ? ? ? Accept a connection on the bound socket or named pipe of
    > `self`.
    >
    > ? ? ? ? Returns a `Connection` object.
    > ? ? ? ? '''
    > ? ? ? ? c = self._listener.accept()
    > ? ? ? ? if self._authkey:
    > ? ? ? ? ? ? deliver_challenge(c, self._authkey)
    > ? ? ? ? ? ? answer_challenge(c, self._authkey)
    > ? ? ? ? return c
    >
    > ? ? def close(self):
    > ? ? ? ? '''
    > ? ? ? ? Close the bound socket or named pipe of `self`.
    > ? ? ? ? '''
    > ? ? ? ? return self._listener.close()
    >
    > ? ? address = property(lambda self: self._listener._address)
    > ? ? last_accepted = property(lambda self:
    > self._listener._last_accepted)
    >
    > def Client(address, family=None, authkey=None, sslsock=True):
    > ? ? '''
    > ? ? Returns a connection to the address of a `Listener`
    > ? ? '''
    > ? ? family = family or address_type(address)
    > ? ? if family == 'AF_PIPE':
    > ? ? ? ? c = PipeClient(address)
    > ? ? else:
    > ? ? ? ? c = SocketClient(address,sslsock)
    >
    > ? ? if authkey is not None and not isinstance(authkey, bytes):
    > ? ? ? ? raise TypeError, 'authkey should be a byte string'
    >
    > ? ? if authkey is not None:
    > ? ? ? ? answer_challenge(c, authkey)
    > ? ? ? ? deliver_challenge(c, authkey)
    >
    > ? ? return c
    >
    > if sys.platform != 'win32':
    >
    > ? ? def Pipe(duplex=True):
    > ? ? ? ? '''
    > ? ? ? ? Returns pair of connection objects at either end of a pipe
    > ? ? ? ? '''
    > ? ? ? ? if duplex:
    > ? ? ? ? ? ? s1, s2 = socket.socketpair()
    > ? ? ? ? ? ? c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
    > ? ? ? ? ? ? c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
    > ? ? ? ? ? ? s1.close()
    > ? ? ? ? ? ? s2.close()
    > ? ? ? ? else:
    > ? ? ? ? ? ? fd1, fd2 = os.pipe()
    > ? ? ? ? ? ? c1 = _multiprocessing.Connection(fd1, writable=False)
    > ? ? ? ? ? ? c2 = _multiprocessing.Connection(fd2, readable=False)
    >
    > ? ? ? ? return c1, c2
    >
    > else:
    >
    > ? ? from ._multiprocessing import win32
    >
    > ? ? def Pipe(duplex=True):
    > ? ? ? ? '''
    > ? ? ? ? Returns pair of connection objects at either end of a pipe
    > ? ? ? ? '''
    > ? ? ? ? address = arbitrary_address('AF_PIPE')
    > ? ? ? ? if duplex:
    > ? ? ? ? ? ? openmode = win32.PIPE_ACCESS_DUPLEX
    > ? ? ? ? ? ? access = win32.GENERIC_READ | win32.GENERIC_WRITE
    > ? ? ? ? ? ? obsize, ibsize = BUFSIZE, BUFSIZE
    > ? ? ? ? else:
    > ? ? ? ? ? ? openmode = win32.PIPE_ACCESS_INBOUND
    > ? ? ? ? ? ? access = win32.GENERIC_WRITE
    > ? ? ? ? ? ? obsize, ibsize = 0, BUFSIZE
    >
    > ? ? ? ? h1 = win32.CreateNamedPipe(
    > ? ? ? ? ? ? address, openmode,
    > ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE |
    > ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? 1, obsize, ibsize, win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? )
    > ? ? ? ? h2 = win32.CreateFile(
    > ? ? ? ? ? ? address, access, 0, win32.NULL, win32.OPEN_EXISTING, 0,
    > win32.NULL
    > ? ? ? ? ? ? )
    > ? ? ? ? win32.SetNamedPipeHandleState(
    > ? ? ? ? ? ? h2, win32.PIPE_READMODE_MESSAGE, None, None
    > ? ? ? ? ? ? )
    >
    > ? ? ? ? try:
    > ? ? ? ? ? ? win32.ConnectNamedPipe(h1, win32.NULL)
    > ? ? ? ? except WindowsError, e:
    > ? ? ? ? ? ? if e.args[0] != win32.ERROR_PIPE_CONNECTED:
    > ? ? ? ? ? ? ? ? raise
    >
    > ? ? ? ? c1 = _multiprocessing.PipeConnection(h1, writable=duplex)
    > ? ? ? ? c2 = _multiprocessing.PipeConnection(h2, readable=duplex)
    >
    > ? ? ? ? return c1, c2
    >
    > #
    > # Definitions for connections based on sockets
    > #
    >
    > class SocketListener(object):
    > ? ? '''
    > ? ? Representation of a socket which is bound to an address and
    > listening
    > ? ? '''
    > # Aadido sslsock por xavi
    > ? ? def __init__(self, address, family, backlog=1, sslsock=True):
    > ? ? ? ? self._socket = socket.socket(getattr(socket, family))
    > ? ? ? ? if sslsock == True:
    > ? ? ? ? ? ? print "SSL Enabled"
    > ? ? ? ? ? ? self._socket = ssl.wrap_socket
    > (self._socket,certfile="cert.pem",server_side=True,ssl_version=ssl.PROTOCOL_TLSv1)
    > ? ? ? ? self._socket.setsockopt(socket.SOL_SOCKET,
    > socket.SO_REUSEADDR, 1)
    > ? ? ? ? self._socket.bind(address)
    > ? ? ? ? self._socket.listen(backlog)
    > ? ? ? ? self._address = self._socket.getsockname()
    > ? ? ? ? self._family = family
    > ? ? ? ? self._last_accepted = None
    >
    > ? ? ? ? if family == 'AF_UNIX':
    > ? ? ? ? ? ? self._unlink = Finalize(
    > ? ? ? ? ? ? ? ? self, os.unlink, args=(address,), exitpriority=0
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? else:
    > ? ? ? ? ? ? self._unlink = None
    >
    > ? ? def accept(self):
    > ? ? ? ? s, self._last_accepted = self._socket.accept()
    > ? ? ? ? fd = duplicate(s.fileno())
    > ? ? ? ? conn = _multiprocessing.Connection(fd)
    > ? ? ? ? s.close()
    > ? ? ? ? return conn
    >
    > ? ? def close(self):
    > ? ? ? ? self._socket.close()
    > ? ? ? ? if self._unlink is not None:
    > ? ? ? ? ? ? self._unlink()
    >
    > def SocketClient(address, sslsock=True):
    > ? ? '''
    > ? ? Return a connection object connected to the socket given by
    > `address`
    > ? ? '''
    > ? ? family = address_type(address)
    > ? ? s = socket.socket( getattr(socket, family) )
    > ? ? if sslsock == True:
    > ? ? ? ? '''
    > ? ? ? ? print "SSL Enabled"
    > ? ? ? ? '''
    > ? ? ? ? s = ssl.wrap_socket
    > (s,ssl_version=ssl.PROTOCOL_TLSv1,cert_reqs=ssl.CERT_NONE,ca_certs=None)
    > ? ? while 1:
    > ? ? ? ? try:
    > ? ? ? ? ? ? s.connect(address)
    > ? ? ? ? except socket.error, e:
    > ? ? ? ? ? ? if e.args[0] != errno.ECONNREFUSED: # connection refused
    > ? ? ? ? ? ? ? ? debug('failed to connect to address %s', address)
    > ? ? ? ? ? ? ? ? raise
    > ? ? ? ? ? ? time.sleep(0.01)
    > ? ? ? ? else:
    > ? ? ? ? ? ? break
    > ? ? else:
    > ? ? ? ? raise
    >
    > ? ? fd = duplicate(s.fileno())
    > ? ? conn = _multiprocessing.Connection(fd)
    > ? ? s.close()
    > ? ? return conn
    >
    > #
    > # Definitions for connections based on named pipes
    > #
    >
    > if sys.platform == 'win32':
    >
    > ? ? class PipeListener(object):
    > ? ? ? ? '''
    > ? ? ? ? Representation of a named pipe
    > ? ? ? ? '''
    > ? ? ? ? def __init__(self, address, backlog=None):
    > ? ? ? ? ? ? self._address = address
    > ? ? ? ? ? ? handle = win32.CreateNamedPipe(
    > ? ? ? ? ? ? ? ? address, win32.PIPE_ACCESS_DUPLEX,
    > ? ? ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    > |
    > ? ? ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? ? ? win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
    > ? ? ? ? ? ? ? ? win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? ? ? self._handle_queue = [handle]
    > ? ? ? ? ? ? self._last_accepted = None
    >
    > ? ? ? ? ? ? sub_debug('listener created with address=%r',
    > self._address)
    >
    > ? ? ? ? ? ? self.close = Finalize(
    > ? ? ? ? ? ? ? ? self, PipeListener._finalize_pipe_listener,
    > ? ? ? ? ? ? ? ? args=(self._handle_queue, self._address),
    > exitpriority=0
    > ? ? ? ? ? ? ? ? )
    >
    > ? ? ? ? def accept(self):
    > ? ? ? ? ? ? newhandle = win32.CreateNamedPipe(
    > ? ? ? ? ? ? ? ? self._address, win32.PIPE_ACCESS_DUPLEX,
    > ? ? ? ? ? ? ? ? win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE
    > |
    > ? ? ? ? ? ? ? ? win32.PIPE_WAIT,
    > ? ? ? ? ? ? ? ? win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
    > ? ? ? ? ? ? ? ? win32.NMPWAIT_WAIT_FOREVER, win32.NULL
    > ? ? ? ? ? ? ? ? )
    > ? ? ? ? ? ? self._handle_queue.append(newhandle)
    > ? ? ? ? ? ? handle = self._handle_queue.pop(0)
    > ? ? ? ? ? ? try:
    > ? ? ? ? ? ? ? ? win32.ConnectNamedPipe(handle, win32.NULL)
    > ? ? ? ? ? ? except WindowsError, e:
    > ? ? ? ? ? ? ? ? if e.args[0] != win32.ERROR_PIPE_CONNECTED:
    > ? ? ? ? ? ? ? ? ? ? raise
    > ? ? ? ? ? ? return _multiprocessing.PipeConnection(handle)
    >
    > ? ? ? ? @staticmethod
    > ? ? ? ? def _finalize_pipe_listener(queue, address):
    > ? ? ? ? ? ? sub_debug('closing listener with address=%r', address)
    > ? ? ? ? ? ? for handle in queue:
    > ? ? ? ? ? ? ? ? close(handle)
    >
    > ? ? def PipeClient(address):
    > ? ? ? ? '''
    > ? ? ? ? Return a connection object connected to the pipe given by...
    >
    > leer m?s ?
    
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:14:15 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:14:15 -0500
    Subject: pointless musings on performance
    In-Reply-To: <50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    References: 	
    	<50697b2c0911240443s29aa4cf0u3700d72148f2ba17@mail.gmail.com>
    Message-ID: 
    
    Chris Rebert wrote:
    > On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft  wrote:
    >> mk wrote in news:mailman.915.1259064240.2873.python-list at python.org in
    >> comp.lang.python:
    >>
    >>> def pythonic():
    >>> def unpythonic():
    >>
    >>> Decidedly counterintuitive: are there special optimizations for "if
    >>> nonevar:" type of statements in cpython implementation?
    >>>
    >> from dis import dis
    >>
    >> dis( unpythonic )
    >>
    >> 18          31 LOAD_FAST                0 (nonevar)
    >>             34 LOAD_CONST               0 (None)
    >>             37 COMPARE_OP               9 (is not)
    >>             40 JUMP_IF_FALSE            4 (to 47)
    >>
    >> dis( pythonic )
    >>
    >> 11          31 LOAD_FAST                0 (nonevar)
    >>             34 JUMP_IF_FALSE            4 (to 41)
    > 
    > In other words, CPython doesn't happen to optimize `if nonevar is not
    > None` as much as it theoretically could (which would essentially
    > require a JUMP_IF_NONE opcode). Since CPython isn't known for doing
    > fancy optimizations, this isn't surprising.
    
    There is a limit of 256 bytecodes. I believe there are currently fewer. 
    It would seem that adding bytecodes that combine current pairs would 
    speed the interpreter, depending on how often the combined pair is used. 
    And people have looked for frequent pairs across a corpus of code, and 
    proposed additions.
    
    However, additional bytecodes enlarge the basic bytecode eval loop, 
    possibly (and sometimes actually) leading to to more processor cache 
    misses and slower execution. At least some proposed non-essential 
    additions have been rejected for the reason.
    
    Also, even though CPython-specific bytecodes are outside the language 
    definition, and could theoretically be revamped every minor (x.y) 
    release, there is a cost to change. Rewrite the ast to bytecode 
    compiler, rewrite dis, rewrite the dis doc, and burden anyone concerned 
    with multiple versions to remember. So in practice, change is minimized 
    and unassigned bytecodes are left open for the future.
    
    Optimizations that make better use of a fix set of bytecodes are a 
    different topic. Guido is conservative because historically, compilier 
    optimizations are too often not exactly equivalent to naive, obviously 
    correct code in some overlooked corner case, leading to subtle, 
    occasional bugs. Of course, byte code changes could mess-up current 
    optimizations that are performed.
    
    Terry Jan Reedy
    
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:29:35 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:29:35 -0500
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>	<7n01t8F3jijv0U1@mid.uni-berlin.de>			<8c633940-bf45-4fba-b71a-4c9974f0da28@u20g2000vbq.googlegroups.com>	
    	
    Message-ID: 
    
    Peter Otten wrote:
    > Terry Reedy wrote:
    
    >> remember exactly what was stored. Maybe a typo.
    > 
    > That's a bug in the store() function
    > 
    > # as posted
    > def store(data, full_name):
    >     names = full_name.split()
    >     if len(names) == 2: names.insert(1, '')
    >     labels = 'first', 'middle', 'last'
    >     for label, name in zip(labels, names):
    >         people = lookup(data, label, name)
    >     if people:
    >         people.append(full_name)
    >     else:
    >         data[label][name] = [full_name]
    > 
    > # what was probably intended
    > def store(data, full_name):
    >     names = full_name.split()
    >     if len(names) == 2: names.insert(1, '')
    >     labels = 'first', 'middle', 'last'
    >     for label, name in zip(labels, names):
    >         people = lookup(data, label, name)
    >         if people:
    >             people.append(full_name)
    >         else:
    >             data[label][name] = [full_name]
    
    (Note indent error, which I overlooked)
    It is a nuisance when people post untested code, without identifying it 
    as such. Publishing untested but trivial-to-test code like this (one 
    print statement needed), especially in a book for learners, is really bad.
    
    (I am trying to do better in the book I am working on.)
    
    tjr
    
    
    
    From hansmu at xs4all.nl  Tue Nov 24 17:38:03 2009
    From: hansmu at xs4all.nl (Hans Mulder)
    Date: Tue, 24 Nov 2009 23:38:03 +0100
    Subject: Perl conversion to python...
    In-Reply-To: <858wdx41ol.fsf@agentultra.com>
    References: <3fcabac5-f837-46a4-81f5-5da46b548538@l35g2000vba.googlegroups.com>
    	<858wdx41ol.fsf@agentultra.com>
    Message-ID: <4b0c60ba$0$22940$e4fe514c@news.xs4all.nl>
    
    J Kenneth King wrote:
    > Benjamin Schollnick  writes:
    
    >> 		select(undef, undef, undef, 0.01);
    
    >         # select() is a system call in Perl..
    >         # insert Python equivalent here
    
    That would be:
    
               time.sleep(0.01)
    
    Perl has a sleep() built-in, but it truncates its argument to an int.
    If you want to sleep less than a second in Perl, you have to use select
    as shown.
    
    Not so in Python.  Python's time.sleep() takes a float argument and
    calls some platform-dependent function that provides sleeping with
    sub-second accuracy.  On some platforms, it ends up calling the
    C level select() function.
    
    Keep in mind that in both languages, your program may end up sleeping
    longer than it should due to scheduling or other activity on the system.
    
    
    Hope this helps,
    
    -- HansM
    
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 17:43:32 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 22:43:32 GMT
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    	
    Message-ID: <031c4f72$0$1336$c3e8da3@news.astraweb.com>
    
    On Tue, 24 Nov 2009 13:19:10 -0500, Chris Jones wrote:
    
    > On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    > 
    >> Good grief, it's about six weeks away from 2010 and Thunderbird still
    >> uses mbox as it's default mail box format. Hello, the nineties called,
    >> they want their mail formats back! Are the tbird developers on crack or
    >> something? I can't believe that they're still using that crappy format.
    >> 
    >> No, I tell a lie. I can believe it far too well.
    > 
    > :-)
    > 
    > I realize that's somewhat OT, but what mail box format do you recommend,
    > and why?
    
    maildir++
    
    http://en.wikipedia.org/wiki/Maildir
    
    Corruption is less likely, if there is corruption you'll only lose a 
    single message rather than potentially everything in the mail folder[*], 
    at a pinch you can read the emails using a text editor or easily grep 
    through them, and compacting the mail folder is lightning fast, there's 
    no wasted space in the mail folder, and there's no need to mangle lines 
    starting with "From " in the body of the email.
    
    The only major downside is that because you're dealing with potentially 
    thousands of smallish files, it *may* have reduced performance on some 
    older file systems that don't deal well with lots of files. These days, 
    that's not a real issue.
    
    Oh yes, and people using Windows can't use maildir because (1) it doesn't 
    allow colons in names, and (2) it doesn't have atomic renames. Neither of 
    these are insurmountable problems: an implementation could substitute 
    another character for the colon, and while that would be a technical 
    violation of the standard, it would still work. And the lack of atomic 
    renames would simply mean that implementations have to be more careful 
    about not having two threads writing to the one mailbox at the same time.
    
    
    
    
    [*] I'm assuming normal "oops there's a bug in the mail client code" 
    corruption rather than "I got drunk and started deleting random files and 
    directories" corruption.
    
    
    
    -- 
    Steven
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Tue Nov 24 17:45:37 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 24 Nov 2009 22:45:37 GMT
    Subject: Where to put the error handing test?
    References: 
    	<4b0b56ea$1@dnews.tpgi.com.au>
    	<366c6f340911232008v2fb4da04k8c4339dd9fd37e3c@mail.gmail.com>
    	<4B0BBC62.7020702@ieee.org>
    	
    Message-ID: <031c4fee$0$1336$c3e8da3@news.astraweb.com>
    
    On Tue, 24 Nov 2009 10:14:19 -0600, Peng Yu wrote:
    
    > I'll still confused by the guideline that an error should be caught as
    > early as possible.
    
    I think you are confused by what that means. It means the error should be 
    caught as early as possible in *time*, not in the function chain.
    
    In Python, errors are always generated as soon as they occur. But imagine 
    a system where you have a function that returns -1 on error and some 
    integer on success. Then it is possible for that -1 error code to be 
    passed along from one function to another to another to another before 
    finally causing a fatal error, by which time you have no idea where it 
    came from. That's what should be prohibited.
    
    
    
    > Suppose I have the following call chain
    > 
    > f1() --> f2() --> f3() --> f4()
    > 
    > The input in f1() might cause an error in f4(). 
    
    Assuming that none of the functions have side-effects, then f4 is the 
    right place to catch the error. To do otherwise means that f1 needs to 
    know all the possible things that can go wrong in f2, and f3, and f4.
    
    
    > However, this error can
    > of cause be caught by f1(), whenever I want to do so. In the worst case,
    > I could duplicate the code of f2 and f3, and the test code in f4 to
    > f1(), to catch the error in f1 rather than f4. But I don't think that
    > this is what you mean.
    > 
    > Then the problem is where to put the test code more effectively. I would
    > consider 'whether it is obvious to test the condition in the give
    > function' as the guideline. However, it might be equal obvious to test
    > the same thing two functions, for example, f1 and f4.
    
    You're not a mathematician, are you?
    
    For each function, define its domain: the values it must work with. 
    Suppose f1 should return a result for (e.g.) all integers, but f2 only 
    returns a result for *positive* integers.
    
    Then it is very simple: f2 will raise an error if given zero or negative 
    values, and so f1 must either:
    
    * avoid that error by handling zero or negative separately; or
    * catch the error and then handle zero or negative separately.
    
    Simplified example:
    
    def f2(x):
        if x > 0:
            return x+1
        raise ValueError
    
    
    def f1(x):  # version 1
        if x > 0:
            return f2(x)
        else:
            return "something else"
    
    # or
    
    def f1(x):  # version 2
        try:
            return f2(x)
        except ValueError:
            return "something else"
    
    
    Version two is the preferred way to do it, since that means f1 doesn't 
    need to know what the domain of f2 is. But if f2 has side-effects 
    (usually a bad idea) then version one is better.
    
    
    But what if f1 and f2 have the same domain?
    
    Then it is very simple: put the error checking wherever it makes sense. 
    If f2 is public, put the error checking there, and then f1 can avoid 
    duplicating the error checking.
    
    But what if f1 has the more restrictive domain? Then put the error 
    checking in f1.
    
    
    -- 
    Steven
    
    
    From tjreedy at udel.edu  Tue Nov 24 17:55:11 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 17:55:11 -0500
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 	
    	
    Message-ID: 
    
    Sibylle Koczian wrote:
    > Peter Otten schrieb:
    >> I'd preprocess the rows as I tend to prefer the simplest approach I can come 
    >> up with. Example:
    >>
    >> def recode_rows(rows, source_encoding, target_encoding):
    >>     def recode(field):
    >>         if isinstance(field, unicode):
    >>             return field.encode(target_encoding)
    >>         elif isinstance(field, str):
    >>             return unicode(field, source_encoding).encode(target_encoding)
    >>         return unicode(field).encode(target_encoding)
    >>
    >>     return (map(recode, row) for row in rows)
    >>
    > 
    > For this case isinstance really seems to be quite reasonable. And it was
    > silly of me not to think of sys.stdout as file object for the example!
    > 
    >> rows = [[1.23], [u"???"], [u"???".encode("latin1")], [1, 2, 3]]
    >> writer = csv.writer(sys.stdout)
    >> writer.writerows(recode_rows(rows, "latin1", "utf-8"))
    >>
    >> The only limitation I can see: target_encoding probably has to be a superset 
    >> of ASCII.
    >>
    > 
    > Coping with umlauts and accents is quite enough for me.
    > 
    > This problem really goes away with Python 3 (tried it on another
    > machine), but something else changes too: in Python 2.6 the
    > documentation for the csv module explicitly says "If csvfile is a file
    > object, it must be opened with the ?b? flag on platforms where that
    > makes a difference." The documentation for Python 3.1 doesn't have this
    > sentence, and if I do that in Python 3.1 I get for all sorts of data,
    > even for a list with only one integer literal:
    > 
    > TypeError: must be bytes or buffer, not str
    > 
    > I don't really understand that.
    
    In Python 3, a file opened in 'b' mode is for reading and writing bytes 
    with no encoding/decoding. I believe cvs works with files in text mode 
    as it returns and expects strings/text for reading and writing. Perhaps 
    the cvs doc should say must not be opened in 'b' mode. Not sure.
    
    tjr
    
    
    
    From max at alcyone.com  Tue Nov 24 17:59:26 2009
    From: max at alcyone.com (Erik Max Francis)
    Date: Tue, 24 Nov 2009 14:59:26 -0800
    Subject: Python-URL! - weekly Python news and links (Nov 24)
    In-Reply-To: <4b0c4dbb$0$8926$426a74cc@news.free.fr>
    References: <2fe9093f-34cc-4133-b345-c0bac99a0273@o9g2000vbj.googlegroups.com>
    	<4b0c4dbb$0$8926$426a74cc@news.free.fr>
    Message-ID: <_fqdncKvQrbT-JHWnZ2dnUVZ_v5i4p2d@giganews.com>
    
    Bruno Desthuilliers wrote:
    > Cameron Laird a ?crit :
    > 
    >>     Grant Edwards on the best way to get help from this group :)
    >>         http://groups.google.com/group/comp.lang.python/t/b8a0c32cae495522/21e80ac383745d88?#21e80ac383745d88
    > 
    > This one really deserves a POTM award !-)
    
    It is a bit surprising to see on IRC how often people are asking for 
    help but trying desperately to either 1. not provide enough information 
    so that anyone could possibly help, or (even weirder) 2. argue with the 
    people trying to help with them or insist they didn't really need the 
    help anyway once they get the answer they're looking for.  The former is 
    surely just laziness, but there's something psychological going on with 
    the latter.
    
    -- 
    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/Skype erikmaxfrancis
       Nine worlds I remember.
        -- Icelandic Edda of Snorri Sturluson
    
    
    From tjreedy at udel.edu  Tue Nov 24 18:06:20 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Tue, 24 Nov 2009 18:06:20 -0500
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    Message-ID: 
    
    utabintarbo wrote:
    > I have a log file with full Windows paths on a line. eg:
    > K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
    > \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ; 1259006416
    > 
    > As I try to pull in the line and process it, python changes the "\10"
    > to a "\x08".
    
    This should only happen if you paste the test into your .py file as a 
    string literal.
    
    > This is before I can do anything with it. Is there a way
    > to specify that incoming lines (say, when using .readlines() ) should
    > be treated as raw strings?
    
    Or if you use execfile or compile and ask Python to interprete the input 
    as code.
    
    There are no raw strings, only raw string code literals marked with an 
    'r' prefix for raw processing of the quoted text.
    
    
    
    From sjmachin at lexicon.net  Tue Nov 24 18:08:05 2009
    From: sjmachin at lexicon.net (John Machin)
    Date: Tue, 24 Nov 2009 15:08:05 -0800 (PST)
    Subject: Newsgroup for beginners
    References: 
    	<7xiqd9yj8v.fsf@ruckus.brouhaha.com> 
    Message-ID: <59789396-9e9a-4bb5-aa7b-eb9797ddce02@g1g2000pra.googlegroups.com>
    
    On Nov 17, 2:56?pm, Grant Edwards  wrote:
    > On 2009-11-17, Paul Rubin  wrote:
    >
    > > mrholtsr  writes:
    > >> Is there a Python newsgroup for those who are strictly beginners at
    > >> programming and python?
    >
    > > This group has its grouchy moments
    >
    > You've really got to try pretty hard to create one. ?But if you
    > want to, here's how to do it:
    [snip]
    > ?2) Python programs are portable, so don't reveal what OS or
    > ? ? Python version you're using. ?People will ask. Just ignore
    > ? ? them.
    
    Don't supply a traceback, lest you inadvertently divulge such
    information (and more!) e.g.
    
      File "C:\python26\lib\encodings\cp1252.py", line 15, in decode
    
    A good safeguard against accidental disclosure of your Python version
    is to avoid using the default installation folder:
    
    File "C:\snake_teehee_ima_comedian\lib\etc_etc"
    
    This technique, used in a question like "How can I have multiple
    versions of Python installed" gives a good chance of getting a grumpy
    response.
    
    
    From samwyse at gmail.com  Tue Nov 24 18:09:00 2009
    From: samwyse at gmail.com (samwyse)
    Date: Tue, 24 Nov 2009 15:09:00 -0800 (PST)
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting 
    	and...
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com> 
    	
    	<031c4f72$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <07beafe7-b882-4bc1-82af-0e6f6596ba3b@f10g2000vbl.googlegroups.com>
    
    On Nov 24, 4:43?pm, Steven D'Aprano  wrote:
    
    > Oh yes, and people using Windows can't use maildir because (1) it doesn't
    > allow colons in names, and (2) it doesn't have atomic renames. Neither of
    > these are insurmountable problems: an implementation could substitute
    > another character for the colon, and while that would be a technical
    > violation of the standard, it would still work. And the lack of atomic
    > renames would simply mean that implementations have to be more careful
    > about not having two threads writing to the one mailbox at the same time.
    
    A common work around for the former is to URL encode the names, which
    let's you stick all sorts of odd characters.
    
    I'm afraid I can't help with the latter, though.
    
    
    From greg.ewing at canterbury.ac.nz  Tue Nov 24 18:49:10 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Wed, 25 Nov 2009 12:49:10 +1300
    Subject: python bijection
    In-Reply-To: 
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com>
    	
    Message-ID: <7n39ojF3jj6iuU1@mid.individual.net>
    
    Joshua Bronson wrote:
    > So I'm
    > thinking of renaming the class injectivedict or idict instead of
    > bijection. Is that crazy?)
    
    I think you'd be better off calling it something more
    down-to-earth such as bidict (bidirectional dictionary).
    That way people without an advanced degree in mathematics
    have a better shot at not being baffled by it.:-)
    
    -- 
    Greg
    
    
    From paul at boddie.org.uk  Tue Nov 24 19:09:10 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Tue, 24 Nov 2009 16:09:10 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	 
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com> 
    	
    Message-ID: <24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    
    On 24 Nov, 19:25, Antoine Pitrou  wrote:
    >
    > Sorry, I have trouble parsing your sentence. Do you mean bytecode
    > interpretation overhead is minimal compared to the cost of actual useful
    > work, or the contrary?
    > (IMO both are wrong by the way)
    
    I'm referring to what you're talking about at the end. The
    enhancements in Python 3 presumably came about after discussion of
    "threaded interpreters", confirming that the evaluation loop in Python
    2 was not exactly optimal.
    
    > > I imagine that someone (or a number of people) must have profiled the
    > > Python interpreter and shown how much time goes on the individual
    > > bytecode implementations and how much goes on the interpreter's own
    > > housekeeping activities.
    >
    > Well the one problem is that it's not easy to draw a line. Another
    > problem is that it depends on the workload. If you are compressing large
    > data or running expensive regular expressions the answer won't be the
    > same as if you compute a Mandelbrot set in pure Python.
    
    You need to draw the line between work done by system and external
    libraries and that done by Python, but a breakdown of the time spent
    executing each kind of bytecode instruction could be interesting.
    Certainly, without such actual cost estimations, a simple counting of
    bytecodes should hardly give an indication of how optimal some Python
    code might be.
    
    Paul
    
    
    From rhodri at wildebst.demon.co.uk  Tue Nov 24 20:11:29 2009
    From: rhodri at wildebst.demon.co.uk (Rhodri James)
    Date: Wed, 25 Nov 2009 01:11:29 -0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    	
    	
    Message-ID: 
    
    On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    wrote:
    
    > On Nov 24, 3:27 pm, MRAB  wrote:
    >>
    >> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >> it returns.
    >>
    >> Could you provide some code which shows your problem?
    >
    > Here is the code block I have so far:
    > for l in open(CONTENTS, 'r').readlines():
    >     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >         shutil.rmtree(os.path.join(DIR1,f))
    >         if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    >             shutil.rmtree(os.path.join(DIR2,f))
    
    Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    os.path.splitext() doesn't work.  Given that replacing the entire loop  
    contents with "print l" readily disproves your assertion, I suggest you  
    cut and paste actual code if you want an answer.  Otherwise we're just  
    going to keep saying "No, it doesn't", because no, it doesn't.
    
    > A minimally obfuscated line from the log file:
    > K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602
    >
    > What I get from the debugger/python shell:
    > 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > 11/24/2009 08:16:42 ; 1259068602'
    
    When you do what, exactly?
    
    -- 
    Rhodri James *-* Wildebeest Herder to the Masses
    
    
    From rhodri at wildebst.demon.co.uk  Tue Nov 24 20:16:15 2009
    From: rhodri at wildebst.demon.co.uk (Rhodri James)
    Date: Wed, 25 Nov 2009 01:16:15 -0000
    Subject: Raw strings as input from File?
    In-Reply-To: 
    References: 
    	
    	
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 01:11:29 -0000, Rhodri James  
     wrote:
    
    > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    > wrote:
    >
    >> On Nov 24, 3:27 pm, MRAB  wrote:
    >>>
    >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >>> it returns.
    >>>
    >>> Could you provide some code which shows your problem?
    >>
    >> Here is the code block I have so far:
    >> for l in open(CONTENTS, 'r').readlines():
    >>     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >>     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >>         shutil.rmtree(os.path.join(DIR1,f))
    >>         if f in os.listdir(DIR2) and  
    >> os.path.isdir(os.path.join(DIR2,f)):
    >>             shutil.rmtree(os.path.join(DIR2,f))
    >
    > Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    > os.path.splitext() doesn't work.
    
    I meant, "doesn't work on a tuple".  Sigh.  It's been one of those days.
    
    -- 
    Rhodri James *-* Wildebeest Herder to the Masses
    
    
    From rt8396 at gmail.com  Tue Nov 24 20:53:21 2009
    From: rt8396 at gmail.com (r)
    Date: Tue, 24 Nov 2009 17:53:21 -0800 (PST)
    Subject: Beginning Question about Python functions, parameters...
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com> 
    	
    Message-ID: <638c0f8f-9c63-4db4-b1ae-a92abfa20691@f16g2000yqm.googlegroups.com>
    
    On Nov 24, 9:45?am, astral orange <457r0... at gmail.com> wrote:
    >
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    > yet I can follow and understand what is going on very easily, that
    > helps out tremendously.
    > Very clearly written...Thank you!
    
    Yes and this is the stumbling block that almost every tutorial writer
    puts before the uninitiated! Simple, Simple examples are the key. The
    subject matter of the example should never outshine the subject that
    is being taught. Everybody understand what a first, middle, and last
    name is! What really ticks me off is when some show-off tut writer
    goes off using an internet protocol or mp3 tags example to explain
    classes or functions... WHAT!-O
    
    Pssst...tut writers remember this! While you may be an emacs "zen
    master" playing key chords that would make most piano virtuosos
    jealous, your tutorials are meant for inexperience users. Yes,
    exposing your "huge intelligence" to the world may give you warm
    fuzzies, but the "shock-and-awe-freak-show" will only be to the
    detriment of the very ideas you are attempting to transform into these
    minds.
    
    
    
    
    
    From jabronson at gmail.com  Tue Nov 24 22:28:38 2009
    From: jabronson at gmail.com (Joshua Bronson)
    Date: Tue, 24 Nov 2009 19:28:38 -0800 (PST)
    Subject: python bijection
    References: 
    	<5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> 
    	 
    	<7n39ojF3jj6iuU1@mid.individual.net>
    Message-ID: <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com>
    
    On Nov 24, 6:49?pm, Gregory Ewing  wrote:
    > Joshua Bronson wrote:
    > > So I'm
    > > thinking of renaming the class injectivedict or idict instead of
    > > bijection. Is that crazy?)
    >
    > I think you'd be better off calling it something more
    > down-to-earth such as bidict (bidirectional dictionary).
    > That way people without an advanced degree in mathematics
    > have a better shot at not being baffled by it.:-)
    >
    > --
    > Greg
    
    heh, duly noted:) bidict it is!
    
    
    From invalid at invalid.invalid  Tue Nov 24 22:31:41 2009
    From: invalid at invalid.invalid (Grant Edwards)
    Date: Wed, 25 Nov 2009 03:31:41 +0000 (UTC)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	
    Message-ID: 
    
    On 2009-11-25, Rhodri James  wrote:
    > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo   
    > wrote:
    >
    >> On Nov 24, 3:27 pm, MRAB  wrote:
    >>>
    >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    >>> it returns.
    >>>
    >>> Could you provide some code which shows your problem?
    >>
    >> Here is the code block I have so far:
    >> for l in open(CONTENTS, 'r').readlines():
    >>     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    >>     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    >>         shutil.rmtree(os.path.join(DIR1,f))
    >>         if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    >>             shutil.rmtree(os.path.join(DIR2,f))
    >
    > Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
    > os.path.splitext() doesn't work.  Given that replacing the entire loop  
    > contents with "print l" readily disproves your assertion, I suggest you  
    > cut and paste actual code if you want an answer.  Otherwise we're just  
    > going to keep saying "No, it doesn't", because no, it doesn't.
    
    It's, um, rewarding to see my recent set of instructions being
    followed.
    
    >> A minimally obfuscated line from the log file:
    >> K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    >> smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    >> 11/24/2009 08:16:42 ; 1259068602
    >>
    >> What I get from the debugger/python shell:
    >> 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    >> smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    >> 11/24/2009 08:16:42 ; 1259068602'
    >
    > When you do what, exactly?
    
    ;)
    
    -- 
    Grant
    
    
    From n00m at narod.ru  Tue Nov 24 23:57:04 2009
    From: n00m at narod.ru (n00m)
    Date: Tue, 24 Nov 2009 20:57:04 -0800 (PST)
    Subject: Can "self" crush itself?
    Message-ID: 
    
    Why does "h" instance stay alive?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                self.crush_me()
        def crush_me(self):
            print 'Will self be crushed?'
            self = None
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    
    print f
    print g
    print h
    
    
    =============== RESTART ====
    
    Will self be crushed?
    <__main__.Moo instance at 0x00CC9260>
    <__main__.Moo instance at 0x00CC9468>
    <__main__.Moo instance at 0x00CC94B8>
    
    
    From cjns1989 at gmail.com  Wed Nov 25 00:11:08 2009
    From: cjns1989 at gmail.com (Chris Jones)
    Date: Wed, 25 Nov 2009 00:11:08 -0500
    Subject: UnicodeDecodeError? Argh! Nothing works! I'm tired and hurting
    	and...
    In-Reply-To: <031c4f72$0$1336$c3e8da3@news.astraweb.com>
    References: 
    	<031bc732$0$1336$c3e8da3@news.astraweb.com>
    	
    	<031c4f72$0$1336$c3e8da3@news.astraweb.com>
    Message-ID: <20091125051108.GE3122@turki.gavron.org>
    
    On Tue, Nov 24, 2009 at 05:43:32PM EST, Steven D'Aprano wrote:
    > On Tue, 24 Nov 2009 13:19:10 -0500, Chris Jones wrote:
    > 
    > > On Tue, Nov 24, 2009 at 08:02:09AM EST, Steven D'Aprano wrote:
    > > 
    > >> Good grief, it's about six weeks away from 2010 and Thunderbird still
    > >> uses mbox as it's default mail box format. Hello, the nineties called,
    > >> they want their mail formats back! Are the tbird developers on crack or
    > >> something? I can't believe that they're still using that crappy format.
    > >> 
    > >> No, I tell a lie. I can believe it far too well.
    > > 
    > > :-)
    > > 
    > > I realize that's somewhat OT, but what mail box format do you recommend,
    > > and why?
    > 
    > maildir++
    > 
    > http://en.wikipedia.org/wiki/Maildir
    
    Outside the two pluses, maildir also goes back to the 90s - 1995, Daniel
    Berstein's orginal specification.
    
    > Corruption is less likely, if there is corruption you'll only lose a 
    > single message rather than potentially everything in the mail folder[*], 
    > at a pinch you can read the emails using a text editor or easily grep 
    > through them, and compacting the mail folder is lightning fast, there's 
    > no wasted space in the mail folder, and there's no need to mangle lines 
    > starting with "From " in the body of the email.
    
    This last aspect very welcome.
    
    > The only major downside is that because you're dealing with potentially 
    > thousands of smallish files, it *may* have reduced performance on some 
    > older file systems that don't deal well with lots of files. These days, 
    > that's not a real issue.
    > 
    > Oh yes, and people using Windows can't use maildir because (1) it doesn't 
    > allow colons in names, and (2) it doesn't have atomic renames. Neither of 
    > these are insurmountable problems: an implementation could substitute 
    > another character for the colon, and while that would be a technical 
    > violation of the standard, it would still work. And the lack of atomic 
    > renames would simply mean that implementations have to be more careful 
    > about not having two threads writing to the one mailbox at the same time.
    > 
    > 
    > [*] I'm assuming normal "oops there's a bug in the mail client code" 
    > corruption rather than "I got drunk and started deleting random files and 
    > directories" corruption.
    
    I'm not concerned with the other aspects, but I'm reaching a point where
    mutt is becoming rather sluggish with the mbox format, especially those
    mail boxes that have more than about 3000 messages and it looks like
    maildir, especially with some form of header caching might help.
    
    Looks like running a local IMAP server would probably be more effective,
    though.
    
    Thank you for your comments.
    
    CJ
    
    
    From ben+python at benfinney.id.au  Wed Nov 25 00:12:26 2009
    From: ben+python at benfinney.id.au (Ben Finney)
    Date: Wed, 25 Nov 2009 16:12:26 +1100
    Subject: Can "self" crush itself?
    References: 
    Message-ID: <87tywj2nnp.fsf@benfinney.id.au>
    
    n00m  writes:
    
    >     def crush_me(self):
    >         print 'Will self be crushed?'
    >         self = None
    
    As with any function, the parameter is bound to a *local* name, in this
    case the name ?self?. Whatever you rebind ?self? to inside the function,
    the binding is lost once the function exits. None of this affects any
    other bindings the same object might retain from outside the function.
    
    It's exactly the same behaviour as this:
    
        >>> def frobnicate(foo):
        ...     print "Entered ?frobnicate?"
        ...     foo = None
        ...     print "Leaving ?frobnicate?"
        ... 
        >>> bar = "syzygy"
        >>> print bar
        syzygy
        >>> frobnicate(bar)
        Entered ?frobnicate?
        Leaving ?frobnicate?
        >>> print bar
        syzygy
    
    The only difference with an instance method is how Python determines
    what object to bind to the local name ?self?. That still doesn't change
    the fact that it's a local name inside that function.
    
    -- 
     \        ?Read not to contradict and confute, nor to believe and take |
      `\          for granted ? but to weigh and consider.? ?Francis Bacon |
    _o__)                                                                  |
    Ben Finney
    
    
    From swheatley at gmail.com  Wed Nov 25 00:38:52 2009
    From: swheatley at gmail.com (Shawn Wheatley)
    Date: Tue, 24 Nov 2009 21:38:52 -0800 (PST)
    Subject: python gui builders
    References: <8u9Mm.35397$Wd1.32454@newsfe15.iad>
    	<007f3944$0$23487$c3e8da3@news.astraweb.com> 
    	<05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com> 
    	<863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com> 
    	
    Message-ID: <987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    
    It's not quite all encompassing, but I found this link last year when
    looking for a similar comparison of Python GUIs:
    http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/
    
    Tkinter, Qt, GTK, IronPython... I think the only thing missing is
    Jython w/ Swing or SWT. Check it out.
    
    Shawn
    
    On Nov 18, 5:11?pm, Stef Mientki  wrote:
    > Wouldn't it be nice
    > if each fan of some form of GUI-package,
    > would post it's code (and resulting images) for generating one or two
    > standard GUI-forms ?
    
    
    From n00m at narod.ru  Wed Nov 25 00:45:56 2009
    From: n00m at narod.ru (n00m)
    Date: Tue, 24 Nov 2009 21:45:56 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    Message-ID: <57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    
    
    > Whatever you rebind ?self? to inside the function...
    
    
    Seems you are right! Thanks, Ben, for the lesson :-)
    
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                self.crush_me()
        def crush_me(self):
            print 'Will self be crushed?'
            self = None
            print self
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    print '================='
    print h
    
    
    
    Will self be crushed?
    None
    =================
    <__main__.Moo instance at 0x00CC9468>
    
    
    From pengyu.ut at gmail.com  Wed Nov 25 00:47:04 2009
    From: pengyu.ut at gmail.com (Peng Yu)
    Date: Tue, 24 Nov 2009 23:47:04 -0600
    Subject: get line number and filename in a source file
    Message-ID: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    
    __LINE__ __FILE__ in C++ can give the current line number and
    filename. Is there a similar thing in python that can give me the
    current line number and filename?
    
    Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    
    
    From clp2 at rebertia.com  Wed Nov 25 01:01:57 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Tue, 24 Nov 2009 22:01:57 -0800
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: <50697b2c0911242201r5f260616wa5c3fc33df0d28db@mail.gmail.com>
    
    On Tue, Nov 24, 2009 at 9:47 PM, Peng Yu  wrote:
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    
    import inspect
    filename, linenum, funcname = inspect.getframeinfo(inspect.currentframe())[:3]
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From rami.chowdhury at gmail.com  Wed Nov 25 01:04:24 2009
    From: rami.chowdhury at gmail.com (Rami Chowdhury)
    Date: Tue, 24 Nov 2009 22:04:24 -0800
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: 
    
    On Nov 24, 2009, at 21:47 , Peng Yu wrote:
    
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    > Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    
    What do you want to use them for? 
    
    > -- 
    > http://mail.python.org/mailman/listinfo/python-list
    
    
    
    From nagle at animats.com  Wed Nov 25 01:42:28 2009
    From: nagle at animats.com (John Nagle)
    Date: Tue, 24 Nov 2009 22:42:28 -0800
    Subject: CentOS 5.3 vs. Python 2.5
    Message-ID: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    
        My dedicated hosting provider wants to switch me to a new server with
    CentOS 5.3, so I have to look at how much work is required.
    
        CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
    requires Python 2.4 for its own internal purposes, and actually
    installing Python 2.5 breaks the package manager.  There's
    no supported RPM for upgrading.
    
        It's apparently necessary to build Python 2.5 from source,
    build all the packages, and debug.  Nor does that "just work".
    There's documentation, but some of it is in Japanese.
    
    http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    
    Google Translate gives me
    
    "[...] On this entry uses the src.rpm. Kitara dropped, rpmbuild-rebuild 
    (rpm-rebuild, but often seen the entry, it says, there's this option only old 
    rpm) [...]"
    
    I'm trying to figure that out.
    
    				John Nagle
    
    
    From davea at ieee.org  Wed Nov 25 01:58:56 2009
    From: davea at ieee.org (Dave Angel)
    Date: Wed, 25 Nov 2009 01:58:56 -0500
    Subject: get line number and filename in a source file
    In-Reply-To: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    References: <366c6f340911242147g5d1ccb94l60ed0932bdfff397@mail.gmail.com>
    Message-ID: <4B0CD5B0.20600@ieee.org>
    
    Peng Yu wrote:
    > __LINE__ __FILE__ in C++ can give the current line number and
    > filename. Is there a similar thing in python that can give me the
    > current line number and filename?
    >
    > Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
    >
    >   
    mod.__name__  gives the module name, and   mod.__file__  gives the full 
    path to the given module.  Or if you need those for the current module, 
    just leave off the prefix.
    
    For line number information, you probably can get it from the inspect 
    module, but I don't have any direct experience.  I do have the following 
    untested line
    in my notes:
               inspect.getframeinfo(inspect.currentframe()).function)
    
    DaveA
    
    
    
    
    
    From timr at probo.com  Wed Nov 25 02:19:01 2009
    From: timr at probo.com (Tim Roberts)
    Date: Tue, 24 Nov 2009 23:19:01 -0800
    Subject: python and Postgresq
    References: 
    	<7mv62nF3hp171U1@mid.uni-berlin.de>
    	
    Message-ID: 
    
    Krishnakant  wrote:
    >
    >Python-pgsql is a much better choice when it comes to big applications,
    >specially if you are going to deal with xml-rpc.  I have found that
    >python-pgsql handles integers and other such postgresql datatypes
    >better.
    
    I wonder if you would mind expanding on the experiences that lead you to
    say this.  I've use both extensively (plus the old "pg"), and I've found
    psycopg to be unconditionally the better choice, especially for big
    applications where performance is critical.
    -- 
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.
    
    
    From wuwei23 at gmail.com  Wed Nov 25 02:28:47 2009
    From: wuwei23 at gmail.com (alex23)
    Date: Tue, 24 Nov 2009 23:28:47 -0800 (PST)
    Subject: IDE+hg
    References: 
    Message-ID: <75ef83cb-b928-4bf4-b20a-11484a3fdc45@2g2000prl.googlegroups.com>
    
    NiklasRTZ  wrote:
    > no py IDE I found has easy hg access.
    
    ActiveState's Komodo IDE has support for CVS, Perforce, subversion,
    bazaar, git and mercurial.
    
    
    
    From news123 at free.fr  Wed Nov 25 03:08:26 2009
    From: news123 at free.fr (News123)
    Date: Wed, 25 Nov 2009 09:08:26 +0100
    Subject: scanning under windows WIA with custom settings (dpi / etc )
    In-Reply-To: <4b097593$0$30269$426a74cc@news.free.fr>
    References: <4b097593$0$30269$426a74cc@news.free.fr>
    Message-ID: <4b0ce5fa$0$25790$426a34cc@news.free.fr>
    
    
    
    News123 wrote:
    > Hi,
    > 
    > I'm trying to scan a document from a python 2.6 script without user
    > interaction.
    > 
    > I found  a code snippet, that allows me to scan under Vista, but that
    > doesn't allow me to select the dpi / color mode / etc.
    
    I'm still stuck.
    
    
    I'll try to look at any solution (visual C++, C#, Basic) first.
    Then it's perhaps easier to pythonize it via python .net.
    
    However I don't know whether python .net exists for 2.6 and whether it
    is stable enough.
    
    
    N
    
    > 
    > The snippet uses win32com.client
    > 
    > # ##################### script start
    > import win32com.client,os
    > 
    > WIA_IMG_FORMAT_PNG       = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
    > WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
    > 
    > os.chdir('c:/temp')
    > wia = win32com.client.Dispatch("WIA.CommonDialog")
    > dev = wia.ShowSelectDevice()
    > for command in dev.Commands:
    >     if command.CommandID==WIA_COMMAND_TAKE_PICTURE:
    >         foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE)
    > i=1
    > for item in dev.Items:
    >     if i==dev.Items.Count:
    >         image=item.Transfer(WIA_IMG_FORMAT_PNG)
    >         break
    >     i=i+1
    > 
    > image.SaveFile("test.png")
    > ######################### script end
    > 
    > 
    > My problems are:
    > 
    > - This script works fine for me under Windows 7, however I'm
    >   unable to   specify additional parameters, like dpi and
    >   color mode.
    > 
    > - The script doesn't work under windows XP, though the scanner driver is
    > installed. (Gimp finds the scanner (as WIA scanner)).
    > Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL.
    > The error message is:
    > --------------------------------------------------------------------
    > Traceback (most recent call last):
    >   File "C:\work\python\minidemos\wia_get_simple.py", line 7, in 
    >     wia = win32com.client.Dispatch("WIA.CommonDialog")
    >   File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line
    > 95, in Dispatch
    >     dispatch, userName =
    > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    >   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
    > 104, in _GetGoodDispatchAndUserName
    >     return (_GetGoodDispatch(IDispatch, clsctx), userName)
    >   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
    > 84, in _GetGoodDispatch
    >     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    > pythoncom.IID_IDispatch)
    > com_error: (-2147221005, 'Invalid class string', None, None)
    > ---------------------------------------------------------------------
    > 
    > 
    > As I have no knowledge of Win32com and WIA I would appreciate some help
    > or good documentation about wincom32 / WIA with python
    > 
    > 
    > 
    > thanks for your help and bye
    > 
    > 
    > N
    > 
    > 
    > 
    > 
    > 
    > 
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 03:13:04 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 25 Nov 2009 08:13:04 GMT
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    Message-ID: 
    
    On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    
    > My dedicated hosting provider wants to switch me to a new server with
    > CentOS 5.3, so I have to look at how much work is required.
    > 
    >     CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
    > requires Python 2.4 for its own internal purposes, and actually
    > installing Python 2.5 breaks the package manager.  There's no supported
    > RPM for upgrading.
    > 
    >     It's apparently necessary to build Python 2.5 from source,
    > build all the packages, and debug.
    
    
    You shouldn't need *quite* that much effort, particularly if you don't 
    care about tkinter. Just use the alternate installation so it doesn't 
    stomp all over the 2.4 installation:
    
    .configure
    make
    make altinstall
    
    You will need root or sudo for that last one.
    
    
    I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly 
    easily for me:
    
    $ wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    ...
    18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    $
    $ tar xzf Python-2.5.4.tgz
    $ cd Python-2.5.4
    $ ./configure
    ...
    $ make
    ...
    $ sudo make altinstall
    Password: 
    ...
    $ python -V
    Python 2.4.3
    $ python2.5 -V
    Python 2.5.4
    
    
    And it all seems to just work for me.
    
    
    
    
    > Nor does that "just work". There's
    > documentation, but some of it is in Japanese.
    > 
    > http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    
    I don't understand why you're using documentation for third-party RPMs as 
    evidence that building from source will be troublesome.
    
    
    
    -- 
    Steven
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 03:24:02 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 09:24:02 +0100
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    	
    Message-ID: <4b0ce96f$0$30625$426a74cc@news.free.fr>
    
    astral orange a ?crit :
    > On Nov 23, 10:37 pm, r  wrote:
    (snip)
    >> This is a horrible example to show noobs. I think the OP could better
    >> understand this as a class EVEN though the OP may or may not know what
    >> a class *is* yet.
    >>
    >>>>> class Name():
    >>         def __init__(self, first, middle, last):
    >>                 self.first = first
    >>                 self.middle = middle
    >>                 self.last = last
    >>
    (snip)
    
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    
    It's a reference to the current Name instance. But while technically 
    correct, I'm sure such this kind of explanation really helps :-/
    
    
    
    From lallous at lgwm.org  Wed Nov 25 03:51:06 2009
    From: lallous at lgwm.org (lallous)
    Date: Wed, 25 Nov 2009 09:51:06 +0100
    Subject: How to import a file by its full path using C api?
    Message-ID: 
    
    Hello
    
    PyObject* PyImport_ImportModule( const char *name) 
    
    How to specify a full file path instead and a module name?
    
    Like PyImport_SomeFunction(const char *path_to_script, const char *name)
    
    Thanks,
    Elias 
    
    
    From joncle at googlemail.com  Wed Nov 25 04:45:08 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Wed, 25 Nov 2009 01:45:08 -0800 (PST)
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    	
    Message-ID: 
    
    On Nov 25, 8:13?am, Steven D'Aprano
     wrote:
    > On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    > > My dedicated hosting provider wants to switch me to a new server with
    > > CentOS 5.3, so I have to look at how much work is required.
    >
    > > ? ? CentOS 5.3 apparently still ships with Python 2.4. ?Worse, it
    > > requires Python 2.4 for its own internal purposes, and actually
    > > installing Python 2.5 breaks the package manager. ?There's no supported
    > > RPM for upgrading.
    >
    > > ? ? It's apparently necessary to build Python 2.5 from source,
    > > build all the packages, and debug.
    >
    > You shouldn't need *quite* that much effort, particularly if you don't
    > care about tkinter. Just use the alternate installation so it doesn't
    > stomp all over the 2.4 installation:
    >
    > .configure
    > make
    > make altinstall
    >
    > You will need root or sudo for that last one.
    >
    > I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
    > easily for me:
    >
    > $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    > ...
    > 18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    > $
    > $ tar xzf Python-2.5.4.tgz
    > $ cd Python-2.5.4
    > $ ./configure
    > ...
    > $ make
    > ...
    > $ sudo make altinstall
    > Password:
    > ...
    > $ python -V
    > Python 2.4.3
    > $ python2.5 -V
    > Python 2.5.4
    >
    > And it all seems to just work for me.
    >
    > > Nor does that "just work". There's
    > > documentation, but some of it is in Japanese.
    >
    > >http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    >
    > I don't understand why you're using documentation for third-party RPMs as
    > evidence that building from source will be troublesome.
    >
    > --
    > Steven
    
    And might I add on a box where there is no root access, but sufficient
    tools (compilers etc...)
    
    1) Compile from source
    2) Set PYTHONPATH correctly for your shell
    3) Set your normal path to include your Python rather than the
    system's default Python
    4) When installing modules (via setup.py install or easy_install)
    include a "home_dir=" (I think that's right OTTOMH) to somewhere in
    your home directory, and make sure step 2) complies with this.
    5) Double check with "which python" to make sure it's the correct
    version.
    
    hth
    Jon.
    
    
    
    
    
    From n00m at narod.ru  Wed Nov 25 04:46:29 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 01:46:29 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    Message-ID: 
    
    Then how can we destroy the 3rd instance,
    right after its creation and from inside
    class Moo code?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.x = x
            self.__class__.cnt += 1
            if self.__class__.cnt > 2:
                print id(self)
                ## 13406816
                ## in what dict is this ID?
                ## and can we delete it from there?
    
                ## ???
    
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    print h
    
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 04:55:05 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 10:55:05 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>
    	
    Message-ID: <4b0cfefa$0$24750$426a34cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > 
    > Let's head towards murkier waters (at least murkier to me -- hopefully 
    > they can be easily clarified):  some of the attributes are read-only, 
    > such as record count; others are not directly exposed, but still 
    > settable, such as table version; and still others require a small amount 
    > of processing... at which point do I switch from simple attribute access 
    > to method access?
    
    Short answer : you don't !-)
    
    Long answer : well, in fact you do, but the client code doesn't have to 
    be aware that it's in fact calling an accessor.
    
    Before we go into more details, you have to know that Python has a 
    pretty good support for computed attributes, with both a simple generic 
    solution (the property type) and the full monty (custom types 
    implementing the descriptor protocol). So from the "interface" POV, you 
    should never have an explicit accessor method for what is semantically 
    an attribute (wheter the attribute is a plain or a computed one being 
    part of the implementation).
    
    Let's start with your second point: "not directly exposed but still 
    settable". I assume you mean "not part of the interface, only supposed 
    to be accessed (rw) from the methods" - if not, please pardon my 
    stupidity and provide better explanations !-). If yes: Python doesn't 
    have "language inforced" access restrictions (private / protected / 
    etc), but a *very strong* naming convention which is that names starting 
    with a leading underscore are implementation details, not part of the 
    official interface, and shouldn't be accessed directly. Kind of a 
    "warranty voided if unsealed".
    
    So if you have attributes you don't want to "expose" to the outside 
    world, just add a single leading underscore to their names.
    
    First and third points are solved by using computed attributes - usually 
    a property. The property type takes a few accessor functions as 
    arguments - typically, a getter and a setter, and eventually a 
    "deleter". Used as a class attribute, a property instance will hook up 
    into the attribute lookup / setup mechanism (__getattribute__ and 
    __setattr__), and will call resp. it's getter or setter function, 
    passing it the instance and (for the setter) value.
    
    This directly solves the third point. For the first one, the obvious 
    solution is to use a property with a setter that raises an exception - 
    canonically, an AttributeError with a message explaining that the 
    attribute is read-only.
    
    And for something more hands-on:
    
    class Person(object):
        def __init__(self, firstname, lastname, birthdate):
            self.firstname = firstname
            self.lastname = lastnale
            self.birthdate = birthdate
            self._foo = 42 # implementation only
    
        def _getfullname(self):
            return "%s %s" % (self.firstname, self.lastname)
        def _setfullname(self, value):
            raise AttributeError("%s.fullname is read-only" % type(self)
        fullname = property(fget=_getfullname, fset=_setfullname)
    
        def _getage(self):
            return some_computation_with(self.birthdate)
        def _setage(self, value):
            raise AttributeError("%s.age is read-only" % type(self)
        age = property(fget=_getage, fset=_setage)
    
    
    For more on computed attributes, you may want to read about the 
    "descriptor protocol" (google is your friend as usual). This and the 
    attribute resolution mechanism are fundamental parts of Python's inner 
    working. Learn how it works if you really want to leverage Python's power.
    
    HTH
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 04:56:19 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 10:56:19 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 		<4b0b92de$0$14677$426a74cc@news.free.fr>		<4B0C1A4E.7050204@stoneleaf.us>	<50697b2c0911241025p655164dl89dc34a727995093@mail.gmail.com>
    	
    Message-ID: <4b0cff43$0$24750$426a34cc@news.free.fr>
    
    Ethan Furman a ?crit :
    (snip)
    
    > Okay, I'll go back and switch all my attributes *back* to attributes -- 
    > and properties will be much nicer than my original implementation (using 
    > __getattr__ and __setattr__).
    
    It will also be faster FWIW.
    
    
    From clp2 at rebertia.com  Wed Nov 25 04:58:49 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Wed, 25 Nov 2009 01:58:49 -0800
    Subject: Can "self" crush itself?
    In-Reply-To: 
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    Message-ID: <50697b2c0911250158p62c1edbcmccb095d3e1779d83@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 1:46 AM, n00m  wrote:
    > Then how can we destroy the 3rd instance,
    > right after its creation and from inside
    > class Moo code?
    
    Why would you want to do that in the first place? It's strange to say the least.
    If you want to prevent an instance being created in the first place,
    you can override __new__().
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From ben+python at benfinney.id.au  Wed Nov 25 05:04:32 2009
    From: ben+python at benfinney.id.au (Ben Finney)
    Date: Wed, 25 Nov 2009 21:04:32 +1100
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    Message-ID: <87einm3opb.fsf@benfinney.id.au>
    
    n00m  writes:
    
    > Then how can we destroy the 3rd instance, right after its creation and
    > from inside class Moo code?
    
    Normally, one binds whatever references one needs, and lets the garbage
    collector clean them up once they fall out of scope. If the references
    are living beyond their usefulness, that's probably a sign that your
    code isn't modular enough; short, focussed functions might help. But
    this is all diagnosis without seeing the symptoms.
    
    Perhaps it's beyond time that you explained what you're trying to
    achieve that you think ?destroy an instance? will help.
    
    -- 
     \      ?I bought a self learning record to learn Spanish. I turned it |
      `\        on and went to sleep; the record got stuck. The next day I |
    _o__)                   could only stutter in Spanish.? ?Steven Wright |
    Ben Finney
    
    
    From n00m at narod.ru  Wed Nov 25 06:42:07 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 03:42:07 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<87tywj2nnp.fsf@benfinney.id.au>
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	 
    	<87einm3opb.fsf@benfinney.id.au>
    Message-ID: <10581b96-f44e-4ac5-b2cb-6d5a5f12aa89@m16g2000yqc.googlegroups.com>
    
    > Why would you want to do that in the first place?
    
    I don't know... :-)
    As Schoepenhauer put it:
    The man can do what he wants to do but he can't want to want
    what he wants to do
    
    
    
    From jeanmichel at sequans.com  Wed Nov 25 06:58:21 2009
    From: jeanmichel at sequans.com (Jean-Michel Pichavant)
    Date: Wed, 25 Nov 2009 12:58:21 +0100
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    References: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    Message-ID: <4B0D1BDD.70400@sequans.com>
    
    Barak, Ron wrote:
    > Hi,
    >  
    > I'm trying to add the logging module to my application, but I seem to 
    > be missing something.
    > My application (a wxPython one) has a main script that calls various 
    > helper classes.
    > I want the log messages from all modules to go to one central log file.
    >  
    > When I implement logging, I think that due to preparation, I get the 
    > same message more than once.
    >  
    > Here's an example:
    >  
    > [snip example]
    >  
    > Could you suggest what should I change in the above scripts so that 
    > the log messages would appear only once ?
    >  
    > Thanks,
    > Ron.
    >
    If you are starting with the logging facility, I would suggest to add 
    handlers only to the root logger (in your __main__ section).
    
    Basically, never configure or add handlers to any logger except for the 
    root logger in your __main__ section. There are very few reasons why you 
    would break this rule. And when you'll be familiar with the logging 
    module you'll when to break it.
    
    
    [server.py]
    
    import logging
    import logging.handlers
    
    logger = logging.getLogger(__name__) # you'd better to create the logger 
    at the module level, you may want to log within   the module function
    
    def aFunction(a, b, ,c):
        logger.debug('You called aFunction')
    
    class Server():
        def __init__(self):
            self.logger = logger
    
        def util(self):
            self.logger.warning('This message comes from Server module ')
    
    
    [client.py]
    
    import logging
    import logging.handlers
    from server import Server
    
    logger = logging.getLogger(__name__)
    
    class Client():
        def __init__(self):
            self.logger = logger
    
        def client_test(self):
            self.logger.warning("This message comes from Client module")
    
    if __name__ == "__main__":
        rootLogger = logging.getLogger()
        rootLogger.addHandler(logging.FileHandler("client.log"))
        rootLogger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s 
    %(name)-12s %(levelname)-8s %(message)s"))
        rootLogger.setLevel(logging.DEBUG)
        ser = Server()
        cli = Client()
        ser.util()
        cli.client_test()
    
    Happy logging,
    
    Jean-Michel
    
    
    From solipsis at pitrou.net  Wed Nov 25 07:02:24 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Wed, 25 Nov 2009 12:02:24 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	 <1259090178.661.34.camel@localhost>
    	
    Message-ID: 
    
    Le Tue, 24 Nov 2009 22:08:19 +0000, Benjamin Peterson a ?crit?:
    > 
    >> Would it be worth in-lining the remaining part of PyObject_IsTrue in
    >> ceval?
    > 
    > Inlining by hand is prone to error and maintainability problems.
    
    Which is why we like to do it :-))
    
    
    
    
    From solipsis at pitrou.net  Wed Nov 25 07:11:31 2009
    From: solipsis at pitrou.net (Antoine Pitrou)
    Date: Wed, 25 Nov 2009 12:11:31 +0000 (UTC)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com>
    	
    	<24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    Message-ID: 
    
    Le Tue, 24 Nov 2009 16:09:10 -0800, Paul Boddie a ?crit?:
    > 
    > I'm referring to what you're talking about at the end. The enhancements
    > in Python 3 presumably came about after discussion of "threaded
    > interpreters", confirming that the evaluation loop in Python 2 was not
    > exactly optimal.
    
    An optimal evaluation loop is a evaluation loop which doesn't get 
    executed at all :-)
    (which is what unladen-swallow, cython and pypy are trying to do)
    
    > You need to draw the line between work done by system and external
    > libraries and that done by Python, but a breakdown of the time spent
    > executing each kind of bytecode instruction could be interesting.
    
    When you say "executing each kind of bytecode instruction", are you 
    talking about the overhead of bytecode dispatch and operand gathering, or 
    the total cost including doing the useful work?
    
    Regardless, it probably isn't easy to do such measurements. I once tried 
    using AMD's CodeAnalyst (I have an AMD CPU) but I didn't manage to get 
    any useful data out of it; the software felt very clumsy and it wasn't 
    obvious how to make it take into account the source code of the Python 
    interpreter.
    
    Regards
    
    Antoine.
    
    
    
    
    From Nadav.C at qualisystems.com  Wed Nov 25 07:47:16 2009
    From: Nadav.C at qualisystems.com (Nadav Chernin)
    Date: Wed, 25 Nov 2009 14:47:16 +0200
    Subject: Help with pprint
    Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    
    Hello, I want to print list of lists in matrix format. So I use pprint
    with parameter 'width' for this target. 
    
    For example :
    
     
    
    >>> data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    
    >>> pprint(data,width=20)
    
    [[1, 1, 1],
    
     [1, 1, 1],
    
     [1, 1, 1]]
    
     
    
    The problem that I don't know how to select width value, because if:
    
     
    
    >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one',
    'one']]  
    
    >>> pprint(data,width=20)
    
    [['one',
    
      'one',
    
      'one'],
    
     ['one',
    
      'one',
    
      'one'],
    
     ['one',
    
      'one',
    
      'one']]
    
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From newsuser at stacom-software.de  Wed Nov 25 07:49:44 2009
    From: newsuser at stacom-software.de (Alexander Eisenhuth)
    Date: Wed, 25 Nov 2009 13:49:44 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application busy"
    Message-ID: 
    
    Hello list,
    
    I'm having a problem with a python COM Excel client that rarely gets the 
    exception pywintypes.com_error with the error code -2147417846. (means Excel is 
    busy) Here the python code of the exception handling:
    
    [...]
    try:
         # write a excel cell
    [...]
    except pywintypes.com_error, ex:
         if ex[0] == -2147417846:
             time.sleep(1.0)
             # retry write?
    [...]
    
    My first approach was to retry the writing to the excel cell. But that ends in a 
    hanging Excel application (probably a deadlock).
    
    After a little research I found this post:
    
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5
    
    "[...] If you don't register a MessageFilter yourself (by calling 
    CoRegisterMessageFilter), you will get default behavior which will be to fail 
    the call if it gets rejected.  .Net converts the failure HRESULT to an 
    exception.  To deal with the possibility of the server being busy when you try 
    to call, you need to implement IMessageFilter::RetryRejectedCall in your client 
    code and also register the message filter.  In most cases, you will just need to 
    wait for a few seconds and then retry the call--generally that will be 
    sufficient time to enable Word to finish whatever it is doing so it can handle 
    your call.  However, if the instance of Word that you are controlling could 
    possibly visible, you might want to add additional logic to display the 
    OLEUIBUSY dialog after some amount of time has passed to notify the user that 
    you are waiting on Word to do something and give them the opportunity to help 
    the process.  For example, as Misha mentions, Word will reject all incoming 
    calls if a modal dialog box is up.  Therefore, in that situation, you would be 
    blocked indefinitely until the dialog is dismissed. [...]"
    
    As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't 
    included in pywin32 I don't see a possibility to do that, or?
    
    Did anybody else have to deal with that problem?
    
    Any hints are very welcome.
    
    Regards
    Alexander
    
    
    From enleverLesX_XXmcX at XmclavXeauX.com.invalid  Wed Nov 25 07:55:40 2009
    From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP)
    Date: Wed, 25 Nov 2009 13:55:40 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application
    	busy"
    References: 
    Message-ID: <4b0d2950$0$967$ba4acef3@news.orange.fr>
    
    Hi! 
    
    Your computer is too slow, for launch Excel.
    Configure the machine for more speed...
    
    @+
    -- 
    MCI
    
    
    From joncle at googlemail.com  Wed Nov 25 07:58:57 2009
    From: joncle at googlemail.com (Jon Clements)
    Date: Wed, 25 Nov 2009 04:58:57 -0800 (PST)
    Subject: Raw strings as input from File?
    References: 
    	
    	
    	
    	
    Message-ID: <80c312f8-2b0f-4ec0-9dcd-da0ed1efdbfc@37g2000yqm.googlegroups.com>
    
    On Nov 25, 3:31?am, Grant Edwards  wrote:
    > On 2009-11-25, Rhodri James  wrote:
    >
    >
    >
    > > On Tue, 24 Nov 2009 21:20:25 -0000, utabintarbo  ?
    > > wrote:
    >
    > >> On Nov 24, 3:27 pm, MRAB  wrote:
    >
    > >>> .readlines() doesn't change the "\10" in a file to "\x08" in the string
    > >>> it returns.
    >
    > >>> Could you provide some code which shows your problem?
    >
    > >> Here is the code block I have so far:
    > >> for l in open(CONTENTS, 'r').readlines():
    > >> ? ? f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
    > >> ? ? if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
    > >> ? ? ? ? shutil.rmtree(os.path.join(DIR1,f))
    > >> ? ? ? ? if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
    > >> ? ? ? ? ? ? shutil.rmtree(os.path.join(DIR2,f))
    >
    > > Ahem. ?This doesn't run. ?os.path.split() returns a tuple, and calling ?
    > > os.path.splitext() doesn't work. ?Given that replacing the entire loop ?
    > > contents with "print l" readily disproves your assertion, I suggest you ?
    > > cut and paste actual code if you want an answer. ?Otherwise we're just ?
    > > going to keep saying "No, it doesn't", because no, it doesn't.
    >
    > It's, um, rewarding to see my recent set of instructions being
    > followed.
    >
    > >> A minimally obfuscated line from the log file:
    > >> K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
    > >> smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > >> 11/24/2009 08:16:42 ; 1259068602
    >
    > >> What I get from the debugger/python shell:
    > >> 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
    > >> smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
    > >> 11/24/2009 08:16:42 ; 1259068602'
    >
    > > When you do what, exactly?
    >
    > ;)
    >
    > --
    > Grant
    
    Can't remember if this thread counts as "Edwards' Law 5[b|c]" :)
    
    I'm sure I pinned it up on my wall somewhere, right next to
    http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png
    
    Jon.
    
    
    From newsuser at stacom-software.de  Wed Nov 25 08:05:45 2009
    From: newsuser at stacom-software.de (Alexander Eisenhuth)
    Date: Wed, 25 Nov 2009 14:05:45 +0100
    Subject: (pywin related) pywintypes.com_error: -2147417846 "Application
    	busy"
    In-Reply-To: <4b0d2950$0$967$ba4acef3@news.orange.fr>
    References:  <4b0d2950$0$967$ba4acef3@news.orange.fr>
    Message-ID: 
    
    I don't think so, because it happens very rarely
    
    Michel Claveau - MVP schrieb:
    > Hi! 
    > 
    > Your computer is too slow, for launch Excel.
    > Configure the machine for more speed...
    > 
    > @+
    
    
    From hv at tbz-pariv.de  Wed Nov 25 09:06:44 2009
    From: hv at tbz-pariv.de (Thomas Guettler)
    Date: Wed, 25 Nov 2009 15:06:44 +0100
    Subject: 'classmethod' object has only read-only attributes
    Message-ID: <7n4rvkF3kjhtpU1@mid.individual.net>
    
    Hi,
    
    why have classmethods only readonly attributes? It works for other methods.
    
    exmpale code:
    {{{
    class Foo(object):
        @classmethod
        def bar(cls):
            pass
        bar.myattr='test'
    }}}
    
    user at host:~> python ~/tmp/t.py
    Traceback (most recent call last):
      File "/home/user/tmp/t.py", line 1, in 
        class Foo(object):
      File "/home/user/tmp/t.py", line 5, in Foo
        bar.myattr='test'
    TypeError: 'classmethod' object has only read-only attributes (assign to .myattr)
    
    
    -- 
    Thomas Guettler, http://www.thomas-guettler.de/
    E-Mail: guettli (*) thomas-guettler + de
    
    
    From lallous at lgwm.org  Wed Nov 25 09:27:44 2009
    From: lallous at lgwm.org (lallous)
    Date: Wed, 25 Nov 2009 15:27:44 +0100
    Subject: How to import a file by its full path using C api?
    References: 
    Message-ID: 
    
    Looks like one way to do that is to use something like:
    
        s.sprintf(
          "import imp\n"
          "imp.load_source('%s', r'%s')", modname, script_path);
        PyRun_SimpleString(s.c_str());
    
    Unless someone has a better suggestion.
    
    Regards,
    Elias
    "lallous"  wrote in message news:heir4g$ohv$1 at aioe.org...
    > Hello
    > 
    > PyObject* PyImport_ImportModule( const char *name) 
    > 
    > How to specify a full file path instead and a module name?
    > 
    > Like PyImport_SomeFunction(const char *path_to_script, const char *name)
    > 
    > Thanks,
    > Elias 
    
    
    From __peter__ at web.de  Wed Nov 25 09:30:21 2009
    From: __peter__ at web.de (Peter Otten)
    Date: Wed, 25 Nov 2009 15:30:21 +0100
    Subject: 'classmethod' object has only read-only attributes
    References: <7n4rvkF3kjhtpU1@mid.individual.net>
    Message-ID: 
    
    Thomas Guettler wrote:
    
    > Hi,
    > 
    > why have classmethods only readonly attributes? It works for other
    > methods.
    > 
    > exmpale code:
    > {{{
    > class Foo(object):
    >     @classmethod
    >     def bar(cls):
    >         pass
    >     bar.myattr='test'
    > }}}
    > 
    > user at host:~> python ~/tmp/t.py
    > Traceback (most recent call last):
    >   File "/home/user/tmp/t.py", line 1, in 
    >     class Foo(object):
    >   File "/home/user/tmp/t.py", line 5, in Foo
    >     bar.myattr='test'
    > TypeError: 'classmethod' object has only read-only attributes (assign to
    > .myattr)
    
    No idea. But here's a workaround:
    
    >>> class A(object):
    ...     def method(cls): print cls
    ...     method.foo = 42
    ...     method = classmethod(method)
    ...
    >>> A.method()
    
    >>> A.method.foo
    42
    
    Or, going fancy:
    
    >>> def attrs(**kw):
    ...     def set(obj):
    ...             for k, v in kw.iteritems():
    ...                     setattr(obj, k, v)
    ...             return obj
    ...     return set
    ...
    >>> class A(object):
    ...     @classmethod
    ...     @attrs(foo=42)
    ...     def method(cls): print cls
    ...
    >>> A.method()
    
    >>> A().method.foo
    42
    
    Peter
    
    
    
    From lie.1296 at gmail.com  Wed Nov 25 10:08:48 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Thu, 26 Nov 2009 02:08:48 +1100
    Subject: Beginning Question about Python functions, parameters...
    In-Reply-To: 
    References: <2306de84-b732-4fd1-bf71-f7ca44e5db94@f10g2000vbl.googlegroups.com>
    	<207276c5-a8ea-456f-80c7-4c45f52bb3a3@m20g2000vbp.googlegroups.com>
    	
    Message-ID: <4b0d48dd$1@dnews.tpgi.com.au>
    
    astral orange wrote:
    > 
    > As for the "class Name():" example above? Even though I haven't seen
    > exactly what purpose 'self' serves
    
    In many other programming language, self (or this, or Me) refers the the 
    current class instance. In some languages, you can refer to an instance 
    attribute without an explicit self, this, or Me; the name resolver will 
    search in the local namespace (method-level), instance namespace 
    (instance-level), class namespace (class-level), perhaps module level 
    namespace (file-level), and finally global (application level).
    
    Python interpreter is simple and stupid. It doesn't have many smarts; 
    instead of having such a sophisticated name resolver, the compiler 
    passes an argument to the function, making `self` a local variable that 
    refers to the current instance.
    
    Python programmers accesses instance and class namespace by explicitly 
    referring to `self`; the name resolver only have two places to lookup 
    names: local namespace (method level) and global namespace (module-level 
    [!] not application level in python).
    
    This choice of design simplifies the name resolver, simplifies 
    method/function object design (since it does not need any code to handle 
    an otherwise implicit self), and completely eliminates ambiguity (to the 
    programmer) when having a local variable with the same name as an 
    instance variable. Among many other advantages.
    
    The side-effect of this design choice is self must be explicitly 
    referenced to access class/instance attributes; unlike in some other 
    language where self/this/Me may be omitted when it doesn't clash with 
    other variable in local namespace.
    
    
    From victorsubervi at gmail.com  Wed Nov 25 10:19:09 2009
    From: victorsubervi at gmail.com (Victor Subervi)
    Date: Wed, 25 Nov 2009 10:19:09 -0500
    Subject: Workaround To Add Value To TextArea
    Message-ID: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    
    Hi;
    I've noticed that html doesn't support a "value" attribute for textarea. I
    have a form in which I enable users to edit data they've entered into my
    database, and one of the data is a textarea. How do I fill the textarea with
    the value, or what kind of workaround can I create?
    TIA,
    Victor
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From rami.chowdhury at gmail.com  Wed Nov 25 10:27:09 2009
    From: rami.chowdhury at gmail.com (Rami Chowdhury)
    Date: Wed, 25 Nov 2009 07:27:09 -0800
    Subject: Workaround To Add Value To TextArea
    In-Reply-To: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    Message-ID: <2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    
    --------
    Rami Chowdhury
    "Never assume malice when stupidity will suffice." -- Hanlon's Razor
    408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
    
    
    
    On Wed, Nov 25, 2009 at 07:19, Victor Subervi  wrote:
    > Hi;
    > I've noticed that html doesn't support a "value" attribute for textarea. I
    > have a form in which I enable users to edit data they've entered into my
    > database, and one of the data is a textarea. How do I fill the textarea with
    > the value, or what kind of workaround can I create?
    
    Hi Victor,
    
    You'll find the textarea and input tags differ significantly, even
    though they're both typically used in HTML forms. The W3C page has a
    fair overview of how various parts of HTML forms work in HTML 4.01,
    and it's roughly accurate for XHTML up to 1.1 as well:
    http://www.w3.org/TR/html401/interact/forms.html
    
    HTH,
    Rami
    
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    
    
    From victorsubervi at gmail.com  Wed Nov 25 10:41:09 2009
    From: victorsubervi at gmail.com (Victor Subervi)
    Date: Wed, 25 Nov 2009 10:41:09 -0500
    Subject: Workaround To Add Value To TextArea
    In-Reply-To: <2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com>
    	<2f79f590911250727u603f3c3fwadafa20073b815d2@mail.gmail.com>
    Message-ID: <4dc0cfea0911250741y15ff4f5eldcad6cc817cf8c6d@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 10:27 AM, Rami Chowdhury
    wrote:
    
    > You'll find the textarea and input tags differ significantly, even
    > though they're both typically used in HTML forms. The W3C page has a
    > fair overview of how various parts of HTML forms work in HTML 4.01,
    > and it's roughly accurate for XHTML up to 1.1 as well:
    > http://www.w3.org/TR/html401/interact/forms.html
    >
    
    Oops. Silly mistake. Thought I had to put the value inside the tag like the
    other tags. Thanks,
    V
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From jitish.p at gmail.com  Wed Nov 25 10:46:19 2009
    From: jitish.p at gmail.com (Jitish)
    Date: Wed, 25 Nov 2009 07:46:19 -0800 (PST)
    Subject: Workaround To Add Value To TextArea
    References: <4dc0cfea0911250719o2a2fb885sb3f6ee2e558f7f0e@mail.gmail.com> 
    	
    Message-ID: 
    
    On Nov 25, 8:27?pm, Rami Chowdhury  wrote:
    > --------
    > Rami Chowdhury
    > "Never assume malice when stupidity will suffice." -- Hanlon's Razor
    > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
    >
    > On Wed, Nov 25, 2009 at 07:19, Victor Subervi  wrote:
    > > Hi;
    > > I've noticed that html doesn't support a "value" attribute for textarea. I
    > > have a form in which I enable users to edit data they've entered into my
    > > database, and one of the data is a textarea. How do I fill the textarea with
    > > the value, or what kind of workaround can I create?
    >
    > Hi Victor,
    >
    > You'll find the textarea and input tags differ significantly, even
    > though they're both typically used in HTML forms. The W3C page has a
    > fair overview of how various parts of HTML forms work in HTML 4.01,
    > and it's roughly accurate for XHTML up to 1.1 as well:http://www.w3.org/TR/html401/interact/forms.html
    >
    > HTH,
    > Rami
    >
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list
    >
    >
    
    HI,
      Ok the simplest solution for this is 
    
    Regards
    Jitish
    
    
    From ethan at stoneleaf.us  Wed Nov 25 10:47:39 2009
    From: ethan at stoneleaf.us (Ethan Furman)
    Date: Wed, 25 Nov 2009 07:47:39 -0800
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: <4b0cfefa$0$24750$426a34cc@news.free.fr>
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>	
    	<4b0cfefa$0$24750$426a34cc@news.free.fr>
    Message-ID: <4B0D519B.2030102@stoneleaf.us>
    
    Bruno Desthuilliers wrote:
    > Ethan Furman a ?crit :
    > 
    >>
    >> Let's head towards murkier waters (at least murkier to me -- hopefully 
    >> they can be easily clarified):  some of the attributes are read-only, 
    >> such as record count; others are not directly exposed, but still 
    >> settable, such as table version; and still others require a small 
    >> amount of processing... at which point do I switch from simple 
    >> attribute access to method access?
    > 
    > 
    > Short answer : you don't !-)
    > 
    > Long answer : well, in fact you do, but the client code doesn't have to 
    > be aware that it's in fact calling an accessor.
    > 
    > Before we go into more details, you have to know that Python has a 
    > pretty good support for computed attributes, with both a simple generic 
    > solution (the property type) and the full monty (custom types 
    > implementing the descriptor protocol). So from the "interface" POV, you 
    > should never have an explicit accessor method for what is semantically 
    > an attribute (wheter the attribute is a plain or a computed one being 
    > part of the implementation).
    > 
    > Let's start with your second point: "not directly exposed but still 
    > settable". I assume you mean "not part of the interface, only supposed 
    > to be accessed (rw) from the methods" - if not, please pardon my 
    > stupidity and provide better explanations !-).
    
    Better explanation: attribute is publicly available, but buried a couple 
    layers deep in a private structure (yes, private structure name starts 
    with a leading underscore).
    
    > If yes: Python doesn't 
    > have "language inforced" access restrictions (private / protected / 
    > etc), but a *very strong* naming convention which is that names starting 
    > with a leading underscore are implementation details, not part of the 
    > official interface, and shouldn't be accessed directly. Kind of a 
    > "warranty voided if unsealed".
    > 
    > So if you have attributes you don't want to "expose" to the outside 
    > world, just add a single leading underscore to their names.
    > 
    > First and third points are solved by using computed attributes - usually 
    > a property. The property type takes a few accessor functions as 
    > arguments - typically, a getter and a setter, and eventually a 
    > "deleter". Used as a class attribute, a property instance will hook up 
    > into the attribute lookup / setup mechanism (__getattribute__ and 
    > __setattr__), and will call resp. it's getter or setter function, 
    > passing it the instance and (for the setter) value.
    > 
    > This directly solves the third point. For the first one, the obvious 
    > solution is to use a property with a setter that raises an exception - 
    > canonically, an AttributeError with a message explaining that the 
    > attribute is read-only.
    > 
    > And for something more hands-on:
    > 
    > class Person(object):
    >    def __init__(self, firstname, lastname, birthdate):
    >        self.firstname = firstname
    >        self.lastname = lastnale
    >        self.birthdate = birthdate
    >        self._foo = 42 # implementation only
    > 
    >    def _getfullname(self):
    >        return "%s %s" % (self.firstname, self.lastname)
    >    def _setfullname(self, value):
    >        raise AttributeError("%s.fullname is read-only" % type(self)
    >    fullname = property(fget=_getfullname, fset=_setfullname)
    > 
    >    def _getage(self):
    >        return some_computation_with(self.birthdate)
    >    def _setage(self, value):
    >        raise AttributeError("%s.age is read-only" % type(self)
    >    age = property(fget=_getage, fset=_setage)
    > 
    > 
    > For more on computed attributes, you may want to read about the 
    > "descriptor protocol" (google is your friend as usual). This and the 
    > attribute resolution mechanism are fundamental parts of Python's inner 
    > working. Learn how it works if you really want to leverage Python's power.
    > 
    > HTH
    
    Very helpful, thank you.  Hopefully my brain will be up to the 
    descriptor protocol this time... the last couple times were, um, less 
    than successful.  :)
    
    ~Ethan~
    
    
    From niklasro at gmail.com  Wed Nov 25 11:05:24 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:05:24 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    Message-ID: 
    
    On Nov 23, 11:37?pm, "Rhodri James" 
    wrote:
    > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    > > Dear experts,
    > > Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > > Mercurial support not found i.e. buttons to clone, commit and push to
    > > repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > I don't really understand this urge to cram everything into a single ?
    > program, since that inevitably leads to compromises that will compromise ?
    > just how much of Mercurial's useful and interesting functionality you can ?
    > get at. ?Still, if you really must, Emacs (and presumably vim) seems to be ?
    > capable of working with most source control systems.
    >
    > --
    > Rhodri James *-* Wildebeest Herder to the Masses
    
    Obvious explainations are commandline is slower and IDEs claim support
    (Eric) which may mean it's up2 programmer to add and enable the ui. Or
    any binding to enable 1 ui. Emacs sure can.
    Thank you
    
    
    From niklasro at gmail.com  Wed Nov 25 11:06:32 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:06:32 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	
    Message-ID: <31ca1f32-70da-4f1f-8040-4ee7d544e55b@j19g2000yqk.googlegroups.com>
    
    On Nov 24, 2:35?pm, Gerhard H?ring  wrote:
    > Rhodri James wrote:
    > > On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >> Dear experts,
    > >> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >> Mercurial support not found i.e. buttons to clone, commit and push to
    > >> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > > I don't really understand this urge to cram everything into a single
    > > program, since that inevitably leads to compromises that will compromise
    > > just how much of Mercurial's useful and interesting functionality you
    > > can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > > to be capable of working with most source control systems.
    >
    > I prefer the commandline tools, too.
    >
    > FWIW, Eclipse supports Mercurial throughhttp://www.vectrace.com/mercurialeclipse/
    >
    > -- Gerhard
    
    Good just Eclipse is too much and tested 4,5... python IDE where non
    can hg. Just 2 or 3 buttons to drPython with script enables it.
    
    
    From niklasro at gmail.com  Wed Nov 25 11:07:41 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Wed, 25 Nov 2009 08:07:41 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    Message-ID: <20a1b95a-a04c-4632-b068-01006a484770@g26g2000yqe.googlegroups.com>
    
    On Nov 24, 3:13?pm, Richard Riley  wrote:
    > Gerhard H?ring  writes:
    > > Rhodri James wrote:
    > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > >>> Dear experts,
    > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > >> I don't really understand this urge to cram everything into a single
    > >> program, since that inevitably leads to compromises that will
    > >> compromise
    >
    > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > merely programmed to hook into the external tools
    >
    > >> just how much of Mercurial's useful and interesting functionality you
    > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > >> to be capable of working with most source control systems.
    >
    > > I prefer the commandline tools, too.
    >
    > > FWIW, Eclipse supports Mercurial through
    > >http://www.vectrace.com/mercurialeclipse/
    >
    > > -- Gerhard
    >
    > Why would you prefer the command line tools in a shell when the same
    > tools can be used in a way which makes navigating the output so much
    > easier? It strikes me as a kind of intransigence. it's a common
    > misconception that IDEs use their own tools all the time. They
    > don't. They integrate the very same tools. e.g Why the hell would I drop
    > to a command line to diff a file with a back version in GIT when I can
    > do the same in the buffer in emacs with a single hot key? Why would I
    > pipe the output of compile into a file then open that file when a single
    > hot key can fire off the SAME compiler and then list the errors in an
    > emacs buffer and another hot key can take me directly to the source
    > lines in question? Living in the past has its mements, but really.
    >
    > e.g I have pylint working live in python buffers. Big time
    > saver. Similar with C.
    
    true. While not many programmers lint the code.
    
    
    From perfreem at gmail.com  Wed Nov 25 11:42:01 2009
    From: perfreem at gmail.com (per)
    Date: Wed, 25 Nov 2009 08:42:01 -0800 (PST)
    Subject: creating pipelines in python
    References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com>
    	<87y6lxd37a.fsf@rudin.co.uk>
    Message-ID: <32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    
    Thanks to all for your replies.  i want to clarify what i mean by a
    pipeline.  a major feature i am looking for is the ability to chain
    functions or scripts together, where the output of one script -- which
    is usually a file -- is required for another script to run.  so one
    script has to wait for the other.  i would like to do this over a
    cluster, where some of the scripts are distributed as separate jobs on
    a cluster but the results are then collected together.  so the ideal
    library would have easily facilities for expressing this things:
    script X and Y run independently, but script Z depends on the output
    of X and Y (which is such and such file or file flag).
    
    is there a way to do this? i prefer not to use a framework that
    requires control of the clusters etc. like Disco, but something that's
    light weight and simple. right now ruffus seems most relevant but i am
    not sure -- are there other candidates?
    
    thank you.
    
    On Nov 23, 4:02?am, Paul Rudin  wrote:
    > per  writes:
    > > hi all,
    >
    > > i am looking for a python package to make it easier to create a
    > > "pipeline" of scripts (all in python). what i do right now is have a
    > > set of scripts that produce certain files as output, and i simply have
    > > a "master" script that checks at each stage whether the output of the
    > > previous script exists, using functions from the os module. this has
    > > several flaws and i am sure someone has thought of nice abstractions
    > > for making these kind of wrappers easier to write.
    >
    > > does anyone have any recommendations for python packages that can do
    > > this?
    >
    > Not entirely what you're looking for, but the subprocess module is
    > easier to work with for this sort of thing than os. See e.g. 
    
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Wed Nov 25 11:46:49 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Wed, 25 Nov 2009 17:46:49 +0100
    Subject: attributes, properties, and accessors -- philosophy
    In-Reply-To: 
    References: 	<4b0b92de$0$14677$426a74cc@news.free.fr>		<4b0cfefa$0$24750$426a34cc@news.free.fr>
    	
    Message-ID: <4b0d5f78$0$23304$426a74cc@news.free.fr>
    
    Ethan Furman a ?crit :
    > 
    > Very helpful, thank you.  Hopefully my brain will be up to the 
    > descriptor protocol this time... the last couple times were, um, less 
    > than successful.  :)
    
    Well, it's quite simple in fact. Most of the "magic" happens in 
    object.__getattribute__ and object.__setattr__. You'll find a rough 
    description of what happens here:
    
    http://groups.google.com/group/comp.lang.python/browse_frm/thread/a136f7626b2a8b7d/70a672cf7448c68e
    
    
    
    
    
    
    From mal at egenix.com  Wed Nov 25 11:53:16 2009
    From: mal at egenix.com (M.-A. Lemburg)
    Date: Wed, 25 Nov 2009 17:53:16 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 
    Message-ID: <4B0D60FC.9030906@egenix.com>
    
    Sibylle Koczian wrote:
    > Hello,
    > 
    > I want to put data from a database into a tab separated text file. This
    > looks like a typical application for the csv module, but there is a
    > snag: the rows I get from the database module (kinterbasdb in this case)
    > contain unicode objects and numbers. And of course the unicode objects
    > contain lots of non-ascii characters.
    > 
    > If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
    > the UnicodeWriter from the module documentation, I get TypeErrors with
    > the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
    > would cause other complications.)
    > 
    > So do I have to process the rows myself and treat numbers and text
    > fields differently? Or what's the best way?
    
    It's best to convert all data to plain strings before passing it
    to the csv module.
    
    There are many situations where you may want to use a different
    string format than the standard str(obj) format, so this is best
    done with a set of format methods - one for each type and format
    you need, e.g. one for integers, floats, monetary values, Unicode
    text, plain text, etc.
    
    The required formatting also depends on the consumers of the
    generated csv or tsv file and their locale.
    
    -- 
    Marc-Andre Lemburg
    eGenix.com
    
    Professional Python Services directly from the Source  (#1, Nov 25 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 emile at fenx.com  Wed Nov 25 12:35:53 2009
    From: emile at fenx.com (Emile van Sebille)
    Date: Wed, 25 Nov 2009 09:35:53 -0800
    Subject: Help with pprint
    In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    References: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    Message-ID: 
    
    On 11/25/2009 4:47 AM Nadav Chernin said...
    > Hello, I want to print list of lists in matrix format. So I use pprint 
    > with parameter ?width? for this target.
    
    > The problem that I don?t know how to select width value, because if:
    > 
    >  
    > 
    >  >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
    > 'one']]  
    > 
    >  >>> pprint(data,width=20)
    
    Almost...
    
     >>> pprint.pprint(data,width=24)
    [['one', 'one', 'one'],
      ['one', 'one', 'one'],
      ['one', 'one', 'one']]
    
    Emile
    
    
    
    From doug.stevens73 at gmail.com  Wed Nov 25 12:38:54 2009
    From: doug.stevens73 at gmail.com (doug)
    Date: Wed, 25 Nov 2009 09:38:54 -0800 (PST)
    Subject: How to run python script in emacs
    References: 
    	
    Message-ID: <5273278a-abb3-4573-82df-ecdfc0de6837@e27g2000yqd.googlegroups.com>
    
    
    When I type C-c C-c my emacs window just hangs.  If I use Task Manager
    to kill cmdproxy I can get emacs back but of course interactivity with
    Python is not accomplished.  By the way, if I do C-c ! then I get a
    functional python shell.  Does anybody know a solution to this?
    
    On Oct 13, 7:12?am, rustom  wrote:
    > On Sep 26, 8:54?pm, devilkin  wrote:
    >
    > > I'm just starting learning python, and coding in emacs. I usually
    > > split emacs window into two, coding in one, and run script in the
    > > other, which is not very convenient. anyone can help me with it? is
    > > there any tricks like emacs short cut?
    >
    > > also please recommand some emacs plug-ins for python programming, i'm
    > > also beginner in emacs.currently i'm only using python.el.
    >
    > python.el comes with emacs
    > python-mode.el comes from python ?https://launchpad.net/python-mode/
    > Because of some emacs politics the first ships with emacs although
    > most uses prefer the second.
    > Note 1. The key bindings are different
    > Note 2. Does not work with python3. See my posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
    >
    > > Are any plugins supply code folding and autocomplete?
    >
    > See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
    > but its an installation headache (requires pymacs bleeding edge
    > version etc)
    > I suggest you just get used to python-mode first (C-c ! and C-c C-c)
    > and then explore these questions a bit later.
    >
    >
    >
    > > BTW, I'm not a english native speaker, any grammer mistakes, please
    > > correct them. :)
    >
    > grammer is spelt grammar :-)
    
    
    
    From jeff at jmcneil.net  Wed Nov 25 12:54:46 2009
    From: jeff at jmcneil.net (Jeff McNeil)
    Date: Wed, 25 Nov 2009 09:54:46 -0800 (PST)
    Subject: CentOS 5.3 vs. Python 2.5
    References: <4b0ccf27$0$1655$742ec2ed@news.sonic.net>
    	 
    	
    Message-ID: <7c952554-96f2-4de2-b4b8-935d8fe45ebd@n35g2000yqm.googlegroups.com>
    
    On Nov 25, 4:45?am, Jon Clements  wrote:
    > On Nov 25, 8:13?am, Steven D'Aprano
    >
    >
    >
    >
    >
    >  wrote:
    > > On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
    > > > My dedicated hosting provider wants to switch me to a new server with
    > > > CentOS 5.3, so I have to look at how much work is required.
    >
    > > > ? ? CentOS 5.3 apparently still ships with Python 2.4. ?Worse, it
    > > > requires Python 2.4 for its own internal purposes, and actually
    > > > installing Python 2.5 breaks the package manager. ?There's no supported
    > > > RPM for upgrading.
    >
    > > > ? ? It's apparently necessary to build Python 2.5 from source,
    > > > build all the packages, and debug.
    >
    > > You shouldn't need *quite* that much effort, particularly if you don't
    > > care about tkinter. Just use the alternate installation so it doesn't
    > > stomp all over the 2.4 installation:
    >
    > > .configure
    > > make
    > > make altinstall
    >
    > > You will need root or sudo for that last one.
    >
    > > I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
    > > easily for me:
    >
    > > $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
    > > ...
    > > 18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
    > > $
    > > $ tar xzf Python-2.5.4.tgz
    > > $ cd Python-2.5.4
    > > $ ./configure
    > > ...
    > > $ make
    > > ...
    > > $ sudo make altinstall
    > > Password:
    > > ...
    > > $ python -V
    > > Python 2.4.3
    > > $ python2.5 -V
    > > Python 2.5.4
    >
    > > And it all seems to just work for me.
    >
    > > > Nor does that "just work". There's
    > > > documentation, but some of it is in Japanese.
    >
    > > >http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/
    >
    > > I don't understand why you're using documentation for third-party RPMs as
    > > evidence that building from source will be troublesome.
    >
    > > --
    > > Steven
    >
    > And might I add on a box where there is no root access, but sufficient
    > tools (compilers etc...)
    >
    > 1) Compile from source
    > 2) Set PYTHONPATH correctly for your shell
    > 3) Set your normal path to include your Python rather than the
    > system's default Python
    > 4) When installing modules (via setup.py install or easy_install)
    > include a "home_dir=" (I think that's right OTTOMH) to somewhere in
    > your home directory, and make sure step 2) complies with this.
    > 5) Double check with "which python" to make sure it's the correct
    > version.
    >
    > hth
    > Jon.
    
    I'm in a RHEL3 - RHEL5.4 environment and the situation is exactly the
    same.  The code I've written requires 2.5 or higher.  I keep a /usr/
    local/pythons directory and manually install the versions I need
    there.  I then use virtualenv so I don't have to worry about setting
    PYTHONPATH manually or anything. I just need to remember to use the
    right Python executable. I got to doing this when I discovered that
    there are issues with the Cluster Manager (Lucci) and some external
    Python packages (some of the Zope stuff, if I remember correctly).
    
    So, in addition to the above steps, you'll probably also want to
    include a '--prefix=.....' on the command line to the configure script
    in order to install in a non-standard location.
    
    
    
    From dboddie at trolltech.com  Wed Nov 25 13:57:17 2009
    From: dboddie at trolltech.com (David Boddie)
    Date: Wed, 25 Nov 2009 19:57:17 +0100
    Subject: QtPython: removeChild/addChild QGroupBox
    Message-ID: <200911251957.18330.dboddie@trolltech.com>
    
    On Mon Nov 23 10:35:26 CET 2009, Threader Slash wrote:
    
    > I am developing a system for a customer which is displayed in a set of
    > GroupBox.
    > Depending on mouse events, the container (groupBox) must be removed from
    > the centralwidget, or then added with new updated data for the table.
    > Here is a piece of the code that runs nicely and shows the a groupBox.
    >
    > Now it starts to show some effects on removeWidget, but it is still didn't
    > clear the box completely.. just the right border of the box is erased.
    
    [...]
    
    Dynamically changing layouts isn't the most intuitive thing to do in Qt.
    It might be easier to get something close to the effect you are looking for
    if you just hide the group box instead.
    
    David
    
    
    From manu3d at gmail.com  Wed Nov 25 14:02:39 2009
    From: manu3d at gmail.com (Emanuele D'Arrigo)
    Date: Wed, 25 Nov 2009 11:02:39 -0800 (PST)
    Subject: Python Statements/Keyword Localization
    Message-ID: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    
    Greetings everybody,
    
    some time ago I saw a paper that used an XSL transformation sheet to
    transform (if I remember correctly) a Chinese xml file (inclusive of
    Chinese-script XML tags) into an XHTML file.
    
    More recently you might have all heard how the ICANN has opened up the
    way for non-latin characters in domain names, so that we'll soon start
    seeing URLs using Russian, Asian and Arabic characters.
    
    In this context I was wondering if there has ever been much thought
    about a mechanism to allow the localization not only of the strings
    handled by python but also of its built-in keywords, such as "if",
    "for", "while", "class" and so on. For example, the following English-
    based piece of code:
    
    class MyClass(object):
        def myMethod(self, aVariable):
             if aVariable == True:
                print "It's True!"
             else:
                print "It's False!"
    
    would become (in Italian):
    
    classe LaMiaClasse(oggetto):
        def ilMioMetodo(io, unaVariabile)
             se unaVariabile == Vero:
                 stampa "E' Vero!"
             altrimenti:
                 stampa "E' Falso!"
    
    I can imagine how a translation script going through the source code
    could do a 1:1 keyword translation to English fairly quickly but this
    would mean that the runtime code still is in English and any error
    message would be in English. I can also imagine that it should be
    possible to "simply" recompile python to use different keywords, but
    then all libraries using the English keywords would become
    incompatible, wouldn't they?
    
    In this context it seems to be the case that the executable would have
    to be able to optionally accept -a list- of dictionaries to internally
    translate to English the keywords found in the input code and at most -
    one- dictionary to internally translate from English output messages
    such as a stack trace.
    
    What do you guys think?
    
    Manu
    
    
    From saketbharamberocks at gmail.com  Wed Nov 25 14:40:30 2009
    From: saketbharamberocks at gmail.com (Saket Bharambe)
    Date: Wed, 25 Nov 2009 11:40:30 -0800 (PST)
    Subject: A language for S40 mobiles
    Message-ID: <2bbdb975-e85c-477c-b906-6c9b31279cb9@s21g2000prm.googlegroups.com>
    
    Hey,
    I have recently created an application for S60 mobiles. But I want to
    create a similar application for S40 mobiles too. I did the
    application of S60 in pyS60 as java had problems with accessing inbox
    and contacts. I tried searching for pyS40 , but i couldnt find it.
    
    Ques : Is there python for S40 mobiles ? If yes , where can i find the
    installation files and documentation . If no , which the best language
    for writing application for S40 mobiles. (keeping in mind that I need
    to access the Inbox(sms) and contacts ) ?
    
    
    From tjreedy at udel.edu  Wed Nov 25 15:03:50 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 15:03:50 -0500
    Subject: How to log messages _only once_ from all modules ?
    In-Reply-To: <4B0D1BDD.70400@sequans.com>
    References: <7F0503CD69378F49BE0DC30661C6CCF68235BD08@enbmail01.lsi.com>
    	<4B0D1BDD.70400@sequans.com>
    Message-ID: 
    
    Jean-Michel Pichavant wrote:
    
    > 
    > Basically, never configure or add handlers to any logger except for the 
    > root logger in your __main__ section. There are very few reasons why you 
    > would break this rule. And when you'll be familiar with the logging 
    > module you'll when to break it.
    
    I have never used logging, but if and when I have a need for it, the 
    advice above and your clear example will be a good guide to getting 
    started. Thank you from me too.
    
    tjr
    
    > [server.py]
    > 
    > import logging
    > import logging.handlers
    > 
    > logger = logging.getLogger(__name__) # you'd better to create the logger 
    > at the module level, you may want to log within   the module function
    > 
    > def aFunction(a, b, ,c):
    >    logger.debug('You called aFunction')
    > 
    > class Server():
    >    def __init__(self):
    >        self.logger = logger
    > 
    >    def util(self):
    >        self.logger.warning('This message comes from Server module ')
    > 
    > 
    > [client.py]
    > 
    > import logging
    > import logging.handlers
    > from server import Server
    > 
    > logger = logging.getLogger(__name__)
    > 
    > class Client():
    >    def __init__(self):
    >        self.logger = logger
    > 
    >    def client_test(self):
    >        self.logger.warning("This message comes from Client module")
    > 
    > if __name__ == "__main__":
    >    rootLogger = logging.getLogger()
    >    rootLogger.addHandler(logging.FileHandler("client.log"))
    >    rootLogger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s 
    > %(name)-12s %(levelname)-8s %(message)s"))
    >    rootLogger.setLevel(logging.DEBUG)
    >    ser = Server()
    >    cli = Client()
    >    ser.util()
    >    cli.client_test()
    > 
    > Happy logging,
    > 
    > Jean-Michel
    
    
    
    From stef.mientki at gmail.com  Wed Nov 25 15:03:54 2009
    From: stef.mientki at gmail.com (Stef Mientki)
    Date: Wed, 25 Nov 2009 21:03:54 +0100
    Subject: python gui builders
    In-Reply-To: <987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    References: <8u9Mm.35397$Wd1.32454@newsfe15.iad>	<007f3944$0$23487$c3e8da3@news.astraweb.com>
    	<05d2b7b3-b5b0-41b3-8050-ccb2c71675ab@m38g2000yqd.googlegroups.com>
    	<863dc6be-0a0c-4045-a02e-a7ccf8d6cbda@r5g2000yqb.googlegroups.com>
    	
    	<987212be-5934-4c90-ab16-33578c57b77c@b2g2000yqi.googlegroups.com>
    Message-ID: <4B0D8DAA.4020200@gmail.com>
    
    Shawn Wheatley wrote:
    > It's not quite all encompassing, but I found this link last year when
    > looking for a similar comparison of Python GUIs:
    > http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/
    >
    > Tkinter, Qt, GTK, IronPython... I think the only thing missing is
    > Jython w/ Swing or SWT. Check it out.
    >   
    Instead of "*hello* world" examples, I was thinking of  "*real* world" 
    applications,
    something like this,
      http://mientki.ruhosting.nl/data_www/pylab_works/random_gui.html
    which in a good GUI package should be doable in about 100 lines of code.
    
    cheers,
    Stef
    > Shawn
    >
    > On Nov 18, 5:11 pm, Stef Mientki  wrote:
    >   
    >> Wouldn't it be nice
    >> if each fan of some form of GUI-package,
    >> would post it's code (and resulting images) for generating one or two
    >> standard GUI-forms ?
    >>     
    
    
    
    From tjreedy at udel.edu  Wed Nov 25 15:22:08 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 15:22:08 -0500
    Subject: Help with pprint
    In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    References: <97FB089C6E1F404CB0132AC3BB3E5C2701947623@exchange.qualisystems.local>
    Message-ID: 
    
    Nadav Chernin wrote:
    > Hello, I want to print list of lists in matrix format. So I use pprint 
    > with parameter ?width? for this target.
    > 
    > For example :
    >  >>> data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    >  >>> pprint(data,width=20)
    > [[1, 1, 1], 
    >  [1, 1, 1],
    >  [1, 1, 1]]
    
    > 
    > The problem that I don?t know how to select width value, because if:
    >   >>>data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
    > 'one']]  
    >  >>> pprint(data,width=20)
    > [['one',
    >   'one',
      [snip]
    
    1. Cpp.pprint(data, width=100)alculate a width that is big enough but 
    not too big. In your example, the interval is [24,69]
    2. Write a loop, which gives you finer control.
    
     >>> for line in data: print(line)
    ['one', 'one', 'one']
    ['one', 'one', 'one']
    ['one', 'one', 'one']
    
    To me, this is more like a matrix and possibly better, depending on your 
    particular application. If the items have different default printed 
    widths and you want column lined up, you will need to custom format each 
      field in a column to a uniform width anyway. Print and pprint are for 
    quick, take-what-you-get output, not for customj-designed production output.
    
    Terry Jan Reedy
    
    
    
    From ericwoodworth at gmail.com  Wed Nov 25 15:22:55 2009
    From: ericwoodworth at gmail.com (EW)
    Date: Wed, 25 Nov 2009 12:22:55 -0800 (PST)
    Subject: reading windows event logs
    Message-ID: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    
    Hi All,
         I'm looking for some guidance on a better way to read eventlogs
    from windows servers.  I've written a handy little app that relies on
    WMI to pull the logs an in all my testing it worked great.  When I
    deployed it, however, WMI choked on servers with a lot of logs.  I've
    tried pulling the logs using much smaller VB scripts as well and they
    still failed, so I'm pretty sure I'm facing a WMI problem and not a
    python or system resources problem.  So I couldn't effectively get
    logs off of domain controllers for example or file servers that had
    auditing turned on.  Sadly those are exactly the types of servers
    whose logs are most interesting.
    
         So I'm looking for suggestions on a way to grab that data without
    using WMI for remote machines.  I know MS has C libraries for this but
    I haven't touched C for 10 years so I'm hoping there's a python
    equivalent out there somewhere.  Any advice would be appreciated.
    
    Thanks in advance for any help,
    Eric
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 15:26:34 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 20:26:34 +0000
    Subject: Python Statements/Keyword Localization
    In-Reply-To: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: <4B0D92FA.8010009@mrabarnett.plus.com>
    
    Emanuele D'Arrigo wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    > 
    > In this context I was wondering if there has ever been much thought
    > about a mechanism to allow the localization not only of the strings
    > handled by python but also of its built-in keywords, such as "if",
    > "for", "while", "class" and so on. For example, the following English-
    > based piece of code:
    > 
    > class MyClass(object):
    >     def myMethod(self, aVariable):
    >          if aVariable == True:
    >             print "It's True!"
    >          else:
    >             print "It's False!"
    > 
    > would become (in Italian):
    > 
    > classe LaMiaClasse(oggetto):
    >     def ilMioMetodo(io, unaVariabile)
    >          se unaVariabile == Vero:
    >              stampa "E' Vero!"
    >          altrimenti:
    >              stampa "E' Falso!"
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly but this
    > would mean that the runtime code still is in English and any error
    > message would be in English. I can also imagine that it should be
    > possible to "simply" recompile python to use different keywords, but
    > then all libraries using the English keywords would become
    > incompatible, wouldn't they?
    > 
    > In this context it seems to be the case that the executable would have
    > to be able to optionally accept -a list- of dictionaries to internally
    > translate to English the keywords found in the input code and at most -
    > one- dictionary to internally translate from English output messages
    > such as a stack trace.
    > 
    > What do you guys think?
    > 
    It might be necessary to work in tokens, where a token is a word or a
    string (or maybe also a comment). Your example would be encoded to:
    
         ?1? ?2?(?3?):
             ?4? ?5?(?6?, ?7?):
                 ?8? ?7? == ?9?:
                     ?10? ?11?
                 ?12?:
                     ?10? ?13?
    
    with either English:
    
         ?1? class
         ?2? MyClass
         ?3? object
         ?4? def
         ?5? myMethod
         ?6? self
         ?7? aVariable
         ?8? if
         ?9? True
         ?10? print
         ?11? "It's True!"
         ?12? else
         ?13? "It's False!"
    
    or Italian:
    
         ?1? classe
         ?2? LaMiaClasse
         ?3? oggetto
         ?4? def
         ?5? ilMioMetodo
         ?6? io
         ?7? unaVariabile
         ?8? se
         ?9? Vero
         ?10? stampa
         ?11? "? Vero!"
         ?12? altrimenti
         ?13? "? Falso!"
    
    Any messages produced by, or format strings used by, the runtime would
    also be tokens.
    
    Python currently does lexical analysis on the source code to identify
    names, strings, etc; a new tokenised file format would partially bypass
    that because the names and strings (and comments?) have already been
    identified.
    
    
    From garabik-news-2005-05 at kassiopeia.juls.savba.sk  Wed Nov 25 15:27:53 2009
    From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk)
    Date: Wed, 25 Nov 2009 20:27:53 +0000 (UTC)
    Subject: Python Statements/Keyword Localization
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: 
    
    Emanuele D'Arrigo  wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    
    Non-latin characters in domain names are already possible (and usable and
    actually used) for some years by now. Google for "punycode".
    
    ICANN was talking about TLD.
    
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly
    
    ...and get conflickts because I named my variable (in English python),
    say, stampa.
    
    Anyway, see http://www.chinesepython.org
    
    -- 
     -----------------------------------------------------------
    | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ |
    | __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
     -----------------------------------------------------------
    Antivirus alert: file .signature infected by signature virus.
    Hi! I'm a signature virus! Copy me into your signature file to help me spread!
    
    
    From nulla.epistola at web.de  Wed Nov 25 15:31:14 2009
    From: nulla.epistola at web.de (Sibylle Koczian)
    Date: Wed, 25 Nov 2009 21:31:14 +0100
    Subject: csv and mixed lists of unicode and numbers
    In-Reply-To: 
    References: 		
    	
    Message-ID: 
    
    Terry Reedy schrieb:
    
    > In Python 3, a file opened in 'b' mode is for reading and writing bytes 
    > with no encoding/decoding. I believe cvs works with files in text mode 
    > as it returns and expects strings/text for reading and writing. Perhaps 
    > the cvs doc should say must not be opened in 'b' mode. Not sure.
    > 
    
    I think that might really be better, because for version 2.6 they 
    explicitly stated 'b' mode was necessary. The results I couldn't 
    understand, even after reading the documentation for open():
    
     >>> import csv
     >>> acsv = open(r"d:\home\sibylle\temp\tmp.csv", "wb")
     >>> row = [b"abc", b"def", b"ghi"]
     >>> wtr = csv.writer(acsv)
     >>> wtr.writerow(row)
    Traceback (most recent call last):
       File "", line 1, in 
         wtr.writerow(row)
    TypeError: must be bytes or buffer, not str
    
    Same error message with row = [5].
    
    But I think I understand it now: the cvs.writer takes mixed lists of 
    text and numbers - that's exactly why I like to use it - so it has to 
    convert them before writing. And it converts into text - even bytes for 
    a file opened in 'b' mode. Right?
    
    Thank you, everybody, for explaining.
    
    Sibylle
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 15:55:20 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 20:55:20 +0000
    Subject: reading windows event logs
    In-Reply-To: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    References: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    Message-ID: <4B0D99B8.1010605@mrabarnett.plus.com>
    
    EW wrote:
    > Hi All,
    >      I'm looking for some guidance on a better way to read eventlogs
    > from windows servers.  I've written a handy little app that relies on
    > WMI to pull the logs an in all my testing it worked great.  When I
    > deployed it, however, WMI choked on servers with a lot of logs.  I've
    > tried pulling the logs using much smaller VB scripts as well and they
    > still failed, so I'm pretty sure I'm facing a WMI problem and not a
    > python or system resources problem.  So I couldn't effectively get
    > logs off of domain controllers for example or file servers that had
    > auditing turned on.  Sadly those are exactly the types of servers
    > whose logs are most interesting.
    > 
    >      So I'm looking for suggestions on a way to grab that data without
    > using WMI for remote machines.  I know MS has C libraries for this but
    > I haven't touched C for 10 years so I'm hoping there's a python
    > equivalent out there somewhere.  Any advice would be appreciated.
    > 
    The events logs are in %SystemRoot%\system32\config and have the
    extension .evt. There's info here on the file format:
    
    http://www.whitehats.ca/main/members/Malik/malik_eventlogs/malik_eventlogs.html
    
    
    
    From tjreedy at udel.edu  Wed Nov 25 16:26:00 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 16:26:00 -0500
    Subject: Python Statements/Keyword Localization
    In-Reply-To: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com>
    Message-ID: 
    
    Emanuele D'Arrigo wrote:
    > Greetings everybody,
    > 
    > some time ago I saw a paper that used an XSL transformation sheet to
    > transform (if I remember correctly) a Chinese xml file (inclusive of
    > Chinese-script XML tags) into an XHTML file.
    > 
    > More recently you might have all heard how the ICANN has opened up the
    > way for non-latin characters in domain names, so that we'll soon start
    > seeing URLs using Russian, Asian and Arabic characters.
    > 
    > In this context I was wondering if there has ever been much thought
    > about a mechanism to allow the localization not only of the strings
    > handled by python but also of its built-in keywords, such as "if",
    > "for", "while", "class" and so on.
    
    There have been various debates and discussions on the topic. There has 
    been slow movement away from ascii-only in user code. (But not in the 
    stdlib, nor will there be there.)
    1. Unicode data type.
    2. Unicode allowed in comment and string literals.
    This required input decoding and coding cookie. This lead, I believe 
    somewhat accidentally, to
    3. Extended ascii (high bit set, for other European chars in various 
    encodings) for identifiers.
    4 (In 3.0) unicode allowed for identifiers
    
      Here is a version of the anti-customized-keyword position. Python is 
    designed to be read by people. Currently, any programmer in the world 
    can potentially read any Python program. The developers, especially 
    Guido, like this. Fixed keywords are not an undue burden because any 
    educated person should learn to read Latin characters a-z,0-9. and 
    Python has an intentionally  short list that the developers are loath to 
    lengthen.
    
    Change 4 above inhibits universal readability. But once 3 happened and 
    str became unicode, in 3.0, it was hard to say no to this.
    
    A 'pro' argument: Python was designed for learning and is good for that 
    and *is* used in schools down to the elementary level. But kids cannot 
    be expected to know foreign alphabets and words whill still learning 
    their own.
    
     > For example, the following English-
    > based piece of code:
    > 
    > class MyClass(object):
    >     def myMethod(self, aVariable):
    >          if aVariable == True:
    >             print "It's True!"
    >          else:
    >             print "It's False!"
    > 
    > would become (in Italian):
    > 
    > classe LaMiaClasse(oggetto):
    >     def ilMioMetodo(io, unaVariabile)
    >          se unaVariabile == Vero:
    >              stampa "E' Vero!"
    >          altrimenti:
    >              stampa "E' Falso!"
    > 
    > I can imagine how a translation script going through the source code
    > could do a 1:1 keyword translation to English fairly quickly but this
    > would mean that the runtime code still is in English and any error
    > message would be in English.
    
    This is currently seen as a reason to not have other keywords: it will 
    do no good anyway. A Python programmer must know minimal English and the 
    keywords are the least of the problem.
    
    I can imagine that there could be a mechanism for extracting and 
    replacing error messages with translations, like there is for Python 
    code, but I do not know if it will even happen with haphazard volunteer 
    work or will require grant sponsorship.
    
    > I can also imagine that it should be
    > possible to "simply" recompile python to use different keywords, but
    > then all libraries using the English keywords would become
    > incompatible, wouldn't they?
    > 
    > In this context it seems to be the case that the executable would have
    > to be able to optionally accept -a list- of dictionaries to internally
    > translate to English the keywords found in the input code and at most -
    > one- dictionary to internally translate from English output messages
    > such as a stack trace.
    > 
    > What do you guys think?
    
    I would like anyone in the world to be able to use Python, and I would 
    like Python programmers to potentially be able to potentially read any 
    Python code and not have the community severely balkanized. To me, this 
    would eventually mean both native keywords and tranliteration from other 
    alphabets and scripts to latin chars. Not an easy project.
    
    Terry Jan Reedy
    
    
    
    From aahz at pythoncraft.com  Wed Nov 25 16:38:19 2009
    From: aahz at pythoncraft.com (Aahz)
    Date: 25 Nov 2009 13:38:19 -0800
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    Message-ID: 
    
    In article ,
    Chris Rebert   wrote:
    >
    >If you want to prevent an instance being created in the first place,
    >you can override __new__().
    
    Or just raise an exception in __init__(), which I think is more common
    practice.
    -- 
    Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/
    
    The best way to get information on Usenet is not to ask a question, but
    to post the wrong information.  
    
    
    From francesco.pietra at accademialucchese.it  Wed Nov 25 16:40:28 2009
    From: francesco.pietra at accademialucchese.it (Francesco Pietra)
    Date: Wed, 25 Nov 2009 22:40:28 +0100
    Subject: reposition a column
    Message-ID: 
    
    Hi:
    
    In a pdb file made of lines "ATOM .." (see attachment as I was unable
    to obtain plain text with gmail) I would like to reposition the second
    "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    would be 20 18). I started with bold slices, then I was unable to
    complete the script. Much obliged for help.
    
    francesco pietra
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: repositionRES.py
    Type: text/x-python
    Size: 438 bytes
    Desc: not available
    URL: 
    
    From stefan_ml at behnel.de  Wed Nov 25 16:46:58 2009
    From: stefan_ml at behnel.de (Stefan Behnel)
    Date: Wed, 25 Nov 2009 22:46:58 +0100
    Subject: creating pipelines in python
    In-Reply-To: <32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    References: <91cb0bcd-02ba-4158-8c57-44caecf6d12e@x31g2000yqx.googlegroups.com>
    	<87y6lxd37a.fsf@rudin.co.uk>
    	<32e1d1e2-4961-421b-85ad-b0c3c2691f52@j14g2000yqm.googlegroups.com>
    Message-ID: <4b0da5d5$0$6573$9b4e6d93@newsspool3.arcor-online.net>
    
    per, 25.11.2009 17:42:
    > Thanks to all for your replies.  i want to clarify what i mean by a
    > pipeline.  a major feature i am looking for is the ability to chain
    > functions or scripts together, where the output of one script -- which
    > is usually a file -- is required for another script to run.  so one
    > script has to wait for the other.  i would like to do this over a
    > cluster, where some of the scripts are distributed as separate jobs on
    > a cluster but the results are then collected together.  so the ideal
    > library would have easily facilities for expressing this things:
    > script X and Y run independently, but script Z depends on the output
    > of X and Y (which is such and such file or file flag).
    > 
    > is there a way to do this? i prefer not to use a framework that
    > requires control of the clusters etc. like Disco, but something that's
    > light weight and simple. right now ruffus seems most relevant but i am
    > not sure -- are there other candidates?
    
    As others have pointed out, a Unix pipe approach might be helpful if you
    want the processes to run in parallel. You can send the output of one
    process to stdout, a network socket, an HTTP channel or whatever, and have
    the next process read it and work on it while it's being generated by the
    first process.
    
    Looking into generators is still a good idea, even if you go for a pipe
    approach. See the link posted by Wolodja Wentland.
    
    Stefan
    
    
    From dksreddy at gmail.com  Wed Nov 25 16:52:09 2009
    From: dksreddy at gmail.com (Sandy)
    Date: Wed, 25 Nov 2009 13:52:09 -0800 (PST)
    Subject: confused with os.fork()
    Message-ID: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    
    Hi all,
    I am a little bit confused about os.fork().
    Say I have the following code.
    
    import os
    a = ['a','b','c','d','e']
    
    for i in xrange(len(a)):
        pid = os.fork()
        if not pid:
            print a[i]
            os._exit(0)
    
    >From most of the tuts and examples I saw online, I expect it to print
    a,b,c,d,e.
    Sometimes (very rare) it prints something like this:
    ab
    c
    d
    e
    I thought there is no way a parent process can enter the 'if'.
    Can anyone explain this behaviour? Is it the case where parent is
    forking a child even before the previous child is printing? In that
    case is there a way to prevent that? I can use os.wait(), but I don't
    want to wait till the child is finished, just don't want to mix the
    child processes, that's it.
    
    - dksr
    
    
    From deets at nospam.web.de  Wed Nov 25 17:15:50 2009
    From: deets at nospam.web.de (Diez B. Roggisch)
    Date: Wed, 25 Nov 2009 23:15:50 +0100
    Subject: confused with os.fork()
    In-Reply-To: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    References: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    Message-ID: <7n5okmF3ju980U1@mid.uni-berlin.de>
    
    Sandy schrieb:
    > Hi all,
    > I am a little bit confused about os.fork().
    > Say I have the following code.
    > 
    > import os
    > a = ['a','b','c','d','e']
    > 
    > for i in xrange(len(a)):
    >     pid = os.fork()
    >     if not pid:
    >         print a[i]
    >         os._exit(0)
    > 
    > From most of the tuts and examples I saw online, I expect it to print
    > a,b,c,d,e.
    > Sometimes (very rare) it prints something like this:
    > ab
    > c
    > d
    > e
    > I thought there is no way a parent process can enter the 'if'.
    > Can anyone explain this behaviour? Is it the case where parent is
    > forking a child even before the previous child is printing? In that
    > case is there a way to prevent that? I can use os.wait(), but I don't
    > want to wait till the child is finished, just don't want to mix the
    > child processes, that's it.
    
    Yes, that's the case - you have a race-condition here. Two childs at the 
    same time write, interleaving their data.
    
    To prevent this, you can use file-locking.
    
    http://docs.python.org/library/fcntl.html#fcntl.lockf
    
    Diez
    
    
    From icanbob at gmail.com  Wed Nov 25 17:18:29 2009
    From: icanbob at gmail.com (bobicanprogram)
    Date: Wed, 25 Nov 2009 14:18:29 -0800 (PST)
    Subject: Python & OpenOffice Spreadsheets
    References: 
    Message-ID: <6933d92b-3e22-4e3f-a69a-9e82db662c0a@s15g2000yqs.googlegroups.com>
    
    On Nov 23, 5:49 am, Gerhard H?ring  wrote:
    > Is there a *simple* way to read OpenOffice spreadsheets?
    >
    > Bonus: write them, too?
    >
    > I mean something like:
    >
    > doc.cells[0][0] = "foo"
    > doc.save("xyz.ods")
    >
    > >From a quick look, pyodf offers little more than just using a XML parser
    >
    > directly.
    >
    > -- Gerhard
    
    
    OO Calc has an HTML file feature for auto updating fields in a
    spreadsheet.
    
    I hacked together something for a talk a few years ago:
    
    http://www.icanprogram.com/hosug
    
    (See Open Office Calc demo section)
    While it isn't Python code it should be easy enough to convert to
    Python.
    
    bob
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 17:25:06 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 22:25:06 +0000
    Subject: reposition a column
    In-Reply-To: 
    References: 
    Message-ID: <4B0DAEC2.7050306@mrabarnett.plus.com>
    
    Francesco Pietra wrote:
    > Hi:
    > 
    > In a pdb file made of lines "ATOM .." (see attachment as I was unable
    > to obtain plain text with gmail) I would like to reposition the second
    > "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    > would be 20 18). I started with bold slices, then I was unable to
    > complete the script. Much obliged for help.
    > 
    I'm assuming that you want to put a space where the 'W' was.
    
    L = L[ : 17] + L[19] + L[18] + ' ' + L[20 : ]
    
    
    
    From vlastimil.brom at gmail.com  Wed Nov 25 17:32:17 2009
    From: vlastimil.brom at gmail.com (Vlastimil Brom)
    Date: Wed, 25 Nov 2009 23:32:17 +0100
    Subject: reposition a column
    In-Reply-To: 
    References: 
    Message-ID: <9fdb569a0911251432h10b04a4dra1ee8dc18c425954@mail.gmail.com>
    
    2009/11/25 Francesco Pietra :
    > Hi:
    >
    > In a pdb file made of lines "ATOM .." (see attachment as I was unable
    > to obtain plain text with gmail) I would like to reposition the second
    > "W" from column 19 to 17 ( (Python numbering; in pdb numbering it
    > would be 20 18). I started with bold slices, then I was unable to
    > complete the script. Much obliged for help.
    >
    > francesco pietra
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    Hi,
    using only string slices, you can probably do something like the
    following (if I underestand the specification correctly, i.e. to swap
    the two columns under the given condition).
    An alternative is to swap the indices directly using list.
    Also a regular expression replace with re.sub might be viable
    (probably the shortest one)...
    
    hth,
      vbr
    
    ######################################
    
    scale = """          1         2         3         4         5         6
    012345678901234567890123456789012345678901234567890123456789012345"""
    data_line = "ATOM      1  W     W     1       0.690  35.960  33.300  1.00  0.00"
    
    if data_line [19] == 'W':
        output_line = data_line [0:17]+data_line [19]+data_line
    [18]+data_line [17]+data_line [20:]
    # alternatively
        ch_19, ch_17 = data_line [19], data_line [17]
        data_lst = list(data_line)
        data_lst[17] = ch_19
        data_lst[19] = ch_17
        output_line_2 = "".join(data_lst)
        print output_line_2 == output_line
    
    else:
        output_line = data_line
    
    print scale
    print data_line
    print scale
    print output_line
    print "=" * 66
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 17:33:50 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Wed, 25 Nov 2009 22:33:50 +0000
    Subject: confused with os.fork()
    In-Reply-To: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    References: <7fc44f39-c6f8-4283-bb64-88d8f30f1d01@m16g2000yqc.googlegroups.com>
    Message-ID: <4B0DB0CE.4030007@mrabarnett.plus.com>
    
    Sandy wrote:
    > Hi all,
    > I am a little bit confused about os.fork().
    > Say I have the following code.
    > 
    > import os
    > a = ['a','b','c','d','e']
    > 
    > for i in xrange(len(a)):
    >     pid = os.fork()
    >     if not pid:
    >         print a[i]
    >         os._exit(0)
    > 
    >>From most of the tuts and examples I saw online, I expect it to print
    > a,b,c,d,e.
    > Sometimes (very rare) it prints something like this:
    > ab
    > c
    > d
    > e
    > I thought there is no way a parent process can enter the 'if'.
    > Can anyone explain this behaviour? Is it the case where parent is
    > forking a child even before the previous child is printing? In that
    > case is there a way to prevent that? I can use os.wait(), but I don't
    > want to wait till the child is finished, just don't want to mix the
    > child processes, that's it.
    > 
    The parent isn't entering the 'if' statement. os.fork() simply forks the
    process and then both the parent and the child processes continue.
    
    All of the child processes run independently and there's no guarantee as
    to the order in which they'll print, and there's nothing to stop the
    printouts from being mixed together (you would need to protect the
    'print' with a mutex to do that).
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 18:32:58 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 15:32:58 -0800 (PST)
    Subject: Cookie name and expiration
    Message-ID: 
    
    Hi,
    
    I'm testing the Cookie module's MarshalCookie in mod_python on my
    localhost environment. Everything looks ok and cookie set, get and
    update operations work well. But I'm not sure about the cookie name
    could be set by Cookie module. I mean the name of cookie file saved in
    the Temporary Internet Files directory of Internet Explorer. Consider
    that I run the script as http://localhost:8080/myScripts/myScript
    When I look at the Temporary Internet Files dir, not like other
    cookies came from normal websites, the cookie file was saved as
    "myScript/" and the cookie address is shown as http://localhost:8080/myScripts/
    I don't know this is normal behaviour of the browser or there is an
    option to set the name of cookie file.
    
    I mentioned the expiration in the subject but maybe it's not related
    to expiration. For example if I run directly http://localhost:8080/myScripts/myScript2
    after a day and look for the temporary internet directory again, I see
    a second cookie named "myScript2/" and the first cookie (myScript/)
    still exists there. But the first cookie seems no longer valid for
    this domain although I set the expire range for 30 days.
    
    Do I miss something about cookies concept and behaviour of browsers?
    Could anyone please clarify?
    
    Thanks and regards,
    Kutlu
    
    
    From skippy.hammond at gmail.com  Wed Nov 25 18:43:59 2009
    From: skippy.hammond at gmail.com (Mark Hammond)
    Date: Thu, 26 Nov 2009 10:43:59 +1100
    Subject: reading windows event logs
    In-Reply-To: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    References: <60f0493c-8437-4cab-8375-3b023c5b37ee@p35g2000yqh.googlegroups.com>
    Message-ID: <4B0DC13F.1060408@gmail.com>
    
    On 26/11/2009 7:22 AM, EW wrote:
    > Hi All,
    >       I'm looking for some guidance on a better way to read eventlogs
    > from windows servers.  I've written a handy little app that relies on
    > WMI to pull the logs an in all my testing it worked great.  When I
    > deployed it, however, WMI choked on servers with a lot of logs.  I've
    > tried pulling the logs using much smaller VB scripts as well and they
    > still failed, so I'm pretty sure I'm facing a WMI problem and not a
    > python or system resources problem.  So I couldn't effectively get
    > logs off of domain controllers for example or file servers that had
    > auditing turned on.  Sadly those are exactly the types of servers
    > whose logs are most interesting.
    >
    >       So I'm looking for suggestions on a way to grab that data without
    > using WMI for remote machines.  I know MS has C libraries for this but
    > I haven't touched C for 10 years so I'm hoping there's a python
    > equivalent out there somewhere.  Any advice would be appreciated.
    
    Look for the win32evtlog and win32evtlogutil modules which come with 
    pywin32 (http://sf.net/projects/pywin32)
    
    Cheers,
    
    Mark
    
    
    From naveen.garg at gmail.com  Wed Nov 25 19:12:09 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 16:12:09 -0800 (PST)
    Subject: embed python dynamically
    Message-ID: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    
    How do you embed the python dll file distributed with the automatic
    installable python distribution on windows?
    Is it possible to dynamically load the python dll from running c
    program and start up a python interpreter ?
    Do you have to compile python from source to be able to embed python?
    
    
    
    From nick.mellor.groups at pobox.com  Wed Nov 25 19:24:57 2009
    From: nick.mellor.groups at pobox.com (Nick Mellor)
    Date: Wed, 25 Nov 2009 16:24:57 -0800 (PST)
    Subject: High-performance Python websites
    Message-ID: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    
    Hi all,
    
    I'm contemplating setting up a Python-powered website for the tourist
    industry, which will involve a web service, a good deal of XML
    processing, and a Django-powered front-end. If the project works, it
    could get a lot of traffic. I'm sure it can be done, but I'm looking
    to find out more about how existing high-volume Python sites have
    managed their workload. Can anyone give me examples of high-volume
    Python-powered websites, if possible with some idea of their
    architecture?
    
    Many thanks,
    
    Nick
    
    
    From andrethehunter at gmail.com  Wed Nov 25 19:32:36 2009
    From: andrethehunter at gmail.com (=?ISO-8859-1?Q?Andr=E9?=)
    Date: Wed, 25 Nov 2009 16:32:36 -0800 (PST)
    Subject: Python 3.1 cx_Oracle 5.0.2 "ImportError: DLL load failed: The 
    	specified module could not be found."
    References: <1e071bb5-3d28-4cc2-9541-83c08a474164@v15g2000prn.googlegroups.com>
    	
    Message-ID: 
    
    On Nov 19, 6:57?pm, Neil Hodgson 
    wrote:
    > Andr?:
    >
    > > Apparently the error is caused by cx_Oracle not being able to find the
    > > Oracle client DLLs (oci.dll and others). The client home path and the
    > > client home path bin directory are in the PATH System Variable and
    > > oci.dll is there.
    >
    > ? ?Open the cx_Oracle extension with Dependency Walker
    > (http://www.dependencywalker.com/) to get a better idea about what the
    > problem is in more detail.
    >
    > ? ?Neil
    
    Thanks Neil. I used Dependency Walker and discovered cx_Oracle was
    looking for python30.dll. I seems to be a known issue with Python 3.1
    http://bugs.python.org/issue4091. I'm now used Python 2.6.4 and the
    corresponding cx_Oracle version with no problems.
    
    Thanks for the help
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 19:33:31 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 16:33:31 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    Message-ID: 
    
    Hi,
    
    Managing load of high volume of visitors is a common issue for all
    kind of web technologies. I mean this is not the python issue. This
    issue is mostly about server level designs. You need to supply load
    balancing for both web servers and databases to make your web site
    able to respond to several concurrent visitors. Of course a good
    programmed website is a key performance issue but for your mention I
    would also suggest considering how many hardwares, how many
    webservers, how many database cluster and which database server should
    be used or will be used in the future..
    
    Regards,
    Kutlu
    
    On Nov 26, 2:24?am, Nick Mellor  wrote:
    > Hi all,
    >
    > I'm contemplating setting up a Python-powered website for the tourist
    > industry, which will involve a web service, a good deal of XML
    > processing, and a Django-powered front-end. If the project works, it
    > could get a lot of traffic. I'm sure it can be done, but I'm looking
    > to find out more about how existing high-volume Python sites have
    > managed their workload. Can anyone give me examples of high-volume
    > Python-powered websites, if possible with some idea of their
    > architecture?
    >
    > Many thanks,
    >
    > Nick
    
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 19:45:27 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 16:45:27 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	
    Message-ID: 
    
    If you need an example one is in front of you and you are using it
    now. Google uses python at their thousands of servers. But as you see
    Google gains this performance from the power of hundreds of thousands
    servers. The main idea behind the Google search engine was indexing
    the whole web through hundreds of servers. So you can imagine where
    Google's power comes from..
    
    Regards
    
    
    On Nov 26, 2:33?am, ShoqulKutlu  wrote:
    > Hi,
    >
    > Managing load of high volume of visitors is a common issue for all
    > kind of web technologies. I mean this is not the python issue. This
    > issue is mostly about server level designs. You need to supply load
    > balancing for both web servers and databases to make your web site
    > able to respond to several concurrent visitors. Of course a good
    > programmed website is a key performance issue but for your mention I
    > would also suggest considering how many hardwares, how many
    > webservers, how many database cluster and which database server should
    > be used or will be used in the future..
    >
    > Regards,
    > Kutlu
    >
    > On Nov 26, 2:24?am, Nick Mellor  wrote:
    >
    >
    >
    > > Hi all,
    >
    > > I'm contemplating setting up a Python-powered website for the tourist
    > > industry, which will involve a web service, a good deal of XML
    > > processing, and a Django-powered front-end. If the project works, it
    > > could get a lot of traffic. I'm sure it can be done, but I'm looking
    > > to find out more about how existing high-volume Python sites have
    > > managed their workload. Can anyone give me examples of high-volume
    > > Python-powered websites, if possible with some idea of their
    > > architecture?
    >
    > > Many thanks,
    >
    > > Nick- Hide quoted text -
    >
    > - Show quoted text -
    
    
    
    From n00m at narod.ru  Wed Nov 25 19:56:07 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 16:56:07 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	
    Message-ID: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    
    > Or just raise an exception in __init__(),..
    
    Then we are forced to handle this exception outside of class code.
    It's Ok. Never mind.
    --------------------
    
    Next thing.
    I can't understand why we can get __name__, but not __dict__,
    on the module level?
    
    
    print __name__
    print __dict__
    
    
    >>> ===================================== RESTART ====
    >>>
    __main__
    
    Traceback (most recent call last):
      File "D:\Python25\zewrt.py", line 19, in 
        print __dict__
    NameError: name '__dict__' is not defined
    
    
    
    From naveen.garg at gmail.com  Wed Nov 25 19:58:50 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 16:58:50 -0800 (PST)
    Subject: embed installed python dynamically
    References: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    Message-ID: <12592aad-d6a4-4d18-b8ea-46521fae03ec@p8g2000yqb.googlegroups.com>
    
    ok, it was almost intuitive.
    just made a simple visual c express dll project
    included python26\include and python26\libs in the project settings
    the debug version has issues, but the release compiles without a
    problem.
    here is the source:
    http://github.com/tinku99/embedpython
    
    
    From tjreedy at udel.edu  Wed Nov 25 20:09:25 2009
    From: tjreedy at udel.edu (Terry Reedy)
    Date: Wed, 25 Nov 2009 20:09:25 -0500
    Subject: Can "self" crush itself?
    In-Reply-To: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    References: 	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    		
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    Message-ID: 
    
    n00m wrote:
    >> Or just raise an exception in __init__(),..
    > 
    > Then we are forced to handle this exception outside of class code.
    > It's Ok. Never mind.
    > --------------------
    > 
    > Next thing.
    > I can't understand why we can get __name__, but not __dict__,
    > on the module level?
    > 
    > 
    > print __name__
    > print __dict__
    
    If the global namespace contained itself, as a dict, there would be an 
    infinite loop.
    
    
    
    From keith at nekotaku.com  Wed Nov 25 20:30:19 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 17:30:19 -0800 (PST)
    Subject: jython and java application
    Message-ID: 
    
    Hi there,
    
    Apologies if this is on the wrong group, this is a jython question.
    Please redirect me to the correct group if this is in error.
    
    I have a java application that takes no arguements. When I run it, it
    spits out output, and finishes.
    
    I am trying to run this java application from jython 2.5.1, JRE6.
    
    I have made simple "Hello World" java classes be callable from a
    simple jython script, yet I am stumbling on the java main construct in
    the application.
    
    print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    args error (expected 1, got 0) as the definition in the java
    application is:
    
    public static void main(String[] args)
    
    The jython code is as follows:
    import krbtest
    
    # was messing with this to pass a java formatted string but to no
    avail
    
    from java.lang import String
    
    print krbtest.SimpleHistoricTutorial().main()
    
    #####
    
    Any advice greatly appreciated! Especially with how to call "main()"
    with arguments from jython.
    
    Apologies in advance again if this is the wrong group.
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 20:54:23 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 17:54:23 -0800 (PST)
    Subject: jython and java application
    References: 
    Message-ID: <1dffc77c-8930-4949-9ce4-d05f5d991c7c@s15g2000yqs.googlegroups.com>
    
    I don't know if it's right place but normally main method requires an
    args even it is not needed to supply from commandline. Maybe this is a
    jython runtime error and requires at least an empty argument. You
    could try to pass and empty string array like ['']. I'm not using
    jython please use your own notation.
    
    Regards,
    Kutlu
    
    On Nov 26, 3:30?am, KB  wrote:
    > Hi there,
    >
    > Apologies if this is on the wrong group, this is a jython question.
    > Please redirect me to the correct group if this is in error.
    >
    > I have a java application that takes no arguements. When I run it, it
    > spits out output, and finishes.
    >
    > I am trying to run this java application from jython 2.5.1, JRE6.
    >
    > I have made simple "Hello World" java classes be callable from a
    > simple jython script, yet I am stumbling on the java main construct in
    > the application.
    >
    > print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    > args error (expected 1, got 0) as the definition in the java
    > application is:
    >
    > public static void main(String[] args)
    >
    > The jython code is as follows:
    > import krbtest
    >
    > # was messing with this to pass a java formatted string but to no
    > avail
    >
    > from java.lang import String
    >
    > print krbtest.SimpleHistoricTutorial().main()
    >
    > #####
    >
    > Any advice greatly appreciated! Especially with how to call "main()"
    > with arguments from jython.
    >
    > Apologies in advance again if this is the wrong group.
    
    
    
    From python at mrabarnett.plus.com  Wed Nov 25 20:54:43 2009
    From: python at mrabarnett.plus.com (MRAB)
    Date: Thu, 26 Nov 2009 01:54:43 +0000
    Subject: jython and java application
    In-Reply-To: 
    References: 
    Message-ID: <4B0DDFE3.1040204@mrabarnett.plus.com>
    
    KB wrote:
    > Hi there,
    > 
    > Apologies if this is on the wrong group, this is a jython question.
    > Please redirect me to the correct group if this is in error.
    > 
    > I have a java application that takes no arguements. When I run it, it
    > spits out output, and finishes.
    > 
    > I am trying to run this java application from jython 2.5.1, JRE6.
    > 
    > I have made simple "Hello World" java classes be callable from a
    > simple jython script, yet I am stumbling on the java main construct in
    > the application.
    > 
    > print krbtest.SimpleHistoricTutorial().main() obviously gives me an
    > args error (expected 1, got 0) as the definition in the java
    > application is:
    > 
    > public static void main(String[] args)
    > 
    > The jython code is as follows:
    > import krbtest
    > 
    > # was messing with this to pass a java formatted string but to no
    > avail
    > 
    > from java.lang import String
    > 
    > print krbtest.SimpleHistoricTutorial().main()
    > 
    > #####
    > 
    > Any advice greatly appreciated! Especially with how to call "main()"
    > with arguments from jython.
    > 
    > Apologies in advance again if this is the wrong group.
    
    I don't know jython, but from the look of it I'd say that you need to
    give main() some kind of argument, such as a string or an empty list.
    (If you pass an empty jython list to a Java method that's expecting an
    array of String, will the Java method receive a zero-length array of
    String?).
    
    
    From naveen.garg at gmail.com  Wed Nov 25 20:57:10 2009
    From: naveen.garg at gmail.com (naveen)
    Date: Wed, 25 Nov 2009 17:57:10 -0800 (PST)
    Subject: embed installed python dynamically
    References: <66061036-cb51-495f-9999-3e0a09aac0aa@m38g2000yqd.googlegroups.com>
    	<12592aad-d6a4-4d18-b8ea-46521fae03ec@p8g2000yqb.googlegroups.com>
    Message-ID: <78043e65-a3c8-4da7-a484-47eacc821b20@j14g2000yqm.googlegroups.com>
    
    ok, its even easier than that.
    With autohotkey:
    
    pythondll := DllCall("LoadLibrary", "str", "c:\windows
    \system32\python26.dll")
    init := DllCall("c:\windows\system32\python26.dll\Py_Initialize"
    , "Cdecl")
    msgbox python initalized
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "import sys", "Cdecl")
    msgbox will exit using python code
    call := DllCall("c:\windows\system32\python26.dll\PyRun_SimpleString"
    , "str", "sys.exit(0)", "Cdecl")
    init := DllCall("c:\windows\system32\python26.dll\Py_Finalize"
    , "Cdecl")
    msgbox % never called
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 21:06:24 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 02:06:24 GMT
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 20:09:25 -0500, Terry Reedy wrote:
    
    > n00m wrote:
    >>> Or just raise an exception in __init__(),..
    >> 
    >> Then we are forced to handle this exception outside of class code. It's
    >> Ok. Never mind.
    >> --------------------
    >> 
    >> Next thing.
    >> I can't understand why we can get __name__, but not __dict__, on the
    >> module level?
    >> 
    >> 
    >> print __name__
    >> print __dict__
    > 
    > If the global namespace contained itself, as a dict, there would be an
    > infinite loop.
    
    
    Why would that be a problem?  Any time you do this:
    
    >>> g = globals()
    
    
    you create such a recursive reference:
    
    >>> globals()['g']['g']['g']['g'] is globals() is g
    True
    
    
    Yes, there's a tiny bit extra work needed when bootstrapping the 
    processes, and when exiting, but I don't see why it's a big deal. Whether 
    it's necessary or useful is another story.
    
    
    
    -- 
    Steven
    
    
    From FearsomeDragonfly at gmail.com  Wed Nov 25 21:35:06 2009
    From: FearsomeDragonfly at gmail.com (The Music Guy)
    Date: Wed, 25 Nov 2009 20:35:06 -0600
    Subject: Feature request: String-inferred names
    Message-ID: 
    
    Hello all,
    
    I just posted to my blog about a feature that I'd like to see added to
    Python. Before I go through the trouble of learning how to write a PEP or
    how to extend the Python interpreter, I want to know what people in the
    community have to say about it.
    
    http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    As far as I know, a feature like this does not appear in any existing PEPs.
    (If it does I would appreciate it if someone could tell me what PEP it is.)
    
    Please give and comments you may have, but I request that you be
    constructive if you must criticize...thank you!
    
    TMG
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From christian.grise at gmail.com  Wed Nov 25 21:39:03 2009
    From: christian.grise at gmail.com (Christian Grise)
    Date: Wed, 25 Nov 2009 21:39:03 -0500
    Subject: Help with error on self.show
    Message-ID: 
    
    Hi,
    
    I am getting an error when I try to run some code my friend gave me. Here is
    the error:
    
    Warning (from warnings module):
      File "C:\Documents and Settings\GriseC\Desktop\Widget Base\applet.py",
    line 145
        self.show()
    GtkWarning: ../../../../gtk+/gdk/win32/gdkwindow-win32.c:1089: SetWindowLong
    failed: Not enough storage is available to process this command.
    
    If anyone knows what this means, any info would be greatly appreciated.
    
    Thanks,
    Christian
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From n00m at narod.ru  Wed Nov 25 21:39:09 2009
    From: n00m at narod.ru (n00m)
    Date: Wed, 25 Nov 2009 18:39:09 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	 
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com> 
    	
    	
    Message-ID: 
    
    
    aaah... globals()...
    Then why "self" not in globals()?
    
    class Moo:
        cnt = 0
        def __init__(self, x):
            self.__class__.cnt += 1
            if self.__class__.cnt < 3:
                self.x = x
            else:
                print id(self)
                for item in globals().items():
                    print item
    
    f = Moo(1)
    g = Moo(2)
    h = Moo(3)
    
    
    >>> ===================================== RESTART ====
    >>>
    13407336
    ('g', <__main__.Moo instance at 0x00CC9260>)
    ('f', <__main__.Moo instance at 0x00CC9440>)
    ('__builtins__', )
    ('Moo', )
    ('__name__', '__main__')
    ('__doc__', None)
    >>>
    
    
    From musicguy at alphaios.net  Wed Nov 25 21:44:36 2009
    From: musicguy at alphaios.net (The Music Guy)
    Date: Wed, 25 Nov 2009 20:44:36 -0600
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 
    Message-ID: 
    
    I just posted to my blog about a feature that I'd like to see added to
    Python. Before I go through the trouble of learning how to write a PEP or
    how to extend the Python interpreter, I want to know what people in the
    community have to say about it.
    
    http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    As far as I know, a feature like this does not appear in any existing PEPs.
    (If it does I would appreciate it if someone could tell me what PEP it
    is.)Please give and comments you may have, but I request that you be
    constructive if you must criticize...thank you!
    
    TMG
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From keith at nekotaku.com  Wed Nov 25 21:49:15 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 18:49:15 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    Message-ID: 
    
    
    Hmmm, for some reason my follow up post didn't make it.
    
    Modified jython script to:
    
    # Eclipse package name for java application
    import krbtest
    
    import java.lang as lang
    from java.lang import String
    from jarray import array
    
    myargs=array([],String)
    
    krbtest.SimpleHistoricTutorial().main(myargs)
    ****
    
    Now I get:
    
    Traceback (most recent call last):
      File "test.py", line 15, in 
        krbtest.SimpleHistoricTutorial().main(myargs)
    	at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)
    
    	at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
    22)
    
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    
    	at java.lang.reflect.Method.invoke(Unknown Source)
    
    
    java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
    bloomberglp/blpapi/Session
    
    
    I would post the java app but its quite large, but the main defn:
    
    	public static void main(String[] args) throws Exception
    	{
    		SimpleHistoricTutorial example = new SimpleHistoricTutorial();
    		example.run();
    	}
    
    
    Is pretty vanilla. I have tried making the run() a public method and
    call it, all to no avail.
    
    Note, the Java app works fine standalone, I just need to call it from
    jython.
    
    Again, any help appreciated.
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:20:44 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:20:44 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    Message-ID: <300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com>
    
    Hi,
    
    I don't know how do you call the java library from within your jython
    application it gives java.lang.NoClassDefFoundError
    This looks like you referenced jar or whatever else from your jython
    application which also needs a class com/bloomberglp/blpapi/Session
    in another library file. It might run while running standalone because
    the dependent libraries exists where it looks for. For your jython
    application you need to make krbtest referenced to the dependent
    libraries. It seems you application took a copy of krbtest and other
    libraries not available to krbtest there. I hope it helps.
    
    Regards,
    Kutlu
    
    
    
    On Nov 26, 4:49?am, KB  wrote:
    > Hmmm, for some reason my follow up post didn't make it.
    >
    > Modified jython script to:
    >
    > # Eclipse package name for java application
    > import krbtest
    >
    > import java.lang as lang
    > from java.lang import String
    > from jarray import array
    >
    > myargs=array([],String)
    >
    > krbtest.SimpleHistoricTutorial().main(myargs)
    > ****
    >
    > Now I get:
    >
    > Traceback (most recent call last):
    > ? File "test.py", line 15, in 
    > ? ? krbtest.SimpleHistoricTutorial().main(myargs)
    > ? ? ? ? at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)
    >
    > ? ? ? ? at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
    > 22)
    >
    > ? ? ? ? at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >
    > ? ? ? ? at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    >
    > ? ? ? ? at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    >
    > ? ? ? ? at java.lang.reflect.Method.invoke(Unknown Source)
    >
    > java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
    > bloomberglp/blpapi/Session
    >
    > I would post the java app but its quite large, but the main defn:
    >
    > ? ? ? ? public static void main(String[] args) throws Exception
    > ? ? ? ? {
    > ? ? ? ? ? ? ? ? SimpleHistoricTutorial example = new SimpleHistoricTutorial();
    > ? ? ? ? ? ? ? ? example.run();
    > ? ? ? ? }
    >
    > Is pretty vanilla. I have tried making the run() a public method and
    > call it, all to no avail.
    >
    > Note, the Java app works fine standalone, I just need to call it from
    > jython.
    >
    > Again, any help appreciated.
    
    
    
    From keith at nekotaku.com  Wed Nov 25 22:33:02 2009
    From: keith at nekotaku.com (KB)
    Date: Wed, 25 Nov 2009 19:33:02 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    	<300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com>
    Message-ID: <708eac8e-c0c0-4ff4-adcd-a8b7742fb9b5@b25g2000prb.googlegroups.com>
    
    Kutlu,
    
    I already have a first born, else I would name her after you.
    
    You are brilliant. That's what it was. Kudos.
    
    For future ref for fellow boneheads like me, in Eclipse, under Project
    properties, Jython Class Path, Add External JAR...
    
    Thanks a million!
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 22:33:05 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 03:33:05 GMT
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    	
    	
    Message-ID: 
    
    On Wed, 25 Nov 2009 18:39:09 -0800, n00m wrote:
    
    > aaah... globals()...
    > Then why "self" not in globals()?
    > 
    > class Moo:
    >     cnt = 0
    >     def __init__(self, x):
    >         self.__class__.cnt += 1
    
    
    Because it isn't a global, it's a local -- it is defined inside a class. 
    Inside functions and classes, names you create are local, not global, 
    unless you declare them global.
    
    
    
    
    -- 
    Steven
    
    
    From mwilson at the-wire.com  Wed Nov 25 22:36:06 2009
    From: mwilson at the-wire.com (Mel)
    Date: Wed, 25 Nov 2009 22:36:06 -0500
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	
    	
    	
    Message-ID: 
    
    n00m wrote:
    
    > 
    > aaah... globals()...
    > Then why "self" not in globals()?
    > 
    > class Moo:
    >     cnt = 0
    >     def __init__(self, x):
    >         self.__class__.cnt += 1
    >         if self.__class__.cnt < 3:
    >             self.x = x
    >         else:
    >             print id(self)
    >             for item in globals().items():
    >                 print item
    > 
    > f = Moo(1)
    > g = Moo(2)
    > h = Moo(3)
    
    Because self is not in globals().
    
    It's defined as a local symbol in Moo.__init__ , supplied to that function 
    as the first parameter.
    
    	Mel.
    
    
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:40:01 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:40:01 -0800 (PST)
    Subject: jython and java application
    References: 
    	
    	
    	<300d2a75-6143-4df7-abd7-597afb5f590d@c34g2000yqn.googlegroups.com> 
    	<708eac8e-c0c0-4ff4-adcd-a8b7742fb9b5@b25g2000prb.googlegroups.com>
    Message-ID: <1360eb33-2a3d-4a30-a40f-53704690c678@j14g2000yqm.googlegroups.com>
    
    Welcome a million :)
    
    On Nov 26, 5:33?am, KB  wrote:
    > Kutlu,
    >
    > I already have a first born, else I would name her after you.
    >
    > You are brilliant. That's what it was. Kudos.
    >
    > For future ref for fellow boneheads like me, in Eclipse, under Project
    > properties, Jython Class Path, Add External JAR...
    >
    > Thanks a million!
    
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 22:45:19 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 03:45:19 GMT
    Subject: How do I correctly download Wikipedia pages?
    Message-ID: 
    
    I'm trying to scrape a Wikipedia page from Python. Following instructions 
    here:
    
    http://en.wikipedia.org/wiki/Wikipedia:Database_download
    http://en.wikipedia.org/wiki/Special:Export
    
    I use the URL "http://en.wikipedia.org/wiki/Special:Export/Train" instead 
    of just "http://en.wikipedia.org/wiki/Train". But instead of getting the 
    page I expect, and can see in my browser, I get an error page:
    
    
    >>> import urllib
    >>> url = "http://en.wikipedia.org/wiki/Special:Export/Train"
    >>> print urllib.urlopen(url).read()
    ...
    Our servers are currently experiencing a technical problem. This is 
    probably temporary and should be fixed soon
    ...
    
    
    (Output is obviously truncated for your sanity and mine.)
    
    
    Is there a trick to downloading from Wikipedia with urllib?
    
    
    
    -- 
    Steven
    
    
    From kursat.kutlu at gmail.com  Wed Nov 25 22:58:57 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 19:58:57 -0800 (PST)
    Subject: How do I correctly download Wikipedia pages?
    References: 
    Message-ID: <6f8913f0-9b93-4ae5-979c-012057f5aff4@v30g2000yqm.googlegroups.com>
    
    Hi,
    
    Try not to be caught if you send multiple requests :)
    
    Have a look at here: http://wolfprojects.altervista.org/changeua.php
    
    Regards
    Kutlu
    
    On Nov 26, 5:45?am, Steven D'Aprano
     wrote:
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    > here:
    >
    > http://en.wikipedia.org/wiki/Wikipedia:Database_downloadhttp://en.wikipedia.org/wiki/Special:Export
    >
    > I use the URL "http://en.wikipedia.org/wiki/Special:Export/Train" instead
    > of just "http://en.wikipedia.org/wiki/Train". But instead of getting the
    > page I expect, and can see in my browser, I get an error page:
    >
    > >>> import urllib
    > >>> url = "http://en.wikipedia.org/wiki/Special:Export/Train"
    > >>> print urllib.urlopen(url).read()
    >
    > ...
    > Our servers are currently experiencing a technical problem. This is
    > probably temporary and should be fixed soon
    > ...
    >
    > (Output is obviously truncated for your sanity and mine.)
    >
    > Is there a trick to downloading from Wikipedia with urllib?
    >
    > --
    > Steven
    
    
    
    From apt.shansen at gmail.com  Wed Nov 25 23:04:00 2009
    From: apt.shansen at gmail.com (Stephen Hansen)
    Date: Wed, 25 Nov 2009 20:04:00 -0800
    Subject: How do I correctly download Wikipedia pages?
    In-Reply-To: 
    References: 
    Message-ID: <7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    
    2009/11/25 Steven D'Aprano 
    
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    > here:
    >
    >
    Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?
    
    Its not just via urllib, but I've scraped several MediaWiki-based sites with
    the software successfully.
    
    --S
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From taskinoor.hasan at csebuet.org  Wed Nov 25 23:37:39 2009
    From: taskinoor.hasan at csebuet.org (Taskinoor Hasan)
    Date: Thu, 26 Nov 2009 10:37:39 +0600
    Subject: How do I correctly download Wikipedia pages?
    In-Reply-To: <7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    References: 
    	<7a9c25c20911252004w5c4bde4ble900f84ecf9bd8ba@mail.gmail.com>
    Message-ID: <79153a2e0911252037h172a3723yd00e5d5f0edb8bf3@mail.gmail.com>
    
    I fetched a different problem. Whenever I tried to fetch any page from
    wikipedia, I received 403. Then I found that wikipedia don't accept the
    default user-agent (might be python-urllib2.x or something like this). After
    setting my own user-agent, it worked fine. You can try this if you receive
    403.
    
    On Thu, Nov 26, 2009 at 10:04 AM, Stephen Hansen wrote:
    
    >
    >
    > 2009/11/25 Steven D'Aprano 
    >
    > I'm trying to scrape a Wikipedia page from Python. Following instructions
    >> here:
    >>
    >>
    > Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?
    >
    > Its not just via urllib, but I've scraped several MediaWiki-based sites
    > with the software successfully.
    >
    > --S
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From clp2 at rebertia.com  Wed Nov 25 23:49:36 2009
    From: clp2 at rebertia.com (Chris Rebert)
    Date: Wed, 25 Nov 2009 20:49:36 -0800
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 
    Message-ID: <50697b2c0911252049n2ccbee1fhdcba9ef56fee1718@mail.gmail.com>
    
    On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
     wrote:
    > Hello all,
    >
    > I just posted to my blog about a feature that I'd like to see added to
    > Python. Before I go through the trouble of learning how to write a PEP or
    > how to extend the Python interpreter, I want to know what people in the
    > community have to say about it.
    >
    > http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    >
    > As far as I know, a feature like this does not appear in any existing PEPs.
    > (If it does I would appreciate it if someone could tell me what PEP it is.)
    >
    > Please give and comments you may have, but I request that you be
    > constructive if you must criticize...thank you!
    
    Ugly, Perlish, and as you even admit, entirely unnecessary.
    And you'd need to wait at least a year anyway:
    http://www.python.org/dev/peps/pep-3003/
    
    Cheers,
    Chris
    --
    http://blog.rebertia.com
    
    
    From steven at REMOVE.THIS.cybersource.com.au  Wed Nov 25 23:59:06 2009
    From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 04:59:06 GMT
    Subject: How do I correctly download Wikipedia pages?
    References: 
    	<6f8913f0-9b93-4ae5-979c-012057f5aff4@v30g2000yqm.googlegroups.com>
    Message-ID: 
    
    On Wed, 25 Nov 2009 19:58:57 -0800, ShoqulKutlu wrote:
    
    > Hi,
    > 
    > Try not to be caught if you send multiple requests :)
    > 
    > Have a look at here: http://wolfprojects.altervista.org/changeua.php
    
    Thanks, that seems to work perfectly.
    
    
    -- 
    Steven
    
    
    From nick.mellor.groups at pobox.com  Thu Nov 26 00:21:25 2009
    From: nick.mellor.groups at pobox.com (Nick Mellor)
    Date: Wed, 25 Nov 2009 21:21:25 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	
    Message-ID: <06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com>
    
    Thanks Kutlu,
    
    I wasn't aware that Google used Python for running their Google groups
    servers. Can you confirm that? The only place
    I've seen Google explicitly use Python on their web front end is in
    the Google Ads tests.
    
    I am impressed by the responsiveness of lawrence.com, ljworld.com and
    others on the Django home page (http://www.djangoproject.com/)
    
    They seem to do a great job of loading large, complex pages using
    Django (stacked on Python, stacked on bytecode, stacked on C.)
    Shows it can be done.
    
    Nick
    
    
    From themusicguy123 at gmail.com  Thu Nov 26 00:45:45 2009
    From: themusicguy123 at gmail.com (Brad)
    Date: Wed, 25 Nov 2009 21:45:45 -0800 (PST)
    Subject: Feature request: String-inferred names
    References:  
    	
    Message-ID: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    
    On Nov 25, 10:49?pm, Chris Rebert  wrote:
    > On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    >
    >  wrote:
    > > Hello all,
    >
    > > I just posted to my blog about a feature that I'd like to see added to
    > > Python. Before I go through the trouble of learning how to write a PEP or
    > > how to extend the Python interpreter, I want to know what people in the
    > > community have to say about it.
    >
    > >http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...
    >
    > > As far as I know, a feature like this does not appear in any existing PEPs.
    > > (If it does I would appreciate it if someone could tell me what PEP it is.)
    >
    > > Please give and comments you may have, but I request that you be
    > > constructive if you must criticize...thank you!
    >
    > Ugly, Perlish, and as you even admit, entirely unnecessary.
    > And you'd need to wait at least a year anyway:http://www.python.org/dev/peps/pep-3003/
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com
    
    Like I said, lots of things in Python are "unnecessary," but that
    doesn't make them "useless," and it certainly doesn't mean they
    shouldn't exist. My proposed feature is not useless; I think it would
    make a lot of code easier.
    
    As for it being ugly...well, that's really a matter of opinion and
    experience. How ugly it looks to you will be a product of how well you
    think it can be used, and how well you use it yourself. When I first
    looked at decorators, I thought they were not only ugly but confusing.
    Now that I understand them, however, I hardly consider them "ugly,"
    and see them as a shining example of Python's abilities. (By the way,
    decorators are another example of a feature that is "entirely
    unnecessary," but still very useful.)
    
    As for the wait, that's to be expected. I'm willing to wait.
    
    
    From musicguy at alphaios.net  Thu Nov 26 00:59:02 2009
    From: musicguy at alphaios.net (The Music Guy)
    Date: Wed, 25 Nov 2009 23:59:02 -0600
    Subject: Feature request: String-inferred names
    In-Reply-To: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    Message-ID: 
    
    P.S., my apologies for sending replies with different email addresses. This
    is an unintentional technical issue and I am currently trying to get it
    fixed.
    
    On Wed, Nov 25, 2009 at 11:45 PM, Brad  wrote:
    
    > On Nov 25, 10:49 pm, Chris Rebert  wrote:
    > > On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    > >
    > >  wrote:
    > > > Hello all,
    > >
    > > > I just posted to my blog about a feature that I'd like to see added to
    > > > Python. Before I go through the trouble of learning how to write a PEP
    > or
    > > > how to extend the Python interpreter, I want to know what people in the
    > > > community have to say about it.
    > >
    > > >http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor.
    > ..
    > >
    > > > As far as I know, a feature like this does not appear in any existing
    > PEPs.
    > > > (If it does I would appreciate it if someone could tell me what PEP it
    > is.)
    > >
    > > > Please give and comments you may have, but I request that you be
    > > > constructive if you must criticize...thank you!
    > >
    > > Ugly, Perlish, and as you even admit, entirely unnecessary.
    > > And you'd need to wait at least a year anyway:
    > http://www.python.org/dev/peps/pep-3003/
    > >
    > > Cheers,
    > > Chris
    > > --http://blog.rebertia.com
    >
    > Like I said, lots of things in Python are "unnecessary," but that
    > doesn't make them "useless," and it certainly doesn't mean they
    > shouldn't exist. My proposed feature is not useless; I think it would
    > make a lot of code easier.
    >
    > As for it being ugly...well, that's really a matter of opinion and
    > experience. How ugly it looks to you will be a product of how well you
    > think it can be used, and how well you use it yourself. When I first
    > looked at decorators, I thought they were not only ugly but confusing.
    > Now that I understand them, however, I hardly consider them "ugly,"
    > and see them as a shining example of Python's abilities. (By the way,
    > decorators are another example of a feature that is "entirely
    > unnecessary," but still very useful.)
    >
    > As for the wait, that's to be expected. I'm willing to wait.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From kursat.kutlu at gmail.com  Thu Nov 26 00:59:22 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 21:59:22 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	 
    	<06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com>
    Message-ID: <610e1147-532d-42b8-92bc-75c11c4e6e79@v25g2000yqk.googlegroups.com>
    
    Hi Nick,
    
    Sorry about my concern on Google. It caused a confusion about Google
    groups. I didn't mean explicitly where Google uses python, I mentioned
    just Google uses Python. A Google officer told that they run Python on
    thousands of their servers at an interview. Due to this claim I wanted
    to say it for you.
    Actualy of course it can be done and even it will not be worse than
    any other frameworks, and I bet can be better than Java and ASP.NET if
    configured and programmed well. I really encourage you to use
    mod_python for any project. Mod_python and mod_wsgi made it very
    powerful at web side. As I said in my previous message a web
    application's responsiveness is dependent to several issues. A good
    web framework, server speed, database design etc.. In this case you
    want to use django, which as I know build for mod_python and can be
    configured to run on a mod_wsgi web server. Consider that you will
    have one million members on your site. That traffic simply needs
    several clustered web servers and clustered databases. This means you
    supply a load balancing. So concurrent user sessions will be shared on
    different web servers. You can do your best with such a clustered
    system with such a powerful language. Really don't worry about that.
    
    Regards,
    Kutlu
    
    On Nov 26, 7:21?am, Nick Mellor  wrote:
    > Thanks Kutlu,
    >
    > I wasn't aware that Google used Python for running their Google groups
    > servers. Can you confirm that? The only place
    > I've seen Google explicitly use Python on their web front end is in
    > the Google Ads tests.
    >
    > I am impressed by the responsiveness of lawrence.com, ljworld.com and
    > others on the Django home page (http://www.djangoproject.com/)
    >
    > They seem to do a great job of loading large, complex pages using
    > Django (stacked on Python, stacked on bytecode, stacked on C.)
    > Shows it can be done.
    >
    > Nick
    
    
    
    From kursat.kutlu at gmail.com  Thu Nov 26 01:09:30 2009
    From: kursat.kutlu at gmail.com (ShoqulKutlu)
    Date: Wed, 25 Nov 2009 22:09:30 -0800 (PST)
    Subject: High-performance Python websites
    References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com>
    	 
    	 
    	<06d5bca6-8bf6-4f14-96bc-2f5c32b27a40@15g2000prz.googlegroups.com> 
    	<610e1147-532d-42b8-92bc-75c11c4e6e79@v25g2000yqk.googlegroups.com>
    Message-ID: 
    
    Hi again,
    
    I also want to say something about creating a better web application.
    If I were you I wouldn't use any web framework like django or other.
    If you want to create a commercial project and want to manage all
    modules of the application yourself I suggest you to create your own
    framework. I don't mean create a Django like framework. Determine your
    needs, modules, services and build your own modules. Use other
    independent open source modules for any specific issues. To make a
    successful project requires your own business logic. And you can do
    this with your own algorithm. Don't avoid collecting other modules for
    templating, xml parsing, DB connectivity issues. But build your own
    framework with these and your own modules..
    
    Regards,
    Kutlu
    
    
    From gagsl-py2 at yahoo.com.ar  Thu Nov 26 01:30:38 2009
    From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina)
    Date: Thu, 26 Nov 2009 03:30:38 -0300
    Subject: Feature request: String-inferred names
    References: 
    Message-ID: 
    
    En Wed, 25 Nov 2009 23:35:06 -0300, The Music Guy  
     escribi?:
    
    > I just posted to my blog about a feature that I'd like to see added to
    > Python. Before I go through the trouble of learning how to write a PEP or
    > how to extend the Python interpreter, I want to know what people in the
    > community have to say about it.
    >
    > http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    >
    > As far as I know, a feature like this does not appear in any existing  
    > PEPs.
    > (If it does I would appreciate it if someone could tell me what PEP it  
    > is.)
    
    Already suggested, and rejected; see PEP 363:  
    http://www.python.org/dev/peps/pep-0363/ and the python-dev discussion.
    
    -- 
    Gabriel Genellina
    
    
    
    From lie.1296 at gmail.com  Thu Nov 26 01:44:17 2009
    From: lie.1296 at gmail.com (Lie Ryan)
    Date: Thu, 26 Nov 2009 17:44:17 +1100
    Subject: Feature request: String-inferred names
    In-Reply-To: <9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    Message-ID: <4b0e241f@dnews.tpgi.com.au>
    
    Brad wrote:
    > On Nov 25, 10:49 pm, Chris Rebert  wrote:
    >> On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
    >>
    >>  wrote:
    >>> Hello all,
    >>> I just posted to my blog about a feature that I'd like to see added to
    >>> Python. Before I go through the trouble of learning how to write a PEP or
    >>> how to extend the Python interpreter, I want to know what people in the
    >>> community have to say about it.
    >>> http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...
    >>> As far as I know, a feature like this does not appear in any existing PEPs.
    >>> (If it does I would appreciate it if someone could tell me what PEP it is.)
    >>> Please give and comments you may have, but I request that you be
    >>> constructive if you must criticize...thank you!
    >> Ugly, Perlish, and as you even admit, entirely unnecessary.
    >> And you'd need to wait at least a year anyway:http://www.python.org/dev/peps/pep-3003/
    >>
    >> Cheers,
    >> Chris
    >> --http://blog.rebertia.com
    > 
    > Like I said, lots of things in Python are "unnecessary," but that
    > doesn't make them "useless," and it certainly doesn't mean they
    > shouldn't exist. My proposed feature is not useless; I think it would
    > make a lot of code easier.
    
    How is it easier than using dictionary with string as keys? setattr, 
    getattr, and delattr are already sugar for accessing instance.__dict__.
    
    You make a comparison with decorators; even if it's unnecessary it does 
    eliminate a DRY case (don't repeat yourself):
    def foo(self): pass
    foo = property(foo)
    
    there you repeat foo three times unnecessarily, instead of:
    @property
    def foo(self): pass
    
    people already bashed decorator syntax because it is ungoogleable; a 
    non-python programmer reading a python code can't google "python @" to 
    find out that it's a decorator. $ has very similar problem; and we don't 
    want to add more of this wart.
    
    You also make with iterators and generators. Iterator and generator is 
    an implication of the core design of python; because python chose not to 
    have a for-loop (python's "for-loop" is actually a for-each-loop). 
    Without the iterator protocol, it is not possible to make an iterable 
    class and people would have to use "for x in range(len(foo)):" every so 
    often. Iterator protocol also makes it possible to have infinite 
    iterable (e.g. for x in primegenerator(): produces prime numbers 
    indefinitely).
    
    A list comprehension is space saver; it saves a lot of lines for the 
    very common operation:
    
    a = []
    for x in orig:
         if test(x):
             a.append(transform(x))
    
    into one concise line:
    a = [transform(x) for x in orig if test(x)]
    
    Also a generator comprehension can be passed around without being evaluated.
    
    As you see, these "unnecessary features" does have significant benefits 
    to it. Decorators reduced DRY, iterators/generators eliminates the need 
    of range-len for-loop, list comprehension is huge space saver.
    
    The proposed syntax only saves a few character, does not eliminate any 
    DRY, is ungoogleable, and looks confusing to me. Is there any 
    significant benefit from it?
    
    
    From greg.ewing at canterbury.ac.nz  Thu Nov 26 02:04:39 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Thu, 26 Nov 2009 20:04:39 +1300
    Subject: Can "self" crush itself?
    In-Reply-To: <7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    Message-ID: <7n6nkoF3ki1sfU1@mid.individual.net>
    
    n00m wrote:
    
    > I can't understand why we can get __name__, but not __dict__,
    > on the module level?
    
    For much the same reason that you can see your own
    feet but (unless you look in a mirror) you can't
    see your own eyes.
    
    -- 
    Greg
    
    
    From greg.ewing at canterbury.ac.nz  Thu Nov 26 02:28:06 2009
    From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
    Date: Thu, 26 Nov 2009 20:28:06 +1300
    Subject: Feature request: String-inferred names
    In-Reply-To: 
    References: 	
    	
    Message-ID: <7n6p0qF3krjueU1@mid.individual.net>
    
    > On Wed, 25 Nov 2009 20:44:36 -0600, The Music Guy
    >  declaimed the following in
    > gmane.comp.python.general:
    > 
    >>I just posted to my blog about a feature that I'd like to see added to
    >>Python.
    >>
    >>http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html
    
    I don't think getattr and setattr are used anywhere near
    frequently enough to justify special syntax.
    
    To warrant having its own synax, a feature needs to be
    used *all the time*. If you find yourself using getattr
    and setattr that much, it's probably a symptom that
    you're abusing namespaces for things that would be
    better done using dictionaries.
    
    (A frequent question asked by newcomers from certain
    other kinds of languages is something like "How do I
    assign to a variable whose name is in another variable?"
    The answer is almost always "Don't do that, use a
    dictionary.")
    
    -- 
    Greg
    
    
    From n00m at narod.ru  Thu Nov 26 03:43:47 2009
    From: n00m at narod.ru (n00m)
    Date: Thu, 26 Nov 2009 00:43:47 -0800 (PST)
    Subject: Can "self" crush itself?
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com> 
    	 
    	
    	 
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com> 
    	<7n6nkoF3ki1sfU1@mid.individual.net>
    Message-ID: <5a01852a-8f8c-45b9-83f9-b250bc5ed328@b2g2000yqi.googlegroups.com>
    
    Ok ok
    Of course, it's a local name; -- just my silly slip.
    And seems it belongs to no dict[]...
    Just an internal volatile elf
    
    
    From bruno.42.desthuilliers at websiteburo.invalid  Thu Nov 26 03:58:09 2009
    From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers)
    Date: Thu, 26 Nov 2009 09:58:09 +0100
    Subject: Feature request: String-inferred names
    In-Reply-To: <4b0e241f@dnews.tpgi.com.au>
    References: 
    	
    	<9619a127-6da3-4109-86fb-29b6a915889e@m38g2000yqd.googlegroups.com>
    	<4b0e241f@dnews.tpgi.com.au>
    Message-ID: <4b0e431b$0$30358$426a34cc@news.free.fr>
    
    Lie Ryan a ?crit :
    
    (snip)
     > setattr,  getattr, and delattr are already sugar for accessing 
    instance.__dict__.
    
    They are actually much more than that - else descriptors and inheritance 
    wouldn't work.
    
    
    
    From calidion at gmail.com  Thu Nov 26 04:21:39 2009
    From: calidion at gmail.com (=?Big5?B?p/Wl1aFBpnKkQKTp?=)
    Date: Thu, 26 Nov 2009 01:21:39 -0800 (PST)
    Subject: a question about python
    Message-ID: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com>
    
    hi,
    i have a question on python programming.
    
    let file a.py has a class named a,
      class a():
        __G__ = "1111"
    
    in file b.py i need to insert an attribute __C__ to class a
    
    it would be as if class a defined in file a.py like this:
      class a():
        __G__ = "1111"
        __C__ = "22222"
    
    how this be done in python without inheritance?
    
    
    From steve at REMOVE-THIS-cybersource.com.au  Thu Nov 26 04:45:51 2009
    From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano)
    Date: 26 Nov 2009 09:45:51 GMT
    Subject: a question about python
    References: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com>
    Message-ID: <031e3c24$0$1335$c3e8da3@news.astraweb.com>
    
    On Thu, 26 Nov 2009 01:21:39 -0800, ?????? wrote:
    
    > hi,
    > i have a question on python programming.
    > 
    > let file a.py has a class named a,
    >   class a():
    >     __G__ = "1111"
    
    
    Methods with double leading and trailing underscores are reserved for 
    Python's special use. You should find a different naming convention.
    
    
    > in file b.py i need to insert an attribute __C__ to class a
    > 
    > it would be as if class a defined in file a.py like this:
    >   class a():
    >     __G__ = "1111"
    >     __C__ = "22222"
    > 
    > how this be done in python without inheritance?
    
    
    import a
    a.a.__C__ = "22222"
    
    
    
    -- 
    Steven
    
    
    From calidion at gmail.com  Thu Nov 26 04:57:45 2009
    From: calidion at gmail.com (=?UTF-8?B?5p2O55m977yM5a2X5LiA5pel?=)
    Date: Thu, 26 Nov 2009 01:57:45 -0800 (PST)
    Subject: a question about python
    References: <3ba67aab-16ac-4cbd-ab83-051780fd8412@2g2000prl.googlegroups.com> 
    	<031e3c24$0$1335$c3e8da3@news.astraweb.com>
    Message-ID: <0b54b155-9b59-4093-8334-73478c9a030e@g1g2000pra.googlegroups.com>
    
    thanks.
    
    On Nov 26, 5:45?pm, Steven D'Aprano  wrote:
    > On Thu, 26 Nov 2009 01:21:39 -0800, ?????? wrote:
    > > hi,
    > > i have a question on python programming.
    >
    > > let file a.py has a class named a,
    > > ? class a():
    > > ? ? __G__ = "1111"
    >
    > Methods with double leading and trailing underscores are reserved for
    > Python's special use. You should find a different naming convention.
    >
    > > in file b.py i need to insert an attribute __C__ to class a
    >
    > > it would be as if class a defined in file a.py like this:
    > > ? class a():
    > > ? ? __G__ = "1111"
    > > ? ? __C__ = "22222"
    >
    > > how this be done in python without inheritance?
    >
    > import a
    > a.a.__C__ = "22222"
    >
    > --
    > Steven
    
    
    
    From f.guerrieri at gmail.com  Thu Nov 26 05:06:44 2009
    From: f.guerrieri at gmail.com (Francesco Guerrieri)
    Date: Thu, 26 Nov 2009 11:06:44 +0100
    Subject: Can "self" crush itself?
    In-Reply-To: <7n6nkoF3ki1sfU1@mid.individual.net>
    References: 
    	<57054947-23bb-435a-b066-14464b0daa75@c34g2000yqn.googlegroups.com>
    	
    	
    	
    	<7ace3de0-4588-4b7d-9848-d97298717597@z41g2000yqz.googlegroups.com>
    	<7n6nkoF3ki1sfU1@mid.individual.net>
    Message-ID: <79b79e730911260206r4a5041fp4cada7a3e9200ac1@mail.gmail.com>
    
    On Thu, Nov 26, 2009 at 8:04 AM, Gregory Ewing
    wrote:
    
    > n00m wrote:
    >
    >  I can't understand why we can get __name__, but not __dict__,
    >> on the module level?
    >>
    >
    > For much the same reason that you can see your own
    > feet but (unless you look in a mirror) you can't
    > see your own eyes.
    >
    
    
    +1 QOTW
    
    Francesco
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: 
    
    From niklasro at gmail.com  Thu Nov 26 05:38:22 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:38:22 -0800 (PST)
    Subject: IDE+hg
    References: 
    	<75ef83cb-b928-4bf4-b20a-11484a3fdc45@2g2000prl.googlegroups.com>
    Message-ID: 
    
    On Nov 25, 7:28?am, alex23  wrote:
    > NiklasRTZ  wrote:
    > > no py IDE I found has easy hg access.
    >
    > ActiveState's Komodo IDE has support for CVS, Perforce, subversion,
    > bazaar, git and mercurial.
    
    unavailable via synaptic ubuntu karmic repos, presuming its
    commercially bound like wing. Boa constructor, PIDA, Eric, drPython
    are 4 where all should be configurable for obvious reasons + I like
    it.
    thanks for anyway prompt reply my friend
    
    
    From niklasro at gmail.com  Thu Nov 26 05:40:13 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:40:13 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    Message-ID: <1eebb434-f1b5-400f-8256-bb179b3a53f5@f16g2000yqm.googlegroups.com>
    
    On Nov 24, 5:47?pm, "G?nther Dietrich" 
    wrote:
    > NiklasRTZ  wrote:
    > >Since no py IDE I found has easy hg access.
    >
    > Obviously, you didn't try Eclipse with PyDev ()
    > and Mercurial Eclipse ()
    > plugins.
    > This combination is also available stuffed into one package as
    > 'EasyEclipse for Python' ().
    >
    > Both, pure Eclipse with plugins installed by hand, and EasyEclipse, are
    > very convenient for python development.
    >
    > Best regards,
    >
    > G?nther
    
    thank you G?nther for the most common recommendation I get (Eclipse)
    sure for C(++) eclipse works too and Netbeans just that pure python
    obviously closer to this min requirement + fed up with java generally
    here for decades moving all to python
    
    
    From niklasro at gmail.com  Thu Nov 26 05:41:10 2009
    From: niklasro at gmail.com (NiklasRTZ)
    Date: Thu, 26 Nov 2009 02:41:10 -0800 (PST)
    Subject: IDE+hg
    References: 
    	
    	 
    	
    	
    Message-ID: 
    
    On Nov 24, 4:09?pm, rustom  wrote:
    > On Nov 24, 8:13?pm, Richard Riley  wrote:
    >
    >
    >
    > > Gerhard H?ring  writes:
    > > > Rhodri James wrote:
    > > >> On Mon, 23 Nov 2009 19:20:27 -0000, NiklasRTZ  wrote:
    >
    > > >>> Dear experts,
    > > >>> Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
    > > >>> Mercurial support not found i.e. buttons to clone, commit and push to
    > > >>> repositories to define dev env dvcs, editor and deployment all in 1.
    >
    > > >> I don't really understand this urge to cram everything into a single
    > > >> program, since that inevitably leads to compromises that will
    > > >> compromise
    >
    > > Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
    > > merely programmed to hook into the external tools
    >
    > > >> just how much of Mercurial's useful and interesting functionality you
    > > >> can get at. ?Still, if you really must, Emacs (and presumably vim) seems
    > > >> to be capable of working with most source control systems.
    >
    > > > I prefer the commandline tools, too.
    >
    > > > FWIW, Eclipse supports Mercurial through
    > > >http://www.vectrace.com/mercurialeclipse/
    >
    > > > -- Gerhard
    >
    > > Why would you prefer the command line tools in a shell when the same
    > > tools can be used in a way which makes navigating the output so much
    > > easier? It strikes me as a kind of intransigence. it's a common
    > > misconception that IDEs use their own tools all the time. They
    > > don't. They integrate the very same tools. e.g Why the hell would I drop
    > > to a command line to diff a file with a back version in GIT when I can
    > > do the same in the buffer in emacs with a single hot key? Why would I
    > > pipe the output of compile into a file then open that file when a single
    > > hot key can fire off the SAME compiler and then list the errors in an
    > > emacs buffer and another hot key can take me directly to the source
    > > lines in question? Living in the past has its mements, but really.
    >
    > > e.g I have pylint working live in python buffers. Big time
    > > saver. Similar with C.
    >
    > I sometimes think that the amount of time I spend tweaking emacs to
    > save my time is more than the time I spend on anything else :-)
    >
    > But more seriously:
    > I tried to use emacs with git recently -- it was a sorry experience.
    > The git.el that comes with git is broken (on windows)
    > vc was too old for git like systems
    > dvc is a joke (its supposedly generic for all Distributed Version
    > Systems -- but everything is couched in terms of tla.
    > TLA! For heavens sake!
    > magit would not run on windows and to use egghttp://github.com/bogolisk/egg
    > I must read magit docs.
    > Finally I decided to stay with what Ive used for the last 25 years --
    > the shell
    
    git is easier via commandline than hg. hg wants gears for simple thing
    ie. hg commit -m wants spec note, too long to type each commit.
    
    
    From paul at boddie.org.uk  Thu Nov 26 06:12:18 2009
    From: paul at boddie.org.uk (Paul Boddie)
    Date: Thu, 26 Nov 2009 03:12:18 -0800 (PST)
    Subject: pointless musings on performance
    References: 
    	<4B0BD0E4.8030707@mrabarnett.plus.com> 
    	
    	 
    	<4fd48f26-cbed-4f55-b846-8a91fdd535f2@e20g2000vbb.googlegroups.com> 
    	
    	<24d0c830-946d-4ef4-8fb3-7f0a8c0b4e4b@g26g2000yqe.googlegroups.com>
    	
    Message-ID: <98899688-7712-4f18-b498-d838e91b909c@x31g2000yqx.googlegroups.com>
    
    On 25 Nov, 13:11, Antoine Pitrou  wrote:
    >
    > When you say "executing each kind of bytecode instruction", are you
    > talking about the overhead of bytecode dispatch and operand gathering, or
    > the total cost including doing the useful work?
    
    Strip away any overhead (dispatch, operand gathering) and just measure
    the cumulative time spent doing the actual work for each kind of
    instruction, then calculate the average "cost" by dividing by the
    frequency of each instruction type. So, for a whole program you'd get
    a table of results like this:
    
    LOAD_CONST   
    Left Center Right
    Lists and divs work the same way, and note that attributes are not a problem. From this... div class="spinnable" ul li id="item1" One li id="item2" Two ...you get this:
    • One
    • Two
    You can still use raw HTML tags where appropriate (such as when converting legacy markup to the new style). From this... tr td Hello World!
    ...you get this:
    Hello World!
    And here is the code: import re def convert_text(in_body): ''' Convert HAML-like markup to HTML. Allow raw HTML to fall through. ''' indenter = Indenter() for prefix, line, kind in get_lines(in_body): if kind == 'branch' and '<' not in line: html_block_tag(prefix, line, indenter) else: indenter.add(prefix, line) return indenter.body() def html_block_tag(prefix, line, indenter): ''' Block tags have syntax like this and only apply to branches in indentation: table tr td class="foo" leaf #1 td leaf #2 ''' start_tag = '<%s>' % line end_tag = '' % line.split()[0] indenter.push(prefix, start_tag, end_tag) class Indenter: ''' Example usage: indenter = Indenter() indenter.push('', 'Start', 'End') indenter.push(' ', 'Foo', '/Foo') indenter.add (' ', 'bar') indenter.add (' ', 'yo') print indenter.body() ''' def __init__(self): self.stack = [] self.lines = [] def push(self, prefix, start, end): self.add(prefix, start) self.stack.append((prefix, end)) def add(self, prefix, line): if line: self.pop(prefix) self.insert(prefix, line) def insert(self, prefix, line): self.lines.append(prefix+line) def pop(self, prefix): while self.stack: start_prefix, end = self.stack[-1] if len(prefix) <= len(start_prefix): whitespace_lines = [] while self.lines and self.lines[-1] == '': whitespace_lines.append(self.lines.pop()) self.insert(start_prefix, end) self.lines += whitespace_lines self.stack.pop() else: return def body(self): self.pop('') return '\n'.join(self.lines) def get_lines(in_body): ''' Splits out lines from a file and identifies whether lines are branches, leafs, or blanks. The detection of branches could probably be done in a more elegant way than patching the last non-blank line, but it works. ''' lines = [] last_line = -1 for line in in_body.split('\n'): m = re.match('(\s*)(.*)', line) prefix, line = m.groups() if line: line = line.rstrip() if last_line >= 0: old_prefix, old_line, ignore = lines[last_line] if len(old_prefix) < len(prefix): lines[last_line] = (old_prefix, old_line, 'branch') last_line = len(lines) lines.append((prefix, line, 'leaf')) # leaf for now else: lines.append(('', '', 'blank')) return lines As I mention in the comment for get_lines(), I wonder if there are more elegant ways to deal with the indentation, both of the input and the output. From passionateforchrist at gmail.com Fri Nov 27 22:13:57 2009 From: passionateforchrist at gmail.com (P.F.C.) Date: Fri, 27 Nov 2009 22:13:57 -0500 Subject: Python C API, building a module Message-ID: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> Hello, I'm new to the mailing list but have been using python for a while. I am now attempting to embed the interpreter into a C application but am having an issue when building a module exposing my application's functions to python. I do not know if this is the right place to ask for help with it, if it isn't then please let me know where to go. the problem I'm having is with making a PyMethodDef array When I make the array like this it works: static PyMethodDef ge_methods[]={ {"test",ge_test,METH_NOARGS,"Test returns 123L"}, {NULL,NULL} }; but as soon as I try to build the array from constant variables like this: const int ge_test_args = METH_NOARGS; //The flag for this function const char* ge_test_doc = "Test\nwill print \"test\""; //The docstring static PyMethodDef ge_methods[]={ {"test",ge_test, ge_test_args, ge_test_doc}, //simply replacing the flag and the docstring with a constant variable {NULL,NULL} }; the compiler then gives the following errors: ./test1.c:74: error: initializer element is not constant ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) ./test1.c:74: error: initializer element is not constant ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) I'm using the gcc compiler This may well be because of my lack of understanding the C language but I was hoping someone could help me out, or at least point me in the right direction I also posted about this at http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 Thank you for any help -- Maranatha! --------------------------------- PFC aka Fezzik aka GAB -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Fri Nov 27 22:20:57 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 03:20:57 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: John Bokma wrote: > r0g wrote: > >> It seems gethostbyname asks the OS to resolve the address and the OS >> uses it's own timeout value ( 25 seconds ) rather than the one provided >> in setdefaulttimeout. 25 seconds of blocking is way too long for me, I >> want the response within 5 seconds or not at all but I can see no >> reasonable way to do this without messing with the OS which naturally I >> am loathe to do! > > use signal.alarm(time) to send SIGALRM to your process: > http://docs.python.org/library/signal.html#signal.alarm > See example at bottom. > > John Ahh so close. I set the alarm for 3 seconds and it raises the exception, but only after spending 25 seconds seemingly blocked in gethostbyname. Here's a snippet, just in case I'm doing it wrong!... def dns_timeout(a,b): raise Exception("DNS timeout") def send_one_ping(my_socket, dest_addr, ID): signal.signal(signal.SIGALRM, dns_timeout) signal.alarm(3) try: dest_addr = socket.gethostbyname(dest_addr) except Exception, exc: print "Exception caught:", exc signal.alarm(0) Oh well, even if it doesn't work in this case it's really useful to know about the signal module, I'd never stumbled across it til now, thanks! Roger. From python at mrabarnett.plus.com Fri Nov 27 22:25:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 03:25:15 +0000 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> Message-ID: <4B10981B.4070903@mrabarnett.plus.com> P.F.C. wrote: > Hello, I'm new to the mailing list but have been using python for a while. > > I am now attempting to embed the interpreter into a C application but am > having an issue when building a module exposing my application's > functions to python. > I do not know if this is the right place to ask for help with it, if it > isn't then please let me know where to go. > > the problem I'm having is with making a PyMethodDef array > When I make the array like this it works: > > static PyMethodDef ge_methods[]={ > {"test",ge_test,METH_NOARGS,"Test returns 123L"}, > {NULL,NULL} > }; > > but as soon as I try to build the array from constant variables like this: > > const int ge_test_args = METH_NOARGS; //The flag > for this function > const char* ge_test_doc = "Test\nwill print \"test\""; //The > docstring > static PyMethodDef ge_methods[]={ > {"test",ge_test, ge_test_args, ge_test_doc}, //simply > replacing the flag and the docstring with a constant variable > {NULL,NULL} > }; > > the compiler then gives the following errors: > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) > > I'm using the gcc compiler > > This may well be because of my lack of understanding the C language but > I was hoping someone could help me out, or at least point me in the > right direction > > I also posted about this at > http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 > > I think it's because C 'const' objects aren't true constants, but are more like read-only variables; you can initialise them in the declaration but not assign to them otherwise. Thus what you're actually trying to do is initialise from a variable, not a constant. From passionateforchrist at gmail.com Fri Nov 27 22:41:38 2009 From: passionateforchrist at gmail.com (P.F.C.) Date: Fri, 27 Nov 2009 22:41:38 -0500 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> <4B10981B.4070903@mrabarnett.plus.com> <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> Message-ID: <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> I see what your saying. Is there another way of declaring (at least) the docstring apart from the actual array?(it would get messy otherwise) I had also tried defining the variables as static but got the same result (I thought static meant in code memory instead of the heap...?) I am new to C so I may just be going about this all wrong... -- Maranatha! --------------------------------- PFC aka Fezzik aka GAB On Fri, Nov 27, 2009 at 10:25 PM, MRAB wrote: > P.F.C. wrote: > >> Hello, I'm new to the mailing list but have been using python for a while. >> >> I am now attempting to embed the interpreter into a C application but am >> having an issue when building a module exposing my application's functions >> to python. >> I do not know if this is the right place to ask for help with it, if it >> isn't then please let me know where to go. >> >> the problem I'm having is with making a PyMethodDef array >> When I make the array like this it works: >> >> static PyMethodDef ge_methods[]={ >> {"test",ge_test,METH_NOARGS,"Test returns 123L"}, >> {NULL,NULL} >> }; >> >> but as soon as I try to build the array from constant variables like this: >> >> const int ge_test_args = METH_NOARGS; //The flag for >> this function >> const char* ge_test_doc = "Test\nwill print \"test\""; //The >> docstring >> static PyMethodDef ge_methods[]={ >> {"test",ge_test, ge_test_args, ge_test_doc}, //simply >> replacing the flag and the docstring with a constant variable >> {NULL,NULL} >> }; >> >> the compiler then gives the following errors: >> ./test1.c:74: error: initializer element is not constant >> ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_flags?) >> ./test1.c:74: error: initializer element is not constant >> ./test1.c:74: error: (near initialization for ?ge_methods[0].ml_doc?) >> >> I'm using the gcc compiler >> >> This may well be because of my lack of understanding the C language but I >> was hoping someone could help me out, or at least point me in the right >> direction >> >> I also posted about this at >> http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 < >> http://talk.christiandevs.com/viewtopic.php?f=13&t=2521> >> >> I think it's because C 'const' objects aren't true constants, but are > more like read-only variables; you can initialise them in the > declaration but not assign to them otherwise. Thus what you're actually > trying to do is initialise from a variable, not a constant. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 84715175 at qq.com Fri Nov 27 22:41:48 2009 From: 84715175 at qq.com (84715175 at qq.com) Date: Fri, 27 Nov 2009 19:41:48 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> Message-ID: <380b0aa5-e651-43a4-8511-c20218b565c3@z4g2000prh.googlegroups.com> On 11?27?, ??4?54?, luca72 wrote: > hello i have a problem > > i have this > > str = 'D3' > and i need to trasform in 0xd3 type int and not type string how i can > do this? > if i do > hex(int(str,16) ) i obtain a string and this is not what i need. > > thanks Luca

    sport jersey sports jersey uggboot nike

    From 84715175 at qq.com Fri Nov 27 22:42:29 2009 From: 84715175 at qq.com (84715175 at qq.com) Date: Fri, 27 Nov 2009 19:42:29 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <87bpioxprk.fsf@benfinney.id.au> Message-ID: <56731260-f284-4ecd-9907-82cc75735882@b25g2000prb.googlegroups.com> On 11?27?, ??6?59?, Marco Mariani wrote: > Ben Finney wrote: > >> i'm using pyscard > > > I don't know what that is; can you give a link to what you're referring > > to? > > Simple story: he has seen the examples with hex literals and didn't know > what they were.

    sport jersey sports jersey uggboot nike

    From cindyqjm at gmail.com Fri Nov 27 22:43:26 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:43:26 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> Message-ID: <5c9bdb00-5ec9-47aa-a7af-ec775b8a69cb@h14g2000pri.googlegroups.com> On 11?27?, ??4?54?, luca72 wrote: > hello i have a problem > > i have this > > str = 'D3' > and i need to trasform in 0xd3 type int and not type string how i can > do this? > if i do > hex(int(str,16) ) i obtain a string and this is not what i need. > > thanks Luca http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Fri Nov 27 22:44:59 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:44:59 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> Message-ID: <383e151a-1f58-45e0-98ab-0b5bf34a563a@g22g2000prf.googlegroups.com> On 11?27?, ??5?35?, "84715... at qq.com" <84715... at qq.com> wrote: > On 11?27?, ??5?28?, luca72 wrote: > > > > > i'm using pyscard > > > and for send a command he need a list like this: > > > cmd = [0xdd,0xff, etc] > > > the problem is that i get a text > > like dd > > and i need to trasform it in 0xdd for the list and if i use hex i have > > a sting that is not what i need > > > Luca > > > On 27 Nov, 10:22, Ben Finney wrote: > > > > luca72 writes: > > > > str = 'D3' > > > > Be careful when choosing names. Here you have clobbered the existing > > > string type binding to the name ?str?. > > > > > and i need to trasform in 0xd3 type int and not type string how i can > > > > do this? > > > > You already have the answer; you used it in your example below. I can > > > only assume you're wanting something additional; what is that? > > > > > if i do hex(int(str,16) ) i obtain a string and this is not what i > > > > need. > > > > You either want it as an int, or you want it as a string. Which is it? > > > > ? ? >>> foo = 'D3' > > > ? ? >>> int(foo, 16) > > > ? ? 211 > > > ? ? >>> 0xD3 > > > ? ? 211 > > > ? ? >>> int(foo, 16) == 0xD3 > > > ? ? True > > > > -- > > > ?\ ? ? ? ? ? ??Human reason is snatching everything to itself, leaving | > > > ? `\ ? ? ? ? ? ? ? ? ? ? nothing for faith.? ?Saint Bernard, 1090?1153 | > > > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > > > Ben Finney- ??????? - > > > - ??????? - > >

    target="sport jersey">sport ? jersey > href="http://www.sport-jersey.net" target="sport > jersey">sports jersey ? title="ugg women" href="http://www.uggwomen.net" target="ugg > women">uggboot ? nike

    - ??????? - > > - ??????? - http://www.enjoyebay.com/ From cindyqjm at gmail.com Fri Nov 27 22:45:53 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:45:53 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <87bpioxprk.fsf@benfinney.id.au> Message-ID: <1f880f64-921e-48cd-95af-7ae1d3df0122@a10g2000pre.googlegroups.com> On 11?27?, ??6?59?, Marco Mariani wrote: > Ben Finney wrote: > >> i'm using pyscard > > > I don't know what that is; can you give a link to what you're referring > > to? > > Simple story: he has seen the examples with hex literals and didn't know > what they were. http://www.mbthome.net/ mbt shoes http://www.nike-airyeezy.com discount nike air yeezy From cindyqjm at gmail.com Fri Nov 27 22:46:47 2009 From: cindyqjm at gmail.com (jessica) Date: Fri, 27 Nov 2009 19:46:47 -0800 (PST) Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <380b0aa5-e651-43a4-8511-c20218b565c3@z4g2000prh.googlegroups.com> Message-ID: On 11?28?, ??11?41?, "84715... at qq.com" <84715... at qq.com> wrote: > On 11?27?, ??4?54?, luca72 wrote: > > > hello i have a problem > > > i have this > > > str = 'D3' > > and i need to trasform in 0xd3 type int and not type string how i can > > do this? > > if i do > > hex(int(str,16) ) i obtain a string and this is not what i need. > > > thanks Luca > >

    target="sport jersey">sport jersey > href="http://www.sport-jersey.net" target="sport > jersey">sports jersey title="ugg women" href="http://www.uggwomen.net" target="ugg > women">uggboot nike

    http://www.mbthome.net/ mbt shoes From python at mrabarnett.plus.com Fri Nov 27 22:58:13 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 03:58:13 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. In-Reply-To: References: Message-ID: <4B109FD5.6040500@mrabarnett.plus.com> r0g wrote: > Hi, > > I'm writing a reliability monitoring app but I've run into a problem. I > was hoping to keep it very simple and single threaded at first but > that's looking unlikely now! The crux of it is this... > > gethostbyname ignores setdefaulttimeout. > > It seems gethostbyname asks the OS to resolve the address and the OS > uses it's own timeout value ( 25 seconds ) rather than the one provided > in setdefaulttimeout. 25 seconds of blocking is way too long for me, I > want the response within 5 seconds or not at all but I can see no > reasonable way to do this without messing with the OS which naturally I > am loathe to do! > > The two ideas I've had so far are... > > Implement a cache. For this to work I'd need to avoid issuing > gethostbyname until the cached address fails. Of course it will fail a > little bit further down i the calling code when the app tries to use it > and I'd then need it to refresh the cache and try again. That seems very > kludgey to me :/ > > A pure python DNS lookup. This seems better but is an unknown quantity. > How big a job is it to use non-blocking sockets to write a DNS lookup > function with a customisable timeout? A few lines? A few hundred? I'd > only need to resolve v4 addresses for the foreseeable. > > Any comments on these strategies, or any suggestions of methods you > think might work better or be a lot easier to implement, warmly received. > How about something like this: def get_host_by_name(hostname, timeout): def proc(): try: q.put(socket.gethostbyname(hostname)) except (socket.gaierror, socket.timeout): pass q = Queue.Queue() t = threading.Thread(target=proc) t.daemon = True t.start() try: return q.get(True, timeout) except Queue.Empty: raise socket.timeout From fearsomedragonfly at gmail.com Fri Nov 27 23:02:31 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 20:02:31 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: <2569860a-797c-413e-a957-8d5f714fc5e8@v30g2000yqm.googlegroups.com> On Nov 26, 9:10?pm, "Gabriel Genellina" wrote: > En Thu, 26 Nov 2009 20:43:04 -0300, The Music Guy ? > escribi?: > > > Nonetheless, the fact remains that the feature I'm proposing closely > > resembles one that has already been rejected... Well, it's been a few > > years since then. Maybe its about time for another PEP to be proposed? > > You'll have to wait a few more years; in case you missed the previous ? > reference to PEP 3003 up in the thread, the language syntax is frozen by ? > now [1] > > [1]http://www.python.org/dev/peps/pep-3003/ > > -- > Gabriel Genellina That PEP seems to pretty clearly state that it applies only to the 3.x branch and not to the 2.x branch. Is there maybe a slim chance of getting my idea added to 2.7, or even 2.8? :D From sisson.j at gmail.com Fri Nov 27 23:05:30 2009 From: sisson.j at gmail.com (J Sisson) Date: Fri, 27 Nov 2009 22:05:30 -0600 Subject: Best strategy for overcoming excessive gethostbyname timeout. In-Reply-To: References: Message-ID: <4297a9020911272005q6c67c7edka3cc2b1f4a9a5d5f@mail.gmail.com> On Fri, Nov 27, 2009 at 9:20 PM, r0g wrote: > Ahh so close. I set the alarm for 3 seconds and it raises the exception, > but only after spending 25 seconds seemingly blocked in gethostbyname. > > Here's a snippet, just in case I'm doing it wrong!... > > If you're doing many lookups prior to connecting to the machines or otherwise processing the information, you can create a very simple thread class to perform just the lookup, store the threads in a list, and poll the threads in the list so you can deal with the ones that finish first before moving on to the remaining ones. You'll still have a 25 second wait for the last ones to finish, but you can get the majority of the work done earlier than you would with a single-thread program. -- Computers are like air conditioners... They quit working when you open Windows. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Fri Nov 27 23:08:10 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Fri, 27 Nov 2009 20:08:10 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> Message-ID: <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> Gred, thanks for your comments. On Nov 26, 7:49?pm, Gregory Ewing wrote: > > [...] Also, many of the uses of getattr in the std lib appear > to be of the 3-argument form, which your suggested syntax > doesn't cover. [...] Good point. After excluding those, only ~435 uses would work for my proposed syntax. Still seems fairly significant to me, though. Also, please keep in mind that I never suggested that the get*r functions should be removed from the language precisely because they DO work in ways that my proposed syntax does not, and that removing them would make a lot of existing code fail. For the purpose of the 3- argument form, I would still prefer using getattr or even a defaultdict depending on the task. (For the record, I disagree with the 2-argument form of Ben's proposed syntax; that's confusing and hard to read.) As for your code, I haven't seen it, so it would be hard for me to say exactly how the new syntax would come into play. What I can tell you, however, is that the parts of your code that would use it would probably be easier to read and change to anyone with a firm grasp of the proposed syntax. Quantity of code is definitely important, but I don't want to underwrite the importance of quality, either. Even if only 30 lines of code--rounding down--out of 40,000 would use it, those 40 lines would probably be easier to read and understand. (Off-handedly, you might also find that the availability of the new syntax makes new solutions to some task obvious which previously were not, so the number could rise.) The discussion of PEP 363 presented some good examples of what I'm talking about. Consider this code, which is a paraphrase of code that appeared in the discussion: setattr(obj, ("my_%s" % foo), getattr(obj, ("my_%s" % foo)) + 3) That could be written much more readably as: obj.$("my_%s" % foo) += 3 Or, if you don't like that exact syntax for it, why not any of these: obj.?("my_%s" % foo) += 3 obj.${"my_%s" % foo} += 3 obj.?{"my_%s" % foo} += 3 obj.<"my_%s" % foo> += 3 (and so on) Even if this sort of thing only needed to happen a few times in an entire project, the project as a whole could only benefit from it. My projects rely on a lot of metaclassing for the automatic generation of properties and methods, which saves tremendous amounts of coding. However, the code for the metaclasses is confusing because it relies heavily on the getattr and setattr functions for accessing not only the classes being created but also the instances of those classes. The code for the metaclasses themselves only constitute a small percentage of the overall code for the projects, but that doesn't mean the code doesn't need to be easy to read and understand. Dynamic attribute access via a syntactical construct would be very beneficial for me. Back to PEP 3003, I understand the odds of getting the feature in right now are slim. I get it. But that doesn't mean the idea of the feature is a bad one. There are other things that can be done in the mean time until the moratorium is lifted, like perfecting the syntax and implementation details, or whatever. --Brad Harms From himanshu.garg at gmail.com Fri Nov 27 23:15:44 2009 From: himanshu.garg at gmail.com (++imanshu) Date: Fri, 27 Nov 2009 20:15:44 -0800 (PST) Subject: How to Detect Use of Unassigned(Undefined) Variable(Function) References: <13b9e14f-b8f7-4cc4-90b3-c00087d595d1@b15g2000yqd.googlegroups.com> Message-ID: On Nov 27, 4:06?pm, Marco Mariani wrote: > Jon Clements wrote: > > pychecker returns "test.py:3: No global (o) found" for the above, and > > can be found athttp://pychecker.sourceforge.net/ > > > There's also pylint and another one whose name I can't remember... > > pyflakes. I use that one Thanks for the replies. Was looking for just these. Thank You, ++imanshu From python at mrabarnett.plus.com Fri Nov 27 23:17:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 04:17:17 +0000 Subject: Python C API, building a module In-Reply-To: <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> References: <384ec87c0911271913g33b606dcn42a17dfa4c0f05ff@mail.gmail.com> <4B10981B.4070903@mrabarnett.plus.com> <384ec87c0911271939x5843a276g9a59662a141c3cb6@mail.gmail.com> <384ec87c0911271941x2fd29ba7l67f34f357eed616a@mail.gmail.com> Message-ID: <4B10A44D.2050709@mrabarnett.plus.com> P.F.C. wrote: > I see what your saying. > > Is there another way of declaring (at least) the docstring apart from > the actual array?(it would get messy otherwise) > > I had also tried defining the variables as static but got the same > result (I thought static meant in code memory instead of the heap...?) > > I am new to C so I may just be going about this all wrong... > The standard way of providing documentation strings is with PyDoc_STRVAR: const int ge_test_args = METH_NOARGS; //The flag for this function PyDoc_STRVAR(ge_test_doc, "Test\nwill print \"test\""); //The docstring static PyMethodDef ge_methods[]={ {"test", NULL, 0, ge_test_doc}, //simply replacing the flag and the docstring with a constant variable {NULL,NULL} }; > > -- Maranatha! > --------------------------------- > PFC aka Fezzik aka GAB > > > On Fri, Nov 27, 2009 at 10:25 PM, MRAB > wrote: > > P.F.C. wrote: > > Hello, I'm new to the mailing list but have been using python > for a while. > > I am now attempting to embed the interpreter into a C > application but am having an issue when building a module > exposing my application's functions to python. > I do not know if this is the right place to ask for help with > it, if it isn't then please let me know where to go. > > the problem I'm having is with making a PyMethodDef array > When I make the array like this it works: > > static PyMethodDef ge_methods[]={ > {"test",ge_test,METH_NOARGS,"Test returns 123L"}, > {NULL,NULL} > }; > > but as soon as I try to build the array from constant variables > like this: > > const int ge_test_args = METH_NOARGS; > //The flag for this function > const char* ge_test_doc = "Test\nwill print \"test\""; > //The docstring > static PyMethodDef ge_methods[]={ > {"test",ge_test, ge_test_args, ge_test_doc}, > //simply replacing the flag and the docstring with a constant > variable > {NULL,NULL} > }; > > the compiler then gives the following errors: > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for > ?ge_methods[0].ml_flags?) > ./test1.c:74: error: initializer element is not constant > ./test1.c:74: error: (near initialization for > ?ge_methods[0].ml_doc?) > > I'm using the gcc compiler > > This may well be because of my lack of understanding the C > language but I was hoping someone could help me out, or at least > point me in the right direction > > I also posted about this at > http://talk.christiandevs.com/viewtopic.php?f=13&t=2521 > > > > > I think it's because C 'const' objects aren't true constants, but are > more like read-only variables; you can initialise them in the > declaration but not assign to them otherwise. Thus what you're actually > trying to do is initialise from a variable, not a constant. > From aioe.org at technicalbloke.com Fri Nov 27 23:20:45 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 04:20:45 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: Gabriel Genellina wrote: > En Fri, 27 Nov 2009 22:35:36 -0300, r0g > escribi?: > >> gethostbyname ignores setdefaulttimeout. >> >> How big a job is it to use non-blocking sockets to write a DNS lookup >> function with a customisable timeout? A few lines? A few hundred? I'd >> only need to resolve v4 addresses for the foreseeable. > > This guy reports good results using GNU adns to perform asynchronous > queries: > http://www.catonmat.net/blog/asynchronous-dns-resolution/ > > Also, look for pydns. Don't be afraid of its age; it always worked fine > for me. > Thanks Gabriel, that worked a treat when combined with John's SIGALARM solution :) For posterity here's the code... import signal, socket try: import DNS except: DNS = False def DNSResolve( s ): if DNS: DNS.ParseResolvConf() # Windows? r = DNS.DnsRequest(name=s,qtype='A') a = r.req() return a.answers[0]['data'] else: return socket.gethostbyname( s ) def dns_timeout(a,b): raise Exception("Oh Noes! a DNS lookup timeout!") def canIHasIP( domain_name, timeout=3 ): signal.signal(signal.SIGALRM, dns_timeout) signal.alarm( timeout ) try: ip = DNSResolve( domain_name ) except Exception, exc: print exc return False signal.alarm(0) return ip usage: canIHasIP( domain_name, timeout_in_seconds) i.e. canIHasIP("google.com",5) Thanks guys! :D Roger. From enkidu.com at com.cliffp.com Fri Nov 27 23:25:54 2009 From: enkidu.com at com.cliffp.com (Enkidu) Date: Sat, 28 Nov 2009 17:25:54 +1300 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <87ocmnv1gt.fsf@benfinney.id.au> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> Message-ID: <4b10a652$1@news2.actrix.gen.nz> Ben Finney wrote: > Enkidu writes: > >> Heh! Maybe a little sleep-deprived, but I didn't realise that the >> original post was cross-posted to comp.lang.python. If I'd purposely >> posted it to CLP it *would* have been a stupid troll. I did it by >> accident, and apologise for doing so. > > Oh, so trash-talking in *other* forums where you feel safe from being > caught is okay? ;-) > I take your point, but the other group in question is a 'local' group. Cheers, Cliff -- The Internet is interesting in that although the nicknames may change, the same old personalities show through. From ldo at geek-central.gen.new_zealand Fri Nov 27 23:44:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 28 Nov 2009 17:44:53 +1300 Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: In message <486869af-d89f-4261-b4c2- f45af5d3bb93 at e7g2000vbi.googlegroups.com>, r wrote: > I find the syntax far to[o] complicated than it should be. That?s because it was originally written for Java programmers. From rt8396 at gmail.com Sat Nov 28 00:33:51 2009 From: rt8396 at gmail.com (r) Date: Fri, 27 Nov 2009 21:33:51 -0800 (PST) Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: <93d1cd57-5dce-4cc8-915d-5e9c33f3fdda@s31g2000yqs.googlegroups.com> On Nov 27, 10:44?pm, Lawrence D'Oliveiro wrote: > In message <486869af-d89f-4261-b4c2- > > f45af5d3b... at e7g2000vbi.googlegroups.com>, r wrote: > > I find the syntax far to[o] complicated than it should be. > > That?s because it was originally written for Java programmers. Well that explains the high level of asininity alright! ;-) From david at bibliolabs.com Sat Nov 28 00:56:37 2009 From: david at bibliolabs.com (David Williams) Date: Fri, 27 Nov 2009 23:56:37 -0600 (CST) Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: <59374.68.58.172.242.1259387797.squirrel@www.bibliobazaar.com> You might want to take a look at this: http://www.ghrml.org/ David > Python has this really neat idea called indentation-based syntax, and > there are folks that have caught on to this idea in the HTML > community. > > AFAIK the most popular indentation-based solution for generating HTML > is a tool called HAML, which actually is written in Ruby. > > I have been poking around with the HAML concepts in Python, with the > specific goal of integrating with Django. But before releasing that, > I thought it would be useful to post code that distills the basic > concept with no assumptions about your target renderer. I hope it > also serves as a good example of what you can do in exactly 100 lines > of Python code. > > Here is what it does... > > You can use indentation syntax for HTML tags like table. > > From this... > > table > tr > td > Left > td > Center > td > Right > > ...you get this: > > > > > > > >
    > Left > > Center > > Right >
    > > Lists and divs work the same way, and note that attributes are not > a problem. > > From this... > > div class="spinnable" > ul > li id="item1" > One > li id="item2" > Two > > ...you get this: > >
    >
      >
    • > One >
    • >
    • > Two >
    • >
    >
    > > You can still use raw HTML tags where appropriate (such as when > converting > legacy markup to the new style). > > From this... > > > tr > td > Hello World! >
    > > ...you get this: > > > > > >
    > Hello World! >
    > > And here is the code: > > import re > > def convert_text(in_body): > ''' > Convert HAML-like markup to HTML. Allow raw HTML to > fall through. > ''' > indenter = Indenter() > for prefix, line, kind in get_lines(in_body): > if kind == 'branch' and '<' not in line: > html_block_tag(prefix, line, indenter) > else: > indenter.add(prefix, line) > return indenter.body() > > > def html_block_tag(prefix, line, indenter): > ''' > Block tags have syntax like this and only > apply to branches in indentation: > > table > tr > td class="foo" > leaf #1 > td > leaf #2 > ''' > start_tag = '<%s>' % line > end_tag = '' % line.split()[0] > indenter.push(prefix, start_tag, end_tag) > > > class Indenter: > ''' > Example usage: > > indenter = Indenter() > indenter.push('', 'Start', 'End') > indenter.push(' ', 'Foo', '/Foo') > indenter.add (' ', 'bar') > indenter.add (' ', 'yo') > print indenter.body() > ''' > def __init__(self): > self.stack = [] > self.lines = [] > > def push(self, prefix, start, end): > self.add(prefix, start) > self.stack.append((prefix, end)) > > def add(self, prefix, line): > if line: > self.pop(prefix) > self.insert(prefix, line) > > def insert(self, prefix, line): > self.lines.append(prefix+line) > > def pop(self, prefix): > while self.stack: > start_prefix, end = self.stack[-1] > if len(prefix) <= len(start_prefix): > whitespace_lines = [] > while self.lines and self.lines[-1] == '': > whitespace_lines.append(self.lines.pop()) > self.insert(start_prefix, end) > self.lines += whitespace_lines > self.stack.pop() > else: > return > > def body(self): > self.pop('') > return '\n'.join(self.lines) > > def get_lines(in_body): > ''' > Splits out lines from a file and identifies whether lines > are branches, leafs, or blanks. The detection of branches > could probably be done in a more elegant way than patching > the last non-blank line, but it works. > ''' > lines = [] > last_line = -1 > for line in in_body.split('\n'): > m = re.match('(\s*)(.*)', line) > prefix, line = m.groups() > if line: > line = line.rstrip() > if last_line >= 0: > old_prefix, old_line, ignore = lines[last_line] > if len(old_prefix) < len(prefix): > lines[last_line] = (old_prefix, old_line, > 'branch') > last_line = len(lines) > lines.append((prefix, line, 'leaf')) # leaf for now > else: > lines.append(('', '', 'blank')) > return lines > > As I mention in the comment for get_lines(), I wonder if there are > more elegant ways to deal with the indentation, both of the input and > the output. > > -- > http://mail.python.org/mailman/listinfo/python-list > From showell30 at yahoo.com Sat Nov 28 01:32:56 2009 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 27 Nov 2009 22:32:56 -0800 (PST) Subject: a 100-line indentation-based preprocessor for HTML References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> On Nov 27, 9:56?pm, "David Williams" wrote: > You might want to take a look at this: > > http://www.ghrml.org/ > Yep, it's not clear how actively they are maintaining that. The fact that it seems to target Genshi only might be limiting their audience, which is unfortunate. From moijes12 at gmail.com Sat Nov 28 02:09:06 2009 From: moijes12 at gmail.com (moijes12) Date: Fri, 27 Nov 2009 23:09:06 -0800 (PST) Subject: need clarification on -0 Message-ID: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Hi I know the value -0 is quite meaningless and makes little sense.But I was just fiddling.I am unable to figure out the below result >>> -0 and True 0 ----------> (Why is this 0 and not say True or False) >>> -0 and false 0 >>> -0 or True True Could someone please provide me some resources on how these operations take place.I'd wanna find it out myself Thanks moijes From subhakolkata1234 at gmail.com Sat Nov 28 02:20:17 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 23:20:17 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> On Nov 28, 5:35?am, Steven D'Aprano wrote: > On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > > Dear Group, > > > I have written a small and simple program like the following: > > > def alphabet1(n): > > ? ? file_open=open("/python26/alphabetlist1.txt","r") > > ? ? file_read=file_open.read() > > ? ? file_word=file_read.split() > > ? ? print file_word > > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > > splitting them into words. > > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > > following: > > > a A > > b B > > c C > > d D > > E e > > F f > > > Where, a/b/c/d/e/f are in ?lower case and A/B/C/D/E/F are in upper case > > which I can say as > > SHIFT+a > > SHIFT+b > > SHIFT+c > > SHIFT+d > > SHIFT+e > > SHIFT+f > > > Now, in the list or anywhere in the program if I want to write > > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > > may feel not only cut/copy/paste. > > > How would I represent them? > > This question is badly defined. What are your constraints? Is this meant > to be a human-readable program? If so, you need to stick to ASCII text > and probably want something like: > > a A CTRL-A ALT-A > b B CTRL-B ALT-B > ... > > but I'm not sure what the point of that would be. > > Normally, control-combinations generate control-characters. For example, > CTRL-M would normally generate a carriage-return character. Depending on > your needs, you can write this as any of the following: > > a description: CTRL-M > an escape sequence: \r > caret notation: ^M > the standard abbreviation: CR > the Unicode display glyph: ? > or an actual carriage-return character. > > Note that in ASCII control characters only have a standard definition for > the following: > > ctrl-@ > ctrl-A through ctrl-Z > ctrl-[ > ctrl-\ > ctrl-] > ctrl-^ > ctrl-_ > ctrl-? > > See here for more:http://en.wikipedia.org/wiki/Control_characters > > As for Alt-combinations, I don't think there is any standard for what > they are. I believe that they are operating system specific, and possibly > even program specific. > > -- > Steven- Hide quoted text - > > - Show quoted text - Dear Sir, I was writing a transliteration program from Bengali to English and vice versa. The program using Unicode chart is giving me perfect outputs in Bengali and vice versa with Bengali input -> English. I wanted to add some more power to the key board entry scheme, as I have developed few fonts also and now trying to work out a windows based word processor in Bengali. Thank you for your kind answer. It helped me lot. ALT portion I'll work out on my own. Sorry for a wrongly given problem statement. Wishing you a happy day ahead, Regards, Subhabrata. From subhakolkata1234 at gmail.com Sat Nov 28 02:30:00 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 27 Nov 2009 23:30:00 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> On Nov 28, 5:35?am, Steven D'Aprano wrote: > On Fri, 27 Nov 2009 12:41:42 -0800, joy99 wrote: > > Dear Group, > > > I have written a small and simple program like the following: > > > def alphabet1(n): > > ? ? file_open=open("/python26/alphabetlist1.txt","r") > > ? ? file_read=file_open.read() > > ? ? file_word=file_read.split() > > ? ? print file_word > > > Here, I am using a file ?alphabetlist1.txt? which I am reading and then > > splitting them into words. > > > In this file ?alphabetlist1.txt? I have arranged few alphabets like the > > following: > > > a A > > b B > > c C > > d D > > E e > > F f > > > Where, a/b/c/d/e/f are in ?lower case and A/B/C/D/E/F are in upper case > > which I can say as > > SHIFT+a > > SHIFT+b > > SHIFT+c > > SHIFT+d > > SHIFT+e > > SHIFT+f > > > Now, in the list or anywhere in the program if I want to write > > CTRL+a/b/c/d/e/f or ALT+a/b/c/d/e/f for which I may assign any value I > > may feel not only cut/copy/paste. > > > How would I represent them? > > This question is badly defined. What are your constraints? Is this meant > to be a human-readable program? If so, you need to stick to ASCII text > and probably want something like: > > a A CTRL-A ALT-A > b B CTRL-B ALT-B > ... > > but I'm not sure what the point of that would be. > > Normally, control-combinations generate control-characters. For example, > CTRL-M would normally generate a carriage-return character. Depending on > your needs, you can write this as any of the following: > > a description: CTRL-M > an escape sequence: \r > caret notation: ^M > the standard abbreviation: CR > the Unicode display glyph: ? > or an actual carriage-return character. > > Note that in ASCII control characters only have a standard definition for > the following: > > ctrl-@ > ctrl-A through ctrl-Z > ctrl-[ > ctrl-\ > ctrl-] > ctrl-^ > ctrl-_ > ctrl-? > > See here for more:http://en.wikipedia.org/wiki/Control_characters > > As for Alt-combinations, I don't think there is any standard for what > they are. I believe that they are operating system specific, and possibly > even program specific. > > -- > Steven- Hide quoted text - > > - Show quoted text - It seems the following site: http://knopok.net/symbol-codes/alt-codes is quite resourceful on Alt. Regards, Subhabrata. From aioe.org at technicalbloke.com Sat Nov 28 02:46:42 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sat, 28 Nov 2009 07:46:42 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > Gabriel Genellina wrote: >> En Fri, 27 Nov 2009 22:35:36 -0300, r0g >> escribi?: >> >>> gethostbyname ignores setdefaulttimeout. >>> >>> How big a job is it to use non-blocking sockets to write a DNS lookup >>> function with a customisable timeout? A few lines? A few hundred? I'd As usual, everything is working beautifully until I try to make it work with windows! Turns out signals.SIGALRM is Unix only and I want to run on both platforms so I have done as the docs suggested and tried to convert the code to use threading.Timer to trigger an exception if the DNS lookup is taking too long. It's behaviour seems quite odd. The exception is raised on schedule after a couple of seconds and appears in the terminal (despite me not printing it to the terminal!). There's then a pause of nearly 30 seconds before the try/except catches it and proceeds as normal. I can see no reason for a delay between the error being raised and caught, unless whatever it's trying to interrupt is blocking, in which case it shouldn't have been interrupted by the signal either no? So anyway my questions are... Why the error message and can it be suppressed? Why the 30 second delay, what's it doing during that time? Code... timeout_timer = threading.Timer(DNS_TIMEOUT, dns_timeout) timeout_timer.start() try: dest_addr = DNSResolve( dest_addr ) except Exception: print "Caught an exception, returning False" try: timeout_timer.cancel() except: None return False Other code as before. On the face of it it looks like it might be dwelling in the .req() method of the pydns library but it can get confusing quickly with threading so I'm far from sure. On top of that I'm not sure if my threads are dying and being cleared up properly. Each Exception I raise shows the Thread number getting higher e.g. "Exception in thread Thread-8:". Do I need to be doing anything to clear these up or does Python just use a monotonic counter for thread names? Is there a less messy way to use signals on both Unix and Windows? The docs seem to suggest they've kludged the signals module into a workable form most platforms but on XP I get 'module' object has no attribute 'SIGALRM' :( Roger. From max at alcyone.com Sat Nov 28 02:55:18 2009 From: max at alcyone.com (Erik Max Francis) Date: Fri, 27 Nov 2009 23:55:18 -0800 Subject: need clarification on -0 In-Reply-To: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <_tSdnUzUUfz7So3WnZ2dnUVZ_rZi4p2d@giganews.com> moijes12 wrote: > I know the value -0 is quite meaningless and makes little sense.But I > was just fiddling.I am unable to figure out the below result > >>>> -0 and True > 0 ----------> (Why is this 0 and not say True or False) >>>> -0 and false > 0 >>>> -0 or True > True > > Could someone please provide me some resources on how these operations > take place.I'd wanna find it out myself Your questions have nothing to do with -0, as it's no different from 0: >>> 0 == -0 True Your examples work the same way with simply 0, which is considered a false value: >>> bool(0) False >>> 0 and True 0 >>> 0 and False 0 >>> 0 or True True What you're seeing is simply the short-circuiting behavior of the `and` and `or` operators; they return the last (relevant) value they encountered before making their determination of the value of the overall expressions. See python.org/doc for more information. -- 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/Skype erikmaxfrancis You'll survive / A true Darwin star -- Des'ree From moijes12 at gmail.com Sat Nov 28 03:45:08 2009 From: moijes12 at gmail.com (moijes12) Date: Sat, 28 Nov 2009 00:45:08 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <_tSdnUzUUfz7So3WnZ2dnUVZ_rZi4p2d@giganews.com> Message-ID: <803a1fbe-f793-4625-89e2-08830577e35e@k13g2000prh.googlegroups.com> On Nov 28, 12:55?pm, Erik Max Francis wrote: > moijes12 wrote: > > I know the value -0 is quite meaningless and makes little sense.But I > > was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > > 0 ----------> (Why is this 0 and not say True or False) > >>>> -0 and false > > 0 > >>>> -0 or True > > True > > > Could someone please provide me some resources on how these operations > > take place.I'd wanna find it out myself > > Your questions have nothing to do with -0, as it's no different from 0: > > ?>>> 0 == -0 > True > > Your examples work the same way with simply 0, which is considered a > false value: > > ?>>> bool(0) > False > ?>>> 0 and True > 0 > ?>>> 0 and False > 0 > ?>>> 0 or True > True > > What you're seeing is simply the short-circuiting behavior of the `and` > and `or` operators; they return the last (relevant) value they > encountered before making their determination of the value of the > overall expressions. ?See python.org/doc for more information. > > -- > Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/ > ? San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis > ? ?You'll survive / A true Darwin star > ? ? -- Des'ree Thanks Erik From lie.1296 at gmail.com Sat Nov 28 04:07:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 20:07:27 +1100 Subject: Feature request: String-inferred names In-Reply-To: <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> Message-ID: <4b10e8b3@dnews.tpgi.com.au> On 11/28/2009 3:08 PM, The Music Guy wrote: > As for your code, I haven't seen it, so it would be hard for me to say > exactly how the new syntax would come into play. What I can tell you, > however, is that the parts of your code that would use it would > probably be easier to read and change to anyone with a firm grasp of > the proposed syntax. Isn't this much easier to read and grasp? obj.d["my_%s" % foo] += 3 doesn't need new syntax as well. > Even if this sort of thing only needed to happen a few times in an > entire project, the project as a whole could only benefit from it. My > projects rely on a lot of metaclassing for the automatic generation of > properties and methods, which saves tremendous amounts of coding. If you use it a lot, it is likely 1) you have abused class syntax for what should have been a dict or 2) what you need is to override __getattr__/__getattribute__ and __setattr__ From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 04:18:17 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 09:18:17 GMT Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <009a6f50$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 23:09:06 -0800, moijes12 wrote: > Hi > > I know the value -0 is quite meaningless and makes little sense. Actually, when it comes to floating point values, it is very useful to be able to distinguish between -0 and +0. > But I > was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > 0 ----------> (Why is this 0 and not say True or False) You need to know two things about Python: (1) All values can be interpreted in a boolean context: if None: print "this will never be printed" else: print "this is always printed" False values include: None, 0, 0.0, "", [], {} and of course False. True values include nearly everything else. (2) `and` and `or` are short-cut operators. They return the first argument which unambiguously defines the result: X and Y => X if X is a false value, and Y if X is a true value. X or Y => X if X is a true value, and Y if X is a false value. Why do `and` and `or` return objects other than True and False? This is especially useful when using `or` in situations like this: process(main_list or fallback_list) which will process the first list of the two which is not empty. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 04:19:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Nov 2009 09:19:53 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <2569860a-797c-413e-a957-8d5f714fc5e8@v30g2000yqm.googlegroups.com> Message-ID: <009a6fb0$0$26925$c3e8da3@news.astraweb.com> On Fri, 27 Nov 2009 20:02:31 -0800, The Music Guy wrote: > That PEP seems to pretty clearly state that it applies only to the 3.x > branch and not to the 2.x branch. Is there maybe a slim chance of > getting my idea added to 2.7, or even 2.8? :D The only new features being added to 2.7 are features which are also being added to 3.x. There is no chance at all of having new features added to 2.7 which isn't added to 3, unless that feature is specifically to make it easier to migrate from 2 to 3. -- Steven From lie.1296 at gmail.com Sat Nov 28 04:22:10 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 20:22:10 +1100 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> Message-ID: <4b10ec28@dnews.tpgi.com.au> On 11/28/2009 6:20 PM, joy99 wrote: > I was writing a transliteration program from Bengali to English and > vice versa. The program using Unicode chart is giving me perfect > outputs in Bengali and vice versa with Bengali input -> English. > I wanted to add some more power to the key board entry scheme, as I > have developed few fonts also and now trying to work out a windows > based word processor in Bengali. > Thank you for your kind answer. > It helped me lot. > ALT portion I'll work out on my own. > Sorry for a wrongly given problem statement. > Wishing you a happy day ahead, > Regards, > Subhabrata. If I haven't misunderstood you, you want to capture keyboard input involving the CTRL and ALT key, am I correct? Getting keyboard input with modifier keys depends on your GUI widgets. Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? From vinay_sajip at yahoo.co.uk Sat Nov 28 04:26:28 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 28 Nov 2009 01:26:28 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> Message-ID: <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> On Nov 27, 1:11?pm, Grimsqueaker wrote: > When I add a Filter to a Handler, everything works as expected (ie. > all messages sent from Loggers below the Filter's level are allowed > through), but when I add the Filter directly on to the Logger, only > that Logger is blocked, regardless of the contents of the Filter. The key thing to remember is that when a logger processes an event, handlers attached to it *and all its parents* are offered the event for handling. In the case where you have just one handler and it has the filter attached, filtering works as you expected. By attaching the filter to the root logger, you are not filtering its handler; this handler is invoked for events logged to all the other loggers, and so (apart from the event at the root logger) those events are not filtered. For some examples of filter usage, see this post: http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 Regards, Vinay Sajip From jabronson at gmail.com Sat Nov 28 04:30:44 2009 From: jabronson at gmail.com (Joshua Bronson) Date: Sat, 28 Nov 2009 01:30:44 -0800 (PST) Subject: python bijection References: <5a99def7-e182-4782-9054-f1035affa34d@x5g2000prf.googlegroups.com> <7n39ojF3jj6iuU1@mid.individual.net> <12c55890-118d-4655-b6c0-c908c9734a17@a32g2000yqm.googlegroups.com> Message-ID: On Nov 27, 9:36?pm, "Gabriel Genellina" wrote: > En Fri, 27 Nov 2009 15:12:36 -0300, Francis Carr ? > escribi?: > > > I was really inspired by this discussion thread! :-) > > > After much tinkering, I think I have a simpler solution. ?Just make > > the inverse mapping accessible via an attribute, -AND- bind the > > inverse of -THAT- mapping back to the original. ?The result is a > > python dict with NO NEW METHODS except this inverse-mapping > > attribute. ?I have posted it on code.activestate.com as > href="http://code.activestate.com/recipes/576968/">Recipe 576968: > > Flipdict -- python dict that also maintains a one-to-one inverse > > mapping > > Nice idea! Indeed! Thanks for sharing! I liked this so much I added something similar in http://bitbucket.org/jab/toys/src/tip/bidict.py (I made the inverse available via a .inv property, as well as via the unary ~ operator (by analogy to bitwise inverse)). I also got rid of getinv, popinv, et al. to keep the API leaner as you recommend. I've kept the slice syntax though as well as namedbidect, so for now I guess I'm allowing for many ways to skin this cat. > Just a couple of comments: > > Instead of: > ? ? ? ? self._flip = dict.__new__(self.__class__) > I'd write: > ? ? ? ? self._flip = self.__class__() > unless I'm missing something (but see the next point). How would this not cause infinite recursion? > Also, although Python's GC is able to handle them, I prefer to avoid ? > circular references like those between x and x._flip. ?Making self._flip a ? > weak reference (and dereferencing it in the property) should be enough. If both self._flip and self._flip._flip are weak references, no strong references to the inverse mapping survive leaving the constructor scope. Unless I'm missing something, only one of these can be a weak reference, and then you'd have to do something like this in the property to prevent "TypeError: FlipDict is not callable": @property def flip(self): try: # we're an inverse, self._flip is a weak reference return self._flip() except TypeError: # we're a forward mapping, self._flip is a strong reference return self._flip From paul.nospam at rudin.co.uk Sat Nov 28 05:14:39 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sat, 28 Nov 2009 10:14:39 +0000 Subject: Python & OpenOffice Spreadsheets References: <486869af-d89f-4261-b4c2-f45af5d3bb93@e7g2000vbi.googlegroups.com> Message-ID: <87k4xbrm5s.fsf@rudin.co.uk> r writes: > On Nov 23, 4:49?am, Gerhard H?ring wrote: >> Is there a *simple* way to read OpenOffice spreadsheets? >> >> Bonus: write them, too? >> >> I mean something like: >> >> doc.cells[0][0] = "foo" >> doc.save("xyz.ods") >> >> >From a quick look, pyodf offers little more than just using a XML parser > > > I find the syntax far to complicated than it should be. Here is an > example just to insert some text.. [employing weapons of mass snippage] It's true that it's a hassle, but the boiler plate stuff can be stuck in a function and then forgotton about really. From lucaberto at libero.it Sat Nov 28 05:29:11 2009 From: lucaberto at libero.it (luca72) Date: Sat, 28 Nov 2009 02:29:11 -0800 (PST) Subject: dvb3 Message-ID: hello i try to use the python-dvb3 bindings, but i have some problem: fe = dvb3.frontend.Frontend(0) type = tipo_1 = fe.get_dvbtype() now i need to set the parameters parametri = dvb3.frontend.QPSKParameters(frequency=frequency, inversion=2 , symbol_rate=27500, fec_inner=9) but when i use fe.set_frontend(parametri) i get the error The debugged program raised the exception IOError "(22, 'Invalid argument')" File: frontend.pyx, Line: 364 thedef is as follow : def set_frontend(self, parameters): global cfrontend cdef cfrontend.dvb_frontend_parameters p if pack_parameters(&p, parameters) == 0: raise ParameterError, "Incorrect parameter type" if ioctl(self.fd, cfrontend.FE_SET_FRONTEND, &p) == -1: raise_ioerror() can you hel me Luca From threaderslash at gmail.com Sat Nov 28 05:38:04 2009 From: threaderslash at gmail.com (Threader Slash) Date: Sat, 28 Nov 2009 21:38:04 +1100 Subject: Python MySQL: clean multiple foreign keys table Message-ID: Hi Everybody, I am working with Python MySQL, and need to clean a table in my database that has 13328 rows. I can not make a simple drop table, because this table is child and also father of other child foreign-keys linked on it. If I try drop table, the system forbidden me. The table is defined with ON UPDATE CASCADE, ON DELETE CASCADE and InnoDB; The primary_key index to that table is defined as productID INT(6) NOT NULL AUTO_INCREMENT ... PRIMARY KEY (productID,productNO) Therefore, I just have to clean; this will automatically restore the table primary key index to 1 for the next input. Right? This procedure worked fine for another table that was a father table, but not also a father and child table. But, for this table, which is child and father of other tables, I got stuck on it. Here is the code - productID is my primary index key to this table: def clean_tableProduct(self): getMaxID_MySQLQuery = """SELECT MAX(productID) FROM product;""" cleanTabeMySQLQuery="""DELETE FROM product WHERE productID <=%s;""" self.cursorMySQL.execute(getMaxID_MySQLQuery) for row in self.cursorMySQL: self.cursorMySQL.execute(cleanTabeMySQLQuery,(row[0],)) If I go to the MySQL console to check the processing results, it gets me: mysql> SELECT MIN(productID) FROM product; 4615748 mysql> SELECT MAX(productID) FROM product; 4629075 If I run the same command on console to clean the table, it works: mysql> DELETE FROM product WHERE productID <='4629075'; Query OK, 13328 rows affected (0.64 sec) and shows me what I would normally expect. However, if I go to Python function after having cleaned the table on console, and run the program again, and clean the table to restart the processing, it restarts the table index not with MIN:1, but instead 4629076. Any suggestion? All comments and suggestions are highly appreciated and welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From subhakolkata1234 at gmail.com Sat Nov 28 05:39:43 2009 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 28 Nov 2009 02:39:43 -0800 (PST) Subject: Some Basic questions on the use of CTRL and ALT Keys References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> <4b10ec28@dnews.tpgi.com.au> Message-ID: On Nov 28, 2:22?pm, Lie Ryan wrote: > On 11/28/2009 6:20 PM, joy99 wrote: > > > I was writing a transliteration program from Bengali to English and > > vice versa. The program using Unicode chart is giving me perfect > > outputs in Bengali and vice versa with Bengali input -> ?English. > > I wanted to add some more power to the key board entry scheme, as I > > have developed few fonts also and now trying to work out a windows > > based word processor in Bengali. > > Thank you for your kind answer. > > It helped me lot. > > ALT portion I'll work out on my own. > > Sorry for a wrongly given problem statement. > > Wishing you a happy day ahead, > > Regards, > > Subhabrata. > > If I haven't misunderstood you, you want to capture keyboard input > involving the CTRL and ALT key, am I correct? > > Getting keyboard input with modifier keys depends on your GUI widgets. > Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? You are very right. I am using IDLE on WinXP and for building GUI- TKinter. From tjreedy at udel.edu Sat Nov 28 05:41:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Nov 2009 05:41:46 -0500 Subject: Intro To Python Using Turtle Graphics In-Reply-To: <4b10a652$1@news2.actrix.gen.nz> References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> <4b10a652$1@news2.actrix.gen.nz> Message-ID: Enkidu wrote: > Ben Finney wrote: > >> Oh, so trash-talking in *other* forums where you feel safe from being >> caught is okay? ;-) >> > I take your point, but the other group in question is a 'local' group. I think he intended to mean that it was a local group where trash-talking and stupid comments are the norm. From ben+python at benfinney.id.au Sat Nov 28 06:11:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 22:11:12 +1100 Subject: Intro To Python Using Turtle Graphics References: <4b1076a8$1@news2.actrix.gen.nz> <009a020b$0$26925$c3e8da3@news.astraweb.com> <4b108315$1@news2.actrix.gen.nz> <87ocmnv1gt.fsf@benfinney.id.au> <4b10a652$1@news2.actrix.gen.nz> Message-ID: <87tyweucof.fsf@benfinney.id.au> Terry Reedy writes: > Enkidu wrote: > > Ben Finney wrote: > >> Oh, so trash-talking in *other* forums where you feel safe from > >> being caught is okay? ;-) > >> > > I take your point, but the other group in question is a 'local' > > group. > > I think he intended to mean that it was a local group where > trash-talking and stupid comments are the norm. Well no, I'm not passing any comment on the group. Merely that trash-talk isn't made any more acceptable just because the target of the trash-talk isn't present to hear it. But more importantly, my comment was intended as a pleasant jibe (hence the smiley), not a severe admonishment. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we give peas a chance, won't the lima beans feel | _o__) left out?? ?_Pinky and The Brain_ | Ben Finney From fearsomedragonfly at gmail.com Sat Nov 28 06:38:38 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 03:38:38 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: On Nov 28, 3:07?am, Lie Ryan wrote: > On 11/28/2009 3:08 PM, The Music Guy wrote: > > > As for your code, I haven't seen it, so it would be hard for me to say > > exactly how the new syntax would come into play. What I can tell you, > > however, is that the parts of your code that would use it would > > probably be easier to read and change to anyone with a firm grasp of > > the proposed syntax. > > Isn't this much easier to read and grasp? > > obj.d["my_%s" % foo] += 3 > > doesn't need new syntax as well. Actually, that's similar to my backup solution, which is a variant of the "attrs" class that PEP 363 provides. It does make things easier to read, but a new syntax would still be better because: 1.) A new syntax would apply to _everything_ as it would be a hook to the very mechanism that gets the value of a member from an object and does not rely on an object defining the magic "d" property. I suppose you could argue that an enhancement could be made to the language that says that all objects must define the magic "d" (so the builins "object" and "type" would have to define it). That also has the added benefit of not conflicting with PEP 3003, which says it is fine to add new methods (and I would assume properties as well) to existing classes. 2.) Ben's patch for his proposed syntax generated an aproximate 1% performance hit for the interpreter overall versus a >40% increase where code that used the getattr/settattr functions was modified to use the proposed syntax. The magic "d" MIGHT have a performance increase over the getattr/setattr functions, but a syntax would still be significantly faster because there would be less function dereferencing/calling. For the purposes that I had intended for the syntax to be used, that would definitely matter. > If you use it a lot, it is likely 1) you have abused class syntax for > what should have been a dict or 2) what you need is to override > __getattr__/__getattribute__ and __setattr__ Oh boy...here we go. :| Please listen. In all the time I've spent in the coding community (that's at least 7 years) and especially since I started paying attention to the Python community (2 years), I have noticed a trend: When one coder does something that another cannot understand, frequently the other will assume the former is not only doing things wrong, but is doing them _blatantly_ wrong. I have caught myself making that very assumption many times in the past, and I've tried hard to build up an immunity against the impulse to make that assumption. At this point, I don't even believe in such a thing as a universal "wrong way" and a "right way" to code that applies to every circumstance. The way to solve a problem depends on the problem. When it comes to coding, there is not an absolute "right" way or "wrong" way--unless we're talking about, say, stealing closed source code without permission, or deliberately coding in a way that will cause problems for the end user (like causing memory clogs or buffer overflows and whatnot). All of this can be determined through common sense. And yet I continue to see the attitude of "my solution is the ONLY solution to your problem, and it doesn't matter if I don't even actually understand the problem." Not everyone does this, but it is a frequent enough occurence to be worth noting. If I had to pull a number out of my magic bag, I would say 4 out of 10 resposes have at least a hint of this attitude, and 2.5/10 where it is very obvious. But I digress. I've already gone over other possible solutions and the one I am using seems to fit the bill better than any other yet presented to me, including the ones you just suggested. In fact, I'm fairly certain that __getattr__ and friends even apply to the situation, or if they do, they're certainly inferior alternatives to the use of getattr/setattr. Not that I'm calling you inferior--I'm just saying that if you had a better understanding of the problem you would not see __getatrr__ et al. as parts of a possible solution because they don't really make logical sense given the circumstances. ...and I have one last thing to say. I feel very strongly that metaclassing is a fiercely underestimated and largely untapped source of good coding solutions. I hope that many coders will see this and help to make it more adoptable by the masses; at present it is seen as a big, scary beast that is hard to tame and even harder to drive. It is portrayed as something dangerous that should only be used in relatively rare situations. I disagree with this view. It is the view itself which makes it seem so dangerous (in other words, it is self- perpetuating). Well, that's about enough yakking for 5:30 in the morning...time to give my noggin a rest. -- Brad Harms From fearsomedragonfly at gmail.com Sat Nov 28 06:44:50 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 03:44:50 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <239496b3-36bc-4e9e-a364-d8c5fc64a968@e27g2000yqd.googlegroups.com> P.S., not trying to start a flame war. It's just that I can't stand to keep silent on the matter any longer. -- Brad Harms From lie.1296 at gmail.com Sat Nov 28 07:10:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 28 Nov 2009 23:10:50 +1100 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <4b1113ad$1@dnews.tpgi.com.au> On 11/28/2009 10:38 PM, The Music Guy wrote: >> If you use it a lot, it is likely 1) you have abused class syntax for >> what should have been a dict or 2) what you need is to override >> __getattr__/__getattribute__ and __setattr__ > > Oh boy...here we go. :| > ok, then what's your use case, AFAICT in the discussion here and previous ones, nobody has yet described a realistic and compelling situation where setattr/getattr is the best solution. That's why the discussion tended to end with "not used frequently enough"; simply because nobody can turn up with a use case to justify a new syntax, especially since all the proposed syntax are ugly (the most acceptable one, for me, is obj.[foo], still ugly but not as ugly as the others). From ben+python at benfinney.id.au Sat Nov 28 07:12:09 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 28 Nov 2009 23:12:09 +1100 Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <87ljhqu9uu.fsf@benfinney.id.au> The Music Guy writes: > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, > frequently the other will assume the former is not only doing things > wrong, but is doing them _blatantly_ wrong. I think you may be misinterpreting the message. > At this point, I don't even believe in such a thing as a universal > "wrong way" and a "right way" to code that applies to every > circumstance. The way to solve a problem depends on the problem. You'll find firm agreement on that in this group. > When it comes to coding, there is not an absolute "right" way or > "wrong" way--unless we're talking about, say, stealing closed source > code without permission, or deliberately coding in a way that will > cause problems for the end user (like causing memory clogs or buffer > overflows and whatnot). However, when it comes to a *specific*, mature programming language, there *are* right and wrong ways. Or, at least, there are ways encouraged or discouraged by the language, its interfaces, its style guides, and its community. Which is very important: it's the rare program that is only ever read by one person in one context. Far more often, the same program needs to be read multiple times, by multiple people, in multiple contexts, over multiple iterations of maintenance. And for that to be feasible, it's very important to write the program the right way *for that language*. Sticking to local conventions has a great deal of practical merit in the medium of human-to-human communication that we call ?programming?. Progress depends on doing things differently; but maintainability depends on keeping unexpected differences to a minimum. -- \ ?The truth is the most valuable thing we have. Let us economize | `\ it.? ?Mark Twain, _Following the Equator_ | _o__) | Ben Finney From cjwilliams43 at gmail.com Sat Nov 28 07:46:16 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sat, 28 Nov 2009 07:46:16 -0500 Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> Message-ID: On 27-Nov-09 22:04 PM, Steve Howell wrote: > Python has this really neat idea called indentation-based syntax, and > there are folks that have caught on to this idea in the HTML > community. > > AFAIK the most popular indentation-based solution for generating HTML > is a tool called HAML, which actually is written in Ruby. > > I have been poking around with the HAML concepts in Python, with the > specific goal of integrating with Django. But before releasing that, > I thought it would be useful to post code that distills the basic > concept with no assumptions about your target renderer. I hope it > also serves as a good example of what you can do in exactly 100 lines > of Python code. > > Here is what it does... > > You can use indentation syntax for HTML tags like table. > > From this... > > table > tr > td > Left > td > Center > td > Right > > ...you get this: > ... [snip] This is a neat idea but would a two character indentation not be enough? Colin W. From detlev at die-offenbachs.de Sat Nov 28 09:22:08 2009 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sat, 28 Nov 2009 15:22:08 +0100 Subject: debugger on system with Python 2 and 3 References: Message-ID: Hi, eric4 snapshot releases support Python3. Detlev Yo Sato wrote: > Hi, > > I am a relative newcomer to the Python language, and only write Python > 3. Now I would very much like to a more-than-basic debugger. However > it seems as if the fact that I have both Python 2 and 3 on the system > complicates the matter... > > First I tried to use something called pydb, but it seems to invoke > python 2, and I don't know quite how to (or whether I can) configure > it for Python 3. > > Secondly I installed something called IDLE3, which complains that TK > is not configured for Python 3. > > I don't want to remove or default to Python 2, as there seem to be a > number of programs that rely on it. > > I wonder how best to avoid my problems. Would perhaps somebody in the > same sort of situation share their wisdom?? > > Yo -- Detlev Offenbach detlev at die-offenbachs.de From vlastimil.brom at gmail.com Sat Nov 28 09:30:36 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 28 Nov 2009 15:30:36 +0100 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <735e5c29-47c4-4a42-ac91-36b898037e86@z35g2000prh.googlegroups.com> <4b10ec28@dnews.tpgi.com.au> Message-ID: <9fdb569a0911280630v526fa3deve702acfc243c057a@mail.gmail.com> 2009/11/28 joy99 : > On Nov 28, 2:22?pm, Lie Ryan wrote: >> On 11/28/2009 6:20 PM, joy99 wrote: >> >> > I was writing a transliteration program from Bengali to English and >> > vice versa. The program using Unicode chart is giving me perfect >> > outputs in Bengali and vice versa with Bengali input -> ?English. >> > I wanted to add some more power to the key board entry scheme, as I >> > have developed few fonts also and now trying to work out a windows >> > based word processor in Bengali. >> > Thank you for your kind answer. >> > It helped me lot. >> > ALT portion I'll work out on my own. >> > Sorry for a wrongly given problem statement. >> > Wishing you a happy day ahead, >> > Regards, >> > Subhabrata. >> >> If I haven't misunderstood you, you want to capture keyboard input >> involving the CTRL and ALT key, am I correct? >> >> Getting keyboard input with modifier keys depends on your GUI widgets. >> Which are you using? Tkinter? wxWidget? PyQT? or plain ol' terminal? > > You are very right. I am using IDLE on WinXP and for building GUI- > TKinter. > -- > http://mail.python.org/mailman/listinfo/python-list > You may check e.g.: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm hth, vbr From pmaupin at gmail.com Sat Nov 28 10:31:51 2009 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 28 Nov 2009 07:31:51 -0800 (PST) Subject: python bijection References: <87aayhgbx8.fsf@benfinney.id.au> Message-ID: On Nov 19, 8:36?pm, Ben Finney wrote: > Carl Banks writes: > > On Nov 19, 3:24?pm, Joshua Bronson wrote: > > Apart from the GPL, it seems perfectly fine to release, and looks like > > an interesting strategy. I've wanted one of those once in a while, > > never enough to bother looking for one or writing one myself. > > I would think GPL is an excellent choice for such a library then, if the > author's intention is to encourage more software to be free software so > that it can incorporate a unique library like this. Well, yes and no. This bidict class sounds nice and full-featured, especially after the changes prompted by the fruitful discussion. I personally use inverse mappings on a regular basis, but for the most part, my data doesn't change all that dynamically (or performance doesn't really matter), so when I need to go backwards I often do something like: inverse_mapping = dict((y, x) for (x, y) in forward_mapping.iteritems ()) Having said that, if I ever actually *need* something more full- featured to add to non-GPLed software, I'd just write it (and release it under a permissive license). IMHO, GPLing something this simple is really the tail trying to wag the dog. Case in point: I was just using rst2pdf to combine some restructured text and SVG images, using svglib. svglib had some bugs and didn't work right on my PDFs. svglib is not developed publicly, and the author is somewhat slow to accept patches. Since svglib is reasonably small, if it had been released under a permissive license, or even the LGPL, I probably would have just copied it into the rst2pdf repository and fixed it. If it were any smaller, I would have rewritten it. I don't own the rst2pdf package, and didn't really want a license discussion about 1K of source lines dictating a license change on 15K lines. As it is, I figure the svglib author will probably get around to fixing the bug at some point anyway, and for now I can easily use PDFs for my graphics input format, so I cleaned up and added to some old PDF code I had lying around, and released it as the open source pdfrw package, and now rst2pdf can use that to import PDFs as vector images without rasterizing them -- a new capability. So in this case, the GPL spurred open-source development, in exactly the same way that proprietary licenses do... I'm quite happy to *use* GPLed software (and greatly appreciate the authors' efforts), and I'm even sometimes willing to debug or add features and submit patches to GPLed software, and I might even have a (business, not political) reason to release some software under the GPL myself someday. But if I ever did release something under the GPL for business reasons, it would be because I also had the right to also offer a proprietary version. This would require that I owned _all_ the code in the package, so the implication is: I'm not going to use your tiny little GPLed code in any major software I write for release, whether my software is GPLed or not. The LGPL is different. I view the LGPL as a statement of "if you ever add related functionality to this or fix a bug in this in a shipping product, I'd like to see the fix, please" and I could even see myself releasing something with this license under the right circumstances. Now if I were doing a web service, it would be a different story. I would be quite happy to add your GPLed software into the mix, so if that's a terrible thing, perhaps you should consider affero for your future offerings :-) Best regards, Pat From phlip2005 at gmail.com Sat Nov 28 11:19:02 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 08:19:02 -0800 (PST) Subject: filename of calling function? Message-ID: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Consider these two python modules: aa.py def a(): print '?' bb.py import aa def bb(): aa.a() bb() How do I make the print line emit the filename of bb.py? (It could be anything.) I am currently playing with sys.exc_info, but it seems to only emit the stack between the raise and the except. Could be pilot error, of course. Thanks for any help! -- Phlip http://c2.com/cgi/wiki?ZeekLand From arts.martijn at gmail.com Sat Nov 28 11:23:15 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Sat, 28 Nov 2009 17:23:15 +0100 Subject: a 100-line indentation-based preprocessor for HTML In-Reply-To: <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> References: <7df64b08-8d81-4159-9f24-ab0945d82cf8@g1g2000pra.googlegroups.com> <7ba442a6-dd93-442a-a0d7-4077645a5a5a@y28g2000prd.googlegroups.com> Message-ID: <23739e0a0911280823x3e80592checabd3ba1c0d13f0@mail.gmail.com> It?s quite clear to me: Not. I've taken a look at the "Timebar", and in the last two months there has been no change at all. On Sat, Nov 28, 2009 at 7:32 AM, Steve Howell wrote: > On Nov 27, 9:56 pm, "David Williams" wrote: > > You might want to take a look at this: > > > > http://www.ghrml.org/ > > > > Yep, it's not clear how actively they are maintaining that. The fact > that it seems to target Genshi only might be limiting their audience, > which is unfortunate. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phlip2005 at gmail.com Sat Nov 28 11:40:41 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 08:40:41 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: On Nov 28, 8:19?am, Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > ? ? print '?' > > bb.py > ? import aa > > def bb(): > ? aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) try: raise None except: import sys from traceback import extract_tb, extract_stack frame = sys.exc_info()[2].tb_frame.f_back calling_file = extract_stack(frame, 2)[1][0] From callmeclaudius at gmail.com Sat Nov 28 12:04:40 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Sat, 28 Nov 2009 09:04:40 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: <62448fc8-ad51-4600-99b6-713d21fa12dc@a32g2000yqm.googlegroups.com> On Nov 28, 11:40?am, Phlip wrote: > On Nov 28, 8:19?am, Phlip wrote: > > > > > Consider these two python modules: > > > aa.py > > > def a(): > > ? ? print '?' > > > bb.py > > ? import aa > > > def bb(): > > ? aa.a() > > > bb() > > > How do I make the print line emit the filename of bb.py? (It could be > > anything.) > > ? ? ? ? try: > ? ? ? ? ? ? raise None > ? ? ? ? except: > ? ? ? ? ? ? import sys > ? ? ? ? ? ? from traceback import extract_tb, extract_stack > ? ? ? ? ? ? frame = sys.exc_info()[2].tb_frame.f_back > ? ? ? ? ? ? calling_file = extract_stack(frame, 2)[1][0] code works perfectly except on my system both the indexes need to be 0 (eg: "extract_stack(frame, 2)[0][0]") From phlip2005 at gmail.com Sat Nov 28 12:37:13 2009 From: phlip2005 at gmail.com (Phlip) Date: Sat, 28 Nov 2009 09:37:13 -0800 (PST) Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> <62448fc8-ad51-4600-99b6-713d21fa12dc@a32g2000yqm.googlegroups.com> Message-ID: <82e2dcd1-6b78-4863-ae04-4811205da3da@v15g2000prn.googlegroups.com> On Nov 28, 9:04?am, Joel Davis wrote: > > ? ? ? ? try: > > ? ? ? ? ? ? raise None > > ? ? ? ? except: > > ? ? ? ? ? ? import sys > > ? ? ? ? ? ? from traceback import extract_tb, extract_stack > > ? ? ? ? ? ? frame = sys.exc_info()[2].tb_frame.f_back > > ? ? ? ? ? ? calling_file = extract_stack(frame, 2)[1][0] > > code works perfectly except on my system both the indexes need to be 0 > (eg: "extract_stack(frame, 2)[0][0]") I thought the 0 was myself, 1 my caller, etc. But tx for trying it From aahz at pythoncraft.com Sat Nov 28 12:38:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:38:13 -0800 Subject: best performance for storage of server information for python CGI web app? References: <58e5cd75-75be-4785-8e79-4903643965ce@e31g2000vbm.googlegroups.com> Message-ID: In article <58e5cd75-75be-4785-8e79-4903643965ce at e31g2000vbm.googlegroups.com>, davidj411 wrote: > >i was also thinking about using SQL Lite with one DB to store all the >info. with this option, i would not have to worry about concurrent >updates, but as the file size increases, i could expect performance to >suffer again? Depends what you mean by "suffer". Performance always decreases as size gets larger unless you take specific steps (such as better algorithms or bigger hardware). Using indexes should give SQLite reasonable performance; you can always upgrade to a faster SQL implementation or switch to another kind of storage. But honestly, until you get to millions of records, you should be fine with SQLite. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:40:08 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:40:08 -0800 Subject: WindowsError is not available on linux? References: Message-ID: In article , wrote: >On 07:53 pm, aahz at pythoncraft.com wrote: >>In article , >>Peng Yu wrote: >>> >>>It's not clear to me whether WindowsError is available on linux or >>>not, after I read the document. >> >>Here's what I told a co-worker to do yesterday: >> >>if os.name =3D=3D 'nt': >> DiskError =3D (OSError, WindowsError) >>else: >> DiskError =3D WindowsError >> >>try: >> disk_operation() >>except DiskError: >> logit() > >This isn't necessary. WindowsError subclasses OSError. Thanks! Much appreciated! (I haven't done much Windows programming in the past -- and would have preferred to keep it that way. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:44:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:44:18 -0800 Subject: Arcane question regarding white space, editors, and code collapsing References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> <87fx8bl74c.fsf@benfinney.id.au> Message-ID: In article <87fx8bl74c.fsf at benfinney.id.au>, Ben Finney wrote: >Wells writes: >> >> Is it... pythonic, then, to have these lines of tabs/spaces to support >> code collapsing? Is it proper, improper, or irrelevant? > >It's quite improper (though syntactically null, in Python) to have >trailing whitespace on lines. That includes blank lines. Your parenthetical is not quite true, unfortunately. Trailing whitespace after a continuation backslash generates a SyntaxError. That's the main reason I loathe continuation lines. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 12:47:48 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 09:47:48 -0800 Subject: Writing a Carriage Return in Unicode References: <52afc5ea-e8be-4575-8ac3-3034d17a3533@p8g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels > declaimed the following in >gmane.comp.python.general: >> >> If you've actually typed on a physical typewriter, you know that moving >> the carriage back is a distinct operation from rolling the platen >> forward; both operations are accomplished when you push the carriage >> back using the bar, but you know they are distinct. > > Of course, if you are describing a /real/ /manual/ typewriter, you >would rapidly discover that the sequence is -- since pushing >the bar would often trigger the line feed before it would slide the >carriage to the right. Often, but not always; it certainly was possible on most typewriters to return the carriage without a line feed -- and occasionally desirable for overstrike. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sat Nov 28 13:24:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 29 Nov 2009 05:24:24 +1100 Subject: Python Programming Challenges for beginners? In-Reply-To: References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> Message-ID: <4b116b3b@dnews.tpgi.com.au> On 11/28/2009 1:51 AM, n00m wrote: > On Nov 27, 1:22 pm, Jon Clements wrote: >> Of course, if you take '~' literally (len(s)<= -10001) I reckon >> you've got way too many :) >> >> Jon. > > Then better: len(s)< abs(~10000) > > PS It's a hard problem; so let's leave it alone I'm not going to write it, but I guess a fairly efficient solution can be written with using a Trie: http://en.wikipedia.org/wiki/Trie and iterating over its items, including partial prefixes. Worse case scenario for creating the tree would be O(n**2) where n = length of string, and iterating the structure would take O(N) where N = number of different substring. for "abbaz", the data structure would be: {'a': {'b': {'b': {'a': {'z': None}}}, 'z': None, }, 'b': {'b': {'a': {'z': None}}, 'a': {'z': None}}, }, 'z': None, } iterating the structure: a ab abb abba abbaz az b bb bba bbaz ba baz z --- 13 (not including '') Now, this makes me interested. How efficient it would be when len(s) == 10000... might as well write it and see. Take back what I said, give me a minute... From inq1ltd at inqvista.com Sat Nov 28 14:38:34 2009 From: inq1ltd at inqvista.com (jim-on-linux) Date: Sat, 28 Nov 2009 14:38:34 -0500 Subject: py2exe users In-Reply-To: <4b116b3b@dnews.tpgi.com.au> References: <4b116b3b@dnews.tpgi.com.au> Message-ID: <200911281438.35080.inq1ltd@inqvista.com> I have used py2exe many times with success. My current program is completing as expected but the exe file fails to open. The output file states that _imaging_gif is missing. I can run the program ok with IDLE but after converting with py2exe, the exe file just sits there. I'm using 2.6 on win XP. Any Ideas? jim-on-linux From n00m at narod.ru Sat Nov 28 14:45:52 2009 From: n00m at narod.ru (n00m) Date: Sat, 28 Nov 2009 11:45:52 -0800 (PST) Subject: Python Programming Challenges for beginners? References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> <4b116b3b@dnews.tpgi.com.au> Message-ID: <566a3d7d-4cc1-4909-aba0-b0c6011f719e@p8g2000yqb.googlegroups.com> On Nov 28, 8:24?pm, Lie Ryan wrote: > Now, this makes me interested. How efficient it would be when len(s) == > 10000... might as well write it and see. Take back what I said, give me > a minute... ... and you can check it here: http://www.spoj.pl/problems/DISUBSTR/ I see there only one (accepted) solution in Python: http://www.spoj.pl/ranks/DISUBSTR/lang=PYTH%202.5 From n00m at narod.ru Sat Nov 28 15:07:30 2009 From: n00m at narod.ru (n00m) Date: Sat, 28 Nov 2009 12:07:30 -0800 (PST) Subject: Python Programming Challenges for beginners? References: <60566f3b-9eb6-4bc7-a4af-68fded97e09d@s20g2000yqd.googlegroups.com> <4B0F9C2D.9060804@NO.SPAM.velseis.com.au> <4f3a3c26-3644-4214-b8b2-b0ac460988d2@g27g2000yqn.googlegroups.com> <4b116b3b@dnews.tpgi.com.au> <566a3d7d-4cc1-4909-aba0-b0c6011f719e@p8g2000yqb.googlegroups.com> Message-ID: <3a695b27-cb82-4c93-b979-7185d2f3c2e9@9g2000yqa.googlegroups.com> PS My straightforward C++ solution got TLE... #include #include #include #include #include #include #include #include #include using namespace std; int main() { //freopen("88.txt", "rt", stdin); //freopen("99.txt", "wt", stdout); int tcs; string s; cin >> tcs; while (tcs-- > 0) { cin >> s; int n = s.size(); s = s + ' '; vector< vector > a(256); int ans = 0; for (int i = n - 1; i >= 0; --i) { int lev = 0; vector p = a[s[i]]; vector q; while (!p.empty()) { q.clear(); ++lev; for (int j = 0; j < p.size(); ++j) { if (s[p[j] + 1] == s[i + lev]) { q.push_back(p[j] + 1); } } p.swap(q); } a[s[i]].push_back(i); ans += n - i - lev; } cout << ans << endl; } return 0; } From grflanagan at gmail.com Sat Nov 28 15:14:53 2009 From: grflanagan at gmail.com (Gerard Flanagan) Date: Sat, 28 Nov 2009 20:14:53 +0000 Subject: filename of calling function? In-Reply-To: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > print '?' > > bb.py > import aa > > def bb(): > aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) > Possibly not very reliable in every situation (doctests, other pythons, ...) but this is what I do: --------- aa.py -------------- import __main__ as CALLER def mynameis(): print CALLER.__file__ --------- bb.py -------------- import aa def whosthere(): aa.mynameis() whosthere() ------------------------------- OUTPUT: bb.py hth G.F. From timr at probo.com Sat Nov 28 15:26:33 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:26:33 -0800 Subject: hex int and string References: <415ae295-84ae-43a2-a2e0-eec27abbf05b@c3g2000yqd.googlegroups.com> <87pr74xqxt.fsf@benfinney.id.au> <4b0f9e7c$1@dnews.tpgi.com.au> Message-ID: <8r13h5tbl1kck2eq0jds72mm15tpaelhon@4ax.com> Marco Mariani wrote: >luca72 wrote: > >> i have checked and pyscard accept also the decimal notation, > >I'm not sure you ever understood what the problem was, or where, but I'm >happy you feel like you've solved it. +1 QOTW. Great reply. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Nov 28 15:31:49 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:31:49 -0800 Subject: why do I get this behavior from a while loop? References: <00998f26$0$26925$c3e8da3@news.astraweb.com> Message-ID: "S. Chris Colbert" wrote: > >What a newbie mistake for me to make. Don't feel too badly about it. Even very experienced programmers get bitten by this issue. Until someone points it out, it's certainly not obvious. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Nov 28 15:39:05 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Nov 2009 12:39:05 -0800 Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> Message-ID: <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> moijes12 wrote: > >I know the value -0 is quite meaningless and makes little sense.But I >was just fiddling.I am unable to figure out the below result > >>>> -0 and True >0 ----------> (Why is this 0 and not say True or False) >>>> -0 and false >0 >>>> -0 or True >True > >Could someone please provide me some resources on how these operations >take place.I'd wanna find it out myself Actually, there ARE computers where you might not see this result. Virtually all of the processors on which Python runs use two's complement arithmetic. In two's complement, there is no separate value called -0. 0 and -0 have the same bit representation. In one's complement, -0 and 0 have different representations. Having spent 10 years with Control Data (the 6000 and Cyber 70/170 mainframes were all one's complement), I am particularly sensitive to this. Processors are usually architected so that you don't normally see the -0, but it leads you to think about arithmetic a bit differently. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From news123 at free.fr Sat Nov 28 16:11:18 2009 From: news123 at free.fr (News123) Date: Sat, 28 Nov 2009 22:11:18 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> Message-ID: <4b1191f6$0$3891$426a74cc@news.free.fr> r wrote: > more *maybe useful dump? > >>>> for i in dev.Items: > for p in i.Properties: > if not p.IsReadOnly: > print p.Name, '->', p.Value > . . . > Horizontal Resolution -> 200 > Vertical Resolution -> 200 > Horizontal Start Position -> 0 . . . > > Now how to set the values... hmmm? > How to set the values? This is THE magic question. At least I found out how to set the values in C# : foreach (Property prop in item.Properties){ if (prop.IsReadOnly) continue; if (prop.Name == "Horizontal Resolution") { IProperty iprop = (IProperty)prop; Object val = 75; iprop.set_Value(ref val); } } Below my most recent complete script: (still not able to set params, though I can with C#) import win32com.client, os WIA_COM = "WIA.CommonDialog" WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE="{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" def takePictureOrNot(dev): # cameras have to call TakePicture for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: print "take PICK" foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) def setImgProps(item): # here scan properties should be set for prop in item.Properties: if prop.IsReadOnly: continue if(prop.Name == "Horizontal Resolution"): res = 250 print "trying to set",prop.Name,prop,"to ",res ### unfortunately the next line (if uncommented) fails #prop.set_Value(res) def transferImg(dev): # set properties and scan image i=1 image = None for item in dev.Items: if i==dev.Items.Count: setImgProps(item) image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 return image def scan_image_wia(): wia = win32com.client.Dispatch(WIA_COM) # CommonDialog object dev = wia.ShowSelectDevice() takePictureOrNot(dev) image = transferImg(dev) return image image = scan_image_wia() fname = 'wia-test.jpg' if os.path.exists(fname): os.remove(fname) image.SaveFile(fname) bye N From news123 at free.fr Sat Nov 28 16:18:35 2009 From: news123 at free.fr (News123) Date: Sat, 28 Nov 2009 22:18:35 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: <4b097593$0$30269$426a74cc@news.free.fr> References: <4b097593$0$30269$426a74cc@news.free.fr> Message-ID: <4b1193ac$0$6093$426a34cc@news.free.fr> Meanwhile I found out, why my script worked only on windows 7/Vista and not on my XP host. The WIA 2.0 Scripting Model is by default not installed on Windows XP. Install instructions can be found at http://msdn.microsoft.com/en-us/library/ms630827%28VS.85%29.aspx My second problem (changing parameters) is still not solved in python. bye N News123 wrote: > Hi, > > I'm trying to scan a document from a python 2.6 script without user > interaction. > > I found a code snippet, that allows me to scan under Vista, but that > doesn't allow me to select the dpi / color mode / etc. > > The snippet uses win32com.client > > # ##################### script start > import win32com.client,os > > WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" > WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" > > os.chdir('c:/temp') > wia = win32com.client.Dispatch("WIA.CommonDialog") > dev = wia.ShowSelectDevice() > for command in dev.Commands: > if command.CommandID==WIA_COMMAND_TAKE_PICTURE: > foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) > i=1 > for item in dev.Items: > if i==dev.Items.Count: > image=item.Transfer(WIA_IMG_FORMAT_PNG) > break > i=i+1 > > image.SaveFile("test.png") > ######################### script end > > > My problems are: > > - This script works fine for me under Windows 7, however I'm > unable to specify additional parameters, like dpi and > color mode. > > - The script doesn't work under windows XP, though the scanner driver is > installed. (Gimp finds the scanner (as WIA scanner)). > Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL. > The error message is: > -------------------------------------------------------------------- > Traceback (most recent call last): > File "C:\work\python\minidemos\wia_get_simple.py", line 7, in > wia = win32com.client.Dispatch("WIA.CommonDialog") > File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line > 95, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line > 104, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line > 84, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > com_error: (-2147221005, 'Invalid class string', None, None) > --------------------------------------------------------------------- From changlani.nitin at gmail.com Sat Nov 28 17:19:02 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sat, 28 Nov 2009 17:19:02 -0500 Subject: Variables with cross-module usage Message-ID: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> Hello everyone, I am fairly new to Python and occasionally run into problems that are almost always resolved by referring to this mailing-list's archives. However, I have this one issue which has got me stuck and I hope you will be tolerant enough to help em out with it! What I want to achieve is something like the global variables in C/C++: you declare them in one file and "extern" them in all the files where you need to use them. I have 3 files: one.py, two.py and three.py as below: one.py ---------- a = 'place_a' b = 'place_b' x = 'place_x' myList = [a, b, 'place_c'] ====================================================================== two.py ---------- import one def myFunc(): print one.x print one.myList ====================================================================== three.py ------------ import one import two def argFunc(): one.x = 'place_no_x' one.a = 'place_no_a' one.b = 'place_no_b' if __name__ == '__main__': two.myFunc() print argFunc() two.myFunc() ====================================================================== Output: ----------- 'place_x' ['place_a', 'place_b', 'place_c'] 'place_no_x' ['place_a', 'place_b', 'place_c'] (*** instead of ['place_no_a', 'place_no_b', 'place_c'] ***) The last line in the output is what's baffling me. Can anyone please help me know if I am doing something wrong? Thanks in advance, Nitin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Nov 28 17:28:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 22:28:49 +0000 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: <4b1191f6$0$3891$426a74cc@news.free.fr> References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> <4b1191f6$0$3891$426a74cc@news.free.fr> Message-ID: <4B11A421.1020607@mrabarnett.plus.com> News123 wrote: > r wrote: >> more *maybe useful dump? >> >>>>> for i in dev.Items: >> for p in i.Properties: >> if not p.IsReadOnly: >> print p.Name, '->', p.Value >> > . . . >> Horizontal Resolution -> 200 >> Vertical Resolution -> 200 >> Horizontal Start Position -> 0 > . . . >> Now how to set the values... hmmm? >> Well, according to that they /aren't/ read-only because it says: if not p.IsReadOnly: ^^^ From python at mrabarnett.plus.com Sat Nov 28 17:36:24 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Nov 2009 22:36:24 +0000 Subject: Variables with cross-module usage In-Reply-To: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> Message-ID: <4B11A5E8.3080700@mrabarnett.plus.com> Nitin Changlani. wrote: > Hello everyone, > > I am fairly new to Python and occasionally run into problems that are > almost always resolved by referring to this mailing-list's archives. > However, I have this one issue which has got me stuck and I hope you > will be tolerant enough to help em out with it! > > What I want to achieve is something like the global variables in C/C++: > you declare them in one file and "extern" them in all the files where > you need to use them. I have 3 files: one.py, two.py and three.py as below: > > one.py > ---------- > a = 'place_a' > b = 'place_b' > x = 'place_x' > > myList = [a, b, 'place_c'] > > ====================================================================== > > two.py > ---------- > import one > > def myFunc(): > print one.x > print one.myList > > ====================================================================== > > three.py > ------------ > import one > import two > > def argFunc(): > one.x = 'place_no_x' > one.a = 'place_no_a' > one.b = 'place_no_b' > > if __name__ == '__main__': > two.myFunc() > print > argFunc() > two.myFunc() > > ====================================================================== > > Output: > ----------- > 'place_x' > ['place_a', 'place_b', 'place_c'] > > 'place_no_x' > ['place_a', 'place_b', 'place_c'] (*** instead of ['place_no_a', > 'place_no_b', 'place_c'] ***) > > The last line in the output is what's baffling me. Can anyone please > help me know if I am doing something wrong? > What's confusing you? myList gets its value (['place_a', 'place_b', 'place_c']) when one.py is first imported, and you never change it after that. From rami.chowdhury at gmail.com Sat Nov 28 17:46:37 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 28 Nov 2009 14:46:37 -0800 Subject: Variables with cross-module usage In-Reply-To: <4B11A5E8.3080700@mrabarnett.plus.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> Message-ID: <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> Hi Nitin, On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > Nitin Changlani. wrote: >> three.py >> ------------ >> import one >> import two >> >> def argFunc(): >> ? ?one.x = 'place_no_x' >> ? ?one.a = 'place_no_a' >> ? ?one.b = 'place_no_b' >> I think this is what is biting you. You might expect that after argFunc, one.x would be set to 'place_no_x' and so on. However, Python's scoping doesn't work like that -- the name one.x is only rebound in the function's scope, so outside of argFunc (e.g. in your main printing code) one.x is still bound to 'place_x'. HTH, Rami From mnordhoff at mattnordhoff.com Sat Nov 28 17:57:09 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Sat, 28 Nov 2009 22:57:09 +0000 Subject: Variables with cross-module usage In-Reply-To: <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> Message-ID: <4B11AAC5.50108@mattnordhoff.com> Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> ------------ >>> import one >>> import two >>> >>> def argFunc(): >>> one.x = 'place_no_x' >>> one.a = 'place_no_a' >>> one.b = 'place_no_b' >>> > > I think this is what is biting you. You might expect that after > argFunc, one.x would be set to 'place_no_x' and so on. However, > Python's scoping doesn't work like that -- the name one.x is only > rebound in the function's scope, so outside of argFunc (e.g. in your > main printing code) one.x is still bound to 'place_x'. > > HTH, > Rami Not true. argFunc does not rebind the name "one", it mutates the module object referred to by the name "one". Since there is only one instance of a given module*, the change is indeed reflected everywhere the "one" module is accessed. The problem is that argFunc does not modify (or replace) one.myList, as MRAB said. * Unless you do something strange like reload() or editing sys.modules or having module available under different names...or something. -- Matt Nordhoff From rami.chowdhury at gmail.com Sat Nov 28 18:06:11 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 28 Nov 2009 15:06:11 -0800 Subject: Variables with cross-module usage In-Reply-To: <4B11AAC5.50108@mattnordhoff.com> References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> <2f79f590911281446k4ee48c18x6a3aae31faa7331d@mail.gmail.com> <4B11AAC5.50108@mattnordhoff.com> Message-ID: <2f79f590911281506j16a66f58h2e974b39ae009787@mail.gmail.com> -------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Sat, Nov 28, 2009 at 14:57, Matt Nordhoff wrote: > Rami Chowdhury wrote: >> Hi Nitin, >> >> On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >>> Nitin Changlani. wrote: >>>> three.py >>>> ------------ >>>> import one >>>> import two >>>> >>>> def argFunc(): >>>> ? ?one.x = 'place_no_x' >>>> ? ?one.a = 'place_no_a' >>>> ? ?one.b = 'place_no_b' >>>> >> >> I think this is what is biting you. You might expect that after >> argFunc, one.x would be set to 'place_no_x' and so on. However, >> Python's scoping doesn't work like that -- the name one.x is only >> rebound in the function's scope, so outside of argFunc (e.g. in your >> main printing code) one.x is still bound to 'place_x'. >> >> HTH, >> Rami > > Not true. argFunc does not rebind the name "one", it mutates the module > object referred to by the name "one". Since there is only one instance > of a given module*, the change is indeed reflected everywhere the "one" > module is accessed. Ah, thanks for clarifying! From news123 at free.fr Sat Nov 28 18:10:45 2009 From: news123 at free.fr (News123) Date: Sun, 29 Nov 2009 00:10:45 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b097593$0$30269$426a74cc@news.free.fr> <4b0a484c$0$8915$426a34cc@news.free.fr> <4b1191f6$0$3891$426a74cc@news.free.fr> Message-ID: <4b11adf5$0$30382$426a74cc@news.free.fr> MRAB wrote: > News123 wrote: >> r wrote: >>> more *maybe useful dump? >>> >>>>>> for i in dev.Items: >>> for p in i.Properties: >>> if not p.IsReadOnly: >>> print p.Name, '->', p.Value >>> >> . . . >>> Horizontal Resolution -> 200 >>> Vertical Resolution -> 200 >>> Horizontal Start Position -> 0 >> . . . >>> Now how to set the values... hmmm? >>> > Well, according to that they /aren't/ read-only because it says: > > if not p.IsReadOnly: > ^^^ > Exactly they are NOT read only, which means they are supposed to be writable. the python code is for p in i.Properties: if not.p.ISReadOnly: # if I'm here I'm supposed to change them, but how? the C# code, which succeds changing the property is: foreach (Property prop in item.Properties){ if (prop.IsReadOnly) continue; // skip rest of loop // if property cannot // be modified // now change property if (prop.Name == "Horizontal Resolution") { IProperty iprop = (IProperty)prop; Object val = 75; iprop.set_Value(ref val); } } The main question is the correct python method to change the property prop = 300 # doesn't work as it just replaces the property with an integer prop.set_Value(res) # doesn't work as the method set_Value doesn't seem to exist > Traceback (most recent call last): > File "C:\WIA\scan_wia.py", line 41, in > image = scan_image_wia() > File "C:\WIA\scan_wia.py", line 37, in scan_image_wia > image = transferImg(dev) > File "C:\WIA\scan_wia.py", line 27, in transferImg > setImgProps(item) > File "C:\WIA\scan_wia.py", line 20, in setImgProps > prop.set_Value(res) > File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 512, in > __getattr__ > raise AttributeError("%s.%s" % (self._username_, attr)) > AttributeError: .set_Value bye N From dickinsm at gmail.com Sat Nov 28 18:14:31 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 28 Nov 2009 15:14:31 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> Message-ID: <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> On Nov 28, 8:39?pm, Tim Roberts wrote: > moijes12 wrote: > > >I know the value -0 is quite meaningless and makes little sense.But I > >was just fiddling.I am unable to figure out the below result > > >>>> -0 and True > >0 ----------> (Why is this 0 and not say True or False) > >>>> -0 and false > >0 > >>>> -0 or True > >True > > >Could someone please provide me some resources on how these operations > >take place.I'd wanna find it out myself > > Actually, there ARE computers where you might not see this result. > Virtually all of the processors on which Python runs use two's complement > arithmetic. ?In two's complement, there is no separate value called -0. ?0 > and -0 have the same bit representation. > > In one's complement, -0 and 0 have different representations. While that's true, I think the implementation of Python is such that the Python objects -0 and 0 should always be indistinguishable even on machines where the underlying architecture represents integers using ones' complement or sign-magnitude. At least that's certainly the intention: there are bits of CPython's source code that are deliberately written in convoluted ways in order to avoid the assumption of two's complement. But I have a nasty suspicion that, were Python ever unlucky enough to meet a ones' complement machine, we'd quickly find that there were many *other* bits of the source code that tacitly (and incorrectly) assumed a two's complement representation. Mark From john at castleamber.com Sat Nov 28 18:25:35 2009 From: john at castleamber.com (John Bokma) Date: 28 Nov 2009 23:25:35 GMT Subject: scanning under windows WIA with custom settings (dpi / etc ) References: <4b11adf5$0$30382$426a74cc@news.free.fr> Message-ID: News123 wrote: > MRAB wrote: >> News123 wrote: >>> r wrote: >>>> more *maybe useful dump? >>>> >>>>>>> for i in dev.Items: >>>> for p in i.Properties: >>>> if not p.IsReadOnly: >>>> print p.Name, '->', p.Value [..] > The main question is the correct python method to change the property > > prop = 300 # doesn't work as it just replaces the property with an > integer wild guess, but how about p.Value = 300 ? John From mwilson at the-wire.com Sat Nov 28 18:26:25 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 28 Nov 2009 18:26:25 -0500 Subject: Variables with cross-module usage References: <647908460911281419n7791b8b4nd353df25e50012da@mail.gmail.com> <4B11A5E8.3080700@mrabarnett.plus.com> Message-ID: Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> ------------ >>> import one >>> import two >>> >>> def argFunc(): >>> one.x = 'place_no_x' >>> one.a = 'place_no_a' >>> one.b = 'place_no_b' >>> > > I think this is what is biting you. You might expect that after > argFunc, one.x would be set to 'place_no_x' and so on. However, > Python's scoping doesn't work like that -- the name one.x is only > rebound in the function's scope, so outside of argFunc (e.g. in your > main printing code) one.x is still bound to 'place_x'. No, It's not like that. MRAB had it. The thing is, that when one.py is imported, it sets the name one.a to refer to a string 'place_a'. Then a list named one.myList is built with one.myList[0] referring to the same string as one.a . So far, so good. Then the function argFunc is called. It uses `one` as a name from its global namespace. Inside argFunc, the names one.x and one.a are rebound to different strings from the ones they started with. *But* one.myList[0] isn't touched, and still refers to 'place_x' like it always did. Mel. From dickinsm at gmail.com Sat Nov 28 18:38:09 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 28 Nov 2009 15:38:09 -0800 (PST) Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> Message-ID: On Nov 28, 11:14?pm, Mark Dickinson wrote: > While that's true, I think the implementation of Python is > such that the Python objects -0 and 0 should always be > indistinguishable even on machines where the underlying > architecture represents integers using ones' complement or > sign-magnitude. Hmm. I really should think before posting. A quick glance at int_and, int_xor and int_or in Objects/intobject.c: http://svn.python.org/view/python/trunk/Objects/intobject.c?view=markup shows that Python clearly fails to be independent of the hardware's choice of integer representation. E.g., on a ones' complement machine, Python would give: >>> -1 & 1 0 but the same operation on longs would give a different result: >>> -1L & 1L 1L Mark From alfps at start.no Sat Nov 28 18:47:00 2009 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 29 Nov 2009 00:47:00 +0100 Subject: Req. for comments section "Basic Data" in intro book Message-ID: I added a section on "basic data" to ch 2 of my writings, an introduction to programming (with Python as main language). The intended reader is someone who is intelligent and wants to learn programming but knows little or nothing about it. As before it would be nice with feedback on this. Format: PDF Current contents: 1 Getting started. 1 1.1 Python variants, implementations and distributions. 1 1.2 Download and install a Python implementation. 2 1.3 Test-drive the Python interpreter. 2 1.4 Create and run a Python console program. 4 1.5 Syntax highlighting and programmers' editors. 6 1.6 Create and run a Python GUI program. 7 1.7 About compilation. 9 1.8 About standalone Windows programs & other kinds. 10 1.9 Browse the local documentation. 11 EOT 12 2 Basic concepts. 1 2.1 Super-basic concept: why programming is not DWIM. 1 2.2 Reported errors. 4 2.2.1 Case-sensitity. 4 2.2.2 Syntax / compilation errors. 4 2.2.3 Runtime errors / crashes. 5 2.3 A programming exploration tool: turtle graphics. 6 2.4 Naming things. 8 2.4.1 Naming actions: routines. 8 2.4.2 Naming data part I: variables. 11 2.4.3 Naming data part II: routine arguments. 13 2.5 Controlling the flow of execution. 14 2.5.1 Repeating actions automatically: loops. 14 2.5.2 Basic comparisions & boolean values. 16 2.5.3 Interlude I: a function graph program / about types. 17 2.5.4 Automated action choices. 21 2.5.5 Value-producing (function-like) routines. 23 2.5.6 Interlude II: a graph with zeroes marked / about program structure. 26 2.5.7 Dynamically nested actions: recursive routines. 28 2.6 Basic data. 36 2.6.1 Basic fundamental types / strings & concatenation. 36 2.6.2 Indexing and single characters (+ vaguely about sequences in general). 39 2.6.3 Interlude III: a ROT-13 encryption/decryption program, refactoring. 40 2.6.4 Attributes, methods, objects. 43 2.6.5 Doc strings. 44 2.6.6 Interlude IV: attribute names as strings, listing str attributes. 45 2.6.7 References. 46 EOT 49 The section on "References", 2.6.7, is about references in Python, it's not a list of references. :-) Cheers, - Alf From rhodri at wildebst.demon.co.uk Sat Nov 28 19:33:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 29 Nov 2009 00:33:31 -0000 Subject: Some Basic questions on the use of CTRL and ALT Keys In-Reply-To: <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> References: <6fb6aca3-c049-46a7-8820-b755fdeb7613@u25g2000prh.googlegroups.com> <0099f4b9$0$26925$c3e8da3@news.astraweb.com> <09bc8614-b2d3-4b07-aea2-1a14d5bc745e@u25g2000prh.googlegroups.com> Message-ID: On Sat, 28 Nov 2009 07:30:00 -0000, joy99 wrote: > On Nov 28, 5:35 am, Steven D'Aprano cybersource.com.au> wrote: >> As for Alt-combinations, I don't think there is any standard for what >> they are. I believe that they are operating system specific, and >> possibly >> even program specific. > > It seems the following site: > http://knopok.net/symbol-codes/alt-codes > is quite resourceful on Alt. *If* (and it's a big if) you're using Windows. Steven's point is very much worth bearing in mind. -- Rhodri James *-* Wildebeest Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 19:58:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 00:58:27 GMT Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> Message-ID: <009b4bab$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 15:14:31 -0800, Mark Dickinson wrote: >> Actually, there ARE computers where you might not see this result. >> Virtually all of the processors on which Python runs use two's >> complement arithmetic. ?In two's complement, there is no separate value >> called -0. ?0 and -0 have the same bit representation. >> >> In one's complement, -0 and 0 have different representations. > > While that's true, I think the implementation of Python is such that the > Python objects -0 and 0 should always be indistinguishable even on > machines where the underlying architecture represents integers using > ones' complement or sign-magnitude. I don't think that really has any bearing on the Original Poster's question -- presumably on such machines, Python should treat both -0 and +0 as false in a boolean context and generate the same result. When it comes to integers, I'm not aware of any mathematical or programming system which treats -0 and +0 as distinct entities, even if they have different internal representations. But the same doesn't apply for floats, where the IEEE standard requires that -0.0 and +0.0 be distinct and distinguishable (although it also requires that they compare as equal). -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 20:05:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 01:05:22 GMT Subject: filename of calling function? References: <07ec7f72-bf20-41c7-a744-e0a3aafd54fc@z3g2000prd.googlegroups.com> Message-ID: <009b4d4a$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 08:19:02 -0800, Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > print '?' > > bb.py > import aa > > def bb(): > aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) See the inspect module: http://stefaanlippens.net/python_inspect -- Steven From news123 at free.fr Sat Nov 28 20:14:53 2009 From: news123 at free.fr (News123) Date: Sun, 29 Nov 2009 02:14:53 +0100 Subject: scanning under windows WIA with custom settings (dpi / etc ) In-Reply-To: References: <4b11adf5$0$30382$426a74cc@news.free.fr> Message-ID: <4b11cb0d$0$5766$426a74cc@news.free.fr> Hi John, John Bokma wrote: > News123 wrote: > >> MRAB wrote: >>> News123 wrote: >>>> r wrote: >>>>> more *maybe useful dump? >>>>> >>>>>>>> for i in dev.Items: >>>>> for p in i.Properties: >>>>> if not p.IsReadOnly: >>>>> print p.Name, '->', p.Value > > [..] > >> The main question is the correct python method to change the property >> >> prop = 300 # doesn't work as it just replaces the property with an >> integer > > wild guess, but how about p.Value = 300 ? > > John Wild and good guess indeed. p.Value = 300 is working. Finally I can do WIA scans and set the parameters. How could I have found this out without guessing? Or phrased differently: What would be the correct way to find out what can be done with variables returned by win32com.client s. I tried dir(prop) prop.__doc__ type(prop) and got ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__doc__', '__eq__', '__getattr__', '__getitem__', '__init__', '__int__', '__len__', '__module__', '__ne__', '__nonzero__', '__repr__', '__setattr__', '__setitem__', '__str__', '_builtMethods_', '_enum_', '_find_dispatch_type_', '_get_good_object_', '_get_good_single_object_', '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] The dynamic class used as a last resort. The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy of using the makepy generated wrapper Python class instead of dynamic.CDispatch if/when possible. and T I'd like to avoid wild guessing when being confronted with another win32.com object. Thanks again N From fearsomedragonfly at gmail.com Sat Nov 28 20:22:27 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 17:22:27 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> Message-ID: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> On Nov 28, 6:10?am, Lie Ryan wrote: > On 11/28/2009 10:38 PM, The Music Guy wrote: > > >> If you use it a lot, it is likely 1) you have abused class syntax for > >> what should have been a dict or 2) what you need is to override > >> __getattr__/__getattribute__ and __setattr__ > > > Oh boy...here we go. :| > > > > ok, then what's your use case, AFAICT in the discussion here and > previous ones, nobody has yet described a realistic and compelling > situation where setattr/getattr is the best solution. That's why the > discussion tended to end with "not used frequently enough"; simply > because nobody can turn up with a use case to justify a new syntax, > especially since all the proposed syntax are ugly (the most acceptable > one, for me, is obj.[foo], still ugly but not as ugly as the others). Alright, I'm not sure if my last message about this came through, so I'm going to assume it didn't. When I first started seeing @ show up in Python code, I said "what the heck is that? It looks so weird and _ugly_. I would never try to mess with that." But I started seeing it more and more, so I asked #python what it was. They told me about decorators, so I looked it up in the docs, and I thought the idea was interesting. It took me a while to figure out exactly how they worked--and judging from messages I've seen in #python a number of people have the same trouble understanding them. My point is that any particular syntax would look ugly to you only because you haven't seen it in use enough, and haven't used it enough yourself. But of course you haven't--it's not currently a valid syntax. However, the ugliness would seem to go away after the syntax had been in use for a while. And again, the EXACT syntax of the feature can be adjusted until its "just right". As for my specific use case, it's somewhat difficult to explain. The general idea was to isolate a pattern that I spotted repeated in several unrelated parts of my project. The pattern manifested itself as a set of 4-5 methods and/or properties on a class whose objects were designed to work in conjunction with other objects that fit a particular behavior. These other objects had methods and properties that were designed to interact with the first type of object in a similar but--how should I say--"inverted" fashion. This pattern showed up in many different classes throughout the project, and not only that, but the code was very similar. I decided to try to eliminate some of the code redundancy by creating a base class for all the classes to derive from. That didn't worked out okay for some things, but not for others. I can't remember the exact details of the problem at this point, but I believe it had to do with the keying/indexing protocol (ie. __getitem__, __setitem__, etc.). I decided to keep the base class (and have since extended it), but decided that it wasn't enough--that's when I decided to try metaclassing. After some work I managed to recreate the object-to- object relationship pattern that kept showing up everywhere, but in a generic way that allowed for the names of methods and properties that composed the pattern to vary in name and in the names that they referenced from other objects. The code worked very well, and allowed for the pattern to be added to any class by using a single, short line of code (something along the lines of __class_attr = { key: value }). Not only that, but the metaclass code itself was comprised of less than a screenful of code after docstrings and comments had been removed. However, the code was (and still is) very difficult to follow simply because of the way getters and setters had to be used to generate the methods and properties. P.s. Lie Ryan, I appreciate your response, and I will get back to you, but I want to make sure I reply under the right circumstances or I'll end up putting my foot in my mouth. ^_^ From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 20:23:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 01:23:18 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <009b517e$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 03:38:38 -0800, The Music Guy wrote: > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, frequently > the other will assume the former is not only doing things wrong, but is > doing them _blatantly_ wrong. That's because most of the time that assumption is correct. 50% of all coders are worse than average -- and in fact since the distribution of coding skill is unlikely to be normally distributed, it may very well be true that *more* than 50% of all coders are worse than average. Which means that, when faced with a coder you know nothing about except that he is trying to do something you can't understand, merely by playing the odds you have at least a 50:50 chance that he's doing something silly. The coders who hang around forums casting judgement are more likely like to better than average -- they're not just code monkeys putting in their eight hours days cranking out boilerplate code. They usually know what they're doing. They are skillful and knowledgeable -- those who aren't don't last long: they either leave, or they learn and become knowledgeable. So when people on forums suggest something is a bad idea, statistics is on their side, to say nothing of reasoned judgement. Most new ideas are bad ideas. Pure statistics again -- if an idea is any good, somebody has probably already had it, and it has become a standard tool that everyone uses. Breaking code up into subroutines is such a good idea, and nearly every programming language has some way of breaking code up into subroutines. But bad ideas keep coming up over and over again, as they're thought of, then rejected, then somebody else comes along and thinks of it again. The same old bad ideas keep being raised again and again. > I have caught myself making that very > assumption many times in the past, and I've tried hard to build up an > immunity against the impulse to make that assumption. Doing so reduces your chances of making uncommon false negatives at the cost of increasing your chances of making common false positives. Personally, I think it's a bad strategy, but that depends on just how much effort you put into giving every new idea a fair shake. > At this point, I > don't even believe in such a thing as a universal "wrong way" and a > "right way" to code that applies to every circumstance. Well duh :) > The way to solve a problem depends on the problem. Well duh again :D But there are certain "standard", common, types of problems. Most problems are just variations on other problems. Very few problems are unique. > When it comes to coding, there is not > an absolute "right" way or "wrong" way--unless we're talking about, say, > stealing closed source code without permission, or deliberately coding > in a way that will cause problems for the end user (like causing memory > clogs or buffer overflows and whatnot). There is no need for "deliberately" in that sentence. If you cause problems like buffer overflows, you're doing it wrong. It's wrong whether you did so maliciously or through ignorance. Even if you document that it is subject to this failure mode ("don't do this"), it's still wrong. Sometimes we do the wrong thing because sometimes it's more important to get a 99% solution today than a 100% solution next month, but it's still objectively buggy. > All of this can be determined through common sense. And yet I continue > to see the attitude of "my solution is the ONLY solution to your > problem, and it doesn't matter if I don't even actually understand the > problem." Not everyone does this, but it is a frequent enough occurence > to be worth noting. If I had to pull a number out of my magic bag, I > would say 4 out of 10 resposes have at least a hint of this attitude, > and 2.5/10 where it is very obvious. You say that as if it's a bad thing. I think it's a good thing -- most solutions are tried and tested, and conservatively sticking to solutions that are known to work is a successful solution: * if you write code which took a lot of effort to understand, it will take a lot of effort to maintain; * if you write code which only the creator understands, then if something happens to the creator, nobody will understand the code; * debugging is harder than writing code in the first place, so if you write the cleverest code you possibly can, then you aren't clever enough to debug it. [...] > ...and I have one last thing to say. I feel very strongly that > metaclassing is a fiercely underestimated and largely untapped source of > good coding solutions. There's a reason for that -- metaclasses are *clever*. Good solutions should be dumb enough that even the 50% of below-average coders can use them. Metaclasses are hard, and because they're hard, they're underutilized, and consequently people are unfamiliar with them. Because they're unfamiliar, that makes them even harder to understand, and so people avoid metaclasses -- a vicious circle, as you pointed out. -- Steven From fearsomedragonfly at gmail.com Sat Nov 28 20:24:09 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sat, 28 Nov 2009 17:24:09 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> Message-ID: <2d3ae8de-5108-4528-b0d6-275e8849609a@g27g2000yqn.googlegroups.com> On Nov 28, 6:10?am, Lie Ryan wrote: > On 11/28/2009 10:38 PM, The Music Guy wrote: > > >> If you use it a lot, it is likely 1) you have abused class syntax for > >> what should have been a dict or 2) what you need is to override > >> __getattr__/__getattribute__ and __setattr__ > > > Oh boy...here we go. :| > > > > ok, then what's your use case, AFAICT in the discussion here and > previous ones, nobody has yet described a realistic and compelling > situation where setattr/getattr is the best solution. That's why the > discussion tended to end with "not used frequently enough"; simply > because nobody can turn up with a use case to justify a new syntax, > especially since all the proposed syntax are ugly (the most acceptable > one, for me, is obj.[foo], still ugly but not as ugly as the others). Alright, I'm not sure if my last message about this came through, so I'm going to assume it didn't. When I first started seeing @ show up in Python code, I said "what the heck is that? It looks so weird and _ugly_. I would never try to mess with that." But I started seeing it more and more, so I asked #python what it was. They told me about decorators, so I looked it up in the docs, and I thought the idea was interesting. It took me a while to figure out exactly how they worked--and judging from messages I've seen in #python a number of people have the same trouble understanding them. My point is that any particular syntax would look ugly to you only because you haven't seen it in use enough, and haven't used it enough yourself. But of course you haven't--it's not currently a valid syntax. However, the ugliness would seem to go away after the syntax had been in use for a while. And again, the EXACT syntax of the feature can be adjusted until its "just right". As for my specific use case, it's somewhat difficult to explain. The general idea was to isolate a pattern that I spotted repeated in several unrelated parts of my project. The pattern manifested itself as a set of 4-5 methods and/or properties on a class whose objects were designed to work in conjunction with other objects that fit a particular behavior. These other objects had methods and properties that were designed to interact with the first type of object in a similar but--how should I say--"inverted" fashion. This pattern showed up in many different classes throughout the project, and not only that, but the code was very similar. I decided to try to eliminate some of the code redundancy by creating a base class for all the classes to derive from. That didn't worked out okay for some things, but not for others. I can't remember the exact details of the problem at this point, but I believe it had to do with the keying/indexing protocol (ie. __getitem__, __setitem__, etc.). I decided to keep the base class (and have since extended it), but decided that it wasn't enough--that's when I decided to try metaclassing. After some work I managed to recreate the object-to- object relationship pattern that kept showing up everywhere, but in a generic way that allowed for the names of methods and properties that composed the pattern to vary in name and in the names that they referenced from other objects. The code worked very well, and allowed for the pattern to be added to any class by using a single, short line of code (something along the lines of __class_attr = { key: value }). Not only that, but the metaclass code itself was comprised of less than a screenful of code after docstrings and comments had been removed. However, the code was (and still is) very difficult to follow simply because of the way getters and setters had to be used to generate the methods and properties. P.s. Ben Finney, I appreciate your response, and I will get back to you, but I want to make sure I reply under the right circumstances or I'll end up putting my foot in my mouth. ^_^ From dreadpiratejeff at gmail.com Sat Nov 28 21:15:24 2009 From: dreadpiratejeff at gmail.com (J) Date: Sat, 28 Nov 2009 21:15:24 -0500 Subject: slightly OT: Python BootCamp Message-ID: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> Ok... so I've been re-teaching myself python, as it's been several years since I last really used it. And in the midst of this, my contracting company came up to me on Friday and asked if I'd be interested in filling a last minute vacancy in this: http://www.otg-nc.com/python-bootcamp It's a week long Python Bootcamp. I figured, free class, a week where I'll not have to actually go to work, AND I'll get paid, sure! So I was just wondering if any of you have attended this one, or one like it, and what your impressions were. I've attended a few before, and found them widely different. The RH300, for example, was blisteringly fast and really just touches on things, so if you don't already know Red Hat inside and out, you'll never survive. The VMWare VCP courses, on the other hand, were fairly languid by contrast and seemed to flow in a less frantic state. So I figured this would be the place to ask. And if it matters, I do have an educational background in programming (VB, C++, C, Java, etc) but my professional background has mostly been limited to Bash, OCCASIONAL C, and now a touch of Python, so I am not new to programming and OO programming, just not as proficient as I would like to be... Cheers Jeff -- Jonathan Swift - "May you live every day of your life." - http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html From joost at h-labahn.de Sat Nov 28 21:32:09 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 18:32:09 -0800 (PST) Subject: Python3 - encoding issues Message-ID: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Hello, at first i must beg the pardon of those from you, whose mailboxes got flooded by my last announcement of depikt. I myself get no emails from this list, and when i had done my corrections and posted each of the sligthly improved versions, i wasn't aware of the extra emails that produces. Sorry ! I read here recently, that some reagard Python3 worse at encoding issues than former versions. For me, a German, quite the contrary is true. The automatic conversion without an Exception from before 3 has caused pain over pain during the last years. Even some weeks before it happened, that pygtk suddenly returned utf-8, not unicode, and my software had delivered a lot of muddled automatically written emails, before i saw the mess. Python 3 would have raised Exceptions - however the translation of my software to 3 has just begun. Now there is a concept of two separated worlds, and i have decided to use bytes for my software. The string representation, that output needs anyway, and with depikt and a changed apsw (file reads anyway) or other database-APIs (internally they all understand utf-8) i can get utf-8 for all input too. This means, that i do not have the standard string methods, but substitutes are easily made. Not for a subclass of bytes, that wouldn't have the b"...." initialization. Thus only in form of functions. Here are some of my utools: u0 = "".encode('utf-8') def u(s): if type(s) in (int, float, type): s = str(s) if type(s) == str: return s.encode("utf-8") if type(s) == bytes: # we keep the two worlds cleanly separated raise TypeError(b"argument is bytes already") raise TypeError(b"Bad argument for utf-encoding") def u_startswith(s, test): try: if s.index(test) == 0: return True except: # a bit frisky perhaps return False def u_endswith(s, test): if s[-len(test):] == test: return True return False def u_split(s, splitter): ret = [] while s and splitter in s: if u_startswith(s, splitter): s = s[len(splitter):]; continue ret += s[:s.index[splitter]] return ret + [s] def u_join(joiner, l): while True: if len(l) in (0,1): return l else: l = [l[0]+joiner+l[1]]+l[2:] (not all with the standard signatures). Writing them is trivial. Note u0 - unfortunately b"" doesn't at all work as expected, i had to learn the hard way. Looking more close to these functions one sees, that they only use the sequence protocol. "index" is in the sequence protocol too now - there the library reference has still to be updated. Thus all of these and much more string methods could get to the sequence protocol too without much work - then nobody would have to write all this. This doesn't only affect string-like objects: split and join for lists could open interesting possibilities for list representations of trees for example. Does anybody want to make a PEP from this (i won't do so) ? Joost Behrends From changlani.nitin at gmail.com Sat Nov 28 21:46:25 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sat, 28 Nov 2009 21:46:25 -0500 Subject: Variables with cross-module usage Message-ID: <647908460911281846n417041cagd5f1db0790e6f55c@mail.gmail.com> Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. > > > > > Hi Nitin, > > > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > >> Nitin Changlani. wrote: > >>> three.py > >>> ------------ > >>> import one > >>> import two > >>> > >>> def argFunc(): > >>> one.x = 'place_no_x' > >>> one.a = 'place_no_a' > >>> one.b = 'place_no_b' > >>> > > > > I think this is what is biting you. You might expect that after > > argFunc, one.x would be set to 'place_no_x' and so on. However, > > Python's scoping doesn't work like that -- the name one.x is only > > rebound in the function's scope, so outside of argFunc (e.g. in your > > main printing code) one.x is still bound to 'place_x'. > > No, It's not like that. MRAB had it. The thing is, that when one.py is > imported, it sets the name one.a to refer to a string 'place_a'. Then a > list named one.myList is built with one.myList[0] referring to the same > string as one.a . So far, so good. > > Then the function argFunc is called. It uses `one` as a name from its > global namespace. Inside argFunc, the names one.x and one.a are rebound to > different strings from the ones they started with. *But* one.myList[0] > isn't touched, and still refers to 'place_x' like it always did. > > Mel. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin at python.org Sat Nov 28 21:51:48 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 Nov 2009 02:51:48 +0000 (UTC) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Message-ID: DreiJane h-labahn.de> writes: > Does anybody want to make a PEP from this (i won't do so) ? I will answer this query with a little interactive prompt session: $ python3 Python 3.1.1 (r311:74480, Nov 14 2009, 13:56:40) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data = b"Good, morning" >>> data.startswith(b"Good") True >>> data.split(b", ") [b'Good', b'morning'] >>> x = data.split(b", ") >>> b", ".join(x) b'Good, morning' Bytes already have the basic string functions! From aahz at pythoncraft.com Sat Nov 28 21:56:28 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 18:56:28 -0800 Subject: slightly OT: Python BootCamp References: Message-ID: In article , J wrote: > >Ok... so I've been re-teaching myself python, as it's been several >years since I last really used it. And in the midst of this, my >contracting company came up to me on Friday and asked if I'd be >interested in filling a last minute vacancy in this: > >http://www.otg-nc.com/python-bootcamp No opinion, but just wanted to note that this is completely ON-topic for comp.lang.python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sat Nov 28 22:01:46 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 19:01:46 -0800 Subject: Python/HTML integration: phileas v0.3 released References: <6ded5cc9-5491-43d3-849c-17fcfaaec85f@k17g2000yqh.googlegroups.com> Message-ID: In article <6ded5cc9-5491-43d3-849c-17fcfaaec85f at k17g2000yqh.googlegroups.com>, papa hippo wrote: > >The prime goal of 'phileas' is to enable html code to be seamlessly >included in python code in a natural looking syntax, without resorting >to templatng language. > >see: > >http://larry.myerscough.nl/phileas_project/ Why would I want to use this instead of Quixote? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From joost at h-labahn.de Sat Nov 28 22:09:20 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 19:09:20 -0800 (PST) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> Message-ID: <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Ohhh - that's nice. But no words of that in the library reference here: http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range Still this fails: >>> a = (1,2,3,4) >>> print(a.startswith((1,2))) Traceback (most recent call last): File "", line 1, in AttributeError: 'tuple' object has no attribute 'startswith' Still methods of this kind would have a better place in the sequence protocol. From changlani.nitin at gmail.com Sat Nov 28 22:18:11 2009 From: changlani.nitin at gmail.com (Nitin Changlani) Date: Sat, 28 Nov 2009 22:18:11 -0500 Subject: Variables with cross-module usage Message-ID: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly suggest what is the correct way to go about it? Nitin. From joost at h-labahn.de Sat Nov 28 22:18:31 2009 From: joost at h-labahn.de (DreiJane) Date: Sat, 28 Nov 2009 19:18:31 -0800 (PST) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Message-ID: <97629ae3-d3e9-4024-aed8-4ebcad2bfcb0@z41g2000yqz.googlegroups.com> No, sorry, i must correct me. There is a paragraph below on the quoted site. ".index" is still under "Mutable sequence types" - but bytes are treated below. From steve at REMOVE-THIS-cybersource.com.au Sat Nov 28 22:39:56 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 03:39:56 GMT Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: <009b7185$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 17:22:27 -0800, The Music Guy wrote: > As for my specific use case, it's somewhat difficult to explain. The > general idea was to isolate a pattern that I spotted repeated in several > unrelated parts of my project. The pattern manifested itself as a set of > 4-5 methods and/or properties on a class whose objects were designed to > work in conjunction with other objects that fit a particular behavior. > These other objects had methods and properties that were designed to > interact with the first type of object in a similar but--how should I > say--"inverted" fashion. > > This pattern showed up in many different classes throughout the project, > and not only that, but the code was very similar. I decided to try to > eliminate some of the code redundancy by creating a base class for all > the classes to derive from. That didn't worked out okay for some things, > but not for others. I can't remember the exact details of the problem at > this point, but I believe it had to do with the keying/indexing protocol > (ie. __getitem__, __setitem__, etc.). I decided to keep the base class > (and have since extended it), but decided that it wasn't enough--that's > when I decided to try metaclassing. After some work I managed to > recreate the object-to- object relationship pattern that kept showing up > everywhere, but in a generic way that allowed for the names of methods > and properties that composed the pattern to vary in name and in the > names that they referenced from other objects. Removing code redundancy is all very well, but beware of turning into an architecture astronaut: http://www.joelonsoftware.com/articles/fog0000000018.html There is such a thing as over-generalisation -- if you're having to struggle to get the abstract code working abstractly enough, you're probably over-generalising. > The code worked very > well, and allowed for the pattern to be added to any class by using a > single, short line of code (something along the lines of __class_attr = > { key: value }). Not only that, but the metaclass code itself was > comprised of less than a screenful of code after docstrings and comments > had been removed. However, the code was (and still is) very difficult to > follow simply because of the way getters and setters had to be used to > generate the methods and properties. That's good evidence that you've over-generalised. -- Steven From benjamin at python.org Sat Nov 28 22:43:21 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 29 Nov 2009 03:43:21 +0000 (UTC) Subject: Python3 - encoding issues References: <16767f3a-4f7c-4f52-a056-d6a58b75b61c@j4g2000yqe.googlegroups.com> <8f280fdb-59d0-4408-9b54-4e206b155b9a@c3g2000yqd.googlegroups.com> Message-ID: DreiJane h-labahn.de> writes: > > Ohhh - that's nice. But no words of that in the library reference > here: > > http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range That's because it's here: http://docs.python.org/3.1/library/stdtypes.html#bytes-and-byte-array-methods > > Still this fails: > > >>> a = (1,2,3,4) > >>> print(a.startswith((1,2))) > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'tuple' object has no attribute 'startswith' > > Still methods of this kind would have a better place in the sequence > protocol. You are welcome to bring this idea to the python-ideas list, just know that it has a small chance of being accepted. From inhahe at gmail.com Sat Nov 28 23:06:15 2009 From: inhahe at gmail.com (inhahe) Date: Sat, 28 Nov 2009 23:06:15 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: Message-ID: i like this idea (i posted some thoughts on it in the blog, but it's not approved yet as of this writing) in short, i suggested extending the idea to make it more a) generalized, b) simple, c) intuitive, and d) flexible. so instead of just using $ for attributes, you could use it anywhere you define or reference a name. as in.. class $a: pass or $a = 1 also, you might want to do something like this b = ["zero", "one"] $b[0] = 0 but that's ambiguous, so you need some sort of grouping mechanism like for example ${b[0]} = 0 although "$(b[0]) = 0" might be just as reasonable. also maybe: b = 'bar' foo$b = 'baz' print foobar #prints baz ${b}foo = 'baz' print barfoo #prints baz $foo{b}baz = 1 print foobarbaz #prints 1 but i know that last idea is getting way into php-land and probably isn't (quote-unquote) necessary. i know a lot of people would probably hate this idea with a passion. i tend to be more liberal when it comes to adding concision and dynamicism in a language, although that could be just because it's too tempting; i.e., maybe it's only because somebody drew a line somewhere that we're coding in Python instead of K. -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Nov 28 23:29:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Nov 2009 20:29:00 -0800 Subject: Imitating "tail -f" References: <31e9dd080911212027g3c4dd0d8n9287df7dfd8177c5@mail.gmail.com> <31e9dd080911212032v46614b20j3a19ed0f52b03590@mail.gmail.com> Message-ID: In article , Matt Nordhoff wrote: >Jason Sewall wrote: >> >> FWIW, GNU tail on Linux uses inotify for tail -f: > >Some other operating systems have similar facilities, e.g. FSEvents on OS X. Having spent some time with FSEvents, I would not call it particularly similar to inotify. FSEvents only works at the directory level. Someone suggested pnotify the last time this subject came up, but I haven't had time to try it out. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From ldo at geek-central.gen.new_zealand Sat Nov 28 23:54:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 29 Nov 2009 17:54:42 +1300 Subject: Is It A Directory Message-ID: When doing recursive directory traversal, sometimes you want to follow symlinks that point at other directories, and sometimes you don?t. Here?s a routine that you can use to check whether a path specifies a directory, with the option to treat a symlink to a directory as a directory, or not: import os import stat def isdir(path, followsymlink) : """returns true iff path specifies a directory. A symlink is followed iff followsymlink.""" return stat.S_ISDIR((os.lstat, os.stat)[followsymlink](path).st_mode) #end isdir From steve at REMOVE-THIS-cybersource.com.au Sun Nov 29 01:02:41 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Nov 2009 06:02:41 GMT Subject: Variables with cross-module usage References: Message-ID: <009b92f9$0$26925$c3e8da3@news.astraweb.com> On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or > used in an expression. It doesn't come intuitively to me as to why that > should not happen. Can you kindly suggest what is the correct way to go > about it? You are confusing *names* and *objects*. The presence or absence of a module qualifier is irrelevant, so for simplicity I will avoid it. I will use ` ` quotation marks to refer to names, to avoid confusing them with strings. The Python statement a = "some text" creates a name `a` which is bound to the object "some text". myList[0] = a stores the object bound to the name `a` to the first position of myList, not the name itself. So myList[0] ends up being "some text", but it has no idea whether it came from the name `a` or somewhere else. Then when you execute: a = "different text" the name `a` is bound to the object "different text". But this doesn't affect myList[0] at all, because you're not changing the object "some text" -- strings are immutable and can't be changed. -- Steven From nad at acm.org Sun Nov 29 01:33:43 2009 From: nad at acm.org (Ned Deily) Date: Sat, 28 Nov 2009 22:33:43 -0800 Subject: need clarification on -0 References: <5369ff4e-1eed-40aa-b989-0eb2b785cd13@v15g2000prn.googlegroups.com> <4623h5t6rf8sekq0pupdo4pf4vhfl7tutk@4ax.com> <65ec63eb-abe0-42cc-9e90-d7f4c33e2ff0@m3g2000yqf.googlegroups.com> <009b4bab$0$26925$c3e8da3@news.astraweb.com> Message-ID: In article <009b4bab$0$26925$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > When it comes to integers, I'm not aware of any mathematical or > programming system which treats -0 and +0 as distinct entities, even if > they have different internal representations. A documented feature of most FORTRAN run-time libraries on the Control Data 6600/70/170 family (a one's-complement architecture cited earlier by Tim Roberts) was to convert a blank numeric input field (i.e. consisting of all space characters) to minus zero. Many programmers took advantage of that, using a test for -0 as an easy, though not 100% foolproof, test for a missing numeric value. -- Ned Deily, nad at acm.org From pok3r4life at gmail.com Sun Nov 29 02:03:34 2009 From: pok3r4life at gmail.com (Poker Player) Date: Sun, 29 Nov 2009 01:03:34 -0600 Subject: Best strategy for converting to Python Message-ID: <002b01ca70c2$11bff6c0$353fe440$@com> I have a calculator program that is written in Visual C# and I would like to convert it to python using any method possible. I am thinking I have to rewrite the GUI and use the Visual C# as I go to make sure I am doing it right but I have no idea as to how this should work when converting a program like this. I almost think I could start from scratch and write the whole thing that way but I want to make sure I do not lose any of the important functionality/features. I can provide any details needed I just don't want to jump in without some sort of guidance. Thanks, Spencer -------------- next part -------------- An HTML attachment was scrubbed... URL: From d.dalton at iinet.net.au Sun Nov 29 02:55:04 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 29 Nov 2009 18:55:04 +1100 Subject: python and vc numbers Message-ID: <20091129075503.GA25864@gwsc.vic.edu.au> Hi, I have a very simple problem, but I can't work out the answer. How do I return the current tty number in python? eg. what function/module should I use to figure out what tty my program was invoked from? Thanks -- Cheers, Dan http://members.iinet.net.au/~ddalton/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From FearsomeDragonfly at gmail.com Sun Nov 29 03:43:37 2009 From: FearsomeDragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 02:43:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> Message-ID: > > On Sat, Nov 28, 2009 at 9:39 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > > Removing code redundancy is all very well, but beware of turning into an > >> architecture astronaut: > >> > http://www.joelonsoftware.com/articles/fog0000000018.html > >> > There is such a thing as over-generalisation -- if you're having to > >> struggle to get the abstract code working abstractly enough, you're > probably over-generalising. > That's an interesting article, but I don't really understand what the author's point is. It's okay to generalize, but don't make a big fuss about it? It's okay, but don't do it anyway? I honestly can't tell. He seems to be criticizing a lot of good products (like Java), not because they are generalizations exactly, but because there is too much hype surrounding them. > Anyway, I'm not generalizing for the sake of generalizing. I'm generalizing because it appears to be a logical solution to a _specific_ problem, namely the fact that nearly identical class definition code was being repeated in several classes with only a few minor details difference. If it were a regular processing problem, a function would be created to do the repeated work, but since the redundancy occurs before any processing has occurred in the traditional sense, the redundancies have to be collected in a _different_ way. > Now that I think about it, though, Python 2.6 and above support decorators on classes (an example of generalization, by the way). The metaclass code could be moved almost verbatim to a decorator function which could then be used on classes that needed it. It would still be a mess, though. > hm...actually, inhahe's code made me realize that the metaclass could be cleaned up even more than I originally thought by the proposed syntax because it could be used for naming functions as well as attributes. ;^_^ > > > > The code worked very > >> > well, and allowed for the pattern to be added to any class by using a > >> > single, short line of code (something along the lines of __class_attr = > >> > { key: value }). Not only that, but the metaclass code itself was > >> > comprised of less than a screenful of code after docstrings and comments > >> > had been removed. However, the code was (and still is) very difficult to > >> > follow simply because of the way getters and setters had to be used to > >> > generate the methods and properties. > >> > That's good evidence that you've over-generalised. > I don't follow. Could you please be more specific? (no pun intended) -------------- next part -------------- An HTML attachment was scrubbed... URL: From n00m at narod.ru Sun Nov 29 03:56:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 00:56:16 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: My Py solution: ===================================================== import psyco psyco.full() def foo(s): n = len(s) s = s + ' ' a = [[] for i in xrange(128)] ans = 0 for i in xrange(n - 1, -1, -1): lev = 0 for st in xrange(len(a[ord(s[i])]) - 1, -1, -1): j = a[ord(s[i])][st] if (n - j <= lev): break if (s[j + lev] != s[i + lev]): continue if (s[j + lev / 2] != s[i + lev / 2]): continue k = 0 while (s[j + k] == s[i + k]): k += 1 if (k > lev): lev = k a[ord(s[i])] += [i] ans += n - i - lev return ans from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] print >> z, foo(s) print >> z, time() - t z.close() ======================================================== From pavlovevidence at gmail.com Sun Nov 29 03:57:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 00:57:21 -0800 (PST) Subject: slightly OT: Python BootCamp References: Message-ID: On Nov 28, 6:15?pm, J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. ?And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. I'm surprised they're able to fill out 5 days with intensive training on Python. :) Carl Banks From dreadpiratejeff at gmail.com Sun Nov 29 04:23:20 2009 From: dreadpiratejeff at gmail.com (J) Date: Sun, 29 Nov 2009 04:23:20 -0500 Subject: slightly OT: Python BootCamp In-Reply-To: References: Message-ID: <36dec4ff0911290123y38bf3d8fr6a8d2ae4af800cfe@mail.gmail.com> On Sun, Nov 29, 2009 at 03:57, Carl Banks wrote: > On Nov 28, 6:15?pm, J wrote: >> http://www.otg-nc.com/python-bootcamp >> >> It's a week long Python Bootcamp. > > > I'm surprised they're able to fill out 5 days with intensive training > on Python. > > :) Well, if it's anything like other similar courses I've taken over the years, the 10 minute break ever 2 hours will be more like 20 minutes, the hour lunch more like 1.5 hours, and the 8:30 to 4:00 times will be more like 8:45 to 3:15 ;) but on a serious note, your comment was why I was asking... I was trying to figure out just how much python you could teach in an assumed 40 hours... but it's also supposed to be probably 80% (arbitrary semi-educated guess) hands on coding, and if that's the case, each 30 minute project could well be 45 minutes to an hour depending on how fast people type, how familiar they are with actually properly formatting code, etc... -- Pablo Picasso - "Computers are useless. They can only give you answers." - http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html From n00m at narod.ru Sun Nov 29 04:26:23 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 01:26:23 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <0fff49e3-29ec-49fd-818e-0425ddacf71c@v30g2000yqm.googlegroups.com> This worked out in 5.28s Imo it's not that *much* slower (of course, Psyco can't help here) =================================== import itertools def subs(s): return len(set(itertools.chain( s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1)))) - 1 from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] print >> z, subs(s) print >> z, time() - t z.close() ================================================== From inhahe at gmail.com Sun Nov 29 04:42:30 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 04:42:30 -0500 Subject: Filling in a tuple from unknown size list In-Reply-To: References: Message-ID: maybe that thing in python 3 that someone mentioned is the answer, but otherwise i always think Python should admit something like this: a, b, c, *d = list i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] not that that solves the None problem, though i don't have any feature suggestions that would address that. On Fri, Nov 27, 2009 at 7:18 AM, boblatest wrote: > Hello all, > > (sorry for posting from Google. I currently don't have access to my > normal nntp account.) > > Here's my question: Given a list of onknown length, I'd like to be > able to do the following: > > (a, b, c, d, e, f) = list > > If the list has fewer items than the tuple, I'd like the remaining > tuple elements to be set to "None". If the list is longer, I'd like > the excess elements to be ignored. > > The code snippet below does what I want, I was just wondering if there > was an interesting "Pythonic" way of expressing the same thing. > > Thanks, > robert > > def iter_inf(li, n): > for i in range(n): > if i < len(li): > r = li[i] > else: > r = None > i += 1 > yield r > > > li = ['a', 'b', 'c'] > (a, b, c, d, e) = iter_inf(li, 5) > print a, b, c, d, e > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From inhahe at gmail.com Sun Nov 29 05:01:15 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 05:01:15 -0500 Subject: Filling in a tuple from unknown size list In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 4:42 AM, inhahe wrote: > maybe that thing in python 3 that someone mentioned is the answer, but > otherwise i always think Python should admit something like this: > > a, b, c, *d = list > > i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] > > not that that solves the None problem, though i don't have any feature > suggestions that would address that. > > Maybe instead of Python working this way: >>> a, b = xrange(10) Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack it should work this way: >>> a, b = xrange(10) >>> print a, b 0 1 and then they could include something in itertools that automatically fills extras with None, like Peter Otten's implementation but without having to pass it a value for the number of assignments, i.e.: a, b, c = itertools.ifill(list) with None being the default fill value, but if we wanted 1 to be, we could do a, b, c = itertools.ifill(list, 1) -------------- next part -------------- An HTML attachment was scrubbed... URL: From fearsomedragonfly at gmail.com Sun Nov 29 05:15:25 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 02:15:25 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> Message-ID: <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Okay, I'm having a really hard time telling which messages are getting on to the list and which ones aren't. Some of the messages I send show up in the comp.lang.python mirror in Google Groups, and some aren't. Others show up on the Groups mirror, but don't show up in Gmail, or show up in a different order. It seems the only way I can guarantee anything showing up on Groups is to post on Groups, but that makes it difficult because I can't see the messages in the thread that only appear in my inbox. Is there a quick fix for this, because it's getting pretty aggravating trying to figure out who heard what. I don't like mailing lists. :P From qwertzuioplkjhgfdsayxcvbnm at gmail.com Sun Nov 29 05:56:28 2009 From: qwertzuioplkjhgfdsayxcvbnm at gmail.com (fejky) Date: Sun, 29 Nov 2009 02:56:28 -0800 (PST) Subject: Simple greatest common factor script Message-ID: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Simple script that calculates greatest common factor using euclid's theorem. a = int(input("Enter a: ")) b = int(input("Enter b: ")) m = 1 while True: if m != 0: if b > a: n = b/a m = b % a print b, " : ", a, " = ", n, " i ost ", m b = m if a > b: n = a/b # line 13 m = a % b print a, " : ", b, " = ", n, " i ost ", m a = m if a == b: print "NZM(", a, ",", b, ") = ", a m = 0 else: break but when i run this script: Enter a: 12345 Enter b: 54321 54321 : 12345 = 4 i ost 4941 12345 : 4941 = 2 i ost 2463 4941 : 2463 = 2 i ost 15 2463 : 15 = 164 i ost 3 15 : 3 = 5 i ost 0 Traceback (most recent call last): File "D:\Programing\Python_2.6\math\NZM.py", line 13, in n = a/b ZeroDivisionError: integer division or modulo by zero I don't see how this script is able to divide by zero. If a and b switch places everything works ok. Thanks From patrick.just4fun at gmail.com Sun Nov 29 06:18:51 2009 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Sun, 29 Nov 2009 12:18:51 +0100 Subject: Simple greatest common factor script In-Reply-To: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> References: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Message-ID: <4B12589B.9060201@gmail.com> > I don't see how this script is able to divide by zero. If a and b > switch places everything works ok. Have a look at your if-statements. It is possible, that both your if's are executed in one loop iteration (you can check this using pdb). You may want to try elif instead. - Patrick From qwertzuioplkjhgfdsayxcvbnm at gmail.com Sun Nov 29 06:23:25 2009 From: qwertzuioplkjhgfdsayxcvbnm at gmail.com (fejky) Date: Sun, 29 Nov 2009 03:23:25 -0800 (PST) Subject: Simple greatest common factor script References: <4609edd2-3d28-45f1-955b-0df556004d3d@l13g2000yqb.googlegroups.com> Message-ID: <18ce3156-f8cb-4d35-ab59-c616332f4db0@m3g2000yqf.googlegroups.com> I have no idea how i missed that. Thanks! From inhahe at gmail.com Sun Nov 29 06:58:33 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 06:58:33 -0500 Subject: Feature request: String-inferred names In-Reply-To: <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 5:15 AM, The Music Guy wrote: > Okay, I'm having a really hard time telling which messages are getting > on to the list and which ones aren't. Some of the messages I send show > up in the comp.lang.python mirror in Google Groups, and some aren't. > Others show up on the Groups mirror, but don't show up in Gmail, or > show up in a different order. It seems the only way I can guarantee > anything showing up on Groups is to post on Groups, but that makes it > difficult because I can't see the messages in the thread that only > appear in my inbox. Is there a quick fix for this, because it's > getting pretty aggravating trying to figure out who heard what. I > don't like mailing lists. :P > -- > http://mail.python.org/mailman/listinfo/python-list > Did you say you were using gmail to post? I think mailing lists tend to have issues with gmail because it puts html in the message or something like that. Btw I recently set up this mailing list to send me a message back when I successfully posted something. oddly enough, i only remember getting one such message, so maybe none of my other messages got through. :P i think there's a way to disable html when sending a gmail message, but don't quote me on that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From inhahe at gmail.com Sun Nov 29 07:10:20 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 07:10:20 -0500 Subject: Arcane question regarding white space, editors, and code collapsing In-Reply-To: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> References: <3f502218-19d5-49dc-b1be-26a835e6d527@u7g2000yqm.googlegroups.com> Message-ID: I had this same problem with an application called Notepad++, which is a shame because I like the way it works and it's nice and tight. Now I use Komodo Edit instead, which doesn't have that problem, and has all the features of Notepad++ but just isn't as fast. Also all the colors were awful, and I realized Notepad++'s were perfect so I spent some time using GetColor! to sample every token color Notepad++ uses and configure Komodo Edit to do the same. I guess this is all irrelevant information since you don't even use a PC, but I just wanted to say that apparently this strange problem is a popular phenomenon. And that Komodo Edit is cool. On Wed, Nov 18, 2009 at 6:28 PM, Wells wrote: > I work in TextMate a lot, which I generally love, but it's code > collapsing confounds me. Essentially you have to indent blank lines to > the proper level for the current block. Then it will collapse that > section as one section. If you have simply a new line, it will see it > as a break, and not collapse, though the python interpreter doesn't > care- it only cares about lines of actual code. > > Is it... pythonic, then, to have these lines of tabs/spaces to support > code collapsing? Is it proper, improper, or irrelevant? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From yosato16 at gmail.com Sun Nov 29 07:29:17 2009 From: yosato16 at gmail.com (Yo Sato) Date: Sun, 29 Nov 2009 12:29:17 +0000 Subject: debugger on system with Python 2 and 3 Message-ID: Thanx Alan, I am using Fedora Core 11. I wanted to use emacs, rather than the full-blown IDE or entirely gui-based debugger, and that's why I was drawn to pydb in the first instance. If there's no other choice I don't mind using winpdb, but it is installed (through Yum) under Python2 library and invokes Py2 at default... Don't quite know how to adapt it to Py3 or install the right version under the right directory, yet. It seems as if some environmental variable change is necessary. On the whole it doesn't seem that there's much support in the third-party debuggers in general as yet... In the meantime I might ask if it is possible to adapt pydb (or perhaps, IDLE) for Py3. Might be just a change in a env variable or two... Yo On Fri, 27 Nov 2009 19:03:10 +0000, Alan Franzoni wrote: > On 11/27/09 6:17 PM, Yo Sato wrote: >> Hi, >> >> I am a relative newcomer to the Python language, and only write Python >> 3. Now I would very much like to a more-than-basic debugger. However it >> seems as if the fact that I have both Python 2 and 3 on the system >> complicates the matter... > > You haven't told OS which OS you're using, and what are your exact > problems, BTW I think two good debuggers for Python are winpdb/rpdb2 > (work on any platform, despite the name) and the one you get in > Eclipse+Pydev. > > You should be able to pick your platform, even though I've never tested > them in Python 3. From bearophileHUGS at lycos.com Sun Nov 29 08:07:15 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:07:15 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <0fff49e3-29ec-49fd-818e-0425ddacf71c@v30g2000yqm.googlegroups.com> Message-ID: n00m: > This worked out in 5.28s > Imo it's not that *much* slower > (of course, Psyco can't help here) There's no need of a chain here, so you can rewrite this: import itertools def subs(s): return len(set(itertools.chain( s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1)))) - 1 as: def subs(s): return len(set(s[i:j] for i in xrange(len(s)) for j in xrange(i, len(s)+1))) - 1 Psyco helps a little (about 10% on my PC) if you use it like this: from time import time import psyco; psyco.full() def main(): t = time() fin = open("input.txt") fout = open("output.txt", "w") fin.next() for line in fin: r = set() s = line.rstrip() len_s = len(s) for i in xrange(len_s): for j in xrange(i, len_s + 1): r.add(s[i : j]) print >> fout, len(r) - 1 fout.close() print time() - t main() Bye, bearophile From bearophileHUGS at lycos.com Sun Nov 29 08:12:07 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:12:07 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <6005ac23-cad7-4951-ab13-ba9097fa95df@p35g2000yqh.googlegroups.com> n00m: > My Py solution: > ... Cute. You can replace: a[ord(s[i])] += [i] With: a[ord(s[i])].append(i) If you want to micro-optimize this with Psyco may be a little faster: (lev >> 1) Than: lev // 2 But to increase speed it's usually better to reduce memory allocations. So you can try to find a way to pull this out of the function: a = [[] for i in xrange(128)] And to avoid a true append: a[ord(s[i])] += [i] (There are many ways to avoid an append. One of them is to have an already allocated list/array and just bump forward an index variable that starts from 0. This is worth doing especially when you use Psyco). Bye, bearophile From thesul1970 at googlemail.com Sun Nov 29 08:14:43 2009 From: thesul1970 at googlemail.com (Paul O'Sullivan) Date: Sun, 29 Nov 2009 05:14:43 -0800 (PST) Subject: mysqldb cursor returning type along with result ? Message-ID: Just taken to Python (2.5)and started to look at some DB cursor stuff using MySQL. Anyway, after creating a query that in MySQL that has a result set of decimals I find that the cursor in python after a fetchall() returns a tuple that contains the following :: ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal ("98.08"),), (Decimal("97.73"),)) as such : sum(result) fails with "TypeError: unsupported operand type(s) for +: 'int' and 'tuple'" How do I either get the resultset back as 'float' or convert the returned tuple to 'floats'.? Thanks, Newb. From bearophileHUGS at lycos.com Sun Nov 29 08:15:14 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 05:15:14 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> Message-ID: <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> n00m: > my home tests proved Python is a fellow fast beast of C++. > Quite unexpected (I expected Py would be by ~10 times slower). > PS > Both my codes are identical in their algorithms. > ============================= > 0.016 ? ? ? ? 0.0150001049042 ? <--- exec times Maybe in your C++ code there's something that can be improved, this is a 1:1 translation to D (V.1) language (using dlibs) and it's about 2.2 times faster than the Psyco version: http://codepad.org/MQLj0ydB Using a smarter usage of memory (that is avoiding all or most memory allocations inside all loops), the performance difference will surely grow. Bye, bearophile From inhahe at gmail.com Sun Nov 29 08:25:21 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 08:25:21 -0500 Subject: staticmethod not callable? (trying to make a Singleton metaclass..) Message-ID: I'm trying to come up with a system for singletons, where I don't have to modify anything for an individual class except to define __metaclass__ or, if possible, to inherit another class. I want it to raise an error if making a duplicate instance of a class is attempted, rather than to return the same object, because my philosophy is that if your class is a singleton and you're trying to make another instance of it then you're doing it wrong and you should probably know. Although the way I'm trying to do it could apply to either philosophy. I've seen several solutions for singletons in Python, but I don't like them, either because they require modification to each individual singleton class, or they require something after the class definition like Class = Class(), or I totally don't understand them. The novel way I've attempted to come up with is this: class Singleton(type): def __new__(meta, classname, bases, classDict): @staticmethod def nonewinst(*args, **kwargs): raise ValueError("Can't make duplicate instance of singleton " + classname) @staticmethod def newoldnew(obj): return obj oldnew = classDict.get("__new__", newoldnew) @staticmethod def newnew(obj, *args, **kwargs): o = oldnew(obj, *args, **kwargs) obj.__new__ = nonewinst return o classDict["__new__"] = newnew return type.__new__(meta, classname, bases, classDict) a little bit of experimentation revealed that apparently even functions defined within a method become class methods, so i tried making them all static methods. however, python is strange to me when it comes to methods and the self parameter. i mean i understand a function being free of the class so that the 'self' parameter doesn't mean anything in particular unless you explicitly pass it an instance. and i understand the method being bound to an object so that when it's called its self parameter is automatically sent the instance. but python seems to have this in-between mode where sometimes a function isn't particularly bound to an instance but if you try to pass the wrong kind of instance to 'self' it'll complain, which gets annoying, and i don't understand how its binding works. but anyway, the problem i'm currently having with the code might not even be related to that..because here's the error I'm getting: >>> from funcs import Singleton >>> class A: ... __metaclass__ = Singleton ... >>> b = A() Traceback (most recent call last): File "", line 1, in File "c:\python25\funcs.py", line 68, in newnew o = oldnew(obj, *args, **kwargs) TypeError: 'staticmethod' object is not callable i'm not that experienced with metaclasses, but it seems to me that something's obviously going fubar here because at that point oldnew should be the function newoldnew (since class A doesn't have a __new__ defined) which is clearly defined right there with a staticmethod decorator, and first of all, functions *should* be callable, and secondly, why is my object a 'staticmethod' object just because I used a decorator on it? it would seem it should be a function, so i tested it like this: >>> class A: ... @staticmethod ... def b(): pass ... >>> type(A.b) in that case, using @staticmethod returns a function. i have nfi why it's different in my Singleton class. oh, and thirdly, staticmethod is a decorator and decorators are callables so even given that for some mysterious reason it's a staticmethod object i don't know why it's not callable. so that's pretty confusing. can anyone clear this up for me? thanks.. ps. i'm aware of the evils of singletons and all that. short answer: I don't care. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 29 08:54:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 07:54:35 -0600 Subject: mysqldb cursor returning type along with result ? In-Reply-To: References: Message-ID: <4B127D1B.1000200@tim.thechases.com> > ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), > (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal > ("98.08"),), (Decimal("97.73"),)) > > as such : > sum(result) > fails with "TypeError: unsupported operand type(s) for +: 'int' and > 'tuple'" > > How do I either get the resultset back as 'float' or convert the > returned tuple to 'floats'.? Well, what you have is a tuple-of-tuples-of-decimals, and Sum can handle Decimal types just fine. You simply have to extract the first (only) item in each row: sum(row[0] for row in result) or sum(value for (value,) in result) whichever makes more sense to you. -tkc From n00m at narod.ru Sun Nov 29 09:10:46 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 06:10:46 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> Message-ID: <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> On Nov 29, 3:15?pm, Bearophile wrote: > Maybe in your C++ code there's something that can be improved, this is > a 1:1 translation to D (V.1) language (using dlibs) and it's about 2.2 > times faster than the Psyco version:http://codepad.org/MQLj0ydB > Using a smarter usage of memory (that is avoiding all or most memory > allocations inside all loops), the performance difference will surely > grow. Very interesting. Thanks. D code looks pretty neat. Btw D lang is among accepted langs there. Even if Py by 4x *slower* -- it's still a perfect Ok for it (C# will be much (much) slower than Python). Micro-optimizations. Of course, the best optimization would be to implement Suffix Tree: http://en.wikipedia.org/wiki/Trie Currently I hardly understand/know/read/etc its core idea. My algo is plainly stupid as soldier muddy boots. My C++ code: #include #include //#include //#include //#include #include #include #include #include using namespace std; int main() { clock_t start_time = clock(); freopen("88.txt", "rt", stdin); freopen("99.txt", "wt", stdout); int tcs; string s; cin >> tcs; while (tcs-- > 0) { cin >> s; int n = s.size(); s = s + ' '; vector< vector > a(128); int ans = 0; for (int i = n - 1; i >= 0; --i) { int lev = 0; for (int st = (int)a[s[i]].size() - 1; st >= 0; --st) { int j = a[s[i]][st]; if (n - j <= lev) break; if (s[j + lev] != s[i + lev]) continue; if (s[j + lev / 2] != s[i + lev / 2]) continue; int k = 0; while (s[j + k] == s[i + k]) ++k; if (k > lev) lev = k; } a[s[i]].push_back(i); ans += n - i - lev; } cout << ans << endl; } cout << (clock() - start_time) / CLOCKS_PER_SEC << endl; return 0; } From n00m at narod.ru Sun Nov 29 09:13:41 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 06:13:41 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: http://en.wikipedia.org/wiki/Suffix_tree Looks not very friendly appealing :-) From russandheather at gmail.com Sun Nov 29 09:25:24 2009 From: russandheather at gmail.com (Russell Warren) Date: Sun, 29 Nov 2009 06:25:24 -0800 (PST) Subject: * for generic unpacking and not just for arguments? Message-ID: Is there a reason that this is fine: >>> def f(a,b,c): ... return a+b+c ... >>> f(1, *(2,3)) 6 but the code below is not? >>> x = (3, 4) >>> (1, 2, *x) == (1, 2, 3, 4) Traceback (most recent call last): File "", line 1, in invalid syntax: , line 1, pos 8 Why does it only work when unpacking arguments for a function? Is it because the code below is preferred, and more readable? >>> x = (3, 4) >>> (1, 2) + x == (1, 2, 3, 4) True I've rooted around to see if there is an answer already and found some threads going way back to 1998 (!!), but can't find a concise answer as to why it is limited to args. I don't have a burning desire for this to work, but I just tried it unsuccessfully when building up a tuple and was mildly surprised that it didn't work, so I'm curious why. Maybe it's just that * is strictly for arguments, and trying it for generic tuple unpacking is abuse (which is down the corridor in 12A). From inhahe at gmail.com Sun Nov 29 09:36:21 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 09:36:21 -0500 Subject: Number of distinct substrings of a string [continuation] In-Reply-To: <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 9:10 AM, n00m wrote: > > Even if Py by 4x *slower* -- it's still a perfect Ok for it (C# will > be > much (much) slower than Python). > > How do you figure? As far as I know C# is many, many times faster than Python. (i was disappointed to find out that even IronPython is dozens of times slower than other .net langs) -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Sun Nov 29 09:58:57 2009 From: drobinow at gmail.com (David Robinow) Date: Sun, 29 Nov 2009 09:58:57 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <009b7185$0$26925$c3e8da3@news.astraweb.com> <9f5666fa-c65e-4db0-8162-21e303e59aee@a21g2000yqc.googlegroups.com> Message-ID: <4eb0089f0911290658p107f0c5eg2e327b85592054cc@mail.gmail.com> On Sun, Nov 29, 2009 at 6:58 AM, inhahe wrote: > Did you say you were using gmail to post? ?I think mailing lists tend to > have issues with gmail because it puts html in the message or something like > that. ?Btw I recently set up this mailing list to send me a message back > when I successfully posted something. ?oddly enough, i only remember getting > one such message, so maybe none of my other messages got through. :P > i think there's a way to disable html when sending a gmail message, but > don't quote me on that. I wasn't aware it was possible to Enable html but apparently it is. Let me know if you see any html in this post. From mwilson at the-wire.com Sun Nov 29 10:40:29 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 29 Nov 2009 10:40:29 -0500 Subject: * for generic unpacking and not just for arguments? References: Message-ID: Russell Warren wrote: > Maybe it's just that * is strictly for arguments, and trying it for > generic tuple unpacking is abuse (which is down the corridor in 12A). I'd agree with that. It's a feature of function calls, not a feature of sequence types, so that you can handle a set of function arguments as a bunch, and apply them when you want. The other function call feature that sequence types don't do is a, b, c = **{'b':3, 'c':a, 'a':c} Mel. From aahz at pythoncraft.com Sun Nov 29 10:52:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 07:52:23 -0800 Subject: python setup.py build 32-bits on x86_64 machine References: <4b08d6e9$0$28097$a729d347@news.telepac.pt> Message-ID: In article <4b08d6e9$0$28097$a729d347 at news.telepac.pt>, =?UTF-8?B?U8Opcmdpbw==?= Monteiro Basto wrote: > >I am in x86_64 arch , but I need >compile things on 32 bits. >python setup.py build Googling for "linux force 32-bit build" and similar phrases should find some useful results. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From lie.1296 at gmail.com Sun Nov 29 10:55:57 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 02:55:57 +1100 Subject: string payload expected: error In-Reply-To: References: <4b0ef5da$1@dnews.tpgi.com.au> Message-ID: <4b1299f3$1@dnews.tpgi.com.au> On 11/27/2009 8:43 PM, Ramdas wrote: > I tried with MIMEBASE but it still fails...... I changed it to > MIMEText, hoping that might trick __handletext to think its a string > Anyway that also doesn't work. > just pass the string directly to MIMEBase.set_payload: fp = open('...') msg1 = MIMEBase(maintype, subtype) msg1.set_payload(fp.read()) either that or use a more specialized subclass of MIMEBase (e.g. MIMEText). From lie.1296 at gmail.com Sun Nov 29 10:57:35 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 02:57:35 +1100 Subject: mysqldb cursor returning type along with result ? In-Reply-To: References: Message-ID: <4b129a54$1@dnews.tpgi.com.au> On 11/30/2009 12:14 AM, Paul O'Sullivan wrote: > Just taken to Python (2.5)and started to look at some DB cursor stuff > using MySQL. Anyway, after creating a query that in MySQL that has a > result set of decimals I find that the cursor in python after a > fetchall() returns a tuple that contains the following :: > > ((Decimal("101.10"),), (Decimal("99.32"),), (Decimal("97.95"),), > (Decimal("98.45"),), (Decimal("97.39"),), (Decimal("97.91"),), (Decimal > ("98.08"),), (Decimal("97.73"),)) > > as such : > sum(result) > fails with "TypeError: unsupported operand type(s) for +: 'int' and > 'tuple'" > > How do I either get the resultset back as 'float' or convert the > returned tuple to 'floats'.? I believe it returned decimal.Decimal() objects. You can do arithmetic with decimal.Decimals, so: sum(x[0] for x in result) From aahz at pythoncraft.com Sun Nov 29 10:57:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 07:57:52 -0800 Subject: xmlrpc idea for getting around the GIL References: <6214d7a20911221338l30296032y32d2d1215de57b6d@mail.gmail.com> <83303a84-a8ca-486a-8173-ef0892779f39@x16g2000vbk.googlegroups.com> <4b0b07a1$0$22159$9b622d9e@news.freenet.de> Message-ID: In article <4b0b07a1$0$22159$9b622d9e at news.freenet.de>, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: > >In any case, I don't think you'll need a multi-process solution; a >single-process multi-threading approach will do fine. Just create >*another* thread, that runs at a low priority and is allowed to block. >Run the Python interpreter in that thread (create multiple of these if >you need them). Then, use some queuing producer-consumer communication >between the high-priority thread and the low priority thread. Have the >high priority threads put requests into the queue, and the low priority >thread take them from the queue, dispatching them to Python. Make sure >you use non-blocking synchronization on the queue, or else priority >inheritance if you can get permission to do so. This is close to what I would recommend, but I would suggest that the low-priority thread make calls out to an external Python process; that way, you can have a Python worker pool of processes. Based on what I've seen posted over the years, I generally recommend against instantiating multiple interpreter instances (although I've seen some success stories, I've seen more people butting their heads against the brick wall). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From showell30 at yahoo.com Sun Nov 29 10:58:05 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 29 Nov 2009 07:58:05 -0800 (PST) Subject: slightly OT: Python BootCamp References: Message-ID: <5c045972-d7f1-42f1-a7e5-9989eb8b7c6f@s21g2000prm.googlegroups.com> On Nov 28, 6:15?pm, J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. ?And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. ?I figured, free class, a week where > I'll not have to actually go to work, AND I'll get paid, suore! > I have never been, but it seems like a no-brainer to attend. Even if the class totally sucks, which I doubt, you will also have the opportunity to network with people with similar interests. If your ONLY objective in life was to learn Python, then I would recommend just hitting the books. From n00m at narod.ru Sun Nov 29 11:00:38 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 08:00:38 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> Message-ID: <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Tested both my codes against a random string of length = 10000. =========================================== from random import choice s = '' for i in xrange(10000): s += choice(('a','b','c','d','e','f')) =========================================== C++: ~0.28s Python: ~0.48s PS I suspect that building of Suffix Tree would be a big exec.time-consuming overhead From aahz at pythoncraft.com Sun Nov 29 11:01:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 08:01:10 -0800 Subject: slightly OT: Python BootCamp References: Message-ID: In article , J wrote: >On Sun, Nov 29, 2009 at 03:57, Carl Banks wrote: >> On Nov 28, 6:15=A0pm, J wrote: >>> >>> http://www.otg-nc.com/python-bootcamp >>> >>> It's a week long Python Bootcamp. >> >> >> I'm surprised they're able to fill out 5 days with intensive training >> on Python. > >but on a serious note, your comment was why I was asking... I was >trying to figure out just how much python you could teach in an >assumed 40 hours... but it's also supposed to be probably 80% >(arbitrary semi-educated guess) hands on coding, and if that's the >case, each 30 minute project could well be 45 minutes to an hour >depending on how fast people type, how familiar they are with actually >properly formatting code, etc... There are a couple of ways you can get benefit out of this even if the class itself isn't that useful for you: * Spend time working on Python projects from your job without the pressure of being at work * Help the other people in the class learn Python, which will cement your knowledge -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aahz at pythoncraft.com Sun Nov 29 11:06:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Nov 2009 08:06:40 -0800 Subject: Implementation of Book Organization tool (Python2.[x]) References: <4b0a06b8$1@dnews.tpgi.com.au> Message-ID: In article <4b0a06b8$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > >Python dictionary is stored in memory and closing the program == >deleting the database. You can pickle dictionary; and this might be >sufficient for quick and dirty, low-volume purpose. Pickled dictionary >is the least portable solution; only python program can open a >pickled dictionary and even different versions of python may have >incompatibilities. While that last sentence is technically true, I've never seen it be an issue for this kind of application when changing versions upward. IOW, pickles from previous versions of Python can almost always be read. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From aioe.org at technicalbloke.com Sun Nov 29 11:08:24 2009 From: aioe.org at technicalbloke.com (r0g) Date: Sun, 29 Nov 2009 16:08:24 +0000 Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: r0g wrote: > r0g wrote: >> Gabriel Genellina wrote: >>> En Fri, 27 Nov 2009 22:35:36 -0300, r0g >>> escribi?: >>> >>>> gethostbyname ignores setdefaulttimeout. >>>> >>>> How big a job is it to use non-blocking sockets to write a DNS lookup >>>> function with a customisable timeout? A few lines? A few hundred? I'd > > > As usual, everything is working beautifully until I try to make it work > with windows! > > Turns out signals.SIGALRM is Unix only and I want to run on both > platforms so I have done as the docs suggested and tried to convert the > code to use threading.Timer to trigger an exception if the DNS lookup is > taking too long. Actually none of that was necessary in the end. Digging into the pydns source to debug the 30 second pause I happened across the timeout parameter! >>> result = ping.do_one( "google.com", 5 ) "" Phew, that simplifies thing a lot! :) Roger. From inhahe at gmail.com Sun Nov 29 11:09:04 2009 From: inhahe at gmail.com (inhahe) Date: Sun, 29 Nov 2009 11:09:04 -0500 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 10:40 AM, Mel wrote: > Russell Warren wrote: > >> Maybe it's just that * is strictly for arguments, and trying it for >> generic tuple unpacking is abuse (which is down the corridor in 12A). > > I'd agree with that. ?It's a feature of function calls, not a feature of > sequence types, so that you can handle a set of function arguments as a > bunch, and apply them when you want. > > The other function call feature that sequence types don't do is > > a, b, c = **{'b':3, 'c':a, 'a':c} > > > ? ? ? ?Mel. > > that's wicked i'd go for that i'd definitely go for the a, b, *c = lst syntax though From lists at cheimes.de Sun Nov 29 11:09:09 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 29 Nov 2009 17:09:09 +0100 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: Russell Warren wrote: > but the code below is not? > >>>> x = (3, 4) >>>> (1, 2, *x) == (1, 2, 3, 4) > Traceback (most recent call last): > File "", line 1, in > invalid syntax: , line 1, pos 8 > > Why does it only work when unpacking arguments for a function? Is it > because the code below is preferred, and more readable? > >>>> x = (3, 4) >>>> (1, 2) + x == (1, 2, 3, 4) > True > > I've rooted around to see if there is an answer already and found some > threads going way back to 1998 (!!), but can't find a concise answer > as to why it is limited to args. The feature is available in Python 3.x: >>> a, b, *c = 1, 2, 3, 4, 5 >>> a, b, c (1, 2, [3, 4, 5]) >>> a, *b, c = 1, 2, 3, 4, 5 >>> a, b, c (1, [2, 3, 4], 5) Christian From senhor.abrantes at gmail.com Sun Nov 29 12:03:05 2009 From: senhor.abrantes at gmail.com (joao abrantes) Date: Sun, 29 Nov 2009 17:03:05 +0000 Subject: Auto net surfing Message-ID: <880fa1d40911290903g2eadd36j67c78e2ca27e2914@mail.gmail.com> How can I make a python program that votes on certain polls ? Atm I am using ClientForm to fill forms but the polls that I found are always of the type = "hidden" and I don't know how to do it. I would also want to do a python program that would vote on a website. For example, if I go to this url http://games.top.org/ultima-online/ while I am on this site: http://www.uo.burstfire.net/ that site will win a vote... if i got to the same url but while i am on this site http://www.drw.ru/en/ the vote goes to this one. Well how can I make python give me the vote for a certain site? I don't know how this vote systems work sorry for the noob questions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From missive at hotmail.com Sun Nov 29 12:34:14 2009 From: missive at hotmail.com (Lee Harr) Date: Sun, 29 Nov 2009 22:04:14 +0430 Subject: [ANNC] pybotwar-0.7 Message-ID: pybotwar is a fun and educational game where players write computer programs to control simulated robots. http://pybotwar.googlecode.com/ pybotwar uses pybox2d for the physical simulation. It can be run in text-only mode -- useful for longer tournaments -- or use pyqt or pygame for a graphical interface and visualization of the action. pybotwar is released under GPLv3. Changes in pybotwar-0.7: ??? - pybox2d-2.0.2b1 compatibility (latest pybox2d release) ??? - decouple view modules so unused graphic modules are not required ??? - added new "pinged" sensor to detect when robot is seen by others ??? - randomize order robots are handled each tick ??? - PyQt4 interface improvements ??????? - new battle dialog to select combatants ??????? - internal text editor improvements ??????? - allow multiple open editor windows ??????? - do a few simple checks on robot programs when saving _________________________________________________________________ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010 From gagsl-py2 at yahoo.com.ar Sun Nov 29 12:58:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 29 Nov 2009 14:58:14 -0300 Subject: staticmethod not callable? (trying to make a Singleton metaclass..) References: Message-ID: En Sun, 29 Nov 2009 10:25:21 -0300, inhahe escribi?: > I'm trying to come up with a system for singletons, where I don't have to > modify anything for an individual class except to define __metaclass__ > or, > if possible, to inherit another class. > > I want it to raise an error if making a duplicate instance of a class is > attempted, rather than to return the same object, (I won't comment on the usefulness of such approach...) > class Singleton(type): > def __new__(meta, classname, bases, classDict): > @staticmethod > def nonewinst(*args, **kwargs): > raise ValueError("Can't make duplicate instance of singleton " + > classname) > @staticmethod > def newoldnew(obj): > return obj > oldnew = classDict.get("__new__", newoldnew) > @staticmethod > def newnew(obj, *args, **kwargs): > o = oldnew(obj, *args, **kwargs) > obj.__new__ = nonewinst > return o > classDict["__new__"] = newnew > return type.__new__(meta, classname, bases, classDict) __new__ is a classmethod, not a staticmethod. > a little bit of experimentation revealed that apparently even functions > defined within a method become class methods, ???????? > so i tried making them all > static methods. ???????? Why do you insist on static methods? > however, python is strange to me when it comes to methods > and the self parameter. i mean i understand a function being free of the > class so that the 'self' parameter doesn't mean anything in particular > unless you explicitly pass it an instance. and i understand the method > being bound to an object so that when it's called its self parameter is > automatically sent the instance. but python seems to have this > in-between > mode where sometimes a function isn't particularly bound to an instance > but > if you try to pass the wrong kind of instance to 'self' it'll complain, > which gets annoying, and i don't understand how its binding works. Do you mean this error? Traceback (most recent call last): File "", line 1, in TypeError: unbound method foo() must be called with X instan ce as first argument (got Y instance instead) This kind of check was removed in Python 3; ClassName.method_name yields a plain function, not an unbound method as in 2.x > but > anyway, the problem i'm currently having with the code might not even be > related to that..because here's the error I'm getting: > >>>> from funcs import Singleton >>>> class A: > ... __metaclass__ = Singleton > ... >>>> b = A() > Traceback (most recent call last): > File "", line 1, in > File "c:\python25\funcs.py", line 68, in newnew > o = oldnew(obj, *args, **kwargs) > TypeError: 'staticmethod' object is not callable That's true: instances of the staticmethod type are not callable. > i'm not that experienced with metaclasses, but it seems to me that > something's obviously going fubar here because at that point oldnew > should > be the function newoldnew (since class A doesn't have a __new__ defined) > which is clearly defined right there with a staticmethod decorator, and > first of all, functions *should* be callable, and secondly, why is my > object > a 'staticmethod' object just because I used a decorator on it? it would > seem it should be a function, so i tested it like this: > >>>> class A: > ... @staticmethod > ... def b(): pass > ... >>>> type(A.b) > > > in that case, using @staticmethod returns a function. i have nfi why > it's > different in my Singleton class. > > oh, and thirdly, staticmethod is a decorator and decorators are > callables so > even given that for some mysterious reason it's a staticmethod object i > don't know why it's not callable. so that's pretty confusing. can > anyone > clear this up for me? thanks.. staticmethod is a type: py> staticmethod Used as a decorator, it's like this: def b(): pass b = staticmethod(b) so b is an staticmethod instance. You can confirm this looking into the class: py> A.__dict__['b'] py> A.b A staticmethod instance is a descriptor; its __get__ method is invoked to resolve A.b (or getattr(A, "b")). If you retrieve it directly, you get the staticmethod object which is not callable: py> A.__dict__['b']() Traceback (most recent call last): File "", line 1, in TypeError: 'staticmethod' object is not callable Going back to your original goal, your code at the top is really a mess. I would not even use a metaclass. If you want to avoid creating more than one instance, just record the fact that you created it in the class constructor, __new__: class HardSingleton(object): "Only one instance of its subclasses may be created ever" _created = False def __new__(cls, *args, **kw): if cls._created: raise ValueError("Can't make duplicate instance of singleton %s" % cls.__name__) result = super(HardSingleton, cls).__new__(cls, *args, **kw) cls._created = True return result class A(HardSingleton): def __init__(self): print "A" s1 = A() s2 = A() -- Gabriel Genellina From russandheather at gmail.com Sun Nov 29 13:01:42 2009 From: russandheather at gmail.com (Russell Warren) Date: Sun, 29 Nov 2009 10:01:42 -0800 (PST) Subject: * for generic unpacking and not just for arguments? References: Message-ID: <039c00e7-324d-463e-84a8-fbf2bc42bb3a@x5g2000prf.googlegroups.com> On Nov 29, 11:09?am, Christian Heimes wrote: > The feature is available in Python 3.x: > > >>> a, b, *c = 1, 2, 3, 4, 5 > >>> a, b, c > (1, 2, [3, 4, 5]) > >>> a, *b, c = 1, 2, 3, 4, 5 > >>> a, b, c > > (1, [2, 3, 4], 5) Interesting... especially the recognition of how both ends work with the "a, *b, c" example. That is some funky syntax. And it goes to a list instead of a tuple now, I see. It is also the opposite of what I was considering, although I expect it goes both ways like it does for functions? The given python 3.0 example is on the LHS with * packing many-to-one while unpacking (like *args inside a function), whereas I was referring to RHS-style unpacking where * explodes/unpacks one-to-many (like passing *args _to_ a function). I've steered clear of 3.x so far, but it looks like I'll have to give it a whirl if only to avoid asking irrelevant questions! From pranny at gmail.com Sun Nov 29 13:06:49 2009 From: pranny at gmail.com (pranav) Date: Sun, 29 Nov 2009 10:06:49 -0800 (PST) Subject: Installing Python 2.5 with Python 2.6 Message-ID: <5265bdcf-cd33-4712-961f-6db9b494600b@d9g2000prh.googlegroups.com> Hi, I used to develop applications on Google AppEngine SDK (which supports Python 2.5) on my Fedora 10. I upgraded to Fedora 12 recently and it has Python 2.6. Unfortunately, some things are breaking up with the SDK. Here is the trace http://dpaste.com/hold/126668/ I had been suggested by the AppEngine guys to install Python 2.5. So i wanted to know -- is it safe to install Python 2.5 alongwith Python 2.6? How will i configure my OS to use Python 2.6 (which was there already) and the SDK to use Python 2.5, which i will install new? Any other issues/suggestions/comments anyone? From francesco.pietra at accademialucchese.it Sun Nov 29 13:12:18 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Sun, 29 Nov 2009 19:12:18 +0100 Subject: delete column content Message-ID: Hi: How to replace with blank the single-character in column 21 of a pdb file (in pdb numbering it is column 22). Attached is an incomplete exercise with slices. I am unable to get real plain text with gmail. Thanks for help francesco pietra -------------- next part -------------- A non-text attachment was scrubbed... Name: delete.label.py Type: text/x-python Size: 423 bytes Desc: not available URL: From nad at acm.org Sun Nov 29 13:12:56 2009 From: nad at acm.org (Ned Deily) Date: Sun, 29 Nov 2009 10:12:56 -0800 Subject: Filling in a tuple from unknown size list References: Message-ID: In article , inhahe wrote: > maybe that thing in python 3 that someone mentioned is the answer, but > otherwise i always think Python should admit something like this: > > a, b, c, *d = list > > i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5] Extended iterable unpacking (http://www.python.org/dev/peps/pep-3132/) is implemented in python 3. $ python3 Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a, b, c, *d = [1,2,3,4,5] >>> d [4, 5] -- Ned Deily, nad at acm.org From deets at nospam.web.de Sun Nov 29 13:27:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 29 Nov 2009 19:27:50 +0100 Subject: delete column content In-Reply-To: References: Message-ID: <7nfsp6F3lpbpvU1@mid.uni-berlin.de> Francesco Pietra schrieb: > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help Wasn't the help you already got a few days ago sufficient? Diez From pranny at gmail.com Sun Nov 29 13:28:13 2009 From: pranny at gmail.com (pranav) Date: Sun, 29 Nov 2009 10:28:13 -0800 (PST) Subject: Installing Python 2.5 with Python 2.6 References: <5265bdcf-cd33-4712-961f-6db9b494600b@d9g2000prh.googlegroups.com> Message-ID: <511263c8-319c-48c5-b7f0-d6d03bd74400@2g2000prl.googlegroups.com> On Nov 29, 11:06?pm, pranav wrote: > Hi, > I used to develop applications on Google AppEngine SDK (which supports > Python 2.5) on my Fedora 10. > I upgraded to Fedora 12 recently and it has Python 2.6. > Unfortunately, some things are breaking up with the SDK. Here is the > tracehttp://dpaste.com/hold/126668/ > I had been suggested by the ?AppEngine guys to install Python 2.5. > So i wanted to know -- ?is it safe to install Python 2.5 alongwith > Python 2.6? How will i configure my OS to use Python 2.6 (which was > there already) and the SDK to use Python 2.5, which i will install > new? > Any other issues/suggestions/comments anyone? here, http://wtanaka.com/linux/f11#python25 . this page talks about installing Python 2.5 on fedora 11. Anyone knows a similar resource for Python 2.5 on Fedora 12? From vlastimil.brom at gmail.com Sun Nov 29 13:48:54 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 29 Nov 2009 19:48:54 +0100 Subject: delete column content In-Reply-To: References: Message-ID: <9fdb569a0911291048y38e83b08oc60abb06faca24f7@mail.gmail.com> 2009/11/29 Francesco Pietra : > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help > > francesco pietra > > -- > http://mail.python.org/mailman/listinfo/python-list > > Do you mean something like >>> line="abcdefghijklmnopqrstuvwxyz" >>> line[:21]+line[22:] 'abcdefghijklmnopqrstuwxyz' ? vbr From nir at winpdb.org Sun Nov 29 14:08:02 2009 From: nir at winpdb.org (Nir) Date: Sun, 29 Nov 2009 11:08:02 -0800 (PST) Subject: debugger on system with Python 2 and 3 References: Message-ID: rpdb2 should be compatible with Python 3.x. And once you start a debugging session with rpdb2 (running with Python 3.x) you can attach to it from a winpdb instance (running with Python 2.x) On Nov 29, 2:29?pm, Yo Sato wrote: > If there's no other choice I don't mind using winpdb, but it is > installed (through Yum) under Python2 library and invokes Py2 at > default... Don't quite know how to adapt it to Py3 or install the > right version under the right directory, yet. It seems as if some > environmental variable change is necessary. On the whole it doesn't > seem that there's much support in the third-party debuggers in general > as yet... > > In the meantime I might ask if it is possible to adapt pydb (or > perhaps, IDLE) for Py3. Might be just a change in a env variable or > two... > > Yo From lie.1296 at gmail.com Sun Nov 29 14:21:44 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 06:21:44 +1100 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: <4b12ca2e$1@dnews.tpgi.com.au> On 11/30/2009 1:25 AM, Russell Warren wrote: > > Maybe it's just that * is strictly for arguments, and trying it for > generic tuple unpacking is abuse (which is down the corridor in 12A). Because (1, 2, *x) == (1, 2, 3, 4) is not tuple unpacking [!] Tuple unpacking is related with assignment, e.g.: a, b, c = 1, 2, 3 In python 3, there is the extended tuple unpacking: >>> a, b, *c = [1, 2, 3, 4, 5] >>> # a = 1; b = 2; c = [3, 4, 5] >>> a, *b, c = [1, 2, 3, 4, 5] >>> # a = 1; b = [2, 3, 4]; c = 5 If I remember correctly, the idea of (1, 2, *x) to mean (1, 2) + x has been discussed before, and rejected as well. From bblais at bryant.edu Sun Nov 29 14:34:49 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 29 Nov 2009 14:34:49 -0500 Subject: teaching python using turtle module Message-ID: Hello, I was just playing with the turtle module, and thought it was an interesting way to augment the introduction to python (I teach college students, who haven't had any programming). It's a great way to introduce functions, for-loops, and general program structures. After a bit of playing, I realized that I couldn't think of many examples which use turtle with conditional structures (if- and while- statements), or functions that return values, as opposed to "procedures" like: def square(length): forward(length) right(90) forward(length) right(90) forward(length) right(90) forward(length) right(90) If-statements could possibly be used with some sort of random behavior (if rand()<0.5 ...). Are there any other situations, using turtle, that these structures would be natural? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Nov 29 14:45:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 13:45:18 -0600 Subject: * for generic unpacking and not just for arguments? In-Reply-To: References: Message-ID: <4B12CF4E.2010203@tim.thechases.com> > The feature is available in Python 3.x: > >>>> a, b, *c = 1, 2, 3, 4, 5 >>>> a, b, c > (1, 2, [3, 4, 5]) >>>> a, *b, c = 1, 2, 3, 4, 5 >>>> a, b, c > (1, [2, 3, 4], 5) This is a nice feature of 3.x but I'm disappointed (especially in light of the move to make more things iterators/generators), that the first form unpacks and returns a list instead returning the unexhausted generator. There are times I've wanted to write something like def powers_of_n(n=2): p = 0 while True: yield n ** p p += 1 def linear(i=0, step=1): while True: yield i i += step CONST_A, CONST_B, CONST_C, *_ = linear() OPT_A, OPT_B, OPT_C, *_ = powers_of_n() because adding another CONST or OPT becomes trivial (just add it to the list of names). I currently have to do something like CONST_A, CONST_B, CONST_C = range(3) and then remember to bump up my range() parameter when I create a new value on the left. It's not bad to see here, but I often have times where N>60 constants and tweaking something in an alphabetically sorted list may require scrolling to see/remember the range() change. However, because 3.x tries to make a list out of it, this doesn't help me at all because my generator is infinite. Boo. Diez Roggisch gave me a beautiful (okay, the implementation code is a bit ugly, but the final product's simplicity achieves elegance) solution to my similar want for 2.x here: http://www.mail-archive.com/python-list at python.org/msg87022.html -tkc From victorsubervi at gmail.com Sun Nov 29 15:11:13 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 29 Nov 2009 15:11:13 -0500 Subject: Exec Statement Question Message-ID: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> Hi; I have the following line of code: exec('%s()' % table) where 'table' is a variable in a for loop that calls variables from another script. I've made it so that it only calls one variable. I know for a fact that it's calling that variable in the script because it found errors in that script. I've tried to have it return the following: print 'hi' return 'hi' It doesn't return anything. No errors are thrown because the code evaluates. I don't know how to capture the output. I would like to do something like: print exec(...) or var = exec(...) but of course those options don't work. Suggestions? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Sun Nov 29 15:39:59 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 12:39:59 -0800 Subject: The Strong Relationship between MatLab and MatPlotLib? What One Needs to Know? Message-ID: Although MatPlotLib has plenty of examples, they do not seem to cover the fundamentals like figure. It seems as though in someway this is dependent upon a user's knowledge of MatLab. Is this true, or oes MatPlotLib provide some description of how forming a figure works? From bearophileHUGS at lycos.com Sun Nov 29 16:08:40 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 13:08:40 -0800 (PST) Subject: * for generic unpacking and not just for arguments? References: Message-ID: <2a6bf3a0-54b7-4ebf-a1ef-f80f847aa325@z41g2000yqz.googlegroups.com> Christian Heimes: > The feature is available in Python 3.x: > > >>> a, b, *c = 1, 2, 3, 4, 5 Is it planned to be added to a close future Python 2.x version? I really hope the answer is positive. Bye, bearophile From marko.loparic at gmail.com Sun Nov 29 16:12:13 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 29 Nov 2009 13:12:13 -0800 (PST) Subject: Creating a local variable scope. Message-ID: Hi, On 18 Sep, 10:36, "markol... at gmail.com" wrote: > On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: > > I find several places in my code where I would like tohavea variable > > scope that is smaller than the enclosing function/class/module definition. > > This is one of the single major frustrations I have with Python and an > important source of bugs for me. Here is a typical situation Here is another bug that I just got. Twenty minutes lost to find it... class ValueColumn(AbstractColumn): def __init__(self, name, header, domain_names): if type(domain_names) != tuple: raise ValueError('a tuple of domain names must be given') for name in domain_names: if type(name) != str: raise ValueError('a tuple of domain names must be given') self.domain_names = domain_names super(ValueColumn, self).__init__(name, header) The upper class was initialized with the wrong name, because the for loop to check domain_names used "name" which is also the argument to be passed. If is an old thread but I am reopening to present real situation where this Python "feature" bothers me... Marko From bearophileHUGS at lycos.com Sun Nov 29 16:43:17 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sun, 29 Nov 2009 13:43:17 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Message-ID: n00m: > I suspect that building of Suffix Tree would > be a big exec.time-consuming overhead In C/D/C++ there are ways to allocate memory in smarter ways, using pools, arenas, stacks, freelists, etc. With that, using a compact encoding of tree nodes (there are many different tricks to reduce space used by a suffix tree), you can go fast enough. Probably a basic implementation too will suffice in many cases :-) Anyway, you may try a pure-Python2.x implementation: http://suffixtree.googlecode.com/files/suffixtree-0.1.py If you find time & will to try to use that (or similar code) to improve your Python solution to the problem 99, you can show us the code here... Bye, bearophile From changlani.nitin at gmail.com Sun Nov 29 17:06:57 2009 From: changlani.nitin at gmail.com (Nitin Changlani.) Date: Sun, 29 Nov 2009 17:06:57 -0500 Subject: Variables with cross-module usage In-Reply-To: <009b92f9$0$26925$c3e8da3@news.astraweb.com> References: <009b92f9$0$26925$c3e8da3@news.astraweb.com> Message-ID: <647908460911291406n5e5dc664wac734924b567055a@mail.gmail.com> Thanks Dennis and Steve, This explains it all! I will discard using one.a and use one.myList[0] directly, instead. I really appreciate your patience and the elaboration of the concept. Warm Regards, Nitin Changlani. On Sun, Nov 29, 2009 at 1:02 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > > > Thanks for the reply MRAB, Rami, Matt and Mel, > > > > I was assuming that since one.myList0] = one.a, the change in one.a will > > ultimately trickle down to myList[0] whenever myList[0] is printed or > > used in an expression. It doesn't come intuitively to me as to why that > > should not happen. Can you kindly suggest what is the correct way to go > > about it? > > > You are confusing *names* and *objects*. The presence or absence of a > module qualifier is irrelevant, so for simplicity I will avoid it. I will > use ` ` quotation marks to refer to names, to avoid confusing them with > strings. > > > The Python statement > > a = "some text" > > creates a name `a` which is bound to the object "some text". > > myList[0] = a > > stores the object bound to the name `a` to the first position of myList, > not the name itself. So myList[0] ends up being "some text", but it has > no idea whether it came from the name `a` or somewhere else. > > Then when you execute: > > a = "different text" > > the name `a` is bound to the object "different text". But this doesn't > affect myList[0] at all, because you're not changing the object "some > text" -- strings are immutable and can't be changed. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or used > in an expression. It doesn't come intuitively to me as to why that should > not happen. Can you kindly suggest what is the correct way to go about it? > First you understand that no common programming language behaves this way... It's not just Python. It's just more subtle in Python. In classical languages "one.myList[0]" represents a location (in this case, think of a room of file cabinets). "one" is a cabinet in the room; myList is a drawer in the cabinet; [0] is a folder in the drawer. and "a" is another drawer. In this classical language "one.myList[0] = one.a" means "open up the drawer a in cabinet one, make a COPY of what it contains, and put that copy into the [0] folder inside drawer myList in cabinet one. In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. "one" is a name attached to an object (the module). "a" is a name "inside" the object "one" which is attached to some other object, whatever it is. Similarly, "myList" is a name attached to an object (an indexed list or a keyed dictionary). "[0]" is a "name" (the index or key) into the object the name "myList" is attached to. "one.myList[0] = one.a" means "find the object with the name 'one.a' attached to it, and attach then name 'one.myList[0]' to the same object" Later, if you do "one.a = something", you say "find the object with name 'something' and attach the name 'one.a' to it" -- it is, in effect, the name that is moved from object to object -- no copy is made. -- Wulfraed Dennis Lee Bieber KD6MOG wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sun Nov 29 17:11:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 09:11:50 +1100 Subject: Creating a local variable scope. In-Reply-To: References: Message-ID: <4b12f20c@dnews.tpgi.com.au> On 11/30/2009 8:12 AM, markolopa wrote: > Hi, > > On 18 Sep, 10:36, "markol... at gmail.com" wrote: >> On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: >>> I find several places in my code where I would like tohavea variable >>> scope that is smaller than the enclosing function/class/module definition. >> >> This is one of the single major frustrations I have with Python and an >> important source of bugs for me. Here is a typical situation > > Here is another bug that I just got. Twenty minutes lost to find it... > > class ValueColumn(AbstractColumn): > def __init__(self, name, header, domain_names): > if type(domain_names) != tuple: > raise ValueError('a tuple of domain names must be given') > for name in domain_names: > if type(name) != str: > raise ValueError('a tuple of domain names must be > given') > self.domain_names = domain_names > super(ValueColumn, self).__init__(name, header) > > The upper class was initialized with the wrong name, because the for > loop to check > domain_names used "name" which is also the argument to be passed. > > If is an old thread but I am reopening to present real situation where > this Python > "feature" bothers me... > here is another bug you might have if python have an "even-more-local" scope: while True: s = raw_input("enter something: ") if s not in ('q', 'quit', 'exit'): break print s if the while block has become its own namespace; print s would generate NameError. It is one or the other, you will have problem caused by "namespace too small" or "namespace too big". Neither is better than the other, so python's two-level name resolution (global and local level) is the simplest one, is the better one. From echerlin at gmail.com Sun Nov 29 17:51:14 2009 From: echerlin at gmail.com (Edward Cherlin) Date: Sun, 29 Nov 2009 14:51:14 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 11:34, Brian Blais wrote: > Hello, > I was just playing with the turtle module, and thought it was an interesting > way to augment the introduction to python (I teach college students, who > haven't had any programming). ?It's a great way to introduce functions, > for-loops, and general program structures. If you use the Python-programmable tile in Turtle Art in Sugar, or Smalltalk in the Turtle Graphics in Etoys, it's even better. I have been doing presentations on teaching Python in elementary schools, and working on how to teach basic Computer Science ideas. You can use an if-then-else to initialize a stream in Python for the first pass, and get a value at each pass thereafter. The logic can be either in the TA or the Python. > After a bit of playing, I realized that I couldn't think of many exaples > which use turtle with conditional structures (if- and while- statements), Repeat is used much more often. but of course we can provide examples of any behavior you like. I like to use the turtle to generate sequences, where I can use a conditional to stop when the turtle would go off the screen. Fibonacci numbers, for example, or exponentials. Similarly for spirals of various types. Simple cases like those are easy to do in TA, while more complex sequences could use Python. There are several fractal examples using loops provided with Sugar on a Stick, including variations on Siepinksi constructions, and the Koch Snowflake. When I can get the code for reading the color of a dot on the screen into the programmable tile, I can program a toy Turing machine, with an array of dots as the transition table, and a line of dots as the tape. > or > functions that return values, as opposed to "procedures" like: > def square(length): > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) > ?? ?forward(length) > ?? ?right(90) Surely you mean repeat(4) forward(length) right(90) > If-statements could possibly be used with some sort of random behavior (if > rand()<0.5 ...). Drunkard's Walk. > Are there any other situations, using turtle, that these > structures would be natural? Recent versions of TA contain stack instructions: push, pop, read, clear. Your students might find it interesting to program Forth instructions in TA or Python. This has practical applications in implementing and porting virtual machines such as Parrot and the VMs in Smalltalk and I-APL. There is plenty more where this came from. You would also be welcome to adapt the Python source code for TA tiles to your environment. > thanks, > Brian Blais > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > > > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > > -- Edward Mokurai (??/???????????????/????????????? ?) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://www.earthtreasury.org/ From bblais at bryant.edu Sun Nov 29 18:14:42 2009 From: bblais at bryant.edu (Brian Blais) Date: Sun, 29 Nov 2009 18:14:42 -0500 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: <34E79EB9-242E-4F6E-B646-626A6A618932@bryant.edu> On Nov 29, 2009, at 17:51 , Edward Cherlin wrote: > If you use the Python-programmable tile in Turtle Art in Sugar, or > Smalltalk in the Turtle Graphics in Etoys, it's even better. I'll have to check this out. > sequences, where I can use a conditional to stop when the turtle would > go off the screen. ah, good idea. >> or >> functions that return values, as opposed to "procedures" like: >> def square(length): >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) > > Surely you mean > > repeat(4) > forward(length) > right(90) > surely I don't mean. :) that's not python. I'd do: def square(length): for i in range(4): forward(length) right(90) but there isn't much difference with such a simple shape. obviously, as one continued, the for-loop method would be clearer. >> If-statements could possibly be used with some sort of random >> behavior (if >> rand()<0.5 ...). > > Drunkard's Walk. > yes, that was the kind of thing I was thinking about. thanks! bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko.loparic at gmail.com Sun Nov 29 19:26:51 2009 From: marko.loparic at gmail.com (markolopa) Date: Sun, 29 Nov 2009 16:26:51 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: Hi Lie! On Nov 29, 11:11?pm, Lie Ryan wrote: > here is another bug you might have if python have an "even-more-local" > scope: > > while True: > ? ? ?s = raw_input("enter something: ") > ? ? ?if s not in ('q', 'quit', 'exit'): break > print s > > if the while block has become its own namespace; print s would generate > NameError. This bug you show is completely different, because it is not dangerous: you get the error and you realise directly how to fix it. > It is one or the other, you will have problem caused by "namespace too > small" or "namespace too big". Neither is better than the other, so > python's two-level name resolution (global and local level) is the > simplest one, is the better one. I would be much happier with the smaller namespace. To fix the code that you show I would impose s = None while True: s = raw_input("enter something: ") if s not in ('q', 'quit', 'exit'): break print s The use in a block of variables created in an inner block is (for me at least) more an exception than a rule. Less than 3 hours have passed since my last post and got yet another bug that could be prevented if Python had the functionality that other languages have to destroy variables when a block ends. Here is the code: ========= arg_columns = [] for domain in self.domains: i = self.get_column_index(column_names, domain.name) col = column_elements[i] if len(col) != len(val_column): ValueError('column %s has not the same size as the value column %s' % (column_names[i], self.name)) arg_columns.append(col) [...] value_dict = {} for i, val_str in enumerate(val_column): arg_name_row = [c[i] for c in arg_columns] args = [domain[name] for name in arg_name_row] value_dict[tuple(args)] = float(val_str) repo[self.name] = value_dict ========= The bug is corrected replacing the line args = [domain[name] for name in arg_name_row] by args = [domain[name] for name, domain in zip(arg_name_row, self.domains)] so "domain" should not exist in my namespace since I have no information associated to "domain" only to "self.domains". Python should allow me to write safe code! Antoher 15 minutes lost because of that Python "feature"... Is it only me??? Thanks for your comment! Marko From ebonak at hotmail.com Sun Nov 29 19:39:48 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 19:39:48 -0500 Subject: semantics of ** (unexpected/inconsistent?) Message-ID: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -3**2 -9 >>> x = -3 >>> x**2 9 >>> I would have expected the same result in both cases. Initially I would have expected -3**2 to yield 9, but I can accept that ** binds tighter than the unary -, but shouldn't the results be consistent regardless if I use a literal or a variable? From showell30 at yahoo.com Sun Nov 29 19:46:43 2009 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 29 Nov 2009 16:46:43 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: On Nov 29, 4:26?pm, markolopa wrote: > Less than 3 hours have passed since my last post and got yet another > bug that could be prevented if Python had the functionality that other > languages have to destroy variables when a block ends. Here is the > code: > > ========= > > arg_columns = [] > for domain in self.domains: > ? ? i = self.get_column_index(column_names, domain.name) > ? ? col = column_elements[i] > ? ? if len(col) != len(val_column): > ? ? ? ? ValueError('column %s has not the same size as the value > column %s' > ? ? ? ? ? ? ? ? ? ?% (column_names[i], self.name)) > ? ? ? ? arg_columns.append(col) > > [...] > > value_dict = {} > for i, val_str in enumerate(val_column): > ? ? arg_name_row = [c[i] for c in arg_columns] > ? ? args = [domain[name] for name in arg_name_row] > ? ? value_dict[tuple(args)] = float(val_str) > repo[self.name] = value_dict > > ========= > > The bug is corrected replacing the line > > ? ? args = [domain[name] for name in arg_name_row] > > by > > ? ? args = [domain[name] for name, domain in zip(arg_name_row, > self.domains)] > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! > > Antoher 15 minutes lost because of that Python "feature"... Is it only > me??? > I occasionally make the error you make, but I think the real problem you are having is lack of attention to detail. If name collisions are a common problem for you, consider writing shorter methods or develop the habit of using more descriptive variable names. In the code above, you could have easily cleaned up the namespace by extracting a method called get_arg_columns(). Having to spend 15 minutes tracking down a bug usually indicates that you are not being systematic in your thinking. If you are rushing too much, slow down. If you are tired, take a break. If you make the same mistake twice, commit to yourself not to make it a third time. Also, test your methods one at a time and get them rock solid before writing more code. From Brian.Mingus at Colorado.EDU Sun Nov 29 19:48:52 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sun, 29 Nov 2009 17:48:52 -0700 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> On Sun, Nov 29, 2009 at 5:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? > I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. >>> (-3)**2 9 >>> 3**2 9 >>> -3**2 -9 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Nov 29 19:50:11 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 Nov 2009 16:50:11 -0800 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>>> -3**2 > -9 > >>>> x = -3 > >>>> x**2 > 9 >>>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? _No_, because using the variable evaluates "-3" as a unit separately by itself, before the exponentiation ever occurs; it's the same as the difference between (-3)**2 and -3**2. Python is not a concatenative programming language[*]; you can't directly textually replace a variable with its value and expect to get the same result from an expression. For instance, in this case, you need to add the parentheses. Cheers, Chris -- http://blog.rebertia.com [*] http://en.wikipedia.org/wiki/Concatenative_language From ebonak at hotmail.com Sun Nov 29 19:58:06 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 19:58:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: Brian J Mingus wrote: > > > > I think you answered your own question. 3**2 comes first in the order of > operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same result if I use the literal -3 or a variable that contains -3 (x in my example). From tjreedy at udel.edu Sun Nov 29 20:00:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:00:07 -0500 Subject: Variables with cross-module usage In-Reply-To: References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Message-ID: Dennis Lee Bieber wrote: > In these languages, the names always refer to the same location. > Python confuses matters by having names that don't really refer to > location, but are attached to the objects. In everyday life and natural languages, names refer to people, other objects, roles, and only occasionally to places that can be occupied. I could claim that it is classical computer languages that confuse by restricting names to locations in a linear sequence. You are just used to the straightjacket ;-). From cjwilliams43 at gmail.com Sun Nov 29 20:03:27 2009 From: cjwilliams43 at gmail.com (Colin W.) Date: Sun, 29 Nov 2009 20:03:27 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: On 29-Nov-09 19:50 PM, Chris Rebert wrote: > On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: >> Ok, this is somewhat unexpected: >> >> Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) >> [GCC 4.3.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >> >>>>> -3**2 >> -9 >> >>>>> x = -3 >> >>>>> x**2 >> 9 >>>>> >> >> I would have expected the same result in both cases. >> >> Initially I would have expected -3**2 to yield 9, but I can accept >> that ** binds tighter than the unary -, but shouldn't the results >> be consistent regardless if I use a literal or a variable? > > _No_, because using the variable evaluates "-3" as a unit separately > by itself, before the exponentiation ever occurs; it's the same as the > difference between (-3)**2 and -3**2. > Python is not a concatenative programming language[*]; you can't > directly textually replace a variable with its value and expect to get > the same result from an expression. For instance, in this case, you > need to add the parentheses. > > Cheers, > Chris > -- > http://blog.rebertia.com > > [*] http://en.wikipedia.org/wiki/Concatenative_language See the Operator Order of Precedence: http://docs.python.org/reference/expressions.html#summary Parentheses permit the user to vary the precedence. Colin W. From martin at v.loewis.de Sun Nov 29 20:03:46 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Nov 2009 02:03:46 +0100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <4b1319f2$0$13193$9b622d9e@news.freenet.de> >> I think you answered your own question. 3**2 comes first in the order >> of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contains -3 (x in my example). There is no literal -3 in Python, only a literal (+)3, see http://docs.python.org/reference/lexical_analysis.html#integer-and-long-integer-literals So -3**2 means -(3**2) == -9. Regards, Martin From ebonak at hotmail.com Sun Nov 29 20:04:01 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 20:04:01 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: Chris Rebert wrote: > > _No_, because using the variable evaluates "-3" as a unit separately > by itself, before the exponentiation ever occurs; it's the same as the > difference between (-3)**2 and -3**2. > Python is not a concatenative programming language[*]; you can't > directly textually replace a variable with its value and expect to get > the same result from an expression. For instance, in this case, you > need to add the parentheses. > > Cheers, > Chris > -- > http://blog.rebertia.com > > [*] http://en.wikipedia.org/wiki/Concatenative_language Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. (I use the Python interpreter frequently for small calculations - otherwise I'd never have realized this) Thanks, Esmail From FearsomeDragonfly at gmail.com Sun Nov 29 20:10:00 2009 From: FearsomeDragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 19:10:00 -0600 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: It's just like in algebra. You evaluate exponents before the - which, after all, is just another way to write -1, or times-negative-one. However, a variable with a negative value is not the same as a value that is being multiplied by a negative. -3 ** 2 = (-1)(3)^(2) in algebraic terms. Exponents first, then multiplication. However, x ** 2 = (x)^(2) = (-3)^(2) regardless of the value of x which, in this case, is -3. When you multiply a negative by itself, you get a positive. In short, the ** operator appears to have a higher precedence than the - operator, based on your results. On Sun, Nov 29, 2009 at 6:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Nov 29 20:10:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:10:12 -0500 Subject: Feature request: String-inferred names In-Reply-To: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: The Music Guy wrote: > When I first started seeing @ show up in Python code, I said "what the > heck is that? For future reference, PySymbols.html at http://code.google.com/p/xploro/downloads/list answers all such symbol questions. From ben+python at benfinney.id.au Sun Nov 29 20:10:47 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 12:10:47 +1100 Subject: semantics of ** (unexpected/inconsistent?) References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <87iqcsrf54.fsf@benfinney.id.au> Esmail writes: > Brian J Mingus wrote: > > > > > > > > I think you answered your own question. 3**2 comes first in the > > order of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 > or a variable that contains -3 (x in my example). You seem to be confusing the values, which (in this case) are numbers, with their incidental representation in Python code, which is literal expressions in text. Perhaps the following dissection will help: >>> -3**2 The expression ?-3**2? is evaluated, and a single value is the result. In that expression, there are two operators: the unary-minus operator and the exponential operator. There are two values as parameters in the expression: the natural number three, and the natural number two. >>> x = -3 The expression ?-3? is evaluated, and a single value is the result. That value has an internal representation of ?the integer that is three less than zero?. It is *not* the sequence of characters that you see in the Python code; it is a number. The name ?x? is then bound to that value. >>> x**2 The expression ?x**2? is evaluated, and a single value is the result. In that expression, there is *one* operator: the exponential operator. There is no unary-minus operator in the expression. There are two values as parameters in the expression: the value referenced by the name ?x? which is the integer negative-three, and the natural number two. I hope that explains the difference in behaviour. -- \ ?I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means ?put down?.? ?Bob Newhart | Ben Finney From alfps at start.no Sun Nov 29 20:11:12 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 02:11:12 +0100 Subject: Creating a local variable scope. In-Reply-To: References: Message-ID: * markolopa: > > On 18 Sep, 10:36, "markol... at gmail.com" wrote: >> On Sep 11, 7:36 pm, Johan Gr?nqvist wrote: >>> I find several places in my code where I would like tohavea variable >>> scope that is smaller than the enclosing function/class/module definition. >> This is one of the single major frustrations I have with Python and an >> important source of bugs for me. Here is a typical situation > > Here is another bug that I just got. Twenty minutes lost to find it... > > class ValueColumn(AbstractColumn): > def __init__(self, name, header, domain_names): > if type(domain_names) != tuple: > raise ValueError('a tuple of domain names must be given') > for name in domain_names: > if type(name) != str: > raise ValueError('a tuple of domain names must be > given') > self.domain_names = domain_names > super(ValueColumn, self).__init__(name, header) > > The upper class was initialized with the wrong name, because the for > loop to check > domain_names used "name" which is also the argument to be passed. > > If is an old thread but I am reopening to present real situation where > this Python > "feature" bothers me... I think if one could somehow declare names as const (final, readonly, whatever) then that would cover the above plus much more. Cheers, - Alf From tjreedy at udel.edu Sun Nov 29 20:14:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 20:14:40 -0500 Subject: slightly OT: Python BootCamp In-Reply-To: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> References: <36dec4ff0911281815p583598i43a476bc66083e29@mail.gmail.com> Message-ID: J wrote: > Ok... so I've been re-teaching myself python, as it's been several > years since I last really used it. And in the midst of this, my > contracting company came up to me on Friday and asked if I'd be > interested in filling a last minute vacancy in this: > > http://www.otg-nc.com/python-bootcamp > > It's a week long Python Bootcamp. I figured, free class, a week where > I'll not have to actually go to work, AND I'll get paid, sure! > > So I was just wondering if any of you have attended this one, or one > like it, and what your impressions were. I've attended a few before, > and found them widely different. The RH300, for example, was > blisteringly fast and really just touches on things, so if you don't > already know Red Hat inside and out, you'll never survive. The VMWare > VCP courses, on the other hand, were fairly languid by contrast and > seemed to flow in a less frantic state. > > So I figured this would be the place to ask. > > And if it matters, I do have an educational background in programming > (VB, C++, C, Java, etc) but my professional background has mostly been > limited to Bash, OCCASIONAL C, and now a touch of Python, so I am not > new to programming and OO programming, just not as proficient as I > would like to be... The list of topics seems to cover basic + intermediate issues. If you do go, perhaps you could review it here. Same for people who have attended other Python training courses, of course. From greg.ewing at canterbury.ac.nz Sun Nov 29 20:21:54 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 30 Nov 2009 14:21:54 +1300 Subject: python and vc numbers In-Reply-To: References: Message-ID: <7ngl1gF3ml76pU1@mid.individual.net> Daniel Dalton wrote: > what function/module should > I use to figure out what tty my program was invoked from? Here's one way: % python Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen("tty").read() '/dev/ttyp1\n' -- Greg From kirby.urner at gmail.com Sun Nov 29 20:22:29 2009 From: kirby.urner at gmail.com (kirby urner) Date: Sun, 29 Nov 2009 17:22:29 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: On Sun, Nov 29, 2009 at 2:51 PM, Edward Cherlin wrote: << snip >> > Drunkard's Walk. > If our think tank (isepp.org) could have gotten permission, we'd have used that Monopoly guy (looks kinda like Planters peanut guy) randomly walking on like some chess board with a lamp post (reminds of Narnia). We don't have that kind of dough though, so just do this conceptually (conceptual art). >> Are there any other situations, using turtle, that these >> structures would be natural? > > Recent versions of TA contain stack instructions: push, pop, read, > clear. Your students might find it interesting to program Forth > instructions in TA or Python. This has practical applications in > implementing and porting virtual machines such as Parrot and the VMs > in Smalltalk and I-APL. > > There is plenty more where this came from. You would also be welcome > to adapt the Python source code for TA tiles to your environment. > I recall Alan Kay communicating Seymour Papert's sense that having "an explicit receiver" was an OK development. What he meant by that, in Smalltalk terms, is that the original Logo had what I'd call a "context turtle" in that FORWARD or RIGHT were w/r to a given Turtle one didn't need to mention explicitly, like what else could one mean? With Python and other object oriented implementations, one first gives birth to a turtle, creates an instance, as in: >>> someturtle = Turtle() That's binding a name to a turtle object (giving some turtle object a name) and then controlling said turtle through the API using dot notation against the name, e.g. someturtle.forward(10) or someturtle.right(90). What you get from this is, of course, the possibility of multiple turtles, each with its own pen color, visibility, other properties of self-hood. This gets showcased in the default demo (in Windows, just double click on turtle.py in the Lib subdirectory): http://www.flickr.com/photos/17157315 at N00/4145780784/ (using Gregor's 3.1 code just minutes ago) IronPython also has access to the .NET turtle library: http://www.flickr.com/photos/mfoord/3104991233/ (not my computer) I suppose I'm only bringing this up to (a) name drop about being in a meeting with Alan Kay (with Guido and Mark Shuttleworth among others) and (b) to remind readers that Logo and turtle art, or the art of programming with turtles, are orthogonal axes. Logo as a language has also been extended considerably, as has the richness of the environment. Some of these are commercial, proprietary offerings. Some of these feature "spatial turtles" in a "turtle tank" i.e. each turtle is more like a biplane in a WWI dogfight (Snoopy vs. Red Baron), with all those extra degrees of freedom (roll, pitch, yaw). Python's turtle module is not, repeat not, an implementation of Logo in the Python language. It's an implementation of turtle graphics on a Tk canvas in the Python language. You'll also find a turtle module in wxPython such as in PythonCard by Kevin Altis. http://pythoncard.sourceforge.net/samples/turtle.html I think Gregor is right to see turtle.py as an easy way to implement an Objects First approach, consistent with a more generic approach to math concepts (vectors, polynomials, polyhedra) as objects (types), extending the OO rubric. We teach maths as extensible type systems that advance through the invention of new types, not just as systems evolving through a progression of proved theorems from fixed axioms. Kirby >> thanks, >> Brian Blais >> -- >> Brian Blais >> bblais at bryant.edu >> http://web.bryant.edu/~bblais >> >> >> >> _______________________________________________ >> Edu-sig mailing list >> Edu-sig at python.org >> http://mail.python.org/mailman/listinfo/edu-sig >> >> > > > > -- > Edward Mokurai (??/???????????????/????????????? ?) Cherlin > Silent Thunder is my name, and Children are my nation. > The Cosmos is my dwelling place, the Truth my destination. > http://www.earthtreasury.org/ > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- >>> from mars import math http://www.wikieducator.org/Martian_Math From alfps at start.no Sun Nov 29 20:23:32 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 02:23:32 +0100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: * Esmail: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? It is. >>> -3**2 -9 >>> x = 3 >>> -x**2 -9 >>> :-) I guess you expect your expression "x**2" to somehow be evaluated as "-3**2". But x doesn't contain text, it contains an integer value that presumably (I don't know) is represented in the binary number system, so it's evaluated as "(-3)**2". If x contained text and was evaluated as such, pure text replacement, then you should be able to write 2 x and have that evaluated as "2 -x"... Cheers & hth., - Alf From mwilson at the-wire.com Sun Nov 29 20:26:47 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 29 Nov 2009 20:26:47 -0500 Subject: semantics of ** (unexpected/inconsistent?) References: Message-ID: Esmail wrote: > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > Initially I would have expected -3**2 to yield 9, but I can accept > that ** binds tighter than the unary -, but shouldn't the results > be consistent regardless if I use a literal or a variable? When you say ** binds tighter than unary -, you're also saying that -3 isn't a literal: it's an expression. Try y=3 -y**2 Mel. From ebonak at hotmail.com Sun Nov 29 20:38:09 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 29 Nov 2009 20:38:09 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. Cheers, Esmail From lie.1296 at gmail.com Sun Nov 29 20:49:40 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 12:49:40 +1100 Subject: Feature request: String-inferred names In-Reply-To: <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> Message-ID: <4b132519$1@dnews.tpgi.com.au> On 11/29/2009 12:22 PM, The Music Guy wrote: > When I first started seeing @ show up in Python code, I said "what the > heck is that? It looks so weird and _ugly_.I would never try to mess > with that." But I started seeing it more and more, so I asked #python > what it was. They told me about decorators, so I looked it up in the > docs, and I thought the idea was interesting. It took me a while to > figure out exactly how they worked--and judging from messages I've > seen in #python a number of people have the same trouble understanding > them. And we don't want a second flood of users asking about foo.$bar. > My point is that any particular syntax would look ugly to you only > because you haven't seen it in use enough, and haven't used it enough > yourself. You're absolutely right, and I have *never needed* to use the plain getattr/setattr/delattr enough to even bother considering a syntax that already looks ugly at first sight. For @decorators, everyone used it *often enough* BEFORE it turned into a syntax that the ugly syntax is justified and become "acceptable". If you can find a syntax that doesn't look ugly at first sight +0, fine by me; otherwise -1, I don't want to be forced to read an ugly syntax for a feature that I don't use often enough. It's not just the syntax, the necessity+syntax don't add up well. > But of course you haven't--it's not currently a valid > syntax. However, the ugliness would seem to go away after the syntax > had been in use for a while. And again, the EXACT syntax of the > feature can be adjusted until its "just right". In so far, your definition of adjusting only means something around "[a-zA-Z0-9_]+\.[^a-zA-Z0-9_][<{(\[]?[a-zA-Z0-9_]+[>})\]]?" that class of syntax is ugly; some are more acceptable (e.g. obj.[arg]) the old thread have spawned better alternatives than that class of syntax. > As for my specific use case, it's somewhat difficult to explain. You know that: If the implementation is hard to explain it's a bad idea. -- Zen of Python -- right? > The > general idea was to isolate a pattern that I spotted repeated in > several unrelated parts of my project. The pattern manifested itself > as a set of 4-5 methods and/or properties on a class whose objects > were designed to work in conjunction with other objects that fit a > particular behavior. These other objects had methods and properties > that were designed to interact with the first type of object in a > similar but--how should I say--"inverted" fashion. Do you mean something like this? class A(object): @property def the_b(self): return self._b @the_b def the_b(self, new_b): self._b = new_b self._b._a = self class B(object): @property def the_a(self): return self._a @the_a def the_a(self, new_a): self._a = new_a self._a._b = self am I getting you right? If not, please elaborate and give an example of what you actually meant. From lie.1296 at gmail.com Sun Nov 29 21:19:33 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 13:19:33 +1100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: Message-ID: <4b132c1b$1@dnews.tpgi.com.au> On 11/30/2009 12:38 PM, Esmail wrote: > Thanks all!! I get it now :-) > > It helped to have a number of different explanations, thanks > for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops, not the unary) * / ** for other operators I would have explicit parens. It's too much work to remember the rest of the precedence sheet. From ben+python at benfinney.id.au Sun Nov 29 21:29:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 13:29:54 +1100 Subject: semantics of ** (unexpected/inconsistent?) References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <87eingrbh9.fsf@benfinney.id.au> Lie Ryan writes: > I generally do not expect operator precedence to be reliable at all Have another read of the thread. The OP's confusion was not over operator precedence, but over how names resolve to values in expressions. -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From wolftracks at invalid.com Sun Nov 29 21:41:16 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 18:41:16 -0800 Subject: Object Not Callable, float? Message-ID: Here's an traceback error msg I get. 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\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", line 467, in ShowHistogram mean = sum(hist) TypeError: 'float' object is not callable for the code: ---------------------- sum = 0.0 avg = 0.0 nplt_bins = 32 for i in range(len(hist)): # msg = "%5d %6d\n" % (i,hist[i]) msg = "%5d %6d\n" % (i,hist[i]) sum = sum + hist[i] text.insert( END, msg ) for i in range(len(hist)): avg = avg + (i*hist[i]/sum) mean = sum(hist) <-------------- faulty line mean = mean/256.0 -------------------------end hist is a list of 256 integers. What does float have to do with this? From ben+python at benfinney.id.au Sun Nov 29 21:48:44 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 13:48:44 +1100 Subject: Object Not Callable, float? References: Message-ID: <87aay4ralv.fsf@benfinney.id.au> "W. eWatson" writes: > "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", > line 467, in ShowHistogram > mean = sum(hist) > TypeError: 'float' object is not callable It means you're calling an object of type ?float?. The line where it occurred shows that you're accessing that object through the name ?sum?, which means you've bound the name ?sum? to a float object. > for the code: > ---------------------- > sum = 0.0 Here you clobber the existing binding of ?sum?, binding it to the float value 0.0. > avg = 0.0 > nplt_bins = 32 > for i in range(len(hist)): > # msg = "%5d %6d\n" % (i,hist[i]) > msg = "%5d %6d\n" % (i,hist[i]) > sum = sum + hist[i] Here you keep re-binding the name ?sum? to new float objects of different value. > text.insert( END, msg ) > for i in range(len(hist)): > avg = avg + (i*hist[i]/sum) > > mean = sum(hist) <-------------- faulty line Here you try to call the object referenced by the name ?sum?, which is a float object. > hist is a list of 256 integers. What does float have to do with this? You explicitly bound the name ?sum? to an object of type ?float?. Solution: Choose names wisely, and if you want to use a built-in name like ?sum? for its built-in putpose, don't clobber that binding before using it. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From tuxsun1 at gmail.com Sun Nov 29 22:03:09 2009 From: tuxsun1 at gmail.com (tuxsun) Date: Sun, 29 Nov 2009 19:03:09 -0800 (PST) Subject: Noobie python shell question Message-ID: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> I've been working in the shell on and off all day, and need to see if a function I defined earlier is defined in the current shell I'm working in. Is there a shell command to get of list of functions I've defined? TIA! P.S. If it makes a difference, I'm using the shell from within IDLE, but once in a while I will use the python shell in a Bash console. From casevh at gmail.com Sun Nov 29 22:04:50 2009 From: casevh at gmail.com (casevh) Date: Sun, 29 Nov 2009 19:04:50 -0800 (PST) Subject: ANN: GMPY 1.11rc1 is available Message-ID: Everyone, I'm pleased to annouce that a new version of GMPY is available. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. GMPY 1.11rc1 is available for download from: http://code.google.com/p/gmpy/ In addition to support for Python 3.x, there are several new features in this release: - Even faster conversion to/from Python longs. - Performance improvements by reducing function overhead. - Performance improvements by improved caching. - Support for cdivmod, fdivmod, and tdivmod. - Unicode strings are accepted on Python 2.x and 3.x. - Fixed regression in GMPY 1.10 where True/False were no longer recognized. Comments on provided binaries The 32-bit Windows installers were compiled with MinGW32 using MPIR 1.3.0rc3 and will automatically recognize the CPU type and use code optimized for the CPU at runtime. The 64-bit Windows installers were compiled Microsoft's SDK compilers using MPRI 1.3.0rc3. Detailed instructions are included if you want to compile your own binary. Future plans On releasing the GIL: I have compared releasing the GIL versus the multiprocessing module and the multiprocessing module offers better and more predictable performance for embarrassingly parallel tasks than releasing the GIL. If there are requests, I can add a compile- time option to enable threading support but it is unlikely to become the default. On mutable integers: The performance advantages of mutable integers appears to be 20% to 30% for some operations. I plan to add a new mutable integer type in the next release of GMPY. If you want to experiment with mutable integers now, GMPY can be compiled with mutable version of the standard 'mpz' type. Please see the file "mutable_mpz.txt" for more information. Please report any issues! casevh From davea at ieee.org Sun Nov 29 22:23:15 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 22:23:15 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> Message-ID: <4B133AA3.4060405@ieee.org> Victor Subervi wrote: > Hi; > I have the following line of code: > > exec('%s()' % table) > > where 'table' is a variable in a for loop that calls variables from another > script. I've made it so that it only calls one variable. I know for a fact > that it's calling that variable in the script because it found errors in > that script. I've tried to have it return the following: > > print 'hi' > return 'hi' > > It doesn't return anything. No errors are thrown because the code evaluates. > I don't know how to capture the output. I would like to do something like: > > print exec(...) > > or > > var = exec(...) > > but of course those options don't work. Suggestions? > TIA, > Victor > > exec is a statement, and statements don't have "return values." It's not a function, so there are no parentheses in its syntax, either. exec is also a technique of last resort; there's nearly always a better/safer/faster way to accomplish what you might want, but of course you don't say what that is. As for "returning" values, exec by default uses the same global space as your app, so you can just modify a global variable in your "called" code and use it afterwards. abc = 42 value = 12 exec "abc = %d" % value print abc DaveA From davea at ieee.org Sun Nov 29 22:46:42 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 22:46:42 -0500 Subject: Creating a local variable scope. In-Reply-To: References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <4B134022.1070508@ieee.org> markolopa wrote: > > ======= > > arg_columns =] > for domain in self.domains: > i =elf.get_column_index(column_names, domain.name) > col =olumn_elements[i] > if len(col) !=en(val_column): > ValueError('column %s has not the same size as the value > column %s' > % (column_names[i], self.name)) > arg_columns.append(col) > > [...] > > value_dict =} > for i, val_str in enumerate(val_column): > arg_name_row =c[i] for c in arg_columns] > args =domain[name] for name in arg_name_row] > value_dict[tuple(args)] =loat(val_str) > repo[self.name] =alue_dict > > ======= > > The bug is corrected replacing the line > > args =domain[name] for name in arg_name_row] > > by > > args =domain[name] for name, domain in zip(arg_name_row, > self.domains)] > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! > > Antoher 15 minutes lost because of that Python "feature"... Is it only > me??? > > Yep, I think so. You're proposing a much more complex scoping rule, where if a variable already exists before entering a loop, then the loop uses that existing variable, but if not, it creates its own local one and destroys it when exiting the loop. That's the exact opposite of what function definitions do, which already makes it confusing. I think if you had your wish, you'd find that you had more exceptions where you had to pre-declare things, than the times when you avoided the bugs you describe. I don't like languages that make me write extra stuff 100 times, to save one instance of extra debugging. If Python already required declarations, then I might buy your arguments. But it wouldn't be Python. > Thanks for your comment! > Marko > > In your particular case, the compiler couldn't guess whether you used the first loop to decide which domain to use in the second loop, or whether you accidentally reused the same name without giving it a new value in the new loop. If you need to use the same name, you could always follow your loops with the del statement to invalidate the name. DaveA From pavlovevidence at gmail.com Sun Nov 29 22:52:44 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 19:52:44 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> Message-ID: <3de04434-55a6-4d49-a716-3e8200d5a1f4@13g2000prl.googlegroups.com> On Nov 26, 3:43?pm, The Music Guy wrote: > That aside, I still feel that a new syntax would be a better solution > than a new class. And, anyway, what I'm proposing isn't *quite* the > same as what Ben North proposed. Ben's idea was *strictly* to create > shorthand syntax to the getattr/setattr/delattr in the context of > specific objects. What I'm suggesting could be more accurately > described as a namespace-neutral transformation of the value of an > expression into a name. So if "bar" is the value of foo, then when the > interpreter sees ?$foo, it reads bar. This transformation isn't possible in Python. Python has seperate compile and run times, and the value of a variable (like foo) isn't known at compile time, but it would have to be known at compile time for the interpreter to "see" the value of that variable ("bar" in this example). Therefore, to get the effect you want, the evaluation of foo would have to be delayed until run time. The interpreter would "see" $foo, and explicitly change it to bar. But that leads to another problem. Local variables (in CPython at least) are converted to index lookups during the compile phase, for efficiency reasons. Python doesn't use the name of a the local variable at run time at all, and you can't dynamically create local variables. Thus, to use your syntax proposal with local variables you would have to accept two concessions: 1. You could not use $foo to dynamically create a new local variable; foo would have to evaluate to the name of a local variable that already exists. 2. You would take a significant performance hit. Furthermore, this would introduce a bad analogical inconsistency into the language. If you can write foo.$bar=1 to create a new attribute, you'd expect to be able to write $bar=1 to create a new local variable, but you can't. These issues are significant, and given that a proposal for just computed attributes that didn't have these issues was already rejected, I would say your proposal would have absolutely no chance, even if there hadn't been a moratorium on new syntax. Carl Banks From python.list at tim.thechases.com Sun Nov 29 22:53:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 29 Nov 2009 21:53:30 -0600 Subject: Noobie python shell question In-Reply-To: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: <4B1341BA.7060607@tim.thechases.com> tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? yesish...you can use dir() from the prompt to see the bound names in a given scope: >>> dir() ['__builtins__', '__doc__', '__name__'] >>> def hello(who='world'): ... print "Hello, %s" % who ... >>> dir() ['__builtins__', '__doc__', '__name__', 'hello'] >>> x = 42 >>> dir() ['__builtins__', '__doc__', '__name__', 'hello', 'x'] however AFAIK, there's no readily accessible way to get the *definition* of that function back (other than scrolling back through your buffer or readline history) and it takes a bit more work to determine whether it's a callable function, or some other data-type. >>> callable(x) False >>> callable(hello) True (as an aside, is there a way to get a local/global variable from a string like one can fetch a variable from a class/object with getattr()? Something like getattr(magic_namespace_here, "hello") used in the above context? I know it can be done with eval(), but that's generally considered unsafe unless you vet your input thoroughly) -tkc From pavlovevidence at gmail.com Sun Nov 29 22:59:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 19:59:52 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> On Nov 28, 3:38?am, The Music Guy wrote: > On Nov 28, 3:07?am, Lie Ryan wrote: > > If you use it a lot, it is likely 1) you have abused class syntax for > > what should have been a dict or 2) what you need is to override > > __getattr__/__getattribute__ and __setattr__ > > Oh boy...here we go. :| > > Please listen. In all the time I've spent in the coding community > (that's at least 7 years) and especially since I started paying > attention to the Python community (2 years), I have noticed a trend: > When one coder does something that another cannot understand, > frequently the other will assume the former is not only doing things > wrong, but is doing them _blatantly_ wrong. I have caught myself > making that very assumption many times in the past, and I've tried > hard to build up an immunity against the impulse to make that > assumption. At this point, I don't even believe in such a thing as a > universal "wrong way" and a "right way" to code that applies to every > circumstance. The way to solve a problem depends on the problem. When > it comes to coding, there is not an absolute "right" way or "wrong" > way--unless we're talking about, say, stealing closed source code > without permission, or deliberately coding in a way that will cause > problems for the end user (like causing memory clogs or buffer > overflows and whatnot). > > All of this can be determined through common sense. Another thing that can be determined through common sense is that if you have object that you are calling getattr and setattr on so much that you think you need special syntax, you should have been using a dict. Carl Banks From FearsomeDragonfly at gmail.com Sun Nov 29 23:04:37 2009 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Sun, 29 Nov 2009 22:04:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: <4b132519$1@dnews.tpgi.com.au> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b1113ad$1@dnews.tpgi.com.au> <152363f1-507c-495a-b55c-ee7882946cea@j4g2000yqe.googlegroups.com> <4b132519$1@dnews.tpgi.com.au> Message-ID: On Sun, Nov 29, 2009 at 7:49 PM, Lie Ryan wrote: > On 11/29/2009 12:22 PM, The Music Guy wrote: > >> When I first started seeing @ show up in Python code, I said "what the >> heck is that? It looks so weird and _ugly_.I would never try to mess >> with that." But I started seeing it more and more, so I asked #python >> what it was. They told me about decorators, so I looked it up in the >> docs, and I thought the idea was interesting. It took me a while to >> figure out exactly how they worked--and judging from messages I've >> seen in #python a number of people have the same trouble understanding >> them. >> > > And we don't want a second flood of users asking about foo.$bar. > > > My point is that any particular syntax would look ugly to you only >> because you haven't seen it in use enough, and haven't used it enough >> yourself. >> > > You're absolutely right, and I have *never needed* to use the plain > getattr/setattr/delattr enough to even bother considering a syntax that > already looks ugly at first sight. For @decorators, everyone used it *often > enough* BEFORE it turned into a syntax that the ugly syntax is justified and > become "acceptable". If you can find a syntax that doesn't look ugly at > first sight +0, fine by me; otherwise -1, I don't want to be forced to read > an ugly syntax for a feature that I don't use often enough. It's not just > the syntax, the necessity+syntax don't add up well. > > > > But of course you haven't--it's not currently a valid > >> syntax. However, the ugliness would seem to go away after the syntax >> had been in use for a while. And again, the EXACT syntax of the >> feature can be adjusted until its "just right". >> > > In so far, your definition of adjusting only means something around > "[a-zA-Z0-9_]+\.[^a-zA-Z0-9_][<{(\[]?[a-zA-Z0-9_]+[>})\]]?" > that class of syntax is ugly; some are more acceptable (e.g. obj.[arg]) the > old thread have spawned better alternatives than that class of syntax. > > As for my specific use case, it's somewhat difficult to explain. >> > > You know that: > If the implementation is hard to explain it's a bad idea. > -- Zen of Python -- > > right? > > > > The > >> general idea was to isolate a pattern that I spotted repeated in >> several unrelated parts of my project. The pattern manifested itself >> as a set of 4-5 methods and/or properties on a class whose objects >> were designed to work in conjunction with other objects that fit a >> particular behavior. These other objects had methods and properties >> that were designed to interact with the first type of object in a >> similar but--how should I say--"inverted" fashion. >> > > Do you mean something like this? > > class A(object): > @property > def the_b(self): > return self._b > @the_b > def the_b(self, new_b): > self._b = new_b > self._b._a = self > > class B(object): > @property > def the_a(self): > return self._a > @the_a > def the_a(self, new_a): > self._a = new_a > self._a._b = self > > am I getting you right? If not, please elaborate and give an example of > what you actually meant. > > -- > http://mail.python.org/mailman/listinfo/python-list > I understand that in all likelyhood this feature won't be added to Python anytime soon, if at all. But I'd like to continue this discussion anyway; it's been enlightening for me. Even though I don't agree with the views of some of the people who've replied, I like the insight. And anyway, I think that if the syntax were already present, people would feel a lot more positively about it; it's the idea of adding it in so late in the game that people seem to have a problem with for the most part. It doesn't seem like anybody besides inhahe has actually realized that my proposition is actually different than PEP 363 in a subtle but crucial way. It's not _literally_ a shorthand for accessing the *attr functions; that's just the way I originally assumed it would be used most often. However, I have since realized that the syntax is more powerful than I originally thought: ANYWHERE that a name appeared--this includes function names, class names, function parameters, possibly even module names--could be replaced by an expression that would be evaluated to the name. That makes the use of any kind of brackets, except maybe , bad options, as it would conflict with [lists,] {dicts,} (tuples,) or generic parenthesized (expressions). There must be a unique indicator of some kind, something that isn't already in use by the interpreter. That way there is no possible way that it could get confused with another syntactical construct. So you could do something like this: def class_factory(this, that) get_that = "get_"+that set_that = "set_"+that _that = "_" + that class $this (object): def __init__(self, $that = None): self.$_that = $that def $get_that (self): return self.$_that def $set_that (self, $that): self.$_that = $that $that = property($get_that, $set_that) return $this Compare the code above with this approximation that uses the current syntax rules: def class_factory(this, that): get_that_name = "get_"+that set_that_name = "set_"+that _that = "_" + that class This(object): def __init__(self, that = None): setattr(self, _that, that) This.__name__ = this def get_that(self, that): return getattr(self, _that) get_that.__name__ = get_that_name setattr(This, get_that_name, get_that.__get__(None, This)) def set_that(self, that): setattr(self, _that, that) set_that.__name__ = set_that_name setattr(This, set_that_name, set_that.__get__(None, This)) setattr(This, that, property(get_that, set_that)) return This Given either of the two class factories above, the following can be done: Spam = new_foo_class("Spam", "eggs") Eggs = new_foo_class("Eggs", "spam") myspam = Spam() myeggs = Eggs() myeggs.spam = myspam myspam.set_eggs( myeggs ) print myspam.get_eggs() # prints "" print myeggs._spam # prints "" However, the following can only be done using the first example: myspam.set_eggs( eggs = myeggs ) For the second example, it would have to be this: myspam.set_eggs( that = myeggs ) The reason is that the parameter names for the first example are determined dynamically, which I don't think python allows you to do currently. The closest thing is **kwargs, but that's less readable than an actual parameter name. That was a relatively simple example; classes as simple as the ones generated by the It is more likely that the class generation could would appear in a metaclass's class constructor or decorator function, and there would be more than just the three attributes given. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Sun Nov 29 23:08:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 23:08:19 -0500 Subject: Noobie python shell question In-Reply-To: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: <4B134533.1060103@ieee.org> tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? > > TIA! > > P.S. If it makes a difference, I'm using the shell from within IDLE, > but once in a while I will use the python shell in a Bash console. > > > dir() is the answer to the question you ask. It'll display the entire global context. But usually there's a better way. If you think you previously defined a function def myfunc() .... just enter myfunc at the prompt (without parentheses). It should tell you it's a function, or undefined. DaveA From mrjean1 at gmail.com Sun Nov 29 23:12:05 2009 From: mrjean1 at gmail.com (MrJean1) Date: Sun, 29 Nov 2009 20:12:05 -0800 (PST) Subject: Best strategy for overcoming excessive gethostbyname timeout. References: Message-ID: <8e74b9ad-5b1f-48e1-bce0-22235ee68f2f@p36g2000vbn.googlegroups.com> Take a look at function timelimited in this recipe /Jean On Nov 29, 8:08?am, r0g wrote: > r0g wrote: > > r0g wrote: > >> Gabriel Genellina wrote: > >>> En Fri, 27 Nov 2009 22:35:36 -0300, r0g > >>> escribi?: > > >>>> gethostbyname ignores setdefaulttimeout. > > >>>> How big a job is it to use non-blocking sockets to write a DNS lookup > >>>> function with a customisable timeout? A few lines? A few hundred? I'd > > > > > As usual, everything is working beautifully until I try to make it work > > with windows! > > > Turns out signals.SIGALRM is Unix only and I want to run on both > > platforms so I have done as the docs suggested and tried to convert the > > code to use threading.Timer to trigger an exception if the DNS lookup is > > taking too long. > > Actually none of that was necessary in the end. Digging into the pydns > source to debug the 30 second pause I happened across the timeout parameter! > > >>> result = ping.do_one( "google.com", 5 ) > > "" > > Phew, that simplifies thing a lot! :) > > Roger. From clp2 at rebertia.com Sun Nov 29 23:14:13 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 29 Nov 2009 20:14:13 -0800 Subject: Noobie python shell question In-Reply-To: <4B1341BA.7060607@tim.thechases.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> <4B1341BA.7060607@tim.thechases.com> Message-ID: <50697b2c0911292014r146b5285le0f7852703f83ff6@mail.gmail.com> On Sun, Nov 29, 2009 at 7:53 PM, Tim Chase wrote: > (as an aside, is there a way to get a local/global variable from a string > like one can fetch a variable from a class/object with getattr()? ?Something > like getattr(magic_namespace_here, "hello") used in the above context? ?I > know it can be done with eval(), but that's generally considered unsafe > unless you vet your input thoroughly) locals()["hello"] and globals()["hello"], respectively Cheers, Chris -- http://blog.rebertia.com From wolftracks at invalid.com Sun Nov 29 23:14:15 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 20:14:15 -0800 Subject: Object Not Callable, float? In-Reply-To: <87aay4ralv.fsf@benfinney.id.au> References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > "W. eWatson" writes: > >> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", >> line 467, in ShowHistogram >> mean = sum(hist) >> TypeError: 'float' object is not callable > > It means you're calling an object of type ?float?. The line where it > occurred shows that you're accessing that object through the name ?sum?, > which means you've bound the name ?sum? to a float object. > >> for the code: >> ---------------------- >> sum = 0.0 > > Here you clobber the existing binding of ?sum?, binding it to the float > value 0.0. > >> avg = 0.0 >> nplt_bins = 32 >> for i in range(len(hist)): >> # msg = "%5d %6d\n" % (i,hist[i]) >> msg = "%5d %6d\n" % (i,hist[i]) >> sum = sum + hist[i] > > Here you keep re-binding the name ?sum? to new float objects of > different value. > >> text.insert( END, msg ) >> for i in range(len(hist)): >> avg = avg + (i*hist[i]/sum) >> >> mean = sum(hist) <-------------- faulty line > > Here you try to call the object referenced by the name ?sum?, which is a > float object. > >> hist is a list of 256 integers. What does float have to do with this? > > You explicitly bound the name ?sum? to an object of type ?float?. > > Solution: Choose names wisely, and if you want to use a built-in name > like ?sum? for its built-in putpose, don't clobber that binding before > using it. > Yikes. Thanks very much. Python seems to act unlike other language in which words like float are reserved. I'll use asum. From tjreedy at udel.edu Sun Nov 29 23:20:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Nov 2009 23:20:10 -0500 Subject: Creating a local variable scope. In-Reply-To: References: <4b12f20c@dnews.tpgi.com.au> Message-ID: markolopa wrote: > > so "domain" should not exist in my namespace since I have no > information associated to "domain" only to "self.domains". Python > should allow me to write safe code! Leaving iteration names bound after loop exit is a feature. If you do not like it, explicitly unbind it. From pavlovevidence at gmail.com Sun Nov 29 23:23:22 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 29 Nov 2009 20:23:22 -0800 (PST) Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <1cbe3891-d00c-4c2d-aa22-dc03041a5c3c@a10g2000pre.googlegroups.com> On Nov 29, 8:14?pm, "W. eWatson" wrote: > Ben Finney wrote: > > "W. eWatson" writes: > > >> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", > >> line 467, in ShowHistogram > >> ? ? mean = sum(hist) > >> TypeError: 'float' object is not callable > > > It means you're calling an object of type ?float?. The line where it > > occurred shows that you're accessing that object through the name ?sum?, > > which means you've bound the name ?sum? to a float object. > > >> for the code: > >> ---------------------- > >> ? ? ? ? sum = 0.0 > > > Here you clobber the existing binding of ?sum?, binding it to the float > > value 0.0. > > >> ? ? ? ? avg = 0.0 > >> ? ? ? ? nplt_bins = 32 > >> ? ? ? ? for i in range(len(hist)): > >> # ? ? ? ? ? ? msg = "%5d %6d\n" % (i,hist[i]) > >> ? ? ? ? ? ? msg = "%5d %6d\n" % (i,hist[i]) > >> ? ? ? ? ? ? sum = sum + hist[i] > > > Here you keep re-binding the name ?sum? to new float objects of > > different value. > > >> ? ? ? ? ? ? text.insert( END, msg ) > >> ? ? ? ? for i in range(len(hist)): > >> ? ? ? ? ? ? avg = avg + (i*hist[i]/sum) > > >> ? ? ? ? mean = sum(hist) ? <-------------- faulty line > > > Here you try to call the object referenced by the name ?sum?, which is a > > float object. > > >> hist is a list of 256 integers. What does float have to do with this? > > > You explicitly bound the name ?sum? to an object of type ?float?. > > > Solution: Choose names wisely, and if you want to use a built-in name > > like ?sum? for its built-in putpose, don't clobber that binding before > > using it. > > Yikes. Thanks very much. Python seems to act unlike other language in > which words like float are reserved. I'll use asum. That "float" isn't reserved isn't the problem here since the conflict occurred with the word sum, which is a function. Most languages I know don't reserve the names of functions. For instance you can't do this in C: int printf = 1; printf("%d\n", printf); Python doesn't reserve the names of types either, which is a little uncommon (but not unheard of), so that can be a gotcha. Carl Banks From john at castleamber.com Sun Nov 29 23:24:15 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 04:24:15 GMT Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: "W. eWatson" wrote: > Yikes. Thanks very much. Python seems to act unlike other language in > which words like float are reserved. I'll use asum. The problem is that there is a function sum and you creating a float sum: sum = 0.0 and mean = sum(hist) even if both could exist side by side it would be very confusing IMO. John From davea at ieee.org Sun Nov 29 23:30:09 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 29 Nov 2009 23:30:09 -0500 Subject: Noobie python shell question In-Reply-To: <4B1341BA.7060607@tim.thechases.com> References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> <4B1341BA.7060607@tim.thechases.com> Message-ID: <4B134A51.1030509@ieee.org> Tim Chase wrote: > > > (as an aside, is there a way to get a local/global variable from a > string like one can fetch a variable from a class/object with > getattr()? Something like getattr(magic_namespace_here, "hello") used > in the above context? I know it can be done with eval(), but that's > generally considered unsafe unless you vet your input thoroughly) > > I think you're looking for globals()["hello"], or of course magic_namespace=globals() DaveA From FearsomeDragonfly at gmail.com Mon Nov 30 00:01:37 2009 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Sun, 29 Nov 2009 23:01:37 -0600 Subject: Feature request: String-inferred names In-Reply-To: <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 9:59 PM, Carl Banks wrote: > Another thing that can be determined through common sense is that if > you have object that you are calling getattr and setattr on so much > that you think you need special syntax, you should have been using a > dict. > (Re-send; original was sent to the wrong address. I--I mean, Gmail--sent it to the wrong address by mistake. :P ) While you were writing this and your previous reply I was working on a response that kind of covers what you were talking about, but I'm going to say something anyway. Well, yes, the names would have to be determined at run time. That's what getattr and setattr do, except that that do it in the context of an object rather than the local scope. However, I was under the impression that python's mechanism for looking up local names was the same as the mechanism used to look up attributes because names and attributes seem to function pretty much the same way. This I assumed because of the functionality of the locals() and globals() functions, which seem to act like the __dict__ attribute on objects except that the work on the current scope. Also, there is the __builtins__ module, which actually _is_ an object, but its names can be accessed in the same way as locals and globals. I had considered the possibility of a peformance hit, however I didn't anticipate that it would be all that much. Not that it matters, but how much are we talking? 10% ? 50% ? In any case, I'm not really an expert on Python's internal constructions, but because of this discussion I'm considering taking some time to learn them. Python is unique compared to several other languages in that it makes a distinction between "items" and "attributes". Some languages, like JavaScript and Lua, do not make this distinction. They leave it to the programmer to access members of an object either as an item or as an attribute. I don't think there is necessarily anything wrong with this, nor do I think there is anything wrong with Python's separation. That said, just because you can use the proposed syntax to use an object in the same way as a dict does not mean that it works the other way around. I'm not talking about the allowance of any specific object to have any number of pairings between arbitrary keys and values. That's what dicts are for, and that's what indexing syntax implies. Rather, I'm talking about specific, concrete variables which objects are expected (though not technically required) to have bound to them according to how the object is intended to be used. (That's probably not the best definition of an attribute, but it's the best I can think of ATM.) I'm not trying to discard Python's distinction between items and attributes, but I don't want to be limited by it due to mere syntactical constraints, either. May the Penguin in the sky bless your every subroutine, Brad Harms -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 00:10:23 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 16:10:23 +1100 Subject: Variables with cross-module usage In-Reply-To: References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> Message-ID: <4b135424$1@dnews.tpgi.com.au> On 11/30/2009 12:00 PM, Terry Reedy wrote: > Dennis Lee Bieber wrote: > >> In these languages, the names always refer to the same location. >> Python confuses matters by having names that don't really refer to >> location, but are attached to the objects. > > In everyday life and natural languages, names refer to people, other > objects, roles, and only occasionally to places that can be occupied. I > could claim that it is classical computer languages that confuse by > restricting names to locations in a linear sequence. You are just used > to the straightjacket ;-). In everyday life and natural languages, though an object may have many names/aliases; once objects are assigned a name, it is practically impossible to change the name to the object the name will be practically stuck to it forever. In everyday life and natural languages, a single name can be used to refer to multiple objects just by context without referring any namespace. Let's not start making analogism between nature and silicon. And of all, no one is confused. It is just a matter of assigning new shade of meaning to a word. From koranthala at gmail.com Mon Nov 30 00:10:53 2009 From: koranthala at gmail.com (koranthala) Date: Sun, 29 Nov 2009 21:10:53 -0800 (PST) Subject: Python py2exe - memory load error Message-ID: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> This is cross post from stackoverflow - I couldnt get the solution there. Hopefully, nobody would mind. I am creating a medium level application in Python. Everything works well now, and I am trying to make this a windows executable with py2exe. The executable is created fine, but when I try to run it, it fails with the following error. File "zipextimporter.pyc", line 82, in load_module File "pyAA\__init__.pyc", line 1, in ? File "zipextimporter.pyc", line 82, in load_module File "pyAA\AA.pyc", line 8, in ? File "zipextimporter.pyc", line 82, in load_module File "pyAA\pyAAc.pyc", line 5, in ? File "zipextimporter.pyc", line 98, in load_module ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd I am using pyAA in this application. I searched internet, but was unable to get any solution. I copied msvcp71.dll to windows/system32, but still issue is there. I had solved it earlier (around 7 months back), but my hard drive crashed and when I try to recreate it, I cannot seem to solve it now. :-( I would be much obliged if someone could help me out here. When I use py2exe without bundle files option, it is working perfectly. But when I use bundle file option, it is failing. I tried without zipfile option, wherein it creates a library.zip alongwith the executable. Again it failed. I did unzip of library.zip using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside the zip file. So, it looks like some issue with memoryloadlibrary function. >dir 11/30/2009 09:48 AM 25,172 AA.pyc 11/30/2009 09:48 AM 3,351 Defer.pyc 11/30/2009 09:48 AM 2,311 Path.pyc 11/30/2009 09:48 AM 11,216 pyAAc.pyc 11/30/2009 09:48 AM 5,920 Watcher.pyc 08/20/2005 02:00 PM 49,152 _pyAAc.pyd 11/30/2009 09:48 AM 162 __init__.pyc >From the trace it does look like it can extract AA.pyc etc. I am using windows7 - can it be some clue? From inhahe at gmail.com Mon Nov 30 00:15:25 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 00:15:25 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: On Sun, Nov 29, 2009 at 8:04 PM, Esmail wrote: > Chris Rebert wrote: > Wow .. never heard of Concatenative_languages languages before or the > distinction you make. Your distinction explains the behavior, but I > find it somewhat counter-intuitive. (I use the Python interpreter frequently > for small calculations - otherwise I'd never have realized this) Well I think of it like this -3**2, because of the order of operations as you know, groups as -(3**2) now if you set x to -3, (-3) is now automatically, inseparably grouped. so in a sense by setting x to that you're grouping it. x == (-3) x**2 == (-3)**2 if it still seems counterintuitive, what about the fact that it's exactly the same way in Algebra? basic algebra: -3(superscript)2 is -9 but if x is -3, then x(superscript)2 is 9 From wolftracks at invalid.com Mon Nov 30 00:20:09 2009 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 29 Nov 2009 21:20:09 -0800 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: John Bokma wrote: > "W. eWatson" wrote: > >> Yikes. Thanks very much. Python seems to act unlike other language in >> which words like float are reserved. I'll use asum. > > The problem is that there is a function sum and you creating a float sum: > > sum = 0.0 > > and > > mean = sum(hist) > > even if both could exist side by side it would be very confusing IMO. > > John I think I understand it, but how does one prevent it from happening, or know it's the cause? That msg I got? I think PL/I, FORTRAN, ALGOL, etc. have reserved words. From tjreedy at udel.edu Mon Nov 30 00:26:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 00:26:06 -0500 Subject: ANN: GMPY 1.11rc1 is available In-Reply-To: References: Message-ID: casevh wrote: > Everyone, > > I'm pleased to annouce that a new version of GMPY is available. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11rc1 is available for download from: Is this an update of the gmpy (1.02) registered at http://pypi.python.org/pypi/gmpy/1.02? Either way, please list it (with modified name if needed) and note that it is 3.x compatible so people searching for such packages can find it. From tjreedy at udel.edu Mon Nov 30 00:28:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 00:28:12 -0500 Subject: Exec Statement Question In-Reply-To: <4B133AA3.4060405@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> Message-ID: Dave Angel wrote: > exec is a statement, and statements don't have "return values." It's > not a function, In 3.x, it is a function, though the use of print as a statement indicates that the OP was using 2.x. From fearsomedragonfly at gmail.com Mon Nov 30 00:37:54 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Sun, 29 Nov 2009 23:37:54 -0600 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: On Sun, Nov 29, 2009 at 11:01 PM, Brad Harms wrote: > > May the Penguin in the sky bless your every subroutine, > Um...feel free to ignore that. >_> -- Brad Harms -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 00:44:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 16:44:50 +1100 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <4b135c37$1@dnews.tpgi.com.au> On 11/30/2009 4:20 PM, W. eWatson wrote: > John Bokma wrote: >> "W. eWatson" wrote: >> >>> Yikes. Thanks very much. Python seems to act unlike other language in >>> which words like float are reserved. I'll use asum. >> >> The problem is that there is a function sum and you creating a float sum: >> >> sum = 0.0 >> >> and >> >> mean = sum(hist) >> >> even if both could exist side by side it would be very confusing IMO. >> >> John > I think I understand it, but how does one prevent it from happening, or > know it's the cause? That msg I got? > > I think PL/I, FORTRAN, ALGOL, etc. have reserved words. Generally, use PyLint or similar tools; they'll warn you. From mwilson at the-wire.com Mon Nov 30 01:07:53 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 30 Nov 2009 01:07:53 -0500 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: W. eWatson wrote: > I think PL/I, FORTRAN, ALGOL, etc. have reserved words. Algol reserved syntactic tokens that resembled English words, but specified that they should be written in a different way from programmer-defined symbols, so no conflict was possible. Published algorithms might have the tokens underlined or boldfaced. In the Algol-60 I used, the tokens had to be enclosed in apostrophes. None of this applied to library subroutine names; it was open season on those. In FORTRAN and PL/I words were un-reserved to a degree that's really bizarre. A short post can't begin to do it justice -- let's just mention that IF and THEN could be variable names, and DO 100 I=1.10 . The syntaxes were carefully crafted so that context completely determined whether a symbol would be taken in a reserved sense or a programmer-defined sense, so any possibility for conflict was a syntax error. Mel. From prakash.stack at gmail.com Mon Nov 30 01:36:25 2009 From: prakash.stack at gmail.com (prakash jp) Date: Mon, 30 Nov 2009 12:06:25 +0530 Subject: Python py2exe - memory load error In-Reply-To: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> References: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> Message-ID: <805f59d50911292236i6b442778mbc073a988c86ea73@mail.gmail.com> Try to install "vcredist_x86.exe", then try to build using py2exe. I think that should solve the issue Regards Prakash On Mon, Nov 30, 2009 at 10:40 AM, koranthala wrote: > This is cross post from stackoverflow - I couldnt get the solution > there. Hopefully, nobody would mind. > > I am creating a medium level application in Python. Everything works > well now, and I am trying to make this a windows executable with > py2exe. The executable is created fine, but when I try to run it, it > fails with the following error. > > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\__init__.pyc", line 1, in ? > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\AA.pyc", line 8, in ? > File "zipextimporter.pyc", line 82, in load_module > File "pyAA\pyAAc.pyc", line 5, in ? > File "zipextimporter.pyc", line 98, in load_module > ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd > > I am using pyAA in this application. I searched internet, but was > unable to get any solution. I copied msvcp71.dll to windows/system32, > but still issue is there. > > I had solved it earlier (around 7 months back), but my hard drive > crashed and when I try to recreate it, I cannot seem to solve it > now. :-( > > I would be much obliged if someone could help me out here. > > When I use py2exe without bundle files option, it is working > perfectly. But when I use bundle file option, it is failing. > > I tried without zipfile option, wherein it creates a library.zip > alongwith the executable. Again it failed. I did unzip of library.zip > using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside > the zip file. So, it looks like some issue with memoryloadlibrary > function. > > >dir > 11/30/2009 09:48 AM 25,172 AA.pyc > 11/30/2009 09:48 AM 3,351 Defer.pyc > 11/30/2009 09:48 AM 2,311 Path.pyc > 11/30/2009 09:48 AM 11,216 pyAAc.pyc > 11/30/2009 09:48 AM 5,920 Watcher.pyc > 08/20/2005 02:00 PM 49,152 _pyAAc.pyd > 11/30/2009 09:48 AM 162 __init__.pyc > > >From the trace it does look like it can extract AA.pyc etc. I am using > windows7 - can it be some clue? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grimsqueaker13 at gmail.com Mon Nov 30 01:42:50 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:42:50 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: On Nov 28, 11:26?am, Vinay Sajip wrote: > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > When I add a Filter to a Handler, everything works as expected (ie. > > all messages sent from Loggers below the Filter's level are allowed > > through), but when I add the Filter directly on to the Logger, only > > that Logger is blocked, regardless of the contents of the Filter. > > The key thing to remember is that when a logger processes an event, > handlers attached to it *and all its parents* are offered the event > for handling. In the case where you have just one handler and it has > the filter attached, filtering works as you expected. By attaching the > filter to the root logger, you are not filtering its handler; this > handler is invoked for events logged to all the other loggers, and so > (apart from the event at the root logger) those events are not > filtered. > > For some examples of filter usage, see this post: > > http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > Regards, > > Vinay Sajip OK, that makes sense, but does this mean that I am unable to block a logging path from one point? ie. in my example, I would have to add Filter(loggerB.name) to every Logger in the 'A' path to block the A path from showing at my root Handler? Is there no way I can just block the whole 'A' path from one point? I was under the impression that Filters worked hierarchically and that a message would be passed up the chain of Loggers until it was stopped by a Filter (or its loglevel was not allowed). Thanks for your help From grimsqueaker13 at gmail.com Mon Nov 30 01:52:09 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:52:09 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: <0eaf51df-ed54-4f63-9514-76077a378ee6@v30g2000yqm.googlegroups.com> On Nov 30, 8:42?am, Grimsqueaker wrote: > On Nov 28, 11:26?am, Vinay Sajip wrote: > > > > > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > > When I add a Filter to a Handler, everything works as expected (ie. > > > all messages sent from Loggers below the Filter's level are allowed > > > through), but when I add the Filter directly on to the Logger, only > > > that Logger is blocked, regardless of the contents of the Filter. > > > The key thing to remember is that when a logger processes an event, > > handlers attached to it *and all its parents* are offered the event > > for handling. In the case where you have just one handler and it has > > the filter attached, filtering works as you expected. By attaching the > > filter to the root logger, you are not filtering its handler; this > > handler is invoked for events logged to all the other loggers, and so > > (apart from the event at the root logger) those events are not > > filtered. > > > For some examples of filter usage, see this post: > > >http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > > Regards, > > > Vinay Sajip > > OK, that makes sense, but does this mean that I am unable to block a > logging path from one point? ie. in my example, I would have to add > Filter(loggerB.name) to every Logger in the 'A' path to block the A > path from showing at my root Handler? Is there no way I can just block > the whole 'A' path from one point? I was under the impression that > Filters worked hierarchically and that a message would be passed up > the chain of Loggers until it was stopped by a Filter (or its loglevel > was not allowed). > > Thanks for your help So would I be correct in saying that Filters apply only the the object they are attached to and have no effect on how messages are propagated through the logging hierarchy? If this is the case my next question would be: How can I affect whether or not a message is propagated further up the tree? Sorry to post again so quickly. From grimsqueaker13 at gmail.com Mon Nov 30 01:52:17 2009 From: grimsqueaker13 at gmail.com (Grimsqueaker) Date: Sun, 29 Nov 2009 22:52:17 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> Message-ID: On Nov 30, 8:42?am, Grimsqueaker wrote: > On Nov 28, 11:26?am, Vinay Sajip wrote: > > > > > On Nov 27, 1:11?pm, Grimsqueaker wrote: > > > > When I add a Filter to a Handler, everything works as expected (ie. > > > all messages sent from Loggers below the Filter's level are allowed > > > through), but when I add the Filter directly on to the Logger, only > > > that Logger is blocked, regardless of the contents of the Filter. > > > The key thing to remember is that when a logger processes an event, > > handlers attached to it *and all its parents* are offered the event > > for handling. In the case where you have just one handler and it has > > the filter attached, filtering works as you expected. By attaching the > > filter to the root logger, you are not filtering its handler; this > > handler is invoked for events logged to all the other loggers, and so > > (apart from the event at the root logger) those events are not > > filtered. > > > For some examples of filter usage, see this post: > > >http://groups.google.com/group/comp.lang.python/msg/2eb4cf8f879c6451 > > > Regards, > > > Vinay Sajip > > OK, that makes sense, but does this mean that I am unable to block a > logging path from one point? ie. in my example, I would have to add > Filter(loggerB.name) to every Logger in the 'A' path to block the A > path from showing at my root Handler? Is there no way I can just block > the whole 'A' path from one point? I was under the impression that > Filters worked hierarchically and that a message would be passed up > the chain of Loggers until it was stopped by a Filter (or its loglevel > was not allowed). > > Thanks for your help So would I be correct in saying that Filters apply only the the object they are attached to and have no effect on how messages are propagated through the logging hierarchy? If this is the case my next question would be: How can I affect whether or not a message is propagated further up the tree? Sorry to post again so quickly. From ben+python at benfinney.id.au Mon Nov 30 01:54:52 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Nov 2009 17:54:52 +1100 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: <87y6lopkn7.fsf@benfinney.id.au> "W. eWatson" writes: > I think I understand it, but how does one prevent it from happening, > or know it's the cause? That msg I got? Yes. The line of code was pretty clear: you were attempting to call an object, and the error message said the object's type doesn't support being called. More generally, you should insert an automatic step into your workflow where you run a static code checker like ?pyflakes? over all of your code to catch common errors and mistakes. -- \ ?To me, boxing is like a ballet, except there's no music, no | `\ choreography, and the dancers hit each other.? ?Jack Handey | _o__) | Ben Finney From n00m at narod.ru Mon Nov 30 02:36:16 2009 From: n00m at narod.ru (n00m) Date: Sun, 29 Nov 2009 23:36:16 -0800 (PST) Subject: Number of distinct substrings of a string [continuation] References: <1d6b5116-e416-4cc2-81c0-9a9654314a3d@j19g2000yqk.googlegroups.com> <88b9cc5e-26b3-4178-b021-a330e6386665@l13g2000yqb.googlegroups.com> <154f6235-7c86-461c-853b-e4b4fc313588@f16g2000yqm.googlegroups.com> <775c86ac-52a0-4487-b2d0-defa53b50155@b2g2000yqi.googlegroups.com> Message-ID: On Nov 29, 11:43?pm, Bearophile wrote: > Anyway, you may try a pure-Python2.x implementation:http://suffixtree.googlecode.com/files/suffixtree-0.1.py Ouch, Bearie... 214 lines of code are there. Ok.. I tested it. Firstly I replaced all "print " with "pass##print " (aiming to avoid intensive printing from inside of the code). Then I left in its final part only building of suffix trees. ================================================================== ... ... ... from time import time t = time() import sys sys.stdin = open('D:/88.txt', 'rt') f = sys.stdin.read().split() sys.stdin.close() z = open('D:/99.txt', 'wt') for tc in range(int(f[0])): s = f[tc + 1] test_str = s + '$' POSITIVE_INFINITY = len(test_str) - 1 suffix_tree = SuffixTree(test_str) print >> z, 'len(s) =', len(s) print >> z, 'time =', time() - t z.close() ============================================================ Output: ============================================================ len(s) = 1000 len(s) = 1000 len(s) = 10000 time = 0.641000032425 ============================================================ 0.64s > 0.48s (of my algo) I.e. the code can't help in my very special and narrow case. But of course it is worthy to be studied and memoized. E.g.: from huge string "s" we built its Suffix Tree. Now we are given arbitrary string "ss". Task: to find the largest its prefix occured in "s", traversing its Suffix Tree. From callmeclaudius at gmail.com Mon Nov 30 03:17:38 2009 From: callmeclaudius at gmail.com (Joel Davis) Date: Mon, 30 Nov 2009 00:17:38 -0800 (PST) Subject: Unpacking Tuples Message-ID: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> I hate to post such a simple Q and A here, but I seriously can't find it anywhere. Python (unsure of starting with which version) enables the remainder of the tuple to be placed in a "catch-all", for example: >> myTuple = (1,2,3,4) >> varOne, varTwo, *remaindingTuple = myTuple. where the values left unpacked get thrown into a tuple referenced to by "remaindingTuple" I included the asterix because it seems like I remember that being the operator that specifying the tuple's dumping ground. Which brings me to my two questions: 1) what's the syntax for this operation 2) what version does it start with? From d.dalton at iinet.net.au Mon Nov 30 03:20:59 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 19:20:59 +1100 Subject: python and vc numbers In-Reply-To: <7ngl1gF3ml76pU1@mid.individual.net> References: <7ngl1gF3ml76pU1@mid.individual.net> Message-ID: <20091130082059.GA10079@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 02:21:54PM +1300, Gregory Ewing wrote: > >I use to figure out what tty my program was invoked from? > > Here's one way: > > % python > Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.popen("tty").read() That did the trick, thanks, after I append [-2] It works great. Thanks Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From Nadav.C at qualisystems.com Mon Nov 30 03:25:35 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Mon, 30 Nov 2009 10:25:35 +0200 Subject: Running function from Win32 dll Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947BB4@exchange.qualisystems.local> Hi all, I want to run function from win32 dll. I used ctypes.windll.LoadLibrary to load the DLL. But I don't know how to select function and run it. Dll example attached (pylab.dll). It includes 2 functions: double Add(double a,double b) - adds 2 double numbers double Random(void) - generates random number Thank you, Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pylab.rar Type: application/octet-stream Size: 12749 bytes Desc: pylab.rar URL: From clp2 at rebertia.com Mon Nov 30 03:26:44 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 00:26:44 -0800 Subject: Unpacking Tuples In-Reply-To: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> References: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> Message-ID: <50697b2c0911300026v139776a3n4b4b8f5babf06dd1@mail.gmail.com> On Mon, Nov 30, 2009 at 12:17 AM, Joel Davis wrote: > I hate to post such a simple Q and A here, but I seriously can't find > it anywhere. Python (unsure of starting with which version) enables > the remainder of the tuple to be placed in a "catch-all", for example: > > >>> myTuple = (1,2,3,4) >>> varOne, varTwo, *remaindingTuple = myTuple. > > where the values left unpacked get thrown into a tuple referenced to > by "remaindingTuple" I included the asterix because it seems like I > remember that being the operator that specifying the tuple's dumping > ground. Which brings me to my two questions: > 1) what's the syntax for this operation Exactly as you showed above (well, minus the period obviously). 2) what version does it start with? Python 3.0 It might be backported into 2.7 when it gets released: http://bugs.python.org/issue2340 Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Mon Nov 30 03:32:38 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 30 Nov 2009 00:32:38 -0800 Subject: Unpacking Tuples In-Reply-To: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> References: <9989c112-0b31-4cea-abcb-20a0e1169b85@m38g2000yqd.googlegroups.com> Message-ID: <4B138326.6060500@islandtraining.com> Joel Davis wrote: > I hate to post such a simple Q and A here, but I seriously can't find > it anywhere. Python (unsure of starting with which version) enables > the remainder of the tuple to be placed in a "catch-all", for example: > > > >>> myTuple = (1,2,3,4) >>> varOne, varTwo, *remaindingTuple = myTuple. >>> > > where the values left unpacked get thrown into a tuple referenced to > by "remaindingTuple" I included the asterix because it seems like I > remember that being the operator that specifying the tuple's dumping > ground. Which brings me to my two questions: 1) what's the syntax for > this operation 2) what version does it start with? > 1) Syntax is just as you have it. (Not including the period you have at the end.) 2) Python 3.0 Gary Herron From Nadav.C at qualisystems.com Mon Nov 30 03:39:40 2009 From: Nadav.C at qualisystems.com (Nadav Chernin) Date: Mon, 30 Nov 2009 10:39:40 +0200 Subject: Running function from win32 dll Message-ID: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> Hi all, I want to run function from win32 dll. I used ctypes.windll.LoadLibrary to load the DLL. But I don't know how to select function and run it. Thank you, Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: From estartu at augusta.de Mon Nov 30 03:41:15 2009 From: estartu at augusta.de (Gerhard Schmidt) Date: Mon, 30 Nov 2009 09:41:15 +0100 Subject: Creating a datetime object from a C Extention Message-ID: HI, I'm writing a python C Extension and need to create datetime objects but when I call value = PyDateTime_FromDateAndTime(ti->tm_year+1900, ti->tm_mon, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec, u); I get an SegFault. ti = {tm_sec = 25, tm_min = 37, tm_hour = 8, tm_mday = 30, tm_mon = 10, tm_year = 109, tm_wday = 1, tm_yday = 333, tm_isdst = 0, tm_gmtoff = 0, tm_zone = 0x800fd20c8 "UTC"} u = 0 Is there an Dokumentation or example code HowTo create a datetime object from a C Extension. Regards Estartu -- ---------------------------------------------------------------------------- Gerhard Schmidt | http://www.augusta.de/~estartu/ | Fischbachweg 3 | | PGP Public Key 86856 Hiltenfingen | JabberID: estartu at augusta.de | auf Anfrage/ Tel: 08232 77 36 4 | IRCNET: Estartu | on request Fax: 08232 77 36 3 | | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 369 bytes Desc: OpenPGP digital signature URL: From greg.ewing at canterbury.ac.nz Mon Nov 30 03:46:42 2009 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 30 Nov 2009 21:46:42 +1300 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> Message-ID: <7nhf3eF3lrgr4U1@mid.individual.net> Esmail wrote: > Wow .. never heard of Concatenative_languages languages before or the > distinction you make. Your distinction explains the behavior, but I > find it somewhat counter-intuitive. You shouldn't find it any more surprising than the fact that a = 2 + 3 print a * 5 gives a different result from print 2 + 3 * 5 -- Greg From marko.loparic at gmail.com Mon Nov 30 03:50:04 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 30 Nov 2009 00:50:04 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <1e5e38b7-3b75-4db6-b8f4-a5adb18fd91a@b15g2000yqd.googlegroups.com> Hi Steve! On Nov 30, 1:46?am, Steve Howell wrote: > I occasionally make the error you make, but I think the real problem > you are having is lack of attention to detail. ?If name collisions are > a common problem for you, consider writing shorter methods Yes, this could be a solution, though I believe that too many (sub) methods called by a single method turn the code less readable. > or develop > the habit of using more descriptive variable names. Also a good suggestion. Alternatively I have considered to do the opposite, to use weird (the opposite of descriptive) names for variables that should exist only inside the block, in order to differentiate them from the variables that should persist. > ?In the code > above, you could have easily cleaned up the namespace by extracting a > method called get_arg_columns(). ?Having to spend 15 minutes tracking > down a bug usually indicates that you are not being systematic in your > thinking. ?If you are rushing too much, slow down. ?If you are tired, > take a break. ?If you make the same mistake twice, commit to yourself > not to make it a third time. ?Also, test your methods one at a time > and get them rock solid before writing more code. Nice suggestions thanks, all of them apply to me!...:-) Compared to the normal coder I have a strong tendency to loose myself in details. That is why I have to be very systematic, write lots of defensive code (to catch the bugs as soon as possible), write unit tests (great habit I've developped recently!). Python is fantastic for those goals. The only laking feature I find is really the survival of variables, a problem that does not exist in C++ or in Perl (with use strict). Besides this kind of bug I have noticed only 2 other sources of bug I had more than once with python code. - expecting float from integer division (easily avoidable, either with 3.0 or from __future__...) - expecting diferent objects in a list have having the same several times (deepcopy issue, also easily avoidable once we know it) So my only other problem is with this "survival" feature. I consider to write my own version of Python, the one that would not allow the usage of varaibles outside the block it was created. Of course I won't rewrite CPython but I could add an error (or warning) to pylint. With some luck it already exists, I will investigate... Greets! Marko From cindyqjm at gmail.com Mon Nov 30 03:56:09 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:09 -0800 (PST) Subject: delete column content References: Message-ID: <2397e4fa-b863-46ce-b65a-672363ee0ee3@g22g2000prf.googlegroups.com> On 11?30?, ??2?12?, Francesco Pietra wrote: > Hi: > How to replace with blank the single-character in column 21 of a pdb > file (in pdb numbering it is column 22). Attached is an incomplete > exercise with slices. I am unable to get real plain text with gmail. > > Thanks for help > > francesco pietra > > ?delete.label.py > < 1K???? http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Mon Nov 30 03:56:19 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:19 -0800 (PST) Subject: delete column content References: <7nfsp6F3lpbpvU1@mid.uni-berlin.de> Message-ID: <3db6d209-9194-4bd4-b6d1-7d46580028fd@e4g2000prn.googlegroups.com> On 11?30?, ??2?27?, "Diez B. Roggisch" wrote: > Francesco Pietra schrieb: > > > Hi: > > How to replace with blank the single-character in column 21 of a pdb > > file (in pdb numbering it is column 22). Attached is an incomplete > > exercise with slices. I am unable to get real plain text with gmail. > > > Thanks for help > > Wasn't the help you already got a few days ago sufficient? > > Diez http://www.mbthome.net/ mbt shoes From cindyqjm at gmail.com Mon Nov 30 03:56:24 2009 From: cindyqjm at gmail.com (jessica) Date: Mon, 30 Nov 2009 00:56:24 -0800 (PST) Subject: delete column content References: Message-ID: <674ee6a8-41c7-4379-b364-dfec070d3adf@u36g2000prn.googlegroups.com> On 11?30?, ??2?48?, Vlastimil Brom wrote: > 2009/11/29 Francesco Pietra : > > > Hi: > > How to replace with blank the single-character in column 21 of a pdb > > file (in pdb numbering it is column 22). Attached is an incomplete > > exercise with slices. I am unable to get real plain text with gmail. > > > Thanks for help > > > francesco pietra > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Do you mean something like > > >>> line="abcdefghijklmnopqrstuvwxyz" > >>> line[:21]+line[22:] > > 'abcdefghijklmnopqrstuwxyz' > > ? > > vbr http://www.mbthome.net/ mbt shoes From martin at v.loewis.de Mon Nov 30 04:07:22 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Nov 2009 10:07:22 +0100 Subject: Creating a datetime object from a C Extention In-Reply-To: References: Message-ID: <4B138B4A.1070106@v.loewis.de> > I'm writing a python C Extension and need to create datetime objects but > when I call > value = PyDateTime_FromDateAndTime(ti->tm_year+1900, ti->tm_mon, > ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec, u); > I get an SegFault. > > ti = {tm_sec = 25, tm_min = 37, tm_hour = 8, tm_mday = 30, tm_mon = 10, > tm_year = 109, tm_wday = 1, tm_yday = 333, tm_isdst = 0, > tm_gmtoff = 0, tm_zone = 0x800fd20c8 "UTC"} > u = 0 > > Is there an Dokumentation or example code HowTo create a datetime object > from a C Extension. You need to put PyDateTime_IMPORT; into your module's init function. HTH, Martin From marko.loparic at gmail.com Mon Nov 30 04:13:35 2009 From: marko.loparic at gmail.com (markolopa) Date: Mon, 30 Nov 2009 01:13:35 -0800 (PST) Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> Message-ID: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> On Nov 30, 4:46?am, Dave Angel wrote: > markolopa wrote: > > Antoher 15 minutes lost because of that Python "feature"... Is it only > > me??? > > Yep, I think so. Not very consoling but thanks anyway!...:-)))) >?You're proposing a much more complex scoping rule, > where if a variable already exists before entering a loop, then the loop > uses that existing variable, but if not, it creates its own local one > and destroys it when exiting the loop. Alternatively you could forbid the creation of a variable in a inner block if it already exists. Either that or forbid the usage of the variable in an outter block later if it exists both in an inner and outer block. Aren't there languages that forbid the declarations of variables in a function with the same name as global variables? I know that this is an extreme defensive measure, but I have to say that I like it. Allowing to create a new variable when a variable with the same name is already exists in the namespace makes for harm that good, for me at least. Of course this issue is much broader than the one I proposed initially. > I think if you had your wish, you'd find that you had more exceptions > where you had to pre-declare things, than the times when you avoided the > bugs you describe. ? You are probably right, otherwise Guido would have done what I suggest... but I really don't see why. > I don't like languages that make me write extra > stuff 100 times, to save one instance of extra debugging. ?If Python > already required declarations, then I might buy your arguments. ?But it > wouldn't be Python. My guess is that if the change I propose was implemented, the number additional lines that would be needed to make the present python code work would be 1 in a thousand or less. Of course I may be wrong... Besides this additional line can make the code more readable, strassing the fact that the variable inside the block actually "belongs" to outside. > In your particular case, the compiler couldn't guess whether you used > the first loop to decide which domain to use in the second loop, That is what I wish the compiler should forbid...:-> > or > whether you accidentally reused the same name without giving it a new > value in the new loop. ? That is what I do regularly...8-> > If you need to use the same name, you could > always follow your loops with the del statement to invalidate the name. Several people have suggested explicit destruction of the variables I don't need. Python allows it but of course this does not solve my problem. It does not make sense to use such a clean language as Python and regularly delete all variables used inside the blocks when leaving it. And of course the bug comes because I have no idea that I am using the same name again. Cheers! Marko From nick at craig-wood.com Mon Nov 30 04:30:14 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 30 Nov 2009 03:30:14 -0600 Subject: ANN: GMPY 1.11rc1 is available References: Message-ID: casevh wrote: > I'm pleased to annouce that a new version of GMPY is available. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11rc1 is available for download from: [snip] > Future plans > > On releasing the GIL: I have compared releasing the GIL versus the > multiprocessing module and the multiprocessing module offers better > and more predictable performance for embarrassingly parallel tasks > than releasing the GIL. If there are requests, I can add a compile- > time option to enable threading support but it is unlikely to > become the default. You could have variant types of mpz etc which do release the GIL so you could mix and match accordingly. > On mutable integers: The performance advantages of mutable integers > appears to be 20% to 30% for some operations. I plan to add a new > mutable integer type in the next release of GMPY. If you want to > experiment with mutable integers now, GMPY can be compiled with > mutable version of the standard 'mpz' type. Please see the file > "mutable_mpz.txt" for more information. Mutable integers - whatever will they think of next ;-) Thanks for maintaining gmpy - it is an excellent bit of software! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From lie.1296 at gmail.com Mon Nov 30 04:30:16 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 30 Nov 2009 20:30:16 +1100 Subject: Creating a local variable scope. In-Reply-To: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: <4b13910d$1@dnews.tpgi.com.au> On 11/30/2009 8:13 PM, markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: >> markolopa wrote: >>> Antoher 15 minutes lost because of that Python "feature"... Is it only >>> me??? >> >> Yep, I think so. > > Not very consoling but thanks anyway!...:-)))) > >> You're proposing a much more complex scoping rule, >> where if a variable already exists before entering a loop, then the loop >> uses that existing variable, but if not, it creates its own local one >> and destroys it when exiting the loop. > > Alternatively you could forbid the creation of a variable in a inner > block if it already exists. Either that or forbid the usage of the > variable in an outter block later if it exists both in an inner and > outer block. > Of course, the best solution would be to allow assignment only in a single line of source of code. Reassignment by different lines of code would be a syntax error. You're forced to have different names if you want assign something multiple times. That way, no bugs is possible. From d.dalton at iinet.net.au Mon Nov 30 05:02:00 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 21:02:00 +1100 Subject: python and vc numbers In-Reply-To: <20091130082059.GA10079@gwsc.vic.edu.au> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> Message-ID: <20091130100200.GB12885@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 07:20:59PM +1100, Daniel Dalton wrote: > That did the trick, thanks, after I append > [-2] Further testing under screen says otherwise -- it seems to give me the tty number, not the virtual console number. Is there any way to figure out what virtual console I'm am in so a certain command ran under screen process A isn't confused with a command ran under screen process B? Thanks Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From nobody at nowhere.com Mon Nov 30 05:19:07 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 30 Nov 2009 10:19:07 +0000 Subject: Object Not Callable, float? References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: On Mon, 30 Nov 2009 01:07:53 -0500, Mel wrote: > In FORTRAN and PL/I words were un-reserved to a degree that's really > bizarre. A short post can't begin to do it justice -- let's just mention > that IF and THEN could be variable names, and DO 100 I=1.10 . The syntaxes > were carefully crafted so that context completely determined whether a > symbol would be taken in a reserved sense or a programmer-defined sense, so > any possibility for conflict was a syntax error. And then Lisp and Tcl just don't have reserved words. Many symbols are pre-defined, but you're free to re-define them (Lisp won't let you use 'quote' as a function name, but you can still use it as a variable name). From steve at REMOVE-THIS-cybersource.com.au Mon Nov 30 05:25:11 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Nov 2009 10:25:11 GMT Subject: Creating a local variable scope. References: Message-ID: <009d2203$0$26893$c3e8da3@news.astraweb.com> On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: > I think if one could somehow declare names as const (final, readonly, > whatever) then that would cover the above plus much more. Having real constants is one feature that I miss. Because Python doesn't have constants, I find I've lost the discipline to avoid "magic numbers" (and strings) in my code. -- Steven From clp2 at rebertia.com Mon Nov 30 05:26:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 02:26:14 -0800 Subject: python and vc numbers In-Reply-To: <20091130100200.GB12885@gwsc.vic.edu.au> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> Message-ID: <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> On Mon, Nov 30, 2009 at 2:02 AM, Daniel Dalton wrote: > > On Mon, Nov 30, 2009 at 07:20:59PM +1100, Daniel Dalton wrote: >> That did the trick, thanks, after I append >> [-2] > > Further testing under screen says otherwise -- it seems to give me the > tty number, not the virtual console number. Is there any way to figure > out what virtual console I'm am in so a certain command ran under screen > process A isn't confused with a command ran under screen process B? >From what I can find, virtual console == tty. Quoting http://en.wikipedia.org/wiki/Virtual_console_%28PC%29 "The virtual consoles are represented by device special files /dev/tty1, /dev/tty2 etc." Also, in my quickie newbie experimentation with `screen`, each screen "window" seems to get a unique tty#. Admittedly I am running OS X here, so if your notion of "virtual console" differs from Wikipedia's and is Linux-specific or something... Perhaps if you could explain your problem in greater detail? Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Nov 30 05:29:10 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 30 Nov 2009 05:29:10 -0500 Subject: Creating a local variable scope. In-Reply-To: <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: <4B139E76.70105@ieee.org> markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: > >> markolopa wrote: >> >>> Antoher 15 minutes lost because of that Python "feature"... Is it only >>> me??? >>> >> Yep, I think so. >> > > Not very consoling but thanks anyway!...:-)))) > > >> You're proposing a much more complex scoping rule, >> where if a variable already exists before entering a loop, then the loop >> uses that existing variable, but if not, it creates its own local one >> and destroys it when exiting the loop. >> > > Alternatively you could forbid the creation of a variable in a inner > block if it already exists. Somehow you seem to think there's some syntax for "creating" a variable. In fact, what's happening is you're binding/rebinding a name to an object. And if you forbid doing this inside the loop, for names that exist outside the loop, then most of the useful work the loop does becomes impossible. Remember, in Python, there's no declaration of a variable (except the global statement, which does it sort-of). So you'd be disallowing the following: counter = 5 for item in itemlist: if item > 19: counter = counter + 5 The only way I can think you possibly want this is if you're just referring to "loop variables", such as "item" in the above example. The problem is that on many loops, for example a "while" loop, there's no such thing. > Either that or forbid the usage of the > variable in an outter block later if it exists both in an inner and > outer block. > > You need to define "exists" in order to make discussion unambiguous. Without extra declarations of some type, I can't believe there's any way to make any variation of this concept work in the general case. > Aren't there languages that forbid the declarations of variables in a > function with the same name as global variables? I know that this is > an extreme defensive measure, but I have to say that I like it. > Allowing to create a new variable when a variable with the same name > is already exists in the namespace makes for harm that good, for me at > least. Of course this issue is much broader than the one I proposed > initially. > > I can't think of any, among the 35 languages I've programmed in professionally over the years. All right, to be fair, about half of those were assembly languages at various levels. And I don't believe I worked in any assembly language that even had separate scoping for functions. DaveA From jeanmichel at sequans.com Mon Nov 30 06:02:53 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 30 Nov 2009 12:02:53 +0100 Subject: Creating a local variable scope. In-Reply-To: <009d2203$0$26893$c3e8da3@news.astraweb.com> References: <009d2203$0$26893$c3e8da3@news.astraweb.com> Message-ID: <4B13A65D.6010902@sequans.com> Steven D'Aprano wrote: > On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: > > >> I think if one could somehow declare names as const (final, readonly, >> whatever) then that would cover the above plus much more. >> > > Having real constants is one feature that I miss. Because Python doesn't > have constants, I find I've lost the discipline to avoid "magic > numbers" (and strings) in my code. > > > I don't get you, this can be easily avoid with a strong naming convention. I mean, despite they are not really constants, you can still use variables to name your numbers and string, to give the reader a usefull hint on the meaning of your code. Yet it is still a matter of discipline, it is sometimes very tempting to put the string directly (unlike numbers string can be meaningful sometimes) JM From d.dalton at iinet.net.au Mon Nov 30 06:05:18 2009 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Mon, 30 Nov 2009 22:05:18 +1100 Subject: python and vc numbers In-Reply-To: <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> Message-ID: <20091130110518.GA799@gwsc.vic.edu.au> On Mon, Nov 30, 2009 at 02:26:14AM -0800, Chris Rebert wrote: > Also, in my quickie newbie experimentation with `screen`, each screen > "window" seems to get a unique tty#. Admittedly I am running OS X Correct (Which creates the problem) > Perhaps if you could explain your problem in greater detail? Sure, well, first I am running screen in a console. Under screen I open many windows, but in my .screenrc file, after 15 minutes screen runs screen lock which is the equivalent of /usr/local/bin/lock /usr/local/bin/lock is my python script, basically it checks to see if file /tmp/.vlock.run exists and if it does, will not run vlock again, but if it doesn't then passes onto vlock. When vlock returns a clean exit, eg. the user unlocks the term, my program removes that statefile and exits nicely. (the purpose of this is so screen doesn't lock the system hundreds of times, asking for a password hundreds of times, or when using -na it doesn't create a bunch of useless blank "lock" windows in my screen session. This works well, but it is only useful for one tty, because if you lock tty1 then it blocks tty2 etc. I know I could have a bunch of different scripts using different files, but this just gets to complicated to manage, so the logical solution is to append vc number to the filename: /tmp/.vlock.run.1 /tmp/.vlock.run.2 etc So we can identify which consoles have been locked, and which haven't. The problem lies with the fact, I can't find a reliable way to determine the current console number with python or any bash tool. When I say console number, I mean the actual console number, not screen window or device it is sending to or whatever. I am totally blind, and therefore use a package called brltty, and this package has the ability to show me what number console I'm in, and even under screen always works reliably and consistently. So anyone know of a better solution, now I have described the issue in great detail? Thanks very much for all the help. Cheers, Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From paul at boddie.org.uk Mon Nov 30 06:15:18 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 30 Nov 2009 03:15:18 -0800 (PST) Subject: Imitating "tail -f" References: Message-ID: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> On 22 Nov, 05:10, exar... at twistedmatrix.com wrote: > > "tail -f" is implemented by sleeping a little bit and then reading to > see if there's anything new. This was the apparent assertion behind the "99 Bottles" concurrency example: http://wiki.python.org/moin/Concurrency/99Bottles However, as I pointed out (and as others have pointed out here), a realistic emulation of "tail -f" would actually involve handling events from operating system mechanisms. Here's the exchange I had at the time: http://wiki.python.org/moin/Concurrency/99Bottles?action=diff&rev2=12&rev1=11 It can be very tricky to think up good examples of multiprocessing (which is what the above page was presumably intended to investigate), as opposed to concurrency (which can quite easily encompass responding to events asynchronously in a single process). Paul P.S. What's Twisted's story on multiprocessing support? In my limited experience, the bulk of the work in providing usable multiprocessing solutions is in the communications handling, which is something Twisted should do very well. From victorsubervi at gmail.com Mon Nov 30 06:23:59 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 06:23:59 -0500 Subject: Exec Statement Question In-Reply-To: <4B133AA3.4060405@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> Message-ID: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: > exec is a statement, and statements don't have "return values." It's not > a function, so there are no parentheses in its syntax, either. exec is also > a technique of last resort; there's nearly always a better/safer/faster way > to accomplish what you might want, but of course you don't say what that is. > > As for "returning" values, exec by default uses the same global space as > your app, so you can just modify a global variable in your "called" code and > use it afterwards. > > abc = 42 > value = 12 > exec "abc = %d" % value > print abc > Taking out the parenthesis did it! Thanks. Now, you state this is an option of last resort. Although this does indeed achieve my desired aim, here is a complete example of what I am trying to achieve. The following is from 'createTables2.py': for table in tables: try: exec 'from options import %s' % table except: pass try: exec '%s()' % table except: pass The following is from 'options.py': def jewelry(which=''): code = [] names = [] meanings = [] code.append(['5', '5½', '6', '6½', '7', '7½', '8', '8½', '9', '9½', '10', '10½', '11', '11½', '12', '12½', '13', '13½']) meanings.append('The standard ring sizes.') names.append('ringSizes') code.append(['Petite (7")', 'Average (7½")', 'Large (8")', 'Extra-large (8½")']) meanings.append('The standard bracelet sizes.') names.append('braceletSizes') code.append(['16"', '18"', '20"', '22"', '24"']) meanings.append('The standard necklace sizes.') names.append('necklaceSizes') code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K white gold', 'platinum', 'tungsten', 'titanium']) meanings.append('The standard jewelry metals.') names.append('metals') code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', 'turquoise']) meanings.append('The standard jewelry stones.') names.append('stones') if which == '': i = 0 all = '' while i < len(meanings): table = '%s\n' % meanings[i] table += "\n \n \n " % names[i] j = 0 for elt in code: if (j + 8) % 8 == 0: table += ' \n' table += ' \n' % code[i] if (j + 8) % 8 == 0: table += ' \n' j += 1 if table[-6:] != '\n': table += ' \n' table += '
    %s
    %s
    \n' all += table + '

    ' i += 1 print all This all works fine; however, if there is a better way of doing it, please let me know. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Nov 30 06:34:59 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 12:34:59 +0100 Subject: Creating a local variable scope. In-Reply-To: References: <009d2203$0$26893$c3e8da3@news.astraweb.com> Message-ID: * Jean-Michel Pichavant: > Steven D'Aprano wrote: >> On Mon, 30 Nov 2009 02:11:12 +0100, Alf P. Steinbach wrote: >> >> >>> I think if one could somehow declare names as const (final, readonly, >>> whatever) then that would cover the above plus much more. >>> >> >> Having real constants is one feature that I miss. Because Python >> doesn't have constants, I find I've lost the discipline to avoid >> "magic numbers" (and strings) in my code. >> >> >> > I don't get you, this can be easily avoid with a strong naming > convention. I mean, despite they are not really constants, you can still > use variables to name your numbers and string, to give the reader a > usefull hint on the meaning of your code. Yet it is still a matter of > discipline, it is sometimes very tempting to put the string directly > (unlike numbers string can be meaningful sometimes) It may be surprising how many things turn out to be readonly. Consider the OP's code: class ValueColumn(AbstractColumn): def __init__(self, name, header, domain_names): if type(domain_names) != tuple: raise ValueError('a tuple of domain names must be given') for name in domain_names: if type(name) != str: raise ValueError('a tuple of domain names must be given') self.domain_names = domain_names super(ValueColumn, self).__init__(name, header) Here the arguments should ideally be read only names, which would have cought the bug of reusing 'name' in the for loop. But you really wouldn't code this as class ValueColumn(AbstractColumn): def __init__(SELF, NAME, HEADER, DOMAIN_NAMES): if type(DOMAIN_NAMES) != tuple: raise ValueError('a tuple of domain names must be given') for name in DOMAIN_NAMES: # Argh, at this point 'name' is readonly, but cannot express that. if type(name) != str: raise ValueError('a tuple of domain names must be given') SELF.domain_names = domain_names super(ValueColumn, SELF).__init__(NAME, HEADER) Or, at least I wouldn't do that. It's ugly. And you have to /change the names/ as the readonly-ness changes. Cheers, - Alf From inhahe at gmail.com Mon Nov 30 06:41:06 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 06:41:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <7nhf3eF3lrgr4U1@mid.individual.net> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> Message-ID: one point of confusion could be the use of ** instead of superscript. it might make things a little bit more counterintuitive-looking than with superscripts, since the issue with would only apply to exponents, as -5*4 and a = -5 a*4 return the same answer, and superscripts make it a little easier to associate the exponent value with the base more than with the - before it. On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing wrote: > Esmail wrote: > >> Wow .. never heard of Concatenative_languages languages before or the >> distinction you make. Your distinction explains the behavior, but I >> find it somewhat counter-intuitive. > > You shouldn't find it any more surprising than the fact that > > ?a = 2 + 3 > ?print a * 5 > > gives a different result from > > ?print 2 + 3 * 5 > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Mon Nov 30 07:26:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 07:26:09 -0500 Subject: Completely OT Message-ID: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Hi; I need a recommendation. I want to print out data like this: blue red and enable the user to select the various colors he wants to add to a list that would populate itself on the same page where the selections are, and then, once he's selected all the colors he wants, click to add them all at once to a table in a database, and move on to the next page. I believe this is achieved through JSON and AJAX; however, I haven't been able to google any demonstrations of this sort. Am I correct, or should I use some other sort of technology? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From lou at cs.rutgers.edu Mon Nov 30 07:35:06 2009 From: lou at cs.rutgers.edu (Louis Steinberg) Date: Mon, 30 Nov 2009 07:35:06 -0500 Subject: problem with lambda / closures Message-ID: I have run into what seems to be a major bug, but given my short exposure to Python is probably just a feature: running Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin with file foo.py containing: ============================== clip here ============ def p(d): print d l=[ ] for k in [1,2,3]: l.append(lambda : p(k)) for f in l: f() ============================== clip here ============ I get output 3 3 3 instead of 1 2 3 which I would expect. Can anyone explain this or give me a workaround? Thank you From gnarlodious at gmail.com Mon Nov 30 07:36:17 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 05:36:17 -0700 Subject: Can't print Chinese to HTTP Message-ID: Hello. The "upgrade to Python 3.1 has been disaster so far. I can't figure out how to print Chinese to a browser. If my script is: #!/usr/bin/python print("Content-type:text/html\n\n") print('?') the Chinese string simply does not print. It works in interactive Terminal no problem, and also works in Python 2.6 (which my server is still running) in 4 different browsers. What am I doing wrong? BTW searched Google for 2 days no solution, if this doesn't get solved soon I will have to roll back to 2.6. Thanks for any clue. -- Gnarlie http://Gnarlodious.com From martin at v.loewis.de Mon Nov 30 07:53:13 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Mon, 30 Nov 2009 13:53:13 +0100 Subject: Can't print Chinese to HTTP In-Reply-To: References: Message-ID: <4b13c039$0$7478$9b622d9e@news.freenet.de> Gnarlodious wrote: > Hello. The "upgrade to Python 3.1 has been disaster so far. I can't > figure out how to print Chinese to a browser. If my script is: > > #!/usr/bin/python > print("Content-type:text/html\n\n") > print('?') > > the Chinese string simply does not print. It works in interactive > Terminal no problem, and also works in Python 2.6 (which my server is > still running) in 4 different browsers. What am I doing wrong? BTW > searched Google for 2 days no solution, if this doesn't get solved > soon I will have to roll back to 2.6. > > Thanks for any clue. In the CGI case, Python cannot figure out what encoding to use for output, so it raises an exception. This exception should show up in the error log of your web server, please check. One way of working around this problem is to encode the output explicitly: #!/usr/bin/python print("Content-type:text/plain;charset=utf-8\n\n") sys.stdout.buffer.write('?\n'.encode("utf-8")) FWIW, the Content-type in your example is wrong in two ways: what you produce is not HTML, and the charset parameter is missing. Regards, Martin From ebonak at hotmail.com Mon Nov 30 08:00:48 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 08:00:48 -0500 Subject: flattening and rebuilding a simple list of lists Message-ID: Hi, I have a list of lists. The number of sublists may vary. The sizes of the sublists may also vary. For instance, here I have a list with 3 sublists of differing sizes. [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] This list will never be any deeper than this one level. What I would like to do is flatten this list, rearrange the items in the new flattened list and then recreate the list of sublists with the new content. I would like the sublists to have the same size and order (relative to each other) as before. My code below seems to work, but it feels a bit "hack'ish", and I am concerned about efficiency - so I would appreciate suggestions. Again, the number of sublists may vary, and sizes of sublists are not always the same (there will always be at least one sublist). thanks! Esmail Here is my working code so far. ---------------- #!/usr/bin/env python from random import shuffle ################################################################## def flatten_list(parts): """ flatten parts, and return index vals where to split """ line = sum(parts, []) # join all parts into one idx_vals = [] idx = 0 for item in parts: # keep track of lengths/index values idx += len(item) idx_vals.append(idx) return line, idx_vals ################################################################## def rebuilt_lists(line, idx): """ rebuild list of list """ new_list = [line[0:idx[0]]] for i in xrange(len(idx)-1): new_list.append(line[idx[i]:idx[i+1]]) return new_list ################################################################## def main(): indi = [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] print 'indi :', indi # flatten list of list new_indi, idx_vals = flatten_list(indi) print 'new_indi:', new_indi print 'lengths :', idx_vals print # manipulate list print 'shuffling new_indi' shuffle(new_indi) print 'new_indi:', new_indi print # rebuild list of lists new_list = rebuilt_lists(new_indi, idx_vals) print 'new_list:', new_list if __name__ == '__main__': main() From olof.bjarnason at gmail.com Mon Nov 30 08:05:31 2009 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Mon, 30 Nov 2009 14:05:31 +0100 Subject: reading from a text file In-Reply-To: References: Message-ID: 2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. > e.g > in the text file i have these data > > 1.hello > 2.my name > 3.is > 4.World > > Your help is highly appreciated..thnx in advance Hi babourarr; import random with open("c:/test.txt") as f: lines = f.read().splitlines() random_line = lines[random.randrange(len(lines))] print(random_line) > > $LIM $H at DY > > > ________________________________ > Windows Live: Friends get your Flickr, Yelp, and Digg updates when they > e-mail you. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- twitter.com/olofb olofb.wordpress.com olofb.wordpress.com/tag/english From simon at brunningonline.net Mon Nov 30 08:06:56 2009 From: simon at brunningonline.net (Simon Brunning) Date: Mon, 30 Nov 2009 13:06:56 +0000 Subject: reading from a text file In-Reply-To: References: Message-ID: <8c7f10c60911300506h37ccf5fcl960f4821d5486a35@mail.gmail.com> 2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. This might be of use: http://code.activestate.com/recipes/426332/#c2 -- Cheers, Simon B. From neilc at norwich.edu Mon Nov 30 08:11:26 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Nov 2009 13:11:26 GMT Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: <7nhujuF3li0kqU1@mid.individual.net> On 2009-11-27, Diez B. Roggisch wrote: > The only thing that migh be automatized after a piece of code > is valid is normalization, like de-tabifying or making > everything based on 4 space characters indention. No idea if > there is something out there that does that. In vim, you can do something like: :set tabstop=4 :set expandtab :retab -- Neil Cerutti From ebonak at hotmail.com Mon Nov 30 08:34:08 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 08:34:08 -0500 Subject: reading from a text file In-Reply-To: References: Message-ID: baboucarr sanneh wrote: > > i would like to create a python program that would read from a text file > and returns one result at random. #!/usr/bin/env python # assuming the file fits into memory, and you are interested in # random lines from random import randrange f = open('data.txt') data = f.readlines() number = len(data) pick = randrange(0, number) print data[pick] should do the trick. Esmail From __peter__ at web.de Mon Nov 30 08:34:29 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Nov 2009 14:34:29 +0100 Subject: flattening and rebuilding a simple list of lists References: Message-ID: Esmail wrote: > Hi, > > I have a list of lists. The number of sublists may vary. The sizes of > the sublists may also vary. For instance, here I have a list with 3 > sublists of differing sizes. > > [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] > > This list will never be any deeper than this one level. > > What I would like to do is flatten this list, rearrange the items in > the new flattened list and then recreate the list of sublists with the > new content. I would like the sublists to have the same size and order > (relative to each other) as before. > > My code below seems to work, but it feels a bit "hack'ish", and I > am concerned about efficiency - so I would appreciate suggestions. I don't think it's hackish, but here's an alternative: >>> items = [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] >>> flat = sum(items, []) >>> flat.reverse() >>> from itertools import imap, islice >>> flat = iter(flat) >>> [list(islice(flat, size)) for size in imap(len, items)] [['i', 'h', 'g'], ['f', 'e'], ['d', 'c', 'b', 'a']] Peter From lacrima.maxim at gmail.com Mon Nov 30 08:46:11 2009 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 30 Nov 2009 05:46:11 -0800 (PST) Subject: TDD with nose or py.test Message-ID: <2519ffb0-fd49-4340-857b-62fca5c71421@33g2000vbe.googlegroups.com> Hello! I am learning TDD with Python and there is not much information about this topic. Python is shipped with unittest module. That is fine, but I also discovered other libraries: nose and py.test. They promise to make life yet easier for a developer. But I still can't figure out, which combination I should use them in. Nose seems simpler than py.test, but py.test offers more features. And both py.test and nose say that they do not replace unittest module, but extend it. So as I understand my choice should be nose + unittest, or py.test + unittest. And now I'd like to hear about best practices in TDD in Python. Maybe not best practices, but basic approach. So which tests should I write with unittest, which with nose or py.test? How should I combine them? I am learning Python and I need your advice. Thanks in advance. Sorry if my English isn't very proper From marco at sferacarta.com Mon Nov 30 09:01:51 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 30 Nov 2009 15:01:51 +0100 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short > exposure to Python is probably just a feature: Yes, it works as advertised :-/ > which I would expect. Can anyone explain this or give me a workaround? like this? > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda k=k: p(k)) > > for f in l: > f() From duncan.booth at invalid.invalid Mon Nov 30 09:04:16 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2009 14:04:16 GMT Subject: problem with lambda / closures References: Message-ID: Louis Steinberg wrote: >============================== clip here ============ > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda : p(k)) > > for f in l: > f() > >============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. Can anyone explain this or give me a > workaround? Thank you > There's nothing magic about lambda. The same holds true for any function definition. When you have a function that accesses a variable declared at an outer or global scope it always use the value of the variable at the time when it is accessed, not the value when it was defined. Your for loop is exactly equivalent to: def foo(): return p(k) l = [ foo, foo, foo ] k = 3 where it should be more obvious that you will always get the same result. Try this instead: from functools import partial l = [ partial(p, k) for k in [1, 2, 3]] -- Duncan Booth http://kupuguy.blogspot.com From neilc at norwich.edu Mon Nov 30 09:06:50 2009 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Nov 2009 14:06:50 GMT Subject: flattening and rebuilding a simple list of lists References: Message-ID: <7ni1rqF3m40htU1@mid.individual.net> On 2009-11-30, Esmail wrote: > I have a list of lists. The number of sublists may vary. The > sizes of the sublists may also vary. For instance, here I have > a list with 3 sublists of differing sizes. > > [['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i']] > > This list will never be any deeper than this one level. > > What I would like to do is flatten this list, rearrange the > items in the new flattened list and then recreate the list of > sublists with the new content. I would like the sublists to > have the same size and order (relative to each other) as > before. Depending on your usage pattern, directly mutating the original through a simple "view" might be a viable alternative: def set_flattened(lst, i, val): j = 0 while i >= len(lst[j]): i -= len(lst[j]) j += 1 lst[j][i] = val def get_flattened(lst, i): j = 0 while i >= len(lst[j]): i -= len(lst[j]) j += 1 return lst[j][i] A "view" should be easier to use and debug than your current flatten, mutate and unflatten approach. The above functions obviously make the maximum number of assumptions about your data structures, and currently don't work sensibly with negative indices. -- Neil Cerutti From vinay_sajip at yahoo.co.uk Mon Nov 30 09:10:41 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 30 Nov 2009 06:10:41 -0800 (PST) Subject: python logging filters References: <889b8e46-1f99-4e9d-bdd4-59b9a8a32886@k17g2000yqh.googlegroups.com> <895b561e-4aed-40e9-b6a9-036bc5e8fe56@p35g2000yqh.googlegroups.com> <0eaf51df-ed54-4f63-9514-76077a378ee6@v30g2000yqm.googlegroups.com> Message-ID: <6704aaa3-b3d1-4da7-a486-06833cbb0509@p33g2000vbn.googlegroups.com> On Nov 30, 6:52?am, Grimsqueaker wrote: > > So would I be correct in saying that Filters apply only the the object > they are attached to and have no effect on how messages are propagated > through thelogginghierarchy? If this is the case my next question > would be: How can I affect whether or not a message is propagated > further up the tree? > You are correct about how Filters work. To prevent propagation, use the propagate attribute, documented here: http://docs.python.org/library/logging.html#logger-objects Most times, you don't need to use this. For example, if you want events in the A hierarchy to go to one place and events in the B hierarchy to go to another place (e.g. two different log files), you just attach different handlers (e.g. two different FileHandlers) to loggers A and B. If you want a combined log as well, add an appropriate handler to the root logger. I find that things usually work OK if I just determine what handlers I need and attach them to the appropriate loggers, setting the levels on handlers and loggers appropriately. If I need filtering logic for a logger or handler which is more involved than just an integer threshold (which happens less often), I use Filters. Even less often, if I need to block events from a part of the logger hierarchy from bubbling upwards, then I use the propagate attribute. Regards, Vinay Sajip From jonas at geiregat.org Mon Nov 30 09:34:09 2009 From: jonas at geiregat.org (Jonas Geiregat) Date: Mon, 30 Nov 2009 15:34:09 +0100 Subject: Possibly something wrong with mailman ? Message-ID: I'm getting lot's of messages to: undisclosed-recipients:; Which horribly scrambles my email, since no filters are applied to them. From exarkun at twistedmatrix.com Mon Nov 30 09:36:38 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 30 Nov 2009 14:36:38 -0000 Subject: Imitating "tail -f" In-Reply-To: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> References: <811bda74-68e8-4aaa-828f-aa8d225bc745@p35g2000yqh.googlegroups.com> Message-ID: <20091130143638.2549.1083615942.divmod.xquotient.42@localhost.localdomain> On 11:15 am, paul at boddie.org.uk wrote: >On 22 Nov, 05:10, exar... at twistedmatrix.com wrote: >> >>"tail -f" is implemented by sleeping a little bit and then reading to >>see if there's anything new. > >This was the apparent assertion behind the "99 Bottles" concurrency >example: > >http://wiki.python.org/moin/Concurrency/99Bottles > >However, as I pointed out (and as others have pointed out here), a >realistic emulation of "tail -f" would actually involve handling >events from operating system mechanisms. Here's the exchange I had at >the time: > >http://wiki.python.org/moin/Concurrency/99Bottles?action=diff&rev2=12&rev1=11 > >It can be very tricky to think up good examples of multiprocessing >(which is what the above page was presumably intended to investigate), >as opposed to concurrency (which can quite easily encompass responding >to events asynchronously in a single process). > >Paul > >P.S. What's Twisted's story on multiprocessing support? In my limited >experience, the bulk of the work in providing usable multiprocessing >solutions is in the communications handling, which is something >Twisted should do very well. Twisted includes a primitive API for launching and controlling child processes, reactor.spawnProcess. It also has several higher-level APIs built on top of this aimed at making certain common tasks more convenient. There is also a third-party project called Ampoule which provides a process pool to which it is is relatively straightforward to send jobs and then collect their results. Jean-Paul From x7-g5W_rt at earthlink.net Mon Nov 30 09:37:19 2009 From: x7-g5W_rt at earthlink.net (gil_johnson) Date: Mon, 30 Nov 2009 06:37:19 -0800 (PST) Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: On Nov 27, 9:58?am, "Diez B. Roggisch" wrote: [...] > > so i would like to have a tool to intelligently format the code for me > > and make the code more beautiful > > and automated. > > This is not possible. Consider the following situation: > [...] > Both are semantically radically different, and only you know which one > is the right one. > Diez I have to agree with Diez, there is no way to automate this. Some human intervention is needed. What I would like is an editor that will indicate what Python will consider a logical block (and sub-block, and sub-sub-block, etc.) It's complicated. I've tried to think of a way to do it, and have gotten lost after a few changes of indentation. Does anyone know of such a thing? I miss curly braces with an editor that will highlight matching parentheses, braces, etc. Gil From steve at REMOVE-THIS-cybersource.com.au Mon Nov 30 09:50:39 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Nov 2009 14:50:39 GMT Subject: * for generic unpacking and not just for arguments? References: Message-ID: <009d603c$0$26893$c3e8da3@news.astraweb.com> On Sun, 29 Nov 2009 13:45:18 -0600, Tim Chase wrote: >> The feature is available in Python 3.x: >> >>>>> a, b, *c = 1, 2, 3, 4, 5 >>>>> a, b, c >> (1, 2, [3, 4, 5]) >>>>> a, *b, c = 1, 2, 3, 4, 5 >>>>> a, b, c >> (1, [2, 3, 4], 5) > > This is a nice feature of 3.x but I'm disappointed (especially in light > of the move to make more things iterators/generators), that the first > form unpacks and returns a list instead returning the unexhausted > generator. So you want *x behave radically different in subtly different contexts? a, *x, b = iterator would give x a list and iterator run to exhaustion, whereas: a, b, *x = iterator would give x identical to iterator, which hasn't run to exhaustion, while both of these: a, *x, b = sequence a, b, *x = sequence would give x a list, but in the second case, unlike the case of iterators, x would not be identical to sequence. No thank you, I'd prefer a nice, consistent behaviour than a magical "Do what I mean" function. However, having some syntax giving the behaviour you want would be nice. Something like this perhaps? a, b, c = *iterable equivalent to: _t = iter(iterable) a = next(_t) b = next(_t) c = next(_t) # and so on for each of the left-hand names del _t That would be useful. -- Steven From lou at cs.rutgers.edu Mon Nov 30 10:09:07 2009 From: lou at cs.rutgers.edu (Louis Steinberg) Date: Mon, 30 Nov 2009 10:09:07 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: <50DAFD40-92BD-4A55-AE39-09E05220F27C@cs.rutgers.edu> I figured out the answer to my own query. In the original example (see below), there was only one binding for k, which was shared by all the closures, so they all saw the same value. Consider: def fie2(k): return lambda: fie3(k) def fie3(m): print m def fie1(j): return fie2(j) l=map(fie1,[1,2,3]) map(lambda f:f(), l) This prints 1 2 3 because each lambda has its own binding of k. On Nov 30, 2009, at 7:35 AM, Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short > exposure to Python is probably just a feature: > > running > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > with file foo.py containing: > > ============================== clip here ============ > def p(d): > print d > > > l=[ ] > for k in [1,2,3]: > l.append(lambda : p(k)) > > for f in l: > f() > > ============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. Can anyone explain this or give me a > workaround? Thank you > > > > From gh at ghaering.de Mon Nov 30 10:13:16 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 30 Nov 2009 16:13:16 +0100 Subject: dbapi2 select where IN (...) In-Reply-To: References: Message-ID: yota.news at gmail.com wrote: > hello, > > I couldn't find how the dbapi2 planned to handle the sql IN statement. > > ex : > SELECT * FROM table WHERE num IN (2,3,8,9); > > I'd be glad to take advantage of the ? mechanism, but what about > tuples ! > > execute("""SELECT * FROM table WHERE num IN ?;""" , > ((2,3,8,9),)) ...fail... [...] You cannot use parameter binding when the number of parameters is unknown in advance. So you'll have to create this part of the SQL query differently. For example: ids = [2, 3, 8, 9] in_clause = " (" + ",".join([str(id) for id in ids]) + ")" query = "select * from table where num in" + in_clause -- Gerhard From jeanmichel at sequans.com Mon Nov 30 10:22:27 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 30 Nov 2009 16:22:27 +0100 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4B13E333.6090300@sequans.com> Victor Subervi wrote: > > if which == '': > i = 0 > all = '' > while i < len(meanings): > table = '%s\n' % meanings[i] > table += "\n \n \n " % names[i] > j = 0 > for elt in code: > if (j + 8) % 8 == 0: > table += ' \n' > table += ' \n' % code[i] > if (j + 8) % 8 == 0: > table += ' \n' > j += 1 > if table[-6:] != '\n': > table += ' \n' > table += '
    align='center'>%s
    %s
    \n' > all += table + '

    ' > i += 1 > print all > > This all works fine; however, if there is a better way of doing it, > please let me know. > Thanks, > V > I wonder which is worse, looking at your python code, or being blind :o) You should have a look at http://tottinge.blogsome.com/meaningfulnames/ Cheers, Jean-Michel From mail at timgolden.me.uk Mon Nov 30 10:41:38 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Nov 2009 15:41:38 +0000 Subject: reading from a text file In-Reply-To: References: Message-ID: <4B13E7B2.5030405@timgolden.me.uk> Olof Bjarnason wrote: > 2009/11/27 baboucarr sanneh : >> hi all >> >> i would like to create a python program that would read from a text file and >> returns one result at random. >> e.g >> in the text file i have these data >> >> 1.hello >> 2.my name >> 3.is >> 4.World >> >> Your help is highly appreciated..thnx in advance > > Hi babourarr; > > import random > with open("c:/test.txt") as f: > lines = f.read().splitlines() > random_line = lines[random.randrange(len(lines))] > print(random_line) Or, slightly more simply: import random with open ("c:/test.txt") as f: print random.choice (list (f)) You need the list () because random.choice only works on a finite iterable. TJG From duncan.booth at invalid.invalid Mon Nov 30 10:46:02 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Nov 2009 15:46:02 GMT Subject: dbapi2 select where IN (...) References: Message-ID: Gerhard H?ring wrote: >> execute("""SELECT * FROM table WHERE num IN ?;""" , >> ((2,3,8,9),)) ...fail... [...] > > You cannot use parameter binding when the number of parameters is > unknown in advance. So you'll have to create this part of the SQL query > differently. > > For example: > > ids = [2, 3, 8, 9] > in_clause = " (" + ",".join([str(id) for id in ids]) + ")" > query = "select * from table where num in" + in_clause > You can use parameter bindings when you don't know the number of parameters in advance. Just don't create the query string until you do know the number of parameters: ids = [2, 3, 8, 9] query = "select * from table where num in (%s)" % ','.join('?'*len(ids)) execute(query, ids) -- Duncan Booth http://kupuguy.blogspot.com From benjamin.kaplan at case.edu Mon Nov 30 10:54:47 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 30 Nov 2009 10:54:47 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: On Monday, November 30, 2009, Louis Steinberg wrote: > I have run into what seems to be a major bug, but given my short exposure to Python is probably just a feature: > > running > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > with file foo.py containing: > > ============================== clip here ============ > def p(d): > ? ?print d > > > l=[ ] > for k in [1,2,3]: > ? ?l.append(lambda : p(k)) > > for f in l: > ? ?f() > > ============================== clip here ============ > I get output > 3 > 3 > 3 > instead of > 1 > 2 > 3 > which I would expect. ?Can anyone explain this or give me a workaround? ?Thank you > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I don't know if anyone considers python's incomplete implementation of closures a "feature" but it's documented so it's not really a bug either. I believe there is a trick with default arguments to get this to work, but I don't use lambdas enough to remember it. From koranthala at gmail.com Mon Nov 30 10:58:50 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 30 Nov 2009 07:58:50 -0800 (PST) Subject: pywintypes error Message-ID: <90c71adb-a774-4a3e-bb49-423014af4b1b@b36g2000prf.googlegroups.com> Hi, When I try to use Django with Apache and mod_python, I am facing an issue. Since this is a very usual configuration, I hope this issue is already solved. My web sites fail with the following error : "C:\\Python24\\Lib\\site-packages\\win32\\lib\\pywintypes.py", line 124, in?\n __import_pywin32_system_module__("pywintypes", globals()) [Mon Nov 30 15:13:50 2009] [error] [client 127.0.0.1] File"C:\ \Python24\\Lib\\site-packages\\win32\\lib\\pywintypes.py", line 114, in__import_pywin32_system_module__\n assert sys.modules[modname] isold_mod [Mon Nov 30 15:13:50 2009] [error] [client 127.0.0.1] AssertionError I checked the code in pywintypes and it is a sure assertion error: old_mod = sys.modules[modname] # Python can load the module mod = imp.load_dynamic(modname, found) # Check the sys.modules[] behaviour we describe above is true... if sys.version_info < (3,0): assert sys.modules[modname] is old_mod assert mod is old_mod else: assert sys.modules[modname] is not old_mod assert sys.modules[modname] is mod # as above - re-reset to the *old* module object then update globs. sys.modules[modname] = old_mod globs.update(mod.__dict__) I have python 2.4 so, it goes to the first check and fails. Has anyone else faced this issue? How to solve the same? From putumutukas at gmail.com Mon Nov 30 11:03:43 2009 From: putumutukas at gmail.com (a b) Date: Mon, 30 Nov 2009 08:03:43 -0800 (PST) Subject: PySerial and termios Message-ID: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> I have a pain in the a** problem with pyserial- it works 90% of time but on the 10% of time it thorows and termios.error exception with the value (5, 'Input/output error') and i cannot get rid of it :( The system works as follows: A device sends out rs485 data -> rs485 to rs232 converter converts it - > an rs232->usb cable attatched to a computer reads the data. Until now it hasn't bothered me too much since it hasn't been a lot of data (every time i get this exception i unload the pl2303 module from kernel, then reload it, open the com port and hope it won't happen soon). But now the amount of data is getting bigger and the exceptions in the log are quite bothering already so if anyone has a good idea what could affect it i'd be very glad... oh and the settings for the port opening are: self.ser = serial.Serial(self.port, self.baudrate, rtscts=0, xonxoff=0, timeout=0) With best regards, Tanel From deets at nospam.web.de Mon Nov 30 11:15:22 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 30 Nov 2009 17:15:22 +0100 Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: <7ni9cqF3lb4goU1@mid.uni-berlin.de> a b wrote: > I have a pain in the a** problem with pyserial- it works 90% of time > but on the 10% of time it thorows and termios.error exception with the > value (5, 'Input/output error') and i cannot get rid of it :( > The system works as follows: > A device sends out rs485 data -> rs485 to rs232 converter converts it - >> an rs232->usb cable attatched to a computer reads the data. Until > now it hasn't bothered me too much since it hasn't been a lot of data > (every time i get this exception i unload the pl2303 module from > kernel, then reload it, open the com port and hope it won't happen > soon). But now the amount of data is getting bigger and the exceptions > in the log are quite bothering already so if anyone has a good idea > what could affect it i'd be very glad... > oh and the settings for the port opening are: > self.ser = serial.Serial(self.port, self.baudrate, rtscts=0, > xonxoff=0, timeout=0) Did you try a different usb2serial-converter? I've got plenty of them used in the past few years, and frankly, they mostly suck. Big time. With them, all kinds of timing-issues and other problems arose, and some hardware refused to outright work with them. So, I suggest you try & get a hold on as many usb2serial-converters you can get from friends and colleagues, and try out which one works best. There is nothing on the software-side you can do (short from lowering the bps, as this might cover up for some issues due to relaxed timing. But I had to cut down to like 2400 bps or some crap like that, which isn't really usable) Diez From ronn.ross at gmail.com Mon Nov 30 11:20:29 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Mon, 30 Nov 2009 11:20:29 -0500 Subject: New to python Message-ID: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> I have recently come across something called a struct. I have googled this, but have note found a good explanation. Can someone give me a good definition or point me to a page that has one. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco at sferacarta.com Mon Nov 30 11:23:03 2009 From: marco at sferacarta.com (Marco Mariani) Date: Mon, 30 Nov 2009 17:23:03 +0100 Subject: Exec Statement Question In-Reply-To: References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: Jean-Michel Pichavant wrote: >> if which == '': >> i = 0 >> all = '' >> while i < len(meanings): >> table = '%s\n' % meanings[i] >> table += "\n \n \n': should use endswith(), and you won't run the risk of counting wrong if your literal changes. if (j + 8) % 8 == 0: could be simpler: if j % 8 == 0: The pattern: j=0 for elt in code: should be replaced by: for j, elt in enumerate(code): (and of course don't forget to then remove the j+=1 ) You're using the indexing variable i when it'd make much more sense to use zip. Or perhaps meanings and code should be a single list, with each item being a tuple. That's what zip builds, after the fact. But if you build it explicitly, you're less likely to accidentally have an extra or missing element in one of them, and have to deal with that bug. The zip approach might look something like: for meaning, code_element in zip(meanings, code): and then whenever you're using meanings[i] you use meaning, and whenever you're using code[i], you use code_element. (Obviously name changes would help, since code is a list, but the name isn't plural) More generally, when I see code with that much data embedded in it, it cries out for templates. They're known by many different names, but the idea is to write your data structures somewhere else, and manipulate them with the code, instead of embedding it all together. I suspect that each of these functions looks very similar, and they each have their own set of bugs and glitches. That's a good indicator that you need to separate the data. For my web work, I've written my own, very simple templating logic that's only as good as I needed. So I can't comment on the various ones that are already available. But the idea is you put data into one or more text files, which you systematically manipulate to produce your end result. A particular text file might be comma delimited, or defined in sections like an .ini file, or both, or some other mechanism, such as xml. But make it easy to parse, so you can concentrate on getting the data into its final form, consistently, and with common code for all your tables, parameterized by the stuff in the data files. DaveA From inhahe at gmail.com Mon Nov 30 12:14:04 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:14:04 -0500 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: to put it simplistically it's a way of combining multiple variables into one for example, for a person you could have person.haircolor person.echnicity person.age etc. but you can then also manipulate 'person' as a whole like you would any other variable, such as x[n] = person a struct, as far as i know, is like a class but with no methods. or a class is like a struct but with methods that act on the struct's data. i don't think structs technically exist in Python (though they exist in C/C++), but you could always use a plain class like a struct, like this, for a simple example: class Blah: pass b = blah() b.eyecolor = "brown" b.haircolor = "blond" b.ethnicity = "caucasion" On Mon, Nov 30, 2009 at 11:20 AM, Ronn Ross wrote: > I have recently come across something called a struct. I have googled this, > but have note found a good explanation. Can someone give me a good > definition or point me to a page that has one. > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > From rami.chowdhury at gmail.com Mon Nov 30 12:15:34 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 30 Nov 2009 09:15:34 -0800 Subject: Completely OT In-Reply-To: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> On Mon, Nov 30, 2009 at 04:26, Victor Subervi wrote: > Hi; > I need a recommendation. I want to print out data like this: > > > > > and enable the user to select the various colors he wants to add to a list > that would populate itself on the same page where the selections are, and > then, once he's selected all the colors he wants, click to add them all at > once to a table in a database, and move on to the next page. I believe this > is achieved through JSON and AJAX; however, I haven't been able to google > any demonstrations of this sort. Am I correct, or should I use some other > sort of technology? > TIA, > Victor There are a huge number of different ways to do this, including all on the server-side, all on the client side, and a mixture of both as you suggested. What kind of behavior are you actually looking for? From rami.chowdhury at gmail.com Mon Nov 30 12:21:15 2009 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 30 Nov 2009 09:21:15 -0800 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <2f79f590911300921w36b32539n9f552fc7f352b0ae@mail.gmail.com> On Mon, Nov 30, 2009 at 08:20, Ronn Ross wrote: > I have recently come across something called a struct. I have googled this, > but have note found a good explanation. Can someone give me a good > definition or point me to a page that has one. > Where did you come across a "struct"? Depending on context it can be used to refer to a number of different things -- I assume you are looking for either the struct module in the Python standard library (http://docs.python.org/library/struct.html) or trying to implement something like a C "struct" in Python (http://stackoverflow.com/questions/35988/c-like-structures-in-python)? From inhahe at gmail.com Mon Nov 30 12:21:58 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:21:58 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: On Mon, Nov 30, 2009 at 10:54 AM, Benjamin Kaplan wrote: > > I don't know if anyone considers python's incomplete implementation of > closures a "feature" but it's documented so it's not really a bug > either. I believe there is a trick with default arguments to get this > to work, but I don't use lambdas enough to remember it. > -- > http://mail.python.org/mailman/listinfo/python-list > Well default arguments isn't the only way - and *sometimes* it's not workable. Another way to make closures in Python is to define the function a within function b which returns function a and in your loop call function b. i guess if you wanted to do that purely with lambas (outside of using default arguments like i=i) you'd have to do something like a = [] for x in xrange(10): a.append((lambda x: lambda: x)(x)) never tried that though.. From manuel.graune at koeln.de Mon Nov 30 12:22:17 2009 From: manuel.graune at koeln.de (Manuel Graune) Date: Mon, 30 Nov 2009 18:22:17 +0100 Subject: Questions about list-creation Message-ID: Hello, in (most) python documentation the syntax "list()" and "[]" is treated as being more or less the same thing. For example "help([])" and "help(list())" point to the same documentation. Since there are at least two cases where this similarity is not the case, (see below) can someone explain the reasoning behind this and point to further / relevant documentation? (To clarify: I am not complaining about this, just asking.) 1.) when using local variables in list comprehensions, say a=[i for i in xrange(10)] the local variable is not destroyed afterwards: print "a",a print "i",i using the similar code b=list(j for j in xrange(10)) the local variable is destroyed after use: print "b",b print "j",j and 2) a=list([]) vs. b=[[]] Regards, Manuel Graune -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From victorsubervi at gmail.com Mon Nov 30 12:26:40 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:26:40 -0400 Subject: Exec Statement Question In-Reply-To: References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4dc0cfea0911300926w1b42e344wc4657b33be50d998@mail.gmail.com> On Mon, Nov 30, 2009 at 12:25 PM, Carsten Haese wrote: > Victor Subervi wrote: > > Taking out the parenthesis did it! Thanks. Now, you state this is an > > option of last resort. Although this does indeed achieve my desired aim, > > here is a complete example of what I am trying to achieve. The following > > is from 'createTables2.py': > > > > for table in tables: > > try: > > exec 'from options import %s' % table > > except: > > pass > > try: > > exec '%s()' % table > > except: > > pass > > Here's a rough sketch of rewriting that snippet in a way that uses > attribute lookup instead of dynamic code execution: > > #---------------------------------------# > import options > for table in tables: > tablefunc = getattr(options, table) > tablefunc() > #---------------------------------------# > > The main ideas behind this approach are: > > 1) Rather than importing the functions from the options module piecemeal > into the local namespace, I just import the entire options module as its > own separate namespace. > > 2) I use getattr on that separate namespace to look up the desired > function object from the options module. I assign the local name > <> to the resulting function object. > > 3) I call that function using the local name <>. > > Thanks. This is good. Thanks Jean-Michelle for the suggestion on better naming. Thanks Marco for the lxml builder, but I'm happy with just plain old html. V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 30 12:27:41 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:27:41 -0400 Subject: Completely OT In-Reply-To: <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <2f79f590911300915w6a50895fg8f5e8aa9f40fa250@mail.gmail.com> Message-ID: <4dc0cfea0911300927i697e8793t75b3dc6e69a7a6c9@mail.gmail.com> On Mon, Nov 30, 2009 at 1:15 PM, Rami Chowdhury wrote: > On Mon, Nov 30, 2009 at 04:26, Victor Subervi > wrote: > > Hi; > > I need a recommendation. I want to print out data like this: > > > > > > > > > > and enable the user to select the various colors he wants to add to a > list > > that would populate itself on the same page where the selections are, and > > then, once he's selected all the colors he wants, click to add them all > at > > once to a table in a database, and move on to the next page. I believe > this > > is achieved through JSON and AJAX; however, I haven't been able to google > > any demonstrations of this sort. Am I correct, or should I use some other > > sort of technology? > > TIA, > > Victor > > There are a huge number of different ways to do this, including all on > the server-side, all on the client side, and a mixture of both as you > suggested. What kind of behavior are you actually looking for? > Definitely client-side. I just want to enable the client to select all the fields he wants to include, then update to the server once. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From garrickp at gmail.com Mon Nov 30 12:30:30 2009 From: garrickp at gmail.com (Falcolas) Date: Mon, 30 Nov 2009 09:30:30 -0800 (PST) Subject: how to format a python source file with tools? References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: On Nov 30, 7:37?am, gil_johnson wrote: > On Nov 27, 9:58?am, "Diez B. Roggisch" wrote: > [...] > > > > so i would like to have a tool to intelligently format the code for me > > > and make the code more beautiful > > > and automated. > > > This is not possible. Consider the following situation: > > [...] > > Both are semantically radically different, and only you know which one > > is the right one. > > Diez > > I have to agree with Diez, there is no way to automate this. Some > human intervention is needed. What I would like is an editor that will > indicate what Python will consider a logical block (and sub-block, and > sub-sub-block, etc.) > It's complicated. I've tried to think of a way to do it, and have > gotten lost after a few changes of indentation. > Does anyone know of such a thing? > I miss curly braces with an editor that will highlight matching > parentheses, braces, etc. > Gil At least with Windows, you get a number of scripts included in your Python install - under the python directory/tools/scripts. There are several scripts here which are intended to help with indentation issues - such as reindent and pindent. Those might help you out some. Nonetheless, it would be better to implement coding standards that everyone can stick to. From victorsubervi at gmail.com Mon Nov 30 12:30:31 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:30:31 -0400 Subject: Exec Statement Question In-Reply-To: <4B13FD11.1000808@ieee.org> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> <4B13FD11.1000808@ieee.org> Message-ID: <4dc0cfea0911300930l6ae653dfwcbf5a4a52fd2d432@mail.gmail.com> On Mon, Nov 30, 2009 at 1:12 PM, Dave Angel wrote: > Victor Subervi wrote: > >> On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: >> >> >> >>> exec is a statement, and statements don't have "return values." It's >>> not >>> a function, so there are no parentheses in its syntax, either. exec is >>> also >>> a technique of last resort; there's nearly always a better/safer/faster >>> way >>> to accomplish what you might want, but of course you don't say what that >>> is. >>> >>> As for "returning" values, exec by default uses the same global space as >>> your app, so you can just modify a global variable in your "called" code >>> and >>> use it afterwards. >>> >>> abc = 42 >>> value = 12 >>> exec "abc = %d" % value >>> print abc >>> >>> >>> >> >> Taking out the parenthesis did it! Thanks. Now, you state this is an >> option >> of last resort. Although this does indeed achieve my desired aim, here is >> a >> complete example of what I am trying to achieve. The following is from >> 'createTables2.py': >> >> for table in tables: >> try: >> exec 'from options import %s' % table >> except: >> pass >> try: >> exec '%s()' % table >> except: >> pass >> >> >> The following is from 'options.py': >> >> def jewelry(which=''): >> code = [] >> names = [] >> meanings = [] >> code.append(['5', '5½', '6', '6½', '7', '7½', '8', >> '8½', '9', '9½', '10', '10½', '11', '11½', >> '12', >> '12½', '13', '13½']) >> meanings.append('The standard ring sizes.') >> names.append('ringSizes') >> code.append(['Petite (7")', 'Average (7½")', 'Large >> (8")', 'Extra-large (8½")']) >> meanings.append('The standard bracelet sizes.') >> names.append('braceletSizes') >> code.append(['16"', '18"', '20"', '22"', '24"']) >> meanings.append('The standard necklace sizes.') >> names.append('necklaceSizes') >> code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K >> white gold', 'platinum', 'tungsten', 'titanium']) >> meanings.append('The standard jewelry metals.') >> names.append('metals') >> code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', >> 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose >> quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', >> 'turquoise']) >> meanings.append('The standard jewelry stones.') >> names.append('stones') >> if which == '': >> i = 0 >> all = '' >> while i < len(meanings): >> table = '%s\n' % meanings[i] >> table += "
    You should have a look at http://tottinge.blogsome.com/meaningfulnames/ I would also suggest to have a look at lxml.builder, or some kind of template system. From carsten.haese at gmail.com Mon Nov 30 11:25:29 2009 From: carsten.haese at gmail.com (Carsten Haese) Date: Mon, 30 Nov 2009 11:25:29 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: Victor Subervi wrote: > Taking out the parenthesis did it! Thanks. Now, you state this is an > option of last resort. Although this does indeed achieve my desired aim, > here is a complete example of what I am trying to achieve. The following > is from 'createTables2.py': > > for table in tables: > try: > exec 'from options import %s' % table > except: > pass > try: > exec '%s()' % table > except: > pass Here's a rough sketch of rewriting that snippet in a way that uses attribute lookup instead of dynamic code execution: #---------------------------------------# import options for table in tables: tablefunc = getattr(options, table) tablefunc() #---------------------------------------# The main ideas behind this approach are: 1) Rather than importing the functions from the options module piecemeal into the local namespace, I just import the entire options module as its own separate namespace. 2) I use getattr on that separate namespace to look up the desired function object from the options module. I assign the local name <> to the resulting function object. 3) I call that function using the local name <>. HTH, -- Carsten Haese http://informixdb.sourceforge.net From bruno.42.desthuilliers at websiteburo.invalid Mon Nov 30 11:35:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 30 Nov 2009 17:35:24 +0100 Subject: Feature request: String-inferred names In-Reply-To: <4b10e8b3@dnews.tpgi.com.au> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> Message-ID: <4b13f44c$0$7868$426a34cc@news.free.fr> Lie Ryan a ?crit : > On 11/28/2009 3:08 PM, The Music Guy wrote: (snip the part about the proposed feature - which I don't like but that's not the point) >> My >> projects rely on a lot of metaclassing for the automatic generation of >> properties and methods, which saves tremendous amounts of coding. > > If you use it a lot, it is likely 1) you have abused class syntax for > what should have been a dict or 2) what you need is to override > __getattr__/__getattribute__ and __setattr__ I have to totally disagree here. The way the OP uses metaprogramming is a really common and handy solution in lots of frameworks, and drastically reduces the need for boilerplate (and the potential for bugs). It's *WAY* cleaner (readability, introspection, doc etc) and far less error-prone than going the __getattr(ibute)__ / __setattr__, and also way more efficient (from execution time POV). Using __getattr__ and __setattr__ to emulate attributes (usually descriptors) that can be built at class creation time is IMHO what should be labeled as an "abuse" (at best). From gregor.lingl at aon.at Mon Nov 30 11:36:14 2009 From: gregor.lingl at aon.at (Gregor Lingl) Date: Mon, 30 Nov 2009 17:36:14 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: <4B13F47E.3080706@aon.at> Hello Brian, I think the most natural use of the if statement (using turtle graphics) occurs in recursive functions drawing trees, fractals and the like. This is well known from Logo, where recursion is the canonical way of doing repetitions. (But note, that Logo has tail recursion optimizaton!) If you are not yet ready to use recursion with your students, probably many of the problems coming to your mind that need the examination of conditions can be solved better by using a conditional loop (i. e. a while -loop in Python) than by using mere if statements. That is not the case however, if you have to perform actions in the body of a loop, that depend on the current situation. I did a quick search in my repository of examples and found a fairly short and simple script that demonstrates, what I mean: a drunken turtle collecting coins (or whatever) on its random walk. ##### Python script using turtle graphics from turtle import Screen, Turtle from random import randint s = Screen() s.setup(560,560) s.title("A drunken turtle collecting ...") s.tracer(False) writer = Turtle(visible=False) writer.penup() writer.goto(0, -275) coins = [] for i in range(-4,5): for j in range(-4, 5): if i == j == 0: continue c = Turtle(shape="circle") c.color("", "orange") c.shapesize(0.5) c.goto(40*i, 40*j) coins.append(c) s.tracer(True) DRUNKENNESS = 45 t = Turtle(shape="turtle") t.color("black","") points = 0 while abs(t.xcor()) < 200 and abs(t.ycor()) < 200: t.forward(5) t.right(randint(-DRUNKENNESS, DRUNKENNESS)) found = None for c in coins: if t.distance(c) < 10: found = c break if found: found.hideturtle() coins.remove(found) t.shapesize(1+points/5., outline=1+points) points += 1 writer.write("{0} points".format(points), align="center", font=('Arial', 24, 'bold')) ############## End of script You can see a screenshot of a run of this script here: http://www.dropbox.com/gallery/2016850/1/TurtleCollector?h=6b370a The script could be expanded in several ways, e. g. for doing statistical investigations or examinig how the result depends on different parameters like drunkenness etc. Or you distribute the coins randomly ... Does that alter the average "harvest"? Just a suggestion ... Regards, Gregor Brian Blais schrieb: > Hello, > > I was just playing with the turtle module, and thought it was an > interesting way to augment the introduction to python (I teach college > students, who haven't had any programming). It's a great way to > introduce functions, for-loops, and general program structures. > > After a bit of playing, I realized that I couldn't think of many > examples which use turtle with conditional structures (if- and while- > statements), or functions that return values, as opposed to > "procedures" like: > > def square(length): > forward(length) > right(90) > forward(length) > right(90) > forward(length) > right(90) > forward(length) > right(90) > > > If-statements could possibly be used with some sort of random behavior > (if rand()<0.5 ...). Are there any other situations, using turtle, > that these structures would be natural? > > > > thanks, > > Brian Blais > > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > From koranthala at gmail.com Mon Nov 30 11:56:13 2009 From: koranthala at gmail.com (koranthala) Date: Mon, 30 Nov 2009 08:56:13 -0800 (PST) Subject: Python py2exe - memory load error References: <12efdb51-11fd-49a2-8090-fd6c0dc90dbf@g10g2000pri.googlegroups.com> Message-ID: <86b33eb1-6d53-43c1-bce3-9773f416d99a@g4g2000pri.googlegroups.com> On Nov 30, 10:10?am, koranthala wrote: > This is cross post from stackoverflow - I couldnt get the solution > there. Hopefully, nobody would mind. > > I am creating a medium level application in Python. Everything works > well now, and I am trying to make this a windows executable with > py2exe. The executable is created fine, but when I try to run it, it > fails with the following error. > > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\__init__.pyc", line 1, in ? > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\AA.pyc", line 8, in ? > ? File "zipextimporter.pyc", line 82, in load_module > ? File "pyAA\pyAAc.pyc", line 5, in ? > ? File "zipextimporter.pyc", line 98, in load_module > ImportError: MemoryLoadLibrary failed loading pyAA\_pyAAc.pyd > > I am using pyAA in this application. I searched internet, but was > unable to get any solution. I copied msvcp71.dll to windows/system32, > but still issue is there. > > I had solved it earlier (around 7 months back), but my hard drive > crashed and when I try to recreate it, I cannot seem to solve it > now. :-( > > I would be much obliged if someone could help me out here. > > When I use py2exe without bundle files option, it is working > perfectly. But when I use bundle file option, it is failing. > > I tried without zipfile option, wherein it creates a library.zip > alongwith the executable. Again it failed. I did unzip of library.zip > using 7-zip, and found that _pyAAc.pyd is there in pyAA folder inside > the zip file. So, it looks like some issue with memoryloadlibrary > function. > > >dir > > 11/30/2009 ?09:48 AM ? ? ? ? ? ?25,172 AA.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 3,351 Defer.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 2,311 Path.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ?11,216 pyAAc.pyc > 11/30/2009 ?09:48 AM ? ? ? ? ? ? 5,920 Watcher.pyc > 08/20/2005 ?02:00 PM ? ? ? ? ? ?49,152 _pyAAc.pyd > 11/30/2009 ?09:48 AM ? ? ? ? ? ? ? 162 __init__.pyc > > From the trace it does look like it can extract AA.pyc etc. I am using > windows7 - can it be some clue? Can anyone provide some clues on how to solve this issue? I would be much obliged if you could do the same. From python.list at tim.thechases.com Mon Nov 30 11:58:48 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Nov 2009 10:58:48 -0600 Subject: * for generic unpacking and not just for arguments? In-Reply-To: <009d603c$0$26893$c3e8da3@news.astraweb.com> References: <009d603c$0$26893$c3e8da3@news.astraweb.com> Message-ID: <4B13F9C8.3030203@tim.thechases.com> > So you want *x behave radically different in subtly different contexts? > > a, *x, b = iterator > > would give x a list and iterator run to exhaustion, whereas: Using the infix "*x" I'd be fine with x being an iterator too in the same way as the postfix "*x" I'd enjoy, but this would require consuming all-but-the-remaining-fixed and the converting the middle bits back into an iterator...which isn't that much different from the current implementation of "a, *x, b = itr" with x = iter(x) after the tuple assignment. Not a great gain, but at least consistent to remove that burr. It doesn't allow for infinite generators, but that's a somewhat nonsensical request anyways :) "b = INF"? "b=-INF"? "b=K"? and it gets weirder with a,*x,b,c,d = inf_seq_of_monotonically_increasing_primes() if you can get me b, c, and d in a finite amount of time, you get some sorta prize :) > However, having some syntax giving the behaviour you want would be nice. > Something like this perhaps? > > a, b, c = *iterable > > equivalent to: > > _t = iter(iterable) > a = next(_t) > b = next(_t) > c = next(_t) # and so on for each of the left-hand names > del _t > > That would be useful. But yes, that's even better for my use case, as it lacks the ugly "*_" sponge to soak up the remainder and removes my need to track the number of items on the LHS of the assignment. That seems it would involve a new Python construct/syntax rather than the existing py3k syntax. Or at least the removal of the "ValueError: too many values to unpack" error. That would be a lovely addition (when the new-feature-ban is lifted :) -tim From gherron at islandtraining.com Mon Nov 30 12:05:16 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 30 Nov 2009 09:05:16 -0800 Subject: New to python In-Reply-To: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <4B13FB4C.9050506@islandtraining.com> Ronn Ross wrote: > I have recently come across something called a struct. I have googled > this, but have note found a good explanation. Can someone give me a > good definition or point me to a page that has one. > > Thanks Well... Since you don't give us *any* information, other then the single word "struct", let's start with this: Python has a module named struct: http://docs.python.org/library/struct.html#module-struct Is that what you wanted? Gary Herron From gnarlodious at gmail.com Mon Nov 30 12:05:16 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 09:05:16 -0800 (PST) Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: Thanks for the help, but it doesn't work. All I get is an error like: UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in position 0: ordinal not in range(128) It does work in Terminal interactively, after I import the sys module. But my script doesn't act the same. Here is my entire script: #!/usr/bin/python print("Content-type:text/plain;charset=utf-8\n\n") import sys sys.stdout.buffer.write('?\n'.encode("utf-8")) All I get is the despised "Internal Server Error" with Console reporting: malformed header from script. Bad header=\xe6\x99\x89 Strangely, if I run the script in Terminal it acts as expected. This is OSX 10.6 2,, Python 3.1.1. And it is frustrating because my entire website is hung up on this one line I have been working on for 5 days. -- Gnarlie http://Gnarlodious.com From davea at ieee.org Mon Nov 30 12:12:49 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 30 Nov 2009 12:12:49 -0500 Subject: Exec Statement Question In-Reply-To: <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> References: <4dc0cfea0911291211j4e7cee40u86ab04f5f724c8b8@mail.gmail.com> <4B133AA3.4060405@ieee.org> <4dc0cfea0911300323w452da5c4kb5bf795b0c18413f@mail.gmail.com> Message-ID: <4B13FD11.1000808@ieee.org> Victor Subervi wrote: > On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote: > > >> exec is a statement, and statements don't have "return values." It's not >> a function, so there are no parentheses in its syntax, either. exec is also >> a technique of last resort; there's nearly always a better/safer/faster way >> to accomplish what you might want, but of course you don't say what that is. >> >> As for "returning" values, exec by default uses the same global space as >> your app, so you can just modify a global variable in your "called" code and >> use it afterwards. >> >> abc = 42 >> value = 12 >> exec "abc = %d" % value >> print abc >> >> > > Taking out the parenthesis did it! Thanks. Now, you state this is an option > of last resort. Although this does indeed achieve my desired aim, here is a > complete example of what I am trying to achieve. The following is from > 'createTables2.py': > > for table in tables: > try: > exec 'from options import %s' % table > except: > pass > try: > exec '%s()' % table > except: > pass > > > The following is from 'options.py': > > def jewelry(which=''): > code = [] > names = [] > meanings = [] > code.append(['5', '5½', '6', '6½', '7', '7½', '8', > '8½', '9', '9½', '10', '10½', '11', '11½', '12', > '12½', '13', '13½']) > meanings.append('The standard ring sizes.') > names.append('ringSizes') > code.append(['Petite (7")', 'Average (7½")', 'Large > (8")', 'Extra-large (8½")']) > meanings.append('The standard bracelet sizes.') > names.append('braceletSizes') > code.append(['16"', '18"', '20"', '22"', '24"']) > meanings.append('The standard necklace sizes.') > names.append('necklaceSizes') > code.append(['14K gold', '18K gold', 'silver', '14K white gold', '18K > white gold', 'platinum', 'tungsten', 'titanium']) > meanings.append('The standard jewelry metals.') > names.append('metals') > code.append(['diamond', 'emerald', 'ruby', 'sapphire', 'pearl', 'opal', > 'topaz', 'onyx', 'lapiz lazuli', 'tanzanite', 'garnet', 'quartz', 'rose > quartz', 'amethyst', 'alexandrite', 'peridot', 'tourmaline', 'citrine', > 'turquoise']) > meanings.append('The standard jewelry stones.') > names.append('stones') > if which == '': > i = 0 > all = '' > while i < len(meanings): > table = '%s\n' % meanings[i] > table += "\n \n \n > " % names[i] > j = 0 > for elt in code: > if (j + 8) % 8 == 0: > table += ' \n' > table += ' \n' % code[i] > if (j + 8) % 8 == 0: > table += ' \n' > j += 1 > if table[-6:] != '\n': > table += ' \n' > table += '
    %s
    %s
    \n' > all += table + '

    ' > i += 1 > print all > > This all works fine; however, if there is a better way of doing it, please > > let me know. > Thanks, > V > > The parentheses can't do any harm for that particular expression, so that wasn't your problem. But I'm glad you fixed whatever else was your problem. I mentioned it because sometimes they can cause problems, and you shouldn't get in bad habits. (things like if, return, and exec are all statements that take an expression, but do not need parentheses.) I'll throw in a comment here about a bare except. Also a bad idea. You could easily mask some other problem involved in the import, and the program silently continues. If you know of a specific problem, or category of problems that you want to ignore, then pick an exception, or tuple of exceptions, to do that. The immediate question is how to get rid of exec. You're using it two places. First case, you're just using it to extract specific objects from that module's namespace. Assuming you've already imported options earlier in the code, you can replace from options import xyzzy by optfunc = options.xyzzy or option_func = getattr(options, "xyzzy", None) or even option_func = getattr(options, "xyzzy", dummyfunc) (where dummyfunc() is a function which takes no arguments and does nothing) Now, assuming you plan to call each such function immediately, you can just say option_func() in the same loop. def dummyfunc(): pass .... for table in tables: option_func = getattr(options, table, dummyfunc) option_func() If you didn't have the dummyfunc, you'd need an "if option_func" in there. Naturally, if this "tables" comes from the user, you need to give him some feedback, so perhaps dummyfunc isn't an empty function after all, but is supplied in options.py Other comments about your code: Someone else has mentioned names, so I won't dwell on that. if table[-6:] != '
    blueredbluered
    \n \n \n >> " % names[i] >> j = 0 >> for elt in code: >> if (j + 8) % 8 == 0: >> table += ' \n' >> table += ' \n' % code[i] >> if (j + 8) % 8 == 0: >> table += ' \n' >> j += 1 >> if table[-6:] != '\n': >> table += ' \n' >> table += '
    %s
    %s
    \n' >> all += table + '

    ' >> i += 1 >> print all >> >> This all works fine; however, if there is a better way of doing it, please >> >> > > let me know. >> Thanks, >> V >> >> >> > The parentheses can't do any harm for that particular expression, so that > wasn't your problem. But I'm glad you fixed whatever else was your problem. > I mentioned it because sometimes they can cause problems, and you shouldn't > get in bad habits. (things like if, return, and exec are all statements > that take an expression, but do not need parentheses.) > > I'll throw in a comment here about a bare except. Also a bad idea. You > could easily mask some other problem involved in the import, and the program > silently continues. If you know of a specific problem, or category of > problems that you want to ignore, then pick an exception, or tuple of > exceptions, to do that. > > > The immediate question is how to get rid of exec. You're using it two > places. First case, you're just using it to extract specific objects from > that module's namespace. > > Assuming you've already imported options earlier in the code, you can > replace > from options import xyzzy > by > optfunc = options.xyzzy > or > option_func = getattr(options, "xyzzy", None) > or even > option_func = getattr(options, "xyzzy", dummyfunc) > (where dummyfunc() is a function which takes no arguments and does nothing) > > Now, assuming you plan to call each such function immediately, you can just > say > option_func() > in the same loop. > > > def dummyfunc(): > pass > > .... > for table in tables: > option_func = getattr(options, table, dummyfunc) > option_func() > > If you didn't have the dummyfunc, you'd need an "if option_func" in there. > > > Naturally, if this "tables" comes from the user, you need to give him some > feedback, so perhaps dummyfunc isn't an empty function after all, but is > supplied in options.py > > Other comments about your code: Someone else has mentioned names, so I > won't dwell on that. > > if table[-6:] != '\n': > > should use endswith(), and you won't run the risk of counting wrong if > your literal changes. > > if (j + 8) % 8 == 0: > > could be simpler: > > if j % 8 == 0: > > The pattern: > j=0 > > for elt in code: > should be replaced by: > for j, elt in enumerate(code): > > (and of course don't forget to then remove the j+=1 ) > > You're using the indexing variable i when it'd make much more sense to use > zip. Or perhaps meanings and code should be a single list, with each item > being a tuple. That's what zip builds, after the fact. But if you build it > explicitly, you're less likely to accidentally have an extra or missing > element in one of them, and have to deal with that bug. > > The zip approach might look something like: > for meaning, code_element in zip(meanings, code): > > and then whenever you're using meanings[i] you use meaning, and whenever > you're using code[i], you use code_element. (Obviously name changes would > help, since code is a list, but the name isn't plural) > > > > More generally, when I see code with that much data embedded in it, it > cries out for templates. They're known by many different names, but the > idea is to write your data structures somewhere else, and manipulate them > with the code, instead of embedding it all together. I suspect that each of > these functions looks very similar, and they each have their own set of bugs > and glitches. That's a good indicator that you need to separate the data. > > For my web work, I've written my own, very simple templating logic that's > only as good as I needed. So I can't comment on the various ones that are > already available. But the idea is you put data into one or more text > files, which you systematically manipulate to produce your end result. A > particular text file might be comma delimited, or defined in sections like > an .ini file, or both, or some other mechanism, such as xml. But make it > easy to parse, so you can concentrate on getting the data into its final > form, consistently, and with common code for all your tables, parameterized > by the stuff in the data files. > > Yeah, maybe on the next iteration after I've finished the shopping cart and got it working. I'm the one who does everything right now, so it's not an issue for me. Thanks, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From senhor.abrantes at gmail.com Mon Nov 30 12:35:31 2009 From: senhor.abrantes at gmail.com (joao abrantes) Date: Mon, 30 Nov 2009 17:35:31 +0000 Subject: os.starfile() linux Message-ID: <880fa1d40911300935v8df6708xc3c5957d3db25cd9@mail.gmail.com> i want a python program to start another python script and i want it to open a new shell and to put the output of the new python program there.. how can it be done? -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.org.uk Mon Nov 30 12:35:57 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 30 Nov 2009 09:35:57 -0800 (PST) Subject: New to python References: <9c8c445f0911300820w5992b426ubec437da7aa19966@mail.gmail.com> Message-ID: <5e77bdd7-deca-4d65-a6e0-7f40d0951d0e@v37g2000vbb.googlegroups.com> On 30 Nov, 18:14, inhahe wrote: > i don't think structs technically exist in Python (though they exist > in C/C++), but you could always use a plain class like a struct, like > this, for a simple example: > > class Blah: > ? pass > > b = blah() > b.eyecolor = "brown" [...] Yes, a "bare" class can be instantiated and the attributes of the created instance populated as desired. In fact, there are structures (or "structs") provided by various built-in extensions supplied with Python, such as the time structure (struct_time), although this appears as a class if you try to investigate it more closely from the Python prompt. See the Objects/structseq.c file in the Python source distribution for how such structures are actually implemented, however. Paul From alfps at start.no Mon Nov 30 12:38:56 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 18:38:56 +0100 Subject: Req. for comments section "Basic Data" in intro book In-Reply-To: References: Message-ID: * Alf P. Steinbach: > I added a section on "basic data" to ch 2 of my writings, an > introduction to programming (with Python as main language). > > The intended reader is someone who is intelligent and wants to learn > programming but knows little or nothing about it. > > As before it would be nice with feedback on this. > > > Format: PDF > > > > Current contents: > > 1 Getting started. 1 > 1.1 Python variants, implementations and distributions. 1 > 1.2 Download and install a Python implementation. 2 > 1.3 Test-drive the Python interpreter. 2 > 1.4 Create and run a Python console program. 4 > 1.5 Syntax highlighting and programmers' editors. 6 > 1.6 Create and run a Python GUI program. 7 > 1.7 About compilation. 9 > 1.8 About standalone Windows programs & other kinds. 10 > 1.9 Browse the local documentation. 11 > EOT 12 > > 2 Basic concepts. 1 > 2.1 Super-basic concept: why programming is not DWIM. 1 > 2.2 Reported errors. 4 > 2.2.1 Case-sensitity. 4 > 2.2.2 Syntax / compilation errors. 4 > 2.2.3 Runtime errors / crashes. 5 > 2.3 A programming exploration tool: turtle graphics. 6 > 2.4 Naming things. 8 > 2.4.1 Naming actions: routines. 8 > 2.4.2 Naming data part I: variables. 11 > 2.4.3 Naming data part II: routine arguments. 13 > 2.5 Controlling the flow of execution. 14 > 2.5.1 Repeating actions automatically: loops. 14 > 2.5.2 Basic comparisions & boolean values. 16 > 2.5.3 Interlude I: a function graph program / about types. 17 > 2.5.4 Automated action choices. 21 > 2.5.5 Value-producing (function-like) routines. 23 > 2.5.6 Interlude II: a graph with zeroes marked / about program > structure. 26 > 2.5.7 Dynamically nested actions: recursive routines. 28 > 2.6 Basic data. 36 > 2.6.1 Basic fundamental types / strings & concatenation. 36 > 2.6.2 Indexing and single characters (+ vaguely about sequences in > general). 39 > 2.6.3 Interlude III: a ROT-13 encryption/decryption program, > refactoring. 40 > 2.6.4 Attributes, methods, objects. 43 > 2.6.5 Doc strings. 44 > 2.6.6 Interlude IV: attribute names as strings, listing str attributes. 45 > 2.6.7 References. 46 > EOT 49 > > The section on "References", 2.6.7, is about references in Python, it's > not a list of references. :-) Based on feedback I received in private communications I've improved (I hope) the wording in various places, and expanded a bit on the last section. I've placed the latest version also in Google Docs, without yet removing the original -- the file names are the same but they have different dates. Comments welcome. Cheers, - Alf From jpiitula at ling.helsinki.fi Mon Nov 30 12:39:00 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Nov 2009 19:39:00 +0200 Subject: problem with lambda / closures References: Message-ID: Benjamin Kaplan writes: > On Monday, November 30, 2009, Louis Steinberg wrote: > > I have run into what seems to be a major bug, but given my short > > exposure to Python is probably just a feature: > > > > running > > Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) > > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > > > with file foo.py containing: > > > > ============================== clip here ============ > > def p(d): > > ? ?print d > > > > > > l=[ ] > > for k in [1,2,3]: > > ? ?l.append(lambda : p(k)) > > > > for f in l: > > ? ?f() > > > > ============================== clip here ============ > > I get output > > 3 > > 3 > > 3 > > instead of > > 1 > > 2 > > 3 > > which I would expect. ?Can anyone explain this or give me a > > workaround? ?Thank you > > I don't know if anyone considers python's incomplete implementation > of closures a "feature" but it's documented so it's not really a bug > either. I believe there is a trick with default arguments to get > this to work, but I don't use lambdas enough to remember it. That trick has been shown in some branch of the present thread. Here's a non-trick solution, which I saved in file quux.py: def p(d): print d l=[] for k in [1,2,3]: l.append((lambda k : lambda : p(k))(k)) for f in l: f() Python 2.3.4 (#1, Jul 16 2009, 07:03:37) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import quux 1 2 3 >>> From inhahe at gmail.com Mon Nov 30 12:39:45 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:39:45 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: i'm pretty new to javascript programming, but i'm pretty sure you just need ajax, which AFAIK is a highly technical way of saying "using javascript in a way that makes web pages interactive" JSON afaik is a way of data to and from the server that allows for lists and more variable types and such, but also requires the user download a third-party js file that implements JSON. i don't think you'd technically need JSON, because you could simply send the server a string of all the colors selected delimited by a space or | or something. javascript also probably has inherent functions for generating xml, considering that the object you use to communicate with the server is an xmlhttprequst. but i think xml might be overkill in this case. the javascript would populate the list for the colors the user selects (the easiest way would probably be to give the list an id and use getElementByID()), and then when he's done it would create an xmlhttprequest object to send the data to the server. On Mon, Nov 30, 2009 at 7:26 AM, Victor Subervi wrote: > Hi; > I need a recommendation. I want to print out data like this: > > blue > red > > and enable the user to select the various colors he wants to add to a list > that would populate itself on the same page where the selections are, and > then, once he's selected all the colors he wants, click to add them all at > once to a table in a database, and move on to the next page. I believe this > is achieved through JSON and AJAX; however, I haven't been able to google > any demonstrations of this sort. Am I correct, or should I use some other > sort of technology? > TIA, > Victor > > -- > http://mail.python.org/mailman/listinfo/python-list > > From invalid at invalid.invalid Mon Nov 30 12:41:12 2009 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 30 Nov 2009 17:41:12 +0000 (UTC) Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: On 2009-11-30, a b wrote: > I have a pain in the a** problem with pyserial- it works 90% > of time but on the 10% of time it thorows and termios.error > exception with the value (5, 'Input/output error') and i > cannot get rid of it :( Sounds like faulty converter or a bug in the device driver to me. > The system works as follows: > A device sends out rs485 data -> rs485 to rs232 converter converts it - >> an rs232->usb cable attatched to a computer reads the data. Until > now it hasn't bothered me too much since it hasn't been a lot > of data (every time i get this exception i unload the pl2303 > module from kernel, then reload it, open the com port Does that get rid of the error? If so, then it's definitely a problem with the converter or device-driver. > and hope it won't happen soon). But now the amount of data is > getting bigger and the exceptions in the log are quite > bothering already so if anyone has a good idea what could > affect it i'd be very glad... oh and the settings for the port > opening are: self.ser = serial.Serial(self.port, > self.baudrate, rtscts=0, xonxoff=0, timeout=0) Unless you want to try to troubleshoot the device driver and USB traffic, the only suggestion I have is to try different converters and/or different versions of the driver. -- Grant Edwards grante Yow! If Robert Di Niro at assassinates Walter Slezak, visi.com will Jodie Foster marry Bonzo?? From ebonak at hotmail.com Mon Nov 30 12:48:15 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 12:48:15 -0500 Subject: flattening and rebuilding a simple list of lists In-Reply-To: References: Message-ID: Ok, well I'm glad no one threw up their hands in horror to the code I posted. I'll have to study the alternate solutions offered (thanks!) Esmail From inhahe at gmail.com Mon Nov 30 12:48:56 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:48:56 -0500 Subject: reading from a text file In-Reply-To: <4B13E7B2.5030405@timgolden.me.uk> References: <4B13E7B2.5030405@timgolden.me.uk> Message-ID: i don't understand the point of using 'with' but i don't understand what 'with' does at all i've tried to understand it a few times anyway here: import random result = random.choice(open("c:\\test.txt").readlines()) On Mon, Nov 30, 2009 at 10:41 AM, Tim Golden wrote: > Olof Bjarnason wrote: >> >> 2009/11/27 baboucarr sanneh : >>> >>> hi all >>> >>> i would like to create a python program that would read from a text file >>> and >>> returns one result at random. >>> e.g >>> in the text file i have these data >>> >>> 1.hello >>> 2.my name >>> 3.is >>> 4.World >>> >>> Your help is highly appreciated..thnx in advance >> >> Hi babourarr; >> >> import random >> with open("c:/test.txt") as f: >> ?lines = f.read().splitlines() >> random_line = lines[random.randrange(len(lines))] >> print(random_line) > > Or, slightly more simply: > > import random > with open ("c:/test.txt") as f: > ?print random.choice (list (f)) > > > You need the list () because random.choice only works > on a finite iterable. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Mon Nov 30 12:49:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 13:49:09 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> On Mon, Nov 30, 2009 at 1:39 PM, inhahe wrote: > i'm pretty new to javascript programming, but i'm pretty sure you just > need ajax, which AFAIK is a highly technical way of saying "using > javascript in a way that makes web pages interactive" > JSON afaik is a way of data to and from the server that allows for > lists and more variable types and such, but also requires the user > download a third-party js file that implements JSON. i don't think > you'd technically need JSON, because you could simply send the server > a string of all the colors selected delimited by a space or | or > something. > javascript also probably has inherent functions for generating xml, > considering that the object you use to communicate with the server is > an xmlhttprequst. but i think xml might be overkill in this case. > > the javascript would populate the list for the colors the user selects > (the easiest way would probably be to give the list an id and use > getElementByID()), and then when he's done it would create an > xmlhttprequest object to send the data to the server. > If I'm not mistaken, that won't help me actually print to screen the user's choices as he selects them, which in my application, is important. Please advise. TIA, V > > On Mon, Nov 30, 2009 at 7:26 AM, Victor Subervi > wrote: > > Hi; > > I need a recommendation. I want to print out data like this: > > > > blue > > red > > > > and enable the user to select the various colors he wants to add to a > list > > that would populate itself on the same page where the selections are, and > > then, once he's selected all the colors he wants, click to add them all > at > > once to a table in a database, and move on to the next page. I believe > this > > is achieved through JSON and AJAX; however, I haven't been able to google > > any demonstrations of this sort. Am I correct, or should I use some other > > sort of technology? > > TIA, > > Victor > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Mon Nov 30 12:57:11 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 30 Nov 2009 12:57:11 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... Message-ID: Hello all. I am using the PIL 1.1.6 and Python 2.6.x under XP without any problems. However, I can't display any images under Vista or Windows 7. I could understand Windows 7 as it's relatively new, but Vista has been around for a bit. Sample code: import Image im = Image.open('c://mypic.jpg') im.show() this will work fine under XP, but under Windows 7 and Vista the default image viewer will come up with some error message that the image can't be found. I tried with an external image view program and tried to supply it via the command parameter to show - but that too didn't work. Definition: im.show(self, title=None, command=None) Any suggestions/help/workarounds? If you can get this to work with Vista or Windows 7 I'd love to hear from you. Thanks! Esmail From jjposner at optimum.net Mon Nov 30 12:58:36 2009 From: jjposner at optimum.net (John Posner) Date: Mon, 30 Nov 2009 12:58:36 -0500 Subject: Noobie python shell question References: <14e60ad4-4084-4870-b9e5-80dde6330662@u7g2000yqm.googlegroups.com> Message-ID: On Sun, 29 Nov 2009 22:03:09 -0500, tuxsun wrote: > I've been working in the shell on and off all day, and need to see if > a function I defined earlier is defined in the current shell I'm > working in. > > Is there a shell command to get of list of functions I've defined? > How about this: ################## > python Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a,b,c = 1,2,3 >>> def spam(): return None ... >>> def eggs(): return None ... >>> dir() ['__builtins__', '__doc__', '__name__', '__package__', 'a', 'b', 'c', 'eggs', 'spam'] >>> locals() {'a': 1, 'c': 3, 'b': 2, 'spam': , '__builtins__': , 'eggs': , '__package__': None, '__name__': '__main__', '__doc__': None} >>> [name for name in locals() if callable(locals()[name])] Traceback (most recent call last): File "", line 1, in RuntimeError: dictionary changed size during iteration >>> [name for name in locals() if callable(locals()[name])] ['spam', 'eggs'] ################## To avoid the harmless RuntimeError, define "name" before using it in the list comprehension (the final expression) -- e.g.: name = 1 -John From inhahe at gmail.com Mon Nov 30 12:58:39 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 12:58:39 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi wrote: > > > On Mon, Nov 30, 2009 at 1:39 PM, inhahe wrote: >> >> i'm pretty new to javascript programming, but i'm pretty sure you just >> need ajax, which AFAIK is a highly technical way of saying "using >> javascript in a way that makes web pages interactive" >> JSON afaik is a way of data to and from the server that allows for >> lists and more variable types and such, but also requires the user >> download a third-party js file that implements JSON. ?i don't think >> you'd technically need JSON, because you could simply send the server >> a string of all the colors selected delimited by a space or | or >> something. >> javascript also probably has inherent functions for generating xml, >> considering that the object you use to communicate with the server is >> an xmlhttprequst. but i think xml might be overkill in this case. >> >> the javascript would populate the list for the colors the user selects >> (the easiest way would probably be to give the list an id and use >> getElementByID()), and then when he's done it would create an >> xmlhttprequest object to send the data to the server. > > If I'm not mistaken, that won't help me actually print to screen the user's > choices as he selects them, which in my application, is important. Please > advise. > TIA, > V sure, that's where this part comes in: the javascript would populate the list for the colors the user selects (the easiest way would probably be to give the list an id and use getElementByID()) so basically you'd define, e.g., an onClick="blah('red'); return true" within the red element's tag, and then define a function blah(x) that says getElementById("my_list_id").innerHtml += "
    " + x; and of course give your list textarea an id="my_list_id" attribute in the tag. that could be slightly wrong, my javascript's rusty From inhahe at gmail.com Mon Nov 30 13:00:03 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:00:03 -0500 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > wrote: >> >> >> If I'm not mistaken, that won't help me actually print to screen the user's >> choices as he selects them, which in my application, is important. Please >> advise. >> TIA, >> V > > > sure, that's where this part comes in: > > the javascript would populate the list for the colors the user selects > (the easiest way would probably be to give the list an id and use > getElementByID()) > > so basically you'd define, e.g., an onClick="blah('red'); return true" > within the red element's tag, and then define a function blah(x) that > says > getElementById("my_list_id").innerHtml += "
    " + x; > and of course give your list textarea an id="my_list_id" attribute in the tag. > > that could be slightly wrong, my javascript's rusty > also don't forget to sanitize the data you receive before committing it to the database, or someone can hack the javascript and send an SQL injection attack From python at mrabarnett.plus.com Mon Nov 30 13:00:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Nov 2009 18:00:06 +0000 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <4b132c1b$1@dnews.tpgi.com.au> References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <4B140826.4070707@mrabarnett.plus.com> Lie Ryan wrote: > On 11/30/2009 12:38 PM, Esmail wrote: >> Thanks all!! I get it now :-) >> >> It helped to have a number of different explanations, thanks >> for taking the time to post. Much appreciated. > > I generally do not expect operator precedence to be reliable at all > except for: > > + - (binary ops, not the unary) > * / > ** > > for other operators I would have explicit parens. It's too much work to > remember the rest of the precedence sheet. Most programming languages don't differentiate in text between the number "negative 3" and the expression "negated 3". APL does. The former is written as "?3" (3 preceded by the overscore character) and the latter as "-3" (3 preceded by the minus sign). From ebonak at gmail.com Mon Nov 30 13:04:45 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 10:04:45 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: Message-ID: > > ? im = Image.open('c://mypic.jpg') sorry, slip of the finger, there's only one forward slash or you can use two backward slashes. The problem isn't with opening it (I know it opens fine since I can get its size attribute via im.size) - the show() is the problem. Esmail From lie.1296 at gmail.com Mon Nov 30 13:07:36 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:07:36 +1100 Subject: Feature request: String-inferred names In-Reply-To: <4b13f44c$0$7868$426a34cc@news.free.fr> References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <4b13f44c$0$7868$426a34cc@news.free.fr> Message-ID: <4b140a4d@dnews.tpgi.com.au> On 12/1/2009 3:35 AM, Bruno Desthuilliers wrote: > Lie Ryan a ?crit : >> On 11/28/2009 3:08 PM, The Music Guy wrote: > > (snip the part about the proposed feature - which I don't like but > that's not the point) > >>> My >>> projects rely on a lot of metaclassing for the automatic generation of >>> properties and methods, which saves tremendous amounts of coding. >> >> If you use it a lot, it is likely 1) you have abused class syntax for >> what should have been a dict or 2) what you need is to override >> __getattr__/__getattribute__ and __setattr__ > > I have to totally disagree here. The way the OP uses metaprogramming is > a really common and handy solution in lots of frameworks, and > drastically reduces the need for boilerplate (and the potential for > bugs). It's *WAY* cleaner (readability, introspection, doc etc) and far > less error-prone than going the __getattr(ibute)__ / __setattr__, and > also way more efficient (from execution time POV). I won't argue with the usefulness of metaclass, I agree that metaclass is the cleanest way to implement certain things; but the main point is the OP's use of getattr/setattr while he got full control of the namespace dictionary. > Using __getattr__ and __setattr__ to emulate attributes (usually > descriptors) that can be built at class creation time is IMHO what > should be labeled as an "abuse" (at best). From manu3d at gmail.com Mon Nov 30 13:08:13 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Mon, 30 Nov 2009 10:08:13 -0800 (PST) Subject: Python Statements/Keyword Localization References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> Message-ID: <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> Thank you all for the insights. I particularly like the broad spread of opinions on the subject. Indeed when I wrote the original post my thoughts were with those young students of non-English speaking countries that start learning to program before they learn English. My case is almost one of those: I started at home when I was 13, toying around with Basic, and at the time not only I didn't know English, but for a few more years I would be learning only French. Later I did start learning English but I still found that while learning programming in Pascal at school its English keywords were somehow an interruption of my mental flow. At the time (20 years ago) localization wasn't a particularly big thing and this issue would have been a bit of a lost cause. But as the world is becoming more and more interconnected I think it is important that we all make an effort to respect cultural needs and sensitivities of both non-western adults and youngsters alike. Ultimately I certainly appreciate the ubiquity of English even though in the interest of fairness and efficiency I'd prefer the role of common language to be given to a constructed language, such as Ido. But it doesn't take a particularly religious person to see that "do to others as you would want them do to you" tends to be a valid principle, and in the same way the world would be at a loss if an Indian university came up with a wonderful programming language available only in Sanskrit, the world is at a loss not having a beautiful language such as Python natively available in other scripts. Again, thank you all! Manu From aahz at pythoncraft.com Mon Nov 30 13:10:25 2009 From: aahz at pythoncraft.com (Aahz) Date: 30 Nov 2009 10:10:25 -0800 Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: In article , Gnarlodious wrote: > >Thanks for the help, but it doesn't work. All I get is an error like: > >UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in >position 0: ordinal not in range(128) No time to give you more info, but you probably need to change the encoding of sys.stdout. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. From inhahe at gmail.com Mon Nov 30 13:12:52 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:12:52 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: On Mon, Nov 30, 2009 at 12:22 PM, Manuel Graune wrote: > > Hello, > > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j > I could be wrong, but I think this was actually a bug that was fixed later. > and 2) > > a=list([]) > > vs. > > b=[[]] > those don't return the same thing list([]) will create a shallow copy of [], which will of course be [] i can't think of a place where you'd want to use list() instead of [], but sometimes you might want to use 'list', such as in a defaultdict, in which case it's being used as a factory > > Regards, > > Manuel Graune > > -- > A hundred men did the rational thing. The sum of those rational choices was > called panic. Neal Stephenson -- System of the world > http://www.graune.org/GnuPG_pubkey.asc > Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A ?5828 5476 7E92 2DB4 3C99 > -- > http://mail.python.org/mailman/listinfo/python-list > From lie.1296 at gmail.com Mon Nov 30 13:13:48 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:13:48 +1100 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <4b140bc1$1@dnews.tpgi.com.au> On 12/1/2009 4:22 AM, Manuel Graune wrote: > > Hello, > > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j It's not so much about list() vs. [] but generator comprehension vs. list comprehension. list() takes a generator comprehension, while [listcomp] is its own syntax. List comprehension leaked its "loop counter" to the surrounding namespace, while generator comprehension got its own tiny namespace. This "bug" (or feature, depending on your political alignment) is fixed in Python 3.x: Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = [i for i in range(10)] >>> i Traceback (most recent call last): File "", line 1, in NameError: name 'i' is not defined >>> a = list(i for i in range(10)) >>> i Traceback (most recent call last): File "", line 1, in NameError: name 'i' is not defined >>> ^Z From victorsubervi at gmail.com Mon Nov 30 13:21:00 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:21:00 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > > wrote: > >> > >> > >> If I'm not mistaken, that won't help me actually print to screen the > user's > >> choices as he selects them, which in my application, is important. > Please > >> advise. > >> TIA, > >> V > > > > > > sure, that's where this part comes in: > > > > the javascript would populate the list for the colors the user selects > > (the easiest way would probably be to give the list an id and use > > getElementByID()) > > > > so basically you'd define, e.g., an onClick="blah('red'); return true" > > within the red element's tag, and then define a function blah(x) that > > says > > getElementById("my_list_id").innerHtml += "
    " + x; > > and of course give your list textarea an id="my_list_id" attribute in the > tag. > > > > that could be slightly wrong, my javascript's rusty > > > > also don't forget to sanitize the data you receive before committing > it to the database, or someone can hack the javascript and send an SQL > injection attack > Good call! However, in my case I can put this all behind a firewall. It's only for the shop builder's use, and that's my client...whom I can track! But I presume this would entail doing searches for and eliminating all unnecessary characters, right? V -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Mon Nov 30 13:24:09 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:24:09 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> Message-ID: <4dc0cfea0911301024i49740011hcf9a5ede46363f4@mail.gmail.com> On Mon, Nov 30, 2009 at 1:35 PM, Dennis Lee Bieber wrote: > On Mon, 30 Nov 2009 07:26:09 -0500, Victor Subervi > declaimed the following in > gmane.comp.python.general: > > > Hi; > > I need a recommendation. I want to print out data like this: > > > > blue > > red > > > Why all the off-page links? > > How about just a table of checkboxes? > > > > > > > > > >
    > Blue >
    > Red >
    >
    > > >
    > > Ya know, in the interest of time, why not. There are a couple of selection lists that have a couple hundred elements each one, but heck, I need to move on and not spend days on this. Thanks ;) V -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Nov 30 13:28:18 2009 From: mwilson at the-wire.com (Mel) Date: Mon, 30 Nov 2009 13:28:18 -0500 Subject: Questions about list-creation References: Message-ID: Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > > > 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i Long ago, lists were built using explicit code: a = [] for i in xrange(10): a.append (i) which of course left i bound to the last value that was appended. People decided later that this was wordier than it had to be, and could bury the real point of a computation under a lot of boilerplate code that initialized lists, so we got list comprehensions, as you note, and they behave the same as the original code. > using the similar code > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: The list constructor is a lot more recent. It takes any iterable as an argument and makes (or tries to make) a list with the resulting values. The example you give takes a sequence comprehension as its argument. A sequence comprehension doesn't create data values -- it creates a block of code that can be executed later to create data values, and it can be executed later in any context. So we could also code (untested): def S(): return (j for j in xrange (10)) def T(s): return list (s) c = S() b = T(c) which still creates a list, but at an astonishing remove. The sequence comprehension `c` can't count on finding a `j` in the namespace it finally gets executed in, so it has to have it's own private namespace to use then. That's why you don't see `j` in your local namespace when `list` finallty runs the sequence comprehension. Mel. From inhahe at gmail.com Mon Nov 30 13:31:29 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:31:29 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: i should also mention that a=[i for i in xrange(10)] and b=list(j for j in xrange(10)) isn't really just a difference of using [] vs. list() the first case is a list comprehension, the second case is a generator comprehension which is then converted to a list (the bug only applies to list comprehensions, not generator comprehensions) i.e. notice that you can do this ''.join(x for x in ['a','b','c']) no list or [] involved - it's just a generator comprehension being passed to a function. On Mon, Nov 30, 2009 at 1:12 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:22 PM, Manuel Graune wrote: >> >> Hello, >> >> in (most) python documentation the syntax "list()" >> and "[]" is treated as being more or less the same >> thing. For example "help([])" and "help(list())" point >> to the same documentation. Since there are at least >> two cases where this similarity is not the case, (see below) >> can someone explain the reasoning behind this and point to >> further / relevant documentation? >> (To clarify: I am not complaining about this, just asking.) >> >> >> 1.) >> >> when using local variables in list comprehensions, say >> >> a=[i for i in xrange(10)] >> >> the local variable is not destroyed afterwards: >> >> print "a",a >> print "i",i >> >> using the similar code >> >> b=list(j for j in xrange(10)) >> >> the local variable is destroyed after use: >> >> print "b",b >> print "j",j >> > > I could be wrong, but I think this was actually a bug that was fixed later. > >> and 2) >> >> a=list([]) >> >> vs. >> >> b=[[]] >> > > those don't return the same thing > list([]) will create a shallow copy of [], which will of course be [] > > i can't think of a place where you'd want to use list() instead of [], > but sometimes you might want to use 'list', such as in a defaultdict, > in which case it's being used as a factory > >> >> Regards, >> >> Manuel Graune >> >> -- >> A hundred men did the rational thing. The sum of those rational choices was >> called panic. Neal Stephenson -- System of the world >> http://www.graune.org/GnuPG_pubkey.asc >> Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A ?5828 5476 7E92 2DB4 3C99 >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > From lie.1296 at gmail.com Mon Nov 30 13:32:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:32:27 +1100 Subject: Can't print Chinese to HTTP In-Reply-To: References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: <4b141020$1@dnews.tpgi.com.au> On 12/1/2009 4:05 AM, Gnarlodious wrote: > Thanks for the help, but it doesn't work. All I get is an error like: > > UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in > position 0: ordinal not in range(128) The error says it all; you're trying to encode the chinese character using 'ascii' codec. > malformed header from script. Bad header=\xe6\x99\x89 Hmmm... strange. The \xe6\x99\x89 happens to coincide with UTF-8 representation of ?. Why is your content becoming a header? > #!/usr/bin/python do you know what python version, exactly, that gets called by this hashbang? You mentioned that you're using python 3, but I'm not sure that this hashbang will invoke python3 (unless Mac OSX has made a progress above other linux distros and made python 3 the default python). > Strangely, if I run the script in Terminal it acts as expected. I think I see it now. You're invoking python3 in the terminal; but your server invokes python 2. Python 2 uses byte-based string literal, while python 3 uses unicode-based string literal. When you try to ' ?\n'.encode("utf-8"), python 2 tried to decode the string using 'ascii' decoder, causing the exception. From mail at timgolden.me.uk Mon Nov 30 13:34:46 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Nov 2009 18:34:46 +0000 Subject: reading from a text file In-Reply-To: References: <4B13E7B2.5030405@timgolden.me.uk> Message-ID: <4B141046.80307@timgolden.me.uk> inhahe wrote: > i don't understand the point of using 'with' > but i don't understand what 'with' does at all > i've tried to understand it a few times > anyway here: > > import random > result = random.choice(open("c:\\test.txt").readlines()) Yep. That'll do the trick. The point of "with" is that, while in CPython, an open file will be closed as soon as it is out of scope -- in this case, after that line -- in other implementations of Python, this may not be so. Good practice suggests using with (or try/finally) which ensures that the file is closed, regardless of the implementation. For a quick example it's not always easy to know whether to include this kind of detail, but a with: block adds very little noise and will save you from being caught out somewhere, someday. http://www.python.org/doc/current/whatsnew/2.6.html#pep-343-the-with-statement TJG From inhahe at gmail.com Mon Nov 30 13:37:22 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:37:22 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi wrote: > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> > wrote: >> >> >> >> >> >> If I'm not mistaken, that won't help me actually print to screen the >> >> user's >> >> choices as he selects them, which in my application, is important. >> >> Please >> >> advise. >> >> TIA, >> >> V >> > >> > >> > sure, that's where this part comes in: >> > >> > the javascript would populate the list for the colors the user selects >> > (the easiest way would probably be to give the list an id and use >> > getElementByID()) >> > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" >> > within the red element's tag, and then define a function blah(x) that >> > says >> > getElementById("my_list_id").innerHtml += "
    " + x; >> > and of course give your list textarea an id="my_list_id" attribute in >> > the tag. >> > >> > that could be slightly wrong, my javascript's rusty >> > >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Good call! However, in my case I can put this all behind a firewall. It's > only for the shop builder's use, and that's my client...whom I can track! > But I presume this would entail doing searches for and eliminating all > unnecessary characters, right? > V > depends on if you're using python or php on the server side if you're using Python, just use parameterized sql, which completely avoids the issue of sql injection if you're using php, parameterized sql is kind of pain in the ass, but it includes a function for sanitizing strings so you don't have to make one yourself. if i remember correctly though, my friend and i had issues with that function, for example ' would be saved as \' in our database, or something like that i'm not sure which characters you need to eliminate to sanitize sql parameters.. i wouldn't be comfortable relying on my own function to do that without thoroughly researching the issue... and i'd probably just rather find a function that's already been written From victorsubervi at gmail.com Mon Nov 30 13:40:25 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 14:40:25 -0400 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: <4dc0cfea0911301040q761ab306h7ef70c601476bfe1@mail.gmail.com> On Mon, Nov 30, 2009 at 2:37 PM, inhahe wrote: > On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi > wrote: > > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: > >> > >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: > >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi > >> > wrote: > >> >> > >> >> > >> >> If I'm not mistaken, that won't help me actually print to screen the > >> >> user's > >> >> choices as he selects them, which in my application, is important. > >> >> Please > >> >> advise. > >> >> TIA, > >> >> V > >> > > >> > > >> > sure, that's where this part comes in: > >> > > >> > the javascript would populate the list for the colors the user selects > >> > (the easiest way would probably be to give the list an id and use > >> > getElementByID()) > >> > > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" > >> > within the red element's tag, and then define a function blah(x) that > >> > says > >> > getElementById("my_list_id").innerHtml += "
    " + x; > >> > and of course give your list textarea an id="my_list_id" attribute in > >> > the tag. > >> > > >> > that could be slightly wrong, my javascript's rusty > >> > > >> > >> also don't forget to sanitize the data you receive before committing > >> it to the database, or someone can hack the javascript and send an SQL > >> injection attack > > > > Good call! However, in my case I can put this all behind a firewall. It's > > only for the shop builder's use, and that's my client...whom I can track! > > But I presume this would entail doing searches for and eliminating all > > unnecessary characters, right? > > V > > > > depends on if you're using python or php on the server side > if you're using Python, just use parameterized sql, which completely > avoids the issue of sql injection > if you're using php, parameterized sql is kind of pain in the ass, but > it includes a function for sanitizing strings so you don't have to > make one yourself. > if i remember correctly though, my friend and i had issues with that > function, for example ' would be saved as \' in our database, or > something like that > i'm not sure which characters you need to eliminate to sanitize sql > parameters.. i wouldn't be comfortable relying on my own function to > do that without thoroughly researching the issue... and i'd probably > just rather find a function that's already been written > Yeah, parameterize it. PHP?! Wash your mouth out with soap! ;) V -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Mon Nov 30 13:40:59 2009 From: nad at acm.org (Ned Deily) Date: Mon, 30 Nov 2009 10:40:59 -0800 Subject: multiprocessing.connection with ssl References: <8ff1698c-8205-4171-9e41-2e382bd52e89@g23g2000vbr.googlegroups.com> Message-ID: In article <8ff1698c-8205-4171-9e41-2e382bd52e89 at g23g2000vbr.googlegroups.com>, Xavier wrote: > I've hacked multiprocessing.connection (in a basic way) to allow ssl > encryption using ssl.wrap_socket. > > Anybody knows how i can contribute this to main developers? If you haven't already, open a feature request issue on the Python bug tracker (http://bugs.python.org/) and attach the code as a patch file. -- Ned Deily, nad at acm.org From lie.1296 at gmail.com Mon Nov 30 13:42:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 05:42:04 +1100 Subject: python and vc numbers In-Reply-To: References: <7ngl1gF3ml76pU1@mid.individual.net> <20091130082059.GA10079@gwsc.vic.edu.au> <20091130100200.GB12885@gwsc.vic.edu.au> <50697b2c0911300226j126d0dfen6e22e053ccca6243@mail.gmail.com> Message-ID: <4b141261$1@dnews.tpgi.com.au> On 11/30/2009 10:05 PM, Daniel Dalton wrote: > On Mon, Nov 30, 2009 at 02:26:14AM -0800, Chris Rebert wrote: >> Also, in my quickie newbie experimentation with `screen`, each screen >> "window" seems to get a unique tty#. Admittedly I am running OS X Can you make do with the tempfile module? Or you'd need to identify from an external process which console is locked? From clp2 at rebertia.com Mon Nov 30 13:53:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 30 Nov 2009 10:53:48 -0800 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> Message-ID: <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> > On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing > wrote: >> Esmail wrote: >> >>> Wow .. never heard of Concatenative_languages languages before or the >>> distinction you make. Your distinction explains the behavior, but I >>> find it somewhat counter-intuitive. >> >> You shouldn't find it any more surprising than the fact that >> >> ?a = 2 + 3 >> ?print a * 5 >> >> gives a different result from >> >> ?print 2 + 3 * 5 On Mon, Nov 30, 2009 at 3:41 AM, inhahe wrote: > one point of confusion could be the use of ** instead of superscript. > it might make things a little bit more counterintuitive-looking than > with superscripts, since the issue with Well, since source code is almost universally just plain ASCII and not in some file format with typesetting, superscripts aren't going to happen any time soon. (Also, avoid top-posting in the future.) Cheers, Chris -- http://blog.rebertia.com From inhahe at gmail.com Mon Nov 30 13:55:55 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:55:55 -0500 Subject: High-performance Python websites In-Reply-To: References: <7cdd7775-0524-4f10-a347-6e79038c821b@a39g2000pre.googlegroups.com> Message-ID: On Wed, Nov 25, 2009 at 7:33 PM, ShoqulKutlu wrote: > Hi, > > Managing load of high volume of visitors is a common issue for all > kind of web technologies. I mean this is not the python issue. This > issue is mostly about server level designs. You need to supply load > balancing for both web servers and databases to make your web site > able to respond to several concurrent visitors. Of course a good > programmed website is a key performance issue but for your mention I > would also suggest considering how many hardwares, how many > webservers, how many database cluster and which database server should > be used or will be used in the future.. > I don't know a lot about this issue, but take apache + php. every time a page is loaded a new instance of php is loaded to run the page, so i imagine load balancing can easiry be done on the page request level by distributing instances of php processes. whereas if you use python, you don't really want to load the python interpreter for every page request. as far as i can tell, the canonical way is to have one app for the whole website that's constantly running and communicates with the server via WSGI. or is that wrong? and wouldn't that make load balancing a little bit more tricky, or at least different? not sure.. From inhahe at gmail.com Mon Nov 30 13:58:06 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 13:58:06 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert wrote: >> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing >> wrote: >>> Esmail wrote: >>> >>>> Wow .. never heard of Concatenative_languages languages before or the >>>> distinction you make. Your distinction explains the behavior, but I >>>> find it somewhat counter-intuitive. >>> >>> You shouldn't find it any more surprising than the fact that >>> >>> ?a = 2 + 3 >>> ?print a * 5 >>> >>> gives a different result from >>> >>> ?print 2 + 3 * 5 > > On Mon, Nov 30, 2009 at 3:41 AM, inhahe wrote: >> one point of confusion could be the use of ** instead of superscript. >> it might make things a little bit more counterintuitive-looking than >> with superscripts, since the issue with > > Well, since source code is almost universally just plain ASCII and not > in some file format with typesetting, superscripts aren't going to > happen any time soon. > (Also, avoid top-posting in the future.) > i wasn't suggesting it as a feature for python, just pointing out why it might seem counterintuitive. From nad at acm.org Mon Nov 30 14:00:12 2009 From: nad at acm.org (Ned Deily) Date: Mon, 30 Nov 2009 11:00:12 -0800 Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: In article , Gnarlodious wrote: > It does work in Terminal interactively, after I import the sys module. > But my script doesn't act the same. Here is my entire script: > > #!/usr/bin/python > print("Content-type:text/plain;charset=utf-8\n\n") > import sys > sys.stdout.buffer.write('???n'.encode("utf-8")) > > All I get is the despised "Internal Server Error" with Console > reporting: > > malformed header from script. Bad header=?xe6?x99?x89 > > Strangely, if I run the script in Terminal it acts as expected. > > This is OSX 10.6 2,, Python 3.1.1. Are you sure you are actually using Python 3? /usr/bin/python is the path to the Apple-supplied python 2.6.1. If you installed Python 3.1.1 using the python.org OS X installer, the path should be /usr/local/bin/python3 -- Ned Deily, nad at acm.org From apt.shansen at gmail.com Mon Nov 30 14:01:46 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 30 Nov 2009 11:01:46 -0800 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: Message-ID: <7a9c25c20911301101t65d16d8er484209fa0b01b915@mail.gmail.com> On Mon, Nov 30, 2009 at 9:57 AM, Esmail wrote: > Hello all. > > I am using the PIL 1.1.6 and Python 2.6.x under XP without any > problems. However, I can't display any images under Vista > or Windows 7. I could understand Windows 7 as it's relatively > new, but Vista has been around for a bit. > > Sample code: > > import Image > > im = Image.open('c://mypic.jpg') > im.show() > Totally a guess, but did you try "c:\\mypic.jpg"? \ is the path separator on windows, not /. A / will work in many situations, but doubling it might cause problems perhaps (especially since you never have to double forward-slashes, unlike back slashes) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 14:02:21 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:02:21 +1100 Subject: how to format a python source file with tools? In-Reply-To: References: <48ec1864-acdb-494e-bf93-e7afd69eb6ec@2g2000prl.googlegroups.com> <877htczah4.fsf@benfinney.id.au> <7nab89FtafbaU1@mid.uni-berlin.de> Message-ID: <4b141722$1@dnews.tpgi.com.au> On 12/1/2009 4:30 AM, Falcolas wrote: > Nonetheless, it would be better to implement coding standards that > everyone can stick to. Agreed. You can't solve social issues with program. From lie.1296 at gmail.com Mon Nov 30 14:05:53 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:05:53 +1100 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> Message-ID: <4b1417f6$1@dnews.tpgi.com.au> On 12/1/2009 5:58 AM, inhahe wrote: > i wasn't suggesting it as a feature for python, just pointing out why > it might seem counterintuitive. I'm interested, what do YOU (inhahe) think the result should be? Should both become -9 or both become 9. What was your expectation when you wrote that post? From lie.1296 at gmail.com Mon Nov 30 14:17:15 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 06:17:15 +1100 Subject: Completely OT In-Reply-To: References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> Message-ID: <4b141aa0@dnews.tpgi.com.au> On 12/1/2009 5:00 AM, inhahe wrote: > On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> wrote: >>> >>> >>> If I'm not mistaken, that won't help me actually print to screen the user's >>> choices as he selects them, which in my application, is important. Please >>> advise. That's where Javascript kicks in. You only need to use the javascript to modify your document (visual effect); you won't need it to submit to the server (the real action). > > also don't forget to sanitize the data you receive before committing > it to the database, or someone can hack the javascript and send an SQL > injection attack Or a XSS attack (Cross-site scripting). Basically, you want to check whether the string received by the server matches your own predefined list of colors before storing to the database. From victorsubervi at gmail.com Mon Nov 30 14:21:29 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 15:21:29 -0400 Subject: os.remove() permission problem Message-ID: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Hi; I get the following error when I try os.remove(file) *OSError*: [Errno 13] Permission denied: 'particulars.py' args = (13, 'Permission denied') errno = 13 filename = 'particulars.py' strerror = 'Permission denied' Here are the permissions: -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py When I go into the python interpreter and execute that statement, it succeeds. What have I missed? TIA, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at twistedmatrix.com Mon Nov 30 14:32:31 2009 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Mon, 30 Nov 2009 19:32:31 -0000 Subject: Can't print Chinese to HTTP In-Reply-To: References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: <20091130193231.2549.395377677.divmod.xquotient.45@localhost.localdomain> On 05:05 pm, gnarlodious at gmail.com wrote: >Thanks for the help, but it doesn't work. All I get is an error like: > >UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in >position 0: ordinal not in range(128) > >It does work in Terminal interactively, after I import the sys module. >But my script doesn't act the same. Here is my entire script: > >#!/usr/bin/python >print("Content-type:text/plain;charset=utf-8\n\n") >import sys >sys.stdout.buffer.write('f49\n'.encode("utf-8")) > >All I get is the despised "Internal Server Error" with Console >reporting: > >malformed header from script. Bad header=\xe6\x99\x89 As the error suggests, you're writing f49 to the headers section of the response. This is because you're not ending the headers section with a blank line. Lines in HTTP end with \r\n, not with just \n. Have you considered using something with fewer sharp corners than CGI? You might find it more productive. Jean-Paul From Brian.Mingus at Colorado.EDU Mon Nov 30 14:42:06 2009 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 30 Nov 2009 12:42:06 -0700 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: References: <9839a05c0911291648n5df51e4dl9b0c398af2e8a0a@mail.gmail.com> Message-ID: <9839a05c0911301142x5c4e3376j74416aa7bfdd73d2@mail.gmail.com> On Sun, Nov 29, 2009 at 5:58 PM, Esmail wrote: > Brian J Mingus wrote: > >> >> >> >> I think you answered your own question. 3**2 comes first in the order of >> operations, followed by the negation. >> > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contains -3 (x in my example) Yes, that is the problem. Setting x=-3 is the same as writing (-3)**2 vs. -(3**2). -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Nov 30 14:52:08 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 30 Nov 2009 11:52:08 -0800 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <7a9c25c20911301152t48a74badv2f91cf77eec2bfeb@mail.gmail.com> On Mon, Nov 30, 2009 at 9:22 AM, Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. For example "help([])" and "help(list())" point > to the same documentation. Since there are at least > two cases where this similarity is not the case, (see below) > can someone explain the reasoning behind this and point to > further / relevant documentation? > (To clarify: I am not complaining about this, just asking.) > They -do- pretty much the same thing, but you can't quite treat them as two forms which can be exchanged at a whim. [] is the syntax for creating a list literal in source code. Its also the syntax for list comprehensions. A list comprehension is an expression that constructs a list all at once. list() is a function (type/constructor/...) which accepts any iterable as an argument (or None), and uses it to construct a list, returning it. Those two things are very different, although in the end they both produce lists: one is syntax, the other is a function which has to be called. 1.) > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: > > print "a",a > print "i",i > > using the similar code > List comprehensions "leaked", as more of an implementation detail I believe then anything else: in Python 3 it was removed, to better match generator expressions (IIRC). > > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: > > print "b",b > print "j",j > > But see, this is something completely different. (j for j in xrange(10)) is NOT a list comprehension. Its a generator comprehension. In the first example with lists, you're using literal syntax to construct (all at once) a list. In this, you're using literal syntax to construct a generator-- the generator is then passed to the list function, which iterates over it and constructs a list, returning when that generator is exhausted. And generator comprehensions don't leak their variables (I can't remember if that was an implementation detail or a deliberate design decision, but eventually list comprehensions were made to match the behavior). > and 2) > > a=list([]) > > vs. > > b=[[]] > Those are also doing two completely different things: on the first, you are using literal syntax to create an empty list. You are then passing this list (which is an iterable) to the list function, telling it to make a list out of that literal. It does so, which is in the end a (shallow) copy of the first list you made. The second, you are using literal syntax to create an empty list, and using literal syntax to place that empty list inside another list. You basically can't treat the two things as interchangable, because they're different: one is syntax, one is a function. Both are ways to make lists. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Mon Nov 30 15:08:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 01 Dec 2009 07:08:26 +1100 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: Message-ID: <4b14269f$1@dnews.tpgi.com.au> On 12/1/2009 5:04 AM, Esmail wrote: >> >> im = Image.open('c://mypic.jpg') > > sorry, slip of the finger, there's only one forward slash > or you can use two backward slashes. > > The problem isn't with opening it (I know it opens fine > since I can get its size attribute via im.size) - the show() > is the problem. What's your default image viewer? im.show is intended to be for debugging purpose and may always guaranteed to work if your image viewer doesn't support receiving the file through . From kyrie at uh.cu Mon Nov 30 15:22:12 2009 From: kyrie at uh.cu (Luis Zarrabeitia) Date: Mon, 30 Nov 2009 15:22:12 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: <200911301522.12827.kyrie@uh.cu> On Monday 30 November 2009 12:22:17 pm Manuel Graune wrote: > > when using local variables in list comprehensions, say > > a=[i for i in xrange(10)] > > the local variable is not destroyed afterwards: [...] > b=list(j for j in xrange(10)) > > the local variable is destroyed after use: Actually, [] and list() are not the same. For instance, list(1,2) rises an error, while [1,2] is the list with two elements. The comprehension is just a syntactic contruct that allows you to simplify the creation of lists, while the list() "function" (it is a class, actually) receives an iterable object and returns a list. What you seem to be confused about is the construct: (j for j in xrange(10)) That is called a generator expression, and it is very similar to the list comprehension, except that it builds an iterator (instead of a list, i.e, the xrange(10) is not consumed until it is needed), and the loop variable doesn't "leak" outside. When you do b=list(j for j in xrange(10)), you are actually doing b=list((j for j in xrange(10))) (note the extra set of parenthesis - python lets you ommit those), i.e, you are calling the list() "function" with a single argument, an iterable that contains all the elements of xrange(10). You could be calling foobar(j for j in xrange(10)) instead. And I think I lost my way... I'm sleepy. If I confused you, sorry... and if I'm helped you, thank you for letting me :D. Cya. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matem?tica y Computaci?n, UH. http://profesores.matcom.uh.cu/~kyrie From victorsubervi at gmail.com Mon Nov 30 15:35:32 2009 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 30 Nov 2009 16:35:32 -0400 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: <4dc0cfea0911301235k12106bcdj8c7ae5a5b7a43b9b@mail.gmail.com> On Mon, Nov 30, 2009 at 3:21 PM, Victor Subervi wrote: > Hi; > I get the following error when I try > os.remove(file) > > *OSError*: [Errno 13] Permission denied: 'particulars.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'particulars.py' > strerror = 'Permission denied' > > Here are the permissions: > > -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py > > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? > > This is on a CentOS system. I've tried manipulating the mode to 666 and 777 but that didn't help at all. I do read from the file, then close it, but I've tried deleting a file I don't read and come up with the same error. TIA, V -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at gmail.com Mon Nov 30 15:45:09 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 12:45:09 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> Message-ID: <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> On Nov 30, 3:08?pm, Lie Ryan wrote: > > What's your default image viewer? im.show is intended to be for > debugging purpose and may always guaranteed to work if your image viewer > doesn't support receiving the file through the image to the program>. It's whatever the default windows viewer is :-) .. so if I double- click on the image in the filemanager it fires it up and shows it. This works in XP and Windows 7 and Vista (ie double clicking on the image and having it display). I dug around in the docs and found a named parameter that I can set when I call show. Definition: im.show(self, title=None, command=None) I installed irfanview and specified it/its path in the parameter, but that didn't work either. It's really quite puzzling in the case of Vista since that's been around for quite a few years now. Esmail From arts.martijn at gmail.com Mon Nov 30 15:50:34 2009 From: arts.martijn at gmail.com (Martijn Arts) Date: Mon, 30 Nov 2009 21:50:34 +0100 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: <23739e0a0911301250h2dcd838en2cdffe2c116df9fd@mail.gmail.com> On Mon, Nov 30, 2009 at 8:21 PM, Victor Subervi wrote: > Hi; > I get the following error when I try > os.remove(file) > > *OSError*: [Errno 13] Permission denied: 'particulars.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'particulars.py' > strerror = 'Permission denied' > > Here are the permissions: > > -rwxr-xr-x 1 root root 455 Nov 28 05:58 particulars.py > Try chmodding the file to 755. > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? > TIA, > Victor > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Nov 30 15:51:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 15:51:02 -0500 Subject: Variables with cross-module usage In-Reply-To: <4b135424$1@dnews.tpgi.com.au> References: <4b11e7fc.0706c00a.63b5.545a@mx.google.com> <4b135424$1@dnews.tpgi.com.au> Message-ID: Lie Ryan wrote: > On 11/30/2009 12:00 PM, Terry Reedy wrote: >> Dennis Lee Bieber wrote: >> >>> In these languages, the names always refer to the same location. >>> Python confuses matters by having names that don't really refer to >>> location, but are attached to the objects. >> >> In everyday life and natural languages, names refer to people, other >> objects, roles, and only occasionally to places that can be occupied. I >> could claim that it is classical computer languages that confuse by >> restricting names to locations in a linear sequence. You are just used >> to the straightjacket ;-). > > In everyday life and natural languages, though an object may have many > names/aliases; once objects are assigned a name, it is practically > impossible to change the name to the object the name will be practically > stuck to it forever. When children play tag, the role of It is rebound to another child every few seconds. When adults play conference, the role of Speaker or Presenter is rebound to another person a few times per hour. In Python, it easy, perhaps too easy, to rebind built-in names, but it is usually a mistake. (Just yesterday there was a newbie post with that mistake.) It is common for global names to be bound just once (especially to functions and classes). In both human life and programming performed by humans, the time scale of name rebinding varies tremendously. Not surprising really. > In everyday life and natural languages, a single > name can be used to refer to multiple objects just by context without > referring any namespace. Namespace are contexts. They were (re)invented in programming just to make it easier to have single name could refer to different objects -- in different contexts. Names bound within a function are interpreted as being within the default local context without explicitly referring to it. Indeed, one cannot explicitly refer to the local namespace of functions, only to a dict copy thereof. > Let's not start making analogism between nature and silicon. There are several things wrong with this. You meant 'analogies'. I will make them when I want to, which is when I think they are useful in providing new viewpoints and insight. They are one way to break out of straight-jacketed or boxed thinking. If you prefer your box, ignore me. Silicon is a part of the natural world, and I was not making any such analogy. Python is an information processing and algorithm language, not a silicon programming language per se. And indeed, without a concept of 'address', it is not very suited to that. I *was* making an analogy between how we communicate informally about the natural and social worlds and how we communicate more formally about the abstract information world. Is it really surprising that we use the same psychological mechanisms? Silicon machine languages do not have names. And names, as used by humans, *are* the subject of discussion here. Dennis clained that Python is confusing because it is not restricted to naming locations. I said I could claim instead that it is the restriction is confusing. I did not go into that counterclaim, but indeed, many people who program in C, for instance, use C names as if they were object names instead of location names (or location,increment tuple names). Sometimes they even forget that they are really just location names. One too-common result of that confusion has been buffer overruns and virus programs that exploit them. These are impossible in Python. To me, the virtue of Python is that it allows one to think and write in a relatively natural named-object model. Let the silicon-based interpreter then translate that to a named-sequential-location model, while avoiding the dangers thereof, even though it has the cost of slower execution. Terry Jan Reedy From kirby.urner at gmail.com Mon Nov 30 15:51:25 2009 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 30 Nov 2009 12:51:25 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: <4B13F47E.3080706@aon.at> References: <4B13F47E.3080706@aon.at> Message-ID: I'm glad turtle graphics intersected my thinking re extended precision decimals (Decimal type) on edu-sig just now. I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod: http://www.4dsolutions.net/ocn/python/tmod.py (runnable source) http://www.flickr.com/photos/17157315 at N00/4147429781/ (GUI view) Here's the graphical output: http://www.flickr.com/photos/17157315 at N00/4148139184/in/photostream/ (Python 3.1) If you actually wanna fold the T, you need to snip off the cap and reverse it, per this diagram: http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html 120 of them, 60 folded left, 60 folded right, all of volume 1/24, make the volume 5 rhombic triacontahedron. http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html If you blow up the volume by 3/2, to 7.5, the radius becomes phi / sqrt(2) -- what we're showing with Decimals. The reason this seems unfamiliar is the unit of volume is the tetrahedron formed by any four equi-radiused balls in inter-tangency. I'm spinning this as Martian Math these days, yakking on math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et al. Kirby From dahl.joachim at gmail.com Mon Nov 30 15:52:26 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 12:52:26 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 Message-ID: I am updating an extension module from Python2.6 to Python3. I used to pass character codes to the extension module, for example, I would write: >>> foo('X') with the corresponding C extension routine defined as follows: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char foo; char *kwlist[] = {"foo", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) return NULL; ... In Python3.0 this also works, but in Python3.1 I get the following error: TypeError: argument 1 must be a byte string of length 1, not str and I seem to be supposed to write >>> foo(b'X') instead. From the Python C API, I have not been able to explain this new behavior. What is the correct way to pass a single character argument to Python3.1 extension modules? From dahl.joachim at gmail.com Mon Nov 30 16:04:39 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 13:04:39 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: Message-ID: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Obviously the name of the C function and the char variable cannot both be foo, so the C code should be: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char foochar; char *kwlist[] = {"foochar", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foochar)) return NULL; ... The question remains the same: why can't I pass a single character argument to this function under Python3.1? Thanks. Joachim On Nov 30, 9:52?pm, Joachim Dahl wrote: > I am updating an extension module from Python2.6 to Python3. > > I used to pass character codes to the extension module, for example, I > would write: > > >>> foo('X') > > with the corresponding C extension routine defined as follows: > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char foo; > ? char *kwlist[] = {"foo", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > ? ? return NULL; > ? ... > > In Python3.0 this also works, but in Python3.1 I get the following > error: > TypeError: argument 1 must be a byte string of length 1, not str > > and I seem to be supposed to write>>> foo(b'X') > > instead. From the Python C API, I have not been able to explain this > new behavior. > What is the correct way to pass a single character argument to > Python3.1 > extension modules? From falk at mauve.rahul.net Mon Nov 30 16:13:29 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 30 Nov 2009 21:13:29 +0000 (UTC) Subject: Python Programming Challenges for beginners? References: <09ea817f-57a9-44a6-b815-299ae3ce75d3@x5g2000prf.googlegroups.com> Message-ID: In article <09ea817f-57a9-44a6-b815-299ae3ce75d3 at x5g2000prf.googlegroups.com>, alex23 wrote: >On Nov 27, 1:24?pm, astral orange <457r0... at gmail.com> wrote: >> I would like to test out what I know so far by solving programming >> challenges. > >Project Euler can be a lot of fun: http://projecteuler.net/ Oooh, that *does* look like fun. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From falk at mauve.rahul.net Mon Nov 30 16:16:50 2009 From: falk at mauve.rahul.net (Edward A. Falk) Date: Mon, 30 Nov 2009 21:16:50 +0000 (UTC) Subject: parsing json data References: Message-ID: There's a json parsing library in 2.6. (Sadly, 2.6 is not out for Ubuntu yet.) -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From casevh at gmail.com Mon Nov 30 16:19:20 2009 From: casevh at gmail.com (casevh) Date: Mon, 30 Nov 2009 13:19:20 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: On Nov 30, 1:04?pm, Joachim Dahl wrote: > Obviously the name of the C function and the char variable cannot both > be foo, > so the C code should be: > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char foochar; > ? char *kwlist[] = {"foochar", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > &foochar)) > ? ? return NULL; > ? ... > > The question remains the same: why can't I pass a single character > argument to this function under Python3.1? > > Thanks. > Joachim > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > > I am updating an extension module from Python2.6 to Python3. > > > I used to pass character codes to the extension module, for example, I > > would write: > > > >>> foo('X') > > > with the corresponding C extension routine defined as follows: > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > { > > ? char foo; > > ? char *kwlist[] = {"foo", NULL}; > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > ? ? return NULL; > > ? ... > > > In Python3.0 this also works, but in Python3.1 I get the following > > error: > > TypeError: argument 1 must be a byte string of length 1, not str > > > and I seem to be supposed to write>>> foo(b'X') > > > instead. From the Python C API, I have not been able to explain this > > new behavior. > > What is the correct way to pass a single character argument to > > Python3.1 > > extension modules?- Hide quoted text - > > - Show quoted text - Python 3.1 uses "c" (lowercase c) to parse a single character from a byte-string and uses "C" (uppercase c) to parse a single character from a Unicode string. I don't think there is an easy way to accept a character from both. HTH, casevh From jon at jonhaddad.com Mon Nov 30 16:34:12 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Mon, 30 Nov 2009 15:34:12 -0600 Subject: top-like behavior Message-ID: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> Is there a specific library used for displaying up to date consoles in the same way top behaves? Thanks in advance, Jon From tjreedy at udel.edu Mon Nov 30 16:35:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 16:35:12 -0500 Subject: Feature request: String-inferred names In-Reply-To: References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <7n8phvF3kjrhgU1@mid.individual.net> <970299f2-9f07-47db-98ae-e081f61967f8@t18g2000vbj.googlegroups.com> <4b10e8b3@dnews.tpgi.com.au> <441e01c8-7c7a-4239-96e8-15160099e9d4@h40g2000prf.googlegroups.com> Message-ID: Brad Harms wrote: > Well, yes, the names would have to be determined at run time. That's > what getattr and setattr do, except that that do it in the context of an > object rather than the local scope. However, I was under the impression > that python's mechanism for looking up local names was the same as the > mechanism used to look up attributes because names and attributes seem > to function pretty much the same way. This I assumed because of the > functionality of the locals() and globals() functions, which seem to act > like the __dict__ attribute on objects except that the work on the > current scope. The definition of locals() allows it to just be a dict *copy* of the local namespace, rather than the local namespace itself. Within functions, (at least for CPython, and probably for other implementations), locals() is just a copy, and changes to locals() are *not* propagated back to the local namespace. Within functions, local name 'lookup' has nothing to do with dict lookup. (It is more like list indexing.) From alfps at start.no Mon Nov 30 16:36:04 2009 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 30 Nov 2009 22:36:04 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: Message-ID: * Edward Cherlin: > On Sun, Nov 29, 2009 at 11:34, Brian Blais wrote: > >> After a bit of playing, I realized that I couldn't think of many exaples >> which use turtle with conditional structures (if- and while- statements), > > Repeat is used much more often. but of course we can provide examples > of any behavior you like. I like to use the turtle to generate > sequences, where I can use a conditional to stop when the turtle would > go off the screen. Fibonacci numbers, for example, or exponentials. > Similarly for spirals of various types. Simple cases like those are > easy to do in TA, while more complex sequences could use Python. There > are several fractal examples using loops provided with Sugar on a > Stick, including variations on Siepinksi constructions, and the Koch > Snowflake. In ch 2 of I use a turtle-generated spiral as the first example of a while loop. I haven't got that far yet with that chapter, but I halfway plan on including a turtle graphics solve-a-maze example, which would/will be an example of conditionals with the turtle as a kind of actor making decisions. >> or >> functions that return values, as opposed to "procedures" like: >> def square(length): >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) >> forward(length) >> right(90) Plotting a graph. Some examples of that in ch 2 of aforementioned URL. Cheers & hth., - Alf From db3l.net at gmail.com Mon Nov 30 16:37:05 2009 From: db3l.net at gmail.com (David Bolen) Date: Mon, 30 Nov 2009 16:37:05 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: Esmail writes: > I dug around in the docs and found a named parameter that I can set > when I > call show. > > Definition: im.show(self, title=None, command=None) > > I installed irfanview and specified it/its path in the parameter, > but that didn't work either. It's really quite puzzling in the > case of Vista since that's been around for quite a few years now. But I thought everyone was sticking their fingers in their ears and humming to try to forget Vista had been released, particularly now that Windows 7 is out :-) Perhaps there's an issue with the temporary file location. I don't have a Vista system to test on, but the show() operation writes the image to a temporary file as returned by tempfile.mktemp(), and then passes the name on to the external viewer. The viewing command is handed to os.system() with the filename embedded without any special quoting. So if, for example, the temporary location has spaces or "interesting" characters, it probably won't get parsed properly. One easy debugging step is probably to add a print just before the os.system() call that views the image (bottom of _showxv function in Image.py in my copy of 1.1.6). That way at least you'll know the exact command being used. If that's the issue, there are various ways around it. You could patch PIL itself (same function) to quote the filename when it is constructing the command. Alternatively, the tempfile module has a tempdir global you could set to some other temporary directory before using the show() function (or any other code using tempfile). -- David From yoavglazner at gmail.com Mon Nov 30 16:38:25 2009 From: yoavglazner at gmail.com (Glazner) Date: Mon, 30 Nov 2009 13:38:25 -0800 (PST) Subject: PySerial and termios References: <10eedef6-4e62-4866-9723-f956e7ebc43c@1g2000vbm.googlegroups.com> Message-ID: On Nov 30, 7:41?pm, Grant Edwards wrote: > On 2009-11-30, a b wrote: > > > I have a pain in the a** problem with pyserial- it works 90% > > of time but on the 10% of time it thorows and termios.error > > exception with the value (5, 'Input/output error') and i > > cannot get rid of it :( > > Sounds like faulty converter or a bug in the device driver to > me. > > > The system works as follows: > > A device sends out rs485 data -> rs485 to rs232 converter converts it - > >> an rs232->usb cable attatched to a computer reads the data. Until > > now it hasn't bothered me too much since it hasn't been a lot > > of data (every time i get this exception i unload the pl2303 > > module from kernel, then reload it, open the com port > > Does that get rid of the error? ?If so, then it's definitely a > problem with the converter or device-driver. > > > and hope it won't happen soon). But now the amount of data is > > getting bigger and the exceptions in the log are quite > > bothering already so if anyone has a good idea what could > > affect it i'd be very glad... oh and the settings for the port > > opening are: self.ser = serial.Serial(self.port, > > self.baudrate, rtscts=0, xonxoff=0, timeout=0) > > Unless you want to try to troubleshoot the device driver and > USB traffic, the only suggestion I have is to try different > converters and/or different versions of the driver. > > -- > Grant Edwards ? ? ? ? ? ? ? ? ? grante ? ? ? ? ? ? Yow! If Robert Di Niro > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? assassinates Walter Slezak, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?visi.com ? ? ? ? ? ?will Jodie Foster marry > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Bonzo?? Try to use Portmon to see if your data is sent correctly.(if not, then its the cable/converter) http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx or another port monitor tool for other OS. From tjreedy at udel.edu Mon Nov 30 16:47:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 16:47:49 -0500 Subject: Object Not Callable, float? In-Reply-To: References: <87aay4ralv.fsf@benfinney.id.au> Message-ID: W. eWatson wrote: > I think I understand it, but how does one prevent it from happening, or > know it's the cause? That msg I got? Yes. The message 'x is not callable', where x is a name of something you expect to be callable (such as the builtin functions and classes), signals that x has been rebound to a non-callable object. On the other hand, if x is something you know not to be callable, there there is either a typo -- yxz(3) instead of yzx[3] -- or a bug such as expr(arg) where you expect expr to evaluate to a function but it does not. Say yzx[3]('abc') where you think yxz is a list of functions, or yzx(3)('abc') where you expect yzx to return a function. tjr From tjreedy at udel.edu Mon Nov 30 17:00:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:00:47 -0500 Subject: Running function from win32 dll In-Reply-To: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> References: <97FB089C6E1F404CB0132AC3BB3E5C2701947BBE@exchange.qualisystems.local> Message-ID: Nadav Chernin wrote: > I want to run function from win32 dll. > I used ctypes.windll.LoadLibrary to load the DLL. > But I don?t know how to select function and run it. Which part of the Lib manual chapter did you not understand? From lists at cheimes.de Mon Nov 30 17:06:32 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 30 Nov 2009 23:06:32 +0100 Subject: os.remove() permission problem In-Reply-To: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> References: <4dc0cfea0911301121u50efa2aat807e245c2ef05f59@mail.gmail.com> Message-ID: Victor Subervi wrote: > When I go into the python interpreter and execute that statement, it > succeeds. What have I missed? You are confusing the permissions of a Unix file system. In order to create or a remove a file from a directory you need the x and w permission to enter the directory (x) and to modify (w) the directory entry. Christian From john at castleamber.com Mon Nov 30 17:07:26 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 22:07:26 GMT Subject: top-like behavior References: Message-ID: Jonathan Haddad wrote: > Is there a specific library used for displaying up to date consoles in > the same way top behaves? No experience but I am quite sure that curses behaves like that. http://www.amk.ca/python/howto/curses/ via http://www.google.com/search?q=python%20curses John From ben+python at benfinney.id.au Mon Nov 30 17:07:30 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 09:07:30 +1100 Subject: Characters in arithmetic expressions (was: semantics of ** (unexpected/inconsistent?)) References: <4b132c1b$1@dnews.tpgi.com.au> Message-ID: <87hbsbpsyl.fsf_-_@benfinney.id.au> MRAB writes: > Most programming languages don't differentiate in text between the > number "negative 3" and the expression "negated 3". APL does. The > former is written as "?3" (3 preceded by the overscore character) and > the latter as "-3" (3 preceded by the minus sign). Well, since we're talking about special characters: the ?-? that we find on our keyboard is a hyphen (U+002D). A minus sign is ??? (U+2212) and is unlikely to be found on the keyboard unless it's a keyboard designed specifically for APL :-) -- \ ?A ?No? uttered from deepest conviction is better and greater | `\ than a ?Yes? merely uttered to please, or what is worse, to | _o__) avoid trouble.? ?Mahatma Gandhi | Ben Finney From necronymouse at gmail.com Mon Nov 30 17:14:31 2009 From: necronymouse at gmail.com (Necronymouse) Date: Mon, 30 Nov 2009 14:14:31 -0800 (PST) Subject: Bored. Message-ID: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Hello, I am learning python for about 2 years and I am bored. Not with python but I have a little problem, when i want to write something I realise that somebody had alredy written it! So i don?t want to make a copy of something but i wanna get better in python skills. Don?t you know what I should do? ---sorry for my english, I ?m from czech rep... From ben+python at benfinney.id.au Mon Nov 30 17:15:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 09:15:12 +1100 Subject: Language and collaboration (was: Python Statements/Keyword Localization) References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> Message-ID: <87d42zpslr.fsf_-_@benfinney.id.au> "Emanuele D'Arrigo" writes: > Ultimately I certainly appreciate the ubiquity of English even though > in the interest of fairness and efficiency I'd prefer the role of > common language to be given to a constructed language, such as Ido. I prefer Lojban as being logically robust while fully expressive, and sharing the Ido goal of avoiding disadvantage to native speakers of any particular existing language. > But it doesn't take a particularly religious person to see that "do to > others as you would want them do to you" tends to be a valid principle Indeed, religion is entirely redundant to that principle: one of the earliest independent expressions of that principle is from a quite non-religious philosopher. ?????????? (What is undesirable to you, do not do to others.) ???? Confucius, 551 BCE ? 479 BCE I prefer this formulation, since it doesn't enjoin to *do* something to others on the unproven assumption that someone else wants the same as me :-) -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From inhahe at gmail.com Mon Nov 30 17:15:17 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 17:15:17 -0500 Subject: Completely OT In-Reply-To: <4b141aa0@dnews.tpgi.com.au> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4b141aa0@dnews.tpgi.com.au> Message-ID: On Mon, Nov 30, 2009 at 2:17 PM, Lie Ryan wrote: > On 12/1/2009 5:00 AM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe ?wrote: >>> >>> On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >>> ?wrote: >>>> >>>> >>>> If I'm not mistaken, that won't help me actually print to screen the >>>> user's >>>> choices as he selects them, which in my application, is important. >>>> Please >>>> advise. > > That's where Javascript kicks in. You only need to use the javascript to > modify your document (visual effect); you won't need it to submit to the > server (the real action). > Oh yes, good point - even though (if he were still going to go the JavaScript route) he'd modify the textarea using javascript, a regular submit button could be used because it'll submit the current contents of that textarea all the same. >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Or a XSS attack (Cross-site scripting). Basically, you want to check whether > the string received by the server matches your own predefined list of colors > before storing to the database. > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Nov 30 17:16:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:16:11 -0500 Subject: Intro To Python Using Turtle Graphics In-Reply-To: References: Message-ID: Lawrence D'Oliveiro wrote: > Done by Northland Polytechnic, available for download under CC-BY-NC-ND here > . I have two problems with the presentation, which make things harder for the students than they should be. First, the instructor has students edit code in an editor that cannot directly run the code. Save the file. Click to a command window. Enter 'python somefile.py'. Ugh. Python comes with IDLE. Let students use it. (Or some equivalent, but turtle works fine with IDLE.) Replace above with 'press F5'. If there is a SyntaxError, not uncommon for students, the edit window comes back with the cursor near the spot of the foul. Within the code, the instructor does 'import turtle' followed by 'turtle.up', turtle.move(x,y)', etc. for tens of lines. Ugh. Either 'from turtle import *' (which turtle was designed for) or, if one does not like that, 'import turtle as t', some one can write 't.up', etc. There is also a echo glitch in the audio when the video comes from the monitor, as opposed to the room camera. Aside from the above, it seems like a decent intro presenting statements, names, conditional execution, repeated execution, and function encapsulation. tjr From john at castleamber.com Mon Nov 30 17:16:45 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 22:16:45 GMT Subject: parsing json data References: Message-ID: falk at mauve.rahul.net (Edward A. Falk) wrote: > There's a json parsing library in 2.6. (Sadly, 2.6 is not out for > Ubuntu yet.) Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 on Ubuntu 9.04 John From dahl.joachim at gmail.com Mon Nov 30 17:18:19 2009 From: dahl.joachim at gmail.com (Joachim Dahl) Date: Mon, 30 Nov 2009 14:18:19 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: I think that "C" encoding is what I need, however I run into an odd problem. If I use the following C code static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char a, b; char *kwlist[] = {"a", "b", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, &b)) return NULL; ... then the following works: >>> foo('a') >>> foo('a','b') >>> foo(a='a',b='b') but the following fails: >>> foo(b='b') RuntimeError: impossible: 'CC' Is this error-message expected? On Nov 30, 10:19?pm, casevh wrote: > On Nov 30, 1:04?pm, Joachim Dahl wrote: > > > > > > > Obviously the name of the C function and the char variable cannot both > > be foo, > > so the C code should be: > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > { > > ? char foochar; > > ? char *kwlist[] = {"foochar", NULL}; > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > > &foochar)) > > ? ? return NULL; > > ? ... > > > The question remains the same: why can't I pass a single character > > argument to this function under Python3.1? > > > Thanks. > > Joachim > > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > I am updating an extension module from Python2.6 to Python3. > > > > I used to pass character codes to the extension module, for example, I > > > would write: > > > > >>> foo('X') > > > > with the corresponding C extension routine defined as follows: > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > { > > > ? char foo; > > > ? char *kwlist[] = {"foo", NULL}; > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > > ? ? return NULL; > > > ? ... > > > > In Python3.0 this also works, but in Python3.1 I get the following > > > error: > > > TypeError: argument 1 must be a byte string of length 1, not str > > > > and I seem to be supposed to write>>> foo(b'X') > > > > instead. From the Python C API, I have not been able to explain this > > > new behavior. > > > What is the correct way to pass a single character argument to > > > Python3.1 > > > extension modules?- Hide quoted text - > > > - Show quoted text - > > Python 3.1 uses "c" (lowercase c) to parse a single character from a > byte-string and uses "C" (uppercase c) to parse a single character > from a Unicode string. I don't think there is an easy way to accept a > character from both. > > HTH, > > casevh From inhahe at gmail.com Mon Nov 30 17:19:59 2009 From: inhahe at gmail.com (inhahe) Date: Mon, 30 Nov 2009 17:19:59 -0500 Subject: semantics of ** (unexpected/inconsistent?) In-Reply-To: <4b1417f6$1@dnews.tpgi.com.au> References: <50697b2c0911291650l5ee0997w1cdf24fadb579544@mail.gmail.com> <7nhf3eF3lrgr4U1@mid.individual.net> <50697b2c0911301053l406c3b68jbedc5e9d3e23320d@mail.gmail.com> <4b1417f6$1@dnews.tpgi.com.au> Message-ID: On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan wrote: > On 12/1/2009 5:58 AM, inhahe wrote: >> >> i wasn't suggesting it as a feature for python, just pointing out why >> it might seem counterintuitive. > > I'm interested, what do YOU (inhahe) think the result should be? Should both > become -9 or both become 9. What was your expectation when you wrote that > post? > -- > http://mail.python.org/mailman/listinfo/python-list > i think the way it works currently is the sane way..pays respect to the standard order of operations, doesn't have to do anything special with x = -3, just treats it as an integer, and corresponds with normal algebra. From jlconlin at gmail.com Mon Nov 30 17:26:32 2009 From: jlconlin at gmail.com (Jeremy) Date: Mon, 30 Nov 2009 14:26:32 -0800 (PST) Subject: How to prevent re.split() from removing part of string Message-ID: I am using re.split to... well, split a string into sections. I want to split when, following a new line, there are 4 or fewer spaces. The pattern I use is: sections = re.split('\n\s{,4}[^\s]', lineoftext) This splits appropriately but I lose the character matched by [^s]. I know I can put parentheses around [^s] and keep the matched character, but the character is placed in it's own element of the list instead of with the rest of the lineoftext. Does anyone know how I can accomplish this without losing the matched character? Thanks, Jeremy From tjreedy at udel.edu Mon Nov 30 17:35:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:35:20 -0500 Subject: Trying to understand += better In-Reply-To: References: <4b0a01aa$1@dnews.tpgi.com.au> Message-ID: Roy Smith wrote: > In article <4b0a01aa$1 at dnews.tpgi.com.au>, Lie Ryan > wrote: > >> The semantic of the in-place operator is something like: >> x += y >> becomes >> x = x.__iadd__(y) Except that the expression x is evaluated just once instead of twice. >> thus >> foo.bar += baz >> becomes >> foo.bar = foo.bar.__iadd__(baz) >> >> So the call sequence is, >> foo.__getattr__('bar') ==> x >> x.__iadd__(baz) ==> y >> foo.__setattr__('bar', y) > > I don't get where the __setattr__() call comes from in this situation. Augmented *ASSIGNMENT* is a type of assignment. The dis module can be used to see what CPython does. >>> from dis import dis >>> def f(): foo.bar += baz >>> dis(f) 2 0 LOAD_GLOBAL 0 (foo) 3 DUP_TOP 4 LOAD_ATTR 1 (bar) 7 LOAD_GLOBAL 2 (baz) 10 INPLACE_ADD 11 ROT_TWO 12 STORE_ATTR 1 (bar) ... This amounts to what Roy said, with x and y being temporary entries on the stack. Terry Jan Reedy From ebonak at gmail.com Mon Nov 30 17:48:45 2009 From: ebonak at gmail.com (Esmail) Date: Mon, 30 Nov 2009 14:48:45 -0800 (PST) Subject: Python PIL and Vista/Windows 7 .. show() not working ... References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: On Nov 30, 4:37?pm, David Bolen wrote: > Esmail writes: > > I dug around in the docs and found a named parameter that I can set > > when I > > call show. > > > Definition: ? ? im.show(self, title=None, command=None) > > > I installed irfanview and specified it/its path in the parameter, > > but that didn't work either. It's really quite puzzling in the > > case of Vista since that's been around for quite a few years now. > > But I thought everyone was sticking their fingers in their ears and > humming to try to forget Vista had been released, particularly now > that Windows 7 is out :-) > > Perhaps there's an issue with the temporary file location. ?I don't > have a Vista system to test on, but the show() operation writes the > image to a temporary file as returned by tempfile.mktemp(), and then > passes the name on to the external viewer. ?The viewing command is > handed to os.system() with the filename embedded without any special > quoting. ?So if, for example, the temporary location has spaces or > "interesting" characters, it probably won't get parsed properly. > > One easy debugging step is probably to add a print just before the > os.system() call that views the image (bottom of _showxv function in > Image.py in my copy of 1.1.6). ?That way at least you'll know the > exact command being used. > > If that's the issue, there are various ways around it. ?You could > patch PIL itself (same function) to quote the filename when it is > constructing the command. ?Alternatively, the tempfile module has a > tempdir global you could set to some other temporary directory before > using the show() function (or any other code using tempfile). > > -- David Thanks for the pointers David, this will give me some things to investigate. As for me, I'm a long time and regular Linux user with some XP tossed in. I use the PIL under XP at times, but this problem is happening to someone I know who is using both Vista and Windows and can't get the basic thing to work so I am trying to help. (I have access to a Win 7 VM for testing purposes at least). If I find a work-around or fix or concrete cause I'll post. In the meantime if anyone has any other ideas or fixes/suggestions, please don't be shy :-) Thanks, Esmail From tjreedy at udel.edu Mon Nov 30 17:53:38 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 17:53:38 -0500 Subject: problem with lambda / closures In-Reply-To: References: Message-ID: Benjamin Kaplan wrote: > I don't know if anyone considers python's incomplete implementation of > closures a "feature" but it's documented so it's not really a bug > either. I believe Python's implementation of closures is quite complete in 3.x. In what way do you consider it otherwise? One just has to use the right syntax. Closures in Python are created by nested function definitions. Lambda expressions create functions just like def statements and are not closures and do not create closure unless nested within another function definition. Thinking otherwise is the OP's mistake. > I believe there is a trick with default arguments to get this > to work, but I don't use lambdas enough to remember it. One can simulate closures by giving an un-nested function a default argument. This has nothing to do with whether the function is defined by a lambda expression or a def statement. Terry Jan Reedy From python.list at tim.thechases.com Mon Nov 30 17:57:30 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Nov 2009 16:57:30 -0600 Subject: top-like behavior In-Reply-To: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> References: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> Message-ID: <4B144DDA.9040705@tim.thechases.com> > Is there a specific library used for displaying up to date consoles in > the same way top behaves? From the last time a similar question was asked[1]: You might look at the sourcecode for "iotop"[2] 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://www.mail-archive.com/python-list at python.org/msg234993.html [2] http://guichaz.free.fr/iotop/ From python at mrabarnett.plus.com Mon Nov 30 17:58:05 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Nov 2009 22:58:05 +0000 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B144DFD.7060507@mrabarnett.plus.com> Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not > with python but I have a little problem, when i want to write > something I realise that somebody had alredy written it! So i don?t > want to make a copy of something but i wanna get better in python > skills. Don?t you know what I should do? > Choose a project that you find interesting. It doesn't matter if someone has already done something similar because you'll learn more by doing. When you have something reasonable, compare it to the one that already exists. Your approach might be better, but if it's not then you can still see why it isn't and how you could improve. This way, when you do something that no-one else has done before, you'll have a better understanding of the language and how best to design and implement your project. From xiao at xiao-yu.com Mon Nov 30 17:58:12 2009 From: xiao at xiao-yu.com (Xiao) Date: Mon, 30 Nov 2009 14:58:12 -0800 (PST) Subject: PIL build error on Snow Leopard Message-ID: <785f1942-6aec-4a5a-934a-8db50648b1ae@e22g2000vbm.googlegroups.com> Hello, I haven't fully understood the nuances in the difference between Apple's system Python and MacPython. But I have just installed Python 2.6.4 from python.org. Now I'm trying to install a fresh downloaded PIL 1.1.6 but couldn't. python setup.py install gives: lipo: can't open input file: /var/tmp//ccfwpQd6.out (No such file or directory) Everything worked fine on Apple's Python 2.6.1 From jon at jonhaddad.com Mon Nov 30 17:59:12 2009 From: jon at jonhaddad.com (Jonathan Haddad) Date: Mon, 30 Nov 2009 16:59:12 -0600 Subject: top-like behavior In-Reply-To: <4B144DDA.9040705@tim.thechases.com> References: <6e8dae020911301334w539a4d20k826fdd8c7aa714a5@mail.gmail.com> <4B144DDA.9040705@tim.thechases.com> Message-ID: <6e8dae020911301459k48a973a0vc9a4ca4e4da10f2c@mail.gmail.com> Awesome. Thank you! Jon On Mon, Nov 30, 2009 at 4:57 PM, Tim Chase wrote: >> Is there a specific library used for displaying up to date consoles in >> the same way top behaves? > > From the last time a similar question was asked[1]: > > You might look at the sourcecode for "iotop"[2] 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://www.mail-archive.com/python-list at python.org/msg234993.html > > [2] > http://guichaz.free.fr/iotop/ > -- Jonathan Haddad http://www.rustyrazorblade.com From jgardner at jonathangardner.net Mon Nov 30 18:01:29 2009 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 30 Nov 2009 15:01:29 -0800 (PST) Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: On Nov 30, 2:14?pm, Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > Generally, lower-level stuff is already written, but the web apps and desktop apps that use those lower-level apps need to be written. I suggest you pick up web dev or app dev in Python. There are a variety of frameworks. Think of an app you'd like to see, find a framework, and have fun. From tjreedy at udel.edu Mon Nov 30 18:21:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:21:09 -0500 Subject: Questions about list-creation In-Reply-To: References: Message-ID: Manuel Graune wrote: > in (most) python documentation the syntax "list()" > and "[]" is treated as being more or less the same > thing. Untrue. List() and [] happen to both evaluate to the same thing, an empty list. But there is no reason to expect list() and [] to always evaluate to the same thing. The docs for list() calls and [] displays and comprehensions are quite different. In particular, they clearly say that [x] interprets x as an item and creates a list with one item, x, while list(x) interprets x as an iterable, and creates a list with multiple items, the items of x. So. in particular, list([]) != [[]]. > For example "help([])" and "help(list())" point > to the same documentation. This has nothing to do with list(text) and [text]. [] evaluates to an instance that has no doc string, so help backs up to its class. Compare >>> help(1) Help on int object: ... The alternative to to print nothing, which would not be very helpful. Try >>> help() ... help> topics and you will see that there is a topic LISTLITERALS, though not one for comprehensions or sets or even generators. The list of topics seems not to have been kept up to date. Terry Jan Reedy From debatem1 at gmail.com Mon Nov 30 18:40:41 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 30 Nov 2009 18:40:41 -0500 Subject: Completely OT In-Reply-To: <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> References: <4dc0cfea0911300426n5fcc3510q92c489e5022ac61@mail.gmail.com> <4dc0cfea0911300949o15f59d78ua27f20e33c4281b3@mail.gmail.com> <4dc0cfea0911301021l76edc9b7x55a1e1fd4a23861@mail.gmail.com> Message-ID: On Mon, Nov 30, 2009 at 1:21 PM, Victor Subervi wrote: > On Mon, Nov 30, 2009 at 2:00 PM, inhahe wrote: >> >> On Mon, Nov 30, 2009 at 12:58 PM, inhahe wrote: >> > On Mon, Nov 30, 2009 at 12:49 PM, Victor Subervi >> > wrote: >> >> >> >> >> >> If I'm not mistaken, that won't help me actually print to screen the >> >> user's >> >> choices as he selects them, which in my application, is important. >> >> Please >> >> advise. >> >> TIA, >> >> V >> > >> > >> > sure, that's where this part comes in: >> > >> > the javascript would populate the list for the colors the user selects >> > (the easiest way would probably be to give the list an id and use >> > getElementByID()) >> > >> > so basically you'd define, e.g., an onClick="blah('red'); return true" >> > within the red element's tag, and then define a function blah(x) that >> > says >> > getElementById("my_list_id").innerHtml += "
    " + x; >> > and of course give your list textarea an id="my_list_id" attribute in >> > the tag. >> > >> > that could be slightly wrong, my javascript's rusty >> > >> >> also don't forget to sanitize the data you receive before committing >> it to the database, or someone can hack the javascript and send an SQL >> injection attack > > Good call! However, in my case I can put this all behind a firewall. It's > only for the shop builder's use, and that's my client...whom I can track! > But I presume this would entail doing searches for and eliminating all > unnecessary characters, right? > V Don't homebrew these things, they're easy to screw up and disastrous to get wrong. Also, if you're worried about how secure something you've written is, you can give yourself a little peace of mind by running over it with some of the standard script kiddie tools before deployment. It'll at least give you the comfort of knowing that they won't be able to autopwn you for a while. Geremy Condra From tjreedy at udel.edu Mon Nov 30 18:40:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:40:42 -0500 Subject: Python PIL and Vista/Windows 7 .. show() not working ... In-Reply-To: References: <4b14269f$1@dnews.tpgi.com.au> <690b938f-a4d7-4ee3-b04c-0a47493f2da7@e7g2000vbi.googlegroups.com> Message-ID: Esmail wrote: > On Nov 30, 4:37 pm, David Bolen wrote: >> If that's the issue, there are various ways around it. You could >> patch PIL itself (same function) to quote the filename when it is >> constructing the command. Alternatively, the tempfile module has a >> tempdir global you could set to some other temporary directory before >> using the show() function (or any other code using tempfile). >> >> -- David > > Thanks for the pointers David, this will give me some things to > investigate. > As for me, I'm a long time and regular Linux user with some XP tossed > in. > I use the PIL under XP at times, but this problem is happening to > someone > I know who is using both Vista and Windows and can't get the basic > thing > to work so I am trying to help. (I have access to a Win 7 VM for > testing > purposes at least). > > If I find a work-around or fix or concrete cause I'll post. In the > meantime > if anyone has any other ideas or fixes/suggestions, please don't be > shy :-) How about forget PIL's show and its automagic behavior. Use PIL's image save to write the image to a nice, known location, such as C:/temp/pic.jgp -- nothing but alphanumerics + ':/.' Next test how to run a known external viewer from a command window. Then use os.system or subprocess to run it with the same command line. Package the two lines as a myshow(params) function. From rich at noir.com Mon Nov 30 18:47:18 2009 From: rich at noir.com (K. Richard Pixley) Date: Mon, 30 Nov 2009 15:47:18 -0800 Subject: emacs, pdb, python3, ubuntu Message-ID: Does anyone have this combination working? And if so, which version of ubuntu and what did you have to do to get it to work? --rich From rtomek at ceti.com.pl Mon Nov 30 18:48:56 2009 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Tue, 1 Dec 2009 00:48:56 +0100 (CET) Subject: Bored. In-Reply-To: <4B144DFD.7060507@mrabarnett.plus.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> <4B144DFD.7060507@mrabarnett.plus.com> Message-ID: Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not > with python but I have a little problem, when i want to write > something I realise that somebody had alredy written it! So i don?t > want to make a copy of something but i wanna get better in python > skills. Don?t you know what I should do? In other words, you would like to be creative? If this is the case, you must let your head out of the box. People coding for too long have the tendency to have a box (say, a cube) on their heads. I think there is plenty of ideas waiting for someone to turn them into code. Look out the window. Read a book. Repeat. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From debatem1 at gmail.com Mon Nov 30 18:51:05 2009 From: debatem1 at gmail.com (geremy condra) Date: Mon, 30 Nov 2009 18:51:05 -0500 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: On Mon, Nov 30, 2009 at 5:14 PM, Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > > > ---sorry for my english, I ?m from czech rep... I'd find a big project and contribute to it. There's a lot more to being a developer than writing code, and its hard to learn much about that side of things by working on your own projects all the time. Plus, it can be very satisfying to make a widely used piece of software better. Geremy Condra From tjreedy at udel.edu Mon Nov 30 18:52:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Nov 2009 18:52:21 -0500 Subject: Language and collaboration In-Reply-To: <87d42zpslr.fsf_-_@benfinney.id.au> References: <5484a2e6-52fc-4607-9ea1-92755e321d93@a21g2000yqc.googlegroups.com> <6f3fb12f-96dc-4d24-8306-5cdfd2c47c65@31g2000vbf.googlegroups.com> <87d42zpslr.fsf_-_@benfinney.id.au> Message-ID: Ben Finney wrote: > "Emanuele D'Arrigo" writes: > >> Ultimately I certainly appreciate the ubiquity of English even though >> in the interest of fairness and efficiency I'd prefer the role of >> common language to be given to a constructed language, such as Ido. > > I prefer Lojban as being logically robust > while fully expressive, and sharing the Ido goal of avoiding > disadvantage to native speakers of any particular existing language. Even though I an mative-English speaking and therefore advantaged with English becoming ubiquitous, I would not mind learning *one* artificial 'natural' language. I even considered Esperanto at one point. But the advocates of such a lingua franca cannot seem to agree on which ;-). (Ido? never heard of it before -- will check W.P). tjr From stef.mientki at gmail.com Mon Nov 30 18:52:24 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 01 Dec 2009 00:52:24 +0100 Subject: Bored. In-Reply-To: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B145AB8.10000@gmail.com> Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don?t want to make a > copy of something but i wanna get better in python skills. Don?t you > know what I should do? > > > ---sorry for my english, I ?m from czech rep... > Well I thought that after 2 years you would know every detail of a language ;-) A few ideas ( or better said the things that I'm still missing, and I guess every one can name a few different ones ) - PyJamas needs a lot of extensions - Simultanuous recording of camera and sound (and preferable other signals) is completely missing - Rich editor or ( embedding of open office) - a system-wide mind mapper - graphical design package a la LabView There's also a Python site, were projects are submitted that needs something ( some even pay a little), but I can't remember where it is :-( cheers, Stef From john at castleamber.com Mon Nov 30 18:58:55 2009 From: john at castleamber.com (John Bokma) Date: 30 Nov 2009 23:58:55 GMT Subject: emacs, pdb, python3, ubuntu References: Message-ID: "K. Richard Pixley" wrote: > Does anyone have this combination working? > > And if so, which version of ubuntu and what did you have to do to get it > to work? I run Ubuntu 8.10 and use Emacs to code Python (mostly 2.5.x but I've done some small Python 3). What has Emacs to do with it? John From john at castleamber.com Mon Nov 30 19:02:31 2009 From: john at castleamber.com (John Bokma) Date: 1 Dec 2009 00:02:31 GMT Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: Stef Mientki wrote: > There's also a Python site, were projects are submitted that needs > something ( some even pay a little), > but I can't remember where it is :-( OP: A Python program to find it :D John From ben+python at benfinney.id.au Mon Nov 30 19:20:00 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Dec 2009 11:20:00 +1100 Subject: Bored. References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <87y6lno89b.fsf@benfinney.id.au> geremy condra writes: > On Mon, Nov 30, 2009 at 5:14 PM, Necronymouse wrote: > > Hello, I am learning python for about 2 years and I am bored. Not > > with python but I have a little problem, when i want to write > > something I realise that somebody had alredy written it! That's great news: it means you can learn by example, and also learn the more important skills of collaborating with other developers. > I'd find a big project and contribute to it. There's a lot more to > being a developer than writing code, and its hard to learn much about > that side of things by working on your own projects all the time. > Plus, it can be very satisfying to make a widely used piece of > software better. This is good advice. I would also say that it can be very satisfying contributing on a *small* project: there is usually less communication overhead since there are fewer people that need to communicate (the principles explored in ?The Mythical Man-Month?). On a small project, too, you can often have a bigger impact which for many people is more satisfying. So, in general: when you realise someone has already written something you want to use, then start using it! You will quickly find that it doesn't quite do everything you want, so that's your opportunity to make improvements and start working with the existing developers. -- \ ?Always code as if the guy who ends up maintaining your code | `\ will be a violent psychopath who knows where you live.? ?John | _o__) F. Woods | Ben Finney From stef.mientki at gmail.com Mon Nov 30 19:24:43 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 01 Dec 2009 01:24:43 +0100 Subject: Bored. In-Reply-To: References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> Message-ID: <4B14624B.6020809@gmail.com> John Bokma wrote: > Stef Mientki wrote: > > >> There's also a Python site, were projects are submitted that needs >> something ( some even pay a little), >> but I can't remember where it is :-( >> > > OP: A Python program to find it :D > > that was the mind mapper I mentioned :-) Stef > John > From python at mrabarnett.plus.com Mon Nov 30 19:24:43 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 01 Dec 2009 00:24:43 +0000 Subject: How to prevent re.split() from removing part of string In-Reply-To: References: Message-ID: <4B14624B.7090902@mrabarnett.plus.com> Jeremy wrote: > I am using re.split to... well, split a string into sections. I want > to split when, following a new line, there are 4 or fewer spaces. The > pattern I use is: > > sections = re.split('\n\s{,4}[^\s]', lineoftext) > > This splits appropriately but I lose the character matched by [^s]. I > know I can put parentheses around [^s] and keep the matched character, > but the character is placed in it's own element of the list instead of > with the rest of the lineoftext. > > Does anyone know how I can accomplish this without losing the matched > character? > First of all, \s matches any character that's _whitespace_, such as space, "\t", "\n", "\r", "\f". There's also \S, which matches any character that's not whitespace. But in answer to your question, use a look-ahead: sections = re.split('\n {,4}(?=\S)', lineoftext) From gregor.lingl at aon.at Mon Nov 30 19:31:52 2009 From: gregor.lingl at aon.at (Gregor Lingl) Date: Tue, 01 Dec 2009 01:31:52 +0100 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: References: <4B13F47E.3080706@aon.at> Message-ID: <4B1463F8.2000902@aon.at> kirby urner schrieb: > I'm glad turtle graphics intersected my thinking re extended precision > decimals (Decimal type) on edu-sig just now. > > I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod: > > http://www.4dsolutions.net/ocn/python/tmod.py (runnable source) > http://www.flickr.com/photos/17157315 at N00/4147429781/ (GUI view) > Nice tiny app! Albeit not an example for using the if statement ;-) Just to show you how turtle.py enables you to implement this using quite different approaches to doing geometry, I'd like to add two more implementations. Besides you may notice that these do not rely on rather complicated calculations of distances and angles, using the Pythagorean theorem and trigonometrics but only on a few more fundamental properties of the figure. ##### Version 2 - using coordinate geometry without coordinates ;-) # a different implementation for Kirby's "Plane Net for T-module" from turtle import * from math import sqrt PHI = (sqrt(5)-1)/2 def planeNet(h=500): setup(560,560) title("Plane Net for T-module") penup() back(h/2); left(90); back(h/2); right(90) pendown() forward(h); left(90) forward(h*PHI); A = pos(); forward(h-h*PHI); left(90) forward(h*PHI); B = pos(); forward(h-h*PHI); left(90) forward(h); C = pos() for P in A, B, C: goto(P) ##### Version 3 - stamping simple transforms of the shape of ##### an isosceles rectangular triangle: from turtle import Screen, Turtle from math import sqrt GOLDEN_RATIO = (sqrt(5)-1)/2 def planeNet(h=500.0, phi=GOLDEN_RATIO): s = Screen(); s.setup(560,560); s.title("Plane Net for T-module") s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h))) designer = Turtle(shape="recttriangle") designer.color("black","") designer.penup() designer.goto(-h/2, h/2) for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)): designer.shapesize(width, height) designer.stamp() designer.forward(h) designer.right(90) designer.hideturtle() Hoping, you will find this a bit interesting, best regards Gregor > Here's the graphical output: > > http://www.flickr.com/photos/17157315 at N00/4148139184/in/photostream/ > (Python 3.1) > > If you actually wanna fold the T, you need to snip off the cap and > reverse it, per this diagram: > > http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html > > 120 of them, 60 folded left, 60 folded right, all of volume 1/24, make > the volume 5 rhombic triacontahedron. > > http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html > > If you blow up the volume by 3/2, to 7.5, the radius becomes phi / > sqrt(2) -- what we're showing with Decimals. > > The reason this seems unfamiliar is the unit of volume is the > tetrahedron formed by any four equi-radiused balls in inter-tangency. > > I'm spinning this as Martian Math these days, yakking on > math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et > al. > > Kirby > > From kirby.urner at gmail.com Mon Nov 30 19:52:09 2009 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 30 Nov 2009 16:52:09 -0800 Subject: [Edu-sig] teaching python using turtle module In-Reply-To: <4B1463F8.2000902@aon.at> References: <4B13F47E.3080706@aon.at> <4B1463F8.2000902@aon.at> Message-ID: On Mon, Nov 30, 2009 at 4:31 PM, Gregor Lingl wrote: << fascinating code >> > > Hoping, you will find this a bit interesting, > best regards > > Gregor > Really enlightening, both mathematically and from a coding point of view. I hadn't used turtle.py enough yet to know about the built-in "context turtle" if you want to just say "forward" and forgo specifying a target. That's a nice Logo-ish touch. Your take on the T is most excellent. With your permission, I'd be happy to add both versions with attribution to my online version of tmod.py for the benefit of future students, and/or I could simply link to this post in the edu-sig archives (why not both?). Kirby -- >>> from mars import math http://www.wikieducator.org/Digital_Math From jorgeecardona at gmail.com Mon Nov 30 20:15:48 2009 From: jorgeecardona at gmail.com (Jorge Cardona) Date: Mon, 30 Nov 2009 20:15:48 -0500 Subject: Bored. In-Reply-To: <4B145AB8.10000@gmail.com> References: <16097008-372c-4522-889d-a78319c3575c@b2g2000yqi.googlegroups.com> <4B145AB8.10000@gmail.com> Message-ID: <51d803a90911301715k6d2eaf21v934b9da62783b25f@mail.gmail.com> 2009/11/30 Stef Mientki : > Necronymouse wrote: >> >> Hello, I am learning python for about 2 years and I am bored. Not with >> python but I have a little problem, when i want to write something I >> realise that somebody had alredy written it! So i don?t want to make a >> copy of something but i wanna get better in python skills. Don?t you >> know what I should do? >> >> >> ---sorry for my english, I ?m from czech rep... >> > > Well I thought that after 2 years you would know every detail of a language > ;-) > > A few ideas ( or better said the things that I'm still missing, and I guess > every one can name a ?few different ones ) > - PyJamas needs a lot of extensions > - Simultanuous recording of ?camera and sound (and preferable other signals) > is completely missing > - Rich editor or ( embedding of open office) > - a system-wide mind mapper > - graphical design package a la LabView I had have a project in mind for several months, a compiler for Modelica language in python, there is actually two main approach, openmodelica and jmodelica, both free ( i don't remember the exactly licences), openmodelica is written in C++ and jmodelica has a front-end for python, but its core is java based. I had started a gtkmodelica project, in code google, with c++ and spirit library( i didn't find at the moment a good library like spirit in python), but developing in c++ is quite slow (but is really nice), and recently I found pyparsing, I think is a good tool for the parser, and i create a repo in github (is empty right now), i wish i could have the enough time right now, but i got a lot of work right now. A project like this has a lot of great challenges: parsing, differential equation solving, a lot about language semantics, the graphical tool could be like labview, simulink, or maplesim ( I love flowcanvas library for gtk in c++, but it is quite old right now), code generation (to use hardware in the loop), real time plotting, etc... it could be a great project. I'm using right now some python classes that works as wrapper for openmodelica, and i use numpy for optimization purpose, and it works great, but a more natural mix with a native python tool would be just fantastic. http://github.com/jorgeecardona/pymodelica http://drobilla.net/software/flowcanvas/ http://code.google.com/p/gtkmodelica/ http://www.jmodelica.org/ http://www.ida.liu.se/~pelab/modelica/OpenModelica.html > > There's also a Python site, were projects are submitted that needs something > ( some even pay a little), > but I can't remember where it is :-( > > cheers, > Stef > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jorge Eduardo Cardona jorgeecardona at gmail.com jorgeecardona.blogspot.com ------------------------------------------------ Linux registered user #391186 Registered machine #291871 ------------------------------------------------ From fearsomedragonfly at gmail.com Mon Nov 30 21:55:46 2009 From: fearsomedragonfly at gmail.com (The Music Guy) Date: Mon, 30 Nov 2009 18:55:46 -0800 (PST) Subject: Feature request: String-inferred names References: <17a26a8c-3358-4152-8871-2dcaa7e97220@g23g2000vbr.googlegroups.com> <87skc0zstu.fsf@benfinney.id.au> Message-ID: > Brad Harms FearsomeDragonfly at gmail.com > Mon Nov 30 05:04:37 CET 2009 > > That was a relatively simple example; classes as simple as the ones > generated by the It is more likely that the class generation could would > appear in a metaclass's class constructor or decorator function, and there > would be more than just the three attributes given. Bwa ha ha! Well, I managed to screw up that paragraph pretty badly. (I code better than I write, honest.) Let me try again: That was a relatively simple example; classes as simple as the ones generated by the factory function example given are not needed very often. It is more likely that the class generation would appear in a metaclass's class constructor or decorator function, and there would be more than just the three attributes. That way it could be possible to ADD those properties and methods to a class in the process of being built rather than make a class with just those attributes. Lie Ryan, I think I see what you're saying about using __dict__ to add members to a class, but it's not quite the same. __dict__ is only for attributes, NOT properties, methods, etc. which all come from the class of an object rather than the object's __dict__. Adding things to __dict__ would only work halfway; it wouldn't be very extensible. That's (one of the reasons) why the members have to be accessed as attributes rather than dict items. From gnarlodious at gmail.com Mon Nov 30 22:24:54 2009 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 30 Nov 2009 19:24:54 -0800 (PST) Subject: Can't print Chinese to HTTP References: <4b13c039$0$7478$9b622d9e@news.freenet.de> Message-ID: > you probably need to change the encoding of sys.stdout >>> sys.stdout.encoding 'UTF-8' >> #!/usr/bin/python > do you know what python version, exactly, that gets called by this hashbang? Verified in HTTP: >>> print(sys.version) 3.1.1 Is is possible modules are getting loaded from my old Python? I symlinked to the new Python, and no I do not want to roll it back because it is work (meaning I would have to type "sudo"). ls /usr/bin/python lrwxr-xr-x 1 root wheel 63 Nov 20 21:24 /usr/bin/python -> /Library/ Frameworks/Python.framework/Versions/3.1/bin/python3.1 Ugh, I have not been able to program in 11 days. Now I remember doing it that way because I could not figure out how to get Apache to find the new Python. ls /usr/local/bin/python3.1 lrwxr-xr-x 1 root wheel 71 Nov 20 08:19 /usr/local/bin/python3.1 - > ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 So they are both pointing to the same Python. And yes, I would prefer easier http scripting, but don't know one. -- Gnarlie From aioe.org at technicalbloke.com Mon Nov 30 23:20:37 2009 From: aioe.org at technicalbloke.com (r0g) Date: Tue, 01 Dec 2009 04:20:37 +0000 Subject: Creating a local variable scope. References: <4b12f20c@dnews.tpgi.com.au> <97a101a2-1362-46f4-9308-b72e5c4ac392@s20g2000yqd.googlegroups.com> Message-ID: markolopa wrote: > On Nov 30, 4:46 am, Dave Angel wrote: >> markolopa wrote: >> or >> whether you accidentally reused the same name without giving it a new >> value in the new loop. > > That is what I do regularly...8-> > Well really dude, you need to stop doing that. It's not a language problem, it's a memory problem (human not RAM!). You need to be aware of what you're putting into your namespace. This is one of the reasons people try to avoid using global variables, if you forget you've used a variable name and use it again somewhere you get an undefined state and hours of debugging / data loss / subtle corruptions you won't spot until the backups have all been cycled etc. I'm surprised you have a recurring problem with this really. My memory is terrible and I reuse variable names all over the place without any trouble. Maybe try keeping the length of your functions down so that they fit on a single screen and create and use a strong naming convention i.e. Long, descriptive variable names all_in_lower_case Function names all in CamelCase Global names are in ALL CAPS Loop variable names all prefixed with 'each_' The details don't so much matter as long as you are consistent with it. I'm sure many here would hate my coding conventions if they had to use them but they seem to work OK for me and I can't recall ever having this problem. Roger. From casevh at gmail.com Mon Nov 30 23:51:06 2009 From: casevh at gmail.com (casevh) Date: Mon, 30 Nov 2009 20:51:06 -0800 (PST) Subject: PyArg_ParseTupleAndKeywords in Python3.1 References: <0a0b822c-8d57-4816-8563-5fd8ff39f7f1@p8g2000yqb.googlegroups.com> Message-ID: <83f08b89-6b61-4005-9fbd-c9a01da36654@d9g2000prh.googlegroups.com> On Nov 30, 2:18?pm, Joachim Dahl wrote: > I think that "C" encoding is what I need, however I run into an odd > problem. > If I use the following C code > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { > ? char a, b; > ? char *kwlist[] = {"a", "b", NULL}; > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, > &b)) > ? ? return NULL; > ? ... > > then the following works: > > >>> foo('a') > >>> foo('a','b') > >>> foo(a='a',b='b') > > but the following fails:>>> foo(b='b') > > RuntimeError: impossible: 'CC' > > Is this error-message expected? Nope. It appears to be a bug in Python. The format code 'C' is missing in the switch statement in skipitem() in getargs.c. I added "case 'C': /* int */" after "case 'c': /* char */" and then example worked for me. I'll open a bug report. casevh > > On Nov 30, 10:19?pm, casevh wrote: > > > On Nov 30, 1:04?pm, Joachim Dahl wrote: > > > > Obviously the name of the C function and the char variable cannot both > > > be foo, > > > so the C code should be: > > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > { > > > ? char foochar; > > > ? char *kwlist[] = {"foochar", NULL}; > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, > > > &foochar)) > > > ? ? return NULL; > > > ? ... > > > > The question remains the same: why can't I pass a single character > > > argument to this function under Python3.1? > > > > Thanks. > > > Joachim > > > > On Nov 30, 9:52?pm, Joachim Dahl wrote: > > > > > I am updating an extension module from Python2.6 to Python3. > > > > > I used to pass character codes to the extension module, for example, I > > > > would write: > > > > > >>> foo('X') > > > > > with the corresponding C extension routine defined as follows: > > > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > > > > { > > > > ? char foo; > > > > ? char *kwlist[] = {"foo", NULL}; > > > > ? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo)) > > > > ? ? return NULL; > > > > ? ... > > > > > In Python3.0 this also works, but in Python3.1 I get the following > > > > error: > > > > TypeError: argument 1 must be a byte string of length 1, not str > > > > > and I seem to be supposed to write>>> foo(b'X') > > > > > instead. From the Python C API, I have not been able to explain this > > > > new behavior. > > > > What is the correct way to pass a single character argument to > > > > Python3.1 > > > > extension modules?- Hide quoted text - > > > > - Show quoted text - > > > Python 3.1 uses "c" (lowercase c) to parse a single character from a > > byte-string and uses "C" (uppercase c) to parse a single character > > from a Unicode string. I don't think there is an easy way to accept a > > character from both. > > > HTH, > > > casevh > >